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
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"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 /* ??? Poison these here until it can be done generically. They've been
116 totally replaced in this file; make sure it stays that way. */
117 #undef DWARF2_UNWIND_INFO
118 #undef DWARF2_FRAME_INFO
119 #if (GCC_VERSION >= 3000)
120 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
123 #ifndef INCOMING_RETURN_ADDR_RTX
124 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
127 /* Map register numbers held in the call frame info that gcc has
128 collected using DWARF_FRAME_REGNUM to those that should be output in
129 .debug_frame and .eh_frame. */
130 #ifndef DWARF2_FRAME_REG_OUT
131 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
134 /* Save the result of dwarf2out_do_frame across PCH. */
135 static GTY(()) bool saved_do_cfi_asm = 0;
137 /* Decide whether we want to emit frame unwind information for the current
141 dwarf2out_do_frame (void)
143 /* We want to emit correct CFA location expressions or lists, so we
144 have to return true if we're going to output debug info, even if
145 we're not going to output frame or unwind info. */
146 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
149 if (saved_do_cfi_asm)
152 if (targetm.debug_unwind_info () == UI_DWARF2)
155 if ((flag_unwind_tables || flag_exceptions)
156 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
162 /* Decide whether to emit frame unwind via assembler directives. */
165 dwarf2out_do_cfi_asm (void)
169 #ifdef MIPS_DEBUGGING_INFO
172 if (saved_do_cfi_asm)
174 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
176 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
179 /* Make sure the personality encoding is one the assembler can support.
180 In particular, aligned addresses can't be handled. */
181 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
182 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
184 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
185 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
188 /* If we can't get the assembler to emit only .debug_frame, and we don't need
189 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
190 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
191 && !flag_unwind_tables && !flag_exceptions
192 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
195 saved_do_cfi_asm = true;
199 /* The size of the target's pointer type. */
201 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
204 /* Array of RTXes referenced by the debugging information, which therefore
205 must be kept around forever. */
206 static GTY(()) VEC(rtx,gc) *used_rtx_array;
208 /* A pointer to the base of a list of incomplete types which might be
209 completed at some later time. incomplete_types_list needs to be a
210 VEC(tree,gc) because we want to tell the garbage collector about
212 static GTY(()) VEC(tree,gc) *incomplete_types;
214 /* A pointer to the base of a table of references to declaration
215 scopes. This table is a display which tracks the nesting
216 of declaration scopes at the current scope and containing
217 scopes. This table is used to find the proper place to
218 define type declaration DIE's. */
219 static GTY(()) VEC(tree,gc) *decl_scope_table;
221 /* Pointers to various DWARF2 sections. */
222 static GTY(()) section *debug_info_section;
223 static GTY(()) section *debug_abbrev_section;
224 static GTY(()) section *debug_aranges_section;
225 static GTY(()) section *debug_macinfo_section;
226 static GTY(()) section *debug_line_section;
227 static GTY(()) section *debug_loc_section;
228 static GTY(()) section *debug_pubnames_section;
229 static GTY(()) section *debug_pubtypes_section;
230 static GTY(()) section *debug_dcall_section;
231 static GTY(()) section *debug_vcall_section;
232 static GTY(()) section *debug_str_section;
233 static GTY(()) section *debug_ranges_section;
234 static GTY(()) section *debug_frame_section;
236 /* Personality decl of current unit. Used only when assembler does not support
238 static GTY(()) rtx current_unit_personality;
240 /* How to start an assembler comment. */
241 #ifndef ASM_COMMENT_START
242 #define ASM_COMMENT_START ";#"
245 typedef struct dw_cfi_struct *dw_cfi_ref;
246 typedef struct dw_fde_struct *dw_fde_ref;
247 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
249 /* Call frames are described using a sequence of Call Frame
250 Information instructions. The register number, offset
251 and address fields are provided as possible operands;
252 their use is selected by the opcode field. */
254 enum dw_cfi_oprnd_type {
256 dw_cfi_oprnd_reg_num,
262 typedef union GTY(()) dw_cfi_oprnd_struct {
263 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
264 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
265 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
266 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
270 typedef struct GTY(()) dw_cfi_struct {
271 dw_cfi_ref dw_cfi_next;
272 enum dwarf_call_frame_info dw_cfi_opc;
273 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
275 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
280 /* This is how we define the location of the CFA. We use to handle it
281 as REG + OFFSET all the time, but now it can be more complex.
282 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
283 Instead of passing around REG and OFFSET, we pass a copy
284 of this structure. */
285 typedef struct GTY(()) cfa_loc {
286 HOST_WIDE_INT offset;
287 HOST_WIDE_INT base_offset;
289 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
290 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
293 /* All call frame descriptions (FDE's) in the GCC generated DWARF
294 refer to a single Common Information Entry (CIE), defined at
295 the beginning of the .debug_frame section. This use of a single
296 CIE obviates the need to keep track of multiple CIE's
297 in the DWARF generation routines below. */
299 typedef struct GTY(()) dw_fde_struct {
301 const char *dw_fde_begin;
302 const char *dw_fde_current_label;
303 const char *dw_fde_end;
304 const char *dw_fde_vms_end_prologue;
305 const char *dw_fde_vms_begin_epilogue;
306 const char *dw_fde_hot_section_label;
307 const char *dw_fde_hot_section_end_label;
308 const char *dw_fde_unlikely_section_label;
309 const char *dw_fde_unlikely_section_end_label;
310 dw_cfi_ref dw_fde_cfi;
311 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
312 HOST_WIDE_INT stack_realignment;
313 unsigned funcdef_number;
314 /* Dynamic realign argument pointer register. */
315 unsigned int drap_reg;
316 /* Virtual dynamic realign argument pointer register. */
317 unsigned int vdrap_reg;
318 /* These 3 flags are copied from rtl_data in function.h. */
319 unsigned all_throwers_are_sibcalls : 1;
320 unsigned uses_eh_lsda : 1;
321 unsigned nothrow : 1;
322 /* Whether we did stack realign in this call frame. */
323 unsigned stack_realign : 1;
324 /* Whether dynamic realign argument pointer register has been saved. */
325 unsigned drap_reg_saved: 1;
326 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
327 unsigned in_std_section : 1;
328 /* True iff dw_fde_unlikely_section_label is in text_section or
329 cold_text_section. */
330 unsigned cold_in_std_section : 1;
331 /* True iff switched sections. */
332 unsigned dw_fde_switched_sections : 1;
333 /* True iff switching from cold to hot section. */
334 unsigned dw_fde_switched_cold_to_hot : 1;
338 /* Maximum size (in bytes) of an artificially generated label. */
339 #define MAX_ARTIFICIAL_LABEL_BYTES 30
341 /* The size of addresses as they appear in the Dwarf 2 data.
342 Some architectures use word addresses to refer to code locations,
343 but Dwarf 2 info always uses byte addresses. On such machines,
344 Dwarf 2 addresses need to be larger than the architecture's
346 #ifndef DWARF2_ADDR_SIZE
347 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
350 /* The size in bytes of a DWARF field indicating an offset or length
351 relative to a debug info section, specified to be 4 bytes in the
352 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
355 #ifndef DWARF_OFFSET_SIZE
356 #define DWARF_OFFSET_SIZE 4
359 /* The size in bytes of a DWARF 4 type signature. */
361 #ifndef DWARF_TYPE_SIGNATURE_SIZE
362 #define DWARF_TYPE_SIGNATURE_SIZE 8
365 /* According to the (draft) DWARF 3 specification, the initial length
366 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
367 bytes are 0xffffffff, followed by the length stored in the next 8
370 However, the SGI/MIPS ABI uses an initial length which is equal to
371 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
373 #ifndef DWARF_INITIAL_LENGTH_SIZE
374 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
377 /* Round SIZE up to the nearest BOUNDARY. */
378 #define DWARF_ROUND(SIZE,BOUNDARY) \
379 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
381 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
382 #ifndef DWARF_CIE_DATA_ALIGNMENT
383 #ifdef STACK_GROWS_DOWNWARD
384 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
386 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
390 /* CIE identifier. */
391 #if HOST_BITS_PER_WIDE_INT >= 64
392 #define DWARF_CIE_ID \
393 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
395 #define DWARF_CIE_ID DW_CIE_ID
398 /* A pointer to the base of a table that contains frame description
399 information for each routine. */
400 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
402 /* Number of elements currently allocated for fde_table. */
403 static GTY(()) unsigned fde_table_allocated;
405 /* Number of elements in fde_table currently in use. */
406 static GTY(()) unsigned fde_table_in_use;
408 /* Size (in elements) of increments by which we may expand the
410 #define FDE_TABLE_INCREMENT 256
412 /* Get the current fde_table entry we should use. */
414 static inline dw_fde_ref
417 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
420 /* A list of call frame insns for the CIE. */
421 static GTY(()) dw_cfi_ref cie_cfi_head;
423 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
424 attribute that accelerates the lookup of the FDE associated
425 with the subprogram. This variable holds the table index of the FDE
426 associated with the current function (body) definition. */
427 static unsigned current_funcdef_fde;
429 struct GTY(()) indirect_string_node {
431 unsigned int refcount;
432 enum dwarf_form form;
436 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
438 /* True if the compilation unit has location entries that reference
440 static GTY(()) bool debug_str_hash_forced = false;
442 static GTY(()) int dw2_string_counter;
443 static GTY(()) unsigned long dwarf2out_cfi_label_num;
445 /* True if the compilation unit places functions in more than one section. */
446 static GTY(()) bool have_multiple_function_sections = false;
448 /* Whether the default text and cold text sections have been used at all. */
450 static GTY(()) bool text_section_used = false;
451 static GTY(()) bool cold_text_section_used = false;
453 /* The default cold text section. */
454 static GTY(()) section *cold_text_section;
456 /* Forward declarations for functions defined in this file. */
458 static char *stripattributes (const char *);
459 static const char *dwarf_cfi_name (unsigned);
460 static dw_cfi_ref new_cfi (void);
461 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
462 static void add_fde_cfi (const char *, dw_cfi_ref);
463 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
464 static void lookup_cfa (dw_cfa_location *);
465 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
466 static void initial_return_save (rtx);
467 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
469 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
470 static void output_cfi_directive (dw_cfi_ref);
471 static void output_call_frame_info (int);
472 static void dwarf2out_note_section_used (void);
473 static bool clobbers_queued_reg_save (const_rtx);
474 static void dwarf2out_frame_debug_expr (rtx, const char *);
476 /* Support for complex CFA locations. */
477 static void output_cfa_loc (dw_cfi_ref);
478 static void output_cfa_loc_raw (dw_cfi_ref);
479 static void get_cfa_from_loc_descr (dw_cfa_location *,
480 struct dw_loc_descr_struct *);
481 static struct dw_loc_descr_struct *build_cfa_loc
482 (dw_cfa_location *, HOST_WIDE_INT);
483 static struct dw_loc_descr_struct *build_cfa_aligned_loc
484 (HOST_WIDE_INT, HOST_WIDE_INT);
485 static void def_cfa_1 (const char *, dw_cfa_location *);
486 static struct dw_loc_descr_struct *mem_loc_descriptor
487 (rtx, enum machine_mode mode, enum var_init_status);
489 /* How to start an assembler comment. */
490 #ifndef ASM_COMMENT_START
491 #define ASM_COMMENT_START ";#"
494 /* Data and reference forms for relocatable data. */
495 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
496 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
498 #ifndef DEBUG_FRAME_SECTION
499 #define DEBUG_FRAME_SECTION ".debug_frame"
502 #ifndef FUNC_BEGIN_LABEL
503 #define FUNC_BEGIN_LABEL "LFB"
506 #ifndef FUNC_END_LABEL
507 #define FUNC_END_LABEL "LFE"
510 #ifndef PROLOGUE_END_LABEL
511 #define PROLOGUE_END_LABEL "LPE"
514 #ifndef EPILOGUE_BEGIN_LABEL
515 #define EPILOGUE_BEGIN_LABEL "LEB"
518 #ifndef FRAME_BEGIN_LABEL
519 #define FRAME_BEGIN_LABEL "Lframe"
521 #define CIE_AFTER_SIZE_LABEL "LSCIE"
522 #define CIE_END_LABEL "LECIE"
523 #define FDE_LABEL "LSFDE"
524 #define FDE_AFTER_SIZE_LABEL "LASFDE"
525 #define FDE_END_LABEL "LEFDE"
526 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
527 #define LINE_NUMBER_END_LABEL "LELT"
528 #define LN_PROLOG_AS_LABEL "LASLTP"
529 #define LN_PROLOG_END_LABEL "LELTP"
530 #define DIE_LABEL_PREFIX "DW"
532 /* The DWARF 2 CFA column which tracks the return address. Normally this
533 is the column for PC, or the first column after all of the hard
535 #ifndef DWARF_FRAME_RETURN_COLUMN
537 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
539 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
543 /* The mapping from gcc register number to DWARF 2 CFA column number. By
544 default, we just provide columns for all registers. */
545 #ifndef DWARF_FRAME_REGNUM
546 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
549 /* Match the base name of a file to the base name of a compilation unit. */
552 matches_main_base (const char *path)
554 /* Cache the last query. */
555 static const char *last_path = NULL;
556 static int last_match = 0;
557 if (path != last_path)
560 int length = base_of_path (path, &base);
562 last_match = (length == main_input_baselength
563 && memcmp (base, main_input_basename, length) == 0);
568 #ifdef DEBUG_DEBUG_STRUCT
571 dump_struct_debug (tree type, enum debug_info_usage usage,
572 enum debug_struct_file criterion, int generic,
573 int matches, int result)
575 /* Find the type name. */
576 tree type_decl = TYPE_STUB_DECL (type);
578 const char *name = 0;
579 if (TREE_CODE (t) == TYPE_DECL)
582 name = IDENTIFIER_POINTER (t);
584 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
586 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
587 matches ? "bas" : "hdr",
588 generic ? "gen" : "ord",
589 usage == DINFO_USAGE_DFN ? ";" :
590 usage == DINFO_USAGE_DIR_USE ? "." : "*",
592 (void*) type_decl, name);
595 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
596 dump_struct_debug (type, usage, criterion, generic, matches, result)
600 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
606 should_emit_struct_debug (tree type, enum debug_info_usage usage)
608 enum debug_struct_file criterion;
610 bool generic = lang_hooks.types.generic_p (type);
613 criterion = debug_struct_generic[usage];
615 criterion = debug_struct_ordinary[usage];
617 if (criterion == DINFO_STRUCT_FILE_NONE)
618 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
619 if (criterion == DINFO_STRUCT_FILE_ANY)
620 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
622 type_decl = TYPE_STUB_DECL (type);
624 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
625 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
627 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
628 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
629 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
632 /* Hook used by __throw. */
635 expand_builtin_dwarf_sp_column (void)
637 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
638 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
641 /* Return a pointer to a copy of the section string name S with all
642 attributes stripped off, and an asterisk prepended (for assemble_name). */
645 stripattributes (const char *s)
647 char *stripped = XNEWVEC (char, strlen (s) + 2);
652 while (*s && *s != ',')
659 /* MEM is a memory reference for the register size table, each element of
660 which has mode MODE. Initialize column C as a return address column. */
663 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
665 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
666 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
667 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
670 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
672 static inline HOST_WIDE_INT
673 div_data_align (HOST_WIDE_INT off)
675 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
676 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
680 /* Return true if we need a signed version of a given opcode
681 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
684 need_data_align_sf_opcode (HOST_WIDE_INT off)
686 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
689 /* Generate code to initialize the register size table. */
692 expand_builtin_init_dwarf_reg_sizes (tree address)
695 enum machine_mode mode = TYPE_MODE (char_type_node);
696 rtx addr = expand_normal (address);
697 rtx mem = gen_rtx_MEM (BLKmode, addr);
698 bool wrote_return_column = false;
700 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
702 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
704 if (rnum < DWARF_FRAME_REGISTERS)
706 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
707 enum machine_mode save_mode = reg_raw_mode[i];
710 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
711 save_mode = choose_hard_reg_mode (i, 1, true);
712 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
714 if (save_mode == VOIDmode)
716 wrote_return_column = true;
718 size = GET_MODE_SIZE (save_mode);
722 emit_move_insn (adjust_address (mem, mode, offset),
723 gen_int_mode (size, mode));
727 if (!wrote_return_column)
728 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
730 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
731 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
734 targetm.init_dwarf_reg_sizes_extra (address);
737 /* Convert a DWARF call frame info. operation to its string name */
740 dwarf_cfi_name (unsigned int cfi_opc)
744 case DW_CFA_advance_loc:
745 return "DW_CFA_advance_loc";
747 return "DW_CFA_offset";
749 return "DW_CFA_restore";
753 return "DW_CFA_set_loc";
754 case DW_CFA_advance_loc1:
755 return "DW_CFA_advance_loc1";
756 case DW_CFA_advance_loc2:
757 return "DW_CFA_advance_loc2";
758 case DW_CFA_advance_loc4:
759 return "DW_CFA_advance_loc4";
760 case DW_CFA_offset_extended:
761 return "DW_CFA_offset_extended";
762 case DW_CFA_restore_extended:
763 return "DW_CFA_restore_extended";
764 case DW_CFA_undefined:
765 return "DW_CFA_undefined";
766 case DW_CFA_same_value:
767 return "DW_CFA_same_value";
768 case DW_CFA_register:
769 return "DW_CFA_register";
770 case DW_CFA_remember_state:
771 return "DW_CFA_remember_state";
772 case DW_CFA_restore_state:
773 return "DW_CFA_restore_state";
775 return "DW_CFA_def_cfa";
776 case DW_CFA_def_cfa_register:
777 return "DW_CFA_def_cfa_register";
778 case DW_CFA_def_cfa_offset:
779 return "DW_CFA_def_cfa_offset";
782 case DW_CFA_def_cfa_expression:
783 return "DW_CFA_def_cfa_expression";
784 case DW_CFA_expression:
785 return "DW_CFA_expression";
786 case DW_CFA_offset_extended_sf:
787 return "DW_CFA_offset_extended_sf";
788 case DW_CFA_def_cfa_sf:
789 return "DW_CFA_def_cfa_sf";
790 case DW_CFA_def_cfa_offset_sf:
791 return "DW_CFA_def_cfa_offset_sf";
793 /* SGI/MIPS specific */
794 case DW_CFA_MIPS_advance_loc8:
795 return "DW_CFA_MIPS_advance_loc8";
798 case DW_CFA_GNU_window_save:
799 return "DW_CFA_GNU_window_save";
800 case DW_CFA_GNU_args_size:
801 return "DW_CFA_GNU_args_size";
802 case DW_CFA_GNU_negative_offset_extended:
803 return "DW_CFA_GNU_negative_offset_extended";
806 return "DW_CFA_<unknown>";
810 /* Return a pointer to a newly allocated Call Frame Instruction. */
812 static inline dw_cfi_ref
815 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
817 cfi->dw_cfi_next = NULL;
818 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
819 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
824 /* Add a Call Frame Instruction to list of instructions. */
827 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
830 dw_fde_ref fde = current_fde ();
832 /* When DRAP is used, CFA is defined with an expression. Redefine
833 CFA may lead to a different CFA value. */
834 /* ??? Of course, this heuristic fails when we're annotating epilogues,
835 because of course we'll always want to redefine the CFA back to the
836 stack pointer on the way out. Where should we move this check? */
837 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
838 switch (cfi->dw_cfi_opc)
840 case DW_CFA_def_cfa_register:
841 case DW_CFA_def_cfa_offset:
842 case DW_CFA_def_cfa_offset_sf:
844 case DW_CFA_def_cfa_sf:
851 /* Find the end of the chain. */
852 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
858 /* Generate a new label for the CFI info to refer to. FORCE is true
859 if a label needs to be output even when using .cfi_* directives. */
862 dwarf2out_cfi_label (bool force)
864 static char label[20];
866 if (!force && dwarf2out_do_cfi_asm ())
868 /* In this case, we will be emitting the asm directive instead of
869 the label, so just return a placeholder to keep the rest of the
871 strcpy (label, "<do not output>");
875 int num = dwarf2out_cfi_label_num++;
876 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
877 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
883 /* True if remember_state should be emitted before following CFI directive. */
884 static bool emit_cfa_remember;
886 /* True if any CFI directives were emitted at the current insn. */
887 static bool any_cfis_emitted;
889 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
890 or to the CIE if LABEL is NULL. */
893 add_fde_cfi (const char *label, dw_cfi_ref cfi)
895 dw_cfi_ref *list_head;
897 if (emit_cfa_remember)
899 dw_cfi_ref cfi_remember;
901 /* Emit the state save. */
902 emit_cfa_remember = false;
903 cfi_remember = new_cfi ();
904 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
905 add_fde_cfi (label, cfi_remember);
908 list_head = &cie_cfi_head;
910 if (dwarf2out_do_cfi_asm ())
914 dw_fde_ref fde = current_fde ();
916 gcc_assert (fde != NULL);
918 /* We still have to add the cfi to the list so that lookup_cfa
919 works later on. When -g2 and above we even need to force
920 emitting of CFI labels and add to list a DW_CFA_set_loc for
921 convert_cfa_to_fb_loc_list purposes. If we're generating
922 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
923 convert_cfa_to_fb_loc_list. */
924 if (dwarf_version == 2
925 && debug_info_level > DINFO_LEVEL_TERSE
926 && (write_symbols == DWARF2_DEBUG
927 || write_symbols == VMS_AND_DWARF2_DEBUG))
929 switch (cfi->dw_cfi_opc)
931 case DW_CFA_def_cfa_offset:
932 case DW_CFA_def_cfa_offset_sf:
933 case DW_CFA_def_cfa_register:
935 case DW_CFA_def_cfa_sf:
936 case DW_CFA_def_cfa_expression:
937 case DW_CFA_restore_state:
938 if (*label == 0 || strcmp (label, "<do not output>") == 0)
939 label = dwarf2out_cfi_label (true);
941 if (fde->dw_fde_current_label == NULL
942 || strcmp (label, fde->dw_fde_current_label) != 0)
946 label = xstrdup (label);
948 /* Set the location counter to the new label. */
950 /* It doesn't metter whether DW_CFA_set_loc
951 or DW_CFA_advance_loc4 is added here, those aren't
952 emitted into assembly, only looked up by
953 convert_cfa_to_fb_loc_list. */
954 xcfi->dw_cfi_opc = DW_CFA_set_loc;
955 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
956 add_cfi (&fde->dw_fde_cfi, xcfi);
957 fde->dw_fde_current_label = label;
965 output_cfi_directive (cfi);
967 list_head = &fde->dw_fde_cfi;
968 any_cfis_emitted = true;
970 /* ??? If this is a CFI for the CIE, we don't emit. This
971 assumes that the standard CIE contents that the assembler
972 uses matches the standard CIE contents that the compiler
973 uses. This is probably a bad assumption. I'm not quite
974 sure how to address this for now. */
978 dw_fde_ref fde = current_fde ();
980 gcc_assert (fde != NULL);
983 label = dwarf2out_cfi_label (false);
985 if (fde->dw_fde_current_label == NULL
986 || strcmp (label, fde->dw_fde_current_label) != 0)
990 label = xstrdup (label);
992 /* Set the location counter to the new label. */
994 /* If we have a current label, advance from there, otherwise
995 set the location directly using set_loc. */
996 xcfi->dw_cfi_opc = fde->dw_fde_current_label
997 ? DW_CFA_advance_loc4
999 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
1000 add_cfi (&fde->dw_fde_cfi, xcfi);
1002 fde->dw_fde_current_label = label;
1005 list_head = &fde->dw_fde_cfi;
1006 any_cfis_emitted = true;
1009 add_cfi (list_head, cfi);
1012 /* Subroutine of lookup_cfa. */
1015 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1017 switch (cfi->dw_cfi_opc)
1019 case DW_CFA_def_cfa_offset:
1020 case DW_CFA_def_cfa_offset_sf:
1021 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1023 case DW_CFA_def_cfa_register:
1024 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1026 case DW_CFA_def_cfa:
1027 case DW_CFA_def_cfa_sf:
1028 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1029 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1031 case DW_CFA_def_cfa_expression:
1032 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1035 case DW_CFA_remember_state:
1036 gcc_assert (!remember->in_use);
1038 remember->in_use = 1;
1040 case DW_CFA_restore_state:
1041 gcc_assert (remember->in_use);
1043 remember->in_use = 0;
1051 /* Find the previous value for the CFA. */
1054 lookup_cfa (dw_cfa_location *loc)
1058 dw_cfa_location remember;
1060 memset (loc, 0, sizeof (*loc));
1061 loc->reg = INVALID_REGNUM;
1064 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1065 lookup_cfa_1 (cfi, loc, &remember);
1067 fde = current_fde ();
1069 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1070 lookup_cfa_1 (cfi, loc, &remember);
1073 /* The current rule for calculating the DWARF2 canonical frame address. */
1074 static dw_cfa_location cfa;
1076 /* The register used for saving registers to the stack, and its offset
1078 static dw_cfa_location cfa_store;
1080 /* The current save location around an epilogue. */
1081 static dw_cfa_location cfa_remember;
1083 /* The running total of the size of arguments pushed onto the stack. */
1084 static HOST_WIDE_INT args_size;
1086 /* The last args_size we actually output. */
1087 static HOST_WIDE_INT old_args_size;
1089 /* Entry point to update the canonical frame address (CFA).
1090 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1091 calculated from REG+OFFSET. */
1094 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1096 dw_cfa_location loc;
1098 loc.base_offset = 0;
1100 loc.offset = offset;
1101 def_cfa_1 (label, &loc);
1104 /* Determine if two dw_cfa_location structures define the same data. */
1107 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1109 return (loc1->reg == loc2->reg
1110 && loc1->offset == loc2->offset
1111 && loc1->indirect == loc2->indirect
1112 && (loc1->indirect == 0
1113 || loc1->base_offset == loc2->base_offset));
1116 /* This routine does the actual work. The CFA is now calculated from
1117 the dw_cfa_location structure. */
1120 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1123 dw_cfa_location old_cfa, loc;
1128 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1129 cfa_store.offset = loc.offset;
1131 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1132 lookup_cfa (&old_cfa);
1134 /* If nothing changed, no need to issue any call frame instructions. */
1135 if (cfa_equal_p (&loc, &old_cfa))
1140 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1142 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1143 the CFA register did not change but the offset did. The data
1144 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1145 in the assembler via the .cfi_def_cfa_offset directive. */
1147 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1149 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1150 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1153 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1154 else if (loc.offset == old_cfa.offset
1155 && old_cfa.reg != INVALID_REGNUM
1157 && !old_cfa.indirect)
1159 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1160 indicating the CFA register has changed to <register> but the
1161 offset has not changed. */
1162 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1163 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1167 else if (loc.indirect == 0)
1169 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1170 indicating the CFA register has changed to <register> with
1171 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1172 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1175 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1177 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1178 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1179 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1183 /* Construct a DW_CFA_def_cfa_expression instruction to
1184 calculate the CFA using a full location expression since no
1185 register-offset pair is available. */
1186 struct dw_loc_descr_struct *loc_list;
1188 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1189 loc_list = build_cfa_loc (&loc, 0);
1190 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1193 add_fde_cfi (label, cfi);
1196 /* Add the CFI for saving a register. REG is the CFA column number.
1197 LABEL is passed to add_fde_cfi.
1198 If SREG is -1, the register is saved at OFFSET from the CFA;
1199 otherwise it is saved in SREG. */
1202 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1204 dw_cfi_ref cfi = new_cfi ();
1205 dw_fde_ref fde = current_fde ();
1207 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1209 /* When stack is aligned, store REG using DW_CFA_expression with
1212 && fde->stack_realign
1213 && sreg == INVALID_REGNUM)
1215 cfi->dw_cfi_opc = DW_CFA_expression;
1216 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1217 cfi->dw_cfi_oprnd2.dw_cfi_loc
1218 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1220 else if (sreg == INVALID_REGNUM)
1222 if (need_data_align_sf_opcode (offset))
1223 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1224 else if (reg & ~0x3f)
1225 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1227 cfi->dw_cfi_opc = DW_CFA_offset;
1228 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1230 else if (sreg == reg)
1231 cfi->dw_cfi_opc = DW_CFA_same_value;
1234 cfi->dw_cfi_opc = DW_CFA_register;
1235 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1238 add_fde_cfi (label, cfi);
1241 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1242 This CFI tells the unwinder that it needs to restore the window registers
1243 from the previous frame's window save area.
1245 ??? Perhaps we should note in the CIE where windows are saved (instead of
1246 assuming 0(cfa)) and what registers are in the window. */
1249 dwarf2out_window_save (const char *label)
1251 dw_cfi_ref cfi = new_cfi ();
1253 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1254 add_fde_cfi (label, cfi);
1257 /* Entry point for saving a register to the stack. REG is the GCC register
1258 number. LABEL and OFFSET are passed to reg_save. */
1261 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1263 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1266 /* Entry point for saving the return address in the stack.
1267 LABEL and OFFSET are passed to reg_save. */
1270 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1272 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1275 /* Entry point for saving the return address in a register.
1276 LABEL and SREG are passed to reg_save. */
1279 dwarf2out_return_reg (const char *label, unsigned int sreg)
1281 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1284 /* Record the initial position of the return address. RTL is
1285 INCOMING_RETURN_ADDR_RTX. */
1288 initial_return_save (rtx rtl)
1290 unsigned int reg = INVALID_REGNUM;
1291 HOST_WIDE_INT offset = 0;
1293 switch (GET_CODE (rtl))
1296 /* RA is in a register. */
1297 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1301 /* RA is on the stack. */
1302 rtl = XEXP (rtl, 0);
1303 switch (GET_CODE (rtl))
1306 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1311 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1312 offset = INTVAL (XEXP (rtl, 1));
1316 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1317 offset = -INTVAL (XEXP (rtl, 1));
1327 /* The return address is at some offset from any value we can
1328 actually load. For instance, on the SPARC it is in %i7+8. Just
1329 ignore the offset for now; it doesn't matter for unwinding frames. */
1330 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1331 initial_return_save (XEXP (rtl, 0));
1338 if (reg != DWARF_FRAME_RETURN_COLUMN)
1339 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1342 /* Given a SET, calculate the amount of stack adjustment it
1345 static HOST_WIDE_INT
1346 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1347 HOST_WIDE_INT cur_offset)
1349 const_rtx src = SET_SRC (pattern);
1350 const_rtx dest = SET_DEST (pattern);
1351 HOST_WIDE_INT offset = 0;
1354 if (dest == stack_pointer_rtx)
1356 code = GET_CODE (src);
1358 /* Assume (set (reg sp) (reg whatever)) sets args_size
1360 if (code == REG && src != stack_pointer_rtx)
1362 offset = -cur_args_size;
1363 #ifndef STACK_GROWS_DOWNWARD
1366 return offset - cur_offset;
1369 if (! (code == PLUS || code == MINUS)
1370 || XEXP (src, 0) != stack_pointer_rtx
1371 || !CONST_INT_P (XEXP (src, 1)))
1374 /* (set (reg sp) (plus (reg sp) (const_int))) */
1375 offset = INTVAL (XEXP (src, 1));
1381 if (MEM_P (src) && !MEM_P (dest))
1385 /* (set (mem (pre_dec (reg sp))) (foo)) */
1386 src = XEXP (dest, 0);
1387 code = GET_CODE (src);
1393 if (XEXP (src, 0) == stack_pointer_rtx)
1395 rtx val = XEXP (XEXP (src, 1), 1);
1396 /* We handle only adjustments by constant amount. */
1397 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1398 && CONST_INT_P (val));
1399 offset = -INTVAL (val);
1406 if (XEXP (src, 0) == stack_pointer_rtx)
1408 offset = GET_MODE_SIZE (GET_MODE (dest));
1415 if (XEXP (src, 0) == stack_pointer_rtx)
1417 offset = -GET_MODE_SIZE (GET_MODE (dest));
1432 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1433 indexed by INSN_UID. */
1435 static HOST_WIDE_INT *barrier_args_size;
1437 /* Helper function for compute_barrier_args_size. Handle one insn. */
1439 static HOST_WIDE_INT
1440 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1441 VEC (rtx, heap) **next)
1443 HOST_WIDE_INT offset = 0;
1446 if (! RTX_FRAME_RELATED_P (insn))
1448 if (prologue_epilogue_contains (insn))
1450 else if (GET_CODE (PATTERN (insn)) == SET)
1451 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1452 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1453 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1455 /* There may be stack adjustments inside compound insns. Search
1457 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1458 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1459 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1460 cur_args_size, offset);
1465 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1469 expr = XEXP (expr, 0);
1470 if (GET_CODE (expr) == PARALLEL
1471 || GET_CODE (expr) == SEQUENCE)
1472 for (i = 1; i < XVECLEN (expr, 0); i++)
1474 rtx elem = XVECEXP (expr, 0, i);
1476 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1477 offset += stack_adjust_offset (elem, cur_args_size, offset);
1482 #ifndef STACK_GROWS_DOWNWARD
1486 cur_args_size += offset;
1487 if (cur_args_size < 0)
1492 rtx dest = JUMP_LABEL (insn);
1496 if (barrier_args_size [INSN_UID (dest)] < 0)
1498 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1499 VEC_safe_push (rtx, heap, *next, dest);
1504 return cur_args_size;
1507 /* Walk the whole function and compute args_size on BARRIERs. */
1510 compute_barrier_args_size (void)
1512 int max_uid = get_max_uid (), i;
1514 VEC (rtx, heap) *worklist, *next, *tmp;
1516 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1517 for (i = 0; i < max_uid; i++)
1518 barrier_args_size[i] = -1;
1520 worklist = VEC_alloc (rtx, heap, 20);
1521 next = VEC_alloc (rtx, heap, 20);
1522 insn = get_insns ();
1523 barrier_args_size[INSN_UID (insn)] = 0;
1524 VEC_quick_push (rtx, worklist, insn);
1527 while (!VEC_empty (rtx, worklist))
1529 rtx prev, body, first_insn;
1530 HOST_WIDE_INT cur_args_size;
1532 first_insn = insn = VEC_pop (rtx, worklist);
1533 cur_args_size = barrier_args_size[INSN_UID (insn)];
1534 prev = prev_nonnote_insn (insn);
1535 if (prev && BARRIER_P (prev))
1536 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1538 for (; insn; insn = NEXT_INSN (insn))
1540 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1542 if (BARRIER_P (insn))
1547 if (insn == first_insn)
1549 else if (barrier_args_size[INSN_UID (insn)] < 0)
1551 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1556 /* The insns starting with this label have been
1557 already scanned or are in the worklist. */
1562 body = PATTERN (insn);
1563 if (GET_CODE (body) == SEQUENCE)
1565 HOST_WIDE_INT dest_args_size = cur_args_size;
1566 for (i = 1; i < XVECLEN (body, 0); i++)
1567 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1568 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1570 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1571 dest_args_size, &next);
1574 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1575 cur_args_size, &next);
1577 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1578 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1579 dest_args_size, &next);
1582 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1583 cur_args_size, &next);
1587 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1591 if (VEC_empty (rtx, next))
1594 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1598 VEC_truncate (rtx, next, 0);
1601 VEC_free (rtx, heap, worklist);
1602 VEC_free (rtx, heap, next);
1605 /* Add a CFI to update the running total of the size of arguments
1606 pushed onto the stack. */
1609 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1613 if (size == old_args_size)
1616 old_args_size = size;
1619 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1620 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1621 add_fde_cfi (label, cfi);
1624 /* Record a stack adjustment of OFFSET bytes. */
1627 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1629 if (cfa.reg == STACK_POINTER_REGNUM)
1630 cfa.offset += offset;
1632 if (cfa_store.reg == STACK_POINTER_REGNUM)
1633 cfa_store.offset += offset;
1635 if (ACCUMULATE_OUTGOING_ARGS)
1638 #ifndef STACK_GROWS_DOWNWARD
1642 args_size += offset;
1646 def_cfa_1 (label, &cfa);
1647 if (flag_asynchronous_unwind_tables)
1648 dwarf2out_args_size (label, args_size);
1651 /* Check INSN to see if it looks like a push or a stack adjustment, and
1652 make a note of it if it does. EH uses this information to find out
1653 how much extra space it needs to pop off the stack. */
1656 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1658 HOST_WIDE_INT offset;
1662 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1663 with this function. Proper support would require all frame-related
1664 insns to be marked, and to be able to handle saving state around
1665 epilogues textually in the middle of the function. */
1666 if (prologue_epilogue_contains (insn))
1669 /* If INSN is an instruction from target of an annulled branch, the
1670 effects are for the target only and so current argument size
1671 shouldn't change at all. */
1673 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1674 && INSN_FROM_TARGET_P (insn))
1677 /* If only calls can throw, and we have a frame pointer,
1678 save up adjustments until we see the CALL_INSN. */
1679 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1681 if (CALL_P (insn) && !after_p)
1683 /* Extract the size of the args from the CALL rtx itself. */
1684 insn = PATTERN (insn);
1685 if (GET_CODE (insn) == PARALLEL)
1686 insn = XVECEXP (insn, 0, 0);
1687 if (GET_CODE (insn) == SET)
1688 insn = SET_SRC (insn);
1689 gcc_assert (GET_CODE (insn) == CALL);
1690 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1695 if (CALL_P (insn) && !after_p)
1697 if (!flag_asynchronous_unwind_tables)
1698 dwarf2out_args_size ("", args_size);
1701 else if (BARRIER_P (insn))
1703 /* Don't call compute_barrier_args_size () if the only
1704 BARRIER is at the end of function. */
1705 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1706 compute_barrier_args_size ();
1707 if (barrier_args_size == NULL)
1711 offset = barrier_args_size[INSN_UID (insn)];
1716 offset -= args_size;
1717 #ifndef STACK_GROWS_DOWNWARD
1721 else if (GET_CODE (PATTERN (insn)) == SET)
1722 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1723 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1724 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1726 /* There may be stack adjustments inside compound insns. Search
1728 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1729 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1730 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1739 label = dwarf2out_cfi_label (false);
1740 dwarf2out_stack_adjust (offset, label);
1743 /* We delay emitting a register save until either (a) we reach the end
1744 of the prologue or (b) the register is clobbered. This clusters
1745 register saves so that there are fewer pc advances. */
1747 struct GTY(()) queued_reg_save {
1748 struct queued_reg_save *next;
1750 HOST_WIDE_INT cfa_offset;
1754 static GTY(()) struct queued_reg_save *queued_reg_saves;
1756 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1757 struct GTY(()) reg_saved_in_data {
1762 /* A list of registers saved in other registers.
1763 The list intentionally has a small maximum capacity of 4; if your
1764 port needs more than that, you might consider implementing a
1765 more efficient data structure. */
1766 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1767 static GTY(()) size_t num_regs_saved_in_regs;
1769 static const char *last_reg_save_label;
1771 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1772 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1775 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1777 struct queued_reg_save *q;
1779 /* Duplicates waste space, but it's also necessary to remove them
1780 for correctness, since the queue gets output in reverse
1782 for (q = queued_reg_saves; q != NULL; q = q->next)
1783 if (REGNO (q->reg) == REGNO (reg))
1788 q = ggc_alloc_queued_reg_save ();
1789 q->next = queued_reg_saves;
1790 queued_reg_saves = q;
1794 q->cfa_offset = offset;
1795 q->saved_reg = sreg;
1797 last_reg_save_label = label;
1800 /* Output all the entries in QUEUED_REG_SAVES. */
1803 dwarf2out_flush_queued_reg_saves (void)
1805 struct queued_reg_save *q;
1807 for (q = queued_reg_saves; q; q = q->next)
1810 unsigned int reg, sreg;
1812 for (i = 0; i < num_regs_saved_in_regs; i++)
1813 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1815 if (q->saved_reg && i == num_regs_saved_in_regs)
1817 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1818 num_regs_saved_in_regs++;
1820 if (i != num_regs_saved_in_regs)
1822 regs_saved_in_regs[i].orig_reg = q->reg;
1823 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1826 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1828 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1830 sreg = INVALID_REGNUM;
1831 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1834 queued_reg_saves = NULL;
1835 last_reg_save_label = NULL;
1838 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1839 location for? Or, does it clobber a register which we've previously
1840 said that some other register is saved in, and for which we now
1841 have a new location for? */
1844 clobbers_queued_reg_save (const_rtx insn)
1846 struct queued_reg_save *q;
1848 for (q = queued_reg_saves; q; q = q->next)
1851 if (modified_in_p (q->reg, insn))
1853 for (i = 0; i < num_regs_saved_in_regs; i++)
1854 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1855 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1862 /* Entry point for saving the first register into the second. */
1865 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1868 unsigned int regno, sregno;
1870 for (i = 0; i < num_regs_saved_in_regs; i++)
1871 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1873 if (i == num_regs_saved_in_regs)
1875 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1876 num_regs_saved_in_regs++;
1878 regs_saved_in_regs[i].orig_reg = reg;
1879 regs_saved_in_regs[i].saved_in_reg = sreg;
1881 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1882 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1883 reg_save (label, regno, sregno, 0);
1886 /* What register, if any, is currently saved in REG? */
1889 reg_saved_in (rtx reg)
1891 unsigned int regn = REGNO (reg);
1893 struct queued_reg_save *q;
1895 for (q = queued_reg_saves; q; q = q->next)
1896 if (q->saved_reg && regn == REGNO (q->saved_reg))
1899 for (i = 0; i < num_regs_saved_in_regs; i++)
1900 if (regs_saved_in_regs[i].saved_in_reg
1901 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1902 return regs_saved_in_regs[i].orig_reg;
1908 /* A temporary register holding an integral value used in adjusting SP
1909 or setting up the store_reg. The "offset" field holds the integer
1910 value, not an offset. */
1911 static dw_cfa_location cfa_temp;
1913 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1916 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1918 memset (&cfa, 0, sizeof (cfa));
1920 switch (GET_CODE (pat))
1923 cfa.reg = REGNO (XEXP (pat, 0));
1924 cfa.offset = INTVAL (XEXP (pat, 1));
1928 cfa.reg = REGNO (pat);
1933 pat = XEXP (pat, 0);
1934 if (GET_CODE (pat) == PLUS)
1936 cfa.base_offset = INTVAL (XEXP (pat, 1));
1937 pat = XEXP (pat, 0);
1939 cfa.reg = REGNO (pat);
1943 /* Recurse and define an expression. */
1947 def_cfa_1 (label, &cfa);
1950 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1953 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1957 gcc_assert (GET_CODE (pat) == SET);
1958 dest = XEXP (pat, 0);
1959 src = XEXP (pat, 1);
1961 switch (GET_CODE (src))
1964 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1965 cfa.offset -= INTVAL (XEXP (src, 1));
1975 cfa.reg = REGNO (dest);
1976 gcc_assert (cfa.indirect == 0);
1978 def_cfa_1 (label, &cfa);
1981 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1984 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1986 HOST_WIDE_INT offset;
1987 rtx src, addr, span;
1989 src = XEXP (set, 1);
1990 addr = XEXP (set, 0);
1991 gcc_assert (MEM_P (addr));
1992 addr = XEXP (addr, 0);
1994 /* As documented, only consider extremely simple addresses. */
1995 switch (GET_CODE (addr))
1998 gcc_assert (REGNO (addr) == cfa.reg);
1999 offset = -cfa.offset;
2002 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
2003 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
2009 span = targetm.dwarf_register_span (src);
2011 /* ??? We'd like to use queue_reg_save, but we need to come up with
2012 a different flushing heuristic for epilogues. */
2014 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2017 /* We have a PARALLEL describing where the contents of SRC live.
2018 Queue register saves for each piece of the PARALLEL. */
2021 HOST_WIDE_INT span_offset = offset;
2023 gcc_assert (GET_CODE (span) == PARALLEL);
2025 limit = XVECLEN (span, 0);
2026 for (par_index = 0; par_index < limit; par_index++)
2028 rtx elem = XVECEXP (span, 0, par_index);
2030 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2031 INVALID_REGNUM, span_offset);
2032 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2037 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2040 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2043 unsigned sregno, dregno;
2045 src = XEXP (set, 1);
2046 dest = XEXP (set, 0);
2049 sregno = DWARF_FRAME_RETURN_COLUMN;
2051 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2053 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2055 /* ??? We'd like to use queue_reg_save, but we need to come up with
2056 a different flushing heuristic for epilogues. */
2057 reg_save (label, sregno, dregno, 0);
2060 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2063 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2065 rtx src, dest, span;
2066 dw_cfi_ref cfi = new_cfi ();
2068 dest = SET_DEST (set);
2069 src = SET_SRC (set);
2071 gcc_assert (REG_P (src));
2072 gcc_assert (MEM_P (dest));
2074 span = targetm.dwarf_register_span (src);
2077 cfi->dw_cfi_opc = DW_CFA_expression;
2078 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2079 cfi->dw_cfi_oprnd2.dw_cfi_loc
2080 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2081 VAR_INIT_STATUS_INITIALIZED);
2083 /* ??? We'd like to use queue_reg_save, were the interface different,
2084 and, as above, we could manage flushing for epilogues. */
2085 add_fde_cfi (label, cfi);
2088 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2091 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2093 dw_cfi_ref cfi = new_cfi ();
2094 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2096 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2097 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2099 add_fde_cfi (label, cfi);
2102 /* Record call frame debugging information for an expression EXPR,
2103 which either sets SP or FP (adjusting how we calculate the frame
2104 address) or saves a register to the stack or another register.
2105 LABEL indicates the address of EXPR.
2107 This function encodes a state machine mapping rtxes to actions on
2108 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2109 users need not read the source code.
2111 The High-Level Picture
2113 Changes in the register we use to calculate the CFA: Currently we
2114 assume that if you copy the CFA register into another register, we
2115 should take the other one as the new CFA register; this seems to
2116 work pretty well. If it's wrong for some target, it's simple
2117 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2119 Changes in the register we use for saving registers to the stack:
2120 This is usually SP, but not always. Again, we deduce that if you
2121 copy SP into another register (and SP is not the CFA register),
2122 then the new register is the one we will be using for register
2123 saves. This also seems to work.
2125 Register saves: There's not much guesswork about this one; if
2126 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2127 register save, and the register used to calculate the destination
2128 had better be the one we think we're using for this purpose.
2129 It's also assumed that a copy from a call-saved register to another
2130 register is saving that register if RTX_FRAME_RELATED_P is set on
2131 that instruction. If the copy is from a call-saved register to
2132 the *same* register, that means that the register is now the same
2133 value as in the caller.
2135 Except: If the register being saved is the CFA register, and the
2136 offset is nonzero, we are saving the CFA, so we assume we have to
2137 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2138 the intent is to save the value of SP from the previous frame.
2140 In addition, if a register has previously been saved to a different
2143 Invariants / Summaries of Rules
2145 cfa current rule for calculating the CFA. It usually
2146 consists of a register and an offset.
2147 cfa_store register used by prologue code to save things to the stack
2148 cfa_store.offset is the offset from the value of
2149 cfa_store.reg to the actual CFA
2150 cfa_temp register holding an integral value. cfa_temp.offset
2151 stores the value, which will be used to adjust the
2152 stack pointer. cfa_temp is also used like cfa_store,
2153 to track stores to the stack via fp or a temp reg.
2155 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2156 with cfa.reg as the first operand changes the cfa.reg and its
2157 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2160 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2161 expression yielding a constant. This sets cfa_temp.reg
2162 and cfa_temp.offset.
2164 Rule 5: Create a new register cfa_store used to save items to the
2167 Rules 10-14: Save a register to the stack. Define offset as the
2168 difference of the original location and cfa_store's
2169 location (or cfa_temp's location if cfa_temp is used).
2171 Rules 16-20: If AND operation happens on sp in prologue, we assume
2172 stack is realigned. We will use a group of DW_OP_XXX
2173 expressions to represent the location of the stored
2174 register instead of CFA+offset.
2178 "{a,b}" indicates a choice of a xor b.
2179 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2182 (set <reg1> <reg2>:cfa.reg)
2183 effects: cfa.reg = <reg1>
2184 cfa.offset unchanged
2185 cfa_temp.reg = <reg1>
2186 cfa_temp.offset = cfa.offset
2189 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2190 {<const_int>,<reg>:cfa_temp.reg}))
2191 effects: cfa.reg = sp if fp used
2192 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2193 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2194 if cfa_store.reg==sp
2197 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2198 effects: cfa.reg = fp
2199 cfa_offset += +/- <const_int>
2202 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2203 constraints: <reg1> != fp
2205 effects: cfa.reg = <reg1>
2206 cfa_temp.reg = <reg1>
2207 cfa_temp.offset = cfa.offset
2210 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2211 constraints: <reg1> != fp
2213 effects: cfa_store.reg = <reg1>
2214 cfa_store.offset = cfa.offset - cfa_temp.offset
2217 (set <reg> <const_int>)
2218 effects: cfa_temp.reg = <reg>
2219 cfa_temp.offset = <const_int>
2222 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2223 effects: cfa_temp.reg = <reg1>
2224 cfa_temp.offset |= <const_int>
2227 (set <reg> (high <exp>))
2231 (set <reg> (lo_sum <exp> <const_int>))
2232 effects: cfa_temp.reg = <reg>
2233 cfa_temp.offset = <const_int>
2236 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2237 effects: cfa_store.offset -= <const_int>
2238 cfa.offset = cfa_store.offset if cfa.reg == sp
2240 cfa.base_offset = -cfa_store.offset
2243 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2244 effects: cfa_store.offset += -/+ mode_size(mem)
2245 cfa.offset = cfa_store.offset if cfa.reg == sp
2247 cfa.base_offset = -cfa_store.offset
2250 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2253 effects: cfa.reg = <reg1>
2254 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2257 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2258 effects: cfa.reg = <reg1>
2259 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2262 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2263 effects: cfa.reg = <reg1>
2264 cfa.base_offset = -cfa_temp.offset
2265 cfa_temp.offset -= mode_size(mem)
2268 (set <reg> {unspec, unspec_volatile})
2269 effects: target-dependent
2272 (set sp (and: sp <const_int>))
2273 constraints: cfa_store.reg == sp
2274 effects: current_fde.stack_realign = 1
2275 cfa_store.offset = 0
2276 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2279 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2280 effects: cfa_store.offset += -/+ mode_size(mem)
2283 (set (mem ({pre_inc, pre_dec} sp)) fp)
2284 constraints: fde->stack_realign == 1
2285 effects: cfa_store.offset = 0
2286 cfa.reg != HARD_FRAME_POINTER_REGNUM
2289 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2290 constraints: fde->stack_realign == 1
2292 && cfa.indirect == 0
2293 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2294 effects: Use DW_CFA_def_cfa_expression to define cfa
2295 cfa.reg == fde->drap_reg */
2298 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2300 rtx src, dest, span;
2301 HOST_WIDE_INT offset;
2304 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2305 the PARALLEL independently. The first element is always processed if
2306 it is a SET. This is for backward compatibility. Other elements
2307 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2308 flag is set in them. */
2309 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2312 int limit = XVECLEN (expr, 0);
2315 /* PARALLELs have strict read-modify-write semantics, so we
2316 ought to evaluate every rvalue before changing any lvalue.
2317 It's cumbersome to do that in general, but there's an
2318 easy approximation that is enough for all current users:
2319 handle register saves before register assignments. */
2320 if (GET_CODE (expr) == PARALLEL)
2321 for (par_index = 0; par_index < limit; par_index++)
2323 elem = XVECEXP (expr, 0, par_index);
2324 if (GET_CODE (elem) == SET
2325 && MEM_P (SET_DEST (elem))
2326 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2327 dwarf2out_frame_debug_expr (elem, label);
2330 for (par_index = 0; par_index < limit; par_index++)
2332 elem = XVECEXP (expr, 0, par_index);
2333 if (GET_CODE (elem) == SET
2334 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2335 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2336 dwarf2out_frame_debug_expr (elem, label);
2337 else if (GET_CODE (elem) == SET
2339 && !RTX_FRAME_RELATED_P (elem))
2341 /* Stack adjustment combining might combine some post-prologue
2342 stack adjustment into a prologue stack adjustment. */
2343 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2346 dwarf2out_stack_adjust (offset, label);
2352 gcc_assert (GET_CODE (expr) == SET);
2354 src = SET_SRC (expr);
2355 dest = SET_DEST (expr);
2359 rtx rsi = reg_saved_in (src);
2364 fde = current_fde ();
2366 switch (GET_CODE (dest))
2369 switch (GET_CODE (src))
2371 /* Setting FP from SP. */
2373 if (cfa.reg == (unsigned) REGNO (src))
2376 /* Update the CFA rule wrt SP or FP. Make sure src is
2377 relative to the current CFA register.
2379 We used to require that dest be either SP or FP, but the
2380 ARM copies SP to a temporary register, and from there to
2381 FP. So we just rely on the backends to only set
2382 RTX_FRAME_RELATED_P on appropriate insns. */
2383 cfa.reg = REGNO (dest);
2384 cfa_temp.reg = cfa.reg;
2385 cfa_temp.offset = cfa.offset;
2389 /* Saving a register in a register. */
2390 gcc_assert (!fixed_regs [REGNO (dest)]
2391 /* For the SPARC and its register window. */
2392 || (DWARF_FRAME_REGNUM (REGNO (src))
2393 == DWARF_FRAME_RETURN_COLUMN));
2395 /* After stack is aligned, we can only save SP in FP
2396 if drap register is used. In this case, we have
2397 to restore stack pointer with the CFA value and we
2398 don't generate this DWARF information. */
2400 && fde->stack_realign
2401 && REGNO (src) == STACK_POINTER_REGNUM)
2402 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2403 && fde->drap_reg != INVALID_REGNUM
2404 && cfa.reg != REGNO (src));
2406 queue_reg_save (label, src, dest, 0);
2413 if (dest == stack_pointer_rtx)
2417 switch (GET_CODE (XEXP (src, 1)))
2420 offset = INTVAL (XEXP (src, 1));
2423 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2425 offset = cfa_temp.offset;
2431 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2433 /* Restoring SP from FP in the epilogue. */
2434 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2435 cfa.reg = STACK_POINTER_REGNUM;
2437 else if (GET_CODE (src) == LO_SUM)
2438 /* Assume we've set the source reg of the LO_SUM from sp. */
2441 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2443 if (GET_CODE (src) != MINUS)
2445 if (cfa.reg == STACK_POINTER_REGNUM)
2446 cfa.offset += offset;
2447 if (cfa_store.reg == STACK_POINTER_REGNUM)
2448 cfa_store.offset += offset;
2450 else if (dest == hard_frame_pointer_rtx)
2453 /* Either setting the FP from an offset of the SP,
2454 or adjusting the FP */
2455 gcc_assert (frame_pointer_needed);
2457 gcc_assert (REG_P (XEXP (src, 0))
2458 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2459 && CONST_INT_P (XEXP (src, 1)));
2460 offset = INTVAL (XEXP (src, 1));
2461 if (GET_CODE (src) != MINUS)
2463 cfa.offset += offset;
2464 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2468 gcc_assert (GET_CODE (src) != MINUS);
2471 if (REG_P (XEXP (src, 0))
2472 && REGNO (XEXP (src, 0)) == cfa.reg
2473 && CONST_INT_P (XEXP (src, 1)))
2475 /* Setting a temporary CFA register that will be copied
2476 into the FP later on. */
2477 offset = - INTVAL (XEXP (src, 1));
2478 cfa.offset += offset;
2479 cfa.reg = REGNO (dest);
2480 /* Or used to save regs to the stack. */
2481 cfa_temp.reg = cfa.reg;
2482 cfa_temp.offset = cfa.offset;
2486 else if (REG_P (XEXP (src, 0))
2487 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2488 && XEXP (src, 1) == stack_pointer_rtx)
2490 /* Setting a scratch register that we will use instead
2491 of SP for saving registers to the stack. */
2492 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2493 cfa_store.reg = REGNO (dest);
2494 cfa_store.offset = cfa.offset - cfa_temp.offset;
2498 else if (GET_CODE (src) == LO_SUM
2499 && CONST_INT_P (XEXP (src, 1)))
2501 cfa_temp.reg = REGNO (dest);
2502 cfa_temp.offset = INTVAL (XEXP (src, 1));
2511 cfa_temp.reg = REGNO (dest);
2512 cfa_temp.offset = INTVAL (src);
2517 gcc_assert (REG_P (XEXP (src, 0))
2518 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2519 && CONST_INT_P (XEXP (src, 1)));
2521 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2522 cfa_temp.reg = REGNO (dest);
2523 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2526 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2527 which will fill in all of the bits. */
2534 case UNSPEC_VOLATILE:
2535 gcc_assert (targetm.dwarf_handle_frame_unspec);
2536 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2541 /* If this AND operation happens on stack pointer in prologue,
2542 we assume the stack is realigned and we extract the
2544 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2546 /* We interpret reg_save differently with stack_realign set.
2547 Thus we must flush whatever we have queued first. */
2548 dwarf2out_flush_queued_reg_saves ();
2550 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2551 fde->stack_realign = 1;
2552 fde->stack_realignment = INTVAL (XEXP (src, 1));
2553 cfa_store.offset = 0;
2555 if (cfa.reg != STACK_POINTER_REGNUM
2556 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2557 fde->drap_reg = cfa.reg;
2565 def_cfa_1 (label, &cfa);
2570 /* Saving a register to the stack. Make sure dest is relative to the
2572 switch (GET_CODE (XEXP (dest, 0)))
2577 /* We can't handle variable size modifications. */
2578 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2580 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2582 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2583 && cfa_store.reg == STACK_POINTER_REGNUM);
2585 cfa_store.offset += offset;
2586 if (cfa.reg == STACK_POINTER_REGNUM)
2587 cfa.offset = cfa_store.offset;
2589 offset = -cfa_store.offset;
2595 offset = GET_MODE_SIZE (GET_MODE (dest));
2596 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2599 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2600 == STACK_POINTER_REGNUM)
2601 && cfa_store.reg == STACK_POINTER_REGNUM);
2603 cfa_store.offset += offset;
2605 /* Rule 18: If stack is aligned, we will use FP as a
2606 reference to represent the address of the stored
2609 && fde->stack_realign
2610 && src == hard_frame_pointer_rtx)
2612 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2613 cfa_store.offset = 0;
2616 if (cfa.reg == STACK_POINTER_REGNUM)
2617 cfa.offset = cfa_store.offset;
2619 offset = -cfa_store.offset;
2623 /* With an offset. */
2630 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2631 && REG_P (XEXP (XEXP (dest, 0), 0)));
2632 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2633 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2636 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2638 if (cfa.reg == (unsigned) regno)
2639 offset -= cfa.offset;
2640 else if (cfa_store.reg == (unsigned) regno)
2641 offset -= cfa_store.offset;
2644 gcc_assert (cfa_temp.reg == (unsigned) regno);
2645 offset -= cfa_temp.offset;
2651 /* Without an offset. */
2654 int regno = REGNO (XEXP (dest, 0));
2656 if (cfa.reg == (unsigned) regno)
2657 offset = -cfa.offset;
2658 else if (cfa_store.reg == (unsigned) regno)
2659 offset = -cfa_store.offset;
2662 gcc_assert (cfa_temp.reg == (unsigned) regno);
2663 offset = -cfa_temp.offset;
2670 gcc_assert (cfa_temp.reg
2671 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2672 offset = -cfa_temp.offset;
2673 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2681 /* If the source operand of this MEM operation is not a
2682 register, basically the source is return address. Here
2683 we only care how much stack grew and we don't save it. */
2687 if (REGNO (src) != STACK_POINTER_REGNUM
2688 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2689 && (unsigned) REGNO (src) == cfa.reg)
2691 /* We're storing the current CFA reg into the stack. */
2693 if (cfa.offset == 0)
2696 /* If stack is aligned, putting CFA reg into stack means
2697 we can no longer use reg + offset to represent CFA.
2698 Here we use DW_CFA_def_cfa_expression instead. The
2699 result of this expression equals to the original CFA
2702 && fde->stack_realign
2703 && cfa.indirect == 0
2704 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2706 dw_cfa_location cfa_exp;
2708 gcc_assert (fde->drap_reg == cfa.reg);
2710 cfa_exp.indirect = 1;
2711 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2712 cfa_exp.base_offset = offset;
2715 fde->drap_reg_saved = 1;
2717 def_cfa_1 (label, &cfa_exp);
2721 /* If the source register is exactly the CFA, assume
2722 we're saving SP like any other register; this happens
2724 def_cfa_1 (label, &cfa);
2725 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2730 /* Otherwise, we'll need to look in the stack to
2731 calculate the CFA. */
2732 rtx x = XEXP (dest, 0);
2736 gcc_assert (REG_P (x));
2738 cfa.reg = REGNO (x);
2739 cfa.base_offset = offset;
2741 def_cfa_1 (label, &cfa);
2746 def_cfa_1 (label, &cfa);
2748 span = targetm.dwarf_register_span (src);
2751 queue_reg_save (label, src, NULL_RTX, offset);
2754 /* We have a PARALLEL describing where the contents of SRC
2755 live. Queue register saves for each piece of the
2759 HOST_WIDE_INT span_offset = offset;
2761 gcc_assert (GET_CODE (span) == PARALLEL);
2763 limit = XVECLEN (span, 0);
2764 for (par_index = 0; par_index < limit; par_index++)
2766 rtx elem = XVECEXP (span, 0, par_index);
2768 queue_reg_save (label, elem, NULL_RTX, span_offset);
2769 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2780 /* Record call frame debugging information for INSN, which either
2781 sets SP or FP (adjusting how we calculate the frame address) or saves a
2782 register to the stack. If INSN is NULL_RTX, initialize our state.
2784 If AFTER_P is false, we're being called before the insn is emitted,
2785 otherwise after. Call instructions get invoked twice. */
2788 dwarf2out_frame_debug (rtx insn, bool after_p)
2792 bool handled_one = false;
2794 if (insn == NULL_RTX)
2798 /* Flush any queued register saves. */
2799 dwarf2out_flush_queued_reg_saves ();
2801 /* Set up state for generating call frame debug info. */
2804 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2806 cfa.reg = STACK_POINTER_REGNUM;
2809 cfa_temp.offset = 0;
2811 for (i = 0; i < num_regs_saved_in_regs; i++)
2813 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2814 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2816 num_regs_saved_in_regs = 0;
2818 if (barrier_args_size)
2820 XDELETEVEC (barrier_args_size);
2821 barrier_args_size = NULL;
2826 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2827 dwarf2out_flush_queued_reg_saves ();
2829 if (!RTX_FRAME_RELATED_P (insn))
2831 /* ??? This should be done unconditionally since stack adjustments
2832 matter if the stack pointer is not the CFA register anymore but
2833 is still used to save registers. */
2834 if (!ACCUMULATE_OUTGOING_ARGS)
2835 dwarf2out_notice_stack_adjust (insn, after_p);
2839 label = dwarf2out_cfi_label (false);
2840 any_cfis_emitted = false;
2842 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2843 switch (REG_NOTE_KIND (note))
2845 case REG_FRAME_RELATED_EXPR:
2846 insn = XEXP (note, 0);
2849 case REG_CFA_DEF_CFA:
2850 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2854 case REG_CFA_ADJUST_CFA:
2859 if (GET_CODE (n) == PARALLEL)
2860 n = XVECEXP (n, 0, 0);
2862 dwarf2out_frame_debug_adjust_cfa (n, label);
2866 case REG_CFA_OFFSET:
2869 n = single_set (insn);
2870 dwarf2out_frame_debug_cfa_offset (n, label);
2874 case REG_CFA_REGISTER:
2879 if (GET_CODE (n) == PARALLEL)
2880 n = XVECEXP (n, 0, 0);
2882 dwarf2out_frame_debug_cfa_register (n, label);
2886 case REG_CFA_EXPRESSION:
2889 n = single_set (insn);
2890 dwarf2out_frame_debug_cfa_expression (n, label);
2894 case REG_CFA_RESTORE:
2899 if (GET_CODE (n) == PARALLEL)
2900 n = XVECEXP (n, 0, 0);
2903 dwarf2out_frame_debug_cfa_restore (n, label);
2907 case REG_CFA_SET_VDRAP:
2911 dw_fde_ref fde = current_fde ();
2914 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2916 fde->vdrap_reg = REGNO (n);
2927 if (any_cfis_emitted)
2928 dwarf2out_flush_queued_reg_saves ();
2932 insn = PATTERN (insn);
2934 dwarf2out_frame_debug_expr (insn, label);
2936 /* Check again. A parallel can save and update the same register.
2937 We could probably check just once, here, but this is safer than
2938 removing the check above. */
2939 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2940 dwarf2out_flush_queued_reg_saves ();
2943 /* Determine if we need to save and restore CFI information around this
2944 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2945 we do need to save/restore, then emit the save now, and insert a
2946 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2949 dwarf2out_cfi_begin_epilogue (rtx insn)
2951 bool saw_frp = false;
2954 /* Scan forward to the return insn, noticing if there are possible
2955 frame related insns. */
2956 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2961 /* Look for both regular and sibcalls to end the block. */
2962 if (returnjump_p (i))
2964 if (CALL_P (i) && SIBLING_CALL_P (i))
2967 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2970 rtx seq = PATTERN (i);
2972 if (returnjump_p (XVECEXP (seq, 0, 0)))
2974 if (CALL_P (XVECEXP (seq, 0, 0))
2975 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2978 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2979 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2983 if (RTX_FRAME_RELATED_P (i))
2987 /* If the port doesn't emit epilogue unwind info, we don't need a
2988 save/restore pair. */
2992 /* Otherwise, search forward to see if the return insn was the last
2993 basic block of the function. If so, we don't need save/restore. */
2994 gcc_assert (i != NULL);
2995 i = next_real_insn (i);
2999 /* Insert the restore before that next real insn in the stream, and before
3000 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3001 properly nested. This should be after any label or alignment. This
3002 will be pushed into the CFI stream by the function below. */
3005 rtx p = PREV_INSN (i);
3008 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3012 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3014 emit_cfa_remember = true;
3016 /* And emulate the state save. */
3017 gcc_assert (!cfa_remember.in_use);
3019 cfa_remember.in_use = 1;
3022 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3026 dwarf2out_frame_debug_restore_state (void)
3028 dw_cfi_ref cfi = new_cfi ();
3029 const char *label = dwarf2out_cfi_label (false);
3031 cfi->dw_cfi_opc = DW_CFA_restore_state;
3032 add_fde_cfi (label, cfi);
3034 gcc_assert (cfa_remember.in_use);
3036 cfa_remember.in_use = 0;
3039 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3040 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3041 (enum dwarf_call_frame_info cfi);
3043 static enum dw_cfi_oprnd_type
3044 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3049 case DW_CFA_GNU_window_save:
3050 case DW_CFA_remember_state:
3051 case DW_CFA_restore_state:
3052 return dw_cfi_oprnd_unused;
3054 case DW_CFA_set_loc:
3055 case DW_CFA_advance_loc1:
3056 case DW_CFA_advance_loc2:
3057 case DW_CFA_advance_loc4:
3058 case DW_CFA_MIPS_advance_loc8:
3059 return dw_cfi_oprnd_addr;
3062 case DW_CFA_offset_extended:
3063 case DW_CFA_def_cfa:
3064 case DW_CFA_offset_extended_sf:
3065 case DW_CFA_def_cfa_sf:
3066 case DW_CFA_restore:
3067 case DW_CFA_restore_extended:
3068 case DW_CFA_undefined:
3069 case DW_CFA_same_value:
3070 case DW_CFA_def_cfa_register:
3071 case DW_CFA_register:
3072 case DW_CFA_expression:
3073 return dw_cfi_oprnd_reg_num;
3075 case DW_CFA_def_cfa_offset:
3076 case DW_CFA_GNU_args_size:
3077 case DW_CFA_def_cfa_offset_sf:
3078 return dw_cfi_oprnd_offset;
3080 case DW_CFA_def_cfa_expression:
3081 return dw_cfi_oprnd_loc;
3088 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3089 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3090 (enum dwarf_call_frame_info cfi);
3092 static enum dw_cfi_oprnd_type
3093 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3097 case DW_CFA_def_cfa:
3098 case DW_CFA_def_cfa_sf:
3100 case DW_CFA_offset_extended_sf:
3101 case DW_CFA_offset_extended:
3102 return dw_cfi_oprnd_offset;
3104 case DW_CFA_register:
3105 return dw_cfi_oprnd_reg_num;
3107 case DW_CFA_expression:
3108 return dw_cfi_oprnd_loc;
3111 return dw_cfi_oprnd_unused;
3115 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3116 switch to the data section instead, and write out a synthetic start label
3117 for collect2 the first time around. */
3120 switch_to_eh_frame_section (bool back)
3124 #ifdef EH_FRAME_SECTION_NAME
3125 if (eh_frame_section == 0)
3129 if (EH_TABLES_CAN_BE_READ_ONLY)
3135 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3137 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3139 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3141 flags = ((! flag_pic
3142 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3143 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3144 && (per_encoding & 0x70) != DW_EH_PE_absptr
3145 && (per_encoding & 0x70) != DW_EH_PE_aligned
3146 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3147 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3148 ? 0 : SECTION_WRITE);
3151 flags = SECTION_WRITE;
3152 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3154 #endif /* EH_FRAME_SECTION_NAME */
3156 if (eh_frame_section)
3157 switch_to_section (eh_frame_section);
3160 /* We have no special eh_frame section. Put the information in
3161 the data section and emit special labels to guide collect2. */
3162 switch_to_section (data_section);
3166 label = get_file_function_name ("F");
3167 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3168 targetm.asm_out.globalize_label (asm_out_file,
3169 IDENTIFIER_POINTER (label));
3170 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3175 /* Switch [BACK] to the eh or debug frame table section, depending on
3179 switch_to_frame_table_section (int for_eh, bool back)
3182 switch_to_eh_frame_section (back);
3185 if (!debug_frame_section)
3186 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3187 SECTION_DEBUG, NULL);
3188 switch_to_section (debug_frame_section);
3192 /* Output a Call Frame Information opcode and its operand(s). */
3195 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3200 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3201 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3202 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3203 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3204 ((unsigned HOST_WIDE_INT)
3205 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3206 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3208 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3209 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3210 "DW_CFA_offset, column %#lx", r);
3211 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3212 dw2_asm_output_data_uleb128 (off, NULL);
3214 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3216 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3217 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3218 "DW_CFA_restore, column %#lx", r);
3222 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3223 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3225 switch (cfi->dw_cfi_opc)
3227 case DW_CFA_set_loc:
3229 dw2_asm_output_encoded_addr_rtx (
3230 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3231 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3234 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3235 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3236 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3239 case DW_CFA_advance_loc1:
3240 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3241 fde->dw_fde_current_label, NULL);
3242 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3245 case DW_CFA_advance_loc2:
3246 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3247 fde->dw_fde_current_label, NULL);
3248 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3251 case DW_CFA_advance_loc4:
3252 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3253 fde->dw_fde_current_label, NULL);
3254 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3257 case DW_CFA_MIPS_advance_loc8:
3258 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3259 fde->dw_fde_current_label, NULL);
3260 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3263 case DW_CFA_offset_extended:
3264 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3265 dw2_asm_output_data_uleb128 (r, NULL);
3266 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3267 dw2_asm_output_data_uleb128 (off, NULL);
3270 case DW_CFA_def_cfa:
3271 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3272 dw2_asm_output_data_uleb128 (r, NULL);
3273 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3276 case DW_CFA_offset_extended_sf:
3277 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3278 dw2_asm_output_data_uleb128 (r, NULL);
3279 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3280 dw2_asm_output_data_sleb128 (off, NULL);
3283 case DW_CFA_def_cfa_sf:
3284 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3285 dw2_asm_output_data_uleb128 (r, NULL);
3286 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3287 dw2_asm_output_data_sleb128 (off, NULL);
3290 case DW_CFA_restore_extended:
3291 case DW_CFA_undefined:
3292 case DW_CFA_same_value:
3293 case DW_CFA_def_cfa_register:
3294 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3295 dw2_asm_output_data_uleb128 (r, NULL);
3298 case DW_CFA_register:
3299 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3300 dw2_asm_output_data_uleb128 (r, NULL);
3301 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3302 dw2_asm_output_data_uleb128 (r, NULL);
3305 case DW_CFA_def_cfa_offset:
3306 case DW_CFA_GNU_args_size:
3307 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3310 case DW_CFA_def_cfa_offset_sf:
3311 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3312 dw2_asm_output_data_sleb128 (off, NULL);
3315 case DW_CFA_GNU_window_save:
3318 case DW_CFA_def_cfa_expression:
3319 case DW_CFA_expression:
3320 output_cfa_loc (cfi);
3323 case DW_CFA_GNU_negative_offset_extended:
3324 /* Obsoleted by DW_CFA_offset_extended_sf. */
3333 /* Similar, but do it via assembler directives instead. */
3336 output_cfi_directive (dw_cfi_ref cfi)
3338 unsigned long r, r2;
3340 switch (cfi->dw_cfi_opc)
3342 case DW_CFA_advance_loc:
3343 case DW_CFA_advance_loc1:
3344 case DW_CFA_advance_loc2:
3345 case DW_CFA_advance_loc4:
3346 case DW_CFA_MIPS_advance_loc8:
3347 case DW_CFA_set_loc:
3348 /* Should only be created by add_fde_cfi in a code path not
3349 followed when emitting via directives. The assembler is
3350 going to take care of this for us. */
3354 case DW_CFA_offset_extended:
3355 case DW_CFA_offset_extended_sf:
3356 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3357 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3358 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3361 case DW_CFA_restore:
3362 case DW_CFA_restore_extended:
3363 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3364 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3367 case DW_CFA_undefined:
3368 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3369 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3372 case DW_CFA_same_value:
3373 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3374 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3377 case DW_CFA_def_cfa:
3378 case DW_CFA_def_cfa_sf:
3379 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3380 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3381 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3384 case DW_CFA_def_cfa_register:
3385 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3386 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3389 case DW_CFA_register:
3390 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3391 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3392 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3395 case DW_CFA_def_cfa_offset:
3396 case DW_CFA_def_cfa_offset_sf:
3397 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3398 HOST_WIDE_INT_PRINT_DEC"\n",
3399 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3402 case DW_CFA_remember_state:
3403 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3405 case DW_CFA_restore_state:
3406 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3409 case DW_CFA_GNU_args_size:
3410 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3411 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3413 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3414 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3415 fputc ('\n', asm_out_file);
3418 case DW_CFA_GNU_window_save:
3419 fprintf (asm_out_file, "\t.cfi_window_save\n");
3422 case DW_CFA_def_cfa_expression:
3423 case DW_CFA_expression:
3424 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3425 output_cfa_loc_raw (cfi);
3426 fputc ('\n', asm_out_file);
3434 DEF_VEC_P (dw_cfi_ref);
3435 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3437 /* Output CFIs to bring current FDE to the same state as after executing
3438 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3439 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3440 other arguments to pass to output_cfi. */
3443 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3445 struct dw_cfi_struct cfi_buf;
3447 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3448 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3449 unsigned int len, idx;
3451 for (;; cfi = cfi->dw_cfi_next)
3452 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3454 case DW_CFA_advance_loc:
3455 case DW_CFA_advance_loc1:
3456 case DW_CFA_advance_loc2:
3457 case DW_CFA_advance_loc4:
3458 case DW_CFA_MIPS_advance_loc8:
3459 case DW_CFA_set_loc:
3460 /* All advances should be ignored. */
3462 case DW_CFA_remember_state:
3464 dw_cfi_ref args_size = cfi_args_size;
3466 /* Skip everything between .cfi_remember_state and
3467 .cfi_restore_state. */
3468 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3469 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3471 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3474 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3481 cfi_args_size = args_size;
3485 case DW_CFA_GNU_args_size:
3486 cfi_args_size = cfi;
3488 case DW_CFA_GNU_window_save:
3491 case DW_CFA_offset_extended:
3492 case DW_CFA_offset_extended_sf:
3493 case DW_CFA_restore:
3494 case DW_CFA_restore_extended:
3495 case DW_CFA_undefined:
3496 case DW_CFA_same_value:
3497 case DW_CFA_register:
3498 case DW_CFA_val_offset:
3499 case DW_CFA_val_offset_sf:
3500 case DW_CFA_expression:
3501 case DW_CFA_val_expression:
3502 case DW_CFA_GNU_negative_offset_extended:
3503 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3504 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3505 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3506 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3508 case DW_CFA_def_cfa:
3509 case DW_CFA_def_cfa_sf:
3510 case DW_CFA_def_cfa_expression:
3512 cfi_cfa_offset = cfi;
3514 case DW_CFA_def_cfa_register:
3517 case DW_CFA_def_cfa_offset:
3518 case DW_CFA_def_cfa_offset_sf:
3519 cfi_cfa_offset = cfi;
3522 gcc_assert (cfi == NULL);
3524 len = VEC_length (dw_cfi_ref, regs);
3525 for (idx = 0; idx < len; idx++)
3527 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3529 && cfi2->dw_cfi_opc != DW_CFA_restore
3530 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3533 output_cfi_directive (cfi2);
3535 output_cfi (cfi2, fde, for_eh);
3538 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3540 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3542 switch (cfi_cfa_offset->dw_cfi_opc)
3544 case DW_CFA_def_cfa_offset:
3545 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3546 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3548 case DW_CFA_def_cfa_offset_sf:
3549 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3550 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3552 case DW_CFA_def_cfa:
3553 case DW_CFA_def_cfa_sf:
3554 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3555 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3562 else if (cfi_cfa_offset)
3563 cfi_cfa = cfi_cfa_offset;
3567 output_cfi_directive (cfi_cfa);
3569 output_cfi (cfi_cfa, fde, for_eh);
3572 cfi_cfa_offset = NULL;
3574 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3577 output_cfi_directive (cfi_args_size);
3579 output_cfi (cfi_args_size, fde, for_eh);
3581 cfi_args_size = NULL;
3584 VEC_free (dw_cfi_ref, heap, regs);
3587 else if (do_cfi_asm)
3588 output_cfi_directive (cfi);
3590 output_cfi (cfi, fde, for_eh);
3597 /* Output one FDE. */
3600 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3601 char *section_start_label, int fde_encoding, char *augmentation,
3602 bool any_lsda_needed, int lsda_encoding)
3604 const char *begin, *end;
3605 static unsigned int j;
3606 char l1[20], l2[20];
3609 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3611 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3613 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3614 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3615 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3616 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3617 " indicating 64-bit DWARF extension");
3618 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3620 ASM_OUTPUT_LABEL (asm_out_file, l1);
3623 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3625 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3626 debug_frame_section, "FDE CIE offset");
3628 if (!fde->dw_fde_switched_sections)
3630 begin = fde->dw_fde_begin;
3631 end = fde->dw_fde_end;
3635 /* For the first section, prefer dw_fde_begin over
3636 dw_fde_{hot,cold}_section_label, as the latter
3637 might be separated from the real start of the
3638 function by alignment padding. */
3640 begin = fde->dw_fde_begin;
3641 else if (fde->dw_fde_switched_cold_to_hot)
3642 begin = fde->dw_fde_hot_section_label;
3644 begin = fde->dw_fde_unlikely_section_label;
3645 if (second ^ fde->dw_fde_switched_cold_to_hot)
3646 end = fde->dw_fde_unlikely_section_end_label;
3648 end = fde->dw_fde_hot_section_end_label;
3653 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3654 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3655 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3656 "FDE initial location");
3657 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3658 end, begin, "FDE address range");
3662 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3663 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3666 if (augmentation[0])
3668 if (any_lsda_needed)
3670 int size = size_of_encoded_value (lsda_encoding);
3672 if (lsda_encoding == DW_EH_PE_aligned)
3674 int offset = ( 4 /* Length */
3675 + 4 /* CIE offset */
3676 + 2 * size_of_encoded_value (fde_encoding)
3677 + 1 /* Augmentation size */ );
3678 int pad = -offset & (PTR_SIZE - 1);
3681 gcc_assert (size_of_uleb128 (size) == 1);
3684 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3686 if (fde->uses_eh_lsda)
3688 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3689 fde->funcdef_number);
3690 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3691 gen_rtx_SYMBOL_REF (Pmode, l1),
3693 "Language Specific Data Area");
3697 if (lsda_encoding == DW_EH_PE_aligned)
3698 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3699 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3700 "Language Specific Data Area (none)");
3704 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3707 /* Loop through the Call Frame Instructions associated with
3709 fde->dw_fde_current_label = begin;
3710 if (!fde->dw_fde_switched_sections)
3711 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3712 output_cfi (cfi, fde, for_eh);
3715 if (fde->dw_fde_switch_cfi)
3716 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3718 output_cfi (cfi, fde, for_eh);
3719 if (cfi == fde->dw_fde_switch_cfi)
3725 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3727 if (fde->dw_fde_switch_cfi)
3729 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3730 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3731 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3732 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3734 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3735 output_cfi (cfi, fde, for_eh);
3738 /* If we are to emit a ref/link from function bodies to their frame tables,
3739 do it now. This is typically performed to make sure that tables
3740 associated with functions are dragged with them and not discarded in
3741 garbage collecting links. We need to do this on a per function basis to
3742 cope with -ffunction-sections. */
3744 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3745 /* Switch to the function section, emit the ref to the tables, and
3746 switch *back* into the table section. */
3747 switch_to_section (function_section (fde->decl));
3748 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3749 switch_to_frame_table_section (for_eh, true);
3752 /* Pad the FDE out to an address sized boundary. */
3753 ASM_OUTPUT_ALIGN (asm_out_file,
3754 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3755 ASM_OUTPUT_LABEL (asm_out_file, l2);
3760 /* Return true if frame description entry FDE is needed for EH. */
3763 fde_needed_for_eh_p (dw_fde_ref fde)
3765 if (flag_asynchronous_unwind_tables)
3768 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3771 if (fde->uses_eh_lsda)
3774 /* If exceptions are enabled, we have collected nothrow info. */
3775 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3781 /* Output the call frame information used to record information
3782 that relates to calculating the frame pointer, and records the
3783 location of saved registers. */
3786 output_call_frame_info (int for_eh)
3791 char l1[20], l2[20], section_start_label[20];
3792 bool any_lsda_needed = false;
3793 char augmentation[6];
3794 int augmentation_size;
3795 int fde_encoding = DW_EH_PE_absptr;
3796 int per_encoding = DW_EH_PE_absptr;
3797 int lsda_encoding = DW_EH_PE_absptr;
3799 rtx personality = NULL;
3802 /* Don't emit a CIE if there won't be any FDEs. */
3803 if (fde_table_in_use == 0)
3806 /* Nothing to do if the assembler's doing it all. */
3807 if (dwarf2out_do_cfi_asm ())
3810 /* If we don't have any functions we'll want to unwind out of, don't emit
3811 any EH unwind information. If we make FDEs linkonce, we may have to
3812 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3813 want to avoid having an FDE kept around when the function it refers to
3814 is discarded. Example where this matters: a primary function template
3815 in C++ requires EH information, an explicit specialization doesn't. */
3818 bool any_eh_needed = false;
3820 for (i = 0; i < fde_table_in_use; i++)
3821 if (fde_table[i].uses_eh_lsda)
3822 any_eh_needed = any_lsda_needed = true;
3823 else if (fde_needed_for_eh_p (&fde_table[i]))
3824 any_eh_needed = true;
3825 else if (TARGET_USES_WEAK_UNWIND_INFO)
3826 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3833 /* We're going to be generating comments, so turn on app. */
3837 /* Switch to the proper frame section, first time. */
3838 switch_to_frame_table_section (for_eh, false);
3840 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3841 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3843 /* Output the CIE. */
3844 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3845 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3846 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3847 dw2_asm_output_data (4, 0xffffffff,
3848 "Initial length escape value indicating 64-bit DWARF extension");
3849 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3850 "Length of Common Information Entry");
3851 ASM_OUTPUT_LABEL (asm_out_file, l1);
3853 /* Now that the CIE pointer is PC-relative for EH,
3854 use 0 to identify the CIE. */
3855 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3856 (for_eh ? 0 : DWARF_CIE_ID),
3857 "CIE Identifier Tag");
3859 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3860 use CIE version 1, unless that would produce incorrect results
3861 due to overflowing the return register column. */
3862 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3864 if (return_reg >= 256 || dwarf_version > 2)
3866 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3868 augmentation[0] = 0;
3869 augmentation_size = 0;
3871 personality = current_unit_personality;
3877 z Indicates that a uleb128 is present to size the
3878 augmentation section.
3879 L Indicates the encoding (and thus presence) of
3880 an LSDA pointer in the FDE augmentation.
3881 R Indicates a non-default pointer encoding for
3883 P Indicates the presence of an encoding + language
3884 personality routine in the CIE augmentation. */
3886 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3887 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3888 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3890 p = augmentation + 1;
3894 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3895 assemble_external_libcall (personality);
3897 if (any_lsda_needed)
3900 augmentation_size += 1;
3902 if (fde_encoding != DW_EH_PE_absptr)
3905 augmentation_size += 1;
3907 if (p > augmentation + 1)
3909 augmentation[0] = 'z';
3913 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3914 if (personality && per_encoding == DW_EH_PE_aligned)
3916 int offset = ( 4 /* Length */
3918 + 1 /* CIE version */
3919 + strlen (augmentation) + 1 /* Augmentation */
3920 + size_of_uleb128 (1) /* Code alignment */
3921 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3923 + 1 /* Augmentation size */
3924 + 1 /* Personality encoding */ );
3925 int pad = -offset & (PTR_SIZE - 1);
3927 augmentation_size += pad;
3929 /* Augmentations should be small, so there's scarce need to
3930 iterate for a solution. Die if we exceed one uleb128 byte. */
3931 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3935 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3936 if (dw_cie_version >= 4)
3938 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3939 dw2_asm_output_data (1, 0, "CIE Segment Size");
3941 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3942 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3943 "CIE Data Alignment Factor");
3945 if (dw_cie_version == 1)
3946 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3948 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3950 if (augmentation[0])
3952 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3955 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3956 eh_data_format_name (per_encoding));
3957 dw2_asm_output_encoded_addr_rtx (per_encoding,
3962 if (any_lsda_needed)
3963 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3964 eh_data_format_name (lsda_encoding));
3966 if (fde_encoding != DW_EH_PE_absptr)
3967 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3968 eh_data_format_name (fde_encoding));
3971 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3972 output_cfi (cfi, NULL, for_eh);
3974 /* Pad the CIE out to an address sized boundary. */
3975 ASM_OUTPUT_ALIGN (asm_out_file,
3976 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3977 ASM_OUTPUT_LABEL (asm_out_file, l2);
3979 /* Loop through all of the FDE's. */
3980 for (i = 0; i < fde_table_in_use; i++)
3983 fde = &fde_table[i];
3985 /* Don't emit EH unwind info for leaf functions that don't need it. */
3986 if (for_eh && !fde_needed_for_eh_p (fde))
3989 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3990 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3991 augmentation, any_lsda_needed, lsda_encoding);
3994 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3995 dw2_asm_output_data (4, 0, "End of Table");
3996 #ifdef MIPS_DEBUGGING_INFO
3997 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3998 get a value of 0. Putting .align 0 after the label fixes it. */
3999 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4002 /* Turn off app to make assembly quicker. */
4007 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
4010 dwarf2out_do_cfi_startproc (bool second)
4014 rtx personality = get_personality_function (current_function_decl);
4016 fprintf (asm_out_file, "\t.cfi_startproc\n");
4020 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4023 /* ??? The GAS support isn't entirely consistent. We have to
4024 handle indirect support ourselves, but PC-relative is done
4025 in the assembler. Further, the assembler can't handle any
4026 of the weirder relocation types. */
4027 if (enc & DW_EH_PE_indirect)
4028 ref = dw2_force_const_mem (ref, true);
4030 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4031 output_addr_const (asm_out_file, ref);
4032 fputc ('\n', asm_out_file);
4035 if (crtl->uses_eh_lsda)
4039 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4040 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4041 current_function_funcdef_no);
4042 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4043 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4045 if (enc & DW_EH_PE_indirect)
4046 ref = dw2_force_const_mem (ref, true);
4048 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4049 output_addr_const (asm_out_file, ref);
4050 fputc ('\n', asm_out_file);
4054 /* Output a marker (i.e. a label) for the beginning of a function, before
4058 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4059 const char *file ATTRIBUTE_UNUSED)
4061 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4067 current_function_func_begin_label = NULL;
4069 do_frame = dwarf2out_do_frame ();
4071 /* ??? current_function_func_begin_label is also used by except.c for
4072 call-site information. We must emit this label if it might be used. */
4074 && (!flag_exceptions
4075 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4078 fnsec = function_section (current_function_decl);
4079 switch_to_section (fnsec);
4080 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4081 current_function_funcdef_no);
4082 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4083 current_function_funcdef_no);
4084 dup_label = xstrdup (label);
4085 current_function_func_begin_label = dup_label;
4087 /* We can elide the fde allocation if we're not emitting debug info. */
4091 /* Expand the fde table if necessary. */
4092 if (fde_table_in_use == fde_table_allocated)
4094 fde_table_allocated += FDE_TABLE_INCREMENT;
4095 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4096 memset (fde_table + fde_table_in_use, 0,
4097 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4100 /* Record the FDE associated with this function. */
4101 current_funcdef_fde = fde_table_in_use;
4103 /* Add the new FDE at the end of the fde_table. */
4104 fde = &fde_table[fde_table_in_use++];
4105 fde->decl = current_function_decl;
4106 fde->dw_fde_begin = dup_label;
4107 fde->dw_fde_current_label = dup_label;
4108 fde->dw_fde_hot_section_label = NULL;
4109 fde->dw_fde_hot_section_end_label = NULL;
4110 fde->dw_fde_unlikely_section_label = NULL;
4111 fde->dw_fde_unlikely_section_end_label = NULL;
4112 fde->dw_fde_switched_sections = 0;
4113 fde->dw_fde_switched_cold_to_hot = 0;
4114 fde->dw_fde_end = NULL;
4115 fde->dw_fde_vms_end_prologue = NULL;
4116 fde->dw_fde_vms_begin_epilogue = NULL;
4117 fde->dw_fde_cfi = NULL;
4118 fde->dw_fde_switch_cfi = NULL;
4119 fde->funcdef_number = current_function_funcdef_no;
4120 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4121 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4122 fde->nothrow = crtl->nothrow;
4123 fde->drap_reg = INVALID_REGNUM;
4124 fde->vdrap_reg = INVALID_REGNUM;
4125 if (flag_reorder_blocks_and_partition)
4127 section *unlikelysec;
4128 if (first_function_block_is_cold)
4129 fde->in_std_section = 1;
4132 = (fnsec == text_section
4133 || (cold_text_section && fnsec == cold_text_section));
4134 unlikelysec = unlikely_text_section ();
4135 fde->cold_in_std_section
4136 = (unlikelysec == text_section
4137 || (cold_text_section && unlikelysec == cold_text_section));
4142 = (fnsec == text_section
4143 || (cold_text_section && fnsec == cold_text_section));
4144 fde->cold_in_std_section = 0;
4147 args_size = old_args_size = 0;
4149 /* We only want to output line number information for the genuine dwarf2
4150 prologue case, not the eh frame case. */
4151 #ifdef DWARF2_DEBUGGING_INFO
4153 dwarf2out_source_line (line, file, 0, true);
4156 if (dwarf2out_do_cfi_asm ())
4157 dwarf2out_do_cfi_startproc (false);
4160 rtx personality = get_personality_function (current_function_decl);
4161 if (!current_unit_personality)
4162 current_unit_personality = personality;
4164 /* We cannot keep a current personality per function as without CFI
4165 asm, at the point where we emit the CFI data, there is no current
4166 function anymore. */
4167 if (personality && current_unit_personality != personality)
4168 sorry ("multiple EH personalities are supported only with assemblers "
4169 "supporting .cfi_personality directive");
4173 /* Output a marker (i.e. a label) for the end of the generated code
4174 for a function prologue. This gets called *after* the prologue code has
4178 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4179 const char *file ATTRIBUTE_UNUSED)
4182 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4184 /* Output a label to mark the endpoint of the code generated for this
4186 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4187 current_function_funcdef_no);
4188 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4189 current_function_funcdef_no);
4190 fde = &fde_table[fde_table_in_use - 1];
4191 fde->dw_fde_vms_end_prologue = xstrdup (label);
4194 /* Output a marker (i.e. a label) for the beginning of the generated code
4195 for a function epilogue. This gets called *before* the prologue code has
4199 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4200 const char *file ATTRIBUTE_UNUSED)
4203 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4205 fde = &fde_table[fde_table_in_use - 1];
4206 if (fde->dw_fde_vms_begin_epilogue)
4209 /* Output a label to mark the endpoint of the code generated for this
4211 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4212 current_function_funcdef_no);
4213 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4214 current_function_funcdef_no);
4215 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4218 /* Output a marker (i.e. a label) for the absolute end of the generated code
4219 for a function definition. This gets called *after* the epilogue code has
4223 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4224 const char *file ATTRIBUTE_UNUSED)
4227 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4229 last_var_location_insn = NULL_RTX;
4231 if (dwarf2out_do_cfi_asm ())
4232 fprintf (asm_out_file, "\t.cfi_endproc\n");
4234 /* Output a label to mark the endpoint of the code generated for this
4236 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4237 current_function_funcdef_no);
4238 ASM_OUTPUT_LABEL (asm_out_file, label);
4239 fde = current_fde ();
4240 gcc_assert (fde != NULL);
4241 fde->dw_fde_end = xstrdup (label);
4245 dwarf2out_frame_init (void)
4247 /* Allocate the initial hunk of the fde_table. */
4248 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4249 fde_table_allocated = FDE_TABLE_INCREMENT;
4250 fde_table_in_use = 0;
4252 /* Generate the CFA instructions common to all FDE's. Do it now for the
4253 sake of lookup_cfa. */
4255 /* On entry, the Canonical Frame Address is at SP. */
4256 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4258 if (targetm.debug_unwind_info () == UI_DWARF2
4259 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4260 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4264 dwarf2out_frame_finish (void)
4266 /* Output call frame information. */
4267 if (targetm.debug_unwind_info () == UI_DWARF2)
4268 output_call_frame_info (0);
4270 /* Output another copy for the unwinder. */
4271 if ((flag_unwind_tables || flag_exceptions)
4272 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4273 output_call_frame_info (1);
4276 /* Note that the current function section is being used for code. */
4279 dwarf2out_note_section_used (void)
4281 section *sec = current_function_section ();
4282 if (sec == text_section)
4283 text_section_used = true;
4284 else if (sec == cold_text_section)
4285 cold_text_section_used = true;
4289 dwarf2out_switch_text_section (void)
4291 dw_fde_ref fde = current_fde ();
4293 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4295 fde->dw_fde_switched_sections = 1;
4296 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4298 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4299 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4300 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4301 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4302 have_multiple_function_sections = true;
4304 /* Reset the current label on switching text sections, so that we
4305 don't attempt to advance_loc4 between labels in different sections. */
4306 fde->dw_fde_current_label = NULL;
4308 /* There is no need to mark used sections when not debugging. */
4309 if (cold_text_section != NULL)
4310 dwarf2out_note_section_used ();
4312 if (dwarf2out_do_cfi_asm ())
4313 fprintf (asm_out_file, "\t.cfi_endproc\n");
4315 /* Now do the real section switch. */
4316 switch_to_section (current_function_section ());
4318 if (dwarf2out_do_cfi_asm ())
4320 dwarf2out_do_cfi_startproc (true);
4321 /* As this is a different FDE, insert all current CFI instructions
4323 output_cfis (fde->dw_fde_cfi, true, fde, true);
4327 dw_cfi_ref cfi = fde->dw_fde_cfi;
4329 cfi = fde->dw_fde_cfi;
4331 while (cfi->dw_cfi_next != NULL)
4332 cfi = cfi->dw_cfi_next;
4333 fde->dw_fde_switch_cfi = cfi;
4337 /* And now, the subset of the debugging information support code necessary
4338 for emitting location expressions. */
4340 /* Data about a single source file. */
4341 struct GTY(()) dwarf_file_data {
4342 const char * filename;
4346 typedef struct dw_val_struct *dw_val_ref;
4347 typedef struct die_struct *dw_die_ref;
4348 typedef const struct die_struct *const_dw_die_ref;
4349 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4350 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4352 typedef struct GTY(()) deferred_locations_struct
4356 } deferred_locations;
4358 DEF_VEC_O(deferred_locations);
4359 DEF_VEC_ALLOC_O(deferred_locations,gc);
4361 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4363 DEF_VEC_P(dw_die_ref);
4364 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4366 /* Each DIE may have a series of attribute/value pairs. Values
4367 can take on several forms. The forms that are used in this
4368 implementation are listed below. */
4373 dw_val_class_offset,
4375 dw_val_class_loc_list,
4376 dw_val_class_range_list,
4378 dw_val_class_unsigned_const,
4379 dw_val_class_const_double,
4382 dw_val_class_die_ref,
4383 dw_val_class_fde_ref,
4384 dw_val_class_lbl_id,
4385 dw_val_class_lineptr,
4387 dw_val_class_macptr,
4390 dw_val_class_decl_ref,
4391 dw_val_class_vms_delta
4394 /* Describe a floating point constant value, or a vector constant value. */
4396 typedef struct GTY(()) dw_vec_struct {
4397 unsigned char * GTY((length ("%h.length"))) array;
4403 /* The dw_val_node describes an attribute's value, as it is
4404 represented internally. */
4406 typedef struct GTY(()) dw_val_struct {
4407 enum dw_val_class val_class;
4408 union dw_val_struct_union
4410 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4411 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4412 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4413 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4414 HOST_WIDE_INT GTY ((default)) val_int;
4415 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4416 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4417 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4418 struct dw_val_die_union
4422 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4423 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4424 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4425 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4426 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4427 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4428 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4429 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4430 struct dw_val_vms_delta_union
4434 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4436 GTY ((desc ("%1.val_class"))) v;
4440 /* Locations in memory are described using a sequence of stack machine
4443 typedef struct GTY(()) dw_loc_descr_struct {
4444 dw_loc_descr_ref dw_loc_next;
4445 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4446 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4447 from DW_OP_addr with a dtp-relative symbol relocation. */
4448 unsigned int dtprel : 1;
4450 dw_val_node dw_loc_oprnd1;
4451 dw_val_node dw_loc_oprnd2;
4455 /* Location lists are ranges + location descriptions for that range,
4456 so you can track variables that are in different places over
4457 their entire life. */
4458 typedef struct GTY(()) dw_loc_list_struct {
4459 dw_loc_list_ref dw_loc_next;
4460 const char *begin; /* Label for begin address of range */
4461 const char *end; /* Label for end address of range */
4462 char *ll_symbol; /* Label for beginning of location list.
4463 Only on head of list */
4464 const char *section; /* Section this loclist is relative to */
4465 dw_loc_descr_ref expr;
4470 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4472 /* Convert a DWARF stack opcode into its string name. */
4475 dwarf_stack_op_name (unsigned int op)
4480 return "DW_OP_addr";
4482 return "DW_OP_deref";
4484 return "DW_OP_const1u";
4486 return "DW_OP_const1s";
4488 return "DW_OP_const2u";
4490 return "DW_OP_const2s";
4492 return "DW_OP_const4u";
4494 return "DW_OP_const4s";
4496 return "DW_OP_const8u";
4498 return "DW_OP_const8s";
4500 return "DW_OP_constu";
4502 return "DW_OP_consts";
4506 return "DW_OP_drop";
4508 return "DW_OP_over";
4510 return "DW_OP_pick";
4512 return "DW_OP_swap";
4516 return "DW_OP_xderef";
4524 return "DW_OP_minus";
4536 return "DW_OP_plus";
4537 case DW_OP_plus_uconst:
4538 return "DW_OP_plus_uconst";
4544 return "DW_OP_shra";
4562 return "DW_OP_skip";
4564 return "DW_OP_lit0";
4566 return "DW_OP_lit1";
4568 return "DW_OP_lit2";
4570 return "DW_OP_lit3";
4572 return "DW_OP_lit4";
4574 return "DW_OP_lit5";
4576 return "DW_OP_lit6";
4578 return "DW_OP_lit7";
4580 return "DW_OP_lit8";
4582 return "DW_OP_lit9";
4584 return "DW_OP_lit10";
4586 return "DW_OP_lit11";
4588 return "DW_OP_lit12";
4590 return "DW_OP_lit13";
4592 return "DW_OP_lit14";
4594 return "DW_OP_lit15";
4596 return "DW_OP_lit16";
4598 return "DW_OP_lit17";
4600 return "DW_OP_lit18";
4602 return "DW_OP_lit19";
4604 return "DW_OP_lit20";
4606 return "DW_OP_lit21";
4608 return "DW_OP_lit22";
4610 return "DW_OP_lit23";
4612 return "DW_OP_lit24";
4614 return "DW_OP_lit25";
4616 return "DW_OP_lit26";
4618 return "DW_OP_lit27";
4620 return "DW_OP_lit28";
4622 return "DW_OP_lit29";
4624 return "DW_OP_lit30";
4626 return "DW_OP_lit31";
4628 return "DW_OP_reg0";
4630 return "DW_OP_reg1";
4632 return "DW_OP_reg2";
4634 return "DW_OP_reg3";
4636 return "DW_OP_reg4";
4638 return "DW_OP_reg5";
4640 return "DW_OP_reg6";
4642 return "DW_OP_reg7";
4644 return "DW_OP_reg8";
4646 return "DW_OP_reg9";
4648 return "DW_OP_reg10";
4650 return "DW_OP_reg11";
4652 return "DW_OP_reg12";
4654 return "DW_OP_reg13";
4656 return "DW_OP_reg14";
4658 return "DW_OP_reg15";
4660 return "DW_OP_reg16";
4662 return "DW_OP_reg17";
4664 return "DW_OP_reg18";
4666 return "DW_OP_reg19";
4668 return "DW_OP_reg20";
4670 return "DW_OP_reg21";
4672 return "DW_OP_reg22";
4674 return "DW_OP_reg23";
4676 return "DW_OP_reg24";
4678 return "DW_OP_reg25";
4680 return "DW_OP_reg26";
4682 return "DW_OP_reg27";
4684 return "DW_OP_reg28";
4686 return "DW_OP_reg29";
4688 return "DW_OP_reg30";
4690 return "DW_OP_reg31";
4692 return "DW_OP_breg0";
4694 return "DW_OP_breg1";
4696 return "DW_OP_breg2";
4698 return "DW_OP_breg3";
4700 return "DW_OP_breg4";
4702 return "DW_OP_breg5";
4704 return "DW_OP_breg6";
4706 return "DW_OP_breg7";
4708 return "DW_OP_breg8";
4710 return "DW_OP_breg9";
4712 return "DW_OP_breg10";
4714 return "DW_OP_breg11";
4716 return "DW_OP_breg12";
4718 return "DW_OP_breg13";
4720 return "DW_OP_breg14";
4722 return "DW_OP_breg15";
4724 return "DW_OP_breg16";
4726 return "DW_OP_breg17";
4728 return "DW_OP_breg18";
4730 return "DW_OP_breg19";
4732 return "DW_OP_breg20";
4734 return "DW_OP_breg21";
4736 return "DW_OP_breg22";
4738 return "DW_OP_breg23";
4740 return "DW_OP_breg24";
4742 return "DW_OP_breg25";
4744 return "DW_OP_breg26";
4746 return "DW_OP_breg27";
4748 return "DW_OP_breg28";
4750 return "DW_OP_breg29";
4752 return "DW_OP_breg30";
4754 return "DW_OP_breg31";
4756 return "DW_OP_regx";
4758 return "DW_OP_fbreg";
4760 return "DW_OP_bregx";
4762 return "DW_OP_piece";
4763 case DW_OP_deref_size:
4764 return "DW_OP_deref_size";
4765 case DW_OP_xderef_size:
4766 return "DW_OP_xderef_size";
4770 case DW_OP_push_object_address:
4771 return "DW_OP_push_object_address";
4773 return "DW_OP_call2";
4775 return "DW_OP_call4";
4776 case DW_OP_call_ref:
4777 return "DW_OP_call_ref";
4778 case DW_OP_implicit_value:
4779 return "DW_OP_implicit_value";
4780 case DW_OP_stack_value:
4781 return "DW_OP_stack_value";
4782 case DW_OP_form_tls_address:
4783 return "DW_OP_form_tls_address";
4784 case DW_OP_call_frame_cfa:
4785 return "DW_OP_call_frame_cfa";
4786 case DW_OP_bit_piece:
4787 return "DW_OP_bit_piece";
4789 case DW_OP_GNU_push_tls_address:
4790 return "DW_OP_GNU_push_tls_address";
4791 case DW_OP_GNU_uninit:
4792 return "DW_OP_GNU_uninit";
4793 case DW_OP_GNU_encoded_addr:
4794 return "DW_OP_GNU_encoded_addr";
4795 case DW_OP_GNU_implicit_pointer:
4796 return "DW_OP_GNU_implicit_pointer";
4799 return "OP_<unknown>";
4803 /* Return a pointer to a newly allocated location description. Location
4804 descriptions are simple expression terms that can be strung
4805 together to form more complicated location (address) descriptions. */
4807 static inline dw_loc_descr_ref
4808 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4809 unsigned HOST_WIDE_INT oprnd2)
4811 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4813 descr->dw_loc_opc = op;
4814 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4815 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4816 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4817 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4822 /* Return a pointer to a newly allocated location description for
4825 static inline dw_loc_descr_ref
4826 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4829 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4832 return new_loc_descr (DW_OP_bregx, reg, offset);
4835 /* Add a location description term to a location description expression. */
4838 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4840 dw_loc_descr_ref *d;
4842 /* Find the end of the chain. */
4843 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4849 /* Add a constant OFFSET to a location expression. */
4852 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4854 dw_loc_descr_ref loc;
4857 gcc_assert (*list_head != NULL);
4862 /* Find the end of the chain. */
4863 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4867 if (loc->dw_loc_opc == DW_OP_fbreg
4868 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4869 p = &loc->dw_loc_oprnd1.v.val_int;
4870 else if (loc->dw_loc_opc == DW_OP_bregx)
4871 p = &loc->dw_loc_oprnd2.v.val_int;
4873 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4874 offset. Don't optimize if an signed integer overflow would happen. */
4876 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4877 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4880 else if (offset > 0)
4881 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4885 loc->dw_loc_next = int_loc_descriptor (-offset);
4886 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4890 /* Add a constant OFFSET to a location list. */
4893 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4896 for (d = list_head; d != NULL; d = d->dw_loc_next)
4897 loc_descr_plus_const (&d->expr, offset);
4900 #define DWARF_REF_SIZE \
4901 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4903 /* Return the size of a location descriptor. */
4905 static unsigned long
4906 size_of_loc_descr (dw_loc_descr_ref loc)
4908 unsigned long size = 1;
4910 switch (loc->dw_loc_opc)
4913 size += DWARF2_ADDR_SIZE;
4932 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4935 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4940 case DW_OP_plus_uconst:
4941 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4979 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4982 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4985 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4988 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4989 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4992 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4994 case DW_OP_bit_piece:
4995 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4996 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4998 case DW_OP_deref_size:
4999 case DW_OP_xderef_size:
5008 case DW_OP_call_ref:
5009 size += DWARF_REF_SIZE;
5011 case DW_OP_implicit_value:
5012 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
5013 + loc->dw_loc_oprnd1.v.val_unsigned;
5015 case DW_OP_GNU_implicit_pointer:
5016 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
5025 /* Return the size of a series of location descriptors. */
5027 static unsigned long
5028 size_of_locs (dw_loc_descr_ref loc)
5033 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5034 field, to avoid writing to a PCH file. */
5035 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5037 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5039 size += size_of_loc_descr (l);
5044 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5046 l->dw_loc_addr = size;
5047 size += size_of_loc_descr (l);
5053 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5054 static void get_ref_die_offset_label (char *, dw_die_ref);
5056 /* Output location description stack opcode's operands (if any). */
5059 output_loc_operands (dw_loc_descr_ref loc)
5061 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5062 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5064 switch (loc->dw_loc_opc)
5066 #ifdef DWARF2_DEBUGGING_INFO
5069 dw2_asm_output_data (2, val1->v.val_int, NULL);
5074 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5075 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5077 fputc ('\n', asm_out_file);
5082 dw2_asm_output_data (4, val1->v.val_int, NULL);
5087 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5088 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5090 fputc ('\n', asm_out_file);
5095 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5096 dw2_asm_output_data (8, val1->v.val_int, NULL);
5103 gcc_assert (val1->val_class == dw_val_class_loc);
5104 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5106 dw2_asm_output_data (2, offset, NULL);
5109 case DW_OP_implicit_value:
5110 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5111 switch (val2->val_class)
5113 case dw_val_class_const:
5114 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5116 case dw_val_class_vec:
5118 unsigned int elt_size = val2->v.val_vec.elt_size;
5119 unsigned int len = val2->v.val_vec.length;
5123 if (elt_size > sizeof (HOST_WIDE_INT))
5128 for (i = 0, p = val2->v.val_vec.array;
5131 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5132 "fp or vector constant word %u", i);
5135 case dw_val_class_const_double:
5137 unsigned HOST_WIDE_INT first, second;
5139 if (WORDS_BIG_ENDIAN)
5141 first = val2->v.val_double.high;
5142 second = val2->v.val_double.low;
5146 first = val2->v.val_double.low;
5147 second = val2->v.val_double.high;
5149 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5151 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5155 case dw_val_class_addr:
5156 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5157 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5172 case DW_OP_implicit_value:
5173 /* We currently don't make any attempt to make sure these are
5174 aligned properly like we do for the main unwind info, so
5175 don't support emitting things larger than a byte if we're
5176 only doing unwinding. */
5181 dw2_asm_output_data (1, val1->v.val_int, NULL);
5184 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5187 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5190 dw2_asm_output_data (1, val1->v.val_int, NULL);
5192 case DW_OP_plus_uconst:
5193 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5227 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5230 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5233 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5236 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5237 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5240 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5242 case DW_OP_bit_piece:
5243 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5244 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5246 case DW_OP_deref_size:
5247 case DW_OP_xderef_size:
5248 dw2_asm_output_data (1, val1->v.val_int, NULL);
5254 if (targetm.asm_out.output_dwarf_dtprel)
5256 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5259 fputc ('\n', asm_out_file);
5266 #ifdef DWARF2_DEBUGGING_INFO
5267 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5274 case DW_OP_GNU_implicit_pointer:
5276 char label[MAX_ARTIFICIAL_LABEL_BYTES
5277 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5278 gcc_assert (val1->val_class == dw_val_class_die_ref);
5279 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5280 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5281 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5286 /* Other codes have no operands. */
5291 /* Output a sequence of location operations. */
5294 output_loc_sequence (dw_loc_descr_ref loc)
5296 for (; loc != NULL; loc = loc->dw_loc_next)
5298 /* Output the opcode. */
5299 dw2_asm_output_data (1, loc->dw_loc_opc,
5300 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5302 /* Output the operand(s) (if any). */
5303 output_loc_operands (loc);
5307 /* Output location description stack opcode's operands (if any).
5308 The output is single bytes on a line, suitable for .cfi_escape. */
5311 output_loc_operands_raw (dw_loc_descr_ref loc)
5313 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5314 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5316 switch (loc->dw_loc_opc)
5319 case DW_OP_implicit_value:
5320 /* We cannot output addresses in .cfi_escape, only bytes. */
5326 case DW_OP_deref_size:
5327 case DW_OP_xderef_size:
5328 fputc (',', asm_out_file);
5329 dw2_asm_output_data_raw (1, val1->v.val_int);
5334 fputc (',', asm_out_file);
5335 dw2_asm_output_data_raw (2, val1->v.val_int);
5340 fputc (',', asm_out_file);
5341 dw2_asm_output_data_raw (4, val1->v.val_int);
5346 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5347 fputc (',', asm_out_file);
5348 dw2_asm_output_data_raw (8, val1->v.val_int);
5356 gcc_assert (val1->val_class == dw_val_class_loc);
5357 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5359 fputc (',', asm_out_file);
5360 dw2_asm_output_data_raw (2, offset);
5365 case DW_OP_plus_uconst:
5368 fputc (',', asm_out_file);
5369 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5372 case DW_OP_bit_piece:
5373 fputc (',', asm_out_file);
5374 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5375 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5412 fputc (',', asm_out_file);
5413 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5417 fputc (',', asm_out_file);
5418 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5419 fputc (',', asm_out_file);
5420 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5423 case DW_OP_GNU_implicit_pointer:
5428 /* Other codes have no operands. */
5434 output_loc_sequence_raw (dw_loc_descr_ref loc)
5438 /* Output the opcode. */
5439 fprintf (asm_out_file, "%#x", loc->dw_loc_opc);
5440 output_loc_operands_raw (loc);
5442 if (!loc->dw_loc_next)
5444 loc = loc->dw_loc_next;
5446 fputc (',', asm_out_file);
5450 /* This routine will generate the correct assembly data for a location
5451 description based on a cfi entry with a complex address. */
5454 output_cfa_loc (dw_cfi_ref cfi)
5456 dw_loc_descr_ref loc;
5459 if (cfi->dw_cfi_opc == DW_CFA_expression)
5461 dw2_asm_output_data (1, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
5462 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5465 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5467 /* Output the size of the block. */
5468 size = size_of_locs (loc);
5469 dw2_asm_output_data_uleb128 (size, NULL);
5471 /* Now output the operations themselves. */
5472 output_loc_sequence (loc);
5475 /* Similar, but used for .cfi_escape. */
5478 output_cfa_loc_raw (dw_cfi_ref cfi)
5480 dw_loc_descr_ref loc;
5483 if (cfi->dw_cfi_opc == DW_CFA_expression)
5485 fprintf (asm_out_file, "%#x,", cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
5486 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5489 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5491 /* Output the size of the block. */
5492 size = size_of_locs (loc);
5493 dw2_asm_output_data_uleb128_raw (size);
5494 fputc (',', asm_out_file);
5496 /* Now output the operations themselves. */
5497 output_loc_sequence_raw (loc);
5500 /* This function builds a dwarf location descriptor sequence from a
5501 dw_cfa_location, adding the given OFFSET to the result of the
5504 static struct dw_loc_descr_struct *
5505 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5507 struct dw_loc_descr_struct *head, *tmp;
5509 offset += cfa->offset;
5513 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5514 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5515 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5516 add_loc_descr (&head, tmp);
5519 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5520 add_loc_descr (&head, tmp);
5524 head = new_reg_loc_descr (cfa->reg, offset);
5529 /* This function builds a dwarf location descriptor sequence for
5530 the address at OFFSET from the CFA when stack is aligned to
5533 static struct dw_loc_descr_struct *
5534 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5536 struct dw_loc_descr_struct *head;
5537 unsigned int dwarf_fp
5538 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5540 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5541 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5543 head = new_reg_loc_descr (dwarf_fp, 0);
5544 add_loc_descr (&head, int_loc_descriptor (alignment));
5545 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5546 loc_descr_plus_const (&head, offset);
5549 head = new_reg_loc_descr (dwarf_fp, offset);
5553 /* This function fills in aa dw_cfa_location structure from a dwarf location
5554 descriptor sequence. */
5557 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5559 struct dw_loc_descr_struct *ptr;
5561 cfa->base_offset = 0;
5565 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5567 enum dwarf_location_atom op = ptr->dw_loc_opc;
5603 cfa->reg = op - DW_OP_reg0;
5606 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5640 cfa->reg = op - DW_OP_breg0;
5641 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5644 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5645 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5650 case DW_OP_plus_uconst:
5651 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5654 internal_error ("DW_LOC_OP %s not implemented",
5655 dwarf_stack_op_name (ptr->dw_loc_opc));
5660 /* And now, the support for symbolic debugging information. */
5662 /* .debug_str support. */
5663 static int output_indirect_string (void **, void *);
5665 static void dwarf2out_init (const char *);
5666 static void dwarf2out_finish (const char *);
5667 static void dwarf2out_assembly_start (void);
5668 static void dwarf2out_define (unsigned int, const char *);
5669 static void dwarf2out_undef (unsigned int, const char *);
5670 static void dwarf2out_start_source_file (unsigned, const char *);
5671 static void dwarf2out_end_source_file (unsigned);
5672 static void dwarf2out_function_decl (tree);
5673 static void dwarf2out_begin_block (unsigned, unsigned);
5674 static void dwarf2out_end_block (unsigned, unsigned);
5675 static bool dwarf2out_ignore_block (const_tree);
5676 static void dwarf2out_global_decl (tree);
5677 static void dwarf2out_type_decl (tree, int);
5678 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5679 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5681 static void dwarf2out_abstract_function (tree);
5682 static void dwarf2out_var_location (rtx);
5683 static void dwarf2out_direct_call (tree);
5684 static void dwarf2out_virtual_call_token (tree, int);
5685 static void dwarf2out_copy_call_info (rtx, rtx);
5686 static void dwarf2out_virtual_call (int);
5687 static void dwarf2out_begin_function (tree);
5688 static void dwarf2out_set_name (tree, tree);
5690 /* The debug hooks structure. */
5692 const struct gcc_debug_hooks dwarf2_debug_hooks =
5696 dwarf2out_assembly_start,
5699 dwarf2out_start_source_file,
5700 dwarf2out_end_source_file,
5701 dwarf2out_begin_block,
5702 dwarf2out_end_block,
5703 dwarf2out_ignore_block,
5704 dwarf2out_source_line,
5705 dwarf2out_begin_prologue,
5706 #if VMS_DEBUGGING_INFO
5707 dwarf2out_vms_end_prologue,
5708 dwarf2out_vms_begin_epilogue,
5710 debug_nothing_int_charstar,
5711 debug_nothing_int_charstar,
5713 dwarf2out_end_epilogue,
5714 dwarf2out_begin_function,
5715 debug_nothing_int, /* end_function */
5716 dwarf2out_function_decl, /* function_decl */
5717 dwarf2out_global_decl,
5718 dwarf2out_type_decl, /* type_decl */
5719 dwarf2out_imported_module_or_decl,
5720 debug_nothing_tree, /* deferred_inline_function */
5721 /* The DWARF 2 backend tries to reduce debugging bloat by not
5722 emitting the abstract description of inline functions until
5723 something tries to reference them. */
5724 dwarf2out_abstract_function, /* outlining_inline_function */
5725 debug_nothing_rtx, /* label */
5726 debug_nothing_int, /* handle_pch */
5727 dwarf2out_var_location,
5728 dwarf2out_switch_text_section,
5729 dwarf2out_direct_call,
5730 dwarf2out_virtual_call_token,
5731 dwarf2out_copy_call_info,
5732 dwarf2out_virtual_call,
5734 1, /* start_end_main_source_file */
5735 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5738 /* NOTE: In the comments in this file, many references are made to
5739 "Debugging Information Entries". This term is abbreviated as `DIE'
5740 throughout the remainder of this file. */
5742 /* An internal representation of the DWARF output is built, and then
5743 walked to generate the DWARF debugging info. The walk of the internal
5744 representation is done after the entire program has been compiled.
5745 The types below are used to describe the internal representation. */
5747 /* Various DIE's use offsets relative to the beginning of the
5748 .debug_info section to refer to each other. */
5750 typedef long int dw_offset;
5752 /* Define typedefs here to avoid circular dependencies. */
5754 typedef struct dw_attr_struct *dw_attr_ref;
5755 typedef struct dw_line_info_struct *dw_line_info_ref;
5756 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5757 typedef struct pubname_struct *pubname_ref;
5758 typedef struct dw_ranges_struct *dw_ranges_ref;
5759 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5760 typedef struct comdat_type_struct *comdat_type_node_ref;
5762 /* Each entry in the line_info_table maintains the file and
5763 line number associated with the label generated for that
5764 entry. The label gives the PC value associated with
5765 the line number entry. */
5767 typedef struct GTY(()) dw_line_info_struct {
5768 unsigned long dw_file_num;
5769 unsigned long dw_line_num;
5773 /* Line information for functions in separate sections; each one gets its
5775 typedef struct GTY(()) dw_separate_line_info_struct {
5776 unsigned long dw_file_num;
5777 unsigned long dw_line_num;
5778 unsigned long function;
5780 dw_separate_line_info_entry;
5782 /* Each DIE attribute has a field specifying the attribute kind,
5783 a link to the next attribute in the chain, and an attribute value.
5784 Attributes are typically linked below the DIE they modify. */
5786 typedef struct GTY(()) dw_attr_struct {
5787 enum dwarf_attribute dw_attr;
5788 dw_val_node dw_attr_val;
5792 DEF_VEC_O(dw_attr_node);
5793 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5795 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5796 The children of each node form a circular list linked by
5797 die_sib. die_child points to the node *before* the "first" child node. */
5799 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5800 union die_symbol_or_type_node
5802 char * GTY ((tag ("0"))) die_symbol;
5803 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5805 GTY ((desc ("dwarf_version >= 4"))) die_id;
5806 VEC(dw_attr_node,gc) * die_attr;
5807 dw_die_ref die_parent;
5808 dw_die_ref die_child;
5810 dw_die_ref die_definition; /* ref from a specification to its definition */
5811 dw_offset die_offset;
5812 unsigned long die_abbrev;
5814 /* Die is used and must not be pruned as unused. */
5815 int die_perennial_p;
5816 unsigned int decl_id;
5817 enum dwarf_tag die_tag;
5821 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5822 #define FOR_EACH_CHILD(die, c, expr) do { \
5823 c = die->die_child; \
5827 } while (c != die->die_child); \
5830 /* The pubname structure */
5832 typedef struct GTY(()) pubname_struct {
5838 DEF_VEC_O(pubname_entry);
5839 DEF_VEC_ALLOC_O(pubname_entry, gc);
5841 struct GTY(()) dw_ranges_struct {
5842 /* If this is positive, it's a block number, otherwise it's a
5843 bitwise-negated index into dw_ranges_by_label. */
5847 /* A structure to hold a macinfo entry. */
5849 typedef struct GTY(()) macinfo_struct {
5850 unsigned HOST_WIDE_INT code;
5851 unsigned HOST_WIDE_INT lineno;
5856 DEF_VEC_O(macinfo_entry);
5857 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5859 struct GTY(()) dw_ranges_by_label_struct {
5864 /* The comdat type node structure. */
5865 typedef struct GTY(()) comdat_type_struct
5867 dw_die_ref root_die;
5868 dw_die_ref type_die;
5869 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5870 struct comdat_type_struct *next;
5874 /* The limbo die list structure. */
5875 typedef struct GTY(()) limbo_die_struct {
5878 struct limbo_die_struct *next;
5882 typedef struct GTY(()) skeleton_chain_struct
5886 struct skeleton_chain_struct *parent;
5888 skeleton_chain_node;
5890 /* How to start an assembler comment. */
5891 #ifndef ASM_COMMENT_START
5892 #define ASM_COMMENT_START ";#"
5895 /* Define a macro which returns nonzero for a TYPE_DECL which was
5896 implicitly generated for a tagged type.
5898 Note that unlike the gcc front end (which generates a NULL named
5899 TYPE_DECL node for each complete tagged type, each array type, and
5900 each function type node created) the g++ front end generates a
5901 _named_ TYPE_DECL node for each tagged type node created.
5902 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5903 generate a DW_TAG_typedef DIE for them. */
5905 #define TYPE_DECL_IS_STUB(decl) \
5906 (DECL_NAME (decl) == NULL_TREE \
5907 || (DECL_ARTIFICIAL (decl) \
5908 && is_tagged_type (TREE_TYPE (decl)) \
5909 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5910 /* This is necessary for stub decls that \
5911 appear in nested inline functions. */ \
5912 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5913 && (decl_ultimate_origin (decl) \
5914 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5916 /* Information concerning the compilation unit's programming
5917 language, and compiler version. */
5919 /* Fixed size portion of the DWARF compilation unit header. */
5920 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5921 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5923 /* Fixed size portion of the DWARF comdat type unit header. */
5924 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
5925 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
5926 + DWARF_OFFSET_SIZE)
5928 /* Fixed size portion of public names info. */
5929 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5931 /* Fixed size portion of the address range info. */
5932 #define DWARF_ARANGES_HEADER_SIZE \
5933 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5934 DWARF2_ADDR_SIZE * 2) \
5935 - DWARF_INITIAL_LENGTH_SIZE)
5937 /* Size of padding portion in the address range info. It must be
5938 aligned to twice the pointer size. */
5939 #define DWARF_ARANGES_PAD_SIZE \
5940 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5941 DWARF2_ADDR_SIZE * 2) \
5942 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5944 /* Use assembler line directives if available. */
5945 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5946 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5947 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5949 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5953 /* Minimum line offset in a special line info. opcode.
5954 This value was chosen to give a reasonable range of values. */
5955 #define DWARF_LINE_BASE -10
5957 /* First special line opcode - leave room for the standard opcodes. */
5958 #define DWARF_LINE_OPCODE_BASE 10
5960 /* Range of line offsets in a special line info. opcode. */
5961 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5963 /* Flag that indicates the initial value of the is_stmt_start flag.
5964 In the present implementation, we do not mark any lines as
5965 the beginning of a source statement, because that information
5966 is not made available by the GCC front-end. */
5967 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5969 /* Maximum number of operations per instruction bundle. */
5970 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
5971 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
5974 /* This location is used by calc_die_sizes() to keep track
5975 the offset of each DIE within the .debug_info section. */
5976 static unsigned long next_die_offset;
5978 /* Record the root of the DIE's built for the current compilation unit. */
5979 static GTY(()) dw_die_ref single_comp_unit_die;
5981 /* A list of type DIEs that have been separated into comdat sections. */
5982 static GTY(()) comdat_type_node *comdat_type_list;
5984 /* A list of DIEs with a NULL parent waiting to be relocated. */
5985 static GTY(()) limbo_die_node *limbo_die_list;
5987 /* A list of DIEs for which we may have to generate
5988 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
5989 static GTY(()) limbo_die_node *deferred_asm_name;
5991 /* Filenames referenced by this compilation unit. */
5992 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5994 /* A hash table of references to DIE's that describe declarations.
5995 The key is a DECL_UID() which is a unique number identifying each decl. */
5996 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5998 /* A hash table of references to DIE's that describe COMMON blocks.
5999 The key is DECL_UID() ^ die_parent. */
6000 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6002 typedef struct GTY(()) die_arg_entry_struct {
6007 DEF_VEC_O(die_arg_entry);
6008 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6010 /* Node of the variable location list. */
6011 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6012 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6013 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6014 in mode of the EXPR_LIST node and first EXPR_LIST operand
6015 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6016 location or NULL for padding. For larger bitsizes,
6017 mode is 0 and first operand is a CONCAT with bitsize
6018 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6019 NULL as second operand. */
6021 const char * GTY (()) label;
6022 struct var_loc_node * GTY (()) next;
6025 /* Variable location list. */
6026 struct GTY (()) var_loc_list_def {
6027 struct var_loc_node * GTY (()) first;
6029 /* Pointer to the last but one or last element of the
6030 chained list. If the list is empty, both first and
6031 last are NULL, if the list contains just one node
6032 or the last node certainly is not redundant, it points
6033 to the last node, otherwise points to the last but one.
6034 Do not mark it for GC because it is marked through the chain. */
6035 struct var_loc_node * GTY ((skip ("%h"))) last;
6037 /* DECL_UID of the variable decl. */
6038 unsigned int decl_id;
6040 typedef struct var_loc_list_def var_loc_list;
6043 /* Table of decl location linked lists. */
6044 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6046 /* A pointer to the base of a list of references to DIE's that
6047 are uniquely identified by their tag, presence/absence of
6048 children DIE's, and list of attribute/value pairs. */
6049 static GTY((length ("abbrev_die_table_allocated")))
6050 dw_die_ref *abbrev_die_table;
6052 /* Number of elements currently allocated for abbrev_die_table. */
6053 static GTY(()) unsigned abbrev_die_table_allocated;
6055 /* Number of elements in type_die_table currently in use. */
6056 static GTY(()) unsigned abbrev_die_table_in_use;
6058 /* Size (in elements) of increments by which we may expand the
6059 abbrev_die_table. */
6060 #define ABBREV_DIE_TABLE_INCREMENT 256
6062 /* A pointer to the base of a table that contains line information
6063 for each source code line in .text in the compilation unit. */
6064 static GTY((length ("line_info_table_allocated")))
6065 dw_line_info_ref line_info_table;
6067 /* Number of elements currently allocated for line_info_table. */
6068 static GTY(()) unsigned line_info_table_allocated;
6070 /* Number of elements in line_info_table currently in use. */
6071 static GTY(()) unsigned line_info_table_in_use;
6073 /* A pointer to the base of a table that contains line information
6074 for each source code line outside of .text in the compilation unit. */
6075 static GTY ((length ("separate_line_info_table_allocated")))
6076 dw_separate_line_info_ref separate_line_info_table;
6078 /* Number of elements currently allocated for separate_line_info_table. */
6079 static GTY(()) unsigned separate_line_info_table_allocated;
6081 /* Number of elements in separate_line_info_table currently in use. */
6082 static GTY(()) unsigned separate_line_info_table_in_use;
6084 /* Size (in elements) of increments by which we may expand the
6086 #define LINE_INFO_TABLE_INCREMENT 1024
6088 /* A flag to tell pubnames/types export if there is an info section to
6090 static bool info_section_emitted;
6092 /* A pointer to the base of a table that contains a list of publicly
6093 accessible names. */
6094 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6096 /* A pointer to the base of a table that contains a list of publicly
6097 accessible types. */
6098 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6100 /* A pointer to the base of a table that contains a list of macro
6101 defines/undefines (and file start/end markers). */
6102 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6104 /* Array of dies for which we should generate .debug_arange info. */
6105 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
6107 /* Number of elements currently allocated for arange_table. */
6108 static GTY(()) unsigned arange_table_allocated;
6110 /* Number of elements in arange_table currently in use. */
6111 static GTY(()) unsigned arange_table_in_use;
6113 /* Size (in elements) of increments by which we may expand the
6115 #define ARANGE_TABLE_INCREMENT 64
6117 /* Array of dies for which we should generate .debug_ranges info. */
6118 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6120 /* Number of elements currently allocated for ranges_table. */
6121 static GTY(()) unsigned ranges_table_allocated;
6123 /* Number of elements in ranges_table currently in use. */
6124 static GTY(()) unsigned ranges_table_in_use;
6126 /* Array of pairs of labels referenced in ranges_table. */
6127 static GTY ((length ("ranges_by_label_allocated")))
6128 dw_ranges_by_label_ref ranges_by_label;
6130 /* Number of elements currently allocated for ranges_by_label. */
6131 static GTY(()) unsigned ranges_by_label_allocated;
6133 /* Number of elements in ranges_by_label currently in use. */
6134 static GTY(()) unsigned ranges_by_label_in_use;
6136 /* Size (in elements) of increments by which we may expand the
6138 #define RANGES_TABLE_INCREMENT 64
6140 /* Whether we have location lists that need outputting */
6141 static GTY(()) bool have_location_lists;
6143 /* Unique label counter. */
6144 static GTY(()) unsigned int loclabel_num;
6146 /* Unique label counter for point-of-call tables. */
6147 static GTY(()) unsigned int poc_label_num;
6149 /* The direct call table structure. */
6151 typedef struct GTY(()) dcall_struct {
6152 unsigned int poc_label_num;
6154 dw_die_ref targ_die;
6158 DEF_VEC_O(dcall_entry);
6159 DEF_VEC_ALLOC_O(dcall_entry, gc);
6161 /* The virtual call table structure. */
6163 typedef struct GTY(()) vcall_struct {
6164 unsigned int poc_label_num;
6165 unsigned int vtable_slot;
6169 DEF_VEC_O(vcall_entry);
6170 DEF_VEC_ALLOC_O(vcall_entry, gc);
6172 /* Pointers to the direct and virtual call tables. */
6173 static GTY (()) VEC (dcall_entry, gc) * dcall_table = NULL;
6174 static GTY (()) VEC (vcall_entry, gc) * vcall_table = NULL;
6176 /* A hash table to map INSN_UIDs to vtable slot indexes. */
6178 struct GTY (()) vcall_insn {
6180 unsigned int vtable_slot;
6183 static GTY ((param_is (struct vcall_insn))) htab_t vcall_insn_table;
6185 /* Record whether the function being analyzed contains inlined functions. */
6186 static int current_function_has_inlines;
6188 /* The last file entry emitted by maybe_emit_file(). */
6189 static GTY(()) struct dwarf_file_data * last_emitted_file;
6191 /* Number of internal labels generated by gen_internal_sym(). */
6192 static GTY(()) int label_num;
6194 /* Cached result of previous call to lookup_filename. */
6195 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6197 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6199 /* Offset from the "steady-state frame pointer" to the frame base,
6200 within the current function. */
6201 static HOST_WIDE_INT frame_pointer_fb_offset;
6203 /* Forward declarations for functions defined in this file. */
6205 static int is_pseudo_reg (const_rtx);
6206 static tree type_main_variant (tree);
6207 static int is_tagged_type (const_tree);
6208 static const char *dwarf_tag_name (unsigned);
6209 static const char *dwarf_attr_name (unsigned);
6210 static const char *dwarf_form_name (unsigned);
6211 static tree decl_ultimate_origin (const_tree);
6212 static tree decl_class_context (tree);
6213 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6214 static inline enum dw_val_class AT_class (dw_attr_ref);
6215 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6216 static inline unsigned AT_flag (dw_attr_ref);
6217 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6218 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6219 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6220 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6221 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6222 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6223 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6224 unsigned int, unsigned char *);
6225 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6226 static hashval_t debug_str_do_hash (const void *);
6227 static int debug_str_eq (const void *, const void *);
6228 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6229 static inline const char *AT_string (dw_attr_ref);
6230 static enum dwarf_form AT_string_form (dw_attr_ref);
6231 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6232 static void add_AT_specification (dw_die_ref, dw_die_ref);
6233 static inline dw_die_ref AT_ref (dw_attr_ref);
6234 static inline int AT_ref_external (dw_attr_ref);
6235 static inline void set_AT_ref_external (dw_attr_ref, int);
6236 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6237 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6238 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6239 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6241 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6242 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6243 static inline rtx AT_addr (dw_attr_ref);
6244 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6245 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6246 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6247 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6248 unsigned HOST_WIDE_INT);
6249 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6251 static inline const char *AT_lbl (dw_attr_ref);
6252 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6253 static const char *get_AT_low_pc (dw_die_ref);
6254 static const char *get_AT_hi_pc (dw_die_ref);
6255 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6256 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6257 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6258 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6259 static bool is_cxx (void);
6260 static bool is_fortran (void);
6261 static bool is_ada (void);
6262 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6263 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6264 static void add_child_die (dw_die_ref, dw_die_ref);
6265 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6266 static dw_die_ref lookup_type_die (tree);
6267 static void equate_type_number_to_die (tree, dw_die_ref);
6268 static hashval_t decl_die_table_hash (const void *);
6269 static int decl_die_table_eq (const void *, const void *);
6270 static dw_die_ref lookup_decl_die (tree);
6271 static hashval_t common_block_die_table_hash (const void *);
6272 static int common_block_die_table_eq (const void *, const void *);
6273 static hashval_t decl_loc_table_hash (const void *);
6274 static int decl_loc_table_eq (const void *, const void *);
6275 static var_loc_list *lookup_decl_loc (const_tree);
6276 static void equate_decl_number_to_die (tree, dw_die_ref);
6277 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6278 static void print_spaces (FILE *);
6279 static void print_die (dw_die_ref, FILE *);
6280 static void print_dwarf_line_table (FILE *);
6281 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6282 static dw_die_ref pop_compile_unit (dw_die_ref);
6283 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6284 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6285 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6286 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6287 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6288 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6289 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6290 struct md5_ctx *, int *);
6291 struct checksum_attributes;
6292 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6293 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6294 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6295 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6296 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6297 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6298 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6299 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6300 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6301 static void compute_section_prefix (dw_die_ref);
6302 static int is_type_die (dw_die_ref);
6303 static int is_comdat_die (dw_die_ref);
6304 static int is_symbol_die (dw_die_ref);
6305 static void assign_symbol_names (dw_die_ref);
6306 static void break_out_includes (dw_die_ref);
6307 static int is_declaration_die (dw_die_ref);
6308 static int should_move_die_to_comdat (dw_die_ref);
6309 static dw_die_ref clone_as_declaration (dw_die_ref);
6310 static dw_die_ref clone_die (dw_die_ref);
6311 static dw_die_ref clone_tree (dw_die_ref);
6312 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6313 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6314 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6315 static dw_die_ref generate_skeleton (dw_die_ref);
6316 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6318 static void break_out_comdat_types (dw_die_ref);
6319 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6320 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6321 static void copy_decls_for_unworthy_types (dw_die_ref);
6323 static hashval_t htab_cu_hash (const void *);
6324 static int htab_cu_eq (const void *, const void *);
6325 static void htab_cu_del (void *);
6326 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6327 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6328 static void add_sibling_attributes (dw_die_ref);
6329 static void build_abbrev_table (dw_die_ref);
6330 static void output_location_lists (dw_die_ref);
6331 static int constant_size (unsigned HOST_WIDE_INT);
6332 static unsigned long size_of_die (dw_die_ref);
6333 static void calc_die_sizes (dw_die_ref);
6334 static void mark_dies (dw_die_ref);
6335 static void unmark_dies (dw_die_ref);
6336 static void unmark_all_dies (dw_die_ref);
6337 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6338 static unsigned long size_of_aranges (void);
6339 static enum dwarf_form value_format (dw_attr_ref);
6340 static void output_value_format (dw_attr_ref);
6341 static void output_abbrev_section (void);
6342 static void output_die_symbol (dw_die_ref);
6343 static void output_die (dw_die_ref);
6344 static void output_compilation_unit_header (void);
6345 static void output_comp_unit (dw_die_ref, int);
6346 static void output_comdat_type_unit (comdat_type_node *);
6347 static const char *dwarf2_name (tree, int);
6348 static void add_pubname (tree, dw_die_ref);
6349 static void add_pubname_string (const char *, dw_die_ref);
6350 static void add_pubtype (tree, dw_die_ref);
6351 static void output_pubnames (VEC (pubname_entry,gc) *);
6352 static void add_arange (tree, dw_die_ref);
6353 static void output_aranges (void);
6354 static unsigned int add_ranges_num (int);
6355 static unsigned int add_ranges (const_tree);
6356 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6358 static void output_ranges (void);
6359 static void output_line_info (void);
6360 static void output_file_names (void);
6361 static dw_die_ref base_type_die (tree);
6362 static int is_base_type (tree);
6363 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6364 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6365 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6366 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6367 static int type_is_enum (const_tree);
6368 static unsigned int dbx_reg_number (const_rtx);
6369 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6370 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6371 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6372 enum var_init_status);
6373 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6374 enum var_init_status);
6375 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6376 enum var_init_status);
6377 static int is_based_loc (const_rtx);
6378 static int resolve_one_addr (rtx *, void *);
6379 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6380 enum var_init_status);
6381 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6382 enum var_init_status);
6383 static dw_loc_list_ref loc_list_from_tree (tree, int);
6384 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6385 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6386 static tree field_type (const_tree);
6387 static unsigned int simple_type_align_in_bits (const_tree);
6388 static unsigned int simple_decl_align_in_bits (const_tree);
6389 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6390 static HOST_WIDE_INT field_byte_offset (const_tree);
6391 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6393 static void add_data_member_location_attribute (dw_die_ref, tree);
6394 static bool add_const_value_attribute (dw_die_ref, rtx);
6395 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6396 static void insert_double (double_int, unsigned char *);
6397 static void insert_float (const_rtx, unsigned char *);
6398 static rtx rtl_for_decl_location (tree);
6399 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6400 enum dwarf_attribute);
6401 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6402 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6403 static void add_name_attribute (dw_die_ref, const char *);
6404 static void add_comp_dir_attribute (dw_die_ref);
6405 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6406 static void add_subscript_info (dw_die_ref, tree, bool);
6407 static void add_byte_size_attribute (dw_die_ref, tree);
6408 static void add_bit_offset_attribute (dw_die_ref, tree);
6409 static void add_bit_size_attribute (dw_die_ref, tree);
6410 static void add_prototyped_attribute (dw_die_ref, tree);
6411 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6412 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6413 static void add_src_coords_attributes (dw_die_ref, tree);
6414 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6415 static void push_decl_scope (tree);
6416 static void pop_decl_scope (void);
6417 static dw_die_ref scope_die_for (tree, dw_die_ref);
6418 static inline int local_scope_p (dw_die_ref);
6419 static inline int class_scope_p (dw_die_ref);
6420 static inline int class_or_namespace_scope_p (dw_die_ref);
6421 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6422 static void add_calling_convention_attribute (dw_die_ref, tree);
6423 static const char *type_tag (const_tree);
6424 static tree member_declared_type (const_tree);
6426 static const char *decl_start_label (tree);
6428 static void gen_array_type_die (tree, dw_die_ref);
6429 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6431 static void gen_entry_point_die (tree, dw_die_ref);
6433 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6434 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6435 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6436 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6437 static void gen_formal_types_die (tree, dw_die_ref);
6438 static void gen_subprogram_die (tree, dw_die_ref);
6439 static void gen_variable_die (tree, tree, dw_die_ref);
6440 static void gen_const_die (tree, dw_die_ref);
6441 static void gen_label_die (tree, dw_die_ref);
6442 static void gen_lexical_block_die (tree, dw_die_ref, int);
6443 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6444 static void gen_field_die (tree, dw_die_ref);
6445 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6446 static dw_die_ref gen_compile_unit_die (const char *);
6447 static void gen_inheritance_die (tree, tree, dw_die_ref);
6448 static void gen_member_die (tree, dw_die_ref);
6449 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6450 enum debug_info_usage);
6451 static void gen_subroutine_type_die (tree, dw_die_ref);
6452 static void gen_typedef_die (tree, dw_die_ref);
6453 static void gen_type_die (tree, dw_die_ref);
6454 static void gen_block_die (tree, dw_die_ref, int);
6455 static void decls_for_scope (tree, dw_die_ref, int);
6456 static int is_redundant_typedef (const_tree);
6457 static bool is_naming_typedef_decl (const_tree);
6458 static inline dw_die_ref get_context_die (tree);
6459 static void gen_namespace_die (tree, dw_die_ref);
6460 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6461 static dw_die_ref force_decl_die (tree);
6462 static dw_die_ref force_type_die (tree);
6463 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6464 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6465 static struct dwarf_file_data * lookup_filename (const char *);
6466 static void retry_incomplete_types (void);
6467 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6468 static void gen_generic_params_dies (tree);
6469 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6470 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6471 static void splice_child_die (dw_die_ref, dw_die_ref);
6472 static int file_info_cmp (const void *, const void *);
6473 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6474 const char *, const char *);
6475 static void output_loc_list (dw_loc_list_ref);
6476 static char *gen_internal_sym (const char *);
6478 static void prune_unmark_dies (dw_die_ref);
6479 static void prune_unused_types_mark (dw_die_ref, int);
6480 static void prune_unused_types_walk (dw_die_ref);
6481 static void prune_unused_types_walk_attribs (dw_die_ref);
6482 static void prune_unused_types_prune (dw_die_ref);
6483 static void prune_unused_types (void);
6484 static int maybe_emit_file (struct dwarf_file_data *fd);
6485 static inline const char *AT_vms_delta1 (dw_attr_ref);
6486 static inline const char *AT_vms_delta2 (dw_attr_ref);
6487 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6488 const char *, const char *);
6489 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6490 static void gen_remaining_tmpl_value_param_die_attribute (void);
6492 /* Section names used to hold DWARF debugging information. */
6493 #ifndef DEBUG_INFO_SECTION
6494 #define DEBUG_INFO_SECTION ".debug_info"
6496 #ifndef DEBUG_ABBREV_SECTION
6497 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6499 #ifndef DEBUG_ARANGES_SECTION
6500 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6502 #ifndef DEBUG_MACINFO_SECTION
6503 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6505 #ifndef DEBUG_LINE_SECTION
6506 #define DEBUG_LINE_SECTION ".debug_line"
6508 #ifndef DEBUG_LOC_SECTION
6509 #define DEBUG_LOC_SECTION ".debug_loc"
6511 #ifndef DEBUG_PUBNAMES_SECTION
6512 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6514 #ifndef DEBUG_PUBTYPES_SECTION
6515 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6517 #ifndef DEBUG_DCALL_SECTION
6518 #define DEBUG_DCALL_SECTION ".debug_dcall"
6520 #ifndef DEBUG_VCALL_SECTION
6521 #define DEBUG_VCALL_SECTION ".debug_vcall"
6523 #ifndef DEBUG_STR_SECTION
6524 #define DEBUG_STR_SECTION ".debug_str"
6526 #ifndef DEBUG_RANGES_SECTION
6527 #define DEBUG_RANGES_SECTION ".debug_ranges"
6530 /* Standard ELF section names for compiled code and data. */
6531 #ifndef TEXT_SECTION_NAME
6532 #define TEXT_SECTION_NAME ".text"
6535 /* Section flags for .debug_str section. */
6536 #define DEBUG_STR_SECTION_FLAGS \
6537 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6538 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6541 /* Labels we insert at beginning sections we can reference instead of
6542 the section names themselves. */
6544 #ifndef TEXT_SECTION_LABEL
6545 #define TEXT_SECTION_LABEL "Ltext"
6547 #ifndef COLD_TEXT_SECTION_LABEL
6548 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6550 #ifndef DEBUG_LINE_SECTION_LABEL
6551 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6553 #ifndef DEBUG_INFO_SECTION_LABEL
6554 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6556 #ifndef DEBUG_ABBREV_SECTION_LABEL
6557 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6559 #ifndef DEBUG_LOC_SECTION_LABEL
6560 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6562 #ifndef DEBUG_RANGES_SECTION_LABEL
6563 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6565 #ifndef DEBUG_MACINFO_SECTION_LABEL
6566 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6570 /* Definitions of defaults for formats and names of various special
6571 (artificial) labels which may be generated within this file (when the -g
6572 options is used and DWARF2_DEBUGGING_INFO is in effect.
6573 If necessary, these may be overridden from within the tm.h file, but
6574 typically, overriding these defaults is unnecessary. */
6576 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6577 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6578 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6579 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6580 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6581 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6582 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6583 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6584 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6585 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6587 #ifndef TEXT_END_LABEL
6588 #define TEXT_END_LABEL "Letext"
6590 #ifndef COLD_END_LABEL
6591 #define COLD_END_LABEL "Letext_cold"
6593 #ifndef BLOCK_BEGIN_LABEL
6594 #define BLOCK_BEGIN_LABEL "LBB"
6596 #ifndef BLOCK_END_LABEL
6597 #define BLOCK_END_LABEL "LBE"
6599 #ifndef LINE_CODE_LABEL
6600 #define LINE_CODE_LABEL "LM"
6602 #ifndef SEPARATE_LINE_CODE_LABEL
6603 #define SEPARATE_LINE_CODE_LABEL "LSM"
6607 /* Return the root of the DIE's built for the current compilation unit. */
6609 comp_unit_die (void)
6611 if (!single_comp_unit_die)
6612 single_comp_unit_die = gen_compile_unit_die (NULL);
6613 return single_comp_unit_die;
6616 /* We allow a language front-end to designate a function that is to be
6617 called to "demangle" any name before it is put into a DIE. */
6619 static const char *(*demangle_name_func) (const char *);
6622 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6624 demangle_name_func = func;
6627 /* Test if rtl node points to a pseudo register. */
6630 is_pseudo_reg (const_rtx rtl)
6632 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6633 || (GET_CODE (rtl) == SUBREG
6634 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6637 /* Return a reference to a type, with its const and volatile qualifiers
6641 type_main_variant (tree type)
6643 type = TYPE_MAIN_VARIANT (type);
6645 /* ??? There really should be only one main variant among any group of
6646 variants of a given type (and all of the MAIN_VARIANT values for all
6647 members of the group should point to that one type) but sometimes the C
6648 front-end messes this up for array types, so we work around that bug
6650 if (TREE_CODE (type) == ARRAY_TYPE)
6651 while (type != TYPE_MAIN_VARIANT (type))
6652 type = TYPE_MAIN_VARIANT (type);
6657 /* Return nonzero if the given type node represents a tagged type. */
6660 is_tagged_type (const_tree type)
6662 enum tree_code code = TREE_CODE (type);
6664 return (code == RECORD_TYPE || code == UNION_TYPE
6665 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6668 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6671 get_ref_die_offset_label (char *label, dw_die_ref ref)
6673 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6676 /* Convert a DIE tag into its string name. */
6679 dwarf_tag_name (unsigned int tag)
6683 case DW_TAG_padding:
6684 return "DW_TAG_padding";
6685 case DW_TAG_array_type:
6686 return "DW_TAG_array_type";
6687 case DW_TAG_class_type:
6688 return "DW_TAG_class_type";
6689 case DW_TAG_entry_point:
6690 return "DW_TAG_entry_point";
6691 case DW_TAG_enumeration_type:
6692 return "DW_TAG_enumeration_type";
6693 case DW_TAG_formal_parameter:
6694 return "DW_TAG_formal_parameter";
6695 case DW_TAG_imported_declaration:
6696 return "DW_TAG_imported_declaration";
6698 return "DW_TAG_label";
6699 case DW_TAG_lexical_block:
6700 return "DW_TAG_lexical_block";
6702 return "DW_TAG_member";
6703 case DW_TAG_pointer_type:
6704 return "DW_TAG_pointer_type";
6705 case DW_TAG_reference_type:
6706 return "DW_TAG_reference_type";
6707 case DW_TAG_compile_unit:
6708 return "DW_TAG_compile_unit";
6709 case DW_TAG_string_type:
6710 return "DW_TAG_string_type";
6711 case DW_TAG_structure_type:
6712 return "DW_TAG_structure_type";
6713 case DW_TAG_subroutine_type:
6714 return "DW_TAG_subroutine_type";
6715 case DW_TAG_typedef:
6716 return "DW_TAG_typedef";
6717 case DW_TAG_union_type:
6718 return "DW_TAG_union_type";
6719 case DW_TAG_unspecified_parameters:
6720 return "DW_TAG_unspecified_parameters";
6721 case DW_TAG_variant:
6722 return "DW_TAG_variant";
6723 case DW_TAG_common_block:
6724 return "DW_TAG_common_block";
6725 case DW_TAG_common_inclusion:
6726 return "DW_TAG_common_inclusion";
6727 case DW_TAG_inheritance:
6728 return "DW_TAG_inheritance";
6729 case DW_TAG_inlined_subroutine:
6730 return "DW_TAG_inlined_subroutine";
6732 return "DW_TAG_module";
6733 case DW_TAG_ptr_to_member_type:
6734 return "DW_TAG_ptr_to_member_type";
6735 case DW_TAG_set_type:
6736 return "DW_TAG_set_type";
6737 case DW_TAG_subrange_type:
6738 return "DW_TAG_subrange_type";
6739 case DW_TAG_with_stmt:
6740 return "DW_TAG_with_stmt";
6741 case DW_TAG_access_declaration:
6742 return "DW_TAG_access_declaration";
6743 case DW_TAG_base_type:
6744 return "DW_TAG_base_type";
6745 case DW_TAG_catch_block:
6746 return "DW_TAG_catch_block";
6747 case DW_TAG_const_type:
6748 return "DW_TAG_const_type";
6749 case DW_TAG_constant:
6750 return "DW_TAG_constant";
6751 case DW_TAG_enumerator:
6752 return "DW_TAG_enumerator";
6753 case DW_TAG_file_type:
6754 return "DW_TAG_file_type";
6756 return "DW_TAG_friend";
6757 case DW_TAG_namelist:
6758 return "DW_TAG_namelist";
6759 case DW_TAG_namelist_item:
6760 return "DW_TAG_namelist_item";
6761 case DW_TAG_packed_type:
6762 return "DW_TAG_packed_type";
6763 case DW_TAG_subprogram:
6764 return "DW_TAG_subprogram";
6765 case DW_TAG_template_type_param:
6766 return "DW_TAG_template_type_param";
6767 case DW_TAG_template_value_param:
6768 return "DW_TAG_template_value_param";
6769 case DW_TAG_thrown_type:
6770 return "DW_TAG_thrown_type";
6771 case DW_TAG_try_block:
6772 return "DW_TAG_try_block";
6773 case DW_TAG_variant_part:
6774 return "DW_TAG_variant_part";
6775 case DW_TAG_variable:
6776 return "DW_TAG_variable";
6777 case DW_TAG_volatile_type:
6778 return "DW_TAG_volatile_type";
6779 case DW_TAG_dwarf_procedure:
6780 return "DW_TAG_dwarf_procedure";
6781 case DW_TAG_restrict_type:
6782 return "DW_TAG_restrict_type";
6783 case DW_TAG_interface_type:
6784 return "DW_TAG_interface_type";
6785 case DW_TAG_namespace:
6786 return "DW_TAG_namespace";
6787 case DW_TAG_imported_module:
6788 return "DW_TAG_imported_module";
6789 case DW_TAG_unspecified_type:
6790 return "DW_TAG_unspecified_type";
6791 case DW_TAG_partial_unit:
6792 return "DW_TAG_partial_unit";
6793 case DW_TAG_imported_unit:
6794 return "DW_TAG_imported_unit";
6795 case DW_TAG_condition:
6796 return "DW_TAG_condition";
6797 case DW_TAG_shared_type:
6798 return "DW_TAG_shared_type";
6799 case DW_TAG_type_unit:
6800 return "DW_TAG_type_unit";
6801 case DW_TAG_rvalue_reference_type:
6802 return "DW_TAG_rvalue_reference_type";
6803 case DW_TAG_template_alias:
6804 return "DW_TAG_template_alias";
6805 case DW_TAG_GNU_template_parameter_pack:
6806 return "DW_TAG_GNU_template_parameter_pack";
6807 case DW_TAG_GNU_formal_parameter_pack:
6808 return "DW_TAG_GNU_formal_parameter_pack";
6809 case DW_TAG_MIPS_loop:
6810 return "DW_TAG_MIPS_loop";
6811 case DW_TAG_format_label:
6812 return "DW_TAG_format_label";
6813 case DW_TAG_function_template:
6814 return "DW_TAG_function_template";
6815 case DW_TAG_class_template:
6816 return "DW_TAG_class_template";
6817 case DW_TAG_GNU_BINCL:
6818 return "DW_TAG_GNU_BINCL";
6819 case DW_TAG_GNU_EINCL:
6820 return "DW_TAG_GNU_EINCL";
6821 case DW_TAG_GNU_template_template_param:
6822 return "DW_TAG_GNU_template_template_param";
6824 return "DW_TAG_<unknown>";
6828 /* Convert a DWARF attribute code into its string name. */
6831 dwarf_attr_name (unsigned int attr)
6836 return "DW_AT_sibling";
6837 case DW_AT_location:
6838 return "DW_AT_location";
6840 return "DW_AT_name";
6841 case DW_AT_ordering:
6842 return "DW_AT_ordering";
6843 case DW_AT_subscr_data:
6844 return "DW_AT_subscr_data";
6845 case DW_AT_byte_size:
6846 return "DW_AT_byte_size";
6847 case DW_AT_bit_offset:
6848 return "DW_AT_bit_offset";
6849 case DW_AT_bit_size:
6850 return "DW_AT_bit_size";
6851 case DW_AT_element_list:
6852 return "DW_AT_element_list";
6853 case DW_AT_stmt_list:
6854 return "DW_AT_stmt_list";
6856 return "DW_AT_low_pc";
6858 return "DW_AT_high_pc";
6859 case DW_AT_language:
6860 return "DW_AT_language";
6862 return "DW_AT_member";
6864 return "DW_AT_discr";
6865 case DW_AT_discr_value:
6866 return "DW_AT_discr_value";
6867 case DW_AT_visibility:
6868 return "DW_AT_visibility";
6870 return "DW_AT_import";
6871 case DW_AT_string_length:
6872 return "DW_AT_string_length";
6873 case DW_AT_common_reference:
6874 return "DW_AT_common_reference";
6875 case DW_AT_comp_dir:
6876 return "DW_AT_comp_dir";
6877 case DW_AT_const_value:
6878 return "DW_AT_const_value";
6879 case DW_AT_containing_type:
6880 return "DW_AT_containing_type";
6881 case DW_AT_default_value:
6882 return "DW_AT_default_value";
6884 return "DW_AT_inline";
6885 case DW_AT_is_optional:
6886 return "DW_AT_is_optional";
6887 case DW_AT_lower_bound:
6888 return "DW_AT_lower_bound";
6889 case DW_AT_producer:
6890 return "DW_AT_producer";
6891 case DW_AT_prototyped:
6892 return "DW_AT_prototyped";
6893 case DW_AT_return_addr:
6894 return "DW_AT_return_addr";
6895 case DW_AT_start_scope:
6896 return "DW_AT_start_scope";
6897 case DW_AT_bit_stride:
6898 return "DW_AT_bit_stride";
6899 case DW_AT_upper_bound:
6900 return "DW_AT_upper_bound";
6901 case DW_AT_abstract_origin:
6902 return "DW_AT_abstract_origin";
6903 case DW_AT_accessibility:
6904 return "DW_AT_accessibility";
6905 case DW_AT_address_class:
6906 return "DW_AT_address_class";
6907 case DW_AT_artificial:
6908 return "DW_AT_artificial";
6909 case DW_AT_base_types:
6910 return "DW_AT_base_types";
6911 case DW_AT_calling_convention:
6912 return "DW_AT_calling_convention";
6914 return "DW_AT_count";
6915 case DW_AT_data_member_location:
6916 return "DW_AT_data_member_location";
6917 case DW_AT_decl_column:
6918 return "DW_AT_decl_column";
6919 case DW_AT_decl_file:
6920 return "DW_AT_decl_file";
6921 case DW_AT_decl_line:
6922 return "DW_AT_decl_line";
6923 case DW_AT_declaration:
6924 return "DW_AT_declaration";
6925 case DW_AT_discr_list:
6926 return "DW_AT_discr_list";
6927 case DW_AT_encoding:
6928 return "DW_AT_encoding";
6929 case DW_AT_external:
6930 return "DW_AT_external";
6931 case DW_AT_explicit:
6932 return "DW_AT_explicit";
6933 case DW_AT_frame_base:
6934 return "DW_AT_frame_base";
6936 return "DW_AT_friend";
6937 case DW_AT_identifier_case:
6938 return "DW_AT_identifier_case";
6939 case DW_AT_macro_info:
6940 return "DW_AT_macro_info";
6941 case DW_AT_namelist_items:
6942 return "DW_AT_namelist_items";
6943 case DW_AT_priority:
6944 return "DW_AT_priority";
6946 return "DW_AT_segment";
6947 case DW_AT_specification:
6948 return "DW_AT_specification";
6949 case DW_AT_static_link:
6950 return "DW_AT_static_link";
6952 return "DW_AT_type";
6953 case DW_AT_use_location:
6954 return "DW_AT_use_location";
6955 case DW_AT_variable_parameter:
6956 return "DW_AT_variable_parameter";
6957 case DW_AT_virtuality:
6958 return "DW_AT_virtuality";
6959 case DW_AT_vtable_elem_location:
6960 return "DW_AT_vtable_elem_location";
6962 case DW_AT_allocated:
6963 return "DW_AT_allocated";
6964 case DW_AT_associated:
6965 return "DW_AT_associated";
6966 case DW_AT_data_location:
6967 return "DW_AT_data_location";
6968 case DW_AT_byte_stride:
6969 return "DW_AT_byte_stride";
6970 case DW_AT_entry_pc:
6971 return "DW_AT_entry_pc";
6972 case DW_AT_use_UTF8:
6973 return "DW_AT_use_UTF8";
6974 case DW_AT_extension:
6975 return "DW_AT_extension";
6977 return "DW_AT_ranges";
6978 case DW_AT_trampoline:
6979 return "DW_AT_trampoline";
6980 case DW_AT_call_column:
6981 return "DW_AT_call_column";
6982 case DW_AT_call_file:
6983 return "DW_AT_call_file";
6984 case DW_AT_call_line:
6985 return "DW_AT_call_line";
6986 case DW_AT_object_pointer:
6987 return "DW_AT_object_pointer";
6989 case DW_AT_signature:
6990 return "DW_AT_signature";
6991 case DW_AT_main_subprogram:
6992 return "DW_AT_main_subprogram";
6993 case DW_AT_data_bit_offset:
6994 return "DW_AT_data_bit_offset";
6995 case DW_AT_const_expr:
6996 return "DW_AT_const_expr";
6997 case DW_AT_enum_class:
6998 return "DW_AT_enum_class";
6999 case DW_AT_linkage_name:
7000 return "DW_AT_linkage_name";
7002 case DW_AT_MIPS_fde:
7003 return "DW_AT_MIPS_fde";
7004 case DW_AT_MIPS_loop_begin:
7005 return "DW_AT_MIPS_loop_begin";
7006 case DW_AT_MIPS_tail_loop_begin:
7007 return "DW_AT_MIPS_tail_loop_begin";
7008 case DW_AT_MIPS_epilog_begin:
7009 return "DW_AT_MIPS_epilog_begin";
7010 #if VMS_DEBUGGING_INFO
7011 case DW_AT_HP_prologue:
7012 return "DW_AT_HP_prologue";
7014 case DW_AT_MIPS_loop_unroll_factor:
7015 return "DW_AT_MIPS_loop_unroll_factor";
7017 case DW_AT_MIPS_software_pipeline_depth:
7018 return "DW_AT_MIPS_software_pipeline_depth";
7019 case DW_AT_MIPS_linkage_name:
7020 return "DW_AT_MIPS_linkage_name";
7021 #if VMS_DEBUGGING_INFO
7022 case DW_AT_HP_epilogue:
7023 return "DW_AT_HP_epilogue";
7025 case DW_AT_MIPS_stride:
7026 return "DW_AT_MIPS_stride";
7028 case DW_AT_MIPS_abstract_name:
7029 return "DW_AT_MIPS_abstract_name";
7030 case DW_AT_MIPS_clone_origin:
7031 return "DW_AT_MIPS_clone_origin";
7032 case DW_AT_MIPS_has_inlines:
7033 return "DW_AT_MIPS_has_inlines";
7035 case DW_AT_sf_names:
7036 return "DW_AT_sf_names";
7037 case DW_AT_src_info:
7038 return "DW_AT_src_info";
7039 case DW_AT_mac_info:
7040 return "DW_AT_mac_info";
7041 case DW_AT_src_coords:
7042 return "DW_AT_src_coords";
7043 case DW_AT_body_begin:
7044 return "DW_AT_body_begin";
7045 case DW_AT_body_end:
7046 return "DW_AT_body_end";
7047 case DW_AT_GNU_vector:
7048 return "DW_AT_GNU_vector";
7049 case DW_AT_GNU_guarded_by:
7050 return "DW_AT_GNU_guarded_by";
7051 case DW_AT_GNU_pt_guarded_by:
7052 return "DW_AT_GNU_pt_guarded_by";
7053 case DW_AT_GNU_guarded:
7054 return "DW_AT_GNU_guarded";
7055 case DW_AT_GNU_pt_guarded:
7056 return "DW_AT_GNU_pt_guarded";
7057 case DW_AT_GNU_locks_excluded:
7058 return "DW_AT_GNU_locks_excluded";
7059 case DW_AT_GNU_exclusive_locks_required:
7060 return "DW_AT_GNU_exclusive_locks_required";
7061 case DW_AT_GNU_shared_locks_required:
7062 return "DW_AT_GNU_shared_locks_required";
7063 case DW_AT_GNU_odr_signature:
7064 return "DW_AT_GNU_odr_signature";
7065 case DW_AT_GNU_template_name:
7066 return "DW_AT_GNU_template_name";
7068 case DW_AT_VMS_rtnbeg_pd_address:
7069 return "DW_AT_VMS_rtnbeg_pd_address";
7072 return "DW_AT_<unknown>";
7076 /* Convert a DWARF value form code into its string name. */
7079 dwarf_form_name (unsigned int form)
7084 return "DW_FORM_addr";
7085 case DW_FORM_block2:
7086 return "DW_FORM_block2";
7087 case DW_FORM_block4:
7088 return "DW_FORM_block4";
7090 return "DW_FORM_data2";
7092 return "DW_FORM_data4";
7094 return "DW_FORM_data8";
7095 case DW_FORM_string:
7096 return "DW_FORM_string";
7098 return "DW_FORM_block";
7099 case DW_FORM_block1:
7100 return "DW_FORM_block1";
7102 return "DW_FORM_data1";
7104 return "DW_FORM_flag";
7106 return "DW_FORM_sdata";
7108 return "DW_FORM_strp";
7110 return "DW_FORM_udata";
7111 case DW_FORM_ref_addr:
7112 return "DW_FORM_ref_addr";
7114 return "DW_FORM_ref1";
7116 return "DW_FORM_ref2";
7118 return "DW_FORM_ref4";
7120 return "DW_FORM_ref8";
7121 case DW_FORM_ref_udata:
7122 return "DW_FORM_ref_udata";
7123 case DW_FORM_indirect:
7124 return "DW_FORM_indirect";
7125 case DW_FORM_sec_offset:
7126 return "DW_FORM_sec_offset";
7127 case DW_FORM_exprloc:
7128 return "DW_FORM_exprloc";
7129 case DW_FORM_flag_present:
7130 return "DW_FORM_flag_present";
7131 case DW_FORM_ref_sig8:
7132 return "DW_FORM_ref_sig8";
7134 return "DW_FORM_<unknown>";
7138 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7139 instance of an inlined instance of a decl which is local to an inline
7140 function, so we have to trace all of the way back through the origin chain
7141 to find out what sort of node actually served as the original seed for the
7145 decl_ultimate_origin (const_tree decl)
7147 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7150 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7151 nodes in the function to point to themselves; ignore that if
7152 we're trying to output the abstract instance of this function. */
7153 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7156 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7157 most distant ancestor, this should never happen. */
7158 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7160 return DECL_ABSTRACT_ORIGIN (decl);
7163 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7164 of a virtual function may refer to a base class, so we check the 'this'
7168 decl_class_context (tree decl)
7170 tree context = NULL_TREE;
7172 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7173 context = DECL_CONTEXT (decl);
7175 context = TYPE_MAIN_VARIANT
7176 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7178 if (context && !TYPE_P (context))
7179 context = NULL_TREE;
7184 /* Add an attribute/value pair to a DIE. */
7187 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7189 /* Maybe this should be an assert? */
7193 if (die->die_attr == NULL)
7194 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7195 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7198 static inline enum dw_val_class
7199 AT_class (dw_attr_ref a)
7201 return a->dw_attr_val.val_class;
7204 /* Add a flag value attribute to a DIE. */
7207 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7211 attr.dw_attr = attr_kind;
7212 attr.dw_attr_val.val_class = dw_val_class_flag;
7213 attr.dw_attr_val.v.val_flag = flag;
7214 add_dwarf_attr (die, &attr);
7217 static inline unsigned
7218 AT_flag (dw_attr_ref a)
7220 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7221 return a->dw_attr_val.v.val_flag;
7224 /* Add a signed integer attribute value to a DIE. */
7227 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7231 attr.dw_attr = attr_kind;
7232 attr.dw_attr_val.val_class = dw_val_class_const;
7233 attr.dw_attr_val.v.val_int = int_val;
7234 add_dwarf_attr (die, &attr);
7237 static inline HOST_WIDE_INT
7238 AT_int (dw_attr_ref a)
7240 gcc_assert (a && AT_class (a) == dw_val_class_const);
7241 return a->dw_attr_val.v.val_int;
7244 /* Add an unsigned integer attribute value to a DIE. */
7247 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7248 unsigned HOST_WIDE_INT unsigned_val)
7252 attr.dw_attr = attr_kind;
7253 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7254 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7255 add_dwarf_attr (die, &attr);
7258 static inline unsigned HOST_WIDE_INT
7259 AT_unsigned (dw_attr_ref a)
7261 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7262 return a->dw_attr_val.v.val_unsigned;
7265 /* Add an unsigned double integer attribute value to a DIE. */
7268 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7269 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7273 attr.dw_attr = attr_kind;
7274 attr.dw_attr_val.val_class = dw_val_class_const_double;
7275 attr.dw_attr_val.v.val_double.high = high;
7276 attr.dw_attr_val.v.val_double.low = low;
7277 add_dwarf_attr (die, &attr);
7280 /* Add a floating point attribute value to a DIE and return it. */
7283 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7284 unsigned int length, unsigned int elt_size, unsigned char *array)
7288 attr.dw_attr = attr_kind;
7289 attr.dw_attr_val.val_class = dw_val_class_vec;
7290 attr.dw_attr_val.v.val_vec.length = length;
7291 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7292 attr.dw_attr_val.v.val_vec.array = array;
7293 add_dwarf_attr (die, &attr);
7296 /* Add an 8-byte data attribute value to a DIE. */
7299 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7300 unsigned char data8[8])
7304 attr.dw_attr = attr_kind;
7305 attr.dw_attr_val.val_class = dw_val_class_data8;
7306 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7307 add_dwarf_attr (die, &attr);
7310 /* Hash and equality functions for debug_str_hash. */
7313 debug_str_do_hash (const void *x)
7315 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7319 debug_str_eq (const void *x1, const void *x2)
7321 return strcmp ((((const struct indirect_string_node *)x1)->str),
7322 (const char *)x2) == 0;
7325 /* Add STR to the indirect string hash table. */
7327 static struct indirect_string_node *
7328 find_AT_string (const char *str)
7330 struct indirect_string_node *node;
7333 if (! debug_str_hash)
7334 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7335 debug_str_eq, NULL);
7337 slot = htab_find_slot_with_hash (debug_str_hash, str,
7338 htab_hash_string (str), INSERT);
7341 node = ggc_alloc_cleared_indirect_string_node ();
7342 node->str = ggc_strdup (str);
7346 node = (struct indirect_string_node *) *slot;
7352 /* Add a string attribute value to a DIE. */
7355 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7358 struct indirect_string_node *node;
7360 node = find_AT_string (str);
7362 attr.dw_attr = attr_kind;
7363 attr.dw_attr_val.val_class = dw_val_class_str;
7364 attr.dw_attr_val.v.val_str = node;
7365 add_dwarf_attr (die, &attr);
7368 /* Create a label for an indirect string node, ensuring it is going to
7369 be output, unless its reference count goes down to zero. */
7372 gen_label_for_indirect_string (struct indirect_string_node *node)
7379 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7380 ++dw2_string_counter;
7381 node->label = xstrdup (label);
7384 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7385 debug string STR. */
7388 get_debug_string_label (const char *str)
7390 struct indirect_string_node *node = find_AT_string (str);
7392 debug_str_hash_forced = true;
7394 gen_label_for_indirect_string (node);
7396 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7399 static inline const char *
7400 AT_string (dw_attr_ref a)
7402 gcc_assert (a && AT_class (a) == dw_val_class_str);
7403 return a->dw_attr_val.v.val_str->str;
7406 /* Find out whether a string should be output inline in DIE
7407 or out-of-line in .debug_str section. */
7409 static enum dwarf_form
7410 AT_string_form (dw_attr_ref a)
7412 struct indirect_string_node *node;
7415 gcc_assert (a && AT_class (a) == dw_val_class_str);
7417 node = a->dw_attr_val.v.val_str;
7421 len = strlen (node->str) + 1;
7423 /* If the string is shorter or equal to the size of the reference, it is
7424 always better to put it inline. */
7425 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7426 return node->form = DW_FORM_string;
7428 /* If we cannot expect the linker to merge strings in .debug_str
7429 section, only put it into .debug_str if it is worth even in this
7431 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7432 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7433 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7434 return node->form = DW_FORM_string;
7436 gen_label_for_indirect_string (node);
7438 return node->form = DW_FORM_strp;
7441 /* Add a DIE reference attribute value to a DIE. */
7444 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7448 #ifdef ENABLE_CHECKING
7449 gcc_assert (targ_die != NULL);
7451 /* With LTO we can end up trying to reference something we didn't create
7452 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7453 if (targ_die == NULL)
7457 attr.dw_attr = attr_kind;
7458 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7459 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7460 attr.dw_attr_val.v.val_die_ref.external = 0;
7461 add_dwarf_attr (die, &attr);
7464 /* Add an AT_specification attribute to a DIE, and also make the back
7465 pointer from the specification to the definition. */
7468 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7470 add_AT_die_ref (die, DW_AT_specification, targ_die);
7471 gcc_assert (!targ_die->die_definition);
7472 targ_die->die_definition = die;
7475 static inline dw_die_ref
7476 AT_ref (dw_attr_ref a)
7478 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7479 return a->dw_attr_val.v.val_die_ref.die;
7483 AT_ref_external (dw_attr_ref a)
7485 if (a && AT_class (a) == dw_val_class_die_ref)
7486 return a->dw_attr_val.v.val_die_ref.external;
7492 set_AT_ref_external (dw_attr_ref a, int i)
7494 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7495 a->dw_attr_val.v.val_die_ref.external = i;
7498 /* Add an FDE reference attribute value to a DIE. */
7501 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7505 attr.dw_attr = attr_kind;
7506 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7507 attr.dw_attr_val.v.val_fde_index = targ_fde;
7508 add_dwarf_attr (die, &attr);
7511 /* Add a location description attribute value to a DIE. */
7514 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7518 attr.dw_attr = attr_kind;
7519 attr.dw_attr_val.val_class = dw_val_class_loc;
7520 attr.dw_attr_val.v.val_loc = loc;
7521 add_dwarf_attr (die, &attr);
7524 static inline dw_loc_descr_ref
7525 AT_loc (dw_attr_ref a)
7527 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7528 return a->dw_attr_val.v.val_loc;
7532 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7536 attr.dw_attr = attr_kind;
7537 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7538 attr.dw_attr_val.v.val_loc_list = loc_list;
7539 add_dwarf_attr (die, &attr);
7540 have_location_lists = true;
7543 static inline dw_loc_list_ref
7544 AT_loc_list (dw_attr_ref a)
7546 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7547 return a->dw_attr_val.v.val_loc_list;
7550 static inline dw_loc_list_ref *
7551 AT_loc_list_ptr (dw_attr_ref a)
7553 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7554 return &a->dw_attr_val.v.val_loc_list;
7557 /* Add an address constant attribute value to a DIE. */
7560 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7564 attr.dw_attr = attr_kind;
7565 attr.dw_attr_val.val_class = dw_val_class_addr;
7566 attr.dw_attr_val.v.val_addr = addr;
7567 add_dwarf_attr (die, &attr);
7570 /* Get the RTX from to an address DIE attribute. */
7573 AT_addr (dw_attr_ref a)
7575 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7576 return a->dw_attr_val.v.val_addr;
7579 /* Add a file attribute value to a DIE. */
7582 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7583 struct dwarf_file_data *fd)
7587 attr.dw_attr = attr_kind;
7588 attr.dw_attr_val.val_class = dw_val_class_file;
7589 attr.dw_attr_val.v.val_file = fd;
7590 add_dwarf_attr (die, &attr);
7593 /* Get the dwarf_file_data from a file DIE attribute. */
7595 static inline struct dwarf_file_data *
7596 AT_file (dw_attr_ref a)
7598 gcc_assert (a && AT_class (a) == dw_val_class_file);
7599 return a->dw_attr_val.v.val_file;
7602 /* Add a vms delta attribute value to a DIE. */
7605 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7606 const char *lbl1, const char *lbl2)
7610 attr.dw_attr = attr_kind;
7611 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7612 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7613 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7614 add_dwarf_attr (die, &attr);
7617 /* Add a label identifier attribute value to a DIE. */
7620 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7624 attr.dw_attr = attr_kind;
7625 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7626 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7627 add_dwarf_attr (die, &attr);
7630 /* Add a section offset attribute value to a DIE, an offset into the
7631 debug_line section. */
7634 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7639 attr.dw_attr = attr_kind;
7640 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7641 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7642 add_dwarf_attr (die, &attr);
7645 /* Add a section offset attribute value to a DIE, an offset into the
7646 debug_macinfo section. */
7649 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7654 attr.dw_attr = attr_kind;
7655 attr.dw_attr_val.val_class = dw_val_class_macptr;
7656 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7657 add_dwarf_attr (die, &attr);
7660 /* Add an offset attribute value to a DIE. */
7663 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7664 unsigned HOST_WIDE_INT offset)
7668 attr.dw_attr = attr_kind;
7669 attr.dw_attr_val.val_class = dw_val_class_offset;
7670 attr.dw_attr_val.v.val_offset = offset;
7671 add_dwarf_attr (die, &attr);
7674 /* Add an range_list attribute value to a DIE. */
7677 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7678 long unsigned int offset)
7682 attr.dw_attr = attr_kind;
7683 attr.dw_attr_val.val_class = dw_val_class_range_list;
7684 attr.dw_attr_val.v.val_offset = offset;
7685 add_dwarf_attr (die, &attr);
7688 /* Return the start label of a delta attribute. */
7690 static inline const char *
7691 AT_vms_delta1 (dw_attr_ref a)
7693 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7694 return a->dw_attr_val.v.val_vms_delta.lbl1;
7697 /* Return the end label of a delta attribute. */
7699 static inline const char *
7700 AT_vms_delta2 (dw_attr_ref a)
7702 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7703 return a->dw_attr_val.v.val_vms_delta.lbl2;
7706 static inline const char *
7707 AT_lbl (dw_attr_ref a)
7709 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7710 || AT_class (a) == dw_val_class_lineptr
7711 || AT_class (a) == dw_val_class_macptr));
7712 return a->dw_attr_val.v.val_lbl_id;
7715 /* Get the attribute of type attr_kind. */
7718 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7722 dw_die_ref spec = NULL;
7727 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7728 if (a->dw_attr == attr_kind)
7730 else if (a->dw_attr == DW_AT_specification
7731 || a->dw_attr == DW_AT_abstract_origin)
7735 return get_AT (spec, attr_kind);
7740 /* Return the "low pc" attribute value, typically associated with a subprogram
7741 DIE. Return null if the "low pc" attribute is either not present, or if it
7742 cannot be represented as an assembler label identifier. */
7744 static inline const char *
7745 get_AT_low_pc (dw_die_ref die)
7747 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7749 return a ? AT_lbl (a) : NULL;
7752 /* Return the "high pc" attribute value, typically associated with a subprogram
7753 DIE. Return null if the "high pc" attribute is either not present, or if it
7754 cannot be represented as an assembler label identifier. */
7756 static inline const char *
7757 get_AT_hi_pc (dw_die_ref die)
7759 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7761 return a ? AT_lbl (a) : NULL;
7764 /* Return the value of the string attribute designated by ATTR_KIND, or
7765 NULL if it is not present. */
7767 static inline const char *
7768 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7770 dw_attr_ref a = get_AT (die, attr_kind);
7772 return a ? AT_string (a) : NULL;
7775 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7776 if it is not present. */
7779 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7781 dw_attr_ref a = get_AT (die, attr_kind);
7783 return a ? AT_flag (a) : 0;
7786 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7787 if it is not present. */
7789 static inline unsigned
7790 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7792 dw_attr_ref a = get_AT (die, attr_kind);
7794 return a ? AT_unsigned (a) : 0;
7797 static inline dw_die_ref
7798 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7800 dw_attr_ref a = get_AT (die, attr_kind);
7802 return a ? AT_ref (a) : NULL;
7805 static inline struct dwarf_file_data *
7806 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7808 dw_attr_ref a = get_AT (die, attr_kind);
7810 return a ? AT_file (a) : NULL;
7813 /* Return TRUE if the language is C++. */
7818 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7820 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7823 /* Return TRUE if the language is Fortran. */
7828 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7830 return (lang == DW_LANG_Fortran77
7831 || lang == DW_LANG_Fortran90
7832 || lang == DW_LANG_Fortran95);
7835 /* Return TRUE if the language is Ada. */
7840 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7842 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7845 /* Remove the specified attribute if present. */
7848 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7856 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7857 if (a->dw_attr == attr_kind)
7859 if (AT_class (a) == dw_val_class_str)
7860 if (a->dw_attr_val.v.val_str->refcount)
7861 a->dw_attr_val.v.val_str->refcount--;
7863 /* VEC_ordered_remove should help reduce the number of abbrevs
7865 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7870 /* Remove CHILD from its parent. PREV must have the property that
7871 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7874 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7876 gcc_assert (child->die_parent == prev->die_parent);
7877 gcc_assert (prev->die_sib == child);
7880 gcc_assert (child->die_parent->die_child == child);
7884 prev->die_sib = child->die_sib;
7885 if (child->die_parent->die_child == child)
7886 child->die_parent->die_child = prev;
7889 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7890 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7893 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7895 dw_die_ref parent = old_child->die_parent;
7897 gcc_assert (parent == prev->die_parent);
7898 gcc_assert (prev->die_sib == old_child);
7900 new_child->die_parent = parent;
7901 if (prev == old_child)
7903 gcc_assert (parent->die_child == old_child);
7904 new_child->die_sib = new_child;
7908 prev->die_sib = new_child;
7909 new_child->die_sib = old_child->die_sib;
7911 if (old_child->die_parent->die_child == old_child)
7912 old_child->die_parent->die_child = new_child;
7915 /* Move all children from OLD_PARENT to NEW_PARENT. */
7918 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7921 new_parent->die_child = old_parent->die_child;
7922 old_parent->die_child = NULL;
7923 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7926 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7930 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7936 dw_die_ref prev = c;
7938 while (c->die_tag == tag)
7940 remove_child_with_prev (c, prev);
7941 /* Might have removed every child. */
7942 if (c == c->die_sib)
7946 } while (c != die->die_child);
7949 /* Add a CHILD_DIE as the last child of DIE. */
7952 add_child_die (dw_die_ref die, dw_die_ref child_die)
7954 /* FIXME this should probably be an assert. */
7955 if (! die || ! child_die)
7957 gcc_assert (die != child_die);
7959 child_die->die_parent = die;
7962 child_die->die_sib = die->die_child->die_sib;
7963 die->die_child->die_sib = child_die;
7966 child_die->die_sib = child_die;
7967 die->die_child = child_die;
7970 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7971 is the specification, to the end of PARENT's list of children.
7972 This is done by removing and re-adding it. */
7975 splice_child_die (dw_die_ref parent, dw_die_ref child)
7979 /* We want the declaration DIE from inside the class, not the
7980 specification DIE at toplevel. */
7981 if (child->die_parent != parent)
7983 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7989 gcc_assert (child->die_parent == parent
7990 || (child->die_parent
7991 == get_AT_ref (parent, DW_AT_specification)));
7993 for (p = child->die_parent->die_child; ; p = p->die_sib)
7994 if (p->die_sib == child)
7996 remove_child_with_prev (child, p);
8000 add_child_die (parent, child);
8003 /* Return a pointer to a newly created DIE node. */
8005 static inline dw_die_ref
8006 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8008 dw_die_ref die = ggc_alloc_cleared_die_node ();
8010 die->die_tag = tag_value;
8012 if (parent_die != NULL)
8013 add_child_die (parent_die, die);
8016 limbo_die_node *limbo_node;
8018 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8019 limbo_node->die = die;
8020 limbo_node->created_for = t;
8021 limbo_node->next = limbo_die_list;
8022 limbo_die_list = limbo_node;
8028 /* Return the DIE associated with the given type specifier. */
8030 static inline dw_die_ref
8031 lookup_type_die (tree type)
8033 return TYPE_SYMTAB_DIE (type);
8036 /* Equate a DIE to a given type specifier. */
8039 equate_type_number_to_die (tree type, dw_die_ref type_die)
8041 TYPE_SYMTAB_DIE (type) = type_die;
8044 /* Returns a hash value for X (which really is a die_struct). */
8047 decl_die_table_hash (const void *x)
8049 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8052 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8055 decl_die_table_eq (const void *x, const void *y)
8057 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8060 /* Return the DIE associated with a given declaration. */
8062 static inline dw_die_ref
8063 lookup_decl_die (tree decl)
8065 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8068 /* Returns a hash value for X (which really is a var_loc_list). */
8071 decl_loc_table_hash (const void *x)
8073 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8076 /* Return nonzero if decl_id of var_loc_list X is the same as
8080 decl_loc_table_eq (const void *x, const void *y)
8082 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8085 /* Return the var_loc list associated with a given declaration. */
8087 static inline var_loc_list *
8088 lookup_decl_loc (const_tree decl)
8090 if (!decl_loc_table)
8092 return (var_loc_list *)
8093 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8096 /* Equate a DIE to a particular declaration. */
8099 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8101 unsigned int decl_id = DECL_UID (decl);
8104 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8106 decl_die->decl_id = decl_id;
8109 /* Return how many bits covers PIECE EXPR_LIST. */
8112 decl_piece_bitsize (rtx piece)
8114 int ret = (int) GET_MODE (piece);
8117 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8118 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8119 return INTVAL (XEXP (XEXP (piece, 0), 0));
8122 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8125 decl_piece_varloc_ptr (rtx piece)
8127 if ((int) GET_MODE (piece))
8128 return &XEXP (piece, 0);
8130 return &XEXP (XEXP (piece, 0), 1);
8133 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8134 Next is the chain of following piece nodes. */
8137 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8139 if (bitsize <= (int) MAX_MACHINE_MODE)
8140 return alloc_EXPR_LIST (bitsize, loc_note, next);
8142 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8147 /* Return rtx that should be stored into loc field for
8148 LOC_NOTE and BITPOS/BITSIZE. */
8151 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8152 HOST_WIDE_INT bitsize)
8156 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8158 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8163 /* This function either modifies location piece list *DEST in
8164 place (if SRC and INNER is NULL), or copies location piece list
8165 *SRC to *DEST while modifying it. Location BITPOS is modified
8166 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8167 not copied and if needed some padding around it is added.
8168 When modifying in place, DEST should point to EXPR_LIST where
8169 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8170 to the start of the whole list and INNER points to the EXPR_LIST
8171 where earlier pieces cover PIECE_BITPOS bits. */
8174 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8175 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8176 HOST_WIDE_INT bitsize, rtx loc_note)
8179 bool copy = inner != NULL;
8183 /* First copy all nodes preceeding the current bitpos. */
8184 while (src != inner)
8186 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8187 decl_piece_bitsize (*src), NULL_RTX);
8188 dest = &XEXP (*dest, 1);
8189 src = &XEXP (*src, 1);
8192 /* Add padding if needed. */
8193 if (bitpos != piece_bitpos)
8195 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8196 copy ? NULL_RTX : *dest);
8197 dest = &XEXP (*dest, 1);
8199 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8202 /* A piece with correct bitpos and bitsize already exist,
8203 just update the location for it and return. */
8204 *decl_piece_varloc_ptr (*dest) = loc_note;
8207 /* Add the piece that changed. */
8208 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8209 dest = &XEXP (*dest, 1);
8210 /* Skip over pieces that overlap it. */
8211 diff = bitpos - piece_bitpos + bitsize;
8214 while (diff > 0 && *src)
8217 diff -= decl_piece_bitsize (piece);
8219 src = &XEXP (piece, 1);
8222 *src = XEXP (piece, 1);
8223 free_EXPR_LIST_node (piece);
8226 /* Add padding if needed. */
8227 if (diff < 0 && *src)
8231 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8232 dest = &XEXP (*dest, 1);
8236 /* Finally copy all nodes following it. */
8239 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8240 decl_piece_bitsize (*src), NULL_RTX);
8241 dest = &XEXP (*dest, 1);
8242 src = &XEXP (*src, 1);
8246 /* Add a variable location node to the linked list for DECL. */
8248 static struct var_loc_node *
8249 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8251 unsigned int decl_id;
8254 struct var_loc_node *loc = NULL;
8255 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8257 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8259 tree realdecl = DECL_DEBUG_EXPR (decl);
8260 if (realdecl && handled_component_p (realdecl))
8262 HOST_WIDE_INT maxsize;
8265 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8266 if (!DECL_P (innerdecl)
8267 || DECL_IGNORED_P (innerdecl)
8268 || TREE_STATIC (innerdecl)
8270 || bitpos + bitsize > 256
8271 || bitsize != maxsize)
8277 decl_id = DECL_UID (decl);
8278 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8281 temp = ggc_alloc_cleared_var_loc_list ();
8282 temp->decl_id = decl_id;
8286 temp = (var_loc_list *) *slot;
8290 struct var_loc_node *last = temp->last, *unused = NULL;
8291 rtx *piece_loc = NULL, last_loc_note;
8292 int piece_bitpos = 0;
8296 gcc_assert (last->next == NULL);
8298 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8300 piece_loc = &last->loc;
8303 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8304 if (piece_bitpos + cur_bitsize > bitpos)
8306 piece_bitpos += cur_bitsize;
8307 piece_loc = &XEXP (*piece_loc, 1);
8311 /* TEMP->LAST here is either pointer to the last but one or
8312 last element in the chained list, LAST is pointer to the
8314 if (label && strcmp (last->label, label) == 0)
8316 /* For SRA optimized variables if there weren't any real
8317 insns since last note, just modify the last node. */
8318 if (piece_loc != NULL)
8320 adjust_piece_list (piece_loc, NULL, NULL,
8321 bitpos, piece_bitpos, bitsize, loc_note);
8324 /* If the last note doesn't cover any instructions, remove it. */
8325 if (temp->last != last)
8327 temp->last->next = NULL;
8330 gcc_assert (strcmp (last->label, label) != 0);
8334 gcc_assert (temp->first == temp->last);
8335 memset (temp->last, '\0', sizeof (*temp->last));
8336 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8340 if (bitsize == -1 && NOTE_P (last->loc))
8341 last_loc_note = last->loc;
8342 else if (piece_loc != NULL
8343 && *piece_loc != NULL_RTX
8344 && piece_bitpos == bitpos
8345 && decl_piece_bitsize (*piece_loc) == bitsize)
8346 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8348 last_loc_note = NULL_RTX;
8349 /* If the current location is the same as the end of the list,
8350 and either both or neither of the locations is uninitialized,
8351 we have nothing to do. */
8352 if (last_loc_note == NULL_RTX
8353 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8354 NOTE_VAR_LOCATION_LOC (loc_note)))
8355 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8356 != NOTE_VAR_LOCATION_STATUS (loc_note))
8357 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8358 == VAR_INIT_STATUS_UNINITIALIZED)
8359 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8360 == VAR_INIT_STATUS_UNINITIALIZED))))
8362 /* Add LOC to the end of list and update LAST. If the last
8363 element of the list has been removed above, reuse its
8364 memory for the new node, otherwise allocate a new one. */
8368 memset (loc, '\0', sizeof (*loc));
8371 loc = ggc_alloc_cleared_var_loc_node ();
8372 if (bitsize == -1 || piece_loc == NULL)
8373 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8375 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8376 bitpos, piece_bitpos, bitsize, loc_note);
8378 /* Ensure TEMP->LAST will point either to the new last but one
8379 element of the chain, or to the last element in it. */
8380 if (last != temp->last)
8388 loc = ggc_alloc_cleared_var_loc_node ();
8391 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8396 /* Keep track of the number of spaces used to indent the
8397 output of the debugging routines that print the structure of
8398 the DIE internal representation. */
8399 static int print_indent;
8401 /* Indent the line the number of spaces given by print_indent. */
8404 print_spaces (FILE *outfile)
8406 fprintf (outfile, "%*s", print_indent, "");
8409 /* Print a type signature in hex. */
8412 print_signature (FILE *outfile, char *sig)
8416 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8417 fprintf (outfile, "%02x", sig[i] & 0xff);
8420 /* Print the information associated with a given DIE, and its children.
8421 This routine is a debugging aid only. */
8424 print_die (dw_die_ref die, FILE *outfile)
8430 print_spaces (outfile);
8431 fprintf (outfile, "DIE %4ld: %s\n",
8432 die->die_offset, dwarf_tag_name (die->die_tag));
8433 print_spaces (outfile);
8434 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8435 fprintf (outfile, " offset: %ld\n", die->die_offset);
8436 if (dwarf_version >= 4 && die->die_id.die_type_node)
8438 print_spaces (outfile);
8439 fprintf (outfile, " signature: ");
8440 print_signature (outfile, die->die_id.die_type_node->signature);
8441 fprintf (outfile, "\n");
8444 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8446 print_spaces (outfile);
8447 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8449 switch (AT_class (a))
8451 case dw_val_class_addr:
8452 fprintf (outfile, "address");
8454 case dw_val_class_offset:
8455 fprintf (outfile, "offset");
8457 case dw_val_class_loc:
8458 fprintf (outfile, "location descriptor");
8460 case dw_val_class_loc_list:
8461 fprintf (outfile, "location list -> label:%s",
8462 AT_loc_list (a)->ll_symbol);
8464 case dw_val_class_range_list:
8465 fprintf (outfile, "range list");
8467 case dw_val_class_const:
8468 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8470 case dw_val_class_unsigned_const:
8471 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8473 case dw_val_class_const_double:
8474 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8475 HOST_WIDE_INT_PRINT_UNSIGNED")",
8476 a->dw_attr_val.v.val_double.high,
8477 a->dw_attr_val.v.val_double.low);
8479 case dw_val_class_vec:
8480 fprintf (outfile, "floating-point or vector constant");
8482 case dw_val_class_flag:
8483 fprintf (outfile, "%u", AT_flag (a));
8485 case dw_val_class_die_ref:
8486 if (AT_ref (a) != NULL)
8488 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8490 fprintf (outfile, "die -> signature: ");
8491 print_signature (outfile,
8492 AT_ref (a)->die_id.die_type_node->signature);
8494 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8495 fprintf (outfile, "die -> label: %s",
8496 AT_ref (a)->die_id.die_symbol);
8498 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8501 fprintf (outfile, "die -> <null>");
8503 case dw_val_class_vms_delta:
8504 fprintf (outfile, "delta: @slotcount(%s-%s)",
8505 AT_vms_delta2 (a), AT_vms_delta1 (a));
8507 case dw_val_class_lbl_id:
8508 case dw_val_class_lineptr:
8509 case dw_val_class_macptr:
8510 fprintf (outfile, "label: %s", AT_lbl (a));
8512 case dw_val_class_str:
8513 if (AT_string (a) != NULL)
8514 fprintf (outfile, "\"%s\"", AT_string (a));
8516 fprintf (outfile, "<null>");
8518 case dw_val_class_file:
8519 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8520 AT_file (a)->emitted_number);
8522 case dw_val_class_data8:
8526 for (i = 0; i < 8; i++)
8527 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8534 fprintf (outfile, "\n");
8537 if (die->die_child != NULL)
8540 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8543 if (print_indent == 0)
8544 fprintf (outfile, "\n");
8547 /* Print the contents of the source code line number correspondence table.
8548 This routine is a debugging aid only. */
8551 print_dwarf_line_table (FILE *outfile)
8554 dw_line_info_ref line_info;
8556 fprintf (outfile, "\n\nDWARF source line information\n");
8557 for (i = 1; i < line_info_table_in_use; i++)
8559 line_info = &line_info_table[i];
8560 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8561 line_info->dw_file_num,
8562 line_info->dw_line_num);
8565 fprintf (outfile, "\n\n");
8568 /* Print the information collected for a given DIE. */
8571 debug_dwarf_die (dw_die_ref die)
8573 print_die (die, stderr);
8576 /* Print all DWARF information collected for the compilation unit.
8577 This routine is a debugging aid only. */
8583 print_die (comp_unit_die (), stderr);
8584 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8585 print_dwarf_line_table (stderr);
8588 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8589 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8590 DIE that marks the start of the DIEs for this include file. */
8593 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8595 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8596 dw_die_ref new_unit = gen_compile_unit_die (filename);
8598 new_unit->die_sib = old_unit;
8602 /* Close an include-file CU and reopen the enclosing one. */
8605 pop_compile_unit (dw_die_ref old_unit)
8607 dw_die_ref new_unit = old_unit->die_sib;
8609 old_unit->die_sib = NULL;
8613 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8614 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8616 /* Calculate the checksum of a location expression. */
8619 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8623 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8625 CHECKSUM (loc->dw_loc_oprnd1);
8626 CHECKSUM (loc->dw_loc_oprnd2);
8629 /* Calculate the checksum of an attribute. */
8632 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8634 dw_loc_descr_ref loc;
8637 CHECKSUM (at->dw_attr);
8639 /* We don't care that this was compiled with a different compiler
8640 snapshot; if the output is the same, that's what matters. */
8641 if (at->dw_attr == DW_AT_producer)
8644 switch (AT_class (at))
8646 case dw_val_class_const:
8647 CHECKSUM (at->dw_attr_val.v.val_int);
8649 case dw_val_class_unsigned_const:
8650 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8652 case dw_val_class_const_double:
8653 CHECKSUM (at->dw_attr_val.v.val_double);
8655 case dw_val_class_vec:
8656 CHECKSUM (at->dw_attr_val.v.val_vec);
8658 case dw_val_class_flag:
8659 CHECKSUM (at->dw_attr_val.v.val_flag);
8661 case dw_val_class_str:
8662 CHECKSUM_STRING (AT_string (at));
8665 case dw_val_class_addr:
8667 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8668 CHECKSUM_STRING (XSTR (r, 0));
8671 case dw_val_class_offset:
8672 CHECKSUM (at->dw_attr_val.v.val_offset);
8675 case dw_val_class_loc:
8676 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8677 loc_checksum (loc, ctx);
8680 case dw_val_class_die_ref:
8681 die_checksum (AT_ref (at), ctx, mark);
8684 case dw_val_class_fde_ref:
8685 case dw_val_class_vms_delta:
8686 case dw_val_class_lbl_id:
8687 case dw_val_class_lineptr:
8688 case dw_val_class_macptr:
8691 case dw_val_class_file:
8692 CHECKSUM_STRING (AT_file (at)->filename);
8695 case dw_val_class_data8:
8696 CHECKSUM (at->dw_attr_val.v.val_data8);
8704 /* Calculate the checksum of a DIE. */
8707 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8713 /* To avoid infinite recursion. */
8716 CHECKSUM (die->die_mark);
8719 die->die_mark = ++(*mark);
8721 CHECKSUM (die->die_tag);
8723 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8724 attr_checksum (a, ctx, mark);
8726 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8730 #undef CHECKSUM_STRING
8732 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8733 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8734 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8735 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8736 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8737 #define CHECKSUM_ATTR(FOO) \
8738 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8740 /* Calculate the checksum of a number in signed LEB128 format. */
8743 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8750 byte = (value & 0x7f);
8752 more = !((value == 0 && (byte & 0x40) == 0)
8753 || (value == -1 && (byte & 0x40) != 0));
8762 /* Calculate the checksum of a number in unsigned LEB128 format. */
8765 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8769 unsigned char byte = (value & 0x7f);
8772 /* More bytes to follow. */
8780 /* Checksum the context of the DIE. This adds the names of any
8781 surrounding namespaces or structures to the checksum. */
8784 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8788 int tag = die->die_tag;
8790 if (tag != DW_TAG_namespace
8791 && tag != DW_TAG_structure_type
8792 && tag != DW_TAG_class_type)
8795 name = get_AT_string (die, DW_AT_name);
8797 spec = get_AT_ref (die, DW_AT_specification);
8801 if (die->die_parent != NULL)
8802 checksum_die_context (die->die_parent, ctx);
8804 CHECKSUM_ULEB128 ('C');
8805 CHECKSUM_ULEB128 (tag);
8807 CHECKSUM_STRING (name);
8810 /* Calculate the checksum of a location expression. */
8813 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8815 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8816 were emitted as a DW_FORM_sdata instead of a location expression. */
8817 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8819 CHECKSUM_ULEB128 (DW_FORM_sdata);
8820 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8824 /* Otherwise, just checksum the raw location expression. */
8827 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8828 CHECKSUM (loc->dw_loc_oprnd1);
8829 CHECKSUM (loc->dw_loc_oprnd2);
8830 loc = loc->dw_loc_next;
8834 /* Calculate the checksum of an attribute. */
8837 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8838 struct md5_ctx *ctx, int *mark)
8840 dw_loc_descr_ref loc;
8843 if (AT_class (at) == dw_val_class_die_ref)
8845 dw_die_ref target_die = AT_ref (at);
8847 /* For pointer and reference types, we checksum only the (qualified)
8848 name of the target type (if there is a name). For friend entries,
8849 we checksum only the (qualified) name of the target type or function.
8850 This allows the checksum to remain the same whether the target type
8851 is complete or not. */
8852 if ((at->dw_attr == DW_AT_type
8853 && (tag == DW_TAG_pointer_type
8854 || tag == DW_TAG_reference_type
8855 || tag == DW_TAG_rvalue_reference_type
8856 || tag == DW_TAG_ptr_to_member_type))
8857 || (at->dw_attr == DW_AT_friend
8858 && tag == DW_TAG_friend))
8860 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8862 if (name_attr != NULL)
8864 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8868 CHECKSUM_ULEB128 ('N');
8869 CHECKSUM_ULEB128 (at->dw_attr);
8870 if (decl->die_parent != NULL)
8871 checksum_die_context (decl->die_parent, ctx);
8872 CHECKSUM_ULEB128 ('E');
8873 CHECKSUM_STRING (AT_string (name_attr));
8878 /* For all other references to another DIE, we check to see if the
8879 target DIE has already been visited. If it has, we emit a
8880 backward reference; if not, we descend recursively. */
8881 if (target_die->die_mark > 0)
8883 CHECKSUM_ULEB128 ('R');
8884 CHECKSUM_ULEB128 (at->dw_attr);
8885 CHECKSUM_ULEB128 (target_die->die_mark);
8889 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8893 target_die->die_mark = ++(*mark);
8894 CHECKSUM_ULEB128 ('T');
8895 CHECKSUM_ULEB128 (at->dw_attr);
8896 if (decl->die_parent != NULL)
8897 checksum_die_context (decl->die_parent, ctx);
8898 die_checksum_ordered (target_die, ctx, mark);
8903 CHECKSUM_ULEB128 ('A');
8904 CHECKSUM_ULEB128 (at->dw_attr);
8906 switch (AT_class (at))
8908 case dw_val_class_const:
8909 CHECKSUM_ULEB128 (DW_FORM_sdata);
8910 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
8913 case dw_val_class_unsigned_const:
8914 CHECKSUM_ULEB128 (DW_FORM_sdata);
8915 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
8918 case dw_val_class_const_double:
8919 CHECKSUM_ULEB128 (DW_FORM_block);
8920 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
8921 CHECKSUM (at->dw_attr_val.v.val_double);
8924 case dw_val_class_vec:
8925 CHECKSUM_ULEB128 (DW_FORM_block);
8926 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
8927 CHECKSUM (at->dw_attr_val.v.val_vec);
8930 case dw_val_class_flag:
8931 CHECKSUM_ULEB128 (DW_FORM_flag);
8932 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
8935 case dw_val_class_str:
8936 CHECKSUM_ULEB128 (DW_FORM_string);
8937 CHECKSUM_STRING (AT_string (at));
8940 case dw_val_class_addr:
8942 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8943 CHECKSUM_ULEB128 (DW_FORM_string);
8944 CHECKSUM_STRING (XSTR (r, 0));
8947 case dw_val_class_offset:
8948 CHECKSUM_ULEB128 (DW_FORM_sdata);
8949 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
8952 case dw_val_class_loc:
8953 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8954 loc_checksum_ordered (loc, ctx);
8957 case dw_val_class_fde_ref:
8958 case dw_val_class_lbl_id:
8959 case dw_val_class_lineptr:
8960 case dw_val_class_macptr:
8963 case dw_val_class_file:
8964 CHECKSUM_ULEB128 (DW_FORM_string);
8965 CHECKSUM_STRING (AT_file (at)->filename);
8968 case dw_val_class_data8:
8969 CHECKSUM (at->dw_attr_val.v.val_data8);
8977 struct checksum_attributes
8979 dw_attr_ref at_name;
8980 dw_attr_ref at_type;
8981 dw_attr_ref at_friend;
8982 dw_attr_ref at_accessibility;
8983 dw_attr_ref at_address_class;
8984 dw_attr_ref at_allocated;
8985 dw_attr_ref at_artificial;
8986 dw_attr_ref at_associated;
8987 dw_attr_ref at_binary_scale;
8988 dw_attr_ref at_bit_offset;
8989 dw_attr_ref at_bit_size;
8990 dw_attr_ref at_bit_stride;
8991 dw_attr_ref at_byte_size;
8992 dw_attr_ref at_byte_stride;
8993 dw_attr_ref at_const_value;
8994 dw_attr_ref at_containing_type;
8995 dw_attr_ref at_count;
8996 dw_attr_ref at_data_location;
8997 dw_attr_ref at_data_member_location;
8998 dw_attr_ref at_decimal_scale;
8999 dw_attr_ref at_decimal_sign;
9000 dw_attr_ref at_default_value;
9001 dw_attr_ref at_digit_count;
9002 dw_attr_ref at_discr;
9003 dw_attr_ref at_discr_list;
9004 dw_attr_ref at_discr_value;
9005 dw_attr_ref at_encoding;
9006 dw_attr_ref at_endianity;
9007 dw_attr_ref at_explicit;
9008 dw_attr_ref at_is_optional;
9009 dw_attr_ref at_location;
9010 dw_attr_ref at_lower_bound;
9011 dw_attr_ref at_mutable;
9012 dw_attr_ref at_ordering;
9013 dw_attr_ref at_picture_string;
9014 dw_attr_ref at_prototyped;
9015 dw_attr_ref at_small;
9016 dw_attr_ref at_segment;
9017 dw_attr_ref at_string_length;
9018 dw_attr_ref at_threads_scaled;
9019 dw_attr_ref at_upper_bound;
9020 dw_attr_ref at_use_location;
9021 dw_attr_ref at_use_UTF8;
9022 dw_attr_ref at_variable_parameter;
9023 dw_attr_ref at_virtuality;
9024 dw_attr_ref at_visibility;
9025 dw_attr_ref at_vtable_elem_location;
9028 /* Collect the attributes that we will want to use for the checksum. */
9031 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9036 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9047 attrs->at_friend = a;
9049 case DW_AT_accessibility:
9050 attrs->at_accessibility = a;
9052 case DW_AT_address_class:
9053 attrs->at_address_class = a;
9055 case DW_AT_allocated:
9056 attrs->at_allocated = a;
9058 case DW_AT_artificial:
9059 attrs->at_artificial = a;
9061 case DW_AT_associated:
9062 attrs->at_associated = a;
9064 case DW_AT_binary_scale:
9065 attrs->at_binary_scale = a;
9067 case DW_AT_bit_offset:
9068 attrs->at_bit_offset = a;
9070 case DW_AT_bit_size:
9071 attrs->at_bit_size = a;
9073 case DW_AT_bit_stride:
9074 attrs->at_bit_stride = a;
9076 case DW_AT_byte_size:
9077 attrs->at_byte_size = a;
9079 case DW_AT_byte_stride:
9080 attrs->at_byte_stride = a;
9082 case DW_AT_const_value:
9083 attrs->at_const_value = a;
9085 case DW_AT_containing_type:
9086 attrs->at_containing_type = a;
9089 attrs->at_count = a;
9091 case DW_AT_data_location:
9092 attrs->at_data_location = a;
9094 case DW_AT_data_member_location:
9095 attrs->at_data_member_location = a;
9097 case DW_AT_decimal_scale:
9098 attrs->at_decimal_scale = a;
9100 case DW_AT_decimal_sign:
9101 attrs->at_decimal_sign = a;
9103 case DW_AT_default_value:
9104 attrs->at_default_value = a;
9106 case DW_AT_digit_count:
9107 attrs->at_digit_count = a;
9110 attrs->at_discr = a;
9112 case DW_AT_discr_list:
9113 attrs->at_discr_list = a;
9115 case DW_AT_discr_value:
9116 attrs->at_discr_value = a;
9118 case DW_AT_encoding:
9119 attrs->at_encoding = a;
9121 case DW_AT_endianity:
9122 attrs->at_endianity = a;
9124 case DW_AT_explicit:
9125 attrs->at_explicit = a;
9127 case DW_AT_is_optional:
9128 attrs->at_is_optional = a;
9130 case DW_AT_location:
9131 attrs->at_location = a;
9133 case DW_AT_lower_bound:
9134 attrs->at_lower_bound = a;
9137 attrs->at_mutable = a;
9139 case DW_AT_ordering:
9140 attrs->at_ordering = a;
9142 case DW_AT_picture_string:
9143 attrs->at_picture_string = a;
9145 case DW_AT_prototyped:
9146 attrs->at_prototyped = a;
9149 attrs->at_small = a;
9152 attrs->at_segment = a;
9154 case DW_AT_string_length:
9155 attrs->at_string_length = a;
9157 case DW_AT_threads_scaled:
9158 attrs->at_threads_scaled = a;
9160 case DW_AT_upper_bound:
9161 attrs->at_upper_bound = a;
9163 case DW_AT_use_location:
9164 attrs->at_use_location = a;
9166 case DW_AT_use_UTF8:
9167 attrs->at_use_UTF8 = a;
9169 case DW_AT_variable_parameter:
9170 attrs->at_variable_parameter = a;
9172 case DW_AT_virtuality:
9173 attrs->at_virtuality = a;
9175 case DW_AT_visibility:
9176 attrs->at_visibility = a;
9178 case DW_AT_vtable_elem_location:
9179 attrs->at_vtable_elem_location = a;
9187 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9190 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9194 struct checksum_attributes attrs;
9196 CHECKSUM_ULEB128 ('D');
9197 CHECKSUM_ULEB128 (die->die_tag);
9199 memset (&attrs, 0, sizeof (attrs));
9201 decl = get_AT_ref (die, DW_AT_specification);
9203 collect_checksum_attributes (&attrs, decl);
9204 collect_checksum_attributes (&attrs, die);
9206 CHECKSUM_ATTR (attrs.at_name);
9207 CHECKSUM_ATTR (attrs.at_accessibility);
9208 CHECKSUM_ATTR (attrs.at_address_class);
9209 CHECKSUM_ATTR (attrs.at_allocated);
9210 CHECKSUM_ATTR (attrs.at_artificial);
9211 CHECKSUM_ATTR (attrs.at_associated);
9212 CHECKSUM_ATTR (attrs.at_binary_scale);
9213 CHECKSUM_ATTR (attrs.at_bit_offset);
9214 CHECKSUM_ATTR (attrs.at_bit_size);
9215 CHECKSUM_ATTR (attrs.at_bit_stride);
9216 CHECKSUM_ATTR (attrs.at_byte_size);
9217 CHECKSUM_ATTR (attrs.at_byte_stride);
9218 CHECKSUM_ATTR (attrs.at_const_value);
9219 CHECKSUM_ATTR (attrs.at_containing_type);
9220 CHECKSUM_ATTR (attrs.at_count);
9221 CHECKSUM_ATTR (attrs.at_data_location);
9222 CHECKSUM_ATTR (attrs.at_data_member_location);
9223 CHECKSUM_ATTR (attrs.at_decimal_scale);
9224 CHECKSUM_ATTR (attrs.at_decimal_sign);
9225 CHECKSUM_ATTR (attrs.at_default_value);
9226 CHECKSUM_ATTR (attrs.at_digit_count);
9227 CHECKSUM_ATTR (attrs.at_discr);
9228 CHECKSUM_ATTR (attrs.at_discr_list);
9229 CHECKSUM_ATTR (attrs.at_discr_value);
9230 CHECKSUM_ATTR (attrs.at_encoding);
9231 CHECKSUM_ATTR (attrs.at_endianity);
9232 CHECKSUM_ATTR (attrs.at_explicit);
9233 CHECKSUM_ATTR (attrs.at_is_optional);
9234 CHECKSUM_ATTR (attrs.at_location);
9235 CHECKSUM_ATTR (attrs.at_lower_bound);
9236 CHECKSUM_ATTR (attrs.at_mutable);
9237 CHECKSUM_ATTR (attrs.at_ordering);
9238 CHECKSUM_ATTR (attrs.at_picture_string);
9239 CHECKSUM_ATTR (attrs.at_prototyped);
9240 CHECKSUM_ATTR (attrs.at_small);
9241 CHECKSUM_ATTR (attrs.at_segment);
9242 CHECKSUM_ATTR (attrs.at_string_length);
9243 CHECKSUM_ATTR (attrs.at_threads_scaled);
9244 CHECKSUM_ATTR (attrs.at_upper_bound);
9245 CHECKSUM_ATTR (attrs.at_use_location);
9246 CHECKSUM_ATTR (attrs.at_use_UTF8);
9247 CHECKSUM_ATTR (attrs.at_variable_parameter);
9248 CHECKSUM_ATTR (attrs.at_virtuality);
9249 CHECKSUM_ATTR (attrs.at_visibility);
9250 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9251 CHECKSUM_ATTR (attrs.at_type);
9252 CHECKSUM_ATTR (attrs.at_friend);
9254 /* Checksum the child DIEs, except for nested types and member functions. */
9257 dw_attr_ref name_attr;
9260 name_attr = get_AT (c, DW_AT_name);
9261 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9262 && name_attr != NULL)
9264 CHECKSUM_ULEB128 ('S');
9265 CHECKSUM_ULEB128 (c->die_tag);
9266 CHECKSUM_STRING (AT_string (name_attr));
9270 /* Mark this DIE so it gets processed when unmarking. */
9271 if (c->die_mark == 0)
9273 die_checksum_ordered (c, ctx, mark);
9275 } while (c != die->die_child);
9277 CHECKSUM_ULEB128 (0);
9281 #undef CHECKSUM_STRING
9282 #undef CHECKSUM_ATTR
9283 #undef CHECKSUM_LEB128
9284 #undef CHECKSUM_ULEB128
9286 /* Generate the type signature for DIE. This is computed by generating an
9287 MD5 checksum over the DIE's tag, its relevant attributes, and its
9288 children. Attributes that are references to other DIEs are processed
9289 by recursion, using the MARK field to prevent infinite recursion.
9290 If the DIE is nested inside a namespace or another type, we also
9291 need to include that context in the signature. The lower 64 bits
9292 of the resulting MD5 checksum comprise the signature. */
9295 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9299 unsigned char checksum[16];
9303 name = get_AT_string (die, DW_AT_name);
9304 decl = get_AT_ref (die, DW_AT_specification);
9306 /* First, compute a signature for just the type name (and its surrounding
9307 context, if any. This is stored in the type unit DIE for link-time
9308 ODR (one-definition rule) checking. */
9310 if (is_cxx() && name != NULL)
9312 md5_init_ctx (&ctx);
9314 /* Checksum the names of surrounding namespaces and structures. */
9315 if (decl != NULL && decl->die_parent != NULL)
9316 checksum_die_context (decl->die_parent, &ctx);
9318 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9319 md5_process_bytes (name, strlen (name) + 1, &ctx);
9320 md5_finish_ctx (&ctx, checksum);
9322 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9325 /* Next, compute the complete type signature. */
9327 md5_init_ctx (&ctx);
9329 die->die_mark = mark;
9331 /* Checksum the names of surrounding namespaces and structures. */
9332 if (decl != NULL && decl->die_parent != NULL)
9333 checksum_die_context (decl->die_parent, &ctx);
9335 /* Checksum the DIE and its children. */
9336 die_checksum_ordered (die, &ctx, &mark);
9337 unmark_all_dies (die);
9338 md5_finish_ctx (&ctx, checksum);
9340 /* Store the signature in the type node and link the type DIE and the
9341 type node together. */
9342 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9343 DWARF_TYPE_SIGNATURE_SIZE);
9344 die->die_id.die_type_node = type_node;
9345 type_node->type_die = die;
9347 /* If the DIE is a specification, link its declaration to the type node
9350 decl->die_id.die_type_node = type_node;
9353 /* Do the location expressions look same? */
9355 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9357 return loc1->dw_loc_opc == loc2->dw_loc_opc
9358 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9359 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9362 /* Do the values look the same? */
9364 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9366 dw_loc_descr_ref loc1, loc2;
9369 if (v1->val_class != v2->val_class)
9372 switch (v1->val_class)
9374 case dw_val_class_const:
9375 return v1->v.val_int == v2->v.val_int;
9376 case dw_val_class_unsigned_const:
9377 return v1->v.val_unsigned == v2->v.val_unsigned;
9378 case dw_val_class_const_double:
9379 return v1->v.val_double.high == v2->v.val_double.high
9380 && v1->v.val_double.low == v2->v.val_double.low;
9381 case dw_val_class_vec:
9382 if (v1->v.val_vec.length != v2->v.val_vec.length
9383 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9385 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9386 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9389 case dw_val_class_flag:
9390 return v1->v.val_flag == v2->v.val_flag;
9391 case dw_val_class_str:
9392 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9394 case dw_val_class_addr:
9395 r1 = v1->v.val_addr;
9396 r2 = v2->v.val_addr;
9397 if (GET_CODE (r1) != GET_CODE (r2))
9399 return !rtx_equal_p (r1, r2);
9401 case dw_val_class_offset:
9402 return v1->v.val_offset == v2->v.val_offset;
9404 case dw_val_class_loc:
9405 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9407 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9408 if (!same_loc_p (loc1, loc2, mark))
9410 return !loc1 && !loc2;
9412 case dw_val_class_die_ref:
9413 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9415 case dw_val_class_fde_ref:
9416 case dw_val_class_vms_delta:
9417 case dw_val_class_lbl_id:
9418 case dw_val_class_lineptr:
9419 case dw_val_class_macptr:
9422 case dw_val_class_file:
9423 return v1->v.val_file == v2->v.val_file;
9425 case dw_val_class_data8:
9426 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9433 /* Do the attributes look the same? */
9436 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9438 if (at1->dw_attr != at2->dw_attr)
9441 /* We don't care that this was compiled with a different compiler
9442 snapshot; if the output is the same, that's what matters. */
9443 if (at1->dw_attr == DW_AT_producer)
9446 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9449 /* Do the dies look the same? */
9452 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9458 /* To avoid infinite recursion. */
9460 return die1->die_mark == die2->die_mark;
9461 die1->die_mark = die2->die_mark = ++(*mark);
9463 if (die1->die_tag != die2->die_tag)
9466 if (VEC_length (dw_attr_node, die1->die_attr)
9467 != VEC_length (dw_attr_node, die2->die_attr))
9470 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9471 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9474 c1 = die1->die_child;
9475 c2 = die2->die_child;
9484 if (!same_die_p (c1, c2, mark))
9488 if (c1 == die1->die_child)
9490 if (c2 == die2->die_child)
9500 /* Do the dies look the same? Wrapper around same_die_p. */
9503 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9506 int ret = same_die_p (die1, die2, &mark);
9508 unmark_all_dies (die1);
9509 unmark_all_dies (die2);
9514 /* The prefix to attach to symbols on DIEs in the current comdat debug
9516 static char *comdat_symbol_id;
9518 /* The index of the current symbol within the current comdat CU. */
9519 static unsigned int comdat_symbol_number;
9521 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9522 children, and set comdat_symbol_id accordingly. */
9525 compute_section_prefix (dw_die_ref unit_die)
9527 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9528 const char *base = die_name ? lbasename (die_name) : "anonymous";
9529 char *name = XALLOCAVEC (char, strlen (base) + 64);
9532 unsigned char checksum[16];
9535 /* Compute the checksum of the DIE, then append part of it as hex digits to
9536 the name filename of the unit. */
9538 md5_init_ctx (&ctx);
9540 die_checksum (unit_die, &ctx, &mark);
9541 unmark_all_dies (unit_die);
9542 md5_finish_ctx (&ctx, checksum);
9544 sprintf (name, "%s.", base);
9545 clean_symbol_name (name);
9547 p = name + strlen (name);
9548 for (i = 0; i < 4; i++)
9550 sprintf (p, "%.2x", checksum[i]);
9554 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9555 comdat_symbol_number = 0;
9558 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9561 is_type_die (dw_die_ref die)
9563 switch (die->die_tag)
9565 case DW_TAG_array_type:
9566 case DW_TAG_class_type:
9567 case DW_TAG_interface_type:
9568 case DW_TAG_enumeration_type:
9569 case DW_TAG_pointer_type:
9570 case DW_TAG_reference_type:
9571 case DW_TAG_rvalue_reference_type:
9572 case DW_TAG_string_type:
9573 case DW_TAG_structure_type:
9574 case DW_TAG_subroutine_type:
9575 case DW_TAG_union_type:
9576 case DW_TAG_ptr_to_member_type:
9577 case DW_TAG_set_type:
9578 case DW_TAG_subrange_type:
9579 case DW_TAG_base_type:
9580 case DW_TAG_const_type:
9581 case DW_TAG_file_type:
9582 case DW_TAG_packed_type:
9583 case DW_TAG_volatile_type:
9584 case DW_TAG_typedef:
9591 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9592 Basically, we want to choose the bits that are likely to be shared between
9593 compilations (types) and leave out the bits that are specific to individual
9594 compilations (functions). */
9597 is_comdat_die (dw_die_ref c)
9599 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9600 we do for stabs. The advantage is a greater likelihood of sharing between
9601 objects that don't include headers in the same order (and therefore would
9602 put the base types in a different comdat). jason 8/28/00 */
9604 if (c->die_tag == DW_TAG_base_type)
9607 if (c->die_tag == DW_TAG_pointer_type
9608 || c->die_tag == DW_TAG_reference_type
9609 || c->die_tag == DW_TAG_rvalue_reference_type
9610 || c->die_tag == DW_TAG_const_type
9611 || c->die_tag == DW_TAG_volatile_type)
9613 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9615 return t ? is_comdat_die (t) : 0;
9618 return is_type_die (c);
9621 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9622 compilation unit. */
9625 is_symbol_die (dw_die_ref c)
9627 return (is_type_die (c)
9628 || is_declaration_die (c)
9629 || c->die_tag == DW_TAG_namespace
9630 || c->die_tag == DW_TAG_module);
9633 /* Returns true iff C is a compile-unit DIE. */
9636 is_cu_die (dw_die_ref c)
9638 return c && c->die_tag == DW_TAG_compile_unit;
9642 gen_internal_sym (const char *prefix)
9646 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9647 return xstrdup (buf);
9650 /* Assign symbols to all worthy DIEs under DIE. */
9653 assign_symbol_names (dw_die_ref die)
9657 if (is_symbol_die (die))
9659 if (comdat_symbol_id)
9661 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9663 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9664 comdat_symbol_id, comdat_symbol_number++);
9665 die->die_id.die_symbol = xstrdup (p);
9668 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9671 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9674 struct cu_hash_table_entry
9677 unsigned min_comdat_num, max_comdat_num;
9678 struct cu_hash_table_entry *next;
9681 /* Routines to manipulate hash table of CUs. */
9683 htab_cu_hash (const void *of)
9685 const struct cu_hash_table_entry *const entry =
9686 (const struct cu_hash_table_entry *) of;
9688 return htab_hash_string (entry->cu->die_id.die_symbol);
9692 htab_cu_eq (const void *of1, const void *of2)
9694 const struct cu_hash_table_entry *const entry1 =
9695 (const struct cu_hash_table_entry *) of1;
9696 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9698 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9702 htab_cu_del (void *what)
9704 struct cu_hash_table_entry *next,
9705 *entry = (struct cu_hash_table_entry *) what;
9715 /* Check whether we have already seen this CU and set up SYM_NUM
9718 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9720 struct cu_hash_table_entry dummy;
9721 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9723 dummy.max_comdat_num = 0;
9725 slot = (struct cu_hash_table_entry **)
9726 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9730 for (; entry; last = entry, entry = entry->next)
9732 if (same_die_p_wrap (cu, entry->cu))
9738 *sym_num = entry->min_comdat_num;
9742 entry = XCNEW (struct cu_hash_table_entry);
9744 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9745 entry->next = *slot;
9751 /* Record SYM_NUM to record of CU in HTABLE. */
9753 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9755 struct cu_hash_table_entry **slot, *entry;
9757 slot = (struct cu_hash_table_entry **)
9758 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9762 entry->max_comdat_num = sym_num;
9765 /* Traverse the DIE (which is always comp_unit_die), and set up
9766 additional compilation units for each of the include files we see
9767 bracketed by BINCL/EINCL. */
9770 break_out_includes (dw_die_ref die)
9773 dw_die_ref unit = NULL;
9774 limbo_die_node *node, **pnode;
9775 htab_t cu_hash_table;
9779 dw_die_ref prev = c;
9781 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9782 || (unit && is_comdat_die (c)))
9784 dw_die_ref next = c->die_sib;
9786 /* This DIE is for a secondary CU; remove it from the main one. */
9787 remove_child_with_prev (c, prev);
9789 if (c->die_tag == DW_TAG_GNU_BINCL)
9790 unit = push_new_compile_unit (unit, c);
9791 else if (c->die_tag == DW_TAG_GNU_EINCL)
9792 unit = pop_compile_unit (unit);
9794 add_child_die (unit, c);
9796 if (c == die->die_child)
9799 } while (c != die->die_child);
9802 /* We can only use this in debugging, since the frontend doesn't check
9803 to make sure that we leave every include file we enter. */
9807 assign_symbol_names (die);
9808 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9809 for (node = limbo_die_list, pnode = &limbo_die_list;
9815 compute_section_prefix (node->die);
9816 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9817 &comdat_symbol_number);
9818 assign_symbol_names (node->die);
9820 *pnode = node->next;
9823 pnode = &node->next;
9824 record_comdat_symbol_number (node->die, cu_hash_table,
9825 comdat_symbol_number);
9828 htab_delete (cu_hash_table);
9831 /* Return non-zero if this DIE is a declaration. */
9834 is_declaration_die (dw_die_ref die)
9839 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9840 if (a->dw_attr == DW_AT_declaration)
9846 /* Return non-zero if this DIE is nested inside a subprogram. */
9849 is_nested_in_subprogram (dw_die_ref die)
9851 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9855 return local_scope_p (decl);
9858 /* Return non-zero if this is a type DIE that should be moved to a
9859 COMDAT .debug_types section. */
9862 should_move_die_to_comdat (dw_die_ref die)
9864 switch (die->die_tag)
9866 case DW_TAG_class_type:
9867 case DW_TAG_structure_type:
9868 case DW_TAG_enumeration_type:
9869 case DW_TAG_union_type:
9870 /* Don't move declarations, inlined instances, or types nested in a
9872 if (is_declaration_die (die)
9873 || get_AT (die, DW_AT_abstract_origin)
9874 || is_nested_in_subprogram (die))
9877 case DW_TAG_array_type:
9878 case DW_TAG_interface_type:
9879 case DW_TAG_pointer_type:
9880 case DW_TAG_reference_type:
9881 case DW_TAG_rvalue_reference_type:
9882 case DW_TAG_string_type:
9883 case DW_TAG_subroutine_type:
9884 case DW_TAG_ptr_to_member_type:
9885 case DW_TAG_set_type:
9886 case DW_TAG_subrange_type:
9887 case DW_TAG_base_type:
9888 case DW_TAG_const_type:
9889 case DW_TAG_file_type:
9890 case DW_TAG_packed_type:
9891 case DW_TAG_volatile_type:
9892 case DW_TAG_typedef:
9898 /* Make a clone of DIE. */
9901 clone_die (dw_die_ref die)
9907 clone = ggc_alloc_cleared_die_node ();
9908 clone->die_tag = die->die_tag;
9910 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9911 add_dwarf_attr (clone, a);
9916 /* Make a clone of the tree rooted at DIE. */
9919 clone_tree (dw_die_ref die)
9922 dw_die_ref clone = clone_die (die);
9924 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
9929 /* Make a clone of DIE as a declaration. */
9932 clone_as_declaration (dw_die_ref die)
9939 /* If the DIE is already a declaration, just clone it. */
9940 if (is_declaration_die (die))
9941 return clone_die (die);
9943 /* If the DIE is a specification, just clone its declaration DIE. */
9944 decl = get_AT_ref (die, DW_AT_specification);
9946 return clone_die (decl);
9948 clone = ggc_alloc_cleared_die_node ();
9949 clone->die_tag = die->die_tag;
9951 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9953 /* We don't want to copy over all attributes.
9954 For example we don't want DW_AT_byte_size because otherwise we will no
9955 longer have a declaration and GDB will treat it as a definition. */
9959 case DW_AT_artificial:
9960 case DW_AT_containing_type:
9961 case DW_AT_external:
9964 case DW_AT_virtuality:
9965 case DW_AT_linkage_name:
9966 case DW_AT_MIPS_linkage_name:
9967 add_dwarf_attr (clone, a);
9969 case DW_AT_byte_size:
9975 if (die->die_id.die_type_node)
9976 add_AT_die_ref (clone, DW_AT_signature, die);
9978 add_AT_flag (clone, DW_AT_declaration, 1);
9982 /* Copy the declaration context to the new compile unit DIE. This includes
9983 any surrounding namespace or type declarations. If the DIE has an
9984 AT_specification attribute, it also includes attributes and children
9985 attached to the specification. */
9988 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
9991 dw_die_ref new_decl;
9993 decl = get_AT_ref (die, DW_AT_specification);
10002 /* Copy the type node pointer from the new DIE to the original
10003 declaration DIE so we can forward references later. */
10004 decl->die_id.die_type_node = die->die_id.die_type_node;
10006 remove_AT (die, DW_AT_specification);
10008 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10010 if (a->dw_attr != DW_AT_name
10011 && a->dw_attr != DW_AT_declaration
10012 && a->dw_attr != DW_AT_external)
10013 add_dwarf_attr (die, a);
10016 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10019 if (decl->die_parent != NULL
10020 && decl->die_parent->die_tag != DW_TAG_compile_unit
10021 && decl->die_parent->die_tag != DW_TAG_type_unit)
10023 new_decl = copy_ancestor_tree (unit, decl, NULL);
10024 if (new_decl != NULL)
10026 remove_AT (new_decl, DW_AT_signature);
10027 add_AT_specification (die, new_decl);
10032 /* Generate the skeleton ancestor tree for the given NODE, then clone
10033 the DIE and add the clone into the tree. */
10036 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10038 if (node->new_die != NULL)
10041 node->new_die = clone_as_declaration (node->old_die);
10043 if (node->parent != NULL)
10045 generate_skeleton_ancestor_tree (node->parent);
10046 add_child_die (node->parent->new_die, node->new_die);
10050 /* Generate a skeleton tree of DIEs containing any declarations that are
10051 found in the original tree. We traverse the tree looking for declaration
10052 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10055 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10057 skeleton_chain_node node;
10060 dw_die_ref prev = NULL;
10061 dw_die_ref next = NULL;
10063 node.parent = parent;
10065 first = c = parent->old_die->die_child;
10069 if (prev == NULL || prev->die_sib == c)
10072 next = (c == first ? NULL : c->die_sib);
10074 node.new_die = NULL;
10075 if (is_declaration_die (c))
10077 /* Clone the existing DIE, move the original to the skeleton
10078 tree (which is in the main CU), and put the clone, with
10079 all the original's children, where the original came from. */
10080 dw_die_ref clone = clone_die (c);
10081 move_all_children (c, clone);
10083 replace_child (c, clone, prev);
10084 generate_skeleton_ancestor_tree (parent);
10085 add_child_die (parent->new_die, c);
10089 generate_skeleton_bottom_up (&node);
10090 } while (next != NULL);
10093 /* Wrapper function for generate_skeleton_bottom_up. */
10096 generate_skeleton (dw_die_ref die)
10098 skeleton_chain_node node;
10100 node.old_die = die;
10101 node.new_die = NULL;
10102 node.parent = NULL;
10104 /* If this type definition is nested inside another type,
10105 always leave at least a declaration in its place. */
10106 if (die->die_parent != NULL && is_type_die (die->die_parent))
10107 node.new_die = clone_as_declaration (die);
10109 generate_skeleton_bottom_up (&node);
10110 return node.new_die;
10113 /* Remove the DIE from its parent, possibly replacing it with a cloned
10114 declaration. The original DIE will be moved to a new compile unit
10115 so that existing references to it follow it to the new location. If
10116 any of the original DIE's descendants is a declaration, we need to
10117 replace the original DIE with a skeleton tree and move the
10118 declarations back into the skeleton tree. */
10121 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10123 dw_die_ref skeleton;
10125 skeleton = generate_skeleton (child);
10126 if (skeleton == NULL)
10127 remove_child_with_prev (child, prev);
10130 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10131 replace_child (child, skeleton, prev);
10137 /* Traverse the DIE and set up additional .debug_types sections for each
10138 type worthy of being placed in a COMDAT section. */
10141 break_out_comdat_types (dw_die_ref die)
10145 dw_die_ref prev = NULL;
10146 dw_die_ref next = NULL;
10147 dw_die_ref unit = NULL;
10149 first = c = die->die_child;
10153 if (prev == NULL || prev->die_sib == c)
10156 next = (c == first ? NULL : c->die_sib);
10157 if (should_move_die_to_comdat (c))
10159 dw_die_ref replacement;
10160 comdat_type_node_ref type_node;
10162 /* Create a new type unit DIE as the root for the new tree, and
10163 add it to the list of comdat types. */
10164 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10165 add_AT_unsigned (unit, DW_AT_language,
10166 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10167 type_node = ggc_alloc_cleared_comdat_type_node ();
10168 type_node->root_die = unit;
10169 type_node->next = comdat_type_list;
10170 comdat_type_list = type_node;
10172 /* Generate the type signature. */
10173 generate_type_signature (c, type_node);
10175 /* Copy the declaration context, attributes, and children of the
10176 declaration into the new compile unit DIE. */
10177 copy_declaration_context (unit, c);
10179 /* Remove this DIE from the main CU. */
10180 replacement = remove_child_or_replace_with_skeleton (c, prev);
10182 /* Break out nested types into their own type units. */
10183 break_out_comdat_types (c);
10185 /* Add the DIE to the new compunit. */
10186 add_child_die (unit, c);
10188 if (replacement != NULL)
10191 else if (c->die_tag == DW_TAG_namespace
10192 || c->die_tag == DW_TAG_class_type
10193 || c->die_tag == DW_TAG_structure_type
10194 || c->die_tag == DW_TAG_union_type)
10196 /* Look for nested types that can be broken out. */
10197 break_out_comdat_types (c);
10199 } while (next != NULL);
10202 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10204 struct decl_table_entry
10210 /* Routines to manipulate hash table of copied declarations. */
10213 htab_decl_hash (const void *of)
10215 const struct decl_table_entry *const entry =
10216 (const struct decl_table_entry *) of;
10218 return htab_hash_pointer (entry->orig);
10222 htab_decl_eq (const void *of1, const void *of2)
10224 const struct decl_table_entry *const entry1 =
10225 (const struct decl_table_entry *) of1;
10226 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10228 return entry1->orig == entry2;
10232 htab_decl_del (void *what)
10234 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10239 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10240 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10241 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10242 to check if the ancestor has already been copied into UNIT. */
10245 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10247 dw_die_ref parent = die->die_parent;
10248 dw_die_ref new_parent = unit;
10250 void **slot = NULL;
10251 struct decl_table_entry *entry = NULL;
10255 /* Check if the entry has already been copied to UNIT. */
10256 slot = htab_find_slot_with_hash (decl_table, die,
10257 htab_hash_pointer (die), INSERT);
10258 if (*slot != HTAB_EMPTY_ENTRY)
10260 entry = (struct decl_table_entry *) *slot;
10261 return entry->copy;
10264 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10265 entry = XCNEW (struct decl_table_entry);
10267 entry->copy = NULL;
10271 if (parent != NULL)
10273 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10276 if (parent->die_tag != DW_TAG_compile_unit
10277 && parent->die_tag != DW_TAG_type_unit)
10278 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10281 copy = clone_as_declaration (die);
10282 add_child_die (new_parent, copy);
10284 if (decl_table != NULL)
10286 /* Record the pointer to the copy. */
10287 entry->copy = copy;
10293 /* Walk the DIE and its children, looking for references to incomplete
10294 or trivial types that are unmarked (i.e., that are not in the current
10298 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10304 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10306 if (AT_class (a) == dw_val_class_die_ref)
10308 dw_die_ref targ = AT_ref (a);
10309 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10311 struct decl_table_entry *entry;
10313 if (targ->die_mark != 0 || type_node != NULL)
10316 slot = htab_find_slot_with_hash (decl_table, targ,
10317 htab_hash_pointer (targ), INSERT);
10319 if (*slot != HTAB_EMPTY_ENTRY)
10321 /* TARG has already been copied, so we just need to
10322 modify the reference to point to the copy. */
10323 entry = (struct decl_table_entry *) *slot;
10324 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10328 dw_die_ref parent = unit;
10329 dw_die_ref copy = clone_tree (targ);
10331 /* Make sure the cloned tree is marked as part of the
10335 /* Record in DECL_TABLE that TARG has been copied.
10336 Need to do this now, before the recursive call,
10337 because DECL_TABLE may be expanded and SLOT
10338 would no longer be a valid pointer. */
10339 entry = XCNEW (struct decl_table_entry);
10340 entry->orig = targ;
10341 entry->copy = copy;
10344 /* If TARG has surrounding context, copy its ancestor tree
10345 into the new type unit. */
10346 if (targ->die_parent != NULL
10347 && targ->die_parent->die_tag != DW_TAG_compile_unit
10348 && targ->die_parent->die_tag != DW_TAG_type_unit)
10349 parent = copy_ancestor_tree (unit, targ->die_parent,
10352 add_child_die (parent, copy);
10353 a->dw_attr_val.v.val_die_ref.die = copy;
10355 /* Make sure the newly-copied DIE is walked. If it was
10356 installed in a previously-added context, it won't
10357 get visited otherwise. */
10358 if (parent != unit)
10360 /* Find the highest point of the newly-added tree,
10361 mark each node along the way, and walk from there. */
10362 parent->die_mark = 1;
10363 while (parent->die_parent
10364 && parent->die_parent->die_mark == 0)
10366 parent = parent->die_parent;
10367 parent->die_mark = 1;
10369 copy_decls_walk (unit, parent, decl_table);
10375 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10378 /* Copy declarations for "unworthy" types into the new comdat section.
10379 Incomplete types, modified types, and certain other types aren't broken
10380 out into comdat sections of their own, so they don't have a signature,
10381 and we need to copy the declaration into the same section so that we
10382 don't have an external reference. */
10385 copy_decls_for_unworthy_types (dw_die_ref unit)
10390 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10391 copy_decls_walk (unit, unit, decl_table);
10392 htab_delete (decl_table);
10393 unmark_dies (unit);
10396 /* Traverse the DIE and add a sibling attribute if it may have the
10397 effect of speeding up access to siblings. To save some space,
10398 avoid generating sibling attributes for DIE's without children. */
10401 add_sibling_attributes (dw_die_ref die)
10405 if (! die->die_child)
10408 if (die->die_parent && die != die->die_parent->die_child)
10409 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10411 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10414 /* Output all location lists for the DIE and its children. */
10417 output_location_lists (dw_die_ref die)
10423 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10424 if (AT_class (a) == dw_val_class_loc_list)
10425 output_loc_list (AT_loc_list (a));
10427 FOR_EACH_CHILD (die, c, output_location_lists (c));
10430 /* The format of each DIE (and its attribute value pairs) is encoded in an
10431 abbreviation table. This routine builds the abbreviation table and assigns
10432 a unique abbreviation id for each abbreviation entry. The children of each
10433 die are visited recursively. */
10436 build_abbrev_table (dw_die_ref die)
10438 unsigned long abbrev_id;
10439 unsigned int n_alloc;
10444 /* Scan the DIE references, and mark as external any that refer to
10445 DIEs from other CUs (i.e. those which are not marked). */
10446 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10447 if (AT_class (a) == dw_val_class_die_ref
10448 && AT_ref (a)->die_mark == 0)
10450 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10451 set_AT_ref_external (a, 1);
10454 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10456 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10457 dw_attr_ref die_a, abbrev_a;
10461 if (abbrev->die_tag != die->die_tag)
10463 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10466 if (VEC_length (dw_attr_node, abbrev->die_attr)
10467 != VEC_length (dw_attr_node, die->die_attr))
10470 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10472 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10473 if ((abbrev_a->dw_attr != die_a->dw_attr)
10474 || (value_format (abbrev_a) != value_format (die_a)))
10484 if (abbrev_id >= abbrev_die_table_in_use)
10486 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10488 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10489 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10492 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10493 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10494 abbrev_die_table_allocated = n_alloc;
10497 ++abbrev_die_table_in_use;
10498 abbrev_die_table[abbrev_id] = die;
10501 die->die_abbrev = abbrev_id;
10502 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10505 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10508 constant_size (unsigned HOST_WIDE_INT value)
10515 log = floor_log2 (value);
10518 log = 1 << (floor_log2 (log) + 1);
10523 /* Return the size of a DIE as it is represented in the
10524 .debug_info section. */
10526 static unsigned long
10527 size_of_die (dw_die_ref die)
10529 unsigned long size = 0;
10533 size += size_of_uleb128 (die->die_abbrev);
10534 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10536 switch (AT_class (a))
10538 case dw_val_class_addr:
10539 size += DWARF2_ADDR_SIZE;
10541 case dw_val_class_offset:
10542 size += DWARF_OFFSET_SIZE;
10544 case dw_val_class_loc:
10546 unsigned long lsize = size_of_locs (AT_loc (a));
10548 /* Block length. */
10549 if (dwarf_version >= 4)
10550 size += size_of_uleb128 (lsize);
10552 size += constant_size (lsize);
10556 case dw_val_class_loc_list:
10557 size += DWARF_OFFSET_SIZE;
10559 case dw_val_class_range_list:
10560 size += DWARF_OFFSET_SIZE;
10562 case dw_val_class_const:
10563 size += size_of_sleb128 (AT_int (a));
10565 case dw_val_class_unsigned_const:
10566 size += constant_size (AT_unsigned (a));
10568 case dw_val_class_const_double:
10569 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10570 if (HOST_BITS_PER_WIDE_INT >= 64)
10571 size++; /* block */
10573 case dw_val_class_vec:
10574 size += constant_size (a->dw_attr_val.v.val_vec.length
10575 * a->dw_attr_val.v.val_vec.elt_size)
10576 + a->dw_attr_val.v.val_vec.length
10577 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10579 case dw_val_class_flag:
10580 if (dwarf_version >= 4)
10581 /* Currently all add_AT_flag calls pass in 1 as last argument,
10582 so DW_FORM_flag_present can be used. If that ever changes,
10583 we'll need to use DW_FORM_flag and have some optimization
10584 in build_abbrev_table that will change those to
10585 DW_FORM_flag_present if it is set to 1 in all DIEs using
10586 the same abbrev entry. */
10587 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10591 case dw_val_class_die_ref:
10592 if (AT_ref_external (a))
10594 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10595 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10596 is sized by target address length, whereas in DWARF3
10597 it's always sized as an offset. */
10598 if (dwarf_version >= 4)
10599 size += DWARF_TYPE_SIGNATURE_SIZE;
10600 else if (dwarf_version == 2)
10601 size += DWARF2_ADDR_SIZE;
10603 size += DWARF_OFFSET_SIZE;
10606 size += DWARF_OFFSET_SIZE;
10608 case dw_val_class_fde_ref:
10609 size += DWARF_OFFSET_SIZE;
10611 case dw_val_class_lbl_id:
10612 size += DWARF2_ADDR_SIZE;
10614 case dw_val_class_lineptr:
10615 case dw_val_class_macptr:
10616 size += DWARF_OFFSET_SIZE;
10618 case dw_val_class_str:
10619 if (AT_string_form (a) == DW_FORM_strp)
10620 size += DWARF_OFFSET_SIZE;
10622 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10624 case dw_val_class_file:
10625 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10627 case dw_val_class_data8:
10630 case dw_val_class_vms_delta:
10631 size += DWARF_OFFSET_SIZE;
10634 gcc_unreachable ();
10641 /* Size the debugging information associated with a given DIE. Visits the
10642 DIE's children recursively. Updates the global variable next_die_offset, on
10643 each time through. Uses the current value of next_die_offset to update the
10644 die_offset field in each DIE. */
10647 calc_die_sizes (dw_die_ref die)
10651 die->die_offset = next_die_offset;
10652 next_die_offset += size_of_die (die);
10654 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10656 if (die->die_child != NULL)
10657 /* Count the null byte used to terminate sibling lists. */
10658 next_die_offset += 1;
10661 /* Set the marks for a die and its children. We do this so
10662 that we know whether or not a reference needs to use FORM_ref_addr; only
10663 DIEs in the same CU will be marked. We used to clear out the offset
10664 and use that as the flag, but ran into ordering problems. */
10667 mark_dies (dw_die_ref die)
10671 gcc_assert (!die->die_mark);
10674 FOR_EACH_CHILD (die, c, mark_dies (c));
10677 /* Clear the marks for a die and its children. */
10680 unmark_dies (dw_die_ref die)
10684 if (dwarf_version < 4)
10685 gcc_assert (die->die_mark);
10688 FOR_EACH_CHILD (die, c, unmark_dies (c));
10691 /* Clear the marks for a die, its children and referred dies. */
10694 unmark_all_dies (dw_die_ref die)
10700 if (!die->die_mark)
10704 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10706 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10707 if (AT_class (a) == dw_val_class_die_ref)
10708 unmark_all_dies (AT_ref (a));
10711 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10712 generated for the compilation unit. */
10714 static unsigned long
10715 size_of_pubnames (VEC (pubname_entry, gc) * names)
10717 unsigned long size;
10721 size = DWARF_PUBNAMES_HEADER_SIZE;
10722 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10723 if (names != pubtype_table
10724 || p->die->die_offset != 0
10725 || !flag_eliminate_unused_debug_types)
10726 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10728 size += DWARF_OFFSET_SIZE;
10732 /* Return the size of the information in the .debug_aranges section. */
10734 static unsigned long
10735 size_of_aranges (void)
10737 unsigned long size;
10739 size = DWARF_ARANGES_HEADER_SIZE;
10741 /* Count the address/length pair for this compilation unit. */
10742 if (text_section_used)
10743 size += 2 * DWARF2_ADDR_SIZE;
10744 if (cold_text_section_used)
10745 size += 2 * DWARF2_ADDR_SIZE;
10746 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10748 /* Count the two zero words used to terminated the address range table. */
10749 size += 2 * DWARF2_ADDR_SIZE;
10753 /* Select the encoding of an attribute value. */
10755 static enum dwarf_form
10756 value_format (dw_attr_ref a)
10758 switch (a->dw_attr_val.val_class)
10760 case dw_val_class_addr:
10761 /* Only very few attributes allow DW_FORM_addr. */
10762 switch (a->dw_attr)
10765 case DW_AT_high_pc:
10766 case DW_AT_entry_pc:
10767 case DW_AT_trampoline:
10768 return DW_FORM_addr;
10772 switch (DWARF2_ADDR_SIZE)
10775 return DW_FORM_data1;
10777 return DW_FORM_data2;
10779 return DW_FORM_data4;
10781 return DW_FORM_data8;
10783 gcc_unreachable ();
10785 case dw_val_class_range_list:
10786 case dw_val_class_loc_list:
10787 if (dwarf_version >= 4)
10788 return DW_FORM_sec_offset;
10790 case dw_val_class_vms_delta:
10791 case dw_val_class_offset:
10792 switch (DWARF_OFFSET_SIZE)
10795 return DW_FORM_data4;
10797 return DW_FORM_data8;
10799 gcc_unreachable ();
10801 case dw_val_class_loc:
10802 if (dwarf_version >= 4)
10803 return DW_FORM_exprloc;
10804 switch (constant_size (size_of_locs (AT_loc (a))))
10807 return DW_FORM_block1;
10809 return DW_FORM_block2;
10811 gcc_unreachable ();
10813 case dw_val_class_const:
10814 return DW_FORM_sdata;
10815 case dw_val_class_unsigned_const:
10816 switch (constant_size (AT_unsigned (a)))
10819 return DW_FORM_data1;
10821 return DW_FORM_data2;
10823 return DW_FORM_data4;
10825 return DW_FORM_data8;
10827 gcc_unreachable ();
10829 case dw_val_class_const_double:
10830 switch (HOST_BITS_PER_WIDE_INT)
10833 return DW_FORM_data2;
10835 return DW_FORM_data4;
10837 return DW_FORM_data8;
10840 return DW_FORM_block1;
10842 case dw_val_class_vec:
10843 switch (constant_size (a->dw_attr_val.v.val_vec.length
10844 * a->dw_attr_val.v.val_vec.elt_size))
10847 return DW_FORM_block1;
10849 return DW_FORM_block2;
10851 return DW_FORM_block4;
10853 gcc_unreachable ();
10855 case dw_val_class_flag:
10856 if (dwarf_version >= 4)
10858 /* Currently all add_AT_flag calls pass in 1 as last argument,
10859 so DW_FORM_flag_present can be used. If that ever changes,
10860 we'll need to use DW_FORM_flag and have some optimization
10861 in build_abbrev_table that will change those to
10862 DW_FORM_flag_present if it is set to 1 in all DIEs using
10863 the same abbrev entry. */
10864 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10865 return DW_FORM_flag_present;
10867 return DW_FORM_flag;
10868 case dw_val_class_die_ref:
10869 if (AT_ref_external (a))
10870 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
10872 return DW_FORM_ref;
10873 case dw_val_class_fde_ref:
10874 return DW_FORM_data;
10875 case dw_val_class_lbl_id:
10876 return DW_FORM_addr;
10877 case dw_val_class_lineptr:
10878 case dw_val_class_macptr:
10879 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10880 case dw_val_class_str:
10881 return AT_string_form (a);
10882 case dw_val_class_file:
10883 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10886 return DW_FORM_data1;
10888 return DW_FORM_data2;
10890 return DW_FORM_data4;
10892 gcc_unreachable ();
10895 case dw_val_class_data8:
10896 return DW_FORM_data8;
10899 gcc_unreachable ();
10903 /* Output the encoding of an attribute value. */
10906 output_value_format (dw_attr_ref a)
10908 enum dwarf_form form = value_format (a);
10910 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10913 /* Output the .debug_abbrev section which defines the DIE abbreviation
10917 output_abbrev_section (void)
10919 unsigned long abbrev_id;
10921 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10923 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10925 dw_attr_ref a_attr;
10927 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10928 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10929 dwarf_tag_name (abbrev->die_tag));
10931 if (abbrev->die_child != NULL)
10932 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10934 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10936 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
10939 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10940 dwarf_attr_name (a_attr->dw_attr));
10941 output_value_format (a_attr);
10944 dw2_asm_output_data (1, 0, NULL);
10945 dw2_asm_output_data (1, 0, NULL);
10948 /* Terminate the table. */
10949 dw2_asm_output_data (1, 0, NULL);
10952 /* Output a symbol we can use to refer to this DIE from another CU. */
10955 output_die_symbol (dw_die_ref die)
10957 char *sym = die->die_id.die_symbol;
10962 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
10963 /* We make these global, not weak; if the target doesn't support
10964 .linkonce, it doesn't support combining the sections, so debugging
10966 targetm.asm_out.globalize_label (asm_out_file, sym);
10968 ASM_OUTPUT_LABEL (asm_out_file, sym);
10971 /* Return a new location list, given the begin and end range, and the
10974 static inline dw_loc_list_ref
10975 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
10976 const char *section)
10978 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
10980 retlist->begin = begin;
10981 retlist->end = end;
10982 retlist->expr = expr;
10983 retlist->section = section;
10988 /* Generate a new internal symbol for this location list node, if it
10989 hasn't got one yet. */
10992 gen_llsym (dw_loc_list_ref list)
10994 gcc_assert (!list->ll_symbol);
10995 list->ll_symbol = gen_internal_sym ("LLST");
10998 /* Output the location list given to us. */
11001 output_loc_list (dw_loc_list_ref list_head)
11003 dw_loc_list_ref curr = list_head;
11005 if (list_head->emitted)
11007 list_head->emitted = true;
11009 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11011 /* Walk the location list, and output each range + expression. */
11012 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11014 unsigned long size;
11015 /* Don't output an entry that starts and ends at the same address. */
11016 if (strcmp (curr->begin, curr->end) == 0)
11018 if (!have_multiple_function_sections)
11020 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11021 "Location list begin address (%s)",
11022 list_head->ll_symbol);
11023 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11024 "Location list end address (%s)",
11025 list_head->ll_symbol);
11029 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11030 "Location list begin address (%s)",
11031 list_head->ll_symbol);
11032 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11033 "Location list end address (%s)",
11034 list_head->ll_symbol);
11036 size = size_of_locs (curr->expr);
11038 /* Output the block length for this list of location operations. */
11039 gcc_assert (size <= 0xffff);
11040 dw2_asm_output_data (2, size, "%s", "Location expression size");
11042 output_loc_sequence (curr->expr);
11045 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11046 "Location list terminator begin (%s)",
11047 list_head->ll_symbol);
11048 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11049 "Location list terminator end (%s)",
11050 list_head->ll_symbol);
11053 /* Output a type signature. */
11056 output_signature (const char *sig, const char *name)
11060 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11061 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11064 /* Output the DIE and its attributes. Called recursively to generate
11065 the definitions of each child DIE. */
11068 output_die (dw_die_ref die)
11072 unsigned long size;
11075 /* If someone in another CU might refer to us, set up a symbol for
11076 them to point to. */
11077 if (dwarf_version < 4 && die->die_id.die_symbol)
11078 output_die_symbol (die);
11080 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11081 (unsigned long)die->die_offset,
11082 dwarf_tag_name (die->die_tag));
11084 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11086 const char *name = dwarf_attr_name (a->dw_attr);
11088 switch (AT_class (a))
11090 case dw_val_class_addr:
11091 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11094 case dw_val_class_offset:
11095 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11099 case dw_val_class_range_list:
11101 char *p = strchr (ranges_section_label, '\0');
11103 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11104 a->dw_attr_val.v.val_offset);
11105 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11106 debug_ranges_section, "%s", name);
11111 case dw_val_class_loc:
11112 size = size_of_locs (AT_loc (a));
11114 /* Output the block length for this list of location operations. */
11115 if (dwarf_version >= 4)
11116 dw2_asm_output_data_uleb128 (size, "%s", name);
11118 dw2_asm_output_data (constant_size (size), size, "%s", name);
11120 output_loc_sequence (AT_loc (a));
11123 case dw_val_class_const:
11124 /* ??? It would be slightly more efficient to use a scheme like is
11125 used for unsigned constants below, but gdb 4.x does not sign
11126 extend. Gdb 5.x does sign extend. */
11127 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11130 case dw_val_class_unsigned_const:
11131 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11132 AT_unsigned (a), "%s", name);
11135 case dw_val_class_const_double:
11137 unsigned HOST_WIDE_INT first, second;
11139 if (HOST_BITS_PER_WIDE_INT >= 64)
11140 dw2_asm_output_data (1,
11141 2 * HOST_BITS_PER_WIDE_INT
11142 / HOST_BITS_PER_CHAR,
11145 if (WORDS_BIG_ENDIAN)
11147 first = a->dw_attr_val.v.val_double.high;
11148 second = a->dw_attr_val.v.val_double.low;
11152 first = a->dw_attr_val.v.val_double.low;
11153 second = a->dw_attr_val.v.val_double.high;
11156 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11158 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11163 case dw_val_class_vec:
11165 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11166 unsigned int len = a->dw_attr_val.v.val_vec.length;
11170 dw2_asm_output_data (constant_size (len * elt_size),
11171 len * elt_size, "%s", name);
11172 if (elt_size > sizeof (HOST_WIDE_INT))
11177 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11179 i++, p += elt_size)
11180 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11181 "fp or vector constant word %u", i);
11185 case dw_val_class_flag:
11186 if (dwarf_version >= 4)
11188 /* Currently all add_AT_flag calls pass in 1 as last argument,
11189 so DW_FORM_flag_present can be used. If that ever changes,
11190 we'll need to use DW_FORM_flag and have some optimization
11191 in build_abbrev_table that will change those to
11192 DW_FORM_flag_present if it is set to 1 in all DIEs using
11193 the same abbrev entry. */
11194 gcc_assert (AT_flag (a) == 1);
11195 if (flag_debug_asm)
11196 fprintf (asm_out_file, "\t\t\t%s %s\n",
11197 ASM_COMMENT_START, name);
11200 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11203 case dw_val_class_loc_list:
11205 char *sym = AT_loc_list (a)->ll_symbol;
11208 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11213 case dw_val_class_die_ref:
11214 if (AT_ref_external (a))
11216 if (dwarf_version >= 4)
11218 comdat_type_node_ref type_node =
11219 AT_ref (a)->die_id.die_type_node;
11221 gcc_assert (type_node);
11222 output_signature (type_node->signature, name);
11226 char *sym = AT_ref (a)->die_id.die_symbol;
11230 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11231 length, whereas in DWARF3 it's always sized as an
11233 if (dwarf_version == 2)
11234 size = DWARF2_ADDR_SIZE;
11236 size = DWARF_OFFSET_SIZE;
11237 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11243 gcc_assert (AT_ref (a)->die_offset);
11244 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11249 case dw_val_class_fde_ref:
11253 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11254 a->dw_attr_val.v.val_fde_index * 2);
11255 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11260 case dw_val_class_vms_delta:
11261 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11262 AT_vms_delta2 (a), AT_vms_delta1 (a),
11266 case dw_val_class_lbl_id:
11267 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11270 case dw_val_class_lineptr:
11271 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11272 debug_line_section, "%s", name);
11275 case dw_val_class_macptr:
11276 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11277 debug_macinfo_section, "%s", name);
11280 case dw_val_class_str:
11281 if (AT_string_form (a) == DW_FORM_strp)
11282 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11283 a->dw_attr_val.v.val_str->label,
11285 "%s: \"%s\"", name, AT_string (a));
11287 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11290 case dw_val_class_file:
11292 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11294 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11295 a->dw_attr_val.v.val_file->filename);
11299 case dw_val_class_data8:
11303 for (i = 0; i < 8; i++)
11304 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11305 i == 0 ? "%s" : NULL, name);
11310 gcc_unreachable ();
11314 FOR_EACH_CHILD (die, c, output_die (c));
11316 /* Add null byte to terminate sibling list. */
11317 if (die->die_child != NULL)
11318 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11319 (unsigned long) die->die_offset);
11322 /* Output the compilation unit that appears at the beginning of the
11323 .debug_info section, and precedes the DIE descriptions. */
11326 output_compilation_unit_header (void)
11328 int ver = dwarf_version;
11330 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11331 dw2_asm_output_data (4, 0xffffffff,
11332 "Initial length escape value indicating 64-bit DWARF extension");
11333 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11334 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11335 "Length of Compilation Unit Info");
11336 dw2_asm_output_data (2, ver, "DWARF version number");
11337 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11338 debug_abbrev_section,
11339 "Offset Into Abbrev. Section");
11340 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11343 /* Output the compilation unit DIE and its children. */
11346 output_comp_unit (dw_die_ref die, int output_if_empty)
11348 const char *secname;
11349 char *oldsym, *tmp;
11351 /* Unless we are outputting main CU, we may throw away empty ones. */
11352 if (!output_if_empty && die->die_child == NULL)
11355 /* Even if there are no children of this DIE, we must output the information
11356 about the compilation unit. Otherwise, on an empty translation unit, we
11357 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11358 will then complain when examining the file. First mark all the DIEs in
11359 this CU so we know which get local refs. */
11362 build_abbrev_table (die);
11364 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11365 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11366 calc_die_sizes (die);
11368 oldsym = die->die_id.die_symbol;
11371 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11373 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11375 die->die_id.die_symbol = NULL;
11376 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11380 switch_to_section (debug_info_section);
11381 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11382 info_section_emitted = true;
11385 /* Output debugging information. */
11386 output_compilation_unit_header ();
11389 /* Leave the marks on the main CU, so we can check them in
11390 output_pubnames. */
11394 die->die_id.die_symbol = oldsym;
11398 /* Output a comdat type unit DIE and its children. */
11401 output_comdat_type_unit (comdat_type_node *node)
11403 const char *secname;
11406 #if defined (OBJECT_FORMAT_ELF)
11410 /* First mark all the DIEs in this CU so we know which get local refs. */
11411 mark_dies (node->root_die);
11413 build_abbrev_table (node->root_die);
11415 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11416 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11417 calc_die_sizes (node->root_die);
11419 #if defined (OBJECT_FORMAT_ELF)
11420 secname = ".debug_types";
11421 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11422 sprintf (tmp, "wt.");
11423 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11424 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11425 comdat_key = get_identifier (tmp);
11426 targetm.asm_out.named_section (secname,
11427 SECTION_DEBUG | SECTION_LINKONCE,
11430 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11431 sprintf (tmp, ".gnu.linkonce.wt.");
11432 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11433 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11435 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11438 /* Output debugging information. */
11439 output_compilation_unit_header ();
11440 output_signature (node->signature, "Type Signature");
11441 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11442 "Offset to Type DIE");
11443 output_die (node->root_die);
11445 unmark_dies (node->root_die);
11448 /* Return the DWARF2/3 pubname associated with a decl. */
11450 static const char *
11451 dwarf2_name (tree decl, int scope)
11453 if (DECL_NAMELESS (decl))
11455 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11458 /* Add a new entry to .debug_pubnames if appropriate. */
11461 add_pubname_string (const char *str, dw_die_ref die)
11463 if (targetm.want_debug_pub_sections)
11468 e.name = xstrdup (str);
11469 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11474 add_pubname (tree decl, dw_die_ref die)
11476 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11478 const char *name = dwarf2_name (decl, 1);
11480 add_pubname_string (name, die);
11484 /* Add a new entry to .debug_pubtypes if appropriate. */
11487 add_pubtype (tree decl, dw_die_ref die)
11491 if (!targetm.want_debug_pub_sections)
11495 if ((TREE_PUBLIC (decl)
11496 || is_cu_die (die->die_parent))
11497 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11502 if (TYPE_NAME (decl))
11504 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11505 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11506 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11507 && DECL_NAME (TYPE_NAME (decl)))
11508 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11510 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11515 e.name = dwarf2_name (decl, 1);
11517 e.name = xstrdup (e.name);
11520 /* If we don't have a name for the type, there's no point in adding
11521 it to the table. */
11522 if (e.name && e.name[0] != '\0')
11523 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11527 /* Output the public names table used to speed up access to externally
11528 visible names; or the public types table used to find type definitions. */
11531 output_pubnames (VEC (pubname_entry, gc) * names)
11534 unsigned long pubnames_length = size_of_pubnames (names);
11537 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11538 dw2_asm_output_data (4, 0xffffffff,
11539 "Initial length escape value indicating 64-bit DWARF extension");
11540 if (names == pubname_table)
11541 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11542 "Length of Public Names Info");
11544 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11545 "Length of Public Type Names Info");
11546 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11547 dw2_asm_output_data (2, 2, "DWARF Version");
11548 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11549 debug_info_section,
11550 "Offset of Compilation Unit Info");
11551 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11552 "Compilation Unit Length");
11554 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11556 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11557 if (names == pubname_table)
11558 gcc_assert (pub->die->die_mark);
11560 if (names != pubtype_table
11561 || pub->die->die_offset != 0
11562 || !flag_eliminate_unused_debug_types)
11564 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11567 dw2_asm_output_nstring (pub->name, -1, "external name");
11571 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11574 /* Add a new entry to .debug_aranges if appropriate. */
11577 add_arange (tree decl, dw_die_ref die)
11579 if (! DECL_SECTION_NAME (decl))
11582 if (arange_table_in_use == arange_table_allocated)
11584 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11585 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11586 arange_table_allocated);
11587 memset (arange_table + arange_table_in_use, 0,
11588 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11591 arange_table[arange_table_in_use++] = die;
11594 /* Output the information that goes into the .debug_aranges table.
11595 Namely, define the beginning and ending address range of the
11596 text section generated for this compilation unit. */
11599 output_aranges (void)
11602 unsigned long aranges_length = size_of_aranges ();
11604 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11605 dw2_asm_output_data (4, 0xffffffff,
11606 "Initial length escape value indicating 64-bit DWARF extension");
11607 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11608 "Length of Address Ranges Info");
11609 /* Version number for aranges is still 2, even in DWARF3. */
11610 dw2_asm_output_data (2, 2, "DWARF Version");
11611 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11612 debug_info_section,
11613 "Offset of Compilation Unit Info");
11614 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11615 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11617 /* We need to align to twice the pointer size here. */
11618 if (DWARF_ARANGES_PAD_SIZE)
11620 /* Pad using a 2 byte words so that padding is correct for any
11622 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11623 2 * DWARF2_ADDR_SIZE);
11624 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11625 dw2_asm_output_data (2, 0, NULL);
11628 /* It is necessary not to output these entries if the sections were
11629 not used; if the sections were not used, the length will be 0 and
11630 the address may end up as 0 if the section is discarded by ld
11631 --gc-sections, leaving an invalid (0, 0) entry that can be
11632 confused with the terminator. */
11633 if (text_section_used)
11635 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11636 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11637 text_section_label, "Length");
11639 if (cold_text_section_used)
11641 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11643 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11644 cold_text_section_label, "Length");
11647 for (i = 0; i < arange_table_in_use; i++)
11649 dw_die_ref die = arange_table[i];
11651 /* We shouldn't see aranges for DIEs outside of the main CU. */
11652 gcc_assert (die->die_mark);
11654 if (die->die_tag == DW_TAG_subprogram)
11656 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11658 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11659 get_AT_low_pc (die), "Length");
11663 /* A static variable; extract the symbol from DW_AT_location.
11664 Note that this code isn't currently hit, as we only emit
11665 aranges for functions (jason 9/23/99). */
11666 dw_attr_ref a = get_AT (die, DW_AT_location);
11667 dw_loc_descr_ref loc;
11669 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11672 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11674 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11675 loc->dw_loc_oprnd1.v.val_addr, "Address");
11676 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11677 get_AT_unsigned (die, DW_AT_byte_size),
11682 /* Output the terminator words. */
11683 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11684 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11687 /* Add a new entry to .debug_ranges. Return the offset at which it
11690 static unsigned int
11691 add_ranges_num (int num)
11693 unsigned int in_use = ranges_table_in_use;
11695 if (in_use == ranges_table_allocated)
11697 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11698 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11699 ranges_table_allocated);
11700 memset (ranges_table + ranges_table_in_use, 0,
11701 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11704 ranges_table[in_use].num = num;
11705 ranges_table_in_use = in_use + 1;
11707 return in_use * 2 * DWARF2_ADDR_SIZE;
11710 /* Add a new entry to .debug_ranges corresponding to a block, or a
11711 range terminator if BLOCK is NULL. */
11713 static unsigned int
11714 add_ranges (const_tree block)
11716 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11719 /* Add a new entry to .debug_ranges corresponding to a pair of
11723 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11726 unsigned int in_use = ranges_by_label_in_use;
11727 unsigned int offset;
11729 if (in_use == ranges_by_label_allocated)
11731 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11732 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11734 ranges_by_label_allocated);
11735 memset (ranges_by_label + ranges_by_label_in_use, 0,
11736 RANGES_TABLE_INCREMENT
11737 * sizeof (struct dw_ranges_by_label_struct));
11740 ranges_by_label[in_use].begin = begin;
11741 ranges_by_label[in_use].end = end;
11742 ranges_by_label_in_use = in_use + 1;
11744 offset = add_ranges_num (-(int)in_use - 1);
11747 add_AT_range_list (die, DW_AT_ranges, offset);
11753 output_ranges (void)
11756 static const char *const start_fmt = "Offset %#x";
11757 const char *fmt = start_fmt;
11759 for (i = 0; i < ranges_table_in_use; i++)
11761 int block_num = ranges_table[i].num;
11765 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11766 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11768 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11769 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11771 /* If all code is in the text section, then the compilation
11772 unit base address defaults to DW_AT_low_pc, which is the
11773 base of the text section. */
11774 if (!have_multiple_function_sections)
11776 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11777 text_section_label,
11778 fmt, i * 2 * DWARF2_ADDR_SIZE);
11779 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11780 text_section_label, NULL);
11783 /* Otherwise, the compilation unit base address is zero,
11784 which allows us to use absolute addresses, and not worry
11785 about whether the target supports cross-section
11789 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11790 fmt, i * 2 * DWARF2_ADDR_SIZE);
11791 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11797 /* Negative block_num stands for an index into ranges_by_label. */
11798 else if (block_num < 0)
11800 int lab_idx = - block_num - 1;
11802 if (!have_multiple_function_sections)
11804 gcc_unreachable ();
11806 /* If we ever use add_ranges_by_labels () for a single
11807 function section, all we have to do is to take out
11808 the #if 0 above. */
11809 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11810 ranges_by_label[lab_idx].begin,
11811 text_section_label,
11812 fmt, i * 2 * DWARF2_ADDR_SIZE);
11813 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11814 ranges_by_label[lab_idx].end,
11815 text_section_label, NULL);
11820 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11821 ranges_by_label[lab_idx].begin,
11822 fmt, i * 2 * DWARF2_ADDR_SIZE);
11823 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11824 ranges_by_label[lab_idx].end,
11830 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11831 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11837 /* Data structure containing information about input files. */
11840 const char *path; /* Complete file name. */
11841 const char *fname; /* File name part. */
11842 int length; /* Length of entire string. */
11843 struct dwarf_file_data * file_idx; /* Index in input file table. */
11844 int dir_idx; /* Index in directory table. */
11847 /* Data structure containing information about directories with source
11851 const char *path; /* Path including directory name. */
11852 int length; /* Path length. */
11853 int prefix; /* Index of directory entry which is a prefix. */
11854 int count; /* Number of files in this directory. */
11855 int dir_idx; /* Index of directory used as base. */
11858 /* Callback function for file_info comparison. We sort by looking at
11859 the directories in the path. */
11862 file_info_cmp (const void *p1, const void *p2)
11864 const struct file_info *const s1 = (const struct file_info *) p1;
11865 const struct file_info *const s2 = (const struct file_info *) p2;
11866 const unsigned char *cp1;
11867 const unsigned char *cp2;
11869 /* Take care of file names without directories. We need to make sure that
11870 we return consistent values to qsort since some will get confused if
11871 we return the same value when identical operands are passed in opposite
11872 orders. So if neither has a directory, return 0 and otherwise return
11873 1 or -1 depending on which one has the directory. */
11874 if ((s1->path == s1->fname || s2->path == s2->fname))
11875 return (s2->path == s2->fname) - (s1->path == s1->fname);
11877 cp1 = (const unsigned char *) s1->path;
11878 cp2 = (const unsigned char *) s2->path;
11884 /* Reached the end of the first path? If so, handle like above. */
11885 if ((cp1 == (const unsigned char *) s1->fname)
11886 || (cp2 == (const unsigned char *) s2->fname))
11887 return ((cp2 == (const unsigned char *) s2->fname)
11888 - (cp1 == (const unsigned char *) s1->fname));
11890 /* Character of current path component the same? */
11891 else if (*cp1 != *cp2)
11892 return *cp1 - *cp2;
11896 struct file_name_acquire_data
11898 struct file_info *files;
11903 /* Traversal function for the hash table. */
11906 file_name_acquire (void ** slot, void *data)
11908 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
11909 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
11910 struct file_info *fi;
11913 gcc_assert (fnad->max_files >= d->emitted_number);
11915 if (! d->emitted_number)
11918 gcc_assert (fnad->max_files != fnad->used_files);
11920 fi = fnad->files + fnad->used_files++;
11922 /* Skip all leading "./". */
11924 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
11927 /* Create a new array entry. */
11929 fi->length = strlen (f);
11932 /* Search for the file name part. */
11933 f = strrchr (f, DIR_SEPARATOR);
11934 #if defined (DIR_SEPARATOR_2)
11936 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
11940 if (f == NULL || f < g)
11946 fi->fname = f == NULL ? fi->path : f + 1;
11950 /* Output the directory table and the file name table. We try to minimize
11951 the total amount of memory needed. A heuristic is used to avoid large
11952 slowdowns with many input files. */
11955 output_file_names (void)
11957 struct file_name_acquire_data fnad;
11959 struct file_info *files;
11960 struct dir_info *dirs;
11968 if (!last_emitted_file)
11970 dw2_asm_output_data (1, 0, "End directory table");
11971 dw2_asm_output_data (1, 0, "End file name table");
11975 numfiles = last_emitted_file->emitted_number;
11977 /* Allocate the various arrays we need. */
11978 files = XALLOCAVEC (struct file_info, numfiles);
11979 dirs = XALLOCAVEC (struct dir_info, numfiles);
11981 fnad.files = files;
11982 fnad.used_files = 0;
11983 fnad.max_files = numfiles;
11984 htab_traverse (file_table, file_name_acquire, &fnad);
11985 gcc_assert (fnad.used_files == fnad.max_files);
11987 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
11989 /* Find all the different directories used. */
11990 dirs[0].path = files[0].path;
11991 dirs[0].length = files[0].fname - files[0].path;
11992 dirs[0].prefix = -1;
11994 dirs[0].dir_idx = 0;
11995 files[0].dir_idx = 0;
11998 for (i = 1; i < numfiles; i++)
11999 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12000 && memcmp (dirs[ndirs - 1].path, files[i].path,
12001 dirs[ndirs - 1].length) == 0)
12003 /* Same directory as last entry. */
12004 files[i].dir_idx = ndirs - 1;
12005 ++dirs[ndirs - 1].count;
12011 /* This is a new directory. */
12012 dirs[ndirs].path = files[i].path;
12013 dirs[ndirs].length = files[i].fname - files[i].path;
12014 dirs[ndirs].count = 1;
12015 dirs[ndirs].dir_idx = ndirs;
12016 files[i].dir_idx = ndirs;
12018 /* Search for a prefix. */
12019 dirs[ndirs].prefix = -1;
12020 for (j = 0; j < ndirs; j++)
12021 if (dirs[j].length < dirs[ndirs].length
12022 && dirs[j].length > 1
12023 && (dirs[ndirs].prefix == -1
12024 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12025 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12026 dirs[ndirs].prefix = j;
12031 /* Now to the actual work. We have to find a subset of the directories which
12032 allow expressing the file name using references to the directory table
12033 with the least amount of characters. We do not do an exhaustive search
12034 where we would have to check out every combination of every single
12035 possible prefix. Instead we use a heuristic which provides nearly optimal
12036 results in most cases and never is much off. */
12037 saved = XALLOCAVEC (int, ndirs);
12038 savehere = XALLOCAVEC (int, ndirs);
12040 memset (saved, '\0', ndirs * sizeof (saved[0]));
12041 for (i = 0; i < ndirs; i++)
12046 /* We can always save some space for the current directory. But this
12047 does not mean it will be enough to justify adding the directory. */
12048 savehere[i] = dirs[i].length;
12049 total = (savehere[i] - saved[i]) * dirs[i].count;
12051 for (j = i + 1; j < ndirs; j++)
12054 if (saved[j] < dirs[i].length)
12056 /* Determine whether the dirs[i] path is a prefix of the
12060 k = dirs[j].prefix;
12061 while (k != -1 && k != (int) i)
12062 k = dirs[k].prefix;
12066 /* Yes it is. We can possibly save some memory by
12067 writing the filenames in dirs[j] relative to
12069 savehere[j] = dirs[i].length;
12070 total += (savehere[j] - saved[j]) * dirs[j].count;
12075 /* Check whether we can save enough to justify adding the dirs[i]
12077 if (total > dirs[i].length + 1)
12079 /* It's worthwhile adding. */
12080 for (j = i; j < ndirs; j++)
12081 if (savehere[j] > 0)
12083 /* Remember how much we saved for this directory so far. */
12084 saved[j] = savehere[j];
12086 /* Remember the prefix directory. */
12087 dirs[j].dir_idx = i;
12092 /* Emit the directory name table. */
12093 idx_offset = dirs[0].length > 0 ? 1 : 0;
12094 for (i = 1 - idx_offset; i < ndirs; i++)
12095 dw2_asm_output_nstring (dirs[i].path,
12097 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12098 "Directory Entry: %#x", i + idx_offset);
12100 dw2_asm_output_data (1, 0, "End directory table");
12102 /* We have to emit them in the order of emitted_number since that's
12103 used in the debug info generation. To do this efficiently we
12104 generate a back-mapping of the indices first. */
12105 backmap = XALLOCAVEC (int, numfiles);
12106 for (i = 0; i < numfiles; i++)
12107 backmap[files[i].file_idx->emitted_number - 1] = i;
12109 /* Now write all the file names. */
12110 for (i = 0; i < numfiles; i++)
12112 int file_idx = backmap[i];
12113 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12115 #ifdef VMS_DEBUGGING_INFO
12116 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12118 /* Setting these fields can lead to debugger miscomparisons,
12119 but VMS Debug requires them to be set correctly. */
12124 int maxfilelen = strlen (files[file_idx].path)
12125 + dirs[dir_idx].length
12126 + MAX_VMS_VERSION_LEN + 1;
12127 char *filebuf = XALLOCAVEC (char, maxfilelen);
12129 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12130 snprintf (filebuf, maxfilelen, "%s;%d",
12131 files[file_idx].path + dirs[dir_idx].length, ver);
12133 dw2_asm_output_nstring
12134 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12136 /* Include directory index. */
12137 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12139 /* Modification time. */
12140 dw2_asm_output_data_uleb128
12141 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12145 /* File length in bytes. */
12146 dw2_asm_output_data_uleb128
12147 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12151 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12152 "File Entry: %#x", (unsigned) i + 1);
12154 /* Include directory index. */
12155 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12157 /* Modification time. */
12158 dw2_asm_output_data_uleb128 (0, NULL);
12160 /* File length in bytes. */
12161 dw2_asm_output_data_uleb128 (0, NULL);
12162 #endif /* VMS_DEBUGGING_INFO */
12165 dw2_asm_output_data (1, 0, "End file name table");
12169 /* Output the source line number correspondence information. This
12170 information goes into the .debug_line section. */
12173 output_line_info (void)
12175 char l1[20], l2[20], p1[20], p2[20];
12176 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12177 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12179 unsigned n_op_args;
12180 unsigned long lt_index;
12181 unsigned long current_line;
12184 unsigned long current_file;
12185 unsigned long function;
12186 int ver = dwarf_version;
12188 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12189 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12190 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12191 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12193 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12194 dw2_asm_output_data (4, 0xffffffff,
12195 "Initial length escape value indicating 64-bit DWARF extension");
12196 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12197 "Length of Source Line Info");
12198 ASM_OUTPUT_LABEL (asm_out_file, l1);
12200 dw2_asm_output_data (2, ver, "DWARF Version");
12201 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12202 ASM_OUTPUT_LABEL (asm_out_file, p1);
12204 /* Define the architecture-dependent minimum instruction length (in
12205 bytes). In this implementation of DWARF, this field is used for
12206 information purposes only. Since GCC generates assembly language,
12207 we have no a priori knowledge of how many instruction bytes are
12208 generated for each source line, and therefore can use only the
12209 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12210 commands. Accordingly, we fix this as `1', which is "correct
12211 enough" for all architectures, and don't let the target override. */
12212 dw2_asm_output_data (1, 1,
12213 "Minimum Instruction Length");
12216 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12217 "Maximum Operations Per Instruction");
12218 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12219 "Default is_stmt_start flag");
12220 dw2_asm_output_data (1, DWARF_LINE_BASE,
12221 "Line Base Value (Special Opcodes)");
12222 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12223 "Line Range Value (Special Opcodes)");
12224 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12225 "Special Opcode Base");
12227 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12231 case DW_LNS_advance_pc:
12232 case DW_LNS_advance_line:
12233 case DW_LNS_set_file:
12234 case DW_LNS_set_column:
12235 case DW_LNS_fixed_advance_pc:
12243 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12247 /* Write out the information about the files we use. */
12248 output_file_names ();
12249 ASM_OUTPUT_LABEL (asm_out_file, p2);
12251 /* We used to set the address register to the first location in the text
12252 section here, but that didn't accomplish anything since we already
12253 have a line note for the opening brace of the first function. */
12255 /* Generate the line number to PC correspondence table, encoded as
12256 a series of state machine operations. */
12260 if (cfun && in_cold_section_p)
12261 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12263 strcpy (prev_line_label, text_section_label);
12264 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12266 dw_line_info_ref line_info = &line_info_table[lt_index];
12269 /* Disable this optimization for now; GDB wants to see two line notes
12270 at the beginning of a function so it can find the end of the
12273 /* Don't emit anything for redundant notes. Just updating the
12274 address doesn't accomplish anything, because we already assume
12275 that anything after the last address is this line. */
12276 if (line_info->dw_line_num == current_line
12277 && line_info->dw_file_num == current_file)
12281 /* Emit debug info for the address of the current line.
12283 Unfortunately, we have little choice here currently, and must always
12284 use the most general form. GCC does not know the address delta
12285 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12286 attributes which will give an upper bound on the address range. We
12287 could perhaps use length attributes to determine when it is safe to
12288 use DW_LNS_fixed_advance_pc. */
12290 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12293 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12294 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12295 "DW_LNS_fixed_advance_pc");
12296 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12300 /* This can handle any delta. This takes
12301 4+DWARF2_ADDR_SIZE bytes. */
12302 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12303 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12304 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12305 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12308 strcpy (prev_line_label, line_label);
12310 /* Emit debug info for the source file of the current line, if
12311 different from the previous line. */
12312 if (line_info->dw_file_num != current_file)
12314 current_file = line_info->dw_file_num;
12315 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12316 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12319 /* Emit debug info for the current line number, choosing the encoding
12320 that uses the least amount of space. */
12321 if (line_info->dw_line_num != current_line)
12323 line_offset = line_info->dw_line_num - current_line;
12324 line_delta = line_offset - DWARF_LINE_BASE;
12325 current_line = line_info->dw_line_num;
12326 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12327 /* This can handle deltas from -10 to 234, using the current
12328 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12330 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12331 "line %lu", current_line);
12334 /* This can handle any delta. This takes at least 4 bytes,
12335 depending on the value being encoded. */
12336 dw2_asm_output_data (1, DW_LNS_advance_line,
12337 "advance to line %lu", current_line);
12338 dw2_asm_output_data_sleb128 (line_offset, NULL);
12339 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12343 /* We still need to start a new row, so output a copy insn. */
12344 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12347 /* Emit debug info for the address of the end of the function. */
12350 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12351 "DW_LNS_fixed_advance_pc");
12352 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12356 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12357 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12358 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12359 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12362 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12363 dw2_asm_output_data_uleb128 (1, NULL);
12364 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12369 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12371 dw_separate_line_info_ref line_info
12372 = &separate_line_info_table[lt_index];
12375 /* Don't emit anything for redundant notes. */
12376 if (line_info->dw_line_num == current_line
12377 && line_info->dw_file_num == current_file
12378 && line_info->function == function)
12382 /* Emit debug info for the address of the current line. If this is
12383 a new function, or the first line of a function, then we need
12384 to handle it differently. */
12385 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12387 if (function != line_info->function)
12389 function = line_info->function;
12391 /* Set the address register to the first line in the function. */
12392 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12393 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12394 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12395 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12399 /* ??? See the DW_LNS_advance_pc comment above. */
12402 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12403 "DW_LNS_fixed_advance_pc");
12404 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12408 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12409 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12410 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12411 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12415 strcpy (prev_line_label, line_label);
12417 /* Emit debug info for the source file of the current line, if
12418 different from the previous line. */
12419 if (line_info->dw_file_num != current_file)
12421 current_file = line_info->dw_file_num;
12422 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12423 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12426 /* Emit debug info for the current line number, choosing the encoding
12427 that uses the least amount of space. */
12428 if (line_info->dw_line_num != current_line)
12430 line_offset = line_info->dw_line_num - current_line;
12431 line_delta = line_offset - DWARF_LINE_BASE;
12432 current_line = line_info->dw_line_num;
12433 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12434 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12435 "line %lu", current_line);
12438 dw2_asm_output_data (1, DW_LNS_advance_line,
12439 "advance to line %lu", current_line);
12440 dw2_asm_output_data_sleb128 (line_offset, NULL);
12441 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12445 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12453 /* If we're done with a function, end its sequence. */
12454 if (lt_index == separate_line_info_table_in_use
12455 || separate_line_info_table[lt_index].function != function)
12460 /* Emit debug info for the address of the end of the function. */
12461 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12464 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12465 "DW_LNS_fixed_advance_pc");
12466 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12470 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12471 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12472 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12473 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12476 /* Output the marker for the end of this sequence. */
12477 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12478 dw2_asm_output_data_uleb128 (1, NULL);
12479 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12483 /* Output the marker for the end of the line number info. */
12484 ASM_OUTPUT_LABEL (asm_out_file, l2);
12487 /* Return the size of the .debug_dcall table for the compilation unit. */
12489 static unsigned long
12490 size_of_dcall_table (void)
12492 unsigned long size;
12495 tree last_poc_decl = NULL;
12497 /* Header: version + debug info section pointer + pointer size. */
12498 size = 2 + DWARF_OFFSET_SIZE + 1;
12500 /* Each entry: code label + DIE offset. */
12501 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12503 gcc_assert (p->targ_die != NULL);
12504 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12505 if (p->poc_decl != last_poc_decl)
12507 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12508 gcc_assert (poc_die);
12509 last_poc_decl = p->poc_decl;
12511 size += (DWARF_OFFSET_SIZE
12512 + size_of_uleb128 (poc_die->die_offset));
12514 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12520 /* Output the direct call table used to disambiguate PC values when
12521 identical function have been merged. */
12524 output_dcall_table (void)
12527 unsigned long dcall_length = size_of_dcall_table ();
12529 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12530 tree last_poc_decl = NULL;
12532 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12533 dw2_asm_output_data (4, 0xffffffff,
12534 "Initial length escape value indicating 64-bit DWARF extension");
12535 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12536 "Length of Direct Call Table");
12537 dw2_asm_output_data (2, 4, "Version number");
12538 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12539 debug_info_section,
12540 "Offset of Compilation Unit Info");
12541 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12543 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12545 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12546 if (p->poc_decl != last_poc_decl)
12548 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12549 last_poc_decl = p->poc_decl;
12552 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12553 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12554 "Caller DIE offset");
12557 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12558 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12559 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12560 "Callee DIE offset");
12564 /* Return the size of the .debug_vcall table for the compilation unit. */
12566 static unsigned long
12567 size_of_vcall_table (void)
12569 unsigned long size;
12573 /* Header: version + pointer size. */
12576 /* Each entry: code label + vtable slot index. */
12577 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12578 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12583 /* Output the virtual call table used to disambiguate PC values when
12584 identical function have been merged. */
12587 output_vcall_table (void)
12590 unsigned long vcall_length = size_of_vcall_table ();
12592 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12594 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12595 dw2_asm_output_data (4, 0xffffffff,
12596 "Initial length escape value indicating 64-bit DWARF extension");
12597 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12598 "Length of Virtual Call Table");
12599 dw2_asm_output_data (2, 4, "Version number");
12600 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12602 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12604 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12605 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12606 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12610 /* Given a pointer to a tree node for some base type, return a pointer to
12611 a DIE that describes the given type.
12613 This routine must only be called for GCC type nodes that correspond to
12614 Dwarf base (fundamental) types. */
12617 base_type_die (tree type)
12619 dw_die_ref base_type_result;
12620 enum dwarf_type encoding;
12622 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12625 /* If this is a subtype that should not be emitted as a subrange type,
12626 use the base type. See subrange_type_for_debug_p. */
12627 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12628 type = TREE_TYPE (type);
12630 switch (TREE_CODE (type))
12633 if ((dwarf_version >= 4 || !dwarf_strict)
12634 && TYPE_NAME (type)
12635 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12636 && DECL_IS_BUILTIN (TYPE_NAME (type))
12637 && DECL_NAME (TYPE_NAME (type)))
12639 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12640 if (strcmp (name, "char16_t") == 0
12641 || strcmp (name, "char32_t") == 0)
12643 encoding = DW_ATE_UTF;
12647 if (TYPE_STRING_FLAG (type))
12649 if (TYPE_UNSIGNED (type))
12650 encoding = DW_ATE_unsigned_char;
12652 encoding = DW_ATE_signed_char;
12654 else if (TYPE_UNSIGNED (type))
12655 encoding = DW_ATE_unsigned;
12657 encoding = DW_ATE_signed;
12661 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12663 if (dwarf_version >= 3 || !dwarf_strict)
12664 encoding = DW_ATE_decimal_float;
12666 encoding = DW_ATE_lo_user;
12669 encoding = DW_ATE_float;
12672 case FIXED_POINT_TYPE:
12673 if (!(dwarf_version >= 3 || !dwarf_strict))
12674 encoding = DW_ATE_lo_user;
12675 else if (TYPE_UNSIGNED (type))
12676 encoding = DW_ATE_unsigned_fixed;
12678 encoding = DW_ATE_signed_fixed;
12681 /* Dwarf2 doesn't know anything about complex ints, so use
12682 a user defined type for it. */
12684 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12685 encoding = DW_ATE_complex_float;
12687 encoding = DW_ATE_lo_user;
12691 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12692 encoding = DW_ATE_boolean;
12696 /* No other TREE_CODEs are Dwarf fundamental types. */
12697 gcc_unreachable ();
12700 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12702 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12703 int_size_in_bytes (type));
12704 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12706 return base_type_result;
12709 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12710 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12713 is_base_type (tree type)
12715 switch (TREE_CODE (type))
12721 case FIXED_POINT_TYPE:
12729 case QUAL_UNION_TYPE:
12730 case ENUMERAL_TYPE:
12731 case FUNCTION_TYPE:
12734 case REFERENCE_TYPE:
12742 gcc_unreachable ();
12748 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12749 node, return the size in bits for the type if it is a constant, or else
12750 return the alignment for the type if the type's size is not constant, or
12751 else return BITS_PER_WORD if the type actually turns out to be an
12752 ERROR_MARK node. */
12754 static inline unsigned HOST_WIDE_INT
12755 simple_type_size_in_bits (const_tree type)
12757 if (TREE_CODE (type) == ERROR_MARK)
12758 return BITS_PER_WORD;
12759 else if (TYPE_SIZE (type) == NULL_TREE)
12761 else if (host_integerp (TYPE_SIZE (type), 1))
12762 return tree_low_cst (TYPE_SIZE (type), 1);
12764 return TYPE_ALIGN (type);
12767 /* Similarly, but return a double_int instead of UHWI. */
12769 static inline double_int
12770 double_int_type_size_in_bits (const_tree type)
12772 if (TREE_CODE (type) == ERROR_MARK)
12773 return uhwi_to_double_int (BITS_PER_WORD);
12774 else if (TYPE_SIZE (type) == NULL_TREE)
12775 return double_int_zero;
12776 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12777 return tree_to_double_int (TYPE_SIZE (type));
12779 return uhwi_to_double_int (TYPE_ALIGN (type));
12782 /* Given a pointer to a tree node for a subrange type, return a pointer
12783 to a DIE that describes the given type. */
12786 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12788 dw_die_ref subrange_die;
12789 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12791 if (context_die == NULL)
12792 context_die = comp_unit_die ();
12794 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12796 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12798 /* The size of the subrange type and its base type do not match,
12799 so we need to generate a size attribute for the subrange type. */
12800 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12804 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12806 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12808 return subrange_die;
12811 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12812 entry that chains various modifiers in front of the given type. */
12815 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12816 dw_die_ref context_die)
12818 enum tree_code code = TREE_CODE (type);
12819 dw_die_ref mod_type_die;
12820 dw_die_ref sub_die = NULL;
12821 tree item_type = NULL;
12822 tree qualified_type;
12823 tree name, low, high;
12825 if (code == ERROR_MARK)
12828 /* See if we already have the appropriately qualified variant of
12831 = get_qualified_type (type,
12832 ((is_const_type ? TYPE_QUAL_CONST : 0)
12833 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12835 if (qualified_type == sizetype
12836 && TYPE_NAME (qualified_type)
12837 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12839 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12841 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12842 && TYPE_PRECISION (t)
12843 == TYPE_PRECISION (qualified_type)
12844 && TYPE_UNSIGNED (t)
12845 == TYPE_UNSIGNED (qualified_type));
12846 qualified_type = t;
12849 /* If we do, then we can just use its DIE, if it exists. */
12850 if (qualified_type)
12852 mod_type_die = lookup_type_die (qualified_type);
12854 return mod_type_die;
12857 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12859 /* Handle C typedef types. */
12860 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12861 && !DECL_ARTIFICIAL (name))
12863 tree dtype = TREE_TYPE (name);
12865 if (qualified_type == dtype)
12867 /* For a named type, use the typedef. */
12868 gen_type_die (qualified_type, context_die);
12869 return lookup_type_die (qualified_type);
12871 else if (is_const_type < TYPE_READONLY (dtype)
12872 || is_volatile_type < TYPE_VOLATILE (dtype)
12873 || (is_const_type <= TYPE_READONLY (dtype)
12874 && is_volatile_type <= TYPE_VOLATILE (dtype)
12875 && DECL_ORIGINAL_TYPE (name) != type))
12876 /* cv-unqualified version of named type. Just use the unnamed
12877 type to which it refers. */
12878 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12879 is_const_type, is_volatile_type,
12881 /* Else cv-qualified version of named type; fall through. */
12886 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12887 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12889 else if (is_volatile_type)
12891 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12892 sub_die = modified_type_die (type, 0, 0, context_die);
12894 else if (code == POINTER_TYPE)
12896 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12897 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12898 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12899 item_type = TREE_TYPE (type);
12900 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12901 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12902 TYPE_ADDR_SPACE (item_type));
12904 else if (code == REFERENCE_TYPE)
12906 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12907 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12910 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12911 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12912 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12913 item_type = TREE_TYPE (type);
12914 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12915 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12916 TYPE_ADDR_SPACE (item_type));
12918 else if (code == INTEGER_TYPE
12919 && TREE_TYPE (type) != NULL_TREE
12920 && subrange_type_for_debug_p (type, &low, &high))
12922 mod_type_die = subrange_type_die (type, low, high, context_die);
12923 item_type = TREE_TYPE (type);
12925 else if (is_base_type (type))
12926 mod_type_die = base_type_die (type);
12929 gen_type_die (type, context_die);
12931 /* We have to get the type_main_variant here (and pass that to the
12932 `lookup_type_die' routine) because the ..._TYPE node we have
12933 might simply be a *copy* of some original type node (where the
12934 copy was created to help us keep track of typedef names) and
12935 that copy might have a different TYPE_UID from the original
12937 if (TREE_CODE (type) != VECTOR_TYPE)
12938 return lookup_type_die (type_main_variant (type));
12940 /* Vectors have the debugging information in the type,
12941 not the main variant. */
12942 return lookup_type_die (type);
12945 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12946 don't output a DW_TAG_typedef, since there isn't one in the
12947 user's program; just attach a DW_AT_name to the type.
12948 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12949 if the base type already has the same name. */
12951 && ((TREE_CODE (name) != TYPE_DECL
12952 && (qualified_type == TYPE_MAIN_VARIANT (type)
12953 || (!is_const_type && !is_volatile_type)))
12954 || (TREE_CODE (name) == TYPE_DECL
12955 && TREE_TYPE (name) == qualified_type
12956 && DECL_NAME (name))))
12958 if (TREE_CODE (name) == TYPE_DECL)
12959 /* Could just call add_name_and_src_coords_attributes here,
12960 but since this is a builtin type it doesn't have any
12961 useful source coordinates anyway. */
12962 name = DECL_NAME (name);
12963 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12965 /* This probably indicates a bug. */
12966 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12967 add_name_attribute (mod_type_die, "__unknown__");
12969 if (qualified_type)
12970 equate_type_number_to_die (qualified_type, mod_type_die);
12973 /* We must do this after the equate_type_number_to_die call, in case
12974 this is a recursive type. This ensures that the modified_type_die
12975 recursion will terminate even if the type is recursive. Recursive
12976 types are possible in Ada. */
12977 sub_die = modified_type_die (item_type,
12978 TYPE_READONLY (item_type),
12979 TYPE_VOLATILE (item_type),
12982 if (sub_die != NULL)
12983 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12985 return mod_type_die;
12988 /* Generate DIEs for the generic parameters of T.
12989 T must be either a generic type or a generic function.
12990 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12993 gen_generic_params_dies (tree t)
12997 dw_die_ref die = NULL;
12999 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13003 die = lookup_type_die (t);
13004 else if (DECL_P (t))
13005 die = lookup_decl_die (t);
13009 parms = lang_hooks.get_innermost_generic_parms (t);
13011 /* T has no generic parameter. It means T is neither a generic type
13012 or function. End of story. */
13015 parms_num = TREE_VEC_LENGTH (parms);
13016 args = lang_hooks.get_innermost_generic_args (t);
13017 for (i = 0; i < parms_num; i++)
13019 tree parm, arg, arg_pack_elems;
13021 parm = TREE_VEC_ELT (parms, i);
13022 arg = TREE_VEC_ELT (args, i);
13023 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13024 gcc_assert (parm && TREE_VALUE (parm) && arg);
13026 if (parm && TREE_VALUE (parm) && arg)
13028 /* If PARM represents a template parameter pack,
13029 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13030 by DW_TAG_template_*_parameter DIEs for the argument
13031 pack elements of ARG. Note that ARG would then be
13032 an argument pack. */
13033 if (arg_pack_elems)
13034 template_parameter_pack_die (TREE_VALUE (parm),
13038 generic_parameter_die (TREE_VALUE (parm), arg,
13039 true /* Emit DW_AT_name */, die);
13044 /* Create and return a DIE for PARM which should be
13045 the representation of a generic type parameter.
13046 For instance, in the C++ front end, PARM would be a template parameter.
13047 ARG is the argument to PARM.
13048 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13050 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13051 as a child node. */
13054 generic_parameter_die (tree parm, tree arg,
13056 dw_die_ref parent_die)
13058 dw_die_ref tmpl_die = NULL;
13059 const char *name = NULL;
13061 if (!parm || !DECL_NAME (parm) || !arg)
13064 /* We support non-type generic parameters and arguments,
13065 type generic parameters and arguments, as well as
13066 generic generic parameters (a.k.a. template template parameters in C++)
13068 if (TREE_CODE (parm) == PARM_DECL)
13069 /* PARM is a nontype generic parameter */
13070 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13071 else if (TREE_CODE (parm) == TYPE_DECL)
13072 /* PARM is a type generic parameter. */
13073 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13074 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13075 /* PARM is a generic generic parameter.
13076 Its DIE is a GNU extension. It shall have a
13077 DW_AT_name attribute to represent the name of the template template
13078 parameter, and a DW_AT_GNU_template_name attribute to represent the
13079 name of the template template argument. */
13080 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13083 gcc_unreachable ();
13089 /* If PARM is a generic parameter pack, it means we are
13090 emitting debug info for a template argument pack element.
13091 In other terms, ARG is a template argument pack element.
13092 In that case, we don't emit any DW_AT_name attribute for
13096 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13098 add_AT_string (tmpl_die, DW_AT_name, name);
13101 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13103 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13104 TMPL_DIE should have a child DW_AT_type attribute that is set
13105 to the type of the argument to PARM, which is ARG.
13106 If PARM is a type generic parameter, TMPL_DIE should have a
13107 child DW_AT_type that is set to ARG. */
13108 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13109 add_type_attribute (tmpl_die, tmpl_type, 0,
13110 TREE_THIS_VOLATILE (tmpl_type),
13115 /* So TMPL_DIE is a DIE representing a
13116 a generic generic template parameter, a.k.a template template
13117 parameter in C++ and arg is a template. */
13119 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13120 to the name of the argument. */
13121 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13123 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13126 if (TREE_CODE (parm) == PARM_DECL)
13127 /* So PARM is a non-type generic parameter.
13128 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13129 attribute of TMPL_DIE which value represents the value
13131 We must be careful here:
13132 The value of ARG might reference some function decls.
13133 We might currently be emitting debug info for a generic
13134 type and types are emitted before function decls, we don't
13135 know if the function decls referenced by ARG will actually be
13136 emitted after cgraph computations.
13137 So must defer the generation of the DW_AT_const_value to
13138 after cgraph is ready. */
13139 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13145 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13146 PARM_PACK must be a template parameter pack. The returned DIE
13147 will be child DIE of PARENT_DIE. */
13150 template_parameter_pack_die (tree parm_pack,
13151 tree parm_pack_args,
13152 dw_die_ref parent_die)
13157 gcc_assert (parent_die && parm_pack);
13159 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13160 add_name_and_src_coords_attributes (die, parm_pack);
13161 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13162 generic_parameter_die (parm_pack,
13163 TREE_VEC_ELT (parm_pack_args, j),
13164 false /* Don't emit DW_AT_name */,
13169 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13170 an enumerated type. */
13173 type_is_enum (const_tree type)
13175 return TREE_CODE (type) == ENUMERAL_TYPE;
13178 /* Return the DBX register number described by a given RTL node. */
13180 static unsigned int
13181 dbx_reg_number (const_rtx rtl)
13183 unsigned regno = REGNO (rtl);
13185 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13187 #ifdef LEAF_REG_REMAP
13188 if (current_function_uses_only_leaf_regs)
13190 int leaf_reg = LEAF_REG_REMAP (regno);
13191 if (leaf_reg != -1)
13192 regno = (unsigned) leaf_reg;
13196 return DBX_REGISTER_NUMBER (regno);
13199 /* Optionally add a DW_OP_piece term to a location description expression.
13200 DW_OP_piece is only added if the location description expression already
13201 doesn't end with DW_OP_piece. */
13204 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13206 dw_loc_descr_ref loc;
13208 if (*list_head != NULL)
13210 /* Find the end of the chain. */
13211 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13214 if (loc->dw_loc_opc != DW_OP_piece)
13215 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13219 /* Return a location descriptor that designates a machine register or
13220 zero if there is none. */
13222 static dw_loc_descr_ref
13223 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13227 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13230 /* We only use "frame base" when we're sure we're talking about the
13231 post-prologue local stack frame. We do this by *not* running
13232 register elimination until this point, and recognizing the special
13233 argument pointer and soft frame pointer rtx's.
13234 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13235 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13236 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13238 dw_loc_descr_ref result = NULL;
13240 if (dwarf_version >= 4 || !dwarf_strict)
13242 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13244 add_loc_descr (&result,
13245 new_loc_descr (DW_OP_stack_value, 0, 0));
13250 regs = targetm.dwarf_register_span (rtl);
13252 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13253 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13255 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13258 /* Return a location descriptor that designates a machine register for
13259 a given hard register number. */
13261 static dw_loc_descr_ref
13262 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13264 dw_loc_descr_ref reg_loc_descr;
13268 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13270 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13272 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13273 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13275 return reg_loc_descr;
13278 /* Given an RTL of a register, return a location descriptor that
13279 designates a value that spans more than one register. */
13281 static dw_loc_descr_ref
13282 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13283 enum var_init_status initialized)
13285 int nregs, size, i;
13287 dw_loc_descr_ref loc_result = NULL;
13290 #ifdef LEAF_REG_REMAP
13291 if (current_function_uses_only_leaf_regs)
13293 int leaf_reg = LEAF_REG_REMAP (reg);
13294 if (leaf_reg != -1)
13295 reg = (unsigned) leaf_reg;
13298 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13299 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13301 /* Simple, contiguous registers. */
13302 if (regs == NULL_RTX)
13304 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13309 dw_loc_descr_ref t;
13311 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13312 VAR_INIT_STATUS_INITIALIZED);
13313 add_loc_descr (&loc_result, t);
13314 add_loc_descr_op_piece (&loc_result, size);
13320 /* Now onto stupid register sets in non contiguous locations. */
13322 gcc_assert (GET_CODE (regs) == PARALLEL);
13324 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13327 for (i = 0; i < XVECLEN (regs, 0); ++i)
13329 dw_loc_descr_ref t;
13331 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13332 VAR_INIT_STATUS_INITIALIZED);
13333 add_loc_descr (&loc_result, t);
13334 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13335 add_loc_descr_op_piece (&loc_result, size);
13338 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13339 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13343 /* Return a location descriptor that designates a constant. */
13345 static dw_loc_descr_ref
13346 int_loc_descriptor (HOST_WIDE_INT i)
13348 enum dwarf_location_atom op;
13350 /* Pick the smallest representation of a constant, rather than just
13351 defaulting to the LEB encoding. */
13355 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13356 else if (i <= 0xff)
13357 op = DW_OP_const1u;
13358 else if (i <= 0xffff)
13359 op = DW_OP_const2u;
13360 else if (HOST_BITS_PER_WIDE_INT == 32
13361 || i <= 0xffffffff)
13362 op = DW_OP_const4u;
13369 op = DW_OP_const1s;
13370 else if (i >= -0x8000)
13371 op = DW_OP_const2s;
13372 else if (HOST_BITS_PER_WIDE_INT == 32
13373 || i >= -0x80000000)
13374 op = DW_OP_const4s;
13379 return new_loc_descr (op, i, 0);
13382 /* Return loc description representing "address" of integer value.
13383 This can appear only as toplevel expression. */
13385 static dw_loc_descr_ref
13386 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13389 dw_loc_descr_ref loc_result = NULL;
13391 if (!(dwarf_version >= 4 || !dwarf_strict))
13398 else if (i <= 0xff)
13400 else if (i <= 0xffff)
13402 else if (HOST_BITS_PER_WIDE_INT == 32
13403 || i <= 0xffffffff)
13406 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13412 else if (i >= -0x8000)
13414 else if (HOST_BITS_PER_WIDE_INT == 32
13415 || i >= -0x80000000)
13418 litsize = 1 + size_of_sleb128 (i);
13420 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13421 is more compact. For DW_OP_stack_value we need:
13422 litsize + 1 (DW_OP_stack_value)
13423 and for DW_OP_implicit_value:
13424 1 (DW_OP_implicit_value) + 1 (length) + size. */
13425 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13427 loc_result = int_loc_descriptor (i);
13428 add_loc_descr (&loc_result,
13429 new_loc_descr (DW_OP_stack_value, 0, 0));
13433 loc_result = new_loc_descr (DW_OP_implicit_value,
13435 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13436 loc_result->dw_loc_oprnd2.v.val_int = i;
13440 /* Return a location descriptor that designates a base+offset location. */
13442 static dw_loc_descr_ref
13443 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13444 enum var_init_status initialized)
13446 unsigned int regno;
13447 dw_loc_descr_ref result;
13448 dw_fde_ref fde = current_fde ();
13450 /* We only use "frame base" when we're sure we're talking about the
13451 post-prologue local stack frame. We do this by *not* running
13452 register elimination until this point, and recognizing the special
13453 argument pointer and soft frame pointer rtx's. */
13454 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13456 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13460 if (GET_CODE (elim) == PLUS)
13462 offset += INTVAL (XEXP (elim, 1));
13463 elim = XEXP (elim, 0);
13465 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13466 && (elim == hard_frame_pointer_rtx
13467 || elim == stack_pointer_rtx))
13468 || elim == (frame_pointer_needed
13469 ? hard_frame_pointer_rtx
13470 : stack_pointer_rtx));
13472 /* If drap register is used to align stack, use frame
13473 pointer + offset to access stack variables. If stack
13474 is aligned without drap, use stack pointer + offset to
13475 access stack variables. */
13476 if (crtl->stack_realign_tried
13477 && reg == frame_pointer_rtx)
13480 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13481 ? HARD_FRAME_POINTER_REGNUM
13482 : STACK_POINTER_REGNUM);
13483 return new_reg_loc_descr (base_reg, offset);
13486 offset += frame_pointer_fb_offset;
13487 return new_loc_descr (DW_OP_fbreg, offset, 0);
13492 && (fde->drap_reg == REGNO (reg)
13493 || fde->vdrap_reg == REGNO (reg)))
13495 /* Use cfa+offset to represent the location of arguments passed
13496 on the stack when drap is used to align stack.
13497 Only do this when not optimizing, for optimized code var-tracking
13498 is supposed to track where the arguments live and the register
13499 used as vdrap or drap in some spot might be used for something
13500 else in other part of the routine. */
13501 return new_loc_descr (DW_OP_fbreg, offset, 0);
13504 regno = dbx_reg_number (reg);
13506 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13509 result = new_loc_descr (DW_OP_bregx, regno, offset);
13511 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13512 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13517 /* Return true if this RTL expression describes a base+offset calculation. */
13520 is_based_loc (const_rtx rtl)
13522 return (GET_CODE (rtl) == PLUS
13523 && ((REG_P (XEXP (rtl, 0))
13524 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13525 && CONST_INT_P (XEXP (rtl, 1)))));
13528 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13531 static dw_loc_descr_ref
13532 tls_mem_loc_descriptor (rtx mem)
13535 dw_loc_descr_ref loc_result;
13537 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13540 base = get_base_address (MEM_EXPR (mem));
13542 || TREE_CODE (base) != VAR_DECL
13543 || !DECL_THREAD_LOCAL_P (base))
13546 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13547 if (loc_result == NULL)
13550 if (INTVAL (MEM_OFFSET (mem)))
13551 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13556 /* Output debug info about reason why we failed to expand expression as dwarf
13560 expansion_failed (tree expr, rtx rtl, char const *reason)
13562 if (dump_file && (dump_flags & TDF_DETAILS))
13564 fprintf (dump_file, "Failed to expand as dwarf: ");
13566 print_generic_expr (dump_file, expr, dump_flags);
13569 fprintf (dump_file, "\n");
13570 print_rtl (dump_file, rtl);
13572 fprintf (dump_file, "\nReason: %s\n", reason);
13576 /* Helper function for const_ok_for_output, called either directly
13577 or via for_each_rtx. */
13580 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13584 if (GET_CODE (rtl) == UNSPEC)
13586 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13587 we can't express it in the debug info. */
13588 #ifdef ENABLE_CHECKING
13589 /* Don't complain about TLS UNSPECs, those are just too hard to
13591 if (XVECLEN (rtl, 0) != 1
13592 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13593 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13594 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13595 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13596 inform (current_function_decl
13597 ? DECL_SOURCE_LOCATION (current_function_decl)
13598 : UNKNOWN_LOCATION,
13599 "non-delegitimized UNSPEC %d found in variable location",
13602 expansion_failed (NULL_TREE, rtl,
13603 "UNSPEC hasn't been delegitimized.\n");
13607 if (GET_CODE (rtl) != SYMBOL_REF)
13610 if (CONSTANT_POOL_ADDRESS_P (rtl))
13613 get_pool_constant_mark (rtl, &marked);
13614 /* If all references to this pool constant were optimized away,
13615 it was not output and thus we can't represent it. */
13618 expansion_failed (NULL_TREE, rtl,
13619 "Constant was removed from constant pool.\n");
13624 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13627 /* Avoid references to external symbols in debug info, on several targets
13628 the linker might even refuse to link when linking a shared library,
13629 and in many other cases the relocations for .debug_info/.debug_loc are
13630 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13631 to be defined within the same shared library or executable are fine. */
13632 if (SYMBOL_REF_EXTERNAL_P (rtl))
13634 tree decl = SYMBOL_REF_DECL (rtl);
13636 if (decl == NULL || !targetm.binds_local_p (decl))
13638 expansion_failed (NULL_TREE, rtl,
13639 "Symbol not defined in current TU.\n");
13647 /* Return true if constant RTL can be emitted in DW_OP_addr or
13648 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13649 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13652 const_ok_for_output (rtx rtl)
13654 if (GET_CODE (rtl) == SYMBOL_REF)
13655 return const_ok_for_output_1 (&rtl, NULL) == 0;
13657 if (GET_CODE (rtl) == CONST)
13658 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13663 /* The following routine converts the RTL for a variable or parameter
13664 (resident in memory) into an equivalent Dwarf representation of a
13665 mechanism for getting the address of that same variable onto the top of a
13666 hypothetical "address evaluation" stack.
13668 When creating memory location descriptors, we are effectively transforming
13669 the RTL for a memory-resident object into its Dwarf postfix expression
13670 equivalent. This routine recursively descends an RTL tree, turning
13671 it into Dwarf postfix code as it goes.
13673 MODE is the mode of the memory reference, needed to handle some
13674 autoincrement addressing modes.
13676 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13677 location list for RTL.
13679 Return 0 if we can't represent the location. */
13681 static dw_loc_descr_ref
13682 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13683 enum var_init_status initialized)
13685 dw_loc_descr_ref mem_loc_result = NULL;
13686 enum dwarf_location_atom op;
13687 dw_loc_descr_ref op0, op1;
13689 /* Note that for a dynamically sized array, the location we will generate a
13690 description of here will be the lowest numbered location which is
13691 actually within the array. That's *not* necessarily the same as the
13692 zeroth element of the array. */
13694 rtl = targetm.delegitimize_address (rtl);
13696 switch (GET_CODE (rtl))
13701 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13704 /* The case of a subreg may arise when we have a local (register)
13705 variable or a formal (register) parameter which doesn't quite fill
13706 up an entire register. For now, just assume that it is
13707 legitimate to make the Dwarf info refer to the whole register which
13708 contains the given subreg. */
13709 if (!subreg_lowpart_p (rtl))
13711 rtl = SUBREG_REG (rtl);
13712 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13714 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13716 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13720 /* Whenever a register number forms a part of the description of the
13721 method for calculating the (dynamic) address of a memory resident
13722 object, DWARF rules require the register number be referred to as
13723 a "base register". This distinction is not based in any way upon
13724 what category of register the hardware believes the given register
13725 belongs to. This is strictly DWARF terminology we're dealing with
13726 here. Note that in cases where the location of a memory-resident
13727 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13728 OP_CONST (0)) the actual DWARF location descriptor that we generate
13729 may just be OP_BASEREG (basereg). This may look deceptively like
13730 the object in question was allocated to a register (rather than in
13731 memory) so DWARF consumers need to be aware of the subtle
13732 distinction between OP_REG and OP_BASEREG. */
13733 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13734 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13735 else if (stack_realign_drap
13737 && crtl->args.internal_arg_pointer == rtl
13738 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13740 /* If RTL is internal_arg_pointer, which has been optimized
13741 out, use DRAP instead. */
13742 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13743 VAR_INIT_STATUS_INITIALIZED);
13749 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13750 VAR_INIT_STATUS_INITIALIZED);
13755 int shift = DWARF2_ADDR_SIZE
13756 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13757 shift *= BITS_PER_UNIT;
13758 if (GET_CODE (rtl) == SIGN_EXTEND)
13762 mem_loc_result = op0;
13763 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13764 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13765 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13766 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13771 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13772 VAR_INIT_STATUS_INITIALIZED);
13773 if (mem_loc_result == NULL)
13774 mem_loc_result = tls_mem_loc_descriptor (rtl);
13775 if (mem_loc_result != 0)
13777 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13779 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13782 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13783 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13785 add_loc_descr (&mem_loc_result,
13786 new_loc_descr (DW_OP_deref_size,
13787 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13791 rtx new_rtl = avoid_constant_pool_reference (rtl);
13792 if (new_rtl != rtl)
13793 return mem_loc_descriptor (new_rtl, mode, initialized);
13798 rtl = XEXP (rtl, 1);
13800 /* ... fall through ... */
13803 /* Some ports can transform a symbol ref into a label ref, because
13804 the symbol ref is too far away and has to be dumped into a constant
13808 if (GET_CODE (rtl) == SYMBOL_REF
13809 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13811 dw_loc_descr_ref temp;
13813 /* If this is not defined, we have no way to emit the data. */
13814 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13817 /* We used to emit DW_OP_addr here, but that's wrong, since
13818 DW_OP_addr should be relocated by the debug info consumer,
13819 while DW_OP_GNU_push_tls_address operand should not. */
13820 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13821 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13822 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13823 temp->dw_loc_oprnd1.v.val_addr = rtl;
13824 temp->dtprel = true;
13826 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13827 add_loc_descr (&mem_loc_result, temp);
13832 if (!const_ok_for_output (rtl))
13836 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13837 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13838 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13839 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13845 case DEBUG_IMPLICIT_PTR:
13846 expansion_failed (NULL_TREE, rtl,
13847 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13851 /* Extract the PLUS expression nested inside and fall into
13852 PLUS code below. */
13853 rtl = XEXP (rtl, 1);
13858 /* Turn these into a PLUS expression and fall into the PLUS code
13860 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13861 GEN_INT (GET_CODE (rtl) == PRE_INC
13862 ? GET_MODE_UNIT_SIZE (mode)
13863 : -GET_MODE_UNIT_SIZE (mode)));
13865 /* ... fall through ... */
13869 if (is_based_loc (rtl))
13870 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13871 INTVAL (XEXP (rtl, 1)),
13872 VAR_INIT_STATUS_INITIALIZED);
13875 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13876 VAR_INIT_STATUS_INITIALIZED);
13877 if (mem_loc_result == 0)
13880 if (CONST_INT_P (XEXP (rtl, 1)))
13881 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13884 dw_loc_descr_ref mem_loc_result2
13885 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13886 VAR_INIT_STATUS_INITIALIZED);
13887 if (mem_loc_result2 == 0)
13889 add_loc_descr (&mem_loc_result, mem_loc_result2);
13890 add_loc_descr (&mem_loc_result,
13891 new_loc_descr (DW_OP_plus, 0, 0));
13896 /* If a pseudo-reg is optimized away, it is possible for it to
13897 be replaced with a MEM containing a multiply or shift. */
13939 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13940 VAR_INIT_STATUS_INITIALIZED);
13941 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13942 VAR_INIT_STATUS_INITIALIZED);
13944 if (op0 == 0 || op1 == 0)
13947 mem_loc_result = op0;
13948 add_loc_descr (&mem_loc_result, op1);
13949 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13953 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13954 VAR_INIT_STATUS_INITIALIZED);
13955 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13956 VAR_INIT_STATUS_INITIALIZED);
13958 if (op0 == 0 || op1 == 0)
13961 mem_loc_result = op0;
13962 add_loc_descr (&mem_loc_result, op1);
13963 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13964 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13965 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13966 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13967 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13983 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13984 VAR_INIT_STATUS_INITIALIZED);
13989 mem_loc_result = op0;
13990 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13994 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14022 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14023 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14027 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14029 if (op_mode == VOIDmode)
14030 op_mode = GET_MODE (XEXP (rtl, 1));
14031 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14034 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14035 VAR_INIT_STATUS_INITIALIZED);
14036 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14037 VAR_INIT_STATUS_INITIALIZED);
14039 if (op0 == 0 || op1 == 0)
14042 if (op_mode != VOIDmode
14043 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14045 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14046 shift *= BITS_PER_UNIT;
14047 /* For eq/ne, if the operands are known to be zero-extended,
14048 there is no need to do the fancy shifting up. */
14049 if (op == DW_OP_eq || op == DW_OP_ne)
14051 dw_loc_descr_ref last0, last1;
14053 last0->dw_loc_next != NULL;
14054 last0 = last0->dw_loc_next)
14057 last1->dw_loc_next != NULL;
14058 last1 = last1->dw_loc_next)
14060 /* deref_size zero extends, and for constants we can check
14061 whether they are zero extended or not. */
14062 if (((last0->dw_loc_opc == DW_OP_deref_size
14063 && last0->dw_loc_oprnd1.v.val_int
14064 <= GET_MODE_SIZE (op_mode))
14065 || (CONST_INT_P (XEXP (rtl, 0))
14066 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14067 == (INTVAL (XEXP (rtl, 0))
14068 & GET_MODE_MASK (op_mode))))
14069 && ((last1->dw_loc_opc == DW_OP_deref_size
14070 && last1->dw_loc_oprnd1.v.val_int
14071 <= GET_MODE_SIZE (op_mode))
14072 || (CONST_INT_P (XEXP (rtl, 1))
14073 && (unsigned HOST_WIDE_INT)
14074 INTVAL (XEXP (rtl, 1))
14075 == (INTVAL (XEXP (rtl, 1))
14076 & GET_MODE_MASK (op_mode)))))
14079 add_loc_descr (&op0, int_loc_descriptor (shift));
14080 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14081 if (CONST_INT_P (XEXP (rtl, 1)))
14082 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14085 add_loc_descr (&op1, int_loc_descriptor (shift));
14086 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14092 mem_loc_result = op0;
14093 add_loc_descr (&mem_loc_result, op1);
14094 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14095 if (STORE_FLAG_VALUE != 1)
14097 add_loc_descr (&mem_loc_result,
14098 int_loc_descriptor (STORE_FLAG_VALUE));
14099 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14120 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14121 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14125 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14127 if (op_mode == VOIDmode)
14128 op_mode = GET_MODE (XEXP (rtl, 1));
14129 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14132 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14133 VAR_INIT_STATUS_INITIALIZED);
14134 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14135 VAR_INIT_STATUS_INITIALIZED);
14137 if (op0 == 0 || op1 == 0)
14140 if (op_mode != VOIDmode
14141 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14143 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14144 dw_loc_descr_ref last0, last1;
14146 last0->dw_loc_next != NULL;
14147 last0 = last0->dw_loc_next)
14150 last1->dw_loc_next != NULL;
14151 last1 = last1->dw_loc_next)
14153 if (CONST_INT_P (XEXP (rtl, 0)))
14154 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14155 /* deref_size zero extends, so no need to mask it again. */
14156 else if (last0->dw_loc_opc != DW_OP_deref_size
14157 || last0->dw_loc_oprnd1.v.val_int
14158 > GET_MODE_SIZE (op_mode))
14160 add_loc_descr (&op0, int_loc_descriptor (mask));
14161 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14163 if (CONST_INT_P (XEXP (rtl, 1)))
14164 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14165 /* deref_size zero extends, so no need to mask it again. */
14166 else if (last1->dw_loc_opc != DW_OP_deref_size
14167 || last1->dw_loc_oprnd1.v.val_int
14168 > GET_MODE_SIZE (op_mode))
14170 add_loc_descr (&op1, int_loc_descriptor (mask));
14171 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14176 HOST_WIDE_INT bias = 1;
14177 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14178 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14179 if (CONST_INT_P (XEXP (rtl, 1)))
14180 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14181 + INTVAL (XEXP (rtl, 1)));
14183 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14193 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14194 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14195 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14198 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14199 VAR_INIT_STATUS_INITIALIZED);
14200 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14201 VAR_INIT_STATUS_INITIALIZED);
14203 if (op0 == 0 || op1 == 0)
14206 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14207 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14208 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14209 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14211 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14213 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14214 add_loc_descr (&op0, int_loc_descriptor (mask));
14215 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14216 add_loc_descr (&op1, int_loc_descriptor (mask));
14217 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14221 HOST_WIDE_INT bias = 1;
14222 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14223 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14224 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14227 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14229 int shift = DWARF2_ADDR_SIZE
14230 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14231 shift *= BITS_PER_UNIT;
14232 add_loc_descr (&op0, int_loc_descriptor (shift));
14233 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14234 add_loc_descr (&op1, int_loc_descriptor (shift));
14235 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14238 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14242 mem_loc_result = op0;
14243 add_loc_descr (&mem_loc_result, op1);
14244 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14246 dw_loc_descr_ref bra_node, drop_node;
14248 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14249 add_loc_descr (&mem_loc_result, bra_node);
14250 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14251 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14252 add_loc_descr (&mem_loc_result, drop_node);
14253 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14254 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14260 if (CONST_INT_P (XEXP (rtl, 1))
14261 && CONST_INT_P (XEXP (rtl, 2))
14262 && ((unsigned) INTVAL (XEXP (rtl, 1))
14263 + (unsigned) INTVAL (XEXP (rtl, 2))
14264 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14265 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14266 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14269 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14270 VAR_INIT_STATUS_INITIALIZED);
14273 if (GET_CODE (rtl) == SIGN_EXTRACT)
14277 mem_loc_result = op0;
14278 size = INTVAL (XEXP (rtl, 1));
14279 shift = INTVAL (XEXP (rtl, 2));
14280 if (BITS_BIG_ENDIAN)
14281 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14283 if (shift + size != (int) DWARF2_ADDR_SIZE)
14285 add_loc_descr (&mem_loc_result,
14286 int_loc_descriptor (DWARF2_ADDR_SIZE
14288 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14290 if (size != (int) DWARF2_ADDR_SIZE)
14292 add_loc_descr (&mem_loc_result,
14293 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14294 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14301 dw_loc_descr_ref op2, bra_node, drop_node;
14302 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14303 VAR_INIT_STATUS_INITIALIZED);
14304 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14305 VAR_INIT_STATUS_INITIALIZED);
14306 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14307 VAR_INIT_STATUS_INITIALIZED);
14308 if (op0 == NULL || op1 == NULL || op2 == NULL)
14311 mem_loc_result = op1;
14312 add_loc_descr (&mem_loc_result, op2);
14313 add_loc_descr (&mem_loc_result, op0);
14314 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14315 add_loc_descr (&mem_loc_result, bra_node);
14316 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14317 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14318 add_loc_descr (&mem_loc_result, drop_node);
14319 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14320 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14328 /* In theory, we could implement the above. */
14329 /* DWARF cannot represent the unsigned compare operations
14356 case FLOAT_TRUNCATE:
14358 case UNSIGNED_FLOAT:
14361 case FRACT_CONVERT:
14362 case UNSIGNED_FRACT_CONVERT:
14364 case UNSIGNED_SAT_FRACT:
14376 case VEC_DUPLICATE:
14379 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14380 can't express it in the debug info. This can happen e.g. with some
14385 resolve_one_addr (&rtl, NULL);
14389 #ifdef ENABLE_CHECKING
14390 print_rtl (stderr, rtl);
14391 gcc_unreachable ();
14397 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14398 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14400 return mem_loc_result;
14403 /* Return a descriptor that describes the concatenation of two locations.
14404 This is typically a complex variable. */
14406 static dw_loc_descr_ref
14407 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14409 dw_loc_descr_ref cc_loc_result = NULL;
14410 dw_loc_descr_ref x0_ref
14411 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14412 dw_loc_descr_ref x1_ref
14413 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14415 if (x0_ref == 0 || x1_ref == 0)
14418 cc_loc_result = x0_ref;
14419 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14421 add_loc_descr (&cc_loc_result, x1_ref);
14422 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14424 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14425 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14427 return cc_loc_result;
14430 /* Return a descriptor that describes the concatenation of N
14433 static dw_loc_descr_ref
14434 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14437 dw_loc_descr_ref cc_loc_result = NULL;
14438 unsigned int n = XVECLEN (concatn, 0);
14440 for (i = 0; i < n; ++i)
14442 dw_loc_descr_ref ref;
14443 rtx x = XVECEXP (concatn, 0, i);
14445 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14449 add_loc_descr (&cc_loc_result, ref);
14450 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14453 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14454 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14456 return cc_loc_result;
14459 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14460 for DEBUG_IMPLICIT_PTR RTL. */
14462 static dw_loc_descr_ref
14463 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14465 dw_loc_descr_ref ret;
14470 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14471 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14472 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14473 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14474 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14475 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14478 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14479 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14480 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14484 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14485 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14490 /* Output a proper Dwarf location descriptor for a variable or parameter
14491 which is either allocated in a register or in a memory location. For a
14492 register, we just generate an OP_REG and the register number. For a
14493 memory location we provide a Dwarf postfix expression describing how to
14494 generate the (dynamic) address of the object onto the address stack.
14496 MODE is mode of the decl if this loc_descriptor is going to be used in
14497 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14498 allowed, VOIDmode otherwise.
14500 If we don't know how to describe it, return 0. */
14502 static dw_loc_descr_ref
14503 loc_descriptor (rtx rtl, enum machine_mode mode,
14504 enum var_init_status initialized)
14506 dw_loc_descr_ref loc_result = NULL;
14508 switch (GET_CODE (rtl))
14511 /* The case of a subreg may arise when we have a local (register)
14512 variable or a formal (register) parameter which doesn't quite fill
14513 up an entire register. For now, just assume that it is
14514 legitimate to make the Dwarf info refer to the whole register which
14515 contains the given subreg. */
14516 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14520 loc_result = reg_loc_descriptor (rtl, initialized);
14524 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14526 if (loc_result == NULL)
14527 loc_result = tls_mem_loc_descriptor (rtl);
14528 if (loc_result == NULL)
14530 rtx new_rtl = avoid_constant_pool_reference (rtl);
14531 if (new_rtl != rtl)
14532 loc_result = loc_descriptor (new_rtl, mode, initialized);
14537 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14542 loc_result = concatn_loc_descriptor (rtl, initialized);
14547 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14549 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14550 if (GET_CODE (loc) == EXPR_LIST)
14551 loc = XEXP (loc, 0);
14552 loc_result = loc_descriptor (loc, mode, initialized);
14556 rtl = XEXP (rtl, 1);
14561 rtvec par_elems = XVEC (rtl, 0);
14562 int num_elem = GET_NUM_ELEM (par_elems);
14563 enum machine_mode mode;
14566 /* Create the first one, so we have something to add to. */
14567 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14568 VOIDmode, initialized);
14569 if (loc_result == NULL)
14571 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14572 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14573 for (i = 1; i < num_elem; i++)
14575 dw_loc_descr_ref temp;
14577 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14578 VOIDmode, initialized);
14581 add_loc_descr (&loc_result, temp);
14582 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14583 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14589 if (mode != VOIDmode && mode != BLKmode)
14590 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14595 if (mode == VOIDmode)
14596 mode = GET_MODE (rtl);
14598 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14600 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14602 /* Note that a CONST_DOUBLE rtx could represent either an integer
14603 or a floating-point constant. A CONST_DOUBLE is used whenever
14604 the constant requires more than one word in order to be
14605 adequately represented. We output CONST_DOUBLEs as blocks. */
14606 loc_result = new_loc_descr (DW_OP_implicit_value,
14607 GET_MODE_SIZE (mode), 0);
14608 if (SCALAR_FLOAT_MODE_P (mode))
14610 unsigned int length = GET_MODE_SIZE (mode);
14611 unsigned char *array
14612 = (unsigned char*) ggc_alloc_atomic (length);
14614 insert_float (rtl, array);
14615 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14616 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14617 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14618 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14622 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14623 loc_result->dw_loc_oprnd2.v.val_double
14624 = rtx_to_double_int (rtl);
14630 if (mode == VOIDmode)
14631 mode = GET_MODE (rtl);
14633 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14635 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14636 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14637 unsigned char *array = (unsigned char *)
14638 ggc_alloc_atomic (length * elt_size);
14642 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14643 switch (GET_MODE_CLASS (mode))
14645 case MODE_VECTOR_INT:
14646 for (i = 0, p = array; i < length; i++, p += elt_size)
14648 rtx elt = CONST_VECTOR_ELT (rtl, i);
14649 double_int val = rtx_to_double_int (elt);
14651 if (elt_size <= sizeof (HOST_WIDE_INT))
14652 insert_int (double_int_to_shwi (val), elt_size, p);
14655 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14656 insert_double (val, p);
14661 case MODE_VECTOR_FLOAT:
14662 for (i = 0, p = array; i < length; i++, p += elt_size)
14664 rtx elt = CONST_VECTOR_ELT (rtl, i);
14665 insert_float (elt, p);
14670 gcc_unreachable ();
14673 loc_result = new_loc_descr (DW_OP_implicit_value,
14674 length * elt_size, 0);
14675 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14676 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14677 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14678 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14683 if (mode == VOIDmode
14684 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14685 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14686 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14688 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14693 if (!const_ok_for_output (rtl))
14696 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14697 && (dwarf_version >= 4 || !dwarf_strict))
14699 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14700 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14701 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14702 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14703 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14707 case DEBUG_IMPLICIT_PTR:
14708 loc_result = implicit_ptr_descriptor (rtl, 0);
14712 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14713 && CONST_INT_P (XEXP (rtl, 1)))
14716 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14721 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14722 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14723 && (dwarf_version >= 4 || !dwarf_strict))
14725 /* Value expression. */
14726 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14728 add_loc_descr (&loc_result,
14729 new_loc_descr (DW_OP_stack_value, 0, 0));
14737 /* We need to figure out what section we should use as the base for the
14738 address ranges where a given location is valid.
14739 1. If this particular DECL has a section associated with it, use that.
14740 2. If this function has a section associated with it, use that.
14741 3. Otherwise, use the text section.
14742 XXX: If you split a variable across multiple sections, we won't notice. */
14744 static const char *
14745 secname_for_decl (const_tree decl)
14747 const char *secname;
14749 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14751 tree sectree = DECL_SECTION_NAME (decl);
14752 secname = TREE_STRING_POINTER (sectree);
14754 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14756 tree sectree = DECL_SECTION_NAME (current_function_decl);
14757 secname = TREE_STRING_POINTER (sectree);
14759 else if (cfun && in_cold_section_p)
14760 secname = crtl->subsections.cold_section_label;
14762 secname = text_section_label;
14767 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14770 decl_by_reference_p (tree decl)
14772 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14773 || TREE_CODE (decl) == VAR_DECL)
14774 && DECL_BY_REFERENCE (decl));
14777 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14780 static dw_loc_descr_ref
14781 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14782 enum var_init_status initialized)
14784 int have_address = 0;
14785 dw_loc_descr_ref descr;
14786 enum machine_mode mode;
14788 if (want_address != 2)
14790 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14792 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14794 varloc = PAT_VAR_LOCATION_LOC (varloc);
14795 if (GET_CODE (varloc) == EXPR_LIST)
14796 varloc = XEXP (varloc, 0);
14797 mode = GET_MODE (varloc);
14798 if (MEM_P (varloc))
14800 rtx addr = XEXP (varloc, 0);
14801 descr = mem_loc_descriptor (addr, mode, initialized);
14806 rtx x = avoid_constant_pool_reference (varloc);
14808 descr = mem_loc_descriptor (x, mode, initialized);
14812 descr = mem_loc_descriptor (varloc, mode, initialized);
14819 if (GET_CODE (varloc) == VAR_LOCATION)
14820 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14822 mode = DECL_MODE (loc);
14823 descr = loc_descriptor (varloc, mode, initialized);
14830 if (want_address == 2 && !have_address
14831 && (dwarf_version >= 4 || !dwarf_strict))
14833 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14835 expansion_failed (loc, NULL_RTX,
14836 "DWARF address size mismatch");
14839 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14842 /* Show if we can't fill the request for an address. */
14843 if (want_address && !have_address)
14845 expansion_failed (loc, NULL_RTX,
14846 "Want address and only have value");
14850 /* If we've got an address and don't want one, dereference. */
14851 if (!want_address && have_address)
14853 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14854 enum dwarf_location_atom op;
14856 if (size > DWARF2_ADDR_SIZE || size == -1)
14858 expansion_failed (loc, NULL_RTX,
14859 "DWARF address size mismatch");
14862 else if (size == DWARF2_ADDR_SIZE)
14865 op = DW_OP_deref_size;
14867 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14873 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14874 if it is not possible. */
14876 static dw_loc_descr_ref
14877 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14879 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14880 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14881 else if (dwarf_version >= 3 || !dwarf_strict)
14882 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14887 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14888 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14890 static dw_loc_descr_ref
14891 dw_sra_loc_expr (tree decl, rtx loc)
14894 unsigned int padsize = 0;
14895 dw_loc_descr_ref descr, *descr_tail;
14896 unsigned HOST_WIDE_INT decl_size;
14898 enum var_init_status initialized;
14900 if (DECL_SIZE (decl) == NULL
14901 || !host_integerp (DECL_SIZE (decl), 1))
14904 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14906 descr_tail = &descr;
14908 for (p = loc; p; p = XEXP (p, 1))
14910 unsigned int bitsize = decl_piece_bitsize (p);
14911 rtx loc_note = *decl_piece_varloc_ptr (p);
14912 dw_loc_descr_ref cur_descr;
14913 dw_loc_descr_ref *tail, last = NULL;
14914 unsigned int opsize = 0;
14916 if (loc_note == NULL_RTX
14917 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14919 padsize += bitsize;
14922 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14923 varloc = NOTE_VAR_LOCATION (loc_note);
14924 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14925 if (cur_descr == NULL)
14927 padsize += bitsize;
14931 /* Check that cur_descr either doesn't use
14932 DW_OP_*piece operations, or their sum is equal
14933 to bitsize. Otherwise we can't embed it. */
14934 for (tail = &cur_descr; *tail != NULL;
14935 tail = &(*tail)->dw_loc_next)
14936 if ((*tail)->dw_loc_opc == DW_OP_piece)
14938 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14942 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14944 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14948 if (last != NULL && opsize != bitsize)
14950 padsize += bitsize;
14954 /* If there is a hole, add DW_OP_*piece after empty DWARF
14955 expression, which means that those bits are optimized out. */
14958 if (padsize > decl_size)
14960 decl_size -= padsize;
14961 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14962 if (*descr_tail == NULL)
14964 descr_tail = &(*descr_tail)->dw_loc_next;
14967 *descr_tail = cur_descr;
14969 if (bitsize > decl_size)
14971 decl_size -= bitsize;
14974 HOST_WIDE_INT offset = 0;
14975 if (GET_CODE (varloc) == VAR_LOCATION
14976 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14978 varloc = PAT_VAR_LOCATION_LOC (varloc);
14979 if (GET_CODE (varloc) == EXPR_LIST)
14980 varloc = XEXP (varloc, 0);
14984 if (GET_CODE (varloc) == CONST
14985 || GET_CODE (varloc) == SIGN_EXTEND
14986 || GET_CODE (varloc) == ZERO_EXTEND)
14987 varloc = XEXP (varloc, 0);
14988 else if (GET_CODE (varloc) == SUBREG)
14989 varloc = SUBREG_REG (varloc);
14994 /* DW_OP_bit_size offset should be zero for register
14995 or implicit location descriptions and empty location
14996 descriptions, but for memory addresses needs big endian
14998 if (MEM_P (varloc))
15000 unsigned HOST_WIDE_INT memsize
15001 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15002 if (memsize != bitsize)
15004 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15005 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15007 if (memsize < bitsize)
15009 if (BITS_BIG_ENDIAN)
15010 offset = memsize - bitsize;
15014 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15015 if (*descr_tail == NULL)
15017 descr_tail = &(*descr_tail)->dw_loc_next;
15021 /* If there were any non-empty expressions, add padding till the end of
15023 if (descr != NULL && decl_size != 0)
15025 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15026 if (*descr_tail == NULL)
15032 /* Return the dwarf representation of the location list LOC_LIST of
15033 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15036 static dw_loc_list_ref
15037 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15039 const char *endname, *secname;
15041 enum var_init_status initialized;
15042 struct var_loc_node *node;
15043 dw_loc_descr_ref descr;
15044 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15045 dw_loc_list_ref list = NULL;
15046 dw_loc_list_ref *listp = &list;
15048 /* Now that we know what section we are using for a base,
15049 actually construct the list of locations.
15050 The first location information is what is passed to the
15051 function that creates the location list, and the remaining
15052 locations just get added on to that list.
15053 Note that we only know the start address for a location
15054 (IE location changes), so to build the range, we use
15055 the range [current location start, next location start].
15056 This means we have to special case the last node, and generate
15057 a range of [last location start, end of function label]. */
15059 secname = secname_for_decl (decl);
15061 for (node = loc_list->first; node; node = node->next)
15062 if (GET_CODE (node->loc) == EXPR_LIST
15063 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15065 if (GET_CODE (node->loc) == EXPR_LIST)
15067 /* This requires DW_OP_{,bit_}piece, which is not usable
15068 inside DWARF expressions. */
15069 if (want_address != 2)
15071 descr = dw_sra_loc_expr (decl, node->loc);
15077 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15078 varloc = NOTE_VAR_LOCATION (node->loc);
15079 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15083 /* The variable has a location between NODE->LABEL and
15084 NODE->NEXT->LABEL. */
15086 endname = node->next->label;
15087 /* If the variable has a location at the last label
15088 it keeps its location until the end of function. */
15089 else if (!current_function_decl)
15090 endname = text_end_label;
15093 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15094 current_function_funcdef_no);
15095 endname = ggc_strdup (label_id);
15098 *listp = new_loc_list (descr, node->label, endname, secname);
15099 listp = &(*listp)->dw_loc_next;
15103 /* Try to avoid the overhead of a location list emitting a location
15104 expression instead, but only if we didn't have more than one
15105 location entry in the first place. If some entries were not
15106 representable, we don't want to pretend a single entry that was
15107 applies to the entire scope in which the variable is
15109 if (list && loc_list->first->next)
15115 /* Return if the loc_list has only single element and thus can be represented
15116 as location description. */
15119 single_element_loc_list_p (dw_loc_list_ref list)
15121 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15122 return !list->ll_symbol;
15125 /* To each location in list LIST add loc descr REF. */
15128 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15130 dw_loc_descr_ref copy;
15131 add_loc_descr (&list->expr, ref);
15132 list = list->dw_loc_next;
15135 copy = ggc_alloc_dw_loc_descr_node ();
15136 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15137 add_loc_descr (&list->expr, copy);
15138 while (copy->dw_loc_next)
15140 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15141 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15142 copy->dw_loc_next = new_copy;
15145 list = list->dw_loc_next;
15149 /* Given two lists RET and LIST
15150 produce location list that is result of adding expression in LIST
15151 to expression in RET on each possition in program.
15152 Might be destructive on both RET and LIST.
15154 TODO: We handle only simple cases of RET or LIST having at most one
15155 element. General case would inolve sorting the lists in program order
15156 and merging them that will need some additional work.
15157 Adding that will improve quality of debug info especially for SRA-ed
15161 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15170 if (!list->dw_loc_next)
15172 add_loc_descr_to_each (*ret, list->expr);
15175 if (!(*ret)->dw_loc_next)
15177 add_loc_descr_to_each (list, (*ret)->expr);
15181 expansion_failed (NULL_TREE, NULL_RTX,
15182 "Don't know how to merge two non-trivial"
15183 " location lists.\n");
15188 /* LOC is constant expression. Try a luck, look it up in constant
15189 pool and return its loc_descr of its address. */
15191 static dw_loc_descr_ref
15192 cst_pool_loc_descr (tree loc)
15194 /* Get an RTL for this, if something has been emitted. */
15195 rtx rtl = lookup_constant_def (loc);
15196 enum machine_mode mode;
15198 if (!rtl || !MEM_P (rtl))
15203 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15205 /* TODO: We might get more coverage if we was actually delaying expansion
15206 of all expressions till end of compilation when constant pools are fully
15208 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15210 expansion_failed (loc, NULL_RTX,
15211 "CST value in contant pool but not marked.");
15214 mode = GET_MODE (rtl);
15215 rtl = XEXP (rtl, 0);
15216 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15219 /* Return dw_loc_list representing address of addr_expr LOC
15220 by looking for innder INDIRECT_REF expression and turing it
15221 into simple arithmetics. */
15223 static dw_loc_list_ref
15224 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15227 HOST_WIDE_INT bitsize, bitpos, bytepos;
15228 enum machine_mode mode;
15230 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15231 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15233 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15234 &bitsize, &bitpos, &offset, &mode,
15235 &unsignedp, &volatilep, false);
15237 if (bitpos % BITS_PER_UNIT)
15239 expansion_failed (loc, NULL_RTX, "bitfield access");
15242 if (!INDIRECT_REF_P (obj))
15244 expansion_failed (obj,
15245 NULL_RTX, "no indirect ref in inner refrence");
15248 if (!offset && !bitpos)
15249 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15251 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15252 && (dwarf_version >= 4 || !dwarf_strict))
15254 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15259 /* Variable offset. */
15260 list_ret1 = loc_list_from_tree (offset, 0);
15261 if (list_ret1 == 0)
15263 add_loc_list (&list_ret, list_ret1);
15266 add_loc_descr_to_each (list_ret,
15267 new_loc_descr (DW_OP_plus, 0, 0));
15269 bytepos = bitpos / BITS_PER_UNIT;
15271 add_loc_descr_to_each (list_ret,
15272 new_loc_descr (DW_OP_plus_uconst,
15274 else if (bytepos < 0)
15275 loc_list_plus_const (list_ret, bytepos);
15276 add_loc_descr_to_each (list_ret,
15277 new_loc_descr (DW_OP_stack_value, 0, 0));
15283 /* Generate Dwarf location list representing LOC.
15284 If WANT_ADDRESS is false, expression computing LOC will be computed
15285 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15286 if WANT_ADDRESS is 2, expression computing address useable in location
15287 will be returned (i.e. DW_OP_reg can be used
15288 to refer to register values). */
15290 static dw_loc_list_ref
15291 loc_list_from_tree (tree loc, int want_address)
15293 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15294 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15295 int have_address = 0;
15296 enum dwarf_location_atom op;
15298 /* ??? Most of the time we do not take proper care for sign/zero
15299 extending the values properly. Hopefully this won't be a real
15302 switch (TREE_CODE (loc))
15305 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15308 case PLACEHOLDER_EXPR:
15309 /* This case involves extracting fields from an object to determine the
15310 position of other fields. We don't try to encode this here. The
15311 only user of this is Ada, which encodes the needed information using
15312 the names of types. */
15313 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15317 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15318 /* There are no opcodes for these operations. */
15321 case PREINCREMENT_EXPR:
15322 case PREDECREMENT_EXPR:
15323 case POSTINCREMENT_EXPR:
15324 case POSTDECREMENT_EXPR:
15325 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15326 /* There are no opcodes for these operations. */
15330 /* If we already want an address, see if there is INDIRECT_REF inside
15331 e.g. for &this->field. */
15334 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15335 (loc, want_address == 2);
15338 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15339 && (ret = cst_pool_loc_descr (loc)))
15342 /* Otherwise, process the argument and look for the address. */
15343 if (!list_ret && !ret)
15344 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15348 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15354 if (DECL_THREAD_LOCAL_P (loc))
15357 enum dwarf_location_atom first_op;
15358 enum dwarf_location_atom second_op;
15359 bool dtprel = false;
15361 if (targetm.have_tls)
15363 /* If this is not defined, we have no way to emit the
15365 if (!targetm.asm_out.output_dwarf_dtprel)
15368 /* The way DW_OP_GNU_push_tls_address is specified, we
15369 can only look up addresses of objects in the current
15370 module. We used DW_OP_addr as first op, but that's
15371 wrong, because DW_OP_addr is relocated by the debug
15372 info consumer, while DW_OP_GNU_push_tls_address
15373 operand shouldn't be. */
15374 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15376 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15378 second_op = DW_OP_GNU_push_tls_address;
15382 if (!targetm.emutls.debug_form_tls_address
15383 || !(dwarf_version >= 3 || !dwarf_strict))
15385 /* We stuffed the control variable into the DECL_VALUE_EXPR
15386 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15387 no longer appear in gimple code. We used the control
15388 variable in specific so that we could pick it up here. */
15389 loc = DECL_VALUE_EXPR (loc);
15390 first_op = DW_OP_addr;
15391 second_op = DW_OP_form_tls_address;
15394 rtl = rtl_for_decl_location (loc);
15395 if (rtl == NULL_RTX)
15400 rtl = XEXP (rtl, 0);
15401 if (! CONSTANT_P (rtl))
15404 ret = new_loc_descr (first_op, 0, 0);
15405 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15406 ret->dw_loc_oprnd1.v.val_addr = rtl;
15407 ret->dtprel = dtprel;
15409 ret1 = new_loc_descr (second_op, 0, 0);
15410 add_loc_descr (&ret, ret1);
15418 if (DECL_HAS_VALUE_EXPR_P (loc))
15419 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15424 case FUNCTION_DECL:
15427 var_loc_list *loc_list = lookup_decl_loc (loc);
15429 if (loc_list && loc_list->first)
15431 list_ret = dw_loc_list (loc_list, loc, want_address);
15432 have_address = want_address != 0;
15435 rtl = rtl_for_decl_location (loc);
15436 if (rtl == NULL_RTX)
15438 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15441 else if (CONST_INT_P (rtl))
15443 HOST_WIDE_INT val = INTVAL (rtl);
15444 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15445 val &= GET_MODE_MASK (DECL_MODE (loc));
15446 ret = int_loc_descriptor (val);
15448 else if (GET_CODE (rtl) == CONST_STRING)
15450 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15453 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15455 ret = new_loc_descr (DW_OP_addr, 0, 0);
15456 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15457 ret->dw_loc_oprnd1.v.val_addr = rtl;
15461 enum machine_mode mode;
15463 /* Certain constructs can only be represented at top-level. */
15464 if (want_address == 2)
15466 ret = loc_descriptor (rtl, VOIDmode,
15467 VAR_INIT_STATUS_INITIALIZED);
15472 mode = GET_MODE (rtl);
15475 rtl = XEXP (rtl, 0);
15478 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15481 expansion_failed (loc, rtl,
15482 "failed to produce loc descriptor for rtl");
15489 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15493 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15497 case COMPOUND_EXPR:
15498 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15501 case VIEW_CONVERT_EXPR:
15504 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15506 case COMPONENT_REF:
15507 case BIT_FIELD_REF:
15509 case ARRAY_RANGE_REF:
15510 case REALPART_EXPR:
15511 case IMAGPART_EXPR:
15514 HOST_WIDE_INT bitsize, bitpos, bytepos;
15515 enum machine_mode mode;
15517 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15519 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15520 &unsignedp, &volatilep, false);
15522 gcc_assert (obj != loc);
15524 list_ret = loc_list_from_tree (obj,
15526 && !bitpos && !offset ? 2 : 1);
15527 /* TODO: We can extract value of the small expression via shifting even
15528 for nonzero bitpos. */
15531 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15533 expansion_failed (loc, NULL_RTX,
15534 "bitfield access");
15538 if (offset != NULL_TREE)
15540 /* Variable offset. */
15541 list_ret1 = loc_list_from_tree (offset, 0);
15542 if (list_ret1 == 0)
15544 add_loc_list (&list_ret, list_ret1);
15547 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15550 bytepos = bitpos / BITS_PER_UNIT;
15552 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15553 else if (bytepos < 0)
15554 loc_list_plus_const (list_ret, bytepos);
15561 if ((want_address || !host_integerp (loc, 0))
15562 && (ret = cst_pool_loc_descr (loc)))
15564 else if (want_address == 2
15565 && host_integerp (loc, 0)
15566 && (ret = address_of_int_loc_descriptor
15567 (int_size_in_bytes (TREE_TYPE (loc)),
15568 tree_low_cst (loc, 0))))
15570 else if (host_integerp (loc, 0))
15571 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15574 expansion_failed (loc, NULL_RTX,
15575 "Integer operand is not host integer");
15584 if ((ret = cst_pool_loc_descr (loc)))
15587 /* We can construct small constants here using int_loc_descriptor. */
15588 expansion_failed (loc, NULL_RTX,
15589 "constructor or constant not in constant pool");
15592 case TRUTH_AND_EXPR:
15593 case TRUTH_ANDIF_EXPR:
15598 case TRUTH_XOR_EXPR:
15603 case TRUTH_OR_EXPR:
15604 case TRUTH_ORIF_EXPR:
15609 case FLOOR_DIV_EXPR:
15610 case CEIL_DIV_EXPR:
15611 case ROUND_DIV_EXPR:
15612 case TRUNC_DIV_EXPR:
15613 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15622 case FLOOR_MOD_EXPR:
15623 case CEIL_MOD_EXPR:
15624 case ROUND_MOD_EXPR:
15625 case TRUNC_MOD_EXPR:
15626 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15631 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15632 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15633 if (list_ret == 0 || list_ret1 == 0)
15636 add_loc_list (&list_ret, list_ret1);
15639 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15640 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15641 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15642 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15643 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15655 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15658 case POINTER_PLUS_EXPR:
15660 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15662 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15666 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15674 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15681 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15688 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15695 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15710 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15711 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15712 if (list_ret == 0 || list_ret1 == 0)
15715 add_loc_list (&list_ret, list_ret1);
15718 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15721 case TRUTH_NOT_EXPR:
15735 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15739 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15745 const enum tree_code code =
15746 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15748 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15749 build2 (code, integer_type_node,
15750 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15751 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15754 /* ... fall through ... */
15758 dw_loc_descr_ref lhs
15759 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15760 dw_loc_list_ref rhs
15761 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15762 dw_loc_descr_ref bra_node, jump_node, tmp;
15764 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15765 if (list_ret == 0 || lhs == 0 || rhs == 0)
15768 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15769 add_loc_descr_to_each (list_ret, bra_node);
15771 add_loc_list (&list_ret, rhs);
15772 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15773 add_loc_descr_to_each (list_ret, jump_node);
15775 add_loc_descr_to_each (list_ret, lhs);
15776 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15777 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15779 /* ??? Need a node to point the skip at. Use a nop. */
15780 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15781 add_loc_descr_to_each (list_ret, tmp);
15782 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15783 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15787 case FIX_TRUNC_EXPR:
15791 /* Leave front-end specific codes as simply unknown. This comes
15792 up, for instance, with the C STMT_EXPR. */
15793 if ((unsigned int) TREE_CODE (loc)
15794 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15796 expansion_failed (loc, NULL_RTX,
15797 "language specific tree node");
15801 #ifdef ENABLE_CHECKING
15802 /* Otherwise this is a generic code; we should just lists all of
15803 these explicitly. We forgot one. */
15804 gcc_unreachable ();
15806 /* In a release build, we want to degrade gracefully: better to
15807 generate incomplete debugging information than to crash. */
15812 if (!ret && !list_ret)
15815 if (want_address == 2 && !have_address
15816 && (dwarf_version >= 4 || !dwarf_strict))
15818 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15820 expansion_failed (loc, NULL_RTX,
15821 "DWARF address size mismatch");
15825 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15827 add_loc_descr_to_each (list_ret,
15828 new_loc_descr (DW_OP_stack_value, 0, 0));
15831 /* Show if we can't fill the request for an address. */
15832 if (want_address && !have_address)
15834 expansion_failed (loc, NULL_RTX,
15835 "Want address and only have value");
15839 gcc_assert (!ret || !list_ret);
15841 /* If we've got an address and don't want one, dereference. */
15842 if (!want_address && have_address)
15844 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15846 if (size > DWARF2_ADDR_SIZE || size == -1)
15848 expansion_failed (loc, NULL_RTX,
15849 "DWARF address size mismatch");
15852 else if (size == DWARF2_ADDR_SIZE)
15855 op = DW_OP_deref_size;
15858 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15860 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15863 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15868 /* Same as above but return only single location expression. */
15869 static dw_loc_descr_ref
15870 loc_descriptor_from_tree (tree loc, int want_address)
15872 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15875 if (ret->dw_loc_next)
15877 expansion_failed (loc, NULL_RTX,
15878 "Location list where only loc descriptor needed");
15884 /* Given a value, round it up to the lowest multiple of `boundary'
15885 which is not less than the value itself. */
15887 static inline HOST_WIDE_INT
15888 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15890 return (((value + boundary - 1) / boundary) * boundary);
15893 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15894 pointer to the declared type for the relevant field variable, or return
15895 `integer_type_node' if the given node turns out to be an
15896 ERROR_MARK node. */
15899 field_type (const_tree decl)
15903 if (TREE_CODE (decl) == ERROR_MARK)
15904 return integer_type_node;
15906 type = DECL_BIT_FIELD_TYPE (decl);
15907 if (type == NULL_TREE)
15908 type = TREE_TYPE (decl);
15913 /* Given a pointer to a tree node, return the alignment in bits for
15914 it, or else return BITS_PER_WORD if the node actually turns out to
15915 be an ERROR_MARK node. */
15917 static inline unsigned
15918 simple_type_align_in_bits (const_tree type)
15920 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15923 static inline unsigned
15924 simple_decl_align_in_bits (const_tree decl)
15926 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15929 /* Return the result of rounding T up to ALIGN. */
15931 static inline double_int
15932 round_up_to_align (double_int t, unsigned int align)
15934 double_int alignd = uhwi_to_double_int (align);
15935 t = double_int_add (t, alignd);
15936 t = double_int_add (t, double_int_minus_one);
15937 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15938 t = double_int_mul (t, alignd);
15942 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15943 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15944 or return 0 if we are unable to determine what that offset is, either
15945 because the argument turns out to be a pointer to an ERROR_MARK node, or
15946 because the offset is actually variable. (We can't handle the latter case
15949 static HOST_WIDE_INT
15950 field_byte_offset (const_tree decl)
15952 double_int object_offset_in_bits;
15953 double_int object_offset_in_bytes;
15954 double_int bitpos_int;
15956 if (TREE_CODE (decl) == ERROR_MARK)
15959 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15961 /* We cannot yet cope with fields whose positions are variable, so
15962 for now, when we see such things, we simply return 0. Someday, we may
15963 be able to handle such cases, but it will be damn difficult. */
15964 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15967 bitpos_int = tree_to_double_int (bit_position (decl));
15969 #ifdef PCC_BITFIELD_TYPE_MATTERS
15970 if (PCC_BITFIELD_TYPE_MATTERS)
15973 tree field_size_tree;
15974 double_int deepest_bitpos;
15975 double_int field_size_in_bits;
15976 unsigned int type_align_in_bits;
15977 unsigned int decl_align_in_bits;
15978 double_int type_size_in_bits;
15980 type = field_type (decl);
15981 type_size_in_bits = double_int_type_size_in_bits (type);
15982 type_align_in_bits = simple_type_align_in_bits (type);
15984 field_size_tree = DECL_SIZE (decl);
15986 /* The size could be unspecified if there was an error, or for
15987 a flexible array member. */
15988 if (!field_size_tree)
15989 field_size_tree = bitsize_zero_node;
15991 /* If the size of the field is not constant, use the type size. */
15992 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15993 field_size_in_bits = tree_to_double_int (field_size_tree);
15995 field_size_in_bits = type_size_in_bits;
15997 decl_align_in_bits = simple_decl_align_in_bits (decl);
15999 /* The GCC front-end doesn't make any attempt to keep track of the
16000 starting bit offset (relative to the start of the containing
16001 structure type) of the hypothetical "containing object" for a
16002 bit-field. Thus, when computing the byte offset value for the
16003 start of the "containing object" of a bit-field, we must deduce
16004 this information on our own. This can be rather tricky to do in
16005 some cases. For example, handling the following structure type
16006 definition when compiling for an i386/i486 target (which only
16007 aligns long long's to 32-bit boundaries) can be very tricky:
16009 struct S { int field1; long long field2:31; };
16011 Fortunately, there is a simple rule-of-thumb which can be used
16012 in such cases. When compiling for an i386/i486, GCC will
16013 allocate 8 bytes for the structure shown above. It decides to
16014 do this based upon one simple rule for bit-field allocation.
16015 GCC allocates each "containing object" for each bit-field at
16016 the first (i.e. lowest addressed) legitimate alignment boundary
16017 (based upon the required minimum alignment for the declared
16018 type of the field) which it can possibly use, subject to the
16019 condition that there is still enough available space remaining
16020 in the containing object (when allocated at the selected point)
16021 to fully accommodate all of the bits of the bit-field itself.
16023 This simple rule makes it obvious why GCC allocates 8 bytes for
16024 each object of the structure type shown above. When looking
16025 for a place to allocate the "containing object" for `field2',
16026 the compiler simply tries to allocate a 64-bit "containing
16027 object" at each successive 32-bit boundary (starting at zero)
16028 until it finds a place to allocate that 64- bit field such that
16029 at least 31 contiguous (and previously unallocated) bits remain
16030 within that selected 64 bit field. (As it turns out, for the
16031 example above, the compiler finds it is OK to allocate the
16032 "containing object" 64-bit field at bit-offset zero within the
16035 Here we attempt to work backwards from the limited set of facts
16036 we're given, and we try to deduce from those facts, where GCC
16037 must have believed that the containing object started (within
16038 the structure type). The value we deduce is then used (by the
16039 callers of this routine) to generate DW_AT_location and
16040 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16041 the case of DW_AT_location, regular fields as well). */
16043 /* Figure out the bit-distance from the start of the structure to
16044 the "deepest" bit of the bit-field. */
16045 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16047 /* This is the tricky part. Use some fancy footwork to deduce
16048 where the lowest addressed bit of the containing object must
16050 object_offset_in_bits
16051 = double_int_sub (deepest_bitpos, type_size_in_bits);
16053 /* Round up to type_align by default. This works best for
16055 object_offset_in_bits
16056 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16058 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16060 object_offset_in_bits
16061 = double_int_sub (deepest_bitpos, type_size_in_bits);
16063 /* Round up to decl_align instead. */
16064 object_offset_in_bits
16065 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16069 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16070 object_offset_in_bits = bitpos_int;
16072 object_offset_in_bytes
16073 = double_int_div (object_offset_in_bits,
16074 uhwi_to_double_int (BITS_PER_UNIT), true,
16076 return double_int_to_shwi (object_offset_in_bytes);
16079 /* The following routines define various Dwarf attributes and any data
16080 associated with them. */
16082 /* Add a location description attribute value to a DIE.
16084 This emits location attributes suitable for whole variables and
16085 whole parameters. Note that the location attributes for struct fields are
16086 generated by the routine `data_member_location_attribute' below. */
16089 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16090 dw_loc_list_ref descr)
16094 if (single_element_loc_list_p (descr))
16095 add_AT_loc (die, attr_kind, descr->expr);
16097 add_AT_loc_list (die, attr_kind, descr);
16100 /* Add DW_AT_accessibility attribute to DIE if needed. */
16103 add_accessibility_attribute (dw_die_ref die, tree decl)
16105 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16106 children, otherwise the default is DW_ACCESS_public. In DWARF2
16107 the default has always been DW_ACCESS_public. */
16108 if (TREE_PROTECTED (decl))
16109 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16110 else if (TREE_PRIVATE (decl))
16112 if (dwarf_version == 2
16113 || die->die_parent == NULL
16114 || die->die_parent->die_tag != DW_TAG_class_type)
16115 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16117 else if (dwarf_version > 2
16119 && die->die_parent->die_tag == DW_TAG_class_type)
16120 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16123 /* Attach the specialized form of location attribute used for data members of
16124 struct and union types. In the special case of a FIELD_DECL node which
16125 represents a bit-field, the "offset" part of this special location
16126 descriptor must indicate the distance in bytes from the lowest-addressed
16127 byte of the containing struct or union type to the lowest-addressed byte of
16128 the "containing object" for the bit-field. (See the `field_byte_offset'
16131 For any given bit-field, the "containing object" is a hypothetical object
16132 (of some integral or enum type) within which the given bit-field lives. The
16133 type of this hypothetical "containing object" is always the same as the
16134 declared type of the individual bit-field itself (for GCC anyway... the
16135 DWARF spec doesn't actually mandate this). Note that it is the size (in
16136 bytes) of the hypothetical "containing object" which will be given in the
16137 DW_AT_byte_size attribute for this bit-field. (See the
16138 `byte_size_attribute' function below.) It is also used when calculating the
16139 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16140 function below.) */
16143 add_data_member_location_attribute (dw_die_ref die, tree decl)
16145 HOST_WIDE_INT offset;
16146 dw_loc_descr_ref loc_descr = 0;
16148 if (TREE_CODE (decl) == TREE_BINFO)
16150 /* We're working on the TAG_inheritance for a base class. */
16151 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16153 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16154 aren't at a fixed offset from all (sub)objects of the same
16155 type. We need to extract the appropriate offset from our
16156 vtable. The following dwarf expression means
16158 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16160 This is specific to the V3 ABI, of course. */
16162 dw_loc_descr_ref tmp;
16164 /* Make a copy of the object address. */
16165 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16166 add_loc_descr (&loc_descr, tmp);
16168 /* Extract the vtable address. */
16169 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16170 add_loc_descr (&loc_descr, tmp);
16172 /* Calculate the address of the offset. */
16173 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16174 gcc_assert (offset < 0);
16176 tmp = int_loc_descriptor (-offset);
16177 add_loc_descr (&loc_descr, tmp);
16178 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16179 add_loc_descr (&loc_descr, tmp);
16181 /* Extract the offset. */
16182 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16183 add_loc_descr (&loc_descr, tmp);
16185 /* Add it to the object address. */
16186 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16187 add_loc_descr (&loc_descr, tmp);
16190 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16193 offset = field_byte_offset (decl);
16197 if (dwarf_version > 2)
16199 /* Don't need to output a location expression, just the constant. */
16201 add_AT_int (die, DW_AT_data_member_location, offset);
16203 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16208 enum dwarf_location_atom op;
16210 /* The DWARF2 standard says that we should assume that the structure
16211 address is already on the stack, so we can specify a structure
16212 field address by using DW_OP_plus_uconst. */
16214 #ifdef MIPS_DEBUGGING_INFO
16215 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16216 operator correctly. It works only if we leave the offset on the
16220 op = DW_OP_plus_uconst;
16223 loc_descr = new_loc_descr (op, offset, 0);
16227 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16230 /* Writes integer values to dw_vec_const array. */
16233 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16237 *dest++ = val & 0xff;
16243 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16245 static HOST_WIDE_INT
16246 extract_int (const unsigned char *src, unsigned int size)
16248 HOST_WIDE_INT val = 0;
16254 val |= *--src & 0xff;
16260 /* Writes double_int values to dw_vec_const array. */
16263 insert_double (double_int val, unsigned char *dest)
16265 unsigned char *p0 = dest;
16266 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16268 if (WORDS_BIG_ENDIAN)
16274 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16275 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16278 /* Writes floating point values to dw_vec_const array. */
16281 insert_float (const_rtx rtl, unsigned char *array)
16283 REAL_VALUE_TYPE rv;
16287 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16288 real_to_target (val, &rv, GET_MODE (rtl));
16290 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16291 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16293 insert_int (val[i], 4, array);
16298 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16299 does not have a "location" either in memory or in a register. These
16300 things can arise in GNU C when a constant is passed as an actual parameter
16301 to an inlined function. They can also arise in C++ where declared
16302 constants do not necessarily get memory "homes". */
16305 add_const_value_attribute (dw_die_ref die, rtx rtl)
16307 switch (GET_CODE (rtl))
16311 HOST_WIDE_INT val = INTVAL (rtl);
16314 add_AT_int (die, DW_AT_const_value, val);
16316 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16321 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16322 floating-point constant. A CONST_DOUBLE is used whenever the
16323 constant requires more than one word in order to be adequately
16326 enum machine_mode mode = GET_MODE (rtl);
16328 if (SCALAR_FLOAT_MODE_P (mode))
16330 unsigned int length = GET_MODE_SIZE (mode);
16331 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16333 insert_float (rtl, array);
16334 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16337 add_AT_double (die, DW_AT_const_value,
16338 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16344 enum machine_mode mode = GET_MODE (rtl);
16345 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16346 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16347 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16348 (length * elt_size);
16352 switch (GET_MODE_CLASS (mode))
16354 case MODE_VECTOR_INT:
16355 for (i = 0, p = array; i < length; i++, p += elt_size)
16357 rtx elt = CONST_VECTOR_ELT (rtl, i);
16358 double_int val = rtx_to_double_int (elt);
16360 if (elt_size <= sizeof (HOST_WIDE_INT))
16361 insert_int (double_int_to_shwi (val), elt_size, p);
16364 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16365 insert_double (val, p);
16370 case MODE_VECTOR_FLOAT:
16371 for (i = 0, p = array; i < length; i++, p += elt_size)
16373 rtx elt = CONST_VECTOR_ELT (rtl, i);
16374 insert_float (elt, p);
16379 gcc_unreachable ();
16382 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16387 if (dwarf_version >= 4 || !dwarf_strict)
16389 dw_loc_descr_ref loc_result;
16390 resolve_one_addr (&rtl, NULL);
16392 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16393 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16394 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16395 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16396 add_AT_loc (die, DW_AT_location, loc_result);
16397 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16403 if (CONSTANT_P (XEXP (rtl, 0)))
16404 return add_const_value_attribute (die, XEXP (rtl, 0));
16407 if (!const_ok_for_output (rtl))
16410 if (dwarf_version >= 4 || !dwarf_strict)
16415 /* In cases where an inlined instance of an inline function is passed
16416 the address of an `auto' variable (which is local to the caller) we
16417 can get a situation where the DECL_RTL of the artificial local
16418 variable (for the inlining) which acts as a stand-in for the
16419 corresponding formal parameter (of the inline function) will look
16420 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16421 exactly a compile-time constant expression, but it isn't the address
16422 of the (artificial) local variable either. Rather, it represents the
16423 *value* which the artificial local variable always has during its
16424 lifetime. We currently have no way to represent such quasi-constant
16425 values in Dwarf, so for now we just punt and generate nothing. */
16433 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16434 && MEM_READONLY_P (rtl)
16435 && GET_MODE (rtl) == BLKmode)
16437 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16443 /* No other kinds of rtx should be possible here. */
16444 gcc_unreachable ();
16449 /* Determine whether the evaluation of EXPR references any variables
16450 or functions which aren't otherwise used (and therefore may not be
16453 reference_to_unused (tree * tp, int * walk_subtrees,
16454 void * data ATTRIBUTE_UNUSED)
16456 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16457 *walk_subtrees = 0;
16459 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16460 && ! TREE_ASM_WRITTEN (*tp))
16462 /* ??? The C++ FE emits debug information for using decls, so
16463 putting gcc_unreachable here falls over. See PR31899. For now
16464 be conservative. */
16465 else if (!cgraph_global_info_ready
16466 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16468 else if (TREE_CODE (*tp) == VAR_DECL)
16470 struct varpool_node *node = varpool_get_node (*tp);
16471 if (!node || !node->needed)
16474 else if (TREE_CODE (*tp) == FUNCTION_DECL
16475 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16477 /* The call graph machinery must have finished analyzing,
16478 optimizing and gimplifying the CU by now.
16479 So if *TP has no call graph node associated
16480 to it, it means *TP will not be emitted. */
16481 if (!cgraph_get_node (*tp))
16484 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16490 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16491 for use in a later add_const_value_attribute call. */
16494 rtl_for_decl_init (tree init, tree type)
16496 rtx rtl = NULL_RTX;
16498 /* If a variable is initialized with a string constant without embedded
16499 zeros, build CONST_STRING. */
16500 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16502 tree enttype = TREE_TYPE (type);
16503 tree domain = TYPE_DOMAIN (type);
16504 enum machine_mode mode = TYPE_MODE (enttype);
16506 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16508 && integer_zerop (TYPE_MIN_VALUE (domain))
16509 && compare_tree_int (TYPE_MAX_VALUE (domain),
16510 TREE_STRING_LENGTH (init) - 1) == 0
16511 && ((size_t) TREE_STRING_LENGTH (init)
16512 == strlen (TREE_STRING_POINTER (init)) + 1))
16514 rtl = gen_rtx_CONST_STRING (VOIDmode,
16515 ggc_strdup (TREE_STRING_POINTER (init)));
16516 rtl = gen_rtx_MEM (BLKmode, rtl);
16517 MEM_READONLY_P (rtl) = 1;
16520 /* Other aggregates, and complex values, could be represented using
16522 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
16524 /* Vectors only work if their mode is supported by the target.
16525 FIXME: generic vectors ought to work too. */
16526 else if (TREE_CODE (type) == VECTOR_TYPE
16527 && !VECTOR_MODE_P (TYPE_MODE (type)))
16529 /* If the initializer is something that we know will expand into an
16530 immediate RTL constant, expand it now. We must be careful not to
16531 reference variables which won't be output. */
16532 else if (initializer_constant_valid_p (init, type)
16533 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16535 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16537 if (TREE_CODE (type) == VECTOR_TYPE)
16538 switch (TREE_CODE (init))
16543 if (TREE_CONSTANT (init))
16545 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16546 bool constant_p = true;
16548 unsigned HOST_WIDE_INT ix;
16550 /* Even when ctor is constant, it might contain non-*_CST
16551 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16552 belong into VECTOR_CST nodes. */
16553 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16554 if (!CONSTANT_CLASS_P (value))
16556 constant_p = false;
16562 init = build_vector_from_ctor (type, elts);
16572 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16574 /* If expand_expr returns a MEM, it wasn't immediate. */
16575 gcc_assert (!rtl || !MEM_P (rtl));
16581 /* Generate RTL for the variable DECL to represent its location. */
16584 rtl_for_decl_location (tree decl)
16588 /* Here we have to decide where we are going to say the parameter "lives"
16589 (as far as the debugger is concerned). We only have a couple of
16590 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16592 DECL_RTL normally indicates where the parameter lives during most of the
16593 activation of the function. If optimization is enabled however, this
16594 could be either NULL or else a pseudo-reg. Both of those cases indicate
16595 that the parameter doesn't really live anywhere (as far as the code
16596 generation parts of GCC are concerned) during most of the function's
16597 activation. That will happen (for example) if the parameter is never
16598 referenced within the function.
16600 We could just generate a location descriptor here for all non-NULL
16601 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16602 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16603 where DECL_RTL is NULL or is a pseudo-reg.
16605 Note however that we can only get away with using DECL_INCOMING_RTL as
16606 a backup substitute for DECL_RTL in certain limited cases. In cases
16607 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16608 we can be sure that the parameter was passed using the same type as it is
16609 declared to have within the function, and that its DECL_INCOMING_RTL
16610 points us to a place where a value of that type is passed.
16612 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16613 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16614 because in these cases DECL_INCOMING_RTL points us to a value of some
16615 type which is *different* from the type of the parameter itself. Thus,
16616 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16617 such cases, the debugger would end up (for example) trying to fetch a
16618 `float' from a place which actually contains the first part of a
16619 `double'. That would lead to really incorrect and confusing
16620 output at debug-time.
16622 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16623 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16624 are a couple of exceptions however. On little-endian machines we can
16625 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16626 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16627 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16628 when (on a little-endian machine) a non-prototyped function has a
16629 parameter declared to be of type `short' or `char'. In such cases,
16630 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16631 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16632 passed `int' value. If the debugger then uses that address to fetch
16633 a `short' or a `char' (on a little-endian machine) the result will be
16634 the correct data, so we allow for such exceptional cases below.
16636 Note that our goal here is to describe the place where the given formal
16637 parameter lives during most of the function's activation (i.e. between the
16638 end of the prologue and the start of the epilogue). We'll do that as best
16639 as we can. Note however that if the given formal parameter is modified
16640 sometime during the execution of the function, then a stack backtrace (at
16641 debug-time) will show the function as having been called with the *new*
16642 value rather than the value which was originally passed in. This happens
16643 rarely enough that it is not a major problem, but it *is* a problem, and
16644 I'd like to fix it.
16646 A future version of dwarf2out.c may generate two additional attributes for
16647 any given DW_TAG_formal_parameter DIE which will describe the "passed
16648 type" and the "passed location" for the given formal parameter in addition
16649 to the attributes we now generate to indicate the "declared type" and the
16650 "active location" for each parameter. This additional set of attributes
16651 could be used by debuggers for stack backtraces. Separately, note that
16652 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16653 This happens (for example) for inlined-instances of inline function formal
16654 parameters which are never referenced. This really shouldn't be
16655 happening. All PARM_DECL nodes should get valid non-NULL
16656 DECL_INCOMING_RTL values. FIXME. */
16658 /* Use DECL_RTL as the "location" unless we find something better. */
16659 rtl = DECL_RTL_IF_SET (decl);
16661 /* When generating abstract instances, ignore everything except
16662 constants, symbols living in memory, and symbols living in
16663 fixed registers. */
16664 if (! reload_completed)
16667 && (CONSTANT_P (rtl)
16669 && CONSTANT_P (XEXP (rtl, 0)))
16671 && TREE_CODE (decl) == VAR_DECL
16672 && TREE_STATIC (decl))))
16674 rtl = targetm.delegitimize_address (rtl);
16679 else if (TREE_CODE (decl) == PARM_DECL)
16681 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16683 tree declared_type = TREE_TYPE (decl);
16684 tree passed_type = DECL_ARG_TYPE (decl);
16685 enum machine_mode dmode = TYPE_MODE (declared_type);
16686 enum machine_mode pmode = TYPE_MODE (passed_type);
16688 /* This decl represents a formal parameter which was optimized out.
16689 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16690 all cases where (rtl == NULL_RTX) just below. */
16691 if (dmode == pmode)
16692 rtl = DECL_INCOMING_RTL (decl);
16693 else if (SCALAR_INT_MODE_P (dmode)
16694 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16695 && DECL_INCOMING_RTL (decl))
16697 rtx inc = DECL_INCOMING_RTL (decl);
16700 else if (MEM_P (inc))
16702 if (BYTES_BIG_ENDIAN)
16703 rtl = adjust_address_nv (inc, dmode,
16704 GET_MODE_SIZE (pmode)
16705 - GET_MODE_SIZE (dmode));
16712 /* If the parm was passed in registers, but lives on the stack, then
16713 make a big endian correction if the mode of the type of the
16714 parameter is not the same as the mode of the rtl. */
16715 /* ??? This is the same series of checks that are made in dbxout.c before
16716 we reach the big endian correction code there. It isn't clear if all
16717 of these checks are necessary here, but keeping them all is the safe
16719 else if (MEM_P (rtl)
16720 && XEXP (rtl, 0) != const0_rtx
16721 && ! CONSTANT_P (XEXP (rtl, 0))
16722 /* Not passed in memory. */
16723 && !MEM_P (DECL_INCOMING_RTL (decl))
16724 /* Not passed by invisible reference. */
16725 && (!REG_P (XEXP (rtl, 0))
16726 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16727 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16728 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16729 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16732 /* Big endian correction check. */
16733 && BYTES_BIG_ENDIAN
16734 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16735 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16738 int offset = (UNITS_PER_WORD
16739 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16741 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16742 plus_constant (XEXP (rtl, 0), offset));
16745 else if (TREE_CODE (decl) == VAR_DECL
16748 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16749 && BYTES_BIG_ENDIAN)
16751 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16752 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16754 /* If a variable is declared "register" yet is smaller than
16755 a register, then if we store the variable to memory, it
16756 looks like we're storing a register-sized value, when in
16757 fact we are not. We need to adjust the offset of the
16758 storage location to reflect the actual value's bytes,
16759 else gdb will not be able to display it. */
16761 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16762 plus_constant (XEXP (rtl, 0), rsize-dsize));
16765 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16766 and will have been substituted directly into all expressions that use it.
16767 C does not have such a concept, but C++ and other languages do. */
16768 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16769 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16772 rtl = targetm.delegitimize_address (rtl);
16774 /* If we don't look past the constant pool, we risk emitting a
16775 reference to a constant pool entry that isn't referenced from
16776 code, and thus is not emitted. */
16778 rtl = avoid_constant_pool_reference (rtl);
16780 /* Try harder to get a rtl. If this symbol ends up not being emitted
16781 in the current CU, resolve_addr will remove the expression referencing
16783 if (rtl == NULL_RTX
16784 && TREE_CODE (decl) == VAR_DECL
16785 && !DECL_EXTERNAL (decl)
16786 && TREE_STATIC (decl)
16787 && DECL_NAME (decl)
16788 && !DECL_HARD_REGISTER (decl)
16789 && DECL_MODE (decl) != VOIDmode)
16791 rtl = make_decl_rtl_for_debug (decl);
16793 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16794 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16801 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16802 returned. If so, the decl for the COMMON block is returned, and the
16803 value is the offset into the common block for the symbol. */
16806 fortran_common (tree decl, HOST_WIDE_INT *value)
16808 tree val_expr, cvar;
16809 enum machine_mode mode;
16810 HOST_WIDE_INT bitsize, bitpos;
16812 int volatilep = 0, unsignedp = 0;
16814 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16815 it does not have a value (the offset into the common area), or if it
16816 is thread local (as opposed to global) then it isn't common, and shouldn't
16817 be handled as such. */
16818 if (TREE_CODE (decl) != VAR_DECL
16819 || !TREE_STATIC (decl)
16820 || !DECL_HAS_VALUE_EXPR_P (decl)
16824 val_expr = DECL_VALUE_EXPR (decl);
16825 if (TREE_CODE (val_expr) != COMPONENT_REF)
16828 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16829 &mode, &unsignedp, &volatilep, true);
16831 if (cvar == NULL_TREE
16832 || TREE_CODE (cvar) != VAR_DECL
16833 || DECL_ARTIFICIAL (cvar)
16834 || !TREE_PUBLIC (cvar))
16838 if (offset != NULL)
16840 if (!host_integerp (offset, 0))
16842 *value = tree_low_cst (offset, 0);
16845 *value += bitpos / BITS_PER_UNIT;
16850 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16851 data attribute for a variable or a parameter. We generate the
16852 DW_AT_const_value attribute only in those cases where the given variable
16853 or parameter does not have a true "location" either in memory or in a
16854 register. This can happen (for example) when a constant is passed as an
16855 actual argument in a call to an inline function. (It's possible that
16856 these things can crop up in other ways also.) Note that one type of
16857 constant value which can be passed into an inlined function is a constant
16858 pointer. This can happen for example if an actual argument in an inlined
16859 function call evaluates to a compile-time constant address. */
16862 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16863 enum dwarf_attribute attr)
16866 dw_loc_list_ref list;
16867 var_loc_list *loc_list;
16869 if (TREE_CODE (decl) == ERROR_MARK)
16872 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16873 || TREE_CODE (decl) == RESULT_DECL);
16875 /* Try to get some constant RTL for this decl, and use that as the value of
16878 rtl = rtl_for_decl_location (decl);
16879 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16880 && add_const_value_attribute (die, rtl))
16883 /* See if we have single element location list that is equivalent to
16884 a constant value. That way we are better to use add_const_value_attribute
16885 rather than expanding constant value equivalent. */
16886 loc_list = lookup_decl_loc (decl);
16889 && loc_list->first->next == NULL
16890 && NOTE_P (loc_list->first->loc)
16891 && NOTE_VAR_LOCATION (loc_list->first->loc)
16892 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16894 struct var_loc_node *node;
16896 node = loc_list->first;
16897 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16898 if (GET_CODE (rtl) == EXPR_LIST)
16899 rtl = XEXP (rtl, 0);
16900 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16901 && add_const_value_attribute (die, rtl))
16904 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16907 add_AT_location_description (die, attr, list);
16910 /* None of that worked, so it must not really have a location;
16911 try adding a constant value attribute from the DECL_INITIAL. */
16912 return tree_add_const_value_attribute_for_decl (die, decl);
16915 /* Add VARIABLE and DIE into deferred locations list. */
16918 defer_location (tree variable, dw_die_ref die)
16920 deferred_locations entry;
16921 entry.variable = variable;
16923 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16926 /* Helper function for tree_add_const_value_attribute. Natively encode
16927 initializer INIT into an array. Return true if successful. */
16930 native_encode_initializer (tree init, unsigned char *array, int size)
16934 if (init == NULL_TREE)
16938 switch (TREE_CODE (init))
16941 type = TREE_TYPE (init);
16942 if (TREE_CODE (type) == ARRAY_TYPE)
16944 tree enttype = TREE_TYPE (type);
16945 enum machine_mode mode = TYPE_MODE (enttype);
16947 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16949 if (int_size_in_bytes (type) != size)
16951 if (size > TREE_STRING_LENGTH (init))
16953 memcpy (array, TREE_STRING_POINTER (init),
16954 TREE_STRING_LENGTH (init));
16955 memset (array + TREE_STRING_LENGTH (init),
16956 '\0', size - TREE_STRING_LENGTH (init));
16959 memcpy (array, TREE_STRING_POINTER (init), size);
16964 type = TREE_TYPE (init);
16965 if (int_size_in_bytes (type) != size)
16967 if (TREE_CODE (type) == ARRAY_TYPE)
16969 HOST_WIDE_INT min_index;
16970 unsigned HOST_WIDE_INT cnt;
16971 int curpos = 0, fieldsize;
16972 constructor_elt *ce;
16974 if (TYPE_DOMAIN (type) == NULL_TREE
16975 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
16978 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16979 if (fieldsize <= 0)
16982 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
16983 memset (array, '\0', size);
16984 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
16986 tree val = ce->value;
16987 tree index = ce->index;
16989 if (index && TREE_CODE (index) == RANGE_EXPR)
16990 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
16993 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
16998 if (!native_encode_initializer (val, array + pos, fieldsize))
17001 curpos = pos + fieldsize;
17002 if (index && TREE_CODE (index) == RANGE_EXPR)
17004 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17005 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17009 memcpy (array + curpos, array + pos, fieldsize);
17010 curpos += fieldsize;
17013 gcc_assert (curpos <= size);
17017 else if (TREE_CODE (type) == RECORD_TYPE
17018 || TREE_CODE (type) == UNION_TYPE)
17020 tree field = NULL_TREE;
17021 unsigned HOST_WIDE_INT cnt;
17022 constructor_elt *ce;
17024 if (int_size_in_bytes (type) != size)
17027 if (TREE_CODE (type) == RECORD_TYPE)
17028 field = TYPE_FIELDS (type);
17030 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17032 tree val = ce->value;
17033 int pos, fieldsize;
17035 if (ce->index != 0)
17041 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17044 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17045 && TYPE_DOMAIN (TREE_TYPE (field))
17046 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17048 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17049 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17051 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17052 pos = int_byte_position (field);
17053 gcc_assert (pos + fieldsize <= size);
17055 && !native_encode_initializer (val, array + pos, fieldsize))
17061 case VIEW_CONVERT_EXPR:
17062 case NON_LVALUE_EXPR:
17063 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17065 return native_encode_expr (init, array, size) == size;
17069 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17070 attribute is the const value T. */
17073 tree_add_const_value_attribute (dw_die_ref die, tree t)
17076 tree type = TREE_TYPE (t);
17079 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17083 gcc_assert (!DECL_P (init));
17085 rtl = rtl_for_decl_init (init, type);
17087 return add_const_value_attribute (die, rtl);
17088 /* If the host and target are sane, try harder. */
17089 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17090 && initializer_constant_valid_p (init, type))
17092 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17093 if (size > 0 && (int) size == size)
17095 unsigned char *array = (unsigned char *)
17096 ggc_alloc_cleared_atomic (size);
17098 if (native_encode_initializer (init, array, size))
17100 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17108 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17109 attribute is the const value of T, where T is an integral constant
17110 variable with static storage duration
17111 (so it can't be a PARM_DECL or a RESULT_DECL). */
17114 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17118 || (TREE_CODE (decl) != VAR_DECL
17119 && TREE_CODE (decl) != CONST_DECL))
17122 if (TREE_READONLY (decl)
17123 && ! TREE_THIS_VOLATILE (decl)
17124 && DECL_INITIAL (decl))
17129 /* Don't add DW_AT_const_value if abstract origin already has one. */
17130 if (get_AT (var_die, DW_AT_const_value))
17133 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17136 /* Convert the CFI instructions for the current function into a
17137 location list. This is used for DW_AT_frame_base when we targeting
17138 a dwarf2 consumer that does not support the dwarf3
17139 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17142 static dw_loc_list_ref
17143 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17146 dw_loc_list_ref list, *list_tail;
17148 dw_cfa_location last_cfa, next_cfa;
17149 const char *start_label, *last_label, *section;
17150 dw_cfa_location remember;
17152 fde = current_fde ();
17153 gcc_assert (fde != NULL);
17155 section = secname_for_decl (current_function_decl);
17159 memset (&next_cfa, 0, sizeof (next_cfa));
17160 next_cfa.reg = INVALID_REGNUM;
17161 remember = next_cfa;
17163 start_label = fde->dw_fde_begin;
17165 /* ??? Bald assumption that the CIE opcode list does not contain
17166 advance opcodes. */
17167 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17168 lookup_cfa_1 (cfi, &next_cfa, &remember);
17170 last_cfa = next_cfa;
17171 last_label = start_label;
17173 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17174 switch (cfi->dw_cfi_opc)
17176 case DW_CFA_set_loc:
17177 case DW_CFA_advance_loc1:
17178 case DW_CFA_advance_loc2:
17179 case DW_CFA_advance_loc4:
17180 if (!cfa_equal_p (&last_cfa, &next_cfa))
17182 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17183 start_label, last_label, section);
17185 list_tail = &(*list_tail)->dw_loc_next;
17186 last_cfa = next_cfa;
17187 start_label = last_label;
17189 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17192 case DW_CFA_advance_loc:
17193 /* The encoding is complex enough that we should never emit this. */
17194 gcc_unreachable ();
17197 lookup_cfa_1 (cfi, &next_cfa, &remember);
17201 if (!cfa_equal_p (&last_cfa, &next_cfa))
17203 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17204 start_label, last_label, section);
17205 list_tail = &(*list_tail)->dw_loc_next;
17206 start_label = last_label;
17209 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17210 start_label, fde->dw_fde_end, section);
17212 if (list && list->dw_loc_next)
17218 /* Compute a displacement from the "steady-state frame pointer" to the
17219 frame base (often the same as the CFA), and store it in
17220 frame_pointer_fb_offset. OFFSET is added to the displacement
17221 before the latter is negated. */
17224 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17228 #ifdef FRAME_POINTER_CFA_OFFSET
17229 reg = frame_pointer_rtx;
17230 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17232 reg = arg_pointer_rtx;
17233 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17236 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17237 if (GET_CODE (elim) == PLUS)
17239 offset += INTVAL (XEXP (elim, 1));
17240 elim = XEXP (elim, 0);
17243 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17244 && (elim == hard_frame_pointer_rtx
17245 || elim == stack_pointer_rtx))
17246 || elim == (frame_pointer_needed
17247 ? hard_frame_pointer_rtx
17248 : stack_pointer_rtx));
17250 frame_pointer_fb_offset = -offset;
17253 /* Generate a DW_AT_name attribute given some string value to be included as
17254 the value of the attribute. */
17257 add_name_attribute (dw_die_ref die, const char *name_string)
17259 if (name_string != NULL && *name_string != 0)
17261 if (demangle_name_func)
17262 name_string = (*demangle_name_func) (name_string);
17264 add_AT_string (die, DW_AT_name, name_string);
17268 /* Generate a DW_AT_comp_dir attribute for DIE. */
17271 add_comp_dir_attribute (dw_die_ref die)
17273 const char *wd = get_src_pwd ();
17279 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17283 wdlen = strlen (wd);
17284 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17286 wd1 [wdlen] = DIR_SEPARATOR;
17287 wd1 [wdlen + 1] = 0;
17291 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17294 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17298 lower_bound_default (void)
17300 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17305 case DW_LANG_C_plus_plus:
17307 case DW_LANG_ObjC_plus_plus:
17310 case DW_LANG_Fortran77:
17311 case DW_LANG_Fortran90:
17312 case DW_LANG_Fortran95:
17316 case DW_LANG_Python:
17317 return dwarf_version >= 4 ? 0 : -1;
17318 case DW_LANG_Ada95:
17319 case DW_LANG_Ada83:
17320 case DW_LANG_Cobol74:
17321 case DW_LANG_Cobol85:
17322 case DW_LANG_Pascal83:
17323 case DW_LANG_Modula2:
17325 return dwarf_version >= 4 ? 1 : -1;
17331 /* Given a tree node describing an array bound (either lower or upper) output
17332 a representation for that bound. */
17335 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17337 switch (TREE_CODE (bound))
17342 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17345 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17348 /* Use the default if possible. */
17349 if (bound_attr == DW_AT_lower_bound
17350 && host_integerp (bound, 0)
17351 && (dflt = lower_bound_default ()) != -1
17352 && tree_low_cst (bound, 0) == dflt)
17355 /* Otherwise represent the bound as an unsigned value with the
17356 precision of its type. The precision and signedness of the
17357 type will be necessary to re-interpret it unambiguously. */
17358 else if (prec < HOST_BITS_PER_WIDE_INT)
17360 unsigned HOST_WIDE_INT mask
17361 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17362 add_AT_unsigned (subrange_die, bound_attr,
17363 TREE_INT_CST_LOW (bound) & mask);
17365 else if (prec == HOST_BITS_PER_WIDE_INT
17366 || TREE_INT_CST_HIGH (bound) == 0)
17367 add_AT_unsigned (subrange_die, bound_attr,
17368 TREE_INT_CST_LOW (bound));
17370 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17371 TREE_INT_CST_LOW (bound));
17376 case VIEW_CONVERT_EXPR:
17377 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17387 dw_die_ref decl_die = lookup_decl_die (bound);
17389 /* ??? Can this happen, or should the variable have been bound
17390 first? Probably it can, since I imagine that we try to create
17391 the types of parameters in the order in which they exist in
17392 the list, and won't have created a forward reference to a
17393 later parameter. */
17394 if (decl_die != NULL)
17396 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17404 /* Otherwise try to create a stack operation procedure to
17405 evaluate the value of the array bound. */
17407 dw_die_ref ctx, decl_die;
17408 dw_loc_list_ref list;
17410 list = loc_list_from_tree (bound, 2);
17411 if (list == NULL || single_element_loc_list_p (list))
17413 /* If DW_AT_*bound is not a reference nor constant, it is
17414 a DWARF expression rather than location description.
17415 For that loc_list_from_tree (bound, 0) is needed.
17416 If that fails to give a single element list,
17417 fall back to outputting this as a reference anyway. */
17418 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17419 if (list2 && single_element_loc_list_p (list2))
17421 add_AT_loc (subrange_die, bound_attr, list2->expr);
17428 if (current_function_decl == 0)
17429 ctx = comp_unit_die ();
17431 ctx = lookup_decl_die (current_function_decl);
17433 decl_die = new_die (DW_TAG_variable, ctx, bound);
17434 add_AT_flag (decl_die, DW_AT_artificial, 1);
17435 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17436 add_AT_location_description (decl_die, DW_AT_location, list);
17437 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17443 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17444 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17445 Note that the block of subscript information for an array type also
17446 includes information about the element type of the given array type. */
17449 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17451 unsigned dimension_number;
17453 dw_die_ref subrange_die;
17455 for (dimension_number = 0;
17456 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17457 type = TREE_TYPE (type), dimension_number++)
17459 tree domain = TYPE_DOMAIN (type);
17461 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17464 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17465 and (in GNU C only) variable bounds. Handle all three forms
17467 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17470 /* We have an array type with specified bounds. */
17471 lower = TYPE_MIN_VALUE (domain);
17472 upper = TYPE_MAX_VALUE (domain);
17474 /* Define the index type. */
17475 if (TREE_TYPE (domain))
17477 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17478 TREE_TYPE field. We can't emit debug info for this
17479 because it is an unnamed integral type. */
17480 if (TREE_CODE (domain) == INTEGER_TYPE
17481 && TYPE_NAME (domain) == NULL_TREE
17482 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17483 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17486 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17490 /* ??? If upper is NULL, the array has unspecified length,
17491 but it does have a lower bound. This happens with Fortran
17493 Since the debugger is definitely going to need to know N
17494 to produce useful results, go ahead and output the lower
17495 bound solo, and hope the debugger can cope. */
17497 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17499 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17502 /* Otherwise we have an array type with an unspecified length. The
17503 DWARF-2 spec does not say how to handle this; let's just leave out the
17509 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17513 switch (TREE_CODE (tree_node))
17518 case ENUMERAL_TYPE:
17521 case QUAL_UNION_TYPE:
17522 size = int_size_in_bytes (tree_node);
17525 /* For a data member of a struct or union, the DW_AT_byte_size is
17526 generally given as the number of bytes normally allocated for an
17527 object of the *declared* type of the member itself. This is true
17528 even for bit-fields. */
17529 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17532 gcc_unreachable ();
17535 /* Note that `size' might be -1 when we get to this point. If it is, that
17536 indicates that the byte size of the entity in question is variable. We
17537 have no good way of expressing this fact in Dwarf at the present time,
17538 so just let the -1 pass on through. */
17539 add_AT_unsigned (die, DW_AT_byte_size, size);
17542 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17543 which specifies the distance in bits from the highest order bit of the
17544 "containing object" for the bit-field to the highest order bit of the
17547 For any given bit-field, the "containing object" is a hypothetical object
17548 (of some integral or enum type) within which the given bit-field lives. The
17549 type of this hypothetical "containing object" is always the same as the
17550 declared type of the individual bit-field itself. The determination of the
17551 exact location of the "containing object" for a bit-field is rather
17552 complicated. It's handled by the `field_byte_offset' function (above).
17554 Note that it is the size (in bytes) of the hypothetical "containing object"
17555 which will be given in the DW_AT_byte_size attribute for this bit-field.
17556 (See `byte_size_attribute' above). */
17559 add_bit_offset_attribute (dw_die_ref die, tree decl)
17561 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17562 tree type = DECL_BIT_FIELD_TYPE (decl);
17563 HOST_WIDE_INT bitpos_int;
17564 HOST_WIDE_INT highest_order_object_bit_offset;
17565 HOST_WIDE_INT highest_order_field_bit_offset;
17566 HOST_WIDE_INT unsigned bit_offset;
17568 /* Must be a field and a bit field. */
17569 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17571 /* We can't yet handle bit-fields whose offsets are variable, so if we
17572 encounter such things, just return without generating any attribute
17573 whatsoever. Likewise for variable or too large size. */
17574 if (! host_integerp (bit_position (decl), 0)
17575 || ! host_integerp (DECL_SIZE (decl), 1))
17578 bitpos_int = int_bit_position (decl);
17580 /* Note that the bit offset is always the distance (in bits) from the
17581 highest-order bit of the "containing object" to the highest-order bit of
17582 the bit-field itself. Since the "high-order end" of any object or field
17583 is different on big-endian and little-endian machines, the computation
17584 below must take account of these differences. */
17585 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17586 highest_order_field_bit_offset = bitpos_int;
17588 if (! BYTES_BIG_ENDIAN)
17590 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17591 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17595 = (! BYTES_BIG_ENDIAN
17596 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17597 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17599 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
17602 /* For a FIELD_DECL node which represents a bit field, output an attribute
17603 which specifies the length in bits of the given field. */
17606 add_bit_size_attribute (dw_die_ref die, tree decl)
17608 /* Must be a field and a bit field. */
17609 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17610 && DECL_BIT_FIELD_TYPE (decl));
17612 if (host_integerp (DECL_SIZE (decl), 1))
17613 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17616 /* If the compiled language is ANSI C, then add a 'prototyped'
17617 attribute, if arg types are given for the parameters of a function. */
17620 add_prototyped_attribute (dw_die_ref die, tree func_type)
17622 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17623 && TYPE_ARG_TYPES (func_type) != NULL)
17624 add_AT_flag (die, DW_AT_prototyped, 1);
17627 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17628 by looking in either the type declaration or object declaration
17631 static inline dw_die_ref
17632 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17634 dw_die_ref origin_die = NULL;
17636 if (TREE_CODE (origin) != FUNCTION_DECL)
17638 /* We may have gotten separated from the block for the inlined
17639 function, if we're in an exception handler or some such; make
17640 sure that the abstract function has been written out.
17642 Doing this for nested functions is wrong, however; functions are
17643 distinct units, and our context might not even be inline. */
17647 fn = TYPE_STUB_DECL (fn);
17649 fn = decl_function_context (fn);
17651 dwarf2out_abstract_function (fn);
17654 if (DECL_P (origin))
17655 origin_die = lookup_decl_die (origin);
17656 else if (TYPE_P (origin))
17657 origin_die = lookup_type_die (origin);
17659 /* XXX: Functions that are never lowered don't always have correct block
17660 trees (in the case of java, they simply have no block tree, in some other
17661 languages). For these functions, there is nothing we can really do to
17662 output correct debug info for inlined functions in all cases. Rather
17663 than die, we'll just produce deficient debug info now, in that we will
17664 have variables without a proper abstract origin. In the future, when all
17665 functions are lowered, we should re-add a gcc_assert (origin_die)
17669 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17673 /* We do not currently support the pure_virtual attribute. */
17676 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17678 if (DECL_VINDEX (func_decl))
17680 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17682 if (host_integerp (DECL_VINDEX (func_decl), 0))
17683 add_AT_loc (die, DW_AT_vtable_elem_location,
17684 new_loc_descr (DW_OP_constu,
17685 tree_low_cst (DECL_VINDEX (func_decl), 0),
17688 /* GNU extension: Record what type this method came from originally. */
17689 if (debug_info_level > DINFO_LEVEL_TERSE
17690 && DECL_CONTEXT (func_decl))
17691 add_AT_die_ref (die, DW_AT_containing_type,
17692 lookup_type_die (DECL_CONTEXT (func_decl)));
17696 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17697 given decl. This used to be a vendor extension until after DWARF 4
17698 standardized it. */
17701 add_linkage_attr (dw_die_ref die, tree decl)
17703 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17705 /* Mimic what assemble_name_raw does with a leading '*'. */
17706 if (name[0] == '*')
17709 if (dwarf_version >= 4)
17710 add_AT_string (die, DW_AT_linkage_name, name);
17712 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17715 /* Add source coordinate attributes for the given decl. */
17718 add_src_coords_attributes (dw_die_ref die, tree decl)
17720 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17722 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17723 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17726 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17729 add_linkage_name (dw_die_ref die, tree decl)
17731 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17732 && TREE_PUBLIC (decl)
17733 && !DECL_ABSTRACT (decl)
17734 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17735 && die->die_tag != DW_TAG_member)
17737 /* Defer until we have an assembler name set. */
17738 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17740 limbo_die_node *asm_name;
17742 asm_name = ggc_alloc_cleared_limbo_die_node ();
17743 asm_name->die = die;
17744 asm_name->created_for = decl;
17745 asm_name->next = deferred_asm_name;
17746 deferred_asm_name = asm_name;
17748 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17749 add_linkage_attr (die, decl);
17753 /* Add a DW_AT_name attribute and source coordinate attribute for the
17754 given decl, but only if it actually has a name. */
17757 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17761 decl_name = DECL_NAME (decl);
17762 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17764 const char *name = dwarf2_name (decl, 0);
17766 add_name_attribute (die, name);
17767 if (! DECL_ARTIFICIAL (decl))
17768 add_src_coords_attributes (die, decl);
17770 add_linkage_name (die, decl);
17773 #ifdef VMS_DEBUGGING_INFO
17774 /* Get the function's name, as described by its RTL. This may be different
17775 from the DECL_NAME name used in the source file. */
17776 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17778 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17779 XEXP (DECL_RTL (decl), 0));
17780 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17782 #endif /* VMS_DEBUGGING_INFO */
17785 #ifdef VMS_DEBUGGING_INFO
17786 /* Output the debug main pointer die for VMS */
17789 dwarf2out_vms_debug_main_pointer (void)
17791 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17794 /* Allocate the VMS debug main subprogram die. */
17795 die = ggc_alloc_cleared_die_node ();
17796 die->die_tag = DW_TAG_subprogram;
17797 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17798 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17799 current_function_funcdef_no);
17800 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17802 /* Make it the first child of comp_unit_die (). */
17803 die->die_parent = comp_unit_die ();
17804 if (comp_unit_die ()->die_child)
17806 die->die_sib = comp_unit_die ()->die_child->die_sib;
17807 comp_unit_die ()->die_child->die_sib = die;
17811 die->die_sib = die;
17812 comp_unit_die ()->die_child = die;
17815 #endif /* VMS_DEBUGGING_INFO */
17817 /* Push a new declaration scope. */
17820 push_decl_scope (tree scope)
17822 VEC_safe_push (tree, gc, decl_scope_table, scope);
17825 /* Pop a declaration scope. */
17828 pop_decl_scope (void)
17830 VEC_pop (tree, decl_scope_table);
17833 /* Return the DIE for the scope that immediately contains this type.
17834 Non-named types get global scope. Named types nested in other
17835 types get their containing scope if it's open, or global scope
17836 otherwise. All other types (i.e. function-local named types) get
17837 the current active scope. */
17840 scope_die_for (tree t, dw_die_ref context_die)
17842 dw_die_ref scope_die = NULL;
17843 tree containing_scope;
17846 /* Non-types always go in the current scope. */
17847 gcc_assert (TYPE_P (t));
17849 containing_scope = TYPE_CONTEXT (t);
17851 /* Use the containing namespace if it was passed in (for a declaration). */
17852 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17854 if (context_die == lookup_decl_die (containing_scope))
17857 containing_scope = NULL_TREE;
17860 /* Ignore function type "scopes" from the C frontend. They mean that
17861 a tagged type is local to a parmlist of a function declarator, but
17862 that isn't useful to DWARF. */
17863 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17864 containing_scope = NULL_TREE;
17866 if (SCOPE_FILE_SCOPE_P (containing_scope))
17867 scope_die = comp_unit_die ();
17868 else if (TYPE_P (containing_scope))
17870 /* For types, we can just look up the appropriate DIE. But
17871 first we check to see if we're in the middle of emitting it
17872 so we know where the new DIE should go. */
17873 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17874 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17879 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17880 || TREE_ASM_WRITTEN (containing_scope));
17881 /*We are not in the middle of emitting the type
17882 CONTAINING_SCOPE. Let's see if it's emitted already. */
17883 scope_die = lookup_type_die (containing_scope);
17885 /* If none of the current dies are suitable, we get file scope. */
17886 if (scope_die == NULL)
17887 scope_die = comp_unit_die ();
17890 scope_die = lookup_type_die (containing_scope);
17893 scope_die = context_die;
17898 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17901 local_scope_p (dw_die_ref context_die)
17903 for (; context_die; context_die = context_die->die_parent)
17904 if (context_die->die_tag == DW_TAG_inlined_subroutine
17905 || context_die->die_tag == DW_TAG_subprogram)
17911 /* Returns nonzero if CONTEXT_DIE is a class. */
17914 class_scope_p (dw_die_ref context_die)
17916 return (context_die
17917 && (context_die->die_tag == DW_TAG_structure_type
17918 || context_die->die_tag == DW_TAG_class_type
17919 || context_die->die_tag == DW_TAG_interface_type
17920 || context_die->die_tag == DW_TAG_union_type));
17923 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17924 whether or not to treat a DIE in this context as a declaration. */
17927 class_or_namespace_scope_p (dw_die_ref context_die)
17929 return (class_scope_p (context_die)
17930 || (context_die && context_die->die_tag == DW_TAG_namespace));
17933 /* Many forms of DIEs require a "type description" attribute. This
17934 routine locates the proper "type descriptor" die for the type given
17935 by 'type', and adds a DW_AT_type attribute below the given die. */
17938 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17939 int decl_volatile, dw_die_ref context_die)
17941 enum tree_code code = TREE_CODE (type);
17942 dw_die_ref type_die = NULL;
17944 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17945 or fixed-point type, use the inner type. This is because we have no
17946 support for unnamed types in base_type_die. This can happen if this is
17947 an Ada subrange type. Correct solution is emit a subrange type die. */
17948 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17949 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17950 type = TREE_TYPE (type), code = TREE_CODE (type);
17952 if (code == ERROR_MARK
17953 /* Handle a special case. For functions whose return type is void, we
17954 generate *no* type attribute. (Note that no object may have type
17955 `void', so this only applies to function return types). */
17956 || code == VOID_TYPE)
17959 type_die = modified_type_die (type,
17960 decl_const || TYPE_READONLY (type),
17961 decl_volatile || TYPE_VOLATILE (type),
17964 if (type_die != NULL)
17965 add_AT_die_ref (object_die, DW_AT_type, type_die);
17968 /* Given an object die, add the calling convention attribute for the
17969 function call type. */
17971 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
17973 enum dwarf_calling_convention value = DW_CC_normal;
17975 value = ((enum dwarf_calling_convention)
17976 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
17979 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
17981 /* DWARF 2 doesn't provide a way to identify a program's source-level
17982 entry point. DW_AT_calling_convention attributes are only meant
17983 to describe functions' calling conventions. However, lacking a
17984 better way to signal the Fortran main program, we used this for
17985 a long time, following existing custom. Now, DWARF 4 has
17986 DW_AT_main_subprogram, which we add below, but some tools still
17987 rely on the old way, which we thus keep. */
17988 value = DW_CC_program;
17990 if (dwarf_version >= 4 || !dwarf_strict)
17991 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
17994 /* Only add the attribute if the backend requests it, and
17995 is not DW_CC_normal. */
17996 if (value && (value != DW_CC_normal))
17997 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18000 /* Given a tree pointer to a struct, class, union, or enum type node, return
18001 a pointer to the (string) tag name for the given type, or zero if the type
18002 was declared without a tag. */
18004 static const char *
18005 type_tag (const_tree type)
18007 const char *name = 0;
18009 if (TYPE_NAME (type) != 0)
18013 /* Find the IDENTIFIER_NODE for the type name. */
18014 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18015 && !TYPE_NAMELESS (type))
18016 t = TYPE_NAME (type);
18018 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18019 a TYPE_DECL node, regardless of whether or not a `typedef' was
18021 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18022 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18024 /* We want to be extra verbose. Don't call dwarf_name if
18025 DECL_NAME isn't set. The default hook for decl_printable_name
18026 doesn't like that, and in this context it's correct to return
18027 0, instead of "<anonymous>" or the like. */
18028 if (DECL_NAME (TYPE_NAME (type))
18029 && !DECL_NAMELESS (TYPE_NAME (type)))
18030 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18033 /* Now get the name as a string, or invent one. */
18034 if (!name && t != 0)
18035 name = IDENTIFIER_POINTER (t);
18038 return (name == 0 || *name == '\0') ? 0 : name;
18041 /* Return the type associated with a data member, make a special check
18042 for bit field types. */
18045 member_declared_type (const_tree member)
18047 return (DECL_BIT_FIELD_TYPE (member)
18048 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18051 /* Get the decl's label, as described by its RTL. This may be different
18052 from the DECL_NAME name used in the source file. */
18055 static const char *
18056 decl_start_label (tree decl)
18059 const char *fnname;
18061 x = DECL_RTL (decl);
18062 gcc_assert (MEM_P (x));
18065 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18067 fnname = XSTR (x, 0);
18072 /* These routines generate the internal representation of the DIE's for
18073 the compilation unit. Debugging information is collected by walking
18074 the declaration trees passed in from dwarf2out_decl(). */
18077 gen_array_type_die (tree type, dw_die_ref context_die)
18079 dw_die_ref scope_die = scope_die_for (type, context_die);
18080 dw_die_ref array_die;
18082 /* GNU compilers represent multidimensional array types as sequences of one
18083 dimensional array types whose element types are themselves array types.
18084 We sometimes squish that down to a single array_type DIE with multiple
18085 subscripts in the Dwarf debugging info. The draft Dwarf specification
18086 say that we are allowed to do this kind of compression in C, because
18087 there is no difference between an array of arrays and a multidimensional
18088 array. We don't do this for Ada to remain as close as possible to the
18089 actual representation, which is especially important against the language
18090 flexibilty wrt arrays of variable size. */
18092 bool collapse_nested_arrays = !is_ada ();
18095 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18096 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18097 if (TYPE_STRING_FLAG (type)
18098 && TREE_CODE (type) == ARRAY_TYPE
18100 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18102 HOST_WIDE_INT size;
18104 array_die = new_die (DW_TAG_string_type, scope_die, type);
18105 add_name_attribute (array_die, type_tag (type));
18106 equate_type_number_to_die (type, array_die);
18107 size = int_size_in_bytes (type);
18109 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18110 else if (TYPE_DOMAIN (type) != NULL_TREE
18111 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18112 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18114 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18115 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18117 size = int_size_in_bytes (TREE_TYPE (szdecl));
18118 if (loc && size > 0)
18120 add_AT_location_description (array_die, DW_AT_string_length, loc);
18121 if (size != DWARF2_ADDR_SIZE)
18122 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18128 /* ??? The SGI dwarf reader fails for array of array of enum types
18129 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18130 array type comes before the outer array type. We thus call gen_type_die
18131 before we new_die and must prevent nested array types collapsing for this
18134 #ifdef MIPS_DEBUGGING_INFO
18135 gen_type_die (TREE_TYPE (type), context_die);
18136 collapse_nested_arrays = false;
18139 array_die = new_die (DW_TAG_array_type, scope_die, type);
18140 add_name_attribute (array_die, type_tag (type));
18141 equate_type_number_to_die (type, array_die);
18143 if (TREE_CODE (type) == VECTOR_TYPE)
18144 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18146 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18148 && TREE_CODE (type) == ARRAY_TYPE
18149 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18150 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18151 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18154 /* We default the array ordering. SDB will probably do
18155 the right things even if DW_AT_ordering is not present. It's not even
18156 an issue until we start to get into multidimensional arrays anyway. If
18157 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18158 then we'll have to put the DW_AT_ordering attribute back in. (But if
18159 and when we find out that we need to put these in, we will only do so
18160 for multidimensional arrays. */
18161 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18164 #ifdef MIPS_DEBUGGING_INFO
18165 /* The SGI compilers handle arrays of unknown bound by setting
18166 AT_declaration and not emitting any subrange DIEs. */
18167 if (TREE_CODE (type) == ARRAY_TYPE
18168 && ! TYPE_DOMAIN (type))
18169 add_AT_flag (array_die, DW_AT_declaration, 1);
18172 if (TREE_CODE (type) == VECTOR_TYPE)
18174 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18175 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18176 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18177 add_bound_info (subrange_die, DW_AT_upper_bound,
18178 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18181 add_subscript_info (array_die, type, collapse_nested_arrays);
18183 /* Add representation of the type of the elements of this array type and
18184 emit the corresponding DIE if we haven't done it already. */
18185 element_type = TREE_TYPE (type);
18186 if (collapse_nested_arrays)
18187 while (TREE_CODE (element_type) == ARRAY_TYPE)
18189 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18191 element_type = TREE_TYPE (element_type);
18194 #ifndef MIPS_DEBUGGING_INFO
18195 gen_type_die (element_type, context_die);
18198 add_type_attribute (array_die, element_type, 0, 0, context_die);
18200 if (get_AT (array_die, DW_AT_name))
18201 add_pubtype (type, array_die);
18204 static dw_loc_descr_ref
18205 descr_info_loc (tree val, tree base_decl)
18207 HOST_WIDE_INT size;
18208 dw_loc_descr_ref loc, loc2;
18209 enum dwarf_location_atom op;
18211 if (val == base_decl)
18212 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18214 switch (TREE_CODE (val))
18217 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18219 return loc_descriptor_from_tree (val, 0);
18221 if (host_integerp (val, 0))
18222 return int_loc_descriptor (tree_low_cst (val, 0));
18225 size = int_size_in_bytes (TREE_TYPE (val));
18228 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18231 if (size == DWARF2_ADDR_SIZE)
18232 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18234 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18236 case POINTER_PLUS_EXPR:
18238 if (host_integerp (TREE_OPERAND (val, 1), 1)
18239 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18242 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18245 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18251 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18254 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18257 add_loc_descr (&loc, loc2);
18258 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18280 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18281 tree val, tree base_decl)
18283 dw_loc_descr_ref loc;
18285 if (host_integerp (val, 0))
18287 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18291 loc = descr_info_loc (val, base_decl);
18295 add_AT_loc (die, attr, loc);
18298 /* This routine generates DIE for array with hidden descriptor, details
18299 are filled into *info by a langhook. */
18302 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18303 dw_die_ref context_die)
18305 dw_die_ref scope_die = scope_die_for (type, context_die);
18306 dw_die_ref array_die;
18309 array_die = new_die (DW_TAG_array_type, scope_die, type);
18310 add_name_attribute (array_die, type_tag (type));
18311 equate_type_number_to_die (type, array_die);
18313 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18315 && info->ndimensions >= 2)
18316 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18318 if (info->data_location)
18319 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18321 if (info->associated)
18322 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18324 if (info->allocated)
18325 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18328 for (dim = 0; dim < info->ndimensions; dim++)
18330 dw_die_ref subrange_die
18331 = new_die (DW_TAG_subrange_type, array_die, NULL);
18333 if (info->dimen[dim].lower_bound)
18335 /* If it is the default value, omit it. */
18338 if (host_integerp (info->dimen[dim].lower_bound, 0)
18339 && (dflt = lower_bound_default ()) != -1
18340 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18343 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18344 info->dimen[dim].lower_bound,
18347 if (info->dimen[dim].upper_bound)
18348 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18349 info->dimen[dim].upper_bound,
18351 if (info->dimen[dim].stride)
18352 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18353 info->dimen[dim].stride,
18357 gen_type_die (info->element_type, context_die);
18358 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18360 if (get_AT (array_die, DW_AT_name))
18361 add_pubtype (type, array_die);
18366 gen_entry_point_die (tree decl, dw_die_ref context_die)
18368 tree origin = decl_ultimate_origin (decl);
18369 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18371 if (origin != NULL)
18372 add_abstract_origin_attribute (decl_die, origin);
18375 add_name_and_src_coords_attributes (decl_die, decl);
18376 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18377 0, 0, context_die);
18380 if (DECL_ABSTRACT (decl))
18381 equate_decl_number_to_die (decl, decl_die);
18383 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18387 /* Walk through the list of incomplete types again, trying once more to
18388 emit full debugging info for them. */
18391 retry_incomplete_types (void)
18395 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18396 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18397 DINFO_USAGE_DIR_USE))
18398 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18401 /* Determine what tag to use for a record type. */
18403 static enum dwarf_tag
18404 record_type_tag (tree type)
18406 if (! lang_hooks.types.classify_record)
18407 return DW_TAG_structure_type;
18409 switch (lang_hooks.types.classify_record (type))
18411 case RECORD_IS_STRUCT:
18412 return DW_TAG_structure_type;
18414 case RECORD_IS_CLASS:
18415 return DW_TAG_class_type;
18417 case RECORD_IS_INTERFACE:
18418 if (dwarf_version >= 3 || !dwarf_strict)
18419 return DW_TAG_interface_type;
18420 return DW_TAG_structure_type;
18423 gcc_unreachable ();
18427 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18428 include all of the information about the enumeration values also. Each
18429 enumerated type name/value is listed as a child of the enumerated type
18433 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18435 dw_die_ref type_die = lookup_type_die (type);
18437 if (type_die == NULL)
18439 type_die = new_die (DW_TAG_enumeration_type,
18440 scope_die_for (type, context_die), type);
18441 equate_type_number_to_die (type, type_die);
18442 add_name_attribute (type_die, type_tag (type));
18443 if (dwarf_version >= 4 || !dwarf_strict)
18445 if (ENUM_IS_SCOPED (type))
18446 add_AT_flag (type_die, DW_AT_enum_class, 1);
18447 if (ENUM_IS_OPAQUE (type))
18448 add_AT_flag (type_die, DW_AT_declaration, 1);
18451 else if (! TYPE_SIZE (type))
18454 remove_AT (type_die, DW_AT_declaration);
18456 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18457 given enum type is incomplete, do not generate the DW_AT_byte_size
18458 attribute or the DW_AT_element_list attribute. */
18459 if (TYPE_SIZE (type))
18463 TREE_ASM_WRITTEN (type) = 1;
18464 add_byte_size_attribute (type_die, type);
18465 if (TYPE_STUB_DECL (type) != NULL_TREE)
18467 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18468 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18471 /* If the first reference to this type was as the return type of an
18472 inline function, then it may not have a parent. Fix this now. */
18473 if (type_die->die_parent == NULL)
18474 add_child_die (scope_die_for (type, context_die), type_die);
18476 for (link = TYPE_VALUES (type);
18477 link != NULL; link = TREE_CHAIN (link))
18479 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18480 tree value = TREE_VALUE (link);
18482 add_name_attribute (enum_die,
18483 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18485 if (TREE_CODE (value) == CONST_DECL)
18486 value = DECL_INITIAL (value);
18488 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18489 /* DWARF2 does not provide a way of indicating whether or
18490 not enumeration constants are signed or unsigned. GDB
18491 always assumes the values are signed, so we output all
18492 values as if they were signed. That means that
18493 enumeration constants with very large unsigned values
18494 will appear to have negative values in the debugger. */
18495 add_AT_int (enum_die, DW_AT_const_value,
18496 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18500 add_AT_flag (type_die, DW_AT_declaration, 1);
18502 if (get_AT (type_die, DW_AT_name))
18503 add_pubtype (type, type_die);
18508 /* Generate a DIE to represent either a real live formal parameter decl or to
18509 represent just the type of some formal parameter position in some function
18512 Note that this routine is a bit unusual because its argument may be a
18513 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18514 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18515 node. If it's the former then this function is being called to output a
18516 DIE to represent a formal parameter object (or some inlining thereof). If
18517 it's the latter, then this function is only being called to output a
18518 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18519 argument type of some subprogram type.
18520 If EMIT_NAME_P is true, name and source coordinate attributes
18524 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18525 dw_die_ref context_die)
18527 tree node_or_origin = node ? node : origin;
18528 tree ultimate_origin;
18529 dw_die_ref parm_die
18530 = new_die (DW_TAG_formal_parameter, context_die, node);
18532 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18534 case tcc_declaration:
18535 ultimate_origin = decl_ultimate_origin (node_or_origin);
18536 if (node || ultimate_origin)
18537 origin = ultimate_origin;
18538 if (origin != NULL)
18539 add_abstract_origin_attribute (parm_die, origin);
18540 else if (emit_name_p)
18541 add_name_and_src_coords_attributes (parm_die, node);
18543 || (! DECL_ABSTRACT (node_or_origin)
18544 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18545 decl_function_context
18546 (node_or_origin))))
18548 tree type = TREE_TYPE (node_or_origin);
18549 if (decl_by_reference_p (node_or_origin))
18550 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18553 add_type_attribute (parm_die, type,
18554 TREE_READONLY (node_or_origin),
18555 TREE_THIS_VOLATILE (node_or_origin),
18558 if (origin == NULL && DECL_ARTIFICIAL (node))
18559 add_AT_flag (parm_die, DW_AT_artificial, 1);
18561 if (node && node != origin)
18562 equate_decl_number_to_die (node, parm_die);
18563 if (! DECL_ABSTRACT (node_or_origin))
18564 add_location_or_const_value_attribute (parm_die, node_or_origin,
18570 /* We were called with some kind of a ..._TYPE node. */
18571 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18575 gcc_unreachable ();
18581 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18582 children DW_TAG_formal_parameter DIEs representing the arguments of the
18585 PARM_PACK must be a function parameter pack.
18586 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18587 must point to the subsequent arguments of the function PACK_ARG belongs to.
18588 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18589 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18590 following the last one for which a DIE was generated. */
18593 gen_formal_parameter_pack_die (tree parm_pack,
18595 dw_die_ref subr_die,
18599 dw_die_ref parm_pack_die;
18601 gcc_assert (parm_pack
18602 && lang_hooks.function_parameter_pack_p (parm_pack)
18605 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18606 add_src_coords_attributes (parm_pack_die, parm_pack);
18608 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18610 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18613 gen_formal_parameter_die (arg, NULL,
18614 false /* Don't emit name attribute. */,
18619 return parm_pack_die;
18622 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18623 at the end of an (ANSI prototyped) formal parameters list. */
18626 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18628 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18631 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18632 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18633 parameters as specified in some function type specification (except for
18634 those which appear as part of a function *definition*). */
18637 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18640 tree formal_type = NULL;
18641 tree first_parm_type;
18644 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18646 arg = DECL_ARGUMENTS (function_or_method_type);
18647 function_or_method_type = TREE_TYPE (function_or_method_type);
18652 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18654 /* Make our first pass over the list of formal parameter types and output a
18655 DW_TAG_formal_parameter DIE for each one. */
18656 for (link = first_parm_type; link; )
18658 dw_die_ref parm_die;
18660 formal_type = TREE_VALUE (link);
18661 if (formal_type == void_type_node)
18664 /* Output a (nameless) DIE to represent the formal parameter itself. */
18665 parm_die = gen_formal_parameter_die (formal_type, NULL,
18666 true /* Emit name attribute. */,
18668 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18669 && link == first_parm_type)
18671 add_AT_flag (parm_die, DW_AT_artificial, 1);
18672 if (dwarf_version >= 3 || !dwarf_strict)
18673 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18675 else if (arg && DECL_ARTIFICIAL (arg))
18676 add_AT_flag (parm_die, DW_AT_artificial, 1);
18678 link = TREE_CHAIN (link);
18680 arg = DECL_CHAIN (arg);
18683 /* If this function type has an ellipsis, add a
18684 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18685 if (formal_type != void_type_node)
18686 gen_unspecified_parameters_die (function_or_method_type, context_die);
18688 /* Make our second (and final) pass over the list of formal parameter types
18689 and output DIEs to represent those types (as necessary). */
18690 for (link = TYPE_ARG_TYPES (function_or_method_type);
18691 link && TREE_VALUE (link);
18692 link = TREE_CHAIN (link))
18693 gen_type_die (TREE_VALUE (link), context_die);
18696 /* We want to generate the DIE for TYPE so that we can generate the
18697 die for MEMBER, which has been defined; we will need to refer back
18698 to the member declaration nested within TYPE. If we're trying to
18699 generate minimal debug info for TYPE, processing TYPE won't do the
18700 trick; we need to attach the member declaration by hand. */
18703 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18705 gen_type_die (type, context_die);
18707 /* If we're trying to avoid duplicate debug info, we may not have
18708 emitted the member decl for this function. Emit it now. */
18709 if (TYPE_STUB_DECL (type)
18710 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18711 && ! lookup_decl_die (member))
18713 dw_die_ref type_die;
18714 gcc_assert (!decl_ultimate_origin (member));
18716 push_decl_scope (type);
18717 type_die = lookup_type_die (type);
18718 if (TREE_CODE (member) == FUNCTION_DECL)
18719 gen_subprogram_die (member, type_die);
18720 else if (TREE_CODE (member) == FIELD_DECL)
18722 /* Ignore the nameless fields that are used to skip bits but handle
18723 C++ anonymous unions and structs. */
18724 if (DECL_NAME (member) != NULL_TREE
18725 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18726 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18728 gen_type_die (member_declared_type (member), type_die);
18729 gen_field_die (member, type_die);
18733 gen_variable_die (member, NULL_TREE, type_die);
18739 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18740 may later generate inlined and/or out-of-line instances of. */
18743 dwarf2out_abstract_function (tree decl)
18745 dw_die_ref old_die;
18749 htab_t old_decl_loc_table;
18751 /* Make sure we have the actual abstract inline, not a clone. */
18752 decl = DECL_ORIGIN (decl);
18754 old_die = lookup_decl_die (decl);
18755 if (old_die && get_AT (old_die, DW_AT_inline))
18756 /* We've already generated the abstract instance. */
18759 /* We can be called while recursively when seeing block defining inlined subroutine
18760 DIE. Be sure to not clobber the outer location table nor use it or we would
18761 get locations in abstract instantces. */
18762 old_decl_loc_table = decl_loc_table;
18763 decl_loc_table = NULL;
18765 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18766 we don't get confused by DECL_ABSTRACT. */
18767 if (debug_info_level > DINFO_LEVEL_TERSE)
18769 context = decl_class_context (decl);
18771 gen_type_die_for_member
18772 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18775 /* Pretend we've just finished compiling this function. */
18776 save_fn = current_function_decl;
18777 current_function_decl = decl;
18778 push_cfun (DECL_STRUCT_FUNCTION (decl));
18780 was_abstract = DECL_ABSTRACT (decl);
18781 set_decl_abstract_flags (decl, 1);
18782 dwarf2out_decl (decl);
18783 if (! was_abstract)
18784 set_decl_abstract_flags (decl, 0);
18786 current_function_decl = save_fn;
18787 decl_loc_table = old_decl_loc_table;
18791 /* Helper function of premark_used_types() which gets called through
18794 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18795 marked as unused by prune_unused_types. */
18798 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18803 type = (tree) *slot;
18804 die = lookup_type_die (type);
18806 die->die_perennial_p = 1;
18810 /* Helper function of premark_types_used_by_global_vars which gets called
18811 through htab_traverse.
18813 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18814 marked as unused by prune_unused_types. The DIE of the type is marked
18815 only if the global variable using the type will actually be emitted. */
18818 premark_types_used_by_global_vars_helper (void **slot,
18819 void *data ATTRIBUTE_UNUSED)
18821 struct types_used_by_vars_entry *entry;
18824 entry = (struct types_used_by_vars_entry *) *slot;
18825 gcc_assert (entry->type != NULL
18826 && entry->var_decl != NULL);
18827 die = lookup_type_die (entry->type);
18830 /* Ask cgraph if the global variable really is to be emitted.
18831 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18832 struct varpool_node *node = varpool_get_node (entry->var_decl);
18833 if (node && node->needed)
18835 die->die_perennial_p = 1;
18836 /* Keep the parent DIEs as well. */
18837 while ((die = die->die_parent) && die->die_perennial_p == 0)
18838 die->die_perennial_p = 1;
18844 /* Mark all members of used_types_hash as perennial. */
18847 premark_used_types (void)
18849 if (cfun && cfun->used_types_hash)
18850 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18853 /* Mark all members of types_used_by_vars_entry as perennial. */
18856 premark_types_used_by_global_vars (void)
18858 if (types_used_by_vars_hash)
18859 htab_traverse (types_used_by_vars_hash,
18860 premark_types_used_by_global_vars_helper, NULL);
18863 /* Generate a DIE to represent a declared function (either file-scope or
18867 gen_subprogram_die (tree decl, dw_die_ref context_die)
18869 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
18870 tree origin = decl_ultimate_origin (decl);
18871 dw_die_ref subr_die;
18874 dw_die_ref old_die = lookup_decl_die (decl);
18875 int declaration = (current_function_decl != decl
18876 || class_or_namespace_scope_p (context_die));
18878 premark_used_types ();
18880 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18881 started to generate the abstract instance of an inline, decided to output
18882 its containing class, and proceeded to emit the declaration of the inline
18883 from the member list for the class. If so, DECLARATION takes priority;
18884 we'll get back to the abstract instance when done with the class. */
18886 /* The class-scope declaration DIE must be the primary DIE. */
18887 if (origin && declaration && class_or_namespace_scope_p (context_die))
18890 gcc_assert (!old_die);
18893 /* Now that the C++ front end lazily declares artificial member fns, we
18894 might need to retrofit the declaration into its class. */
18895 if (!declaration && !origin && !old_die
18896 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18897 && !class_or_namespace_scope_p (context_die)
18898 && debug_info_level > DINFO_LEVEL_TERSE)
18899 old_die = force_decl_die (decl);
18901 if (origin != NULL)
18903 gcc_assert (!declaration || local_scope_p (context_die));
18905 /* Fixup die_parent for the abstract instance of a nested
18906 inline function. */
18907 if (old_die && old_die->die_parent == NULL)
18908 add_child_die (context_die, old_die);
18910 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18911 add_abstract_origin_attribute (subr_die, origin);
18915 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18916 struct dwarf_file_data * file_index = lookup_filename (s.file);
18918 if (!get_AT_flag (old_die, DW_AT_declaration)
18919 /* We can have a normal definition following an inline one in the
18920 case of redefinition of GNU C extern inlines.
18921 It seems reasonable to use AT_specification in this case. */
18922 && !get_AT (old_die, DW_AT_inline))
18924 /* Detect and ignore this case, where we are trying to output
18925 something we have already output. */
18929 /* If the definition comes from the same place as the declaration,
18930 maybe use the old DIE. We always want the DIE for this function
18931 that has the *_pc attributes to be under comp_unit_die so the
18932 debugger can find it. We also need to do this for abstract
18933 instances of inlines, since the spec requires the out-of-line copy
18934 to have the same parent. For local class methods, this doesn't
18935 apply; we just use the old DIE. */
18936 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
18937 && (DECL_ARTIFICIAL (decl)
18938 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
18939 && (get_AT_unsigned (old_die, DW_AT_decl_line)
18940 == (unsigned) s.line))))
18942 subr_die = old_die;
18944 /* Clear out the declaration attribute and the formal parameters.
18945 Do not remove all children, because it is possible that this
18946 declaration die was forced using force_decl_die(). In such
18947 cases die that forced declaration die (e.g. TAG_imported_module)
18948 is one of the children that we do not want to remove. */
18949 remove_AT (subr_die, DW_AT_declaration);
18950 remove_AT (subr_die, DW_AT_object_pointer);
18951 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
18955 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18956 add_AT_specification (subr_die, old_die);
18957 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18958 add_AT_file (subr_die, DW_AT_decl_file, file_index);
18959 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18960 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
18965 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18967 if (TREE_PUBLIC (decl))
18968 add_AT_flag (subr_die, DW_AT_external, 1);
18970 add_name_and_src_coords_attributes (subr_die, decl);
18971 if (debug_info_level > DINFO_LEVEL_TERSE)
18973 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
18974 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
18975 0, 0, context_die);
18978 add_pure_or_virtual_attribute (subr_die, decl);
18979 if (DECL_ARTIFICIAL (decl))
18980 add_AT_flag (subr_die, DW_AT_artificial, 1);
18982 add_accessibility_attribute (subr_die, decl);
18987 if (!old_die || !get_AT (old_die, DW_AT_inline))
18989 add_AT_flag (subr_die, DW_AT_declaration, 1);
18991 /* If this is an explicit function declaration then generate
18992 a DW_AT_explicit attribute. */
18993 if (lang_hooks.decls.function_decl_explicit_p (decl)
18994 && (dwarf_version >= 3 || !dwarf_strict))
18995 add_AT_flag (subr_die, DW_AT_explicit, 1);
18997 /* The first time we see a member function, it is in the context of
18998 the class to which it belongs. We make sure of this by emitting
18999 the class first. The next time is the definition, which is
19000 handled above. The two may come from the same source text.
19002 Note that force_decl_die() forces function declaration die. It is
19003 later reused to represent definition. */
19004 equate_decl_number_to_die (decl, subr_die);
19007 else if (DECL_ABSTRACT (decl))
19009 if (DECL_DECLARED_INLINE_P (decl))
19011 if (cgraph_function_possibly_inlined_p (decl))
19012 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19014 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19018 if (cgraph_function_possibly_inlined_p (decl))
19019 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19021 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19024 if (DECL_DECLARED_INLINE_P (decl)
19025 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19026 add_AT_flag (subr_die, DW_AT_artificial, 1);
19028 equate_decl_number_to_die (decl, subr_die);
19030 else if (!DECL_EXTERNAL (decl))
19032 HOST_WIDE_INT cfa_fb_offset;
19034 if (!old_die || !get_AT (old_die, DW_AT_inline))
19035 equate_decl_number_to_die (decl, subr_die);
19037 if (!flag_reorder_blocks_and_partition)
19039 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19040 current_function_funcdef_no);
19041 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19042 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19043 current_function_funcdef_no);
19044 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19046 #if VMS_DEBUGGING_INFO
19047 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19048 Section 2.3 Prologue and Epilogue Attributes:
19049 When a breakpoint is set on entry to a function, it is generally
19050 desirable for execution to be suspended, not on the very first
19051 instruction of the function, but rather at a point after the
19052 function's frame has been set up, after any language defined local
19053 declaration processing has been completed, and before execution of
19054 the first statement of the function begins. Debuggers generally
19055 cannot properly determine where this point is. Similarly for a
19056 breakpoint set on exit from a function. The prologue and epilogue
19057 attributes allow a compiler to communicate the location(s) to use. */
19060 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19062 if (fde->dw_fde_vms_end_prologue)
19063 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19064 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19066 if (fde->dw_fde_vms_begin_epilogue)
19067 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19068 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19072 add_pubname (decl, subr_die);
19073 add_arange (decl, subr_die);
19076 { /* Do nothing for now; maybe need to duplicate die, one for
19077 hot section and one for cold section, then use the hot/cold
19078 section begin/end labels to generate the aranges... */
19080 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
19081 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
19082 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
19083 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
19085 add_pubname (decl, subr_die);
19086 add_arange (decl, subr_die);
19087 add_arange (decl, subr_die);
19091 #ifdef MIPS_DEBUGGING_INFO
19092 /* Add a reference to the FDE for this routine. */
19093 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19096 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19098 /* We define the "frame base" as the function's CFA. This is more
19099 convenient for several reasons: (1) It's stable across the prologue
19100 and epilogue, which makes it better than just a frame pointer,
19101 (2) With dwarf3, there exists a one-byte encoding that allows us
19102 to reference the .debug_frame data by proxy, but failing that,
19103 (3) We can at least reuse the code inspection and interpretation
19104 code that determines the CFA position at various points in the
19106 if (dwarf_version >= 3)
19108 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19109 add_AT_loc (subr_die, DW_AT_frame_base, op);
19113 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19114 if (list->dw_loc_next)
19115 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19117 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19120 /* Compute a displacement from the "steady-state frame pointer" to
19121 the CFA. The former is what all stack slots and argument slots
19122 will reference in the rtl; the later is what we've told the
19123 debugger about. We'll need to adjust all frame_base references
19124 by this displacement. */
19125 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19127 if (cfun->static_chain_decl)
19128 add_AT_location_description (subr_die, DW_AT_static_link,
19129 loc_list_from_tree (cfun->static_chain_decl, 2));
19132 /* Generate child dies for template paramaters. */
19133 if (debug_info_level > DINFO_LEVEL_TERSE)
19134 gen_generic_params_dies (decl);
19136 /* Now output descriptions of the arguments for this function. This gets
19137 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19138 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19139 `...' at the end of the formal parameter list. In order to find out if
19140 there was a trailing ellipsis or not, we must instead look at the type
19141 associated with the FUNCTION_DECL. This will be a node of type
19142 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19143 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19144 an ellipsis at the end. */
19146 /* In the case where we are describing a mere function declaration, all we
19147 need to do here (and all we *can* do here) is to describe the *types* of
19148 its formal parameters. */
19149 if (debug_info_level <= DINFO_LEVEL_TERSE)
19151 else if (declaration)
19152 gen_formal_types_die (decl, subr_die);
19155 /* Generate DIEs to represent all known formal parameters. */
19156 tree parm = DECL_ARGUMENTS (decl);
19157 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19158 tree generic_decl_parm = generic_decl
19159 ? DECL_ARGUMENTS (generic_decl)
19162 /* Now we want to walk the list of parameters of the function and
19163 emit their relevant DIEs.
19165 We consider the case of DECL being an instance of a generic function
19166 as well as it being a normal function.
19168 If DECL is an instance of a generic function we walk the
19169 parameters of the generic function declaration _and_ the parameters of
19170 DECL itself. This is useful because we want to emit specific DIEs for
19171 function parameter packs and those are declared as part of the
19172 generic function declaration. In that particular case,
19173 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19174 That DIE has children DIEs representing the set of arguments
19175 of the pack. Note that the set of pack arguments can be empty.
19176 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19179 Otherwise, we just consider the parameters of DECL. */
19180 while (generic_decl_parm || parm)
19182 if (generic_decl_parm
19183 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19184 gen_formal_parameter_pack_die (generic_decl_parm,
19189 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19191 if (parm == DECL_ARGUMENTS (decl)
19192 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19194 && (dwarf_version >= 3 || !dwarf_strict))
19195 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19197 parm = DECL_CHAIN (parm);
19200 if (generic_decl_parm)
19201 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19204 /* Decide whether we need an unspecified_parameters DIE at the end.
19205 There are 2 more cases to do this for: 1) the ansi ... declaration -
19206 this is detectable when the end of the arg list is not a
19207 void_type_node 2) an unprototyped function declaration (not a
19208 definition). This just means that we have no info about the
19209 parameters at all. */
19210 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
19211 if (fn_arg_types != NULL)
19213 /* This is the prototyped case, check for.... */
19214 if (stdarg_p (TREE_TYPE (decl)))
19215 gen_unspecified_parameters_die (decl, subr_die);
19217 else if (DECL_INITIAL (decl) == NULL_TREE)
19218 gen_unspecified_parameters_die (decl, subr_die);
19221 /* Output Dwarf info for all of the stuff within the body of the function
19222 (if it has one - it may be just a declaration). */
19223 outer_scope = DECL_INITIAL (decl);
19225 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19226 a function. This BLOCK actually represents the outermost binding contour
19227 for the function, i.e. the contour in which the function's formal
19228 parameters and labels get declared. Curiously, it appears that the front
19229 end doesn't actually put the PARM_DECL nodes for the current function onto
19230 the BLOCK_VARS list for this outer scope, but are strung off of the
19231 DECL_ARGUMENTS list for the function instead.
19233 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19234 the LABEL_DECL nodes for the function however, and we output DWARF info
19235 for those in decls_for_scope. Just within the `outer_scope' there will be
19236 a BLOCK node representing the function's outermost pair of curly braces,
19237 and any blocks used for the base and member initializers of a C++
19238 constructor function. */
19239 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19241 /* Emit a DW_TAG_variable DIE for a named return value. */
19242 if (DECL_NAME (DECL_RESULT (decl)))
19243 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19245 current_function_has_inlines = 0;
19246 decls_for_scope (outer_scope, subr_die, 0);
19248 /* Add the calling convention attribute if requested. */
19249 add_calling_convention_attribute (subr_die, decl);
19253 /* Returns a hash value for X (which really is a die_struct). */
19256 common_block_die_table_hash (const void *x)
19258 const_dw_die_ref d = (const_dw_die_ref) x;
19259 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19262 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19263 as decl_id and die_parent of die_struct Y. */
19266 common_block_die_table_eq (const void *x, const void *y)
19268 const_dw_die_ref d = (const_dw_die_ref) x;
19269 const_dw_die_ref e = (const_dw_die_ref) y;
19270 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19273 /* Generate a DIE to represent a declared data object.
19274 Either DECL or ORIGIN must be non-null. */
19277 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19281 tree decl_or_origin = decl ? decl : origin;
19282 tree ultimate_origin;
19283 dw_die_ref var_die;
19284 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19285 dw_die_ref origin_die;
19286 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19287 || class_or_namespace_scope_p (context_die));
19288 bool specialization_p = false;
19290 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19291 if (decl || ultimate_origin)
19292 origin = ultimate_origin;
19293 com_decl = fortran_common (decl_or_origin, &off);
19295 /* Symbol in common gets emitted as a child of the common block, in the form
19296 of a data member. */
19299 dw_die_ref com_die;
19300 dw_loc_list_ref loc;
19301 die_node com_die_arg;
19303 var_die = lookup_decl_die (decl_or_origin);
19306 if (get_AT (var_die, DW_AT_location) == NULL)
19308 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19313 /* Optimize the common case. */
19314 if (single_element_loc_list_p (loc)
19315 && loc->expr->dw_loc_opc == DW_OP_addr
19316 && loc->expr->dw_loc_next == NULL
19317 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19319 loc->expr->dw_loc_oprnd1.v.val_addr
19320 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19322 loc_list_plus_const (loc, off);
19324 add_AT_location_description (var_die, DW_AT_location, loc);
19325 remove_AT (var_die, DW_AT_declaration);
19331 if (common_block_die_table == NULL)
19332 common_block_die_table
19333 = htab_create_ggc (10, common_block_die_table_hash,
19334 common_block_die_table_eq, NULL);
19336 com_die_arg.decl_id = DECL_UID (com_decl);
19337 com_die_arg.die_parent = context_die;
19338 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19339 loc = loc_list_from_tree (com_decl, 2);
19340 if (com_die == NULL)
19343 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19346 com_die = new_die (DW_TAG_common_block, context_die, decl);
19347 add_name_and_src_coords_attributes (com_die, com_decl);
19350 add_AT_location_description (com_die, DW_AT_location, loc);
19351 /* Avoid sharing the same loc descriptor between
19352 DW_TAG_common_block and DW_TAG_variable. */
19353 loc = loc_list_from_tree (com_decl, 2);
19355 else if (DECL_EXTERNAL (decl))
19356 add_AT_flag (com_die, DW_AT_declaration, 1);
19357 add_pubname_string (cnam, com_die); /* ??? needed? */
19358 com_die->decl_id = DECL_UID (com_decl);
19359 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19360 *slot = (void *) com_die;
19362 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19364 add_AT_location_description (com_die, DW_AT_location, loc);
19365 loc = loc_list_from_tree (com_decl, 2);
19366 remove_AT (com_die, DW_AT_declaration);
19368 var_die = new_die (DW_TAG_variable, com_die, decl);
19369 add_name_and_src_coords_attributes (var_die, decl);
19370 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19371 TREE_THIS_VOLATILE (decl), context_die);
19372 add_AT_flag (var_die, DW_AT_external, 1);
19377 /* Optimize the common case. */
19378 if (single_element_loc_list_p (loc)
19379 && loc->expr->dw_loc_opc == DW_OP_addr
19380 && loc->expr->dw_loc_next == NULL
19381 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19382 loc->expr->dw_loc_oprnd1.v.val_addr
19383 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19385 loc_list_plus_const (loc, off);
19387 add_AT_location_description (var_die, DW_AT_location, loc);
19389 else if (DECL_EXTERNAL (decl))
19390 add_AT_flag (var_die, DW_AT_declaration, 1);
19391 equate_decl_number_to_die (decl, var_die);
19395 /* If the compiler emitted a definition for the DECL declaration
19396 and if we already emitted a DIE for it, don't emit a second
19397 DIE for it again. Allow re-declarations of DECLs that are
19398 inside functions, though. */
19399 if (old_die && declaration && !local_scope_p (context_die))
19402 /* For static data members, the declaration in the class is supposed
19403 to have DW_TAG_member tag; the specification should still be
19404 DW_TAG_variable referencing the DW_TAG_member DIE. */
19405 if (declaration && class_scope_p (context_die))
19406 var_die = new_die (DW_TAG_member, context_die, decl);
19408 var_die = new_die (DW_TAG_variable, context_die, decl);
19411 if (origin != NULL)
19412 origin_die = add_abstract_origin_attribute (var_die, origin);
19414 /* Loop unrolling can create multiple blocks that refer to the same
19415 static variable, so we must test for the DW_AT_declaration flag.
19417 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19418 copy decls and set the DECL_ABSTRACT flag on them instead of
19421 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19423 ??? The declare_in_namespace support causes us to get two DIEs for one
19424 variable, both of which are declarations. We want to avoid considering
19425 one to be a specification, so we must test that this DIE is not a
19427 else if (old_die && TREE_STATIC (decl) && ! declaration
19428 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19430 /* This is a definition of a C++ class level static. */
19431 add_AT_specification (var_die, old_die);
19432 specialization_p = true;
19433 if (DECL_NAME (decl))
19435 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19436 struct dwarf_file_data * file_index = lookup_filename (s.file);
19438 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19439 add_AT_file (var_die, DW_AT_decl_file, file_index);
19441 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19442 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19444 if (old_die->die_tag == DW_TAG_member)
19445 add_linkage_name (var_die, decl);
19449 add_name_and_src_coords_attributes (var_die, decl);
19451 if ((origin == NULL && !specialization_p)
19453 && !DECL_ABSTRACT (decl_or_origin)
19454 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19455 decl_function_context
19456 (decl_or_origin))))
19458 tree type = TREE_TYPE (decl_or_origin);
19460 if (decl_by_reference_p (decl_or_origin))
19461 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19463 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19464 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19467 if (origin == NULL && !specialization_p)
19469 if (TREE_PUBLIC (decl))
19470 add_AT_flag (var_die, DW_AT_external, 1);
19472 if (DECL_ARTIFICIAL (decl))
19473 add_AT_flag (var_die, DW_AT_artificial, 1);
19475 add_accessibility_attribute (var_die, decl);
19479 add_AT_flag (var_die, DW_AT_declaration, 1);
19481 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19482 equate_decl_number_to_die (decl, var_die);
19485 && (! DECL_ABSTRACT (decl_or_origin)
19486 /* Local static vars are shared between all clones/inlines,
19487 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19489 || (TREE_CODE (decl_or_origin) == VAR_DECL
19490 && TREE_STATIC (decl_or_origin)
19491 && DECL_RTL_SET_P (decl_or_origin)))
19492 /* When abstract origin already has DW_AT_location attribute, no need
19493 to add it again. */
19494 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19496 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19497 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19498 defer_location (decl_or_origin, var_die);
19500 add_location_or_const_value_attribute (var_die,
19503 add_pubname (decl_or_origin, var_die);
19506 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19509 /* Generate a DIE to represent a named constant. */
19512 gen_const_die (tree decl, dw_die_ref context_die)
19514 dw_die_ref const_die;
19515 tree type = TREE_TYPE (decl);
19517 const_die = new_die (DW_TAG_constant, context_die, decl);
19518 add_name_and_src_coords_attributes (const_die, decl);
19519 add_type_attribute (const_die, type, 1, 0, context_die);
19520 if (TREE_PUBLIC (decl))
19521 add_AT_flag (const_die, DW_AT_external, 1);
19522 if (DECL_ARTIFICIAL (decl))
19523 add_AT_flag (const_die, DW_AT_artificial, 1);
19524 tree_add_const_value_attribute_for_decl (const_die, decl);
19527 /* Generate a DIE to represent a label identifier. */
19530 gen_label_die (tree decl, dw_die_ref context_die)
19532 tree origin = decl_ultimate_origin (decl);
19533 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19535 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19537 if (origin != NULL)
19538 add_abstract_origin_attribute (lbl_die, origin);
19540 add_name_and_src_coords_attributes (lbl_die, decl);
19542 if (DECL_ABSTRACT (decl))
19543 equate_decl_number_to_die (decl, lbl_die);
19546 insn = DECL_RTL_IF_SET (decl);
19548 /* Deleted labels are programmer specified labels which have been
19549 eliminated because of various optimizations. We still emit them
19550 here so that it is possible to put breakpoints on them. */
19554 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19556 /* When optimization is enabled (via -O) some parts of the compiler
19557 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19558 represent source-level labels which were explicitly declared by
19559 the user. This really shouldn't be happening though, so catch
19560 it if it ever does happen. */
19561 gcc_assert (!INSN_DELETED_P (insn));
19563 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19564 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19569 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19570 attributes to the DIE for a block STMT, to describe where the inlined
19571 function was called from. This is similar to add_src_coords_attributes. */
19574 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19576 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19578 if (dwarf_version >= 3 || !dwarf_strict)
19580 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19581 add_AT_unsigned (die, DW_AT_call_line, s.line);
19586 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19587 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19590 add_high_low_attributes (tree stmt, dw_die_ref die)
19592 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19594 if (BLOCK_FRAGMENT_CHAIN (stmt)
19595 && (dwarf_version >= 3 || !dwarf_strict))
19599 if (inlined_function_outer_scope_p (stmt))
19601 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19602 BLOCK_NUMBER (stmt));
19603 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19606 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19608 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19611 add_ranges (chain);
19612 chain = BLOCK_FRAGMENT_CHAIN (chain);
19619 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19620 BLOCK_NUMBER (stmt));
19621 add_AT_lbl_id (die, DW_AT_low_pc, label);
19622 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19623 BLOCK_NUMBER (stmt));
19624 add_AT_lbl_id (die, DW_AT_high_pc, label);
19628 /* Generate a DIE for a lexical block. */
19631 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19633 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19635 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19636 add_high_low_attributes (stmt, stmt_die);
19638 decls_for_scope (stmt, stmt_die, depth);
19641 /* Generate a DIE for an inlined subprogram. */
19644 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19648 /* The instance of function that is effectively being inlined shall not
19650 gcc_assert (! BLOCK_ABSTRACT (stmt));
19652 decl = block_ultimate_origin (stmt);
19654 /* Emit info for the abstract instance first, if we haven't yet. We
19655 must emit this even if the block is abstract, otherwise when we
19656 emit the block below (or elsewhere), we may end up trying to emit
19657 a die whose origin die hasn't been emitted, and crashing. */
19658 dwarf2out_abstract_function (decl);
19660 if (! BLOCK_ABSTRACT (stmt))
19662 dw_die_ref subr_die
19663 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19665 add_abstract_origin_attribute (subr_die, decl);
19666 if (TREE_ASM_WRITTEN (stmt))
19667 add_high_low_attributes (stmt, subr_die);
19668 add_call_src_coords_attributes (stmt, subr_die);
19670 decls_for_scope (stmt, subr_die, depth);
19671 current_function_has_inlines = 1;
19675 /* Generate a DIE for a field in a record, or structure. */
19678 gen_field_die (tree decl, dw_die_ref context_die)
19680 dw_die_ref decl_die;
19682 if (TREE_TYPE (decl) == error_mark_node)
19685 decl_die = new_die (DW_TAG_member, context_die, decl);
19686 add_name_and_src_coords_attributes (decl_die, decl);
19687 add_type_attribute (decl_die, member_declared_type (decl),
19688 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
19691 if (DECL_BIT_FIELD_TYPE (decl))
19693 add_byte_size_attribute (decl_die, decl);
19694 add_bit_size_attribute (decl_die, decl);
19695 add_bit_offset_attribute (decl_die, decl);
19698 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
19699 add_data_member_location_attribute (decl_die, decl);
19701 if (DECL_ARTIFICIAL (decl))
19702 add_AT_flag (decl_die, DW_AT_artificial, 1);
19704 add_accessibility_attribute (decl_die, decl);
19706 /* Equate decl number to die, so that we can look up this decl later on. */
19707 equate_decl_number_to_die (decl, decl_die);
19711 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19712 Use modified_type_die instead.
19713 We keep this code here just in case these types of DIEs may be needed to
19714 represent certain things in other languages (e.g. Pascal) someday. */
19717 gen_pointer_type_die (tree type, dw_die_ref context_die)
19720 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
19722 equate_type_number_to_die (type, ptr_die);
19723 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19724 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19727 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19728 Use modified_type_die instead.
19729 We keep this code here just in case these types of DIEs may be needed to
19730 represent certain things in other languages (e.g. Pascal) someday. */
19733 gen_reference_type_die (tree type, dw_die_ref context_die)
19735 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
19737 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
19738 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
19740 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
19742 equate_type_number_to_die (type, ref_die);
19743 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
19744 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19748 /* Generate a DIE for a pointer to a member type. */
19751 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
19754 = new_die (DW_TAG_ptr_to_member_type,
19755 scope_die_for (type, context_die), type);
19757 equate_type_number_to_die (type, ptr_die);
19758 add_AT_die_ref (ptr_die, DW_AT_containing_type,
19759 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
19760 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19763 /* Generate the DIE for the compilation unit. */
19766 gen_compile_unit_die (const char *filename)
19769 char producer[250];
19770 const char *language_string = lang_hooks.name;
19773 die = new_die (DW_TAG_compile_unit, NULL, NULL);
19777 add_name_attribute (die, filename);
19778 /* Don't add cwd for <built-in>. */
19779 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
19780 add_comp_dir_attribute (die);
19783 sprintf (producer, "%s %s", language_string, version_string);
19785 #ifdef MIPS_DEBUGGING_INFO
19786 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
19787 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
19788 not appear in the producer string, the debugger reaches the conclusion
19789 that the object file is stripped and has no debugging information.
19790 To get the MIPS/SGI debugger to believe that there is debugging
19791 information in the object file, we add a -g to the producer string. */
19792 if (debug_info_level > DINFO_LEVEL_TERSE)
19793 strcat (producer, " -g");
19796 add_AT_string (die, DW_AT_producer, producer);
19798 /* If our producer is LTO try to figure out a common language to use
19799 from the global list of translation units. */
19800 if (strcmp (language_string, "GNU GIMPLE") == 0)
19804 const char *common_lang = NULL;
19806 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
19808 if (!TRANSLATION_UNIT_LANGUAGE (t))
19811 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
19812 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
19814 else if (strncmp (common_lang, "GNU C", 5) == 0
19815 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
19816 /* Mixing C and C++ is ok, use C++ in that case. */
19817 common_lang = "GNU C++";
19820 /* Fall back to C. */
19821 common_lang = NULL;
19827 language_string = common_lang;
19830 language = DW_LANG_C89;
19831 if (strcmp (language_string, "GNU C++") == 0)
19832 language = DW_LANG_C_plus_plus;
19833 else if (strcmp (language_string, "GNU F77") == 0)
19834 language = DW_LANG_Fortran77;
19835 else if (strcmp (language_string, "GNU Pascal") == 0)
19836 language = DW_LANG_Pascal83;
19837 else if (dwarf_version >= 3 || !dwarf_strict)
19839 if (strcmp (language_string, "GNU Ada") == 0)
19840 language = DW_LANG_Ada95;
19841 else if (strcmp (language_string, "GNU Fortran") == 0)
19842 language = DW_LANG_Fortran95;
19843 else if (strcmp (language_string, "GNU Java") == 0)
19844 language = DW_LANG_Java;
19845 else if (strcmp (language_string, "GNU Objective-C") == 0)
19846 language = DW_LANG_ObjC;
19847 else if (strcmp (language_string, "GNU Objective-C++") == 0)
19848 language = DW_LANG_ObjC_plus_plus;
19851 add_AT_unsigned (die, DW_AT_language, language);
19855 case DW_LANG_Fortran77:
19856 case DW_LANG_Fortran90:
19857 case DW_LANG_Fortran95:
19858 /* Fortran has case insensitive identifiers and the front-end
19859 lowercases everything. */
19860 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
19863 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19869 /* Generate the DIE for a base class. */
19872 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
19874 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
19876 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
19877 add_data_member_location_attribute (die, binfo);
19879 if (BINFO_VIRTUAL_P (binfo))
19880 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
19882 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19883 children, otherwise the default is DW_ACCESS_public. In DWARF2
19884 the default has always been DW_ACCESS_private. */
19885 if (access == access_public_node)
19887 if (dwarf_version == 2
19888 || context_die->die_tag == DW_TAG_class_type)
19889 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
19891 else if (access == access_protected_node)
19892 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
19893 else if (dwarf_version > 2
19894 && context_die->die_tag != DW_TAG_class_type)
19895 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
19898 /* Generate a DIE for a class member. */
19901 gen_member_die (tree type, dw_die_ref context_die)
19904 tree binfo = TYPE_BINFO (type);
19907 /* If this is not an incomplete type, output descriptions of each of its
19908 members. Note that as we output the DIEs necessary to represent the
19909 members of this record or union type, we will also be trying to output
19910 DIEs to represent the *types* of those members. However the `type'
19911 function (above) will specifically avoid generating type DIEs for member
19912 types *within* the list of member DIEs for this (containing) type except
19913 for those types (of members) which are explicitly marked as also being
19914 members of this (containing) type themselves. The g++ front- end can
19915 force any given type to be treated as a member of some other (containing)
19916 type by setting the TYPE_CONTEXT of the given (member) type to point to
19917 the TREE node representing the appropriate (containing) type. */
19919 /* First output info about the base classes. */
19922 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
19926 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
19927 gen_inheritance_die (base,
19928 (accesses ? VEC_index (tree, accesses, i)
19929 : access_public_node), context_die);
19932 /* Now output info about the data members and type members. */
19933 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
19935 /* If we thought we were generating minimal debug info for TYPE
19936 and then changed our minds, some of the member declarations
19937 may have already been defined. Don't define them again, but
19938 do put them in the right order. */
19940 child = lookup_decl_die (member);
19942 splice_child_die (context_die, child);
19944 gen_decl_die (member, NULL, context_die);
19947 /* Now output info about the function members (if any). */
19948 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
19950 /* Don't include clones in the member list. */
19951 if (DECL_ABSTRACT_ORIGIN (member))
19954 child = lookup_decl_die (member);
19956 splice_child_die (context_die, child);
19958 gen_decl_die (member, NULL, context_die);
19962 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19963 is set, we pretend that the type was never defined, so we only get the
19964 member DIEs needed by later specification DIEs. */
19967 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
19968 enum debug_info_usage usage)
19970 dw_die_ref type_die = lookup_type_die (type);
19971 dw_die_ref scope_die = 0;
19973 int complete = (TYPE_SIZE (type)
19974 && (! TYPE_STUB_DECL (type)
19975 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
19976 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
19977 complete = complete && should_emit_struct_debug (type, usage);
19979 if (type_die && ! complete)
19982 if (TYPE_CONTEXT (type) != NULL_TREE
19983 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
19984 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
19987 scope_die = scope_die_for (type, context_die);
19989 if (! type_die || (nested && is_cu_die (scope_die)))
19990 /* First occurrence of type or toplevel definition of nested class. */
19992 dw_die_ref old_die = type_die;
19994 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
19995 ? record_type_tag (type) : DW_TAG_union_type,
19997 equate_type_number_to_die (type, type_die);
19999 add_AT_specification (type_die, old_die);
20001 add_name_attribute (type_die, type_tag (type));
20004 remove_AT (type_die, DW_AT_declaration);
20006 /* Generate child dies for template paramaters. */
20007 if (debug_info_level > DINFO_LEVEL_TERSE
20008 && COMPLETE_TYPE_P (type))
20009 gen_generic_params_dies (type);
20011 /* If this type has been completed, then give it a byte_size attribute and
20012 then give a list of members. */
20013 if (complete && !ns_decl)
20015 /* Prevent infinite recursion in cases where the type of some member of
20016 this type is expressed in terms of this type itself. */
20017 TREE_ASM_WRITTEN (type) = 1;
20018 add_byte_size_attribute (type_die, type);
20019 if (TYPE_STUB_DECL (type) != NULL_TREE)
20021 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20022 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20025 /* If the first reference to this type was as the return type of an
20026 inline function, then it may not have a parent. Fix this now. */
20027 if (type_die->die_parent == NULL)
20028 add_child_die (scope_die, type_die);
20030 push_decl_scope (type);
20031 gen_member_die (type, type_die);
20034 /* GNU extension: Record what type our vtable lives in. */
20035 if (TYPE_VFIELD (type))
20037 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20039 gen_type_die (vtype, context_die);
20040 add_AT_die_ref (type_die, DW_AT_containing_type,
20041 lookup_type_die (vtype));
20046 add_AT_flag (type_die, DW_AT_declaration, 1);
20048 /* We don't need to do this for function-local types. */
20049 if (TYPE_STUB_DECL (type)
20050 && ! decl_function_context (TYPE_STUB_DECL (type)))
20051 VEC_safe_push (tree, gc, incomplete_types, type);
20054 if (get_AT (type_die, DW_AT_name))
20055 add_pubtype (type, type_die);
20058 /* Generate a DIE for a subroutine _type_. */
20061 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20063 tree return_type = TREE_TYPE (type);
20064 dw_die_ref subr_die
20065 = new_die (DW_TAG_subroutine_type,
20066 scope_die_for (type, context_die), type);
20068 equate_type_number_to_die (type, subr_die);
20069 add_prototyped_attribute (subr_die, type);
20070 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20071 gen_formal_types_die (type, subr_die);
20073 if (get_AT (subr_die, DW_AT_name))
20074 add_pubtype (type, subr_die);
20077 /* Generate a DIE for a type definition. */
20080 gen_typedef_die (tree decl, dw_die_ref context_die)
20082 dw_die_ref type_die;
20085 if (TREE_ASM_WRITTEN (decl))
20088 TREE_ASM_WRITTEN (decl) = 1;
20089 type_die = new_die (DW_TAG_typedef, context_die, decl);
20090 origin = decl_ultimate_origin (decl);
20091 if (origin != NULL)
20092 add_abstract_origin_attribute (type_die, origin);
20097 add_name_and_src_coords_attributes (type_die, decl);
20098 if (DECL_ORIGINAL_TYPE (decl))
20100 type = DECL_ORIGINAL_TYPE (decl);
20102 gcc_assert (type != TREE_TYPE (decl));
20103 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20107 type = TREE_TYPE (decl);
20109 if (is_naming_typedef_decl (TYPE_NAME (type)))
20111 /* Here, we are in the case of decl being a typedef naming
20112 an anonymous type, e.g:
20113 typedef struct {...} foo;
20114 In that case TREE_TYPE (decl) is not a typedef variant
20115 type and TYPE_NAME of the anonymous type is set to the
20116 TYPE_DECL of the typedef. This construct is emitted by
20119 TYPE is the anonymous struct named by the typedef
20120 DECL. As we need the DW_AT_type attribute of the
20121 DW_TAG_typedef to point to the DIE of TYPE, let's
20122 generate that DIE right away. add_type_attribute
20123 called below will then pick (via lookup_type_die) that
20124 anonymous struct DIE. */
20125 if (!TREE_ASM_WRITTEN (type))
20126 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20130 add_type_attribute (type_die, type, TREE_READONLY (decl),
20131 TREE_THIS_VOLATILE (decl), context_die);
20133 if (is_naming_typedef_decl (decl))
20134 /* We want that all subsequent calls to lookup_type_die with
20135 TYPE in argument yield the DW_TAG_typedef we have just
20137 equate_type_number_to_die (type, type_die);
20139 add_accessibility_attribute (type_die, decl);
20142 if (DECL_ABSTRACT (decl))
20143 equate_decl_number_to_die (decl, type_die);
20145 if (get_AT (type_die, DW_AT_name))
20146 add_pubtype (decl, type_die);
20149 /* Generate a DIE for a struct, class, enum or union type. */
20152 gen_tagged_type_die (tree type,
20153 dw_die_ref context_die,
20154 enum debug_info_usage usage)
20158 if (type == NULL_TREE
20159 || !is_tagged_type (type))
20162 /* If this is a nested type whose containing class hasn't been written
20163 out yet, writing it out will cover this one, too. This does not apply
20164 to instantiations of member class templates; they need to be added to
20165 the containing class as they are generated. FIXME: This hurts the
20166 idea of combining type decls from multiple TUs, since we can't predict
20167 what set of template instantiations we'll get. */
20168 if (TYPE_CONTEXT (type)
20169 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20170 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20172 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20174 if (TREE_ASM_WRITTEN (type))
20177 /* If that failed, attach ourselves to the stub. */
20178 push_decl_scope (TYPE_CONTEXT (type));
20179 context_die = lookup_type_die (TYPE_CONTEXT (type));
20182 else if (TYPE_CONTEXT (type) != NULL_TREE
20183 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20185 /* If this type is local to a function that hasn't been written
20186 out yet, use a NULL context for now; it will be fixed up in
20187 decls_for_scope. */
20188 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20193 context_die = declare_in_namespace (type, context_die);
20197 if (TREE_CODE (type) == ENUMERAL_TYPE)
20199 /* This might have been written out by the call to
20200 declare_in_namespace. */
20201 if (!TREE_ASM_WRITTEN (type))
20202 gen_enumeration_type_die (type, context_die);
20205 gen_struct_or_union_type_die (type, context_die, usage);
20210 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20211 it up if it is ever completed. gen_*_type_die will set it for us
20212 when appropriate. */
20215 /* Generate a type description DIE. */
20218 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20219 enum debug_info_usage usage)
20221 struct array_descr_info info;
20223 if (type == NULL_TREE || type == error_mark_node)
20226 /* If TYPE is a typedef type variant, let's generate debug info
20227 for the parent typedef which TYPE is a type of. */
20228 if (typedef_variant_p (type))
20230 if (TREE_ASM_WRITTEN (type))
20233 /* Prevent broken recursion; we can't hand off to the same type. */
20234 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20236 /* Use the DIE of the containing namespace as the parent DIE of
20237 the type description DIE we want to generate. */
20238 if (DECL_CONTEXT (TYPE_NAME (type))
20239 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20240 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20242 TREE_ASM_WRITTEN (type) = 1;
20244 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20248 /* If type is an anonymous tagged type named by a typedef, let's
20249 generate debug info for the typedef. */
20250 if (is_naming_typedef_decl (TYPE_NAME (type)))
20252 /* Use the DIE of the containing namespace as the parent DIE of
20253 the type description DIE we want to generate. */
20254 if (DECL_CONTEXT (TYPE_NAME (type))
20255 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20256 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20258 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20262 /* If this is an array type with hidden descriptor, handle it first. */
20263 if (!TREE_ASM_WRITTEN (type)
20264 && lang_hooks.types.get_array_descr_info
20265 && lang_hooks.types.get_array_descr_info (type, &info)
20266 && (dwarf_version >= 3 || !dwarf_strict))
20268 gen_descr_array_type_die (type, &info, context_die);
20269 TREE_ASM_WRITTEN (type) = 1;
20273 /* We are going to output a DIE to represent the unqualified version
20274 of this type (i.e. without any const or volatile qualifiers) so
20275 get the main variant (i.e. the unqualified version) of this type
20276 now. (Vectors are special because the debugging info is in the
20277 cloned type itself). */
20278 if (TREE_CODE (type) != VECTOR_TYPE)
20279 type = type_main_variant (type);
20281 if (TREE_ASM_WRITTEN (type))
20284 switch (TREE_CODE (type))
20290 case REFERENCE_TYPE:
20291 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20292 ensures that the gen_type_die recursion will terminate even if the
20293 type is recursive. Recursive types are possible in Ada. */
20294 /* ??? We could perhaps do this for all types before the switch
20296 TREE_ASM_WRITTEN (type) = 1;
20298 /* For these types, all that is required is that we output a DIE (or a
20299 set of DIEs) to represent the "basis" type. */
20300 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20301 DINFO_USAGE_IND_USE);
20305 /* This code is used for C++ pointer-to-data-member types.
20306 Output a description of the relevant class type. */
20307 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20308 DINFO_USAGE_IND_USE);
20310 /* Output a description of the type of the object pointed to. */
20311 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20312 DINFO_USAGE_IND_USE);
20314 /* Now output a DIE to represent this pointer-to-data-member type
20316 gen_ptr_to_mbr_type_die (type, context_die);
20319 case FUNCTION_TYPE:
20320 /* Force out return type (in case it wasn't forced out already). */
20321 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20322 DINFO_USAGE_DIR_USE);
20323 gen_subroutine_type_die (type, context_die);
20327 /* Force out return type (in case it wasn't forced out already). */
20328 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20329 DINFO_USAGE_DIR_USE);
20330 gen_subroutine_type_die (type, context_die);
20334 gen_array_type_die (type, context_die);
20338 gen_array_type_die (type, context_die);
20341 case ENUMERAL_TYPE:
20344 case QUAL_UNION_TYPE:
20345 gen_tagged_type_die (type, context_die, usage);
20351 case FIXED_POINT_TYPE:
20354 /* No DIEs needed for fundamental types. */
20359 /* Just use DW_TAG_unspecified_type. */
20361 dw_die_ref type_die = lookup_type_die (type);
20362 if (type_die == NULL)
20364 tree name = TYPE_NAME (type);
20365 if (TREE_CODE (name) == TYPE_DECL)
20366 name = DECL_NAME (name);
20367 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20368 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20369 equate_type_number_to_die (type, type_die);
20375 gcc_unreachable ();
20378 TREE_ASM_WRITTEN (type) = 1;
20382 gen_type_die (tree type, dw_die_ref context_die)
20384 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20387 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20388 things which are local to the given block. */
20391 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20393 int must_output_die = 0;
20396 /* Ignore blocks that are NULL. */
20397 if (stmt == NULL_TREE)
20400 inlined_func = inlined_function_outer_scope_p (stmt);
20402 /* If the block is one fragment of a non-contiguous block, do not
20403 process the variables, since they will have been done by the
20404 origin block. Do process subblocks. */
20405 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20409 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20410 gen_block_die (sub, context_die, depth + 1);
20415 /* Determine if we need to output any Dwarf DIEs at all to represent this
20418 /* The outer scopes for inlinings *must* always be represented. We
20419 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20420 must_output_die = 1;
20423 /* Determine if this block directly contains any "significant"
20424 local declarations which we will need to output DIEs for. */
20425 if (debug_info_level > DINFO_LEVEL_TERSE)
20426 /* We are not in terse mode so *any* local declaration counts
20427 as being a "significant" one. */
20428 must_output_die = ((BLOCK_VARS (stmt) != NULL
20429 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20430 && (TREE_USED (stmt)
20431 || TREE_ASM_WRITTEN (stmt)
20432 || BLOCK_ABSTRACT (stmt)));
20433 else if ((TREE_USED (stmt)
20434 || TREE_ASM_WRITTEN (stmt)
20435 || BLOCK_ABSTRACT (stmt))
20436 && !dwarf2out_ignore_block (stmt))
20437 must_output_die = 1;
20440 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20441 DIE for any block which contains no significant local declarations at
20442 all. Rather, in such cases we just call `decls_for_scope' so that any
20443 needed Dwarf info for any sub-blocks will get properly generated. Note
20444 that in terse mode, our definition of what constitutes a "significant"
20445 local declaration gets restricted to include only inlined function
20446 instances and local (nested) function definitions. */
20447 if (must_output_die)
20451 /* If STMT block is abstract, that means we have been called
20452 indirectly from dwarf2out_abstract_function.
20453 That function rightfully marks the descendent blocks (of
20454 the abstract function it is dealing with) as being abstract,
20455 precisely to prevent us from emitting any
20456 DW_TAG_inlined_subroutine DIE as a descendent
20457 of an abstract function instance. So in that case, we should
20458 not call gen_inlined_subroutine_die.
20460 Later though, when cgraph asks dwarf2out to emit info
20461 for the concrete instance of the function decl into which
20462 the concrete instance of STMT got inlined, the later will lead
20463 to the generation of a DW_TAG_inlined_subroutine DIE. */
20464 if (! BLOCK_ABSTRACT (stmt))
20465 gen_inlined_subroutine_die (stmt, context_die, depth);
20468 gen_lexical_block_die (stmt, context_die, depth);
20471 decls_for_scope (stmt, context_die, depth);
20474 /* Process variable DECL (or variable with origin ORIGIN) within
20475 block STMT and add it to CONTEXT_DIE. */
20477 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20480 tree decl_or_origin = decl ? decl : origin;
20482 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20483 die = lookup_decl_die (decl_or_origin);
20484 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20485 && TYPE_DECL_IS_STUB (decl_or_origin))
20486 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20490 if (die != NULL && die->die_parent == NULL)
20491 add_child_die (context_die, die);
20492 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20493 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20494 stmt, context_die);
20496 gen_decl_die (decl, origin, context_die);
20499 /* Generate all of the decls declared within a given scope and (recursively)
20500 all of its sub-blocks. */
20503 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20509 /* Ignore NULL blocks. */
20510 if (stmt == NULL_TREE)
20513 /* Output the DIEs to represent all of the data objects and typedefs
20514 declared directly within this block but not within any nested
20515 sub-blocks. Also, nested function and tag DIEs have been
20516 generated with a parent of NULL; fix that up now. */
20517 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20518 process_scope_var (stmt, decl, NULL_TREE, context_die);
20519 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20520 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20523 /* If we're at -g1, we're not interested in subblocks. */
20524 if (debug_info_level <= DINFO_LEVEL_TERSE)
20527 /* Output the DIEs to represent all sub-blocks (and the items declared
20528 therein) of this block. */
20529 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20531 subblocks = BLOCK_CHAIN (subblocks))
20532 gen_block_die (subblocks, context_die, depth + 1);
20535 /* Is this a typedef we can avoid emitting? */
20538 is_redundant_typedef (const_tree decl)
20540 if (TYPE_DECL_IS_STUB (decl))
20543 if (DECL_ARTIFICIAL (decl)
20544 && DECL_CONTEXT (decl)
20545 && is_tagged_type (DECL_CONTEXT (decl))
20546 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20547 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20548 /* Also ignore the artificial member typedef for the class name. */
20554 /* Return TRUE if TYPE is a typedef that names a type for linkage
20555 purposes. This kind of typedefs is produced by the C++ FE for
20558 typedef struct {...} foo;
20560 In that case, there is no typedef variant type produced for foo.
20561 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20565 is_naming_typedef_decl (const_tree decl)
20567 if (decl == NULL_TREE
20568 || TREE_CODE (decl) != TYPE_DECL
20569 || !is_tagged_type (TREE_TYPE (decl))
20570 || DECL_IS_BUILTIN (decl)
20571 || is_redundant_typedef (decl)
20572 /* It looks like Ada produces TYPE_DECLs that are very similar
20573 to C++ naming typedefs but that have different
20574 semantics. Let's be specific to c++ for now. */
20578 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20579 && TYPE_NAME (TREE_TYPE (decl)) == decl
20580 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20581 != TYPE_NAME (TREE_TYPE (decl))));
20584 /* Returns the DIE for a context. */
20586 static inline dw_die_ref
20587 get_context_die (tree context)
20591 /* Find die that represents this context. */
20592 if (TYPE_P (context))
20593 return force_type_die (TYPE_MAIN_VARIANT (context));
20595 return force_decl_die (context);
20597 return comp_unit_die ();
20600 /* Returns the DIE for decl. A DIE will always be returned. */
20603 force_decl_die (tree decl)
20605 dw_die_ref decl_die;
20606 unsigned saved_external_flag;
20607 tree save_fn = NULL_TREE;
20608 decl_die = lookup_decl_die (decl);
20611 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20613 decl_die = lookup_decl_die (decl);
20617 switch (TREE_CODE (decl))
20619 case FUNCTION_DECL:
20620 /* Clear current_function_decl, so that gen_subprogram_die thinks
20621 that this is a declaration. At this point, we just want to force
20622 declaration die. */
20623 save_fn = current_function_decl;
20624 current_function_decl = NULL_TREE;
20625 gen_subprogram_die (decl, context_die);
20626 current_function_decl = save_fn;
20630 /* Set external flag to force declaration die. Restore it after
20631 gen_decl_die() call. */
20632 saved_external_flag = DECL_EXTERNAL (decl);
20633 DECL_EXTERNAL (decl) = 1;
20634 gen_decl_die (decl, NULL, context_die);
20635 DECL_EXTERNAL (decl) = saved_external_flag;
20638 case NAMESPACE_DECL:
20639 if (dwarf_version >= 3 || !dwarf_strict)
20640 dwarf2out_decl (decl);
20642 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20643 decl_die = comp_unit_die ();
20646 case TRANSLATION_UNIT_DECL:
20647 decl_die = comp_unit_die ();
20651 gcc_unreachable ();
20654 /* We should be able to find the DIE now. */
20656 decl_die = lookup_decl_die (decl);
20657 gcc_assert (decl_die);
20663 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20664 always returned. */
20667 force_type_die (tree type)
20669 dw_die_ref type_die;
20671 type_die = lookup_type_die (type);
20674 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
20676 type_die = modified_type_die (type, TYPE_READONLY (type),
20677 TYPE_VOLATILE (type), context_die);
20678 gcc_assert (type_die);
20683 /* Force out any required namespaces to be able to output DECL,
20684 and return the new context_die for it, if it's changed. */
20687 setup_namespace_context (tree thing, dw_die_ref context_die)
20689 tree context = (DECL_P (thing)
20690 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
20691 if (context && TREE_CODE (context) == NAMESPACE_DECL)
20692 /* Force out the namespace. */
20693 context_die = force_decl_die (context);
20695 return context_die;
20698 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20699 type) within its namespace, if appropriate.
20701 For compatibility with older debuggers, namespace DIEs only contain
20702 declarations; all definitions are emitted at CU scope. */
20705 declare_in_namespace (tree thing, dw_die_ref context_die)
20707 dw_die_ref ns_context;
20709 if (debug_info_level <= DINFO_LEVEL_TERSE)
20710 return context_die;
20712 /* If this decl is from an inlined function, then don't try to emit it in its
20713 namespace, as we will get confused. It would have already been emitted
20714 when the abstract instance of the inline function was emitted anyways. */
20715 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
20716 return context_die;
20718 ns_context = setup_namespace_context (thing, context_die);
20720 if (ns_context != context_die)
20724 if (DECL_P (thing))
20725 gen_decl_die (thing, NULL, ns_context);
20727 gen_type_die (thing, ns_context);
20729 return context_die;
20732 /* Generate a DIE for a namespace or namespace alias. */
20735 gen_namespace_die (tree decl, dw_die_ref context_die)
20737 dw_die_ref namespace_die;
20739 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20740 they are an alias of. */
20741 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
20743 /* Output a real namespace or module. */
20744 context_die = setup_namespace_context (decl, comp_unit_die ());
20745 namespace_die = new_die (is_fortran ()
20746 ? DW_TAG_module : DW_TAG_namespace,
20747 context_die, decl);
20748 /* For Fortran modules defined in different CU don't add src coords. */
20749 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
20751 const char *name = dwarf2_name (decl, 0);
20753 add_name_attribute (namespace_die, name);
20756 add_name_and_src_coords_attributes (namespace_die, decl);
20757 if (DECL_EXTERNAL (decl))
20758 add_AT_flag (namespace_die, DW_AT_declaration, 1);
20759 equate_decl_number_to_die (decl, namespace_die);
20763 /* Output a namespace alias. */
20765 /* Force out the namespace we are an alias of, if necessary. */
20766 dw_die_ref origin_die
20767 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
20769 if (DECL_FILE_SCOPE_P (decl)
20770 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
20771 context_die = setup_namespace_context (decl, comp_unit_die ());
20772 /* Now create the namespace alias DIE. */
20773 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
20774 add_name_and_src_coords_attributes (namespace_die, decl);
20775 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
20776 equate_decl_number_to_die (decl, namespace_die);
20780 /* Generate Dwarf debug information for a decl described by DECL.
20781 The return value is currently only meaningful for PARM_DECLs,
20782 for all other decls it returns NULL. */
20785 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
20787 tree decl_or_origin = decl ? decl : origin;
20788 tree class_origin = NULL, ultimate_origin;
20790 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
20793 switch (TREE_CODE (decl_or_origin))
20799 if (!is_fortran () && !is_ada ())
20801 /* The individual enumerators of an enum type get output when we output
20802 the Dwarf representation of the relevant enum type itself. */
20806 /* Emit its type. */
20807 gen_type_die (TREE_TYPE (decl), context_die);
20809 /* And its containing namespace. */
20810 context_die = declare_in_namespace (decl, context_die);
20812 gen_const_die (decl, context_die);
20815 case FUNCTION_DECL:
20816 /* Don't output any DIEs to represent mere function declarations,
20817 unless they are class members or explicit block externs. */
20818 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
20819 && DECL_FILE_SCOPE_P (decl_or_origin)
20820 && (current_function_decl == NULL_TREE
20821 || DECL_ARTIFICIAL (decl_or_origin)))
20826 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20827 on local redeclarations of global functions. That seems broken. */
20828 if (current_function_decl != decl)
20829 /* This is only a declaration. */;
20832 /* If we're emitting a clone, emit info for the abstract instance. */
20833 if (origin || DECL_ORIGIN (decl) != decl)
20834 dwarf2out_abstract_function (origin
20835 ? DECL_ORIGIN (origin)
20836 : DECL_ABSTRACT_ORIGIN (decl));
20838 /* If we're emitting an out-of-line copy of an inline function,
20839 emit info for the abstract instance and set up to refer to it. */
20840 else if (cgraph_function_possibly_inlined_p (decl)
20841 && ! DECL_ABSTRACT (decl)
20842 && ! class_or_namespace_scope_p (context_die)
20843 /* dwarf2out_abstract_function won't emit a die if this is just
20844 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20845 that case, because that works only if we have a die. */
20846 && DECL_INITIAL (decl) != NULL_TREE)
20848 dwarf2out_abstract_function (decl);
20849 set_decl_origin_self (decl);
20852 /* Otherwise we're emitting the primary DIE for this decl. */
20853 else if (debug_info_level > DINFO_LEVEL_TERSE)
20855 /* Before we describe the FUNCTION_DECL itself, make sure that we
20856 have its containing type. */
20858 origin = decl_class_context (decl);
20859 if (origin != NULL_TREE)
20860 gen_type_die (origin, context_die);
20862 /* And its return type. */
20863 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
20865 /* And its virtual context. */
20866 if (DECL_VINDEX (decl) != NULL_TREE)
20867 gen_type_die (DECL_CONTEXT (decl), context_die);
20869 /* Make sure we have a member DIE for decl. */
20870 if (origin != NULL_TREE)
20871 gen_type_die_for_member (origin, decl, context_die);
20873 /* And its containing namespace. */
20874 context_die = declare_in_namespace (decl, context_die);
20877 /* Now output a DIE to represent the function itself. */
20879 gen_subprogram_die (decl, context_die);
20883 /* If we are in terse mode, don't generate any DIEs to represent any
20884 actual typedefs. */
20885 if (debug_info_level <= DINFO_LEVEL_TERSE)
20888 /* In the special case of a TYPE_DECL node representing the declaration
20889 of some type tag, if the given TYPE_DECL is marked as having been
20890 instantiated from some other (original) TYPE_DECL node (e.g. one which
20891 was generated within the original definition of an inline function) we
20892 used to generate a special (abbreviated) DW_TAG_structure_type,
20893 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20894 should be actually referencing those DIEs, as variable DIEs with that
20895 type would be emitted already in the abstract origin, so it was always
20896 removed during unused type prunning. Don't add anything in this
20898 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
20901 if (is_redundant_typedef (decl))
20902 gen_type_die (TREE_TYPE (decl), context_die);
20904 /* Output a DIE to represent the typedef itself. */
20905 gen_typedef_die (decl, context_die);
20909 if (debug_info_level >= DINFO_LEVEL_NORMAL)
20910 gen_label_die (decl, context_die);
20915 /* If we are in terse mode, don't generate any DIEs to represent any
20916 variable declarations or definitions. */
20917 if (debug_info_level <= DINFO_LEVEL_TERSE)
20920 /* Output any DIEs that are needed to specify the type of this data
20922 if (decl_by_reference_p (decl_or_origin))
20923 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20925 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20927 /* And its containing type. */
20928 class_origin = decl_class_context (decl_or_origin);
20929 if (class_origin != NULL_TREE)
20930 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
20932 /* And its containing namespace. */
20933 context_die = declare_in_namespace (decl_or_origin, context_die);
20935 /* Now output the DIE to represent the data object itself. This gets
20936 complicated because of the possibility that the VAR_DECL really
20937 represents an inlined instance of a formal parameter for an inline
20939 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20940 if (ultimate_origin != NULL_TREE
20941 && TREE_CODE (ultimate_origin) == PARM_DECL)
20942 gen_formal_parameter_die (decl, origin,
20943 true /* Emit name attribute. */,
20946 gen_variable_die (decl, origin, context_die);
20950 /* Ignore the nameless fields that are used to skip bits but handle C++
20951 anonymous unions and structs. */
20952 if (DECL_NAME (decl) != NULL_TREE
20953 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
20954 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
20956 gen_type_die (member_declared_type (decl), context_die);
20957 gen_field_die (decl, context_die);
20962 if (DECL_BY_REFERENCE (decl_or_origin))
20963 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20965 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20966 return gen_formal_parameter_die (decl, origin,
20967 true /* Emit name attribute. */,
20970 case NAMESPACE_DECL:
20971 case IMPORTED_DECL:
20972 if (dwarf_version >= 3 || !dwarf_strict)
20973 gen_namespace_die (decl, context_die);
20977 /* Probably some frontend-internal decl. Assume we don't care. */
20978 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
20985 /* Output debug information for global decl DECL. Called from toplev.c after
20986 compilation proper has finished. */
20989 dwarf2out_global_decl (tree decl)
20991 /* Output DWARF2 information for file-scope tentative data object
20992 declarations, file-scope (extern) function declarations (which
20993 had no corresponding body) and file-scope tagged type declarations
20994 and definitions which have not yet been forced out. */
20995 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
20996 dwarf2out_decl (decl);
20999 /* Output debug information for type decl DECL. Called from toplev.c
21000 and from language front ends (to record built-in types). */
21002 dwarf2out_type_decl (tree decl, int local)
21005 dwarf2out_decl (decl);
21008 /* Output debug information for imported module or decl DECL.
21009 NAME is non-NULL name in the lexical block if the decl has been renamed.
21010 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21011 that DECL belongs to.
21012 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21014 dwarf2out_imported_module_or_decl_1 (tree decl,
21016 tree lexical_block,
21017 dw_die_ref lexical_block_die)
21019 expanded_location xloc;
21020 dw_die_ref imported_die = NULL;
21021 dw_die_ref at_import_die;
21023 if (TREE_CODE (decl) == IMPORTED_DECL)
21025 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21026 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21030 xloc = expand_location (input_location);
21032 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21034 at_import_die = force_type_die (TREE_TYPE (decl));
21035 /* For namespace N { typedef void T; } using N::T; base_type_die
21036 returns NULL, but DW_TAG_imported_declaration requires
21037 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21038 if (!at_import_die)
21040 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21041 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21042 at_import_die = lookup_type_die (TREE_TYPE (decl));
21043 gcc_assert (at_import_die);
21048 at_import_die = lookup_decl_die (decl);
21049 if (!at_import_die)
21051 /* If we're trying to avoid duplicate debug info, we may not have
21052 emitted the member decl for this field. Emit it now. */
21053 if (TREE_CODE (decl) == FIELD_DECL)
21055 tree type = DECL_CONTEXT (decl);
21057 if (TYPE_CONTEXT (type)
21058 && TYPE_P (TYPE_CONTEXT (type))
21059 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21060 DINFO_USAGE_DIR_USE))
21062 gen_type_die_for_member (type, decl,
21063 get_context_die (TYPE_CONTEXT (type)));
21065 at_import_die = force_decl_die (decl);
21069 if (TREE_CODE (decl) == NAMESPACE_DECL)
21071 if (dwarf_version >= 3 || !dwarf_strict)
21072 imported_die = new_die (DW_TAG_imported_module,
21079 imported_die = new_die (DW_TAG_imported_declaration,
21083 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21084 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21086 add_AT_string (imported_die, DW_AT_name,
21087 IDENTIFIER_POINTER (name));
21088 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21091 /* Output debug information for imported module or decl DECL.
21092 NAME is non-NULL name in context if the decl has been renamed.
21093 CHILD is true if decl is one of the renamed decls as part of
21094 importing whole module. */
21097 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21100 /* dw_die_ref at_import_die; */
21101 dw_die_ref scope_die;
21103 if (debug_info_level <= DINFO_LEVEL_TERSE)
21108 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21109 We need decl DIE for reference and scope die. First, get DIE for the decl
21112 /* Get the scope die for decl context. Use comp_unit_die for global module
21113 or decl. If die is not found for non globals, force new die. */
21115 && TYPE_P (context)
21116 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21119 if (!(dwarf_version >= 3 || !dwarf_strict))
21122 scope_die = get_context_die (context);
21126 gcc_assert (scope_die->die_child);
21127 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21128 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21129 scope_die = scope_die->die_child;
21132 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21133 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21137 /* Write the debugging output for DECL. */
21140 dwarf2out_decl (tree decl)
21142 dw_die_ref context_die = comp_unit_die ();
21144 switch (TREE_CODE (decl))
21149 case FUNCTION_DECL:
21150 /* What we would really like to do here is to filter out all mere
21151 file-scope declarations of file-scope functions which are never
21152 referenced later within this translation unit (and keep all of ones
21153 that *are* referenced later on) but we aren't clairvoyant, so we have
21154 no idea which functions will be referenced in the future (i.e. later
21155 on within the current translation unit). So here we just ignore all
21156 file-scope function declarations which are not also definitions. If
21157 and when the debugger needs to know something about these functions,
21158 it will have to hunt around and find the DWARF information associated
21159 with the definition of the function.
21161 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21162 nodes represent definitions and which ones represent mere
21163 declarations. We have to check DECL_INITIAL instead. That's because
21164 the C front-end supports some weird semantics for "extern inline"
21165 function definitions. These can get inlined within the current
21166 translation unit (and thus, we need to generate Dwarf info for their
21167 abstract instances so that the Dwarf info for the concrete inlined
21168 instances can have something to refer to) but the compiler never
21169 generates any out-of-lines instances of such things (despite the fact
21170 that they *are* definitions).
21172 The important point is that the C front-end marks these "extern
21173 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21174 them anyway. Note that the C++ front-end also plays some similar games
21175 for inline function definitions appearing within include files which
21176 also contain `#pragma interface' pragmas. */
21177 if (DECL_INITIAL (decl) == NULL_TREE)
21180 /* If we're a nested function, initially use a parent of NULL; if we're
21181 a plain function, this will be fixed up in decls_for_scope. If
21182 we're a method, it will be ignored, since we already have a DIE. */
21183 if (decl_function_context (decl)
21184 /* But if we're in terse mode, we don't care about scope. */
21185 && debug_info_level > DINFO_LEVEL_TERSE)
21186 context_die = NULL;
21190 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21191 declaration and if the declaration was never even referenced from
21192 within this entire compilation unit. We suppress these DIEs in
21193 order to save space in the .debug section (by eliminating entries
21194 which are probably useless). Note that we must not suppress
21195 block-local extern declarations (whether used or not) because that
21196 would screw-up the debugger's name lookup mechanism and cause it to
21197 miss things which really ought to be in scope at a given point. */
21198 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21201 /* For local statics lookup proper context die. */
21202 if (TREE_STATIC (decl) && decl_function_context (decl))
21203 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21205 /* If we are in terse mode, don't generate any DIEs to represent any
21206 variable declarations or definitions. */
21207 if (debug_info_level <= DINFO_LEVEL_TERSE)
21212 if (debug_info_level <= DINFO_LEVEL_TERSE)
21214 if (!is_fortran () && !is_ada ())
21216 if (TREE_STATIC (decl) && decl_function_context (decl))
21217 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21220 case NAMESPACE_DECL:
21221 case IMPORTED_DECL:
21222 if (debug_info_level <= DINFO_LEVEL_TERSE)
21224 if (lookup_decl_die (decl) != NULL)
21229 /* Don't emit stubs for types unless they are needed by other DIEs. */
21230 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21233 /* Don't bother trying to generate any DIEs to represent any of the
21234 normal built-in types for the language we are compiling. */
21235 if (DECL_IS_BUILTIN (decl))
21238 /* If we are in terse mode, don't generate any DIEs for types. */
21239 if (debug_info_level <= DINFO_LEVEL_TERSE)
21242 /* If we're a function-scope tag, initially use a parent of NULL;
21243 this will be fixed up in decls_for_scope. */
21244 if (decl_function_context (decl))
21245 context_die = NULL;
21253 gen_decl_die (decl, NULL, context_die);
21256 /* Write the debugging output for DECL. */
21259 dwarf2out_function_decl (tree decl)
21261 dwarf2out_decl (decl);
21263 htab_empty (decl_loc_table);
21266 /* Output a marker (i.e. a label) for the beginning of the generated code for
21267 a lexical block. */
21270 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21271 unsigned int blocknum)
21273 switch_to_section (current_function_section ());
21274 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21277 /* Output a marker (i.e. a label) for the end of the generated code for a
21281 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21283 switch_to_section (current_function_section ());
21284 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21287 /* Returns nonzero if it is appropriate not to emit any debugging
21288 information for BLOCK, because it doesn't contain any instructions.
21290 Don't allow this for blocks with nested functions or local classes
21291 as we would end up with orphans, and in the presence of scheduling
21292 we may end up calling them anyway. */
21295 dwarf2out_ignore_block (const_tree block)
21300 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21301 if (TREE_CODE (decl) == FUNCTION_DECL
21302 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21304 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21306 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21307 if (TREE_CODE (decl) == FUNCTION_DECL
21308 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21315 /* Hash table routines for file_hash. */
21318 file_table_eq (const void *p1_p, const void *p2_p)
21320 const struct dwarf_file_data *const p1 =
21321 (const struct dwarf_file_data *) p1_p;
21322 const char *const p2 = (const char *) p2_p;
21323 return strcmp (p1->filename, p2) == 0;
21327 file_table_hash (const void *p_p)
21329 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21330 return htab_hash_string (p->filename);
21333 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21334 dwarf2out.c) and return its "index". The index of each (known) filename is
21335 just a unique number which is associated with only that one filename. We
21336 need such numbers for the sake of generating labels (in the .debug_sfnames
21337 section) and references to those files numbers (in the .debug_srcinfo
21338 and.debug_macinfo sections). If the filename given as an argument is not
21339 found in our current list, add it to the list and assign it the next
21340 available unique index number. In order to speed up searches, we remember
21341 the index of the filename was looked up last. This handles the majority of
21344 static struct dwarf_file_data *
21345 lookup_filename (const char *file_name)
21348 struct dwarf_file_data * created;
21350 /* Check to see if the file name that was searched on the previous
21351 call matches this file name. If so, return the index. */
21352 if (file_table_last_lookup
21353 && (file_name == file_table_last_lookup->filename
21354 || strcmp (file_table_last_lookup->filename, file_name) == 0))
21355 return file_table_last_lookup;
21357 /* Didn't match the previous lookup, search the table. */
21358 slot = htab_find_slot_with_hash (file_table, file_name,
21359 htab_hash_string (file_name), INSERT);
21361 return (struct dwarf_file_data *) *slot;
21363 created = ggc_alloc_dwarf_file_data ();
21364 created->filename = file_name;
21365 created->emitted_number = 0;
21370 /* If the assembler will construct the file table, then translate the compiler
21371 internal file table number into the assembler file table number, and emit
21372 a .file directive if we haven't already emitted one yet. The file table
21373 numbers are different because we prune debug info for unused variables and
21374 types, which may include filenames. */
21377 maybe_emit_file (struct dwarf_file_data * fd)
21379 if (! fd->emitted_number)
21381 if (last_emitted_file)
21382 fd->emitted_number = last_emitted_file->emitted_number + 1;
21384 fd->emitted_number = 1;
21385 last_emitted_file = fd;
21387 if (DWARF2_ASM_LINE_DEBUG_INFO)
21389 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21390 output_quoted_string (asm_out_file,
21391 remap_debug_filename (fd->filename));
21392 fputc ('\n', asm_out_file);
21396 return fd->emitted_number;
21399 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21400 That generation should happen after function debug info has been
21401 generated. The value of the attribute is the constant value of ARG. */
21404 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21406 die_arg_entry entry;
21411 if (!tmpl_value_parm_die_table)
21412 tmpl_value_parm_die_table
21413 = VEC_alloc (die_arg_entry, gc, 32);
21417 VEC_safe_push (die_arg_entry, gc,
21418 tmpl_value_parm_die_table,
21422 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21423 by append_entry_to_tmpl_value_parm_die_table. This function must
21424 be called after function DIEs have been generated. */
21427 gen_remaining_tmpl_value_param_die_attribute (void)
21429 if (tmpl_value_parm_die_table)
21434 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21435 tree_add_const_value_attribute (e->die, e->arg);
21440 /* Replace DW_AT_name for the decl with name. */
21443 dwarf2out_set_name (tree decl, tree name)
21449 die = TYPE_SYMTAB_DIE (decl);
21453 dname = dwarf2_name (name, 0);
21457 attr = get_AT (die, DW_AT_name);
21460 struct indirect_string_node *node;
21462 node = find_AT_string (dname);
21463 /* replace the string. */
21464 attr->dw_attr_val.v.val_str = node;
21468 add_name_attribute (die, dname);
21471 /* Called by the final INSN scan whenever we see a direct function call.
21472 Make an entry into the direct call table, recording the point of call
21473 and a reference to the target function's debug entry. */
21476 dwarf2out_direct_call (tree targ)
21479 tree origin = decl_ultimate_origin (targ);
21481 /* If this is a clone, use the abstract origin as the target. */
21485 e.poc_label_num = poc_label_num++;
21486 e.poc_decl = current_function_decl;
21487 e.targ_die = force_decl_die (targ);
21488 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
21490 /* Drop a label at the return point to mark the point of call. */
21491 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21494 /* Returns a hash value for X (which really is a struct vcall_insn). */
21497 vcall_insn_table_hash (const void *x)
21499 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
21502 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21503 insnd_uid of *Y. */
21506 vcall_insn_table_eq (const void *x, const void *y)
21508 return (((const struct vcall_insn *) x)->insn_uid
21509 == ((const struct vcall_insn *) y)->insn_uid);
21512 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21515 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
21517 struct vcall_insn *item = ggc_alloc_vcall_insn ();
21518 struct vcall_insn **slot;
21521 item->insn_uid = insn_uid;
21522 item->vtable_slot = vtable_slot;
21523 slot = (struct vcall_insn **)
21524 htab_find_slot_with_hash (vcall_insn_table, &item,
21525 (hashval_t) insn_uid, INSERT);
21529 /* Return the VTABLE_SLOT associated with INSN_UID. */
21531 static unsigned int
21532 lookup_vcall_insn (unsigned int insn_uid)
21534 struct vcall_insn item;
21535 struct vcall_insn *p;
21537 item.insn_uid = insn_uid;
21538 item.vtable_slot = 0;
21539 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
21541 (hashval_t) insn_uid);
21543 return (unsigned int) -1;
21544 return p->vtable_slot;
21548 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21549 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21550 is the vtable slot index that we will need to put in the virtual call
21554 dwarf2out_virtual_call_token (tree addr, int insn_uid)
21556 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
21558 tree token = OBJ_TYPE_REF_TOKEN (addr);
21559 if (TREE_CODE (token) == INTEGER_CST)
21560 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
21564 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21565 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21569 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
21571 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
21573 if (vtable_slot != (unsigned int) -1)
21574 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
21577 /* Called by the final INSN scan whenever we see a virtual function call.
21578 Make an entry into the virtual call table, recording the point of call
21579 and the slot index of the vtable entry used to call the virtual member
21580 function. The slot index was associated with the INSN_UID during the
21581 lowering to RTL. */
21584 dwarf2out_virtual_call (int insn_uid)
21586 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
21589 if (vtable_slot == (unsigned int) -1)
21592 e.poc_label_num = poc_label_num++;
21593 e.vtable_slot = vtable_slot;
21594 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
21596 /* Drop a label at the return point to mark the point of call. */
21597 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21600 /* Called by the final INSN scan whenever we see a var location. We
21601 use it to drop labels in the right places, and throw the location in
21602 our lookup table. */
21605 dwarf2out_var_location (rtx loc_note)
21607 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21608 struct var_loc_node *newloc;
21610 static const char *last_label;
21611 static const char *last_postcall_label;
21612 static bool last_in_cold_section_p;
21615 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21618 next_real = next_real_insn (loc_note);
21619 /* If there are no instructions which would be affected by this note,
21620 don't do anything. */
21621 if (next_real == NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
21624 /* If there were any real insns between note we processed last time
21625 and this note (or if it is the first note), clear
21626 last_{,postcall_}label so that they are not reused this time. */
21627 if (last_var_location_insn == NULL_RTX
21628 || last_var_location_insn != next_real
21629 || last_in_cold_section_p != in_cold_section_p)
21632 last_postcall_label = NULL;
21635 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21636 newloc = add_var_loc_to_decl (decl, loc_note,
21637 NOTE_DURING_CALL_P (loc_note)
21638 ? last_postcall_label : last_label);
21639 if (newloc == NULL)
21642 /* If there were no real insns between note we processed last time
21643 and this note, use the label we emitted last time. Otherwise
21644 create a new label and emit it. */
21645 if (last_label == NULL)
21647 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21648 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21650 last_label = ggc_strdup (loclabel);
21653 if (!NOTE_DURING_CALL_P (loc_note))
21654 newloc->label = last_label;
21657 if (!last_postcall_label)
21659 sprintf (loclabel, "%s-1", last_label);
21660 last_postcall_label = ggc_strdup (loclabel);
21662 newloc->label = last_postcall_label;
21665 last_var_location_insn = next_real;
21666 last_in_cold_section_p = in_cold_section_p;
21669 /* We need to reset the locations at the beginning of each
21670 function. We can't do this in the end_function hook, because the
21671 declarations that use the locations won't have been output when
21672 that hook is called. Also compute have_multiple_function_sections here. */
21675 dwarf2out_begin_function (tree fun)
21677 if (function_section (fun) != text_section)
21678 have_multiple_function_sections = true;
21679 else if (flag_reorder_blocks_and_partition && !cold_text_section)
21681 gcc_assert (current_function_decl == fun);
21682 cold_text_section = unlikely_text_section ();
21683 switch_to_section (cold_text_section);
21684 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
21685 switch_to_section (current_function_section ());
21688 dwarf2out_note_section_used ();
21691 /* Output a label to mark the beginning of a source code line entry
21692 and record information relating to this source line, in
21693 'line_info_table' for later output of the .debug_line section. */
21696 dwarf2out_source_line (unsigned int line, const char *filename,
21697 int discriminator, bool is_stmt)
21699 static bool last_is_stmt = true;
21701 if (debug_info_level >= DINFO_LEVEL_NORMAL
21704 int file_num = maybe_emit_file (lookup_filename (filename));
21706 switch_to_section (current_function_section ());
21708 /* If requested, emit something human-readable. */
21709 if (flag_debug_asm)
21710 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
21713 if (DWARF2_ASM_LINE_DEBUG_INFO)
21715 /* Emit the .loc directive understood by GNU as. */
21716 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
21717 if (is_stmt != last_is_stmt)
21719 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
21720 last_is_stmt = is_stmt;
21722 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
21723 fprintf (asm_out_file, " discriminator %d", discriminator);
21724 fputc ('\n', asm_out_file);
21726 /* Indicate that line number info exists. */
21727 line_info_table_in_use++;
21729 else if (function_section (current_function_decl) != text_section)
21731 dw_separate_line_info_ref line_info;
21732 targetm.asm_out.internal_label (asm_out_file,
21733 SEPARATE_LINE_CODE_LABEL,
21734 separate_line_info_table_in_use);
21736 /* Expand the line info table if necessary. */
21737 if (separate_line_info_table_in_use
21738 == separate_line_info_table_allocated)
21740 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21741 separate_line_info_table
21742 = GGC_RESIZEVEC (dw_separate_line_info_entry,
21743 separate_line_info_table,
21744 separate_line_info_table_allocated);
21745 memset (separate_line_info_table
21746 + separate_line_info_table_in_use,
21748 (LINE_INFO_TABLE_INCREMENT
21749 * sizeof (dw_separate_line_info_entry)));
21752 /* Add the new entry at the end of the line_info_table. */
21754 = &separate_line_info_table[separate_line_info_table_in_use++];
21755 line_info->dw_file_num = file_num;
21756 line_info->dw_line_num = line;
21757 line_info->function = current_function_funcdef_no;
21761 dw_line_info_ref line_info;
21763 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
21764 line_info_table_in_use);
21766 /* Expand the line info table if necessary. */
21767 if (line_info_table_in_use == line_info_table_allocated)
21769 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21771 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
21772 line_info_table_allocated);
21773 memset (line_info_table + line_info_table_in_use, 0,
21774 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
21777 /* Add the new entry at the end of the line_info_table. */
21778 line_info = &line_info_table[line_info_table_in_use++];
21779 line_info->dw_file_num = file_num;
21780 line_info->dw_line_num = line;
21785 /* Record the beginning of a new source file. */
21788 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
21790 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21792 /* Record the beginning of the file for break_out_includes. */
21793 dw_die_ref bincl_die;
21795 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
21796 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
21799 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21802 e.code = DW_MACINFO_start_file;
21804 e.info = xstrdup (filename);
21805 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21809 /* Record the end of a source file. */
21812 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
21814 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21815 /* Record the end of the file for break_out_includes. */
21816 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
21818 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21821 e.code = DW_MACINFO_end_file;
21824 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21828 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21829 the tail part of the directive line, i.e. the part which is past the
21830 initial whitespace, #, whitespace, directive-name, whitespace part. */
21833 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
21834 const char *buffer ATTRIBUTE_UNUSED)
21836 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21839 e.code = DW_MACINFO_define;
21841 e.info = xstrdup (buffer);;
21842 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21846 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21847 the tail part of the directive line, i.e. the part which is past the
21848 initial whitespace, #, whitespace, directive-name, whitespace part. */
21851 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
21852 const char *buffer ATTRIBUTE_UNUSED)
21854 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21857 e.code = DW_MACINFO_undef;
21859 e.info = xstrdup (buffer);;
21860 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21865 output_macinfo (void)
21868 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
21869 macinfo_entry *ref;
21874 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
21878 case DW_MACINFO_start_file:
21880 int file_num = maybe_emit_file (lookup_filename (ref->info));
21881 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
21882 dw2_asm_output_data_uleb128
21883 (ref->lineno, "Included from line number %lu",
21884 (unsigned long)ref->lineno);
21885 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
21888 case DW_MACINFO_end_file:
21889 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
21891 case DW_MACINFO_define:
21892 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
21893 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
21894 (unsigned long)ref->lineno);
21895 dw2_asm_output_nstring (ref->info, -1, "The macro");
21897 case DW_MACINFO_undef:
21898 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
21899 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
21900 (unsigned long)ref->lineno);
21901 dw2_asm_output_nstring (ref->info, -1, "The macro");
21904 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
21905 ASM_COMMENT_START, (unsigned long)ref->code);
21911 /* Set up for Dwarf output at the start of compilation. */
21914 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21916 /* Allocate the file_table. */
21917 file_table = htab_create_ggc (50, file_table_hash,
21918 file_table_eq, NULL);
21920 /* Allocate the decl_die_table. */
21921 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21922 decl_die_table_eq, NULL);
21924 /* Allocate the decl_loc_table. */
21925 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21926 decl_loc_table_eq, NULL);
21928 /* Allocate the initial hunk of the decl_scope_table. */
21929 decl_scope_table = VEC_alloc (tree, gc, 256);
21931 /* Allocate the initial hunk of the abbrev_die_table. */
21932 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21933 (ABBREV_DIE_TABLE_INCREMENT);
21934 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21935 /* Zero-th entry is allocated, but unused. */
21936 abbrev_die_table_in_use = 1;
21938 /* Allocate the initial hunk of the line_info_table. */
21939 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
21940 (LINE_INFO_TABLE_INCREMENT);
21941 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
21943 /* Zero-th entry is allocated, but unused. */
21944 line_info_table_in_use = 1;
21946 /* Allocate the pubtypes and pubnames vectors. */
21947 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21948 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21950 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21951 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
21952 vcall_insn_table_eq, NULL);
21954 incomplete_types = VEC_alloc (tree, gc, 64);
21956 used_rtx_array = VEC_alloc (rtx, gc, 32);
21958 debug_info_section = get_section (DEBUG_INFO_SECTION,
21959 SECTION_DEBUG, NULL);
21960 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21961 SECTION_DEBUG, NULL);
21962 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21963 SECTION_DEBUG, NULL);
21964 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
21965 SECTION_DEBUG, NULL);
21966 debug_line_section = get_section (DEBUG_LINE_SECTION,
21967 SECTION_DEBUG, NULL);
21968 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21969 SECTION_DEBUG, NULL);
21970 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21971 SECTION_DEBUG, NULL);
21972 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21973 SECTION_DEBUG, NULL);
21974 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
21975 SECTION_DEBUG, NULL);
21976 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
21977 SECTION_DEBUG, NULL);
21978 debug_str_section = get_section (DEBUG_STR_SECTION,
21979 DEBUG_STR_SECTION_FLAGS, NULL);
21980 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
21981 SECTION_DEBUG, NULL);
21982 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
21983 SECTION_DEBUG, NULL);
21985 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
21986 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
21987 DEBUG_ABBREV_SECTION_LABEL, 0);
21988 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
21989 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
21990 COLD_TEXT_SECTION_LABEL, 0);
21991 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
21993 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
21994 DEBUG_INFO_SECTION_LABEL, 0);
21995 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
21996 DEBUG_LINE_SECTION_LABEL, 0);
21997 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
21998 DEBUG_RANGES_SECTION_LABEL, 0);
21999 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22000 DEBUG_MACINFO_SECTION_LABEL, 0);
22002 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22003 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22005 switch_to_section (text_section);
22006 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22009 /* Called before cgraph_optimize starts outputtting functions, variables
22010 and toplevel asms into assembly. */
22013 dwarf2out_assembly_start (void)
22015 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22016 && dwarf2out_do_cfi_asm ()
22017 && (!(flag_unwind_tables || flag_exceptions)
22018 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22019 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22022 /* A helper function for dwarf2out_finish called through
22023 htab_traverse. Emit one queued .debug_str string. */
22026 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22028 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22030 if (node->label && node->refcount)
22032 switch_to_section (debug_str_section);
22033 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22034 assemble_string (node->str, strlen (node->str) + 1);
22040 #if ENABLE_ASSERT_CHECKING
22041 /* Verify that all marks are clear. */
22044 verify_marks_clear (dw_die_ref die)
22048 gcc_assert (! die->die_mark);
22049 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22051 #endif /* ENABLE_ASSERT_CHECKING */
22053 /* Clear the marks for a die and its children.
22054 Be cool if the mark isn't set. */
22057 prune_unmark_dies (dw_die_ref die)
22063 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22066 /* Given DIE that we're marking as used, find any other dies
22067 it references as attributes and mark them as used. */
22070 prune_unused_types_walk_attribs (dw_die_ref die)
22075 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22077 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22079 /* A reference to another DIE.
22080 Make sure that it will get emitted.
22081 If it was broken out into a comdat group, don't follow it. */
22082 if (dwarf_version < 4
22083 || a->dw_attr == DW_AT_specification
22084 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22085 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22087 /* Set the string's refcount to 0 so that prune_unused_types_mark
22088 accounts properly for it. */
22089 if (AT_class (a) == dw_val_class_str)
22090 a->dw_attr_val.v.val_str->refcount = 0;
22095 /* Mark DIE as being used. If DOKIDS is true, then walk down
22096 to DIE's children. */
22099 prune_unused_types_mark (dw_die_ref die, int dokids)
22103 if (die->die_mark == 0)
22105 /* We haven't done this node yet. Mark it as used. */
22108 /* We also have to mark its parents as used.
22109 (But we don't want to mark our parents' kids due to this.) */
22110 if (die->die_parent)
22111 prune_unused_types_mark (die->die_parent, 0);
22113 /* Mark any referenced nodes. */
22114 prune_unused_types_walk_attribs (die);
22116 /* If this node is a specification,
22117 also mark the definition, if it exists. */
22118 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22119 prune_unused_types_mark (die->die_definition, 1);
22122 if (dokids && die->die_mark != 2)
22124 /* We need to walk the children, but haven't done so yet.
22125 Remember that we've walked the kids. */
22128 /* If this is an array type, we need to make sure our
22129 kids get marked, even if they're types. If we're
22130 breaking out types into comdat sections, do this
22131 for all type definitions. */
22132 if (die->die_tag == DW_TAG_array_type
22133 || (dwarf_version >= 4
22134 && is_type_die (die) && ! is_declaration_die (die)))
22135 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22137 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22141 /* For local classes, look if any static member functions were emitted
22142 and if so, mark them. */
22145 prune_unused_types_walk_local_classes (dw_die_ref die)
22149 if (die->die_mark == 2)
22152 switch (die->die_tag)
22154 case DW_TAG_structure_type:
22155 case DW_TAG_union_type:
22156 case DW_TAG_class_type:
22159 case DW_TAG_subprogram:
22160 if (!get_AT_flag (die, DW_AT_declaration)
22161 || die->die_definition != NULL)
22162 prune_unused_types_mark (die, 1);
22169 /* Mark children. */
22170 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22173 /* Walk the tree DIE and mark types that we actually use. */
22176 prune_unused_types_walk (dw_die_ref die)
22180 /* Don't do anything if this node is already marked and
22181 children have been marked as well. */
22182 if (die->die_mark == 2)
22185 switch (die->die_tag)
22187 case DW_TAG_structure_type:
22188 case DW_TAG_union_type:
22189 case DW_TAG_class_type:
22190 if (die->die_perennial_p)
22193 for (c = die->die_parent; c; c = c->die_parent)
22194 if (c->die_tag == DW_TAG_subprogram)
22197 /* Finding used static member functions inside of classes
22198 is needed just for local classes, because for other classes
22199 static member function DIEs with DW_AT_specification
22200 are emitted outside of the DW_TAG_*_type. If we ever change
22201 it, we'd need to call this even for non-local classes. */
22203 prune_unused_types_walk_local_classes (die);
22205 /* It's a type node --- don't mark it. */
22208 case DW_TAG_const_type:
22209 case DW_TAG_packed_type:
22210 case DW_TAG_pointer_type:
22211 case DW_TAG_reference_type:
22212 case DW_TAG_rvalue_reference_type:
22213 case DW_TAG_volatile_type:
22214 case DW_TAG_typedef:
22215 case DW_TAG_array_type:
22216 case DW_TAG_interface_type:
22217 case DW_TAG_friend:
22218 case DW_TAG_variant_part:
22219 case DW_TAG_enumeration_type:
22220 case DW_TAG_subroutine_type:
22221 case DW_TAG_string_type:
22222 case DW_TAG_set_type:
22223 case DW_TAG_subrange_type:
22224 case DW_TAG_ptr_to_member_type:
22225 case DW_TAG_file_type:
22226 if (die->die_perennial_p)
22229 /* It's a type node --- don't mark it. */
22233 /* Mark everything else. */
22237 if (die->die_mark == 0)
22241 /* Now, mark any dies referenced from here. */
22242 prune_unused_types_walk_attribs (die);
22247 /* Mark children. */
22248 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22251 /* Increment the string counts on strings referred to from DIE's
22255 prune_unused_types_update_strings (dw_die_ref die)
22260 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22261 if (AT_class (a) == dw_val_class_str)
22263 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22265 /* Avoid unnecessarily putting strings that are used less than
22266 twice in the hash table. */
22268 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22271 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22272 htab_hash_string (s->str),
22274 gcc_assert (*slot == NULL);
22280 /* Remove from the tree DIE any dies that aren't marked. */
22283 prune_unused_types_prune (dw_die_ref die)
22287 gcc_assert (die->die_mark);
22288 prune_unused_types_update_strings (die);
22290 if (! die->die_child)
22293 c = die->die_child;
22295 dw_die_ref prev = c;
22296 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22297 if (c == die->die_child)
22299 /* No marked children between 'prev' and the end of the list. */
22301 /* No marked children at all. */
22302 die->die_child = NULL;
22305 prev->die_sib = c->die_sib;
22306 die->die_child = prev;
22311 if (c != prev->die_sib)
22313 prune_unused_types_prune (c);
22314 } while (c != die->die_child);
22317 /* A helper function for dwarf2out_finish called through
22318 htab_traverse. Clear .debug_str strings that we haven't already
22319 decided to emit. */
22322 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22324 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22326 if (!node->label || !node->refcount)
22327 htab_clear_slot (debug_str_hash, h);
22332 /* Remove dies representing declarations that we never use. */
22335 prune_unused_types (void)
22338 limbo_die_node *node;
22339 comdat_type_node *ctnode;
22341 dcall_entry *dcall;
22343 #if ENABLE_ASSERT_CHECKING
22344 /* All the marks should already be clear. */
22345 verify_marks_clear (comp_unit_die ());
22346 for (node = limbo_die_list; node; node = node->next)
22347 verify_marks_clear (node->die);
22348 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22349 verify_marks_clear (ctnode->root_die);
22350 #endif /* ENABLE_ASSERT_CHECKING */
22352 /* Mark types that are used in global variables. */
22353 premark_types_used_by_global_vars ();
22355 /* Set the mark on nodes that are actually used. */
22356 prune_unused_types_walk (comp_unit_die ());
22357 for (node = limbo_die_list; node; node = node->next)
22358 prune_unused_types_walk (node->die);
22359 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22361 prune_unused_types_walk (ctnode->root_die);
22362 prune_unused_types_mark (ctnode->type_die, 1);
22365 /* Also set the mark on nodes referenced from the
22366 pubname_table or arange_table. */
22367 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22368 prune_unused_types_mark (pub->die, 1);
22369 for (i = 0; i < arange_table_in_use; i++)
22370 prune_unused_types_mark (arange_table[i], 1);
22372 /* Mark nodes referenced from the direct call table. */
22373 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, dcall)
22374 prune_unused_types_mark (dcall->targ_die, 1);
22376 /* Get rid of nodes that aren't marked; and update the string counts. */
22377 if (debug_str_hash && debug_str_hash_forced)
22378 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22379 else if (debug_str_hash)
22380 htab_empty (debug_str_hash);
22381 prune_unused_types_prune (comp_unit_die ());
22382 for (node = limbo_die_list; node; node = node->next)
22383 prune_unused_types_prune (node->die);
22384 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22385 prune_unused_types_prune (ctnode->root_die);
22387 /* Leave the marks clear. */
22388 prune_unmark_dies (comp_unit_die ());
22389 for (node = limbo_die_list; node; node = node->next)
22390 prune_unmark_dies (node->die);
22391 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22392 prune_unmark_dies (ctnode->root_die);
22395 /* Set the parameter to true if there are any relative pathnames in
22398 file_table_relative_p (void ** slot, void *param)
22400 bool *p = (bool *) param;
22401 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22402 if (!IS_ABSOLUTE_PATH (d->filename))
22410 /* Routines to manipulate hash table of comdat type units. */
22413 htab_ct_hash (const void *of)
22416 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22418 memcpy (&h, type_node->signature, sizeof (h));
22423 htab_ct_eq (const void *of1, const void *of2)
22425 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22426 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22428 return (! memcmp (type_node_1->signature, type_node_2->signature,
22429 DWARF_TYPE_SIGNATURE_SIZE));
22432 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22433 to the location it would have been added, should we know its
22434 DECL_ASSEMBLER_NAME when we added other attributes. This will
22435 probably improve compactness of debug info, removing equivalent
22436 abbrevs, and hide any differences caused by deferring the
22437 computation of the assembler name, triggered by e.g. PCH. */
22440 move_linkage_attr (dw_die_ref die)
22442 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22443 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22445 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22446 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22450 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22452 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22456 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22458 VEC_pop (dw_attr_node, die->die_attr);
22459 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22463 /* Helper function for resolve_addr, attempt to resolve
22464 one CONST_STRING, return non-zero if not successful. Similarly verify that
22465 SYMBOL_REFs refer to variables emitted in the current CU. */
22468 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22472 if (GET_CODE (rtl) == CONST_STRING)
22474 size_t len = strlen (XSTR (rtl, 0)) + 1;
22475 tree t = build_string (len, XSTR (rtl, 0));
22476 tree tlen = build_int_cst (NULL_TREE, len - 1);
22478 = build_array_type (char_type_node, build_index_type (tlen));
22479 rtl = lookup_constant_def (t);
22480 if (!rtl || !MEM_P (rtl))
22482 rtl = XEXP (rtl, 0);
22483 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22488 if (GET_CODE (rtl) == SYMBOL_REF
22489 && SYMBOL_REF_DECL (rtl)
22490 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22493 if (GET_CODE (rtl) == CONST
22494 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22500 /* Helper function for resolve_addr, handle one location
22501 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22502 the location list couldn't be resolved. */
22505 resolve_addr_in_expr (dw_loc_descr_ref loc)
22507 for (; loc; loc = loc->dw_loc_next)
22508 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22509 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22510 || (loc->dw_loc_opc == DW_OP_implicit_value
22511 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22512 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22514 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22515 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22518 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22521 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22522 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22523 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22528 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22529 an address in .rodata section if the string literal is emitted there,
22530 or remove the containing location list or replace DW_AT_const_value
22531 with DW_AT_location and empty location expression, if it isn't found
22532 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22533 to something that has been emitted in the current CU. */
22536 resolve_addr (dw_die_ref die)
22540 dw_loc_list_ref *curr;
22543 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22544 switch (AT_class (a))
22546 case dw_val_class_loc_list:
22547 curr = AT_loc_list_ptr (a);
22550 if (!resolve_addr_in_expr ((*curr)->expr))
22552 dw_loc_list_ref next = (*curr)->dw_loc_next;
22553 if (next && (*curr)->ll_symbol)
22555 gcc_assert (!next->ll_symbol);
22556 next->ll_symbol = (*curr)->ll_symbol;
22561 curr = &(*curr)->dw_loc_next;
22563 if (!AT_loc_list (a))
22565 remove_AT (die, a->dw_attr);
22569 case dw_val_class_loc:
22570 if (!resolve_addr_in_expr (AT_loc (a)))
22572 remove_AT (die, a->dw_attr);
22576 case dw_val_class_addr:
22577 if (a->dw_attr == DW_AT_const_value
22578 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22580 remove_AT (die, a->dw_attr);
22588 FOR_EACH_CHILD (die, c, resolve_addr (c));
22591 /* Helper routines for optimize_location_lists.
22592 This pass tries to share identical local lists in .debug_loc
22595 /* Iteratively hash operands of LOC opcode. */
22597 static inline hashval_t
22598 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
22600 dw_val_ref val1 = &loc->dw_loc_oprnd1;
22601 dw_val_ref val2 = &loc->dw_loc_oprnd2;
22603 switch (loc->dw_loc_opc)
22605 case DW_OP_const4u:
22606 case DW_OP_const8u:
22610 case DW_OP_const1u:
22611 case DW_OP_const1s:
22612 case DW_OP_const2u:
22613 case DW_OP_const2s:
22614 case DW_OP_const4s:
22615 case DW_OP_const8s:
22619 case DW_OP_plus_uconst:
22655 case DW_OP_deref_size:
22656 case DW_OP_xderef_size:
22657 hash = iterative_hash_object (val1->v.val_int, hash);
22664 gcc_assert (val1->val_class == dw_val_class_loc);
22665 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
22666 hash = iterative_hash_object (offset, hash);
22669 case DW_OP_implicit_value:
22670 hash = iterative_hash_object (val1->v.val_unsigned, hash);
22671 switch (val2->val_class)
22673 case dw_val_class_const:
22674 hash = iterative_hash_object (val2->v.val_int, hash);
22676 case dw_val_class_vec:
22678 unsigned int elt_size = val2->v.val_vec.elt_size;
22679 unsigned int len = val2->v.val_vec.length;
22681 hash = iterative_hash_object (elt_size, hash);
22682 hash = iterative_hash_object (len, hash);
22683 hash = iterative_hash (val2->v.val_vec.array,
22684 len * elt_size, hash);
22687 case dw_val_class_const_double:
22688 hash = iterative_hash_object (val2->v.val_double.low, hash);
22689 hash = iterative_hash_object (val2->v.val_double.high, hash);
22691 case dw_val_class_addr:
22692 hash = iterative_hash_rtx (val2->v.val_addr, hash);
22695 gcc_unreachable ();
22699 case DW_OP_bit_piece:
22700 hash = iterative_hash_object (val1->v.val_int, hash);
22701 hash = iterative_hash_object (val2->v.val_int, hash);
22707 unsigned char dtprel = 0xd1;
22708 hash = iterative_hash_object (dtprel, hash);
22710 hash = iterative_hash_rtx (val1->v.val_addr, hash);
22712 case DW_OP_GNU_implicit_pointer:
22713 hash = iterative_hash_object (val2->v.val_int, hash);
22717 /* Other codes have no operands. */
22723 /* Iteratively hash the whole DWARF location expression LOC. */
22725 static inline hashval_t
22726 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
22728 dw_loc_descr_ref l;
22729 bool sizes_computed = false;
22730 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22731 size_of_locs (loc);
22733 for (l = loc; l != NULL; l = l->dw_loc_next)
22735 enum dwarf_location_atom opc = l->dw_loc_opc;
22736 hash = iterative_hash_object (opc, hash);
22737 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
22739 size_of_locs (loc);
22740 sizes_computed = true;
22742 hash = hash_loc_operands (l, hash);
22747 /* Compute hash of the whole location list LIST_HEAD. */
22750 hash_loc_list (dw_loc_list_ref list_head)
22752 dw_loc_list_ref curr = list_head;
22753 hashval_t hash = 0;
22755 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
22757 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
22758 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
22760 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
22762 hash = hash_locs (curr->expr, hash);
22764 list_head->hash = hash;
22767 /* Return true if X and Y opcodes have the same operands. */
22770 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
22772 dw_val_ref valx1 = &x->dw_loc_oprnd1;
22773 dw_val_ref valx2 = &x->dw_loc_oprnd2;
22774 dw_val_ref valy1 = &y->dw_loc_oprnd1;
22775 dw_val_ref valy2 = &y->dw_loc_oprnd2;
22777 switch (x->dw_loc_opc)
22779 case DW_OP_const4u:
22780 case DW_OP_const8u:
22784 case DW_OP_const1u:
22785 case DW_OP_const1s:
22786 case DW_OP_const2u:
22787 case DW_OP_const2s:
22788 case DW_OP_const4s:
22789 case DW_OP_const8s:
22793 case DW_OP_plus_uconst:
22829 case DW_OP_deref_size:
22830 case DW_OP_xderef_size:
22831 return valx1->v.val_int == valy1->v.val_int;
22834 gcc_assert (valx1->val_class == dw_val_class_loc
22835 && valy1->val_class == dw_val_class_loc
22836 && x->dw_loc_addr == y->dw_loc_addr);
22837 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22838 case DW_OP_implicit_value:
22839 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22840 || valx2->val_class != valy2->val_class)
22842 switch (valx2->val_class)
22844 case dw_val_class_const:
22845 return valx2->v.val_int == valy2->v.val_int;
22846 case dw_val_class_vec:
22847 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22848 && valx2->v.val_vec.length == valy2->v.val_vec.length
22849 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22850 valx2->v.val_vec.elt_size
22851 * valx2->v.val_vec.length) == 0;
22852 case dw_val_class_const_double:
22853 return valx2->v.val_double.low == valy2->v.val_double.low
22854 && valx2->v.val_double.high == valy2->v.val_double.high;
22855 case dw_val_class_addr:
22856 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22858 gcc_unreachable ();
22861 case DW_OP_bit_piece:
22862 return valx1->v.val_int == valy1->v.val_int
22863 && valx2->v.val_int == valy2->v.val_int;
22866 return rtx_equal_p (valx1->v.val_addr, valx2->v.val_addr);
22867 case DW_OP_GNU_implicit_pointer:
22868 return valx1->val_class == dw_val_class_die_ref
22869 && valx1->val_class == valy1->val_class
22870 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22871 && valx2->v.val_int == valy2->v.val_int;
22873 /* Other codes have no operands. */
22878 /* Return true if DWARF location expressions X and Y are the same. */
22881 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22883 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22884 if (x->dw_loc_opc != y->dw_loc_opc
22885 || x->dtprel != y->dtprel
22886 || !compare_loc_operands (x, y))
22888 return x == NULL && y == NULL;
22891 /* Return precomputed hash of location list X. */
22894 loc_list_hash (const void *x)
22896 return ((const struct dw_loc_list_struct *) x)->hash;
22899 /* Return 1 if location lists X and Y are the same. */
22902 loc_list_eq (const void *x, const void *y)
22904 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22905 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22908 if (a->hash != b->hash)
22910 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22911 if (strcmp (a->begin, b->begin) != 0
22912 || strcmp (a->end, b->end) != 0
22913 || (a->section == NULL) != (b->section == NULL)
22914 || (a->section && strcmp (a->section, b->section) != 0)
22915 || !compare_locs (a->expr, b->expr))
22917 return a == NULL && b == NULL;
22920 /* Recursively optimize location lists referenced from DIE
22921 children and share them whenever possible. */
22924 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22931 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22932 if (AT_class (a) == dw_val_class_loc_list)
22934 dw_loc_list_ref list = AT_loc_list (a);
22935 /* TODO: perform some optimizations here, before hashing
22936 it and storing into the hash table. */
22937 hash_loc_list (list);
22938 slot = htab_find_slot_with_hash (htab, list, list->hash,
22941 *slot = (void *) list;
22943 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22946 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22949 /* Optimize location lists referenced from DIE
22950 children and share them whenever possible. */
22953 optimize_location_lists (dw_die_ref die)
22955 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22956 optimize_location_lists_1 (die, htab);
22957 htab_delete (htab);
22960 /* Output stuff that dwarf requires at the end of every file,
22961 and generate the DWARF-2 debugging info. */
22964 dwarf2out_finish (const char *filename)
22966 limbo_die_node *node, *next_node;
22967 comdat_type_node *ctnode;
22968 htab_t comdat_type_table;
22971 gen_remaining_tmpl_value_param_die_attribute ();
22973 /* Add the name for the main input file now. We delayed this from
22974 dwarf2out_init to avoid complications with PCH. */
22975 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
22976 if (!IS_ABSOLUTE_PATH (filename))
22977 add_comp_dir_attribute (comp_unit_die ());
22978 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
22981 htab_traverse (file_table, file_table_relative_p, &p);
22983 add_comp_dir_attribute (comp_unit_die ());
22986 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
22988 add_location_or_const_value_attribute (
22989 VEC_index (deferred_locations, deferred_locations_list, i)->die,
22990 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
22994 /* Traverse the limbo die list, and add parent/child links. The only
22995 dies without parents that should be here are concrete instances of
22996 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
22997 For concrete instances, we can get the parent die from the abstract
22999 for (node = limbo_die_list; node; node = next_node)
23001 dw_die_ref die = node->die;
23002 next_node = node->next;
23004 if (die->die_parent == NULL)
23006 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23009 add_child_die (origin->die_parent, die);
23010 else if (is_cu_die (die))
23012 else if (seen_error ())
23013 /* It's OK to be confused by errors in the input. */
23014 add_child_die (comp_unit_die (), die);
23017 /* In certain situations, the lexical block containing a
23018 nested function can be optimized away, which results
23019 in the nested function die being orphaned. Likewise
23020 with the return type of that nested function. Force
23021 this to be a child of the containing function.
23023 It may happen that even the containing function got fully
23024 inlined and optimized out. In that case we are lost and
23025 assign the empty child. This should not be big issue as
23026 the function is likely unreachable too. */
23027 tree context = NULL_TREE;
23029 gcc_assert (node->created_for);
23031 if (DECL_P (node->created_for))
23032 context = DECL_CONTEXT (node->created_for);
23033 else if (TYPE_P (node->created_for))
23034 context = TYPE_CONTEXT (node->created_for);
23036 gcc_assert (context
23037 && (TREE_CODE (context) == FUNCTION_DECL
23038 || TREE_CODE (context) == NAMESPACE_DECL));
23040 origin = lookup_decl_die (context);
23042 add_child_die (origin, die);
23044 add_child_die (comp_unit_die (), die);
23049 limbo_die_list = NULL;
23051 resolve_addr (comp_unit_die ());
23053 for (node = deferred_asm_name; node; node = node->next)
23055 tree decl = node->created_for;
23056 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23058 add_linkage_attr (node->die, decl);
23059 move_linkage_attr (node->die);
23063 deferred_asm_name = NULL;
23065 /* Walk through the list of incomplete types again, trying once more to
23066 emit full debugging info for them. */
23067 retry_incomplete_types ();
23069 if (flag_eliminate_unused_debug_types)
23070 prune_unused_types ();
23072 /* Generate separate CUs for each of the include files we've seen.
23073 They will go into limbo_die_list. */
23074 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23075 break_out_includes (comp_unit_die ());
23077 /* Generate separate COMDAT sections for type DIEs. */
23078 if (dwarf_version >= 4)
23080 break_out_comdat_types (comp_unit_die ());
23082 /* Each new type_unit DIE was added to the limbo die list when created.
23083 Since these have all been added to comdat_type_list, clear the
23085 limbo_die_list = NULL;
23087 /* For each new comdat type unit, copy declarations for incomplete
23088 types to make the new unit self-contained (i.e., no direct
23089 references to the main compile unit). */
23090 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23091 copy_decls_for_unworthy_types (ctnode->root_die);
23092 copy_decls_for_unworthy_types (comp_unit_die ());
23094 /* In the process of copying declarations from one unit to another,
23095 we may have left some declarations behind that are no longer
23096 referenced. Prune them. */
23097 prune_unused_types ();
23100 /* Traverse the DIE's and add add sibling attributes to those DIE's
23101 that have children. */
23102 add_sibling_attributes (comp_unit_die ());
23103 for (node = limbo_die_list; node; node = node->next)
23104 add_sibling_attributes (node->die);
23105 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23106 add_sibling_attributes (ctnode->root_die);
23108 /* Output a terminator label for the .text section. */
23109 switch_to_section (text_section);
23110 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23111 if (cold_text_section)
23113 switch_to_section (cold_text_section);
23114 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23117 /* We can only use the low/high_pc attributes if all of the code was
23119 if (!have_multiple_function_sections
23120 || !(dwarf_version >= 3 || !dwarf_strict))
23122 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23123 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23128 unsigned fde_idx = 0;
23129 bool range_list_added = false;
23131 /* We need to give .debug_loc and .debug_ranges an appropriate
23132 "base address". Use zero so that these addresses become
23133 absolute. Historically, we've emitted the unexpected
23134 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23135 Emit both to give time for other tools to adapt. */
23136 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23137 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23139 if (text_section_used)
23140 add_ranges_by_labels (comp_unit_die (), text_section_label,
23141 text_end_label, &range_list_added);
23142 if (flag_reorder_blocks_and_partition && cold_text_section_used)
23143 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23144 cold_end_label, &range_list_added);
23146 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23148 dw_fde_ref fde = &fde_table[fde_idx];
23150 if (fde->dw_fde_switched_sections)
23152 if (!fde->in_std_section)
23153 add_ranges_by_labels (comp_unit_die (),
23154 fde->dw_fde_hot_section_label,
23155 fde->dw_fde_hot_section_end_label,
23156 &range_list_added);
23157 if (!fde->cold_in_std_section)
23158 add_ranges_by_labels (comp_unit_die (),
23159 fde->dw_fde_unlikely_section_label,
23160 fde->dw_fde_unlikely_section_end_label,
23161 &range_list_added);
23163 else if (!fde->in_std_section)
23164 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23165 fde->dw_fde_end, &range_list_added);
23168 if (range_list_added)
23172 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23173 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23174 debug_line_section_label);
23176 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23177 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23179 if (have_location_lists)
23180 optimize_location_lists (comp_unit_die ());
23182 /* Output all of the compilation units. We put the main one last so that
23183 the offsets are available to output_pubnames. */
23184 for (node = limbo_die_list; node; node = node->next)
23185 output_comp_unit (node->die, 0);
23187 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23188 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23190 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23192 /* Don't output duplicate types. */
23193 if (*slot != HTAB_EMPTY_ENTRY)
23196 /* Add a pointer to the line table for the main compilation unit
23197 so that the debugger can make sense of DW_AT_decl_file
23199 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23200 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23201 debug_line_section_label);
23203 output_comdat_type_unit (ctnode);
23206 htab_delete (comdat_type_table);
23208 /* Output the main compilation unit if non-empty or if .debug_macinfo
23209 will be emitted. */
23210 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23212 /* Output the abbreviation table. */
23213 switch_to_section (debug_abbrev_section);
23214 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23215 output_abbrev_section ();
23217 /* Output location list section if necessary. */
23218 if (have_location_lists)
23220 /* Output the location lists info. */
23221 switch_to_section (debug_loc_section);
23222 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23223 DEBUG_LOC_SECTION_LABEL, 0);
23224 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23225 output_location_lists (comp_unit_die ());
23228 /* Output public names table if necessary. */
23229 if (!VEC_empty (pubname_entry, pubname_table))
23231 gcc_assert (info_section_emitted);
23232 switch_to_section (debug_pubnames_section);
23233 output_pubnames (pubname_table);
23236 /* Output public types table if necessary. */
23237 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23238 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23239 simply won't look for the section. */
23240 if (!VEC_empty (pubname_entry, pubtype_table))
23242 bool empty = false;
23244 if (flag_eliminate_unused_debug_types)
23246 /* The pubtypes table might be emptied by pruning unused items. */
23250 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23251 if (p->die->die_offset != 0)
23259 gcc_assert (info_section_emitted);
23260 switch_to_section (debug_pubtypes_section);
23261 output_pubnames (pubtype_table);
23265 /* Output direct and virtual call tables if necessary. */
23266 if (!VEC_empty (dcall_entry, dcall_table))
23268 switch_to_section (debug_dcall_section);
23269 output_dcall_table ();
23271 if (!VEC_empty (vcall_entry, vcall_table))
23273 switch_to_section (debug_vcall_section);
23274 output_vcall_table ();
23277 /* Output the address range information. We only put functions in the arange
23278 table, so don't write it out if we don't have any. */
23279 if (fde_table_in_use)
23281 switch_to_section (debug_aranges_section);
23285 /* Output ranges section if necessary. */
23286 if (ranges_table_in_use)
23288 switch_to_section (debug_ranges_section);
23289 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23293 /* Output the source line correspondence table. We must do this
23294 even if there is no line information. Otherwise, on an empty
23295 translation unit, we will generate a present, but empty,
23296 .debug_info section. IRIX 6.5 `nm' will then complain when
23297 examining the file. This is done late so that any filenames
23298 used by the debug_info section are marked as 'used'. */
23299 switch_to_section (debug_line_section);
23300 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23301 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23302 output_line_info ();
23304 /* Have to end the macro section. */
23305 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23307 switch_to_section (debug_macinfo_section);
23308 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23309 if (!VEC_empty (macinfo_entry, macinfo_table))
23311 dw2_asm_output_data (1, 0, "End compilation unit");
23314 /* If we emitted any DW_FORM_strp form attribute, output the string
23316 if (debug_str_hash)
23317 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23320 #include "gt-dwarf2out.h"