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 dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6268 static void equate_type_number_to_die (tree, dw_die_ref);
6269 static hashval_t decl_die_table_hash (const void *);
6270 static int decl_die_table_eq (const void *, const void *);
6271 static dw_die_ref lookup_decl_die (tree);
6272 static hashval_t common_block_die_table_hash (const void *);
6273 static int common_block_die_table_eq (const void *, const void *);
6274 static hashval_t decl_loc_table_hash (const void *);
6275 static int decl_loc_table_eq (const void *, const void *);
6276 static var_loc_list *lookup_decl_loc (const_tree);
6277 static void equate_decl_number_to_die (tree, dw_die_ref);
6278 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6279 static void print_spaces (FILE *);
6280 static void print_die (dw_die_ref, FILE *);
6281 static void print_dwarf_line_table (FILE *);
6282 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6283 static dw_die_ref pop_compile_unit (dw_die_ref);
6284 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6285 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6286 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6287 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6288 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6289 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6290 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6291 struct md5_ctx *, int *);
6292 struct checksum_attributes;
6293 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6294 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6295 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6296 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6297 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6298 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6299 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6300 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6301 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6302 static void compute_section_prefix (dw_die_ref);
6303 static int is_type_die (dw_die_ref);
6304 static int is_comdat_die (dw_die_ref);
6305 static int is_symbol_die (dw_die_ref);
6306 static void assign_symbol_names (dw_die_ref);
6307 static void break_out_includes (dw_die_ref);
6308 static int is_declaration_die (dw_die_ref);
6309 static int should_move_die_to_comdat (dw_die_ref);
6310 static dw_die_ref clone_as_declaration (dw_die_ref);
6311 static dw_die_ref clone_die (dw_die_ref);
6312 static dw_die_ref clone_tree (dw_die_ref);
6313 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6314 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6315 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6316 static dw_die_ref generate_skeleton (dw_die_ref);
6317 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6319 static void break_out_comdat_types (dw_die_ref);
6320 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6321 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6322 static void copy_decls_for_unworthy_types (dw_die_ref);
6324 static hashval_t htab_cu_hash (const void *);
6325 static int htab_cu_eq (const void *, const void *);
6326 static void htab_cu_del (void *);
6327 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6328 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6329 static void add_sibling_attributes (dw_die_ref);
6330 static void build_abbrev_table (dw_die_ref);
6331 static void output_location_lists (dw_die_ref);
6332 static int constant_size (unsigned HOST_WIDE_INT);
6333 static unsigned long size_of_die (dw_die_ref);
6334 static void calc_die_sizes (dw_die_ref);
6335 static void mark_dies (dw_die_ref);
6336 static void unmark_dies (dw_die_ref);
6337 static void unmark_all_dies (dw_die_ref);
6338 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6339 static unsigned long size_of_aranges (void);
6340 static enum dwarf_form value_format (dw_attr_ref);
6341 static void output_value_format (dw_attr_ref);
6342 static void output_abbrev_section (void);
6343 static void output_die_symbol (dw_die_ref);
6344 static void output_die (dw_die_ref);
6345 static void output_compilation_unit_header (void);
6346 static void output_comp_unit (dw_die_ref, int);
6347 static void output_comdat_type_unit (comdat_type_node *);
6348 static const char *dwarf2_name (tree, int);
6349 static void add_pubname (tree, dw_die_ref);
6350 static void add_pubname_string (const char *, dw_die_ref);
6351 static void add_pubtype (tree, dw_die_ref);
6352 static void output_pubnames (VEC (pubname_entry,gc) *);
6353 static void add_arange (tree, dw_die_ref);
6354 static void output_aranges (void);
6355 static unsigned int add_ranges_num (int);
6356 static unsigned int add_ranges (const_tree);
6357 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6359 static void output_ranges (void);
6360 static void output_line_info (void);
6361 static void output_file_names (void);
6362 static dw_die_ref base_type_die (tree);
6363 static int is_base_type (tree);
6364 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6365 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6366 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6367 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6368 static int type_is_enum (const_tree);
6369 static unsigned int dbx_reg_number (const_rtx);
6370 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6371 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6372 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6373 enum var_init_status);
6374 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6375 enum var_init_status);
6376 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6377 enum var_init_status);
6378 static int is_based_loc (const_rtx);
6379 static int resolve_one_addr (rtx *, void *);
6380 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6381 enum var_init_status);
6382 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6383 enum var_init_status);
6384 static dw_loc_list_ref loc_list_from_tree (tree, int);
6385 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6386 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6387 static tree field_type (const_tree);
6388 static unsigned int simple_type_align_in_bits (const_tree);
6389 static unsigned int simple_decl_align_in_bits (const_tree);
6390 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6391 static HOST_WIDE_INT field_byte_offset (const_tree);
6392 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6394 static void add_data_member_location_attribute (dw_die_ref, tree);
6395 static bool add_const_value_attribute (dw_die_ref, rtx);
6396 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6397 static void insert_double (double_int, unsigned char *);
6398 static void insert_float (const_rtx, unsigned char *);
6399 static rtx rtl_for_decl_location (tree);
6400 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
6401 enum dwarf_attribute);
6402 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6403 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6404 static void add_name_attribute (dw_die_ref, const char *);
6405 static void add_comp_dir_attribute (dw_die_ref);
6406 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6407 static void add_subscript_info (dw_die_ref, tree, bool);
6408 static void add_byte_size_attribute (dw_die_ref, tree);
6409 static void add_bit_offset_attribute (dw_die_ref, tree);
6410 static void add_bit_size_attribute (dw_die_ref, tree);
6411 static void add_prototyped_attribute (dw_die_ref, tree);
6412 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6413 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6414 static void add_src_coords_attributes (dw_die_ref, tree);
6415 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6416 static void push_decl_scope (tree);
6417 static void pop_decl_scope (void);
6418 static dw_die_ref scope_die_for (tree, dw_die_ref);
6419 static inline int local_scope_p (dw_die_ref);
6420 static inline int class_scope_p (dw_die_ref);
6421 static inline int class_or_namespace_scope_p (dw_die_ref);
6422 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6423 static void add_calling_convention_attribute (dw_die_ref, tree);
6424 static const char *type_tag (const_tree);
6425 static tree member_declared_type (const_tree);
6427 static const char *decl_start_label (tree);
6429 static void gen_array_type_die (tree, dw_die_ref);
6430 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6432 static void gen_entry_point_die (tree, dw_die_ref);
6434 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6435 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6436 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6437 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6438 static void gen_formal_types_die (tree, dw_die_ref);
6439 static void gen_subprogram_die (tree, dw_die_ref);
6440 static void gen_variable_die (tree, tree, dw_die_ref);
6441 static void gen_const_die (tree, dw_die_ref);
6442 static void gen_label_die (tree, dw_die_ref);
6443 static void gen_lexical_block_die (tree, dw_die_ref, int);
6444 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6445 static void gen_field_die (tree, dw_die_ref);
6446 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6447 static dw_die_ref gen_compile_unit_die (const char *);
6448 static void gen_inheritance_die (tree, tree, dw_die_ref);
6449 static void gen_member_die (tree, dw_die_ref);
6450 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6451 enum debug_info_usage);
6452 static void gen_subroutine_type_die (tree, dw_die_ref);
6453 static void gen_typedef_die (tree, dw_die_ref);
6454 static void gen_type_die (tree, dw_die_ref);
6455 static void gen_block_die (tree, dw_die_ref, int);
6456 static void decls_for_scope (tree, dw_die_ref, int);
6457 static int is_redundant_typedef (const_tree);
6458 static bool is_naming_typedef_decl (const_tree);
6459 static inline dw_die_ref get_context_die (tree);
6460 static void gen_namespace_die (tree, dw_die_ref);
6461 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6462 static dw_die_ref force_decl_die (tree);
6463 static dw_die_ref force_type_die (tree);
6464 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6465 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6466 static struct dwarf_file_data * lookup_filename (const char *);
6467 static void retry_incomplete_types (void);
6468 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6469 static void gen_generic_params_dies (tree);
6470 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6471 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6472 static void splice_child_die (dw_die_ref, dw_die_ref);
6473 static int file_info_cmp (const void *, const void *);
6474 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6475 const char *, const char *);
6476 static void output_loc_list (dw_loc_list_ref);
6477 static char *gen_internal_sym (const char *);
6479 static void prune_unmark_dies (dw_die_ref);
6480 static void prune_unused_types_mark (dw_die_ref, int);
6481 static void prune_unused_types_walk (dw_die_ref);
6482 static void prune_unused_types_walk_attribs (dw_die_ref);
6483 static void prune_unused_types_prune (dw_die_ref);
6484 static void prune_unused_types (void);
6485 static int maybe_emit_file (struct dwarf_file_data *fd);
6486 static inline const char *AT_vms_delta1 (dw_attr_ref);
6487 static inline const char *AT_vms_delta2 (dw_attr_ref);
6488 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6489 const char *, const char *);
6490 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6491 static void gen_remaining_tmpl_value_param_die_attribute (void);
6493 /* Section names used to hold DWARF debugging information. */
6494 #ifndef DEBUG_INFO_SECTION
6495 #define DEBUG_INFO_SECTION ".debug_info"
6497 #ifndef DEBUG_ABBREV_SECTION
6498 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6500 #ifndef DEBUG_ARANGES_SECTION
6501 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6503 #ifndef DEBUG_MACINFO_SECTION
6504 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6506 #ifndef DEBUG_LINE_SECTION
6507 #define DEBUG_LINE_SECTION ".debug_line"
6509 #ifndef DEBUG_LOC_SECTION
6510 #define DEBUG_LOC_SECTION ".debug_loc"
6512 #ifndef DEBUG_PUBNAMES_SECTION
6513 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6515 #ifndef DEBUG_PUBTYPES_SECTION
6516 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6518 #ifndef DEBUG_DCALL_SECTION
6519 #define DEBUG_DCALL_SECTION ".debug_dcall"
6521 #ifndef DEBUG_VCALL_SECTION
6522 #define DEBUG_VCALL_SECTION ".debug_vcall"
6524 #ifndef DEBUG_STR_SECTION
6525 #define DEBUG_STR_SECTION ".debug_str"
6527 #ifndef DEBUG_RANGES_SECTION
6528 #define DEBUG_RANGES_SECTION ".debug_ranges"
6531 /* Standard ELF section names for compiled code and data. */
6532 #ifndef TEXT_SECTION_NAME
6533 #define TEXT_SECTION_NAME ".text"
6536 /* Section flags for .debug_str section. */
6537 #define DEBUG_STR_SECTION_FLAGS \
6538 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6539 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6542 /* Labels we insert at beginning sections we can reference instead of
6543 the section names themselves. */
6545 #ifndef TEXT_SECTION_LABEL
6546 #define TEXT_SECTION_LABEL "Ltext"
6548 #ifndef COLD_TEXT_SECTION_LABEL
6549 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6551 #ifndef DEBUG_LINE_SECTION_LABEL
6552 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6554 #ifndef DEBUG_INFO_SECTION_LABEL
6555 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6557 #ifndef DEBUG_ABBREV_SECTION_LABEL
6558 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6560 #ifndef DEBUG_LOC_SECTION_LABEL
6561 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6563 #ifndef DEBUG_RANGES_SECTION_LABEL
6564 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6566 #ifndef DEBUG_MACINFO_SECTION_LABEL
6567 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6571 /* Definitions of defaults for formats and names of various special
6572 (artificial) labels which may be generated within this file (when the -g
6573 options is used and DWARF2_DEBUGGING_INFO is in effect.
6574 If necessary, these may be overridden from within the tm.h file, but
6575 typically, overriding these defaults is unnecessary. */
6577 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6578 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6579 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6580 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6581 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6582 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6583 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6584 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6585 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6586 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6588 #ifndef TEXT_END_LABEL
6589 #define TEXT_END_LABEL "Letext"
6591 #ifndef COLD_END_LABEL
6592 #define COLD_END_LABEL "Letext_cold"
6594 #ifndef BLOCK_BEGIN_LABEL
6595 #define BLOCK_BEGIN_LABEL "LBB"
6597 #ifndef BLOCK_END_LABEL
6598 #define BLOCK_END_LABEL "LBE"
6600 #ifndef LINE_CODE_LABEL
6601 #define LINE_CODE_LABEL "LM"
6603 #ifndef SEPARATE_LINE_CODE_LABEL
6604 #define SEPARATE_LINE_CODE_LABEL "LSM"
6608 /* Return the root of the DIE's built for the current compilation unit. */
6610 comp_unit_die (void)
6612 if (!single_comp_unit_die)
6613 single_comp_unit_die = gen_compile_unit_die (NULL);
6614 return single_comp_unit_die;
6617 /* We allow a language front-end to designate a function that is to be
6618 called to "demangle" any name before it is put into a DIE. */
6620 static const char *(*demangle_name_func) (const char *);
6623 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6625 demangle_name_func = func;
6628 /* Test if rtl node points to a pseudo register. */
6631 is_pseudo_reg (const_rtx rtl)
6633 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6634 || (GET_CODE (rtl) == SUBREG
6635 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6638 /* Return a reference to a type, with its const and volatile qualifiers
6642 type_main_variant (tree type)
6644 type = TYPE_MAIN_VARIANT (type);
6646 /* ??? There really should be only one main variant among any group of
6647 variants of a given type (and all of the MAIN_VARIANT values for all
6648 members of the group should point to that one type) but sometimes the C
6649 front-end messes this up for array types, so we work around that bug
6651 if (TREE_CODE (type) == ARRAY_TYPE)
6652 while (type != TYPE_MAIN_VARIANT (type))
6653 type = TYPE_MAIN_VARIANT (type);
6658 /* Return nonzero if the given type node represents a tagged type. */
6661 is_tagged_type (const_tree type)
6663 enum tree_code code = TREE_CODE (type);
6665 return (code == RECORD_TYPE || code == UNION_TYPE
6666 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6669 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6672 get_ref_die_offset_label (char *label, dw_die_ref ref)
6674 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6677 /* Convert a DIE tag into its string name. */
6680 dwarf_tag_name (unsigned int tag)
6684 case DW_TAG_padding:
6685 return "DW_TAG_padding";
6686 case DW_TAG_array_type:
6687 return "DW_TAG_array_type";
6688 case DW_TAG_class_type:
6689 return "DW_TAG_class_type";
6690 case DW_TAG_entry_point:
6691 return "DW_TAG_entry_point";
6692 case DW_TAG_enumeration_type:
6693 return "DW_TAG_enumeration_type";
6694 case DW_TAG_formal_parameter:
6695 return "DW_TAG_formal_parameter";
6696 case DW_TAG_imported_declaration:
6697 return "DW_TAG_imported_declaration";
6699 return "DW_TAG_label";
6700 case DW_TAG_lexical_block:
6701 return "DW_TAG_lexical_block";
6703 return "DW_TAG_member";
6704 case DW_TAG_pointer_type:
6705 return "DW_TAG_pointer_type";
6706 case DW_TAG_reference_type:
6707 return "DW_TAG_reference_type";
6708 case DW_TAG_compile_unit:
6709 return "DW_TAG_compile_unit";
6710 case DW_TAG_string_type:
6711 return "DW_TAG_string_type";
6712 case DW_TAG_structure_type:
6713 return "DW_TAG_structure_type";
6714 case DW_TAG_subroutine_type:
6715 return "DW_TAG_subroutine_type";
6716 case DW_TAG_typedef:
6717 return "DW_TAG_typedef";
6718 case DW_TAG_union_type:
6719 return "DW_TAG_union_type";
6720 case DW_TAG_unspecified_parameters:
6721 return "DW_TAG_unspecified_parameters";
6722 case DW_TAG_variant:
6723 return "DW_TAG_variant";
6724 case DW_TAG_common_block:
6725 return "DW_TAG_common_block";
6726 case DW_TAG_common_inclusion:
6727 return "DW_TAG_common_inclusion";
6728 case DW_TAG_inheritance:
6729 return "DW_TAG_inheritance";
6730 case DW_TAG_inlined_subroutine:
6731 return "DW_TAG_inlined_subroutine";
6733 return "DW_TAG_module";
6734 case DW_TAG_ptr_to_member_type:
6735 return "DW_TAG_ptr_to_member_type";
6736 case DW_TAG_set_type:
6737 return "DW_TAG_set_type";
6738 case DW_TAG_subrange_type:
6739 return "DW_TAG_subrange_type";
6740 case DW_TAG_with_stmt:
6741 return "DW_TAG_with_stmt";
6742 case DW_TAG_access_declaration:
6743 return "DW_TAG_access_declaration";
6744 case DW_TAG_base_type:
6745 return "DW_TAG_base_type";
6746 case DW_TAG_catch_block:
6747 return "DW_TAG_catch_block";
6748 case DW_TAG_const_type:
6749 return "DW_TAG_const_type";
6750 case DW_TAG_constant:
6751 return "DW_TAG_constant";
6752 case DW_TAG_enumerator:
6753 return "DW_TAG_enumerator";
6754 case DW_TAG_file_type:
6755 return "DW_TAG_file_type";
6757 return "DW_TAG_friend";
6758 case DW_TAG_namelist:
6759 return "DW_TAG_namelist";
6760 case DW_TAG_namelist_item:
6761 return "DW_TAG_namelist_item";
6762 case DW_TAG_packed_type:
6763 return "DW_TAG_packed_type";
6764 case DW_TAG_subprogram:
6765 return "DW_TAG_subprogram";
6766 case DW_TAG_template_type_param:
6767 return "DW_TAG_template_type_param";
6768 case DW_TAG_template_value_param:
6769 return "DW_TAG_template_value_param";
6770 case DW_TAG_thrown_type:
6771 return "DW_TAG_thrown_type";
6772 case DW_TAG_try_block:
6773 return "DW_TAG_try_block";
6774 case DW_TAG_variant_part:
6775 return "DW_TAG_variant_part";
6776 case DW_TAG_variable:
6777 return "DW_TAG_variable";
6778 case DW_TAG_volatile_type:
6779 return "DW_TAG_volatile_type";
6780 case DW_TAG_dwarf_procedure:
6781 return "DW_TAG_dwarf_procedure";
6782 case DW_TAG_restrict_type:
6783 return "DW_TAG_restrict_type";
6784 case DW_TAG_interface_type:
6785 return "DW_TAG_interface_type";
6786 case DW_TAG_namespace:
6787 return "DW_TAG_namespace";
6788 case DW_TAG_imported_module:
6789 return "DW_TAG_imported_module";
6790 case DW_TAG_unspecified_type:
6791 return "DW_TAG_unspecified_type";
6792 case DW_TAG_partial_unit:
6793 return "DW_TAG_partial_unit";
6794 case DW_TAG_imported_unit:
6795 return "DW_TAG_imported_unit";
6796 case DW_TAG_condition:
6797 return "DW_TAG_condition";
6798 case DW_TAG_shared_type:
6799 return "DW_TAG_shared_type";
6800 case DW_TAG_type_unit:
6801 return "DW_TAG_type_unit";
6802 case DW_TAG_rvalue_reference_type:
6803 return "DW_TAG_rvalue_reference_type";
6804 case DW_TAG_template_alias:
6805 return "DW_TAG_template_alias";
6806 case DW_TAG_GNU_template_parameter_pack:
6807 return "DW_TAG_GNU_template_parameter_pack";
6808 case DW_TAG_GNU_formal_parameter_pack:
6809 return "DW_TAG_GNU_formal_parameter_pack";
6810 case DW_TAG_MIPS_loop:
6811 return "DW_TAG_MIPS_loop";
6812 case DW_TAG_format_label:
6813 return "DW_TAG_format_label";
6814 case DW_TAG_function_template:
6815 return "DW_TAG_function_template";
6816 case DW_TAG_class_template:
6817 return "DW_TAG_class_template";
6818 case DW_TAG_GNU_BINCL:
6819 return "DW_TAG_GNU_BINCL";
6820 case DW_TAG_GNU_EINCL:
6821 return "DW_TAG_GNU_EINCL";
6822 case DW_TAG_GNU_template_template_param:
6823 return "DW_TAG_GNU_template_template_param";
6825 return "DW_TAG_<unknown>";
6829 /* Convert a DWARF attribute code into its string name. */
6832 dwarf_attr_name (unsigned int attr)
6837 return "DW_AT_sibling";
6838 case DW_AT_location:
6839 return "DW_AT_location";
6841 return "DW_AT_name";
6842 case DW_AT_ordering:
6843 return "DW_AT_ordering";
6844 case DW_AT_subscr_data:
6845 return "DW_AT_subscr_data";
6846 case DW_AT_byte_size:
6847 return "DW_AT_byte_size";
6848 case DW_AT_bit_offset:
6849 return "DW_AT_bit_offset";
6850 case DW_AT_bit_size:
6851 return "DW_AT_bit_size";
6852 case DW_AT_element_list:
6853 return "DW_AT_element_list";
6854 case DW_AT_stmt_list:
6855 return "DW_AT_stmt_list";
6857 return "DW_AT_low_pc";
6859 return "DW_AT_high_pc";
6860 case DW_AT_language:
6861 return "DW_AT_language";
6863 return "DW_AT_member";
6865 return "DW_AT_discr";
6866 case DW_AT_discr_value:
6867 return "DW_AT_discr_value";
6868 case DW_AT_visibility:
6869 return "DW_AT_visibility";
6871 return "DW_AT_import";
6872 case DW_AT_string_length:
6873 return "DW_AT_string_length";
6874 case DW_AT_common_reference:
6875 return "DW_AT_common_reference";
6876 case DW_AT_comp_dir:
6877 return "DW_AT_comp_dir";
6878 case DW_AT_const_value:
6879 return "DW_AT_const_value";
6880 case DW_AT_containing_type:
6881 return "DW_AT_containing_type";
6882 case DW_AT_default_value:
6883 return "DW_AT_default_value";
6885 return "DW_AT_inline";
6886 case DW_AT_is_optional:
6887 return "DW_AT_is_optional";
6888 case DW_AT_lower_bound:
6889 return "DW_AT_lower_bound";
6890 case DW_AT_producer:
6891 return "DW_AT_producer";
6892 case DW_AT_prototyped:
6893 return "DW_AT_prototyped";
6894 case DW_AT_return_addr:
6895 return "DW_AT_return_addr";
6896 case DW_AT_start_scope:
6897 return "DW_AT_start_scope";
6898 case DW_AT_bit_stride:
6899 return "DW_AT_bit_stride";
6900 case DW_AT_upper_bound:
6901 return "DW_AT_upper_bound";
6902 case DW_AT_abstract_origin:
6903 return "DW_AT_abstract_origin";
6904 case DW_AT_accessibility:
6905 return "DW_AT_accessibility";
6906 case DW_AT_address_class:
6907 return "DW_AT_address_class";
6908 case DW_AT_artificial:
6909 return "DW_AT_artificial";
6910 case DW_AT_base_types:
6911 return "DW_AT_base_types";
6912 case DW_AT_calling_convention:
6913 return "DW_AT_calling_convention";
6915 return "DW_AT_count";
6916 case DW_AT_data_member_location:
6917 return "DW_AT_data_member_location";
6918 case DW_AT_decl_column:
6919 return "DW_AT_decl_column";
6920 case DW_AT_decl_file:
6921 return "DW_AT_decl_file";
6922 case DW_AT_decl_line:
6923 return "DW_AT_decl_line";
6924 case DW_AT_declaration:
6925 return "DW_AT_declaration";
6926 case DW_AT_discr_list:
6927 return "DW_AT_discr_list";
6928 case DW_AT_encoding:
6929 return "DW_AT_encoding";
6930 case DW_AT_external:
6931 return "DW_AT_external";
6932 case DW_AT_explicit:
6933 return "DW_AT_explicit";
6934 case DW_AT_frame_base:
6935 return "DW_AT_frame_base";
6937 return "DW_AT_friend";
6938 case DW_AT_identifier_case:
6939 return "DW_AT_identifier_case";
6940 case DW_AT_macro_info:
6941 return "DW_AT_macro_info";
6942 case DW_AT_namelist_items:
6943 return "DW_AT_namelist_items";
6944 case DW_AT_priority:
6945 return "DW_AT_priority";
6947 return "DW_AT_segment";
6948 case DW_AT_specification:
6949 return "DW_AT_specification";
6950 case DW_AT_static_link:
6951 return "DW_AT_static_link";
6953 return "DW_AT_type";
6954 case DW_AT_use_location:
6955 return "DW_AT_use_location";
6956 case DW_AT_variable_parameter:
6957 return "DW_AT_variable_parameter";
6958 case DW_AT_virtuality:
6959 return "DW_AT_virtuality";
6960 case DW_AT_vtable_elem_location:
6961 return "DW_AT_vtable_elem_location";
6963 case DW_AT_allocated:
6964 return "DW_AT_allocated";
6965 case DW_AT_associated:
6966 return "DW_AT_associated";
6967 case DW_AT_data_location:
6968 return "DW_AT_data_location";
6969 case DW_AT_byte_stride:
6970 return "DW_AT_byte_stride";
6971 case DW_AT_entry_pc:
6972 return "DW_AT_entry_pc";
6973 case DW_AT_use_UTF8:
6974 return "DW_AT_use_UTF8";
6975 case DW_AT_extension:
6976 return "DW_AT_extension";
6978 return "DW_AT_ranges";
6979 case DW_AT_trampoline:
6980 return "DW_AT_trampoline";
6981 case DW_AT_call_column:
6982 return "DW_AT_call_column";
6983 case DW_AT_call_file:
6984 return "DW_AT_call_file";
6985 case DW_AT_call_line:
6986 return "DW_AT_call_line";
6987 case DW_AT_object_pointer:
6988 return "DW_AT_object_pointer";
6990 case DW_AT_signature:
6991 return "DW_AT_signature";
6992 case DW_AT_main_subprogram:
6993 return "DW_AT_main_subprogram";
6994 case DW_AT_data_bit_offset:
6995 return "DW_AT_data_bit_offset";
6996 case DW_AT_const_expr:
6997 return "DW_AT_const_expr";
6998 case DW_AT_enum_class:
6999 return "DW_AT_enum_class";
7000 case DW_AT_linkage_name:
7001 return "DW_AT_linkage_name";
7003 case DW_AT_MIPS_fde:
7004 return "DW_AT_MIPS_fde";
7005 case DW_AT_MIPS_loop_begin:
7006 return "DW_AT_MIPS_loop_begin";
7007 case DW_AT_MIPS_tail_loop_begin:
7008 return "DW_AT_MIPS_tail_loop_begin";
7009 case DW_AT_MIPS_epilog_begin:
7010 return "DW_AT_MIPS_epilog_begin";
7011 #if VMS_DEBUGGING_INFO
7012 case DW_AT_HP_prologue:
7013 return "DW_AT_HP_prologue";
7015 case DW_AT_MIPS_loop_unroll_factor:
7016 return "DW_AT_MIPS_loop_unroll_factor";
7018 case DW_AT_MIPS_software_pipeline_depth:
7019 return "DW_AT_MIPS_software_pipeline_depth";
7020 case DW_AT_MIPS_linkage_name:
7021 return "DW_AT_MIPS_linkage_name";
7022 #if VMS_DEBUGGING_INFO
7023 case DW_AT_HP_epilogue:
7024 return "DW_AT_HP_epilogue";
7026 case DW_AT_MIPS_stride:
7027 return "DW_AT_MIPS_stride";
7029 case DW_AT_MIPS_abstract_name:
7030 return "DW_AT_MIPS_abstract_name";
7031 case DW_AT_MIPS_clone_origin:
7032 return "DW_AT_MIPS_clone_origin";
7033 case DW_AT_MIPS_has_inlines:
7034 return "DW_AT_MIPS_has_inlines";
7036 case DW_AT_sf_names:
7037 return "DW_AT_sf_names";
7038 case DW_AT_src_info:
7039 return "DW_AT_src_info";
7040 case DW_AT_mac_info:
7041 return "DW_AT_mac_info";
7042 case DW_AT_src_coords:
7043 return "DW_AT_src_coords";
7044 case DW_AT_body_begin:
7045 return "DW_AT_body_begin";
7046 case DW_AT_body_end:
7047 return "DW_AT_body_end";
7048 case DW_AT_GNU_vector:
7049 return "DW_AT_GNU_vector";
7050 case DW_AT_GNU_guarded_by:
7051 return "DW_AT_GNU_guarded_by";
7052 case DW_AT_GNU_pt_guarded_by:
7053 return "DW_AT_GNU_pt_guarded_by";
7054 case DW_AT_GNU_guarded:
7055 return "DW_AT_GNU_guarded";
7056 case DW_AT_GNU_pt_guarded:
7057 return "DW_AT_GNU_pt_guarded";
7058 case DW_AT_GNU_locks_excluded:
7059 return "DW_AT_GNU_locks_excluded";
7060 case DW_AT_GNU_exclusive_locks_required:
7061 return "DW_AT_GNU_exclusive_locks_required";
7062 case DW_AT_GNU_shared_locks_required:
7063 return "DW_AT_GNU_shared_locks_required";
7064 case DW_AT_GNU_odr_signature:
7065 return "DW_AT_GNU_odr_signature";
7066 case DW_AT_GNU_template_name:
7067 return "DW_AT_GNU_template_name";
7069 case DW_AT_VMS_rtnbeg_pd_address:
7070 return "DW_AT_VMS_rtnbeg_pd_address";
7073 return "DW_AT_<unknown>";
7077 /* Convert a DWARF value form code into its string name. */
7080 dwarf_form_name (unsigned int form)
7085 return "DW_FORM_addr";
7086 case DW_FORM_block2:
7087 return "DW_FORM_block2";
7088 case DW_FORM_block4:
7089 return "DW_FORM_block4";
7091 return "DW_FORM_data2";
7093 return "DW_FORM_data4";
7095 return "DW_FORM_data8";
7096 case DW_FORM_string:
7097 return "DW_FORM_string";
7099 return "DW_FORM_block";
7100 case DW_FORM_block1:
7101 return "DW_FORM_block1";
7103 return "DW_FORM_data1";
7105 return "DW_FORM_flag";
7107 return "DW_FORM_sdata";
7109 return "DW_FORM_strp";
7111 return "DW_FORM_udata";
7112 case DW_FORM_ref_addr:
7113 return "DW_FORM_ref_addr";
7115 return "DW_FORM_ref1";
7117 return "DW_FORM_ref2";
7119 return "DW_FORM_ref4";
7121 return "DW_FORM_ref8";
7122 case DW_FORM_ref_udata:
7123 return "DW_FORM_ref_udata";
7124 case DW_FORM_indirect:
7125 return "DW_FORM_indirect";
7126 case DW_FORM_sec_offset:
7127 return "DW_FORM_sec_offset";
7128 case DW_FORM_exprloc:
7129 return "DW_FORM_exprloc";
7130 case DW_FORM_flag_present:
7131 return "DW_FORM_flag_present";
7132 case DW_FORM_ref_sig8:
7133 return "DW_FORM_ref_sig8";
7135 return "DW_FORM_<unknown>";
7139 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7140 instance of an inlined instance of a decl which is local to an inline
7141 function, so we have to trace all of the way back through the origin chain
7142 to find out what sort of node actually served as the original seed for the
7146 decl_ultimate_origin (const_tree decl)
7148 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7151 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7152 nodes in the function to point to themselves; ignore that if
7153 we're trying to output the abstract instance of this function. */
7154 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7157 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7158 most distant ancestor, this should never happen. */
7159 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7161 return DECL_ABSTRACT_ORIGIN (decl);
7164 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7165 of a virtual function may refer to a base class, so we check the 'this'
7169 decl_class_context (tree decl)
7171 tree context = NULL_TREE;
7173 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7174 context = DECL_CONTEXT (decl);
7176 context = TYPE_MAIN_VARIANT
7177 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7179 if (context && !TYPE_P (context))
7180 context = NULL_TREE;
7185 /* Add an attribute/value pair to a DIE. */
7188 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7190 /* Maybe this should be an assert? */
7194 if (die->die_attr == NULL)
7195 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7196 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7199 static inline enum dw_val_class
7200 AT_class (dw_attr_ref a)
7202 return a->dw_attr_val.val_class;
7205 /* Add a flag value attribute to a DIE. */
7208 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7212 attr.dw_attr = attr_kind;
7213 attr.dw_attr_val.val_class = dw_val_class_flag;
7214 attr.dw_attr_val.v.val_flag = flag;
7215 add_dwarf_attr (die, &attr);
7218 static inline unsigned
7219 AT_flag (dw_attr_ref a)
7221 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7222 return a->dw_attr_val.v.val_flag;
7225 /* Add a signed integer attribute value to a DIE. */
7228 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7232 attr.dw_attr = attr_kind;
7233 attr.dw_attr_val.val_class = dw_val_class_const;
7234 attr.dw_attr_val.v.val_int = int_val;
7235 add_dwarf_attr (die, &attr);
7238 static inline HOST_WIDE_INT
7239 AT_int (dw_attr_ref a)
7241 gcc_assert (a && AT_class (a) == dw_val_class_const);
7242 return a->dw_attr_val.v.val_int;
7245 /* Add an unsigned integer attribute value to a DIE. */
7248 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7249 unsigned HOST_WIDE_INT unsigned_val)
7253 attr.dw_attr = attr_kind;
7254 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7255 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7256 add_dwarf_attr (die, &attr);
7259 static inline unsigned HOST_WIDE_INT
7260 AT_unsigned (dw_attr_ref a)
7262 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7263 return a->dw_attr_val.v.val_unsigned;
7266 /* Add an unsigned double integer attribute value to a DIE. */
7269 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7270 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7274 attr.dw_attr = attr_kind;
7275 attr.dw_attr_val.val_class = dw_val_class_const_double;
7276 attr.dw_attr_val.v.val_double.high = high;
7277 attr.dw_attr_val.v.val_double.low = low;
7278 add_dwarf_attr (die, &attr);
7281 /* Add a floating point attribute value to a DIE and return it. */
7284 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7285 unsigned int length, unsigned int elt_size, unsigned char *array)
7289 attr.dw_attr = attr_kind;
7290 attr.dw_attr_val.val_class = dw_val_class_vec;
7291 attr.dw_attr_val.v.val_vec.length = length;
7292 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7293 attr.dw_attr_val.v.val_vec.array = array;
7294 add_dwarf_attr (die, &attr);
7297 /* Add an 8-byte data attribute value to a DIE. */
7300 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7301 unsigned char data8[8])
7305 attr.dw_attr = attr_kind;
7306 attr.dw_attr_val.val_class = dw_val_class_data8;
7307 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7308 add_dwarf_attr (die, &attr);
7311 /* Hash and equality functions for debug_str_hash. */
7314 debug_str_do_hash (const void *x)
7316 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7320 debug_str_eq (const void *x1, const void *x2)
7322 return strcmp ((((const struct indirect_string_node *)x1)->str),
7323 (const char *)x2) == 0;
7326 /* Add STR to the indirect string hash table. */
7328 static struct indirect_string_node *
7329 find_AT_string (const char *str)
7331 struct indirect_string_node *node;
7334 if (! debug_str_hash)
7335 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7336 debug_str_eq, NULL);
7338 slot = htab_find_slot_with_hash (debug_str_hash, str,
7339 htab_hash_string (str), INSERT);
7342 node = ggc_alloc_cleared_indirect_string_node ();
7343 node->str = ggc_strdup (str);
7347 node = (struct indirect_string_node *) *slot;
7353 /* Add a string attribute value to a DIE. */
7356 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7359 struct indirect_string_node *node;
7361 node = find_AT_string (str);
7363 attr.dw_attr = attr_kind;
7364 attr.dw_attr_val.val_class = dw_val_class_str;
7365 attr.dw_attr_val.v.val_str = node;
7366 add_dwarf_attr (die, &attr);
7369 /* Create a label for an indirect string node, ensuring it is going to
7370 be output, unless its reference count goes down to zero. */
7373 gen_label_for_indirect_string (struct indirect_string_node *node)
7380 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7381 ++dw2_string_counter;
7382 node->label = xstrdup (label);
7385 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7386 debug string STR. */
7389 get_debug_string_label (const char *str)
7391 struct indirect_string_node *node = find_AT_string (str);
7393 debug_str_hash_forced = true;
7395 gen_label_for_indirect_string (node);
7397 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7400 static inline const char *
7401 AT_string (dw_attr_ref a)
7403 gcc_assert (a && AT_class (a) == dw_val_class_str);
7404 return a->dw_attr_val.v.val_str->str;
7407 /* Find out whether a string should be output inline in DIE
7408 or out-of-line in .debug_str section. */
7410 static enum dwarf_form
7411 AT_string_form (dw_attr_ref a)
7413 struct indirect_string_node *node;
7416 gcc_assert (a && AT_class (a) == dw_val_class_str);
7418 node = a->dw_attr_val.v.val_str;
7422 len = strlen (node->str) + 1;
7424 /* If the string is shorter or equal to the size of the reference, it is
7425 always better to put it inline. */
7426 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7427 return node->form = DW_FORM_string;
7429 /* If we cannot expect the linker to merge strings in .debug_str
7430 section, only put it into .debug_str if it is worth even in this
7432 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7433 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7434 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7435 return node->form = DW_FORM_string;
7437 gen_label_for_indirect_string (node);
7439 return node->form = DW_FORM_strp;
7442 /* Add a DIE reference attribute value to a DIE. */
7445 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7449 #ifdef ENABLE_CHECKING
7450 gcc_assert (targ_die != NULL);
7452 /* With LTO we can end up trying to reference something we didn't create
7453 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7454 if (targ_die == NULL)
7458 attr.dw_attr = attr_kind;
7459 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7460 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7461 attr.dw_attr_val.v.val_die_ref.external = 0;
7462 add_dwarf_attr (die, &attr);
7465 /* Add an AT_specification attribute to a DIE, and also make the back
7466 pointer from the specification to the definition. */
7469 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7471 add_AT_die_ref (die, DW_AT_specification, targ_die);
7472 gcc_assert (!targ_die->die_definition);
7473 targ_die->die_definition = die;
7476 static inline dw_die_ref
7477 AT_ref (dw_attr_ref a)
7479 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7480 return a->dw_attr_val.v.val_die_ref.die;
7484 AT_ref_external (dw_attr_ref a)
7486 if (a && AT_class (a) == dw_val_class_die_ref)
7487 return a->dw_attr_val.v.val_die_ref.external;
7493 set_AT_ref_external (dw_attr_ref a, int i)
7495 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7496 a->dw_attr_val.v.val_die_ref.external = i;
7499 /* Add an FDE reference attribute value to a DIE. */
7502 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7506 attr.dw_attr = attr_kind;
7507 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7508 attr.dw_attr_val.v.val_fde_index = targ_fde;
7509 add_dwarf_attr (die, &attr);
7512 /* Add a location description attribute value to a DIE. */
7515 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7519 attr.dw_attr = attr_kind;
7520 attr.dw_attr_val.val_class = dw_val_class_loc;
7521 attr.dw_attr_val.v.val_loc = loc;
7522 add_dwarf_attr (die, &attr);
7525 static inline dw_loc_descr_ref
7526 AT_loc (dw_attr_ref a)
7528 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7529 return a->dw_attr_val.v.val_loc;
7533 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7537 attr.dw_attr = attr_kind;
7538 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7539 attr.dw_attr_val.v.val_loc_list = loc_list;
7540 add_dwarf_attr (die, &attr);
7541 have_location_lists = true;
7544 static inline dw_loc_list_ref
7545 AT_loc_list (dw_attr_ref a)
7547 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7548 return a->dw_attr_val.v.val_loc_list;
7551 static inline dw_loc_list_ref *
7552 AT_loc_list_ptr (dw_attr_ref a)
7554 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7555 return &a->dw_attr_val.v.val_loc_list;
7558 /* Add an address constant attribute value to a DIE. */
7561 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7565 attr.dw_attr = attr_kind;
7566 attr.dw_attr_val.val_class = dw_val_class_addr;
7567 attr.dw_attr_val.v.val_addr = addr;
7568 add_dwarf_attr (die, &attr);
7571 /* Get the RTX from to an address DIE attribute. */
7574 AT_addr (dw_attr_ref a)
7576 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7577 return a->dw_attr_val.v.val_addr;
7580 /* Add a file attribute value to a DIE. */
7583 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7584 struct dwarf_file_data *fd)
7588 attr.dw_attr = attr_kind;
7589 attr.dw_attr_val.val_class = dw_val_class_file;
7590 attr.dw_attr_val.v.val_file = fd;
7591 add_dwarf_attr (die, &attr);
7594 /* Get the dwarf_file_data from a file DIE attribute. */
7596 static inline struct dwarf_file_data *
7597 AT_file (dw_attr_ref a)
7599 gcc_assert (a && AT_class (a) == dw_val_class_file);
7600 return a->dw_attr_val.v.val_file;
7603 /* Add a vms delta attribute value to a DIE. */
7606 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7607 const char *lbl1, const char *lbl2)
7611 attr.dw_attr = attr_kind;
7612 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7613 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7614 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7615 add_dwarf_attr (die, &attr);
7618 /* Add a label identifier attribute value to a DIE. */
7621 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7625 attr.dw_attr = attr_kind;
7626 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7627 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7628 add_dwarf_attr (die, &attr);
7631 /* Add a section offset attribute value to a DIE, an offset into the
7632 debug_line section. */
7635 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7640 attr.dw_attr = attr_kind;
7641 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7642 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7643 add_dwarf_attr (die, &attr);
7646 /* Add a section offset attribute value to a DIE, an offset into the
7647 debug_macinfo section. */
7650 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7655 attr.dw_attr = attr_kind;
7656 attr.dw_attr_val.val_class = dw_val_class_macptr;
7657 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7658 add_dwarf_attr (die, &attr);
7661 /* Add an offset attribute value to a DIE. */
7664 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7665 unsigned HOST_WIDE_INT offset)
7669 attr.dw_attr = attr_kind;
7670 attr.dw_attr_val.val_class = dw_val_class_offset;
7671 attr.dw_attr_val.v.val_offset = offset;
7672 add_dwarf_attr (die, &attr);
7675 /* Add an range_list attribute value to a DIE. */
7678 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7679 long unsigned int offset)
7683 attr.dw_attr = attr_kind;
7684 attr.dw_attr_val.val_class = dw_val_class_range_list;
7685 attr.dw_attr_val.v.val_offset = offset;
7686 add_dwarf_attr (die, &attr);
7689 /* Return the start label of a delta attribute. */
7691 static inline const char *
7692 AT_vms_delta1 (dw_attr_ref a)
7694 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7695 return a->dw_attr_val.v.val_vms_delta.lbl1;
7698 /* Return the end label of a delta attribute. */
7700 static inline const char *
7701 AT_vms_delta2 (dw_attr_ref a)
7703 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7704 return a->dw_attr_val.v.val_vms_delta.lbl2;
7707 static inline const char *
7708 AT_lbl (dw_attr_ref a)
7710 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7711 || AT_class (a) == dw_val_class_lineptr
7712 || AT_class (a) == dw_val_class_macptr));
7713 return a->dw_attr_val.v.val_lbl_id;
7716 /* Get the attribute of type attr_kind. */
7719 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7723 dw_die_ref spec = NULL;
7728 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7729 if (a->dw_attr == attr_kind)
7731 else if (a->dw_attr == DW_AT_specification
7732 || a->dw_attr == DW_AT_abstract_origin)
7736 return get_AT (spec, attr_kind);
7741 /* Return the "low pc" attribute value, typically associated with a subprogram
7742 DIE. Return null if the "low pc" attribute is either not present, or if it
7743 cannot be represented as an assembler label identifier. */
7745 static inline const char *
7746 get_AT_low_pc (dw_die_ref die)
7748 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7750 return a ? AT_lbl (a) : NULL;
7753 /* Return the "high pc" attribute value, typically associated with a subprogram
7754 DIE. Return null if the "high pc" attribute is either not present, or if it
7755 cannot be represented as an assembler label identifier. */
7757 static inline const char *
7758 get_AT_hi_pc (dw_die_ref die)
7760 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7762 return a ? AT_lbl (a) : NULL;
7765 /* Return the value of the string attribute designated by ATTR_KIND, or
7766 NULL if it is not present. */
7768 static inline const char *
7769 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7771 dw_attr_ref a = get_AT (die, attr_kind);
7773 return a ? AT_string (a) : NULL;
7776 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7777 if it is not present. */
7780 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7782 dw_attr_ref a = get_AT (die, attr_kind);
7784 return a ? AT_flag (a) : 0;
7787 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7788 if it is not present. */
7790 static inline unsigned
7791 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7793 dw_attr_ref a = get_AT (die, attr_kind);
7795 return a ? AT_unsigned (a) : 0;
7798 static inline dw_die_ref
7799 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7801 dw_attr_ref a = get_AT (die, attr_kind);
7803 return a ? AT_ref (a) : NULL;
7806 static inline struct dwarf_file_data *
7807 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7809 dw_attr_ref a = get_AT (die, attr_kind);
7811 return a ? AT_file (a) : NULL;
7814 /* Return TRUE if the language is C++. */
7819 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7821 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7824 /* Return TRUE if the language is Fortran. */
7829 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7831 return (lang == DW_LANG_Fortran77
7832 || lang == DW_LANG_Fortran90
7833 || lang == DW_LANG_Fortran95);
7836 /* Return TRUE if the language is Ada. */
7841 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7843 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7846 /* Remove the specified attribute if present. */
7849 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7857 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7858 if (a->dw_attr == attr_kind)
7860 if (AT_class (a) == dw_val_class_str)
7861 if (a->dw_attr_val.v.val_str->refcount)
7862 a->dw_attr_val.v.val_str->refcount--;
7864 /* VEC_ordered_remove should help reduce the number of abbrevs
7866 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7871 /* Remove CHILD from its parent. PREV must have the property that
7872 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7875 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7877 gcc_assert (child->die_parent == prev->die_parent);
7878 gcc_assert (prev->die_sib == child);
7881 gcc_assert (child->die_parent->die_child == child);
7885 prev->die_sib = child->die_sib;
7886 if (child->die_parent->die_child == child)
7887 child->die_parent->die_child = prev;
7890 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
7891 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
7894 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
7896 dw_die_ref parent = old_child->die_parent;
7898 gcc_assert (parent == prev->die_parent);
7899 gcc_assert (prev->die_sib == old_child);
7901 new_child->die_parent = parent;
7902 if (prev == old_child)
7904 gcc_assert (parent->die_child == old_child);
7905 new_child->die_sib = new_child;
7909 prev->die_sib = new_child;
7910 new_child->die_sib = old_child->die_sib;
7912 if (old_child->die_parent->die_child == old_child)
7913 old_child->die_parent->die_child = new_child;
7916 /* Move all children from OLD_PARENT to NEW_PARENT. */
7919 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
7922 new_parent->die_child = old_parent->die_child;
7923 old_parent->die_child = NULL;
7924 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
7927 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7931 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7937 dw_die_ref prev = c;
7939 while (c->die_tag == tag)
7941 remove_child_with_prev (c, prev);
7942 /* Might have removed every child. */
7943 if (c == c->die_sib)
7947 } while (c != die->die_child);
7950 /* Add a CHILD_DIE as the last child of DIE. */
7953 add_child_die (dw_die_ref die, dw_die_ref child_die)
7955 /* FIXME this should probably be an assert. */
7956 if (! die || ! child_die)
7958 gcc_assert (die != child_die);
7960 child_die->die_parent = die;
7963 child_die->die_sib = die->die_child->die_sib;
7964 die->die_child->die_sib = child_die;
7967 child_die->die_sib = child_die;
7968 die->die_child = child_die;
7971 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7972 is the specification, to the end of PARENT's list of children.
7973 This is done by removing and re-adding it. */
7976 splice_child_die (dw_die_ref parent, dw_die_ref child)
7980 /* We want the declaration DIE from inside the class, not the
7981 specification DIE at toplevel. */
7982 if (child->die_parent != parent)
7984 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7990 gcc_assert (child->die_parent == parent
7991 || (child->die_parent
7992 == get_AT_ref (parent, DW_AT_specification)));
7994 for (p = child->die_parent->die_child; ; p = p->die_sib)
7995 if (p->die_sib == child)
7997 remove_child_with_prev (child, p);
8001 add_child_die (parent, child);
8004 /* Return a pointer to a newly created DIE node. */
8006 static inline dw_die_ref
8007 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8009 dw_die_ref die = ggc_alloc_cleared_die_node ();
8011 die->die_tag = tag_value;
8013 if (parent_die != NULL)
8014 add_child_die (parent_die, die);
8017 limbo_die_node *limbo_node;
8019 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8020 limbo_node->die = die;
8021 limbo_node->created_for = t;
8022 limbo_node->next = limbo_die_list;
8023 limbo_die_list = limbo_node;
8029 /* Return the DIE associated with the given type specifier. */
8031 static inline dw_die_ref
8032 lookup_type_die (tree type)
8034 return TYPE_SYMTAB_DIE (type);
8037 /* Like lookup_type_die, but if type is an anonymous type named by a
8038 typedef[1], return the DIE of the anonymous type instead the one of
8039 the naming typedef. This is because in gen_typedef_die, we did
8040 equate the anonymous struct named by the typedef with the DIE of
8041 the naming typedef. So by default, lookup_type_die on an anonymous
8042 struct yields the DIE of the naming typedef.
8044 [1]: Read the comment of is_naming_typedef_decl to learn about what
8045 a naming typedef is. */
8047 static inline dw_die_ref
8048 lookup_type_die_strip_naming_typedef (tree type)
8050 dw_die_ref die = lookup_type_die (type);
8051 if (TREE_CODE (type) == RECORD_TYPE
8052 && die->die_tag == DW_TAG_typedef
8053 && is_naming_typedef_decl (TYPE_NAME (type)))
8054 die = get_AT_ref (die, DW_AT_type);
8058 /* Equate a DIE to a given type specifier. */
8061 equate_type_number_to_die (tree type, dw_die_ref type_die)
8063 TYPE_SYMTAB_DIE (type) = type_die;
8066 /* Returns a hash value for X (which really is a die_struct). */
8069 decl_die_table_hash (const void *x)
8071 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8074 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8077 decl_die_table_eq (const void *x, const void *y)
8079 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8082 /* Return the DIE associated with a given declaration. */
8084 static inline dw_die_ref
8085 lookup_decl_die (tree decl)
8087 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8090 /* Returns a hash value for X (which really is a var_loc_list). */
8093 decl_loc_table_hash (const void *x)
8095 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8098 /* Return nonzero if decl_id of var_loc_list X is the same as
8102 decl_loc_table_eq (const void *x, const void *y)
8104 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8107 /* Return the var_loc list associated with a given declaration. */
8109 static inline var_loc_list *
8110 lookup_decl_loc (const_tree decl)
8112 if (!decl_loc_table)
8114 return (var_loc_list *)
8115 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8118 /* Equate a DIE to a particular declaration. */
8121 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8123 unsigned int decl_id = DECL_UID (decl);
8126 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8128 decl_die->decl_id = decl_id;
8131 /* Return how many bits covers PIECE EXPR_LIST. */
8134 decl_piece_bitsize (rtx piece)
8136 int ret = (int) GET_MODE (piece);
8139 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8140 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8141 return INTVAL (XEXP (XEXP (piece, 0), 0));
8144 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8147 decl_piece_varloc_ptr (rtx piece)
8149 if ((int) GET_MODE (piece))
8150 return &XEXP (piece, 0);
8152 return &XEXP (XEXP (piece, 0), 1);
8155 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8156 Next is the chain of following piece nodes. */
8159 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8161 if (bitsize <= (int) MAX_MACHINE_MODE)
8162 return alloc_EXPR_LIST (bitsize, loc_note, next);
8164 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8169 /* Return rtx that should be stored into loc field for
8170 LOC_NOTE and BITPOS/BITSIZE. */
8173 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8174 HOST_WIDE_INT bitsize)
8178 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8180 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8185 /* This function either modifies location piece list *DEST in
8186 place (if SRC and INNER is NULL), or copies location piece list
8187 *SRC to *DEST while modifying it. Location BITPOS is modified
8188 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8189 not copied and if needed some padding around it is added.
8190 When modifying in place, DEST should point to EXPR_LIST where
8191 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8192 to the start of the whole list and INNER points to the EXPR_LIST
8193 where earlier pieces cover PIECE_BITPOS bits. */
8196 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8197 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8198 HOST_WIDE_INT bitsize, rtx loc_note)
8201 bool copy = inner != NULL;
8205 /* First copy all nodes preceeding the current bitpos. */
8206 while (src != inner)
8208 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8209 decl_piece_bitsize (*src), NULL_RTX);
8210 dest = &XEXP (*dest, 1);
8211 src = &XEXP (*src, 1);
8214 /* Add padding if needed. */
8215 if (bitpos != piece_bitpos)
8217 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8218 copy ? NULL_RTX : *dest);
8219 dest = &XEXP (*dest, 1);
8221 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8224 /* A piece with correct bitpos and bitsize already exist,
8225 just update the location for it and return. */
8226 *decl_piece_varloc_ptr (*dest) = loc_note;
8229 /* Add the piece that changed. */
8230 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8231 dest = &XEXP (*dest, 1);
8232 /* Skip over pieces that overlap it. */
8233 diff = bitpos - piece_bitpos + bitsize;
8236 while (diff > 0 && *src)
8239 diff -= decl_piece_bitsize (piece);
8241 src = &XEXP (piece, 1);
8244 *src = XEXP (piece, 1);
8245 free_EXPR_LIST_node (piece);
8248 /* Add padding if needed. */
8249 if (diff < 0 && *src)
8253 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8254 dest = &XEXP (*dest, 1);
8258 /* Finally copy all nodes following it. */
8261 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8262 decl_piece_bitsize (*src), NULL_RTX);
8263 dest = &XEXP (*dest, 1);
8264 src = &XEXP (*src, 1);
8268 /* Add a variable location node to the linked list for DECL. */
8270 static struct var_loc_node *
8271 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8273 unsigned int decl_id;
8276 struct var_loc_node *loc = NULL;
8277 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8279 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8281 tree realdecl = DECL_DEBUG_EXPR (decl);
8282 if (realdecl && handled_component_p (realdecl))
8284 HOST_WIDE_INT maxsize;
8287 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8288 if (!DECL_P (innerdecl)
8289 || DECL_IGNORED_P (innerdecl)
8290 || TREE_STATIC (innerdecl)
8292 || bitpos + bitsize > 256
8293 || bitsize != maxsize)
8299 decl_id = DECL_UID (decl);
8300 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8303 temp = ggc_alloc_cleared_var_loc_list ();
8304 temp->decl_id = decl_id;
8308 temp = (var_loc_list *) *slot;
8312 struct var_loc_node *last = temp->last, *unused = NULL;
8313 rtx *piece_loc = NULL, last_loc_note;
8314 int piece_bitpos = 0;
8318 gcc_assert (last->next == NULL);
8320 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8322 piece_loc = &last->loc;
8325 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8326 if (piece_bitpos + cur_bitsize > bitpos)
8328 piece_bitpos += cur_bitsize;
8329 piece_loc = &XEXP (*piece_loc, 1);
8333 /* TEMP->LAST here is either pointer to the last but one or
8334 last element in the chained list, LAST is pointer to the
8336 if (label && strcmp (last->label, label) == 0)
8338 /* For SRA optimized variables if there weren't any real
8339 insns since last note, just modify the last node. */
8340 if (piece_loc != NULL)
8342 adjust_piece_list (piece_loc, NULL, NULL,
8343 bitpos, piece_bitpos, bitsize, loc_note);
8346 /* If the last note doesn't cover any instructions, remove it. */
8347 if (temp->last != last)
8349 temp->last->next = NULL;
8352 gcc_assert (strcmp (last->label, label) != 0);
8356 gcc_assert (temp->first == temp->last);
8357 memset (temp->last, '\0', sizeof (*temp->last));
8358 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8362 if (bitsize == -1 && NOTE_P (last->loc))
8363 last_loc_note = last->loc;
8364 else if (piece_loc != NULL
8365 && *piece_loc != NULL_RTX
8366 && piece_bitpos == bitpos
8367 && decl_piece_bitsize (*piece_loc) == bitsize)
8368 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8370 last_loc_note = NULL_RTX;
8371 /* If the current location is the same as the end of the list,
8372 and either both or neither of the locations is uninitialized,
8373 we have nothing to do. */
8374 if (last_loc_note == NULL_RTX
8375 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8376 NOTE_VAR_LOCATION_LOC (loc_note)))
8377 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8378 != NOTE_VAR_LOCATION_STATUS (loc_note))
8379 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8380 == VAR_INIT_STATUS_UNINITIALIZED)
8381 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8382 == VAR_INIT_STATUS_UNINITIALIZED))))
8384 /* Add LOC to the end of list and update LAST. If the last
8385 element of the list has been removed above, reuse its
8386 memory for the new node, otherwise allocate a new one. */
8390 memset (loc, '\0', sizeof (*loc));
8393 loc = ggc_alloc_cleared_var_loc_node ();
8394 if (bitsize == -1 || piece_loc == NULL)
8395 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8397 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8398 bitpos, piece_bitpos, bitsize, loc_note);
8400 /* Ensure TEMP->LAST will point either to the new last but one
8401 element of the chain, or to the last element in it. */
8402 if (last != temp->last)
8410 loc = ggc_alloc_cleared_var_loc_node ();
8413 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8418 /* Keep track of the number of spaces used to indent the
8419 output of the debugging routines that print the structure of
8420 the DIE internal representation. */
8421 static int print_indent;
8423 /* Indent the line the number of spaces given by print_indent. */
8426 print_spaces (FILE *outfile)
8428 fprintf (outfile, "%*s", print_indent, "");
8431 /* Print a type signature in hex. */
8434 print_signature (FILE *outfile, char *sig)
8438 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8439 fprintf (outfile, "%02x", sig[i] & 0xff);
8442 /* Print the information associated with a given DIE, and its children.
8443 This routine is a debugging aid only. */
8446 print_die (dw_die_ref die, FILE *outfile)
8452 print_spaces (outfile);
8453 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8454 die->die_offset, dwarf_tag_name (die->die_tag),
8456 print_spaces (outfile);
8457 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8458 fprintf (outfile, " offset: %ld", die->die_offset);
8459 fprintf (outfile, " mark: %d\n", die->die_mark);
8461 if (dwarf_version >= 4 && die->die_id.die_type_node)
8463 print_spaces (outfile);
8464 fprintf (outfile, " signature: ");
8465 print_signature (outfile, die->die_id.die_type_node->signature);
8466 fprintf (outfile, "\n");
8469 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8471 print_spaces (outfile);
8472 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8474 switch (AT_class (a))
8476 case dw_val_class_addr:
8477 fprintf (outfile, "address");
8479 case dw_val_class_offset:
8480 fprintf (outfile, "offset");
8482 case dw_val_class_loc:
8483 fprintf (outfile, "location descriptor");
8485 case dw_val_class_loc_list:
8486 fprintf (outfile, "location list -> label:%s",
8487 AT_loc_list (a)->ll_symbol);
8489 case dw_val_class_range_list:
8490 fprintf (outfile, "range list");
8492 case dw_val_class_const:
8493 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8495 case dw_val_class_unsigned_const:
8496 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8498 case dw_val_class_const_double:
8499 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8500 HOST_WIDE_INT_PRINT_UNSIGNED")",
8501 a->dw_attr_val.v.val_double.high,
8502 a->dw_attr_val.v.val_double.low);
8504 case dw_val_class_vec:
8505 fprintf (outfile, "floating-point or vector constant");
8507 case dw_val_class_flag:
8508 fprintf (outfile, "%u", AT_flag (a));
8510 case dw_val_class_die_ref:
8511 if (AT_ref (a) != NULL)
8513 if (dwarf_version >= 4 && AT_ref (a)->die_id.die_type_node)
8515 fprintf (outfile, "die -> signature: ");
8516 print_signature (outfile,
8517 AT_ref (a)->die_id.die_type_node->signature);
8519 else if (dwarf_version < 4 && AT_ref (a)->die_id.die_symbol)
8520 fprintf (outfile, "die -> label: %s",
8521 AT_ref (a)->die_id.die_symbol);
8523 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8524 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8527 fprintf (outfile, "die -> <null>");
8529 case dw_val_class_vms_delta:
8530 fprintf (outfile, "delta: @slotcount(%s-%s)",
8531 AT_vms_delta2 (a), AT_vms_delta1 (a));
8533 case dw_val_class_lbl_id:
8534 case dw_val_class_lineptr:
8535 case dw_val_class_macptr:
8536 fprintf (outfile, "label: %s", AT_lbl (a));
8538 case dw_val_class_str:
8539 if (AT_string (a) != NULL)
8540 fprintf (outfile, "\"%s\"", AT_string (a));
8542 fprintf (outfile, "<null>");
8544 case dw_val_class_file:
8545 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8546 AT_file (a)->emitted_number);
8548 case dw_val_class_data8:
8552 for (i = 0; i < 8; i++)
8553 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8560 fprintf (outfile, "\n");
8563 if (die->die_child != NULL)
8566 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8569 if (print_indent == 0)
8570 fprintf (outfile, "\n");
8573 /* Print the contents of the source code line number correspondence table.
8574 This routine is a debugging aid only. */
8577 print_dwarf_line_table (FILE *outfile)
8580 dw_line_info_ref line_info;
8582 fprintf (outfile, "\n\nDWARF source line information\n");
8583 for (i = 1; i < line_info_table_in_use; i++)
8585 line_info = &line_info_table[i];
8586 fprintf (outfile, "%5d: %4ld %6ld\n", i,
8587 line_info->dw_file_num,
8588 line_info->dw_line_num);
8591 fprintf (outfile, "\n\n");
8594 /* Print the information collected for a given DIE. */
8597 debug_dwarf_die (dw_die_ref die)
8599 print_die (die, stderr);
8602 /* Print all DWARF information collected for the compilation unit.
8603 This routine is a debugging aid only. */
8609 print_die (comp_unit_die (), stderr);
8610 if (! DWARF2_ASM_LINE_DEBUG_INFO)
8611 print_dwarf_line_table (stderr);
8614 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8615 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8616 DIE that marks the start of the DIEs for this include file. */
8619 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8621 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8622 dw_die_ref new_unit = gen_compile_unit_die (filename);
8624 new_unit->die_sib = old_unit;
8628 /* Close an include-file CU and reopen the enclosing one. */
8631 pop_compile_unit (dw_die_ref old_unit)
8633 dw_die_ref new_unit = old_unit->die_sib;
8635 old_unit->die_sib = NULL;
8639 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8640 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8642 /* Calculate the checksum of a location expression. */
8645 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8649 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8651 CHECKSUM (loc->dw_loc_oprnd1);
8652 CHECKSUM (loc->dw_loc_oprnd2);
8655 /* Calculate the checksum of an attribute. */
8658 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8660 dw_loc_descr_ref loc;
8663 CHECKSUM (at->dw_attr);
8665 /* We don't care that this was compiled with a different compiler
8666 snapshot; if the output is the same, that's what matters. */
8667 if (at->dw_attr == DW_AT_producer)
8670 switch (AT_class (at))
8672 case dw_val_class_const:
8673 CHECKSUM (at->dw_attr_val.v.val_int);
8675 case dw_val_class_unsigned_const:
8676 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8678 case dw_val_class_const_double:
8679 CHECKSUM (at->dw_attr_val.v.val_double);
8681 case dw_val_class_vec:
8682 CHECKSUM (at->dw_attr_val.v.val_vec);
8684 case dw_val_class_flag:
8685 CHECKSUM (at->dw_attr_val.v.val_flag);
8687 case dw_val_class_str:
8688 CHECKSUM_STRING (AT_string (at));
8691 case dw_val_class_addr:
8693 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8694 CHECKSUM_STRING (XSTR (r, 0));
8697 case dw_val_class_offset:
8698 CHECKSUM (at->dw_attr_val.v.val_offset);
8701 case dw_val_class_loc:
8702 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8703 loc_checksum (loc, ctx);
8706 case dw_val_class_die_ref:
8707 die_checksum (AT_ref (at), ctx, mark);
8710 case dw_val_class_fde_ref:
8711 case dw_val_class_vms_delta:
8712 case dw_val_class_lbl_id:
8713 case dw_val_class_lineptr:
8714 case dw_val_class_macptr:
8717 case dw_val_class_file:
8718 CHECKSUM_STRING (AT_file (at)->filename);
8721 case dw_val_class_data8:
8722 CHECKSUM (at->dw_attr_val.v.val_data8);
8730 /* Calculate the checksum of a DIE. */
8733 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8739 /* To avoid infinite recursion. */
8742 CHECKSUM (die->die_mark);
8745 die->die_mark = ++(*mark);
8747 CHECKSUM (die->die_tag);
8749 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8750 attr_checksum (a, ctx, mark);
8752 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8756 #undef CHECKSUM_STRING
8758 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8759 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8760 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8761 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8762 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8763 #define CHECKSUM_ATTR(FOO) \
8764 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8766 /* Calculate the checksum of a number in signed LEB128 format. */
8769 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8776 byte = (value & 0x7f);
8778 more = !((value == 0 && (byte & 0x40) == 0)
8779 || (value == -1 && (byte & 0x40) != 0));
8788 /* Calculate the checksum of a number in unsigned LEB128 format. */
8791 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8795 unsigned char byte = (value & 0x7f);
8798 /* More bytes to follow. */
8806 /* Checksum the context of the DIE. This adds the names of any
8807 surrounding namespaces or structures to the checksum. */
8810 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8814 int tag = die->die_tag;
8816 if (tag != DW_TAG_namespace
8817 && tag != DW_TAG_structure_type
8818 && tag != DW_TAG_class_type)
8821 name = get_AT_string (die, DW_AT_name);
8823 spec = get_AT_ref (die, DW_AT_specification);
8827 if (die->die_parent != NULL)
8828 checksum_die_context (die->die_parent, ctx);
8830 CHECKSUM_ULEB128 ('C');
8831 CHECKSUM_ULEB128 (tag);
8833 CHECKSUM_STRING (name);
8836 /* Calculate the checksum of a location expression. */
8839 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8841 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8842 were emitted as a DW_FORM_sdata instead of a location expression. */
8843 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8845 CHECKSUM_ULEB128 (DW_FORM_sdata);
8846 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8850 /* Otherwise, just checksum the raw location expression. */
8853 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8854 CHECKSUM (loc->dw_loc_oprnd1);
8855 CHECKSUM (loc->dw_loc_oprnd2);
8856 loc = loc->dw_loc_next;
8860 /* Calculate the checksum of an attribute. */
8863 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8864 struct md5_ctx *ctx, int *mark)
8866 dw_loc_descr_ref loc;
8869 if (AT_class (at) == dw_val_class_die_ref)
8871 dw_die_ref target_die = AT_ref (at);
8873 /* For pointer and reference types, we checksum only the (qualified)
8874 name of the target type (if there is a name). For friend entries,
8875 we checksum only the (qualified) name of the target type or function.
8876 This allows the checksum to remain the same whether the target type
8877 is complete or not. */
8878 if ((at->dw_attr == DW_AT_type
8879 && (tag == DW_TAG_pointer_type
8880 || tag == DW_TAG_reference_type
8881 || tag == DW_TAG_rvalue_reference_type
8882 || tag == DW_TAG_ptr_to_member_type))
8883 || (at->dw_attr == DW_AT_friend
8884 && tag == DW_TAG_friend))
8886 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
8888 if (name_attr != NULL)
8890 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8894 CHECKSUM_ULEB128 ('N');
8895 CHECKSUM_ULEB128 (at->dw_attr);
8896 if (decl->die_parent != NULL)
8897 checksum_die_context (decl->die_parent, ctx);
8898 CHECKSUM_ULEB128 ('E');
8899 CHECKSUM_STRING (AT_string (name_attr));
8904 /* For all other references to another DIE, we check to see if the
8905 target DIE has already been visited. If it has, we emit a
8906 backward reference; if not, we descend recursively. */
8907 if (target_die->die_mark > 0)
8909 CHECKSUM_ULEB128 ('R');
8910 CHECKSUM_ULEB128 (at->dw_attr);
8911 CHECKSUM_ULEB128 (target_die->die_mark);
8915 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
8919 target_die->die_mark = ++(*mark);
8920 CHECKSUM_ULEB128 ('T');
8921 CHECKSUM_ULEB128 (at->dw_attr);
8922 if (decl->die_parent != NULL)
8923 checksum_die_context (decl->die_parent, ctx);
8924 die_checksum_ordered (target_die, ctx, mark);
8929 CHECKSUM_ULEB128 ('A');
8930 CHECKSUM_ULEB128 (at->dw_attr);
8932 switch (AT_class (at))
8934 case dw_val_class_const:
8935 CHECKSUM_ULEB128 (DW_FORM_sdata);
8936 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
8939 case dw_val_class_unsigned_const:
8940 CHECKSUM_ULEB128 (DW_FORM_sdata);
8941 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
8944 case dw_val_class_const_double:
8945 CHECKSUM_ULEB128 (DW_FORM_block);
8946 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
8947 CHECKSUM (at->dw_attr_val.v.val_double);
8950 case dw_val_class_vec:
8951 CHECKSUM_ULEB128 (DW_FORM_block);
8952 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
8953 CHECKSUM (at->dw_attr_val.v.val_vec);
8956 case dw_val_class_flag:
8957 CHECKSUM_ULEB128 (DW_FORM_flag);
8958 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
8961 case dw_val_class_str:
8962 CHECKSUM_ULEB128 (DW_FORM_string);
8963 CHECKSUM_STRING (AT_string (at));
8966 case dw_val_class_addr:
8968 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8969 CHECKSUM_ULEB128 (DW_FORM_string);
8970 CHECKSUM_STRING (XSTR (r, 0));
8973 case dw_val_class_offset:
8974 CHECKSUM_ULEB128 (DW_FORM_sdata);
8975 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
8978 case dw_val_class_loc:
8979 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8980 loc_checksum_ordered (loc, ctx);
8983 case dw_val_class_fde_ref:
8984 case dw_val_class_lbl_id:
8985 case dw_val_class_lineptr:
8986 case dw_val_class_macptr:
8989 case dw_val_class_file:
8990 CHECKSUM_ULEB128 (DW_FORM_string);
8991 CHECKSUM_STRING (AT_file (at)->filename);
8994 case dw_val_class_data8:
8995 CHECKSUM (at->dw_attr_val.v.val_data8);
9003 struct checksum_attributes
9005 dw_attr_ref at_name;
9006 dw_attr_ref at_type;
9007 dw_attr_ref at_friend;
9008 dw_attr_ref at_accessibility;
9009 dw_attr_ref at_address_class;
9010 dw_attr_ref at_allocated;
9011 dw_attr_ref at_artificial;
9012 dw_attr_ref at_associated;
9013 dw_attr_ref at_binary_scale;
9014 dw_attr_ref at_bit_offset;
9015 dw_attr_ref at_bit_size;
9016 dw_attr_ref at_bit_stride;
9017 dw_attr_ref at_byte_size;
9018 dw_attr_ref at_byte_stride;
9019 dw_attr_ref at_const_value;
9020 dw_attr_ref at_containing_type;
9021 dw_attr_ref at_count;
9022 dw_attr_ref at_data_location;
9023 dw_attr_ref at_data_member_location;
9024 dw_attr_ref at_decimal_scale;
9025 dw_attr_ref at_decimal_sign;
9026 dw_attr_ref at_default_value;
9027 dw_attr_ref at_digit_count;
9028 dw_attr_ref at_discr;
9029 dw_attr_ref at_discr_list;
9030 dw_attr_ref at_discr_value;
9031 dw_attr_ref at_encoding;
9032 dw_attr_ref at_endianity;
9033 dw_attr_ref at_explicit;
9034 dw_attr_ref at_is_optional;
9035 dw_attr_ref at_location;
9036 dw_attr_ref at_lower_bound;
9037 dw_attr_ref at_mutable;
9038 dw_attr_ref at_ordering;
9039 dw_attr_ref at_picture_string;
9040 dw_attr_ref at_prototyped;
9041 dw_attr_ref at_small;
9042 dw_attr_ref at_segment;
9043 dw_attr_ref at_string_length;
9044 dw_attr_ref at_threads_scaled;
9045 dw_attr_ref at_upper_bound;
9046 dw_attr_ref at_use_location;
9047 dw_attr_ref at_use_UTF8;
9048 dw_attr_ref at_variable_parameter;
9049 dw_attr_ref at_virtuality;
9050 dw_attr_ref at_visibility;
9051 dw_attr_ref at_vtable_elem_location;
9054 /* Collect the attributes that we will want to use for the checksum. */
9057 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9062 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9073 attrs->at_friend = a;
9075 case DW_AT_accessibility:
9076 attrs->at_accessibility = a;
9078 case DW_AT_address_class:
9079 attrs->at_address_class = a;
9081 case DW_AT_allocated:
9082 attrs->at_allocated = a;
9084 case DW_AT_artificial:
9085 attrs->at_artificial = a;
9087 case DW_AT_associated:
9088 attrs->at_associated = a;
9090 case DW_AT_binary_scale:
9091 attrs->at_binary_scale = a;
9093 case DW_AT_bit_offset:
9094 attrs->at_bit_offset = a;
9096 case DW_AT_bit_size:
9097 attrs->at_bit_size = a;
9099 case DW_AT_bit_stride:
9100 attrs->at_bit_stride = a;
9102 case DW_AT_byte_size:
9103 attrs->at_byte_size = a;
9105 case DW_AT_byte_stride:
9106 attrs->at_byte_stride = a;
9108 case DW_AT_const_value:
9109 attrs->at_const_value = a;
9111 case DW_AT_containing_type:
9112 attrs->at_containing_type = a;
9115 attrs->at_count = a;
9117 case DW_AT_data_location:
9118 attrs->at_data_location = a;
9120 case DW_AT_data_member_location:
9121 attrs->at_data_member_location = a;
9123 case DW_AT_decimal_scale:
9124 attrs->at_decimal_scale = a;
9126 case DW_AT_decimal_sign:
9127 attrs->at_decimal_sign = a;
9129 case DW_AT_default_value:
9130 attrs->at_default_value = a;
9132 case DW_AT_digit_count:
9133 attrs->at_digit_count = a;
9136 attrs->at_discr = a;
9138 case DW_AT_discr_list:
9139 attrs->at_discr_list = a;
9141 case DW_AT_discr_value:
9142 attrs->at_discr_value = a;
9144 case DW_AT_encoding:
9145 attrs->at_encoding = a;
9147 case DW_AT_endianity:
9148 attrs->at_endianity = a;
9150 case DW_AT_explicit:
9151 attrs->at_explicit = a;
9153 case DW_AT_is_optional:
9154 attrs->at_is_optional = a;
9156 case DW_AT_location:
9157 attrs->at_location = a;
9159 case DW_AT_lower_bound:
9160 attrs->at_lower_bound = a;
9163 attrs->at_mutable = a;
9165 case DW_AT_ordering:
9166 attrs->at_ordering = a;
9168 case DW_AT_picture_string:
9169 attrs->at_picture_string = a;
9171 case DW_AT_prototyped:
9172 attrs->at_prototyped = a;
9175 attrs->at_small = a;
9178 attrs->at_segment = a;
9180 case DW_AT_string_length:
9181 attrs->at_string_length = a;
9183 case DW_AT_threads_scaled:
9184 attrs->at_threads_scaled = a;
9186 case DW_AT_upper_bound:
9187 attrs->at_upper_bound = a;
9189 case DW_AT_use_location:
9190 attrs->at_use_location = a;
9192 case DW_AT_use_UTF8:
9193 attrs->at_use_UTF8 = a;
9195 case DW_AT_variable_parameter:
9196 attrs->at_variable_parameter = a;
9198 case DW_AT_virtuality:
9199 attrs->at_virtuality = a;
9201 case DW_AT_visibility:
9202 attrs->at_visibility = a;
9204 case DW_AT_vtable_elem_location:
9205 attrs->at_vtable_elem_location = a;
9213 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9216 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9220 struct checksum_attributes attrs;
9222 CHECKSUM_ULEB128 ('D');
9223 CHECKSUM_ULEB128 (die->die_tag);
9225 memset (&attrs, 0, sizeof (attrs));
9227 decl = get_AT_ref (die, DW_AT_specification);
9229 collect_checksum_attributes (&attrs, decl);
9230 collect_checksum_attributes (&attrs, die);
9232 CHECKSUM_ATTR (attrs.at_name);
9233 CHECKSUM_ATTR (attrs.at_accessibility);
9234 CHECKSUM_ATTR (attrs.at_address_class);
9235 CHECKSUM_ATTR (attrs.at_allocated);
9236 CHECKSUM_ATTR (attrs.at_artificial);
9237 CHECKSUM_ATTR (attrs.at_associated);
9238 CHECKSUM_ATTR (attrs.at_binary_scale);
9239 CHECKSUM_ATTR (attrs.at_bit_offset);
9240 CHECKSUM_ATTR (attrs.at_bit_size);
9241 CHECKSUM_ATTR (attrs.at_bit_stride);
9242 CHECKSUM_ATTR (attrs.at_byte_size);
9243 CHECKSUM_ATTR (attrs.at_byte_stride);
9244 CHECKSUM_ATTR (attrs.at_const_value);
9245 CHECKSUM_ATTR (attrs.at_containing_type);
9246 CHECKSUM_ATTR (attrs.at_count);
9247 CHECKSUM_ATTR (attrs.at_data_location);
9248 CHECKSUM_ATTR (attrs.at_data_member_location);
9249 CHECKSUM_ATTR (attrs.at_decimal_scale);
9250 CHECKSUM_ATTR (attrs.at_decimal_sign);
9251 CHECKSUM_ATTR (attrs.at_default_value);
9252 CHECKSUM_ATTR (attrs.at_digit_count);
9253 CHECKSUM_ATTR (attrs.at_discr);
9254 CHECKSUM_ATTR (attrs.at_discr_list);
9255 CHECKSUM_ATTR (attrs.at_discr_value);
9256 CHECKSUM_ATTR (attrs.at_encoding);
9257 CHECKSUM_ATTR (attrs.at_endianity);
9258 CHECKSUM_ATTR (attrs.at_explicit);
9259 CHECKSUM_ATTR (attrs.at_is_optional);
9260 CHECKSUM_ATTR (attrs.at_location);
9261 CHECKSUM_ATTR (attrs.at_lower_bound);
9262 CHECKSUM_ATTR (attrs.at_mutable);
9263 CHECKSUM_ATTR (attrs.at_ordering);
9264 CHECKSUM_ATTR (attrs.at_picture_string);
9265 CHECKSUM_ATTR (attrs.at_prototyped);
9266 CHECKSUM_ATTR (attrs.at_small);
9267 CHECKSUM_ATTR (attrs.at_segment);
9268 CHECKSUM_ATTR (attrs.at_string_length);
9269 CHECKSUM_ATTR (attrs.at_threads_scaled);
9270 CHECKSUM_ATTR (attrs.at_upper_bound);
9271 CHECKSUM_ATTR (attrs.at_use_location);
9272 CHECKSUM_ATTR (attrs.at_use_UTF8);
9273 CHECKSUM_ATTR (attrs.at_variable_parameter);
9274 CHECKSUM_ATTR (attrs.at_virtuality);
9275 CHECKSUM_ATTR (attrs.at_visibility);
9276 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9277 CHECKSUM_ATTR (attrs.at_type);
9278 CHECKSUM_ATTR (attrs.at_friend);
9280 /* Checksum the child DIEs, except for nested types and member functions. */
9283 dw_attr_ref name_attr;
9286 name_attr = get_AT (c, DW_AT_name);
9287 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9288 && name_attr != NULL)
9290 CHECKSUM_ULEB128 ('S');
9291 CHECKSUM_ULEB128 (c->die_tag);
9292 CHECKSUM_STRING (AT_string (name_attr));
9296 /* Mark this DIE so it gets processed when unmarking. */
9297 if (c->die_mark == 0)
9299 die_checksum_ordered (c, ctx, mark);
9301 } while (c != die->die_child);
9303 CHECKSUM_ULEB128 (0);
9307 #undef CHECKSUM_STRING
9308 #undef CHECKSUM_ATTR
9309 #undef CHECKSUM_LEB128
9310 #undef CHECKSUM_ULEB128
9312 /* Generate the type signature for DIE. This is computed by generating an
9313 MD5 checksum over the DIE's tag, its relevant attributes, and its
9314 children. Attributes that are references to other DIEs are processed
9315 by recursion, using the MARK field to prevent infinite recursion.
9316 If the DIE is nested inside a namespace or another type, we also
9317 need to include that context in the signature. The lower 64 bits
9318 of the resulting MD5 checksum comprise the signature. */
9321 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9325 unsigned char checksum[16];
9329 name = get_AT_string (die, DW_AT_name);
9330 decl = get_AT_ref (die, DW_AT_specification);
9332 /* First, compute a signature for just the type name (and its surrounding
9333 context, if any. This is stored in the type unit DIE for link-time
9334 ODR (one-definition rule) checking. */
9336 if (is_cxx() && name != NULL)
9338 md5_init_ctx (&ctx);
9340 /* Checksum the names of surrounding namespaces and structures. */
9341 if (decl != NULL && decl->die_parent != NULL)
9342 checksum_die_context (decl->die_parent, &ctx);
9344 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9345 md5_process_bytes (name, strlen (name) + 1, &ctx);
9346 md5_finish_ctx (&ctx, checksum);
9348 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9351 /* Next, compute the complete type signature. */
9353 md5_init_ctx (&ctx);
9355 die->die_mark = mark;
9357 /* Checksum the names of surrounding namespaces and structures. */
9358 if (decl != NULL && decl->die_parent != NULL)
9359 checksum_die_context (decl->die_parent, &ctx);
9361 /* Checksum the DIE and its children. */
9362 die_checksum_ordered (die, &ctx, &mark);
9363 unmark_all_dies (die);
9364 md5_finish_ctx (&ctx, checksum);
9366 /* Store the signature in the type node and link the type DIE and the
9367 type node together. */
9368 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9369 DWARF_TYPE_SIGNATURE_SIZE);
9370 die->die_id.die_type_node = type_node;
9371 type_node->type_die = die;
9373 /* If the DIE is a specification, link its declaration to the type node
9376 decl->die_id.die_type_node = type_node;
9379 /* Do the location expressions look same? */
9381 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9383 return loc1->dw_loc_opc == loc2->dw_loc_opc
9384 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9385 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9388 /* Do the values look the same? */
9390 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9392 dw_loc_descr_ref loc1, loc2;
9395 if (v1->val_class != v2->val_class)
9398 switch (v1->val_class)
9400 case dw_val_class_const:
9401 return v1->v.val_int == v2->v.val_int;
9402 case dw_val_class_unsigned_const:
9403 return v1->v.val_unsigned == v2->v.val_unsigned;
9404 case dw_val_class_const_double:
9405 return v1->v.val_double.high == v2->v.val_double.high
9406 && v1->v.val_double.low == v2->v.val_double.low;
9407 case dw_val_class_vec:
9408 if (v1->v.val_vec.length != v2->v.val_vec.length
9409 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9411 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9412 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9415 case dw_val_class_flag:
9416 return v1->v.val_flag == v2->v.val_flag;
9417 case dw_val_class_str:
9418 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9420 case dw_val_class_addr:
9421 r1 = v1->v.val_addr;
9422 r2 = v2->v.val_addr;
9423 if (GET_CODE (r1) != GET_CODE (r2))
9425 return !rtx_equal_p (r1, r2);
9427 case dw_val_class_offset:
9428 return v1->v.val_offset == v2->v.val_offset;
9430 case dw_val_class_loc:
9431 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9433 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9434 if (!same_loc_p (loc1, loc2, mark))
9436 return !loc1 && !loc2;
9438 case dw_val_class_die_ref:
9439 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9441 case dw_val_class_fde_ref:
9442 case dw_val_class_vms_delta:
9443 case dw_val_class_lbl_id:
9444 case dw_val_class_lineptr:
9445 case dw_val_class_macptr:
9448 case dw_val_class_file:
9449 return v1->v.val_file == v2->v.val_file;
9451 case dw_val_class_data8:
9452 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9459 /* Do the attributes look the same? */
9462 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9464 if (at1->dw_attr != at2->dw_attr)
9467 /* We don't care that this was compiled with a different compiler
9468 snapshot; if the output is the same, that's what matters. */
9469 if (at1->dw_attr == DW_AT_producer)
9472 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9475 /* Do the dies look the same? */
9478 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9484 /* To avoid infinite recursion. */
9486 return die1->die_mark == die2->die_mark;
9487 die1->die_mark = die2->die_mark = ++(*mark);
9489 if (die1->die_tag != die2->die_tag)
9492 if (VEC_length (dw_attr_node, die1->die_attr)
9493 != VEC_length (dw_attr_node, die2->die_attr))
9496 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9497 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9500 c1 = die1->die_child;
9501 c2 = die2->die_child;
9510 if (!same_die_p (c1, c2, mark))
9514 if (c1 == die1->die_child)
9516 if (c2 == die2->die_child)
9526 /* Do the dies look the same? Wrapper around same_die_p. */
9529 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9532 int ret = same_die_p (die1, die2, &mark);
9534 unmark_all_dies (die1);
9535 unmark_all_dies (die2);
9540 /* The prefix to attach to symbols on DIEs in the current comdat debug
9542 static char *comdat_symbol_id;
9544 /* The index of the current symbol within the current comdat CU. */
9545 static unsigned int comdat_symbol_number;
9547 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9548 children, and set comdat_symbol_id accordingly. */
9551 compute_section_prefix (dw_die_ref unit_die)
9553 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9554 const char *base = die_name ? lbasename (die_name) : "anonymous";
9555 char *name = XALLOCAVEC (char, strlen (base) + 64);
9558 unsigned char checksum[16];
9561 /* Compute the checksum of the DIE, then append part of it as hex digits to
9562 the name filename of the unit. */
9564 md5_init_ctx (&ctx);
9566 die_checksum (unit_die, &ctx, &mark);
9567 unmark_all_dies (unit_die);
9568 md5_finish_ctx (&ctx, checksum);
9570 sprintf (name, "%s.", base);
9571 clean_symbol_name (name);
9573 p = name + strlen (name);
9574 for (i = 0; i < 4; i++)
9576 sprintf (p, "%.2x", checksum[i]);
9580 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9581 comdat_symbol_number = 0;
9584 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9587 is_type_die (dw_die_ref die)
9589 switch (die->die_tag)
9591 case DW_TAG_array_type:
9592 case DW_TAG_class_type:
9593 case DW_TAG_interface_type:
9594 case DW_TAG_enumeration_type:
9595 case DW_TAG_pointer_type:
9596 case DW_TAG_reference_type:
9597 case DW_TAG_rvalue_reference_type:
9598 case DW_TAG_string_type:
9599 case DW_TAG_structure_type:
9600 case DW_TAG_subroutine_type:
9601 case DW_TAG_union_type:
9602 case DW_TAG_ptr_to_member_type:
9603 case DW_TAG_set_type:
9604 case DW_TAG_subrange_type:
9605 case DW_TAG_base_type:
9606 case DW_TAG_const_type:
9607 case DW_TAG_file_type:
9608 case DW_TAG_packed_type:
9609 case DW_TAG_volatile_type:
9610 case DW_TAG_typedef:
9617 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9618 Basically, we want to choose the bits that are likely to be shared between
9619 compilations (types) and leave out the bits that are specific to individual
9620 compilations (functions). */
9623 is_comdat_die (dw_die_ref c)
9625 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9626 we do for stabs. The advantage is a greater likelihood of sharing between
9627 objects that don't include headers in the same order (and therefore would
9628 put the base types in a different comdat). jason 8/28/00 */
9630 if (c->die_tag == DW_TAG_base_type)
9633 if (c->die_tag == DW_TAG_pointer_type
9634 || c->die_tag == DW_TAG_reference_type
9635 || c->die_tag == DW_TAG_rvalue_reference_type
9636 || c->die_tag == DW_TAG_const_type
9637 || c->die_tag == DW_TAG_volatile_type)
9639 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9641 return t ? is_comdat_die (t) : 0;
9644 return is_type_die (c);
9647 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9648 compilation unit. */
9651 is_symbol_die (dw_die_ref c)
9653 return (is_type_die (c)
9654 || is_declaration_die (c)
9655 || c->die_tag == DW_TAG_namespace
9656 || c->die_tag == DW_TAG_module);
9659 /* Returns true iff C is a compile-unit DIE. */
9662 is_cu_die (dw_die_ref c)
9664 return c && c->die_tag == DW_TAG_compile_unit;
9668 gen_internal_sym (const char *prefix)
9672 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9673 return xstrdup (buf);
9676 /* Assign symbols to all worthy DIEs under DIE. */
9679 assign_symbol_names (dw_die_ref die)
9683 if (is_symbol_die (die))
9685 if (comdat_symbol_id)
9687 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9689 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9690 comdat_symbol_id, comdat_symbol_number++);
9691 die->die_id.die_symbol = xstrdup (p);
9694 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9697 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9700 struct cu_hash_table_entry
9703 unsigned min_comdat_num, max_comdat_num;
9704 struct cu_hash_table_entry *next;
9707 /* Routines to manipulate hash table of CUs. */
9709 htab_cu_hash (const void *of)
9711 const struct cu_hash_table_entry *const entry =
9712 (const struct cu_hash_table_entry *) of;
9714 return htab_hash_string (entry->cu->die_id.die_symbol);
9718 htab_cu_eq (const void *of1, const void *of2)
9720 const struct cu_hash_table_entry *const entry1 =
9721 (const struct cu_hash_table_entry *) of1;
9722 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9724 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9728 htab_cu_del (void *what)
9730 struct cu_hash_table_entry *next,
9731 *entry = (struct cu_hash_table_entry *) what;
9741 /* Check whether we have already seen this CU and set up SYM_NUM
9744 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9746 struct cu_hash_table_entry dummy;
9747 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9749 dummy.max_comdat_num = 0;
9751 slot = (struct cu_hash_table_entry **)
9752 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9756 for (; entry; last = entry, entry = entry->next)
9758 if (same_die_p_wrap (cu, entry->cu))
9764 *sym_num = entry->min_comdat_num;
9768 entry = XCNEW (struct cu_hash_table_entry);
9770 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9771 entry->next = *slot;
9777 /* Record SYM_NUM to record of CU in HTABLE. */
9779 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9781 struct cu_hash_table_entry **slot, *entry;
9783 slot = (struct cu_hash_table_entry **)
9784 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9788 entry->max_comdat_num = sym_num;
9791 /* Traverse the DIE (which is always comp_unit_die), and set up
9792 additional compilation units for each of the include files we see
9793 bracketed by BINCL/EINCL. */
9796 break_out_includes (dw_die_ref die)
9799 dw_die_ref unit = NULL;
9800 limbo_die_node *node, **pnode;
9801 htab_t cu_hash_table;
9805 dw_die_ref prev = c;
9807 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9808 || (unit && is_comdat_die (c)))
9810 dw_die_ref next = c->die_sib;
9812 /* This DIE is for a secondary CU; remove it from the main one. */
9813 remove_child_with_prev (c, prev);
9815 if (c->die_tag == DW_TAG_GNU_BINCL)
9816 unit = push_new_compile_unit (unit, c);
9817 else if (c->die_tag == DW_TAG_GNU_EINCL)
9818 unit = pop_compile_unit (unit);
9820 add_child_die (unit, c);
9822 if (c == die->die_child)
9825 } while (c != die->die_child);
9828 /* We can only use this in debugging, since the frontend doesn't check
9829 to make sure that we leave every include file we enter. */
9833 assign_symbol_names (die);
9834 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9835 for (node = limbo_die_list, pnode = &limbo_die_list;
9841 compute_section_prefix (node->die);
9842 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9843 &comdat_symbol_number);
9844 assign_symbol_names (node->die);
9846 *pnode = node->next;
9849 pnode = &node->next;
9850 record_comdat_symbol_number (node->die, cu_hash_table,
9851 comdat_symbol_number);
9854 htab_delete (cu_hash_table);
9857 /* Return non-zero if this DIE is a declaration. */
9860 is_declaration_die (dw_die_ref die)
9865 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9866 if (a->dw_attr == DW_AT_declaration)
9872 /* Return non-zero if this DIE is nested inside a subprogram. */
9875 is_nested_in_subprogram (dw_die_ref die)
9877 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
9881 return local_scope_p (decl);
9884 /* Return non-zero if this is a type DIE that should be moved to a
9885 COMDAT .debug_types section. */
9888 should_move_die_to_comdat (dw_die_ref die)
9890 switch (die->die_tag)
9892 case DW_TAG_class_type:
9893 case DW_TAG_structure_type:
9894 case DW_TAG_enumeration_type:
9895 case DW_TAG_union_type:
9896 /* Don't move declarations, inlined instances, or types nested in a
9898 if (is_declaration_die (die)
9899 || get_AT (die, DW_AT_abstract_origin)
9900 || is_nested_in_subprogram (die))
9903 case DW_TAG_array_type:
9904 case DW_TAG_interface_type:
9905 case DW_TAG_pointer_type:
9906 case DW_TAG_reference_type:
9907 case DW_TAG_rvalue_reference_type:
9908 case DW_TAG_string_type:
9909 case DW_TAG_subroutine_type:
9910 case DW_TAG_ptr_to_member_type:
9911 case DW_TAG_set_type:
9912 case DW_TAG_subrange_type:
9913 case DW_TAG_base_type:
9914 case DW_TAG_const_type:
9915 case DW_TAG_file_type:
9916 case DW_TAG_packed_type:
9917 case DW_TAG_volatile_type:
9918 case DW_TAG_typedef:
9924 /* Make a clone of DIE. */
9927 clone_die (dw_die_ref die)
9933 clone = ggc_alloc_cleared_die_node ();
9934 clone->die_tag = die->die_tag;
9936 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9937 add_dwarf_attr (clone, a);
9942 /* Make a clone of the tree rooted at DIE. */
9945 clone_tree (dw_die_ref die)
9948 dw_die_ref clone = clone_die (die);
9950 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
9955 /* Make a clone of DIE as a declaration. */
9958 clone_as_declaration (dw_die_ref die)
9965 /* If the DIE is already a declaration, just clone it. */
9966 if (is_declaration_die (die))
9967 return clone_die (die);
9969 /* If the DIE is a specification, just clone its declaration DIE. */
9970 decl = get_AT_ref (die, DW_AT_specification);
9972 return clone_die (decl);
9974 clone = ggc_alloc_cleared_die_node ();
9975 clone->die_tag = die->die_tag;
9977 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9979 /* We don't want to copy over all attributes.
9980 For example we don't want DW_AT_byte_size because otherwise we will no
9981 longer have a declaration and GDB will treat it as a definition. */
9985 case DW_AT_artificial:
9986 case DW_AT_containing_type:
9987 case DW_AT_external:
9990 case DW_AT_virtuality:
9991 case DW_AT_linkage_name:
9992 case DW_AT_MIPS_linkage_name:
9993 add_dwarf_attr (clone, a);
9995 case DW_AT_byte_size:
10001 if (die->die_id.die_type_node)
10002 add_AT_die_ref (clone, DW_AT_signature, die);
10004 add_AT_flag (clone, DW_AT_declaration, 1);
10008 /* Copy the declaration context to the new compile unit DIE. This includes
10009 any surrounding namespace or type declarations. If the DIE has an
10010 AT_specification attribute, it also includes attributes and children
10011 attached to the specification. */
10014 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10017 dw_die_ref new_decl;
10019 decl = get_AT_ref (die, DW_AT_specification);
10028 /* Copy the type node pointer from the new DIE to the original
10029 declaration DIE so we can forward references later. */
10030 decl->die_id.die_type_node = die->die_id.die_type_node;
10032 remove_AT (die, DW_AT_specification);
10034 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10036 if (a->dw_attr != DW_AT_name
10037 && a->dw_attr != DW_AT_declaration
10038 && a->dw_attr != DW_AT_external)
10039 add_dwarf_attr (die, a);
10042 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10045 if (decl->die_parent != NULL
10046 && decl->die_parent->die_tag != DW_TAG_compile_unit
10047 && decl->die_parent->die_tag != DW_TAG_type_unit)
10049 new_decl = copy_ancestor_tree (unit, decl, NULL);
10050 if (new_decl != NULL)
10052 remove_AT (new_decl, DW_AT_signature);
10053 add_AT_specification (die, new_decl);
10058 /* Generate the skeleton ancestor tree for the given NODE, then clone
10059 the DIE and add the clone into the tree. */
10062 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10064 if (node->new_die != NULL)
10067 node->new_die = clone_as_declaration (node->old_die);
10069 if (node->parent != NULL)
10071 generate_skeleton_ancestor_tree (node->parent);
10072 add_child_die (node->parent->new_die, node->new_die);
10076 /* Generate a skeleton tree of DIEs containing any declarations that are
10077 found in the original tree. We traverse the tree looking for declaration
10078 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10081 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10083 skeleton_chain_node node;
10086 dw_die_ref prev = NULL;
10087 dw_die_ref next = NULL;
10089 node.parent = parent;
10091 first = c = parent->old_die->die_child;
10095 if (prev == NULL || prev->die_sib == c)
10098 next = (c == first ? NULL : c->die_sib);
10100 node.new_die = NULL;
10101 if (is_declaration_die (c))
10103 /* Clone the existing DIE, move the original to the skeleton
10104 tree (which is in the main CU), and put the clone, with
10105 all the original's children, where the original came from. */
10106 dw_die_ref clone = clone_die (c);
10107 move_all_children (c, clone);
10109 replace_child (c, clone, prev);
10110 generate_skeleton_ancestor_tree (parent);
10111 add_child_die (parent->new_die, c);
10115 generate_skeleton_bottom_up (&node);
10116 } while (next != NULL);
10119 /* Wrapper function for generate_skeleton_bottom_up. */
10122 generate_skeleton (dw_die_ref die)
10124 skeleton_chain_node node;
10126 node.old_die = die;
10127 node.new_die = NULL;
10128 node.parent = NULL;
10130 /* If this type definition is nested inside another type,
10131 always leave at least a declaration in its place. */
10132 if (die->die_parent != NULL && is_type_die (die->die_parent))
10133 node.new_die = clone_as_declaration (die);
10135 generate_skeleton_bottom_up (&node);
10136 return node.new_die;
10139 /* Remove the DIE from its parent, possibly replacing it with a cloned
10140 declaration. The original DIE will be moved to a new compile unit
10141 so that existing references to it follow it to the new location. If
10142 any of the original DIE's descendants is a declaration, we need to
10143 replace the original DIE with a skeleton tree and move the
10144 declarations back into the skeleton tree. */
10147 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10149 dw_die_ref skeleton;
10151 skeleton = generate_skeleton (child);
10152 if (skeleton == NULL)
10153 remove_child_with_prev (child, prev);
10156 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10157 replace_child (child, skeleton, prev);
10163 /* Traverse the DIE and set up additional .debug_types sections for each
10164 type worthy of being placed in a COMDAT section. */
10167 break_out_comdat_types (dw_die_ref die)
10171 dw_die_ref prev = NULL;
10172 dw_die_ref next = NULL;
10173 dw_die_ref unit = NULL;
10175 first = c = die->die_child;
10179 if (prev == NULL || prev->die_sib == c)
10182 next = (c == first ? NULL : c->die_sib);
10183 if (should_move_die_to_comdat (c))
10185 dw_die_ref replacement;
10186 comdat_type_node_ref type_node;
10188 /* Create a new type unit DIE as the root for the new tree, and
10189 add it to the list of comdat types. */
10190 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10191 add_AT_unsigned (unit, DW_AT_language,
10192 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10193 type_node = ggc_alloc_cleared_comdat_type_node ();
10194 type_node->root_die = unit;
10195 type_node->next = comdat_type_list;
10196 comdat_type_list = type_node;
10198 /* Generate the type signature. */
10199 generate_type_signature (c, type_node);
10201 /* Copy the declaration context, attributes, and children of the
10202 declaration into the new compile unit DIE. */
10203 copy_declaration_context (unit, c);
10205 /* Remove this DIE from the main CU. */
10206 replacement = remove_child_or_replace_with_skeleton (c, prev);
10208 /* Break out nested types into their own type units. */
10209 break_out_comdat_types (c);
10211 /* Add the DIE to the new compunit. */
10212 add_child_die (unit, c);
10214 if (replacement != NULL)
10217 else if (c->die_tag == DW_TAG_namespace
10218 || c->die_tag == DW_TAG_class_type
10219 || c->die_tag == DW_TAG_structure_type
10220 || c->die_tag == DW_TAG_union_type)
10222 /* Look for nested types that can be broken out. */
10223 break_out_comdat_types (c);
10225 } while (next != NULL);
10228 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10230 struct decl_table_entry
10236 /* Routines to manipulate hash table of copied declarations. */
10239 htab_decl_hash (const void *of)
10241 const struct decl_table_entry *const entry =
10242 (const struct decl_table_entry *) of;
10244 return htab_hash_pointer (entry->orig);
10248 htab_decl_eq (const void *of1, const void *of2)
10250 const struct decl_table_entry *const entry1 =
10251 (const struct decl_table_entry *) of1;
10252 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10254 return entry1->orig == entry2;
10258 htab_decl_del (void *what)
10260 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10265 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10266 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10267 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10268 to check if the ancestor has already been copied into UNIT. */
10271 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10273 dw_die_ref parent = die->die_parent;
10274 dw_die_ref new_parent = unit;
10276 void **slot = NULL;
10277 struct decl_table_entry *entry = NULL;
10281 /* Check if the entry has already been copied to UNIT. */
10282 slot = htab_find_slot_with_hash (decl_table, die,
10283 htab_hash_pointer (die), INSERT);
10284 if (*slot != HTAB_EMPTY_ENTRY)
10286 entry = (struct decl_table_entry *) *slot;
10287 return entry->copy;
10290 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10291 entry = XCNEW (struct decl_table_entry);
10293 entry->copy = NULL;
10297 if (parent != NULL)
10299 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10302 if (parent->die_tag != DW_TAG_compile_unit
10303 && parent->die_tag != DW_TAG_type_unit)
10304 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10307 copy = clone_as_declaration (die);
10308 add_child_die (new_parent, copy);
10310 if (decl_table != NULL)
10312 /* Record the pointer to the copy. */
10313 entry->copy = copy;
10319 /* Walk the DIE and its children, looking for references to incomplete
10320 or trivial types that are unmarked (i.e., that are not in the current
10324 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10330 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10332 if (AT_class (a) == dw_val_class_die_ref)
10334 dw_die_ref targ = AT_ref (a);
10335 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10337 struct decl_table_entry *entry;
10339 if (targ->die_mark != 0 || type_node != NULL)
10342 slot = htab_find_slot_with_hash (decl_table, targ,
10343 htab_hash_pointer (targ), INSERT);
10345 if (*slot != HTAB_EMPTY_ENTRY)
10347 /* TARG has already been copied, so we just need to
10348 modify the reference to point to the copy. */
10349 entry = (struct decl_table_entry *) *slot;
10350 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10354 dw_die_ref parent = unit;
10355 dw_die_ref copy = clone_tree (targ);
10357 /* Make sure the cloned tree is marked as part of the
10361 /* Record in DECL_TABLE that TARG has been copied.
10362 Need to do this now, before the recursive call,
10363 because DECL_TABLE may be expanded and SLOT
10364 would no longer be a valid pointer. */
10365 entry = XCNEW (struct decl_table_entry);
10366 entry->orig = targ;
10367 entry->copy = copy;
10370 /* If TARG has surrounding context, copy its ancestor tree
10371 into the new type unit. */
10372 if (targ->die_parent != NULL
10373 && targ->die_parent->die_tag != DW_TAG_compile_unit
10374 && targ->die_parent->die_tag != DW_TAG_type_unit)
10375 parent = copy_ancestor_tree (unit, targ->die_parent,
10378 add_child_die (parent, copy);
10379 a->dw_attr_val.v.val_die_ref.die = copy;
10381 /* Make sure the newly-copied DIE is walked. If it was
10382 installed in a previously-added context, it won't
10383 get visited otherwise. */
10384 if (parent != unit)
10386 /* Find the highest point of the newly-added tree,
10387 mark each node along the way, and walk from there. */
10388 parent->die_mark = 1;
10389 while (parent->die_parent
10390 && parent->die_parent->die_mark == 0)
10392 parent = parent->die_parent;
10393 parent->die_mark = 1;
10395 copy_decls_walk (unit, parent, decl_table);
10401 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10404 /* Copy declarations for "unworthy" types into the new comdat section.
10405 Incomplete types, modified types, and certain other types aren't broken
10406 out into comdat sections of their own, so they don't have a signature,
10407 and we need to copy the declaration into the same section so that we
10408 don't have an external reference. */
10411 copy_decls_for_unworthy_types (dw_die_ref unit)
10416 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10417 copy_decls_walk (unit, unit, decl_table);
10418 htab_delete (decl_table);
10419 unmark_dies (unit);
10422 /* Traverse the DIE and add a sibling attribute if it may have the
10423 effect of speeding up access to siblings. To save some space,
10424 avoid generating sibling attributes for DIE's without children. */
10427 add_sibling_attributes (dw_die_ref die)
10431 if (! die->die_child)
10434 if (die->die_parent && die != die->die_parent->die_child)
10435 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10437 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10440 /* Output all location lists for the DIE and its children. */
10443 output_location_lists (dw_die_ref die)
10449 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10450 if (AT_class (a) == dw_val_class_loc_list)
10451 output_loc_list (AT_loc_list (a));
10453 FOR_EACH_CHILD (die, c, output_location_lists (c));
10456 /* The format of each DIE (and its attribute value pairs) is encoded in an
10457 abbreviation table. This routine builds the abbreviation table and assigns
10458 a unique abbreviation id for each abbreviation entry. The children of each
10459 die are visited recursively. */
10462 build_abbrev_table (dw_die_ref die)
10464 unsigned long abbrev_id;
10465 unsigned int n_alloc;
10470 /* Scan the DIE references, and mark as external any that refer to
10471 DIEs from other CUs (i.e. those which are not marked). */
10472 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10473 if (AT_class (a) == dw_val_class_die_ref
10474 && AT_ref (a)->die_mark == 0)
10476 gcc_assert (dwarf_version >= 4 || AT_ref (a)->die_id.die_symbol);
10477 set_AT_ref_external (a, 1);
10480 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10482 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10483 dw_attr_ref die_a, abbrev_a;
10487 if (abbrev->die_tag != die->die_tag)
10489 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10492 if (VEC_length (dw_attr_node, abbrev->die_attr)
10493 != VEC_length (dw_attr_node, die->die_attr))
10496 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10498 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10499 if ((abbrev_a->dw_attr != die_a->dw_attr)
10500 || (value_format (abbrev_a) != value_format (die_a)))
10510 if (abbrev_id >= abbrev_die_table_in_use)
10512 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10514 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10515 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10518 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10519 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10520 abbrev_die_table_allocated = n_alloc;
10523 ++abbrev_die_table_in_use;
10524 abbrev_die_table[abbrev_id] = die;
10527 die->die_abbrev = abbrev_id;
10528 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10531 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10534 constant_size (unsigned HOST_WIDE_INT value)
10541 log = floor_log2 (value);
10544 log = 1 << (floor_log2 (log) + 1);
10549 /* Return the size of a DIE as it is represented in the
10550 .debug_info section. */
10552 static unsigned long
10553 size_of_die (dw_die_ref die)
10555 unsigned long size = 0;
10559 size += size_of_uleb128 (die->die_abbrev);
10560 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10562 switch (AT_class (a))
10564 case dw_val_class_addr:
10565 size += DWARF2_ADDR_SIZE;
10567 case dw_val_class_offset:
10568 size += DWARF_OFFSET_SIZE;
10570 case dw_val_class_loc:
10572 unsigned long lsize = size_of_locs (AT_loc (a));
10574 /* Block length. */
10575 if (dwarf_version >= 4)
10576 size += size_of_uleb128 (lsize);
10578 size += constant_size (lsize);
10582 case dw_val_class_loc_list:
10583 size += DWARF_OFFSET_SIZE;
10585 case dw_val_class_range_list:
10586 size += DWARF_OFFSET_SIZE;
10588 case dw_val_class_const:
10589 size += size_of_sleb128 (AT_int (a));
10591 case dw_val_class_unsigned_const:
10592 size += constant_size (AT_unsigned (a));
10594 case dw_val_class_const_double:
10595 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10596 if (HOST_BITS_PER_WIDE_INT >= 64)
10597 size++; /* block */
10599 case dw_val_class_vec:
10600 size += constant_size (a->dw_attr_val.v.val_vec.length
10601 * a->dw_attr_val.v.val_vec.elt_size)
10602 + a->dw_attr_val.v.val_vec.length
10603 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10605 case dw_val_class_flag:
10606 if (dwarf_version >= 4)
10607 /* Currently all add_AT_flag calls pass in 1 as last argument,
10608 so DW_FORM_flag_present can be used. If that ever changes,
10609 we'll need to use DW_FORM_flag and have some optimization
10610 in build_abbrev_table that will change those to
10611 DW_FORM_flag_present if it is set to 1 in all DIEs using
10612 the same abbrev entry. */
10613 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10617 case dw_val_class_die_ref:
10618 if (AT_ref_external (a))
10620 /* In DWARF4, we use DW_FORM_sig8; for earlier versions
10621 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10622 is sized by target address length, whereas in DWARF3
10623 it's always sized as an offset. */
10624 if (dwarf_version >= 4)
10625 size += DWARF_TYPE_SIGNATURE_SIZE;
10626 else if (dwarf_version == 2)
10627 size += DWARF2_ADDR_SIZE;
10629 size += DWARF_OFFSET_SIZE;
10632 size += DWARF_OFFSET_SIZE;
10634 case dw_val_class_fde_ref:
10635 size += DWARF_OFFSET_SIZE;
10637 case dw_val_class_lbl_id:
10638 size += DWARF2_ADDR_SIZE;
10640 case dw_val_class_lineptr:
10641 case dw_val_class_macptr:
10642 size += DWARF_OFFSET_SIZE;
10644 case dw_val_class_str:
10645 if (AT_string_form (a) == DW_FORM_strp)
10646 size += DWARF_OFFSET_SIZE;
10648 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10650 case dw_val_class_file:
10651 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10653 case dw_val_class_data8:
10656 case dw_val_class_vms_delta:
10657 size += DWARF_OFFSET_SIZE;
10660 gcc_unreachable ();
10667 /* Size the debugging information associated with a given DIE. Visits the
10668 DIE's children recursively. Updates the global variable next_die_offset, on
10669 each time through. Uses the current value of next_die_offset to update the
10670 die_offset field in each DIE. */
10673 calc_die_sizes (dw_die_ref die)
10677 die->die_offset = next_die_offset;
10678 next_die_offset += size_of_die (die);
10680 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10682 if (die->die_child != NULL)
10683 /* Count the null byte used to terminate sibling lists. */
10684 next_die_offset += 1;
10687 /* Set the marks for a die and its children. We do this so
10688 that we know whether or not a reference needs to use FORM_ref_addr; only
10689 DIEs in the same CU will be marked. We used to clear out the offset
10690 and use that as the flag, but ran into ordering problems. */
10693 mark_dies (dw_die_ref die)
10697 gcc_assert (!die->die_mark);
10700 FOR_EACH_CHILD (die, c, mark_dies (c));
10703 /* Clear the marks for a die and its children. */
10706 unmark_dies (dw_die_ref die)
10710 if (dwarf_version < 4)
10711 gcc_assert (die->die_mark);
10714 FOR_EACH_CHILD (die, c, unmark_dies (c));
10717 /* Clear the marks for a die, its children and referred dies. */
10720 unmark_all_dies (dw_die_ref die)
10726 if (!die->die_mark)
10730 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10732 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10733 if (AT_class (a) == dw_val_class_die_ref)
10734 unmark_all_dies (AT_ref (a));
10737 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10738 generated for the compilation unit. */
10740 static unsigned long
10741 size_of_pubnames (VEC (pubname_entry, gc) * names)
10743 unsigned long size;
10747 size = DWARF_PUBNAMES_HEADER_SIZE;
10748 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10749 if (names != pubtype_table
10750 || p->die->die_offset != 0
10751 || !flag_eliminate_unused_debug_types)
10752 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10754 size += DWARF_OFFSET_SIZE;
10758 /* Return the size of the information in the .debug_aranges section. */
10760 static unsigned long
10761 size_of_aranges (void)
10763 unsigned long size;
10765 size = DWARF_ARANGES_HEADER_SIZE;
10767 /* Count the address/length pair for this compilation unit. */
10768 if (text_section_used)
10769 size += 2 * DWARF2_ADDR_SIZE;
10770 if (cold_text_section_used)
10771 size += 2 * DWARF2_ADDR_SIZE;
10772 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
10774 /* Count the two zero words used to terminated the address range table. */
10775 size += 2 * DWARF2_ADDR_SIZE;
10779 /* Select the encoding of an attribute value. */
10781 static enum dwarf_form
10782 value_format (dw_attr_ref a)
10784 switch (a->dw_attr_val.val_class)
10786 case dw_val_class_addr:
10787 /* Only very few attributes allow DW_FORM_addr. */
10788 switch (a->dw_attr)
10791 case DW_AT_high_pc:
10792 case DW_AT_entry_pc:
10793 case DW_AT_trampoline:
10794 return DW_FORM_addr;
10798 switch (DWARF2_ADDR_SIZE)
10801 return DW_FORM_data1;
10803 return DW_FORM_data2;
10805 return DW_FORM_data4;
10807 return DW_FORM_data8;
10809 gcc_unreachable ();
10811 case dw_val_class_range_list:
10812 case dw_val_class_loc_list:
10813 if (dwarf_version >= 4)
10814 return DW_FORM_sec_offset;
10816 case dw_val_class_vms_delta:
10817 case dw_val_class_offset:
10818 switch (DWARF_OFFSET_SIZE)
10821 return DW_FORM_data4;
10823 return DW_FORM_data8;
10825 gcc_unreachable ();
10827 case dw_val_class_loc:
10828 if (dwarf_version >= 4)
10829 return DW_FORM_exprloc;
10830 switch (constant_size (size_of_locs (AT_loc (a))))
10833 return DW_FORM_block1;
10835 return DW_FORM_block2;
10837 gcc_unreachable ();
10839 case dw_val_class_const:
10840 return DW_FORM_sdata;
10841 case dw_val_class_unsigned_const:
10842 switch (constant_size (AT_unsigned (a)))
10845 return DW_FORM_data1;
10847 return DW_FORM_data2;
10849 return DW_FORM_data4;
10851 return DW_FORM_data8;
10853 gcc_unreachable ();
10855 case dw_val_class_const_double:
10856 switch (HOST_BITS_PER_WIDE_INT)
10859 return DW_FORM_data2;
10861 return DW_FORM_data4;
10863 return DW_FORM_data8;
10866 return DW_FORM_block1;
10868 case dw_val_class_vec:
10869 switch (constant_size (a->dw_attr_val.v.val_vec.length
10870 * a->dw_attr_val.v.val_vec.elt_size))
10873 return DW_FORM_block1;
10875 return DW_FORM_block2;
10877 return DW_FORM_block4;
10879 gcc_unreachable ();
10881 case dw_val_class_flag:
10882 if (dwarf_version >= 4)
10884 /* Currently all add_AT_flag calls pass in 1 as last argument,
10885 so DW_FORM_flag_present can be used. If that ever changes,
10886 we'll need to use DW_FORM_flag and have some optimization
10887 in build_abbrev_table that will change those to
10888 DW_FORM_flag_present if it is set to 1 in all DIEs using
10889 the same abbrev entry. */
10890 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10891 return DW_FORM_flag_present;
10893 return DW_FORM_flag;
10894 case dw_val_class_die_ref:
10895 if (AT_ref_external (a))
10896 return dwarf_version >= 4 ? DW_FORM_sig8 : DW_FORM_ref_addr;
10898 return DW_FORM_ref;
10899 case dw_val_class_fde_ref:
10900 return DW_FORM_data;
10901 case dw_val_class_lbl_id:
10902 return DW_FORM_addr;
10903 case dw_val_class_lineptr:
10904 case dw_val_class_macptr:
10905 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10906 case dw_val_class_str:
10907 return AT_string_form (a);
10908 case dw_val_class_file:
10909 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10912 return DW_FORM_data1;
10914 return DW_FORM_data2;
10916 return DW_FORM_data4;
10918 gcc_unreachable ();
10921 case dw_val_class_data8:
10922 return DW_FORM_data8;
10925 gcc_unreachable ();
10929 /* Output the encoding of an attribute value. */
10932 output_value_format (dw_attr_ref a)
10934 enum dwarf_form form = value_format (a);
10936 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10939 /* Output the .debug_abbrev section which defines the DIE abbreviation
10943 output_abbrev_section (void)
10945 unsigned long abbrev_id;
10947 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10949 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10951 dw_attr_ref a_attr;
10953 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10954 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10955 dwarf_tag_name (abbrev->die_tag));
10957 if (abbrev->die_child != NULL)
10958 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10960 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10962 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
10965 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10966 dwarf_attr_name (a_attr->dw_attr));
10967 output_value_format (a_attr);
10970 dw2_asm_output_data (1, 0, NULL);
10971 dw2_asm_output_data (1, 0, NULL);
10974 /* Terminate the table. */
10975 dw2_asm_output_data (1, 0, NULL);
10978 /* Output a symbol we can use to refer to this DIE from another CU. */
10981 output_die_symbol (dw_die_ref die)
10983 char *sym = die->die_id.die_symbol;
10988 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
10989 /* We make these global, not weak; if the target doesn't support
10990 .linkonce, it doesn't support combining the sections, so debugging
10992 targetm.asm_out.globalize_label (asm_out_file, sym);
10994 ASM_OUTPUT_LABEL (asm_out_file, sym);
10997 /* Return a new location list, given the begin and end range, and the
11000 static inline dw_loc_list_ref
11001 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11002 const char *section)
11004 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11006 retlist->begin = begin;
11007 retlist->end = end;
11008 retlist->expr = expr;
11009 retlist->section = section;
11014 /* Generate a new internal symbol for this location list node, if it
11015 hasn't got one yet. */
11018 gen_llsym (dw_loc_list_ref list)
11020 gcc_assert (!list->ll_symbol);
11021 list->ll_symbol = gen_internal_sym ("LLST");
11024 /* Output the location list given to us. */
11027 output_loc_list (dw_loc_list_ref list_head)
11029 dw_loc_list_ref curr = list_head;
11031 if (list_head->emitted)
11033 list_head->emitted = true;
11035 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11037 /* Walk the location list, and output each range + expression. */
11038 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11040 unsigned long size;
11041 /* Don't output an entry that starts and ends at the same address. */
11042 if (strcmp (curr->begin, curr->end) == 0)
11044 if (!have_multiple_function_sections)
11046 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11047 "Location list begin address (%s)",
11048 list_head->ll_symbol);
11049 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11050 "Location list end address (%s)",
11051 list_head->ll_symbol);
11055 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11056 "Location list begin address (%s)",
11057 list_head->ll_symbol);
11058 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11059 "Location list end address (%s)",
11060 list_head->ll_symbol);
11062 size = size_of_locs (curr->expr);
11064 /* Output the block length for this list of location operations. */
11065 gcc_assert (size <= 0xffff);
11066 dw2_asm_output_data (2, size, "%s", "Location expression size");
11068 output_loc_sequence (curr->expr);
11071 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11072 "Location list terminator begin (%s)",
11073 list_head->ll_symbol);
11074 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11075 "Location list terminator end (%s)",
11076 list_head->ll_symbol);
11079 /* Output a type signature. */
11082 output_signature (const char *sig, const char *name)
11086 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11087 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11090 /* Output the DIE and its attributes. Called recursively to generate
11091 the definitions of each child DIE. */
11094 output_die (dw_die_ref die)
11098 unsigned long size;
11101 /* If someone in another CU might refer to us, set up a symbol for
11102 them to point to. */
11103 if (dwarf_version < 4 && die->die_id.die_symbol)
11104 output_die_symbol (die);
11106 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11107 (unsigned long)die->die_offset,
11108 dwarf_tag_name (die->die_tag));
11110 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11112 const char *name = dwarf_attr_name (a->dw_attr);
11114 switch (AT_class (a))
11116 case dw_val_class_addr:
11117 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11120 case dw_val_class_offset:
11121 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11125 case dw_val_class_range_list:
11127 char *p = strchr (ranges_section_label, '\0');
11129 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11130 a->dw_attr_val.v.val_offset);
11131 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11132 debug_ranges_section, "%s", name);
11137 case dw_val_class_loc:
11138 size = size_of_locs (AT_loc (a));
11140 /* Output the block length for this list of location operations. */
11141 if (dwarf_version >= 4)
11142 dw2_asm_output_data_uleb128 (size, "%s", name);
11144 dw2_asm_output_data (constant_size (size), size, "%s", name);
11146 output_loc_sequence (AT_loc (a));
11149 case dw_val_class_const:
11150 /* ??? It would be slightly more efficient to use a scheme like is
11151 used for unsigned constants below, but gdb 4.x does not sign
11152 extend. Gdb 5.x does sign extend. */
11153 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11156 case dw_val_class_unsigned_const:
11157 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11158 AT_unsigned (a), "%s", name);
11161 case dw_val_class_const_double:
11163 unsigned HOST_WIDE_INT first, second;
11165 if (HOST_BITS_PER_WIDE_INT >= 64)
11166 dw2_asm_output_data (1,
11167 2 * HOST_BITS_PER_WIDE_INT
11168 / HOST_BITS_PER_CHAR,
11171 if (WORDS_BIG_ENDIAN)
11173 first = a->dw_attr_val.v.val_double.high;
11174 second = a->dw_attr_val.v.val_double.low;
11178 first = a->dw_attr_val.v.val_double.low;
11179 second = a->dw_attr_val.v.val_double.high;
11182 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11184 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11189 case dw_val_class_vec:
11191 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11192 unsigned int len = a->dw_attr_val.v.val_vec.length;
11196 dw2_asm_output_data (constant_size (len * elt_size),
11197 len * elt_size, "%s", name);
11198 if (elt_size > sizeof (HOST_WIDE_INT))
11203 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11205 i++, p += elt_size)
11206 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11207 "fp or vector constant word %u", i);
11211 case dw_val_class_flag:
11212 if (dwarf_version >= 4)
11214 /* Currently all add_AT_flag calls pass in 1 as last argument,
11215 so DW_FORM_flag_present can be used. If that ever changes,
11216 we'll need to use DW_FORM_flag and have some optimization
11217 in build_abbrev_table that will change those to
11218 DW_FORM_flag_present if it is set to 1 in all DIEs using
11219 the same abbrev entry. */
11220 gcc_assert (AT_flag (a) == 1);
11221 if (flag_debug_asm)
11222 fprintf (asm_out_file, "\t\t\t%s %s\n",
11223 ASM_COMMENT_START, name);
11226 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11229 case dw_val_class_loc_list:
11231 char *sym = AT_loc_list (a)->ll_symbol;
11234 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11239 case dw_val_class_die_ref:
11240 if (AT_ref_external (a))
11242 if (dwarf_version >= 4)
11244 comdat_type_node_ref type_node =
11245 AT_ref (a)->die_id.die_type_node;
11247 gcc_assert (type_node);
11248 output_signature (type_node->signature, name);
11252 char *sym = AT_ref (a)->die_id.die_symbol;
11256 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11257 length, whereas in DWARF3 it's always sized as an
11259 if (dwarf_version == 2)
11260 size = DWARF2_ADDR_SIZE;
11262 size = DWARF_OFFSET_SIZE;
11263 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11269 gcc_assert (AT_ref (a)->die_offset);
11270 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11275 case dw_val_class_fde_ref:
11279 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11280 a->dw_attr_val.v.val_fde_index * 2);
11281 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11286 case dw_val_class_vms_delta:
11287 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11288 AT_vms_delta2 (a), AT_vms_delta1 (a),
11292 case dw_val_class_lbl_id:
11293 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11296 case dw_val_class_lineptr:
11297 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11298 debug_line_section, "%s", name);
11301 case dw_val_class_macptr:
11302 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11303 debug_macinfo_section, "%s", name);
11306 case dw_val_class_str:
11307 if (AT_string_form (a) == DW_FORM_strp)
11308 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11309 a->dw_attr_val.v.val_str->label,
11311 "%s: \"%s\"", name, AT_string (a));
11313 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11316 case dw_val_class_file:
11318 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11320 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11321 a->dw_attr_val.v.val_file->filename);
11325 case dw_val_class_data8:
11329 for (i = 0; i < 8; i++)
11330 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11331 i == 0 ? "%s" : NULL, name);
11336 gcc_unreachable ();
11340 FOR_EACH_CHILD (die, c, output_die (c));
11342 /* Add null byte to terminate sibling list. */
11343 if (die->die_child != NULL)
11344 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11345 (unsigned long) die->die_offset);
11348 /* Output the compilation unit that appears at the beginning of the
11349 .debug_info section, and precedes the DIE descriptions. */
11352 output_compilation_unit_header (void)
11354 int ver = dwarf_version;
11356 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11357 dw2_asm_output_data (4, 0xffffffff,
11358 "Initial length escape value indicating 64-bit DWARF extension");
11359 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11360 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11361 "Length of Compilation Unit Info");
11362 dw2_asm_output_data (2, ver, "DWARF version number");
11363 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11364 debug_abbrev_section,
11365 "Offset Into Abbrev. Section");
11366 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11369 /* Output the compilation unit DIE and its children. */
11372 output_comp_unit (dw_die_ref die, int output_if_empty)
11374 const char *secname;
11375 char *oldsym, *tmp;
11377 /* Unless we are outputting main CU, we may throw away empty ones. */
11378 if (!output_if_empty && die->die_child == NULL)
11381 /* Even if there are no children of this DIE, we must output the information
11382 about the compilation unit. Otherwise, on an empty translation unit, we
11383 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11384 will then complain when examining the file. First mark all the DIEs in
11385 this CU so we know which get local refs. */
11388 build_abbrev_table (die);
11390 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11391 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11392 calc_die_sizes (die);
11394 oldsym = die->die_id.die_symbol;
11397 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11399 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11401 die->die_id.die_symbol = NULL;
11402 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11406 switch_to_section (debug_info_section);
11407 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11408 info_section_emitted = true;
11411 /* Output debugging information. */
11412 output_compilation_unit_header ();
11415 /* Leave the marks on the main CU, so we can check them in
11416 output_pubnames. */
11420 die->die_id.die_symbol = oldsym;
11424 /* Output a comdat type unit DIE and its children. */
11427 output_comdat_type_unit (comdat_type_node *node)
11429 const char *secname;
11432 #if defined (OBJECT_FORMAT_ELF)
11436 /* First mark all the DIEs in this CU so we know which get local refs. */
11437 mark_dies (node->root_die);
11439 build_abbrev_table (node->root_die);
11441 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11442 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11443 calc_die_sizes (node->root_die);
11445 #if defined (OBJECT_FORMAT_ELF)
11446 secname = ".debug_types";
11447 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11448 sprintf (tmp, "wt.");
11449 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11450 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11451 comdat_key = get_identifier (tmp);
11452 targetm.asm_out.named_section (secname,
11453 SECTION_DEBUG | SECTION_LINKONCE,
11456 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11457 sprintf (tmp, ".gnu.linkonce.wt.");
11458 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11459 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11461 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11464 /* Output debugging information. */
11465 output_compilation_unit_header ();
11466 output_signature (node->signature, "Type Signature");
11467 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11468 "Offset to Type DIE");
11469 output_die (node->root_die);
11471 unmark_dies (node->root_die);
11474 /* Return the DWARF2/3 pubname associated with a decl. */
11476 static const char *
11477 dwarf2_name (tree decl, int scope)
11479 if (DECL_NAMELESS (decl))
11481 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11484 /* Add a new entry to .debug_pubnames if appropriate. */
11487 add_pubname_string (const char *str, dw_die_ref die)
11489 if (targetm.want_debug_pub_sections)
11494 e.name = xstrdup (str);
11495 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11500 add_pubname (tree decl, dw_die_ref die)
11502 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11504 const char *name = dwarf2_name (decl, 1);
11506 add_pubname_string (name, die);
11510 /* Add a new entry to .debug_pubtypes if appropriate. */
11513 add_pubtype (tree decl, dw_die_ref die)
11517 if (!targetm.want_debug_pub_sections)
11521 if ((TREE_PUBLIC (decl)
11522 || is_cu_die (die->die_parent))
11523 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11528 if (TYPE_NAME (decl))
11530 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11531 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11532 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11533 && DECL_NAME (TYPE_NAME (decl)))
11534 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11536 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11541 e.name = dwarf2_name (decl, 1);
11543 e.name = xstrdup (e.name);
11546 /* If we don't have a name for the type, there's no point in adding
11547 it to the table. */
11548 if (e.name && e.name[0] != '\0')
11549 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11553 /* Output the public names table used to speed up access to externally
11554 visible names; or the public types table used to find type definitions. */
11557 output_pubnames (VEC (pubname_entry, gc) * names)
11560 unsigned long pubnames_length = size_of_pubnames (names);
11563 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11564 dw2_asm_output_data (4, 0xffffffff,
11565 "Initial length escape value indicating 64-bit DWARF extension");
11566 if (names == pubname_table)
11567 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11568 "Length of Public Names Info");
11570 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11571 "Length of Public Type Names Info");
11572 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11573 dw2_asm_output_data (2, 2, "DWARF Version");
11574 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11575 debug_info_section,
11576 "Offset of Compilation Unit Info");
11577 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11578 "Compilation Unit Length");
11580 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11582 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11583 if (names == pubname_table)
11584 gcc_assert (pub->die->die_mark);
11586 if (names != pubtype_table
11587 || pub->die->die_offset != 0
11588 || !flag_eliminate_unused_debug_types)
11590 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11593 dw2_asm_output_nstring (pub->name, -1, "external name");
11597 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11600 /* Add a new entry to .debug_aranges if appropriate. */
11603 add_arange (tree decl, dw_die_ref die)
11605 if (! DECL_SECTION_NAME (decl))
11608 if (arange_table_in_use == arange_table_allocated)
11610 arange_table_allocated += ARANGE_TABLE_INCREMENT;
11611 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
11612 arange_table_allocated);
11613 memset (arange_table + arange_table_in_use, 0,
11614 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
11617 arange_table[arange_table_in_use++] = die;
11620 /* Output the information that goes into the .debug_aranges table.
11621 Namely, define the beginning and ending address range of the
11622 text section generated for this compilation unit. */
11625 output_aranges (void)
11628 unsigned long aranges_length = size_of_aranges ();
11630 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11631 dw2_asm_output_data (4, 0xffffffff,
11632 "Initial length escape value indicating 64-bit DWARF extension");
11633 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11634 "Length of Address Ranges Info");
11635 /* Version number for aranges is still 2, even in DWARF3. */
11636 dw2_asm_output_data (2, 2, "DWARF Version");
11637 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11638 debug_info_section,
11639 "Offset of Compilation Unit Info");
11640 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11641 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11643 /* We need to align to twice the pointer size here. */
11644 if (DWARF_ARANGES_PAD_SIZE)
11646 /* Pad using a 2 byte words so that padding is correct for any
11648 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11649 2 * DWARF2_ADDR_SIZE);
11650 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11651 dw2_asm_output_data (2, 0, NULL);
11654 /* It is necessary not to output these entries if the sections were
11655 not used; if the sections were not used, the length will be 0 and
11656 the address may end up as 0 if the section is discarded by ld
11657 --gc-sections, leaving an invalid (0, 0) entry that can be
11658 confused with the terminator. */
11659 if (text_section_used)
11661 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11662 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11663 text_section_label, "Length");
11665 if (cold_text_section_used)
11667 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11669 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11670 cold_text_section_label, "Length");
11673 for (i = 0; i < arange_table_in_use; i++)
11675 dw_die_ref die = arange_table[i];
11677 /* We shouldn't see aranges for DIEs outside of the main CU. */
11678 gcc_assert (die->die_mark);
11680 if (die->die_tag == DW_TAG_subprogram)
11682 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
11684 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
11685 get_AT_low_pc (die), "Length");
11689 /* A static variable; extract the symbol from DW_AT_location.
11690 Note that this code isn't currently hit, as we only emit
11691 aranges for functions (jason 9/23/99). */
11692 dw_attr_ref a = get_AT (die, DW_AT_location);
11693 dw_loc_descr_ref loc;
11695 gcc_assert (a && AT_class (a) == dw_val_class_loc);
11698 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
11700 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
11701 loc->dw_loc_oprnd1.v.val_addr, "Address");
11702 dw2_asm_output_data (DWARF2_ADDR_SIZE,
11703 get_AT_unsigned (die, DW_AT_byte_size),
11708 /* Output the terminator words. */
11709 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11710 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11713 /* Add a new entry to .debug_ranges. Return the offset at which it
11716 static unsigned int
11717 add_ranges_num (int num)
11719 unsigned int in_use = ranges_table_in_use;
11721 if (in_use == ranges_table_allocated)
11723 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11724 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11725 ranges_table_allocated);
11726 memset (ranges_table + ranges_table_in_use, 0,
11727 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11730 ranges_table[in_use].num = num;
11731 ranges_table_in_use = in_use + 1;
11733 return in_use * 2 * DWARF2_ADDR_SIZE;
11736 /* Add a new entry to .debug_ranges corresponding to a block, or a
11737 range terminator if BLOCK is NULL. */
11739 static unsigned int
11740 add_ranges (const_tree block)
11742 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11745 /* Add a new entry to .debug_ranges corresponding to a pair of
11749 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11752 unsigned int in_use = ranges_by_label_in_use;
11753 unsigned int offset;
11755 if (in_use == ranges_by_label_allocated)
11757 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11758 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11760 ranges_by_label_allocated);
11761 memset (ranges_by_label + ranges_by_label_in_use, 0,
11762 RANGES_TABLE_INCREMENT
11763 * sizeof (struct dw_ranges_by_label_struct));
11766 ranges_by_label[in_use].begin = begin;
11767 ranges_by_label[in_use].end = end;
11768 ranges_by_label_in_use = in_use + 1;
11770 offset = add_ranges_num (-(int)in_use - 1);
11773 add_AT_range_list (die, DW_AT_ranges, offset);
11779 output_ranges (void)
11782 static const char *const start_fmt = "Offset %#x";
11783 const char *fmt = start_fmt;
11785 for (i = 0; i < ranges_table_in_use; i++)
11787 int block_num = ranges_table[i].num;
11791 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11792 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11794 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11795 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11797 /* If all code is in the text section, then the compilation
11798 unit base address defaults to DW_AT_low_pc, which is the
11799 base of the text section. */
11800 if (!have_multiple_function_sections)
11802 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11803 text_section_label,
11804 fmt, i * 2 * DWARF2_ADDR_SIZE);
11805 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11806 text_section_label, NULL);
11809 /* Otherwise, the compilation unit base address is zero,
11810 which allows us to use absolute addresses, and not worry
11811 about whether the target supports cross-section
11815 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11816 fmt, i * 2 * DWARF2_ADDR_SIZE);
11817 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11823 /* Negative block_num stands for an index into ranges_by_label. */
11824 else if (block_num < 0)
11826 int lab_idx = - block_num - 1;
11828 if (!have_multiple_function_sections)
11830 gcc_unreachable ();
11832 /* If we ever use add_ranges_by_labels () for a single
11833 function section, all we have to do is to take out
11834 the #if 0 above. */
11835 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11836 ranges_by_label[lab_idx].begin,
11837 text_section_label,
11838 fmt, i * 2 * DWARF2_ADDR_SIZE);
11839 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11840 ranges_by_label[lab_idx].end,
11841 text_section_label, NULL);
11846 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11847 ranges_by_label[lab_idx].begin,
11848 fmt, i * 2 * DWARF2_ADDR_SIZE);
11849 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11850 ranges_by_label[lab_idx].end,
11856 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11857 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11863 /* Data structure containing information about input files. */
11866 const char *path; /* Complete file name. */
11867 const char *fname; /* File name part. */
11868 int length; /* Length of entire string. */
11869 struct dwarf_file_data * file_idx; /* Index in input file table. */
11870 int dir_idx; /* Index in directory table. */
11873 /* Data structure containing information about directories with source
11877 const char *path; /* Path including directory name. */
11878 int length; /* Path length. */
11879 int prefix; /* Index of directory entry which is a prefix. */
11880 int count; /* Number of files in this directory. */
11881 int dir_idx; /* Index of directory used as base. */
11884 /* Callback function for file_info comparison. We sort by looking at
11885 the directories in the path. */
11888 file_info_cmp (const void *p1, const void *p2)
11890 const struct file_info *const s1 = (const struct file_info *) p1;
11891 const struct file_info *const s2 = (const struct file_info *) p2;
11892 const unsigned char *cp1;
11893 const unsigned char *cp2;
11895 /* Take care of file names without directories. We need to make sure that
11896 we return consistent values to qsort since some will get confused if
11897 we return the same value when identical operands are passed in opposite
11898 orders. So if neither has a directory, return 0 and otherwise return
11899 1 or -1 depending on which one has the directory. */
11900 if ((s1->path == s1->fname || s2->path == s2->fname))
11901 return (s2->path == s2->fname) - (s1->path == s1->fname);
11903 cp1 = (const unsigned char *) s1->path;
11904 cp2 = (const unsigned char *) s2->path;
11910 /* Reached the end of the first path? If so, handle like above. */
11911 if ((cp1 == (const unsigned char *) s1->fname)
11912 || (cp2 == (const unsigned char *) s2->fname))
11913 return ((cp2 == (const unsigned char *) s2->fname)
11914 - (cp1 == (const unsigned char *) s1->fname));
11916 /* Character of current path component the same? */
11917 else if (*cp1 != *cp2)
11918 return *cp1 - *cp2;
11922 struct file_name_acquire_data
11924 struct file_info *files;
11929 /* Traversal function for the hash table. */
11932 file_name_acquire (void ** slot, void *data)
11934 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
11935 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
11936 struct file_info *fi;
11939 gcc_assert (fnad->max_files >= d->emitted_number);
11941 if (! d->emitted_number)
11944 gcc_assert (fnad->max_files != fnad->used_files);
11946 fi = fnad->files + fnad->used_files++;
11948 /* Skip all leading "./". */
11950 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
11953 /* Create a new array entry. */
11955 fi->length = strlen (f);
11958 /* Search for the file name part. */
11959 f = strrchr (f, DIR_SEPARATOR);
11960 #if defined (DIR_SEPARATOR_2)
11962 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
11966 if (f == NULL || f < g)
11972 fi->fname = f == NULL ? fi->path : f + 1;
11976 /* Output the directory table and the file name table. We try to minimize
11977 the total amount of memory needed. A heuristic is used to avoid large
11978 slowdowns with many input files. */
11981 output_file_names (void)
11983 struct file_name_acquire_data fnad;
11985 struct file_info *files;
11986 struct dir_info *dirs;
11994 if (!last_emitted_file)
11996 dw2_asm_output_data (1, 0, "End directory table");
11997 dw2_asm_output_data (1, 0, "End file name table");
12001 numfiles = last_emitted_file->emitted_number;
12003 /* Allocate the various arrays we need. */
12004 files = XALLOCAVEC (struct file_info, numfiles);
12005 dirs = XALLOCAVEC (struct dir_info, numfiles);
12007 fnad.files = files;
12008 fnad.used_files = 0;
12009 fnad.max_files = numfiles;
12010 htab_traverse (file_table, file_name_acquire, &fnad);
12011 gcc_assert (fnad.used_files == fnad.max_files);
12013 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12015 /* Find all the different directories used. */
12016 dirs[0].path = files[0].path;
12017 dirs[0].length = files[0].fname - files[0].path;
12018 dirs[0].prefix = -1;
12020 dirs[0].dir_idx = 0;
12021 files[0].dir_idx = 0;
12024 for (i = 1; i < numfiles; i++)
12025 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12026 && memcmp (dirs[ndirs - 1].path, files[i].path,
12027 dirs[ndirs - 1].length) == 0)
12029 /* Same directory as last entry. */
12030 files[i].dir_idx = ndirs - 1;
12031 ++dirs[ndirs - 1].count;
12037 /* This is a new directory. */
12038 dirs[ndirs].path = files[i].path;
12039 dirs[ndirs].length = files[i].fname - files[i].path;
12040 dirs[ndirs].count = 1;
12041 dirs[ndirs].dir_idx = ndirs;
12042 files[i].dir_idx = ndirs;
12044 /* Search for a prefix. */
12045 dirs[ndirs].prefix = -1;
12046 for (j = 0; j < ndirs; j++)
12047 if (dirs[j].length < dirs[ndirs].length
12048 && dirs[j].length > 1
12049 && (dirs[ndirs].prefix == -1
12050 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12051 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12052 dirs[ndirs].prefix = j;
12057 /* Now to the actual work. We have to find a subset of the directories which
12058 allow expressing the file name using references to the directory table
12059 with the least amount of characters. We do not do an exhaustive search
12060 where we would have to check out every combination of every single
12061 possible prefix. Instead we use a heuristic which provides nearly optimal
12062 results in most cases and never is much off. */
12063 saved = XALLOCAVEC (int, ndirs);
12064 savehere = XALLOCAVEC (int, ndirs);
12066 memset (saved, '\0', ndirs * sizeof (saved[0]));
12067 for (i = 0; i < ndirs; i++)
12072 /* We can always save some space for the current directory. But this
12073 does not mean it will be enough to justify adding the directory. */
12074 savehere[i] = dirs[i].length;
12075 total = (savehere[i] - saved[i]) * dirs[i].count;
12077 for (j = i + 1; j < ndirs; j++)
12080 if (saved[j] < dirs[i].length)
12082 /* Determine whether the dirs[i] path is a prefix of the
12086 k = dirs[j].prefix;
12087 while (k != -1 && k != (int) i)
12088 k = dirs[k].prefix;
12092 /* Yes it is. We can possibly save some memory by
12093 writing the filenames in dirs[j] relative to
12095 savehere[j] = dirs[i].length;
12096 total += (savehere[j] - saved[j]) * dirs[j].count;
12101 /* Check whether we can save enough to justify adding the dirs[i]
12103 if (total > dirs[i].length + 1)
12105 /* It's worthwhile adding. */
12106 for (j = i; j < ndirs; j++)
12107 if (savehere[j] > 0)
12109 /* Remember how much we saved for this directory so far. */
12110 saved[j] = savehere[j];
12112 /* Remember the prefix directory. */
12113 dirs[j].dir_idx = i;
12118 /* Emit the directory name table. */
12119 idx_offset = dirs[0].length > 0 ? 1 : 0;
12120 for (i = 1 - idx_offset; i < ndirs; i++)
12121 dw2_asm_output_nstring (dirs[i].path,
12123 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12124 "Directory Entry: %#x", i + idx_offset);
12126 dw2_asm_output_data (1, 0, "End directory table");
12128 /* We have to emit them in the order of emitted_number since that's
12129 used in the debug info generation. To do this efficiently we
12130 generate a back-mapping of the indices first. */
12131 backmap = XALLOCAVEC (int, numfiles);
12132 for (i = 0; i < numfiles; i++)
12133 backmap[files[i].file_idx->emitted_number - 1] = i;
12135 /* Now write all the file names. */
12136 for (i = 0; i < numfiles; i++)
12138 int file_idx = backmap[i];
12139 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12141 #ifdef VMS_DEBUGGING_INFO
12142 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12144 /* Setting these fields can lead to debugger miscomparisons,
12145 but VMS Debug requires them to be set correctly. */
12150 int maxfilelen = strlen (files[file_idx].path)
12151 + dirs[dir_idx].length
12152 + MAX_VMS_VERSION_LEN + 1;
12153 char *filebuf = XALLOCAVEC (char, maxfilelen);
12155 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12156 snprintf (filebuf, maxfilelen, "%s;%d",
12157 files[file_idx].path + dirs[dir_idx].length, ver);
12159 dw2_asm_output_nstring
12160 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12162 /* Include directory index. */
12163 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12165 /* Modification time. */
12166 dw2_asm_output_data_uleb128
12167 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12171 /* File length in bytes. */
12172 dw2_asm_output_data_uleb128
12173 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12177 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12178 "File Entry: %#x", (unsigned) i + 1);
12180 /* Include directory index. */
12181 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12183 /* Modification time. */
12184 dw2_asm_output_data_uleb128 (0, NULL);
12186 /* File length in bytes. */
12187 dw2_asm_output_data_uleb128 (0, NULL);
12188 #endif /* VMS_DEBUGGING_INFO */
12191 dw2_asm_output_data (1, 0, "End file name table");
12195 /* Output the source line number correspondence information. This
12196 information goes into the .debug_line section. */
12199 output_line_info (void)
12201 char l1[20], l2[20], p1[20], p2[20];
12202 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12203 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12205 unsigned n_op_args;
12206 unsigned long lt_index;
12207 unsigned long current_line;
12210 unsigned long current_file;
12211 unsigned long function;
12212 int ver = dwarf_version;
12214 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12215 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12216 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12217 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12219 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12220 dw2_asm_output_data (4, 0xffffffff,
12221 "Initial length escape value indicating 64-bit DWARF extension");
12222 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12223 "Length of Source Line Info");
12224 ASM_OUTPUT_LABEL (asm_out_file, l1);
12226 dw2_asm_output_data (2, ver, "DWARF Version");
12227 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12228 ASM_OUTPUT_LABEL (asm_out_file, p1);
12230 /* Define the architecture-dependent minimum instruction length (in
12231 bytes). In this implementation of DWARF, this field is used for
12232 information purposes only. Since GCC generates assembly language,
12233 we have no a priori knowledge of how many instruction bytes are
12234 generated for each source line, and therefore can use only the
12235 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
12236 commands. Accordingly, we fix this as `1', which is "correct
12237 enough" for all architectures, and don't let the target override. */
12238 dw2_asm_output_data (1, 1,
12239 "Minimum Instruction Length");
12242 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12243 "Maximum Operations Per Instruction");
12244 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12245 "Default is_stmt_start flag");
12246 dw2_asm_output_data (1, DWARF_LINE_BASE,
12247 "Line Base Value (Special Opcodes)");
12248 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12249 "Line Range Value (Special Opcodes)");
12250 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12251 "Special Opcode Base");
12253 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12257 case DW_LNS_advance_pc:
12258 case DW_LNS_advance_line:
12259 case DW_LNS_set_file:
12260 case DW_LNS_set_column:
12261 case DW_LNS_fixed_advance_pc:
12269 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12273 /* Write out the information about the files we use. */
12274 output_file_names ();
12275 ASM_OUTPUT_LABEL (asm_out_file, p2);
12277 /* We used to set the address register to the first location in the text
12278 section here, but that didn't accomplish anything since we already
12279 have a line note for the opening brace of the first function. */
12281 /* Generate the line number to PC correspondence table, encoded as
12282 a series of state machine operations. */
12286 if (cfun && in_cold_section_p)
12287 strcpy (prev_line_label, crtl->subsections.cold_section_label);
12289 strcpy (prev_line_label, text_section_label);
12290 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
12292 dw_line_info_ref line_info = &line_info_table[lt_index];
12295 /* Disable this optimization for now; GDB wants to see two line notes
12296 at the beginning of a function so it can find the end of the
12299 /* Don't emit anything for redundant notes. Just updating the
12300 address doesn't accomplish anything, because we already assume
12301 that anything after the last address is this line. */
12302 if (line_info->dw_line_num == current_line
12303 && line_info->dw_file_num == current_file)
12307 /* Emit debug info for the address of the current line.
12309 Unfortunately, we have little choice here currently, and must always
12310 use the most general form. GCC does not know the address delta
12311 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
12312 attributes which will give an upper bound on the address range. We
12313 could perhaps use length attributes to determine when it is safe to
12314 use DW_LNS_fixed_advance_pc. */
12316 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
12319 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
12320 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12321 "DW_LNS_fixed_advance_pc");
12322 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12326 /* This can handle any delta. This takes
12327 4+DWARF2_ADDR_SIZE bytes. */
12328 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12329 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12330 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12331 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12334 strcpy (prev_line_label, line_label);
12336 /* Emit debug info for the source file of the current line, if
12337 different from the previous line. */
12338 if (line_info->dw_file_num != current_file)
12340 current_file = line_info->dw_file_num;
12341 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12342 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12345 /* Emit debug info for the current line number, choosing the encoding
12346 that uses the least amount of space. */
12347 if (line_info->dw_line_num != current_line)
12349 line_offset = line_info->dw_line_num - current_line;
12350 line_delta = line_offset - DWARF_LINE_BASE;
12351 current_line = line_info->dw_line_num;
12352 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12353 /* This can handle deltas from -10 to 234, using the current
12354 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
12356 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12357 "line %lu", current_line);
12360 /* This can handle any delta. This takes at least 4 bytes,
12361 depending on the value being encoded. */
12362 dw2_asm_output_data (1, DW_LNS_advance_line,
12363 "advance to line %lu", current_line);
12364 dw2_asm_output_data_sleb128 (line_offset, NULL);
12365 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12369 /* We still need to start a new row, so output a copy insn. */
12370 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12373 /* Emit debug info for the address of the end of the function. */
12376 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12377 "DW_LNS_fixed_advance_pc");
12378 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
12382 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12383 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12384 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12385 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
12388 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12389 dw2_asm_output_data_uleb128 (1, NULL);
12390 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12395 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
12397 dw_separate_line_info_ref line_info
12398 = &separate_line_info_table[lt_index];
12401 /* Don't emit anything for redundant notes. */
12402 if (line_info->dw_line_num == current_line
12403 && line_info->dw_file_num == current_file
12404 && line_info->function == function)
12408 /* Emit debug info for the address of the current line. If this is
12409 a new function, or the first line of a function, then we need
12410 to handle it differently. */
12411 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
12413 if (function != line_info->function)
12415 function = line_info->function;
12417 /* Set the address register to the first line in the function. */
12418 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12419 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12420 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12421 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12425 /* ??? See the DW_LNS_advance_pc comment above. */
12428 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12429 "DW_LNS_fixed_advance_pc");
12430 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12434 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12435 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12436 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12437 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12441 strcpy (prev_line_label, line_label);
12443 /* Emit debug info for the source file of the current line, if
12444 different from the previous line. */
12445 if (line_info->dw_file_num != current_file)
12447 current_file = line_info->dw_file_num;
12448 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
12449 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
12452 /* Emit debug info for the current line number, choosing the encoding
12453 that uses the least amount of space. */
12454 if (line_info->dw_line_num != current_line)
12456 line_offset = line_info->dw_line_num - current_line;
12457 line_delta = line_offset - DWARF_LINE_BASE;
12458 current_line = line_info->dw_line_num;
12459 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12460 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12461 "line %lu", current_line);
12464 dw2_asm_output_data (1, DW_LNS_advance_line,
12465 "advance to line %lu", current_line);
12466 dw2_asm_output_data_sleb128 (line_offset, NULL);
12467 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12471 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
12479 /* If we're done with a function, end its sequence. */
12480 if (lt_index == separate_line_info_table_in_use
12481 || separate_line_info_table[lt_index].function != function)
12486 /* Emit debug info for the address of the end of the function. */
12487 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
12490 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
12491 "DW_LNS_fixed_advance_pc");
12492 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
12496 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
12497 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12498 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12499 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12502 /* Output the marker for the end of this sequence. */
12503 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
12504 dw2_asm_output_data_uleb128 (1, NULL);
12505 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12509 /* Output the marker for the end of the line number info. */
12510 ASM_OUTPUT_LABEL (asm_out_file, l2);
12513 /* Return the size of the .debug_dcall table for the compilation unit. */
12515 static unsigned long
12516 size_of_dcall_table (void)
12518 unsigned long size;
12521 tree last_poc_decl = NULL;
12523 /* Header: version + debug info section pointer + pointer size. */
12524 size = 2 + DWARF_OFFSET_SIZE + 1;
12526 /* Each entry: code label + DIE offset. */
12527 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12529 gcc_assert (p->targ_die != NULL);
12530 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12531 if (p->poc_decl != last_poc_decl)
12533 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12534 gcc_assert (poc_die);
12535 last_poc_decl = p->poc_decl;
12537 size += (DWARF_OFFSET_SIZE
12538 + size_of_uleb128 (poc_die->die_offset));
12540 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->targ_die->die_offset);
12546 /* Output the direct call table used to disambiguate PC values when
12547 identical function have been merged. */
12550 output_dcall_table (void)
12553 unsigned long dcall_length = size_of_dcall_table ();
12555 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12556 tree last_poc_decl = NULL;
12558 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12559 dw2_asm_output_data (4, 0xffffffff,
12560 "Initial length escape value indicating 64-bit DWARF extension");
12561 dw2_asm_output_data (DWARF_OFFSET_SIZE, dcall_length,
12562 "Length of Direct Call Table");
12563 dw2_asm_output_data (2, 4, "Version number");
12564 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
12565 debug_info_section,
12566 "Offset of Compilation Unit Info");
12567 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12569 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, p)
12571 /* Insert a "from" entry when the point-of-call DIE offset changes. */
12572 if (p->poc_decl != last_poc_decl)
12574 dw_die_ref poc_die = lookup_decl_die (p->poc_decl);
12575 last_poc_decl = p->poc_decl;
12578 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "New caller");
12579 dw2_asm_output_data_uleb128 (poc_die->die_offset,
12580 "Caller DIE offset");
12583 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12584 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12585 dw2_asm_output_data_uleb128 (p->targ_die->die_offset,
12586 "Callee DIE offset");
12590 /* Return the size of the .debug_vcall table for the compilation unit. */
12592 static unsigned long
12593 size_of_vcall_table (void)
12595 unsigned long size;
12599 /* Header: version + pointer size. */
12602 /* Each entry: code label + vtable slot index. */
12603 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12604 size += DWARF_OFFSET_SIZE + size_of_uleb128 (p->vtable_slot);
12609 /* Output the virtual call table used to disambiguate PC values when
12610 identical function have been merged. */
12613 output_vcall_table (void)
12616 unsigned long vcall_length = size_of_vcall_table ();
12618 char poc_label[MAX_ARTIFICIAL_LABEL_BYTES];
12620 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12621 dw2_asm_output_data (4, 0xffffffff,
12622 "Initial length escape value indicating 64-bit DWARF extension");
12623 dw2_asm_output_data (DWARF_OFFSET_SIZE, vcall_length,
12624 "Length of Virtual Call Table");
12625 dw2_asm_output_data (2, 4, "Version number");
12626 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
12628 FOR_EACH_VEC_ELT (vcall_entry, vcall_table, i, p)
12630 ASM_GENERATE_INTERNAL_LABEL (poc_label, "LPOC", p->poc_label_num);
12631 dw2_asm_output_addr (DWARF_OFFSET_SIZE, poc_label, "Point of call");
12632 dw2_asm_output_data_uleb128 (p->vtable_slot, "Vtable slot");
12636 /* Given a pointer to a tree node for some base type, return a pointer to
12637 a DIE that describes the given type.
12639 This routine must only be called for GCC type nodes that correspond to
12640 Dwarf base (fundamental) types. */
12643 base_type_die (tree type)
12645 dw_die_ref base_type_result;
12646 enum dwarf_type encoding;
12648 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12651 /* If this is a subtype that should not be emitted as a subrange type,
12652 use the base type. See subrange_type_for_debug_p. */
12653 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12654 type = TREE_TYPE (type);
12656 switch (TREE_CODE (type))
12659 if ((dwarf_version >= 4 || !dwarf_strict)
12660 && TYPE_NAME (type)
12661 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12662 && DECL_IS_BUILTIN (TYPE_NAME (type))
12663 && DECL_NAME (TYPE_NAME (type)))
12665 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12666 if (strcmp (name, "char16_t") == 0
12667 || strcmp (name, "char32_t") == 0)
12669 encoding = DW_ATE_UTF;
12673 if (TYPE_STRING_FLAG (type))
12675 if (TYPE_UNSIGNED (type))
12676 encoding = DW_ATE_unsigned_char;
12678 encoding = DW_ATE_signed_char;
12680 else if (TYPE_UNSIGNED (type))
12681 encoding = DW_ATE_unsigned;
12683 encoding = DW_ATE_signed;
12687 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12689 if (dwarf_version >= 3 || !dwarf_strict)
12690 encoding = DW_ATE_decimal_float;
12692 encoding = DW_ATE_lo_user;
12695 encoding = DW_ATE_float;
12698 case FIXED_POINT_TYPE:
12699 if (!(dwarf_version >= 3 || !dwarf_strict))
12700 encoding = DW_ATE_lo_user;
12701 else if (TYPE_UNSIGNED (type))
12702 encoding = DW_ATE_unsigned_fixed;
12704 encoding = DW_ATE_signed_fixed;
12707 /* Dwarf2 doesn't know anything about complex ints, so use
12708 a user defined type for it. */
12710 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12711 encoding = DW_ATE_complex_float;
12713 encoding = DW_ATE_lo_user;
12717 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12718 encoding = DW_ATE_boolean;
12722 /* No other TREE_CODEs are Dwarf fundamental types. */
12723 gcc_unreachable ();
12726 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12728 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12729 int_size_in_bytes (type));
12730 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12732 return base_type_result;
12735 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12736 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12739 is_base_type (tree type)
12741 switch (TREE_CODE (type))
12747 case FIXED_POINT_TYPE:
12755 case QUAL_UNION_TYPE:
12756 case ENUMERAL_TYPE:
12757 case FUNCTION_TYPE:
12760 case REFERENCE_TYPE:
12768 gcc_unreachable ();
12774 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12775 node, return the size in bits for the type if it is a constant, or else
12776 return the alignment for the type if the type's size is not constant, or
12777 else return BITS_PER_WORD if the type actually turns out to be an
12778 ERROR_MARK node. */
12780 static inline unsigned HOST_WIDE_INT
12781 simple_type_size_in_bits (const_tree type)
12783 if (TREE_CODE (type) == ERROR_MARK)
12784 return BITS_PER_WORD;
12785 else if (TYPE_SIZE (type) == NULL_TREE)
12787 else if (host_integerp (TYPE_SIZE (type), 1))
12788 return tree_low_cst (TYPE_SIZE (type), 1);
12790 return TYPE_ALIGN (type);
12793 /* Similarly, but return a double_int instead of UHWI. */
12795 static inline double_int
12796 double_int_type_size_in_bits (const_tree type)
12798 if (TREE_CODE (type) == ERROR_MARK)
12799 return uhwi_to_double_int (BITS_PER_WORD);
12800 else if (TYPE_SIZE (type) == NULL_TREE)
12801 return double_int_zero;
12802 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12803 return tree_to_double_int (TYPE_SIZE (type));
12805 return uhwi_to_double_int (TYPE_ALIGN (type));
12808 /* Given a pointer to a tree node for a subrange type, return a pointer
12809 to a DIE that describes the given type. */
12812 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12814 dw_die_ref subrange_die;
12815 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12817 if (context_die == NULL)
12818 context_die = comp_unit_die ();
12820 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12822 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12824 /* The size of the subrange type and its base type do not match,
12825 so we need to generate a size attribute for the subrange type. */
12826 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12830 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12832 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12834 return subrange_die;
12837 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12838 entry that chains various modifiers in front of the given type. */
12841 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12842 dw_die_ref context_die)
12844 enum tree_code code = TREE_CODE (type);
12845 dw_die_ref mod_type_die;
12846 dw_die_ref sub_die = NULL;
12847 tree item_type = NULL;
12848 tree qualified_type;
12849 tree name, low, high;
12851 if (code == ERROR_MARK)
12854 /* See if we already have the appropriately qualified variant of
12857 = get_qualified_type (type,
12858 ((is_const_type ? TYPE_QUAL_CONST : 0)
12859 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12861 if (qualified_type == sizetype
12862 && TYPE_NAME (qualified_type)
12863 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12865 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12867 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12868 && TYPE_PRECISION (t)
12869 == TYPE_PRECISION (qualified_type)
12870 && TYPE_UNSIGNED (t)
12871 == TYPE_UNSIGNED (qualified_type));
12872 qualified_type = t;
12875 /* If we do, then we can just use its DIE, if it exists. */
12876 if (qualified_type)
12878 mod_type_die = lookup_type_die (qualified_type);
12880 return mod_type_die;
12883 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12885 /* Handle C typedef types. */
12886 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12887 && !DECL_ARTIFICIAL (name))
12889 tree dtype = TREE_TYPE (name);
12891 if (qualified_type == dtype)
12893 /* For a named type, use the typedef. */
12894 gen_type_die (qualified_type, context_die);
12895 return lookup_type_die (qualified_type);
12897 else if (is_const_type < TYPE_READONLY (dtype)
12898 || is_volatile_type < TYPE_VOLATILE (dtype)
12899 || (is_const_type <= TYPE_READONLY (dtype)
12900 && is_volatile_type <= TYPE_VOLATILE (dtype)
12901 && DECL_ORIGINAL_TYPE (name) != type))
12902 /* cv-unqualified version of named type. Just use the unnamed
12903 type to which it refers. */
12904 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12905 is_const_type, is_volatile_type,
12907 /* Else cv-qualified version of named type; fall through. */
12912 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12913 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12915 else if (is_volatile_type)
12917 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12918 sub_die = modified_type_die (type, 0, 0, context_die);
12920 else if (code == POINTER_TYPE)
12922 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12923 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12924 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12925 item_type = TREE_TYPE (type);
12926 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12927 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12928 TYPE_ADDR_SPACE (item_type));
12930 else if (code == REFERENCE_TYPE)
12932 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
12933 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12936 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12937 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12938 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12939 item_type = TREE_TYPE (type);
12940 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12941 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12942 TYPE_ADDR_SPACE (item_type));
12944 else if (code == INTEGER_TYPE
12945 && TREE_TYPE (type) != NULL_TREE
12946 && subrange_type_for_debug_p (type, &low, &high))
12948 mod_type_die = subrange_type_die (type, low, high, context_die);
12949 item_type = TREE_TYPE (type);
12951 else if (is_base_type (type))
12952 mod_type_die = base_type_die (type);
12955 gen_type_die (type, context_die);
12957 /* We have to get the type_main_variant here (and pass that to the
12958 `lookup_type_die' routine) because the ..._TYPE node we have
12959 might simply be a *copy* of some original type node (where the
12960 copy was created to help us keep track of typedef names) and
12961 that copy might have a different TYPE_UID from the original
12963 if (TREE_CODE (type) != VECTOR_TYPE)
12964 return lookup_type_die (type_main_variant (type));
12966 /* Vectors have the debugging information in the type,
12967 not the main variant. */
12968 return lookup_type_die (type);
12971 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12972 don't output a DW_TAG_typedef, since there isn't one in the
12973 user's program; just attach a DW_AT_name to the type.
12974 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12975 if the base type already has the same name. */
12977 && ((TREE_CODE (name) != TYPE_DECL
12978 && (qualified_type == TYPE_MAIN_VARIANT (type)
12979 || (!is_const_type && !is_volatile_type)))
12980 || (TREE_CODE (name) == TYPE_DECL
12981 && TREE_TYPE (name) == qualified_type
12982 && DECL_NAME (name))))
12984 if (TREE_CODE (name) == TYPE_DECL)
12985 /* Could just call add_name_and_src_coords_attributes here,
12986 but since this is a builtin type it doesn't have any
12987 useful source coordinates anyway. */
12988 name = DECL_NAME (name);
12989 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12991 /* This probably indicates a bug. */
12992 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12993 add_name_attribute (mod_type_die, "__unknown__");
12995 if (qualified_type)
12996 equate_type_number_to_die (qualified_type, mod_type_die);
12999 /* We must do this after the equate_type_number_to_die call, in case
13000 this is a recursive type. This ensures that the modified_type_die
13001 recursion will terminate even if the type is recursive. Recursive
13002 types are possible in Ada. */
13003 sub_die = modified_type_die (item_type,
13004 TYPE_READONLY (item_type),
13005 TYPE_VOLATILE (item_type),
13008 if (sub_die != NULL)
13009 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
13011 return mod_type_die;
13014 /* Generate DIEs for the generic parameters of T.
13015 T must be either a generic type or a generic function.
13016 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
13019 gen_generic_params_dies (tree t)
13023 dw_die_ref die = NULL;
13025 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
13029 die = lookup_type_die (t);
13030 else if (DECL_P (t))
13031 die = lookup_decl_die (t);
13035 parms = lang_hooks.get_innermost_generic_parms (t);
13037 /* T has no generic parameter. It means T is neither a generic type
13038 or function. End of story. */
13041 parms_num = TREE_VEC_LENGTH (parms);
13042 args = lang_hooks.get_innermost_generic_args (t);
13043 for (i = 0; i < parms_num; i++)
13045 tree parm, arg, arg_pack_elems;
13047 parm = TREE_VEC_ELT (parms, i);
13048 arg = TREE_VEC_ELT (args, i);
13049 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
13050 gcc_assert (parm && TREE_VALUE (parm) && arg);
13052 if (parm && TREE_VALUE (parm) && arg)
13054 /* If PARM represents a template parameter pack,
13055 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
13056 by DW_TAG_template_*_parameter DIEs for the argument
13057 pack elements of ARG. Note that ARG would then be
13058 an argument pack. */
13059 if (arg_pack_elems)
13060 template_parameter_pack_die (TREE_VALUE (parm),
13064 generic_parameter_die (TREE_VALUE (parm), arg,
13065 true /* Emit DW_AT_name */, die);
13070 /* Create and return a DIE for PARM which should be
13071 the representation of a generic type parameter.
13072 For instance, in the C++ front end, PARM would be a template parameter.
13073 ARG is the argument to PARM.
13074 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
13076 PARENT_DIE is the parent DIE which the new created DIE should be added to,
13077 as a child node. */
13080 generic_parameter_die (tree parm, tree arg,
13082 dw_die_ref parent_die)
13084 dw_die_ref tmpl_die = NULL;
13085 const char *name = NULL;
13087 if (!parm || !DECL_NAME (parm) || !arg)
13090 /* We support non-type generic parameters and arguments,
13091 type generic parameters and arguments, as well as
13092 generic generic parameters (a.k.a. template template parameters in C++)
13094 if (TREE_CODE (parm) == PARM_DECL)
13095 /* PARM is a nontype generic parameter */
13096 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
13097 else if (TREE_CODE (parm) == TYPE_DECL)
13098 /* PARM is a type generic parameter. */
13099 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
13100 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13101 /* PARM is a generic generic parameter.
13102 Its DIE is a GNU extension. It shall have a
13103 DW_AT_name attribute to represent the name of the template template
13104 parameter, and a DW_AT_GNU_template_name attribute to represent the
13105 name of the template template argument. */
13106 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
13109 gcc_unreachable ();
13115 /* If PARM is a generic parameter pack, it means we are
13116 emitting debug info for a template argument pack element.
13117 In other terms, ARG is a template argument pack element.
13118 In that case, we don't emit any DW_AT_name attribute for
13122 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13124 add_AT_string (tmpl_die, DW_AT_name, name);
13127 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13129 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13130 TMPL_DIE should have a child DW_AT_type attribute that is set
13131 to the type of the argument to PARM, which is ARG.
13132 If PARM is a type generic parameter, TMPL_DIE should have a
13133 child DW_AT_type that is set to ARG. */
13134 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13135 add_type_attribute (tmpl_die, tmpl_type, 0,
13136 TREE_THIS_VOLATILE (tmpl_type),
13141 /* So TMPL_DIE is a DIE representing a
13142 a generic generic template parameter, a.k.a template template
13143 parameter in C++ and arg is a template. */
13145 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13146 to the name of the argument. */
13147 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13149 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13152 if (TREE_CODE (parm) == PARM_DECL)
13153 /* So PARM is a non-type generic parameter.
13154 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13155 attribute of TMPL_DIE which value represents the value
13157 We must be careful here:
13158 The value of ARG might reference some function decls.
13159 We might currently be emitting debug info for a generic
13160 type and types are emitted before function decls, we don't
13161 know if the function decls referenced by ARG will actually be
13162 emitted after cgraph computations.
13163 So must defer the generation of the DW_AT_const_value to
13164 after cgraph is ready. */
13165 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13171 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13172 PARM_PACK must be a template parameter pack. The returned DIE
13173 will be child DIE of PARENT_DIE. */
13176 template_parameter_pack_die (tree parm_pack,
13177 tree parm_pack_args,
13178 dw_die_ref parent_die)
13183 gcc_assert (parent_die && parm_pack);
13185 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13186 add_name_and_src_coords_attributes (die, parm_pack);
13187 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13188 generic_parameter_die (parm_pack,
13189 TREE_VEC_ELT (parm_pack_args, j),
13190 false /* Don't emit DW_AT_name */,
13195 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13196 an enumerated type. */
13199 type_is_enum (const_tree type)
13201 return TREE_CODE (type) == ENUMERAL_TYPE;
13204 /* Return the DBX register number described by a given RTL node. */
13206 static unsigned int
13207 dbx_reg_number (const_rtx rtl)
13209 unsigned regno = REGNO (rtl);
13211 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13213 #ifdef LEAF_REG_REMAP
13214 if (current_function_uses_only_leaf_regs)
13216 int leaf_reg = LEAF_REG_REMAP (regno);
13217 if (leaf_reg != -1)
13218 regno = (unsigned) leaf_reg;
13222 return DBX_REGISTER_NUMBER (regno);
13225 /* Optionally add a DW_OP_piece term to a location description expression.
13226 DW_OP_piece is only added if the location description expression already
13227 doesn't end with DW_OP_piece. */
13230 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13232 dw_loc_descr_ref loc;
13234 if (*list_head != NULL)
13236 /* Find the end of the chain. */
13237 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13240 if (loc->dw_loc_opc != DW_OP_piece)
13241 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13245 /* Return a location descriptor that designates a machine register or
13246 zero if there is none. */
13248 static dw_loc_descr_ref
13249 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13253 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13256 /* We only use "frame base" when we're sure we're talking about the
13257 post-prologue local stack frame. We do this by *not* running
13258 register elimination until this point, and recognizing the special
13259 argument pointer and soft frame pointer rtx's.
13260 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13261 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13262 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13264 dw_loc_descr_ref result = NULL;
13266 if (dwarf_version >= 4 || !dwarf_strict)
13268 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13270 add_loc_descr (&result,
13271 new_loc_descr (DW_OP_stack_value, 0, 0));
13276 regs = targetm.dwarf_register_span (rtl);
13278 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13279 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13281 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13284 /* Return a location descriptor that designates a machine register for
13285 a given hard register number. */
13287 static dw_loc_descr_ref
13288 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13290 dw_loc_descr_ref reg_loc_descr;
13294 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13296 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13298 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13299 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13301 return reg_loc_descr;
13304 /* Given an RTL of a register, return a location descriptor that
13305 designates a value that spans more than one register. */
13307 static dw_loc_descr_ref
13308 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13309 enum var_init_status initialized)
13311 int nregs, size, i;
13313 dw_loc_descr_ref loc_result = NULL;
13316 #ifdef LEAF_REG_REMAP
13317 if (current_function_uses_only_leaf_regs)
13319 int leaf_reg = LEAF_REG_REMAP (reg);
13320 if (leaf_reg != -1)
13321 reg = (unsigned) leaf_reg;
13324 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13325 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13327 /* Simple, contiguous registers. */
13328 if (regs == NULL_RTX)
13330 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13335 dw_loc_descr_ref t;
13337 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13338 VAR_INIT_STATUS_INITIALIZED);
13339 add_loc_descr (&loc_result, t);
13340 add_loc_descr_op_piece (&loc_result, size);
13346 /* Now onto stupid register sets in non contiguous locations. */
13348 gcc_assert (GET_CODE (regs) == PARALLEL);
13350 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13353 for (i = 0; i < XVECLEN (regs, 0); ++i)
13355 dw_loc_descr_ref t;
13357 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13358 VAR_INIT_STATUS_INITIALIZED);
13359 add_loc_descr (&loc_result, t);
13360 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13361 add_loc_descr_op_piece (&loc_result, size);
13364 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13365 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13369 /* Return a location descriptor that designates a constant. */
13371 static dw_loc_descr_ref
13372 int_loc_descriptor (HOST_WIDE_INT i)
13374 enum dwarf_location_atom op;
13376 /* Pick the smallest representation of a constant, rather than just
13377 defaulting to the LEB encoding. */
13381 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13382 else if (i <= 0xff)
13383 op = DW_OP_const1u;
13384 else if (i <= 0xffff)
13385 op = DW_OP_const2u;
13386 else if (HOST_BITS_PER_WIDE_INT == 32
13387 || i <= 0xffffffff)
13388 op = DW_OP_const4u;
13395 op = DW_OP_const1s;
13396 else if (i >= -0x8000)
13397 op = DW_OP_const2s;
13398 else if (HOST_BITS_PER_WIDE_INT == 32
13399 || i >= -0x80000000)
13400 op = DW_OP_const4s;
13405 return new_loc_descr (op, i, 0);
13408 /* Return loc description representing "address" of integer value.
13409 This can appear only as toplevel expression. */
13411 static dw_loc_descr_ref
13412 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13415 dw_loc_descr_ref loc_result = NULL;
13417 if (!(dwarf_version >= 4 || !dwarf_strict))
13424 else if (i <= 0xff)
13426 else if (i <= 0xffff)
13428 else if (HOST_BITS_PER_WIDE_INT == 32
13429 || i <= 0xffffffff)
13432 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13438 else if (i >= -0x8000)
13440 else if (HOST_BITS_PER_WIDE_INT == 32
13441 || i >= -0x80000000)
13444 litsize = 1 + size_of_sleb128 (i);
13446 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13447 is more compact. For DW_OP_stack_value we need:
13448 litsize + 1 (DW_OP_stack_value)
13449 and for DW_OP_implicit_value:
13450 1 (DW_OP_implicit_value) + 1 (length) + size. */
13451 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13453 loc_result = int_loc_descriptor (i);
13454 add_loc_descr (&loc_result,
13455 new_loc_descr (DW_OP_stack_value, 0, 0));
13459 loc_result = new_loc_descr (DW_OP_implicit_value,
13461 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13462 loc_result->dw_loc_oprnd2.v.val_int = i;
13466 /* Return a location descriptor that designates a base+offset location. */
13468 static dw_loc_descr_ref
13469 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13470 enum var_init_status initialized)
13472 unsigned int regno;
13473 dw_loc_descr_ref result;
13474 dw_fde_ref fde = current_fde ();
13476 /* We only use "frame base" when we're sure we're talking about the
13477 post-prologue local stack frame. We do this by *not* running
13478 register elimination until this point, and recognizing the special
13479 argument pointer and soft frame pointer rtx's. */
13480 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13482 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13486 if (GET_CODE (elim) == PLUS)
13488 offset += INTVAL (XEXP (elim, 1));
13489 elim = XEXP (elim, 0);
13491 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13492 && (elim == hard_frame_pointer_rtx
13493 || elim == stack_pointer_rtx))
13494 || elim == (frame_pointer_needed
13495 ? hard_frame_pointer_rtx
13496 : stack_pointer_rtx));
13498 /* If drap register is used to align stack, use frame
13499 pointer + offset to access stack variables. If stack
13500 is aligned without drap, use stack pointer + offset to
13501 access stack variables. */
13502 if (crtl->stack_realign_tried
13503 && reg == frame_pointer_rtx)
13506 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13507 ? HARD_FRAME_POINTER_REGNUM
13508 : STACK_POINTER_REGNUM);
13509 return new_reg_loc_descr (base_reg, offset);
13512 offset += frame_pointer_fb_offset;
13513 return new_loc_descr (DW_OP_fbreg, offset, 0);
13518 && (fde->drap_reg == REGNO (reg)
13519 || fde->vdrap_reg == REGNO (reg)))
13521 /* Use cfa+offset to represent the location of arguments passed
13522 on the stack when drap is used to align stack.
13523 Only do this when not optimizing, for optimized code var-tracking
13524 is supposed to track where the arguments live and the register
13525 used as vdrap or drap in some spot might be used for something
13526 else in other part of the routine. */
13527 return new_loc_descr (DW_OP_fbreg, offset, 0);
13530 regno = dbx_reg_number (reg);
13532 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13535 result = new_loc_descr (DW_OP_bregx, regno, offset);
13537 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13538 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13543 /* Return true if this RTL expression describes a base+offset calculation. */
13546 is_based_loc (const_rtx rtl)
13548 return (GET_CODE (rtl) == PLUS
13549 && ((REG_P (XEXP (rtl, 0))
13550 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13551 && CONST_INT_P (XEXP (rtl, 1)))));
13554 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13557 static dw_loc_descr_ref
13558 tls_mem_loc_descriptor (rtx mem)
13561 dw_loc_descr_ref loc_result;
13563 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13566 base = get_base_address (MEM_EXPR (mem));
13568 || TREE_CODE (base) != VAR_DECL
13569 || !DECL_THREAD_LOCAL_P (base))
13572 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13573 if (loc_result == NULL)
13576 if (INTVAL (MEM_OFFSET (mem)))
13577 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13582 /* Output debug info about reason why we failed to expand expression as dwarf
13586 expansion_failed (tree expr, rtx rtl, char const *reason)
13588 if (dump_file && (dump_flags & TDF_DETAILS))
13590 fprintf (dump_file, "Failed to expand as dwarf: ");
13592 print_generic_expr (dump_file, expr, dump_flags);
13595 fprintf (dump_file, "\n");
13596 print_rtl (dump_file, rtl);
13598 fprintf (dump_file, "\nReason: %s\n", reason);
13602 /* Helper function for const_ok_for_output, called either directly
13603 or via for_each_rtx. */
13606 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13610 if (GET_CODE (rtl) == UNSPEC)
13612 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13613 we can't express it in the debug info. */
13614 #ifdef ENABLE_CHECKING
13615 /* Don't complain about TLS UNSPECs, those are just too hard to
13617 if (XVECLEN (rtl, 0) != 1
13618 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13619 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13620 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13621 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13622 inform (current_function_decl
13623 ? DECL_SOURCE_LOCATION (current_function_decl)
13624 : UNKNOWN_LOCATION,
13625 "non-delegitimized UNSPEC %d found in variable location",
13628 expansion_failed (NULL_TREE, rtl,
13629 "UNSPEC hasn't been delegitimized.\n");
13633 if (GET_CODE (rtl) != SYMBOL_REF)
13636 if (CONSTANT_POOL_ADDRESS_P (rtl))
13639 get_pool_constant_mark (rtl, &marked);
13640 /* If all references to this pool constant were optimized away,
13641 it was not output and thus we can't represent it. */
13644 expansion_failed (NULL_TREE, rtl,
13645 "Constant was removed from constant pool.\n");
13650 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13653 /* Avoid references to external symbols in debug info, on several targets
13654 the linker might even refuse to link when linking a shared library,
13655 and in many other cases the relocations for .debug_info/.debug_loc are
13656 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13657 to be defined within the same shared library or executable are fine. */
13658 if (SYMBOL_REF_EXTERNAL_P (rtl))
13660 tree decl = SYMBOL_REF_DECL (rtl);
13662 if (decl == NULL || !targetm.binds_local_p (decl))
13664 expansion_failed (NULL_TREE, rtl,
13665 "Symbol not defined in current TU.\n");
13673 /* Return true if constant RTL can be emitted in DW_OP_addr or
13674 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13675 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13678 const_ok_for_output (rtx rtl)
13680 if (GET_CODE (rtl) == SYMBOL_REF)
13681 return const_ok_for_output_1 (&rtl, NULL) == 0;
13683 if (GET_CODE (rtl) == CONST)
13684 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13689 /* The following routine converts the RTL for a variable or parameter
13690 (resident in memory) into an equivalent Dwarf representation of a
13691 mechanism for getting the address of that same variable onto the top of a
13692 hypothetical "address evaluation" stack.
13694 When creating memory location descriptors, we are effectively transforming
13695 the RTL for a memory-resident object into its Dwarf postfix expression
13696 equivalent. This routine recursively descends an RTL tree, turning
13697 it into Dwarf postfix code as it goes.
13699 MODE is the mode of the memory reference, needed to handle some
13700 autoincrement addressing modes.
13702 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13703 location list for RTL.
13705 Return 0 if we can't represent the location. */
13707 static dw_loc_descr_ref
13708 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13709 enum var_init_status initialized)
13711 dw_loc_descr_ref mem_loc_result = NULL;
13712 enum dwarf_location_atom op;
13713 dw_loc_descr_ref op0, op1;
13715 /* Note that for a dynamically sized array, the location we will generate a
13716 description of here will be the lowest numbered location which is
13717 actually within the array. That's *not* necessarily the same as the
13718 zeroth element of the array. */
13720 rtl = targetm.delegitimize_address (rtl);
13722 switch (GET_CODE (rtl))
13727 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13730 /* The case of a subreg may arise when we have a local (register)
13731 variable or a formal (register) parameter which doesn't quite fill
13732 up an entire register. For now, just assume that it is
13733 legitimate to make the Dwarf info refer to the whole register which
13734 contains the given subreg. */
13735 if (!subreg_lowpart_p (rtl))
13737 rtl = SUBREG_REG (rtl);
13738 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13740 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13742 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13746 /* Whenever a register number forms a part of the description of the
13747 method for calculating the (dynamic) address of a memory resident
13748 object, DWARF rules require the register number be referred to as
13749 a "base register". This distinction is not based in any way upon
13750 what category of register the hardware believes the given register
13751 belongs to. This is strictly DWARF terminology we're dealing with
13752 here. Note that in cases where the location of a memory-resident
13753 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13754 OP_CONST (0)) the actual DWARF location descriptor that we generate
13755 may just be OP_BASEREG (basereg). This may look deceptively like
13756 the object in question was allocated to a register (rather than in
13757 memory) so DWARF consumers need to be aware of the subtle
13758 distinction between OP_REG and OP_BASEREG. */
13759 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13760 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13761 else if (stack_realign_drap
13763 && crtl->args.internal_arg_pointer == rtl
13764 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13766 /* If RTL is internal_arg_pointer, which has been optimized
13767 out, use DRAP instead. */
13768 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13769 VAR_INIT_STATUS_INITIALIZED);
13775 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13776 VAR_INIT_STATUS_INITIALIZED);
13781 int shift = DWARF2_ADDR_SIZE
13782 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13783 shift *= BITS_PER_UNIT;
13784 if (GET_CODE (rtl) == SIGN_EXTEND)
13788 mem_loc_result = op0;
13789 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13790 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13791 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13792 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13797 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13798 VAR_INIT_STATUS_INITIALIZED);
13799 if (mem_loc_result == NULL)
13800 mem_loc_result = tls_mem_loc_descriptor (rtl);
13801 if (mem_loc_result != 0)
13803 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13805 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13808 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13809 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13811 add_loc_descr (&mem_loc_result,
13812 new_loc_descr (DW_OP_deref_size,
13813 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13817 rtx new_rtl = avoid_constant_pool_reference (rtl);
13818 if (new_rtl != rtl)
13819 return mem_loc_descriptor (new_rtl, mode, initialized);
13824 rtl = XEXP (rtl, 1);
13826 /* ... fall through ... */
13829 /* Some ports can transform a symbol ref into a label ref, because
13830 the symbol ref is too far away and has to be dumped into a constant
13834 if (GET_CODE (rtl) == SYMBOL_REF
13835 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13837 dw_loc_descr_ref temp;
13839 /* If this is not defined, we have no way to emit the data. */
13840 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13843 /* We used to emit DW_OP_addr here, but that's wrong, since
13844 DW_OP_addr should be relocated by the debug info consumer,
13845 while DW_OP_GNU_push_tls_address operand should not. */
13846 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13847 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13848 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13849 temp->dw_loc_oprnd1.v.val_addr = rtl;
13850 temp->dtprel = true;
13852 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13853 add_loc_descr (&mem_loc_result, temp);
13858 if (!const_ok_for_output (rtl))
13862 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13863 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13864 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13865 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13871 case DEBUG_IMPLICIT_PTR:
13872 expansion_failed (NULL_TREE, rtl,
13873 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13877 /* Extract the PLUS expression nested inside and fall into
13878 PLUS code below. */
13879 rtl = XEXP (rtl, 1);
13884 /* Turn these into a PLUS expression and fall into the PLUS code
13886 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13887 GEN_INT (GET_CODE (rtl) == PRE_INC
13888 ? GET_MODE_UNIT_SIZE (mode)
13889 : -GET_MODE_UNIT_SIZE (mode)));
13891 /* ... fall through ... */
13895 if (is_based_loc (rtl))
13896 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13897 INTVAL (XEXP (rtl, 1)),
13898 VAR_INIT_STATUS_INITIALIZED);
13901 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13902 VAR_INIT_STATUS_INITIALIZED);
13903 if (mem_loc_result == 0)
13906 if (CONST_INT_P (XEXP (rtl, 1)))
13907 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13910 dw_loc_descr_ref mem_loc_result2
13911 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13912 VAR_INIT_STATUS_INITIALIZED);
13913 if (mem_loc_result2 == 0)
13915 add_loc_descr (&mem_loc_result, mem_loc_result2);
13916 add_loc_descr (&mem_loc_result,
13917 new_loc_descr (DW_OP_plus, 0, 0));
13922 /* If a pseudo-reg is optimized away, it is possible for it to
13923 be replaced with a MEM containing a multiply or shift. */
13965 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13966 VAR_INIT_STATUS_INITIALIZED);
13967 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13968 VAR_INIT_STATUS_INITIALIZED);
13970 if (op0 == 0 || op1 == 0)
13973 mem_loc_result = op0;
13974 add_loc_descr (&mem_loc_result, op1);
13975 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13979 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13980 VAR_INIT_STATUS_INITIALIZED);
13981 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13982 VAR_INIT_STATUS_INITIALIZED);
13984 if (op0 == 0 || op1 == 0)
13987 mem_loc_result = op0;
13988 add_loc_descr (&mem_loc_result, op1);
13989 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13990 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13991 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13992 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13993 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
14009 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14010 VAR_INIT_STATUS_INITIALIZED);
14015 mem_loc_result = op0;
14016 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14020 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
14048 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14049 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14053 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14055 if (op_mode == VOIDmode)
14056 op_mode = GET_MODE (XEXP (rtl, 1));
14057 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14060 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14061 VAR_INIT_STATUS_INITIALIZED);
14062 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14063 VAR_INIT_STATUS_INITIALIZED);
14065 if (op0 == 0 || op1 == 0)
14068 if (op_mode != VOIDmode
14069 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14071 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
14072 shift *= BITS_PER_UNIT;
14073 /* For eq/ne, if the operands are known to be zero-extended,
14074 there is no need to do the fancy shifting up. */
14075 if (op == DW_OP_eq || op == DW_OP_ne)
14077 dw_loc_descr_ref last0, last1;
14079 last0->dw_loc_next != NULL;
14080 last0 = last0->dw_loc_next)
14083 last1->dw_loc_next != NULL;
14084 last1 = last1->dw_loc_next)
14086 /* deref_size zero extends, and for constants we can check
14087 whether they are zero extended or not. */
14088 if (((last0->dw_loc_opc == DW_OP_deref_size
14089 && last0->dw_loc_oprnd1.v.val_int
14090 <= GET_MODE_SIZE (op_mode))
14091 || (CONST_INT_P (XEXP (rtl, 0))
14092 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
14093 == (INTVAL (XEXP (rtl, 0))
14094 & GET_MODE_MASK (op_mode))))
14095 && ((last1->dw_loc_opc == DW_OP_deref_size
14096 && last1->dw_loc_oprnd1.v.val_int
14097 <= GET_MODE_SIZE (op_mode))
14098 || (CONST_INT_P (XEXP (rtl, 1))
14099 && (unsigned HOST_WIDE_INT)
14100 INTVAL (XEXP (rtl, 1))
14101 == (INTVAL (XEXP (rtl, 1))
14102 & GET_MODE_MASK (op_mode)))))
14105 add_loc_descr (&op0, int_loc_descriptor (shift));
14106 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14107 if (CONST_INT_P (XEXP (rtl, 1)))
14108 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14111 add_loc_descr (&op1, int_loc_descriptor (shift));
14112 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14118 mem_loc_result = op0;
14119 add_loc_descr (&mem_loc_result, op1);
14120 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14121 if (STORE_FLAG_VALUE != 1)
14123 add_loc_descr (&mem_loc_result,
14124 int_loc_descriptor (STORE_FLAG_VALUE));
14125 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14146 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14147 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14151 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14153 if (op_mode == VOIDmode)
14154 op_mode = GET_MODE (XEXP (rtl, 1));
14155 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14158 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14159 VAR_INIT_STATUS_INITIALIZED);
14160 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14161 VAR_INIT_STATUS_INITIALIZED);
14163 if (op0 == 0 || op1 == 0)
14166 if (op_mode != VOIDmode
14167 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14169 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14170 dw_loc_descr_ref last0, last1;
14172 last0->dw_loc_next != NULL;
14173 last0 = last0->dw_loc_next)
14176 last1->dw_loc_next != NULL;
14177 last1 = last1->dw_loc_next)
14179 if (CONST_INT_P (XEXP (rtl, 0)))
14180 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14181 /* deref_size zero extends, so no need to mask it again. */
14182 else if (last0->dw_loc_opc != DW_OP_deref_size
14183 || last0->dw_loc_oprnd1.v.val_int
14184 > GET_MODE_SIZE (op_mode))
14186 add_loc_descr (&op0, int_loc_descriptor (mask));
14187 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14189 if (CONST_INT_P (XEXP (rtl, 1)))
14190 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14191 /* deref_size zero extends, so no need to mask it again. */
14192 else if (last1->dw_loc_opc != DW_OP_deref_size
14193 || last1->dw_loc_oprnd1.v.val_int
14194 > GET_MODE_SIZE (op_mode))
14196 add_loc_descr (&op1, int_loc_descriptor (mask));
14197 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14202 HOST_WIDE_INT bias = 1;
14203 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14204 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14205 if (CONST_INT_P (XEXP (rtl, 1)))
14206 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14207 + INTVAL (XEXP (rtl, 1)));
14209 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14219 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14220 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14221 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14224 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14225 VAR_INIT_STATUS_INITIALIZED);
14226 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14227 VAR_INIT_STATUS_INITIALIZED);
14229 if (op0 == 0 || op1 == 0)
14232 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14233 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14234 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14235 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14237 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14239 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14240 add_loc_descr (&op0, int_loc_descriptor (mask));
14241 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14242 add_loc_descr (&op1, int_loc_descriptor (mask));
14243 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14247 HOST_WIDE_INT bias = 1;
14248 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14249 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14250 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14253 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14255 int shift = DWARF2_ADDR_SIZE
14256 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14257 shift *= BITS_PER_UNIT;
14258 add_loc_descr (&op0, int_loc_descriptor (shift));
14259 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14260 add_loc_descr (&op1, int_loc_descriptor (shift));
14261 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14264 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14268 mem_loc_result = op0;
14269 add_loc_descr (&mem_loc_result, op1);
14270 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14272 dw_loc_descr_ref bra_node, drop_node;
14274 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14275 add_loc_descr (&mem_loc_result, bra_node);
14276 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14277 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14278 add_loc_descr (&mem_loc_result, drop_node);
14279 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14280 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14286 if (CONST_INT_P (XEXP (rtl, 1))
14287 && CONST_INT_P (XEXP (rtl, 2))
14288 && ((unsigned) INTVAL (XEXP (rtl, 1))
14289 + (unsigned) INTVAL (XEXP (rtl, 2))
14290 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14291 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14292 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14295 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14296 VAR_INIT_STATUS_INITIALIZED);
14299 if (GET_CODE (rtl) == SIGN_EXTRACT)
14303 mem_loc_result = op0;
14304 size = INTVAL (XEXP (rtl, 1));
14305 shift = INTVAL (XEXP (rtl, 2));
14306 if (BITS_BIG_ENDIAN)
14307 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14309 if (shift + size != (int) DWARF2_ADDR_SIZE)
14311 add_loc_descr (&mem_loc_result,
14312 int_loc_descriptor (DWARF2_ADDR_SIZE
14314 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14316 if (size != (int) DWARF2_ADDR_SIZE)
14318 add_loc_descr (&mem_loc_result,
14319 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14320 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14327 dw_loc_descr_ref op2, bra_node, drop_node;
14328 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14329 VAR_INIT_STATUS_INITIALIZED);
14330 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14331 VAR_INIT_STATUS_INITIALIZED);
14332 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14333 VAR_INIT_STATUS_INITIALIZED);
14334 if (op0 == NULL || op1 == NULL || op2 == NULL)
14337 mem_loc_result = op1;
14338 add_loc_descr (&mem_loc_result, op2);
14339 add_loc_descr (&mem_loc_result, op0);
14340 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14341 add_loc_descr (&mem_loc_result, bra_node);
14342 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14343 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14344 add_loc_descr (&mem_loc_result, drop_node);
14345 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14346 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14354 /* In theory, we could implement the above. */
14355 /* DWARF cannot represent the unsigned compare operations
14382 case FLOAT_TRUNCATE:
14384 case UNSIGNED_FLOAT:
14387 case FRACT_CONVERT:
14388 case UNSIGNED_FRACT_CONVERT:
14390 case UNSIGNED_SAT_FRACT:
14402 case VEC_DUPLICATE:
14405 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14406 can't express it in the debug info. This can happen e.g. with some
14411 resolve_one_addr (&rtl, NULL);
14415 #ifdef ENABLE_CHECKING
14416 print_rtl (stderr, rtl);
14417 gcc_unreachable ();
14423 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14424 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14426 return mem_loc_result;
14429 /* Return a descriptor that describes the concatenation of two locations.
14430 This is typically a complex variable. */
14432 static dw_loc_descr_ref
14433 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14435 dw_loc_descr_ref cc_loc_result = NULL;
14436 dw_loc_descr_ref x0_ref
14437 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14438 dw_loc_descr_ref x1_ref
14439 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14441 if (x0_ref == 0 || x1_ref == 0)
14444 cc_loc_result = x0_ref;
14445 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14447 add_loc_descr (&cc_loc_result, x1_ref);
14448 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14450 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14451 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14453 return cc_loc_result;
14456 /* Return a descriptor that describes the concatenation of N
14459 static dw_loc_descr_ref
14460 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14463 dw_loc_descr_ref cc_loc_result = NULL;
14464 unsigned int n = XVECLEN (concatn, 0);
14466 for (i = 0; i < n; ++i)
14468 dw_loc_descr_ref ref;
14469 rtx x = XVECEXP (concatn, 0, i);
14471 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14475 add_loc_descr (&cc_loc_result, ref);
14476 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14479 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14480 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14482 return cc_loc_result;
14485 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14486 for DEBUG_IMPLICIT_PTR RTL. */
14488 static dw_loc_descr_ref
14489 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14491 dw_loc_descr_ref ret;
14496 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14497 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14498 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14499 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14500 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14501 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14504 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14505 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14506 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14510 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14511 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14516 /* Output a proper Dwarf location descriptor for a variable or parameter
14517 which is either allocated in a register or in a memory location. For a
14518 register, we just generate an OP_REG and the register number. For a
14519 memory location we provide a Dwarf postfix expression describing how to
14520 generate the (dynamic) address of the object onto the address stack.
14522 MODE is mode of the decl if this loc_descriptor is going to be used in
14523 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14524 allowed, VOIDmode otherwise.
14526 If we don't know how to describe it, return 0. */
14528 static dw_loc_descr_ref
14529 loc_descriptor (rtx rtl, enum machine_mode mode,
14530 enum var_init_status initialized)
14532 dw_loc_descr_ref loc_result = NULL;
14534 switch (GET_CODE (rtl))
14537 /* The case of a subreg may arise when we have a local (register)
14538 variable or a formal (register) parameter which doesn't quite fill
14539 up an entire register. For now, just assume that it is
14540 legitimate to make the Dwarf info refer to the whole register which
14541 contains the given subreg. */
14542 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14546 loc_result = reg_loc_descriptor (rtl, initialized);
14550 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14552 if (loc_result == NULL)
14553 loc_result = tls_mem_loc_descriptor (rtl);
14554 if (loc_result == NULL)
14556 rtx new_rtl = avoid_constant_pool_reference (rtl);
14557 if (new_rtl != rtl)
14558 loc_result = loc_descriptor (new_rtl, mode, initialized);
14563 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14568 loc_result = concatn_loc_descriptor (rtl, initialized);
14573 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14575 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14576 if (GET_CODE (loc) == EXPR_LIST)
14577 loc = XEXP (loc, 0);
14578 loc_result = loc_descriptor (loc, mode, initialized);
14582 rtl = XEXP (rtl, 1);
14587 rtvec par_elems = XVEC (rtl, 0);
14588 int num_elem = GET_NUM_ELEM (par_elems);
14589 enum machine_mode mode;
14592 /* Create the first one, so we have something to add to. */
14593 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14594 VOIDmode, initialized);
14595 if (loc_result == NULL)
14597 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14598 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14599 for (i = 1; i < num_elem; i++)
14601 dw_loc_descr_ref temp;
14603 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14604 VOIDmode, initialized);
14607 add_loc_descr (&loc_result, temp);
14608 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14609 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14615 if (mode != VOIDmode && mode != BLKmode)
14616 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14621 if (mode == VOIDmode)
14622 mode = GET_MODE (rtl);
14624 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14626 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14628 /* Note that a CONST_DOUBLE rtx could represent either an integer
14629 or a floating-point constant. A CONST_DOUBLE is used whenever
14630 the constant requires more than one word in order to be
14631 adequately represented. We output CONST_DOUBLEs as blocks. */
14632 loc_result = new_loc_descr (DW_OP_implicit_value,
14633 GET_MODE_SIZE (mode), 0);
14634 if (SCALAR_FLOAT_MODE_P (mode))
14636 unsigned int length = GET_MODE_SIZE (mode);
14637 unsigned char *array
14638 = (unsigned char*) ggc_alloc_atomic (length);
14640 insert_float (rtl, array);
14641 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14642 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14643 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14644 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14648 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14649 loc_result->dw_loc_oprnd2.v.val_double
14650 = rtx_to_double_int (rtl);
14656 if (mode == VOIDmode)
14657 mode = GET_MODE (rtl);
14659 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14661 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14662 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14663 unsigned char *array = (unsigned char *)
14664 ggc_alloc_atomic (length * elt_size);
14668 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14669 switch (GET_MODE_CLASS (mode))
14671 case MODE_VECTOR_INT:
14672 for (i = 0, p = array; i < length; i++, p += elt_size)
14674 rtx elt = CONST_VECTOR_ELT (rtl, i);
14675 double_int val = rtx_to_double_int (elt);
14677 if (elt_size <= sizeof (HOST_WIDE_INT))
14678 insert_int (double_int_to_shwi (val), elt_size, p);
14681 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14682 insert_double (val, p);
14687 case MODE_VECTOR_FLOAT:
14688 for (i = 0, p = array; i < length; i++, p += elt_size)
14690 rtx elt = CONST_VECTOR_ELT (rtl, i);
14691 insert_float (elt, p);
14696 gcc_unreachable ();
14699 loc_result = new_loc_descr (DW_OP_implicit_value,
14700 length * elt_size, 0);
14701 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14702 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14703 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14704 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14709 if (mode == VOIDmode
14710 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14711 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14712 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14714 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14719 if (!const_ok_for_output (rtl))
14722 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14723 && (dwarf_version >= 4 || !dwarf_strict))
14725 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14726 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14727 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14728 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14729 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14733 case DEBUG_IMPLICIT_PTR:
14734 loc_result = implicit_ptr_descriptor (rtl, 0);
14738 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14739 && CONST_INT_P (XEXP (rtl, 1)))
14742 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14747 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14748 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14749 && (dwarf_version >= 4 || !dwarf_strict))
14751 /* Value expression. */
14752 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14754 add_loc_descr (&loc_result,
14755 new_loc_descr (DW_OP_stack_value, 0, 0));
14763 /* We need to figure out what section we should use as the base for the
14764 address ranges where a given location is valid.
14765 1. If this particular DECL has a section associated with it, use that.
14766 2. If this function has a section associated with it, use that.
14767 3. Otherwise, use the text section.
14768 XXX: If you split a variable across multiple sections, we won't notice. */
14770 static const char *
14771 secname_for_decl (const_tree decl)
14773 const char *secname;
14775 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14777 tree sectree = DECL_SECTION_NAME (decl);
14778 secname = TREE_STRING_POINTER (sectree);
14780 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14782 tree sectree = DECL_SECTION_NAME (current_function_decl);
14783 secname = TREE_STRING_POINTER (sectree);
14785 else if (cfun && in_cold_section_p)
14786 secname = crtl->subsections.cold_section_label;
14788 secname = text_section_label;
14793 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14796 decl_by_reference_p (tree decl)
14798 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14799 || TREE_CODE (decl) == VAR_DECL)
14800 && DECL_BY_REFERENCE (decl));
14803 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14806 static dw_loc_descr_ref
14807 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14808 enum var_init_status initialized)
14810 int have_address = 0;
14811 dw_loc_descr_ref descr;
14812 enum machine_mode mode;
14814 if (want_address != 2)
14816 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14818 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14820 varloc = PAT_VAR_LOCATION_LOC (varloc);
14821 if (GET_CODE (varloc) == EXPR_LIST)
14822 varloc = XEXP (varloc, 0);
14823 mode = GET_MODE (varloc);
14824 if (MEM_P (varloc))
14826 rtx addr = XEXP (varloc, 0);
14827 descr = mem_loc_descriptor (addr, mode, initialized);
14832 rtx x = avoid_constant_pool_reference (varloc);
14834 descr = mem_loc_descriptor (x, mode, initialized);
14838 descr = mem_loc_descriptor (varloc, mode, initialized);
14845 if (GET_CODE (varloc) == VAR_LOCATION)
14846 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14848 mode = DECL_MODE (loc);
14849 descr = loc_descriptor (varloc, mode, initialized);
14856 if (want_address == 2 && !have_address
14857 && (dwarf_version >= 4 || !dwarf_strict))
14859 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14861 expansion_failed (loc, NULL_RTX,
14862 "DWARF address size mismatch");
14865 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14868 /* Show if we can't fill the request for an address. */
14869 if (want_address && !have_address)
14871 expansion_failed (loc, NULL_RTX,
14872 "Want address and only have value");
14876 /* If we've got an address and don't want one, dereference. */
14877 if (!want_address && have_address)
14879 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14880 enum dwarf_location_atom op;
14882 if (size > DWARF2_ADDR_SIZE || size == -1)
14884 expansion_failed (loc, NULL_RTX,
14885 "DWARF address size mismatch");
14888 else if (size == DWARF2_ADDR_SIZE)
14891 op = DW_OP_deref_size;
14893 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14899 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14900 if it is not possible. */
14902 static dw_loc_descr_ref
14903 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14905 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14906 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14907 else if (dwarf_version >= 3 || !dwarf_strict)
14908 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14913 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14914 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14916 static dw_loc_descr_ref
14917 dw_sra_loc_expr (tree decl, rtx loc)
14920 unsigned int padsize = 0;
14921 dw_loc_descr_ref descr, *descr_tail;
14922 unsigned HOST_WIDE_INT decl_size;
14924 enum var_init_status initialized;
14926 if (DECL_SIZE (decl) == NULL
14927 || !host_integerp (DECL_SIZE (decl), 1))
14930 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14932 descr_tail = &descr;
14934 for (p = loc; p; p = XEXP (p, 1))
14936 unsigned int bitsize = decl_piece_bitsize (p);
14937 rtx loc_note = *decl_piece_varloc_ptr (p);
14938 dw_loc_descr_ref cur_descr;
14939 dw_loc_descr_ref *tail, last = NULL;
14940 unsigned int opsize = 0;
14942 if (loc_note == NULL_RTX
14943 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14945 padsize += bitsize;
14948 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14949 varloc = NOTE_VAR_LOCATION (loc_note);
14950 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14951 if (cur_descr == NULL)
14953 padsize += bitsize;
14957 /* Check that cur_descr either doesn't use
14958 DW_OP_*piece operations, or their sum is equal
14959 to bitsize. Otherwise we can't embed it. */
14960 for (tail = &cur_descr; *tail != NULL;
14961 tail = &(*tail)->dw_loc_next)
14962 if ((*tail)->dw_loc_opc == DW_OP_piece)
14964 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14968 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14970 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14974 if (last != NULL && opsize != bitsize)
14976 padsize += bitsize;
14980 /* If there is a hole, add DW_OP_*piece after empty DWARF
14981 expression, which means that those bits are optimized out. */
14984 if (padsize > decl_size)
14986 decl_size -= padsize;
14987 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14988 if (*descr_tail == NULL)
14990 descr_tail = &(*descr_tail)->dw_loc_next;
14993 *descr_tail = cur_descr;
14995 if (bitsize > decl_size)
14997 decl_size -= bitsize;
15000 HOST_WIDE_INT offset = 0;
15001 if (GET_CODE (varloc) == VAR_LOCATION
15002 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
15004 varloc = PAT_VAR_LOCATION_LOC (varloc);
15005 if (GET_CODE (varloc) == EXPR_LIST)
15006 varloc = XEXP (varloc, 0);
15010 if (GET_CODE (varloc) == CONST
15011 || GET_CODE (varloc) == SIGN_EXTEND
15012 || GET_CODE (varloc) == ZERO_EXTEND)
15013 varloc = XEXP (varloc, 0);
15014 else if (GET_CODE (varloc) == SUBREG)
15015 varloc = SUBREG_REG (varloc);
15020 /* DW_OP_bit_size offset should be zero for register
15021 or implicit location descriptions and empty location
15022 descriptions, but for memory addresses needs big endian
15024 if (MEM_P (varloc))
15026 unsigned HOST_WIDE_INT memsize
15027 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
15028 if (memsize != bitsize)
15030 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
15031 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
15033 if (memsize < bitsize)
15035 if (BITS_BIG_ENDIAN)
15036 offset = memsize - bitsize;
15040 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
15041 if (*descr_tail == NULL)
15043 descr_tail = &(*descr_tail)->dw_loc_next;
15047 /* If there were any non-empty expressions, add padding till the end of
15049 if (descr != NULL && decl_size != 0)
15051 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
15052 if (*descr_tail == NULL)
15058 /* Return the dwarf representation of the location list LOC_LIST of
15059 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
15062 static dw_loc_list_ref
15063 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
15065 const char *endname, *secname;
15067 enum var_init_status initialized;
15068 struct var_loc_node *node;
15069 dw_loc_descr_ref descr;
15070 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15071 dw_loc_list_ref list = NULL;
15072 dw_loc_list_ref *listp = &list;
15074 /* Now that we know what section we are using for a base,
15075 actually construct the list of locations.
15076 The first location information is what is passed to the
15077 function that creates the location list, and the remaining
15078 locations just get added on to that list.
15079 Note that we only know the start address for a location
15080 (IE location changes), so to build the range, we use
15081 the range [current location start, next location start].
15082 This means we have to special case the last node, and generate
15083 a range of [last location start, end of function label]. */
15085 secname = secname_for_decl (decl);
15087 for (node = loc_list->first; node; node = node->next)
15088 if (GET_CODE (node->loc) == EXPR_LIST
15089 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
15091 if (GET_CODE (node->loc) == EXPR_LIST)
15093 /* This requires DW_OP_{,bit_}piece, which is not usable
15094 inside DWARF expressions. */
15095 if (want_address != 2)
15097 descr = dw_sra_loc_expr (decl, node->loc);
15103 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15104 varloc = NOTE_VAR_LOCATION (node->loc);
15105 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15109 /* The variable has a location between NODE->LABEL and
15110 NODE->NEXT->LABEL. */
15112 endname = node->next->label;
15113 /* If the variable has a location at the last label
15114 it keeps its location until the end of function. */
15115 else if (!current_function_decl)
15116 endname = text_end_label;
15119 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15120 current_function_funcdef_no);
15121 endname = ggc_strdup (label_id);
15124 *listp = new_loc_list (descr, node->label, endname, secname);
15125 listp = &(*listp)->dw_loc_next;
15129 /* Try to avoid the overhead of a location list emitting a location
15130 expression instead, but only if we didn't have more than one
15131 location entry in the first place. If some entries were not
15132 representable, we don't want to pretend a single entry that was
15133 applies to the entire scope in which the variable is
15135 if (list && loc_list->first->next)
15141 /* Return if the loc_list has only single element and thus can be represented
15142 as location description. */
15145 single_element_loc_list_p (dw_loc_list_ref list)
15147 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15148 return !list->ll_symbol;
15151 /* To each location in list LIST add loc descr REF. */
15154 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15156 dw_loc_descr_ref copy;
15157 add_loc_descr (&list->expr, ref);
15158 list = list->dw_loc_next;
15161 copy = ggc_alloc_dw_loc_descr_node ();
15162 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15163 add_loc_descr (&list->expr, copy);
15164 while (copy->dw_loc_next)
15166 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15167 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15168 copy->dw_loc_next = new_copy;
15171 list = list->dw_loc_next;
15175 /* Given two lists RET and LIST
15176 produce location list that is result of adding expression in LIST
15177 to expression in RET on each possition in program.
15178 Might be destructive on both RET and LIST.
15180 TODO: We handle only simple cases of RET or LIST having at most one
15181 element. General case would inolve sorting the lists in program order
15182 and merging them that will need some additional work.
15183 Adding that will improve quality of debug info especially for SRA-ed
15187 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15196 if (!list->dw_loc_next)
15198 add_loc_descr_to_each (*ret, list->expr);
15201 if (!(*ret)->dw_loc_next)
15203 add_loc_descr_to_each (list, (*ret)->expr);
15207 expansion_failed (NULL_TREE, NULL_RTX,
15208 "Don't know how to merge two non-trivial"
15209 " location lists.\n");
15214 /* LOC is constant expression. Try a luck, look it up in constant
15215 pool and return its loc_descr of its address. */
15217 static dw_loc_descr_ref
15218 cst_pool_loc_descr (tree loc)
15220 /* Get an RTL for this, if something has been emitted. */
15221 rtx rtl = lookup_constant_def (loc);
15222 enum machine_mode mode;
15224 if (!rtl || !MEM_P (rtl))
15229 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15231 /* TODO: We might get more coverage if we was actually delaying expansion
15232 of all expressions till end of compilation when constant pools are fully
15234 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15236 expansion_failed (loc, NULL_RTX,
15237 "CST value in contant pool but not marked.");
15240 mode = GET_MODE (rtl);
15241 rtl = XEXP (rtl, 0);
15242 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15245 /* Return dw_loc_list representing address of addr_expr LOC
15246 by looking for innder INDIRECT_REF expression and turing it
15247 into simple arithmetics. */
15249 static dw_loc_list_ref
15250 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15253 HOST_WIDE_INT bitsize, bitpos, bytepos;
15254 enum machine_mode mode;
15256 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15257 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15259 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15260 &bitsize, &bitpos, &offset, &mode,
15261 &unsignedp, &volatilep, false);
15263 if (bitpos % BITS_PER_UNIT)
15265 expansion_failed (loc, NULL_RTX, "bitfield access");
15268 if (!INDIRECT_REF_P (obj))
15270 expansion_failed (obj,
15271 NULL_RTX, "no indirect ref in inner refrence");
15274 if (!offset && !bitpos)
15275 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15277 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15278 && (dwarf_version >= 4 || !dwarf_strict))
15280 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15285 /* Variable offset. */
15286 list_ret1 = loc_list_from_tree (offset, 0);
15287 if (list_ret1 == 0)
15289 add_loc_list (&list_ret, list_ret1);
15292 add_loc_descr_to_each (list_ret,
15293 new_loc_descr (DW_OP_plus, 0, 0));
15295 bytepos = bitpos / BITS_PER_UNIT;
15297 add_loc_descr_to_each (list_ret,
15298 new_loc_descr (DW_OP_plus_uconst,
15300 else if (bytepos < 0)
15301 loc_list_plus_const (list_ret, bytepos);
15302 add_loc_descr_to_each (list_ret,
15303 new_loc_descr (DW_OP_stack_value, 0, 0));
15309 /* Generate Dwarf location list representing LOC.
15310 If WANT_ADDRESS is false, expression computing LOC will be computed
15311 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15312 if WANT_ADDRESS is 2, expression computing address useable in location
15313 will be returned (i.e. DW_OP_reg can be used
15314 to refer to register values). */
15316 static dw_loc_list_ref
15317 loc_list_from_tree (tree loc, int want_address)
15319 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15320 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15321 int have_address = 0;
15322 enum dwarf_location_atom op;
15324 /* ??? Most of the time we do not take proper care for sign/zero
15325 extending the values properly. Hopefully this won't be a real
15328 switch (TREE_CODE (loc))
15331 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15334 case PLACEHOLDER_EXPR:
15335 /* This case involves extracting fields from an object to determine the
15336 position of other fields. We don't try to encode this here. The
15337 only user of this is Ada, which encodes the needed information using
15338 the names of types. */
15339 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15343 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15344 /* There are no opcodes for these operations. */
15347 case PREINCREMENT_EXPR:
15348 case PREDECREMENT_EXPR:
15349 case POSTINCREMENT_EXPR:
15350 case POSTDECREMENT_EXPR:
15351 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15352 /* There are no opcodes for these operations. */
15356 /* If we already want an address, see if there is INDIRECT_REF inside
15357 e.g. for &this->field. */
15360 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15361 (loc, want_address == 2);
15364 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15365 && (ret = cst_pool_loc_descr (loc)))
15368 /* Otherwise, process the argument and look for the address. */
15369 if (!list_ret && !ret)
15370 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15374 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15380 if (DECL_THREAD_LOCAL_P (loc))
15383 enum dwarf_location_atom first_op;
15384 enum dwarf_location_atom second_op;
15385 bool dtprel = false;
15387 if (targetm.have_tls)
15389 /* If this is not defined, we have no way to emit the
15391 if (!targetm.asm_out.output_dwarf_dtprel)
15394 /* The way DW_OP_GNU_push_tls_address is specified, we
15395 can only look up addresses of objects in the current
15396 module. We used DW_OP_addr as first op, but that's
15397 wrong, because DW_OP_addr is relocated by the debug
15398 info consumer, while DW_OP_GNU_push_tls_address
15399 operand shouldn't be. */
15400 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15402 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15404 second_op = DW_OP_GNU_push_tls_address;
15408 if (!targetm.emutls.debug_form_tls_address
15409 || !(dwarf_version >= 3 || !dwarf_strict))
15411 /* We stuffed the control variable into the DECL_VALUE_EXPR
15412 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15413 no longer appear in gimple code. We used the control
15414 variable in specific so that we could pick it up here. */
15415 loc = DECL_VALUE_EXPR (loc);
15416 first_op = DW_OP_addr;
15417 second_op = DW_OP_form_tls_address;
15420 rtl = rtl_for_decl_location (loc);
15421 if (rtl == NULL_RTX)
15426 rtl = XEXP (rtl, 0);
15427 if (! CONSTANT_P (rtl))
15430 ret = new_loc_descr (first_op, 0, 0);
15431 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15432 ret->dw_loc_oprnd1.v.val_addr = rtl;
15433 ret->dtprel = dtprel;
15435 ret1 = new_loc_descr (second_op, 0, 0);
15436 add_loc_descr (&ret, ret1);
15444 if (DECL_HAS_VALUE_EXPR_P (loc))
15445 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15450 case FUNCTION_DECL:
15453 var_loc_list *loc_list = lookup_decl_loc (loc);
15455 if (loc_list && loc_list->first)
15457 list_ret = dw_loc_list (loc_list, loc, want_address);
15458 have_address = want_address != 0;
15461 rtl = rtl_for_decl_location (loc);
15462 if (rtl == NULL_RTX)
15464 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15467 else if (CONST_INT_P (rtl))
15469 HOST_WIDE_INT val = INTVAL (rtl);
15470 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15471 val &= GET_MODE_MASK (DECL_MODE (loc));
15472 ret = int_loc_descriptor (val);
15474 else if (GET_CODE (rtl) == CONST_STRING)
15476 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15479 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15481 ret = new_loc_descr (DW_OP_addr, 0, 0);
15482 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15483 ret->dw_loc_oprnd1.v.val_addr = rtl;
15487 enum machine_mode mode;
15489 /* Certain constructs can only be represented at top-level. */
15490 if (want_address == 2)
15492 ret = loc_descriptor (rtl, VOIDmode,
15493 VAR_INIT_STATUS_INITIALIZED);
15498 mode = GET_MODE (rtl);
15501 rtl = XEXP (rtl, 0);
15504 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15507 expansion_failed (loc, rtl,
15508 "failed to produce loc descriptor for rtl");
15515 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15519 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15523 case COMPOUND_EXPR:
15524 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15527 case VIEW_CONVERT_EXPR:
15530 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15532 case COMPONENT_REF:
15533 case BIT_FIELD_REF:
15535 case ARRAY_RANGE_REF:
15536 case REALPART_EXPR:
15537 case IMAGPART_EXPR:
15540 HOST_WIDE_INT bitsize, bitpos, bytepos;
15541 enum machine_mode mode;
15543 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15545 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15546 &unsignedp, &volatilep, false);
15548 gcc_assert (obj != loc);
15550 list_ret = loc_list_from_tree (obj,
15552 && !bitpos && !offset ? 2 : 1);
15553 /* TODO: We can extract value of the small expression via shifting even
15554 for nonzero bitpos. */
15557 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15559 expansion_failed (loc, NULL_RTX,
15560 "bitfield access");
15564 if (offset != NULL_TREE)
15566 /* Variable offset. */
15567 list_ret1 = loc_list_from_tree (offset, 0);
15568 if (list_ret1 == 0)
15570 add_loc_list (&list_ret, list_ret1);
15573 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15576 bytepos = bitpos / BITS_PER_UNIT;
15578 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15579 else if (bytepos < 0)
15580 loc_list_plus_const (list_ret, bytepos);
15587 if ((want_address || !host_integerp (loc, 0))
15588 && (ret = cst_pool_loc_descr (loc)))
15590 else if (want_address == 2
15591 && host_integerp (loc, 0)
15592 && (ret = address_of_int_loc_descriptor
15593 (int_size_in_bytes (TREE_TYPE (loc)),
15594 tree_low_cst (loc, 0))))
15596 else if (host_integerp (loc, 0))
15597 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15600 expansion_failed (loc, NULL_RTX,
15601 "Integer operand is not host integer");
15610 if ((ret = cst_pool_loc_descr (loc)))
15613 /* We can construct small constants here using int_loc_descriptor. */
15614 expansion_failed (loc, NULL_RTX,
15615 "constructor or constant not in constant pool");
15618 case TRUTH_AND_EXPR:
15619 case TRUTH_ANDIF_EXPR:
15624 case TRUTH_XOR_EXPR:
15629 case TRUTH_OR_EXPR:
15630 case TRUTH_ORIF_EXPR:
15635 case FLOOR_DIV_EXPR:
15636 case CEIL_DIV_EXPR:
15637 case ROUND_DIV_EXPR:
15638 case TRUNC_DIV_EXPR:
15639 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15648 case FLOOR_MOD_EXPR:
15649 case CEIL_MOD_EXPR:
15650 case ROUND_MOD_EXPR:
15651 case TRUNC_MOD_EXPR:
15652 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15657 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15658 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15659 if (list_ret == 0 || list_ret1 == 0)
15662 add_loc_list (&list_ret, list_ret1);
15665 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15666 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15667 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15668 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15669 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15681 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15684 case POINTER_PLUS_EXPR:
15686 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15688 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15692 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15700 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15707 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15714 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15721 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15736 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15737 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15738 if (list_ret == 0 || list_ret1 == 0)
15741 add_loc_list (&list_ret, list_ret1);
15744 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15747 case TRUTH_NOT_EXPR:
15761 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15765 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15771 const enum tree_code code =
15772 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15774 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15775 build2 (code, integer_type_node,
15776 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15777 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15780 /* ... fall through ... */
15784 dw_loc_descr_ref lhs
15785 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15786 dw_loc_list_ref rhs
15787 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15788 dw_loc_descr_ref bra_node, jump_node, tmp;
15790 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15791 if (list_ret == 0 || lhs == 0 || rhs == 0)
15794 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15795 add_loc_descr_to_each (list_ret, bra_node);
15797 add_loc_list (&list_ret, rhs);
15798 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15799 add_loc_descr_to_each (list_ret, jump_node);
15801 add_loc_descr_to_each (list_ret, lhs);
15802 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15803 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15805 /* ??? Need a node to point the skip at. Use a nop. */
15806 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15807 add_loc_descr_to_each (list_ret, tmp);
15808 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15809 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15813 case FIX_TRUNC_EXPR:
15817 /* Leave front-end specific codes as simply unknown. This comes
15818 up, for instance, with the C STMT_EXPR. */
15819 if ((unsigned int) TREE_CODE (loc)
15820 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15822 expansion_failed (loc, NULL_RTX,
15823 "language specific tree node");
15827 #ifdef ENABLE_CHECKING
15828 /* Otherwise this is a generic code; we should just lists all of
15829 these explicitly. We forgot one. */
15830 gcc_unreachable ();
15832 /* In a release build, we want to degrade gracefully: better to
15833 generate incomplete debugging information than to crash. */
15838 if (!ret && !list_ret)
15841 if (want_address == 2 && !have_address
15842 && (dwarf_version >= 4 || !dwarf_strict))
15844 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15846 expansion_failed (loc, NULL_RTX,
15847 "DWARF address size mismatch");
15851 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15853 add_loc_descr_to_each (list_ret,
15854 new_loc_descr (DW_OP_stack_value, 0, 0));
15857 /* Show if we can't fill the request for an address. */
15858 if (want_address && !have_address)
15860 expansion_failed (loc, NULL_RTX,
15861 "Want address and only have value");
15865 gcc_assert (!ret || !list_ret);
15867 /* If we've got an address and don't want one, dereference. */
15868 if (!want_address && have_address)
15870 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15872 if (size > DWARF2_ADDR_SIZE || size == -1)
15874 expansion_failed (loc, NULL_RTX,
15875 "DWARF address size mismatch");
15878 else if (size == DWARF2_ADDR_SIZE)
15881 op = DW_OP_deref_size;
15884 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15886 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15889 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15894 /* Same as above but return only single location expression. */
15895 static dw_loc_descr_ref
15896 loc_descriptor_from_tree (tree loc, int want_address)
15898 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15901 if (ret->dw_loc_next)
15903 expansion_failed (loc, NULL_RTX,
15904 "Location list where only loc descriptor needed");
15910 /* Given a value, round it up to the lowest multiple of `boundary'
15911 which is not less than the value itself. */
15913 static inline HOST_WIDE_INT
15914 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15916 return (((value + boundary - 1) / boundary) * boundary);
15919 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15920 pointer to the declared type for the relevant field variable, or return
15921 `integer_type_node' if the given node turns out to be an
15922 ERROR_MARK node. */
15925 field_type (const_tree decl)
15929 if (TREE_CODE (decl) == ERROR_MARK)
15930 return integer_type_node;
15932 type = DECL_BIT_FIELD_TYPE (decl);
15933 if (type == NULL_TREE)
15934 type = TREE_TYPE (decl);
15939 /* Given a pointer to a tree node, return the alignment in bits for
15940 it, or else return BITS_PER_WORD if the node actually turns out to
15941 be an ERROR_MARK node. */
15943 static inline unsigned
15944 simple_type_align_in_bits (const_tree type)
15946 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15949 static inline unsigned
15950 simple_decl_align_in_bits (const_tree decl)
15952 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15955 /* Return the result of rounding T up to ALIGN. */
15957 static inline double_int
15958 round_up_to_align (double_int t, unsigned int align)
15960 double_int alignd = uhwi_to_double_int (align);
15961 t = double_int_add (t, alignd);
15962 t = double_int_add (t, double_int_minus_one);
15963 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15964 t = double_int_mul (t, alignd);
15968 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15969 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15970 or return 0 if we are unable to determine what that offset is, either
15971 because the argument turns out to be a pointer to an ERROR_MARK node, or
15972 because the offset is actually variable. (We can't handle the latter case
15975 static HOST_WIDE_INT
15976 field_byte_offset (const_tree decl)
15978 double_int object_offset_in_bits;
15979 double_int object_offset_in_bytes;
15980 double_int bitpos_int;
15982 if (TREE_CODE (decl) == ERROR_MARK)
15985 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15987 /* We cannot yet cope with fields whose positions are variable, so
15988 for now, when we see such things, we simply return 0. Someday, we may
15989 be able to handle such cases, but it will be damn difficult. */
15990 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15993 bitpos_int = tree_to_double_int (bit_position (decl));
15995 #ifdef PCC_BITFIELD_TYPE_MATTERS
15996 if (PCC_BITFIELD_TYPE_MATTERS)
15999 tree field_size_tree;
16000 double_int deepest_bitpos;
16001 double_int field_size_in_bits;
16002 unsigned int type_align_in_bits;
16003 unsigned int decl_align_in_bits;
16004 double_int type_size_in_bits;
16006 type = field_type (decl);
16007 type_size_in_bits = double_int_type_size_in_bits (type);
16008 type_align_in_bits = simple_type_align_in_bits (type);
16010 field_size_tree = DECL_SIZE (decl);
16012 /* The size could be unspecified if there was an error, or for
16013 a flexible array member. */
16014 if (!field_size_tree)
16015 field_size_tree = bitsize_zero_node;
16017 /* If the size of the field is not constant, use the type size. */
16018 if (TREE_CODE (field_size_tree) == INTEGER_CST)
16019 field_size_in_bits = tree_to_double_int (field_size_tree);
16021 field_size_in_bits = type_size_in_bits;
16023 decl_align_in_bits = simple_decl_align_in_bits (decl);
16025 /* The GCC front-end doesn't make any attempt to keep track of the
16026 starting bit offset (relative to the start of the containing
16027 structure type) of the hypothetical "containing object" for a
16028 bit-field. Thus, when computing the byte offset value for the
16029 start of the "containing object" of a bit-field, we must deduce
16030 this information on our own. This can be rather tricky to do in
16031 some cases. For example, handling the following structure type
16032 definition when compiling for an i386/i486 target (which only
16033 aligns long long's to 32-bit boundaries) can be very tricky:
16035 struct S { int field1; long long field2:31; };
16037 Fortunately, there is a simple rule-of-thumb which can be used
16038 in such cases. When compiling for an i386/i486, GCC will
16039 allocate 8 bytes for the structure shown above. It decides to
16040 do this based upon one simple rule for bit-field allocation.
16041 GCC allocates each "containing object" for each bit-field at
16042 the first (i.e. lowest addressed) legitimate alignment boundary
16043 (based upon the required minimum alignment for the declared
16044 type of the field) which it can possibly use, subject to the
16045 condition that there is still enough available space remaining
16046 in the containing object (when allocated at the selected point)
16047 to fully accommodate all of the bits of the bit-field itself.
16049 This simple rule makes it obvious why GCC allocates 8 bytes for
16050 each object of the structure type shown above. When looking
16051 for a place to allocate the "containing object" for `field2',
16052 the compiler simply tries to allocate a 64-bit "containing
16053 object" at each successive 32-bit boundary (starting at zero)
16054 until it finds a place to allocate that 64- bit field such that
16055 at least 31 contiguous (and previously unallocated) bits remain
16056 within that selected 64 bit field. (As it turns out, for the
16057 example above, the compiler finds it is OK to allocate the
16058 "containing object" 64-bit field at bit-offset zero within the
16061 Here we attempt to work backwards from the limited set of facts
16062 we're given, and we try to deduce from those facts, where GCC
16063 must have believed that the containing object started (within
16064 the structure type). The value we deduce is then used (by the
16065 callers of this routine) to generate DW_AT_location and
16066 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16067 the case of DW_AT_location, regular fields as well). */
16069 /* Figure out the bit-distance from the start of the structure to
16070 the "deepest" bit of the bit-field. */
16071 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16073 /* This is the tricky part. Use some fancy footwork to deduce
16074 where the lowest addressed bit of the containing object must
16076 object_offset_in_bits
16077 = double_int_sub (deepest_bitpos, type_size_in_bits);
16079 /* Round up to type_align by default. This works best for
16081 object_offset_in_bits
16082 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16084 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16086 object_offset_in_bits
16087 = double_int_sub (deepest_bitpos, type_size_in_bits);
16089 /* Round up to decl_align instead. */
16090 object_offset_in_bits
16091 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16095 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16096 object_offset_in_bits = bitpos_int;
16098 object_offset_in_bytes
16099 = double_int_div (object_offset_in_bits,
16100 uhwi_to_double_int (BITS_PER_UNIT), true,
16102 return double_int_to_shwi (object_offset_in_bytes);
16105 /* The following routines define various Dwarf attributes and any data
16106 associated with them. */
16108 /* Add a location description attribute value to a DIE.
16110 This emits location attributes suitable for whole variables and
16111 whole parameters. Note that the location attributes for struct fields are
16112 generated by the routine `data_member_location_attribute' below. */
16115 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16116 dw_loc_list_ref descr)
16120 if (single_element_loc_list_p (descr))
16121 add_AT_loc (die, attr_kind, descr->expr);
16123 add_AT_loc_list (die, attr_kind, descr);
16126 /* Add DW_AT_accessibility attribute to DIE if needed. */
16129 add_accessibility_attribute (dw_die_ref die, tree decl)
16131 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16132 children, otherwise the default is DW_ACCESS_public. In DWARF2
16133 the default has always been DW_ACCESS_public. */
16134 if (TREE_PROTECTED (decl))
16135 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16136 else if (TREE_PRIVATE (decl))
16138 if (dwarf_version == 2
16139 || die->die_parent == NULL
16140 || die->die_parent->die_tag != DW_TAG_class_type)
16141 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16143 else if (dwarf_version > 2
16145 && die->die_parent->die_tag == DW_TAG_class_type)
16146 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16149 /* Attach the specialized form of location attribute used for data members of
16150 struct and union types. In the special case of a FIELD_DECL node which
16151 represents a bit-field, the "offset" part of this special location
16152 descriptor must indicate the distance in bytes from the lowest-addressed
16153 byte of the containing struct or union type to the lowest-addressed byte of
16154 the "containing object" for the bit-field. (See the `field_byte_offset'
16157 For any given bit-field, the "containing object" is a hypothetical object
16158 (of some integral or enum type) within which the given bit-field lives. The
16159 type of this hypothetical "containing object" is always the same as the
16160 declared type of the individual bit-field itself (for GCC anyway... the
16161 DWARF spec doesn't actually mandate this). Note that it is the size (in
16162 bytes) of the hypothetical "containing object" which will be given in the
16163 DW_AT_byte_size attribute for this bit-field. (See the
16164 `byte_size_attribute' function below.) It is also used when calculating the
16165 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16166 function below.) */
16169 add_data_member_location_attribute (dw_die_ref die, tree decl)
16171 HOST_WIDE_INT offset;
16172 dw_loc_descr_ref loc_descr = 0;
16174 if (TREE_CODE (decl) == TREE_BINFO)
16176 /* We're working on the TAG_inheritance for a base class. */
16177 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16179 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16180 aren't at a fixed offset from all (sub)objects of the same
16181 type. We need to extract the appropriate offset from our
16182 vtable. The following dwarf expression means
16184 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16186 This is specific to the V3 ABI, of course. */
16188 dw_loc_descr_ref tmp;
16190 /* Make a copy of the object address. */
16191 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16192 add_loc_descr (&loc_descr, tmp);
16194 /* Extract the vtable address. */
16195 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16196 add_loc_descr (&loc_descr, tmp);
16198 /* Calculate the address of the offset. */
16199 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16200 gcc_assert (offset < 0);
16202 tmp = int_loc_descriptor (-offset);
16203 add_loc_descr (&loc_descr, tmp);
16204 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16205 add_loc_descr (&loc_descr, tmp);
16207 /* Extract the offset. */
16208 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16209 add_loc_descr (&loc_descr, tmp);
16211 /* Add it to the object address. */
16212 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16213 add_loc_descr (&loc_descr, tmp);
16216 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16219 offset = field_byte_offset (decl);
16223 if (dwarf_version > 2)
16225 /* Don't need to output a location expression, just the constant. */
16227 add_AT_int (die, DW_AT_data_member_location, offset);
16229 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16234 enum dwarf_location_atom op;
16236 /* The DWARF2 standard says that we should assume that the structure
16237 address is already on the stack, so we can specify a structure
16238 field address by using DW_OP_plus_uconst. */
16240 #ifdef MIPS_DEBUGGING_INFO
16241 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16242 operator correctly. It works only if we leave the offset on the
16246 op = DW_OP_plus_uconst;
16249 loc_descr = new_loc_descr (op, offset, 0);
16253 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16256 /* Writes integer values to dw_vec_const array. */
16259 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16263 *dest++ = val & 0xff;
16269 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16271 static HOST_WIDE_INT
16272 extract_int (const unsigned char *src, unsigned int size)
16274 HOST_WIDE_INT val = 0;
16280 val |= *--src & 0xff;
16286 /* Writes double_int values to dw_vec_const array. */
16289 insert_double (double_int val, unsigned char *dest)
16291 unsigned char *p0 = dest;
16292 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16294 if (WORDS_BIG_ENDIAN)
16300 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16301 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16304 /* Writes floating point values to dw_vec_const array. */
16307 insert_float (const_rtx rtl, unsigned char *array)
16309 REAL_VALUE_TYPE rv;
16313 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16314 real_to_target (val, &rv, GET_MODE (rtl));
16316 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16317 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16319 insert_int (val[i], 4, array);
16324 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16325 does not have a "location" either in memory or in a register. These
16326 things can arise in GNU C when a constant is passed as an actual parameter
16327 to an inlined function. They can also arise in C++ where declared
16328 constants do not necessarily get memory "homes". */
16331 add_const_value_attribute (dw_die_ref die, rtx rtl)
16333 switch (GET_CODE (rtl))
16337 HOST_WIDE_INT val = INTVAL (rtl);
16340 add_AT_int (die, DW_AT_const_value, val);
16342 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16347 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16348 floating-point constant. A CONST_DOUBLE is used whenever the
16349 constant requires more than one word in order to be adequately
16352 enum machine_mode mode = GET_MODE (rtl);
16354 if (SCALAR_FLOAT_MODE_P (mode))
16356 unsigned int length = GET_MODE_SIZE (mode);
16357 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16359 insert_float (rtl, array);
16360 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16363 add_AT_double (die, DW_AT_const_value,
16364 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16370 enum machine_mode mode = GET_MODE (rtl);
16371 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16372 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16373 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16374 (length * elt_size);
16378 switch (GET_MODE_CLASS (mode))
16380 case MODE_VECTOR_INT:
16381 for (i = 0, p = array; i < length; i++, p += elt_size)
16383 rtx elt = CONST_VECTOR_ELT (rtl, i);
16384 double_int val = rtx_to_double_int (elt);
16386 if (elt_size <= sizeof (HOST_WIDE_INT))
16387 insert_int (double_int_to_shwi (val), elt_size, p);
16390 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16391 insert_double (val, p);
16396 case MODE_VECTOR_FLOAT:
16397 for (i = 0, p = array; i < length; i++, p += elt_size)
16399 rtx elt = CONST_VECTOR_ELT (rtl, i);
16400 insert_float (elt, p);
16405 gcc_unreachable ();
16408 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16413 if (dwarf_version >= 4 || !dwarf_strict)
16415 dw_loc_descr_ref loc_result;
16416 resolve_one_addr (&rtl, NULL);
16418 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16419 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16420 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16421 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16422 add_AT_loc (die, DW_AT_location, loc_result);
16423 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16429 if (CONSTANT_P (XEXP (rtl, 0)))
16430 return add_const_value_attribute (die, XEXP (rtl, 0));
16433 if (!const_ok_for_output (rtl))
16436 if (dwarf_version >= 4 || !dwarf_strict)
16441 /* In cases where an inlined instance of an inline function is passed
16442 the address of an `auto' variable (which is local to the caller) we
16443 can get a situation where the DECL_RTL of the artificial local
16444 variable (for the inlining) which acts as a stand-in for the
16445 corresponding formal parameter (of the inline function) will look
16446 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16447 exactly a compile-time constant expression, but it isn't the address
16448 of the (artificial) local variable either. Rather, it represents the
16449 *value* which the artificial local variable always has during its
16450 lifetime. We currently have no way to represent such quasi-constant
16451 values in Dwarf, so for now we just punt and generate nothing. */
16459 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16460 && MEM_READONLY_P (rtl)
16461 && GET_MODE (rtl) == BLKmode)
16463 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16469 /* No other kinds of rtx should be possible here. */
16470 gcc_unreachable ();
16475 /* Determine whether the evaluation of EXPR references any variables
16476 or functions which aren't otherwise used (and therefore may not be
16479 reference_to_unused (tree * tp, int * walk_subtrees,
16480 void * data ATTRIBUTE_UNUSED)
16482 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16483 *walk_subtrees = 0;
16485 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16486 && ! TREE_ASM_WRITTEN (*tp))
16488 /* ??? The C++ FE emits debug information for using decls, so
16489 putting gcc_unreachable here falls over. See PR31899. For now
16490 be conservative. */
16491 else if (!cgraph_global_info_ready
16492 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16494 else if (TREE_CODE (*tp) == VAR_DECL)
16496 struct varpool_node *node = varpool_get_node (*tp);
16497 if (!node || !node->needed)
16500 else if (TREE_CODE (*tp) == FUNCTION_DECL
16501 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16503 /* The call graph machinery must have finished analyzing,
16504 optimizing and gimplifying the CU by now.
16505 So if *TP has no call graph node associated
16506 to it, it means *TP will not be emitted. */
16507 if (!cgraph_get_node (*tp))
16510 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16516 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16517 for use in a later add_const_value_attribute call. */
16520 rtl_for_decl_init (tree init, tree type)
16522 rtx rtl = NULL_RTX;
16524 /* If a variable is initialized with a string constant without embedded
16525 zeros, build CONST_STRING. */
16526 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16528 tree enttype = TREE_TYPE (type);
16529 tree domain = TYPE_DOMAIN (type);
16530 enum machine_mode mode = TYPE_MODE (enttype);
16532 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16534 && integer_zerop (TYPE_MIN_VALUE (domain))
16535 && compare_tree_int (TYPE_MAX_VALUE (domain),
16536 TREE_STRING_LENGTH (init) - 1) == 0
16537 && ((size_t) TREE_STRING_LENGTH (init)
16538 == strlen (TREE_STRING_POINTER (init)) + 1))
16540 rtl = gen_rtx_CONST_STRING (VOIDmode,
16541 ggc_strdup (TREE_STRING_POINTER (init)));
16542 rtl = gen_rtx_MEM (BLKmode, rtl);
16543 MEM_READONLY_P (rtl) = 1;
16546 /* Other aggregates, and complex values, could be represented using
16548 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
16550 /* Vectors only work if their mode is supported by the target.
16551 FIXME: generic vectors ought to work too. */
16552 else if (TREE_CODE (type) == VECTOR_TYPE
16553 && !VECTOR_MODE_P (TYPE_MODE (type)))
16555 /* If the initializer is something that we know will expand into an
16556 immediate RTL constant, expand it now. We must be careful not to
16557 reference variables which won't be output. */
16558 else if (initializer_constant_valid_p (init, type)
16559 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16561 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16563 if (TREE_CODE (type) == VECTOR_TYPE)
16564 switch (TREE_CODE (init))
16569 if (TREE_CONSTANT (init))
16571 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16572 bool constant_p = true;
16574 unsigned HOST_WIDE_INT ix;
16576 /* Even when ctor is constant, it might contain non-*_CST
16577 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16578 belong into VECTOR_CST nodes. */
16579 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16580 if (!CONSTANT_CLASS_P (value))
16582 constant_p = false;
16588 init = build_vector_from_ctor (type, elts);
16598 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16600 /* If expand_expr returns a MEM, it wasn't immediate. */
16601 gcc_assert (!rtl || !MEM_P (rtl));
16607 /* Generate RTL for the variable DECL to represent its location. */
16610 rtl_for_decl_location (tree decl)
16614 /* Here we have to decide where we are going to say the parameter "lives"
16615 (as far as the debugger is concerned). We only have a couple of
16616 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16618 DECL_RTL normally indicates where the parameter lives during most of the
16619 activation of the function. If optimization is enabled however, this
16620 could be either NULL or else a pseudo-reg. Both of those cases indicate
16621 that the parameter doesn't really live anywhere (as far as the code
16622 generation parts of GCC are concerned) during most of the function's
16623 activation. That will happen (for example) if the parameter is never
16624 referenced within the function.
16626 We could just generate a location descriptor here for all non-NULL
16627 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16628 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16629 where DECL_RTL is NULL or is a pseudo-reg.
16631 Note however that we can only get away with using DECL_INCOMING_RTL as
16632 a backup substitute for DECL_RTL in certain limited cases. In cases
16633 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16634 we can be sure that the parameter was passed using the same type as it is
16635 declared to have within the function, and that its DECL_INCOMING_RTL
16636 points us to a place where a value of that type is passed.
16638 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16639 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16640 because in these cases DECL_INCOMING_RTL points us to a value of some
16641 type which is *different* from the type of the parameter itself. Thus,
16642 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16643 such cases, the debugger would end up (for example) trying to fetch a
16644 `float' from a place which actually contains the first part of a
16645 `double'. That would lead to really incorrect and confusing
16646 output at debug-time.
16648 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16649 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16650 are a couple of exceptions however. On little-endian machines we can
16651 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16652 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16653 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16654 when (on a little-endian machine) a non-prototyped function has a
16655 parameter declared to be of type `short' or `char'. In such cases,
16656 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16657 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16658 passed `int' value. If the debugger then uses that address to fetch
16659 a `short' or a `char' (on a little-endian machine) the result will be
16660 the correct data, so we allow for such exceptional cases below.
16662 Note that our goal here is to describe the place where the given formal
16663 parameter lives during most of the function's activation (i.e. between the
16664 end of the prologue and the start of the epilogue). We'll do that as best
16665 as we can. Note however that if the given formal parameter is modified
16666 sometime during the execution of the function, then a stack backtrace (at
16667 debug-time) will show the function as having been called with the *new*
16668 value rather than the value which was originally passed in. This happens
16669 rarely enough that it is not a major problem, but it *is* a problem, and
16670 I'd like to fix it.
16672 A future version of dwarf2out.c may generate two additional attributes for
16673 any given DW_TAG_formal_parameter DIE which will describe the "passed
16674 type" and the "passed location" for the given formal parameter in addition
16675 to the attributes we now generate to indicate the "declared type" and the
16676 "active location" for each parameter. This additional set of attributes
16677 could be used by debuggers for stack backtraces. Separately, note that
16678 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16679 This happens (for example) for inlined-instances of inline function formal
16680 parameters which are never referenced. This really shouldn't be
16681 happening. All PARM_DECL nodes should get valid non-NULL
16682 DECL_INCOMING_RTL values. FIXME. */
16684 /* Use DECL_RTL as the "location" unless we find something better. */
16685 rtl = DECL_RTL_IF_SET (decl);
16687 /* When generating abstract instances, ignore everything except
16688 constants, symbols living in memory, and symbols living in
16689 fixed registers. */
16690 if (! reload_completed)
16693 && (CONSTANT_P (rtl)
16695 && CONSTANT_P (XEXP (rtl, 0)))
16697 && TREE_CODE (decl) == VAR_DECL
16698 && TREE_STATIC (decl))))
16700 rtl = targetm.delegitimize_address (rtl);
16705 else if (TREE_CODE (decl) == PARM_DECL)
16707 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
16709 tree declared_type = TREE_TYPE (decl);
16710 tree passed_type = DECL_ARG_TYPE (decl);
16711 enum machine_mode dmode = TYPE_MODE (declared_type);
16712 enum machine_mode pmode = TYPE_MODE (passed_type);
16714 /* This decl represents a formal parameter which was optimized out.
16715 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16716 all cases where (rtl == NULL_RTX) just below. */
16717 if (dmode == pmode)
16718 rtl = DECL_INCOMING_RTL (decl);
16719 else if (SCALAR_INT_MODE_P (dmode)
16720 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16721 && DECL_INCOMING_RTL (decl))
16723 rtx inc = DECL_INCOMING_RTL (decl);
16726 else if (MEM_P (inc))
16728 if (BYTES_BIG_ENDIAN)
16729 rtl = adjust_address_nv (inc, dmode,
16730 GET_MODE_SIZE (pmode)
16731 - GET_MODE_SIZE (dmode));
16738 /* If the parm was passed in registers, but lives on the stack, then
16739 make a big endian correction if the mode of the type of the
16740 parameter is not the same as the mode of the rtl. */
16741 /* ??? This is the same series of checks that are made in dbxout.c before
16742 we reach the big endian correction code there. It isn't clear if all
16743 of these checks are necessary here, but keeping them all is the safe
16745 else if (MEM_P (rtl)
16746 && XEXP (rtl, 0) != const0_rtx
16747 && ! CONSTANT_P (XEXP (rtl, 0))
16748 /* Not passed in memory. */
16749 && !MEM_P (DECL_INCOMING_RTL (decl))
16750 /* Not passed by invisible reference. */
16751 && (!REG_P (XEXP (rtl, 0))
16752 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16753 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16754 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16755 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16758 /* Big endian correction check. */
16759 && BYTES_BIG_ENDIAN
16760 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16761 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16764 int offset = (UNITS_PER_WORD
16765 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16767 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16768 plus_constant (XEXP (rtl, 0), offset));
16771 else if (TREE_CODE (decl) == VAR_DECL
16774 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16775 && BYTES_BIG_ENDIAN)
16777 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16778 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16780 /* If a variable is declared "register" yet is smaller than
16781 a register, then if we store the variable to memory, it
16782 looks like we're storing a register-sized value, when in
16783 fact we are not. We need to adjust the offset of the
16784 storage location to reflect the actual value's bytes,
16785 else gdb will not be able to display it. */
16787 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16788 plus_constant (XEXP (rtl, 0), rsize-dsize));
16791 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16792 and will have been substituted directly into all expressions that use it.
16793 C does not have such a concept, but C++ and other languages do. */
16794 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16795 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16798 rtl = targetm.delegitimize_address (rtl);
16800 /* If we don't look past the constant pool, we risk emitting a
16801 reference to a constant pool entry that isn't referenced from
16802 code, and thus is not emitted. */
16804 rtl = avoid_constant_pool_reference (rtl);
16806 /* Try harder to get a rtl. If this symbol ends up not being emitted
16807 in the current CU, resolve_addr will remove the expression referencing
16809 if (rtl == NULL_RTX
16810 && TREE_CODE (decl) == VAR_DECL
16811 && !DECL_EXTERNAL (decl)
16812 && TREE_STATIC (decl)
16813 && DECL_NAME (decl)
16814 && !DECL_HARD_REGISTER (decl)
16815 && DECL_MODE (decl) != VOIDmode)
16817 rtl = make_decl_rtl_for_debug (decl);
16819 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16820 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16827 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16828 returned. If so, the decl for the COMMON block is returned, and the
16829 value is the offset into the common block for the symbol. */
16832 fortran_common (tree decl, HOST_WIDE_INT *value)
16834 tree val_expr, cvar;
16835 enum machine_mode mode;
16836 HOST_WIDE_INT bitsize, bitpos;
16838 int volatilep = 0, unsignedp = 0;
16840 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16841 it does not have a value (the offset into the common area), or if it
16842 is thread local (as opposed to global) then it isn't common, and shouldn't
16843 be handled as such. */
16844 if (TREE_CODE (decl) != VAR_DECL
16845 || !TREE_STATIC (decl)
16846 || !DECL_HAS_VALUE_EXPR_P (decl)
16850 val_expr = DECL_VALUE_EXPR (decl);
16851 if (TREE_CODE (val_expr) != COMPONENT_REF)
16854 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16855 &mode, &unsignedp, &volatilep, true);
16857 if (cvar == NULL_TREE
16858 || TREE_CODE (cvar) != VAR_DECL
16859 || DECL_ARTIFICIAL (cvar)
16860 || !TREE_PUBLIC (cvar))
16864 if (offset != NULL)
16866 if (!host_integerp (offset, 0))
16868 *value = tree_low_cst (offset, 0);
16871 *value += bitpos / BITS_PER_UNIT;
16876 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16877 data attribute for a variable or a parameter. We generate the
16878 DW_AT_const_value attribute only in those cases where the given variable
16879 or parameter does not have a true "location" either in memory or in a
16880 register. This can happen (for example) when a constant is passed as an
16881 actual argument in a call to an inline function. (It's possible that
16882 these things can crop up in other ways also.) Note that one type of
16883 constant value which can be passed into an inlined function is a constant
16884 pointer. This can happen for example if an actual argument in an inlined
16885 function call evaluates to a compile-time constant address. */
16888 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
16889 enum dwarf_attribute attr)
16892 dw_loc_list_ref list;
16893 var_loc_list *loc_list;
16895 if (TREE_CODE (decl) == ERROR_MARK)
16898 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16899 || TREE_CODE (decl) == RESULT_DECL);
16901 /* Try to get some constant RTL for this decl, and use that as the value of
16904 rtl = rtl_for_decl_location (decl);
16905 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16906 && add_const_value_attribute (die, rtl))
16909 /* See if we have single element location list that is equivalent to
16910 a constant value. That way we are better to use add_const_value_attribute
16911 rather than expanding constant value equivalent. */
16912 loc_list = lookup_decl_loc (decl);
16915 && loc_list->first->next == NULL
16916 && NOTE_P (loc_list->first->loc)
16917 && NOTE_VAR_LOCATION (loc_list->first->loc)
16918 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16920 struct var_loc_node *node;
16922 node = loc_list->first;
16923 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16924 if (GET_CODE (rtl) == EXPR_LIST)
16925 rtl = XEXP (rtl, 0);
16926 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16927 && add_const_value_attribute (die, rtl))
16930 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16933 add_AT_location_description (die, attr, list);
16936 /* None of that worked, so it must not really have a location;
16937 try adding a constant value attribute from the DECL_INITIAL. */
16938 return tree_add_const_value_attribute_for_decl (die, decl);
16941 /* Add VARIABLE and DIE into deferred locations list. */
16944 defer_location (tree variable, dw_die_ref die)
16946 deferred_locations entry;
16947 entry.variable = variable;
16949 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16952 /* Helper function for tree_add_const_value_attribute. Natively encode
16953 initializer INIT into an array. Return true if successful. */
16956 native_encode_initializer (tree init, unsigned char *array, int size)
16960 if (init == NULL_TREE)
16964 switch (TREE_CODE (init))
16967 type = TREE_TYPE (init);
16968 if (TREE_CODE (type) == ARRAY_TYPE)
16970 tree enttype = TREE_TYPE (type);
16971 enum machine_mode mode = TYPE_MODE (enttype);
16973 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16975 if (int_size_in_bytes (type) != size)
16977 if (size > TREE_STRING_LENGTH (init))
16979 memcpy (array, TREE_STRING_POINTER (init),
16980 TREE_STRING_LENGTH (init));
16981 memset (array + TREE_STRING_LENGTH (init),
16982 '\0', size - TREE_STRING_LENGTH (init));
16985 memcpy (array, TREE_STRING_POINTER (init), size);
16990 type = TREE_TYPE (init);
16991 if (int_size_in_bytes (type) != size)
16993 if (TREE_CODE (type) == ARRAY_TYPE)
16995 HOST_WIDE_INT min_index;
16996 unsigned HOST_WIDE_INT cnt;
16997 int curpos = 0, fieldsize;
16998 constructor_elt *ce;
17000 if (TYPE_DOMAIN (type) == NULL_TREE
17001 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
17004 fieldsize = int_size_in_bytes (TREE_TYPE (type));
17005 if (fieldsize <= 0)
17008 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
17009 memset (array, '\0', size);
17010 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17012 tree val = ce->value;
17013 tree index = ce->index;
17015 if (index && TREE_CODE (index) == RANGE_EXPR)
17016 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17019 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17024 if (!native_encode_initializer (val, array + pos, fieldsize))
17027 curpos = pos + fieldsize;
17028 if (index && TREE_CODE (index) == RANGE_EXPR)
17030 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17031 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17035 memcpy (array + curpos, array + pos, fieldsize);
17036 curpos += fieldsize;
17039 gcc_assert (curpos <= size);
17043 else if (TREE_CODE (type) == RECORD_TYPE
17044 || TREE_CODE (type) == UNION_TYPE)
17046 tree field = NULL_TREE;
17047 unsigned HOST_WIDE_INT cnt;
17048 constructor_elt *ce;
17050 if (int_size_in_bytes (type) != size)
17053 if (TREE_CODE (type) == RECORD_TYPE)
17054 field = TYPE_FIELDS (type);
17056 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17058 tree val = ce->value;
17059 int pos, fieldsize;
17061 if (ce->index != 0)
17067 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17070 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17071 && TYPE_DOMAIN (TREE_TYPE (field))
17072 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17074 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17075 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17077 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17078 pos = int_byte_position (field);
17079 gcc_assert (pos + fieldsize <= size);
17081 && !native_encode_initializer (val, array + pos, fieldsize))
17087 case VIEW_CONVERT_EXPR:
17088 case NON_LVALUE_EXPR:
17089 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17091 return native_encode_expr (init, array, size) == size;
17095 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17096 attribute is the const value T. */
17099 tree_add_const_value_attribute (dw_die_ref die, tree t)
17102 tree type = TREE_TYPE (t);
17105 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17109 gcc_assert (!DECL_P (init));
17111 rtl = rtl_for_decl_init (init, type);
17113 return add_const_value_attribute (die, rtl);
17114 /* If the host and target are sane, try harder. */
17115 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17116 && initializer_constant_valid_p (init, type))
17118 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17119 if (size > 0 && (int) size == size)
17121 unsigned char *array = (unsigned char *)
17122 ggc_alloc_cleared_atomic (size);
17124 if (native_encode_initializer (init, array, size))
17126 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17134 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17135 attribute is the const value of T, where T is an integral constant
17136 variable with static storage duration
17137 (so it can't be a PARM_DECL or a RESULT_DECL). */
17140 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17144 || (TREE_CODE (decl) != VAR_DECL
17145 && TREE_CODE (decl) != CONST_DECL))
17148 if (TREE_READONLY (decl)
17149 && ! TREE_THIS_VOLATILE (decl)
17150 && DECL_INITIAL (decl))
17155 /* Don't add DW_AT_const_value if abstract origin already has one. */
17156 if (get_AT (var_die, DW_AT_const_value))
17159 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17162 /* Convert the CFI instructions for the current function into a
17163 location list. This is used for DW_AT_frame_base when we targeting
17164 a dwarf2 consumer that does not support the dwarf3
17165 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17168 static dw_loc_list_ref
17169 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17172 dw_loc_list_ref list, *list_tail;
17174 dw_cfa_location last_cfa, next_cfa;
17175 const char *start_label, *last_label, *section;
17176 dw_cfa_location remember;
17178 fde = current_fde ();
17179 gcc_assert (fde != NULL);
17181 section = secname_for_decl (current_function_decl);
17185 memset (&next_cfa, 0, sizeof (next_cfa));
17186 next_cfa.reg = INVALID_REGNUM;
17187 remember = next_cfa;
17189 start_label = fde->dw_fde_begin;
17191 /* ??? Bald assumption that the CIE opcode list does not contain
17192 advance opcodes. */
17193 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17194 lookup_cfa_1 (cfi, &next_cfa, &remember);
17196 last_cfa = next_cfa;
17197 last_label = start_label;
17199 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17200 switch (cfi->dw_cfi_opc)
17202 case DW_CFA_set_loc:
17203 case DW_CFA_advance_loc1:
17204 case DW_CFA_advance_loc2:
17205 case DW_CFA_advance_loc4:
17206 if (!cfa_equal_p (&last_cfa, &next_cfa))
17208 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17209 start_label, last_label, section);
17211 list_tail = &(*list_tail)->dw_loc_next;
17212 last_cfa = next_cfa;
17213 start_label = last_label;
17215 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17218 case DW_CFA_advance_loc:
17219 /* The encoding is complex enough that we should never emit this. */
17220 gcc_unreachable ();
17223 lookup_cfa_1 (cfi, &next_cfa, &remember);
17227 if (!cfa_equal_p (&last_cfa, &next_cfa))
17229 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17230 start_label, last_label, section);
17231 list_tail = &(*list_tail)->dw_loc_next;
17232 start_label = last_label;
17235 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17236 start_label, fde->dw_fde_end, section);
17238 if (list && list->dw_loc_next)
17244 /* Compute a displacement from the "steady-state frame pointer" to the
17245 frame base (often the same as the CFA), and store it in
17246 frame_pointer_fb_offset. OFFSET is added to the displacement
17247 before the latter is negated. */
17250 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17254 #ifdef FRAME_POINTER_CFA_OFFSET
17255 reg = frame_pointer_rtx;
17256 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17258 reg = arg_pointer_rtx;
17259 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17262 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17263 if (GET_CODE (elim) == PLUS)
17265 offset += INTVAL (XEXP (elim, 1));
17266 elim = XEXP (elim, 0);
17269 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17270 && (elim == hard_frame_pointer_rtx
17271 || elim == stack_pointer_rtx))
17272 || elim == (frame_pointer_needed
17273 ? hard_frame_pointer_rtx
17274 : stack_pointer_rtx));
17276 frame_pointer_fb_offset = -offset;
17279 /* Generate a DW_AT_name attribute given some string value to be included as
17280 the value of the attribute. */
17283 add_name_attribute (dw_die_ref die, const char *name_string)
17285 if (name_string != NULL && *name_string != 0)
17287 if (demangle_name_func)
17288 name_string = (*demangle_name_func) (name_string);
17290 add_AT_string (die, DW_AT_name, name_string);
17294 /* Generate a DW_AT_comp_dir attribute for DIE. */
17297 add_comp_dir_attribute (dw_die_ref die)
17299 const char *wd = get_src_pwd ();
17305 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17309 wdlen = strlen (wd);
17310 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17312 wd1 [wdlen] = DIR_SEPARATOR;
17313 wd1 [wdlen + 1] = 0;
17317 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17320 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17324 lower_bound_default (void)
17326 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17331 case DW_LANG_C_plus_plus:
17333 case DW_LANG_ObjC_plus_plus:
17336 case DW_LANG_Fortran77:
17337 case DW_LANG_Fortran90:
17338 case DW_LANG_Fortran95:
17342 case DW_LANG_Python:
17343 return dwarf_version >= 4 ? 0 : -1;
17344 case DW_LANG_Ada95:
17345 case DW_LANG_Ada83:
17346 case DW_LANG_Cobol74:
17347 case DW_LANG_Cobol85:
17348 case DW_LANG_Pascal83:
17349 case DW_LANG_Modula2:
17351 return dwarf_version >= 4 ? 1 : -1;
17357 /* Given a tree node describing an array bound (either lower or upper) output
17358 a representation for that bound. */
17361 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17363 switch (TREE_CODE (bound))
17368 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17371 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17374 /* Use the default if possible. */
17375 if (bound_attr == DW_AT_lower_bound
17376 && host_integerp (bound, 0)
17377 && (dflt = lower_bound_default ()) != -1
17378 && tree_low_cst (bound, 0) == dflt)
17381 /* Otherwise represent the bound as an unsigned value with the
17382 precision of its type. The precision and signedness of the
17383 type will be necessary to re-interpret it unambiguously. */
17384 else if (prec < HOST_BITS_PER_WIDE_INT)
17386 unsigned HOST_WIDE_INT mask
17387 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17388 add_AT_unsigned (subrange_die, bound_attr,
17389 TREE_INT_CST_LOW (bound) & mask);
17391 else if (prec == HOST_BITS_PER_WIDE_INT
17392 || TREE_INT_CST_HIGH (bound) == 0)
17393 add_AT_unsigned (subrange_die, bound_attr,
17394 TREE_INT_CST_LOW (bound));
17396 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17397 TREE_INT_CST_LOW (bound));
17402 case VIEW_CONVERT_EXPR:
17403 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17413 dw_die_ref decl_die = lookup_decl_die (bound);
17415 /* ??? Can this happen, or should the variable have been bound
17416 first? Probably it can, since I imagine that we try to create
17417 the types of parameters in the order in which they exist in
17418 the list, and won't have created a forward reference to a
17419 later parameter. */
17420 if (decl_die != NULL)
17422 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17430 /* Otherwise try to create a stack operation procedure to
17431 evaluate the value of the array bound. */
17433 dw_die_ref ctx, decl_die;
17434 dw_loc_list_ref list;
17436 list = loc_list_from_tree (bound, 2);
17437 if (list == NULL || single_element_loc_list_p (list))
17439 /* If DW_AT_*bound is not a reference nor constant, it is
17440 a DWARF expression rather than location description.
17441 For that loc_list_from_tree (bound, 0) is needed.
17442 If that fails to give a single element list,
17443 fall back to outputting this as a reference anyway. */
17444 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17445 if (list2 && single_element_loc_list_p (list2))
17447 add_AT_loc (subrange_die, bound_attr, list2->expr);
17454 if (current_function_decl == 0)
17455 ctx = comp_unit_die ();
17457 ctx = lookup_decl_die (current_function_decl);
17459 decl_die = new_die (DW_TAG_variable, ctx, bound);
17460 add_AT_flag (decl_die, DW_AT_artificial, 1);
17461 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17462 add_AT_location_description (decl_die, DW_AT_location, list);
17463 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17469 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17470 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17471 Note that the block of subscript information for an array type also
17472 includes information about the element type of the given array type. */
17475 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17477 unsigned dimension_number;
17479 dw_die_ref subrange_die;
17481 for (dimension_number = 0;
17482 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17483 type = TREE_TYPE (type), dimension_number++)
17485 tree domain = TYPE_DOMAIN (type);
17487 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17490 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17491 and (in GNU C only) variable bounds. Handle all three forms
17493 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17496 /* We have an array type with specified bounds. */
17497 lower = TYPE_MIN_VALUE (domain);
17498 upper = TYPE_MAX_VALUE (domain);
17500 /* Define the index type. */
17501 if (TREE_TYPE (domain))
17503 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17504 TREE_TYPE field. We can't emit debug info for this
17505 because it is an unnamed integral type. */
17506 if (TREE_CODE (domain) == INTEGER_TYPE
17507 && TYPE_NAME (domain) == NULL_TREE
17508 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17509 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17512 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17516 /* ??? If upper is NULL, the array has unspecified length,
17517 but it does have a lower bound. This happens with Fortran
17519 Since the debugger is definitely going to need to know N
17520 to produce useful results, go ahead and output the lower
17521 bound solo, and hope the debugger can cope. */
17523 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17525 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17528 /* Otherwise we have an array type with an unspecified length. The
17529 DWARF-2 spec does not say how to handle this; let's just leave out the
17535 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17539 switch (TREE_CODE (tree_node))
17544 case ENUMERAL_TYPE:
17547 case QUAL_UNION_TYPE:
17548 size = int_size_in_bytes (tree_node);
17551 /* For a data member of a struct or union, the DW_AT_byte_size is
17552 generally given as the number of bytes normally allocated for an
17553 object of the *declared* type of the member itself. This is true
17554 even for bit-fields. */
17555 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17558 gcc_unreachable ();
17561 /* Note that `size' might be -1 when we get to this point. If it is, that
17562 indicates that the byte size of the entity in question is variable. We
17563 have no good way of expressing this fact in Dwarf at the present time,
17564 so just let the -1 pass on through. */
17565 add_AT_unsigned (die, DW_AT_byte_size, size);
17568 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17569 which specifies the distance in bits from the highest order bit of the
17570 "containing object" for the bit-field to the highest order bit of the
17573 For any given bit-field, the "containing object" is a hypothetical object
17574 (of some integral or enum type) within which the given bit-field lives. The
17575 type of this hypothetical "containing object" is always the same as the
17576 declared type of the individual bit-field itself. The determination of the
17577 exact location of the "containing object" for a bit-field is rather
17578 complicated. It's handled by the `field_byte_offset' function (above).
17580 Note that it is the size (in bytes) of the hypothetical "containing object"
17581 which will be given in the DW_AT_byte_size attribute for this bit-field.
17582 (See `byte_size_attribute' above). */
17585 add_bit_offset_attribute (dw_die_ref die, tree decl)
17587 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17588 tree type = DECL_BIT_FIELD_TYPE (decl);
17589 HOST_WIDE_INT bitpos_int;
17590 HOST_WIDE_INT highest_order_object_bit_offset;
17591 HOST_WIDE_INT highest_order_field_bit_offset;
17592 HOST_WIDE_INT unsigned bit_offset;
17594 /* Must be a field and a bit field. */
17595 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17597 /* We can't yet handle bit-fields whose offsets are variable, so if we
17598 encounter such things, just return without generating any attribute
17599 whatsoever. Likewise for variable or too large size. */
17600 if (! host_integerp (bit_position (decl), 0)
17601 || ! host_integerp (DECL_SIZE (decl), 1))
17604 bitpos_int = int_bit_position (decl);
17606 /* Note that the bit offset is always the distance (in bits) from the
17607 highest-order bit of the "containing object" to the highest-order bit of
17608 the bit-field itself. Since the "high-order end" of any object or field
17609 is different on big-endian and little-endian machines, the computation
17610 below must take account of these differences. */
17611 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17612 highest_order_field_bit_offset = bitpos_int;
17614 if (! BYTES_BIG_ENDIAN)
17616 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17617 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17621 = (! BYTES_BIG_ENDIAN
17622 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17623 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17625 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
17628 /* For a FIELD_DECL node which represents a bit field, output an attribute
17629 which specifies the length in bits of the given field. */
17632 add_bit_size_attribute (dw_die_ref die, tree decl)
17634 /* Must be a field and a bit field. */
17635 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17636 && DECL_BIT_FIELD_TYPE (decl));
17638 if (host_integerp (DECL_SIZE (decl), 1))
17639 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17642 /* If the compiled language is ANSI C, then add a 'prototyped'
17643 attribute, if arg types are given for the parameters of a function. */
17646 add_prototyped_attribute (dw_die_ref die, tree func_type)
17648 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17649 && TYPE_ARG_TYPES (func_type) != NULL)
17650 add_AT_flag (die, DW_AT_prototyped, 1);
17653 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17654 by looking in either the type declaration or object declaration
17657 static inline dw_die_ref
17658 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17660 dw_die_ref origin_die = NULL;
17662 if (TREE_CODE (origin) != FUNCTION_DECL)
17664 /* We may have gotten separated from the block for the inlined
17665 function, if we're in an exception handler or some such; make
17666 sure that the abstract function has been written out.
17668 Doing this for nested functions is wrong, however; functions are
17669 distinct units, and our context might not even be inline. */
17673 fn = TYPE_STUB_DECL (fn);
17675 fn = decl_function_context (fn);
17677 dwarf2out_abstract_function (fn);
17680 if (DECL_P (origin))
17681 origin_die = lookup_decl_die (origin);
17682 else if (TYPE_P (origin))
17683 origin_die = lookup_type_die (origin);
17685 /* XXX: Functions that are never lowered don't always have correct block
17686 trees (in the case of java, they simply have no block tree, in some other
17687 languages). For these functions, there is nothing we can really do to
17688 output correct debug info for inlined functions in all cases. Rather
17689 than die, we'll just produce deficient debug info now, in that we will
17690 have variables without a proper abstract origin. In the future, when all
17691 functions are lowered, we should re-add a gcc_assert (origin_die)
17695 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17699 /* We do not currently support the pure_virtual attribute. */
17702 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17704 if (DECL_VINDEX (func_decl))
17706 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17708 if (host_integerp (DECL_VINDEX (func_decl), 0))
17709 add_AT_loc (die, DW_AT_vtable_elem_location,
17710 new_loc_descr (DW_OP_constu,
17711 tree_low_cst (DECL_VINDEX (func_decl), 0),
17714 /* GNU extension: Record what type this method came from originally. */
17715 if (debug_info_level > DINFO_LEVEL_TERSE
17716 && DECL_CONTEXT (func_decl))
17717 add_AT_die_ref (die, DW_AT_containing_type,
17718 lookup_type_die (DECL_CONTEXT (func_decl)));
17722 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17723 given decl. This used to be a vendor extension until after DWARF 4
17724 standardized it. */
17727 add_linkage_attr (dw_die_ref die, tree decl)
17729 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17731 /* Mimic what assemble_name_raw does with a leading '*'. */
17732 if (name[0] == '*')
17735 if (dwarf_version >= 4)
17736 add_AT_string (die, DW_AT_linkage_name, name);
17738 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17741 /* Add source coordinate attributes for the given decl. */
17744 add_src_coords_attributes (dw_die_ref die, tree decl)
17746 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
17748 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17749 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17752 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17755 add_linkage_name (dw_die_ref die, tree decl)
17757 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17758 && TREE_PUBLIC (decl)
17759 && !DECL_ABSTRACT (decl)
17760 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17761 && die->die_tag != DW_TAG_member)
17763 /* Defer until we have an assembler name set. */
17764 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17766 limbo_die_node *asm_name;
17768 asm_name = ggc_alloc_cleared_limbo_die_node ();
17769 asm_name->die = die;
17770 asm_name->created_for = decl;
17771 asm_name->next = deferred_asm_name;
17772 deferred_asm_name = asm_name;
17774 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17775 add_linkage_attr (die, decl);
17779 /* Add a DW_AT_name attribute and source coordinate attribute for the
17780 given decl, but only if it actually has a name. */
17783 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17787 decl_name = DECL_NAME (decl);
17788 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17790 const char *name = dwarf2_name (decl, 0);
17792 add_name_attribute (die, name);
17793 if (! DECL_ARTIFICIAL (decl))
17794 add_src_coords_attributes (die, decl);
17796 add_linkage_name (die, decl);
17799 #ifdef VMS_DEBUGGING_INFO
17800 /* Get the function's name, as described by its RTL. This may be different
17801 from the DECL_NAME name used in the source file. */
17802 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17804 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17805 XEXP (DECL_RTL (decl), 0));
17806 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17808 #endif /* VMS_DEBUGGING_INFO */
17811 #ifdef VMS_DEBUGGING_INFO
17812 /* Output the debug main pointer die for VMS */
17815 dwarf2out_vms_debug_main_pointer (void)
17817 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17820 /* Allocate the VMS debug main subprogram die. */
17821 die = ggc_alloc_cleared_die_node ();
17822 die->die_tag = DW_TAG_subprogram;
17823 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17824 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17825 current_function_funcdef_no);
17826 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17828 /* Make it the first child of comp_unit_die (). */
17829 die->die_parent = comp_unit_die ();
17830 if (comp_unit_die ()->die_child)
17832 die->die_sib = comp_unit_die ()->die_child->die_sib;
17833 comp_unit_die ()->die_child->die_sib = die;
17837 die->die_sib = die;
17838 comp_unit_die ()->die_child = die;
17841 #endif /* VMS_DEBUGGING_INFO */
17843 /* Push a new declaration scope. */
17846 push_decl_scope (tree scope)
17848 VEC_safe_push (tree, gc, decl_scope_table, scope);
17851 /* Pop a declaration scope. */
17854 pop_decl_scope (void)
17856 VEC_pop (tree, decl_scope_table);
17859 /* Return the DIE for the scope that immediately contains this type.
17860 Non-named types get global scope. Named types nested in other
17861 types get their containing scope if it's open, or global scope
17862 otherwise. All other types (i.e. function-local named types) get
17863 the current active scope. */
17866 scope_die_for (tree t, dw_die_ref context_die)
17868 dw_die_ref scope_die = NULL;
17869 tree containing_scope;
17872 /* Non-types always go in the current scope. */
17873 gcc_assert (TYPE_P (t));
17875 containing_scope = TYPE_CONTEXT (t);
17877 /* Use the containing namespace if it was passed in (for a declaration). */
17878 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17880 if (context_die == lookup_decl_die (containing_scope))
17883 containing_scope = NULL_TREE;
17886 /* Ignore function type "scopes" from the C frontend. They mean that
17887 a tagged type is local to a parmlist of a function declarator, but
17888 that isn't useful to DWARF. */
17889 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17890 containing_scope = NULL_TREE;
17892 if (SCOPE_FILE_SCOPE_P (containing_scope))
17893 scope_die = comp_unit_die ();
17894 else if (TYPE_P (containing_scope))
17896 /* For types, we can just look up the appropriate DIE. But
17897 first we check to see if we're in the middle of emitting it
17898 so we know where the new DIE should go. */
17899 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17900 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17905 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17906 || TREE_ASM_WRITTEN (containing_scope));
17907 /*We are not in the middle of emitting the type
17908 CONTAINING_SCOPE. Let's see if it's emitted already. */
17909 scope_die = lookup_type_die (containing_scope);
17911 /* If none of the current dies are suitable, we get file scope. */
17912 if (scope_die == NULL)
17913 scope_die = comp_unit_die ();
17916 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17919 scope_die = context_die;
17924 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17927 local_scope_p (dw_die_ref context_die)
17929 for (; context_die; context_die = context_die->die_parent)
17930 if (context_die->die_tag == DW_TAG_inlined_subroutine
17931 || context_die->die_tag == DW_TAG_subprogram)
17937 /* Returns nonzero if CONTEXT_DIE is a class. */
17940 class_scope_p (dw_die_ref context_die)
17942 return (context_die
17943 && (context_die->die_tag == DW_TAG_structure_type
17944 || context_die->die_tag == DW_TAG_class_type
17945 || context_die->die_tag == DW_TAG_interface_type
17946 || context_die->die_tag == DW_TAG_union_type));
17949 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17950 whether or not to treat a DIE in this context as a declaration. */
17953 class_or_namespace_scope_p (dw_die_ref context_die)
17955 return (class_scope_p (context_die)
17956 || (context_die && context_die->die_tag == DW_TAG_namespace));
17959 /* Many forms of DIEs require a "type description" attribute. This
17960 routine locates the proper "type descriptor" die for the type given
17961 by 'type', and adds a DW_AT_type attribute below the given die. */
17964 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
17965 int decl_volatile, dw_die_ref context_die)
17967 enum tree_code code = TREE_CODE (type);
17968 dw_die_ref type_die = NULL;
17970 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17971 or fixed-point type, use the inner type. This is because we have no
17972 support for unnamed types in base_type_die. This can happen if this is
17973 an Ada subrange type. Correct solution is emit a subrange type die. */
17974 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
17975 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
17976 type = TREE_TYPE (type), code = TREE_CODE (type);
17978 if (code == ERROR_MARK
17979 /* Handle a special case. For functions whose return type is void, we
17980 generate *no* type attribute. (Note that no object may have type
17981 `void', so this only applies to function return types). */
17982 || code == VOID_TYPE)
17985 type_die = modified_type_die (type,
17986 decl_const || TYPE_READONLY (type),
17987 decl_volatile || TYPE_VOLATILE (type),
17990 if (type_die != NULL)
17991 add_AT_die_ref (object_die, DW_AT_type, type_die);
17994 /* Given an object die, add the calling convention attribute for the
17995 function call type. */
17997 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
17999 enum dwarf_calling_convention value = DW_CC_normal;
18001 value = ((enum dwarf_calling_convention)
18002 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18005 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18007 /* DWARF 2 doesn't provide a way to identify a program's source-level
18008 entry point. DW_AT_calling_convention attributes are only meant
18009 to describe functions' calling conventions. However, lacking a
18010 better way to signal the Fortran main program, we used this for
18011 a long time, following existing custom. Now, DWARF 4 has
18012 DW_AT_main_subprogram, which we add below, but some tools still
18013 rely on the old way, which we thus keep. */
18014 value = DW_CC_program;
18016 if (dwarf_version >= 4 || !dwarf_strict)
18017 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18020 /* Only add the attribute if the backend requests it, and
18021 is not DW_CC_normal. */
18022 if (value && (value != DW_CC_normal))
18023 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18026 /* Given a tree pointer to a struct, class, union, or enum type node, return
18027 a pointer to the (string) tag name for the given type, or zero if the type
18028 was declared without a tag. */
18030 static const char *
18031 type_tag (const_tree type)
18033 const char *name = 0;
18035 if (TYPE_NAME (type) != 0)
18039 /* Find the IDENTIFIER_NODE for the type name. */
18040 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18041 && !TYPE_NAMELESS (type))
18042 t = TYPE_NAME (type);
18044 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18045 a TYPE_DECL node, regardless of whether or not a `typedef' was
18047 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18048 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18050 /* We want to be extra verbose. Don't call dwarf_name if
18051 DECL_NAME isn't set. The default hook for decl_printable_name
18052 doesn't like that, and in this context it's correct to return
18053 0, instead of "<anonymous>" or the like. */
18054 if (DECL_NAME (TYPE_NAME (type))
18055 && !DECL_NAMELESS (TYPE_NAME (type)))
18056 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18059 /* Now get the name as a string, or invent one. */
18060 if (!name && t != 0)
18061 name = IDENTIFIER_POINTER (t);
18064 return (name == 0 || *name == '\0') ? 0 : name;
18067 /* Return the type associated with a data member, make a special check
18068 for bit field types. */
18071 member_declared_type (const_tree member)
18073 return (DECL_BIT_FIELD_TYPE (member)
18074 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18077 /* Get the decl's label, as described by its RTL. This may be different
18078 from the DECL_NAME name used in the source file. */
18081 static const char *
18082 decl_start_label (tree decl)
18085 const char *fnname;
18087 x = DECL_RTL (decl);
18088 gcc_assert (MEM_P (x));
18091 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18093 fnname = XSTR (x, 0);
18098 /* These routines generate the internal representation of the DIE's for
18099 the compilation unit. Debugging information is collected by walking
18100 the declaration trees passed in from dwarf2out_decl(). */
18103 gen_array_type_die (tree type, dw_die_ref context_die)
18105 dw_die_ref scope_die = scope_die_for (type, context_die);
18106 dw_die_ref array_die;
18108 /* GNU compilers represent multidimensional array types as sequences of one
18109 dimensional array types whose element types are themselves array types.
18110 We sometimes squish that down to a single array_type DIE with multiple
18111 subscripts in the Dwarf debugging info. The draft Dwarf specification
18112 say that we are allowed to do this kind of compression in C, because
18113 there is no difference between an array of arrays and a multidimensional
18114 array. We don't do this for Ada to remain as close as possible to the
18115 actual representation, which is especially important against the language
18116 flexibilty wrt arrays of variable size. */
18118 bool collapse_nested_arrays = !is_ada ();
18121 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18122 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18123 if (TYPE_STRING_FLAG (type)
18124 && TREE_CODE (type) == ARRAY_TYPE
18126 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18128 HOST_WIDE_INT size;
18130 array_die = new_die (DW_TAG_string_type, scope_die, type);
18131 add_name_attribute (array_die, type_tag (type));
18132 equate_type_number_to_die (type, array_die);
18133 size = int_size_in_bytes (type);
18135 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18136 else if (TYPE_DOMAIN (type) != NULL_TREE
18137 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18138 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18140 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18141 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18143 size = int_size_in_bytes (TREE_TYPE (szdecl));
18144 if (loc && size > 0)
18146 add_AT_location_description (array_die, DW_AT_string_length, loc);
18147 if (size != DWARF2_ADDR_SIZE)
18148 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18154 /* ??? The SGI dwarf reader fails for array of array of enum types
18155 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18156 array type comes before the outer array type. We thus call gen_type_die
18157 before we new_die and must prevent nested array types collapsing for this
18160 #ifdef MIPS_DEBUGGING_INFO
18161 gen_type_die (TREE_TYPE (type), context_die);
18162 collapse_nested_arrays = false;
18165 array_die = new_die (DW_TAG_array_type, scope_die, type);
18166 add_name_attribute (array_die, type_tag (type));
18167 equate_type_number_to_die (type, array_die);
18169 if (TREE_CODE (type) == VECTOR_TYPE)
18170 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18172 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18174 && TREE_CODE (type) == ARRAY_TYPE
18175 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18176 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18177 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18180 /* We default the array ordering. SDB will probably do
18181 the right things even if DW_AT_ordering is not present. It's not even
18182 an issue until we start to get into multidimensional arrays anyway. If
18183 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18184 then we'll have to put the DW_AT_ordering attribute back in. (But if
18185 and when we find out that we need to put these in, we will only do so
18186 for multidimensional arrays. */
18187 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18190 #ifdef MIPS_DEBUGGING_INFO
18191 /* The SGI compilers handle arrays of unknown bound by setting
18192 AT_declaration and not emitting any subrange DIEs. */
18193 if (TREE_CODE (type) == ARRAY_TYPE
18194 && ! TYPE_DOMAIN (type))
18195 add_AT_flag (array_die, DW_AT_declaration, 1);
18198 if (TREE_CODE (type) == VECTOR_TYPE)
18200 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18201 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18202 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18203 add_bound_info (subrange_die, DW_AT_upper_bound,
18204 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18207 add_subscript_info (array_die, type, collapse_nested_arrays);
18209 /* Add representation of the type of the elements of this array type and
18210 emit the corresponding DIE if we haven't done it already. */
18211 element_type = TREE_TYPE (type);
18212 if (collapse_nested_arrays)
18213 while (TREE_CODE (element_type) == ARRAY_TYPE)
18215 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18217 element_type = TREE_TYPE (element_type);
18220 #ifndef MIPS_DEBUGGING_INFO
18221 gen_type_die (element_type, context_die);
18224 add_type_attribute (array_die, element_type, 0, 0, context_die);
18226 if (get_AT (array_die, DW_AT_name))
18227 add_pubtype (type, array_die);
18230 static dw_loc_descr_ref
18231 descr_info_loc (tree val, tree base_decl)
18233 HOST_WIDE_INT size;
18234 dw_loc_descr_ref loc, loc2;
18235 enum dwarf_location_atom op;
18237 if (val == base_decl)
18238 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18240 switch (TREE_CODE (val))
18243 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18245 return loc_descriptor_from_tree (val, 0);
18247 if (host_integerp (val, 0))
18248 return int_loc_descriptor (tree_low_cst (val, 0));
18251 size = int_size_in_bytes (TREE_TYPE (val));
18254 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18257 if (size == DWARF2_ADDR_SIZE)
18258 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18260 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18262 case POINTER_PLUS_EXPR:
18264 if (host_integerp (TREE_OPERAND (val, 1), 1)
18265 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18268 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18271 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18277 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18280 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18283 add_loc_descr (&loc, loc2);
18284 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18306 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18307 tree val, tree base_decl)
18309 dw_loc_descr_ref loc;
18311 if (host_integerp (val, 0))
18313 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18317 loc = descr_info_loc (val, base_decl);
18321 add_AT_loc (die, attr, loc);
18324 /* This routine generates DIE for array with hidden descriptor, details
18325 are filled into *info by a langhook. */
18328 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18329 dw_die_ref context_die)
18331 dw_die_ref scope_die = scope_die_for (type, context_die);
18332 dw_die_ref array_die;
18335 array_die = new_die (DW_TAG_array_type, scope_die, type);
18336 add_name_attribute (array_die, type_tag (type));
18337 equate_type_number_to_die (type, array_die);
18339 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18341 && info->ndimensions >= 2)
18342 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18344 if (info->data_location)
18345 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18347 if (info->associated)
18348 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18350 if (info->allocated)
18351 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18354 for (dim = 0; dim < info->ndimensions; dim++)
18356 dw_die_ref subrange_die
18357 = new_die (DW_TAG_subrange_type, array_die, NULL);
18359 if (info->dimen[dim].lower_bound)
18361 /* If it is the default value, omit it. */
18364 if (host_integerp (info->dimen[dim].lower_bound, 0)
18365 && (dflt = lower_bound_default ()) != -1
18366 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18369 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18370 info->dimen[dim].lower_bound,
18373 if (info->dimen[dim].upper_bound)
18374 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18375 info->dimen[dim].upper_bound,
18377 if (info->dimen[dim].stride)
18378 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18379 info->dimen[dim].stride,
18383 gen_type_die (info->element_type, context_die);
18384 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18386 if (get_AT (array_die, DW_AT_name))
18387 add_pubtype (type, array_die);
18392 gen_entry_point_die (tree decl, dw_die_ref context_die)
18394 tree origin = decl_ultimate_origin (decl);
18395 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18397 if (origin != NULL)
18398 add_abstract_origin_attribute (decl_die, origin);
18401 add_name_and_src_coords_attributes (decl_die, decl);
18402 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18403 0, 0, context_die);
18406 if (DECL_ABSTRACT (decl))
18407 equate_decl_number_to_die (decl, decl_die);
18409 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18413 /* Walk through the list of incomplete types again, trying once more to
18414 emit full debugging info for them. */
18417 retry_incomplete_types (void)
18421 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18422 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18423 DINFO_USAGE_DIR_USE))
18424 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18427 /* Determine what tag to use for a record type. */
18429 static enum dwarf_tag
18430 record_type_tag (tree type)
18432 if (! lang_hooks.types.classify_record)
18433 return DW_TAG_structure_type;
18435 switch (lang_hooks.types.classify_record (type))
18437 case RECORD_IS_STRUCT:
18438 return DW_TAG_structure_type;
18440 case RECORD_IS_CLASS:
18441 return DW_TAG_class_type;
18443 case RECORD_IS_INTERFACE:
18444 if (dwarf_version >= 3 || !dwarf_strict)
18445 return DW_TAG_interface_type;
18446 return DW_TAG_structure_type;
18449 gcc_unreachable ();
18453 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18454 include all of the information about the enumeration values also. Each
18455 enumerated type name/value is listed as a child of the enumerated type
18459 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18461 dw_die_ref type_die = lookup_type_die (type);
18463 if (type_die == NULL)
18465 type_die = new_die (DW_TAG_enumeration_type,
18466 scope_die_for (type, context_die), type);
18467 equate_type_number_to_die (type, type_die);
18468 add_name_attribute (type_die, type_tag (type));
18469 if (dwarf_version >= 4 || !dwarf_strict)
18471 if (ENUM_IS_SCOPED (type))
18472 add_AT_flag (type_die, DW_AT_enum_class, 1);
18473 if (ENUM_IS_OPAQUE (type))
18474 add_AT_flag (type_die, DW_AT_declaration, 1);
18477 else if (! TYPE_SIZE (type))
18480 remove_AT (type_die, DW_AT_declaration);
18482 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18483 given enum type is incomplete, do not generate the DW_AT_byte_size
18484 attribute or the DW_AT_element_list attribute. */
18485 if (TYPE_SIZE (type))
18489 TREE_ASM_WRITTEN (type) = 1;
18490 add_byte_size_attribute (type_die, type);
18491 if (TYPE_STUB_DECL (type) != NULL_TREE)
18493 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18494 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18497 /* If the first reference to this type was as the return type of an
18498 inline function, then it may not have a parent. Fix this now. */
18499 if (type_die->die_parent == NULL)
18500 add_child_die (scope_die_for (type, context_die), type_die);
18502 for (link = TYPE_VALUES (type);
18503 link != NULL; link = TREE_CHAIN (link))
18505 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18506 tree value = TREE_VALUE (link);
18508 add_name_attribute (enum_die,
18509 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18511 if (TREE_CODE (value) == CONST_DECL)
18512 value = DECL_INITIAL (value);
18514 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18515 /* DWARF2 does not provide a way of indicating whether or
18516 not enumeration constants are signed or unsigned. GDB
18517 always assumes the values are signed, so we output all
18518 values as if they were signed. That means that
18519 enumeration constants with very large unsigned values
18520 will appear to have negative values in the debugger. */
18521 add_AT_int (enum_die, DW_AT_const_value,
18522 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18526 add_AT_flag (type_die, DW_AT_declaration, 1);
18528 if (get_AT (type_die, DW_AT_name))
18529 add_pubtype (type, type_die);
18534 /* Generate a DIE to represent either a real live formal parameter decl or to
18535 represent just the type of some formal parameter position in some function
18538 Note that this routine is a bit unusual because its argument may be a
18539 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18540 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18541 node. If it's the former then this function is being called to output a
18542 DIE to represent a formal parameter object (or some inlining thereof). If
18543 it's the latter, then this function is only being called to output a
18544 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18545 argument type of some subprogram type.
18546 If EMIT_NAME_P is true, name and source coordinate attributes
18550 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18551 dw_die_ref context_die)
18553 tree node_or_origin = node ? node : origin;
18554 tree ultimate_origin;
18555 dw_die_ref parm_die
18556 = new_die (DW_TAG_formal_parameter, context_die, node);
18558 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18560 case tcc_declaration:
18561 ultimate_origin = decl_ultimate_origin (node_or_origin);
18562 if (node || ultimate_origin)
18563 origin = ultimate_origin;
18564 if (origin != NULL)
18565 add_abstract_origin_attribute (parm_die, origin);
18566 else if (emit_name_p)
18567 add_name_and_src_coords_attributes (parm_die, node);
18569 || (! DECL_ABSTRACT (node_or_origin)
18570 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18571 decl_function_context
18572 (node_or_origin))))
18574 tree type = TREE_TYPE (node_or_origin);
18575 if (decl_by_reference_p (node_or_origin))
18576 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18579 add_type_attribute (parm_die, type,
18580 TREE_READONLY (node_or_origin),
18581 TREE_THIS_VOLATILE (node_or_origin),
18584 if (origin == NULL && DECL_ARTIFICIAL (node))
18585 add_AT_flag (parm_die, DW_AT_artificial, 1);
18587 if (node && node != origin)
18588 equate_decl_number_to_die (node, parm_die);
18589 if (! DECL_ABSTRACT (node_or_origin))
18590 add_location_or_const_value_attribute (parm_die, node_or_origin,
18596 /* We were called with some kind of a ..._TYPE node. */
18597 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18601 gcc_unreachable ();
18607 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18608 children DW_TAG_formal_parameter DIEs representing the arguments of the
18611 PARM_PACK must be a function parameter pack.
18612 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18613 must point to the subsequent arguments of the function PACK_ARG belongs to.
18614 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18615 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18616 following the last one for which a DIE was generated. */
18619 gen_formal_parameter_pack_die (tree parm_pack,
18621 dw_die_ref subr_die,
18625 dw_die_ref parm_pack_die;
18627 gcc_assert (parm_pack
18628 && lang_hooks.function_parameter_pack_p (parm_pack)
18631 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18632 add_src_coords_attributes (parm_pack_die, parm_pack);
18634 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18636 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18639 gen_formal_parameter_die (arg, NULL,
18640 false /* Don't emit name attribute. */,
18645 return parm_pack_die;
18648 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18649 at the end of an (ANSI prototyped) formal parameters list. */
18652 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18654 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18657 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18658 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18659 parameters as specified in some function type specification (except for
18660 those which appear as part of a function *definition*). */
18663 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18666 tree formal_type = NULL;
18667 tree first_parm_type;
18670 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18672 arg = DECL_ARGUMENTS (function_or_method_type);
18673 function_or_method_type = TREE_TYPE (function_or_method_type);
18678 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18680 /* Make our first pass over the list of formal parameter types and output a
18681 DW_TAG_formal_parameter DIE for each one. */
18682 for (link = first_parm_type; link; )
18684 dw_die_ref parm_die;
18686 formal_type = TREE_VALUE (link);
18687 if (formal_type == void_type_node)
18690 /* Output a (nameless) DIE to represent the formal parameter itself. */
18691 parm_die = gen_formal_parameter_die (formal_type, NULL,
18692 true /* Emit name attribute. */,
18694 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18695 && link == first_parm_type)
18697 add_AT_flag (parm_die, DW_AT_artificial, 1);
18698 if (dwarf_version >= 3 || !dwarf_strict)
18699 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18701 else if (arg && DECL_ARTIFICIAL (arg))
18702 add_AT_flag (parm_die, DW_AT_artificial, 1);
18704 link = TREE_CHAIN (link);
18706 arg = DECL_CHAIN (arg);
18709 /* If this function type has an ellipsis, add a
18710 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18711 if (formal_type != void_type_node)
18712 gen_unspecified_parameters_die (function_or_method_type, context_die);
18714 /* Make our second (and final) pass over the list of formal parameter types
18715 and output DIEs to represent those types (as necessary). */
18716 for (link = TYPE_ARG_TYPES (function_or_method_type);
18717 link && TREE_VALUE (link);
18718 link = TREE_CHAIN (link))
18719 gen_type_die (TREE_VALUE (link), context_die);
18722 /* We want to generate the DIE for TYPE so that we can generate the
18723 die for MEMBER, which has been defined; we will need to refer back
18724 to the member declaration nested within TYPE. If we're trying to
18725 generate minimal debug info for TYPE, processing TYPE won't do the
18726 trick; we need to attach the member declaration by hand. */
18729 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18731 gen_type_die (type, context_die);
18733 /* If we're trying to avoid duplicate debug info, we may not have
18734 emitted the member decl for this function. Emit it now. */
18735 if (TYPE_STUB_DECL (type)
18736 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18737 && ! lookup_decl_die (member))
18739 dw_die_ref type_die;
18740 gcc_assert (!decl_ultimate_origin (member));
18742 push_decl_scope (type);
18743 type_die = lookup_type_die_strip_naming_typedef (type);
18744 if (TREE_CODE (member) == FUNCTION_DECL)
18745 gen_subprogram_die (member, type_die);
18746 else if (TREE_CODE (member) == FIELD_DECL)
18748 /* Ignore the nameless fields that are used to skip bits but handle
18749 C++ anonymous unions and structs. */
18750 if (DECL_NAME (member) != NULL_TREE
18751 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18752 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18754 gen_type_die (member_declared_type (member), type_die);
18755 gen_field_die (member, type_die);
18759 gen_variable_die (member, NULL_TREE, type_die);
18765 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18766 may later generate inlined and/or out-of-line instances of. */
18769 dwarf2out_abstract_function (tree decl)
18771 dw_die_ref old_die;
18775 htab_t old_decl_loc_table;
18777 /* Make sure we have the actual abstract inline, not a clone. */
18778 decl = DECL_ORIGIN (decl);
18780 old_die = lookup_decl_die (decl);
18781 if (old_die && get_AT (old_die, DW_AT_inline))
18782 /* We've already generated the abstract instance. */
18785 /* We can be called while recursively when seeing block defining inlined subroutine
18786 DIE. Be sure to not clobber the outer location table nor use it or we would
18787 get locations in abstract instantces. */
18788 old_decl_loc_table = decl_loc_table;
18789 decl_loc_table = NULL;
18791 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18792 we don't get confused by DECL_ABSTRACT. */
18793 if (debug_info_level > DINFO_LEVEL_TERSE)
18795 context = decl_class_context (decl);
18797 gen_type_die_for_member
18798 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18801 /* Pretend we've just finished compiling this function. */
18802 save_fn = current_function_decl;
18803 current_function_decl = decl;
18804 push_cfun (DECL_STRUCT_FUNCTION (decl));
18806 was_abstract = DECL_ABSTRACT (decl);
18807 set_decl_abstract_flags (decl, 1);
18808 dwarf2out_decl (decl);
18809 if (! was_abstract)
18810 set_decl_abstract_flags (decl, 0);
18812 current_function_decl = save_fn;
18813 decl_loc_table = old_decl_loc_table;
18817 /* Helper function of premark_used_types() which gets called through
18820 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18821 marked as unused by prune_unused_types. */
18824 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18829 type = (tree) *slot;
18830 die = lookup_type_die (type);
18832 die->die_perennial_p = 1;
18836 /* Helper function of premark_types_used_by_global_vars which gets called
18837 through htab_traverse.
18839 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18840 marked as unused by prune_unused_types. The DIE of the type is marked
18841 only if the global variable using the type will actually be emitted. */
18844 premark_types_used_by_global_vars_helper (void **slot,
18845 void *data ATTRIBUTE_UNUSED)
18847 struct types_used_by_vars_entry *entry;
18850 entry = (struct types_used_by_vars_entry *) *slot;
18851 gcc_assert (entry->type != NULL
18852 && entry->var_decl != NULL);
18853 die = lookup_type_die (entry->type);
18856 /* Ask cgraph if the global variable really is to be emitted.
18857 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18858 struct varpool_node *node = varpool_get_node (entry->var_decl);
18859 if (node && node->needed)
18861 die->die_perennial_p = 1;
18862 /* Keep the parent DIEs as well. */
18863 while ((die = die->die_parent) && die->die_perennial_p == 0)
18864 die->die_perennial_p = 1;
18870 /* Mark all members of used_types_hash as perennial. */
18873 premark_used_types (void)
18875 if (cfun && cfun->used_types_hash)
18876 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18879 /* Mark all members of types_used_by_vars_entry as perennial. */
18882 premark_types_used_by_global_vars (void)
18884 if (types_used_by_vars_hash)
18885 htab_traverse (types_used_by_vars_hash,
18886 premark_types_used_by_global_vars_helper, NULL);
18889 /* Generate a DIE to represent a declared function (either file-scope or
18893 gen_subprogram_die (tree decl, dw_die_ref context_die)
18895 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
18896 tree origin = decl_ultimate_origin (decl);
18897 dw_die_ref subr_die;
18900 dw_die_ref old_die = lookup_decl_die (decl);
18901 int declaration = (current_function_decl != decl
18902 || class_or_namespace_scope_p (context_die));
18904 premark_used_types ();
18906 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18907 started to generate the abstract instance of an inline, decided to output
18908 its containing class, and proceeded to emit the declaration of the inline
18909 from the member list for the class. If so, DECLARATION takes priority;
18910 we'll get back to the abstract instance when done with the class. */
18912 /* The class-scope declaration DIE must be the primary DIE. */
18913 if (origin && declaration && class_or_namespace_scope_p (context_die))
18916 gcc_assert (!old_die);
18919 /* Now that the C++ front end lazily declares artificial member fns, we
18920 might need to retrofit the declaration into its class. */
18921 if (!declaration && !origin && !old_die
18922 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
18923 && !class_or_namespace_scope_p (context_die)
18924 && debug_info_level > DINFO_LEVEL_TERSE)
18925 old_die = force_decl_die (decl);
18927 if (origin != NULL)
18929 gcc_assert (!declaration || local_scope_p (context_die));
18931 /* Fixup die_parent for the abstract instance of a nested
18932 inline function. */
18933 if (old_die && old_die->die_parent == NULL)
18934 add_child_die (context_die, old_die);
18936 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18937 add_abstract_origin_attribute (subr_die, origin);
18941 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
18942 struct dwarf_file_data * file_index = lookup_filename (s.file);
18944 if (!get_AT_flag (old_die, DW_AT_declaration)
18945 /* We can have a normal definition following an inline one in the
18946 case of redefinition of GNU C extern inlines.
18947 It seems reasonable to use AT_specification in this case. */
18948 && !get_AT (old_die, DW_AT_inline))
18950 /* Detect and ignore this case, where we are trying to output
18951 something we have already output. */
18955 /* If the definition comes from the same place as the declaration,
18956 maybe use the old DIE. We always want the DIE for this function
18957 that has the *_pc attributes to be under comp_unit_die so the
18958 debugger can find it. We also need to do this for abstract
18959 instances of inlines, since the spec requires the out-of-line copy
18960 to have the same parent. For local class methods, this doesn't
18961 apply; we just use the old DIE. */
18962 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
18963 && (DECL_ARTIFICIAL (decl)
18964 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
18965 && (get_AT_unsigned (old_die, DW_AT_decl_line)
18966 == (unsigned) s.line))))
18968 subr_die = old_die;
18970 /* Clear out the declaration attribute and the formal parameters.
18971 Do not remove all children, because it is possible that this
18972 declaration die was forced using force_decl_die(). In such
18973 cases die that forced declaration die (e.g. TAG_imported_module)
18974 is one of the children that we do not want to remove. */
18975 remove_AT (subr_die, DW_AT_declaration);
18976 remove_AT (subr_die, DW_AT_object_pointer);
18977 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
18981 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18982 add_AT_specification (subr_die, old_die);
18983 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
18984 add_AT_file (subr_die, DW_AT_decl_file, file_index);
18985 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
18986 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
18991 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
18993 if (TREE_PUBLIC (decl))
18994 add_AT_flag (subr_die, DW_AT_external, 1);
18996 add_name_and_src_coords_attributes (subr_die, decl);
18997 if (debug_info_level > DINFO_LEVEL_TERSE)
18999 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19000 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19001 0, 0, context_die);
19004 add_pure_or_virtual_attribute (subr_die, decl);
19005 if (DECL_ARTIFICIAL (decl))
19006 add_AT_flag (subr_die, DW_AT_artificial, 1);
19008 add_accessibility_attribute (subr_die, decl);
19013 if (!old_die || !get_AT (old_die, DW_AT_inline))
19015 add_AT_flag (subr_die, DW_AT_declaration, 1);
19017 /* If this is an explicit function declaration then generate
19018 a DW_AT_explicit attribute. */
19019 if (lang_hooks.decls.function_decl_explicit_p (decl)
19020 && (dwarf_version >= 3 || !dwarf_strict))
19021 add_AT_flag (subr_die, DW_AT_explicit, 1);
19023 /* The first time we see a member function, it is in the context of
19024 the class to which it belongs. We make sure of this by emitting
19025 the class first. The next time is the definition, which is
19026 handled above. The two may come from the same source text.
19028 Note that force_decl_die() forces function declaration die. It is
19029 later reused to represent definition. */
19030 equate_decl_number_to_die (decl, subr_die);
19033 else if (DECL_ABSTRACT (decl))
19035 if (DECL_DECLARED_INLINE_P (decl))
19037 if (cgraph_function_possibly_inlined_p (decl))
19038 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19040 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19044 if (cgraph_function_possibly_inlined_p (decl))
19045 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19047 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19050 if (DECL_DECLARED_INLINE_P (decl)
19051 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19052 add_AT_flag (subr_die, DW_AT_artificial, 1);
19054 equate_decl_number_to_die (decl, subr_die);
19056 else if (!DECL_EXTERNAL (decl))
19058 HOST_WIDE_INT cfa_fb_offset;
19060 if (!old_die || !get_AT (old_die, DW_AT_inline))
19061 equate_decl_number_to_die (decl, subr_die);
19063 if (!flag_reorder_blocks_and_partition)
19065 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19066 current_function_funcdef_no);
19067 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19068 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19069 current_function_funcdef_no);
19070 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19072 #if VMS_DEBUGGING_INFO
19073 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19074 Section 2.3 Prologue and Epilogue Attributes:
19075 When a breakpoint is set on entry to a function, it is generally
19076 desirable for execution to be suspended, not on the very first
19077 instruction of the function, but rather at a point after the
19078 function's frame has been set up, after any language defined local
19079 declaration processing has been completed, and before execution of
19080 the first statement of the function begins. Debuggers generally
19081 cannot properly determine where this point is. Similarly for a
19082 breakpoint set on exit from a function. The prologue and epilogue
19083 attributes allow a compiler to communicate the location(s) to use. */
19086 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19088 if (fde->dw_fde_vms_end_prologue)
19089 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19090 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19092 if (fde->dw_fde_vms_begin_epilogue)
19093 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19094 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19098 add_pubname (decl, subr_die);
19099 add_arange (decl, subr_die);
19102 { /* Do nothing for now; maybe need to duplicate die, one for
19103 hot section and one for cold section, then use the hot/cold
19104 section begin/end labels to generate the aranges... */
19106 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
19107 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
19108 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
19109 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
19111 add_pubname (decl, subr_die);
19112 add_arange (decl, subr_die);
19113 add_arange (decl, subr_die);
19117 #ifdef MIPS_DEBUGGING_INFO
19118 /* Add a reference to the FDE for this routine. */
19119 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19122 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19124 /* We define the "frame base" as the function's CFA. This is more
19125 convenient for several reasons: (1) It's stable across the prologue
19126 and epilogue, which makes it better than just a frame pointer,
19127 (2) With dwarf3, there exists a one-byte encoding that allows us
19128 to reference the .debug_frame data by proxy, but failing that,
19129 (3) We can at least reuse the code inspection and interpretation
19130 code that determines the CFA position at various points in the
19132 if (dwarf_version >= 3)
19134 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19135 add_AT_loc (subr_die, DW_AT_frame_base, op);
19139 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19140 if (list->dw_loc_next)
19141 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19143 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19146 /* Compute a displacement from the "steady-state frame pointer" to
19147 the CFA. The former is what all stack slots and argument slots
19148 will reference in the rtl; the later is what we've told the
19149 debugger about. We'll need to adjust all frame_base references
19150 by this displacement. */
19151 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19153 if (cfun->static_chain_decl)
19154 add_AT_location_description (subr_die, DW_AT_static_link,
19155 loc_list_from_tree (cfun->static_chain_decl, 2));
19158 /* Generate child dies for template paramaters. */
19159 if (debug_info_level > DINFO_LEVEL_TERSE)
19160 gen_generic_params_dies (decl);
19162 /* Now output descriptions of the arguments for this function. This gets
19163 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19164 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19165 `...' at the end of the formal parameter list. In order to find out if
19166 there was a trailing ellipsis or not, we must instead look at the type
19167 associated with the FUNCTION_DECL. This will be a node of type
19168 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19169 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19170 an ellipsis at the end. */
19172 /* In the case where we are describing a mere function declaration, all we
19173 need to do here (and all we *can* do here) is to describe the *types* of
19174 its formal parameters. */
19175 if (debug_info_level <= DINFO_LEVEL_TERSE)
19177 else if (declaration)
19178 gen_formal_types_die (decl, subr_die);
19181 /* Generate DIEs to represent all known formal parameters. */
19182 tree parm = DECL_ARGUMENTS (decl);
19183 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19184 tree generic_decl_parm = generic_decl
19185 ? DECL_ARGUMENTS (generic_decl)
19188 /* Now we want to walk the list of parameters of the function and
19189 emit their relevant DIEs.
19191 We consider the case of DECL being an instance of a generic function
19192 as well as it being a normal function.
19194 If DECL is an instance of a generic function we walk the
19195 parameters of the generic function declaration _and_ the parameters of
19196 DECL itself. This is useful because we want to emit specific DIEs for
19197 function parameter packs and those are declared as part of the
19198 generic function declaration. In that particular case,
19199 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19200 That DIE has children DIEs representing the set of arguments
19201 of the pack. Note that the set of pack arguments can be empty.
19202 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19205 Otherwise, we just consider the parameters of DECL. */
19206 while (generic_decl_parm || parm)
19208 if (generic_decl_parm
19209 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19210 gen_formal_parameter_pack_die (generic_decl_parm,
19215 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19217 if (parm == DECL_ARGUMENTS (decl)
19218 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19220 && (dwarf_version >= 3 || !dwarf_strict))
19221 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19223 parm = DECL_CHAIN (parm);
19226 if (generic_decl_parm)
19227 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19230 /* Decide whether we need an unspecified_parameters DIE at the end.
19231 There are 2 more cases to do this for: 1) the ansi ... declaration -
19232 this is detectable when the end of the arg list is not a
19233 void_type_node 2) an unprototyped function declaration (not a
19234 definition). This just means that we have no info about the
19235 parameters at all. */
19236 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
19237 if (fn_arg_types != NULL)
19239 /* This is the prototyped case, check for.... */
19240 if (stdarg_p (TREE_TYPE (decl)))
19241 gen_unspecified_parameters_die (decl, subr_die);
19243 else if (DECL_INITIAL (decl) == NULL_TREE)
19244 gen_unspecified_parameters_die (decl, subr_die);
19247 /* Output Dwarf info for all of the stuff within the body of the function
19248 (if it has one - it may be just a declaration). */
19249 outer_scope = DECL_INITIAL (decl);
19251 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19252 a function. This BLOCK actually represents the outermost binding contour
19253 for the function, i.e. the contour in which the function's formal
19254 parameters and labels get declared. Curiously, it appears that the front
19255 end doesn't actually put the PARM_DECL nodes for the current function onto
19256 the BLOCK_VARS list for this outer scope, but are strung off of the
19257 DECL_ARGUMENTS list for the function instead.
19259 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19260 the LABEL_DECL nodes for the function however, and we output DWARF info
19261 for those in decls_for_scope. Just within the `outer_scope' there will be
19262 a BLOCK node representing the function's outermost pair of curly braces,
19263 and any blocks used for the base and member initializers of a C++
19264 constructor function. */
19265 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19267 /* Emit a DW_TAG_variable DIE for a named return value. */
19268 if (DECL_NAME (DECL_RESULT (decl)))
19269 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19271 current_function_has_inlines = 0;
19272 decls_for_scope (outer_scope, subr_die, 0);
19274 /* Add the calling convention attribute if requested. */
19275 add_calling_convention_attribute (subr_die, decl);
19279 /* Returns a hash value for X (which really is a die_struct). */
19282 common_block_die_table_hash (const void *x)
19284 const_dw_die_ref d = (const_dw_die_ref) x;
19285 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19288 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19289 as decl_id and die_parent of die_struct Y. */
19292 common_block_die_table_eq (const void *x, const void *y)
19294 const_dw_die_ref d = (const_dw_die_ref) x;
19295 const_dw_die_ref e = (const_dw_die_ref) y;
19296 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19299 /* Generate a DIE to represent a declared data object.
19300 Either DECL or ORIGIN must be non-null. */
19303 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19307 tree decl_or_origin = decl ? decl : origin;
19308 tree ultimate_origin;
19309 dw_die_ref var_die;
19310 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19311 dw_die_ref origin_die;
19312 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19313 || class_or_namespace_scope_p (context_die));
19314 bool specialization_p = false;
19316 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19317 if (decl || ultimate_origin)
19318 origin = ultimate_origin;
19319 com_decl = fortran_common (decl_or_origin, &off);
19321 /* Symbol in common gets emitted as a child of the common block, in the form
19322 of a data member. */
19325 dw_die_ref com_die;
19326 dw_loc_list_ref loc;
19327 die_node com_die_arg;
19329 var_die = lookup_decl_die (decl_or_origin);
19332 if (get_AT (var_die, DW_AT_location) == NULL)
19334 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19339 /* Optimize the common case. */
19340 if (single_element_loc_list_p (loc)
19341 && loc->expr->dw_loc_opc == DW_OP_addr
19342 && loc->expr->dw_loc_next == NULL
19343 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19345 loc->expr->dw_loc_oprnd1.v.val_addr
19346 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19348 loc_list_plus_const (loc, off);
19350 add_AT_location_description (var_die, DW_AT_location, loc);
19351 remove_AT (var_die, DW_AT_declaration);
19357 if (common_block_die_table == NULL)
19358 common_block_die_table
19359 = htab_create_ggc (10, common_block_die_table_hash,
19360 common_block_die_table_eq, NULL);
19362 com_die_arg.decl_id = DECL_UID (com_decl);
19363 com_die_arg.die_parent = context_die;
19364 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19365 loc = loc_list_from_tree (com_decl, 2);
19366 if (com_die == NULL)
19369 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19372 com_die = new_die (DW_TAG_common_block, context_die, decl);
19373 add_name_and_src_coords_attributes (com_die, com_decl);
19376 add_AT_location_description (com_die, DW_AT_location, loc);
19377 /* Avoid sharing the same loc descriptor between
19378 DW_TAG_common_block and DW_TAG_variable. */
19379 loc = loc_list_from_tree (com_decl, 2);
19381 else if (DECL_EXTERNAL (decl))
19382 add_AT_flag (com_die, DW_AT_declaration, 1);
19383 add_pubname_string (cnam, com_die); /* ??? needed? */
19384 com_die->decl_id = DECL_UID (com_decl);
19385 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19386 *slot = (void *) com_die;
19388 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19390 add_AT_location_description (com_die, DW_AT_location, loc);
19391 loc = loc_list_from_tree (com_decl, 2);
19392 remove_AT (com_die, DW_AT_declaration);
19394 var_die = new_die (DW_TAG_variable, com_die, decl);
19395 add_name_and_src_coords_attributes (var_die, decl);
19396 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19397 TREE_THIS_VOLATILE (decl), context_die);
19398 add_AT_flag (var_die, DW_AT_external, 1);
19403 /* Optimize the common case. */
19404 if (single_element_loc_list_p (loc)
19405 && loc->expr->dw_loc_opc == DW_OP_addr
19406 && loc->expr->dw_loc_next == NULL
19407 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19408 loc->expr->dw_loc_oprnd1.v.val_addr
19409 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19411 loc_list_plus_const (loc, off);
19413 add_AT_location_description (var_die, DW_AT_location, loc);
19415 else if (DECL_EXTERNAL (decl))
19416 add_AT_flag (var_die, DW_AT_declaration, 1);
19417 equate_decl_number_to_die (decl, var_die);
19421 /* If the compiler emitted a definition for the DECL declaration
19422 and if we already emitted a DIE for it, don't emit a second
19423 DIE for it again. Allow re-declarations of DECLs that are
19424 inside functions, though. */
19425 if (old_die && declaration && !local_scope_p (context_die))
19428 /* For static data members, the declaration in the class is supposed
19429 to have DW_TAG_member tag; the specification should still be
19430 DW_TAG_variable referencing the DW_TAG_member DIE. */
19431 if (declaration && class_scope_p (context_die))
19432 var_die = new_die (DW_TAG_member, context_die, decl);
19434 var_die = new_die (DW_TAG_variable, context_die, decl);
19437 if (origin != NULL)
19438 origin_die = add_abstract_origin_attribute (var_die, origin);
19440 /* Loop unrolling can create multiple blocks that refer to the same
19441 static variable, so we must test for the DW_AT_declaration flag.
19443 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19444 copy decls and set the DECL_ABSTRACT flag on them instead of
19447 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19449 ??? The declare_in_namespace support causes us to get two DIEs for one
19450 variable, both of which are declarations. We want to avoid considering
19451 one to be a specification, so we must test that this DIE is not a
19453 else if (old_die && TREE_STATIC (decl) && ! declaration
19454 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19456 /* This is a definition of a C++ class level static. */
19457 add_AT_specification (var_die, old_die);
19458 specialization_p = true;
19459 if (DECL_NAME (decl))
19461 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19462 struct dwarf_file_data * file_index = lookup_filename (s.file);
19464 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19465 add_AT_file (var_die, DW_AT_decl_file, file_index);
19467 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19468 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19470 if (old_die->die_tag == DW_TAG_member)
19471 add_linkage_name (var_die, decl);
19475 add_name_and_src_coords_attributes (var_die, decl);
19477 if ((origin == NULL && !specialization_p)
19479 && !DECL_ABSTRACT (decl_or_origin)
19480 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19481 decl_function_context
19482 (decl_or_origin))))
19484 tree type = TREE_TYPE (decl_or_origin);
19486 if (decl_by_reference_p (decl_or_origin))
19487 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19489 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19490 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19493 if (origin == NULL && !specialization_p)
19495 if (TREE_PUBLIC (decl))
19496 add_AT_flag (var_die, DW_AT_external, 1);
19498 if (DECL_ARTIFICIAL (decl))
19499 add_AT_flag (var_die, DW_AT_artificial, 1);
19501 add_accessibility_attribute (var_die, decl);
19505 add_AT_flag (var_die, DW_AT_declaration, 1);
19507 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19508 equate_decl_number_to_die (decl, var_die);
19511 && (! DECL_ABSTRACT (decl_or_origin)
19512 /* Local static vars are shared between all clones/inlines,
19513 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19515 || (TREE_CODE (decl_or_origin) == VAR_DECL
19516 && TREE_STATIC (decl_or_origin)
19517 && DECL_RTL_SET_P (decl_or_origin)))
19518 /* When abstract origin already has DW_AT_location attribute, no need
19519 to add it again. */
19520 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19522 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19523 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19524 defer_location (decl_or_origin, var_die);
19526 add_location_or_const_value_attribute (var_die,
19529 add_pubname (decl_or_origin, var_die);
19532 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19535 /* Generate a DIE to represent a named constant. */
19538 gen_const_die (tree decl, dw_die_ref context_die)
19540 dw_die_ref const_die;
19541 tree type = TREE_TYPE (decl);
19543 const_die = new_die (DW_TAG_constant, context_die, decl);
19544 add_name_and_src_coords_attributes (const_die, decl);
19545 add_type_attribute (const_die, type, 1, 0, context_die);
19546 if (TREE_PUBLIC (decl))
19547 add_AT_flag (const_die, DW_AT_external, 1);
19548 if (DECL_ARTIFICIAL (decl))
19549 add_AT_flag (const_die, DW_AT_artificial, 1);
19550 tree_add_const_value_attribute_for_decl (const_die, decl);
19553 /* Generate a DIE to represent a label identifier. */
19556 gen_label_die (tree decl, dw_die_ref context_die)
19558 tree origin = decl_ultimate_origin (decl);
19559 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19561 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19563 if (origin != NULL)
19564 add_abstract_origin_attribute (lbl_die, origin);
19566 add_name_and_src_coords_attributes (lbl_die, decl);
19568 if (DECL_ABSTRACT (decl))
19569 equate_decl_number_to_die (decl, lbl_die);
19572 insn = DECL_RTL_IF_SET (decl);
19574 /* Deleted labels are programmer specified labels which have been
19575 eliminated because of various optimizations. We still emit them
19576 here so that it is possible to put breakpoints on them. */
19580 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19582 /* When optimization is enabled (via -O) some parts of the compiler
19583 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19584 represent source-level labels which were explicitly declared by
19585 the user. This really shouldn't be happening though, so catch
19586 it if it ever does happen. */
19587 gcc_assert (!INSN_DELETED_P (insn));
19589 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19590 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19595 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19596 attributes to the DIE for a block STMT, to describe where the inlined
19597 function was called from. This is similar to add_src_coords_attributes. */
19600 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19602 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19604 if (dwarf_version >= 3 || !dwarf_strict)
19606 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19607 add_AT_unsigned (die, DW_AT_call_line, s.line);
19612 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19613 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19616 add_high_low_attributes (tree stmt, dw_die_ref die)
19618 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19620 if (BLOCK_FRAGMENT_CHAIN (stmt)
19621 && (dwarf_version >= 3 || !dwarf_strict))
19625 if (inlined_function_outer_scope_p (stmt))
19627 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19628 BLOCK_NUMBER (stmt));
19629 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19632 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19634 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19637 add_ranges (chain);
19638 chain = BLOCK_FRAGMENT_CHAIN (chain);
19645 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19646 BLOCK_NUMBER (stmt));
19647 add_AT_lbl_id (die, DW_AT_low_pc, label);
19648 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19649 BLOCK_NUMBER (stmt));
19650 add_AT_lbl_id (die, DW_AT_high_pc, label);
19654 /* Generate a DIE for a lexical block. */
19657 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19659 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19661 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19662 add_high_low_attributes (stmt, stmt_die);
19664 decls_for_scope (stmt, stmt_die, depth);
19667 /* Generate a DIE for an inlined subprogram. */
19670 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19674 /* The instance of function that is effectively being inlined shall not
19676 gcc_assert (! BLOCK_ABSTRACT (stmt));
19678 decl = block_ultimate_origin (stmt);
19680 /* Emit info for the abstract instance first, if we haven't yet. We
19681 must emit this even if the block is abstract, otherwise when we
19682 emit the block below (or elsewhere), we may end up trying to emit
19683 a die whose origin die hasn't been emitted, and crashing. */
19684 dwarf2out_abstract_function (decl);
19686 if (! BLOCK_ABSTRACT (stmt))
19688 dw_die_ref subr_die
19689 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
19691 add_abstract_origin_attribute (subr_die, decl);
19692 if (TREE_ASM_WRITTEN (stmt))
19693 add_high_low_attributes (stmt, subr_die);
19694 add_call_src_coords_attributes (stmt, subr_die);
19696 decls_for_scope (stmt, subr_die, depth);
19697 current_function_has_inlines = 1;
19701 /* Generate a DIE for a field in a record, or structure. */
19704 gen_field_die (tree decl, dw_die_ref context_die)
19706 dw_die_ref decl_die;
19708 if (TREE_TYPE (decl) == error_mark_node)
19711 decl_die = new_die (DW_TAG_member, context_die, decl);
19712 add_name_and_src_coords_attributes (decl_die, decl);
19713 add_type_attribute (decl_die, member_declared_type (decl),
19714 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
19717 if (DECL_BIT_FIELD_TYPE (decl))
19719 add_byte_size_attribute (decl_die, decl);
19720 add_bit_size_attribute (decl_die, decl);
19721 add_bit_offset_attribute (decl_die, decl);
19724 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
19725 add_data_member_location_attribute (decl_die, decl);
19727 if (DECL_ARTIFICIAL (decl))
19728 add_AT_flag (decl_die, DW_AT_artificial, 1);
19730 add_accessibility_attribute (decl_die, decl);
19732 /* Equate decl number to die, so that we can look up this decl later on. */
19733 equate_decl_number_to_die (decl, decl_die);
19737 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19738 Use modified_type_die instead.
19739 We keep this code here just in case these types of DIEs may be needed to
19740 represent certain things in other languages (e.g. Pascal) someday. */
19743 gen_pointer_type_die (tree type, dw_die_ref context_die)
19746 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
19748 equate_type_number_to_die (type, ptr_die);
19749 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19750 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19753 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19754 Use modified_type_die instead.
19755 We keep this code here just in case these types of DIEs may be needed to
19756 represent certain things in other languages (e.g. Pascal) someday. */
19759 gen_reference_type_die (tree type, dw_die_ref context_die)
19761 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
19763 if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
19764 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
19766 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
19768 equate_type_number_to_die (type, ref_die);
19769 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
19770 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
19774 /* Generate a DIE for a pointer to a member type. */
19777 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
19780 = new_die (DW_TAG_ptr_to_member_type,
19781 scope_die_for (type, context_die), type);
19783 equate_type_number_to_die (type, ptr_die);
19784 add_AT_die_ref (ptr_die, DW_AT_containing_type,
19785 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
19786 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
19789 /* Generate the DIE for the compilation unit. */
19792 gen_compile_unit_die (const char *filename)
19795 char producer[250];
19796 const char *language_string = lang_hooks.name;
19799 die = new_die (DW_TAG_compile_unit, NULL, NULL);
19803 add_name_attribute (die, filename);
19804 /* Don't add cwd for <built-in>. */
19805 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
19806 add_comp_dir_attribute (die);
19809 sprintf (producer, "%s %s", language_string, version_string);
19811 #ifdef MIPS_DEBUGGING_INFO
19812 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
19813 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
19814 not appear in the producer string, the debugger reaches the conclusion
19815 that the object file is stripped and has no debugging information.
19816 To get the MIPS/SGI debugger to believe that there is debugging
19817 information in the object file, we add a -g to the producer string. */
19818 if (debug_info_level > DINFO_LEVEL_TERSE)
19819 strcat (producer, " -g");
19822 add_AT_string (die, DW_AT_producer, producer);
19824 /* If our producer is LTO try to figure out a common language to use
19825 from the global list of translation units. */
19826 if (strcmp (language_string, "GNU GIMPLE") == 0)
19830 const char *common_lang = NULL;
19832 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
19834 if (!TRANSLATION_UNIT_LANGUAGE (t))
19837 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
19838 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
19840 else if (strncmp (common_lang, "GNU C", 5) == 0
19841 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
19842 /* Mixing C and C++ is ok, use C++ in that case. */
19843 common_lang = "GNU C++";
19846 /* Fall back to C. */
19847 common_lang = NULL;
19853 language_string = common_lang;
19856 language = DW_LANG_C89;
19857 if (strcmp (language_string, "GNU C++") == 0)
19858 language = DW_LANG_C_plus_plus;
19859 else if (strcmp (language_string, "GNU F77") == 0)
19860 language = DW_LANG_Fortran77;
19861 else if (strcmp (language_string, "GNU Pascal") == 0)
19862 language = DW_LANG_Pascal83;
19863 else if (dwarf_version >= 3 || !dwarf_strict)
19865 if (strcmp (language_string, "GNU Ada") == 0)
19866 language = DW_LANG_Ada95;
19867 else if (strcmp (language_string, "GNU Fortran") == 0)
19868 language = DW_LANG_Fortran95;
19869 else if (strcmp (language_string, "GNU Java") == 0)
19870 language = DW_LANG_Java;
19871 else if (strcmp (language_string, "GNU Objective-C") == 0)
19872 language = DW_LANG_ObjC;
19873 else if (strcmp (language_string, "GNU Objective-C++") == 0)
19874 language = DW_LANG_ObjC_plus_plus;
19877 add_AT_unsigned (die, DW_AT_language, language);
19881 case DW_LANG_Fortran77:
19882 case DW_LANG_Fortran90:
19883 case DW_LANG_Fortran95:
19884 /* Fortran has case insensitive identifiers and the front-end
19885 lowercases everything. */
19886 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
19889 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19895 /* Generate the DIE for a base class. */
19898 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
19900 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
19902 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
19903 add_data_member_location_attribute (die, binfo);
19905 if (BINFO_VIRTUAL_P (binfo))
19906 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
19908 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19909 children, otherwise the default is DW_ACCESS_public. In DWARF2
19910 the default has always been DW_ACCESS_private. */
19911 if (access == access_public_node)
19913 if (dwarf_version == 2
19914 || context_die->die_tag == DW_TAG_class_type)
19915 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
19917 else if (access == access_protected_node)
19918 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
19919 else if (dwarf_version > 2
19920 && context_die->die_tag != DW_TAG_class_type)
19921 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
19924 /* Generate a DIE for a class member. */
19927 gen_member_die (tree type, dw_die_ref context_die)
19930 tree binfo = TYPE_BINFO (type);
19933 /* If this is not an incomplete type, output descriptions of each of its
19934 members. Note that as we output the DIEs necessary to represent the
19935 members of this record or union type, we will also be trying to output
19936 DIEs to represent the *types* of those members. However the `type'
19937 function (above) will specifically avoid generating type DIEs for member
19938 types *within* the list of member DIEs for this (containing) type except
19939 for those types (of members) which are explicitly marked as also being
19940 members of this (containing) type themselves. The g++ front- end can
19941 force any given type to be treated as a member of some other (containing)
19942 type by setting the TYPE_CONTEXT of the given (member) type to point to
19943 the TREE node representing the appropriate (containing) type. */
19945 /* First output info about the base classes. */
19948 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
19952 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
19953 gen_inheritance_die (base,
19954 (accesses ? VEC_index (tree, accesses, i)
19955 : access_public_node), context_die);
19958 /* Now output info about the data members and type members. */
19959 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
19961 /* If we thought we were generating minimal debug info for TYPE
19962 and then changed our minds, some of the member declarations
19963 may have already been defined. Don't define them again, but
19964 do put them in the right order. */
19966 child = lookup_decl_die (member);
19968 splice_child_die (context_die, child);
19970 gen_decl_die (member, NULL, context_die);
19973 /* Now output info about the function members (if any). */
19974 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
19976 /* Don't include clones in the member list. */
19977 if (DECL_ABSTRACT_ORIGIN (member))
19980 child = lookup_decl_die (member);
19982 splice_child_die (context_die, child);
19984 gen_decl_die (member, NULL, context_die);
19988 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19989 is set, we pretend that the type was never defined, so we only get the
19990 member DIEs needed by later specification DIEs. */
19993 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
19994 enum debug_info_usage usage)
19996 dw_die_ref type_die = lookup_type_die (type);
19997 dw_die_ref scope_die = 0;
19999 int complete = (TYPE_SIZE (type)
20000 && (! TYPE_STUB_DECL (type)
20001 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20002 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20003 complete = complete && should_emit_struct_debug (type, usage);
20005 if (type_die && ! complete)
20008 if (TYPE_CONTEXT (type) != NULL_TREE
20009 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20010 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20013 scope_die = scope_die_for (type, context_die);
20015 if (! type_die || (nested && is_cu_die (scope_die)))
20016 /* First occurrence of type or toplevel definition of nested class. */
20018 dw_die_ref old_die = type_die;
20020 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20021 ? record_type_tag (type) : DW_TAG_union_type,
20023 equate_type_number_to_die (type, type_die);
20025 add_AT_specification (type_die, old_die);
20027 add_name_attribute (type_die, type_tag (type));
20030 remove_AT (type_die, DW_AT_declaration);
20032 /* Generate child dies for template paramaters. */
20033 if (debug_info_level > DINFO_LEVEL_TERSE
20034 && COMPLETE_TYPE_P (type))
20035 gen_generic_params_dies (type);
20037 /* If this type has been completed, then give it a byte_size attribute and
20038 then give a list of members. */
20039 if (complete && !ns_decl)
20041 /* Prevent infinite recursion in cases where the type of some member of
20042 this type is expressed in terms of this type itself. */
20043 TREE_ASM_WRITTEN (type) = 1;
20044 add_byte_size_attribute (type_die, type);
20045 if (TYPE_STUB_DECL (type) != NULL_TREE)
20047 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20048 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20051 /* If the first reference to this type was as the return type of an
20052 inline function, then it may not have a parent. Fix this now. */
20053 if (type_die->die_parent == NULL)
20054 add_child_die (scope_die, type_die);
20056 push_decl_scope (type);
20057 gen_member_die (type, type_die);
20060 /* GNU extension: Record what type our vtable lives in. */
20061 if (TYPE_VFIELD (type))
20063 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20065 gen_type_die (vtype, context_die);
20066 add_AT_die_ref (type_die, DW_AT_containing_type,
20067 lookup_type_die (vtype));
20072 add_AT_flag (type_die, DW_AT_declaration, 1);
20074 /* We don't need to do this for function-local types. */
20075 if (TYPE_STUB_DECL (type)
20076 && ! decl_function_context (TYPE_STUB_DECL (type)))
20077 VEC_safe_push (tree, gc, incomplete_types, type);
20080 if (get_AT (type_die, DW_AT_name))
20081 add_pubtype (type, type_die);
20084 /* Generate a DIE for a subroutine _type_. */
20087 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20089 tree return_type = TREE_TYPE (type);
20090 dw_die_ref subr_die
20091 = new_die (DW_TAG_subroutine_type,
20092 scope_die_for (type, context_die), type);
20094 equate_type_number_to_die (type, subr_die);
20095 add_prototyped_attribute (subr_die, type);
20096 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20097 gen_formal_types_die (type, subr_die);
20099 if (get_AT (subr_die, DW_AT_name))
20100 add_pubtype (type, subr_die);
20103 /* Generate a DIE for a type definition. */
20106 gen_typedef_die (tree decl, dw_die_ref context_die)
20108 dw_die_ref type_die;
20111 if (TREE_ASM_WRITTEN (decl))
20114 TREE_ASM_WRITTEN (decl) = 1;
20115 type_die = new_die (DW_TAG_typedef, context_die, decl);
20116 origin = decl_ultimate_origin (decl);
20117 if (origin != NULL)
20118 add_abstract_origin_attribute (type_die, origin);
20123 add_name_and_src_coords_attributes (type_die, decl);
20124 if (DECL_ORIGINAL_TYPE (decl))
20126 type = DECL_ORIGINAL_TYPE (decl);
20128 gcc_assert (type != TREE_TYPE (decl));
20129 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20133 type = TREE_TYPE (decl);
20135 if (is_naming_typedef_decl (TYPE_NAME (type)))
20137 /* Here, we are in the case of decl being a typedef naming
20138 an anonymous type, e.g:
20139 typedef struct {...} foo;
20140 In that case TREE_TYPE (decl) is not a typedef variant
20141 type and TYPE_NAME of the anonymous type is set to the
20142 TYPE_DECL of the typedef. This construct is emitted by
20145 TYPE is the anonymous struct named by the typedef
20146 DECL. As we need the DW_AT_type attribute of the
20147 DW_TAG_typedef to point to the DIE of TYPE, let's
20148 generate that DIE right away. add_type_attribute
20149 called below will then pick (via lookup_type_die) that
20150 anonymous struct DIE. */
20151 if (!TREE_ASM_WRITTEN (type))
20152 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20156 add_type_attribute (type_die, type, TREE_READONLY (decl),
20157 TREE_THIS_VOLATILE (decl), context_die);
20159 if (is_naming_typedef_decl (decl))
20160 /* We want that all subsequent calls to lookup_type_die with
20161 TYPE in argument yield the DW_TAG_typedef we have just
20163 equate_type_number_to_die (type, type_die);
20165 add_accessibility_attribute (type_die, decl);
20168 if (DECL_ABSTRACT (decl))
20169 equate_decl_number_to_die (decl, type_die);
20171 if (get_AT (type_die, DW_AT_name))
20172 add_pubtype (decl, type_die);
20175 /* Generate a DIE for a struct, class, enum or union type. */
20178 gen_tagged_type_die (tree type,
20179 dw_die_ref context_die,
20180 enum debug_info_usage usage)
20184 if (type == NULL_TREE
20185 || !is_tagged_type (type))
20188 /* If this is a nested type whose containing class hasn't been written
20189 out yet, writing it out will cover this one, too. This does not apply
20190 to instantiations of member class templates; they need to be added to
20191 the containing class as they are generated. FIXME: This hurts the
20192 idea of combining type decls from multiple TUs, since we can't predict
20193 what set of template instantiations we'll get. */
20194 if (TYPE_CONTEXT (type)
20195 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20196 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20198 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20200 if (TREE_ASM_WRITTEN (type))
20203 /* If that failed, attach ourselves to the stub. */
20204 push_decl_scope (TYPE_CONTEXT (type));
20205 context_die = lookup_type_die (TYPE_CONTEXT (type));
20208 else if (TYPE_CONTEXT (type) != NULL_TREE
20209 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20211 /* If this type is local to a function that hasn't been written
20212 out yet, use a NULL context for now; it will be fixed up in
20213 decls_for_scope. */
20214 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20219 context_die = declare_in_namespace (type, context_die);
20223 if (TREE_CODE (type) == ENUMERAL_TYPE)
20225 /* This might have been written out by the call to
20226 declare_in_namespace. */
20227 if (!TREE_ASM_WRITTEN (type))
20228 gen_enumeration_type_die (type, context_die);
20231 gen_struct_or_union_type_die (type, context_die, usage);
20236 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20237 it up if it is ever completed. gen_*_type_die will set it for us
20238 when appropriate. */
20241 /* Generate a type description DIE. */
20244 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20245 enum debug_info_usage usage)
20247 struct array_descr_info info;
20249 if (type == NULL_TREE || type == error_mark_node)
20252 /* If TYPE is a typedef type variant, let's generate debug info
20253 for the parent typedef which TYPE is a type of. */
20254 if (typedef_variant_p (type))
20256 if (TREE_ASM_WRITTEN (type))
20259 /* Prevent broken recursion; we can't hand off to the same type. */
20260 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20262 /* Use the DIE of the containing namespace as the parent DIE of
20263 the type description DIE we want to generate. */
20264 if (DECL_CONTEXT (TYPE_NAME (type))
20265 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20266 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20268 TREE_ASM_WRITTEN (type) = 1;
20270 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20274 /* If type is an anonymous tagged type named by a typedef, let's
20275 generate debug info for the typedef. */
20276 if (is_naming_typedef_decl (TYPE_NAME (type)))
20278 /* Use the DIE of the containing namespace as the parent DIE of
20279 the type description DIE we want to generate. */
20280 if (DECL_CONTEXT (TYPE_NAME (type))
20281 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20282 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20284 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20288 /* If this is an array type with hidden descriptor, handle it first. */
20289 if (!TREE_ASM_WRITTEN (type)
20290 && lang_hooks.types.get_array_descr_info
20291 && lang_hooks.types.get_array_descr_info (type, &info)
20292 && (dwarf_version >= 3 || !dwarf_strict))
20294 gen_descr_array_type_die (type, &info, context_die);
20295 TREE_ASM_WRITTEN (type) = 1;
20299 /* We are going to output a DIE to represent the unqualified version
20300 of this type (i.e. without any const or volatile qualifiers) so
20301 get the main variant (i.e. the unqualified version) of this type
20302 now. (Vectors are special because the debugging info is in the
20303 cloned type itself). */
20304 if (TREE_CODE (type) != VECTOR_TYPE)
20305 type = type_main_variant (type);
20307 if (TREE_ASM_WRITTEN (type))
20310 switch (TREE_CODE (type))
20316 case REFERENCE_TYPE:
20317 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20318 ensures that the gen_type_die recursion will terminate even if the
20319 type is recursive. Recursive types are possible in Ada. */
20320 /* ??? We could perhaps do this for all types before the switch
20322 TREE_ASM_WRITTEN (type) = 1;
20324 /* For these types, all that is required is that we output a DIE (or a
20325 set of DIEs) to represent the "basis" type. */
20326 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20327 DINFO_USAGE_IND_USE);
20331 /* This code is used for C++ pointer-to-data-member types.
20332 Output a description of the relevant class type. */
20333 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20334 DINFO_USAGE_IND_USE);
20336 /* Output a description of the type of the object pointed to. */
20337 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20338 DINFO_USAGE_IND_USE);
20340 /* Now output a DIE to represent this pointer-to-data-member type
20342 gen_ptr_to_mbr_type_die (type, context_die);
20345 case FUNCTION_TYPE:
20346 /* Force out return type (in case it wasn't forced out already). */
20347 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20348 DINFO_USAGE_DIR_USE);
20349 gen_subroutine_type_die (type, context_die);
20353 /* Force out return type (in case it wasn't forced out already). */
20354 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20355 DINFO_USAGE_DIR_USE);
20356 gen_subroutine_type_die (type, context_die);
20360 gen_array_type_die (type, context_die);
20364 gen_array_type_die (type, context_die);
20367 case ENUMERAL_TYPE:
20370 case QUAL_UNION_TYPE:
20371 gen_tagged_type_die (type, context_die, usage);
20377 case FIXED_POINT_TYPE:
20380 /* No DIEs needed for fundamental types. */
20385 /* Just use DW_TAG_unspecified_type. */
20387 dw_die_ref type_die = lookup_type_die (type);
20388 if (type_die == NULL)
20390 tree name = TYPE_NAME (type);
20391 if (TREE_CODE (name) == TYPE_DECL)
20392 name = DECL_NAME (name);
20393 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20394 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20395 equate_type_number_to_die (type, type_die);
20401 gcc_unreachable ();
20404 TREE_ASM_WRITTEN (type) = 1;
20408 gen_type_die (tree type, dw_die_ref context_die)
20410 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20413 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20414 things which are local to the given block. */
20417 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20419 int must_output_die = 0;
20422 /* Ignore blocks that are NULL. */
20423 if (stmt == NULL_TREE)
20426 inlined_func = inlined_function_outer_scope_p (stmt);
20428 /* If the block is one fragment of a non-contiguous block, do not
20429 process the variables, since they will have been done by the
20430 origin block. Do process subblocks. */
20431 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20435 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20436 gen_block_die (sub, context_die, depth + 1);
20441 /* Determine if we need to output any Dwarf DIEs at all to represent this
20444 /* The outer scopes for inlinings *must* always be represented. We
20445 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20446 must_output_die = 1;
20449 /* Determine if this block directly contains any "significant"
20450 local declarations which we will need to output DIEs for. */
20451 if (debug_info_level > DINFO_LEVEL_TERSE)
20452 /* We are not in terse mode so *any* local declaration counts
20453 as being a "significant" one. */
20454 must_output_die = ((BLOCK_VARS (stmt) != NULL
20455 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20456 && (TREE_USED (stmt)
20457 || TREE_ASM_WRITTEN (stmt)
20458 || BLOCK_ABSTRACT (stmt)));
20459 else if ((TREE_USED (stmt)
20460 || TREE_ASM_WRITTEN (stmt)
20461 || BLOCK_ABSTRACT (stmt))
20462 && !dwarf2out_ignore_block (stmt))
20463 must_output_die = 1;
20466 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20467 DIE for any block which contains no significant local declarations at
20468 all. Rather, in such cases we just call `decls_for_scope' so that any
20469 needed Dwarf info for any sub-blocks will get properly generated. Note
20470 that in terse mode, our definition of what constitutes a "significant"
20471 local declaration gets restricted to include only inlined function
20472 instances and local (nested) function definitions. */
20473 if (must_output_die)
20477 /* If STMT block is abstract, that means we have been called
20478 indirectly from dwarf2out_abstract_function.
20479 That function rightfully marks the descendent blocks (of
20480 the abstract function it is dealing with) as being abstract,
20481 precisely to prevent us from emitting any
20482 DW_TAG_inlined_subroutine DIE as a descendent
20483 of an abstract function instance. So in that case, we should
20484 not call gen_inlined_subroutine_die.
20486 Later though, when cgraph asks dwarf2out to emit info
20487 for the concrete instance of the function decl into which
20488 the concrete instance of STMT got inlined, the later will lead
20489 to the generation of a DW_TAG_inlined_subroutine DIE. */
20490 if (! BLOCK_ABSTRACT (stmt))
20491 gen_inlined_subroutine_die (stmt, context_die, depth);
20494 gen_lexical_block_die (stmt, context_die, depth);
20497 decls_for_scope (stmt, context_die, depth);
20500 /* Process variable DECL (or variable with origin ORIGIN) within
20501 block STMT and add it to CONTEXT_DIE. */
20503 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20506 tree decl_or_origin = decl ? decl : origin;
20508 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20509 die = lookup_decl_die (decl_or_origin);
20510 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20511 && TYPE_DECL_IS_STUB (decl_or_origin))
20512 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20516 if (die != NULL && die->die_parent == NULL)
20517 add_child_die (context_die, die);
20518 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20519 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20520 stmt, context_die);
20522 gen_decl_die (decl, origin, context_die);
20525 /* Generate all of the decls declared within a given scope and (recursively)
20526 all of its sub-blocks. */
20529 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20535 /* Ignore NULL blocks. */
20536 if (stmt == NULL_TREE)
20539 /* Output the DIEs to represent all of the data objects and typedefs
20540 declared directly within this block but not within any nested
20541 sub-blocks. Also, nested function and tag DIEs have been
20542 generated with a parent of NULL; fix that up now. */
20543 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20544 process_scope_var (stmt, decl, NULL_TREE, context_die);
20545 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20546 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20549 /* If we're at -g1, we're not interested in subblocks. */
20550 if (debug_info_level <= DINFO_LEVEL_TERSE)
20553 /* Output the DIEs to represent all sub-blocks (and the items declared
20554 therein) of this block. */
20555 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20557 subblocks = BLOCK_CHAIN (subblocks))
20558 gen_block_die (subblocks, context_die, depth + 1);
20561 /* Is this a typedef we can avoid emitting? */
20564 is_redundant_typedef (const_tree decl)
20566 if (TYPE_DECL_IS_STUB (decl))
20569 if (DECL_ARTIFICIAL (decl)
20570 && DECL_CONTEXT (decl)
20571 && is_tagged_type (DECL_CONTEXT (decl))
20572 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20573 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20574 /* Also ignore the artificial member typedef for the class name. */
20580 /* Return TRUE if TYPE is a typedef that names a type for linkage
20581 purposes. This kind of typedefs is produced by the C++ FE for
20584 typedef struct {...} foo;
20586 In that case, there is no typedef variant type produced for foo.
20587 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20591 is_naming_typedef_decl (const_tree decl)
20593 if (decl == NULL_TREE
20594 || TREE_CODE (decl) != TYPE_DECL
20595 || !is_tagged_type (TREE_TYPE (decl))
20596 || DECL_IS_BUILTIN (decl)
20597 || is_redundant_typedef (decl)
20598 /* It looks like Ada produces TYPE_DECLs that are very similar
20599 to C++ naming typedefs but that have different
20600 semantics. Let's be specific to c++ for now. */
20604 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20605 && TYPE_NAME (TREE_TYPE (decl)) == decl
20606 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20607 != TYPE_NAME (TREE_TYPE (decl))));
20610 /* Returns the DIE for a context. */
20612 static inline dw_die_ref
20613 get_context_die (tree context)
20617 /* Find die that represents this context. */
20618 if (TYPE_P (context))
20619 return force_type_die (TYPE_MAIN_VARIANT (context));
20621 return force_decl_die (context);
20623 return comp_unit_die ();
20626 /* Returns the DIE for decl. A DIE will always be returned. */
20629 force_decl_die (tree decl)
20631 dw_die_ref decl_die;
20632 unsigned saved_external_flag;
20633 tree save_fn = NULL_TREE;
20634 decl_die = lookup_decl_die (decl);
20637 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20639 decl_die = lookup_decl_die (decl);
20643 switch (TREE_CODE (decl))
20645 case FUNCTION_DECL:
20646 /* Clear current_function_decl, so that gen_subprogram_die thinks
20647 that this is a declaration. At this point, we just want to force
20648 declaration die. */
20649 save_fn = current_function_decl;
20650 current_function_decl = NULL_TREE;
20651 gen_subprogram_die (decl, context_die);
20652 current_function_decl = save_fn;
20656 /* Set external flag to force declaration die. Restore it after
20657 gen_decl_die() call. */
20658 saved_external_flag = DECL_EXTERNAL (decl);
20659 DECL_EXTERNAL (decl) = 1;
20660 gen_decl_die (decl, NULL, context_die);
20661 DECL_EXTERNAL (decl) = saved_external_flag;
20664 case NAMESPACE_DECL:
20665 if (dwarf_version >= 3 || !dwarf_strict)
20666 dwarf2out_decl (decl);
20668 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20669 decl_die = comp_unit_die ();
20672 case TRANSLATION_UNIT_DECL:
20673 decl_die = comp_unit_die ();
20677 gcc_unreachable ();
20680 /* We should be able to find the DIE now. */
20682 decl_die = lookup_decl_die (decl);
20683 gcc_assert (decl_die);
20689 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20690 always returned. */
20693 force_type_die (tree type)
20695 dw_die_ref type_die;
20697 type_die = lookup_type_die (type);
20700 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
20702 type_die = modified_type_die (type, TYPE_READONLY (type),
20703 TYPE_VOLATILE (type), context_die);
20704 gcc_assert (type_die);
20709 /* Force out any required namespaces to be able to output DECL,
20710 and return the new context_die for it, if it's changed. */
20713 setup_namespace_context (tree thing, dw_die_ref context_die)
20715 tree context = (DECL_P (thing)
20716 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
20717 if (context && TREE_CODE (context) == NAMESPACE_DECL)
20718 /* Force out the namespace. */
20719 context_die = force_decl_die (context);
20721 return context_die;
20724 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20725 type) within its namespace, if appropriate.
20727 For compatibility with older debuggers, namespace DIEs only contain
20728 declarations; all definitions are emitted at CU scope. */
20731 declare_in_namespace (tree thing, dw_die_ref context_die)
20733 dw_die_ref ns_context;
20735 if (debug_info_level <= DINFO_LEVEL_TERSE)
20736 return context_die;
20738 /* If this decl is from an inlined function, then don't try to emit it in its
20739 namespace, as we will get confused. It would have already been emitted
20740 when the abstract instance of the inline function was emitted anyways. */
20741 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
20742 return context_die;
20744 ns_context = setup_namespace_context (thing, context_die);
20746 if (ns_context != context_die)
20750 if (DECL_P (thing))
20751 gen_decl_die (thing, NULL, ns_context);
20753 gen_type_die (thing, ns_context);
20755 return context_die;
20758 /* Generate a DIE for a namespace or namespace alias. */
20761 gen_namespace_die (tree decl, dw_die_ref context_die)
20763 dw_die_ref namespace_die;
20765 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20766 they are an alias of. */
20767 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
20769 /* Output a real namespace or module. */
20770 context_die = setup_namespace_context (decl, comp_unit_die ());
20771 namespace_die = new_die (is_fortran ()
20772 ? DW_TAG_module : DW_TAG_namespace,
20773 context_die, decl);
20774 /* For Fortran modules defined in different CU don't add src coords. */
20775 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
20777 const char *name = dwarf2_name (decl, 0);
20779 add_name_attribute (namespace_die, name);
20782 add_name_and_src_coords_attributes (namespace_die, decl);
20783 if (DECL_EXTERNAL (decl))
20784 add_AT_flag (namespace_die, DW_AT_declaration, 1);
20785 equate_decl_number_to_die (decl, namespace_die);
20789 /* Output a namespace alias. */
20791 /* Force out the namespace we are an alias of, if necessary. */
20792 dw_die_ref origin_die
20793 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
20795 if (DECL_FILE_SCOPE_P (decl)
20796 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
20797 context_die = setup_namespace_context (decl, comp_unit_die ());
20798 /* Now create the namespace alias DIE. */
20799 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
20800 add_name_and_src_coords_attributes (namespace_die, decl);
20801 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
20802 equate_decl_number_to_die (decl, namespace_die);
20806 /* Generate Dwarf debug information for a decl described by DECL.
20807 The return value is currently only meaningful for PARM_DECLs,
20808 for all other decls it returns NULL. */
20811 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
20813 tree decl_or_origin = decl ? decl : origin;
20814 tree class_origin = NULL, ultimate_origin;
20816 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
20819 switch (TREE_CODE (decl_or_origin))
20825 if (!is_fortran () && !is_ada ())
20827 /* The individual enumerators of an enum type get output when we output
20828 the Dwarf representation of the relevant enum type itself. */
20832 /* Emit its type. */
20833 gen_type_die (TREE_TYPE (decl), context_die);
20835 /* And its containing namespace. */
20836 context_die = declare_in_namespace (decl, context_die);
20838 gen_const_die (decl, context_die);
20841 case FUNCTION_DECL:
20842 /* Don't output any DIEs to represent mere function declarations,
20843 unless they are class members or explicit block externs. */
20844 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
20845 && DECL_FILE_SCOPE_P (decl_or_origin)
20846 && (current_function_decl == NULL_TREE
20847 || DECL_ARTIFICIAL (decl_or_origin)))
20852 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20853 on local redeclarations of global functions. That seems broken. */
20854 if (current_function_decl != decl)
20855 /* This is only a declaration. */;
20858 /* If we're emitting a clone, emit info for the abstract instance. */
20859 if (origin || DECL_ORIGIN (decl) != decl)
20860 dwarf2out_abstract_function (origin
20861 ? DECL_ORIGIN (origin)
20862 : DECL_ABSTRACT_ORIGIN (decl));
20864 /* If we're emitting an out-of-line copy of an inline function,
20865 emit info for the abstract instance and set up to refer to it. */
20866 else if (cgraph_function_possibly_inlined_p (decl)
20867 && ! DECL_ABSTRACT (decl)
20868 && ! class_or_namespace_scope_p (context_die)
20869 /* dwarf2out_abstract_function won't emit a die if this is just
20870 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20871 that case, because that works only if we have a die. */
20872 && DECL_INITIAL (decl) != NULL_TREE)
20874 dwarf2out_abstract_function (decl);
20875 set_decl_origin_self (decl);
20878 /* Otherwise we're emitting the primary DIE for this decl. */
20879 else if (debug_info_level > DINFO_LEVEL_TERSE)
20881 /* Before we describe the FUNCTION_DECL itself, make sure that we
20882 have its containing type. */
20884 origin = decl_class_context (decl);
20885 if (origin != NULL_TREE)
20886 gen_type_die (origin, context_die);
20888 /* And its return type. */
20889 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
20891 /* And its virtual context. */
20892 if (DECL_VINDEX (decl) != NULL_TREE)
20893 gen_type_die (DECL_CONTEXT (decl), context_die);
20895 /* Make sure we have a member DIE for decl. */
20896 if (origin != NULL_TREE)
20897 gen_type_die_for_member (origin, decl, context_die);
20899 /* And its containing namespace. */
20900 context_die = declare_in_namespace (decl, context_die);
20903 /* Now output a DIE to represent the function itself. */
20905 gen_subprogram_die (decl, context_die);
20909 /* If we are in terse mode, don't generate any DIEs to represent any
20910 actual typedefs. */
20911 if (debug_info_level <= DINFO_LEVEL_TERSE)
20914 /* In the special case of a TYPE_DECL node representing the declaration
20915 of some type tag, if the given TYPE_DECL is marked as having been
20916 instantiated from some other (original) TYPE_DECL node (e.g. one which
20917 was generated within the original definition of an inline function) we
20918 used to generate a special (abbreviated) DW_TAG_structure_type,
20919 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20920 should be actually referencing those DIEs, as variable DIEs with that
20921 type would be emitted already in the abstract origin, so it was always
20922 removed during unused type prunning. Don't add anything in this
20924 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
20927 if (is_redundant_typedef (decl))
20928 gen_type_die (TREE_TYPE (decl), context_die);
20930 /* Output a DIE to represent the typedef itself. */
20931 gen_typedef_die (decl, context_die);
20935 if (debug_info_level >= DINFO_LEVEL_NORMAL)
20936 gen_label_die (decl, context_die);
20941 /* If we are in terse mode, don't generate any DIEs to represent any
20942 variable declarations or definitions. */
20943 if (debug_info_level <= DINFO_LEVEL_TERSE)
20946 /* Output any DIEs that are needed to specify the type of this data
20948 if (decl_by_reference_p (decl_or_origin))
20949 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20951 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20953 /* And its containing type. */
20954 class_origin = decl_class_context (decl_or_origin);
20955 if (class_origin != NULL_TREE)
20956 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
20958 /* And its containing namespace. */
20959 context_die = declare_in_namespace (decl_or_origin, context_die);
20961 /* Now output the DIE to represent the data object itself. This gets
20962 complicated because of the possibility that the VAR_DECL really
20963 represents an inlined instance of a formal parameter for an inline
20965 ultimate_origin = decl_ultimate_origin (decl_or_origin);
20966 if (ultimate_origin != NULL_TREE
20967 && TREE_CODE (ultimate_origin) == PARM_DECL)
20968 gen_formal_parameter_die (decl, origin,
20969 true /* Emit name attribute. */,
20972 gen_variable_die (decl, origin, context_die);
20976 /* Ignore the nameless fields that are used to skip bits but handle C++
20977 anonymous unions and structs. */
20978 if (DECL_NAME (decl) != NULL_TREE
20979 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
20980 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
20982 gen_type_die (member_declared_type (decl), context_die);
20983 gen_field_die (decl, context_die);
20988 if (DECL_BY_REFERENCE (decl_or_origin))
20989 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
20991 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
20992 return gen_formal_parameter_die (decl, origin,
20993 true /* Emit name attribute. */,
20996 case NAMESPACE_DECL:
20997 case IMPORTED_DECL:
20998 if (dwarf_version >= 3 || !dwarf_strict)
20999 gen_namespace_die (decl, context_die);
21003 /* Probably some frontend-internal decl. Assume we don't care. */
21004 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21011 /* Output debug information for global decl DECL. Called from toplev.c after
21012 compilation proper has finished. */
21015 dwarf2out_global_decl (tree decl)
21017 /* Output DWARF2 information for file-scope tentative data object
21018 declarations, file-scope (extern) function declarations (which
21019 had no corresponding body) and file-scope tagged type declarations
21020 and definitions which have not yet been forced out. */
21021 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21022 dwarf2out_decl (decl);
21025 /* Output debug information for type decl DECL. Called from toplev.c
21026 and from language front ends (to record built-in types). */
21028 dwarf2out_type_decl (tree decl, int local)
21031 dwarf2out_decl (decl);
21034 /* Output debug information for imported module or decl DECL.
21035 NAME is non-NULL name in the lexical block if the decl has been renamed.
21036 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21037 that DECL belongs to.
21038 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21040 dwarf2out_imported_module_or_decl_1 (tree decl,
21042 tree lexical_block,
21043 dw_die_ref lexical_block_die)
21045 expanded_location xloc;
21046 dw_die_ref imported_die = NULL;
21047 dw_die_ref at_import_die;
21049 if (TREE_CODE (decl) == IMPORTED_DECL)
21051 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21052 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21056 xloc = expand_location (input_location);
21058 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21060 at_import_die = force_type_die (TREE_TYPE (decl));
21061 /* For namespace N { typedef void T; } using N::T; base_type_die
21062 returns NULL, but DW_TAG_imported_declaration requires
21063 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21064 if (!at_import_die)
21066 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21067 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21068 at_import_die = lookup_type_die (TREE_TYPE (decl));
21069 gcc_assert (at_import_die);
21074 at_import_die = lookup_decl_die (decl);
21075 if (!at_import_die)
21077 /* If we're trying to avoid duplicate debug info, we may not have
21078 emitted the member decl for this field. Emit it now. */
21079 if (TREE_CODE (decl) == FIELD_DECL)
21081 tree type = DECL_CONTEXT (decl);
21083 if (TYPE_CONTEXT (type)
21084 && TYPE_P (TYPE_CONTEXT (type))
21085 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21086 DINFO_USAGE_DIR_USE))
21088 gen_type_die_for_member (type, decl,
21089 get_context_die (TYPE_CONTEXT (type)));
21091 at_import_die = force_decl_die (decl);
21095 if (TREE_CODE (decl) == NAMESPACE_DECL)
21097 if (dwarf_version >= 3 || !dwarf_strict)
21098 imported_die = new_die (DW_TAG_imported_module,
21105 imported_die = new_die (DW_TAG_imported_declaration,
21109 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21110 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21112 add_AT_string (imported_die, DW_AT_name,
21113 IDENTIFIER_POINTER (name));
21114 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21117 /* Output debug information for imported module or decl DECL.
21118 NAME is non-NULL name in context if the decl has been renamed.
21119 CHILD is true if decl is one of the renamed decls as part of
21120 importing whole module. */
21123 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21126 /* dw_die_ref at_import_die; */
21127 dw_die_ref scope_die;
21129 if (debug_info_level <= DINFO_LEVEL_TERSE)
21134 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21135 We need decl DIE for reference and scope die. First, get DIE for the decl
21138 /* Get the scope die for decl context. Use comp_unit_die for global module
21139 or decl. If die is not found for non globals, force new die. */
21141 && TYPE_P (context)
21142 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21145 if (!(dwarf_version >= 3 || !dwarf_strict))
21148 scope_die = get_context_die (context);
21152 gcc_assert (scope_die->die_child);
21153 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21154 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21155 scope_die = scope_die->die_child;
21158 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21159 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21163 /* Write the debugging output for DECL. */
21166 dwarf2out_decl (tree decl)
21168 dw_die_ref context_die = comp_unit_die ();
21170 switch (TREE_CODE (decl))
21175 case FUNCTION_DECL:
21176 /* What we would really like to do here is to filter out all mere
21177 file-scope declarations of file-scope functions which are never
21178 referenced later within this translation unit (and keep all of ones
21179 that *are* referenced later on) but we aren't clairvoyant, so we have
21180 no idea which functions will be referenced in the future (i.e. later
21181 on within the current translation unit). So here we just ignore all
21182 file-scope function declarations which are not also definitions. If
21183 and when the debugger needs to know something about these functions,
21184 it will have to hunt around and find the DWARF information associated
21185 with the definition of the function.
21187 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21188 nodes represent definitions and which ones represent mere
21189 declarations. We have to check DECL_INITIAL instead. That's because
21190 the C front-end supports some weird semantics for "extern inline"
21191 function definitions. These can get inlined within the current
21192 translation unit (and thus, we need to generate Dwarf info for their
21193 abstract instances so that the Dwarf info for the concrete inlined
21194 instances can have something to refer to) but the compiler never
21195 generates any out-of-lines instances of such things (despite the fact
21196 that they *are* definitions).
21198 The important point is that the C front-end marks these "extern
21199 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21200 them anyway. Note that the C++ front-end also plays some similar games
21201 for inline function definitions appearing within include files which
21202 also contain `#pragma interface' pragmas. */
21203 if (DECL_INITIAL (decl) == NULL_TREE)
21206 /* If we're a nested function, initially use a parent of NULL; if we're
21207 a plain function, this will be fixed up in decls_for_scope. If
21208 we're a method, it will be ignored, since we already have a DIE. */
21209 if (decl_function_context (decl)
21210 /* But if we're in terse mode, we don't care about scope. */
21211 && debug_info_level > DINFO_LEVEL_TERSE)
21212 context_die = NULL;
21216 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21217 declaration and if the declaration was never even referenced from
21218 within this entire compilation unit. We suppress these DIEs in
21219 order to save space in the .debug section (by eliminating entries
21220 which are probably useless). Note that we must not suppress
21221 block-local extern declarations (whether used or not) because that
21222 would screw-up the debugger's name lookup mechanism and cause it to
21223 miss things which really ought to be in scope at a given point. */
21224 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21227 /* For local statics lookup proper context die. */
21228 if (TREE_STATIC (decl) && decl_function_context (decl))
21229 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21231 /* If we are in terse mode, don't generate any DIEs to represent any
21232 variable declarations or definitions. */
21233 if (debug_info_level <= DINFO_LEVEL_TERSE)
21238 if (debug_info_level <= DINFO_LEVEL_TERSE)
21240 if (!is_fortran () && !is_ada ())
21242 if (TREE_STATIC (decl) && decl_function_context (decl))
21243 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21246 case NAMESPACE_DECL:
21247 case IMPORTED_DECL:
21248 if (debug_info_level <= DINFO_LEVEL_TERSE)
21250 if (lookup_decl_die (decl) != NULL)
21255 /* Don't emit stubs for types unless they are needed by other DIEs. */
21256 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21259 /* Don't bother trying to generate any DIEs to represent any of the
21260 normal built-in types for the language we are compiling. */
21261 if (DECL_IS_BUILTIN (decl))
21264 /* If we are in terse mode, don't generate any DIEs for types. */
21265 if (debug_info_level <= DINFO_LEVEL_TERSE)
21268 /* If we're a function-scope tag, initially use a parent of NULL;
21269 this will be fixed up in decls_for_scope. */
21270 if (decl_function_context (decl))
21271 context_die = NULL;
21279 gen_decl_die (decl, NULL, context_die);
21282 /* Write the debugging output for DECL. */
21285 dwarf2out_function_decl (tree decl)
21287 dwarf2out_decl (decl);
21289 htab_empty (decl_loc_table);
21292 /* Output a marker (i.e. a label) for the beginning of the generated code for
21293 a lexical block. */
21296 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21297 unsigned int blocknum)
21299 switch_to_section (current_function_section ());
21300 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21303 /* Output a marker (i.e. a label) for the end of the generated code for a
21307 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21309 switch_to_section (current_function_section ());
21310 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21313 /* Returns nonzero if it is appropriate not to emit any debugging
21314 information for BLOCK, because it doesn't contain any instructions.
21316 Don't allow this for blocks with nested functions or local classes
21317 as we would end up with orphans, and in the presence of scheduling
21318 we may end up calling them anyway. */
21321 dwarf2out_ignore_block (const_tree block)
21326 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21327 if (TREE_CODE (decl) == FUNCTION_DECL
21328 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21330 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21332 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21333 if (TREE_CODE (decl) == FUNCTION_DECL
21334 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21341 /* Hash table routines for file_hash. */
21344 file_table_eq (const void *p1_p, const void *p2_p)
21346 const struct dwarf_file_data *const p1 =
21347 (const struct dwarf_file_data *) p1_p;
21348 const char *const p2 = (const char *) p2_p;
21349 return strcmp (p1->filename, p2) == 0;
21353 file_table_hash (const void *p_p)
21355 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21356 return htab_hash_string (p->filename);
21359 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21360 dwarf2out.c) and return its "index". The index of each (known) filename is
21361 just a unique number which is associated with only that one filename. We
21362 need such numbers for the sake of generating labels (in the .debug_sfnames
21363 section) and references to those files numbers (in the .debug_srcinfo
21364 and.debug_macinfo sections). If the filename given as an argument is not
21365 found in our current list, add it to the list and assign it the next
21366 available unique index number. In order to speed up searches, we remember
21367 the index of the filename was looked up last. This handles the majority of
21370 static struct dwarf_file_data *
21371 lookup_filename (const char *file_name)
21374 struct dwarf_file_data * created;
21376 /* Check to see if the file name that was searched on the previous
21377 call matches this file name. If so, return the index. */
21378 if (file_table_last_lookup
21379 && (file_name == file_table_last_lookup->filename
21380 || strcmp (file_table_last_lookup->filename, file_name) == 0))
21381 return file_table_last_lookup;
21383 /* Didn't match the previous lookup, search the table. */
21384 slot = htab_find_slot_with_hash (file_table, file_name,
21385 htab_hash_string (file_name), INSERT);
21387 return (struct dwarf_file_data *) *slot;
21389 created = ggc_alloc_dwarf_file_data ();
21390 created->filename = file_name;
21391 created->emitted_number = 0;
21396 /* If the assembler will construct the file table, then translate the compiler
21397 internal file table number into the assembler file table number, and emit
21398 a .file directive if we haven't already emitted one yet. The file table
21399 numbers are different because we prune debug info for unused variables and
21400 types, which may include filenames. */
21403 maybe_emit_file (struct dwarf_file_data * fd)
21405 if (! fd->emitted_number)
21407 if (last_emitted_file)
21408 fd->emitted_number = last_emitted_file->emitted_number + 1;
21410 fd->emitted_number = 1;
21411 last_emitted_file = fd;
21413 if (DWARF2_ASM_LINE_DEBUG_INFO)
21415 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21416 output_quoted_string (asm_out_file,
21417 remap_debug_filename (fd->filename));
21418 fputc ('\n', asm_out_file);
21422 return fd->emitted_number;
21425 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21426 That generation should happen after function debug info has been
21427 generated. The value of the attribute is the constant value of ARG. */
21430 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21432 die_arg_entry entry;
21437 if (!tmpl_value_parm_die_table)
21438 tmpl_value_parm_die_table
21439 = VEC_alloc (die_arg_entry, gc, 32);
21443 VEC_safe_push (die_arg_entry, gc,
21444 tmpl_value_parm_die_table,
21448 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21449 by append_entry_to_tmpl_value_parm_die_table. This function must
21450 be called after function DIEs have been generated. */
21453 gen_remaining_tmpl_value_param_die_attribute (void)
21455 if (tmpl_value_parm_die_table)
21460 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21461 tree_add_const_value_attribute (e->die, e->arg);
21466 /* Replace DW_AT_name for the decl with name. */
21469 dwarf2out_set_name (tree decl, tree name)
21475 die = TYPE_SYMTAB_DIE (decl);
21479 dname = dwarf2_name (name, 0);
21483 attr = get_AT (die, DW_AT_name);
21486 struct indirect_string_node *node;
21488 node = find_AT_string (dname);
21489 /* replace the string. */
21490 attr->dw_attr_val.v.val_str = node;
21494 add_name_attribute (die, dname);
21497 /* Called by the final INSN scan whenever we see a direct function call.
21498 Make an entry into the direct call table, recording the point of call
21499 and a reference to the target function's debug entry. */
21502 dwarf2out_direct_call (tree targ)
21505 tree origin = decl_ultimate_origin (targ);
21507 /* If this is a clone, use the abstract origin as the target. */
21511 e.poc_label_num = poc_label_num++;
21512 e.poc_decl = current_function_decl;
21513 e.targ_die = force_decl_die (targ);
21514 VEC_safe_push (dcall_entry, gc, dcall_table, &e);
21516 /* Drop a label at the return point to mark the point of call. */
21517 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21520 /* Returns a hash value for X (which really is a struct vcall_insn). */
21523 vcall_insn_table_hash (const void *x)
21525 return (hashval_t) ((const struct vcall_insn *) x)->insn_uid;
21528 /* Return nonzero if insn_uid of struct vcall_insn *X is the same as
21529 insnd_uid of *Y. */
21532 vcall_insn_table_eq (const void *x, const void *y)
21534 return (((const struct vcall_insn *) x)->insn_uid
21535 == ((const struct vcall_insn *) y)->insn_uid);
21538 /* Associate VTABLE_SLOT with INSN_UID in the VCALL_INSN_TABLE. */
21541 store_vcall_insn (unsigned int vtable_slot, int insn_uid)
21543 struct vcall_insn *item = ggc_alloc_vcall_insn ();
21544 struct vcall_insn **slot;
21547 item->insn_uid = insn_uid;
21548 item->vtable_slot = vtable_slot;
21549 slot = (struct vcall_insn **)
21550 htab_find_slot_with_hash (vcall_insn_table, &item,
21551 (hashval_t) insn_uid, INSERT);
21555 /* Return the VTABLE_SLOT associated with INSN_UID. */
21557 static unsigned int
21558 lookup_vcall_insn (unsigned int insn_uid)
21560 struct vcall_insn item;
21561 struct vcall_insn *p;
21563 item.insn_uid = insn_uid;
21564 item.vtable_slot = 0;
21565 p = (struct vcall_insn *) htab_find_with_hash (vcall_insn_table,
21567 (hashval_t) insn_uid);
21569 return (unsigned int) -1;
21570 return p->vtable_slot;
21574 /* Called when lowering indirect calls to RTL. We make a note of INSN_UID
21575 and the OBJ_TYPE_REF_TOKEN from ADDR. For C++ virtual calls, the token
21576 is the vtable slot index that we will need to put in the virtual call
21580 dwarf2out_virtual_call_token (tree addr, int insn_uid)
21582 if (is_cxx() && TREE_CODE (addr) == OBJ_TYPE_REF)
21584 tree token = OBJ_TYPE_REF_TOKEN (addr);
21585 if (TREE_CODE (token) == INTEGER_CST)
21586 store_vcall_insn (TREE_INT_CST_LOW (token), insn_uid);
21590 /* Called when scheduling RTL, when a CALL_INSN is split. Copies the
21591 OBJ_TYPE_REF_TOKEN previously associated with OLD_INSN and associates it
21595 dwarf2out_copy_call_info (rtx old_insn, rtx new_insn)
21597 unsigned int vtable_slot = lookup_vcall_insn (INSN_UID (old_insn));
21599 if (vtable_slot != (unsigned int) -1)
21600 store_vcall_insn (vtable_slot, INSN_UID (new_insn));
21603 /* Called by the final INSN scan whenever we see a virtual function call.
21604 Make an entry into the virtual call table, recording the point of call
21605 and the slot index of the vtable entry used to call the virtual member
21606 function. The slot index was associated with the INSN_UID during the
21607 lowering to RTL. */
21610 dwarf2out_virtual_call (int insn_uid)
21612 unsigned int vtable_slot = lookup_vcall_insn (insn_uid);
21615 if (vtable_slot == (unsigned int) -1)
21618 e.poc_label_num = poc_label_num++;
21619 e.vtable_slot = vtable_slot;
21620 VEC_safe_push (vcall_entry, gc, vcall_table, &e);
21622 /* Drop a label at the return point to mark the point of call. */
21623 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LPOC", e.poc_label_num);
21626 /* Called by the final INSN scan whenever we see a var location. We
21627 use it to drop labels in the right places, and throw the location in
21628 our lookup table. */
21631 dwarf2out_var_location (rtx loc_note)
21633 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21634 struct var_loc_node *newloc;
21636 static const char *last_label;
21637 static const char *last_postcall_label;
21638 static bool last_in_cold_section_p;
21641 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21644 next_real = next_real_insn (loc_note);
21645 /* If there are no instructions which would be affected by this note,
21646 don't do anything. */
21647 if (next_real == NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
21650 /* If there were any real insns between note we processed last time
21651 and this note (or if it is the first note), clear
21652 last_{,postcall_}label so that they are not reused this time. */
21653 if (last_var_location_insn == NULL_RTX
21654 || last_var_location_insn != next_real
21655 || last_in_cold_section_p != in_cold_section_p)
21658 last_postcall_label = NULL;
21661 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21662 newloc = add_var_loc_to_decl (decl, loc_note,
21663 NOTE_DURING_CALL_P (loc_note)
21664 ? last_postcall_label : last_label);
21665 if (newloc == NULL)
21668 /* If there were no real insns between note we processed last time
21669 and this note, use the label we emitted last time. Otherwise
21670 create a new label and emit it. */
21671 if (last_label == NULL)
21673 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21674 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21676 last_label = ggc_strdup (loclabel);
21679 if (!NOTE_DURING_CALL_P (loc_note))
21680 newloc->label = last_label;
21683 if (!last_postcall_label)
21685 sprintf (loclabel, "%s-1", last_label);
21686 last_postcall_label = ggc_strdup (loclabel);
21688 newloc->label = last_postcall_label;
21691 last_var_location_insn = next_real;
21692 last_in_cold_section_p = in_cold_section_p;
21695 /* We need to reset the locations at the beginning of each
21696 function. We can't do this in the end_function hook, because the
21697 declarations that use the locations won't have been output when
21698 that hook is called. Also compute have_multiple_function_sections here. */
21701 dwarf2out_begin_function (tree fun)
21703 if (function_section (fun) != text_section)
21704 have_multiple_function_sections = true;
21705 else if (flag_reorder_blocks_and_partition && !cold_text_section)
21707 gcc_assert (current_function_decl == fun);
21708 cold_text_section = unlikely_text_section ();
21709 switch_to_section (cold_text_section);
21710 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
21711 switch_to_section (current_function_section ());
21714 dwarf2out_note_section_used ();
21717 /* Output a label to mark the beginning of a source code line entry
21718 and record information relating to this source line, in
21719 'line_info_table' for later output of the .debug_line section. */
21722 dwarf2out_source_line (unsigned int line, const char *filename,
21723 int discriminator, bool is_stmt)
21725 static bool last_is_stmt = true;
21727 if (debug_info_level >= DINFO_LEVEL_NORMAL
21730 int file_num = maybe_emit_file (lookup_filename (filename));
21732 switch_to_section (current_function_section ());
21734 /* If requested, emit something human-readable. */
21735 if (flag_debug_asm)
21736 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
21739 if (DWARF2_ASM_LINE_DEBUG_INFO)
21741 /* Emit the .loc directive understood by GNU as. */
21742 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
21743 if (is_stmt != last_is_stmt)
21745 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
21746 last_is_stmt = is_stmt;
21748 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
21749 fprintf (asm_out_file, " discriminator %d", discriminator);
21750 fputc ('\n', asm_out_file);
21752 /* Indicate that line number info exists. */
21753 line_info_table_in_use++;
21755 else if (function_section (current_function_decl) != text_section)
21757 dw_separate_line_info_ref line_info;
21758 targetm.asm_out.internal_label (asm_out_file,
21759 SEPARATE_LINE_CODE_LABEL,
21760 separate_line_info_table_in_use);
21762 /* Expand the line info table if necessary. */
21763 if (separate_line_info_table_in_use
21764 == separate_line_info_table_allocated)
21766 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21767 separate_line_info_table
21768 = GGC_RESIZEVEC (dw_separate_line_info_entry,
21769 separate_line_info_table,
21770 separate_line_info_table_allocated);
21771 memset (separate_line_info_table
21772 + separate_line_info_table_in_use,
21774 (LINE_INFO_TABLE_INCREMENT
21775 * sizeof (dw_separate_line_info_entry)));
21778 /* Add the new entry at the end of the line_info_table. */
21780 = &separate_line_info_table[separate_line_info_table_in_use++];
21781 line_info->dw_file_num = file_num;
21782 line_info->dw_line_num = line;
21783 line_info->function = current_function_funcdef_no;
21787 dw_line_info_ref line_info;
21789 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
21790 line_info_table_in_use);
21792 /* Expand the line info table if necessary. */
21793 if (line_info_table_in_use == line_info_table_allocated)
21795 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
21797 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
21798 line_info_table_allocated);
21799 memset (line_info_table + line_info_table_in_use, 0,
21800 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
21803 /* Add the new entry at the end of the line_info_table. */
21804 line_info = &line_info_table[line_info_table_in_use++];
21805 line_info->dw_file_num = file_num;
21806 line_info->dw_line_num = line;
21811 /* Record the beginning of a new source file. */
21814 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
21816 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21818 /* Record the beginning of the file for break_out_includes. */
21819 dw_die_ref bincl_die;
21821 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
21822 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
21825 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21828 e.code = DW_MACINFO_start_file;
21830 e.info = xstrdup (filename);
21831 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21835 /* Record the end of a source file. */
21838 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
21840 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
21841 /* Record the end of the file for break_out_includes. */
21842 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
21844 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21847 e.code = DW_MACINFO_end_file;
21850 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21854 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21855 the tail part of the directive line, i.e. the part which is past the
21856 initial whitespace, #, whitespace, directive-name, whitespace part. */
21859 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
21860 const char *buffer ATTRIBUTE_UNUSED)
21862 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21865 e.code = DW_MACINFO_define;
21867 e.info = xstrdup (buffer);;
21868 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21872 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21873 the tail part of the directive line, i.e. the part which is past the
21874 initial whitespace, #, whitespace, directive-name, whitespace part. */
21877 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
21878 const char *buffer ATTRIBUTE_UNUSED)
21880 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
21883 e.code = DW_MACINFO_undef;
21885 e.info = xstrdup (buffer);;
21886 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
21891 output_macinfo (void)
21894 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
21895 macinfo_entry *ref;
21900 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
21904 case DW_MACINFO_start_file:
21906 int file_num = maybe_emit_file (lookup_filename (ref->info));
21907 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
21908 dw2_asm_output_data_uleb128
21909 (ref->lineno, "Included from line number %lu",
21910 (unsigned long)ref->lineno);
21911 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
21914 case DW_MACINFO_end_file:
21915 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
21917 case DW_MACINFO_define:
21918 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
21919 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
21920 (unsigned long)ref->lineno);
21921 dw2_asm_output_nstring (ref->info, -1, "The macro");
21923 case DW_MACINFO_undef:
21924 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
21925 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
21926 (unsigned long)ref->lineno);
21927 dw2_asm_output_nstring (ref->info, -1, "The macro");
21930 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
21931 ASM_COMMENT_START, (unsigned long)ref->code);
21937 /* Set up for Dwarf output at the start of compilation. */
21940 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
21942 /* Allocate the file_table. */
21943 file_table = htab_create_ggc (50, file_table_hash,
21944 file_table_eq, NULL);
21946 /* Allocate the decl_die_table. */
21947 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
21948 decl_die_table_eq, NULL);
21950 /* Allocate the decl_loc_table. */
21951 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
21952 decl_loc_table_eq, NULL);
21954 /* Allocate the initial hunk of the decl_scope_table. */
21955 decl_scope_table = VEC_alloc (tree, gc, 256);
21957 /* Allocate the initial hunk of the abbrev_die_table. */
21958 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
21959 (ABBREV_DIE_TABLE_INCREMENT);
21960 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
21961 /* Zero-th entry is allocated, but unused. */
21962 abbrev_die_table_in_use = 1;
21964 /* Allocate the initial hunk of the line_info_table. */
21965 line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
21966 (LINE_INFO_TABLE_INCREMENT);
21967 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
21969 /* Zero-th entry is allocated, but unused. */
21970 line_info_table_in_use = 1;
21972 /* Allocate the pubtypes and pubnames vectors. */
21973 pubname_table = VEC_alloc (pubname_entry, gc, 32);
21974 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
21976 /* Allocate the table that maps insn UIDs to vtable slot indexes. */
21977 vcall_insn_table = htab_create_ggc (10, vcall_insn_table_hash,
21978 vcall_insn_table_eq, NULL);
21980 incomplete_types = VEC_alloc (tree, gc, 64);
21982 used_rtx_array = VEC_alloc (rtx, gc, 32);
21984 debug_info_section = get_section (DEBUG_INFO_SECTION,
21985 SECTION_DEBUG, NULL);
21986 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
21987 SECTION_DEBUG, NULL);
21988 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
21989 SECTION_DEBUG, NULL);
21990 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
21991 SECTION_DEBUG, NULL);
21992 debug_line_section = get_section (DEBUG_LINE_SECTION,
21993 SECTION_DEBUG, NULL);
21994 debug_loc_section = get_section (DEBUG_LOC_SECTION,
21995 SECTION_DEBUG, NULL);
21996 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
21997 SECTION_DEBUG, NULL);
21998 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
21999 SECTION_DEBUG, NULL);
22000 debug_dcall_section = get_section (DEBUG_DCALL_SECTION,
22001 SECTION_DEBUG, NULL);
22002 debug_vcall_section = get_section (DEBUG_VCALL_SECTION,
22003 SECTION_DEBUG, NULL);
22004 debug_str_section = get_section (DEBUG_STR_SECTION,
22005 DEBUG_STR_SECTION_FLAGS, NULL);
22006 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22007 SECTION_DEBUG, NULL);
22008 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22009 SECTION_DEBUG, NULL);
22011 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22012 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22013 DEBUG_ABBREV_SECTION_LABEL, 0);
22014 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22015 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22016 COLD_TEXT_SECTION_LABEL, 0);
22017 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22019 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22020 DEBUG_INFO_SECTION_LABEL, 0);
22021 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22022 DEBUG_LINE_SECTION_LABEL, 0);
22023 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22024 DEBUG_RANGES_SECTION_LABEL, 0);
22025 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22026 DEBUG_MACINFO_SECTION_LABEL, 0);
22028 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22029 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22031 switch_to_section (text_section);
22032 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22035 /* Called before cgraph_optimize starts outputtting functions, variables
22036 and toplevel asms into assembly. */
22039 dwarf2out_assembly_start (void)
22041 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22042 && dwarf2out_do_cfi_asm ()
22043 && (!(flag_unwind_tables || flag_exceptions)
22044 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22045 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22048 /* A helper function for dwarf2out_finish called through
22049 htab_traverse. Emit one queued .debug_str string. */
22052 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22054 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22056 if (node->label && node->refcount)
22058 switch_to_section (debug_str_section);
22059 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22060 assemble_string (node->str, strlen (node->str) + 1);
22066 #if ENABLE_ASSERT_CHECKING
22067 /* Verify that all marks are clear. */
22070 verify_marks_clear (dw_die_ref die)
22074 gcc_assert (! die->die_mark);
22075 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22077 #endif /* ENABLE_ASSERT_CHECKING */
22079 /* Clear the marks for a die and its children.
22080 Be cool if the mark isn't set. */
22083 prune_unmark_dies (dw_die_ref die)
22089 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22092 /* Given DIE that we're marking as used, find any other dies
22093 it references as attributes and mark them as used. */
22096 prune_unused_types_walk_attribs (dw_die_ref die)
22101 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22103 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22105 /* A reference to another DIE.
22106 Make sure that it will get emitted.
22107 If it was broken out into a comdat group, don't follow it. */
22108 if (dwarf_version < 4
22109 || a->dw_attr == DW_AT_specification
22110 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22111 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22113 /* Set the string's refcount to 0 so that prune_unused_types_mark
22114 accounts properly for it. */
22115 if (AT_class (a) == dw_val_class_str)
22116 a->dw_attr_val.v.val_str->refcount = 0;
22121 /* Mark DIE as being used. If DOKIDS is true, then walk down
22122 to DIE's children. */
22125 prune_unused_types_mark (dw_die_ref die, int dokids)
22129 if (die->die_mark == 0)
22131 /* We haven't done this node yet. Mark it as used. */
22134 /* We also have to mark its parents as used.
22135 (But we don't want to mark our parents' kids due to this.) */
22136 if (die->die_parent)
22137 prune_unused_types_mark (die->die_parent, 0);
22139 /* Mark any referenced nodes. */
22140 prune_unused_types_walk_attribs (die);
22142 /* If this node is a specification,
22143 also mark the definition, if it exists. */
22144 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22145 prune_unused_types_mark (die->die_definition, 1);
22148 if (dokids && die->die_mark != 2)
22150 /* We need to walk the children, but haven't done so yet.
22151 Remember that we've walked the kids. */
22154 /* If this is an array type, we need to make sure our
22155 kids get marked, even if they're types. If we're
22156 breaking out types into comdat sections, do this
22157 for all type definitions. */
22158 if (die->die_tag == DW_TAG_array_type
22159 || (dwarf_version >= 4
22160 && is_type_die (die) && ! is_declaration_die (die)))
22161 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22163 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22167 /* For local classes, look if any static member functions were emitted
22168 and if so, mark them. */
22171 prune_unused_types_walk_local_classes (dw_die_ref die)
22175 if (die->die_mark == 2)
22178 switch (die->die_tag)
22180 case DW_TAG_structure_type:
22181 case DW_TAG_union_type:
22182 case DW_TAG_class_type:
22185 case DW_TAG_subprogram:
22186 if (!get_AT_flag (die, DW_AT_declaration)
22187 || die->die_definition != NULL)
22188 prune_unused_types_mark (die, 1);
22195 /* Mark children. */
22196 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22199 /* Walk the tree DIE and mark types that we actually use. */
22202 prune_unused_types_walk (dw_die_ref die)
22206 /* Don't do anything if this node is already marked and
22207 children have been marked as well. */
22208 if (die->die_mark == 2)
22211 switch (die->die_tag)
22213 case DW_TAG_structure_type:
22214 case DW_TAG_union_type:
22215 case DW_TAG_class_type:
22216 if (die->die_perennial_p)
22219 for (c = die->die_parent; c; c = c->die_parent)
22220 if (c->die_tag == DW_TAG_subprogram)
22223 /* Finding used static member functions inside of classes
22224 is needed just for local classes, because for other classes
22225 static member function DIEs with DW_AT_specification
22226 are emitted outside of the DW_TAG_*_type. If we ever change
22227 it, we'd need to call this even for non-local classes. */
22229 prune_unused_types_walk_local_classes (die);
22231 /* It's a type node --- don't mark it. */
22234 case DW_TAG_const_type:
22235 case DW_TAG_packed_type:
22236 case DW_TAG_pointer_type:
22237 case DW_TAG_reference_type:
22238 case DW_TAG_rvalue_reference_type:
22239 case DW_TAG_volatile_type:
22240 case DW_TAG_typedef:
22241 case DW_TAG_array_type:
22242 case DW_TAG_interface_type:
22243 case DW_TAG_friend:
22244 case DW_TAG_variant_part:
22245 case DW_TAG_enumeration_type:
22246 case DW_TAG_subroutine_type:
22247 case DW_TAG_string_type:
22248 case DW_TAG_set_type:
22249 case DW_TAG_subrange_type:
22250 case DW_TAG_ptr_to_member_type:
22251 case DW_TAG_file_type:
22252 if (die->die_perennial_p)
22255 /* It's a type node --- don't mark it. */
22259 /* Mark everything else. */
22263 if (die->die_mark == 0)
22267 /* Now, mark any dies referenced from here. */
22268 prune_unused_types_walk_attribs (die);
22273 /* Mark children. */
22274 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22277 /* Increment the string counts on strings referred to from DIE's
22281 prune_unused_types_update_strings (dw_die_ref die)
22286 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22287 if (AT_class (a) == dw_val_class_str)
22289 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22291 /* Avoid unnecessarily putting strings that are used less than
22292 twice in the hash table. */
22294 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22297 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22298 htab_hash_string (s->str),
22300 gcc_assert (*slot == NULL);
22306 /* Remove from the tree DIE any dies that aren't marked. */
22309 prune_unused_types_prune (dw_die_ref die)
22313 gcc_assert (die->die_mark);
22314 prune_unused_types_update_strings (die);
22316 if (! die->die_child)
22319 c = die->die_child;
22321 dw_die_ref prev = c;
22322 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22323 if (c == die->die_child)
22325 /* No marked children between 'prev' and the end of the list. */
22327 /* No marked children at all. */
22328 die->die_child = NULL;
22331 prev->die_sib = c->die_sib;
22332 die->die_child = prev;
22337 if (c != prev->die_sib)
22339 prune_unused_types_prune (c);
22340 } while (c != die->die_child);
22343 /* A helper function for dwarf2out_finish called through
22344 htab_traverse. Clear .debug_str strings that we haven't already
22345 decided to emit. */
22348 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22350 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22352 if (!node->label || !node->refcount)
22353 htab_clear_slot (debug_str_hash, h);
22358 /* Remove dies representing declarations that we never use. */
22361 prune_unused_types (void)
22364 limbo_die_node *node;
22365 comdat_type_node *ctnode;
22367 dcall_entry *dcall;
22369 #if ENABLE_ASSERT_CHECKING
22370 /* All the marks should already be clear. */
22371 verify_marks_clear (comp_unit_die ());
22372 for (node = limbo_die_list; node; node = node->next)
22373 verify_marks_clear (node->die);
22374 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22375 verify_marks_clear (ctnode->root_die);
22376 #endif /* ENABLE_ASSERT_CHECKING */
22378 /* Mark types that are used in global variables. */
22379 premark_types_used_by_global_vars ();
22381 /* Set the mark on nodes that are actually used. */
22382 prune_unused_types_walk (comp_unit_die ());
22383 for (node = limbo_die_list; node; node = node->next)
22384 prune_unused_types_walk (node->die);
22385 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22387 prune_unused_types_walk (ctnode->root_die);
22388 prune_unused_types_mark (ctnode->type_die, 1);
22391 /* Also set the mark on nodes referenced from the
22392 pubname_table or arange_table. */
22393 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22394 prune_unused_types_mark (pub->die, 1);
22395 for (i = 0; i < arange_table_in_use; i++)
22396 prune_unused_types_mark (arange_table[i], 1);
22398 /* Mark nodes referenced from the direct call table. */
22399 FOR_EACH_VEC_ELT (dcall_entry, dcall_table, i, dcall)
22400 prune_unused_types_mark (dcall->targ_die, 1);
22402 /* Get rid of nodes that aren't marked; and update the string counts. */
22403 if (debug_str_hash && debug_str_hash_forced)
22404 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22405 else if (debug_str_hash)
22406 htab_empty (debug_str_hash);
22407 prune_unused_types_prune (comp_unit_die ());
22408 for (node = limbo_die_list; node; node = node->next)
22409 prune_unused_types_prune (node->die);
22410 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22411 prune_unused_types_prune (ctnode->root_die);
22413 /* Leave the marks clear. */
22414 prune_unmark_dies (comp_unit_die ());
22415 for (node = limbo_die_list; node; node = node->next)
22416 prune_unmark_dies (node->die);
22417 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22418 prune_unmark_dies (ctnode->root_die);
22421 /* Set the parameter to true if there are any relative pathnames in
22424 file_table_relative_p (void ** slot, void *param)
22426 bool *p = (bool *) param;
22427 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22428 if (!IS_ABSOLUTE_PATH (d->filename))
22436 /* Routines to manipulate hash table of comdat type units. */
22439 htab_ct_hash (const void *of)
22442 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22444 memcpy (&h, type_node->signature, sizeof (h));
22449 htab_ct_eq (const void *of1, const void *of2)
22451 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22452 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22454 return (! memcmp (type_node_1->signature, type_node_2->signature,
22455 DWARF_TYPE_SIGNATURE_SIZE));
22458 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22459 to the location it would have been added, should we know its
22460 DECL_ASSEMBLER_NAME when we added other attributes. This will
22461 probably improve compactness of debug info, removing equivalent
22462 abbrevs, and hide any differences caused by deferring the
22463 computation of the assembler name, triggered by e.g. PCH. */
22466 move_linkage_attr (dw_die_ref die)
22468 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22469 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22471 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22472 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22476 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22478 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22482 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22484 VEC_pop (dw_attr_node, die->die_attr);
22485 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22489 /* Helper function for resolve_addr, attempt to resolve
22490 one CONST_STRING, return non-zero if not successful. Similarly verify that
22491 SYMBOL_REFs refer to variables emitted in the current CU. */
22494 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22498 if (GET_CODE (rtl) == CONST_STRING)
22500 size_t len = strlen (XSTR (rtl, 0)) + 1;
22501 tree t = build_string (len, XSTR (rtl, 0));
22502 tree tlen = build_int_cst (NULL_TREE, len - 1);
22504 = build_array_type (char_type_node, build_index_type (tlen));
22505 rtl = lookup_constant_def (t);
22506 if (!rtl || !MEM_P (rtl))
22508 rtl = XEXP (rtl, 0);
22509 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22514 if (GET_CODE (rtl) == SYMBOL_REF
22515 && SYMBOL_REF_DECL (rtl)
22516 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22519 if (GET_CODE (rtl) == CONST
22520 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22526 /* Helper function for resolve_addr, handle one location
22527 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22528 the location list couldn't be resolved. */
22531 resolve_addr_in_expr (dw_loc_descr_ref loc)
22533 for (; loc; loc = loc->dw_loc_next)
22534 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22535 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22536 || (loc->dw_loc_opc == DW_OP_implicit_value
22537 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22538 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22540 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22541 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22544 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22547 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22548 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
22549 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
22554 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22555 an address in .rodata section if the string literal is emitted there,
22556 or remove the containing location list or replace DW_AT_const_value
22557 with DW_AT_location and empty location expression, if it isn't found
22558 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22559 to something that has been emitted in the current CU. */
22562 resolve_addr (dw_die_ref die)
22566 dw_loc_list_ref *curr;
22569 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22570 switch (AT_class (a))
22572 case dw_val_class_loc_list:
22573 curr = AT_loc_list_ptr (a);
22576 if (!resolve_addr_in_expr ((*curr)->expr))
22578 dw_loc_list_ref next = (*curr)->dw_loc_next;
22579 if (next && (*curr)->ll_symbol)
22581 gcc_assert (!next->ll_symbol);
22582 next->ll_symbol = (*curr)->ll_symbol;
22587 curr = &(*curr)->dw_loc_next;
22589 if (!AT_loc_list (a))
22591 remove_AT (die, a->dw_attr);
22595 case dw_val_class_loc:
22596 if (!resolve_addr_in_expr (AT_loc (a)))
22598 remove_AT (die, a->dw_attr);
22602 case dw_val_class_addr:
22603 if (a->dw_attr == DW_AT_const_value
22604 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
22606 remove_AT (die, a->dw_attr);
22614 FOR_EACH_CHILD (die, c, resolve_addr (c));
22617 /* Helper routines for optimize_location_lists.
22618 This pass tries to share identical local lists in .debug_loc
22621 /* Iteratively hash operands of LOC opcode. */
22623 static inline hashval_t
22624 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
22626 dw_val_ref val1 = &loc->dw_loc_oprnd1;
22627 dw_val_ref val2 = &loc->dw_loc_oprnd2;
22629 switch (loc->dw_loc_opc)
22631 case DW_OP_const4u:
22632 case DW_OP_const8u:
22636 case DW_OP_const1u:
22637 case DW_OP_const1s:
22638 case DW_OP_const2u:
22639 case DW_OP_const2s:
22640 case DW_OP_const4s:
22641 case DW_OP_const8s:
22645 case DW_OP_plus_uconst:
22681 case DW_OP_deref_size:
22682 case DW_OP_xderef_size:
22683 hash = iterative_hash_object (val1->v.val_int, hash);
22690 gcc_assert (val1->val_class == dw_val_class_loc);
22691 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
22692 hash = iterative_hash_object (offset, hash);
22695 case DW_OP_implicit_value:
22696 hash = iterative_hash_object (val1->v.val_unsigned, hash);
22697 switch (val2->val_class)
22699 case dw_val_class_const:
22700 hash = iterative_hash_object (val2->v.val_int, hash);
22702 case dw_val_class_vec:
22704 unsigned int elt_size = val2->v.val_vec.elt_size;
22705 unsigned int len = val2->v.val_vec.length;
22707 hash = iterative_hash_object (elt_size, hash);
22708 hash = iterative_hash_object (len, hash);
22709 hash = iterative_hash (val2->v.val_vec.array,
22710 len * elt_size, hash);
22713 case dw_val_class_const_double:
22714 hash = iterative_hash_object (val2->v.val_double.low, hash);
22715 hash = iterative_hash_object (val2->v.val_double.high, hash);
22717 case dw_val_class_addr:
22718 hash = iterative_hash_rtx (val2->v.val_addr, hash);
22721 gcc_unreachable ();
22725 case DW_OP_bit_piece:
22726 hash = iterative_hash_object (val1->v.val_int, hash);
22727 hash = iterative_hash_object (val2->v.val_int, hash);
22733 unsigned char dtprel = 0xd1;
22734 hash = iterative_hash_object (dtprel, hash);
22736 hash = iterative_hash_rtx (val1->v.val_addr, hash);
22738 case DW_OP_GNU_implicit_pointer:
22739 hash = iterative_hash_object (val2->v.val_int, hash);
22743 /* Other codes have no operands. */
22749 /* Iteratively hash the whole DWARF location expression LOC. */
22751 static inline hashval_t
22752 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
22754 dw_loc_descr_ref l;
22755 bool sizes_computed = false;
22756 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22757 size_of_locs (loc);
22759 for (l = loc; l != NULL; l = l->dw_loc_next)
22761 enum dwarf_location_atom opc = l->dw_loc_opc;
22762 hash = iterative_hash_object (opc, hash);
22763 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
22765 size_of_locs (loc);
22766 sizes_computed = true;
22768 hash = hash_loc_operands (l, hash);
22773 /* Compute hash of the whole location list LIST_HEAD. */
22776 hash_loc_list (dw_loc_list_ref list_head)
22778 dw_loc_list_ref curr = list_head;
22779 hashval_t hash = 0;
22781 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
22783 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
22784 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
22786 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
22788 hash = hash_locs (curr->expr, hash);
22790 list_head->hash = hash;
22793 /* Return true if X and Y opcodes have the same operands. */
22796 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
22798 dw_val_ref valx1 = &x->dw_loc_oprnd1;
22799 dw_val_ref valx2 = &x->dw_loc_oprnd2;
22800 dw_val_ref valy1 = &y->dw_loc_oprnd1;
22801 dw_val_ref valy2 = &y->dw_loc_oprnd2;
22803 switch (x->dw_loc_opc)
22805 case DW_OP_const4u:
22806 case DW_OP_const8u:
22810 case DW_OP_const1u:
22811 case DW_OP_const1s:
22812 case DW_OP_const2u:
22813 case DW_OP_const2s:
22814 case DW_OP_const4s:
22815 case DW_OP_const8s:
22819 case DW_OP_plus_uconst:
22855 case DW_OP_deref_size:
22856 case DW_OP_xderef_size:
22857 return valx1->v.val_int == valy1->v.val_int;
22860 gcc_assert (valx1->val_class == dw_val_class_loc
22861 && valy1->val_class == dw_val_class_loc
22862 && x->dw_loc_addr == y->dw_loc_addr);
22863 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
22864 case DW_OP_implicit_value:
22865 if (valx1->v.val_unsigned != valy1->v.val_unsigned
22866 || valx2->val_class != valy2->val_class)
22868 switch (valx2->val_class)
22870 case dw_val_class_const:
22871 return valx2->v.val_int == valy2->v.val_int;
22872 case dw_val_class_vec:
22873 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
22874 && valx2->v.val_vec.length == valy2->v.val_vec.length
22875 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
22876 valx2->v.val_vec.elt_size
22877 * valx2->v.val_vec.length) == 0;
22878 case dw_val_class_const_double:
22879 return valx2->v.val_double.low == valy2->v.val_double.low
22880 && valx2->v.val_double.high == valy2->v.val_double.high;
22881 case dw_val_class_addr:
22882 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
22884 gcc_unreachable ();
22887 case DW_OP_bit_piece:
22888 return valx1->v.val_int == valy1->v.val_int
22889 && valx2->v.val_int == valy2->v.val_int;
22892 return rtx_equal_p (valx1->v.val_addr, valx2->v.val_addr);
22893 case DW_OP_GNU_implicit_pointer:
22894 return valx1->val_class == dw_val_class_die_ref
22895 && valx1->val_class == valy1->val_class
22896 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
22897 && valx2->v.val_int == valy2->v.val_int;
22899 /* Other codes have no operands. */
22904 /* Return true if DWARF location expressions X and Y are the same. */
22907 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
22909 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
22910 if (x->dw_loc_opc != y->dw_loc_opc
22911 || x->dtprel != y->dtprel
22912 || !compare_loc_operands (x, y))
22914 return x == NULL && y == NULL;
22917 /* Return precomputed hash of location list X. */
22920 loc_list_hash (const void *x)
22922 return ((const struct dw_loc_list_struct *) x)->hash;
22925 /* Return 1 if location lists X and Y are the same. */
22928 loc_list_eq (const void *x, const void *y)
22930 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
22931 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
22934 if (a->hash != b->hash)
22936 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
22937 if (strcmp (a->begin, b->begin) != 0
22938 || strcmp (a->end, b->end) != 0
22939 || (a->section == NULL) != (b->section == NULL)
22940 || (a->section && strcmp (a->section, b->section) != 0)
22941 || !compare_locs (a->expr, b->expr))
22943 return a == NULL && b == NULL;
22946 /* Recursively optimize location lists referenced from DIE
22947 children and share them whenever possible. */
22950 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
22957 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22958 if (AT_class (a) == dw_val_class_loc_list)
22960 dw_loc_list_ref list = AT_loc_list (a);
22961 /* TODO: perform some optimizations here, before hashing
22962 it and storing into the hash table. */
22963 hash_loc_list (list);
22964 slot = htab_find_slot_with_hash (htab, list, list->hash,
22967 *slot = (void *) list;
22969 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
22972 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
22975 /* Optimize location lists referenced from DIE
22976 children and share them whenever possible. */
22979 optimize_location_lists (dw_die_ref die)
22981 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
22982 optimize_location_lists_1 (die, htab);
22983 htab_delete (htab);
22986 /* Output stuff that dwarf requires at the end of every file,
22987 and generate the DWARF-2 debugging info. */
22990 dwarf2out_finish (const char *filename)
22992 limbo_die_node *node, *next_node;
22993 comdat_type_node *ctnode;
22994 htab_t comdat_type_table;
22997 gen_remaining_tmpl_value_param_die_attribute ();
22999 /* Add the name for the main input file now. We delayed this from
23000 dwarf2out_init to avoid complications with PCH. */
23001 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23002 if (!IS_ABSOLUTE_PATH (filename))
23003 add_comp_dir_attribute (comp_unit_die ());
23004 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23007 htab_traverse (file_table, file_table_relative_p, &p);
23009 add_comp_dir_attribute (comp_unit_die ());
23012 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23014 add_location_or_const_value_attribute (
23015 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23016 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23020 /* Traverse the limbo die list, and add parent/child links. The only
23021 dies without parents that should be here are concrete instances of
23022 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23023 For concrete instances, we can get the parent die from the abstract
23025 for (node = limbo_die_list; node; node = next_node)
23027 dw_die_ref die = node->die;
23028 next_node = node->next;
23030 if (die->die_parent == NULL)
23032 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23035 add_child_die (origin->die_parent, die);
23036 else if (is_cu_die (die))
23038 else if (seen_error ())
23039 /* It's OK to be confused by errors in the input. */
23040 add_child_die (comp_unit_die (), die);
23043 /* In certain situations, the lexical block containing a
23044 nested function can be optimized away, which results
23045 in the nested function die being orphaned. Likewise
23046 with the return type of that nested function. Force
23047 this to be a child of the containing function.
23049 It may happen that even the containing function got fully
23050 inlined and optimized out. In that case we are lost and
23051 assign the empty child. This should not be big issue as
23052 the function is likely unreachable too. */
23053 tree context = NULL_TREE;
23055 gcc_assert (node->created_for);
23057 if (DECL_P (node->created_for))
23058 context = DECL_CONTEXT (node->created_for);
23059 else if (TYPE_P (node->created_for))
23060 context = TYPE_CONTEXT (node->created_for);
23062 gcc_assert (context
23063 && (TREE_CODE (context) == FUNCTION_DECL
23064 || TREE_CODE (context) == NAMESPACE_DECL));
23066 origin = lookup_decl_die (context);
23068 add_child_die (origin, die);
23070 add_child_die (comp_unit_die (), die);
23075 limbo_die_list = NULL;
23077 resolve_addr (comp_unit_die ());
23079 for (node = deferred_asm_name; node; node = node->next)
23081 tree decl = node->created_for;
23082 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23084 add_linkage_attr (node->die, decl);
23085 move_linkage_attr (node->die);
23089 deferred_asm_name = NULL;
23091 /* Walk through the list of incomplete types again, trying once more to
23092 emit full debugging info for them. */
23093 retry_incomplete_types ();
23095 if (flag_eliminate_unused_debug_types)
23096 prune_unused_types ();
23098 /* Generate separate CUs for each of the include files we've seen.
23099 They will go into limbo_die_list. */
23100 if (flag_eliminate_dwarf2_dups && dwarf_version < 4)
23101 break_out_includes (comp_unit_die ());
23103 /* Generate separate COMDAT sections for type DIEs. */
23104 if (dwarf_version >= 4)
23106 break_out_comdat_types (comp_unit_die ());
23108 /* Each new type_unit DIE was added to the limbo die list when created.
23109 Since these have all been added to comdat_type_list, clear the
23111 limbo_die_list = NULL;
23113 /* For each new comdat type unit, copy declarations for incomplete
23114 types to make the new unit self-contained (i.e., no direct
23115 references to the main compile unit). */
23116 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23117 copy_decls_for_unworthy_types (ctnode->root_die);
23118 copy_decls_for_unworthy_types (comp_unit_die ());
23120 /* In the process of copying declarations from one unit to another,
23121 we may have left some declarations behind that are no longer
23122 referenced. Prune them. */
23123 prune_unused_types ();
23126 /* Traverse the DIE's and add add sibling attributes to those DIE's
23127 that have children. */
23128 add_sibling_attributes (comp_unit_die ());
23129 for (node = limbo_die_list; node; node = node->next)
23130 add_sibling_attributes (node->die);
23131 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23132 add_sibling_attributes (ctnode->root_die);
23134 /* Output a terminator label for the .text section. */
23135 switch_to_section (text_section);
23136 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23137 if (cold_text_section)
23139 switch_to_section (cold_text_section);
23140 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23143 /* We can only use the low/high_pc attributes if all of the code was
23145 if (!have_multiple_function_sections
23146 || !(dwarf_version >= 3 || !dwarf_strict))
23148 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23149 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23154 unsigned fde_idx = 0;
23155 bool range_list_added = false;
23157 /* We need to give .debug_loc and .debug_ranges an appropriate
23158 "base address". Use zero so that these addresses become
23159 absolute. Historically, we've emitted the unexpected
23160 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23161 Emit both to give time for other tools to adapt. */
23162 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23163 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23165 if (text_section_used)
23166 add_ranges_by_labels (comp_unit_die (), text_section_label,
23167 text_end_label, &range_list_added);
23168 if (flag_reorder_blocks_and_partition && cold_text_section_used)
23169 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23170 cold_end_label, &range_list_added);
23172 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23174 dw_fde_ref fde = &fde_table[fde_idx];
23176 if (fde->dw_fde_switched_sections)
23178 if (!fde->in_std_section)
23179 add_ranges_by_labels (comp_unit_die (),
23180 fde->dw_fde_hot_section_label,
23181 fde->dw_fde_hot_section_end_label,
23182 &range_list_added);
23183 if (!fde->cold_in_std_section)
23184 add_ranges_by_labels (comp_unit_die (),
23185 fde->dw_fde_unlikely_section_label,
23186 fde->dw_fde_unlikely_section_end_label,
23187 &range_list_added);
23189 else if (!fde->in_std_section)
23190 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23191 fde->dw_fde_end, &range_list_added);
23194 if (range_list_added)
23198 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23199 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23200 debug_line_section_label);
23202 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23203 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23205 if (have_location_lists)
23206 optimize_location_lists (comp_unit_die ());
23208 /* Output all of the compilation units. We put the main one last so that
23209 the offsets are available to output_pubnames. */
23210 for (node = limbo_die_list; node; node = node->next)
23211 output_comp_unit (node->die, 0);
23213 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23214 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23216 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23218 /* Don't output duplicate types. */
23219 if (*slot != HTAB_EMPTY_ENTRY)
23222 /* Add a pointer to the line table for the main compilation unit
23223 so that the debugger can make sense of DW_AT_decl_file
23225 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23226 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23227 debug_line_section_label);
23229 output_comdat_type_unit (ctnode);
23232 htab_delete (comdat_type_table);
23234 /* Output the main compilation unit if non-empty or if .debug_macinfo
23235 will be emitted. */
23236 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23238 /* Output the abbreviation table. */
23239 switch_to_section (debug_abbrev_section);
23240 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23241 output_abbrev_section ();
23243 /* Output location list section if necessary. */
23244 if (have_location_lists)
23246 /* Output the location lists info. */
23247 switch_to_section (debug_loc_section);
23248 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23249 DEBUG_LOC_SECTION_LABEL, 0);
23250 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23251 output_location_lists (comp_unit_die ());
23254 /* Output public names table if necessary. */
23255 if (!VEC_empty (pubname_entry, pubname_table))
23257 gcc_assert (info_section_emitted);
23258 switch_to_section (debug_pubnames_section);
23259 output_pubnames (pubname_table);
23262 /* Output public types table if necessary. */
23263 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23264 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23265 simply won't look for the section. */
23266 if (!VEC_empty (pubname_entry, pubtype_table))
23268 bool empty = false;
23270 if (flag_eliminate_unused_debug_types)
23272 /* The pubtypes table might be emptied by pruning unused items. */
23276 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23277 if (p->die->die_offset != 0)
23285 gcc_assert (info_section_emitted);
23286 switch_to_section (debug_pubtypes_section);
23287 output_pubnames (pubtype_table);
23291 /* Output direct and virtual call tables if necessary. */
23292 if (!VEC_empty (dcall_entry, dcall_table))
23294 switch_to_section (debug_dcall_section);
23295 output_dcall_table ();
23297 if (!VEC_empty (vcall_entry, vcall_table))
23299 switch_to_section (debug_vcall_section);
23300 output_vcall_table ();
23303 /* Output the address range information. We only put functions in the arange
23304 table, so don't write it out if we don't have any. */
23305 if (fde_table_in_use)
23307 switch_to_section (debug_aranges_section);
23311 /* Output ranges section if necessary. */
23312 if (ranges_table_in_use)
23314 switch_to_section (debug_ranges_section);
23315 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23319 /* Output the source line correspondence table. We must do this
23320 even if there is no line information. Otherwise, on an empty
23321 translation unit, we will generate a present, but empty,
23322 .debug_info section. IRIX 6.5 `nm' will then complain when
23323 examining the file. This is done late so that any filenames
23324 used by the debug_info section are marked as 'used'. */
23325 switch_to_section (debug_line_section);
23326 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23327 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23328 output_line_info ();
23330 /* Have to end the macro section. */
23331 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23333 switch_to_section (debug_macinfo_section);
23334 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23335 if (!VEC_empty (macinfo_entry, macinfo_table))
23337 dw2_asm_output_data (1, 0, "End compilation unit");
23340 /* If we emitted any DW_FORM_strp form attribute, output the string
23342 if (debug_str_hash)
23343 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23346 #include "gt-dwarf2out.h"