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 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #include "tree-pass.h"
95 #ifdef DWARF2_DEBUGGING_INFO
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn;
101 #ifdef VMS_DEBUGGING_INFO
102 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
104 /* Define this macro to be a nonzero value if the directory specifications
105 which are output in the debug info should end with a separator. */
106 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
107 /* Define this macro to evaluate to a nonzero value if GCC should refrain
108 from generating indirect strings in DWARF2 debug information, for instance
109 if your target is stuck with an old version of GDB that is unable to
110 process them properly or uses VMS Debug. */
111 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
114 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
117 #ifndef DWARF2_FRAME_INFO
118 # ifdef DWARF2_DEBUGGING_INFO
119 # define DWARF2_FRAME_INFO \
120 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
122 # define DWARF2_FRAME_INFO 0
126 /* Map register numbers held in the call frame info that gcc has
127 collected using DWARF_FRAME_REGNUM to those that should be output in
128 .debug_frame and .eh_frame. */
129 #ifndef DWARF2_FRAME_REG_OUT
130 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
133 /* Save the result of dwarf2out_do_frame across PCH. */
134 static GTY(()) bool saved_do_cfi_asm = 0;
136 /* Decide whether we want to emit frame unwind information for the current
140 dwarf2out_do_frame (void)
142 /* We want to emit correct CFA location expressions or lists, so we
143 have to return true if we're going to output debug info, even if
144 we're not going to output frame or unwind info. */
145 return (write_symbols == DWARF2_DEBUG
146 || write_symbols == VMS_AND_DWARF2_DEBUG
147 || DWARF2_FRAME_INFO || saved_do_cfi_asm
148 #ifdef DWARF2_UNWIND_INFO
149 || (DWARF2_UNWIND_INFO
150 && (flag_unwind_tables
151 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
156 /* Decide whether to emit frame unwind via assembler directives. */
159 dwarf2out_do_cfi_asm (void)
163 #ifdef MIPS_DEBUGGING_INFO
166 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
168 if (saved_do_cfi_asm)
170 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
173 /* Make sure the personality encoding is one the assembler can support.
174 In particular, aligned addresses can't be handled. */
175 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
176 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
178 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
179 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
182 saved_do_cfi_asm = true;
186 /* The size of the target's pointer type. */
188 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
191 /* Array of RTXes referenced by the debugging information, which therefore
192 must be kept around forever. */
193 static GTY(()) VEC(rtx,gc) *used_rtx_array;
195 /* A pointer to the base of a list of incomplete types which might be
196 completed at some later time. incomplete_types_list needs to be a
197 VEC(tree,gc) because we want to tell the garbage collector about
199 static GTY(()) VEC(tree,gc) *incomplete_types;
201 /* A pointer to the base of a table of references to declaration
202 scopes. This table is a display which tracks the nesting
203 of declaration scopes at the current scope and containing
204 scopes. This table is used to find the proper place to
205 define type declaration DIE's. */
206 static GTY(()) VEC(tree,gc) *decl_scope_table;
208 /* Pointers to various DWARF2 sections. */
209 static GTY(()) section *debug_info_section;
210 static GTY(()) section *debug_abbrev_section;
211 static GTY(()) section *debug_aranges_section;
212 static GTY(()) section *debug_macinfo_section;
213 static GTY(()) section *debug_line_section;
214 static GTY(()) section *debug_loc_section;
215 static GTY(()) section *debug_pubnames_section;
216 static GTY(()) section *debug_pubtypes_section;
217 static GTY(()) section *debug_str_section;
218 static GTY(()) section *debug_ranges_section;
219 static GTY(()) section *debug_frame_section;
221 /* Personality decl of current unit. Used only when assembler does not support
223 static GTY(()) rtx current_unit_personality;
225 /* How to start an assembler comment. */
226 #ifndef ASM_COMMENT_START
227 #define ASM_COMMENT_START ";#"
230 typedef struct dw_cfi_struct *dw_cfi_ref;
231 typedef struct dw_fde_struct *dw_fde_ref;
232 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
234 /* Call frames are described using a sequence of Call Frame
235 Information instructions. The register number, offset
236 and address fields are provided as possible operands;
237 their use is selected by the opcode field. */
239 enum dw_cfi_oprnd_type {
241 dw_cfi_oprnd_reg_num,
247 typedef union GTY(()) dw_cfi_oprnd_struct {
248 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
249 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
250 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
251 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
255 typedef struct GTY(()) dw_cfi_struct {
256 dw_cfi_ref dw_cfi_next;
257 enum dwarf_call_frame_info dw_cfi_opc;
258 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
260 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
265 /* This is how we define the location of the CFA. We use to handle it
266 as REG + OFFSET all the time, but now it can be more complex.
267 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
268 Instead of passing around REG and OFFSET, we pass a copy
269 of this structure. */
270 typedef struct GTY(()) cfa_loc {
271 HOST_WIDE_INT offset;
272 HOST_WIDE_INT base_offset;
274 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
275 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
278 /* All call frame descriptions (FDE's) in the GCC generated DWARF
279 refer to a single Common Information Entry (CIE), defined at
280 the beginning of the .debug_frame section. This use of a single
281 CIE obviates the need to keep track of multiple CIE's
282 in the DWARF generation routines below. */
284 typedef struct GTY(()) dw_fde_struct {
286 const char *dw_fde_begin;
287 const char *dw_fde_current_label;
288 const char *dw_fde_end;
289 const char *dw_fde_hot_section_label;
290 const char *dw_fde_hot_section_end_label;
291 const char *dw_fde_unlikely_section_label;
292 const char *dw_fde_unlikely_section_end_label;
293 dw_cfi_ref dw_fde_cfi;
294 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
295 unsigned funcdef_number;
296 HOST_WIDE_INT stack_realignment;
297 /* Dynamic realign argument pointer register. */
298 unsigned int drap_reg;
299 /* Virtual dynamic realign argument pointer register. */
300 unsigned int vdrap_reg;
301 unsigned all_throwers_are_sibcalls : 1;
302 unsigned nothrow : 1;
303 unsigned uses_eh_lsda : 1;
304 /* Whether we did stack realign in this call frame. */
305 unsigned stack_realign : 1;
306 /* Whether dynamic realign argument pointer register has been saved. */
307 unsigned drap_reg_saved: 1;
308 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
309 unsigned in_std_section : 1;
310 /* True iff dw_fde_unlikely_section_label is in text_section or
311 cold_text_section. */
312 unsigned cold_in_std_section : 1;
313 /* True iff switched sections. */
314 unsigned dw_fde_switched_sections : 1;
315 /* True iff switching from cold to hot section. */
316 unsigned dw_fde_switched_cold_to_hot : 1;
320 /* Maximum size (in bytes) of an artificially generated label. */
321 #define MAX_ARTIFICIAL_LABEL_BYTES 30
323 /* The size of addresses as they appear in the Dwarf 2 data.
324 Some architectures use word addresses to refer to code locations,
325 but Dwarf 2 info always uses byte addresses. On such machines,
326 Dwarf 2 addresses need to be larger than the architecture's
328 #ifndef DWARF2_ADDR_SIZE
329 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
332 /* The size in bytes of a DWARF field indicating an offset or length
333 relative to a debug info section, specified to be 4 bytes in the
334 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
337 #ifndef DWARF_OFFSET_SIZE
338 #define DWARF_OFFSET_SIZE 4
341 /* According to the (draft) DWARF 3 specification, the initial length
342 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
343 bytes are 0xffffffff, followed by the length stored in the next 8
346 However, the SGI/MIPS ABI uses an initial length which is equal to
347 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
349 #ifndef DWARF_INITIAL_LENGTH_SIZE
350 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
353 /* Round SIZE up to the nearest BOUNDARY. */
354 #define DWARF_ROUND(SIZE,BOUNDARY) \
355 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
357 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
358 #ifndef DWARF_CIE_DATA_ALIGNMENT
359 #ifdef STACK_GROWS_DOWNWARD
360 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
362 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
366 /* CIE identifier. */
367 #if HOST_BITS_PER_WIDE_INT >= 64
368 #define DWARF_CIE_ID \
369 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
371 #define DWARF_CIE_ID DW_CIE_ID
374 /* A pointer to the base of a table that contains frame description
375 information for each routine. */
376 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
378 /* Number of elements currently allocated for fde_table. */
379 static GTY(()) unsigned fde_table_allocated;
381 /* Number of elements in fde_table currently in use. */
382 static GTY(()) unsigned fde_table_in_use;
384 /* Size (in elements) of increments by which we may expand the
386 #define FDE_TABLE_INCREMENT 256
388 /* Get the current fde_table entry we should use. */
390 static inline dw_fde_ref
393 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
396 /* A list of call frame insns for the CIE. */
397 static GTY(()) dw_cfi_ref cie_cfi_head;
399 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
400 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
401 attribute that accelerates the lookup of the FDE associated
402 with the subprogram. This variable holds the table index of the FDE
403 associated with the current function (body) definition. */
404 static unsigned current_funcdef_fde;
407 struct GTY(()) indirect_string_node {
409 unsigned int refcount;
410 enum dwarf_form form;
414 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
416 /* True if the compilation unit has location entries that reference
418 static GTY(()) bool debug_str_hash_forced = false;
420 static GTY(()) int dw2_string_counter;
421 static GTY(()) unsigned long dwarf2out_cfi_label_num;
423 /* True if the compilation unit places functions in more than one section. */
424 static GTY(()) bool have_multiple_function_sections = false;
426 /* Whether the default text and cold text sections have been used at all. */
428 static GTY(()) bool text_section_used = false;
429 static GTY(()) bool cold_text_section_used = false;
431 /* The default cold text section. */
432 static GTY(()) section *cold_text_section;
434 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
436 /* Forward declarations for functions defined in this file. */
438 static char *stripattributes (const char *);
439 static const char *dwarf_cfi_name (unsigned);
440 static dw_cfi_ref new_cfi (void);
441 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
442 static void add_fde_cfi (const char *, dw_cfi_ref);
443 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
444 static void lookup_cfa (dw_cfa_location *);
445 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
446 #ifdef DWARF2_UNWIND_INFO
447 static void initial_return_save (rtx);
449 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
451 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
452 static void output_cfi_directive (dw_cfi_ref);
453 static void output_call_frame_info (int);
454 static void dwarf2out_note_section_used (void);
455 static void dwarf2out_stack_adjust (rtx, bool);
456 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
457 static void flush_queued_reg_saves (void);
458 static bool clobbers_queued_reg_save (const_rtx);
459 static void dwarf2out_frame_debug_expr (rtx, const char *);
461 /* Support for complex CFA locations. */
462 static void output_cfa_loc (dw_cfi_ref);
463 static void output_cfa_loc_raw (dw_cfi_ref);
464 static void get_cfa_from_loc_descr (dw_cfa_location *,
465 struct dw_loc_descr_struct *);
466 static struct dw_loc_descr_struct *build_cfa_loc
467 (dw_cfa_location *, HOST_WIDE_INT);
468 static struct dw_loc_descr_struct *build_cfa_aligned_loc
469 (HOST_WIDE_INT, HOST_WIDE_INT);
470 static void def_cfa_1 (const char *, dw_cfa_location *);
472 /* How to start an assembler comment. */
473 #ifndef ASM_COMMENT_START
474 #define ASM_COMMENT_START ";#"
477 /* Data and reference forms for relocatable data. */
478 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
479 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
481 #ifndef DEBUG_FRAME_SECTION
482 #define DEBUG_FRAME_SECTION ".debug_frame"
485 #ifndef FUNC_BEGIN_LABEL
486 #define FUNC_BEGIN_LABEL "LFB"
489 #ifndef FUNC_END_LABEL
490 #define FUNC_END_LABEL "LFE"
493 #ifndef FRAME_BEGIN_LABEL
494 #define FRAME_BEGIN_LABEL "Lframe"
496 #define CIE_AFTER_SIZE_LABEL "LSCIE"
497 #define CIE_END_LABEL "LECIE"
498 #define FDE_LABEL "LSFDE"
499 #define FDE_AFTER_SIZE_LABEL "LASFDE"
500 #define FDE_END_LABEL "LEFDE"
501 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
502 #define LINE_NUMBER_END_LABEL "LELT"
503 #define LN_PROLOG_AS_LABEL "LASLTP"
504 #define LN_PROLOG_END_LABEL "LELTP"
505 #define DIE_LABEL_PREFIX "DW"
507 /* The DWARF 2 CFA column which tracks the return address. Normally this
508 is the column for PC, or the first column after all of the hard
510 #ifndef DWARF_FRAME_RETURN_COLUMN
512 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
514 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
518 /* The mapping from gcc register number to DWARF 2 CFA column number. By
519 default, we just provide columns for all registers. */
520 #ifndef DWARF_FRAME_REGNUM
521 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
524 /* Hook used by __throw. */
527 expand_builtin_dwarf_sp_column (void)
529 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
530 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
533 /* Return a pointer to a copy of the section string name S with all
534 attributes stripped off, and an asterisk prepended (for assemble_name). */
537 stripattributes (const char *s)
539 char *stripped = XNEWVEC (char, strlen (s) + 2);
544 while (*s && *s != ',')
551 /* MEM is a memory reference for the register size table, each element of
552 which has mode MODE. Initialize column C as a return address column. */
555 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
557 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
558 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
559 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
562 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
564 static inline HOST_WIDE_INT
565 div_data_align (HOST_WIDE_INT off)
567 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
568 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
572 /* Return true if we need a signed version of a given opcode
573 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
576 need_data_align_sf_opcode (HOST_WIDE_INT off)
578 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
581 /* Generate code to initialize the register size table. */
584 expand_builtin_init_dwarf_reg_sizes (tree address)
587 enum machine_mode mode = TYPE_MODE (char_type_node);
588 rtx addr = expand_normal (address);
589 rtx mem = gen_rtx_MEM (BLKmode, addr);
590 bool wrote_return_column = false;
592 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
594 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
596 if (rnum < DWARF_FRAME_REGISTERS)
598 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
599 enum machine_mode save_mode = reg_raw_mode[i];
602 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
603 save_mode = choose_hard_reg_mode (i, 1, true);
604 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
606 if (save_mode == VOIDmode)
608 wrote_return_column = true;
610 size = GET_MODE_SIZE (save_mode);
614 emit_move_insn (adjust_address (mem, mode, offset),
615 gen_int_mode (size, mode));
619 if (!wrote_return_column)
620 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
622 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
623 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
626 targetm.init_dwarf_reg_sizes_extra (address);
629 /* Convert a DWARF call frame info. operation to its string name */
632 dwarf_cfi_name (unsigned int cfi_opc)
636 case DW_CFA_advance_loc:
637 return "DW_CFA_advance_loc";
639 return "DW_CFA_offset";
641 return "DW_CFA_restore";
645 return "DW_CFA_set_loc";
646 case DW_CFA_advance_loc1:
647 return "DW_CFA_advance_loc1";
648 case DW_CFA_advance_loc2:
649 return "DW_CFA_advance_loc2";
650 case DW_CFA_advance_loc4:
651 return "DW_CFA_advance_loc4";
652 case DW_CFA_offset_extended:
653 return "DW_CFA_offset_extended";
654 case DW_CFA_restore_extended:
655 return "DW_CFA_restore_extended";
656 case DW_CFA_undefined:
657 return "DW_CFA_undefined";
658 case DW_CFA_same_value:
659 return "DW_CFA_same_value";
660 case DW_CFA_register:
661 return "DW_CFA_register";
662 case DW_CFA_remember_state:
663 return "DW_CFA_remember_state";
664 case DW_CFA_restore_state:
665 return "DW_CFA_restore_state";
667 return "DW_CFA_def_cfa";
668 case DW_CFA_def_cfa_register:
669 return "DW_CFA_def_cfa_register";
670 case DW_CFA_def_cfa_offset:
671 return "DW_CFA_def_cfa_offset";
674 case DW_CFA_def_cfa_expression:
675 return "DW_CFA_def_cfa_expression";
676 case DW_CFA_expression:
677 return "DW_CFA_expression";
678 case DW_CFA_offset_extended_sf:
679 return "DW_CFA_offset_extended_sf";
680 case DW_CFA_def_cfa_sf:
681 return "DW_CFA_def_cfa_sf";
682 case DW_CFA_def_cfa_offset_sf:
683 return "DW_CFA_def_cfa_offset_sf";
685 /* SGI/MIPS specific */
686 case DW_CFA_MIPS_advance_loc8:
687 return "DW_CFA_MIPS_advance_loc8";
690 case DW_CFA_GNU_window_save:
691 return "DW_CFA_GNU_window_save";
692 case DW_CFA_GNU_args_size:
693 return "DW_CFA_GNU_args_size";
694 case DW_CFA_GNU_negative_offset_extended:
695 return "DW_CFA_GNU_negative_offset_extended";
698 return "DW_CFA_<unknown>";
702 /* Return a pointer to a newly allocated Call Frame Instruction. */
704 static inline dw_cfi_ref
707 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
709 cfi->dw_cfi_next = NULL;
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
711 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
716 /* Add a Call Frame Instruction to list of instructions. */
719 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
722 dw_fde_ref fde = current_fde ();
724 /* When DRAP is used, CFA is defined with an expression. Redefine
725 CFA may lead to a different CFA value. */
726 /* ??? Of course, this heuristic fails when we're annotating epilogues,
727 because of course we'll always want to redefine the CFA back to the
728 stack pointer on the way out. Where should we move this check? */
729 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
730 switch (cfi->dw_cfi_opc)
732 case DW_CFA_def_cfa_register:
733 case DW_CFA_def_cfa_offset:
734 case DW_CFA_def_cfa_offset_sf:
736 case DW_CFA_def_cfa_sf:
743 /* Find the end of the chain. */
744 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
750 /* Generate a new label for the CFI info to refer to. FORCE is true
751 if a label needs to be output even when using .cfi_* directives. */
754 dwarf2out_cfi_label (bool force)
756 static char label[20];
758 if (!force && dwarf2out_do_cfi_asm ())
760 /* In this case, we will be emitting the asm directive instead of
761 the label, so just return a placeholder to keep the rest of the
763 strcpy (label, "<do not output>");
767 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
768 ASM_OUTPUT_LABEL (asm_out_file, label);
774 /* True if remember_state should be emitted before following CFI directive. */
775 static bool emit_cfa_remember;
777 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
778 or to the CIE if LABEL is NULL. */
781 add_fde_cfi (const char *label, dw_cfi_ref cfi)
783 dw_cfi_ref *list_head;
785 if (emit_cfa_remember)
787 dw_cfi_ref cfi_remember;
789 /* Emit the state save. */
790 emit_cfa_remember = false;
791 cfi_remember = new_cfi ();
792 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
793 add_fde_cfi (label, cfi_remember);
796 list_head = &cie_cfi_head;
798 if (dwarf2out_do_cfi_asm ())
802 dw_fde_ref fde = current_fde ();
804 gcc_assert (fde != NULL);
806 /* We still have to add the cfi to the list so that lookup_cfa
807 works later on. When -g2 and above we even need to force
808 emitting of CFI labels and add to list a DW_CFA_set_loc for
809 convert_cfa_to_fb_loc_list purposes. If we're generating
810 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
811 convert_cfa_to_fb_loc_list. */
812 if (dwarf_version == 2
813 && debug_info_level > DINFO_LEVEL_TERSE
814 && (write_symbols == DWARF2_DEBUG
815 || write_symbols == VMS_AND_DWARF2_DEBUG))
817 switch (cfi->dw_cfi_opc)
819 case DW_CFA_def_cfa_offset:
820 case DW_CFA_def_cfa_offset_sf:
821 case DW_CFA_def_cfa_register:
823 case DW_CFA_def_cfa_sf:
824 case DW_CFA_def_cfa_expression:
825 case DW_CFA_restore_state:
826 if (*label == 0 || strcmp (label, "<do not output>") == 0)
827 label = dwarf2out_cfi_label (true);
829 if (fde->dw_fde_current_label == NULL
830 || strcmp (label, fde->dw_fde_current_label) != 0)
834 label = xstrdup (label);
836 /* Set the location counter to the new label. */
838 /* It doesn't metter whether DW_CFA_set_loc
839 or DW_CFA_advance_loc4 is added here, those aren't
840 emitted into assembly, only looked up by
841 convert_cfa_to_fb_loc_list. */
842 xcfi->dw_cfi_opc = DW_CFA_set_loc;
843 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
844 add_cfi (&fde->dw_fde_cfi, xcfi);
845 fde->dw_fde_current_label = label;
853 output_cfi_directive (cfi);
855 list_head = &fde->dw_fde_cfi;
857 /* ??? If this is a CFI for the CIE, we don't emit. This
858 assumes that the standard CIE contents that the assembler
859 uses matches the standard CIE contents that the compiler
860 uses. This is probably a bad assumption. I'm not quite
861 sure how to address this for now. */
865 dw_fde_ref fde = current_fde ();
867 gcc_assert (fde != NULL);
870 label = dwarf2out_cfi_label (false);
872 if (fde->dw_fde_current_label == NULL
873 || strcmp (label, fde->dw_fde_current_label) != 0)
877 label = xstrdup (label);
879 /* Set the location counter to the new label. */
881 /* If we have a current label, advance from there, otherwise
882 set the location directly using set_loc. */
883 xcfi->dw_cfi_opc = fde->dw_fde_current_label
884 ? DW_CFA_advance_loc4
886 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
887 add_cfi (&fde->dw_fde_cfi, xcfi);
889 fde->dw_fde_current_label = label;
892 list_head = &fde->dw_fde_cfi;
895 add_cfi (list_head, cfi);
898 /* Subroutine of lookup_cfa. */
901 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
903 switch (cfi->dw_cfi_opc)
905 case DW_CFA_def_cfa_offset:
906 case DW_CFA_def_cfa_offset_sf:
907 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
909 case DW_CFA_def_cfa_register:
910 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
913 case DW_CFA_def_cfa_sf:
914 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
915 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
917 case DW_CFA_def_cfa_expression:
918 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
921 case DW_CFA_remember_state:
922 gcc_assert (!remember->in_use);
924 remember->in_use = 1;
926 case DW_CFA_restore_state:
927 gcc_assert (remember->in_use);
929 remember->in_use = 0;
937 /* Find the previous value for the CFA. */
940 lookup_cfa (dw_cfa_location *loc)
944 dw_cfa_location remember;
946 memset (loc, 0, sizeof (*loc));
947 loc->reg = INVALID_REGNUM;
950 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
951 lookup_cfa_1 (cfi, loc, &remember);
953 fde = current_fde ();
955 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
956 lookup_cfa_1 (cfi, loc, &remember);
959 /* The current rule for calculating the DWARF2 canonical frame address. */
960 static dw_cfa_location cfa;
962 /* The register used for saving registers to the stack, and its offset
964 static dw_cfa_location cfa_store;
966 /* The current save location around an epilogue. */
967 static dw_cfa_location cfa_remember;
969 /* The running total of the size of arguments pushed onto the stack. */
970 static HOST_WIDE_INT args_size;
972 /* The last args_size we actually output. */
973 static HOST_WIDE_INT old_args_size;
975 /* Entry point to update the canonical frame address (CFA).
976 LABEL is passed to add_fde_cfi. The value of CFA is now to be
977 calculated from REG+OFFSET. */
980 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
987 def_cfa_1 (label, &loc);
990 /* Determine if two dw_cfa_location structures define the same data. */
993 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
995 return (loc1->reg == loc2->reg
996 && loc1->offset == loc2->offset
997 && loc1->indirect == loc2->indirect
998 && (loc1->indirect == 0
999 || loc1->base_offset == loc2->base_offset));
1002 /* This routine does the actual work. The CFA is now calculated from
1003 the dw_cfa_location structure. */
1006 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1009 dw_cfa_location old_cfa, loc;
1014 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1015 cfa_store.offset = loc.offset;
1017 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1018 lookup_cfa (&old_cfa);
1020 /* If nothing changed, no need to issue any call frame instructions. */
1021 if (cfa_equal_p (&loc, &old_cfa))
1026 if (loc.reg == old_cfa.reg && !loc.indirect)
1028 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1029 the CFA register did not change but the offset did. The data
1030 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1031 in the assembler via the .cfi_def_cfa_offset directive. */
1033 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1035 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1036 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1039 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1040 else if (loc.offset == old_cfa.offset
1041 && old_cfa.reg != INVALID_REGNUM
1044 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1045 indicating the CFA register has changed to <register> but the
1046 offset has not changed. */
1047 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1048 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1052 else if (loc.indirect == 0)
1054 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1055 indicating the CFA register has changed to <register> with
1056 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1057 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1060 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1062 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1063 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1064 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1068 /* Construct a DW_CFA_def_cfa_expression instruction to
1069 calculate the CFA using a full location expression since no
1070 register-offset pair is available. */
1071 struct dw_loc_descr_struct *loc_list;
1073 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1074 loc_list = build_cfa_loc (&loc, 0);
1075 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1078 add_fde_cfi (label, cfi);
1081 /* Add the CFI for saving a register. REG is the CFA column number.
1082 LABEL is passed to add_fde_cfi.
1083 If SREG is -1, the register is saved at OFFSET from the CFA;
1084 otherwise it is saved in SREG. */
1087 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1089 dw_cfi_ref cfi = new_cfi ();
1090 dw_fde_ref fde = current_fde ();
1092 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1094 /* When stack is aligned, store REG using DW_CFA_expression with
1097 && fde->stack_realign
1098 && sreg == INVALID_REGNUM)
1100 cfi->dw_cfi_opc = DW_CFA_expression;
1101 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1102 cfi->dw_cfi_oprnd1.dw_cfi_loc
1103 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1105 else if (sreg == INVALID_REGNUM)
1107 if (need_data_align_sf_opcode (offset))
1108 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1109 else if (reg & ~0x3f)
1110 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1112 cfi->dw_cfi_opc = DW_CFA_offset;
1113 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1115 else if (sreg == reg)
1116 cfi->dw_cfi_opc = DW_CFA_same_value;
1119 cfi->dw_cfi_opc = DW_CFA_register;
1120 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1123 add_fde_cfi (label, cfi);
1126 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1127 This CFI tells the unwinder that it needs to restore the window registers
1128 from the previous frame's window save area.
1130 ??? Perhaps we should note in the CIE where windows are saved (instead of
1131 assuming 0(cfa)) and what registers are in the window. */
1134 dwarf2out_window_save (const char *label)
1136 dw_cfi_ref cfi = new_cfi ();
1138 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1139 add_fde_cfi (label, cfi);
1142 /* Add a CFI to update the running total of the size of arguments
1143 pushed onto the stack. */
1146 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1150 if (size == old_args_size)
1153 old_args_size = size;
1156 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1157 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1158 add_fde_cfi (label, cfi);
1161 /* Entry point for saving a register to the stack. REG is the GCC register
1162 number. LABEL and OFFSET are passed to reg_save. */
1165 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1167 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1170 /* Entry point for saving the return address in the stack.
1171 LABEL and OFFSET are passed to reg_save. */
1174 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1176 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1179 /* Entry point for saving the return address in a register.
1180 LABEL and SREG are passed to reg_save. */
1183 dwarf2out_return_reg (const char *label, unsigned int sreg)
1185 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1188 #ifdef DWARF2_UNWIND_INFO
1189 /* Record the initial position of the return address. RTL is
1190 INCOMING_RETURN_ADDR_RTX. */
1193 initial_return_save (rtx rtl)
1195 unsigned int reg = INVALID_REGNUM;
1196 HOST_WIDE_INT offset = 0;
1198 switch (GET_CODE (rtl))
1201 /* RA is in a register. */
1202 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1206 /* RA is on the stack. */
1207 rtl = XEXP (rtl, 0);
1208 switch (GET_CODE (rtl))
1211 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1216 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1217 offset = INTVAL (XEXP (rtl, 1));
1221 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1222 offset = -INTVAL (XEXP (rtl, 1));
1232 /* The return address is at some offset from any value we can
1233 actually load. For instance, on the SPARC it is in %i7+8. Just
1234 ignore the offset for now; it doesn't matter for unwinding frames. */
1235 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1236 initial_return_save (XEXP (rtl, 0));
1243 if (reg != DWARF_FRAME_RETURN_COLUMN)
1244 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1248 /* Given a SET, calculate the amount of stack adjustment it
1251 static HOST_WIDE_INT
1252 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1253 HOST_WIDE_INT cur_offset)
1255 const_rtx src = SET_SRC (pattern);
1256 const_rtx dest = SET_DEST (pattern);
1257 HOST_WIDE_INT offset = 0;
1260 if (dest == stack_pointer_rtx)
1262 code = GET_CODE (src);
1264 /* Assume (set (reg sp) (reg whatever)) sets args_size
1266 if (code == REG && src != stack_pointer_rtx)
1268 offset = -cur_args_size;
1269 #ifndef STACK_GROWS_DOWNWARD
1272 return offset - cur_offset;
1275 if (! (code == PLUS || code == MINUS)
1276 || XEXP (src, 0) != stack_pointer_rtx
1277 || !CONST_INT_P (XEXP (src, 1)))
1280 /* (set (reg sp) (plus (reg sp) (const_int))) */
1281 offset = INTVAL (XEXP (src, 1));
1287 if (MEM_P (src) && !MEM_P (dest))
1291 /* (set (mem (pre_dec (reg sp))) (foo)) */
1292 src = XEXP (dest, 0);
1293 code = GET_CODE (src);
1299 if (XEXP (src, 0) == stack_pointer_rtx)
1301 rtx val = XEXP (XEXP (src, 1), 1);
1302 /* We handle only adjustments by constant amount. */
1303 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1304 && CONST_INT_P (val));
1305 offset = -INTVAL (val);
1312 if (XEXP (src, 0) == stack_pointer_rtx)
1314 offset = GET_MODE_SIZE (GET_MODE (dest));
1321 if (XEXP (src, 0) == stack_pointer_rtx)
1323 offset = -GET_MODE_SIZE (GET_MODE (dest));
1338 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1339 indexed by INSN_UID. */
1341 static HOST_WIDE_INT *barrier_args_size;
1343 /* Helper function for compute_barrier_args_size. Handle one insn. */
1345 static HOST_WIDE_INT
1346 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1347 VEC (rtx, heap) **next)
1349 HOST_WIDE_INT offset = 0;
1352 if (! RTX_FRAME_RELATED_P (insn))
1354 if (prologue_epilogue_contains (insn))
1356 else if (GET_CODE (PATTERN (insn)) == SET)
1357 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1358 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1359 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1361 /* There may be stack adjustments inside compound insns. Search
1363 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1364 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1365 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1366 cur_args_size, offset);
1371 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1375 expr = XEXP (expr, 0);
1376 if (GET_CODE (expr) == PARALLEL
1377 || GET_CODE (expr) == SEQUENCE)
1378 for (i = 1; i < XVECLEN (expr, 0); i++)
1380 rtx elem = XVECEXP (expr, 0, i);
1382 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1383 offset += stack_adjust_offset (elem, cur_args_size, offset);
1388 #ifndef STACK_GROWS_DOWNWARD
1392 cur_args_size += offset;
1393 if (cur_args_size < 0)
1398 rtx dest = JUMP_LABEL (insn);
1402 if (barrier_args_size [INSN_UID (dest)] < 0)
1404 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1405 VEC_safe_push (rtx, heap, *next, dest);
1410 return cur_args_size;
1413 /* Walk the whole function and compute args_size on BARRIERs. */
1416 compute_barrier_args_size (void)
1418 int max_uid = get_max_uid (), i;
1420 VEC (rtx, heap) *worklist, *next, *tmp;
1422 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1423 for (i = 0; i < max_uid; i++)
1424 barrier_args_size[i] = -1;
1426 worklist = VEC_alloc (rtx, heap, 20);
1427 next = VEC_alloc (rtx, heap, 20);
1428 insn = get_insns ();
1429 barrier_args_size[INSN_UID (insn)] = 0;
1430 VEC_quick_push (rtx, worklist, insn);
1433 while (!VEC_empty (rtx, worklist))
1435 rtx prev, body, first_insn;
1436 HOST_WIDE_INT cur_args_size;
1438 first_insn = insn = VEC_pop (rtx, worklist);
1439 cur_args_size = barrier_args_size[INSN_UID (insn)];
1440 prev = prev_nonnote_insn (insn);
1441 if (prev && BARRIER_P (prev))
1442 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1444 for (; insn; insn = NEXT_INSN (insn))
1446 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1448 if (BARRIER_P (insn))
1453 if (insn == first_insn)
1455 else if (barrier_args_size[INSN_UID (insn)] < 0)
1457 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1462 /* The insns starting with this label have been
1463 already scanned or are in the worklist. */
1468 body = PATTERN (insn);
1469 if (GET_CODE (body) == SEQUENCE)
1471 HOST_WIDE_INT dest_args_size = cur_args_size;
1472 for (i = 1; i < XVECLEN (body, 0); i++)
1473 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1474 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1476 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1477 dest_args_size, &next);
1480 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1481 cur_args_size, &next);
1483 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1484 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1485 dest_args_size, &next);
1488 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1489 cur_args_size, &next);
1493 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1497 if (VEC_empty (rtx, next))
1500 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1504 VEC_truncate (rtx, next, 0);
1507 VEC_free (rtx, heap, worklist);
1508 VEC_free (rtx, heap, next);
1512 /* Check INSN to see if it looks like a push or a stack adjustment, and
1513 make a note of it if it does. EH uses this information to find out how
1514 much extra space it needs to pop off the stack. */
1517 dwarf2out_stack_adjust (rtx insn, bool after_p)
1519 HOST_WIDE_INT offset;
1523 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1524 with this function. Proper support would require all frame-related
1525 insns to be marked, and to be able to handle saving state around
1526 epilogues textually in the middle of the function. */
1527 if (prologue_epilogue_contains (insn))
1530 /* If INSN is an instruction from target of an annulled branch, the
1531 effects are for the target only and so current argument size
1532 shouldn't change at all. */
1534 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1535 && INSN_FROM_TARGET_P (insn))
1538 /* If only calls can throw, and we have a frame pointer,
1539 save up adjustments until we see the CALL_INSN. */
1540 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1542 if (CALL_P (insn) && !after_p)
1544 /* Extract the size of the args from the CALL rtx itself. */
1545 insn = PATTERN (insn);
1546 if (GET_CODE (insn) == PARALLEL)
1547 insn = XVECEXP (insn, 0, 0);
1548 if (GET_CODE (insn) == SET)
1549 insn = SET_SRC (insn);
1550 gcc_assert (GET_CODE (insn) == CALL);
1551 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1556 if (CALL_P (insn) && !after_p)
1558 if (!flag_asynchronous_unwind_tables)
1559 dwarf2out_args_size ("", args_size);
1562 else if (BARRIER_P (insn))
1564 /* Don't call compute_barrier_args_size () if the only
1565 BARRIER is at the end of function. */
1566 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1567 compute_barrier_args_size ();
1568 if (barrier_args_size == NULL)
1572 offset = barrier_args_size[INSN_UID (insn)];
1577 offset -= args_size;
1578 #ifndef STACK_GROWS_DOWNWARD
1582 else if (GET_CODE (PATTERN (insn)) == SET)
1583 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1584 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1585 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1587 /* There may be stack adjustments inside compound insns. Search
1589 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1590 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1591 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1600 label = dwarf2out_cfi_label (false);
1601 dwarf2out_args_size_adjust (offset, label);
1604 /* Adjust args_size based on stack adjustment OFFSET. */
1607 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1609 if (cfa.reg == STACK_POINTER_REGNUM)
1610 cfa.offset += offset;
1612 if (cfa_store.reg == STACK_POINTER_REGNUM)
1613 cfa_store.offset += offset;
1615 #ifndef STACK_GROWS_DOWNWARD
1619 args_size += offset;
1623 def_cfa_1 (label, &cfa);
1624 if (flag_asynchronous_unwind_tables)
1625 dwarf2out_args_size (label, args_size);
1630 /* We delay emitting a register save until either (a) we reach the end
1631 of the prologue or (b) the register is clobbered. This clusters
1632 register saves so that there are fewer pc advances. */
1634 struct GTY(()) queued_reg_save {
1635 struct queued_reg_save *next;
1637 HOST_WIDE_INT cfa_offset;
1641 static GTY(()) struct queued_reg_save *queued_reg_saves;
1643 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1644 struct GTY(()) reg_saved_in_data {
1649 /* A list of registers saved in other registers.
1650 The list intentionally has a small maximum capacity of 4; if your
1651 port needs more than that, you might consider implementing a
1652 more efficient data structure. */
1653 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1654 static GTY(()) size_t num_regs_saved_in_regs;
1656 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1657 static const char *last_reg_save_label;
1659 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1660 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1663 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1665 struct queued_reg_save *q;
1667 /* Duplicates waste space, but it's also necessary to remove them
1668 for correctness, since the queue gets output in reverse
1670 for (q = queued_reg_saves; q != NULL; q = q->next)
1671 if (REGNO (q->reg) == REGNO (reg))
1676 q = GGC_NEW (struct queued_reg_save);
1677 q->next = queued_reg_saves;
1678 queued_reg_saves = q;
1682 q->cfa_offset = offset;
1683 q->saved_reg = sreg;
1685 last_reg_save_label = label;
1688 /* Output all the entries in QUEUED_REG_SAVES. */
1691 flush_queued_reg_saves (void)
1693 struct queued_reg_save *q;
1695 for (q = queued_reg_saves; q; q = q->next)
1698 unsigned int reg, sreg;
1700 for (i = 0; i < num_regs_saved_in_regs; i++)
1701 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1703 if (q->saved_reg && i == num_regs_saved_in_regs)
1705 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1706 num_regs_saved_in_regs++;
1708 if (i != num_regs_saved_in_regs)
1710 regs_saved_in_regs[i].orig_reg = q->reg;
1711 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1714 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1716 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1718 sreg = INVALID_REGNUM;
1719 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1722 queued_reg_saves = NULL;
1723 last_reg_save_label = NULL;
1726 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1727 location for? Or, does it clobber a register which we've previously
1728 said that some other register is saved in, and for which we now
1729 have a new location for? */
1732 clobbers_queued_reg_save (const_rtx insn)
1734 struct queued_reg_save *q;
1736 for (q = queued_reg_saves; q; q = q->next)
1739 if (modified_in_p (q->reg, insn))
1741 for (i = 0; i < num_regs_saved_in_regs; i++)
1742 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1743 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1750 /* Entry point for saving the first register into the second. */
1753 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1756 unsigned int regno, sregno;
1758 for (i = 0; i < num_regs_saved_in_regs; i++)
1759 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1761 if (i == num_regs_saved_in_regs)
1763 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1764 num_regs_saved_in_regs++;
1766 regs_saved_in_regs[i].orig_reg = reg;
1767 regs_saved_in_regs[i].saved_in_reg = sreg;
1769 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1770 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1771 reg_save (label, regno, sregno, 0);
1774 /* What register, if any, is currently saved in REG? */
1777 reg_saved_in (rtx reg)
1779 unsigned int regn = REGNO (reg);
1781 struct queued_reg_save *q;
1783 for (q = queued_reg_saves; q; q = q->next)
1784 if (q->saved_reg && regn == REGNO (q->saved_reg))
1787 for (i = 0; i < num_regs_saved_in_regs; i++)
1788 if (regs_saved_in_regs[i].saved_in_reg
1789 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1790 return regs_saved_in_regs[i].orig_reg;
1796 /* A temporary register holding an integral value used in adjusting SP
1797 or setting up the store_reg. The "offset" field holds the integer
1798 value, not an offset. */
1799 static dw_cfa_location cfa_temp;
1801 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1804 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1806 memset (&cfa, 0, sizeof (cfa));
1808 switch (GET_CODE (pat))
1811 cfa.reg = REGNO (XEXP (pat, 0));
1812 cfa.offset = INTVAL (XEXP (pat, 1));
1816 cfa.reg = REGNO (pat);
1820 /* Recurse and define an expression. */
1824 def_cfa_1 (label, &cfa);
1827 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1830 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1834 gcc_assert (GET_CODE (pat) == SET);
1835 dest = XEXP (pat, 0);
1836 src = XEXP (pat, 1);
1838 switch (GET_CODE (src))
1841 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1842 cfa.offset -= INTVAL (XEXP (src, 1));
1852 cfa.reg = REGNO (dest);
1853 gcc_assert (cfa.indirect == 0);
1855 def_cfa_1 (label, &cfa);
1858 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1861 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1863 HOST_WIDE_INT offset;
1864 rtx src, addr, span;
1866 src = XEXP (set, 1);
1867 addr = XEXP (set, 0);
1868 gcc_assert (MEM_P (addr));
1869 addr = XEXP (addr, 0);
1871 /* As documented, only consider extremely simple addresses. */
1872 switch (GET_CODE (addr))
1875 gcc_assert (REGNO (addr) == cfa.reg);
1876 offset = -cfa.offset;
1879 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1880 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1886 span = targetm.dwarf_register_span (src);
1888 /* ??? We'd like to use queue_reg_save, but we need to come up with
1889 a different flushing heuristic for epilogues. */
1891 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1894 /* We have a PARALLEL describing where the contents of SRC live.
1895 Queue register saves for each piece of the PARALLEL. */
1898 HOST_WIDE_INT span_offset = offset;
1900 gcc_assert (GET_CODE (span) == PARALLEL);
1902 limit = XVECLEN (span, 0);
1903 for (par_index = 0; par_index < limit; par_index++)
1905 rtx elem = XVECEXP (span, 0, par_index);
1907 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1908 INVALID_REGNUM, span_offset);
1909 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1914 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1917 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1920 unsigned sregno, dregno;
1922 src = XEXP (set, 1);
1923 dest = XEXP (set, 0);
1926 sregno = DWARF_FRAME_RETURN_COLUMN;
1928 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1930 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1932 /* ??? We'd like to use queue_reg_save, but we need to come up with
1933 a different flushing heuristic for epilogues. */
1934 reg_save (label, sregno, dregno, 0);
1937 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1940 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1942 dw_cfi_ref cfi = new_cfi ();
1943 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1945 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1946 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1948 add_fde_cfi (label, cfi);
1951 /* Record call frame debugging information for an expression EXPR,
1952 which either sets SP or FP (adjusting how we calculate the frame
1953 address) or saves a register to the stack or another register.
1954 LABEL indicates the address of EXPR.
1956 This function encodes a state machine mapping rtxes to actions on
1957 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1958 users need not read the source code.
1960 The High-Level Picture
1962 Changes in the register we use to calculate the CFA: Currently we
1963 assume that if you copy the CFA register into another register, we
1964 should take the other one as the new CFA register; this seems to
1965 work pretty well. If it's wrong for some target, it's simple
1966 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1968 Changes in the register we use for saving registers to the stack:
1969 This is usually SP, but not always. Again, we deduce that if you
1970 copy SP into another register (and SP is not the CFA register),
1971 then the new register is the one we will be using for register
1972 saves. This also seems to work.
1974 Register saves: There's not much guesswork about this one; if
1975 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1976 register save, and the register used to calculate the destination
1977 had better be the one we think we're using for this purpose.
1978 It's also assumed that a copy from a call-saved register to another
1979 register is saving that register if RTX_FRAME_RELATED_P is set on
1980 that instruction. If the copy is from a call-saved register to
1981 the *same* register, that means that the register is now the same
1982 value as in the caller.
1984 Except: If the register being saved is the CFA register, and the
1985 offset is nonzero, we are saving the CFA, so we assume we have to
1986 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1987 the intent is to save the value of SP from the previous frame.
1989 In addition, if a register has previously been saved to a different
1992 Invariants / Summaries of Rules
1994 cfa current rule for calculating the CFA. It usually
1995 consists of a register and an offset.
1996 cfa_store register used by prologue code to save things to the stack
1997 cfa_store.offset is the offset from the value of
1998 cfa_store.reg to the actual CFA
1999 cfa_temp register holding an integral value. cfa_temp.offset
2000 stores the value, which will be used to adjust the
2001 stack pointer. cfa_temp is also used like cfa_store,
2002 to track stores to the stack via fp or a temp reg.
2004 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2005 with cfa.reg as the first operand changes the cfa.reg and its
2006 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2009 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2010 expression yielding a constant. This sets cfa_temp.reg
2011 and cfa_temp.offset.
2013 Rule 5: Create a new register cfa_store used to save items to the
2016 Rules 10-14: Save a register to the stack. Define offset as the
2017 difference of the original location and cfa_store's
2018 location (or cfa_temp's location if cfa_temp is used).
2020 Rules 16-20: If AND operation happens on sp in prologue, we assume
2021 stack is realigned. We will use a group of DW_OP_XXX
2022 expressions to represent the location of the stored
2023 register instead of CFA+offset.
2027 "{a,b}" indicates a choice of a xor b.
2028 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2031 (set <reg1> <reg2>:cfa.reg)
2032 effects: cfa.reg = <reg1>
2033 cfa.offset unchanged
2034 cfa_temp.reg = <reg1>
2035 cfa_temp.offset = cfa.offset
2038 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2039 {<const_int>,<reg>:cfa_temp.reg}))
2040 effects: cfa.reg = sp if fp used
2041 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2042 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2043 if cfa_store.reg==sp
2046 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2047 effects: cfa.reg = fp
2048 cfa_offset += +/- <const_int>
2051 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2052 constraints: <reg1> != fp
2054 effects: cfa.reg = <reg1>
2055 cfa_temp.reg = <reg1>
2056 cfa_temp.offset = cfa.offset
2059 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2060 constraints: <reg1> != fp
2062 effects: cfa_store.reg = <reg1>
2063 cfa_store.offset = cfa.offset - cfa_temp.offset
2066 (set <reg> <const_int>)
2067 effects: cfa_temp.reg = <reg>
2068 cfa_temp.offset = <const_int>
2071 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2072 effects: cfa_temp.reg = <reg1>
2073 cfa_temp.offset |= <const_int>
2076 (set <reg> (high <exp>))
2080 (set <reg> (lo_sum <exp> <const_int>))
2081 effects: cfa_temp.reg = <reg>
2082 cfa_temp.offset = <const_int>
2085 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2086 effects: cfa_store.offset -= <const_int>
2087 cfa.offset = cfa_store.offset if cfa.reg == sp
2089 cfa.base_offset = -cfa_store.offset
2092 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2093 effects: cfa_store.offset += -/+ mode_size(mem)
2094 cfa.offset = cfa_store.offset if cfa.reg == sp
2096 cfa.base_offset = -cfa_store.offset
2099 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2102 effects: cfa.reg = <reg1>
2103 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2106 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2107 effects: cfa.reg = <reg1>
2108 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2111 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2112 effects: cfa.reg = <reg1>
2113 cfa.base_offset = -cfa_temp.offset
2114 cfa_temp.offset -= mode_size(mem)
2117 (set <reg> {unspec, unspec_volatile})
2118 effects: target-dependent
2121 (set sp (and: sp <const_int>))
2122 constraints: cfa_store.reg == sp
2123 effects: current_fde.stack_realign = 1
2124 cfa_store.offset = 0
2125 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2128 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2129 effects: cfa_store.offset += -/+ mode_size(mem)
2132 (set (mem ({pre_inc, pre_dec} sp)) fp)
2133 constraints: fde->stack_realign == 1
2134 effects: cfa_store.offset = 0
2135 cfa.reg != HARD_FRAME_POINTER_REGNUM
2138 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2139 constraints: fde->stack_realign == 1
2141 && cfa.indirect == 0
2142 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2143 effects: Use DW_CFA_def_cfa_expression to define cfa
2144 cfa.reg == fde->drap_reg
2147 (set reg fde->drap_reg)
2148 constraints: fde->vdrap_reg == INVALID_REGNUM
2149 effects: fde->vdrap_reg = reg.
2150 (set mem fde->drap_reg)
2151 constraints: fde->drap_reg_saved == 1
2155 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2157 rtx src, dest, span;
2158 HOST_WIDE_INT offset;
2161 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2162 the PARALLEL independently. The first element is always processed if
2163 it is a SET. This is for backward compatibility. Other elements
2164 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2165 flag is set in them. */
2166 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2169 int limit = XVECLEN (expr, 0);
2172 /* PARALLELs have strict read-modify-write semantics, so we
2173 ought to evaluate every rvalue before changing any lvalue.
2174 It's cumbersome to do that in general, but there's an
2175 easy approximation that is enough for all current users:
2176 handle register saves before register assignments. */
2177 if (GET_CODE (expr) == PARALLEL)
2178 for (par_index = 0; par_index < limit; par_index++)
2180 elem = XVECEXP (expr, 0, par_index);
2181 if (GET_CODE (elem) == SET
2182 && MEM_P (SET_DEST (elem))
2183 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2184 dwarf2out_frame_debug_expr (elem, label);
2187 for (par_index = 0; par_index < limit; par_index++)
2189 elem = XVECEXP (expr, 0, par_index);
2190 if (GET_CODE (elem) == SET
2191 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2192 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2193 dwarf2out_frame_debug_expr (elem, label);
2194 else if (GET_CODE (elem) == SET
2196 && !RTX_FRAME_RELATED_P (elem))
2198 /* Stack adjustment combining might combine some post-prologue
2199 stack adjustment into a prologue stack adjustment. */
2200 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2203 dwarf2out_args_size_adjust (offset, label);
2209 gcc_assert (GET_CODE (expr) == SET);
2211 src = SET_SRC (expr);
2212 dest = SET_DEST (expr);
2216 rtx rsi = reg_saved_in (src);
2221 fde = current_fde ();
2225 && fde->drap_reg == REGNO (src)
2226 && (fde->drap_reg_saved
2230 /* If we are saving dynamic realign argument pointer to a
2231 register, the destination is virtual dynamic realign
2232 argument pointer. It may be used to access argument. */
2235 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2236 fde->vdrap_reg = REGNO (dest);
2241 switch (GET_CODE (dest))
2244 switch (GET_CODE (src))
2246 /* Setting FP from SP. */
2248 if (cfa.reg == (unsigned) REGNO (src))
2251 /* Update the CFA rule wrt SP or FP. Make sure src is
2252 relative to the current CFA register.
2254 We used to require that dest be either SP or FP, but the
2255 ARM copies SP to a temporary register, and from there to
2256 FP. So we just rely on the backends to only set
2257 RTX_FRAME_RELATED_P on appropriate insns. */
2258 cfa.reg = REGNO (dest);
2259 cfa_temp.reg = cfa.reg;
2260 cfa_temp.offset = cfa.offset;
2264 /* Saving a register in a register. */
2265 gcc_assert (!fixed_regs [REGNO (dest)]
2266 /* For the SPARC and its register window. */
2267 || (DWARF_FRAME_REGNUM (REGNO (src))
2268 == DWARF_FRAME_RETURN_COLUMN));
2270 /* After stack is aligned, we can only save SP in FP
2271 if drap register is used. In this case, we have
2272 to restore stack pointer with the CFA value and we
2273 don't generate this DWARF information. */
2275 && fde->stack_realign
2276 && REGNO (src) == STACK_POINTER_REGNUM)
2277 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2278 && fde->drap_reg != INVALID_REGNUM
2279 && cfa.reg != REGNO (src));
2281 queue_reg_save (label, src, dest, 0);
2288 if (dest == stack_pointer_rtx)
2292 switch (GET_CODE (XEXP (src, 1)))
2295 offset = INTVAL (XEXP (src, 1));
2298 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2300 offset = cfa_temp.offset;
2306 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2308 /* Restoring SP from FP in the epilogue. */
2309 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2310 cfa.reg = STACK_POINTER_REGNUM;
2312 else if (GET_CODE (src) == LO_SUM)
2313 /* Assume we've set the source reg of the LO_SUM from sp. */
2316 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2318 if (GET_CODE (src) != MINUS)
2320 if (cfa.reg == STACK_POINTER_REGNUM)
2321 cfa.offset += offset;
2322 if (cfa_store.reg == STACK_POINTER_REGNUM)
2323 cfa_store.offset += offset;
2325 else if (dest == hard_frame_pointer_rtx)
2328 /* Either setting the FP from an offset of the SP,
2329 or adjusting the FP */
2330 gcc_assert (frame_pointer_needed);
2332 gcc_assert (REG_P (XEXP (src, 0))
2333 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2334 && CONST_INT_P (XEXP (src, 1)));
2335 offset = INTVAL (XEXP (src, 1));
2336 if (GET_CODE (src) != MINUS)
2338 cfa.offset += offset;
2339 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2343 gcc_assert (GET_CODE (src) != MINUS);
2346 if (REG_P (XEXP (src, 0))
2347 && REGNO (XEXP (src, 0)) == cfa.reg
2348 && CONST_INT_P (XEXP (src, 1)))
2350 /* Setting a temporary CFA register that will be copied
2351 into the FP later on. */
2352 offset = - INTVAL (XEXP (src, 1));
2353 cfa.offset += offset;
2354 cfa.reg = REGNO (dest);
2355 /* Or used to save regs to the stack. */
2356 cfa_temp.reg = cfa.reg;
2357 cfa_temp.offset = cfa.offset;
2361 else if (REG_P (XEXP (src, 0))
2362 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2363 && XEXP (src, 1) == stack_pointer_rtx)
2365 /* Setting a scratch register that we will use instead
2366 of SP for saving registers to the stack. */
2367 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2368 cfa_store.reg = REGNO (dest);
2369 cfa_store.offset = cfa.offset - cfa_temp.offset;
2373 else if (GET_CODE (src) == LO_SUM
2374 && CONST_INT_P (XEXP (src, 1)))
2376 cfa_temp.reg = REGNO (dest);
2377 cfa_temp.offset = INTVAL (XEXP (src, 1));
2386 cfa_temp.reg = REGNO (dest);
2387 cfa_temp.offset = INTVAL (src);
2392 gcc_assert (REG_P (XEXP (src, 0))
2393 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2394 && CONST_INT_P (XEXP (src, 1)));
2396 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2397 cfa_temp.reg = REGNO (dest);
2398 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2401 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2402 which will fill in all of the bits. */
2409 case UNSPEC_VOLATILE:
2410 gcc_assert (targetm.dwarf_handle_frame_unspec);
2411 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2416 /* If this AND operation happens on stack pointer in prologue,
2417 we assume the stack is realigned and we extract the
2419 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2421 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2422 fde->stack_realign = 1;
2423 fde->stack_realignment = INTVAL (XEXP (src, 1));
2424 cfa_store.offset = 0;
2426 if (cfa.reg != STACK_POINTER_REGNUM
2427 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2428 fde->drap_reg = cfa.reg;
2436 def_cfa_1 (label, &cfa);
2441 /* Saving a register to the stack. Make sure dest is relative to the
2443 switch (GET_CODE (XEXP (dest, 0)))
2448 /* We can't handle variable size modifications. */
2449 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2451 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2453 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2454 && cfa_store.reg == STACK_POINTER_REGNUM);
2456 cfa_store.offset += offset;
2457 if (cfa.reg == STACK_POINTER_REGNUM)
2458 cfa.offset = cfa_store.offset;
2460 offset = -cfa_store.offset;
2466 offset = GET_MODE_SIZE (GET_MODE (dest));
2467 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2470 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2471 == STACK_POINTER_REGNUM)
2472 && cfa_store.reg == STACK_POINTER_REGNUM);
2474 cfa_store.offset += offset;
2476 /* Rule 18: If stack is aligned, we will use FP as a
2477 reference to represent the address of the stored
2480 && fde->stack_realign
2481 && src == hard_frame_pointer_rtx)
2483 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2484 cfa_store.offset = 0;
2487 if (cfa.reg == STACK_POINTER_REGNUM)
2488 cfa.offset = cfa_store.offset;
2490 offset = -cfa_store.offset;
2494 /* With an offset. */
2501 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2502 && REG_P (XEXP (XEXP (dest, 0), 0)));
2503 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2504 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2507 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2509 if (cfa_store.reg == (unsigned) regno)
2510 offset -= cfa_store.offset;
2513 gcc_assert (cfa_temp.reg == (unsigned) regno);
2514 offset -= cfa_temp.offset;
2520 /* Without an offset. */
2523 int regno = REGNO (XEXP (dest, 0));
2525 if (cfa_store.reg == (unsigned) regno)
2526 offset = -cfa_store.offset;
2529 gcc_assert (cfa_temp.reg == (unsigned) regno);
2530 offset = -cfa_temp.offset;
2537 gcc_assert (cfa_temp.reg
2538 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2539 offset = -cfa_temp.offset;
2540 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2548 /* If the source operand of this MEM operation is not a
2549 register, basically the source is return address. Here
2550 we only care how much stack grew and we don't save it. */
2554 if (REGNO (src) != STACK_POINTER_REGNUM
2555 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2556 && (unsigned) REGNO (src) == cfa.reg)
2558 /* We're storing the current CFA reg into the stack. */
2560 if (cfa.offset == 0)
2563 /* If stack is aligned, putting CFA reg into stack means
2564 we can no longer use reg + offset to represent CFA.
2565 Here we use DW_CFA_def_cfa_expression instead. The
2566 result of this expression equals to the original CFA
2569 && fde->stack_realign
2570 && cfa.indirect == 0
2571 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2573 dw_cfa_location cfa_exp;
2575 gcc_assert (fde->drap_reg == cfa.reg);
2577 cfa_exp.indirect = 1;
2578 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2579 cfa_exp.base_offset = offset;
2582 fde->drap_reg_saved = 1;
2584 def_cfa_1 (label, &cfa_exp);
2588 /* If the source register is exactly the CFA, assume
2589 we're saving SP like any other register; this happens
2591 def_cfa_1 (label, &cfa);
2592 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2597 /* Otherwise, we'll need to look in the stack to
2598 calculate the CFA. */
2599 rtx x = XEXP (dest, 0);
2603 gcc_assert (REG_P (x));
2605 cfa.reg = REGNO (x);
2606 cfa.base_offset = offset;
2608 def_cfa_1 (label, &cfa);
2613 def_cfa_1 (label, &cfa);
2615 span = targetm.dwarf_register_span (src);
2618 queue_reg_save (label, src, NULL_RTX, offset);
2621 /* We have a PARALLEL describing where the contents of SRC
2622 live. Queue register saves for each piece of the
2626 HOST_WIDE_INT span_offset = offset;
2628 gcc_assert (GET_CODE (span) == PARALLEL);
2630 limit = XVECLEN (span, 0);
2631 for (par_index = 0; par_index < limit; par_index++)
2633 rtx elem = XVECEXP (span, 0, par_index);
2635 queue_reg_save (label, elem, NULL_RTX, span_offset);
2636 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2647 /* Record call frame debugging information for INSN, which either
2648 sets SP or FP (adjusting how we calculate the frame address) or saves a
2649 register to the stack. If INSN is NULL_RTX, initialize our state.
2651 If AFTER_P is false, we're being called before the insn is emitted,
2652 otherwise after. Call instructions get invoked twice. */
2655 dwarf2out_frame_debug (rtx insn, bool after_p)
2659 bool handled_one = false;
2661 if (insn == NULL_RTX)
2665 /* Flush any queued register saves. */
2666 flush_queued_reg_saves ();
2668 /* Set up state for generating call frame debug info. */
2671 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2673 cfa.reg = STACK_POINTER_REGNUM;
2676 cfa_temp.offset = 0;
2678 for (i = 0; i < num_regs_saved_in_regs; i++)
2680 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2681 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2683 num_regs_saved_in_regs = 0;
2685 if (barrier_args_size)
2687 XDELETEVEC (barrier_args_size);
2688 barrier_args_size = NULL;
2693 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2694 flush_queued_reg_saves ();
2696 if (! RTX_FRAME_RELATED_P (insn))
2698 if (!ACCUMULATE_OUTGOING_ARGS)
2699 dwarf2out_stack_adjust (insn, after_p);
2703 label = dwarf2out_cfi_label (false);
2705 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2706 switch (REG_NOTE_KIND (note))
2708 case REG_FRAME_RELATED_EXPR:
2709 insn = XEXP (note, 0);
2712 case REG_CFA_DEF_CFA:
2713 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2717 case REG_CFA_ADJUST_CFA:
2722 if (GET_CODE (n) == PARALLEL)
2723 n = XVECEXP (n, 0, 0);
2725 dwarf2out_frame_debug_adjust_cfa (n, label);
2729 case REG_CFA_OFFSET:
2732 n = single_set (insn);
2733 dwarf2out_frame_debug_cfa_offset (n, label);
2737 case REG_CFA_REGISTER:
2742 if (GET_CODE (n) == PARALLEL)
2743 n = XVECEXP (n, 0, 0);
2745 dwarf2out_frame_debug_cfa_register (n, label);
2749 case REG_CFA_RESTORE:
2754 if (GET_CODE (n) == PARALLEL)
2755 n = XVECEXP (n, 0, 0);
2758 dwarf2out_frame_debug_cfa_restore (n, label);
2768 insn = PATTERN (insn);
2770 dwarf2out_frame_debug_expr (insn, label);
2773 /* Determine if we need to save and restore CFI information around this
2774 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2775 we do need to save/restore, then emit the save now, and insert a
2776 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2779 dwarf2out_begin_epilogue (rtx insn)
2781 bool saw_frp = false;
2784 /* Scan forward to the return insn, noticing if there are possible
2785 frame related insns. */
2786 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2791 /* Look for both regular and sibcalls to end the block. */
2792 if (returnjump_p (i))
2794 if (CALL_P (i) && SIBLING_CALL_P (i))
2797 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2800 rtx seq = PATTERN (i);
2802 if (returnjump_p (XVECEXP (seq, 0, 0)))
2804 if (CALL_P (XVECEXP (seq, 0, 0))
2805 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2808 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2809 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2813 if (RTX_FRAME_RELATED_P (i))
2817 /* If the port doesn't emit epilogue unwind info, we don't need a
2818 save/restore pair. */
2822 /* Otherwise, search forward to see if the return insn was the last
2823 basic block of the function. If so, we don't need save/restore. */
2824 gcc_assert (i != NULL);
2825 i = next_real_insn (i);
2829 /* Insert the restore before that next real insn in the stream, and before
2830 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2831 properly nested. This should be after any label or alignment. This
2832 will be pushed into the CFI stream by the function below. */
2835 rtx p = PREV_INSN (i);
2838 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2842 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2844 emit_cfa_remember = true;
2846 /* And emulate the state save. */
2847 gcc_assert (!cfa_remember.in_use);
2849 cfa_remember.in_use = 1;
2852 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2855 dwarf2out_frame_debug_restore_state (void)
2857 dw_cfi_ref cfi = new_cfi ();
2858 const char *label = dwarf2out_cfi_label (false);
2860 cfi->dw_cfi_opc = DW_CFA_restore_state;
2861 add_fde_cfi (label, cfi);
2863 gcc_assert (cfa_remember.in_use);
2865 cfa_remember.in_use = 0;
2870 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2871 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2872 (enum dwarf_call_frame_info cfi);
2874 static enum dw_cfi_oprnd_type
2875 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2880 case DW_CFA_GNU_window_save:
2881 case DW_CFA_remember_state:
2882 case DW_CFA_restore_state:
2883 return dw_cfi_oprnd_unused;
2885 case DW_CFA_set_loc:
2886 case DW_CFA_advance_loc1:
2887 case DW_CFA_advance_loc2:
2888 case DW_CFA_advance_loc4:
2889 case DW_CFA_MIPS_advance_loc8:
2890 return dw_cfi_oprnd_addr;
2893 case DW_CFA_offset_extended:
2894 case DW_CFA_def_cfa:
2895 case DW_CFA_offset_extended_sf:
2896 case DW_CFA_def_cfa_sf:
2897 case DW_CFA_restore:
2898 case DW_CFA_restore_extended:
2899 case DW_CFA_undefined:
2900 case DW_CFA_same_value:
2901 case DW_CFA_def_cfa_register:
2902 case DW_CFA_register:
2903 return dw_cfi_oprnd_reg_num;
2905 case DW_CFA_def_cfa_offset:
2906 case DW_CFA_GNU_args_size:
2907 case DW_CFA_def_cfa_offset_sf:
2908 return dw_cfi_oprnd_offset;
2910 case DW_CFA_def_cfa_expression:
2911 case DW_CFA_expression:
2912 return dw_cfi_oprnd_loc;
2919 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2920 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2921 (enum dwarf_call_frame_info cfi);
2923 static enum dw_cfi_oprnd_type
2924 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2928 case DW_CFA_def_cfa:
2929 case DW_CFA_def_cfa_sf:
2931 case DW_CFA_offset_extended_sf:
2932 case DW_CFA_offset_extended:
2933 return dw_cfi_oprnd_offset;
2935 case DW_CFA_register:
2936 return dw_cfi_oprnd_reg_num;
2939 return dw_cfi_oprnd_unused;
2943 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2945 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2946 switch to the data section instead, and write out a synthetic start label
2947 for collect2 the first time around. */
2950 switch_to_eh_frame_section (bool back)
2954 #ifdef EH_FRAME_SECTION_NAME
2955 if (eh_frame_section == 0)
2959 if (EH_TABLES_CAN_BE_READ_ONLY)
2965 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2967 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2969 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2971 flags = ((! flag_pic
2972 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2973 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2974 && (per_encoding & 0x70) != DW_EH_PE_absptr
2975 && (per_encoding & 0x70) != DW_EH_PE_aligned
2976 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2977 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2978 ? 0 : SECTION_WRITE);
2981 flags = SECTION_WRITE;
2982 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2986 if (eh_frame_section)
2987 switch_to_section (eh_frame_section);
2990 /* We have no special eh_frame section. Put the information in
2991 the data section and emit special labels to guide collect2. */
2992 switch_to_section (data_section);
2996 label = get_file_function_name ("F");
2997 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2998 targetm.asm_out.globalize_label (asm_out_file,
2999 IDENTIFIER_POINTER (label));
3000 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3005 /* Switch [BACK] to the eh or debug frame table section, depending on
3009 switch_to_frame_table_section (int for_eh, bool back)
3012 switch_to_eh_frame_section (back);
3015 if (!debug_frame_section)
3016 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3017 SECTION_DEBUG, NULL);
3018 switch_to_section (debug_frame_section);
3022 /* Output a Call Frame Information opcode and its operand(s). */
3025 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3030 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3031 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3032 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3033 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3034 ((unsigned HOST_WIDE_INT)
3035 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3036 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3038 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3039 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3040 "DW_CFA_offset, column 0x%lx", r);
3041 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3042 dw2_asm_output_data_uleb128 (off, NULL);
3044 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3046 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3047 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3048 "DW_CFA_restore, column 0x%lx", r);
3052 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3053 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3055 switch (cfi->dw_cfi_opc)
3057 case DW_CFA_set_loc:
3059 dw2_asm_output_encoded_addr_rtx (
3060 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3061 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3064 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3065 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3066 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3069 case DW_CFA_advance_loc1:
3070 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3071 fde->dw_fde_current_label, NULL);
3072 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3075 case DW_CFA_advance_loc2:
3076 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3077 fde->dw_fde_current_label, NULL);
3078 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3081 case DW_CFA_advance_loc4:
3082 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3083 fde->dw_fde_current_label, NULL);
3084 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3087 case DW_CFA_MIPS_advance_loc8:
3088 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3089 fde->dw_fde_current_label, NULL);
3090 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3093 case DW_CFA_offset_extended:
3094 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3095 dw2_asm_output_data_uleb128 (r, NULL);
3096 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3097 dw2_asm_output_data_uleb128 (off, NULL);
3100 case DW_CFA_def_cfa:
3101 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3102 dw2_asm_output_data_uleb128 (r, NULL);
3103 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3106 case DW_CFA_offset_extended_sf:
3107 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3108 dw2_asm_output_data_uleb128 (r, NULL);
3109 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3110 dw2_asm_output_data_sleb128 (off, NULL);
3113 case DW_CFA_def_cfa_sf:
3114 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3115 dw2_asm_output_data_uleb128 (r, NULL);
3116 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3117 dw2_asm_output_data_sleb128 (off, NULL);
3120 case DW_CFA_restore_extended:
3121 case DW_CFA_undefined:
3122 case DW_CFA_same_value:
3123 case DW_CFA_def_cfa_register:
3124 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3125 dw2_asm_output_data_uleb128 (r, NULL);
3128 case DW_CFA_register:
3129 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3130 dw2_asm_output_data_uleb128 (r, NULL);
3131 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3132 dw2_asm_output_data_uleb128 (r, NULL);
3135 case DW_CFA_def_cfa_offset:
3136 case DW_CFA_GNU_args_size:
3137 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3140 case DW_CFA_def_cfa_offset_sf:
3141 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3142 dw2_asm_output_data_sleb128 (off, NULL);
3145 case DW_CFA_GNU_window_save:
3148 case DW_CFA_def_cfa_expression:
3149 case DW_CFA_expression:
3150 output_cfa_loc (cfi);
3153 case DW_CFA_GNU_negative_offset_extended:
3154 /* Obsoleted by DW_CFA_offset_extended_sf. */
3163 /* Similar, but do it via assembler directives instead. */
3166 output_cfi_directive (dw_cfi_ref cfi)
3168 unsigned long r, r2;
3170 switch (cfi->dw_cfi_opc)
3172 case DW_CFA_advance_loc:
3173 case DW_CFA_advance_loc1:
3174 case DW_CFA_advance_loc2:
3175 case DW_CFA_advance_loc4:
3176 case DW_CFA_MIPS_advance_loc8:
3177 case DW_CFA_set_loc:
3178 /* Should only be created by add_fde_cfi in a code path not
3179 followed when emitting via directives. The assembler is
3180 going to take care of this for us. */
3184 case DW_CFA_offset_extended:
3185 case DW_CFA_offset_extended_sf:
3186 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3187 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3188 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3191 case DW_CFA_restore:
3192 case DW_CFA_restore_extended:
3193 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3194 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3197 case DW_CFA_undefined:
3198 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3199 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3202 case DW_CFA_same_value:
3203 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3204 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3207 case DW_CFA_def_cfa:
3208 case DW_CFA_def_cfa_sf:
3209 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3210 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3211 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3214 case DW_CFA_def_cfa_register:
3215 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3216 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3219 case DW_CFA_register:
3220 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3221 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3222 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3225 case DW_CFA_def_cfa_offset:
3226 case DW_CFA_def_cfa_offset_sf:
3227 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3228 HOST_WIDE_INT_PRINT_DEC"\n",
3229 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3232 case DW_CFA_remember_state:
3233 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3235 case DW_CFA_restore_state:
3236 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3239 case DW_CFA_GNU_args_size:
3240 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3241 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3243 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3244 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3245 fputc ('\n', asm_out_file);
3248 case DW_CFA_GNU_window_save:
3249 fprintf (asm_out_file, "\t.cfi_window_save\n");
3252 case DW_CFA_def_cfa_expression:
3253 case DW_CFA_expression:
3254 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3255 output_cfa_loc_raw (cfi);
3256 fputc ('\n', asm_out_file);
3264 DEF_VEC_P (dw_cfi_ref);
3265 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3267 /* Output CFIs to bring current FDE to the same state as after executing
3268 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3269 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3270 other arguments to pass to output_cfi. */
3273 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3275 struct dw_cfi_struct cfi_buf;
3277 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3278 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3279 unsigned int len, idx;
3281 for (;; cfi = cfi->dw_cfi_next)
3282 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3284 case DW_CFA_advance_loc:
3285 case DW_CFA_advance_loc1:
3286 case DW_CFA_advance_loc2:
3287 case DW_CFA_advance_loc4:
3288 case DW_CFA_MIPS_advance_loc8:
3289 case DW_CFA_set_loc:
3290 /* All advances should be ignored. */
3292 case DW_CFA_remember_state:
3294 dw_cfi_ref args_size = cfi_args_size;
3296 /* Skip everything between .cfi_remember_state and
3297 .cfi_restore_state. */
3298 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3299 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3301 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3304 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3311 cfi_args_size = args_size;
3315 case DW_CFA_GNU_args_size:
3316 cfi_args_size = cfi;
3318 case DW_CFA_GNU_window_save:
3321 case DW_CFA_offset_extended:
3322 case DW_CFA_offset_extended_sf:
3323 case DW_CFA_restore:
3324 case DW_CFA_restore_extended:
3325 case DW_CFA_undefined:
3326 case DW_CFA_same_value:
3327 case DW_CFA_register:
3328 case DW_CFA_val_offset:
3329 case DW_CFA_val_offset_sf:
3330 case DW_CFA_expression:
3331 case DW_CFA_val_expression:
3332 case DW_CFA_GNU_negative_offset_extended:
3333 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3334 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3335 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3336 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3338 case DW_CFA_def_cfa:
3339 case DW_CFA_def_cfa_sf:
3340 case DW_CFA_def_cfa_expression:
3342 cfi_cfa_offset = cfi;
3344 case DW_CFA_def_cfa_register:
3347 case DW_CFA_def_cfa_offset:
3348 case DW_CFA_def_cfa_offset_sf:
3349 cfi_cfa_offset = cfi;
3352 gcc_assert (cfi == NULL);
3354 len = VEC_length (dw_cfi_ref, regs);
3355 for (idx = 0; idx < len; idx++)
3357 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3359 && cfi2->dw_cfi_opc != DW_CFA_restore
3360 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3363 output_cfi_directive (cfi2);
3365 output_cfi (cfi2, fde, for_eh);
3368 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3370 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3372 switch (cfi_cfa_offset->dw_cfi_opc)
3374 case DW_CFA_def_cfa_offset:
3375 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3376 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3378 case DW_CFA_def_cfa_offset_sf:
3379 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3380 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3382 case DW_CFA_def_cfa:
3383 case DW_CFA_def_cfa_sf:
3384 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3385 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3392 else if (cfi_cfa_offset)
3393 cfi_cfa = cfi_cfa_offset;
3397 output_cfi_directive (cfi_cfa);
3399 output_cfi (cfi_cfa, fde, for_eh);
3402 cfi_cfa_offset = NULL;
3404 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3407 output_cfi_directive (cfi_args_size);
3409 output_cfi (cfi_args_size, fde, for_eh);
3411 cfi_args_size = NULL;
3414 VEC_free (dw_cfi_ref, heap, regs);
3417 else if (do_cfi_asm)
3418 output_cfi_directive (cfi);
3420 output_cfi (cfi, fde, for_eh);
3427 /* Output one FDE. */
3430 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3431 char *section_start_label, int fde_encoding, char *augmentation,
3432 bool any_lsda_needed, int lsda_encoding)
3434 const char *begin, *end;
3435 static unsigned int j;
3436 char l1[20], l2[20];
3439 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3441 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3443 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3444 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3445 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3446 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3447 " indicating 64-bit DWARF extension");
3448 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3450 ASM_OUTPUT_LABEL (asm_out_file, l1);
3453 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3455 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3456 debug_frame_section, "FDE CIE offset");
3458 if (!fde->dw_fde_switched_sections)
3460 begin = fde->dw_fde_begin;
3461 end = fde->dw_fde_end;
3465 /* For the first section, prefer dw_fde_begin over
3466 dw_fde_{hot,cold}_section_label, as the latter
3467 might be separated from the real start of the
3468 function by alignment padding. */
3470 begin = fde->dw_fde_begin;
3471 else if (fde->dw_fde_switched_cold_to_hot)
3472 begin = fde->dw_fde_hot_section_label;
3474 begin = fde->dw_fde_unlikely_section_label;
3475 if (second ^ fde->dw_fde_switched_cold_to_hot)
3476 end = fde->dw_fde_unlikely_section_end_label;
3478 end = fde->dw_fde_hot_section_end_label;
3483 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3484 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3485 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3486 "FDE initial location");
3487 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3488 end, begin, "FDE address range");
3492 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3493 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3496 if (augmentation[0])
3498 if (any_lsda_needed)
3500 int size = size_of_encoded_value (lsda_encoding);
3502 if (lsda_encoding == DW_EH_PE_aligned)
3504 int offset = ( 4 /* Length */
3505 + 4 /* CIE offset */
3506 + 2 * size_of_encoded_value (fde_encoding)
3507 + 1 /* Augmentation size */ );
3508 int pad = -offset & (PTR_SIZE - 1);
3511 gcc_assert (size_of_uleb128 (size) == 1);
3514 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3516 if (fde->uses_eh_lsda)
3518 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3519 fde->funcdef_number);
3520 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3521 gen_rtx_SYMBOL_REF (Pmode, l1),
3523 "Language Specific Data Area");
3527 if (lsda_encoding == DW_EH_PE_aligned)
3528 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3529 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3530 "Language Specific Data Area (none)");
3534 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3537 /* Loop through the Call Frame Instructions associated with
3539 fde->dw_fde_current_label = begin;
3540 if (!fde->dw_fde_switched_sections)
3541 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3542 output_cfi (cfi, fde, for_eh);
3545 if (fde->dw_fde_switch_cfi)
3546 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3548 output_cfi (cfi, fde, for_eh);
3549 if (cfi == fde->dw_fde_switch_cfi)
3555 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3557 if (fde->dw_fde_switch_cfi)
3559 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3560 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3561 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3562 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3564 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3565 output_cfi (cfi, fde, for_eh);
3568 /* If we are to emit a ref/link from function bodies to their frame tables,
3569 do it now. This is typically performed to make sure that tables
3570 associated with functions are dragged with them and not discarded in
3571 garbage collecting links. We need to do this on a per function basis to
3572 cope with -ffunction-sections. */
3574 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3575 /* Switch to the function section, emit the ref to the tables, and
3576 switch *back* into the table section. */
3577 switch_to_section (function_section (fde->decl));
3578 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3579 switch_to_frame_table_section (for_eh, true);
3582 /* Pad the FDE out to an address sized boundary. */
3583 ASM_OUTPUT_ALIGN (asm_out_file,
3584 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3585 ASM_OUTPUT_LABEL (asm_out_file, l2);
3590 /* Output the call frame information used to record information
3591 that relates to calculating the frame pointer, and records the
3592 location of saved registers. */
3595 output_call_frame_info (int for_eh)
3600 char l1[20], l2[20], section_start_label[20];
3601 bool any_lsda_needed = false;
3602 char augmentation[6];
3603 int augmentation_size;
3604 int fde_encoding = DW_EH_PE_absptr;
3605 int per_encoding = DW_EH_PE_absptr;
3606 int lsda_encoding = DW_EH_PE_absptr;
3608 rtx personality = NULL;
3611 /* Don't emit a CIE if there won't be any FDEs. */
3612 if (fde_table_in_use == 0)
3615 /* Nothing to do if the assembler's doing it all. */
3616 if (dwarf2out_do_cfi_asm ())
3619 /* If we make FDEs linkonce, we may have to emit an empty label for
3620 an FDE that wouldn't otherwise be emitted. We want to avoid
3621 having an FDE kept around when the function it refers to is
3622 discarded. Example where this matters: a primary function
3623 template in C++ requires EH information, but an explicit
3624 specialization doesn't. */
3625 if (TARGET_USES_WEAK_UNWIND_INFO
3626 && ! flag_asynchronous_unwind_tables
3629 for (i = 0; i < fde_table_in_use; i++)
3630 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3631 && !fde_table[i].uses_eh_lsda
3632 && ! DECL_WEAK (fde_table[i].decl))
3633 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3634 for_eh, /* empty */ 1);
3636 /* If we don't have any functions we'll want to unwind out of, don't
3637 emit any EH unwind information. Note that if exceptions aren't
3638 enabled, we won't have collected nothrow information, and if we
3639 asked for asynchronous tables, we always want this info. */
3642 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3644 for (i = 0; i < fde_table_in_use; i++)
3645 if (fde_table[i].uses_eh_lsda)
3646 any_eh_needed = any_lsda_needed = true;
3647 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3648 any_eh_needed = true;
3649 else if (! fde_table[i].nothrow
3650 && ! fde_table[i].all_throwers_are_sibcalls)
3651 any_eh_needed = true;
3653 if (! any_eh_needed)
3657 /* We're going to be generating comments, so turn on app. */
3661 /* Switch to the proper frame section, first time. */
3662 switch_to_frame_table_section (for_eh, false);
3664 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3665 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3667 /* Output the CIE. */
3668 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3669 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3670 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3671 dw2_asm_output_data (4, 0xffffffff,
3672 "Initial length escape value indicating 64-bit DWARF extension");
3673 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3674 "Length of Common Information Entry");
3675 ASM_OUTPUT_LABEL (asm_out_file, l1);
3677 /* Now that the CIE pointer is PC-relative for EH,
3678 use 0 to identify the CIE. */
3679 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3680 (for_eh ? 0 : DWARF_CIE_ID),
3681 "CIE Identifier Tag");
3683 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3684 use CIE version 1, unless that would produce incorrect results
3685 due to overflowing the return register column. */
3686 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3688 if (return_reg >= 256 || dwarf_version > 2)
3690 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3692 augmentation[0] = 0;
3693 augmentation_size = 0;
3695 personality = current_unit_personality;
3701 z Indicates that a uleb128 is present to size the
3702 augmentation section.
3703 L Indicates the encoding (and thus presence) of
3704 an LSDA pointer in the FDE augmentation.
3705 R Indicates a non-default pointer encoding for
3707 P Indicates the presence of an encoding + language
3708 personality routine in the CIE augmentation. */
3710 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3711 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3712 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3714 p = augmentation + 1;
3718 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3719 assemble_external_libcall (personality);
3721 if (any_lsda_needed)
3724 augmentation_size += 1;
3726 if (fde_encoding != DW_EH_PE_absptr)
3729 augmentation_size += 1;
3731 if (p > augmentation + 1)
3733 augmentation[0] = 'z';
3737 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3738 if (personality && per_encoding == DW_EH_PE_aligned)
3740 int offset = ( 4 /* Length */
3742 + 1 /* CIE version */
3743 + strlen (augmentation) + 1 /* Augmentation */
3744 + size_of_uleb128 (1) /* Code alignment */
3745 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3747 + 1 /* Augmentation size */
3748 + 1 /* Personality encoding */ );
3749 int pad = -offset & (PTR_SIZE - 1);
3751 augmentation_size += pad;
3753 /* Augmentations should be small, so there's scarce need to
3754 iterate for a solution. Die if we exceed one uleb128 byte. */
3755 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3759 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3760 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3761 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3762 "CIE Data Alignment Factor");
3764 if (dw_cie_version == 1)
3765 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3767 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3769 if (augmentation[0])
3771 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3774 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3775 eh_data_format_name (per_encoding));
3776 dw2_asm_output_encoded_addr_rtx (per_encoding,
3781 if (any_lsda_needed)
3782 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3783 eh_data_format_name (lsda_encoding));
3785 if (fde_encoding != DW_EH_PE_absptr)
3786 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3787 eh_data_format_name (fde_encoding));
3790 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3791 output_cfi (cfi, NULL, for_eh);
3793 /* Pad the CIE out to an address sized boundary. */
3794 ASM_OUTPUT_ALIGN (asm_out_file,
3795 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3796 ASM_OUTPUT_LABEL (asm_out_file, l2);
3798 /* Loop through all of the FDE's. */
3799 for (i = 0; i < fde_table_in_use; i++)
3802 fde = &fde_table[i];
3804 /* Don't emit EH unwind info for leaf functions that don't need it. */
3805 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3806 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3807 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3808 && !fde->uses_eh_lsda)
3811 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3812 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3813 augmentation, any_lsda_needed, lsda_encoding);
3816 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3817 dw2_asm_output_data (4, 0, "End of Table");
3818 #ifdef MIPS_DEBUGGING_INFO
3819 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3820 get a value of 0. Putting .align 0 after the label fixes it. */
3821 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3824 /* Turn off app to make assembly quicker. */
3829 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3832 dwarf2out_do_cfi_startproc (bool second)
3836 rtx personality = get_personality_function (current_function_decl);
3838 fprintf (asm_out_file, "\t.cfi_startproc\n");
3842 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3845 /* ??? The GAS support isn't entirely consistent. We have to
3846 handle indirect support ourselves, but PC-relative is done
3847 in the assembler. Further, the assembler can't handle any
3848 of the weirder relocation types. */
3849 if (enc & DW_EH_PE_indirect)
3850 ref = dw2_force_const_mem (ref, true);
3852 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3853 output_addr_const (asm_out_file, ref);
3854 fputc ('\n', asm_out_file);
3857 if (crtl->uses_eh_lsda)
3861 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3862 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3863 current_function_funcdef_no);
3864 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3865 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3867 if (enc & DW_EH_PE_indirect)
3868 ref = dw2_force_const_mem (ref, true);
3870 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3871 output_addr_const (asm_out_file, ref);
3872 fputc ('\n', asm_out_file);
3876 /* Output a marker (i.e. a label) for the beginning of a function, before
3880 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3881 const char *file ATTRIBUTE_UNUSED)
3883 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3888 current_function_func_begin_label = NULL;
3890 #ifdef TARGET_UNWIND_INFO
3891 /* ??? current_function_func_begin_label is also used by except.c
3892 for call-site information. We must emit this label if it might
3894 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3895 && ! dwarf2out_do_frame ())
3898 if (! dwarf2out_do_frame ())
3902 fnsec = function_section (current_function_decl);
3903 switch_to_section (fnsec);
3904 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3905 current_function_funcdef_no);
3906 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3907 current_function_funcdef_no);
3908 dup_label = xstrdup (label);
3909 current_function_func_begin_label = dup_label;
3911 #ifdef TARGET_UNWIND_INFO
3912 /* We can elide the fde allocation if we're not emitting debug info. */
3913 if (! dwarf2out_do_frame ())
3917 /* Expand the fde table if necessary. */
3918 if (fde_table_in_use == fde_table_allocated)
3920 fde_table_allocated += FDE_TABLE_INCREMENT;
3921 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3922 memset (fde_table + fde_table_in_use, 0,
3923 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3926 /* Record the FDE associated with this function. */
3927 current_funcdef_fde = fde_table_in_use;
3929 /* Add the new FDE at the end of the fde_table. */
3930 fde = &fde_table[fde_table_in_use++];
3931 fde->decl = current_function_decl;
3932 fde->dw_fde_begin = dup_label;
3933 fde->dw_fde_current_label = dup_label;
3934 fde->dw_fde_hot_section_label = NULL;
3935 fde->dw_fde_hot_section_end_label = NULL;
3936 fde->dw_fde_unlikely_section_label = NULL;
3937 fde->dw_fde_unlikely_section_end_label = NULL;
3938 fde->dw_fde_switched_sections = 0;
3939 fde->dw_fde_switched_cold_to_hot = 0;
3940 fde->dw_fde_end = NULL;
3941 fde->dw_fde_cfi = NULL;
3942 fde->dw_fde_switch_cfi = NULL;
3943 fde->funcdef_number = current_function_funcdef_no;
3944 fde->nothrow = crtl->nothrow;
3945 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3946 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3947 fde->drap_reg = INVALID_REGNUM;
3948 fde->vdrap_reg = INVALID_REGNUM;
3949 if (flag_reorder_blocks_and_partition)
3951 section *unlikelysec;
3952 if (first_function_block_is_cold)
3953 fde->in_std_section = 1;
3956 = (fnsec == text_section
3957 || (cold_text_section && fnsec == cold_text_section));
3958 unlikelysec = unlikely_text_section ();
3959 fde->cold_in_std_section
3960 = (unlikelysec == text_section
3961 || (cold_text_section && unlikelysec == cold_text_section));
3966 = (fnsec == text_section
3967 || (cold_text_section && fnsec == cold_text_section));
3968 fde->cold_in_std_section = 0;
3971 args_size = old_args_size = 0;
3973 /* We only want to output line number information for the genuine dwarf2
3974 prologue case, not the eh frame case. */
3975 #ifdef DWARF2_DEBUGGING_INFO
3977 dwarf2out_source_line (line, file, 0, true);
3980 if (dwarf2out_do_cfi_asm ())
3981 dwarf2out_do_cfi_startproc (false);
3984 rtx personality = get_personality_function (current_function_decl);
3985 if (!current_unit_personality)
3986 current_unit_personality = personality;
3988 /* We cannot keep a current personality per function as without CFI
3989 asm at the point where we emit the CFI data there is no current
3990 function anymore. */
3992 && current_unit_personality != personality)
3993 sorry ("Multiple EH personalities are supported only with assemblers "
3994 "supporting .cfi.personality directive.");
3998 /* Output a marker (i.e. a label) for the absolute end of the generated code
3999 for a function definition. This gets called *after* the epilogue code has
4003 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4004 const char *file ATTRIBUTE_UNUSED)
4007 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4009 #ifdef DWARF2_DEBUGGING_INFO
4010 last_var_location_insn = NULL_RTX;
4013 if (dwarf2out_do_cfi_asm ())
4014 fprintf (asm_out_file, "\t.cfi_endproc\n");
4016 /* Output a label to mark the endpoint of the code generated for this
4018 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4019 current_function_funcdef_no);
4020 ASM_OUTPUT_LABEL (asm_out_file, label);
4021 fde = current_fde ();
4022 gcc_assert (fde != NULL);
4023 fde->dw_fde_end = xstrdup (label);
4027 dwarf2out_frame_init (void)
4029 /* Allocate the initial hunk of the fde_table. */
4030 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
4031 fde_table_allocated = FDE_TABLE_INCREMENT;
4032 fde_table_in_use = 0;
4034 /* Generate the CFA instructions common to all FDE's. Do it now for the
4035 sake of lookup_cfa. */
4037 /* On entry, the Canonical Frame Address is at SP. */
4038 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4040 #ifdef DWARF2_UNWIND_INFO
4041 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4042 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4047 dwarf2out_frame_finish (void)
4049 /* Output call frame information. */
4050 if (DWARF2_FRAME_INFO)
4051 output_call_frame_info (0);
4053 #ifndef TARGET_UNWIND_INFO
4054 /* Output another copy for the unwinder. */
4055 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4056 output_call_frame_info (1);
4060 /* Note that the current function section is being used for code. */
4063 dwarf2out_note_section_used (void)
4065 section *sec = current_function_section ();
4066 if (sec == text_section)
4067 text_section_used = true;
4068 else if (sec == cold_text_section)
4069 cold_text_section_used = true;
4073 dwarf2out_switch_text_section (void)
4075 dw_fde_ref fde = current_fde ();
4077 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4079 fde->dw_fde_switched_sections = 1;
4080 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4082 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4083 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4084 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4085 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4086 have_multiple_function_sections = true;
4088 /* Reset the current label on switching text sections, so that we
4089 don't attempt to advance_loc4 between labels in different sections. */
4090 fde->dw_fde_current_label = NULL;
4092 /* There is no need to mark used sections when not debugging. */
4093 if (cold_text_section != NULL)
4094 dwarf2out_note_section_used ();
4096 if (dwarf2out_do_cfi_asm ())
4097 fprintf (asm_out_file, "\t.cfi_endproc\n");
4099 /* Now do the real section switch. */
4100 switch_to_section (current_function_section ());
4102 if (dwarf2out_do_cfi_asm ())
4104 dwarf2out_do_cfi_startproc (true);
4105 /* As this is a different FDE, insert all current CFI instructions
4107 output_cfis (fde->dw_fde_cfi, true, fde, true);
4111 dw_cfi_ref cfi = fde->dw_fde_cfi;
4113 cfi = fde->dw_fde_cfi;
4115 while (cfi->dw_cfi_next != NULL)
4116 cfi = cfi->dw_cfi_next;
4117 fde->dw_fde_switch_cfi = cfi;
4122 /* And now, the subset of the debugging information support code necessary
4123 for emitting location expressions. */
4125 /* Data about a single source file. */
4126 struct GTY(()) dwarf_file_data {
4127 const char * filename;
4131 typedef struct dw_val_struct *dw_val_ref;
4132 typedef struct die_struct *dw_die_ref;
4133 typedef const struct die_struct *const_dw_die_ref;
4134 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4135 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4137 typedef struct GTY(()) deferred_locations_struct
4141 } deferred_locations;
4143 DEF_VEC_O(deferred_locations);
4144 DEF_VEC_ALLOC_O(deferred_locations,gc);
4146 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4148 /* Each DIE may have a series of attribute/value pairs. Values
4149 can take on several forms. The forms that are used in this
4150 implementation are listed below. */
4155 dw_val_class_offset,
4157 dw_val_class_loc_list,
4158 dw_val_class_range_list,
4160 dw_val_class_unsigned_const,
4161 dw_val_class_const_double,
4164 dw_val_class_die_ref,
4165 dw_val_class_fde_ref,
4166 dw_val_class_lbl_id,
4167 dw_val_class_lineptr,
4169 dw_val_class_macptr,
4173 /* Describe a floating point constant value, or a vector constant value. */
4175 typedef struct GTY(()) dw_vec_struct {
4176 unsigned char * GTY((length ("%h.length"))) array;
4182 /* The dw_val_node describes an attribute's value, as it is
4183 represented internally. */
4185 typedef struct GTY(()) dw_val_struct {
4186 enum dw_val_class val_class;
4187 union dw_val_struct_union
4189 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4190 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4191 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4192 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4193 HOST_WIDE_INT GTY ((default)) val_int;
4194 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4195 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4196 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4197 struct dw_val_die_union
4201 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4202 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4203 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4204 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4205 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4206 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4208 GTY ((desc ("%1.val_class"))) v;
4212 /* Locations in memory are described using a sequence of stack machine
4215 typedef struct GTY(()) dw_loc_descr_struct {
4216 dw_loc_descr_ref dw_loc_next;
4217 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4218 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4219 from DW_OP_addr with a dtp-relative symbol relocation. */
4220 unsigned int dtprel : 1;
4222 dw_val_node dw_loc_oprnd1;
4223 dw_val_node dw_loc_oprnd2;
4227 /* Location lists are ranges + location descriptions for that range,
4228 so you can track variables that are in different places over
4229 their entire life. */
4230 typedef struct GTY(()) dw_loc_list_struct {
4231 dw_loc_list_ref dw_loc_next;
4232 const char *begin; /* Label for begin address of range */
4233 const char *end; /* Label for end address of range */
4234 char *ll_symbol; /* Label for beginning of location list.
4235 Only on head of list */
4236 const char *section; /* Section this loclist is relative to */
4237 dw_loc_descr_ref expr;
4240 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
4242 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4244 /* Convert a DWARF stack opcode into its string name. */
4247 dwarf_stack_op_name (unsigned int op)
4252 return "DW_OP_addr";
4254 return "DW_OP_deref";
4256 return "DW_OP_const1u";
4258 return "DW_OP_const1s";
4260 return "DW_OP_const2u";
4262 return "DW_OP_const2s";
4264 return "DW_OP_const4u";
4266 return "DW_OP_const4s";
4268 return "DW_OP_const8u";
4270 return "DW_OP_const8s";
4272 return "DW_OP_constu";
4274 return "DW_OP_consts";
4278 return "DW_OP_drop";
4280 return "DW_OP_over";
4282 return "DW_OP_pick";
4284 return "DW_OP_swap";
4288 return "DW_OP_xderef";
4296 return "DW_OP_minus";
4308 return "DW_OP_plus";
4309 case DW_OP_plus_uconst:
4310 return "DW_OP_plus_uconst";
4316 return "DW_OP_shra";
4334 return "DW_OP_skip";
4336 return "DW_OP_lit0";
4338 return "DW_OP_lit1";
4340 return "DW_OP_lit2";
4342 return "DW_OP_lit3";
4344 return "DW_OP_lit4";
4346 return "DW_OP_lit5";
4348 return "DW_OP_lit6";
4350 return "DW_OP_lit7";
4352 return "DW_OP_lit8";
4354 return "DW_OP_lit9";
4356 return "DW_OP_lit10";
4358 return "DW_OP_lit11";
4360 return "DW_OP_lit12";
4362 return "DW_OP_lit13";
4364 return "DW_OP_lit14";
4366 return "DW_OP_lit15";
4368 return "DW_OP_lit16";
4370 return "DW_OP_lit17";
4372 return "DW_OP_lit18";
4374 return "DW_OP_lit19";
4376 return "DW_OP_lit20";
4378 return "DW_OP_lit21";
4380 return "DW_OP_lit22";
4382 return "DW_OP_lit23";
4384 return "DW_OP_lit24";
4386 return "DW_OP_lit25";
4388 return "DW_OP_lit26";
4390 return "DW_OP_lit27";
4392 return "DW_OP_lit28";
4394 return "DW_OP_lit29";
4396 return "DW_OP_lit30";
4398 return "DW_OP_lit31";
4400 return "DW_OP_reg0";
4402 return "DW_OP_reg1";
4404 return "DW_OP_reg2";
4406 return "DW_OP_reg3";
4408 return "DW_OP_reg4";
4410 return "DW_OP_reg5";
4412 return "DW_OP_reg6";
4414 return "DW_OP_reg7";
4416 return "DW_OP_reg8";
4418 return "DW_OP_reg9";
4420 return "DW_OP_reg10";
4422 return "DW_OP_reg11";
4424 return "DW_OP_reg12";
4426 return "DW_OP_reg13";
4428 return "DW_OP_reg14";
4430 return "DW_OP_reg15";
4432 return "DW_OP_reg16";
4434 return "DW_OP_reg17";
4436 return "DW_OP_reg18";
4438 return "DW_OP_reg19";
4440 return "DW_OP_reg20";
4442 return "DW_OP_reg21";
4444 return "DW_OP_reg22";
4446 return "DW_OP_reg23";
4448 return "DW_OP_reg24";
4450 return "DW_OP_reg25";
4452 return "DW_OP_reg26";
4454 return "DW_OP_reg27";
4456 return "DW_OP_reg28";
4458 return "DW_OP_reg29";
4460 return "DW_OP_reg30";
4462 return "DW_OP_reg31";
4464 return "DW_OP_breg0";
4466 return "DW_OP_breg1";
4468 return "DW_OP_breg2";
4470 return "DW_OP_breg3";
4472 return "DW_OP_breg4";
4474 return "DW_OP_breg5";
4476 return "DW_OP_breg6";
4478 return "DW_OP_breg7";
4480 return "DW_OP_breg8";
4482 return "DW_OP_breg9";
4484 return "DW_OP_breg10";
4486 return "DW_OP_breg11";
4488 return "DW_OP_breg12";
4490 return "DW_OP_breg13";
4492 return "DW_OP_breg14";
4494 return "DW_OP_breg15";
4496 return "DW_OP_breg16";
4498 return "DW_OP_breg17";
4500 return "DW_OP_breg18";
4502 return "DW_OP_breg19";
4504 return "DW_OP_breg20";
4506 return "DW_OP_breg21";
4508 return "DW_OP_breg22";
4510 return "DW_OP_breg23";
4512 return "DW_OP_breg24";
4514 return "DW_OP_breg25";
4516 return "DW_OP_breg26";
4518 return "DW_OP_breg27";
4520 return "DW_OP_breg28";
4522 return "DW_OP_breg29";
4524 return "DW_OP_breg30";
4526 return "DW_OP_breg31";
4528 return "DW_OP_regx";
4530 return "DW_OP_fbreg";
4532 return "DW_OP_bregx";
4534 return "DW_OP_piece";
4535 case DW_OP_deref_size:
4536 return "DW_OP_deref_size";
4537 case DW_OP_xderef_size:
4538 return "DW_OP_xderef_size";
4542 case DW_OP_push_object_address:
4543 return "DW_OP_push_object_address";
4545 return "DW_OP_call2";
4547 return "DW_OP_call4";
4548 case DW_OP_call_ref:
4549 return "DW_OP_call_ref";
4550 case DW_OP_implicit_value:
4551 return "DW_OP_implicit_value";
4552 case DW_OP_stack_value:
4553 return "DW_OP_stack_value";
4554 case DW_OP_form_tls_address:
4555 return "DW_OP_form_tls_address";
4556 case DW_OP_call_frame_cfa:
4557 return "DW_OP_call_frame_cfa";
4558 case DW_OP_bit_piece:
4559 return "DW_OP_bit_piece";
4561 case DW_OP_GNU_push_tls_address:
4562 return "DW_OP_GNU_push_tls_address";
4563 case DW_OP_GNU_uninit:
4564 return "DW_OP_GNU_uninit";
4565 case DW_OP_GNU_encoded_addr:
4566 return "DW_OP_GNU_encoded_addr";
4569 return "OP_<unknown>";
4573 /* Return a pointer to a newly allocated location description. Location
4574 descriptions are simple expression terms that can be strung
4575 together to form more complicated location (address) descriptions. */
4577 static inline dw_loc_descr_ref
4578 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4579 unsigned HOST_WIDE_INT oprnd2)
4581 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4583 descr->dw_loc_opc = op;
4584 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4585 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4586 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4587 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4592 /* Return a pointer to a newly allocated location description for
4595 static inline dw_loc_descr_ref
4596 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4599 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4602 return new_loc_descr (DW_OP_bregx, reg, offset);
4605 /* Add a location description term to a location description expression. */
4608 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4610 dw_loc_descr_ref *d;
4612 /* Find the end of the chain. */
4613 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4619 /* Add a constant OFFSET to a location expression. */
4622 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4624 dw_loc_descr_ref loc;
4627 gcc_assert (*list_head != NULL);
4632 /* Find the end of the chain. */
4633 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4637 if (loc->dw_loc_opc == DW_OP_fbreg
4638 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4639 p = &loc->dw_loc_oprnd1.v.val_int;
4640 else if (loc->dw_loc_opc == DW_OP_bregx)
4641 p = &loc->dw_loc_oprnd2.v.val_int;
4643 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4644 offset. Don't optimize if an signed integer overflow would happen. */
4646 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4647 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4650 else if (offset > 0)
4651 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4655 loc->dw_loc_next = int_loc_descriptor (offset);
4656 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4660 #ifdef DWARF2_DEBUGGING_INFO
4661 /* Add a constant OFFSET to a location list. */
4664 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4667 for (d = list_head; d != NULL; d = d->dw_loc_next)
4668 loc_descr_plus_const (&d->expr, offset);
4672 /* Return the size of a location descriptor. */
4674 static unsigned long
4675 size_of_loc_descr (dw_loc_descr_ref loc)
4677 unsigned long size = 1;
4679 switch (loc->dw_loc_opc)
4682 size += DWARF2_ADDR_SIZE;
4701 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4704 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4709 case DW_OP_plus_uconst:
4710 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4748 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4751 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4754 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4757 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4758 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4761 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4763 case DW_OP_deref_size:
4764 case DW_OP_xderef_size:
4773 case DW_OP_call_ref:
4774 size += DWARF2_ADDR_SIZE;
4776 case DW_OP_implicit_value:
4777 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4778 + loc->dw_loc_oprnd1.v.val_unsigned;
4787 /* Return the size of a series of location descriptors. */
4789 static unsigned long
4790 size_of_locs (dw_loc_descr_ref loc)
4795 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4796 field, to avoid writing to a PCH file. */
4797 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4799 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4801 size += size_of_loc_descr (l);
4806 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4808 l->dw_loc_addr = size;
4809 size += size_of_loc_descr (l);
4815 #ifdef DWARF2_DEBUGGING_INFO
4816 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4819 /* Output location description stack opcode's operands (if any). */
4822 output_loc_operands (dw_loc_descr_ref loc)
4824 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4825 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4827 switch (loc->dw_loc_opc)
4829 #ifdef DWARF2_DEBUGGING_INFO
4832 dw2_asm_output_data (2, val1->v.val_int, NULL);
4836 dw2_asm_output_data (4, val1->v.val_int, NULL);
4840 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
4841 dw2_asm_output_data (8, val1->v.val_int, NULL);
4848 gcc_assert (val1->val_class == dw_val_class_loc);
4849 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4851 dw2_asm_output_data (2, offset, NULL);
4854 case DW_OP_implicit_value:
4855 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4856 switch (val2->val_class)
4858 case dw_val_class_const:
4859 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
4861 case dw_val_class_vec:
4863 unsigned int elt_size = val2->v.val_vec.elt_size;
4864 unsigned int len = val2->v.val_vec.length;
4868 if (elt_size > sizeof (HOST_WIDE_INT))
4873 for (i = 0, p = val2->v.val_vec.array;
4876 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
4877 "fp or vector constant word %u", i);
4880 case dw_val_class_const_double:
4882 unsigned HOST_WIDE_INT first, second;
4884 if (WORDS_BIG_ENDIAN)
4886 first = val2->v.val_double.high;
4887 second = val2->v.val_double.low;
4891 first = val2->v.val_double.low;
4892 second = val2->v.val_double.high;
4894 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4896 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4900 case dw_val_class_addr:
4901 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
4902 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
4917 case DW_OP_implicit_value:
4918 /* We currently don't make any attempt to make sure these are
4919 aligned properly like we do for the main unwind info, so
4920 don't support emitting things larger than a byte if we're
4921 only doing unwinding. */
4926 dw2_asm_output_data (1, val1->v.val_int, NULL);
4929 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4932 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4935 dw2_asm_output_data (1, val1->v.val_int, NULL);
4937 case DW_OP_plus_uconst:
4938 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4972 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4975 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4978 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4981 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4982 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4985 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4987 case DW_OP_deref_size:
4988 case DW_OP_xderef_size:
4989 dw2_asm_output_data (1, val1->v.val_int, NULL);
4995 if (targetm.asm_out.output_dwarf_dtprel)
4997 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5000 fputc ('\n', asm_out_file);
5007 #ifdef DWARF2_DEBUGGING_INFO
5008 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5016 /* Other codes have no operands. */
5021 /* Output a sequence of location operations. */
5024 output_loc_sequence (dw_loc_descr_ref loc)
5026 for (; loc != NULL; loc = loc->dw_loc_next)
5028 /* Output the opcode. */
5029 dw2_asm_output_data (1, loc->dw_loc_opc,
5030 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5032 /* Output the operand(s) (if any). */
5033 output_loc_operands (loc);
5037 /* Output location description stack opcode's operands (if any).
5038 The output is single bytes on a line, suitable for .cfi_escape. */
5041 output_loc_operands_raw (dw_loc_descr_ref loc)
5043 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5044 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5046 switch (loc->dw_loc_opc)
5049 case DW_OP_implicit_value:
5050 /* We cannot output addresses in .cfi_escape, only bytes. */
5056 case DW_OP_deref_size:
5057 case DW_OP_xderef_size:
5058 fputc (',', asm_out_file);
5059 dw2_asm_output_data_raw (1, val1->v.val_int);
5064 fputc (',', asm_out_file);
5065 dw2_asm_output_data_raw (2, val1->v.val_int);
5070 fputc (',', asm_out_file);
5071 dw2_asm_output_data_raw (4, val1->v.val_int);
5076 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5077 fputc (',', asm_out_file);
5078 dw2_asm_output_data_raw (8, val1->v.val_int);
5086 gcc_assert (val1->val_class == dw_val_class_loc);
5087 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5089 fputc (',', asm_out_file);
5090 dw2_asm_output_data_raw (2, offset);
5095 case DW_OP_plus_uconst:
5098 fputc (',', asm_out_file);
5099 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5136 fputc (',', asm_out_file);
5137 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5141 fputc (',', asm_out_file);
5142 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5143 fputc (',', asm_out_file);
5144 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5148 /* Other codes have no operands. */
5154 output_loc_sequence_raw (dw_loc_descr_ref loc)
5158 /* Output the opcode. */
5159 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
5160 output_loc_operands_raw (loc);
5162 if (!loc->dw_loc_next)
5164 loc = loc->dw_loc_next;
5166 fputc (',', asm_out_file);
5170 /* This routine will generate the correct assembly data for a location
5171 description based on a cfi entry with a complex address. */
5174 output_cfa_loc (dw_cfi_ref cfi)
5176 dw_loc_descr_ref loc;
5179 if (cfi->dw_cfi_opc == DW_CFA_expression)
5180 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
5182 /* Output the size of the block. */
5183 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5184 size = size_of_locs (loc);
5185 dw2_asm_output_data_uleb128 (size, NULL);
5187 /* Now output the operations themselves. */
5188 output_loc_sequence (loc);
5191 /* Similar, but used for .cfi_escape. */
5194 output_cfa_loc_raw (dw_cfi_ref cfi)
5196 dw_loc_descr_ref loc;
5199 if (cfi->dw_cfi_opc == DW_CFA_expression)
5200 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
5202 /* Output the size of the block. */
5203 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5204 size = size_of_locs (loc);
5205 dw2_asm_output_data_uleb128_raw (size);
5206 fputc (',', asm_out_file);
5208 /* Now output the operations themselves. */
5209 output_loc_sequence_raw (loc);
5212 /* This function builds a dwarf location descriptor sequence from a
5213 dw_cfa_location, adding the given OFFSET to the result of the
5216 static struct dw_loc_descr_struct *
5217 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5219 struct dw_loc_descr_struct *head, *tmp;
5221 offset += cfa->offset;
5225 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5226 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5227 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5228 add_loc_descr (&head, tmp);
5231 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5232 add_loc_descr (&head, tmp);
5236 head = new_reg_loc_descr (cfa->reg, offset);
5241 /* This function builds a dwarf location descriptor sequence for
5242 the address at OFFSET from the CFA when stack is aligned to
5245 static struct dw_loc_descr_struct *
5246 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5248 struct dw_loc_descr_struct *head;
5249 unsigned int dwarf_fp
5250 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5252 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5253 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5255 head = new_reg_loc_descr (dwarf_fp, 0);
5256 add_loc_descr (&head, int_loc_descriptor (alignment));
5257 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5258 loc_descr_plus_const (&head, offset);
5261 head = new_reg_loc_descr (dwarf_fp, offset);
5265 /* This function fills in aa dw_cfa_location structure from a dwarf location
5266 descriptor sequence. */
5269 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5271 struct dw_loc_descr_struct *ptr;
5273 cfa->base_offset = 0;
5277 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5279 enum dwarf_location_atom op = ptr->dw_loc_opc;
5315 cfa->reg = op - DW_OP_reg0;
5318 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5352 cfa->reg = op - DW_OP_breg0;
5353 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5356 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5357 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5362 case DW_OP_plus_uconst:
5363 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5366 internal_error ("DW_LOC_OP %s not implemented",
5367 dwarf_stack_op_name (ptr->dw_loc_opc));
5371 #endif /* .debug_frame support */
5373 /* And now, the support for symbolic debugging information. */
5374 #ifdef DWARF2_DEBUGGING_INFO
5376 /* .debug_str support. */
5377 static int output_indirect_string (void **, void *);
5379 static void dwarf2out_init (const char *);
5380 static void dwarf2out_finish (const char *);
5381 static void dwarf2out_define (unsigned int, const char *);
5382 static void dwarf2out_undef (unsigned int, const char *);
5383 static void dwarf2out_start_source_file (unsigned, const char *);
5384 static void dwarf2out_end_source_file (unsigned);
5385 static void dwarf2out_begin_block (unsigned, unsigned);
5386 static void dwarf2out_end_block (unsigned, unsigned);
5387 static bool dwarf2out_ignore_block (const_tree);
5388 static void dwarf2out_global_decl (tree);
5389 static void dwarf2out_type_decl (tree, int);
5390 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5391 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5393 static void dwarf2out_abstract_function (tree);
5394 static void dwarf2out_var_location (rtx);
5395 static void dwarf2out_begin_function (tree);
5396 static void dwarf2out_set_name (tree, tree);
5398 /* The debug hooks structure. */
5400 const struct gcc_debug_hooks dwarf2_debug_hooks =
5406 dwarf2out_start_source_file,
5407 dwarf2out_end_source_file,
5408 dwarf2out_begin_block,
5409 dwarf2out_end_block,
5410 dwarf2out_ignore_block,
5411 dwarf2out_source_line,
5412 dwarf2out_begin_prologue,
5413 debug_nothing_int_charstar, /* end_prologue */
5414 dwarf2out_end_epilogue,
5415 dwarf2out_begin_function,
5416 debug_nothing_int, /* end_function */
5417 dwarf2out_decl, /* function_decl */
5418 dwarf2out_global_decl,
5419 dwarf2out_type_decl, /* type_decl */
5420 dwarf2out_imported_module_or_decl,
5421 debug_nothing_tree, /* deferred_inline_function */
5422 /* The DWARF 2 backend tries to reduce debugging bloat by not
5423 emitting the abstract description of inline functions until
5424 something tries to reference them. */
5425 dwarf2out_abstract_function, /* outlining_inline_function */
5426 debug_nothing_rtx, /* label */
5427 debug_nothing_int, /* handle_pch */
5428 dwarf2out_var_location,
5429 dwarf2out_switch_text_section,
5431 1 /* start_end_main_source_file */
5435 /* NOTE: In the comments in this file, many references are made to
5436 "Debugging Information Entries". This term is abbreviated as `DIE'
5437 throughout the remainder of this file. */
5439 /* An internal representation of the DWARF output is built, and then
5440 walked to generate the DWARF debugging info. The walk of the internal
5441 representation is done after the entire program has been compiled.
5442 The types below are used to describe the internal representation. */
5444 /* Various DIE's use offsets relative to the beginning of the
5445 .debug_info section to refer to each other. */
5447 typedef long int dw_offset;
5449 /* Define typedefs here to avoid circular dependencies. */
5451 typedef struct dw_attr_struct *dw_attr_ref;
5452 typedef struct dw_line_info_struct *dw_line_info_ref;
5453 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5454 typedef struct pubname_struct *pubname_ref;
5455 typedef struct dw_ranges_struct *dw_ranges_ref;
5456 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5458 /* Each entry in the line_info_table maintains the file and
5459 line number associated with the label generated for that
5460 entry. The label gives the PC value associated with
5461 the line number entry. */
5463 typedef struct GTY(()) dw_line_info_struct {
5464 unsigned long dw_file_num;
5465 unsigned long dw_line_num;
5469 /* Line information for functions in separate sections; each one gets its
5471 typedef struct GTY(()) dw_separate_line_info_struct {
5472 unsigned long dw_file_num;
5473 unsigned long dw_line_num;
5474 unsigned long function;
5476 dw_separate_line_info_entry;
5478 /* Each DIE attribute has a field specifying the attribute kind,
5479 a link to the next attribute in the chain, and an attribute value.
5480 Attributes are typically linked below the DIE they modify. */
5482 typedef struct GTY(()) dw_attr_struct {
5483 enum dwarf_attribute dw_attr;
5484 dw_val_node dw_attr_val;
5488 DEF_VEC_O(dw_attr_node);
5489 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5491 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5492 The children of each node form a circular list linked by
5493 die_sib. die_child points to the node *before* the "first" child node. */
5495 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5496 enum dwarf_tag die_tag;
5498 VEC(dw_attr_node,gc) * die_attr;
5499 dw_die_ref die_parent;
5500 dw_die_ref die_child;
5502 dw_die_ref die_definition; /* ref from a specification to its definition */
5503 dw_offset die_offset;
5504 unsigned long die_abbrev;
5506 /* Die is used and must not be pruned as unused. */
5507 int die_perennial_p;
5508 unsigned int decl_id;
5512 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5513 #define FOR_EACH_CHILD(die, c, expr) do { \
5514 c = die->die_child; \
5518 } while (c != die->die_child); \
5521 /* The pubname structure */
5523 typedef struct GTY(()) pubname_struct {
5529 DEF_VEC_O(pubname_entry);
5530 DEF_VEC_ALLOC_O(pubname_entry, gc);
5532 struct GTY(()) dw_ranges_struct {
5533 /* If this is positive, it's a block number, otherwise it's a
5534 bitwise-negated index into dw_ranges_by_label. */
5538 struct GTY(()) dw_ranges_by_label_struct {
5543 /* The limbo die list structure. */
5544 typedef struct GTY(()) limbo_die_struct {
5547 struct limbo_die_struct *next;
5551 /* How to start an assembler comment. */
5552 #ifndef ASM_COMMENT_START
5553 #define ASM_COMMENT_START ";#"
5556 /* Define a macro which returns nonzero for a TYPE_DECL which was
5557 implicitly generated for a tagged type.
5559 Note that unlike the gcc front end (which generates a NULL named
5560 TYPE_DECL node for each complete tagged type, each array type, and
5561 each function type node created) the g++ front end generates a
5562 _named_ TYPE_DECL node for each tagged type node created.
5563 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5564 generate a DW_TAG_typedef DIE for them. */
5566 #define TYPE_DECL_IS_STUB(decl) \
5567 (DECL_NAME (decl) == NULL_TREE \
5568 || (DECL_ARTIFICIAL (decl) \
5569 && is_tagged_type (TREE_TYPE (decl)) \
5570 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5571 /* This is necessary for stub decls that \
5572 appear in nested inline functions. */ \
5573 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5574 && (decl_ultimate_origin (decl) \
5575 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5577 /* Information concerning the compilation unit's programming
5578 language, and compiler version. */
5580 /* Fixed size portion of the DWARF compilation unit header. */
5581 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5582 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5584 /* Fixed size portion of public names info. */
5585 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5587 /* Fixed size portion of the address range info. */
5588 #define DWARF_ARANGES_HEADER_SIZE \
5589 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5590 DWARF2_ADDR_SIZE * 2) \
5591 - DWARF_INITIAL_LENGTH_SIZE)
5593 /* Size of padding portion in the address range info. It must be
5594 aligned to twice the pointer size. */
5595 #define DWARF_ARANGES_PAD_SIZE \
5596 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5597 DWARF2_ADDR_SIZE * 2) \
5598 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5600 /* Use assembler line directives if available. */
5601 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5602 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5603 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5605 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5609 /* Minimum line offset in a special line info. opcode.
5610 This value was chosen to give a reasonable range of values. */
5611 #define DWARF_LINE_BASE -10
5613 /* First special line opcode - leave room for the standard opcodes. */
5614 #define DWARF_LINE_OPCODE_BASE 10
5616 /* Range of line offsets in a special line info. opcode. */
5617 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5619 /* Flag that indicates the initial value of the is_stmt_start flag.
5620 In the present implementation, we do not mark any lines as
5621 the beginning of a source statement, because that information
5622 is not made available by the GCC front-end. */
5623 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5625 #ifdef DWARF2_DEBUGGING_INFO
5626 /* This location is used by calc_die_sizes() to keep track
5627 the offset of each DIE within the .debug_info section. */
5628 static unsigned long next_die_offset;
5631 /* Record the root of the DIE's built for the current compilation unit. */
5632 static GTY(()) dw_die_ref comp_unit_die;
5634 /* A list of DIEs with a NULL parent waiting to be relocated. */
5635 static GTY(()) limbo_die_node *limbo_die_list;
5637 /* A list of DIEs for which we may have to generate
5638 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5640 static GTY(()) limbo_die_node *deferred_asm_name;
5642 /* Filenames referenced by this compilation unit. */
5643 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5645 /* A hash table of references to DIE's that describe declarations.
5646 The key is a DECL_UID() which is a unique number identifying each decl. */
5647 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5649 /* A hash table of references to DIE's that describe COMMON blocks.
5650 The key is DECL_UID() ^ die_parent. */
5651 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5653 typedef struct GTY(()) die_arg_entry_struct {
5658 DEF_VEC_O(die_arg_entry);
5659 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5661 /* Node of the variable location list. */
5662 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5663 rtx GTY (()) var_loc_note;
5664 const char * GTY (()) label;
5665 const char * GTY (()) section_label;
5666 struct var_loc_node * GTY (()) next;
5669 /* Variable location list. */
5670 struct GTY (()) var_loc_list_def {
5671 struct var_loc_node * GTY (()) first;
5673 /* Do not mark the last element of the chained list because
5674 it is marked through the chain. */
5675 struct var_loc_node * GTY ((skip ("%h"))) last;
5677 /* DECL_UID of the variable decl. */
5678 unsigned int decl_id;
5680 typedef struct var_loc_list_def var_loc_list;
5683 /* Table of decl location linked lists. */
5684 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5686 /* A pointer to the base of a list of references to DIE's that
5687 are uniquely identified by their tag, presence/absence of
5688 children DIE's, and list of attribute/value pairs. */
5689 static GTY((length ("abbrev_die_table_allocated")))
5690 dw_die_ref *abbrev_die_table;
5692 /* Number of elements currently allocated for abbrev_die_table. */
5693 static GTY(()) unsigned abbrev_die_table_allocated;
5695 /* Number of elements in type_die_table currently in use. */
5696 static GTY(()) unsigned abbrev_die_table_in_use;
5698 /* Size (in elements) of increments by which we may expand the
5699 abbrev_die_table. */
5700 #define ABBREV_DIE_TABLE_INCREMENT 256
5702 /* A pointer to the base of a table that contains line information
5703 for each source code line in .text in the compilation unit. */
5704 static GTY((length ("line_info_table_allocated")))
5705 dw_line_info_ref line_info_table;
5707 /* Number of elements currently allocated for line_info_table. */
5708 static GTY(()) unsigned line_info_table_allocated;
5710 /* Number of elements in line_info_table currently in use. */
5711 static GTY(()) unsigned line_info_table_in_use;
5713 /* A pointer to the base of a table that contains line information
5714 for each source code line outside of .text in the compilation unit. */
5715 static GTY ((length ("separate_line_info_table_allocated")))
5716 dw_separate_line_info_ref separate_line_info_table;
5718 /* Number of elements currently allocated for separate_line_info_table. */
5719 static GTY(()) unsigned separate_line_info_table_allocated;
5721 /* Number of elements in separate_line_info_table currently in use. */
5722 static GTY(()) unsigned separate_line_info_table_in_use;
5724 /* Size (in elements) of increments by which we may expand the
5726 #define LINE_INFO_TABLE_INCREMENT 1024
5728 /* A pointer to the base of a table that contains a list of publicly
5729 accessible names. */
5730 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5732 /* A pointer to the base of a table that contains a list of publicly
5733 accessible types. */
5734 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5736 /* Array of dies for which we should generate .debug_arange info. */
5737 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5739 /* Number of elements currently allocated for arange_table. */
5740 static GTY(()) unsigned arange_table_allocated;
5742 /* Number of elements in arange_table currently in use. */
5743 static GTY(()) unsigned arange_table_in_use;
5745 /* Size (in elements) of increments by which we may expand the
5747 #define ARANGE_TABLE_INCREMENT 64
5749 /* Array of dies for which we should generate .debug_ranges info. */
5750 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5752 /* Number of elements currently allocated for ranges_table. */
5753 static GTY(()) unsigned ranges_table_allocated;
5755 /* Number of elements in ranges_table currently in use. */
5756 static GTY(()) unsigned ranges_table_in_use;
5758 /* Array of pairs of labels referenced in ranges_table. */
5759 static GTY ((length ("ranges_by_label_allocated")))
5760 dw_ranges_by_label_ref ranges_by_label;
5762 /* Number of elements currently allocated for ranges_by_label. */
5763 static GTY(()) unsigned ranges_by_label_allocated;
5765 /* Number of elements in ranges_by_label currently in use. */
5766 static GTY(()) unsigned ranges_by_label_in_use;
5768 /* Size (in elements) of increments by which we may expand the
5770 #define RANGES_TABLE_INCREMENT 64
5772 /* Whether we have location lists that need outputting */
5773 static GTY(()) bool have_location_lists;
5775 /* Unique label counter. */
5776 static GTY(()) unsigned int loclabel_num;
5778 #ifdef DWARF2_DEBUGGING_INFO
5779 /* Record whether the function being analyzed contains inlined functions. */
5780 static int current_function_has_inlines;
5782 #if 0 && defined (MIPS_DEBUGGING_INFO)
5783 static int comp_unit_has_inlines;
5786 /* The last file entry emitted by maybe_emit_file(). */
5787 static GTY(()) struct dwarf_file_data * last_emitted_file;
5789 /* Number of internal labels generated by gen_internal_sym(). */
5790 static GTY(()) int label_num;
5792 /* Cached result of previous call to lookup_filename. */
5793 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5795 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
5797 #ifdef DWARF2_DEBUGGING_INFO
5799 /* Offset from the "steady-state frame pointer" to the frame base,
5800 within the current function. */
5801 static HOST_WIDE_INT frame_pointer_fb_offset;
5803 /* Forward declarations for functions defined in this file. */
5805 static int is_pseudo_reg (const_rtx);
5806 static tree type_main_variant (tree);
5807 static int is_tagged_type (const_tree);
5808 static const char *dwarf_tag_name (unsigned);
5809 static const char *dwarf_attr_name (unsigned);
5810 static const char *dwarf_form_name (unsigned);
5811 static tree decl_ultimate_origin (const_tree);
5812 static tree decl_class_context (tree);
5813 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5814 static inline enum dw_val_class AT_class (dw_attr_ref);
5815 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5816 static inline unsigned AT_flag (dw_attr_ref);
5817 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5818 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5819 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5820 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5821 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
5822 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
5823 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5824 unsigned int, unsigned char *);
5825 static hashval_t debug_str_do_hash (const void *);
5826 static int debug_str_eq (const void *, const void *);
5827 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5828 static inline const char *AT_string (dw_attr_ref);
5829 static enum dwarf_form AT_string_form (dw_attr_ref);
5830 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5831 static void add_AT_specification (dw_die_ref, dw_die_ref);
5832 static inline dw_die_ref AT_ref (dw_attr_ref);
5833 static inline int AT_ref_external (dw_attr_ref);
5834 static inline void set_AT_ref_external (dw_attr_ref, int);
5835 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5836 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5837 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5838 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5840 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5841 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5842 static inline rtx AT_addr (dw_attr_ref);
5843 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5844 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5845 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5846 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5847 unsigned HOST_WIDE_INT);
5848 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5850 static inline const char *AT_lbl (dw_attr_ref);
5851 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5852 static const char *get_AT_low_pc (dw_die_ref);
5853 static const char *get_AT_hi_pc (dw_die_ref);
5854 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5855 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5856 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5857 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5858 static bool is_c_family (void);
5859 static bool is_cxx (void);
5860 static bool is_java (void);
5861 static bool is_fortran (void);
5862 static bool is_ada (void);
5863 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5864 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5865 static void add_child_die (dw_die_ref, dw_die_ref);
5866 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5867 static dw_die_ref lookup_type_die (tree);
5868 static void equate_type_number_to_die (tree, dw_die_ref);
5869 static hashval_t decl_die_table_hash (const void *);
5870 static int decl_die_table_eq (const void *, const void *);
5871 static dw_die_ref lookup_decl_die (tree);
5872 static hashval_t common_block_die_table_hash (const void *);
5873 static int common_block_die_table_eq (const void *, const void *);
5874 static hashval_t decl_loc_table_hash (const void *);
5875 static int decl_loc_table_eq (const void *, const void *);
5876 static var_loc_list *lookup_decl_loc (const_tree);
5877 static void equate_decl_number_to_die (tree, dw_die_ref);
5878 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5879 static void print_spaces (FILE *);
5880 static void print_die (dw_die_ref, FILE *);
5881 static void print_dwarf_line_table (FILE *);
5882 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5883 static dw_die_ref pop_compile_unit (dw_die_ref);
5884 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5885 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5886 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5887 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5888 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5889 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5890 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5891 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5892 static void compute_section_prefix (dw_die_ref);
5893 static int is_type_die (dw_die_ref);
5894 static int is_comdat_die (dw_die_ref);
5895 static int is_symbol_die (dw_die_ref);
5896 static void assign_symbol_names (dw_die_ref);
5897 static void break_out_includes (dw_die_ref);
5898 static hashval_t htab_cu_hash (const void *);
5899 static int htab_cu_eq (const void *, const void *);
5900 static void htab_cu_del (void *);
5901 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5902 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5903 static void add_sibling_attributes (dw_die_ref);
5904 static void build_abbrev_table (dw_die_ref);
5905 static void output_location_lists (dw_die_ref);
5906 static int constant_size (unsigned HOST_WIDE_INT);
5907 static unsigned long size_of_die (dw_die_ref);
5908 static void calc_die_sizes (dw_die_ref);
5909 static void mark_dies (dw_die_ref);
5910 static void unmark_dies (dw_die_ref);
5911 static void unmark_all_dies (dw_die_ref);
5912 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5913 static unsigned long size_of_aranges (void);
5914 static enum dwarf_form value_format (dw_attr_ref);
5915 static void output_value_format (dw_attr_ref);
5916 static void output_abbrev_section (void);
5917 static void output_die_symbol (dw_die_ref);
5918 static void output_die (dw_die_ref);
5919 static void output_compilation_unit_header (void);
5920 static void output_comp_unit (dw_die_ref, int);
5921 static const char *dwarf2_name (tree, int);
5922 static void add_pubname (tree, dw_die_ref);
5923 static void add_pubname_string (const char *, dw_die_ref);
5924 static void add_pubtype (tree, dw_die_ref);
5925 static void output_pubnames (VEC (pubname_entry,gc) *);
5926 static void add_arange (tree, dw_die_ref);
5927 static void output_aranges (void);
5928 static unsigned int add_ranges_num (int);
5929 static unsigned int add_ranges (const_tree);
5930 static unsigned int add_ranges_by_labels (const char *, const char *);
5931 static void output_ranges (void);
5932 static void output_line_info (void);
5933 static void output_file_names (void);
5934 static dw_die_ref base_type_die (tree);
5935 static int is_base_type (tree);
5936 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5937 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5938 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
5939 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
5940 static int type_is_enum (const_tree);
5941 static unsigned int dbx_reg_number (const_rtx);
5942 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5943 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5944 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5945 enum var_init_status);
5946 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5947 enum var_init_status);
5948 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5949 enum var_init_status);
5950 static int is_based_loc (const_rtx);
5951 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5952 enum var_init_status);
5953 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5954 enum var_init_status);
5955 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
5956 enum var_init_status);
5957 static dw_loc_list_ref loc_list_from_tree (tree, int);
5958 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
5959 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5960 static tree field_type (const_tree);
5961 static unsigned int simple_type_align_in_bits (const_tree);
5962 static unsigned int simple_decl_align_in_bits (const_tree);
5963 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5964 static HOST_WIDE_INT field_byte_offset (const_tree);
5965 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5967 static void add_data_member_location_attribute (dw_die_ref, tree);
5968 static bool add_const_value_attribute (dw_die_ref, rtx);
5969 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5970 static void insert_float (const_rtx, unsigned char *);
5971 static rtx rtl_for_decl_location (tree);
5972 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
5973 enum dwarf_attribute);
5974 static bool tree_add_const_value_attribute (dw_die_ref, tree);
5975 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
5976 static void add_name_attribute (dw_die_ref, const char *);
5977 static void add_comp_dir_attribute (dw_die_ref);
5978 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5979 static void add_subscript_info (dw_die_ref, tree, bool);
5980 static void add_byte_size_attribute (dw_die_ref, tree);
5981 static void add_bit_offset_attribute (dw_die_ref, tree);
5982 static void add_bit_size_attribute (dw_die_ref, tree);
5983 static void add_prototyped_attribute (dw_die_ref, tree);
5984 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5985 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5986 static void add_src_coords_attributes (dw_die_ref, tree);
5987 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5988 static void push_decl_scope (tree);
5989 static void pop_decl_scope (void);
5990 static dw_die_ref scope_die_for (tree, dw_die_ref);
5991 static inline int local_scope_p (dw_die_ref);
5992 static inline int class_scope_p (dw_die_ref);
5993 static inline int class_or_namespace_scope_p (dw_die_ref);
5994 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5995 static void add_calling_convention_attribute (dw_die_ref, tree);
5996 static const char *type_tag (const_tree);
5997 static tree member_declared_type (const_tree);
5999 static const char *decl_start_label (tree);
6001 static void gen_array_type_die (tree, dw_die_ref);
6002 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6004 static void gen_entry_point_die (tree, dw_die_ref);
6006 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6007 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6008 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6009 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6010 static void gen_formal_types_die (tree, dw_die_ref);
6011 static void gen_subprogram_die (tree, dw_die_ref);
6012 static void gen_variable_die (tree, tree, dw_die_ref);
6013 static void gen_const_die (tree, dw_die_ref);
6014 static void gen_label_die (tree, dw_die_ref);
6015 static void gen_lexical_block_die (tree, dw_die_ref, int);
6016 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6017 static void gen_field_die (tree, dw_die_ref);
6018 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6019 static dw_die_ref gen_compile_unit_die (const char *);
6020 static void gen_inheritance_die (tree, tree, dw_die_ref);
6021 static void gen_member_die (tree, dw_die_ref);
6022 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6023 enum debug_info_usage);
6024 static void gen_subroutine_type_die (tree, dw_die_ref);
6025 static void gen_typedef_die (tree, dw_die_ref);
6026 static void gen_type_die (tree, dw_die_ref);
6027 static void gen_block_die (tree, dw_die_ref, int);
6028 static void decls_for_scope (tree, dw_die_ref, int);
6029 static int is_redundant_typedef (const_tree);
6030 static inline dw_die_ref get_context_die (tree);
6031 static void gen_namespace_die (tree, dw_die_ref);
6032 static void gen_decl_die (tree, tree, dw_die_ref);
6033 static dw_die_ref force_decl_die (tree);
6034 static dw_die_ref force_type_die (tree);
6035 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6036 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6037 static struct dwarf_file_data * lookup_filename (const char *);
6038 static void retry_incomplete_types (void);
6039 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6040 static void gen_generic_params_dies (tree);
6041 static void splice_child_die (dw_die_ref, dw_die_ref);
6042 static int file_info_cmp (const void *, const void *);
6043 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6044 const char *, const char *, unsigned);
6045 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
6046 const char *, const char *,
6048 static void output_loc_list (dw_loc_list_ref);
6049 static char *gen_internal_sym (const char *);
6051 static void prune_unmark_dies (dw_die_ref);
6052 static void prune_unused_types_mark (dw_die_ref, int);
6053 static void prune_unused_types_walk (dw_die_ref);
6054 static void prune_unused_types_walk_attribs (dw_die_ref);
6055 static void prune_unused_types_prune (dw_die_ref);
6056 static void prune_unused_types (void);
6057 static int maybe_emit_file (struct dwarf_file_data *fd);
6058 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6059 static void gen_remaining_tmpl_value_param_die_attribute (void);
6061 /* Section names used to hold DWARF debugging information. */
6062 #ifndef DEBUG_INFO_SECTION
6063 #define DEBUG_INFO_SECTION ".debug_info"
6065 #ifndef DEBUG_ABBREV_SECTION
6066 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6068 #ifndef DEBUG_ARANGES_SECTION
6069 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6071 #ifndef DEBUG_MACINFO_SECTION
6072 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6074 #ifndef DEBUG_LINE_SECTION
6075 #define DEBUG_LINE_SECTION ".debug_line"
6077 #ifndef DEBUG_LOC_SECTION
6078 #define DEBUG_LOC_SECTION ".debug_loc"
6080 #ifndef DEBUG_PUBNAMES_SECTION
6081 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6083 #ifndef DEBUG_PUBTYPES_SECTION
6084 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6086 #ifndef DEBUG_STR_SECTION
6087 #define DEBUG_STR_SECTION ".debug_str"
6089 #ifndef DEBUG_RANGES_SECTION
6090 #define DEBUG_RANGES_SECTION ".debug_ranges"
6093 /* Standard ELF section names for compiled code and data. */
6094 #ifndef TEXT_SECTION_NAME
6095 #define TEXT_SECTION_NAME ".text"
6098 /* Section flags for .debug_str section. */
6099 #define DEBUG_STR_SECTION_FLAGS \
6100 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6101 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6104 /* Labels we insert at beginning sections we can reference instead of
6105 the section names themselves. */
6107 #ifndef TEXT_SECTION_LABEL
6108 #define TEXT_SECTION_LABEL "Ltext"
6110 #ifndef COLD_TEXT_SECTION_LABEL
6111 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6113 #ifndef DEBUG_LINE_SECTION_LABEL
6114 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6116 #ifndef DEBUG_INFO_SECTION_LABEL
6117 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6119 #ifndef DEBUG_ABBREV_SECTION_LABEL
6120 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6122 #ifndef DEBUG_LOC_SECTION_LABEL
6123 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6125 #ifndef DEBUG_RANGES_SECTION_LABEL
6126 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6128 #ifndef DEBUG_MACINFO_SECTION_LABEL
6129 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6132 /* Definitions of defaults for formats and names of various special
6133 (artificial) labels which may be generated within this file (when the -g
6134 options is used and DWARF2_DEBUGGING_INFO is in effect.
6135 If necessary, these may be overridden from within the tm.h file, but
6136 typically, overriding these defaults is unnecessary. */
6138 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6139 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6140 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6141 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6142 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6143 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6144 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6145 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6146 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6147 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6149 #ifndef TEXT_END_LABEL
6150 #define TEXT_END_LABEL "Letext"
6152 #ifndef COLD_END_LABEL
6153 #define COLD_END_LABEL "Letext_cold"
6155 #ifndef BLOCK_BEGIN_LABEL
6156 #define BLOCK_BEGIN_LABEL "LBB"
6158 #ifndef BLOCK_END_LABEL
6159 #define BLOCK_END_LABEL "LBE"
6161 #ifndef LINE_CODE_LABEL
6162 #define LINE_CODE_LABEL "LM"
6164 #ifndef SEPARATE_LINE_CODE_LABEL
6165 #define SEPARATE_LINE_CODE_LABEL "LSM"
6169 /* We allow a language front-end to designate a function that is to be
6170 called to "demangle" any name before it is put into a DIE. */
6172 static const char *(*demangle_name_func) (const char *);
6175 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6177 demangle_name_func = func;
6180 /* Test if rtl node points to a pseudo register. */
6183 is_pseudo_reg (const_rtx rtl)
6185 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6186 || (GET_CODE (rtl) == SUBREG
6187 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6190 /* Return a reference to a type, with its const and volatile qualifiers
6194 type_main_variant (tree type)
6196 type = TYPE_MAIN_VARIANT (type);
6198 /* ??? There really should be only one main variant among any group of
6199 variants of a given type (and all of the MAIN_VARIANT values for all
6200 members of the group should point to that one type) but sometimes the C
6201 front-end messes this up for array types, so we work around that bug
6203 if (TREE_CODE (type) == ARRAY_TYPE)
6204 while (type != TYPE_MAIN_VARIANT (type))
6205 type = TYPE_MAIN_VARIANT (type);
6210 /* Return nonzero if the given type node represents a tagged type. */
6213 is_tagged_type (const_tree type)
6215 enum tree_code code = TREE_CODE (type);
6217 return (code == RECORD_TYPE || code == UNION_TYPE
6218 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6221 /* Convert a DIE tag into its string name. */
6224 dwarf_tag_name (unsigned int tag)
6228 case DW_TAG_padding:
6229 return "DW_TAG_padding";
6230 case DW_TAG_array_type:
6231 return "DW_TAG_array_type";
6232 case DW_TAG_class_type:
6233 return "DW_TAG_class_type";
6234 case DW_TAG_entry_point:
6235 return "DW_TAG_entry_point";
6236 case DW_TAG_enumeration_type:
6237 return "DW_TAG_enumeration_type";
6238 case DW_TAG_formal_parameter:
6239 return "DW_TAG_formal_parameter";
6240 case DW_TAG_imported_declaration:
6241 return "DW_TAG_imported_declaration";
6243 return "DW_TAG_label";
6244 case DW_TAG_lexical_block:
6245 return "DW_TAG_lexical_block";
6247 return "DW_TAG_member";
6248 case DW_TAG_pointer_type:
6249 return "DW_TAG_pointer_type";
6250 case DW_TAG_reference_type:
6251 return "DW_TAG_reference_type";
6252 case DW_TAG_compile_unit:
6253 return "DW_TAG_compile_unit";
6254 case DW_TAG_string_type:
6255 return "DW_TAG_string_type";
6256 case DW_TAG_structure_type:
6257 return "DW_TAG_structure_type";
6258 case DW_TAG_subroutine_type:
6259 return "DW_TAG_subroutine_type";
6260 case DW_TAG_typedef:
6261 return "DW_TAG_typedef";
6262 case DW_TAG_union_type:
6263 return "DW_TAG_union_type";
6264 case DW_TAG_unspecified_parameters:
6265 return "DW_TAG_unspecified_parameters";
6266 case DW_TAG_variant:
6267 return "DW_TAG_variant";
6268 case DW_TAG_common_block:
6269 return "DW_TAG_common_block";
6270 case DW_TAG_common_inclusion:
6271 return "DW_TAG_common_inclusion";
6272 case DW_TAG_inheritance:
6273 return "DW_TAG_inheritance";
6274 case DW_TAG_inlined_subroutine:
6275 return "DW_TAG_inlined_subroutine";
6277 return "DW_TAG_module";
6278 case DW_TAG_ptr_to_member_type:
6279 return "DW_TAG_ptr_to_member_type";
6280 case DW_TAG_set_type:
6281 return "DW_TAG_set_type";
6282 case DW_TAG_subrange_type:
6283 return "DW_TAG_subrange_type";
6284 case DW_TAG_with_stmt:
6285 return "DW_TAG_with_stmt";
6286 case DW_TAG_access_declaration:
6287 return "DW_TAG_access_declaration";
6288 case DW_TAG_base_type:
6289 return "DW_TAG_base_type";
6290 case DW_TAG_catch_block:
6291 return "DW_TAG_catch_block";
6292 case DW_TAG_const_type:
6293 return "DW_TAG_const_type";
6294 case DW_TAG_constant:
6295 return "DW_TAG_constant";
6296 case DW_TAG_enumerator:
6297 return "DW_TAG_enumerator";
6298 case DW_TAG_file_type:
6299 return "DW_TAG_file_type";
6301 return "DW_TAG_friend";
6302 case DW_TAG_namelist:
6303 return "DW_TAG_namelist";
6304 case DW_TAG_namelist_item:
6305 return "DW_TAG_namelist_item";
6306 case DW_TAG_packed_type:
6307 return "DW_TAG_packed_type";
6308 case DW_TAG_subprogram:
6309 return "DW_TAG_subprogram";
6310 case DW_TAG_template_type_param:
6311 return "DW_TAG_template_type_param";
6312 case DW_TAG_template_value_param:
6313 return "DW_TAG_template_value_param";
6314 case DW_TAG_thrown_type:
6315 return "DW_TAG_thrown_type";
6316 case DW_TAG_try_block:
6317 return "DW_TAG_try_block";
6318 case DW_TAG_variant_part:
6319 return "DW_TAG_variant_part";
6320 case DW_TAG_variable:
6321 return "DW_TAG_variable";
6322 case DW_TAG_volatile_type:
6323 return "DW_TAG_volatile_type";
6324 case DW_TAG_dwarf_procedure:
6325 return "DW_TAG_dwarf_procedure";
6326 case DW_TAG_restrict_type:
6327 return "DW_TAG_restrict_type";
6328 case DW_TAG_interface_type:
6329 return "DW_TAG_interface_type";
6330 case DW_TAG_namespace:
6331 return "DW_TAG_namespace";
6332 case DW_TAG_imported_module:
6333 return "DW_TAG_imported_module";
6334 case DW_TAG_unspecified_type:
6335 return "DW_TAG_unspecified_type";
6336 case DW_TAG_partial_unit:
6337 return "DW_TAG_partial_unit";
6338 case DW_TAG_imported_unit:
6339 return "DW_TAG_imported_unit";
6340 case DW_TAG_condition:
6341 return "DW_TAG_condition";
6342 case DW_TAG_shared_type:
6343 return "DW_TAG_shared_type";
6344 case DW_TAG_GNU_template_parameter_pack:
6345 return "DW_TAG_GNU_template_parameter_pack";
6346 case DW_TAG_GNU_formal_parameter_pack:
6347 return "DW_TAG_GNU_formal_parameter_pack";
6348 case DW_TAG_MIPS_loop:
6349 return "DW_TAG_MIPS_loop";
6350 case DW_TAG_format_label:
6351 return "DW_TAG_format_label";
6352 case DW_TAG_function_template:
6353 return "DW_TAG_function_template";
6354 case DW_TAG_class_template:
6355 return "DW_TAG_class_template";
6356 case DW_TAG_GNU_BINCL:
6357 return "DW_TAG_GNU_BINCL";
6358 case DW_TAG_GNU_EINCL:
6359 return "DW_TAG_GNU_EINCL";
6360 case DW_TAG_GNU_template_template_param:
6361 return "DW_TAG_GNU_template_template_param";
6363 return "DW_TAG_<unknown>";
6367 /* Convert a DWARF attribute code into its string name. */
6370 dwarf_attr_name (unsigned int attr)
6375 return "DW_AT_sibling";
6376 case DW_AT_location:
6377 return "DW_AT_location";
6379 return "DW_AT_name";
6380 case DW_AT_ordering:
6381 return "DW_AT_ordering";
6382 case DW_AT_subscr_data:
6383 return "DW_AT_subscr_data";
6384 case DW_AT_byte_size:
6385 return "DW_AT_byte_size";
6386 case DW_AT_bit_offset:
6387 return "DW_AT_bit_offset";
6388 case DW_AT_bit_size:
6389 return "DW_AT_bit_size";
6390 case DW_AT_element_list:
6391 return "DW_AT_element_list";
6392 case DW_AT_stmt_list:
6393 return "DW_AT_stmt_list";
6395 return "DW_AT_low_pc";
6397 return "DW_AT_high_pc";
6398 case DW_AT_language:
6399 return "DW_AT_language";
6401 return "DW_AT_member";
6403 return "DW_AT_discr";
6404 case DW_AT_discr_value:
6405 return "DW_AT_discr_value";
6406 case DW_AT_visibility:
6407 return "DW_AT_visibility";
6409 return "DW_AT_import";
6410 case DW_AT_string_length:
6411 return "DW_AT_string_length";
6412 case DW_AT_common_reference:
6413 return "DW_AT_common_reference";
6414 case DW_AT_comp_dir:
6415 return "DW_AT_comp_dir";
6416 case DW_AT_const_value:
6417 return "DW_AT_const_value";
6418 case DW_AT_containing_type:
6419 return "DW_AT_containing_type";
6420 case DW_AT_default_value:
6421 return "DW_AT_default_value";
6423 return "DW_AT_inline";
6424 case DW_AT_is_optional:
6425 return "DW_AT_is_optional";
6426 case DW_AT_lower_bound:
6427 return "DW_AT_lower_bound";
6428 case DW_AT_producer:
6429 return "DW_AT_producer";
6430 case DW_AT_prototyped:
6431 return "DW_AT_prototyped";
6432 case DW_AT_return_addr:
6433 return "DW_AT_return_addr";
6434 case DW_AT_start_scope:
6435 return "DW_AT_start_scope";
6436 case DW_AT_bit_stride:
6437 return "DW_AT_bit_stride";
6438 case DW_AT_upper_bound:
6439 return "DW_AT_upper_bound";
6440 case DW_AT_abstract_origin:
6441 return "DW_AT_abstract_origin";
6442 case DW_AT_accessibility:
6443 return "DW_AT_accessibility";
6444 case DW_AT_address_class:
6445 return "DW_AT_address_class";
6446 case DW_AT_artificial:
6447 return "DW_AT_artificial";
6448 case DW_AT_base_types:
6449 return "DW_AT_base_types";
6450 case DW_AT_calling_convention:
6451 return "DW_AT_calling_convention";
6453 return "DW_AT_count";
6454 case DW_AT_data_member_location:
6455 return "DW_AT_data_member_location";
6456 case DW_AT_decl_column:
6457 return "DW_AT_decl_column";
6458 case DW_AT_decl_file:
6459 return "DW_AT_decl_file";
6460 case DW_AT_decl_line:
6461 return "DW_AT_decl_line";
6462 case DW_AT_declaration:
6463 return "DW_AT_declaration";
6464 case DW_AT_discr_list:
6465 return "DW_AT_discr_list";
6466 case DW_AT_encoding:
6467 return "DW_AT_encoding";
6468 case DW_AT_external:
6469 return "DW_AT_external";
6470 case DW_AT_explicit:
6471 return "DW_AT_explicit";
6472 case DW_AT_frame_base:
6473 return "DW_AT_frame_base";
6475 return "DW_AT_friend";
6476 case DW_AT_identifier_case:
6477 return "DW_AT_identifier_case";
6478 case DW_AT_macro_info:
6479 return "DW_AT_macro_info";
6480 case DW_AT_namelist_items:
6481 return "DW_AT_namelist_items";
6482 case DW_AT_priority:
6483 return "DW_AT_priority";
6485 return "DW_AT_segment";
6486 case DW_AT_specification:
6487 return "DW_AT_specification";
6488 case DW_AT_static_link:
6489 return "DW_AT_static_link";
6491 return "DW_AT_type";
6492 case DW_AT_use_location:
6493 return "DW_AT_use_location";
6494 case DW_AT_variable_parameter:
6495 return "DW_AT_variable_parameter";
6496 case DW_AT_virtuality:
6497 return "DW_AT_virtuality";
6498 case DW_AT_vtable_elem_location:
6499 return "DW_AT_vtable_elem_location";
6501 case DW_AT_allocated:
6502 return "DW_AT_allocated";
6503 case DW_AT_associated:
6504 return "DW_AT_associated";
6505 case DW_AT_data_location:
6506 return "DW_AT_data_location";
6507 case DW_AT_byte_stride:
6508 return "DW_AT_byte_stride";
6509 case DW_AT_entry_pc:
6510 return "DW_AT_entry_pc";
6511 case DW_AT_use_UTF8:
6512 return "DW_AT_use_UTF8";
6513 case DW_AT_extension:
6514 return "DW_AT_extension";
6516 return "DW_AT_ranges";
6517 case DW_AT_trampoline:
6518 return "DW_AT_trampoline";
6519 case DW_AT_call_column:
6520 return "DW_AT_call_column";
6521 case DW_AT_call_file:
6522 return "DW_AT_call_file";
6523 case DW_AT_call_line:
6524 return "DW_AT_call_line";
6526 case DW_AT_MIPS_fde:
6527 return "DW_AT_MIPS_fde";
6528 case DW_AT_MIPS_loop_begin:
6529 return "DW_AT_MIPS_loop_begin";
6530 case DW_AT_MIPS_tail_loop_begin:
6531 return "DW_AT_MIPS_tail_loop_begin";
6532 case DW_AT_MIPS_epilog_begin:
6533 return "DW_AT_MIPS_epilog_begin";
6534 case DW_AT_MIPS_loop_unroll_factor:
6535 return "DW_AT_MIPS_loop_unroll_factor";
6536 case DW_AT_MIPS_software_pipeline_depth:
6537 return "DW_AT_MIPS_software_pipeline_depth";
6538 case DW_AT_MIPS_linkage_name:
6539 return "DW_AT_MIPS_linkage_name";
6540 case DW_AT_MIPS_stride:
6541 return "DW_AT_MIPS_stride";
6542 case DW_AT_MIPS_abstract_name:
6543 return "DW_AT_MIPS_abstract_name";
6544 case DW_AT_MIPS_clone_origin:
6545 return "DW_AT_MIPS_clone_origin";
6546 case DW_AT_MIPS_has_inlines:
6547 return "DW_AT_MIPS_has_inlines";
6549 case DW_AT_sf_names:
6550 return "DW_AT_sf_names";
6551 case DW_AT_src_info:
6552 return "DW_AT_src_info";
6553 case DW_AT_mac_info:
6554 return "DW_AT_mac_info";
6555 case DW_AT_src_coords:
6556 return "DW_AT_src_coords";
6557 case DW_AT_body_begin:
6558 return "DW_AT_body_begin";
6559 case DW_AT_body_end:
6560 return "DW_AT_body_end";
6561 case DW_AT_GNU_vector:
6562 return "DW_AT_GNU_vector";
6563 case DW_AT_GNU_template_name:
6564 return "DW_AT_GNU_template_name";
6566 case DW_AT_VMS_rtnbeg_pd_address:
6567 return "DW_AT_VMS_rtnbeg_pd_address";
6570 return "DW_AT_<unknown>";
6574 /* Convert a DWARF value form code into its string name. */
6577 dwarf_form_name (unsigned int form)
6582 return "DW_FORM_addr";
6583 case DW_FORM_block2:
6584 return "DW_FORM_block2";
6585 case DW_FORM_block4:
6586 return "DW_FORM_block4";
6588 return "DW_FORM_data2";
6590 return "DW_FORM_data4";
6592 return "DW_FORM_data8";
6593 case DW_FORM_string:
6594 return "DW_FORM_string";
6596 return "DW_FORM_block";
6597 case DW_FORM_block1:
6598 return "DW_FORM_block1";
6600 return "DW_FORM_data1";
6602 return "DW_FORM_flag";
6604 return "DW_FORM_sdata";
6606 return "DW_FORM_strp";
6608 return "DW_FORM_udata";
6609 case DW_FORM_ref_addr:
6610 return "DW_FORM_ref_addr";
6612 return "DW_FORM_ref1";
6614 return "DW_FORM_ref2";
6616 return "DW_FORM_ref4";
6618 return "DW_FORM_ref8";
6619 case DW_FORM_ref_udata:
6620 return "DW_FORM_ref_udata";
6621 case DW_FORM_indirect:
6622 return "DW_FORM_indirect";
6624 return "DW_FORM_<unknown>";
6628 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6629 instance of an inlined instance of a decl which is local to an inline
6630 function, so we have to trace all of the way back through the origin chain
6631 to find out what sort of node actually served as the original seed for the
6635 decl_ultimate_origin (const_tree decl)
6637 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6640 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6641 nodes in the function to point to themselves; ignore that if
6642 we're trying to output the abstract instance of this function. */
6643 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6646 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6647 most distant ancestor, this should never happen. */
6648 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6650 return DECL_ABSTRACT_ORIGIN (decl);
6653 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6654 of a virtual function may refer to a base class, so we check the 'this'
6658 decl_class_context (tree decl)
6660 tree context = NULL_TREE;
6662 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6663 context = DECL_CONTEXT (decl);
6665 context = TYPE_MAIN_VARIANT
6666 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6668 if (context && !TYPE_P (context))
6669 context = NULL_TREE;
6674 /* Add an attribute/value pair to a DIE. */
6677 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6679 /* Maybe this should be an assert? */
6683 if (die->die_attr == NULL)
6684 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6685 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6688 static inline enum dw_val_class
6689 AT_class (dw_attr_ref a)
6691 return a->dw_attr_val.val_class;
6694 /* Add a flag value attribute to a DIE. */
6697 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6701 attr.dw_attr = attr_kind;
6702 attr.dw_attr_val.val_class = dw_val_class_flag;
6703 attr.dw_attr_val.v.val_flag = flag;
6704 add_dwarf_attr (die, &attr);
6707 static inline unsigned
6708 AT_flag (dw_attr_ref a)
6710 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6711 return a->dw_attr_val.v.val_flag;
6714 /* Add a signed integer attribute value to a DIE. */
6717 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6721 attr.dw_attr = attr_kind;
6722 attr.dw_attr_val.val_class = dw_val_class_const;
6723 attr.dw_attr_val.v.val_int = int_val;
6724 add_dwarf_attr (die, &attr);
6727 static inline HOST_WIDE_INT
6728 AT_int (dw_attr_ref a)
6730 gcc_assert (a && AT_class (a) == dw_val_class_const);
6731 return a->dw_attr_val.v.val_int;
6734 /* Add an unsigned integer attribute value to a DIE. */
6737 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6738 unsigned HOST_WIDE_INT unsigned_val)
6742 attr.dw_attr = attr_kind;
6743 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6744 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6745 add_dwarf_attr (die, &attr);
6748 static inline unsigned HOST_WIDE_INT
6749 AT_unsigned (dw_attr_ref a)
6751 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6752 return a->dw_attr_val.v.val_unsigned;
6755 /* Add an unsigned double integer attribute value to a DIE. */
6758 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
6759 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
6763 attr.dw_attr = attr_kind;
6764 attr.dw_attr_val.val_class = dw_val_class_const_double;
6765 attr.dw_attr_val.v.val_double.high = high;
6766 attr.dw_attr_val.v.val_double.low = low;
6767 add_dwarf_attr (die, &attr);
6770 /* Add a floating point attribute value to a DIE and return it. */
6773 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6774 unsigned int length, unsigned int elt_size, unsigned char *array)
6778 attr.dw_attr = attr_kind;
6779 attr.dw_attr_val.val_class = dw_val_class_vec;
6780 attr.dw_attr_val.v.val_vec.length = length;
6781 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6782 attr.dw_attr_val.v.val_vec.array = array;
6783 add_dwarf_attr (die, &attr);
6786 /* Hash and equality functions for debug_str_hash. */
6789 debug_str_do_hash (const void *x)
6791 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6795 debug_str_eq (const void *x1, const void *x2)
6797 return strcmp ((((const struct indirect_string_node *)x1)->str),
6798 (const char *)x2) == 0;
6801 /* Add STR to the indirect string hash table. */
6803 static struct indirect_string_node *
6804 find_AT_string (const char *str)
6806 struct indirect_string_node *node;
6809 if (! debug_str_hash)
6810 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6811 debug_str_eq, NULL);
6813 slot = htab_find_slot_with_hash (debug_str_hash, str,
6814 htab_hash_string (str), INSERT);
6817 node = (struct indirect_string_node *)
6818 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6819 node->str = ggc_strdup (str);
6823 node = (struct indirect_string_node *) *slot;
6829 /* Add a string attribute value to a DIE. */
6832 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6835 struct indirect_string_node *node;
6837 node = find_AT_string (str);
6839 attr.dw_attr = attr_kind;
6840 attr.dw_attr_val.val_class = dw_val_class_str;
6841 attr.dw_attr_val.v.val_str = node;
6842 add_dwarf_attr (die, &attr);
6845 /* Create a label for an indirect string node, ensuring it is going to
6846 be output, unless its reference count goes down to zero. */
6849 gen_label_for_indirect_string (struct indirect_string_node *node)
6856 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6857 ++dw2_string_counter;
6858 node->label = xstrdup (label);
6861 /* Create a SYMBOL_REF rtx whose value is the initial address of a
6862 debug string STR. */
6865 get_debug_string_label (const char *str)
6867 struct indirect_string_node *node = find_AT_string (str);
6869 debug_str_hash_forced = true;
6871 gen_label_for_indirect_string (node);
6873 return gen_rtx_SYMBOL_REF (Pmode, node->label);
6876 static inline const char *
6877 AT_string (dw_attr_ref a)
6879 gcc_assert (a && AT_class (a) == dw_val_class_str);
6880 return a->dw_attr_val.v.val_str->str;
6883 /* Find out whether a string should be output inline in DIE
6884 or out-of-line in .debug_str section. */
6886 static enum dwarf_form
6887 AT_string_form (dw_attr_ref a)
6889 struct indirect_string_node *node;
6892 gcc_assert (a && AT_class (a) == dw_val_class_str);
6894 node = a->dw_attr_val.v.val_str;
6898 len = strlen (node->str) + 1;
6900 /* If the string is shorter or equal to the size of the reference, it is
6901 always better to put it inline. */
6902 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6903 return node->form = DW_FORM_string;
6905 /* If we cannot expect the linker to merge strings in .debug_str
6906 section, only put it into .debug_str if it is worth even in this
6908 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
6909 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
6910 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
6911 return node->form = DW_FORM_string;
6913 gen_label_for_indirect_string (node);
6915 return node->form = DW_FORM_strp;
6918 /* Add a DIE reference attribute value to a DIE. */
6921 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6925 attr.dw_attr = attr_kind;
6926 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6927 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6928 attr.dw_attr_val.v.val_die_ref.external = 0;
6929 add_dwarf_attr (die, &attr);
6932 /* Add an AT_specification attribute to a DIE, and also make the back
6933 pointer from the specification to the definition. */
6936 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6938 add_AT_die_ref (die, DW_AT_specification, targ_die);
6939 gcc_assert (!targ_die->die_definition);
6940 targ_die->die_definition = die;
6943 static inline dw_die_ref
6944 AT_ref (dw_attr_ref a)
6946 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6947 return a->dw_attr_val.v.val_die_ref.die;
6951 AT_ref_external (dw_attr_ref a)
6953 if (a && AT_class (a) == dw_val_class_die_ref)
6954 return a->dw_attr_val.v.val_die_ref.external;
6960 set_AT_ref_external (dw_attr_ref a, int i)
6962 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6963 a->dw_attr_val.v.val_die_ref.external = i;
6966 /* Add an FDE reference attribute value to a DIE. */
6969 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6973 attr.dw_attr = attr_kind;
6974 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6975 attr.dw_attr_val.v.val_fde_index = targ_fde;
6976 add_dwarf_attr (die, &attr);
6979 /* Add a location description attribute value to a DIE. */
6982 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6986 attr.dw_attr = attr_kind;
6987 attr.dw_attr_val.val_class = dw_val_class_loc;
6988 attr.dw_attr_val.v.val_loc = loc;
6989 add_dwarf_attr (die, &attr);
6992 static inline dw_loc_descr_ref
6993 AT_loc (dw_attr_ref a)
6995 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6996 return a->dw_attr_val.v.val_loc;
7000 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7004 attr.dw_attr = attr_kind;
7005 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7006 attr.dw_attr_val.v.val_loc_list = loc_list;
7007 add_dwarf_attr (die, &attr);
7008 have_location_lists = true;
7011 static inline dw_loc_list_ref
7012 AT_loc_list (dw_attr_ref a)
7014 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7015 return a->dw_attr_val.v.val_loc_list;
7018 /* Add an address constant attribute value to a DIE. */
7021 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7025 attr.dw_attr = attr_kind;
7026 attr.dw_attr_val.val_class = dw_val_class_addr;
7027 attr.dw_attr_val.v.val_addr = addr;
7028 add_dwarf_attr (die, &attr);
7031 /* Get the RTX from to an address DIE attribute. */
7034 AT_addr (dw_attr_ref a)
7036 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7037 return a->dw_attr_val.v.val_addr;
7040 /* Add a file attribute value to a DIE. */
7043 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7044 struct dwarf_file_data *fd)
7048 attr.dw_attr = attr_kind;
7049 attr.dw_attr_val.val_class = dw_val_class_file;
7050 attr.dw_attr_val.v.val_file = fd;
7051 add_dwarf_attr (die, &attr);
7054 /* Get the dwarf_file_data from a file DIE attribute. */
7056 static inline struct dwarf_file_data *
7057 AT_file (dw_attr_ref a)
7059 gcc_assert (a && AT_class (a) == dw_val_class_file);
7060 return a->dw_attr_val.v.val_file;
7063 /* Add a label identifier attribute value to a DIE. */
7066 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7070 attr.dw_attr = attr_kind;
7071 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7072 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7073 add_dwarf_attr (die, &attr);
7076 /* Add a section offset attribute value to a DIE, an offset into the
7077 debug_line section. */
7080 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7085 attr.dw_attr = attr_kind;
7086 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7087 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7088 add_dwarf_attr (die, &attr);
7091 /* Add a section offset attribute value to a DIE, an offset into the
7092 debug_macinfo section. */
7095 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7100 attr.dw_attr = attr_kind;
7101 attr.dw_attr_val.val_class = dw_val_class_macptr;
7102 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7103 add_dwarf_attr (die, &attr);
7106 /* Add an offset attribute value to a DIE. */
7109 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7110 unsigned HOST_WIDE_INT offset)
7114 attr.dw_attr = attr_kind;
7115 attr.dw_attr_val.val_class = dw_val_class_offset;
7116 attr.dw_attr_val.v.val_offset = offset;
7117 add_dwarf_attr (die, &attr);
7120 /* Add an range_list attribute value to a DIE. */
7123 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7124 long unsigned int offset)
7128 attr.dw_attr = attr_kind;
7129 attr.dw_attr_val.val_class = dw_val_class_range_list;
7130 attr.dw_attr_val.v.val_offset = offset;
7131 add_dwarf_attr (die, &attr);
7134 static inline const char *
7135 AT_lbl (dw_attr_ref a)
7137 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7138 || AT_class (a) == dw_val_class_lineptr
7139 || AT_class (a) == dw_val_class_macptr));
7140 return a->dw_attr_val.v.val_lbl_id;
7143 /* Get the attribute of type attr_kind. */
7146 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7150 dw_die_ref spec = NULL;
7155 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7156 if (a->dw_attr == attr_kind)
7158 else if (a->dw_attr == DW_AT_specification
7159 || a->dw_attr == DW_AT_abstract_origin)
7163 return get_AT (spec, attr_kind);
7168 /* Return the "low pc" attribute value, typically associated with a subprogram
7169 DIE. Return null if the "low pc" attribute is either not present, or if it
7170 cannot be represented as an assembler label identifier. */
7172 static inline const char *
7173 get_AT_low_pc (dw_die_ref die)
7175 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7177 return a ? AT_lbl (a) : NULL;
7180 /* Return the "high pc" attribute value, typically associated with a subprogram
7181 DIE. Return null if the "high pc" attribute is either not present, or if it
7182 cannot be represented as an assembler label identifier. */
7184 static inline const char *
7185 get_AT_hi_pc (dw_die_ref die)
7187 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7189 return a ? AT_lbl (a) : NULL;
7192 /* Return the value of the string attribute designated by ATTR_KIND, or
7193 NULL if it is not present. */
7195 static inline const char *
7196 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7198 dw_attr_ref a = get_AT (die, attr_kind);
7200 return a ? AT_string (a) : NULL;
7203 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7204 if it is not present. */
7207 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7209 dw_attr_ref a = get_AT (die, attr_kind);
7211 return a ? AT_flag (a) : 0;
7214 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7215 if it is not present. */
7217 static inline unsigned
7218 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7220 dw_attr_ref a = get_AT (die, attr_kind);
7222 return a ? AT_unsigned (a) : 0;
7225 static inline dw_die_ref
7226 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7228 dw_attr_ref a = get_AT (die, attr_kind);
7230 return a ? AT_ref (a) : NULL;
7233 static inline struct dwarf_file_data *
7234 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7236 dw_attr_ref a = get_AT (die, attr_kind);
7238 return a ? AT_file (a) : NULL;
7241 /* Return TRUE if the language is C or C++. */
7246 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7248 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
7249 || lang == DW_LANG_C99
7250 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
7253 /* Return TRUE if the language is C++. */
7258 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7260 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7263 /* Return TRUE if the language is Fortran. */
7268 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7270 return (lang == DW_LANG_Fortran77
7271 || lang == DW_LANG_Fortran90
7272 || lang == DW_LANG_Fortran95);
7275 /* Return TRUE if the language is Java. */
7280 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7282 return lang == DW_LANG_Java;
7285 /* Return TRUE if the language is Ada. */
7290 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7292 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7295 /* Remove the specified attribute if present. */
7298 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7306 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7307 if (a->dw_attr == attr_kind)
7309 if (AT_class (a) == dw_val_class_str)
7310 if (a->dw_attr_val.v.val_str->refcount)
7311 a->dw_attr_val.v.val_str->refcount--;
7313 /* VEC_ordered_remove should help reduce the number of abbrevs
7315 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7320 /* Remove CHILD from its parent. PREV must have the property that
7321 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7324 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7326 gcc_assert (child->die_parent == prev->die_parent);
7327 gcc_assert (prev->die_sib == child);
7330 gcc_assert (child->die_parent->die_child == child);
7334 prev->die_sib = child->die_sib;
7335 if (child->die_parent->die_child == child)
7336 child->die_parent->die_child = prev;
7339 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7343 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7349 dw_die_ref prev = c;
7351 while (c->die_tag == tag)
7353 remove_child_with_prev (c, prev);
7354 /* Might have removed every child. */
7355 if (c == c->die_sib)
7359 } while (c != die->die_child);
7362 /* Add a CHILD_DIE as the last child of DIE. */
7365 add_child_die (dw_die_ref die, dw_die_ref child_die)
7367 /* FIXME this should probably be an assert. */
7368 if (! die || ! child_die)
7370 gcc_assert (die != child_die);
7372 child_die->die_parent = die;
7375 child_die->die_sib = die->die_child->die_sib;
7376 die->die_child->die_sib = child_die;
7379 child_die->die_sib = child_die;
7380 die->die_child = child_die;
7383 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7384 is the specification, to the end of PARENT's list of children.
7385 This is done by removing and re-adding it. */
7388 splice_child_die (dw_die_ref parent, dw_die_ref child)
7392 /* We want the declaration DIE from inside the class, not the
7393 specification DIE at toplevel. */
7394 if (child->die_parent != parent)
7396 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7402 gcc_assert (child->die_parent == parent
7403 || (child->die_parent
7404 == get_AT_ref (parent, DW_AT_specification)));
7406 for (p = child->die_parent->die_child; ; p = p->die_sib)
7407 if (p->die_sib == child)
7409 remove_child_with_prev (child, p);
7413 add_child_die (parent, child);
7416 /* Return a pointer to a newly created DIE node. */
7418 static inline dw_die_ref
7419 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7421 dw_die_ref die = GGC_CNEW (die_node);
7423 die->die_tag = tag_value;
7425 if (parent_die != NULL)
7426 add_child_die (parent_die, die);
7429 limbo_die_node *limbo_node;
7431 limbo_node = GGC_CNEW (limbo_die_node);
7432 limbo_node->die = die;
7433 limbo_node->created_for = t;
7434 limbo_node->next = limbo_die_list;
7435 limbo_die_list = limbo_node;
7441 /* Return the DIE associated with the given type specifier. */
7443 static inline dw_die_ref
7444 lookup_type_die (tree type)
7446 return TYPE_SYMTAB_DIE (type);
7449 /* Equate a DIE to a given type specifier. */
7452 equate_type_number_to_die (tree type, dw_die_ref type_die)
7454 TYPE_SYMTAB_DIE (type) = type_die;
7457 /* Returns a hash value for X (which really is a die_struct). */
7460 decl_die_table_hash (const void *x)
7462 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7465 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7468 decl_die_table_eq (const void *x, const void *y)
7470 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7473 /* Return the DIE associated with a given declaration. */
7475 static inline dw_die_ref
7476 lookup_decl_die (tree decl)
7478 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7481 /* Returns a hash value for X (which really is a var_loc_list). */
7484 decl_loc_table_hash (const void *x)
7486 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7489 /* Return nonzero if decl_id of var_loc_list X is the same as
7493 decl_loc_table_eq (const void *x, const void *y)
7495 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7498 /* Return the var_loc list associated with a given declaration. */
7500 static inline var_loc_list *
7501 lookup_decl_loc (const_tree decl)
7503 if (!decl_loc_table)
7505 return (var_loc_list *)
7506 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7509 /* Equate a DIE to a particular declaration. */
7512 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7514 unsigned int decl_id = DECL_UID (decl);
7517 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7519 decl_die->decl_id = decl_id;
7522 /* Add a variable location node to the linked list for DECL. */
7525 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7527 unsigned int decl_id = DECL_UID (decl);
7531 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7534 temp = GGC_CNEW (var_loc_list);
7535 temp->decl_id = decl_id;
7539 temp = (var_loc_list *) *slot;
7543 /* If the current location is the same as the end of the list,
7544 and either both or neither of the locations is uninitialized,
7545 we have nothing to do. */
7546 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7547 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7548 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7549 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7550 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7551 == VAR_INIT_STATUS_UNINITIALIZED)
7552 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7553 == VAR_INIT_STATUS_UNINITIALIZED))))
7555 /* Add LOC to the end of list and update LAST. */
7556 temp->last->next = loc;
7560 /* Do not add empty location to the beginning of the list. */
7561 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7568 /* Keep track of the number of spaces used to indent the
7569 output of the debugging routines that print the structure of
7570 the DIE internal representation. */
7571 static int print_indent;
7573 /* Indent the line the number of spaces given by print_indent. */
7576 print_spaces (FILE *outfile)
7578 fprintf (outfile, "%*s", print_indent, "");
7581 /* Print the information associated with a given DIE, and its children.
7582 This routine is a debugging aid only. */
7585 print_die (dw_die_ref die, FILE *outfile)
7591 print_spaces (outfile);
7592 fprintf (outfile, "DIE %4ld: %s\n",
7593 die->die_offset, dwarf_tag_name (die->die_tag));
7594 print_spaces (outfile);
7595 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7596 fprintf (outfile, " offset: %ld\n", die->die_offset);
7598 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7600 print_spaces (outfile);
7601 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7603 switch (AT_class (a))
7605 case dw_val_class_addr:
7606 fprintf (outfile, "address");
7608 case dw_val_class_offset:
7609 fprintf (outfile, "offset");
7611 case dw_val_class_loc:
7612 fprintf (outfile, "location descriptor");
7614 case dw_val_class_loc_list:
7615 fprintf (outfile, "location list -> label:%s",
7616 AT_loc_list (a)->ll_symbol);
7618 case dw_val_class_range_list:
7619 fprintf (outfile, "range list");
7621 case dw_val_class_const:
7622 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7624 case dw_val_class_unsigned_const:
7625 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7627 case dw_val_class_const_double:
7628 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
7629 HOST_WIDE_INT_PRINT_UNSIGNED")",
7630 a->dw_attr_val.v.val_double.high,
7631 a->dw_attr_val.v.val_double.low);
7633 case dw_val_class_vec:
7634 fprintf (outfile, "floating-point or vector constant");
7636 case dw_val_class_flag:
7637 fprintf (outfile, "%u", AT_flag (a));
7639 case dw_val_class_die_ref:
7640 if (AT_ref (a) != NULL)
7642 if (AT_ref (a)->die_symbol)
7643 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7645 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7648 fprintf (outfile, "die -> <null>");
7650 case dw_val_class_lbl_id:
7651 case dw_val_class_lineptr:
7652 case dw_val_class_macptr:
7653 fprintf (outfile, "label: %s", AT_lbl (a));
7655 case dw_val_class_str:
7656 if (AT_string (a) != NULL)
7657 fprintf (outfile, "\"%s\"", AT_string (a));
7659 fprintf (outfile, "<null>");
7661 case dw_val_class_file:
7662 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7663 AT_file (a)->emitted_number);
7669 fprintf (outfile, "\n");
7672 if (die->die_child != NULL)
7675 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7678 if (print_indent == 0)
7679 fprintf (outfile, "\n");
7682 /* Print the contents of the source code line number correspondence table.
7683 This routine is a debugging aid only. */
7686 print_dwarf_line_table (FILE *outfile)
7689 dw_line_info_ref line_info;
7691 fprintf (outfile, "\n\nDWARF source line information\n");
7692 for (i = 1; i < line_info_table_in_use; i++)
7694 line_info = &line_info_table[i];
7695 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7696 line_info->dw_file_num,
7697 line_info->dw_line_num);
7700 fprintf (outfile, "\n\n");
7703 /* Print the information collected for a given DIE. */
7706 debug_dwarf_die (dw_die_ref die)
7708 print_die (die, stderr);
7711 /* Print all DWARF information collected for the compilation unit.
7712 This routine is a debugging aid only. */
7718 print_die (comp_unit_die, stderr);
7719 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7720 print_dwarf_line_table (stderr);
7723 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7724 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7725 DIE that marks the start of the DIEs for this include file. */
7728 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7730 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7731 dw_die_ref new_unit = gen_compile_unit_die (filename);
7733 new_unit->die_sib = old_unit;
7737 /* Close an include-file CU and reopen the enclosing one. */
7740 pop_compile_unit (dw_die_ref old_unit)
7742 dw_die_ref new_unit = old_unit->die_sib;
7744 old_unit->die_sib = NULL;
7748 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7749 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7751 /* Calculate the checksum of a location expression. */
7754 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7758 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7760 CHECKSUM (loc->dw_loc_oprnd1);
7761 CHECKSUM (loc->dw_loc_oprnd2);
7764 /* Calculate the checksum of an attribute. */
7767 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7769 dw_loc_descr_ref loc;
7772 CHECKSUM (at->dw_attr);
7774 /* We don't care that this was compiled with a different compiler
7775 snapshot; if the output is the same, that's what matters. */
7776 if (at->dw_attr == DW_AT_producer)
7779 switch (AT_class (at))
7781 case dw_val_class_const:
7782 CHECKSUM (at->dw_attr_val.v.val_int);
7784 case dw_val_class_unsigned_const:
7785 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7787 case dw_val_class_const_double:
7788 CHECKSUM (at->dw_attr_val.v.val_double);
7790 case dw_val_class_vec:
7791 CHECKSUM (at->dw_attr_val.v.val_vec);
7793 case dw_val_class_flag:
7794 CHECKSUM (at->dw_attr_val.v.val_flag);
7796 case dw_val_class_str:
7797 CHECKSUM_STRING (AT_string (at));
7800 case dw_val_class_addr:
7802 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7803 CHECKSUM_STRING (XSTR (r, 0));
7806 case dw_val_class_offset:
7807 CHECKSUM (at->dw_attr_val.v.val_offset);
7810 case dw_val_class_loc:
7811 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7812 loc_checksum (loc, ctx);
7815 case dw_val_class_die_ref:
7816 die_checksum (AT_ref (at), ctx, mark);
7819 case dw_val_class_fde_ref:
7820 case dw_val_class_lbl_id:
7821 case dw_val_class_lineptr:
7822 case dw_val_class_macptr:
7825 case dw_val_class_file:
7826 CHECKSUM_STRING (AT_file (at)->filename);
7834 /* Calculate the checksum of a DIE. */
7837 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7843 /* To avoid infinite recursion. */
7846 CHECKSUM (die->die_mark);
7849 die->die_mark = ++(*mark);
7851 CHECKSUM (die->die_tag);
7853 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7854 attr_checksum (a, ctx, mark);
7856 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7860 #undef CHECKSUM_STRING
7862 /* Do the location expressions look same? */
7864 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7866 return loc1->dw_loc_opc == loc2->dw_loc_opc
7867 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7868 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7871 /* Do the values look the same? */
7873 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7875 dw_loc_descr_ref loc1, loc2;
7878 if (v1->val_class != v2->val_class)
7881 switch (v1->val_class)
7883 case dw_val_class_const:
7884 return v1->v.val_int == v2->v.val_int;
7885 case dw_val_class_unsigned_const:
7886 return v1->v.val_unsigned == v2->v.val_unsigned;
7887 case dw_val_class_const_double:
7888 return v1->v.val_double.high == v2->v.val_double.high
7889 && v1->v.val_double.low == v2->v.val_double.low;
7890 case dw_val_class_vec:
7891 if (v1->v.val_vec.length != v2->v.val_vec.length
7892 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7894 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7895 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7898 case dw_val_class_flag:
7899 return v1->v.val_flag == v2->v.val_flag;
7900 case dw_val_class_str:
7901 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7903 case dw_val_class_addr:
7904 r1 = v1->v.val_addr;
7905 r2 = v2->v.val_addr;
7906 if (GET_CODE (r1) != GET_CODE (r2))
7908 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7909 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7911 case dw_val_class_offset:
7912 return v1->v.val_offset == v2->v.val_offset;
7914 case dw_val_class_loc:
7915 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7917 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7918 if (!same_loc_p (loc1, loc2, mark))
7920 return !loc1 && !loc2;
7922 case dw_val_class_die_ref:
7923 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7925 case dw_val_class_fde_ref:
7926 case dw_val_class_lbl_id:
7927 case dw_val_class_lineptr:
7928 case dw_val_class_macptr:
7931 case dw_val_class_file:
7932 return v1->v.val_file == v2->v.val_file;
7939 /* Do the attributes look the same? */
7942 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7944 if (at1->dw_attr != at2->dw_attr)
7947 /* We don't care that this was compiled with a different compiler
7948 snapshot; if the output is the same, that's what matters. */
7949 if (at1->dw_attr == DW_AT_producer)
7952 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7955 /* Do the dies look the same? */
7958 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7964 /* To avoid infinite recursion. */
7966 return die1->die_mark == die2->die_mark;
7967 die1->die_mark = die2->die_mark = ++(*mark);
7969 if (die1->die_tag != die2->die_tag)
7972 if (VEC_length (dw_attr_node, die1->die_attr)
7973 != VEC_length (dw_attr_node, die2->die_attr))
7976 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7977 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7980 c1 = die1->die_child;
7981 c2 = die2->die_child;
7990 if (!same_die_p (c1, c2, mark))
7994 if (c1 == die1->die_child)
7996 if (c2 == die2->die_child)
8006 /* Do the dies look the same? Wrapper around same_die_p. */
8009 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
8012 int ret = same_die_p (die1, die2, &mark);
8014 unmark_all_dies (die1);
8015 unmark_all_dies (die2);
8020 /* The prefix to attach to symbols on DIEs in the current comdat debug
8022 static char *comdat_symbol_id;
8024 /* The index of the current symbol within the current comdat CU. */
8025 static unsigned int comdat_symbol_number;
8027 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8028 children, and set comdat_symbol_id accordingly. */
8031 compute_section_prefix (dw_die_ref unit_die)
8033 const char *die_name = get_AT_string (unit_die, DW_AT_name);
8034 const char *base = die_name ? lbasename (die_name) : "anonymous";
8035 char *name = XALLOCAVEC (char, strlen (base) + 64);
8038 unsigned char checksum[16];
8041 /* Compute the checksum of the DIE, then append part of it as hex digits to
8042 the name filename of the unit. */
8044 md5_init_ctx (&ctx);
8046 die_checksum (unit_die, &ctx, &mark);
8047 unmark_all_dies (unit_die);
8048 md5_finish_ctx (&ctx, checksum);
8050 sprintf (name, "%s.", base);
8051 clean_symbol_name (name);
8053 p = name + strlen (name);
8054 for (i = 0; i < 4; i++)
8056 sprintf (p, "%.2x", checksum[i]);
8060 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
8061 comdat_symbol_number = 0;
8064 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
8067 is_type_die (dw_die_ref die)
8069 switch (die->die_tag)
8071 case DW_TAG_array_type:
8072 case DW_TAG_class_type:
8073 case DW_TAG_interface_type:
8074 case DW_TAG_enumeration_type:
8075 case DW_TAG_pointer_type:
8076 case DW_TAG_reference_type:
8077 case DW_TAG_string_type:
8078 case DW_TAG_structure_type:
8079 case DW_TAG_subroutine_type:
8080 case DW_TAG_union_type:
8081 case DW_TAG_ptr_to_member_type:
8082 case DW_TAG_set_type:
8083 case DW_TAG_subrange_type:
8084 case DW_TAG_base_type:
8085 case DW_TAG_const_type:
8086 case DW_TAG_file_type:
8087 case DW_TAG_packed_type:
8088 case DW_TAG_volatile_type:
8089 case DW_TAG_typedef:
8096 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
8097 Basically, we want to choose the bits that are likely to be shared between
8098 compilations (types) and leave out the bits that are specific to individual
8099 compilations (functions). */
8102 is_comdat_die (dw_die_ref c)
8104 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
8105 we do for stabs. The advantage is a greater likelihood of sharing between
8106 objects that don't include headers in the same order (and therefore would
8107 put the base types in a different comdat). jason 8/28/00 */
8109 if (c->die_tag == DW_TAG_base_type)
8112 if (c->die_tag == DW_TAG_pointer_type
8113 || c->die_tag == DW_TAG_reference_type
8114 || c->die_tag == DW_TAG_const_type
8115 || c->die_tag == DW_TAG_volatile_type)
8117 dw_die_ref t = get_AT_ref (c, DW_AT_type);
8119 return t ? is_comdat_die (t) : 0;
8122 return is_type_die (c);
8125 /* Returns 1 iff C is the sort of DIE that might be referred to from another
8126 compilation unit. */
8129 is_symbol_die (dw_die_ref c)
8131 return (is_type_die (c)
8132 || (get_AT (c, DW_AT_declaration)
8133 && !get_AT (c, DW_AT_specification))
8134 || c->die_tag == DW_TAG_namespace
8135 || c->die_tag == DW_TAG_module);
8139 gen_internal_sym (const char *prefix)
8143 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8144 return xstrdup (buf);
8147 /* Assign symbols to all worthy DIEs under DIE. */
8150 assign_symbol_names (dw_die_ref die)
8154 if (is_symbol_die (die))
8156 if (comdat_symbol_id)
8158 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
8160 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
8161 comdat_symbol_id, comdat_symbol_number++);
8162 die->die_symbol = xstrdup (p);
8165 die->die_symbol = gen_internal_sym ("LDIE");
8168 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
8171 struct cu_hash_table_entry
8174 unsigned min_comdat_num, max_comdat_num;
8175 struct cu_hash_table_entry *next;
8178 /* Routines to manipulate hash table of CUs. */
8180 htab_cu_hash (const void *of)
8182 const struct cu_hash_table_entry *const entry =
8183 (const struct cu_hash_table_entry *) of;
8185 return htab_hash_string (entry->cu->die_symbol);
8189 htab_cu_eq (const void *of1, const void *of2)
8191 const struct cu_hash_table_entry *const entry1 =
8192 (const struct cu_hash_table_entry *) of1;
8193 const struct die_struct *const entry2 = (const struct die_struct *) of2;
8195 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
8199 htab_cu_del (void *what)
8201 struct cu_hash_table_entry *next,
8202 *entry = (struct cu_hash_table_entry *) what;
8212 /* Check whether we have already seen this CU and set up SYM_NUM
8215 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
8217 struct cu_hash_table_entry dummy;
8218 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
8220 dummy.max_comdat_num = 0;
8222 slot = (struct cu_hash_table_entry **)
8223 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8227 for (; entry; last = entry, entry = entry->next)
8229 if (same_die_p_wrap (cu, entry->cu))
8235 *sym_num = entry->min_comdat_num;
8239 entry = XCNEW (struct cu_hash_table_entry);
8241 entry->min_comdat_num = *sym_num = last->max_comdat_num;
8242 entry->next = *slot;
8248 /* Record SYM_NUM to record of CU in HTABLE. */
8250 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
8252 struct cu_hash_table_entry **slot, *entry;
8254 slot = (struct cu_hash_table_entry **)
8255 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8259 entry->max_comdat_num = sym_num;
8262 /* Traverse the DIE (which is always comp_unit_die), and set up
8263 additional compilation units for each of the include files we see
8264 bracketed by BINCL/EINCL. */
8267 break_out_includes (dw_die_ref die)
8270 dw_die_ref unit = NULL;
8271 limbo_die_node *node, **pnode;
8272 htab_t cu_hash_table;
8276 dw_die_ref prev = c;
8278 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
8279 || (unit && is_comdat_die (c)))
8281 dw_die_ref next = c->die_sib;
8283 /* This DIE is for a secondary CU; remove it from the main one. */
8284 remove_child_with_prev (c, prev);
8286 if (c->die_tag == DW_TAG_GNU_BINCL)
8287 unit = push_new_compile_unit (unit, c);
8288 else if (c->die_tag == DW_TAG_GNU_EINCL)
8289 unit = pop_compile_unit (unit);
8291 add_child_die (unit, c);
8293 if (c == die->die_child)
8296 } while (c != die->die_child);
8299 /* We can only use this in debugging, since the frontend doesn't check
8300 to make sure that we leave every include file we enter. */
8304 assign_symbol_names (die);
8305 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
8306 for (node = limbo_die_list, pnode = &limbo_die_list;
8312 compute_section_prefix (node->die);
8313 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
8314 &comdat_symbol_number);
8315 assign_symbol_names (node->die);
8317 *pnode = node->next;
8320 pnode = &node->next;
8321 record_comdat_symbol_number (node->die, cu_hash_table,
8322 comdat_symbol_number);
8325 htab_delete (cu_hash_table);
8328 /* Traverse the DIE and add a sibling attribute if it may have the
8329 effect of speeding up access to siblings. To save some space,
8330 avoid generating sibling attributes for DIE's without children. */
8333 add_sibling_attributes (dw_die_ref die)
8337 if (! die->die_child)
8340 if (die->die_parent && die != die->die_parent->die_child)
8341 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8343 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8346 /* Output all location lists for the DIE and its children. */
8349 output_location_lists (dw_die_ref die)
8355 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8356 if (AT_class (a) == dw_val_class_loc_list)
8357 output_loc_list (AT_loc_list (a));
8359 FOR_EACH_CHILD (die, c, output_location_lists (c));
8362 /* The format of each DIE (and its attribute value pairs) is encoded in an
8363 abbreviation table. This routine builds the abbreviation table and assigns
8364 a unique abbreviation id for each abbreviation entry. The children of each
8365 die are visited recursively. */
8368 build_abbrev_table (dw_die_ref die)
8370 unsigned long abbrev_id;
8371 unsigned int n_alloc;
8376 /* Scan the DIE references, and mark as external any that refer to
8377 DIEs from other CUs (i.e. those which are not marked). */
8378 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8379 if (AT_class (a) == dw_val_class_die_ref
8380 && AT_ref (a)->die_mark == 0)
8382 gcc_assert (AT_ref (a)->die_symbol);
8383 set_AT_ref_external (a, 1);
8386 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8388 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8389 dw_attr_ref die_a, abbrev_a;
8393 if (abbrev->die_tag != die->die_tag)
8395 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8398 if (VEC_length (dw_attr_node, abbrev->die_attr)
8399 != VEC_length (dw_attr_node, die->die_attr))
8402 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
8404 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8405 if ((abbrev_a->dw_attr != die_a->dw_attr)
8406 || (value_format (abbrev_a) != value_format (die_a)))
8416 if (abbrev_id >= abbrev_die_table_in_use)
8418 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8420 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8421 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8424 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8425 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8426 abbrev_die_table_allocated = n_alloc;
8429 ++abbrev_die_table_in_use;
8430 abbrev_die_table[abbrev_id] = die;
8433 die->die_abbrev = abbrev_id;
8434 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8437 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8440 constant_size (unsigned HOST_WIDE_INT value)
8447 log = floor_log2 (value);
8450 log = 1 << (floor_log2 (log) + 1);
8455 /* Return the size of a DIE as it is represented in the
8456 .debug_info section. */
8458 static unsigned long
8459 size_of_die (dw_die_ref die)
8461 unsigned long size = 0;
8465 size += size_of_uleb128 (die->die_abbrev);
8466 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8468 switch (AT_class (a))
8470 case dw_val_class_addr:
8471 size += DWARF2_ADDR_SIZE;
8473 case dw_val_class_offset:
8474 size += DWARF_OFFSET_SIZE;
8476 case dw_val_class_loc:
8478 unsigned long lsize = size_of_locs (AT_loc (a));
8481 size += constant_size (lsize);
8485 case dw_val_class_loc_list:
8486 size += DWARF_OFFSET_SIZE;
8488 case dw_val_class_range_list:
8489 size += DWARF_OFFSET_SIZE;
8491 case dw_val_class_const:
8492 size += size_of_sleb128 (AT_int (a));
8494 case dw_val_class_unsigned_const:
8495 size += constant_size (AT_unsigned (a));
8497 case dw_val_class_const_double:
8498 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
8499 if (HOST_BITS_PER_WIDE_INT >= 64)
8502 case dw_val_class_vec:
8503 size += constant_size (a->dw_attr_val.v.val_vec.length
8504 * a->dw_attr_val.v.val_vec.elt_size)
8505 + a->dw_attr_val.v.val_vec.length
8506 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8508 case dw_val_class_flag:
8511 case dw_val_class_die_ref:
8512 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8513 whereas in DWARF3 it's always sized as an offset. */
8514 if (AT_ref_external (a) && dwarf_version == 2)
8515 size += DWARF2_ADDR_SIZE;
8517 size += DWARF_OFFSET_SIZE;
8519 case dw_val_class_fde_ref:
8520 size += DWARF_OFFSET_SIZE;
8522 case dw_val_class_lbl_id:
8523 size += DWARF2_ADDR_SIZE;
8525 case dw_val_class_lineptr:
8526 case dw_val_class_macptr:
8527 size += DWARF_OFFSET_SIZE;
8529 case dw_val_class_str:
8530 if (AT_string_form (a) == DW_FORM_strp)
8531 size += DWARF_OFFSET_SIZE;
8533 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8535 case dw_val_class_file:
8536 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8546 /* Size the debugging information associated with a given DIE. Visits the
8547 DIE's children recursively. Updates the global variable next_die_offset, on
8548 each time through. Uses the current value of next_die_offset to update the
8549 die_offset field in each DIE. */
8552 calc_die_sizes (dw_die_ref die)
8556 die->die_offset = next_die_offset;
8557 next_die_offset += size_of_die (die);
8559 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8561 if (die->die_child != NULL)
8562 /* Count the null byte used to terminate sibling lists. */
8563 next_die_offset += 1;
8566 /* Set the marks for a die and its children. We do this so
8567 that we know whether or not a reference needs to use FORM_ref_addr; only
8568 DIEs in the same CU will be marked. We used to clear out the offset
8569 and use that as the flag, but ran into ordering problems. */
8572 mark_dies (dw_die_ref die)
8576 gcc_assert (!die->die_mark);
8579 FOR_EACH_CHILD (die, c, mark_dies (c));
8582 /* Clear the marks for a die and its children. */
8585 unmark_dies (dw_die_ref die)
8589 gcc_assert (die->die_mark);
8592 FOR_EACH_CHILD (die, c, unmark_dies (c));
8595 /* Clear the marks for a die, its children and referred dies. */
8598 unmark_all_dies (dw_die_ref die)
8608 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8610 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8611 if (AT_class (a) == dw_val_class_die_ref)
8612 unmark_all_dies (AT_ref (a));
8615 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8616 generated for the compilation unit. */
8618 static unsigned long
8619 size_of_pubnames (VEC (pubname_entry, gc) * names)
8625 size = DWARF_PUBNAMES_HEADER_SIZE;
8626 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8627 if (names != pubtype_table
8628 || p->die->die_offset != 0
8629 || !flag_eliminate_unused_debug_types)
8630 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8632 size += DWARF_OFFSET_SIZE;
8636 /* Return the size of the information in the .debug_aranges section. */
8638 static unsigned long
8639 size_of_aranges (void)
8643 size = DWARF_ARANGES_HEADER_SIZE;
8645 /* Count the address/length pair for this compilation unit. */
8646 if (text_section_used)
8647 size += 2 * DWARF2_ADDR_SIZE;
8648 if (cold_text_section_used)
8649 size += 2 * DWARF2_ADDR_SIZE;
8650 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8652 /* Count the two zero words used to terminated the address range table. */
8653 size += 2 * DWARF2_ADDR_SIZE;
8657 /* Select the encoding of an attribute value. */
8659 static enum dwarf_form
8660 value_format (dw_attr_ref a)
8662 switch (a->dw_attr_val.val_class)
8664 case dw_val_class_addr:
8665 return DW_FORM_addr;
8666 case dw_val_class_range_list:
8667 case dw_val_class_offset:
8668 case dw_val_class_loc_list:
8669 switch (DWARF_OFFSET_SIZE)
8672 return DW_FORM_data4;
8674 return DW_FORM_data8;
8678 case dw_val_class_loc:
8679 switch (constant_size (size_of_locs (AT_loc (a))))
8682 return DW_FORM_block1;
8684 return DW_FORM_block2;
8688 case dw_val_class_const:
8689 return DW_FORM_sdata;
8690 case dw_val_class_unsigned_const:
8691 switch (constant_size (AT_unsigned (a)))
8694 return DW_FORM_data1;
8696 return DW_FORM_data2;
8698 return DW_FORM_data4;
8700 return DW_FORM_data8;
8704 case dw_val_class_const_double:
8705 switch (HOST_BITS_PER_WIDE_INT)
8708 return DW_FORM_data2;
8710 return DW_FORM_data4;
8712 return DW_FORM_data8;
8715 return DW_FORM_block1;
8717 case dw_val_class_vec:
8718 switch (constant_size (a->dw_attr_val.v.val_vec.length
8719 * a->dw_attr_val.v.val_vec.elt_size))
8722 return DW_FORM_block1;
8724 return DW_FORM_block2;
8726 return DW_FORM_block4;
8730 case dw_val_class_flag:
8731 return DW_FORM_flag;
8732 case dw_val_class_die_ref:
8733 if (AT_ref_external (a))
8734 return DW_FORM_ref_addr;
8737 case dw_val_class_fde_ref:
8738 return DW_FORM_data;
8739 case dw_val_class_lbl_id:
8740 return DW_FORM_addr;
8741 case dw_val_class_lineptr:
8742 case dw_val_class_macptr:
8743 return DW_FORM_data;
8744 case dw_val_class_str:
8745 return AT_string_form (a);
8746 case dw_val_class_file:
8747 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8750 return DW_FORM_data1;
8752 return DW_FORM_data2;
8754 return DW_FORM_data4;
8764 /* Output the encoding of an attribute value. */
8767 output_value_format (dw_attr_ref a)
8769 enum dwarf_form form = value_format (a);
8771 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8774 /* Output the .debug_abbrev section which defines the DIE abbreviation
8778 output_abbrev_section (void)
8780 unsigned long abbrev_id;
8782 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8784 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8788 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8789 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8790 dwarf_tag_name (abbrev->die_tag));
8792 if (abbrev->die_child != NULL)
8793 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8795 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8797 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8800 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8801 dwarf_attr_name (a_attr->dw_attr));
8802 output_value_format (a_attr);
8805 dw2_asm_output_data (1, 0, NULL);
8806 dw2_asm_output_data (1, 0, NULL);
8809 /* Terminate the table. */
8810 dw2_asm_output_data (1, 0, NULL);
8813 /* Output a symbol we can use to refer to this DIE from another CU. */
8816 output_die_symbol (dw_die_ref die)
8818 char *sym = die->die_symbol;
8823 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8824 /* We make these global, not weak; if the target doesn't support
8825 .linkonce, it doesn't support combining the sections, so debugging
8827 targetm.asm_out.globalize_label (asm_out_file, sym);
8829 ASM_OUTPUT_LABEL (asm_out_file, sym);
8832 /* Return a new location list, given the begin and end range, and the
8833 expression. gensym tells us whether to generate a new internal symbol for
8834 this location list node, which is done for the head of the list only. */
8836 static inline dw_loc_list_ref
8837 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8838 const char *section, unsigned int gensym)
8840 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8842 retlist->begin = begin;
8844 retlist->expr = expr;
8845 retlist->section = section;
8847 retlist->ll_symbol = gen_internal_sym ("LLST");
8852 /* Add a location description expression to a location list. */
8855 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8856 const char *begin, const char *end,
8857 const char *section)
8861 /* Find the end of the chain. */
8862 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8865 /* Add a new location list node to the list. */
8866 *d = new_loc_list (descr, begin, end, section, 0);
8869 /* Output the location list given to us. */
8872 output_loc_list (dw_loc_list_ref list_head)
8874 dw_loc_list_ref curr = list_head;
8876 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8878 /* Walk the location list, and output each range + expression. */
8879 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8882 /* Don't output an entry that starts and ends at the same address. */
8883 if (strcmp (curr->begin, curr->end) == 0)
8885 if (!have_multiple_function_sections)
8887 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8888 "Location list begin address (%s)",
8889 list_head->ll_symbol);
8890 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8891 "Location list end address (%s)",
8892 list_head->ll_symbol);
8896 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8897 "Location list begin address (%s)",
8898 list_head->ll_symbol);
8899 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8900 "Location list end address (%s)",
8901 list_head->ll_symbol);
8903 size = size_of_locs (curr->expr);
8905 /* Output the block length for this list of location operations. */
8906 gcc_assert (size <= 0xffff);
8907 dw2_asm_output_data (2, size, "%s", "Location expression size");
8909 output_loc_sequence (curr->expr);
8912 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8913 "Location list terminator begin (%s)",
8914 list_head->ll_symbol);
8915 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8916 "Location list terminator end (%s)",
8917 list_head->ll_symbol);
8920 /* Output the DIE and its attributes. Called recursively to generate
8921 the definitions of each child DIE. */
8924 output_die (dw_die_ref die)
8931 /* If someone in another CU might refer to us, set up a symbol for
8932 them to point to. */
8933 if (die->die_symbol)
8934 output_die_symbol (die);
8936 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8937 (unsigned long)die->die_offset,
8938 dwarf_tag_name (die->die_tag));
8940 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8942 const char *name = dwarf_attr_name (a->dw_attr);
8944 switch (AT_class (a))
8946 case dw_val_class_addr:
8947 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8950 case dw_val_class_offset:
8951 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8955 case dw_val_class_range_list:
8957 char *p = strchr (ranges_section_label, '\0');
8959 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8960 a->dw_attr_val.v.val_offset);
8961 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8962 debug_ranges_section, "%s", name);
8967 case dw_val_class_loc:
8968 size = size_of_locs (AT_loc (a));
8970 /* Output the block length for this list of location operations. */
8971 dw2_asm_output_data (constant_size (size), size, "%s", name);
8973 output_loc_sequence (AT_loc (a));
8976 case dw_val_class_const:
8977 /* ??? It would be slightly more efficient to use a scheme like is
8978 used for unsigned constants below, but gdb 4.x does not sign
8979 extend. Gdb 5.x does sign extend. */
8980 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8983 case dw_val_class_unsigned_const:
8984 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8985 AT_unsigned (a), "%s", name);
8988 case dw_val_class_const_double:
8990 unsigned HOST_WIDE_INT first, second;
8992 if (HOST_BITS_PER_WIDE_INT >= 64)
8993 dw2_asm_output_data (1,
8994 2 * HOST_BITS_PER_WIDE_INT
8995 / HOST_BITS_PER_CHAR,
8998 if (WORDS_BIG_ENDIAN)
9000 first = a->dw_attr_val.v.val_double.high;
9001 second = a->dw_attr_val.v.val_double.low;
9005 first = a->dw_attr_val.v.val_double.low;
9006 second = a->dw_attr_val.v.val_double.high;
9009 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
9011 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
9016 case dw_val_class_vec:
9018 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
9019 unsigned int len = a->dw_attr_val.v.val_vec.length;
9023 dw2_asm_output_data (constant_size (len * elt_size),
9024 len * elt_size, "%s", name);
9025 if (elt_size > sizeof (HOST_WIDE_INT))
9030 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
9033 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
9034 "fp or vector constant word %u", i);
9038 case dw_val_class_flag:
9039 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9042 case dw_val_class_loc_list:
9044 char *sym = AT_loc_list (a)->ll_symbol;
9047 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
9052 case dw_val_class_die_ref:
9053 if (AT_ref_external (a))
9055 char *sym = AT_ref (a)->die_symbol;
9060 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9061 length, whereas in DWARF3 it's always sized as an offset. */
9062 if (dwarf_version == 2)
9063 size = DWARF2_ADDR_SIZE;
9065 size = DWARF_OFFSET_SIZE;
9066 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
9070 gcc_assert (AT_ref (a)->die_offset);
9071 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9076 case dw_val_class_fde_ref:
9080 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9081 a->dw_attr_val.v.val_fde_index * 2);
9082 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9087 case dw_val_class_lbl_id:
9088 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
9091 case dw_val_class_lineptr:
9092 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9093 debug_line_section, "%s", name);
9096 case dw_val_class_macptr:
9097 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9098 debug_macinfo_section, "%s", name);
9101 case dw_val_class_str:
9102 if (AT_string_form (a) == DW_FORM_strp)
9103 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9104 a->dw_attr_val.v.val_str->label,
9106 "%s: \"%s\"", name, AT_string (a));
9108 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9111 case dw_val_class_file:
9113 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9115 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9116 a->dw_attr_val.v.val_file->filename);
9125 FOR_EACH_CHILD (die, c, output_die (c));
9127 /* Add null byte to terminate sibling list. */
9128 if (die->die_child != NULL)
9129 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
9130 (unsigned long) die->die_offset);
9133 /* Output the compilation unit that appears at the beginning of the
9134 .debug_info section, and precedes the DIE descriptions. */
9137 output_compilation_unit_header (void)
9139 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9140 dw2_asm_output_data (4, 0xffffffff,
9141 "Initial length escape value indicating 64-bit DWARF extension");
9142 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9143 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9144 "Length of Compilation Unit Info");
9145 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
9146 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9147 debug_abbrev_section,
9148 "Offset Into Abbrev. Section");
9149 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9152 /* Output the compilation unit DIE and its children. */
9155 output_comp_unit (dw_die_ref die, int output_if_empty)
9157 const char *secname;
9160 /* Unless we are outputting main CU, we may throw away empty ones. */
9161 if (!output_if_empty && die->die_child == NULL)
9164 /* Even if there are no children of this DIE, we must output the information
9165 about the compilation unit. Otherwise, on an empty translation unit, we
9166 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9167 will then complain when examining the file. First mark all the DIEs in
9168 this CU so we know which get local refs. */
9171 build_abbrev_table (die);
9173 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9174 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9175 calc_die_sizes (die);
9177 oldsym = die->die_symbol;
9180 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9182 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9184 die->die_symbol = NULL;
9185 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9188 switch_to_section (debug_info_section);
9190 /* Output debugging information. */
9191 output_compilation_unit_header ();
9194 /* Leave the marks on the main CU, so we can check them in
9199 die->die_symbol = oldsym;
9203 /* Return the DWARF2/3 pubname associated with a decl. */
9206 dwarf2_name (tree decl, int scope)
9208 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9211 /* Add a new entry to .debug_pubnames if appropriate. */
9214 add_pubname_string (const char *str, dw_die_ref die)
9219 e.name = xstrdup (str);
9220 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9224 add_pubname (tree decl, dw_die_ref die)
9226 if (TREE_PUBLIC (decl))
9227 add_pubname_string (dwarf2_name (decl, 1), die);
9230 /* Add a new entry to .debug_pubtypes if appropriate. */
9233 add_pubtype (tree decl, dw_die_ref die)
9238 if ((TREE_PUBLIC (decl)
9239 || die->die_parent == comp_unit_die)
9240 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9245 if (TYPE_NAME (decl))
9247 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9248 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9249 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9250 && DECL_NAME (TYPE_NAME (decl)))
9251 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9253 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9257 e.name = xstrdup (dwarf2_name (decl, 1));
9259 /* If we don't have a name for the type, there's no point in adding
9261 if (e.name && e.name[0] != '\0')
9262 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9266 /* Output the public names table used to speed up access to externally
9267 visible names; or the public types table used to find type definitions. */
9270 output_pubnames (VEC (pubname_entry, gc) * names)
9273 unsigned long pubnames_length = size_of_pubnames (names);
9276 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9277 dw2_asm_output_data (4, 0xffffffff,
9278 "Initial length escape value indicating 64-bit DWARF extension");
9279 if (names == pubname_table)
9280 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9281 "Length of Public Names Info");
9283 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9284 "Length of Public Type Names Info");
9285 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9286 dw2_asm_output_data (2, 2, "DWARF Version");
9287 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9289 "Offset of Compilation Unit Info");
9290 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9291 "Compilation Unit Length");
9293 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
9295 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9296 if (names == pubname_table)
9297 gcc_assert (pub->die->die_mark);
9299 if (names != pubtype_table
9300 || pub->die->die_offset != 0
9301 || !flag_eliminate_unused_debug_types)
9303 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9306 dw2_asm_output_nstring (pub->name, -1, "external name");
9310 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9313 /* Add a new entry to .debug_aranges if appropriate. */
9316 add_arange (tree decl, dw_die_ref die)
9318 if (! DECL_SECTION_NAME (decl))
9321 if (arange_table_in_use == arange_table_allocated)
9323 arange_table_allocated += ARANGE_TABLE_INCREMENT;
9324 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
9325 arange_table_allocated);
9326 memset (arange_table + arange_table_in_use, 0,
9327 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
9330 arange_table[arange_table_in_use++] = die;
9333 /* Output the information that goes into the .debug_aranges table.
9334 Namely, define the beginning and ending address range of the
9335 text section generated for this compilation unit. */
9338 output_aranges (void)
9341 unsigned long aranges_length = size_of_aranges ();
9343 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9344 dw2_asm_output_data (4, 0xffffffff,
9345 "Initial length escape value indicating 64-bit DWARF extension");
9346 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9347 "Length of Address Ranges Info");
9348 /* Version number for aranges is still 2, even in DWARF3. */
9349 dw2_asm_output_data (2, 2, "DWARF Version");
9350 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9352 "Offset of Compilation Unit Info");
9353 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9354 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9356 /* We need to align to twice the pointer size here. */
9357 if (DWARF_ARANGES_PAD_SIZE)
9359 /* Pad using a 2 byte words so that padding is correct for any
9361 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9362 2 * DWARF2_ADDR_SIZE);
9363 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9364 dw2_asm_output_data (2, 0, NULL);
9367 /* It is necessary not to output these entries if the sections were
9368 not used; if the sections were not used, the length will be 0 and
9369 the address may end up as 0 if the section is discarded by ld
9370 --gc-sections, leaving an invalid (0, 0) entry that can be
9371 confused with the terminator. */
9372 if (text_section_used)
9374 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9375 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9376 text_section_label, "Length");
9378 if (cold_text_section_used)
9380 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9382 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9383 cold_text_section_label, "Length");
9386 for (i = 0; i < arange_table_in_use; i++)
9388 dw_die_ref die = arange_table[i];
9390 /* We shouldn't see aranges for DIEs outside of the main CU. */
9391 gcc_assert (die->die_mark);
9393 if (die->die_tag == DW_TAG_subprogram)
9395 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
9397 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
9398 get_AT_low_pc (die), "Length");
9402 /* A static variable; extract the symbol from DW_AT_location.
9403 Note that this code isn't currently hit, as we only emit
9404 aranges for functions (jason 9/23/99). */
9405 dw_attr_ref a = get_AT (die, DW_AT_location);
9406 dw_loc_descr_ref loc;
9408 gcc_assert (a && AT_class (a) == dw_val_class_loc);
9411 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
9413 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
9414 loc->dw_loc_oprnd1.v.val_addr, "Address");
9415 dw2_asm_output_data (DWARF2_ADDR_SIZE,
9416 get_AT_unsigned (die, DW_AT_byte_size),
9421 /* Output the terminator words. */
9422 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9423 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9426 /* Add a new entry to .debug_ranges. Return the offset at which it
9430 add_ranges_num (int num)
9432 unsigned int in_use = ranges_table_in_use;
9434 if (in_use == ranges_table_allocated)
9436 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9437 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9438 ranges_table_allocated);
9439 memset (ranges_table + ranges_table_in_use, 0,
9440 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9443 ranges_table[in_use].num = num;
9444 ranges_table_in_use = in_use + 1;
9446 return in_use * 2 * DWARF2_ADDR_SIZE;
9449 /* Add a new entry to .debug_ranges corresponding to a block, or a
9450 range terminator if BLOCK is NULL. */
9453 add_ranges (const_tree block)
9455 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9458 /* Add a new entry to .debug_ranges corresponding to a pair of
9462 add_ranges_by_labels (const char *begin, const char *end)
9464 unsigned int in_use = ranges_by_label_in_use;
9466 if (in_use == ranges_by_label_allocated)
9468 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9469 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9471 ranges_by_label_allocated);
9472 memset (ranges_by_label + ranges_by_label_in_use, 0,
9473 RANGES_TABLE_INCREMENT
9474 * sizeof (struct dw_ranges_by_label_struct));
9477 ranges_by_label[in_use].begin = begin;
9478 ranges_by_label[in_use].end = end;
9479 ranges_by_label_in_use = in_use + 1;
9481 return add_ranges_num (-(int)in_use - 1);
9485 output_ranges (void)
9488 static const char *const start_fmt = "Offset 0x%x";
9489 const char *fmt = start_fmt;
9491 for (i = 0; i < ranges_table_in_use; i++)
9493 int block_num = ranges_table[i].num;
9497 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9498 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9500 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9501 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9503 /* If all code is in the text section, then the compilation
9504 unit base address defaults to DW_AT_low_pc, which is the
9505 base of the text section. */
9506 if (!have_multiple_function_sections)
9508 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9510 fmt, i * 2 * DWARF2_ADDR_SIZE);
9511 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9512 text_section_label, NULL);
9515 /* Otherwise, the compilation unit base address is zero,
9516 which allows us to use absolute addresses, and not worry
9517 about whether the target supports cross-section
9521 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9522 fmt, i * 2 * DWARF2_ADDR_SIZE);
9523 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9529 /* Negative block_num stands for an index into ranges_by_label. */
9530 else if (block_num < 0)
9532 int lab_idx = - block_num - 1;
9534 if (!have_multiple_function_sections)
9538 /* If we ever use add_ranges_by_labels () for a single
9539 function section, all we have to do is to take out
9541 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9542 ranges_by_label[lab_idx].begin,
9544 fmt, i * 2 * DWARF2_ADDR_SIZE);
9545 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9546 ranges_by_label[lab_idx].end,
9547 text_section_label, NULL);
9552 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9553 ranges_by_label[lab_idx].begin,
9554 fmt, i * 2 * DWARF2_ADDR_SIZE);
9555 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9556 ranges_by_label[lab_idx].end,
9562 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9563 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9569 /* Data structure containing information about input files. */
9572 const char *path; /* Complete file name. */
9573 const char *fname; /* File name part. */
9574 int length; /* Length of entire string. */
9575 struct dwarf_file_data * file_idx; /* Index in input file table. */
9576 int dir_idx; /* Index in directory table. */
9579 /* Data structure containing information about directories with source
9583 const char *path; /* Path including directory name. */
9584 int length; /* Path length. */
9585 int prefix; /* Index of directory entry which is a prefix. */
9586 int count; /* Number of files in this directory. */
9587 int dir_idx; /* Index of directory used as base. */
9590 /* Callback function for file_info comparison. We sort by looking at
9591 the directories in the path. */
9594 file_info_cmp (const void *p1, const void *p2)
9596 const struct file_info *const s1 = (const struct file_info *) p1;
9597 const struct file_info *const s2 = (const struct file_info *) p2;
9598 const unsigned char *cp1;
9599 const unsigned char *cp2;
9601 /* Take care of file names without directories. We need to make sure that
9602 we return consistent values to qsort since some will get confused if
9603 we return the same value when identical operands are passed in opposite
9604 orders. So if neither has a directory, return 0 and otherwise return
9605 1 or -1 depending on which one has the directory. */
9606 if ((s1->path == s1->fname || s2->path == s2->fname))
9607 return (s2->path == s2->fname) - (s1->path == s1->fname);
9609 cp1 = (const unsigned char *) s1->path;
9610 cp2 = (const unsigned char *) s2->path;
9616 /* Reached the end of the first path? If so, handle like above. */
9617 if ((cp1 == (const unsigned char *) s1->fname)
9618 || (cp2 == (const unsigned char *) s2->fname))
9619 return ((cp2 == (const unsigned char *) s2->fname)
9620 - (cp1 == (const unsigned char *) s1->fname));
9622 /* Character of current path component the same? */
9623 else if (*cp1 != *cp2)
9628 struct file_name_acquire_data
9630 struct file_info *files;
9635 /* Traversal function for the hash table. */
9638 file_name_acquire (void ** slot, void *data)
9640 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9641 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9642 struct file_info *fi;
9645 gcc_assert (fnad->max_files >= d->emitted_number);
9647 if (! d->emitted_number)
9650 gcc_assert (fnad->max_files != fnad->used_files);
9652 fi = fnad->files + fnad->used_files++;
9654 /* Skip all leading "./". */
9656 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9659 /* Create a new array entry. */
9661 fi->length = strlen (f);
9664 /* Search for the file name part. */
9665 f = strrchr (f, DIR_SEPARATOR);
9666 #if defined (DIR_SEPARATOR_2)
9668 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9672 if (f == NULL || f < g)
9678 fi->fname = f == NULL ? fi->path : f + 1;
9682 /* Output the directory table and the file name table. We try to minimize
9683 the total amount of memory needed. A heuristic is used to avoid large
9684 slowdowns with many input files. */
9687 output_file_names (void)
9689 struct file_name_acquire_data fnad;
9691 struct file_info *files;
9692 struct dir_info *dirs;
9701 if (!last_emitted_file)
9703 dw2_asm_output_data (1, 0, "End directory table");
9704 dw2_asm_output_data (1, 0, "End file name table");
9708 numfiles = last_emitted_file->emitted_number;
9710 /* Allocate the various arrays we need. */
9711 files = XALLOCAVEC (struct file_info, numfiles);
9712 dirs = XALLOCAVEC (struct dir_info, numfiles);
9715 fnad.used_files = 0;
9716 fnad.max_files = numfiles;
9717 htab_traverse (file_table, file_name_acquire, &fnad);
9718 gcc_assert (fnad.used_files == fnad.max_files);
9720 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9722 /* Find all the different directories used. */
9723 dirs[0].path = files[0].path;
9724 dirs[0].length = files[0].fname - files[0].path;
9725 dirs[0].prefix = -1;
9727 dirs[0].dir_idx = 0;
9728 files[0].dir_idx = 0;
9731 for (i = 1; i < numfiles; i++)
9732 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9733 && memcmp (dirs[ndirs - 1].path, files[i].path,
9734 dirs[ndirs - 1].length) == 0)
9736 /* Same directory as last entry. */
9737 files[i].dir_idx = ndirs - 1;
9738 ++dirs[ndirs - 1].count;
9744 /* This is a new directory. */
9745 dirs[ndirs].path = files[i].path;
9746 dirs[ndirs].length = files[i].fname - files[i].path;
9747 dirs[ndirs].count = 1;
9748 dirs[ndirs].dir_idx = ndirs;
9749 files[i].dir_idx = ndirs;
9751 /* Search for a prefix. */
9752 dirs[ndirs].prefix = -1;
9753 for (j = 0; j < ndirs; j++)
9754 if (dirs[j].length < dirs[ndirs].length
9755 && dirs[j].length > 1
9756 && (dirs[ndirs].prefix == -1
9757 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9758 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9759 dirs[ndirs].prefix = j;
9764 /* Now to the actual work. We have to find a subset of the directories which
9765 allow expressing the file name using references to the directory table
9766 with the least amount of characters. We do not do an exhaustive search
9767 where we would have to check out every combination of every single
9768 possible prefix. Instead we use a heuristic which provides nearly optimal
9769 results in most cases and never is much off. */
9770 saved = XALLOCAVEC (int, ndirs);
9771 savehere = XALLOCAVEC (int, ndirs);
9773 memset (saved, '\0', ndirs * sizeof (saved[0]));
9774 for (i = 0; i < ndirs; i++)
9779 /* We can always save some space for the current directory. But this
9780 does not mean it will be enough to justify adding the directory. */
9781 savehere[i] = dirs[i].length;
9782 total = (savehere[i] - saved[i]) * dirs[i].count;
9784 for (j = i + 1; j < ndirs; j++)
9787 if (saved[j] < dirs[i].length)
9789 /* Determine whether the dirs[i] path is a prefix of the
9794 while (k != -1 && k != (int) i)
9799 /* Yes it is. We can possibly save some memory by
9800 writing the filenames in dirs[j] relative to
9802 savehere[j] = dirs[i].length;
9803 total += (savehere[j] - saved[j]) * dirs[j].count;
9808 /* Check whether we can save enough to justify adding the dirs[i]
9810 if (total > dirs[i].length + 1)
9812 /* It's worthwhile adding. */
9813 for (j = i; j < ndirs; j++)
9814 if (savehere[j] > 0)
9816 /* Remember how much we saved for this directory so far. */
9817 saved[j] = savehere[j];
9819 /* Remember the prefix directory. */
9820 dirs[j].dir_idx = i;
9825 /* Emit the directory name table. */
9827 idx_offset = dirs[0].length > 0 ? 1 : 0;
9828 for (i = 1 - idx_offset; i < ndirs; i++)
9829 dw2_asm_output_nstring (dirs[i].path,
9831 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9832 "Directory Entry: 0x%x", i + idx_offset);
9834 dw2_asm_output_data (1, 0, "End directory table");
9836 /* We have to emit them in the order of emitted_number since that's
9837 used in the debug info generation. To do this efficiently we
9838 generate a back-mapping of the indices first. */
9839 backmap = XALLOCAVEC (int, numfiles);
9840 for (i = 0; i < numfiles; i++)
9841 backmap[files[i].file_idx->emitted_number - 1] = i;
9843 /* Now write all the file names. */
9844 for (i = 0; i < numfiles; i++)
9846 int file_idx = backmap[i];
9847 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9849 #ifdef VMS_DEBUGGING_INFO
9850 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9852 /* Setting these fields can lead to debugger miscomparisons,
9853 but VMS Debug requires them to be set correctly. */
9858 int maxfilelen = strlen (files[file_idx].path)
9859 + dirs[dir_idx].length
9860 + MAX_VMS_VERSION_LEN + 1;
9861 char *filebuf = XALLOCAVEC (char, maxfilelen);
9863 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9864 snprintf (filebuf, maxfilelen, "%s;%d",
9865 files[file_idx].path + dirs[dir_idx].length, ver);
9867 dw2_asm_output_nstring
9868 (filebuf, -1, "File Entry: 0x%x", (unsigned) i + 1);
9870 /* Include directory index. */
9871 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9873 /* Modification time. */
9874 dw2_asm_output_data_uleb128
9875 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9879 /* File length in bytes. */
9880 dw2_asm_output_data_uleb128
9881 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9885 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9886 "File Entry: 0x%x", (unsigned) i + 1);
9888 /* Include directory index. */
9889 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9891 /* Modification time. */
9892 dw2_asm_output_data_uleb128 (0, NULL);
9894 /* File length in bytes. */
9895 dw2_asm_output_data_uleb128 (0, NULL);
9899 dw2_asm_output_data (1, 0, "End file name table");
9903 /* Output the source line number correspondence information. This
9904 information goes into the .debug_line section. */
9907 output_line_info (void)
9909 char l1[20], l2[20], p1[20], p2[20];
9910 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9911 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9914 unsigned long lt_index;
9915 unsigned long current_line;
9918 unsigned long current_file;
9919 unsigned long function;
9921 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9922 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9923 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9924 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9926 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9927 dw2_asm_output_data (4, 0xffffffff,
9928 "Initial length escape value indicating 64-bit DWARF extension");
9929 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9930 "Length of Source Line Info");
9931 ASM_OUTPUT_LABEL (asm_out_file, l1);
9933 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9934 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9935 ASM_OUTPUT_LABEL (asm_out_file, p1);
9937 /* Define the architecture-dependent minimum instruction length (in
9938 bytes). In this implementation of DWARF, this field is used for
9939 information purposes only. Since GCC generates assembly language,
9940 we have no a priori knowledge of how many instruction bytes are
9941 generated for each source line, and therefore can use only the
9942 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9943 commands. Accordingly, we fix this as `1', which is "correct
9944 enough" for all architectures, and don't let the target override. */
9945 dw2_asm_output_data (1, 1,
9946 "Minimum Instruction Length");
9948 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9949 "Default is_stmt_start flag");
9950 dw2_asm_output_data (1, DWARF_LINE_BASE,
9951 "Line Base Value (Special Opcodes)");
9952 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9953 "Line Range Value (Special Opcodes)");
9954 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9955 "Special Opcode Base");
9957 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9961 case DW_LNS_advance_pc:
9962 case DW_LNS_advance_line:
9963 case DW_LNS_set_file:
9964 case DW_LNS_set_column:
9965 case DW_LNS_fixed_advance_pc:
9973 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9977 /* Write out the information about the files we use. */
9978 output_file_names ();
9979 ASM_OUTPUT_LABEL (asm_out_file, p2);
9981 /* We used to set the address register to the first location in the text
9982 section here, but that didn't accomplish anything since we already
9983 have a line note for the opening brace of the first function. */
9985 /* Generate the line number to PC correspondence table, encoded as
9986 a series of state machine operations. */
9990 if (cfun && in_cold_section_p)
9991 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9993 strcpy (prev_line_label, text_section_label);
9994 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9996 dw_line_info_ref line_info = &line_info_table[lt_index];
9999 /* Disable this optimization for now; GDB wants to see two line notes
10000 at the beginning of a function so it can find the end of the
10003 /* Don't emit anything for redundant notes. Just updating the
10004 address doesn't accomplish anything, because we already assume
10005 that anything after the last address is this line. */
10006 if (line_info->dw_line_num == current_line
10007 && line_info->dw_file_num == current_file)
10011 /* Emit debug info for the address of the current line.
10013 Unfortunately, we have little choice here currently, and must always
10014 use the most general form. GCC does not know the address delta
10015 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
10016 attributes which will give an upper bound on the address range. We
10017 could perhaps use length attributes to determine when it is safe to
10018 use DW_LNS_fixed_advance_pc. */
10020 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
10023 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
10024 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10025 "DW_LNS_fixed_advance_pc");
10026 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10030 /* This can handle any delta. This takes
10031 4+DWARF2_ADDR_SIZE bytes. */
10032 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10033 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10034 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10035 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10038 strcpy (prev_line_label, line_label);
10040 /* Emit debug info for the source file of the current line, if
10041 different from the previous line. */
10042 if (line_info->dw_file_num != current_file)
10044 current_file = line_info->dw_file_num;
10045 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10046 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10049 /* Emit debug info for the current line number, choosing the encoding
10050 that uses the least amount of space. */
10051 if (line_info->dw_line_num != current_line)
10053 line_offset = line_info->dw_line_num - current_line;
10054 line_delta = line_offset - DWARF_LINE_BASE;
10055 current_line = line_info->dw_line_num;
10056 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10057 /* This can handle deltas from -10 to 234, using the current
10058 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
10060 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10061 "line %lu", current_line);
10064 /* This can handle any delta. This takes at least 4 bytes,
10065 depending on the value being encoded. */
10066 dw2_asm_output_data (1, DW_LNS_advance_line,
10067 "advance to line %lu", current_line);
10068 dw2_asm_output_data_sleb128 (line_offset, NULL);
10069 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10073 /* We still need to start a new row, so output a copy insn. */
10074 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10077 /* Emit debug info for the address of the end of the function. */
10080 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10081 "DW_LNS_fixed_advance_pc");
10082 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
10086 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10087 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10088 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10089 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
10092 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10093 dw2_asm_output_data_uleb128 (1, NULL);
10094 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10099 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
10101 dw_separate_line_info_ref line_info
10102 = &separate_line_info_table[lt_index];
10105 /* Don't emit anything for redundant notes. */
10106 if (line_info->dw_line_num == current_line
10107 && line_info->dw_file_num == current_file
10108 && line_info->function == function)
10112 /* Emit debug info for the address of the current line. If this is
10113 a new function, or the first line of a function, then we need
10114 to handle it differently. */
10115 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
10117 if (function != line_info->function)
10119 function = line_info->function;
10121 /* Set the address register to the first line in the function. */
10122 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10123 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10124 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10125 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10129 /* ??? See the DW_LNS_advance_pc comment above. */
10132 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10133 "DW_LNS_fixed_advance_pc");
10134 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10138 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10139 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10140 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10141 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10145 strcpy (prev_line_label, line_label);
10147 /* Emit debug info for the source file of the current line, if
10148 different from the previous line. */
10149 if (line_info->dw_file_num != current_file)
10151 current_file = line_info->dw_file_num;
10152 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10153 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10156 /* Emit debug info for the current line number, choosing the encoding
10157 that uses the least amount of space. */
10158 if (line_info->dw_line_num != current_line)
10160 line_offset = line_info->dw_line_num - current_line;
10161 line_delta = line_offset - DWARF_LINE_BASE;
10162 current_line = line_info->dw_line_num;
10163 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10164 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10165 "line %lu", current_line);
10168 dw2_asm_output_data (1, DW_LNS_advance_line,
10169 "advance to line %lu", current_line);
10170 dw2_asm_output_data_sleb128 (line_offset, NULL);
10171 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10175 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10183 /* If we're done with a function, end its sequence. */
10184 if (lt_index == separate_line_info_table_in_use
10185 || separate_line_info_table[lt_index].function != function)
10190 /* Emit debug info for the address of the end of the function. */
10191 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
10194 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10195 "DW_LNS_fixed_advance_pc");
10196 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10200 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10201 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10202 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10203 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10206 /* Output the marker for the end of this sequence. */
10207 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10208 dw2_asm_output_data_uleb128 (1, NULL);
10209 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10213 /* Output the marker for the end of the line number info. */
10214 ASM_OUTPUT_LABEL (asm_out_file, l2);
10217 /* Given a pointer to a tree node for some base type, return a pointer to
10218 a DIE that describes the given type.
10220 This routine must only be called for GCC type nodes that correspond to
10221 Dwarf base (fundamental) types. */
10224 base_type_die (tree type)
10226 dw_die_ref base_type_result;
10227 enum dwarf_type encoding;
10229 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10232 /* If this is a subtype that should not be emitted as a subrange type,
10233 use the base type. See subrange_type_for_debug_p. */
10234 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10235 type = TREE_TYPE (type);
10237 switch (TREE_CODE (type))
10240 if (TYPE_STRING_FLAG (type))
10242 if (TYPE_UNSIGNED (type))
10243 encoding = DW_ATE_unsigned_char;
10245 encoding = DW_ATE_signed_char;
10247 else if (TYPE_UNSIGNED (type))
10248 encoding = DW_ATE_unsigned;
10250 encoding = DW_ATE_signed;
10254 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10256 if (dwarf_version >= 3 || !dwarf_strict)
10257 encoding = DW_ATE_decimal_float;
10259 encoding = DW_ATE_lo_user;
10262 encoding = DW_ATE_float;
10265 case FIXED_POINT_TYPE:
10266 if (!(dwarf_version >= 3 || !dwarf_strict))
10267 encoding = DW_ATE_lo_user;
10268 else if (TYPE_UNSIGNED (type))
10269 encoding = DW_ATE_unsigned_fixed;
10271 encoding = DW_ATE_signed_fixed;
10274 /* Dwarf2 doesn't know anything about complex ints, so use
10275 a user defined type for it. */
10277 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10278 encoding = DW_ATE_complex_float;
10280 encoding = DW_ATE_lo_user;
10284 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10285 encoding = DW_ATE_boolean;
10289 /* No other TREE_CODEs are Dwarf fundamental types. */
10290 gcc_unreachable ();
10293 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
10295 /* This probably indicates a bug. */
10296 if (! TYPE_NAME (type))
10297 add_name_attribute (base_type_result, "__unknown__");
10299 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10300 int_size_in_bytes (type));
10301 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10303 return base_type_result;
10306 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10307 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10310 is_base_type (tree type)
10312 switch (TREE_CODE (type))
10318 case FIXED_POINT_TYPE:
10326 case QUAL_UNION_TYPE:
10327 case ENUMERAL_TYPE:
10328 case FUNCTION_TYPE:
10331 case REFERENCE_TYPE:
10338 gcc_unreachable ();
10344 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10345 node, return the size in bits for the type if it is a constant, or else
10346 return the alignment for the type if the type's size is not constant, or
10347 else return BITS_PER_WORD if the type actually turns out to be an
10348 ERROR_MARK node. */
10350 static inline unsigned HOST_WIDE_INT
10351 simple_type_size_in_bits (const_tree type)
10353 if (TREE_CODE (type) == ERROR_MARK)
10354 return BITS_PER_WORD;
10355 else if (TYPE_SIZE (type) == NULL_TREE)
10357 else if (host_integerp (TYPE_SIZE (type), 1))
10358 return tree_low_cst (TYPE_SIZE (type), 1);
10360 return TYPE_ALIGN (type);
10363 /* Given a pointer to a tree node for a subrange type, return a pointer
10364 to a DIE that describes the given type. */
10367 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10369 dw_die_ref subrange_die;
10370 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10372 if (context_die == NULL)
10373 context_die = comp_unit_die;
10375 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10377 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10379 /* The size of the subrange type and its base type do not match,
10380 so we need to generate a size attribute for the subrange type. */
10381 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10385 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10387 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10389 return subrange_die;
10392 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10393 entry that chains various modifiers in front of the given type. */
10396 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10397 dw_die_ref context_die)
10399 enum tree_code code = TREE_CODE (type);
10400 dw_die_ref mod_type_die;
10401 dw_die_ref sub_die = NULL;
10402 tree item_type = NULL;
10403 tree qualified_type;
10404 tree name, low, high;
10406 if (code == ERROR_MARK)
10409 /* See if we already have the appropriately qualified variant of
10412 = get_qualified_type (type,
10413 ((is_const_type ? TYPE_QUAL_CONST : 0)
10414 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10416 /* If we do, then we can just use its DIE, if it exists. */
10417 if (qualified_type)
10419 mod_type_die = lookup_type_die (qualified_type);
10421 return mod_type_die;
10424 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10426 /* Handle C typedef types. */
10427 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
10429 tree dtype = TREE_TYPE (name);
10431 if (qualified_type == dtype)
10433 /* For a named type, use the typedef. */
10434 gen_type_die (qualified_type, context_die);
10435 return lookup_type_die (qualified_type);
10437 else if (is_const_type < TYPE_READONLY (dtype)
10438 || is_volatile_type < TYPE_VOLATILE (dtype)
10439 || (is_const_type <= TYPE_READONLY (dtype)
10440 && is_volatile_type <= TYPE_VOLATILE (dtype)
10441 && DECL_ORIGINAL_TYPE (name) != type))
10442 /* cv-unqualified version of named type. Just use the unnamed
10443 type to which it refers. */
10444 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10445 is_const_type, is_volatile_type,
10447 /* Else cv-qualified version of named type; fall through. */
10452 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
10453 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10455 else if (is_volatile_type)
10457 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
10458 sub_die = modified_type_die (type, 0, 0, context_die);
10460 else if (code == POINTER_TYPE)
10462 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
10463 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10464 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10465 item_type = TREE_TYPE (type);
10467 else if (code == REFERENCE_TYPE)
10469 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
10470 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10471 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10472 item_type = TREE_TYPE (type);
10474 else if (code == INTEGER_TYPE
10475 && TREE_TYPE (type) != NULL_TREE
10476 && subrange_type_for_debug_p (type, &low, &high))
10478 mod_type_die = subrange_type_die (type, low, high, context_die);
10479 item_type = TREE_TYPE (type);
10481 else if (is_base_type (type))
10482 mod_type_die = base_type_die (type);
10485 gen_type_die (type, context_die);
10487 /* We have to get the type_main_variant here (and pass that to the
10488 `lookup_type_die' routine) because the ..._TYPE node we have
10489 might simply be a *copy* of some original type node (where the
10490 copy was created to help us keep track of typedef names) and
10491 that copy might have a different TYPE_UID from the original
10493 if (TREE_CODE (type) != VECTOR_TYPE)
10494 return lookup_type_die (type_main_variant (type));
10496 /* Vectors have the debugging information in the type,
10497 not the main variant. */
10498 return lookup_type_die (type);
10501 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10502 don't output a DW_TAG_typedef, since there isn't one in the
10503 user's program; just attach a DW_AT_name to the type. */
10505 && (TREE_CODE (name) != TYPE_DECL
10506 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
10508 if (TREE_CODE (name) == TYPE_DECL)
10509 /* Could just call add_name_and_src_coords_attributes here,
10510 but since this is a builtin type it doesn't have any
10511 useful source coordinates anyway. */
10512 name = DECL_NAME (name);
10513 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10516 if (qualified_type)
10517 equate_type_number_to_die (qualified_type, mod_type_die);
10520 /* We must do this after the equate_type_number_to_die call, in case
10521 this is a recursive type. This ensures that the modified_type_die
10522 recursion will terminate even if the type is recursive. Recursive
10523 types are possible in Ada. */
10524 sub_die = modified_type_die (item_type,
10525 TYPE_READONLY (item_type),
10526 TYPE_VOLATILE (item_type),
10529 if (sub_die != NULL)
10530 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10532 return mod_type_die;
10535 /* Generate DIEs for the generic parameters of T.
10536 T must be either a generic type or a generic function.
10537 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10540 gen_generic_params_dies (tree t)
10544 dw_die_ref die = NULL;
10546 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10550 die = lookup_type_die (t);
10551 else if (DECL_P (t))
10552 die = lookup_decl_die (t);
10556 parms = lang_hooks.get_innermost_generic_parms (t);
10558 /* T has no generic parameter. It means T is neither a generic type
10559 or function. End of story. */
10562 parms_num = TREE_VEC_LENGTH (parms);
10563 args = lang_hooks.get_innermost_generic_args (t);
10564 for (i = 0; i < parms_num; i++)
10566 tree parm, arg, arg_pack_elems;
10568 parm = TREE_VEC_ELT (parms, i);
10569 arg = TREE_VEC_ELT (args, i);
10570 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
10571 gcc_assert (parm && TREE_VALUE (parm) && arg);
10573 if (parm && TREE_VALUE (parm) && arg)
10575 /* If PARM represents a template parameter pack,
10576 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10577 by DW_TAG_template_*_parameter DIEs for the argument
10578 pack elements of ARG. Note that ARG would then be
10579 an argument pack. */
10580 if (arg_pack_elems)
10581 template_parameter_pack_die (TREE_VALUE (parm),
10585 generic_parameter_die (TREE_VALUE (parm), arg,
10586 true /* Emit DW_AT_name */, die);
10591 /* Create and return a DIE for PARM which should be
10592 the representation of a generic type parameter.
10593 For instance, in the C++ front end, PARM would be a template parameter.
10594 ARG is the argument to PARM.
10595 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10597 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10598 as a child node. */
10601 generic_parameter_die (tree parm, tree arg,
10603 dw_die_ref parent_die)
10605 dw_die_ref tmpl_die = NULL;
10606 const char *name = NULL;
10608 if (!parm || !DECL_NAME (parm) || !arg)
10611 /* We support non-type generic parameters and arguments,
10612 type generic parameters and arguments, as well as
10613 generic generic parameters (a.k.a. template template parameters in C++)
10615 if (TREE_CODE (parm) == PARM_DECL)
10616 /* PARM is a nontype generic parameter */
10617 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10618 else if (TREE_CODE (parm) == TYPE_DECL)
10619 /* PARM is a type generic parameter. */
10620 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10621 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10622 /* PARM is a generic generic parameter.
10623 Its DIE is a GNU extension. It shall have a
10624 DW_AT_name attribute to represent the name of the template template
10625 parameter, and a DW_AT_GNU_template_name attribute to represent the
10626 name of the template template argument. */
10627 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10630 gcc_unreachable ();
10636 /* If PARM is a generic parameter pack, it means we are
10637 emitting debug info for a template argument pack element.
10638 In other terms, ARG is a template argument pack element.
10639 In that case, we don't emit any DW_AT_name attribute for
10643 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10645 add_AT_string (tmpl_die, DW_AT_name, name);
10648 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10650 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10651 TMPL_DIE should have a child DW_AT_type attribute that is set
10652 to the type of the argument to PARM, which is ARG.
10653 If PARM is a type generic parameter, TMPL_DIE should have a
10654 child DW_AT_type that is set to ARG. */
10655 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10656 add_type_attribute (tmpl_die, tmpl_type, 0,
10657 TREE_THIS_VOLATILE (tmpl_type),
10662 /* So TMPL_DIE is a DIE representing a
10663 a generic generic template parameter, a.k.a template template
10664 parameter in C++ and arg is a template. */
10666 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10667 to the name of the argument. */
10668 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10669 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10672 if (TREE_CODE (parm) == PARM_DECL)
10673 /* So PARM is a non-type generic parameter.
10674 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10675 attribute of TMPL_DIE which value represents the value
10677 We must be careful here:
10678 The value of ARG might reference some function decls.
10679 We might currently be emitting debug info for a generic
10680 type and types are emitted before function decls, we don't
10681 know if the function decls referenced by ARG will actually be
10682 emitted after cgraph computations.
10683 So must defer the generation of the DW_AT_const_value to
10684 after cgraph is ready. */
10685 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10691 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10692 PARM_PACK must be a template parameter pack. The returned DIE
10693 will be child DIE of PARENT_DIE. */
10696 template_parameter_pack_die (tree parm_pack,
10697 tree parm_pack_args,
10698 dw_die_ref parent_die)
10703 gcc_assert (parent_die
10705 && DECL_NAME (parm_pack));
10707 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
10708 add_AT_string (die, DW_AT_name, IDENTIFIER_POINTER (DECL_NAME (parm_pack)));
10710 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
10711 generic_parameter_die (parm_pack,
10712 TREE_VEC_ELT (parm_pack_args, j),
10713 false /* Don't emit DW_AT_name */,
10718 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10719 an enumerated type. */
10722 type_is_enum (const_tree type)
10724 return TREE_CODE (type) == ENUMERAL_TYPE;
10727 /* Return the DBX register number described by a given RTL node. */
10729 static unsigned int
10730 dbx_reg_number (const_rtx rtl)
10732 unsigned regno = REGNO (rtl);
10734 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10736 #ifdef LEAF_REG_REMAP
10737 if (current_function_uses_only_leaf_regs)
10739 int leaf_reg = LEAF_REG_REMAP (regno);
10740 if (leaf_reg != -1)
10741 regno = (unsigned) leaf_reg;
10745 return DBX_REGISTER_NUMBER (regno);
10748 /* Optionally add a DW_OP_piece term to a location description expression.
10749 DW_OP_piece is only added if the location description expression already
10750 doesn't end with DW_OP_piece. */
10753 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10755 dw_loc_descr_ref loc;
10757 if (*list_head != NULL)
10759 /* Find the end of the chain. */
10760 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10763 if (loc->dw_loc_opc != DW_OP_piece)
10764 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10768 /* Return a location descriptor that designates a machine register or
10769 zero if there is none. */
10771 static dw_loc_descr_ref
10772 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10776 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10779 regs = targetm.dwarf_register_span (rtl);
10781 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10782 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10784 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10787 /* Return a location descriptor that designates a machine register for
10788 a given hard register number. */
10790 static dw_loc_descr_ref
10791 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10793 dw_loc_descr_ref reg_loc_descr;
10797 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10799 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10801 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10802 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10804 return reg_loc_descr;
10807 /* Given an RTL of a register, return a location descriptor that
10808 designates a value that spans more than one register. */
10810 static dw_loc_descr_ref
10811 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10812 enum var_init_status initialized)
10814 int nregs, size, i;
10816 dw_loc_descr_ref loc_result = NULL;
10819 #ifdef LEAF_REG_REMAP
10820 if (current_function_uses_only_leaf_regs)
10822 int leaf_reg = LEAF_REG_REMAP (reg);
10823 if (leaf_reg != -1)
10824 reg = (unsigned) leaf_reg;
10827 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10828 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10830 /* Simple, contiguous registers. */
10831 if (regs == NULL_RTX)
10833 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10838 dw_loc_descr_ref t;
10840 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10841 VAR_INIT_STATUS_INITIALIZED);
10842 add_loc_descr (&loc_result, t);
10843 add_loc_descr_op_piece (&loc_result, size);
10849 /* Now onto stupid register sets in non contiguous locations. */
10851 gcc_assert (GET_CODE (regs) == PARALLEL);
10853 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10856 for (i = 0; i < XVECLEN (regs, 0); ++i)
10858 dw_loc_descr_ref t;
10860 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10861 VAR_INIT_STATUS_INITIALIZED);
10862 add_loc_descr (&loc_result, t);
10863 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10864 add_loc_descr_op_piece (&loc_result, size);
10867 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10868 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10872 #endif /* DWARF2_DEBUGGING_INFO */
10874 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10876 /* Return a location descriptor that designates a constant. */
10878 static dw_loc_descr_ref
10879 int_loc_descriptor (HOST_WIDE_INT i)
10881 enum dwarf_location_atom op;
10883 /* Pick the smallest representation of a constant, rather than just
10884 defaulting to the LEB encoding. */
10888 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10889 else if (i <= 0xff)
10890 op = DW_OP_const1u;
10891 else if (i <= 0xffff)
10892 op = DW_OP_const2u;
10893 else if (HOST_BITS_PER_WIDE_INT == 32
10894 || i <= 0xffffffff)
10895 op = DW_OP_const4u;
10902 op = DW_OP_const1s;
10903 else if (i >= -0x8000)
10904 op = DW_OP_const2s;
10905 else if (HOST_BITS_PER_WIDE_INT == 32
10906 || i >= -0x80000000)
10907 op = DW_OP_const4s;
10912 return new_loc_descr (op, i, 0);
10916 #ifdef DWARF2_DEBUGGING_INFO
10917 /* Return loc description representing "address" of integer value.
10918 This can appear only as toplevel expression. */
10920 static dw_loc_descr_ref
10921 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10924 dw_loc_descr_ref loc_result = NULL;
10926 if (!(dwarf_version >= 4 || !dwarf_strict))
10933 else if (i <= 0xff)
10935 else if (i <= 0xffff)
10937 else if (HOST_BITS_PER_WIDE_INT == 32
10938 || i <= 0xffffffff)
10941 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10947 else if (i >= -0x8000)
10949 else if (HOST_BITS_PER_WIDE_INT == 32
10950 || i >= -0x80000000)
10953 litsize = 1 + size_of_sleb128 (i);
10955 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10956 is more compact. For DW_OP_stack_value we need:
10957 litsize + 1 (DW_OP_stack_value)
10958 and for DW_OP_implicit_value:
10959 1 (DW_OP_implicit_value) + 1 (length) + size. */
10960 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10962 loc_result = int_loc_descriptor (i);
10963 add_loc_descr (&loc_result,
10964 new_loc_descr (DW_OP_stack_value, 0, 0));
10968 loc_result = new_loc_descr (DW_OP_implicit_value,
10970 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
10971 loc_result->dw_loc_oprnd2.v.val_int = i;
10975 /* Return a location descriptor that designates a base+offset location. */
10977 static dw_loc_descr_ref
10978 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10979 enum var_init_status initialized)
10981 unsigned int regno;
10982 dw_loc_descr_ref result;
10983 dw_fde_ref fde = current_fde ();
10985 /* We only use "frame base" when we're sure we're talking about the
10986 post-prologue local stack frame. We do this by *not* running
10987 register elimination until this point, and recognizing the special
10988 argument pointer and soft frame pointer rtx's. */
10989 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10991 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10995 if (GET_CODE (elim) == PLUS)
10997 offset += INTVAL (XEXP (elim, 1));
10998 elim = XEXP (elim, 0);
11000 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11001 && (elim == hard_frame_pointer_rtx
11002 || elim == stack_pointer_rtx))
11003 || elim == (frame_pointer_needed
11004 ? hard_frame_pointer_rtx
11005 : stack_pointer_rtx));
11007 /* If drap register is used to align stack, use frame
11008 pointer + offset to access stack variables. If stack
11009 is aligned without drap, use stack pointer + offset to
11010 access stack variables. */
11011 if (crtl->stack_realign_tried
11012 && reg == frame_pointer_rtx)
11015 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
11016 ? HARD_FRAME_POINTER_REGNUM
11017 : STACK_POINTER_REGNUM);
11018 return new_reg_loc_descr (base_reg, offset);
11021 offset += frame_pointer_fb_offset;
11022 return new_loc_descr (DW_OP_fbreg, offset, 0);
11026 && fde->drap_reg != INVALID_REGNUM
11027 && (fde->drap_reg == REGNO (reg)
11028 || fde->vdrap_reg == REGNO (reg)))
11030 /* Use cfa+offset to represent the location of arguments passed
11031 on stack when drap is used to align stack. */
11032 return new_loc_descr (DW_OP_fbreg, offset, 0);
11035 regno = dbx_reg_number (reg);
11037 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
11040 result = new_loc_descr (DW_OP_bregx, regno, offset);
11042 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11043 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11048 /* Return true if this RTL expression describes a base+offset calculation. */
11051 is_based_loc (const_rtx rtl)
11053 return (GET_CODE (rtl) == PLUS
11054 && ((REG_P (XEXP (rtl, 0))
11055 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
11056 && CONST_INT_P (XEXP (rtl, 1)))));
11059 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11062 static dw_loc_descr_ref
11063 tls_mem_loc_descriptor (rtx mem)
11066 dw_loc_descr_ref loc_result;
11068 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
11071 base = get_base_address (MEM_EXPR (mem));
11073 || TREE_CODE (base) != VAR_DECL
11074 || !DECL_THREAD_LOCAL_P (base))
11077 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
11078 if (loc_result == NULL)
11081 if (INTVAL (MEM_OFFSET (mem)))
11082 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
11087 /* Output debug info about reason why we failed to expand expression as dwarf
11091 expansion_failed (tree expr, rtx rtl, char const *reason)
11093 if (dump_file && (dump_flags & TDF_DETAILS))
11095 fprintf (dump_file, "Failed to expand as dwarf: ");
11097 print_generic_expr (dump_file, expr, dump_flags);
11100 fprintf (dump_file, "\n");
11101 print_rtl (dump_file, rtl);
11103 fprintf (dump_file, "\nReason: %s\n", reason);
11107 /* The following routine converts the RTL for a variable or parameter
11108 (resident in memory) into an equivalent Dwarf representation of a
11109 mechanism for getting the address of that same variable onto the top of a
11110 hypothetical "address evaluation" stack.
11112 When creating memory location descriptors, we are effectively transforming
11113 the RTL for a memory-resident object into its Dwarf postfix expression
11114 equivalent. This routine recursively descends an RTL tree, turning
11115 it into Dwarf postfix code as it goes.
11117 MODE is the mode of the memory reference, needed to handle some
11118 autoincrement addressing modes.
11120 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
11121 location list for RTL.
11123 Return 0 if we can't represent the location. */
11125 static dw_loc_descr_ref
11126 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11127 enum var_init_status initialized)
11129 dw_loc_descr_ref mem_loc_result = NULL;
11130 enum dwarf_location_atom op;
11131 dw_loc_descr_ref op0, op1;
11133 /* Note that for a dynamically sized array, the location we will generate a
11134 description of here will be the lowest numbered location which is
11135 actually within the array. That's *not* necessarily the same as the
11136 zeroth element of the array. */
11138 rtl = targetm.delegitimize_address (rtl);
11140 switch (GET_CODE (rtl))
11145 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
11146 just fall into the SUBREG code. */
11148 /* ... fall through ... */
11151 /* The case of a subreg may arise when we have a local (register)
11152 variable or a formal (register) parameter which doesn't quite fill
11153 up an entire register. For now, just assume that it is
11154 legitimate to make the Dwarf info refer to the whole register which
11155 contains the given subreg. */
11156 rtl = XEXP (rtl, 0);
11157 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
11159 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
11163 /* Whenever a register number forms a part of the description of the
11164 method for calculating the (dynamic) address of a memory resident
11165 object, DWARF rules require the register number be referred to as
11166 a "base register". This distinction is not based in any way upon
11167 what category of register the hardware believes the given register
11168 belongs to. This is strictly DWARF terminology we're dealing with
11169 here. Note that in cases where the location of a memory-resident
11170 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11171 OP_CONST (0)) the actual DWARF location descriptor that we generate
11172 may just be OP_BASEREG (basereg). This may look deceptively like
11173 the object in question was allocated to a register (rather than in
11174 memory) so DWARF consumers need to be aware of the subtle
11175 distinction between OP_REG and OP_BASEREG. */
11176 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11177 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11178 else if (stack_realign_drap
11180 && crtl->args.internal_arg_pointer == rtl
11181 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11183 /* If RTL is internal_arg_pointer, which has been optimized
11184 out, use DRAP instead. */
11185 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11186 VAR_INIT_STATUS_INITIALIZED);
11192 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11193 VAR_INIT_STATUS_INITIALIZED);
11198 int shift = DWARF2_ADDR_SIZE
11199 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11200 shift *= BITS_PER_UNIT;
11201 if (GET_CODE (rtl) == SIGN_EXTEND)
11205 mem_loc_result = op0;
11206 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11207 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11208 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11209 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11214 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11215 VAR_INIT_STATUS_INITIALIZED);
11216 if (mem_loc_result == NULL)
11217 mem_loc_result = tls_mem_loc_descriptor (rtl);
11218 if (mem_loc_result != 0)
11219 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11223 rtl = XEXP (rtl, 1);
11225 /* ... fall through ... */
11228 /* Some ports can transform a symbol ref into a label ref, because
11229 the symbol ref is too far away and has to be dumped into a constant
11233 /* Alternatively, the symbol in the constant pool might be referenced
11234 by a different symbol. */
11235 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
11238 rtx tmp = get_pool_constant_mark (rtl, &marked);
11240 if (GET_CODE (tmp) == SYMBOL_REF)
11243 if (CONSTANT_POOL_ADDRESS_P (tmp))
11244 get_pool_constant_mark (tmp, &marked);
11249 /* If all references to this pool constant were optimized away,
11250 it was not output and thus we can't represent it.
11251 FIXME: might try to use DW_OP_const_value here, though
11252 DW_OP_piece complicates it. */
11255 expansion_failed (NULL_TREE, rtl,
11256 "Constant was removed from constant pool.\n");
11261 if (GET_CODE (rtl) == SYMBOL_REF
11262 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11264 dw_loc_descr_ref temp;
11266 /* If this is not defined, we have no way to emit the data. */
11267 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11270 temp = new_loc_descr (DW_OP_addr, 0, 0);
11271 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11272 temp->dw_loc_oprnd1.v.val_addr = rtl;
11273 temp->dtprel = true;
11275 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11276 add_loc_descr (&mem_loc_result, temp);
11281 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11282 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11283 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11284 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11290 expansion_failed (NULL_TREE, rtl,
11291 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11292 gcc_unreachable ();
11296 /* Extract the PLUS expression nested inside and fall into
11297 PLUS code below. */
11298 rtl = XEXP (rtl, 1);
11303 /* Turn these into a PLUS expression and fall into the PLUS code
11305 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
11306 GEN_INT (GET_CODE (rtl) == PRE_INC
11307 ? GET_MODE_UNIT_SIZE (mode)
11308 : -GET_MODE_UNIT_SIZE (mode)));
11310 /* ... fall through ... */
11314 if (is_based_loc (rtl))
11315 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11316 INTVAL (XEXP (rtl, 1)),
11317 VAR_INIT_STATUS_INITIALIZED);
11320 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
11321 VAR_INIT_STATUS_INITIALIZED);
11322 if (mem_loc_result == 0)
11325 if (CONST_INT_P (XEXP (rtl, 1)))
11326 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11329 dw_loc_descr_ref mem_loc_result2
11330 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11331 VAR_INIT_STATUS_INITIALIZED);
11332 if (mem_loc_result2 == 0)
11334 add_loc_descr (&mem_loc_result, mem_loc_result2);
11335 add_loc_descr (&mem_loc_result,
11336 new_loc_descr (DW_OP_plus, 0, 0));
11341 /* If a pseudo-reg is optimized away, it is possible for it to
11342 be replaced with a MEM containing a multiply or shift. */
11384 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11385 VAR_INIT_STATUS_INITIALIZED);
11386 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11387 VAR_INIT_STATUS_INITIALIZED);
11389 if (op0 == 0 || op1 == 0)
11392 mem_loc_result = op0;
11393 add_loc_descr (&mem_loc_result, op1);
11394 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11410 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11411 VAR_INIT_STATUS_INITIALIZED);
11416 mem_loc_result = op0;
11417 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11421 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11449 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11450 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11451 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11454 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11455 VAR_INIT_STATUS_INITIALIZED);
11456 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11457 VAR_INIT_STATUS_INITIALIZED);
11459 if (op0 == 0 || op1 == 0)
11462 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11464 int shift = DWARF2_ADDR_SIZE
11465 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11466 shift *= BITS_PER_UNIT;
11467 add_loc_descr (&op0, int_loc_descriptor (shift));
11468 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11469 if (CONST_INT_P (XEXP (rtl, 1)))
11470 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
11473 add_loc_descr (&op1, int_loc_descriptor (shift));
11474 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11479 mem_loc_result = op0;
11480 add_loc_descr (&mem_loc_result, op1);
11481 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11482 if (STORE_FLAG_VALUE != 1)
11484 add_loc_descr (&mem_loc_result,
11485 int_loc_descriptor (STORE_FLAG_VALUE));
11486 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11507 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11508 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11509 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11512 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11513 VAR_INIT_STATUS_INITIALIZED);
11514 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11515 VAR_INIT_STATUS_INITIALIZED);
11517 if (op0 == 0 || op1 == 0)
11520 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11522 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11523 add_loc_descr (&op0, int_loc_descriptor (mask));
11524 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11525 if (CONST_INT_P (XEXP (rtl, 1)))
11526 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11529 add_loc_descr (&op1, int_loc_descriptor (mask));
11530 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11535 HOST_WIDE_INT bias = 1;
11536 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11537 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11538 if (CONST_INT_P (XEXP (rtl, 1)))
11539 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11540 + INTVAL (XEXP (rtl, 1)));
11542 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11550 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11551 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11552 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11555 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11556 VAR_INIT_STATUS_INITIALIZED);
11557 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11558 VAR_INIT_STATUS_INITIALIZED);
11560 if (op0 == 0 || op1 == 0)
11563 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11564 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11565 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11566 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11568 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11570 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11571 add_loc_descr (&op0, int_loc_descriptor (mask));
11572 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11573 add_loc_descr (&op1, int_loc_descriptor (mask));
11574 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11578 HOST_WIDE_INT bias = 1;
11579 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11580 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11581 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11584 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11586 int shift = DWARF2_ADDR_SIZE
11587 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11588 shift *= BITS_PER_UNIT;
11589 add_loc_descr (&op0, int_loc_descriptor (shift));
11590 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11591 add_loc_descr (&op1, int_loc_descriptor (shift));
11592 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11595 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11599 mem_loc_result = op0;
11600 add_loc_descr (&mem_loc_result, op1);
11601 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11603 dw_loc_descr_ref bra_node, drop_node;
11605 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11606 add_loc_descr (&mem_loc_result, bra_node);
11607 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
11608 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11609 add_loc_descr (&mem_loc_result, drop_node);
11610 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11611 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11617 if (CONST_INT_P (XEXP (rtl, 1))
11618 && CONST_INT_P (XEXP (rtl, 2))
11619 && ((unsigned) INTVAL (XEXP (rtl, 1))
11620 + (unsigned) INTVAL (XEXP (rtl, 2))
11621 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
11622 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
11623 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
11626 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11627 VAR_INIT_STATUS_INITIALIZED);
11630 if (GET_CODE (rtl) == SIGN_EXTRACT)
11634 mem_loc_result = op0;
11635 size = INTVAL (XEXP (rtl, 1));
11636 shift = INTVAL (XEXP (rtl, 2));
11637 if (BITS_BIG_ENDIAN)
11638 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11640 add_loc_descr (&mem_loc_result,
11641 int_loc_descriptor (DWARF2_ADDR_SIZE - shift - size));
11642 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11643 add_loc_descr (&mem_loc_result,
11644 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
11645 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11654 /* In theory, we could implement the above. */
11655 /* DWARF cannot represent the unsigned compare operations
11671 case FLOAT_TRUNCATE:
11673 case UNSIGNED_FLOAT:
11676 case FRACT_CONVERT:
11677 case UNSIGNED_FRACT_CONVERT:
11679 case UNSIGNED_SAT_FRACT:
11690 /* If delegitimize_address couldn't do anything with the UNSPEC, we
11691 can't express it in the debug info. This can happen e.g. with some
11696 /* These can't easily be tracked, see PR41404. */
11700 #ifdef ENABLE_CHECKING
11701 print_rtl (stderr, rtl);
11702 gcc_unreachable ();
11708 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11709 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11711 return mem_loc_result;
11714 /* Return a descriptor that describes the concatenation of two locations.
11715 This is typically a complex variable. */
11717 static dw_loc_descr_ref
11718 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
11720 dw_loc_descr_ref cc_loc_result = NULL;
11721 dw_loc_descr_ref x0_ref
11722 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11723 dw_loc_descr_ref x1_ref
11724 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11726 if (x0_ref == 0 || x1_ref == 0)
11729 cc_loc_result = x0_ref;
11730 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
11732 add_loc_descr (&cc_loc_result, x1_ref);
11733 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
11735 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11736 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11738 return cc_loc_result;
11741 /* Return a descriptor that describes the concatenation of N
11744 static dw_loc_descr_ref
11745 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
11748 dw_loc_descr_ref cc_loc_result = NULL;
11749 unsigned int n = XVECLEN (concatn, 0);
11751 for (i = 0; i < n; ++i)
11753 dw_loc_descr_ref ref;
11754 rtx x = XVECEXP (concatn, 0, i);
11756 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11760 add_loc_descr (&cc_loc_result, ref);
11761 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
11764 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11765 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11767 return cc_loc_result;
11770 /* Output a proper Dwarf location descriptor for a variable or parameter
11771 which is either allocated in a register or in a memory location. For a
11772 register, we just generate an OP_REG and the register number. For a
11773 memory location we provide a Dwarf postfix expression describing how to
11774 generate the (dynamic) address of the object onto the address stack.
11776 MODE is mode of the decl if this loc_descriptor is going to be used in
11777 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
11778 allowed, VOIDmode otherwise.
11780 If we don't know how to describe it, return 0. */
11782 static dw_loc_descr_ref
11783 loc_descriptor (rtx rtl, enum machine_mode mode,
11784 enum var_init_status initialized)
11786 dw_loc_descr_ref loc_result = NULL;
11788 switch (GET_CODE (rtl))
11791 /* The case of a subreg may arise when we have a local (register)
11792 variable or a formal (register) parameter which doesn't quite fill
11793 up an entire register. For now, just assume that it is
11794 legitimate to make the Dwarf info refer to the whole register which
11795 contains the given subreg. */
11796 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
11800 loc_result = reg_loc_descriptor (rtl, initialized);
11805 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11809 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11811 if (loc_result == NULL)
11812 loc_result = tls_mem_loc_descriptor (rtl);
11816 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
11821 loc_result = concatn_loc_descriptor (rtl, initialized);
11826 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
11828 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), mode,
11833 rtl = XEXP (rtl, 1);
11838 rtvec par_elems = XVEC (rtl, 0);
11839 int num_elem = GET_NUM_ELEM (par_elems);
11840 enum machine_mode mode;
11843 /* Create the first one, so we have something to add to. */
11844 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
11845 VOIDmode, initialized);
11846 if (loc_result == NULL)
11848 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
11849 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11850 for (i = 1; i < num_elem; i++)
11852 dw_loc_descr_ref temp;
11854 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
11855 VOIDmode, initialized);
11858 add_loc_descr (&loc_result, temp);
11859 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
11860 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11866 if (mode != VOIDmode && mode != BLKmode)
11867 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
11872 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
11874 /* Note that a CONST_DOUBLE rtx could represent either an integer
11875 or a floating-point constant. A CONST_DOUBLE is used whenever
11876 the constant requires more than one word in order to be
11877 adequately represented. We output CONST_DOUBLEs as blocks. */
11878 if (GET_MODE (rtl) != VOIDmode)
11879 mode = GET_MODE (rtl);
11881 loc_result = new_loc_descr (DW_OP_implicit_value,
11882 GET_MODE_SIZE (mode), 0);
11883 if (SCALAR_FLOAT_MODE_P (mode))
11885 unsigned int length = GET_MODE_SIZE (mode);
11886 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11888 insert_float (rtl, array);
11889 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11890 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
11891 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
11892 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11896 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
11897 loc_result->dw_loc_oprnd2.v.val_double.high
11898 = CONST_DOUBLE_HIGH (rtl);
11899 loc_result->dw_loc_oprnd2.v.val_double.low
11900 = CONST_DOUBLE_LOW (rtl);
11906 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
11908 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
11909 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11910 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11914 mode = GET_MODE (rtl);
11915 switch (GET_MODE_CLASS (mode))
11917 case MODE_VECTOR_INT:
11918 for (i = 0, p = array; i < length; i++, p += elt_size)
11920 rtx elt = CONST_VECTOR_ELT (rtl, i);
11921 HOST_WIDE_INT lo, hi;
11923 switch (GET_CODE (elt))
11931 lo = CONST_DOUBLE_LOW (elt);
11932 hi = CONST_DOUBLE_HIGH (elt);
11936 gcc_unreachable ();
11939 if (elt_size <= sizeof (HOST_WIDE_INT))
11940 insert_int (lo, elt_size, p);
11943 unsigned char *p0 = p;
11944 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11946 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11947 if (WORDS_BIG_ENDIAN)
11952 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11953 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11958 case MODE_VECTOR_FLOAT:
11959 for (i = 0, p = array; i < length; i++, p += elt_size)
11961 rtx elt = CONST_VECTOR_ELT (rtl, i);
11962 insert_float (elt, p);
11967 gcc_unreachable ();
11970 loc_result = new_loc_descr (DW_OP_implicit_value,
11971 length * elt_size, 0);
11972 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11973 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
11974 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
11975 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11980 if (mode == VOIDmode
11981 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
11982 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
11983 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
11985 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11990 if (GET_CODE (rtl) == SYMBOL_REF
11991 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11994 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
11995 && (dwarf_version >= 4 || !dwarf_strict))
11997 loc_result = new_loc_descr (DW_OP_implicit_value,
11998 DWARF2_ADDR_SIZE, 0);
11999 loc_result->dw_loc_oprnd2.val_class = dw_val_class_addr;
12000 loc_result->dw_loc_oprnd2.v.val_addr = rtl;
12001 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12006 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12007 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12008 && (dwarf_version >= 4 || !dwarf_strict))
12010 /* Value expression. */
12011 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
12013 add_loc_descr (&loc_result,
12014 new_loc_descr (DW_OP_stack_value, 0, 0));
12022 /* We need to figure out what section we should use as the base for the
12023 address ranges where a given location is valid.
12024 1. If this particular DECL has a section associated with it, use that.
12025 2. If this function has a section associated with it, use that.
12026 3. Otherwise, use the text section.
12027 XXX: If you split a variable across multiple sections, we won't notice. */
12029 static const char *
12030 secname_for_decl (const_tree decl)
12032 const char *secname;
12034 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12036 tree sectree = DECL_SECTION_NAME (decl);
12037 secname = TREE_STRING_POINTER (sectree);
12039 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12041 tree sectree = DECL_SECTION_NAME (current_function_decl);
12042 secname = TREE_STRING_POINTER (sectree);
12044 else if (cfun && in_cold_section_p)
12045 secname = crtl->subsections.cold_section_label;
12047 secname = text_section_label;
12052 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12055 decl_by_reference_p (tree decl)
12057 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12058 || TREE_CODE (decl) == VAR_DECL)
12059 && DECL_BY_REFERENCE (decl));
12063 /* Dereference a location expression LOC if DECL is passed by invisible
12066 static dw_loc_descr_ref
12067 loc_by_reference (dw_loc_descr_ref loc, tree decl)
12069 HOST_WIDE_INT size;
12070 enum dwarf_location_atom op;
12075 if (!decl_by_reference_p (decl))
12078 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
12079 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
12080 location expression is considered to be address of a memory location,
12081 rather than the register itself. */
12082 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
12083 || loc->dw_loc_opc == DW_OP_regx)
12084 && (loc->dw_loc_next == NULL
12085 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
12086 && loc->dw_loc_next->dw_loc_next == NULL)))
12088 if (loc->dw_loc_opc == DW_OP_regx)
12090 loc->dw_loc_opc = DW_OP_bregx;
12091 loc->dw_loc_oprnd2.v.val_int = 0;
12096 = (enum dwarf_location_atom)
12097 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
12098 loc->dw_loc_oprnd1.v.val_int = 0;
12103 size = int_size_in_bytes (TREE_TYPE (decl));
12104 if (size > DWARF2_ADDR_SIZE || size == -1)
12106 else if (size == DWARF2_ADDR_SIZE)
12109 op = DW_OP_deref_size;
12110 add_loc_descr (&loc, new_loc_descr (op, size, 0));
12114 /* Return single element location list containing loc descr REF. */
12116 static dw_loc_list_ref
12117 single_element_loc_list (dw_loc_descr_ref ref)
12119 return new_loc_list (ref, NULL, NULL, NULL, 0);
12122 /* Return dwarf representation of location list representing for
12123 LOC_LIST of DECL. */
12125 static dw_loc_list_ref
12126 dw_loc_list (var_loc_list * loc_list, tree decl, bool toplevel)
12128 const char *endname, *secname;
12129 dw_loc_list_ref list;
12131 enum var_init_status initialized;
12132 struct var_loc_node *node;
12133 dw_loc_descr_ref descr;
12134 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12136 bool by_reference = decl_by_reference_p (decl);
12138 /* Now that we know what section we are using for a base,
12139 actually construct the list of locations.
12140 The first location information is what is passed to the
12141 function that creates the location list, and the remaining
12142 locations just get added on to that list.
12143 Note that we only know the start address for a location
12144 (IE location changes), so to build the range, we use
12145 the range [current location start, next location start].
12146 This means we have to special case the last node, and generate
12147 a range of [last location start, end of function label]. */
12149 node = loc_list->first;
12150 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12151 secname = secname_for_decl (decl);
12153 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
12154 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12156 initialized = VAR_INIT_STATUS_INITIALIZED;
12158 if (!toplevel || by_reference)
12160 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12162 if (GET_CODE (XEXP (varloc, 1)) != PARALLEL)
12163 descr = loc_by_reference (mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0),
12164 TYPE_MODE (TREE_TYPE (decl)),
12171 descr = loc_descriptor (varloc, DECL_MODE (decl), initialized);
12173 if (loc_list && loc_list->first != loc_list->last)
12174 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
12176 return single_element_loc_list (descr);
12182 for (; node->next; node = node->next)
12183 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12185 /* The variable has a location between NODE->LABEL and
12186 NODE->NEXT->LABEL. */
12187 enum var_init_status initialized =
12188 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12189 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12190 if (!toplevel || by_reference)
12192 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12194 if (GET_CODE (XEXP (varloc, 1)) != PARALLEL)
12195 descr = mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0),
12196 TYPE_MODE (TREE_TYPE (decl)), initialized);
12199 descr = loc_by_reference (descr, decl);
12202 descr = loc_descriptor (varloc, DECL_MODE (decl), initialized);
12203 add_loc_descr_to_loc_list (&list, descr,
12204 node->label, node->next->label, secname);
12207 /* If the variable has a location at the last label
12208 it keeps its location until the end of function. */
12209 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12211 enum var_init_status initialized =
12212 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12214 if (!current_function_decl)
12215 endname = text_end_label;
12218 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12219 current_function_funcdef_no);
12220 endname = ggc_strdup (label_id);
12223 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12224 if (!toplevel || by_reference)
12226 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12228 if (GET_CODE (XEXP (varloc, 1)) != PARALLEL)
12229 descr = mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0),
12230 TYPE_MODE (TREE_TYPE (decl)), initialized);
12233 descr = loc_by_reference (descr, decl);
12236 descr = loc_descriptor (varloc, DECL_MODE (decl), initialized);
12237 add_loc_descr_to_loc_list (&list, descr, node->label, endname, secname);
12242 /* Return if the loc_list has only single element and thus can be represented
12243 as location description. */
12246 single_element_loc_list_p (dw_loc_list_ref list)
12248 return (!list->dw_loc_next && !list->begin && !list->end);
12251 /* To each location in list LIST add loc descr REF. */
12254 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
12256 dw_loc_descr_ref copy;
12257 add_loc_descr (&list->expr, ref);
12258 list = list->dw_loc_next;
12261 copy = GGC_CNEW (dw_loc_descr_node);
12262 memcpy (copy, ref, sizeof (dw_loc_descr_node));
12263 add_loc_descr (&list->expr, copy);
12264 while (copy->dw_loc_next)
12266 dw_loc_descr_ref new_copy = GGC_CNEW (dw_loc_descr_node);
12267 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
12268 copy->dw_loc_next = new_copy;
12271 list = list->dw_loc_next;
12275 /* Given two lists RET and LIST
12276 produce location list that is result of adding expression in LIST
12277 to expression in RET on each possition in program.
12278 Might be destructive on both RET and LIST.
12280 TODO: We handle only simple cases of RET or LIST having at most one
12281 element. General case would inolve sorting the lists in program order
12282 and merging them that will need some additional work.
12283 Adding that will improve quality of debug info especially for SRA-ed
12287 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
12296 if (!list->dw_loc_next)
12298 add_loc_descr_to_each (*ret, list->expr);
12301 if (!(*ret)->dw_loc_next)
12303 add_loc_descr_to_each (list, (*ret)->expr);
12307 expansion_failed (NULL_TREE, NULL_RTX,
12308 "Don't know how to merge two non-trivial"
12309 " location lists.\n");
12314 /* LOC is constant expression. Try a luck, look it up in constant
12315 pool and return its loc_descr of its address. */
12317 static dw_loc_descr_ref
12318 cst_pool_loc_descr (tree loc)
12320 /* Get an RTL for this, if something has been emitted. */
12321 rtx rtl = lookup_constant_def (loc);
12322 enum machine_mode mode;
12324 if (!rtl || !MEM_P (rtl))
12329 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
12331 /* TODO: We might get more coverage if we was actually delaying expansion
12332 of all expressions till end of compilation when constant pools are fully
12334 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
12336 expansion_failed (loc, NULL_RTX,
12337 "CST value in contant pool but not marked.");
12340 mode = GET_MODE (rtl);
12341 rtl = XEXP (rtl, 0);
12342 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12345 /* Return dw_loc_list representing address of addr_expr LOC
12346 by looking for innder INDIRECT_REF expression and turing it
12347 into simple arithmetics. */
12349 static dw_loc_list_ref
12350 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
12353 HOST_WIDE_INT bitsize, bitpos, bytepos;
12354 enum machine_mode mode;
12356 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
12357 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
12359 obj = get_inner_reference (TREE_OPERAND (loc, 0),
12360 &bitsize, &bitpos, &offset, &mode,
12361 &unsignedp, &volatilep, false);
12363 if (bitpos % BITS_PER_UNIT)
12365 expansion_failed (loc, NULL_RTX, "bitfield access");
12368 if (!INDIRECT_REF_P (obj))
12370 expansion_failed (obj,
12371 NULL_RTX, "no indirect ref in inner refrence");
12374 if (!offset && !bitpos)
12375 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
12377 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
12378 && (dwarf_version >= 4 || !dwarf_strict))
12380 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
12385 /* Variable offset. */
12386 list_ret1 = loc_list_from_tree (offset, 0);
12387 if (list_ret1 == 0)
12389 add_loc_list (&list_ret, list_ret1);
12392 add_loc_descr_to_each (list_ret,
12393 new_loc_descr (DW_OP_plus, 0, 0));
12395 bytepos = bitpos / BITS_PER_UNIT;
12397 add_loc_descr_to_each (list_ret,
12398 new_loc_descr (DW_OP_plus_uconst,
12400 else if (bytepos < 0)
12401 loc_list_plus_const (list_ret, bytepos);
12402 add_loc_descr_to_each (list_ret,
12403 new_loc_descr (DW_OP_stack_value, 0, 0));
12409 /* Generate Dwarf location list representing LOC.
12410 If WANT_ADDRESS is false, expression computing LOC will be computed
12411 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
12412 if WANT_ADDRESS is 2, expression computing address useable in location
12413 will be returned (i.e. DW_OP_reg can be used
12414 to refer to register values)
12415 TODO: Dwarf4 adds types to the stack machine that ought to be used here
12416 DW_OP_stack_value will help in cases where we fail to find address of the
12420 static dw_loc_list_ref
12421 loc_list_from_tree (tree loc, int want_address)
12423 dw_loc_descr_ref ret = NULL, ret1 = NULL;
12424 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
12425 int have_address = 0;
12426 enum dwarf_location_atom op;
12428 /* ??? Most of the time we do not take proper care for sign/zero
12429 extending the values properly. Hopefully this won't be a real
12432 switch (TREE_CODE (loc))
12435 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
12438 case PLACEHOLDER_EXPR:
12439 /* This case involves extracting fields from an object to determine the
12440 position of other fields. We don't try to encode this here. The
12441 only user of this is Ada, which encodes the needed information using
12442 the names of types. */
12443 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
12447 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
12448 /* There are no opcodes for these operations. */
12451 case PREINCREMENT_EXPR:
12452 case PREDECREMENT_EXPR:
12453 case POSTINCREMENT_EXPR:
12454 case POSTDECREMENT_EXPR:
12455 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
12456 /* There are no opcodes for these operations. */
12460 /* If we already want an address, see if there is INDIRECT_REF inside
12461 e.g. for &this->field. */
12464 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
12465 (loc, want_address == 2);
12468 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
12469 && (ret = cst_pool_loc_descr (loc)))
12472 /* Otherwise, process the argument and look for the address. */
12473 if (!list_ret && !ret)
12474 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
12478 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
12484 if (DECL_THREAD_LOCAL_P (loc))
12487 enum dwarf_location_atom first_op;
12488 enum dwarf_location_atom second_op;
12489 bool dtprel = false;
12491 if (targetm.have_tls)
12493 /* If this is not defined, we have no way to emit the
12495 if (!targetm.asm_out.output_dwarf_dtprel)
12498 /* The way DW_OP_GNU_push_tls_address is specified, we
12499 can only look up addresses of objects in the current
12501 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
12503 first_op = DW_OP_addr;
12505 second_op = DW_OP_GNU_push_tls_address;
12509 if (!targetm.emutls.debug_form_tls_address
12510 || !(dwarf_version >= 3 || !dwarf_strict))
12512 loc = emutls_decl (loc);
12513 first_op = DW_OP_addr;
12514 second_op = DW_OP_form_tls_address;
12517 rtl = rtl_for_decl_location (loc);
12518 if (rtl == NULL_RTX)
12523 rtl = XEXP (rtl, 0);
12524 if (! CONSTANT_P (rtl))
12527 ret = new_loc_descr (first_op, 0, 0);
12528 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12529 ret->dw_loc_oprnd1.v.val_addr = rtl;
12530 ret->dtprel = dtprel;
12532 ret1 = new_loc_descr (second_op, 0, 0);
12533 add_loc_descr (&ret, ret1);
12541 if (DECL_HAS_VALUE_EXPR_P (loc))
12542 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
12547 case FUNCTION_DECL:
12549 rtx rtl = rtl_for_decl_location (loc);
12550 var_loc_list *loc_list = lookup_decl_loc (loc);
12552 if (loc_list && loc_list->first
12553 && (list_ret = dw_loc_list (loc_list, loc, want_address == 2)))
12555 else if (rtl == NULL_RTX)
12557 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
12560 else if (CONST_INT_P (rtl))
12562 HOST_WIDE_INT val = INTVAL (rtl);
12563 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
12564 val &= GET_MODE_MASK (DECL_MODE (loc));
12565 ret = int_loc_descriptor (val);
12567 else if (GET_CODE (rtl) == CONST_STRING)
12569 expansion_failed (loc, NULL_RTX, "CONST_STRING");
12572 else if (CONSTANT_P (rtl))
12574 ret = new_loc_descr (DW_OP_addr, 0, 0);
12575 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12576 ret->dw_loc_oprnd1.v.val_addr = rtl;
12580 enum machine_mode mode;
12582 /* Certain constructs can only be represented at top-level. */
12583 if (want_address == 2)
12585 ret = loc_descriptor (rtl, VOIDmode,
12586 VAR_INIT_STATUS_INITIALIZED);
12591 mode = GET_MODE (rtl);
12594 rtl = XEXP (rtl, 0);
12597 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12600 expansion_failed (loc, rtl,
12601 "failed to produce loc descriptor for rtl");
12607 case ALIGN_INDIRECT_REF:
12608 case MISALIGNED_INDIRECT_REF:
12609 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12613 case COMPOUND_EXPR:
12614 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
12617 case VIEW_CONVERT_EXPR:
12620 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
12622 case COMPONENT_REF:
12623 case BIT_FIELD_REF:
12625 case ARRAY_RANGE_REF:
12626 case REALPART_EXPR:
12627 case IMAGPART_EXPR:
12630 HOST_WIDE_INT bitsize, bitpos, bytepos;
12631 enum machine_mode mode;
12633 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
12635 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
12636 &unsignedp, &volatilep, false);
12638 gcc_assert (obj != loc);
12640 list_ret = loc_list_from_tree (obj,
12642 && !bitpos && !offset ? 2 : 1);
12643 /* TODO: We can extract value of the small expression via shifting even
12644 for nonzero bitpos. */
12647 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
12649 expansion_failed (loc, NULL_RTX,
12650 "bitfield access");
12654 if (offset != NULL_TREE)
12656 /* Variable offset. */
12657 list_ret1 = loc_list_from_tree (offset, 0);
12658 if (list_ret1 == 0)
12660 add_loc_list (&list_ret, list_ret1);
12663 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
12666 bytepos = bitpos / BITS_PER_UNIT;
12668 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
12669 else if (bytepos < 0)
12670 loc_list_plus_const (list_ret, bytepos);
12677 if ((want_address || !host_integerp (loc, 0))
12678 && (ret = cst_pool_loc_descr (loc)))
12680 else if (want_address == 2
12681 && host_integerp (loc, 0)
12682 && (ret = address_of_int_loc_descriptor
12683 (int_size_in_bytes (TREE_TYPE (loc)),
12684 tree_low_cst (loc, 0))))
12686 else if (host_integerp (loc, 0))
12687 ret = int_loc_descriptor (tree_low_cst (loc, 0));
12690 expansion_failed (loc, NULL_RTX,
12691 "Integer operand is not host integer");
12700 if ((ret = cst_pool_loc_descr (loc)))
12703 /* We can construct small constants here using int_loc_descriptor. */
12704 expansion_failed (loc, NULL_RTX,
12705 "constructor or constant not in constant pool");
12708 case TRUTH_AND_EXPR:
12709 case TRUTH_ANDIF_EXPR:
12714 case TRUTH_XOR_EXPR:
12719 case TRUTH_OR_EXPR:
12720 case TRUTH_ORIF_EXPR:
12725 case FLOOR_DIV_EXPR:
12726 case CEIL_DIV_EXPR:
12727 case ROUND_DIV_EXPR:
12728 case TRUNC_DIV_EXPR:
12736 case FLOOR_MOD_EXPR:
12737 case CEIL_MOD_EXPR:
12738 case ROUND_MOD_EXPR:
12739 case TRUNC_MOD_EXPR:
12752 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
12755 case POINTER_PLUS_EXPR:
12757 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
12758 && host_integerp (TREE_OPERAND (loc, 1), 0))
12760 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12764 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
12772 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12779 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12786 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12793 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12808 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12809 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
12810 if (list_ret == 0 || list_ret1 == 0)
12813 add_loc_list (&list_ret, list_ret1);
12816 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
12819 case TRUTH_NOT_EXPR:
12833 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12837 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
12843 const enum tree_code code =
12844 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
12846 loc = build3 (COND_EXPR, TREE_TYPE (loc),
12847 build2 (code, integer_type_node,
12848 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
12849 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
12852 /* ... fall through ... */
12856 dw_loc_descr_ref lhs
12857 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
12858 dw_loc_list_ref rhs
12859 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
12860 dw_loc_descr_ref bra_node, jump_node, tmp;
12862 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12863 if (list_ret == 0 || lhs == 0 || rhs == 0)
12866 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12867 add_loc_descr_to_each (list_ret, bra_node);
12869 add_loc_list (&list_ret, rhs);
12870 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
12871 add_loc_descr_to_each (list_ret, jump_node);
12873 add_loc_descr_to_each (list_ret, lhs);
12874 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12875 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
12877 /* ??? Need a node to point the skip at. Use a nop. */
12878 tmp = new_loc_descr (DW_OP_nop, 0, 0);
12879 add_loc_descr_to_each (list_ret, tmp);
12880 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12881 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
12885 case FIX_TRUNC_EXPR:
12889 /* Leave front-end specific codes as simply unknown. This comes
12890 up, for instance, with the C STMT_EXPR. */
12891 if ((unsigned int) TREE_CODE (loc)
12892 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
12894 expansion_failed (loc, NULL_RTX,
12895 "language specific tree node");
12899 #ifdef ENABLE_CHECKING
12900 /* Otherwise this is a generic code; we should just lists all of
12901 these explicitly. We forgot one. */
12902 gcc_unreachable ();
12904 /* In a release build, we want to degrade gracefully: better to
12905 generate incomplete debugging information than to crash. */
12910 if (!ret && !list_ret)
12913 if (want_address == 2 && !have_address
12914 && (dwarf_version >= 4 || !dwarf_strict))
12916 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
12918 expansion_failed (loc, NULL_RTX,
12919 "DWARF address size mismatch");
12922 add_loc_descr_to_each (list_ret,
12923 new_loc_descr (DW_OP_stack_value, 0, 0));
12926 /* Show if we can't fill the request for an address. */
12927 if (want_address && !have_address)
12929 expansion_failed (loc, NULL_RTX,
12930 "Want address and only have value");
12934 gcc_assert (!ret || !list_ret);
12936 /* If we've got an address and don't want one, dereference. */
12937 if (!want_address && have_address)
12939 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12941 if (size > DWARF2_ADDR_SIZE || size == -1)
12943 expansion_failed (loc, NULL_RTX,
12944 "DWARF address size mismatch");
12947 else if (size == DWARF2_ADDR_SIZE)
12950 op = DW_OP_deref_size;
12953 add_loc_descr (&ret, new_loc_descr (op, size, 0));
12955 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
12958 list_ret = single_element_loc_list (ret);
12963 /* Same as above but return only single location expression. */
12964 static dw_loc_descr_ref
12965 loc_descriptor_from_tree (tree loc, int want_address)
12967 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
12970 if (ret->dw_loc_next)
12972 expansion_failed (loc, NULL_RTX,
12973 "Location list where only loc descriptor needed");
12979 /* Given a value, round it up to the lowest multiple of `boundary'
12980 which is not less than the value itself. */
12982 static inline HOST_WIDE_INT
12983 ceiling (HOST_WIDE_INT value, unsigned int boundary)
12985 return (((value + boundary - 1) / boundary) * boundary);
12988 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
12989 pointer to the declared type for the relevant field variable, or return
12990 `integer_type_node' if the given node turns out to be an
12991 ERROR_MARK node. */
12994 field_type (const_tree decl)
12998 if (TREE_CODE (decl) == ERROR_MARK)
12999 return integer_type_node;
13001 type = DECL_BIT_FIELD_TYPE (decl);
13002 if (type == NULL_TREE)
13003 type = TREE_TYPE (decl);
13008 /* Given a pointer to a tree node, return the alignment in bits for
13009 it, or else return BITS_PER_WORD if the node actually turns out to
13010 be an ERROR_MARK node. */
13012 static inline unsigned
13013 simple_type_align_in_bits (const_tree type)
13015 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
13018 static inline unsigned
13019 simple_decl_align_in_bits (const_tree decl)
13021 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
13024 /* Return the result of rounding T up to ALIGN. */
13026 static inline HOST_WIDE_INT
13027 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
13029 /* We must be careful if T is negative because HOST_WIDE_INT can be
13030 either "above" or "below" unsigned int as per the C promotion
13031 rules, depending on the host, thus making the signedness of the
13032 direct multiplication and division unpredictable. */
13033 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
13039 return (HOST_WIDE_INT) u;
13042 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13043 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13044 or return 0 if we are unable to determine what that offset is, either
13045 because the argument turns out to be a pointer to an ERROR_MARK node, or
13046 because the offset is actually variable. (We can't handle the latter case
13049 static HOST_WIDE_INT
13050 field_byte_offset (const_tree decl)
13052 HOST_WIDE_INT object_offset_in_bits;
13053 HOST_WIDE_INT bitpos_int;
13055 if (TREE_CODE (decl) == ERROR_MARK)
13058 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
13060 /* We cannot yet cope with fields whose positions are variable, so
13061 for now, when we see such things, we simply return 0. Someday, we may
13062 be able to handle such cases, but it will be damn difficult. */
13063 if (! host_integerp (bit_position (decl), 0))
13066 bitpos_int = int_bit_position (decl);
13068 #ifdef PCC_BITFIELD_TYPE_MATTERS
13069 if (PCC_BITFIELD_TYPE_MATTERS)
13072 tree field_size_tree;
13073 HOST_WIDE_INT deepest_bitpos;
13074 unsigned HOST_WIDE_INT field_size_in_bits;
13075 unsigned int type_align_in_bits;
13076 unsigned int decl_align_in_bits;
13077 unsigned HOST_WIDE_INT type_size_in_bits;
13079 type = field_type (decl);
13080 type_size_in_bits = simple_type_size_in_bits (type);
13081 type_align_in_bits = simple_type_align_in_bits (type);
13083 field_size_tree = DECL_SIZE (decl);
13085 /* The size could be unspecified if there was an error, or for
13086 a flexible array member. */
13087 if (!field_size_tree)
13088 field_size_tree = bitsize_zero_node;
13090 /* If the size of the field is not constant, use the type size. */
13091 if (host_integerp (field_size_tree, 1))
13092 field_size_in_bits = tree_low_cst (field_size_tree, 1);
13094 field_size_in_bits = type_size_in_bits;
13096 decl_align_in_bits = simple_decl_align_in_bits (decl);
13098 /* The GCC front-end doesn't make any attempt to keep track of the
13099 starting bit offset (relative to the start of the containing
13100 structure type) of the hypothetical "containing object" for a
13101 bit-field. Thus, when computing the byte offset value for the
13102 start of the "containing object" of a bit-field, we must deduce
13103 this information on our own. This can be rather tricky to do in
13104 some cases. For example, handling the following structure type
13105 definition when compiling for an i386/i486 target (which only
13106 aligns long long's to 32-bit boundaries) can be very tricky:
13108 struct S { int field1; long long field2:31; };
13110 Fortunately, there is a simple rule-of-thumb which can be used
13111 in such cases. When compiling for an i386/i486, GCC will
13112 allocate 8 bytes for the structure shown above. It decides to
13113 do this based upon one simple rule for bit-field allocation.
13114 GCC allocates each "containing object" for each bit-field at
13115 the first (i.e. lowest addressed) legitimate alignment boundary
13116 (based upon the required minimum alignment for the declared
13117 type of the field) which it can possibly use, subject to the
13118 condition that there is still enough available space remaining
13119 in the containing object (when allocated at the selected point)
13120 to fully accommodate all of the bits of the bit-field itself.
13122 This simple rule makes it obvious why GCC allocates 8 bytes for
13123 each object of the structure type shown above. When looking
13124 for a place to allocate the "containing object" for `field2',
13125 the compiler simply tries to allocate a 64-bit "containing
13126 object" at each successive 32-bit boundary (starting at zero)
13127 until it finds a place to allocate that 64- bit field such that
13128 at least 31 contiguous (and previously unallocated) bits remain
13129 within that selected 64 bit field. (As it turns out, for the
13130 example above, the compiler finds it is OK to allocate the
13131 "containing object" 64-bit field at bit-offset zero within the
13134 Here we attempt to work backwards from the limited set of facts
13135 we're given, and we try to deduce from those facts, where GCC
13136 must have believed that the containing object started (within
13137 the structure type). The value we deduce is then used (by the
13138 callers of this routine) to generate DW_AT_location and
13139 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13140 the case of DW_AT_location, regular fields as well). */
13142 /* Figure out the bit-distance from the start of the structure to
13143 the "deepest" bit of the bit-field. */
13144 deepest_bitpos = bitpos_int + field_size_in_bits;
13146 /* This is the tricky part. Use some fancy footwork to deduce
13147 where the lowest addressed bit of the containing object must
13149 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
13151 /* Round up to type_align by default. This works best for
13153 object_offset_in_bits
13154 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
13156 if (object_offset_in_bits > bitpos_int)
13158 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
13160 /* Round up to decl_align instead. */
13161 object_offset_in_bits
13162 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
13167 object_offset_in_bits = bitpos_int;
13169 return object_offset_in_bits / BITS_PER_UNIT;
13172 /* The following routines define various Dwarf attributes and any data
13173 associated with them. */
13175 /* Add a location description attribute value to a DIE.
13177 This emits location attributes suitable for whole variables and
13178 whole parameters. Note that the location attributes for struct fields are
13179 generated by the routine `data_member_location_attribute' below. */
13182 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
13183 dw_loc_list_ref descr)
13187 if (single_element_loc_list_p (descr))
13188 add_AT_loc (die, attr_kind, descr->expr);
13190 add_AT_loc_list (die, attr_kind, descr);
13193 /* Attach the specialized form of location attribute used for data members of
13194 struct and union types. In the special case of a FIELD_DECL node which
13195 represents a bit-field, the "offset" part of this special location
13196 descriptor must indicate the distance in bytes from the lowest-addressed
13197 byte of the containing struct or union type to the lowest-addressed byte of
13198 the "containing object" for the bit-field. (See the `field_byte_offset'
13201 For any given bit-field, the "containing object" is a hypothetical object
13202 (of some integral or enum type) within which the given bit-field lives. The
13203 type of this hypothetical "containing object" is always the same as the
13204 declared type of the individual bit-field itself (for GCC anyway... the
13205 DWARF spec doesn't actually mandate this). Note that it is the size (in
13206 bytes) of the hypothetical "containing object" which will be given in the
13207 DW_AT_byte_size attribute for this bit-field. (See the
13208 `byte_size_attribute' function below.) It is also used when calculating the
13209 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
13210 function below.) */
13213 add_data_member_location_attribute (dw_die_ref die, tree decl)
13215 HOST_WIDE_INT offset;
13216 dw_loc_descr_ref loc_descr = 0;
13218 if (TREE_CODE (decl) == TREE_BINFO)
13220 /* We're working on the TAG_inheritance for a base class. */
13221 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
13223 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
13224 aren't at a fixed offset from all (sub)objects of the same
13225 type. We need to extract the appropriate offset from our
13226 vtable. The following dwarf expression means
13228 BaseAddr = ObAddr + *((*ObAddr) - Offset)
13230 This is specific to the V3 ABI, of course. */
13232 dw_loc_descr_ref tmp;
13234 /* Make a copy of the object address. */
13235 tmp = new_loc_descr (DW_OP_dup, 0, 0);
13236 add_loc_descr (&loc_descr, tmp);
13238 /* Extract the vtable address. */
13239 tmp = new_loc_descr (DW_OP_deref, 0, 0);
13240 add_loc_descr (&loc_descr, tmp);
13242 /* Calculate the address of the offset. */
13243 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
13244 gcc_assert (offset < 0);
13246 tmp = int_loc_descriptor (-offset);
13247 add_loc_descr (&loc_descr, tmp);
13248 tmp = new_loc_descr (DW_OP_minus, 0, 0);
13249 add_loc_descr (&loc_descr, tmp);
13251 /* Extract the offset. */
13252 tmp = new_loc_descr (DW_OP_deref, 0, 0);
13253 add_loc_descr (&loc_descr, tmp);
13255 /* Add it to the object address. */
13256 tmp = new_loc_descr (DW_OP_plus, 0, 0);
13257 add_loc_descr (&loc_descr, tmp);
13260 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
13263 offset = field_byte_offset (decl);
13267 if (dwarf_version > 2)
13269 /* Don't need to output a location expression, just the constant. */
13270 add_AT_int (die, DW_AT_data_member_location, offset);
13275 enum dwarf_location_atom op;
13277 /* The DWARF2 standard says that we should assume that the structure
13278 address is already on the stack, so we can specify a structure
13279 field address by using DW_OP_plus_uconst. */
13281 #ifdef MIPS_DEBUGGING_INFO
13282 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
13283 operator correctly. It works only if we leave the offset on the
13287 op = DW_OP_plus_uconst;
13290 loc_descr = new_loc_descr (op, offset, 0);
13294 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
13297 /* Writes integer values to dw_vec_const array. */
13300 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
13304 *dest++ = val & 0xff;
13310 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
13312 static HOST_WIDE_INT
13313 extract_int (const unsigned char *src, unsigned int size)
13315 HOST_WIDE_INT val = 0;
13321 val |= *--src & 0xff;
13327 /* Writes floating point values to dw_vec_const array. */
13330 insert_float (const_rtx rtl, unsigned char *array)
13332 REAL_VALUE_TYPE rv;
13336 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
13337 real_to_target (val, &rv, GET_MODE (rtl));
13339 /* real_to_target puts 32-bit pieces in each long. Pack them. */
13340 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
13342 insert_int (val[i], 4, array);
13347 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
13348 does not have a "location" either in memory or in a register. These
13349 things can arise in GNU C when a constant is passed as an actual parameter
13350 to an inlined function. They can also arise in C++ where declared
13351 constants do not necessarily get memory "homes". */
13354 add_const_value_attribute (dw_die_ref die, rtx rtl)
13356 switch (GET_CODE (rtl))
13360 HOST_WIDE_INT val = INTVAL (rtl);
13363 add_AT_int (die, DW_AT_const_value, val);
13365 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
13370 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
13371 floating-point constant. A CONST_DOUBLE is used whenever the
13372 constant requires more than one word in order to be adequately
13375 enum machine_mode mode = GET_MODE (rtl);
13377 if (SCALAR_FLOAT_MODE_P (mode))
13379 unsigned int length = GET_MODE_SIZE (mode);
13380 unsigned char *array = GGC_NEWVEC (unsigned char, length);
13382 insert_float (rtl, array);
13383 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
13386 add_AT_double (die, DW_AT_const_value,
13387 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
13393 enum machine_mode mode = GET_MODE (rtl);
13394 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
13395 unsigned int length = CONST_VECTOR_NUNITS (rtl);
13396 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
13400 switch (GET_MODE_CLASS (mode))
13402 case MODE_VECTOR_INT:
13403 for (i = 0, p = array; i < length; i++, p += elt_size)
13405 rtx elt = CONST_VECTOR_ELT (rtl, i);
13406 HOST_WIDE_INT lo, hi;
13408 switch (GET_CODE (elt))
13416 lo = CONST_DOUBLE_LOW (elt);
13417 hi = CONST_DOUBLE_HIGH (elt);
13421 gcc_unreachable ();
13424 if (elt_size <= sizeof (HOST_WIDE_INT))
13425 insert_int (lo, elt_size, p);
13428 unsigned char *p0 = p;
13429 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
13431 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
13432 if (WORDS_BIG_ENDIAN)
13437 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
13438 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
13443 case MODE_VECTOR_FLOAT:
13444 for (i = 0, p = array; i < length; i++, p += elt_size)
13446 rtx elt = CONST_VECTOR_ELT (rtl, i);
13447 insert_float (elt, p);
13452 gcc_unreachable ();
13455 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
13460 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
13464 if (CONSTANT_P (XEXP (rtl, 0)))
13465 return add_const_value_attribute (die, XEXP (rtl, 0));
13468 if (GET_CODE (rtl) == SYMBOL_REF
13469 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13472 add_AT_addr (die, DW_AT_const_value, rtl);
13473 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13477 /* In cases where an inlined instance of an inline function is passed
13478 the address of an `auto' variable (which is local to the caller) we
13479 can get a situation where the DECL_RTL of the artificial local
13480 variable (for the inlining) which acts as a stand-in for the
13481 corresponding formal parameter (of the inline function) will look
13482 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
13483 exactly a compile-time constant expression, but it isn't the address
13484 of the (artificial) local variable either. Rather, it represents the
13485 *value* which the artificial local variable always has during its
13486 lifetime. We currently have no way to represent such quasi-constant
13487 values in Dwarf, so for now we just punt and generate nothing. */
13495 /* No other kinds of rtx should be possible here. */
13496 gcc_unreachable ();
13501 /* Determine whether the evaluation of EXPR references any variables
13502 or functions which aren't otherwise used (and therefore may not be
13505 reference_to_unused (tree * tp, int * walk_subtrees,
13506 void * data ATTRIBUTE_UNUSED)
13508 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
13509 *walk_subtrees = 0;
13511 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
13512 && ! TREE_ASM_WRITTEN (*tp))
13514 /* ??? The C++ FE emits debug information for using decls, so
13515 putting gcc_unreachable here falls over. See PR31899. For now
13516 be conservative. */
13517 else if (!cgraph_global_info_ready
13518 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
13520 else if (TREE_CODE (*tp) == VAR_DECL)
13522 struct varpool_node *node = varpool_node (*tp);
13526 else if (TREE_CODE (*tp) == FUNCTION_DECL
13527 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
13529 /* The call graph machinery must have finished analyzing,
13530 optimizing and gimplifying the CU by now.
13531 So if *TP has no call graph node associated
13532 to it, it means *TP will not be emitted. */
13533 if (!cgraph_get_node (*tp))
13536 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
13542 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
13543 for use in a later add_const_value_attribute call. */
13546 rtl_for_decl_init (tree init, tree type)
13548 rtx rtl = NULL_RTX;
13550 /* If a variable is initialized with a string constant without embedded
13551 zeros, build CONST_STRING. */
13552 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
13554 tree enttype = TREE_TYPE (type);
13555 tree domain = TYPE_DOMAIN (type);
13556 enum machine_mode mode = TYPE_MODE (enttype);
13558 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
13560 && integer_zerop (TYPE_MIN_VALUE (domain))
13561 && compare_tree_int (TYPE_MAX_VALUE (domain),
13562 TREE_STRING_LENGTH (init) - 1) == 0
13563 && ((size_t) TREE_STRING_LENGTH (init)
13564 == strlen (TREE_STRING_POINTER (init)) + 1))
13565 rtl = gen_rtx_CONST_STRING (VOIDmode,
13566 ggc_strdup (TREE_STRING_POINTER (init)));
13568 /* Other aggregates, and complex values, could be represented using
13570 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
13572 /* Vectors only work if their mode is supported by the target.
13573 FIXME: generic vectors ought to work too. */
13574 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
13576 /* If the initializer is something that we know will expand into an
13577 immediate RTL constant, expand it now. We must be careful not to
13578 reference variables which won't be output. */
13579 else if (initializer_constant_valid_p (init, type)
13580 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
13582 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
13584 if (TREE_CODE (type) == VECTOR_TYPE)
13585 switch (TREE_CODE (init))
13590 if (TREE_CONSTANT (init))
13592 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
13593 bool constant_p = true;
13595 unsigned HOST_WIDE_INT ix;
13597 /* Even when ctor is constant, it might contain non-*_CST
13598 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
13599 belong into VECTOR_CST nodes. */
13600 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
13601 if (!CONSTANT_CLASS_P (value))
13603 constant_p = false;
13609 init = build_vector_from_ctor (type, elts);
13619 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
13621 /* If expand_expr returns a MEM, it wasn't immediate. */
13622 gcc_assert (!rtl || !MEM_P (rtl));
13628 /* Generate RTL for the variable DECL to represent its location. */
13631 rtl_for_decl_location (tree decl)
13635 /* Here we have to decide where we are going to say the parameter "lives"
13636 (as far as the debugger is concerned). We only have a couple of
13637 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
13639 DECL_RTL normally indicates where the parameter lives during most of the
13640 activation of the function. If optimization is enabled however, this
13641 could be either NULL or else a pseudo-reg. Both of those cases indicate
13642 that the parameter doesn't really live anywhere (as far as the code
13643 generation parts of GCC are concerned) during most of the function's
13644 activation. That will happen (for example) if the parameter is never
13645 referenced within the function.
13647 We could just generate a location descriptor here for all non-NULL
13648 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
13649 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
13650 where DECL_RTL is NULL or is a pseudo-reg.
13652 Note however that we can only get away with using DECL_INCOMING_RTL as
13653 a backup substitute for DECL_RTL in certain limited cases. In cases
13654 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
13655 we can be sure that the parameter was passed using the same type as it is
13656 declared to have within the function, and that its DECL_INCOMING_RTL
13657 points us to a place where a value of that type is passed.
13659 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
13660 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
13661 because in these cases DECL_INCOMING_RTL points us to a value of some
13662 type which is *different* from the type of the parameter itself. Thus,
13663 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
13664 such cases, the debugger would end up (for example) trying to fetch a
13665 `float' from a place which actually contains the first part of a
13666 `double'. That would lead to really incorrect and confusing
13667 output at debug-time.
13669 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
13670 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
13671 are a couple of exceptions however. On little-endian machines we can
13672 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
13673 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
13674 an integral type that is smaller than TREE_TYPE (decl). These cases arise
13675 when (on a little-endian machine) a non-prototyped function has a
13676 parameter declared to be of type `short' or `char'. In such cases,
13677 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
13678 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
13679 passed `int' value. If the debugger then uses that address to fetch
13680 a `short' or a `char' (on a little-endian machine) the result will be
13681 the correct data, so we allow for such exceptional cases below.
13683 Note that our goal here is to describe the place where the given formal
13684 parameter lives during most of the function's activation (i.e. between the
13685 end of the prologue and the start of the epilogue). We'll do that as best
13686 as we can. Note however that if the given formal parameter is modified
13687 sometime during the execution of the function, then a stack backtrace (at
13688 debug-time) will show the function as having been called with the *new*
13689 value rather than the value which was originally passed in. This happens
13690 rarely enough that it is not a major problem, but it *is* a problem, and
13691 I'd like to fix it.
13693 A future version of dwarf2out.c may generate two additional attributes for
13694 any given DW_TAG_formal_parameter DIE which will describe the "passed
13695 type" and the "passed location" for the given formal parameter in addition
13696 to the attributes we now generate to indicate the "declared type" and the
13697 "active location" for each parameter. This additional set of attributes
13698 could be used by debuggers for stack backtraces. Separately, note that
13699 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
13700 This happens (for example) for inlined-instances of inline function formal
13701 parameters which are never referenced. This really shouldn't be
13702 happening. All PARM_DECL nodes should get valid non-NULL
13703 DECL_INCOMING_RTL values. FIXME. */
13705 /* Use DECL_RTL as the "location" unless we find something better. */
13706 rtl = DECL_RTL_IF_SET (decl);
13708 /* When generating abstract instances, ignore everything except
13709 constants, symbols living in memory, and symbols living in
13710 fixed registers. */
13711 if (! reload_completed)
13714 && (CONSTANT_P (rtl)
13716 && CONSTANT_P (XEXP (rtl, 0)))
13718 && TREE_CODE (decl) == VAR_DECL
13719 && TREE_STATIC (decl))))
13721 rtl = targetm.delegitimize_address (rtl);
13726 else if (TREE_CODE (decl) == PARM_DECL)
13728 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
13730 tree declared_type = TREE_TYPE (decl);
13731 tree passed_type = DECL_ARG_TYPE (decl);
13732 enum machine_mode dmode = TYPE_MODE (declared_type);
13733 enum machine_mode pmode = TYPE_MODE (passed_type);
13735 /* This decl represents a formal parameter which was optimized out.
13736 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
13737 all cases where (rtl == NULL_RTX) just below. */
13738 if (dmode == pmode)
13739 rtl = DECL_INCOMING_RTL (decl);
13740 else if (SCALAR_INT_MODE_P (dmode)
13741 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
13742 && DECL_INCOMING_RTL (decl))
13744 rtx inc = DECL_INCOMING_RTL (decl);
13747 else if (MEM_P (inc))
13749 if (BYTES_BIG_ENDIAN)
13750 rtl = adjust_address_nv (inc, dmode,
13751 GET_MODE_SIZE (pmode)
13752 - GET_MODE_SIZE (dmode));
13759 /* If the parm was passed in registers, but lives on the stack, then
13760 make a big endian correction if the mode of the type of the
13761 parameter is not the same as the mode of the rtl. */
13762 /* ??? This is the same series of checks that are made in dbxout.c before
13763 we reach the big endian correction code there. It isn't clear if all
13764 of these checks are necessary here, but keeping them all is the safe
13766 else if (MEM_P (rtl)
13767 && XEXP (rtl, 0) != const0_rtx
13768 && ! CONSTANT_P (XEXP (rtl, 0))
13769 /* Not passed in memory. */
13770 && !MEM_P (DECL_INCOMING_RTL (decl))
13771 /* Not passed by invisible reference. */
13772 && (!REG_P (XEXP (rtl, 0))
13773 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
13774 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
13775 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
13776 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
13779 /* Big endian correction check. */
13780 && BYTES_BIG_ENDIAN
13781 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
13782 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
13785 int offset = (UNITS_PER_WORD
13786 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
13788 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13789 plus_constant (XEXP (rtl, 0), offset));
13792 else if (TREE_CODE (decl) == VAR_DECL
13795 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
13796 && BYTES_BIG_ENDIAN)
13798 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
13799 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
13801 /* If a variable is declared "register" yet is smaller than
13802 a register, then if we store the variable to memory, it
13803 looks like we're storing a register-sized value, when in
13804 fact we are not. We need to adjust the offset of the
13805 storage location to reflect the actual value's bytes,
13806 else gdb will not be able to display it. */
13808 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13809 plus_constant (XEXP (rtl, 0), rsize-dsize));
13812 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
13813 and will have been substituted directly into all expressions that use it.
13814 C does not have such a concept, but C++ and other languages do. */
13815 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
13816 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
13819 rtl = targetm.delegitimize_address (rtl);
13821 /* If we don't look past the constant pool, we risk emitting a
13822 reference to a constant pool entry that isn't referenced from
13823 code, and thus is not emitted. */
13825 rtl = avoid_constant_pool_reference (rtl);
13830 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
13831 returned. If so, the decl for the COMMON block is returned, and the
13832 value is the offset into the common block for the symbol. */
13835 fortran_common (tree decl, HOST_WIDE_INT *value)
13837 tree val_expr, cvar;
13838 enum machine_mode mode;
13839 HOST_WIDE_INT bitsize, bitpos;
13841 int volatilep = 0, unsignedp = 0;
13843 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
13844 it does not have a value (the offset into the common area), or if it
13845 is thread local (as opposed to global) then it isn't common, and shouldn't
13846 be handled as such. */
13847 if (TREE_CODE (decl) != VAR_DECL
13848 || !TREE_PUBLIC (decl)
13849 || !TREE_STATIC (decl)
13850 || !DECL_HAS_VALUE_EXPR_P (decl)
13854 val_expr = DECL_VALUE_EXPR (decl);
13855 if (TREE_CODE (val_expr) != COMPONENT_REF)
13858 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
13859 &mode, &unsignedp, &volatilep, true);
13861 if (cvar == NULL_TREE
13862 || TREE_CODE (cvar) != VAR_DECL
13863 || DECL_ARTIFICIAL (cvar)
13864 || !TREE_PUBLIC (cvar))
13868 if (offset != NULL)
13870 if (!host_integerp (offset, 0))
13872 *value = tree_low_cst (offset, 0);
13875 *value += bitpos / BITS_PER_UNIT;
13880 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
13881 data attribute for a variable or a parameter. We generate the
13882 DW_AT_const_value attribute only in those cases where the given variable
13883 or parameter does not have a true "location" either in memory or in a
13884 register. This can happen (for example) when a constant is passed as an
13885 actual argument in a call to an inline function. (It's possible that
13886 these things can crop up in other ways also.) Note that one type of
13887 constant value which can be passed into an inlined function is a constant
13888 pointer. This can happen for example if an actual argument in an inlined
13889 function call evaluates to a compile-time constant address. */
13892 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
13893 enum dwarf_attribute attr)
13896 dw_loc_list_ref list;
13897 var_loc_list *loc_list;
13899 if (TREE_CODE (decl) == ERROR_MARK)
13902 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
13903 || TREE_CODE (decl) == RESULT_DECL);
13905 /* Try to get some constant RTL for this decl, and use that as the value of
13908 rtl = rtl_for_decl_location (decl);
13909 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
13910 && add_const_value_attribute (die, rtl))
13913 /* See if we have single element location list that is equivalent to
13914 a constant value. That way we are better to use add_const_value_attribute
13915 rather than expanding constant value equivalent. */
13916 loc_list = lookup_decl_loc (decl);
13917 if (loc_list && loc_list->first && loc_list->first == loc_list->last)
13919 enum var_init_status status;
13920 struct var_loc_node *node;
13922 node = loc_list->first;
13923 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13924 rtl = NOTE_VAR_LOCATION (node->var_loc_note);
13925 if (GET_CODE (rtl) == VAR_LOCATION
13926 && GET_CODE (XEXP (rtl, 1)) != PARALLEL)
13927 rtl = XEXP (XEXP (rtl, 1), 0);
13928 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
13929 && add_const_value_attribute (die, rtl))
13932 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
13935 add_AT_location_description (die, attr, list);
13938 /* None of that worked, so it must not really have a location;
13939 try adding a constant value attribute from the DECL_INITIAL. */
13940 return tree_add_const_value_attribute_for_decl (die, decl);
13943 /* Add VARIABLE and DIE into deferred locations list. */
13946 defer_location (tree variable, dw_die_ref die)
13948 deferred_locations entry;
13949 entry.variable = variable;
13951 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
13954 /* Helper function for tree_add_const_value_attribute. Natively encode
13955 initializer INIT into an array. Return true if successful. */
13958 native_encode_initializer (tree init, unsigned char *array, int size)
13962 if (init == NULL_TREE)
13966 switch (TREE_CODE (init))
13969 type = TREE_TYPE (init);
13970 if (TREE_CODE (type) == ARRAY_TYPE)
13972 tree enttype = TREE_TYPE (type);
13973 enum machine_mode mode = TYPE_MODE (enttype);
13975 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
13977 if (int_size_in_bytes (type) != size)
13979 if (size > TREE_STRING_LENGTH (init))
13981 memcpy (array, TREE_STRING_POINTER (init),
13982 TREE_STRING_LENGTH (init));
13983 memset (array + TREE_STRING_LENGTH (init),
13984 '\0', size - TREE_STRING_LENGTH (init));
13987 memcpy (array, TREE_STRING_POINTER (init), size);
13992 type = TREE_TYPE (init);
13993 if (int_size_in_bytes (type) != size)
13995 if (TREE_CODE (type) == ARRAY_TYPE)
13997 HOST_WIDE_INT min_index;
13998 unsigned HOST_WIDE_INT cnt;
13999 int curpos = 0, fieldsize;
14000 constructor_elt *ce;
14002 if (TYPE_DOMAIN (type) == NULL_TREE
14003 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
14006 fieldsize = int_size_in_bytes (TREE_TYPE (type));
14007 if (fieldsize <= 0)
14010 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
14011 memset (array, '\0', size);
14013 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
14016 tree val = ce->value;
14017 tree index = ce->index;
14019 if (index && TREE_CODE (index) == RANGE_EXPR)
14020 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
14023 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
14028 if (!native_encode_initializer (val, array + pos, fieldsize))
14031 curpos = pos + fieldsize;
14032 if (index && TREE_CODE (index) == RANGE_EXPR)
14034 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
14035 - tree_low_cst (TREE_OPERAND (index, 0), 0);
14039 memcpy (array + curpos, array + pos, fieldsize);
14040 curpos += fieldsize;
14043 gcc_assert (curpos <= size);
14047 else if (TREE_CODE (type) == RECORD_TYPE
14048 || TREE_CODE (type) == UNION_TYPE)
14050 tree field = NULL_TREE;
14051 unsigned HOST_WIDE_INT cnt;
14052 constructor_elt *ce;
14054 if (int_size_in_bytes (type) != size)
14057 if (TREE_CODE (type) == RECORD_TYPE)
14058 field = TYPE_FIELDS (type);
14061 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
14062 cnt++, field = field ? TREE_CHAIN (field) : 0)
14064 tree val = ce->value;
14065 int pos, fieldsize;
14067 if (ce->index != 0)
14073 if (field == NULL_TREE || DECL_BIT_FIELD (field))
14076 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
14077 && TYPE_DOMAIN (TREE_TYPE (field))
14078 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
14080 else if (DECL_SIZE_UNIT (field) == NULL_TREE
14081 || !host_integerp (DECL_SIZE_UNIT (field), 0))
14083 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
14084 pos = int_byte_position (field);
14085 gcc_assert (pos + fieldsize <= size);
14087 && !native_encode_initializer (val, array + pos, fieldsize))
14093 case VIEW_CONVERT_EXPR:
14094 case NON_LVALUE_EXPR:
14095 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
14097 return native_encode_expr (init, array, size) == size;
14101 /* Attach a DW_AT_const_value attribute to DIE. The value of the
14102 attribute is the const value T. */
14105 tree_add_const_value_attribute (dw_die_ref die, tree t)
14108 tree type = TREE_TYPE (t);
14111 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
14115 gcc_assert (!DECL_P (init));
14117 rtl = rtl_for_decl_init (init, type);
14119 return add_const_value_attribute (die, rtl);
14120 /* If the host and target are sane, try harder. */
14121 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
14122 && initializer_constant_valid_p (init, type))
14124 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
14125 if (size > 0 && (int) size == size)
14127 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
14129 if (native_encode_initializer (init, array, size))
14131 add_AT_vec (die, DW_AT_const_value, size, 1, array);
14139 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
14140 attribute is the const value of T, where T is an integral constant
14141 variable with static storage duration
14142 (so it can't be a PARM_DECL or a RESULT_DECL). */
14145 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
14149 || (TREE_CODE (decl) != VAR_DECL
14150 && TREE_CODE (decl) != CONST_DECL))
14153 if (TREE_READONLY (decl)
14154 && ! TREE_THIS_VOLATILE (decl)
14155 && DECL_INITIAL (decl))
14160 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
14163 /* Convert the CFI instructions for the current function into a
14164 location list. This is used for DW_AT_frame_base when we targeting
14165 a dwarf2 consumer that does not support the dwarf3
14166 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
14169 static dw_loc_list_ref
14170 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
14173 dw_loc_list_ref list, *list_tail;
14175 dw_cfa_location last_cfa, next_cfa;
14176 const char *start_label, *last_label, *section;
14177 dw_cfa_location remember;
14179 fde = current_fde ();
14180 gcc_assert (fde != NULL);
14182 section = secname_for_decl (current_function_decl);
14186 memset (&next_cfa, 0, sizeof (next_cfa));
14187 next_cfa.reg = INVALID_REGNUM;
14188 remember = next_cfa;
14190 start_label = fde->dw_fde_begin;
14192 /* ??? Bald assumption that the CIE opcode list does not contain
14193 advance opcodes. */
14194 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
14195 lookup_cfa_1 (cfi, &next_cfa, &remember);
14197 last_cfa = next_cfa;
14198 last_label = start_label;
14200 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
14201 switch (cfi->dw_cfi_opc)
14203 case DW_CFA_set_loc:
14204 case DW_CFA_advance_loc1:
14205 case DW_CFA_advance_loc2:
14206 case DW_CFA_advance_loc4:
14207 if (!cfa_equal_p (&last_cfa, &next_cfa))
14209 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
14210 start_label, last_label, section,
14213 list_tail = &(*list_tail)->dw_loc_next;
14214 last_cfa = next_cfa;
14215 start_label = last_label;
14217 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
14220 case DW_CFA_advance_loc:
14221 /* The encoding is complex enough that we should never emit this. */
14222 gcc_unreachable ();
14225 lookup_cfa_1 (cfi, &next_cfa, &remember);
14229 if (!cfa_equal_p (&last_cfa, &next_cfa))
14231 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
14232 start_label, last_label, section,
14234 list_tail = &(*list_tail)->dw_loc_next;
14235 start_label = last_label;
14237 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
14238 start_label, fde->dw_fde_end, section,
14244 /* Compute a displacement from the "steady-state frame pointer" to the
14245 frame base (often the same as the CFA), and store it in
14246 frame_pointer_fb_offset. OFFSET is added to the displacement
14247 before the latter is negated. */
14250 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
14254 #ifdef FRAME_POINTER_CFA_OFFSET
14255 reg = frame_pointer_rtx;
14256 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
14258 reg = arg_pointer_rtx;
14259 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
14262 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
14263 if (GET_CODE (elim) == PLUS)
14265 offset += INTVAL (XEXP (elim, 1));
14266 elim = XEXP (elim, 0);
14269 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
14270 && (elim == hard_frame_pointer_rtx
14271 || elim == stack_pointer_rtx))
14272 || elim == (frame_pointer_needed
14273 ? hard_frame_pointer_rtx
14274 : stack_pointer_rtx));
14276 frame_pointer_fb_offset = -offset;
14279 /* Generate a DW_AT_name attribute given some string value to be included as
14280 the value of the attribute. */
14283 add_name_attribute (dw_die_ref die, const char *name_string)
14285 if (name_string != NULL && *name_string != 0)
14287 if (demangle_name_func)
14288 name_string = (*demangle_name_func) (name_string);
14290 add_AT_string (die, DW_AT_name, name_string);
14294 /* Generate a DW_AT_comp_dir attribute for DIE. */
14297 add_comp_dir_attribute (dw_die_ref die)
14299 const char *wd = get_src_pwd ();
14305 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
14309 wdlen = strlen (wd);
14310 wd1 = GGC_NEWVEC (char, wdlen + 2);
14312 wd1 [wdlen] = DIR_SEPARATOR;
14313 wd1 [wdlen + 1] = 0;
14317 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
14320 /* Given a tree node describing an array bound (either lower or upper) output
14321 a representation for that bound. */
14324 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
14326 switch (TREE_CODE (bound))
14331 /* All fixed-bounds are represented by INTEGER_CST nodes. */
14334 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
14336 /* Use the default if possible. */
14337 if (bound_attr == DW_AT_lower_bound
14338 && (((is_c_family () || is_java ()) && integer_zerop (bound))
14339 || (is_fortran () && integer_onep (bound))))
14342 /* Otherwise represent the bound as an unsigned value with the
14343 precision of its type. The precision and signedness of the
14344 type will be necessary to re-interpret it unambiguously. */
14345 else if (prec < HOST_BITS_PER_WIDE_INT)
14347 unsigned HOST_WIDE_INT mask
14348 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
14349 add_AT_unsigned (subrange_die, bound_attr,
14350 TREE_INT_CST_LOW (bound) & mask);
14352 else if (prec == HOST_BITS_PER_WIDE_INT
14353 || TREE_INT_CST_HIGH (bound) == 0)
14354 add_AT_unsigned (subrange_die, bound_attr,
14355 TREE_INT_CST_LOW (bound));
14357 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
14358 TREE_INT_CST_LOW (bound));
14363 case VIEW_CONVERT_EXPR:
14364 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
14374 dw_die_ref decl_die = lookup_decl_die (bound);
14375 dw_loc_list_ref loc;
14377 /* ??? Can this happen, or should the variable have been bound
14378 first? Probably it can, since I imagine that we try to create
14379 the types of parameters in the order in which they exist in
14380 the list, and won't have created a forward reference to a
14381 later parameter. */
14382 if (decl_die != NULL)
14383 add_AT_die_ref (subrange_die, bound_attr, decl_die);
14386 loc = loc_list_from_tree (bound, 0);
14387 add_AT_location_description (subrange_die, bound_attr, loc);
14394 /* Otherwise try to create a stack operation procedure to
14395 evaluate the value of the array bound. */
14397 dw_die_ref ctx, decl_die;
14398 dw_loc_list_ref list;
14400 list = loc_list_from_tree (bound, 2);
14404 if (current_function_decl == 0)
14405 ctx = comp_unit_die;
14407 ctx = lookup_decl_die (current_function_decl);
14409 decl_die = new_die (DW_TAG_variable, ctx, bound);
14410 add_AT_flag (decl_die, DW_AT_artificial, 1);
14411 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
14412 if (list->dw_loc_next)
14413 add_AT_loc_list (decl_die, DW_AT_location, list);
14415 add_AT_loc (decl_die, DW_AT_location, list->expr);
14417 add_AT_die_ref (subrange_die, bound_attr, decl_die);
14423 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
14424 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
14425 Note that the block of subscript information for an array type also
14426 includes information about the element type of the given array type. */
14429 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
14431 unsigned dimension_number;
14433 dw_die_ref subrange_die;
14435 for (dimension_number = 0;
14436 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
14437 type = TREE_TYPE (type), dimension_number++)
14439 tree domain = TYPE_DOMAIN (type);
14441 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
14444 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
14445 and (in GNU C only) variable bounds. Handle all three forms
14447 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
14450 /* We have an array type with specified bounds. */
14451 lower = TYPE_MIN_VALUE (domain);
14452 upper = TYPE_MAX_VALUE (domain);
14454 /* Define the index type. */
14455 if (TREE_TYPE (domain))
14457 /* ??? This is probably an Ada unnamed subrange type. Ignore the
14458 TREE_TYPE field. We can't emit debug info for this
14459 because it is an unnamed integral type. */
14460 if (TREE_CODE (domain) == INTEGER_TYPE
14461 && TYPE_NAME (domain) == NULL_TREE
14462 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
14463 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
14466 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
14470 /* ??? If upper is NULL, the array has unspecified length,
14471 but it does have a lower bound. This happens with Fortran
14473 Since the debugger is definitely going to need to know N
14474 to produce useful results, go ahead and output the lower
14475 bound solo, and hope the debugger can cope. */
14477 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
14479 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
14482 /* Otherwise we have an array type with an unspecified length. The
14483 DWARF-2 spec does not say how to handle this; let's just leave out the
14489 add_byte_size_attribute (dw_die_ref die, tree tree_node)
14493 switch (TREE_CODE (tree_node))
14498 case ENUMERAL_TYPE:
14501 case QUAL_UNION_TYPE:
14502 size = int_size_in_bytes (tree_node);
14505 /* For a data member of a struct or union, the DW_AT_byte_size is
14506 generally given as the number of bytes normally allocated for an
14507 object of the *declared* type of the member itself. This is true
14508 even for bit-fields. */
14509 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
14512 gcc_unreachable ();
14515 /* Note that `size' might be -1 when we get to this point. If it is, that
14516 indicates that the byte size of the entity in question is variable. We
14517 have no good way of expressing this fact in Dwarf at the present time,
14518 so just let the -1 pass on through. */
14519 add_AT_unsigned (die, DW_AT_byte_size, size);
14522 /* For a FIELD_DECL node which represents a bit-field, output an attribute
14523 which specifies the distance in bits from the highest order bit of the
14524 "containing object" for the bit-field to the highest order bit of the
14527 For any given bit-field, the "containing object" is a hypothetical object
14528 (of some integral or enum type) within which the given bit-field lives. The
14529 type of this hypothetical "containing object" is always the same as the
14530 declared type of the individual bit-field itself. The determination of the
14531 exact location of the "containing object" for a bit-field is rather
14532 complicated. It's handled by the `field_byte_offset' function (above).
14534 Note that it is the size (in bytes) of the hypothetical "containing object"
14535 which will be given in the DW_AT_byte_size attribute for this bit-field.
14536 (See `byte_size_attribute' above). */
14539 add_bit_offset_attribute (dw_die_ref die, tree decl)
14541 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
14542 tree type = DECL_BIT_FIELD_TYPE (decl);
14543 HOST_WIDE_INT bitpos_int;
14544 HOST_WIDE_INT highest_order_object_bit_offset;
14545 HOST_WIDE_INT highest_order_field_bit_offset;
14546 HOST_WIDE_INT unsigned bit_offset;
14548 /* Must be a field and a bit field. */
14549 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
14551 /* We can't yet handle bit-fields whose offsets are variable, so if we
14552 encounter such things, just return without generating any attribute
14553 whatsoever. Likewise for variable or too large size. */
14554 if (! host_integerp (bit_position (decl), 0)
14555 || ! host_integerp (DECL_SIZE (decl), 1))
14558 bitpos_int = int_bit_position (decl);
14560 /* Note that the bit offset is always the distance (in bits) from the
14561 highest-order bit of the "containing object" to the highest-order bit of
14562 the bit-field itself. Since the "high-order end" of any object or field
14563 is different on big-endian and little-endian machines, the computation
14564 below must take account of these differences. */
14565 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
14566 highest_order_field_bit_offset = bitpos_int;
14568 if (! BYTES_BIG_ENDIAN)
14570 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
14571 highest_order_object_bit_offset += simple_type_size_in_bits (type);
14575 = (! BYTES_BIG_ENDIAN
14576 ? highest_order_object_bit_offset - highest_order_field_bit_offset
14577 : highest_order_field_bit_offset - highest_order_object_bit_offset);
14579 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
14582 /* For a FIELD_DECL node which represents a bit field, output an attribute
14583 which specifies the length in bits of the given field. */
14586 add_bit_size_attribute (dw_die_ref die, tree decl)
14588 /* Must be a field and a bit field. */
14589 gcc_assert (TREE_CODE (decl) == FIELD_DECL
14590 && DECL_BIT_FIELD_TYPE (decl));
14592 if (host_integerp (DECL_SIZE (decl), 1))
14593 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
14596 /* If the compiled language is ANSI C, then add a 'prototyped'
14597 attribute, if arg types are given for the parameters of a function. */
14600 add_prototyped_attribute (dw_die_ref die, tree func_type)
14602 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
14603 && TYPE_ARG_TYPES (func_type) != NULL)
14604 add_AT_flag (die, DW_AT_prototyped, 1);
14607 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
14608 by looking in either the type declaration or object declaration
14611 static inline dw_die_ref
14612 add_abstract_origin_attribute (dw_die_ref die, tree origin)
14614 dw_die_ref origin_die = NULL;
14616 if (TREE_CODE (origin) != FUNCTION_DECL)
14618 /* We may have gotten separated from the block for the inlined
14619 function, if we're in an exception handler or some such; make
14620 sure that the abstract function has been written out.
14622 Doing this for nested functions is wrong, however; functions are
14623 distinct units, and our context might not even be inline. */
14627 fn = TYPE_STUB_DECL (fn);
14629 fn = decl_function_context (fn);
14631 dwarf2out_abstract_function (fn);
14634 if (DECL_P (origin))
14635 origin_die = lookup_decl_die (origin);
14636 else if (TYPE_P (origin))
14637 origin_die = lookup_type_die (origin);
14639 /* XXX: Functions that are never lowered don't always have correct block
14640 trees (in the case of java, they simply have no block tree, in some other
14641 languages). For these functions, there is nothing we can really do to
14642 output correct debug info for inlined functions in all cases. Rather
14643 than die, we'll just produce deficient debug info now, in that we will
14644 have variables without a proper abstract origin. In the future, when all
14645 functions are lowered, we should re-add a gcc_assert (origin_die)
14649 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
14653 /* We do not currently support the pure_virtual attribute. */
14656 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
14658 if (DECL_VINDEX (func_decl))
14660 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14662 if (host_integerp (DECL_VINDEX (func_decl), 0))
14663 add_AT_loc (die, DW_AT_vtable_elem_location,
14664 new_loc_descr (DW_OP_constu,
14665 tree_low_cst (DECL_VINDEX (func_decl), 0),
14668 /* GNU extension: Record what type this method came from originally. */
14669 if (debug_info_level > DINFO_LEVEL_TERSE)
14670 add_AT_die_ref (die, DW_AT_containing_type,
14671 lookup_type_die (DECL_CONTEXT (func_decl)));
14675 /* Add source coordinate attributes for the given decl. */
14678 add_src_coords_attributes (dw_die_ref die, tree decl)
14680 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14682 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
14683 add_AT_unsigned (die, DW_AT_decl_line, s.line);
14686 /* Add a DW_AT_name attribute and source coordinate attribute for the
14687 given decl, but only if it actually has a name. */
14690 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
14694 decl_name = DECL_NAME (decl);
14695 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
14697 add_name_attribute (die, dwarf2_name (decl, 0));
14698 if (! DECL_ARTIFICIAL (decl))
14699 add_src_coords_attributes (die, decl);
14701 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
14702 && TREE_PUBLIC (decl)
14703 && !DECL_ABSTRACT (decl)
14704 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
14707 /* Defer until we have an assembler name set. */
14708 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
14710 limbo_die_node *asm_name;
14712 asm_name = GGC_CNEW (limbo_die_node);
14713 asm_name->die = die;
14714 asm_name->created_for = decl;
14715 asm_name->next = deferred_asm_name;
14716 deferred_asm_name = asm_name;
14718 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
14719 add_AT_string (die, DW_AT_MIPS_linkage_name,
14720 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
14724 #ifdef VMS_DEBUGGING_INFO
14725 /* Get the function's name, as described by its RTL. This may be different
14726 from the DECL_NAME name used in the source file. */
14727 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
14729 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
14730 XEXP (DECL_RTL (decl), 0));
14731 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
14736 /* Push a new declaration scope. */
14739 push_decl_scope (tree scope)
14741 VEC_safe_push (tree, gc, decl_scope_table, scope);
14744 /* Pop a declaration scope. */
14747 pop_decl_scope (void)
14749 VEC_pop (tree, decl_scope_table);
14752 /* Return the DIE for the scope that immediately contains this type.
14753 Non-named types get global scope. Named types nested in other
14754 types get their containing scope if it's open, or global scope
14755 otherwise. All other types (i.e. function-local named types) get
14756 the current active scope. */
14759 scope_die_for (tree t, dw_die_ref context_die)
14761 dw_die_ref scope_die = NULL;
14762 tree containing_scope;
14765 /* Non-types always go in the current scope. */
14766 gcc_assert (TYPE_P (t));
14768 containing_scope = TYPE_CONTEXT (t);
14770 /* Use the containing namespace if it was passed in (for a declaration). */
14771 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
14773 if (context_die == lookup_decl_die (containing_scope))
14776 containing_scope = NULL_TREE;
14779 /* Ignore function type "scopes" from the C frontend. They mean that
14780 a tagged type is local to a parmlist of a function declarator, but
14781 that isn't useful to DWARF. */
14782 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
14783 containing_scope = NULL_TREE;
14785 if (containing_scope == NULL_TREE)
14786 scope_die = comp_unit_die;
14787 else if (TYPE_P (containing_scope))
14789 /* For types, we can just look up the appropriate DIE. But
14790 first we check to see if we're in the middle of emitting it
14791 so we know where the new DIE should go. */
14792 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
14793 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
14798 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
14799 || TREE_ASM_WRITTEN (containing_scope));
14801 /* If none of the current dies are suitable, we get file scope. */
14802 scope_die = comp_unit_die;
14805 scope_die = lookup_type_die (containing_scope);
14808 scope_die = context_die;
14813 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
14816 local_scope_p (dw_die_ref context_die)
14818 for (; context_die; context_die = context_die->die_parent)
14819 if (context_die->die_tag == DW_TAG_inlined_subroutine
14820 || context_die->die_tag == DW_TAG_subprogram)
14826 /* Returns nonzero if CONTEXT_DIE is a class. */
14829 class_scope_p (dw_die_ref context_die)
14831 return (context_die
14832 && (context_die->die_tag == DW_TAG_structure_type
14833 || context_die->die_tag == DW_TAG_class_type
14834 || context_die->die_tag == DW_TAG_interface_type
14835 || context_die->die_tag == DW_TAG_union_type));
14838 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
14839 whether or not to treat a DIE in this context as a declaration. */
14842 class_or_namespace_scope_p (dw_die_ref context_die)
14844 return (class_scope_p (context_die)
14845 || (context_die && context_die->die_tag == DW_TAG_namespace));
14848 /* Many forms of DIEs require a "type description" attribute. This
14849 routine locates the proper "type descriptor" die for the type given
14850 by 'type', and adds a DW_AT_type attribute below the given die. */
14853 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
14854 int decl_volatile, dw_die_ref context_die)
14856 enum tree_code code = TREE_CODE (type);
14857 dw_die_ref type_die = NULL;
14859 /* ??? If this type is an unnamed subrange type of an integral, floating-point
14860 or fixed-point type, use the inner type. This is because we have no
14861 support for unnamed types in base_type_die. This can happen if this is
14862 an Ada subrange type. Correct solution is emit a subrange type die. */
14863 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
14864 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
14865 type = TREE_TYPE (type), code = TREE_CODE (type);
14867 if (code == ERROR_MARK
14868 /* Handle a special case. For functions whose return type is void, we
14869 generate *no* type attribute. (Note that no object may have type
14870 `void', so this only applies to function return types). */
14871 || code == VOID_TYPE)
14874 type_die = modified_type_die (type,
14875 decl_const || TYPE_READONLY (type),
14876 decl_volatile || TYPE_VOLATILE (type),
14879 if (type_die != NULL)
14880 add_AT_die_ref (object_die, DW_AT_type, type_die);
14883 /* Given an object die, add the calling convention attribute for the
14884 function call type. */
14886 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
14888 enum dwarf_calling_convention value = DW_CC_normal;
14890 value = ((enum dwarf_calling_convention)
14891 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
14893 /* DWARF doesn't provide a way to identify a program's source-level
14894 entry point. DW_AT_calling_convention attributes are only meant
14895 to describe functions' calling conventions. However, lacking a
14896 better way to signal the Fortran main program, we use this for the
14897 time being, following existing custom. */
14899 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
14900 value = DW_CC_program;
14902 /* Only add the attribute if the backend requests it, and
14903 is not DW_CC_normal. */
14904 if (value && (value != DW_CC_normal))
14905 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
14908 /* Given a tree pointer to a struct, class, union, or enum type node, return
14909 a pointer to the (string) tag name for the given type, or zero if the type
14910 was declared without a tag. */
14912 static const char *
14913 type_tag (const_tree type)
14915 const char *name = 0;
14917 if (TYPE_NAME (type) != 0)
14921 /* Find the IDENTIFIER_NODE for the type name. */
14922 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
14923 t = TYPE_NAME (type);
14925 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
14926 a TYPE_DECL node, regardless of whether or not a `typedef' was
14928 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14929 && ! DECL_IGNORED_P (TYPE_NAME (type)))
14931 /* We want to be extra verbose. Don't call dwarf_name if
14932 DECL_NAME isn't set. The default hook for decl_printable_name
14933 doesn't like that, and in this context it's correct to return
14934 0, instead of "<anonymous>" or the like. */
14935 if (DECL_NAME (TYPE_NAME (type)))
14936 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
14939 /* Now get the name as a string, or invent one. */
14940 if (!name && t != 0)
14941 name = IDENTIFIER_POINTER (t);
14944 return (name == 0 || *name == '\0') ? 0 : name;
14947 /* Return the type associated with a data member, make a special check
14948 for bit field types. */
14951 member_declared_type (const_tree member)
14953 return (DECL_BIT_FIELD_TYPE (member)
14954 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
14957 /* Get the decl's label, as described by its RTL. This may be different
14958 from the DECL_NAME name used in the source file. */
14961 static const char *
14962 decl_start_label (tree decl)
14965 const char *fnname;
14967 x = DECL_RTL (decl);
14968 gcc_assert (MEM_P (x));
14971 gcc_assert (GET_CODE (x) == SYMBOL_REF);
14973 fnname = XSTR (x, 0);
14978 /* These routines generate the internal representation of the DIE's for
14979 the compilation unit. Debugging information is collected by walking
14980 the declaration trees passed in from dwarf2out_decl(). */
14983 gen_array_type_die (tree type, dw_die_ref context_die)
14985 dw_die_ref scope_die = scope_die_for (type, context_die);
14986 dw_die_ref array_die;
14988 /* GNU compilers represent multidimensional array types as sequences of one
14989 dimensional array types whose element types are themselves array types.
14990 We sometimes squish that down to a single array_type DIE with multiple
14991 subscripts in the Dwarf debugging info. The draft Dwarf specification
14992 say that we are allowed to do this kind of compression in C, because
14993 there is no difference between an array of arrays and a multidimensional
14994 array. We don't do this for Ada to remain as close as possible to the
14995 actual representation, which is especially important against the language
14996 flexibilty wrt arrays of variable size. */
14998 bool collapse_nested_arrays = !is_ada ();
15001 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
15002 DW_TAG_string_type doesn't have DW_AT_type attribute). */
15003 if (TYPE_STRING_FLAG (type)
15004 && TREE_CODE (type) == ARRAY_TYPE
15006 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
15008 HOST_WIDE_INT size;
15010 array_die = new_die (DW_TAG_string_type, scope_die, type);
15011 add_name_attribute (array_die, type_tag (type));
15012 equate_type_number_to_die (type, array_die);
15013 size = int_size_in_bytes (type);
15015 add_AT_unsigned (array_die, DW_AT_byte_size, size);
15016 else if (TYPE_DOMAIN (type) != NULL_TREE
15017 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
15018 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
15020 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
15021 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
15023 size = int_size_in_bytes (TREE_TYPE (szdecl));
15024 if (loc && size > 0)
15026 add_AT_location_description (array_die, DW_AT_string_length, loc);
15027 if (size != DWARF2_ADDR_SIZE)
15028 add_AT_unsigned (array_die, DW_AT_byte_size, size);
15034 /* ??? The SGI dwarf reader fails for array of array of enum types
15035 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
15036 array type comes before the outer array type. We thus call gen_type_die
15037 before we new_die and must prevent nested array types collapsing for this
15040 #ifdef MIPS_DEBUGGING_INFO
15041 gen_type_die (TREE_TYPE (type), context_die);
15042 collapse_nested_arrays = false;
15045 array_die = new_die (DW_TAG_array_type, scope_die, type);
15046 add_name_attribute (array_die, type_tag (type));
15047 equate_type_number_to_die (type, array_die);
15049 if (TREE_CODE (type) == VECTOR_TYPE)
15051 /* The frontend feeds us a representation for the vector as a struct
15052 containing an array. Pull out the array type. */
15053 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
15054 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
15057 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
15059 && TREE_CODE (type) == ARRAY_TYPE
15060 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
15061 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
15062 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
15065 /* We default the array ordering. SDB will probably do
15066 the right things even if DW_AT_ordering is not present. It's not even
15067 an issue until we start to get into multidimensional arrays anyway. If
15068 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
15069 then we'll have to put the DW_AT_ordering attribute back in. (But if
15070 and when we find out that we need to put these in, we will only do so
15071 for multidimensional arrays. */
15072 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
15075 #ifdef MIPS_DEBUGGING_INFO
15076 /* The SGI compilers handle arrays of unknown bound by setting
15077 AT_declaration and not emitting any subrange DIEs. */
15078 if (! TYPE_DOMAIN (type))
15079 add_AT_flag (array_die, DW_AT_declaration, 1);
15082 add_subscript_info (array_die, type, collapse_nested_arrays);
15084 /* Add representation of the type of the elements of this array type and
15085 emit the corresponding DIE if we haven't done it already. */
15086 element_type = TREE_TYPE (type);
15087 if (collapse_nested_arrays)
15088 while (TREE_CODE (element_type) == ARRAY_TYPE)
15090 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
15092 element_type = TREE_TYPE (element_type);
15095 #ifndef MIPS_DEBUGGING_INFO
15096 gen_type_die (element_type, context_die);
15099 add_type_attribute (array_die, element_type, 0, 0, context_die);
15101 if (get_AT (array_die, DW_AT_name))
15102 add_pubtype (type, array_die);
15105 static dw_loc_descr_ref
15106 descr_info_loc (tree val, tree base_decl)
15108 HOST_WIDE_INT size;
15109 dw_loc_descr_ref loc, loc2;
15110 enum dwarf_location_atom op;
15112 if (val == base_decl)
15113 return new_loc_descr (DW_OP_push_object_address, 0, 0);
15115 switch (TREE_CODE (val))
15118 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15120 return loc_descriptor_from_tree (val, 0);
15122 if (host_integerp (val, 0))
15123 return int_loc_descriptor (tree_low_cst (val, 0));
15126 size = int_size_in_bytes (TREE_TYPE (val));
15129 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15132 if (size == DWARF2_ADDR_SIZE)
15133 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
15135 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
15137 case POINTER_PLUS_EXPR:
15139 if (host_integerp (TREE_OPERAND (val, 1), 1)
15140 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
15143 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15146 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
15152 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15155 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
15158 add_loc_descr (&loc, loc2);
15159 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
15181 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
15182 tree val, tree base_decl)
15184 dw_loc_descr_ref loc;
15186 if (host_integerp (val, 0))
15188 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
15192 loc = descr_info_loc (val, base_decl);
15196 add_AT_loc (die, attr, loc);
15199 /* This routine generates DIE for array with hidden descriptor, details
15200 are filled into *info by a langhook. */
15203 gen_descr_array_type_die (tree type, struct array_descr_info *info,
15204 dw_die_ref context_die)
15206 dw_die_ref scope_die = scope_die_for (type, context_die);
15207 dw_die_ref array_die;
15210 array_die = new_die (DW_TAG_array_type, scope_die, type);
15211 add_name_attribute (array_die, type_tag (type));
15212 equate_type_number_to_die (type, array_die);
15214 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
15216 && info->ndimensions >= 2)
15217 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
15219 if (info->data_location)
15220 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
15222 if (info->associated)
15223 add_descr_info_field (array_die, DW_AT_associated, info->associated,
15225 if (info->allocated)
15226 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
15229 for (dim = 0; dim < info->ndimensions; dim++)
15231 dw_die_ref subrange_die
15232 = new_die (DW_TAG_subrange_type, array_die, NULL);
15234 if (info->dimen[dim].lower_bound)
15236 /* If it is the default value, omit it. */
15237 if ((is_c_family () || is_java ())
15238 && integer_zerop (info->dimen[dim].lower_bound))
15240 else if (is_fortran ()
15241 && integer_onep (info->dimen[dim].lower_bound))
15244 add_descr_info_field (subrange_die, DW_AT_lower_bound,
15245 info->dimen[dim].lower_bound,
15248 if (info->dimen[dim].upper_bound)
15249 add_descr_info_field (subrange_die, DW_AT_upper_bound,
15250 info->dimen[dim].upper_bound,
15252 if (info->dimen[dim].stride)
15253 add_descr_info_field (subrange_die, DW_AT_byte_stride,
15254 info->dimen[dim].stride,
15258 gen_type_die (info->element_type, context_die);
15259 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
15261 if (get_AT (array_die, DW_AT_name))
15262 add_pubtype (type, array_die);
15267 gen_entry_point_die (tree decl, dw_die_ref context_die)
15269 tree origin = decl_ultimate_origin (decl);
15270 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
15272 if (origin != NULL)
15273 add_abstract_origin_attribute (decl_die, origin);
15276 add_name_and_src_coords_attributes (decl_die, decl);
15277 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
15278 0, 0, context_die);
15281 if (DECL_ABSTRACT (decl))
15282 equate_decl_number_to_die (decl, decl_die);
15284 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
15288 /* Walk through the list of incomplete types again, trying once more to
15289 emit full debugging info for them. */
15292 retry_incomplete_types (void)
15296 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
15297 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
15300 /* Determine what tag to use for a record type. */
15302 static enum dwarf_tag
15303 record_type_tag (tree type)
15305 if (! lang_hooks.types.classify_record)
15306 return DW_TAG_structure_type;
15308 switch (lang_hooks.types.classify_record (type))
15310 case RECORD_IS_STRUCT:
15311 return DW_TAG_structure_type;
15313 case RECORD_IS_CLASS:
15314 return DW_TAG_class_type;
15316 case RECORD_IS_INTERFACE:
15317 if (dwarf_version >= 3 || !dwarf_strict)
15318 return DW_TAG_interface_type;
15319 return DW_TAG_structure_type;
15322 gcc_unreachable ();
15326 /* Generate a DIE to represent an enumeration type. Note that these DIEs
15327 include all of the information about the enumeration values also. Each
15328 enumerated type name/value is listed as a child of the enumerated type
15332 gen_enumeration_type_die (tree type, dw_die_ref context_die)
15334 dw_die_ref type_die = lookup_type_die (type);
15336 if (type_die == NULL)
15338 type_die = new_die (DW_TAG_enumeration_type,
15339 scope_die_for (type, context_die), type);
15340 equate_type_number_to_die (type, type_die);
15341 add_name_attribute (type_die, type_tag (type));
15343 else if (! TYPE_SIZE (type))
15346 remove_AT (type_die, DW_AT_declaration);
15348 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
15349 given enum type is incomplete, do not generate the DW_AT_byte_size
15350 attribute or the DW_AT_element_list attribute. */
15351 if (TYPE_SIZE (type))
15355 TREE_ASM_WRITTEN (type) = 1;
15356 add_byte_size_attribute (type_die, type);
15357 if (TYPE_STUB_DECL (type) != NULL_TREE)
15358 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
15360 /* If the first reference to this type was as the return type of an
15361 inline function, then it may not have a parent. Fix this now. */
15362 if (type_die->die_parent == NULL)
15363 add_child_die (scope_die_for (type, context_die), type_die);
15365 for (link = TYPE_VALUES (type);
15366 link != NULL; link = TREE_CHAIN (link))
15368 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
15369 tree value = TREE_VALUE (link);
15371 add_name_attribute (enum_die,
15372 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
15374 if (TREE_CODE (value) == CONST_DECL)
15375 value = DECL_INITIAL (value);
15377 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
15378 /* DWARF2 does not provide a way of indicating whether or
15379 not enumeration constants are signed or unsigned. GDB
15380 always assumes the values are signed, so we output all
15381 values as if they were signed. That means that
15382 enumeration constants with very large unsigned values
15383 will appear to have negative values in the debugger. */
15384 add_AT_int (enum_die, DW_AT_const_value,
15385 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
15389 add_AT_flag (type_die, DW_AT_declaration, 1);
15391 if (get_AT (type_die, DW_AT_name))
15392 add_pubtype (type, type_die);
15397 /* Generate a DIE to represent either a real live formal parameter decl or to
15398 represent just the type of some formal parameter position in some function
15401 Note that this routine is a bit unusual because its argument may be a
15402 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
15403 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
15404 node. If it's the former then this function is being called to output a
15405 DIE to represent a formal parameter object (or some inlining thereof). If
15406 it's the latter, then this function is only being called to output a
15407 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
15408 argument type of some subprogram type.
15409 If EMIT_NAME_P is true, name and source coordinate attributes
15413 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
15414 dw_die_ref context_die)
15416 tree node_or_origin = node ? node : origin;
15417 dw_die_ref parm_die
15418 = new_die (DW_TAG_formal_parameter, context_die, node);
15420 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
15422 case tcc_declaration:
15424 origin = decl_ultimate_origin (node);
15425 if (origin != NULL)
15426 add_abstract_origin_attribute (parm_die, origin);
15429 tree type = TREE_TYPE (node);
15431 add_name_and_src_coords_attributes (parm_die, node);
15432 if (decl_by_reference_p (node))
15433 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
15436 add_type_attribute (parm_die, type,
15437 TREE_READONLY (node),
15438 TREE_THIS_VOLATILE (node),
15440 if (DECL_ARTIFICIAL (node))
15441 add_AT_flag (parm_die, DW_AT_artificial, 1);
15444 if (node && node != origin)
15445 equate_decl_number_to_die (node, parm_die);
15446 if (! DECL_ABSTRACT (node_or_origin))
15447 add_location_or_const_value_attribute (parm_die, node_or_origin,
15453 /* We were called with some kind of a ..._TYPE node. */
15454 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
15458 gcc_unreachable ();
15464 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
15465 children DW_TAG_formal_parameter DIEs representing the arguments of the
15468 PARM_PACK must be a function parameter pack.
15469 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
15470 must point to the subsequent arguments of the function PACK_ARG belongs to.
15471 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
15472 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
15473 following the last one for which a DIE was generated. */
15476 gen_formal_parameter_pack_die (tree parm_pack,
15478 dw_die_ref subr_die,
15482 dw_die_ref parm_pack_die;
15484 gcc_assert (parm_pack
15485 && lang_hooks.function_parameter_pack_p (parm_pack)
15486 && DECL_NAME (parm_pack)
15489 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
15490 add_AT_string (parm_pack_die, DW_AT_name,
15491 IDENTIFIER_POINTER (DECL_NAME (parm_pack)));
15493 for (arg = pack_arg; arg; arg = TREE_CHAIN (arg))
15495 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
15498 gen_formal_parameter_die (arg, NULL,
15499 false /* Don't emit name attribute. */,
15504 return parm_pack_die;
15507 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
15508 at the end of an (ANSI prototyped) formal parameters list. */
15511 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
15513 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
15516 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
15517 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
15518 parameters as specified in some function type specification (except for
15519 those which appear as part of a function *definition*). */
15522 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
15525 tree formal_type = NULL;
15526 tree first_parm_type;
15529 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
15531 arg = DECL_ARGUMENTS (function_or_method_type);
15532 function_or_method_type = TREE_TYPE (function_or_method_type);
15537 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
15539 /* Make our first pass over the list of formal parameter types and output a
15540 DW_TAG_formal_parameter DIE for each one. */
15541 for (link = first_parm_type; link; )
15543 dw_die_ref parm_die;
15545 formal_type = TREE_VALUE (link);
15546 if (formal_type == void_type_node)
15549 /* Output a (nameless) DIE to represent the formal parameter itself. */
15550 parm_die = gen_formal_parameter_die (formal_type, NULL,
15551 true /* Emit name attribute. */,
15553 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
15554 && link == first_parm_type)
15555 || (arg && DECL_ARTIFICIAL (arg)))
15556 add_AT_flag (parm_die, DW_AT_artificial, 1);
15558 link = TREE_CHAIN (link);
15560 arg = TREE_CHAIN (arg);
15563 /* If this function type has an ellipsis, add a
15564 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
15565 if (formal_type != void_type_node)
15566 gen_unspecified_parameters_die (function_or_method_type, context_die);
15568 /* Make our second (and final) pass over the list of formal parameter types
15569 and output DIEs to represent those types (as necessary). */
15570 for (link = TYPE_ARG_TYPES (function_or_method_type);
15571 link && TREE_VALUE (link);
15572 link = TREE_CHAIN (link))
15573 gen_type_die (TREE_VALUE (link), context_die);
15576 /* We want to generate the DIE for TYPE so that we can generate the
15577 die for MEMBER, which has been defined; we will need to refer back
15578 to the member declaration nested within TYPE. If we're trying to
15579 generate minimal debug info for TYPE, processing TYPE won't do the
15580 trick; we need to attach the member declaration by hand. */
15583 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
15585 gen_type_die (type, context_die);
15587 /* If we're trying to avoid duplicate debug info, we may not have
15588 emitted the member decl for this function. Emit it now. */
15589 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
15590 && ! lookup_decl_die (member))
15592 dw_die_ref type_die;
15593 gcc_assert (!decl_ultimate_origin (member));
15595 push_decl_scope (type);
15596 type_die = lookup_type_die (type);
15597 if (TREE_CODE (member) == FUNCTION_DECL)
15598 gen_subprogram_die (member, type_die);
15599 else if (TREE_CODE (member) == FIELD_DECL)
15601 /* Ignore the nameless fields that are used to skip bits but handle
15602 C++ anonymous unions and structs. */
15603 if (DECL_NAME (member) != NULL_TREE
15604 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
15605 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
15607 gen_type_die (member_declared_type (member), type_die);
15608 gen_field_die (member, type_die);
15612 gen_variable_die (member, NULL_TREE, type_die);
15618 /* Generate the DWARF2 info for the "abstract" instance of a function which we
15619 may later generate inlined and/or out-of-line instances of. */
15622 dwarf2out_abstract_function (tree decl)
15624 dw_die_ref old_die;
15627 int was_abstract = DECL_ABSTRACT (decl);
15628 htab_t old_decl_loc_table;
15630 /* Make sure we have the actual abstract inline, not a clone. */
15631 decl = DECL_ORIGIN (decl);
15633 old_die = lookup_decl_die (decl);
15634 if (old_die && get_AT (old_die, DW_AT_inline))
15635 /* We've already generated the abstract instance. */
15638 /* We can be called while recursively when seeing block defining inlined subroutine
15639 DIE. Be sure to not clobber the outer location table nor use it or we would
15640 get locations in abstract instantces. */
15641 old_decl_loc_table = decl_loc_table;
15642 decl_loc_table = NULL;
15644 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
15645 we don't get confused by DECL_ABSTRACT. */
15646 if (debug_info_level > DINFO_LEVEL_TERSE)
15648 context = decl_class_context (decl);
15650 gen_type_die_for_member
15651 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
15654 /* Pretend we've just finished compiling this function. */
15655 save_fn = current_function_decl;
15656 current_function_decl = decl;
15657 push_cfun (DECL_STRUCT_FUNCTION (decl));
15659 set_decl_abstract_flags (decl, 1);
15660 dwarf2out_decl (decl);
15661 if (! was_abstract)
15662 set_decl_abstract_flags (decl, 0);
15664 current_function_decl = save_fn;
15665 decl_loc_table = old_decl_loc_table;
15669 /* Helper function of premark_used_types() which gets called through
15672 Marks the DIE of a given type in *SLOT as perennial, so it never gets
15673 marked as unused by prune_unused_types. */
15676 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
15681 type = (tree) *slot;
15682 die = lookup_type_die (type);
15684 die->die_perennial_p = 1;
15688 /* Helper function of premark_types_used_by_global_vars which gets called
15689 through htab_traverse.
15691 Marks the DIE of a given type in *SLOT as perennial, so it never gets
15692 marked as unused by prune_unused_types. The DIE of the type is marked
15693 only if the global variable using the type will actually be emitted. */
15696 premark_types_used_by_global_vars_helper (void **slot,
15697 void *data ATTRIBUTE_UNUSED)
15699 struct types_used_by_vars_entry *entry;
15702 entry = (struct types_used_by_vars_entry *) *slot;
15703 gcc_assert (entry->type != NULL
15704 && entry->var_decl != NULL);
15705 die = lookup_type_die (entry->type);
15708 /* Ask cgraph if the global variable really is to be emitted.
15709 If yes, then we'll keep the DIE of ENTRY->TYPE. */
15710 struct varpool_node *node = varpool_node (entry->var_decl);
15713 die->die_perennial_p = 1;
15714 /* Keep the parent DIEs as well. */
15715 while ((die = die->die_parent) && die->die_perennial_p == 0)
15716 die->die_perennial_p = 1;
15722 /* Mark all members of used_types_hash as perennial. */
15725 premark_used_types (void)
15727 if (cfun && cfun->used_types_hash)
15728 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
15731 /* Mark all members of types_used_by_vars_entry as perennial. */
15734 premark_types_used_by_global_vars (void)
15736 if (types_used_by_vars_hash)
15737 htab_traverse (types_used_by_vars_hash,
15738 premark_types_used_by_global_vars_helper, NULL);
15741 /* Generate a DIE to represent a declared function (either file-scope or
15745 gen_subprogram_die (tree decl, dw_die_ref context_die)
15747 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15748 tree origin = decl_ultimate_origin (decl);
15749 dw_die_ref subr_die;
15752 dw_die_ref old_die = lookup_decl_die (decl);
15753 int declaration = (current_function_decl != decl
15754 || class_or_namespace_scope_p (context_die));
15756 premark_used_types ();
15758 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
15759 started to generate the abstract instance of an inline, decided to output
15760 its containing class, and proceeded to emit the declaration of the inline
15761 from the member list for the class. If so, DECLARATION takes priority;
15762 we'll get back to the abstract instance when done with the class. */
15764 /* The class-scope declaration DIE must be the primary DIE. */
15765 if (origin && declaration && class_or_namespace_scope_p (context_die))
15768 gcc_assert (!old_die);
15771 /* Now that the C++ front end lazily declares artificial member fns, we
15772 might need to retrofit the declaration into its class. */
15773 if (!declaration && !origin && !old_die
15774 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
15775 && !class_or_namespace_scope_p (context_die)
15776 && debug_info_level > DINFO_LEVEL_TERSE)
15777 old_die = force_decl_die (decl);
15779 if (origin != NULL)
15781 gcc_assert (!declaration || local_scope_p (context_die));
15783 /* Fixup die_parent for the abstract instance of a nested
15784 inline function. */
15785 if (old_die && old_die->die_parent == NULL)
15786 add_child_die (context_die, old_die);
15788 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15789 add_abstract_origin_attribute (subr_die, origin);
15793 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
15794 struct dwarf_file_data * file_index = lookup_filename (s.file);
15796 if (!get_AT_flag (old_die, DW_AT_declaration)
15797 /* We can have a normal definition following an inline one in the
15798 case of redefinition of GNU C extern inlines.
15799 It seems reasonable to use AT_specification in this case. */
15800 && !get_AT (old_die, DW_AT_inline))
15802 /* Detect and ignore this case, where we are trying to output
15803 something we have already output. */
15807 /* If the definition comes from the same place as the declaration,
15808 maybe use the old DIE. We always want the DIE for this function
15809 that has the *_pc attributes to be under comp_unit_die so the
15810 debugger can find it. We also need to do this for abstract
15811 instances of inlines, since the spec requires the out-of-line copy
15812 to have the same parent. For local class methods, this doesn't
15813 apply; we just use the old DIE. */
15814 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
15815 && (DECL_ARTIFICIAL (decl)
15816 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
15817 && (get_AT_unsigned (old_die, DW_AT_decl_line)
15818 == (unsigned) s.line))))
15820 subr_die = old_die;
15822 /* Clear out the declaration attribute and the formal parameters.
15823 Do not remove all children, because it is possible that this
15824 declaration die was forced using force_decl_die(). In such
15825 cases die that forced declaration die (e.g. TAG_imported_module)
15826 is one of the children that we do not want to remove. */
15827 remove_AT (subr_die, DW_AT_declaration);
15828 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
15832 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15833 add_AT_specification (subr_die, old_die);
15834 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
15835 add_AT_file (subr_die, DW_AT_decl_file, file_index);
15836 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
15837 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
15842 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15844 if (TREE_PUBLIC (decl))
15845 add_AT_flag (subr_die, DW_AT_external, 1);
15847 add_name_and_src_coords_attributes (subr_die, decl);
15848 if (debug_info_level > DINFO_LEVEL_TERSE)
15850 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
15851 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
15852 0, 0, context_die);
15855 add_pure_or_virtual_attribute (subr_die, decl);
15856 if (DECL_ARTIFICIAL (decl))
15857 add_AT_flag (subr_die, DW_AT_artificial, 1);
15859 if (TREE_PROTECTED (decl))
15860 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
15861 else if (TREE_PRIVATE (decl))
15862 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
15867 if (!old_die || !get_AT (old_die, DW_AT_inline))
15869 add_AT_flag (subr_die, DW_AT_declaration, 1);
15871 /* If this is an explicit function declaration then generate
15872 a DW_AT_explicit attribute. */
15873 if (lang_hooks.decls.function_decl_explicit_p (decl)
15874 && (dwarf_version >= 3 || !dwarf_strict))
15875 add_AT_flag (subr_die, DW_AT_explicit, 1);
15877 /* The first time we see a member function, it is in the context of
15878 the class to which it belongs. We make sure of this by emitting
15879 the class first. The next time is the definition, which is
15880 handled above. The two may come from the same source text.
15882 Note that force_decl_die() forces function declaration die. It is
15883 later reused to represent definition. */
15884 equate_decl_number_to_die (decl, subr_die);
15887 else if (DECL_ABSTRACT (decl))
15889 if (DECL_DECLARED_INLINE_P (decl))
15891 if (cgraph_function_possibly_inlined_p (decl))
15892 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
15894 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
15898 if (cgraph_function_possibly_inlined_p (decl))
15899 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
15901 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
15904 if (DECL_DECLARED_INLINE_P (decl)
15905 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
15906 add_AT_flag (subr_die, DW_AT_artificial, 1);
15908 equate_decl_number_to_die (decl, subr_die);
15910 else if (!DECL_EXTERNAL (decl))
15912 HOST_WIDE_INT cfa_fb_offset;
15914 if (!old_die || !get_AT (old_die, DW_AT_inline))
15915 equate_decl_number_to_die (decl, subr_die);
15917 if (!flag_reorder_blocks_and_partition)
15919 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
15920 current_function_funcdef_no);
15921 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
15922 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15923 current_function_funcdef_no);
15924 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
15926 add_pubname (decl, subr_die);
15927 add_arange (decl, subr_die);
15930 { /* Do nothing for now; maybe need to duplicate die, one for
15931 hot section and one for cold section, then use the hot/cold
15932 section begin/end labels to generate the aranges... */
15934 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
15935 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
15936 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
15937 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
15939 add_pubname (decl, subr_die);
15940 add_arange (decl, subr_die);
15941 add_arange (decl, subr_die);
15945 #ifdef MIPS_DEBUGGING_INFO
15946 /* Add a reference to the FDE for this routine. */
15947 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
15950 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
15952 /* We define the "frame base" as the function's CFA. This is more
15953 convenient for several reasons: (1) It's stable across the prologue
15954 and epilogue, which makes it better than just a frame pointer,
15955 (2) With dwarf3, there exists a one-byte encoding that allows us
15956 to reference the .debug_frame data by proxy, but failing that,
15957 (3) We can at least reuse the code inspection and interpretation
15958 code that determines the CFA position at various points in the
15960 if (dwarf_version >= 3)
15962 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
15963 add_AT_loc (subr_die, DW_AT_frame_base, op);
15967 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
15968 if (list->dw_loc_next)
15969 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
15971 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
15974 /* Compute a displacement from the "steady-state frame pointer" to
15975 the CFA. The former is what all stack slots and argument slots
15976 will reference in the rtl; the later is what we've told the
15977 debugger about. We'll need to adjust all frame_base references
15978 by this displacement. */
15979 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
15981 if (cfun->static_chain_decl)
15982 add_AT_location_description (subr_die, DW_AT_static_link,
15983 loc_list_from_tree (cfun->static_chain_decl, 2));
15986 /* Generate child dies for template paramaters. */
15987 if (debug_info_level > DINFO_LEVEL_TERSE)
15988 gen_generic_params_dies (decl);
15990 /* Now output descriptions of the arguments for this function. This gets
15991 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
15992 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
15993 `...' at the end of the formal parameter list. In order to find out if
15994 there was a trailing ellipsis or not, we must instead look at the type
15995 associated with the FUNCTION_DECL. This will be a node of type
15996 FUNCTION_TYPE. If the chain of type nodes hanging off of this
15997 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
15998 an ellipsis at the end. */
16000 /* In the case where we are describing a mere function declaration, all we
16001 need to do here (and all we *can* do here) is to describe the *types* of
16002 its formal parameters. */
16003 if (debug_info_level <= DINFO_LEVEL_TERSE)
16005 else if (declaration)
16006 gen_formal_types_die (decl, subr_die);
16009 /* Generate DIEs to represent all known formal parameters. */
16010 tree parm = DECL_ARGUMENTS (decl);
16011 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
16012 tree generic_decl_parm = generic_decl
16013 ? DECL_ARGUMENTS (generic_decl)
16016 /* Now we want to walk the list of parameters of the function and
16017 emit their relevant DIEs.
16019 We consider the case of DECL being an instance of a generic function
16020 as well as it being a normal function.
16022 If DECL is an instance of a generic function we walk the
16023 parameters of the generic function declaration _and_ the parameters of
16024 DECL itself. This is useful because we want to emit specific DIEs for
16025 function parameter packs and those are declared as part of the
16026 generic function declaration. In that particular case,
16027 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
16028 That DIE has children DIEs representing the set of arguments
16029 of the pack. Note that the set of pack arguments can be empty.
16030 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
16033 Otherwise, we just consider the parameters of DECL. */
16034 while (generic_decl_parm || parm)
16036 if (generic_decl_parm
16037 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
16038 gen_formal_parameter_pack_die (generic_decl_parm,
16043 gen_decl_die (parm, NULL, subr_die);
16044 parm = TREE_CHAIN (parm);
16047 if (generic_decl_parm)
16048 generic_decl_parm = TREE_CHAIN (generic_decl_parm);
16051 /* Decide whether we need an unspecified_parameters DIE at the end.
16052 There are 2 more cases to do this for: 1) the ansi ... declaration -
16053 this is detectable when the end of the arg list is not a
16054 void_type_node 2) an unprototyped function declaration (not a
16055 definition). This just means that we have no info about the
16056 parameters at all. */
16057 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
16058 if (fn_arg_types != NULL)
16060 /* This is the prototyped case, check for.... */
16061 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
16062 gen_unspecified_parameters_die (decl, subr_die);
16064 else if (DECL_INITIAL (decl) == NULL_TREE)
16065 gen_unspecified_parameters_die (decl, subr_die);
16068 /* Output Dwarf info for all of the stuff within the body of the function
16069 (if it has one - it may be just a declaration). */
16070 outer_scope = DECL_INITIAL (decl);
16072 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
16073 a function. This BLOCK actually represents the outermost binding contour
16074 for the function, i.e. the contour in which the function's formal
16075 parameters and labels get declared. Curiously, it appears that the front
16076 end doesn't actually put the PARM_DECL nodes for the current function onto
16077 the BLOCK_VARS list for this outer scope, but are strung off of the
16078 DECL_ARGUMENTS list for the function instead.
16080 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
16081 the LABEL_DECL nodes for the function however, and we output DWARF info
16082 for those in decls_for_scope. Just within the `outer_scope' there will be
16083 a BLOCK node representing the function's outermost pair of curly braces,
16084 and any blocks used for the base and member initializers of a C++
16085 constructor function. */
16086 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
16088 /* Emit a DW_TAG_variable DIE for a named return value. */
16089 if (DECL_NAME (DECL_RESULT (decl)))
16090 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
16092 current_function_has_inlines = 0;
16093 decls_for_scope (outer_scope, subr_die, 0);
16095 #if 0 && defined (MIPS_DEBUGGING_INFO)
16096 if (current_function_has_inlines)
16098 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
16099 if (! comp_unit_has_inlines)
16101 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
16102 comp_unit_has_inlines = 1;
16107 /* Add the calling convention attribute if requested. */
16108 add_calling_convention_attribute (subr_die, decl);
16112 /* Returns a hash value for X (which really is a die_struct). */
16115 common_block_die_table_hash (const void *x)
16117 const_dw_die_ref d = (const_dw_die_ref) x;
16118 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
16121 /* Return nonzero if decl_id and die_parent of die_struct X is the same
16122 as decl_id and die_parent of die_struct Y. */
16125 common_block_die_table_eq (const void *x, const void *y)
16127 const_dw_die_ref d = (const_dw_die_ref) x;
16128 const_dw_die_ref e = (const_dw_die_ref) y;
16129 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
16132 /* Generate a DIE to represent a declared data object.
16133 Either DECL or ORIGIN must be non-null. */
16136 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
16140 tree decl_or_origin = decl ? decl : origin;
16141 dw_die_ref var_die;
16142 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
16143 dw_die_ref origin_die;
16144 int declaration = (DECL_EXTERNAL (decl_or_origin)
16145 /* If DECL is COMDAT and has not actually been
16146 emitted, we cannot take its address; there
16147 might end up being no definition anywhere in
16148 the program. For example, consider the C++
16152 struct S { static const int i = 7; };
16157 int f() { return S<int>::i; }
16159 Here, S<int>::i is not DECL_EXTERNAL, but no
16160 definition is required, so the compiler will
16161 not emit a definition. */
16162 || (TREE_CODE (decl_or_origin) == VAR_DECL
16163 && DECL_COMDAT (decl_or_origin)
16164 && !TREE_ASM_WRITTEN (decl_or_origin))
16165 || class_or_namespace_scope_p (context_die));
16168 origin = decl_ultimate_origin (decl);
16170 com_decl = fortran_common (decl_or_origin, &off);
16172 /* Symbol in common gets emitted as a child of the common block, in the form
16173 of a data member. */
16177 dw_die_ref com_die;
16178 dw_loc_list_ref loc;
16179 die_node com_die_arg;
16181 var_die = lookup_decl_die (decl_or_origin);
16184 if (get_AT (var_die, DW_AT_location) == NULL)
16186 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
16191 /* Optimize the common case. */
16192 if (single_element_loc_list_p (loc)
16193 && loc->expr->dw_loc_opc == DW_OP_addr
16194 && loc->expr->dw_loc_next == NULL
16195 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
16197 loc->expr->dw_loc_oprnd1.v.val_addr
16198 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
16200 loc_list_plus_const (loc, off);
16202 add_AT_location_description (var_die, DW_AT_location, loc);
16203 remove_AT (var_die, DW_AT_declaration);
16209 if (common_block_die_table == NULL)
16210 common_block_die_table
16211 = htab_create_ggc (10, common_block_die_table_hash,
16212 common_block_die_table_eq, NULL);
16214 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
16215 com_die_arg.decl_id = DECL_UID (com_decl);
16216 com_die_arg.die_parent = context_die;
16217 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
16218 loc = loc_list_from_tree (com_decl, 2);
16219 if (com_die == NULL)
16222 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
16225 com_die = new_die (DW_TAG_common_block, context_die, decl);
16226 add_name_and_src_coords_attributes (com_die, com_decl);
16229 add_AT_location_description (com_die, DW_AT_location, loc);
16230 /* Avoid sharing the same loc descriptor between
16231 DW_TAG_common_block and DW_TAG_variable. */
16232 loc = loc_list_from_tree (com_decl, 2);
16234 else if (DECL_EXTERNAL (decl))
16235 add_AT_flag (com_die, DW_AT_declaration, 1);
16236 add_pubname_string (cnam, com_die); /* ??? needed? */
16237 com_die->decl_id = DECL_UID (com_decl);
16238 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
16239 *slot = (void *) com_die;
16241 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
16243 add_AT_location_description (com_die, DW_AT_location, loc);
16244 loc = loc_list_from_tree (com_decl, 2);
16245 remove_AT (com_die, DW_AT_declaration);
16247 var_die = new_die (DW_TAG_variable, com_die, decl);
16248 add_name_and_src_coords_attributes (var_die, decl);
16249 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
16250 TREE_THIS_VOLATILE (decl), context_die);
16251 add_AT_flag (var_die, DW_AT_external, 1);
16256 /* Optimize the common case. */
16257 if (single_element_loc_list_p (loc)
16258 && loc->expr->dw_loc_opc == DW_OP_addr
16259 && loc->expr->dw_loc_next == NULL
16260 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
16261 loc->expr->dw_loc_oprnd1.v.val_addr
16262 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
16264 loc_list_plus_const (loc, off);
16266 add_AT_location_description (var_die, DW_AT_location, loc);
16268 else if (DECL_EXTERNAL (decl))
16269 add_AT_flag (var_die, DW_AT_declaration, 1);
16270 equate_decl_number_to_die (decl, var_die);
16274 /* If the compiler emitted a definition for the DECL declaration
16275 and if we already emitted a DIE for it, don't emit a second
16276 DIE for it again. */
16279 && old_die->die_parent == context_die)
16282 /* For static data members, the declaration in the class is supposed
16283 to have DW_TAG_member tag; the specification should still be
16284 DW_TAG_variable referencing the DW_TAG_member DIE. */
16285 if (declaration && class_scope_p (context_die))
16286 var_die = new_die (DW_TAG_member, context_die, decl);
16288 var_die = new_die (DW_TAG_variable, context_die, decl);
16291 if (origin != NULL)
16292 origin_die = add_abstract_origin_attribute (var_die, origin);
16294 /* Loop unrolling can create multiple blocks that refer to the same
16295 static variable, so we must test for the DW_AT_declaration flag.
16297 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
16298 copy decls and set the DECL_ABSTRACT flag on them instead of
16301 ??? Duplicated blocks have been rewritten to use .debug_ranges.
16303 ??? The declare_in_namespace support causes us to get two DIEs for one
16304 variable, both of which are declarations. We want to avoid considering
16305 one to be a specification, so we must test that this DIE is not a
16307 else if (old_die && TREE_STATIC (decl) && ! declaration
16308 && get_AT_flag (old_die, DW_AT_declaration) == 1)
16310 /* This is a definition of a C++ class level static. */
16311 add_AT_specification (var_die, old_die);
16312 if (DECL_NAME (decl))
16314 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
16315 struct dwarf_file_data * file_index = lookup_filename (s.file);
16317 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
16318 add_AT_file (var_die, DW_AT_decl_file, file_index);
16320 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
16321 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
16326 tree type = TREE_TYPE (decl);
16328 add_name_and_src_coords_attributes (var_die, decl);
16329 if (decl_by_reference_p (decl))
16330 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
16332 add_type_attribute (var_die, type, TREE_READONLY (decl),
16333 TREE_THIS_VOLATILE (decl), context_die);
16335 if (TREE_PUBLIC (decl))
16336 add_AT_flag (var_die, DW_AT_external, 1);
16338 if (DECL_ARTIFICIAL (decl))
16339 add_AT_flag (var_die, DW_AT_artificial, 1);
16341 if (TREE_PROTECTED (decl))
16342 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
16343 else if (TREE_PRIVATE (decl))
16344 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
16348 add_AT_flag (var_die, DW_AT_declaration, 1);
16350 if (decl && (DECL_ABSTRACT (decl) || declaration))
16351 equate_decl_number_to_die (decl, var_die);
16354 && (! DECL_ABSTRACT (decl_or_origin)
16355 /* Local static vars are shared between all clones/inlines,
16356 so emit DW_AT_location on the abstract DIE if DECL_RTL is
16358 || (TREE_CODE (decl_or_origin) == VAR_DECL
16359 && TREE_STATIC (decl_or_origin)
16360 && DECL_RTL_SET_P (decl_or_origin)))
16361 /* When abstract origin already has DW_AT_location attribute, no need
16362 to add it again. */
16363 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
16365 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
16366 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
16367 defer_location (decl_or_origin, var_die);
16369 add_location_or_const_value_attribute (var_die,
16372 add_pubname (decl_or_origin, var_die);
16375 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
16378 /* Generate a DIE to represent a named constant. */
16381 gen_const_die (tree decl, dw_die_ref context_die)
16383 dw_die_ref const_die;
16384 tree type = TREE_TYPE (decl);
16386 const_die = new_die (DW_TAG_constant, context_die, decl);
16387 add_name_and_src_coords_attributes (const_die, decl);
16388 add_type_attribute (const_die, type, 1, 0, context_die);
16389 if (TREE_PUBLIC (decl))
16390 add_AT_flag (const_die, DW_AT_external, 1);
16391 if (DECL_ARTIFICIAL (decl))
16392 add_AT_flag (const_die, DW_AT_artificial, 1);
16393 tree_add_const_value_attribute_for_decl (const_die, decl);
16396 /* Generate a DIE to represent a label identifier. */
16399 gen_label_die (tree decl, dw_die_ref context_die)
16401 tree origin = decl_ultimate_origin (decl);
16402 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
16404 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16406 if (origin != NULL)
16407 add_abstract_origin_attribute (lbl_die, origin);
16409 add_name_and_src_coords_attributes (lbl_die, decl);
16411 if (DECL_ABSTRACT (decl))
16412 equate_decl_number_to_die (decl, lbl_die);
16415 insn = DECL_RTL_IF_SET (decl);
16417 /* Deleted labels are programmer specified labels which have been
16418 eliminated because of various optimizations. We still emit them
16419 here so that it is possible to put breakpoints on them. */
16423 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
16425 /* When optimization is enabled (via -O) some parts of the compiler
16426 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
16427 represent source-level labels which were explicitly declared by
16428 the user. This really shouldn't be happening though, so catch
16429 it if it ever does happen. */
16430 gcc_assert (!INSN_DELETED_P (insn));
16432 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
16433 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
16438 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
16439 attributes to the DIE for a block STMT, to describe where the inlined
16440 function was called from. This is similar to add_src_coords_attributes. */
16443 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
16445 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
16447 if (dwarf_version >= 3 || !dwarf_strict)
16449 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
16450 add_AT_unsigned (die, DW_AT_call_line, s.line);
16455 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
16456 Add low_pc and high_pc attributes to the DIE for a block STMT. */
16459 add_high_low_attributes (tree stmt, dw_die_ref die)
16461 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16463 if (BLOCK_FRAGMENT_CHAIN (stmt)
16464 && (dwarf_version >= 3 || !dwarf_strict))
16468 if (inlined_function_outer_scope_p (stmt))
16470 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
16471 BLOCK_NUMBER (stmt));
16472 add_AT_lbl_id (die, DW_AT_entry_pc, label);
16475 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
16477 chain = BLOCK_FRAGMENT_CHAIN (stmt);
16480 add_ranges (chain);
16481 chain = BLOCK_FRAGMENT_CHAIN (chain);
16488 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
16489 BLOCK_NUMBER (stmt));
16490 add_AT_lbl_id (die, DW_AT_low_pc, label);
16491 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
16492 BLOCK_NUMBER (stmt));
16493 add_AT_lbl_id (die, DW_AT_high_pc, label);
16497 /* Generate a DIE for a lexical block. */
16500 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
16502 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
16504 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
16505 add_high_low_attributes (stmt, stmt_die);
16507 decls_for_scope (stmt, stmt_die, depth);
16510 /* Generate a DIE for an inlined subprogram. */
16513 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
16517 /* The instance of function that is effectively being inlined shall not
16519 gcc_assert (! BLOCK_ABSTRACT (stmt));
16521 decl = block_ultimate_origin (stmt);
16523 /* Emit info for the abstract instance first, if we haven't yet. We
16524 must emit this even if the block is abstract, otherwise when we
16525 emit the block below (or elsewhere), we may end up trying to emit
16526 a die whose origin die hasn't been emitted, and crashing. */
16527 dwarf2out_abstract_function (decl);
16529 if (! BLOCK_ABSTRACT (stmt))
16531 dw_die_ref subr_die
16532 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
16534 add_abstract_origin_attribute (subr_die, decl);
16535 if (TREE_ASM_WRITTEN (stmt))
16536 add_high_low_attributes (stmt, subr_die);
16537 add_call_src_coords_attributes (stmt, subr_die);
16539 decls_for_scope (stmt, subr_die, depth);
16540 current_function_has_inlines = 1;
16544 /* Generate a DIE for a field in a record, or structure. */
16547 gen_field_die (tree decl, dw_die_ref context_die)
16549 dw_die_ref decl_die;
16551 if (TREE_TYPE (decl) == error_mark_node)
16554 decl_die = new_die (DW_TAG_member, context_die, decl);
16555 add_name_and_src_coords_attributes (decl_die, decl);
16556 add_type_attribute (decl_die, member_declared_type (decl),
16557 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
16560 if (DECL_BIT_FIELD_TYPE (decl))
16562 add_byte_size_attribute (decl_die, decl);
16563 add_bit_size_attribute (decl_die, decl);
16564 add_bit_offset_attribute (decl_die, decl);
16567 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
16568 add_data_member_location_attribute (decl_die, decl);
16570 if (DECL_ARTIFICIAL (decl))
16571 add_AT_flag (decl_die, DW_AT_artificial, 1);
16573 if (TREE_PROTECTED (decl))
16574 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
16575 else if (TREE_PRIVATE (decl))
16576 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
16578 /* Equate decl number to die, so that we can look up this decl later on. */
16579 equate_decl_number_to_die (decl, decl_die);
16583 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16584 Use modified_type_die instead.
16585 We keep this code here just in case these types of DIEs may be needed to
16586 represent certain things in other languages (e.g. Pascal) someday. */
16589 gen_pointer_type_die (tree type, dw_die_ref context_die)
16592 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
16594 equate_type_number_to_die (type, ptr_die);
16595 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16596 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16599 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16600 Use modified_type_die instead.
16601 We keep this code here just in case these types of DIEs may be needed to
16602 represent certain things in other languages (e.g. Pascal) someday. */
16605 gen_reference_type_die (tree type, dw_die_ref context_die)
16608 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
16610 equate_type_number_to_die (type, ref_die);
16611 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
16612 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16616 /* Generate a DIE for a pointer to a member type. */
16619 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
16622 = new_die (DW_TAG_ptr_to_member_type,
16623 scope_die_for (type, context_die), type);
16625 equate_type_number_to_die (type, ptr_die);
16626 add_AT_die_ref (ptr_die, DW_AT_containing_type,
16627 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
16628 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16631 /* Generate the DIE for the compilation unit. */
16634 gen_compile_unit_die (const char *filename)
16637 char producer[250];
16638 const char *language_string = lang_hooks.name;
16641 die = new_die (DW_TAG_compile_unit, NULL, NULL);
16645 add_name_attribute (die, filename);
16646 /* Don't add cwd for <built-in>. */
16647 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
16648 add_comp_dir_attribute (die);
16651 sprintf (producer, "%s %s", language_string, version_string);
16653 #ifdef MIPS_DEBUGGING_INFO
16654 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
16655 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
16656 not appear in the producer string, the debugger reaches the conclusion
16657 that the object file is stripped and has no debugging information.
16658 To get the MIPS/SGI debugger to believe that there is debugging
16659 information in the object file, we add a -g to the producer string. */
16660 if (debug_info_level > DINFO_LEVEL_TERSE)
16661 strcat (producer, " -g");
16664 add_AT_string (die, DW_AT_producer, producer);
16666 language = DW_LANG_C89;
16667 if (strcmp (language_string, "GNU C++") == 0)
16668 language = DW_LANG_C_plus_plus;
16669 else if (strcmp (language_string, "GNU F77") == 0)
16670 language = DW_LANG_Fortran77;
16671 else if (strcmp (language_string, "GNU Pascal") == 0)
16672 language = DW_LANG_Pascal83;
16673 else if (dwarf_version >= 3 || !dwarf_strict)
16675 if (strcmp (language_string, "GNU Ada") == 0)
16676 language = DW_LANG_Ada95;
16677 else if (strcmp (language_string, "GNU Fortran") == 0)
16678 language = DW_LANG_Fortran95;
16679 else if (strcmp (language_string, "GNU Java") == 0)
16680 language = DW_LANG_Java;
16681 else if (strcmp (language_string, "GNU Objective-C") == 0)
16682 language = DW_LANG_ObjC;
16683 else if (strcmp (language_string, "GNU Objective-C++") == 0)
16684 language = DW_LANG_ObjC_plus_plus;
16687 add_AT_unsigned (die, DW_AT_language, language);
16691 /* Generate the DIE for a base class. */
16694 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
16696 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
16698 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
16699 add_data_member_location_attribute (die, binfo);
16701 if (BINFO_VIRTUAL_P (binfo))
16702 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
16704 if (access == access_public_node)
16705 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16706 else if (access == access_protected_node)
16707 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16710 /* Generate a DIE for a class member. */
16713 gen_member_die (tree type, dw_die_ref context_die)
16716 tree binfo = TYPE_BINFO (type);
16719 /* If this is not an incomplete type, output descriptions of each of its
16720 members. Note that as we output the DIEs necessary to represent the
16721 members of this record or union type, we will also be trying to output
16722 DIEs to represent the *types* of those members. However the `type'
16723 function (above) will specifically avoid generating type DIEs for member
16724 types *within* the list of member DIEs for this (containing) type except
16725 for those types (of members) which are explicitly marked as also being
16726 members of this (containing) type themselves. The g++ front- end can
16727 force any given type to be treated as a member of some other (containing)
16728 type by setting the TYPE_CONTEXT of the given (member) type to point to
16729 the TREE node representing the appropriate (containing) type. */
16731 /* First output info about the base classes. */
16734 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
16738 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
16739 gen_inheritance_die (base,
16740 (accesses ? VEC_index (tree, accesses, i)
16741 : access_public_node), context_die);
16744 /* Now output info about the data members and type members. */
16745 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
16747 /* If we thought we were generating minimal debug info for TYPE
16748 and then changed our minds, some of the member declarations
16749 may have already been defined. Don't define them again, but
16750 do put them in the right order. */
16752 child = lookup_decl_die (member);
16754 splice_child_die (context_die, child);
16756 gen_decl_die (member, NULL, context_die);
16759 /* Now output info about the function members (if any). */
16760 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
16762 /* Don't include clones in the member list. */
16763 if (DECL_ABSTRACT_ORIGIN (member))
16766 child = lookup_decl_die (member);
16768 splice_child_die (context_die, child);
16770 gen_decl_die (member, NULL, context_die);
16774 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
16775 is set, we pretend that the type was never defined, so we only get the
16776 member DIEs needed by later specification DIEs. */
16779 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
16780 enum debug_info_usage usage)
16782 dw_die_ref type_die = lookup_type_die (type);
16783 dw_die_ref scope_die = 0;
16785 int complete = (TYPE_SIZE (type)
16786 && (! TYPE_STUB_DECL (type)
16787 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
16788 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
16789 complete = complete && should_emit_struct_debug (type, usage);
16791 if (type_die && ! complete)
16794 if (TYPE_CONTEXT (type) != NULL_TREE
16795 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
16796 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
16799 scope_die = scope_die_for (type, context_die);
16801 if (! type_die || (nested && scope_die == comp_unit_die))
16802 /* First occurrence of type or toplevel definition of nested class. */
16804 dw_die_ref old_die = type_die;
16806 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
16807 ? record_type_tag (type) : DW_TAG_union_type,
16809 equate_type_number_to_die (type, type_die);
16811 add_AT_specification (type_die, old_die);
16813 add_name_attribute (type_die, type_tag (type));
16816 remove_AT (type_die, DW_AT_declaration);
16818 /* Generate child dies for template paramaters. */
16819 if (debug_info_level > DINFO_LEVEL_TERSE
16820 && COMPLETE_TYPE_P (type))
16821 gen_generic_params_dies (type);
16823 /* If this type has been completed, then give it a byte_size attribute and
16824 then give a list of members. */
16825 if (complete && !ns_decl)
16827 /* Prevent infinite recursion in cases where the type of some member of
16828 this type is expressed in terms of this type itself. */
16829 TREE_ASM_WRITTEN (type) = 1;
16830 add_byte_size_attribute (type_die, type);
16831 if (TYPE_STUB_DECL (type) != NULL_TREE)
16832 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16834 /* If the first reference to this type was as the return type of an
16835 inline function, then it may not have a parent. Fix this now. */
16836 if (type_die->die_parent == NULL)
16837 add_child_die (scope_die, type_die);
16839 push_decl_scope (type);
16840 gen_member_die (type, type_die);
16843 /* GNU extension: Record what type our vtable lives in. */
16844 if (TYPE_VFIELD (type))
16846 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
16848 gen_type_die (vtype, context_die);
16849 add_AT_die_ref (type_die, DW_AT_containing_type,
16850 lookup_type_die (vtype));
16855 add_AT_flag (type_die, DW_AT_declaration, 1);
16857 /* We don't need to do this for function-local types. */
16858 if (TYPE_STUB_DECL (type)
16859 && ! decl_function_context (TYPE_STUB_DECL (type)))
16860 VEC_safe_push (tree, gc, incomplete_types, type);
16863 if (get_AT (type_die, DW_AT_name))
16864 add_pubtype (type, type_die);
16867 /* Generate a DIE for a subroutine _type_. */
16870 gen_subroutine_type_die (tree type, dw_die_ref context_die)
16872 tree return_type = TREE_TYPE (type);
16873 dw_die_ref subr_die
16874 = new_die (DW_TAG_subroutine_type,
16875 scope_die_for (type, context_die), type);
16877 equate_type_number_to_die (type, subr_die);
16878 add_prototyped_attribute (subr_die, type);
16879 add_type_attribute (subr_die, return_type, 0, 0, context_die);
16880 gen_formal_types_die (type, subr_die);
16882 if (get_AT (subr_die, DW_AT_name))
16883 add_pubtype (type, subr_die);
16886 /* Generate a DIE for a type definition. */
16889 gen_typedef_die (tree decl, dw_die_ref context_die)
16891 dw_die_ref type_die;
16894 if (TREE_ASM_WRITTEN (decl))
16897 TREE_ASM_WRITTEN (decl) = 1;
16898 type_die = new_die (DW_TAG_typedef, context_die, decl);
16899 origin = decl_ultimate_origin (decl);
16900 if (origin != NULL)
16901 add_abstract_origin_attribute (type_die, origin);
16906 add_name_and_src_coords_attributes (type_die, decl);
16907 if (DECL_ORIGINAL_TYPE (decl))
16909 type = DECL_ORIGINAL_TYPE (decl);
16911 gcc_assert (type != TREE_TYPE (decl));
16912 equate_type_number_to_die (TREE_TYPE (decl), type_die);
16915 type = TREE_TYPE (decl);
16917 add_type_attribute (type_die, type, TREE_READONLY (decl),
16918 TREE_THIS_VOLATILE (decl), context_die);
16921 if (DECL_ABSTRACT (decl))
16922 equate_decl_number_to_die (decl, type_die);
16924 if (get_AT (type_die, DW_AT_name))
16925 add_pubtype (decl, type_die);
16928 /* Generate a type description DIE. */
16931 gen_type_die_with_usage (tree type, dw_die_ref context_die,
16932 enum debug_info_usage usage)
16935 struct array_descr_info info;
16937 if (type == NULL_TREE || type == error_mark_node)
16940 /* If TYPE is a typedef type variant, let's generate debug info
16941 for the parent typedef which TYPE is a type of. */
16942 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16943 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
16945 if (TREE_ASM_WRITTEN (type))
16948 /* Prevent broken recursion; we can't hand off to the same type. */
16949 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
16951 /* Use the DIE of the containing namespace as the parent DIE of
16952 the type description DIE we want to generate. */
16953 if (DECL_CONTEXT (TYPE_NAME (type))
16954 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
16955 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
16957 TREE_ASM_WRITTEN (type) = 1;
16958 gen_decl_die (TYPE_NAME (type), NULL, context_die);
16962 /* If this is an array type with hidden descriptor, handle it first. */
16963 if (!TREE_ASM_WRITTEN (type)
16964 && lang_hooks.types.get_array_descr_info
16965 && lang_hooks.types.get_array_descr_info (type, &info)
16966 && (dwarf_version >= 3 || !dwarf_strict))
16968 gen_descr_array_type_die (type, &info, context_die);
16969 TREE_ASM_WRITTEN (type) = 1;
16973 /* We are going to output a DIE to represent the unqualified version
16974 of this type (i.e. without any const or volatile qualifiers) so
16975 get the main variant (i.e. the unqualified version) of this type
16976 now. (Vectors are special because the debugging info is in the
16977 cloned type itself). */
16978 if (TREE_CODE (type) != VECTOR_TYPE)
16979 type = type_main_variant (type);
16981 if (TREE_ASM_WRITTEN (type))
16984 switch (TREE_CODE (type))
16990 case REFERENCE_TYPE:
16991 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
16992 ensures that the gen_type_die recursion will terminate even if the
16993 type is recursive. Recursive types are possible in Ada. */
16994 /* ??? We could perhaps do this for all types before the switch
16996 TREE_ASM_WRITTEN (type) = 1;
16998 /* For these types, all that is required is that we output a DIE (or a
16999 set of DIEs) to represent the "basis" type. */
17000 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17001 DINFO_USAGE_IND_USE);
17005 /* This code is used for C++ pointer-to-data-member types.
17006 Output a description of the relevant class type. */
17007 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
17008 DINFO_USAGE_IND_USE);
17010 /* Output a description of the type of the object pointed to. */
17011 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17012 DINFO_USAGE_IND_USE);
17014 /* Now output a DIE to represent this pointer-to-data-member type
17016 gen_ptr_to_mbr_type_die (type, context_die);
17019 case FUNCTION_TYPE:
17020 /* Force out return type (in case it wasn't forced out already). */
17021 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17022 DINFO_USAGE_DIR_USE);
17023 gen_subroutine_type_die (type, context_die);
17027 /* Force out return type (in case it wasn't forced out already). */
17028 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17029 DINFO_USAGE_DIR_USE);
17030 gen_subroutine_type_die (type, context_die);
17034 gen_array_type_die (type, context_die);
17038 gen_array_type_die (type, context_die);
17041 case ENUMERAL_TYPE:
17044 case QUAL_UNION_TYPE:
17045 /* If this is a nested type whose containing class hasn't been written
17046 out yet, writing it out will cover this one, too. This does not apply
17047 to instantiations of member class templates; they need to be added to
17048 the containing class as they are generated. FIXME: This hurts the
17049 idea of combining type decls from multiple TUs, since we can't predict
17050 what set of template instantiations we'll get. */
17051 if (TYPE_CONTEXT (type)
17052 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
17053 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
17055 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
17057 if (TREE_ASM_WRITTEN (type))
17060 /* If that failed, attach ourselves to the stub. */
17061 push_decl_scope (TYPE_CONTEXT (type));
17062 context_die = lookup_type_die (TYPE_CONTEXT (type));
17065 else if (TYPE_CONTEXT (type) != NULL_TREE
17066 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
17068 /* If this type is local to a function that hasn't been written
17069 out yet, use a NULL context for now; it will be fixed up in
17070 decls_for_scope. */
17071 context_die = lookup_decl_die (TYPE_CONTEXT (type));
17076 context_die = declare_in_namespace (type, context_die);
17080 if (TREE_CODE (type) == ENUMERAL_TYPE)
17082 /* This might have been written out by the call to
17083 declare_in_namespace. */
17084 if (!TREE_ASM_WRITTEN (type))
17085 gen_enumeration_type_die (type, context_die);
17088 gen_struct_or_union_type_die (type, context_die, usage);
17093 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
17094 it up if it is ever completed. gen_*_type_die will set it for us
17095 when appropriate. */
17101 case FIXED_POINT_TYPE:
17104 /* No DIEs needed for fundamental types. */
17108 /* No Dwarf representation currently defined. */
17112 gcc_unreachable ();
17115 TREE_ASM_WRITTEN (type) = 1;
17119 gen_type_die (tree type, dw_die_ref context_die)
17121 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
17124 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
17125 things which are local to the given block. */
17128 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
17130 int must_output_die = 0;
17133 /* Ignore blocks that are NULL. */
17134 if (stmt == NULL_TREE)
17137 inlined_func = inlined_function_outer_scope_p (stmt);
17139 /* If the block is one fragment of a non-contiguous block, do not
17140 process the variables, since they will have been done by the
17141 origin block. Do process subblocks. */
17142 if (BLOCK_FRAGMENT_ORIGIN (stmt))
17146 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
17147 gen_block_die (sub, context_die, depth + 1);
17152 /* Determine if we need to output any Dwarf DIEs at all to represent this
17155 /* The outer scopes for inlinings *must* always be represented. We
17156 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
17157 must_output_die = 1;
17160 /* Determine if this block directly contains any "significant"
17161 local declarations which we will need to output DIEs for. */
17162 if (debug_info_level > DINFO_LEVEL_TERSE)
17163 /* We are not in terse mode so *any* local declaration counts
17164 as being a "significant" one. */
17165 must_output_die = ((BLOCK_VARS (stmt) != NULL
17166 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
17167 && (TREE_USED (stmt)
17168 || TREE_ASM_WRITTEN (stmt)
17169 || BLOCK_ABSTRACT (stmt)));
17170 else if ((TREE_USED (stmt)
17171 || TREE_ASM_WRITTEN (stmt)
17172 || BLOCK_ABSTRACT (stmt))
17173 && !dwarf2out_ignore_block (stmt))
17174 must_output_die = 1;
17177 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
17178 DIE for any block which contains no significant local declarations at
17179 all. Rather, in such cases we just call `decls_for_scope' so that any
17180 needed Dwarf info for any sub-blocks will get properly generated. Note
17181 that in terse mode, our definition of what constitutes a "significant"
17182 local declaration gets restricted to include only inlined function
17183 instances and local (nested) function definitions. */
17184 if (must_output_die)
17188 /* If STMT block is abstract, that means we have been called
17189 indirectly from dwarf2out_abstract_function.
17190 That function rightfully marks the descendent blocks (of
17191 the abstract function it is dealing with) as being abstract,
17192 precisely to prevent us from emitting any
17193 DW_TAG_inlined_subroutine DIE as a descendent
17194 of an abstract function instance. So in that case, we should
17195 not call gen_inlined_subroutine_die.
17197 Later though, when cgraph asks dwarf2out to emit info
17198 for the concrete instance of the function decl into which
17199 the concrete instance of STMT got inlined, the later will lead
17200 to the generation of a DW_TAG_inlined_subroutine DIE. */
17201 if (! BLOCK_ABSTRACT (stmt))
17202 gen_inlined_subroutine_die (stmt, context_die, depth);
17205 gen_lexical_block_die (stmt, context_die, depth);
17208 decls_for_scope (stmt, context_die, depth);
17211 /* Process variable DECL (or variable with origin ORIGIN) within
17212 block STMT and add it to CONTEXT_DIE. */
17214 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
17217 tree decl_or_origin = decl ? decl : origin;
17218 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
17220 if (ultimate_origin)
17221 origin = ultimate_origin;
17223 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
17224 die = lookup_decl_die (decl_or_origin);
17225 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
17226 && TYPE_DECL_IS_STUB (decl_or_origin))
17227 die = lookup_type_die (TREE_TYPE (decl_or_origin));
17231 if (die != NULL && die->die_parent == NULL)
17232 add_child_die (context_die, die);
17233 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
17234 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
17235 stmt, context_die);
17237 gen_decl_die (decl, origin, context_die);
17240 /* Generate all of the decls declared within a given scope and (recursively)
17241 all of its sub-blocks. */
17244 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
17250 /* Ignore NULL blocks. */
17251 if (stmt == NULL_TREE)
17254 /* Output the DIEs to represent all of the data objects and typedefs
17255 declared directly within this block but not within any nested
17256 sub-blocks. Also, nested function and tag DIEs have been
17257 generated with a parent of NULL; fix that up now. */
17258 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
17259 process_scope_var (stmt, decl, NULL_TREE, context_die);
17260 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
17261 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
17264 /* If we're at -g1, we're not interested in subblocks. */
17265 if (debug_info_level <= DINFO_LEVEL_TERSE)
17268 /* Output the DIEs to represent all sub-blocks (and the items declared
17269 therein) of this block. */
17270 for (subblocks = BLOCK_SUBBLOCKS (stmt);
17272 subblocks = BLOCK_CHAIN (subblocks))
17273 gen_block_die (subblocks, context_die, depth + 1);
17276 /* Is this a typedef we can avoid emitting? */
17279 is_redundant_typedef (const_tree decl)
17281 if (TYPE_DECL_IS_STUB (decl))
17284 if (DECL_ARTIFICIAL (decl)
17285 && DECL_CONTEXT (decl)
17286 && is_tagged_type (DECL_CONTEXT (decl))
17287 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
17288 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
17289 /* Also ignore the artificial member typedef for the class name. */
17295 /* Returns the DIE for a context. */
17297 static inline dw_die_ref
17298 get_context_die (tree context)
17302 /* Find die that represents this context. */
17303 if (TYPE_P (context))
17304 return force_type_die (context);
17306 return force_decl_die (context);
17308 return comp_unit_die;
17311 /* Returns the DIE for decl. A DIE will always be returned. */
17314 force_decl_die (tree decl)
17316 dw_die_ref decl_die;
17317 unsigned saved_external_flag;
17318 tree save_fn = NULL_TREE;
17319 decl_die = lookup_decl_die (decl);
17322 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
17324 decl_die = lookup_decl_die (decl);
17328 switch (TREE_CODE (decl))
17330 case FUNCTION_DECL:
17331 /* Clear current_function_decl, so that gen_subprogram_die thinks
17332 that this is a declaration. At this point, we just want to force
17333 declaration die. */
17334 save_fn = current_function_decl;
17335 current_function_decl = NULL_TREE;
17336 gen_subprogram_die (decl, context_die);
17337 current_function_decl = save_fn;
17341 /* Set external flag to force declaration die. Restore it after
17342 gen_decl_die() call. */
17343 saved_external_flag = DECL_EXTERNAL (decl);
17344 DECL_EXTERNAL (decl) = 1;
17345 gen_decl_die (decl, NULL, context_die);
17346 DECL_EXTERNAL (decl) = saved_external_flag;
17349 case NAMESPACE_DECL:
17350 if (dwarf_version >= 3 || !dwarf_strict)
17351 dwarf2out_decl (decl);
17353 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
17354 decl_die = comp_unit_die;
17358 gcc_unreachable ();
17361 /* We should be able to find the DIE now. */
17363 decl_die = lookup_decl_die (decl);
17364 gcc_assert (decl_die);
17370 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
17371 always returned. */
17374 force_type_die (tree type)
17376 dw_die_ref type_die;
17378 type_die = lookup_type_die (type);
17381 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
17383 type_die = modified_type_die (type, TYPE_READONLY (type),
17384 TYPE_VOLATILE (type), context_die);
17385 gcc_assert (type_die);
17390 /* Force out any required namespaces to be able to output DECL,
17391 and return the new context_die for it, if it's changed. */
17394 setup_namespace_context (tree thing, dw_die_ref context_die)
17396 tree context = (DECL_P (thing)
17397 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
17398 if (context && TREE_CODE (context) == NAMESPACE_DECL)
17399 /* Force out the namespace. */
17400 context_die = force_decl_die (context);
17402 return context_die;
17405 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
17406 type) within its namespace, if appropriate.
17408 For compatibility with older debuggers, namespace DIEs only contain
17409 declarations; all definitions are emitted at CU scope. */
17412 declare_in_namespace (tree thing, dw_die_ref context_die)
17414 dw_die_ref ns_context;
17416 if (debug_info_level <= DINFO_LEVEL_TERSE)
17417 return context_die;
17419 /* If this decl is from an inlined function, then don't try to emit it in its
17420 namespace, as we will get confused. It would have already been emitted
17421 when the abstract instance of the inline function was emitted anyways. */
17422 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
17423 return context_die;
17425 ns_context = setup_namespace_context (thing, context_die);
17427 if (ns_context != context_die)
17431 if (DECL_P (thing))
17432 gen_decl_die (thing, NULL, ns_context);
17434 gen_type_die (thing, ns_context);
17436 return context_die;
17439 /* Generate a DIE for a namespace or namespace alias. */
17442 gen_namespace_die (tree decl, dw_die_ref context_die)
17444 dw_die_ref namespace_die;
17446 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
17447 they are an alias of. */
17448 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
17450 /* Output a real namespace or module. */
17451 context_die = setup_namespace_context (decl, comp_unit_die);
17452 namespace_die = new_die (is_fortran ()
17453 ? DW_TAG_module : DW_TAG_namespace,
17454 context_die, decl);
17455 /* For Fortran modules defined in different CU don't add src coords. */
17456 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
17457 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
17459 add_name_and_src_coords_attributes (namespace_die, decl);
17460 if (DECL_EXTERNAL (decl))
17461 add_AT_flag (namespace_die, DW_AT_declaration, 1);
17462 equate_decl_number_to_die (decl, namespace_die);
17466 /* Output a namespace alias. */
17468 /* Force out the namespace we are an alias of, if necessary. */
17469 dw_die_ref origin_die
17470 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
17472 if (DECL_CONTEXT (decl) == NULL_TREE
17473 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
17474 context_die = setup_namespace_context (decl, comp_unit_die);
17475 /* Now create the namespace alias DIE. */
17476 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
17477 add_name_and_src_coords_attributes (namespace_die, decl);
17478 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
17479 equate_decl_number_to_die (decl, namespace_die);
17483 /* Generate Dwarf debug information for a decl described by DECL. */
17486 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
17488 tree decl_or_origin = decl ? decl : origin;
17489 tree class_origin = NULL;
17491 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
17494 switch (TREE_CODE (decl_or_origin))
17500 if (!is_fortran ())
17502 /* The individual enumerators of an enum type get output when we output
17503 the Dwarf representation of the relevant enum type itself. */
17507 /* Emit its type. */
17508 gen_type_die (TREE_TYPE (decl), context_die);
17510 /* And its containing namespace. */
17511 context_die = declare_in_namespace (decl, context_die);
17513 gen_const_die (decl, context_die);
17516 case FUNCTION_DECL:
17517 /* Don't output any DIEs to represent mere function declarations,
17518 unless they are class members or explicit block externs. */
17519 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
17520 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
17521 && (current_function_decl == NULL_TREE
17522 || DECL_ARTIFICIAL (decl_or_origin)))
17527 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
17528 on local redeclarations of global functions. That seems broken. */
17529 if (current_function_decl != decl)
17530 /* This is only a declaration. */;
17533 /* If we're emitting a clone, emit info for the abstract instance. */
17534 if (origin || DECL_ORIGIN (decl) != decl)
17535 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
17537 /* If we're emitting an out-of-line copy of an inline function,
17538 emit info for the abstract instance and set up to refer to it. */
17539 else if (cgraph_function_possibly_inlined_p (decl)
17540 && ! DECL_ABSTRACT (decl)
17541 && ! class_or_namespace_scope_p (context_die)
17542 /* dwarf2out_abstract_function won't emit a die if this is just
17543 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
17544 that case, because that works only if we have a die. */
17545 && DECL_INITIAL (decl) != NULL_TREE)
17547 dwarf2out_abstract_function (decl);
17548 set_decl_origin_self (decl);
17551 /* Otherwise we're emitting the primary DIE for this decl. */
17552 else if (debug_info_level > DINFO_LEVEL_TERSE)
17554 /* Before we describe the FUNCTION_DECL itself, make sure that we
17555 have described its return type. */
17556 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
17558 /* And its virtual context. */
17559 if (DECL_VINDEX (decl) != NULL_TREE)
17560 gen_type_die (DECL_CONTEXT (decl), context_die);
17562 /* And its containing type. */
17564 origin = decl_class_context (decl);
17565 if (origin != NULL_TREE)
17566 gen_type_die_for_member (origin, decl, context_die);
17568 /* And its containing namespace. */
17569 context_die = declare_in_namespace (decl, context_die);
17572 /* Now output a DIE to represent the function itself. */
17574 gen_subprogram_die (decl, context_die);
17578 /* If we are in terse mode, don't generate any DIEs to represent any
17579 actual typedefs. */
17580 if (debug_info_level <= DINFO_LEVEL_TERSE)
17583 /* In the special case of a TYPE_DECL node representing the declaration
17584 of some type tag, if the given TYPE_DECL is marked as having been
17585 instantiated from some other (original) TYPE_DECL node (e.g. one which
17586 was generated within the original definition of an inline function) we
17587 used to generate a special (abbreviated) DW_TAG_structure_type,
17588 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
17589 should be actually referencing those DIEs, as variable DIEs with that
17590 type would be emitted already in the abstract origin, so it was always
17591 removed during unused type prunning. Don't add anything in this
17593 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
17596 if (is_redundant_typedef (decl))
17597 gen_type_die (TREE_TYPE (decl), context_die);
17599 /* Output a DIE to represent the typedef itself. */
17600 gen_typedef_die (decl, context_die);
17604 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17605 gen_label_die (decl, context_die);
17610 /* If we are in terse mode, don't generate any DIEs to represent any
17611 variable declarations or definitions. */
17612 if (debug_info_level <= DINFO_LEVEL_TERSE)
17615 /* Output any DIEs that are needed to specify the type of this data
17617 if (decl_by_reference_p (decl_or_origin))
17618 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17620 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17622 /* And its containing type. */
17623 class_origin = decl_class_context (decl_or_origin);
17624 if (class_origin != NULL_TREE)
17625 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
17627 /* And its containing namespace. */
17628 context_die = declare_in_namespace (decl_or_origin, context_die);
17630 /* Now output the DIE to represent the data object itself. This gets
17631 complicated because of the possibility that the VAR_DECL really
17632 represents an inlined instance of a formal parameter for an inline
17635 origin = decl_ultimate_origin (decl);
17636 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
17637 gen_formal_parameter_die (decl, origin,
17638 true /* Emit name attribute. */,
17641 gen_variable_die (decl, origin, context_die);
17645 /* Ignore the nameless fields that are used to skip bits but handle C++
17646 anonymous unions and structs. */
17647 if (DECL_NAME (decl) != NULL_TREE
17648 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
17649 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
17651 gen_type_die (member_declared_type (decl), context_die);
17652 gen_field_die (decl, context_die);
17657 if (DECL_BY_REFERENCE (decl_or_origin))
17658 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17660 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17661 gen_formal_parameter_die (decl, origin,
17662 true /* Emit name attribute. */,
17666 case NAMESPACE_DECL:
17667 case IMPORTED_DECL:
17668 if (dwarf_version >= 3 || !dwarf_strict)
17669 gen_namespace_die (decl, context_die);
17673 /* Probably some frontend-internal decl. Assume we don't care. */
17674 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
17679 /* Output debug information for global decl DECL. Called from toplev.c after
17680 compilation proper has finished. */
17683 dwarf2out_global_decl (tree decl)
17685 /* Output DWARF2 information for file-scope tentative data object
17686 declarations, file-scope (extern) function declarations (which
17687 had no corresponding body) and file-scope tagged type declarations
17688 and definitions which have not yet been forced out. */
17689 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
17690 dwarf2out_decl (decl);
17693 /* Output debug information for type decl DECL. Called from toplev.c
17694 and from language front ends (to record built-in types). */
17696 dwarf2out_type_decl (tree decl, int local)
17699 dwarf2out_decl (decl);
17702 /* Output debug information for imported module or decl DECL.
17703 NAME is non-NULL name in the lexical block if the decl has been renamed.
17704 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
17705 that DECL belongs to.
17706 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
17708 dwarf2out_imported_module_or_decl_1 (tree decl,
17710 tree lexical_block,
17711 dw_die_ref lexical_block_die)
17713 expanded_location xloc;
17714 dw_die_ref imported_die = NULL;
17715 dw_die_ref at_import_die;
17717 if (TREE_CODE (decl) == IMPORTED_DECL)
17719 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
17720 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
17724 xloc = expand_location (input_location);
17726 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
17728 if (is_base_type (TREE_TYPE (decl)))
17729 at_import_die = base_type_die (TREE_TYPE (decl));
17731 at_import_die = force_type_die (TREE_TYPE (decl));
17732 /* For namespace N { typedef void T; } using N::T; base_type_die
17733 returns NULL, but DW_TAG_imported_declaration requires
17734 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
17735 if (!at_import_die)
17737 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
17738 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
17739 at_import_die = lookup_type_die (TREE_TYPE (decl));
17740 gcc_assert (at_import_die);
17745 at_import_die = lookup_decl_die (decl);
17746 if (!at_import_die)
17748 /* If we're trying to avoid duplicate debug info, we may not have
17749 emitted the member decl for this field. Emit it now. */
17750 if (TREE_CODE (decl) == FIELD_DECL)
17752 tree type = DECL_CONTEXT (decl);
17754 if (TYPE_CONTEXT (type)
17755 && TYPE_P (TYPE_CONTEXT (type))
17756 && !should_emit_struct_debug (TYPE_CONTEXT (type),
17757 DINFO_USAGE_DIR_USE))
17759 gen_type_die_for_member (type, decl,
17760 get_context_die (TYPE_CONTEXT (type)));
17762 at_import_die = force_decl_die (decl);
17766 if (TREE_CODE (decl) == NAMESPACE_DECL)
17768 if (dwarf_version >= 3 || !dwarf_strict)
17769 imported_die = new_die (DW_TAG_imported_module,
17776 imported_die = new_die (DW_TAG_imported_declaration,
17780 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
17781 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
17783 add_AT_string (imported_die, DW_AT_name,
17784 IDENTIFIER_POINTER (name));
17785 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
17788 /* Output debug information for imported module or decl DECL.
17789 NAME is non-NULL name in context if the decl has been renamed.
17790 CHILD is true if decl is one of the renamed decls as part of
17791 importing whole module. */
17794 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
17797 /* dw_die_ref at_import_die; */
17798 dw_die_ref scope_die;
17800 if (debug_info_level <= DINFO_LEVEL_TERSE)
17805 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
17806 We need decl DIE for reference and scope die. First, get DIE for the decl
17809 /* Get the scope die for decl context. Use comp_unit_die for global module
17810 or decl. If die is not found for non globals, force new die. */
17812 && TYPE_P (context)
17813 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
17816 if (!(dwarf_version >= 3 || !dwarf_strict))
17819 scope_die = get_context_die (context);
17823 gcc_assert (scope_die->die_child);
17824 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
17825 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
17826 scope_die = scope_die->die_child;
17829 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
17830 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
17834 /* Write the debugging output for DECL. */
17837 dwarf2out_decl (tree decl)
17839 dw_die_ref context_die = comp_unit_die;
17841 switch (TREE_CODE (decl))
17846 case FUNCTION_DECL:
17847 /* What we would really like to do here is to filter out all mere
17848 file-scope declarations of file-scope functions which are never
17849 referenced later within this translation unit (and keep all of ones
17850 that *are* referenced later on) but we aren't clairvoyant, so we have
17851 no idea which functions will be referenced in the future (i.e. later
17852 on within the current translation unit). So here we just ignore all
17853 file-scope function declarations which are not also definitions. If
17854 and when the debugger needs to know something about these functions,
17855 it will have to hunt around and find the DWARF information associated
17856 with the definition of the function.
17858 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
17859 nodes represent definitions and which ones represent mere
17860 declarations. We have to check DECL_INITIAL instead. That's because
17861 the C front-end supports some weird semantics for "extern inline"
17862 function definitions. These can get inlined within the current
17863 translation unit (and thus, we need to generate Dwarf info for their
17864 abstract instances so that the Dwarf info for the concrete inlined
17865 instances can have something to refer to) but the compiler never
17866 generates any out-of-lines instances of such things (despite the fact
17867 that they *are* definitions).
17869 The important point is that the C front-end marks these "extern
17870 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
17871 them anyway. Note that the C++ front-end also plays some similar games
17872 for inline function definitions appearing within include files which
17873 also contain `#pragma interface' pragmas. */
17874 if (DECL_INITIAL (decl) == NULL_TREE)
17877 /* If we're a nested function, initially use a parent of NULL; if we're
17878 a plain function, this will be fixed up in decls_for_scope. If
17879 we're a method, it will be ignored, since we already have a DIE. */
17880 if (decl_function_context (decl)
17881 /* But if we're in terse mode, we don't care about scope. */
17882 && debug_info_level > DINFO_LEVEL_TERSE)
17883 context_die = NULL;
17887 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
17888 declaration and if the declaration was never even referenced from
17889 within this entire compilation unit. We suppress these DIEs in
17890 order to save space in the .debug section (by eliminating entries
17891 which are probably useless). Note that we must not suppress
17892 block-local extern declarations (whether used or not) because that
17893 would screw-up the debugger's name lookup mechanism and cause it to
17894 miss things which really ought to be in scope at a given point. */
17895 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
17898 /* For local statics lookup proper context die. */
17899 if (TREE_STATIC (decl) && decl_function_context (decl))
17900 context_die = lookup_decl_die (DECL_CONTEXT (decl));
17902 /* If we are in terse mode, don't generate any DIEs to represent any
17903 variable declarations or definitions. */
17904 if (debug_info_level <= DINFO_LEVEL_TERSE)
17909 if (debug_info_level <= DINFO_LEVEL_TERSE)
17911 if (!is_fortran ())
17913 if (TREE_STATIC (decl) && decl_function_context (decl))
17914 context_die = lookup_decl_die (DECL_CONTEXT (decl));
17917 case NAMESPACE_DECL:
17918 case IMPORTED_DECL:
17919 if (debug_info_level <= DINFO_LEVEL_TERSE)
17921 if (lookup_decl_die (decl) != NULL)
17926 /* Don't emit stubs for types unless they are needed by other DIEs. */
17927 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
17930 /* Don't bother trying to generate any DIEs to represent any of the
17931 normal built-in types for the language we are compiling. */
17932 if (DECL_IS_BUILTIN (decl))
17934 /* OK, we need to generate one for `bool' so GDB knows what type
17935 comparisons have. */
17937 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
17938 && ! DECL_IGNORED_P (decl))
17939 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
17944 /* If we are in terse mode, don't generate any DIEs for types. */
17945 if (debug_info_level <= DINFO_LEVEL_TERSE)
17948 /* If we're a function-scope tag, initially use a parent of NULL;
17949 this will be fixed up in decls_for_scope. */
17950 if (decl_function_context (decl))
17951 context_die = NULL;
17959 gen_decl_die (decl, NULL, context_die);
17962 /* Output a marker (i.e. a label) for the beginning of the generated code for
17963 a lexical block. */
17966 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
17967 unsigned int blocknum)
17969 switch_to_section (current_function_section ());
17970 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
17973 /* Output a marker (i.e. a label) for the end of the generated code for a
17977 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
17979 switch_to_section (current_function_section ());
17980 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
17983 /* Returns nonzero if it is appropriate not to emit any debugging
17984 information for BLOCK, because it doesn't contain any instructions.
17986 Don't allow this for blocks with nested functions or local classes
17987 as we would end up with orphans, and in the presence of scheduling
17988 we may end up calling them anyway. */
17991 dwarf2out_ignore_block (const_tree block)
17996 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
17997 if (TREE_CODE (decl) == FUNCTION_DECL
17998 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
18000 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
18002 decl = BLOCK_NONLOCALIZED_VAR (block, i);
18003 if (TREE_CODE (decl) == FUNCTION_DECL
18004 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
18011 /* Hash table routines for file_hash. */
18014 file_table_eq (const void *p1_p, const void *p2_p)
18016 const struct dwarf_file_data *const p1 =
18017 (const struct dwarf_file_data *) p1_p;
18018 const char *const p2 = (const char *) p2_p;
18019 return strcmp (p1->filename, p2) == 0;
18023 file_table_hash (const void *p_p)
18025 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
18026 return htab_hash_string (p->filename);
18029 /* Lookup FILE_NAME (in the list of filenames that we know about here in
18030 dwarf2out.c) and return its "index". The index of each (known) filename is
18031 just a unique number which is associated with only that one filename. We
18032 need such numbers for the sake of generating labels (in the .debug_sfnames
18033 section) and references to those files numbers (in the .debug_srcinfo
18034 and.debug_macinfo sections). If the filename given as an argument is not
18035 found in our current list, add it to the list and assign it the next
18036 available unique index number. In order to speed up searches, we remember
18037 the index of the filename was looked up last. This handles the majority of
18040 static struct dwarf_file_data *
18041 lookup_filename (const char *file_name)
18044 struct dwarf_file_data * created;
18046 /* Check to see if the file name that was searched on the previous
18047 call matches this file name. If so, return the index. */
18048 if (file_table_last_lookup
18049 && (file_name == file_table_last_lookup->filename
18050 || strcmp (file_table_last_lookup->filename, file_name) == 0))
18051 return file_table_last_lookup;
18053 /* Didn't match the previous lookup, search the table. */
18054 slot = htab_find_slot_with_hash (file_table, file_name,
18055 htab_hash_string (file_name), INSERT);
18057 return (struct dwarf_file_data *) *slot;
18059 created = GGC_NEW (struct dwarf_file_data);
18060 created->filename = file_name;
18061 created->emitted_number = 0;
18066 /* If the assembler will construct the file table, then translate the compiler
18067 internal file table number into the assembler file table number, and emit
18068 a .file directive if we haven't already emitted one yet. The file table
18069 numbers are different because we prune debug info for unused variables and
18070 types, which may include filenames. */
18073 maybe_emit_file (struct dwarf_file_data * fd)
18075 if (! fd->emitted_number)
18077 if (last_emitted_file)
18078 fd->emitted_number = last_emitted_file->emitted_number + 1;
18080 fd->emitted_number = 1;
18081 last_emitted_file = fd;
18083 if (DWARF2_ASM_LINE_DEBUG_INFO)
18085 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
18086 output_quoted_string (asm_out_file,
18087 remap_debug_filename (fd->filename));
18088 fputc ('\n', asm_out_file);
18092 return fd->emitted_number;
18095 /* Schedule generation of a DW_AT_const_value attribute to DIE.
18096 That generation should happen after function debug info has been
18097 generated. The value of the attribute is the constant value of ARG. */
18100 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
18102 die_arg_entry entry;
18107 if (!tmpl_value_parm_die_table)
18108 tmpl_value_parm_die_table
18109 = VEC_alloc (die_arg_entry, gc, 32);
18113 VEC_safe_push (die_arg_entry, gc,
18114 tmpl_value_parm_die_table,
18118 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
18119 by append_entry_to_tmpl_value_parm_die_table. This function must
18120 be called after function DIEs have been generated. */
18123 gen_remaining_tmpl_value_param_die_attribute (void)
18125 if (tmpl_value_parm_die_table)
18131 VEC_iterate (die_arg_entry, tmpl_value_parm_die_table, i, e);
18133 tree_add_const_value_attribute (e->die, e->arg);
18138 /* Replace DW_AT_name for the decl with name. */
18141 dwarf2out_set_name (tree decl, tree name)
18146 die = TYPE_SYMTAB_DIE (decl);
18150 attr = get_AT (die, DW_AT_name);
18153 struct indirect_string_node *node;
18155 node = find_AT_string (dwarf2_name (name, 0));
18156 /* replace the string. */
18157 attr->dw_attr_val.v.val_str = node;
18161 add_name_attribute (die, dwarf2_name (name, 0));
18164 /* Called by the final INSN scan whenever we see a var location. We
18165 use it to drop labels in the right places, and throw the location in
18166 our lookup table. */
18169 dwarf2out_var_location (rtx loc_note)
18171 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
18172 struct var_loc_node *newloc;
18174 static const char *last_label;
18175 static const char *last_postcall_label;
18176 static bool last_in_cold_section_p;
18179 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
18182 next_real = next_real_insn (loc_note);
18183 /* If there are no instructions which would be affected by this note,
18184 don't do anything. */
18185 if (next_real == NULL_RTX)
18188 newloc = GGC_CNEW (struct var_loc_node);
18189 /* If there were no real insns between note we processed last time
18190 and this note, use the label we emitted last time. */
18191 if (last_var_location_insn == NULL_RTX
18192 || last_var_location_insn != next_real
18193 || last_in_cold_section_p != in_cold_section_p)
18195 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
18196 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
18198 last_label = ggc_strdup (loclabel);
18199 if (!NOTE_DURING_CALL_P (loc_note))
18200 last_postcall_label = NULL;
18202 newloc->var_loc_note = loc_note;
18203 newloc->next = NULL;
18205 if (!NOTE_DURING_CALL_P (loc_note))
18206 newloc->label = last_label;
18209 if (!last_postcall_label)
18211 sprintf (loclabel, "%s-1", last_label);
18212 last_postcall_label = ggc_strdup (loclabel);
18214 newloc->label = last_postcall_label;
18217 if (cfun && in_cold_section_p)
18218 newloc->section_label = crtl->subsections.cold_section_label;
18220 newloc->section_label = text_section_label;
18222 last_var_location_insn = next_real;
18223 last_in_cold_section_p = in_cold_section_p;
18224 decl = NOTE_VAR_LOCATION_DECL (loc_note);
18225 add_var_loc_to_decl (decl, newloc);
18228 /* We need to reset the locations at the beginning of each
18229 function. We can't do this in the end_function hook, because the
18230 declarations that use the locations won't have been output when
18231 that hook is called. Also compute have_multiple_function_sections here. */
18234 dwarf2out_begin_function (tree fun)
18236 htab_empty (decl_loc_table);
18238 if (function_section (fun) != text_section)
18239 have_multiple_function_sections = true;
18241 dwarf2out_note_section_used ();
18244 /* Output a label to mark the beginning of a source code line entry
18245 and record information relating to this source line, in
18246 'line_info_table' for later output of the .debug_line section. */
18249 dwarf2out_source_line (unsigned int line, const char *filename,
18250 int discriminator, bool is_stmt)
18252 static bool last_is_stmt = true;
18254 if (debug_info_level >= DINFO_LEVEL_NORMAL
18257 int file_num = maybe_emit_file (lookup_filename (filename));
18259 switch_to_section (current_function_section ());
18261 /* If requested, emit something human-readable. */
18262 if (flag_debug_asm)
18263 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
18266 if (DWARF2_ASM_LINE_DEBUG_INFO)
18268 /* Emit the .loc directive understood by GNU as. */
18269 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
18270 if (is_stmt != last_is_stmt)
18272 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
18273 last_is_stmt = is_stmt;
18275 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
18276 fprintf (asm_out_file, " discriminator %d", discriminator);
18277 fputc ('\n', asm_out_file);
18279 /* Indicate that line number info exists. */
18280 line_info_table_in_use++;
18282 else if (function_section (current_function_decl) != text_section)
18284 dw_separate_line_info_ref line_info;
18285 targetm.asm_out.internal_label (asm_out_file,
18286 SEPARATE_LINE_CODE_LABEL,
18287 separate_line_info_table_in_use);
18289 /* Expand the line info table if necessary. */
18290 if (separate_line_info_table_in_use
18291 == separate_line_info_table_allocated)
18293 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
18294 separate_line_info_table
18295 = GGC_RESIZEVEC (dw_separate_line_info_entry,
18296 separate_line_info_table,
18297 separate_line_info_table_allocated);
18298 memset (separate_line_info_table
18299 + separate_line_info_table_in_use,
18301 (LINE_INFO_TABLE_INCREMENT
18302 * sizeof (dw_separate_line_info_entry)));
18305 /* Add the new entry at the end of the line_info_table. */
18307 = &separate_line_info_table[separate_line_info_table_in_use++];
18308 line_info->dw_file_num = file_num;
18309 line_info->dw_line_num = line;
18310 line_info->function = current_function_funcdef_no;
18314 dw_line_info_ref line_info;
18316 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
18317 line_info_table_in_use);
18319 /* Expand the line info table if necessary. */
18320 if (line_info_table_in_use == line_info_table_allocated)
18322 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
18324 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
18325 line_info_table_allocated);
18326 memset (line_info_table + line_info_table_in_use, 0,
18327 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
18330 /* Add the new entry at the end of the line_info_table. */
18331 line_info = &line_info_table[line_info_table_in_use++];
18332 line_info->dw_file_num = file_num;
18333 line_info->dw_line_num = line;
18338 /* Record the beginning of a new source file. */
18341 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
18343 if (flag_eliminate_dwarf2_dups)
18345 /* Record the beginning of the file for break_out_includes. */
18346 dw_die_ref bincl_die;
18348 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
18349 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
18352 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18354 int file_num = maybe_emit_file (lookup_filename (filename));
18356 switch_to_section (debug_macinfo_section);
18357 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
18358 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
18361 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
18365 /* Record the end of a source file. */
18368 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
18370 if (flag_eliminate_dwarf2_dups)
18371 /* Record the end of the file for break_out_includes. */
18372 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
18374 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18376 switch_to_section (debug_macinfo_section);
18377 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
18381 /* Called from debug_define in toplev.c. The `buffer' parameter contains
18382 the tail part of the directive line, i.e. the part which is past the
18383 initial whitespace, #, whitespace, directive-name, whitespace part. */
18386 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
18387 const char *buffer ATTRIBUTE_UNUSED)
18389 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18391 switch_to_section (debug_macinfo_section);
18392 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
18393 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
18394 dw2_asm_output_nstring (buffer, -1, "The macro");
18398 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
18399 the tail part of the directive line, i.e. the part which is past the
18400 initial whitespace, #, whitespace, directive-name, whitespace part. */
18403 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
18404 const char *buffer ATTRIBUTE_UNUSED)
18406 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18408 switch_to_section (debug_macinfo_section);
18409 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
18410 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
18411 dw2_asm_output_nstring (buffer, -1, "The macro");
18415 /* Set up for Dwarf output at the start of compilation. */
18418 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
18420 /* Allocate the file_table. */
18421 file_table = htab_create_ggc (50, file_table_hash,
18422 file_table_eq, NULL);
18424 /* Allocate the decl_die_table. */
18425 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
18426 decl_die_table_eq, NULL);
18428 /* Allocate the decl_loc_table. */
18429 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
18430 decl_loc_table_eq, NULL);
18432 /* Allocate the initial hunk of the decl_scope_table. */
18433 decl_scope_table = VEC_alloc (tree, gc, 256);
18435 /* Allocate the initial hunk of the abbrev_die_table. */
18436 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
18437 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
18438 /* Zero-th entry is allocated, but unused. */
18439 abbrev_die_table_in_use = 1;
18441 /* Allocate the initial hunk of the line_info_table. */
18442 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
18443 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
18445 /* Zero-th entry is allocated, but unused. */
18446 line_info_table_in_use = 1;
18448 /* Allocate the pubtypes and pubnames vectors. */
18449 pubname_table = VEC_alloc (pubname_entry, gc, 32);
18450 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
18452 /* Generate the initial DIE for the .debug section. Note that the (string)
18453 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
18454 will (typically) be a relative pathname and that this pathname should be
18455 taken as being relative to the directory from which the compiler was
18456 invoked when the given (base) source file was compiled. We will fill
18457 in this value in dwarf2out_finish. */
18458 comp_unit_die = gen_compile_unit_die (NULL);
18460 incomplete_types = VEC_alloc (tree, gc, 64);
18462 used_rtx_array = VEC_alloc (rtx, gc, 32);
18464 debug_info_section = get_section (DEBUG_INFO_SECTION,
18465 SECTION_DEBUG, NULL);
18466 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
18467 SECTION_DEBUG, NULL);
18468 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
18469 SECTION_DEBUG, NULL);
18470 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
18471 SECTION_DEBUG, NULL);
18472 debug_line_section = get_section (DEBUG_LINE_SECTION,
18473 SECTION_DEBUG, NULL);
18474 debug_loc_section = get_section (DEBUG_LOC_SECTION,
18475 SECTION_DEBUG, NULL);
18476 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
18477 SECTION_DEBUG, NULL);
18478 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
18479 SECTION_DEBUG, NULL);
18480 debug_str_section = get_section (DEBUG_STR_SECTION,
18481 DEBUG_STR_SECTION_FLAGS, NULL);
18482 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
18483 SECTION_DEBUG, NULL);
18484 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
18485 SECTION_DEBUG, NULL);
18487 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
18488 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
18489 DEBUG_ABBREV_SECTION_LABEL, 0);
18490 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
18491 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
18492 COLD_TEXT_SECTION_LABEL, 0);
18493 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
18495 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
18496 DEBUG_INFO_SECTION_LABEL, 0);
18497 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
18498 DEBUG_LINE_SECTION_LABEL, 0);
18499 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
18500 DEBUG_RANGES_SECTION_LABEL, 0);
18501 switch_to_section (debug_abbrev_section);
18502 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
18503 switch_to_section (debug_info_section);
18504 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
18505 switch_to_section (debug_line_section);
18506 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
18508 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18510 switch_to_section (debug_macinfo_section);
18511 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
18512 DEBUG_MACINFO_SECTION_LABEL, 0);
18513 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
18516 switch_to_section (text_section);
18517 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
18518 if (flag_reorder_blocks_and_partition)
18520 cold_text_section = unlikely_text_section ();
18521 switch_to_section (cold_text_section);
18522 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
18526 /* A helper function for dwarf2out_finish called through
18527 htab_traverse. Emit one queued .debug_str string. */
18530 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
18532 struct indirect_string_node *node = (struct indirect_string_node *) *h;
18534 if (node->label && node->refcount)
18536 switch_to_section (debug_str_section);
18537 ASM_OUTPUT_LABEL (asm_out_file, node->label);
18538 assemble_string (node->str, strlen (node->str) + 1);
18544 #if ENABLE_ASSERT_CHECKING
18545 /* Verify that all marks are clear. */
18548 verify_marks_clear (dw_die_ref die)
18552 gcc_assert (! die->die_mark);
18553 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
18555 #endif /* ENABLE_ASSERT_CHECKING */
18557 /* Clear the marks for a die and its children.
18558 Be cool if the mark isn't set. */
18561 prune_unmark_dies (dw_die_ref die)
18567 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
18570 /* Given DIE that we're marking as used, find any other dies
18571 it references as attributes and mark them as used. */
18574 prune_unused_types_walk_attribs (dw_die_ref die)
18579 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18581 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
18583 /* A reference to another DIE.
18584 Make sure that it will get emitted. */
18585 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
18587 /* Set the string's refcount to 0 so that prune_unused_types_mark
18588 accounts properly for it. */
18589 if (AT_class (a) == dw_val_class_str)
18590 a->dw_attr_val.v.val_str->refcount = 0;
18595 /* Mark DIE as being used. If DOKIDS is true, then walk down
18596 to DIE's children. */
18599 prune_unused_types_mark (dw_die_ref die, int dokids)
18603 if (die->die_mark == 0)
18605 /* We haven't done this node yet. Mark it as used. */
18608 /* We also have to mark its parents as used.
18609 (But we don't want to mark our parents' kids due to this.) */
18610 if (die->die_parent)
18611 prune_unused_types_mark (die->die_parent, 0);
18613 /* Mark any referenced nodes. */
18614 prune_unused_types_walk_attribs (die);
18616 /* If this node is a specification,
18617 also mark the definition, if it exists. */
18618 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
18619 prune_unused_types_mark (die->die_definition, 1);
18622 if (dokids && die->die_mark != 2)
18624 /* We need to walk the children, but haven't done so yet.
18625 Remember that we've walked the kids. */
18628 /* If this is an array type, we need to make sure our
18629 kids get marked, even if they're types. */
18630 if (die->die_tag == DW_TAG_array_type)
18631 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
18633 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18637 /* For local classes, look if any static member functions were emitted
18638 and if so, mark them. */
18641 prune_unused_types_walk_local_classes (dw_die_ref die)
18645 if (die->die_mark == 2)
18648 switch (die->die_tag)
18650 case DW_TAG_structure_type:
18651 case DW_TAG_union_type:
18652 case DW_TAG_class_type:
18655 case DW_TAG_subprogram:
18656 if (!get_AT_flag (die, DW_AT_declaration)
18657 || die->die_definition != NULL)
18658 prune_unused_types_mark (die, 1);
18665 /* Mark children. */
18666 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
18669 /* Walk the tree DIE and mark types that we actually use. */
18672 prune_unused_types_walk (dw_die_ref die)
18676 /* Don't do anything if this node is already marked and
18677 children have been marked as well. */
18678 if (die->die_mark == 2)
18681 switch (die->die_tag)
18683 case DW_TAG_structure_type:
18684 case DW_TAG_union_type:
18685 case DW_TAG_class_type:
18686 if (die->die_perennial_p)
18689 for (c = die->die_parent; c; c = c->die_parent)
18690 if (c->die_tag == DW_TAG_subprogram)
18693 /* Finding used static member functions inside of classes
18694 is needed just for local classes, because for other classes
18695 static member function DIEs with DW_AT_specification
18696 are emitted outside of the DW_TAG_*_type. If we ever change
18697 it, we'd need to call this even for non-local classes. */
18699 prune_unused_types_walk_local_classes (die);
18701 /* It's a type node --- don't mark it. */
18704 case DW_TAG_const_type:
18705 case DW_TAG_packed_type:
18706 case DW_TAG_pointer_type:
18707 case DW_TAG_reference_type:
18708 case DW_TAG_volatile_type:
18709 case DW_TAG_typedef:
18710 case DW_TAG_array_type:
18711 case DW_TAG_interface_type:
18712 case DW_TAG_friend:
18713 case DW_TAG_variant_part:
18714 case DW_TAG_enumeration_type:
18715 case DW_TAG_subroutine_type:
18716 case DW_TAG_string_type:
18717 case DW_TAG_set_type:
18718 case DW_TAG_subrange_type:
18719 case DW_TAG_ptr_to_member_type:
18720 case DW_TAG_file_type:
18721 if (die->die_perennial_p)
18724 /* It's a type node --- don't mark it. */
18728 /* Mark everything else. */
18732 if (die->die_mark == 0)
18736 /* Now, mark any dies referenced from here. */
18737 prune_unused_types_walk_attribs (die);
18742 /* Mark children. */
18743 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18746 /* Increment the string counts on strings referred to from DIE's
18750 prune_unused_types_update_strings (dw_die_ref die)
18755 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18756 if (AT_class (a) == dw_val_class_str)
18758 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
18760 /* Avoid unnecessarily putting strings that are used less than
18761 twice in the hash table. */
18763 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
18766 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
18767 htab_hash_string (s->str),
18769 gcc_assert (*slot == NULL);
18775 /* Remove from the tree DIE any dies that aren't marked. */
18778 prune_unused_types_prune (dw_die_ref die)
18782 gcc_assert (die->die_mark);
18783 prune_unused_types_update_strings (die);
18785 if (! die->die_child)
18788 c = die->die_child;
18790 dw_die_ref prev = c;
18791 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
18792 if (c == die->die_child)
18794 /* No marked children between 'prev' and the end of the list. */
18796 /* No marked children at all. */
18797 die->die_child = NULL;
18800 prev->die_sib = c->die_sib;
18801 die->die_child = prev;
18806 if (c != prev->die_sib)
18808 prune_unused_types_prune (c);
18809 } while (c != die->die_child);
18812 /* A helper function for dwarf2out_finish called through
18813 htab_traverse. Clear .debug_str strings that we haven't already
18814 decided to emit. */
18817 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
18819 struct indirect_string_node *node = (struct indirect_string_node *) *h;
18821 if (!node->label || !node->refcount)
18822 htab_clear_slot (debug_str_hash, h);
18827 /* Remove dies representing declarations that we never use. */
18830 prune_unused_types (void)
18833 limbo_die_node *node;
18836 #if ENABLE_ASSERT_CHECKING
18837 /* All the marks should already be clear. */
18838 verify_marks_clear (comp_unit_die);
18839 for (node = limbo_die_list; node; node = node->next)
18840 verify_marks_clear (node->die);
18841 #endif /* ENABLE_ASSERT_CHECKING */
18843 /* Mark types that are used in global variables. */
18844 premark_types_used_by_global_vars ();
18846 /* Set the mark on nodes that are actually used. */
18847 prune_unused_types_walk (comp_unit_die);
18848 for (node = limbo_die_list; node; node = node->next)
18849 prune_unused_types_walk (node->die);
18851 /* Also set the mark on nodes referenced from the
18852 pubname_table or arange_table. */
18853 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
18854 prune_unused_types_mark (pub->die, 1);
18855 for (i = 0; i < arange_table_in_use; i++)
18856 prune_unused_types_mark (arange_table[i], 1);
18858 /* Get rid of nodes that aren't marked; and update the string counts. */
18859 if (debug_str_hash && debug_str_hash_forced)
18860 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
18861 else if (debug_str_hash)
18862 htab_empty (debug_str_hash);
18863 prune_unused_types_prune (comp_unit_die);
18864 for (node = limbo_die_list; node; node = node->next)
18865 prune_unused_types_prune (node->die);
18867 /* Leave the marks clear. */
18868 prune_unmark_dies (comp_unit_die);
18869 for (node = limbo_die_list; node; node = node->next)
18870 prune_unmark_dies (node->die);
18873 /* Set the parameter to true if there are any relative pathnames in
18876 file_table_relative_p (void ** slot, void *param)
18878 bool *p = (bool *) param;
18879 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
18880 if (!IS_ABSOLUTE_PATH (d->filename))
18888 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
18889 to the location it would have been added, should we know its
18890 DECL_ASSEMBLER_NAME when we added other attributes. This will
18891 probably improve compactness of debug info, removing equivalent
18892 abbrevs, and hide any differences caused by deferring the
18893 computation of the assembler name, triggered by e.g. PCH. */
18896 move_linkage_attr (dw_die_ref die)
18898 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
18899 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
18901 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
18905 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
18907 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
18911 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
18913 VEC_pop (dw_attr_node, die->die_attr);
18914 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
18918 /* Output stuff that dwarf requires at the end of every file,
18919 and generate the DWARF-2 debugging info. */
18922 dwarf2out_finish (const char *filename)
18924 limbo_die_node *node, *next_node;
18925 dw_die_ref die = 0;
18928 gen_remaining_tmpl_value_param_die_attribute ();
18930 /* Add the name for the main input file now. We delayed this from
18931 dwarf2out_init to avoid complications with PCH. */
18932 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
18933 if (!IS_ABSOLUTE_PATH (filename))
18934 add_comp_dir_attribute (comp_unit_die);
18935 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
18938 htab_traverse (file_table, file_table_relative_p, &p);
18940 add_comp_dir_attribute (comp_unit_die);
18943 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
18945 add_location_or_const_value_attribute (
18946 VEC_index (deferred_locations, deferred_locations_list, i)->die,
18947 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
18951 /* Traverse the limbo die list, and add parent/child links. The only
18952 dies without parents that should be here are concrete instances of
18953 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
18954 For concrete instances, we can get the parent die from the abstract
18956 for (node = limbo_die_list; node; node = next_node)
18958 next_node = node->next;
18961 if (die->die_parent == NULL)
18963 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
18966 add_child_die (origin->die_parent, die);
18967 else if (die == comp_unit_die)
18969 else if (errorcount > 0 || sorrycount > 0)
18970 /* It's OK to be confused by errors in the input. */
18971 add_child_die (comp_unit_die, die);
18974 /* In certain situations, the lexical block containing a
18975 nested function can be optimized away, which results
18976 in the nested function die being orphaned. Likewise
18977 with the return type of that nested function. Force
18978 this to be a child of the containing function.
18980 It may happen that even the containing function got fully
18981 inlined and optimized out. In that case we are lost and
18982 assign the empty child. This should not be big issue as
18983 the function is likely unreachable too. */
18984 tree context = NULL_TREE;
18986 gcc_assert (node->created_for);
18988 if (DECL_P (node->created_for))
18989 context = DECL_CONTEXT (node->created_for);
18990 else if (TYPE_P (node->created_for))
18991 context = TYPE_CONTEXT (node->created_for);
18993 gcc_assert (context
18994 && (TREE_CODE (context) == FUNCTION_DECL
18995 || TREE_CODE (context) == NAMESPACE_DECL));
18997 origin = lookup_decl_die (context);
18999 add_child_die (origin, die);
19001 add_child_die (comp_unit_die, die);
19006 limbo_die_list = NULL;
19008 for (node = deferred_asm_name; node; node = node->next)
19010 tree decl = node->created_for;
19011 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
19013 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
19014 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
19015 move_linkage_attr (node->die);
19019 deferred_asm_name = NULL;
19021 /* Walk through the list of incomplete types again, trying once more to
19022 emit full debugging info for them. */
19023 retry_incomplete_types ();
19025 if (flag_eliminate_unused_debug_types)
19026 prune_unused_types ();
19028 /* Generate separate CUs for each of the include files we've seen.
19029 They will go into limbo_die_list. */
19030 if (flag_eliminate_dwarf2_dups)
19031 break_out_includes (comp_unit_die);
19033 /* Traverse the DIE's and add add sibling attributes to those DIE's
19034 that have children. */
19035 add_sibling_attributes (comp_unit_die);
19036 for (node = limbo_die_list; node; node = node->next)
19037 add_sibling_attributes (node->die);
19039 /* Output a terminator label for the .text section. */
19040 switch_to_section (text_section);
19041 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
19042 if (flag_reorder_blocks_and_partition)
19044 switch_to_section (unlikely_text_section ());
19045 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
19048 /* We can only use the low/high_pc attributes if all of the code was
19050 if (!have_multiple_function_sections
19051 || !(dwarf_version >= 3 || !dwarf_strict))
19053 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
19054 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
19059 unsigned fde_idx = 0;
19061 /* We need to give .debug_loc and .debug_ranges an appropriate
19062 "base address". Use zero so that these addresses become
19063 absolute. Historically, we've emitted the unexpected
19064 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
19065 Emit both to give time for other tools to adapt. */
19066 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
19067 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
19069 add_AT_range_list (comp_unit_die, DW_AT_ranges,
19070 add_ranges_by_labels (text_section_label,
19072 if (flag_reorder_blocks_and_partition)
19073 add_ranges_by_labels (cold_text_section_label,
19076 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
19078 dw_fde_ref fde = &fde_table[fde_idx];
19080 if (fde->dw_fde_switched_sections)
19082 if (!fde->in_std_section)
19083 add_ranges_by_labels (fde->dw_fde_hot_section_label,
19084 fde->dw_fde_hot_section_end_label);
19085 if (!fde->cold_in_std_section)
19086 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
19087 fde->dw_fde_unlikely_section_end_label);
19089 else if (!fde->in_std_section)
19090 add_ranges_by_labels (fde->dw_fde_begin,
19097 /* Output location list section if necessary. */
19098 if (have_location_lists)
19100 /* Output the location lists info. */
19101 switch_to_section (debug_loc_section);
19102 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
19103 DEBUG_LOC_SECTION_LABEL, 0);
19104 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
19105 output_location_lists (die);
19108 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19109 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
19110 debug_line_section_label);
19112 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
19113 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
19115 /* Output all of the compilation units. We put the main one last so that
19116 the offsets are available to output_pubnames. */
19117 for (node = limbo_die_list; node; node = node->next)
19118 output_comp_unit (node->die, 0);
19120 /* Output the main compilation unit if non-empty or if .debug_macinfo
19121 has been emitted. */
19122 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
19124 /* Output the abbreviation table. */
19125 switch_to_section (debug_abbrev_section);
19126 output_abbrev_section ();
19128 /* Output public names table if necessary. */
19129 if (!VEC_empty (pubname_entry, pubname_table))
19131 switch_to_section (debug_pubnames_section);
19132 output_pubnames (pubname_table);
19135 /* Output public types table if necessary. */
19136 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
19137 It shouldn't hurt to emit it always, since pure DWARF2 consumers
19138 simply won't look for the section. */
19139 if (!VEC_empty (pubname_entry, pubtype_table))
19141 switch_to_section (debug_pubtypes_section);
19142 output_pubnames (pubtype_table);
19145 /* Output the address range information. We only put functions in the arange
19146 table, so don't write it out if we don't have any. */
19147 if (fde_table_in_use)
19149 switch_to_section (debug_aranges_section);
19153 /* Output ranges section if necessary. */
19154 if (ranges_table_in_use)
19156 switch_to_section (debug_ranges_section);
19157 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
19161 /* Output the source line correspondence table. We must do this
19162 even if there is no line information. Otherwise, on an empty
19163 translation unit, we will generate a present, but empty,
19164 .debug_info section. IRIX 6.5 `nm' will then complain when
19165 examining the file. This is done late so that any filenames
19166 used by the debug_info section are marked as 'used'. */
19167 if (! DWARF2_ASM_LINE_DEBUG_INFO)
19169 switch_to_section (debug_line_section);
19170 output_line_info ();
19173 /* Have to end the macro section. */
19174 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
19176 switch_to_section (debug_macinfo_section);
19177 dw2_asm_output_data (1, 0, "End compilation unit");
19180 /* If we emitted any DW_FORM_strp form attribute, output the string
19182 if (debug_str_hash)
19183 htab_traverse (debug_str_hash, output_indirect_string, NULL);
19187 /* This should never be used, but its address is needed for comparisons. */
19188 const struct gcc_debug_hooks dwarf2_debug_hooks =
19194 0, /* start_source_file */
19195 0, /* end_source_file */
19196 0, /* begin_block */
19198 0, /* ignore_block */
19199 0, /* source_line */
19200 0, /* begin_prologue */
19201 0, /* end_prologue */
19202 0, /* end_epilogue */
19203 0, /* begin_function */
19204 0, /* end_function */
19205 0, /* function_decl */
19206 0, /* global_decl */
19208 0, /* imported_module_or_decl */
19209 0, /* deferred_inline_function */
19210 0, /* outlining_inline_function */
19212 0, /* handle_pch */
19213 0, /* var_location */
19214 0, /* switch_text_section */
19216 0 /* start_end_main_source_file */
19219 #endif /* DWARF2_DEBUGGING_INFO */
19221 #include "gt-dwarf2out.h"