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_dcall_section;
232 static GTY(()) section *debug_vcall_section;
233 static GTY(()) section *debug_str_section;
234 static GTY(()) section *debug_ranges_section;
235 static GTY(()) section *debug_frame_section;
237 /* Personality decl of current unit. Used only when assembler does not support
239 static GTY(()) rtx current_unit_personality;
241 /* How to start an assembler comment. */
242 #ifndef ASM_COMMENT_START
243 #define ASM_COMMENT_START ";#"
246 typedef struct dw_cfi_struct *dw_cfi_ref;
247 typedef struct dw_fde_struct *dw_fde_ref;
248 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
250 /* Call frames are described using a sequence of Call Frame
251 Information instructions. The register number, offset
252 and address fields are provided as possible operands;
253 their use is selected by the opcode field. */
255 enum dw_cfi_oprnd_type {
257 dw_cfi_oprnd_reg_num,
263 typedef union GTY(()) dw_cfi_oprnd_struct {
264 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
265 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
266 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
267 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
271 typedef struct GTY(()) dw_cfi_struct {
272 dw_cfi_ref dw_cfi_next;
273 enum dwarf_call_frame_info dw_cfi_opc;
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
276 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
281 /* This is how we define the location of the CFA. We use to handle it
282 as REG + OFFSET all the time, but now it can be more complex.
283 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
284 Instead of passing around REG and OFFSET, we pass a copy
285 of this structure. */
286 typedef struct cfa_loc {
287 HOST_WIDE_INT offset;
288 HOST_WIDE_INT base_offset;
290 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
291 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
294 /* All call frame descriptions (FDE's) in the GCC generated DWARF
295 refer to a single Common Information Entry (CIE), defined at
296 the beginning of the .debug_frame section. This use of a single
297 CIE obviates the need to keep track of multiple CIE's
298 in the DWARF generation routines below. */
300 typedef struct GTY(()) dw_fde_struct {
302 const char *dw_fde_begin;
303 const char *dw_fde_current_label;
304 const char *dw_fde_end;
305 const char *dw_fde_vms_end_prologue;
306 const char *dw_fde_vms_begin_epilogue;
307 const char *dw_fde_hot_section_label;
308 const char *dw_fde_hot_section_end_label;
309 const char *dw_fde_unlikely_section_label;
310 const char *dw_fde_unlikely_section_end_label;
311 dw_cfi_ref dw_fde_cfi;
312 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
313 HOST_WIDE_INT stack_realignment;
314 unsigned funcdef_number;
315 /* Dynamic realign argument pointer register. */
316 unsigned int drap_reg;
317 /* Virtual dynamic realign argument pointer register. */
318 unsigned int vdrap_reg;
319 /* These 3 flags are copied from rtl_data in function.h. */
320 unsigned all_throwers_are_sibcalls : 1;
321 unsigned uses_eh_lsda : 1;
322 unsigned nothrow : 1;
323 /* Whether we did stack realign in this call frame. */
324 unsigned stack_realign : 1;
325 /* Whether dynamic realign argument pointer register has been saved. */
326 unsigned drap_reg_saved: 1;
327 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
328 unsigned in_std_section : 1;
329 /* True iff dw_fde_unlikely_section_label is in text_section or
330 cold_text_section. */
331 unsigned cold_in_std_section : 1;
332 /* True iff switched sections. */
333 unsigned dw_fde_switched_sections : 1;
334 /* True iff switching from cold to hot section. */
335 unsigned dw_fde_switched_cold_to_hot : 1;
339 /* Maximum size (in bytes) of an artificially generated label. */
340 #define MAX_ARTIFICIAL_LABEL_BYTES 30
342 /* The size of addresses as they appear in the Dwarf 2 data.
343 Some architectures use word addresses to refer to code locations,
344 but Dwarf 2 info always uses byte addresses. On such machines,
345 Dwarf 2 addresses need to be larger than the architecture's
347 #ifndef DWARF2_ADDR_SIZE
348 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
351 /* The size in bytes of a DWARF field indicating an offset or length
352 relative to a debug info section, specified to be 4 bytes in the
353 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
356 #ifndef DWARF_OFFSET_SIZE
357 #define DWARF_OFFSET_SIZE 4
360 /* The size in bytes of a DWARF 4 type signature. */
362 #ifndef DWARF_TYPE_SIGNATURE_SIZE
363 #define DWARF_TYPE_SIGNATURE_SIZE 8
366 /* According to the (draft) DWARF 3 specification, the initial length
367 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
368 bytes are 0xffffffff, followed by the length stored in the next 8
371 However, the SGI/MIPS ABI uses an initial length which is equal to
372 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
374 #ifndef DWARF_INITIAL_LENGTH_SIZE
375 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
378 /* Round SIZE up to the nearest BOUNDARY. */
379 #define DWARF_ROUND(SIZE,BOUNDARY) \
380 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
382 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
383 #ifndef DWARF_CIE_DATA_ALIGNMENT
384 #ifdef STACK_GROWS_DOWNWARD
385 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
387 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
391 /* CIE identifier. */
392 #if HOST_BITS_PER_WIDE_INT >= 64
393 #define DWARF_CIE_ID \
394 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
396 #define DWARF_CIE_ID DW_CIE_ID
399 /* A pointer to the base of a table that contains frame description
400 information for each routine. */
401 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
403 /* Number of elements currently allocated for fde_table. */
404 static GTY(()) unsigned fde_table_allocated;
406 /* Number of elements in fde_table currently in use. */
407 static GTY(()) unsigned fde_table_in_use;
409 /* Size (in elements) of increments by which we may expand the
411 #define FDE_TABLE_INCREMENT 256
413 /* Get the current fde_table entry we should use. */
415 static inline dw_fde_ref
418 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
421 /* A list of call frame insns for the CIE. */
422 static GTY(()) dw_cfi_ref cie_cfi_head;
424 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
425 attribute that accelerates the lookup of the FDE associated
426 with the subprogram. This variable holds the table index of the FDE
427 associated with the current function (body) definition. */
428 static unsigned current_funcdef_fde;
430 struct GTY(()) indirect_string_node {
432 unsigned int refcount;
433 enum dwarf_form form;
437 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
439 /* True if the compilation unit has location entries that reference
441 static GTY(()) bool debug_str_hash_forced = false;
443 static GTY(()) int dw2_string_counter;
444 static GTY(()) unsigned long dwarf2out_cfi_label_num;
446 /* True if the compilation unit places functions in more than one section. */
447 static GTY(()) bool have_multiple_function_sections = false;
449 /* Whether the default text and cold text sections have been used at all. */
451 static GTY(()) bool text_section_used = false;
452 static GTY(()) bool cold_text_section_used = false;
454 /* The default cold text section. */
455 static GTY(()) section *cold_text_section;
457 /* Forward declarations for functions defined in this file. */
459 static char *stripattributes (const char *);
460 static const char *dwarf_cfi_name (unsigned);
461 static dw_cfi_ref new_cfi (void);
462 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
463 static void add_fde_cfi (const char *, dw_cfi_ref);
464 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
465 static void lookup_cfa (dw_cfa_location *);
466 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
467 static void initial_return_save (rtx);
468 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
470 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
471 static void output_cfi_directive (dw_cfi_ref);
472 static void output_call_frame_info (int);
473 static void dwarf2out_note_section_used (void);
474 static bool clobbers_queued_reg_save (const_rtx);
475 static void dwarf2out_frame_debug_expr (rtx, const char *);
477 /* Support for complex CFA locations. */
478 static void output_cfa_loc (dw_cfi_ref, int);
479 static void output_cfa_loc_raw (dw_cfi_ref);
480 static void get_cfa_from_loc_descr (dw_cfa_location *,
481 struct dw_loc_descr_struct *);
482 static struct dw_loc_descr_struct *build_cfa_loc
483 (dw_cfa_location *, HOST_WIDE_INT);
484 static struct dw_loc_descr_struct *build_cfa_aligned_loc
485 (HOST_WIDE_INT, HOST_WIDE_INT);
486 static void def_cfa_1 (const char *, dw_cfa_location *);
487 static struct dw_loc_descr_struct *mem_loc_descriptor
488 (rtx, enum machine_mode mode, enum var_init_status);
490 /* How to start an assembler comment. */
491 #ifndef ASM_COMMENT_START
492 #define ASM_COMMENT_START ";#"
495 /* Data and reference forms for relocatable data. */
496 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
497 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
499 #ifndef DEBUG_FRAME_SECTION
500 #define DEBUG_FRAME_SECTION ".debug_frame"
503 #ifndef FUNC_BEGIN_LABEL
504 #define FUNC_BEGIN_LABEL "LFB"
507 #ifndef FUNC_END_LABEL
508 #define FUNC_END_LABEL "LFE"
511 #ifndef PROLOGUE_END_LABEL
512 #define PROLOGUE_END_LABEL "LPE"
515 #ifndef EPILOGUE_BEGIN_LABEL
516 #define EPILOGUE_BEGIN_LABEL "LEB"
519 #ifndef FRAME_BEGIN_LABEL
520 #define FRAME_BEGIN_LABEL "Lframe"
522 #define CIE_AFTER_SIZE_LABEL "LSCIE"
523 #define CIE_END_LABEL "LECIE"
524 #define FDE_LABEL "LSFDE"
525 #define FDE_AFTER_SIZE_LABEL "LASFDE"
526 #define FDE_END_LABEL "LEFDE"
527 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
528 #define LINE_NUMBER_END_LABEL "LELT"
529 #define LN_PROLOG_AS_LABEL "LASLTP"
530 #define LN_PROLOG_END_LABEL "LELTP"
531 #define DIE_LABEL_PREFIX "DW"
533 /* The DWARF 2 CFA column which tracks the return address. Normally this
534 is the column for PC, or the first column after all of the hard
536 #ifndef DWARF_FRAME_RETURN_COLUMN
538 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
540 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
544 /* The mapping from gcc register number to DWARF 2 CFA column number. By
545 default, we just provide columns for all registers. */
546 #ifndef DWARF_FRAME_REGNUM
547 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
550 /* Match the base name of a file to the base name of a compilation unit. */
553 matches_main_base (const char *path)
555 /* Cache the last query. */
556 static const char *last_path = NULL;
557 static int last_match = 0;
558 if (path != last_path)
561 int length = base_of_path (path, &base);
563 last_match = (length == main_input_baselength
564 && memcmp (base, main_input_basename, length) == 0);
569 #ifdef DEBUG_DEBUG_STRUCT
572 dump_struct_debug (tree type, enum debug_info_usage usage,
573 enum debug_struct_file criterion, int generic,
574 int matches, int result)
576 /* Find the type name. */
577 tree type_decl = TYPE_STUB_DECL (type);
579 const char *name = 0;
580 if (TREE_CODE (t) == TYPE_DECL)
583 name = IDENTIFIER_POINTER (t);
585 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
587 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
588 matches ? "bas" : "hdr",
589 generic ? "gen" : "ord",
590 usage == DINFO_USAGE_DFN ? ";" :
591 usage == DINFO_USAGE_DIR_USE ? "." : "*",
593 (void*) type_decl, name);
596 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
597 dump_struct_debug (type, usage, criterion, generic, matches, result)
601 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
607 should_emit_struct_debug (tree type, enum debug_info_usage usage)
609 enum debug_struct_file criterion;
611 bool generic = lang_hooks.types.generic_p (type);
614 criterion = debug_struct_generic[usage];
616 criterion = debug_struct_ordinary[usage];
618 if (criterion == DINFO_STRUCT_FILE_NONE)
619 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
620 if (criterion == DINFO_STRUCT_FILE_ANY)
621 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
623 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
625 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
626 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
628 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
629 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
630 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
633 /* Hook used by __throw. */
636 expand_builtin_dwarf_sp_column (void)
638 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
639 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
642 /* Return a pointer to a copy of the section string name S with all
643 attributes stripped off, and an asterisk prepended (for assemble_name). */
646 stripattributes (const char *s)
648 char *stripped = XNEWVEC (char, strlen (s) + 2);
653 while (*s && *s != ',')
660 /* MEM is a memory reference for the register size table, each element of
661 which has mode MODE. Initialize column C as a return address column. */
664 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
666 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
667 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
668 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
671 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
673 static inline HOST_WIDE_INT
674 div_data_align (HOST_WIDE_INT off)
676 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
677 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
681 /* Return true if we need a signed version of a given opcode
682 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
685 need_data_align_sf_opcode (HOST_WIDE_INT off)
687 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
690 /* Generate code to initialize the register size table. */
693 expand_builtin_init_dwarf_reg_sizes (tree address)
696 enum machine_mode mode = TYPE_MODE (char_type_node);
697 rtx addr = expand_normal (address);
698 rtx mem = gen_rtx_MEM (BLKmode, addr);
699 bool wrote_return_column = false;
701 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
703 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
705 if (rnum < DWARF_FRAME_REGISTERS)
707 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
708 enum machine_mode save_mode = reg_raw_mode[i];
711 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
712 save_mode = choose_hard_reg_mode (i, 1, true);
713 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
715 if (save_mode == VOIDmode)
717 wrote_return_column = true;
719 size = GET_MODE_SIZE (save_mode);
723 emit_move_insn (adjust_address (mem, mode, offset),
724 gen_int_mode (size, mode));
728 if (!wrote_return_column)
729 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
731 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
732 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
735 targetm.init_dwarf_reg_sizes_extra (address);
738 /* Convert a DWARF call frame info. operation to its string name */
741 dwarf_cfi_name (unsigned int cfi_opc)
745 case DW_CFA_advance_loc:
746 return "DW_CFA_advance_loc";
748 return "DW_CFA_offset";
750 return "DW_CFA_restore";
754 return "DW_CFA_set_loc";
755 case DW_CFA_advance_loc1:
756 return "DW_CFA_advance_loc1";
757 case DW_CFA_advance_loc2:
758 return "DW_CFA_advance_loc2";
759 case DW_CFA_advance_loc4:
760 return "DW_CFA_advance_loc4";
761 case DW_CFA_offset_extended:
762 return "DW_CFA_offset_extended";
763 case DW_CFA_restore_extended:
764 return "DW_CFA_restore_extended";
765 case DW_CFA_undefined:
766 return "DW_CFA_undefined";
767 case DW_CFA_same_value:
768 return "DW_CFA_same_value";
769 case DW_CFA_register:
770 return "DW_CFA_register";
771 case DW_CFA_remember_state:
772 return "DW_CFA_remember_state";
773 case DW_CFA_restore_state:
774 return "DW_CFA_restore_state";
776 return "DW_CFA_def_cfa";
777 case DW_CFA_def_cfa_register:
778 return "DW_CFA_def_cfa_register";
779 case DW_CFA_def_cfa_offset:
780 return "DW_CFA_def_cfa_offset";
783 case DW_CFA_def_cfa_expression:
784 return "DW_CFA_def_cfa_expression";
785 case DW_CFA_expression:
786 return "DW_CFA_expression";
787 case DW_CFA_offset_extended_sf:
788 return "DW_CFA_offset_extended_sf";
789 case DW_CFA_def_cfa_sf:
790 return "DW_CFA_def_cfa_sf";
791 case DW_CFA_def_cfa_offset_sf:
792 return "DW_CFA_def_cfa_offset_sf";
794 /* SGI/MIPS specific */
795 case DW_CFA_MIPS_advance_loc8:
796 return "DW_CFA_MIPS_advance_loc8";
799 case DW_CFA_GNU_window_save:
800 return "DW_CFA_GNU_window_save";
801 case DW_CFA_GNU_args_size:
802 return "DW_CFA_GNU_args_size";
803 case DW_CFA_GNU_negative_offset_extended:
804 return "DW_CFA_GNU_negative_offset_extended";
807 return "DW_CFA_<unknown>";
811 /* Return a pointer to a newly allocated Call Frame Instruction. */
813 static inline dw_cfi_ref
816 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
818 cfi->dw_cfi_next = NULL;
819 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
820 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
825 /* Add a Call Frame Instruction to list of instructions. */
828 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
831 dw_fde_ref fde = current_fde ();
833 /* When DRAP is used, CFA is defined with an expression. Redefine
834 CFA may lead to a different CFA value. */
835 /* ??? Of course, this heuristic fails when we're annotating epilogues,
836 because of course we'll always want to redefine the CFA back to the
837 stack pointer on the way out. Where should we move this check? */
838 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
839 switch (cfi->dw_cfi_opc)
841 case DW_CFA_def_cfa_register:
842 case DW_CFA_def_cfa_offset:
843 case DW_CFA_def_cfa_offset_sf:
845 case DW_CFA_def_cfa_sf:
852 /* Find the end of the chain. */
853 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
859 /* Generate a new label for the CFI info to refer to. FORCE is true
860 if a label needs to be output even when using .cfi_* directives. */
863 dwarf2out_cfi_label (bool force)
865 static char label[20];
867 if (!force && dwarf2out_do_cfi_asm ())
869 /* In this case, we will be emitting the asm directive instead of
870 the label, so just return a placeholder to keep the rest of the
872 strcpy (label, "<do not output>");
876 int num = dwarf2out_cfi_label_num++;
877 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
878 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
884 /* True if remember_state should be emitted before following CFI directive. */
885 static bool emit_cfa_remember;
887 /* True if any CFI directives were emitted at the current insn. */
888 static bool any_cfis_emitted;
890 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
891 or to the CIE if LABEL is NULL. */
894 add_fde_cfi (const char *label, dw_cfi_ref cfi)
896 dw_cfi_ref *list_head;
898 if (emit_cfa_remember)
900 dw_cfi_ref cfi_remember;
902 /* Emit the state save. */
903 emit_cfa_remember = false;
904 cfi_remember = new_cfi ();
905 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
906 add_fde_cfi (label, cfi_remember);
909 list_head = &cie_cfi_head;
911 if (dwarf2out_do_cfi_asm ())
915 dw_fde_ref fde = current_fde ();
917 gcc_assert (fde != NULL);
919 /* We still have to add the cfi to the list so that lookup_cfa
920 works later on. When -g2 and above we even need to force
921 emitting of CFI labels and add to list a DW_CFA_set_loc for
922 convert_cfa_to_fb_loc_list purposes. If we're generating
923 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
924 convert_cfa_to_fb_loc_list. */
925 if (dwarf_version == 2
926 && debug_info_level > DINFO_LEVEL_TERSE
927 && (write_symbols == DWARF2_DEBUG
928 || write_symbols == VMS_AND_DWARF2_DEBUG))
930 switch (cfi->dw_cfi_opc)
932 case DW_CFA_def_cfa_offset:
933 case DW_CFA_def_cfa_offset_sf:
934 case DW_CFA_def_cfa_register:
936 case DW_CFA_def_cfa_sf:
937 case DW_CFA_def_cfa_expression:
938 case DW_CFA_restore_state:
939 if (*label == 0 || strcmp (label, "<do not output>") == 0)
940 label = dwarf2out_cfi_label (true);
942 if (fde->dw_fde_current_label == NULL
943 || strcmp (label, fde->dw_fde_current_label) != 0)
947 label = xstrdup (label);
949 /* Set the location counter to the new label. */
951 /* It doesn't metter whether DW_CFA_set_loc
952 or DW_CFA_advance_loc4 is added here, those aren't
953 emitted into assembly, only looked up by
954 convert_cfa_to_fb_loc_list. */
955 xcfi->dw_cfi_opc = DW_CFA_set_loc;
956 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
957 add_cfi (&fde->dw_fde_cfi, xcfi);
958 fde->dw_fde_current_label = label;
966 output_cfi_directive (cfi);
968 list_head = &fde->dw_fde_cfi;
969 any_cfis_emitted = true;
971 /* ??? If this is a CFI for the CIE, we don't emit. This
972 assumes that the standard CIE contents that the assembler
973 uses matches the standard CIE contents that the compiler
974 uses. This is probably a bad assumption. I'm not quite
975 sure how to address this for now. */
979 dw_fde_ref fde = current_fde ();
981 gcc_assert (fde != NULL);
984 label = dwarf2out_cfi_label (false);
986 if (fde->dw_fde_current_label == NULL
987 || strcmp (label, fde->dw_fde_current_label) != 0)
991 label = xstrdup (label);
993 /* Set the location counter to the new label. */
995 /* If we have a current label, advance from there, otherwise
996 set the location directly using set_loc. */
997 xcfi->dw_cfi_opc = fde->dw_fde_current_label
998 ? DW_CFA_advance_loc4
1000 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
1001 add_cfi (&fde->dw_fde_cfi, xcfi);
1003 fde->dw_fde_current_label = label;
1006 list_head = &fde->dw_fde_cfi;
1007 any_cfis_emitted = true;
1010 add_cfi (list_head, cfi);
1013 /* Subroutine of lookup_cfa. */
1016 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1018 switch (cfi->dw_cfi_opc)
1020 case DW_CFA_def_cfa_offset:
1021 case DW_CFA_def_cfa_offset_sf:
1022 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1024 case DW_CFA_def_cfa_register:
1025 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1027 case DW_CFA_def_cfa:
1028 case DW_CFA_def_cfa_sf:
1029 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1030 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1032 case DW_CFA_def_cfa_expression:
1033 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1036 case DW_CFA_remember_state:
1037 gcc_assert (!remember->in_use);
1039 remember->in_use = 1;
1041 case DW_CFA_restore_state:
1042 gcc_assert (remember->in_use);
1044 remember->in_use = 0;
1052 /* Find the previous value for the CFA. */
1055 lookup_cfa (dw_cfa_location *loc)
1059 dw_cfa_location remember;
1061 memset (loc, 0, sizeof (*loc));
1062 loc->reg = INVALID_REGNUM;
1065 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1066 lookup_cfa_1 (cfi, loc, &remember);
1068 fde = current_fde ();
1070 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1071 lookup_cfa_1 (cfi, loc, &remember);
1074 /* The current rule for calculating the DWARF2 canonical frame address. */
1075 static dw_cfa_location cfa;
1077 /* The register used for saving registers to the stack, and its offset
1079 static dw_cfa_location cfa_store;
1081 /* The current save location around an epilogue. */
1082 static dw_cfa_location cfa_remember;
1084 /* The running total of the size of arguments pushed onto the stack. */
1085 static HOST_WIDE_INT args_size;
1087 /* The last args_size we actually output. */
1088 static HOST_WIDE_INT old_args_size;
1090 /* Entry point to update the canonical frame address (CFA).
1091 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1092 calculated from REG+OFFSET. */
1095 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1097 dw_cfa_location loc;
1099 loc.base_offset = 0;
1101 loc.offset = offset;
1102 def_cfa_1 (label, &loc);
1105 /* Determine if two dw_cfa_location structures define the same data. */
1108 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1110 return (loc1->reg == loc2->reg
1111 && loc1->offset == loc2->offset
1112 && loc1->indirect == loc2->indirect
1113 && (loc1->indirect == 0
1114 || loc1->base_offset == loc2->base_offset));
1117 /* This routine does the actual work. The CFA is now calculated from
1118 the dw_cfa_location structure. */
1121 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1124 dw_cfa_location old_cfa, loc;
1129 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1130 cfa_store.offset = loc.offset;
1132 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1133 lookup_cfa (&old_cfa);
1135 /* If nothing changed, no need to issue any call frame instructions. */
1136 if (cfa_equal_p (&loc, &old_cfa))
1141 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1143 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1144 the CFA register did not change but the offset did. The data
1145 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1146 in the assembler via the .cfi_def_cfa_offset directive. */
1148 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1150 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1151 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1154 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1155 else if (loc.offset == old_cfa.offset
1156 && old_cfa.reg != INVALID_REGNUM
1158 && !old_cfa.indirect)
1160 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1161 indicating the CFA register has changed to <register> but the
1162 offset has not changed. */
1163 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1164 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1168 else if (loc.indirect == 0)
1170 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1171 indicating the CFA register has changed to <register> with
1172 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1173 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1176 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1178 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1179 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1180 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1184 /* Construct a DW_CFA_def_cfa_expression instruction to
1185 calculate the CFA using a full location expression since no
1186 register-offset pair is available. */
1187 struct dw_loc_descr_struct *loc_list;
1189 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1190 loc_list = build_cfa_loc (&loc, 0);
1191 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1194 add_fde_cfi (label, cfi);
1197 /* Add the CFI for saving a register. REG is the CFA column number.
1198 LABEL is passed to add_fde_cfi.
1199 If SREG is -1, the register is saved at OFFSET from the CFA;
1200 otherwise it is saved in SREG. */
1203 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1205 dw_cfi_ref cfi = new_cfi ();
1206 dw_fde_ref fde = current_fde ();
1208 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1210 /* When stack is aligned, store REG using DW_CFA_expression with
1213 && fde->stack_realign
1214 && sreg == INVALID_REGNUM)
1216 cfi->dw_cfi_opc = DW_CFA_expression;
1217 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1218 cfi->dw_cfi_oprnd2.dw_cfi_loc
1219 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1221 else if (sreg == INVALID_REGNUM)
1223 if (need_data_align_sf_opcode (offset))
1224 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1225 else if (reg & ~0x3f)
1226 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1228 cfi->dw_cfi_opc = DW_CFA_offset;
1229 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1231 else if (sreg == reg)
1232 cfi->dw_cfi_opc = DW_CFA_same_value;
1235 cfi->dw_cfi_opc = DW_CFA_register;
1236 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1239 add_fde_cfi (label, cfi);
1242 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1243 This CFI tells the unwinder that it needs to restore the window registers
1244 from the previous frame's window save area.
1246 ??? Perhaps we should note in the CIE where windows are saved (instead of
1247 assuming 0(cfa)) and what registers are in the window. */
1250 dwarf2out_window_save (const char *label)
1252 dw_cfi_ref cfi = new_cfi ();
1254 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1255 add_fde_cfi (label, cfi);
1258 /* Entry point for saving a register to the stack. REG is the GCC register
1259 number. LABEL and OFFSET are passed to reg_save. */
1262 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1264 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1267 /* Entry point for saving the return address in the stack.
1268 LABEL and OFFSET are passed to reg_save. */
1271 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1273 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1276 /* Entry point for saving the return address in a register.
1277 LABEL and SREG are passed to reg_save. */
1280 dwarf2out_return_reg (const char *label, unsigned int sreg)
1282 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1285 /* Record the initial position of the return address. RTL is
1286 INCOMING_RETURN_ADDR_RTX. */
1289 initial_return_save (rtx rtl)
1291 unsigned int reg = INVALID_REGNUM;
1292 HOST_WIDE_INT offset = 0;
1294 switch (GET_CODE (rtl))
1297 /* RA is in a register. */
1298 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1302 /* RA is on the stack. */
1303 rtl = XEXP (rtl, 0);
1304 switch (GET_CODE (rtl))
1307 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1312 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1313 offset = INTVAL (XEXP (rtl, 1));
1317 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1318 offset = -INTVAL (XEXP (rtl, 1));
1328 /* The return address is at some offset from any value we can
1329 actually load. For instance, on the SPARC it is in %i7+8. Just
1330 ignore the offset for now; it doesn't matter for unwinding frames. */
1331 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1332 initial_return_save (XEXP (rtl, 0));
1339 if (reg != DWARF_FRAME_RETURN_COLUMN)
1340 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1343 /* Given a SET, calculate the amount of stack adjustment it
1346 static HOST_WIDE_INT
1347 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1348 HOST_WIDE_INT cur_offset)
1350 const_rtx src = SET_SRC (pattern);
1351 const_rtx dest = SET_DEST (pattern);
1352 HOST_WIDE_INT offset = 0;
1355 if (dest == stack_pointer_rtx)
1357 code = GET_CODE (src);
1359 /* Assume (set (reg sp) (reg whatever)) sets args_size
1361 if (code == REG && src != stack_pointer_rtx)
1363 offset = -cur_args_size;
1364 #ifndef STACK_GROWS_DOWNWARD
1367 return offset - cur_offset;
1370 if (! (code == PLUS || code == MINUS)
1371 || XEXP (src, 0) != stack_pointer_rtx
1372 || !CONST_INT_P (XEXP (src, 1)))
1375 /* (set (reg sp) (plus (reg sp) (const_int))) */
1376 offset = INTVAL (XEXP (src, 1));
1382 if (MEM_P (src) && !MEM_P (dest))
1386 /* (set (mem (pre_dec (reg sp))) (foo)) */
1387 src = XEXP (dest, 0);
1388 code = GET_CODE (src);
1394 if (XEXP (src, 0) == stack_pointer_rtx)
1396 rtx val = XEXP (XEXP (src, 1), 1);
1397 /* We handle only adjustments by constant amount. */
1398 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1399 && CONST_INT_P (val));
1400 offset = -INTVAL (val);
1407 if (XEXP (src, 0) == stack_pointer_rtx)
1409 offset = GET_MODE_SIZE (GET_MODE (dest));
1416 if (XEXP (src, 0) == stack_pointer_rtx)
1418 offset = -GET_MODE_SIZE (GET_MODE (dest));
1433 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1434 indexed by INSN_UID. */
1436 static HOST_WIDE_INT *barrier_args_size;
1438 /* Helper function for compute_barrier_args_size. Handle one insn. */
1440 static HOST_WIDE_INT
1441 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1442 VEC (rtx, heap) **next)
1444 HOST_WIDE_INT offset = 0;
1447 if (! RTX_FRAME_RELATED_P (insn))
1449 if (prologue_epilogue_contains (insn))
1451 else if (GET_CODE (PATTERN (insn)) == SET)
1452 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1453 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1454 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1456 /* There may be stack adjustments inside compound insns. Search
1458 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1459 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1460 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1461 cur_args_size, offset);
1466 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1470 expr = XEXP (expr, 0);
1471 if (GET_CODE (expr) == PARALLEL
1472 || GET_CODE (expr) == SEQUENCE)
1473 for (i = 1; i < XVECLEN (expr, 0); i++)
1475 rtx elem = XVECEXP (expr, 0, i);
1477 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1478 offset += stack_adjust_offset (elem, cur_args_size, offset);
1483 #ifndef STACK_GROWS_DOWNWARD
1487 cur_args_size += offset;
1488 if (cur_args_size < 0)
1493 rtx dest = JUMP_LABEL (insn);
1497 if (barrier_args_size [INSN_UID (dest)] < 0)
1499 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1500 VEC_safe_push (rtx, heap, *next, dest);
1505 return cur_args_size;
1508 /* Walk the whole function and compute args_size on BARRIERs. */
1511 compute_barrier_args_size (void)
1513 int max_uid = get_max_uid (), i;
1515 VEC (rtx, heap) *worklist, *next, *tmp;
1517 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1518 for (i = 0; i < max_uid; i++)
1519 barrier_args_size[i] = -1;
1521 worklist = VEC_alloc (rtx, heap, 20);
1522 next = VEC_alloc (rtx, heap, 20);
1523 insn = get_insns ();
1524 barrier_args_size[INSN_UID (insn)] = 0;
1525 VEC_quick_push (rtx, worklist, insn);
1528 while (!VEC_empty (rtx, worklist))
1530 rtx prev, body, first_insn;
1531 HOST_WIDE_INT cur_args_size;
1533 first_insn = insn = VEC_pop (rtx, worklist);
1534 cur_args_size = barrier_args_size[INSN_UID (insn)];
1535 prev = prev_nonnote_insn (insn);
1536 if (prev && BARRIER_P (prev))
1537 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1539 for (; insn; insn = NEXT_INSN (insn))
1541 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1543 if (BARRIER_P (insn))
1548 if (insn == first_insn)
1550 else if (barrier_args_size[INSN_UID (insn)] < 0)
1552 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1557 /* The insns starting with this label have been
1558 already scanned or are in the worklist. */
1563 body = PATTERN (insn);
1564 if (GET_CODE (body) == SEQUENCE)
1566 HOST_WIDE_INT dest_args_size = cur_args_size;
1567 for (i = 1; i < XVECLEN (body, 0); i++)
1568 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1569 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1571 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1572 dest_args_size, &next);
1575 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1576 cur_args_size, &next);
1578 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1579 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1580 dest_args_size, &next);
1583 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1584 cur_args_size, &next);
1588 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1592 if (VEC_empty (rtx, next))
1595 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1599 VEC_truncate (rtx, next, 0);
1602 VEC_free (rtx, heap, worklist);
1603 VEC_free (rtx, heap, next);
1606 /* Add a CFI to update the running total of the size of arguments
1607 pushed onto the stack. */
1610 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1614 if (size == old_args_size)
1617 old_args_size = size;
1620 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1621 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1622 add_fde_cfi (label, cfi);
1625 /* Record a stack adjustment of OFFSET bytes. */
1628 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1630 if (cfa.reg == STACK_POINTER_REGNUM)
1631 cfa.offset += offset;
1633 if (cfa_store.reg == STACK_POINTER_REGNUM)
1634 cfa_store.offset += offset;
1636 if (ACCUMULATE_OUTGOING_ARGS)
1639 #ifndef STACK_GROWS_DOWNWARD
1643 args_size += offset;
1647 def_cfa_1 (label, &cfa);
1648 if (flag_asynchronous_unwind_tables)
1649 dwarf2out_args_size (label, args_size);
1652 /* Check INSN to see if it looks like a push or a stack adjustment, and
1653 make a note of it if it does. EH uses this information to find out
1654 how much extra space it needs to pop off the stack. */
1657 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1659 HOST_WIDE_INT offset;
1663 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1664 with this function. Proper support would require all frame-related
1665 insns to be marked, and to be able to handle saving state around
1666 epilogues textually in the middle of the function. */
1667 if (prologue_epilogue_contains (insn))
1670 /* If INSN is an instruction from target of an annulled branch, the
1671 effects are for the target only and so current argument size
1672 shouldn't change at all. */
1674 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1675 && INSN_FROM_TARGET_P (insn))
1678 /* If only calls can throw, and we have a frame pointer,
1679 save up adjustments until we see the CALL_INSN. */
1680 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1682 if (CALL_P (insn) && !after_p)
1684 /* Extract the size of the args from the CALL rtx itself. */
1685 insn = PATTERN (insn);
1686 if (GET_CODE (insn) == PARALLEL)
1687 insn = XVECEXP (insn, 0, 0);
1688 if (GET_CODE (insn) == SET)
1689 insn = SET_SRC (insn);
1690 gcc_assert (GET_CODE (insn) == CALL);
1691 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1696 if (CALL_P (insn) && !after_p)
1698 if (!flag_asynchronous_unwind_tables)
1699 dwarf2out_args_size ("", args_size);
1702 else if (BARRIER_P (insn))
1704 /* Don't call compute_barrier_args_size () if the only
1705 BARRIER is at the end of function. */
1706 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1707 compute_barrier_args_size ();
1708 if (barrier_args_size == NULL)
1712 offset = barrier_args_size[INSN_UID (insn)];
1717 offset -= args_size;
1718 #ifndef STACK_GROWS_DOWNWARD
1722 else if (GET_CODE (PATTERN (insn)) == SET)
1723 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1724 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1725 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1727 /* There may be stack adjustments inside compound insns. Search
1729 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1730 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1731 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1740 label = dwarf2out_cfi_label (false);
1741 dwarf2out_stack_adjust (offset, label);
1744 /* We delay emitting a register save until either (a) we reach the end
1745 of the prologue or (b) the register is clobbered. This clusters
1746 register saves so that there are fewer pc advances. */
1748 struct GTY(()) queued_reg_save {
1749 struct queued_reg_save *next;
1751 HOST_WIDE_INT cfa_offset;
1755 static GTY(()) struct queued_reg_save *queued_reg_saves;
1757 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1758 struct GTY(()) reg_saved_in_data {
1763 /* A list of registers saved in other registers.
1764 The list intentionally has a small maximum capacity of 4; if your
1765 port needs more than that, you might consider implementing a
1766 more efficient data structure. */
1767 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1768 static GTY(()) size_t num_regs_saved_in_regs;
1770 static const char *last_reg_save_label;
1772 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1773 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1776 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1778 struct queued_reg_save *q;
1780 /* Duplicates waste space, but it's also necessary to remove them
1781 for correctness, since the queue gets output in reverse
1783 for (q = queued_reg_saves; q != NULL; q = q->next)
1784 if (REGNO (q->reg) == REGNO (reg))
1789 q = ggc_alloc_queued_reg_save ();
1790 q->next = queued_reg_saves;
1791 queued_reg_saves = q;
1795 q->cfa_offset = offset;
1796 q->saved_reg = sreg;
1798 last_reg_save_label = label;
1801 /* Output all the entries in QUEUED_REG_SAVES. */
1804 dwarf2out_flush_queued_reg_saves (void)
1806 struct queued_reg_save *q;
1808 for (q = queued_reg_saves; q; q = q->next)
1811 unsigned int reg, sreg;
1813 for (i = 0; i < num_regs_saved_in_regs; i++)
1814 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1816 if (q->saved_reg && i == num_regs_saved_in_regs)
1818 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1819 num_regs_saved_in_regs++;
1821 if (i != num_regs_saved_in_regs)
1823 regs_saved_in_regs[i].orig_reg = q->reg;
1824 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1827 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1829 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1831 sreg = INVALID_REGNUM;
1832 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1835 queued_reg_saves = NULL;
1836 last_reg_save_label = NULL;
1839 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1840 location for? Or, does it clobber a register which we've previously
1841 said that some other register is saved in, and for which we now
1842 have a new location for? */
1845 clobbers_queued_reg_save (const_rtx insn)
1847 struct queued_reg_save *q;
1849 for (q = queued_reg_saves; q; q = q->next)
1852 if (modified_in_p (q->reg, insn))
1854 for (i = 0; i < num_regs_saved_in_regs; i++)
1855 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1856 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1863 /* Entry point for saving the first register into the second. */
1866 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1869 unsigned int regno, sregno;
1871 for (i = 0; i < num_regs_saved_in_regs; i++)
1872 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1874 if (i == num_regs_saved_in_regs)
1876 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1877 num_regs_saved_in_regs++;
1879 regs_saved_in_regs[i].orig_reg = reg;
1880 regs_saved_in_regs[i].saved_in_reg = sreg;
1882 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1883 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1884 reg_save (label, regno, sregno, 0);
1887 /* What register, if any, is currently saved in REG? */
1890 reg_saved_in (rtx reg)
1892 unsigned int regn = REGNO (reg);
1894 struct queued_reg_save *q;
1896 for (q = queued_reg_saves; q; q = q->next)
1897 if (q->saved_reg && regn == REGNO (q->saved_reg))
1900 for (i = 0; i < num_regs_saved_in_regs; i++)
1901 if (regs_saved_in_regs[i].saved_in_reg
1902 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1903 return regs_saved_in_regs[i].orig_reg;
1909 /* A temporary register holding an integral value used in adjusting SP
1910 or setting up the store_reg. The "offset" field holds the integer
1911 value, not an offset. */
1912 static dw_cfa_location cfa_temp;
1914 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1917 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1919 memset (&cfa, 0, sizeof (cfa));
1921 switch (GET_CODE (pat))
1924 cfa.reg = REGNO (XEXP (pat, 0));
1925 cfa.offset = INTVAL (XEXP (pat, 1));
1929 cfa.reg = REGNO (pat);
1934 pat = XEXP (pat, 0);
1935 if (GET_CODE (pat) == PLUS)
1937 cfa.base_offset = INTVAL (XEXP (pat, 1));
1938 pat = XEXP (pat, 0);
1940 cfa.reg = REGNO (pat);
1944 /* Recurse and define an expression. */
1948 def_cfa_1 (label, &cfa);
1951 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1954 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1958 gcc_assert (GET_CODE (pat) == SET);
1959 dest = XEXP (pat, 0);
1960 src = XEXP (pat, 1);
1962 switch (GET_CODE (src))
1965 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1966 cfa.offset -= INTVAL (XEXP (src, 1));
1976 cfa.reg = REGNO (dest);
1977 gcc_assert (cfa.indirect == 0);
1979 def_cfa_1 (label, &cfa);
1982 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1985 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1987 HOST_WIDE_INT offset;
1988 rtx src, addr, span;
1990 src = XEXP (set, 1);
1991 addr = XEXP (set, 0);
1992 gcc_assert (MEM_P (addr));
1993 addr = XEXP (addr, 0);
1995 /* As documented, only consider extremely simple addresses. */
1996 switch (GET_CODE (addr))
1999 gcc_assert (REGNO (addr) == cfa.reg);
2000 offset = -cfa.offset;
2003 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
2004 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2010 span = targetm.dwarf_register_span (src);
2012 /* ??? We'd like to use queue_reg_save, but we need to come up with
2013 a different flushing heuristic for epilogues. */
2015 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2018 /* We have a PARALLEL describing where the contents of SRC live.
2019 Queue register saves for each piece of the PARALLEL. */
2022 HOST_WIDE_INT span_offset = offset;
2024 gcc_assert (GET_CODE (span) == PARALLEL);
2026 limit = XVECLEN (span, 0);
2027 for (par_index = 0; par_index < limit; par_index++)
2029 rtx elem = XVECEXP (span, 0, par_index);
2031 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2032 INVALID_REGNUM, span_offset);
2033 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2038 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2041 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2044 unsigned sregno, dregno;
2046 src = XEXP (set, 1);
2047 dest = XEXP (set, 0);
2050 sregno = DWARF_FRAME_RETURN_COLUMN;
2052 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2054 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2056 /* ??? We'd like to use queue_reg_save, but we need to come up with
2057 a different flushing heuristic for epilogues. */
2058 reg_save (label, sregno, dregno, 0);
2061 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2064 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2066 rtx src, dest, span;
2067 dw_cfi_ref cfi = new_cfi ();
2069 dest = SET_DEST (set);
2070 src = SET_SRC (set);
2072 gcc_assert (REG_P (src));
2073 gcc_assert (MEM_P (dest));
2075 span = targetm.dwarf_register_span (src);
2078 cfi->dw_cfi_opc = DW_CFA_expression;
2079 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2080 cfi->dw_cfi_oprnd2.dw_cfi_loc
2081 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2082 VAR_INIT_STATUS_INITIALIZED);
2084 /* ??? We'd like to use queue_reg_save, were the interface different,
2085 and, as above, we could manage flushing for epilogues. */
2086 add_fde_cfi (label, cfi);
2089 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2092 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2094 dw_cfi_ref cfi = new_cfi ();
2095 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2097 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2098 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2100 add_fde_cfi (label, cfi);
2103 /* Record call frame debugging information for an expression EXPR,
2104 which either sets SP or FP (adjusting how we calculate the frame
2105 address) or saves a register to the stack or another register.
2106 LABEL indicates the address of EXPR.
2108 This function encodes a state machine mapping rtxes to actions on
2109 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2110 users need not read the source code.
2112 The High-Level Picture
2114 Changes in the register we use to calculate the CFA: Currently we
2115 assume that if you copy the CFA register into another register, we
2116 should take the other one as the new CFA register; this seems to
2117 work pretty well. If it's wrong for some target, it's simple
2118 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2120 Changes in the register we use for saving registers to the stack:
2121 This is usually SP, but not always. Again, we deduce that if you
2122 copy SP into another register (and SP is not the CFA register),
2123 then the new register is the one we will be using for register
2124 saves. This also seems to work.
2126 Register saves: There's not much guesswork about this one; if
2127 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2128 register save, and the register used to calculate the destination
2129 had better be the one we think we're using for this purpose.
2130 It's also assumed that a copy from a call-saved register to another
2131 register is saving that register if RTX_FRAME_RELATED_P is set on
2132 that instruction. If the copy is from a call-saved register to
2133 the *same* register, that means that the register is now the same
2134 value as in the caller.
2136 Except: If the register being saved is the CFA register, and the
2137 offset is nonzero, we are saving the CFA, so we assume we have to
2138 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2139 the intent is to save the value of SP from the previous frame.
2141 In addition, if a register has previously been saved to a different
2144 Invariants / Summaries of Rules
2146 cfa current rule for calculating the CFA. It usually
2147 consists of a register and an offset.
2148 cfa_store register used by prologue code to save things to the stack
2149 cfa_store.offset is the offset from the value of
2150 cfa_store.reg to the actual CFA
2151 cfa_temp register holding an integral value. cfa_temp.offset
2152 stores the value, which will be used to adjust the
2153 stack pointer. cfa_temp is also used like cfa_store,
2154 to track stores to the stack via fp or a temp reg.
2156 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2157 with cfa.reg as the first operand changes the cfa.reg and its
2158 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2161 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2162 expression yielding a constant. This sets cfa_temp.reg
2163 and cfa_temp.offset.
2165 Rule 5: Create a new register cfa_store used to save items to the
2168 Rules 10-14: Save a register to the stack. Define offset as the
2169 difference of the original location and cfa_store's
2170 location (or cfa_temp's location if cfa_temp is used).
2172 Rules 16-20: If AND operation happens on sp in prologue, we assume
2173 stack is realigned. We will use a group of DW_OP_XXX
2174 expressions to represent the location of the stored
2175 register instead of CFA+offset.
2179 "{a,b}" indicates a choice of a xor b.
2180 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2183 (set <reg1> <reg2>:cfa.reg)
2184 effects: cfa.reg = <reg1>
2185 cfa.offset unchanged
2186 cfa_temp.reg = <reg1>
2187 cfa_temp.offset = cfa.offset
2190 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2191 {<const_int>,<reg>:cfa_temp.reg}))
2192 effects: cfa.reg = sp if fp used
2193 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2194 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2195 if cfa_store.reg==sp
2198 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2199 effects: cfa.reg = fp
2200 cfa_offset += +/- <const_int>
2203 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2204 constraints: <reg1> != fp
2206 effects: cfa.reg = <reg1>
2207 cfa_temp.reg = <reg1>
2208 cfa_temp.offset = cfa.offset
2211 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2212 constraints: <reg1> != fp
2214 effects: cfa_store.reg = <reg1>
2215 cfa_store.offset = cfa.offset - cfa_temp.offset
2218 (set <reg> <const_int>)
2219 effects: cfa_temp.reg = <reg>
2220 cfa_temp.offset = <const_int>
2223 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2224 effects: cfa_temp.reg = <reg1>
2225 cfa_temp.offset |= <const_int>
2228 (set <reg> (high <exp>))
2232 (set <reg> (lo_sum <exp> <const_int>))
2233 effects: cfa_temp.reg = <reg>
2234 cfa_temp.offset = <const_int>
2237 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2238 effects: cfa_store.offset -= <const_int>
2239 cfa.offset = cfa_store.offset if cfa.reg == sp
2241 cfa.base_offset = -cfa_store.offset
2244 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2245 effects: cfa_store.offset += -/+ mode_size(mem)
2246 cfa.offset = cfa_store.offset if cfa.reg == sp
2248 cfa.base_offset = -cfa_store.offset
2251 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2254 effects: cfa.reg = <reg1>
2255 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2258 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2259 effects: cfa.reg = <reg1>
2260 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2263 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2264 effects: cfa.reg = <reg1>
2265 cfa.base_offset = -cfa_temp.offset
2266 cfa_temp.offset -= mode_size(mem)
2269 (set <reg> {unspec, unspec_volatile})
2270 effects: target-dependent
2273 (set sp (and: sp <const_int>))
2274 constraints: cfa_store.reg == sp
2275 effects: current_fde.stack_realign = 1
2276 cfa_store.offset = 0
2277 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2280 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2281 effects: cfa_store.offset += -/+ mode_size(mem)
2284 (set (mem ({pre_inc, pre_dec} sp)) fp)
2285 constraints: fde->stack_realign == 1
2286 effects: cfa_store.offset = 0
2287 cfa.reg != HARD_FRAME_POINTER_REGNUM
2290 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2291 constraints: fde->stack_realign == 1
2293 && cfa.indirect == 0
2294 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2295 effects: Use DW_CFA_def_cfa_expression to define cfa
2296 cfa.reg == fde->drap_reg */
2299 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2301 rtx src, dest, span;
2302 HOST_WIDE_INT offset;
2305 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2306 the PARALLEL independently. The first element is always processed if
2307 it is a SET. This is for backward compatibility. Other elements
2308 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2309 flag is set in them. */
2310 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2313 int limit = XVECLEN (expr, 0);
2316 /* PARALLELs have strict read-modify-write semantics, so we
2317 ought to evaluate every rvalue before changing any lvalue.
2318 It's cumbersome to do that in general, but there's an
2319 easy approximation that is enough for all current users:
2320 handle register saves before register assignments. */
2321 if (GET_CODE (expr) == PARALLEL)
2322 for (par_index = 0; par_index < limit; par_index++)
2324 elem = XVECEXP (expr, 0, par_index);
2325 if (GET_CODE (elem) == SET
2326 && MEM_P (SET_DEST (elem))
2327 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2328 dwarf2out_frame_debug_expr (elem, label);
2331 for (par_index = 0; par_index < limit; par_index++)
2333 elem = XVECEXP (expr, 0, par_index);
2334 if (GET_CODE (elem) == SET
2335 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2336 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2337 dwarf2out_frame_debug_expr (elem, label);
2338 else if (GET_CODE (elem) == SET
2340 && !RTX_FRAME_RELATED_P (elem))
2342 /* Stack adjustment combining might combine some post-prologue
2343 stack adjustment into a prologue stack adjustment. */
2344 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2347 dwarf2out_stack_adjust (offset, label);
2353 gcc_assert (GET_CODE (expr) == SET);
2355 src = SET_SRC (expr);
2356 dest = SET_DEST (expr);
2360 rtx rsi = reg_saved_in (src);
2365 fde = current_fde ();
2367 switch (GET_CODE (dest))
2370 switch (GET_CODE (src))
2372 /* Setting FP from SP. */
2374 if (cfa.reg == (unsigned) REGNO (src))
2377 /* Update the CFA rule wrt SP or FP. Make sure src is
2378 relative to the current CFA register.
2380 We used to require that dest be either SP or FP, but the
2381 ARM copies SP to a temporary register, and from there to
2382 FP. So we just rely on the backends to only set
2383 RTX_FRAME_RELATED_P on appropriate insns. */
2384 cfa.reg = REGNO (dest);
2385 cfa_temp.reg = cfa.reg;
2386 cfa_temp.offset = cfa.offset;
2390 /* Saving a register in a register. */
2391 gcc_assert (!fixed_regs [REGNO (dest)]
2392 /* For the SPARC and its register window. */
2393 || (DWARF_FRAME_REGNUM (REGNO (src))
2394 == DWARF_FRAME_RETURN_COLUMN));
2396 /* After stack is aligned, we can only save SP in FP
2397 if drap register is used. In this case, we have
2398 to restore stack pointer with the CFA value and we
2399 don't generate this DWARF information. */
2401 && fde->stack_realign
2402 && REGNO (src) == STACK_POINTER_REGNUM)
2403 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2404 && fde->drap_reg != INVALID_REGNUM
2405 && cfa.reg != REGNO (src));
2407 queue_reg_save (label, src, dest, 0);
2414 if (dest == stack_pointer_rtx)
2418 switch (GET_CODE (XEXP (src, 1)))
2421 offset = INTVAL (XEXP (src, 1));
2424 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2426 offset = cfa_temp.offset;
2432 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2434 /* Restoring SP from FP in the epilogue. */
2435 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2436 cfa.reg = STACK_POINTER_REGNUM;
2438 else if (GET_CODE (src) == LO_SUM)
2439 /* Assume we've set the source reg of the LO_SUM from sp. */
2442 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2444 if (GET_CODE (src) != MINUS)
2446 if (cfa.reg == STACK_POINTER_REGNUM)
2447 cfa.offset += offset;
2448 if (cfa_store.reg == STACK_POINTER_REGNUM)
2449 cfa_store.offset += offset;
2451 else if (dest == hard_frame_pointer_rtx)
2454 /* Either setting the FP from an offset of the SP,
2455 or adjusting the FP */
2456 gcc_assert (frame_pointer_needed);
2458 gcc_assert (REG_P (XEXP (src, 0))
2459 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2460 && CONST_INT_P (XEXP (src, 1)));
2461 offset = INTVAL (XEXP (src, 1));
2462 if (GET_CODE (src) != MINUS)
2464 cfa.offset += offset;
2465 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2469 gcc_assert (GET_CODE (src) != MINUS);
2472 if (REG_P (XEXP (src, 0))
2473 && REGNO (XEXP (src, 0)) == cfa.reg
2474 && CONST_INT_P (XEXP (src, 1)))
2476 /* Setting a temporary CFA register that will be copied
2477 into the FP later on. */
2478 offset = - INTVAL (XEXP (src, 1));
2479 cfa.offset += offset;
2480 cfa.reg = REGNO (dest);
2481 /* Or used to save regs to the stack. */
2482 cfa_temp.reg = cfa.reg;
2483 cfa_temp.offset = cfa.offset;
2487 else if (REG_P (XEXP (src, 0))
2488 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2489 && XEXP (src, 1) == stack_pointer_rtx)
2491 /* Setting a scratch register that we will use instead
2492 of SP for saving registers to the stack. */
2493 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2494 cfa_store.reg = REGNO (dest);
2495 cfa_store.offset = cfa.offset - cfa_temp.offset;
2499 else if (GET_CODE (src) == LO_SUM
2500 && CONST_INT_P (XEXP (src, 1)))
2502 cfa_temp.reg = REGNO (dest);
2503 cfa_temp.offset = INTVAL (XEXP (src, 1));
2512 cfa_temp.reg = REGNO (dest);
2513 cfa_temp.offset = INTVAL (src);
2518 gcc_assert (REG_P (XEXP (src, 0))
2519 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2520 && CONST_INT_P (XEXP (src, 1)));
2522 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2523 cfa_temp.reg = REGNO (dest);
2524 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2527 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2528 which will fill in all of the bits. */
2535 case UNSPEC_VOLATILE:
2536 gcc_assert (targetm.dwarf_handle_frame_unspec);
2537 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2542 /* If this AND operation happens on stack pointer in prologue,
2543 we assume the stack is realigned and we extract the
2545 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2547 /* We interpret reg_save differently with stack_realign set.
2548 Thus we must flush whatever we have queued first. */
2549 dwarf2out_flush_queued_reg_saves ();
2551 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2552 fde->stack_realign = 1;
2553 fde->stack_realignment = INTVAL (XEXP (src, 1));
2554 cfa_store.offset = 0;
2556 if (cfa.reg != STACK_POINTER_REGNUM
2557 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2558 fde->drap_reg = cfa.reg;
2566 def_cfa_1 (label, &cfa);
2571 /* Saving a register to the stack. Make sure dest is relative to the
2573 switch (GET_CODE (XEXP (dest, 0)))
2578 /* We can't handle variable size modifications. */
2579 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2581 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2583 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2584 && cfa_store.reg == STACK_POINTER_REGNUM);
2586 cfa_store.offset += offset;
2587 if (cfa.reg == STACK_POINTER_REGNUM)
2588 cfa.offset = cfa_store.offset;
2590 offset = -cfa_store.offset;
2596 offset = GET_MODE_SIZE (GET_MODE (dest));
2597 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2600 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2601 == STACK_POINTER_REGNUM)
2602 && cfa_store.reg == STACK_POINTER_REGNUM);
2604 cfa_store.offset += offset;
2606 /* Rule 18: If stack is aligned, we will use FP as a
2607 reference to represent the address of the stored
2610 && fde->stack_realign
2611 && src == hard_frame_pointer_rtx)
2613 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2614 cfa_store.offset = 0;
2617 if (cfa.reg == STACK_POINTER_REGNUM)
2618 cfa.offset = cfa_store.offset;
2620 offset = -cfa_store.offset;
2624 /* With an offset. */
2631 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2632 && REG_P (XEXP (XEXP (dest, 0), 0)));
2633 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2634 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2637 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2639 if (cfa.reg == (unsigned) regno)
2640 offset -= cfa.offset;
2641 else if (cfa_store.reg == (unsigned) regno)
2642 offset -= cfa_store.offset;
2645 gcc_assert (cfa_temp.reg == (unsigned) regno);
2646 offset -= cfa_temp.offset;
2652 /* Without an offset. */
2655 int regno = REGNO (XEXP (dest, 0));
2657 if (cfa.reg == (unsigned) regno)
2658 offset = -cfa.offset;
2659 else if (cfa_store.reg == (unsigned) regno)
2660 offset = -cfa_store.offset;
2663 gcc_assert (cfa_temp.reg == (unsigned) regno);
2664 offset = -cfa_temp.offset;
2671 gcc_assert (cfa_temp.reg
2672 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2673 offset = -cfa_temp.offset;
2674 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2682 /* If the source operand of this MEM operation is not a
2683 register, basically the source is return address. Here
2684 we only care how much stack grew and we don't save it. */
2688 if (REGNO (src) != STACK_POINTER_REGNUM
2689 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2690 && (unsigned) REGNO (src) == cfa.reg)
2692 /* We're storing the current CFA reg into the stack. */
2694 if (cfa.offset == 0)
2697 /* If stack is aligned, putting CFA reg into stack means
2698 we can no longer use reg + offset to represent CFA.
2699 Here we use DW_CFA_def_cfa_expression instead. The
2700 result of this expression equals to the original CFA
2703 && fde->stack_realign
2704 && cfa.indirect == 0
2705 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2707 dw_cfa_location cfa_exp;
2709 gcc_assert (fde->drap_reg == cfa.reg);
2711 cfa_exp.indirect = 1;
2712 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2713 cfa_exp.base_offset = offset;
2716 fde->drap_reg_saved = 1;
2718 def_cfa_1 (label, &cfa_exp);
2722 /* If the source register is exactly the CFA, assume
2723 we're saving SP like any other register; this happens
2725 def_cfa_1 (label, &cfa);
2726 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2731 /* Otherwise, we'll need to look in the stack to
2732 calculate the CFA. */
2733 rtx x = XEXP (dest, 0);
2737 gcc_assert (REG_P (x));
2739 cfa.reg = REGNO (x);
2740 cfa.base_offset = offset;
2742 def_cfa_1 (label, &cfa);
2747 def_cfa_1 (label, &cfa);
2749 span = targetm.dwarf_register_span (src);
2752 queue_reg_save (label, src, NULL_RTX, offset);
2755 /* We have a PARALLEL describing where the contents of SRC
2756 live. Queue register saves for each piece of the
2760 HOST_WIDE_INT span_offset = offset;
2762 gcc_assert (GET_CODE (span) == PARALLEL);
2764 limit = XVECLEN (span, 0);
2765 for (par_index = 0; par_index < limit; par_index++)
2767 rtx elem = XVECEXP (span, 0, par_index);
2769 queue_reg_save (label, elem, NULL_RTX, span_offset);
2770 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2781 /* Record call frame debugging information for INSN, which either
2782 sets SP or FP (adjusting how we calculate the frame address) or saves a
2783 register to the stack. If INSN is NULL_RTX, initialize our state.
2785 If AFTER_P is false, we're being called before the insn is emitted,
2786 otherwise after. Call instructions get invoked twice. */
2789 dwarf2out_frame_debug (rtx insn, bool after_p)
2793 bool handled_one = false;
2795 if (insn == NULL_RTX)
2799 /* Flush any queued register saves. */
2800 dwarf2out_flush_queued_reg_saves ();
2802 /* Set up state for generating call frame debug info. */
2805 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2807 cfa.reg = STACK_POINTER_REGNUM;
2810 cfa_temp.offset = 0;
2812 for (i = 0; i < num_regs_saved_in_regs; i++)
2814 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2815 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2817 num_regs_saved_in_regs = 0;
2819 if (barrier_args_size)
2821 XDELETEVEC (barrier_args_size);
2822 barrier_args_size = NULL;
2827 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2828 dwarf2out_flush_queued_reg_saves ();
2830 if (!RTX_FRAME_RELATED_P (insn))
2832 /* ??? This should be done unconditionally since stack adjustments
2833 matter if the stack pointer is not the CFA register anymore but
2834 is still used to save registers. */
2835 if (!ACCUMULATE_OUTGOING_ARGS)
2836 dwarf2out_notice_stack_adjust (insn, after_p);
2840 label = dwarf2out_cfi_label (false);
2841 any_cfis_emitted = false;
2843 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2844 switch (REG_NOTE_KIND (note))
2846 case REG_FRAME_RELATED_EXPR:
2847 insn = XEXP (note, 0);
2850 case REG_CFA_DEF_CFA:
2851 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2855 case REG_CFA_ADJUST_CFA:
2860 if (GET_CODE (n) == PARALLEL)
2861 n = XVECEXP (n, 0, 0);
2863 dwarf2out_frame_debug_adjust_cfa (n, label);
2867 case REG_CFA_OFFSET:
2870 n = single_set (insn);
2871 dwarf2out_frame_debug_cfa_offset (n, label);
2875 case REG_CFA_REGISTER:
2880 if (GET_CODE (n) == PARALLEL)
2881 n = XVECEXP (n, 0, 0);
2883 dwarf2out_frame_debug_cfa_register (n, label);
2887 case REG_CFA_EXPRESSION:
2890 n = single_set (insn);
2891 dwarf2out_frame_debug_cfa_expression (n, label);
2895 case REG_CFA_RESTORE:
2900 if (GET_CODE (n) == PARALLEL)
2901 n = XVECEXP (n, 0, 0);
2904 dwarf2out_frame_debug_cfa_restore (n, label);
2908 case REG_CFA_SET_VDRAP:
2912 dw_fde_ref fde = current_fde ();
2915 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2917 fde->vdrap_reg = REGNO (n);
2928 if (any_cfis_emitted)
2929 dwarf2out_flush_queued_reg_saves ();
2933 insn = PATTERN (insn);
2935 dwarf2out_frame_debug_expr (insn, label);
2937 /* Check again. A parallel can save and update the same register.
2938 We could probably check just once, here, but this is safer than
2939 removing the check above. */
2940 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2941 dwarf2out_flush_queued_reg_saves ();
2944 /* Determine if we need to save and restore CFI information around this
2945 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2946 we do need to save/restore, then emit the save now, and insert a
2947 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2950 dwarf2out_cfi_begin_epilogue (rtx insn)
2952 bool saw_frp = false;
2955 /* Scan forward to the return insn, noticing if there are possible
2956 frame related insns. */
2957 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2962 /* Look for both regular and sibcalls to end the block. */
2963 if (returnjump_p (i))
2965 if (CALL_P (i) && SIBLING_CALL_P (i))
2968 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2971 rtx seq = PATTERN (i);
2973 if (returnjump_p (XVECEXP (seq, 0, 0)))
2975 if (CALL_P (XVECEXP (seq, 0, 0))
2976 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2979 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2980 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2984 if (RTX_FRAME_RELATED_P (i))
2988 /* If the port doesn't emit epilogue unwind info, we don't need a
2989 save/restore pair. */
2993 /* Otherwise, search forward to see if the return insn was the last
2994 basic block of the function. If so, we don't need save/restore. */
2995 gcc_assert (i != NULL);
2996 i = next_real_insn (i);
3000 /* Insert the restore before that next real insn in the stream, and before
3001 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3002 properly nested. This should be after any label or alignment. This
3003 will be pushed into the CFI stream by the function below. */
3006 rtx p = PREV_INSN (i);
3009 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3013 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3015 emit_cfa_remember = true;
3017 /* And emulate the state save. */
3018 gcc_assert (!cfa_remember.in_use);
3020 cfa_remember.in_use = 1;
3023 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3027 dwarf2out_frame_debug_restore_state (void)
3029 dw_cfi_ref cfi = new_cfi ();
3030 const char *label = dwarf2out_cfi_label (false);
3032 cfi->dw_cfi_opc = DW_CFA_restore_state;
3033 add_fde_cfi (label, cfi);
3035 gcc_assert (cfa_remember.in_use);
3037 cfa_remember.in_use = 0;
3040 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3041 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3042 (enum dwarf_call_frame_info cfi);
3044 static enum dw_cfi_oprnd_type
3045 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3050 case DW_CFA_GNU_window_save:
3051 case DW_CFA_remember_state:
3052 case DW_CFA_restore_state:
3053 return dw_cfi_oprnd_unused;
3055 case DW_CFA_set_loc:
3056 case DW_CFA_advance_loc1:
3057 case DW_CFA_advance_loc2:
3058 case DW_CFA_advance_loc4:
3059 case DW_CFA_MIPS_advance_loc8:
3060 return dw_cfi_oprnd_addr;
3063 case DW_CFA_offset_extended:
3064 case DW_CFA_def_cfa:
3065 case DW_CFA_offset_extended_sf:
3066 case DW_CFA_def_cfa_sf:
3067 case DW_CFA_restore:
3068 case DW_CFA_restore_extended:
3069 case DW_CFA_undefined:
3070 case DW_CFA_same_value:
3071 case DW_CFA_def_cfa_register:
3072 case DW_CFA_register:
3073 case DW_CFA_expression:
3074 return dw_cfi_oprnd_reg_num;
3076 case DW_CFA_def_cfa_offset:
3077 case DW_CFA_GNU_args_size:
3078 case DW_CFA_def_cfa_offset_sf:
3079 return dw_cfi_oprnd_offset;
3081 case DW_CFA_def_cfa_expression:
3082 return dw_cfi_oprnd_loc;
3089 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3090 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3091 (enum dwarf_call_frame_info cfi);
3093 static enum dw_cfi_oprnd_type
3094 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3098 case DW_CFA_def_cfa:
3099 case DW_CFA_def_cfa_sf:
3101 case DW_CFA_offset_extended_sf:
3102 case DW_CFA_offset_extended:
3103 return dw_cfi_oprnd_offset;
3105 case DW_CFA_register:
3106 return dw_cfi_oprnd_reg_num;
3108 case DW_CFA_expression:
3109 return dw_cfi_oprnd_loc;
3112 return dw_cfi_oprnd_unused;
3116 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3117 switch to the data section instead, and write out a synthetic start label
3118 for collect2 the first time around. */
3121 switch_to_eh_frame_section (bool back)
3125 #ifdef EH_FRAME_SECTION_NAME
3126 if (eh_frame_section == 0)
3130 if (EH_TABLES_CAN_BE_READ_ONLY)
3136 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3138 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3140 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3142 flags = ((! flag_pic
3143 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3144 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3145 && (per_encoding & 0x70) != DW_EH_PE_absptr
3146 && (per_encoding & 0x70) != DW_EH_PE_aligned
3147 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3148 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3149 ? 0 : SECTION_WRITE);
3152 flags = SECTION_WRITE;
3153 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3155 #endif /* EH_FRAME_SECTION_NAME */
3157 if (eh_frame_section)
3158 switch_to_section (eh_frame_section);
3161 /* We have no special eh_frame section. Put the information in
3162 the data section and emit special labels to guide collect2. */
3163 switch_to_section (data_section);
3167 label = get_file_function_name ("F");
3168 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3169 targetm.asm_out.globalize_label (asm_out_file,
3170 IDENTIFIER_POINTER (label));
3171 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3176 /* Switch [BACK] to the eh or debug frame table section, depending on
3180 switch_to_frame_table_section (int for_eh, bool back)
3183 switch_to_eh_frame_section (back);
3186 if (!debug_frame_section)
3187 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3188 SECTION_DEBUG, NULL);
3189 switch_to_section (debug_frame_section);
3193 /* Output a Call Frame Information opcode and its operand(s). */
3196 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3201 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3202 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3203 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3204 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3205 ((unsigned HOST_WIDE_INT)
3206 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3207 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3209 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3210 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3211 "DW_CFA_offset, column %#lx", r);
3212 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3213 dw2_asm_output_data_uleb128 (off, NULL);
3215 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3217 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3218 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3219 "DW_CFA_restore, column %#lx", r);
3223 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3224 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3226 switch (cfi->dw_cfi_opc)
3228 case DW_CFA_set_loc:
3230 dw2_asm_output_encoded_addr_rtx (
3231 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3232 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3235 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3236 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3237 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3240 case DW_CFA_advance_loc1:
3241 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3242 fde->dw_fde_current_label, NULL);
3243 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3246 case DW_CFA_advance_loc2:
3247 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3248 fde->dw_fde_current_label, NULL);
3249 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3252 case DW_CFA_advance_loc4:
3253 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3254 fde->dw_fde_current_label, NULL);
3255 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3258 case DW_CFA_MIPS_advance_loc8:
3259 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3260 fde->dw_fde_current_label, NULL);
3261 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3264 case DW_CFA_offset_extended:
3265 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3266 dw2_asm_output_data_uleb128 (r, NULL);
3267 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3268 dw2_asm_output_data_uleb128 (off, NULL);
3271 case DW_CFA_def_cfa:
3272 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3273 dw2_asm_output_data_uleb128 (r, NULL);
3274 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3277 case DW_CFA_offset_extended_sf:
3278 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3279 dw2_asm_output_data_uleb128 (r, NULL);
3280 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3281 dw2_asm_output_data_sleb128 (off, NULL);
3284 case DW_CFA_def_cfa_sf:
3285 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3286 dw2_asm_output_data_uleb128 (r, NULL);
3287 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3288 dw2_asm_output_data_sleb128 (off, NULL);
3291 case DW_CFA_restore_extended:
3292 case DW_CFA_undefined:
3293 case DW_CFA_same_value:
3294 case DW_CFA_def_cfa_register:
3295 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3296 dw2_asm_output_data_uleb128 (r, NULL);
3299 case DW_CFA_register:
3300 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3301 dw2_asm_output_data_uleb128 (r, NULL);
3302 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3303 dw2_asm_output_data_uleb128 (r, NULL);
3306 case DW_CFA_def_cfa_offset:
3307 case DW_CFA_GNU_args_size:
3308 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3311 case DW_CFA_def_cfa_offset_sf:
3312 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3313 dw2_asm_output_data_sleb128 (off, NULL);
3316 case DW_CFA_GNU_window_save:
3319 case DW_CFA_def_cfa_expression:
3320 case DW_CFA_expression:
3321 output_cfa_loc (cfi, for_eh);
3324 case DW_CFA_GNU_negative_offset_extended:
3325 /* Obsoleted by DW_CFA_offset_extended_sf. */
3334 /* Similar, but do it via assembler directives instead. */
3337 output_cfi_directive (dw_cfi_ref cfi)
3339 unsigned long r, r2;
3341 switch (cfi->dw_cfi_opc)
3343 case DW_CFA_advance_loc:
3344 case DW_CFA_advance_loc1:
3345 case DW_CFA_advance_loc2:
3346 case DW_CFA_advance_loc4:
3347 case DW_CFA_MIPS_advance_loc8:
3348 case DW_CFA_set_loc:
3349 /* Should only be created by add_fde_cfi in a code path not
3350 followed when emitting via directives. The assembler is
3351 going to take care of this for us. */
3355 case DW_CFA_offset_extended:
3356 case DW_CFA_offset_extended_sf:
3357 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3358 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3359 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3362 case DW_CFA_restore:
3363 case DW_CFA_restore_extended:
3364 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3365 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3368 case DW_CFA_undefined:
3369 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3370 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3373 case DW_CFA_same_value:
3374 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3375 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3378 case DW_CFA_def_cfa:
3379 case DW_CFA_def_cfa_sf:
3380 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3381 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3382 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3385 case DW_CFA_def_cfa_register:
3386 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3387 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3390 case DW_CFA_register:
3391 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3392 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3393 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3396 case DW_CFA_def_cfa_offset:
3397 case DW_CFA_def_cfa_offset_sf:
3398 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3399 HOST_WIDE_INT_PRINT_DEC"\n",
3400 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3403 case DW_CFA_remember_state:
3404 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3406 case DW_CFA_restore_state:
3407 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3410 case DW_CFA_GNU_args_size:
3411 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3412 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3414 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3415 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3416 fputc ('\n', asm_out_file);
3419 case DW_CFA_GNU_window_save:
3420 fprintf (asm_out_file, "\t.cfi_window_save\n");
3423 case DW_CFA_def_cfa_expression:
3424 case DW_CFA_expression:
3425 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3426 output_cfa_loc_raw (cfi);
3427 fputc ('\n', asm_out_file);
3435 DEF_VEC_P (dw_cfi_ref);
3436 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3438 /* Output CFIs to bring current FDE to the same state as after executing
3439 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3440 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3441 other arguments to pass to output_cfi. */
3444 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3446 struct dw_cfi_struct cfi_buf;
3448 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3449 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3450 unsigned int len, idx;
3452 for (;; cfi = cfi->dw_cfi_next)
3453 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3455 case DW_CFA_advance_loc:
3456 case DW_CFA_advance_loc1:
3457 case DW_CFA_advance_loc2:
3458 case DW_CFA_advance_loc4:
3459 case DW_CFA_MIPS_advance_loc8:
3460 case DW_CFA_set_loc:
3461 /* All advances should be ignored. */
3463 case DW_CFA_remember_state:
3465 dw_cfi_ref args_size = cfi_args_size;
3467 /* Skip everything between .cfi_remember_state and
3468 .cfi_restore_state. */
3469 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3470 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3472 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3475 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3482 cfi_args_size = args_size;
3486 case DW_CFA_GNU_args_size:
3487 cfi_args_size = cfi;
3489 case DW_CFA_GNU_window_save:
3492 case DW_CFA_offset_extended:
3493 case DW_CFA_offset_extended_sf:
3494 case DW_CFA_restore:
3495 case DW_CFA_restore_extended:
3496 case DW_CFA_undefined:
3497 case DW_CFA_same_value:
3498 case DW_CFA_register:
3499 case DW_CFA_val_offset:
3500 case DW_CFA_val_offset_sf:
3501 case DW_CFA_expression:
3502 case DW_CFA_val_expression:
3503 case DW_CFA_GNU_negative_offset_extended:
3504 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3505 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3506 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3507 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3509 case DW_CFA_def_cfa:
3510 case DW_CFA_def_cfa_sf:
3511 case DW_CFA_def_cfa_expression:
3513 cfi_cfa_offset = cfi;
3515 case DW_CFA_def_cfa_register:
3518 case DW_CFA_def_cfa_offset:
3519 case DW_CFA_def_cfa_offset_sf:
3520 cfi_cfa_offset = cfi;
3523 gcc_assert (cfi == NULL);
3525 len = VEC_length (dw_cfi_ref, regs);
3526 for (idx = 0; idx < len; idx++)
3528 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3530 && cfi2->dw_cfi_opc != DW_CFA_restore
3531 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3534 output_cfi_directive (cfi2);
3536 output_cfi (cfi2, fde, for_eh);
3539 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3541 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3543 switch (cfi_cfa_offset->dw_cfi_opc)
3545 case DW_CFA_def_cfa_offset:
3546 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3547 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3549 case DW_CFA_def_cfa_offset_sf:
3550 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3551 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3553 case DW_CFA_def_cfa:
3554 case DW_CFA_def_cfa_sf:
3555 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3556 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3563 else if (cfi_cfa_offset)
3564 cfi_cfa = cfi_cfa_offset;
3568 output_cfi_directive (cfi_cfa);
3570 output_cfi (cfi_cfa, fde, for_eh);
3573 cfi_cfa_offset = NULL;
3575 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3578 output_cfi_directive (cfi_args_size);
3580 output_cfi (cfi_args_size, fde, for_eh);
3582 cfi_args_size = NULL;
3585 VEC_free (dw_cfi_ref, heap, regs);
3588 else if (do_cfi_asm)
3589 output_cfi_directive (cfi);
3591 output_cfi (cfi, fde, for_eh);
3598 /* Output one FDE. */
3601 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3602 char *section_start_label, int fde_encoding, char *augmentation,
3603 bool any_lsda_needed, int lsda_encoding)
3605 const char *begin, *end;
3606 static unsigned int j;
3607 char l1[20], l2[20];
3610 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3612 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3614 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3615 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3616 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3617 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3618 " indicating 64-bit DWARF extension");
3619 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3621 ASM_OUTPUT_LABEL (asm_out_file, l1);
3624 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3626 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3627 debug_frame_section, "FDE CIE offset");
3629 if (!fde->dw_fde_switched_sections)
3631 begin = fde->dw_fde_begin;
3632 end = fde->dw_fde_end;
3636 /* For the first section, prefer dw_fde_begin over
3637 dw_fde_{hot,cold}_section_label, as the latter
3638 might be separated from the real start of the
3639 function by alignment padding. */
3641 begin = fde->dw_fde_begin;
3642 else if (fde->dw_fde_switched_cold_to_hot)
3643 begin = fde->dw_fde_hot_section_label;
3645 begin = fde->dw_fde_unlikely_section_label;
3646 if (second ^ fde->dw_fde_switched_cold_to_hot)
3647 end = fde->dw_fde_unlikely_section_end_label;
3649 end = fde->dw_fde_hot_section_end_label;
3654 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3655 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3656 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3657 "FDE initial location");
3658 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3659 end, begin, "FDE address range");
3663 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3664 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3667 if (augmentation[0])
3669 if (any_lsda_needed)
3671 int size = size_of_encoded_value (lsda_encoding);
3673 if (lsda_encoding == DW_EH_PE_aligned)
3675 int offset = ( 4 /* Length */
3676 + 4 /* CIE offset */
3677 + 2 * size_of_encoded_value (fde_encoding)
3678 + 1 /* Augmentation size */ );
3679 int pad = -offset & (PTR_SIZE - 1);
3682 gcc_assert (size_of_uleb128 (size) == 1);
3685 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3687 if (fde->uses_eh_lsda)
3689 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3690 fde->funcdef_number);
3691 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3692 gen_rtx_SYMBOL_REF (Pmode, l1),
3694 "Language Specific Data Area");
3698 if (lsda_encoding == DW_EH_PE_aligned)
3699 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3700 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3701 "Language Specific Data Area (none)");
3705 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3708 /* Loop through the Call Frame Instructions associated with
3710 fde->dw_fde_current_label = begin;
3711 if (!fde->dw_fde_switched_sections)
3712 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3713 output_cfi (cfi, fde, for_eh);
3716 if (fde->dw_fde_switch_cfi)
3717 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3719 output_cfi (cfi, fde, for_eh);
3720 if (cfi == fde->dw_fde_switch_cfi)
3726 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3728 if (fde->dw_fde_switch_cfi)
3730 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3731 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3732 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3733 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3735 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3736 output_cfi (cfi, fde, for_eh);
3739 /* If we are to emit a ref/link from function bodies to their frame tables,
3740 do it now. This is typically performed to make sure that tables
3741 associated with functions are dragged with them and not discarded in
3742 garbage collecting links. We need to do this on a per function basis to
3743 cope with -ffunction-sections. */
3745 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3746 /* Switch to the function section, emit the ref to the tables, and
3747 switch *back* into the table section. */
3748 switch_to_section (function_section (fde->decl));
3749 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3750 switch_to_frame_table_section (for_eh, true);
3753 /* Pad the FDE out to an address sized boundary. */
3754 ASM_OUTPUT_ALIGN (asm_out_file,
3755 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3756 ASM_OUTPUT_LABEL (asm_out_file, l2);
3761 /* Return true if frame description entry FDE is needed for EH. */
3764 fde_needed_for_eh_p (dw_fde_ref fde)
3766 if (flag_asynchronous_unwind_tables)
3769 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3772 if (fde->uses_eh_lsda)
3775 /* If exceptions are enabled, we have collected nothrow info. */
3776 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3782 /* Output the call frame information used to record information
3783 that relates to calculating the frame pointer, and records the
3784 location of saved registers. */
3787 output_call_frame_info (int for_eh)
3792 char l1[20], l2[20], section_start_label[20];
3793 bool any_lsda_needed = false;
3794 char augmentation[6];
3795 int augmentation_size;
3796 int fde_encoding = DW_EH_PE_absptr;
3797 int per_encoding = DW_EH_PE_absptr;
3798 int lsda_encoding = DW_EH_PE_absptr;
3800 rtx personality = NULL;
3803 /* Don't emit a CIE if there won't be any FDEs. */
3804 if (fde_table_in_use == 0)
3807 /* Nothing to do if the assembler's doing it all. */
3808 if (dwarf2out_do_cfi_asm ())
3811 /* If we don't have any functions we'll want to unwind out of, don't emit
3812 any EH unwind information. If we make FDEs linkonce, we may have to
3813 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3814 want to avoid having an FDE kept around when the function it refers to
3815 is discarded. Example where this matters: a primary function template
3816 in C++ requires EH information, an explicit specialization doesn't. */
3819 bool any_eh_needed = false;
3821 for (i = 0; i < fde_table_in_use; i++)
3822 if (fde_table[i].uses_eh_lsda)
3823 any_eh_needed = any_lsda_needed = true;
3824 else if (fde_needed_for_eh_p (&fde_table[i]))
3825 any_eh_needed = true;
3826 else if (TARGET_USES_WEAK_UNWIND_INFO)
3827 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3834 /* We're going to be generating comments, so turn on app. */
3838 /* Switch to the proper frame section, first time. */
3839 switch_to_frame_table_section (for_eh, false);
3841 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3842 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3844 /* Output the CIE. */
3845 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3846 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3847 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3848 dw2_asm_output_data (4, 0xffffffff,
3849 "Initial length escape value indicating 64-bit DWARF extension");
3850 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3851 "Length of Common Information Entry");
3852 ASM_OUTPUT_LABEL (asm_out_file, l1);
3854 /* Now that the CIE pointer is PC-relative for EH,
3855 use 0 to identify the CIE. */
3856 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3857 (for_eh ? 0 : DWARF_CIE_ID),
3858 "CIE Identifier Tag");
3860 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3861 use CIE version 1, unless that would produce incorrect results
3862 due to overflowing the return register column. */
3863 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3865 if (return_reg >= 256 || dwarf_version > 2)
3867 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3869 augmentation[0] = 0;
3870 augmentation_size = 0;
3872 personality = current_unit_personality;
3878 z Indicates that a uleb128 is present to size the
3879 augmentation section.
3880 L Indicates the encoding (and thus presence) of
3881 an LSDA pointer in the FDE augmentation.
3882 R Indicates a non-default pointer encoding for
3884 P Indicates the presence of an encoding + language
3885 personality routine in the CIE augmentation. */
3887 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3888 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3889 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3891 p = augmentation + 1;
3895 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3896 assemble_external_libcall (personality);
3898 if (any_lsda_needed)
3901 augmentation_size += 1;
3903 if (fde_encoding != DW_EH_PE_absptr)
3906 augmentation_size += 1;
3908 if (p > augmentation + 1)
3910 augmentation[0] = 'z';
3914 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3915 if (personality && per_encoding == DW_EH_PE_aligned)
3917 int offset = ( 4 /* Length */
3919 + 1 /* CIE version */
3920 + strlen (augmentation) + 1 /* Augmentation */
3921 + size_of_uleb128 (1) /* Code alignment */
3922 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3924 + 1 /* Augmentation size */
3925 + 1 /* Personality encoding */ );
3926 int pad = -offset & (PTR_SIZE - 1);
3928 augmentation_size += pad;
3930 /* Augmentations should be small, so there's scarce need to
3931 iterate for a solution. Die if we exceed one uleb128 byte. */
3932 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3936 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3937 if (dw_cie_version >= 4)
3939 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3940 dw2_asm_output_data (1, 0, "CIE Segment Size");
3942 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3943 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3944 "CIE Data Alignment Factor");
3946 if (dw_cie_version == 1)
3947 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3949 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3951 if (augmentation[0])
3953 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3956 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3957 eh_data_format_name (per_encoding));
3958 dw2_asm_output_encoded_addr_rtx (per_encoding,
3963 if (any_lsda_needed)
3964 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3965 eh_data_format_name (lsda_encoding));
3967 if (fde_encoding != DW_EH_PE_absptr)
3968 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3969 eh_data_format_name (fde_encoding));
3972 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3973 output_cfi (cfi, NULL, for_eh);
3975 /* Pad the CIE out to an address sized boundary. */
3976 ASM_OUTPUT_ALIGN (asm_out_file,
3977 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3978 ASM_OUTPUT_LABEL (asm_out_file, l2);
3980 /* Loop through all of the FDE's. */
3981 for (i = 0; i < fde_table_in_use; i++)
3984 fde = &fde_table[i];
3986 /* Don't emit EH unwind info for leaf functions that don't need it. */
3987 if (for_eh && !fde_needed_for_eh_p (fde))
3990 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3991 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3992 augmentation, any_lsda_needed, lsda_encoding);
3995 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3996 dw2_asm_output_data (4, 0, "End of Table");
3997 #ifdef MIPS_DEBUGGING_INFO
3998 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3999 get a value of 0. Putting .align 0 after the label fixes it. */
4000 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4003 /* Turn off app to make assembly quicker. */
4008 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4011 dwarf2out_do_cfi_startproc (bool second)
4015 rtx personality = get_personality_function (current_function_decl);
4017 fprintf (asm_out_file, "\t.cfi_startproc\n");
4021 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4024 /* ??? The GAS support isn't entirely consistent. We have to
4025 handle indirect support ourselves, but PC-relative is done
4026 in the assembler. Further, the assembler can't handle any
4027 of the weirder relocation types. */
4028 if (enc & DW_EH_PE_indirect)
4029 ref = dw2_force_const_mem (ref, true);
4031 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4032 output_addr_const (asm_out_file, ref);
4033 fputc ('\n', asm_out_file);
4036 if (crtl->uses_eh_lsda)
4040 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4041 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4042 current_function_funcdef_no);
4043 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4044 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4046 if (enc & DW_EH_PE_indirect)
4047 ref = dw2_force_const_mem (ref, true);
4049 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4050 output_addr_const (asm_out_file, ref);
4051 fputc ('\n', asm_out_file);
4055 /* Output a marker (i.e. a label) for the beginning of a function, before
4059 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4060 const char *file ATTRIBUTE_UNUSED)
4062 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4068 current_function_func_begin_label = NULL;
4070 do_frame = dwarf2out_do_frame ();
4072 /* ??? current_function_func_begin_label is also used by except.c for
4073 call-site information. We must emit this label if it might be used. */
4075 && (!flag_exceptions
4076 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4079 fnsec = function_section (current_function_decl);
4080 switch_to_section (fnsec);
4081 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4082 current_function_funcdef_no);
4083 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4084 current_function_funcdef_no);
4085 dup_label = xstrdup (label);
4086 current_function_func_begin_label = dup_label;
4088 /* We can elide the fde allocation if we're not emitting debug info. */
4092 /* Expand the fde table if necessary. */
4093 if (fde_table_in_use == fde_table_allocated)
4095 fde_table_allocated += FDE_TABLE_INCREMENT;
4096 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4097 memset (fde_table + fde_table_in_use, 0,
4098 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4101 /* Record the FDE associated with this function. */
4102 current_funcdef_fde = fde_table_in_use;
4104 /* Add the new FDE at the end of the fde_table. */
4105 fde = &fde_table[fde_table_in_use++];
4106 fde->decl = current_function_decl;
4107 fde->dw_fde_begin = dup_label;
4108 fde->dw_fde_current_label = dup_label;
4109 fde->dw_fde_hot_section_label = NULL;
4110 fde->dw_fde_hot_section_end_label = NULL;
4111 fde->dw_fde_unlikely_section_label = NULL;
4112 fde->dw_fde_unlikely_section_end_label = NULL;
4113 fde->dw_fde_switched_sections = 0;
4114 fde->dw_fde_switched_cold_to_hot = 0;
4115 fde->dw_fde_end = NULL;
4116 fde->dw_fde_vms_end_prologue = NULL;
4117 fde->dw_fde_vms_begin_epilogue = NULL;
4118 fde->dw_fde_cfi = NULL;
4119 fde->dw_fde_switch_cfi = NULL;
4120 fde->funcdef_number = current_function_funcdef_no;
4121 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4122 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4123 fde->nothrow = crtl->nothrow;
4124 fde->drap_reg = INVALID_REGNUM;
4125 fde->vdrap_reg = INVALID_REGNUM;
4126 if (flag_reorder_blocks_and_partition)
4128 section *unlikelysec;
4129 if (first_function_block_is_cold)
4130 fde->in_std_section = 1;
4133 = (fnsec == text_section
4134 || (cold_text_section && fnsec == cold_text_section));
4135 unlikelysec = unlikely_text_section ();
4136 fde->cold_in_std_section
4137 = (unlikelysec == text_section
4138 || (cold_text_section && unlikelysec == cold_text_section));
4143 = (fnsec == text_section
4144 || (cold_text_section && fnsec == cold_text_section));
4145 fde->cold_in_std_section = 0;
4148 args_size = old_args_size = 0;
4150 /* We only want to output line number information for the genuine dwarf2
4151 prologue case, not the eh frame case. */
4152 #ifdef DWARF2_DEBUGGING_INFO
4154 dwarf2out_source_line (line, file, 0, true);
4157 if (dwarf2out_do_cfi_asm ())
4158 dwarf2out_do_cfi_startproc (false);
4161 rtx personality = get_personality_function (current_function_decl);
4162 if (!current_unit_personality)
4163 current_unit_personality = personality;
4165 /* We cannot keep a current personality per function as without CFI
4166 asm, at the point where we emit the CFI data, there is no current
4167 function anymore. */
4168 if (personality && current_unit_personality != personality)
4169 sorry ("multiple EH personalities are supported only with assemblers "
4170 "supporting .cfi_personality directive");
4174 /* Output a marker (i.e. a label) for the end of the generated code
4175 for a function prologue. This gets called *after* the prologue code has
4179 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4180 const char *file ATTRIBUTE_UNUSED)
4183 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4185 /* Output a label to mark the endpoint of the code generated for this
4187 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4188 current_function_funcdef_no);
4189 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4190 current_function_funcdef_no);
4191 fde = &fde_table[fde_table_in_use - 1];
4192 fde->dw_fde_vms_end_prologue = xstrdup (label);
4195 /* Output a marker (i.e. a label) for the beginning of the generated code
4196 for a function epilogue. This gets called *before* the prologue code has
4200 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4201 const char *file ATTRIBUTE_UNUSED)
4204 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4206 fde = &fde_table[fde_table_in_use - 1];
4207 if (fde->dw_fde_vms_begin_epilogue)
4210 /* Output a label to mark the endpoint of the code generated for this
4212 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4213 current_function_funcdef_no);
4214 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4215 current_function_funcdef_no);
4216 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4219 /* Output a marker (i.e. a label) for the absolute end of the generated code
4220 for a function definition. This gets called *after* the epilogue code has
4224 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4225 const char *file ATTRIBUTE_UNUSED)
4228 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4230 last_var_location_insn = NULL_RTX;
4232 if (dwarf2out_do_cfi_asm ())
4233 fprintf (asm_out_file, "\t.cfi_endproc\n");
4235 /* Output a label to mark the endpoint of the code generated for this
4237 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4238 current_function_funcdef_no);
4239 ASM_OUTPUT_LABEL (asm_out_file, label);
4240 fde = current_fde ();
4241 gcc_assert (fde != NULL);
4242 fde->dw_fde_end = xstrdup (label);
4246 dwarf2out_frame_init (void)
4248 /* Allocate the initial hunk of the fde_table. */
4249 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4250 fde_table_allocated = FDE_TABLE_INCREMENT;
4251 fde_table_in_use = 0;
4253 /* Generate the CFA instructions common to all FDE's. Do it now for the
4254 sake of lookup_cfa. */
4256 /* On entry, the Canonical Frame Address is at SP. */
4257 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4259 if (targetm.debug_unwind_info () == UI_DWARF2
4260 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4261 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4265 dwarf2out_frame_finish (void)
4267 /* Output call frame information. */
4268 if (targetm.debug_unwind_info () == UI_DWARF2)
4269 output_call_frame_info (0);
4271 /* Output another copy for the unwinder. */
4272 if ((flag_unwind_tables || flag_exceptions)
4273 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4274 output_call_frame_info (1);
4277 /* Note that the current function section is being used for code. */
4280 dwarf2out_note_section_used (void)
4282 section *sec = current_function_section ();
4283 if (sec == text_section)
4284 text_section_used = true;
4285 else if (sec == cold_text_section)
4286 cold_text_section_used = true;
4290 dwarf2out_switch_text_section (void)
4292 dw_fde_ref fde = current_fde ();
4294 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4296 fde->dw_fde_switched_sections = 1;
4297 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4299 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4300 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4301 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4302 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4303 have_multiple_function_sections = true;
4305 /* Reset the current label on switching text sections, so that we
4306 don't attempt to advance_loc4 between labels in different sections. */
4307 fde->dw_fde_current_label = NULL;
4309 /* There is no need to mark used sections when not debugging. */
4310 if (cold_text_section != NULL)
4311 dwarf2out_note_section_used ();
4313 if (dwarf2out_do_cfi_asm ())
4314 fprintf (asm_out_file, "\t.cfi_endproc\n");
4316 /* Now do the real section switch. */
4317 switch_to_section (current_function_section ());
4319 if (dwarf2out_do_cfi_asm ())
4321 dwarf2out_do_cfi_startproc (true);
4322 /* As this is a different FDE, insert all current CFI instructions
4324 output_cfis (fde->dw_fde_cfi, true, fde, true);
4328 dw_cfi_ref cfi = fde->dw_fde_cfi;
4330 cfi = fde->dw_fde_cfi;
4332 while (cfi->dw_cfi_next != NULL)
4333 cfi = cfi->dw_cfi_next;
4334 fde->dw_fde_switch_cfi = cfi;
4338 /* And now, the subset of the debugging information support code necessary
4339 for emitting location expressions. */
4341 /* Data about a single source file. */
4342 struct GTY(()) dwarf_file_data {
4343 const char * filename;
4347 typedef struct dw_val_struct *dw_val_ref;
4348 typedef struct die_struct *dw_die_ref;
4349 typedef const struct die_struct *const_dw_die_ref;
4350 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4351 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4353 typedef struct GTY(()) deferred_locations_struct
4357 } deferred_locations;
4359 DEF_VEC_O(deferred_locations);
4360 DEF_VEC_ALLOC_O(deferred_locations,gc);
4362 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4364 DEF_VEC_P(dw_die_ref);
4365 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4367 /* Each DIE may have a series of attribute/value pairs. Values
4368 can take on several forms. The forms that are used in this
4369 implementation are listed below. */
4374 dw_val_class_offset,
4376 dw_val_class_loc_list,
4377 dw_val_class_range_list,
4379 dw_val_class_unsigned_const,
4380 dw_val_class_const_double,
4383 dw_val_class_die_ref,
4384 dw_val_class_fde_ref,
4385 dw_val_class_lbl_id,
4386 dw_val_class_lineptr,
4388 dw_val_class_macptr,
4391 dw_val_class_decl_ref,
4392 dw_val_class_vms_delta
4395 /* Describe a floating point constant value, or a vector constant value. */
4397 typedef struct GTY(()) dw_vec_struct {
4398 unsigned char * GTY((length ("%h.length"))) array;
4404 /* The dw_val_node describes an attribute's value, as it is
4405 represented internally. */
4407 typedef struct GTY(()) dw_val_struct {
4408 enum dw_val_class val_class;
4409 union dw_val_struct_union
4411 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4412 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4413 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4414 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4415 HOST_WIDE_INT GTY ((default)) val_int;
4416 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4417 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4418 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4419 struct dw_val_die_union
4423 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4424 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4425 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4426 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4427 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4428 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4429 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4430 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4431 struct dw_val_vms_delta_union
4435 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4437 GTY ((desc ("%1.val_class"))) v;
4441 /* Locations in memory are described using a sequence of stack machine
4444 typedef struct GTY(()) dw_loc_descr_struct {
4445 dw_loc_descr_ref dw_loc_next;
4446 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4447 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4448 from DW_OP_addr with a dtp-relative symbol relocation. */
4449 unsigned int dtprel : 1;
4451 dw_val_node dw_loc_oprnd1;
4452 dw_val_node dw_loc_oprnd2;
4456 /* Location lists are ranges + location descriptions for that range,
4457 so you can track variables that are in different places over
4458 their entire life. */
4459 typedef struct GTY(()) dw_loc_list_struct {
4460 dw_loc_list_ref dw_loc_next;
4461 const char *begin; /* Label for begin address of range */
4462 const char *end; /* Label for end address of range */
4463 char *ll_symbol; /* Label for beginning of location list.
4464 Only on head of list */
4465 const char *section; /* Section this loclist is relative to */
4466 dw_loc_descr_ref expr;
4471 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4473 /* Convert a DWARF stack opcode into its string name. */
4476 dwarf_stack_op_name (unsigned int op)
4481 return "DW_OP_addr";
4483 return "DW_OP_deref";
4485 return "DW_OP_const1u";
4487 return "DW_OP_const1s";
4489 return "DW_OP_const2u";
4491 return "DW_OP_const2s";
4493 return "DW_OP_const4u";
4495 return "DW_OP_const4s";
4497 return "DW_OP_const8u";
4499 return "DW_OP_const8s";
4501 return "DW_OP_constu";
4503 return "DW_OP_consts";
4507 return "DW_OP_drop";
4509 return "DW_OP_over";
4511 return "DW_OP_pick";
4513 return "DW_OP_swap";
4517 return "DW_OP_xderef";
4525 return "DW_OP_minus";
4537 return "DW_OP_plus";
4538 case DW_OP_plus_uconst:
4539 return "DW_OP_plus_uconst";
4545 return "DW_OP_shra";
4563 return "DW_OP_skip";
4565 return "DW_OP_lit0";
4567 return "DW_OP_lit1";
4569 return "DW_OP_lit2";
4571 return "DW_OP_lit3";
4573 return "DW_OP_lit4";
4575 return "DW_OP_lit5";
4577 return "DW_OP_lit6";
4579 return "DW_OP_lit7";
4581 return "DW_OP_lit8";
4583 return "DW_OP_lit9";
4585 return "DW_OP_lit10";
4587 return "DW_OP_lit11";
4589 return "DW_OP_lit12";
4591 return "DW_OP_lit13";
4593 return "DW_OP_lit14";
4595 return "DW_OP_lit15";
4597 return "DW_OP_lit16";
4599 return "DW_OP_lit17";
4601 return "DW_OP_lit18";
4603 return "DW_OP_lit19";
4605 return "DW_OP_lit20";
4607 return "DW_OP_lit21";
4609 return "DW_OP_lit22";
4611 return "DW_OP_lit23";
4613 return "DW_OP_lit24";
4615 return "DW_OP_lit25";
4617 return "DW_OP_lit26";
4619 return "DW_OP_lit27";
4621 return "DW_OP_lit28";
4623 return "DW_OP_lit29";
4625 return "DW_OP_lit30";
4627 return "DW_OP_lit31";
4629 return "DW_OP_reg0";
4631 return "DW_OP_reg1";
4633 return "DW_OP_reg2";
4635 return "DW_OP_reg3";
4637 return "DW_OP_reg4";
4639 return "DW_OP_reg5";
4641 return "DW_OP_reg6";
4643 return "DW_OP_reg7";
4645 return "DW_OP_reg8";
4647 return "DW_OP_reg9";
4649 return "DW_OP_reg10";
4651 return "DW_OP_reg11";
4653 return "DW_OP_reg12";
4655 return "DW_OP_reg13";
4657 return "DW_OP_reg14";
4659 return "DW_OP_reg15";
4661 return "DW_OP_reg16";
4663 return "DW_OP_reg17";
4665 return "DW_OP_reg18";
4667 return "DW_OP_reg19";
4669 return "DW_OP_reg20";
4671 return "DW_OP_reg21";
4673 return "DW_OP_reg22";
4675 return "DW_OP_reg23";
4677 return "DW_OP_reg24";
4679 return "DW_OP_reg25";
4681 return "DW_OP_reg26";
4683 return "DW_OP_reg27";
4685 return "DW_OP_reg28";
4687 return "DW_OP_reg29";
4689 return "DW_OP_reg30";
4691 return "DW_OP_reg31";
4693 return "DW_OP_breg0";
4695 return "DW_OP_breg1";
4697 return "DW_OP_breg2";
4699 return "DW_OP_breg3";
4701 return "DW_OP_breg4";
4703 return "DW_OP_breg5";
4705 return "DW_OP_breg6";
4707 return "DW_OP_breg7";
4709 return "DW_OP_breg8";
4711 return "DW_OP_breg9";
4713 return "DW_OP_breg10";
4715 return "DW_OP_breg11";
4717 return "DW_OP_breg12";
4719 return "DW_OP_breg13";
4721 return "DW_OP_breg14";
4723 return "DW_OP_breg15";
4725 return "DW_OP_breg16";
4727 return "DW_OP_breg17";
4729 return "DW_OP_breg18";
4731 return "DW_OP_breg19";
4733 return "DW_OP_breg20";
4735 return "DW_OP_breg21";
4737 return "DW_OP_breg22";
4739 return "DW_OP_breg23";
4741 return "DW_OP_breg24";
4743 return "DW_OP_breg25";
4745 return "DW_OP_breg26";
4747 return "DW_OP_breg27";
4749 return "DW_OP_breg28";
4751 return "DW_OP_breg29";
4753 return "DW_OP_breg30";
4755 return "DW_OP_breg31";
4757 return "DW_OP_regx";
4759 return "DW_OP_fbreg";
4761 return "DW_OP_bregx";
4763 return "DW_OP_piece";
4764 case DW_OP_deref_size:
4765 return "DW_OP_deref_size";
4766 case DW_OP_xderef_size:
4767 return "DW_OP_xderef_size";
4771 case DW_OP_push_object_address:
4772 return "DW_OP_push_object_address";
4774 return "DW_OP_call2";
4776 return "DW_OP_call4";
4777 case DW_OP_call_ref:
4778 return "DW_OP_call_ref";
4779 case DW_OP_implicit_value:
4780 return "DW_OP_implicit_value";
4781 case DW_OP_stack_value:
4782 return "DW_OP_stack_value";
4783 case DW_OP_form_tls_address:
4784 return "DW_OP_form_tls_address";
4785 case DW_OP_call_frame_cfa:
4786 return "DW_OP_call_frame_cfa";
4787 case DW_OP_bit_piece:
4788 return "DW_OP_bit_piece";
4790 case DW_OP_GNU_push_tls_address:
4791 return "DW_OP_GNU_push_tls_address";
4792 case DW_OP_GNU_uninit:
4793 return "DW_OP_GNU_uninit";
4794 case DW_OP_GNU_encoded_addr:
4795 return "DW_OP_GNU_encoded_addr";
4796 case DW_OP_GNU_implicit_pointer:
4797 return "DW_OP_GNU_implicit_pointer";
4798 case DW_OP_GNU_entry_value:
4799 return "DW_OP_GNU_entry_value";
4802 return "OP_<unknown>";
4806 /* Return a pointer to a newly allocated location description. Location
4807 descriptions are simple expression terms that can be strung
4808 together to form more complicated location (address) descriptions. */
4810 static inline dw_loc_descr_ref
4811 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4812 unsigned HOST_WIDE_INT oprnd2)
4814 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4816 descr->dw_loc_opc = op;
4817 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4818 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4819 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4820 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4825 /* Return a pointer to a newly allocated location description for
4828 static inline dw_loc_descr_ref
4829 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4832 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4835 return new_loc_descr (DW_OP_bregx, reg, offset);
4838 /* Add a location description term to a location description expression. */
4841 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4843 dw_loc_descr_ref *d;
4845 /* Find the end of the chain. */
4846 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4852 /* Add a constant OFFSET to a location expression. */
4855 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4857 dw_loc_descr_ref loc;
4860 gcc_assert (*list_head != NULL);
4865 /* Find the end of the chain. */
4866 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4870 if (loc->dw_loc_opc == DW_OP_fbreg
4871 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4872 p = &loc->dw_loc_oprnd1.v.val_int;
4873 else if (loc->dw_loc_opc == DW_OP_bregx)
4874 p = &loc->dw_loc_oprnd2.v.val_int;
4876 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4877 offset. Don't optimize if an signed integer overflow would happen. */
4879 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4880 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4883 else if (offset > 0)
4884 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4888 loc->dw_loc_next = int_loc_descriptor (-offset);
4889 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4893 /* Add a constant OFFSET to a location list. */
4896 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4899 for (d = list_head; d != NULL; d = d->dw_loc_next)
4900 loc_descr_plus_const (&d->expr, offset);
4903 #define DWARF_REF_SIZE \
4904 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4906 static unsigned long size_of_locs (dw_loc_descr_ref);
4908 /* Return the size of a location descriptor. */
4910 static unsigned long
4911 size_of_loc_descr (dw_loc_descr_ref loc)
4913 unsigned long size = 1;
4915 switch (loc->dw_loc_opc)
4918 size += DWARF2_ADDR_SIZE;
4937 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4940 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4945 case DW_OP_plus_uconst:
4946 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4984 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4987 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4990 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4993 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4994 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4997 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4999 case DW_OP_bit_piece:
5000 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
5001 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
5003 case DW_OP_deref_size:
5004 case DW_OP_xderef_size:
5013 case DW_OP_call_ref:
5014 size += DWARF_REF_SIZE;
5016 case DW_OP_implicit_value:
5017 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5018 + loc->dw_loc_oprnd1.v.val_unsigned;
5020 case DW_OP_GNU_implicit_pointer:
5021 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5023 case DW_OP_GNU_entry_value:
5025 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5026 size += size_of_uleb128 (op_size) + op_size;
5036 /* Return the size of a series of location descriptors. */
5038 static unsigned long
5039 size_of_locs (dw_loc_descr_ref loc)
5044 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5045 field, to avoid writing to a PCH file. */
5046 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5048 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5050 size += size_of_loc_descr (l);
5055 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5057 l->dw_loc_addr = size;
5058 size += size_of_loc_descr (l);
5064 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5065 static void get_ref_die_offset_label (char *, dw_die_ref);
5066 static void output_loc_sequence (dw_loc_descr_ref, int);
5068 /* Output location description stack opcode's operands (if any).
5069 The for_eh_or_skip parameter controls whether register numbers are
5070 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5071 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5072 info). This should be suppressed for the cases that have not been converted
5073 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5076 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5078 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5079 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5081 switch (loc->dw_loc_opc)
5083 #ifdef DWARF2_DEBUGGING_INFO
5086 dw2_asm_output_data (2, val1->v.val_int, NULL);
5091 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5092 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5094 fputc ('\n', asm_out_file);
5099 dw2_asm_output_data (4, val1->v.val_int, NULL);
5104 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5105 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5107 fputc ('\n', asm_out_file);
5112 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5113 dw2_asm_output_data (8, val1->v.val_int, NULL);
5120 gcc_assert (val1->val_class == dw_val_class_loc);
5121 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5123 dw2_asm_output_data (2, offset, NULL);
5126 case DW_OP_implicit_value:
5127 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5128 switch (val2->val_class)
5130 case dw_val_class_const:
5131 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5133 case dw_val_class_vec:
5135 unsigned int elt_size = val2->v.val_vec.elt_size;
5136 unsigned int len = val2->v.val_vec.length;
5140 if (elt_size > sizeof (HOST_WIDE_INT))
5145 for (i = 0, p = val2->v.val_vec.array;
5148 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5149 "fp or vector constant word %u", i);
5152 case dw_val_class_const_double:
5154 unsigned HOST_WIDE_INT first, second;
5156 if (WORDS_BIG_ENDIAN)
5158 first = val2->v.val_double.high;
5159 second = val2->v.val_double.low;
5163 first = val2->v.val_double.low;
5164 second = val2->v.val_double.high;
5166 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5168 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5172 case dw_val_class_addr:
5173 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5174 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5189 case DW_OP_implicit_value:
5190 /* We currently don't make any attempt to make sure these are
5191 aligned properly like we do for the main unwind info, so
5192 don't support emitting things larger than a byte if we're
5193 only doing unwinding. */
5198 dw2_asm_output_data (1, val1->v.val_int, NULL);
5201 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5204 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5207 dw2_asm_output_data (1, val1->v.val_int, NULL);
5209 case DW_OP_plus_uconst:
5210 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5244 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5248 unsigned r = val1->v.val_unsigned;
5249 if (for_eh_or_skip >= 0)
5250 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5251 gcc_assert (size_of_uleb128 (r)
5252 == size_of_uleb128 (val1->v.val_unsigned));
5253 dw2_asm_output_data_uleb128 (r, NULL);
5257 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5261 unsigned r = val1->v.val_unsigned;
5262 if (for_eh_or_skip >= 0)
5263 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5264 gcc_assert (size_of_uleb128 (r)
5265 == size_of_uleb128 (val1->v.val_unsigned));
5266 dw2_asm_output_data_uleb128 (r, NULL);
5267 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5271 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5273 case DW_OP_bit_piece:
5274 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5275 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5277 case DW_OP_deref_size:
5278 case DW_OP_xderef_size:
5279 dw2_asm_output_data (1, val1->v.val_int, NULL);
5285 if (targetm.asm_out.output_dwarf_dtprel)
5287 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5290 fputc ('\n', asm_out_file);
5297 #ifdef DWARF2_DEBUGGING_INFO
5298 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5305 case DW_OP_GNU_implicit_pointer:
5307 char label[MAX_ARTIFICIAL_LABEL_BYTES
5308 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5309 gcc_assert (val1->val_class == dw_val_class_die_ref);
5310 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5311 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5312 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5316 case DW_OP_GNU_entry_value:
5317 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5318 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5322 /* Other codes have no operands. */
5327 /* Output a sequence of location operations.
5328 The for_eh_or_skip parameter controls whether register numbers are
5329 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5330 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5331 info). This should be suppressed for the cases that have not been converted
5332 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5335 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5337 for (; loc != NULL; loc = loc->dw_loc_next)
5339 enum dwarf_location_atom opc = loc->dw_loc_opc;
5340 /* Output the opcode. */
5341 if (for_eh_or_skip >= 0
5342 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5344 unsigned r = (opc - DW_OP_breg0);
5345 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5346 gcc_assert (r <= 31);
5347 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5349 else if (for_eh_or_skip >= 0
5350 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5352 unsigned r = (opc - DW_OP_reg0);
5353 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5354 gcc_assert (r <= 31);
5355 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5358 dw2_asm_output_data (1, opc,
5359 "%s", dwarf_stack_op_name (opc));
5361 /* Output the operand(s) (if any). */
5362 output_loc_operands (loc, for_eh_or_skip);
5366 /* Output location description stack opcode's operands (if any).
5367 The output is single bytes on a line, suitable for .cfi_escape. */
5370 output_loc_operands_raw (dw_loc_descr_ref loc)
5372 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5373 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5375 switch (loc->dw_loc_opc)
5378 case DW_OP_implicit_value:
5379 /* We cannot output addresses in .cfi_escape, only bytes. */
5385 case DW_OP_deref_size:
5386 case DW_OP_xderef_size:
5387 fputc (',', asm_out_file);
5388 dw2_asm_output_data_raw (1, val1->v.val_int);
5393 fputc (',', asm_out_file);
5394 dw2_asm_output_data_raw (2, val1->v.val_int);
5399 fputc (',', asm_out_file);
5400 dw2_asm_output_data_raw (4, val1->v.val_int);
5405 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5406 fputc (',', asm_out_file);
5407 dw2_asm_output_data_raw (8, val1->v.val_int);
5415 gcc_assert (val1->val_class == dw_val_class_loc);
5416 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5418 fputc (',', asm_out_file);
5419 dw2_asm_output_data_raw (2, offset);
5425 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5426 gcc_assert (size_of_uleb128 (r)
5427 == size_of_uleb128 (val1->v.val_unsigned));
5428 fputc (',', asm_out_file);
5429 dw2_asm_output_data_uleb128_raw (r);
5434 case DW_OP_plus_uconst:
5436 fputc (',', asm_out_file);
5437 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5440 case DW_OP_bit_piece:
5441 fputc (',', asm_out_file);
5442 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5443 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5480 fputc (',', asm_out_file);
5481 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5486 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5487 gcc_assert (size_of_uleb128 (r)
5488 == size_of_uleb128 (val1->v.val_unsigned));
5489 fputc (',', asm_out_file);
5490 dw2_asm_output_data_uleb128_raw (r);
5491 fputc (',', asm_out_file);
5492 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5496 case DW_OP_GNU_implicit_pointer:
5497 case DW_OP_GNU_entry_value:
5502 /* Other codes have no operands. */
5508 output_loc_sequence_raw (dw_loc_descr_ref loc)
5512 enum dwarf_location_atom opc = loc->dw_loc_opc;
5513 /* Output the opcode. */
5514 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5516 unsigned r = (opc - DW_OP_breg0);
5517 r = DWARF2_FRAME_REG_OUT (r, 1);
5518 gcc_assert (r <= 31);
5519 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5521 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5523 unsigned r = (opc - DW_OP_reg0);
5524 r = DWARF2_FRAME_REG_OUT (r, 1);
5525 gcc_assert (r <= 31);
5526 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5528 /* Output the opcode. */
5529 fprintf (asm_out_file, "%#x", opc);
5530 output_loc_operands_raw (loc);
5532 if (!loc->dw_loc_next)
5534 loc = loc->dw_loc_next;
5536 fputc (',', asm_out_file);
5540 /* This routine will generate the correct assembly data for a location
5541 description based on a cfi entry with a complex address. */
5544 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5546 dw_loc_descr_ref loc;
5549 if (cfi->dw_cfi_opc == DW_CFA_expression)
5552 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5553 dw2_asm_output_data (1, r, NULL);
5554 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5557 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5559 /* Output the size of the block. */
5560 size = size_of_locs (loc);
5561 dw2_asm_output_data_uleb128 (size, NULL);
5563 /* Now output the operations themselves. */
5564 output_loc_sequence (loc, for_eh);
5567 /* Similar, but used for .cfi_escape. */
5570 output_cfa_loc_raw (dw_cfi_ref cfi)
5572 dw_loc_descr_ref loc;
5575 if (cfi->dw_cfi_opc == DW_CFA_expression)
5578 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5579 fprintf (asm_out_file, "%#x,", r);
5580 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5583 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5585 /* Output the size of the block. */
5586 size = size_of_locs (loc);
5587 dw2_asm_output_data_uleb128_raw (size);
5588 fputc (',', asm_out_file);
5590 /* Now output the operations themselves. */
5591 output_loc_sequence_raw (loc);
5594 /* This function builds a dwarf location descriptor sequence from a
5595 dw_cfa_location, adding the given OFFSET to the result of the
5598 static struct dw_loc_descr_struct *
5599 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5601 struct dw_loc_descr_struct *head, *tmp;
5603 offset += cfa->offset;
5607 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5608 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5609 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5610 add_loc_descr (&head, tmp);
5613 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5614 add_loc_descr (&head, tmp);
5618 head = new_reg_loc_descr (cfa->reg, offset);
5623 /* This function builds a dwarf location descriptor sequence for
5624 the address at OFFSET from the CFA when stack is aligned to
5627 static struct dw_loc_descr_struct *
5628 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5630 struct dw_loc_descr_struct *head;
5631 unsigned int dwarf_fp
5632 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5634 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5635 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5637 head = new_reg_loc_descr (dwarf_fp, 0);
5638 add_loc_descr (&head, int_loc_descriptor (alignment));
5639 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5640 loc_descr_plus_const (&head, offset);
5643 head = new_reg_loc_descr (dwarf_fp, offset);
5647 /* This function fills in aa dw_cfa_location structure from a dwarf location
5648 descriptor sequence. */
5651 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5653 struct dw_loc_descr_struct *ptr;
5655 cfa->base_offset = 0;
5659 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5661 enum dwarf_location_atom op = ptr->dw_loc_opc;
5697 cfa->reg = op - DW_OP_reg0;
5700 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5734 cfa->reg = op - DW_OP_breg0;
5735 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5738 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5739 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5744 case DW_OP_plus_uconst:
5745 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5748 internal_error ("DW_LOC_OP %s not implemented",
5749 dwarf_stack_op_name (ptr->dw_loc_opc));
5754 /* And now, the support for symbolic debugging information. */
5756 /* .debug_str support. */
5757 static int output_indirect_string (void **, void *);
5759 static void dwarf2out_init (const char *);
5760 static void dwarf2out_finish (const char *);
5761 static void dwarf2out_assembly_start (void);
5762 static void dwarf2out_define (unsigned int, const char *);
5763 static void dwarf2out_undef (unsigned int, const char *);
5764 static void dwarf2out_start_source_file (unsigned, const char *);
5765 static void dwarf2out_end_source_file (unsigned);
5766 static void dwarf2out_function_decl (tree);
5767 static void dwarf2out_begin_block (unsigned, unsigned);
5768 static void dwarf2out_end_block (unsigned, unsigned);
5769 static bool dwarf2out_ignore_block (const_tree);
5770 static void dwarf2out_global_decl (tree);
5771 static void dwarf2out_type_decl (tree, int);
5772 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5773 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5775 static void dwarf2out_abstract_function (tree);
5776 static void dwarf2out_var_location (rtx);
5777 static void dwarf2out_direct_call (tree);
5778 static void dwarf2out_virtual_call_token (tree, int);
5779 static void dwarf2out_copy_call_info (rtx, rtx);
5780 static void dwarf2out_virtual_call (int);
5781 static void dwarf2out_begin_function (tree);
5782 static void dwarf2out_set_name (tree, tree);
5784 /* The debug hooks structure. */
5786 const struct gcc_debug_hooks dwarf2_debug_hooks =
5790 dwarf2out_assembly_start,
5793 dwarf2out_start_source_file,
5794 dwarf2out_end_source_file,
5795 dwarf2out_begin_block,
5796 dwarf2out_end_block,
5797 dwarf2out_ignore_block,
5798 dwarf2out_source_line,
5799 dwarf2out_begin_prologue,
5800 #if VMS_DEBUGGING_INFO
5801 dwarf2out_vms_end_prologue,
5802 dwarf2out_vms_begin_epilogue,
5804 debug_nothing_int_charstar,
5805 debug_nothing_int_charstar,
5807 dwarf2out_end_epilogue,
5808 dwarf2out_begin_function,
5809 debug_nothing_int, /* end_function */
5810 dwarf2out_function_decl, /* function_decl */
5811 dwarf2out_global_decl,
5812 dwarf2out_type_decl, /* type_decl */
5813 dwarf2out_imported_module_or_decl,
5814 debug_nothing_tree, /* deferred_inline_function */
5815 /* The DWARF 2 backend tries to reduce debugging bloat by not
5816 emitting the abstract description of inline functions until
5817 something tries to reference them. */
5818 dwarf2out_abstract_function, /* outlining_inline_function */
5819 debug_nothing_rtx, /* label */
5820 debug_nothing_int, /* handle_pch */
5821 dwarf2out_var_location,
5822 dwarf2out_switch_text_section,
5823 dwarf2out_direct_call,
5824 dwarf2out_virtual_call_token,
5825 dwarf2out_copy_call_info,
5826 dwarf2out_virtual_call,
5828 1, /* start_end_main_source_file */
5829 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5832 /* NOTE: In the comments in this file, many references are made to
5833 "Debugging Information Entries". This term is abbreviated as `DIE'
5834 throughout the remainder of this file. */
5836 /* An internal representation of the DWARF output is built, and then
5837 walked to generate the DWARF debugging info. The walk of the internal
5838 representation is done after the entire program has been compiled.
5839 The types below are used to describe the internal representation. */
5841 /* Various DIE's use offsets relative to the beginning of the
5842 .debug_info section to refer to each other. */
5844 typedef long int dw_offset;
5846 /* Define typedefs here to avoid circular dependencies. */
5848 typedef struct dw_attr_struct *dw_attr_ref;
5849 typedef struct dw_line_info_struct *dw_line_info_ref;
5850 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5851 typedef struct pubname_struct *pubname_ref;
5852 typedef struct dw_ranges_struct *dw_ranges_ref;
5853 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5854 typedef struct comdat_type_struct *comdat_type_node_ref;
5856 /* Each entry in the line_info_table maintains the file and
5857 line number associated with the label generated for that
5858 entry. The label gives the PC value associated with
5859 the line number entry. */
5861 typedef struct GTY(()) dw_line_info_struct {
5862 unsigned long dw_file_num;
5863 unsigned long dw_line_num;
5867 /* Line information for functions in separate sections; each one gets its
5869 typedef struct GTY(()) dw_separate_line_info_struct {
5870 unsigned long dw_file_num;
5871 unsigned long dw_line_num;
5872 unsigned long function;
5874 dw_separate_line_info_entry;
5876 /* Each DIE attribute has a field specifying the attribute kind,
5877 a link to the next attribute in the chain, and an attribute value.
5878 Attributes are typically linked below the DIE they modify. */
5880 typedef struct GTY(()) dw_attr_struct {
5881 enum dwarf_attribute dw_attr;
5882 dw_val_node dw_attr_val;
5886 DEF_VEC_O(dw_attr_node);
5887 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5889 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5890 The children of each node form a circular list linked by
5891 die_sib. die_child points to the node *before* the "first" child node. */
5893 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5894 union die_symbol_or_type_node
5896 char * GTY ((tag ("0"))) die_symbol;
5897 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5899 GTY ((desc ("dwarf_version >= 4"))) die_id;
5900 VEC(dw_attr_node,gc) * die_attr;
5901 dw_die_ref die_parent;
5902 dw_die_ref die_child;
5904 dw_die_ref die_definition; /* ref from a specification to its definition */
5905 dw_offset die_offset;
5906 unsigned long die_abbrev;
5908 /* Die is used and must not be pruned as unused. */
5909 int die_perennial_p;
5910 unsigned int decl_id;
5911 enum dwarf_tag die_tag;
5915 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5916 #define FOR_EACH_CHILD(die, c, expr) do { \
5917 c = die->die_child; \
5921 } while (c != die->die_child); \
5924 /* The pubname structure */
5926 typedef struct GTY(()) pubname_struct {
5932 DEF_VEC_O(pubname_entry);
5933 DEF_VEC_ALLOC_O(pubname_entry, gc);
5935 struct GTY(()) dw_ranges_struct {
5936 /* If this is positive, it's a block number, otherwise it's a
5937 bitwise-negated index into dw_ranges_by_label. */
5941 /* A structure to hold a macinfo entry. */
5943 typedef struct GTY(()) macinfo_struct {
5944 unsigned HOST_WIDE_INT code;
5945 unsigned HOST_WIDE_INT lineno;
5950 DEF_VEC_O(macinfo_entry);
5951 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5953 struct GTY(()) dw_ranges_by_label_struct {
5958 /* The comdat type node structure. */
5959 typedef struct GTY(()) comdat_type_struct
5961 dw_die_ref root_die;
5962 dw_die_ref type_die;
5963 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5964 struct comdat_type_struct *next;
5968 /* The limbo die list structure. */
5969 typedef struct GTY(()) limbo_die_struct {
5972 struct limbo_die_struct *next;
5976 typedef struct skeleton_chain_struct
5980 struct skeleton_chain_struct *parent;
5982 skeleton_chain_node;
5984 /* How to start an assembler comment. */
5985 #ifndef ASM_COMMENT_START
5986 #define ASM_COMMENT_START ";#"
5989 /* Define a macro which returns nonzero for a TYPE_DECL which was
5990 implicitly generated for a tagged type.
5992 Note that unlike the gcc front end (which generates a NULL named
5993 TYPE_DECL node for each complete tagged type, each array type, and
5994 each function type node created) the g++ front end generates a
5995 _named_ TYPE_DECL node for each tagged type node created.
5996 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5997 generate a DW_TAG_typedef DIE for them. */
5999 #define TYPE_DECL_IS_STUB(decl) \
6000 (DECL_NAME (decl) == NULL_TREE \
6001 || (DECL_ARTIFICIAL (decl) \
6002 && is_tagged_type (TREE_TYPE (decl)) \
6003 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6004 /* This is necessary for stub decls that \
6005 appear in nested inline functions. */ \
6006 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6007 && (decl_ultimate_origin (decl) \
6008 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6010 /* Information concerning the compilation unit's programming
6011 language, and compiler version. */
6013 /* Fixed size portion of the DWARF compilation unit header. */
6014 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6015 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6017 /* Fixed size portion of the DWARF comdat type unit header. */
6018 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6019 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6020 + DWARF_OFFSET_SIZE)
6022 /* Fixed size portion of public names info. */
6023 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6025 /* Fixed size portion of the address range info. */
6026 #define DWARF_ARANGES_HEADER_SIZE \
6027 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6028 DWARF2_ADDR_SIZE * 2) \
6029 - DWARF_INITIAL_LENGTH_SIZE)
6031 /* Size of padding portion in the address range info. It must be
6032 aligned to twice the pointer size. */
6033 #define DWARF_ARANGES_PAD_SIZE \
6034 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6035 DWARF2_ADDR_SIZE * 2) \
6036 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6038 /* Use assembler line directives if available. */
6039 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6040 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6041 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6043 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6047 /* Minimum line offset in a special line info. opcode.
6048 This value was chosen to give a reasonable range of values. */
6049 #define DWARF_LINE_BASE -10
6051 /* First special line opcode - leave room for the standard opcodes. */
6052 #define DWARF_LINE_OPCODE_BASE 10
6054 /* Range of line offsets in a special line info. opcode. */
6055 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6057 /* Flag that indicates the initial value of the is_stmt_start flag.
6058 In the present implementation, we do not mark any lines as
6059 the beginning of a source statement, because that information
6060 is not made available by the GCC front-end. */
6061 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6063 /* Maximum number of operations per instruction bundle. */
6064 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6065 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6068 /* This location is used by calc_die_sizes() to keep track
6069 the offset of each DIE within the .debug_info section. */
6070 static unsigned long next_die_offset;
6072 /* Record the root of the DIE's built for the current compilation unit. */
6073 static GTY(()) dw_die_ref single_comp_unit_die;
6075 /* A list of type DIEs that have been separated into comdat sections. */
6076 static GTY(()) comdat_type_node *comdat_type_list;
6078 /* A list of DIEs with a NULL parent waiting to be relocated. */
6079 static GTY(()) limbo_die_node *limbo_die_list;
6081 /* A list of DIEs for which we may have to generate
6082 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6083 static GTY(()) limbo_die_node *deferred_asm_name;
6085 /* Filenames referenced by this compilation unit. */
6086 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6088 /* A hash table of references to DIE's that describe declarations.
6089 The key is a DECL_UID() which is a unique number identifying each decl. */
6090 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6092 /* A hash table of references to DIE's that describe COMMON blocks.
6093 The key is DECL_UID() ^ die_parent. */
6094 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6096 typedef struct GTY(()) die_arg_entry_struct {
6101 DEF_VEC_O(die_arg_entry);
6102 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6104 /* Node of the variable location list. */
6105 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6106 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6107 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6108 in mode of the EXPR_LIST node and first EXPR_LIST operand
6109 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6110 location or NULL for padding. For larger bitsizes,
6111 mode is 0 and first operand is a CONCAT with bitsize
6112 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6113 NULL as second operand. */
6115 const char * GTY (()) label;
6116 struct var_loc_node * GTY (()) next;
6119 /* Variable location list. */
6120 struct GTY (()) var_loc_list_def {
6121 struct var_loc_node * GTY (()) first;
6123 /* Pointer to the last but one or last element of the
6124 chained list. If the list is empty, both first and
6125 last are NULL, if the list contains just one node
6126 or the last node certainly is not redundant, it points
6127 to the last node, otherwise points to the last but one.
6128 Do not mark it for GC because it is marked through the chain. */
6129 struct var_loc_node * GTY ((skip ("%h"))) last;
6131 /* DECL_UID of the variable decl. */
6132 unsigned int decl_id;
6134 typedef struct var_loc_list_def var_loc_list;
6136 /* Call argument location list. */
6137 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6138 rtx GTY (()) call_arg_loc_note;
6139 const char * GTY (()) label;
6140 tree GTY (()) block;
6142 rtx GTY (()) symbol_ref;
6143 struct call_arg_loc_node * GTY (()) next;
6147 /* Table of decl location linked lists. */
6148 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6150 /* Head and tail of call_arg_loc chain. */
6151 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6152 static struct call_arg_loc_node *call_arg_loc_last;
6154 /* Number of call sites in the current function. */
6155 static int call_site_count = -1;
6156 /* Number of tail call sites in the current function. */
6157 static int tail_call_site_count = -1;
6159 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6161 static VEC (dw_die_ref, heap) *block_map;
6163 /* A pointer to the base of a list of references to DIE's that
6164 are uniquely identified by their tag, presence/absence of
6165 children DIE's, and list of attribute/value pairs. */
6166 static GTY((length ("abbrev_die_table_allocated")))
6167 dw_die_ref *abbrev_die_table;
6169 /* Number of elements currently allocated for abbrev_die_table. */
6170 static GTY(()) unsigned abbrev_die_table_allocated;
6172 /* Number of elements in type_die_table currently in use. */
6173 static GTY(()) unsigned abbrev_die_table_in_use;
6175 /* Size (in elements) of increments by which we may expand the
6176 abbrev_die_table. */
6177 #define ABBREV_DIE_TABLE_INCREMENT 256
6179 /* A pointer to the base of a table that contains line information
6180 for each source code line in .text in the compilation unit. */
6181 static GTY((length ("line_info_table_allocated")))
6182 dw_line_info_ref line_info_table;
6184 /* Number of elements currently allocated for line_info_table. */
6185 static GTY(()) unsigned line_info_table_allocated;
6187 /* Number of elements in line_info_table currently in use. */
6188 static GTY(()) unsigned line_info_table_in_use;
6190 /* A pointer to the base of a table that contains line information
6191 for each source code line outside of .text in the compilation unit. */
6192 static GTY ((length ("separate_line_info_table_allocated")))
6193 dw_separate_line_info_ref separate_line_info_table;
6195 /* Number of elements currently allocated for separate_line_info_table. */
6196 static GTY(()) unsigned separate_line_info_table_allocated;
6198 /* Number of elements in separate_line_info_table currently in use. */
6199 static GTY(()) unsigned separate_line_info_table_in_use;
6201 /* Size (in elements) of increments by which we may expand the
6203 #define LINE_INFO_TABLE_INCREMENT 1024
6205 /* A flag to tell pubnames/types export if there is an info section to
6207 static bool info_section_emitted;
6209 /* A pointer to the base of a table that contains a list of publicly
6210 accessible names. */
6211 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6213 /* A pointer to the base of a table that contains a list of publicly
6214 accessible types. */
6215 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6217 /* A pointer to the base of a table that contains a list of macro
6218 defines/undefines (and file start/end markers). */
6219 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6221 /* Array of dies for which we should generate .debug_arange info. */
6222 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
6224 /* Number of elements currently allocated for arange_table. */
6225 static GTY(()) unsigned arange_table_allocated;
6227 /* Number of elements in arange_table currently in use. */
6228 static GTY(()) unsigned arange_table_in_use;
6230 /* Size (in elements) of increments by which we may expand the
6232 #define ARANGE_TABLE_INCREMENT 64
6234 /* Array of dies for which we should generate .debug_ranges info. */
6235 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6237 /* Number of elements currently allocated for ranges_table. */
6238 static GTY(()) unsigned ranges_table_allocated;
6240 /* Number of elements in ranges_table currently in use. */
6241 static GTY(()) unsigned ranges_table_in_use;
6243 /* Array of pairs of labels referenced in ranges_table. */
6244 static GTY ((length ("ranges_by_label_allocated")))
6245 dw_ranges_by_label_ref ranges_by_label;
6247 /* Number of elements currently allocated for ranges_by_label. */
6248 static GTY(()) unsigned ranges_by_label_allocated;
6250 /* Number of elements in ranges_by_label currently in use. */
6251 static GTY(()) unsigned ranges_by_label_in_use;
6253 /* Size (in elements) of increments by which we may expand the
6255 #define RANGES_TABLE_INCREMENT 64
6257 /* Whether we have location lists that need outputting */
6258 static GTY(()) bool have_location_lists;
6260 /* Unique label counter. */
6261 static GTY(()) unsigned int loclabel_num;
6263 /* Unique label counter for point-of-call tables. */
6264 static GTY(()) unsigned int poc_label_num;
6266 /* The direct call table structure. */
6268 typedef struct GTY(()) dcall_struct {
6269 unsigned int poc_label_num;
6271 dw_die_ref targ_die;
6275 DEF_VEC_O(dcall_entry);
6276 DEF_VEC_ALLOC_O(dcall_entry, gc);
6278 /* The virtual call table structure. */
6280 typedef struct GTY(()) vcall_struct {
6281 unsigned int poc_label_num;
6282 unsigned int vtable_slot;
6286 DEF_VEC_O(vcall_entry);
6287 DEF_VEC_ALLOC_O(vcall_entry, gc);
6289 /* Pointers to the direct and virtual call tables. */
6290 static GTY (()) VEC (dcall_entry, gc) * dcall_table = NULL;
6291 static GTY (()) VEC (vcall_entry, gc) * vcall_table = NULL;
6293 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6295 struct GTY (()) vcall_insn {
6297 unsigned int vtable_slot;
6300 static GTY ((param_is (struct vcall_insn))) htab_t vcall_insn_table;
6302 /* Record whether the function being analyzed contains inlined functions. */
6303 static int current_function_has_inlines;
6305 /* The last file entry emitted by maybe_emit_file(). */
6306 static GTY(()) struct dwarf_file_data * last_emitted_file;
6308 /* Number of internal labels generated by gen_internal_sym(). */
6309 static GTY(()) int label_num;
6311 /* Cached result of previous call to lookup_filename. */
6312 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6314 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6316 /* Instances of generic types for which we need to generate debug
6317 info that describe their generic parameters and arguments. That
6318 generation needs to happen once all types are properly laid out so
6319 we do it at the end of compilation. */
6320 static GTY(()) VEC(tree,gc) *generic_type_instances;
6322 /* Offset from the "steady-state frame pointer" to the frame base,
6323 within the current function. */
6324 static HOST_WIDE_INT frame_pointer_fb_offset;
6326 /* Forward declarations for functions defined in this file. */
6328 static int is_pseudo_reg (const_rtx);
6329 static tree type_main_variant (tree);
6330 static int is_tagged_type (const_tree);
6331 static const char *dwarf_tag_name (unsigned);
6332 static const char *dwarf_attr_name (unsigned);
6333 static const char *dwarf_form_name (unsigned);
6334 static tree decl_ultimate_origin (const_tree);
6335 static tree decl_class_context (tree);
6336 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6337 static inline enum dw_val_class AT_class (dw_attr_ref);
6338 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6339 static inline unsigned AT_flag (dw_attr_ref);
6340 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6341 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6342 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6343 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6344 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6345 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6346 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6347 unsigned int, unsigned char *);
6348 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6349 static hashval_t debug_str_do_hash (const void *);
6350 static int debug_str_eq (const void *, const void *);
6351 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6352 static inline const char *AT_string (dw_attr_ref);
6353 static enum dwarf_form AT_string_form (dw_attr_ref);
6354 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6355 static void add_AT_specification (dw_die_ref, dw_die_ref);
6356 static inline dw_die_ref AT_ref (dw_attr_ref);
6357 static inline int AT_ref_external (dw_attr_ref);
6358 static inline void set_AT_ref_external (dw_attr_ref, int);
6359 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6360 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6361 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6362 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6364 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6365 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6366 static inline rtx AT_addr (dw_attr_ref);
6367 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6368 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6369 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6370 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6371 unsigned HOST_WIDE_INT);
6372 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6374 static inline const char *AT_lbl (dw_attr_ref);
6375 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6376 static const char *get_AT_low_pc (dw_die_ref);
6377 static const char *get_AT_hi_pc (dw_die_ref);
6378 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6379 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6380 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6381 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6382 static bool is_cxx (void);
6383 static bool is_fortran (void);
6384 static bool is_ada (void);
6385 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6386 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6387 static void add_child_die (dw_die_ref, dw_die_ref);
6388 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6389 static dw_die_ref lookup_type_die (tree);
6390 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6391 static void equate_type_number_to_die (tree, dw_die_ref);
6392 static hashval_t decl_die_table_hash (const void *);
6393 static int decl_die_table_eq (const void *, const void *);
6394 static dw_die_ref lookup_decl_die (tree);
6395 static hashval_t common_block_die_table_hash (const void *);
6396 static int common_block_die_table_eq (const void *, const void *);
6397 static hashval_t decl_loc_table_hash (const void *);
6398 static int decl_loc_table_eq (const void *, const void *);
6399 static var_loc_list *lookup_decl_loc (const_tree);
6400 static void equate_decl_number_to_die (tree, dw_die_ref);
6401 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6402 static void print_spaces (FILE *);
6403 static void print_die (dw_die_ref, FILE *);
6404 static void print_dwarf_line_table (FILE *);
6405 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6406 static dw_die_ref pop_compile_unit (dw_die_ref);
6407 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6408 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6409 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6410 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6411 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6412 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6413 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6414 struct md5_ctx *, int *);
6415 struct checksum_attributes;
6416 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6417 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6418 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6419 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6420 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6421 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6422 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6423 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6424 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6425 static void compute_section_prefix (dw_die_ref);
6426 static int is_type_die (dw_die_ref);
6427 static int is_comdat_die (dw_die_ref);
6428 static int is_symbol_die (dw_die_ref);
6429 static void assign_symbol_names (dw_die_ref);
6430 static void break_out_includes (dw_die_ref);
6431 static int is_declaration_die (dw_die_ref);
6432 static int should_move_die_to_comdat (dw_die_ref);
6433 static dw_die_ref clone_as_declaration (dw_die_ref);
6434 static dw_die_ref clone_die (dw_die_ref);
6435 static dw_die_ref clone_tree (dw_die_ref);
6436 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6437 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6438 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6439 static dw_die_ref generate_skeleton (dw_die_ref);
6440 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6442 static void break_out_comdat_types (dw_die_ref);
6443 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6444 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6445 static void copy_decls_for_unworthy_types (dw_die_ref);
6447 static hashval_t htab_cu_hash (const void *);
6448 static int htab_cu_eq (const void *, const void *);
6449 static void htab_cu_del (void *);
6450 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6451 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6452 static void add_sibling_attributes (dw_die_ref);
6453 static void build_abbrev_table (dw_die_ref);
6454 static void output_location_lists (dw_die_ref);
6455 static int constant_size (unsigned HOST_WIDE_INT);
6456 static unsigned long size_of_die (dw_die_ref);
6457 static void calc_die_sizes (dw_die_ref);
6458 static void mark_dies (dw_die_ref);
6459 static void unmark_dies (dw_die_ref);
6460 static void unmark_all_dies (dw_die_ref);
6461 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6462 static unsigned long size_of_aranges (void);
6463 static enum dwarf_form value_format (dw_attr_ref);
6464 static void output_value_format (dw_attr_ref);
6465 static void output_abbrev_section (void);
6466 static void output_die_symbol (dw_die_ref);
6467 static void output_die (dw_die_ref);
6468 static void output_compilation_unit_header (void);
6469 static void output_comp_unit (dw_die_ref, int);
6470 static void output_comdat_type_unit (comdat_type_node *);
6471 static const char *dwarf2_name (tree, int);
6472 static void add_pubname (tree, dw_die_ref);
6473 static void add_pubname_string (const char *, dw_die_ref);
6474 static void add_pubtype (tree, dw_die_ref);
6475 static void output_pubnames (VEC (pubname_entry,gc) *);
6476 static void add_arange (tree, dw_die_ref);
6477 static void output_aranges (void);
6478 static unsigned int add_ranges_num (int);
6479 static unsigned int add_ranges (const_tree);
6480 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6482 static void output_ranges (void);
6483 static void output_line_info (void);
6484 static void output_file_names (void);
6485 static dw_die_ref base_type_die (tree);
6486 static int is_base_type (tree);
6487 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6488 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6489 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6490 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6491 static int type_is_enum (const_tree);
6492 static unsigned int dbx_reg_number (const_rtx);
6493 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6494 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6495 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6496 enum var_init_status);
6497 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6498 enum var_init_status);
6499 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6500 enum var_init_status);
6501 static int is_based_loc (const_rtx);
6502 static int resolve_one_addr (rtx *, void *);
6503 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6504 enum var_init_status);
6505 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6506 enum var_init_status);
6507 static dw_loc_list_ref loc_list_from_tree (tree, int);
6508 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6509 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6510 static tree field_type (const_tree);
6511 static unsigned int simple_type_align_in_bits (const_tree);
6512 static unsigned int simple_decl_align_in_bits (const_tree);
6513 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6514 static HOST_WIDE_INT field_byte_offset (const_tree);
6515 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6517 static void add_data_member_location_attribute (dw_die_ref, tree);
6518 static bool add_const_value_attribute (dw_die_ref, rtx);
6519 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6520 static void insert_double (double_int, unsigned char *);
6521 static void insert_float (const_rtx, unsigned char *);
6522 static rtx rtl_for_decl_location (tree);
6523 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6524 enum dwarf_attribute);
6525 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6526 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6527 static void add_name_attribute (dw_die_ref, const char *);
6528 static void add_comp_dir_attribute (dw_die_ref);
6529 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6530 static void add_subscript_info (dw_die_ref, tree, bool);
6531 static void add_byte_size_attribute (dw_die_ref, tree);
6532 static void add_bit_offset_attribute (dw_die_ref, tree);
6533 static void add_bit_size_attribute (dw_die_ref, tree);
6534 static void add_prototyped_attribute (dw_die_ref, tree);
6535 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6536 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6537 static void add_src_coords_attributes (dw_die_ref, tree);
6538 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6539 static void push_decl_scope (tree);
6540 static void pop_decl_scope (void);
6541 static dw_die_ref scope_die_for (tree, dw_die_ref);
6542 static inline int local_scope_p (dw_die_ref);
6543 static inline int class_scope_p (dw_die_ref);
6544 static inline int class_or_namespace_scope_p (dw_die_ref);
6545 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6546 static void add_calling_convention_attribute (dw_die_ref, tree);
6547 static const char *type_tag (const_tree);
6548 static tree member_declared_type (const_tree);
6550 static const char *decl_start_label (tree);
6552 static void gen_array_type_die (tree, dw_die_ref);
6553 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6555 static void gen_entry_point_die (tree, dw_die_ref);
6557 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6558 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6559 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6560 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6561 static void gen_formal_types_die (tree, dw_die_ref);
6562 static void gen_subprogram_die (tree, dw_die_ref);
6563 static void gen_variable_die (tree, tree, dw_die_ref);
6564 static void gen_const_die (tree, dw_die_ref);
6565 static void gen_label_die (tree, dw_die_ref);
6566 static void gen_lexical_block_die (tree, dw_die_ref, int);
6567 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6568 static void gen_field_die (tree, dw_die_ref);
6569 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6570 static dw_die_ref gen_compile_unit_die (const char *);
6571 static void gen_inheritance_die (tree, tree, dw_die_ref);
6572 static void gen_member_die (tree, dw_die_ref);
6573 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6574 enum debug_info_usage);
6575 static void gen_subroutine_type_die (tree, dw_die_ref);
6576 static void gen_typedef_die (tree, dw_die_ref);
6577 static void gen_type_die (tree, dw_die_ref);
6578 static void gen_block_die (tree, dw_die_ref, int);
6579 static void decls_for_scope (tree, dw_die_ref, int);
6580 static int is_redundant_typedef (const_tree);
6581 static bool is_naming_typedef_decl (const_tree);
6582 static inline dw_die_ref get_context_die (tree);
6583 static void gen_namespace_die (tree, dw_die_ref);
6584 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6585 static dw_die_ref force_decl_die (tree);
6586 static dw_die_ref force_type_die (tree);
6587 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6588 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6589 static struct dwarf_file_data * lookup_filename (const char *);
6590 static void retry_incomplete_types (void);
6591 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6592 static void gen_generic_params_dies (tree);
6593 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6594 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6595 static void splice_child_die (dw_die_ref, dw_die_ref);
6596 static int file_info_cmp (const void *, const void *);
6597 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6598 const char *, const char *);
6599 static void output_loc_list (dw_loc_list_ref);
6600 static char *gen_internal_sym (const char *);
6602 static void prune_unmark_dies (dw_die_ref);
6603 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6604 static void prune_unused_types_mark (dw_die_ref, int);
6605 static void prune_unused_types_walk (dw_die_ref);
6606 static void prune_unused_types_walk_attribs (dw_die_ref);
6607 static void prune_unused_types_prune (dw_die_ref);
6608 static void prune_unused_types (void);
6609 static int maybe_emit_file (struct dwarf_file_data *fd);
6610 static inline const char *AT_vms_delta1 (dw_attr_ref);
6611 static inline const char *AT_vms_delta2 (dw_attr_ref);
6612 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6613 const char *, const char *);
6614 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6615 static void gen_remaining_tmpl_value_param_die_attribute (void);
6616 static bool generic_type_p (tree);
6617 static void schedule_generic_params_dies_gen (tree t);
6618 static void gen_scheduled_generic_parms_dies (void);
6620 /* Section names used to hold DWARF debugging information. */
6621 #ifndef DEBUG_INFO_SECTION
6622 #define DEBUG_INFO_SECTION ".debug_info"
6624 #ifndef DEBUG_ABBREV_SECTION
6625 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6627 #ifndef DEBUG_ARANGES_SECTION
6628 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6630 #ifndef DEBUG_MACINFO_SECTION
6631 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6633 #ifndef DEBUG_LINE_SECTION
6634 #define DEBUG_LINE_SECTION ".debug_line"
6636 #ifndef DEBUG_LOC_SECTION
6637 #define DEBUG_LOC_SECTION ".debug_loc"
6639 #ifndef DEBUG_PUBNAMES_SECTION
6640 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6642 #ifndef DEBUG_PUBTYPES_SECTION
6643 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6645 #ifndef DEBUG_DCALL_SECTION
6646 #define DEBUG_DCALL_SECTION ".debug_dcall"
6648 #ifndef DEBUG_VCALL_SECTION
6649 #define DEBUG_VCALL_SECTION ".debug_vcall"
6651 #ifndef DEBUG_STR_SECTION
6652 #define DEBUG_STR_SECTION ".debug_str"
6654 #ifndef DEBUG_RANGES_SECTION
6655 #define DEBUG_RANGES_SECTION ".debug_ranges"
6658 /* Standard ELF section names for compiled code and data. */
6659 #ifndef TEXT_SECTION_NAME
6660 #define TEXT_SECTION_NAME ".text"
6663 /* Section flags for .debug_str section. */
6664 #define DEBUG_STR_SECTION_FLAGS \
6665 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6666 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6669 /* Labels we insert at beginning sections we can reference instead of
6670 the section names themselves. */
6672 #ifndef TEXT_SECTION_LABEL
6673 #define TEXT_SECTION_LABEL "Ltext"
6675 #ifndef COLD_TEXT_SECTION_LABEL
6676 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6678 #ifndef DEBUG_LINE_SECTION_LABEL
6679 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6681 #ifndef DEBUG_INFO_SECTION_LABEL
6682 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6684 #ifndef DEBUG_ABBREV_SECTION_LABEL
6685 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6687 #ifndef DEBUG_LOC_SECTION_LABEL
6688 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6690 #ifndef DEBUG_RANGES_SECTION_LABEL
6691 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6693 #ifndef DEBUG_MACINFO_SECTION_LABEL
6694 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6698 /* Definitions of defaults for formats and names of various special
6699 (artificial) labels which may be generated within this file (when the -g
6700 options is used and DWARF2_DEBUGGING_INFO is in effect.
6701 If necessary, these may be overridden from within the tm.h file, but
6702 typically, overriding these defaults is unnecessary. */
6704 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6705 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6706 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6707 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6708 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6709 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6710 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6711 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6712 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6713 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6715 #ifndef TEXT_END_LABEL
6716 #define TEXT_END_LABEL "Letext"
6718 #ifndef COLD_END_LABEL
6719 #define COLD_END_LABEL "Letext_cold"
6721 #ifndef BLOCK_BEGIN_LABEL
6722 #define BLOCK_BEGIN_LABEL "LBB"
6724 #ifndef BLOCK_END_LABEL
6725 #define BLOCK_END_LABEL "LBE"
6727 #ifndef LINE_CODE_LABEL
6728 #define LINE_CODE_LABEL "LM"
6730 #ifndef SEPARATE_LINE_CODE_LABEL
6731 #define SEPARATE_LINE_CODE_LABEL "LSM"
6735 /* Return the root of the DIE's built for the current compilation unit. */
6737 comp_unit_die (void)
6739 if (!single_comp_unit_die)
6740 single_comp_unit_die = gen_compile_unit_die (NULL);
6741 return single_comp_unit_die;
6744 /* We allow a language front-end to designate a function that is to be
6745 called to "demangle" any name before it is put into a DIE. */
6747 static const char *(*demangle_name_func) (const char *);
6750 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6752 demangle_name_func = func;
6755 /* Test if rtl node points to a pseudo register. */
6758 is_pseudo_reg (const_rtx rtl)
6760 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6761 || (GET_CODE (rtl) == SUBREG
6762 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6765 /* Return a reference to a type, with its const and volatile qualifiers
6769 type_main_variant (tree type)
6771 type = TYPE_MAIN_VARIANT (type);
6773 /* ??? There really should be only one main variant among any group of
6774 variants of a given type (and all of the MAIN_VARIANT values for all
6775 members of the group should point to that one type) but sometimes the C
6776 front-end messes this up for array types, so we work around that bug
6778 if (TREE_CODE (type) == ARRAY_TYPE)
6779 while (type != TYPE_MAIN_VARIANT (type))
6780 type = TYPE_MAIN_VARIANT (type);
6785 /* Return nonzero if the given type node represents a tagged type. */
6788 is_tagged_type (const_tree type)
6790 enum tree_code code = TREE_CODE (type);
6792 return (code == RECORD_TYPE || code == UNION_TYPE
6793 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6796 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6799 get_ref_die_offset_label (char *label, dw_die_ref ref)
6801 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6804 /* Convert a DIE tag into its string name. */
6807 dwarf_tag_name (unsigned int tag)
6811 case DW_TAG_padding:
6812 return "DW_TAG_padding";
6813 case DW_TAG_array_type:
6814 return "DW_TAG_array_type";
6815 case DW_TAG_class_type:
6816 return "DW_TAG_class_type";
6817 case DW_TAG_entry_point:
6818 return "DW_TAG_entry_point";
6819 case DW_TAG_enumeration_type:
6820 return "DW_TAG_enumeration_type";
6821 case DW_TAG_formal_parameter:
6822 return "DW_TAG_formal_parameter";
6823 case DW_TAG_imported_declaration:
6824 return "DW_TAG_imported_declaration";
6826 return "DW_TAG_label";
6827 case DW_TAG_lexical_block:
6828 return "DW_TAG_lexical_block";
6830 return "DW_TAG_member";
6831 case DW_TAG_pointer_type:
6832 return "DW_TAG_pointer_type";
6833 case DW_TAG_reference_type:
6834 return "DW_TAG_reference_type";
6835 case DW_TAG_compile_unit:
6836 return "DW_TAG_compile_unit";
6837 case DW_TAG_string_type:
6838 return "DW_TAG_string_type";
6839 case DW_TAG_structure_type:
6840 return "DW_TAG_structure_type";
6841 case DW_TAG_subroutine_type:
6842 return "DW_TAG_subroutine_type";
6843 case DW_TAG_typedef:
6844 return "DW_TAG_typedef";
6845 case DW_TAG_union_type:
6846 return "DW_TAG_union_type";
6847 case DW_TAG_unspecified_parameters:
6848 return "DW_TAG_unspecified_parameters";
6849 case DW_TAG_variant:
6850 return "DW_TAG_variant";
6851 case DW_TAG_common_block:
6852 return "DW_TAG_common_block";
6853 case DW_TAG_common_inclusion:
6854 return "DW_TAG_common_inclusion";
6855 case DW_TAG_inheritance:
6856 return "DW_TAG_inheritance";
6857 case DW_TAG_inlined_subroutine:
6858 return "DW_TAG_inlined_subroutine";
6860 return "DW_TAG_module";
6861 case DW_TAG_ptr_to_member_type:
6862 return "DW_TAG_ptr_to_member_type";
6863 case DW_TAG_set_type:
6864 return "DW_TAG_set_type";
6865 case DW_TAG_subrange_type:
6866 return "DW_TAG_subrange_type";
6867 case DW_TAG_with_stmt:
6868 return "DW_TAG_with_stmt";
6869 case DW_TAG_access_declaration:
6870 return "DW_TAG_access_declaration";
6871 case DW_TAG_base_type:
6872 return "DW_TAG_base_type";
6873 case DW_TAG_catch_block:
6874 return "DW_TAG_catch_block";
6875 case DW_TAG_const_type:
6876 return "DW_TAG_const_type";
6877 case DW_TAG_constant:
6878 return "DW_TAG_constant";
6879 case DW_TAG_enumerator:
6880 return "DW_TAG_enumerator";
6881 case DW_TAG_file_type:
6882 return "DW_TAG_file_type";
6884 return "DW_TAG_friend";
6885 case DW_TAG_namelist:
6886 return "DW_TAG_namelist";
6887 case DW_TAG_namelist_item:
6888 return "DW_TAG_namelist_item";
6889 case DW_TAG_packed_type:
6890 return "DW_TAG_packed_type";
6891 case DW_TAG_subprogram:
6892 return "DW_TAG_subprogram";
6893 case DW_TAG_template_type_param:
6894 return "DW_TAG_template_type_param";
6895 case DW_TAG_template_value_param:
6896 return "DW_TAG_template_value_param";
6897 case DW_TAG_thrown_type:
6898 return "DW_TAG_thrown_type";
6899 case DW_TAG_try_block:
6900 return "DW_TAG_try_block";
6901 case DW_TAG_variant_part:
6902 return "DW_TAG_variant_part";
6903 case DW_TAG_variable:
6904 return "DW_TAG_variable";
6905 case DW_TAG_volatile_type:
6906 return "DW_TAG_volatile_type";
6907 case DW_TAG_dwarf_procedure:
6908 return "DW_TAG_dwarf_procedure";
6909 case DW_TAG_restrict_type:
6910 return "DW_TAG_restrict_type";
6911 case DW_TAG_interface_type:
6912 return "DW_TAG_interface_type";
6913 case DW_TAG_namespace:
6914 return "DW_TAG_namespace";
6915 case DW_TAG_imported_module:
6916 return "DW_TAG_imported_module";
6917 case DW_TAG_unspecified_type:
6918 return "DW_TAG_unspecified_type";
6919 case DW_TAG_partial_unit:
6920 return "DW_TAG_partial_unit";
6921 case DW_TAG_imported_unit:
6922 return "DW_TAG_imported_unit";
6923 case DW_TAG_condition:
6924 return "DW_TAG_condition";
6925 case DW_TAG_shared_type:
6926 return "DW_TAG_shared_type";
6927 case DW_TAG_type_unit:
6928 return "DW_TAG_type_unit";
6929 case DW_TAG_rvalue_reference_type:
6930 return "DW_TAG_rvalue_reference_type";
6931 case DW_TAG_template_alias:
6932 return "DW_TAG_template_alias";
6933 case DW_TAG_GNU_template_parameter_pack:
6934 return "DW_TAG_GNU_template_parameter_pack";
6935 case DW_TAG_GNU_formal_parameter_pack:
6936 return "DW_TAG_GNU_formal_parameter_pack";
6937 case DW_TAG_MIPS_loop:
6938 return "DW_TAG_MIPS_loop";
6939 case DW_TAG_format_label:
6940 return "DW_TAG_format_label";
6941 case DW_TAG_function_template:
6942 return "DW_TAG_function_template";
6943 case DW_TAG_class_template:
6944 return "DW_TAG_class_template";
6945 case DW_TAG_GNU_BINCL:
6946 return "DW_TAG_GNU_BINCL";
6947 case DW_TAG_GNU_EINCL:
6948 return "DW_TAG_GNU_EINCL";
6949 case DW_TAG_GNU_template_template_param:
6950 return "DW_TAG_GNU_template_template_param";
6951 case DW_TAG_GNU_call_site:
6952 return "DW_TAG_GNU_call_site";
6953 case DW_TAG_GNU_call_site_parameter:
6954 return "DW_TAG_GNU_call_site_parameter";
6956 return "DW_TAG_<unknown>";
6960 /* Convert a DWARF attribute code into its string name. */
6963 dwarf_attr_name (unsigned int attr)
6968 return "DW_AT_sibling";
6969 case DW_AT_location:
6970 return "DW_AT_location";
6972 return "DW_AT_name";
6973 case DW_AT_ordering:
6974 return "DW_AT_ordering";
6975 case DW_AT_subscr_data:
6976 return "DW_AT_subscr_data";
6977 case DW_AT_byte_size:
6978 return "DW_AT_byte_size";
6979 case DW_AT_bit_offset:
6980 return "DW_AT_bit_offset";
6981 case DW_AT_bit_size:
6982 return "DW_AT_bit_size";
6983 case DW_AT_element_list:
6984 return "DW_AT_element_list";
6985 case DW_AT_stmt_list:
6986 return "DW_AT_stmt_list";
6988 return "DW_AT_low_pc";
6990 return "DW_AT_high_pc";
6991 case DW_AT_language:
6992 return "DW_AT_language";
6994 return "DW_AT_member";
6996 return "DW_AT_discr";
6997 case DW_AT_discr_value:
6998 return "DW_AT_discr_value";
6999 case DW_AT_visibility:
7000 return "DW_AT_visibility";
7002 return "DW_AT_import";
7003 case DW_AT_string_length:
7004 return "DW_AT_string_length";
7005 case DW_AT_common_reference:
7006 return "DW_AT_common_reference";
7007 case DW_AT_comp_dir:
7008 return "DW_AT_comp_dir";
7009 case DW_AT_const_value:
7010 return "DW_AT_const_value";
7011 case DW_AT_containing_type:
7012 return "DW_AT_containing_type";
7013 case DW_AT_default_value:
7014 return "DW_AT_default_value";
7016 return "DW_AT_inline";
7017 case DW_AT_is_optional:
7018 return "DW_AT_is_optional";
7019 case DW_AT_lower_bound:
7020 return "DW_AT_lower_bound";
7021 case DW_AT_producer:
7022 return "DW_AT_producer";
7023 case DW_AT_prototyped:
7024 return "DW_AT_prototyped";
7025 case DW_AT_return_addr:
7026 return "DW_AT_return_addr";
7027 case DW_AT_start_scope:
7028 return "DW_AT_start_scope";
7029 case DW_AT_bit_stride:
7030 return "DW_AT_bit_stride";
7031 case DW_AT_upper_bound:
7032 return "DW_AT_upper_bound";
7033 case DW_AT_abstract_origin:
7034 return "DW_AT_abstract_origin";
7035 case DW_AT_accessibility:
7036 return "DW_AT_accessibility";
7037 case DW_AT_address_class:
7038 return "DW_AT_address_class";
7039 case DW_AT_artificial:
7040 return "DW_AT_artificial";
7041 case DW_AT_base_types:
7042 return "DW_AT_base_types";
7043 case DW_AT_calling_convention:
7044 return "DW_AT_calling_convention";
7046 return "DW_AT_count";
7047 case DW_AT_data_member_location:
7048 return "DW_AT_data_member_location";
7049 case DW_AT_decl_column:
7050 return "DW_AT_decl_column";
7051 case DW_AT_decl_file:
7052 return "DW_AT_decl_file";
7053 case DW_AT_decl_line:
7054 return "DW_AT_decl_line";
7055 case DW_AT_declaration:
7056 return "DW_AT_declaration";
7057 case DW_AT_discr_list:
7058 return "DW_AT_discr_list";
7059 case DW_AT_encoding:
7060 return "DW_AT_encoding";
7061 case DW_AT_external:
7062 return "DW_AT_external";
7063 case DW_AT_explicit:
7064 return "DW_AT_explicit";
7065 case DW_AT_frame_base:
7066 return "DW_AT_frame_base";
7068 return "DW_AT_friend";
7069 case DW_AT_identifier_case:
7070 return "DW_AT_identifier_case";
7071 case DW_AT_macro_info:
7072 return "DW_AT_macro_info";
7073 case DW_AT_namelist_items:
7074 return "DW_AT_namelist_items";
7075 case DW_AT_priority:
7076 return "DW_AT_priority";
7078 return "DW_AT_segment";
7079 case DW_AT_specification:
7080 return "DW_AT_specification";
7081 case DW_AT_static_link:
7082 return "DW_AT_static_link";
7084 return "DW_AT_type";
7085 case DW_AT_use_location:
7086 return "DW_AT_use_location";
7087 case DW_AT_variable_parameter:
7088 return "DW_AT_variable_parameter";
7089 case DW_AT_virtuality:
7090 return "DW_AT_virtuality";
7091 case DW_AT_vtable_elem_location:
7092 return "DW_AT_vtable_elem_location";
7094 case DW_AT_allocated:
7095 return "DW_AT_allocated";
7096 case DW_AT_associated:
7097 return "DW_AT_associated";
7098 case DW_AT_data_location:
7099 return "DW_AT_data_location";
7100 case DW_AT_byte_stride:
7101 return "DW_AT_byte_stride";
7102 case DW_AT_entry_pc:
7103 return "DW_AT_entry_pc";
7104 case DW_AT_use_UTF8:
7105 return "DW_AT_use_UTF8";
7106 case DW_AT_extension:
7107 return "DW_AT_extension";
7109 return "DW_AT_ranges";
7110 case DW_AT_trampoline:
7111 return "DW_AT_trampoline";
7112 case DW_AT_call_column:
7113 return "DW_AT_call_column";
7114 case DW_AT_call_file:
7115 return "DW_AT_call_file";
7116 case DW_AT_call_line:
7117 return "DW_AT_call_line";
7118 case DW_AT_object_pointer:
7119 return "DW_AT_object_pointer";
7121 case DW_AT_signature:
7122 return "DW_AT_signature";
7123 case DW_AT_main_subprogram:
7124 return "DW_AT_main_subprogram";
7125 case DW_AT_data_bit_offset:
7126 return "DW_AT_data_bit_offset";
7127 case DW_AT_const_expr:
7128 return "DW_AT_const_expr";
7129 case DW_AT_enum_class:
7130 return "DW_AT_enum_class";
7131 case DW_AT_linkage_name:
7132 return "DW_AT_linkage_name";
7134 case DW_AT_MIPS_fde:
7135 return "DW_AT_MIPS_fde";
7136 case DW_AT_MIPS_loop_begin:
7137 return "DW_AT_MIPS_loop_begin";
7138 case DW_AT_MIPS_tail_loop_begin:
7139 return "DW_AT_MIPS_tail_loop_begin";
7140 case DW_AT_MIPS_epilog_begin:
7141 return "DW_AT_MIPS_epilog_begin";
7142 #if VMS_DEBUGGING_INFO
7143 case DW_AT_HP_prologue:
7144 return "DW_AT_HP_prologue";
7146 case DW_AT_MIPS_loop_unroll_factor:
7147 return "DW_AT_MIPS_loop_unroll_factor";
7149 case DW_AT_MIPS_software_pipeline_depth:
7150 return "DW_AT_MIPS_software_pipeline_depth";
7151 case DW_AT_MIPS_linkage_name:
7152 return "DW_AT_MIPS_linkage_name";
7153 #if VMS_DEBUGGING_INFO
7154 case DW_AT_HP_epilogue:
7155 return "DW_AT_HP_epilogue";
7157 case DW_AT_MIPS_stride:
7158 return "DW_AT_MIPS_stride";
7160 case DW_AT_MIPS_abstract_name:
7161 return "DW_AT_MIPS_abstract_name";
7162 case DW_AT_MIPS_clone_origin:
7163 return "DW_AT_MIPS_clone_origin";
7164 case DW_AT_MIPS_has_inlines:
7165 return "DW_AT_MIPS_has_inlines";
7167 case DW_AT_sf_names:
7168 return "DW_AT_sf_names";
7169 case DW_AT_src_info:
7170 return "DW_AT_src_info";
7171 case DW_AT_mac_info:
7172 return "DW_AT_mac_info";
7173 case DW_AT_src_coords:
7174 return "DW_AT_src_coords";
7175 case DW_AT_body_begin:
7176 return "DW_AT_body_begin";
7177 case DW_AT_body_end:
7178 return "DW_AT_body_end";
7179 case DW_AT_GNU_vector:
7180 return "DW_AT_GNU_vector";
7181 case DW_AT_GNU_guarded_by:
7182 return "DW_AT_GNU_guarded_by";
7183 case DW_AT_GNU_pt_guarded_by:
7184 return "DW_AT_GNU_pt_guarded_by";
7185 case DW_AT_GNU_guarded:
7186 return "DW_AT_GNU_guarded";
7187 case DW_AT_GNU_pt_guarded:
7188 return "DW_AT_GNU_pt_guarded";
7189 case DW_AT_GNU_locks_excluded:
7190 return "DW_AT_GNU_locks_excluded";
7191 case DW_AT_GNU_exclusive_locks_required:
7192 return "DW_AT_GNU_exclusive_locks_required";
7193 case DW_AT_GNU_shared_locks_required:
7194 return "DW_AT_GNU_shared_locks_required";
7195 case DW_AT_GNU_odr_signature:
7196 return "DW_AT_GNU_odr_signature";
7197 case DW_AT_GNU_template_name:
7198 return "DW_AT_GNU_template_name";
7199 case DW_AT_GNU_call_site_value:
7200 return "DW_AT_GNU_call_site_value";
7201 case DW_AT_GNU_call_site_data_value:
7202 return "DW_AT_GNU_call_site_data_value";
7203 case DW_AT_GNU_call_site_target:
7204 return "DW_AT_GNU_call_site_target";
7205 case DW_AT_GNU_call_site_target_clobbered:
7206 return "DW_AT_GNU_call_site_target_clobbered";
7207 case DW_AT_GNU_tail_call:
7208 return "DW_AT_GNU_tail_call";
7209 case DW_AT_GNU_all_tail_call_sites:
7210 return "DW_AT_GNU_all_tail_call_sites";
7211 case DW_AT_GNU_all_call_sites:
7212 return "DW_AT_GNU_all_call_sites";
7213 case DW_AT_GNU_all_source_call_sites:
7214 return "DW_AT_GNU_all_source_call_sites";
7216 case DW_AT_VMS_rtnbeg_pd_address:
7217 return "DW_AT_VMS_rtnbeg_pd_address";
7220 return "DW_AT_<unknown>";
7224 /* Convert a DWARF value form code into its string name. */
7227 dwarf_form_name (unsigned int form)
7232 return "DW_FORM_addr";
7233 case DW_FORM_block2:
7234 return "DW_FORM_block2";
7235 case DW_FORM_block4:
7236 return "DW_FORM_block4";
7238 return "DW_FORM_data2";
7240 return "DW_FORM_data4";
7242 return "DW_FORM_data8";
7243 case DW_FORM_string:
7244 return "DW_FORM_string";
7246 return "DW_FORM_block";
7247 case DW_FORM_block1:
7248 return "DW_FORM_block1";
7250 return "DW_FORM_data1";
7252 return "DW_FORM_flag";
7254 return "DW_FORM_sdata";
7256 return "DW_FORM_strp";
7258 return "DW_FORM_udata";
7259 case DW_FORM_ref_addr:
7260 return "DW_FORM_ref_addr";
7262 return "DW_FORM_ref1";
7264 return "DW_FORM_ref2";
7266 return "DW_FORM_ref4";
7268 return "DW_FORM_ref8";
7269 case DW_FORM_ref_udata:
7270 return "DW_FORM_ref_udata";
7271 case DW_FORM_indirect:
7272 return "DW_FORM_indirect";
7273 case DW_FORM_sec_offset:
7274 return "DW_FORM_sec_offset";
7275 case DW_FORM_exprloc:
7276 return "DW_FORM_exprloc";
7277 case DW_FORM_flag_present:
7278 return "DW_FORM_flag_present";
7279 case DW_FORM_ref_sig8:
7280 return "DW_FORM_ref_sig8";
7282 return "DW_FORM_<unknown>";
7286 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7287 instance of an inlined instance of a decl which is local to an inline
7288 function, so we have to trace all of the way back through the origin chain
7289 to find out what sort of node actually served as the original seed for the
7293 decl_ultimate_origin (const_tree decl)
7295 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7298 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7299 nodes in the function to point to themselves; ignore that if
7300 we're trying to output the abstract instance of this function. */
7301 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7304 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7305 most distant ancestor, this should never happen. */
7306 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7308 return DECL_ABSTRACT_ORIGIN (decl);
7311 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7312 of a virtual function may refer to a base class, so we check the 'this'
7316 decl_class_context (tree decl)
7318 tree context = NULL_TREE;
7320 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7321 context = DECL_CONTEXT (decl);
7323 context = TYPE_MAIN_VARIANT
7324 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7326 if (context && !TYPE_P (context))
7327 context = NULL_TREE;
7332 /* Add an attribute/value pair to a DIE. */
7335 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7337 /* Maybe this should be an assert? */
7341 if (die->die_attr == NULL)
7342 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7343 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7346 static inline enum dw_val_class
7347 AT_class (dw_attr_ref a)
7349 return a->dw_attr_val.val_class;
7352 /* Add a flag value attribute to a DIE. */
7355 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7359 attr.dw_attr = attr_kind;
7360 attr.dw_attr_val.val_class = dw_val_class_flag;
7361 attr.dw_attr_val.v.val_flag = flag;
7362 add_dwarf_attr (die, &attr);
7365 static inline unsigned
7366 AT_flag (dw_attr_ref a)
7368 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7369 return a->dw_attr_val.v.val_flag;
7372 /* Add a signed integer attribute value to a DIE. */
7375 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7379 attr.dw_attr = attr_kind;
7380 attr.dw_attr_val.val_class = dw_val_class_const;
7381 attr.dw_attr_val.v.val_int = int_val;
7382 add_dwarf_attr (die, &attr);
7385 static inline HOST_WIDE_INT
7386 AT_int (dw_attr_ref a)
7388 gcc_assert (a && AT_class (a) == dw_val_class_const);
7389 return a->dw_attr_val.v.val_int;
7392 /* Add an unsigned integer attribute value to a DIE. */
7395 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7396 unsigned HOST_WIDE_INT unsigned_val)
7400 attr.dw_attr = attr_kind;
7401 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7402 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7403 add_dwarf_attr (die, &attr);
7406 static inline unsigned HOST_WIDE_INT
7407 AT_unsigned (dw_attr_ref a)
7409 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7410 return a->dw_attr_val.v.val_unsigned;
7413 /* Add an unsigned double integer attribute value to a DIE. */
7416 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7417 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7421 attr.dw_attr = attr_kind;
7422 attr.dw_attr_val.val_class = dw_val_class_const_double;
7423 attr.dw_attr_val.v.val_double.high = high;
7424 attr.dw_attr_val.v.val_double.low = low;
7425 add_dwarf_attr (die, &attr);
7428 /* Add a floating point attribute value to a DIE and return it. */
7431 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7432 unsigned int length, unsigned int elt_size, unsigned char *array)
7436 attr.dw_attr = attr_kind;
7437 attr.dw_attr_val.val_class = dw_val_class_vec;
7438 attr.dw_attr_val.v.val_vec.length = length;
7439 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7440 attr.dw_attr_val.v.val_vec.array = array;
7441 add_dwarf_attr (die, &attr);
7444 /* Add an 8-byte data attribute value to a DIE. */
7447 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7448 unsigned char data8[8])
7452 attr.dw_attr = attr_kind;
7453 attr.dw_attr_val.val_class = dw_val_class_data8;
7454 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7455 add_dwarf_attr (die, &attr);
7458 /* Hash and equality functions for debug_str_hash. */
7461 debug_str_do_hash (const void *x)
7463 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7467 debug_str_eq (const void *x1, const void *x2)
7469 return strcmp ((((const struct indirect_string_node *)x1)->str),
7470 (const char *)x2) == 0;
7473 /* Add STR to the indirect string hash table. */
7475 static struct indirect_string_node *
7476 find_AT_string (const char *str)
7478 struct indirect_string_node *node;
7481 if (! debug_str_hash)
7482 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7483 debug_str_eq, NULL);
7485 slot = htab_find_slot_with_hash (debug_str_hash, str,
7486 htab_hash_string (str), INSERT);
7489 node = ggc_alloc_cleared_indirect_string_node ();
7490 node->str = ggc_strdup (str);
7494 node = (struct indirect_string_node *) *slot;
7500 /* Add a string attribute value to a DIE. */
7503 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7506 struct indirect_string_node *node;
7508 node = find_AT_string (str);
7510 attr.dw_attr = attr_kind;
7511 attr.dw_attr_val.val_class = dw_val_class_str;
7512 attr.dw_attr_val.v.val_str = node;
7513 add_dwarf_attr (die, &attr);
7516 /* Create a label for an indirect string node, ensuring it is going to
7517 be output, unless its reference count goes down to zero. */
7520 gen_label_for_indirect_string (struct indirect_string_node *node)
7527 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7528 ++dw2_string_counter;
7529 node->label = xstrdup (label);
7532 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7533 debug string STR. */
7536 get_debug_string_label (const char *str)
7538 struct indirect_string_node *node = find_AT_string (str);
7540 debug_str_hash_forced = true;
7542 gen_label_for_indirect_string (node);
7544 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7547 static inline const char *
7548 AT_string (dw_attr_ref a)
7550 gcc_assert (a && AT_class (a) == dw_val_class_str);
7551 return a->dw_attr_val.v.val_str->str;
7554 /* Find out whether a string should be output inline in DIE
7555 or out-of-line in .debug_str section. */
7557 static enum dwarf_form
7558 AT_string_form (dw_attr_ref a)
7560 struct indirect_string_node *node;
7563 gcc_assert (a && AT_class (a) == dw_val_class_str);
7565 node = a->dw_attr_val.v.val_str;
7569 len = strlen (node->str) + 1;
7571 /* If the string is shorter or equal to the size of the reference, it is
7572 always better to put it inline. */
7573 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7574 return node->form = DW_FORM_string;
7576 /* If we cannot expect the linker to merge strings in .debug_str
7577 section, only put it into .debug_str if it is worth even in this
7579 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7580 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7581 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7582 return node->form = DW_FORM_string;
7584 gen_label_for_indirect_string (node);
7586 return node->form = DW_FORM_strp;
7589 /* Add a DIE reference attribute value to a DIE. */
7592 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7596 #ifdef ENABLE_CHECKING
7597 gcc_assert (targ_die != NULL);
7599 /* With LTO we can end up trying to reference something we didn't create
7600 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7601 if (targ_die == NULL)
7605 attr.dw_attr = attr_kind;
7606 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7607 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7608 attr.dw_attr_val.v.val_die_ref.external = 0;
7609 add_dwarf_attr (die, &attr);
7612 /* Add an AT_specification attribute to a DIE, and also make the back
7613 pointer from the specification to the definition. */
7616 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7618 add_AT_die_ref (die, DW_AT_specification, targ_die);
7619 gcc_assert (!targ_die->die_definition);
7620 targ_die->die_definition = die;
7623 static inline dw_die_ref
7624 AT_ref (dw_attr_ref a)
7626 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7627 return a->dw_attr_val.v.val_die_ref.die;
7631 AT_ref_external (dw_attr_ref a)
7633 if (a && AT_class (a) == dw_val_class_die_ref)
7634 return a->dw_attr_val.v.val_die_ref.external;
7640 set_AT_ref_external (dw_attr_ref a, int i)
7642 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7643 a->dw_attr_val.v.val_die_ref.external = i;
7646 /* Add an FDE reference attribute value to a DIE. */
7649 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7653 attr.dw_attr = attr_kind;
7654 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7655 attr.dw_attr_val.v.val_fde_index = targ_fde;
7656 add_dwarf_attr (die, &attr);
7659 /* Add a location description attribute value to a DIE. */
7662 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7666 attr.dw_attr = attr_kind;
7667 attr.dw_attr_val.val_class = dw_val_class_loc;
7668 attr.dw_attr_val.v.val_loc = loc;
7669 add_dwarf_attr (die, &attr);
7672 static inline dw_loc_descr_ref
7673 AT_loc (dw_attr_ref a)
7675 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7676 return a->dw_attr_val.v.val_loc;
7680 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7684 attr.dw_attr = attr_kind;
7685 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7686 attr.dw_attr_val.v.val_loc_list = loc_list;
7687 add_dwarf_attr (die, &attr);
7688 have_location_lists = true;
7691 static inline dw_loc_list_ref
7692 AT_loc_list (dw_attr_ref a)
7694 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7695 return a->dw_attr_val.v.val_loc_list;
7698 static inline dw_loc_list_ref *
7699 AT_loc_list_ptr (dw_attr_ref a)
7701 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7702 return &a->dw_attr_val.v.val_loc_list;
7705 /* Add an address constant attribute value to a DIE. */
7708 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7712 attr.dw_attr = attr_kind;
7713 attr.dw_attr_val.val_class = dw_val_class_addr;
7714 attr.dw_attr_val.v.val_addr = addr;
7715 add_dwarf_attr (die, &attr);
7718 /* Get the RTX from to an address DIE attribute. */
7721 AT_addr (dw_attr_ref a)
7723 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7724 return a->dw_attr_val.v.val_addr;
7727 /* Add a file attribute value to a DIE. */
7730 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7731 struct dwarf_file_data *fd)
7735 attr.dw_attr = attr_kind;
7736 attr.dw_attr_val.val_class = dw_val_class_file;
7737 attr.dw_attr_val.v.val_file = fd;
7738 add_dwarf_attr (die, &attr);
7741 /* Get the dwarf_file_data from a file DIE attribute. */
7743 static inline struct dwarf_file_data *
7744 AT_file (dw_attr_ref a)
7746 gcc_assert (a && AT_class (a) == dw_val_class_file);
7747 return a->dw_attr_val.v.val_file;
7750 /* Add a vms delta attribute value to a DIE. */
7753 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7754 const char *lbl1, const char *lbl2)
7758 attr.dw_attr = attr_kind;
7759 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7760 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7761 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7762 add_dwarf_attr (die, &attr);
7765 /* Add a label identifier attribute value to a DIE. */
7768 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7772 attr.dw_attr = attr_kind;
7773 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7774 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7775 add_dwarf_attr (die, &attr);
7778 /* Add a section offset attribute value to a DIE, an offset into the
7779 debug_line section. */
7782 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7787 attr.dw_attr = attr_kind;
7788 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7789 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7790 add_dwarf_attr (die, &attr);
7793 /* Add a section offset attribute value to a DIE, an offset into the
7794 debug_macinfo section. */
7797 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7802 attr.dw_attr = attr_kind;
7803 attr.dw_attr_val.val_class = dw_val_class_macptr;
7804 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7805 add_dwarf_attr (die, &attr);
7808 /* Add an offset attribute value to a DIE. */
7811 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7812 unsigned HOST_WIDE_INT offset)
7816 attr.dw_attr = attr_kind;
7817 attr.dw_attr_val.val_class = dw_val_class_offset;
7818 attr.dw_attr_val.v.val_offset = offset;
7819 add_dwarf_attr (die, &attr);
7822 /* Add an range_list attribute value to a DIE. */
7825 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7826 long unsigned int offset)
7830 attr.dw_attr = attr_kind;
7831 attr.dw_attr_val.val_class = dw_val_class_range_list;
7832 attr.dw_attr_val.v.val_offset = offset;
7833 add_dwarf_attr (die, &attr);
7836 /* Return the start label of a delta attribute. */
7838 static inline const char *
7839 AT_vms_delta1 (dw_attr_ref a)
7841 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7842 return a->dw_attr_val.v.val_vms_delta.lbl1;
7845 /* Return the end label of a delta attribute. */
7847 static inline const char *
7848 AT_vms_delta2 (dw_attr_ref a)
7850 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7851 return a->dw_attr_val.v.val_vms_delta.lbl2;
7854 static inline const char *
7855 AT_lbl (dw_attr_ref a)
7857 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7858 || AT_class (a) == dw_val_class_lineptr
7859 || AT_class (a) == dw_val_class_macptr));
7860 return a->dw_attr_val.v.val_lbl_id;
7863 /* Get the attribute of type attr_kind. */
7866 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7870 dw_die_ref spec = NULL;
7875 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7876 if (a->dw_attr == attr_kind)
7878 else if (a->dw_attr == DW_AT_specification
7879 || a->dw_attr == DW_AT_abstract_origin)
7883 return get_AT (spec, attr_kind);
7888 /* Return the "low pc" attribute value, typically associated with a subprogram
7889 DIE. Return null if the "low pc" attribute is either not present, or if it
7890 cannot be represented as an assembler label identifier. */
7892 static inline const char *
7893 get_AT_low_pc (dw_die_ref die)
7895 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7897 return a ? AT_lbl (a) : NULL;
7900 /* Return the "high pc" attribute value, typically associated with a subprogram
7901 DIE. Return null if the "high pc" attribute is either not present, or if it
7902 cannot be represented as an assembler label identifier. */
7904 static inline const char *
7905 get_AT_hi_pc (dw_die_ref die)
7907 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7909 return a ? AT_lbl (a) : NULL;
7912 /* Return the value of the string attribute designated by ATTR_KIND, or
7913 NULL if it is not present. */
7915 static inline const char *
7916 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7918 dw_attr_ref a = get_AT (die, attr_kind);
7920 return a ? AT_string (a) : NULL;
7923 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7924 if it is not present. */
7927 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7929 dw_attr_ref a = get_AT (die, attr_kind);
7931 return a ? AT_flag (a) : 0;
7934 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7935 if it is not present. */
7937 static inline unsigned
7938 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7940 dw_attr_ref a = get_AT (die, attr_kind);
7942 return a ? AT_unsigned (a) : 0;
7945 static inline dw_die_ref
7946 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7948 dw_attr_ref a = get_AT (die, attr_kind);
7950 return a ? AT_ref (a) : NULL;
7953 static inline struct dwarf_file_data *
7954 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7956 dw_attr_ref a = get_AT (die, attr_kind);
7958 return a ? AT_file (a) : NULL;
7961 /* Return TRUE if the language is C++. */
7966 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7968 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7971 /* Return TRUE if the language is Fortran. */
7976 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7978 return (lang == DW_LANG_Fortran77
7979 || lang == DW_LANG_Fortran90
7980 || lang == DW_LANG_Fortran95);
7983 /* Return TRUE if the language is Ada. */
7988 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7990 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7993 /* Remove the specified attribute if present. */
7996 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
8004 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8005 if (a->dw_attr == attr_kind)
8007 if (AT_class (a) == dw_val_class_str)
8008 if (a->dw_attr_val.v.val_str->refcount)
8009 a->dw_attr_val.v.val_str->refcount--;
8011 /* VEC_ordered_remove should help reduce the number of abbrevs
8013 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
8018 /* Remove CHILD from its parent. PREV must have the property that
8019 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
8022 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
8024 gcc_assert (child->die_parent == prev->die_parent);
8025 gcc_assert (prev->die_sib == child);
8028 gcc_assert (child->die_parent->die_child == child);
8032 prev->die_sib = child->die_sib;
8033 if (child->die_parent->die_child == child)
8034 child->die_parent->die_child = prev;
8037 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8038 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8041 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8043 dw_die_ref parent = old_child->die_parent;
8045 gcc_assert (parent == prev->die_parent);
8046 gcc_assert (prev->die_sib == old_child);
8048 new_child->die_parent = parent;
8049 if (prev == old_child)
8051 gcc_assert (parent->die_child == old_child);
8052 new_child->die_sib = new_child;
8056 prev->die_sib = new_child;
8057 new_child->die_sib = old_child->die_sib;
8059 if (old_child->die_parent->die_child == old_child)
8060 old_child->die_parent->die_child = new_child;
8063 /* Move all children from OLD_PARENT to NEW_PARENT. */
8066 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8069 new_parent->die_child = old_parent->die_child;
8070 old_parent->die_child = NULL;
8071 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8074 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8078 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8084 dw_die_ref prev = c;
8086 while (c->die_tag == tag)
8088 remove_child_with_prev (c, prev);
8089 /* Might have removed every child. */
8090 if (c == c->die_sib)
8094 } while (c != die->die_child);
8097 /* Add a CHILD_DIE as the last child of DIE. */
8100 add_child_die (dw_die_ref die, dw_die_ref child_die)
8102 /* FIXME this should probably be an assert. */
8103 if (! die || ! child_die)
8105 gcc_assert (die != child_die);
8107 child_die->die_parent = die;
8110 child_die->die_sib = die->die_child->die_sib;
8111 die->die_child->die_sib = child_die;
8114 child_die->die_sib = child_die;
8115 die->die_child = child_die;
8118 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8119 is the specification, to the end of PARENT's list of children.
8120 This is done by removing and re-adding it. */
8123 splice_child_die (dw_die_ref parent, dw_die_ref child)
8127 /* We want the declaration DIE from inside the class, not the
8128 specification DIE at toplevel. */
8129 if (child->die_parent != parent)
8131 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8137 gcc_assert (child->die_parent == parent
8138 || (child->die_parent
8139 == get_AT_ref (parent, DW_AT_specification)));
8141 for (p = child->die_parent->die_child; ; p = p->die_sib)
8142 if (p->die_sib == child)
8144 remove_child_with_prev (child, p);
8148 add_child_die (parent, child);
8151 /* Return a pointer to a newly created DIE node. */
8153 static inline dw_die_ref
8154 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8156 dw_die_ref die = ggc_alloc_cleared_die_node ();
8158 die->die_tag = tag_value;
8160 if (parent_die != NULL)
8161 add_child_die (parent_die, die);
8164 limbo_die_node *limbo_node;
8166 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8167 limbo_node->die = die;
8168 limbo_node->created_for = t;
8169 limbo_node->next = limbo_die_list;
8170 limbo_die_list = limbo_node;
8176 /* Return the DIE associated with the given type specifier. */
8178 static inline dw_die_ref
8179 lookup_type_die (tree type)
8181 return TYPE_SYMTAB_DIE (type);
8184 /* Like lookup_type_die, but if type is an anonymous type named by a
8185 typedef[1], return the DIE of the anonymous type instead the one of
8186 the naming typedef. This is because in gen_typedef_die, we did
8187 equate the anonymous struct named by the typedef with the DIE of
8188 the naming typedef. So by default, lookup_type_die on an anonymous
8189 struct yields the DIE of the naming typedef.
8191 [1]: Read the comment of is_naming_typedef_decl to learn about what
8192 a naming typedef is. */
8194 static inline dw_die_ref
8195 lookup_type_die_strip_naming_typedef (tree type)
8197 dw_die_ref die = lookup_type_die (type);
8198 if (TREE_CODE (type) == RECORD_TYPE
8199 && die->die_tag == DW_TAG_typedef
8200 && is_naming_typedef_decl (TYPE_NAME (type)))
8201 die = get_AT_ref (die, DW_AT_type);
8205 /* Equate a DIE to a given type specifier. */
8208 equate_type_number_to_die (tree type, dw_die_ref type_die)
8210 TYPE_SYMTAB_DIE (type) = type_die;
8213 /* Returns a hash value for X (which really is a die_struct). */
8216 decl_die_table_hash (const void *x)
8218 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8221 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8224 decl_die_table_eq (const void *x, const void *y)
8226 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8229 /* Return the DIE associated with a given declaration. */
8231 static inline dw_die_ref
8232 lookup_decl_die (tree decl)
8234 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8237 /* Returns a hash value for X (which really is a var_loc_list). */
8240 decl_loc_table_hash (const void *x)
8242 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8245 /* Return nonzero if decl_id of var_loc_list X is the same as
8249 decl_loc_table_eq (const void *x, const void *y)
8251 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8254 /* Return the var_loc list associated with a given declaration. */
8256 static inline var_loc_list *
8257 lookup_decl_loc (const_tree decl)
8259 if (!decl_loc_table)
8261 return (var_loc_list *)
8262 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8265 /* Equate a DIE to a particular declaration. */
8268 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8270 unsigned int decl_id = DECL_UID (decl);
8273 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8275 decl_die->decl_id = decl_id;
8278 /* Return how many bits covers PIECE EXPR_LIST. */
8281 decl_piece_bitsize (rtx piece)
8283 int ret = (int) GET_MODE (piece);
8286 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8287 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8288 return INTVAL (XEXP (XEXP (piece, 0), 0));
8291 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8294 decl_piece_varloc_ptr (rtx piece)
8296 if ((int) GET_MODE (piece))
8297 return &XEXP (piece, 0);
8299 return &XEXP (XEXP (piece, 0), 1);
8302 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8303 Next is the chain of following piece nodes. */
8306 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8308 if (bitsize <= (int) MAX_MACHINE_MODE)
8309 return alloc_EXPR_LIST (bitsize, loc_note, next);
8311 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8316 /* Return rtx that should be stored into loc field for
8317 LOC_NOTE and BITPOS/BITSIZE. */
8320 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8321 HOST_WIDE_INT bitsize)
8325 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8327 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8332 /* This function either modifies location piece list *DEST in
8333 place (if SRC and INNER is NULL), or copies location piece list
8334 *SRC to *DEST while modifying it. Location BITPOS is modified
8335 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8336 not copied and if needed some padding around it is added.
8337 When modifying in place, DEST should point to EXPR_LIST where
8338 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8339 to the start of the whole list and INNER points to the EXPR_LIST
8340 where earlier pieces cover PIECE_BITPOS bits. */
8343 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8344 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8345 HOST_WIDE_INT bitsize, rtx loc_note)
8348 bool copy = inner != NULL;
8352 /* First copy all nodes preceeding the current bitpos. */
8353 while (src != inner)
8355 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8356 decl_piece_bitsize (*src), NULL_RTX);
8357 dest = &XEXP (*dest, 1);
8358 src = &XEXP (*src, 1);
8361 /* Add padding if needed. */
8362 if (bitpos != piece_bitpos)
8364 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8365 copy ? NULL_RTX : *dest);
8366 dest = &XEXP (*dest, 1);
8368 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8371 /* A piece with correct bitpos and bitsize already exist,
8372 just update the location for it and return. */
8373 *decl_piece_varloc_ptr (*dest) = loc_note;
8376 /* Add the piece that changed. */
8377 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8378 dest = &XEXP (*dest, 1);
8379 /* Skip over pieces that overlap it. */
8380 diff = bitpos - piece_bitpos + bitsize;
8383 while (diff > 0 && *src)
8386 diff -= decl_piece_bitsize (piece);
8388 src = &XEXP (piece, 1);
8391 *src = XEXP (piece, 1);
8392 free_EXPR_LIST_node (piece);
8395 /* Add padding if needed. */
8396 if (diff < 0 && *src)
8400 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8401 dest = &XEXP (*dest, 1);
8405 /* Finally copy all nodes following it. */
8408 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8409 decl_piece_bitsize (*src), NULL_RTX);
8410 dest = &XEXP (*dest, 1);
8411 src = &XEXP (*src, 1);
8415 /* Add a variable location node to the linked list for DECL. */
8417 static struct var_loc_node *
8418 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8420 unsigned int decl_id;
8423 struct var_loc_node *loc = NULL;
8424 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8426 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8428 tree realdecl = DECL_DEBUG_EXPR (decl);
8429 if (realdecl && handled_component_p (realdecl))
8431 HOST_WIDE_INT maxsize;
8434 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8435 if (!DECL_P (innerdecl)
8436 || DECL_IGNORED_P (innerdecl)
8437 || TREE_STATIC (innerdecl)
8439 || bitpos + bitsize > 256
8440 || bitsize != maxsize)
8446 decl_id = DECL_UID (decl);
8447 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8450 temp = ggc_alloc_cleared_var_loc_list ();
8451 temp->decl_id = decl_id;
8455 temp = (var_loc_list *) *slot;
8459 struct var_loc_node *last = temp->last, *unused = NULL;
8460 rtx *piece_loc = NULL, last_loc_note;
8461 int piece_bitpos = 0;
8465 gcc_assert (last->next == NULL);
8467 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8469 piece_loc = &last->loc;
8472 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8473 if (piece_bitpos + cur_bitsize > bitpos)
8475 piece_bitpos += cur_bitsize;
8476 piece_loc = &XEXP (*piece_loc, 1);
8480 /* TEMP->LAST here is either pointer to the last but one or
8481 last element in the chained list, LAST is pointer to the
8483 if (label && strcmp (last->label, label) == 0)
8485 /* For SRA optimized variables if there weren't any real
8486 insns since last note, just modify the last node. */
8487 if (piece_loc != NULL)
8489 adjust_piece_list (piece_loc, NULL, NULL,
8490 bitpos, piece_bitpos, bitsize, loc_note);
8493 /* If the last note doesn't cover any instructions, remove it. */
8494 if (temp->last != last)
8496 temp->last->next = NULL;
8499 gcc_assert (strcmp (last->label, label) != 0);
8503 gcc_assert (temp->first == temp->last);
8504 memset (temp->last, '\0', sizeof (*temp->last));
8505 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8509 if (bitsize == -1 && NOTE_P (last->loc))
8510 last_loc_note = last->loc;
8511 else if (piece_loc != NULL
8512 && *piece_loc != NULL_RTX
8513 && piece_bitpos == bitpos
8514 && decl_piece_bitsize (*piece_loc) == bitsize)
8515 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8517 last_loc_note = NULL_RTX;
8518 /* If the current location is the same as the end of the list,
8519 and either both or neither of the locations is uninitialized,
8520 we have nothing to do. */
8521 if (last_loc_note == NULL_RTX
8522 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8523 NOTE_VAR_LOCATION_LOC (loc_note)))
8524 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8525 != NOTE_VAR_LOCATION_STATUS (loc_note))
8526 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8527 == VAR_INIT_STATUS_UNINITIALIZED)
8528 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8529 == VAR_INIT_STATUS_UNINITIALIZED))))
8531 /* Add LOC to the end of list and update LAST. If the last
8532 element of the list has been removed above, reuse its
8533 memory for the new node, otherwise allocate a new one. */
8537 memset (loc, '\0', sizeof (*loc));
8540 loc = ggc_alloc_cleared_var_loc_node ();
8541 if (bitsize == -1 || piece_loc == NULL)
8542 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8544 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8545 bitpos, piece_bitpos, bitsize, loc_note);
8547 /* Ensure TEMP->LAST will point either to the new last but one
8548 element of the chain, or to the last element in it. */
8549 if (last != temp->last)
8557 loc = ggc_alloc_cleared_var_loc_node ();
8560 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8565 /* Keep track of the number of spaces used to indent the
8566 output of the debugging routines that print the structure of
8567 the DIE internal representation. */
8568 static int print_indent;
8570 /* Indent the line the number of spaces given by print_indent. */
8573 print_spaces (FILE *outfile)
8575 fprintf (outfile, "%*s", print_indent, "");
8578 /* Print a type signature in hex. */
8581 print_signature (FILE *outfile, char *sig)
8585 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8586 fprintf (outfile, "%02x", sig[i] & 0xff);
8589 /* Print the information associated with a given DIE, and its children.
8590 This routine is a debugging aid only. */
8593 print_die (dw_die_ref die, FILE *outfile)
8599 print_spaces (outfile);
8600 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8601 die->die_offset, dwarf_tag_name (die->die_tag),
8603 print_spaces (outfile);
8604 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8605 fprintf (outfile, " offset: %ld", die->die_offset);
8606 fprintf (outfile, " mark: %d\n", die->die_mark);
8608 if (dwarf_version >= 4 && die->die_id.die_type_node)
8610 print_spaces (outfile);
8611 fprintf (outfile, " signature: ");
8612 print_signature (outfile, die->die_id.die_type_node->signature);
8613 fprintf (outfile, "\n");
8616 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8618 print_spaces (outfile);
8619 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8621 switch (AT_class (a))
8623 case dw_val_class_addr:
8624 fprintf (outfile, "address");
8626 case dw_val_class_offset:
8627 fprintf (outfile, "offset");
8629 case dw_val_class_loc:
8630 fprintf (outfile, "location descriptor");
8632 case dw_val_class_loc_list:
8633 fprintf (outfile, "location list -> label:%s",
8634 AT_loc_list (a)->ll_symbol);
8636 case dw_val_class_range_list:
8637 fprintf (outfile, "range list");
8639 case dw_val_class_const:
8640 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8642 case dw_val_class_unsigned_const:
8643 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8645 case dw_val_class_const_double:
8646 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8647 HOST_WIDE_INT_PRINT_UNSIGNED")",
8648 a->dw_attr_val.v.val_double.high,
8649 a->dw_attr_val.v.val_double.low);
8651 case dw_val_class_vec:
8652 fprintf (outfile, "floating-point or vector constant");
8654 case dw_val_class_flag:
8655 fprintf (outfile, "%u", AT_flag (a));
8657 case dw_val_class_die_ref:
8658 if (AT_ref (a) != NULL)
8660 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8662 fprintf (outfile, "die -> signature: ");
8663 print_signature (outfile,
8664 AT_ref (a)->die_id.die_type_node->signature);
8666 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8667 fprintf (outfile, "die -> label: %s",
8668 AT_ref (a)->die_id.die_symbol);
8670 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8671 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8674 fprintf (outfile, "die -> <null>");
8676 case dw_val_class_vms_delta:
8677 fprintf (outfile, "delta: @slotcount(%s-%s)",
8678 AT_vms_delta2 (a), AT_vms_delta1 (a));
8680 case dw_val_class_lbl_id:
8681 case dw_val_class_lineptr:
8682 case dw_val_class_macptr:
8683 fprintf (outfile, "label: %s", AT_lbl (a));
8685 case dw_val_class_str:
8686 if (AT_string (a) != NULL)
8687 fprintf (outfile, "\"%s\"", AT_string (a));
8689 fprintf (outfile, "<null>");
8691 case dw_val_class_file:
8692 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8693 AT_file (a)->emitted_number);
8695 case dw_val_class_data8:
8699 for (i = 0; i < 8; i++)
8700 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8707 fprintf (outfile, "\n");
8710 if (die->die_child != NULL)
8713 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8716 if (print_indent == 0)
8717 fprintf (outfile, "\n");
8720 /* Print the contents of the source code line number correspondence table.
8721 This routine is a debugging aid only. */
8724 print_dwarf_line_table (FILE *outfile)
8727 dw_line_info_ref line_info;
8729 fprintf (outfile, "\n\nDWARF source line information\n");
8730 for (i = 1; i < line_info_table_in_use; i++)
8732 line_info = &line_info_table[i];
8733 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8734 line_info->dw_file_num,
8735 line_info->dw_line_num);
8738 fprintf (outfile, "\n\n");
8741 /* Print the information collected for a given DIE. */
8744 debug_dwarf_die (dw_die_ref die)
8746 print_die (die, stderr);
8749 /* Print all DWARF information collected for the compilation unit.
8750 This routine is a debugging aid only. */
8756 print_die (comp_unit_die (), stderr);
8757 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8758 print_dwarf_line_table (stderr);
8761 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8762 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8763 DIE that marks the start of the DIEs for this include file. */
8766 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8768 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8769 dw_die_ref new_unit = gen_compile_unit_die (filename);
8771 new_unit->die_sib = old_unit;
8775 /* Close an include-file CU and reopen the enclosing one. */
8778 pop_compile_unit (dw_die_ref old_unit)
8780 dw_die_ref new_unit = old_unit->die_sib;
8782 old_unit->die_sib = NULL;
8786 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8787 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8789 /* Calculate the checksum of a location expression. */
8792 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8796 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8798 CHECKSUM (loc->dw_loc_oprnd1);
8799 CHECKSUM (loc->dw_loc_oprnd2);
8802 /* Calculate the checksum of an attribute. */
8805 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8807 dw_loc_descr_ref loc;
8810 CHECKSUM (at->dw_attr);
8812 /* We don't care that this was compiled with a different compiler
8813 snapshot; if the output is the same, that's what matters. */
8814 if (at->dw_attr == DW_AT_producer)
8817 switch (AT_class (at))
8819 case dw_val_class_const:
8820 CHECKSUM (at->dw_attr_val.v.val_int);
8822 case dw_val_class_unsigned_const:
8823 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8825 case dw_val_class_const_double:
8826 CHECKSUM (at->dw_attr_val.v.val_double);
8828 case dw_val_class_vec:
8829 CHECKSUM (at->dw_attr_val.v.val_vec);
8831 case dw_val_class_flag:
8832 CHECKSUM (at->dw_attr_val.v.val_flag);
8834 case dw_val_class_str:
8835 CHECKSUM_STRING (AT_string (at));
8838 case dw_val_class_addr:
8840 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8841 CHECKSUM_STRING (XSTR (r, 0));
8844 case dw_val_class_offset:
8845 CHECKSUM (at->dw_attr_val.v.val_offset);
8848 case dw_val_class_loc:
8849 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8850 loc_checksum (loc, ctx);
8853 case dw_val_class_die_ref:
8854 die_checksum (AT_ref (at), ctx, mark);
8857 case dw_val_class_fde_ref:
8858 case dw_val_class_vms_delta:
8859 case dw_val_class_lbl_id:
8860 case dw_val_class_lineptr:
8861 case dw_val_class_macptr:
8864 case dw_val_class_file:
8865 CHECKSUM_STRING (AT_file (at)->filename);
8868 case dw_val_class_data8:
8869 CHECKSUM (at->dw_attr_val.v.val_data8);
8877 /* Calculate the checksum of a DIE. */
8880 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8886 /* To avoid infinite recursion. */
8889 CHECKSUM (die->die_mark);
8892 die->die_mark = ++(*mark);
8894 CHECKSUM (die->die_tag);
8896 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8897 attr_checksum (a, ctx, mark);
8899 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8903 #undef CHECKSUM_STRING
8905 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8906 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8907 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8908 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8909 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8910 #define CHECKSUM_ATTR(FOO) \
8911 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8913 /* Calculate the checksum of a number in signed LEB128 format. */
8916 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8923 byte = (value & 0x7f);
8925 more = !((value == 0 && (byte & 0x40) == 0)
8926 || (value == -1 && (byte & 0x40) != 0));
8935 /* Calculate the checksum of a number in unsigned LEB128 format. */
8938 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8942 unsigned char byte = (value & 0x7f);
8945 /* More bytes to follow. */
8953 /* Checksum the context of the DIE. This adds the names of any
8954 surrounding namespaces or structures to the checksum. */
8957 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8961 int tag = die->die_tag;
8963 if (tag != DW_TAG_namespace
8964 && tag != DW_TAG_structure_type
8965 && tag != DW_TAG_class_type)
8968 name = get_AT_string (die, DW_AT_name);
8970 spec = get_AT_ref (die, DW_AT_specification);
8974 if (die->die_parent != NULL)
8975 checksum_die_context (die->die_parent, ctx);
8977 CHECKSUM_ULEB128 ('C');
8978 CHECKSUM_ULEB128 (tag);
8980 CHECKSUM_STRING (name);
8983 /* Calculate the checksum of a location expression. */
8986 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8988 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8989 were emitted as a DW_FORM_sdata instead of a location expression. */
8990 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8992 CHECKSUM_ULEB128 (DW_FORM_sdata);
8993 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8997 /* Otherwise, just checksum the raw location expression. */
9000 CHECKSUM_ULEB128 (loc->dw_loc_opc);
9001 CHECKSUM (loc->dw_loc_oprnd1);
9002 CHECKSUM (loc->dw_loc_oprnd2);
9003 loc = loc->dw_loc_next;
9007 /* Calculate the checksum of an attribute. */
9010 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
9011 struct md5_ctx *ctx, int *mark)
9013 dw_loc_descr_ref loc;
9016 if (AT_class (at) == dw_val_class_die_ref)
9018 dw_die_ref target_die = AT_ref (at);
9020 /* For pointer and reference types, we checksum only the (qualified)
9021 name of the target type (if there is a name). For friend entries,
9022 we checksum only the (qualified) name of the target type or function.
9023 This allows the checksum to remain the same whether the target type
9024 is complete or not. */
9025 if ((at->dw_attr == DW_AT_type
9026 && (tag == DW_TAG_pointer_type
9027 || tag == DW_TAG_reference_type
9028 || tag == DW_TAG_rvalue_reference_type
9029 || tag == DW_TAG_ptr_to_member_type))
9030 || (at->dw_attr == DW_AT_friend
9031 && tag == DW_TAG_friend))
9033 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9035 if (name_attr != NULL)
9037 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9041 CHECKSUM_ULEB128 ('N');
9042 CHECKSUM_ULEB128 (at->dw_attr);
9043 if (decl->die_parent != NULL)
9044 checksum_die_context (decl->die_parent, ctx);
9045 CHECKSUM_ULEB128 ('E');
9046 CHECKSUM_STRING (AT_string (name_attr));
9051 /* For all other references to another DIE, we check to see if the
9052 target DIE has already been visited. If it has, we emit a
9053 backward reference; if not, we descend recursively. */
9054 if (target_die->die_mark > 0)
9056 CHECKSUM_ULEB128 ('R');
9057 CHECKSUM_ULEB128 (at->dw_attr);
9058 CHECKSUM_ULEB128 (target_die->die_mark);
9062 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9066 target_die->die_mark = ++(*mark);
9067 CHECKSUM_ULEB128 ('T');
9068 CHECKSUM_ULEB128 (at->dw_attr);
9069 if (decl->die_parent != NULL)
9070 checksum_die_context (decl->die_parent, ctx);
9071 die_checksum_ordered (target_die, ctx, mark);
9076 CHECKSUM_ULEB128 ('A');
9077 CHECKSUM_ULEB128 (at->dw_attr);
9079 switch (AT_class (at))
9081 case dw_val_class_const:
9082 CHECKSUM_ULEB128 (DW_FORM_sdata);
9083 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9086 case dw_val_class_unsigned_const:
9087 CHECKSUM_ULEB128 (DW_FORM_sdata);
9088 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9091 case dw_val_class_const_double:
9092 CHECKSUM_ULEB128 (DW_FORM_block);
9093 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9094 CHECKSUM (at->dw_attr_val.v.val_double);
9097 case dw_val_class_vec:
9098 CHECKSUM_ULEB128 (DW_FORM_block);
9099 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9100 CHECKSUM (at->dw_attr_val.v.val_vec);
9103 case dw_val_class_flag:
9104 CHECKSUM_ULEB128 (DW_FORM_flag);
9105 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9108 case dw_val_class_str:
9109 CHECKSUM_ULEB128 (DW_FORM_string);
9110 CHECKSUM_STRING (AT_string (at));
9113 case dw_val_class_addr:
9115 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9116 CHECKSUM_ULEB128 (DW_FORM_string);
9117 CHECKSUM_STRING (XSTR (r, 0));
9120 case dw_val_class_offset:
9121 CHECKSUM_ULEB128 (DW_FORM_sdata);
9122 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9125 case dw_val_class_loc:
9126 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9127 loc_checksum_ordered (loc, ctx);
9130 case dw_val_class_fde_ref:
9131 case dw_val_class_lbl_id:
9132 case dw_val_class_lineptr:
9133 case dw_val_class_macptr:
9136 case dw_val_class_file:
9137 CHECKSUM_ULEB128 (DW_FORM_string);
9138 CHECKSUM_STRING (AT_file (at)->filename);
9141 case dw_val_class_data8:
9142 CHECKSUM (at->dw_attr_val.v.val_data8);
9150 struct checksum_attributes
9152 dw_attr_ref at_name;
9153 dw_attr_ref at_type;
9154 dw_attr_ref at_friend;
9155 dw_attr_ref at_accessibility;
9156 dw_attr_ref at_address_class;
9157 dw_attr_ref at_allocated;
9158 dw_attr_ref at_artificial;
9159 dw_attr_ref at_associated;
9160 dw_attr_ref at_binary_scale;
9161 dw_attr_ref at_bit_offset;
9162 dw_attr_ref at_bit_size;
9163 dw_attr_ref at_bit_stride;
9164 dw_attr_ref at_byte_size;
9165 dw_attr_ref at_byte_stride;
9166 dw_attr_ref at_const_value;
9167 dw_attr_ref at_containing_type;
9168 dw_attr_ref at_count;
9169 dw_attr_ref at_data_location;
9170 dw_attr_ref at_data_member_location;
9171 dw_attr_ref at_decimal_scale;
9172 dw_attr_ref at_decimal_sign;
9173 dw_attr_ref at_default_value;
9174 dw_attr_ref at_digit_count;
9175 dw_attr_ref at_discr;
9176 dw_attr_ref at_discr_list;
9177 dw_attr_ref at_discr_value;
9178 dw_attr_ref at_encoding;
9179 dw_attr_ref at_endianity;
9180 dw_attr_ref at_explicit;
9181 dw_attr_ref at_is_optional;
9182 dw_attr_ref at_location;
9183 dw_attr_ref at_lower_bound;
9184 dw_attr_ref at_mutable;
9185 dw_attr_ref at_ordering;
9186 dw_attr_ref at_picture_string;
9187 dw_attr_ref at_prototyped;
9188 dw_attr_ref at_small;
9189 dw_attr_ref at_segment;
9190 dw_attr_ref at_string_length;
9191 dw_attr_ref at_threads_scaled;
9192 dw_attr_ref at_upper_bound;
9193 dw_attr_ref at_use_location;
9194 dw_attr_ref at_use_UTF8;
9195 dw_attr_ref at_variable_parameter;
9196 dw_attr_ref at_virtuality;
9197 dw_attr_ref at_visibility;
9198 dw_attr_ref at_vtable_elem_location;
9201 /* Collect the attributes that we will want to use for the checksum. */
9204 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9209 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9220 attrs->at_friend = a;
9222 case DW_AT_accessibility:
9223 attrs->at_accessibility = a;
9225 case DW_AT_address_class:
9226 attrs->at_address_class = a;
9228 case DW_AT_allocated:
9229 attrs->at_allocated = a;
9231 case DW_AT_artificial:
9232 attrs->at_artificial = a;
9234 case DW_AT_associated:
9235 attrs->at_associated = a;
9237 case DW_AT_binary_scale:
9238 attrs->at_binary_scale = a;
9240 case DW_AT_bit_offset:
9241 attrs->at_bit_offset = a;
9243 case DW_AT_bit_size:
9244 attrs->at_bit_size = a;
9246 case DW_AT_bit_stride:
9247 attrs->at_bit_stride = a;
9249 case DW_AT_byte_size:
9250 attrs->at_byte_size = a;
9252 case DW_AT_byte_stride:
9253 attrs->at_byte_stride = a;
9255 case DW_AT_const_value:
9256 attrs->at_const_value = a;
9258 case DW_AT_containing_type:
9259 attrs->at_containing_type = a;
9262 attrs->at_count = a;
9264 case DW_AT_data_location:
9265 attrs->at_data_location = a;
9267 case DW_AT_data_member_location:
9268 attrs->at_data_member_location = a;
9270 case DW_AT_decimal_scale:
9271 attrs->at_decimal_scale = a;
9273 case DW_AT_decimal_sign:
9274 attrs->at_decimal_sign = a;
9276 case DW_AT_default_value:
9277 attrs->at_default_value = a;
9279 case DW_AT_digit_count:
9280 attrs->at_digit_count = a;
9283 attrs->at_discr = a;
9285 case DW_AT_discr_list:
9286 attrs->at_discr_list = a;
9288 case DW_AT_discr_value:
9289 attrs->at_discr_value = a;
9291 case DW_AT_encoding:
9292 attrs->at_encoding = a;
9294 case DW_AT_endianity:
9295 attrs->at_endianity = a;
9297 case DW_AT_explicit:
9298 attrs->at_explicit = a;
9300 case DW_AT_is_optional:
9301 attrs->at_is_optional = a;
9303 case DW_AT_location:
9304 attrs->at_location = a;
9306 case DW_AT_lower_bound:
9307 attrs->at_lower_bound = a;
9310 attrs->at_mutable = a;
9312 case DW_AT_ordering:
9313 attrs->at_ordering = a;
9315 case DW_AT_picture_string:
9316 attrs->at_picture_string = a;
9318 case DW_AT_prototyped:
9319 attrs->at_prototyped = a;
9322 attrs->at_small = a;
9325 attrs->at_segment = a;
9327 case DW_AT_string_length:
9328 attrs->at_string_length = a;
9330 case DW_AT_threads_scaled:
9331 attrs->at_threads_scaled = a;
9333 case DW_AT_upper_bound:
9334 attrs->at_upper_bound = a;
9336 case DW_AT_use_location:
9337 attrs->at_use_location = a;
9339 case DW_AT_use_UTF8:
9340 attrs->at_use_UTF8 = a;
9342 case DW_AT_variable_parameter:
9343 attrs->at_variable_parameter = a;
9345 case DW_AT_virtuality:
9346 attrs->at_virtuality = a;
9348 case DW_AT_visibility:
9349 attrs->at_visibility = a;
9351 case DW_AT_vtable_elem_location:
9352 attrs->at_vtable_elem_location = a;
9360 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9363 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9367 struct checksum_attributes attrs;
9369 CHECKSUM_ULEB128 ('D');
9370 CHECKSUM_ULEB128 (die->die_tag);
9372 memset (&attrs, 0, sizeof (attrs));
9374 decl = get_AT_ref (die, DW_AT_specification);
9376 collect_checksum_attributes (&attrs, decl);
9377 collect_checksum_attributes (&attrs, die);
9379 CHECKSUM_ATTR (attrs.at_name);
9380 CHECKSUM_ATTR (attrs.at_accessibility);
9381 CHECKSUM_ATTR (attrs.at_address_class);
9382 CHECKSUM_ATTR (attrs.at_allocated);
9383 CHECKSUM_ATTR (attrs.at_artificial);
9384 CHECKSUM_ATTR (attrs.at_associated);
9385 CHECKSUM_ATTR (attrs.at_binary_scale);
9386 CHECKSUM_ATTR (attrs.at_bit_offset);
9387 CHECKSUM_ATTR (attrs.at_bit_size);
9388 CHECKSUM_ATTR (attrs.at_bit_stride);
9389 CHECKSUM_ATTR (attrs.at_byte_size);
9390 CHECKSUM_ATTR (attrs.at_byte_stride);
9391 CHECKSUM_ATTR (attrs.at_const_value);
9392 CHECKSUM_ATTR (attrs.at_containing_type);
9393 CHECKSUM_ATTR (attrs.at_count);
9394 CHECKSUM_ATTR (attrs.at_data_location);
9395 CHECKSUM_ATTR (attrs.at_data_member_location);
9396 CHECKSUM_ATTR (attrs.at_decimal_scale);
9397 CHECKSUM_ATTR (attrs.at_decimal_sign);
9398 CHECKSUM_ATTR (attrs.at_default_value);
9399 CHECKSUM_ATTR (attrs.at_digit_count);
9400 CHECKSUM_ATTR (attrs.at_discr);
9401 CHECKSUM_ATTR (attrs.at_discr_list);
9402 CHECKSUM_ATTR (attrs.at_discr_value);
9403 CHECKSUM_ATTR (attrs.at_encoding);
9404 CHECKSUM_ATTR (attrs.at_endianity);
9405 CHECKSUM_ATTR (attrs.at_explicit);
9406 CHECKSUM_ATTR (attrs.at_is_optional);
9407 CHECKSUM_ATTR (attrs.at_location);
9408 CHECKSUM_ATTR (attrs.at_lower_bound);
9409 CHECKSUM_ATTR (attrs.at_mutable);
9410 CHECKSUM_ATTR (attrs.at_ordering);
9411 CHECKSUM_ATTR (attrs.at_picture_string);
9412 CHECKSUM_ATTR (attrs.at_prototyped);
9413 CHECKSUM_ATTR (attrs.at_small);
9414 CHECKSUM_ATTR (attrs.at_segment);
9415 CHECKSUM_ATTR (attrs.at_string_length);
9416 CHECKSUM_ATTR (attrs.at_threads_scaled);
9417 CHECKSUM_ATTR (attrs.at_upper_bound);
9418 CHECKSUM_ATTR (attrs.at_use_location);
9419 CHECKSUM_ATTR (attrs.at_use_UTF8);
9420 CHECKSUM_ATTR (attrs.at_variable_parameter);
9421 CHECKSUM_ATTR (attrs.at_virtuality);
9422 CHECKSUM_ATTR (attrs.at_visibility);
9423 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9424 CHECKSUM_ATTR (attrs.at_type);
9425 CHECKSUM_ATTR (attrs.at_friend);
9427 /* Checksum the child DIEs, except for nested types and member functions. */
9430 dw_attr_ref name_attr;
9433 name_attr = get_AT (c, DW_AT_name);
9434 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9435 && name_attr != NULL)
9437 CHECKSUM_ULEB128 ('S');
9438 CHECKSUM_ULEB128 (c->die_tag);
9439 CHECKSUM_STRING (AT_string (name_attr));
9443 /* Mark this DIE so it gets processed when unmarking. */
9444 if (c->die_mark == 0)
9446 die_checksum_ordered (c, ctx, mark);
9448 } while (c != die->die_child);
9450 CHECKSUM_ULEB128 (0);
9454 #undef CHECKSUM_STRING
9455 #undef CHECKSUM_ATTR
9456 #undef CHECKSUM_LEB128
9457 #undef CHECKSUM_ULEB128
9459 /* Generate the type signature for DIE. This is computed by generating an
9460 MD5 checksum over the DIE's tag, its relevant attributes, and its
9461 children. Attributes that are references to other DIEs are processed
9462 by recursion, using the MARK field to prevent infinite recursion.
9463 If the DIE is nested inside a namespace or another type, we also
9464 need to include that context in the signature. The lower 64 bits
9465 of the resulting MD5 checksum comprise the signature. */
9468 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9472 unsigned char checksum[16];
9476 name = get_AT_string (die, DW_AT_name);
9477 decl = get_AT_ref (die, DW_AT_specification);
9479 /* First, compute a signature for just the type name (and its surrounding
9480 context, if any. This is stored in the type unit DIE for link-time
9481 ODR (one-definition rule) checking. */
9483 if (is_cxx() && name != NULL)
9485 md5_init_ctx (&ctx);
9487 /* Checksum the names of surrounding namespaces and structures. */
9488 if (decl != NULL && decl->die_parent != NULL)
9489 checksum_die_context (decl->die_parent, &ctx);
9491 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9492 md5_process_bytes (name, strlen (name) + 1, &ctx);
9493 md5_finish_ctx (&ctx, checksum);
9495 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9498 /* Next, compute the complete type signature. */
9500 md5_init_ctx (&ctx);
9502 die->die_mark = mark;
9504 /* Checksum the names of surrounding namespaces and structures. */
9505 if (decl != NULL && decl->die_parent != NULL)
9506 checksum_die_context (decl->die_parent, &ctx);
9508 /* Checksum the DIE and its children. */
9509 die_checksum_ordered (die, &ctx, &mark);
9510 unmark_all_dies (die);
9511 md5_finish_ctx (&ctx, checksum);
9513 /* Store the signature in the type node and link the type DIE and the
9514 type node together. */
9515 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9516 DWARF_TYPE_SIGNATURE_SIZE);
9517 die->die_id.die_type_node = type_node;
9518 type_node->type_die = die;
9520 /* If the DIE is a specification, link its declaration to the type node
9523 decl->die_id.die_type_node = type_node;
9526 /* Do the location expressions look same? */
9528 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9530 return loc1->dw_loc_opc == loc2->dw_loc_opc
9531 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9532 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9535 /* Do the values look the same? */
9537 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9539 dw_loc_descr_ref loc1, loc2;
9542 if (v1->val_class != v2->val_class)
9545 switch (v1->val_class)
9547 case dw_val_class_const:
9548 return v1->v.val_int == v2->v.val_int;
9549 case dw_val_class_unsigned_const:
9550 return v1->v.val_unsigned == v2->v.val_unsigned;
9551 case dw_val_class_const_double:
9552 return v1->v.val_double.high == v2->v.val_double.high
9553 && v1->v.val_double.low == v2->v.val_double.low;
9554 case dw_val_class_vec:
9555 if (v1->v.val_vec.length != v2->v.val_vec.length
9556 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9558 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9559 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9562 case dw_val_class_flag:
9563 return v1->v.val_flag == v2->v.val_flag;
9564 case dw_val_class_str:
9565 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9567 case dw_val_class_addr:
9568 r1 = v1->v.val_addr;
9569 r2 = v2->v.val_addr;
9570 if (GET_CODE (r1) != GET_CODE (r2))
9572 return !rtx_equal_p (r1, r2);
9574 case dw_val_class_offset:
9575 return v1->v.val_offset == v2->v.val_offset;
9577 case dw_val_class_loc:
9578 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9580 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9581 if (!same_loc_p (loc1, loc2, mark))
9583 return !loc1 && !loc2;
9585 case dw_val_class_die_ref:
9586 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9588 case dw_val_class_fde_ref:
9589 case dw_val_class_vms_delta:
9590 case dw_val_class_lbl_id:
9591 case dw_val_class_lineptr:
9592 case dw_val_class_macptr:
9595 case dw_val_class_file:
9596 return v1->v.val_file == v2->v.val_file;
9598 case dw_val_class_data8:
9599 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9606 /* Do the attributes look the same? */
9609 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9611 if (at1->dw_attr != at2->dw_attr)
9614 /* We don't care that this was compiled with a different compiler
9615 snapshot; if the output is the same, that's what matters. */
9616 if (at1->dw_attr == DW_AT_producer)
9619 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9622 /* Do the dies look the same? */
9625 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9631 /* To avoid infinite recursion. */
9633 return die1->die_mark == die2->die_mark;
9634 die1->die_mark = die2->die_mark = ++(*mark);
9636 if (die1->die_tag != die2->die_tag)
9639 if (VEC_length (dw_attr_node, die1->die_attr)
9640 != VEC_length (dw_attr_node, die2->die_attr))
9643 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9644 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9647 c1 = die1->die_child;
9648 c2 = die2->die_child;
9657 if (!same_die_p (c1, c2, mark))
9661 if (c1 == die1->die_child)
9663 if (c2 == die2->die_child)
9673 /* Do the dies look the same? Wrapper around same_die_p. */
9676 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9679 int ret = same_die_p (die1, die2, &mark);
9681 unmark_all_dies (die1);
9682 unmark_all_dies (die2);
9687 /* The prefix to attach to symbols on DIEs in the current comdat debug
9689 static char *comdat_symbol_id;
9691 /* The index of the current symbol within the current comdat CU. */
9692 static unsigned int comdat_symbol_number;
9694 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9695 children, and set comdat_symbol_id accordingly. */
9698 compute_section_prefix (dw_die_ref unit_die)
9700 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9701 const char *base = die_name ? lbasename (die_name) : "anonymous";
9702 char *name = XALLOCAVEC (char, strlen (base) + 64);
9705 unsigned char checksum[16];
9708 /* Compute the checksum of the DIE, then append part of it as hex digits to
9709 the name filename of the unit. */
9711 md5_init_ctx (&ctx);
9713 die_checksum (unit_die, &ctx, &mark);
9714 unmark_all_dies (unit_die);
9715 md5_finish_ctx (&ctx, checksum);
9717 sprintf (name, "%s.", base);
9718 clean_symbol_name (name);
9720 p = name + strlen (name);
9721 for (i = 0; i < 4; i++)
9723 sprintf (p, "%.2x", checksum[i]);
9727 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9728 comdat_symbol_number = 0;
9731 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9734 is_type_die (dw_die_ref die)
9736 switch (die->die_tag)
9738 case DW_TAG_array_type:
9739 case DW_TAG_class_type:
9740 case DW_TAG_interface_type:
9741 case DW_TAG_enumeration_type:
9742 case DW_TAG_pointer_type:
9743 case DW_TAG_reference_type:
9744 case DW_TAG_rvalue_reference_type:
9745 case DW_TAG_string_type:
9746 case DW_TAG_structure_type:
9747 case DW_TAG_subroutine_type:
9748 case DW_TAG_union_type:
9749 case DW_TAG_ptr_to_member_type:
9750 case DW_TAG_set_type:
9751 case DW_TAG_subrange_type:
9752 case DW_TAG_base_type:
9753 case DW_TAG_const_type:
9754 case DW_TAG_file_type:
9755 case DW_TAG_packed_type:
9756 case DW_TAG_volatile_type:
9757 case DW_TAG_typedef:
9764 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9765 Basically, we want to choose the bits that are likely to be shared between
9766 compilations (types) and leave out the bits that are specific to individual
9767 compilations (functions). */
9770 is_comdat_die (dw_die_ref c)
9772 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9773 we do for stabs. The advantage is a greater likelihood of sharing between
9774 objects that don't include headers in the same order (and therefore would
9775 put the base types in a different comdat). jason 8/28/00 */
9777 if (c->die_tag == DW_TAG_base_type)
9780 if (c->die_tag == DW_TAG_pointer_type
9781 || c->die_tag == DW_TAG_reference_type
9782 || c->die_tag == DW_TAG_rvalue_reference_type
9783 || c->die_tag == DW_TAG_const_type
9784 || c->die_tag == DW_TAG_volatile_type)
9786 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9788 return t ? is_comdat_die (t) : 0;
9791 return is_type_die (c);
9794 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9795 compilation unit. */
9798 is_symbol_die (dw_die_ref c)
9800 return (is_type_die (c)
9801 || is_declaration_die (c)
9802 || c->die_tag == DW_TAG_namespace
9803 || c->die_tag == DW_TAG_module);
9806 /* Returns true iff C is a compile-unit DIE. */
9809 is_cu_die (dw_die_ref c)
9811 return c && c->die_tag == DW_TAG_compile_unit;
9815 gen_internal_sym (const char *prefix)
9819 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9820 return xstrdup (buf);
9823 /* Assign symbols to all worthy DIEs under DIE. */
9826 assign_symbol_names (dw_die_ref die)
9830 if (is_symbol_die (die))
9832 if (comdat_symbol_id)
9834 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9836 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9837 comdat_symbol_id, comdat_symbol_number++);
9838 die->die_id.die_symbol = xstrdup (p);
9841 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9844 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9847 struct cu_hash_table_entry
9850 unsigned min_comdat_num, max_comdat_num;
9851 struct cu_hash_table_entry *next;
9854 /* Routines to manipulate hash table of CUs. */
9856 htab_cu_hash (const void *of)
9858 const struct cu_hash_table_entry *const entry =
9859 (const struct cu_hash_table_entry *) of;
9861 return htab_hash_string (entry->cu->die_id.die_symbol);
9865 htab_cu_eq (const void *of1, const void *of2)
9867 const struct cu_hash_table_entry *const entry1 =
9868 (const struct cu_hash_table_entry *) of1;
9869 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9871 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9875 htab_cu_del (void *what)
9877 struct cu_hash_table_entry *next,
9878 *entry = (struct cu_hash_table_entry *) what;
9888 /* Check whether we have already seen this CU and set up SYM_NUM
9891 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9893 struct cu_hash_table_entry dummy;
9894 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9896 dummy.max_comdat_num = 0;
9898 slot = (struct cu_hash_table_entry **)
9899 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9903 for (; entry; last = entry, entry = entry->next)
9905 if (same_die_p_wrap (cu, entry->cu))
9911 *sym_num = entry->min_comdat_num;
9915 entry = XCNEW (struct cu_hash_table_entry);
9917 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9918 entry->next = *slot;
9924 /* Record SYM_NUM to record of CU in HTABLE. */
9926 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9928 struct cu_hash_table_entry **slot, *entry;
9930 slot = (struct cu_hash_table_entry **)
9931 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9935 entry->max_comdat_num = sym_num;
9938 /* Traverse the DIE (which is always comp_unit_die), and set up
9939 additional compilation units for each of the include files we see
9940 bracketed by BINCL/EINCL. */
9943 break_out_includes (dw_die_ref die)
9946 dw_die_ref unit = NULL;
9947 limbo_die_node *node, **pnode;
9948 htab_t cu_hash_table;
9952 dw_die_ref prev = c;
9954 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9955 || (unit && is_comdat_die (c)))
9957 dw_die_ref next = c->die_sib;
9959 /* This DIE is for a secondary CU; remove it from the main one. */
9960 remove_child_with_prev (c, prev);
9962 if (c->die_tag == DW_TAG_GNU_BINCL)
9963 unit = push_new_compile_unit (unit, c);
9964 else if (c->die_tag == DW_TAG_GNU_EINCL)
9965 unit = pop_compile_unit (unit);
9967 add_child_die (unit, c);
9969 if (c == die->die_child)
9972 } while (c != die->die_child);
9975 /* We can only use this in debugging, since the frontend doesn't check
9976 to make sure that we leave every include file we enter. */
9980 assign_symbol_names (die);
9981 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9982 for (node = limbo_die_list, pnode = &limbo_die_list;
9988 compute_section_prefix (node->die);
9989 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9990 &comdat_symbol_number);
9991 assign_symbol_names (node->die);
9993 *pnode = node->next;
9996 pnode = &node->next;
9997 record_comdat_symbol_number (node->die, cu_hash_table,
9998 comdat_symbol_number);
10001 htab_delete (cu_hash_table);
10004 /* Return non-zero if this DIE is a declaration. */
10007 is_declaration_die (dw_die_ref die)
10012 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10013 if (a->dw_attr == DW_AT_declaration)
10019 /* Return non-zero if this DIE is nested inside a subprogram. */
10022 is_nested_in_subprogram (dw_die_ref die)
10024 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10028 return local_scope_p (decl);
10031 /* Return non-zero if this is a type DIE that should be moved to a
10032 COMDAT .debug_types section. */
10035 should_move_die_to_comdat (dw_die_ref die)
10037 switch (die->die_tag)
10039 case DW_TAG_class_type:
10040 case DW_TAG_structure_type:
10041 case DW_TAG_enumeration_type:
10042 case DW_TAG_union_type:
10043 /* Don't move declarations, inlined instances, or types nested in a
10045 if (is_declaration_die (die)
10046 || get_AT (die, DW_AT_abstract_origin)
10047 || is_nested_in_subprogram (die))
10050 case DW_TAG_array_type:
10051 case DW_TAG_interface_type:
10052 case DW_TAG_pointer_type:
10053 case DW_TAG_reference_type:
10054 case DW_TAG_rvalue_reference_type:
10055 case DW_TAG_string_type:
10056 case DW_TAG_subroutine_type:
10057 case DW_TAG_ptr_to_member_type:
10058 case DW_TAG_set_type:
10059 case DW_TAG_subrange_type:
10060 case DW_TAG_base_type:
10061 case DW_TAG_const_type:
10062 case DW_TAG_file_type:
10063 case DW_TAG_packed_type:
10064 case DW_TAG_volatile_type:
10065 case DW_TAG_typedef:
10071 /* Make a clone of DIE. */
10074 clone_die (dw_die_ref die)
10080 clone = ggc_alloc_cleared_die_node ();
10081 clone->die_tag = die->die_tag;
10083 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10084 add_dwarf_attr (clone, a);
10089 /* Make a clone of the tree rooted at DIE. */
10092 clone_tree (dw_die_ref die)
10095 dw_die_ref clone = clone_die (die);
10097 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10102 /* Make a clone of DIE as a declaration. */
10105 clone_as_declaration (dw_die_ref die)
10112 /* If the DIE is already a declaration, just clone it. */
10113 if (is_declaration_die (die))
10114 return clone_die (die);
10116 /* If the DIE is a specification, just clone its declaration DIE. */
10117 decl = get_AT_ref (die, DW_AT_specification);
10119 return clone_die (decl);
10121 clone = ggc_alloc_cleared_die_node ();
10122 clone->die_tag = die->die_tag;
10124 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10126 /* We don't want to copy over all attributes.
10127 For example we don't want DW_AT_byte_size because otherwise we will no
10128 longer have a declaration and GDB will treat it as a definition. */
10130 switch (a->dw_attr)
10132 case DW_AT_artificial:
10133 case DW_AT_containing_type:
10134 case DW_AT_external:
10137 case DW_AT_virtuality:
10138 case DW_AT_linkage_name:
10139 case DW_AT_MIPS_linkage_name:
10140 add_dwarf_attr (clone, a);
10142 case DW_AT_byte_size:
10148 if (die->die_id.die_type_node)
10149 add_AT_die_ref (clone, DW_AT_signature, die);
10151 add_AT_flag (clone, DW_AT_declaration, 1);
10155 /* Copy the declaration context to the new compile unit DIE. This includes
10156 any surrounding namespace or type declarations. If the DIE has an
10157 AT_specification attribute, it also includes attributes and children
10158 attached to the specification. */
10161 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10164 dw_die_ref new_decl;
10166 decl = get_AT_ref (die, DW_AT_specification);
10175 /* Copy the type node pointer from the new DIE to the original
10176 declaration DIE so we can forward references later. */
10177 decl->die_id.die_type_node = die->die_id.die_type_node;
10179 remove_AT (die, DW_AT_specification);
10181 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10183 if (a->dw_attr != DW_AT_name
10184 && a->dw_attr != DW_AT_declaration
10185 && a->dw_attr != DW_AT_external)
10186 add_dwarf_attr (die, a);
10189 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10192 if (decl->die_parent != NULL
10193 && decl->die_parent->die_tag != DW_TAG_compile_unit
10194 && decl->die_parent->die_tag != DW_TAG_type_unit)
10196 new_decl = copy_ancestor_tree (unit, decl, NULL);
10197 if (new_decl != NULL)
10199 remove_AT (new_decl, DW_AT_signature);
10200 add_AT_specification (die, new_decl);
10205 /* Generate the skeleton ancestor tree for the given NODE, then clone
10206 the DIE and add the clone into the tree. */
10209 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10211 if (node->new_die != NULL)
10214 node->new_die = clone_as_declaration (node->old_die);
10216 if (node->parent != NULL)
10218 generate_skeleton_ancestor_tree (node->parent);
10219 add_child_die (node->parent->new_die, node->new_die);
10223 /* Generate a skeleton tree of DIEs containing any declarations that are
10224 found in the original tree. We traverse the tree looking for declaration
10225 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10228 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10230 skeleton_chain_node node;
10233 dw_die_ref prev = NULL;
10234 dw_die_ref next = NULL;
10236 node.parent = parent;
10238 first = c = parent->old_die->die_child;
10242 if (prev == NULL || prev->die_sib == c)
10245 next = (c == first ? NULL : c->die_sib);
10247 node.new_die = NULL;
10248 if (is_declaration_die (c))
10250 /* Clone the existing DIE, move the original to the skeleton
10251 tree (which is in the main CU), and put the clone, with
10252 all the original's children, where the original came from. */
10253 dw_die_ref clone = clone_die (c);
10254 move_all_children (c, clone);
10256 replace_child (c, clone, prev);
10257 generate_skeleton_ancestor_tree (parent);
10258 add_child_die (parent->new_die, c);
10262 generate_skeleton_bottom_up (&node);
10263 } while (next != NULL);
10266 /* Wrapper function for generate_skeleton_bottom_up. */
10269 generate_skeleton (dw_die_ref die)
10271 skeleton_chain_node node;
10273 node.old_die = die;
10274 node.new_die = NULL;
10275 node.parent = NULL;
10277 /* If this type definition is nested inside another type,
10278 always leave at least a declaration in its place. */
10279 if (die->die_parent != NULL && is_type_die (die->die_parent))
10280 node.new_die = clone_as_declaration (die);
10282 generate_skeleton_bottom_up (&node);
10283 return node.new_die;
10286 /* Remove the DIE from its parent, possibly replacing it with a cloned
10287 declaration. The original DIE will be moved to a new compile unit
10288 so that existing references to it follow it to the new location. If
10289 any of the original DIE's descendants is a declaration, we need to
10290 replace the original DIE with a skeleton tree and move the
10291 declarations back into the skeleton tree. */
10294 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10296 dw_die_ref skeleton;
10298 skeleton = generate_skeleton (child);
10299 if (skeleton == NULL)
10300 remove_child_with_prev (child, prev);
10303 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10304 replace_child (child, skeleton, prev);
10310 /* Traverse the DIE and set up additional .debug_types sections for each
10311 type worthy of being placed in a COMDAT section. */
10314 break_out_comdat_types (dw_die_ref die)
10318 dw_die_ref prev = NULL;
10319 dw_die_ref next = NULL;
10320 dw_die_ref unit = NULL;
10322 first = c = die->die_child;
10326 if (prev == NULL || prev->die_sib == c)
10329 next = (c == first ? NULL : c->die_sib);
10330 if (should_move_die_to_comdat (c))
10332 dw_die_ref replacement;
10333 comdat_type_node_ref type_node;
10335 /* Create a new type unit DIE as the root for the new tree, and
10336 add it to the list of comdat types. */
10337 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10338 add_AT_unsigned (unit, DW_AT_language,
10339 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10340 type_node = ggc_alloc_cleared_comdat_type_node ();
10341 type_node->root_die = unit;
10342 type_node->next = comdat_type_list;
10343 comdat_type_list = type_node;
10345 /* Generate the type signature. */
10346 generate_type_signature (c, type_node);
10348 /* Copy the declaration context, attributes, and children of the
10349 declaration into the new compile unit DIE. */
10350 copy_declaration_context (unit, c);
10352 /* Remove this DIE from the main CU. */
10353 replacement = remove_child_or_replace_with_skeleton (c, prev);
10355 /* Break out nested types into their own type units. */
10356 break_out_comdat_types (c);
10358 /* Add the DIE to the new compunit. */
10359 add_child_die (unit, c);
10361 if (replacement != NULL)
10364 else if (c->die_tag == DW_TAG_namespace
10365 || c->die_tag == DW_TAG_class_type
10366 || c->die_tag == DW_TAG_structure_type
10367 || c->die_tag == DW_TAG_union_type)
10369 /* Look for nested types that can be broken out. */
10370 break_out_comdat_types (c);
10372 } while (next != NULL);
10375 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10377 struct decl_table_entry
10383 /* Routines to manipulate hash table of copied declarations. */
10386 htab_decl_hash (const void *of)
10388 const struct decl_table_entry *const entry =
10389 (const struct decl_table_entry *) of;
10391 return htab_hash_pointer (entry->orig);
10395 htab_decl_eq (const void *of1, const void *of2)
10397 const struct decl_table_entry *const entry1 =
10398 (const struct decl_table_entry *) of1;
10399 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10401 return entry1->orig == entry2;
10405 htab_decl_del (void *what)
10407 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10412 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10413 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10414 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10415 to check if the ancestor has already been copied into UNIT. */
10418 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10420 dw_die_ref parent = die->die_parent;
10421 dw_die_ref new_parent = unit;
10423 void **slot = NULL;
10424 struct decl_table_entry *entry = NULL;
10428 /* Check if the entry has already been copied to UNIT. */
10429 slot = htab_find_slot_with_hash (decl_table, die,
10430 htab_hash_pointer (die), INSERT);
10431 if (*slot != HTAB_EMPTY_ENTRY)
10433 entry = (struct decl_table_entry *) *slot;
10434 return entry->copy;
10437 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10438 entry = XCNEW (struct decl_table_entry);
10440 entry->copy = NULL;
10444 if (parent != NULL)
10446 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10449 if (parent->die_tag != DW_TAG_compile_unit
10450 && parent->die_tag != DW_TAG_type_unit)
10451 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10454 copy = clone_as_declaration (die);
10455 add_child_die (new_parent, copy);
10457 if (decl_table != NULL)
10459 /* Record the pointer to the copy. */
10460 entry->copy = copy;
10466 /* Walk the DIE and its children, looking for references to incomplete
10467 or trivial types that are unmarked (i.e., that are not in the current
10471 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10477 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10479 if (AT_class (a) == dw_val_class_die_ref)
10481 dw_die_ref targ = AT_ref (a);
10482 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10484 struct decl_table_entry *entry;
10486 if (targ->die_mark != 0 || type_node != NULL)
10489 slot = htab_find_slot_with_hash (decl_table, targ,
10490 htab_hash_pointer (targ), INSERT);
10492 if (*slot != HTAB_EMPTY_ENTRY)
10494 /* TARG has already been copied, so we just need to
10495 modify the reference to point to the copy. */
10496 entry = (struct decl_table_entry *) *slot;
10497 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10501 dw_die_ref parent = unit;
10502 dw_die_ref copy = clone_tree (targ);
10504 /* Make sure the cloned tree is marked as part of the
10508 /* Record in DECL_TABLE that TARG has been copied.
10509 Need to do this now, before the recursive call,
10510 because DECL_TABLE may be expanded and SLOT
10511 would no longer be a valid pointer. */
10512 entry = XCNEW (struct decl_table_entry);
10513 entry->orig = targ;
10514 entry->copy = copy;
10517 /* If TARG has surrounding context, copy its ancestor tree
10518 into the new type unit. */
10519 if (targ->die_parent != NULL
10520 && targ->die_parent->die_tag != DW_TAG_compile_unit
10521 && targ->die_parent->die_tag != DW_TAG_type_unit)
10522 parent = copy_ancestor_tree (unit, targ->die_parent,
10525 add_child_die (parent, copy);
10526 a->dw_attr_val.v.val_die_ref.die = copy;
10528 /* Make sure the newly-copied DIE is walked. If it was
10529 installed in a previously-added context, it won't
10530 get visited otherwise. */
10531 if (parent != unit)
10533 /* Find the highest point of the newly-added tree,
10534 mark each node along the way, and walk from there. */
10535 parent->die_mark = 1;
10536 while (parent->die_parent
10537 && parent->die_parent->die_mark == 0)
10539 parent = parent->die_parent;
10540 parent->die_mark = 1;
10542 copy_decls_walk (unit, parent, decl_table);
10548 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10551 /* Copy declarations for "unworthy" types into the new comdat section.
10552 Incomplete types, modified types, and certain other types aren't broken
10553 out into comdat sections of their own, so they don't have a signature,
10554 and we need to copy the declaration into the same section so that we
10555 don't have an external reference. */
10558 copy_decls_for_unworthy_types (dw_die_ref unit)
10563 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10564 copy_decls_walk (unit, unit, decl_table);
10565 htab_delete (decl_table);
10566 unmark_dies (unit);
10569 /* Traverse the DIE and add a sibling attribute if it may have the
10570 effect of speeding up access to siblings. To save some space,
10571 avoid generating sibling attributes for DIE's without children. */
10574 add_sibling_attributes (dw_die_ref die)
10578 if (! die->die_child)
10581 if (die->die_parent && die != die->die_parent->die_child)
10582 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10584 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10587 /* Output all location lists for the DIE and its children. */
10590 output_location_lists (dw_die_ref die)
10596 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10597 if (AT_class (a) == dw_val_class_loc_list)
10598 output_loc_list (AT_loc_list (a));
10600 FOR_EACH_CHILD (die, c, output_location_lists (c));
10603 /* The format of each DIE (and its attribute value pairs) is encoded in an
10604 abbreviation table. This routine builds the abbreviation table and assigns
10605 a unique abbreviation id for each abbreviation entry. The children of each
10606 die are visited recursively. */
10609 build_abbrev_table (dw_die_ref die)
10611 unsigned long abbrev_id;
10612 unsigned int n_alloc;
10617 /* Scan the DIE references, and mark as external any that refer to
10618 DIEs from other CUs (i.e. those which are not marked). */
10619 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10620 if (AT_class (a) == dw_val_class_die_ref
10621 && AT_ref (a)->die_mark == 0)
10623 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10624 set_AT_ref_external (a, 1);
10627 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10629 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10630 dw_attr_ref die_a, abbrev_a;
10634 if (abbrev->die_tag != die->die_tag)
10636 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10639 if (VEC_length (dw_attr_node, abbrev->die_attr)
10640 != VEC_length (dw_attr_node, die->die_attr))
10643 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10645 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10646 if ((abbrev_a->dw_attr != die_a->dw_attr)
10647 || (value_format (abbrev_a) != value_format (die_a)))
10657 if (abbrev_id >= abbrev_die_table_in_use)
10659 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10661 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10662 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10665 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10666 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10667 abbrev_die_table_allocated = n_alloc;
10670 ++abbrev_die_table_in_use;
10671 abbrev_die_table[abbrev_id] = die;
10674 die->die_abbrev = abbrev_id;
10675 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10678 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10681 constant_size (unsigned HOST_WIDE_INT value)
10688 log = floor_log2 (value);
10691 log = 1 << (floor_log2 (log) + 1);
10696 /* Return the size of a DIE as it is represented in the
10697 .debug_info section. */
10699 static unsigned long
10700 size_of_die (dw_die_ref die)
10702 unsigned long size = 0;
10706 size += size_of_uleb128 (die->die_abbrev);
10707 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10709 switch (AT_class (a))
10711 case dw_val_class_addr:
10712 size += DWARF2_ADDR_SIZE;
10714 case dw_val_class_offset:
10715 size += DWARF_OFFSET_SIZE;
10717 case dw_val_class_loc:
10719 unsigned long lsize = size_of_locs (AT_loc (a));
10721 /* Block length. */
10722 if (dwarf_version >= 4)
10723 size += size_of_uleb128 (lsize);
10725 size += constant_size (lsize);
10729 case dw_val_class_loc_list:
10730 size += DWARF_OFFSET_SIZE;
10732 case dw_val_class_range_list:
10733 size += DWARF_OFFSET_SIZE;
10735 case dw_val_class_const:
10736 size += size_of_sleb128 (AT_int (a));
10738 case dw_val_class_unsigned_const:
10739 size += constant_size (AT_unsigned (a));
10741 case dw_val_class_const_double:
10742 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10743 if (HOST_BITS_PER_WIDE_INT >= 64)
10744 size++; /* block */
10746 case dw_val_class_vec:
10747 size += constant_size (a->dw_attr_val.v.val_vec.length
10748 * a->dw_attr_val.v.val_vec.elt_size)
10749 + a->dw_attr_val.v.val_vec.length
10750 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10752 case dw_val_class_flag:
10753 if (dwarf_version >= 4)
10754 /* Currently all add_AT_flag calls pass in 1 as last argument,
10755 so DW_FORM_flag_present can be used. If that ever changes,
10756 we'll need to use DW_FORM_flag and have some optimization
10757 in build_abbrev_table that will change those to
10758 DW_FORM_flag_present if it is set to 1 in all DIEs using
10759 the same abbrev entry. */
10760 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10764 case dw_val_class_die_ref:
10765 if (AT_ref_external (a))
10767 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10768 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10769 is sized by target address length, whereas in DWARF3
10770 it's always sized as an offset. */
10771 if (dwarf_version >= 4)
10772 size += DWARF_TYPE_SIGNATURE_SIZE;
10773 else if (dwarf_version == 2)
10774 size += DWARF2_ADDR_SIZE;
10776 size += DWARF_OFFSET_SIZE;
10779 size += DWARF_OFFSET_SIZE;
10781 case dw_val_class_fde_ref:
10782 size += DWARF_OFFSET_SIZE;
10784 case dw_val_class_lbl_id:
10785 size += DWARF2_ADDR_SIZE;
10787 case dw_val_class_lineptr:
10788 case dw_val_class_macptr:
10789 size += DWARF_OFFSET_SIZE;
10791 case dw_val_class_str:
10792 if (AT_string_form (a) == DW_FORM_strp)
10793 size += DWARF_OFFSET_SIZE;
10795 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10797 case dw_val_class_file:
10798 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10800 case dw_val_class_data8:
10803 case dw_val_class_vms_delta:
10804 size += DWARF_OFFSET_SIZE;
10807 gcc_unreachable ();
10814 /* Size the debugging information associated with a given DIE. Visits the
10815 DIE's children recursively. Updates the global variable next_die_offset, on
10816 each time through. Uses the current value of next_die_offset to update the
10817 die_offset field in each DIE. */
10820 calc_die_sizes (dw_die_ref die)
10824 die->die_offset = next_die_offset;
10825 next_die_offset += size_of_die (die);
10827 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10829 if (die->die_child != NULL)
10830 /* Count the null byte used to terminate sibling lists. */
10831 next_die_offset += 1;
10834 /* Set the marks for a die and its children. We do this so
10835 that we know whether or not a reference needs to use FORM_ref_addr; only
10836 DIEs in the same CU will be marked. We used to clear out the offset
10837 and use that as the flag, but ran into ordering problems. */
10840 mark_dies (dw_die_ref die)
10844 gcc_assert (!die->die_mark);
10847 FOR_EACH_CHILD (die, c, mark_dies (c));
10850 /* Clear the marks for a die and its children. */
10853 unmark_dies (dw_die_ref die)
10857 if (dwarf_version < 4)
10858 gcc_assert (die->die_mark);
10861 FOR_EACH_CHILD (die, c, unmark_dies (c));
10864 /* Clear the marks for a die, its children and referred dies. */
10867 unmark_all_dies (dw_die_ref die)
10873 if (!die->die_mark)
10877 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10879 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10880 if (AT_class (a) == dw_val_class_die_ref)
10881 unmark_all_dies (AT_ref (a));
10884 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10885 generated for the compilation unit. */
10887 static unsigned long
10888 size_of_pubnames (VEC (pubname_entry, gc) * names)
10890 unsigned long size;
10894 size = DWARF_PUBNAMES_HEADER_SIZE;
10895 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10896 if (names != pubtype_table
10897 || p->die->die_offset != 0
10898 || !flag_eliminate_unused_debug_types)
10899 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10901 size += DWARF_OFFSET_SIZE;
10905 /* Return the size of the information in the .debug_aranges section. */
10907 static unsigned long
10908 size_of_aranges (void)
10910 unsigned long size;
10912 size = DWARF_ARANGES_HEADER_SIZE;
10914 /* Count the address/length pair for this compilation unit. */
10915 if (text_section_used)
10916 size += 2 * DWARF2_ADDR_SIZE;
10917 if (cold_text_section_used)
10918 size += 2 * DWARF2_ADDR_SIZE;
10919 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10921 /* Count the two zero words used to terminated the address range table. */
10922 size += 2 * DWARF2_ADDR_SIZE;
10926 /* Select the encoding of an attribute value. */
10928 static enum dwarf_form
10929 value_format (dw_attr_ref a)
10931 switch (a->dw_attr_val.val_class)
10933 case dw_val_class_addr:
10934 /* Only very few attributes allow DW_FORM_addr. */
10935 switch (a->dw_attr)
10938 case DW_AT_high_pc:
10939 case DW_AT_entry_pc:
10940 case DW_AT_trampoline:
10941 return DW_FORM_addr;
10945 switch (DWARF2_ADDR_SIZE)
10948 return DW_FORM_data1;
10950 return DW_FORM_data2;
10952 return DW_FORM_data4;
10954 return DW_FORM_data8;
10956 gcc_unreachable ();
10958 case dw_val_class_range_list:
10959 case dw_val_class_loc_list:
10960 if (dwarf_version >= 4)
10961 return DW_FORM_sec_offset;
10963 case dw_val_class_vms_delta:
10964 case dw_val_class_offset:
10965 switch (DWARF_OFFSET_SIZE)
10968 return DW_FORM_data4;
10970 return DW_FORM_data8;
10972 gcc_unreachable ();
10974 case dw_val_class_loc:
10975 if (dwarf_version >= 4)
10976 return DW_FORM_exprloc;
10977 switch (constant_size (size_of_locs (AT_loc (a))))
10980 return DW_FORM_block1;
10982 return DW_FORM_block2;
10984 gcc_unreachable ();
10986 case dw_val_class_const:
10987 return DW_FORM_sdata;
10988 case dw_val_class_unsigned_const:
10989 switch (constant_size (AT_unsigned (a)))
10992 return DW_FORM_data1;
10994 return DW_FORM_data2;
10996 return DW_FORM_data4;
10998 return DW_FORM_data8;
11000 gcc_unreachable ();
11002 case dw_val_class_const_double:
11003 switch (HOST_BITS_PER_WIDE_INT)
11006 return DW_FORM_data2;
11008 return DW_FORM_data4;
11010 return DW_FORM_data8;
11013 return DW_FORM_block1;
11015 case dw_val_class_vec:
11016 switch (constant_size (a->dw_attr_val.v.val_vec.length
11017 * a->dw_attr_val.v.val_vec.elt_size))
11020 return DW_FORM_block1;
11022 return DW_FORM_block2;
11024 return DW_FORM_block4;
11026 gcc_unreachable ();
11028 case dw_val_class_flag:
11029 if (dwarf_version >= 4)
11031 /* Currently all add_AT_flag calls pass in 1 as last argument,
11032 so DW_FORM_flag_present can be used. If that ever changes,
11033 we'll need to use DW_FORM_flag and have some optimization
11034 in build_abbrev_table that will change those to
11035 DW_FORM_flag_present if it is set to 1 in all DIEs using
11036 the same abbrev entry. */
11037 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11038 return DW_FORM_flag_present;
11040 return DW_FORM_flag;
11041 case dw_val_class_die_ref:
11042 if (AT_ref_external (a))
11043 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
11045 return DW_FORM_ref;
11046 case dw_val_class_fde_ref:
11047 return DW_FORM_data;
11048 case dw_val_class_lbl_id:
11049 return DW_FORM_addr;
11050 case dw_val_class_lineptr:
11051 case dw_val_class_macptr:
11052 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11053 case dw_val_class_str:
11054 return AT_string_form (a);
11055 case dw_val_class_file:
11056 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11059 return DW_FORM_data1;
11061 return DW_FORM_data2;
11063 return DW_FORM_data4;
11065 gcc_unreachable ();
11068 case dw_val_class_data8:
11069 return DW_FORM_data8;
11072 gcc_unreachable ();
11076 /* Output the encoding of an attribute value. */
11079 output_value_format (dw_attr_ref a)
11081 enum dwarf_form form = value_format (a);
11083 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11086 /* Output the .debug_abbrev section which defines the DIE abbreviation
11090 output_abbrev_section (void)
11092 unsigned long abbrev_id;
11094 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11096 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11098 dw_attr_ref a_attr;
11100 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11101 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11102 dwarf_tag_name (abbrev->die_tag));
11104 if (abbrev->die_child != NULL)
11105 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11107 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11109 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11112 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11113 dwarf_attr_name (a_attr->dw_attr));
11114 output_value_format (a_attr);
11117 dw2_asm_output_data (1, 0, NULL);
11118 dw2_asm_output_data (1, 0, NULL);
11121 /* Terminate the table. */
11122 dw2_asm_output_data (1, 0, NULL);
11125 /* Output a symbol we can use to refer to this DIE from another CU. */
11128 output_die_symbol (dw_die_ref die)
11130 char *sym = die->die_id.die_symbol;
11135 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11136 /* We make these global, not weak; if the target doesn't support
11137 .linkonce, it doesn't support combining the sections, so debugging
11139 targetm.asm_out.globalize_label (asm_out_file, sym);
11141 ASM_OUTPUT_LABEL (asm_out_file, sym);
11144 /* Return a new location list, given the begin and end range, and the
11147 static inline dw_loc_list_ref
11148 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11149 const char *section)
11151 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11153 retlist->begin = begin;
11154 retlist->end = end;
11155 retlist->expr = expr;
11156 retlist->section = section;
11161 /* Generate a new internal symbol for this location list node, if it
11162 hasn't got one yet. */
11165 gen_llsym (dw_loc_list_ref list)
11167 gcc_assert (!list->ll_symbol);
11168 list->ll_symbol = gen_internal_sym ("LLST");
11171 /* Output the location list given to us. */
11174 output_loc_list (dw_loc_list_ref list_head)
11176 dw_loc_list_ref curr = list_head;
11178 if (list_head->emitted)
11180 list_head->emitted = true;
11182 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11184 /* Walk the location list, and output each range + expression. */
11185 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11187 unsigned long size;
11188 /* Don't output an entry that starts and ends at the same address. */
11189 if (strcmp (curr->begin, curr->end) == 0)
11191 if (!have_multiple_function_sections)
11193 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11194 "Location list begin address (%s)",
11195 list_head->ll_symbol);
11196 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11197 "Location list end address (%s)",
11198 list_head->ll_symbol);
11202 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11203 "Location list begin address (%s)",
11204 list_head->ll_symbol);
11205 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11206 "Location list end address (%s)",
11207 list_head->ll_symbol);
11209 size = size_of_locs (curr->expr);
11211 /* Output the block length for this list of location operations. */
11212 gcc_assert (size <= 0xffff);
11213 dw2_asm_output_data (2, size, "%s", "Location expression size");
11215 output_loc_sequence (curr->expr, -1);
11218 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11219 "Location list terminator begin (%s)",
11220 list_head->ll_symbol);
11221 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11222 "Location list terminator end (%s)",
11223 list_head->ll_symbol);
11226 /* Output a type signature. */
11229 output_signature (const char *sig, const char *name)
11233 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11234 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11237 /* Output the DIE and its attributes. Called recursively to generate
11238 the definitions of each child DIE. */
11241 output_die (dw_die_ref die)
11245 unsigned long size;
11248 /* If someone in another CU might refer to us, set up a symbol for
11249 them to point to. */
11250 if (dwarf_version < 4 && die->die_id.die_symbol)
11251 output_die_symbol (die);
11253 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11254 (unsigned long)die->die_offset,
11255 dwarf_tag_name (die->die_tag));
11257 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11259 const char *name = dwarf_attr_name (a->dw_attr);
11261 switch (AT_class (a))
11263 case dw_val_class_addr:
11264 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11267 case dw_val_class_offset:
11268 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11272 case dw_val_class_range_list:
11274 char *p = strchr (ranges_section_label, '\0');
11276 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11277 a->dw_attr_val.v.val_offset);
11278 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11279 debug_ranges_section, "%s", name);
11284 case dw_val_class_loc:
11285 size = size_of_locs (AT_loc (a));
11287 /* Output the block length for this list of location operations. */
11288 if (dwarf_version >= 4)
11289 dw2_asm_output_data_uleb128 (size, "%s", name);
11291 dw2_asm_output_data (constant_size (size), size, "%s", name);
11293 output_loc_sequence (AT_loc (a), -1);
11296 case dw_val_class_const:
11297 /* ??? It would be slightly more efficient to use a scheme like is
11298 used for unsigned constants below, but gdb 4.x does not sign
11299 extend. Gdb 5.x does sign extend. */
11300 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11303 case dw_val_class_unsigned_const:
11304 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11305 AT_unsigned (a), "%s", name);
11308 case dw_val_class_const_double:
11310 unsigned HOST_WIDE_INT first, second;
11312 if (HOST_BITS_PER_WIDE_INT >= 64)
11313 dw2_asm_output_data (1,
11314 2 * HOST_BITS_PER_WIDE_INT
11315 / HOST_BITS_PER_CHAR,
11318 if (WORDS_BIG_ENDIAN)
11320 first = a->dw_attr_val.v.val_double.high;
11321 second = a->dw_attr_val.v.val_double.low;
11325 first = a->dw_attr_val.v.val_double.low;
11326 second = a->dw_attr_val.v.val_double.high;
11329 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11331 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11336 case dw_val_class_vec:
11338 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11339 unsigned int len = a->dw_attr_val.v.val_vec.length;
11343 dw2_asm_output_data (constant_size (len * elt_size),
11344 len * elt_size, "%s", name);
11345 if (elt_size > sizeof (HOST_WIDE_INT))
11350 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11352 i++, p += elt_size)
11353 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11354 "fp or vector constant word %u", i);
11358 case dw_val_class_flag:
11359 if (dwarf_version >= 4)
11361 /* Currently all add_AT_flag calls pass in 1 as last argument,
11362 so DW_FORM_flag_present can be used. If that ever changes,
11363 we'll need to use DW_FORM_flag and have some optimization
11364 in build_abbrev_table that will change those to
11365 DW_FORM_flag_present if it is set to 1 in all DIEs using
11366 the same abbrev entry. */
11367 gcc_assert (AT_flag (a) == 1);
11368 if (flag_debug_asm)
11369 fprintf (asm_out_file, "\t\t\t%s %s\n",
11370 ASM_COMMENT_START, name);
11373 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11376 case dw_val_class_loc_list:
11378 char *sym = AT_loc_list (a)->ll_symbol;
11381 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11386 case dw_val_class_die_ref:
11387 if (AT_ref_external (a))
11389 if (dwarf_version >= 4)
11391 comdat_type_node_ref type_node =
11392 AT_ref (a)->die_id.die_type_node;
11394 gcc_assert (type_node);
11395 output_signature (type_node->signature, name);
11399 char *sym = AT_ref (a)->die_id.die_symbol;
11403 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11404 length, whereas in DWARF3 it's always sized as an
11406 if (dwarf_version == 2)
11407 size = DWARF2_ADDR_SIZE;
11409 size = DWARF_OFFSET_SIZE;
11410 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11416 gcc_assert (AT_ref (a)->die_offset);
11417 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11422 case dw_val_class_fde_ref:
11426 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11427 a->dw_attr_val.v.val_fde_index * 2);
11428 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11433 case dw_val_class_vms_delta:
11434 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11435 AT_vms_delta2 (a), AT_vms_delta1 (a),
11439 case dw_val_class_lbl_id:
11440 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11443 case dw_val_class_lineptr:
11444 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11445 debug_line_section, "%s", name);
11448 case dw_val_class_macptr:
11449 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11450 debug_macinfo_section, "%s", name);
11453 case dw_val_class_str:
11454 if (AT_string_form (a) == DW_FORM_strp)
11455 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11456 a->dw_attr_val.v.val_str->label,
11458 "%s: \"%s\"", name, AT_string (a));
11460 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11463 case dw_val_class_file:
11465 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11467 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11468 a->dw_attr_val.v.val_file->filename);
11472 case dw_val_class_data8:
11476 for (i = 0; i < 8; i++)
11477 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11478 i == 0 ? "%s" : NULL, name);
11483 gcc_unreachable ();
11487 FOR_EACH_CHILD (die, c, output_die (c));
11489 /* Add null byte to terminate sibling list. */
11490 if (die->die_child != NULL)
11491 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11492 (unsigned long) die->die_offset);
11495 /* Output the compilation unit that appears at the beginning of the
11496 .debug_info section, and precedes the DIE descriptions. */
11499 output_compilation_unit_header (void)
11501 int ver = dwarf_version;
11503 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11504 dw2_asm_output_data (4, 0xffffffff,
11505 "Initial length escape value indicating 64-bit DWARF extension");
11506 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11507 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11508 "Length of Compilation Unit Info");
11509 dw2_asm_output_data (2, ver, "DWARF version number");
11510 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11511 debug_abbrev_section,
11512 "Offset Into Abbrev. Section");
11513 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11516 /* Output the compilation unit DIE and its children. */
11519 output_comp_unit (dw_die_ref die, int output_if_empty)
11521 const char *secname;
11522 char *oldsym, *tmp;
11524 /* Unless we are outputting main CU, we may throw away empty ones. */
11525 if (!output_if_empty && die->die_child == NULL)
11528 /* Even if there are no children of this DIE, we must output the information
11529 about the compilation unit. Otherwise, on an empty translation unit, we
11530 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11531 will then complain when examining the file. First mark all the DIEs in
11532 this CU so we know which get local refs. */
11535 build_abbrev_table (die);
11537 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11538 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11539 calc_die_sizes (die);
11541 oldsym = die->die_id.die_symbol;
11544 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11546 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11548 die->die_id.die_symbol = NULL;
11549 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11553 switch_to_section (debug_info_section);
11554 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11555 info_section_emitted = true;
11558 /* Output debugging information. */
11559 output_compilation_unit_header ();
11562 /* Leave the marks on the main CU, so we can check them in
11563 output_pubnames. */
11567 die->die_id.die_symbol = oldsym;
11571 /* Output a comdat type unit DIE and its children. */
11574 output_comdat_type_unit (comdat_type_node *node)
11576 const char *secname;
11579 #if defined (OBJECT_FORMAT_ELF)
11583 /* First mark all the DIEs in this CU so we know which get local refs. */
11584 mark_dies (node->root_die);
11586 build_abbrev_table (node->root_die);
11588 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11589 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11590 calc_die_sizes (node->root_die);
11592 #if defined (OBJECT_FORMAT_ELF)
11593 secname = ".debug_types";
11594 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11595 sprintf (tmp, "wt.");
11596 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11597 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11598 comdat_key = get_identifier (tmp);
11599 targetm.asm_out.named_section (secname,
11600 SECTION_DEBUG | SECTION_LINKONCE,
11603 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11604 sprintf (tmp, ".gnu.linkonce.wt.");
11605 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11606 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11608 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11611 /* Output debugging information. */
11612 output_compilation_unit_header ();
11613 output_signature (node->signature, "Type Signature");
11614 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11615 "Offset to Type DIE");
11616 output_die (node->root_die);
11618 unmark_dies (node->root_die);
11621 /* Return the DWARF2/3 pubname associated with a decl. */
11623 static const char *
11624 dwarf2_name (tree decl, int scope)
11626 if (DECL_NAMELESS (decl))
11628 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11631 /* Add a new entry to .debug_pubnames if appropriate. */
11634 add_pubname_string (const char *str, dw_die_ref die)
11636 if (targetm.want_debug_pub_sections)
11641 e.name = xstrdup (str);
11642 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11647 add_pubname (tree decl, dw_die_ref die)
11649 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11651 const char *name = dwarf2_name (decl, 1);
11653 add_pubname_string (name, die);
11657 /* Add a new entry to .debug_pubtypes if appropriate. */
11660 add_pubtype (tree decl, dw_die_ref die)
11664 if (!targetm.want_debug_pub_sections)
11668 if ((TREE_PUBLIC (decl)
11669 || is_cu_die (die->die_parent))
11670 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11675 if (TYPE_NAME (decl))
11677 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11678 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11679 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11680 && DECL_NAME (TYPE_NAME (decl)))
11681 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11683 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11688 e.name = dwarf2_name (decl, 1);
11690 e.name = xstrdup (e.name);
11693 /* If we don't have a name for the type, there's no point in adding
11694 it to the table. */
11695 if (e.name && e.name[0] != '\0')
11696 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11700 /* Output the public names table used to speed up access to externally
11701 visible names; or the public types table used to find type definitions. */
11704 output_pubnames (VEC (pubname_entry, gc) * names)
11707 unsigned long pubnames_length = size_of_pubnames (names);
11710 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11711 dw2_asm_output_data (4, 0xffffffff,
11712 "Initial length escape value indicating 64-bit DWARF extension");
11713 if (names == pubname_table)
11714 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11715 "Length of Public Names Info");
11717 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11718 "Length of Public Type Names Info");
11719 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11720 dw2_asm_output_data (2, 2, "DWARF Version");
11721 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11722 debug_info_section,
11723 "Offset of Compilation Unit Info");
11724 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11725 "Compilation Unit Length");
11727 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11729 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11730 if (names == pubname_table)
11731 gcc_assert (pub->die->die_mark);
11733 if (names != pubtype_table
11734 || pub->die->die_offset != 0
11735 || !flag_eliminate_unused_debug_types)
11737 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11740 dw2_asm_output_nstring (pub->name, -1, "external name");
11744 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11747 /* Add a new entry to .debug_aranges if appropriate. */
11750 add_arange (tree decl, dw_die_ref die)
11752 if (! DECL_SECTION_NAME (decl))
11755 if (arange_table_in_use == arange_table_allocated)
11757 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11758 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11759 arange_table_allocated);
11760 memset (arange_table + arange_table_in_use, 0,
11761 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11764 arange_table[arange_table_in_use++] = die;
11767 /* Output the information that goes into the .debug_aranges table.
11768 Namely, define the beginning and ending address range of the
11769 text section generated for this compilation unit. */
11772 output_aranges (void)
11775 unsigned long aranges_length = size_of_aranges ();
11777 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11778 dw2_asm_output_data (4, 0xffffffff,
11779 "Initial length escape value indicating 64-bit DWARF extension");
11780 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11781 "Length of Address Ranges Info");
11782 /* Version number for aranges is still 2, even in DWARF3. */
11783 dw2_asm_output_data (2, 2, "DWARF Version");
11784 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11785 debug_info_section,
11786 "Offset of Compilation Unit Info");
11787 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11788 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11790 /* We need to align to twice the pointer size here. */
11791 if (DWARF_ARANGES_PAD_SIZE)
11793 /* Pad using a 2 byte words so that padding is correct for any
11795 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11796 2 * DWARF2_ADDR_SIZE);
11797 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11798 dw2_asm_output_data (2, 0, NULL);
11801 /* It is necessary not to output these entries if the sections were
11802 not used; if the sections were not used, the length will be 0 and
11803 the address may end up as 0 if the section is discarded by ld
11804 --gc-sections, leaving an invalid (0, 0) entry that can be
11805 confused with the terminator. */
11806 if (text_section_used)
11808 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11809 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11810 text_section_label, "Length");
11812 if (cold_text_section_used)
11814 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11816 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11817 cold_text_section_label, "Length");
11820 for (i = 0; i < arange_table_in_use; i++)
11822 dw_die_ref die = arange_table[i];
11824 /* We shouldn't see aranges for DIEs outside of the main CU. */
11825 gcc_assert (die->die_mark);
11827 if (die->die_tag == DW_TAG_subprogram)
11829 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11831 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11832 get_AT_low_pc (die), "Length");
11836 /* A static variable; extract the symbol from DW_AT_location.
11837 Note that this code isn't currently hit, as we only emit
11838 aranges for functions (jason 9/23/99). */
11839 dw_attr_ref a = get_AT (die, DW_AT_location);
11840 dw_loc_descr_ref loc;
11842 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11845 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11847 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11848 loc->dw_loc_oprnd1.v.val_addr, "Address");
11849 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11850 get_AT_unsigned (die, DW_AT_byte_size),
11855 /* Output the terminator words. */
11856 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11857 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11860 /* Add a new entry to .debug_ranges. Return the offset at which it
11863 static unsigned int
11864 add_ranges_num (int num)
11866 unsigned int in_use = ranges_table_in_use;
11868 if (in_use == ranges_table_allocated)
11870 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11871 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11872 ranges_table_allocated);
11873 memset (ranges_table + ranges_table_in_use, 0,
11874 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11877 ranges_table[in_use].num = num;
11878 ranges_table_in_use = in_use + 1;
11880 return in_use * 2 * DWARF2_ADDR_SIZE;
11883 /* Add a new entry to .debug_ranges corresponding to a block, or a
11884 range terminator if BLOCK is NULL. */
11886 static unsigned int
11887 add_ranges (const_tree block)
11889 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11892 /* Add a new entry to .debug_ranges corresponding to a pair of
11896 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11899 unsigned int in_use = ranges_by_label_in_use;
11900 unsigned int offset;
11902 if (in_use == ranges_by_label_allocated)
11904 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11905 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11907 ranges_by_label_allocated);
11908 memset (ranges_by_label + ranges_by_label_in_use, 0,
11909 RANGES_TABLE_INCREMENT
11910 * sizeof (struct dw_ranges_by_label_struct));
11913 ranges_by_label[in_use].begin = begin;
11914 ranges_by_label[in_use].end = end;
11915 ranges_by_label_in_use = in_use + 1;
11917 offset = add_ranges_num (-(int)in_use - 1);
11920 add_AT_range_list (die, DW_AT_ranges, offset);
11926 output_ranges (void)
11929 static const char *const start_fmt = "Offset %#x";
11930 const char *fmt = start_fmt;
11932 for (i = 0; i < ranges_table_in_use; i++)
11934 int block_num = ranges_table[i].num;
11938 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11939 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11941 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11942 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11944 /* If all code is in the text section, then the compilation
11945 unit base address defaults to DW_AT_low_pc, which is the
11946 base of the text section. */
11947 if (!have_multiple_function_sections)
11949 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11950 text_section_label,
11951 fmt, i * 2 * DWARF2_ADDR_SIZE);
11952 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11953 text_section_label, NULL);
11956 /* Otherwise, the compilation unit base address is zero,
11957 which allows us to use absolute addresses, and not worry
11958 about whether the target supports cross-section
11962 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11963 fmt, i * 2 * DWARF2_ADDR_SIZE);
11964 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11970 /* Negative block_num stands for an index into ranges_by_label. */
11971 else if (block_num < 0)
11973 int lab_idx = - block_num - 1;
11975 if (!have_multiple_function_sections)
11977 gcc_unreachable ();
11979 /* If we ever use add_ranges_by_labels () for a single
11980 function section, all we have to do is to take out
11981 the #if 0 above. */
11982 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11983 ranges_by_label[lab_idx].begin,
11984 text_section_label,
11985 fmt, i * 2 * DWARF2_ADDR_SIZE);
11986 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11987 ranges_by_label[lab_idx].end,
11988 text_section_label, NULL);
11993 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11994 ranges_by_label[lab_idx].begin,
11995 fmt, i * 2 * DWARF2_ADDR_SIZE);
11996 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11997 ranges_by_label[lab_idx].end,
12003 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12004 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12010 /* Data structure containing information about input files. */
12013 const char *path; /* Complete file name. */
12014 const char *fname; /* File name part. */
12015 int length; /* Length of entire string. */
12016 struct dwarf_file_data * file_idx; /* Index in input file table. */
12017 int dir_idx; /* Index in directory table. */
12020 /* Data structure containing information about directories with source
12024 const char *path; /* Path including directory name. */
12025 int length; /* Path length. */
12026 int prefix; /* Index of directory entry which is a prefix. */
12027 int count; /* Number of files in this directory. */
12028 int dir_idx; /* Index of directory used as base. */
12031 /* Callback function for file_info comparison. We sort by looking at
12032 the directories in the path. */
12035 file_info_cmp (const void *p1, const void *p2)
12037 const struct file_info *const s1 = (const struct file_info *) p1;
12038 const struct file_info *const s2 = (const struct file_info *) p2;
12039 const unsigned char *cp1;
12040 const unsigned char *cp2;
12042 /* Take care of file names without directories. We need to make sure that
12043 we return consistent values to qsort since some will get confused if
12044 we return the same value when identical operands are passed in opposite
12045 orders. So if neither has a directory, return 0 and otherwise return
12046 1 or -1 depending on which one has the directory. */
12047 if ((s1->path == s1->fname || s2->path == s2->fname))
12048 return (s2->path == s2->fname) - (s1->path == s1->fname);
12050 cp1 = (const unsigned char *) s1->path;
12051 cp2 = (const unsigned char *) s2->path;
12057 /* Reached the end of the first path? If so, handle like above. */
12058 if ((cp1 == (const unsigned char *) s1->fname)
12059 || (cp2 == (const unsigned char *) s2->fname))
12060 return ((cp2 == (const unsigned char *) s2->fname)
12061 - (cp1 == (const unsigned char *) s1->fname));
12063 /* Character of current path component the same? */
12064 else if (*cp1 != *cp2)
12065 return *cp1 - *cp2;
12069 struct file_name_acquire_data
12071 struct file_info *files;
12076 /* Traversal function for the hash table. */
12079 file_name_acquire (void ** slot, void *data)
12081 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12082 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12083 struct file_info *fi;
12086 gcc_assert (fnad->max_files >= d->emitted_number);
12088 if (! d->emitted_number)
12091 gcc_assert (fnad->max_files != fnad->used_files);
12093 fi = fnad->files + fnad->used_files++;
12095 /* Skip all leading "./". */
12097 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12100 /* Create a new array entry. */
12102 fi->length = strlen (f);
12105 /* Search for the file name part. */
12106 f = strrchr (f, DIR_SEPARATOR);
12107 #if defined (DIR_SEPARATOR_2)
12109 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12113 if (f == NULL || f < g)
12119 fi->fname = f == NULL ? fi->path : f + 1;
12123 /* Output the directory table and the file name table. We try to minimize
12124 the total amount of memory needed. A heuristic is used to avoid large
12125 slowdowns with many input files. */
12128 output_file_names (void)
12130 struct file_name_acquire_data fnad;
12132 struct file_info *files;
12133 struct dir_info *dirs;
12141 if (!last_emitted_file)
12143 dw2_asm_output_data (1, 0, "End directory table");
12144 dw2_asm_output_data (1, 0, "End file name table");
12148 numfiles = last_emitted_file->emitted_number;
12150 /* Allocate the various arrays we need. */
12151 files = XALLOCAVEC (struct file_info, numfiles);
12152 dirs = XALLOCAVEC (struct dir_info, numfiles);
12154 fnad.files = files;
12155 fnad.used_files = 0;
12156 fnad.max_files = numfiles;
12157 htab_traverse (file_table, file_name_acquire, &fnad);
12158 gcc_assert (fnad.used_files == fnad.max_files);
12160 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12162 /* Find all the different directories used. */
12163 dirs[0].path = files[0].path;
12164 dirs[0].length = files[0].fname - files[0].path;
12165 dirs[0].prefix = -1;
12167 dirs[0].dir_idx = 0;
12168 files[0].dir_idx = 0;
12171 for (i = 1; i < numfiles; i++)
12172 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12173 && memcmp (dirs[ndirs - 1].path, files[i].path,
12174 dirs[ndirs - 1].length) == 0)
12176 /* Same directory as last entry. */
12177 files[i].dir_idx = ndirs - 1;
12178 ++dirs[ndirs - 1].count;
12184 /* This is a new directory. */
12185 dirs[ndirs].path = files[i].path;
12186 dirs[ndirs].length = files[i].fname - files[i].path;
12187 dirs[ndirs].count = 1;
12188 dirs[ndirs].dir_idx = ndirs;
12189 files[i].dir_idx = ndirs;
12191 /* Search for a prefix. */
12192 dirs[ndirs].prefix = -1;
12193 for (j = 0; j < ndirs; j++)
12194 if (dirs[j].length < dirs[ndirs].length
12195 && dirs[j].length > 1
12196 && (dirs[ndirs].prefix == -1
12197 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12198 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12199 dirs[ndirs].prefix = j;
12204 /* Now to the actual work. We have to find a subset of the directories which
12205 allow expressing the file name using references to the directory table
12206 with the least amount of characters. We do not do an exhaustive search
12207 where we would have to check out every combination of every single
12208 possible prefix. Instead we use a heuristic which provides nearly optimal
12209 results in most cases and never is much off. */
12210 saved = XALLOCAVEC (int, ndirs);
12211 savehere = XALLOCAVEC (int, ndirs);
12213 memset (saved, '\0', ndirs * sizeof (saved[0]));
12214 for (i = 0; i < ndirs; i++)
12219 /* We can always save some space for the current directory. But this
12220 does not mean it will be enough to justify adding the directory. */
12221 savehere[i] = dirs[i].length;
12222 total = (savehere[i] - saved[i]) * dirs[i].count;
12224 for (j = i + 1; j < ndirs; j++)
12227 if (saved[j] < dirs[i].length)
12229 /* Determine whether the dirs[i] path is a prefix of the
12233 k = dirs[j].prefix;
12234 while (k != -1 && k != (int) i)
12235 k = dirs[k].prefix;
12239 /* Yes it is. We can possibly save some memory by
12240 writing the filenames in dirs[j] relative to
12242 savehere[j] = dirs[i].length;
12243 total += (savehere[j] - saved[j]) * dirs[j].count;
12248 /* Check whether we can save enough to justify adding the dirs[i]
12250 if (total > dirs[i].length + 1)
12252 /* It's worthwhile adding. */
12253 for (j = i; j < ndirs; j++)
12254 if (savehere[j] > 0)
12256 /* Remember how much we saved for this directory so far. */
12257 saved[j] = savehere[j];
12259 /* Remember the prefix directory. */
12260 dirs[j].dir_idx = i;
12265 /* Emit the directory name table. */
12266 idx_offset = dirs[0].length > 0 ? 1 : 0;
12267 for (i = 1 - idx_offset; i < ndirs; i++)
12268 dw2_asm_output_nstring (dirs[i].path,
12270 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12271 "Directory Entry: %#x", i + idx_offset);
12273 dw2_asm_output_data (1, 0, "End directory table");
12275 /* We have to emit them in the order of emitted_number since that's
12276 used in the debug info generation. To do this efficiently we
12277 generate a back-mapping of the indices first. */
12278 backmap = XALLOCAVEC (int, numfiles);
12279 for (i = 0; i < numfiles; i++)
12280 backmap[files[i].file_idx->emitted_number - 1] = i;
12282 /* Now write all the file names. */
12283 for (i = 0; i < numfiles; i++)
12285 int file_idx = backmap[i];
12286 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12288 #ifdef VMS_DEBUGGING_INFO
12289 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12291 /* Setting these fields can lead to debugger miscomparisons,
12292 but VMS Debug requires them to be set correctly. */
12297 int maxfilelen = strlen (files[file_idx].path)
12298 + dirs[dir_idx].length
12299 + MAX_VMS_VERSION_LEN + 1;
12300 char *filebuf = XALLOCAVEC (char, maxfilelen);
12302 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12303 snprintf (filebuf, maxfilelen, "%s;%d",
12304 files[file_idx].path + dirs[dir_idx].length, ver);
12306 dw2_asm_output_nstring
12307 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12309 /* Include directory index. */
12310 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12312 /* Modification time. */
12313 dw2_asm_output_data_uleb128
12314 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12318 /* File length in bytes. */
12319 dw2_asm_output_data_uleb128
12320 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12324 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12325 "File Entry: %#x", (unsigned) i + 1);
12327 /* Include directory index. */
12328 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12330 /* Modification time. */
12331 dw2_asm_output_data_uleb128 (0, NULL);
12333 /* File length in bytes. */
12334 dw2_asm_output_data_uleb128 (0, NULL);
12335 #endif /* VMS_DEBUGGING_INFO */
12338 dw2_asm_output_data (1, 0, "End file name table");
12342 /* Output the source line number correspondence information. This
12343 information goes into the .debug_line section. */
12346 output_line_info (void)
12348 char l1[20], l2[20], p1[20], p2[20];
12349 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12350 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12352 unsigned n_op_args;
12353 unsigned long lt_index;
12354 unsigned long current_line;
12357 unsigned long current_file;
12358 unsigned long function;
12359 int ver = dwarf_version;
12361 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12362 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12363 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12364 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12366 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12367 dw2_asm_output_data (4, 0xffffffff,
12368 "Initial length escape value indicating 64-bit DWARF extension");
12369 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12370 "Length of Source Line Info");
12371 ASM_OUTPUT_LABEL (asm_out_file, l1);
12373 dw2_asm_output_data (2, ver, "DWARF Version");
12374 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12375 ASM_OUTPUT_LABEL (asm_out_file, p1);
12377 /* Define the architecture-dependent minimum instruction length (in
12378 bytes). In this implementation of DWARF, this field is used for
12379 information purposes only. Since GCC generates assembly language,
12380 we have no a priori knowledge of how many instruction bytes are
12381 generated for each source line, and therefore can use only the
12382 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12383 commands. Accordingly, we fix this as `1', which is "correct
12384 enough" for all architectures, and don't let the target override. */
12385 dw2_asm_output_data (1, 1,
12386 "Minimum Instruction Length");
12389 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12390 "Maximum Operations Per Instruction");
12391 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12392 "Default is_stmt_start flag");
12393 dw2_asm_output_data (1, DWARF_LINE_BASE,
12394 "Line Base Value (Special Opcodes)");
12395 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12396 "Line Range Value (Special Opcodes)");
12397 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12398 "Special Opcode Base");
12400 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12404 case DW_LNS_advance_pc:
12405 case DW_LNS_advance_line:
12406 case DW_LNS_set_file:
12407 case DW_LNS_set_column:
12408 case DW_LNS_fixed_advance_pc:
12416 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12420 /* Write out the information about the files we use. */
12421 output_file_names ();
12422 ASM_OUTPUT_LABEL (asm_out_file, p2);
12424 /* We used to set the address register to the first location in the text
12425 section here, but that didn't accomplish anything since we already
12426 have a line note for the opening brace of the first function. */
12428 /* Generate the line number to PC correspondence table, encoded as
12429 a series of state machine operations. */
12433 if (cfun && in_cold_section_p)
12434 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12436 strcpy (prev_line_label, text_section_label);
12437 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12439 dw_line_info_ref line_info = &line_info_table[lt_index];
12442 /* Disable this optimization for now; GDB wants to see two line notes
12443 at the beginning of a function so it can find the end of the
12446 /* Don't emit anything for redundant notes. Just updating the
12447 address doesn't accomplish anything, because we already assume
12448 that anything after the last address is this line. */
12449 if (line_info->dw_line_num == current_line
12450 && line_info->dw_file_num == current_file)
12454 /* Emit debug info for the address of the current line.
12456 Unfortunately, we have little choice here currently, and must always
12457 use the most general form. GCC does not know the address delta
12458 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12459 attributes which will give an upper bound on the address range. We
12460 could perhaps use length attributes to determine when it is safe to
12461 use DW_LNS_fixed_advance_pc. */
12463 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12466 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12467 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12468 "DW_LNS_fixed_advance_pc");
12469 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12473 /* This can handle any delta. This takes
12474 4+DWARF2_ADDR_SIZE bytes. */
12475 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12476 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12477 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12478 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12481 strcpy (prev_line_label, line_label);
12483 /* Emit debug info for the source file of the current line, if
12484 different from the previous line. */
12485 if (line_info->dw_file_num != current_file)
12487 current_file = line_info->dw_file_num;
12488 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12489 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12492 /* Emit debug info for the current line number, choosing the encoding
12493 that uses the least amount of space. */
12494 if (line_info->dw_line_num != current_line)
12496 line_offset = line_info->dw_line_num - current_line;
12497 line_delta = line_offset - DWARF_LINE_BASE;
12498 current_line = line_info->dw_line_num;
12499 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12500 /* This can handle deltas from -10 to 234, using the current
12501 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12503 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12504 "line %lu", current_line);
12507 /* This can handle any delta. This takes at least 4 bytes,
12508 depending on the value being encoded. */
12509 dw2_asm_output_data (1, DW_LNS_advance_line,
12510 "advance to line %lu", current_line);
12511 dw2_asm_output_data_sleb128 (line_offset, NULL);
12512 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12516 /* We still need to start a new row, so output a copy insn. */
12517 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12520 /* Emit debug info for the address of the end of the function. */
12523 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12524 "DW_LNS_fixed_advance_pc");
12525 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12529 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12530 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12531 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12532 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12535 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12536 dw2_asm_output_data_uleb128 (1, NULL);
12537 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12542 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12544 dw_separate_line_info_ref line_info
12545 = &separate_line_info_table[lt_index];
12548 /* Don't emit anything for redundant notes. */
12549 if (line_info->dw_line_num == current_line
12550 && line_info->dw_file_num == current_file
12551 && line_info->function == function)
12555 /* Emit debug info for the address of the current line. If this is
12556 a new function, or the first line of a function, then we need
12557 to handle it differently. */
12558 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12560 if (function != line_info->function)
12562 function = line_info->function;
12564 /* Set the address register to the first line in the function. */
12565 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12566 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12567 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12568 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12572 /* ??? See the DW_LNS_advance_pc comment above. */
12575 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12576 "DW_LNS_fixed_advance_pc");
12577 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12581 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12582 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12583 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12584 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12588 strcpy (prev_line_label, line_label);
12590 /* Emit debug info for the source file of the current line, if
12591 different from the previous line. */
12592 if (line_info->dw_file_num != current_file)
12594 current_file = line_info->dw_file_num;
12595 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12596 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12599 /* Emit debug info for the current line number, choosing the encoding
12600 that uses the least amount of space. */
12601 if (line_info->dw_line_num != current_line)
12603 line_offset = line_info->dw_line_num - current_line;
12604 line_delta = line_offset - DWARF_LINE_BASE;
12605 current_line = line_info->dw_line_num;
12606 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12607 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12608 "line %lu", current_line);
12611 dw2_asm_output_data (1, DW_LNS_advance_line,
12612 "advance to line %lu", current_line);
12613 dw2_asm_output_data_sleb128 (line_offset, NULL);
12614 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12618 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12626 /* If we're done with a function, end its sequence. */
12627 if (lt_index == separate_line_info_table_in_use
12628 || separate_line_info_table[lt_index].function != function)
12633 /* Emit debug info for the address of the end of the function. */
12634 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12637 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12638 "DW_LNS_fixed_advance_pc");
12639 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12643 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12644 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12645 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12646 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12649 /* Output the marker for the end of this sequence. */
12650 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12651 dw2_asm_output_data_uleb128 (1, NULL);
12652 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12656 /* Output the marker for the end of the line number info. */
12657 ASM_OUTPUT_LABEL (asm_out_file, l2);
12660 /* Return the size of the .debug_dcall table for the compilation unit. */
12662 static unsigned long
12663 size_of_dcall_table (void)
12665 unsigned long size;
12668 tree last_poc_decl = NULL;
12670 /* Header: version + debug info section pointer + pointer size. */
12671 size = 2 + DWARF_OFFSET_SIZE + 1;
12673 /* Each entry: code label + DIE offset. */
12674 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12676 gcc_assert (p->targ_die != NULL);
12677 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12678 if (p->poc_decl != last_poc_decl)
12680 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12681 gcc_assert (poc_die);
12682 last_poc_decl = p->poc_decl;
12684 size += (DWARF_OFFSET_SIZE
12685 + size_of_uleb128 (poc_die->die_offset));
12687 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12693 /* Output the direct call table used to disambiguate PC values when
12694 identical function have been merged. */
12697 output_dcall_table (void)
12700 unsigned long dcall_length = size_of_dcall_table ();
12702 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12703 tree last_poc_decl = NULL;
12705 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12706 dw2_asm_output_data (4, 0xffffffff,
12707 "Initial length escape value indicating 64-bit DWARF extension");
12708 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12709 "Length of Direct Call Table");
12710 dw2_asm_output_data (2, 4, "Version number");
12711 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12712 debug_info_section,
12713 "Offset of Compilation Unit Info");
12714 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12716 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12718 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12719 if (p->poc_decl != last_poc_decl)
12721 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12722 last_poc_decl = p->poc_decl;
12725 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12726 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12727 "Caller DIE offset");
12730 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12731 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12732 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12733 "Callee DIE offset");
12737 /* Return the size of the .debug_vcall table for the compilation unit. */
12739 static unsigned long
12740 size_of_vcall_table (void)
12742 unsigned long size;
12746 /* Header: version + pointer size. */
12749 /* Each entry: code label + vtable slot index. */
12750 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12751 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12756 /* Output the virtual call table used to disambiguate PC values when
12757 identical function have been merged. */
12760 output_vcall_table (void)
12763 unsigned long vcall_length = size_of_vcall_table ();
12765 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12767 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12768 dw2_asm_output_data (4, 0xffffffff,
12769 "Initial length escape value indicating 64-bit DWARF extension");
12770 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12771 "Length of Virtual Call Table");
12772 dw2_asm_output_data (2, 4, "Version number");
12773 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12775 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12777 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12778 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12779 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12783 /* Given a pointer to a tree node for some base type, return a pointer to
12784 a DIE that describes the given type.
12786 This routine must only be called for GCC type nodes that correspond to
12787 Dwarf base (fundamental) types. */
12790 base_type_die (tree type)
12792 dw_die_ref base_type_result;
12793 enum dwarf_type encoding;
12795 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12798 /* If this is a subtype that should not be emitted as a subrange type,
12799 use the base type. See subrange_type_for_debug_p. */
12800 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12801 type = TREE_TYPE (type);
12803 switch (TREE_CODE (type))
12806 if ((dwarf_version >= 4 || !dwarf_strict)
12807 && TYPE_NAME (type)
12808 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12809 && DECL_IS_BUILTIN (TYPE_NAME (type))
12810 && DECL_NAME (TYPE_NAME (type)))
12812 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12813 if (strcmp (name, "char16_t") == 0
12814 || strcmp (name, "char32_t") == 0)
12816 encoding = DW_ATE_UTF;
12820 if (TYPE_STRING_FLAG (type))
12822 if (TYPE_UNSIGNED (type))
12823 encoding = DW_ATE_unsigned_char;
12825 encoding = DW_ATE_signed_char;
12827 else if (TYPE_UNSIGNED (type))
12828 encoding = DW_ATE_unsigned;
12830 encoding = DW_ATE_signed;
12834 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12836 if (dwarf_version >= 3 || !dwarf_strict)
12837 encoding = DW_ATE_decimal_float;
12839 encoding = DW_ATE_lo_user;
12842 encoding = DW_ATE_float;
12845 case FIXED_POINT_TYPE:
12846 if (!(dwarf_version >= 3 || !dwarf_strict))
12847 encoding = DW_ATE_lo_user;
12848 else if (TYPE_UNSIGNED (type))
12849 encoding = DW_ATE_unsigned_fixed;
12851 encoding = DW_ATE_signed_fixed;
12854 /* Dwarf2 doesn't know anything about complex ints, so use
12855 a user defined type for it. */
12857 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12858 encoding = DW_ATE_complex_float;
12860 encoding = DW_ATE_lo_user;
12864 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12865 encoding = DW_ATE_boolean;
12869 /* No other TREE_CODEs are Dwarf fundamental types. */
12870 gcc_unreachable ();
12873 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12875 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12876 int_size_in_bytes (type));
12877 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12879 return base_type_result;
12882 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12883 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12886 is_base_type (tree type)
12888 switch (TREE_CODE (type))
12894 case FIXED_POINT_TYPE:
12902 case QUAL_UNION_TYPE:
12903 case ENUMERAL_TYPE:
12904 case FUNCTION_TYPE:
12907 case REFERENCE_TYPE:
12915 gcc_unreachable ();
12921 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12922 node, return the size in bits for the type if it is a constant, or else
12923 return the alignment for the type if the type's size is not constant, or
12924 else return BITS_PER_WORD if the type actually turns out to be an
12925 ERROR_MARK node. */
12927 static inline unsigned HOST_WIDE_INT
12928 simple_type_size_in_bits (const_tree type)
12930 if (TREE_CODE (type) == ERROR_MARK)
12931 return BITS_PER_WORD;
12932 else if (TYPE_SIZE (type) == NULL_TREE)
12934 else if (host_integerp (TYPE_SIZE (type), 1))
12935 return tree_low_cst (TYPE_SIZE (type), 1);
12937 return TYPE_ALIGN (type);
12940 /* Similarly, but return a double_int instead of UHWI. */
12942 static inline double_int
12943 double_int_type_size_in_bits (const_tree type)
12945 if (TREE_CODE (type) == ERROR_MARK)
12946 return uhwi_to_double_int (BITS_PER_WORD);
12947 else if (TYPE_SIZE (type) == NULL_TREE)
12948 return double_int_zero;
12949 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12950 return tree_to_double_int (TYPE_SIZE (type));
12952 return uhwi_to_double_int (TYPE_ALIGN (type));
12955 /* Given a pointer to a tree node for a subrange type, return a pointer
12956 to a DIE that describes the given type. */
12959 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12961 dw_die_ref subrange_die;
12962 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12964 if (context_die == NULL)
12965 context_die = comp_unit_die ();
12967 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12969 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12971 /* The size of the subrange type and its base type do not match,
12972 so we need to generate a size attribute for the subrange type. */
12973 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12977 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12979 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12981 return subrange_die;
12984 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12985 entry that chains various modifiers in front of the given type. */
12988 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12989 dw_die_ref context_die)
12991 enum tree_code code = TREE_CODE (type);
12992 dw_die_ref mod_type_die;
12993 dw_die_ref sub_die = NULL;
12994 tree item_type = NULL;
12995 tree qualified_type;
12996 tree name, low, high;
12998 if (code == ERROR_MARK)
13001 /* See if we already have the appropriately qualified variant of
13004 = get_qualified_type (type,
13005 ((is_const_type ? TYPE_QUAL_CONST : 0)
13006 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
13008 if (qualified_type == sizetype
13009 && TYPE_NAME (qualified_type)
13010 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
13012 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
13014 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
13015 && TYPE_PRECISION (t)
13016 == TYPE_PRECISION (qualified_type)
13017 && TYPE_UNSIGNED (t)
13018 == TYPE_UNSIGNED (qualified_type));
13019 qualified_type = t;
13022 /* If we do, then we can just use its DIE, if it exists. */
13023 if (qualified_type)
13025 mod_type_die = lookup_type_die (qualified_type);
13027 return mod_type_die;
13030 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13032 /* Handle C typedef types. */
13033 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
13034 && !DECL_ARTIFICIAL (name))
13036 tree dtype = TREE_TYPE (name);
13038 if (qualified_type == dtype)
13040 /* For a named type, use the typedef. */
13041 gen_type_die (qualified_type, context_die);
13042 return lookup_type_die (qualified_type);
13044 else if (is_const_type < TYPE_READONLY (dtype)
13045 || is_volatile_type < TYPE_VOLATILE (dtype)
13046 || (is_const_type <= TYPE_READONLY (dtype)
13047 && is_volatile_type <= TYPE_VOLATILE (dtype)
13048 && DECL_ORIGINAL_TYPE (name) != type))
13049 /* cv-unqualified version of named type. Just use the unnamed
13050 type to which it refers. */
13051 return modified_type_die (DECL_ORIGINAL_TYPE (name),
13052 is_const_type, is_volatile_type,
13054 /* Else cv-qualified version of named type; fall through. */
13058 /* If both is_const_type and is_volatile_type, prefer the path
13059 which leads to a qualified type. */
13060 && (!is_volatile_type
13061 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
13062 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
13064 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
13065 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
13067 else if (is_volatile_type)
13069 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
13070 sub_die = modified_type_die (type, is_const_type, 0, context_die);
13072 else if (code == POINTER_TYPE)
13074 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
13075 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13076 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13077 item_type = TREE_TYPE (type);
13078 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13079 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13080 TYPE_ADDR_SPACE (item_type));
13082 else if (code == REFERENCE_TYPE)
13084 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
13085 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
13088 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
13089 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13090 simple_type_size_in_bits (type) / BITS_PER_UNIT);
13091 item_type = TREE_TYPE (type);
13092 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
13093 add_AT_unsigned (mod_type_die, DW_AT_address_class,
13094 TYPE_ADDR_SPACE (item_type));
13096 else if (code == INTEGER_TYPE
13097 && TREE_TYPE (type) != NULL_TREE
13098 && subrange_type_for_debug_p (type, &low, &high))
13100 mod_type_die = subrange_type_die (type, low, high, context_die);
13101 item_type = TREE_TYPE (type);
13103 else if (is_base_type (type))
13104 mod_type_die = base_type_die (type);
13107 gen_type_die (type, context_die);
13109 /* We have to get the type_main_variant here (and pass that to the
13110 `lookup_type_die' routine) because the ..._TYPE node we have
13111 might simply be a *copy* of some original type node (where the
13112 copy was created to help us keep track of typedef names) and
13113 that copy might have a different TYPE_UID from the original
13115 if (TREE_CODE (type) != VECTOR_TYPE)
13116 return lookup_type_die (type_main_variant (type));
13118 /* Vectors have the debugging information in the type,
13119 not the main variant. */
13120 return lookup_type_die (type);
13123 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
13124 don't output a DW_TAG_typedef, since there isn't one in the
13125 user's program; just attach a DW_AT_name to the type.
13126 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
13127 if the base type already has the same name. */
13129 && ((TREE_CODE (name) != TYPE_DECL
13130 && (qualified_type == TYPE_MAIN_VARIANT (type)
13131 || (!is_const_type && !is_volatile_type)))
13132 || (TREE_CODE (name) == TYPE_DECL
13133 && TREE_TYPE (name) == qualified_type
13134 && DECL_NAME (name))))
13136 if (TREE_CODE (name) == TYPE_DECL)
13137 /* Could just call add_name_and_src_coords_attributes here,
13138 but since this is a builtin type it doesn't have any
13139 useful source coordinates anyway. */
13140 name = DECL_NAME (name);
13141 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
13143 /* This probably indicates a bug. */
13144 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
13145 add_name_attribute (mod_type_die, "__unknown__");
13147 if (qualified_type)
13148 equate_type_number_to_die (qualified_type, mod_type_die);
13151 /* We must do this after the equate_type_number_to_die call, in case
13152 this is a recursive type. This ensures that the modified_type_die
13153 recursion will terminate even if the type is recursive. Recursive
13154 types are possible in Ada. */
13155 sub_die = modified_type_die (item_type,
13156 TYPE_READONLY (item_type),
13157 TYPE_VOLATILE (item_type),
13160 if (sub_die != NULL)
13161 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13163 return mod_type_die;
13166 /* Generate DIEs for the generic parameters of T.
13167 T must be either a generic type or a generic function.
13168 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13171 gen_generic_params_dies (tree t)
13175 dw_die_ref die = NULL;
13177 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13181 die = lookup_type_die (t);
13182 else if (DECL_P (t))
13183 die = lookup_decl_die (t);
13187 parms = lang_hooks.get_innermost_generic_parms (t);
13189 /* T has no generic parameter. It means T is neither a generic type
13190 or function. End of story. */
13193 parms_num = TREE_VEC_LENGTH (parms);
13194 args = lang_hooks.get_innermost_generic_args (t);
13195 for (i = 0; i < parms_num; i++)
13197 tree parm, arg, arg_pack_elems;
13199 parm = TREE_VEC_ELT (parms, i);
13200 arg = TREE_VEC_ELT (args, i);
13201 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13202 gcc_assert (parm && TREE_VALUE (parm) && arg);
13204 if (parm && TREE_VALUE (parm) && arg)
13206 /* If PARM represents a template parameter pack,
13207 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13208 by DW_TAG_template_*_parameter DIEs for the argument
13209 pack elements of ARG. Note that ARG would then be
13210 an argument pack. */
13211 if (arg_pack_elems)
13212 template_parameter_pack_die (TREE_VALUE (parm),
13216 generic_parameter_die (TREE_VALUE (parm), arg,
13217 true /* Emit DW_AT_name */, die);
13222 /* Create and return a DIE for PARM which should be
13223 the representation of a generic type parameter.
13224 For instance, in the C++ front end, PARM would be a template parameter.
13225 ARG is the argument to PARM.
13226 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13228 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13229 as a child node. */
13232 generic_parameter_die (tree parm, tree arg,
13234 dw_die_ref parent_die)
13236 dw_die_ref tmpl_die = NULL;
13237 const char *name = NULL;
13239 if (!parm || !DECL_NAME (parm) || !arg)
13242 /* We support non-type generic parameters and arguments,
13243 type generic parameters and arguments, as well as
13244 generic generic parameters (a.k.a. template template parameters in C++)
13246 if (TREE_CODE (parm) == PARM_DECL)
13247 /* PARM is a nontype generic parameter */
13248 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13249 else if (TREE_CODE (parm) == TYPE_DECL)
13250 /* PARM is a type generic parameter. */
13251 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13252 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13253 /* PARM is a generic generic parameter.
13254 Its DIE is a GNU extension. It shall have a
13255 DW_AT_name attribute to represent the name of the template template
13256 parameter, and a DW_AT_GNU_template_name attribute to represent the
13257 name of the template template argument. */
13258 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13261 gcc_unreachable ();
13267 /* If PARM is a generic parameter pack, it means we are
13268 emitting debug info for a template argument pack element.
13269 In other terms, ARG is a template argument pack element.
13270 In that case, we don't emit any DW_AT_name attribute for
13274 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13276 add_AT_string (tmpl_die, DW_AT_name, name);
13279 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13281 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13282 TMPL_DIE should have a child DW_AT_type attribute that is set
13283 to the type of the argument to PARM, which is ARG.
13284 If PARM is a type generic parameter, TMPL_DIE should have a
13285 child DW_AT_type that is set to ARG. */
13286 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13287 add_type_attribute (tmpl_die, tmpl_type, 0,
13288 TREE_THIS_VOLATILE (tmpl_type),
13293 /* So TMPL_DIE is a DIE representing a
13294 a generic generic template parameter, a.k.a template template
13295 parameter in C++ and arg is a template. */
13297 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13298 to the name of the argument. */
13299 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13301 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13304 if (TREE_CODE (parm) == PARM_DECL)
13305 /* So PARM is a non-type generic parameter.
13306 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13307 attribute of TMPL_DIE which value represents the value
13309 We must be careful here:
13310 The value of ARG might reference some function decls.
13311 We might currently be emitting debug info for a generic
13312 type and types are emitted before function decls, we don't
13313 know if the function decls referenced by ARG will actually be
13314 emitted after cgraph computations.
13315 So must defer the generation of the DW_AT_const_value to
13316 after cgraph is ready. */
13317 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13323 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13324 PARM_PACK must be a template parameter pack. The returned DIE
13325 will be child DIE of PARENT_DIE. */
13328 template_parameter_pack_die (tree parm_pack,
13329 tree parm_pack_args,
13330 dw_die_ref parent_die)
13335 gcc_assert (parent_die && parm_pack);
13337 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13338 add_name_and_src_coords_attributes (die, parm_pack);
13339 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13340 generic_parameter_die (parm_pack,
13341 TREE_VEC_ELT (parm_pack_args, j),
13342 false /* Don't emit DW_AT_name */,
13347 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13348 an enumerated type. */
13351 type_is_enum (const_tree type)
13353 return TREE_CODE (type) == ENUMERAL_TYPE;
13356 /* Return the DBX register number described by a given RTL node. */
13358 static unsigned int
13359 dbx_reg_number (const_rtx rtl)
13361 unsigned regno = REGNO (rtl);
13363 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13365 #ifdef LEAF_REG_REMAP
13366 if (current_function_uses_only_leaf_regs)
13368 int leaf_reg = LEAF_REG_REMAP (regno);
13369 if (leaf_reg != -1)
13370 regno = (unsigned) leaf_reg;
13374 return DBX_REGISTER_NUMBER (regno);
13377 /* Optionally add a DW_OP_piece term to a location description expression.
13378 DW_OP_piece is only added if the location description expression already
13379 doesn't end with DW_OP_piece. */
13382 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13384 dw_loc_descr_ref loc;
13386 if (*list_head != NULL)
13388 /* Find the end of the chain. */
13389 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13392 if (loc->dw_loc_opc != DW_OP_piece)
13393 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13397 /* Return a location descriptor that designates a machine register or
13398 zero if there is none. */
13400 static dw_loc_descr_ref
13401 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13405 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13408 /* We only use "frame base" when we're sure we're talking about the
13409 post-prologue local stack frame. We do this by *not* running
13410 register elimination until this point, and recognizing the special
13411 argument pointer and soft frame pointer rtx's.
13412 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13413 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13414 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13416 dw_loc_descr_ref result = NULL;
13418 if (dwarf_version >= 4 || !dwarf_strict)
13420 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13422 add_loc_descr (&result,
13423 new_loc_descr (DW_OP_stack_value, 0, 0));
13428 regs = targetm.dwarf_register_span (rtl);
13430 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13431 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13433 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13436 /* Return a location descriptor that designates a machine register for
13437 a given hard register number. */
13439 static dw_loc_descr_ref
13440 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13442 dw_loc_descr_ref reg_loc_descr;
13446 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13448 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13450 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13451 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13453 return reg_loc_descr;
13456 /* Given an RTL of a register, return a location descriptor that
13457 designates a value that spans more than one register. */
13459 static dw_loc_descr_ref
13460 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13461 enum var_init_status initialized)
13463 int nregs, size, i;
13465 dw_loc_descr_ref loc_result = NULL;
13468 #ifdef LEAF_REG_REMAP
13469 if (current_function_uses_only_leaf_regs)
13471 int leaf_reg = LEAF_REG_REMAP (reg);
13472 if (leaf_reg != -1)
13473 reg = (unsigned) leaf_reg;
13476 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13477 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13479 /* Simple, contiguous registers. */
13480 if (regs == NULL_RTX)
13482 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13487 dw_loc_descr_ref t;
13489 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13490 VAR_INIT_STATUS_INITIALIZED);
13491 add_loc_descr (&loc_result, t);
13492 add_loc_descr_op_piece (&loc_result, size);
13498 /* Now onto stupid register sets in non contiguous locations. */
13500 gcc_assert (GET_CODE (regs) == PARALLEL);
13502 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13505 for (i = 0; i < XVECLEN (regs, 0); ++i)
13507 dw_loc_descr_ref t;
13509 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13510 VAR_INIT_STATUS_INITIALIZED);
13511 add_loc_descr (&loc_result, t);
13512 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13513 add_loc_descr_op_piece (&loc_result, size);
13516 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13517 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13521 /* Return a location descriptor that designates a constant. */
13523 static dw_loc_descr_ref
13524 int_loc_descriptor (HOST_WIDE_INT i)
13526 enum dwarf_location_atom op;
13528 /* Pick the smallest representation of a constant, rather than just
13529 defaulting to the LEB encoding. */
13533 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13534 else if (i <= 0xff)
13535 op = DW_OP_const1u;
13536 else if (i <= 0xffff)
13537 op = DW_OP_const2u;
13538 else if (HOST_BITS_PER_WIDE_INT == 32
13539 || i <= 0xffffffff)
13540 op = DW_OP_const4u;
13547 op = DW_OP_const1s;
13548 else if (i >= -0x8000)
13549 op = DW_OP_const2s;
13550 else if (HOST_BITS_PER_WIDE_INT == 32
13551 || i >= -0x80000000)
13552 op = DW_OP_const4s;
13557 return new_loc_descr (op, i, 0);
13560 /* Return loc description representing "address" of integer value.
13561 This can appear only as toplevel expression. */
13563 static dw_loc_descr_ref
13564 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13567 dw_loc_descr_ref loc_result = NULL;
13569 if (!(dwarf_version >= 4 || !dwarf_strict))
13576 else if (i <= 0xff)
13578 else if (i <= 0xffff)
13580 else if (HOST_BITS_PER_WIDE_INT == 32
13581 || i <= 0xffffffff)
13584 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13590 else if (i >= -0x8000)
13592 else if (HOST_BITS_PER_WIDE_INT == 32
13593 || i >= -0x80000000)
13596 litsize = 1 + size_of_sleb128 (i);
13598 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13599 is more compact. For DW_OP_stack_value we need:
13600 litsize + 1 (DW_OP_stack_value)
13601 and for DW_OP_implicit_value:
13602 1 (DW_OP_implicit_value) + 1 (length) + size. */
13603 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13605 loc_result = int_loc_descriptor (i);
13606 add_loc_descr (&loc_result,
13607 new_loc_descr (DW_OP_stack_value, 0, 0));
13611 loc_result = new_loc_descr (DW_OP_implicit_value,
13613 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13614 loc_result->dw_loc_oprnd2.v.val_int = i;
13618 /* Return a location descriptor that designates a base+offset location. */
13620 static dw_loc_descr_ref
13621 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13622 enum var_init_status initialized)
13624 unsigned int regno;
13625 dw_loc_descr_ref result;
13626 dw_fde_ref fde = current_fde ();
13628 /* We only use "frame base" when we're sure we're talking about the
13629 post-prologue local stack frame. We do this by *not* running
13630 register elimination until this point, and recognizing the special
13631 argument pointer and soft frame pointer rtx's. */
13632 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13634 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13638 if (GET_CODE (elim) == PLUS)
13640 offset += INTVAL (XEXP (elim, 1));
13641 elim = XEXP (elim, 0);
13643 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13644 && (elim == hard_frame_pointer_rtx
13645 || elim == stack_pointer_rtx))
13646 || elim == (frame_pointer_needed
13647 ? hard_frame_pointer_rtx
13648 : stack_pointer_rtx));
13650 /* If drap register is used to align stack, use frame
13651 pointer + offset to access stack variables. If stack
13652 is aligned without drap, use stack pointer + offset to
13653 access stack variables. */
13654 if (crtl->stack_realign_tried
13655 && reg == frame_pointer_rtx)
13658 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13659 ? HARD_FRAME_POINTER_REGNUM
13660 : STACK_POINTER_REGNUM);
13661 return new_reg_loc_descr (base_reg, offset);
13664 offset += frame_pointer_fb_offset;
13665 return new_loc_descr (DW_OP_fbreg, offset, 0);
13670 && (fde->drap_reg == REGNO (reg)
13671 || fde->vdrap_reg == REGNO (reg)))
13673 /* Use cfa+offset to represent the location of arguments passed
13674 on the stack when drap is used to align stack.
13675 Only do this when not optimizing, for optimized code var-tracking
13676 is supposed to track where the arguments live and the register
13677 used as vdrap or drap in some spot might be used for something
13678 else in other part of the routine. */
13679 return new_loc_descr (DW_OP_fbreg, offset, 0);
13682 regno = dbx_reg_number (reg);
13684 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13687 result = new_loc_descr (DW_OP_bregx, regno, offset);
13689 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13690 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13695 /* Return true if this RTL expression describes a base+offset calculation. */
13698 is_based_loc (const_rtx rtl)
13700 return (GET_CODE (rtl) == PLUS
13701 && ((REG_P (XEXP (rtl, 0))
13702 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13703 && CONST_INT_P (XEXP (rtl, 1)))));
13706 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13709 static dw_loc_descr_ref
13710 tls_mem_loc_descriptor (rtx mem)
13713 dw_loc_descr_ref loc_result;
13715 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13718 base = get_base_address (MEM_EXPR (mem));
13720 || TREE_CODE (base) != VAR_DECL
13721 || !DECL_THREAD_LOCAL_P (base))
13724 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13725 if (loc_result == NULL)
13728 if (INTVAL (MEM_OFFSET (mem)))
13729 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13734 /* Output debug info about reason why we failed to expand expression as dwarf
13738 expansion_failed (tree expr, rtx rtl, char const *reason)
13740 if (dump_file && (dump_flags & TDF_DETAILS))
13742 fprintf (dump_file, "Failed to expand as dwarf: ");
13744 print_generic_expr (dump_file, expr, dump_flags);
13747 fprintf (dump_file, "\n");
13748 print_rtl (dump_file, rtl);
13750 fprintf (dump_file, "\nReason: %s\n", reason);
13754 /* Helper function for const_ok_for_output, called either directly
13755 or via for_each_rtx. */
13758 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13762 if (GET_CODE (rtl) == UNSPEC)
13764 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13765 we can't express it in the debug info. */
13766 #ifdef ENABLE_CHECKING
13767 /* Don't complain about TLS UNSPECs, those are just too hard to
13769 if (XVECLEN (rtl, 0) != 1
13770 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13771 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13772 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13773 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13774 inform (current_function_decl
13775 ? DECL_SOURCE_LOCATION (current_function_decl)
13776 : UNKNOWN_LOCATION,
13777 "non-delegitimized UNSPEC %d found in variable location",
13780 expansion_failed (NULL_TREE, rtl,
13781 "UNSPEC hasn't been delegitimized.\n");
13785 if (GET_CODE (rtl) != SYMBOL_REF)
13788 if (CONSTANT_POOL_ADDRESS_P (rtl))
13791 get_pool_constant_mark (rtl, &marked);
13792 /* If all references to this pool constant were optimized away,
13793 it was not output and thus we can't represent it. */
13796 expansion_failed (NULL_TREE, rtl,
13797 "Constant was removed from constant pool.\n");
13802 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13805 /* Avoid references to external symbols in debug info, on several targets
13806 the linker might even refuse to link when linking a shared library,
13807 and in many other cases the relocations for .debug_info/.debug_loc are
13808 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13809 to be defined within the same shared library or executable are fine. */
13810 if (SYMBOL_REF_EXTERNAL_P (rtl))
13812 tree decl = SYMBOL_REF_DECL (rtl);
13814 if (decl == NULL || !targetm.binds_local_p (decl))
13816 expansion_failed (NULL_TREE, rtl,
13817 "Symbol not defined in current TU.\n");
13825 /* Return true if constant RTL can be emitted in DW_OP_addr or
13826 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13827 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13830 const_ok_for_output (rtx rtl)
13832 if (GET_CODE (rtl) == SYMBOL_REF)
13833 return const_ok_for_output_1 (&rtl, NULL) == 0;
13835 if (GET_CODE (rtl) == CONST)
13836 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13841 /* The following routine converts the RTL for a variable or parameter
13842 (resident in memory) into an equivalent Dwarf representation of a
13843 mechanism for getting the address of that same variable onto the top of a
13844 hypothetical "address evaluation" stack.
13846 When creating memory location descriptors, we are effectively transforming
13847 the RTL for a memory-resident object into its Dwarf postfix expression
13848 equivalent. This routine recursively descends an RTL tree, turning
13849 it into Dwarf postfix code as it goes.
13851 MODE is the mode of the memory reference, needed to handle some
13852 autoincrement addressing modes.
13854 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13855 location list for RTL.
13857 Return 0 if we can't represent the location. */
13859 static dw_loc_descr_ref
13860 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13861 enum var_init_status initialized)
13863 dw_loc_descr_ref mem_loc_result = NULL;
13864 enum dwarf_location_atom op;
13865 dw_loc_descr_ref op0, op1;
13867 /* Note that for a dynamically sized array, the location we will generate a
13868 description of here will be the lowest numbered location which is
13869 actually within the array. That's *not* necessarily the same as the
13870 zeroth element of the array. */
13872 rtl = targetm.delegitimize_address (rtl);
13874 switch (GET_CODE (rtl))
13879 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13882 /* The case of a subreg may arise when we have a local (register)
13883 variable or a formal (register) parameter which doesn't quite fill
13884 up an entire register. For now, just assume that it is
13885 legitimate to make the Dwarf info refer to the whole register which
13886 contains the given subreg. */
13887 if (!subreg_lowpart_p (rtl))
13889 rtl = SUBREG_REG (rtl);
13890 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13892 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13894 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13898 /* Whenever a register number forms a part of the description of the
13899 method for calculating the (dynamic) address of a memory resident
13900 object, DWARF rules require the register number be referred to as
13901 a "base register". This distinction is not based in any way upon
13902 what category of register the hardware believes the given register
13903 belongs to. This is strictly DWARF terminology we're dealing with
13904 here. Note that in cases where the location of a memory-resident
13905 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13906 OP_CONST (0)) the actual DWARF location descriptor that we generate
13907 may just be OP_BASEREG (basereg). This may look deceptively like
13908 the object in question was allocated to a register (rather than in
13909 memory) so DWARF consumers need to be aware of the subtle
13910 distinction between OP_REG and OP_BASEREG. */
13911 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13912 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13913 else if (stack_realign_drap
13915 && crtl->args.internal_arg_pointer == rtl
13916 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13918 /* If RTL is internal_arg_pointer, which has been optimized
13919 out, use DRAP instead. */
13920 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13921 VAR_INIT_STATUS_INITIALIZED);
13927 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13928 VAR_INIT_STATUS_INITIALIZED);
13933 int shift = DWARF2_ADDR_SIZE
13934 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13935 shift *= BITS_PER_UNIT;
13936 if (GET_CODE (rtl) == SIGN_EXTEND)
13940 mem_loc_result = op0;
13941 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13942 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13943 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13944 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13949 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13950 VAR_INIT_STATUS_INITIALIZED);
13951 if (mem_loc_result == NULL)
13952 mem_loc_result = tls_mem_loc_descriptor (rtl);
13953 if (mem_loc_result != 0)
13955 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13957 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13960 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13961 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13963 add_loc_descr (&mem_loc_result,
13964 new_loc_descr (DW_OP_deref_size,
13965 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13969 rtx new_rtl = avoid_constant_pool_reference (rtl);
13970 if (new_rtl != rtl)
13971 return mem_loc_descriptor (new_rtl, mode, initialized);
13976 rtl = XEXP (rtl, 1);
13978 /* ... fall through ... */
13981 /* Some ports can transform a symbol ref into a label ref, because
13982 the symbol ref is too far away and has to be dumped into a constant
13986 if (GET_CODE (rtl) == SYMBOL_REF
13987 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13989 dw_loc_descr_ref temp;
13991 /* If this is not defined, we have no way to emit the data. */
13992 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13995 /* We used to emit DW_OP_addr here, but that's wrong, since
13996 DW_OP_addr should be relocated by the debug info consumer,
13997 while DW_OP_GNU_push_tls_address operand should not. */
13998 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13999 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
14000 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
14001 temp->dw_loc_oprnd1.v.val_addr = rtl;
14002 temp->dtprel = true;
14004 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
14005 add_loc_descr (&mem_loc_result, temp);
14010 if (!const_ok_for_output (rtl))
14014 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14015 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14016 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14017 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14023 case DEBUG_IMPLICIT_PTR:
14024 expansion_failed (NULL_TREE, rtl,
14025 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
14029 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
14030 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
14031 if (REG_P (XEXP (rtl, 0)))
14032 mem_loc_result->dw_loc_oprnd1.v.val_loc
14033 = one_reg_loc_descriptor (dbx_reg_number (XEXP (rtl, 0)),
14034 VAR_INIT_STATUS_INITIALIZED);
14035 else if (MEM_P (XEXP (rtl, 0)) && REG_P (XEXP (XEXP (rtl, 0), 0)))
14037 dw_loc_descr_ref ref
14038 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14039 VAR_INIT_STATUS_INITIALIZED);
14042 mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
14045 gcc_unreachable ();
14046 return mem_loc_result;
14049 /* Extract the PLUS expression nested inside and fall into
14050 PLUS code below. */
14051 rtl = XEXP (rtl, 1);
14056 /* Turn these into a PLUS expression and fall into the PLUS code
14058 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
14059 GEN_INT (GET_CODE (rtl) == PRE_INC
14060 ? GET_MODE_UNIT_SIZE (mode)
14061 : -GET_MODE_UNIT_SIZE (mode)));
14063 /* ... fall through ... */
14067 if (is_based_loc (rtl))
14068 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
14069 INTVAL (XEXP (rtl, 1)),
14070 VAR_INIT_STATUS_INITIALIZED);
14073 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
14074 VAR_INIT_STATUS_INITIALIZED);
14075 if (mem_loc_result == 0)
14078 if (CONST_INT_P (XEXP (rtl, 1)))
14079 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
14082 dw_loc_descr_ref mem_loc_result2
14083 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14084 VAR_INIT_STATUS_INITIALIZED);
14085 if (mem_loc_result2 == 0)
14087 add_loc_descr (&mem_loc_result, mem_loc_result2);
14088 add_loc_descr (&mem_loc_result,
14089 new_loc_descr (DW_OP_plus, 0, 0));
14094 /* If a pseudo-reg is optimized away, it is possible for it to
14095 be replaced with a MEM containing a multiply or shift. */
14137 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14138 VAR_INIT_STATUS_INITIALIZED);
14139 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14140 VAR_INIT_STATUS_INITIALIZED);
14142 if (op0 == 0 || op1 == 0)
14145 mem_loc_result = op0;
14146 add_loc_descr (&mem_loc_result, op1);
14147 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14151 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14152 VAR_INIT_STATUS_INITIALIZED);
14153 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14154 VAR_INIT_STATUS_INITIALIZED);
14156 if (op0 == 0 || op1 == 0)
14159 mem_loc_result = op0;
14160 add_loc_descr (&mem_loc_result, op1);
14161 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14162 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
14163 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
14164 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14165 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14181 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14182 VAR_INIT_STATUS_INITIALIZED);
14187 mem_loc_result = op0;
14188 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14192 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14220 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14221 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14225 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14227 if (op_mode == VOIDmode)
14228 op_mode = GET_MODE (XEXP (rtl, 1));
14229 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14232 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14233 VAR_INIT_STATUS_INITIALIZED);
14234 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14235 VAR_INIT_STATUS_INITIALIZED);
14237 if (op0 == 0 || op1 == 0)
14240 if (op_mode != VOIDmode
14241 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14243 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14244 shift *= BITS_PER_UNIT;
14245 /* For eq/ne, if the operands are known to be zero-extended,
14246 there is no need to do the fancy shifting up. */
14247 if (op == DW_OP_eq || op == DW_OP_ne)
14249 dw_loc_descr_ref last0, last1;
14251 last0->dw_loc_next != NULL;
14252 last0 = last0->dw_loc_next)
14255 last1->dw_loc_next != NULL;
14256 last1 = last1->dw_loc_next)
14258 /* deref_size zero extends, and for constants we can check
14259 whether they are zero extended or not. */
14260 if (((last0->dw_loc_opc == DW_OP_deref_size
14261 && last0->dw_loc_oprnd1.v.val_int
14262 <= GET_MODE_SIZE (op_mode))
14263 || (CONST_INT_P (XEXP (rtl, 0))
14264 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14265 == (INTVAL (XEXP (rtl, 0))
14266 & GET_MODE_MASK (op_mode))))
14267 && ((last1->dw_loc_opc == DW_OP_deref_size
14268 && last1->dw_loc_oprnd1.v.val_int
14269 <= GET_MODE_SIZE (op_mode))
14270 || (CONST_INT_P (XEXP (rtl, 1))
14271 && (unsigned HOST_WIDE_INT)
14272 INTVAL (XEXP (rtl, 1))
14273 == (INTVAL (XEXP (rtl, 1))
14274 & GET_MODE_MASK (op_mode)))))
14277 add_loc_descr (&op0, int_loc_descriptor (shift));
14278 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14279 if (CONST_INT_P (XEXP (rtl, 1)))
14280 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14283 add_loc_descr (&op1, int_loc_descriptor (shift));
14284 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14290 mem_loc_result = op0;
14291 add_loc_descr (&mem_loc_result, op1);
14292 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14293 if (STORE_FLAG_VALUE != 1)
14295 add_loc_descr (&mem_loc_result,
14296 int_loc_descriptor (STORE_FLAG_VALUE));
14297 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14318 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14319 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14323 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14325 if (op_mode == VOIDmode)
14326 op_mode = GET_MODE (XEXP (rtl, 1));
14327 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14330 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14331 VAR_INIT_STATUS_INITIALIZED);
14332 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14333 VAR_INIT_STATUS_INITIALIZED);
14335 if (op0 == 0 || op1 == 0)
14338 if (op_mode != VOIDmode
14339 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14341 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14342 dw_loc_descr_ref last0, last1;
14344 last0->dw_loc_next != NULL;
14345 last0 = last0->dw_loc_next)
14348 last1->dw_loc_next != NULL;
14349 last1 = last1->dw_loc_next)
14351 if (CONST_INT_P (XEXP (rtl, 0)))
14352 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14353 /* deref_size zero extends, so no need to mask it again. */
14354 else if (last0->dw_loc_opc != DW_OP_deref_size
14355 || last0->dw_loc_oprnd1.v.val_int
14356 > GET_MODE_SIZE (op_mode))
14358 add_loc_descr (&op0, int_loc_descriptor (mask));
14359 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14361 if (CONST_INT_P (XEXP (rtl, 1)))
14362 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14363 /* deref_size zero extends, so no need to mask it again. */
14364 else if (last1->dw_loc_opc != DW_OP_deref_size
14365 || last1->dw_loc_oprnd1.v.val_int
14366 > GET_MODE_SIZE (op_mode))
14368 add_loc_descr (&op1, int_loc_descriptor (mask));
14369 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14374 HOST_WIDE_INT bias = 1;
14375 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14376 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14377 if (CONST_INT_P (XEXP (rtl, 1)))
14378 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14379 + INTVAL (XEXP (rtl, 1)));
14381 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14391 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14392 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14393 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14396 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14397 VAR_INIT_STATUS_INITIALIZED);
14398 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14399 VAR_INIT_STATUS_INITIALIZED);
14401 if (op0 == 0 || op1 == 0)
14404 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14405 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14406 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14407 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14409 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14411 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14412 add_loc_descr (&op0, int_loc_descriptor (mask));
14413 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14414 add_loc_descr (&op1, int_loc_descriptor (mask));
14415 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14419 HOST_WIDE_INT bias = 1;
14420 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14421 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14422 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14425 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14427 int shift = DWARF2_ADDR_SIZE
14428 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14429 shift *= BITS_PER_UNIT;
14430 add_loc_descr (&op0, int_loc_descriptor (shift));
14431 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14432 add_loc_descr (&op1, int_loc_descriptor (shift));
14433 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14436 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14440 mem_loc_result = op0;
14441 add_loc_descr (&mem_loc_result, op1);
14442 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14444 dw_loc_descr_ref bra_node, drop_node;
14446 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14447 add_loc_descr (&mem_loc_result, bra_node);
14448 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14449 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14450 add_loc_descr (&mem_loc_result, drop_node);
14451 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14452 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14458 if (CONST_INT_P (XEXP (rtl, 1))
14459 && CONST_INT_P (XEXP (rtl, 2))
14460 && ((unsigned) INTVAL (XEXP (rtl, 1))
14461 + (unsigned) INTVAL (XEXP (rtl, 2))
14462 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14463 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14464 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14467 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14468 VAR_INIT_STATUS_INITIALIZED);
14471 if (GET_CODE (rtl) == SIGN_EXTRACT)
14475 mem_loc_result = op0;
14476 size = INTVAL (XEXP (rtl, 1));
14477 shift = INTVAL (XEXP (rtl, 2));
14478 if (BITS_BIG_ENDIAN)
14479 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14481 if (shift + size != (int) DWARF2_ADDR_SIZE)
14483 add_loc_descr (&mem_loc_result,
14484 int_loc_descriptor (DWARF2_ADDR_SIZE
14486 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14488 if (size != (int) DWARF2_ADDR_SIZE)
14490 add_loc_descr (&mem_loc_result,
14491 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14492 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14499 dw_loc_descr_ref op2, bra_node, drop_node;
14500 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14501 VAR_INIT_STATUS_INITIALIZED);
14502 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14503 VAR_INIT_STATUS_INITIALIZED);
14504 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14505 VAR_INIT_STATUS_INITIALIZED);
14506 if (op0 == NULL || op1 == NULL || op2 == NULL)
14509 mem_loc_result = op1;
14510 add_loc_descr (&mem_loc_result, op2);
14511 add_loc_descr (&mem_loc_result, op0);
14512 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14513 add_loc_descr (&mem_loc_result, bra_node);
14514 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14515 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14516 add_loc_descr (&mem_loc_result, drop_node);
14517 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14518 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14526 /* In theory, we could implement the above. */
14527 /* DWARF cannot represent the unsigned compare operations
14554 case FLOAT_TRUNCATE:
14556 case UNSIGNED_FLOAT:
14559 case FRACT_CONVERT:
14560 case UNSIGNED_FRACT_CONVERT:
14562 case UNSIGNED_SAT_FRACT:
14574 case VEC_DUPLICATE:
14577 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14578 can't express it in the debug info. This can happen e.g. with some
14583 resolve_one_addr (&rtl, NULL);
14587 #ifdef ENABLE_CHECKING
14588 print_rtl (stderr, rtl);
14589 gcc_unreachable ();
14595 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14596 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14598 return mem_loc_result;
14601 /* Return a descriptor that describes the concatenation of two locations.
14602 This is typically a complex variable. */
14604 static dw_loc_descr_ref
14605 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14607 dw_loc_descr_ref cc_loc_result = NULL;
14608 dw_loc_descr_ref x0_ref
14609 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14610 dw_loc_descr_ref x1_ref
14611 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14613 if (x0_ref == 0 || x1_ref == 0)
14616 cc_loc_result = x0_ref;
14617 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14619 add_loc_descr (&cc_loc_result, x1_ref);
14620 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14622 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14623 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14625 return cc_loc_result;
14628 /* Return a descriptor that describes the concatenation of N
14631 static dw_loc_descr_ref
14632 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14635 dw_loc_descr_ref cc_loc_result = NULL;
14636 unsigned int n = XVECLEN (concatn, 0);
14638 for (i = 0; i < n; ++i)
14640 dw_loc_descr_ref ref;
14641 rtx x = XVECEXP (concatn, 0, i);
14643 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14647 add_loc_descr (&cc_loc_result, ref);
14648 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14651 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14652 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14654 return cc_loc_result;
14657 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14658 for DEBUG_IMPLICIT_PTR RTL. */
14660 static dw_loc_descr_ref
14661 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14663 dw_loc_descr_ref ret;
14668 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14669 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14670 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14671 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14672 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14673 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14676 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14677 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14678 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14682 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14683 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14688 /* Output a proper Dwarf location descriptor for a variable or parameter
14689 which is either allocated in a register or in a memory location. For a
14690 register, we just generate an OP_REG and the register number. For a
14691 memory location we provide a Dwarf postfix expression describing how to
14692 generate the (dynamic) address of the object onto the address stack.
14694 MODE is mode of the decl if this loc_descriptor is going to be used in
14695 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14696 allowed, VOIDmode otherwise.
14698 If we don't know how to describe it, return 0. */
14700 static dw_loc_descr_ref
14701 loc_descriptor (rtx rtl, enum machine_mode mode,
14702 enum var_init_status initialized)
14704 dw_loc_descr_ref loc_result = NULL;
14706 switch (GET_CODE (rtl))
14709 /* The case of a subreg may arise when we have a local (register)
14710 variable or a formal (register) parameter which doesn't quite fill
14711 up an entire register. For now, just assume that it is
14712 legitimate to make the Dwarf info refer to the whole register which
14713 contains the given subreg. */
14714 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14718 loc_result = reg_loc_descriptor (rtl, initialized);
14722 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14724 if (loc_result == NULL)
14725 loc_result = tls_mem_loc_descriptor (rtl);
14726 if (loc_result == NULL)
14728 rtx new_rtl = avoid_constant_pool_reference (rtl);
14729 if (new_rtl != rtl)
14730 loc_result = loc_descriptor (new_rtl, mode, initialized);
14735 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14740 loc_result = concatn_loc_descriptor (rtl, initialized);
14745 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14747 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14748 if (GET_CODE (loc) == EXPR_LIST)
14749 loc = XEXP (loc, 0);
14750 loc_result = loc_descriptor (loc, mode, initialized);
14754 rtl = XEXP (rtl, 1);
14759 rtvec par_elems = XVEC (rtl, 0);
14760 int num_elem = GET_NUM_ELEM (par_elems);
14761 enum machine_mode mode;
14764 /* Create the first one, so we have something to add to. */
14765 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14766 VOIDmode, initialized);
14767 if (loc_result == NULL)
14769 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14770 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14771 for (i = 1; i < num_elem; i++)
14773 dw_loc_descr_ref temp;
14775 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14776 VOIDmode, initialized);
14779 add_loc_descr (&loc_result, temp);
14780 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14781 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14787 if (mode != VOIDmode && mode != BLKmode)
14788 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14793 if (mode == VOIDmode)
14794 mode = GET_MODE (rtl);
14796 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14798 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14800 /* Note that a CONST_DOUBLE rtx could represent either an integer
14801 or a floating-point constant. A CONST_DOUBLE is used whenever
14802 the constant requires more than one word in order to be
14803 adequately represented. We output CONST_DOUBLEs as blocks. */
14804 loc_result = new_loc_descr (DW_OP_implicit_value,
14805 GET_MODE_SIZE (mode), 0);
14806 if (SCALAR_FLOAT_MODE_P (mode))
14808 unsigned int length = GET_MODE_SIZE (mode);
14809 unsigned char *array
14810 = (unsigned char*) ggc_alloc_atomic (length);
14812 insert_float (rtl, array);
14813 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14814 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14815 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14816 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14820 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14821 loc_result->dw_loc_oprnd2.v.val_double
14822 = rtx_to_double_int (rtl);
14828 if (mode == VOIDmode)
14829 mode = GET_MODE (rtl);
14831 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14833 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14834 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14835 unsigned char *array = (unsigned char *)
14836 ggc_alloc_atomic (length * elt_size);
14840 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14841 switch (GET_MODE_CLASS (mode))
14843 case MODE_VECTOR_INT:
14844 for (i = 0, p = array; i < length; i++, p += elt_size)
14846 rtx elt = CONST_VECTOR_ELT (rtl, i);
14847 double_int val = rtx_to_double_int (elt);
14849 if (elt_size <= sizeof (HOST_WIDE_INT))
14850 insert_int (double_int_to_shwi (val), elt_size, p);
14853 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14854 insert_double (val, p);
14859 case MODE_VECTOR_FLOAT:
14860 for (i = 0, p = array; i < length; i++, p += elt_size)
14862 rtx elt = CONST_VECTOR_ELT (rtl, i);
14863 insert_float (elt, p);
14868 gcc_unreachable ();
14871 loc_result = new_loc_descr (DW_OP_implicit_value,
14872 length * elt_size, 0);
14873 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14874 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14875 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14876 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14881 if (mode == VOIDmode
14882 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14883 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14884 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14886 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14891 if (!const_ok_for_output (rtl))
14894 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14895 && (dwarf_version >= 4 || !dwarf_strict))
14897 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14898 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14899 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14900 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14901 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14905 case DEBUG_IMPLICIT_PTR:
14906 loc_result = implicit_ptr_descriptor (rtl, 0);
14910 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14911 && CONST_INT_P (XEXP (rtl, 1)))
14914 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14919 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14920 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14921 && (dwarf_version >= 4 || !dwarf_strict))
14923 /* Value expression. */
14924 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14926 add_loc_descr (&loc_result,
14927 new_loc_descr (DW_OP_stack_value, 0, 0));
14935 /* We need to figure out what section we should use as the base for the
14936 address ranges where a given location is valid.
14937 1. If this particular DECL has a section associated with it, use that.
14938 2. If this function has a section associated with it, use that.
14939 3. Otherwise, use the text section.
14940 XXX: If you split a variable across multiple sections, we won't notice. */
14942 static const char *
14943 secname_for_decl (const_tree decl)
14945 const char *secname;
14947 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14949 tree sectree = DECL_SECTION_NAME (decl);
14950 secname = TREE_STRING_POINTER (sectree);
14952 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14954 tree sectree = DECL_SECTION_NAME (current_function_decl);
14955 secname = TREE_STRING_POINTER (sectree);
14957 else if (cfun && in_cold_section_p)
14958 secname = crtl->subsections.cold_section_label;
14960 secname = text_section_label;
14965 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14968 decl_by_reference_p (tree decl)
14970 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14971 || TREE_CODE (decl) == VAR_DECL)
14972 && DECL_BY_REFERENCE (decl));
14975 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14978 static dw_loc_descr_ref
14979 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14980 enum var_init_status initialized)
14982 int have_address = 0;
14983 dw_loc_descr_ref descr;
14984 enum machine_mode mode;
14986 if (want_address != 2)
14988 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14990 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14992 varloc = PAT_VAR_LOCATION_LOC (varloc);
14993 if (GET_CODE (varloc) == EXPR_LIST)
14994 varloc = XEXP (varloc, 0);
14995 mode = GET_MODE (varloc);
14996 if (MEM_P (varloc))
14998 rtx addr = XEXP (varloc, 0);
14999 descr = mem_loc_descriptor (addr, mode, initialized);
15004 rtx x = avoid_constant_pool_reference (varloc);
15006 descr = mem_loc_descriptor (x, mode, initialized);
15010 descr = mem_loc_descriptor (varloc, mode, initialized);
15017 if (GET_CODE (varloc) == VAR_LOCATION)
15018 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
15020 mode = DECL_MODE (loc);
15021 descr = loc_descriptor (varloc, mode, initialized);
15028 if (want_address == 2 && !have_address
15029 && (dwarf_version >= 4 || !dwarf_strict))
15031 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15033 expansion_failed (loc, NULL_RTX,
15034 "DWARF address size mismatch");
15037 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
15040 /* Show if we can't fill the request for an address. */
15041 if (want_address && !have_address)
15043 expansion_failed (loc, NULL_RTX,
15044 "Want address and only have value");
15048 /* If we've got an address and don't want one, dereference. */
15049 if (!want_address && have_address)
15051 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15052 enum dwarf_location_atom op;
15054 if (size > DWARF2_ADDR_SIZE || size == -1)
15056 expansion_failed (loc, NULL_RTX,
15057 "DWARF address size mismatch");
15060 else if (size == DWARF2_ADDR_SIZE)
15063 op = DW_OP_deref_size;
15065 add_loc_descr (&descr, new_loc_descr (op, size, 0));
15071 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
15072 if it is not possible. */
15074 static dw_loc_descr_ref
15075 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
15077 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
15078 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
15079 else if (dwarf_version >= 3 || !dwarf_strict)
15080 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
15085 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
15086 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
15088 static dw_loc_descr_ref
15089 dw_sra_loc_expr (tree decl, rtx loc)
15092 unsigned int padsize = 0;
15093 dw_loc_descr_ref descr, *descr_tail;
15094 unsigned HOST_WIDE_INT decl_size;
15096 enum var_init_status initialized;
15098 if (DECL_SIZE (decl) == NULL
15099 || !host_integerp (DECL_SIZE (decl), 1))
15102 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
15104 descr_tail = &descr;
15106 for (p = loc; p; p = XEXP (p, 1))
15108 unsigned int bitsize = decl_piece_bitsize (p);
15109 rtx loc_note = *decl_piece_varloc_ptr (p);
15110 dw_loc_descr_ref cur_descr;
15111 dw_loc_descr_ref *tail, last = NULL;
15112 unsigned int opsize = 0;
15114 if (loc_note == NULL_RTX
15115 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
15117 padsize += bitsize;
15120 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
15121 varloc = NOTE_VAR_LOCATION (loc_note);
15122 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
15123 if (cur_descr == NULL)
15125 padsize += bitsize;
15129 /* Check that cur_descr either doesn't use
15130 DW_OP_*piece operations, or their sum is equal
15131 to bitsize. Otherwise we can't embed it. */
15132 for (tail = &cur_descr; *tail != NULL;
15133 tail = &(*tail)->dw_loc_next)
15134 if ((*tail)->dw_loc_opc == DW_OP_piece)
15136 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
15140 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
15142 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
15146 if (last != NULL && opsize != bitsize)
15148 padsize += bitsize;
15152 /* If there is a hole, add DW_OP_*piece after empty DWARF
15153 expression, which means that those bits are optimized out. */
15156 if (padsize > decl_size)
15158 decl_size -= padsize;
15159 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
15160 if (*descr_tail == NULL)
15162 descr_tail = &(*descr_tail)->dw_loc_next;
15165 *descr_tail = cur_descr;
15167 if (bitsize > decl_size)
15169 decl_size -= bitsize;
15172 HOST_WIDE_INT offset = 0;
15173 if (GET_CODE (varloc) == VAR_LOCATION
15174 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15176 varloc = PAT_VAR_LOCATION_LOC (varloc);
15177 if (GET_CODE (varloc) == EXPR_LIST)
15178 varloc = XEXP (varloc, 0);
15182 if (GET_CODE (varloc) == CONST
15183 || GET_CODE (varloc) == SIGN_EXTEND
15184 || GET_CODE (varloc) == ZERO_EXTEND)
15185 varloc = XEXP (varloc, 0);
15186 else if (GET_CODE (varloc) == SUBREG)
15187 varloc = SUBREG_REG (varloc);
15192 /* DW_OP_bit_size offset should be zero for register
15193 or implicit location descriptions and empty location
15194 descriptions, but for memory addresses needs big endian
15196 if (MEM_P (varloc))
15198 unsigned HOST_WIDE_INT memsize
15199 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15200 if (memsize != bitsize)
15202 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15203 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15205 if (memsize < bitsize)
15207 if (BITS_BIG_ENDIAN)
15208 offset = memsize - bitsize;
15212 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15213 if (*descr_tail == NULL)
15215 descr_tail = &(*descr_tail)->dw_loc_next;
15219 /* If there were any non-empty expressions, add padding till the end of
15221 if (descr != NULL && decl_size != 0)
15223 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15224 if (*descr_tail == NULL)
15230 /* Return the dwarf representation of the location list LOC_LIST of
15231 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15234 static dw_loc_list_ref
15235 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15237 const char *endname, *secname;
15239 enum var_init_status initialized;
15240 struct var_loc_node *node;
15241 dw_loc_descr_ref descr;
15242 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15243 dw_loc_list_ref list = NULL;
15244 dw_loc_list_ref *listp = &list;
15246 /* Now that we know what section we are using for a base,
15247 actually construct the list of locations.
15248 The first location information is what is passed to the
15249 function that creates the location list, and the remaining
15250 locations just get added on to that list.
15251 Note that we only know the start address for a location
15252 (IE location changes), so to build the range, we use
15253 the range [current location start, next location start].
15254 This means we have to special case the last node, and generate
15255 a range of [last location start, end of function label]. */
15257 secname = secname_for_decl (decl);
15259 for (node = loc_list->first; node; node = node->next)
15260 if (GET_CODE (node->loc) == EXPR_LIST
15261 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15263 if (GET_CODE (node->loc) == EXPR_LIST)
15265 /* This requires DW_OP_{,bit_}piece, which is not usable
15266 inside DWARF expressions. */
15267 if (want_address != 2)
15269 descr = dw_sra_loc_expr (decl, node->loc);
15275 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15276 varloc = NOTE_VAR_LOCATION (node->loc);
15277 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15281 /* The variable has a location between NODE->LABEL and
15282 NODE->NEXT->LABEL. */
15284 endname = node->next->label;
15285 /* If the variable has a location at the last label
15286 it keeps its location until the end of function. */
15287 else if (!current_function_decl)
15288 endname = text_end_label;
15291 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15292 current_function_funcdef_no);
15293 endname = ggc_strdup (label_id);
15296 *listp = new_loc_list (descr, node->label, endname, secname);
15297 listp = &(*listp)->dw_loc_next;
15301 /* Try to avoid the overhead of a location list emitting a location
15302 expression instead, but only if we didn't have more than one
15303 location entry in the first place. If some entries were not
15304 representable, we don't want to pretend a single entry that was
15305 applies to the entire scope in which the variable is
15307 if (list && loc_list->first->next)
15313 /* Return if the loc_list has only single element and thus can be represented
15314 as location description. */
15317 single_element_loc_list_p (dw_loc_list_ref list)
15319 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15320 return !list->ll_symbol;
15323 /* To each location in list LIST add loc descr REF. */
15326 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15328 dw_loc_descr_ref copy;
15329 add_loc_descr (&list->expr, ref);
15330 list = list->dw_loc_next;
15333 copy = ggc_alloc_dw_loc_descr_node ();
15334 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15335 add_loc_descr (&list->expr, copy);
15336 while (copy->dw_loc_next)
15338 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15339 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15340 copy->dw_loc_next = new_copy;
15343 list = list->dw_loc_next;
15347 /* Given two lists RET and LIST
15348 produce location list that is result of adding expression in LIST
15349 to expression in RET on each possition in program.
15350 Might be destructive on both RET and LIST.
15352 TODO: We handle only simple cases of RET or LIST having at most one
15353 element. General case would inolve sorting the lists in program order
15354 and merging them that will need some additional work.
15355 Adding that will improve quality of debug info especially for SRA-ed
15359 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15368 if (!list->dw_loc_next)
15370 add_loc_descr_to_each (*ret, list->expr);
15373 if (!(*ret)->dw_loc_next)
15375 add_loc_descr_to_each (list, (*ret)->expr);
15379 expansion_failed (NULL_TREE, NULL_RTX,
15380 "Don't know how to merge two non-trivial"
15381 " location lists.\n");
15386 /* LOC is constant expression. Try a luck, look it up in constant
15387 pool and return its loc_descr of its address. */
15389 static dw_loc_descr_ref
15390 cst_pool_loc_descr (tree loc)
15392 /* Get an RTL for this, if something has been emitted. */
15393 rtx rtl = lookup_constant_def (loc);
15394 enum machine_mode mode;
15396 if (!rtl || !MEM_P (rtl))
15401 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15403 /* TODO: We might get more coverage if we was actually delaying expansion
15404 of all expressions till end of compilation when constant pools are fully
15406 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15408 expansion_failed (loc, NULL_RTX,
15409 "CST value in contant pool but not marked.");
15412 mode = GET_MODE (rtl);
15413 rtl = XEXP (rtl, 0);
15414 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15417 /* Return dw_loc_list representing address of addr_expr LOC
15418 by looking for innder INDIRECT_REF expression and turing it
15419 into simple arithmetics. */
15421 static dw_loc_list_ref
15422 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15425 HOST_WIDE_INT bitsize, bitpos, bytepos;
15426 enum machine_mode mode;
15428 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15429 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15431 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15432 &bitsize, &bitpos, &offset, &mode,
15433 &unsignedp, &volatilep, false);
15435 if (bitpos % BITS_PER_UNIT)
15437 expansion_failed (loc, NULL_RTX, "bitfield access");
15440 if (!INDIRECT_REF_P (obj))
15442 expansion_failed (obj,
15443 NULL_RTX, "no indirect ref in inner refrence");
15446 if (!offset && !bitpos)
15447 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15449 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15450 && (dwarf_version >= 4 || !dwarf_strict))
15452 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15457 /* Variable offset. */
15458 list_ret1 = loc_list_from_tree (offset, 0);
15459 if (list_ret1 == 0)
15461 add_loc_list (&list_ret, list_ret1);
15464 add_loc_descr_to_each (list_ret,
15465 new_loc_descr (DW_OP_plus, 0, 0));
15467 bytepos = bitpos / BITS_PER_UNIT;
15469 add_loc_descr_to_each (list_ret,
15470 new_loc_descr (DW_OP_plus_uconst,
15472 else if (bytepos < 0)
15473 loc_list_plus_const (list_ret, bytepos);
15474 add_loc_descr_to_each (list_ret,
15475 new_loc_descr (DW_OP_stack_value, 0, 0));
15481 /* Generate Dwarf location list representing LOC.
15482 If WANT_ADDRESS is false, expression computing LOC will be computed
15483 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15484 if WANT_ADDRESS is 2, expression computing address useable in location
15485 will be returned (i.e. DW_OP_reg can be used
15486 to refer to register values). */
15488 static dw_loc_list_ref
15489 loc_list_from_tree (tree loc, int want_address)
15491 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15492 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15493 int have_address = 0;
15494 enum dwarf_location_atom op;
15496 /* ??? Most of the time we do not take proper care for sign/zero
15497 extending the values properly. Hopefully this won't be a real
15500 switch (TREE_CODE (loc))
15503 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15506 case PLACEHOLDER_EXPR:
15507 /* This case involves extracting fields from an object to determine the
15508 position of other fields. We don't try to encode this here. The
15509 only user of this is Ada, which encodes the needed information using
15510 the names of types. */
15511 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15515 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15516 /* There are no opcodes for these operations. */
15519 case PREINCREMENT_EXPR:
15520 case PREDECREMENT_EXPR:
15521 case POSTINCREMENT_EXPR:
15522 case POSTDECREMENT_EXPR:
15523 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15524 /* There are no opcodes for these operations. */
15528 /* If we already want an address, see if there is INDIRECT_REF inside
15529 e.g. for &this->field. */
15532 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15533 (loc, want_address == 2);
15536 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15537 && (ret = cst_pool_loc_descr (loc)))
15540 /* Otherwise, process the argument and look for the address. */
15541 if (!list_ret && !ret)
15542 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15546 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15552 if (DECL_THREAD_LOCAL_P (loc))
15555 enum dwarf_location_atom first_op;
15556 enum dwarf_location_atom second_op;
15557 bool dtprel = false;
15559 if (targetm.have_tls)
15561 /* If this is not defined, we have no way to emit the
15563 if (!targetm.asm_out.output_dwarf_dtprel)
15566 /* The way DW_OP_GNU_push_tls_address is specified, we
15567 can only look up addresses of objects in the current
15568 module. We used DW_OP_addr as first op, but that's
15569 wrong, because DW_OP_addr is relocated by the debug
15570 info consumer, while DW_OP_GNU_push_tls_address
15571 operand shouldn't be. */
15572 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15574 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15576 second_op = DW_OP_GNU_push_tls_address;
15580 if (!targetm.emutls.debug_form_tls_address
15581 || !(dwarf_version >= 3 || !dwarf_strict))
15583 /* We stuffed the control variable into the DECL_VALUE_EXPR
15584 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15585 no longer appear in gimple code. We used the control
15586 variable in specific so that we could pick it up here. */
15587 loc = DECL_VALUE_EXPR (loc);
15588 first_op = DW_OP_addr;
15589 second_op = DW_OP_form_tls_address;
15592 rtl = rtl_for_decl_location (loc);
15593 if (rtl == NULL_RTX)
15598 rtl = XEXP (rtl, 0);
15599 if (! CONSTANT_P (rtl))
15602 ret = new_loc_descr (first_op, 0, 0);
15603 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15604 ret->dw_loc_oprnd1.v.val_addr = rtl;
15605 ret->dtprel = dtprel;
15607 ret1 = new_loc_descr (second_op, 0, 0);
15608 add_loc_descr (&ret, ret1);
15617 if (DECL_HAS_VALUE_EXPR_P (loc))
15618 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15622 case FUNCTION_DECL:
15625 var_loc_list *loc_list = lookup_decl_loc (loc);
15627 if (loc_list && loc_list->first)
15629 list_ret = dw_loc_list (loc_list, loc, want_address);
15630 have_address = want_address != 0;
15633 rtl = rtl_for_decl_location (loc);
15634 if (rtl == NULL_RTX)
15636 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15639 else if (CONST_INT_P (rtl))
15641 HOST_WIDE_INT val = INTVAL (rtl);
15642 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15643 val &= GET_MODE_MASK (DECL_MODE (loc));
15644 ret = int_loc_descriptor (val);
15646 else if (GET_CODE (rtl) == CONST_STRING)
15648 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15651 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15653 ret = new_loc_descr (DW_OP_addr, 0, 0);
15654 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15655 ret->dw_loc_oprnd1.v.val_addr = rtl;
15659 enum machine_mode mode;
15661 /* Certain constructs can only be represented at top-level. */
15662 if (want_address == 2)
15664 ret = loc_descriptor (rtl, VOIDmode,
15665 VAR_INIT_STATUS_INITIALIZED);
15670 mode = GET_MODE (rtl);
15673 rtl = XEXP (rtl, 0);
15676 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15679 expansion_failed (loc, rtl,
15680 "failed to produce loc descriptor for rtl");
15687 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15691 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15695 case COMPOUND_EXPR:
15696 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15699 case VIEW_CONVERT_EXPR:
15702 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15704 case COMPONENT_REF:
15705 case BIT_FIELD_REF:
15707 case ARRAY_RANGE_REF:
15708 case REALPART_EXPR:
15709 case IMAGPART_EXPR:
15712 HOST_WIDE_INT bitsize, bitpos, bytepos;
15713 enum machine_mode mode;
15715 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15717 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15718 &unsignedp, &volatilep, false);
15720 gcc_assert (obj != loc);
15722 list_ret = loc_list_from_tree (obj,
15724 && !bitpos && !offset ? 2 : 1);
15725 /* TODO: We can extract value of the small expression via shifting even
15726 for nonzero bitpos. */
15729 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15731 expansion_failed (loc, NULL_RTX,
15732 "bitfield access");
15736 if (offset != NULL_TREE)
15738 /* Variable offset. */
15739 list_ret1 = loc_list_from_tree (offset, 0);
15740 if (list_ret1 == 0)
15742 add_loc_list (&list_ret, list_ret1);
15745 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15748 bytepos = bitpos / BITS_PER_UNIT;
15750 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15751 else if (bytepos < 0)
15752 loc_list_plus_const (list_ret, bytepos);
15759 if ((want_address || !host_integerp (loc, 0))
15760 && (ret = cst_pool_loc_descr (loc)))
15762 else if (want_address == 2
15763 && host_integerp (loc, 0)
15764 && (ret = address_of_int_loc_descriptor
15765 (int_size_in_bytes (TREE_TYPE (loc)),
15766 tree_low_cst (loc, 0))))
15768 else if (host_integerp (loc, 0))
15769 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15772 expansion_failed (loc, NULL_RTX,
15773 "Integer operand is not host integer");
15782 if ((ret = cst_pool_loc_descr (loc)))
15785 /* We can construct small constants here using int_loc_descriptor. */
15786 expansion_failed (loc, NULL_RTX,
15787 "constructor or constant not in constant pool");
15790 case TRUTH_AND_EXPR:
15791 case TRUTH_ANDIF_EXPR:
15796 case TRUTH_XOR_EXPR:
15801 case TRUTH_OR_EXPR:
15802 case TRUTH_ORIF_EXPR:
15807 case FLOOR_DIV_EXPR:
15808 case CEIL_DIV_EXPR:
15809 case ROUND_DIV_EXPR:
15810 case TRUNC_DIV_EXPR:
15811 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15820 case FLOOR_MOD_EXPR:
15821 case CEIL_MOD_EXPR:
15822 case ROUND_MOD_EXPR:
15823 case TRUNC_MOD_EXPR:
15824 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15829 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15830 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15831 if (list_ret == 0 || list_ret1 == 0)
15834 add_loc_list (&list_ret, list_ret1);
15837 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15838 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15839 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15840 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15841 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15853 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15856 case POINTER_PLUS_EXPR:
15858 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15860 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15864 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15872 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15879 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15886 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15893 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15908 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15909 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15910 if (list_ret == 0 || list_ret1 == 0)
15913 add_loc_list (&list_ret, list_ret1);
15916 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15919 case TRUTH_NOT_EXPR:
15933 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15937 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15943 const enum tree_code code =
15944 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15946 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15947 build2 (code, integer_type_node,
15948 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15949 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15952 /* ... fall through ... */
15956 dw_loc_descr_ref lhs
15957 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15958 dw_loc_list_ref rhs
15959 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15960 dw_loc_descr_ref bra_node, jump_node, tmp;
15962 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15963 if (list_ret == 0 || lhs == 0 || rhs == 0)
15966 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15967 add_loc_descr_to_each (list_ret, bra_node);
15969 add_loc_list (&list_ret, rhs);
15970 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15971 add_loc_descr_to_each (list_ret, jump_node);
15973 add_loc_descr_to_each (list_ret, lhs);
15974 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15975 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15977 /* ??? Need a node to point the skip at. Use a nop. */
15978 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15979 add_loc_descr_to_each (list_ret, tmp);
15980 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15981 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15985 case FIX_TRUNC_EXPR:
15989 /* Leave front-end specific codes as simply unknown. This comes
15990 up, for instance, with the C STMT_EXPR. */
15991 if ((unsigned int) TREE_CODE (loc)
15992 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15994 expansion_failed (loc, NULL_RTX,
15995 "language specific tree node");
15999 #ifdef ENABLE_CHECKING
16000 /* Otherwise this is a generic code; we should just lists all of
16001 these explicitly. We forgot one. */
16002 gcc_unreachable ();
16004 /* In a release build, we want to degrade gracefully: better to
16005 generate incomplete debugging information than to crash. */
16010 if (!ret && !list_ret)
16013 if (want_address == 2 && !have_address
16014 && (dwarf_version >= 4 || !dwarf_strict))
16016 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
16018 expansion_failed (loc, NULL_RTX,
16019 "DWARF address size mismatch");
16023 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
16025 add_loc_descr_to_each (list_ret,
16026 new_loc_descr (DW_OP_stack_value, 0, 0));
16029 /* Show if we can't fill the request for an address. */
16030 if (want_address && !have_address)
16032 expansion_failed (loc, NULL_RTX,
16033 "Want address and only have value");
16037 gcc_assert (!ret || !list_ret);
16039 /* If we've got an address and don't want one, dereference. */
16040 if (!want_address && have_address)
16042 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
16044 if (size > DWARF2_ADDR_SIZE || size == -1)
16046 expansion_failed (loc, NULL_RTX,
16047 "DWARF address size mismatch");
16050 else if (size == DWARF2_ADDR_SIZE)
16053 op = DW_OP_deref_size;
16056 add_loc_descr (&ret, new_loc_descr (op, size, 0));
16058 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
16061 list_ret = new_loc_list (ret, NULL, NULL, NULL);
16066 /* Same as above but return only single location expression. */
16067 static dw_loc_descr_ref
16068 loc_descriptor_from_tree (tree loc, int want_address)
16070 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
16073 if (ret->dw_loc_next)
16075 expansion_failed (loc, NULL_RTX,
16076 "Location list where only loc descriptor needed");
16082 /* Given a value, round it up to the lowest multiple of `boundary'
16083 which is not less than the value itself. */
16085 static inline HOST_WIDE_INT
16086 ceiling (HOST_WIDE_INT value, unsigned int boundary)
16088 return (((value + boundary - 1) / boundary) * boundary);
16091 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16092 pointer to the declared type for the relevant field variable, or return
16093 `integer_type_node' if the given node turns out to be an
16094 ERROR_MARK node. */
16097 field_type (const_tree decl)
16101 if (TREE_CODE (decl) == ERROR_MARK)
16102 return integer_type_node;
16104 type = DECL_BIT_FIELD_TYPE (decl);
16105 if (type == NULL_TREE)
16106 type = TREE_TYPE (decl);
16111 /* Given a pointer to a tree node, return the alignment in bits for
16112 it, or else return BITS_PER_WORD if the node actually turns out to
16113 be an ERROR_MARK node. */
16115 static inline unsigned
16116 simple_type_align_in_bits (const_tree type)
16118 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
16121 static inline unsigned
16122 simple_decl_align_in_bits (const_tree decl)
16124 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
16127 /* Return the result of rounding T up to ALIGN. */
16129 static inline double_int
16130 round_up_to_align (double_int t, unsigned int align)
16132 double_int alignd = uhwi_to_double_int (align);
16133 t = double_int_add (t, alignd);
16134 t = double_int_add (t, double_int_minus_one);
16135 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
16136 t = double_int_mul (t, alignd);
16140 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
16141 lowest addressed byte of the "containing object" for the given FIELD_DECL,
16142 or return 0 if we are unable to determine what that offset is, either
16143 because the argument turns out to be a pointer to an ERROR_MARK node, or
16144 because the offset is actually variable. (We can't handle the latter case
16147 static HOST_WIDE_INT
16148 field_byte_offset (const_tree decl)
16150 double_int object_offset_in_bits;
16151 double_int object_offset_in_bytes;
16152 double_int bitpos_int;
16154 if (TREE_CODE (decl) == ERROR_MARK)
16157 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
16159 /* We cannot yet cope with fields whose positions are variable, so
16160 for now, when we see such things, we simply return 0. Someday, we may
16161 be able to handle such cases, but it will be damn difficult. */
16162 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
16165 bitpos_int = tree_to_double_int (bit_position (decl));
16167 #ifdef PCC_BITFIELD_TYPE_MATTERS
16168 if (PCC_BITFIELD_TYPE_MATTERS)
16171 tree field_size_tree;
16172 double_int deepest_bitpos;
16173 double_int field_size_in_bits;
16174 unsigned int type_align_in_bits;
16175 unsigned int decl_align_in_bits;
16176 double_int type_size_in_bits;
16178 type = field_type (decl);
16179 type_size_in_bits = double_int_type_size_in_bits (type);
16180 type_align_in_bits = simple_type_align_in_bits (type);
16182 field_size_tree = DECL_SIZE (decl);
16184 /* The size could be unspecified if there was an error, or for
16185 a flexible array member. */
16186 if (!field_size_tree)
16187 field_size_tree = bitsize_zero_node;
16189 /* If the size of the field is not constant, use the type size. */
16190 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16191 field_size_in_bits = tree_to_double_int (field_size_tree);
16193 field_size_in_bits = type_size_in_bits;
16195 decl_align_in_bits = simple_decl_align_in_bits (decl);
16197 /* The GCC front-end doesn't make any attempt to keep track of the
16198 starting bit offset (relative to the start of the containing
16199 structure type) of the hypothetical "containing object" for a
16200 bit-field. Thus, when computing the byte offset value for the
16201 start of the "containing object" of a bit-field, we must deduce
16202 this information on our own. This can be rather tricky to do in
16203 some cases. For example, handling the following structure type
16204 definition when compiling for an i386/i486 target (which only
16205 aligns long long's to 32-bit boundaries) can be very tricky:
16207 struct S { int field1; long long field2:31; };
16209 Fortunately, there is a simple rule-of-thumb which can be used
16210 in such cases. When compiling for an i386/i486, GCC will
16211 allocate 8 bytes for the structure shown above. It decides to
16212 do this based upon one simple rule for bit-field allocation.
16213 GCC allocates each "containing object" for each bit-field at
16214 the first (i.e. lowest addressed) legitimate alignment boundary
16215 (based upon the required minimum alignment for the declared
16216 type of the field) which it can possibly use, subject to the
16217 condition that there is still enough available space remaining
16218 in the containing object (when allocated at the selected point)
16219 to fully accommodate all of the bits of the bit-field itself.
16221 This simple rule makes it obvious why GCC allocates 8 bytes for
16222 each object of the structure type shown above. When looking
16223 for a place to allocate the "containing object" for `field2',
16224 the compiler simply tries to allocate a 64-bit "containing
16225 object" at each successive 32-bit boundary (starting at zero)
16226 until it finds a place to allocate that 64- bit field such that
16227 at least 31 contiguous (and previously unallocated) bits remain
16228 within that selected 64 bit field. (As it turns out, for the
16229 example above, the compiler finds it is OK to allocate the
16230 "containing object" 64-bit field at bit-offset zero within the
16233 Here we attempt to work backwards from the limited set of facts
16234 we're given, and we try to deduce from those facts, where GCC
16235 must have believed that the containing object started (within
16236 the structure type). The value we deduce is then used (by the
16237 callers of this routine) to generate DW_AT_location and
16238 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16239 the case of DW_AT_location, regular fields as well). */
16241 /* Figure out the bit-distance from the start of the structure to
16242 the "deepest" bit of the bit-field. */
16243 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16245 /* This is the tricky part. Use some fancy footwork to deduce
16246 where the lowest addressed bit of the containing object must
16248 object_offset_in_bits
16249 = double_int_sub (deepest_bitpos, type_size_in_bits);
16251 /* Round up to type_align by default. This works best for
16253 object_offset_in_bits
16254 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16256 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16258 object_offset_in_bits
16259 = double_int_sub (deepest_bitpos, type_size_in_bits);
16261 /* Round up to decl_align instead. */
16262 object_offset_in_bits
16263 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16267 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16268 object_offset_in_bits = bitpos_int;
16270 object_offset_in_bytes
16271 = double_int_div (object_offset_in_bits,
16272 uhwi_to_double_int (BITS_PER_UNIT), true,
16274 return double_int_to_shwi (object_offset_in_bytes);
16277 /* The following routines define various Dwarf attributes and any data
16278 associated with them. */
16280 /* Add a location description attribute value to a DIE.
16282 This emits location attributes suitable for whole variables and
16283 whole parameters. Note that the location attributes for struct fields are
16284 generated by the routine `data_member_location_attribute' below. */
16287 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16288 dw_loc_list_ref descr)
16292 if (single_element_loc_list_p (descr))
16293 add_AT_loc (die, attr_kind, descr->expr);
16295 add_AT_loc_list (die, attr_kind, descr);
16298 /* Add DW_AT_accessibility attribute to DIE if needed. */
16301 add_accessibility_attribute (dw_die_ref die, tree decl)
16303 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16304 children, otherwise the default is DW_ACCESS_public. In DWARF2
16305 the default has always been DW_ACCESS_public. */
16306 if (TREE_PROTECTED (decl))
16307 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16308 else if (TREE_PRIVATE (decl))
16310 if (dwarf_version == 2
16311 || die->die_parent == NULL
16312 || die->die_parent->die_tag != DW_TAG_class_type)
16313 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16315 else if (dwarf_version > 2
16317 && die->die_parent->die_tag == DW_TAG_class_type)
16318 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16321 /* Attach the specialized form of location attribute used for data members of
16322 struct and union types. In the special case of a FIELD_DECL node which
16323 represents a bit-field, the "offset" part of this special location
16324 descriptor must indicate the distance in bytes from the lowest-addressed
16325 byte of the containing struct or union type to the lowest-addressed byte of
16326 the "containing object" for the bit-field. (See the `field_byte_offset'
16329 For any given bit-field, the "containing object" is a hypothetical object
16330 (of some integral or enum type) within which the given bit-field lives. The
16331 type of this hypothetical "containing object" is always the same as the
16332 declared type of the individual bit-field itself (for GCC anyway... the
16333 DWARF spec doesn't actually mandate this). Note that it is the size (in
16334 bytes) of the hypothetical "containing object" which will be given in the
16335 DW_AT_byte_size attribute for this bit-field. (See the
16336 `byte_size_attribute' function below.) It is also used when calculating the
16337 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16338 function below.) */
16341 add_data_member_location_attribute (dw_die_ref die, tree decl)
16343 HOST_WIDE_INT offset;
16344 dw_loc_descr_ref loc_descr = 0;
16346 if (TREE_CODE (decl) == TREE_BINFO)
16348 /* We're working on the TAG_inheritance for a base class. */
16349 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16351 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16352 aren't at a fixed offset from all (sub)objects of the same
16353 type. We need to extract the appropriate offset from our
16354 vtable. The following dwarf expression means
16356 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16358 This is specific to the V3 ABI, of course. */
16360 dw_loc_descr_ref tmp;
16362 /* Make a copy of the object address. */
16363 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16364 add_loc_descr (&loc_descr, tmp);
16366 /* Extract the vtable address. */
16367 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16368 add_loc_descr (&loc_descr, tmp);
16370 /* Calculate the address of the offset. */
16371 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16372 gcc_assert (offset < 0);
16374 tmp = int_loc_descriptor (-offset);
16375 add_loc_descr (&loc_descr, tmp);
16376 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16377 add_loc_descr (&loc_descr, tmp);
16379 /* Extract the offset. */
16380 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16381 add_loc_descr (&loc_descr, tmp);
16383 /* Add it to the object address. */
16384 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16385 add_loc_descr (&loc_descr, tmp);
16388 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16391 offset = field_byte_offset (decl);
16395 if (dwarf_version > 2)
16397 /* Don't need to output a location expression, just the constant. */
16399 add_AT_int (die, DW_AT_data_member_location, offset);
16401 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16406 enum dwarf_location_atom op;
16408 /* The DWARF2 standard says that we should assume that the structure
16409 address is already on the stack, so we can specify a structure
16410 field address by using DW_OP_plus_uconst. */
16412 #ifdef MIPS_DEBUGGING_INFO
16413 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16414 operator correctly. It works only if we leave the offset on the
16418 op = DW_OP_plus_uconst;
16421 loc_descr = new_loc_descr (op, offset, 0);
16425 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16428 /* Writes integer values to dw_vec_const array. */
16431 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16435 *dest++ = val & 0xff;
16441 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16443 static HOST_WIDE_INT
16444 extract_int (const unsigned char *src, unsigned int size)
16446 HOST_WIDE_INT val = 0;
16452 val |= *--src & 0xff;
16458 /* Writes double_int values to dw_vec_const array. */
16461 insert_double (double_int val, unsigned char *dest)
16463 unsigned char *p0 = dest;
16464 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16466 if (WORDS_BIG_ENDIAN)
16472 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16473 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16476 /* Writes floating point values to dw_vec_const array. */
16479 insert_float (const_rtx rtl, unsigned char *array)
16481 REAL_VALUE_TYPE rv;
16485 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16486 real_to_target (val, &rv, GET_MODE (rtl));
16488 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16489 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16491 insert_int (val[i], 4, array);
16496 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16497 does not have a "location" either in memory or in a register. These
16498 things can arise in GNU C when a constant is passed as an actual parameter
16499 to an inlined function. They can also arise in C++ where declared
16500 constants do not necessarily get memory "homes". */
16503 add_const_value_attribute (dw_die_ref die, rtx rtl)
16505 switch (GET_CODE (rtl))
16509 HOST_WIDE_INT val = INTVAL (rtl);
16512 add_AT_int (die, DW_AT_const_value, val);
16514 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16519 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16520 floating-point constant. A CONST_DOUBLE is used whenever the
16521 constant requires more than one word in order to be adequately
16524 enum machine_mode mode = GET_MODE (rtl);
16526 if (SCALAR_FLOAT_MODE_P (mode))
16528 unsigned int length = GET_MODE_SIZE (mode);
16529 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16531 insert_float (rtl, array);
16532 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16535 add_AT_double (die, DW_AT_const_value,
16536 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16542 enum machine_mode mode = GET_MODE (rtl);
16543 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16544 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16545 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16546 (length * elt_size);
16550 switch (GET_MODE_CLASS (mode))
16552 case MODE_VECTOR_INT:
16553 for (i = 0, p = array; i < length; i++, p += elt_size)
16555 rtx elt = CONST_VECTOR_ELT (rtl, i);
16556 double_int val = rtx_to_double_int (elt);
16558 if (elt_size <= sizeof (HOST_WIDE_INT))
16559 insert_int (double_int_to_shwi (val), elt_size, p);
16562 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16563 insert_double (val, p);
16568 case MODE_VECTOR_FLOAT:
16569 for (i = 0, p = array; i < length; i++, p += elt_size)
16571 rtx elt = CONST_VECTOR_ELT (rtl, i);
16572 insert_float (elt, p);
16577 gcc_unreachable ();
16580 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16585 if (dwarf_version >= 4 || !dwarf_strict)
16587 dw_loc_descr_ref loc_result;
16588 resolve_one_addr (&rtl, NULL);
16590 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16591 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16592 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16593 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16594 add_AT_loc (die, DW_AT_location, loc_result);
16595 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16601 if (CONSTANT_P (XEXP (rtl, 0)))
16602 return add_const_value_attribute (die, XEXP (rtl, 0));
16605 if (!const_ok_for_output (rtl))
16608 if (dwarf_version >= 4 || !dwarf_strict)
16613 /* In cases where an inlined instance of an inline function is passed
16614 the address of an `auto' variable (which is local to the caller) we
16615 can get a situation where the DECL_RTL of the artificial local
16616 variable (for the inlining) which acts as a stand-in for the
16617 corresponding formal parameter (of the inline function) will look
16618 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16619 exactly a compile-time constant expression, but it isn't the address
16620 of the (artificial) local variable either. Rather, it represents the
16621 *value* which the artificial local variable always has during its
16622 lifetime. We currently have no way to represent such quasi-constant
16623 values in Dwarf, so for now we just punt and generate nothing. */
16631 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16632 && MEM_READONLY_P (rtl)
16633 && GET_MODE (rtl) == BLKmode)
16635 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16641 /* No other kinds of rtx should be possible here. */
16642 gcc_unreachable ();
16647 /* Determine whether the evaluation of EXPR references any variables
16648 or functions which aren't otherwise used (and therefore may not be
16651 reference_to_unused (tree * tp, int * walk_subtrees,
16652 void * data ATTRIBUTE_UNUSED)
16654 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16655 *walk_subtrees = 0;
16657 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16658 && ! TREE_ASM_WRITTEN (*tp))
16660 /* ??? The C++ FE emits debug information for using decls, so
16661 putting gcc_unreachable here falls over. See PR31899. For now
16662 be conservative. */
16663 else if (!cgraph_global_info_ready
16664 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16666 else if (TREE_CODE (*tp) == VAR_DECL)
16668 struct varpool_node *node = varpool_get_node (*tp);
16669 if (!node || !node->needed)
16672 else if (TREE_CODE (*tp) == FUNCTION_DECL
16673 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16675 /* The call graph machinery must have finished analyzing,
16676 optimizing and gimplifying the CU by now.
16677 So if *TP has no call graph node associated
16678 to it, it means *TP will not be emitted. */
16679 if (!cgraph_get_node (*tp))
16682 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16688 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16689 for use in a later add_const_value_attribute call. */
16692 rtl_for_decl_init (tree init, tree type)
16694 rtx rtl = NULL_RTX;
16698 /* If a variable is initialized with a string constant without embedded
16699 zeros, build CONST_STRING. */
16700 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16702 tree enttype = TREE_TYPE (type);
16703 tree domain = TYPE_DOMAIN (type);
16704 enum machine_mode mode = TYPE_MODE (enttype);
16706 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16708 && integer_zerop (TYPE_MIN_VALUE (domain))
16709 && compare_tree_int (TYPE_MAX_VALUE (domain),
16710 TREE_STRING_LENGTH (init) - 1) == 0
16711 && ((size_t) TREE_STRING_LENGTH (init)
16712 == strlen (TREE_STRING_POINTER (init)) + 1))
16714 rtl = gen_rtx_CONST_STRING (VOIDmode,
16715 ggc_strdup (TREE_STRING_POINTER (init)));
16716 rtl = gen_rtx_MEM (BLKmode, rtl);
16717 MEM_READONLY_P (rtl) = 1;
16720 /* Other aggregates, and complex values, could be represented using
16722 else if (AGGREGATE_TYPE_P (type)
16723 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16724 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16725 || TREE_CODE (type) == COMPLEX_TYPE)
16727 /* Vectors only work if their mode is supported by the target.
16728 FIXME: generic vectors ought to work too. */
16729 else if (TREE_CODE (type) == VECTOR_TYPE
16730 && !VECTOR_MODE_P (TYPE_MODE (type)))
16732 /* If the initializer is something that we know will expand into an
16733 immediate RTL constant, expand it now. We must be careful not to
16734 reference variables which won't be output. */
16735 else if (initializer_constant_valid_p (init, type)
16736 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16738 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16740 if (TREE_CODE (type) == VECTOR_TYPE)
16741 switch (TREE_CODE (init))
16746 if (TREE_CONSTANT (init))
16748 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16749 bool constant_p = true;
16751 unsigned HOST_WIDE_INT ix;
16753 /* Even when ctor is constant, it might contain non-*_CST
16754 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16755 belong into VECTOR_CST nodes. */
16756 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16757 if (!CONSTANT_CLASS_P (value))
16759 constant_p = false;
16765 init = build_vector_from_ctor (type, elts);
16775 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16777 /* If expand_expr returns a MEM, it wasn't immediate. */
16778 gcc_assert (!rtl || !MEM_P (rtl));
16784 /* Generate RTL for the variable DECL to represent its location. */
16787 rtl_for_decl_location (tree decl)
16791 /* Here we have to decide where we are going to say the parameter "lives"
16792 (as far as the debugger is concerned). We only have a couple of
16793 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16795 DECL_RTL normally indicates where the parameter lives during most of the
16796 activation of the function. If optimization is enabled however, this
16797 could be either NULL or else a pseudo-reg. Both of those cases indicate
16798 that the parameter doesn't really live anywhere (as far as the code
16799 generation parts of GCC are concerned) during most of the function's
16800 activation. That will happen (for example) if the parameter is never
16801 referenced within the function.
16803 We could just generate a location descriptor here for all non-NULL
16804 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16805 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16806 where DECL_RTL is NULL or is a pseudo-reg.
16808 Note however that we can only get away with using DECL_INCOMING_RTL as
16809 a backup substitute for DECL_RTL in certain limited cases. In cases
16810 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16811 we can be sure that the parameter was passed using the same type as it is
16812 declared to have within the function, and that its DECL_INCOMING_RTL
16813 points us to a place where a value of that type is passed.
16815 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16816 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16817 because in these cases DECL_INCOMING_RTL points us to a value of some
16818 type which is *different* from the type of the parameter itself. Thus,
16819 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16820 such cases, the debugger would end up (for example) trying to fetch a
16821 `float' from a place which actually contains the first part of a
16822 `double'. That would lead to really incorrect and confusing
16823 output at debug-time.
16825 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16826 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16827 are a couple of exceptions however. On little-endian machines we can
16828 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16829 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16830 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16831 when (on a little-endian machine) a non-prototyped function has a
16832 parameter declared to be of type `short' or `char'. In such cases,
16833 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16834 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16835 passed `int' value. If the debugger then uses that address to fetch
16836 a `short' or a `char' (on a little-endian machine) the result will be
16837 the correct data, so we allow for such exceptional cases below.
16839 Note that our goal here is to describe the place where the given formal
16840 parameter lives during most of the function's activation (i.e. between the
16841 end of the prologue and the start of the epilogue). We'll do that as best
16842 as we can. Note however that if the given formal parameter is modified
16843 sometime during the execution of the function, then a stack backtrace (at
16844 debug-time) will show the function as having been called with the *new*
16845 value rather than the value which was originally passed in. This happens
16846 rarely enough that it is not a major problem, but it *is* a problem, and
16847 I'd like to fix it.
16849 A future version of dwarf2out.c may generate two additional attributes for
16850 any given DW_TAG_formal_parameter DIE which will describe the "passed
16851 type" and the "passed location" for the given formal parameter in addition
16852 to the attributes we now generate to indicate the "declared type" and the
16853 "active location" for each parameter. This additional set of attributes
16854 could be used by debuggers for stack backtraces. Separately, note that
16855 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16856 This happens (for example) for inlined-instances of inline function formal
16857 parameters which are never referenced. This really shouldn't be
16858 happening. All PARM_DECL nodes should get valid non-NULL
16859 DECL_INCOMING_RTL values. FIXME. */
16861 /* Use DECL_RTL as the "location" unless we find something better. */
16862 rtl = DECL_RTL_IF_SET (decl);
16864 /* When generating abstract instances, ignore everything except
16865 constants, symbols living in memory, and symbols living in
16866 fixed registers. */
16867 if (! reload_completed)
16870 && (CONSTANT_P (rtl)
16872 && CONSTANT_P (XEXP (rtl, 0)))
16874 && TREE_CODE (decl) == VAR_DECL
16875 && TREE_STATIC (decl))))
16877 rtl = targetm.delegitimize_address (rtl);
16882 else if (TREE_CODE (decl) == PARM_DECL)
16884 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16886 tree declared_type = TREE_TYPE (decl);
16887 tree passed_type = DECL_ARG_TYPE (decl);
16888 enum machine_mode dmode = TYPE_MODE (declared_type);
16889 enum machine_mode pmode = TYPE_MODE (passed_type);
16891 /* This decl represents a formal parameter which was optimized out.
16892 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16893 all cases where (rtl == NULL_RTX) just below. */
16894 if (dmode == pmode)
16895 rtl = DECL_INCOMING_RTL (decl);
16896 else if (SCALAR_INT_MODE_P (dmode)
16897 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16898 && DECL_INCOMING_RTL (decl))
16900 rtx inc = DECL_INCOMING_RTL (decl);
16903 else if (MEM_P (inc))
16905 if (BYTES_BIG_ENDIAN)
16906 rtl = adjust_address_nv (inc, dmode,
16907 GET_MODE_SIZE (pmode)
16908 - GET_MODE_SIZE (dmode));
16915 /* If the parm was passed in registers, but lives on the stack, then
16916 make a big endian correction if the mode of the type of the
16917 parameter is not the same as the mode of the rtl. */
16918 /* ??? This is the same series of checks that are made in dbxout.c before
16919 we reach the big endian correction code there. It isn't clear if all
16920 of these checks are necessary here, but keeping them all is the safe
16922 else if (MEM_P (rtl)
16923 && XEXP (rtl, 0) != const0_rtx
16924 && ! CONSTANT_P (XEXP (rtl, 0))
16925 /* Not passed in memory. */
16926 && !MEM_P (DECL_INCOMING_RTL (decl))
16927 /* Not passed by invisible reference. */
16928 && (!REG_P (XEXP (rtl, 0))
16929 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16930 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16931 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16932 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16935 /* Big endian correction check. */
16936 && BYTES_BIG_ENDIAN
16937 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16938 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16941 int offset = (UNITS_PER_WORD
16942 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16944 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16945 plus_constant (XEXP (rtl, 0), offset));
16948 else if (TREE_CODE (decl) == VAR_DECL
16951 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16952 && BYTES_BIG_ENDIAN)
16954 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16955 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16957 /* If a variable is declared "register" yet is smaller than
16958 a register, then if we store the variable to memory, it
16959 looks like we're storing a register-sized value, when in
16960 fact we are not. We need to adjust the offset of the
16961 storage location to reflect the actual value's bytes,
16962 else gdb will not be able to display it. */
16964 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16965 plus_constant (XEXP (rtl, 0), rsize-dsize));
16968 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16969 and will have been substituted directly into all expressions that use it.
16970 C does not have such a concept, but C++ and other languages do. */
16971 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16972 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16975 rtl = targetm.delegitimize_address (rtl);
16977 /* If we don't look past the constant pool, we risk emitting a
16978 reference to a constant pool entry that isn't referenced from
16979 code, and thus is not emitted. */
16981 rtl = avoid_constant_pool_reference (rtl);
16983 /* Try harder to get a rtl. If this symbol ends up not being emitted
16984 in the current CU, resolve_addr will remove the expression referencing
16986 if (rtl == NULL_RTX
16987 && TREE_CODE (decl) == VAR_DECL
16988 && !DECL_EXTERNAL (decl)
16989 && TREE_STATIC (decl)
16990 && DECL_NAME (decl)
16991 && !DECL_HARD_REGISTER (decl)
16992 && DECL_MODE (decl) != VOIDmode)
16994 rtl = make_decl_rtl_for_debug (decl);
16996 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16997 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
17004 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17005 returned. If so, the decl for the COMMON block is returned, and the
17006 value is the offset into the common block for the symbol. */
17009 fortran_common (tree decl, HOST_WIDE_INT *value)
17011 tree val_expr, cvar;
17012 enum machine_mode mode;
17013 HOST_WIDE_INT bitsize, bitpos;
17015 int volatilep = 0, unsignedp = 0;
17017 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17018 it does not have a value (the offset into the common area), or if it
17019 is thread local (as opposed to global) then it isn't common, and shouldn't
17020 be handled as such. */
17021 if (TREE_CODE (decl) != VAR_DECL
17022 || !TREE_STATIC (decl)
17023 || !DECL_HAS_VALUE_EXPR_P (decl)
17027 val_expr = DECL_VALUE_EXPR (decl);
17028 if (TREE_CODE (val_expr) != COMPONENT_REF)
17031 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
17032 &mode, &unsignedp, &volatilep, true);
17034 if (cvar == NULL_TREE
17035 || TREE_CODE (cvar) != VAR_DECL
17036 || DECL_ARTIFICIAL (cvar)
17037 || !TREE_PUBLIC (cvar))
17041 if (offset != NULL)
17043 if (!host_integerp (offset, 0))
17045 *value = tree_low_cst (offset, 0);
17048 *value += bitpos / BITS_PER_UNIT;
17053 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17054 data attribute for a variable or a parameter. We generate the
17055 DW_AT_const_value attribute only in those cases where the given variable
17056 or parameter does not have a true "location" either in memory or in a
17057 register. This can happen (for example) when a constant is passed as an
17058 actual argument in a call to an inline function. (It's possible that
17059 these things can crop up in other ways also.) Note that one type of
17060 constant value which can be passed into an inlined function is a constant
17061 pointer. This can happen for example if an actual argument in an inlined
17062 function call evaluates to a compile-time constant address. */
17065 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
17066 enum dwarf_attribute attr)
17069 dw_loc_list_ref list;
17070 var_loc_list *loc_list;
17072 if (TREE_CODE (decl) == ERROR_MARK)
17075 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
17076 || TREE_CODE (decl) == RESULT_DECL);
17078 /* Try to get some constant RTL for this decl, and use that as the value of
17081 rtl = rtl_for_decl_location (decl);
17082 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17083 && add_const_value_attribute (die, rtl))
17086 /* See if we have single element location list that is equivalent to
17087 a constant value. That way we are better to use add_const_value_attribute
17088 rather than expanding constant value equivalent. */
17089 loc_list = lookup_decl_loc (decl);
17092 && loc_list->first->next == NULL
17093 && NOTE_P (loc_list->first->loc)
17094 && NOTE_VAR_LOCATION (loc_list->first->loc)
17095 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
17097 struct var_loc_node *node;
17099 node = loc_list->first;
17100 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
17101 if (GET_CODE (rtl) == EXPR_LIST)
17102 rtl = XEXP (rtl, 0);
17103 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
17104 && add_const_value_attribute (die, rtl))
17107 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
17110 add_AT_location_description (die, attr, list);
17113 /* None of that worked, so it must not really have a location;
17114 try adding a constant value attribute from the DECL_INITIAL. */
17115 return tree_add_const_value_attribute_for_decl (die, decl);
17118 /* Add VARIABLE and DIE into deferred locations list. */
17121 defer_location (tree variable, dw_die_ref die)
17123 deferred_locations entry;
17124 entry.variable = variable;
17126 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
17129 /* Helper function for tree_add_const_value_attribute. Natively encode
17130 initializer INIT into an array. Return true if successful. */
17133 native_encode_initializer (tree init, unsigned char *array, int size)
17137 if (init == NULL_TREE)
17141 switch (TREE_CODE (init))
17144 type = TREE_TYPE (init);
17145 if (TREE_CODE (type) == ARRAY_TYPE)
17147 tree enttype = TREE_TYPE (type);
17148 enum machine_mode mode = TYPE_MODE (enttype);
17150 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
17152 if (int_size_in_bytes (type) != size)
17154 if (size > TREE_STRING_LENGTH (init))
17156 memcpy (array, TREE_STRING_POINTER (init),
17157 TREE_STRING_LENGTH (init));
17158 memset (array + TREE_STRING_LENGTH (init),
17159 '\0', size - TREE_STRING_LENGTH (init));
17162 memcpy (array, TREE_STRING_POINTER (init), size);
17167 type = TREE_TYPE (init);
17168 if (int_size_in_bytes (type) != size)
17170 if (TREE_CODE (type) == ARRAY_TYPE)
17172 HOST_WIDE_INT min_index;
17173 unsigned HOST_WIDE_INT cnt;
17174 int curpos = 0, fieldsize;
17175 constructor_elt *ce;
17177 if (TYPE_DOMAIN (type) == NULL_TREE
17178 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17181 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17182 if (fieldsize <= 0)
17185 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17186 memset (array, '\0', size);
17187 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17189 tree val = ce->value;
17190 tree index = ce->index;
17192 if (index && TREE_CODE (index) == RANGE_EXPR)
17193 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17196 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17201 if (!native_encode_initializer (val, array + pos, fieldsize))
17204 curpos = pos + fieldsize;
17205 if (index && TREE_CODE (index) == RANGE_EXPR)
17207 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17208 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17212 memcpy (array + curpos, array + pos, fieldsize);
17213 curpos += fieldsize;
17216 gcc_assert (curpos <= size);
17220 else if (TREE_CODE (type) == RECORD_TYPE
17221 || TREE_CODE (type) == UNION_TYPE)
17223 tree field = NULL_TREE;
17224 unsigned HOST_WIDE_INT cnt;
17225 constructor_elt *ce;
17227 if (int_size_in_bytes (type) != size)
17230 if (TREE_CODE (type) == RECORD_TYPE)
17231 field = TYPE_FIELDS (type);
17233 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17235 tree val = ce->value;
17236 int pos, fieldsize;
17238 if (ce->index != 0)
17244 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17247 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17248 && TYPE_DOMAIN (TREE_TYPE (field))
17249 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17251 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17252 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17254 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17255 pos = int_byte_position (field);
17256 gcc_assert (pos + fieldsize <= size);
17258 && !native_encode_initializer (val, array + pos, fieldsize))
17264 case VIEW_CONVERT_EXPR:
17265 case NON_LVALUE_EXPR:
17266 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17268 return native_encode_expr (init, array, size) == size;
17272 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17273 attribute is the const value T. */
17276 tree_add_const_value_attribute (dw_die_ref die, tree t)
17279 tree type = TREE_TYPE (t);
17282 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17286 gcc_assert (!DECL_P (init));
17288 rtl = rtl_for_decl_init (init, type);
17290 return add_const_value_attribute (die, rtl);
17291 /* If the host and target are sane, try harder. */
17292 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17293 && initializer_constant_valid_p (init, type))
17295 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17296 if (size > 0 && (int) size == size)
17298 unsigned char *array = (unsigned char *)
17299 ggc_alloc_cleared_atomic (size);
17301 if (native_encode_initializer (init, array, size))
17303 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17311 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17312 attribute is the const value of T, where T is an integral constant
17313 variable with static storage duration
17314 (so it can't be a PARM_DECL or a RESULT_DECL). */
17317 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17321 || (TREE_CODE (decl) != VAR_DECL
17322 && TREE_CODE (decl) != CONST_DECL))
17325 if (TREE_READONLY (decl)
17326 && ! TREE_THIS_VOLATILE (decl)
17327 && DECL_INITIAL (decl))
17332 /* Don't add DW_AT_const_value if abstract origin already has one. */
17333 if (get_AT (var_die, DW_AT_const_value))
17336 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17339 /* Convert the CFI instructions for the current function into a
17340 location list. This is used for DW_AT_frame_base when we targeting
17341 a dwarf2 consumer that does not support the dwarf3
17342 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17345 static dw_loc_list_ref
17346 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17349 dw_loc_list_ref list, *list_tail;
17351 dw_cfa_location last_cfa, next_cfa;
17352 const char *start_label, *last_label, *section;
17353 dw_cfa_location remember;
17355 fde = current_fde ();
17356 gcc_assert (fde != NULL);
17358 section = secname_for_decl (current_function_decl);
17362 memset (&next_cfa, 0, sizeof (next_cfa));
17363 next_cfa.reg = INVALID_REGNUM;
17364 remember = next_cfa;
17366 start_label = fde->dw_fde_begin;
17368 /* ??? Bald assumption that the CIE opcode list does not contain
17369 advance opcodes. */
17370 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17371 lookup_cfa_1 (cfi, &next_cfa, &remember);
17373 last_cfa = next_cfa;
17374 last_label = start_label;
17376 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17377 switch (cfi->dw_cfi_opc)
17379 case DW_CFA_set_loc:
17380 case DW_CFA_advance_loc1:
17381 case DW_CFA_advance_loc2:
17382 case DW_CFA_advance_loc4:
17383 if (!cfa_equal_p (&last_cfa, &next_cfa))
17385 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17386 start_label, last_label, section);
17388 list_tail = &(*list_tail)->dw_loc_next;
17389 last_cfa = next_cfa;
17390 start_label = last_label;
17392 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17395 case DW_CFA_advance_loc:
17396 /* The encoding is complex enough that we should never emit this. */
17397 gcc_unreachable ();
17400 lookup_cfa_1 (cfi, &next_cfa, &remember);
17404 if (!cfa_equal_p (&last_cfa, &next_cfa))
17406 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17407 start_label, last_label, section);
17408 list_tail = &(*list_tail)->dw_loc_next;
17409 start_label = last_label;
17412 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17413 start_label, fde->dw_fde_end, section);
17415 if (list && list->dw_loc_next)
17421 /* Compute a displacement from the "steady-state frame pointer" to the
17422 frame base (often the same as the CFA), and store it in
17423 frame_pointer_fb_offset. OFFSET is added to the displacement
17424 before the latter is negated. */
17427 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17431 #ifdef FRAME_POINTER_CFA_OFFSET
17432 reg = frame_pointer_rtx;
17433 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17435 reg = arg_pointer_rtx;
17436 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17439 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17440 if (GET_CODE (elim) == PLUS)
17442 offset += INTVAL (XEXP (elim, 1));
17443 elim = XEXP (elim, 0);
17446 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17447 && (elim == hard_frame_pointer_rtx
17448 || elim == stack_pointer_rtx))
17449 || elim == (frame_pointer_needed
17450 ? hard_frame_pointer_rtx
17451 : stack_pointer_rtx));
17453 frame_pointer_fb_offset = -offset;
17456 /* Generate a DW_AT_name attribute given some string value to be included as
17457 the value of the attribute. */
17460 add_name_attribute (dw_die_ref die, const char *name_string)
17462 if (name_string != NULL && *name_string != 0)
17464 if (demangle_name_func)
17465 name_string = (*demangle_name_func) (name_string);
17467 add_AT_string (die, DW_AT_name, name_string);
17471 /* Generate a DW_AT_comp_dir attribute for DIE. */
17474 add_comp_dir_attribute (dw_die_ref die)
17476 const char *wd = get_src_pwd ();
17482 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17486 wdlen = strlen (wd);
17487 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17489 wd1 [wdlen] = DIR_SEPARATOR;
17490 wd1 [wdlen + 1] = 0;
17494 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17497 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17501 lower_bound_default (void)
17503 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17508 case DW_LANG_C_plus_plus:
17510 case DW_LANG_ObjC_plus_plus:
17513 case DW_LANG_Fortran77:
17514 case DW_LANG_Fortran90:
17515 case DW_LANG_Fortran95:
17519 case DW_LANG_Python:
17520 return dwarf_version >= 4 ? 0 : -1;
17521 case DW_LANG_Ada95:
17522 case DW_LANG_Ada83:
17523 case DW_LANG_Cobol74:
17524 case DW_LANG_Cobol85:
17525 case DW_LANG_Pascal83:
17526 case DW_LANG_Modula2:
17528 return dwarf_version >= 4 ? 1 : -1;
17534 /* Given a tree node describing an array bound (either lower or upper) output
17535 a representation for that bound. */
17538 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17540 switch (TREE_CODE (bound))
17545 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17548 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17551 /* Use the default if possible. */
17552 if (bound_attr == DW_AT_lower_bound
17553 && host_integerp (bound, 0)
17554 && (dflt = lower_bound_default ()) != -1
17555 && tree_low_cst (bound, 0) == dflt)
17558 /* Otherwise represent the bound as an unsigned value with the
17559 precision of its type. The precision and signedness of the
17560 type will be necessary to re-interpret it unambiguously. */
17561 else if (prec < HOST_BITS_PER_WIDE_INT)
17563 unsigned HOST_WIDE_INT mask
17564 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17565 add_AT_unsigned (subrange_die, bound_attr,
17566 TREE_INT_CST_LOW (bound) & mask);
17568 else if (prec == HOST_BITS_PER_WIDE_INT
17569 || TREE_INT_CST_HIGH (bound) == 0)
17570 add_AT_unsigned (subrange_die, bound_attr,
17571 TREE_INT_CST_LOW (bound));
17573 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17574 TREE_INT_CST_LOW (bound));
17579 case VIEW_CONVERT_EXPR:
17580 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17590 dw_die_ref decl_die = lookup_decl_die (bound);
17592 /* ??? Can this happen, or should the variable have been bound
17593 first? Probably it can, since I imagine that we try to create
17594 the types of parameters in the order in which they exist in
17595 the list, and won't have created a forward reference to a
17596 later parameter. */
17597 if (decl_die != NULL)
17599 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17607 /* Otherwise try to create a stack operation procedure to
17608 evaluate the value of the array bound. */
17610 dw_die_ref ctx, decl_die;
17611 dw_loc_list_ref list;
17613 list = loc_list_from_tree (bound, 2);
17614 if (list == NULL || single_element_loc_list_p (list))
17616 /* If DW_AT_*bound is not a reference nor constant, it is
17617 a DWARF expression rather than location description.
17618 For that loc_list_from_tree (bound, 0) is needed.
17619 If that fails to give a single element list,
17620 fall back to outputting this as a reference anyway. */
17621 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17622 if (list2 && single_element_loc_list_p (list2))
17624 add_AT_loc (subrange_die, bound_attr, list2->expr);
17631 if (current_function_decl == 0)
17632 ctx = comp_unit_die ();
17634 ctx = lookup_decl_die (current_function_decl);
17636 decl_die = new_die (DW_TAG_variable, ctx, bound);
17637 add_AT_flag (decl_die, DW_AT_artificial, 1);
17638 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17639 add_AT_location_description (decl_die, DW_AT_location, list);
17640 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17646 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17647 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17648 Note that the block of subscript information for an array type also
17649 includes information about the element type of the given array type. */
17652 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17654 unsigned dimension_number;
17656 dw_die_ref subrange_die;
17658 for (dimension_number = 0;
17659 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17660 type = TREE_TYPE (type), dimension_number++)
17662 tree domain = TYPE_DOMAIN (type);
17664 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17667 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17668 and (in GNU C only) variable bounds. Handle all three forms
17670 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17673 /* We have an array type with specified bounds. */
17674 lower = TYPE_MIN_VALUE (domain);
17675 upper = TYPE_MAX_VALUE (domain);
17677 /* Define the index type. */
17678 if (TREE_TYPE (domain))
17680 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17681 TREE_TYPE field. We can't emit debug info for this
17682 because it is an unnamed integral type. */
17683 if (TREE_CODE (domain) == INTEGER_TYPE
17684 && TYPE_NAME (domain) == NULL_TREE
17685 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17686 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17689 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17693 /* ??? If upper is NULL, the array has unspecified length,
17694 but it does have a lower bound. This happens with Fortran
17696 Since the debugger is definitely going to need to know N
17697 to produce useful results, go ahead and output the lower
17698 bound solo, and hope the debugger can cope. */
17700 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17702 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17705 /* Otherwise we have an array type with an unspecified length. The
17706 DWARF-2 spec does not say how to handle this; let's just leave out the
17712 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17716 switch (TREE_CODE (tree_node))
17721 case ENUMERAL_TYPE:
17724 case QUAL_UNION_TYPE:
17725 size = int_size_in_bytes (tree_node);
17728 /* For a data member of a struct or union, the DW_AT_byte_size is
17729 generally given as the number of bytes normally allocated for an
17730 object of the *declared* type of the member itself. This is true
17731 even for bit-fields. */
17732 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17735 gcc_unreachable ();
17738 /* Note that `size' might be -1 when we get to this point. If it is, that
17739 indicates that the byte size of the entity in question is variable. We
17740 have no good way of expressing this fact in Dwarf at the present time,
17741 so just let the -1 pass on through. */
17742 add_AT_unsigned (die, DW_AT_byte_size, size);
17745 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17746 which specifies the distance in bits from the highest order bit of the
17747 "containing object" for the bit-field to the highest order bit of the
17750 For any given bit-field, the "containing object" is a hypothetical object
17751 (of some integral or enum type) within which the given bit-field lives. The
17752 type of this hypothetical "containing object" is always the same as the
17753 declared type of the individual bit-field itself. The determination of the
17754 exact location of the "containing object" for a bit-field is rather
17755 complicated. It's handled by the `field_byte_offset' function (above).
17757 Note that it is the size (in bytes) of the hypothetical "containing object"
17758 which will be given in the DW_AT_byte_size attribute for this bit-field.
17759 (See `byte_size_attribute' above). */
17762 add_bit_offset_attribute (dw_die_ref die, tree decl)
17764 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17765 tree type = DECL_BIT_FIELD_TYPE (decl);
17766 HOST_WIDE_INT bitpos_int;
17767 HOST_WIDE_INT highest_order_object_bit_offset;
17768 HOST_WIDE_INT highest_order_field_bit_offset;
17769 HOST_WIDE_INT bit_offset;
17771 /* Must be a field and a bit field. */
17772 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17774 /* We can't yet handle bit-fields whose offsets are variable, so if we
17775 encounter such things, just return without generating any attribute
17776 whatsoever. Likewise for variable or too large size. */
17777 if (! host_integerp (bit_position (decl), 0)
17778 || ! host_integerp (DECL_SIZE (decl), 1))
17781 bitpos_int = int_bit_position (decl);
17783 /* Note that the bit offset is always the distance (in bits) from the
17784 highest-order bit of the "containing object" to the highest-order bit of
17785 the bit-field itself. Since the "high-order end" of any object or field
17786 is different on big-endian and little-endian machines, the computation
17787 below must take account of these differences. */
17788 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17789 highest_order_field_bit_offset = bitpos_int;
17791 if (! BYTES_BIG_ENDIAN)
17793 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17794 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17798 = (! BYTES_BIG_ENDIAN
17799 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17800 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17802 if (bit_offset < 0)
17803 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17805 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17808 /* For a FIELD_DECL node which represents a bit field, output an attribute
17809 which specifies the length in bits of the given field. */
17812 add_bit_size_attribute (dw_die_ref die, tree decl)
17814 /* Must be a field and a bit field. */
17815 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17816 && DECL_BIT_FIELD_TYPE (decl));
17818 if (host_integerp (DECL_SIZE (decl), 1))
17819 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17822 /* If the compiled language is ANSI C, then add a 'prototyped'
17823 attribute, if arg types are given for the parameters of a function. */
17826 add_prototyped_attribute (dw_die_ref die, tree func_type)
17828 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17829 && prototype_p (func_type))
17830 add_AT_flag (die, DW_AT_prototyped, 1);
17833 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17834 by looking in either the type declaration or object declaration
17837 static inline dw_die_ref
17838 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17840 dw_die_ref origin_die = NULL;
17842 if (TREE_CODE (origin) != FUNCTION_DECL)
17844 /* We may have gotten separated from the block for the inlined
17845 function, if we're in an exception handler or some such; make
17846 sure that the abstract function has been written out.
17848 Doing this for nested functions is wrong, however; functions are
17849 distinct units, and our context might not even be inline. */
17853 fn = TYPE_STUB_DECL (fn);
17855 fn = decl_function_context (fn);
17857 dwarf2out_abstract_function (fn);
17860 if (DECL_P (origin))
17861 origin_die = lookup_decl_die (origin);
17862 else if (TYPE_P (origin))
17863 origin_die = lookup_type_die (origin);
17865 /* XXX: Functions that are never lowered don't always have correct block
17866 trees (in the case of java, they simply have no block tree, in some other
17867 languages). For these functions, there is nothing we can really do to
17868 output correct debug info for inlined functions in all cases. Rather
17869 than die, we'll just produce deficient debug info now, in that we will
17870 have variables without a proper abstract origin. In the future, when all
17871 functions are lowered, we should re-add a gcc_assert (origin_die)
17875 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17879 /* We do not currently support the pure_virtual attribute. */
17882 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17884 if (DECL_VINDEX (func_decl))
17886 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17888 if (host_integerp (DECL_VINDEX (func_decl), 0))
17889 add_AT_loc (die, DW_AT_vtable_elem_location,
17890 new_loc_descr (DW_OP_constu,
17891 tree_low_cst (DECL_VINDEX (func_decl), 0),
17894 /* GNU extension: Record what type this method came from originally. */
17895 if (debug_info_level > DINFO_LEVEL_TERSE
17896 && DECL_CONTEXT (func_decl))
17897 add_AT_die_ref (die, DW_AT_containing_type,
17898 lookup_type_die (DECL_CONTEXT (func_decl)));
17902 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17903 given decl. This used to be a vendor extension until after DWARF 4
17904 standardized it. */
17907 add_linkage_attr (dw_die_ref die, tree decl)
17909 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17911 /* Mimic what assemble_name_raw does with a leading '*'. */
17912 if (name[0] == '*')
17915 if (dwarf_version >= 4)
17916 add_AT_string (die, DW_AT_linkage_name, name);
17918 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17921 /* Add source coordinate attributes for the given decl. */
17924 add_src_coords_attributes (dw_die_ref die, tree decl)
17926 expanded_location s;
17928 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
17930 s = expand_location (DECL_SOURCE_LOCATION (decl));
17931 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17932 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17935 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17938 add_linkage_name (dw_die_ref die, tree decl)
17940 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17941 && TREE_PUBLIC (decl)
17942 && !DECL_ABSTRACT (decl)
17943 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17944 && die->die_tag != DW_TAG_member)
17946 /* Defer until we have an assembler name set. */
17947 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17949 limbo_die_node *asm_name;
17951 asm_name = ggc_alloc_cleared_limbo_die_node ();
17952 asm_name->die = die;
17953 asm_name->created_for = decl;
17954 asm_name->next = deferred_asm_name;
17955 deferred_asm_name = asm_name;
17957 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17958 add_linkage_attr (die, decl);
17962 /* Add a DW_AT_name attribute and source coordinate attribute for the
17963 given decl, but only if it actually has a name. */
17966 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17970 decl_name = DECL_NAME (decl);
17971 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17973 const char *name = dwarf2_name (decl, 0);
17975 add_name_attribute (die, name);
17976 if (! DECL_ARTIFICIAL (decl))
17977 add_src_coords_attributes (die, decl);
17979 add_linkage_name (die, decl);
17982 #ifdef VMS_DEBUGGING_INFO
17983 /* Get the function's name, as described by its RTL. This may be different
17984 from the DECL_NAME name used in the source file. */
17985 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17987 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17988 XEXP (DECL_RTL (decl), 0));
17989 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17991 #endif /* VMS_DEBUGGING_INFO */
17994 #ifdef VMS_DEBUGGING_INFO
17995 /* Output the debug main pointer die for VMS */
17998 dwarf2out_vms_debug_main_pointer (void)
18000 char label[MAX_ARTIFICIAL_LABEL_BYTES];
18003 /* Allocate the VMS debug main subprogram die. */
18004 die = ggc_alloc_cleared_die_node ();
18005 die->die_tag = DW_TAG_subprogram;
18006 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
18007 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
18008 current_function_funcdef_no);
18009 add_AT_lbl_id (die, DW_AT_entry_pc, label);
18011 /* Make it the first child of comp_unit_die (). */
18012 die->die_parent = comp_unit_die ();
18013 if (comp_unit_die ()->die_child)
18015 die->die_sib = comp_unit_die ()->die_child->die_sib;
18016 comp_unit_die ()->die_child->die_sib = die;
18020 die->die_sib = die;
18021 comp_unit_die ()->die_child = die;
18024 #endif /* VMS_DEBUGGING_INFO */
18026 /* Push a new declaration scope. */
18029 push_decl_scope (tree scope)
18031 VEC_safe_push (tree, gc, decl_scope_table, scope);
18034 /* Pop a declaration scope. */
18037 pop_decl_scope (void)
18039 VEC_pop (tree, decl_scope_table);
18042 /* Return the DIE for the scope that immediately contains this type.
18043 Non-named types get global scope. Named types nested in other
18044 types get their containing scope if it's open, or global scope
18045 otherwise. All other types (i.e. function-local named types) get
18046 the current active scope. */
18049 scope_die_for (tree t, dw_die_ref context_die)
18051 dw_die_ref scope_die = NULL;
18052 tree containing_scope;
18055 /* Non-types always go in the current scope. */
18056 gcc_assert (TYPE_P (t));
18058 containing_scope = TYPE_CONTEXT (t);
18060 /* Use the containing namespace if it was passed in (for a declaration). */
18061 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
18063 if (context_die == lookup_decl_die (containing_scope))
18066 containing_scope = NULL_TREE;
18069 /* Ignore function type "scopes" from the C frontend. They mean that
18070 a tagged type is local to a parmlist of a function declarator, but
18071 that isn't useful to DWARF. */
18072 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
18073 containing_scope = NULL_TREE;
18075 if (SCOPE_FILE_SCOPE_P (containing_scope))
18076 scope_die = comp_unit_die ();
18077 else if (TYPE_P (containing_scope))
18079 /* For types, we can just look up the appropriate DIE. But
18080 first we check to see if we're in the middle of emitting it
18081 so we know where the new DIE should go. */
18082 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
18083 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
18088 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
18089 || TREE_ASM_WRITTEN (containing_scope));
18090 /*We are not in the middle of emitting the type
18091 CONTAINING_SCOPE. Let's see if it's emitted already. */
18092 scope_die = lookup_type_die (containing_scope);
18094 /* If none of the current dies are suitable, we get file scope. */
18095 if (scope_die == NULL)
18096 scope_die = comp_unit_die ();
18099 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
18102 scope_die = context_die;
18107 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18110 local_scope_p (dw_die_ref context_die)
18112 for (; context_die; context_die = context_die->die_parent)
18113 if (context_die->die_tag == DW_TAG_inlined_subroutine
18114 || context_die->die_tag == DW_TAG_subprogram)
18120 /* Returns nonzero if CONTEXT_DIE is a class. */
18123 class_scope_p (dw_die_ref context_die)
18125 return (context_die
18126 && (context_die->die_tag == DW_TAG_structure_type
18127 || context_die->die_tag == DW_TAG_class_type
18128 || context_die->die_tag == DW_TAG_interface_type
18129 || context_die->die_tag == DW_TAG_union_type));
18132 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18133 whether or not to treat a DIE in this context as a declaration. */
18136 class_or_namespace_scope_p (dw_die_ref context_die)
18138 return (class_scope_p (context_die)
18139 || (context_die && context_die->die_tag == DW_TAG_namespace));
18142 /* Many forms of DIEs require a "type description" attribute. This
18143 routine locates the proper "type descriptor" die for the type given
18144 by 'type', and adds a DW_AT_type attribute below the given die. */
18147 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
18148 int decl_volatile, dw_die_ref context_die)
18150 enum tree_code code = TREE_CODE (type);
18151 dw_die_ref type_die = NULL;
18153 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18154 or fixed-point type, use the inner type. This is because we have no
18155 support for unnamed types in base_type_die. This can happen if this is
18156 an Ada subrange type. Correct solution is emit a subrange type die. */
18157 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18158 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18159 type = TREE_TYPE (type), code = TREE_CODE (type);
18161 if (code == ERROR_MARK
18162 /* Handle a special case. For functions whose return type is void, we
18163 generate *no* type attribute. (Note that no object may have type
18164 `void', so this only applies to function return types). */
18165 || code == VOID_TYPE)
18168 type_die = modified_type_die (type,
18169 decl_const || TYPE_READONLY (type),
18170 decl_volatile || TYPE_VOLATILE (type),
18173 if (type_die != NULL)
18174 add_AT_die_ref (object_die, DW_AT_type, type_die);
18177 /* Given an object die, add the calling convention attribute for the
18178 function call type. */
18180 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18182 enum dwarf_calling_convention value = DW_CC_normal;
18184 value = ((enum dwarf_calling_convention)
18185 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18188 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18190 /* DWARF 2 doesn't provide a way to identify a program's source-level
18191 entry point. DW_AT_calling_convention attributes are only meant
18192 to describe functions' calling conventions. However, lacking a
18193 better way to signal the Fortran main program, we used this for
18194 a long time, following existing custom. Now, DWARF 4 has
18195 DW_AT_main_subprogram, which we add below, but some tools still
18196 rely on the old way, which we thus keep. */
18197 value = DW_CC_program;
18199 if (dwarf_version >= 4 || !dwarf_strict)
18200 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18203 /* Only add the attribute if the backend requests it, and
18204 is not DW_CC_normal. */
18205 if (value && (value != DW_CC_normal))
18206 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18209 /* Given a tree pointer to a struct, class, union, or enum type node, return
18210 a pointer to the (string) tag name for the given type, or zero if the type
18211 was declared without a tag. */
18213 static const char *
18214 type_tag (const_tree type)
18216 const char *name = 0;
18218 if (TYPE_NAME (type) != 0)
18222 /* Find the IDENTIFIER_NODE for the type name. */
18223 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18224 && !TYPE_NAMELESS (type))
18225 t = TYPE_NAME (type);
18227 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18228 a TYPE_DECL node, regardless of whether or not a `typedef' was
18230 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18231 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18233 /* We want to be extra verbose. Don't call dwarf_name if
18234 DECL_NAME isn't set. The default hook for decl_printable_name
18235 doesn't like that, and in this context it's correct to return
18236 0, instead of "<anonymous>" or the like. */
18237 if (DECL_NAME (TYPE_NAME (type))
18238 && !DECL_NAMELESS (TYPE_NAME (type)))
18239 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18242 /* Now get the name as a string, or invent one. */
18243 if (!name && t != 0)
18244 name = IDENTIFIER_POINTER (t);
18247 return (name == 0 || *name == '\0') ? 0 : name;
18250 /* Return the type associated with a data member, make a special check
18251 for bit field types. */
18254 member_declared_type (const_tree member)
18256 return (DECL_BIT_FIELD_TYPE (member)
18257 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18260 /* Get the decl's label, as described by its RTL. This may be different
18261 from the DECL_NAME name used in the source file. */
18264 static const char *
18265 decl_start_label (tree decl)
18268 const char *fnname;
18270 x = DECL_RTL (decl);
18271 gcc_assert (MEM_P (x));
18274 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18276 fnname = XSTR (x, 0);
18281 /* These routines generate the internal representation of the DIE's for
18282 the compilation unit. Debugging information is collected by walking
18283 the declaration trees passed in from dwarf2out_decl(). */
18286 gen_array_type_die (tree type, dw_die_ref context_die)
18288 dw_die_ref scope_die = scope_die_for (type, context_die);
18289 dw_die_ref array_die;
18291 /* GNU compilers represent multidimensional array types as sequences of one
18292 dimensional array types whose element types are themselves array types.
18293 We sometimes squish that down to a single array_type DIE with multiple
18294 subscripts in the Dwarf debugging info. The draft Dwarf specification
18295 say that we are allowed to do this kind of compression in C, because
18296 there is no difference between an array of arrays and a multidimensional
18297 array. We don't do this for Ada to remain as close as possible to the
18298 actual representation, which is especially important against the language
18299 flexibilty wrt arrays of variable size. */
18301 bool collapse_nested_arrays = !is_ada ();
18304 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18305 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18306 if (TYPE_STRING_FLAG (type)
18307 && TREE_CODE (type) == ARRAY_TYPE
18309 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18311 HOST_WIDE_INT size;
18313 array_die = new_die (DW_TAG_string_type, scope_die, type);
18314 add_name_attribute (array_die, type_tag (type));
18315 equate_type_number_to_die (type, array_die);
18316 size = int_size_in_bytes (type);
18318 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18319 else if (TYPE_DOMAIN (type) != NULL_TREE
18320 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18321 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18323 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18324 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18326 size = int_size_in_bytes (TREE_TYPE (szdecl));
18327 if (loc && size > 0)
18329 add_AT_location_description (array_die, DW_AT_string_length, loc);
18330 if (size != DWARF2_ADDR_SIZE)
18331 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18337 /* ??? The SGI dwarf reader fails for array of array of enum types
18338 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18339 array type comes before the outer array type. We thus call gen_type_die
18340 before we new_die and must prevent nested array types collapsing for this
18343 #ifdef MIPS_DEBUGGING_INFO
18344 gen_type_die (TREE_TYPE (type), context_die);
18345 collapse_nested_arrays = false;
18348 array_die = new_die (DW_TAG_array_type, scope_die, type);
18349 add_name_attribute (array_die, type_tag (type));
18350 equate_type_number_to_die (type, array_die);
18352 if (TREE_CODE (type) == VECTOR_TYPE)
18353 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18355 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18357 && TREE_CODE (type) == ARRAY_TYPE
18358 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18359 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18360 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18363 /* We default the array ordering. SDB will probably do
18364 the right things even if DW_AT_ordering is not present. It's not even
18365 an issue until we start to get into multidimensional arrays anyway. If
18366 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18367 then we'll have to put the DW_AT_ordering attribute back in. (But if
18368 and when we find out that we need to put these in, we will only do so
18369 for multidimensional arrays. */
18370 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18373 #ifdef MIPS_DEBUGGING_INFO
18374 /* The SGI compilers handle arrays of unknown bound by setting
18375 AT_declaration and not emitting any subrange DIEs. */
18376 if (TREE_CODE (type) == ARRAY_TYPE
18377 && ! TYPE_DOMAIN (type))
18378 add_AT_flag (array_die, DW_AT_declaration, 1);
18381 if (TREE_CODE (type) == VECTOR_TYPE)
18383 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18384 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18385 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18386 add_bound_info (subrange_die, DW_AT_upper_bound,
18387 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18390 add_subscript_info (array_die, type, collapse_nested_arrays);
18392 /* Add representation of the type of the elements of this array type and
18393 emit the corresponding DIE if we haven't done it already. */
18394 element_type = TREE_TYPE (type);
18395 if (collapse_nested_arrays)
18396 while (TREE_CODE (element_type) == ARRAY_TYPE)
18398 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18400 element_type = TREE_TYPE (element_type);
18403 #ifndef MIPS_DEBUGGING_INFO
18404 gen_type_die (element_type, context_die);
18407 add_type_attribute (array_die, element_type, 0, 0, context_die);
18409 if (get_AT (array_die, DW_AT_name))
18410 add_pubtype (type, array_die);
18413 static dw_loc_descr_ref
18414 descr_info_loc (tree val, tree base_decl)
18416 HOST_WIDE_INT size;
18417 dw_loc_descr_ref loc, loc2;
18418 enum dwarf_location_atom op;
18420 if (val == base_decl)
18421 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18423 switch (TREE_CODE (val))
18426 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18428 return loc_descriptor_from_tree (val, 0);
18430 if (host_integerp (val, 0))
18431 return int_loc_descriptor (tree_low_cst (val, 0));
18434 size = int_size_in_bytes (TREE_TYPE (val));
18437 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18440 if (size == DWARF2_ADDR_SIZE)
18441 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18443 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18445 case POINTER_PLUS_EXPR:
18447 if (host_integerp (TREE_OPERAND (val, 1), 1)
18448 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18451 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18454 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18460 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18463 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18466 add_loc_descr (&loc, loc2);
18467 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18489 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18490 tree val, tree base_decl)
18492 dw_loc_descr_ref loc;
18494 if (host_integerp (val, 0))
18496 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18500 loc = descr_info_loc (val, base_decl);
18504 add_AT_loc (die, attr, loc);
18507 /* This routine generates DIE for array with hidden descriptor, details
18508 are filled into *info by a langhook. */
18511 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18512 dw_die_ref context_die)
18514 dw_die_ref scope_die = scope_die_for (type, context_die);
18515 dw_die_ref array_die;
18518 array_die = new_die (DW_TAG_array_type, scope_die, type);
18519 add_name_attribute (array_die, type_tag (type));
18520 equate_type_number_to_die (type, array_die);
18522 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18524 && info->ndimensions >= 2)
18525 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18527 if (info->data_location)
18528 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18530 if (info->associated)
18531 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18533 if (info->allocated)
18534 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18537 for (dim = 0; dim < info->ndimensions; dim++)
18539 dw_die_ref subrange_die
18540 = new_die (DW_TAG_subrange_type, array_die, NULL);
18542 if (info->dimen[dim].lower_bound)
18544 /* If it is the default value, omit it. */
18547 if (host_integerp (info->dimen[dim].lower_bound, 0)
18548 && (dflt = lower_bound_default ()) != -1
18549 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18552 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18553 info->dimen[dim].lower_bound,
18556 if (info->dimen[dim].upper_bound)
18557 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18558 info->dimen[dim].upper_bound,
18560 if (info->dimen[dim].stride)
18561 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18562 info->dimen[dim].stride,
18566 gen_type_die (info->element_type, context_die);
18567 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18569 if (get_AT (array_die, DW_AT_name))
18570 add_pubtype (type, array_die);
18575 gen_entry_point_die (tree decl, dw_die_ref context_die)
18577 tree origin = decl_ultimate_origin (decl);
18578 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18580 if (origin != NULL)
18581 add_abstract_origin_attribute (decl_die, origin);
18584 add_name_and_src_coords_attributes (decl_die, decl);
18585 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18586 0, 0, context_die);
18589 if (DECL_ABSTRACT (decl))
18590 equate_decl_number_to_die (decl, decl_die);
18592 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18596 /* Walk through the list of incomplete types again, trying once more to
18597 emit full debugging info for them. */
18600 retry_incomplete_types (void)
18604 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18605 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18606 DINFO_USAGE_DIR_USE))
18607 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18610 /* Determine what tag to use for a record type. */
18612 static enum dwarf_tag
18613 record_type_tag (tree type)
18615 if (! lang_hooks.types.classify_record)
18616 return DW_TAG_structure_type;
18618 switch (lang_hooks.types.classify_record (type))
18620 case RECORD_IS_STRUCT:
18621 return DW_TAG_structure_type;
18623 case RECORD_IS_CLASS:
18624 return DW_TAG_class_type;
18626 case RECORD_IS_INTERFACE:
18627 if (dwarf_version >= 3 || !dwarf_strict)
18628 return DW_TAG_interface_type;
18629 return DW_TAG_structure_type;
18632 gcc_unreachable ();
18636 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18637 include all of the information about the enumeration values also. Each
18638 enumerated type name/value is listed as a child of the enumerated type
18642 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18644 dw_die_ref type_die = lookup_type_die (type);
18646 if (type_die == NULL)
18648 type_die = new_die (DW_TAG_enumeration_type,
18649 scope_die_for (type, context_die), type);
18650 equate_type_number_to_die (type, type_die);
18651 add_name_attribute (type_die, type_tag (type));
18652 if (dwarf_version >= 4 || !dwarf_strict)
18654 if (ENUM_IS_SCOPED (type))
18655 add_AT_flag (type_die, DW_AT_enum_class, 1);
18656 if (ENUM_IS_OPAQUE (type))
18657 add_AT_flag (type_die, DW_AT_declaration, 1);
18660 else if (! TYPE_SIZE (type))
18663 remove_AT (type_die, DW_AT_declaration);
18665 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18666 given enum type is incomplete, do not generate the DW_AT_byte_size
18667 attribute or the DW_AT_element_list attribute. */
18668 if (TYPE_SIZE (type))
18672 TREE_ASM_WRITTEN (type) = 1;
18673 add_byte_size_attribute (type_die, type);
18674 if (TYPE_STUB_DECL (type) != NULL_TREE)
18676 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18677 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18680 /* If the first reference to this type was as the return type of an
18681 inline function, then it may not have a parent. Fix this now. */
18682 if (type_die->die_parent == NULL)
18683 add_child_die (scope_die_for (type, context_die), type_die);
18685 for (link = TYPE_VALUES (type);
18686 link != NULL; link = TREE_CHAIN (link))
18688 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18689 tree value = TREE_VALUE (link);
18691 add_name_attribute (enum_die,
18692 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18694 if (TREE_CODE (value) == CONST_DECL)
18695 value = DECL_INITIAL (value);
18697 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18698 /* DWARF2 does not provide a way of indicating whether or
18699 not enumeration constants are signed or unsigned. GDB
18700 always assumes the values are signed, so we output all
18701 values as if they were signed. That means that
18702 enumeration constants with very large unsigned values
18703 will appear to have negative values in the debugger. */
18704 add_AT_int (enum_die, DW_AT_const_value,
18705 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18709 add_AT_flag (type_die, DW_AT_declaration, 1);
18711 if (get_AT (type_die, DW_AT_name))
18712 add_pubtype (type, type_die);
18717 /* Generate a DIE to represent either a real live formal parameter decl or to
18718 represent just the type of some formal parameter position in some function
18721 Note that this routine is a bit unusual because its argument may be a
18722 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18723 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18724 node. If it's the former then this function is being called to output a
18725 DIE to represent a formal parameter object (or some inlining thereof). If
18726 it's the latter, then this function is only being called to output a
18727 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18728 argument type of some subprogram type.
18729 If EMIT_NAME_P is true, name and source coordinate attributes
18733 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18734 dw_die_ref context_die)
18736 tree node_or_origin = node ? node : origin;
18737 tree ultimate_origin;
18738 dw_die_ref parm_die
18739 = new_die (DW_TAG_formal_parameter, context_die, node);
18741 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18743 case tcc_declaration:
18744 ultimate_origin = decl_ultimate_origin (node_or_origin);
18745 if (node || ultimate_origin)
18746 origin = ultimate_origin;
18747 if (origin != NULL)
18748 add_abstract_origin_attribute (parm_die, origin);
18749 else if (emit_name_p)
18750 add_name_and_src_coords_attributes (parm_die, node);
18752 || (! DECL_ABSTRACT (node_or_origin)
18753 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18754 decl_function_context
18755 (node_or_origin))))
18757 tree type = TREE_TYPE (node_or_origin);
18758 if (decl_by_reference_p (node_or_origin))
18759 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18762 add_type_attribute (parm_die, type,
18763 TREE_READONLY (node_or_origin),
18764 TREE_THIS_VOLATILE (node_or_origin),
18767 if (origin == NULL && DECL_ARTIFICIAL (node))
18768 add_AT_flag (parm_die, DW_AT_artificial, 1);
18770 if (node && node != origin)
18771 equate_decl_number_to_die (node, parm_die);
18772 if (! DECL_ABSTRACT (node_or_origin))
18773 add_location_or_const_value_attribute (parm_die, node_or_origin,
18779 /* We were called with some kind of a ..._TYPE node. */
18780 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18784 gcc_unreachable ();
18790 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18791 children DW_TAG_formal_parameter DIEs representing the arguments of the
18794 PARM_PACK must be a function parameter pack.
18795 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18796 must point to the subsequent arguments of the function PACK_ARG belongs to.
18797 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18798 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18799 following the last one for which a DIE was generated. */
18802 gen_formal_parameter_pack_die (tree parm_pack,
18804 dw_die_ref subr_die,
18808 dw_die_ref parm_pack_die;
18810 gcc_assert (parm_pack
18811 && lang_hooks.function_parameter_pack_p (parm_pack)
18814 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18815 add_src_coords_attributes (parm_pack_die, parm_pack);
18817 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18819 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18822 gen_formal_parameter_die (arg, NULL,
18823 false /* Don't emit name attribute. */,
18828 return parm_pack_die;
18831 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18832 at the end of an (ANSI prototyped) formal parameters list. */
18835 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18837 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18840 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18841 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18842 parameters as specified in some function type specification (except for
18843 those which appear as part of a function *definition*). */
18846 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18849 tree formal_type = NULL;
18850 tree first_parm_type;
18853 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18855 arg = DECL_ARGUMENTS (function_or_method_type);
18856 function_or_method_type = TREE_TYPE (function_or_method_type);
18861 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18863 /* Make our first pass over the list of formal parameter types and output a
18864 DW_TAG_formal_parameter DIE for each one. */
18865 for (link = first_parm_type; link; )
18867 dw_die_ref parm_die;
18869 formal_type = TREE_VALUE (link);
18870 if (formal_type == void_type_node)
18873 /* Output a (nameless) DIE to represent the formal parameter itself. */
18874 parm_die = gen_formal_parameter_die (formal_type, NULL,
18875 true /* Emit name attribute. */,
18877 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18878 && link == first_parm_type)
18880 add_AT_flag (parm_die, DW_AT_artificial, 1);
18881 if (dwarf_version >= 3 || !dwarf_strict)
18882 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18884 else if (arg && DECL_ARTIFICIAL (arg))
18885 add_AT_flag (parm_die, DW_AT_artificial, 1);
18887 link = TREE_CHAIN (link);
18889 arg = DECL_CHAIN (arg);
18892 /* If this function type has an ellipsis, add a
18893 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18894 if (formal_type != void_type_node)
18895 gen_unspecified_parameters_die (function_or_method_type, context_die);
18897 /* Make our second (and final) pass over the list of formal parameter types
18898 and output DIEs to represent those types (as necessary). */
18899 for (link = TYPE_ARG_TYPES (function_or_method_type);
18900 link && TREE_VALUE (link);
18901 link = TREE_CHAIN (link))
18902 gen_type_die (TREE_VALUE (link), context_die);
18905 /* We want to generate the DIE for TYPE so that we can generate the
18906 die for MEMBER, which has been defined; we will need to refer back
18907 to the member declaration nested within TYPE. If we're trying to
18908 generate minimal debug info for TYPE, processing TYPE won't do the
18909 trick; we need to attach the member declaration by hand. */
18912 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18914 gen_type_die (type, context_die);
18916 /* If we're trying to avoid duplicate debug info, we may not have
18917 emitted the member decl for this function. Emit it now. */
18918 if (TYPE_STUB_DECL (type)
18919 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18920 && ! lookup_decl_die (member))
18922 dw_die_ref type_die;
18923 gcc_assert (!decl_ultimate_origin (member));
18925 push_decl_scope (type);
18926 type_die = lookup_type_die_strip_naming_typedef (type);
18927 if (TREE_CODE (member) == FUNCTION_DECL)
18928 gen_subprogram_die (member, type_die);
18929 else if (TREE_CODE (member) == FIELD_DECL)
18931 /* Ignore the nameless fields that are used to skip bits but handle
18932 C++ anonymous unions and structs. */
18933 if (DECL_NAME (member) != NULL_TREE
18934 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18935 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18937 gen_type_die (member_declared_type (member), type_die);
18938 gen_field_die (member, type_die);
18942 gen_variable_die (member, NULL_TREE, type_die);
18948 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18949 may later generate inlined and/or out-of-line instances of. */
18952 dwarf2out_abstract_function (tree decl)
18954 dw_die_ref old_die;
18958 htab_t old_decl_loc_table;
18959 int old_call_site_count, old_tail_call_site_count;
18960 struct call_arg_loc_node *old_call_arg_locations;
18962 /* Make sure we have the actual abstract inline, not a clone. */
18963 decl = DECL_ORIGIN (decl);
18965 old_die = lookup_decl_die (decl);
18966 if (old_die && get_AT (old_die, DW_AT_inline))
18967 /* We've already generated the abstract instance. */
18970 /* We can be called while recursively when seeing block defining inlined subroutine
18971 DIE. Be sure to not clobber the outer location table nor use it or we would
18972 get locations in abstract instantces. */
18973 old_decl_loc_table = decl_loc_table;
18974 decl_loc_table = NULL;
18975 old_call_arg_locations = call_arg_locations;
18976 call_arg_locations = NULL;
18977 old_call_site_count = call_site_count;
18978 call_site_count = -1;
18979 old_tail_call_site_count = tail_call_site_count;
18980 tail_call_site_count = -1;
18982 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18983 we don't get confused by DECL_ABSTRACT. */
18984 if (debug_info_level > DINFO_LEVEL_TERSE)
18986 context = decl_class_context (decl);
18988 gen_type_die_for_member
18989 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18992 /* Pretend we've just finished compiling this function. */
18993 save_fn = current_function_decl;
18994 current_function_decl = decl;
18995 push_cfun (DECL_STRUCT_FUNCTION (decl));
18997 was_abstract = DECL_ABSTRACT (decl);
18998 set_decl_abstract_flags (decl, 1);
18999 dwarf2out_decl (decl);
19000 if (! was_abstract)
19001 set_decl_abstract_flags (decl, 0);
19003 current_function_decl = save_fn;
19004 decl_loc_table = old_decl_loc_table;
19005 call_arg_locations = old_call_arg_locations;
19006 call_site_count = old_call_site_count;
19007 tail_call_site_count = old_tail_call_site_count;
19011 /* Helper function of premark_used_types() which gets called through
19014 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19015 marked as unused by prune_unused_types. */
19018 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
19023 type = (tree) *slot;
19024 die = lookup_type_die (type);
19026 die->die_perennial_p = 1;
19030 /* Helper function of premark_types_used_by_global_vars which gets called
19031 through htab_traverse.
19033 Marks the DIE of a given type in *SLOT as perennial, so it never gets
19034 marked as unused by prune_unused_types. The DIE of the type is marked
19035 only if the global variable using the type will actually be emitted. */
19038 premark_types_used_by_global_vars_helper (void **slot,
19039 void *data ATTRIBUTE_UNUSED)
19041 struct types_used_by_vars_entry *entry;
19044 entry = (struct types_used_by_vars_entry *) *slot;
19045 gcc_assert (entry->type != NULL
19046 && entry->var_decl != NULL);
19047 die = lookup_type_die (entry->type);
19050 /* Ask cgraph if the global variable really is to be emitted.
19051 If yes, then we'll keep the DIE of ENTRY->TYPE. */
19052 struct varpool_node *node = varpool_get_node (entry->var_decl);
19053 if (node && node->needed)
19055 die->die_perennial_p = 1;
19056 /* Keep the parent DIEs as well. */
19057 while ((die = die->die_parent) && die->die_perennial_p == 0)
19058 die->die_perennial_p = 1;
19064 /* Mark all members of used_types_hash as perennial. */
19067 premark_used_types (void)
19069 if (cfun && cfun->used_types_hash)
19070 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
19073 /* Mark all members of types_used_by_vars_entry as perennial. */
19076 premark_types_used_by_global_vars (void)
19078 if (types_used_by_vars_hash)
19079 htab_traverse (types_used_by_vars_hash,
19080 premark_types_used_by_global_vars_helper, NULL);
19083 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
19084 for CA_LOC call arg loc node. */
19087 gen_call_site_die (tree decl, dw_die_ref subr_die,
19088 struct call_arg_loc_node *ca_loc)
19090 dw_die_ref stmt_die = NULL, die;
19091 tree block = ca_loc->block;
19094 && block != DECL_INITIAL (decl)
19095 && TREE_CODE (block) == BLOCK)
19097 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
19098 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
19101 block = BLOCK_SUPERCONTEXT (block);
19103 if (stmt_die == NULL)
19104 stmt_die = subr_die;
19105 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
19106 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
19107 if (ca_loc->tail_call_p)
19108 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
19109 if (ca_loc->symbol_ref)
19111 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
19113 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
19115 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
19120 /* Generate a DIE to represent a declared function (either file-scope or
19124 gen_subprogram_die (tree decl, dw_die_ref context_die)
19126 tree origin = decl_ultimate_origin (decl);
19127 dw_die_ref subr_die;
19129 dw_die_ref old_die = lookup_decl_die (decl);
19130 int declaration = (current_function_decl != decl
19131 || class_or_namespace_scope_p (context_die));
19133 premark_used_types ();
19135 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
19136 started to generate the abstract instance of an inline, decided to output
19137 its containing class, and proceeded to emit the declaration of the inline
19138 from the member list for the class. If so, DECLARATION takes priority;
19139 we'll get back to the abstract instance when done with the class. */
19141 /* The class-scope declaration DIE must be the primary DIE. */
19142 if (origin && declaration && class_or_namespace_scope_p (context_die))
19145 gcc_assert (!old_die);
19148 /* Now that the C++ front end lazily declares artificial member fns, we
19149 might need to retrofit the declaration into its class. */
19150 if (!declaration && !origin && !old_die
19151 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
19152 && !class_or_namespace_scope_p (context_die)
19153 && debug_info_level > DINFO_LEVEL_TERSE)
19154 old_die = force_decl_die (decl);
19156 if (origin != NULL)
19158 gcc_assert (!declaration || local_scope_p (context_die));
19160 /* Fixup die_parent for the abstract instance of a nested
19161 inline function. */
19162 if (old_die && old_die->die_parent == NULL)
19163 add_child_die (context_die, old_die);
19165 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19166 add_abstract_origin_attribute (subr_die, origin);
19170 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19171 struct dwarf_file_data * file_index = lookup_filename (s.file);
19173 if (!get_AT_flag (old_die, DW_AT_declaration)
19174 /* We can have a normal definition following an inline one in the
19175 case of redefinition of GNU C extern inlines.
19176 It seems reasonable to use AT_specification in this case. */
19177 && !get_AT (old_die, DW_AT_inline))
19179 /* Detect and ignore this case, where we are trying to output
19180 something we have already output. */
19184 /* If the definition comes from the same place as the declaration,
19185 maybe use the old DIE. We always want the DIE for this function
19186 that has the *_pc attributes to be under comp_unit_die so the
19187 debugger can find it. We also need to do this for abstract
19188 instances of inlines, since the spec requires the out-of-line copy
19189 to have the same parent. For local class methods, this doesn't
19190 apply; we just use the old DIE. */
19191 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19192 && (DECL_ARTIFICIAL (decl)
19193 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19194 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19195 == (unsigned) s.line))))
19197 subr_die = old_die;
19199 /* Clear out the declaration attribute and the formal parameters.
19200 Do not remove all children, because it is possible that this
19201 declaration die was forced using force_decl_die(). In such
19202 cases die that forced declaration die (e.g. TAG_imported_module)
19203 is one of the children that we do not want to remove. */
19204 remove_AT (subr_die, DW_AT_declaration);
19205 remove_AT (subr_die, DW_AT_object_pointer);
19206 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19210 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19211 add_AT_specification (subr_die, old_die);
19212 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19213 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19214 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19215 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19220 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19222 if (TREE_PUBLIC (decl))
19223 add_AT_flag (subr_die, DW_AT_external, 1);
19225 add_name_and_src_coords_attributes (subr_die, decl);
19226 if (debug_info_level > DINFO_LEVEL_TERSE)
19228 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19229 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19230 0, 0, context_die);
19233 add_pure_or_virtual_attribute (subr_die, decl);
19234 if (DECL_ARTIFICIAL (decl))
19235 add_AT_flag (subr_die, DW_AT_artificial, 1);
19237 add_accessibility_attribute (subr_die, decl);
19242 if (!old_die || !get_AT (old_die, DW_AT_inline))
19244 add_AT_flag (subr_die, DW_AT_declaration, 1);
19246 /* If this is an explicit function declaration then generate
19247 a DW_AT_explicit attribute. */
19248 if (lang_hooks.decls.function_decl_explicit_p (decl)
19249 && (dwarf_version >= 3 || !dwarf_strict))
19250 add_AT_flag (subr_die, DW_AT_explicit, 1);
19252 /* The first time we see a member function, it is in the context of
19253 the class to which it belongs. We make sure of this by emitting
19254 the class first. The next time is the definition, which is
19255 handled above. The two may come from the same source text.
19257 Note that force_decl_die() forces function declaration die. It is
19258 later reused to represent definition. */
19259 equate_decl_number_to_die (decl, subr_die);
19262 else if (DECL_ABSTRACT (decl))
19264 if (DECL_DECLARED_INLINE_P (decl))
19266 if (cgraph_function_possibly_inlined_p (decl))
19267 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19269 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19273 if (cgraph_function_possibly_inlined_p (decl))
19274 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19276 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19279 if (DECL_DECLARED_INLINE_P (decl)
19280 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19281 add_AT_flag (subr_die, DW_AT_artificial, 1);
19283 equate_decl_number_to_die (decl, subr_die);
19285 else if (!DECL_EXTERNAL (decl))
19287 HOST_WIDE_INT cfa_fb_offset;
19289 if (!old_die || !get_AT (old_die, DW_AT_inline))
19290 equate_decl_number_to_die (decl, subr_die);
19292 if (!flag_reorder_blocks_and_partition)
19294 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19295 if (fde->dw_fde_begin)
19297 /* We have already generated the labels. */
19298 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19299 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19303 /* Create start/end labels and add the range. */
19304 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19305 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19306 current_function_funcdef_no);
19307 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19308 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19309 current_function_funcdef_no);
19310 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19313 #if VMS_DEBUGGING_INFO
19314 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19315 Section 2.3 Prologue and Epilogue Attributes:
19316 When a breakpoint is set on entry to a function, it is generally
19317 desirable for execution to be suspended, not on the very first
19318 instruction of the function, but rather at a point after the
19319 function's frame has been set up, after any language defined local
19320 declaration processing has been completed, and before execution of
19321 the first statement of the function begins. Debuggers generally
19322 cannot properly determine where this point is. Similarly for a
19323 breakpoint set on exit from a function. The prologue and epilogue
19324 attributes allow a compiler to communicate the location(s) to use. */
19327 if (fde->dw_fde_vms_end_prologue)
19328 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19329 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19331 if (fde->dw_fde_vms_begin_epilogue)
19332 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19333 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19337 add_pubname (decl, subr_die);
19338 add_arange (decl, subr_die);
19341 { /* Generate pubnames entries for the split function code
19343 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19345 if (fde->dw_fde_switched_sections)
19347 if (dwarf_version >= 3 || !dwarf_strict)
19349 /* We should use ranges for non-contiguous code section
19350 addresses. Use the actual code range for the initial
19351 section, since the HOT/COLD labels might precede an
19352 alignment offset. */
19353 bool range_list_added = false;
19354 if (fde->in_std_section)
19356 add_ranges_by_labels (subr_die,
19359 &range_list_added);
19360 add_ranges_by_labels (subr_die,
19361 fde->dw_fde_unlikely_section_label,
19362 fde->dw_fde_unlikely_section_end_label,
19363 &range_list_added);
19367 add_ranges_by_labels (subr_die,
19370 &range_list_added);
19371 add_ranges_by_labels (subr_die,
19372 fde->dw_fde_hot_section_label,
19373 fde->dw_fde_hot_section_end_label,
19374 &range_list_added);
19376 add_pubname (decl, subr_die);
19377 if (range_list_added)
19382 /* There is no real support in DW2 for this .. so we make
19383 a work-around. First, emit the pub name for the segment
19384 containing the function label. Then make and emit a
19385 simplified subprogram DIE for the second segment with the
19386 name pre-fixed by __hot/cold_sect_of_. We use the same
19387 linkage name for the second die so that gdb will find both
19388 sections when given "b foo". */
19389 const char *name = NULL;
19390 tree decl_name = DECL_NAME (decl);
19391 dw_die_ref seg_die;
19393 /* Do the 'primary' section. */
19394 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19395 fde->dw_fde_begin);
19396 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19399 add_pubname (decl, subr_die);
19400 add_arange (decl, subr_die);
19402 /* Build a minimal DIE for the secondary section. */
19403 seg_die = new_die (DW_TAG_subprogram,
19404 subr_die->die_parent, decl);
19406 if (TREE_PUBLIC (decl))
19407 add_AT_flag (seg_die, DW_AT_external, 1);
19409 if (decl_name != NULL
19410 && IDENTIFIER_POINTER (decl_name) != NULL)
19412 name = dwarf2_name (decl, 1);
19413 if (! DECL_ARTIFICIAL (decl))
19414 add_src_coords_attributes (seg_die, decl);
19416 add_linkage_name (seg_die, decl);
19418 gcc_assert (name!=NULL);
19419 add_pure_or_virtual_attribute (seg_die, decl);
19420 if (DECL_ARTIFICIAL (decl))
19421 add_AT_flag (seg_die, DW_AT_artificial, 1);
19423 if (fde->in_std_section)
19425 name = concat ("__cold_sect_of_", name, NULL);
19426 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19427 fde->dw_fde_unlikely_section_label);
19428 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19429 fde->dw_fde_unlikely_section_end_label);
19433 name = concat ("__hot_sect_of_", name, NULL);
19434 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19435 fde->dw_fde_hot_section_label);
19436 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19437 fde->dw_fde_hot_section_end_label);
19439 add_name_attribute (seg_die, name);
19440 add_pubname_string (name, seg_die);
19441 add_arange (decl, seg_die);
19446 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19447 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19448 add_pubname (decl, subr_die);
19449 add_arange (decl, subr_die);
19453 #ifdef MIPS_DEBUGGING_INFO
19454 /* Add a reference to the FDE for this routine. */
19455 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19458 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19460 /* We define the "frame base" as the function's CFA. This is more
19461 convenient for several reasons: (1) It's stable across the prologue
19462 and epilogue, which makes it better than just a frame pointer,
19463 (2) With dwarf3, there exists a one-byte encoding that allows us
19464 to reference the .debug_frame data by proxy, but failing that,
19465 (3) We can at least reuse the code inspection and interpretation
19466 code that determines the CFA position at various points in the
19468 if (dwarf_version >= 3)
19470 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19471 add_AT_loc (subr_die, DW_AT_frame_base, op);
19475 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19476 if (list->dw_loc_next)
19477 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19479 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19482 /* Compute a displacement from the "steady-state frame pointer" to
19483 the CFA. The former is what all stack slots and argument slots
19484 will reference in the rtl; the later is what we've told the
19485 debugger about. We'll need to adjust all frame_base references
19486 by this displacement. */
19487 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19489 if (cfun->static_chain_decl)
19490 add_AT_location_description (subr_die, DW_AT_static_link,
19491 loc_list_from_tree (cfun->static_chain_decl, 2));
19494 /* Generate child dies for template paramaters. */
19495 if (debug_info_level > DINFO_LEVEL_TERSE)
19496 gen_generic_params_dies (decl);
19498 /* Now output descriptions of the arguments for this function. This gets
19499 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19500 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19501 `...' at the end of the formal parameter list. In order to find out if
19502 there was a trailing ellipsis or not, we must instead look at the type
19503 associated with the FUNCTION_DECL. This will be a node of type
19504 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19505 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19506 an ellipsis at the end. */
19508 /* In the case where we are describing a mere function declaration, all we
19509 need to do here (and all we *can* do here) is to describe the *types* of
19510 its formal parameters. */
19511 if (debug_info_level <= DINFO_LEVEL_TERSE)
19513 else if (declaration)
19514 gen_formal_types_die (decl, subr_die);
19517 /* Generate DIEs to represent all known formal parameters. */
19518 tree parm = DECL_ARGUMENTS (decl);
19519 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19520 tree generic_decl_parm = generic_decl
19521 ? DECL_ARGUMENTS (generic_decl)
19524 /* Now we want to walk the list of parameters of the function and
19525 emit their relevant DIEs.
19527 We consider the case of DECL being an instance of a generic function
19528 as well as it being a normal function.
19530 If DECL is an instance of a generic function we walk the
19531 parameters of the generic function declaration _and_ the parameters of
19532 DECL itself. This is useful because we want to emit specific DIEs for
19533 function parameter packs and those are declared as part of the
19534 generic function declaration. In that particular case,
19535 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19536 That DIE has children DIEs representing the set of arguments
19537 of the pack. Note that the set of pack arguments can be empty.
19538 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19541 Otherwise, we just consider the parameters of DECL. */
19542 while (generic_decl_parm || parm)
19544 if (generic_decl_parm
19545 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19546 gen_formal_parameter_pack_die (generic_decl_parm,
19551 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19553 if (parm == DECL_ARGUMENTS (decl)
19554 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19556 && (dwarf_version >= 3 || !dwarf_strict))
19557 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19559 parm = DECL_CHAIN (parm);
19562 if (generic_decl_parm)
19563 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19566 /* Decide whether we need an unspecified_parameters DIE at the end.
19567 There are 2 more cases to do this for: 1) the ansi ... declaration -
19568 this is detectable when the end of the arg list is not a
19569 void_type_node 2) an unprototyped function declaration (not a
19570 definition). This just means that we have no info about the
19571 parameters at all. */
19572 if (prototype_p (TREE_TYPE (decl)))
19574 /* This is the prototyped case, check for.... */
19575 if (stdarg_p (TREE_TYPE (decl)))
19576 gen_unspecified_parameters_die (decl, subr_die);
19578 else if (DECL_INITIAL (decl) == NULL_TREE)
19579 gen_unspecified_parameters_die (decl, subr_die);
19582 /* Output Dwarf info for all of the stuff within the body of the function
19583 (if it has one - it may be just a declaration). */
19584 outer_scope = DECL_INITIAL (decl);
19586 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19587 a function. This BLOCK actually represents the outermost binding contour
19588 for the function, i.e. the contour in which the function's formal
19589 parameters and labels get declared. Curiously, it appears that the front
19590 end doesn't actually put the PARM_DECL nodes for the current function onto
19591 the BLOCK_VARS list for this outer scope, but are strung off of the
19592 DECL_ARGUMENTS list for the function instead.
19594 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19595 the LABEL_DECL nodes for the function however, and we output DWARF info
19596 for those in decls_for_scope. Just within the `outer_scope' there will be
19597 a BLOCK node representing the function's outermost pair of curly braces,
19598 and any blocks used for the base and member initializers of a C++
19599 constructor function. */
19600 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19602 int call_site_note_count = 0;
19603 int tail_call_site_note_count = 0;
19605 /* Emit a DW_TAG_variable DIE for a named return value. */
19606 if (DECL_NAME (DECL_RESULT (decl)))
19607 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19609 current_function_has_inlines = 0;
19610 decls_for_scope (outer_scope, subr_die, 0);
19612 if (call_arg_locations)
19614 struct call_arg_loc_node *ca_loc;
19615 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19617 dw_die_ref die = NULL;
19618 rtx tloc = NULL_RTX;
19621 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19622 arg; arg = next_arg)
19624 dw_loc_descr_ref reg, val;
19625 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19628 next_arg = XEXP (arg, 1);
19629 if (REG_P (XEXP (XEXP (arg, 0), 0))
19631 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19632 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19633 && REGNO (XEXP (XEXP (arg, 0), 0))
19634 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19635 next_arg = XEXP (next_arg, 1);
19636 if (mode == VOIDmode)
19637 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19638 if (GET_MODE_CLASS (mode) != MODE_INT
19639 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
19641 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19643 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19644 tloc = XEXP (XEXP (arg, 0), 1);
19647 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19648 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19649 VAR_INIT_STATUS_INITIALIZED);
19650 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19651 reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
19653 VAR_INIT_STATUS_INITIALIZED);
19658 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
19659 VAR_INIT_STATUS_INITIALIZED);
19663 die = gen_call_site_die (decl, subr_die, ca_loc);
19664 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19666 add_AT_loc (cdie, DW_AT_location, reg);
19667 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19668 if (next_arg != XEXP (arg, 1))
19670 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19672 VAR_INIT_STATUS_INITIALIZED);
19674 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19678 && (ca_loc->symbol_ref || tloc))
19679 die = gen_call_site_die (decl, subr_die, ca_loc);
19680 if (die != NULL && tloc != NULL_RTX)
19682 dw_loc_descr_ref tval
19683 = mem_loc_descriptor (tloc, VOIDmode,
19684 VAR_INIT_STATUS_INITIALIZED);
19686 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19690 call_site_note_count++;
19691 if (ca_loc->tail_call_p)
19692 tail_call_site_note_count++;
19695 call_arg_locations = NULL;
19696 call_arg_loc_last = NULL;
19698 if (tail_call_site_count >= 0
19699 && tail_call_site_count == tail_call_site_note_count)
19701 if (call_site_count >= 0
19702 && call_site_count == call_site_note_count)
19703 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19705 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19707 call_site_count = -1;
19708 tail_call_site_count = -1;
19710 /* Add the calling convention attribute if requested. */
19711 add_calling_convention_attribute (subr_die, decl);
19715 /* Returns a hash value for X (which really is a die_struct). */
19718 common_block_die_table_hash (const void *x)
19720 const_dw_die_ref d = (const_dw_die_ref) x;
19721 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19724 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19725 as decl_id and die_parent of die_struct Y. */
19728 common_block_die_table_eq (const void *x, const void *y)
19730 const_dw_die_ref d = (const_dw_die_ref) x;
19731 const_dw_die_ref e = (const_dw_die_ref) y;
19732 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19735 /* Generate a DIE to represent a declared data object.
19736 Either DECL or ORIGIN must be non-null. */
19739 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19743 tree decl_or_origin = decl ? decl : origin;
19744 tree ultimate_origin;
19745 dw_die_ref var_die;
19746 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19747 dw_die_ref origin_die;
19748 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19749 || class_or_namespace_scope_p (context_die));
19750 bool specialization_p = false;
19752 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19753 if (decl || ultimate_origin)
19754 origin = ultimate_origin;
19755 com_decl = fortran_common (decl_or_origin, &off);
19757 /* Symbol in common gets emitted as a child of the common block, in the form
19758 of a data member. */
19761 dw_die_ref com_die;
19762 dw_loc_list_ref loc;
19763 die_node com_die_arg;
19765 var_die = lookup_decl_die (decl_or_origin);
19768 if (get_AT (var_die, DW_AT_location) == NULL)
19770 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19775 /* Optimize the common case. */
19776 if (single_element_loc_list_p (loc)
19777 && loc->expr->dw_loc_opc == DW_OP_addr
19778 && loc->expr->dw_loc_next == NULL
19779 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19781 loc->expr->dw_loc_oprnd1.v.val_addr
19782 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19784 loc_list_plus_const (loc, off);
19786 add_AT_location_description (var_die, DW_AT_location, loc);
19787 remove_AT (var_die, DW_AT_declaration);
19793 if (common_block_die_table == NULL)
19794 common_block_die_table
19795 = htab_create_ggc (10, common_block_die_table_hash,
19796 common_block_die_table_eq, NULL);
19798 com_die_arg.decl_id = DECL_UID (com_decl);
19799 com_die_arg.die_parent = context_die;
19800 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19801 loc = loc_list_from_tree (com_decl, 2);
19802 if (com_die == NULL)
19805 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19808 com_die = new_die (DW_TAG_common_block, context_die, decl);
19809 add_name_and_src_coords_attributes (com_die, com_decl);
19812 add_AT_location_description (com_die, DW_AT_location, loc);
19813 /* Avoid sharing the same loc descriptor between
19814 DW_TAG_common_block and DW_TAG_variable. */
19815 loc = loc_list_from_tree (com_decl, 2);
19817 else if (DECL_EXTERNAL (decl))
19818 add_AT_flag (com_die, DW_AT_declaration, 1);
19819 add_pubname_string (cnam, com_die); /* ??? needed? */
19820 com_die->decl_id = DECL_UID (com_decl);
19821 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19822 *slot = (void *) com_die;
19824 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19826 add_AT_location_description (com_die, DW_AT_location, loc);
19827 loc = loc_list_from_tree (com_decl, 2);
19828 remove_AT (com_die, DW_AT_declaration);
19830 var_die = new_die (DW_TAG_variable, com_die, decl);
19831 add_name_and_src_coords_attributes (var_die, decl);
19832 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19833 TREE_THIS_VOLATILE (decl), context_die);
19834 add_AT_flag (var_die, DW_AT_external, 1);
19839 /* Optimize the common case. */
19840 if (single_element_loc_list_p (loc)
19841 && loc->expr->dw_loc_opc == DW_OP_addr
19842 && loc->expr->dw_loc_next == NULL
19843 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19844 loc->expr->dw_loc_oprnd1.v.val_addr
19845 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19847 loc_list_plus_const (loc, off);
19849 add_AT_location_description (var_die, DW_AT_location, loc);
19851 else if (DECL_EXTERNAL (decl))
19852 add_AT_flag (var_die, DW_AT_declaration, 1);
19853 equate_decl_number_to_die (decl, var_die);
19857 /* If the compiler emitted a definition for the DECL declaration
19858 and if we already emitted a DIE for it, don't emit a second
19859 DIE for it again. Allow re-declarations of DECLs that are
19860 inside functions, though. */
19861 if (old_die && declaration && !local_scope_p (context_die))
19864 /* For static data members, the declaration in the class is supposed
19865 to have DW_TAG_member tag; the specification should still be
19866 DW_TAG_variable referencing the DW_TAG_member DIE. */
19867 if (declaration && class_scope_p (context_die))
19868 var_die = new_die (DW_TAG_member, context_die, decl);
19870 var_die = new_die (DW_TAG_variable, context_die, decl);
19873 if (origin != NULL)
19874 origin_die = add_abstract_origin_attribute (var_die, origin);
19876 /* Loop unrolling can create multiple blocks that refer to the same
19877 static variable, so we must test for the DW_AT_declaration flag.
19879 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19880 copy decls and set the DECL_ABSTRACT flag on them instead of
19883 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19885 ??? The declare_in_namespace support causes us to get two DIEs for one
19886 variable, both of which are declarations. We want to avoid considering
19887 one to be a specification, so we must test that this DIE is not a
19889 else if (old_die && TREE_STATIC (decl) && ! declaration
19890 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19892 /* This is a definition of a C++ class level static. */
19893 add_AT_specification (var_die, old_die);
19894 specialization_p = true;
19895 if (DECL_NAME (decl))
19897 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19898 struct dwarf_file_data * file_index = lookup_filename (s.file);
19900 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19901 add_AT_file (var_die, DW_AT_decl_file, file_index);
19903 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19904 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19906 if (old_die->die_tag == DW_TAG_member)
19907 add_linkage_name (var_die, decl);
19911 add_name_and_src_coords_attributes (var_die, decl);
19913 if ((origin == NULL && !specialization_p)
19915 && !DECL_ABSTRACT (decl_or_origin)
19916 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19917 decl_function_context
19918 (decl_or_origin))))
19920 tree type = TREE_TYPE (decl_or_origin);
19922 if (decl_by_reference_p (decl_or_origin))
19923 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19925 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19926 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19929 if (origin == NULL && !specialization_p)
19931 if (TREE_PUBLIC (decl))
19932 add_AT_flag (var_die, DW_AT_external, 1);
19934 if (DECL_ARTIFICIAL (decl))
19935 add_AT_flag (var_die, DW_AT_artificial, 1);
19937 add_accessibility_attribute (var_die, decl);
19941 add_AT_flag (var_die, DW_AT_declaration, 1);
19943 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19944 equate_decl_number_to_die (decl, var_die);
19947 && (! DECL_ABSTRACT (decl_or_origin)
19948 /* Local static vars are shared between all clones/inlines,
19949 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19951 || (TREE_CODE (decl_or_origin) == VAR_DECL
19952 && TREE_STATIC (decl_or_origin)
19953 && DECL_RTL_SET_P (decl_or_origin)))
19954 /* When abstract origin already has DW_AT_location attribute, no need
19955 to add it again. */
19956 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19958 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19959 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19960 defer_location (decl_or_origin, var_die);
19962 add_location_or_const_value_attribute (var_die,
19965 add_pubname (decl_or_origin, var_die);
19968 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19971 /* Generate a DIE to represent a named constant. */
19974 gen_const_die (tree decl, dw_die_ref context_die)
19976 dw_die_ref const_die;
19977 tree type = TREE_TYPE (decl);
19979 const_die = new_die (DW_TAG_constant, context_die, decl);
19980 add_name_and_src_coords_attributes (const_die, decl);
19981 add_type_attribute (const_die, type, 1, 0, context_die);
19982 if (TREE_PUBLIC (decl))
19983 add_AT_flag (const_die, DW_AT_external, 1);
19984 if (DECL_ARTIFICIAL (decl))
19985 add_AT_flag (const_die, DW_AT_artificial, 1);
19986 tree_add_const_value_attribute_for_decl (const_die, decl);
19989 /* Generate a DIE to represent a label identifier. */
19992 gen_label_die (tree decl, dw_die_ref context_die)
19994 tree origin = decl_ultimate_origin (decl);
19995 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19997 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19999 if (origin != NULL)
20000 add_abstract_origin_attribute (lbl_die, origin);
20002 add_name_and_src_coords_attributes (lbl_die, decl);
20004 if (DECL_ABSTRACT (decl))
20005 equate_decl_number_to_die (decl, lbl_die);
20008 insn = DECL_RTL_IF_SET (decl);
20010 /* Deleted labels are programmer specified labels which have been
20011 eliminated because of various optimizations. We still emit them
20012 here so that it is possible to put breakpoints on them. */
20016 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
20018 /* When optimization is enabled (via -O) some parts of the compiler
20019 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
20020 represent source-level labels which were explicitly declared by
20021 the user. This really shouldn't be happening though, so catch
20022 it if it ever does happen. */
20023 gcc_assert (!INSN_DELETED_P (insn));
20025 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
20026 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
20031 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
20032 attributes to the DIE for a block STMT, to describe where the inlined
20033 function was called from. This is similar to add_src_coords_attributes. */
20036 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
20038 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
20040 if (dwarf_version >= 3 || !dwarf_strict)
20042 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
20043 add_AT_unsigned (die, DW_AT_call_line, s.line);
20048 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
20049 Add low_pc and high_pc attributes to the DIE for a block STMT. */
20052 add_high_low_attributes (tree stmt, dw_die_ref die)
20054 char label[MAX_ARTIFICIAL_LABEL_BYTES];
20056 if (BLOCK_FRAGMENT_CHAIN (stmt)
20057 && (dwarf_version >= 3 || !dwarf_strict))
20061 if (inlined_function_outer_scope_p (stmt))
20063 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
20064 BLOCK_NUMBER (stmt));
20065 add_AT_lbl_id (die, DW_AT_entry_pc, label);
20068 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
20070 chain = BLOCK_FRAGMENT_CHAIN (stmt);
20073 add_ranges (chain);
20074 chain = BLOCK_FRAGMENT_CHAIN (chain);
20081 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
20082 BLOCK_NUMBER (stmt));
20083 add_AT_lbl_id (die, DW_AT_low_pc, label);
20084 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
20085 BLOCK_NUMBER (stmt));
20086 add_AT_lbl_id (die, DW_AT_high_pc, label);
20090 /* Generate a DIE for a lexical block. */
20093 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
20095 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
20097 if (call_arg_locations)
20099 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20100 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20101 BLOCK_NUMBER (stmt) + 1);
20102 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
20105 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
20106 add_high_low_attributes (stmt, stmt_die);
20108 decls_for_scope (stmt, stmt_die, depth);
20111 /* Generate a DIE for an inlined subprogram. */
20114 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
20118 /* The instance of function that is effectively being inlined shall not
20120 gcc_assert (! BLOCK_ABSTRACT (stmt));
20122 decl = block_ultimate_origin (stmt);
20124 /* Emit info for the abstract instance first, if we haven't yet. We
20125 must emit this even if the block is abstract, otherwise when we
20126 emit the block below (or elsewhere), we may end up trying to emit
20127 a die whose origin die hasn't been emitted, and crashing. */
20128 dwarf2out_abstract_function (decl);
20130 if (! BLOCK_ABSTRACT (stmt))
20132 dw_die_ref subr_die
20133 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20135 if (call_arg_locations)
20137 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20138 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20139 BLOCK_NUMBER (stmt) + 1);
20140 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
20142 add_abstract_origin_attribute (subr_die, decl);
20143 if (TREE_ASM_WRITTEN (stmt))
20144 add_high_low_attributes (stmt, subr_die);
20145 add_call_src_coords_attributes (stmt, subr_die);
20147 decls_for_scope (stmt, subr_die, depth);
20148 current_function_has_inlines = 1;
20152 /* Generate a DIE for a field in a record, or structure. */
20155 gen_field_die (tree decl, dw_die_ref context_die)
20157 dw_die_ref decl_die;
20159 if (TREE_TYPE (decl) == error_mark_node)
20162 decl_die = new_die (DW_TAG_member, context_die, decl);
20163 add_name_and_src_coords_attributes (decl_die, decl);
20164 add_type_attribute (decl_die, member_declared_type (decl),
20165 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20168 if (DECL_BIT_FIELD_TYPE (decl))
20170 add_byte_size_attribute (decl_die, decl);
20171 add_bit_size_attribute (decl_die, decl);
20172 add_bit_offset_attribute (decl_die, decl);
20175 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20176 add_data_member_location_attribute (decl_die, decl);
20178 if (DECL_ARTIFICIAL (decl))
20179 add_AT_flag (decl_die, DW_AT_artificial, 1);
20181 add_accessibility_attribute (decl_die, decl);
20183 /* Equate decl number to die, so that we can look up this decl later on. */
20184 equate_decl_number_to_die (decl, decl_die);
20188 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20189 Use modified_type_die instead.
20190 We keep this code here just in case these types of DIEs may be needed to
20191 represent certain things in other languages (e.g. Pascal) someday. */
20194 gen_pointer_type_die (tree type, dw_die_ref context_die)
20197 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20199 equate_type_number_to_die (type, ptr_die);
20200 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20201 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20204 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20205 Use modified_type_die instead.
20206 We keep this code here just in case these types of DIEs may be needed to
20207 represent certain things in other languages (e.g. Pascal) someday. */
20210 gen_reference_type_die (tree type, dw_die_ref context_die)
20212 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20214 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
20215 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20217 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20219 equate_type_number_to_die (type, ref_die);
20220 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20221 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20225 /* Generate a DIE for a pointer to a member type. */
20228 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20231 = new_die (DW_TAG_ptr_to_member_type,
20232 scope_die_for (type, context_die), type);
20234 equate_type_number_to_die (type, ptr_die);
20235 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20236 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20237 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20240 /* Generate the DIE for the compilation unit. */
20243 gen_compile_unit_die (const char *filename)
20246 char producer[250];
20247 const char *language_string = lang_hooks.name;
20250 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20254 add_name_attribute (die, filename);
20255 /* Don't add cwd for <built-in>. */
20256 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20257 add_comp_dir_attribute (die);
20260 sprintf (producer, "%s %s", language_string, version_string);
20262 #ifdef MIPS_DEBUGGING_INFO
20263 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20264 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20265 not appear in the producer string, the debugger reaches the conclusion
20266 that the object file is stripped and has no debugging information.
20267 To get the MIPS/SGI debugger to believe that there is debugging
20268 information in the object file, we add a -g to the producer string. */
20269 if (debug_info_level > DINFO_LEVEL_TERSE)
20270 strcat (producer, " -g");
20273 add_AT_string (die, DW_AT_producer, producer);
20275 /* If our producer is LTO try to figure out a common language to use
20276 from the global list of translation units. */
20277 if (strcmp (language_string, "GNU GIMPLE") == 0)
20281 const char *common_lang = NULL;
20283 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20285 if (!TRANSLATION_UNIT_LANGUAGE (t))
20288 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20289 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20291 else if (strncmp (common_lang, "GNU C", 5) == 0
20292 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20293 /* Mixing C and C++ is ok, use C++ in that case. */
20294 common_lang = "GNU C++";
20297 /* Fall back to C. */
20298 common_lang = NULL;
20304 language_string = common_lang;
20307 language = DW_LANG_C89;
20308 if (strcmp (language_string, "GNU C++") == 0)
20309 language = DW_LANG_C_plus_plus;
20310 else if (strcmp (language_string, "GNU F77") == 0)
20311 language = DW_LANG_Fortran77;
20312 else if (strcmp (language_string, "GNU Pascal") == 0)
20313 language = DW_LANG_Pascal83;
20314 else if (dwarf_version >= 3 || !dwarf_strict)
20316 if (strcmp (language_string, "GNU Ada") == 0)
20317 language = DW_LANG_Ada95;
20318 else if (strcmp (language_string, "GNU Fortran") == 0)
20319 language = DW_LANG_Fortran95;
20320 else if (strcmp (language_string, "GNU Java") == 0)
20321 language = DW_LANG_Java;
20322 else if (strcmp (language_string, "GNU Objective-C") == 0)
20323 language = DW_LANG_ObjC;
20324 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20325 language = DW_LANG_ObjC_plus_plus;
20328 add_AT_unsigned (die, DW_AT_language, language);
20332 case DW_LANG_Fortran77:
20333 case DW_LANG_Fortran90:
20334 case DW_LANG_Fortran95:
20335 /* Fortran has case insensitive identifiers and the front-end
20336 lowercases everything. */
20337 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20340 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20346 /* Generate the DIE for a base class. */
20349 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20351 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20353 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20354 add_data_member_location_attribute (die, binfo);
20356 if (BINFO_VIRTUAL_P (binfo))
20357 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20359 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20360 children, otherwise the default is DW_ACCESS_public. In DWARF2
20361 the default has always been DW_ACCESS_private. */
20362 if (access == access_public_node)
20364 if (dwarf_version == 2
20365 || context_die->die_tag == DW_TAG_class_type)
20366 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20368 else if (access == access_protected_node)
20369 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20370 else if (dwarf_version > 2
20371 && context_die->die_tag != DW_TAG_class_type)
20372 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20375 /* Generate a DIE for a class member. */
20378 gen_member_die (tree type, dw_die_ref context_die)
20381 tree binfo = TYPE_BINFO (type);
20384 /* If this is not an incomplete type, output descriptions of each of its
20385 members. Note that as we output the DIEs necessary to represent the
20386 members of this record or union type, we will also be trying to output
20387 DIEs to represent the *types* of those members. However the `type'
20388 function (above) will specifically avoid generating type DIEs for member
20389 types *within* the list of member DIEs for this (containing) type except
20390 for those types (of members) which are explicitly marked as also being
20391 members of this (containing) type themselves. The g++ front- end can
20392 force any given type to be treated as a member of some other (containing)
20393 type by setting the TYPE_CONTEXT of the given (member) type to point to
20394 the TREE node representing the appropriate (containing) type. */
20396 /* First output info about the base classes. */
20399 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20403 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20404 gen_inheritance_die (base,
20405 (accesses ? VEC_index (tree, accesses, i)
20406 : access_public_node), context_die);
20409 /* Now output info about the data members and type members. */
20410 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20412 /* If we thought we were generating minimal debug info for TYPE
20413 and then changed our minds, some of the member declarations
20414 may have already been defined. Don't define them again, but
20415 do put them in the right order. */
20417 child = lookup_decl_die (member);
20419 splice_child_die (context_die, child);
20421 gen_decl_die (member, NULL, context_die);
20424 /* Now output info about the function members (if any). */
20425 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20427 /* Don't include clones in the member list. */
20428 if (DECL_ABSTRACT_ORIGIN (member))
20431 child = lookup_decl_die (member);
20433 splice_child_die (context_die, child);
20435 gen_decl_die (member, NULL, context_die);
20439 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20440 is set, we pretend that the type was never defined, so we only get the
20441 member DIEs needed by later specification DIEs. */
20444 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20445 enum debug_info_usage usage)
20447 dw_die_ref type_die = lookup_type_die (type);
20448 dw_die_ref scope_die = 0;
20450 int complete = (TYPE_SIZE (type)
20451 && (! TYPE_STUB_DECL (type)
20452 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20453 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20454 complete = complete && should_emit_struct_debug (type, usage);
20456 if (type_die && ! complete)
20459 if (TYPE_CONTEXT (type) != NULL_TREE
20460 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20461 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20464 scope_die = scope_die_for (type, context_die);
20466 if (! type_die || (nested && is_cu_die (scope_die)))
20467 /* First occurrence of type or toplevel definition of nested class. */
20469 dw_die_ref old_die = type_die;
20471 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20472 ? record_type_tag (type) : DW_TAG_union_type,
20474 equate_type_number_to_die (type, type_die);
20476 add_AT_specification (type_die, old_die);
20478 add_name_attribute (type_die, type_tag (type));
20481 remove_AT (type_die, DW_AT_declaration);
20483 /* Generate child dies for template paramaters. */
20484 if (debug_info_level > DINFO_LEVEL_TERSE
20485 && COMPLETE_TYPE_P (type))
20486 schedule_generic_params_dies_gen (type);
20488 /* If this type has been completed, then give it a byte_size attribute and
20489 then give a list of members. */
20490 if (complete && !ns_decl)
20492 /* Prevent infinite recursion in cases where the type of some member of
20493 this type is expressed in terms of this type itself. */
20494 TREE_ASM_WRITTEN (type) = 1;
20495 add_byte_size_attribute (type_die, type);
20496 if (TYPE_STUB_DECL (type) != NULL_TREE)
20498 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20499 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20502 /* If the first reference to this type was as the return type of an
20503 inline function, then it may not have a parent. Fix this now. */
20504 if (type_die->die_parent == NULL)
20505 add_child_die (scope_die, type_die);
20507 push_decl_scope (type);
20508 gen_member_die (type, type_die);
20511 /* GNU extension: Record what type our vtable lives in. */
20512 if (TYPE_VFIELD (type))
20514 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20516 gen_type_die (vtype, context_die);
20517 add_AT_die_ref (type_die, DW_AT_containing_type,
20518 lookup_type_die (vtype));
20523 add_AT_flag (type_die, DW_AT_declaration, 1);
20525 /* We don't need to do this for function-local types. */
20526 if (TYPE_STUB_DECL (type)
20527 && ! decl_function_context (TYPE_STUB_DECL (type)))
20528 VEC_safe_push (tree, gc, incomplete_types, type);
20531 if (get_AT (type_die, DW_AT_name))
20532 add_pubtype (type, type_die);
20535 /* Generate a DIE for a subroutine _type_. */
20538 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20540 tree return_type = TREE_TYPE (type);
20541 dw_die_ref subr_die
20542 = new_die (DW_TAG_subroutine_type,
20543 scope_die_for (type, context_die), type);
20545 equate_type_number_to_die (type, subr_die);
20546 add_prototyped_attribute (subr_die, type);
20547 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20548 gen_formal_types_die (type, subr_die);
20550 if (get_AT (subr_die, DW_AT_name))
20551 add_pubtype (type, subr_die);
20554 /* Generate a DIE for a type definition. */
20557 gen_typedef_die (tree decl, dw_die_ref context_die)
20559 dw_die_ref type_die;
20562 if (TREE_ASM_WRITTEN (decl))
20565 TREE_ASM_WRITTEN (decl) = 1;
20566 type_die = new_die (DW_TAG_typedef, context_die, decl);
20567 origin = decl_ultimate_origin (decl);
20568 if (origin != NULL)
20569 add_abstract_origin_attribute (type_die, origin);
20574 add_name_and_src_coords_attributes (type_die, decl);
20575 if (DECL_ORIGINAL_TYPE (decl))
20577 type = DECL_ORIGINAL_TYPE (decl);
20579 gcc_assert (type != TREE_TYPE (decl));
20580 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20584 type = TREE_TYPE (decl);
20586 if (is_naming_typedef_decl (TYPE_NAME (type)))
20588 /* Here, we are in the case of decl being a typedef naming
20589 an anonymous type, e.g:
20590 typedef struct {...} foo;
20591 In that case TREE_TYPE (decl) is not a typedef variant
20592 type and TYPE_NAME of the anonymous type is set to the
20593 TYPE_DECL of the typedef. This construct is emitted by
20596 TYPE is the anonymous struct named by the typedef
20597 DECL. As we need the DW_AT_type attribute of the
20598 DW_TAG_typedef to point to the DIE of TYPE, let's
20599 generate that DIE right away. add_type_attribute
20600 called below will then pick (via lookup_type_die) that
20601 anonymous struct DIE. */
20602 if (!TREE_ASM_WRITTEN (type))
20603 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20607 add_type_attribute (type_die, type, TREE_READONLY (decl),
20608 TREE_THIS_VOLATILE (decl), context_die);
20610 if (is_naming_typedef_decl (decl))
20611 /* We want that all subsequent calls to lookup_type_die with
20612 TYPE in argument yield the DW_TAG_typedef we have just
20614 equate_type_number_to_die (type, type_die);
20616 add_accessibility_attribute (type_die, decl);
20619 if (DECL_ABSTRACT (decl))
20620 equate_decl_number_to_die (decl, type_die);
20622 if (get_AT (type_die, DW_AT_name))
20623 add_pubtype (decl, type_die);
20626 /* Generate a DIE for a struct, class, enum or union type. */
20629 gen_tagged_type_die (tree type,
20630 dw_die_ref context_die,
20631 enum debug_info_usage usage)
20635 if (type == NULL_TREE
20636 || !is_tagged_type (type))
20639 /* If this is a nested type whose containing class hasn't been written
20640 out yet, writing it out will cover this one, too. This does not apply
20641 to instantiations of member class templates; they need to be added to
20642 the containing class as they are generated. FIXME: This hurts the
20643 idea of combining type decls from multiple TUs, since we can't predict
20644 what set of template instantiations we'll get. */
20645 if (TYPE_CONTEXT (type)
20646 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20647 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20649 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20651 if (TREE_ASM_WRITTEN (type))
20654 /* If that failed, attach ourselves to the stub. */
20655 push_decl_scope (TYPE_CONTEXT (type));
20656 context_die = lookup_type_die (TYPE_CONTEXT (type));
20659 else if (TYPE_CONTEXT (type) != NULL_TREE
20660 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20662 /* If this type is local to a function that hasn't been written
20663 out yet, use a NULL context for now; it will be fixed up in
20664 decls_for_scope. */
20665 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20666 /* A declaration DIE doesn't count; nested types need to go in the
20668 if (context_die && is_declaration_die (context_die))
20669 context_die = NULL;
20674 context_die = declare_in_namespace (type, context_die);
20678 if (TREE_CODE (type) == ENUMERAL_TYPE)
20680 /* This might have been written out by the call to
20681 declare_in_namespace. */
20682 if (!TREE_ASM_WRITTEN (type))
20683 gen_enumeration_type_die (type, context_die);
20686 gen_struct_or_union_type_die (type, context_die, usage);
20691 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20692 it up if it is ever completed. gen_*_type_die will set it for us
20693 when appropriate. */
20696 /* Generate a type description DIE. */
20699 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20700 enum debug_info_usage usage)
20702 struct array_descr_info info;
20704 if (type == NULL_TREE || type == error_mark_node)
20707 if (TYPE_NAME (type) != NULL_TREE
20708 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20709 && is_redundant_typedef (TYPE_NAME (type))
20710 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20711 /* The DECL of this type is a typedef we don't want to emit debug
20712 info for but we want debug info for its underlying typedef.
20713 This can happen for e.g, the injected-class-name of a C++
20715 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20717 /* If TYPE is a typedef type variant, let's generate debug info
20718 for the parent typedef which TYPE is a type of. */
20719 if (typedef_variant_p (type))
20721 if (TREE_ASM_WRITTEN (type))
20724 /* Prevent broken recursion; we can't hand off to the same type. */
20725 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20727 /* Use the DIE of the containing namespace as the parent DIE of
20728 the type description DIE we want to generate. */
20729 if (DECL_CONTEXT (TYPE_NAME (type))
20730 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20731 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20733 TREE_ASM_WRITTEN (type) = 1;
20735 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20739 /* If type is an anonymous tagged type named by a typedef, let's
20740 generate debug info for the typedef. */
20741 if (is_naming_typedef_decl (TYPE_NAME (type)))
20743 /* Use the DIE of the containing namespace as the parent DIE of
20744 the type description DIE we want to generate. */
20745 if (DECL_CONTEXT (TYPE_NAME (type))
20746 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20747 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20749 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20753 /* If this is an array type with hidden descriptor, handle it first. */
20754 if (!TREE_ASM_WRITTEN (type)
20755 && lang_hooks.types.get_array_descr_info
20756 && lang_hooks.types.get_array_descr_info (type, &info)
20757 && (dwarf_version >= 3 || !dwarf_strict))
20759 gen_descr_array_type_die (type, &info, context_die);
20760 TREE_ASM_WRITTEN (type) = 1;
20764 /* We are going to output a DIE to represent the unqualified version
20765 of this type (i.e. without any const or volatile qualifiers) so
20766 get the main variant (i.e. the unqualified version) of this type
20767 now. (Vectors are special because the debugging info is in the
20768 cloned type itself). */
20769 if (TREE_CODE (type) != VECTOR_TYPE)
20770 type = type_main_variant (type);
20772 if (TREE_ASM_WRITTEN (type))
20775 switch (TREE_CODE (type))
20781 case REFERENCE_TYPE:
20782 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20783 ensures that the gen_type_die recursion will terminate even if the
20784 type is recursive. Recursive types are possible in Ada. */
20785 /* ??? We could perhaps do this for all types before the switch
20787 TREE_ASM_WRITTEN (type) = 1;
20789 /* For these types, all that is required is that we output a DIE (or a
20790 set of DIEs) to represent the "basis" type. */
20791 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20792 DINFO_USAGE_IND_USE);
20796 /* This code is used for C++ pointer-to-data-member types.
20797 Output a description of the relevant class type. */
20798 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20799 DINFO_USAGE_IND_USE);
20801 /* Output a description of the type of the object pointed to. */
20802 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20803 DINFO_USAGE_IND_USE);
20805 /* Now output a DIE to represent this pointer-to-data-member type
20807 gen_ptr_to_mbr_type_die (type, context_die);
20810 case FUNCTION_TYPE:
20811 /* Force out return type (in case it wasn't forced out already). */
20812 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20813 DINFO_USAGE_DIR_USE);
20814 gen_subroutine_type_die (type, context_die);
20818 /* Force out return type (in case it wasn't forced out already). */
20819 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20820 DINFO_USAGE_DIR_USE);
20821 gen_subroutine_type_die (type, context_die);
20825 gen_array_type_die (type, context_die);
20829 gen_array_type_die (type, context_die);
20832 case ENUMERAL_TYPE:
20835 case QUAL_UNION_TYPE:
20836 gen_tagged_type_die (type, context_die, usage);
20842 case FIXED_POINT_TYPE:
20845 /* No DIEs needed for fundamental types. */
20850 /* Just use DW_TAG_unspecified_type. */
20852 dw_die_ref type_die = lookup_type_die (type);
20853 if (type_die == NULL)
20855 tree name = TYPE_NAME (type);
20856 if (TREE_CODE (name) == TYPE_DECL)
20857 name = DECL_NAME (name);
20858 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20859 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20860 equate_type_number_to_die (type, type_die);
20866 gcc_unreachable ();
20869 TREE_ASM_WRITTEN (type) = 1;
20873 gen_type_die (tree type, dw_die_ref context_die)
20875 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20878 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20879 things which are local to the given block. */
20882 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20884 int must_output_die = 0;
20887 /* Ignore blocks that are NULL. */
20888 if (stmt == NULL_TREE)
20891 inlined_func = inlined_function_outer_scope_p (stmt);
20893 /* If the block is one fragment of a non-contiguous block, do not
20894 process the variables, since they will have been done by the
20895 origin block. Do process subblocks. */
20896 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20900 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20901 gen_block_die (sub, context_die, depth + 1);
20906 /* Determine if we need to output any Dwarf DIEs at all to represent this
20909 /* The outer scopes for inlinings *must* always be represented. We
20910 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20911 must_output_die = 1;
20914 /* Determine if this block directly contains any "significant"
20915 local declarations which we will need to output DIEs for. */
20916 if (debug_info_level > DINFO_LEVEL_TERSE)
20917 /* We are not in terse mode so *any* local declaration counts
20918 as being a "significant" one. */
20919 must_output_die = ((BLOCK_VARS (stmt) != NULL
20920 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20921 && (TREE_USED (stmt)
20922 || TREE_ASM_WRITTEN (stmt)
20923 || BLOCK_ABSTRACT (stmt)));
20924 else if ((TREE_USED (stmt)
20925 || TREE_ASM_WRITTEN (stmt)
20926 || BLOCK_ABSTRACT (stmt))
20927 && !dwarf2out_ignore_block (stmt))
20928 must_output_die = 1;
20931 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20932 DIE for any block which contains no significant local declarations at
20933 all. Rather, in such cases we just call `decls_for_scope' so that any
20934 needed Dwarf info for any sub-blocks will get properly generated. Note
20935 that in terse mode, our definition of what constitutes a "significant"
20936 local declaration gets restricted to include only inlined function
20937 instances and local (nested) function definitions. */
20938 if (must_output_die)
20942 /* If STMT block is abstract, that means we have been called
20943 indirectly from dwarf2out_abstract_function.
20944 That function rightfully marks the descendent blocks (of
20945 the abstract function it is dealing with) as being abstract,
20946 precisely to prevent us from emitting any
20947 DW_TAG_inlined_subroutine DIE as a descendent
20948 of an abstract function instance. So in that case, we should
20949 not call gen_inlined_subroutine_die.
20951 Later though, when cgraph asks dwarf2out to emit info
20952 for the concrete instance of the function decl into which
20953 the concrete instance of STMT got inlined, the later will lead
20954 to the generation of a DW_TAG_inlined_subroutine DIE. */
20955 if (! BLOCK_ABSTRACT (stmt))
20956 gen_inlined_subroutine_die (stmt, context_die, depth);
20959 gen_lexical_block_die (stmt, context_die, depth);
20962 decls_for_scope (stmt, context_die, depth);
20965 /* Process variable DECL (or variable with origin ORIGIN) within
20966 block STMT and add it to CONTEXT_DIE. */
20968 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20971 tree decl_or_origin = decl ? decl : origin;
20973 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20974 die = lookup_decl_die (decl_or_origin);
20975 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20976 && TYPE_DECL_IS_STUB (decl_or_origin))
20977 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20981 if (die != NULL && die->die_parent == NULL)
20982 add_child_die (context_die, die);
20983 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20984 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20985 stmt, context_die);
20987 gen_decl_die (decl, origin, context_die);
20990 /* Generate all of the decls declared within a given scope and (recursively)
20991 all of its sub-blocks. */
20994 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
21000 /* Ignore NULL blocks. */
21001 if (stmt == NULL_TREE)
21004 /* Output the DIEs to represent all of the data objects and typedefs
21005 declared directly within this block but not within any nested
21006 sub-blocks. Also, nested function and tag DIEs have been
21007 generated with a parent of NULL; fix that up now. */
21008 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
21009 process_scope_var (stmt, decl, NULL_TREE, context_die);
21010 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
21011 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
21014 /* If we're at -g1, we're not interested in subblocks. */
21015 if (debug_info_level <= DINFO_LEVEL_TERSE)
21018 /* Output the DIEs to represent all sub-blocks (and the items declared
21019 therein) of this block. */
21020 for (subblocks = BLOCK_SUBBLOCKS (stmt);
21022 subblocks = BLOCK_CHAIN (subblocks))
21023 gen_block_die (subblocks, context_die, depth + 1);
21026 /* Is this a typedef we can avoid emitting? */
21029 is_redundant_typedef (const_tree decl)
21031 if (TYPE_DECL_IS_STUB (decl))
21034 if (DECL_ARTIFICIAL (decl)
21035 && DECL_CONTEXT (decl)
21036 && is_tagged_type (DECL_CONTEXT (decl))
21037 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
21038 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
21039 /* Also ignore the artificial member typedef for the class name. */
21045 /* Return TRUE if TYPE is a typedef that names a type for linkage
21046 purposes. This kind of typedefs is produced by the C++ FE for
21049 typedef struct {...} foo;
21051 In that case, there is no typedef variant type produced for foo.
21052 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21056 is_naming_typedef_decl (const_tree decl)
21058 if (decl == NULL_TREE
21059 || TREE_CODE (decl) != TYPE_DECL
21060 || !is_tagged_type (TREE_TYPE (decl))
21061 || DECL_IS_BUILTIN (decl)
21062 || is_redundant_typedef (decl)
21063 /* It looks like Ada produces TYPE_DECLs that are very similar
21064 to C++ naming typedefs but that have different
21065 semantics. Let's be specific to c++ for now. */
21069 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
21070 && TYPE_NAME (TREE_TYPE (decl)) == decl
21071 && (TYPE_STUB_DECL (TREE_TYPE (decl))
21072 != TYPE_NAME (TREE_TYPE (decl))));
21075 /* Returns the DIE for a context. */
21077 static inline dw_die_ref
21078 get_context_die (tree context)
21082 /* Find die that represents this context. */
21083 if (TYPE_P (context))
21084 return force_type_die (TYPE_MAIN_VARIANT (context));
21086 return force_decl_die (context);
21088 return comp_unit_die ();
21091 /* Returns the DIE for decl. A DIE will always be returned. */
21094 force_decl_die (tree decl)
21096 dw_die_ref decl_die;
21097 unsigned saved_external_flag;
21098 tree save_fn = NULL_TREE;
21099 decl_die = lookup_decl_die (decl);
21102 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
21104 decl_die = lookup_decl_die (decl);
21108 switch (TREE_CODE (decl))
21110 case FUNCTION_DECL:
21111 /* Clear current_function_decl, so that gen_subprogram_die thinks
21112 that this is a declaration. At this point, we just want to force
21113 declaration die. */
21114 save_fn = current_function_decl;
21115 current_function_decl = NULL_TREE;
21116 gen_subprogram_die (decl, context_die);
21117 current_function_decl = save_fn;
21121 /* Set external flag to force declaration die. Restore it after
21122 gen_decl_die() call. */
21123 saved_external_flag = DECL_EXTERNAL (decl);
21124 DECL_EXTERNAL (decl) = 1;
21125 gen_decl_die (decl, NULL, context_die);
21126 DECL_EXTERNAL (decl) = saved_external_flag;
21129 case NAMESPACE_DECL:
21130 if (dwarf_version >= 3 || !dwarf_strict)
21131 dwarf2out_decl (decl);
21133 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21134 decl_die = comp_unit_die ();
21137 case TRANSLATION_UNIT_DECL:
21138 decl_die = comp_unit_die ();
21142 gcc_unreachable ();
21145 /* We should be able to find the DIE now. */
21147 decl_die = lookup_decl_die (decl);
21148 gcc_assert (decl_die);
21154 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21155 always returned. */
21158 force_type_die (tree type)
21160 dw_die_ref type_die;
21162 type_die = lookup_type_die (type);
21165 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21167 type_die = modified_type_die (type, TYPE_READONLY (type),
21168 TYPE_VOLATILE (type), context_die);
21169 gcc_assert (type_die);
21174 /* Force out any required namespaces to be able to output DECL,
21175 and return the new context_die for it, if it's changed. */
21178 setup_namespace_context (tree thing, dw_die_ref context_die)
21180 tree context = (DECL_P (thing)
21181 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21182 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21183 /* Force out the namespace. */
21184 context_die = force_decl_die (context);
21186 return context_die;
21189 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21190 type) within its namespace, if appropriate.
21192 For compatibility with older debuggers, namespace DIEs only contain
21193 declarations; all definitions are emitted at CU scope. */
21196 declare_in_namespace (tree thing, dw_die_ref context_die)
21198 dw_die_ref ns_context;
21200 if (debug_info_level <= DINFO_LEVEL_TERSE)
21201 return context_die;
21203 /* If this decl is from an inlined function, then don't try to emit it in its
21204 namespace, as we will get confused. It would have already been emitted
21205 when the abstract instance of the inline function was emitted anyways. */
21206 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21207 return context_die;
21209 ns_context = setup_namespace_context (thing, context_die);
21211 if (ns_context != context_die)
21215 if (DECL_P (thing))
21216 gen_decl_die (thing, NULL, ns_context);
21218 gen_type_die (thing, ns_context);
21220 return context_die;
21223 /* Generate a DIE for a namespace or namespace alias. */
21226 gen_namespace_die (tree decl, dw_die_ref context_die)
21228 dw_die_ref namespace_die;
21230 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21231 they are an alias of. */
21232 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21234 /* Output a real namespace or module. */
21235 context_die = setup_namespace_context (decl, comp_unit_die ());
21236 namespace_die = new_die (is_fortran ()
21237 ? DW_TAG_module : DW_TAG_namespace,
21238 context_die, decl);
21239 /* For Fortran modules defined in different CU don't add src coords. */
21240 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21242 const char *name = dwarf2_name (decl, 0);
21244 add_name_attribute (namespace_die, name);
21247 add_name_and_src_coords_attributes (namespace_die, decl);
21248 if (DECL_EXTERNAL (decl))
21249 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21250 equate_decl_number_to_die (decl, namespace_die);
21254 /* Output a namespace alias. */
21256 /* Force out the namespace we are an alias of, if necessary. */
21257 dw_die_ref origin_die
21258 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21260 if (DECL_FILE_SCOPE_P (decl)
21261 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21262 context_die = setup_namespace_context (decl, comp_unit_die ());
21263 /* Now create the namespace alias DIE. */
21264 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21265 add_name_and_src_coords_attributes (namespace_die, decl);
21266 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21267 equate_decl_number_to_die (decl, namespace_die);
21271 /* Generate Dwarf debug information for a decl described by DECL.
21272 The return value is currently only meaningful for PARM_DECLs,
21273 for all other decls it returns NULL. */
21276 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21278 tree decl_or_origin = decl ? decl : origin;
21279 tree class_origin = NULL, ultimate_origin;
21281 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21284 switch (TREE_CODE (decl_or_origin))
21290 if (!is_fortran () && !is_ada ())
21292 /* The individual enumerators of an enum type get output when we output
21293 the Dwarf representation of the relevant enum type itself. */
21297 /* Emit its type. */
21298 gen_type_die (TREE_TYPE (decl), context_die);
21300 /* And its containing namespace. */
21301 context_die = declare_in_namespace (decl, context_die);
21303 gen_const_die (decl, context_die);
21306 case FUNCTION_DECL:
21307 /* Don't output any DIEs to represent mere function declarations,
21308 unless they are class members or explicit block externs. */
21309 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21310 && DECL_FILE_SCOPE_P (decl_or_origin)
21311 && (current_function_decl == NULL_TREE
21312 || DECL_ARTIFICIAL (decl_or_origin)))
21317 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21318 on local redeclarations of global functions. That seems broken. */
21319 if (current_function_decl != decl)
21320 /* This is only a declaration. */;
21323 /* If we're emitting a clone, emit info for the abstract instance. */
21324 if (origin || DECL_ORIGIN (decl) != decl)
21325 dwarf2out_abstract_function (origin
21326 ? DECL_ORIGIN (origin)
21327 : DECL_ABSTRACT_ORIGIN (decl));
21329 /* If we're emitting an out-of-line copy of an inline function,
21330 emit info for the abstract instance and set up to refer to it. */
21331 else if (cgraph_function_possibly_inlined_p (decl)
21332 && ! DECL_ABSTRACT (decl)
21333 && ! class_or_namespace_scope_p (context_die)
21334 /* dwarf2out_abstract_function won't emit a die if this is just
21335 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21336 that case, because that works only if we have a die. */
21337 && DECL_INITIAL (decl) != NULL_TREE)
21339 dwarf2out_abstract_function (decl);
21340 set_decl_origin_self (decl);
21343 /* Otherwise we're emitting the primary DIE for this decl. */
21344 else if (debug_info_level > DINFO_LEVEL_TERSE)
21346 /* Before we describe the FUNCTION_DECL itself, make sure that we
21347 have its containing type. */
21349 origin = decl_class_context (decl);
21350 if (origin != NULL_TREE)
21351 gen_type_die (origin, context_die);
21353 /* And its return type. */
21354 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21356 /* And its virtual context. */
21357 if (DECL_VINDEX (decl) != NULL_TREE)
21358 gen_type_die (DECL_CONTEXT (decl), context_die);
21360 /* Make sure we have a member DIE for decl. */
21361 if (origin != NULL_TREE)
21362 gen_type_die_for_member (origin, decl, context_die);
21364 /* And its containing namespace. */
21365 context_die = declare_in_namespace (decl, context_die);
21368 /* Now output a DIE to represent the function itself. */
21370 gen_subprogram_die (decl, context_die);
21374 /* If we are in terse mode, don't generate any DIEs to represent any
21375 actual typedefs. */
21376 if (debug_info_level <= DINFO_LEVEL_TERSE)
21379 /* In the special case of a TYPE_DECL node representing the declaration
21380 of some type tag, if the given TYPE_DECL is marked as having been
21381 instantiated from some other (original) TYPE_DECL node (e.g. one which
21382 was generated within the original definition of an inline function) we
21383 used to generate a special (abbreviated) DW_TAG_structure_type,
21384 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21385 should be actually referencing those DIEs, as variable DIEs with that
21386 type would be emitted already in the abstract origin, so it was always
21387 removed during unused type prunning. Don't add anything in this
21389 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21392 if (is_redundant_typedef (decl))
21393 gen_type_die (TREE_TYPE (decl), context_die);
21395 /* Output a DIE to represent the typedef itself. */
21396 gen_typedef_die (decl, context_die);
21400 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21401 gen_label_die (decl, context_die);
21406 /* If we are in terse mode, don't generate any DIEs to represent any
21407 variable declarations or definitions. */
21408 if (debug_info_level <= DINFO_LEVEL_TERSE)
21411 /* Output any DIEs that are needed to specify the type of this data
21413 if (decl_by_reference_p (decl_or_origin))
21414 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21416 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21418 /* And its containing type. */
21419 class_origin = decl_class_context (decl_or_origin);
21420 if (class_origin != NULL_TREE)
21421 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21423 /* And its containing namespace. */
21424 context_die = declare_in_namespace (decl_or_origin, context_die);
21426 /* Now output the DIE to represent the data object itself. This gets
21427 complicated because of the possibility that the VAR_DECL really
21428 represents an inlined instance of a formal parameter for an inline
21430 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21431 if (ultimate_origin != NULL_TREE
21432 && TREE_CODE (ultimate_origin) == PARM_DECL)
21433 gen_formal_parameter_die (decl, origin,
21434 true /* Emit name attribute. */,
21437 gen_variable_die (decl, origin, context_die);
21441 /* Ignore the nameless fields that are used to skip bits but handle C++
21442 anonymous unions and structs. */
21443 if (DECL_NAME (decl) != NULL_TREE
21444 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21445 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21447 gen_type_die (member_declared_type (decl), context_die);
21448 gen_field_die (decl, context_die);
21453 if (DECL_BY_REFERENCE (decl_or_origin))
21454 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21456 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21457 return gen_formal_parameter_die (decl, origin,
21458 true /* Emit name attribute. */,
21461 case NAMESPACE_DECL:
21462 case IMPORTED_DECL:
21463 if (dwarf_version >= 3 || !dwarf_strict)
21464 gen_namespace_die (decl, context_die);
21468 /* Probably some frontend-internal decl. Assume we don't care. */
21469 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21476 /* Output debug information for global decl DECL. Called from toplev.c after
21477 compilation proper has finished. */
21480 dwarf2out_global_decl (tree decl)
21482 /* Output DWARF2 information for file-scope tentative data object
21483 declarations, file-scope (extern) function declarations (which
21484 had no corresponding body) and file-scope tagged type declarations
21485 and definitions which have not yet been forced out. */
21486 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21487 dwarf2out_decl (decl);
21490 /* Output debug information for type decl DECL. Called from toplev.c
21491 and from language front ends (to record built-in types). */
21493 dwarf2out_type_decl (tree decl, int local)
21496 dwarf2out_decl (decl);
21499 /* Output debug information for imported module or decl DECL.
21500 NAME is non-NULL name in the lexical block if the decl has been renamed.
21501 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21502 that DECL belongs to.
21503 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21505 dwarf2out_imported_module_or_decl_1 (tree decl,
21507 tree lexical_block,
21508 dw_die_ref lexical_block_die)
21510 expanded_location xloc;
21511 dw_die_ref imported_die = NULL;
21512 dw_die_ref at_import_die;
21514 if (TREE_CODE (decl) == IMPORTED_DECL)
21516 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21517 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21521 xloc = expand_location (input_location);
21523 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21525 at_import_die = force_type_die (TREE_TYPE (decl));
21526 /* For namespace N { typedef void T; } using N::T; base_type_die
21527 returns NULL, but DW_TAG_imported_declaration requires
21528 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21529 if (!at_import_die)
21531 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21532 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21533 at_import_die = lookup_type_die (TREE_TYPE (decl));
21534 gcc_assert (at_import_die);
21539 at_import_die = lookup_decl_die (decl);
21540 if (!at_import_die)
21542 /* If we're trying to avoid duplicate debug info, we may not have
21543 emitted the member decl for this field. Emit it now. */
21544 if (TREE_CODE (decl) == FIELD_DECL)
21546 tree type = DECL_CONTEXT (decl);
21548 if (TYPE_CONTEXT (type)
21549 && TYPE_P (TYPE_CONTEXT (type))
21550 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21551 DINFO_USAGE_DIR_USE))
21553 gen_type_die_for_member (type, decl,
21554 get_context_die (TYPE_CONTEXT (type)));
21556 at_import_die = force_decl_die (decl);
21560 if (TREE_CODE (decl) == NAMESPACE_DECL)
21562 if (dwarf_version >= 3 || !dwarf_strict)
21563 imported_die = new_die (DW_TAG_imported_module,
21570 imported_die = new_die (DW_TAG_imported_declaration,
21574 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21575 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21577 add_AT_string (imported_die, DW_AT_name,
21578 IDENTIFIER_POINTER (name));
21579 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21582 /* Output debug information for imported module or decl DECL.
21583 NAME is non-NULL name in context if the decl has been renamed.
21584 CHILD is true if decl is one of the renamed decls as part of
21585 importing whole module. */
21588 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21591 /* dw_die_ref at_import_die; */
21592 dw_die_ref scope_die;
21594 if (debug_info_level <= DINFO_LEVEL_TERSE)
21599 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21600 We need decl DIE for reference and scope die. First, get DIE for the decl
21603 /* Get the scope die for decl context. Use comp_unit_die for global module
21604 or decl. If die is not found for non globals, force new die. */
21606 && TYPE_P (context)
21607 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21610 if (!(dwarf_version >= 3 || !dwarf_strict))
21613 scope_die = get_context_die (context);
21617 gcc_assert (scope_die->die_child);
21618 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21619 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21620 scope_die = scope_die->die_child;
21623 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21624 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21628 /* Write the debugging output for DECL. */
21631 dwarf2out_decl (tree decl)
21633 dw_die_ref context_die = comp_unit_die ();
21635 switch (TREE_CODE (decl))
21640 case FUNCTION_DECL:
21641 /* What we would really like to do here is to filter out all mere
21642 file-scope declarations of file-scope functions which are never
21643 referenced later within this translation unit (and keep all of ones
21644 that *are* referenced later on) but we aren't clairvoyant, so we have
21645 no idea which functions will be referenced in the future (i.e. later
21646 on within the current translation unit). So here we just ignore all
21647 file-scope function declarations which are not also definitions. If
21648 and when the debugger needs to know something about these functions,
21649 it will have to hunt around and find the DWARF information associated
21650 with the definition of the function.
21652 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21653 nodes represent definitions and which ones represent mere
21654 declarations. We have to check DECL_INITIAL instead. That's because
21655 the C front-end supports some weird semantics for "extern inline"
21656 function definitions. These can get inlined within the current
21657 translation unit (and thus, we need to generate Dwarf info for their
21658 abstract instances so that the Dwarf info for the concrete inlined
21659 instances can have something to refer to) but the compiler never
21660 generates any out-of-lines instances of such things (despite the fact
21661 that they *are* definitions).
21663 The important point is that the C front-end marks these "extern
21664 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21665 them anyway. Note that the C++ front-end also plays some similar games
21666 for inline function definitions appearing within include files which
21667 also contain `#pragma interface' pragmas. */
21668 if (DECL_INITIAL (decl) == NULL_TREE)
21671 /* If we're a nested function, initially use a parent of NULL; if we're
21672 a plain function, this will be fixed up in decls_for_scope. If
21673 we're a method, it will be ignored, since we already have a DIE. */
21674 if (decl_function_context (decl)
21675 /* But if we're in terse mode, we don't care about scope. */
21676 && debug_info_level > DINFO_LEVEL_TERSE)
21677 context_die = NULL;
21681 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21682 declaration and if the declaration was never even referenced from
21683 within this entire compilation unit. We suppress these DIEs in
21684 order to save space in the .debug section (by eliminating entries
21685 which are probably useless). Note that we must not suppress
21686 block-local extern declarations (whether used or not) because that
21687 would screw-up the debugger's name lookup mechanism and cause it to
21688 miss things which really ought to be in scope at a given point. */
21689 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21692 /* For local statics lookup proper context die. */
21693 if (TREE_STATIC (decl) && decl_function_context (decl))
21694 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21696 /* If we are in terse mode, don't generate any DIEs to represent any
21697 variable declarations or definitions. */
21698 if (debug_info_level <= DINFO_LEVEL_TERSE)
21703 if (debug_info_level <= DINFO_LEVEL_TERSE)
21705 if (!is_fortran () && !is_ada ())
21707 if (TREE_STATIC (decl) && decl_function_context (decl))
21708 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21711 case NAMESPACE_DECL:
21712 case IMPORTED_DECL:
21713 if (debug_info_level <= DINFO_LEVEL_TERSE)
21715 if (lookup_decl_die (decl) != NULL)
21720 /* Don't emit stubs for types unless they are needed by other DIEs. */
21721 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21724 /* Don't bother trying to generate any DIEs to represent any of the
21725 normal built-in types for the language we are compiling. */
21726 if (DECL_IS_BUILTIN (decl))
21729 /* If we are in terse mode, don't generate any DIEs for types. */
21730 if (debug_info_level <= DINFO_LEVEL_TERSE)
21733 /* If we're a function-scope tag, initially use a parent of NULL;
21734 this will be fixed up in decls_for_scope. */
21735 if (decl_function_context (decl))
21736 context_die = NULL;
21744 gen_decl_die (decl, NULL, context_die);
21747 /* Write the debugging output for DECL. */
21750 dwarf2out_function_decl (tree decl)
21752 dwarf2out_decl (decl);
21753 call_arg_locations = NULL;
21754 call_arg_loc_last = NULL;
21755 call_site_count = -1;
21756 tail_call_site_count = -1;
21757 VEC_free (dw_die_ref, heap, block_map);
21758 htab_empty (decl_loc_table);
21761 /* Output a marker (i.e. a label) for the beginning of the generated code for
21762 a lexical block. */
21765 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21766 unsigned int blocknum)
21768 switch_to_section (current_function_section ());
21769 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21772 /* Output a marker (i.e. a label) for the end of the generated code for a
21776 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21778 switch_to_section (current_function_section ());
21779 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21782 /* Returns nonzero if it is appropriate not to emit any debugging
21783 information for BLOCK, because it doesn't contain any instructions.
21785 Don't allow this for blocks with nested functions or local classes
21786 as we would end up with orphans, and in the presence of scheduling
21787 we may end up calling them anyway. */
21790 dwarf2out_ignore_block (const_tree block)
21795 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21796 if (TREE_CODE (decl) == FUNCTION_DECL
21797 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21799 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21801 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21802 if (TREE_CODE (decl) == FUNCTION_DECL
21803 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21810 /* Hash table routines for file_hash. */
21813 file_table_eq (const void *p1_p, const void *p2_p)
21815 const struct dwarf_file_data *const p1 =
21816 (const struct dwarf_file_data *) p1_p;
21817 const char *const p2 = (const char *) p2_p;
21818 return filename_cmp (p1->filename, p2) == 0;
21822 file_table_hash (const void *p_p)
21824 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21825 return htab_hash_string (p->filename);
21828 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21829 dwarf2out.c) and return its "index". The index of each (known) filename is
21830 just a unique number which is associated with only that one filename. We
21831 need such numbers for the sake of generating labels (in the .debug_sfnames
21832 section) and references to those files numbers (in the .debug_srcinfo
21833 and.debug_macinfo sections). If the filename given as an argument is not
21834 found in our current list, add it to the list and assign it the next
21835 available unique index number. In order to speed up searches, we remember
21836 the index of the filename was looked up last. This handles the majority of
21839 static struct dwarf_file_data *
21840 lookup_filename (const char *file_name)
21843 struct dwarf_file_data * created;
21845 /* Check to see if the file name that was searched on the previous
21846 call matches this file name. If so, return the index. */
21847 if (file_table_last_lookup
21848 && (file_name == file_table_last_lookup->filename
21849 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21850 return file_table_last_lookup;
21852 /* Didn't match the previous lookup, search the table. */
21853 slot = htab_find_slot_with_hash (file_table, file_name,
21854 htab_hash_string (file_name), INSERT);
21856 return (struct dwarf_file_data *) *slot;
21858 created = ggc_alloc_dwarf_file_data ();
21859 created->filename = file_name;
21860 created->emitted_number = 0;
21865 /* If the assembler will construct the file table, then translate the compiler
21866 internal file table number into the assembler file table number, and emit
21867 a .file directive if we haven't already emitted one yet. The file table
21868 numbers are different because we prune debug info for unused variables and
21869 types, which may include filenames. */
21872 maybe_emit_file (struct dwarf_file_data * fd)
21874 if (! fd->emitted_number)
21876 if (last_emitted_file)
21877 fd->emitted_number = last_emitted_file->emitted_number + 1;
21879 fd->emitted_number = 1;
21880 last_emitted_file = fd;
21882 if (DWARF2_ASM_LINE_DEBUG_INFO)
21884 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21885 output_quoted_string (asm_out_file,
21886 remap_debug_filename (fd->filename));
21887 fputc ('\n', asm_out_file);
21891 return fd->emitted_number;
21894 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21895 That generation should happen after function debug info has been
21896 generated. The value of the attribute is the constant value of ARG. */
21899 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21901 die_arg_entry entry;
21906 if (!tmpl_value_parm_die_table)
21907 tmpl_value_parm_die_table
21908 = VEC_alloc (die_arg_entry, gc, 32);
21912 VEC_safe_push (die_arg_entry, gc,
21913 tmpl_value_parm_die_table,
21917 /* Return TRUE if T is an instance of generic type, FALSE
21921 generic_type_p (tree t)
21923 if (t == NULL_TREE || !TYPE_P (t))
21925 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21928 /* Schedule the generation of the generic parameter dies for the
21929 instance of generic type T. The proper generation itself is later
21930 done by gen_scheduled_generic_parms_dies. */
21933 schedule_generic_params_dies_gen (tree t)
21935 if (!generic_type_p (t))
21938 if (generic_type_instances == NULL)
21939 generic_type_instances = VEC_alloc (tree, gc, 256);
21941 VEC_safe_push (tree, gc, generic_type_instances, t);
21944 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21945 by append_entry_to_tmpl_value_parm_die_table. This function must
21946 be called after function DIEs have been generated. */
21949 gen_remaining_tmpl_value_param_die_attribute (void)
21951 if (tmpl_value_parm_die_table)
21956 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21957 tree_add_const_value_attribute (e->die, e->arg);
21961 /* Generate generic parameters DIEs for instances of generic types
21962 that have been previously scheduled by
21963 schedule_generic_params_dies_gen. This function must be called
21964 after all the types of the CU have been laid out. */
21967 gen_scheduled_generic_parms_dies (void)
21972 if (generic_type_instances == NULL)
21975 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21976 gen_generic_params_dies (t);
21980 /* Replace DW_AT_name for the decl with name. */
21983 dwarf2out_set_name (tree decl, tree name)
21989 die = TYPE_SYMTAB_DIE (decl);
21993 dname = dwarf2_name (name, 0);
21997 attr = get_AT (die, DW_AT_name);
22000 struct indirect_string_node *node;
22002 node = find_AT_string (dname);
22003 /* replace the string. */
22004 attr->dw_attr_val.v.val_str = node;
22008 add_name_attribute (die, dname);
22011 /* Called by the final INSN scan whenever we see a direct function call.
22012 Make an entry into the direct call table, recording the point of call
22013 and a reference to the target function's debug entry. */
22016 dwarf2out_direct_call (tree targ)
22019 tree origin = decl_ultimate_origin (targ);
22021 /* If this is a clone, use the abstract origin as the target. */
22025 e.poc_label_num = poc_label_num++;
22026 e.poc_decl = current_function_decl;
22027 e.targ_die = force_decl_die (targ);
22028 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
22030 /* Drop a label at the return point to mark the point of call. */
22031 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
22034 /* Returns a hash value for X (which really is a struct vcall_insn). */
22037 vcall_insn_table_hash (const void *x)
22039 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
22042 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
22043 insnd_uid of *Y. */
22046 vcall_insn_table_eq (const void *x, const void *y)
22048 return (((const struct vcall_insn *) x)->insn_uid
22049 == ((const struct vcall_insn *) y)->insn_uid);
22052 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
22055 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
22057 struct vcall_insn *item = ggc_alloc_vcall_insn ();
22058 struct vcall_insn **slot;
22061 item->insn_uid = insn_uid;
22062 item->vtable_slot = vtable_slot;
22063 slot = (struct vcall_insn **)
22064 htab_find_slot_with_hash (vcall_insn_table, &item,
22065 (hashval_t) insn_uid, INSERT);
22069 /* Return the VTABLE_SLOT associated with INSN_UID. */
22071 static unsigned int
22072 lookup_vcall_insn (unsigned int insn_uid)
22074 struct vcall_insn item;
22075 struct vcall_insn *p;
22077 item.insn_uid = insn_uid;
22078 item.vtable_slot = 0;
22079 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
22081 (hashval_t) insn_uid);
22083 return (unsigned int) -1;
22084 return p->vtable_slot;
22088 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
22089 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
22090 is the vtable slot index that we will need to put in the virtual call
22094 dwarf2out_virtual_call_token (tree addr, int insn_uid)
22096 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
22098 tree token = OBJ_TYPE_REF_TOKEN (addr);
22099 if (TREE_CODE (token) == INTEGER_CST)
22100 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
22104 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
22105 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
22109 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
22111 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
22113 if (vtable_slot != (unsigned int) -1)
22114 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
22117 /* Called by the final INSN scan whenever we see a virtual function call.
22118 Make an entry into the virtual call table, recording the point of call
22119 and the slot index of the vtable entry used to call the virtual member
22120 function. The slot index was associated with the INSN_UID during the
22121 lowering to RTL. */
22124 dwarf2out_virtual_call (int insn_uid)
22126 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
22129 if (vtable_slot == (unsigned int) -1)
22132 e.poc_label_num = poc_label_num++;
22133 e.vtable_slot = vtable_slot;
22134 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
22136 /* Drop a label at the return point to mark the point of call. */
22137 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
22140 /* Called by the final INSN scan whenever we see a var location. We
22141 use it to drop labels in the right places, and throw the location in
22142 our lookup table. */
22145 dwarf2out_var_location (rtx loc_note)
22147 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
22148 struct var_loc_node *newloc;
22150 static const char *last_label;
22151 static const char *last_postcall_label;
22152 static bool last_in_cold_section_p;
22156 if (!NOTE_P (loc_note))
22158 if (CALL_P (loc_note))
22161 if (SIBLING_CALL_P (loc_note))
22162 tail_call_site_count++;
22167 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
22168 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
22171 next_real = next_real_insn (loc_note);
22173 /* If there are no instructions which would be affected by this note,
22174 don't do anything. */
22176 && next_real == NULL_RTX
22177 && !NOTE_DURING_CALL_P (loc_note))
22180 if (next_real == NULL_RTX)
22181 next_real = get_last_insn ();
22183 /* If there were any real insns between note we processed last time
22184 and this note (or if it is the first note), clear
22185 last_{,postcall_}label so that they are not reused this time. */
22186 if (last_var_location_insn == NULL_RTX
22187 || last_var_location_insn != next_real
22188 || last_in_cold_section_p != in_cold_section_p)
22191 last_postcall_label = NULL;
22196 decl = NOTE_VAR_LOCATION_DECL (loc_note);
22197 newloc = add_var_loc_to_decl (decl, loc_note,
22198 NOTE_DURING_CALL_P (loc_note)
22199 ? last_postcall_label : last_label);
22200 if (newloc == NULL)
22209 /* If there were no real insns between note we processed last time
22210 and this note, use the label we emitted last time. Otherwise
22211 create a new label and emit it. */
22212 if (last_label == NULL)
22214 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
22215 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
22217 last_label = ggc_strdup (loclabel);
22222 struct call_arg_loc_node *ca_loc
22223 = ggc_alloc_cleared_call_arg_loc_node ();
22224 rtx prev = prev_real_insn (loc_note), x;
22225 ca_loc->call_arg_loc_note = loc_note;
22226 ca_loc->next = NULL;
22227 ca_loc->label = last_label;
22230 || (NONJUMP_INSN_P (prev)
22231 && GET_CODE (PATTERN (prev)) == SEQUENCE
22232 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
22233 if (!CALL_P (prev))
22234 prev = XVECEXP (PATTERN (prev), 0, 0);
22235 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
22236 x = PATTERN (prev);
22237 if (GET_CODE (x) == PARALLEL)
22238 x = XVECEXP (x, 0, 0);
22239 if (GET_CODE (x) == SET)
22241 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
22243 x = XEXP (XEXP (x, 0), 0);
22244 if (GET_CODE (x) == SYMBOL_REF
22245 && SYMBOL_REF_DECL (x)
22246 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22247 ca_loc->symbol_ref = x;
22249 ca_loc->block = insn_scope (prev);
22250 if (call_arg_locations)
22251 call_arg_loc_last->next = ca_loc;
22253 call_arg_locations = ca_loc;
22254 call_arg_loc_last = ca_loc;
22256 else if (!NOTE_DURING_CALL_P (loc_note))
22257 newloc->label = last_label;
22260 if (!last_postcall_label)
22262 sprintf (loclabel, "%s-1", last_label);
22263 last_postcall_label = ggc_strdup (loclabel);
22265 newloc->label = last_postcall_label;
22268 last_var_location_insn = next_real;
22269 last_in_cold_section_p = in_cold_section_p;
22272 /* We need to reset the locations at the beginning of each
22273 function. We can't do this in the end_function hook, because the
22274 declarations that use the locations won't have been output when
22275 that hook is called. Also compute have_multiple_function_sections here. */
22278 dwarf2out_begin_function (tree fun)
22280 if (function_section (fun) != text_section)
22281 have_multiple_function_sections = true;
22282 else if (flag_reorder_blocks_and_partition && !cold_text_section)
22284 gcc_assert (current_function_decl == fun);
22285 cold_text_section = unlikely_text_section ();
22286 switch_to_section (cold_text_section);
22287 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22288 switch_to_section (current_function_section ());
22291 dwarf2out_note_section_used ();
22292 call_site_count = 0;
22293 tail_call_site_count = 0;
22296 /* Output a label to mark the beginning of a source code line entry
22297 and record information relating to this source line, in
22298 'line_info_table' for later output of the .debug_line section. */
22301 dwarf2out_source_line (unsigned int line, const char *filename,
22302 int discriminator, bool is_stmt)
22304 static bool last_is_stmt = true;
22306 if (debug_info_level >= DINFO_LEVEL_NORMAL
22309 int file_num = maybe_emit_file (lookup_filename (filename));
22311 switch_to_section (current_function_section ());
22313 /* If requested, emit something human-readable. */
22314 if (flag_debug_asm)
22315 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
22318 if (DWARF2_ASM_LINE_DEBUG_INFO)
22320 /* Emit the .loc directive understood by GNU as. */
22321 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22322 if (is_stmt != last_is_stmt)
22324 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22325 last_is_stmt = is_stmt;
22327 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22328 fprintf (asm_out_file, " discriminator %d", discriminator);
22329 fputc ('\n', asm_out_file);
22331 /* Indicate that line number info exists. */
22332 line_info_table_in_use++;
22334 else if (function_section (current_function_decl) != text_section)
22336 dw_separate_line_info_ref line_info;
22337 targetm.asm_out.internal_label (asm_out_file,
22338 SEPARATE_LINE_CODE_LABEL,
22339 separate_line_info_table_in_use);
22341 /* Expand the line info table if necessary. */
22342 if (separate_line_info_table_in_use
22343 == separate_line_info_table_allocated)
22345 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22346 separate_line_info_table
22347 = GGC_RESIZEVEC (dw_separate_line_info_entry,
22348 separate_line_info_table,
22349 separate_line_info_table_allocated);
22350 memset (separate_line_info_table
22351 + separate_line_info_table_in_use,
22353 (LINE_INFO_TABLE_INCREMENT
22354 * sizeof (dw_separate_line_info_entry)));
22357 /* Add the new entry at the end of the line_info_table. */
22359 = &separate_line_info_table[separate_line_info_table_in_use++];
22360 line_info->dw_file_num = file_num;
22361 line_info->dw_line_num = line;
22362 line_info->function = current_function_funcdef_no;
22366 dw_line_info_ref line_info;
22368 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
22369 line_info_table_in_use);
22371 /* Expand the line info table if necessary. */
22372 if (line_info_table_in_use == line_info_table_allocated)
22374 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
22376 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
22377 line_info_table_allocated);
22378 memset (line_info_table + line_info_table_in_use, 0,
22379 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
22382 /* Add the new entry at the end of the line_info_table. */
22383 line_info = &line_info_table[line_info_table_in_use++];
22384 line_info->dw_file_num = file_num;
22385 line_info->dw_line_num = line;
22390 /* Record the beginning of a new source file. */
22393 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22395 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22397 /* Record the beginning of the file for break_out_includes. */
22398 dw_die_ref bincl_die;
22400 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22401 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22404 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22407 e.code = DW_MACINFO_start_file;
22409 e.info = xstrdup (filename);
22410 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22414 /* Record the end of a source file. */
22417 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22419 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
22420 /* Record the end of the file for break_out_includes. */
22421 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22423 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22426 e.code = DW_MACINFO_end_file;
22429 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22433 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22434 the tail part of the directive line, i.e. the part which is past the
22435 initial whitespace, #, whitespace, directive-name, whitespace part. */
22438 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22439 const char *buffer ATTRIBUTE_UNUSED)
22441 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22444 e.code = DW_MACINFO_define;
22446 e.info = xstrdup (buffer);;
22447 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22451 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22452 the tail part of the directive line, i.e. the part which is past the
22453 initial whitespace, #, whitespace, directive-name, whitespace part. */
22456 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22457 const char *buffer ATTRIBUTE_UNUSED)
22459 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22462 e.code = DW_MACINFO_undef;
22464 e.info = xstrdup (buffer);;
22465 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22470 output_macinfo (void)
22473 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22474 macinfo_entry *ref;
22479 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22483 case DW_MACINFO_start_file:
22485 int file_num = maybe_emit_file (lookup_filename (ref->info));
22486 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22487 dw2_asm_output_data_uleb128
22488 (ref->lineno, "Included from line number %lu",
22489 (unsigned long)ref->lineno);
22490 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22493 case DW_MACINFO_end_file:
22494 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22496 case DW_MACINFO_define:
22497 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22498 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22499 (unsigned long)ref->lineno);
22500 dw2_asm_output_nstring (ref->info, -1, "The macro");
22502 case DW_MACINFO_undef:
22503 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22504 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22505 (unsigned long)ref->lineno);
22506 dw2_asm_output_nstring (ref->info, -1, "The macro");
22509 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22510 ASM_COMMENT_START, (unsigned long)ref->code);
22516 /* Set up for Dwarf output at the start of compilation. */
22519 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22521 /* Allocate the file_table. */
22522 file_table = htab_create_ggc (50, file_table_hash,
22523 file_table_eq, NULL);
22525 /* Allocate the decl_die_table. */
22526 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22527 decl_die_table_eq, NULL);
22529 /* Allocate the decl_loc_table. */
22530 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22531 decl_loc_table_eq, NULL);
22533 /* Allocate the initial hunk of the decl_scope_table. */
22534 decl_scope_table = VEC_alloc (tree, gc, 256);
22536 /* Allocate the initial hunk of the abbrev_die_table. */
22537 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22538 (ABBREV_DIE_TABLE_INCREMENT);
22539 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22540 /* Zero-th entry is allocated, but unused. */
22541 abbrev_die_table_in_use = 1;
22543 /* Allocate the initial hunk of the line_info_table. */
22544 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
22545 (LINE_INFO_TABLE_INCREMENT);
22546 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
22548 /* Zero-th entry is allocated, but unused. */
22549 line_info_table_in_use = 1;
22551 /* Allocate the pubtypes and pubnames vectors. */
22552 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22553 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22555 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
22556 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
22557 vcall_insn_table_eq, NULL);
22559 incomplete_types = VEC_alloc (tree, gc, 64);
22561 used_rtx_array = VEC_alloc (rtx, gc, 32);
22563 debug_info_section = get_section (DEBUG_INFO_SECTION,
22564 SECTION_DEBUG, NULL);
22565 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22566 SECTION_DEBUG, NULL);
22567 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22568 SECTION_DEBUG, NULL);
22569 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22570 SECTION_DEBUG, NULL);
22571 debug_line_section = get_section (DEBUG_LINE_SECTION,
22572 SECTION_DEBUG, NULL);
22573 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22574 SECTION_DEBUG, NULL);
22575 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22576 SECTION_DEBUG, NULL);
22577 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22578 SECTION_DEBUG, NULL);
22579 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
22580 SECTION_DEBUG, NULL);
22581 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
22582 SECTION_DEBUG, NULL);
22583 debug_str_section = get_section (DEBUG_STR_SECTION,
22584 DEBUG_STR_SECTION_FLAGS, NULL);
22585 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22586 SECTION_DEBUG, NULL);
22587 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22588 SECTION_DEBUG, NULL);
22590 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22591 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22592 DEBUG_ABBREV_SECTION_LABEL, 0);
22593 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22594 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22595 COLD_TEXT_SECTION_LABEL, 0);
22596 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22598 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22599 DEBUG_INFO_SECTION_LABEL, 0);
22600 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22601 DEBUG_LINE_SECTION_LABEL, 0);
22602 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22603 DEBUG_RANGES_SECTION_LABEL, 0);
22604 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22605 DEBUG_MACINFO_SECTION_LABEL, 0);
22607 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22608 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22610 switch_to_section (text_section);
22611 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22614 /* Called before cgraph_optimize starts outputtting functions, variables
22615 and toplevel asms into assembly. */
22618 dwarf2out_assembly_start (void)
22620 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22621 && dwarf2out_do_cfi_asm ()
22622 && (!(flag_unwind_tables || flag_exceptions)
22623 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22624 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22627 /* A helper function for dwarf2out_finish called through
22628 htab_traverse. Emit one queued .debug_str string. */
22631 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22633 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22635 if (node->label && node->refcount)
22637 switch_to_section (debug_str_section);
22638 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22639 assemble_string (node->str, strlen (node->str) + 1);
22645 #if ENABLE_ASSERT_CHECKING
22646 /* Verify that all marks are clear. */
22649 verify_marks_clear (dw_die_ref die)
22653 gcc_assert (! die->die_mark);
22654 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22656 #endif /* ENABLE_ASSERT_CHECKING */
22658 /* Clear the marks for a die and its children.
22659 Be cool if the mark isn't set. */
22662 prune_unmark_dies (dw_die_ref die)
22668 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22671 /* Given DIE that we're marking as used, find any other dies
22672 it references as attributes and mark them as used. */
22675 prune_unused_types_walk_attribs (dw_die_ref die)
22680 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22682 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22684 /* A reference to another DIE.
22685 Make sure that it will get emitted.
22686 If it was broken out into a comdat group, don't follow it. */
22687 if (dwarf_version < 4
22688 || a->dw_attr == DW_AT_specification
22689 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22690 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22692 /* Set the string's refcount to 0 so that prune_unused_types_mark
22693 accounts properly for it. */
22694 if (AT_class (a) == dw_val_class_str)
22695 a->dw_attr_val.v.val_str->refcount = 0;
22699 /* Mark the generic parameters and arguments children DIEs of DIE. */
22702 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22706 if (die == NULL || die->die_child == NULL)
22708 c = die->die_child;
22711 switch (c->die_tag)
22713 case DW_TAG_template_type_param:
22714 case DW_TAG_template_value_param:
22715 case DW_TAG_GNU_template_template_param:
22716 case DW_TAG_GNU_template_parameter_pack:
22717 prune_unused_types_mark (c, 1);
22723 } while (c && c != die->die_child);
22726 /* Mark DIE as being used. If DOKIDS is true, then walk down
22727 to DIE's children. */
22730 prune_unused_types_mark (dw_die_ref die, int dokids)
22734 if (die->die_mark == 0)
22736 /* We haven't done this node yet. Mark it as used. */
22738 /* If this is the DIE of a generic type instantiation,
22739 mark the children DIEs that describe its generic parms and
22741 prune_unused_types_mark_generic_parms_dies (die);
22743 /* We also have to mark its parents as used.
22744 (But we don't want to mark our parents' kids due to this.) */
22745 if (die->die_parent)
22746 prune_unused_types_mark (die->die_parent, 0);
22748 /* Mark any referenced nodes. */
22749 prune_unused_types_walk_attribs (die);
22751 /* If this node is a specification,
22752 also mark the definition, if it exists. */
22753 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22754 prune_unused_types_mark (die->die_definition, 1);
22757 if (dokids && die->die_mark != 2)
22759 /* We need to walk the children, but haven't done so yet.
22760 Remember that we've walked the kids. */
22763 /* If this is an array type, we need to make sure our
22764 kids get marked, even if they're types. If we're
22765 breaking out types into comdat sections, do this
22766 for all type definitions. */
22767 if (die->die_tag == DW_TAG_array_type
22768 || (dwarf_version >= 4
22769 && is_type_die (die) && ! is_declaration_die (die)))
22770 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22772 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22776 /* For local classes, look if any static member functions were emitted
22777 and if so, mark them. */
22780 prune_unused_types_walk_local_classes (dw_die_ref die)
22784 if (die->die_mark == 2)
22787 switch (die->die_tag)
22789 case DW_TAG_structure_type:
22790 case DW_TAG_union_type:
22791 case DW_TAG_class_type:
22794 case DW_TAG_subprogram:
22795 if (!get_AT_flag (die, DW_AT_declaration)
22796 || die->die_definition != NULL)
22797 prune_unused_types_mark (die, 1);
22804 /* Mark children. */
22805 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22808 /* Walk the tree DIE and mark types that we actually use. */
22811 prune_unused_types_walk (dw_die_ref die)
22815 /* Don't do anything if this node is already marked and
22816 children have been marked as well. */
22817 if (die->die_mark == 2)
22820 switch (die->die_tag)
22822 case DW_TAG_structure_type:
22823 case DW_TAG_union_type:
22824 case DW_TAG_class_type:
22825 if (die->die_perennial_p)
22828 for (c = die->die_parent; c; c = c->die_parent)
22829 if (c->die_tag == DW_TAG_subprogram)
22832 /* Finding used static member functions inside of classes
22833 is needed just for local classes, because for other classes
22834 static member function DIEs with DW_AT_specification
22835 are emitted outside of the DW_TAG_*_type. If we ever change
22836 it, we'd need to call this even for non-local classes. */
22838 prune_unused_types_walk_local_classes (die);
22840 /* It's a type node --- don't mark it. */
22843 case DW_TAG_const_type:
22844 case DW_TAG_packed_type:
22845 case DW_TAG_pointer_type:
22846 case DW_TAG_reference_type:
22847 case DW_TAG_rvalue_reference_type:
22848 case DW_TAG_volatile_type:
22849 case DW_TAG_typedef:
22850 case DW_TAG_array_type:
22851 case DW_TAG_interface_type:
22852 case DW_TAG_friend:
22853 case DW_TAG_variant_part:
22854 case DW_TAG_enumeration_type:
22855 case DW_TAG_subroutine_type:
22856 case DW_TAG_string_type:
22857 case DW_TAG_set_type:
22858 case DW_TAG_subrange_type:
22859 case DW_TAG_ptr_to_member_type:
22860 case DW_TAG_file_type:
22861 if (die->die_perennial_p)
22864 /* It's a type node --- don't mark it. */
22868 /* Mark everything else. */
22872 if (die->die_mark == 0)
22876 /* Now, mark any dies referenced from here. */
22877 prune_unused_types_walk_attribs (die);
22882 /* Mark children. */
22883 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22886 /* Increment the string counts on strings referred to from DIE's
22890 prune_unused_types_update_strings (dw_die_ref die)
22895 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22896 if (AT_class (a) == dw_val_class_str)
22898 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22900 /* Avoid unnecessarily putting strings that are used less than
22901 twice in the hash table. */
22903 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22906 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22907 htab_hash_string (s->str),
22909 gcc_assert (*slot == NULL);
22915 /* Remove from the tree DIE any dies that aren't marked. */
22918 prune_unused_types_prune (dw_die_ref die)
22922 gcc_assert (die->die_mark);
22923 prune_unused_types_update_strings (die);
22925 if (! die->die_child)
22928 c = die->die_child;
22930 dw_die_ref prev = c;
22931 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22932 if (c == die->die_child)
22934 /* No marked children between 'prev' and the end of the list. */
22936 /* No marked children at all. */
22937 die->die_child = NULL;
22940 prev->die_sib = c->die_sib;
22941 die->die_child = prev;
22946 if (c != prev->die_sib)
22948 prune_unused_types_prune (c);
22949 } while (c != die->die_child);
22952 /* A helper function for dwarf2out_finish called through
22953 htab_traverse. Clear .debug_str strings that we haven't already
22954 decided to emit. */
22957 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22959 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22961 if (!node->label || !node->refcount)
22962 htab_clear_slot (debug_str_hash, h);
22967 /* Remove dies representing declarations that we never use. */
22970 prune_unused_types (void)
22973 limbo_die_node *node;
22974 comdat_type_node *ctnode;
22976 dcall_entry *dcall;
22978 #if ENABLE_ASSERT_CHECKING
22979 /* All the marks should already be clear. */
22980 verify_marks_clear (comp_unit_die ());
22981 for (node = limbo_die_list; node; node = node->next)
22982 verify_marks_clear (node->die);
22983 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22984 verify_marks_clear (ctnode->root_die);
22985 #endif /* ENABLE_ASSERT_CHECKING */
22987 /* Mark types that are used in global variables. */
22988 premark_types_used_by_global_vars ();
22990 /* Set the mark on nodes that are actually used. */
22991 prune_unused_types_walk (comp_unit_die ());
22992 for (node = limbo_die_list; node; node = node->next)
22993 prune_unused_types_walk (node->die);
22994 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22996 prune_unused_types_walk (ctnode->root_die);
22997 prune_unused_types_mark (ctnode->type_die, 1);
23000 /* Also set the mark on nodes referenced from the
23001 pubname_table or arange_table. */
23002 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
23003 prune_unused_types_mark (pub->die, 1);
23004 for (i = 0; i < arange_table_in_use; i++)
23005 prune_unused_types_mark (arange_table[i], 1);
23007 /* Mark nodes referenced from the direct call table. */
23008 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, dcall)
23009 prune_unused_types_mark (dcall->targ_die, 1);
23011 /* Get rid of nodes that aren't marked; and update the string counts. */
23012 if (debug_str_hash && debug_str_hash_forced)
23013 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
23014 else if (debug_str_hash)
23015 htab_empty (debug_str_hash);
23016 prune_unused_types_prune (comp_unit_die ());
23017 for (node = limbo_die_list; node; node = node->next)
23018 prune_unused_types_prune (node->die);
23019 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23020 prune_unused_types_prune (ctnode->root_die);
23022 /* Leave the marks clear. */
23023 prune_unmark_dies (comp_unit_die ());
23024 for (node = limbo_die_list; node; node = node->next)
23025 prune_unmark_dies (node->die);
23026 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
23027 prune_unmark_dies (ctnode->root_die);
23030 /* Set the parameter to true if there are any relative pathnames in
23033 file_table_relative_p (void ** slot, void *param)
23035 bool *p = (bool *) param;
23036 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
23037 if (!IS_ABSOLUTE_PATH (d->filename))
23045 /* Routines to manipulate hash table of comdat type units. */
23048 htab_ct_hash (const void *of)
23051 const comdat_type_node *const type_node = (const comdat_type_node *) of;
23053 memcpy (&h, type_node->signature, sizeof (h));
23058 htab_ct_eq (const void *of1, const void *of2)
23060 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
23061 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
23063 return (! memcmp (type_node_1->signature, type_node_2->signature,
23064 DWARF_TYPE_SIGNATURE_SIZE));
23067 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23068 to the location it would have been added, should we know its
23069 DECL_ASSEMBLER_NAME when we added other attributes. This will
23070 probably improve compactness of debug info, removing equivalent
23071 abbrevs, and hide any differences caused by deferring the
23072 computation of the assembler name, triggered by e.g. PCH. */
23075 move_linkage_attr (dw_die_ref die)
23077 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
23078 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
23080 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
23081 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
23085 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
23087 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
23091 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
23093 VEC_pop (dw_attr_node, die->die_attr);
23094 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
23098 /* Helper function for resolve_addr, attempt to resolve
23099 one CONST_STRING, return non-zero if not successful. Similarly verify that
23100 SYMBOL_REFs refer to variables emitted in the current CU. */
23103 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
23107 if (GET_CODE (rtl) == CONST_STRING)
23109 size_t len = strlen (XSTR (rtl, 0)) + 1;
23110 tree t = build_string (len, XSTR (rtl, 0));
23111 tree tlen = build_int_cst (NULL_TREE, len - 1);
23113 = build_array_type (char_type_node, build_index_type (tlen));
23114 rtl = lookup_constant_def (t);
23115 if (!rtl || !MEM_P (rtl))
23117 rtl = XEXP (rtl, 0);
23118 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
23123 if (GET_CODE (rtl) == SYMBOL_REF
23124 && SYMBOL_REF_DECL (rtl))
23126 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
23128 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
23131 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
23135 if (GET_CODE (rtl) == CONST
23136 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
23142 /* Helper function for resolve_addr, handle one location
23143 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23144 the location list couldn't be resolved. */
23147 resolve_addr_in_expr (dw_loc_descr_ref loc)
23149 for (; loc; loc = loc->dw_loc_next)
23150 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
23151 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
23152 || (loc->dw_loc_opc == DW_OP_implicit_value
23153 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
23154 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
23156 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
23157 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
23160 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
23163 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
23164 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
23165 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
23170 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23171 an address in .rodata section if the string literal is emitted there,
23172 or remove the containing location list or replace DW_AT_const_value
23173 with DW_AT_location and empty location expression, if it isn't found
23174 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23175 to something that has been emitted in the current CU. */
23178 resolve_addr (dw_die_ref die)
23182 dw_loc_list_ref *curr;
23185 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23186 switch (AT_class (a))
23188 case dw_val_class_loc_list:
23189 curr = AT_loc_list_ptr (a);
23192 if (!resolve_addr_in_expr ((*curr)->expr))
23194 dw_loc_list_ref next = (*curr)->dw_loc_next;
23195 if (next && (*curr)->ll_symbol)
23197 gcc_assert (!next->ll_symbol);
23198 next->ll_symbol = (*curr)->ll_symbol;
23203 curr = &(*curr)->dw_loc_next;
23205 if (!AT_loc_list (a))
23207 remove_AT (die, a->dw_attr);
23211 case dw_val_class_loc:
23212 if (!resolve_addr_in_expr (AT_loc (a)))
23214 remove_AT (die, a->dw_attr);
23218 case dw_val_class_addr:
23219 if (a->dw_attr == DW_AT_const_value
23220 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
23222 remove_AT (die, a->dw_attr);
23225 if (die->die_tag == DW_TAG_GNU_call_site
23226 && a->dw_attr == DW_AT_abstract_origin)
23228 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
23229 dw_die_ref tdie = lookup_decl_die (tdecl);
23230 if (tdie == NULL && DECL_EXTERNAL (tdecl))
23232 force_decl_die (tdecl);
23233 tdie = lookup_decl_die (tdecl);
23237 a->dw_attr_val.val_class = dw_val_class_die_ref;
23238 a->dw_attr_val.v.val_die_ref.die = tdie;
23239 a->dw_attr_val.v.val_die_ref.external = 0;
23243 remove_AT (die, a->dw_attr);
23252 FOR_EACH_CHILD (die, c, resolve_addr (c));
23255 /* Helper routines for optimize_location_lists.
23256 This pass tries to share identical local lists in .debug_loc
23259 /* Iteratively hash operands of LOC opcode. */
23261 static inline hashval_t
23262 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23264 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23265 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23267 switch (loc->dw_loc_opc)
23269 case DW_OP_const4u:
23270 case DW_OP_const8u:
23274 case DW_OP_const1u:
23275 case DW_OP_const1s:
23276 case DW_OP_const2u:
23277 case DW_OP_const2s:
23278 case DW_OP_const4s:
23279 case DW_OP_const8s:
23283 case DW_OP_plus_uconst:
23319 case DW_OP_deref_size:
23320 case DW_OP_xderef_size:
23321 hash = iterative_hash_object (val1->v.val_int, hash);
23328 gcc_assert (val1->val_class == dw_val_class_loc);
23329 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23330 hash = iterative_hash_object (offset, hash);
23333 case DW_OP_implicit_value:
23334 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23335 switch (val2->val_class)
23337 case dw_val_class_const:
23338 hash = iterative_hash_object (val2->v.val_int, hash);
23340 case dw_val_class_vec:
23342 unsigned int elt_size = val2->v.val_vec.elt_size;
23343 unsigned int len = val2->v.val_vec.length;
23345 hash = iterative_hash_object (elt_size, hash);
23346 hash = iterative_hash_object (len, hash);
23347 hash = iterative_hash (val2->v.val_vec.array,
23348 len * elt_size, hash);
23351 case dw_val_class_const_double:
23352 hash = iterative_hash_object (val2->v.val_double.low, hash);
23353 hash = iterative_hash_object (val2->v.val_double.high, hash);
23355 case dw_val_class_addr:
23356 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23359 gcc_unreachable ();
23363 case DW_OP_bit_piece:
23364 hash = iterative_hash_object (val1->v.val_int, hash);
23365 hash = iterative_hash_object (val2->v.val_int, hash);
23371 unsigned char dtprel = 0xd1;
23372 hash = iterative_hash_object (dtprel, hash);
23374 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23376 case DW_OP_GNU_implicit_pointer:
23377 hash = iterative_hash_object (val2->v.val_int, hash);
23381 /* Other codes have no operands. */
23387 /* Iteratively hash the whole DWARF location expression LOC. */
23389 static inline hashval_t
23390 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23392 dw_loc_descr_ref l;
23393 bool sizes_computed = false;
23394 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23395 size_of_locs (loc);
23397 for (l = loc; l != NULL; l = l->dw_loc_next)
23399 enum dwarf_location_atom opc = l->dw_loc_opc;
23400 hash = iterative_hash_object (opc, hash);
23401 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23403 size_of_locs (loc);
23404 sizes_computed = true;
23406 hash = hash_loc_operands (l, hash);
23411 /* Compute hash of the whole location list LIST_HEAD. */
23414 hash_loc_list (dw_loc_list_ref list_head)
23416 dw_loc_list_ref curr = list_head;
23417 hashval_t hash = 0;
23419 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23421 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23422 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23424 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23426 hash = hash_locs (curr->expr, hash);
23428 list_head->hash = hash;
23431 /* Return true if X and Y opcodes have the same operands. */
23434 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23436 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23437 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23438 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23439 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23441 switch (x->dw_loc_opc)
23443 case DW_OP_const4u:
23444 case DW_OP_const8u:
23448 case DW_OP_const1u:
23449 case DW_OP_const1s:
23450 case DW_OP_const2u:
23451 case DW_OP_const2s:
23452 case DW_OP_const4s:
23453 case DW_OP_const8s:
23457 case DW_OP_plus_uconst:
23493 case DW_OP_deref_size:
23494 case DW_OP_xderef_size:
23495 return valx1->v.val_int == valy1->v.val_int;
23498 gcc_assert (valx1->val_class == dw_val_class_loc
23499 && valy1->val_class == dw_val_class_loc
23500 && x->dw_loc_addr == y->dw_loc_addr);
23501 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23502 case DW_OP_implicit_value:
23503 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23504 || valx2->val_class != valy2->val_class)
23506 switch (valx2->val_class)
23508 case dw_val_class_const:
23509 return valx2->v.val_int == valy2->v.val_int;
23510 case dw_val_class_vec:
23511 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23512 && valx2->v.val_vec.length == valy2->v.val_vec.length
23513 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23514 valx2->v.val_vec.elt_size
23515 * valx2->v.val_vec.length) == 0;
23516 case dw_val_class_const_double:
23517 return valx2->v.val_double.low == valy2->v.val_double.low
23518 && valx2->v.val_double.high == valy2->v.val_double.high;
23519 case dw_val_class_addr:
23520 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23522 gcc_unreachable ();
23525 case DW_OP_bit_piece:
23526 return valx1->v.val_int == valy1->v.val_int
23527 && valx2->v.val_int == valy2->v.val_int;
23530 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23531 case DW_OP_GNU_implicit_pointer:
23532 return valx1->val_class == dw_val_class_die_ref
23533 && valx1->val_class == valy1->val_class
23534 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23535 && valx2->v.val_int == valy2->v.val_int;
23537 /* Other codes have no operands. */
23542 /* Return true if DWARF location expressions X and Y are the same. */
23545 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23547 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23548 if (x->dw_loc_opc != y->dw_loc_opc
23549 || x->dtprel != y->dtprel
23550 || !compare_loc_operands (x, y))
23552 return x == NULL && y == NULL;
23555 /* Return precomputed hash of location list X. */
23558 loc_list_hash (const void *x)
23560 return ((const struct dw_loc_list_struct *) x)->hash;
23563 /* Return 1 if location lists X and Y are the same. */
23566 loc_list_eq (const void *x, const void *y)
23568 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23569 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23572 if (a->hash != b->hash)
23574 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23575 if (strcmp (a->begin, b->begin) != 0
23576 || strcmp (a->end, b->end) != 0
23577 || (a->section == NULL) != (b->section == NULL)
23578 || (a->section && strcmp (a->section, b->section) != 0)
23579 || !compare_locs (a->expr, b->expr))
23581 return a == NULL && b == NULL;
23584 /* Recursively optimize location lists referenced from DIE
23585 children and share them whenever possible. */
23588 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23595 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23596 if (AT_class (a) == dw_val_class_loc_list)
23598 dw_loc_list_ref list = AT_loc_list (a);
23599 /* TODO: perform some optimizations here, before hashing
23600 it and storing into the hash table. */
23601 hash_loc_list (list);
23602 slot = htab_find_slot_with_hash (htab, list, list->hash,
23605 *slot = (void *) list;
23607 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23610 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23613 /* Optimize location lists referenced from DIE
23614 children and share them whenever possible. */
23617 optimize_location_lists (dw_die_ref die)
23619 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23620 optimize_location_lists_1 (die, htab);
23621 htab_delete (htab);
23624 /* Output stuff that dwarf requires at the end of every file,
23625 and generate the DWARF-2 debugging info. */
23628 dwarf2out_finish (const char *filename)
23630 limbo_die_node *node, *next_node;
23631 comdat_type_node *ctnode;
23632 htab_t comdat_type_table;
23635 gen_scheduled_generic_parms_dies ();
23636 gen_remaining_tmpl_value_param_die_attribute ();
23638 /* Add the name for the main input file now. We delayed this from
23639 dwarf2out_init to avoid complications with PCH. */
23640 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23641 if (!IS_ABSOLUTE_PATH (filename))
23642 add_comp_dir_attribute (comp_unit_die ());
23643 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23646 htab_traverse (file_table, file_table_relative_p, &p);
23648 add_comp_dir_attribute (comp_unit_die ());
23651 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23653 add_location_or_const_value_attribute (
23654 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23655 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23659 /* Traverse the limbo die list, and add parent/child links. The only
23660 dies without parents that should be here are concrete instances of
23661 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23662 For concrete instances, we can get the parent die from the abstract
23664 for (node = limbo_die_list; node; node = next_node)
23666 dw_die_ref die = node->die;
23667 next_node = node->next;
23669 if (die->die_parent == NULL)
23671 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23674 add_child_die (origin->die_parent, die);
23675 else if (is_cu_die (die))
23677 else if (seen_error ())
23678 /* It's OK to be confused by errors in the input. */
23679 add_child_die (comp_unit_die (), die);
23682 /* In certain situations, the lexical block containing a
23683 nested function can be optimized away, which results
23684 in the nested function die being orphaned. Likewise
23685 with the return type of that nested function. Force
23686 this to be a child of the containing function.
23688 It may happen that even the containing function got fully
23689 inlined and optimized out. In that case we are lost and
23690 assign the empty child. This should not be big issue as
23691 the function is likely unreachable too. */
23692 tree context = NULL_TREE;
23694 gcc_assert (node->created_for);
23696 if (DECL_P (node->created_for))
23697 context = DECL_CONTEXT (node->created_for);
23698 else if (TYPE_P (node->created_for))
23699 context = TYPE_CONTEXT (node->created_for);
23701 gcc_assert (context
23702 && (TREE_CODE (context) == FUNCTION_DECL
23703 || TREE_CODE (context) == NAMESPACE_DECL));
23705 origin = lookup_decl_die (context);
23707 add_child_die (origin, die);
23709 add_child_die (comp_unit_die (), die);
23714 limbo_die_list = NULL;
23716 resolve_addr (comp_unit_die ());
23718 for (node = deferred_asm_name; node; node = node->next)
23720 tree decl = node->created_for;
23721 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23723 add_linkage_attr (node->die, decl);
23724 move_linkage_attr (node->die);
23728 deferred_asm_name = NULL;
23730 /* Walk through the list of incomplete types again, trying once more to
23731 emit full debugging info for them. */
23732 retry_incomplete_types ();
23734 if (flag_eliminate_unused_debug_types)
23735 prune_unused_types ();
23737 /* Generate separate CUs for each of the include files we've seen.
23738 They will go into limbo_die_list. */
23739 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23740 break_out_includes (comp_unit_die ());
23742 /* Generate separate COMDAT sections for type DIEs. */
23743 if (dwarf_version >= 4)
23745 break_out_comdat_types (comp_unit_die ());
23747 /* Each new type_unit DIE was added to the limbo die list when created.
23748 Since these have all been added to comdat_type_list, clear the
23750 limbo_die_list = NULL;
23752 /* For each new comdat type unit, copy declarations for incomplete
23753 types to make the new unit self-contained (i.e., no direct
23754 references to the main compile unit). */
23755 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23756 copy_decls_for_unworthy_types (ctnode->root_die);
23757 copy_decls_for_unworthy_types (comp_unit_die ());
23759 /* In the process of copying declarations from one unit to another,
23760 we may have left some declarations behind that are no longer
23761 referenced. Prune them. */
23762 prune_unused_types ();
23765 /* Traverse the DIE's and add add sibling attributes to those DIE's
23766 that have children. */
23767 add_sibling_attributes (comp_unit_die ());
23768 for (node = limbo_die_list; node; node = node->next)
23769 add_sibling_attributes (node->die);
23770 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23771 add_sibling_attributes (ctnode->root_die);
23773 /* Output a terminator label for the .text section. */
23774 switch_to_section (text_section);
23775 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23776 if (cold_text_section)
23778 switch_to_section (cold_text_section);
23779 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23782 /* We can only use the low/high_pc attributes if all of the code was
23784 if (!have_multiple_function_sections
23785 || (dwarf_version < 3 && dwarf_strict))
23787 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23788 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23793 unsigned fde_idx = 0;
23794 bool range_list_added = false;
23796 /* We need to give .debug_loc and .debug_ranges an appropriate
23797 "base address". Use zero so that these addresses become
23798 absolute. Historically, we've emitted the unexpected
23799 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23800 Emit both to give time for other tools to adapt. */
23801 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23802 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23804 if (text_section_used)
23805 add_ranges_by_labels (comp_unit_die (), text_section_label,
23806 text_end_label, &range_list_added);
23807 if (flag_reorder_blocks_and_partition && cold_text_section_used)
23808 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23809 cold_end_label, &range_list_added);
23811 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23813 dw_fde_ref fde = &fde_table[fde_idx];
23815 if (fde->dw_fde_switched_sections)
23817 if (!fde->in_std_section)
23818 add_ranges_by_labels (comp_unit_die (),
23819 fde->dw_fde_hot_section_label,
23820 fde->dw_fde_hot_section_end_label,
23821 &range_list_added);
23822 if (!fde->cold_in_std_section)
23823 add_ranges_by_labels (comp_unit_die (),
23824 fde->dw_fde_unlikely_section_label,
23825 fde->dw_fde_unlikely_section_end_label,
23826 &range_list_added);
23828 else if (!fde->in_std_section)
23829 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23830 fde->dw_fde_end, &range_list_added);
23833 if (range_list_added)
23837 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23838 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23839 debug_line_section_label);
23841 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23842 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23844 if (have_location_lists)
23845 optimize_location_lists (comp_unit_die ());
23847 /* Output all of the compilation units. We put the main one last so that
23848 the offsets are available to output_pubnames. */
23849 for (node = limbo_die_list; node; node = node->next)
23850 output_comp_unit (node->die, 0);
23852 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23853 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23855 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23857 /* Don't output duplicate types. */
23858 if (*slot != HTAB_EMPTY_ENTRY)
23861 /* Add a pointer to the line table for the main compilation unit
23862 so that the debugger can make sense of DW_AT_decl_file
23864 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23865 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23866 debug_line_section_label);
23868 output_comdat_type_unit (ctnode);
23871 htab_delete (comdat_type_table);
23873 /* Output the main compilation unit if non-empty or if .debug_macinfo
23874 will be emitted. */
23875 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23877 /* Output the abbreviation table. */
23878 switch_to_section (debug_abbrev_section);
23879 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23880 output_abbrev_section ();
23882 /* Output location list section if necessary. */
23883 if (have_location_lists)
23885 /* Output the location lists info. */
23886 switch_to_section (debug_loc_section);
23887 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23888 DEBUG_LOC_SECTION_LABEL, 0);
23889 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23890 output_location_lists (comp_unit_die ());
23893 /* Output public names table if necessary. */
23894 if (!VEC_empty (pubname_entry, pubname_table))
23896 gcc_assert (info_section_emitted);
23897 switch_to_section (debug_pubnames_section);
23898 output_pubnames (pubname_table);
23901 /* Output public types table if necessary. */
23902 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23903 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23904 simply won't look for the section. */
23905 if (!VEC_empty (pubname_entry, pubtype_table))
23907 bool empty = false;
23909 if (flag_eliminate_unused_debug_types)
23911 /* The pubtypes table might be emptied by pruning unused items. */
23915 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23916 if (p->die->die_offset != 0)
23924 gcc_assert (info_section_emitted);
23925 switch_to_section (debug_pubtypes_section);
23926 output_pubnames (pubtype_table);
23930 /* Output direct and virtual call tables if necessary. */
23931 if (!VEC_empty (dcall_entry, dcall_table))
23933 switch_to_section (debug_dcall_section);
23934 output_dcall_table ();
23936 if (!VEC_empty (vcall_entry, vcall_table))
23938 switch_to_section (debug_vcall_section);
23939 output_vcall_table ();
23942 /* Output the address range information. We only put functions in the arange
23943 table, so don't write it out if we don't have any. */
23944 if (arange_table_in_use)
23946 switch_to_section (debug_aranges_section);
23950 /* Output ranges section if necessary. */
23951 if (ranges_table_in_use)
23953 switch_to_section (debug_ranges_section);
23954 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23958 /* Output the source line correspondence table. We must do this
23959 even if there is no line information. Otherwise, on an empty
23960 translation unit, we will generate a present, but empty,
23961 .debug_info section. IRIX 6.5 `nm' will then complain when
23962 examining the file. This is done late so that any filenames
23963 used by the debug_info section are marked as 'used'. */
23964 switch_to_section (debug_line_section);
23965 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23966 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23967 output_line_info ();
23969 /* Have to end the macro section. */
23970 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23972 switch_to_section (debug_macinfo_section);
23973 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23974 if (!VEC_empty (macinfo_entry, macinfo_table))
23976 dw2_asm_output_data (1, 0, "End compilation unit");
23979 /* If we emitted any DW_FORM_strp form attribute, output the string
23981 if (debug_str_hash)
23982 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23985 #include "gt-dwarf2out.h"