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 (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2792 dwarf2out_flush_queued_reg_saves ();
2794 if (!RTX_FRAME_RELATED_P (insn))
2796 /* ??? This should be done unconditionally since stack adjustments
2797 matter if the stack pointer is not the CFA register anymore but
2798 is still used to save registers. */
2799 if (!ACCUMULATE_OUTGOING_ARGS)
2800 dwarf2out_notice_stack_adjust (insn, after_p);
2804 label = dwarf2out_cfi_label (false);
2805 any_cfis_emitted = false;
2807 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2808 switch (REG_NOTE_KIND (note))
2810 case REG_FRAME_RELATED_EXPR:
2811 insn = XEXP (note, 0);
2814 case REG_CFA_DEF_CFA:
2815 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2819 case REG_CFA_ADJUST_CFA:
2824 if (GET_CODE (n) == PARALLEL)
2825 n = XVECEXP (n, 0, 0);
2827 dwarf2out_frame_debug_adjust_cfa (n, label);
2831 case REG_CFA_OFFSET:
2834 n = single_set (insn);
2835 dwarf2out_frame_debug_cfa_offset (n, label);
2839 case REG_CFA_REGISTER:
2844 if (GET_CODE (n) == PARALLEL)
2845 n = XVECEXP (n, 0, 0);
2847 dwarf2out_frame_debug_cfa_register (n, label);
2851 case REG_CFA_EXPRESSION:
2854 n = single_set (insn);
2855 dwarf2out_frame_debug_cfa_expression (n, label);
2859 case REG_CFA_RESTORE:
2864 if (GET_CODE (n) == PARALLEL)
2865 n = XVECEXP (n, 0, 0);
2868 dwarf2out_frame_debug_cfa_restore (n, label);
2872 case REG_CFA_SET_VDRAP:
2876 dw_fde_ref fde = current_fde ();
2879 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2881 fde->vdrap_reg = REGNO (n);
2892 if (any_cfis_emitted)
2893 dwarf2out_flush_queued_reg_saves ();
2897 insn = PATTERN (insn);
2899 dwarf2out_frame_debug_expr (insn, label);
2901 /* Check again. A parallel can save and update the same register.
2902 We could probably check just once, here, but this is safer than
2903 removing the check above. */
2904 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2905 dwarf2out_flush_queued_reg_saves ();
2908 /* Called once at the start of final to initialize some data for the
2909 current function. */
2911 dwarf2out_frame_debug_init (void)
2915 /* Flush any queued register saves. */
2916 dwarf2out_flush_queued_reg_saves ();
2918 /* Set up state for generating call frame debug info. */
2921 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2923 cfa.reg = STACK_POINTER_REGNUM;
2926 cfa_temp.offset = 0;
2928 for (i = 0; i < num_regs_saved_in_regs; i++)
2930 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2931 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2933 num_regs_saved_in_regs = 0;
2935 if (barrier_args_size)
2937 XDELETEVEC (barrier_args_size);
2938 barrier_args_size = NULL;
2942 /* Determine if we need to save and restore CFI information around this
2943 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2944 we do need to save/restore, then emit the save now, and insert a
2945 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2948 dwarf2out_cfi_begin_epilogue (rtx insn)
2950 bool saw_frp = false;
2953 /* Scan forward to the return insn, noticing if there are possible
2954 frame related insns. */
2955 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2960 /* Look for both regular and sibcalls to end the block. */
2961 if (returnjump_p (i))
2963 if (CALL_P (i) && SIBLING_CALL_P (i))
2966 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2969 rtx seq = PATTERN (i);
2971 if (returnjump_p (XVECEXP (seq, 0, 0)))
2973 if (CALL_P (XVECEXP (seq, 0, 0))
2974 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2977 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2978 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2982 if (RTX_FRAME_RELATED_P (i))
2986 /* If the port doesn't emit epilogue unwind info, we don't need a
2987 save/restore pair. */
2991 /* Otherwise, search forward to see if the return insn was the last
2992 basic block of the function. If so, we don't need save/restore. */
2993 gcc_assert (i != NULL);
2994 i = next_real_insn (i);
2998 /* Insert the restore before that next real insn in the stream, and before
2999 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3000 properly nested. This should be after any label or alignment. This
3001 will be pushed into the CFI stream by the function below. */
3004 rtx p = PREV_INSN (i);
3007 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3011 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3013 emit_cfa_remember = true;
3015 /* And emulate the state save. */
3016 gcc_assert (!cfa_remember.in_use);
3018 cfa_remember.in_use = 1;
3021 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3025 dwarf2out_frame_debug_restore_state (void)
3027 dw_cfi_ref cfi = new_cfi ();
3028 const char *label = dwarf2out_cfi_label (false);
3030 cfi->dw_cfi_opc = DW_CFA_restore_state;
3031 add_fde_cfi (label, cfi);
3033 gcc_assert (cfa_remember.in_use);
3035 cfa_remember.in_use = 0;
3038 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3039 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3040 (enum dwarf_call_frame_info cfi);
3042 static enum dw_cfi_oprnd_type
3043 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3048 case DW_CFA_GNU_window_save:
3049 case DW_CFA_remember_state:
3050 case DW_CFA_restore_state:
3051 return dw_cfi_oprnd_unused;
3053 case DW_CFA_set_loc:
3054 case DW_CFA_advance_loc1:
3055 case DW_CFA_advance_loc2:
3056 case DW_CFA_advance_loc4:
3057 case DW_CFA_MIPS_advance_loc8:
3058 return dw_cfi_oprnd_addr;
3061 case DW_CFA_offset_extended:
3062 case DW_CFA_def_cfa:
3063 case DW_CFA_offset_extended_sf:
3064 case DW_CFA_def_cfa_sf:
3065 case DW_CFA_restore:
3066 case DW_CFA_restore_extended:
3067 case DW_CFA_undefined:
3068 case DW_CFA_same_value:
3069 case DW_CFA_def_cfa_register:
3070 case DW_CFA_register:
3071 case DW_CFA_expression:
3072 return dw_cfi_oprnd_reg_num;
3074 case DW_CFA_def_cfa_offset:
3075 case DW_CFA_GNU_args_size:
3076 case DW_CFA_def_cfa_offset_sf:
3077 return dw_cfi_oprnd_offset;
3079 case DW_CFA_def_cfa_expression:
3080 return dw_cfi_oprnd_loc;
3087 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3088 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3089 (enum dwarf_call_frame_info cfi);
3091 static enum dw_cfi_oprnd_type
3092 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3096 case DW_CFA_def_cfa:
3097 case DW_CFA_def_cfa_sf:
3099 case DW_CFA_offset_extended_sf:
3100 case DW_CFA_offset_extended:
3101 return dw_cfi_oprnd_offset;
3103 case DW_CFA_register:
3104 return dw_cfi_oprnd_reg_num;
3106 case DW_CFA_expression:
3107 return dw_cfi_oprnd_loc;
3110 return dw_cfi_oprnd_unused;
3114 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3115 switch to the data section instead, and write out a synthetic start label
3116 for collect2 the first time around. */
3119 switch_to_eh_frame_section (bool back)
3123 #ifdef EH_FRAME_SECTION_NAME
3124 if (eh_frame_section == 0)
3128 if (EH_TABLES_CAN_BE_READ_ONLY)
3134 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3136 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3138 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3140 flags = ((! flag_pic
3141 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3142 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3143 && (per_encoding & 0x70) != DW_EH_PE_absptr
3144 && (per_encoding & 0x70) != DW_EH_PE_aligned
3145 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3146 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3147 ? 0 : SECTION_WRITE);
3150 flags = SECTION_WRITE;
3151 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3153 #endif /* EH_FRAME_SECTION_NAME */
3155 if (eh_frame_section)
3156 switch_to_section (eh_frame_section);
3159 /* We have no special eh_frame section. Put the information in
3160 the data section and emit special labels to guide collect2. */
3161 switch_to_section (data_section);
3165 label = get_file_function_name ("F");
3166 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3167 targetm.asm_out.globalize_label (asm_out_file,
3168 IDENTIFIER_POINTER (label));
3169 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3174 /* Switch [BACK] to the eh or debug frame table section, depending on
3178 switch_to_frame_table_section (int for_eh, bool back)
3181 switch_to_eh_frame_section (back);
3184 if (!debug_frame_section)
3185 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3186 SECTION_DEBUG, NULL);
3187 switch_to_section (debug_frame_section);
3191 /* Output a Call Frame Information opcode and its operand(s). */
3194 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3199 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3200 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3201 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3202 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3203 ((unsigned HOST_WIDE_INT)
3204 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3205 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3207 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3208 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3209 "DW_CFA_offset, column %#lx", r);
3210 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3211 dw2_asm_output_data_uleb128 (off, NULL);
3213 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3215 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3216 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3217 "DW_CFA_restore, column %#lx", r);
3221 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3222 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3224 switch (cfi->dw_cfi_opc)
3226 case DW_CFA_set_loc:
3228 dw2_asm_output_encoded_addr_rtx (
3229 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3230 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3233 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3234 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3235 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3238 case DW_CFA_advance_loc1:
3239 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3240 fde->dw_fde_current_label, NULL);
3241 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3244 case DW_CFA_advance_loc2:
3245 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3246 fde->dw_fde_current_label, NULL);
3247 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3250 case DW_CFA_advance_loc4:
3251 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3252 fde->dw_fde_current_label, NULL);
3253 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3256 case DW_CFA_MIPS_advance_loc8:
3257 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3258 fde->dw_fde_current_label, NULL);
3259 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3262 case DW_CFA_offset_extended:
3263 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3264 dw2_asm_output_data_uleb128 (r, NULL);
3265 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3266 dw2_asm_output_data_uleb128 (off, NULL);
3269 case DW_CFA_def_cfa:
3270 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3271 dw2_asm_output_data_uleb128 (r, NULL);
3272 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3275 case DW_CFA_offset_extended_sf:
3276 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3277 dw2_asm_output_data_uleb128 (r, NULL);
3278 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3279 dw2_asm_output_data_sleb128 (off, NULL);
3282 case DW_CFA_def_cfa_sf:
3283 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3284 dw2_asm_output_data_uleb128 (r, NULL);
3285 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3286 dw2_asm_output_data_sleb128 (off, NULL);
3289 case DW_CFA_restore_extended:
3290 case DW_CFA_undefined:
3291 case DW_CFA_same_value:
3292 case DW_CFA_def_cfa_register:
3293 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3294 dw2_asm_output_data_uleb128 (r, NULL);
3297 case DW_CFA_register:
3298 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3299 dw2_asm_output_data_uleb128 (r, NULL);
3300 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3301 dw2_asm_output_data_uleb128 (r, NULL);
3304 case DW_CFA_def_cfa_offset:
3305 case DW_CFA_GNU_args_size:
3306 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3309 case DW_CFA_def_cfa_offset_sf:
3310 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3311 dw2_asm_output_data_sleb128 (off, NULL);
3314 case DW_CFA_GNU_window_save:
3317 case DW_CFA_def_cfa_expression:
3318 case DW_CFA_expression:
3319 output_cfa_loc (cfi, for_eh);
3322 case DW_CFA_GNU_negative_offset_extended:
3323 /* Obsoleted by DW_CFA_offset_extended_sf. */
3332 /* Similar, but do it via assembler directives instead. */
3335 output_cfi_directive (dw_cfi_ref cfi)
3337 unsigned long r, r2;
3339 switch (cfi->dw_cfi_opc)
3341 case DW_CFA_advance_loc:
3342 case DW_CFA_advance_loc1:
3343 case DW_CFA_advance_loc2:
3344 case DW_CFA_advance_loc4:
3345 case DW_CFA_MIPS_advance_loc8:
3346 case DW_CFA_set_loc:
3347 /* Should only be created by add_fde_cfi in a code path not
3348 followed when emitting via directives. The assembler is
3349 going to take care of this for us. */
3353 case DW_CFA_offset_extended:
3354 case DW_CFA_offset_extended_sf:
3355 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3356 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3357 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3360 case DW_CFA_restore:
3361 case DW_CFA_restore_extended:
3362 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3363 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3366 case DW_CFA_undefined:
3367 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3368 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3371 case DW_CFA_same_value:
3372 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3373 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3376 case DW_CFA_def_cfa:
3377 case DW_CFA_def_cfa_sf:
3378 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3379 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3380 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3383 case DW_CFA_def_cfa_register:
3384 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3385 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3388 case DW_CFA_register:
3389 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3390 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3391 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3394 case DW_CFA_def_cfa_offset:
3395 case DW_CFA_def_cfa_offset_sf:
3396 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3397 HOST_WIDE_INT_PRINT_DEC"\n",
3398 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3401 case DW_CFA_remember_state:
3402 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3404 case DW_CFA_restore_state:
3405 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3408 case DW_CFA_GNU_args_size:
3409 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3410 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3412 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3413 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3414 fputc ('\n', asm_out_file);
3417 case DW_CFA_GNU_window_save:
3418 fprintf (asm_out_file, "\t.cfi_window_save\n");
3421 case DW_CFA_def_cfa_expression:
3422 case DW_CFA_expression:
3423 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3424 output_cfa_loc_raw (cfi);
3425 fputc ('\n', asm_out_file);
3433 DEF_VEC_P (dw_cfi_ref);
3434 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3436 /* Output CFIs to bring current FDE to the same state as after executing
3437 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3438 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3439 other arguments to pass to output_cfi. */
3442 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3444 struct dw_cfi_struct cfi_buf;
3446 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3447 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3448 unsigned int len, idx;
3450 for (;; cfi = cfi->dw_cfi_next)
3451 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3453 case DW_CFA_advance_loc:
3454 case DW_CFA_advance_loc1:
3455 case DW_CFA_advance_loc2:
3456 case DW_CFA_advance_loc4:
3457 case DW_CFA_MIPS_advance_loc8:
3458 case DW_CFA_set_loc:
3459 /* All advances should be ignored. */
3461 case DW_CFA_remember_state:
3463 dw_cfi_ref args_size = cfi_args_size;
3465 /* Skip everything between .cfi_remember_state and
3466 .cfi_restore_state. */
3467 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3468 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3470 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3473 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3480 cfi_args_size = args_size;
3484 case DW_CFA_GNU_args_size:
3485 cfi_args_size = cfi;
3487 case DW_CFA_GNU_window_save:
3490 case DW_CFA_offset_extended:
3491 case DW_CFA_offset_extended_sf:
3492 case DW_CFA_restore:
3493 case DW_CFA_restore_extended:
3494 case DW_CFA_undefined:
3495 case DW_CFA_same_value:
3496 case DW_CFA_register:
3497 case DW_CFA_val_offset:
3498 case DW_CFA_val_offset_sf:
3499 case DW_CFA_expression:
3500 case DW_CFA_val_expression:
3501 case DW_CFA_GNU_negative_offset_extended:
3502 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3503 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3504 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3505 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3507 case DW_CFA_def_cfa:
3508 case DW_CFA_def_cfa_sf:
3509 case DW_CFA_def_cfa_expression:
3511 cfi_cfa_offset = cfi;
3513 case DW_CFA_def_cfa_register:
3516 case DW_CFA_def_cfa_offset:
3517 case DW_CFA_def_cfa_offset_sf:
3518 cfi_cfa_offset = cfi;
3521 gcc_assert (cfi == NULL);
3523 len = VEC_length (dw_cfi_ref, regs);
3524 for (idx = 0; idx < len; idx++)
3526 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3528 && cfi2->dw_cfi_opc != DW_CFA_restore
3529 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3532 output_cfi_directive (cfi2);
3534 output_cfi (cfi2, fde, for_eh);
3537 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3539 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3541 switch (cfi_cfa_offset->dw_cfi_opc)
3543 case DW_CFA_def_cfa_offset:
3544 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3545 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3547 case DW_CFA_def_cfa_offset_sf:
3548 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3549 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3551 case DW_CFA_def_cfa:
3552 case DW_CFA_def_cfa_sf:
3553 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3554 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3561 else if (cfi_cfa_offset)
3562 cfi_cfa = cfi_cfa_offset;
3566 output_cfi_directive (cfi_cfa);
3568 output_cfi (cfi_cfa, fde, for_eh);
3571 cfi_cfa_offset = NULL;
3573 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3576 output_cfi_directive (cfi_args_size);
3578 output_cfi (cfi_args_size, fde, for_eh);
3580 cfi_args_size = NULL;
3583 VEC_free (dw_cfi_ref, heap, regs);
3586 else if (do_cfi_asm)
3587 output_cfi_directive (cfi);
3589 output_cfi (cfi, fde, for_eh);
3596 /* Output one FDE. */
3599 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3600 char *section_start_label, int fde_encoding, char *augmentation,
3601 bool any_lsda_needed, int lsda_encoding)
3603 const char *begin, *end;
3604 static unsigned int j;
3605 char l1[20], l2[20];
3608 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3610 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3612 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3613 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3614 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3615 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3616 " indicating 64-bit DWARF extension");
3617 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3619 ASM_OUTPUT_LABEL (asm_out_file, l1);
3622 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3624 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3625 debug_frame_section, "FDE CIE offset");
3627 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3628 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3632 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3633 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3634 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3635 "FDE initial location");
3636 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3637 end, begin, "FDE address range");
3641 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3642 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3645 if (augmentation[0])
3647 if (any_lsda_needed)
3649 int size = size_of_encoded_value (lsda_encoding);
3651 if (lsda_encoding == DW_EH_PE_aligned)
3653 int offset = ( 4 /* Length */
3654 + 4 /* CIE offset */
3655 + 2 * size_of_encoded_value (fde_encoding)
3656 + 1 /* Augmentation size */ );
3657 int pad = -offset & (PTR_SIZE - 1);
3660 gcc_assert (size_of_uleb128 (size) == 1);
3663 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3665 if (fde->uses_eh_lsda)
3667 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3668 fde->funcdef_number);
3669 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3670 gen_rtx_SYMBOL_REF (Pmode, l1),
3672 "Language Specific Data Area");
3676 if (lsda_encoding == DW_EH_PE_aligned)
3677 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3678 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3679 "Language Specific Data Area (none)");
3683 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3686 /* Loop through the Call Frame Instructions associated with
3688 fde->dw_fde_current_label = begin;
3689 if (fde->dw_fde_second_begin == NULL)
3690 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3691 output_cfi (cfi, fde, for_eh);
3694 if (fde->dw_fde_switch_cfi)
3695 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3697 output_cfi (cfi, fde, for_eh);
3698 if (cfi == fde->dw_fde_switch_cfi)
3704 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3706 if (fde->dw_fde_switch_cfi)
3708 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3709 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3710 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3711 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3713 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3714 output_cfi (cfi, fde, for_eh);
3717 /* If we are to emit a ref/link from function bodies to their frame tables,
3718 do it now. This is typically performed to make sure that tables
3719 associated with functions are dragged with them and not discarded in
3720 garbage collecting links. We need to do this on a per function basis to
3721 cope with -ffunction-sections. */
3723 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3724 /* Switch to the function section, emit the ref to the tables, and
3725 switch *back* into the table section. */
3726 switch_to_section (function_section (fde->decl));
3727 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3728 switch_to_frame_table_section (for_eh, true);
3731 /* Pad the FDE out to an address sized boundary. */
3732 ASM_OUTPUT_ALIGN (asm_out_file,
3733 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3734 ASM_OUTPUT_LABEL (asm_out_file, l2);
3739 /* Return true if frame description entry FDE is needed for EH. */
3742 fde_needed_for_eh_p (dw_fde_ref fde)
3744 if (flag_asynchronous_unwind_tables)
3747 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3750 if (fde->uses_eh_lsda)
3753 /* If exceptions are enabled, we have collected nothrow info. */
3754 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3760 /* Output the call frame information used to record information
3761 that relates to calculating the frame pointer, and records the
3762 location of saved registers. */
3765 output_call_frame_info (int for_eh)
3770 char l1[20], l2[20], section_start_label[20];
3771 bool any_lsda_needed = false;
3772 char augmentation[6];
3773 int augmentation_size;
3774 int fde_encoding = DW_EH_PE_absptr;
3775 int per_encoding = DW_EH_PE_absptr;
3776 int lsda_encoding = DW_EH_PE_absptr;
3778 rtx personality = NULL;
3781 /* Don't emit a CIE if there won't be any FDEs. */
3782 if (fde_table_in_use == 0)
3785 /* Nothing to do if the assembler's doing it all. */
3786 if (dwarf2out_do_cfi_asm ())
3789 /* If we don't have any functions we'll want to unwind out of, don't emit
3790 any EH unwind information. If we make FDEs linkonce, we may have to
3791 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3792 want to avoid having an FDE kept around when the function it refers to
3793 is discarded. Example where this matters: a primary function template
3794 in C++ requires EH information, an explicit specialization doesn't. */
3797 bool any_eh_needed = false;
3799 for (i = 0; i < fde_table_in_use; i++)
3800 if (fde_table[i].uses_eh_lsda)
3801 any_eh_needed = any_lsda_needed = true;
3802 else if (fde_needed_for_eh_p (&fde_table[i]))
3803 any_eh_needed = true;
3804 else if (TARGET_USES_WEAK_UNWIND_INFO)
3805 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3812 /* We're going to be generating comments, so turn on app. */
3816 /* Switch to the proper frame section, first time. */
3817 switch_to_frame_table_section (for_eh, false);
3819 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3820 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3822 /* Output the CIE. */
3823 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3824 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3825 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3826 dw2_asm_output_data (4, 0xffffffff,
3827 "Initial length escape value indicating 64-bit DWARF extension");
3828 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3829 "Length of Common Information Entry");
3830 ASM_OUTPUT_LABEL (asm_out_file, l1);
3832 /* Now that the CIE pointer is PC-relative for EH,
3833 use 0 to identify the CIE. */
3834 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3835 (for_eh ? 0 : DWARF_CIE_ID),
3836 "CIE Identifier Tag");
3838 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3839 use CIE version 1, unless that would produce incorrect results
3840 due to overflowing the return register column. */
3841 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3843 if (return_reg >= 256 || dwarf_version > 2)
3845 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3847 augmentation[0] = 0;
3848 augmentation_size = 0;
3850 personality = current_unit_personality;
3856 z Indicates that a uleb128 is present to size the
3857 augmentation section.
3858 L Indicates the encoding (and thus presence) of
3859 an LSDA pointer in the FDE augmentation.
3860 R Indicates a non-default pointer encoding for
3862 P Indicates the presence of an encoding + language
3863 personality routine in the CIE augmentation. */
3865 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3866 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3867 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3869 p = augmentation + 1;
3873 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3874 assemble_external_libcall (personality);
3876 if (any_lsda_needed)
3879 augmentation_size += 1;
3881 if (fde_encoding != DW_EH_PE_absptr)
3884 augmentation_size += 1;
3886 if (p > augmentation + 1)
3888 augmentation[0] = 'z';
3892 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3893 if (personality && per_encoding == DW_EH_PE_aligned)
3895 int offset = ( 4 /* Length */
3897 + 1 /* CIE version */
3898 + strlen (augmentation) + 1 /* Augmentation */
3899 + size_of_uleb128 (1) /* Code alignment */
3900 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3902 + 1 /* Augmentation size */
3903 + 1 /* Personality encoding */ );
3904 int pad = -offset & (PTR_SIZE - 1);
3906 augmentation_size += pad;
3908 /* Augmentations should be small, so there's scarce need to
3909 iterate for a solution. Die if we exceed one uleb128 byte. */
3910 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3914 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3915 if (dw_cie_version >= 4)
3917 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3918 dw2_asm_output_data (1, 0, "CIE Segment Size");
3920 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3921 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3922 "CIE Data Alignment Factor");
3924 if (dw_cie_version == 1)
3925 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3927 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3929 if (augmentation[0])
3931 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3934 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3935 eh_data_format_name (per_encoding));
3936 dw2_asm_output_encoded_addr_rtx (per_encoding,
3941 if (any_lsda_needed)
3942 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3943 eh_data_format_name (lsda_encoding));
3945 if (fde_encoding != DW_EH_PE_absptr)
3946 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3947 eh_data_format_name (fde_encoding));
3950 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3951 output_cfi (cfi, NULL, for_eh);
3953 /* Pad the CIE out to an address sized boundary. */
3954 ASM_OUTPUT_ALIGN (asm_out_file,
3955 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3956 ASM_OUTPUT_LABEL (asm_out_file, l2);
3958 /* Loop through all of the FDE's. */
3959 for (i = 0; i < fde_table_in_use; i++)
3962 fde = &fde_table[i];
3964 /* Don't emit EH unwind info for leaf functions that don't need it. */
3965 if (for_eh && !fde_needed_for_eh_p (fde))
3968 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
3969 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3970 augmentation, any_lsda_needed, lsda_encoding);
3973 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3974 dw2_asm_output_data (4, 0, "End of Table");
3975 #ifdef MIPS_DEBUGGING_INFO
3976 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3977 get a value of 0. Putting .align 0 after the label fixes it. */
3978 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3981 /* Turn off app to make assembly quicker. */
3986 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3989 dwarf2out_do_cfi_startproc (bool second)
3993 rtx personality = get_personality_function (current_function_decl);
3995 fprintf (asm_out_file, "\t.cfi_startproc\n");
3999 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4002 /* ??? The GAS support isn't entirely consistent. We have to
4003 handle indirect support ourselves, but PC-relative is done
4004 in the assembler. Further, the assembler can't handle any
4005 of the weirder relocation types. */
4006 if (enc & DW_EH_PE_indirect)
4007 ref = dw2_force_const_mem (ref, true);
4009 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4010 output_addr_const (asm_out_file, ref);
4011 fputc ('\n', asm_out_file);
4014 if (crtl->uses_eh_lsda)
4018 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4019 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4020 current_function_funcdef_no);
4021 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4022 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4024 if (enc & DW_EH_PE_indirect)
4025 ref = dw2_force_const_mem (ref, true);
4027 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4028 output_addr_const (asm_out_file, ref);
4029 fputc ('\n', asm_out_file);
4033 /* Output a marker (i.e. a label) for the beginning of a function, before
4037 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4038 const char *file ATTRIBUTE_UNUSED)
4040 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4046 current_function_func_begin_label = NULL;
4048 do_frame = dwarf2out_do_frame ();
4050 /* ??? current_function_func_begin_label is also used by except.c for
4051 call-site information. We must emit this label if it might be used. */
4053 && (!flag_exceptions
4054 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4057 fnsec = function_section (current_function_decl);
4058 switch_to_section (fnsec);
4059 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4060 current_function_funcdef_no);
4061 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4062 current_function_funcdef_no);
4063 dup_label = xstrdup (label);
4064 current_function_func_begin_label = dup_label;
4066 /* We can elide the fde allocation if we're not emitting debug info. */
4070 /* Expand the fde table if necessary. */
4071 if (fde_table_in_use == fde_table_allocated)
4073 fde_table_allocated += FDE_TABLE_INCREMENT;
4074 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4075 memset (fde_table + fde_table_in_use, 0,
4076 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4079 /* Record the FDE associated with this function. */
4080 current_funcdef_fde = fde_table_in_use;
4082 /* Add the new FDE at the end of the fde_table. */
4083 fde = &fde_table[fde_table_in_use++];
4084 fde->decl = current_function_decl;
4085 fde->dw_fde_begin = dup_label;
4086 fde->dw_fde_end = NULL;
4087 fde->dw_fde_current_label = dup_label;
4088 fde->dw_fde_second_begin = NULL;
4089 fde->dw_fde_second_end = NULL;
4090 fde->dw_fde_vms_end_prologue = NULL;
4091 fde->dw_fde_vms_begin_epilogue = NULL;
4092 fde->dw_fde_cfi = NULL;
4093 fde->dw_fde_switch_cfi = NULL;
4094 fde->funcdef_number = current_function_funcdef_no;
4095 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4096 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4097 fde->nothrow = crtl->nothrow;
4098 fde->drap_reg = INVALID_REGNUM;
4099 fde->vdrap_reg = INVALID_REGNUM;
4100 fde->in_std_section = (fnsec == text_section
4101 || (cold_text_section && fnsec == cold_text_section));
4102 fde->second_in_std_section = 0;
4104 args_size = old_args_size = 0;
4106 /* We only want to output line number information for the genuine dwarf2
4107 prologue case, not the eh frame case. */
4108 #ifdef DWARF2_DEBUGGING_INFO
4110 dwarf2out_source_line (line, file, 0, true);
4113 if (dwarf2out_do_cfi_asm ())
4114 dwarf2out_do_cfi_startproc (false);
4117 rtx personality = get_personality_function (current_function_decl);
4118 if (!current_unit_personality)
4119 current_unit_personality = personality;
4121 /* We cannot keep a current personality per function as without CFI
4122 asm, at the point where we emit the CFI data, there is no current
4123 function anymore. */
4124 if (personality && current_unit_personality != personality)
4125 sorry ("multiple EH personalities are supported only with assemblers "
4126 "supporting .cfi_personality directive");
4130 /* Output a marker (i.e. a label) for the end of the generated code
4131 for a function prologue. This gets called *after* the prologue code has
4135 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4136 const char *file ATTRIBUTE_UNUSED)
4139 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4141 /* Output a label to mark the endpoint of the code generated for this
4143 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4144 current_function_funcdef_no);
4145 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4146 current_function_funcdef_no);
4147 fde = &fde_table[fde_table_in_use - 1];
4148 fde->dw_fde_vms_end_prologue = xstrdup (label);
4151 /* Output a marker (i.e. a label) for the beginning of the generated code
4152 for a function epilogue. This gets called *before* the prologue code has
4156 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4157 const char *file ATTRIBUTE_UNUSED)
4160 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4162 fde = &fde_table[fde_table_in_use - 1];
4163 if (fde->dw_fde_vms_begin_epilogue)
4166 /* Output a label to mark the endpoint of the code generated for this
4168 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4169 current_function_funcdef_no);
4170 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4171 current_function_funcdef_no);
4172 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4175 /* Output a marker (i.e. a label) for the absolute end of the generated code
4176 for a function definition. This gets called *after* the epilogue code has
4180 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4181 const char *file ATTRIBUTE_UNUSED)
4184 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4186 last_var_location_insn = NULL_RTX;
4188 if (dwarf2out_do_cfi_asm ())
4189 fprintf (asm_out_file, "\t.cfi_endproc\n");
4191 /* Output a label to mark the endpoint of the code generated for this
4193 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4194 current_function_funcdef_no);
4195 ASM_OUTPUT_LABEL (asm_out_file, label);
4196 fde = current_fde ();
4197 gcc_assert (fde != NULL);
4198 if (fde->dw_fde_second_begin == NULL)
4199 fde->dw_fde_end = xstrdup (label);
4203 dwarf2out_frame_init (void)
4205 /* Allocate the initial hunk of the fde_table. */
4206 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4207 fde_table_allocated = FDE_TABLE_INCREMENT;
4208 fde_table_in_use = 0;
4210 /* Generate the CFA instructions common to all FDE's. Do it now for the
4211 sake of lookup_cfa. */
4213 /* On entry, the Canonical Frame Address is at SP. */
4214 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4216 if (targetm.debug_unwind_info () == UI_DWARF2
4217 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4218 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4222 dwarf2out_frame_finish (void)
4224 /* Output call frame information. */
4225 if (targetm.debug_unwind_info () == UI_DWARF2)
4226 output_call_frame_info (0);
4228 /* Output another copy for the unwinder. */
4229 if ((flag_unwind_tables || flag_exceptions)
4230 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4231 output_call_frame_info (1);
4234 /* Note that the current function section is being used for code. */
4237 dwarf2out_note_section_used (void)
4239 section *sec = current_function_section ();
4240 if (sec == text_section)
4241 text_section_used = true;
4242 else if (sec == cold_text_section)
4243 cold_text_section_used = true;
4246 static void var_location_switch_text_section (void);
4247 static void set_cur_line_info_table (section *);
4250 dwarf2out_switch_text_section (void)
4253 dw_fde_ref fde = current_fde ();
4256 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4258 if (!in_cold_section_p)
4260 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4261 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4262 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4266 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4267 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4268 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4270 have_multiple_function_sections = true;
4272 /* Reset the current label on switching text sections, so that we
4273 don't attempt to advance_loc4 between labels in different sections. */
4274 fde->dw_fde_current_label = NULL;
4276 /* There is no need to mark used sections when not debugging. */
4277 if (cold_text_section != NULL)
4278 dwarf2out_note_section_used ();
4280 if (dwarf2out_do_cfi_asm ())
4281 fprintf (asm_out_file, "\t.cfi_endproc\n");
4283 /* Now do the real section switch. */
4284 sect = current_function_section ();
4285 switch_to_section (sect);
4287 fde->second_in_std_section
4288 = (sect == text_section
4289 || (cold_text_section && sect == cold_text_section));
4291 if (dwarf2out_do_cfi_asm ())
4293 dwarf2out_do_cfi_startproc (true);
4294 /* As this is a different FDE, insert all current CFI instructions
4296 output_cfis (fde->dw_fde_cfi, true, fde, true);
4298 cfi = fde->dw_fde_cfi;
4300 while (cfi->dw_cfi_next != NULL)
4301 cfi = cfi->dw_cfi_next;
4302 fde->dw_fde_switch_cfi = cfi;
4303 var_location_switch_text_section ();
4305 set_cur_line_info_table (sect);
4308 /* And now, the subset of the debugging information support code necessary
4309 for emitting location expressions. */
4311 /* Data about a single source file. */
4312 struct GTY(()) dwarf_file_data {
4313 const char * filename;
4317 typedef struct dw_val_struct *dw_val_ref;
4318 typedef struct die_struct *dw_die_ref;
4319 typedef const struct die_struct *const_dw_die_ref;
4320 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4321 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4323 typedef struct GTY(()) deferred_locations_struct
4327 } deferred_locations;
4329 DEF_VEC_O(deferred_locations);
4330 DEF_VEC_ALLOC_O(deferred_locations,gc);
4332 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4334 DEF_VEC_P(dw_die_ref);
4335 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4337 /* Each DIE may have a series of attribute/value pairs. Values
4338 can take on several forms. The forms that are used in this
4339 implementation are listed below. */
4344 dw_val_class_offset,
4346 dw_val_class_loc_list,
4347 dw_val_class_range_list,
4349 dw_val_class_unsigned_const,
4350 dw_val_class_const_double,
4353 dw_val_class_die_ref,
4354 dw_val_class_fde_ref,
4355 dw_val_class_lbl_id,
4356 dw_val_class_lineptr,
4358 dw_val_class_macptr,
4361 dw_val_class_decl_ref,
4362 dw_val_class_vms_delta
4365 /* Describe a floating point constant value, or a vector constant value. */
4367 typedef struct GTY(()) dw_vec_struct {
4368 unsigned char * GTY((length ("%h.length"))) array;
4374 /* The dw_val_node describes an attribute's value, as it is
4375 represented internally. */
4377 typedef struct GTY(()) dw_val_struct {
4378 enum dw_val_class val_class;
4379 union dw_val_struct_union
4381 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4382 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4383 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4384 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4385 HOST_WIDE_INT GTY ((default)) val_int;
4386 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4387 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4388 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4389 struct dw_val_die_union
4393 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4394 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4395 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4396 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4397 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4398 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4399 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4400 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4401 struct dw_val_vms_delta_union
4405 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4407 GTY ((desc ("%1.val_class"))) v;
4411 /* Locations in memory are described using a sequence of stack machine
4414 typedef struct GTY(()) dw_loc_descr_struct {
4415 dw_loc_descr_ref dw_loc_next;
4416 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4417 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4418 from DW_OP_addr with a dtp-relative symbol relocation. */
4419 unsigned int dtprel : 1;
4421 dw_val_node dw_loc_oprnd1;
4422 dw_val_node dw_loc_oprnd2;
4426 /* Location lists are ranges + location descriptions for that range,
4427 so you can track variables that are in different places over
4428 their entire life. */
4429 typedef struct GTY(()) dw_loc_list_struct {
4430 dw_loc_list_ref dw_loc_next;
4431 const char *begin; /* Label for begin address of range */
4432 const char *end; /* Label for end address of range */
4433 char *ll_symbol; /* Label for beginning of location list.
4434 Only on head of list */
4435 const char *section; /* Section this loclist is relative to */
4436 dw_loc_descr_ref expr;
4438 /* True if all addresses in this and subsequent lists are known to be
4441 /* True if this list has been replaced by dw_loc_next. */
4446 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4448 /* Convert a DWARF stack opcode into its string name. */
4451 dwarf_stack_op_name (unsigned int op)
4456 return "DW_OP_addr";
4458 return "DW_OP_deref";
4460 return "DW_OP_const1u";
4462 return "DW_OP_const1s";
4464 return "DW_OP_const2u";
4466 return "DW_OP_const2s";
4468 return "DW_OP_const4u";
4470 return "DW_OP_const4s";
4472 return "DW_OP_const8u";
4474 return "DW_OP_const8s";
4476 return "DW_OP_constu";
4478 return "DW_OP_consts";
4482 return "DW_OP_drop";
4484 return "DW_OP_over";
4486 return "DW_OP_pick";
4488 return "DW_OP_swap";
4492 return "DW_OP_xderef";
4500 return "DW_OP_minus";
4512 return "DW_OP_plus";
4513 case DW_OP_plus_uconst:
4514 return "DW_OP_plus_uconst";
4520 return "DW_OP_shra";
4538 return "DW_OP_skip";
4540 return "DW_OP_lit0";
4542 return "DW_OP_lit1";
4544 return "DW_OP_lit2";
4546 return "DW_OP_lit3";
4548 return "DW_OP_lit4";
4550 return "DW_OP_lit5";
4552 return "DW_OP_lit6";
4554 return "DW_OP_lit7";
4556 return "DW_OP_lit8";
4558 return "DW_OP_lit9";
4560 return "DW_OP_lit10";
4562 return "DW_OP_lit11";
4564 return "DW_OP_lit12";
4566 return "DW_OP_lit13";
4568 return "DW_OP_lit14";
4570 return "DW_OP_lit15";
4572 return "DW_OP_lit16";
4574 return "DW_OP_lit17";
4576 return "DW_OP_lit18";
4578 return "DW_OP_lit19";
4580 return "DW_OP_lit20";
4582 return "DW_OP_lit21";
4584 return "DW_OP_lit22";
4586 return "DW_OP_lit23";
4588 return "DW_OP_lit24";
4590 return "DW_OP_lit25";
4592 return "DW_OP_lit26";
4594 return "DW_OP_lit27";
4596 return "DW_OP_lit28";
4598 return "DW_OP_lit29";
4600 return "DW_OP_lit30";
4602 return "DW_OP_lit31";
4604 return "DW_OP_reg0";
4606 return "DW_OP_reg1";
4608 return "DW_OP_reg2";
4610 return "DW_OP_reg3";
4612 return "DW_OP_reg4";
4614 return "DW_OP_reg5";
4616 return "DW_OP_reg6";
4618 return "DW_OP_reg7";
4620 return "DW_OP_reg8";
4622 return "DW_OP_reg9";
4624 return "DW_OP_reg10";
4626 return "DW_OP_reg11";
4628 return "DW_OP_reg12";
4630 return "DW_OP_reg13";
4632 return "DW_OP_reg14";
4634 return "DW_OP_reg15";
4636 return "DW_OP_reg16";
4638 return "DW_OP_reg17";
4640 return "DW_OP_reg18";
4642 return "DW_OP_reg19";
4644 return "DW_OP_reg20";
4646 return "DW_OP_reg21";
4648 return "DW_OP_reg22";
4650 return "DW_OP_reg23";
4652 return "DW_OP_reg24";
4654 return "DW_OP_reg25";
4656 return "DW_OP_reg26";
4658 return "DW_OP_reg27";
4660 return "DW_OP_reg28";
4662 return "DW_OP_reg29";
4664 return "DW_OP_reg30";
4666 return "DW_OP_reg31";
4668 return "DW_OP_breg0";
4670 return "DW_OP_breg1";
4672 return "DW_OP_breg2";
4674 return "DW_OP_breg3";
4676 return "DW_OP_breg4";
4678 return "DW_OP_breg5";
4680 return "DW_OP_breg6";
4682 return "DW_OP_breg7";
4684 return "DW_OP_breg8";
4686 return "DW_OP_breg9";
4688 return "DW_OP_breg10";
4690 return "DW_OP_breg11";
4692 return "DW_OP_breg12";
4694 return "DW_OP_breg13";
4696 return "DW_OP_breg14";
4698 return "DW_OP_breg15";
4700 return "DW_OP_breg16";
4702 return "DW_OP_breg17";
4704 return "DW_OP_breg18";
4706 return "DW_OP_breg19";
4708 return "DW_OP_breg20";
4710 return "DW_OP_breg21";
4712 return "DW_OP_breg22";
4714 return "DW_OP_breg23";
4716 return "DW_OP_breg24";
4718 return "DW_OP_breg25";
4720 return "DW_OP_breg26";
4722 return "DW_OP_breg27";
4724 return "DW_OP_breg28";
4726 return "DW_OP_breg29";
4728 return "DW_OP_breg30";
4730 return "DW_OP_breg31";
4732 return "DW_OP_regx";
4734 return "DW_OP_fbreg";
4736 return "DW_OP_bregx";
4738 return "DW_OP_piece";
4739 case DW_OP_deref_size:
4740 return "DW_OP_deref_size";
4741 case DW_OP_xderef_size:
4742 return "DW_OP_xderef_size";
4746 case DW_OP_push_object_address:
4747 return "DW_OP_push_object_address";
4749 return "DW_OP_call2";
4751 return "DW_OP_call4";
4752 case DW_OP_call_ref:
4753 return "DW_OP_call_ref";
4754 case DW_OP_implicit_value:
4755 return "DW_OP_implicit_value";
4756 case DW_OP_stack_value:
4757 return "DW_OP_stack_value";
4758 case DW_OP_form_tls_address:
4759 return "DW_OP_form_tls_address";
4760 case DW_OP_call_frame_cfa:
4761 return "DW_OP_call_frame_cfa";
4762 case DW_OP_bit_piece:
4763 return "DW_OP_bit_piece";
4765 case DW_OP_GNU_push_tls_address:
4766 return "DW_OP_GNU_push_tls_address";
4767 case DW_OP_GNU_uninit:
4768 return "DW_OP_GNU_uninit";
4769 case DW_OP_GNU_encoded_addr:
4770 return "DW_OP_GNU_encoded_addr";
4771 case DW_OP_GNU_implicit_pointer:
4772 return "DW_OP_GNU_implicit_pointer";
4773 case DW_OP_GNU_entry_value:
4774 return "DW_OP_GNU_entry_value";
4777 return "OP_<unknown>";
4781 /* Return a pointer to a newly allocated location description. Location
4782 descriptions are simple expression terms that can be strung
4783 together to form more complicated location (address) descriptions. */
4785 static inline dw_loc_descr_ref
4786 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4787 unsigned HOST_WIDE_INT oprnd2)
4789 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4791 descr->dw_loc_opc = op;
4792 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4793 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4794 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4795 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4800 /* Return a pointer to a newly allocated location description for
4803 static inline dw_loc_descr_ref
4804 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4807 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4810 return new_loc_descr (DW_OP_bregx, reg, offset);
4813 /* Add a location description term to a location description expression. */
4816 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4818 dw_loc_descr_ref *d;
4820 /* Find the end of the chain. */
4821 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4827 /* Add a constant OFFSET to a location expression. */
4830 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4832 dw_loc_descr_ref loc;
4835 gcc_assert (*list_head != NULL);
4840 /* Find the end of the chain. */
4841 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4845 if (loc->dw_loc_opc == DW_OP_fbreg
4846 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4847 p = &loc->dw_loc_oprnd1.v.val_int;
4848 else if (loc->dw_loc_opc == DW_OP_bregx)
4849 p = &loc->dw_loc_oprnd2.v.val_int;
4851 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4852 offset. Don't optimize if an signed integer overflow would happen. */
4854 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4855 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4858 else if (offset > 0)
4859 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4863 loc->dw_loc_next = int_loc_descriptor (-offset);
4864 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4868 /* Add a constant OFFSET to a location list. */
4871 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4874 for (d = list_head; d != NULL; d = d->dw_loc_next)
4875 loc_descr_plus_const (&d->expr, offset);
4878 #define DWARF_REF_SIZE \
4879 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4881 static unsigned long size_of_locs (dw_loc_descr_ref);
4883 /* Return the size of a location descriptor. */
4885 static unsigned long
4886 size_of_loc_descr (dw_loc_descr_ref loc)
4888 unsigned long size = 1;
4890 switch (loc->dw_loc_opc)
4893 size += DWARF2_ADDR_SIZE;
4912 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4915 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4920 case DW_OP_plus_uconst:
4921 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4959 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4962 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4965 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4968 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4969 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4972 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4974 case DW_OP_bit_piece:
4975 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4976 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4978 case DW_OP_deref_size:
4979 case DW_OP_xderef_size:
4988 case DW_OP_call_ref:
4989 size += DWARF_REF_SIZE;
4991 case DW_OP_implicit_value:
4992 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4993 + loc->dw_loc_oprnd1.v.val_unsigned;
4995 case DW_OP_GNU_implicit_pointer:
4996 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4998 case DW_OP_GNU_entry_value:
5000 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5001 size += size_of_uleb128 (op_size) + op_size;
5011 /* Return the size of a series of location descriptors. */
5013 static unsigned long
5014 size_of_locs (dw_loc_descr_ref loc)
5019 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5020 field, to avoid writing to a PCH file. */
5021 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5023 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5025 size += size_of_loc_descr (l);
5030 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5032 l->dw_loc_addr = size;
5033 size += size_of_loc_descr (l);
5039 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5040 static void get_ref_die_offset_label (char *, dw_die_ref);
5041 static void output_loc_sequence (dw_loc_descr_ref, int);
5043 /* Output location description stack opcode's operands (if any).
5044 The for_eh_or_skip parameter controls whether register numbers are
5045 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5046 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5047 info). This should be suppressed for the cases that have not been converted
5048 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5051 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5053 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5054 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5056 switch (loc->dw_loc_opc)
5058 #ifdef DWARF2_DEBUGGING_INFO
5061 dw2_asm_output_data (2, val1->v.val_int, NULL);
5066 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5067 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5069 fputc ('\n', asm_out_file);
5074 dw2_asm_output_data (4, val1->v.val_int, NULL);
5079 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5080 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5082 fputc ('\n', asm_out_file);
5087 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5088 dw2_asm_output_data (8, val1->v.val_int, NULL);
5095 gcc_assert (val1->val_class == dw_val_class_loc);
5096 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5098 dw2_asm_output_data (2, offset, NULL);
5101 case DW_OP_implicit_value:
5102 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5103 switch (val2->val_class)
5105 case dw_val_class_const:
5106 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5108 case dw_val_class_vec:
5110 unsigned int elt_size = val2->v.val_vec.elt_size;
5111 unsigned int len = val2->v.val_vec.length;
5115 if (elt_size > sizeof (HOST_WIDE_INT))
5120 for (i = 0, p = val2->v.val_vec.array;
5123 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5124 "fp or vector constant word %u", i);
5127 case dw_val_class_const_double:
5129 unsigned HOST_WIDE_INT first, second;
5131 if (WORDS_BIG_ENDIAN)
5133 first = val2->v.val_double.high;
5134 second = val2->v.val_double.low;
5138 first = val2->v.val_double.low;
5139 second = val2->v.val_double.high;
5141 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5143 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5147 case dw_val_class_addr:
5148 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5149 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5164 case DW_OP_implicit_value:
5165 /* We currently don't make any attempt to make sure these are
5166 aligned properly like we do for the main unwind info, so
5167 don't support emitting things larger than a byte if we're
5168 only doing unwinding. */
5173 dw2_asm_output_data (1, val1->v.val_int, NULL);
5176 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5179 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5182 dw2_asm_output_data (1, val1->v.val_int, NULL);
5184 case DW_OP_plus_uconst:
5185 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5219 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5223 unsigned r = val1->v.val_unsigned;
5224 if (for_eh_or_skip >= 0)
5225 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5226 gcc_assert (size_of_uleb128 (r)
5227 == size_of_uleb128 (val1->v.val_unsigned));
5228 dw2_asm_output_data_uleb128 (r, NULL);
5232 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5236 unsigned r = val1->v.val_unsigned;
5237 if (for_eh_or_skip >= 0)
5238 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5239 gcc_assert (size_of_uleb128 (r)
5240 == size_of_uleb128 (val1->v.val_unsigned));
5241 dw2_asm_output_data_uleb128 (r, NULL);
5242 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5246 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5248 case DW_OP_bit_piece:
5249 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5250 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5252 case DW_OP_deref_size:
5253 case DW_OP_xderef_size:
5254 dw2_asm_output_data (1, val1->v.val_int, NULL);
5260 if (targetm.asm_out.output_dwarf_dtprel)
5262 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5265 fputc ('\n', asm_out_file);
5272 #ifdef DWARF2_DEBUGGING_INFO
5273 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5280 case DW_OP_GNU_implicit_pointer:
5282 char label[MAX_ARTIFICIAL_LABEL_BYTES
5283 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5284 gcc_assert (val1->val_class == dw_val_class_die_ref);
5285 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5286 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5287 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5291 case DW_OP_GNU_entry_value:
5292 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5293 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5297 /* Other codes have no operands. */
5302 /* Output a sequence of location operations.
5303 The for_eh_or_skip parameter controls whether register numbers are
5304 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5305 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5306 info). This should be suppressed for the cases that have not been converted
5307 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5310 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5312 for (; loc != NULL; loc = loc->dw_loc_next)
5314 enum dwarf_location_atom opc = loc->dw_loc_opc;
5315 /* Output the opcode. */
5316 if (for_eh_or_skip >= 0
5317 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5319 unsigned r = (opc - DW_OP_breg0);
5320 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5321 gcc_assert (r <= 31);
5322 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5324 else if (for_eh_or_skip >= 0
5325 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5327 unsigned r = (opc - DW_OP_reg0);
5328 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5329 gcc_assert (r <= 31);
5330 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5333 dw2_asm_output_data (1, opc,
5334 "%s", dwarf_stack_op_name (opc));
5336 /* Output the operand(s) (if any). */
5337 output_loc_operands (loc, for_eh_or_skip);
5341 /* Output location description stack opcode's operands (if any).
5342 The output is single bytes on a line, suitable for .cfi_escape. */
5345 output_loc_operands_raw (dw_loc_descr_ref loc)
5347 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5348 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5350 switch (loc->dw_loc_opc)
5353 case DW_OP_implicit_value:
5354 /* We cannot output addresses in .cfi_escape, only bytes. */
5360 case DW_OP_deref_size:
5361 case DW_OP_xderef_size:
5362 fputc (',', asm_out_file);
5363 dw2_asm_output_data_raw (1, val1->v.val_int);
5368 fputc (',', asm_out_file);
5369 dw2_asm_output_data_raw (2, val1->v.val_int);
5374 fputc (',', asm_out_file);
5375 dw2_asm_output_data_raw (4, val1->v.val_int);
5380 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5381 fputc (',', asm_out_file);
5382 dw2_asm_output_data_raw (8, val1->v.val_int);
5390 gcc_assert (val1->val_class == dw_val_class_loc);
5391 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5393 fputc (',', asm_out_file);
5394 dw2_asm_output_data_raw (2, offset);
5400 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5401 gcc_assert (size_of_uleb128 (r)
5402 == size_of_uleb128 (val1->v.val_unsigned));
5403 fputc (',', asm_out_file);
5404 dw2_asm_output_data_uleb128_raw (r);
5409 case DW_OP_plus_uconst:
5411 fputc (',', asm_out_file);
5412 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5415 case DW_OP_bit_piece:
5416 fputc (',', asm_out_file);
5417 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5418 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5455 fputc (',', asm_out_file);
5456 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5461 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5462 gcc_assert (size_of_uleb128 (r)
5463 == size_of_uleb128 (val1->v.val_unsigned));
5464 fputc (',', asm_out_file);
5465 dw2_asm_output_data_uleb128_raw (r);
5466 fputc (',', asm_out_file);
5467 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5471 case DW_OP_GNU_implicit_pointer:
5472 case DW_OP_GNU_entry_value:
5477 /* Other codes have no operands. */
5483 output_loc_sequence_raw (dw_loc_descr_ref loc)
5487 enum dwarf_location_atom opc = loc->dw_loc_opc;
5488 /* Output the opcode. */
5489 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5491 unsigned r = (opc - DW_OP_breg0);
5492 r = DWARF2_FRAME_REG_OUT (r, 1);
5493 gcc_assert (r <= 31);
5494 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5496 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5498 unsigned r = (opc - DW_OP_reg0);
5499 r = DWARF2_FRAME_REG_OUT (r, 1);
5500 gcc_assert (r <= 31);
5501 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5503 /* Output the opcode. */
5504 fprintf (asm_out_file, "%#x", opc);
5505 output_loc_operands_raw (loc);
5507 if (!loc->dw_loc_next)
5509 loc = loc->dw_loc_next;
5511 fputc (',', asm_out_file);
5515 /* This routine will generate the correct assembly data for a location
5516 description based on a cfi entry with a complex address. */
5519 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5521 dw_loc_descr_ref loc;
5524 if (cfi->dw_cfi_opc == DW_CFA_expression)
5527 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5528 dw2_asm_output_data (1, r, NULL);
5529 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5532 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5534 /* Output the size of the block. */
5535 size = size_of_locs (loc);
5536 dw2_asm_output_data_uleb128 (size, NULL);
5538 /* Now output the operations themselves. */
5539 output_loc_sequence (loc, for_eh);
5542 /* Similar, but used for .cfi_escape. */
5545 output_cfa_loc_raw (dw_cfi_ref cfi)
5547 dw_loc_descr_ref loc;
5550 if (cfi->dw_cfi_opc == DW_CFA_expression)
5553 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5554 fprintf (asm_out_file, "%#x,", r);
5555 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5558 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5560 /* Output the size of the block. */
5561 size = size_of_locs (loc);
5562 dw2_asm_output_data_uleb128_raw (size);
5563 fputc (',', asm_out_file);
5565 /* Now output the operations themselves. */
5566 output_loc_sequence_raw (loc);
5569 /* This function builds a dwarf location descriptor sequence from a
5570 dw_cfa_location, adding the given OFFSET to the result of the
5573 static struct dw_loc_descr_struct *
5574 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5576 struct dw_loc_descr_struct *head, *tmp;
5578 offset += cfa->offset;
5582 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5583 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5584 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5585 add_loc_descr (&head, tmp);
5588 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5589 add_loc_descr (&head, tmp);
5593 head = new_reg_loc_descr (cfa->reg, offset);
5598 /* This function builds a dwarf location descriptor sequence for
5599 the address at OFFSET from the CFA when stack is aligned to
5602 static struct dw_loc_descr_struct *
5603 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5605 struct dw_loc_descr_struct *head;
5606 unsigned int dwarf_fp
5607 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5609 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5610 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5612 head = new_reg_loc_descr (dwarf_fp, 0);
5613 add_loc_descr (&head, int_loc_descriptor (alignment));
5614 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5615 loc_descr_plus_const (&head, offset);
5618 head = new_reg_loc_descr (dwarf_fp, offset);
5622 /* This function fills in aa dw_cfa_location structure from a dwarf location
5623 descriptor sequence. */
5626 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5628 struct dw_loc_descr_struct *ptr;
5630 cfa->base_offset = 0;
5634 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5636 enum dwarf_location_atom op = ptr->dw_loc_opc;
5672 cfa->reg = op - DW_OP_reg0;
5675 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5709 cfa->reg = op - DW_OP_breg0;
5710 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5713 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5714 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5719 case DW_OP_plus_uconst:
5720 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5723 internal_error ("DW_LOC_OP %s not implemented",
5724 dwarf_stack_op_name (ptr->dw_loc_opc));
5729 /* And now, the support for symbolic debugging information. */
5731 /* .debug_str support. */
5732 static int output_indirect_string (void **, void *);
5734 static void dwarf2out_init (const char *);
5735 static void dwarf2out_finish (const char *);
5736 static void dwarf2out_assembly_start (void);
5737 static void dwarf2out_define (unsigned int, const char *);
5738 static void dwarf2out_undef (unsigned int, const char *);
5739 static void dwarf2out_start_source_file (unsigned, const char *);
5740 static void dwarf2out_end_source_file (unsigned);
5741 static void dwarf2out_function_decl (tree);
5742 static void dwarf2out_begin_block (unsigned, unsigned);
5743 static void dwarf2out_end_block (unsigned, unsigned);
5744 static bool dwarf2out_ignore_block (const_tree);
5745 static void dwarf2out_global_decl (tree);
5746 static void dwarf2out_type_decl (tree, int);
5747 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5748 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5750 static void dwarf2out_abstract_function (tree);
5751 static void dwarf2out_var_location (rtx);
5752 static void dwarf2out_begin_function (tree);
5753 static void dwarf2out_set_name (tree, tree);
5755 /* The debug hooks structure. */
5757 const struct gcc_debug_hooks dwarf2_debug_hooks =
5761 dwarf2out_assembly_start,
5764 dwarf2out_start_source_file,
5765 dwarf2out_end_source_file,
5766 dwarf2out_begin_block,
5767 dwarf2out_end_block,
5768 dwarf2out_ignore_block,
5769 dwarf2out_source_line,
5770 dwarf2out_begin_prologue,
5771 #if VMS_DEBUGGING_INFO
5772 dwarf2out_vms_end_prologue,
5773 dwarf2out_vms_begin_epilogue,
5775 debug_nothing_int_charstar,
5776 debug_nothing_int_charstar,
5778 dwarf2out_end_epilogue,
5779 dwarf2out_begin_function,
5780 debug_nothing_int, /* end_function */
5781 dwarf2out_function_decl, /* function_decl */
5782 dwarf2out_global_decl,
5783 dwarf2out_type_decl, /* type_decl */
5784 dwarf2out_imported_module_or_decl,
5785 debug_nothing_tree, /* deferred_inline_function */
5786 /* The DWARF 2 backend tries to reduce debugging bloat by not
5787 emitting the abstract description of inline functions until
5788 something tries to reference them. */
5789 dwarf2out_abstract_function, /* outlining_inline_function */
5790 debug_nothing_rtx, /* label */
5791 debug_nothing_int, /* handle_pch */
5792 dwarf2out_var_location,
5793 dwarf2out_switch_text_section,
5795 1, /* start_end_main_source_file */
5796 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5799 /* NOTE: In the comments in this file, many references are made to
5800 "Debugging Information Entries". This term is abbreviated as `DIE'
5801 throughout the remainder of this file. */
5803 /* An internal representation of the DWARF output is built, and then
5804 walked to generate the DWARF debugging info. The walk of the internal
5805 representation is done after the entire program has been compiled.
5806 The types below are used to describe the internal representation. */
5808 /* Whether to put type DIEs into their own section .debug_types instead
5809 of making them part of the .debug_info section. Only supported for
5810 Dwarf V4 or higher and the user didn't disable them through
5811 -fno-debug-types-section. It is more efficient to put them in a
5812 separate comdat sections since the linker will then be able to
5813 remove duplicates. But not all tools support .debug_types sections
5816 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
5818 /* Various DIE's use offsets relative to the beginning of the
5819 .debug_info section to refer to each other. */
5821 typedef long int dw_offset;
5823 /* Define typedefs here to avoid circular dependencies. */
5825 typedef struct dw_attr_struct *dw_attr_ref;
5826 typedef struct dw_line_info_struct *dw_line_info_ref;
5827 typedef struct pubname_struct *pubname_ref;
5828 typedef struct dw_ranges_struct *dw_ranges_ref;
5829 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5830 typedef struct comdat_type_struct *comdat_type_node_ref;
5832 /* The entries in the line_info table more-or-less mirror the opcodes
5833 that are used in the real dwarf line table. Arrays of these entries
5834 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
5837 enum dw_line_info_opcode {
5838 /* Emit DW_LNE_set_address; the operand is the label index. */
5841 /* Emit a row to the matrix with the given line. This may be done
5842 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
5846 /* Emit a DW_LNS_set_file. */
5849 /* Emit a DW_LNS_set_column. */
5852 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
5855 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
5856 LI_set_prologue_end,
5857 LI_set_epilogue_begin,
5859 /* Emit a DW_LNE_set_discriminator. */
5860 LI_set_discriminator
5863 typedef struct GTY(()) dw_line_info_struct {
5864 enum dw_line_info_opcode opcode;
5866 } dw_line_info_entry;
5868 DEF_VEC_O(dw_line_info_entry);
5869 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
5871 typedef struct GTY(()) dw_line_info_table_struct {
5872 /* The label that marks the end of this section. */
5873 const char *end_label;
5875 /* The values for the last row of the matrix, as collected in the table.
5876 These are used to minimize the changes to the next row. */
5877 unsigned int file_num;
5878 unsigned int line_num;
5879 unsigned int column_num;
5884 VEC(dw_line_info_entry, gc) *entries;
5885 } dw_line_info_table;
5887 typedef dw_line_info_table *dw_line_info_table_p;
5889 DEF_VEC_P(dw_line_info_table_p);
5890 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
5892 /* Each DIE attribute has a field specifying the attribute kind,
5893 a link to the next attribute in the chain, and an attribute value.
5894 Attributes are typically linked below the DIE they modify. */
5896 typedef struct GTY(()) dw_attr_struct {
5897 enum dwarf_attribute dw_attr;
5898 dw_val_node dw_attr_val;
5902 DEF_VEC_O(dw_attr_node);
5903 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5905 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5906 The children of each node form a circular list linked by
5907 die_sib. die_child points to the node *before* the "first" child node. */
5909 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5910 union die_symbol_or_type_node
5912 char * GTY ((tag ("0"))) die_symbol;
5913 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5915 GTY ((desc ("use_debug_types"))) die_id;
5916 VEC(dw_attr_node,gc) * die_attr;
5917 dw_die_ref die_parent;
5918 dw_die_ref die_child;
5920 dw_die_ref die_definition; /* ref from a specification to its definition */
5921 dw_offset die_offset;
5922 unsigned long die_abbrev;
5924 /* Die is used and must not be pruned as unused. */
5925 int die_perennial_p;
5926 unsigned int decl_id;
5927 enum dwarf_tag die_tag;
5931 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5932 #define FOR_EACH_CHILD(die, c, expr) do { \
5933 c = die->die_child; \
5937 } while (c != die->die_child); \
5940 /* The pubname structure */
5942 typedef struct GTY(()) pubname_struct {
5948 DEF_VEC_O(pubname_entry);
5949 DEF_VEC_ALLOC_O(pubname_entry, gc);
5951 struct GTY(()) dw_ranges_struct {
5952 /* If this is positive, it's a block number, otherwise it's a
5953 bitwise-negated index into dw_ranges_by_label. */
5957 /* A structure to hold a macinfo entry. */
5959 typedef struct GTY(()) macinfo_struct {
5960 unsigned HOST_WIDE_INT code;
5961 unsigned HOST_WIDE_INT lineno;
5966 DEF_VEC_O(macinfo_entry);
5967 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5969 struct GTY(()) dw_ranges_by_label_struct {
5974 /* The comdat type node structure. */
5975 typedef struct GTY(()) comdat_type_struct
5977 dw_die_ref root_die;
5978 dw_die_ref type_die;
5979 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5980 struct comdat_type_struct *next;
5984 /* The limbo die list structure. */
5985 typedef struct GTY(()) limbo_die_struct {
5988 struct limbo_die_struct *next;
5992 typedef struct skeleton_chain_struct
5996 struct skeleton_chain_struct *parent;
5998 skeleton_chain_node;
6000 /* How to start an assembler comment. */
6001 #ifndef ASM_COMMENT_START
6002 #define ASM_COMMENT_START ";#"
6005 /* Define a macro which returns nonzero for a TYPE_DECL which was
6006 implicitly generated for a tagged type.
6008 Note that unlike the gcc front end (which generates a NULL named
6009 TYPE_DECL node for each complete tagged type, each array type, and
6010 each function type node created) the g++ front end generates a
6011 _named_ TYPE_DECL node for each tagged type node created.
6012 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6013 generate a DW_TAG_typedef DIE for them. */
6015 #define TYPE_DECL_IS_STUB(decl) \
6016 (DECL_NAME (decl) == NULL_TREE \
6017 || (DECL_ARTIFICIAL (decl) \
6018 && is_tagged_type (TREE_TYPE (decl)) \
6019 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6020 /* This is necessary for stub decls that \
6021 appear in nested inline functions. */ \
6022 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6023 && (decl_ultimate_origin (decl) \
6024 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6026 /* Information concerning the compilation unit's programming
6027 language, and compiler version. */
6029 /* Fixed size portion of the DWARF compilation unit header. */
6030 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6031 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6033 /* Fixed size portion of the DWARF comdat type unit header. */
6034 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6035 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6036 + DWARF_OFFSET_SIZE)
6038 /* Fixed size portion of public names info. */
6039 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6041 /* Fixed size portion of the address range info. */
6042 #define DWARF_ARANGES_HEADER_SIZE \
6043 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6044 DWARF2_ADDR_SIZE * 2) \
6045 - DWARF_INITIAL_LENGTH_SIZE)
6047 /* Size of padding portion in the address range info. It must be
6048 aligned to twice the pointer size. */
6049 #define DWARF_ARANGES_PAD_SIZE \
6050 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6051 DWARF2_ADDR_SIZE * 2) \
6052 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6054 /* Use assembler line directives if available. */
6055 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6056 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6057 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6059 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6063 /* Minimum line offset in a special line info. opcode.
6064 This value was chosen to give a reasonable range of values. */
6065 #define DWARF_LINE_BASE -10
6067 /* First special line opcode - leave room for the standard opcodes. */
6068 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6070 /* Range of line offsets in a special line info. opcode. */
6071 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6073 /* Flag that indicates the initial value of the is_stmt_start flag.
6074 In the present implementation, we do not mark any lines as
6075 the beginning of a source statement, because that information
6076 is not made available by the GCC front-end. */
6077 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6079 /* Maximum number of operations per instruction bundle. */
6080 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6081 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6084 /* This location is used by calc_die_sizes() to keep track
6085 the offset of each DIE within the .debug_info section. */
6086 static unsigned long next_die_offset;
6088 /* Record the root of the DIE's built for the current compilation unit. */
6089 static GTY(()) dw_die_ref single_comp_unit_die;
6091 /* A list of type DIEs that have been separated into comdat sections. */
6092 static GTY(()) comdat_type_node *comdat_type_list;
6094 /* A list of DIEs with a NULL parent waiting to be relocated. */
6095 static GTY(()) limbo_die_node *limbo_die_list;
6097 /* A list of DIEs for which we may have to generate
6098 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6099 static GTY(()) limbo_die_node *deferred_asm_name;
6101 /* Filenames referenced by this compilation unit. */
6102 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6104 /* A hash table of references to DIE's that describe declarations.
6105 The key is a DECL_UID() which is a unique number identifying each decl. */
6106 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6108 /* A hash table of references to DIE's that describe COMMON blocks.
6109 The key is DECL_UID() ^ die_parent. */
6110 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6112 typedef struct GTY(()) die_arg_entry_struct {
6117 DEF_VEC_O(die_arg_entry);
6118 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6120 /* Node of the variable location list. */
6121 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6122 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6123 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6124 in mode of the EXPR_LIST node and first EXPR_LIST operand
6125 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6126 location or NULL for padding. For larger bitsizes,
6127 mode is 0 and first operand is a CONCAT with bitsize
6128 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6129 NULL as second operand. */
6131 const char * GTY (()) label;
6132 struct var_loc_node * GTY (()) next;
6135 /* Variable location list. */
6136 struct GTY (()) var_loc_list_def {
6137 struct var_loc_node * GTY (()) first;
6139 /* Pointer to the last but one or last element of the
6140 chained list. If the list is empty, both first and
6141 last are NULL, if the list contains just one node
6142 or the last node certainly is not redundant, it points
6143 to the last node, otherwise points to the last but one.
6144 Do not mark it for GC because it is marked through the chain. */
6145 struct var_loc_node * GTY ((skip ("%h"))) last;
6147 /* Pointer to the last element before section switch,
6148 if NULL, either sections weren't switched or first
6149 is after section switch. */
6150 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6152 /* DECL_UID of the variable decl. */
6153 unsigned int decl_id;
6155 typedef struct var_loc_list_def var_loc_list;
6157 /* Call argument location list. */
6158 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6159 rtx GTY (()) call_arg_loc_note;
6160 const char * GTY (()) label;
6161 tree GTY (()) block;
6163 rtx GTY (()) symbol_ref;
6164 struct call_arg_loc_node * GTY (()) next;
6168 /* Table of decl location linked lists. */
6169 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6171 /* Head and tail of call_arg_loc chain. */
6172 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6173 static struct call_arg_loc_node *call_arg_loc_last;
6175 /* Number of call sites in the current function. */
6176 static int call_site_count = -1;
6177 /* Number of tail call sites in the current function. */
6178 static int tail_call_site_count = -1;
6180 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6182 static VEC (dw_die_ref, heap) *block_map;
6184 /* A cached location list. */
6185 struct GTY (()) cached_dw_loc_list_def {
6186 /* The DECL_UID of the decl that this entry describes. */
6187 unsigned int decl_id;
6189 /* The cached location list. */
6190 dw_loc_list_ref loc_list;
6192 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6194 /* Table of cached location lists. */
6195 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6197 /* A pointer to the base of a list of references to DIE's that
6198 are uniquely identified by their tag, presence/absence of
6199 children DIE's, and list of attribute/value pairs. */
6200 static GTY((length ("abbrev_die_table_allocated")))
6201 dw_die_ref *abbrev_die_table;
6203 /* Number of elements currently allocated for abbrev_die_table. */
6204 static GTY(()) unsigned abbrev_die_table_allocated;
6206 /* Number of elements in type_die_table currently in use. */
6207 static GTY(()) unsigned abbrev_die_table_in_use;
6209 /* Size (in elements) of increments by which we may expand the
6210 abbrev_die_table. */
6211 #define ABBREV_DIE_TABLE_INCREMENT 256
6213 /* A global counter for generating labels for line number data. */
6214 static unsigned int line_info_label_num;
6216 /* The current table to which we should emit line number information
6217 for the current function. This will be set up at the beginning of
6218 assembly for the function. */
6219 static dw_line_info_table *cur_line_info_table;
6221 /* The two default tables of line number info. */
6222 static GTY(()) dw_line_info_table *text_section_line_info;
6223 static GTY(()) dw_line_info_table *cold_text_section_line_info;
6225 /* The set of all non-default tables of line number info. */
6226 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
6228 /* A flag to tell pubnames/types export if there is an info section to
6230 static bool info_section_emitted;
6232 /* A pointer to the base of a table that contains a list of publicly
6233 accessible names. */
6234 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6236 /* A pointer to the base of a table that contains a list of publicly
6237 accessible types. */
6238 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6240 /* A pointer to the base of a table that contains a list of macro
6241 defines/undefines (and file start/end markers). */
6242 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6244 /* Array of dies for which we should generate .debug_ranges info. */
6245 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6247 /* Number of elements currently allocated for ranges_table. */
6248 static GTY(()) unsigned ranges_table_allocated;
6250 /* Number of elements in ranges_table currently in use. */
6251 static GTY(()) unsigned ranges_table_in_use;
6253 /* Array of pairs of labels referenced in ranges_table. */
6254 static GTY ((length ("ranges_by_label_allocated")))
6255 dw_ranges_by_label_ref ranges_by_label;
6257 /* Number of elements currently allocated for ranges_by_label. */
6258 static GTY(()) unsigned ranges_by_label_allocated;
6260 /* Number of elements in ranges_by_label currently in use. */
6261 static GTY(()) unsigned ranges_by_label_in_use;
6263 /* Size (in elements) of increments by which we may expand the
6265 #define RANGES_TABLE_INCREMENT 64
6267 /* Whether we have location lists that need outputting */
6268 static GTY(()) bool have_location_lists;
6270 /* Unique label counter. */
6271 static GTY(()) unsigned int loclabel_num;
6273 /* Unique label counter for point-of-call tables. */
6274 static GTY(()) unsigned int poc_label_num;
6276 /* Record whether the function being analyzed contains inlined functions. */
6277 static int current_function_has_inlines;
6279 /* The last file entry emitted by maybe_emit_file(). */
6280 static GTY(()) struct dwarf_file_data * last_emitted_file;
6282 /* Number of internal labels generated by gen_internal_sym(). */
6283 static GTY(()) int label_num;
6285 /* Cached result of previous call to lookup_filename. */
6286 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6288 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6290 /* Instances of generic types for which we need to generate debug
6291 info that describe their generic parameters and arguments. That
6292 generation needs to happen once all types are properly laid out so
6293 we do it at the end of compilation. */
6294 static GTY(()) VEC(tree,gc) *generic_type_instances;
6296 /* Offset from the "steady-state frame pointer" to the frame base,
6297 within the current function. */
6298 static HOST_WIDE_INT frame_pointer_fb_offset;
6300 /* Forward declarations for functions defined in this file. */
6302 static int is_pseudo_reg (const_rtx);
6303 static tree type_main_variant (tree);
6304 static int is_tagged_type (const_tree);
6305 static const char *dwarf_tag_name (unsigned);
6306 static const char *dwarf_attr_name (unsigned);
6307 static const char *dwarf_form_name (unsigned);
6308 static tree decl_ultimate_origin (const_tree);
6309 static tree decl_class_context (tree);
6310 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6311 static inline enum dw_val_class AT_class (dw_attr_ref);
6312 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6313 static inline unsigned AT_flag (dw_attr_ref);
6314 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6315 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6316 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6317 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6318 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6319 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6320 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6321 unsigned int, unsigned char *);
6322 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6323 static hashval_t debug_str_do_hash (const void *);
6324 static int debug_str_eq (const void *, const void *);
6325 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6326 static inline const char *AT_string (dw_attr_ref);
6327 static enum dwarf_form AT_string_form (dw_attr_ref);
6328 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6329 static void add_AT_specification (dw_die_ref, dw_die_ref);
6330 static inline dw_die_ref AT_ref (dw_attr_ref);
6331 static inline int AT_ref_external (dw_attr_ref);
6332 static inline void set_AT_ref_external (dw_attr_ref, int);
6333 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6334 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6335 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6336 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6338 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6339 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6340 static inline rtx AT_addr (dw_attr_ref);
6341 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6342 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6343 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6344 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6345 unsigned HOST_WIDE_INT);
6346 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6348 static inline const char *AT_lbl (dw_attr_ref);
6349 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6350 static const char *get_AT_low_pc (dw_die_ref);
6351 static const char *get_AT_hi_pc (dw_die_ref);
6352 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6353 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6354 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6355 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6356 static bool is_cxx (void);
6357 static bool is_fortran (void);
6358 static bool is_ada (void);
6359 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6360 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6361 static void add_child_die (dw_die_ref, dw_die_ref);
6362 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6363 static dw_die_ref lookup_type_die (tree);
6364 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6365 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6366 static void equate_type_number_to_die (tree, dw_die_ref);
6367 static hashval_t decl_die_table_hash (const void *);
6368 static int decl_die_table_eq (const void *, const void *);
6369 static dw_die_ref lookup_decl_die (tree);
6370 static hashval_t common_block_die_table_hash (const void *);
6371 static int common_block_die_table_eq (const void *, const void *);
6372 static hashval_t decl_loc_table_hash (const void *);
6373 static int decl_loc_table_eq (const void *, const void *);
6374 static var_loc_list *lookup_decl_loc (const_tree);
6375 static void equate_decl_number_to_die (tree, dw_die_ref);
6376 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6377 static void print_spaces (FILE *);
6378 static void print_die (dw_die_ref, FILE *);
6379 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6380 static dw_die_ref pop_compile_unit (dw_die_ref);
6381 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6382 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6383 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6384 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6385 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6386 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6387 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6388 struct md5_ctx *, int *);
6389 struct checksum_attributes;
6390 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6391 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6392 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6393 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6394 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6395 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6396 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6397 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6398 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6399 static void compute_section_prefix (dw_die_ref);
6400 static int is_type_die (dw_die_ref);
6401 static int is_comdat_die (dw_die_ref);
6402 static int is_symbol_die (dw_die_ref);
6403 static void assign_symbol_names (dw_die_ref);
6404 static void break_out_includes (dw_die_ref);
6405 static int is_declaration_die (dw_die_ref);
6406 static int should_move_die_to_comdat (dw_die_ref);
6407 static dw_die_ref clone_as_declaration (dw_die_ref);
6408 static dw_die_ref clone_die (dw_die_ref);
6409 static dw_die_ref clone_tree (dw_die_ref);
6410 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6411 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6412 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6413 static dw_die_ref generate_skeleton (dw_die_ref);
6414 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6416 static void break_out_comdat_types (dw_die_ref);
6417 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6418 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6419 static void copy_decls_for_unworthy_types (dw_die_ref);
6421 static hashval_t htab_cu_hash (const void *);
6422 static int htab_cu_eq (const void *, const void *);
6423 static void htab_cu_del (void *);
6424 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6425 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6426 static void add_sibling_attributes (dw_die_ref);
6427 static void build_abbrev_table (dw_die_ref);
6428 static void output_location_lists (dw_die_ref);
6429 static int constant_size (unsigned HOST_WIDE_INT);
6430 static unsigned long size_of_die (dw_die_ref);
6431 static void calc_die_sizes (dw_die_ref);
6432 static void mark_dies (dw_die_ref);
6433 static void unmark_dies (dw_die_ref);
6434 static void unmark_all_dies (dw_die_ref);
6435 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6436 static unsigned long size_of_aranges (void);
6437 static enum dwarf_form value_format (dw_attr_ref);
6438 static void output_value_format (dw_attr_ref);
6439 static void output_abbrev_section (void);
6440 static void output_die_symbol (dw_die_ref);
6441 static void output_die (dw_die_ref);
6442 static void output_compilation_unit_header (void);
6443 static void output_comp_unit (dw_die_ref, int);
6444 static void output_comdat_type_unit (comdat_type_node *);
6445 static const char *dwarf2_name (tree, int);
6446 static void add_pubname (tree, dw_die_ref);
6447 static void add_pubname_string (const char *, dw_die_ref);
6448 static void add_pubtype (tree, dw_die_ref);
6449 static void output_pubnames (VEC (pubname_entry,gc) *);
6450 static void output_aranges (unsigned long);
6451 static unsigned int add_ranges_num (int);
6452 static unsigned int add_ranges (const_tree);
6453 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6455 static void output_ranges (void);
6456 static dw_line_info_table *new_line_info_table (void);
6457 static void output_line_info (void);
6458 static void output_file_names (void);
6459 static dw_die_ref base_type_die (tree);
6460 static int is_base_type (tree);
6461 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6462 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6463 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6464 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6465 static int type_is_enum (const_tree);
6466 static unsigned int dbx_reg_number (const_rtx);
6467 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6468 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6469 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6470 enum var_init_status);
6471 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6472 enum var_init_status);
6473 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6474 enum var_init_status);
6475 static int is_based_loc (const_rtx);
6476 static int resolve_one_addr (rtx *, void *);
6477 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6478 enum var_init_status);
6479 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6480 enum var_init_status);
6481 static dw_loc_list_ref loc_list_from_tree (tree, int);
6482 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6483 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6484 static tree field_type (const_tree);
6485 static unsigned int simple_type_align_in_bits (const_tree);
6486 static unsigned int simple_decl_align_in_bits (const_tree);
6487 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6488 static HOST_WIDE_INT field_byte_offset (const_tree);
6489 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6491 static void add_data_member_location_attribute (dw_die_ref, tree);
6492 static bool add_const_value_attribute (dw_die_ref, rtx);
6493 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6494 static void insert_double (double_int, unsigned char *);
6495 static void insert_float (const_rtx, unsigned char *);
6496 static rtx rtl_for_decl_location (tree);
6497 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6498 enum dwarf_attribute);
6499 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6500 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6501 static void add_name_attribute (dw_die_ref, const char *);
6502 static void add_comp_dir_attribute (dw_die_ref);
6503 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6504 static void add_subscript_info (dw_die_ref, tree, bool);
6505 static void add_byte_size_attribute (dw_die_ref, tree);
6506 static void add_bit_offset_attribute (dw_die_ref, tree);
6507 static void add_bit_size_attribute (dw_die_ref, tree);
6508 static void add_prototyped_attribute (dw_die_ref, tree);
6509 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6510 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6511 static void add_src_coords_attributes (dw_die_ref, tree);
6512 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6513 static void push_decl_scope (tree);
6514 static void pop_decl_scope (void);
6515 static dw_die_ref scope_die_for (tree, dw_die_ref);
6516 static inline int local_scope_p (dw_die_ref);
6517 static inline int class_scope_p (dw_die_ref);
6518 static inline int class_or_namespace_scope_p (dw_die_ref);
6519 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6520 static void add_calling_convention_attribute (dw_die_ref, tree);
6521 static const char *type_tag (const_tree);
6522 static tree member_declared_type (const_tree);
6524 static const char *decl_start_label (tree);
6526 static void gen_array_type_die (tree, dw_die_ref);
6527 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6529 static void gen_entry_point_die (tree, dw_die_ref);
6531 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6532 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6533 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6534 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6535 static void gen_formal_types_die (tree, dw_die_ref);
6536 static void gen_subprogram_die (tree, dw_die_ref);
6537 static void gen_variable_die (tree, tree, dw_die_ref);
6538 static void gen_const_die (tree, dw_die_ref);
6539 static void gen_label_die (tree, dw_die_ref);
6540 static void gen_lexical_block_die (tree, dw_die_ref, int);
6541 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6542 static void gen_field_die (tree, dw_die_ref);
6543 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6544 static dw_die_ref gen_compile_unit_die (const char *);
6545 static void gen_inheritance_die (tree, tree, dw_die_ref);
6546 static void gen_member_die (tree, dw_die_ref);
6547 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6548 enum debug_info_usage);
6549 static void gen_subroutine_type_die (tree, dw_die_ref);
6550 static void gen_typedef_die (tree, dw_die_ref);
6551 static void gen_type_die (tree, dw_die_ref);
6552 static void gen_block_die (tree, dw_die_ref, int);
6553 static void decls_for_scope (tree, dw_die_ref, int);
6554 static int is_redundant_typedef (const_tree);
6555 static bool is_naming_typedef_decl (const_tree);
6556 static inline dw_die_ref get_context_die (tree);
6557 static void gen_namespace_die (tree, dw_die_ref);
6558 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6559 static dw_die_ref force_decl_die (tree);
6560 static dw_die_ref force_type_die (tree);
6561 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6562 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6563 static struct dwarf_file_data * lookup_filename (const char *);
6564 static void retry_incomplete_types (void);
6565 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6566 static void gen_generic_params_dies (tree);
6567 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6568 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6569 static void splice_child_die (dw_die_ref, dw_die_ref);
6570 static int file_info_cmp (const void *, const void *);
6571 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6572 const char *, const char *);
6573 static void output_loc_list (dw_loc_list_ref);
6574 static char *gen_internal_sym (const char *);
6576 static void prune_unmark_dies (dw_die_ref);
6577 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6578 static void prune_unused_types_mark (dw_die_ref, int);
6579 static void prune_unused_types_walk (dw_die_ref);
6580 static void prune_unused_types_walk_attribs (dw_die_ref);
6581 static void prune_unused_types_prune (dw_die_ref);
6582 static void prune_unused_types (void);
6583 static int maybe_emit_file (struct dwarf_file_data *fd);
6584 static inline const char *AT_vms_delta1 (dw_attr_ref);
6585 static inline const char *AT_vms_delta2 (dw_attr_ref);
6586 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6587 const char *, const char *);
6588 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6589 static void gen_remaining_tmpl_value_param_die_attribute (void);
6590 static bool generic_type_p (tree);
6591 static void schedule_generic_params_dies_gen (tree t);
6592 static void gen_scheduled_generic_parms_dies (void);
6594 /* Section names used to hold DWARF debugging information. */
6595 #ifndef DEBUG_INFO_SECTION
6596 #define DEBUG_INFO_SECTION ".debug_info"
6598 #ifndef DEBUG_ABBREV_SECTION
6599 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6601 #ifndef DEBUG_ARANGES_SECTION
6602 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6604 #ifndef DEBUG_MACINFO_SECTION
6605 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6607 #ifndef DEBUG_LINE_SECTION
6608 #define DEBUG_LINE_SECTION ".debug_line"
6610 #ifndef DEBUG_LOC_SECTION
6611 #define DEBUG_LOC_SECTION ".debug_loc"
6613 #ifndef DEBUG_PUBNAMES_SECTION
6614 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6616 #ifndef DEBUG_PUBTYPES_SECTION
6617 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6619 #ifndef DEBUG_STR_SECTION
6620 #define DEBUG_STR_SECTION ".debug_str"
6622 #ifndef DEBUG_RANGES_SECTION
6623 #define DEBUG_RANGES_SECTION ".debug_ranges"
6626 /* Standard ELF section names for compiled code and data. */
6627 #ifndef TEXT_SECTION_NAME
6628 #define TEXT_SECTION_NAME ".text"
6631 /* Section flags for .debug_str section. */
6632 #define DEBUG_STR_SECTION_FLAGS \
6633 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6634 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6637 /* Labels we insert at beginning sections we can reference instead of
6638 the section names themselves. */
6640 #ifndef TEXT_SECTION_LABEL
6641 #define TEXT_SECTION_LABEL "Ltext"
6643 #ifndef COLD_TEXT_SECTION_LABEL
6644 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6646 #ifndef DEBUG_LINE_SECTION_LABEL
6647 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6649 #ifndef DEBUG_INFO_SECTION_LABEL
6650 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6652 #ifndef DEBUG_ABBREV_SECTION_LABEL
6653 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6655 #ifndef DEBUG_LOC_SECTION_LABEL
6656 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6658 #ifndef DEBUG_RANGES_SECTION_LABEL
6659 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6661 #ifndef DEBUG_MACINFO_SECTION_LABEL
6662 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6666 /* Definitions of defaults for formats and names of various special
6667 (artificial) labels which may be generated within this file (when the -g
6668 options is used and DWARF2_DEBUGGING_INFO is in effect.
6669 If necessary, these may be overridden from within the tm.h file, but
6670 typically, overriding these defaults is unnecessary. */
6672 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6673 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6674 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6675 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6676 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6677 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6678 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6679 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6680 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6681 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6683 #ifndef TEXT_END_LABEL
6684 #define TEXT_END_LABEL "Letext"
6686 #ifndef COLD_END_LABEL
6687 #define COLD_END_LABEL "Letext_cold"
6689 #ifndef BLOCK_BEGIN_LABEL
6690 #define BLOCK_BEGIN_LABEL "LBB"
6692 #ifndef BLOCK_END_LABEL
6693 #define BLOCK_END_LABEL "LBE"
6695 #ifndef LINE_CODE_LABEL
6696 #define LINE_CODE_LABEL "LM"
6700 /* Return the root of the DIE's built for the current compilation unit. */
6702 comp_unit_die (void)
6704 if (!single_comp_unit_die)
6705 single_comp_unit_die = gen_compile_unit_die (NULL);
6706 return single_comp_unit_die;
6709 /* We allow a language front-end to designate a function that is to be
6710 called to "demangle" any name before it is put into a DIE. */
6712 static const char *(*demangle_name_func) (const char *);
6715 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6717 demangle_name_func = func;
6720 /* Test if rtl node points to a pseudo register. */
6723 is_pseudo_reg (const_rtx rtl)
6725 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6726 || (GET_CODE (rtl) == SUBREG
6727 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6730 /* Return a reference to a type, with its const and volatile qualifiers
6734 type_main_variant (tree type)
6736 type = TYPE_MAIN_VARIANT (type);
6738 /* ??? There really should be only one main variant among any group of
6739 variants of a given type (and all of the MAIN_VARIANT values for all
6740 members of the group should point to that one type) but sometimes the C
6741 front-end messes this up for array types, so we work around that bug
6743 if (TREE_CODE (type) == ARRAY_TYPE)
6744 while (type != TYPE_MAIN_VARIANT (type))
6745 type = TYPE_MAIN_VARIANT (type);
6750 /* Return nonzero if the given type node represents a tagged type. */
6753 is_tagged_type (const_tree type)
6755 enum tree_code code = TREE_CODE (type);
6757 return (code == RECORD_TYPE || code == UNION_TYPE
6758 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6761 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6764 get_ref_die_offset_label (char *label, dw_die_ref ref)
6766 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6769 /* Convert a DIE tag into its string name. */
6772 dwarf_tag_name (unsigned int tag)
6776 case DW_TAG_padding:
6777 return "DW_TAG_padding";
6778 case DW_TAG_array_type:
6779 return "DW_TAG_array_type";
6780 case DW_TAG_class_type:
6781 return "DW_TAG_class_type";
6782 case DW_TAG_entry_point:
6783 return "DW_TAG_entry_point";
6784 case DW_TAG_enumeration_type:
6785 return "DW_TAG_enumeration_type";
6786 case DW_TAG_formal_parameter:
6787 return "DW_TAG_formal_parameter";
6788 case DW_TAG_imported_declaration:
6789 return "DW_TAG_imported_declaration";
6791 return "DW_TAG_label";
6792 case DW_TAG_lexical_block:
6793 return "DW_TAG_lexical_block";
6795 return "DW_TAG_member";
6796 case DW_TAG_pointer_type:
6797 return "DW_TAG_pointer_type";
6798 case DW_TAG_reference_type:
6799 return "DW_TAG_reference_type";
6800 case DW_TAG_compile_unit:
6801 return "DW_TAG_compile_unit";
6802 case DW_TAG_string_type:
6803 return "DW_TAG_string_type";
6804 case DW_TAG_structure_type:
6805 return "DW_TAG_structure_type";
6806 case DW_TAG_subroutine_type:
6807 return "DW_TAG_subroutine_type";
6808 case DW_TAG_typedef:
6809 return "DW_TAG_typedef";
6810 case DW_TAG_union_type:
6811 return "DW_TAG_union_type";
6812 case DW_TAG_unspecified_parameters:
6813 return "DW_TAG_unspecified_parameters";
6814 case DW_TAG_variant:
6815 return "DW_TAG_variant";
6816 case DW_TAG_common_block:
6817 return "DW_TAG_common_block";
6818 case DW_TAG_common_inclusion:
6819 return "DW_TAG_common_inclusion";
6820 case DW_TAG_inheritance:
6821 return "DW_TAG_inheritance";
6822 case DW_TAG_inlined_subroutine:
6823 return "DW_TAG_inlined_subroutine";
6825 return "DW_TAG_module";
6826 case DW_TAG_ptr_to_member_type:
6827 return "DW_TAG_ptr_to_member_type";
6828 case DW_TAG_set_type:
6829 return "DW_TAG_set_type";
6830 case DW_TAG_subrange_type:
6831 return "DW_TAG_subrange_type";
6832 case DW_TAG_with_stmt:
6833 return "DW_TAG_with_stmt";
6834 case DW_TAG_access_declaration:
6835 return "DW_TAG_access_declaration";
6836 case DW_TAG_base_type:
6837 return "DW_TAG_base_type";
6838 case DW_TAG_catch_block:
6839 return "DW_TAG_catch_block";
6840 case DW_TAG_const_type:
6841 return "DW_TAG_const_type";
6842 case DW_TAG_constant:
6843 return "DW_TAG_constant";
6844 case DW_TAG_enumerator:
6845 return "DW_TAG_enumerator";
6846 case DW_TAG_file_type:
6847 return "DW_TAG_file_type";
6849 return "DW_TAG_friend";
6850 case DW_TAG_namelist:
6851 return "DW_TAG_namelist";
6852 case DW_TAG_namelist_item:
6853 return "DW_TAG_namelist_item";
6854 case DW_TAG_packed_type:
6855 return "DW_TAG_packed_type";
6856 case DW_TAG_subprogram:
6857 return "DW_TAG_subprogram";
6858 case DW_TAG_template_type_param:
6859 return "DW_TAG_template_type_param";
6860 case DW_TAG_template_value_param:
6861 return "DW_TAG_template_value_param";
6862 case DW_TAG_thrown_type:
6863 return "DW_TAG_thrown_type";
6864 case DW_TAG_try_block:
6865 return "DW_TAG_try_block";
6866 case DW_TAG_variant_part:
6867 return "DW_TAG_variant_part";
6868 case DW_TAG_variable:
6869 return "DW_TAG_variable";
6870 case DW_TAG_volatile_type:
6871 return "DW_TAG_volatile_type";
6872 case DW_TAG_dwarf_procedure:
6873 return "DW_TAG_dwarf_procedure";
6874 case DW_TAG_restrict_type:
6875 return "DW_TAG_restrict_type";
6876 case DW_TAG_interface_type:
6877 return "DW_TAG_interface_type";
6878 case DW_TAG_namespace:
6879 return "DW_TAG_namespace";
6880 case DW_TAG_imported_module:
6881 return "DW_TAG_imported_module";
6882 case DW_TAG_unspecified_type:
6883 return "DW_TAG_unspecified_type";
6884 case DW_TAG_partial_unit:
6885 return "DW_TAG_partial_unit";
6886 case DW_TAG_imported_unit:
6887 return "DW_TAG_imported_unit";
6888 case DW_TAG_condition:
6889 return "DW_TAG_condition";
6890 case DW_TAG_shared_type:
6891 return "DW_TAG_shared_type";
6892 case DW_TAG_type_unit:
6893 return "DW_TAG_type_unit";
6894 case DW_TAG_rvalue_reference_type:
6895 return "DW_TAG_rvalue_reference_type";
6896 case DW_TAG_template_alias:
6897 return "DW_TAG_template_alias";
6898 case DW_TAG_GNU_template_parameter_pack:
6899 return "DW_TAG_GNU_template_parameter_pack";
6900 case DW_TAG_GNU_formal_parameter_pack:
6901 return "DW_TAG_GNU_formal_parameter_pack";
6902 case DW_TAG_MIPS_loop:
6903 return "DW_TAG_MIPS_loop";
6904 case DW_TAG_format_label:
6905 return "DW_TAG_format_label";
6906 case DW_TAG_function_template:
6907 return "DW_TAG_function_template";
6908 case DW_TAG_class_template:
6909 return "DW_TAG_class_template";
6910 case DW_TAG_GNU_BINCL:
6911 return "DW_TAG_GNU_BINCL";
6912 case DW_TAG_GNU_EINCL:
6913 return "DW_TAG_GNU_EINCL";
6914 case DW_TAG_GNU_template_template_param:
6915 return "DW_TAG_GNU_template_template_param";
6916 case DW_TAG_GNU_call_site:
6917 return "DW_TAG_GNU_call_site";
6918 case DW_TAG_GNU_call_site_parameter:
6919 return "DW_TAG_GNU_call_site_parameter";
6921 return "DW_TAG_<unknown>";
6925 /* Convert a DWARF attribute code into its string name. */
6928 dwarf_attr_name (unsigned int attr)
6933 return "DW_AT_sibling";
6934 case DW_AT_location:
6935 return "DW_AT_location";
6937 return "DW_AT_name";
6938 case DW_AT_ordering:
6939 return "DW_AT_ordering";
6940 case DW_AT_subscr_data:
6941 return "DW_AT_subscr_data";
6942 case DW_AT_byte_size:
6943 return "DW_AT_byte_size";
6944 case DW_AT_bit_offset:
6945 return "DW_AT_bit_offset";
6946 case DW_AT_bit_size:
6947 return "DW_AT_bit_size";
6948 case DW_AT_element_list:
6949 return "DW_AT_element_list";
6950 case DW_AT_stmt_list:
6951 return "DW_AT_stmt_list";
6953 return "DW_AT_low_pc";
6955 return "DW_AT_high_pc";
6956 case DW_AT_language:
6957 return "DW_AT_language";
6959 return "DW_AT_member";
6961 return "DW_AT_discr";
6962 case DW_AT_discr_value:
6963 return "DW_AT_discr_value";
6964 case DW_AT_visibility:
6965 return "DW_AT_visibility";
6967 return "DW_AT_import";
6968 case DW_AT_string_length:
6969 return "DW_AT_string_length";
6970 case DW_AT_common_reference:
6971 return "DW_AT_common_reference";
6972 case DW_AT_comp_dir:
6973 return "DW_AT_comp_dir";
6974 case DW_AT_const_value:
6975 return "DW_AT_const_value";
6976 case DW_AT_containing_type:
6977 return "DW_AT_containing_type";
6978 case DW_AT_default_value:
6979 return "DW_AT_default_value";
6981 return "DW_AT_inline";
6982 case DW_AT_is_optional:
6983 return "DW_AT_is_optional";
6984 case DW_AT_lower_bound:
6985 return "DW_AT_lower_bound";
6986 case DW_AT_producer:
6987 return "DW_AT_producer";
6988 case DW_AT_prototyped:
6989 return "DW_AT_prototyped";
6990 case DW_AT_return_addr:
6991 return "DW_AT_return_addr";
6992 case DW_AT_start_scope:
6993 return "DW_AT_start_scope";
6994 case DW_AT_bit_stride:
6995 return "DW_AT_bit_stride";
6996 case DW_AT_upper_bound:
6997 return "DW_AT_upper_bound";
6998 case DW_AT_abstract_origin:
6999 return "DW_AT_abstract_origin";
7000 case DW_AT_accessibility:
7001 return "DW_AT_accessibility";
7002 case DW_AT_address_class:
7003 return "DW_AT_address_class";
7004 case DW_AT_artificial:
7005 return "DW_AT_artificial";
7006 case DW_AT_base_types:
7007 return "DW_AT_base_types";
7008 case DW_AT_calling_convention:
7009 return "DW_AT_calling_convention";
7011 return "DW_AT_count";
7012 case DW_AT_data_member_location:
7013 return "DW_AT_data_member_location";
7014 case DW_AT_decl_column:
7015 return "DW_AT_decl_column";
7016 case DW_AT_decl_file:
7017 return "DW_AT_decl_file";
7018 case DW_AT_decl_line:
7019 return "DW_AT_decl_line";
7020 case DW_AT_declaration:
7021 return "DW_AT_declaration";
7022 case DW_AT_discr_list:
7023 return "DW_AT_discr_list";
7024 case DW_AT_encoding:
7025 return "DW_AT_encoding";
7026 case DW_AT_external:
7027 return "DW_AT_external";
7028 case DW_AT_explicit:
7029 return "DW_AT_explicit";
7030 case DW_AT_frame_base:
7031 return "DW_AT_frame_base";
7033 return "DW_AT_friend";
7034 case DW_AT_identifier_case:
7035 return "DW_AT_identifier_case";
7036 case DW_AT_macro_info:
7037 return "DW_AT_macro_info";
7038 case DW_AT_namelist_items:
7039 return "DW_AT_namelist_items";
7040 case DW_AT_priority:
7041 return "DW_AT_priority";
7043 return "DW_AT_segment";
7044 case DW_AT_specification:
7045 return "DW_AT_specification";
7046 case DW_AT_static_link:
7047 return "DW_AT_static_link";
7049 return "DW_AT_type";
7050 case DW_AT_use_location:
7051 return "DW_AT_use_location";
7052 case DW_AT_variable_parameter:
7053 return "DW_AT_variable_parameter";
7054 case DW_AT_virtuality:
7055 return "DW_AT_virtuality";
7056 case DW_AT_vtable_elem_location:
7057 return "DW_AT_vtable_elem_location";
7059 case DW_AT_allocated:
7060 return "DW_AT_allocated";
7061 case DW_AT_associated:
7062 return "DW_AT_associated";
7063 case DW_AT_data_location:
7064 return "DW_AT_data_location";
7065 case DW_AT_byte_stride:
7066 return "DW_AT_byte_stride";
7067 case DW_AT_entry_pc:
7068 return "DW_AT_entry_pc";
7069 case DW_AT_use_UTF8:
7070 return "DW_AT_use_UTF8";
7071 case DW_AT_extension:
7072 return "DW_AT_extension";
7074 return "DW_AT_ranges";
7075 case DW_AT_trampoline:
7076 return "DW_AT_trampoline";
7077 case DW_AT_call_column:
7078 return "DW_AT_call_column";
7079 case DW_AT_call_file:
7080 return "DW_AT_call_file";
7081 case DW_AT_call_line:
7082 return "DW_AT_call_line";
7083 case DW_AT_object_pointer:
7084 return "DW_AT_object_pointer";
7086 case DW_AT_signature:
7087 return "DW_AT_signature";
7088 case DW_AT_main_subprogram:
7089 return "DW_AT_main_subprogram";
7090 case DW_AT_data_bit_offset:
7091 return "DW_AT_data_bit_offset";
7092 case DW_AT_const_expr:
7093 return "DW_AT_const_expr";
7094 case DW_AT_enum_class:
7095 return "DW_AT_enum_class";
7096 case DW_AT_linkage_name:
7097 return "DW_AT_linkage_name";
7099 case DW_AT_MIPS_fde:
7100 return "DW_AT_MIPS_fde";
7101 case DW_AT_MIPS_loop_begin:
7102 return "DW_AT_MIPS_loop_begin";
7103 case DW_AT_MIPS_tail_loop_begin:
7104 return "DW_AT_MIPS_tail_loop_begin";
7105 case DW_AT_MIPS_epilog_begin:
7106 return "DW_AT_MIPS_epilog_begin";
7107 #if VMS_DEBUGGING_INFO
7108 case DW_AT_HP_prologue:
7109 return "DW_AT_HP_prologue";
7111 case DW_AT_MIPS_loop_unroll_factor:
7112 return "DW_AT_MIPS_loop_unroll_factor";
7114 case DW_AT_MIPS_software_pipeline_depth:
7115 return "DW_AT_MIPS_software_pipeline_depth";
7116 case DW_AT_MIPS_linkage_name:
7117 return "DW_AT_MIPS_linkage_name";
7118 #if VMS_DEBUGGING_INFO
7119 case DW_AT_HP_epilogue:
7120 return "DW_AT_HP_epilogue";
7122 case DW_AT_MIPS_stride:
7123 return "DW_AT_MIPS_stride";
7125 case DW_AT_MIPS_abstract_name:
7126 return "DW_AT_MIPS_abstract_name";
7127 case DW_AT_MIPS_clone_origin:
7128 return "DW_AT_MIPS_clone_origin";
7129 case DW_AT_MIPS_has_inlines:
7130 return "DW_AT_MIPS_has_inlines";
7132 case DW_AT_sf_names:
7133 return "DW_AT_sf_names";
7134 case DW_AT_src_info:
7135 return "DW_AT_src_info";
7136 case DW_AT_mac_info:
7137 return "DW_AT_mac_info";
7138 case DW_AT_src_coords:
7139 return "DW_AT_src_coords";
7140 case DW_AT_body_begin:
7141 return "DW_AT_body_begin";
7142 case DW_AT_body_end:
7143 return "DW_AT_body_end";
7144 case DW_AT_GNU_vector:
7145 return "DW_AT_GNU_vector";
7146 case DW_AT_GNU_guarded_by:
7147 return "DW_AT_GNU_guarded_by";
7148 case DW_AT_GNU_pt_guarded_by:
7149 return "DW_AT_GNU_pt_guarded_by";
7150 case DW_AT_GNU_guarded:
7151 return "DW_AT_GNU_guarded";
7152 case DW_AT_GNU_pt_guarded:
7153 return "DW_AT_GNU_pt_guarded";
7154 case DW_AT_GNU_locks_excluded:
7155 return "DW_AT_GNU_locks_excluded";
7156 case DW_AT_GNU_exclusive_locks_required:
7157 return "DW_AT_GNU_exclusive_locks_required";
7158 case DW_AT_GNU_shared_locks_required:
7159 return "DW_AT_GNU_shared_locks_required";
7160 case DW_AT_GNU_odr_signature:
7161 return "DW_AT_GNU_odr_signature";
7162 case DW_AT_GNU_template_name:
7163 return "DW_AT_GNU_template_name";
7164 case DW_AT_GNU_call_site_value:
7165 return "DW_AT_GNU_call_site_value";
7166 case DW_AT_GNU_call_site_data_value:
7167 return "DW_AT_GNU_call_site_data_value";
7168 case DW_AT_GNU_call_site_target:
7169 return "DW_AT_GNU_call_site_target";
7170 case DW_AT_GNU_call_site_target_clobbered:
7171 return "DW_AT_GNU_call_site_target_clobbered";
7172 case DW_AT_GNU_tail_call:
7173 return "DW_AT_GNU_tail_call";
7174 case DW_AT_GNU_all_tail_call_sites:
7175 return "DW_AT_GNU_all_tail_call_sites";
7176 case DW_AT_GNU_all_call_sites:
7177 return "DW_AT_GNU_all_call_sites";
7178 case DW_AT_GNU_all_source_call_sites:
7179 return "DW_AT_GNU_all_source_call_sites";
7181 case DW_AT_VMS_rtnbeg_pd_address:
7182 return "DW_AT_VMS_rtnbeg_pd_address";
7185 return "DW_AT_<unknown>";
7189 /* Convert a DWARF value form code into its string name. */
7192 dwarf_form_name (unsigned int form)
7197 return "DW_FORM_addr";
7198 case DW_FORM_block2:
7199 return "DW_FORM_block2";
7200 case DW_FORM_block4:
7201 return "DW_FORM_block4";
7203 return "DW_FORM_data2";
7205 return "DW_FORM_data4";
7207 return "DW_FORM_data8";
7208 case DW_FORM_string:
7209 return "DW_FORM_string";
7211 return "DW_FORM_block";
7212 case DW_FORM_block1:
7213 return "DW_FORM_block1";
7215 return "DW_FORM_data1";
7217 return "DW_FORM_flag";
7219 return "DW_FORM_sdata";
7221 return "DW_FORM_strp";
7223 return "DW_FORM_udata";
7224 case DW_FORM_ref_addr:
7225 return "DW_FORM_ref_addr";
7227 return "DW_FORM_ref1";
7229 return "DW_FORM_ref2";
7231 return "DW_FORM_ref4";
7233 return "DW_FORM_ref8";
7234 case DW_FORM_ref_udata:
7235 return "DW_FORM_ref_udata";
7236 case DW_FORM_indirect:
7237 return "DW_FORM_indirect";
7238 case DW_FORM_sec_offset:
7239 return "DW_FORM_sec_offset";
7240 case DW_FORM_exprloc:
7241 return "DW_FORM_exprloc";
7242 case DW_FORM_flag_present:
7243 return "DW_FORM_flag_present";
7244 case DW_FORM_ref_sig8:
7245 return "DW_FORM_ref_sig8";
7247 return "DW_FORM_<unknown>";
7251 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7252 instance of an inlined instance of a decl which is local to an inline
7253 function, so we have to trace all of the way back through the origin chain
7254 to find out what sort of node actually served as the original seed for the
7258 decl_ultimate_origin (const_tree decl)
7260 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7263 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7264 nodes in the function to point to themselves; ignore that if
7265 we're trying to output the abstract instance of this function. */
7266 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7269 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7270 most distant ancestor, this should never happen. */
7271 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7273 return DECL_ABSTRACT_ORIGIN (decl);
7276 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7277 of a virtual function may refer to a base class, so we check the 'this'
7281 decl_class_context (tree decl)
7283 tree context = NULL_TREE;
7285 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7286 context = DECL_CONTEXT (decl);
7288 context = TYPE_MAIN_VARIANT
7289 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7291 if (context && !TYPE_P (context))
7292 context = NULL_TREE;
7297 /* Add an attribute/value pair to a DIE. */
7300 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7302 /* Maybe this should be an assert? */
7306 if (die->die_attr == NULL)
7307 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7308 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7311 static inline enum dw_val_class
7312 AT_class (dw_attr_ref a)
7314 return a->dw_attr_val.val_class;
7317 /* Add a flag value attribute to a DIE. */
7320 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7324 attr.dw_attr = attr_kind;
7325 attr.dw_attr_val.val_class = dw_val_class_flag;
7326 attr.dw_attr_val.v.val_flag = flag;
7327 add_dwarf_attr (die, &attr);
7330 static inline unsigned
7331 AT_flag (dw_attr_ref a)
7333 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7334 return a->dw_attr_val.v.val_flag;
7337 /* Add a signed integer attribute value to a DIE. */
7340 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7344 attr.dw_attr = attr_kind;
7345 attr.dw_attr_val.val_class = dw_val_class_const;
7346 attr.dw_attr_val.v.val_int = int_val;
7347 add_dwarf_attr (die, &attr);
7350 static inline HOST_WIDE_INT
7351 AT_int (dw_attr_ref a)
7353 gcc_assert (a && AT_class (a) == dw_val_class_const);
7354 return a->dw_attr_val.v.val_int;
7357 /* Add an unsigned integer attribute value to a DIE. */
7360 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7361 unsigned HOST_WIDE_INT unsigned_val)
7365 attr.dw_attr = attr_kind;
7366 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7367 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7368 add_dwarf_attr (die, &attr);
7371 static inline unsigned HOST_WIDE_INT
7372 AT_unsigned (dw_attr_ref a)
7374 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7375 return a->dw_attr_val.v.val_unsigned;
7378 /* Add an unsigned double integer attribute value to a DIE. */
7381 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7382 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7386 attr.dw_attr = attr_kind;
7387 attr.dw_attr_val.val_class = dw_val_class_const_double;
7388 attr.dw_attr_val.v.val_double.high = high;
7389 attr.dw_attr_val.v.val_double.low = low;
7390 add_dwarf_attr (die, &attr);
7393 /* Add a floating point attribute value to a DIE and return it. */
7396 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7397 unsigned int length, unsigned int elt_size, unsigned char *array)
7401 attr.dw_attr = attr_kind;
7402 attr.dw_attr_val.val_class = dw_val_class_vec;
7403 attr.dw_attr_val.v.val_vec.length = length;
7404 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7405 attr.dw_attr_val.v.val_vec.array = array;
7406 add_dwarf_attr (die, &attr);
7409 /* Add an 8-byte data attribute value to a DIE. */
7412 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7413 unsigned char data8[8])
7417 attr.dw_attr = attr_kind;
7418 attr.dw_attr_val.val_class = dw_val_class_data8;
7419 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7420 add_dwarf_attr (die, &attr);
7423 /* Hash and equality functions for debug_str_hash. */
7426 debug_str_do_hash (const void *x)
7428 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7432 debug_str_eq (const void *x1, const void *x2)
7434 return strcmp ((((const struct indirect_string_node *)x1)->str),
7435 (const char *)x2) == 0;
7438 /* Add STR to the indirect string hash table. */
7440 static struct indirect_string_node *
7441 find_AT_string (const char *str)
7443 struct indirect_string_node *node;
7446 if (! debug_str_hash)
7447 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7448 debug_str_eq, NULL);
7450 slot = htab_find_slot_with_hash (debug_str_hash, str,
7451 htab_hash_string (str), INSERT);
7454 node = ggc_alloc_cleared_indirect_string_node ();
7455 node->str = ggc_strdup (str);
7459 node = (struct indirect_string_node *) *slot;
7465 /* Add a string attribute value to a DIE. */
7468 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7471 struct indirect_string_node *node;
7473 node = find_AT_string (str);
7475 attr.dw_attr = attr_kind;
7476 attr.dw_attr_val.val_class = dw_val_class_str;
7477 attr.dw_attr_val.v.val_str = node;
7478 add_dwarf_attr (die, &attr);
7481 /* Create a label for an indirect string node, ensuring it is going to
7482 be output, unless its reference count goes down to zero. */
7485 gen_label_for_indirect_string (struct indirect_string_node *node)
7492 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7493 ++dw2_string_counter;
7494 node->label = xstrdup (label);
7497 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7498 debug string STR. */
7501 get_debug_string_label (const char *str)
7503 struct indirect_string_node *node = find_AT_string (str);
7505 debug_str_hash_forced = true;
7507 gen_label_for_indirect_string (node);
7509 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7512 static inline const char *
7513 AT_string (dw_attr_ref a)
7515 gcc_assert (a && AT_class (a) == dw_val_class_str);
7516 return a->dw_attr_val.v.val_str->str;
7519 /* Find out whether a string should be output inline in DIE
7520 or out-of-line in .debug_str section. */
7522 static enum dwarf_form
7523 AT_string_form (dw_attr_ref a)
7525 struct indirect_string_node *node;
7528 gcc_assert (a && AT_class (a) == dw_val_class_str);
7530 node = a->dw_attr_val.v.val_str;
7534 len = strlen (node->str) + 1;
7536 /* If the string is shorter or equal to the size of the reference, it is
7537 always better to put it inline. */
7538 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7539 return node->form = DW_FORM_string;
7541 /* If we cannot expect the linker to merge strings in .debug_str
7542 section, only put it into .debug_str if it is worth even in this
7544 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7545 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7546 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7547 return node->form = DW_FORM_string;
7549 gen_label_for_indirect_string (node);
7551 return node->form = DW_FORM_strp;
7554 /* Add a DIE reference attribute value to a DIE. */
7557 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7561 #ifdef ENABLE_CHECKING
7562 gcc_assert (targ_die != NULL);
7564 /* With LTO we can end up trying to reference something we didn't create
7565 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7566 if (targ_die == NULL)
7570 attr.dw_attr = attr_kind;
7571 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7572 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7573 attr.dw_attr_val.v.val_die_ref.external = 0;
7574 add_dwarf_attr (die, &attr);
7577 /* Add an AT_specification attribute to a DIE, and also make the back
7578 pointer from the specification to the definition. */
7581 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7583 add_AT_die_ref (die, DW_AT_specification, targ_die);
7584 gcc_assert (!targ_die->die_definition);
7585 targ_die->die_definition = die;
7588 static inline dw_die_ref
7589 AT_ref (dw_attr_ref a)
7591 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7592 return a->dw_attr_val.v.val_die_ref.die;
7596 AT_ref_external (dw_attr_ref a)
7598 if (a && AT_class (a) == dw_val_class_die_ref)
7599 return a->dw_attr_val.v.val_die_ref.external;
7605 set_AT_ref_external (dw_attr_ref a, int i)
7607 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7608 a->dw_attr_val.v.val_die_ref.external = i;
7611 /* Add an FDE reference attribute value to a DIE. */
7614 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7618 attr.dw_attr = attr_kind;
7619 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7620 attr.dw_attr_val.v.val_fde_index = targ_fde;
7621 add_dwarf_attr (die, &attr);
7624 /* Add a location description attribute value to a DIE. */
7627 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7631 attr.dw_attr = attr_kind;
7632 attr.dw_attr_val.val_class = dw_val_class_loc;
7633 attr.dw_attr_val.v.val_loc = loc;
7634 add_dwarf_attr (die, &attr);
7637 static inline dw_loc_descr_ref
7638 AT_loc (dw_attr_ref a)
7640 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7641 return a->dw_attr_val.v.val_loc;
7645 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7649 attr.dw_attr = attr_kind;
7650 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7651 attr.dw_attr_val.v.val_loc_list = loc_list;
7652 add_dwarf_attr (die, &attr);
7653 have_location_lists = true;
7656 static inline dw_loc_list_ref
7657 AT_loc_list (dw_attr_ref a)
7659 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7660 return a->dw_attr_val.v.val_loc_list;
7663 static inline dw_loc_list_ref *
7664 AT_loc_list_ptr (dw_attr_ref a)
7666 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7667 return &a->dw_attr_val.v.val_loc_list;
7670 /* Add an address constant attribute value to a DIE. */
7673 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7677 attr.dw_attr = attr_kind;
7678 attr.dw_attr_val.val_class = dw_val_class_addr;
7679 attr.dw_attr_val.v.val_addr = addr;
7680 add_dwarf_attr (die, &attr);
7683 /* Get the RTX from to an address DIE attribute. */
7686 AT_addr (dw_attr_ref a)
7688 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7689 return a->dw_attr_val.v.val_addr;
7692 /* Add a file attribute value to a DIE. */
7695 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7696 struct dwarf_file_data *fd)
7700 attr.dw_attr = attr_kind;
7701 attr.dw_attr_val.val_class = dw_val_class_file;
7702 attr.dw_attr_val.v.val_file = fd;
7703 add_dwarf_attr (die, &attr);
7706 /* Get the dwarf_file_data from a file DIE attribute. */
7708 static inline struct dwarf_file_data *
7709 AT_file (dw_attr_ref a)
7711 gcc_assert (a && AT_class (a) == dw_val_class_file);
7712 return a->dw_attr_val.v.val_file;
7715 /* Add a vms delta attribute value to a DIE. */
7718 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7719 const char *lbl1, const char *lbl2)
7723 attr.dw_attr = attr_kind;
7724 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7725 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7726 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7727 add_dwarf_attr (die, &attr);
7730 /* Add a label identifier attribute value to a DIE. */
7733 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7737 attr.dw_attr = attr_kind;
7738 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7739 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7740 add_dwarf_attr (die, &attr);
7743 /* Add a section offset attribute value to a DIE, an offset into the
7744 debug_line section. */
7747 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7752 attr.dw_attr = attr_kind;
7753 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7754 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7755 add_dwarf_attr (die, &attr);
7758 /* Add a section offset attribute value to a DIE, an offset into the
7759 debug_macinfo section. */
7762 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7767 attr.dw_attr = attr_kind;
7768 attr.dw_attr_val.val_class = dw_val_class_macptr;
7769 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7770 add_dwarf_attr (die, &attr);
7773 /* Add an offset attribute value to a DIE. */
7776 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7777 unsigned HOST_WIDE_INT offset)
7781 attr.dw_attr = attr_kind;
7782 attr.dw_attr_val.val_class = dw_val_class_offset;
7783 attr.dw_attr_val.v.val_offset = offset;
7784 add_dwarf_attr (die, &attr);
7787 /* Add an range_list attribute value to a DIE. */
7790 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7791 long unsigned int offset)
7795 attr.dw_attr = attr_kind;
7796 attr.dw_attr_val.val_class = dw_val_class_range_list;
7797 attr.dw_attr_val.v.val_offset = offset;
7798 add_dwarf_attr (die, &attr);
7801 /* Return the start label of a delta attribute. */
7803 static inline const char *
7804 AT_vms_delta1 (dw_attr_ref a)
7806 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7807 return a->dw_attr_val.v.val_vms_delta.lbl1;
7810 /* Return the end label of a delta attribute. */
7812 static inline const char *
7813 AT_vms_delta2 (dw_attr_ref a)
7815 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7816 return a->dw_attr_val.v.val_vms_delta.lbl2;
7819 static inline const char *
7820 AT_lbl (dw_attr_ref a)
7822 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7823 || AT_class (a) == dw_val_class_lineptr
7824 || AT_class (a) == dw_val_class_macptr));
7825 return a->dw_attr_val.v.val_lbl_id;
7828 /* Get the attribute of type attr_kind. */
7831 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7835 dw_die_ref spec = NULL;
7840 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7841 if (a->dw_attr == attr_kind)
7843 else if (a->dw_attr == DW_AT_specification
7844 || a->dw_attr == DW_AT_abstract_origin)
7848 return get_AT (spec, attr_kind);
7853 /* Return the "low pc" attribute value, typically associated with a subprogram
7854 DIE. Return null if the "low pc" attribute is either not present, or if it
7855 cannot be represented as an assembler label identifier. */
7857 static inline const char *
7858 get_AT_low_pc (dw_die_ref die)
7860 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7862 return a ? AT_lbl (a) : NULL;
7865 /* Return the "high pc" attribute value, typically associated with a subprogram
7866 DIE. Return null if the "high pc" attribute is either not present, or if it
7867 cannot be represented as an assembler label identifier. */
7869 static inline const char *
7870 get_AT_hi_pc (dw_die_ref die)
7872 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7874 return a ? AT_lbl (a) : NULL;
7877 /* Return the value of the string attribute designated by ATTR_KIND, or
7878 NULL if it is not present. */
7880 static inline const char *
7881 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7883 dw_attr_ref a = get_AT (die, attr_kind);
7885 return a ? AT_string (a) : NULL;
7888 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7889 if it is not present. */
7892 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7894 dw_attr_ref a = get_AT (die, attr_kind);
7896 return a ? AT_flag (a) : 0;
7899 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7900 if it is not present. */
7902 static inline unsigned
7903 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7905 dw_attr_ref a = get_AT (die, attr_kind);
7907 return a ? AT_unsigned (a) : 0;
7910 static inline dw_die_ref
7911 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7913 dw_attr_ref a = get_AT (die, attr_kind);
7915 return a ? AT_ref (a) : NULL;
7918 static inline struct dwarf_file_data *
7919 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7921 dw_attr_ref a = get_AT (die, attr_kind);
7923 return a ? AT_file (a) : NULL;
7926 /* Return TRUE if the language is C++. */
7931 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7933 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7936 /* Return TRUE if the language is Fortran. */
7941 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7943 return (lang == DW_LANG_Fortran77
7944 || lang == DW_LANG_Fortran90
7945 || lang == DW_LANG_Fortran95);
7948 /* Return TRUE if the language is Ada. */
7953 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7955 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7958 /* Remove the specified attribute if present. */
7961 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7969 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7970 if (a->dw_attr == attr_kind)
7972 if (AT_class (a) == dw_val_class_str)
7973 if (a->dw_attr_val.v.val_str->refcount)
7974 a->dw_attr_val.v.val_str->refcount--;
7976 /* VEC_ordered_remove should help reduce the number of abbrevs
7978 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7983 /* Remove CHILD from its parent. PREV must have the property that
7984 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7987 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7989 gcc_assert (child->die_parent == prev->die_parent);
7990 gcc_assert (prev->die_sib == child);
7993 gcc_assert (child->die_parent->die_child == child);
7997 prev->die_sib = child->die_sib;
7998 if (child->die_parent->die_child == child)
7999 child->die_parent->die_child = prev;
8002 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8003 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8006 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8008 dw_die_ref parent = old_child->die_parent;
8010 gcc_assert (parent == prev->die_parent);
8011 gcc_assert (prev->die_sib == old_child);
8013 new_child->die_parent = parent;
8014 if (prev == old_child)
8016 gcc_assert (parent->die_child == old_child);
8017 new_child->die_sib = new_child;
8021 prev->die_sib = new_child;
8022 new_child->die_sib = old_child->die_sib;
8024 if (old_child->die_parent->die_child == old_child)
8025 old_child->die_parent->die_child = new_child;
8028 /* Move all children from OLD_PARENT to NEW_PARENT. */
8031 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8034 new_parent->die_child = old_parent->die_child;
8035 old_parent->die_child = NULL;
8036 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8039 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8043 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8049 dw_die_ref prev = c;
8051 while (c->die_tag == tag)
8053 remove_child_with_prev (c, prev);
8054 /* Might have removed every child. */
8055 if (c == c->die_sib)
8059 } while (c != die->die_child);
8062 /* Add a CHILD_DIE as the last child of DIE. */
8065 add_child_die (dw_die_ref die, dw_die_ref child_die)
8067 /* FIXME this should probably be an assert. */
8068 if (! die || ! child_die)
8070 gcc_assert (die != child_die);
8072 child_die->die_parent = die;
8075 child_die->die_sib = die->die_child->die_sib;
8076 die->die_child->die_sib = child_die;
8079 child_die->die_sib = child_die;
8080 die->die_child = child_die;
8083 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8084 is the specification, to the end of PARENT's list of children.
8085 This is done by removing and re-adding it. */
8088 splice_child_die (dw_die_ref parent, dw_die_ref child)
8092 /* We want the declaration DIE from inside the class, not the
8093 specification DIE at toplevel. */
8094 if (child->die_parent != parent)
8096 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8102 gcc_assert (child->die_parent == parent
8103 || (child->die_parent
8104 == get_AT_ref (parent, DW_AT_specification)));
8106 for (p = child->die_parent->die_child; ; p = p->die_sib)
8107 if (p->die_sib == child)
8109 remove_child_with_prev (child, p);
8113 add_child_die (parent, child);
8116 /* Return a pointer to a newly created DIE node. */
8118 static inline dw_die_ref
8119 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8121 dw_die_ref die = ggc_alloc_cleared_die_node ();
8123 die->die_tag = tag_value;
8125 if (parent_die != NULL)
8126 add_child_die (parent_die, die);
8129 limbo_die_node *limbo_node;
8131 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8132 limbo_node->die = die;
8133 limbo_node->created_for = t;
8134 limbo_node->next = limbo_die_list;
8135 limbo_die_list = limbo_node;
8141 /* Return the DIE associated with the given type specifier. */
8143 static inline dw_die_ref
8144 lookup_type_die (tree type)
8146 return TYPE_SYMTAB_DIE (type);
8149 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8150 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8151 anonymous type instead the one of the naming typedef. */
8153 static inline dw_die_ref
8154 strip_naming_typedef (tree type, dw_die_ref type_die)
8157 && TREE_CODE (type) == RECORD_TYPE
8159 && type_die->die_tag == DW_TAG_typedef
8160 && is_naming_typedef_decl (TYPE_NAME (type)))
8161 type_die = get_AT_ref (type_die, DW_AT_type);
8165 /* Like lookup_type_die, but if type is an anonymous type named by a
8166 typedef[1], return the DIE of the anonymous type instead the one of
8167 the naming typedef. This is because in gen_typedef_die, we did
8168 equate the anonymous struct named by the typedef with the DIE of
8169 the naming typedef. So by default, lookup_type_die on an anonymous
8170 struct yields the DIE of the naming typedef.
8172 [1]: Read the comment of is_naming_typedef_decl to learn about what
8173 a naming typedef is. */
8175 static inline dw_die_ref
8176 lookup_type_die_strip_naming_typedef (tree type)
8178 dw_die_ref die = lookup_type_die (type);
8179 return strip_naming_typedef (type, die);
8182 /* Equate a DIE to a given type specifier. */
8185 equate_type_number_to_die (tree type, dw_die_ref type_die)
8187 TYPE_SYMTAB_DIE (type) = type_die;
8190 /* Returns a hash value for X (which really is a die_struct). */
8193 decl_die_table_hash (const void *x)
8195 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8198 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8201 decl_die_table_eq (const void *x, const void *y)
8203 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8206 /* Return the DIE associated with a given declaration. */
8208 static inline dw_die_ref
8209 lookup_decl_die (tree decl)
8211 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8214 /* Returns a hash value for X (which really is a var_loc_list). */
8217 decl_loc_table_hash (const void *x)
8219 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8222 /* Return nonzero if decl_id of var_loc_list X is the same as
8226 decl_loc_table_eq (const void *x, const void *y)
8228 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8231 /* Return the var_loc list associated with a given declaration. */
8233 static inline var_loc_list *
8234 lookup_decl_loc (const_tree decl)
8236 if (!decl_loc_table)
8238 return (var_loc_list *)
8239 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8242 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8245 cached_dw_loc_list_table_hash (const void *x)
8247 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8250 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8254 cached_dw_loc_list_table_eq (const void *x, const void *y)
8256 return (((const cached_dw_loc_list *) x)->decl_id
8257 == DECL_UID ((const_tree) y));
8260 /* Equate a DIE to a particular declaration. */
8263 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8265 unsigned int decl_id = DECL_UID (decl);
8268 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8270 decl_die->decl_id = decl_id;
8273 /* Return how many bits covers PIECE EXPR_LIST. */
8276 decl_piece_bitsize (rtx piece)
8278 int ret = (int) GET_MODE (piece);
8281 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8282 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8283 return INTVAL (XEXP (XEXP (piece, 0), 0));
8286 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8289 decl_piece_varloc_ptr (rtx piece)
8291 if ((int) GET_MODE (piece))
8292 return &XEXP (piece, 0);
8294 return &XEXP (XEXP (piece, 0), 1);
8297 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8298 Next is the chain of following piece nodes. */
8301 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8303 if (bitsize <= (int) MAX_MACHINE_MODE)
8304 return alloc_EXPR_LIST (bitsize, loc_note, next);
8306 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8311 /* Return rtx that should be stored into loc field for
8312 LOC_NOTE and BITPOS/BITSIZE. */
8315 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8316 HOST_WIDE_INT bitsize)
8320 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8322 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8327 /* This function either modifies location piece list *DEST in
8328 place (if SRC and INNER is NULL), or copies location piece list
8329 *SRC to *DEST while modifying it. Location BITPOS is modified
8330 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8331 not copied and if needed some padding around it is added.
8332 When modifying in place, DEST should point to EXPR_LIST where
8333 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8334 to the start of the whole list and INNER points to the EXPR_LIST
8335 where earlier pieces cover PIECE_BITPOS bits. */
8338 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8339 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8340 HOST_WIDE_INT bitsize, rtx loc_note)
8343 bool copy = inner != NULL;
8347 /* First copy all nodes preceeding the current bitpos. */
8348 while (src != inner)
8350 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8351 decl_piece_bitsize (*src), NULL_RTX);
8352 dest = &XEXP (*dest, 1);
8353 src = &XEXP (*src, 1);
8356 /* Add padding if needed. */
8357 if (bitpos != piece_bitpos)
8359 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8360 copy ? NULL_RTX : *dest);
8361 dest = &XEXP (*dest, 1);
8363 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8366 /* A piece with correct bitpos and bitsize already exist,
8367 just update the location for it and return. */
8368 *decl_piece_varloc_ptr (*dest) = loc_note;
8371 /* Add the piece that changed. */
8372 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8373 dest = &XEXP (*dest, 1);
8374 /* Skip over pieces that overlap it. */
8375 diff = bitpos - piece_bitpos + bitsize;
8378 while (diff > 0 && *src)
8381 diff -= decl_piece_bitsize (piece);
8383 src = &XEXP (piece, 1);
8386 *src = XEXP (piece, 1);
8387 free_EXPR_LIST_node (piece);
8390 /* Add padding if needed. */
8391 if (diff < 0 && *src)
8395 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8396 dest = &XEXP (*dest, 1);
8400 /* Finally copy all nodes following it. */
8403 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8404 decl_piece_bitsize (*src), NULL_RTX);
8405 dest = &XEXP (*dest, 1);
8406 src = &XEXP (*src, 1);
8410 /* Add a variable location node to the linked list for DECL. */
8412 static struct var_loc_node *
8413 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8415 unsigned int decl_id;
8418 struct var_loc_node *loc = NULL;
8419 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8421 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8423 tree realdecl = DECL_DEBUG_EXPR (decl);
8424 if (realdecl && handled_component_p (realdecl))
8426 HOST_WIDE_INT maxsize;
8429 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8430 if (!DECL_P (innerdecl)
8431 || DECL_IGNORED_P (innerdecl)
8432 || TREE_STATIC (innerdecl)
8434 || bitpos + bitsize > 256
8435 || bitsize != maxsize)
8441 decl_id = DECL_UID (decl);
8442 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8445 temp = ggc_alloc_cleared_var_loc_list ();
8446 temp->decl_id = decl_id;
8450 temp = (var_loc_list *) *slot;
8454 struct var_loc_node *last = temp->last, *unused = NULL;
8455 rtx *piece_loc = NULL, last_loc_note;
8456 int piece_bitpos = 0;
8460 gcc_assert (last->next == NULL);
8462 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8464 piece_loc = &last->loc;
8467 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8468 if (piece_bitpos + cur_bitsize > bitpos)
8470 piece_bitpos += cur_bitsize;
8471 piece_loc = &XEXP (*piece_loc, 1);
8475 /* TEMP->LAST here is either pointer to the last but one or
8476 last element in the chained list, LAST is pointer to the
8478 if (label && strcmp (last->label, label) == 0)
8480 /* For SRA optimized variables if there weren't any real
8481 insns since last note, just modify the last node. */
8482 if (piece_loc != NULL)
8484 adjust_piece_list (piece_loc, NULL, NULL,
8485 bitpos, piece_bitpos, bitsize, loc_note);
8488 /* If the last note doesn't cover any instructions, remove it. */
8489 if (temp->last != last)
8491 temp->last->next = NULL;
8494 gcc_assert (strcmp (last->label, label) != 0);
8498 gcc_assert (temp->first == temp->last);
8499 memset (temp->last, '\0', sizeof (*temp->last));
8500 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8504 if (bitsize == -1 && NOTE_P (last->loc))
8505 last_loc_note = last->loc;
8506 else if (piece_loc != NULL
8507 && *piece_loc != NULL_RTX
8508 && piece_bitpos == bitpos
8509 && decl_piece_bitsize (*piece_loc) == bitsize)
8510 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8512 last_loc_note = NULL_RTX;
8513 /* If the current location is the same as the end of the list,
8514 and either both or neither of the locations is uninitialized,
8515 we have nothing to do. */
8516 if (last_loc_note == NULL_RTX
8517 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8518 NOTE_VAR_LOCATION_LOC (loc_note)))
8519 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8520 != NOTE_VAR_LOCATION_STATUS (loc_note))
8521 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8522 == VAR_INIT_STATUS_UNINITIALIZED)
8523 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8524 == VAR_INIT_STATUS_UNINITIALIZED))))
8526 /* Add LOC to the end of list and update LAST. If the last
8527 element of the list has been removed above, reuse its
8528 memory for the new node, otherwise allocate a new one. */
8532 memset (loc, '\0', sizeof (*loc));
8535 loc = ggc_alloc_cleared_var_loc_node ();
8536 if (bitsize == -1 || piece_loc == NULL)
8537 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8539 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8540 bitpos, piece_bitpos, bitsize, loc_note);
8542 /* Ensure TEMP->LAST will point either to the new last but one
8543 element of the chain, or to the last element in it. */
8544 if (last != temp->last)
8552 loc = ggc_alloc_cleared_var_loc_node ();
8555 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8560 /* Keep track of the number of spaces used to indent the
8561 output of the debugging routines that print the structure of
8562 the DIE internal representation. */
8563 static int print_indent;
8565 /* Indent the line the number of spaces given by print_indent. */
8568 print_spaces (FILE *outfile)
8570 fprintf (outfile, "%*s", print_indent, "");
8573 /* Print a type signature in hex. */
8576 print_signature (FILE *outfile, char *sig)
8580 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8581 fprintf (outfile, "%02x", sig[i] & 0xff);
8584 /* Print the information associated with a given DIE, and its children.
8585 This routine is a debugging aid only. */
8588 print_die (dw_die_ref die, FILE *outfile)
8594 print_spaces (outfile);
8595 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8596 die->die_offset, dwarf_tag_name (die->die_tag),
8598 print_spaces (outfile);
8599 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8600 fprintf (outfile, " offset: %ld", die->die_offset);
8601 fprintf (outfile, " mark: %d\n", die->die_mark);
8603 if (use_debug_types && die->die_id.die_type_node)
8605 print_spaces (outfile);
8606 fprintf (outfile, " signature: ");
8607 print_signature (outfile, die->die_id.die_type_node->signature);
8608 fprintf (outfile, "\n");
8611 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8613 print_spaces (outfile);
8614 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8616 switch (AT_class (a))
8618 case dw_val_class_addr:
8619 fprintf (outfile, "address");
8621 case dw_val_class_offset:
8622 fprintf (outfile, "offset");
8624 case dw_val_class_loc:
8625 fprintf (outfile, "location descriptor");
8627 case dw_val_class_loc_list:
8628 fprintf (outfile, "location list -> label:%s",
8629 AT_loc_list (a)->ll_symbol);
8631 case dw_val_class_range_list:
8632 fprintf (outfile, "range list");
8634 case dw_val_class_const:
8635 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8637 case dw_val_class_unsigned_const:
8638 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8640 case dw_val_class_const_double:
8641 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8642 HOST_WIDE_INT_PRINT_UNSIGNED")",
8643 a->dw_attr_val.v.val_double.high,
8644 a->dw_attr_val.v.val_double.low);
8646 case dw_val_class_vec:
8647 fprintf (outfile, "floating-point or vector constant");
8649 case dw_val_class_flag:
8650 fprintf (outfile, "%u", AT_flag (a));
8652 case dw_val_class_die_ref:
8653 if (AT_ref (a) != NULL)
8655 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
8657 fprintf (outfile, "die -> signature: ");
8658 print_signature (outfile,
8659 AT_ref (a)->die_id.die_type_node->signature);
8661 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
8662 fprintf (outfile, "die -> label: %s",
8663 AT_ref (a)->die_id.die_symbol);
8665 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8666 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8669 fprintf (outfile, "die -> <null>");
8671 case dw_val_class_vms_delta:
8672 fprintf (outfile, "delta: @slotcount(%s-%s)",
8673 AT_vms_delta2 (a), AT_vms_delta1 (a));
8675 case dw_val_class_lbl_id:
8676 case dw_val_class_lineptr:
8677 case dw_val_class_macptr:
8678 fprintf (outfile, "label: %s", AT_lbl (a));
8680 case dw_val_class_str:
8681 if (AT_string (a) != NULL)
8682 fprintf (outfile, "\"%s\"", AT_string (a));
8684 fprintf (outfile, "<null>");
8686 case dw_val_class_file:
8687 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8688 AT_file (a)->emitted_number);
8690 case dw_val_class_data8:
8694 for (i = 0; i < 8; i++)
8695 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8702 fprintf (outfile, "\n");
8705 if (die->die_child != NULL)
8708 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8711 if (print_indent == 0)
8712 fprintf (outfile, "\n");
8715 /* Print the information collected for a given DIE. */
8718 debug_dwarf_die (dw_die_ref die)
8720 print_die (die, stderr);
8723 /* Print all DWARF information collected for the compilation unit.
8724 This routine is a debugging aid only. */
8730 print_die (comp_unit_die (), stderr);
8733 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8734 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8735 DIE that marks the start of the DIEs for this include file. */
8738 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8740 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8741 dw_die_ref new_unit = gen_compile_unit_die (filename);
8743 new_unit->die_sib = old_unit;
8747 /* Close an include-file CU and reopen the enclosing one. */
8750 pop_compile_unit (dw_die_ref old_unit)
8752 dw_die_ref new_unit = old_unit->die_sib;
8754 old_unit->die_sib = NULL;
8758 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8759 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8761 /* Calculate the checksum of a location expression. */
8764 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8768 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8770 CHECKSUM (loc->dw_loc_oprnd1);
8771 CHECKSUM (loc->dw_loc_oprnd2);
8774 /* Calculate the checksum of an attribute. */
8777 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8779 dw_loc_descr_ref loc;
8782 CHECKSUM (at->dw_attr);
8784 /* We don't care that this was compiled with a different compiler
8785 snapshot; if the output is the same, that's what matters. */
8786 if (at->dw_attr == DW_AT_producer)
8789 switch (AT_class (at))
8791 case dw_val_class_const:
8792 CHECKSUM (at->dw_attr_val.v.val_int);
8794 case dw_val_class_unsigned_const:
8795 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8797 case dw_val_class_const_double:
8798 CHECKSUM (at->dw_attr_val.v.val_double);
8800 case dw_val_class_vec:
8801 CHECKSUM (at->dw_attr_val.v.val_vec);
8803 case dw_val_class_flag:
8804 CHECKSUM (at->dw_attr_val.v.val_flag);
8806 case dw_val_class_str:
8807 CHECKSUM_STRING (AT_string (at));
8810 case dw_val_class_addr:
8812 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8813 CHECKSUM_STRING (XSTR (r, 0));
8816 case dw_val_class_offset:
8817 CHECKSUM (at->dw_attr_val.v.val_offset);
8820 case dw_val_class_loc:
8821 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8822 loc_checksum (loc, ctx);
8825 case dw_val_class_die_ref:
8826 die_checksum (AT_ref (at), ctx, mark);
8829 case dw_val_class_fde_ref:
8830 case dw_val_class_vms_delta:
8831 case dw_val_class_lbl_id:
8832 case dw_val_class_lineptr:
8833 case dw_val_class_macptr:
8836 case dw_val_class_file:
8837 CHECKSUM_STRING (AT_file (at)->filename);
8840 case dw_val_class_data8:
8841 CHECKSUM (at->dw_attr_val.v.val_data8);
8849 /* Calculate the checksum of a DIE. */
8852 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8858 /* To avoid infinite recursion. */
8861 CHECKSUM (die->die_mark);
8864 die->die_mark = ++(*mark);
8866 CHECKSUM (die->die_tag);
8868 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8869 attr_checksum (a, ctx, mark);
8871 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8875 #undef CHECKSUM_STRING
8877 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8878 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8879 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8880 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8881 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8882 #define CHECKSUM_ATTR(FOO) \
8883 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8885 /* Calculate the checksum of a number in signed LEB128 format. */
8888 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8895 byte = (value & 0x7f);
8897 more = !((value == 0 && (byte & 0x40) == 0)
8898 || (value == -1 && (byte & 0x40) != 0));
8907 /* Calculate the checksum of a number in unsigned LEB128 format. */
8910 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8914 unsigned char byte = (value & 0x7f);
8917 /* More bytes to follow. */
8925 /* Checksum the context of the DIE. This adds the names of any
8926 surrounding namespaces or structures to the checksum. */
8929 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8933 int tag = die->die_tag;
8935 if (tag != DW_TAG_namespace
8936 && tag != DW_TAG_structure_type
8937 && tag != DW_TAG_class_type)
8940 name = get_AT_string (die, DW_AT_name);
8942 spec = get_AT_ref (die, DW_AT_specification);
8946 if (die->die_parent != NULL)
8947 checksum_die_context (die->die_parent, ctx);
8949 CHECKSUM_ULEB128 ('C');
8950 CHECKSUM_ULEB128 (tag);
8952 CHECKSUM_STRING (name);
8955 /* Calculate the checksum of a location expression. */
8958 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8960 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8961 were emitted as a DW_FORM_sdata instead of a location expression. */
8962 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8964 CHECKSUM_ULEB128 (DW_FORM_sdata);
8965 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8969 /* Otherwise, just checksum the raw location expression. */
8972 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8973 CHECKSUM (loc->dw_loc_oprnd1);
8974 CHECKSUM (loc->dw_loc_oprnd2);
8975 loc = loc->dw_loc_next;
8979 /* Calculate the checksum of an attribute. */
8982 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8983 struct md5_ctx *ctx, int *mark)
8985 dw_loc_descr_ref loc;
8988 if (AT_class (at) == dw_val_class_die_ref)
8990 dw_die_ref target_die = AT_ref (at);
8992 /* For pointer and reference types, we checksum only the (qualified)
8993 name of the target type (if there is a name). For friend entries,
8994 we checksum only the (qualified) name of the target type or function.
8995 This allows the checksum to remain the same whether the target type
8996 is complete or not. */
8997 if ((at->dw_attr == DW_AT_type
8998 && (tag == DW_TAG_pointer_type
8999 || tag == DW_TAG_reference_type
9000 || tag == DW_TAG_rvalue_reference_type
9001 || tag == DW_TAG_ptr_to_member_type))
9002 || (at->dw_attr == DW_AT_friend
9003 && tag == DW_TAG_friend))
9005 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9007 if (name_attr != NULL)
9009 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9013 CHECKSUM_ULEB128 ('N');
9014 CHECKSUM_ULEB128 (at->dw_attr);
9015 if (decl->die_parent != NULL)
9016 checksum_die_context (decl->die_parent, ctx);
9017 CHECKSUM_ULEB128 ('E');
9018 CHECKSUM_STRING (AT_string (name_attr));
9023 /* For all other references to another DIE, we check to see if the
9024 target DIE has already been visited. If it has, we emit a
9025 backward reference; if not, we descend recursively. */
9026 if (target_die->die_mark > 0)
9028 CHECKSUM_ULEB128 ('R');
9029 CHECKSUM_ULEB128 (at->dw_attr);
9030 CHECKSUM_ULEB128 (target_die->die_mark);
9034 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9038 target_die->die_mark = ++(*mark);
9039 CHECKSUM_ULEB128 ('T');
9040 CHECKSUM_ULEB128 (at->dw_attr);
9041 if (decl->die_parent != NULL)
9042 checksum_die_context (decl->die_parent, ctx);
9043 die_checksum_ordered (target_die, ctx, mark);
9048 CHECKSUM_ULEB128 ('A');
9049 CHECKSUM_ULEB128 (at->dw_attr);
9051 switch (AT_class (at))
9053 case dw_val_class_const:
9054 CHECKSUM_ULEB128 (DW_FORM_sdata);
9055 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9058 case dw_val_class_unsigned_const:
9059 CHECKSUM_ULEB128 (DW_FORM_sdata);
9060 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9063 case dw_val_class_const_double:
9064 CHECKSUM_ULEB128 (DW_FORM_block);
9065 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9066 CHECKSUM (at->dw_attr_val.v.val_double);
9069 case dw_val_class_vec:
9070 CHECKSUM_ULEB128 (DW_FORM_block);
9071 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9072 CHECKSUM (at->dw_attr_val.v.val_vec);
9075 case dw_val_class_flag:
9076 CHECKSUM_ULEB128 (DW_FORM_flag);
9077 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9080 case dw_val_class_str:
9081 CHECKSUM_ULEB128 (DW_FORM_string);
9082 CHECKSUM_STRING (AT_string (at));
9085 case dw_val_class_addr:
9087 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9088 CHECKSUM_ULEB128 (DW_FORM_string);
9089 CHECKSUM_STRING (XSTR (r, 0));
9092 case dw_val_class_offset:
9093 CHECKSUM_ULEB128 (DW_FORM_sdata);
9094 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9097 case dw_val_class_loc:
9098 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9099 loc_checksum_ordered (loc, ctx);
9102 case dw_val_class_fde_ref:
9103 case dw_val_class_lbl_id:
9104 case dw_val_class_lineptr:
9105 case dw_val_class_macptr:
9108 case dw_val_class_file:
9109 CHECKSUM_ULEB128 (DW_FORM_string);
9110 CHECKSUM_STRING (AT_file (at)->filename);
9113 case dw_val_class_data8:
9114 CHECKSUM (at->dw_attr_val.v.val_data8);
9122 struct checksum_attributes
9124 dw_attr_ref at_name;
9125 dw_attr_ref at_type;
9126 dw_attr_ref at_friend;
9127 dw_attr_ref at_accessibility;
9128 dw_attr_ref at_address_class;
9129 dw_attr_ref at_allocated;
9130 dw_attr_ref at_artificial;
9131 dw_attr_ref at_associated;
9132 dw_attr_ref at_binary_scale;
9133 dw_attr_ref at_bit_offset;
9134 dw_attr_ref at_bit_size;
9135 dw_attr_ref at_bit_stride;
9136 dw_attr_ref at_byte_size;
9137 dw_attr_ref at_byte_stride;
9138 dw_attr_ref at_const_value;
9139 dw_attr_ref at_containing_type;
9140 dw_attr_ref at_count;
9141 dw_attr_ref at_data_location;
9142 dw_attr_ref at_data_member_location;
9143 dw_attr_ref at_decimal_scale;
9144 dw_attr_ref at_decimal_sign;
9145 dw_attr_ref at_default_value;
9146 dw_attr_ref at_digit_count;
9147 dw_attr_ref at_discr;
9148 dw_attr_ref at_discr_list;
9149 dw_attr_ref at_discr_value;
9150 dw_attr_ref at_encoding;
9151 dw_attr_ref at_endianity;
9152 dw_attr_ref at_explicit;
9153 dw_attr_ref at_is_optional;
9154 dw_attr_ref at_location;
9155 dw_attr_ref at_lower_bound;
9156 dw_attr_ref at_mutable;
9157 dw_attr_ref at_ordering;
9158 dw_attr_ref at_picture_string;
9159 dw_attr_ref at_prototyped;
9160 dw_attr_ref at_small;
9161 dw_attr_ref at_segment;
9162 dw_attr_ref at_string_length;
9163 dw_attr_ref at_threads_scaled;
9164 dw_attr_ref at_upper_bound;
9165 dw_attr_ref at_use_location;
9166 dw_attr_ref at_use_UTF8;
9167 dw_attr_ref at_variable_parameter;
9168 dw_attr_ref at_virtuality;
9169 dw_attr_ref at_visibility;
9170 dw_attr_ref at_vtable_elem_location;
9173 /* Collect the attributes that we will want to use for the checksum. */
9176 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9181 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9192 attrs->at_friend = a;
9194 case DW_AT_accessibility:
9195 attrs->at_accessibility = a;
9197 case DW_AT_address_class:
9198 attrs->at_address_class = a;
9200 case DW_AT_allocated:
9201 attrs->at_allocated = a;
9203 case DW_AT_artificial:
9204 attrs->at_artificial = a;
9206 case DW_AT_associated:
9207 attrs->at_associated = a;
9209 case DW_AT_binary_scale:
9210 attrs->at_binary_scale = a;
9212 case DW_AT_bit_offset:
9213 attrs->at_bit_offset = a;
9215 case DW_AT_bit_size:
9216 attrs->at_bit_size = a;
9218 case DW_AT_bit_stride:
9219 attrs->at_bit_stride = a;
9221 case DW_AT_byte_size:
9222 attrs->at_byte_size = a;
9224 case DW_AT_byte_stride:
9225 attrs->at_byte_stride = a;
9227 case DW_AT_const_value:
9228 attrs->at_const_value = a;
9230 case DW_AT_containing_type:
9231 attrs->at_containing_type = a;
9234 attrs->at_count = a;
9236 case DW_AT_data_location:
9237 attrs->at_data_location = a;
9239 case DW_AT_data_member_location:
9240 attrs->at_data_member_location = a;
9242 case DW_AT_decimal_scale:
9243 attrs->at_decimal_scale = a;
9245 case DW_AT_decimal_sign:
9246 attrs->at_decimal_sign = a;
9248 case DW_AT_default_value:
9249 attrs->at_default_value = a;
9251 case DW_AT_digit_count:
9252 attrs->at_digit_count = a;
9255 attrs->at_discr = a;
9257 case DW_AT_discr_list:
9258 attrs->at_discr_list = a;
9260 case DW_AT_discr_value:
9261 attrs->at_discr_value = a;
9263 case DW_AT_encoding:
9264 attrs->at_encoding = a;
9266 case DW_AT_endianity:
9267 attrs->at_endianity = a;
9269 case DW_AT_explicit:
9270 attrs->at_explicit = a;
9272 case DW_AT_is_optional:
9273 attrs->at_is_optional = a;
9275 case DW_AT_location:
9276 attrs->at_location = a;
9278 case DW_AT_lower_bound:
9279 attrs->at_lower_bound = a;
9282 attrs->at_mutable = a;
9284 case DW_AT_ordering:
9285 attrs->at_ordering = a;
9287 case DW_AT_picture_string:
9288 attrs->at_picture_string = a;
9290 case DW_AT_prototyped:
9291 attrs->at_prototyped = a;
9294 attrs->at_small = a;
9297 attrs->at_segment = a;
9299 case DW_AT_string_length:
9300 attrs->at_string_length = a;
9302 case DW_AT_threads_scaled:
9303 attrs->at_threads_scaled = a;
9305 case DW_AT_upper_bound:
9306 attrs->at_upper_bound = a;
9308 case DW_AT_use_location:
9309 attrs->at_use_location = a;
9311 case DW_AT_use_UTF8:
9312 attrs->at_use_UTF8 = a;
9314 case DW_AT_variable_parameter:
9315 attrs->at_variable_parameter = a;
9317 case DW_AT_virtuality:
9318 attrs->at_virtuality = a;
9320 case DW_AT_visibility:
9321 attrs->at_visibility = a;
9323 case DW_AT_vtable_elem_location:
9324 attrs->at_vtable_elem_location = a;
9332 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9335 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9339 struct checksum_attributes attrs;
9341 CHECKSUM_ULEB128 ('D');
9342 CHECKSUM_ULEB128 (die->die_tag);
9344 memset (&attrs, 0, sizeof (attrs));
9346 decl = get_AT_ref (die, DW_AT_specification);
9348 collect_checksum_attributes (&attrs, decl);
9349 collect_checksum_attributes (&attrs, die);
9351 CHECKSUM_ATTR (attrs.at_name);
9352 CHECKSUM_ATTR (attrs.at_accessibility);
9353 CHECKSUM_ATTR (attrs.at_address_class);
9354 CHECKSUM_ATTR (attrs.at_allocated);
9355 CHECKSUM_ATTR (attrs.at_artificial);
9356 CHECKSUM_ATTR (attrs.at_associated);
9357 CHECKSUM_ATTR (attrs.at_binary_scale);
9358 CHECKSUM_ATTR (attrs.at_bit_offset);
9359 CHECKSUM_ATTR (attrs.at_bit_size);
9360 CHECKSUM_ATTR (attrs.at_bit_stride);
9361 CHECKSUM_ATTR (attrs.at_byte_size);
9362 CHECKSUM_ATTR (attrs.at_byte_stride);
9363 CHECKSUM_ATTR (attrs.at_const_value);
9364 CHECKSUM_ATTR (attrs.at_containing_type);
9365 CHECKSUM_ATTR (attrs.at_count);
9366 CHECKSUM_ATTR (attrs.at_data_location);
9367 CHECKSUM_ATTR (attrs.at_data_member_location);
9368 CHECKSUM_ATTR (attrs.at_decimal_scale);
9369 CHECKSUM_ATTR (attrs.at_decimal_sign);
9370 CHECKSUM_ATTR (attrs.at_default_value);
9371 CHECKSUM_ATTR (attrs.at_digit_count);
9372 CHECKSUM_ATTR (attrs.at_discr);
9373 CHECKSUM_ATTR (attrs.at_discr_list);
9374 CHECKSUM_ATTR (attrs.at_discr_value);
9375 CHECKSUM_ATTR (attrs.at_encoding);
9376 CHECKSUM_ATTR (attrs.at_endianity);
9377 CHECKSUM_ATTR (attrs.at_explicit);
9378 CHECKSUM_ATTR (attrs.at_is_optional);
9379 CHECKSUM_ATTR (attrs.at_location);
9380 CHECKSUM_ATTR (attrs.at_lower_bound);
9381 CHECKSUM_ATTR (attrs.at_mutable);
9382 CHECKSUM_ATTR (attrs.at_ordering);
9383 CHECKSUM_ATTR (attrs.at_picture_string);
9384 CHECKSUM_ATTR (attrs.at_prototyped);
9385 CHECKSUM_ATTR (attrs.at_small);
9386 CHECKSUM_ATTR (attrs.at_segment);
9387 CHECKSUM_ATTR (attrs.at_string_length);
9388 CHECKSUM_ATTR (attrs.at_threads_scaled);
9389 CHECKSUM_ATTR (attrs.at_upper_bound);
9390 CHECKSUM_ATTR (attrs.at_use_location);
9391 CHECKSUM_ATTR (attrs.at_use_UTF8);
9392 CHECKSUM_ATTR (attrs.at_variable_parameter);
9393 CHECKSUM_ATTR (attrs.at_virtuality);
9394 CHECKSUM_ATTR (attrs.at_visibility);
9395 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9396 CHECKSUM_ATTR (attrs.at_type);
9397 CHECKSUM_ATTR (attrs.at_friend);
9399 /* Checksum the child DIEs, except for nested types and member functions. */
9402 dw_attr_ref name_attr;
9405 name_attr = get_AT (c, DW_AT_name);
9406 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9407 && name_attr != NULL)
9409 CHECKSUM_ULEB128 ('S');
9410 CHECKSUM_ULEB128 (c->die_tag);
9411 CHECKSUM_STRING (AT_string (name_attr));
9415 /* Mark this DIE so it gets processed when unmarking. */
9416 if (c->die_mark == 0)
9418 die_checksum_ordered (c, ctx, mark);
9420 } while (c != die->die_child);
9422 CHECKSUM_ULEB128 (0);
9426 #undef CHECKSUM_STRING
9427 #undef CHECKSUM_ATTR
9428 #undef CHECKSUM_LEB128
9429 #undef CHECKSUM_ULEB128
9431 /* Generate the type signature for DIE. This is computed by generating an
9432 MD5 checksum over the DIE's tag, its relevant attributes, and its
9433 children. Attributes that are references to other DIEs are processed
9434 by recursion, using the MARK field to prevent infinite recursion.
9435 If the DIE is nested inside a namespace or another type, we also
9436 need to include that context in the signature. The lower 64 bits
9437 of the resulting MD5 checksum comprise the signature. */
9440 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9444 unsigned char checksum[16];
9448 name = get_AT_string (die, DW_AT_name);
9449 decl = get_AT_ref (die, DW_AT_specification);
9451 /* First, compute a signature for just the type name (and its surrounding
9452 context, if any. This is stored in the type unit DIE for link-time
9453 ODR (one-definition rule) checking. */
9455 if (is_cxx() && name != NULL)
9457 md5_init_ctx (&ctx);
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 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9464 md5_process_bytes (name, strlen (name) + 1, &ctx);
9465 md5_finish_ctx (&ctx, checksum);
9467 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9470 /* Next, compute the complete type signature. */
9472 md5_init_ctx (&ctx);
9474 die->die_mark = mark;
9476 /* Checksum the names of surrounding namespaces and structures. */
9477 if (decl != NULL && decl->die_parent != NULL)
9478 checksum_die_context (decl->die_parent, &ctx);
9480 /* Checksum the DIE and its children. */
9481 die_checksum_ordered (die, &ctx, &mark);
9482 unmark_all_dies (die);
9483 md5_finish_ctx (&ctx, checksum);
9485 /* Store the signature in the type node and link the type DIE and the
9486 type node together. */
9487 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9488 DWARF_TYPE_SIGNATURE_SIZE);
9489 die->die_id.die_type_node = type_node;
9490 type_node->type_die = die;
9492 /* If the DIE is a specification, link its declaration to the type node
9495 decl->die_id.die_type_node = type_node;
9498 /* Do the location expressions look same? */
9500 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9502 return loc1->dw_loc_opc == loc2->dw_loc_opc
9503 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9504 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9507 /* Do the values look the same? */
9509 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9511 dw_loc_descr_ref loc1, loc2;
9514 if (v1->val_class != v2->val_class)
9517 switch (v1->val_class)
9519 case dw_val_class_const:
9520 return v1->v.val_int == v2->v.val_int;
9521 case dw_val_class_unsigned_const:
9522 return v1->v.val_unsigned == v2->v.val_unsigned;
9523 case dw_val_class_const_double:
9524 return v1->v.val_double.high == v2->v.val_double.high
9525 && v1->v.val_double.low == v2->v.val_double.low;
9526 case dw_val_class_vec:
9527 if (v1->v.val_vec.length != v2->v.val_vec.length
9528 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9530 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9531 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9534 case dw_val_class_flag:
9535 return v1->v.val_flag == v2->v.val_flag;
9536 case dw_val_class_str:
9537 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9539 case dw_val_class_addr:
9540 r1 = v1->v.val_addr;
9541 r2 = v2->v.val_addr;
9542 if (GET_CODE (r1) != GET_CODE (r2))
9544 return !rtx_equal_p (r1, r2);
9546 case dw_val_class_offset:
9547 return v1->v.val_offset == v2->v.val_offset;
9549 case dw_val_class_loc:
9550 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9552 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9553 if (!same_loc_p (loc1, loc2, mark))
9555 return !loc1 && !loc2;
9557 case dw_val_class_die_ref:
9558 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9560 case dw_val_class_fde_ref:
9561 case dw_val_class_vms_delta:
9562 case dw_val_class_lbl_id:
9563 case dw_val_class_lineptr:
9564 case dw_val_class_macptr:
9567 case dw_val_class_file:
9568 return v1->v.val_file == v2->v.val_file;
9570 case dw_val_class_data8:
9571 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9578 /* Do the attributes look the same? */
9581 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9583 if (at1->dw_attr != at2->dw_attr)
9586 /* We don't care that this was compiled with a different compiler
9587 snapshot; if the output is the same, that's what matters. */
9588 if (at1->dw_attr == DW_AT_producer)
9591 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9594 /* Do the dies look the same? */
9597 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9603 /* To avoid infinite recursion. */
9605 return die1->die_mark == die2->die_mark;
9606 die1->die_mark = die2->die_mark = ++(*mark);
9608 if (die1->die_tag != die2->die_tag)
9611 if (VEC_length (dw_attr_node, die1->die_attr)
9612 != VEC_length (dw_attr_node, die2->die_attr))
9615 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9616 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9619 c1 = die1->die_child;
9620 c2 = die2->die_child;
9629 if (!same_die_p (c1, c2, mark))
9633 if (c1 == die1->die_child)
9635 if (c2 == die2->die_child)
9645 /* Do the dies look the same? Wrapper around same_die_p. */
9648 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9651 int ret = same_die_p (die1, die2, &mark);
9653 unmark_all_dies (die1);
9654 unmark_all_dies (die2);
9659 /* The prefix to attach to symbols on DIEs in the current comdat debug
9661 static char *comdat_symbol_id;
9663 /* The index of the current symbol within the current comdat CU. */
9664 static unsigned int comdat_symbol_number;
9666 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9667 children, and set comdat_symbol_id accordingly. */
9670 compute_section_prefix (dw_die_ref unit_die)
9672 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9673 const char *base = die_name ? lbasename (die_name) : "anonymous";
9674 char *name = XALLOCAVEC (char, strlen (base) + 64);
9677 unsigned char checksum[16];
9680 /* Compute the checksum of the DIE, then append part of it as hex digits to
9681 the name filename of the unit. */
9683 md5_init_ctx (&ctx);
9685 die_checksum (unit_die, &ctx, &mark);
9686 unmark_all_dies (unit_die);
9687 md5_finish_ctx (&ctx, checksum);
9689 sprintf (name, "%s.", base);
9690 clean_symbol_name (name);
9692 p = name + strlen (name);
9693 for (i = 0; i < 4; i++)
9695 sprintf (p, "%.2x", checksum[i]);
9699 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9700 comdat_symbol_number = 0;
9703 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9706 is_type_die (dw_die_ref die)
9708 switch (die->die_tag)
9710 case DW_TAG_array_type:
9711 case DW_TAG_class_type:
9712 case DW_TAG_interface_type:
9713 case DW_TAG_enumeration_type:
9714 case DW_TAG_pointer_type:
9715 case DW_TAG_reference_type:
9716 case DW_TAG_rvalue_reference_type:
9717 case DW_TAG_string_type:
9718 case DW_TAG_structure_type:
9719 case DW_TAG_subroutine_type:
9720 case DW_TAG_union_type:
9721 case DW_TAG_ptr_to_member_type:
9722 case DW_TAG_set_type:
9723 case DW_TAG_subrange_type:
9724 case DW_TAG_base_type:
9725 case DW_TAG_const_type:
9726 case DW_TAG_file_type:
9727 case DW_TAG_packed_type:
9728 case DW_TAG_volatile_type:
9729 case DW_TAG_typedef:
9736 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9737 Basically, we want to choose the bits that are likely to be shared between
9738 compilations (types) and leave out the bits that are specific to individual
9739 compilations (functions). */
9742 is_comdat_die (dw_die_ref c)
9744 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9745 we do for stabs. The advantage is a greater likelihood of sharing between
9746 objects that don't include headers in the same order (and therefore would
9747 put the base types in a different comdat). jason 8/28/00 */
9749 if (c->die_tag == DW_TAG_base_type)
9752 if (c->die_tag == DW_TAG_pointer_type
9753 || c->die_tag == DW_TAG_reference_type
9754 || c->die_tag == DW_TAG_rvalue_reference_type
9755 || c->die_tag == DW_TAG_const_type
9756 || c->die_tag == DW_TAG_volatile_type)
9758 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9760 return t ? is_comdat_die (t) : 0;
9763 return is_type_die (c);
9766 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9767 compilation unit. */
9770 is_symbol_die (dw_die_ref c)
9772 return (is_type_die (c)
9773 || is_declaration_die (c)
9774 || c->die_tag == DW_TAG_namespace
9775 || c->die_tag == DW_TAG_module);
9778 /* Returns true iff C is a compile-unit DIE. */
9781 is_cu_die (dw_die_ref c)
9783 return c && c->die_tag == DW_TAG_compile_unit;
9787 gen_internal_sym (const char *prefix)
9791 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9792 return xstrdup (buf);
9795 /* Assign symbols to all worthy DIEs under DIE. */
9798 assign_symbol_names (dw_die_ref die)
9802 if (is_symbol_die (die))
9804 if (comdat_symbol_id)
9806 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9808 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9809 comdat_symbol_id, comdat_symbol_number++);
9810 die->die_id.die_symbol = xstrdup (p);
9813 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9816 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9819 struct cu_hash_table_entry
9822 unsigned min_comdat_num, max_comdat_num;
9823 struct cu_hash_table_entry *next;
9826 /* Routines to manipulate hash table of CUs. */
9828 htab_cu_hash (const void *of)
9830 const struct cu_hash_table_entry *const entry =
9831 (const struct cu_hash_table_entry *) of;
9833 return htab_hash_string (entry->cu->die_id.die_symbol);
9837 htab_cu_eq (const void *of1, const void *of2)
9839 const struct cu_hash_table_entry *const entry1 =
9840 (const struct cu_hash_table_entry *) of1;
9841 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9843 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9847 htab_cu_del (void *what)
9849 struct cu_hash_table_entry *next,
9850 *entry = (struct cu_hash_table_entry *) what;
9860 /* Check whether we have already seen this CU and set up SYM_NUM
9863 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9865 struct cu_hash_table_entry dummy;
9866 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9868 dummy.max_comdat_num = 0;
9870 slot = (struct cu_hash_table_entry **)
9871 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9875 for (; entry; last = entry, entry = entry->next)
9877 if (same_die_p_wrap (cu, entry->cu))
9883 *sym_num = entry->min_comdat_num;
9887 entry = XCNEW (struct cu_hash_table_entry);
9889 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9890 entry->next = *slot;
9896 /* Record SYM_NUM to record of CU in HTABLE. */
9898 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9900 struct cu_hash_table_entry **slot, *entry;
9902 slot = (struct cu_hash_table_entry **)
9903 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9907 entry->max_comdat_num = sym_num;
9910 /* Traverse the DIE (which is always comp_unit_die), and set up
9911 additional compilation units for each of the include files we see
9912 bracketed by BINCL/EINCL. */
9915 break_out_includes (dw_die_ref die)
9918 dw_die_ref unit = NULL;
9919 limbo_die_node *node, **pnode;
9920 htab_t cu_hash_table;
9924 dw_die_ref prev = c;
9926 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9927 || (unit && is_comdat_die (c)))
9929 dw_die_ref next = c->die_sib;
9931 /* This DIE is for a secondary CU; remove it from the main one. */
9932 remove_child_with_prev (c, prev);
9934 if (c->die_tag == DW_TAG_GNU_BINCL)
9935 unit = push_new_compile_unit (unit, c);
9936 else if (c->die_tag == DW_TAG_GNU_EINCL)
9937 unit = pop_compile_unit (unit);
9939 add_child_die (unit, c);
9941 if (c == die->die_child)
9944 } while (c != die->die_child);
9947 /* We can only use this in debugging, since the frontend doesn't check
9948 to make sure that we leave every include file we enter. */
9952 assign_symbol_names (die);
9953 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9954 for (node = limbo_die_list, pnode = &limbo_die_list;
9960 compute_section_prefix (node->die);
9961 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9962 &comdat_symbol_number);
9963 assign_symbol_names (node->die);
9965 *pnode = node->next;
9968 pnode = &node->next;
9969 record_comdat_symbol_number (node->die, cu_hash_table,
9970 comdat_symbol_number);
9973 htab_delete (cu_hash_table);
9976 /* Return non-zero if this DIE is a declaration. */
9979 is_declaration_die (dw_die_ref die)
9984 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9985 if (a->dw_attr == DW_AT_declaration)
9991 /* Return non-zero if this DIE is nested inside a subprogram. */
9994 is_nested_in_subprogram (dw_die_ref die)
9996 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10000 return local_scope_p (decl);
10003 /* Return non-zero if this is a type DIE that should be moved to a
10004 COMDAT .debug_types section. */
10007 should_move_die_to_comdat (dw_die_ref die)
10009 switch (die->die_tag)
10011 case DW_TAG_class_type:
10012 case DW_TAG_structure_type:
10013 case DW_TAG_enumeration_type:
10014 case DW_TAG_union_type:
10015 /* Don't move declarations, inlined instances, or types nested in a
10017 if (is_declaration_die (die)
10018 || get_AT (die, DW_AT_abstract_origin)
10019 || is_nested_in_subprogram (die))
10022 case DW_TAG_array_type:
10023 case DW_TAG_interface_type:
10024 case DW_TAG_pointer_type:
10025 case DW_TAG_reference_type:
10026 case DW_TAG_rvalue_reference_type:
10027 case DW_TAG_string_type:
10028 case DW_TAG_subroutine_type:
10029 case DW_TAG_ptr_to_member_type:
10030 case DW_TAG_set_type:
10031 case DW_TAG_subrange_type:
10032 case DW_TAG_base_type:
10033 case DW_TAG_const_type:
10034 case DW_TAG_file_type:
10035 case DW_TAG_packed_type:
10036 case DW_TAG_volatile_type:
10037 case DW_TAG_typedef:
10043 /* Make a clone of DIE. */
10046 clone_die (dw_die_ref die)
10052 clone = ggc_alloc_cleared_die_node ();
10053 clone->die_tag = die->die_tag;
10055 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10056 add_dwarf_attr (clone, a);
10061 /* Make a clone of the tree rooted at DIE. */
10064 clone_tree (dw_die_ref die)
10067 dw_die_ref clone = clone_die (die);
10069 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10074 /* Make a clone of DIE as a declaration. */
10077 clone_as_declaration (dw_die_ref die)
10084 /* If the DIE is already a declaration, just clone it. */
10085 if (is_declaration_die (die))
10086 return clone_die (die);
10088 /* If the DIE is a specification, just clone its declaration DIE. */
10089 decl = get_AT_ref (die, DW_AT_specification);
10091 return clone_die (decl);
10093 clone = ggc_alloc_cleared_die_node ();
10094 clone->die_tag = die->die_tag;
10096 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10098 /* We don't want to copy over all attributes.
10099 For example we don't want DW_AT_byte_size because otherwise we will no
10100 longer have a declaration and GDB will treat it as a definition. */
10102 switch (a->dw_attr)
10104 case DW_AT_artificial:
10105 case DW_AT_containing_type:
10106 case DW_AT_external:
10109 case DW_AT_virtuality:
10110 case DW_AT_linkage_name:
10111 case DW_AT_MIPS_linkage_name:
10112 add_dwarf_attr (clone, a);
10114 case DW_AT_byte_size:
10120 if (die->die_id.die_type_node)
10121 add_AT_die_ref (clone, DW_AT_signature, die);
10123 add_AT_flag (clone, DW_AT_declaration, 1);
10127 /* Copy the declaration context to the new compile unit DIE. This includes
10128 any surrounding namespace or type declarations. If the DIE has an
10129 AT_specification attribute, it also includes attributes and children
10130 attached to the specification. */
10133 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10136 dw_die_ref new_decl;
10138 decl = get_AT_ref (die, DW_AT_specification);
10147 /* Copy the type node pointer from the new DIE to the original
10148 declaration DIE so we can forward references later. */
10149 decl->die_id.die_type_node = die->die_id.die_type_node;
10151 remove_AT (die, DW_AT_specification);
10153 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10155 if (a->dw_attr != DW_AT_name
10156 && a->dw_attr != DW_AT_declaration
10157 && a->dw_attr != DW_AT_external)
10158 add_dwarf_attr (die, a);
10161 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10164 if (decl->die_parent != NULL
10165 && decl->die_parent->die_tag != DW_TAG_compile_unit
10166 && decl->die_parent->die_tag != DW_TAG_type_unit)
10168 new_decl = copy_ancestor_tree (unit, decl, NULL);
10169 if (new_decl != NULL)
10171 remove_AT (new_decl, DW_AT_signature);
10172 add_AT_specification (die, new_decl);
10177 /* Generate the skeleton ancestor tree for the given NODE, then clone
10178 the DIE and add the clone into the tree. */
10181 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10183 if (node->new_die != NULL)
10186 node->new_die = clone_as_declaration (node->old_die);
10188 if (node->parent != NULL)
10190 generate_skeleton_ancestor_tree (node->parent);
10191 add_child_die (node->parent->new_die, node->new_die);
10195 /* Generate a skeleton tree of DIEs containing any declarations that are
10196 found in the original tree. We traverse the tree looking for declaration
10197 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10200 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10202 skeleton_chain_node node;
10205 dw_die_ref prev = NULL;
10206 dw_die_ref next = NULL;
10208 node.parent = parent;
10210 first = c = parent->old_die->die_child;
10214 if (prev == NULL || prev->die_sib == c)
10217 next = (c == first ? NULL : c->die_sib);
10219 node.new_die = NULL;
10220 if (is_declaration_die (c))
10222 /* Clone the existing DIE, move the original to the skeleton
10223 tree (which is in the main CU), and put the clone, with
10224 all the original's children, where the original came from. */
10225 dw_die_ref clone = clone_die (c);
10226 move_all_children (c, clone);
10228 replace_child (c, clone, prev);
10229 generate_skeleton_ancestor_tree (parent);
10230 add_child_die (parent->new_die, c);
10234 generate_skeleton_bottom_up (&node);
10235 } while (next != NULL);
10238 /* Wrapper function for generate_skeleton_bottom_up. */
10241 generate_skeleton (dw_die_ref die)
10243 skeleton_chain_node node;
10245 node.old_die = die;
10246 node.new_die = NULL;
10247 node.parent = NULL;
10249 /* If this type definition is nested inside another type,
10250 always leave at least a declaration in its place. */
10251 if (die->die_parent != NULL && is_type_die (die->die_parent))
10252 node.new_die = clone_as_declaration (die);
10254 generate_skeleton_bottom_up (&node);
10255 return node.new_die;
10258 /* Remove the DIE from its parent, possibly replacing it with a cloned
10259 declaration. The original DIE will be moved to a new compile unit
10260 so that existing references to it follow it to the new location. If
10261 any of the original DIE's descendants is a declaration, we need to
10262 replace the original DIE with a skeleton tree and move the
10263 declarations back into the skeleton tree. */
10266 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10268 dw_die_ref skeleton;
10270 skeleton = generate_skeleton (child);
10271 if (skeleton == NULL)
10272 remove_child_with_prev (child, prev);
10275 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10276 replace_child (child, skeleton, prev);
10282 /* Traverse the DIE and set up additional .debug_types sections for each
10283 type worthy of being placed in a COMDAT section. */
10286 break_out_comdat_types (dw_die_ref die)
10290 dw_die_ref prev = NULL;
10291 dw_die_ref next = NULL;
10292 dw_die_ref unit = NULL;
10294 first = c = die->die_child;
10298 if (prev == NULL || prev->die_sib == c)
10301 next = (c == first ? NULL : c->die_sib);
10302 if (should_move_die_to_comdat (c))
10304 dw_die_ref replacement;
10305 comdat_type_node_ref type_node;
10307 /* Create a new type unit DIE as the root for the new tree, and
10308 add it to the list of comdat types. */
10309 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10310 add_AT_unsigned (unit, DW_AT_language,
10311 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10312 type_node = ggc_alloc_cleared_comdat_type_node ();
10313 type_node->root_die = unit;
10314 type_node->next = comdat_type_list;
10315 comdat_type_list = type_node;
10317 /* Generate the type signature. */
10318 generate_type_signature (c, type_node);
10320 /* Copy the declaration context, attributes, and children of the
10321 declaration into the new compile unit DIE. */
10322 copy_declaration_context (unit, c);
10324 /* Remove this DIE from the main CU. */
10325 replacement = remove_child_or_replace_with_skeleton (c, prev);
10327 /* Break out nested types into their own type units. */
10328 break_out_comdat_types (c);
10330 /* Add the DIE to the new compunit. */
10331 add_child_die (unit, c);
10333 if (replacement != NULL)
10336 else if (c->die_tag == DW_TAG_namespace
10337 || c->die_tag == DW_TAG_class_type
10338 || c->die_tag == DW_TAG_structure_type
10339 || c->die_tag == DW_TAG_union_type)
10341 /* Look for nested types that can be broken out. */
10342 break_out_comdat_types (c);
10344 } while (next != NULL);
10347 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10349 struct decl_table_entry
10355 /* Routines to manipulate hash table of copied declarations. */
10358 htab_decl_hash (const void *of)
10360 const struct decl_table_entry *const entry =
10361 (const struct decl_table_entry *) of;
10363 return htab_hash_pointer (entry->orig);
10367 htab_decl_eq (const void *of1, const void *of2)
10369 const struct decl_table_entry *const entry1 =
10370 (const struct decl_table_entry *) of1;
10371 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10373 return entry1->orig == entry2;
10377 htab_decl_del (void *what)
10379 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10384 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10385 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10386 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10387 to check if the ancestor has already been copied into UNIT. */
10390 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10392 dw_die_ref parent = die->die_parent;
10393 dw_die_ref new_parent = unit;
10395 void **slot = NULL;
10396 struct decl_table_entry *entry = NULL;
10400 /* Check if the entry has already been copied to UNIT. */
10401 slot = htab_find_slot_with_hash (decl_table, die,
10402 htab_hash_pointer (die), INSERT);
10403 if (*slot != HTAB_EMPTY_ENTRY)
10405 entry = (struct decl_table_entry *) *slot;
10406 return entry->copy;
10409 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10410 entry = XCNEW (struct decl_table_entry);
10412 entry->copy = NULL;
10416 if (parent != NULL)
10418 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10421 if (parent->die_tag != DW_TAG_compile_unit
10422 && parent->die_tag != DW_TAG_type_unit)
10423 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10426 copy = clone_as_declaration (die);
10427 add_child_die (new_parent, copy);
10429 if (decl_table != NULL)
10431 /* Record the pointer to the copy. */
10432 entry->copy = copy;
10438 /* Walk the DIE and its children, looking for references to incomplete
10439 or trivial types that are unmarked (i.e., that are not in the current
10443 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10449 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10451 if (AT_class (a) == dw_val_class_die_ref)
10453 dw_die_ref targ = AT_ref (a);
10454 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10456 struct decl_table_entry *entry;
10458 if (targ->die_mark != 0 || type_node != NULL)
10461 slot = htab_find_slot_with_hash (decl_table, targ,
10462 htab_hash_pointer (targ), INSERT);
10464 if (*slot != HTAB_EMPTY_ENTRY)
10466 /* TARG has already been copied, so we just need to
10467 modify the reference to point to the copy. */
10468 entry = (struct decl_table_entry *) *slot;
10469 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10473 dw_die_ref parent = unit;
10474 dw_die_ref copy = clone_tree (targ);
10476 /* Make sure the cloned tree is marked as part of the
10480 /* Record in DECL_TABLE that TARG has been copied.
10481 Need to do this now, before the recursive call,
10482 because DECL_TABLE may be expanded and SLOT
10483 would no longer be a valid pointer. */
10484 entry = XCNEW (struct decl_table_entry);
10485 entry->orig = targ;
10486 entry->copy = copy;
10489 /* If TARG has surrounding context, copy its ancestor tree
10490 into the new type unit. */
10491 if (targ->die_parent != NULL
10492 && targ->die_parent->die_tag != DW_TAG_compile_unit
10493 && targ->die_parent->die_tag != DW_TAG_type_unit)
10494 parent = copy_ancestor_tree (unit, targ->die_parent,
10497 add_child_die (parent, copy);
10498 a->dw_attr_val.v.val_die_ref.die = copy;
10500 /* Make sure the newly-copied DIE is walked. If it was
10501 installed in a previously-added context, it won't
10502 get visited otherwise. */
10503 if (parent != unit)
10505 /* Find the highest point of the newly-added tree,
10506 mark each node along the way, and walk from there. */
10507 parent->die_mark = 1;
10508 while (parent->die_parent
10509 && parent->die_parent->die_mark == 0)
10511 parent = parent->die_parent;
10512 parent->die_mark = 1;
10514 copy_decls_walk (unit, parent, decl_table);
10520 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10523 /* Copy declarations for "unworthy" types into the new comdat section.
10524 Incomplete types, modified types, and certain other types aren't broken
10525 out into comdat sections of their own, so they don't have a signature,
10526 and we need to copy the declaration into the same section so that we
10527 don't have an external reference. */
10530 copy_decls_for_unworthy_types (dw_die_ref unit)
10535 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10536 copy_decls_walk (unit, unit, decl_table);
10537 htab_delete (decl_table);
10538 unmark_dies (unit);
10541 /* Traverse the DIE and add a sibling attribute if it may have the
10542 effect of speeding up access to siblings. To save some space,
10543 avoid generating sibling attributes for DIE's without children. */
10546 add_sibling_attributes (dw_die_ref die)
10550 if (! die->die_child)
10553 if (die->die_parent && die != die->die_parent->die_child)
10554 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10556 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10559 /* Output all location lists for the DIE and its children. */
10562 output_location_lists (dw_die_ref die)
10568 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10569 if (AT_class (a) == dw_val_class_loc_list)
10570 output_loc_list (AT_loc_list (a));
10572 FOR_EACH_CHILD (die, c, output_location_lists (c));
10575 /* The format of each DIE (and its attribute value pairs) is encoded in an
10576 abbreviation table. This routine builds the abbreviation table and assigns
10577 a unique abbreviation id for each abbreviation entry. The children of each
10578 die are visited recursively. */
10581 build_abbrev_table (dw_die_ref die)
10583 unsigned long abbrev_id;
10584 unsigned int n_alloc;
10589 /* Scan the DIE references, and mark as external any that refer to
10590 DIEs from other CUs (i.e. those which are not marked). */
10591 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10592 if (AT_class (a) == dw_val_class_die_ref
10593 && AT_ref (a)->die_mark == 0)
10595 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
10596 set_AT_ref_external (a, 1);
10599 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10601 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10602 dw_attr_ref die_a, abbrev_a;
10606 if (abbrev->die_tag != die->die_tag)
10608 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10611 if (VEC_length (dw_attr_node, abbrev->die_attr)
10612 != VEC_length (dw_attr_node, die->die_attr))
10615 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10617 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10618 if ((abbrev_a->dw_attr != die_a->dw_attr)
10619 || (value_format (abbrev_a) != value_format (die_a)))
10629 if (abbrev_id >= abbrev_die_table_in_use)
10631 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10633 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10634 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10637 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10638 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10639 abbrev_die_table_allocated = n_alloc;
10642 ++abbrev_die_table_in_use;
10643 abbrev_die_table[abbrev_id] = die;
10646 die->die_abbrev = abbrev_id;
10647 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10650 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10653 constant_size (unsigned HOST_WIDE_INT value)
10660 log = floor_log2 (value);
10663 log = 1 << (floor_log2 (log) + 1);
10668 /* Return the size of a DIE as it is represented in the
10669 .debug_info section. */
10671 static unsigned long
10672 size_of_die (dw_die_ref die)
10674 unsigned long size = 0;
10678 size += size_of_uleb128 (die->die_abbrev);
10679 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10681 switch (AT_class (a))
10683 case dw_val_class_addr:
10684 size += DWARF2_ADDR_SIZE;
10686 case dw_val_class_offset:
10687 size += DWARF_OFFSET_SIZE;
10689 case dw_val_class_loc:
10691 unsigned long lsize = size_of_locs (AT_loc (a));
10693 /* Block length. */
10694 if (dwarf_version >= 4)
10695 size += size_of_uleb128 (lsize);
10697 size += constant_size (lsize);
10701 case dw_val_class_loc_list:
10702 size += DWARF_OFFSET_SIZE;
10704 case dw_val_class_range_list:
10705 size += DWARF_OFFSET_SIZE;
10707 case dw_val_class_const:
10708 size += size_of_sleb128 (AT_int (a));
10710 case dw_val_class_unsigned_const:
10711 size += constant_size (AT_unsigned (a));
10713 case dw_val_class_const_double:
10714 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10715 if (HOST_BITS_PER_WIDE_INT >= 64)
10716 size++; /* block */
10718 case dw_val_class_vec:
10719 size += constant_size (a->dw_attr_val.v.val_vec.length
10720 * a->dw_attr_val.v.val_vec.elt_size)
10721 + a->dw_attr_val.v.val_vec.length
10722 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10724 case dw_val_class_flag:
10725 if (dwarf_version >= 4)
10726 /* Currently all add_AT_flag calls pass in 1 as last argument,
10727 so DW_FORM_flag_present can be used. If that ever changes,
10728 we'll need to use DW_FORM_flag and have some optimization
10729 in build_abbrev_table that will change those to
10730 DW_FORM_flag_present if it is set to 1 in all DIEs using
10731 the same abbrev entry. */
10732 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10736 case dw_val_class_die_ref:
10737 if (AT_ref_external (a))
10739 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10740 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10741 is sized by target address length, whereas in DWARF3
10742 it's always sized as an offset. */
10743 if (use_debug_types)
10744 size += DWARF_TYPE_SIGNATURE_SIZE;
10745 else if (dwarf_version == 2)
10746 size += DWARF2_ADDR_SIZE;
10748 size += DWARF_OFFSET_SIZE;
10751 size += DWARF_OFFSET_SIZE;
10753 case dw_val_class_fde_ref:
10754 size += DWARF_OFFSET_SIZE;
10756 case dw_val_class_lbl_id:
10757 size += DWARF2_ADDR_SIZE;
10759 case dw_val_class_lineptr:
10760 case dw_val_class_macptr:
10761 size += DWARF_OFFSET_SIZE;
10763 case dw_val_class_str:
10764 if (AT_string_form (a) == DW_FORM_strp)
10765 size += DWARF_OFFSET_SIZE;
10767 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10769 case dw_val_class_file:
10770 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10772 case dw_val_class_data8:
10775 case dw_val_class_vms_delta:
10776 size += DWARF_OFFSET_SIZE;
10779 gcc_unreachable ();
10786 /* Size the debugging information associated with a given DIE. Visits the
10787 DIE's children recursively. Updates the global variable next_die_offset, on
10788 each time through. Uses the current value of next_die_offset to update the
10789 die_offset field in each DIE. */
10792 calc_die_sizes (dw_die_ref die)
10796 die->die_offset = next_die_offset;
10797 next_die_offset += size_of_die (die);
10799 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10801 if (die->die_child != NULL)
10802 /* Count the null byte used to terminate sibling lists. */
10803 next_die_offset += 1;
10806 /* Set the marks for a die and its children. We do this so
10807 that we know whether or not a reference needs to use FORM_ref_addr; only
10808 DIEs in the same CU will be marked. We used to clear out the offset
10809 and use that as the flag, but ran into ordering problems. */
10812 mark_dies (dw_die_ref die)
10816 gcc_assert (!die->die_mark);
10819 FOR_EACH_CHILD (die, c, mark_dies (c));
10822 /* Clear the marks for a die and its children. */
10825 unmark_dies (dw_die_ref die)
10829 if (! use_debug_types)
10830 gcc_assert (die->die_mark);
10833 FOR_EACH_CHILD (die, c, unmark_dies (c));
10836 /* Clear the marks for a die, its children and referred dies. */
10839 unmark_all_dies (dw_die_ref die)
10845 if (!die->die_mark)
10849 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10851 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10852 if (AT_class (a) == dw_val_class_die_ref)
10853 unmark_all_dies (AT_ref (a));
10856 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10857 generated for the compilation unit. */
10859 static unsigned long
10860 size_of_pubnames (VEC (pubname_entry, gc) * names)
10862 unsigned long size;
10866 size = DWARF_PUBNAMES_HEADER_SIZE;
10867 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10868 if (names != pubtype_table
10869 || p->die->die_offset != 0
10870 || !flag_eliminate_unused_debug_types)
10871 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10873 size += DWARF_OFFSET_SIZE;
10877 /* Return the size of the information in the .debug_aranges section. */
10879 static unsigned long
10880 size_of_aranges (void)
10882 unsigned long size;
10884 size = DWARF_ARANGES_HEADER_SIZE;
10886 /* Count the address/length pair for this compilation unit. */
10887 if (text_section_used)
10888 size += 2 * DWARF2_ADDR_SIZE;
10889 if (cold_text_section_used)
10890 size += 2 * DWARF2_ADDR_SIZE;
10891 if (have_multiple_function_sections)
10893 unsigned fde_idx = 0;
10895 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
10897 dw_fde_ref fde = &fde_table[fde_idx];
10899 if (!fde->in_std_section)
10900 size += 2 * DWARF2_ADDR_SIZE;
10901 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
10902 size += 2 * DWARF2_ADDR_SIZE;
10906 /* Count the two zero words used to terminated the address range table. */
10907 size += 2 * DWARF2_ADDR_SIZE;
10911 /* Select the encoding of an attribute value. */
10913 static enum dwarf_form
10914 value_format (dw_attr_ref a)
10916 switch (a->dw_attr_val.val_class)
10918 case dw_val_class_addr:
10919 /* Only very few attributes allow DW_FORM_addr. */
10920 switch (a->dw_attr)
10923 case DW_AT_high_pc:
10924 case DW_AT_entry_pc:
10925 case DW_AT_trampoline:
10926 return DW_FORM_addr;
10930 switch (DWARF2_ADDR_SIZE)
10933 return DW_FORM_data1;
10935 return DW_FORM_data2;
10937 return DW_FORM_data4;
10939 return DW_FORM_data8;
10941 gcc_unreachable ();
10943 case dw_val_class_range_list:
10944 case dw_val_class_loc_list:
10945 if (dwarf_version >= 4)
10946 return DW_FORM_sec_offset;
10948 case dw_val_class_vms_delta:
10949 case dw_val_class_offset:
10950 switch (DWARF_OFFSET_SIZE)
10953 return DW_FORM_data4;
10955 return DW_FORM_data8;
10957 gcc_unreachable ();
10959 case dw_val_class_loc:
10960 if (dwarf_version >= 4)
10961 return DW_FORM_exprloc;
10962 switch (constant_size (size_of_locs (AT_loc (a))))
10965 return DW_FORM_block1;
10967 return DW_FORM_block2;
10969 gcc_unreachable ();
10971 case dw_val_class_const:
10972 return DW_FORM_sdata;
10973 case dw_val_class_unsigned_const:
10974 switch (constant_size (AT_unsigned (a)))
10977 return DW_FORM_data1;
10979 return DW_FORM_data2;
10981 return DW_FORM_data4;
10983 return DW_FORM_data8;
10985 gcc_unreachable ();
10987 case dw_val_class_const_double:
10988 switch (HOST_BITS_PER_WIDE_INT)
10991 return DW_FORM_data2;
10993 return DW_FORM_data4;
10995 return DW_FORM_data8;
10998 return DW_FORM_block1;
11000 case dw_val_class_vec:
11001 switch (constant_size (a->dw_attr_val.v.val_vec.length
11002 * a->dw_attr_val.v.val_vec.elt_size))
11005 return DW_FORM_block1;
11007 return DW_FORM_block2;
11009 return DW_FORM_block4;
11011 gcc_unreachable ();
11013 case dw_val_class_flag:
11014 if (dwarf_version >= 4)
11016 /* Currently all add_AT_flag calls pass in 1 as last argument,
11017 so DW_FORM_flag_present can be used. If that ever changes,
11018 we'll need to use DW_FORM_flag and have some optimization
11019 in build_abbrev_table that will change those to
11020 DW_FORM_flag_present if it is set to 1 in all DIEs using
11021 the same abbrev entry. */
11022 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11023 return DW_FORM_flag_present;
11025 return DW_FORM_flag;
11026 case dw_val_class_die_ref:
11027 if (AT_ref_external (a))
11028 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11030 return DW_FORM_ref;
11031 case dw_val_class_fde_ref:
11032 return DW_FORM_data;
11033 case dw_val_class_lbl_id:
11034 return DW_FORM_addr;
11035 case dw_val_class_lineptr:
11036 case dw_val_class_macptr:
11037 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11038 case dw_val_class_str:
11039 return AT_string_form (a);
11040 case dw_val_class_file:
11041 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11044 return DW_FORM_data1;
11046 return DW_FORM_data2;
11048 return DW_FORM_data4;
11050 gcc_unreachable ();
11053 case dw_val_class_data8:
11054 return DW_FORM_data8;
11057 gcc_unreachable ();
11061 /* Output the encoding of an attribute value. */
11064 output_value_format (dw_attr_ref a)
11066 enum dwarf_form form = value_format (a);
11068 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11071 /* Output the .debug_abbrev section which defines the DIE abbreviation
11075 output_abbrev_section (void)
11077 unsigned long abbrev_id;
11079 if (abbrev_die_table_in_use == 1)
11082 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11084 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11086 dw_attr_ref a_attr;
11088 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11089 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11090 dwarf_tag_name (abbrev->die_tag));
11092 if (abbrev->die_child != NULL)
11093 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11095 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11097 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11100 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11101 dwarf_attr_name (a_attr->dw_attr));
11102 output_value_format (a_attr);
11105 dw2_asm_output_data (1, 0, NULL);
11106 dw2_asm_output_data (1, 0, NULL);
11109 /* Terminate the table. */
11110 dw2_asm_output_data (1, 0, NULL);
11113 /* Output a symbol we can use to refer to this DIE from another CU. */
11116 output_die_symbol (dw_die_ref die)
11118 char *sym = die->die_id.die_symbol;
11123 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11124 /* We make these global, not weak; if the target doesn't support
11125 .linkonce, it doesn't support combining the sections, so debugging
11127 targetm.asm_out.globalize_label (asm_out_file, sym);
11129 ASM_OUTPUT_LABEL (asm_out_file, sym);
11132 /* Return a new location list, given the begin and end range, and the
11135 static inline dw_loc_list_ref
11136 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11137 const char *section)
11139 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11141 retlist->begin = begin;
11142 retlist->end = end;
11143 retlist->expr = expr;
11144 retlist->section = section;
11149 /* Generate a new internal symbol for this location list node, if it
11150 hasn't got one yet. */
11153 gen_llsym (dw_loc_list_ref list)
11155 gcc_assert (!list->ll_symbol);
11156 list->ll_symbol = gen_internal_sym ("LLST");
11159 /* Output the location list given to us. */
11162 output_loc_list (dw_loc_list_ref list_head)
11164 dw_loc_list_ref curr = list_head;
11166 if (list_head->emitted)
11168 list_head->emitted = true;
11170 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11172 /* Walk the location list, and output each range + expression. */
11173 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11175 unsigned long size;
11176 /* Don't output an entry that starts and ends at the same address. */
11177 if (strcmp (curr->begin, curr->end) == 0)
11179 if (!have_multiple_function_sections)
11181 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11182 "Location list begin address (%s)",
11183 list_head->ll_symbol);
11184 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11185 "Location list end address (%s)",
11186 list_head->ll_symbol);
11190 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11191 "Location list begin address (%s)",
11192 list_head->ll_symbol);
11193 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11194 "Location list end address (%s)",
11195 list_head->ll_symbol);
11197 size = size_of_locs (curr->expr);
11199 /* Output the block length for this list of location operations. */
11200 gcc_assert (size <= 0xffff);
11201 dw2_asm_output_data (2, size, "%s", "Location expression size");
11203 output_loc_sequence (curr->expr, -1);
11206 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11207 "Location list terminator begin (%s)",
11208 list_head->ll_symbol);
11209 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11210 "Location list terminator end (%s)",
11211 list_head->ll_symbol);
11214 /* Output a type signature. */
11217 output_signature (const char *sig, const char *name)
11221 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11222 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11225 /* Output the DIE and its attributes. Called recursively to generate
11226 the definitions of each child DIE. */
11229 output_die (dw_die_ref die)
11233 unsigned long size;
11236 /* If someone in another CU might refer to us, set up a symbol for
11237 them to point to. */
11238 if (! use_debug_types && die->die_id.die_symbol)
11239 output_die_symbol (die);
11241 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11242 (unsigned long)die->die_offset,
11243 dwarf_tag_name (die->die_tag));
11245 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11247 const char *name = dwarf_attr_name (a->dw_attr);
11249 switch (AT_class (a))
11251 case dw_val_class_addr:
11252 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11255 case dw_val_class_offset:
11256 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11260 case dw_val_class_range_list:
11262 char *p = strchr (ranges_section_label, '\0');
11264 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11265 a->dw_attr_val.v.val_offset);
11266 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11267 debug_ranges_section, "%s", name);
11272 case dw_val_class_loc:
11273 size = size_of_locs (AT_loc (a));
11275 /* Output the block length for this list of location operations. */
11276 if (dwarf_version >= 4)
11277 dw2_asm_output_data_uleb128 (size, "%s", name);
11279 dw2_asm_output_data (constant_size (size), size, "%s", name);
11281 output_loc_sequence (AT_loc (a), -1);
11284 case dw_val_class_const:
11285 /* ??? It would be slightly more efficient to use a scheme like is
11286 used for unsigned constants below, but gdb 4.x does not sign
11287 extend. Gdb 5.x does sign extend. */
11288 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11291 case dw_val_class_unsigned_const:
11292 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11293 AT_unsigned (a), "%s", name);
11296 case dw_val_class_const_double:
11298 unsigned HOST_WIDE_INT first, second;
11300 if (HOST_BITS_PER_WIDE_INT >= 64)
11301 dw2_asm_output_data (1,
11302 2 * HOST_BITS_PER_WIDE_INT
11303 / HOST_BITS_PER_CHAR,
11306 if (WORDS_BIG_ENDIAN)
11308 first = a->dw_attr_val.v.val_double.high;
11309 second = a->dw_attr_val.v.val_double.low;
11313 first = a->dw_attr_val.v.val_double.low;
11314 second = a->dw_attr_val.v.val_double.high;
11317 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11319 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11324 case dw_val_class_vec:
11326 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11327 unsigned int len = a->dw_attr_val.v.val_vec.length;
11331 dw2_asm_output_data (constant_size (len * elt_size),
11332 len * elt_size, "%s", name);
11333 if (elt_size > sizeof (HOST_WIDE_INT))
11338 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11340 i++, p += elt_size)
11341 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11342 "fp or vector constant word %u", i);
11346 case dw_val_class_flag:
11347 if (dwarf_version >= 4)
11349 /* Currently all add_AT_flag calls pass in 1 as last argument,
11350 so DW_FORM_flag_present can be used. If that ever changes,
11351 we'll need to use DW_FORM_flag and have some optimization
11352 in build_abbrev_table that will change those to
11353 DW_FORM_flag_present if it is set to 1 in all DIEs using
11354 the same abbrev entry. */
11355 gcc_assert (AT_flag (a) == 1);
11356 if (flag_debug_asm)
11357 fprintf (asm_out_file, "\t\t\t%s %s\n",
11358 ASM_COMMENT_START, name);
11361 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11364 case dw_val_class_loc_list:
11366 char *sym = AT_loc_list (a)->ll_symbol;
11369 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11374 case dw_val_class_die_ref:
11375 if (AT_ref_external (a))
11377 if (use_debug_types)
11379 comdat_type_node_ref type_node =
11380 AT_ref (a)->die_id.die_type_node;
11382 gcc_assert (type_node);
11383 output_signature (type_node->signature, name);
11387 char *sym = AT_ref (a)->die_id.die_symbol;
11391 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11392 length, whereas in DWARF3 it's always sized as an
11394 if (dwarf_version == 2)
11395 size = DWARF2_ADDR_SIZE;
11397 size = DWARF_OFFSET_SIZE;
11398 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11404 gcc_assert (AT_ref (a)->die_offset);
11405 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11410 case dw_val_class_fde_ref:
11414 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11415 a->dw_attr_val.v.val_fde_index * 2);
11416 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11421 case dw_val_class_vms_delta:
11422 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11423 AT_vms_delta2 (a), AT_vms_delta1 (a),
11427 case dw_val_class_lbl_id:
11428 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11431 case dw_val_class_lineptr:
11432 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11433 debug_line_section, "%s", name);
11436 case dw_val_class_macptr:
11437 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11438 debug_macinfo_section, "%s", name);
11441 case dw_val_class_str:
11442 if (AT_string_form (a) == DW_FORM_strp)
11443 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11444 a->dw_attr_val.v.val_str->label,
11446 "%s: \"%s\"", name, AT_string (a));
11448 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11451 case dw_val_class_file:
11453 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11455 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11456 a->dw_attr_val.v.val_file->filename);
11460 case dw_val_class_data8:
11464 for (i = 0; i < 8; i++)
11465 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11466 i == 0 ? "%s" : NULL, name);
11471 gcc_unreachable ();
11475 FOR_EACH_CHILD (die, c, output_die (c));
11477 /* Add null byte to terminate sibling list. */
11478 if (die->die_child != NULL)
11479 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11480 (unsigned long) die->die_offset);
11483 /* Output the compilation unit that appears at the beginning of the
11484 .debug_info section, and precedes the DIE descriptions. */
11487 output_compilation_unit_header (void)
11489 int ver = dwarf_version;
11491 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11492 dw2_asm_output_data (4, 0xffffffff,
11493 "Initial length escape value indicating 64-bit DWARF extension");
11494 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11495 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11496 "Length of Compilation Unit Info");
11497 dw2_asm_output_data (2, ver, "DWARF version number");
11498 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11499 debug_abbrev_section,
11500 "Offset Into Abbrev. Section");
11501 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11504 /* Output the compilation unit DIE and its children. */
11507 output_comp_unit (dw_die_ref die, int output_if_empty)
11509 const char *secname;
11510 char *oldsym, *tmp;
11512 /* Unless we are outputting main CU, we may throw away empty ones. */
11513 if (!output_if_empty && die->die_child == NULL)
11516 /* Even if there are no children of this DIE, we must output the information
11517 about the compilation unit. Otherwise, on an empty translation unit, we
11518 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11519 will then complain when examining the file. First mark all the DIEs in
11520 this CU so we know which get local refs. */
11523 build_abbrev_table (die);
11525 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11526 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11527 calc_die_sizes (die);
11529 oldsym = die->die_id.die_symbol;
11532 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11534 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11536 die->die_id.die_symbol = NULL;
11537 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11541 switch_to_section (debug_info_section);
11542 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11543 info_section_emitted = true;
11546 /* Output debugging information. */
11547 output_compilation_unit_header ();
11550 /* Leave the marks on the main CU, so we can check them in
11551 output_pubnames. */
11555 die->die_id.die_symbol = oldsym;
11559 /* Output a comdat type unit DIE and its children. */
11562 output_comdat_type_unit (comdat_type_node *node)
11564 const char *secname;
11567 #if defined (OBJECT_FORMAT_ELF)
11571 /* First mark all the DIEs in this CU so we know which get local refs. */
11572 mark_dies (node->root_die);
11574 build_abbrev_table (node->root_die);
11576 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11577 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11578 calc_die_sizes (node->root_die);
11580 #if defined (OBJECT_FORMAT_ELF)
11581 secname = ".debug_types";
11582 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11583 sprintf (tmp, "wt.");
11584 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11585 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11586 comdat_key = get_identifier (tmp);
11587 targetm.asm_out.named_section (secname,
11588 SECTION_DEBUG | SECTION_LINKONCE,
11591 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11592 sprintf (tmp, ".gnu.linkonce.wt.");
11593 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11594 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11596 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11599 /* Output debugging information. */
11600 output_compilation_unit_header ();
11601 output_signature (node->signature, "Type Signature");
11602 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11603 "Offset to Type DIE");
11604 output_die (node->root_die);
11606 unmark_dies (node->root_die);
11609 /* Return the DWARF2/3 pubname associated with a decl. */
11611 static const char *
11612 dwarf2_name (tree decl, int scope)
11614 if (DECL_NAMELESS (decl))
11616 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11619 /* Add a new entry to .debug_pubnames if appropriate. */
11622 add_pubname_string (const char *str, dw_die_ref die)
11624 if (targetm.want_debug_pub_sections)
11629 e.name = xstrdup (str);
11630 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11635 add_pubname (tree decl, dw_die_ref die)
11637 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11639 const char *name = dwarf2_name (decl, 1);
11641 add_pubname_string (name, die);
11645 /* Add a new entry to .debug_pubtypes if appropriate. */
11648 add_pubtype (tree decl, dw_die_ref die)
11652 if (!targetm.want_debug_pub_sections)
11656 if ((TREE_PUBLIC (decl)
11657 || is_cu_die (die->die_parent))
11658 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11663 if (TYPE_NAME (decl))
11665 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11666 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11667 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11668 && DECL_NAME (TYPE_NAME (decl)))
11669 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11671 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11676 e.name = dwarf2_name (decl, 1);
11678 e.name = xstrdup (e.name);
11681 /* If we don't have a name for the type, there's no point in adding
11682 it to the table. */
11683 if (e.name && e.name[0] != '\0')
11684 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11688 /* Output the public names table used to speed up access to externally
11689 visible names; or the public types table used to find type definitions. */
11692 output_pubnames (VEC (pubname_entry, gc) * names)
11695 unsigned long pubnames_length = size_of_pubnames (names);
11698 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11699 dw2_asm_output_data (4, 0xffffffff,
11700 "Initial length escape value indicating 64-bit DWARF extension");
11701 if (names == pubname_table)
11702 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11703 "Length of Public Names Info");
11705 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11706 "Length of Public Type Names Info");
11707 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11708 dw2_asm_output_data (2, 2, "DWARF Version");
11709 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11710 debug_info_section,
11711 "Offset of Compilation Unit Info");
11712 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11713 "Compilation Unit Length");
11715 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11717 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11718 if (names == pubname_table)
11719 gcc_assert (pub->die->die_mark);
11721 if (names != pubtype_table
11722 || pub->die->die_offset != 0
11723 || !flag_eliminate_unused_debug_types)
11725 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11728 dw2_asm_output_nstring (pub->name, -1, "external name");
11732 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11735 /* Output the information that goes into the .debug_aranges table.
11736 Namely, define the beginning and ending address range of the
11737 text section generated for this compilation unit. */
11740 output_aranges (unsigned long aranges_length)
11744 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11745 dw2_asm_output_data (4, 0xffffffff,
11746 "Initial length escape value indicating 64-bit DWARF extension");
11747 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11748 "Length of Address Ranges Info");
11749 /* Version number for aranges is still 2, even in DWARF3. */
11750 dw2_asm_output_data (2, 2, "DWARF Version");
11751 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11752 debug_info_section,
11753 "Offset of Compilation Unit Info");
11754 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11755 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11757 /* We need to align to twice the pointer size here. */
11758 if (DWARF_ARANGES_PAD_SIZE)
11760 /* Pad using a 2 byte words so that padding is correct for any
11762 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11763 2 * DWARF2_ADDR_SIZE);
11764 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11765 dw2_asm_output_data (2, 0, NULL);
11768 /* It is necessary not to output these entries if the sections were
11769 not used; if the sections were not used, the length will be 0 and
11770 the address may end up as 0 if the section is discarded by ld
11771 --gc-sections, leaving an invalid (0, 0) entry that can be
11772 confused with the terminator. */
11773 if (text_section_used)
11775 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11776 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11777 text_section_label, "Length");
11779 if (cold_text_section_used)
11781 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11783 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11784 cold_text_section_label, "Length");
11787 if (have_multiple_function_sections)
11789 unsigned fde_idx = 0;
11791 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11793 dw_fde_ref fde = &fde_table[fde_idx];
11795 if (!fde->in_std_section)
11797 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11799 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11800 fde->dw_fde_begin, "Length");
11802 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11804 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11806 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
11807 fde->dw_fde_second_begin, "Length");
11812 /* Output the terminator words. */
11813 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11814 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11817 /* Add a new entry to .debug_ranges. Return the offset at which it
11820 static unsigned int
11821 add_ranges_num (int num)
11823 unsigned int in_use = ranges_table_in_use;
11825 if (in_use == ranges_table_allocated)
11827 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11828 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11829 ranges_table_allocated);
11830 memset (ranges_table + ranges_table_in_use, 0,
11831 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11834 ranges_table[in_use].num = num;
11835 ranges_table_in_use = in_use + 1;
11837 return in_use * 2 * DWARF2_ADDR_SIZE;
11840 /* Add a new entry to .debug_ranges corresponding to a block, or a
11841 range terminator if BLOCK is NULL. */
11843 static unsigned int
11844 add_ranges (const_tree block)
11846 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11849 /* Add a new entry to .debug_ranges corresponding to a pair of
11853 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11856 unsigned int in_use = ranges_by_label_in_use;
11857 unsigned int offset;
11859 if (in_use == ranges_by_label_allocated)
11861 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11862 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11864 ranges_by_label_allocated);
11865 memset (ranges_by_label + ranges_by_label_in_use, 0,
11866 RANGES_TABLE_INCREMENT
11867 * sizeof (struct dw_ranges_by_label_struct));
11870 ranges_by_label[in_use].begin = begin;
11871 ranges_by_label[in_use].end = end;
11872 ranges_by_label_in_use = in_use + 1;
11874 offset = add_ranges_num (-(int)in_use - 1);
11877 add_AT_range_list (die, DW_AT_ranges, offset);
11883 output_ranges (void)
11886 static const char *const start_fmt = "Offset %#x";
11887 const char *fmt = start_fmt;
11889 for (i = 0; i < ranges_table_in_use; i++)
11891 int block_num = ranges_table[i].num;
11895 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11896 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11898 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11899 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11901 /* If all code is in the text section, then the compilation
11902 unit base address defaults to DW_AT_low_pc, which is the
11903 base of the text section. */
11904 if (!have_multiple_function_sections)
11906 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11907 text_section_label,
11908 fmt, i * 2 * DWARF2_ADDR_SIZE);
11909 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11910 text_section_label, NULL);
11913 /* Otherwise, the compilation unit base address is zero,
11914 which allows us to use absolute addresses, and not worry
11915 about whether the target supports cross-section
11919 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11920 fmt, i * 2 * DWARF2_ADDR_SIZE);
11921 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11927 /* Negative block_num stands for an index into ranges_by_label. */
11928 else if (block_num < 0)
11930 int lab_idx = - block_num - 1;
11932 if (!have_multiple_function_sections)
11934 gcc_unreachable ();
11936 /* If we ever use add_ranges_by_labels () for a single
11937 function section, all we have to do is to take out
11938 the #if 0 above. */
11939 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11940 ranges_by_label[lab_idx].begin,
11941 text_section_label,
11942 fmt, i * 2 * DWARF2_ADDR_SIZE);
11943 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11944 ranges_by_label[lab_idx].end,
11945 text_section_label, NULL);
11950 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11951 ranges_by_label[lab_idx].begin,
11952 fmt, i * 2 * DWARF2_ADDR_SIZE);
11953 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11954 ranges_by_label[lab_idx].end,
11960 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11961 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11967 /* Data structure containing information about input files. */
11970 const char *path; /* Complete file name. */
11971 const char *fname; /* File name part. */
11972 int length; /* Length of entire string. */
11973 struct dwarf_file_data * file_idx; /* Index in input file table. */
11974 int dir_idx; /* Index in directory table. */
11977 /* Data structure containing information about directories with source
11981 const char *path; /* Path including directory name. */
11982 int length; /* Path length. */
11983 int prefix; /* Index of directory entry which is a prefix. */
11984 int count; /* Number of files in this directory. */
11985 int dir_idx; /* Index of directory used as base. */
11988 /* Callback function for file_info comparison. We sort by looking at
11989 the directories in the path. */
11992 file_info_cmp (const void *p1, const void *p2)
11994 const struct file_info *const s1 = (const struct file_info *) p1;
11995 const struct file_info *const s2 = (const struct file_info *) p2;
11996 const unsigned char *cp1;
11997 const unsigned char *cp2;
11999 /* Take care of file names without directories. We need to make sure that
12000 we return consistent values to qsort since some will get confused if
12001 we return the same value when identical operands are passed in opposite
12002 orders. So if neither has a directory, return 0 and otherwise return
12003 1 or -1 depending on which one has the directory. */
12004 if ((s1->path == s1->fname || s2->path == s2->fname))
12005 return (s2->path == s2->fname) - (s1->path == s1->fname);
12007 cp1 = (const unsigned char *) s1->path;
12008 cp2 = (const unsigned char *) s2->path;
12014 /* Reached the end of the first path? If so, handle like above. */
12015 if ((cp1 == (const unsigned char *) s1->fname)
12016 || (cp2 == (const unsigned char *) s2->fname))
12017 return ((cp2 == (const unsigned char *) s2->fname)
12018 - (cp1 == (const unsigned char *) s1->fname));
12020 /* Character of current path component the same? */
12021 else if (*cp1 != *cp2)
12022 return *cp1 - *cp2;
12026 struct file_name_acquire_data
12028 struct file_info *files;
12033 /* Traversal function for the hash table. */
12036 file_name_acquire (void ** slot, void *data)
12038 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12039 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12040 struct file_info *fi;
12043 gcc_assert (fnad->max_files >= d->emitted_number);
12045 if (! d->emitted_number)
12048 gcc_assert (fnad->max_files != fnad->used_files);
12050 fi = fnad->files + fnad->used_files++;
12052 /* Skip all leading "./". */
12054 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12057 /* Create a new array entry. */
12059 fi->length = strlen (f);
12062 /* Search for the file name part. */
12063 f = strrchr (f, DIR_SEPARATOR);
12064 #if defined (DIR_SEPARATOR_2)
12066 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12070 if (f == NULL || f < g)
12076 fi->fname = f == NULL ? fi->path : f + 1;
12080 /* Output the directory table and the file name table. We try to minimize
12081 the total amount of memory needed. A heuristic is used to avoid large
12082 slowdowns with many input files. */
12085 output_file_names (void)
12087 struct file_name_acquire_data fnad;
12089 struct file_info *files;
12090 struct dir_info *dirs;
12098 if (!last_emitted_file)
12100 dw2_asm_output_data (1, 0, "End directory table");
12101 dw2_asm_output_data (1, 0, "End file name table");
12105 numfiles = last_emitted_file->emitted_number;
12107 /* Allocate the various arrays we need. */
12108 files = XALLOCAVEC (struct file_info, numfiles);
12109 dirs = XALLOCAVEC (struct dir_info, numfiles);
12111 fnad.files = files;
12112 fnad.used_files = 0;
12113 fnad.max_files = numfiles;
12114 htab_traverse (file_table, file_name_acquire, &fnad);
12115 gcc_assert (fnad.used_files == fnad.max_files);
12117 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12119 /* Find all the different directories used. */
12120 dirs[0].path = files[0].path;
12121 dirs[0].length = files[0].fname - files[0].path;
12122 dirs[0].prefix = -1;
12124 dirs[0].dir_idx = 0;
12125 files[0].dir_idx = 0;
12128 for (i = 1; i < numfiles; i++)
12129 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12130 && memcmp (dirs[ndirs - 1].path, files[i].path,
12131 dirs[ndirs - 1].length) == 0)
12133 /* Same directory as last entry. */
12134 files[i].dir_idx = ndirs - 1;
12135 ++dirs[ndirs - 1].count;
12141 /* This is a new directory. */
12142 dirs[ndirs].path = files[i].path;
12143 dirs[ndirs].length = files[i].fname - files[i].path;
12144 dirs[ndirs].count = 1;
12145 dirs[ndirs].dir_idx = ndirs;
12146 files[i].dir_idx = ndirs;
12148 /* Search for a prefix. */
12149 dirs[ndirs].prefix = -1;
12150 for (j = 0; j < ndirs; j++)
12151 if (dirs[j].length < dirs[ndirs].length
12152 && dirs[j].length > 1
12153 && (dirs[ndirs].prefix == -1
12154 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12155 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12156 dirs[ndirs].prefix = j;
12161 /* Now to the actual work. We have to find a subset of the directories which
12162 allow expressing the file name using references to the directory table
12163 with the least amount of characters. We do not do an exhaustive search
12164 where we would have to check out every combination of every single
12165 possible prefix. Instead we use a heuristic which provides nearly optimal
12166 results in most cases and never is much off. */
12167 saved = XALLOCAVEC (int, ndirs);
12168 savehere = XALLOCAVEC (int, ndirs);
12170 memset (saved, '\0', ndirs * sizeof (saved[0]));
12171 for (i = 0; i < ndirs; i++)
12176 /* We can always save some space for the current directory. But this
12177 does not mean it will be enough to justify adding the directory. */
12178 savehere[i] = dirs[i].length;
12179 total = (savehere[i] - saved[i]) * dirs[i].count;
12181 for (j = i + 1; j < ndirs; j++)
12184 if (saved[j] < dirs[i].length)
12186 /* Determine whether the dirs[i] path is a prefix of the
12190 k = dirs[j].prefix;
12191 while (k != -1 && k != (int) i)
12192 k = dirs[k].prefix;
12196 /* Yes it is. We can possibly save some memory by
12197 writing the filenames in dirs[j] relative to
12199 savehere[j] = dirs[i].length;
12200 total += (savehere[j] - saved[j]) * dirs[j].count;
12205 /* Check whether we can save enough to justify adding the dirs[i]
12207 if (total > dirs[i].length + 1)
12209 /* It's worthwhile adding. */
12210 for (j = i; j < ndirs; j++)
12211 if (savehere[j] > 0)
12213 /* Remember how much we saved for this directory so far. */
12214 saved[j] = savehere[j];
12216 /* Remember the prefix directory. */
12217 dirs[j].dir_idx = i;
12222 /* Emit the directory name table. */
12223 idx_offset = dirs[0].length > 0 ? 1 : 0;
12224 for (i = 1 - idx_offset; i < ndirs; i++)
12225 dw2_asm_output_nstring (dirs[i].path,
12227 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12228 "Directory Entry: %#x", i + idx_offset);
12230 dw2_asm_output_data (1, 0, "End directory table");
12232 /* We have to emit them in the order of emitted_number since that's
12233 used in the debug info generation. To do this efficiently we
12234 generate a back-mapping of the indices first. */
12235 backmap = XALLOCAVEC (int, numfiles);
12236 for (i = 0; i < numfiles; i++)
12237 backmap[files[i].file_idx->emitted_number - 1] = i;
12239 /* Now write all the file names. */
12240 for (i = 0; i < numfiles; i++)
12242 int file_idx = backmap[i];
12243 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12245 #ifdef VMS_DEBUGGING_INFO
12246 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12248 /* Setting these fields can lead to debugger miscomparisons,
12249 but VMS Debug requires them to be set correctly. */
12254 int maxfilelen = strlen (files[file_idx].path)
12255 + dirs[dir_idx].length
12256 + MAX_VMS_VERSION_LEN + 1;
12257 char *filebuf = XALLOCAVEC (char, maxfilelen);
12259 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12260 snprintf (filebuf, maxfilelen, "%s;%d",
12261 files[file_idx].path + dirs[dir_idx].length, ver);
12263 dw2_asm_output_nstring
12264 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12266 /* Include directory index. */
12267 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12269 /* Modification time. */
12270 dw2_asm_output_data_uleb128
12271 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12275 /* File length in bytes. */
12276 dw2_asm_output_data_uleb128
12277 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12281 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12282 "File Entry: %#x", (unsigned) i + 1);
12284 /* Include directory index. */
12285 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12287 /* Modification time. */
12288 dw2_asm_output_data_uleb128 (0, NULL);
12290 /* File length in bytes. */
12291 dw2_asm_output_data_uleb128 (0, NULL);
12292 #endif /* VMS_DEBUGGING_INFO */
12295 dw2_asm_output_data (1, 0, "End file name table");
12299 /* Output one line number table into the .debug_line section. */
12302 output_one_line_info_table (dw_line_info_table *table)
12304 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12305 unsigned int current_line = 1;
12306 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12307 dw_line_info_entry *ent;
12310 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
12312 switch (ent->opcode)
12314 case LI_set_address:
12315 /* ??? Unfortunately, we have little choice here currently, and
12316 must always use the most general form. GCC does not know the
12317 address delta itself, so we can't use DW_LNS_advance_pc. Many
12318 ports do have length attributes which will give an upper bound
12319 on the address range. We could perhaps use length attributes
12320 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12321 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12323 /* This can handle any delta. This takes
12324 4+DWARF2_ADDR_SIZE bytes. */
12325 dw2_asm_output_data (1, 0, "set address %s", line_label);
12326 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12327 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12328 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12332 if (ent->val == current_line)
12334 /* We still need to start a new row, so output a copy insn. */
12335 dw2_asm_output_data (1, DW_LNS_copy,
12336 "copy line %u", current_line);
12340 int line_offset = ent->val - current_line;
12341 int line_delta = line_offset - DWARF_LINE_BASE;
12343 current_line = ent->val;
12344 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12346 /* This can handle deltas from -10 to 234, using the current
12347 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12348 This takes 1 byte. */
12349 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12350 "line %u", current_line);
12354 /* This can handle any delta. This takes at least 4 bytes,
12355 depending on the value being encoded. */
12356 dw2_asm_output_data (1, DW_LNS_advance_line,
12357 "advance to line %u", current_line);
12358 dw2_asm_output_data_sleb128 (line_offset, NULL);
12359 dw2_asm_output_data (1, DW_LNS_copy, NULL);
12365 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
12366 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12369 case LI_set_column:
12370 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
12371 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12374 case LI_negate_stmt:
12375 current_is_stmt = !current_is_stmt;
12376 dw2_asm_output_data (1, DW_LNS_negate_stmt,
12377 "is_stmt %d", current_is_stmt);
12380 case LI_set_prologue_end:
12381 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
12382 "set prologue end");
12385 case LI_set_epilogue_begin:
12386 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
12387 "set epilogue begin");
12390 case LI_set_discriminator:
12391 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
12392 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
12393 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
12394 dw2_asm_output_data_uleb128 (ent->val, NULL);
12399 /* Emit debug info for the address of the end of the table. */
12400 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
12401 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12402 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12403 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
12405 dw2_asm_output_data (1, 0, "end sequence");
12406 dw2_asm_output_data_uleb128 (1, NULL);
12407 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12410 /* Output the source line number correspondence information. This
12411 information goes into the .debug_line section. */
12414 output_line_info (void)
12416 char l1[20], l2[20], p1[20], p2[20];
12417 int ver = dwarf_version;
12420 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12421 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12422 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12423 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12425 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12426 dw2_asm_output_data (4, 0xffffffff,
12427 "Initial length escape value indicating 64-bit DWARF extension");
12428 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12429 "Length of Source Line Info");
12430 ASM_OUTPUT_LABEL (asm_out_file, l1);
12432 dw2_asm_output_data (2, ver, "DWARF Version");
12433 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12434 ASM_OUTPUT_LABEL (asm_out_file, p1);
12436 /* Define the architecture-dependent minimum instruction length (in bytes).
12437 In this implementation of DWARF, this field is used for information
12438 purposes only. Since GCC generates assembly language, we have no
12439 a priori knowledge of how many instruction bytes are generated for each
12440 source line, and therefore can use only the DW_LNE_set_address and
12441 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12442 this as '1', which is "correct enough" for all architectures,
12443 and don't let the target override. */
12444 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12447 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12448 "Maximum Operations Per Instruction");
12449 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12450 "Default is_stmt_start flag");
12451 dw2_asm_output_data (1, DWARF_LINE_BASE,
12452 "Line Base Value (Special Opcodes)");
12453 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12454 "Line Range Value (Special Opcodes)");
12455 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12456 "Special Opcode Base");
12458 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12463 case DW_LNS_advance_pc:
12464 case DW_LNS_advance_line:
12465 case DW_LNS_set_file:
12466 case DW_LNS_set_column:
12467 case DW_LNS_fixed_advance_pc:
12468 case DW_LNS_set_isa:
12476 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12480 /* Write out the information about the files we use. */
12481 output_file_names ();
12482 ASM_OUTPUT_LABEL (asm_out_file, p2);
12484 if (text_section_line_info && text_section_line_info->in_use)
12485 output_one_line_info_table (text_section_line_info);
12486 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
12487 output_one_line_info_table (cold_text_section_line_info);
12489 if (separate_line_info)
12491 dw_line_info_table *table;
12494 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
12496 output_one_line_info_table (table);
12499 /* Output the marker for the end of the line number info. */
12500 ASM_OUTPUT_LABEL (asm_out_file, l2);
12503 /* Given a pointer to a tree node for some base type, return a pointer to
12504 a DIE that describes the given type.
12506 This routine must only be called for GCC type nodes that correspond to
12507 Dwarf base (fundamental) types. */
12510 base_type_die (tree type)
12512 dw_die_ref base_type_result;
12513 enum dwarf_type encoding;
12515 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12518 /* If this is a subtype that should not be emitted as a subrange type,
12519 use the base type. See subrange_type_for_debug_p. */
12520 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12521 type = TREE_TYPE (type);
12523 switch (TREE_CODE (type))
12526 if ((dwarf_version >= 4 || !dwarf_strict)
12527 && TYPE_NAME (type)
12528 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12529 && DECL_IS_BUILTIN (TYPE_NAME (type))
12530 && DECL_NAME (TYPE_NAME (type)))
12532 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12533 if (strcmp (name, "char16_t") == 0
12534 || strcmp (name, "char32_t") == 0)
12536 encoding = DW_ATE_UTF;
12540 if (TYPE_STRING_FLAG (type))
12542 if (TYPE_UNSIGNED (type))
12543 encoding = DW_ATE_unsigned_char;
12545 encoding = DW_ATE_signed_char;
12547 else if (TYPE_UNSIGNED (type))
12548 encoding = DW_ATE_unsigned;
12550 encoding = DW_ATE_signed;
12554 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12556 if (dwarf_version >= 3 || !dwarf_strict)
12557 encoding = DW_ATE_decimal_float;
12559 encoding = DW_ATE_lo_user;
12562 encoding = DW_ATE_float;
12565 case FIXED_POINT_TYPE:
12566 if (!(dwarf_version >= 3 || !dwarf_strict))
12567 encoding = DW_ATE_lo_user;
12568 else if (TYPE_UNSIGNED (type))
12569 encoding = DW_ATE_unsigned_fixed;
12571 encoding = DW_ATE_signed_fixed;
12574 /* Dwarf2 doesn't know anything about complex ints, so use
12575 a user defined type for it. */
12577 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12578 encoding = DW_ATE_complex_float;
12580 encoding = DW_ATE_lo_user;
12584 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12585 encoding = DW_ATE_boolean;
12589 /* No other TREE_CODEs are Dwarf fundamental types. */
12590 gcc_unreachable ();
12593 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12595 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12596 int_size_in_bytes (type));
12597 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12599 return base_type_result;
12602 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12603 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12606 is_base_type (tree type)
12608 switch (TREE_CODE (type))
12614 case FIXED_POINT_TYPE:
12622 case QUAL_UNION_TYPE:
12623 case ENUMERAL_TYPE:
12624 case FUNCTION_TYPE:
12627 case REFERENCE_TYPE:
12635 gcc_unreachable ();
12641 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12642 node, return the size in bits for the type if it is a constant, or else
12643 return the alignment for the type if the type's size is not constant, or
12644 else return BITS_PER_WORD if the type actually turns out to be an
12645 ERROR_MARK node. */
12647 static inline unsigned HOST_WIDE_INT
12648 simple_type_size_in_bits (const_tree type)
12650 if (TREE_CODE (type) == ERROR_MARK)
12651 return BITS_PER_WORD;
12652 else if (TYPE_SIZE (type) == NULL_TREE)
12654 else if (host_integerp (TYPE_SIZE (type), 1))
12655 return tree_low_cst (TYPE_SIZE (type), 1);
12657 return TYPE_ALIGN (type);
12660 /* Similarly, but return a double_int instead of UHWI. */
12662 static inline double_int
12663 double_int_type_size_in_bits (const_tree type)
12665 if (TREE_CODE (type) == ERROR_MARK)
12666 return uhwi_to_double_int (BITS_PER_WORD);
12667 else if (TYPE_SIZE (type) == NULL_TREE)
12668 return double_int_zero;
12669 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12670 return tree_to_double_int (TYPE_SIZE (type));
12672 return uhwi_to_double_int (TYPE_ALIGN (type));
12675 /* Given a pointer to a tree node for a subrange type, return a pointer
12676 to a DIE that describes the given type. */
12679 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12681 dw_die_ref subrange_die;
12682 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12684 if (context_die == NULL)
12685 context_die = comp_unit_die ();
12687 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12689 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12691 /* The size of the subrange type and its base type do not match,
12692 so we need to generate a size attribute for the subrange type. */
12693 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12697 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12699 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12701 return subrange_die;
12704 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12705 entry that chains various modifiers in front of the given type. */
12708 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12709 dw_die_ref context_die)
12711 enum tree_code code = TREE_CODE (type);
12712 dw_die_ref mod_type_die;
12713 dw_die_ref sub_die = NULL;
12714 tree item_type = NULL;
12715 tree qualified_type;
12716 tree name, low, high;
12718 if (code == ERROR_MARK)
12721 /* See if we already have the appropriately qualified variant of
12724 = get_qualified_type (type,
12725 ((is_const_type ? TYPE_QUAL_CONST : 0)
12726 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12728 if (qualified_type == sizetype
12729 && TYPE_NAME (qualified_type)
12730 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12732 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12734 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12735 && TYPE_PRECISION (t)
12736 == TYPE_PRECISION (qualified_type)
12737 && TYPE_UNSIGNED (t)
12738 == TYPE_UNSIGNED (qualified_type));
12739 qualified_type = t;
12742 /* If we do, then we can just use its DIE, if it exists. */
12743 if (qualified_type)
12745 mod_type_die = lookup_type_die (qualified_type);
12747 return mod_type_die;
12750 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12752 /* Handle C typedef types. */
12753 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12754 && !DECL_ARTIFICIAL (name))
12756 tree dtype = TREE_TYPE (name);
12758 if (qualified_type == dtype)
12760 /* For a named type, use the typedef. */
12761 gen_type_die (qualified_type, context_die);
12762 return lookup_type_die (qualified_type);
12764 else if (is_const_type < TYPE_READONLY (dtype)
12765 || is_volatile_type < TYPE_VOLATILE (dtype)
12766 || (is_const_type <= TYPE_READONLY (dtype)
12767 && is_volatile_type <= TYPE_VOLATILE (dtype)
12768 && DECL_ORIGINAL_TYPE (name) != type))
12769 /* cv-unqualified version of named type. Just use the unnamed
12770 type to which it refers. */
12771 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12772 is_const_type, is_volatile_type,
12774 /* Else cv-qualified version of named type; fall through. */
12778 /* If both is_const_type and is_volatile_type, prefer the path
12779 which leads to a qualified type. */
12780 && (!is_volatile_type
12781 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
12782 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
12784 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12785 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12787 else if (is_volatile_type)
12789 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12790 sub_die = modified_type_die (type, is_const_type, 0, context_die);
12792 else if (code == POINTER_TYPE)
12794 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12795 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12796 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12797 item_type = TREE_TYPE (type);
12798 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12799 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12800 TYPE_ADDR_SPACE (item_type));
12802 else if (code == REFERENCE_TYPE)
12804 if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
12805 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12808 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12809 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12810 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12811 item_type = TREE_TYPE (type);
12812 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12813 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12814 TYPE_ADDR_SPACE (item_type));
12816 else if (code == INTEGER_TYPE
12817 && TREE_TYPE (type) != NULL_TREE
12818 && subrange_type_for_debug_p (type, &low, &high))
12820 mod_type_die = subrange_type_die (type, low, high, context_die);
12821 item_type = TREE_TYPE (type);
12823 else if (is_base_type (type))
12824 mod_type_die = base_type_die (type);
12827 gen_type_die (type, context_die);
12829 /* We have to get the type_main_variant here (and pass that to the
12830 `lookup_type_die' routine) because the ..._TYPE node we have
12831 might simply be a *copy* of some original type node (where the
12832 copy was created to help us keep track of typedef names) and
12833 that copy might have a different TYPE_UID from the original
12835 if (TREE_CODE (type) != VECTOR_TYPE)
12836 return lookup_type_die (type_main_variant (type));
12838 /* Vectors have the debugging information in the type,
12839 not the main variant. */
12840 return lookup_type_die (type);
12843 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12844 don't output a DW_TAG_typedef, since there isn't one in the
12845 user's program; just attach a DW_AT_name to the type.
12846 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12847 if the base type already has the same name. */
12849 && ((TREE_CODE (name) != TYPE_DECL
12850 && (qualified_type == TYPE_MAIN_VARIANT (type)
12851 || (!is_const_type && !is_volatile_type)))
12852 || (TREE_CODE (name) == TYPE_DECL
12853 && TREE_TYPE (name) == qualified_type
12854 && DECL_NAME (name))))
12856 if (TREE_CODE (name) == TYPE_DECL)
12857 /* Could just call add_name_and_src_coords_attributes here,
12858 but since this is a builtin type it doesn't have any
12859 useful source coordinates anyway. */
12860 name = DECL_NAME (name);
12861 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12863 /* This probably indicates a bug. */
12864 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12865 add_name_attribute (mod_type_die, "__unknown__");
12867 if (qualified_type)
12868 equate_type_number_to_die (qualified_type, mod_type_die);
12871 /* We must do this after the equate_type_number_to_die call, in case
12872 this is a recursive type. This ensures that the modified_type_die
12873 recursion will terminate even if the type is recursive. Recursive
12874 types are possible in Ada. */
12875 sub_die = modified_type_die (item_type,
12876 TYPE_READONLY (item_type),
12877 TYPE_VOLATILE (item_type),
12880 if (sub_die != NULL)
12881 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12883 return mod_type_die;
12886 /* Generate DIEs for the generic parameters of T.
12887 T must be either a generic type or a generic function.
12888 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12891 gen_generic_params_dies (tree t)
12895 dw_die_ref die = NULL;
12897 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
12901 die = lookup_type_die (t);
12902 else if (DECL_P (t))
12903 die = lookup_decl_die (t);
12907 parms = lang_hooks.get_innermost_generic_parms (t);
12909 /* T has no generic parameter. It means T is neither a generic type
12910 or function. End of story. */
12913 parms_num = TREE_VEC_LENGTH (parms);
12914 args = lang_hooks.get_innermost_generic_args (t);
12915 for (i = 0; i < parms_num; i++)
12917 tree parm, arg, arg_pack_elems;
12919 parm = TREE_VEC_ELT (parms, i);
12920 arg = TREE_VEC_ELT (args, i);
12921 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
12922 gcc_assert (parm && TREE_VALUE (parm) && arg);
12924 if (parm && TREE_VALUE (parm) && arg)
12926 /* If PARM represents a template parameter pack,
12927 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12928 by DW_TAG_template_*_parameter DIEs for the argument
12929 pack elements of ARG. Note that ARG would then be
12930 an argument pack. */
12931 if (arg_pack_elems)
12932 template_parameter_pack_die (TREE_VALUE (parm),
12936 generic_parameter_die (TREE_VALUE (parm), arg,
12937 true /* Emit DW_AT_name */, die);
12942 /* Create and return a DIE for PARM which should be
12943 the representation of a generic type parameter.
12944 For instance, in the C++ front end, PARM would be a template parameter.
12945 ARG is the argument to PARM.
12946 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12948 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12949 as a child node. */
12952 generic_parameter_die (tree parm, tree arg,
12954 dw_die_ref parent_die)
12956 dw_die_ref tmpl_die = NULL;
12957 const char *name = NULL;
12959 if (!parm || !DECL_NAME (parm) || !arg)
12962 /* We support non-type generic parameters and arguments,
12963 type generic parameters and arguments, as well as
12964 generic generic parameters (a.k.a. template template parameters in C++)
12966 if (TREE_CODE (parm) == PARM_DECL)
12967 /* PARM is a nontype generic parameter */
12968 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
12969 else if (TREE_CODE (parm) == TYPE_DECL)
12970 /* PARM is a type generic parameter. */
12971 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
12972 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12973 /* PARM is a generic generic parameter.
12974 Its DIE is a GNU extension. It shall have a
12975 DW_AT_name attribute to represent the name of the template template
12976 parameter, and a DW_AT_GNU_template_name attribute to represent the
12977 name of the template template argument. */
12978 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
12981 gcc_unreachable ();
12987 /* If PARM is a generic parameter pack, it means we are
12988 emitting debug info for a template argument pack element.
12989 In other terms, ARG is a template argument pack element.
12990 In that case, we don't emit any DW_AT_name attribute for
12994 name = IDENTIFIER_POINTER (DECL_NAME (parm));
12996 add_AT_string (tmpl_die, DW_AT_name, name);
12999 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13001 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13002 TMPL_DIE should have a child DW_AT_type attribute that is set
13003 to the type of the argument to PARM, which is ARG.
13004 If PARM is a type generic parameter, TMPL_DIE should have a
13005 child DW_AT_type that is set to ARG. */
13006 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13007 add_type_attribute (tmpl_die, tmpl_type, 0,
13008 TREE_THIS_VOLATILE (tmpl_type),
13013 /* So TMPL_DIE is a DIE representing a
13014 a generic generic template parameter, a.k.a template template
13015 parameter in C++ and arg is a template. */
13017 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13018 to the name of the argument. */
13019 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13021 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13024 if (TREE_CODE (parm) == PARM_DECL)
13025 /* So PARM is a non-type generic parameter.
13026 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13027 attribute of TMPL_DIE which value represents the value
13029 We must be careful here:
13030 The value of ARG might reference some function decls.
13031 We might currently be emitting debug info for a generic
13032 type and types are emitted before function decls, we don't
13033 know if the function decls referenced by ARG will actually be
13034 emitted after cgraph computations.
13035 So must defer the generation of the DW_AT_const_value to
13036 after cgraph is ready. */
13037 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13043 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13044 PARM_PACK must be a template parameter pack. The returned DIE
13045 will be child DIE of PARENT_DIE. */
13048 template_parameter_pack_die (tree parm_pack,
13049 tree parm_pack_args,
13050 dw_die_ref parent_die)
13055 gcc_assert (parent_die && parm_pack);
13057 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13058 add_name_and_src_coords_attributes (die, parm_pack);
13059 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13060 generic_parameter_die (parm_pack,
13061 TREE_VEC_ELT (parm_pack_args, j),
13062 false /* Don't emit DW_AT_name */,
13067 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13068 an enumerated type. */
13071 type_is_enum (const_tree type)
13073 return TREE_CODE (type) == ENUMERAL_TYPE;
13076 /* Return the DBX register number described by a given RTL node. */
13078 static unsigned int
13079 dbx_reg_number (const_rtx rtl)
13081 unsigned regno = REGNO (rtl);
13083 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13085 #ifdef LEAF_REG_REMAP
13086 if (current_function_uses_only_leaf_regs)
13088 int leaf_reg = LEAF_REG_REMAP (regno);
13089 if (leaf_reg != -1)
13090 regno = (unsigned) leaf_reg;
13094 return DBX_REGISTER_NUMBER (regno);
13097 /* Optionally add a DW_OP_piece term to a location description expression.
13098 DW_OP_piece is only added if the location description expression already
13099 doesn't end with DW_OP_piece. */
13102 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13104 dw_loc_descr_ref loc;
13106 if (*list_head != NULL)
13108 /* Find the end of the chain. */
13109 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13112 if (loc->dw_loc_opc != DW_OP_piece)
13113 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13117 /* Return a location descriptor that designates a machine register or
13118 zero if there is none. */
13120 static dw_loc_descr_ref
13121 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13125 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13128 /* We only use "frame base" when we're sure we're talking about the
13129 post-prologue local stack frame. We do this by *not* running
13130 register elimination until this point, and recognizing the special
13131 argument pointer and soft frame pointer rtx's.
13132 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13133 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13134 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13136 dw_loc_descr_ref result = NULL;
13138 if (dwarf_version >= 4 || !dwarf_strict)
13140 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13142 add_loc_descr (&result,
13143 new_loc_descr (DW_OP_stack_value, 0, 0));
13148 regs = targetm.dwarf_register_span (rtl);
13150 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13151 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13153 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13156 /* Return a location descriptor that designates a machine register for
13157 a given hard register number. */
13159 static dw_loc_descr_ref
13160 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13162 dw_loc_descr_ref reg_loc_descr;
13166 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13168 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13170 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13171 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13173 return reg_loc_descr;
13176 /* Given an RTL of a register, return a location descriptor that
13177 designates a value that spans more than one register. */
13179 static dw_loc_descr_ref
13180 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13181 enum var_init_status initialized)
13183 int nregs, size, i;
13185 dw_loc_descr_ref loc_result = NULL;
13188 #ifdef LEAF_REG_REMAP
13189 if (current_function_uses_only_leaf_regs)
13191 int leaf_reg = LEAF_REG_REMAP (reg);
13192 if (leaf_reg != -1)
13193 reg = (unsigned) leaf_reg;
13196 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13197 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13199 /* Simple, contiguous registers. */
13200 if (regs == NULL_RTX)
13202 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13207 dw_loc_descr_ref t;
13209 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13210 VAR_INIT_STATUS_INITIALIZED);
13211 add_loc_descr (&loc_result, t);
13212 add_loc_descr_op_piece (&loc_result, size);
13218 /* Now onto stupid register sets in non contiguous locations. */
13220 gcc_assert (GET_CODE (regs) == PARALLEL);
13222 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13225 for (i = 0; i < XVECLEN (regs, 0); ++i)
13227 dw_loc_descr_ref t;
13229 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13230 VAR_INIT_STATUS_INITIALIZED);
13231 add_loc_descr (&loc_result, t);
13232 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13233 add_loc_descr_op_piece (&loc_result, size);
13236 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13237 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13241 /* Return a location descriptor that designates a constant. */
13243 static dw_loc_descr_ref
13244 int_loc_descriptor (HOST_WIDE_INT i)
13246 enum dwarf_location_atom op;
13248 /* Pick the smallest representation of a constant, rather than just
13249 defaulting to the LEB encoding. */
13253 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13254 else if (i <= 0xff)
13255 op = DW_OP_const1u;
13256 else if (i <= 0xffff)
13257 op = DW_OP_const2u;
13258 else if (HOST_BITS_PER_WIDE_INT == 32
13259 || i <= 0xffffffff)
13260 op = DW_OP_const4u;
13267 op = DW_OP_const1s;
13268 else if (i >= -0x8000)
13269 op = DW_OP_const2s;
13270 else if (HOST_BITS_PER_WIDE_INT == 32
13271 || i >= -0x80000000)
13272 op = DW_OP_const4s;
13277 return new_loc_descr (op, i, 0);
13280 /* Return loc description representing "address" of integer value.
13281 This can appear only as toplevel expression. */
13283 static dw_loc_descr_ref
13284 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13287 dw_loc_descr_ref loc_result = NULL;
13289 if (!(dwarf_version >= 4 || !dwarf_strict))
13296 else if (i <= 0xff)
13298 else if (i <= 0xffff)
13300 else if (HOST_BITS_PER_WIDE_INT == 32
13301 || i <= 0xffffffff)
13304 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13310 else if (i >= -0x8000)
13312 else if (HOST_BITS_PER_WIDE_INT == 32
13313 || i >= -0x80000000)
13316 litsize = 1 + size_of_sleb128 (i);
13318 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13319 is more compact. For DW_OP_stack_value we need:
13320 litsize + 1 (DW_OP_stack_value)
13321 and for DW_OP_implicit_value:
13322 1 (DW_OP_implicit_value) + 1 (length) + size. */
13323 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13325 loc_result = int_loc_descriptor (i);
13326 add_loc_descr (&loc_result,
13327 new_loc_descr (DW_OP_stack_value, 0, 0));
13331 loc_result = new_loc_descr (DW_OP_implicit_value,
13333 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13334 loc_result->dw_loc_oprnd2.v.val_int = i;
13338 /* Return a location descriptor that designates a base+offset location. */
13340 static dw_loc_descr_ref
13341 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13342 enum var_init_status initialized)
13344 unsigned int regno;
13345 dw_loc_descr_ref result;
13346 dw_fde_ref fde = current_fde ();
13348 /* We only use "frame base" when we're sure we're talking about the
13349 post-prologue local stack frame. We do this by *not* running
13350 register elimination until this point, and recognizing the special
13351 argument pointer and soft frame pointer rtx's. */
13352 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13354 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13358 if (GET_CODE (elim) == PLUS)
13360 offset += INTVAL (XEXP (elim, 1));
13361 elim = XEXP (elim, 0);
13363 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13364 && (elim == hard_frame_pointer_rtx
13365 || elim == stack_pointer_rtx))
13366 || elim == (frame_pointer_needed
13367 ? hard_frame_pointer_rtx
13368 : stack_pointer_rtx));
13370 /* If drap register is used to align stack, use frame
13371 pointer + offset to access stack variables. If stack
13372 is aligned without drap, use stack pointer + offset to
13373 access stack variables. */
13374 if (crtl->stack_realign_tried
13375 && reg == frame_pointer_rtx)
13378 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13379 ? HARD_FRAME_POINTER_REGNUM
13380 : STACK_POINTER_REGNUM);
13381 return new_reg_loc_descr (base_reg, offset);
13384 offset += frame_pointer_fb_offset;
13385 return new_loc_descr (DW_OP_fbreg, offset, 0);
13390 && (fde->drap_reg == REGNO (reg)
13391 || fde->vdrap_reg == REGNO (reg)))
13393 /* Use cfa+offset to represent the location of arguments passed
13394 on the stack when drap is used to align stack.
13395 Only do this when not optimizing, for optimized code var-tracking
13396 is supposed to track where the arguments live and the register
13397 used as vdrap or drap in some spot might be used for something
13398 else in other part of the routine. */
13399 return new_loc_descr (DW_OP_fbreg, offset, 0);
13402 regno = dbx_reg_number (reg);
13404 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13407 result = new_loc_descr (DW_OP_bregx, regno, offset);
13409 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13410 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13415 /* Return true if this RTL expression describes a base+offset calculation. */
13418 is_based_loc (const_rtx rtl)
13420 return (GET_CODE (rtl) == PLUS
13421 && ((REG_P (XEXP (rtl, 0))
13422 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13423 && CONST_INT_P (XEXP (rtl, 1)))));
13426 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13429 static dw_loc_descr_ref
13430 tls_mem_loc_descriptor (rtx mem)
13433 dw_loc_descr_ref loc_result;
13435 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13438 base = get_base_address (MEM_EXPR (mem));
13440 || TREE_CODE (base) != VAR_DECL
13441 || !DECL_THREAD_LOCAL_P (base))
13444 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13445 if (loc_result == NULL)
13448 if (INTVAL (MEM_OFFSET (mem)))
13449 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13454 /* Output debug info about reason why we failed to expand expression as dwarf
13458 expansion_failed (tree expr, rtx rtl, char const *reason)
13460 if (dump_file && (dump_flags & TDF_DETAILS))
13462 fprintf (dump_file, "Failed to expand as dwarf: ");
13464 print_generic_expr (dump_file, expr, dump_flags);
13467 fprintf (dump_file, "\n");
13468 print_rtl (dump_file, rtl);
13470 fprintf (dump_file, "\nReason: %s\n", reason);
13474 /* Helper function for const_ok_for_output, called either directly
13475 or via for_each_rtx. */
13478 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13482 if (GET_CODE (rtl) == UNSPEC)
13484 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13485 we can't express it in the debug info. */
13486 #ifdef ENABLE_CHECKING
13487 /* Don't complain about TLS UNSPECs, those are just too hard to
13489 if (XVECLEN (rtl, 0) != 1
13490 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13491 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13492 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13493 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13494 inform (current_function_decl
13495 ? DECL_SOURCE_LOCATION (current_function_decl)
13496 : UNKNOWN_LOCATION,
13497 #if NUM_UNSPEC_VALUES > 0
13498 "non-delegitimized UNSPEC %s (%d) found in variable location",
13499 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13500 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13503 "non-delegitimized UNSPEC %d found in variable location",
13507 expansion_failed (NULL_TREE, rtl,
13508 "UNSPEC hasn't been delegitimized.\n");
13512 if (GET_CODE (rtl) != SYMBOL_REF)
13515 if (CONSTANT_POOL_ADDRESS_P (rtl))
13518 get_pool_constant_mark (rtl, &marked);
13519 /* If all references to this pool constant were optimized away,
13520 it was not output and thus we can't represent it. */
13523 expansion_failed (NULL_TREE, rtl,
13524 "Constant was removed from constant pool.\n");
13529 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13532 /* Avoid references to external symbols in debug info, on several targets
13533 the linker might even refuse to link when linking a shared library,
13534 and in many other cases the relocations for .debug_info/.debug_loc are
13535 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13536 to be defined within the same shared library or executable are fine. */
13537 if (SYMBOL_REF_EXTERNAL_P (rtl))
13539 tree decl = SYMBOL_REF_DECL (rtl);
13541 if (decl == NULL || !targetm.binds_local_p (decl))
13543 expansion_failed (NULL_TREE, rtl,
13544 "Symbol not defined in current TU.\n");
13552 /* Return true if constant RTL can be emitted in DW_OP_addr or
13553 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13554 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13557 const_ok_for_output (rtx rtl)
13559 if (GET_CODE (rtl) == SYMBOL_REF)
13560 return const_ok_for_output_1 (&rtl, NULL) == 0;
13562 if (GET_CODE (rtl) == CONST)
13563 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13568 /* The following routine converts the RTL for a variable or parameter
13569 (resident in memory) into an equivalent Dwarf representation of a
13570 mechanism for getting the address of that same variable onto the top of a
13571 hypothetical "address evaluation" stack.
13573 When creating memory location descriptors, we are effectively transforming
13574 the RTL for a memory-resident object into its Dwarf postfix expression
13575 equivalent. This routine recursively descends an RTL tree, turning
13576 it into Dwarf postfix code as it goes.
13578 MODE is the mode of the memory reference, needed to handle some
13579 autoincrement addressing modes.
13581 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13582 location list for RTL.
13584 Return 0 if we can't represent the location. */
13586 static dw_loc_descr_ref
13587 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13588 enum var_init_status initialized)
13590 dw_loc_descr_ref mem_loc_result = NULL;
13591 enum dwarf_location_atom op;
13592 dw_loc_descr_ref op0, op1;
13594 /* Note that for a dynamically sized array, the location we will generate a
13595 description of here will be the lowest numbered location which is
13596 actually within the array. That's *not* necessarily the same as the
13597 zeroth element of the array. */
13599 rtl = targetm.delegitimize_address (rtl);
13601 switch (GET_CODE (rtl))
13606 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13609 /* The case of a subreg may arise when we have a local (register)
13610 variable or a formal (register) parameter which doesn't quite fill
13611 up an entire register. For now, just assume that it is
13612 legitimate to make the Dwarf info refer to the whole register which
13613 contains the given subreg. */
13614 if (!subreg_lowpart_p (rtl))
13616 rtl = SUBREG_REG (rtl);
13617 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13619 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13621 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13625 /* Whenever a register number forms a part of the description of the
13626 method for calculating the (dynamic) address of a memory resident
13627 object, DWARF rules require the register number be referred to as
13628 a "base register". This distinction is not based in any way upon
13629 what category of register the hardware believes the given register
13630 belongs to. This is strictly DWARF terminology we're dealing with
13631 here. Note that in cases where the location of a memory-resident
13632 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13633 OP_CONST (0)) the actual DWARF location descriptor that we generate
13634 may just be OP_BASEREG (basereg). This may look deceptively like
13635 the object in question was allocated to a register (rather than in
13636 memory) so DWARF consumers need to be aware of the subtle
13637 distinction between OP_REG and OP_BASEREG. */
13638 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13639 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13640 else if (stack_realign_drap
13642 && crtl->args.internal_arg_pointer == rtl
13643 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13645 /* If RTL is internal_arg_pointer, which has been optimized
13646 out, use DRAP instead. */
13647 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13648 VAR_INIT_STATUS_INITIALIZED);
13654 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13655 VAR_INIT_STATUS_INITIALIZED);
13660 int shift = DWARF2_ADDR_SIZE
13661 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13662 shift *= BITS_PER_UNIT;
13663 if (GET_CODE (rtl) == SIGN_EXTEND)
13667 mem_loc_result = op0;
13668 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13669 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13670 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13671 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13676 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13677 VAR_INIT_STATUS_INITIALIZED);
13678 if (mem_loc_result == NULL)
13679 mem_loc_result = tls_mem_loc_descriptor (rtl);
13680 if (mem_loc_result != 0)
13682 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13684 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13687 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13688 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13690 add_loc_descr (&mem_loc_result,
13691 new_loc_descr (DW_OP_deref_size,
13692 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13696 rtx new_rtl = avoid_constant_pool_reference (rtl);
13697 if (new_rtl != rtl)
13698 return mem_loc_descriptor (new_rtl, mode, initialized);
13703 rtl = XEXP (rtl, 1);
13705 /* ... fall through ... */
13708 /* Some ports can transform a symbol ref into a label ref, because
13709 the symbol ref is too far away and has to be dumped into a constant
13713 if (GET_CODE (rtl) == SYMBOL_REF
13714 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13716 dw_loc_descr_ref temp;
13718 /* If this is not defined, we have no way to emit the data. */
13719 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13722 /* We used to emit DW_OP_addr here, but that's wrong, since
13723 DW_OP_addr should be relocated by the debug info consumer,
13724 while DW_OP_GNU_push_tls_address operand should not. */
13725 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13726 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13727 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13728 temp->dw_loc_oprnd1.v.val_addr = rtl;
13729 temp->dtprel = true;
13731 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13732 add_loc_descr (&mem_loc_result, temp);
13737 if (!const_ok_for_output (rtl))
13741 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13742 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13743 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13744 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13750 case DEBUG_IMPLICIT_PTR:
13751 expansion_failed (NULL_TREE, rtl,
13752 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13758 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
13759 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
13760 if (REG_P (ENTRY_VALUE_EXP (rtl)))
13761 mem_loc_result->dw_loc_oprnd1.v.val_loc
13762 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
13763 VAR_INIT_STATUS_INITIALIZED);
13764 else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
13766 dw_loc_descr_ref ref
13767 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
13768 VAR_INIT_STATUS_INITIALIZED);
13769 if (ref == NULL || ref->dw_loc_opc == DW_OP_fbreg)
13771 mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
13774 gcc_unreachable ();
13775 return mem_loc_result;
13778 /* Extract the PLUS expression nested inside and fall into
13779 PLUS code below. */
13780 rtl = XEXP (rtl, 1);
13785 /* Turn these into a PLUS expression and fall into the PLUS code
13787 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13788 GEN_INT (GET_CODE (rtl) == PRE_INC
13789 ? GET_MODE_UNIT_SIZE (mode)
13790 : -GET_MODE_UNIT_SIZE (mode)));
13792 /* ... fall through ... */
13796 if (is_based_loc (rtl))
13797 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13798 INTVAL (XEXP (rtl, 1)),
13799 VAR_INIT_STATUS_INITIALIZED);
13802 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13803 VAR_INIT_STATUS_INITIALIZED);
13804 if (mem_loc_result == 0)
13807 if (CONST_INT_P (XEXP (rtl, 1)))
13808 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13811 dw_loc_descr_ref mem_loc_result2
13812 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13813 VAR_INIT_STATUS_INITIALIZED);
13814 if (mem_loc_result2 == 0)
13816 add_loc_descr (&mem_loc_result, mem_loc_result2);
13817 add_loc_descr (&mem_loc_result,
13818 new_loc_descr (DW_OP_plus, 0, 0));
13823 /* If a pseudo-reg is optimized away, it is possible for it to
13824 be replaced with a MEM containing a multiply or shift. */
13866 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13867 VAR_INIT_STATUS_INITIALIZED);
13868 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13869 VAR_INIT_STATUS_INITIALIZED);
13871 if (op0 == 0 || op1 == 0)
13874 mem_loc_result = op0;
13875 add_loc_descr (&mem_loc_result, op1);
13876 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13880 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13881 VAR_INIT_STATUS_INITIALIZED);
13882 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13883 VAR_INIT_STATUS_INITIALIZED);
13885 if (op0 == 0 || op1 == 0)
13888 mem_loc_result = op0;
13889 add_loc_descr (&mem_loc_result, op1);
13890 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13891 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13892 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13893 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13894 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13910 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13911 VAR_INIT_STATUS_INITIALIZED);
13916 mem_loc_result = op0;
13917 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13921 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13949 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13950 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13954 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13956 if (op_mode == VOIDmode)
13957 op_mode = GET_MODE (XEXP (rtl, 1));
13958 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13961 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13962 VAR_INIT_STATUS_INITIALIZED);
13963 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13964 VAR_INIT_STATUS_INITIALIZED);
13966 if (op0 == 0 || op1 == 0)
13969 if (op_mode != VOIDmode
13970 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13972 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
13973 shift *= BITS_PER_UNIT;
13974 /* For eq/ne, if the operands are known to be zero-extended,
13975 there is no need to do the fancy shifting up. */
13976 if (op == DW_OP_eq || op == DW_OP_ne)
13978 dw_loc_descr_ref last0, last1;
13980 last0->dw_loc_next != NULL;
13981 last0 = last0->dw_loc_next)
13984 last1->dw_loc_next != NULL;
13985 last1 = last1->dw_loc_next)
13987 /* deref_size zero extends, and for constants we can check
13988 whether they are zero extended or not. */
13989 if (((last0->dw_loc_opc == DW_OP_deref_size
13990 && last0->dw_loc_oprnd1.v.val_int
13991 <= GET_MODE_SIZE (op_mode))
13992 || (CONST_INT_P (XEXP (rtl, 0))
13993 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
13994 == (INTVAL (XEXP (rtl, 0))
13995 & GET_MODE_MASK (op_mode))))
13996 && ((last1->dw_loc_opc == DW_OP_deref_size
13997 && last1->dw_loc_oprnd1.v.val_int
13998 <= GET_MODE_SIZE (op_mode))
13999 || (CONST_INT_P (XEXP (rtl, 1))
14000 && (unsigned HOST_WIDE_INT)
14001 INTVAL (XEXP (rtl, 1))
14002 == (INTVAL (XEXP (rtl, 1))
14003 & GET_MODE_MASK (op_mode)))))
14006 add_loc_descr (&op0, int_loc_descriptor (shift));
14007 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14008 if (CONST_INT_P (XEXP (rtl, 1)))
14009 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14012 add_loc_descr (&op1, int_loc_descriptor (shift));
14013 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14019 mem_loc_result = op0;
14020 add_loc_descr (&mem_loc_result, op1);
14021 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14022 if (STORE_FLAG_VALUE != 1)
14024 add_loc_descr (&mem_loc_result,
14025 int_loc_descriptor (STORE_FLAG_VALUE));
14026 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14047 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14048 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14052 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14054 if (op_mode == VOIDmode)
14055 op_mode = GET_MODE (XEXP (rtl, 1));
14056 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14059 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14060 VAR_INIT_STATUS_INITIALIZED);
14061 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14062 VAR_INIT_STATUS_INITIALIZED);
14064 if (op0 == 0 || op1 == 0)
14067 if (op_mode != VOIDmode
14068 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14070 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14071 dw_loc_descr_ref last0, last1;
14073 last0->dw_loc_next != NULL;
14074 last0 = last0->dw_loc_next)
14077 last1->dw_loc_next != NULL;
14078 last1 = last1->dw_loc_next)
14080 if (CONST_INT_P (XEXP (rtl, 0)))
14081 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14082 /* deref_size zero extends, so no need to mask it again. */
14083 else if (last0->dw_loc_opc != DW_OP_deref_size
14084 || last0->dw_loc_oprnd1.v.val_int
14085 > GET_MODE_SIZE (op_mode))
14087 add_loc_descr (&op0, int_loc_descriptor (mask));
14088 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14090 if (CONST_INT_P (XEXP (rtl, 1)))
14091 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14092 /* deref_size zero extends, so no need to mask it again. */
14093 else if (last1->dw_loc_opc != DW_OP_deref_size
14094 || last1->dw_loc_oprnd1.v.val_int
14095 > GET_MODE_SIZE (op_mode))
14097 add_loc_descr (&op1, int_loc_descriptor (mask));
14098 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14103 HOST_WIDE_INT bias = 1;
14104 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14105 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14106 if (CONST_INT_P (XEXP (rtl, 1)))
14107 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14108 + INTVAL (XEXP (rtl, 1)));
14110 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14120 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14121 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14122 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14125 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14126 VAR_INIT_STATUS_INITIALIZED);
14127 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14128 VAR_INIT_STATUS_INITIALIZED);
14130 if (op0 == 0 || op1 == 0)
14133 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14134 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14135 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14136 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14138 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14140 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14141 add_loc_descr (&op0, int_loc_descriptor (mask));
14142 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14143 add_loc_descr (&op1, int_loc_descriptor (mask));
14144 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14148 HOST_WIDE_INT bias = 1;
14149 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14150 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14151 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14154 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14156 int shift = DWARF2_ADDR_SIZE
14157 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14158 shift *= BITS_PER_UNIT;
14159 add_loc_descr (&op0, int_loc_descriptor (shift));
14160 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14161 add_loc_descr (&op1, int_loc_descriptor (shift));
14162 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14165 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14169 mem_loc_result = op0;
14170 add_loc_descr (&mem_loc_result, op1);
14171 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14173 dw_loc_descr_ref bra_node, drop_node;
14175 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14176 add_loc_descr (&mem_loc_result, bra_node);
14177 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14178 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14179 add_loc_descr (&mem_loc_result, drop_node);
14180 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14181 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14187 if (CONST_INT_P (XEXP (rtl, 1))
14188 && CONST_INT_P (XEXP (rtl, 2))
14189 && ((unsigned) INTVAL (XEXP (rtl, 1))
14190 + (unsigned) INTVAL (XEXP (rtl, 2))
14191 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14192 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14193 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14196 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14197 VAR_INIT_STATUS_INITIALIZED);
14200 if (GET_CODE (rtl) == SIGN_EXTRACT)
14204 mem_loc_result = op0;
14205 size = INTVAL (XEXP (rtl, 1));
14206 shift = INTVAL (XEXP (rtl, 2));
14207 if (BITS_BIG_ENDIAN)
14208 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14210 if (shift + size != (int) DWARF2_ADDR_SIZE)
14212 add_loc_descr (&mem_loc_result,
14213 int_loc_descriptor (DWARF2_ADDR_SIZE
14215 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14217 if (size != (int) DWARF2_ADDR_SIZE)
14219 add_loc_descr (&mem_loc_result,
14220 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14221 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14228 dw_loc_descr_ref op2, bra_node, drop_node;
14229 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14230 VAR_INIT_STATUS_INITIALIZED);
14231 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14232 VAR_INIT_STATUS_INITIALIZED);
14233 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14234 VAR_INIT_STATUS_INITIALIZED);
14235 if (op0 == NULL || op1 == NULL || op2 == NULL)
14238 mem_loc_result = op1;
14239 add_loc_descr (&mem_loc_result, op2);
14240 add_loc_descr (&mem_loc_result, op0);
14241 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14242 add_loc_descr (&mem_loc_result, bra_node);
14243 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14244 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14245 add_loc_descr (&mem_loc_result, drop_node);
14246 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14247 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14255 /* In theory, we could implement the above. */
14256 /* DWARF cannot represent the unsigned compare operations
14283 case FLOAT_TRUNCATE:
14285 case UNSIGNED_FLOAT:
14288 case FRACT_CONVERT:
14289 case UNSIGNED_FRACT_CONVERT:
14291 case UNSIGNED_SAT_FRACT:
14303 case VEC_DUPLICATE:
14306 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14307 can't express it in the debug info. This can happen e.g. with some
14312 resolve_one_addr (&rtl, NULL);
14316 #ifdef ENABLE_CHECKING
14317 print_rtl (stderr, rtl);
14318 gcc_unreachable ();
14324 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14325 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14327 return mem_loc_result;
14330 /* Return a descriptor that describes the concatenation of two locations.
14331 This is typically a complex variable. */
14333 static dw_loc_descr_ref
14334 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14336 dw_loc_descr_ref cc_loc_result = NULL;
14337 dw_loc_descr_ref x0_ref
14338 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14339 dw_loc_descr_ref x1_ref
14340 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14342 if (x0_ref == 0 || x1_ref == 0)
14345 cc_loc_result = x0_ref;
14346 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14348 add_loc_descr (&cc_loc_result, x1_ref);
14349 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14351 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14352 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14354 return cc_loc_result;
14357 /* Return a descriptor that describes the concatenation of N
14360 static dw_loc_descr_ref
14361 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14364 dw_loc_descr_ref cc_loc_result = NULL;
14365 unsigned int n = XVECLEN (concatn, 0);
14367 for (i = 0; i < n; ++i)
14369 dw_loc_descr_ref ref;
14370 rtx x = XVECEXP (concatn, 0, i);
14372 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14376 add_loc_descr (&cc_loc_result, ref);
14377 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14380 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14381 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14383 return cc_loc_result;
14386 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14387 for DEBUG_IMPLICIT_PTR RTL. */
14389 static dw_loc_descr_ref
14390 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14392 dw_loc_descr_ref ret;
14397 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14398 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14399 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14400 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14401 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14402 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14405 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14406 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14407 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14411 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14412 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14417 /* Output a proper Dwarf location descriptor for a variable or parameter
14418 which is either allocated in a register or in a memory location. For a
14419 register, we just generate an OP_REG and the register number. For a
14420 memory location we provide a Dwarf postfix expression describing how to
14421 generate the (dynamic) address of the object onto the address stack.
14423 MODE is mode of the decl if this loc_descriptor is going to be used in
14424 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14425 allowed, VOIDmode otherwise.
14427 If we don't know how to describe it, return 0. */
14429 static dw_loc_descr_ref
14430 loc_descriptor (rtx rtl, enum machine_mode mode,
14431 enum var_init_status initialized)
14433 dw_loc_descr_ref loc_result = NULL;
14435 switch (GET_CODE (rtl))
14438 /* The case of a subreg may arise when we have a local (register)
14439 variable or a formal (register) parameter which doesn't quite fill
14440 up an entire register. For now, just assume that it is
14441 legitimate to make the Dwarf info refer to the whole register which
14442 contains the given subreg. */
14443 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14447 loc_result = reg_loc_descriptor (rtl, initialized);
14451 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14453 if (loc_result == NULL)
14454 loc_result = tls_mem_loc_descriptor (rtl);
14455 if (loc_result == NULL)
14457 rtx new_rtl = avoid_constant_pool_reference (rtl);
14458 if (new_rtl != rtl)
14459 loc_result = loc_descriptor (new_rtl, mode, initialized);
14464 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14469 loc_result = concatn_loc_descriptor (rtl, initialized);
14474 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14476 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14477 if (GET_CODE (loc) == EXPR_LIST)
14478 loc = XEXP (loc, 0);
14479 loc_result = loc_descriptor (loc, mode, initialized);
14483 rtl = XEXP (rtl, 1);
14488 rtvec par_elems = XVEC (rtl, 0);
14489 int num_elem = GET_NUM_ELEM (par_elems);
14490 enum machine_mode mode;
14493 /* Create the first one, so we have something to add to. */
14494 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14495 VOIDmode, initialized);
14496 if (loc_result == NULL)
14498 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14499 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14500 for (i = 1; i < num_elem; i++)
14502 dw_loc_descr_ref temp;
14504 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14505 VOIDmode, initialized);
14508 add_loc_descr (&loc_result, temp);
14509 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14510 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14516 if (mode != VOIDmode && mode != BLKmode)
14517 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14522 if (mode == VOIDmode)
14523 mode = GET_MODE (rtl);
14525 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14527 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14529 /* Note that a CONST_DOUBLE rtx could represent either an integer
14530 or a floating-point constant. A CONST_DOUBLE is used whenever
14531 the constant requires more than one word in order to be
14532 adequately represented. We output CONST_DOUBLEs as blocks. */
14533 loc_result = new_loc_descr (DW_OP_implicit_value,
14534 GET_MODE_SIZE (mode), 0);
14535 if (SCALAR_FLOAT_MODE_P (mode))
14537 unsigned int length = GET_MODE_SIZE (mode);
14538 unsigned char *array
14539 = (unsigned char*) ggc_alloc_atomic (length);
14541 insert_float (rtl, array);
14542 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14543 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14544 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14545 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14549 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14550 loc_result->dw_loc_oprnd2.v.val_double
14551 = rtx_to_double_int (rtl);
14557 if (mode == VOIDmode)
14558 mode = GET_MODE (rtl);
14560 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14562 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14563 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14564 unsigned char *array = (unsigned char *)
14565 ggc_alloc_atomic (length * elt_size);
14569 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14570 switch (GET_MODE_CLASS (mode))
14572 case MODE_VECTOR_INT:
14573 for (i = 0, p = array; i < length; i++, p += elt_size)
14575 rtx elt = CONST_VECTOR_ELT (rtl, i);
14576 double_int val = rtx_to_double_int (elt);
14578 if (elt_size <= sizeof (HOST_WIDE_INT))
14579 insert_int (double_int_to_shwi (val), elt_size, p);
14582 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14583 insert_double (val, p);
14588 case MODE_VECTOR_FLOAT:
14589 for (i = 0, p = array; i < length; i++, p += elt_size)
14591 rtx elt = CONST_VECTOR_ELT (rtl, i);
14592 insert_float (elt, p);
14597 gcc_unreachable ();
14600 loc_result = new_loc_descr (DW_OP_implicit_value,
14601 length * elt_size, 0);
14602 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14603 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14604 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14605 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14610 if (mode == VOIDmode
14611 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14612 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14613 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14615 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14620 if (!const_ok_for_output (rtl))
14623 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14624 && (dwarf_version >= 4 || !dwarf_strict))
14626 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14627 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14628 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14629 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14630 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14634 case DEBUG_IMPLICIT_PTR:
14635 loc_result = implicit_ptr_descriptor (rtl, 0);
14639 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14640 && CONST_INT_P (XEXP (rtl, 1)))
14643 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14648 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14649 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14650 && (dwarf_version >= 4 || !dwarf_strict))
14652 /* Value expression. */
14653 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14655 add_loc_descr (&loc_result,
14656 new_loc_descr (DW_OP_stack_value, 0, 0));
14664 /* We need to figure out what section we should use as the base for the
14665 address ranges where a given location is valid.
14666 1. If this particular DECL has a section associated with it, use that.
14667 2. If this function has a section associated with it, use that.
14668 3. Otherwise, use the text section.
14669 XXX: If you split a variable across multiple sections, we won't notice. */
14671 static const char *
14672 secname_for_decl (const_tree decl)
14674 const char *secname;
14676 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14678 tree sectree = DECL_SECTION_NAME (decl);
14679 secname = TREE_STRING_POINTER (sectree);
14681 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14683 tree sectree = DECL_SECTION_NAME (current_function_decl);
14684 secname = TREE_STRING_POINTER (sectree);
14686 else if (cfun && in_cold_section_p)
14687 secname = crtl->subsections.cold_section_label;
14689 secname = text_section_label;
14694 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14697 decl_by_reference_p (tree decl)
14699 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14700 || TREE_CODE (decl) == VAR_DECL)
14701 && DECL_BY_REFERENCE (decl));
14704 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14707 static dw_loc_descr_ref
14708 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14709 enum var_init_status initialized)
14711 int have_address = 0;
14712 dw_loc_descr_ref descr;
14713 enum machine_mode mode;
14715 if (want_address != 2)
14717 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14719 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14721 varloc = PAT_VAR_LOCATION_LOC (varloc);
14722 if (GET_CODE (varloc) == EXPR_LIST)
14723 varloc = XEXP (varloc, 0);
14724 mode = GET_MODE (varloc);
14725 if (MEM_P (varloc))
14727 rtx addr = XEXP (varloc, 0);
14728 descr = mem_loc_descriptor (addr, mode, initialized);
14733 rtx x = avoid_constant_pool_reference (varloc);
14735 descr = mem_loc_descriptor (x, mode, initialized);
14739 descr = mem_loc_descriptor (varloc, mode, initialized);
14746 if (GET_CODE (varloc) == VAR_LOCATION)
14747 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14749 mode = DECL_MODE (loc);
14750 descr = loc_descriptor (varloc, mode, initialized);
14757 if (want_address == 2 && !have_address
14758 && (dwarf_version >= 4 || !dwarf_strict))
14760 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14762 expansion_failed (loc, NULL_RTX,
14763 "DWARF address size mismatch");
14766 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14769 /* Show if we can't fill the request for an address. */
14770 if (want_address && !have_address)
14772 expansion_failed (loc, NULL_RTX,
14773 "Want address and only have value");
14777 /* If we've got an address and don't want one, dereference. */
14778 if (!want_address && have_address)
14780 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14781 enum dwarf_location_atom op;
14783 if (size > DWARF2_ADDR_SIZE || size == -1)
14785 expansion_failed (loc, NULL_RTX,
14786 "DWARF address size mismatch");
14789 else if (size == DWARF2_ADDR_SIZE)
14792 op = DW_OP_deref_size;
14794 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14800 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14801 if it is not possible. */
14803 static dw_loc_descr_ref
14804 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14806 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14807 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14808 else if (dwarf_version >= 3 || !dwarf_strict)
14809 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14814 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14815 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14817 static dw_loc_descr_ref
14818 dw_sra_loc_expr (tree decl, rtx loc)
14821 unsigned int padsize = 0;
14822 dw_loc_descr_ref descr, *descr_tail;
14823 unsigned HOST_WIDE_INT decl_size;
14825 enum var_init_status initialized;
14827 if (DECL_SIZE (decl) == NULL
14828 || !host_integerp (DECL_SIZE (decl), 1))
14831 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14833 descr_tail = &descr;
14835 for (p = loc; p; p = XEXP (p, 1))
14837 unsigned int bitsize = decl_piece_bitsize (p);
14838 rtx loc_note = *decl_piece_varloc_ptr (p);
14839 dw_loc_descr_ref cur_descr;
14840 dw_loc_descr_ref *tail, last = NULL;
14841 unsigned int opsize = 0;
14843 if (loc_note == NULL_RTX
14844 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14846 padsize += bitsize;
14849 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14850 varloc = NOTE_VAR_LOCATION (loc_note);
14851 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14852 if (cur_descr == NULL)
14854 padsize += bitsize;
14858 /* Check that cur_descr either doesn't use
14859 DW_OP_*piece operations, or their sum is equal
14860 to bitsize. Otherwise we can't embed it. */
14861 for (tail = &cur_descr; *tail != NULL;
14862 tail = &(*tail)->dw_loc_next)
14863 if ((*tail)->dw_loc_opc == DW_OP_piece)
14865 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14869 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14871 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14875 if (last != NULL && opsize != bitsize)
14877 padsize += bitsize;
14881 /* If there is a hole, add DW_OP_*piece after empty DWARF
14882 expression, which means that those bits are optimized out. */
14885 if (padsize > decl_size)
14887 decl_size -= padsize;
14888 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14889 if (*descr_tail == NULL)
14891 descr_tail = &(*descr_tail)->dw_loc_next;
14894 *descr_tail = cur_descr;
14896 if (bitsize > decl_size)
14898 decl_size -= bitsize;
14901 HOST_WIDE_INT offset = 0;
14902 if (GET_CODE (varloc) == VAR_LOCATION
14903 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14905 varloc = PAT_VAR_LOCATION_LOC (varloc);
14906 if (GET_CODE (varloc) == EXPR_LIST)
14907 varloc = XEXP (varloc, 0);
14911 if (GET_CODE (varloc) == CONST
14912 || GET_CODE (varloc) == SIGN_EXTEND
14913 || GET_CODE (varloc) == ZERO_EXTEND)
14914 varloc = XEXP (varloc, 0);
14915 else if (GET_CODE (varloc) == SUBREG)
14916 varloc = SUBREG_REG (varloc);
14921 /* DW_OP_bit_size offset should be zero for register
14922 or implicit location descriptions and empty location
14923 descriptions, but for memory addresses needs big endian
14925 if (MEM_P (varloc))
14927 unsigned HOST_WIDE_INT memsize
14928 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
14929 if (memsize != bitsize)
14931 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14932 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14934 if (memsize < bitsize)
14936 if (BITS_BIG_ENDIAN)
14937 offset = memsize - bitsize;
14941 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14942 if (*descr_tail == NULL)
14944 descr_tail = &(*descr_tail)->dw_loc_next;
14948 /* If there were any non-empty expressions, add padding till the end of
14950 if (descr != NULL && decl_size != 0)
14952 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14953 if (*descr_tail == NULL)
14959 /* Return the dwarf representation of the location list LOC_LIST of
14960 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14963 static dw_loc_list_ref
14964 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14966 const char *endname, *secname;
14968 enum var_init_status initialized;
14969 struct var_loc_node *node;
14970 dw_loc_descr_ref descr;
14971 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14972 dw_loc_list_ref list = NULL;
14973 dw_loc_list_ref *listp = &list;
14975 /* Now that we know what section we are using for a base,
14976 actually construct the list of locations.
14977 The first location information is what is passed to the
14978 function that creates the location list, and the remaining
14979 locations just get added on to that list.
14980 Note that we only know the start address for a location
14981 (IE location changes), so to build the range, we use
14982 the range [current location start, next location start].
14983 This means we have to special case the last node, and generate
14984 a range of [last location start, end of function label]. */
14986 secname = secname_for_decl (decl);
14988 for (node = loc_list->first; node; node = node->next)
14989 if (GET_CODE (node->loc) == EXPR_LIST
14990 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14992 if (GET_CODE (node->loc) == EXPR_LIST)
14994 /* This requires DW_OP_{,bit_}piece, which is not usable
14995 inside DWARF expressions. */
14996 if (want_address != 2)
14998 descr = dw_sra_loc_expr (decl, node->loc);
15004 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15005 varloc = NOTE_VAR_LOCATION (node->loc);
15006 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15010 bool range_across_switch = false;
15011 /* If section switch happens in between node->label
15012 and node->next->label (or end of function) and
15013 we can't emit it as a single entry list,
15014 emit two ranges, first one ending at the end
15015 of first partition and second one starting at the
15016 beginning of second partition. */
15017 if (node == loc_list->last_before_switch
15018 && (node != loc_list->first || loc_list->first->next)
15019 && current_function_decl)
15021 endname = current_fde ()->dw_fde_end;
15022 range_across_switch = true;
15024 /* The variable has a location between NODE->LABEL and
15025 NODE->NEXT->LABEL. */
15026 else if (node->next)
15027 endname = node->next->label;
15028 /* If the variable has a location at the last label
15029 it keeps its location until the end of function. */
15030 else if (!current_function_decl)
15031 endname = text_end_label;
15034 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15035 current_function_funcdef_no);
15036 endname = ggc_strdup (label_id);
15039 *listp = new_loc_list (descr, node->label, endname, secname);
15040 listp = &(*listp)->dw_loc_next;
15042 if (range_across_switch)
15044 if (GET_CODE (node->loc) == EXPR_LIST)
15045 descr = dw_sra_loc_expr (decl, node->loc);
15048 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15049 varloc = NOTE_VAR_LOCATION (node->loc);
15050 descr = dw_loc_list_1 (decl, varloc, want_address,
15053 gcc_assert (descr);
15054 /* The variable has a location between NODE->LABEL and
15055 NODE->NEXT->LABEL. */
15057 endname = node->next->label;
15059 endname = current_fde ()->dw_fde_second_end;
15060 *listp = new_loc_list (descr,
15061 current_fde ()->dw_fde_second_begin,
15063 listp = &(*listp)->dw_loc_next;
15068 /* Try to avoid the overhead of a location list emitting a location
15069 expression instead, but only if we didn't have more than one
15070 location entry in the first place. If some entries were not
15071 representable, we don't want to pretend a single entry that was
15072 applies to the entire scope in which the variable is
15074 if (list && loc_list->first->next)
15080 /* Return if the loc_list has only single element and thus can be represented
15081 as location description. */
15084 single_element_loc_list_p (dw_loc_list_ref list)
15086 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15087 return !list->ll_symbol;
15090 /* To each location in list LIST add loc descr REF. */
15093 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15095 dw_loc_descr_ref copy;
15096 add_loc_descr (&list->expr, ref);
15097 list = list->dw_loc_next;
15100 copy = ggc_alloc_dw_loc_descr_node ();
15101 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15102 add_loc_descr (&list->expr, copy);
15103 while (copy->dw_loc_next)
15105 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15106 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15107 copy->dw_loc_next = new_copy;
15110 list = list->dw_loc_next;
15114 /* Given two lists RET and LIST
15115 produce location list that is result of adding expression in LIST
15116 to expression in RET on each possition in program.
15117 Might be destructive on both RET and LIST.
15119 TODO: We handle only simple cases of RET or LIST having at most one
15120 element. General case would inolve sorting the lists in program order
15121 and merging them that will need some additional work.
15122 Adding that will improve quality of debug info especially for SRA-ed
15126 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15135 if (!list->dw_loc_next)
15137 add_loc_descr_to_each (*ret, list->expr);
15140 if (!(*ret)->dw_loc_next)
15142 add_loc_descr_to_each (list, (*ret)->expr);
15146 expansion_failed (NULL_TREE, NULL_RTX,
15147 "Don't know how to merge two non-trivial"
15148 " location lists.\n");
15153 /* LOC is constant expression. Try a luck, look it up in constant
15154 pool and return its loc_descr of its address. */
15156 static dw_loc_descr_ref
15157 cst_pool_loc_descr (tree loc)
15159 /* Get an RTL for this, if something has been emitted. */
15160 rtx rtl = lookup_constant_def (loc);
15161 enum machine_mode mode;
15163 if (!rtl || !MEM_P (rtl))
15168 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15170 /* TODO: We might get more coverage if we was actually delaying expansion
15171 of all expressions till end of compilation when constant pools are fully
15173 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15175 expansion_failed (loc, NULL_RTX,
15176 "CST value in contant pool but not marked.");
15179 mode = GET_MODE (rtl);
15180 rtl = XEXP (rtl, 0);
15181 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15184 /* Return dw_loc_list representing address of addr_expr LOC
15185 by looking for innder INDIRECT_REF expression and turing it
15186 into simple arithmetics. */
15188 static dw_loc_list_ref
15189 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15192 HOST_WIDE_INT bitsize, bitpos, bytepos;
15193 enum machine_mode mode;
15195 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15196 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15198 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15199 &bitsize, &bitpos, &offset, &mode,
15200 &unsignedp, &volatilep, false);
15202 if (bitpos % BITS_PER_UNIT)
15204 expansion_failed (loc, NULL_RTX, "bitfield access");
15207 if (!INDIRECT_REF_P (obj))
15209 expansion_failed (obj,
15210 NULL_RTX, "no indirect ref in inner refrence");
15213 if (!offset && !bitpos)
15214 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15216 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15217 && (dwarf_version >= 4 || !dwarf_strict))
15219 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15224 /* Variable offset. */
15225 list_ret1 = loc_list_from_tree (offset, 0);
15226 if (list_ret1 == 0)
15228 add_loc_list (&list_ret, list_ret1);
15231 add_loc_descr_to_each (list_ret,
15232 new_loc_descr (DW_OP_plus, 0, 0));
15234 bytepos = bitpos / BITS_PER_UNIT;
15236 add_loc_descr_to_each (list_ret,
15237 new_loc_descr (DW_OP_plus_uconst,
15239 else if (bytepos < 0)
15240 loc_list_plus_const (list_ret, bytepos);
15241 add_loc_descr_to_each (list_ret,
15242 new_loc_descr (DW_OP_stack_value, 0, 0));
15248 /* Generate Dwarf location list representing LOC.
15249 If WANT_ADDRESS is false, expression computing LOC will be computed
15250 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15251 if WANT_ADDRESS is 2, expression computing address useable in location
15252 will be returned (i.e. DW_OP_reg can be used
15253 to refer to register values). */
15255 static dw_loc_list_ref
15256 loc_list_from_tree (tree loc, int want_address)
15258 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15259 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15260 int have_address = 0;
15261 enum dwarf_location_atom op;
15263 /* ??? Most of the time we do not take proper care for sign/zero
15264 extending the values properly. Hopefully this won't be a real
15267 switch (TREE_CODE (loc))
15270 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15273 case PLACEHOLDER_EXPR:
15274 /* This case involves extracting fields from an object to determine the
15275 position of other fields. We don't try to encode this here. The
15276 only user of this is Ada, which encodes the needed information using
15277 the names of types. */
15278 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15282 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15283 /* There are no opcodes for these operations. */
15286 case PREINCREMENT_EXPR:
15287 case PREDECREMENT_EXPR:
15288 case POSTINCREMENT_EXPR:
15289 case POSTDECREMENT_EXPR:
15290 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15291 /* There are no opcodes for these operations. */
15295 /* If we already want an address, see if there is INDIRECT_REF inside
15296 e.g. for &this->field. */
15299 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15300 (loc, want_address == 2);
15303 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15304 && (ret = cst_pool_loc_descr (loc)))
15307 /* Otherwise, process the argument and look for the address. */
15308 if (!list_ret && !ret)
15309 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15313 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15319 if (DECL_THREAD_LOCAL_P (loc))
15322 enum dwarf_location_atom first_op;
15323 enum dwarf_location_atom second_op;
15324 bool dtprel = false;
15326 if (targetm.have_tls)
15328 /* If this is not defined, we have no way to emit the
15330 if (!targetm.asm_out.output_dwarf_dtprel)
15333 /* The way DW_OP_GNU_push_tls_address is specified, we
15334 can only look up addresses of objects in the current
15335 module. We used DW_OP_addr as first op, but that's
15336 wrong, because DW_OP_addr is relocated by the debug
15337 info consumer, while DW_OP_GNU_push_tls_address
15338 operand shouldn't be. */
15339 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15341 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15343 second_op = DW_OP_GNU_push_tls_address;
15347 if (!targetm.emutls.debug_form_tls_address
15348 || !(dwarf_version >= 3 || !dwarf_strict))
15350 /* We stuffed the control variable into the DECL_VALUE_EXPR
15351 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15352 no longer appear in gimple code. We used the control
15353 variable in specific so that we could pick it up here. */
15354 loc = DECL_VALUE_EXPR (loc);
15355 first_op = DW_OP_addr;
15356 second_op = DW_OP_form_tls_address;
15359 rtl = rtl_for_decl_location (loc);
15360 if (rtl == NULL_RTX)
15365 rtl = XEXP (rtl, 0);
15366 if (! CONSTANT_P (rtl))
15369 ret = new_loc_descr (first_op, 0, 0);
15370 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15371 ret->dw_loc_oprnd1.v.val_addr = rtl;
15372 ret->dtprel = dtprel;
15374 ret1 = new_loc_descr (second_op, 0, 0);
15375 add_loc_descr (&ret, ret1);
15384 if (DECL_HAS_VALUE_EXPR_P (loc))
15385 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15389 case FUNCTION_DECL:
15392 var_loc_list *loc_list = lookup_decl_loc (loc);
15394 if (loc_list && loc_list->first)
15396 list_ret = dw_loc_list (loc_list, loc, want_address);
15397 have_address = want_address != 0;
15400 rtl = rtl_for_decl_location (loc);
15401 if (rtl == NULL_RTX)
15403 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15406 else if (CONST_INT_P (rtl))
15408 HOST_WIDE_INT val = INTVAL (rtl);
15409 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15410 val &= GET_MODE_MASK (DECL_MODE (loc));
15411 ret = int_loc_descriptor (val);
15413 else if (GET_CODE (rtl) == CONST_STRING)
15415 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15418 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15420 ret = new_loc_descr (DW_OP_addr, 0, 0);
15421 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15422 ret->dw_loc_oprnd1.v.val_addr = rtl;
15426 enum machine_mode mode;
15428 /* Certain constructs can only be represented at top-level. */
15429 if (want_address == 2)
15431 ret = loc_descriptor (rtl, VOIDmode,
15432 VAR_INIT_STATUS_INITIALIZED);
15437 mode = GET_MODE (rtl);
15440 rtl = XEXP (rtl, 0);
15443 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15446 expansion_failed (loc, rtl,
15447 "failed to produce loc descriptor for rtl");
15454 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15458 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15462 case COMPOUND_EXPR:
15463 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15466 case VIEW_CONVERT_EXPR:
15469 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15471 case COMPONENT_REF:
15472 case BIT_FIELD_REF:
15474 case ARRAY_RANGE_REF:
15475 case REALPART_EXPR:
15476 case IMAGPART_EXPR:
15479 HOST_WIDE_INT bitsize, bitpos, bytepos;
15480 enum machine_mode mode;
15482 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15484 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15485 &unsignedp, &volatilep, false);
15487 gcc_assert (obj != loc);
15489 list_ret = loc_list_from_tree (obj,
15491 && !bitpos && !offset ? 2 : 1);
15492 /* TODO: We can extract value of the small expression via shifting even
15493 for nonzero bitpos. */
15496 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15498 expansion_failed (loc, NULL_RTX,
15499 "bitfield access");
15503 if (offset != NULL_TREE)
15505 /* Variable offset. */
15506 list_ret1 = loc_list_from_tree (offset, 0);
15507 if (list_ret1 == 0)
15509 add_loc_list (&list_ret, list_ret1);
15512 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15515 bytepos = bitpos / BITS_PER_UNIT;
15517 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15518 else if (bytepos < 0)
15519 loc_list_plus_const (list_ret, bytepos);
15526 if ((want_address || !host_integerp (loc, 0))
15527 && (ret = cst_pool_loc_descr (loc)))
15529 else if (want_address == 2
15530 && host_integerp (loc, 0)
15531 && (ret = address_of_int_loc_descriptor
15532 (int_size_in_bytes (TREE_TYPE (loc)),
15533 tree_low_cst (loc, 0))))
15535 else if (host_integerp (loc, 0))
15536 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15539 expansion_failed (loc, NULL_RTX,
15540 "Integer operand is not host integer");
15549 if ((ret = cst_pool_loc_descr (loc)))
15552 /* We can construct small constants here using int_loc_descriptor. */
15553 expansion_failed (loc, NULL_RTX,
15554 "constructor or constant not in constant pool");
15557 case TRUTH_AND_EXPR:
15558 case TRUTH_ANDIF_EXPR:
15563 case TRUTH_XOR_EXPR:
15568 case TRUTH_OR_EXPR:
15569 case TRUTH_ORIF_EXPR:
15574 case FLOOR_DIV_EXPR:
15575 case CEIL_DIV_EXPR:
15576 case ROUND_DIV_EXPR:
15577 case TRUNC_DIV_EXPR:
15578 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15587 case FLOOR_MOD_EXPR:
15588 case CEIL_MOD_EXPR:
15589 case ROUND_MOD_EXPR:
15590 case TRUNC_MOD_EXPR:
15591 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15596 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15597 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15598 if (list_ret == 0 || list_ret1 == 0)
15601 add_loc_list (&list_ret, list_ret1);
15604 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15605 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15606 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15607 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15608 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15620 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15623 case POINTER_PLUS_EXPR:
15625 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15627 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15631 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15639 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15646 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15653 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15660 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15675 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15676 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15677 if (list_ret == 0 || list_ret1 == 0)
15680 add_loc_list (&list_ret, list_ret1);
15683 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15686 case TRUTH_NOT_EXPR:
15700 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15704 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15710 const enum tree_code code =
15711 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15713 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15714 build2 (code, integer_type_node,
15715 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15716 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15719 /* ... fall through ... */
15723 dw_loc_descr_ref lhs
15724 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15725 dw_loc_list_ref rhs
15726 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15727 dw_loc_descr_ref bra_node, jump_node, tmp;
15729 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15730 if (list_ret == 0 || lhs == 0 || rhs == 0)
15733 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15734 add_loc_descr_to_each (list_ret, bra_node);
15736 add_loc_list (&list_ret, rhs);
15737 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15738 add_loc_descr_to_each (list_ret, jump_node);
15740 add_loc_descr_to_each (list_ret, lhs);
15741 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15742 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15744 /* ??? Need a node to point the skip at. Use a nop. */
15745 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15746 add_loc_descr_to_each (list_ret, tmp);
15747 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15748 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15752 case FIX_TRUNC_EXPR:
15756 /* Leave front-end specific codes as simply unknown. This comes
15757 up, for instance, with the C STMT_EXPR. */
15758 if ((unsigned int) TREE_CODE (loc)
15759 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15761 expansion_failed (loc, NULL_RTX,
15762 "language specific tree node");
15766 #ifdef ENABLE_CHECKING
15767 /* Otherwise this is a generic code; we should just lists all of
15768 these explicitly. We forgot one. */
15769 gcc_unreachable ();
15771 /* In a release build, we want to degrade gracefully: better to
15772 generate incomplete debugging information than to crash. */
15777 if (!ret && !list_ret)
15780 if (want_address == 2 && !have_address
15781 && (dwarf_version >= 4 || !dwarf_strict))
15783 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15785 expansion_failed (loc, NULL_RTX,
15786 "DWARF address size mismatch");
15790 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15792 add_loc_descr_to_each (list_ret,
15793 new_loc_descr (DW_OP_stack_value, 0, 0));
15796 /* Show if we can't fill the request for an address. */
15797 if (want_address && !have_address)
15799 expansion_failed (loc, NULL_RTX,
15800 "Want address and only have value");
15804 gcc_assert (!ret || !list_ret);
15806 /* If we've got an address and don't want one, dereference. */
15807 if (!want_address && have_address)
15809 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15811 if (size > DWARF2_ADDR_SIZE || size == -1)
15813 expansion_failed (loc, NULL_RTX,
15814 "DWARF address size mismatch");
15817 else if (size == DWARF2_ADDR_SIZE)
15820 op = DW_OP_deref_size;
15823 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15825 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15828 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15833 /* Same as above but return only single location expression. */
15834 static dw_loc_descr_ref
15835 loc_descriptor_from_tree (tree loc, int want_address)
15837 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15840 if (ret->dw_loc_next)
15842 expansion_failed (loc, NULL_RTX,
15843 "Location list where only loc descriptor needed");
15849 /* Given a value, round it up to the lowest multiple of `boundary'
15850 which is not less than the value itself. */
15852 static inline HOST_WIDE_INT
15853 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15855 return (((value + boundary - 1) / boundary) * boundary);
15858 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15859 pointer to the declared type for the relevant field variable, or return
15860 `integer_type_node' if the given node turns out to be an
15861 ERROR_MARK node. */
15864 field_type (const_tree decl)
15868 if (TREE_CODE (decl) == ERROR_MARK)
15869 return integer_type_node;
15871 type = DECL_BIT_FIELD_TYPE (decl);
15872 if (type == NULL_TREE)
15873 type = TREE_TYPE (decl);
15878 /* Given a pointer to a tree node, return the alignment in bits for
15879 it, or else return BITS_PER_WORD if the node actually turns out to
15880 be an ERROR_MARK node. */
15882 static inline unsigned
15883 simple_type_align_in_bits (const_tree type)
15885 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15888 static inline unsigned
15889 simple_decl_align_in_bits (const_tree decl)
15891 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15894 /* Return the result of rounding T up to ALIGN. */
15896 static inline double_int
15897 round_up_to_align (double_int t, unsigned int align)
15899 double_int alignd = uhwi_to_double_int (align);
15900 t = double_int_add (t, alignd);
15901 t = double_int_add (t, double_int_minus_one);
15902 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15903 t = double_int_mul (t, alignd);
15907 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15908 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15909 or return 0 if we are unable to determine what that offset is, either
15910 because the argument turns out to be a pointer to an ERROR_MARK node, or
15911 because the offset is actually variable. (We can't handle the latter case
15914 static HOST_WIDE_INT
15915 field_byte_offset (const_tree decl)
15917 double_int object_offset_in_bits;
15918 double_int object_offset_in_bytes;
15919 double_int bitpos_int;
15921 if (TREE_CODE (decl) == ERROR_MARK)
15924 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15926 /* We cannot yet cope with fields whose positions are variable, so
15927 for now, when we see such things, we simply return 0. Someday, we may
15928 be able to handle such cases, but it will be damn difficult. */
15929 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15932 bitpos_int = tree_to_double_int (bit_position (decl));
15934 #ifdef PCC_BITFIELD_TYPE_MATTERS
15935 if (PCC_BITFIELD_TYPE_MATTERS)
15938 tree field_size_tree;
15939 double_int deepest_bitpos;
15940 double_int field_size_in_bits;
15941 unsigned int type_align_in_bits;
15942 unsigned int decl_align_in_bits;
15943 double_int type_size_in_bits;
15945 type = field_type (decl);
15946 type_size_in_bits = double_int_type_size_in_bits (type);
15947 type_align_in_bits = simple_type_align_in_bits (type);
15949 field_size_tree = DECL_SIZE (decl);
15951 /* The size could be unspecified if there was an error, or for
15952 a flexible array member. */
15953 if (!field_size_tree)
15954 field_size_tree = bitsize_zero_node;
15956 /* If the size of the field is not constant, use the type size. */
15957 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15958 field_size_in_bits = tree_to_double_int (field_size_tree);
15960 field_size_in_bits = type_size_in_bits;
15962 decl_align_in_bits = simple_decl_align_in_bits (decl);
15964 /* The GCC front-end doesn't make any attempt to keep track of the
15965 starting bit offset (relative to the start of the containing
15966 structure type) of the hypothetical "containing object" for a
15967 bit-field. Thus, when computing the byte offset value for the
15968 start of the "containing object" of a bit-field, we must deduce
15969 this information on our own. This can be rather tricky to do in
15970 some cases. For example, handling the following structure type
15971 definition when compiling for an i386/i486 target (which only
15972 aligns long long's to 32-bit boundaries) can be very tricky:
15974 struct S { int field1; long long field2:31; };
15976 Fortunately, there is a simple rule-of-thumb which can be used
15977 in such cases. When compiling for an i386/i486, GCC will
15978 allocate 8 bytes for the structure shown above. It decides to
15979 do this based upon one simple rule for bit-field allocation.
15980 GCC allocates each "containing object" for each bit-field at
15981 the first (i.e. lowest addressed) legitimate alignment boundary
15982 (based upon the required minimum alignment for the declared
15983 type of the field) which it can possibly use, subject to the
15984 condition that there is still enough available space remaining
15985 in the containing object (when allocated at the selected point)
15986 to fully accommodate all of the bits of the bit-field itself.
15988 This simple rule makes it obvious why GCC allocates 8 bytes for
15989 each object of the structure type shown above. When looking
15990 for a place to allocate the "containing object" for `field2',
15991 the compiler simply tries to allocate a 64-bit "containing
15992 object" at each successive 32-bit boundary (starting at zero)
15993 until it finds a place to allocate that 64- bit field such that
15994 at least 31 contiguous (and previously unallocated) bits remain
15995 within that selected 64 bit field. (As it turns out, for the
15996 example above, the compiler finds it is OK to allocate the
15997 "containing object" 64-bit field at bit-offset zero within the
16000 Here we attempt to work backwards from the limited set of facts
16001 we're given, and we try to deduce from those facts, where GCC
16002 must have believed that the containing object started (within
16003 the structure type). The value we deduce is then used (by the
16004 callers of this routine) to generate DW_AT_location and
16005 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16006 the case of DW_AT_location, regular fields as well). */
16008 /* Figure out the bit-distance from the start of the structure to
16009 the "deepest" bit of the bit-field. */
16010 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16012 /* This is the tricky part. Use some fancy footwork to deduce
16013 where the lowest addressed bit of the containing object must
16015 object_offset_in_bits
16016 = double_int_sub (deepest_bitpos, type_size_in_bits);
16018 /* Round up to type_align by default. This works best for
16020 object_offset_in_bits
16021 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16023 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16025 object_offset_in_bits
16026 = double_int_sub (deepest_bitpos, type_size_in_bits);
16028 /* Round up to decl_align instead. */
16029 object_offset_in_bits
16030 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16034 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16035 object_offset_in_bits = bitpos_int;
16037 object_offset_in_bytes
16038 = double_int_div (object_offset_in_bits,
16039 uhwi_to_double_int (BITS_PER_UNIT), true,
16041 return double_int_to_shwi (object_offset_in_bytes);
16044 /* The following routines define various Dwarf attributes and any data
16045 associated with them. */
16047 /* Add a location description attribute value to a DIE.
16049 This emits location attributes suitable for whole variables and
16050 whole parameters. Note that the location attributes for struct fields are
16051 generated by the routine `data_member_location_attribute' below. */
16054 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16055 dw_loc_list_ref descr)
16059 if (single_element_loc_list_p (descr))
16060 add_AT_loc (die, attr_kind, descr->expr);
16062 add_AT_loc_list (die, attr_kind, descr);
16065 /* Add DW_AT_accessibility attribute to DIE if needed. */
16068 add_accessibility_attribute (dw_die_ref die, tree decl)
16070 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16071 children, otherwise the default is DW_ACCESS_public. In DWARF2
16072 the default has always been DW_ACCESS_public. */
16073 if (TREE_PROTECTED (decl))
16074 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16075 else if (TREE_PRIVATE (decl))
16077 if (dwarf_version == 2
16078 || die->die_parent == NULL
16079 || die->die_parent->die_tag != DW_TAG_class_type)
16080 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16082 else if (dwarf_version > 2
16084 && die->die_parent->die_tag == DW_TAG_class_type)
16085 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16088 /* Attach the specialized form of location attribute used for data members of
16089 struct and union types. In the special case of a FIELD_DECL node which
16090 represents a bit-field, the "offset" part of this special location
16091 descriptor must indicate the distance in bytes from the lowest-addressed
16092 byte of the containing struct or union type to the lowest-addressed byte of
16093 the "containing object" for the bit-field. (See the `field_byte_offset'
16096 For any given bit-field, the "containing object" is a hypothetical object
16097 (of some integral or enum type) within which the given bit-field lives. The
16098 type of this hypothetical "containing object" is always the same as the
16099 declared type of the individual bit-field itself (for GCC anyway... the
16100 DWARF spec doesn't actually mandate this). Note that it is the size (in
16101 bytes) of the hypothetical "containing object" which will be given in the
16102 DW_AT_byte_size attribute for this bit-field. (See the
16103 `byte_size_attribute' function below.) It is also used when calculating the
16104 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16105 function below.) */
16108 add_data_member_location_attribute (dw_die_ref die, tree decl)
16110 HOST_WIDE_INT offset;
16111 dw_loc_descr_ref loc_descr = 0;
16113 if (TREE_CODE (decl) == TREE_BINFO)
16115 /* We're working on the TAG_inheritance for a base class. */
16116 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16118 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16119 aren't at a fixed offset from all (sub)objects of the same
16120 type. We need to extract the appropriate offset from our
16121 vtable. The following dwarf expression means
16123 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16125 This is specific to the V3 ABI, of course. */
16127 dw_loc_descr_ref tmp;
16129 /* Make a copy of the object address. */
16130 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16131 add_loc_descr (&loc_descr, tmp);
16133 /* Extract the vtable address. */
16134 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16135 add_loc_descr (&loc_descr, tmp);
16137 /* Calculate the address of the offset. */
16138 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16139 gcc_assert (offset < 0);
16141 tmp = int_loc_descriptor (-offset);
16142 add_loc_descr (&loc_descr, tmp);
16143 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16144 add_loc_descr (&loc_descr, tmp);
16146 /* Extract the offset. */
16147 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16148 add_loc_descr (&loc_descr, tmp);
16150 /* Add it to the object address. */
16151 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16152 add_loc_descr (&loc_descr, tmp);
16155 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16158 offset = field_byte_offset (decl);
16162 if (dwarf_version > 2)
16164 /* Don't need to output a location expression, just the constant. */
16166 add_AT_int (die, DW_AT_data_member_location, offset);
16168 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16173 enum dwarf_location_atom op;
16175 /* The DWARF2 standard says that we should assume that the structure
16176 address is already on the stack, so we can specify a structure
16177 field address by using DW_OP_plus_uconst. */
16179 #ifdef MIPS_DEBUGGING_INFO
16180 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16181 operator correctly. It works only if we leave the offset on the
16185 op = DW_OP_plus_uconst;
16188 loc_descr = new_loc_descr (op, offset, 0);
16192 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16195 /* Writes integer values to dw_vec_const array. */
16198 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16202 *dest++ = val & 0xff;
16208 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16210 static HOST_WIDE_INT
16211 extract_int (const unsigned char *src, unsigned int size)
16213 HOST_WIDE_INT val = 0;
16219 val |= *--src & 0xff;
16225 /* Writes double_int values to dw_vec_const array. */
16228 insert_double (double_int val, unsigned char *dest)
16230 unsigned char *p0 = dest;
16231 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16233 if (WORDS_BIG_ENDIAN)
16239 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16240 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16243 /* Writes floating point values to dw_vec_const array. */
16246 insert_float (const_rtx rtl, unsigned char *array)
16248 REAL_VALUE_TYPE rv;
16252 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16253 real_to_target (val, &rv, GET_MODE (rtl));
16255 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16256 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16258 insert_int (val[i], 4, array);
16263 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16264 does not have a "location" either in memory or in a register. These
16265 things can arise in GNU C when a constant is passed as an actual parameter
16266 to an inlined function. They can also arise in C++ where declared
16267 constants do not necessarily get memory "homes". */
16270 add_const_value_attribute (dw_die_ref die, rtx rtl)
16272 switch (GET_CODE (rtl))
16276 HOST_WIDE_INT val = INTVAL (rtl);
16279 add_AT_int (die, DW_AT_const_value, val);
16281 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16286 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16287 floating-point constant. A CONST_DOUBLE is used whenever the
16288 constant requires more than one word in order to be adequately
16291 enum machine_mode mode = GET_MODE (rtl);
16293 if (SCALAR_FLOAT_MODE_P (mode))
16295 unsigned int length = GET_MODE_SIZE (mode);
16296 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16298 insert_float (rtl, array);
16299 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16302 add_AT_double (die, DW_AT_const_value,
16303 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16309 enum machine_mode mode = GET_MODE (rtl);
16310 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16311 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16312 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16313 (length * elt_size);
16317 switch (GET_MODE_CLASS (mode))
16319 case MODE_VECTOR_INT:
16320 for (i = 0, p = array; i < length; i++, p += elt_size)
16322 rtx elt = CONST_VECTOR_ELT (rtl, i);
16323 double_int val = rtx_to_double_int (elt);
16325 if (elt_size <= sizeof (HOST_WIDE_INT))
16326 insert_int (double_int_to_shwi (val), elt_size, p);
16329 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16330 insert_double (val, p);
16335 case MODE_VECTOR_FLOAT:
16336 for (i = 0, p = array; i < length; i++, p += elt_size)
16338 rtx elt = CONST_VECTOR_ELT (rtl, i);
16339 insert_float (elt, p);
16344 gcc_unreachable ();
16347 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16352 if (dwarf_version >= 4 || !dwarf_strict)
16354 dw_loc_descr_ref loc_result;
16355 resolve_one_addr (&rtl, NULL);
16357 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16358 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16359 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16360 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16361 add_AT_loc (die, DW_AT_location, loc_result);
16362 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16368 if (CONSTANT_P (XEXP (rtl, 0)))
16369 return add_const_value_attribute (die, XEXP (rtl, 0));
16372 if (!const_ok_for_output (rtl))
16375 if (dwarf_version >= 4 || !dwarf_strict)
16380 /* In cases where an inlined instance of an inline function is passed
16381 the address of an `auto' variable (which is local to the caller) we
16382 can get a situation where the DECL_RTL of the artificial local
16383 variable (for the inlining) which acts as a stand-in for the
16384 corresponding formal parameter (of the inline function) will look
16385 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16386 exactly a compile-time constant expression, but it isn't the address
16387 of the (artificial) local variable either. Rather, it represents the
16388 *value* which the artificial local variable always has during its
16389 lifetime. We currently have no way to represent such quasi-constant
16390 values in Dwarf, so for now we just punt and generate nothing. */
16398 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16399 && MEM_READONLY_P (rtl)
16400 && GET_MODE (rtl) == BLKmode)
16402 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16408 /* No other kinds of rtx should be possible here. */
16409 gcc_unreachable ();
16414 /* Determine whether the evaluation of EXPR references any variables
16415 or functions which aren't otherwise used (and therefore may not be
16418 reference_to_unused (tree * tp, int * walk_subtrees,
16419 void * data ATTRIBUTE_UNUSED)
16421 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16422 *walk_subtrees = 0;
16424 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16425 && ! TREE_ASM_WRITTEN (*tp))
16427 /* ??? The C++ FE emits debug information for using decls, so
16428 putting gcc_unreachable here falls over. See PR31899. For now
16429 be conservative. */
16430 else if (!cgraph_global_info_ready
16431 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16433 else if (TREE_CODE (*tp) == VAR_DECL)
16435 struct varpool_node *node = varpool_get_node (*tp);
16436 if (!node || !node->needed)
16439 else if (TREE_CODE (*tp) == FUNCTION_DECL
16440 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16442 /* The call graph machinery must have finished analyzing,
16443 optimizing and gimplifying the CU by now.
16444 So if *TP has no call graph node associated
16445 to it, it means *TP will not be emitted. */
16446 if (!cgraph_get_node (*tp))
16449 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16455 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16456 for use in a later add_const_value_attribute call. */
16459 rtl_for_decl_init (tree init, tree type)
16461 rtx rtl = NULL_RTX;
16465 /* If a variable is initialized with a string constant without embedded
16466 zeros, build CONST_STRING. */
16467 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16469 tree enttype = TREE_TYPE (type);
16470 tree domain = TYPE_DOMAIN (type);
16471 enum machine_mode mode = TYPE_MODE (enttype);
16473 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16475 && integer_zerop (TYPE_MIN_VALUE (domain))
16476 && compare_tree_int (TYPE_MAX_VALUE (domain),
16477 TREE_STRING_LENGTH (init) - 1) == 0
16478 && ((size_t) TREE_STRING_LENGTH (init)
16479 == strlen (TREE_STRING_POINTER (init)) + 1))
16481 rtl = gen_rtx_CONST_STRING (VOIDmode,
16482 ggc_strdup (TREE_STRING_POINTER (init)));
16483 rtl = gen_rtx_MEM (BLKmode, rtl);
16484 MEM_READONLY_P (rtl) = 1;
16487 /* Other aggregates, and complex values, could be represented using
16489 else if (AGGREGATE_TYPE_P (type)
16490 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16491 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16492 || TREE_CODE (type) == COMPLEX_TYPE)
16494 /* Vectors only work if their mode is supported by the target.
16495 FIXME: generic vectors ought to work too. */
16496 else if (TREE_CODE (type) == VECTOR_TYPE
16497 && !VECTOR_MODE_P (TYPE_MODE (type)))
16499 /* If the initializer is something that we know will expand into an
16500 immediate RTL constant, expand it now. We must be careful not to
16501 reference variables which won't be output. */
16502 else if (initializer_constant_valid_p (init, type)
16503 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16505 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16507 if (TREE_CODE (type) == VECTOR_TYPE)
16508 switch (TREE_CODE (init))
16513 if (TREE_CONSTANT (init))
16515 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16516 bool constant_p = true;
16518 unsigned HOST_WIDE_INT ix;
16520 /* Even when ctor is constant, it might contain non-*_CST
16521 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16522 belong into VECTOR_CST nodes. */
16523 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16524 if (!CONSTANT_CLASS_P (value))
16526 constant_p = false;
16532 init = build_vector_from_ctor (type, elts);
16542 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16544 /* If expand_expr returns a MEM, it wasn't immediate. */
16545 gcc_assert (!rtl || !MEM_P (rtl));
16551 /* Generate RTL for the variable DECL to represent its location. */
16554 rtl_for_decl_location (tree decl)
16558 /* Here we have to decide where we are going to say the parameter "lives"
16559 (as far as the debugger is concerned). We only have a couple of
16560 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16562 DECL_RTL normally indicates where the parameter lives during most of the
16563 activation of the function. If optimization is enabled however, this
16564 could be either NULL or else a pseudo-reg. Both of those cases indicate
16565 that the parameter doesn't really live anywhere (as far as the code
16566 generation parts of GCC are concerned) during most of the function's
16567 activation. That will happen (for example) if the parameter is never
16568 referenced within the function.
16570 We could just generate a location descriptor here for all non-NULL
16571 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16572 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16573 where DECL_RTL is NULL or is a pseudo-reg.
16575 Note however that we can only get away with using DECL_INCOMING_RTL as
16576 a backup substitute for DECL_RTL in certain limited cases. In cases
16577 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16578 we can be sure that the parameter was passed using the same type as it is
16579 declared to have within the function, and that its DECL_INCOMING_RTL
16580 points us to a place where a value of that type is passed.
16582 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16583 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16584 because in these cases DECL_INCOMING_RTL points us to a value of some
16585 type which is *different* from the type of the parameter itself. Thus,
16586 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16587 such cases, the debugger would end up (for example) trying to fetch a
16588 `float' from a place which actually contains the first part of a
16589 `double'. That would lead to really incorrect and confusing
16590 output at debug-time.
16592 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16593 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16594 are a couple of exceptions however. On little-endian machines we can
16595 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16596 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16597 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16598 when (on a little-endian machine) a non-prototyped function has a
16599 parameter declared to be of type `short' or `char'. In such cases,
16600 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16601 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16602 passed `int' value. If the debugger then uses that address to fetch
16603 a `short' or a `char' (on a little-endian machine) the result will be
16604 the correct data, so we allow for such exceptional cases below.
16606 Note that our goal here is to describe the place where the given formal
16607 parameter lives during most of the function's activation (i.e. between the
16608 end of the prologue and the start of the epilogue). We'll do that as best
16609 as we can. Note however that if the given formal parameter is modified
16610 sometime during the execution of the function, then a stack backtrace (at
16611 debug-time) will show the function as having been called with the *new*
16612 value rather than the value which was originally passed in. This happens
16613 rarely enough that it is not a major problem, but it *is* a problem, and
16614 I'd like to fix it.
16616 A future version of dwarf2out.c may generate two additional attributes for
16617 any given DW_TAG_formal_parameter DIE which will describe the "passed
16618 type" and the "passed location" for the given formal parameter in addition
16619 to the attributes we now generate to indicate the "declared type" and the
16620 "active location" for each parameter. This additional set of attributes
16621 could be used by debuggers for stack backtraces. Separately, note that
16622 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16623 This happens (for example) for inlined-instances of inline function formal
16624 parameters which are never referenced. This really shouldn't be
16625 happening. All PARM_DECL nodes should get valid non-NULL
16626 DECL_INCOMING_RTL values. FIXME. */
16628 /* Use DECL_RTL as the "location" unless we find something better. */
16629 rtl = DECL_RTL_IF_SET (decl);
16631 /* When generating abstract instances, ignore everything except
16632 constants, symbols living in memory, and symbols living in
16633 fixed registers. */
16634 if (! reload_completed)
16637 && (CONSTANT_P (rtl)
16639 && CONSTANT_P (XEXP (rtl, 0)))
16641 && TREE_CODE (decl) == VAR_DECL
16642 && TREE_STATIC (decl))))
16644 rtl = targetm.delegitimize_address (rtl);
16649 else if (TREE_CODE (decl) == PARM_DECL)
16651 if (rtl == NULL_RTX
16652 || is_pseudo_reg (rtl)
16654 && is_pseudo_reg (XEXP (rtl, 0))
16655 && DECL_INCOMING_RTL (decl)
16656 && MEM_P (DECL_INCOMING_RTL (decl))
16657 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
16659 tree declared_type = TREE_TYPE (decl);
16660 tree passed_type = DECL_ARG_TYPE (decl);
16661 enum machine_mode dmode = TYPE_MODE (declared_type);
16662 enum machine_mode pmode = TYPE_MODE (passed_type);
16664 /* This decl represents a formal parameter which was optimized out.
16665 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16666 all cases where (rtl == NULL_RTX) just below. */
16667 if (dmode == pmode)
16668 rtl = DECL_INCOMING_RTL (decl);
16669 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
16670 && SCALAR_INT_MODE_P (dmode)
16671 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16672 && DECL_INCOMING_RTL (decl))
16674 rtx inc = DECL_INCOMING_RTL (decl);
16677 else if (MEM_P (inc))
16679 if (BYTES_BIG_ENDIAN)
16680 rtl = adjust_address_nv (inc, dmode,
16681 GET_MODE_SIZE (pmode)
16682 - GET_MODE_SIZE (dmode));
16689 /* If the parm was passed in registers, but lives on the stack, then
16690 make a big endian correction if the mode of the type of the
16691 parameter is not the same as the mode of the rtl. */
16692 /* ??? This is the same series of checks that are made in dbxout.c before
16693 we reach the big endian correction code there. It isn't clear if all
16694 of these checks are necessary here, but keeping them all is the safe
16696 else if (MEM_P (rtl)
16697 && XEXP (rtl, 0) != const0_rtx
16698 && ! CONSTANT_P (XEXP (rtl, 0))
16699 /* Not passed in memory. */
16700 && !MEM_P (DECL_INCOMING_RTL (decl))
16701 /* Not passed by invisible reference. */
16702 && (!REG_P (XEXP (rtl, 0))
16703 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16704 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16705 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16706 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16709 /* Big endian correction check. */
16710 && BYTES_BIG_ENDIAN
16711 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16712 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16715 int offset = (UNITS_PER_WORD
16716 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16718 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16719 plus_constant (XEXP (rtl, 0), offset));
16722 else if (TREE_CODE (decl) == VAR_DECL
16725 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16726 && BYTES_BIG_ENDIAN)
16728 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16729 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16731 /* If a variable is declared "register" yet is smaller than
16732 a register, then if we store the variable to memory, it
16733 looks like we're storing a register-sized value, when in
16734 fact we are not. We need to adjust the offset of the
16735 storage location to reflect the actual value's bytes,
16736 else gdb will not be able to display it. */
16738 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16739 plus_constant (XEXP (rtl, 0), rsize-dsize));
16742 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16743 and will have been substituted directly into all expressions that use it.
16744 C does not have such a concept, but C++ and other languages do. */
16745 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16746 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16749 rtl = targetm.delegitimize_address (rtl);
16751 /* If we don't look past the constant pool, we risk emitting a
16752 reference to a constant pool entry that isn't referenced from
16753 code, and thus is not emitted. */
16755 rtl = avoid_constant_pool_reference (rtl);
16757 /* Try harder to get a rtl. If this symbol ends up not being emitted
16758 in the current CU, resolve_addr will remove the expression referencing
16760 if (rtl == NULL_RTX
16761 && TREE_CODE (decl) == VAR_DECL
16762 && !DECL_EXTERNAL (decl)
16763 && TREE_STATIC (decl)
16764 && DECL_NAME (decl)
16765 && !DECL_HARD_REGISTER (decl)
16766 && DECL_MODE (decl) != VOIDmode)
16768 rtl = make_decl_rtl_for_debug (decl);
16770 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16771 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16778 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16779 returned. If so, the decl for the COMMON block is returned, and the
16780 value is the offset into the common block for the symbol. */
16783 fortran_common (tree decl, HOST_WIDE_INT *value)
16785 tree val_expr, cvar;
16786 enum machine_mode mode;
16787 HOST_WIDE_INT bitsize, bitpos;
16789 int volatilep = 0, unsignedp = 0;
16791 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16792 it does not have a value (the offset into the common area), or if it
16793 is thread local (as opposed to global) then it isn't common, and shouldn't
16794 be handled as such. */
16795 if (TREE_CODE (decl) != VAR_DECL
16796 || !TREE_STATIC (decl)
16797 || !DECL_HAS_VALUE_EXPR_P (decl)
16801 val_expr = DECL_VALUE_EXPR (decl);
16802 if (TREE_CODE (val_expr) != COMPONENT_REF)
16805 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16806 &mode, &unsignedp, &volatilep, true);
16808 if (cvar == NULL_TREE
16809 || TREE_CODE (cvar) != VAR_DECL
16810 || DECL_ARTIFICIAL (cvar)
16811 || !TREE_PUBLIC (cvar))
16815 if (offset != NULL)
16817 if (!host_integerp (offset, 0))
16819 *value = tree_low_cst (offset, 0);
16822 *value += bitpos / BITS_PER_UNIT;
16827 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16828 data attribute for a variable or a parameter. We generate the
16829 DW_AT_const_value attribute only in those cases where the given variable
16830 or parameter does not have a true "location" either in memory or in a
16831 register. This can happen (for example) when a constant is passed as an
16832 actual argument in a call to an inline function. (It's possible that
16833 these things can crop up in other ways also.) Note that one type of
16834 constant value which can be passed into an inlined function is a constant
16835 pointer. This can happen for example if an actual argument in an inlined
16836 function call evaluates to a compile-time constant address.
16838 CACHE_P is true if it is worth caching the location list for DECL,
16839 so that future calls can reuse it rather than regenerate it from scratch.
16840 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16841 since we will need to refer to them each time the function is inlined. */
16844 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
16845 enum dwarf_attribute attr)
16848 dw_loc_list_ref list;
16849 var_loc_list *loc_list;
16850 cached_dw_loc_list *cache;
16853 if (TREE_CODE (decl) == ERROR_MARK)
16856 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16857 || TREE_CODE (decl) == RESULT_DECL);
16859 /* Try to get some constant RTL for this decl, and use that as the value of
16862 rtl = rtl_for_decl_location (decl);
16863 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16864 && add_const_value_attribute (die, rtl))
16867 /* See if we have single element location list that is equivalent to
16868 a constant value. That way we are better to use add_const_value_attribute
16869 rather than expanding constant value equivalent. */
16870 loc_list = lookup_decl_loc (decl);
16873 && loc_list->first->next == NULL
16874 && NOTE_P (loc_list->first->loc)
16875 && NOTE_VAR_LOCATION (loc_list->first->loc)
16876 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16878 struct var_loc_node *node;
16880 node = loc_list->first;
16881 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16882 if (GET_CODE (rtl) == EXPR_LIST)
16883 rtl = XEXP (rtl, 0);
16884 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16885 && add_const_value_attribute (die, rtl))
16888 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16889 list several times. See if we've already cached the contents. */
16891 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
16895 cache = (cached_dw_loc_list *)
16896 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
16898 list = cache->loc_list;
16902 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16903 /* It is usually worth caching this result if the decl is from
16904 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16905 if (cache_p && list && list->dw_loc_next)
16907 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
16908 DECL_UID (decl), INSERT);
16909 cache = ggc_alloc_cleared_cached_dw_loc_list ();
16910 cache->decl_id = DECL_UID (decl);
16911 cache->loc_list = list;
16917 add_AT_location_description (die, attr, list);
16920 /* None of that worked, so it must not really have a location;
16921 try adding a constant value attribute from the DECL_INITIAL. */
16922 return tree_add_const_value_attribute_for_decl (die, decl);
16925 /* Add VARIABLE and DIE into deferred locations list. */
16928 defer_location (tree variable, dw_die_ref die)
16930 deferred_locations entry;
16931 entry.variable = variable;
16933 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16936 /* Helper function for tree_add_const_value_attribute. Natively encode
16937 initializer INIT into an array. Return true if successful. */
16940 native_encode_initializer (tree init, unsigned char *array, int size)
16944 if (init == NULL_TREE)
16948 switch (TREE_CODE (init))
16951 type = TREE_TYPE (init);
16952 if (TREE_CODE (type) == ARRAY_TYPE)
16954 tree enttype = TREE_TYPE (type);
16955 enum machine_mode mode = TYPE_MODE (enttype);
16957 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16959 if (int_size_in_bytes (type) != size)
16961 if (size > TREE_STRING_LENGTH (init))
16963 memcpy (array, TREE_STRING_POINTER (init),
16964 TREE_STRING_LENGTH (init));
16965 memset (array + TREE_STRING_LENGTH (init),
16966 '\0', size - TREE_STRING_LENGTH (init));
16969 memcpy (array, TREE_STRING_POINTER (init), size);
16974 type = TREE_TYPE (init);
16975 if (int_size_in_bytes (type) != size)
16977 if (TREE_CODE (type) == ARRAY_TYPE)
16979 HOST_WIDE_INT min_index;
16980 unsigned HOST_WIDE_INT cnt;
16981 int curpos = 0, fieldsize;
16982 constructor_elt *ce;
16984 if (TYPE_DOMAIN (type) == NULL_TREE
16985 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
16988 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16989 if (fieldsize <= 0)
16992 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
16993 memset (array, '\0', size);
16994 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
16996 tree val = ce->value;
16997 tree index = ce->index;
16999 if (index && TREE_CODE (index) == RANGE_EXPR)
17000 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17003 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17008 if (!native_encode_initializer (val, array + pos, fieldsize))
17011 curpos = pos + fieldsize;
17012 if (index && TREE_CODE (index) == RANGE_EXPR)
17014 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17015 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17019 memcpy (array + curpos, array + pos, fieldsize);
17020 curpos += fieldsize;
17023 gcc_assert (curpos <= size);
17027 else if (TREE_CODE (type) == RECORD_TYPE
17028 || TREE_CODE (type) == UNION_TYPE)
17030 tree field = NULL_TREE;
17031 unsigned HOST_WIDE_INT cnt;
17032 constructor_elt *ce;
17034 if (int_size_in_bytes (type) != size)
17037 if (TREE_CODE (type) == RECORD_TYPE)
17038 field = TYPE_FIELDS (type);
17040 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17042 tree val = ce->value;
17043 int pos, fieldsize;
17045 if (ce->index != 0)
17051 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17054 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17055 && TYPE_DOMAIN (TREE_TYPE (field))
17056 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17058 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17059 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17061 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17062 pos = int_byte_position (field);
17063 gcc_assert (pos + fieldsize <= size);
17065 && !native_encode_initializer (val, array + pos, fieldsize))
17071 case VIEW_CONVERT_EXPR:
17072 case NON_LVALUE_EXPR:
17073 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17075 return native_encode_expr (init, array, size) == size;
17079 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17080 attribute is the const value T. */
17083 tree_add_const_value_attribute (dw_die_ref die, tree t)
17086 tree type = TREE_TYPE (t);
17089 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17093 gcc_assert (!DECL_P (init));
17095 rtl = rtl_for_decl_init (init, type);
17097 return add_const_value_attribute (die, rtl);
17098 /* If the host and target are sane, try harder. */
17099 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17100 && initializer_constant_valid_p (init, type))
17102 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17103 if (size > 0 && (int) size == size)
17105 unsigned char *array = (unsigned char *)
17106 ggc_alloc_cleared_atomic (size);
17108 if (native_encode_initializer (init, array, size))
17110 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17118 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17119 attribute is the const value of T, where T is an integral constant
17120 variable with static storage duration
17121 (so it can't be a PARM_DECL or a RESULT_DECL). */
17124 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17128 || (TREE_CODE (decl) != VAR_DECL
17129 && TREE_CODE (decl) != CONST_DECL))
17132 if (TREE_READONLY (decl)
17133 && ! TREE_THIS_VOLATILE (decl)
17134 && DECL_INITIAL (decl))
17139 /* Don't add DW_AT_const_value if abstract origin already has one. */
17140 if (get_AT (var_die, DW_AT_const_value))
17143 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17146 /* Convert the CFI instructions for the current function into a
17147 location list. This is used for DW_AT_frame_base when we targeting
17148 a dwarf2 consumer that does not support the dwarf3
17149 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17152 static dw_loc_list_ref
17153 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17156 dw_loc_list_ref list, *list_tail;
17158 dw_cfa_location last_cfa, next_cfa;
17159 const char *start_label, *last_label, *section;
17160 dw_cfa_location remember;
17162 fde = current_fde ();
17163 gcc_assert (fde != NULL);
17165 section = secname_for_decl (current_function_decl);
17169 memset (&next_cfa, 0, sizeof (next_cfa));
17170 next_cfa.reg = INVALID_REGNUM;
17171 remember = next_cfa;
17173 start_label = fde->dw_fde_begin;
17175 /* ??? Bald assumption that the CIE opcode list does not contain
17176 advance opcodes. */
17177 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17178 lookup_cfa_1 (cfi, &next_cfa, &remember);
17180 last_cfa = next_cfa;
17181 last_label = start_label;
17183 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi == NULL)
17185 /* If the first partition contained no CFI adjustments, the
17186 CIE opcodes apply to the whole first partition. */
17187 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17188 fde->dw_fde_begin, fde->dw_fde_end, section);
17189 list_tail =&(*list_tail)->dw_loc_next;
17190 start_label = last_label = fde->dw_fde_second_begin;
17193 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17195 switch (cfi->dw_cfi_opc)
17197 case DW_CFA_set_loc:
17198 case DW_CFA_advance_loc1:
17199 case DW_CFA_advance_loc2:
17200 case DW_CFA_advance_loc4:
17201 if (!cfa_equal_p (&last_cfa, &next_cfa))
17203 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17204 start_label, last_label, section);
17206 list_tail = &(*list_tail)->dw_loc_next;
17207 last_cfa = next_cfa;
17208 start_label = last_label;
17210 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17213 case DW_CFA_advance_loc:
17214 /* The encoding is complex enough that we should never emit this. */
17215 gcc_unreachable ();
17218 lookup_cfa_1 (cfi, &next_cfa, &remember);
17221 if (cfi == fde->dw_fde_switch_cfi)
17223 if (!cfa_equal_p (&last_cfa, &next_cfa))
17225 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17226 start_label, last_label, section);
17228 list_tail = &(*list_tail)->dw_loc_next;
17229 last_cfa = next_cfa;
17230 start_label = last_label;
17232 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17233 start_label, fde->dw_fde_end, section);
17234 list_tail = &(*list_tail)->dw_loc_next;
17235 start_label = last_label = fde->dw_fde_second_begin;
17239 if (!cfa_equal_p (&last_cfa, &next_cfa))
17241 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17242 start_label, last_label, section);
17243 list_tail = &(*list_tail)->dw_loc_next;
17244 start_label = last_label;
17247 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17249 fde->dw_fde_second_begin
17250 ? fde->dw_fde_second_end : fde->dw_fde_end,
17253 if (list && list->dw_loc_next)
17259 /* Compute a displacement from the "steady-state frame pointer" to the
17260 frame base (often the same as the CFA), and store it in
17261 frame_pointer_fb_offset. OFFSET is added to the displacement
17262 before the latter is negated. */
17265 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17269 #ifdef FRAME_POINTER_CFA_OFFSET
17270 reg = frame_pointer_rtx;
17271 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17273 reg = arg_pointer_rtx;
17274 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17277 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17278 if (GET_CODE (elim) == PLUS)
17280 offset += INTVAL (XEXP (elim, 1));
17281 elim = XEXP (elim, 0);
17284 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17285 && (elim == hard_frame_pointer_rtx
17286 || elim == stack_pointer_rtx))
17287 || elim == (frame_pointer_needed
17288 ? hard_frame_pointer_rtx
17289 : stack_pointer_rtx));
17291 frame_pointer_fb_offset = -offset;
17294 /* Generate a DW_AT_name attribute given some string value to be included as
17295 the value of the attribute. */
17298 add_name_attribute (dw_die_ref die, const char *name_string)
17300 if (name_string != NULL && *name_string != 0)
17302 if (demangle_name_func)
17303 name_string = (*demangle_name_func) (name_string);
17305 add_AT_string (die, DW_AT_name, name_string);
17309 /* Generate a DW_AT_comp_dir attribute for DIE. */
17312 add_comp_dir_attribute (dw_die_ref die)
17314 const char *wd = get_src_pwd ();
17320 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17324 wdlen = strlen (wd);
17325 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17327 wd1 [wdlen] = DIR_SEPARATOR;
17328 wd1 [wdlen + 1] = 0;
17332 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17335 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17339 lower_bound_default (void)
17341 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17346 case DW_LANG_C_plus_plus:
17348 case DW_LANG_ObjC_plus_plus:
17351 case DW_LANG_Fortran77:
17352 case DW_LANG_Fortran90:
17353 case DW_LANG_Fortran95:
17357 case DW_LANG_Python:
17358 return dwarf_version >= 4 ? 0 : -1;
17359 case DW_LANG_Ada95:
17360 case DW_LANG_Ada83:
17361 case DW_LANG_Cobol74:
17362 case DW_LANG_Cobol85:
17363 case DW_LANG_Pascal83:
17364 case DW_LANG_Modula2:
17366 return dwarf_version >= 4 ? 1 : -1;
17372 /* Given a tree node describing an array bound (either lower or upper) output
17373 a representation for that bound. */
17376 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17378 switch (TREE_CODE (bound))
17383 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17386 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17389 /* Use the default if possible. */
17390 if (bound_attr == DW_AT_lower_bound
17391 && host_integerp (bound, 0)
17392 && (dflt = lower_bound_default ()) != -1
17393 && tree_low_cst (bound, 0) == dflt)
17396 /* Otherwise represent the bound as an unsigned value with the
17397 precision of its type. The precision and signedness of the
17398 type will be necessary to re-interpret it unambiguously. */
17399 else if (prec < HOST_BITS_PER_WIDE_INT)
17401 unsigned HOST_WIDE_INT mask
17402 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17403 add_AT_unsigned (subrange_die, bound_attr,
17404 TREE_INT_CST_LOW (bound) & mask);
17406 else if (prec == HOST_BITS_PER_WIDE_INT
17407 || TREE_INT_CST_HIGH (bound) == 0)
17408 add_AT_unsigned (subrange_die, bound_attr,
17409 TREE_INT_CST_LOW (bound));
17411 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17412 TREE_INT_CST_LOW (bound));
17417 case VIEW_CONVERT_EXPR:
17418 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17428 dw_die_ref decl_die = lookup_decl_die (bound);
17430 /* ??? Can this happen, or should the variable have been bound
17431 first? Probably it can, since I imagine that we try to create
17432 the types of parameters in the order in which they exist in
17433 the list, and won't have created a forward reference to a
17434 later parameter. */
17435 if (decl_die != NULL)
17437 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17445 /* Otherwise try to create a stack operation procedure to
17446 evaluate the value of the array bound. */
17448 dw_die_ref ctx, decl_die;
17449 dw_loc_list_ref list;
17451 list = loc_list_from_tree (bound, 2);
17452 if (list == NULL || single_element_loc_list_p (list))
17454 /* If DW_AT_*bound is not a reference nor constant, it is
17455 a DWARF expression rather than location description.
17456 For that loc_list_from_tree (bound, 0) is needed.
17457 If that fails to give a single element list,
17458 fall back to outputting this as a reference anyway. */
17459 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17460 if (list2 && single_element_loc_list_p (list2))
17462 add_AT_loc (subrange_die, bound_attr, list2->expr);
17469 if (current_function_decl == 0)
17470 ctx = comp_unit_die ();
17472 ctx = lookup_decl_die (current_function_decl);
17474 decl_die = new_die (DW_TAG_variable, ctx, bound);
17475 add_AT_flag (decl_die, DW_AT_artificial, 1);
17476 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17477 add_AT_location_description (decl_die, DW_AT_location, list);
17478 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17484 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17485 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17486 Note that the block of subscript information for an array type also
17487 includes information about the element type of the given array type. */
17490 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17492 unsigned dimension_number;
17494 dw_die_ref subrange_die;
17496 for (dimension_number = 0;
17497 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17498 type = TREE_TYPE (type), dimension_number++)
17500 tree domain = TYPE_DOMAIN (type);
17502 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17505 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17506 and (in GNU C only) variable bounds. Handle all three forms
17508 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17511 /* We have an array type with specified bounds. */
17512 lower = TYPE_MIN_VALUE (domain);
17513 upper = TYPE_MAX_VALUE (domain);
17515 /* Define the index type. */
17516 if (TREE_TYPE (domain))
17518 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17519 TREE_TYPE field. We can't emit debug info for this
17520 because it is an unnamed integral type. */
17521 if (TREE_CODE (domain) == INTEGER_TYPE
17522 && TYPE_NAME (domain) == NULL_TREE
17523 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17524 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17527 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17531 /* ??? If upper is NULL, the array has unspecified length,
17532 but it does have a lower bound. This happens with Fortran
17534 Since the debugger is definitely going to need to know N
17535 to produce useful results, go ahead and output the lower
17536 bound solo, and hope the debugger can cope. */
17538 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17540 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17543 /* Otherwise we have an array type with an unspecified length. The
17544 DWARF-2 spec does not say how to handle this; let's just leave out the
17550 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17554 switch (TREE_CODE (tree_node))
17559 case ENUMERAL_TYPE:
17562 case QUAL_UNION_TYPE:
17563 size = int_size_in_bytes (tree_node);
17566 /* For a data member of a struct or union, the DW_AT_byte_size is
17567 generally given as the number of bytes normally allocated for an
17568 object of the *declared* type of the member itself. This is true
17569 even for bit-fields. */
17570 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17573 gcc_unreachable ();
17576 /* Note that `size' might be -1 when we get to this point. If it is, that
17577 indicates that the byte size of the entity in question is variable. We
17578 have no good way of expressing this fact in Dwarf at the present time,
17579 so just let the -1 pass on through. */
17580 add_AT_unsigned (die, DW_AT_byte_size, size);
17583 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17584 which specifies the distance in bits from the highest order bit of the
17585 "containing object" for the bit-field to the highest order bit of the
17588 For any given bit-field, the "containing object" is a hypothetical object
17589 (of some integral or enum type) within which the given bit-field lives. The
17590 type of this hypothetical "containing object" is always the same as the
17591 declared type of the individual bit-field itself. The determination of the
17592 exact location of the "containing object" for a bit-field is rather
17593 complicated. It's handled by the `field_byte_offset' function (above).
17595 Note that it is the size (in bytes) of the hypothetical "containing object"
17596 which will be given in the DW_AT_byte_size attribute for this bit-field.
17597 (See `byte_size_attribute' above). */
17600 add_bit_offset_attribute (dw_die_ref die, tree decl)
17602 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17603 tree type = DECL_BIT_FIELD_TYPE (decl);
17604 HOST_WIDE_INT bitpos_int;
17605 HOST_WIDE_INT highest_order_object_bit_offset;
17606 HOST_WIDE_INT highest_order_field_bit_offset;
17607 HOST_WIDE_INT bit_offset;
17609 /* Must be a field and a bit field. */
17610 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17612 /* We can't yet handle bit-fields whose offsets are variable, so if we
17613 encounter such things, just return without generating any attribute
17614 whatsoever. Likewise for variable or too large size. */
17615 if (! host_integerp (bit_position (decl), 0)
17616 || ! host_integerp (DECL_SIZE (decl), 1))
17619 bitpos_int = int_bit_position (decl);
17621 /* Note that the bit offset is always the distance (in bits) from the
17622 highest-order bit of the "containing object" to the highest-order bit of
17623 the bit-field itself. Since the "high-order end" of any object or field
17624 is different on big-endian and little-endian machines, the computation
17625 below must take account of these differences. */
17626 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17627 highest_order_field_bit_offset = bitpos_int;
17629 if (! BYTES_BIG_ENDIAN)
17631 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17632 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17636 = (! BYTES_BIG_ENDIAN
17637 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17638 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17640 if (bit_offset < 0)
17641 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17643 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17646 /* For a FIELD_DECL node which represents a bit field, output an attribute
17647 which specifies the length in bits of the given field. */
17650 add_bit_size_attribute (dw_die_ref die, tree decl)
17652 /* Must be a field and a bit field. */
17653 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17654 && DECL_BIT_FIELD_TYPE (decl));
17656 if (host_integerp (DECL_SIZE (decl), 1))
17657 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17660 /* If the compiled language is ANSI C, then add a 'prototyped'
17661 attribute, if arg types are given for the parameters of a function. */
17664 add_prototyped_attribute (dw_die_ref die, tree func_type)
17666 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17667 && prototype_p (func_type))
17668 add_AT_flag (die, DW_AT_prototyped, 1);
17671 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17672 by looking in either the type declaration or object declaration
17675 static inline dw_die_ref
17676 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17678 dw_die_ref origin_die = NULL;
17680 if (TREE_CODE (origin) != FUNCTION_DECL)
17682 /* We may have gotten separated from the block for the inlined
17683 function, if we're in an exception handler or some such; make
17684 sure that the abstract function has been written out.
17686 Doing this for nested functions is wrong, however; functions are
17687 distinct units, and our context might not even be inline. */
17691 fn = TYPE_STUB_DECL (fn);
17693 fn = decl_function_context (fn);
17695 dwarf2out_abstract_function (fn);
17698 if (DECL_P (origin))
17699 origin_die = lookup_decl_die (origin);
17700 else if (TYPE_P (origin))
17701 origin_die = lookup_type_die (origin);
17703 /* XXX: Functions that are never lowered don't always have correct block
17704 trees (in the case of java, they simply have no block tree, in some other
17705 languages). For these functions, there is nothing we can really do to
17706 output correct debug info for inlined functions in all cases. Rather
17707 than die, we'll just produce deficient debug info now, in that we will
17708 have variables without a proper abstract origin. In the future, when all
17709 functions are lowered, we should re-add a gcc_assert (origin_die)
17713 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17717 /* We do not currently support the pure_virtual attribute. */
17720 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17722 if (DECL_VINDEX (func_decl))
17724 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17726 if (host_integerp (DECL_VINDEX (func_decl), 0))
17727 add_AT_loc (die, DW_AT_vtable_elem_location,
17728 new_loc_descr (DW_OP_constu,
17729 tree_low_cst (DECL_VINDEX (func_decl), 0),
17732 /* GNU extension: Record what type this method came from originally. */
17733 if (debug_info_level > DINFO_LEVEL_TERSE
17734 && DECL_CONTEXT (func_decl))
17735 add_AT_die_ref (die, DW_AT_containing_type,
17736 lookup_type_die (DECL_CONTEXT (func_decl)));
17740 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17741 given decl. This used to be a vendor extension until after DWARF 4
17742 standardized it. */
17745 add_linkage_attr (dw_die_ref die, tree decl)
17747 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17749 /* Mimic what assemble_name_raw does with a leading '*'. */
17750 if (name[0] == '*')
17753 if (dwarf_version >= 4)
17754 add_AT_string (die, DW_AT_linkage_name, name);
17756 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17759 /* Add source coordinate attributes for the given decl. */
17762 add_src_coords_attributes (dw_die_ref die, tree decl)
17764 expanded_location s;
17766 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
17768 s = expand_location (DECL_SOURCE_LOCATION (decl));
17769 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17770 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17773 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17776 add_linkage_name (dw_die_ref die, tree decl)
17778 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17779 && TREE_PUBLIC (decl)
17780 && !DECL_ABSTRACT (decl)
17781 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17782 && die->die_tag != DW_TAG_member)
17784 /* Defer until we have an assembler name set. */
17785 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17787 limbo_die_node *asm_name;
17789 asm_name = ggc_alloc_cleared_limbo_die_node ();
17790 asm_name->die = die;
17791 asm_name->created_for = decl;
17792 asm_name->next = deferred_asm_name;
17793 deferred_asm_name = asm_name;
17795 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17796 add_linkage_attr (die, decl);
17800 /* Add a DW_AT_name attribute and source coordinate attribute for the
17801 given decl, but only if it actually has a name. */
17804 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17808 decl_name = DECL_NAME (decl);
17809 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17811 const char *name = dwarf2_name (decl, 0);
17813 add_name_attribute (die, name);
17814 if (! DECL_ARTIFICIAL (decl))
17815 add_src_coords_attributes (die, decl);
17817 add_linkage_name (die, decl);
17820 #ifdef VMS_DEBUGGING_INFO
17821 /* Get the function's name, as described by its RTL. This may be different
17822 from the DECL_NAME name used in the source file. */
17823 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17825 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17826 XEXP (DECL_RTL (decl), 0));
17827 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17829 #endif /* VMS_DEBUGGING_INFO */
17832 #ifdef VMS_DEBUGGING_INFO
17833 /* Output the debug main pointer die for VMS */
17836 dwarf2out_vms_debug_main_pointer (void)
17838 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17841 /* Allocate the VMS debug main subprogram die. */
17842 die = ggc_alloc_cleared_die_node ();
17843 die->die_tag = DW_TAG_subprogram;
17844 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17845 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17846 current_function_funcdef_no);
17847 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17849 /* Make it the first child of comp_unit_die (). */
17850 die->die_parent = comp_unit_die ();
17851 if (comp_unit_die ()->die_child)
17853 die->die_sib = comp_unit_die ()->die_child->die_sib;
17854 comp_unit_die ()->die_child->die_sib = die;
17858 die->die_sib = die;
17859 comp_unit_die ()->die_child = die;
17862 #endif /* VMS_DEBUGGING_INFO */
17864 /* Push a new declaration scope. */
17867 push_decl_scope (tree scope)
17869 VEC_safe_push (tree, gc, decl_scope_table, scope);
17872 /* Pop a declaration scope. */
17875 pop_decl_scope (void)
17877 VEC_pop (tree, decl_scope_table);
17880 /* Return the DIE for the scope that immediately contains this type.
17881 Non-named types get global scope. Named types nested in other
17882 types get their containing scope if it's open, or global scope
17883 otherwise. All other types (i.e. function-local named types) get
17884 the current active scope. */
17887 scope_die_for (tree t, dw_die_ref context_die)
17889 dw_die_ref scope_die = NULL;
17890 tree containing_scope;
17893 /* Non-types always go in the current scope. */
17894 gcc_assert (TYPE_P (t));
17896 containing_scope = TYPE_CONTEXT (t);
17898 /* Use the containing namespace if it was passed in (for a declaration). */
17899 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17901 if (context_die == lookup_decl_die (containing_scope))
17904 containing_scope = NULL_TREE;
17907 /* Ignore function type "scopes" from the C frontend. They mean that
17908 a tagged type is local to a parmlist of a function declarator, but
17909 that isn't useful to DWARF. */
17910 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17911 containing_scope = NULL_TREE;
17913 if (SCOPE_FILE_SCOPE_P (containing_scope))
17914 scope_die = comp_unit_die ();
17915 else if (TYPE_P (containing_scope))
17917 /* For types, we can just look up the appropriate DIE. But
17918 first we check to see if we're in the middle of emitting it
17919 so we know where the new DIE should go. */
17920 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17921 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17926 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17927 || TREE_ASM_WRITTEN (containing_scope));
17928 /*We are not in the middle of emitting the type
17929 CONTAINING_SCOPE. Let's see if it's emitted already. */
17930 scope_die = lookup_type_die (containing_scope);
17932 /* If none of the current dies are suitable, we get file scope. */
17933 if (scope_die == NULL)
17934 scope_die = comp_unit_die ();
17937 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17940 scope_die = context_die;
17945 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17948 local_scope_p (dw_die_ref context_die)
17950 for (; context_die; context_die = context_die->die_parent)
17951 if (context_die->die_tag == DW_TAG_inlined_subroutine
17952 || context_die->die_tag == DW_TAG_subprogram)
17958 /* Returns nonzero if CONTEXT_DIE is a class. */
17961 class_scope_p (dw_die_ref context_die)
17963 return (context_die
17964 && (context_die->die_tag == DW_TAG_structure_type
17965 || context_die->die_tag == DW_TAG_class_type
17966 || context_die->die_tag == DW_TAG_interface_type
17967 || context_die->die_tag == DW_TAG_union_type));
17970 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17971 whether or not to treat a DIE in this context as a declaration. */
17974 class_or_namespace_scope_p (dw_die_ref context_die)
17976 return (class_scope_p (context_die)
17977 || (context_die && context_die->die_tag == DW_TAG_namespace));
17980 /* Many forms of DIEs require a "type description" attribute. This
17981 routine locates the proper "type descriptor" die for the type given
17982 by 'type', and adds a DW_AT_type attribute below the given die. */
17985 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17986 int decl_volatile, dw_die_ref context_die)
17988 enum tree_code code = TREE_CODE (type);
17989 dw_die_ref type_die = NULL;
17991 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17992 or fixed-point type, use the inner type. This is because we have no
17993 support for unnamed types in base_type_die. This can happen if this is
17994 an Ada subrange type. Correct solution is emit a subrange type die. */
17995 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17996 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17997 type = TREE_TYPE (type), code = TREE_CODE (type);
17999 if (code == ERROR_MARK
18000 /* Handle a special case. For functions whose return type is void, we
18001 generate *no* type attribute. (Note that no object may have type
18002 `void', so this only applies to function return types). */
18003 || code == VOID_TYPE)
18006 type_die = modified_type_die (type,
18007 decl_const || TYPE_READONLY (type),
18008 decl_volatile || TYPE_VOLATILE (type),
18011 if (type_die != NULL)
18012 add_AT_die_ref (object_die, DW_AT_type, type_die);
18015 /* Given an object die, add the calling convention attribute for the
18016 function call type. */
18018 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18020 enum dwarf_calling_convention value = DW_CC_normal;
18022 value = ((enum dwarf_calling_convention)
18023 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18026 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18028 /* DWARF 2 doesn't provide a way to identify a program's source-level
18029 entry point. DW_AT_calling_convention attributes are only meant
18030 to describe functions' calling conventions. However, lacking a
18031 better way to signal the Fortran main program, we used this for
18032 a long time, following existing custom. Now, DWARF 4 has
18033 DW_AT_main_subprogram, which we add below, but some tools still
18034 rely on the old way, which we thus keep. */
18035 value = DW_CC_program;
18037 if (dwarf_version >= 4 || !dwarf_strict)
18038 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18041 /* Only add the attribute if the backend requests it, and
18042 is not DW_CC_normal. */
18043 if (value && (value != DW_CC_normal))
18044 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18047 /* Given a tree pointer to a struct, class, union, or enum type node, return
18048 a pointer to the (string) tag name for the given type, or zero if the type
18049 was declared without a tag. */
18051 static const char *
18052 type_tag (const_tree type)
18054 const char *name = 0;
18056 if (TYPE_NAME (type) != 0)
18060 /* Find the IDENTIFIER_NODE for the type name. */
18061 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18062 && !TYPE_NAMELESS (type))
18063 t = TYPE_NAME (type);
18065 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18066 a TYPE_DECL node, regardless of whether or not a `typedef' was
18068 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18069 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18071 /* We want to be extra verbose. Don't call dwarf_name if
18072 DECL_NAME isn't set. The default hook for decl_printable_name
18073 doesn't like that, and in this context it's correct to return
18074 0, instead of "<anonymous>" or the like. */
18075 if (DECL_NAME (TYPE_NAME (type))
18076 && !DECL_NAMELESS (TYPE_NAME (type)))
18077 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18080 /* Now get the name as a string, or invent one. */
18081 if (!name && t != 0)
18082 name = IDENTIFIER_POINTER (t);
18085 return (name == 0 || *name == '\0') ? 0 : name;
18088 /* Return the type associated with a data member, make a special check
18089 for bit field types. */
18092 member_declared_type (const_tree member)
18094 return (DECL_BIT_FIELD_TYPE (member)
18095 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18098 /* Get the decl's label, as described by its RTL. This may be different
18099 from the DECL_NAME name used in the source file. */
18102 static const char *
18103 decl_start_label (tree decl)
18106 const char *fnname;
18108 x = DECL_RTL (decl);
18109 gcc_assert (MEM_P (x));
18112 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18114 fnname = XSTR (x, 0);
18119 /* These routines generate the internal representation of the DIE's for
18120 the compilation unit. Debugging information is collected by walking
18121 the declaration trees passed in from dwarf2out_decl(). */
18124 gen_array_type_die (tree type, dw_die_ref context_die)
18126 dw_die_ref scope_die = scope_die_for (type, context_die);
18127 dw_die_ref array_die;
18129 /* GNU compilers represent multidimensional array types as sequences of one
18130 dimensional array types whose element types are themselves array types.
18131 We sometimes squish that down to a single array_type DIE with multiple
18132 subscripts in the Dwarf debugging info. The draft Dwarf specification
18133 say that we are allowed to do this kind of compression in C, because
18134 there is no difference between an array of arrays and a multidimensional
18135 array. We don't do this for Ada to remain as close as possible to the
18136 actual representation, which is especially important against the language
18137 flexibilty wrt arrays of variable size. */
18139 bool collapse_nested_arrays = !is_ada ();
18142 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18143 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18144 if (TYPE_STRING_FLAG (type)
18145 && TREE_CODE (type) == ARRAY_TYPE
18147 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18149 HOST_WIDE_INT size;
18151 array_die = new_die (DW_TAG_string_type, scope_die, type);
18152 add_name_attribute (array_die, type_tag (type));
18153 equate_type_number_to_die (type, array_die);
18154 size = int_size_in_bytes (type);
18156 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18157 else if (TYPE_DOMAIN (type) != NULL_TREE
18158 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18159 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18161 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18162 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18164 size = int_size_in_bytes (TREE_TYPE (szdecl));
18165 if (loc && size > 0)
18167 add_AT_location_description (array_die, DW_AT_string_length, loc);
18168 if (size != DWARF2_ADDR_SIZE)
18169 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18175 /* ??? The SGI dwarf reader fails for array of array of enum types
18176 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18177 array type comes before the outer array type. We thus call gen_type_die
18178 before we new_die and must prevent nested array types collapsing for this
18181 #ifdef MIPS_DEBUGGING_INFO
18182 gen_type_die (TREE_TYPE (type), context_die);
18183 collapse_nested_arrays = false;
18186 array_die = new_die (DW_TAG_array_type, scope_die, type);
18187 add_name_attribute (array_die, type_tag (type));
18188 equate_type_number_to_die (type, array_die);
18190 if (TREE_CODE (type) == VECTOR_TYPE)
18191 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18193 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18195 && TREE_CODE (type) == ARRAY_TYPE
18196 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18197 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18198 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18201 /* We default the array ordering. SDB will probably do
18202 the right things even if DW_AT_ordering is not present. It's not even
18203 an issue until we start to get into multidimensional arrays anyway. If
18204 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18205 then we'll have to put the DW_AT_ordering attribute back in. (But if
18206 and when we find out that we need to put these in, we will only do so
18207 for multidimensional arrays. */
18208 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18211 #ifdef MIPS_DEBUGGING_INFO
18212 /* The SGI compilers handle arrays of unknown bound by setting
18213 AT_declaration and not emitting any subrange DIEs. */
18214 if (TREE_CODE (type) == ARRAY_TYPE
18215 && ! TYPE_DOMAIN (type))
18216 add_AT_flag (array_die, DW_AT_declaration, 1);
18219 if (TREE_CODE (type) == VECTOR_TYPE)
18221 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18222 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18223 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18224 add_bound_info (subrange_die, DW_AT_upper_bound,
18225 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18228 add_subscript_info (array_die, type, collapse_nested_arrays);
18230 /* Add representation of the type of the elements of this array type and
18231 emit the corresponding DIE if we haven't done it already. */
18232 element_type = TREE_TYPE (type);
18233 if (collapse_nested_arrays)
18234 while (TREE_CODE (element_type) == ARRAY_TYPE)
18236 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18238 element_type = TREE_TYPE (element_type);
18241 #ifndef MIPS_DEBUGGING_INFO
18242 gen_type_die (element_type, context_die);
18245 add_type_attribute (array_die, element_type, 0, 0, context_die);
18247 if (get_AT (array_die, DW_AT_name))
18248 add_pubtype (type, array_die);
18251 static dw_loc_descr_ref
18252 descr_info_loc (tree val, tree base_decl)
18254 HOST_WIDE_INT size;
18255 dw_loc_descr_ref loc, loc2;
18256 enum dwarf_location_atom op;
18258 if (val == base_decl)
18259 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18261 switch (TREE_CODE (val))
18264 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18266 return loc_descriptor_from_tree (val, 0);
18268 if (host_integerp (val, 0))
18269 return int_loc_descriptor (tree_low_cst (val, 0));
18272 size = int_size_in_bytes (TREE_TYPE (val));
18275 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18278 if (size == DWARF2_ADDR_SIZE)
18279 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18281 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18283 case POINTER_PLUS_EXPR:
18285 if (host_integerp (TREE_OPERAND (val, 1), 1)
18286 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18289 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18292 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18298 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18301 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18304 add_loc_descr (&loc, loc2);
18305 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18327 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18328 tree val, tree base_decl)
18330 dw_loc_descr_ref loc;
18332 if (host_integerp (val, 0))
18334 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18338 loc = descr_info_loc (val, base_decl);
18342 add_AT_loc (die, attr, loc);
18345 /* This routine generates DIE for array with hidden descriptor, details
18346 are filled into *info by a langhook. */
18349 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18350 dw_die_ref context_die)
18352 dw_die_ref scope_die = scope_die_for (type, context_die);
18353 dw_die_ref array_die;
18356 array_die = new_die (DW_TAG_array_type, scope_die, type);
18357 add_name_attribute (array_die, type_tag (type));
18358 equate_type_number_to_die (type, array_die);
18360 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18362 && info->ndimensions >= 2)
18363 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18365 if (info->data_location)
18366 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18368 if (info->associated)
18369 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18371 if (info->allocated)
18372 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18375 for (dim = 0; dim < info->ndimensions; dim++)
18377 dw_die_ref subrange_die
18378 = new_die (DW_TAG_subrange_type, array_die, NULL);
18380 if (info->dimen[dim].lower_bound)
18382 /* If it is the default value, omit it. */
18385 if (host_integerp (info->dimen[dim].lower_bound, 0)
18386 && (dflt = lower_bound_default ()) != -1
18387 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18390 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18391 info->dimen[dim].lower_bound,
18394 if (info->dimen[dim].upper_bound)
18395 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18396 info->dimen[dim].upper_bound,
18398 if (info->dimen[dim].stride)
18399 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18400 info->dimen[dim].stride,
18404 gen_type_die (info->element_type, context_die);
18405 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18407 if (get_AT (array_die, DW_AT_name))
18408 add_pubtype (type, array_die);
18413 gen_entry_point_die (tree decl, dw_die_ref context_die)
18415 tree origin = decl_ultimate_origin (decl);
18416 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18418 if (origin != NULL)
18419 add_abstract_origin_attribute (decl_die, origin);
18422 add_name_and_src_coords_attributes (decl_die, decl);
18423 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18424 0, 0, context_die);
18427 if (DECL_ABSTRACT (decl))
18428 equate_decl_number_to_die (decl, decl_die);
18430 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18434 /* Walk through the list of incomplete types again, trying once more to
18435 emit full debugging info for them. */
18438 retry_incomplete_types (void)
18442 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18443 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18444 DINFO_USAGE_DIR_USE))
18445 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18448 /* Determine what tag to use for a record type. */
18450 static enum dwarf_tag
18451 record_type_tag (tree type)
18453 if (! lang_hooks.types.classify_record)
18454 return DW_TAG_structure_type;
18456 switch (lang_hooks.types.classify_record (type))
18458 case RECORD_IS_STRUCT:
18459 return DW_TAG_structure_type;
18461 case RECORD_IS_CLASS:
18462 return DW_TAG_class_type;
18464 case RECORD_IS_INTERFACE:
18465 if (dwarf_version >= 3 || !dwarf_strict)
18466 return DW_TAG_interface_type;
18467 return DW_TAG_structure_type;
18470 gcc_unreachable ();
18474 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18475 include all of the information about the enumeration values also. Each
18476 enumerated type name/value is listed as a child of the enumerated type
18480 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18482 dw_die_ref type_die = lookup_type_die (type);
18484 if (type_die == NULL)
18486 type_die = new_die (DW_TAG_enumeration_type,
18487 scope_die_for (type, context_die), type);
18488 equate_type_number_to_die (type, type_die);
18489 add_name_attribute (type_die, type_tag (type));
18490 if (dwarf_version >= 4 || !dwarf_strict)
18492 if (ENUM_IS_SCOPED (type))
18493 add_AT_flag (type_die, DW_AT_enum_class, 1);
18494 if (ENUM_IS_OPAQUE (type))
18495 add_AT_flag (type_die, DW_AT_declaration, 1);
18498 else if (! TYPE_SIZE (type))
18501 remove_AT (type_die, DW_AT_declaration);
18503 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18504 given enum type is incomplete, do not generate the DW_AT_byte_size
18505 attribute or the DW_AT_element_list attribute. */
18506 if (TYPE_SIZE (type))
18510 TREE_ASM_WRITTEN (type) = 1;
18511 add_byte_size_attribute (type_die, type);
18512 if (TYPE_STUB_DECL (type) != NULL_TREE)
18514 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18515 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18518 /* If the first reference to this type was as the return type of an
18519 inline function, then it may not have a parent. Fix this now. */
18520 if (type_die->die_parent == NULL)
18521 add_child_die (scope_die_for (type, context_die), type_die);
18523 for (link = TYPE_VALUES (type);
18524 link != NULL; link = TREE_CHAIN (link))
18526 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18527 tree value = TREE_VALUE (link);
18529 add_name_attribute (enum_die,
18530 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18532 if (TREE_CODE (value) == CONST_DECL)
18533 value = DECL_INITIAL (value);
18535 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18536 /* DWARF2 does not provide a way of indicating whether or
18537 not enumeration constants are signed or unsigned. GDB
18538 always assumes the values are signed, so we output all
18539 values as if they were signed. That means that
18540 enumeration constants with very large unsigned values
18541 will appear to have negative values in the debugger. */
18542 add_AT_int (enum_die, DW_AT_const_value,
18543 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18547 add_AT_flag (type_die, DW_AT_declaration, 1);
18549 if (get_AT (type_die, DW_AT_name))
18550 add_pubtype (type, type_die);
18555 /* Generate a DIE to represent either a real live formal parameter decl or to
18556 represent just the type of some formal parameter position in some function
18559 Note that this routine is a bit unusual because its argument may be a
18560 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18561 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18562 node. If it's the former then this function is being called to output a
18563 DIE to represent a formal parameter object (or some inlining thereof). If
18564 it's the latter, then this function is only being called to output a
18565 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18566 argument type of some subprogram type.
18567 If EMIT_NAME_P is true, name and source coordinate attributes
18571 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18572 dw_die_ref context_die)
18574 tree node_or_origin = node ? node : origin;
18575 tree ultimate_origin;
18576 dw_die_ref parm_die
18577 = new_die (DW_TAG_formal_parameter, context_die, node);
18579 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18581 case tcc_declaration:
18582 ultimate_origin = decl_ultimate_origin (node_or_origin);
18583 if (node || ultimate_origin)
18584 origin = ultimate_origin;
18585 if (origin != NULL)
18586 add_abstract_origin_attribute (parm_die, origin);
18587 else if (emit_name_p)
18588 add_name_and_src_coords_attributes (parm_die, node);
18590 || (! DECL_ABSTRACT (node_or_origin)
18591 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18592 decl_function_context
18593 (node_or_origin))))
18595 tree type = TREE_TYPE (node_or_origin);
18596 if (decl_by_reference_p (node_or_origin))
18597 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18600 add_type_attribute (parm_die, type,
18601 TREE_READONLY (node_or_origin),
18602 TREE_THIS_VOLATILE (node_or_origin),
18605 if (origin == NULL && DECL_ARTIFICIAL (node))
18606 add_AT_flag (parm_die, DW_AT_artificial, 1);
18608 if (node && node != origin)
18609 equate_decl_number_to_die (node, parm_die);
18610 if (! DECL_ABSTRACT (node_or_origin))
18611 add_location_or_const_value_attribute (parm_die, node_or_origin,
18612 node == NULL, DW_AT_location);
18617 /* We were called with some kind of a ..._TYPE node. */
18618 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18622 gcc_unreachable ();
18628 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18629 children DW_TAG_formal_parameter DIEs representing the arguments of the
18632 PARM_PACK must be a function parameter pack.
18633 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18634 must point to the subsequent arguments of the function PACK_ARG belongs to.
18635 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18636 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18637 following the last one for which a DIE was generated. */
18640 gen_formal_parameter_pack_die (tree parm_pack,
18642 dw_die_ref subr_die,
18646 dw_die_ref parm_pack_die;
18648 gcc_assert (parm_pack
18649 && lang_hooks.function_parameter_pack_p (parm_pack)
18652 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18653 add_src_coords_attributes (parm_pack_die, parm_pack);
18655 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18657 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18660 gen_formal_parameter_die (arg, NULL,
18661 false /* Don't emit name attribute. */,
18666 return parm_pack_die;
18669 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18670 at the end of an (ANSI prototyped) formal parameters list. */
18673 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18675 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18678 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18679 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18680 parameters as specified in some function type specification (except for
18681 those which appear as part of a function *definition*). */
18684 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18687 tree formal_type = NULL;
18688 tree first_parm_type;
18691 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18693 arg = DECL_ARGUMENTS (function_or_method_type);
18694 function_or_method_type = TREE_TYPE (function_or_method_type);
18699 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18701 /* Make our first pass over the list of formal parameter types and output a
18702 DW_TAG_formal_parameter DIE for each one. */
18703 for (link = first_parm_type; link; )
18705 dw_die_ref parm_die;
18707 formal_type = TREE_VALUE (link);
18708 if (formal_type == void_type_node)
18711 /* Output a (nameless) DIE to represent the formal parameter itself. */
18712 parm_die = gen_formal_parameter_die (formal_type, NULL,
18713 true /* Emit name attribute. */,
18715 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18716 && link == first_parm_type)
18718 add_AT_flag (parm_die, DW_AT_artificial, 1);
18719 if (dwarf_version >= 3 || !dwarf_strict)
18720 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18722 else if (arg && DECL_ARTIFICIAL (arg))
18723 add_AT_flag (parm_die, DW_AT_artificial, 1);
18725 link = TREE_CHAIN (link);
18727 arg = DECL_CHAIN (arg);
18730 /* If this function type has an ellipsis, add a
18731 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18732 if (formal_type != void_type_node)
18733 gen_unspecified_parameters_die (function_or_method_type, context_die);
18735 /* Make our second (and final) pass over the list of formal parameter types
18736 and output DIEs to represent those types (as necessary). */
18737 for (link = TYPE_ARG_TYPES (function_or_method_type);
18738 link && TREE_VALUE (link);
18739 link = TREE_CHAIN (link))
18740 gen_type_die (TREE_VALUE (link), context_die);
18743 /* We want to generate the DIE for TYPE so that we can generate the
18744 die for MEMBER, which has been defined; we will need to refer back
18745 to the member declaration nested within TYPE. If we're trying to
18746 generate minimal debug info for TYPE, processing TYPE won't do the
18747 trick; we need to attach the member declaration by hand. */
18750 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18752 gen_type_die (type, context_die);
18754 /* If we're trying to avoid duplicate debug info, we may not have
18755 emitted the member decl for this function. Emit it now. */
18756 if (TYPE_STUB_DECL (type)
18757 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18758 && ! lookup_decl_die (member))
18760 dw_die_ref type_die;
18761 gcc_assert (!decl_ultimate_origin (member));
18763 push_decl_scope (type);
18764 type_die = lookup_type_die_strip_naming_typedef (type);
18765 if (TREE_CODE (member) == FUNCTION_DECL)
18766 gen_subprogram_die (member, type_die);
18767 else if (TREE_CODE (member) == FIELD_DECL)
18769 /* Ignore the nameless fields that are used to skip bits but handle
18770 C++ anonymous unions and structs. */
18771 if (DECL_NAME (member) != NULL_TREE
18772 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18773 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18775 gen_type_die (member_declared_type (member), type_die);
18776 gen_field_die (member, type_die);
18780 gen_variable_die (member, NULL_TREE, type_die);
18786 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18787 may later generate inlined and/or out-of-line instances of. */
18790 dwarf2out_abstract_function (tree decl)
18792 dw_die_ref old_die;
18796 htab_t old_decl_loc_table;
18797 htab_t old_cached_dw_loc_list_table;
18798 int old_call_site_count, old_tail_call_site_count;
18799 struct call_arg_loc_node *old_call_arg_locations;
18801 /* Make sure we have the actual abstract inline, not a clone. */
18802 decl = DECL_ORIGIN (decl);
18804 old_die = lookup_decl_die (decl);
18805 if (old_die && get_AT (old_die, DW_AT_inline))
18806 /* We've already generated the abstract instance. */
18809 /* We can be called while recursively when seeing block defining inlined subroutine
18810 DIE. Be sure to not clobber the outer location table nor use it or we would
18811 get locations in abstract instantces. */
18812 old_decl_loc_table = decl_loc_table;
18813 decl_loc_table = NULL;
18814 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
18815 cached_dw_loc_list_table = NULL;
18816 old_call_arg_locations = call_arg_locations;
18817 call_arg_locations = NULL;
18818 old_call_site_count = call_site_count;
18819 call_site_count = -1;
18820 old_tail_call_site_count = tail_call_site_count;
18821 tail_call_site_count = -1;
18823 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18824 we don't get confused by DECL_ABSTRACT. */
18825 if (debug_info_level > DINFO_LEVEL_TERSE)
18827 context = decl_class_context (decl);
18829 gen_type_die_for_member
18830 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18833 /* Pretend we've just finished compiling this function. */
18834 save_fn = current_function_decl;
18835 current_function_decl = decl;
18836 push_cfun (DECL_STRUCT_FUNCTION (decl));
18838 was_abstract = DECL_ABSTRACT (decl);
18839 set_decl_abstract_flags (decl, 1);
18840 dwarf2out_decl (decl);
18841 if (! was_abstract)
18842 set_decl_abstract_flags (decl, 0);
18844 current_function_decl = save_fn;
18845 decl_loc_table = old_decl_loc_table;
18846 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
18847 call_arg_locations = old_call_arg_locations;
18848 call_site_count = old_call_site_count;
18849 tail_call_site_count = old_tail_call_site_count;
18853 /* Helper function of premark_used_types() which gets called through
18856 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18857 marked as unused by prune_unused_types. */
18860 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18865 type = (tree) *slot;
18866 die = lookup_type_die (type);
18868 die->die_perennial_p = 1;
18872 /* Helper function of premark_types_used_by_global_vars which gets called
18873 through htab_traverse.
18875 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18876 marked as unused by prune_unused_types. The DIE of the type is marked
18877 only if the global variable using the type will actually be emitted. */
18880 premark_types_used_by_global_vars_helper (void **slot,
18881 void *data ATTRIBUTE_UNUSED)
18883 struct types_used_by_vars_entry *entry;
18886 entry = (struct types_used_by_vars_entry *) *slot;
18887 gcc_assert (entry->type != NULL
18888 && entry->var_decl != NULL);
18889 die = lookup_type_die (entry->type);
18892 /* Ask cgraph if the global variable really is to be emitted.
18893 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18894 struct varpool_node *node = varpool_get_node (entry->var_decl);
18895 if (node && node->needed)
18897 die->die_perennial_p = 1;
18898 /* Keep the parent DIEs as well. */
18899 while ((die = die->die_parent) && die->die_perennial_p == 0)
18900 die->die_perennial_p = 1;
18906 /* Mark all members of used_types_hash as perennial. */
18909 premark_used_types (void)
18911 if (cfun && cfun->used_types_hash)
18912 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18915 /* Mark all members of types_used_by_vars_entry as perennial. */
18918 premark_types_used_by_global_vars (void)
18920 if (types_used_by_vars_hash)
18921 htab_traverse (types_used_by_vars_hash,
18922 premark_types_used_by_global_vars_helper, NULL);
18925 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18926 for CA_LOC call arg loc node. */
18929 gen_call_site_die (tree decl, dw_die_ref subr_die,
18930 struct call_arg_loc_node *ca_loc)
18932 dw_die_ref stmt_die = NULL, die;
18933 tree block = ca_loc->block;
18936 && block != DECL_INITIAL (decl)
18937 && TREE_CODE (block) == BLOCK)
18939 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
18940 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
18943 block = BLOCK_SUPERCONTEXT (block);
18945 if (stmt_die == NULL)
18946 stmt_die = subr_die;
18947 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
18948 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
18949 if (ca_loc->tail_call_p)
18950 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
18951 if (ca_loc->symbol_ref)
18953 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
18955 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
18957 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
18962 /* Generate a DIE to represent a declared function (either file-scope or
18966 gen_subprogram_die (tree decl, dw_die_ref context_die)
18968 tree origin = decl_ultimate_origin (decl);
18969 dw_die_ref subr_die;
18971 dw_die_ref old_die = lookup_decl_die (decl);
18972 int declaration = (current_function_decl != decl
18973 || class_or_namespace_scope_p (context_die));
18975 premark_used_types ();
18977 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18978 started to generate the abstract instance of an inline, decided to output
18979 its containing class, and proceeded to emit the declaration of the inline
18980 from the member list for the class. If so, DECLARATION takes priority;
18981 we'll get back to the abstract instance when done with the class. */
18983 /* The class-scope declaration DIE must be the primary DIE. */
18984 if (origin && declaration && class_or_namespace_scope_p (context_die))
18987 gcc_assert (!old_die);
18990 /* Now that the C++ front end lazily declares artificial member fns, we
18991 might need to retrofit the declaration into its class. */
18992 if (!declaration && !origin && !old_die
18993 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18994 && !class_or_namespace_scope_p (context_die)
18995 && debug_info_level > DINFO_LEVEL_TERSE)
18996 old_die = force_decl_die (decl);
18998 if (origin != NULL)
19000 gcc_assert (!declaration || local_scope_p (context_die));
19002 /* Fixup die_parent for the abstract instance of a nested
19003 inline function. */
19004 if (old_die && old_die->die_parent == NULL)
19005 add_child_die (context_die, old_die);
19007 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19008 add_abstract_origin_attribute (subr_die, origin);
19012 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19013 struct dwarf_file_data * file_index = lookup_filename (s.file);
19015 if (!get_AT_flag (old_die, DW_AT_declaration)
19016 /* We can have a normal definition following an inline one in the
19017 case of redefinition of GNU C extern inlines.
19018 It seems reasonable to use AT_specification in this case. */
19019 && !get_AT (old_die, DW_AT_inline))
19021 /* Detect and ignore this case, where we are trying to output
19022 something we have already output. */
19026 /* If the definition comes from the same place as the declaration,
19027 maybe use the old DIE. We always want the DIE for this function
19028 that has the *_pc attributes to be under comp_unit_die so the
19029 debugger can find it. We also need to do this for abstract
19030 instances of inlines, since the spec requires the out-of-line copy
19031 to have the same parent. For local class methods, this doesn't
19032 apply; we just use the old DIE. */
19033 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19034 && (DECL_ARTIFICIAL (decl)
19035 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19036 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19037 == (unsigned) s.line))))
19039 subr_die = old_die;
19041 /* Clear out the declaration attribute and the formal parameters.
19042 Do not remove all children, because it is possible that this
19043 declaration die was forced using force_decl_die(). In such
19044 cases die that forced declaration die (e.g. TAG_imported_module)
19045 is one of the children that we do not want to remove. */
19046 remove_AT (subr_die, DW_AT_declaration);
19047 remove_AT (subr_die, DW_AT_object_pointer);
19048 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19052 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19053 add_AT_specification (subr_die, old_die);
19054 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19055 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19056 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19057 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19062 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19064 if (TREE_PUBLIC (decl))
19065 add_AT_flag (subr_die, DW_AT_external, 1);
19067 add_name_and_src_coords_attributes (subr_die, decl);
19068 if (debug_info_level > DINFO_LEVEL_TERSE)
19070 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19071 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19072 0, 0, context_die);
19075 add_pure_or_virtual_attribute (subr_die, decl);
19076 if (DECL_ARTIFICIAL (decl))
19077 add_AT_flag (subr_die, DW_AT_artificial, 1);
19079 add_accessibility_attribute (subr_die, decl);
19084 if (!old_die || !get_AT (old_die, DW_AT_inline))
19086 add_AT_flag (subr_die, DW_AT_declaration, 1);
19088 /* If this is an explicit function declaration then generate
19089 a DW_AT_explicit attribute. */
19090 if (lang_hooks.decls.function_decl_explicit_p (decl)
19091 && (dwarf_version >= 3 || !dwarf_strict))
19092 add_AT_flag (subr_die, DW_AT_explicit, 1);
19094 /* The first time we see a member function, it is in the context of
19095 the class to which it belongs. We make sure of this by emitting
19096 the class first. The next time is the definition, which is
19097 handled above. The two may come from the same source text.
19099 Note that force_decl_die() forces function declaration die. It is
19100 later reused to represent definition. */
19101 equate_decl_number_to_die (decl, subr_die);
19104 else if (DECL_ABSTRACT (decl))
19106 if (DECL_DECLARED_INLINE_P (decl))
19108 if (cgraph_function_possibly_inlined_p (decl))
19109 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19111 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19115 if (cgraph_function_possibly_inlined_p (decl))
19116 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19118 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19121 if (DECL_DECLARED_INLINE_P (decl)
19122 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19123 add_AT_flag (subr_die, DW_AT_artificial, 1);
19125 equate_decl_number_to_die (decl, subr_die);
19127 else if (!DECL_EXTERNAL (decl))
19129 HOST_WIDE_INT cfa_fb_offset;
19131 if (!old_die || !get_AT (old_die, DW_AT_inline))
19132 equate_decl_number_to_die (decl, subr_die);
19134 if (!flag_reorder_blocks_and_partition)
19136 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19137 if (fde->dw_fde_begin)
19139 /* We have already generated the labels. */
19140 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19141 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19145 /* Create start/end labels and add the range. */
19146 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19147 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19148 current_function_funcdef_no);
19149 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19150 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19151 current_function_funcdef_no);
19152 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19155 #if VMS_DEBUGGING_INFO
19156 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19157 Section 2.3 Prologue and Epilogue Attributes:
19158 When a breakpoint is set on entry to a function, it is generally
19159 desirable for execution to be suspended, not on the very first
19160 instruction of the function, but rather at a point after the
19161 function's frame has been set up, after any language defined local
19162 declaration processing has been completed, and before execution of
19163 the first statement of the function begins. Debuggers generally
19164 cannot properly determine where this point is. Similarly for a
19165 breakpoint set on exit from a function. The prologue and epilogue
19166 attributes allow a compiler to communicate the location(s) to use. */
19169 if (fde->dw_fde_vms_end_prologue)
19170 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19171 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19173 if (fde->dw_fde_vms_begin_epilogue)
19174 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19175 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19179 add_pubname (decl, subr_die);
19182 { /* Generate pubnames entries for the split function code
19184 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19186 if (fde->dw_fde_second_begin)
19188 if (dwarf_version >= 3 || !dwarf_strict)
19190 /* We should use ranges for non-contiguous code section
19191 addresses. Use the actual code range for the initial
19192 section, since the HOT/COLD labels might precede an
19193 alignment offset. */
19194 bool range_list_added = false;
19195 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
19196 fde->dw_fde_end, &range_list_added);
19197 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
19198 fde->dw_fde_second_end,
19199 &range_list_added);
19200 add_pubname (decl, subr_die);
19201 if (range_list_added)
19206 /* There is no real support in DW2 for this .. so we make
19207 a work-around. First, emit the pub name for the segment
19208 containing the function label. Then make and emit a
19209 simplified subprogram DIE for the second segment with the
19210 name pre-fixed by __hot/cold_sect_of_. We use the same
19211 linkage name for the second die so that gdb will find both
19212 sections when given "b foo". */
19213 const char *name = NULL;
19214 tree decl_name = DECL_NAME (decl);
19215 dw_die_ref seg_die;
19217 /* Do the 'primary' section. */
19218 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19219 fde->dw_fde_begin);
19220 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19223 add_pubname (decl, subr_die);
19225 /* Build a minimal DIE for the secondary section. */
19226 seg_die = new_die (DW_TAG_subprogram,
19227 subr_die->die_parent, decl);
19229 if (TREE_PUBLIC (decl))
19230 add_AT_flag (seg_die, DW_AT_external, 1);
19232 if (decl_name != NULL
19233 && IDENTIFIER_POINTER (decl_name) != NULL)
19235 name = dwarf2_name (decl, 1);
19236 if (! DECL_ARTIFICIAL (decl))
19237 add_src_coords_attributes (seg_die, decl);
19239 add_linkage_name (seg_die, decl);
19241 gcc_assert (name != NULL);
19242 add_pure_or_virtual_attribute (seg_die, decl);
19243 if (DECL_ARTIFICIAL (decl))
19244 add_AT_flag (seg_die, DW_AT_artificial, 1);
19246 name = concat ("__second_sect_of_", name, NULL);
19247 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19248 fde->dw_fde_second_begin);
19249 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19250 fde->dw_fde_second_end);
19251 add_name_attribute (seg_die, name);
19252 add_pubname_string (name, seg_die);
19257 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19258 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19259 add_pubname (decl, subr_die);
19263 #ifdef MIPS_DEBUGGING_INFO
19264 /* Add a reference to the FDE for this routine. */
19265 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19268 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19270 /* We define the "frame base" as the function's CFA. This is more
19271 convenient for several reasons: (1) It's stable across the prologue
19272 and epilogue, which makes it better than just a frame pointer,
19273 (2) With dwarf3, there exists a one-byte encoding that allows us
19274 to reference the .debug_frame data by proxy, but failing that,
19275 (3) We can at least reuse the code inspection and interpretation
19276 code that determines the CFA position at various points in the
19278 if (dwarf_version >= 3)
19280 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19281 add_AT_loc (subr_die, DW_AT_frame_base, op);
19285 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19286 if (list->dw_loc_next)
19287 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19289 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19292 /* Compute a displacement from the "steady-state frame pointer" to
19293 the CFA. The former is what all stack slots and argument slots
19294 will reference in the rtl; the later is what we've told the
19295 debugger about. We'll need to adjust all frame_base references
19296 by this displacement. */
19297 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19299 if (cfun->static_chain_decl)
19300 add_AT_location_description (subr_die, DW_AT_static_link,
19301 loc_list_from_tree (cfun->static_chain_decl, 2));
19304 /* Generate child dies for template paramaters. */
19305 if (debug_info_level > DINFO_LEVEL_TERSE)
19306 gen_generic_params_dies (decl);
19308 /* Now output descriptions of the arguments for this function. This gets
19309 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19310 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19311 `...' at the end of the formal parameter list. In order to find out if
19312 there was a trailing ellipsis or not, we must instead look at the type
19313 associated with the FUNCTION_DECL. This will be a node of type
19314 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19315 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19316 an ellipsis at the end. */
19318 /* In the case where we are describing a mere function declaration, all we
19319 need to do here (and all we *can* do here) is to describe the *types* of
19320 its formal parameters. */
19321 if (debug_info_level <= DINFO_LEVEL_TERSE)
19323 else if (declaration)
19324 gen_formal_types_die (decl, subr_die);
19327 /* Generate DIEs to represent all known formal parameters. */
19328 tree parm = DECL_ARGUMENTS (decl);
19329 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19330 tree generic_decl_parm = generic_decl
19331 ? DECL_ARGUMENTS (generic_decl)
19334 /* Now we want to walk the list of parameters of the function and
19335 emit their relevant DIEs.
19337 We consider the case of DECL being an instance of a generic function
19338 as well as it being a normal function.
19340 If DECL is an instance of a generic function we walk the
19341 parameters of the generic function declaration _and_ the parameters of
19342 DECL itself. This is useful because we want to emit specific DIEs for
19343 function parameter packs and those are declared as part of the
19344 generic function declaration. In that particular case,
19345 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19346 That DIE has children DIEs representing the set of arguments
19347 of the pack. Note that the set of pack arguments can be empty.
19348 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19351 Otherwise, we just consider the parameters of DECL. */
19352 while (generic_decl_parm || parm)
19354 if (generic_decl_parm
19355 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19356 gen_formal_parameter_pack_die (generic_decl_parm,
19361 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19363 if (parm == DECL_ARGUMENTS (decl)
19364 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19366 && (dwarf_version >= 3 || !dwarf_strict))
19367 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19369 parm = DECL_CHAIN (parm);
19372 if (generic_decl_parm)
19373 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19376 /* Decide whether we need an unspecified_parameters DIE at the end.
19377 There are 2 more cases to do this for: 1) the ansi ... declaration -
19378 this is detectable when the end of the arg list is not a
19379 void_type_node 2) an unprototyped function declaration (not a
19380 definition). This just means that we have no info about the
19381 parameters at all. */
19382 if (prototype_p (TREE_TYPE (decl)))
19384 /* This is the prototyped case, check for.... */
19385 if (stdarg_p (TREE_TYPE (decl)))
19386 gen_unspecified_parameters_die (decl, subr_die);
19388 else if (DECL_INITIAL (decl) == NULL_TREE)
19389 gen_unspecified_parameters_die (decl, subr_die);
19392 /* Output Dwarf info for all of the stuff within the body of the function
19393 (if it has one - it may be just a declaration). */
19394 outer_scope = DECL_INITIAL (decl);
19396 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19397 a function. This BLOCK actually represents the outermost binding contour
19398 for the function, i.e. the contour in which the function's formal
19399 parameters and labels get declared. Curiously, it appears that the front
19400 end doesn't actually put the PARM_DECL nodes for the current function onto
19401 the BLOCK_VARS list for this outer scope, but are strung off of the
19402 DECL_ARGUMENTS list for the function instead.
19404 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19405 the LABEL_DECL nodes for the function however, and we output DWARF info
19406 for those in decls_for_scope. Just within the `outer_scope' there will be
19407 a BLOCK node representing the function's outermost pair of curly braces,
19408 and any blocks used for the base and member initializers of a C++
19409 constructor function. */
19410 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19412 int call_site_note_count = 0;
19413 int tail_call_site_note_count = 0;
19415 /* Emit a DW_TAG_variable DIE for a named return value. */
19416 if (DECL_NAME (DECL_RESULT (decl)))
19417 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19419 current_function_has_inlines = 0;
19420 decls_for_scope (outer_scope, subr_die, 0);
19422 if (call_arg_locations && !dwarf_strict)
19424 struct call_arg_loc_node *ca_loc;
19425 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19427 dw_die_ref die = NULL;
19428 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19431 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19432 arg; arg = next_arg)
19434 dw_loc_descr_ref reg, val;
19435 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19438 next_arg = XEXP (arg, 1);
19439 if (REG_P (XEXP (XEXP (arg, 0), 0))
19441 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19442 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19443 && REGNO (XEXP (XEXP (arg, 0), 0))
19444 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19445 next_arg = XEXP (next_arg, 1);
19446 if (mode == VOIDmode)
19448 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19449 if (mode == VOIDmode)
19450 mode = GET_MODE (XEXP (arg, 0));
19452 if (GET_MODE_CLASS (mode) != MODE_INT
19453 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
19455 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19457 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19458 tloc = XEXP (XEXP (arg, 0), 1);
19461 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19462 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19464 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19465 tlocc = XEXP (XEXP (arg, 0), 1);
19468 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19469 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19470 VAR_INIT_STATUS_INITIALIZED);
19471 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19472 reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
19474 VAR_INIT_STATUS_INITIALIZED);
19479 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
19480 VAR_INIT_STATUS_INITIALIZED);
19484 die = gen_call_site_die (decl, subr_die, ca_loc);
19485 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19487 add_AT_loc (cdie, DW_AT_location, reg);
19488 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19489 if (next_arg != XEXP (arg, 1))
19491 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19493 VAR_INIT_STATUS_INITIALIZED);
19495 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19499 && (ca_loc->symbol_ref || tloc))
19500 die = gen_call_site_die (decl, subr_die, ca_loc);
19501 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19503 dw_loc_descr_ref tval = NULL;
19505 if (tloc != NULL_RTX)
19506 tval = mem_loc_descriptor (tloc, VOIDmode,
19507 VAR_INIT_STATUS_INITIALIZED);
19509 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19510 else if (tlocc != NULL_RTX)
19512 tval = mem_loc_descriptor (tlocc, VOIDmode,
19513 VAR_INIT_STATUS_INITIALIZED);
19515 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19521 call_site_note_count++;
19522 if (ca_loc->tail_call_p)
19523 tail_call_site_note_count++;
19527 call_arg_locations = NULL;
19528 call_arg_loc_last = NULL;
19529 if (tail_call_site_count >= 0
19530 && tail_call_site_count == tail_call_site_note_count
19533 if (call_site_count >= 0
19534 && call_site_count == call_site_note_count)
19535 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19537 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19539 call_site_count = -1;
19540 tail_call_site_count = -1;
19542 /* Add the calling convention attribute if requested. */
19543 add_calling_convention_attribute (subr_die, decl);
19547 /* Returns a hash value for X (which really is a die_struct). */
19550 common_block_die_table_hash (const void *x)
19552 const_dw_die_ref d = (const_dw_die_ref) x;
19553 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19556 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19557 as decl_id and die_parent of die_struct Y. */
19560 common_block_die_table_eq (const void *x, const void *y)
19562 const_dw_die_ref d = (const_dw_die_ref) x;
19563 const_dw_die_ref e = (const_dw_die_ref) y;
19564 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19567 /* Generate a DIE to represent a declared data object.
19568 Either DECL or ORIGIN must be non-null. */
19571 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19575 tree decl_or_origin = decl ? decl : origin;
19576 tree ultimate_origin;
19577 dw_die_ref var_die;
19578 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19579 dw_die_ref origin_die;
19580 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19581 || class_or_namespace_scope_p (context_die));
19582 bool specialization_p = false;
19584 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19585 if (decl || ultimate_origin)
19586 origin = ultimate_origin;
19587 com_decl = fortran_common (decl_or_origin, &off);
19589 /* Symbol in common gets emitted as a child of the common block, in the form
19590 of a data member. */
19593 dw_die_ref com_die;
19594 dw_loc_list_ref loc;
19595 die_node com_die_arg;
19597 var_die = lookup_decl_die (decl_or_origin);
19600 if (get_AT (var_die, DW_AT_location) == NULL)
19602 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19607 /* Optimize the common case. */
19608 if (single_element_loc_list_p (loc)
19609 && loc->expr->dw_loc_opc == DW_OP_addr
19610 && loc->expr->dw_loc_next == NULL
19611 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19613 loc->expr->dw_loc_oprnd1.v.val_addr
19614 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19616 loc_list_plus_const (loc, off);
19618 add_AT_location_description (var_die, DW_AT_location, loc);
19619 remove_AT (var_die, DW_AT_declaration);
19625 if (common_block_die_table == NULL)
19626 common_block_die_table
19627 = htab_create_ggc (10, common_block_die_table_hash,
19628 common_block_die_table_eq, NULL);
19630 com_die_arg.decl_id = DECL_UID (com_decl);
19631 com_die_arg.die_parent = context_die;
19632 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19633 loc = loc_list_from_tree (com_decl, 2);
19634 if (com_die == NULL)
19637 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19640 com_die = new_die (DW_TAG_common_block, context_die, decl);
19641 add_name_and_src_coords_attributes (com_die, com_decl);
19644 add_AT_location_description (com_die, DW_AT_location, loc);
19645 /* Avoid sharing the same loc descriptor between
19646 DW_TAG_common_block and DW_TAG_variable. */
19647 loc = loc_list_from_tree (com_decl, 2);
19649 else if (DECL_EXTERNAL (decl))
19650 add_AT_flag (com_die, DW_AT_declaration, 1);
19651 add_pubname_string (cnam, com_die); /* ??? needed? */
19652 com_die->decl_id = DECL_UID (com_decl);
19653 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19654 *slot = (void *) com_die;
19656 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19658 add_AT_location_description (com_die, DW_AT_location, loc);
19659 loc = loc_list_from_tree (com_decl, 2);
19660 remove_AT (com_die, DW_AT_declaration);
19662 var_die = new_die (DW_TAG_variable, com_die, decl);
19663 add_name_and_src_coords_attributes (var_die, decl);
19664 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19665 TREE_THIS_VOLATILE (decl), context_die);
19666 add_AT_flag (var_die, DW_AT_external, 1);
19671 /* Optimize the common case. */
19672 if (single_element_loc_list_p (loc)
19673 && loc->expr->dw_loc_opc == DW_OP_addr
19674 && loc->expr->dw_loc_next == NULL
19675 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19676 loc->expr->dw_loc_oprnd1.v.val_addr
19677 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19679 loc_list_plus_const (loc, off);
19681 add_AT_location_description (var_die, DW_AT_location, loc);
19683 else if (DECL_EXTERNAL (decl))
19684 add_AT_flag (var_die, DW_AT_declaration, 1);
19685 equate_decl_number_to_die (decl, var_die);
19689 /* If the compiler emitted a definition for the DECL declaration
19690 and if we already emitted a DIE for it, don't emit a second
19691 DIE for it again. Allow re-declarations of DECLs that are
19692 inside functions, though. */
19693 if (old_die && declaration && !local_scope_p (context_die))
19696 /* For static data members, the declaration in the class is supposed
19697 to have DW_TAG_member tag; the specification should still be
19698 DW_TAG_variable referencing the DW_TAG_member DIE. */
19699 if (declaration && class_scope_p (context_die))
19700 var_die = new_die (DW_TAG_member, context_die, decl);
19702 var_die = new_die (DW_TAG_variable, context_die, decl);
19705 if (origin != NULL)
19706 origin_die = add_abstract_origin_attribute (var_die, origin);
19708 /* Loop unrolling can create multiple blocks that refer to the same
19709 static variable, so we must test for the DW_AT_declaration flag.
19711 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19712 copy decls and set the DECL_ABSTRACT flag on them instead of
19715 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19717 ??? The declare_in_namespace support causes us to get two DIEs for one
19718 variable, both of which are declarations. We want to avoid considering
19719 one to be a specification, so we must test that this DIE is not a
19721 else if (old_die && TREE_STATIC (decl) && ! declaration
19722 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19724 /* This is a definition of a C++ class level static. */
19725 add_AT_specification (var_die, old_die);
19726 specialization_p = true;
19727 if (DECL_NAME (decl))
19729 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19730 struct dwarf_file_data * file_index = lookup_filename (s.file);
19732 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19733 add_AT_file (var_die, DW_AT_decl_file, file_index);
19735 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19736 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19738 if (old_die->die_tag == DW_TAG_member)
19739 add_linkage_name (var_die, decl);
19743 add_name_and_src_coords_attributes (var_die, decl);
19745 if ((origin == NULL && !specialization_p)
19747 && !DECL_ABSTRACT (decl_or_origin)
19748 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19749 decl_function_context
19750 (decl_or_origin))))
19752 tree type = TREE_TYPE (decl_or_origin);
19754 if (decl_by_reference_p (decl_or_origin))
19755 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19757 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19758 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19761 if (origin == NULL && !specialization_p)
19763 if (TREE_PUBLIC (decl))
19764 add_AT_flag (var_die, DW_AT_external, 1);
19766 if (DECL_ARTIFICIAL (decl))
19767 add_AT_flag (var_die, DW_AT_artificial, 1);
19769 add_accessibility_attribute (var_die, decl);
19773 add_AT_flag (var_die, DW_AT_declaration, 1);
19775 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19776 equate_decl_number_to_die (decl, var_die);
19779 && (! DECL_ABSTRACT (decl_or_origin)
19780 /* Local static vars are shared between all clones/inlines,
19781 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19783 || (TREE_CODE (decl_or_origin) == VAR_DECL
19784 && TREE_STATIC (decl_or_origin)
19785 && DECL_RTL_SET_P (decl_or_origin)))
19786 /* When abstract origin already has DW_AT_location attribute, no need
19787 to add it again. */
19788 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19790 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19791 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19792 defer_location (decl_or_origin, var_die);
19794 add_location_or_const_value_attribute (var_die, decl_or_origin,
19795 decl == NULL, DW_AT_location);
19796 add_pubname (decl_or_origin, var_die);
19799 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19802 /* Generate a DIE to represent a named constant. */
19805 gen_const_die (tree decl, dw_die_ref context_die)
19807 dw_die_ref const_die;
19808 tree type = TREE_TYPE (decl);
19810 const_die = new_die (DW_TAG_constant, context_die, decl);
19811 add_name_and_src_coords_attributes (const_die, decl);
19812 add_type_attribute (const_die, type, 1, 0, context_die);
19813 if (TREE_PUBLIC (decl))
19814 add_AT_flag (const_die, DW_AT_external, 1);
19815 if (DECL_ARTIFICIAL (decl))
19816 add_AT_flag (const_die, DW_AT_artificial, 1);
19817 tree_add_const_value_attribute_for_decl (const_die, decl);
19820 /* Generate a DIE to represent a label identifier. */
19823 gen_label_die (tree decl, dw_die_ref context_die)
19825 tree origin = decl_ultimate_origin (decl);
19826 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19828 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19830 if (origin != NULL)
19831 add_abstract_origin_attribute (lbl_die, origin);
19833 add_name_and_src_coords_attributes (lbl_die, decl);
19835 if (DECL_ABSTRACT (decl))
19836 equate_decl_number_to_die (decl, lbl_die);
19839 insn = DECL_RTL_IF_SET (decl);
19841 /* Deleted labels are programmer specified labels which have been
19842 eliminated because of various optimizations. We still emit them
19843 here so that it is possible to put breakpoints on them. */
19847 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19849 /* When optimization is enabled (via -O) some parts of the compiler
19850 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19851 represent source-level labels which were explicitly declared by
19852 the user. This really shouldn't be happening though, so catch
19853 it if it ever does happen. */
19854 gcc_assert (!INSN_DELETED_P (insn));
19856 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19857 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19862 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19863 attributes to the DIE for a block STMT, to describe where the inlined
19864 function was called from. This is similar to add_src_coords_attributes. */
19867 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19869 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19871 if (dwarf_version >= 3 || !dwarf_strict)
19873 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19874 add_AT_unsigned (die, DW_AT_call_line, s.line);
19879 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19880 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19883 add_high_low_attributes (tree stmt, dw_die_ref die)
19885 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19887 if (BLOCK_FRAGMENT_CHAIN (stmt)
19888 && (dwarf_version >= 3 || !dwarf_strict))
19892 if (inlined_function_outer_scope_p (stmt))
19894 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19895 BLOCK_NUMBER (stmt));
19896 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19899 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19901 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19904 add_ranges (chain);
19905 chain = BLOCK_FRAGMENT_CHAIN (chain);
19912 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19913 BLOCK_NUMBER (stmt));
19914 add_AT_lbl_id (die, DW_AT_low_pc, label);
19915 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19916 BLOCK_NUMBER (stmt));
19917 add_AT_lbl_id (die, DW_AT_high_pc, label);
19921 /* Generate a DIE for a lexical block. */
19924 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19926 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19928 if (call_arg_locations)
19930 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
19931 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
19932 BLOCK_NUMBER (stmt) + 1);
19933 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
19936 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19937 add_high_low_attributes (stmt, stmt_die);
19939 decls_for_scope (stmt, stmt_die, depth);
19942 /* Generate a DIE for an inlined subprogram. */
19945 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19949 /* The instance of function that is effectively being inlined shall not
19951 gcc_assert (! BLOCK_ABSTRACT (stmt));
19953 decl = block_ultimate_origin (stmt);
19955 /* Emit info for the abstract instance first, if we haven't yet. We
19956 must emit this even if the block is abstract, otherwise when we
19957 emit the block below (or elsewhere), we may end up trying to emit
19958 a die whose origin die hasn't been emitted, and crashing. */
19959 dwarf2out_abstract_function (decl);
19961 if (! BLOCK_ABSTRACT (stmt))
19963 dw_die_ref subr_die
19964 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19966 if (call_arg_locations)
19968 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
19969 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
19970 BLOCK_NUMBER (stmt) + 1);
19971 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
19973 add_abstract_origin_attribute (subr_die, decl);
19974 if (TREE_ASM_WRITTEN (stmt))
19975 add_high_low_attributes (stmt, subr_die);
19976 add_call_src_coords_attributes (stmt, subr_die);
19978 decls_for_scope (stmt, subr_die, depth);
19979 current_function_has_inlines = 1;
19983 /* Generate a DIE for a field in a record, or structure. */
19986 gen_field_die (tree decl, dw_die_ref context_die)
19988 dw_die_ref decl_die;
19990 if (TREE_TYPE (decl) == error_mark_node)
19993 decl_die = new_die (DW_TAG_member, context_die, decl);
19994 add_name_and_src_coords_attributes (decl_die, decl);
19995 add_type_attribute (decl_die, member_declared_type (decl),
19996 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
19999 if (DECL_BIT_FIELD_TYPE (decl))
20001 add_byte_size_attribute (decl_die, decl);
20002 add_bit_size_attribute (decl_die, decl);
20003 add_bit_offset_attribute (decl_die, decl);
20006 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20007 add_data_member_location_attribute (decl_die, decl);
20009 if (DECL_ARTIFICIAL (decl))
20010 add_AT_flag (decl_die, DW_AT_artificial, 1);
20012 add_accessibility_attribute (decl_die, decl);
20014 /* Equate decl number to die, so that we can look up this decl later on. */
20015 equate_decl_number_to_die (decl, decl_die);
20019 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20020 Use modified_type_die instead.
20021 We keep this code here just in case these types of DIEs may be needed to
20022 represent certain things in other languages (e.g. Pascal) someday. */
20025 gen_pointer_type_die (tree type, dw_die_ref context_die)
20028 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20030 equate_type_number_to_die (type, ptr_die);
20031 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20032 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20035 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20036 Use modified_type_die instead.
20037 We keep this code here just in case these types of DIEs may be needed to
20038 represent certain things in other languages (e.g. Pascal) someday. */
20041 gen_reference_type_die (tree type, dw_die_ref context_die)
20043 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20045 if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
20046 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20048 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20050 equate_type_number_to_die (type, ref_die);
20051 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20052 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20056 /* Generate a DIE for a pointer to a member type. */
20059 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20062 = new_die (DW_TAG_ptr_to_member_type,
20063 scope_die_for (type, context_die), type);
20065 equate_type_number_to_die (type, ptr_die);
20066 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20067 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20068 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20071 /* Generate the DIE for the compilation unit. */
20074 gen_compile_unit_die (const char *filename)
20077 char producer[250];
20078 const char *language_string = lang_hooks.name;
20081 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20085 add_name_attribute (die, filename);
20086 /* Don't add cwd for <built-in>. */
20087 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20088 add_comp_dir_attribute (die);
20091 sprintf (producer, "%s %s", language_string, version_string);
20093 #ifdef MIPS_DEBUGGING_INFO
20094 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20095 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20096 not appear in the producer string, the debugger reaches the conclusion
20097 that the object file is stripped and has no debugging information.
20098 To get the MIPS/SGI debugger to believe that there is debugging
20099 information in the object file, we add a -g to the producer string. */
20100 if (debug_info_level > DINFO_LEVEL_TERSE)
20101 strcat (producer, " -g");
20104 add_AT_string (die, DW_AT_producer, producer);
20106 /* If our producer is LTO try to figure out a common language to use
20107 from the global list of translation units. */
20108 if (strcmp (language_string, "GNU GIMPLE") == 0)
20112 const char *common_lang = NULL;
20114 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20116 if (!TRANSLATION_UNIT_LANGUAGE (t))
20119 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20120 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20122 else if (strncmp (common_lang, "GNU C", 5) == 0
20123 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20124 /* Mixing C and C++ is ok, use C++ in that case. */
20125 common_lang = "GNU C++";
20128 /* Fall back to C. */
20129 common_lang = NULL;
20135 language_string = common_lang;
20138 language = DW_LANG_C89;
20139 if (strcmp (language_string, "GNU C++") == 0)
20140 language = DW_LANG_C_plus_plus;
20141 else if (strcmp (language_string, "GNU F77") == 0)
20142 language = DW_LANG_Fortran77;
20143 else if (strcmp (language_string, "GNU Pascal") == 0)
20144 language = DW_LANG_Pascal83;
20145 else if (dwarf_version >= 3 || !dwarf_strict)
20147 if (strcmp (language_string, "GNU Ada") == 0)
20148 language = DW_LANG_Ada95;
20149 else if (strcmp (language_string, "GNU Fortran") == 0)
20150 language = DW_LANG_Fortran95;
20151 else if (strcmp (language_string, "GNU Java") == 0)
20152 language = DW_LANG_Java;
20153 else if (strcmp (language_string, "GNU Objective-C") == 0)
20154 language = DW_LANG_ObjC;
20155 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20156 language = DW_LANG_ObjC_plus_plus;
20159 add_AT_unsigned (die, DW_AT_language, language);
20163 case DW_LANG_Fortran77:
20164 case DW_LANG_Fortran90:
20165 case DW_LANG_Fortran95:
20166 /* Fortran has case insensitive identifiers and the front-end
20167 lowercases everything. */
20168 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20171 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20177 /* Generate the DIE for a base class. */
20180 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20182 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20184 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20185 add_data_member_location_attribute (die, binfo);
20187 if (BINFO_VIRTUAL_P (binfo))
20188 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20190 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20191 children, otherwise the default is DW_ACCESS_public. In DWARF2
20192 the default has always been DW_ACCESS_private. */
20193 if (access == access_public_node)
20195 if (dwarf_version == 2
20196 || context_die->die_tag == DW_TAG_class_type)
20197 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20199 else if (access == access_protected_node)
20200 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20201 else if (dwarf_version > 2
20202 && context_die->die_tag != DW_TAG_class_type)
20203 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20206 /* Generate a DIE for a class member. */
20209 gen_member_die (tree type, dw_die_ref context_die)
20212 tree binfo = TYPE_BINFO (type);
20215 /* If this is not an incomplete type, output descriptions of each of its
20216 members. Note that as we output the DIEs necessary to represent the
20217 members of this record or union type, we will also be trying to output
20218 DIEs to represent the *types* of those members. However the `type'
20219 function (above) will specifically avoid generating type DIEs for member
20220 types *within* the list of member DIEs for this (containing) type except
20221 for those types (of members) which are explicitly marked as also being
20222 members of this (containing) type themselves. The g++ front- end can
20223 force any given type to be treated as a member of some other (containing)
20224 type by setting the TYPE_CONTEXT of the given (member) type to point to
20225 the TREE node representing the appropriate (containing) type. */
20227 /* First output info about the base classes. */
20230 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20234 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20235 gen_inheritance_die (base,
20236 (accesses ? VEC_index (tree, accesses, i)
20237 : access_public_node), context_die);
20240 /* Now output info about the data members and type members. */
20241 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20243 /* If we thought we were generating minimal debug info for TYPE
20244 and then changed our minds, some of the member declarations
20245 may have already been defined. Don't define them again, but
20246 do put them in the right order. */
20248 child = lookup_decl_die (member);
20250 splice_child_die (context_die, child);
20252 gen_decl_die (member, NULL, context_die);
20255 /* Now output info about the function members (if any). */
20256 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20258 /* Don't include clones in the member list. */
20259 if (DECL_ABSTRACT_ORIGIN (member))
20262 child = lookup_decl_die (member);
20264 splice_child_die (context_die, child);
20266 gen_decl_die (member, NULL, context_die);
20270 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20271 is set, we pretend that the type was never defined, so we only get the
20272 member DIEs needed by later specification DIEs. */
20275 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20276 enum debug_info_usage usage)
20278 dw_die_ref type_die = lookup_type_die (type);
20279 dw_die_ref scope_die = 0;
20281 int complete = (TYPE_SIZE (type)
20282 && (! TYPE_STUB_DECL (type)
20283 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20284 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20285 complete = complete && should_emit_struct_debug (type, usage);
20287 if (type_die && ! complete)
20290 if (TYPE_CONTEXT (type) != NULL_TREE
20291 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20292 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20295 scope_die = scope_die_for (type, context_die);
20297 if (! type_die || (nested && is_cu_die (scope_die)))
20298 /* First occurrence of type or toplevel definition of nested class. */
20300 dw_die_ref old_die = type_die;
20302 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20303 ? record_type_tag (type) : DW_TAG_union_type,
20305 equate_type_number_to_die (type, type_die);
20307 add_AT_specification (type_die, old_die);
20309 add_name_attribute (type_die, type_tag (type));
20312 remove_AT (type_die, DW_AT_declaration);
20314 /* Generate child dies for template paramaters. */
20315 if (debug_info_level > DINFO_LEVEL_TERSE
20316 && COMPLETE_TYPE_P (type))
20317 schedule_generic_params_dies_gen (type);
20319 /* If this type has been completed, then give it a byte_size attribute and
20320 then give a list of members. */
20321 if (complete && !ns_decl)
20323 /* Prevent infinite recursion in cases where the type of some member of
20324 this type is expressed in terms of this type itself. */
20325 TREE_ASM_WRITTEN (type) = 1;
20326 add_byte_size_attribute (type_die, type);
20327 if (TYPE_STUB_DECL (type) != NULL_TREE)
20329 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20330 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20333 /* If the first reference to this type was as the return type of an
20334 inline function, then it may not have a parent. Fix this now. */
20335 if (type_die->die_parent == NULL)
20336 add_child_die (scope_die, type_die);
20338 push_decl_scope (type);
20339 gen_member_die (type, type_die);
20342 /* GNU extension: Record what type our vtable lives in. */
20343 if (TYPE_VFIELD (type))
20345 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20347 gen_type_die (vtype, context_die);
20348 add_AT_die_ref (type_die, DW_AT_containing_type,
20349 lookup_type_die (vtype));
20354 add_AT_flag (type_die, DW_AT_declaration, 1);
20356 /* We don't need to do this for function-local types. */
20357 if (TYPE_STUB_DECL (type)
20358 && ! decl_function_context (TYPE_STUB_DECL (type)))
20359 VEC_safe_push (tree, gc, incomplete_types, type);
20362 if (get_AT (type_die, DW_AT_name))
20363 add_pubtype (type, type_die);
20366 /* Generate a DIE for a subroutine _type_. */
20369 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20371 tree return_type = TREE_TYPE (type);
20372 dw_die_ref subr_die
20373 = new_die (DW_TAG_subroutine_type,
20374 scope_die_for (type, context_die), type);
20376 equate_type_number_to_die (type, subr_die);
20377 add_prototyped_attribute (subr_die, type);
20378 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20379 gen_formal_types_die (type, subr_die);
20381 if (get_AT (subr_die, DW_AT_name))
20382 add_pubtype (type, subr_die);
20385 /* Generate a DIE for a type definition. */
20388 gen_typedef_die (tree decl, dw_die_ref context_die)
20390 dw_die_ref type_die;
20393 if (TREE_ASM_WRITTEN (decl))
20396 TREE_ASM_WRITTEN (decl) = 1;
20397 type_die = new_die (DW_TAG_typedef, context_die, decl);
20398 origin = decl_ultimate_origin (decl);
20399 if (origin != NULL)
20400 add_abstract_origin_attribute (type_die, origin);
20405 add_name_and_src_coords_attributes (type_die, decl);
20406 if (DECL_ORIGINAL_TYPE (decl))
20408 type = DECL_ORIGINAL_TYPE (decl);
20410 gcc_assert (type != TREE_TYPE (decl));
20411 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20415 type = TREE_TYPE (decl);
20417 if (is_naming_typedef_decl (TYPE_NAME (type)))
20419 /* Here, we are in the case of decl being a typedef naming
20420 an anonymous type, e.g:
20421 typedef struct {...} foo;
20422 In that case TREE_TYPE (decl) is not a typedef variant
20423 type and TYPE_NAME of the anonymous type is set to the
20424 TYPE_DECL of the typedef. This construct is emitted by
20427 TYPE is the anonymous struct named by the typedef
20428 DECL. As we need the DW_AT_type attribute of the
20429 DW_TAG_typedef to point to the DIE of TYPE, let's
20430 generate that DIE right away. add_type_attribute
20431 called below will then pick (via lookup_type_die) that
20432 anonymous struct DIE. */
20433 if (!TREE_ASM_WRITTEN (type))
20434 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20436 /* This is a GNU Extension. We are adding a
20437 DW_AT_linkage_name attribute to the DIE of the
20438 anonymous struct TYPE. The value of that attribute
20439 is the name of the typedef decl naming the anonymous
20440 struct. This greatly eases the work of consumers of
20441 this debug info. */
20442 add_linkage_attr (lookup_type_die (type), decl);
20446 add_type_attribute (type_die, type, TREE_READONLY (decl),
20447 TREE_THIS_VOLATILE (decl), context_die);
20449 if (is_naming_typedef_decl (decl))
20450 /* We want that all subsequent calls to lookup_type_die with
20451 TYPE in argument yield the DW_TAG_typedef we have just
20453 equate_type_number_to_die (type, type_die);
20455 add_accessibility_attribute (type_die, decl);
20458 if (DECL_ABSTRACT (decl))
20459 equate_decl_number_to_die (decl, type_die);
20461 if (get_AT (type_die, DW_AT_name))
20462 add_pubtype (decl, type_die);
20465 /* Generate a DIE for a struct, class, enum or union type. */
20468 gen_tagged_type_die (tree type,
20469 dw_die_ref context_die,
20470 enum debug_info_usage usage)
20474 if (type == NULL_TREE
20475 || !is_tagged_type (type))
20478 /* If this is a nested type whose containing class hasn't been written
20479 out yet, writing it out will cover this one, too. This does not apply
20480 to instantiations of member class templates; they need to be added to
20481 the containing class as they are generated. FIXME: This hurts the
20482 idea of combining type decls from multiple TUs, since we can't predict
20483 what set of template instantiations we'll get. */
20484 if (TYPE_CONTEXT (type)
20485 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20486 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20488 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20490 if (TREE_ASM_WRITTEN (type))
20493 /* If that failed, attach ourselves to the stub. */
20494 push_decl_scope (TYPE_CONTEXT (type));
20495 context_die = lookup_type_die (TYPE_CONTEXT (type));
20498 else if (TYPE_CONTEXT (type) != NULL_TREE
20499 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20501 /* If this type is local to a function that hasn't been written
20502 out yet, use a NULL context for now; it will be fixed up in
20503 decls_for_scope. */
20504 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20505 /* A declaration DIE doesn't count; nested types need to go in the
20507 if (context_die && is_declaration_die (context_die))
20508 context_die = NULL;
20513 context_die = declare_in_namespace (type, context_die);
20517 if (TREE_CODE (type) == ENUMERAL_TYPE)
20519 /* This might have been written out by the call to
20520 declare_in_namespace. */
20521 if (!TREE_ASM_WRITTEN (type))
20522 gen_enumeration_type_die (type, context_die);
20525 gen_struct_or_union_type_die (type, context_die, usage);
20530 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20531 it up if it is ever completed. gen_*_type_die will set it for us
20532 when appropriate. */
20535 /* Generate a type description DIE. */
20538 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20539 enum debug_info_usage usage)
20541 struct array_descr_info info;
20543 if (type == NULL_TREE || type == error_mark_node)
20546 if (TYPE_NAME (type) != NULL_TREE
20547 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20548 && is_redundant_typedef (TYPE_NAME (type))
20549 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20550 /* The DECL of this type is a typedef we don't want to emit debug
20551 info for but we want debug info for its underlying typedef.
20552 This can happen for e.g, the injected-class-name of a C++
20554 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20556 /* If TYPE is a typedef type variant, let's generate debug info
20557 for the parent typedef which TYPE is a type of. */
20558 if (typedef_variant_p (type))
20560 if (TREE_ASM_WRITTEN (type))
20563 /* Prevent broken recursion; we can't hand off to the same type. */
20564 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20566 /* Use the DIE of the containing namespace as the parent DIE of
20567 the type description DIE we want to generate. */
20568 if (DECL_CONTEXT (TYPE_NAME (type))
20569 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20570 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20572 TREE_ASM_WRITTEN (type) = 1;
20574 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20578 /* If type is an anonymous tagged type named by a typedef, let's
20579 generate debug info for the typedef. */
20580 if (is_naming_typedef_decl (TYPE_NAME (type)))
20582 /* Use the DIE of the containing namespace as the parent DIE of
20583 the type description DIE we want to generate. */
20584 if (DECL_CONTEXT (TYPE_NAME (type))
20585 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20586 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20588 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20592 /* If this is an array type with hidden descriptor, handle it first. */
20593 if (!TREE_ASM_WRITTEN (type)
20594 && lang_hooks.types.get_array_descr_info
20595 && lang_hooks.types.get_array_descr_info (type, &info)
20596 && (dwarf_version >= 3 || !dwarf_strict))
20598 gen_descr_array_type_die (type, &info, context_die);
20599 TREE_ASM_WRITTEN (type) = 1;
20603 /* We are going to output a DIE to represent the unqualified version
20604 of this type (i.e. without any const or volatile qualifiers) so
20605 get the main variant (i.e. the unqualified version) of this type
20606 now. (Vectors are special because the debugging info is in the
20607 cloned type itself). */
20608 if (TREE_CODE (type) != VECTOR_TYPE)
20609 type = type_main_variant (type);
20611 if (TREE_ASM_WRITTEN (type))
20614 switch (TREE_CODE (type))
20620 case REFERENCE_TYPE:
20621 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20622 ensures that the gen_type_die recursion will terminate even if the
20623 type is recursive. Recursive types are possible in Ada. */
20624 /* ??? We could perhaps do this for all types before the switch
20626 TREE_ASM_WRITTEN (type) = 1;
20628 /* For these types, all that is required is that we output a DIE (or a
20629 set of DIEs) to represent the "basis" type. */
20630 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20631 DINFO_USAGE_IND_USE);
20635 /* This code is used for C++ pointer-to-data-member types.
20636 Output a description of the relevant class type. */
20637 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20638 DINFO_USAGE_IND_USE);
20640 /* Output a description of the type of the object pointed to. */
20641 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20642 DINFO_USAGE_IND_USE);
20644 /* Now output a DIE to represent this pointer-to-data-member type
20646 gen_ptr_to_mbr_type_die (type, context_die);
20649 case FUNCTION_TYPE:
20650 /* Force out return type (in case it wasn't forced out already). */
20651 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20652 DINFO_USAGE_DIR_USE);
20653 gen_subroutine_type_die (type, context_die);
20657 /* Force out return type (in case it wasn't forced out already). */
20658 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20659 DINFO_USAGE_DIR_USE);
20660 gen_subroutine_type_die (type, context_die);
20664 gen_array_type_die (type, context_die);
20668 gen_array_type_die (type, context_die);
20671 case ENUMERAL_TYPE:
20674 case QUAL_UNION_TYPE:
20675 gen_tagged_type_die (type, context_die, usage);
20681 case FIXED_POINT_TYPE:
20684 /* No DIEs needed for fundamental types. */
20689 /* Just use DW_TAG_unspecified_type. */
20691 dw_die_ref type_die = lookup_type_die (type);
20692 if (type_die == NULL)
20694 tree name = TYPE_NAME (type);
20695 if (TREE_CODE (name) == TYPE_DECL)
20696 name = DECL_NAME (name);
20697 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20698 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20699 equate_type_number_to_die (type, type_die);
20705 gcc_unreachable ();
20708 TREE_ASM_WRITTEN (type) = 1;
20712 gen_type_die (tree type, dw_die_ref context_die)
20714 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20717 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20718 things which are local to the given block. */
20721 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20723 int must_output_die = 0;
20726 /* Ignore blocks that are NULL. */
20727 if (stmt == NULL_TREE)
20730 inlined_func = inlined_function_outer_scope_p (stmt);
20732 /* If the block is one fragment of a non-contiguous block, do not
20733 process the variables, since they will have been done by the
20734 origin block. Do process subblocks. */
20735 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20739 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20740 gen_block_die (sub, context_die, depth + 1);
20745 /* Determine if we need to output any Dwarf DIEs at all to represent this
20748 /* The outer scopes for inlinings *must* always be represented. We
20749 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20750 must_output_die = 1;
20753 /* Determine if this block directly contains any "significant"
20754 local declarations which we will need to output DIEs for. */
20755 if (debug_info_level > DINFO_LEVEL_TERSE)
20756 /* We are not in terse mode so *any* local declaration counts
20757 as being a "significant" one. */
20758 must_output_die = ((BLOCK_VARS (stmt) != NULL
20759 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20760 && (TREE_USED (stmt)
20761 || TREE_ASM_WRITTEN (stmt)
20762 || BLOCK_ABSTRACT (stmt)));
20763 else if ((TREE_USED (stmt)
20764 || TREE_ASM_WRITTEN (stmt)
20765 || BLOCK_ABSTRACT (stmt))
20766 && !dwarf2out_ignore_block (stmt))
20767 must_output_die = 1;
20770 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20771 DIE for any block which contains no significant local declarations at
20772 all. Rather, in such cases we just call `decls_for_scope' so that any
20773 needed Dwarf info for any sub-blocks will get properly generated. Note
20774 that in terse mode, our definition of what constitutes a "significant"
20775 local declaration gets restricted to include only inlined function
20776 instances and local (nested) function definitions. */
20777 if (must_output_die)
20781 /* If STMT block is abstract, that means we have been called
20782 indirectly from dwarf2out_abstract_function.
20783 That function rightfully marks the descendent blocks (of
20784 the abstract function it is dealing with) as being abstract,
20785 precisely to prevent us from emitting any
20786 DW_TAG_inlined_subroutine DIE as a descendent
20787 of an abstract function instance. So in that case, we should
20788 not call gen_inlined_subroutine_die.
20790 Later though, when cgraph asks dwarf2out to emit info
20791 for the concrete instance of the function decl into which
20792 the concrete instance of STMT got inlined, the later will lead
20793 to the generation of a DW_TAG_inlined_subroutine DIE. */
20794 if (! BLOCK_ABSTRACT (stmt))
20795 gen_inlined_subroutine_die (stmt, context_die, depth);
20798 gen_lexical_block_die (stmt, context_die, depth);
20801 decls_for_scope (stmt, context_die, depth);
20804 /* Process variable DECL (or variable with origin ORIGIN) within
20805 block STMT and add it to CONTEXT_DIE. */
20807 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20810 tree decl_or_origin = decl ? decl : origin;
20812 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20813 die = lookup_decl_die (decl_or_origin);
20814 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20815 && TYPE_DECL_IS_STUB (decl_or_origin))
20816 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20820 if (die != NULL && die->die_parent == NULL)
20821 add_child_die (context_die, die);
20822 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20823 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20824 stmt, context_die);
20826 gen_decl_die (decl, origin, context_die);
20829 /* Generate all of the decls declared within a given scope and (recursively)
20830 all of its sub-blocks. */
20833 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20839 /* Ignore NULL blocks. */
20840 if (stmt == NULL_TREE)
20843 /* Output the DIEs to represent all of the data objects and typedefs
20844 declared directly within this block but not within any nested
20845 sub-blocks. Also, nested function and tag DIEs have been
20846 generated with a parent of NULL; fix that up now. */
20847 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20848 process_scope_var (stmt, decl, NULL_TREE, context_die);
20849 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20850 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20853 /* If we're at -g1, we're not interested in subblocks. */
20854 if (debug_info_level <= DINFO_LEVEL_TERSE)
20857 /* Output the DIEs to represent all sub-blocks (and the items declared
20858 therein) of this block. */
20859 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20861 subblocks = BLOCK_CHAIN (subblocks))
20862 gen_block_die (subblocks, context_die, depth + 1);
20865 /* Is this a typedef we can avoid emitting? */
20868 is_redundant_typedef (const_tree decl)
20870 if (TYPE_DECL_IS_STUB (decl))
20873 if (DECL_ARTIFICIAL (decl)
20874 && DECL_CONTEXT (decl)
20875 && is_tagged_type (DECL_CONTEXT (decl))
20876 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20877 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20878 /* Also ignore the artificial member typedef for the class name. */
20884 /* Return TRUE if TYPE is a typedef that names a type for linkage
20885 purposes. This kind of typedefs is produced by the C++ FE for
20888 typedef struct {...} foo;
20890 In that case, there is no typedef variant type produced for foo.
20891 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20895 is_naming_typedef_decl (const_tree decl)
20897 if (decl == NULL_TREE
20898 || TREE_CODE (decl) != TYPE_DECL
20899 || !is_tagged_type (TREE_TYPE (decl))
20900 || DECL_IS_BUILTIN (decl)
20901 || is_redundant_typedef (decl)
20902 /* It looks like Ada produces TYPE_DECLs that are very similar
20903 to C++ naming typedefs but that have different
20904 semantics. Let's be specific to c++ for now. */
20908 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20909 && TYPE_NAME (TREE_TYPE (decl)) == decl
20910 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20911 != TYPE_NAME (TREE_TYPE (decl))));
20914 /* Returns the DIE for a context. */
20916 static inline dw_die_ref
20917 get_context_die (tree context)
20921 /* Find die that represents this context. */
20922 if (TYPE_P (context))
20924 context = TYPE_MAIN_VARIANT (context);
20925 return strip_naming_typedef (context, force_type_die (context));
20928 return force_decl_die (context);
20930 return comp_unit_die ();
20933 /* Returns the DIE for decl. A DIE will always be returned. */
20936 force_decl_die (tree decl)
20938 dw_die_ref decl_die;
20939 unsigned saved_external_flag;
20940 tree save_fn = NULL_TREE;
20941 decl_die = lookup_decl_die (decl);
20944 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20946 decl_die = lookup_decl_die (decl);
20950 switch (TREE_CODE (decl))
20952 case FUNCTION_DECL:
20953 /* Clear current_function_decl, so that gen_subprogram_die thinks
20954 that this is a declaration. At this point, we just want to force
20955 declaration die. */
20956 save_fn = current_function_decl;
20957 current_function_decl = NULL_TREE;
20958 gen_subprogram_die (decl, context_die);
20959 current_function_decl = save_fn;
20963 /* Set external flag to force declaration die. Restore it after
20964 gen_decl_die() call. */
20965 saved_external_flag = DECL_EXTERNAL (decl);
20966 DECL_EXTERNAL (decl) = 1;
20967 gen_decl_die (decl, NULL, context_die);
20968 DECL_EXTERNAL (decl) = saved_external_flag;
20971 case NAMESPACE_DECL:
20972 if (dwarf_version >= 3 || !dwarf_strict)
20973 dwarf2out_decl (decl);
20975 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20976 decl_die = comp_unit_die ();
20979 case TRANSLATION_UNIT_DECL:
20980 decl_die = comp_unit_die ();
20984 gcc_unreachable ();
20987 /* We should be able to find the DIE now. */
20989 decl_die = lookup_decl_die (decl);
20990 gcc_assert (decl_die);
20996 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20997 always returned. */
21000 force_type_die (tree type)
21002 dw_die_ref type_die;
21004 type_die = lookup_type_die (type);
21007 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21009 type_die = modified_type_die (type, TYPE_READONLY (type),
21010 TYPE_VOLATILE (type), context_die);
21011 gcc_assert (type_die);
21016 /* Force out any required namespaces to be able to output DECL,
21017 and return the new context_die for it, if it's changed. */
21020 setup_namespace_context (tree thing, dw_die_ref context_die)
21022 tree context = (DECL_P (thing)
21023 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21024 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21025 /* Force out the namespace. */
21026 context_die = force_decl_die (context);
21028 return context_die;
21031 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21032 type) within its namespace, if appropriate.
21034 For compatibility with older debuggers, namespace DIEs only contain
21035 declarations; all definitions are emitted at CU scope. */
21038 declare_in_namespace (tree thing, dw_die_ref context_die)
21040 dw_die_ref ns_context;
21042 if (debug_info_level <= DINFO_LEVEL_TERSE)
21043 return context_die;
21045 /* If this decl is from an inlined function, then don't try to emit it in its
21046 namespace, as we will get confused. It would have already been emitted
21047 when the abstract instance of the inline function was emitted anyways. */
21048 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21049 return context_die;
21051 ns_context = setup_namespace_context (thing, context_die);
21053 if (ns_context != context_die)
21057 if (DECL_P (thing))
21058 gen_decl_die (thing, NULL, ns_context);
21060 gen_type_die (thing, ns_context);
21062 return context_die;
21065 /* Generate a DIE for a namespace or namespace alias. */
21068 gen_namespace_die (tree decl, dw_die_ref context_die)
21070 dw_die_ref namespace_die;
21072 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21073 they are an alias of. */
21074 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21076 /* Output a real namespace or module. */
21077 context_die = setup_namespace_context (decl, comp_unit_die ());
21078 namespace_die = new_die (is_fortran ()
21079 ? DW_TAG_module : DW_TAG_namespace,
21080 context_die, decl);
21081 /* For Fortran modules defined in different CU don't add src coords. */
21082 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21084 const char *name = dwarf2_name (decl, 0);
21086 add_name_attribute (namespace_die, name);
21089 add_name_and_src_coords_attributes (namespace_die, decl);
21090 if (DECL_EXTERNAL (decl))
21091 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21092 equate_decl_number_to_die (decl, namespace_die);
21096 /* Output a namespace alias. */
21098 /* Force out the namespace we are an alias of, if necessary. */
21099 dw_die_ref origin_die
21100 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21102 if (DECL_FILE_SCOPE_P (decl)
21103 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21104 context_die = setup_namespace_context (decl, comp_unit_die ());
21105 /* Now create the namespace alias DIE. */
21106 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21107 add_name_and_src_coords_attributes (namespace_die, decl);
21108 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21109 equate_decl_number_to_die (decl, namespace_die);
21113 /* Generate Dwarf debug information for a decl described by DECL.
21114 The return value is currently only meaningful for PARM_DECLs,
21115 for all other decls it returns NULL. */
21118 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21120 tree decl_or_origin = decl ? decl : origin;
21121 tree class_origin = NULL, ultimate_origin;
21123 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21126 switch (TREE_CODE (decl_or_origin))
21132 if (!is_fortran () && !is_ada ())
21134 /* The individual enumerators of an enum type get output when we output
21135 the Dwarf representation of the relevant enum type itself. */
21139 /* Emit its type. */
21140 gen_type_die (TREE_TYPE (decl), context_die);
21142 /* And its containing namespace. */
21143 context_die = declare_in_namespace (decl, context_die);
21145 gen_const_die (decl, context_die);
21148 case FUNCTION_DECL:
21149 /* Don't output any DIEs to represent mere function declarations,
21150 unless they are class members or explicit block externs. */
21151 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21152 && DECL_FILE_SCOPE_P (decl_or_origin)
21153 && (current_function_decl == NULL_TREE
21154 || DECL_ARTIFICIAL (decl_or_origin)))
21159 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21160 on local redeclarations of global functions. That seems broken. */
21161 if (current_function_decl != decl)
21162 /* This is only a declaration. */;
21165 /* If we're emitting a clone, emit info for the abstract instance. */
21166 if (origin || DECL_ORIGIN (decl) != decl)
21167 dwarf2out_abstract_function (origin
21168 ? DECL_ORIGIN (origin)
21169 : DECL_ABSTRACT_ORIGIN (decl));
21171 /* If we're emitting an out-of-line copy of an inline function,
21172 emit info for the abstract instance and set up to refer to it. */
21173 else if (cgraph_function_possibly_inlined_p (decl)
21174 && ! DECL_ABSTRACT (decl)
21175 && ! class_or_namespace_scope_p (context_die)
21176 /* dwarf2out_abstract_function won't emit a die if this is just
21177 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21178 that case, because that works only if we have a die. */
21179 && DECL_INITIAL (decl) != NULL_TREE)
21181 dwarf2out_abstract_function (decl);
21182 set_decl_origin_self (decl);
21185 /* Otherwise we're emitting the primary DIE for this decl. */
21186 else if (debug_info_level > DINFO_LEVEL_TERSE)
21188 /* Before we describe the FUNCTION_DECL itself, make sure that we
21189 have its containing type. */
21191 origin = decl_class_context (decl);
21192 if (origin != NULL_TREE)
21193 gen_type_die (origin, context_die);
21195 /* And its return type. */
21196 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21198 /* And its virtual context. */
21199 if (DECL_VINDEX (decl) != NULL_TREE)
21200 gen_type_die (DECL_CONTEXT (decl), context_die);
21202 /* Make sure we have a member DIE for decl. */
21203 if (origin != NULL_TREE)
21204 gen_type_die_for_member (origin, decl, context_die);
21206 /* And its containing namespace. */
21207 context_die = declare_in_namespace (decl, context_die);
21210 /* Now output a DIE to represent the function itself. */
21212 gen_subprogram_die (decl, context_die);
21216 /* If we are in terse mode, don't generate any DIEs to represent any
21217 actual typedefs. */
21218 if (debug_info_level <= DINFO_LEVEL_TERSE)
21221 /* In the special case of a TYPE_DECL node representing the declaration
21222 of some type tag, if the given TYPE_DECL is marked as having been
21223 instantiated from some other (original) TYPE_DECL node (e.g. one which
21224 was generated within the original definition of an inline function) we
21225 used to generate a special (abbreviated) DW_TAG_structure_type,
21226 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21227 should be actually referencing those DIEs, as variable DIEs with that
21228 type would be emitted already in the abstract origin, so it was always
21229 removed during unused type prunning. Don't add anything in this
21231 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21234 if (is_redundant_typedef (decl))
21235 gen_type_die (TREE_TYPE (decl), context_die);
21237 /* Output a DIE to represent the typedef itself. */
21238 gen_typedef_die (decl, context_die);
21242 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21243 gen_label_die (decl, context_die);
21248 /* If we are in terse mode, don't generate any DIEs to represent any
21249 variable declarations or definitions. */
21250 if (debug_info_level <= DINFO_LEVEL_TERSE)
21253 /* Output any DIEs that are needed to specify the type of this data
21255 if (decl_by_reference_p (decl_or_origin))
21256 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21258 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21260 /* And its containing type. */
21261 class_origin = decl_class_context (decl_or_origin);
21262 if (class_origin != NULL_TREE)
21263 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21265 /* And its containing namespace. */
21266 context_die = declare_in_namespace (decl_or_origin, context_die);
21268 /* Now output the DIE to represent the data object itself. This gets
21269 complicated because of the possibility that the VAR_DECL really
21270 represents an inlined instance of a formal parameter for an inline
21272 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21273 if (ultimate_origin != NULL_TREE
21274 && TREE_CODE (ultimate_origin) == PARM_DECL)
21275 gen_formal_parameter_die (decl, origin,
21276 true /* Emit name attribute. */,
21279 gen_variable_die (decl, origin, context_die);
21283 /* Ignore the nameless fields that are used to skip bits but handle C++
21284 anonymous unions and structs. */
21285 if (DECL_NAME (decl) != NULL_TREE
21286 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21287 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21289 gen_type_die (member_declared_type (decl), context_die);
21290 gen_field_die (decl, context_die);
21295 if (DECL_BY_REFERENCE (decl_or_origin))
21296 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21298 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21299 return gen_formal_parameter_die (decl, origin,
21300 true /* Emit name attribute. */,
21303 case NAMESPACE_DECL:
21304 case IMPORTED_DECL:
21305 if (dwarf_version >= 3 || !dwarf_strict)
21306 gen_namespace_die (decl, context_die);
21310 /* Probably some frontend-internal decl. Assume we don't care. */
21311 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21318 /* Output debug information for global decl DECL. Called from toplev.c after
21319 compilation proper has finished. */
21322 dwarf2out_global_decl (tree decl)
21324 /* Output DWARF2 information for file-scope tentative data object
21325 declarations, file-scope (extern) function declarations (which
21326 had no corresponding body) and file-scope tagged type declarations
21327 and definitions which have not yet been forced out. */
21328 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21329 dwarf2out_decl (decl);
21332 /* Output debug information for type decl DECL. Called from toplev.c
21333 and from language front ends (to record built-in types). */
21335 dwarf2out_type_decl (tree decl, int local)
21338 dwarf2out_decl (decl);
21341 /* Output debug information for imported module or decl DECL.
21342 NAME is non-NULL name in the lexical block if the decl has been renamed.
21343 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21344 that DECL belongs to.
21345 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21347 dwarf2out_imported_module_or_decl_1 (tree decl,
21349 tree lexical_block,
21350 dw_die_ref lexical_block_die)
21352 expanded_location xloc;
21353 dw_die_ref imported_die = NULL;
21354 dw_die_ref at_import_die;
21356 if (TREE_CODE (decl) == IMPORTED_DECL)
21358 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21359 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21363 xloc = expand_location (input_location);
21365 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21367 at_import_die = force_type_die (TREE_TYPE (decl));
21368 /* For namespace N { typedef void T; } using N::T; base_type_die
21369 returns NULL, but DW_TAG_imported_declaration requires
21370 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21371 if (!at_import_die)
21373 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21374 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21375 at_import_die = lookup_type_die (TREE_TYPE (decl));
21376 gcc_assert (at_import_die);
21381 at_import_die = lookup_decl_die (decl);
21382 if (!at_import_die)
21384 /* If we're trying to avoid duplicate debug info, we may not have
21385 emitted the member decl for this field. Emit it now. */
21386 if (TREE_CODE (decl) == FIELD_DECL)
21388 tree type = DECL_CONTEXT (decl);
21390 if (TYPE_CONTEXT (type)
21391 && TYPE_P (TYPE_CONTEXT (type))
21392 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21393 DINFO_USAGE_DIR_USE))
21395 gen_type_die_for_member (type, decl,
21396 get_context_die (TYPE_CONTEXT (type)));
21398 at_import_die = force_decl_die (decl);
21402 if (TREE_CODE (decl) == NAMESPACE_DECL)
21404 if (dwarf_version >= 3 || !dwarf_strict)
21405 imported_die = new_die (DW_TAG_imported_module,
21412 imported_die = new_die (DW_TAG_imported_declaration,
21416 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21417 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21419 add_AT_string (imported_die, DW_AT_name,
21420 IDENTIFIER_POINTER (name));
21421 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21424 /* Output debug information for imported module or decl DECL.
21425 NAME is non-NULL name in context if the decl has been renamed.
21426 CHILD is true if decl is one of the renamed decls as part of
21427 importing whole module. */
21430 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21433 /* dw_die_ref at_import_die; */
21434 dw_die_ref scope_die;
21436 if (debug_info_level <= DINFO_LEVEL_TERSE)
21441 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21442 We need decl DIE for reference and scope die. First, get DIE for the decl
21445 /* Get the scope die for decl context. Use comp_unit_die for global module
21446 or decl. If die is not found for non globals, force new die. */
21448 && TYPE_P (context)
21449 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21452 if (!(dwarf_version >= 3 || !dwarf_strict))
21455 scope_die = get_context_die (context);
21459 gcc_assert (scope_die->die_child);
21460 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21461 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21462 scope_die = scope_die->die_child;
21465 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21466 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21470 /* Write the debugging output for DECL. */
21473 dwarf2out_decl (tree decl)
21475 dw_die_ref context_die = comp_unit_die ();
21477 switch (TREE_CODE (decl))
21482 case FUNCTION_DECL:
21483 /* What we would really like to do here is to filter out all mere
21484 file-scope declarations of file-scope functions which are never
21485 referenced later within this translation unit (and keep all of ones
21486 that *are* referenced later on) but we aren't clairvoyant, so we have
21487 no idea which functions will be referenced in the future (i.e. later
21488 on within the current translation unit). So here we just ignore all
21489 file-scope function declarations which are not also definitions. If
21490 and when the debugger needs to know something about these functions,
21491 it will have to hunt around and find the DWARF information associated
21492 with the definition of the function.
21494 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21495 nodes represent definitions and which ones represent mere
21496 declarations. We have to check DECL_INITIAL instead. That's because
21497 the C front-end supports some weird semantics for "extern inline"
21498 function definitions. These can get inlined within the current
21499 translation unit (and thus, we need to generate Dwarf info for their
21500 abstract instances so that the Dwarf info for the concrete inlined
21501 instances can have something to refer to) but the compiler never
21502 generates any out-of-lines instances of such things (despite the fact
21503 that they *are* definitions).
21505 The important point is that the C front-end marks these "extern
21506 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21507 them anyway. Note that the C++ front-end also plays some similar games
21508 for inline function definitions appearing within include files which
21509 also contain `#pragma interface' pragmas. */
21510 if (DECL_INITIAL (decl) == NULL_TREE)
21513 /* If we're a nested function, initially use a parent of NULL; if we're
21514 a plain function, this will be fixed up in decls_for_scope. If
21515 we're a method, it will be ignored, since we already have a DIE. */
21516 if (decl_function_context (decl)
21517 /* But if we're in terse mode, we don't care about scope. */
21518 && debug_info_level > DINFO_LEVEL_TERSE)
21519 context_die = NULL;
21523 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21524 declaration and if the declaration was never even referenced from
21525 within this entire compilation unit. We suppress these DIEs in
21526 order to save space in the .debug section (by eliminating entries
21527 which are probably useless). Note that we must not suppress
21528 block-local extern declarations (whether used or not) because that
21529 would screw-up the debugger's name lookup mechanism and cause it to
21530 miss things which really ought to be in scope at a given point. */
21531 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21534 /* For local statics lookup proper context die. */
21535 if (TREE_STATIC (decl) && decl_function_context (decl))
21536 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21538 /* If we are in terse mode, don't generate any DIEs to represent any
21539 variable declarations or definitions. */
21540 if (debug_info_level <= DINFO_LEVEL_TERSE)
21545 if (debug_info_level <= DINFO_LEVEL_TERSE)
21547 if (!is_fortran () && !is_ada ())
21549 if (TREE_STATIC (decl) && decl_function_context (decl))
21550 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21553 case NAMESPACE_DECL:
21554 case IMPORTED_DECL:
21555 if (debug_info_level <= DINFO_LEVEL_TERSE)
21557 if (lookup_decl_die (decl) != NULL)
21562 /* Don't emit stubs for types unless they are needed by other DIEs. */
21563 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21566 /* Don't bother trying to generate any DIEs to represent any of the
21567 normal built-in types for the language we are compiling. */
21568 if (DECL_IS_BUILTIN (decl))
21571 /* If we are in terse mode, don't generate any DIEs for types. */
21572 if (debug_info_level <= DINFO_LEVEL_TERSE)
21575 /* If we're a function-scope tag, initially use a parent of NULL;
21576 this will be fixed up in decls_for_scope. */
21577 if (decl_function_context (decl))
21578 context_die = NULL;
21586 gen_decl_die (decl, NULL, context_die);
21589 /* Write the debugging output for DECL. */
21592 dwarf2out_function_decl (tree decl)
21594 dwarf2out_decl (decl);
21595 call_arg_locations = NULL;
21596 call_arg_loc_last = NULL;
21597 call_site_count = -1;
21598 tail_call_site_count = -1;
21599 VEC_free (dw_die_ref, heap, block_map);
21600 htab_empty (decl_loc_table);
21601 htab_empty (cached_dw_loc_list_table);
21604 /* Output a marker (i.e. a label) for the beginning of the generated code for
21605 a lexical block. */
21608 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21609 unsigned int blocknum)
21611 switch_to_section (current_function_section ());
21612 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21615 /* Output a marker (i.e. a label) for the end of the generated code for a
21619 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21621 switch_to_section (current_function_section ());
21622 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21625 /* Returns nonzero if it is appropriate not to emit any debugging
21626 information for BLOCK, because it doesn't contain any instructions.
21628 Don't allow this for blocks with nested functions or local classes
21629 as we would end up with orphans, and in the presence of scheduling
21630 we may end up calling them anyway. */
21633 dwarf2out_ignore_block (const_tree block)
21638 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21639 if (TREE_CODE (decl) == FUNCTION_DECL
21640 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21642 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21644 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21645 if (TREE_CODE (decl) == FUNCTION_DECL
21646 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21653 /* Hash table routines for file_hash. */
21656 file_table_eq (const void *p1_p, const void *p2_p)
21658 const struct dwarf_file_data *const p1 =
21659 (const struct dwarf_file_data *) p1_p;
21660 const char *const p2 = (const char *) p2_p;
21661 return filename_cmp (p1->filename, p2) == 0;
21665 file_table_hash (const void *p_p)
21667 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21668 return htab_hash_string (p->filename);
21671 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21672 dwarf2out.c) and return its "index". The index of each (known) filename is
21673 just a unique number which is associated with only that one filename. We
21674 need such numbers for the sake of generating labels (in the .debug_sfnames
21675 section) and references to those files numbers (in the .debug_srcinfo
21676 and.debug_macinfo sections). If the filename given as an argument is not
21677 found in our current list, add it to the list and assign it the next
21678 available unique index number. In order to speed up searches, we remember
21679 the index of the filename was looked up last. This handles the majority of
21682 static struct dwarf_file_data *
21683 lookup_filename (const char *file_name)
21686 struct dwarf_file_data * created;
21688 /* Check to see if the file name that was searched on the previous
21689 call matches this file name. If so, return the index. */
21690 if (file_table_last_lookup
21691 && (file_name == file_table_last_lookup->filename
21692 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21693 return file_table_last_lookup;
21695 /* Didn't match the previous lookup, search the table. */
21696 slot = htab_find_slot_with_hash (file_table, file_name,
21697 htab_hash_string (file_name), INSERT);
21699 return (struct dwarf_file_data *) *slot;
21701 created = ggc_alloc_dwarf_file_data ();
21702 created->filename = file_name;
21703 created->emitted_number = 0;
21708 /* If the assembler will construct the file table, then translate the compiler
21709 internal file table number into the assembler file table number, and emit
21710 a .file directive if we haven't already emitted one yet. The file table
21711 numbers are different because we prune debug info for unused variables and
21712 types, which may include filenames. */
21715 maybe_emit_file (struct dwarf_file_data * fd)
21717 if (! fd->emitted_number)
21719 if (last_emitted_file)
21720 fd->emitted_number = last_emitted_file->emitted_number + 1;
21722 fd->emitted_number = 1;
21723 last_emitted_file = fd;
21725 if (DWARF2_ASM_LINE_DEBUG_INFO)
21727 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21728 output_quoted_string (asm_out_file,
21729 remap_debug_filename (fd->filename));
21730 fputc ('\n', asm_out_file);
21734 return fd->emitted_number;
21737 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21738 That generation should happen after function debug info has been
21739 generated. The value of the attribute is the constant value of ARG. */
21742 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21744 die_arg_entry entry;
21749 if (!tmpl_value_parm_die_table)
21750 tmpl_value_parm_die_table
21751 = VEC_alloc (die_arg_entry, gc, 32);
21755 VEC_safe_push (die_arg_entry, gc,
21756 tmpl_value_parm_die_table,
21760 /* Return TRUE if T is an instance of generic type, FALSE
21764 generic_type_p (tree t)
21766 if (t == NULL_TREE || !TYPE_P (t))
21768 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21771 /* Schedule the generation of the generic parameter dies for the
21772 instance of generic type T. The proper generation itself is later
21773 done by gen_scheduled_generic_parms_dies. */
21776 schedule_generic_params_dies_gen (tree t)
21778 if (!generic_type_p (t))
21781 if (generic_type_instances == NULL)
21782 generic_type_instances = VEC_alloc (tree, gc, 256);
21784 VEC_safe_push (tree, gc, generic_type_instances, t);
21787 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21788 by append_entry_to_tmpl_value_parm_die_table. This function must
21789 be called after function DIEs have been generated. */
21792 gen_remaining_tmpl_value_param_die_attribute (void)
21794 if (tmpl_value_parm_die_table)
21799 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21800 tree_add_const_value_attribute (e->die, e->arg);
21804 /* Generate generic parameters DIEs for instances of generic types
21805 that have been previously scheduled by
21806 schedule_generic_params_dies_gen. This function must be called
21807 after all the types of the CU have been laid out. */
21810 gen_scheduled_generic_parms_dies (void)
21815 if (generic_type_instances == NULL)
21818 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21819 gen_generic_params_dies (t);
21823 /* Replace DW_AT_name for the decl with name. */
21826 dwarf2out_set_name (tree decl, tree name)
21832 die = TYPE_SYMTAB_DIE (decl);
21836 dname = dwarf2_name (name, 0);
21840 attr = get_AT (die, DW_AT_name);
21843 struct indirect_string_node *node;
21845 node = find_AT_string (dname);
21846 /* replace the string. */
21847 attr->dw_attr_val.v.val_str = node;
21851 add_name_attribute (die, dname);
21854 /* Called by the final INSN scan whenever we see a var location. We
21855 use it to drop labels in the right places, and throw the location in
21856 our lookup table. */
21859 dwarf2out_var_location (rtx loc_note)
21861 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21862 struct var_loc_node *newloc;
21864 static const char *last_label;
21865 static const char *last_postcall_label;
21866 static bool last_in_cold_section_p;
21870 if (!NOTE_P (loc_note))
21872 if (CALL_P (loc_note))
21875 if (SIBLING_CALL_P (loc_note))
21876 tail_call_site_count++;
21881 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
21882 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21885 next_real = next_real_insn (loc_note);
21887 /* If there are no instructions which would be affected by this note,
21888 don't do anything. */
21890 && next_real == NULL_RTX
21891 && !NOTE_DURING_CALL_P (loc_note))
21894 if (next_real == NULL_RTX)
21895 next_real = get_last_insn ();
21897 /* If there were any real insns between note we processed last time
21898 and this note (or if it is the first note), clear
21899 last_{,postcall_}label so that they are not reused this time. */
21900 if (last_var_location_insn == NULL_RTX
21901 || last_var_location_insn != next_real
21902 || last_in_cold_section_p != in_cold_section_p)
21905 last_postcall_label = NULL;
21910 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21911 newloc = add_var_loc_to_decl (decl, loc_note,
21912 NOTE_DURING_CALL_P (loc_note)
21913 ? last_postcall_label : last_label);
21914 if (newloc == NULL)
21923 /* If there were no real insns between note we processed last time
21924 and this note, use the label we emitted last time. Otherwise
21925 create a new label and emit it. */
21926 if (last_label == NULL)
21928 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21929 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21931 last_label = ggc_strdup (loclabel);
21936 struct call_arg_loc_node *ca_loc
21937 = ggc_alloc_cleared_call_arg_loc_node ();
21938 rtx prev = prev_real_insn (loc_note), x;
21939 ca_loc->call_arg_loc_note = loc_note;
21940 ca_loc->next = NULL;
21941 ca_loc->label = last_label;
21944 || (NONJUMP_INSN_P (prev)
21945 && GET_CODE (PATTERN (prev)) == SEQUENCE
21946 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
21947 if (!CALL_P (prev))
21948 prev = XVECEXP (PATTERN (prev), 0, 0);
21949 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
21950 x = PATTERN (prev);
21951 if (GET_CODE (x) == PARALLEL)
21952 x = XVECEXP (x, 0, 0);
21953 if (GET_CODE (x) == SET)
21955 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
21957 x = XEXP (XEXP (x, 0), 0);
21958 if (GET_CODE (x) == SYMBOL_REF
21959 && SYMBOL_REF_DECL (x)
21960 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
21961 ca_loc->symbol_ref = x;
21963 ca_loc->block = insn_scope (prev);
21964 if (call_arg_locations)
21965 call_arg_loc_last->next = ca_loc;
21967 call_arg_locations = ca_loc;
21968 call_arg_loc_last = ca_loc;
21970 else if (!NOTE_DURING_CALL_P (loc_note))
21971 newloc->label = last_label;
21974 if (!last_postcall_label)
21976 sprintf (loclabel, "%s-1", last_label);
21977 last_postcall_label = ggc_strdup (loclabel);
21979 newloc->label = last_postcall_label;
21982 last_var_location_insn = next_real;
21983 last_in_cold_section_p = in_cold_section_p;
21986 /* Note in one location list that text section has changed. */
21989 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
21991 var_loc_list *list = (var_loc_list *) *slot;
21993 list->last_before_switch
21994 = list->last->next ? list->last->next : list->last;
21998 /* Note in all location lists that text section has changed. */
22001 var_location_switch_text_section (void)
22003 if (decl_loc_table == NULL)
22006 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
22009 /* Create a new line number table. */
22011 static dw_line_info_table *
22012 new_line_info_table (void)
22014 dw_line_info_table *table;
22016 table = ggc_alloc_cleared_dw_line_info_table_struct ();
22017 table->file_num = 1;
22018 table->line_num = 1;
22019 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
22024 /* Lookup the "current" table into which we emit line info, so
22025 that we don't have to do it for every source line. */
22028 set_cur_line_info_table (section *sec)
22030 dw_line_info_table *table;
22032 if (sec == text_section)
22034 table = text_section_line_info;
22037 text_section_line_info = table = new_line_info_table ();
22038 table->end_label = text_end_label;
22041 else if (sec == cold_text_section)
22043 table = cold_text_section_line_info;
22046 cold_text_section_line_info = table = new_line_info_table ();
22047 table->end_label = cold_end_label;
22052 const char *end_label;
22054 if (flag_reorder_blocks_and_partition)
22056 if (in_cold_section_p)
22057 end_label = crtl->subsections.cold_section_end_label;
22059 end_label = crtl->subsections.hot_section_end_label;
22063 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22064 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
22065 current_function_funcdef_no);
22066 end_label = ggc_strdup (label);
22069 table = new_line_info_table ();
22070 table->end_label = end_label;
22072 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
22075 cur_line_info_table = table;
22079 /* We need to reset the locations at the beginning of each
22080 function. We can't do this in the end_function hook, because the
22081 declarations that use the locations won't have been output when
22082 that hook is called. Also compute have_multiple_function_sections here. */
22085 dwarf2out_begin_function (tree fun)
22087 section *sec = function_section (fun);
22089 if (sec != text_section)
22090 have_multiple_function_sections = true;
22092 if (flag_reorder_blocks_and_partition && !cold_text_section)
22094 gcc_assert (current_function_decl == fun);
22095 cold_text_section = unlikely_text_section ();
22096 switch_to_section (cold_text_section);
22097 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22098 switch_to_section (sec);
22101 dwarf2out_note_section_used ();
22102 call_site_count = 0;
22103 tail_call_site_count = 0;
22105 set_cur_line_info_table (sec);
22108 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22111 push_dw_line_info_entry (dw_line_info_table *table,
22112 enum dw_line_info_opcode opcode, unsigned int val)
22114 dw_line_info_entry e;
22117 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
22120 /* Output a label to mark the beginning of a source code line entry
22121 and record information relating to this source line, in
22122 'line_info_table' for later output of the .debug_line section. */
22123 /* ??? The discriminator parameter ought to be unsigned. */
22126 dwarf2out_source_line (unsigned int line, const char *filename,
22127 int discriminator, bool is_stmt)
22129 unsigned int file_num;
22130 dw_line_info_table *table;
22132 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
22135 switch_to_section (current_function_section ());
22137 /* If requested, emit something human-readable. */
22138 if (flag_debug_asm)
22139 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
22141 table = cur_line_info_table;
22142 file_num = maybe_emit_file (lookup_filename (filename));
22144 if (0 && file_num == table->file_num
22145 && line == table->line_num
22146 && discriminator == table->discrim_num
22147 && is_stmt == table->is_stmt)
22150 if (DWARF2_ASM_LINE_DEBUG_INFO)
22152 /* Emit the .loc directive understood by GNU as. */
22153 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22154 if (is_stmt != table->is_stmt)
22155 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22156 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22157 fprintf (asm_out_file, " discriminator %d", discriminator);
22158 fputc ('\n', asm_out_file);
22162 unsigned int label_num = ++line_info_label_num;
22164 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
22166 push_dw_line_info_entry (table, LI_set_address, label_num);
22167 if (file_num != table->file_num)
22168 push_dw_line_info_entry (table, LI_set_file, file_num);
22169 if (discriminator != table->discrim_num)
22170 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
22171 if (is_stmt != table->is_stmt)
22172 push_dw_line_info_entry (table, LI_negate_stmt, 0);
22173 push_dw_line_info_entry (table, LI_set_line, line);
22176 table->file_num = file_num;
22177 table->line_num = line;
22178 table->discrim_num = discriminator;
22179 table->is_stmt = is_stmt;
22180 table->in_use = true;
22183 /* Record the beginning of a new source file. */
22186 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22188 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22190 /* Record the beginning of the file for break_out_includes. */
22191 dw_die_ref bincl_die;
22193 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22194 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22197 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22200 e.code = DW_MACINFO_start_file;
22202 e.info = xstrdup (filename);
22203 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22207 /* Record the end of a source file. */
22210 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22212 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22213 /* Record the end of the file for break_out_includes. */
22214 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22216 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22219 e.code = DW_MACINFO_end_file;
22222 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22226 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22227 the tail part of the directive line, i.e. the part which is past the
22228 initial whitespace, #, whitespace, directive-name, whitespace part. */
22231 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22232 const char *buffer ATTRIBUTE_UNUSED)
22234 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22237 e.code = DW_MACINFO_define;
22239 e.info = xstrdup (buffer);;
22240 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22244 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22245 the tail part of the directive line, i.e. the part which is past the
22246 initial whitespace, #, whitespace, directive-name, whitespace part. */
22249 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22250 const char *buffer ATTRIBUTE_UNUSED)
22252 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22255 e.code = DW_MACINFO_undef;
22257 e.info = xstrdup (buffer);;
22258 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22263 output_macinfo (void)
22266 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22267 macinfo_entry *ref;
22272 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22276 case DW_MACINFO_start_file:
22278 int file_num = maybe_emit_file (lookup_filename (ref->info));
22279 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22280 dw2_asm_output_data_uleb128
22281 (ref->lineno, "Included from line number %lu",
22282 (unsigned long)ref->lineno);
22283 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22286 case DW_MACINFO_end_file:
22287 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22289 case DW_MACINFO_define:
22290 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22291 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22292 (unsigned long)ref->lineno);
22293 dw2_asm_output_nstring (ref->info, -1, "The macro");
22295 case DW_MACINFO_undef:
22296 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22297 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22298 (unsigned long)ref->lineno);
22299 dw2_asm_output_nstring (ref->info, -1, "The macro");
22302 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22303 ASM_COMMENT_START, (unsigned long)ref->code);
22309 /* Set up for Dwarf output at the start of compilation. */
22312 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22314 /* Allocate the file_table. */
22315 file_table = htab_create_ggc (50, file_table_hash,
22316 file_table_eq, NULL);
22318 /* Allocate the decl_die_table. */
22319 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22320 decl_die_table_eq, NULL);
22322 /* Allocate the decl_loc_table. */
22323 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22324 decl_loc_table_eq, NULL);
22326 /* Allocate the cached_dw_loc_list_table. */
22327 cached_dw_loc_list_table
22328 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
22329 cached_dw_loc_list_table_eq, NULL);
22331 /* Allocate the initial hunk of the decl_scope_table. */
22332 decl_scope_table = VEC_alloc (tree, gc, 256);
22334 /* Allocate the initial hunk of the abbrev_die_table. */
22335 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22336 (ABBREV_DIE_TABLE_INCREMENT);
22337 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22338 /* Zero-th entry is allocated, but unused. */
22339 abbrev_die_table_in_use = 1;
22341 /* Allocate the pubtypes and pubnames vectors. */
22342 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22343 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22345 incomplete_types = VEC_alloc (tree, gc, 64);
22347 used_rtx_array = VEC_alloc (rtx, gc, 32);
22349 debug_info_section = get_section (DEBUG_INFO_SECTION,
22350 SECTION_DEBUG, NULL);
22351 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22352 SECTION_DEBUG, NULL);
22353 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22354 SECTION_DEBUG, NULL);
22355 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22356 SECTION_DEBUG, NULL);
22357 debug_line_section = get_section (DEBUG_LINE_SECTION,
22358 SECTION_DEBUG, NULL);
22359 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22360 SECTION_DEBUG, NULL);
22361 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22362 SECTION_DEBUG, NULL);
22363 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22364 SECTION_DEBUG, NULL);
22365 debug_str_section = get_section (DEBUG_STR_SECTION,
22366 DEBUG_STR_SECTION_FLAGS, NULL);
22367 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22368 SECTION_DEBUG, NULL);
22369 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22370 SECTION_DEBUG, NULL);
22372 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22373 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22374 DEBUG_ABBREV_SECTION_LABEL, 0);
22375 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22376 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22377 COLD_TEXT_SECTION_LABEL, 0);
22378 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22380 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22381 DEBUG_INFO_SECTION_LABEL, 0);
22382 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22383 DEBUG_LINE_SECTION_LABEL, 0);
22384 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22385 DEBUG_RANGES_SECTION_LABEL, 0);
22386 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22387 DEBUG_MACINFO_SECTION_LABEL, 0);
22389 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22390 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22392 switch_to_section (text_section);
22393 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22396 /* Called before cgraph_optimize starts outputtting functions, variables
22397 and toplevel asms into assembly. */
22400 dwarf2out_assembly_start (void)
22402 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22403 && dwarf2out_do_cfi_asm ()
22404 && (!(flag_unwind_tables || flag_exceptions)
22405 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22406 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22409 /* A helper function for dwarf2out_finish called through
22410 htab_traverse. Emit one queued .debug_str string. */
22413 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22415 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22417 if (node->label && node->refcount)
22419 switch_to_section (debug_str_section);
22420 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22421 assemble_string (node->str, strlen (node->str) + 1);
22427 #if ENABLE_ASSERT_CHECKING
22428 /* Verify that all marks are clear. */
22431 verify_marks_clear (dw_die_ref die)
22435 gcc_assert (! die->die_mark);
22436 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22438 #endif /* ENABLE_ASSERT_CHECKING */
22440 /* Clear the marks for a die and its children.
22441 Be cool if the mark isn't set. */
22444 prune_unmark_dies (dw_die_ref die)
22450 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22453 /* Given DIE that we're marking as used, find any other dies
22454 it references as attributes and mark them as used. */
22457 prune_unused_types_walk_attribs (dw_die_ref die)
22462 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22464 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22466 /* A reference to another DIE.
22467 Make sure that it will get emitted.
22468 If it was broken out into a comdat group, don't follow it. */
22469 if (! use_debug_types
22470 || a->dw_attr == DW_AT_specification
22471 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22472 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22474 /* Set the string's refcount to 0 so that prune_unused_types_mark
22475 accounts properly for it. */
22476 if (AT_class (a) == dw_val_class_str)
22477 a->dw_attr_val.v.val_str->refcount = 0;
22481 /* Mark the generic parameters and arguments children DIEs of DIE. */
22484 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22488 if (die == NULL || die->die_child == NULL)
22490 c = die->die_child;
22493 switch (c->die_tag)
22495 case DW_TAG_template_type_param:
22496 case DW_TAG_template_value_param:
22497 case DW_TAG_GNU_template_template_param:
22498 case DW_TAG_GNU_template_parameter_pack:
22499 prune_unused_types_mark (c, 1);
22505 } while (c && c != die->die_child);
22508 /* Mark DIE as being used. If DOKIDS is true, then walk down
22509 to DIE's children. */
22512 prune_unused_types_mark (dw_die_ref die, int dokids)
22516 if (die->die_mark == 0)
22518 /* We haven't done this node yet. Mark it as used. */
22520 /* If this is the DIE of a generic type instantiation,
22521 mark the children DIEs that describe its generic parms and
22523 prune_unused_types_mark_generic_parms_dies (die);
22525 /* We also have to mark its parents as used.
22526 (But we don't want to mark our parents' kids due to this.) */
22527 if (die->die_parent)
22528 prune_unused_types_mark (die->die_parent, 0);
22530 /* Mark any referenced nodes. */
22531 prune_unused_types_walk_attribs (die);
22533 /* If this node is a specification,
22534 also mark the definition, if it exists. */
22535 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22536 prune_unused_types_mark (die->die_definition, 1);
22539 if (dokids && die->die_mark != 2)
22541 /* We need to walk the children, but haven't done so yet.
22542 Remember that we've walked the kids. */
22545 /* If this is an array type, we need to make sure our
22546 kids get marked, even if they're types. If we're
22547 breaking out types into comdat sections, do this
22548 for all type definitions. */
22549 if (die->die_tag == DW_TAG_array_type
22550 || (use_debug_types
22551 && is_type_die (die) && ! is_declaration_die (die)))
22552 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22554 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22558 /* For local classes, look if any static member functions were emitted
22559 and if so, mark them. */
22562 prune_unused_types_walk_local_classes (dw_die_ref die)
22566 if (die->die_mark == 2)
22569 switch (die->die_tag)
22571 case DW_TAG_structure_type:
22572 case DW_TAG_union_type:
22573 case DW_TAG_class_type:
22576 case DW_TAG_subprogram:
22577 if (!get_AT_flag (die, DW_AT_declaration)
22578 || die->die_definition != NULL)
22579 prune_unused_types_mark (die, 1);
22586 /* Mark children. */
22587 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22590 /* Walk the tree DIE and mark types that we actually use. */
22593 prune_unused_types_walk (dw_die_ref die)
22597 /* Don't do anything if this node is already marked and
22598 children have been marked as well. */
22599 if (die->die_mark == 2)
22602 switch (die->die_tag)
22604 case DW_TAG_structure_type:
22605 case DW_TAG_union_type:
22606 case DW_TAG_class_type:
22607 if (die->die_perennial_p)
22610 for (c = die->die_parent; c; c = c->die_parent)
22611 if (c->die_tag == DW_TAG_subprogram)
22614 /* Finding used static member functions inside of classes
22615 is needed just for local classes, because for other classes
22616 static member function DIEs with DW_AT_specification
22617 are emitted outside of the DW_TAG_*_type. If we ever change
22618 it, we'd need to call this even for non-local classes. */
22620 prune_unused_types_walk_local_classes (die);
22622 /* It's a type node --- don't mark it. */
22625 case DW_TAG_const_type:
22626 case DW_TAG_packed_type:
22627 case DW_TAG_pointer_type:
22628 case DW_TAG_reference_type:
22629 case DW_TAG_rvalue_reference_type:
22630 case DW_TAG_volatile_type:
22631 case DW_TAG_typedef:
22632 case DW_TAG_array_type:
22633 case DW_TAG_interface_type:
22634 case DW_TAG_friend:
22635 case DW_TAG_variant_part:
22636 case DW_TAG_enumeration_type:
22637 case DW_TAG_subroutine_type:
22638 case DW_TAG_string_type:
22639 case DW_TAG_set_type:
22640 case DW_TAG_subrange_type:
22641 case DW_TAG_ptr_to_member_type:
22642 case DW_TAG_file_type:
22643 if (die->die_perennial_p)
22646 /* It's a type node --- don't mark it. */
22650 /* Mark everything else. */
22654 if (die->die_mark == 0)
22658 /* Now, mark any dies referenced from here. */
22659 prune_unused_types_walk_attribs (die);
22664 /* Mark children. */
22665 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22668 /* Increment the string counts on strings referred to from DIE's
22672 prune_unused_types_update_strings (dw_die_ref die)
22677 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22678 if (AT_class (a) == dw_val_class_str)
22680 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22682 /* Avoid unnecessarily putting strings that are used less than
22683 twice in the hash table. */
22685 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22688 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22689 htab_hash_string (s->str),
22691 gcc_assert (*slot == NULL);
22697 /* Remove from the tree DIE any dies that aren't marked. */
22700 prune_unused_types_prune (dw_die_ref die)
22704 gcc_assert (die->die_mark);
22705 prune_unused_types_update_strings (die);
22707 if (! die->die_child)
22710 c = die->die_child;
22712 dw_die_ref prev = c;
22713 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22714 if (c == die->die_child)
22716 /* No marked children between 'prev' and the end of the list. */
22718 /* No marked children at all. */
22719 die->die_child = NULL;
22722 prev->die_sib = c->die_sib;
22723 die->die_child = prev;
22728 if (c != prev->die_sib)
22730 prune_unused_types_prune (c);
22731 } while (c != die->die_child);
22734 /* A helper function for dwarf2out_finish called through
22735 htab_traverse. Clear .debug_str strings that we haven't already
22736 decided to emit. */
22739 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22741 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22743 if (!node->label || !node->refcount)
22744 htab_clear_slot (debug_str_hash, h);
22749 /* Remove dies representing declarations that we never use. */
22752 prune_unused_types (void)
22755 limbo_die_node *node;
22756 comdat_type_node *ctnode;
22759 #if ENABLE_ASSERT_CHECKING
22760 /* All the marks should already be clear. */
22761 verify_marks_clear (comp_unit_die ());
22762 for (node = limbo_die_list; node; node = node->next)
22763 verify_marks_clear (node->die);
22764 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22765 verify_marks_clear (ctnode->root_die);
22766 #endif /* ENABLE_ASSERT_CHECKING */
22768 /* Mark types that are used in global variables. */
22769 premark_types_used_by_global_vars ();
22771 /* Set the mark on nodes that are actually used. */
22772 prune_unused_types_walk (comp_unit_die ());
22773 for (node = limbo_die_list; node; node = node->next)
22774 prune_unused_types_walk (node->die);
22775 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22777 prune_unused_types_walk (ctnode->root_die);
22778 prune_unused_types_mark (ctnode->type_die, 1);
22781 /* Also set the mark on nodes referenced from the
22783 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22784 prune_unused_types_mark (pub->die, 1);
22786 /* Get rid of nodes that aren't marked; and update the string counts. */
22787 if (debug_str_hash && debug_str_hash_forced)
22788 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22789 else if (debug_str_hash)
22790 htab_empty (debug_str_hash);
22791 prune_unused_types_prune (comp_unit_die ());
22792 for (node = limbo_die_list; node; node = node->next)
22793 prune_unused_types_prune (node->die);
22794 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22795 prune_unused_types_prune (ctnode->root_die);
22797 /* Leave the marks clear. */
22798 prune_unmark_dies (comp_unit_die ());
22799 for (node = limbo_die_list; node; node = node->next)
22800 prune_unmark_dies (node->die);
22801 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22802 prune_unmark_dies (ctnode->root_die);
22805 /* Set the parameter to true if there are any relative pathnames in
22808 file_table_relative_p (void ** slot, void *param)
22810 bool *p = (bool *) param;
22811 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22812 if (!IS_ABSOLUTE_PATH (d->filename))
22820 /* Routines to manipulate hash table of comdat type units. */
22823 htab_ct_hash (const void *of)
22826 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22828 memcpy (&h, type_node->signature, sizeof (h));
22833 htab_ct_eq (const void *of1, const void *of2)
22835 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22836 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22838 return (! memcmp (type_node_1->signature, type_node_2->signature,
22839 DWARF_TYPE_SIGNATURE_SIZE));
22842 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22843 to the location it would have been added, should we know its
22844 DECL_ASSEMBLER_NAME when we added other attributes. This will
22845 probably improve compactness of debug info, removing equivalent
22846 abbrevs, and hide any differences caused by deferring the
22847 computation of the assembler name, triggered by e.g. PCH. */
22850 move_linkage_attr (dw_die_ref die)
22852 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22853 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22855 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22856 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22860 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22862 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22866 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22868 VEC_pop (dw_attr_node, die->die_attr);
22869 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22873 /* Helper function for resolve_addr, attempt to resolve
22874 one CONST_STRING, return non-zero if not successful. Similarly verify that
22875 SYMBOL_REFs refer to variables emitted in the current CU. */
22878 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22882 if (GET_CODE (rtl) == CONST_STRING)
22884 size_t len = strlen (XSTR (rtl, 0)) + 1;
22885 tree t = build_string (len, XSTR (rtl, 0));
22886 tree tlen = build_int_cst (NULL_TREE, len - 1);
22888 = build_array_type (char_type_node, build_index_type (tlen));
22889 rtl = lookup_constant_def (t);
22890 if (!rtl || !MEM_P (rtl))
22892 rtl = XEXP (rtl, 0);
22893 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22898 if (GET_CODE (rtl) == SYMBOL_REF
22899 && SYMBOL_REF_DECL (rtl))
22901 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
22903 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
22906 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22910 if (GET_CODE (rtl) == CONST
22911 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22917 /* Helper function for resolve_addr, handle one location
22918 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22919 the location list couldn't be resolved. */
22922 resolve_addr_in_expr (dw_loc_descr_ref loc)
22924 for (; loc; loc = loc->dw_loc_next)
22925 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22926 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22927 || (loc->dw_loc_opc == DW_OP_implicit_value
22928 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22929 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22931 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22932 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22935 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22938 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22939 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22940 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22945 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22946 an address in .rodata section if the string literal is emitted there,
22947 or remove the containing location list or replace DW_AT_const_value
22948 with DW_AT_location and empty location expression, if it isn't found
22949 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22950 to something that has been emitted in the current CU. */
22953 resolve_addr (dw_die_ref die)
22957 dw_loc_list_ref *curr, *start, loc;
22960 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22961 switch (AT_class (a))
22963 case dw_val_class_loc_list:
22964 start = curr = AT_loc_list_ptr (a);
22967 /* The same list can be referenced more than once. See if we have
22968 already recorded the result from a previous pass. */
22970 *curr = loc->dw_loc_next;
22971 else if (!loc->resolved_addr)
22973 /* As things stand, we do not expect or allow one die to
22974 reference a suffix of another die's location list chain.
22975 References must be identical or completely separate.
22976 There is therefore no need to cache the result of this
22977 pass on any list other than the first; doing so
22978 would lead to unnecessary writes. */
22981 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
22982 if (!resolve_addr_in_expr ((*curr)->expr))
22984 dw_loc_list_ref next = (*curr)->dw_loc_next;
22985 if (next && (*curr)->ll_symbol)
22987 gcc_assert (!next->ll_symbol);
22988 next->ll_symbol = (*curr)->ll_symbol;
22993 curr = &(*curr)->dw_loc_next;
22996 loc->resolved_addr = 1;
23000 loc->dw_loc_next = *start;
23005 remove_AT (die, a->dw_attr);
23009 case dw_val_class_loc:
23010 if (!resolve_addr_in_expr (AT_loc (a)))
23012 remove_AT (die, a->dw_attr);
23016 case dw_val_class_addr:
23017 if (a->dw_attr == DW_AT_const_value
23018 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
23020 remove_AT (die, a->dw_attr);
23023 if (die->die_tag == DW_TAG_GNU_call_site
23024 && a->dw_attr == DW_AT_abstract_origin)
23026 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
23027 dw_die_ref tdie = lookup_decl_die (tdecl);
23028 if (tdie == NULL && DECL_EXTERNAL (tdecl))
23030 force_decl_die (tdecl);
23031 tdie = lookup_decl_die (tdecl);
23035 a->dw_attr_val.val_class = dw_val_class_die_ref;
23036 a->dw_attr_val.v.val_die_ref.die = tdie;
23037 a->dw_attr_val.v.val_die_ref.external = 0;
23041 remove_AT (die, a->dw_attr);
23050 FOR_EACH_CHILD (die, c, resolve_addr (c));
23053 /* Helper routines for optimize_location_lists.
23054 This pass tries to share identical local lists in .debug_loc
23057 /* Iteratively hash operands of LOC opcode. */
23059 static inline hashval_t
23060 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23062 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23063 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23065 switch (loc->dw_loc_opc)
23067 case DW_OP_const4u:
23068 case DW_OP_const8u:
23072 case DW_OP_const1u:
23073 case DW_OP_const1s:
23074 case DW_OP_const2u:
23075 case DW_OP_const2s:
23076 case DW_OP_const4s:
23077 case DW_OP_const8s:
23081 case DW_OP_plus_uconst:
23117 case DW_OP_deref_size:
23118 case DW_OP_xderef_size:
23119 hash = iterative_hash_object (val1->v.val_int, hash);
23126 gcc_assert (val1->val_class == dw_val_class_loc);
23127 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23128 hash = iterative_hash_object (offset, hash);
23131 case DW_OP_implicit_value:
23132 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23133 switch (val2->val_class)
23135 case dw_val_class_const:
23136 hash = iterative_hash_object (val2->v.val_int, hash);
23138 case dw_val_class_vec:
23140 unsigned int elt_size = val2->v.val_vec.elt_size;
23141 unsigned int len = val2->v.val_vec.length;
23143 hash = iterative_hash_object (elt_size, hash);
23144 hash = iterative_hash_object (len, hash);
23145 hash = iterative_hash (val2->v.val_vec.array,
23146 len * elt_size, hash);
23149 case dw_val_class_const_double:
23150 hash = iterative_hash_object (val2->v.val_double.low, hash);
23151 hash = iterative_hash_object (val2->v.val_double.high, hash);
23153 case dw_val_class_addr:
23154 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23157 gcc_unreachable ();
23161 case DW_OP_bit_piece:
23162 hash = iterative_hash_object (val1->v.val_int, hash);
23163 hash = iterative_hash_object (val2->v.val_int, hash);
23169 unsigned char dtprel = 0xd1;
23170 hash = iterative_hash_object (dtprel, hash);
23172 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23174 case DW_OP_GNU_implicit_pointer:
23175 hash = iterative_hash_object (val2->v.val_int, hash);
23177 case DW_OP_GNU_entry_value:
23178 hash = hash_loc_operands (val1->v.val_loc, hash);
23182 /* Other codes have no operands. */
23188 /* Iteratively hash the whole DWARF location expression LOC. */
23190 static inline hashval_t
23191 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23193 dw_loc_descr_ref l;
23194 bool sizes_computed = false;
23195 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23196 size_of_locs (loc);
23198 for (l = loc; l != NULL; l = l->dw_loc_next)
23200 enum dwarf_location_atom opc = l->dw_loc_opc;
23201 hash = iterative_hash_object (opc, hash);
23202 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23204 size_of_locs (loc);
23205 sizes_computed = true;
23207 hash = hash_loc_operands (l, hash);
23212 /* Compute hash of the whole location list LIST_HEAD. */
23215 hash_loc_list (dw_loc_list_ref list_head)
23217 dw_loc_list_ref curr = list_head;
23218 hashval_t hash = 0;
23220 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23222 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23223 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23225 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23227 hash = hash_locs (curr->expr, hash);
23229 list_head->hash = hash;
23232 /* Return true if X and Y opcodes have the same operands. */
23235 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23237 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23238 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23239 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23240 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23242 switch (x->dw_loc_opc)
23244 case DW_OP_const4u:
23245 case DW_OP_const8u:
23249 case DW_OP_const1u:
23250 case DW_OP_const1s:
23251 case DW_OP_const2u:
23252 case DW_OP_const2s:
23253 case DW_OP_const4s:
23254 case DW_OP_const8s:
23258 case DW_OP_plus_uconst:
23294 case DW_OP_deref_size:
23295 case DW_OP_xderef_size:
23296 return valx1->v.val_int == valy1->v.val_int;
23299 gcc_assert (valx1->val_class == dw_val_class_loc
23300 && valy1->val_class == dw_val_class_loc
23301 && x->dw_loc_addr == y->dw_loc_addr);
23302 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23303 case DW_OP_implicit_value:
23304 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23305 || valx2->val_class != valy2->val_class)
23307 switch (valx2->val_class)
23309 case dw_val_class_const:
23310 return valx2->v.val_int == valy2->v.val_int;
23311 case dw_val_class_vec:
23312 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23313 && valx2->v.val_vec.length == valy2->v.val_vec.length
23314 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23315 valx2->v.val_vec.elt_size
23316 * valx2->v.val_vec.length) == 0;
23317 case dw_val_class_const_double:
23318 return valx2->v.val_double.low == valy2->v.val_double.low
23319 && valx2->v.val_double.high == valy2->v.val_double.high;
23320 case dw_val_class_addr:
23321 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23323 gcc_unreachable ();
23326 case DW_OP_bit_piece:
23327 return valx1->v.val_int == valy1->v.val_int
23328 && valx2->v.val_int == valy2->v.val_int;
23331 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23332 case DW_OP_GNU_implicit_pointer:
23333 return valx1->val_class == dw_val_class_die_ref
23334 && valx1->val_class == valy1->val_class
23335 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23336 && valx2->v.val_int == valy2->v.val_int;
23337 case DW_OP_GNU_entry_value:
23338 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
23340 /* Other codes have no operands. */
23345 /* Return true if DWARF location expressions X and Y are the same. */
23348 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23350 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23351 if (x->dw_loc_opc != y->dw_loc_opc
23352 || x->dtprel != y->dtprel
23353 || !compare_loc_operands (x, y))
23355 return x == NULL && y == NULL;
23358 /* Return precomputed hash of location list X. */
23361 loc_list_hash (const void *x)
23363 return ((const struct dw_loc_list_struct *) x)->hash;
23366 /* Return 1 if location lists X and Y are the same. */
23369 loc_list_eq (const void *x, const void *y)
23371 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23372 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23375 if (a->hash != b->hash)
23377 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23378 if (strcmp (a->begin, b->begin) != 0
23379 || strcmp (a->end, b->end) != 0
23380 || (a->section == NULL) != (b->section == NULL)
23381 || (a->section && strcmp (a->section, b->section) != 0)
23382 || !compare_locs (a->expr, b->expr))
23384 return a == NULL && b == NULL;
23387 /* Recursively optimize location lists referenced from DIE
23388 children and share them whenever possible. */
23391 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23398 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23399 if (AT_class (a) == dw_val_class_loc_list)
23401 dw_loc_list_ref list = AT_loc_list (a);
23402 /* TODO: perform some optimizations here, before hashing
23403 it and storing into the hash table. */
23404 hash_loc_list (list);
23405 slot = htab_find_slot_with_hash (htab, list, list->hash,
23408 *slot = (void *) list;
23410 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23413 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23416 /* Optimize location lists referenced from DIE
23417 children and share them whenever possible. */
23420 optimize_location_lists (dw_die_ref die)
23422 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23423 optimize_location_lists_1 (die, htab);
23424 htab_delete (htab);
23427 /* Output stuff that dwarf requires at the end of every file,
23428 and generate the DWARF-2 debugging info. */
23431 dwarf2out_finish (const char *filename)
23433 limbo_die_node *node, *next_node;
23434 comdat_type_node *ctnode;
23435 htab_t comdat_type_table;
23438 gen_scheduled_generic_parms_dies ();
23439 gen_remaining_tmpl_value_param_die_attribute ();
23441 /* Add the name for the main input file now. We delayed this from
23442 dwarf2out_init to avoid complications with PCH. */
23443 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23444 if (!IS_ABSOLUTE_PATH (filename))
23445 add_comp_dir_attribute (comp_unit_die ());
23446 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23449 htab_traverse (file_table, file_table_relative_p, &p);
23451 add_comp_dir_attribute (comp_unit_die ());
23454 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23456 add_location_or_const_value_attribute (
23457 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23458 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23463 /* Traverse the limbo die list, and add parent/child links. The only
23464 dies without parents that should be here are concrete instances of
23465 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23466 For concrete instances, we can get the parent die from the abstract
23468 for (node = limbo_die_list; node; node = next_node)
23470 dw_die_ref die = node->die;
23471 next_node = node->next;
23473 if (die->die_parent == NULL)
23475 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23478 add_child_die (origin->die_parent, die);
23479 else if (is_cu_die (die))
23481 else if (seen_error ())
23482 /* It's OK to be confused by errors in the input. */
23483 add_child_die (comp_unit_die (), die);
23486 /* In certain situations, the lexical block containing a
23487 nested function can be optimized away, which results
23488 in the nested function die being orphaned. Likewise
23489 with the return type of that nested function. Force
23490 this to be a child of the containing function.
23492 It may happen that even the containing function got fully
23493 inlined and optimized out. In that case we are lost and
23494 assign the empty child. This should not be big issue as
23495 the function is likely unreachable too. */
23496 tree context = NULL_TREE;
23498 gcc_assert (node->created_for);
23500 if (DECL_P (node->created_for))
23501 context = DECL_CONTEXT (node->created_for);
23502 else if (TYPE_P (node->created_for))
23503 context = TYPE_CONTEXT (node->created_for);
23505 gcc_assert (context
23506 && (TREE_CODE (context) == FUNCTION_DECL
23507 || TREE_CODE (context) == NAMESPACE_DECL));
23509 origin = lookup_decl_die (context);
23511 add_child_die (origin, die);
23513 add_child_die (comp_unit_die (), die);
23518 limbo_die_list = NULL;
23520 resolve_addr (comp_unit_die ());
23522 for (node = deferred_asm_name; node; node = node->next)
23524 tree decl = node->created_for;
23525 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23527 add_linkage_attr (node->die, decl);
23528 move_linkage_attr (node->die);
23532 deferred_asm_name = NULL;
23534 /* Walk through the list of incomplete types again, trying once more to
23535 emit full debugging info for them. */
23536 retry_incomplete_types ();
23538 if (flag_eliminate_unused_debug_types)
23539 prune_unused_types ();
23541 /* Generate separate CUs for each of the include files we've seen.
23542 They will go into limbo_die_list. */
23543 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23544 break_out_includes (comp_unit_die ());
23546 /* Generate separate COMDAT sections for type DIEs. */
23547 if (use_debug_types)
23549 break_out_comdat_types (comp_unit_die ());
23551 /* Each new type_unit DIE was added to the limbo die list when created.
23552 Since these have all been added to comdat_type_list, clear the
23554 limbo_die_list = NULL;
23556 /* For each new comdat type unit, copy declarations for incomplete
23557 types to make the new unit self-contained (i.e., no direct
23558 references to the main compile unit). */
23559 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23560 copy_decls_for_unworthy_types (ctnode->root_die);
23561 copy_decls_for_unworthy_types (comp_unit_die ());
23563 /* In the process of copying declarations from one unit to another,
23564 we may have left some declarations behind that are no longer
23565 referenced. Prune them. */
23566 prune_unused_types ();
23569 /* Traverse the DIE's and add add sibling attributes to those DIE's
23570 that have children. */
23571 add_sibling_attributes (comp_unit_die ());
23572 for (node = limbo_die_list; node; node = node->next)
23573 add_sibling_attributes (node->die);
23574 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23575 add_sibling_attributes (ctnode->root_die);
23577 /* Output a terminator label for the .text section. */
23578 switch_to_section (text_section);
23579 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23580 if (cold_text_section)
23582 switch_to_section (cold_text_section);
23583 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23586 /* We can only use the low/high_pc attributes if all of the code was
23588 if (!have_multiple_function_sections
23589 || (dwarf_version < 3 && dwarf_strict))
23591 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23592 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23597 unsigned fde_idx = 0;
23598 bool range_list_added = false;
23600 /* We need to give .debug_loc and .debug_ranges an appropriate
23601 "base address". Use zero so that these addresses become
23602 absolute. Historically, we've emitted the unexpected
23603 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23604 Emit both to give time for other tools to adapt. */
23605 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23606 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23608 if (text_section_used)
23609 add_ranges_by_labels (comp_unit_die (), text_section_label,
23610 text_end_label, &range_list_added);
23611 if (cold_text_section_used)
23612 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23613 cold_end_label, &range_list_added);
23615 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23617 dw_fde_ref fde = &fde_table[fde_idx];
23619 if (!fde->in_std_section)
23620 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23621 fde->dw_fde_end, &range_list_added);
23622 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
23623 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
23624 fde->dw_fde_second_end, &range_list_added);
23627 if (range_list_added)
23631 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23632 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23633 debug_line_section_label);
23635 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23636 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23638 if (have_location_lists)
23639 optimize_location_lists (comp_unit_die ());
23641 /* Output all of the compilation units. We put the main one last so that
23642 the offsets are available to output_pubnames. */
23643 for (node = limbo_die_list; node; node = node->next)
23644 output_comp_unit (node->die, 0);
23646 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23647 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23649 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23651 /* Don't output duplicate types. */
23652 if (*slot != HTAB_EMPTY_ENTRY)
23655 /* Add a pointer to the line table for the main compilation unit
23656 so that the debugger can make sense of DW_AT_decl_file
23658 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23659 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23660 debug_line_section_label);
23662 output_comdat_type_unit (ctnode);
23665 htab_delete (comdat_type_table);
23667 /* Output the main compilation unit if non-empty or if .debug_macinfo
23668 will be emitted. */
23669 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23671 /* Output the abbreviation table. */
23672 switch_to_section (debug_abbrev_section);
23673 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23674 output_abbrev_section ();
23676 /* Output location list section if necessary. */
23677 if (have_location_lists)
23679 /* Output the location lists info. */
23680 switch_to_section (debug_loc_section);
23681 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23682 DEBUG_LOC_SECTION_LABEL, 0);
23683 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23684 output_location_lists (comp_unit_die ());
23687 /* Output public names table if necessary. */
23688 if (!VEC_empty (pubname_entry, pubname_table))
23690 gcc_assert (info_section_emitted);
23691 switch_to_section (debug_pubnames_section);
23692 output_pubnames (pubname_table);
23695 /* Output public types table if necessary. */
23696 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23697 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23698 simply won't look for the section. */
23699 if (!VEC_empty (pubname_entry, pubtype_table))
23701 bool empty = false;
23703 if (flag_eliminate_unused_debug_types)
23705 /* The pubtypes table might be emptied by pruning unused items. */
23709 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23710 if (p->die->die_offset != 0)
23718 gcc_assert (info_section_emitted);
23719 switch_to_section (debug_pubtypes_section);
23720 output_pubnames (pubtype_table);
23724 /* Output the address range information. We only put functions in the
23725 arange table, so don't write it out if we don't have any. */
23726 if (info_section_emitted)
23728 unsigned long aranges_length = size_of_aranges ();
23730 /* Empty .debug_aranges would contain just header and
23731 terminating 0,0. */
23733 != (unsigned long) (DWARF_ARANGES_HEADER_SIZE
23734 + 2 * DWARF2_ADDR_SIZE))
23736 switch_to_section (debug_aranges_section);
23737 output_aranges (aranges_length);
23741 /* Output ranges section if necessary. */
23742 if (ranges_table_in_use)
23744 switch_to_section (debug_ranges_section);
23745 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23749 /* Output the source line correspondence table. We must do this
23750 even if there is no line information. Otherwise, on an empty
23751 translation unit, we will generate a present, but empty,
23752 .debug_info section. IRIX 6.5 `nm' will then complain when
23753 examining the file. This is done late so that any filenames
23754 used by the debug_info section are marked as 'used'. */
23755 switch_to_section (debug_line_section);
23756 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23757 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23758 output_line_info ();
23760 /* Have to end the macro section. */
23761 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23763 switch_to_section (debug_macinfo_section);
23764 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23765 if (!VEC_empty (macinfo_entry, macinfo_table))
23767 dw2_asm_output_data (1, 0, "End compilation unit");
23770 /* If we emitted any DW_FORM_strp form attribute, output the string
23772 if (debug_str_hash)
23773 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23776 #include "gt-dwarf2out.h"