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 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE)
184 #ifdef TARGET_UNWIND_INFO
187 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
192 saved_do_cfi_asm = true;
196 /* The size of the target's pointer type. */
198 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
201 /* Array of RTXes referenced by the debugging information, which therefore
202 must be kept around forever. */
203 static GTY(()) VEC(rtx,gc) *used_rtx_array;
205 /* A pointer to the base of a list of incomplete types which might be
206 completed at some later time. incomplete_types_list needs to be a
207 VEC(tree,gc) because we want to tell the garbage collector about
209 static GTY(()) VEC(tree,gc) *incomplete_types;
211 /* A pointer to the base of a table of references to declaration
212 scopes. This table is a display which tracks the nesting
213 of declaration scopes at the current scope and containing
214 scopes. This table is used to find the proper place to
215 define type declaration DIE's. */
216 static GTY(()) VEC(tree,gc) *decl_scope_table;
218 /* Pointers to various DWARF2 sections. */
219 static GTY(()) section *debug_info_section;
220 static GTY(()) section *debug_abbrev_section;
221 static GTY(()) section *debug_aranges_section;
222 static GTY(()) section *debug_macinfo_section;
223 static GTY(()) section *debug_line_section;
224 static GTY(()) section *debug_loc_section;
225 static GTY(()) section *debug_pubnames_section;
226 static GTY(()) section *debug_pubtypes_section;
227 static GTY(()) section *debug_str_section;
228 static GTY(()) section *debug_ranges_section;
229 static GTY(()) section *debug_frame_section;
231 /* Personality decl of current unit. Used only when assembler does not support
233 static GTY(()) rtx current_unit_personality;
235 /* How to start an assembler comment. */
236 #ifndef ASM_COMMENT_START
237 #define ASM_COMMENT_START ";#"
240 typedef struct dw_cfi_struct *dw_cfi_ref;
241 typedef struct dw_fde_struct *dw_fde_ref;
242 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
244 /* Call frames are described using a sequence of Call Frame
245 Information instructions. The register number, offset
246 and address fields are provided as possible operands;
247 their use is selected by the opcode field. */
249 enum dw_cfi_oprnd_type {
251 dw_cfi_oprnd_reg_num,
257 typedef union GTY(()) dw_cfi_oprnd_struct {
258 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
259 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
260 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
261 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
265 typedef struct GTY(()) dw_cfi_struct {
266 dw_cfi_ref dw_cfi_next;
267 enum dwarf_call_frame_info dw_cfi_opc;
268 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
270 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
275 /* This is how we define the location of the CFA. We use to handle it
276 as REG + OFFSET all the time, but now it can be more complex.
277 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
278 Instead of passing around REG and OFFSET, we pass a copy
279 of this structure. */
280 typedef struct GTY(()) cfa_loc {
281 HOST_WIDE_INT offset;
282 HOST_WIDE_INT base_offset;
284 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
285 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
288 /* All call frame descriptions (FDE's) in the GCC generated DWARF
289 refer to a single Common Information Entry (CIE), defined at
290 the beginning of the .debug_frame section. This use of a single
291 CIE obviates the need to keep track of multiple CIE's
292 in the DWARF generation routines below. */
294 typedef struct GTY(()) dw_fde_struct {
296 const char *dw_fde_begin;
297 const char *dw_fde_current_label;
298 const char *dw_fde_end;
299 const char *dw_fde_hot_section_label;
300 const char *dw_fde_hot_section_end_label;
301 const char *dw_fde_unlikely_section_label;
302 const char *dw_fde_unlikely_section_end_label;
303 dw_cfi_ref dw_fde_cfi;
304 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
305 unsigned funcdef_number;
306 HOST_WIDE_INT stack_realignment;
307 /* Dynamic realign argument pointer register. */
308 unsigned int drap_reg;
309 /* Virtual dynamic realign argument pointer register. */
310 unsigned int vdrap_reg;
311 unsigned all_throwers_are_sibcalls : 1;
312 unsigned nothrow : 1;
313 unsigned uses_eh_lsda : 1;
314 /* Whether we did stack realign in this call frame. */
315 unsigned stack_realign : 1;
316 /* Whether dynamic realign argument pointer register has been saved. */
317 unsigned drap_reg_saved: 1;
318 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
319 unsigned in_std_section : 1;
320 /* True iff dw_fde_unlikely_section_label is in text_section or
321 cold_text_section. */
322 unsigned cold_in_std_section : 1;
323 /* True iff switched sections. */
324 unsigned dw_fde_switched_sections : 1;
325 /* True iff switching from cold to hot section. */
326 unsigned dw_fde_switched_cold_to_hot : 1;
330 /* Maximum size (in bytes) of an artificially generated label. */
331 #define MAX_ARTIFICIAL_LABEL_BYTES 30
333 /* The size of addresses as they appear in the Dwarf 2 data.
334 Some architectures use word addresses to refer to code locations,
335 but Dwarf 2 info always uses byte addresses. On such machines,
336 Dwarf 2 addresses need to be larger than the architecture's
338 #ifndef DWARF2_ADDR_SIZE
339 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
342 /* The size in bytes of a DWARF field indicating an offset or length
343 relative to a debug info section, specified to be 4 bytes in the
344 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
347 #ifndef DWARF_OFFSET_SIZE
348 #define DWARF_OFFSET_SIZE 4
351 /* According to the (draft) DWARF 3 specification, the initial length
352 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
353 bytes are 0xffffffff, followed by the length stored in the next 8
356 However, the SGI/MIPS ABI uses an initial length which is equal to
357 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
359 #ifndef DWARF_INITIAL_LENGTH_SIZE
360 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
363 /* Round SIZE up to the nearest BOUNDARY. */
364 #define DWARF_ROUND(SIZE,BOUNDARY) \
365 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
367 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
368 #ifndef DWARF_CIE_DATA_ALIGNMENT
369 #ifdef STACK_GROWS_DOWNWARD
370 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
372 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
376 /* CIE identifier. */
377 #if HOST_BITS_PER_WIDE_INT >= 64
378 #define DWARF_CIE_ID \
379 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
381 #define DWARF_CIE_ID DW_CIE_ID
384 /* A pointer to the base of a table that contains frame description
385 information for each routine. */
386 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
388 /* Number of elements currently allocated for fde_table. */
389 static GTY(()) unsigned fde_table_allocated;
391 /* Number of elements in fde_table currently in use. */
392 static GTY(()) unsigned fde_table_in_use;
394 /* Size (in elements) of increments by which we may expand the
396 #define FDE_TABLE_INCREMENT 256
398 /* Get the current fde_table entry we should use. */
400 static inline dw_fde_ref
403 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
406 /* A list of call frame insns for the CIE. */
407 static GTY(()) dw_cfi_ref cie_cfi_head;
409 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
410 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
411 attribute that accelerates the lookup of the FDE associated
412 with the subprogram. This variable holds the table index of the FDE
413 associated with the current function (body) definition. */
414 static unsigned current_funcdef_fde;
417 struct GTY(()) indirect_string_node {
419 unsigned int refcount;
420 enum dwarf_form form;
424 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
426 /* True if the compilation unit has location entries that reference
428 static GTY(()) bool debug_str_hash_forced = false;
430 static GTY(()) int dw2_string_counter;
431 static GTY(()) unsigned long dwarf2out_cfi_label_num;
433 /* True if the compilation unit places functions in more than one section. */
434 static GTY(()) bool have_multiple_function_sections = false;
436 /* Whether the default text and cold text sections have been used at all. */
438 static GTY(()) bool text_section_used = false;
439 static GTY(()) bool cold_text_section_used = false;
441 /* The default cold text section. */
442 static GTY(()) section *cold_text_section;
444 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
446 /* Forward declarations for functions defined in this file. */
448 static char *stripattributes (const char *);
449 static const char *dwarf_cfi_name (unsigned);
450 static dw_cfi_ref new_cfi (void);
451 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
452 static void add_fde_cfi (const char *, dw_cfi_ref);
453 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
454 static void lookup_cfa (dw_cfa_location *);
455 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
456 #ifdef DWARF2_UNWIND_INFO
457 static void initial_return_save (rtx);
459 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
461 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
462 static void output_cfi_directive (dw_cfi_ref);
463 static void output_call_frame_info (int);
464 static void dwarf2out_note_section_used (void);
465 static void dwarf2out_stack_adjust (rtx, bool);
466 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
467 static void flush_queued_reg_saves (void);
468 static bool clobbers_queued_reg_save (const_rtx);
469 static void dwarf2out_frame_debug_expr (rtx, const char *);
471 /* Support for complex CFA locations. */
472 static void output_cfa_loc (dw_cfi_ref);
473 static void output_cfa_loc_raw (dw_cfi_ref);
474 static void get_cfa_from_loc_descr (dw_cfa_location *,
475 struct dw_loc_descr_struct *);
476 static struct dw_loc_descr_struct *build_cfa_loc
477 (dw_cfa_location *, HOST_WIDE_INT);
478 static struct dw_loc_descr_struct *build_cfa_aligned_loc
479 (HOST_WIDE_INT, HOST_WIDE_INT);
480 static void def_cfa_1 (const char *, dw_cfa_location *);
482 /* How to start an assembler comment. */
483 #ifndef ASM_COMMENT_START
484 #define ASM_COMMENT_START ";#"
487 /* Data and reference forms for relocatable data. */
488 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
489 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
491 #ifndef DEBUG_FRAME_SECTION
492 #define DEBUG_FRAME_SECTION ".debug_frame"
495 #ifndef FUNC_BEGIN_LABEL
496 #define FUNC_BEGIN_LABEL "LFB"
499 #ifndef FUNC_END_LABEL
500 #define FUNC_END_LABEL "LFE"
503 #ifndef FRAME_BEGIN_LABEL
504 #define FRAME_BEGIN_LABEL "Lframe"
506 #define CIE_AFTER_SIZE_LABEL "LSCIE"
507 #define CIE_END_LABEL "LECIE"
508 #define FDE_LABEL "LSFDE"
509 #define FDE_AFTER_SIZE_LABEL "LASFDE"
510 #define FDE_END_LABEL "LEFDE"
511 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
512 #define LINE_NUMBER_END_LABEL "LELT"
513 #define LN_PROLOG_AS_LABEL "LASLTP"
514 #define LN_PROLOG_END_LABEL "LELTP"
515 #define DIE_LABEL_PREFIX "DW"
517 /* The DWARF 2 CFA column which tracks the return address. Normally this
518 is the column for PC, or the first column after all of the hard
520 #ifndef DWARF_FRAME_RETURN_COLUMN
522 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
524 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
528 /* The mapping from gcc register number to DWARF 2 CFA column number. By
529 default, we just provide columns for all registers. */
530 #ifndef DWARF_FRAME_REGNUM
531 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
534 /* Hook used by __throw. */
537 expand_builtin_dwarf_sp_column (void)
539 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
540 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
543 /* Return a pointer to a copy of the section string name S with all
544 attributes stripped off, and an asterisk prepended (for assemble_name). */
547 stripattributes (const char *s)
549 char *stripped = XNEWVEC (char, strlen (s) + 2);
554 while (*s && *s != ',')
561 /* MEM is a memory reference for the register size table, each element of
562 which has mode MODE. Initialize column C as a return address column. */
565 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
567 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
568 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
569 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
572 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
574 static inline HOST_WIDE_INT
575 div_data_align (HOST_WIDE_INT off)
577 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
578 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
582 /* Return true if we need a signed version of a given opcode
583 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
586 need_data_align_sf_opcode (HOST_WIDE_INT off)
588 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
591 /* Generate code to initialize the register size table. */
594 expand_builtin_init_dwarf_reg_sizes (tree address)
597 enum machine_mode mode = TYPE_MODE (char_type_node);
598 rtx addr = expand_normal (address);
599 rtx mem = gen_rtx_MEM (BLKmode, addr);
600 bool wrote_return_column = false;
602 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
604 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
606 if (rnum < DWARF_FRAME_REGISTERS)
608 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
609 enum machine_mode save_mode = reg_raw_mode[i];
612 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
613 save_mode = choose_hard_reg_mode (i, 1, true);
614 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
616 if (save_mode == VOIDmode)
618 wrote_return_column = true;
620 size = GET_MODE_SIZE (save_mode);
624 emit_move_insn (adjust_address (mem, mode, offset),
625 gen_int_mode (size, mode));
629 if (!wrote_return_column)
630 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
632 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
633 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
636 targetm.init_dwarf_reg_sizes_extra (address);
639 /* Convert a DWARF call frame info. operation to its string name */
642 dwarf_cfi_name (unsigned int cfi_opc)
646 case DW_CFA_advance_loc:
647 return "DW_CFA_advance_loc";
649 return "DW_CFA_offset";
651 return "DW_CFA_restore";
655 return "DW_CFA_set_loc";
656 case DW_CFA_advance_loc1:
657 return "DW_CFA_advance_loc1";
658 case DW_CFA_advance_loc2:
659 return "DW_CFA_advance_loc2";
660 case DW_CFA_advance_loc4:
661 return "DW_CFA_advance_loc4";
662 case DW_CFA_offset_extended:
663 return "DW_CFA_offset_extended";
664 case DW_CFA_restore_extended:
665 return "DW_CFA_restore_extended";
666 case DW_CFA_undefined:
667 return "DW_CFA_undefined";
668 case DW_CFA_same_value:
669 return "DW_CFA_same_value";
670 case DW_CFA_register:
671 return "DW_CFA_register";
672 case DW_CFA_remember_state:
673 return "DW_CFA_remember_state";
674 case DW_CFA_restore_state:
675 return "DW_CFA_restore_state";
677 return "DW_CFA_def_cfa";
678 case DW_CFA_def_cfa_register:
679 return "DW_CFA_def_cfa_register";
680 case DW_CFA_def_cfa_offset:
681 return "DW_CFA_def_cfa_offset";
684 case DW_CFA_def_cfa_expression:
685 return "DW_CFA_def_cfa_expression";
686 case DW_CFA_expression:
687 return "DW_CFA_expression";
688 case DW_CFA_offset_extended_sf:
689 return "DW_CFA_offset_extended_sf";
690 case DW_CFA_def_cfa_sf:
691 return "DW_CFA_def_cfa_sf";
692 case DW_CFA_def_cfa_offset_sf:
693 return "DW_CFA_def_cfa_offset_sf";
695 /* SGI/MIPS specific */
696 case DW_CFA_MIPS_advance_loc8:
697 return "DW_CFA_MIPS_advance_loc8";
700 case DW_CFA_GNU_window_save:
701 return "DW_CFA_GNU_window_save";
702 case DW_CFA_GNU_args_size:
703 return "DW_CFA_GNU_args_size";
704 case DW_CFA_GNU_negative_offset_extended:
705 return "DW_CFA_GNU_negative_offset_extended";
708 return "DW_CFA_<unknown>";
712 /* Return a pointer to a newly allocated Call Frame Instruction. */
714 static inline dw_cfi_ref
717 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
719 cfi->dw_cfi_next = NULL;
720 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
721 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
726 /* Add a Call Frame Instruction to list of instructions. */
729 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
732 dw_fde_ref fde = current_fde ();
734 /* When DRAP is used, CFA is defined with an expression. Redefine
735 CFA may lead to a different CFA value. */
736 /* ??? Of course, this heuristic fails when we're annotating epilogues,
737 because of course we'll always want to redefine the CFA back to the
738 stack pointer on the way out. Where should we move this check? */
739 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
740 switch (cfi->dw_cfi_opc)
742 case DW_CFA_def_cfa_register:
743 case DW_CFA_def_cfa_offset:
744 case DW_CFA_def_cfa_offset_sf:
746 case DW_CFA_def_cfa_sf:
753 /* Find the end of the chain. */
754 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
760 /* Generate a new label for the CFI info to refer to. FORCE is true
761 if a label needs to be output even when using .cfi_* directives. */
764 dwarf2out_cfi_label (bool force)
766 static char label[20];
768 if (!force && dwarf2out_do_cfi_asm ())
770 /* In this case, we will be emitting the asm directive instead of
771 the label, so just return a placeholder to keep the rest of the
773 strcpy (label, "<do not output>");
777 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
778 ASM_OUTPUT_LABEL (asm_out_file, label);
784 /* True if remember_state should be emitted before following CFI directive. */
785 static bool emit_cfa_remember;
787 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
788 or to the CIE if LABEL is NULL. */
791 add_fde_cfi (const char *label, dw_cfi_ref cfi)
793 dw_cfi_ref *list_head;
795 if (emit_cfa_remember)
797 dw_cfi_ref cfi_remember;
799 /* Emit the state save. */
800 emit_cfa_remember = false;
801 cfi_remember = new_cfi ();
802 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
803 add_fde_cfi (label, cfi_remember);
806 list_head = &cie_cfi_head;
808 if (dwarf2out_do_cfi_asm ())
812 dw_fde_ref fde = current_fde ();
814 gcc_assert (fde != NULL);
816 /* We still have to add the cfi to the list so that lookup_cfa
817 works later on. When -g2 and above we even need to force
818 emitting of CFI labels and add to list a DW_CFA_set_loc for
819 convert_cfa_to_fb_loc_list purposes. If we're generating
820 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
821 convert_cfa_to_fb_loc_list. */
822 if (dwarf_version == 2
823 && debug_info_level > DINFO_LEVEL_TERSE
824 && (write_symbols == DWARF2_DEBUG
825 || write_symbols == VMS_AND_DWARF2_DEBUG))
827 switch (cfi->dw_cfi_opc)
829 case DW_CFA_def_cfa_offset:
830 case DW_CFA_def_cfa_offset_sf:
831 case DW_CFA_def_cfa_register:
833 case DW_CFA_def_cfa_sf:
834 case DW_CFA_def_cfa_expression:
835 case DW_CFA_restore_state:
836 if (*label == 0 || strcmp (label, "<do not output>") == 0)
837 label = dwarf2out_cfi_label (true);
839 if (fde->dw_fde_current_label == NULL
840 || strcmp (label, fde->dw_fde_current_label) != 0)
844 label = xstrdup (label);
846 /* Set the location counter to the new label. */
848 /* It doesn't metter whether DW_CFA_set_loc
849 or DW_CFA_advance_loc4 is added here, those aren't
850 emitted into assembly, only looked up by
851 convert_cfa_to_fb_loc_list. */
852 xcfi->dw_cfi_opc = DW_CFA_set_loc;
853 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
854 add_cfi (&fde->dw_fde_cfi, xcfi);
855 fde->dw_fde_current_label = label;
863 output_cfi_directive (cfi);
865 list_head = &fde->dw_fde_cfi;
867 /* ??? If this is a CFI for the CIE, we don't emit. This
868 assumes that the standard CIE contents that the assembler
869 uses matches the standard CIE contents that the compiler
870 uses. This is probably a bad assumption. I'm not quite
871 sure how to address this for now. */
875 dw_fde_ref fde = current_fde ();
877 gcc_assert (fde != NULL);
880 label = dwarf2out_cfi_label (false);
882 if (fde->dw_fde_current_label == NULL
883 || strcmp (label, fde->dw_fde_current_label) != 0)
887 label = xstrdup (label);
889 /* Set the location counter to the new label. */
891 /* If we have a current label, advance from there, otherwise
892 set the location directly using set_loc. */
893 xcfi->dw_cfi_opc = fde->dw_fde_current_label
894 ? DW_CFA_advance_loc4
896 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
897 add_cfi (&fde->dw_fde_cfi, xcfi);
899 fde->dw_fde_current_label = label;
902 list_head = &fde->dw_fde_cfi;
905 add_cfi (list_head, cfi);
908 /* Subroutine of lookup_cfa. */
911 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
913 switch (cfi->dw_cfi_opc)
915 case DW_CFA_def_cfa_offset:
916 case DW_CFA_def_cfa_offset_sf:
917 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
919 case DW_CFA_def_cfa_register:
920 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
923 case DW_CFA_def_cfa_sf:
924 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
925 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
927 case DW_CFA_def_cfa_expression:
928 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
931 case DW_CFA_remember_state:
932 gcc_assert (!remember->in_use);
934 remember->in_use = 1;
936 case DW_CFA_restore_state:
937 gcc_assert (remember->in_use);
939 remember->in_use = 0;
947 /* Find the previous value for the CFA. */
950 lookup_cfa (dw_cfa_location *loc)
954 dw_cfa_location remember;
956 memset (loc, 0, sizeof (*loc));
957 loc->reg = INVALID_REGNUM;
960 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
961 lookup_cfa_1 (cfi, loc, &remember);
963 fde = current_fde ();
965 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
966 lookup_cfa_1 (cfi, loc, &remember);
969 /* The current rule for calculating the DWARF2 canonical frame address. */
970 static dw_cfa_location cfa;
972 /* The register used for saving registers to the stack, and its offset
974 static dw_cfa_location cfa_store;
976 /* The current save location around an epilogue. */
977 static dw_cfa_location cfa_remember;
979 /* The running total of the size of arguments pushed onto the stack. */
980 static HOST_WIDE_INT args_size;
982 /* The last args_size we actually output. */
983 static HOST_WIDE_INT old_args_size;
985 /* Entry point to update the canonical frame address (CFA).
986 LABEL is passed to add_fde_cfi. The value of CFA is now to be
987 calculated from REG+OFFSET. */
990 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
997 def_cfa_1 (label, &loc);
1000 /* Determine if two dw_cfa_location structures define the same data. */
1003 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1005 return (loc1->reg == loc2->reg
1006 && loc1->offset == loc2->offset
1007 && loc1->indirect == loc2->indirect
1008 && (loc1->indirect == 0
1009 || loc1->base_offset == loc2->base_offset));
1012 /* This routine does the actual work. The CFA is now calculated from
1013 the dw_cfa_location structure. */
1016 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1019 dw_cfa_location old_cfa, loc;
1024 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1025 cfa_store.offset = loc.offset;
1027 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1028 lookup_cfa (&old_cfa);
1030 /* If nothing changed, no need to issue any call frame instructions. */
1031 if (cfa_equal_p (&loc, &old_cfa))
1036 if (loc.reg == old_cfa.reg && !loc.indirect)
1038 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1039 the CFA register did not change but the offset did. The data
1040 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1041 in the assembler via the .cfi_def_cfa_offset directive. */
1043 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1045 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1046 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1049 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1050 else if (loc.offset == old_cfa.offset
1051 && old_cfa.reg != INVALID_REGNUM
1054 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1055 indicating the CFA register has changed to <register> but the
1056 offset has not changed. */
1057 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1058 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1062 else if (loc.indirect == 0)
1064 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1065 indicating the CFA register has changed to <register> with
1066 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1067 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1070 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1072 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1073 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1074 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1078 /* Construct a DW_CFA_def_cfa_expression instruction to
1079 calculate the CFA using a full location expression since no
1080 register-offset pair is available. */
1081 struct dw_loc_descr_struct *loc_list;
1083 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1084 loc_list = build_cfa_loc (&loc, 0);
1085 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1088 add_fde_cfi (label, cfi);
1091 /* Add the CFI for saving a register. REG is the CFA column number.
1092 LABEL is passed to add_fde_cfi.
1093 If SREG is -1, the register is saved at OFFSET from the CFA;
1094 otherwise it is saved in SREG. */
1097 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1099 dw_cfi_ref cfi = new_cfi ();
1100 dw_fde_ref fde = current_fde ();
1102 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1104 /* When stack is aligned, store REG using DW_CFA_expression with
1107 && fde->stack_realign
1108 && sreg == INVALID_REGNUM)
1110 cfi->dw_cfi_opc = DW_CFA_expression;
1111 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1112 cfi->dw_cfi_oprnd1.dw_cfi_loc
1113 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1115 else if (sreg == INVALID_REGNUM)
1117 if (need_data_align_sf_opcode (offset))
1118 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1119 else if (reg & ~0x3f)
1120 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1122 cfi->dw_cfi_opc = DW_CFA_offset;
1123 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1125 else if (sreg == reg)
1126 cfi->dw_cfi_opc = DW_CFA_same_value;
1129 cfi->dw_cfi_opc = DW_CFA_register;
1130 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1133 add_fde_cfi (label, cfi);
1136 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1137 This CFI tells the unwinder that it needs to restore the window registers
1138 from the previous frame's window save area.
1140 ??? Perhaps we should note in the CIE where windows are saved (instead of
1141 assuming 0(cfa)) and what registers are in the window. */
1144 dwarf2out_window_save (const char *label)
1146 dw_cfi_ref cfi = new_cfi ();
1148 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1149 add_fde_cfi (label, cfi);
1152 /* Add a CFI to update the running total of the size of arguments
1153 pushed onto the stack. */
1156 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1160 if (size == old_args_size)
1163 old_args_size = size;
1166 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1167 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1168 add_fde_cfi (label, cfi);
1171 /* Entry point for saving a register to the stack. REG is the GCC register
1172 number. LABEL and OFFSET are passed to reg_save. */
1175 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1177 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1180 /* Entry point for saving the return address in the stack.
1181 LABEL and OFFSET are passed to reg_save. */
1184 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1186 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1189 /* Entry point for saving the return address in a register.
1190 LABEL and SREG are passed to reg_save. */
1193 dwarf2out_return_reg (const char *label, unsigned int sreg)
1195 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1198 #ifdef DWARF2_UNWIND_INFO
1199 /* Record the initial position of the return address. RTL is
1200 INCOMING_RETURN_ADDR_RTX. */
1203 initial_return_save (rtx rtl)
1205 unsigned int reg = INVALID_REGNUM;
1206 HOST_WIDE_INT offset = 0;
1208 switch (GET_CODE (rtl))
1211 /* RA is in a register. */
1212 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1216 /* RA is on the stack. */
1217 rtl = XEXP (rtl, 0);
1218 switch (GET_CODE (rtl))
1221 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1226 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1227 offset = INTVAL (XEXP (rtl, 1));
1231 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1232 offset = -INTVAL (XEXP (rtl, 1));
1242 /* The return address is at some offset from any value we can
1243 actually load. For instance, on the SPARC it is in %i7+8. Just
1244 ignore the offset for now; it doesn't matter for unwinding frames. */
1245 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1246 initial_return_save (XEXP (rtl, 0));
1253 if (reg != DWARF_FRAME_RETURN_COLUMN)
1254 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1258 /* Given a SET, calculate the amount of stack adjustment it
1261 static HOST_WIDE_INT
1262 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1263 HOST_WIDE_INT cur_offset)
1265 const_rtx src = SET_SRC (pattern);
1266 const_rtx dest = SET_DEST (pattern);
1267 HOST_WIDE_INT offset = 0;
1270 if (dest == stack_pointer_rtx)
1272 code = GET_CODE (src);
1274 /* Assume (set (reg sp) (reg whatever)) sets args_size
1276 if (code == REG && src != stack_pointer_rtx)
1278 offset = -cur_args_size;
1279 #ifndef STACK_GROWS_DOWNWARD
1282 return offset - cur_offset;
1285 if (! (code == PLUS || code == MINUS)
1286 || XEXP (src, 0) != stack_pointer_rtx
1287 || !CONST_INT_P (XEXP (src, 1)))
1290 /* (set (reg sp) (plus (reg sp) (const_int))) */
1291 offset = INTVAL (XEXP (src, 1));
1297 if (MEM_P (src) && !MEM_P (dest))
1301 /* (set (mem (pre_dec (reg sp))) (foo)) */
1302 src = XEXP (dest, 0);
1303 code = GET_CODE (src);
1309 if (XEXP (src, 0) == stack_pointer_rtx)
1311 rtx val = XEXP (XEXP (src, 1), 1);
1312 /* We handle only adjustments by constant amount. */
1313 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1314 && CONST_INT_P (val));
1315 offset = -INTVAL (val);
1322 if (XEXP (src, 0) == stack_pointer_rtx)
1324 offset = GET_MODE_SIZE (GET_MODE (dest));
1331 if (XEXP (src, 0) == stack_pointer_rtx)
1333 offset = -GET_MODE_SIZE (GET_MODE (dest));
1348 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1349 indexed by INSN_UID. */
1351 static HOST_WIDE_INT *barrier_args_size;
1353 /* Helper function for compute_barrier_args_size. Handle one insn. */
1355 static HOST_WIDE_INT
1356 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1357 VEC (rtx, heap) **next)
1359 HOST_WIDE_INT offset = 0;
1362 if (! RTX_FRAME_RELATED_P (insn))
1364 if (prologue_epilogue_contains (insn))
1366 else if (GET_CODE (PATTERN (insn)) == SET)
1367 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1368 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1369 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1371 /* There may be stack adjustments inside compound insns. Search
1373 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1374 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1375 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1376 cur_args_size, offset);
1381 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1385 expr = XEXP (expr, 0);
1386 if (GET_CODE (expr) == PARALLEL
1387 || GET_CODE (expr) == SEQUENCE)
1388 for (i = 1; i < XVECLEN (expr, 0); i++)
1390 rtx elem = XVECEXP (expr, 0, i);
1392 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1393 offset += stack_adjust_offset (elem, cur_args_size, offset);
1398 #ifndef STACK_GROWS_DOWNWARD
1402 cur_args_size += offset;
1403 if (cur_args_size < 0)
1408 rtx dest = JUMP_LABEL (insn);
1412 if (barrier_args_size [INSN_UID (dest)] < 0)
1414 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1415 VEC_safe_push (rtx, heap, *next, dest);
1420 return cur_args_size;
1423 /* Walk the whole function and compute args_size on BARRIERs. */
1426 compute_barrier_args_size (void)
1428 int max_uid = get_max_uid (), i;
1430 VEC (rtx, heap) *worklist, *next, *tmp;
1432 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1433 for (i = 0; i < max_uid; i++)
1434 barrier_args_size[i] = -1;
1436 worklist = VEC_alloc (rtx, heap, 20);
1437 next = VEC_alloc (rtx, heap, 20);
1438 insn = get_insns ();
1439 barrier_args_size[INSN_UID (insn)] = 0;
1440 VEC_quick_push (rtx, worklist, insn);
1443 while (!VEC_empty (rtx, worklist))
1445 rtx prev, body, first_insn;
1446 HOST_WIDE_INT cur_args_size;
1448 first_insn = insn = VEC_pop (rtx, worklist);
1449 cur_args_size = barrier_args_size[INSN_UID (insn)];
1450 prev = prev_nonnote_insn (insn);
1451 if (prev && BARRIER_P (prev))
1452 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1454 for (; insn; insn = NEXT_INSN (insn))
1456 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1458 if (BARRIER_P (insn))
1463 if (insn == first_insn)
1465 else if (barrier_args_size[INSN_UID (insn)] < 0)
1467 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1472 /* The insns starting with this label have been
1473 already scanned or are in the worklist. */
1478 body = PATTERN (insn);
1479 if (GET_CODE (body) == SEQUENCE)
1481 HOST_WIDE_INT dest_args_size = cur_args_size;
1482 for (i = 1; i < XVECLEN (body, 0); i++)
1483 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1484 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1486 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1487 dest_args_size, &next);
1490 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1491 cur_args_size, &next);
1493 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1494 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1495 dest_args_size, &next);
1498 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1499 cur_args_size, &next);
1503 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1507 if (VEC_empty (rtx, next))
1510 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1514 VEC_truncate (rtx, next, 0);
1517 VEC_free (rtx, heap, worklist);
1518 VEC_free (rtx, heap, next);
1522 /* Check INSN to see if it looks like a push or a stack adjustment, and
1523 make a note of it if it does. EH uses this information to find out how
1524 much extra space it needs to pop off the stack. */
1527 dwarf2out_stack_adjust (rtx insn, bool after_p)
1529 HOST_WIDE_INT offset;
1533 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1534 with this function. Proper support would require all frame-related
1535 insns to be marked, and to be able to handle saving state around
1536 epilogues textually in the middle of the function. */
1537 if (prologue_epilogue_contains (insn))
1540 /* If INSN is an instruction from target of an annulled branch, the
1541 effects are for the target only and so current argument size
1542 shouldn't change at all. */
1544 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1545 && INSN_FROM_TARGET_P (insn))
1548 /* If only calls can throw, and we have a frame pointer,
1549 save up adjustments until we see the CALL_INSN. */
1550 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1552 if (CALL_P (insn) && !after_p)
1554 /* Extract the size of the args from the CALL rtx itself. */
1555 insn = PATTERN (insn);
1556 if (GET_CODE (insn) == PARALLEL)
1557 insn = XVECEXP (insn, 0, 0);
1558 if (GET_CODE (insn) == SET)
1559 insn = SET_SRC (insn);
1560 gcc_assert (GET_CODE (insn) == CALL);
1561 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1566 if (CALL_P (insn) && !after_p)
1568 if (!flag_asynchronous_unwind_tables)
1569 dwarf2out_args_size ("", args_size);
1572 else if (BARRIER_P (insn))
1574 /* Don't call compute_barrier_args_size () if the only
1575 BARRIER is at the end of function. */
1576 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1577 compute_barrier_args_size ();
1578 if (barrier_args_size == NULL)
1582 offset = barrier_args_size[INSN_UID (insn)];
1587 offset -= args_size;
1588 #ifndef STACK_GROWS_DOWNWARD
1592 else if (GET_CODE (PATTERN (insn)) == SET)
1593 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1594 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1595 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1597 /* There may be stack adjustments inside compound insns. Search
1599 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1600 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1601 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1610 label = dwarf2out_cfi_label (false);
1611 dwarf2out_args_size_adjust (offset, label);
1614 /* Adjust args_size based on stack adjustment OFFSET. */
1617 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1619 if (cfa.reg == STACK_POINTER_REGNUM)
1620 cfa.offset += offset;
1622 if (cfa_store.reg == STACK_POINTER_REGNUM)
1623 cfa_store.offset += offset;
1625 #ifndef STACK_GROWS_DOWNWARD
1629 args_size += offset;
1633 def_cfa_1 (label, &cfa);
1634 if (flag_asynchronous_unwind_tables)
1635 dwarf2out_args_size (label, args_size);
1640 /* We delay emitting a register save until either (a) we reach the end
1641 of the prologue or (b) the register is clobbered. This clusters
1642 register saves so that there are fewer pc advances. */
1644 struct GTY(()) queued_reg_save {
1645 struct queued_reg_save *next;
1647 HOST_WIDE_INT cfa_offset;
1651 static GTY(()) struct queued_reg_save *queued_reg_saves;
1653 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1654 struct GTY(()) reg_saved_in_data {
1659 /* A list of registers saved in other registers.
1660 The list intentionally has a small maximum capacity of 4; if your
1661 port needs more than that, you might consider implementing a
1662 more efficient data structure. */
1663 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1664 static GTY(()) size_t num_regs_saved_in_regs;
1666 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1667 static const char *last_reg_save_label;
1669 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1670 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1673 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1675 struct queued_reg_save *q;
1677 /* Duplicates waste space, but it's also necessary to remove them
1678 for correctness, since the queue gets output in reverse
1680 for (q = queued_reg_saves; q != NULL; q = q->next)
1681 if (REGNO (q->reg) == REGNO (reg))
1686 q = GGC_NEW (struct queued_reg_save);
1687 q->next = queued_reg_saves;
1688 queued_reg_saves = q;
1692 q->cfa_offset = offset;
1693 q->saved_reg = sreg;
1695 last_reg_save_label = label;
1698 /* Output all the entries in QUEUED_REG_SAVES. */
1701 flush_queued_reg_saves (void)
1703 struct queued_reg_save *q;
1705 for (q = queued_reg_saves; q; q = q->next)
1708 unsigned int reg, sreg;
1710 for (i = 0; i < num_regs_saved_in_regs; i++)
1711 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1713 if (q->saved_reg && i == num_regs_saved_in_regs)
1715 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1716 num_regs_saved_in_regs++;
1718 if (i != num_regs_saved_in_regs)
1720 regs_saved_in_regs[i].orig_reg = q->reg;
1721 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1724 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1726 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1728 sreg = INVALID_REGNUM;
1729 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1732 queued_reg_saves = NULL;
1733 last_reg_save_label = NULL;
1736 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1737 location for? Or, does it clobber a register which we've previously
1738 said that some other register is saved in, and for which we now
1739 have a new location for? */
1742 clobbers_queued_reg_save (const_rtx insn)
1744 struct queued_reg_save *q;
1746 for (q = queued_reg_saves; q; q = q->next)
1749 if (modified_in_p (q->reg, insn))
1751 for (i = 0; i < num_regs_saved_in_regs; i++)
1752 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1753 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1760 /* Entry point for saving the first register into the second. */
1763 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1766 unsigned int regno, sregno;
1768 for (i = 0; i < num_regs_saved_in_regs; i++)
1769 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1771 if (i == num_regs_saved_in_regs)
1773 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1774 num_regs_saved_in_regs++;
1776 regs_saved_in_regs[i].orig_reg = reg;
1777 regs_saved_in_regs[i].saved_in_reg = sreg;
1779 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1780 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1781 reg_save (label, regno, sregno, 0);
1784 /* What register, if any, is currently saved in REG? */
1787 reg_saved_in (rtx reg)
1789 unsigned int regn = REGNO (reg);
1791 struct queued_reg_save *q;
1793 for (q = queued_reg_saves; q; q = q->next)
1794 if (q->saved_reg && regn == REGNO (q->saved_reg))
1797 for (i = 0; i < num_regs_saved_in_regs; i++)
1798 if (regs_saved_in_regs[i].saved_in_reg
1799 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1800 return regs_saved_in_regs[i].orig_reg;
1806 /* A temporary register holding an integral value used in adjusting SP
1807 or setting up the store_reg. The "offset" field holds the integer
1808 value, not an offset. */
1809 static dw_cfa_location cfa_temp;
1811 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1814 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1816 memset (&cfa, 0, sizeof (cfa));
1818 switch (GET_CODE (pat))
1821 cfa.reg = REGNO (XEXP (pat, 0));
1822 cfa.offset = INTVAL (XEXP (pat, 1));
1826 cfa.reg = REGNO (pat);
1830 /* Recurse and define an expression. */
1834 def_cfa_1 (label, &cfa);
1837 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1840 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1844 gcc_assert (GET_CODE (pat) == SET);
1845 dest = XEXP (pat, 0);
1846 src = XEXP (pat, 1);
1848 switch (GET_CODE (src))
1851 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1852 cfa.offset -= INTVAL (XEXP (src, 1));
1862 cfa.reg = REGNO (dest);
1863 gcc_assert (cfa.indirect == 0);
1865 def_cfa_1 (label, &cfa);
1868 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1871 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1873 HOST_WIDE_INT offset;
1874 rtx src, addr, span;
1876 src = XEXP (set, 1);
1877 addr = XEXP (set, 0);
1878 gcc_assert (MEM_P (addr));
1879 addr = XEXP (addr, 0);
1881 /* As documented, only consider extremely simple addresses. */
1882 switch (GET_CODE (addr))
1885 gcc_assert (REGNO (addr) == cfa.reg);
1886 offset = -cfa.offset;
1889 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1890 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1896 span = targetm.dwarf_register_span (src);
1898 /* ??? We'd like to use queue_reg_save, but we need to come up with
1899 a different flushing heuristic for epilogues. */
1901 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1904 /* We have a PARALLEL describing where the contents of SRC live.
1905 Queue register saves for each piece of the PARALLEL. */
1908 HOST_WIDE_INT span_offset = offset;
1910 gcc_assert (GET_CODE (span) == PARALLEL);
1912 limit = XVECLEN (span, 0);
1913 for (par_index = 0; par_index < limit; par_index++)
1915 rtx elem = XVECEXP (span, 0, par_index);
1917 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1918 INVALID_REGNUM, span_offset);
1919 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1924 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1927 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1930 unsigned sregno, dregno;
1932 src = XEXP (set, 1);
1933 dest = XEXP (set, 0);
1936 sregno = DWARF_FRAME_RETURN_COLUMN;
1938 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1940 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1942 /* ??? We'd like to use queue_reg_save, but we need to come up with
1943 a different flushing heuristic for epilogues. */
1944 reg_save (label, sregno, dregno, 0);
1947 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1950 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1952 dw_cfi_ref cfi = new_cfi ();
1953 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1955 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1956 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1958 add_fde_cfi (label, cfi);
1961 /* Record call frame debugging information for an expression EXPR,
1962 which either sets SP or FP (adjusting how we calculate the frame
1963 address) or saves a register to the stack or another register.
1964 LABEL indicates the address of EXPR.
1966 This function encodes a state machine mapping rtxes to actions on
1967 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1968 users need not read the source code.
1970 The High-Level Picture
1972 Changes in the register we use to calculate the CFA: Currently we
1973 assume that if you copy the CFA register into another register, we
1974 should take the other one as the new CFA register; this seems to
1975 work pretty well. If it's wrong for some target, it's simple
1976 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1978 Changes in the register we use for saving registers to the stack:
1979 This is usually SP, but not always. Again, we deduce that if you
1980 copy SP into another register (and SP is not the CFA register),
1981 then the new register is the one we will be using for register
1982 saves. This also seems to work.
1984 Register saves: There's not much guesswork about this one; if
1985 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1986 register save, and the register used to calculate the destination
1987 had better be the one we think we're using for this purpose.
1988 It's also assumed that a copy from a call-saved register to another
1989 register is saving that register if RTX_FRAME_RELATED_P is set on
1990 that instruction. If the copy is from a call-saved register to
1991 the *same* register, that means that the register is now the same
1992 value as in the caller.
1994 Except: If the register being saved is the CFA register, and the
1995 offset is nonzero, we are saving the CFA, so we assume we have to
1996 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1997 the intent is to save the value of SP from the previous frame.
1999 In addition, if a register has previously been saved to a different
2002 Invariants / Summaries of Rules
2004 cfa current rule for calculating the CFA. It usually
2005 consists of a register and an offset.
2006 cfa_store register used by prologue code to save things to the stack
2007 cfa_store.offset is the offset from the value of
2008 cfa_store.reg to the actual CFA
2009 cfa_temp register holding an integral value. cfa_temp.offset
2010 stores the value, which will be used to adjust the
2011 stack pointer. cfa_temp is also used like cfa_store,
2012 to track stores to the stack via fp or a temp reg.
2014 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2015 with cfa.reg as the first operand changes the cfa.reg and its
2016 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2019 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2020 expression yielding a constant. This sets cfa_temp.reg
2021 and cfa_temp.offset.
2023 Rule 5: Create a new register cfa_store used to save items to the
2026 Rules 10-14: Save a register to the stack. Define offset as the
2027 difference of the original location and cfa_store's
2028 location (or cfa_temp's location if cfa_temp is used).
2030 Rules 16-20: If AND operation happens on sp in prologue, we assume
2031 stack is realigned. We will use a group of DW_OP_XXX
2032 expressions to represent the location of the stored
2033 register instead of CFA+offset.
2037 "{a,b}" indicates a choice of a xor b.
2038 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2041 (set <reg1> <reg2>:cfa.reg)
2042 effects: cfa.reg = <reg1>
2043 cfa.offset unchanged
2044 cfa_temp.reg = <reg1>
2045 cfa_temp.offset = cfa.offset
2048 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2049 {<const_int>,<reg>:cfa_temp.reg}))
2050 effects: cfa.reg = sp if fp used
2051 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2052 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2053 if cfa_store.reg==sp
2056 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2057 effects: cfa.reg = fp
2058 cfa_offset += +/- <const_int>
2061 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2062 constraints: <reg1> != fp
2064 effects: cfa.reg = <reg1>
2065 cfa_temp.reg = <reg1>
2066 cfa_temp.offset = cfa.offset
2069 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2070 constraints: <reg1> != fp
2072 effects: cfa_store.reg = <reg1>
2073 cfa_store.offset = cfa.offset - cfa_temp.offset
2076 (set <reg> <const_int>)
2077 effects: cfa_temp.reg = <reg>
2078 cfa_temp.offset = <const_int>
2081 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2082 effects: cfa_temp.reg = <reg1>
2083 cfa_temp.offset |= <const_int>
2086 (set <reg> (high <exp>))
2090 (set <reg> (lo_sum <exp> <const_int>))
2091 effects: cfa_temp.reg = <reg>
2092 cfa_temp.offset = <const_int>
2095 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2096 effects: cfa_store.offset -= <const_int>
2097 cfa.offset = cfa_store.offset if cfa.reg == sp
2099 cfa.base_offset = -cfa_store.offset
2102 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2103 effects: cfa_store.offset += -/+ mode_size(mem)
2104 cfa.offset = cfa_store.offset if cfa.reg == sp
2106 cfa.base_offset = -cfa_store.offset
2109 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2112 effects: cfa.reg = <reg1>
2113 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2116 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2117 effects: cfa.reg = <reg1>
2118 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2121 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2122 effects: cfa.reg = <reg1>
2123 cfa.base_offset = -cfa_temp.offset
2124 cfa_temp.offset -= mode_size(mem)
2127 (set <reg> {unspec, unspec_volatile})
2128 effects: target-dependent
2131 (set sp (and: sp <const_int>))
2132 constraints: cfa_store.reg == sp
2133 effects: current_fde.stack_realign = 1
2134 cfa_store.offset = 0
2135 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2138 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2139 effects: cfa_store.offset += -/+ mode_size(mem)
2142 (set (mem ({pre_inc, pre_dec} sp)) fp)
2143 constraints: fde->stack_realign == 1
2144 effects: cfa_store.offset = 0
2145 cfa.reg != HARD_FRAME_POINTER_REGNUM
2148 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2149 constraints: fde->stack_realign == 1
2151 && cfa.indirect == 0
2152 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2153 effects: Use DW_CFA_def_cfa_expression to define cfa
2154 cfa.reg == fde->drap_reg
2157 (set reg fde->drap_reg)
2158 constraints: fde->vdrap_reg == INVALID_REGNUM
2159 effects: fde->vdrap_reg = reg.
2160 (set mem fde->drap_reg)
2161 constraints: fde->drap_reg_saved == 1
2165 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2167 rtx src, dest, span;
2168 HOST_WIDE_INT offset;
2171 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2172 the PARALLEL independently. The first element is always processed if
2173 it is a SET. This is for backward compatibility. Other elements
2174 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2175 flag is set in them. */
2176 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2179 int limit = XVECLEN (expr, 0);
2182 /* PARALLELs have strict read-modify-write semantics, so we
2183 ought to evaluate every rvalue before changing any lvalue.
2184 It's cumbersome to do that in general, but there's an
2185 easy approximation that is enough for all current users:
2186 handle register saves before register assignments. */
2187 if (GET_CODE (expr) == PARALLEL)
2188 for (par_index = 0; par_index < limit; par_index++)
2190 elem = XVECEXP (expr, 0, par_index);
2191 if (GET_CODE (elem) == SET
2192 && MEM_P (SET_DEST (elem))
2193 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2194 dwarf2out_frame_debug_expr (elem, label);
2197 for (par_index = 0; par_index < limit; par_index++)
2199 elem = XVECEXP (expr, 0, par_index);
2200 if (GET_CODE (elem) == SET
2201 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2202 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2203 dwarf2out_frame_debug_expr (elem, label);
2204 else if (GET_CODE (elem) == SET
2206 && !RTX_FRAME_RELATED_P (elem))
2208 /* Stack adjustment combining might combine some post-prologue
2209 stack adjustment into a prologue stack adjustment. */
2210 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2213 dwarf2out_args_size_adjust (offset, label);
2219 gcc_assert (GET_CODE (expr) == SET);
2221 src = SET_SRC (expr);
2222 dest = SET_DEST (expr);
2226 rtx rsi = reg_saved_in (src);
2231 fde = current_fde ();
2235 && fde->drap_reg == REGNO (src)
2236 && (fde->drap_reg_saved
2240 /* If we are saving dynamic realign argument pointer to a
2241 register, the destination is virtual dynamic realign
2242 argument pointer. It may be used to access argument. */
2245 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2246 fde->vdrap_reg = REGNO (dest);
2251 switch (GET_CODE (dest))
2254 switch (GET_CODE (src))
2256 /* Setting FP from SP. */
2258 if (cfa.reg == (unsigned) REGNO (src))
2261 /* Update the CFA rule wrt SP or FP. Make sure src is
2262 relative to the current CFA register.
2264 We used to require that dest be either SP or FP, but the
2265 ARM copies SP to a temporary register, and from there to
2266 FP. So we just rely on the backends to only set
2267 RTX_FRAME_RELATED_P on appropriate insns. */
2268 cfa.reg = REGNO (dest);
2269 cfa_temp.reg = cfa.reg;
2270 cfa_temp.offset = cfa.offset;
2274 /* Saving a register in a register. */
2275 gcc_assert (!fixed_regs [REGNO (dest)]
2276 /* For the SPARC and its register window. */
2277 || (DWARF_FRAME_REGNUM (REGNO (src))
2278 == DWARF_FRAME_RETURN_COLUMN));
2280 /* After stack is aligned, we can only save SP in FP
2281 if drap register is used. In this case, we have
2282 to restore stack pointer with the CFA value and we
2283 don't generate this DWARF information. */
2285 && fde->stack_realign
2286 && REGNO (src) == STACK_POINTER_REGNUM)
2287 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2288 && fde->drap_reg != INVALID_REGNUM
2289 && cfa.reg != REGNO (src));
2291 queue_reg_save (label, src, dest, 0);
2298 if (dest == stack_pointer_rtx)
2302 switch (GET_CODE (XEXP (src, 1)))
2305 offset = INTVAL (XEXP (src, 1));
2308 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2310 offset = cfa_temp.offset;
2316 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2318 /* Restoring SP from FP in the epilogue. */
2319 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2320 cfa.reg = STACK_POINTER_REGNUM;
2322 else if (GET_CODE (src) == LO_SUM)
2323 /* Assume we've set the source reg of the LO_SUM from sp. */
2326 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2328 if (GET_CODE (src) != MINUS)
2330 if (cfa.reg == STACK_POINTER_REGNUM)
2331 cfa.offset += offset;
2332 if (cfa_store.reg == STACK_POINTER_REGNUM)
2333 cfa_store.offset += offset;
2335 else if (dest == hard_frame_pointer_rtx)
2338 /* Either setting the FP from an offset of the SP,
2339 or adjusting the FP */
2340 gcc_assert (frame_pointer_needed);
2342 gcc_assert (REG_P (XEXP (src, 0))
2343 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2344 && CONST_INT_P (XEXP (src, 1)));
2345 offset = INTVAL (XEXP (src, 1));
2346 if (GET_CODE (src) != MINUS)
2348 cfa.offset += offset;
2349 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2353 gcc_assert (GET_CODE (src) != MINUS);
2356 if (REG_P (XEXP (src, 0))
2357 && REGNO (XEXP (src, 0)) == cfa.reg
2358 && CONST_INT_P (XEXP (src, 1)))
2360 /* Setting a temporary CFA register that will be copied
2361 into the FP later on. */
2362 offset = - INTVAL (XEXP (src, 1));
2363 cfa.offset += offset;
2364 cfa.reg = REGNO (dest);
2365 /* Or used to save regs to the stack. */
2366 cfa_temp.reg = cfa.reg;
2367 cfa_temp.offset = cfa.offset;
2371 else if (REG_P (XEXP (src, 0))
2372 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2373 && XEXP (src, 1) == stack_pointer_rtx)
2375 /* Setting a scratch register that we will use instead
2376 of SP for saving registers to the stack. */
2377 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2378 cfa_store.reg = REGNO (dest);
2379 cfa_store.offset = cfa.offset - cfa_temp.offset;
2383 else if (GET_CODE (src) == LO_SUM
2384 && CONST_INT_P (XEXP (src, 1)))
2386 cfa_temp.reg = REGNO (dest);
2387 cfa_temp.offset = INTVAL (XEXP (src, 1));
2396 cfa_temp.reg = REGNO (dest);
2397 cfa_temp.offset = INTVAL (src);
2402 gcc_assert (REG_P (XEXP (src, 0))
2403 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2404 && CONST_INT_P (XEXP (src, 1)));
2406 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2407 cfa_temp.reg = REGNO (dest);
2408 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2411 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2412 which will fill in all of the bits. */
2419 case UNSPEC_VOLATILE:
2420 gcc_assert (targetm.dwarf_handle_frame_unspec);
2421 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2426 /* If this AND operation happens on stack pointer in prologue,
2427 we assume the stack is realigned and we extract the
2429 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2431 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2432 fde->stack_realign = 1;
2433 fde->stack_realignment = INTVAL (XEXP (src, 1));
2434 cfa_store.offset = 0;
2436 if (cfa.reg != STACK_POINTER_REGNUM
2437 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2438 fde->drap_reg = cfa.reg;
2446 def_cfa_1 (label, &cfa);
2451 /* Saving a register to the stack. Make sure dest is relative to the
2453 switch (GET_CODE (XEXP (dest, 0)))
2458 /* We can't handle variable size modifications. */
2459 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2461 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2463 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2464 && cfa_store.reg == STACK_POINTER_REGNUM);
2466 cfa_store.offset += offset;
2467 if (cfa.reg == STACK_POINTER_REGNUM)
2468 cfa.offset = cfa_store.offset;
2470 offset = -cfa_store.offset;
2476 offset = GET_MODE_SIZE (GET_MODE (dest));
2477 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2480 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2481 == STACK_POINTER_REGNUM)
2482 && cfa_store.reg == STACK_POINTER_REGNUM);
2484 cfa_store.offset += offset;
2486 /* Rule 18: If stack is aligned, we will use FP as a
2487 reference to represent the address of the stored
2490 && fde->stack_realign
2491 && src == hard_frame_pointer_rtx)
2493 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2494 cfa_store.offset = 0;
2497 if (cfa.reg == STACK_POINTER_REGNUM)
2498 cfa.offset = cfa_store.offset;
2500 offset = -cfa_store.offset;
2504 /* With an offset. */
2511 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2512 && REG_P (XEXP (XEXP (dest, 0), 0)));
2513 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2514 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2517 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2519 if (cfa_store.reg == (unsigned) regno)
2520 offset -= cfa_store.offset;
2523 gcc_assert (cfa_temp.reg == (unsigned) regno);
2524 offset -= cfa_temp.offset;
2530 /* Without an offset. */
2533 int regno = REGNO (XEXP (dest, 0));
2535 if (cfa_store.reg == (unsigned) regno)
2536 offset = -cfa_store.offset;
2539 gcc_assert (cfa_temp.reg == (unsigned) regno);
2540 offset = -cfa_temp.offset;
2547 gcc_assert (cfa_temp.reg
2548 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2549 offset = -cfa_temp.offset;
2550 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2558 /* If the source operand of this MEM operation is not a
2559 register, basically the source is return address. Here
2560 we only care how much stack grew and we don't save it. */
2564 if (REGNO (src) != STACK_POINTER_REGNUM
2565 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2566 && (unsigned) REGNO (src) == cfa.reg)
2568 /* We're storing the current CFA reg into the stack. */
2570 if (cfa.offset == 0)
2573 /* If stack is aligned, putting CFA reg into stack means
2574 we can no longer use reg + offset to represent CFA.
2575 Here we use DW_CFA_def_cfa_expression instead. The
2576 result of this expression equals to the original CFA
2579 && fde->stack_realign
2580 && cfa.indirect == 0
2581 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2583 dw_cfa_location cfa_exp;
2585 gcc_assert (fde->drap_reg == cfa.reg);
2587 cfa_exp.indirect = 1;
2588 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2589 cfa_exp.base_offset = offset;
2592 fde->drap_reg_saved = 1;
2594 def_cfa_1 (label, &cfa_exp);
2598 /* If the source register is exactly the CFA, assume
2599 we're saving SP like any other register; this happens
2601 def_cfa_1 (label, &cfa);
2602 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2607 /* Otherwise, we'll need to look in the stack to
2608 calculate the CFA. */
2609 rtx x = XEXP (dest, 0);
2613 gcc_assert (REG_P (x));
2615 cfa.reg = REGNO (x);
2616 cfa.base_offset = offset;
2618 def_cfa_1 (label, &cfa);
2623 def_cfa_1 (label, &cfa);
2625 span = targetm.dwarf_register_span (src);
2628 queue_reg_save (label, src, NULL_RTX, offset);
2631 /* We have a PARALLEL describing where the contents of SRC
2632 live. Queue register saves for each piece of the
2636 HOST_WIDE_INT span_offset = offset;
2638 gcc_assert (GET_CODE (span) == PARALLEL);
2640 limit = XVECLEN (span, 0);
2641 for (par_index = 0; par_index < limit; par_index++)
2643 rtx elem = XVECEXP (span, 0, par_index);
2645 queue_reg_save (label, elem, NULL_RTX, span_offset);
2646 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2657 /* Record call frame debugging information for INSN, which either
2658 sets SP or FP (adjusting how we calculate the frame address) or saves a
2659 register to the stack. If INSN is NULL_RTX, initialize our state.
2661 If AFTER_P is false, we're being called before the insn is emitted,
2662 otherwise after. Call instructions get invoked twice. */
2665 dwarf2out_frame_debug (rtx insn, bool after_p)
2669 bool handled_one = false;
2671 if (insn == NULL_RTX)
2675 /* Flush any queued register saves. */
2676 flush_queued_reg_saves ();
2678 /* Set up state for generating call frame debug info. */
2681 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2683 cfa.reg = STACK_POINTER_REGNUM;
2686 cfa_temp.offset = 0;
2688 for (i = 0; i < num_regs_saved_in_regs; i++)
2690 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2691 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2693 num_regs_saved_in_regs = 0;
2695 if (barrier_args_size)
2697 XDELETEVEC (barrier_args_size);
2698 barrier_args_size = NULL;
2703 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2704 flush_queued_reg_saves ();
2706 if (! RTX_FRAME_RELATED_P (insn))
2708 if (!ACCUMULATE_OUTGOING_ARGS)
2709 dwarf2out_stack_adjust (insn, after_p);
2713 label = dwarf2out_cfi_label (false);
2715 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2716 switch (REG_NOTE_KIND (note))
2718 case REG_FRAME_RELATED_EXPR:
2719 insn = XEXP (note, 0);
2722 case REG_CFA_DEF_CFA:
2723 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2727 case REG_CFA_ADJUST_CFA:
2732 if (GET_CODE (n) == PARALLEL)
2733 n = XVECEXP (n, 0, 0);
2735 dwarf2out_frame_debug_adjust_cfa (n, label);
2739 case REG_CFA_OFFSET:
2742 n = single_set (insn);
2743 dwarf2out_frame_debug_cfa_offset (n, label);
2747 case REG_CFA_REGISTER:
2752 if (GET_CODE (n) == PARALLEL)
2753 n = XVECEXP (n, 0, 0);
2755 dwarf2out_frame_debug_cfa_register (n, label);
2759 case REG_CFA_RESTORE:
2764 if (GET_CODE (n) == PARALLEL)
2765 n = XVECEXP (n, 0, 0);
2768 dwarf2out_frame_debug_cfa_restore (n, label);
2778 insn = PATTERN (insn);
2780 dwarf2out_frame_debug_expr (insn, label);
2783 /* Determine if we need to save and restore CFI information around this
2784 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2785 we do need to save/restore, then emit the save now, and insert a
2786 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2789 dwarf2out_begin_epilogue (rtx insn)
2791 bool saw_frp = false;
2794 /* Scan forward to the return insn, noticing if there are possible
2795 frame related insns. */
2796 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2801 /* Look for both regular and sibcalls to end the block. */
2802 if (returnjump_p (i))
2804 if (CALL_P (i) && SIBLING_CALL_P (i))
2807 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2810 rtx seq = PATTERN (i);
2812 if (returnjump_p (XVECEXP (seq, 0, 0)))
2814 if (CALL_P (XVECEXP (seq, 0, 0))
2815 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2818 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2819 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2823 if (RTX_FRAME_RELATED_P (i))
2827 /* If the port doesn't emit epilogue unwind info, we don't need a
2828 save/restore pair. */
2832 /* Otherwise, search forward to see if the return insn was the last
2833 basic block of the function. If so, we don't need save/restore. */
2834 gcc_assert (i != NULL);
2835 i = next_real_insn (i);
2839 /* Insert the restore before that next real insn in the stream, and before
2840 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2841 properly nested. This should be after any label or alignment. This
2842 will be pushed into the CFI stream by the function below. */
2845 rtx p = PREV_INSN (i);
2848 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2852 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2854 emit_cfa_remember = true;
2856 /* And emulate the state save. */
2857 gcc_assert (!cfa_remember.in_use);
2859 cfa_remember.in_use = 1;
2862 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2865 dwarf2out_frame_debug_restore_state (void)
2867 dw_cfi_ref cfi = new_cfi ();
2868 const char *label = dwarf2out_cfi_label (false);
2870 cfi->dw_cfi_opc = DW_CFA_restore_state;
2871 add_fde_cfi (label, cfi);
2873 gcc_assert (cfa_remember.in_use);
2875 cfa_remember.in_use = 0;
2880 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2881 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2882 (enum dwarf_call_frame_info cfi);
2884 static enum dw_cfi_oprnd_type
2885 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2890 case DW_CFA_GNU_window_save:
2891 case DW_CFA_remember_state:
2892 case DW_CFA_restore_state:
2893 return dw_cfi_oprnd_unused;
2895 case DW_CFA_set_loc:
2896 case DW_CFA_advance_loc1:
2897 case DW_CFA_advance_loc2:
2898 case DW_CFA_advance_loc4:
2899 case DW_CFA_MIPS_advance_loc8:
2900 return dw_cfi_oprnd_addr;
2903 case DW_CFA_offset_extended:
2904 case DW_CFA_def_cfa:
2905 case DW_CFA_offset_extended_sf:
2906 case DW_CFA_def_cfa_sf:
2907 case DW_CFA_restore:
2908 case DW_CFA_restore_extended:
2909 case DW_CFA_undefined:
2910 case DW_CFA_same_value:
2911 case DW_CFA_def_cfa_register:
2912 case DW_CFA_register:
2913 return dw_cfi_oprnd_reg_num;
2915 case DW_CFA_def_cfa_offset:
2916 case DW_CFA_GNU_args_size:
2917 case DW_CFA_def_cfa_offset_sf:
2918 return dw_cfi_oprnd_offset;
2920 case DW_CFA_def_cfa_expression:
2921 case DW_CFA_expression:
2922 return dw_cfi_oprnd_loc;
2929 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2930 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2931 (enum dwarf_call_frame_info cfi);
2933 static enum dw_cfi_oprnd_type
2934 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2938 case DW_CFA_def_cfa:
2939 case DW_CFA_def_cfa_sf:
2941 case DW_CFA_offset_extended_sf:
2942 case DW_CFA_offset_extended:
2943 return dw_cfi_oprnd_offset;
2945 case DW_CFA_register:
2946 return dw_cfi_oprnd_reg_num;
2949 return dw_cfi_oprnd_unused;
2953 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2955 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2956 switch to the data section instead, and write out a synthetic start label
2957 for collect2 the first time around. */
2960 switch_to_eh_frame_section (bool back)
2964 #ifdef EH_FRAME_SECTION_NAME
2965 if (eh_frame_section == 0)
2969 if (EH_TABLES_CAN_BE_READ_ONLY)
2975 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2977 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2979 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2981 flags = ((! flag_pic
2982 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2983 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2984 && (per_encoding & 0x70) != DW_EH_PE_absptr
2985 && (per_encoding & 0x70) != DW_EH_PE_aligned
2986 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2987 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2988 ? 0 : SECTION_WRITE);
2991 flags = SECTION_WRITE;
2992 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2996 if (eh_frame_section)
2997 switch_to_section (eh_frame_section);
3000 /* We have no special eh_frame section. Put the information in
3001 the data section and emit special labels to guide collect2. */
3002 switch_to_section (data_section);
3006 label = get_file_function_name ("F");
3007 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3008 targetm.asm_out.globalize_label (asm_out_file,
3009 IDENTIFIER_POINTER (label));
3010 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3015 /* Switch [BACK] to the eh or debug frame table section, depending on
3019 switch_to_frame_table_section (int for_eh, bool back)
3022 switch_to_eh_frame_section (back);
3025 if (!debug_frame_section)
3026 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3027 SECTION_DEBUG, NULL);
3028 switch_to_section (debug_frame_section);
3032 /* Output a Call Frame Information opcode and its operand(s). */
3035 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3040 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3041 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3042 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3043 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3044 ((unsigned HOST_WIDE_INT)
3045 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3046 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3048 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3049 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3050 "DW_CFA_offset, column 0x%lx", r);
3051 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3052 dw2_asm_output_data_uleb128 (off, NULL);
3054 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3056 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3057 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3058 "DW_CFA_restore, column 0x%lx", r);
3062 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3063 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3065 switch (cfi->dw_cfi_opc)
3067 case DW_CFA_set_loc:
3069 dw2_asm_output_encoded_addr_rtx (
3070 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3071 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3074 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3075 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3076 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3079 case DW_CFA_advance_loc1:
3080 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3081 fde->dw_fde_current_label, NULL);
3082 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3085 case DW_CFA_advance_loc2:
3086 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3087 fde->dw_fde_current_label, NULL);
3088 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3091 case DW_CFA_advance_loc4:
3092 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3093 fde->dw_fde_current_label, NULL);
3094 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3097 case DW_CFA_MIPS_advance_loc8:
3098 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3099 fde->dw_fde_current_label, NULL);
3100 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3103 case DW_CFA_offset_extended:
3104 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3105 dw2_asm_output_data_uleb128 (r, NULL);
3106 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3107 dw2_asm_output_data_uleb128 (off, NULL);
3110 case DW_CFA_def_cfa:
3111 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3112 dw2_asm_output_data_uleb128 (r, NULL);
3113 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3116 case DW_CFA_offset_extended_sf:
3117 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3118 dw2_asm_output_data_uleb128 (r, NULL);
3119 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3120 dw2_asm_output_data_sleb128 (off, NULL);
3123 case DW_CFA_def_cfa_sf:
3124 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3125 dw2_asm_output_data_uleb128 (r, NULL);
3126 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3127 dw2_asm_output_data_sleb128 (off, NULL);
3130 case DW_CFA_restore_extended:
3131 case DW_CFA_undefined:
3132 case DW_CFA_same_value:
3133 case DW_CFA_def_cfa_register:
3134 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3135 dw2_asm_output_data_uleb128 (r, NULL);
3138 case DW_CFA_register:
3139 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3140 dw2_asm_output_data_uleb128 (r, NULL);
3141 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3142 dw2_asm_output_data_uleb128 (r, NULL);
3145 case DW_CFA_def_cfa_offset:
3146 case DW_CFA_GNU_args_size:
3147 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3150 case DW_CFA_def_cfa_offset_sf:
3151 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3152 dw2_asm_output_data_sleb128 (off, NULL);
3155 case DW_CFA_GNU_window_save:
3158 case DW_CFA_def_cfa_expression:
3159 case DW_CFA_expression:
3160 output_cfa_loc (cfi);
3163 case DW_CFA_GNU_negative_offset_extended:
3164 /* Obsoleted by DW_CFA_offset_extended_sf. */
3173 /* Similar, but do it via assembler directives instead. */
3176 output_cfi_directive (dw_cfi_ref cfi)
3178 unsigned long r, r2;
3180 switch (cfi->dw_cfi_opc)
3182 case DW_CFA_advance_loc:
3183 case DW_CFA_advance_loc1:
3184 case DW_CFA_advance_loc2:
3185 case DW_CFA_advance_loc4:
3186 case DW_CFA_MIPS_advance_loc8:
3187 case DW_CFA_set_loc:
3188 /* Should only be created by add_fde_cfi in a code path not
3189 followed when emitting via directives. The assembler is
3190 going to take care of this for us. */
3194 case DW_CFA_offset_extended:
3195 case DW_CFA_offset_extended_sf:
3196 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3197 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3198 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3201 case DW_CFA_restore:
3202 case DW_CFA_restore_extended:
3203 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3204 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3207 case DW_CFA_undefined:
3208 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3209 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3212 case DW_CFA_same_value:
3213 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3214 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3217 case DW_CFA_def_cfa:
3218 case DW_CFA_def_cfa_sf:
3219 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3220 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3221 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3224 case DW_CFA_def_cfa_register:
3225 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3226 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3229 case DW_CFA_register:
3230 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3231 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3232 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3235 case DW_CFA_def_cfa_offset:
3236 case DW_CFA_def_cfa_offset_sf:
3237 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3238 HOST_WIDE_INT_PRINT_DEC"\n",
3239 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3242 case DW_CFA_remember_state:
3243 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3245 case DW_CFA_restore_state:
3246 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3249 case DW_CFA_GNU_args_size:
3250 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3251 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3253 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3254 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3255 fputc ('\n', asm_out_file);
3258 case DW_CFA_GNU_window_save:
3259 fprintf (asm_out_file, "\t.cfi_window_save\n");
3262 case DW_CFA_def_cfa_expression:
3263 case DW_CFA_expression:
3264 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3265 output_cfa_loc_raw (cfi);
3266 fputc ('\n', asm_out_file);
3274 DEF_VEC_P (dw_cfi_ref);
3275 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3277 /* Output CFIs to bring current FDE to the same state as after executing
3278 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3279 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3280 other arguments to pass to output_cfi. */
3283 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3285 struct dw_cfi_struct cfi_buf;
3287 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3288 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3289 unsigned int len, idx;
3291 for (;; cfi = cfi->dw_cfi_next)
3292 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3294 case DW_CFA_advance_loc:
3295 case DW_CFA_advance_loc1:
3296 case DW_CFA_advance_loc2:
3297 case DW_CFA_advance_loc4:
3298 case DW_CFA_MIPS_advance_loc8:
3299 case DW_CFA_set_loc:
3300 /* All advances should be ignored. */
3302 case DW_CFA_remember_state:
3304 dw_cfi_ref args_size = cfi_args_size;
3306 /* Skip everything between .cfi_remember_state and
3307 .cfi_restore_state. */
3308 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3309 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3311 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3314 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3321 cfi_args_size = args_size;
3325 case DW_CFA_GNU_args_size:
3326 cfi_args_size = cfi;
3328 case DW_CFA_GNU_window_save:
3331 case DW_CFA_offset_extended:
3332 case DW_CFA_offset_extended_sf:
3333 case DW_CFA_restore:
3334 case DW_CFA_restore_extended:
3335 case DW_CFA_undefined:
3336 case DW_CFA_same_value:
3337 case DW_CFA_register:
3338 case DW_CFA_val_offset:
3339 case DW_CFA_val_offset_sf:
3340 case DW_CFA_expression:
3341 case DW_CFA_val_expression:
3342 case DW_CFA_GNU_negative_offset_extended:
3343 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3344 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3345 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3346 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3348 case DW_CFA_def_cfa:
3349 case DW_CFA_def_cfa_sf:
3350 case DW_CFA_def_cfa_expression:
3352 cfi_cfa_offset = cfi;
3354 case DW_CFA_def_cfa_register:
3357 case DW_CFA_def_cfa_offset:
3358 case DW_CFA_def_cfa_offset_sf:
3359 cfi_cfa_offset = cfi;
3362 gcc_assert (cfi == NULL);
3364 len = VEC_length (dw_cfi_ref, regs);
3365 for (idx = 0; idx < len; idx++)
3367 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3369 && cfi2->dw_cfi_opc != DW_CFA_restore
3370 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3373 output_cfi_directive (cfi2);
3375 output_cfi (cfi2, fde, for_eh);
3378 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3380 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3382 switch (cfi_cfa_offset->dw_cfi_opc)
3384 case DW_CFA_def_cfa_offset:
3385 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3386 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3388 case DW_CFA_def_cfa_offset_sf:
3389 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3390 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3392 case DW_CFA_def_cfa:
3393 case DW_CFA_def_cfa_sf:
3394 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3395 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3402 else if (cfi_cfa_offset)
3403 cfi_cfa = cfi_cfa_offset;
3407 output_cfi_directive (cfi_cfa);
3409 output_cfi (cfi_cfa, fde, for_eh);
3412 cfi_cfa_offset = NULL;
3414 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3417 output_cfi_directive (cfi_args_size);
3419 output_cfi (cfi_args_size, fde, for_eh);
3421 cfi_args_size = NULL;
3424 VEC_free (dw_cfi_ref, heap, regs);
3427 else if (do_cfi_asm)
3428 output_cfi_directive (cfi);
3430 output_cfi (cfi, fde, for_eh);
3437 /* Output one FDE. */
3440 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3441 char *section_start_label, int fde_encoding, char *augmentation,
3442 bool any_lsda_needed, int lsda_encoding)
3444 const char *begin, *end;
3445 static unsigned int j;
3446 char l1[20], l2[20];
3449 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3451 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3453 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3454 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3455 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3456 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3457 " indicating 64-bit DWARF extension");
3458 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3460 ASM_OUTPUT_LABEL (asm_out_file, l1);
3463 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3465 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3466 debug_frame_section, "FDE CIE offset");
3468 if (!fde->dw_fde_switched_sections)
3470 begin = fde->dw_fde_begin;
3471 end = fde->dw_fde_end;
3475 /* For the first section, prefer dw_fde_begin over
3476 dw_fde_{hot,cold}_section_label, as the latter
3477 might be separated from the real start of the
3478 function by alignment padding. */
3480 begin = fde->dw_fde_begin;
3481 else if (fde->dw_fde_switched_cold_to_hot)
3482 begin = fde->dw_fde_hot_section_label;
3484 begin = fde->dw_fde_unlikely_section_label;
3485 if (second ^ fde->dw_fde_switched_cold_to_hot)
3486 end = fde->dw_fde_unlikely_section_end_label;
3488 end = fde->dw_fde_hot_section_end_label;
3493 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3494 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3495 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3496 "FDE initial location");
3497 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3498 end, begin, "FDE address range");
3502 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3503 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3506 if (augmentation[0])
3508 if (any_lsda_needed)
3510 int size = size_of_encoded_value (lsda_encoding);
3512 if (lsda_encoding == DW_EH_PE_aligned)
3514 int offset = ( 4 /* Length */
3515 + 4 /* CIE offset */
3516 + 2 * size_of_encoded_value (fde_encoding)
3517 + 1 /* Augmentation size */ );
3518 int pad = -offset & (PTR_SIZE - 1);
3521 gcc_assert (size_of_uleb128 (size) == 1);
3524 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3526 if (fde->uses_eh_lsda)
3528 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3529 fde->funcdef_number);
3530 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3531 gen_rtx_SYMBOL_REF (Pmode, l1),
3533 "Language Specific Data Area");
3537 if (lsda_encoding == DW_EH_PE_aligned)
3538 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3539 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3540 "Language Specific Data Area (none)");
3544 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3547 /* Loop through the Call Frame Instructions associated with
3549 fde->dw_fde_current_label = begin;
3550 if (!fde->dw_fde_switched_sections)
3551 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3552 output_cfi (cfi, fde, for_eh);
3555 if (fde->dw_fde_switch_cfi)
3556 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3558 output_cfi (cfi, fde, for_eh);
3559 if (cfi == fde->dw_fde_switch_cfi)
3565 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3567 if (fde->dw_fde_switch_cfi)
3569 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3570 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3571 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3572 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3574 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3575 output_cfi (cfi, fde, for_eh);
3578 /* If we are to emit a ref/link from function bodies to their frame tables,
3579 do it now. This is typically performed to make sure that tables
3580 associated with functions are dragged with them and not discarded in
3581 garbage collecting links. We need to do this on a per function basis to
3582 cope with -ffunction-sections. */
3584 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3585 /* Switch to the function section, emit the ref to the tables, and
3586 switch *back* into the table section. */
3587 switch_to_section (function_section (fde->decl));
3588 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3589 switch_to_frame_table_section (for_eh, true);
3592 /* Pad the FDE out to an address sized boundary. */
3593 ASM_OUTPUT_ALIGN (asm_out_file,
3594 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3595 ASM_OUTPUT_LABEL (asm_out_file, l2);
3600 /* Output the call frame information used to record information
3601 that relates to calculating the frame pointer, and records the
3602 location of saved registers. */
3605 output_call_frame_info (int for_eh)
3610 char l1[20], l2[20], section_start_label[20];
3611 bool any_lsda_needed = false;
3612 char augmentation[6];
3613 int augmentation_size;
3614 int fde_encoding = DW_EH_PE_absptr;
3615 int per_encoding = DW_EH_PE_absptr;
3616 int lsda_encoding = DW_EH_PE_absptr;
3618 rtx personality = NULL;
3621 /* Don't emit a CIE if there won't be any FDEs. */
3622 if (fde_table_in_use == 0)
3625 /* Nothing to do if the assembler's doing it all. */
3626 if (dwarf2out_do_cfi_asm ())
3629 /* If we make FDEs linkonce, we may have to emit an empty label for
3630 an FDE that wouldn't otherwise be emitted. We want to avoid
3631 having an FDE kept around when the function it refers to is
3632 discarded. Example where this matters: a primary function
3633 template in C++ requires EH information, but an explicit
3634 specialization doesn't. */
3635 if (TARGET_USES_WEAK_UNWIND_INFO
3636 && ! flag_asynchronous_unwind_tables
3639 for (i = 0; i < fde_table_in_use; i++)
3640 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3641 && !fde_table[i].uses_eh_lsda
3642 && ! DECL_WEAK (fde_table[i].decl))
3643 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3644 for_eh, /* empty */ 1);
3646 /* If we don't have any functions we'll want to unwind out of, don't
3647 emit any EH unwind information. Note that if exceptions aren't
3648 enabled, we won't have collected nothrow information, and if we
3649 asked for asynchronous tables, we always want this info. */
3652 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3654 for (i = 0; i < fde_table_in_use; i++)
3655 if (fde_table[i].uses_eh_lsda)
3656 any_eh_needed = any_lsda_needed = true;
3657 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3658 any_eh_needed = true;
3659 else if (! fde_table[i].nothrow
3660 && ! fde_table[i].all_throwers_are_sibcalls)
3661 any_eh_needed = true;
3663 if (! any_eh_needed)
3667 /* We're going to be generating comments, so turn on app. */
3671 /* Switch to the proper frame section, first time. */
3672 switch_to_frame_table_section (for_eh, false);
3674 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3675 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3677 /* Output the CIE. */
3678 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3679 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3680 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3681 dw2_asm_output_data (4, 0xffffffff,
3682 "Initial length escape value indicating 64-bit DWARF extension");
3683 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3684 "Length of Common Information Entry");
3685 ASM_OUTPUT_LABEL (asm_out_file, l1);
3687 /* Now that the CIE pointer is PC-relative for EH,
3688 use 0 to identify the CIE. */
3689 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3690 (for_eh ? 0 : DWARF_CIE_ID),
3691 "CIE Identifier Tag");
3693 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3694 use CIE version 1, unless that would produce incorrect results
3695 due to overflowing the return register column. */
3696 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3698 if (return_reg >= 256 || dwarf_version > 2)
3700 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3702 augmentation[0] = 0;
3703 augmentation_size = 0;
3705 personality = current_unit_personality;
3711 z Indicates that a uleb128 is present to size the
3712 augmentation section.
3713 L Indicates the encoding (and thus presence) of
3714 an LSDA pointer in the FDE augmentation.
3715 R Indicates a non-default pointer encoding for
3717 P Indicates the presence of an encoding + language
3718 personality routine in the CIE augmentation. */
3720 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3721 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3722 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3724 p = augmentation + 1;
3728 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3729 assemble_external_libcall (personality);
3731 if (any_lsda_needed)
3734 augmentation_size += 1;
3736 if (fde_encoding != DW_EH_PE_absptr)
3739 augmentation_size += 1;
3741 if (p > augmentation + 1)
3743 augmentation[0] = 'z';
3747 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3748 if (personality && per_encoding == DW_EH_PE_aligned)
3750 int offset = ( 4 /* Length */
3752 + 1 /* CIE version */
3753 + strlen (augmentation) + 1 /* Augmentation */
3754 + size_of_uleb128 (1) /* Code alignment */
3755 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3757 + 1 /* Augmentation size */
3758 + 1 /* Personality encoding */ );
3759 int pad = -offset & (PTR_SIZE - 1);
3761 augmentation_size += pad;
3763 /* Augmentations should be small, so there's scarce need to
3764 iterate for a solution. Die if we exceed one uleb128 byte. */
3765 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3769 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3770 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3771 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3772 "CIE Data Alignment Factor");
3774 if (dw_cie_version == 1)
3775 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3777 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3779 if (augmentation[0])
3781 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3784 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3785 eh_data_format_name (per_encoding));
3786 dw2_asm_output_encoded_addr_rtx (per_encoding,
3791 if (any_lsda_needed)
3792 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3793 eh_data_format_name (lsda_encoding));
3795 if (fde_encoding != DW_EH_PE_absptr)
3796 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3797 eh_data_format_name (fde_encoding));
3800 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3801 output_cfi (cfi, NULL, for_eh);
3803 /* Pad the CIE out to an address sized boundary. */
3804 ASM_OUTPUT_ALIGN (asm_out_file,
3805 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3806 ASM_OUTPUT_LABEL (asm_out_file, l2);
3808 /* Loop through all of the FDE's. */
3809 for (i = 0; i < fde_table_in_use; i++)
3812 fde = &fde_table[i];
3814 /* Don't emit EH unwind info for leaf functions that don't need it. */
3815 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3816 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3817 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3818 && !fde->uses_eh_lsda)
3821 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3822 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3823 augmentation, any_lsda_needed, lsda_encoding);
3826 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3827 dw2_asm_output_data (4, 0, "End of Table");
3828 #ifdef MIPS_DEBUGGING_INFO
3829 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3830 get a value of 0. Putting .align 0 after the label fixes it. */
3831 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3834 /* Turn off app to make assembly quicker. */
3839 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3842 dwarf2out_do_cfi_startproc (bool second)
3846 rtx personality = get_personality_function (current_function_decl);
3848 fprintf (asm_out_file, "\t.cfi_startproc\n");
3852 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3855 /* ??? The GAS support isn't entirely consistent. We have to
3856 handle indirect support ourselves, but PC-relative is done
3857 in the assembler. Further, the assembler can't handle any
3858 of the weirder relocation types. */
3859 if (enc & DW_EH_PE_indirect)
3860 ref = dw2_force_const_mem (ref, true);
3862 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3863 output_addr_const (asm_out_file, ref);
3864 fputc ('\n', asm_out_file);
3867 if (crtl->uses_eh_lsda)
3871 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3872 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3873 current_function_funcdef_no);
3874 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3875 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3877 if (enc & DW_EH_PE_indirect)
3878 ref = dw2_force_const_mem (ref, true);
3880 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3881 output_addr_const (asm_out_file, ref);
3882 fputc ('\n', asm_out_file);
3886 /* Output a marker (i.e. a label) for the beginning of a function, before
3890 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3891 const char *file ATTRIBUTE_UNUSED)
3893 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3898 current_function_func_begin_label = NULL;
3900 #ifdef TARGET_UNWIND_INFO
3901 /* ??? current_function_func_begin_label is also used by except.c
3902 for call-site information. We must emit this label if it might
3904 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3905 && ! dwarf2out_do_frame ())
3908 if (! dwarf2out_do_frame ())
3912 fnsec = function_section (current_function_decl);
3913 switch_to_section (fnsec);
3914 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3915 current_function_funcdef_no);
3916 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3917 current_function_funcdef_no);
3918 dup_label = xstrdup (label);
3919 current_function_func_begin_label = dup_label;
3921 #ifdef TARGET_UNWIND_INFO
3922 /* We can elide the fde allocation if we're not emitting debug info. */
3923 if (! dwarf2out_do_frame ())
3927 /* Expand the fde table if necessary. */
3928 if (fde_table_in_use == fde_table_allocated)
3930 fde_table_allocated += FDE_TABLE_INCREMENT;
3931 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3932 memset (fde_table + fde_table_in_use, 0,
3933 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3936 /* Record the FDE associated with this function. */
3937 current_funcdef_fde = fde_table_in_use;
3939 /* Add the new FDE at the end of the fde_table. */
3940 fde = &fde_table[fde_table_in_use++];
3941 fde->decl = current_function_decl;
3942 fde->dw_fde_begin = dup_label;
3943 fde->dw_fde_current_label = dup_label;
3944 fde->dw_fde_hot_section_label = NULL;
3945 fde->dw_fde_hot_section_end_label = NULL;
3946 fde->dw_fde_unlikely_section_label = NULL;
3947 fde->dw_fde_unlikely_section_end_label = NULL;
3948 fde->dw_fde_switched_sections = 0;
3949 fde->dw_fde_switched_cold_to_hot = 0;
3950 fde->dw_fde_end = NULL;
3951 fde->dw_fde_cfi = NULL;
3952 fde->dw_fde_switch_cfi = NULL;
3953 fde->funcdef_number = current_function_funcdef_no;
3954 fde->nothrow = crtl->nothrow;
3955 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3956 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3957 fde->drap_reg = INVALID_REGNUM;
3958 fde->vdrap_reg = INVALID_REGNUM;
3959 if (flag_reorder_blocks_and_partition)
3961 section *unlikelysec;
3962 if (first_function_block_is_cold)
3963 fde->in_std_section = 1;
3966 = (fnsec == text_section
3967 || (cold_text_section && fnsec == cold_text_section));
3968 unlikelysec = unlikely_text_section ();
3969 fde->cold_in_std_section
3970 = (unlikelysec == text_section
3971 || (cold_text_section && unlikelysec == cold_text_section));
3976 = (fnsec == text_section
3977 || (cold_text_section && fnsec == cold_text_section));
3978 fde->cold_in_std_section = 0;
3981 args_size = old_args_size = 0;
3983 /* We only want to output line number information for the genuine dwarf2
3984 prologue case, not the eh frame case. */
3985 #ifdef DWARF2_DEBUGGING_INFO
3987 dwarf2out_source_line (line, file, 0, true);
3990 if (dwarf2out_do_cfi_asm ())
3991 dwarf2out_do_cfi_startproc (false);
3994 rtx personality = get_personality_function (current_function_decl);
3995 if (!current_unit_personality)
3996 current_unit_personality = personality;
3998 /* We cannot keep a current personality per function as without CFI
3999 asm at the point where we emit the CFI data there is no current
4000 function anymore. */
4002 && current_unit_personality != personality)
4003 sorry ("Multiple EH personalities are supported only with assemblers "
4004 "supporting .cfi.personality directive.");
4008 /* Output a marker (i.e. a label) for the absolute end of the generated code
4009 for a function definition. This gets called *after* the epilogue code has
4013 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4014 const char *file ATTRIBUTE_UNUSED)
4017 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4019 #ifdef DWARF2_DEBUGGING_INFO
4020 last_var_location_insn = NULL_RTX;
4023 if (dwarf2out_do_cfi_asm ())
4024 fprintf (asm_out_file, "\t.cfi_endproc\n");
4026 /* Output a label to mark the endpoint of the code generated for this
4028 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4029 current_function_funcdef_no);
4030 ASM_OUTPUT_LABEL (asm_out_file, label);
4031 fde = current_fde ();
4032 gcc_assert (fde != NULL);
4033 fde->dw_fde_end = xstrdup (label);
4037 dwarf2out_frame_init (void)
4039 /* Allocate the initial hunk of the fde_table. */
4040 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
4041 fde_table_allocated = FDE_TABLE_INCREMENT;
4042 fde_table_in_use = 0;
4044 /* Generate the CFA instructions common to all FDE's. Do it now for the
4045 sake of lookup_cfa. */
4047 /* On entry, the Canonical Frame Address is at SP. */
4048 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4050 #ifdef DWARF2_UNWIND_INFO
4051 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4052 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4057 dwarf2out_frame_finish (void)
4059 /* Output call frame information. */
4060 if (DWARF2_FRAME_INFO)
4061 output_call_frame_info (0);
4063 #ifndef TARGET_UNWIND_INFO
4064 /* Output another copy for the unwinder. */
4065 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4066 output_call_frame_info (1);
4070 /* Note that the current function section is being used for code. */
4073 dwarf2out_note_section_used (void)
4075 section *sec = current_function_section ();
4076 if (sec == text_section)
4077 text_section_used = true;
4078 else if (sec == cold_text_section)
4079 cold_text_section_used = true;
4083 dwarf2out_switch_text_section (void)
4085 dw_fde_ref fde = current_fde ();
4087 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4089 fde->dw_fde_switched_sections = 1;
4090 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4092 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4093 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4094 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4095 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4096 have_multiple_function_sections = true;
4098 /* Reset the current label on switching text sections, so that we
4099 don't attempt to advance_loc4 between labels in different sections. */
4100 fde->dw_fde_current_label = NULL;
4102 /* There is no need to mark used sections when not debugging. */
4103 if (cold_text_section != NULL)
4104 dwarf2out_note_section_used ();
4106 if (dwarf2out_do_cfi_asm ())
4107 fprintf (asm_out_file, "\t.cfi_endproc\n");
4109 /* Now do the real section switch. */
4110 switch_to_section (current_function_section ());
4112 if (dwarf2out_do_cfi_asm ())
4114 dwarf2out_do_cfi_startproc (true);
4115 /* As this is a different FDE, insert all current CFI instructions
4117 output_cfis (fde->dw_fde_cfi, true, fde, true);
4121 dw_cfi_ref cfi = fde->dw_fde_cfi;
4123 cfi = fde->dw_fde_cfi;
4125 while (cfi->dw_cfi_next != NULL)
4126 cfi = cfi->dw_cfi_next;
4127 fde->dw_fde_switch_cfi = cfi;
4132 /* And now, the subset of the debugging information support code necessary
4133 for emitting location expressions. */
4135 /* Data about a single source file. */
4136 struct GTY(()) dwarf_file_data {
4137 const char * filename;
4141 typedef struct dw_val_struct *dw_val_ref;
4142 typedef struct die_struct *dw_die_ref;
4143 typedef const struct die_struct *const_dw_die_ref;
4144 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4145 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4147 typedef struct GTY(()) deferred_locations_struct
4151 } deferred_locations;
4153 DEF_VEC_O(deferred_locations);
4154 DEF_VEC_ALLOC_O(deferred_locations,gc);
4156 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4158 /* Each DIE may have a series of attribute/value pairs. Values
4159 can take on several forms. The forms that are used in this
4160 implementation are listed below. */
4165 dw_val_class_offset,
4167 dw_val_class_loc_list,
4168 dw_val_class_range_list,
4170 dw_val_class_unsigned_const,
4171 dw_val_class_const_double,
4174 dw_val_class_die_ref,
4175 dw_val_class_fde_ref,
4176 dw_val_class_lbl_id,
4177 dw_val_class_lineptr,
4179 dw_val_class_macptr,
4183 /* Describe a floating point constant value, or a vector constant value. */
4185 typedef struct GTY(()) dw_vec_struct {
4186 unsigned char * GTY((length ("%h.length"))) array;
4192 /* The dw_val_node describes an attribute's value, as it is
4193 represented internally. */
4195 typedef struct GTY(()) dw_val_struct {
4196 enum dw_val_class val_class;
4197 union dw_val_struct_union
4199 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4200 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4201 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4202 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4203 HOST_WIDE_INT GTY ((default)) val_int;
4204 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4205 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4206 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4207 struct dw_val_die_union
4211 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4212 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4213 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4214 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4215 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4216 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4218 GTY ((desc ("%1.val_class"))) v;
4222 /* Locations in memory are described using a sequence of stack machine
4225 typedef struct GTY(()) dw_loc_descr_struct {
4226 dw_loc_descr_ref dw_loc_next;
4227 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4228 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4229 from DW_OP_addr with a dtp-relative symbol relocation. */
4230 unsigned int dtprel : 1;
4232 dw_val_node dw_loc_oprnd1;
4233 dw_val_node dw_loc_oprnd2;
4237 /* Location lists are ranges + location descriptions for that range,
4238 so you can track variables that are in different places over
4239 their entire life. */
4240 typedef struct GTY(()) dw_loc_list_struct {
4241 dw_loc_list_ref dw_loc_next;
4242 const char *begin; /* Label for begin address of range */
4243 const char *end; /* Label for end address of range */
4244 char *ll_symbol; /* Label for beginning of location list.
4245 Only on head of list */
4246 const char *section; /* Section this loclist is relative to */
4247 dw_loc_descr_ref expr;
4250 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
4252 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4254 /* Convert a DWARF stack opcode into its string name. */
4257 dwarf_stack_op_name (unsigned int op)
4262 return "DW_OP_addr";
4264 return "DW_OP_deref";
4266 return "DW_OP_const1u";
4268 return "DW_OP_const1s";
4270 return "DW_OP_const2u";
4272 return "DW_OP_const2s";
4274 return "DW_OP_const4u";
4276 return "DW_OP_const4s";
4278 return "DW_OP_const8u";
4280 return "DW_OP_const8s";
4282 return "DW_OP_constu";
4284 return "DW_OP_consts";
4288 return "DW_OP_drop";
4290 return "DW_OP_over";
4292 return "DW_OP_pick";
4294 return "DW_OP_swap";
4298 return "DW_OP_xderef";
4306 return "DW_OP_minus";
4318 return "DW_OP_plus";
4319 case DW_OP_plus_uconst:
4320 return "DW_OP_plus_uconst";
4326 return "DW_OP_shra";
4344 return "DW_OP_skip";
4346 return "DW_OP_lit0";
4348 return "DW_OP_lit1";
4350 return "DW_OP_lit2";
4352 return "DW_OP_lit3";
4354 return "DW_OP_lit4";
4356 return "DW_OP_lit5";
4358 return "DW_OP_lit6";
4360 return "DW_OP_lit7";
4362 return "DW_OP_lit8";
4364 return "DW_OP_lit9";
4366 return "DW_OP_lit10";
4368 return "DW_OP_lit11";
4370 return "DW_OP_lit12";
4372 return "DW_OP_lit13";
4374 return "DW_OP_lit14";
4376 return "DW_OP_lit15";
4378 return "DW_OP_lit16";
4380 return "DW_OP_lit17";
4382 return "DW_OP_lit18";
4384 return "DW_OP_lit19";
4386 return "DW_OP_lit20";
4388 return "DW_OP_lit21";
4390 return "DW_OP_lit22";
4392 return "DW_OP_lit23";
4394 return "DW_OP_lit24";
4396 return "DW_OP_lit25";
4398 return "DW_OP_lit26";
4400 return "DW_OP_lit27";
4402 return "DW_OP_lit28";
4404 return "DW_OP_lit29";
4406 return "DW_OP_lit30";
4408 return "DW_OP_lit31";
4410 return "DW_OP_reg0";
4412 return "DW_OP_reg1";
4414 return "DW_OP_reg2";
4416 return "DW_OP_reg3";
4418 return "DW_OP_reg4";
4420 return "DW_OP_reg5";
4422 return "DW_OP_reg6";
4424 return "DW_OP_reg7";
4426 return "DW_OP_reg8";
4428 return "DW_OP_reg9";
4430 return "DW_OP_reg10";
4432 return "DW_OP_reg11";
4434 return "DW_OP_reg12";
4436 return "DW_OP_reg13";
4438 return "DW_OP_reg14";
4440 return "DW_OP_reg15";
4442 return "DW_OP_reg16";
4444 return "DW_OP_reg17";
4446 return "DW_OP_reg18";
4448 return "DW_OP_reg19";
4450 return "DW_OP_reg20";
4452 return "DW_OP_reg21";
4454 return "DW_OP_reg22";
4456 return "DW_OP_reg23";
4458 return "DW_OP_reg24";
4460 return "DW_OP_reg25";
4462 return "DW_OP_reg26";
4464 return "DW_OP_reg27";
4466 return "DW_OP_reg28";
4468 return "DW_OP_reg29";
4470 return "DW_OP_reg30";
4472 return "DW_OP_reg31";
4474 return "DW_OP_breg0";
4476 return "DW_OP_breg1";
4478 return "DW_OP_breg2";
4480 return "DW_OP_breg3";
4482 return "DW_OP_breg4";
4484 return "DW_OP_breg5";
4486 return "DW_OP_breg6";
4488 return "DW_OP_breg7";
4490 return "DW_OP_breg8";
4492 return "DW_OP_breg9";
4494 return "DW_OP_breg10";
4496 return "DW_OP_breg11";
4498 return "DW_OP_breg12";
4500 return "DW_OP_breg13";
4502 return "DW_OP_breg14";
4504 return "DW_OP_breg15";
4506 return "DW_OP_breg16";
4508 return "DW_OP_breg17";
4510 return "DW_OP_breg18";
4512 return "DW_OP_breg19";
4514 return "DW_OP_breg20";
4516 return "DW_OP_breg21";
4518 return "DW_OP_breg22";
4520 return "DW_OP_breg23";
4522 return "DW_OP_breg24";
4524 return "DW_OP_breg25";
4526 return "DW_OP_breg26";
4528 return "DW_OP_breg27";
4530 return "DW_OP_breg28";
4532 return "DW_OP_breg29";
4534 return "DW_OP_breg30";
4536 return "DW_OP_breg31";
4538 return "DW_OP_regx";
4540 return "DW_OP_fbreg";
4542 return "DW_OP_bregx";
4544 return "DW_OP_piece";
4545 case DW_OP_deref_size:
4546 return "DW_OP_deref_size";
4547 case DW_OP_xderef_size:
4548 return "DW_OP_xderef_size";
4552 case DW_OP_push_object_address:
4553 return "DW_OP_push_object_address";
4555 return "DW_OP_call2";
4557 return "DW_OP_call4";
4558 case DW_OP_call_ref:
4559 return "DW_OP_call_ref";
4560 case DW_OP_implicit_value:
4561 return "DW_OP_implicit_value";
4562 case DW_OP_stack_value:
4563 return "DW_OP_stack_value";
4564 case DW_OP_form_tls_address:
4565 return "DW_OP_form_tls_address";
4566 case DW_OP_call_frame_cfa:
4567 return "DW_OP_call_frame_cfa";
4568 case DW_OP_bit_piece:
4569 return "DW_OP_bit_piece";
4571 case DW_OP_GNU_push_tls_address:
4572 return "DW_OP_GNU_push_tls_address";
4573 case DW_OP_GNU_uninit:
4574 return "DW_OP_GNU_uninit";
4575 case DW_OP_GNU_encoded_addr:
4576 return "DW_OP_GNU_encoded_addr";
4579 return "OP_<unknown>";
4583 /* Return a pointer to a newly allocated location description. Location
4584 descriptions are simple expression terms that can be strung
4585 together to form more complicated location (address) descriptions. */
4587 static inline dw_loc_descr_ref
4588 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4589 unsigned HOST_WIDE_INT oprnd2)
4591 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4593 descr->dw_loc_opc = op;
4594 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4595 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4596 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4597 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4602 /* Return a pointer to a newly allocated location description for
4605 static inline dw_loc_descr_ref
4606 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4609 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4612 return new_loc_descr (DW_OP_bregx, reg, offset);
4615 /* Add a location description term to a location description expression. */
4618 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4620 dw_loc_descr_ref *d;
4622 /* Find the end of the chain. */
4623 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4629 /* Add a constant OFFSET to a location expression. */
4632 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4634 dw_loc_descr_ref loc;
4637 gcc_assert (*list_head != NULL);
4642 /* Find the end of the chain. */
4643 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4647 if (loc->dw_loc_opc == DW_OP_fbreg
4648 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4649 p = &loc->dw_loc_oprnd1.v.val_int;
4650 else if (loc->dw_loc_opc == DW_OP_bregx)
4651 p = &loc->dw_loc_oprnd2.v.val_int;
4653 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4654 offset. Don't optimize if an signed integer overflow would happen. */
4656 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4657 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4660 else if (offset > 0)
4661 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4665 loc->dw_loc_next = int_loc_descriptor (offset);
4666 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4670 #ifdef DWARF2_DEBUGGING_INFO
4671 /* Add a constant OFFSET to a location list. */
4674 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4677 for (d = list_head; d != NULL; d = d->dw_loc_next)
4678 loc_descr_plus_const (&d->expr, offset);
4682 /* Return the size of a location descriptor. */
4684 static unsigned long
4685 size_of_loc_descr (dw_loc_descr_ref loc)
4687 unsigned long size = 1;
4689 switch (loc->dw_loc_opc)
4692 size += DWARF2_ADDR_SIZE;
4711 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4714 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4719 case DW_OP_plus_uconst:
4720 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4758 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4761 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4764 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4767 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4768 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4771 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4773 case DW_OP_deref_size:
4774 case DW_OP_xderef_size:
4783 case DW_OP_call_ref:
4784 size += DWARF2_ADDR_SIZE;
4786 case DW_OP_implicit_value:
4787 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4788 + loc->dw_loc_oprnd1.v.val_unsigned;
4797 /* Return the size of a series of location descriptors. */
4799 static unsigned long
4800 size_of_locs (dw_loc_descr_ref loc)
4805 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4806 field, to avoid writing to a PCH file. */
4807 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4809 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4811 size += size_of_loc_descr (l);
4816 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4818 l->dw_loc_addr = size;
4819 size += size_of_loc_descr (l);
4825 #ifdef DWARF2_DEBUGGING_INFO
4826 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4829 /* Output location description stack opcode's operands (if any). */
4832 output_loc_operands (dw_loc_descr_ref loc)
4834 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4835 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4837 switch (loc->dw_loc_opc)
4839 #ifdef DWARF2_DEBUGGING_INFO
4842 dw2_asm_output_data (2, val1->v.val_int, NULL);
4846 dw2_asm_output_data (4, val1->v.val_int, NULL);
4850 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
4851 dw2_asm_output_data (8, val1->v.val_int, NULL);
4858 gcc_assert (val1->val_class == dw_val_class_loc);
4859 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4861 dw2_asm_output_data (2, offset, NULL);
4864 case DW_OP_implicit_value:
4865 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4866 switch (val2->val_class)
4868 case dw_val_class_const:
4869 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
4871 case dw_val_class_vec:
4873 unsigned int elt_size = val2->v.val_vec.elt_size;
4874 unsigned int len = val2->v.val_vec.length;
4878 if (elt_size > sizeof (HOST_WIDE_INT))
4883 for (i = 0, p = val2->v.val_vec.array;
4886 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
4887 "fp or vector constant word %u", i);
4890 case dw_val_class_const_double:
4892 unsigned HOST_WIDE_INT first, second;
4894 if (WORDS_BIG_ENDIAN)
4896 first = val2->v.val_double.high;
4897 second = val2->v.val_double.low;
4901 first = val2->v.val_double.low;
4902 second = val2->v.val_double.high;
4904 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4906 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4910 case dw_val_class_addr:
4911 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
4912 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
4927 case DW_OP_implicit_value:
4928 /* We currently don't make any attempt to make sure these are
4929 aligned properly like we do for the main unwind info, so
4930 don't support emitting things larger than a byte if we're
4931 only doing unwinding. */
4936 dw2_asm_output_data (1, val1->v.val_int, NULL);
4939 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4942 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4945 dw2_asm_output_data (1, val1->v.val_int, NULL);
4947 case DW_OP_plus_uconst:
4948 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4982 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4985 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4988 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4991 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4992 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4995 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4997 case DW_OP_deref_size:
4998 case DW_OP_xderef_size:
4999 dw2_asm_output_data (1, val1->v.val_int, NULL);
5005 if (targetm.asm_out.output_dwarf_dtprel)
5007 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5010 fputc ('\n', asm_out_file);
5017 #ifdef DWARF2_DEBUGGING_INFO
5018 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5026 /* Other codes have no operands. */
5031 /* Output a sequence of location operations. */
5034 output_loc_sequence (dw_loc_descr_ref loc)
5036 for (; loc != NULL; loc = loc->dw_loc_next)
5038 /* Output the opcode. */
5039 dw2_asm_output_data (1, loc->dw_loc_opc,
5040 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5042 /* Output the operand(s) (if any). */
5043 output_loc_operands (loc);
5047 /* Output location description stack opcode's operands (if any).
5048 The output is single bytes on a line, suitable for .cfi_escape. */
5051 output_loc_operands_raw (dw_loc_descr_ref loc)
5053 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5054 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5056 switch (loc->dw_loc_opc)
5059 case DW_OP_implicit_value:
5060 /* We cannot output addresses in .cfi_escape, only bytes. */
5066 case DW_OP_deref_size:
5067 case DW_OP_xderef_size:
5068 fputc (',', asm_out_file);
5069 dw2_asm_output_data_raw (1, val1->v.val_int);
5074 fputc (',', asm_out_file);
5075 dw2_asm_output_data_raw (2, val1->v.val_int);
5080 fputc (',', asm_out_file);
5081 dw2_asm_output_data_raw (4, val1->v.val_int);
5086 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5087 fputc (',', asm_out_file);
5088 dw2_asm_output_data_raw (8, val1->v.val_int);
5096 gcc_assert (val1->val_class == dw_val_class_loc);
5097 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5099 fputc (',', asm_out_file);
5100 dw2_asm_output_data_raw (2, offset);
5105 case DW_OP_plus_uconst:
5108 fputc (',', asm_out_file);
5109 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5146 fputc (',', asm_out_file);
5147 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5151 fputc (',', asm_out_file);
5152 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5153 fputc (',', asm_out_file);
5154 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5158 /* Other codes have no operands. */
5164 output_loc_sequence_raw (dw_loc_descr_ref loc)
5168 /* Output the opcode. */
5169 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
5170 output_loc_operands_raw (loc);
5172 if (!loc->dw_loc_next)
5174 loc = loc->dw_loc_next;
5176 fputc (',', asm_out_file);
5180 /* This routine will generate the correct assembly data for a location
5181 description based on a cfi entry with a complex address. */
5184 output_cfa_loc (dw_cfi_ref cfi)
5186 dw_loc_descr_ref loc;
5189 if (cfi->dw_cfi_opc == DW_CFA_expression)
5190 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
5192 /* Output the size of the block. */
5193 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5194 size = size_of_locs (loc);
5195 dw2_asm_output_data_uleb128 (size, NULL);
5197 /* Now output the operations themselves. */
5198 output_loc_sequence (loc);
5201 /* Similar, but used for .cfi_escape. */
5204 output_cfa_loc_raw (dw_cfi_ref cfi)
5206 dw_loc_descr_ref loc;
5209 if (cfi->dw_cfi_opc == DW_CFA_expression)
5210 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
5212 /* Output the size of the block. */
5213 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5214 size = size_of_locs (loc);
5215 dw2_asm_output_data_uleb128_raw (size);
5216 fputc (',', asm_out_file);
5218 /* Now output the operations themselves. */
5219 output_loc_sequence_raw (loc);
5222 /* This function builds a dwarf location descriptor sequence from a
5223 dw_cfa_location, adding the given OFFSET to the result of the
5226 static struct dw_loc_descr_struct *
5227 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5229 struct dw_loc_descr_struct *head, *tmp;
5231 offset += cfa->offset;
5235 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5236 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5237 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5238 add_loc_descr (&head, tmp);
5241 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5242 add_loc_descr (&head, tmp);
5246 head = new_reg_loc_descr (cfa->reg, offset);
5251 /* This function builds a dwarf location descriptor sequence for
5252 the address at OFFSET from the CFA when stack is aligned to
5255 static struct dw_loc_descr_struct *
5256 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5258 struct dw_loc_descr_struct *head;
5259 unsigned int dwarf_fp
5260 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5262 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5263 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5265 head = new_reg_loc_descr (dwarf_fp, 0);
5266 add_loc_descr (&head, int_loc_descriptor (alignment));
5267 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5268 loc_descr_plus_const (&head, offset);
5271 head = new_reg_loc_descr (dwarf_fp, offset);
5275 /* This function fills in aa dw_cfa_location structure from a dwarf location
5276 descriptor sequence. */
5279 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5281 struct dw_loc_descr_struct *ptr;
5283 cfa->base_offset = 0;
5287 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5289 enum dwarf_location_atom op = ptr->dw_loc_opc;
5325 cfa->reg = op - DW_OP_reg0;
5328 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5362 cfa->reg = op - DW_OP_breg0;
5363 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5366 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5367 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5372 case DW_OP_plus_uconst:
5373 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5376 internal_error ("DW_LOC_OP %s not implemented",
5377 dwarf_stack_op_name (ptr->dw_loc_opc));
5381 #endif /* .debug_frame support */
5383 /* And now, the support for symbolic debugging information. */
5384 #ifdef DWARF2_DEBUGGING_INFO
5386 /* .debug_str support. */
5387 static int output_indirect_string (void **, void *);
5389 static void dwarf2out_init (const char *);
5390 static void dwarf2out_finish (const char *);
5391 static void dwarf2out_define (unsigned int, const char *);
5392 static void dwarf2out_undef (unsigned int, const char *);
5393 static void dwarf2out_start_source_file (unsigned, const char *);
5394 static void dwarf2out_end_source_file (unsigned);
5395 static void dwarf2out_begin_block (unsigned, unsigned);
5396 static void dwarf2out_end_block (unsigned, unsigned);
5397 static bool dwarf2out_ignore_block (const_tree);
5398 static void dwarf2out_global_decl (tree);
5399 static void dwarf2out_type_decl (tree, int);
5400 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5401 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5403 static void dwarf2out_abstract_function (tree);
5404 static void dwarf2out_var_location (rtx);
5405 static void dwarf2out_begin_function (tree);
5406 static void dwarf2out_set_name (tree, tree);
5408 /* The debug hooks structure. */
5410 const struct gcc_debug_hooks dwarf2_debug_hooks =
5416 dwarf2out_start_source_file,
5417 dwarf2out_end_source_file,
5418 dwarf2out_begin_block,
5419 dwarf2out_end_block,
5420 dwarf2out_ignore_block,
5421 dwarf2out_source_line,
5422 dwarf2out_begin_prologue,
5423 debug_nothing_int_charstar, /* end_prologue */
5424 dwarf2out_end_epilogue,
5425 dwarf2out_begin_function,
5426 debug_nothing_int, /* end_function */
5427 dwarf2out_decl, /* function_decl */
5428 dwarf2out_global_decl,
5429 dwarf2out_type_decl, /* type_decl */
5430 dwarf2out_imported_module_or_decl,
5431 debug_nothing_tree, /* deferred_inline_function */
5432 /* The DWARF 2 backend tries to reduce debugging bloat by not
5433 emitting the abstract description of inline functions until
5434 something tries to reference them. */
5435 dwarf2out_abstract_function, /* outlining_inline_function */
5436 debug_nothing_rtx, /* label */
5437 debug_nothing_int, /* handle_pch */
5438 dwarf2out_var_location,
5439 dwarf2out_switch_text_section,
5441 1 /* start_end_main_source_file */
5445 /* NOTE: In the comments in this file, many references are made to
5446 "Debugging Information Entries". This term is abbreviated as `DIE'
5447 throughout the remainder of this file. */
5449 /* An internal representation of the DWARF output is built, and then
5450 walked to generate the DWARF debugging info. The walk of the internal
5451 representation is done after the entire program has been compiled.
5452 The types below are used to describe the internal representation. */
5454 /* Various DIE's use offsets relative to the beginning of the
5455 .debug_info section to refer to each other. */
5457 typedef long int dw_offset;
5459 /* Define typedefs here to avoid circular dependencies. */
5461 typedef struct dw_attr_struct *dw_attr_ref;
5462 typedef struct dw_line_info_struct *dw_line_info_ref;
5463 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5464 typedef struct pubname_struct *pubname_ref;
5465 typedef struct dw_ranges_struct *dw_ranges_ref;
5466 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5468 /* Each entry in the line_info_table maintains the file and
5469 line number associated with the label generated for that
5470 entry. The label gives the PC value associated with
5471 the line number entry. */
5473 typedef struct GTY(()) dw_line_info_struct {
5474 unsigned long dw_file_num;
5475 unsigned long dw_line_num;
5479 /* Line information for functions in separate sections; each one gets its
5481 typedef struct GTY(()) dw_separate_line_info_struct {
5482 unsigned long dw_file_num;
5483 unsigned long dw_line_num;
5484 unsigned long function;
5486 dw_separate_line_info_entry;
5488 /* Each DIE attribute has a field specifying the attribute kind,
5489 a link to the next attribute in the chain, and an attribute value.
5490 Attributes are typically linked below the DIE they modify. */
5492 typedef struct GTY(()) dw_attr_struct {
5493 enum dwarf_attribute dw_attr;
5494 dw_val_node dw_attr_val;
5498 DEF_VEC_O(dw_attr_node);
5499 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5501 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5502 The children of each node form a circular list linked by
5503 die_sib. die_child points to the node *before* the "first" child node. */
5505 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5506 enum dwarf_tag die_tag;
5508 VEC(dw_attr_node,gc) * die_attr;
5509 dw_die_ref die_parent;
5510 dw_die_ref die_child;
5512 dw_die_ref die_definition; /* ref from a specification to its definition */
5513 dw_offset die_offset;
5514 unsigned long die_abbrev;
5516 /* Die is used and must not be pruned as unused. */
5517 int die_perennial_p;
5518 unsigned int decl_id;
5522 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5523 #define FOR_EACH_CHILD(die, c, expr) do { \
5524 c = die->die_child; \
5528 } while (c != die->die_child); \
5531 /* The pubname structure */
5533 typedef struct GTY(()) pubname_struct {
5539 DEF_VEC_O(pubname_entry);
5540 DEF_VEC_ALLOC_O(pubname_entry, gc);
5542 struct GTY(()) dw_ranges_struct {
5543 /* If this is positive, it's a block number, otherwise it's a
5544 bitwise-negated index into dw_ranges_by_label. */
5548 struct GTY(()) dw_ranges_by_label_struct {
5553 /* The limbo die list structure. */
5554 typedef struct GTY(()) limbo_die_struct {
5557 struct limbo_die_struct *next;
5561 /* How to start an assembler comment. */
5562 #ifndef ASM_COMMENT_START
5563 #define ASM_COMMENT_START ";#"
5566 /* Define a macro which returns nonzero for a TYPE_DECL which was
5567 implicitly generated for a tagged type.
5569 Note that unlike the gcc front end (which generates a NULL named
5570 TYPE_DECL node for each complete tagged type, each array type, and
5571 each function type node created) the g++ front end generates a
5572 _named_ TYPE_DECL node for each tagged type node created.
5573 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5574 generate a DW_TAG_typedef DIE for them. */
5576 #define TYPE_DECL_IS_STUB(decl) \
5577 (DECL_NAME (decl) == NULL_TREE \
5578 || (DECL_ARTIFICIAL (decl) \
5579 && is_tagged_type (TREE_TYPE (decl)) \
5580 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5581 /* This is necessary for stub decls that \
5582 appear in nested inline functions. */ \
5583 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5584 && (decl_ultimate_origin (decl) \
5585 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5587 /* Information concerning the compilation unit's programming
5588 language, and compiler version. */
5590 /* Fixed size portion of the DWARF compilation unit header. */
5591 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5592 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5594 /* Fixed size portion of public names info. */
5595 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5597 /* Fixed size portion of the address range info. */
5598 #define DWARF_ARANGES_HEADER_SIZE \
5599 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5600 DWARF2_ADDR_SIZE * 2) \
5601 - DWARF_INITIAL_LENGTH_SIZE)
5603 /* Size of padding portion in the address range info. It must be
5604 aligned to twice the pointer size. */
5605 #define DWARF_ARANGES_PAD_SIZE \
5606 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5607 DWARF2_ADDR_SIZE * 2) \
5608 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5610 /* Use assembler line directives if available. */
5611 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5612 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5613 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5615 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5619 /* Minimum line offset in a special line info. opcode.
5620 This value was chosen to give a reasonable range of values. */
5621 #define DWARF_LINE_BASE -10
5623 /* First special line opcode - leave room for the standard opcodes. */
5624 #define DWARF_LINE_OPCODE_BASE 10
5626 /* Range of line offsets in a special line info. opcode. */
5627 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5629 /* Flag that indicates the initial value of the is_stmt_start flag.
5630 In the present implementation, we do not mark any lines as
5631 the beginning of a source statement, because that information
5632 is not made available by the GCC front-end. */
5633 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5635 #ifdef DWARF2_DEBUGGING_INFO
5636 /* This location is used by calc_die_sizes() to keep track
5637 the offset of each DIE within the .debug_info section. */
5638 static unsigned long next_die_offset;
5641 /* Record the root of the DIE's built for the current compilation unit. */
5642 static GTY(()) dw_die_ref comp_unit_die;
5644 /* A list of DIEs with a NULL parent waiting to be relocated. */
5645 static GTY(()) limbo_die_node *limbo_die_list;
5647 /* A list of DIEs for which we may have to generate
5648 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5650 static GTY(()) limbo_die_node *deferred_asm_name;
5652 /* Filenames referenced by this compilation unit. */
5653 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5655 /* A hash table of references to DIE's that describe declarations.
5656 The key is a DECL_UID() which is a unique number identifying each decl. */
5657 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5659 /* A hash table of references to DIE's that describe COMMON blocks.
5660 The key is DECL_UID() ^ die_parent. */
5661 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5663 typedef struct GTY(()) die_arg_entry_struct {
5668 DEF_VEC_O(die_arg_entry);
5669 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5671 /* Node of the variable location list. */
5672 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5673 rtx GTY (()) var_loc_note;
5674 const char * GTY (()) label;
5675 const char * GTY (()) section_label;
5676 struct var_loc_node * GTY (()) next;
5679 /* Variable location list. */
5680 struct GTY (()) var_loc_list_def {
5681 struct var_loc_node * GTY (()) first;
5683 /* Do not mark the last element of the chained list because
5684 it is marked through the chain. */
5685 struct var_loc_node * GTY ((skip ("%h"))) last;
5687 /* DECL_UID of the variable decl. */
5688 unsigned int decl_id;
5690 typedef struct var_loc_list_def var_loc_list;
5693 /* Table of decl location linked lists. */
5694 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5696 /* A pointer to the base of a list of references to DIE's that
5697 are uniquely identified by their tag, presence/absence of
5698 children DIE's, and list of attribute/value pairs. */
5699 static GTY((length ("abbrev_die_table_allocated")))
5700 dw_die_ref *abbrev_die_table;
5702 /* Number of elements currently allocated for abbrev_die_table. */
5703 static GTY(()) unsigned abbrev_die_table_allocated;
5705 /* Number of elements in type_die_table currently in use. */
5706 static GTY(()) unsigned abbrev_die_table_in_use;
5708 /* Size (in elements) of increments by which we may expand the
5709 abbrev_die_table. */
5710 #define ABBREV_DIE_TABLE_INCREMENT 256
5712 /* A pointer to the base of a table that contains line information
5713 for each source code line in .text in the compilation unit. */
5714 static GTY((length ("line_info_table_allocated")))
5715 dw_line_info_ref line_info_table;
5717 /* Number of elements currently allocated for line_info_table. */
5718 static GTY(()) unsigned line_info_table_allocated;
5720 /* Number of elements in line_info_table currently in use. */
5721 static GTY(()) unsigned line_info_table_in_use;
5723 /* A pointer to the base of a table that contains line information
5724 for each source code line outside of .text in the compilation unit. */
5725 static GTY ((length ("separate_line_info_table_allocated")))
5726 dw_separate_line_info_ref separate_line_info_table;
5728 /* Number of elements currently allocated for separate_line_info_table. */
5729 static GTY(()) unsigned separate_line_info_table_allocated;
5731 /* Number of elements in separate_line_info_table currently in use. */
5732 static GTY(()) unsigned separate_line_info_table_in_use;
5734 /* Size (in elements) of increments by which we may expand the
5736 #define LINE_INFO_TABLE_INCREMENT 1024
5738 /* A pointer to the base of a table that contains a list of publicly
5739 accessible names. */
5740 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5742 /* A pointer to the base of a table that contains a list of publicly
5743 accessible types. */
5744 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5746 /* Array of dies for which we should generate .debug_arange info. */
5747 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5749 /* Number of elements currently allocated for arange_table. */
5750 static GTY(()) unsigned arange_table_allocated;
5752 /* Number of elements in arange_table currently in use. */
5753 static GTY(()) unsigned arange_table_in_use;
5755 /* Size (in elements) of increments by which we may expand the
5757 #define ARANGE_TABLE_INCREMENT 64
5759 /* Array of dies for which we should generate .debug_ranges info. */
5760 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5762 /* Number of elements currently allocated for ranges_table. */
5763 static GTY(()) unsigned ranges_table_allocated;
5765 /* Number of elements in ranges_table currently in use. */
5766 static GTY(()) unsigned ranges_table_in_use;
5768 /* Array of pairs of labels referenced in ranges_table. */
5769 static GTY ((length ("ranges_by_label_allocated")))
5770 dw_ranges_by_label_ref ranges_by_label;
5772 /* Number of elements currently allocated for ranges_by_label. */
5773 static GTY(()) unsigned ranges_by_label_allocated;
5775 /* Number of elements in ranges_by_label currently in use. */
5776 static GTY(()) unsigned ranges_by_label_in_use;
5778 /* Size (in elements) of increments by which we may expand the
5780 #define RANGES_TABLE_INCREMENT 64
5782 /* Whether we have location lists that need outputting */
5783 static GTY(()) bool have_location_lists;
5785 /* Unique label counter. */
5786 static GTY(()) unsigned int loclabel_num;
5788 #ifdef DWARF2_DEBUGGING_INFO
5789 /* Record whether the function being analyzed contains inlined functions. */
5790 static int current_function_has_inlines;
5792 #if 0 && defined (MIPS_DEBUGGING_INFO)
5793 static int comp_unit_has_inlines;
5796 /* The last file entry emitted by maybe_emit_file(). */
5797 static GTY(()) struct dwarf_file_data * last_emitted_file;
5799 /* Number of internal labels generated by gen_internal_sym(). */
5800 static GTY(()) int label_num;
5802 /* Cached result of previous call to lookup_filename. */
5803 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5805 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
5807 #ifdef DWARF2_DEBUGGING_INFO
5809 /* Offset from the "steady-state frame pointer" to the frame base,
5810 within the current function. */
5811 static HOST_WIDE_INT frame_pointer_fb_offset;
5813 /* Forward declarations for functions defined in this file. */
5815 static int is_pseudo_reg (const_rtx);
5816 static tree type_main_variant (tree);
5817 static int is_tagged_type (const_tree);
5818 static const char *dwarf_tag_name (unsigned);
5819 static const char *dwarf_attr_name (unsigned);
5820 static const char *dwarf_form_name (unsigned);
5821 static tree decl_ultimate_origin (const_tree);
5822 static tree decl_class_context (tree);
5823 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5824 static inline enum dw_val_class AT_class (dw_attr_ref);
5825 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5826 static inline unsigned AT_flag (dw_attr_ref);
5827 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5828 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5829 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5830 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5831 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
5832 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
5833 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5834 unsigned int, unsigned char *);
5835 static hashval_t debug_str_do_hash (const void *);
5836 static int debug_str_eq (const void *, const void *);
5837 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5838 static inline const char *AT_string (dw_attr_ref);
5839 static enum dwarf_form AT_string_form (dw_attr_ref);
5840 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5841 static void add_AT_specification (dw_die_ref, dw_die_ref);
5842 static inline dw_die_ref AT_ref (dw_attr_ref);
5843 static inline int AT_ref_external (dw_attr_ref);
5844 static inline void set_AT_ref_external (dw_attr_ref, int);
5845 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5846 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5847 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5848 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5850 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5851 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5852 static inline rtx AT_addr (dw_attr_ref);
5853 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5854 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5855 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5856 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5857 unsigned HOST_WIDE_INT);
5858 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5860 static inline const char *AT_lbl (dw_attr_ref);
5861 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5862 static const char *get_AT_low_pc (dw_die_ref);
5863 static const char *get_AT_hi_pc (dw_die_ref);
5864 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5865 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5866 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5867 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5868 static bool is_c_family (void);
5869 static bool is_cxx (void);
5870 static bool is_java (void);
5871 static bool is_fortran (void);
5872 static bool is_ada (void);
5873 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5874 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5875 static void add_child_die (dw_die_ref, dw_die_ref);
5876 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5877 static dw_die_ref lookup_type_die (tree);
5878 static void equate_type_number_to_die (tree, dw_die_ref);
5879 static hashval_t decl_die_table_hash (const void *);
5880 static int decl_die_table_eq (const void *, const void *);
5881 static dw_die_ref lookup_decl_die (tree);
5882 static hashval_t common_block_die_table_hash (const void *);
5883 static int common_block_die_table_eq (const void *, const void *);
5884 static hashval_t decl_loc_table_hash (const void *);
5885 static int decl_loc_table_eq (const void *, const void *);
5886 static var_loc_list *lookup_decl_loc (const_tree);
5887 static void equate_decl_number_to_die (tree, dw_die_ref);
5888 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5889 static void print_spaces (FILE *);
5890 static void print_die (dw_die_ref, FILE *);
5891 static void print_dwarf_line_table (FILE *);
5892 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5893 static dw_die_ref pop_compile_unit (dw_die_ref);
5894 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5895 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5896 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5897 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5898 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5899 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5900 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5901 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5902 static void compute_section_prefix (dw_die_ref);
5903 static int is_type_die (dw_die_ref);
5904 static int is_comdat_die (dw_die_ref);
5905 static int is_symbol_die (dw_die_ref);
5906 static void assign_symbol_names (dw_die_ref);
5907 static void break_out_includes (dw_die_ref);
5908 static hashval_t htab_cu_hash (const void *);
5909 static int htab_cu_eq (const void *, const void *);
5910 static void htab_cu_del (void *);
5911 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5912 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5913 static void add_sibling_attributes (dw_die_ref);
5914 static void build_abbrev_table (dw_die_ref);
5915 static void output_location_lists (dw_die_ref);
5916 static int constant_size (unsigned HOST_WIDE_INT);
5917 static unsigned long size_of_die (dw_die_ref);
5918 static void calc_die_sizes (dw_die_ref);
5919 static void mark_dies (dw_die_ref);
5920 static void unmark_dies (dw_die_ref);
5921 static void unmark_all_dies (dw_die_ref);
5922 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5923 static unsigned long size_of_aranges (void);
5924 static enum dwarf_form value_format (dw_attr_ref);
5925 static void output_value_format (dw_attr_ref);
5926 static void output_abbrev_section (void);
5927 static void output_die_symbol (dw_die_ref);
5928 static void output_die (dw_die_ref);
5929 static void output_compilation_unit_header (void);
5930 static void output_comp_unit (dw_die_ref, int);
5931 static const char *dwarf2_name (tree, int);
5932 static void add_pubname (tree, dw_die_ref);
5933 static void add_pubname_string (const char *, dw_die_ref);
5934 static void add_pubtype (tree, dw_die_ref);
5935 static void output_pubnames (VEC (pubname_entry,gc) *);
5936 static void add_arange (tree, dw_die_ref);
5937 static void output_aranges (void);
5938 static unsigned int add_ranges_num (int);
5939 static unsigned int add_ranges (const_tree);
5940 static unsigned int add_ranges_by_labels (const char *, const char *);
5941 static void output_ranges (void);
5942 static void output_line_info (void);
5943 static void output_file_names (void);
5944 static dw_die_ref base_type_die (tree);
5945 static int is_base_type (tree);
5946 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5947 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5948 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
5949 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
5950 static int type_is_enum (const_tree);
5951 static unsigned int dbx_reg_number (const_rtx);
5952 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5953 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5954 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5955 enum var_init_status);
5956 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5957 enum var_init_status);
5958 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5959 enum var_init_status);
5960 static int is_based_loc (const_rtx);
5961 static int resolve_one_addr (rtx *, void *);
5962 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5963 enum var_init_status);
5964 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5965 enum var_init_status);
5966 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
5967 enum var_init_status);
5968 static dw_loc_list_ref loc_list_from_tree (tree, int);
5969 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
5970 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5971 static tree field_type (const_tree);
5972 static unsigned int simple_type_align_in_bits (const_tree);
5973 static unsigned int simple_decl_align_in_bits (const_tree);
5974 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5975 static HOST_WIDE_INT field_byte_offset (const_tree);
5976 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5978 static void add_data_member_location_attribute (dw_die_ref, tree);
5979 static bool add_const_value_attribute (dw_die_ref, rtx);
5980 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5981 static void insert_float (const_rtx, unsigned char *);
5982 static rtx rtl_for_decl_location (tree);
5983 static bool add_location_or_const_value_attribute (dw_die_ref, tree,
5984 enum dwarf_attribute);
5985 static bool tree_add_const_value_attribute (dw_die_ref, tree);
5986 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
5987 static void add_name_attribute (dw_die_ref, const char *);
5988 static void add_comp_dir_attribute (dw_die_ref);
5989 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5990 static void add_subscript_info (dw_die_ref, tree, bool);
5991 static void add_byte_size_attribute (dw_die_ref, tree);
5992 static void add_bit_offset_attribute (dw_die_ref, tree);
5993 static void add_bit_size_attribute (dw_die_ref, tree);
5994 static void add_prototyped_attribute (dw_die_ref, tree);
5995 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5996 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5997 static void add_src_coords_attributes (dw_die_ref, tree);
5998 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5999 static void push_decl_scope (tree);
6000 static void pop_decl_scope (void);
6001 static dw_die_ref scope_die_for (tree, dw_die_ref);
6002 static inline int local_scope_p (dw_die_ref);
6003 static inline int class_scope_p (dw_die_ref);
6004 static inline int class_or_namespace_scope_p (dw_die_ref);
6005 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6006 static void add_calling_convention_attribute (dw_die_ref, tree);
6007 static const char *type_tag (const_tree);
6008 static tree member_declared_type (const_tree);
6010 static const char *decl_start_label (tree);
6012 static void gen_array_type_die (tree, dw_die_ref);
6013 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6015 static void gen_entry_point_die (tree, dw_die_ref);
6017 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6018 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6019 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6020 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6021 static void gen_formal_types_die (tree, dw_die_ref);
6022 static void gen_subprogram_die (tree, dw_die_ref);
6023 static void gen_variable_die (tree, tree, dw_die_ref);
6024 static void gen_const_die (tree, dw_die_ref);
6025 static void gen_label_die (tree, dw_die_ref);
6026 static void gen_lexical_block_die (tree, dw_die_ref, int);
6027 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6028 static void gen_field_die (tree, dw_die_ref);
6029 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6030 static dw_die_ref gen_compile_unit_die (const char *);
6031 static void gen_inheritance_die (tree, tree, dw_die_ref);
6032 static void gen_member_die (tree, dw_die_ref);
6033 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6034 enum debug_info_usage);
6035 static void gen_subroutine_type_die (tree, dw_die_ref);
6036 static void gen_typedef_die (tree, dw_die_ref);
6037 static void gen_type_die (tree, dw_die_ref);
6038 static void gen_block_die (tree, dw_die_ref, int);
6039 static void decls_for_scope (tree, dw_die_ref, int);
6040 static int is_redundant_typedef (const_tree);
6041 static inline dw_die_ref get_context_die (tree);
6042 static void gen_namespace_die (tree, dw_die_ref);
6043 static void gen_decl_die (tree, tree, dw_die_ref);
6044 static dw_die_ref force_decl_die (tree);
6045 static dw_die_ref force_type_die (tree);
6046 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6047 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6048 static struct dwarf_file_data * lookup_filename (const char *);
6049 static void retry_incomplete_types (void);
6050 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6051 static void gen_generic_params_dies (tree);
6052 static void splice_child_die (dw_die_ref, dw_die_ref);
6053 static int file_info_cmp (const void *, const void *);
6054 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6055 const char *, const char *, unsigned);
6056 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
6057 const char *, const char *,
6059 static void output_loc_list (dw_loc_list_ref);
6060 static char *gen_internal_sym (const char *);
6062 static void prune_unmark_dies (dw_die_ref);
6063 static void prune_unused_types_mark (dw_die_ref, int);
6064 static void prune_unused_types_walk (dw_die_ref);
6065 static void prune_unused_types_walk_attribs (dw_die_ref);
6066 static void prune_unused_types_prune (dw_die_ref);
6067 static void prune_unused_types (void);
6068 static int maybe_emit_file (struct dwarf_file_data *fd);
6069 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6070 static void gen_remaining_tmpl_value_param_die_attribute (void);
6072 /* Section names used to hold DWARF debugging information. */
6073 #ifndef DEBUG_INFO_SECTION
6074 #define DEBUG_INFO_SECTION ".debug_info"
6076 #ifndef DEBUG_ABBREV_SECTION
6077 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6079 #ifndef DEBUG_ARANGES_SECTION
6080 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6082 #ifndef DEBUG_MACINFO_SECTION
6083 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6085 #ifndef DEBUG_LINE_SECTION
6086 #define DEBUG_LINE_SECTION ".debug_line"
6088 #ifndef DEBUG_LOC_SECTION
6089 #define DEBUG_LOC_SECTION ".debug_loc"
6091 #ifndef DEBUG_PUBNAMES_SECTION
6092 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6094 #ifndef DEBUG_PUBTYPES_SECTION
6095 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6097 #ifndef DEBUG_STR_SECTION
6098 #define DEBUG_STR_SECTION ".debug_str"
6100 #ifndef DEBUG_RANGES_SECTION
6101 #define DEBUG_RANGES_SECTION ".debug_ranges"
6104 /* Standard ELF section names for compiled code and data. */
6105 #ifndef TEXT_SECTION_NAME
6106 #define TEXT_SECTION_NAME ".text"
6109 /* Section flags for .debug_str section. */
6110 #define DEBUG_STR_SECTION_FLAGS \
6111 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6112 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6115 /* Labels we insert at beginning sections we can reference instead of
6116 the section names themselves. */
6118 #ifndef TEXT_SECTION_LABEL
6119 #define TEXT_SECTION_LABEL "Ltext"
6121 #ifndef COLD_TEXT_SECTION_LABEL
6122 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6124 #ifndef DEBUG_LINE_SECTION_LABEL
6125 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6127 #ifndef DEBUG_INFO_SECTION_LABEL
6128 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6130 #ifndef DEBUG_ABBREV_SECTION_LABEL
6131 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6133 #ifndef DEBUG_LOC_SECTION_LABEL
6134 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6136 #ifndef DEBUG_RANGES_SECTION_LABEL
6137 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6139 #ifndef DEBUG_MACINFO_SECTION_LABEL
6140 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6143 /* Definitions of defaults for formats and names of various special
6144 (artificial) labels which may be generated within this file (when the -g
6145 options is used and DWARF2_DEBUGGING_INFO is in effect.
6146 If necessary, these may be overridden from within the tm.h file, but
6147 typically, overriding these defaults is unnecessary. */
6149 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6150 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6151 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6152 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6153 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6154 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6155 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6156 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6157 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6158 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6160 #ifndef TEXT_END_LABEL
6161 #define TEXT_END_LABEL "Letext"
6163 #ifndef COLD_END_LABEL
6164 #define COLD_END_LABEL "Letext_cold"
6166 #ifndef BLOCK_BEGIN_LABEL
6167 #define BLOCK_BEGIN_LABEL "LBB"
6169 #ifndef BLOCK_END_LABEL
6170 #define BLOCK_END_LABEL "LBE"
6172 #ifndef LINE_CODE_LABEL
6173 #define LINE_CODE_LABEL "LM"
6175 #ifndef SEPARATE_LINE_CODE_LABEL
6176 #define SEPARATE_LINE_CODE_LABEL "LSM"
6180 /* We allow a language front-end to designate a function that is to be
6181 called to "demangle" any name before it is put into a DIE. */
6183 static const char *(*demangle_name_func) (const char *);
6186 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6188 demangle_name_func = func;
6191 /* Test if rtl node points to a pseudo register. */
6194 is_pseudo_reg (const_rtx rtl)
6196 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6197 || (GET_CODE (rtl) == SUBREG
6198 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6201 /* Return a reference to a type, with its const and volatile qualifiers
6205 type_main_variant (tree type)
6207 type = TYPE_MAIN_VARIANT (type);
6209 /* ??? There really should be only one main variant among any group of
6210 variants of a given type (and all of the MAIN_VARIANT values for all
6211 members of the group should point to that one type) but sometimes the C
6212 front-end messes this up for array types, so we work around that bug
6214 if (TREE_CODE (type) == ARRAY_TYPE)
6215 while (type != TYPE_MAIN_VARIANT (type))
6216 type = TYPE_MAIN_VARIANT (type);
6221 /* Return nonzero if the given type node represents a tagged type. */
6224 is_tagged_type (const_tree type)
6226 enum tree_code code = TREE_CODE (type);
6228 return (code == RECORD_TYPE || code == UNION_TYPE
6229 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6232 /* Convert a DIE tag into its string name. */
6235 dwarf_tag_name (unsigned int tag)
6239 case DW_TAG_padding:
6240 return "DW_TAG_padding";
6241 case DW_TAG_array_type:
6242 return "DW_TAG_array_type";
6243 case DW_TAG_class_type:
6244 return "DW_TAG_class_type";
6245 case DW_TAG_entry_point:
6246 return "DW_TAG_entry_point";
6247 case DW_TAG_enumeration_type:
6248 return "DW_TAG_enumeration_type";
6249 case DW_TAG_formal_parameter:
6250 return "DW_TAG_formal_parameter";
6251 case DW_TAG_imported_declaration:
6252 return "DW_TAG_imported_declaration";
6254 return "DW_TAG_label";
6255 case DW_TAG_lexical_block:
6256 return "DW_TAG_lexical_block";
6258 return "DW_TAG_member";
6259 case DW_TAG_pointer_type:
6260 return "DW_TAG_pointer_type";
6261 case DW_TAG_reference_type:
6262 return "DW_TAG_reference_type";
6263 case DW_TAG_compile_unit:
6264 return "DW_TAG_compile_unit";
6265 case DW_TAG_string_type:
6266 return "DW_TAG_string_type";
6267 case DW_TAG_structure_type:
6268 return "DW_TAG_structure_type";
6269 case DW_TAG_subroutine_type:
6270 return "DW_TAG_subroutine_type";
6271 case DW_TAG_typedef:
6272 return "DW_TAG_typedef";
6273 case DW_TAG_union_type:
6274 return "DW_TAG_union_type";
6275 case DW_TAG_unspecified_parameters:
6276 return "DW_TAG_unspecified_parameters";
6277 case DW_TAG_variant:
6278 return "DW_TAG_variant";
6279 case DW_TAG_common_block:
6280 return "DW_TAG_common_block";
6281 case DW_TAG_common_inclusion:
6282 return "DW_TAG_common_inclusion";
6283 case DW_TAG_inheritance:
6284 return "DW_TAG_inheritance";
6285 case DW_TAG_inlined_subroutine:
6286 return "DW_TAG_inlined_subroutine";
6288 return "DW_TAG_module";
6289 case DW_TAG_ptr_to_member_type:
6290 return "DW_TAG_ptr_to_member_type";
6291 case DW_TAG_set_type:
6292 return "DW_TAG_set_type";
6293 case DW_TAG_subrange_type:
6294 return "DW_TAG_subrange_type";
6295 case DW_TAG_with_stmt:
6296 return "DW_TAG_with_stmt";
6297 case DW_TAG_access_declaration:
6298 return "DW_TAG_access_declaration";
6299 case DW_TAG_base_type:
6300 return "DW_TAG_base_type";
6301 case DW_TAG_catch_block:
6302 return "DW_TAG_catch_block";
6303 case DW_TAG_const_type:
6304 return "DW_TAG_const_type";
6305 case DW_TAG_constant:
6306 return "DW_TAG_constant";
6307 case DW_TAG_enumerator:
6308 return "DW_TAG_enumerator";
6309 case DW_TAG_file_type:
6310 return "DW_TAG_file_type";
6312 return "DW_TAG_friend";
6313 case DW_TAG_namelist:
6314 return "DW_TAG_namelist";
6315 case DW_TAG_namelist_item:
6316 return "DW_TAG_namelist_item";
6317 case DW_TAG_packed_type:
6318 return "DW_TAG_packed_type";
6319 case DW_TAG_subprogram:
6320 return "DW_TAG_subprogram";
6321 case DW_TAG_template_type_param:
6322 return "DW_TAG_template_type_param";
6323 case DW_TAG_template_value_param:
6324 return "DW_TAG_template_value_param";
6325 case DW_TAG_thrown_type:
6326 return "DW_TAG_thrown_type";
6327 case DW_TAG_try_block:
6328 return "DW_TAG_try_block";
6329 case DW_TAG_variant_part:
6330 return "DW_TAG_variant_part";
6331 case DW_TAG_variable:
6332 return "DW_TAG_variable";
6333 case DW_TAG_volatile_type:
6334 return "DW_TAG_volatile_type";
6335 case DW_TAG_dwarf_procedure:
6336 return "DW_TAG_dwarf_procedure";
6337 case DW_TAG_restrict_type:
6338 return "DW_TAG_restrict_type";
6339 case DW_TAG_interface_type:
6340 return "DW_TAG_interface_type";
6341 case DW_TAG_namespace:
6342 return "DW_TAG_namespace";
6343 case DW_TAG_imported_module:
6344 return "DW_TAG_imported_module";
6345 case DW_TAG_unspecified_type:
6346 return "DW_TAG_unspecified_type";
6347 case DW_TAG_partial_unit:
6348 return "DW_TAG_partial_unit";
6349 case DW_TAG_imported_unit:
6350 return "DW_TAG_imported_unit";
6351 case DW_TAG_condition:
6352 return "DW_TAG_condition";
6353 case DW_TAG_shared_type:
6354 return "DW_TAG_shared_type";
6355 case DW_TAG_GNU_template_parameter_pack:
6356 return "DW_TAG_GNU_template_parameter_pack";
6357 case DW_TAG_GNU_formal_parameter_pack:
6358 return "DW_TAG_GNU_formal_parameter_pack";
6359 case DW_TAG_MIPS_loop:
6360 return "DW_TAG_MIPS_loop";
6361 case DW_TAG_format_label:
6362 return "DW_TAG_format_label";
6363 case DW_TAG_function_template:
6364 return "DW_TAG_function_template";
6365 case DW_TAG_class_template:
6366 return "DW_TAG_class_template";
6367 case DW_TAG_GNU_BINCL:
6368 return "DW_TAG_GNU_BINCL";
6369 case DW_TAG_GNU_EINCL:
6370 return "DW_TAG_GNU_EINCL";
6371 case DW_TAG_GNU_template_template_param:
6372 return "DW_TAG_GNU_template_template_param";
6374 return "DW_TAG_<unknown>";
6378 /* Convert a DWARF attribute code into its string name. */
6381 dwarf_attr_name (unsigned int attr)
6386 return "DW_AT_sibling";
6387 case DW_AT_location:
6388 return "DW_AT_location";
6390 return "DW_AT_name";
6391 case DW_AT_ordering:
6392 return "DW_AT_ordering";
6393 case DW_AT_subscr_data:
6394 return "DW_AT_subscr_data";
6395 case DW_AT_byte_size:
6396 return "DW_AT_byte_size";
6397 case DW_AT_bit_offset:
6398 return "DW_AT_bit_offset";
6399 case DW_AT_bit_size:
6400 return "DW_AT_bit_size";
6401 case DW_AT_element_list:
6402 return "DW_AT_element_list";
6403 case DW_AT_stmt_list:
6404 return "DW_AT_stmt_list";
6406 return "DW_AT_low_pc";
6408 return "DW_AT_high_pc";
6409 case DW_AT_language:
6410 return "DW_AT_language";
6412 return "DW_AT_member";
6414 return "DW_AT_discr";
6415 case DW_AT_discr_value:
6416 return "DW_AT_discr_value";
6417 case DW_AT_visibility:
6418 return "DW_AT_visibility";
6420 return "DW_AT_import";
6421 case DW_AT_string_length:
6422 return "DW_AT_string_length";
6423 case DW_AT_common_reference:
6424 return "DW_AT_common_reference";
6425 case DW_AT_comp_dir:
6426 return "DW_AT_comp_dir";
6427 case DW_AT_const_value:
6428 return "DW_AT_const_value";
6429 case DW_AT_containing_type:
6430 return "DW_AT_containing_type";
6431 case DW_AT_default_value:
6432 return "DW_AT_default_value";
6434 return "DW_AT_inline";
6435 case DW_AT_is_optional:
6436 return "DW_AT_is_optional";
6437 case DW_AT_lower_bound:
6438 return "DW_AT_lower_bound";
6439 case DW_AT_producer:
6440 return "DW_AT_producer";
6441 case DW_AT_prototyped:
6442 return "DW_AT_prototyped";
6443 case DW_AT_return_addr:
6444 return "DW_AT_return_addr";
6445 case DW_AT_start_scope:
6446 return "DW_AT_start_scope";
6447 case DW_AT_bit_stride:
6448 return "DW_AT_bit_stride";
6449 case DW_AT_upper_bound:
6450 return "DW_AT_upper_bound";
6451 case DW_AT_abstract_origin:
6452 return "DW_AT_abstract_origin";
6453 case DW_AT_accessibility:
6454 return "DW_AT_accessibility";
6455 case DW_AT_address_class:
6456 return "DW_AT_address_class";
6457 case DW_AT_artificial:
6458 return "DW_AT_artificial";
6459 case DW_AT_base_types:
6460 return "DW_AT_base_types";
6461 case DW_AT_calling_convention:
6462 return "DW_AT_calling_convention";
6464 return "DW_AT_count";
6465 case DW_AT_data_member_location:
6466 return "DW_AT_data_member_location";
6467 case DW_AT_decl_column:
6468 return "DW_AT_decl_column";
6469 case DW_AT_decl_file:
6470 return "DW_AT_decl_file";
6471 case DW_AT_decl_line:
6472 return "DW_AT_decl_line";
6473 case DW_AT_declaration:
6474 return "DW_AT_declaration";
6475 case DW_AT_discr_list:
6476 return "DW_AT_discr_list";
6477 case DW_AT_encoding:
6478 return "DW_AT_encoding";
6479 case DW_AT_external:
6480 return "DW_AT_external";
6481 case DW_AT_explicit:
6482 return "DW_AT_explicit";
6483 case DW_AT_frame_base:
6484 return "DW_AT_frame_base";
6486 return "DW_AT_friend";
6487 case DW_AT_identifier_case:
6488 return "DW_AT_identifier_case";
6489 case DW_AT_macro_info:
6490 return "DW_AT_macro_info";
6491 case DW_AT_namelist_items:
6492 return "DW_AT_namelist_items";
6493 case DW_AT_priority:
6494 return "DW_AT_priority";
6496 return "DW_AT_segment";
6497 case DW_AT_specification:
6498 return "DW_AT_specification";
6499 case DW_AT_static_link:
6500 return "DW_AT_static_link";
6502 return "DW_AT_type";
6503 case DW_AT_use_location:
6504 return "DW_AT_use_location";
6505 case DW_AT_variable_parameter:
6506 return "DW_AT_variable_parameter";
6507 case DW_AT_virtuality:
6508 return "DW_AT_virtuality";
6509 case DW_AT_vtable_elem_location:
6510 return "DW_AT_vtable_elem_location";
6512 case DW_AT_allocated:
6513 return "DW_AT_allocated";
6514 case DW_AT_associated:
6515 return "DW_AT_associated";
6516 case DW_AT_data_location:
6517 return "DW_AT_data_location";
6518 case DW_AT_byte_stride:
6519 return "DW_AT_byte_stride";
6520 case DW_AT_entry_pc:
6521 return "DW_AT_entry_pc";
6522 case DW_AT_use_UTF8:
6523 return "DW_AT_use_UTF8";
6524 case DW_AT_extension:
6525 return "DW_AT_extension";
6527 return "DW_AT_ranges";
6528 case DW_AT_trampoline:
6529 return "DW_AT_trampoline";
6530 case DW_AT_call_column:
6531 return "DW_AT_call_column";
6532 case DW_AT_call_file:
6533 return "DW_AT_call_file";
6534 case DW_AT_call_line:
6535 return "DW_AT_call_line";
6537 case DW_AT_MIPS_fde:
6538 return "DW_AT_MIPS_fde";
6539 case DW_AT_MIPS_loop_begin:
6540 return "DW_AT_MIPS_loop_begin";
6541 case DW_AT_MIPS_tail_loop_begin:
6542 return "DW_AT_MIPS_tail_loop_begin";
6543 case DW_AT_MIPS_epilog_begin:
6544 return "DW_AT_MIPS_epilog_begin";
6545 case DW_AT_MIPS_loop_unroll_factor:
6546 return "DW_AT_MIPS_loop_unroll_factor";
6547 case DW_AT_MIPS_software_pipeline_depth:
6548 return "DW_AT_MIPS_software_pipeline_depth";
6549 case DW_AT_MIPS_linkage_name:
6550 return "DW_AT_MIPS_linkage_name";
6551 case DW_AT_MIPS_stride:
6552 return "DW_AT_MIPS_stride";
6553 case DW_AT_MIPS_abstract_name:
6554 return "DW_AT_MIPS_abstract_name";
6555 case DW_AT_MIPS_clone_origin:
6556 return "DW_AT_MIPS_clone_origin";
6557 case DW_AT_MIPS_has_inlines:
6558 return "DW_AT_MIPS_has_inlines";
6560 case DW_AT_sf_names:
6561 return "DW_AT_sf_names";
6562 case DW_AT_src_info:
6563 return "DW_AT_src_info";
6564 case DW_AT_mac_info:
6565 return "DW_AT_mac_info";
6566 case DW_AT_src_coords:
6567 return "DW_AT_src_coords";
6568 case DW_AT_body_begin:
6569 return "DW_AT_body_begin";
6570 case DW_AT_body_end:
6571 return "DW_AT_body_end";
6572 case DW_AT_GNU_vector:
6573 return "DW_AT_GNU_vector";
6574 case DW_AT_GNU_template_name:
6575 return "DW_AT_GNU_template_name";
6577 case DW_AT_VMS_rtnbeg_pd_address:
6578 return "DW_AT_VMS_rtnbeg_pd_address";
6581 return "DW_AT_<unknown>";
6585 /* Convert a DWARF value form code into its string name. */
6588 dwarf_form_name (unsigned int form)
6593 return "DW_FORM_addr";
6594 case DW_FORM_block2:
6595 return "DW_FORM_block2";
6596 case DW_FORM_block4:
6597 return "DW_FORM_block4";
6599 return "DW_FORM_data2";
6601 return "DW_FORM_data4";
6603 return "DW_FORM_data8";
6604 case DW_FORM_string:
6605 return "DW_FORM_string";
6607 return "DW_FORM_block";
6608 case DW_FORM_block1:
6609 return "DW_FORM_block1";
6611 return "DW_FORM_data1";
6613 return "DW_FORM_flag";
6615 return "DW_FORM_sdata";
6617 return "DW_FORM_strp";
6619 return "DW_FORM_udata";
6620 case DW_FORM_ref_addr:
6621 return "DW_FORM_ref_addr";
6623 return "DW_FORM_ref1";
6625 return "DW_FORM_ref2";
6627 return "DW_FORM_ref4";
6629 return "DW_FORM_ref8";
6630 case DW_FORM_ref_udata:
6631 return "DW_FORM_ref_udata";
6632 case DW_FORM_indirect:
6633 return "DW_FORM_indirect";
6635 return "DW_FORM_<unknown>";
6639 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6640 instance of an inlined instance of a decl which is local to an inline
6641 function, so we have to trace all of the way back through the origin chain
6642 to find out what sort of node actually served as the original seed for the
6646 decl_ultimate_origin (const_tree decl)
6648 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6651 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6652 nodes in the function to point to themselves; ignore that if
6653 we're trying to output the abstract instance of this function. */
6654 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6657 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6658 most distant ancestor, this should never happen. */
6659 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6661 return DECL_ABSTRACT_ORIGIN (decl);
6664 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6665 of a virtual function may refer to a base class, so we check the 'this'
6669 decl_class_context (tree decl)
6671 tree context = NULL_TREE;
6673 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6674 context = DECL_CONTEXT (decl);
6676 context = TYPE_MAIN_VARIANT
6677 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6679 if (context && !TYPE_P (context))
6680 context = NULL_TREE;
6685 /* Add an attribute/value pair to a DIE. */
6688 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6690 /* Maybe this should be an assert? */
6694 if (die->die_attr == NULL)
6695 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6696 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6699 static inline enum dw_val_class
6700 AT_class (dw_attr_ref a)
6702 return a->dw_attr_val.val_class;
6705 /* Add a flag value attribute to a DIE. */
6708 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6712 attr.dw_attr = attr_kind;
6713 attr.dw_attr_val.val_class = dw_val_class_flag;
6714 attr.dw_attr_val.v.val_flag = flag;
6715 add_dwarf_attr (die, &attr);
6718 static inline unsigned
6719 AT_flag (dw_attr_ref a)
6721 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6722 return a->dw_attr_val.v.val_flag;
6725 /* Add a signed integer attribute value to a DIE. */
6728 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6732 attr.dw_attr = attr_kind;
6733 attr.dw_attr_val.val_class = dw_val_class_const;
6734 attr.dw_attr_val.v.val_int = int_val;
6735 add_dwarf_attr (die, &attr);
6738 static inline HOST_WIDE_INT
6739 AT_int (dw_attr_ref a)
6741 gcc_assert (a && AT_class (a) == dw_val_class_const);
6742 return a->dw_attr_val.v.val_int;
6745 /* Add an unsigned integer attribute value to a DIE. */
6748 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6749 unsigned HOST_WIDE_INT unsigned_val)
6753 attr.dw_attr = attr_kind;
6754 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6755 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6756 add_dwarf_attr (die, &attr);
6759 static inline unsigned HOST_WIDE_INT
6760 AT_unsigned (dw_attr_ref a)
6762 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6763 return a->dw_attr_val.v.val_unsigned;
6766 /* Add an unsigned double integer attribute value to a DIE. */
6769 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
6770 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
6774 attr.dw_attr = attr_kind;
6775 attr.dw_attr_val.val_class = dw_val_class_const_double;
6776 attr.dw_attr_val.v.val_double.high = high;
6777 attr.dw_attr_val.v.val_double.low = low;
6778 add_dwarf_attr (die, &attr);
6781 /* Add a floating point attribute value to a DIE and return it. */
6784 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6785 unsigned int length, unsigned int elt_size, unsigned char *array)
6789 attr.dw_attr = attr_kind;
6790 attr.dw_attr_val.val_class = dw_val_class_vec;
6791 attr.dw_attr_val.v.val_vec.length = length;
6792 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6793 attr.dw_attr_val.v.val_vec.array = array;
6794 add_dwarf_attr (die, &attr);
6797 /* Hash and equality functions for debug_str_hash. */
6800 debug_str_do_hash (const void *x)
6802 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6806 debug_str_eq (const void *x1, const void *x2)
6808 return strcmp ((((const struct indirect_string_node *)x1)->str),
6809 (const char *)x2) == 0;
6812 /* Add STR to the indirect string hash table. */
6814 static struct indirect_string_node *
6815 find_AT_string (const char *str)
6817 struct indirect_string_node *node;
6820 if (! debug_str_hash)
6821 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6822 debug_str_eq, NULL);
6824 slot = htab_find_slot_with_hash (debug_str_hash, str,
6825 htab_hash_string (str), INSERT);
6828 node = (struct indirect_string_node *)
6829 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6830 node->str = ggc_strdup (str);
6834 node = (struct indirect_string_node *) *slot;
6840 /* Add a string attribute value to a DIE. */
6843 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6846 struct indirect_string_node *node;
6848 node = find_AT_string (str);
6850 attr.dw_attr = attr_kind;
6851 attr.dw_attr_val.val_class = dw_val_class_str;
6852 attr.dw_attr_val.v.val_str = node;
6853 add_dwarf_attr (die, &attr);
6856 /* Create a label for an indirect string node, ensuring it is going to
6857 be output, unless its reference count goes down to zero. */
6860 gen_label_for_indirect_string (struct indirect_string_node *node)
6867 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6868 ++dw2_string_counter;
6869 node->label = xstrdup (label);
6872 /* Create a SYMBOL_REF rtx whose value is the initial address of a
6873 debug string STR. */
6876 get_debug_string_label (const char *str)
6878 struct indirect_string_node *node = find_AT_string (str);
6880 debug_str_hash_forced = true;
6882 gen_label_for_indirect_string (node);
6884 return gen_rtx_SYMBOL_REF (Pmode, node->label);
6887 static inline const char *
6888 AT_string (dw_attr_ref a)
6890 gcc_assert (a && AT_class (a) == dw_val_class_str);
6891 return a->dw_attr_val.v.val_str->str;
6894 /* Find out whether a string should be output inline in DIE
6895 or out-of-line in .debug_str section. */
6897 static enum dwarf_form
6898 AT_string_form (dw_attr_ref a)
6900 struct indirect_string_node *node;
6903 gcc_assert (a && AT_class (a) == dw_val_class_str);
6905 node = a->dw_attr_val.v.val_str;
6909 len = strlen (node->str) + 1;
6911 /* If the string is shorter or equal to the size of the reference, it is
6912 always better to put it inline. */
6913 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6914 return node->form = DW_FORM_string;
6916 /* If we cannot expect the linker to merge strings in .debug_str
6917 section, only put it into .debug_str if it is worth even in this
6919 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
6920 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
6921 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
6922 return node->form = DW_FORM_string;
6924 gen_label_for_indirect_string (node);
6926 return node->form = DW_FORM_strp;
6929 /* Add a DIE reference attribute value to a DIE. */
6932 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6936 attr.dw_attr = attr_kind;
6937 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6938 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6939 attr.dw_attr_val.v.val_die_ref.external = 0;
6940 add_dwarf_attr (die, &attr);
6943 /* Add an AT_specification attribute to a DIE, and also make the back
6944 pointer from the specification to the definition. */
6947 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6949 add_AT_die_ref (die, DW_AT_specification, targ_die);
6950 gcc_assert (!targ_die->die_definition);
6951 targ_die->die_definition = die;
6954 static inline dw_die_ref
6955 AT_ref (dw_attr_ref a)
6957 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6958 return a->dw_attr_val.v.val_die_ref.die;
6962 AT_ref_external (dw_attr_ref a)
6964 if (a && AT_class (a) == dw_val_class_die_ref)
6965 return a->dw_attr_val.v.val_die_ref.external;
6971 set_AT_ref_external (dw_attr_ref a, int i)
6973 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6974 a->dw_attr_val.v.val_die_ref.external = i;
6977 /* Add an FDE reference attribute value to a DIE. */
6980 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6984 attr.dw_attr = attr_kind;
6985 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6986 attr.dw_attr_val.v.val_fde_index = targ_fde;
6987 add_dwarf_attr (die, &attr);
6990 /* Add a location description attribute value to a DIE. */
6993 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6997 attr.dw_attr = attr_kind;
6998 attr.dw_attr_val.val_class = dw_val_class_loc;
6999 attr.dw_attr_val.v.val_loc = loc;
7000 add_dwarf_attr (die, &attr);
7003 static inline dw_loc_descr_ref
7004 AT_loc (dw_attr_ref a)
7006 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7007 return a->dw_attr_val.v.val_loc;
7011 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7015 attr.dw_attr = attr_kind;
7016 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7017 attr.dw_attr_val.v.val_loc_list = loc_list;
7018 add_dwarf_attr (die, &attr);
7019 have_location_lists = true;
7022 static inline dw_loc_list_ref
7023 AT_loc_list (dw_attr_ref a)
7025 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7026 return a->dw_attr_val.v.val_loc_list;
7029 /* Add an address constant attribute value to a DIE. */
7032 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7036 attr.dw_attr = attr_kind;
7037 attr.dw_attr_val.val_class = dw_val_class_addr;
7038 attr.dw_attr_val.v.val_addr = addr;
7039 add_dwarf_attr (die, &attr);
7042 /* Get the RTX from to an address DIE attribute. */
7045 AT_addr (dw_attr_ref a)
7047 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7048 return a->dw_attr_val.v.val_addr;
7051 /* Add a file attribute value to a DIE. */
7054 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7055 struct dwarf_file_data *fd)
7059 attr.dw_attr = attr_kind;
7060 attr.dw_attr_val.val_class = dw_val_class_file;
7061 attr.dw_attr_val.v.val_file = fd;
7062 add_dwarf_attr (die, &attr);
7065 /* Get the dwarf_file_data from a file DIE attribute. */
7067 static inline struct dwarf_file_data *
7068 AT_file (dw_attr_ref a)
7070 gcc_assert (a && AT_class (a) == dw_val_class_file);
7071 return a->dw_attr_val.v.val_file;
7074 /* Add a label identifier attribute value to a DIE. */
7077 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7081 attr.dw_attr = attr_kind;
7082 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7083 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7084 add_dwarf_attr (die, &attr);
7087 /* Add a section offset attribute value to a DIE, an offset into the
7088 debug_line section. */
7091 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7096 attr.dw_attr = attr_kind;
7097 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7098 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7099 add_dwarf_attr (die, &attr);
7102 /* Add a section offset attribute value to a DIE, an offset into the
7103 debug_macinfo section. */
7106 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7111 attr.dw_attr = attr_kind;
7112 attr.dw_attr_val.val_class = dw_val_class_macptr;
7113 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7114 add_dwarf_attr (die, &attr);
7117 /* Add an offset attribute value to a DIE. */
7120 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7121 unsigned HOST_WIDE_INT offset)
7125 attr.dw_attr = attr_kind;
7126 attr.dw_attr_val.val_class = dw_val_class_offset;
7127 attr.dw_attr_val.v.val_offset = offset;
7128 add_dwarf_attr (die, &attr);
7131 /* Add an range_list attribute value to a DIE. */
7134 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7135 long unsigned int offset)
7139 attr.dw_attr = attr_kind;
7140 attr.dw_attr_val.val_class = dw_val_class_range_list;
7141 attr.dw_attr_val.v.val_offset = offset;
7142 add_dwarf_attr (die, &attr);
7145 static inline const char *
7146 AT_lbl (dw_attr_ref a)
7148 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7149 || AT_class (a) == dw_val_class_lineptr
7150 || AT_class (a) == dw_val_class_macptr));
7151 return a->dw_attr_val.v.val_lbl_id;
7154 /* Get the attribute of type attr_kind. */
7157 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7161 dw_die_ref spec = NULL;
7166 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7167 if (a->dw_attr == attr_kind)
7169 else if (a->dw_attr == DW_AT_specification
7170 || a->dw_attr == DW_AT_abstract_origin)
7174 return get_AT (spec, attr_kind);
7179 /* Return the "low pc" attribute value, typically associated with a subprogram
7180 DIE. Return null if the "low pc" attribute is either not present, or if it
7181 cannot be represented as an assembler label identifier. */
7183 static inline const char *
7184 get_AT_low_pc (dw_die_ref die)
7186 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7188 return a ? AT_lbl (a) : NULL;
7191 /* Return the "high pc" attribute value, typically associated with a subprogram
7192 DIE. Return null if the "high pc" attribute is either not present, or if it
7193 cannot be represented as an assembler label identifier. */
7195 static inline const char *
7196 get_AT_hi_pc (dw_die_ref die)
7198 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7200 return a ? AT_lbl (a) : NULL;
7203 /* Return the value of the string attribute designated by ATTR_KIND, or
7204 NULL if it is not present. */
7206 static inline const char *
7207 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7209 dw_attr_ref a = get_AT (die, attr_kind);
7211 return a ? AT_string (a) : NULL;
7214 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7215 if it is not present. */
7218 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7220 dw_attr_ref a = get_AT (die, attr_kind);
7222 return a ? AT_flag (a) : 0;
7225 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7226 if it is not present. */
7228 static inline unsigned
7229 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7231 dw_attr_ref a = get_AT (die, attr_kind);
7233 return a ? AT_unsigned (a) : 0;
7236 static inline dw_die_ref
7237 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7239 dw_attr_ref a = get_AT (die, attr_kind);
7241 return a ? AT_ref (a) : NULL;
7244 static inline struct dwarf_file_data *
7245 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7247 dw_attr_ref a = get_AT (die, attr_kind);
7249 return a ? AT_file (a) : NULL;
7252 /* Return TRUE if the language is C or C++. */
7257 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7259 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
7260 || lang == DW_LANG_C99
7261 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
7264 /* Return TRUE if the language is C++. */
7269 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7271 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7274 /* Return TRUE if the language is Fortran. */
7279 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7281 return (lang == DW_LANG_Fortran77
7282 || lang == DW_LANG_Fortran90
7283 || lang == DW_LANG_Fortran95);
7286 /* Return TRUE if the language is Java. */
7291 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7293 return lang == DW_LANG_Java;
7296 /* Return TRUE if the language is Ada. */
7301 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7303 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7306 /* Remove the specified attribute if present. */
7309 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7317 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7318 if (a->dw_attr == attr_kind)
7320 if (AT_class (a) == dw_val_class_str)
7321 if (a->dw_attr_val.v.val_str->refcount)
7322 a->dw_attr_val.v.val_str->refcount--;
7324 /* VEC_ordered_remove should help reduce the number of abbrevs
7326 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7331 /* Remove CHILD from its parent. PREV must have the property that
7332 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7335 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7337 gcc_assert (child->die_parent == prev->die_parent);
7338 gcc_assert (prev->die_sib == child);
7341 gcc_assert (child->die_parent->die_child == child);
7345 prev->die_sib = child->die_sib;
7346 if (child->die_parent->die_child == child)
7347 child->die_parent->die_child = prev;
7350 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7354 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7360 dw_die_ref prev = c;
7362 while (c->die_tag == tag)
7364 remove_child_with_prev (c, prev);
7365 /* Might have removed every child. */
7366 if (c == c->die_sib)
7370 } while (c != die->die_child);
7373 /* Add a CHILD_DIE as the last child of DIE. */
7376 add_child_die (dw_die_ref die, dw_die_ref child_die)
7378 /* FIXME this should probably be an assert. */
7379 if (! die || ! child_die)
7381 gcc_assert (die != child_die);
7383 child_die->die_parent = die;
7386 child_die->die_sib = die->die_child->die_sib;
7387 die->die_child->die_sib = child_die;
7390 child_die->die_sib = child_die;
7391 die->die_child = child_die;
7394 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7395 is the specification, to the end of PARENT's list of children.
7396 This is done by removing and re-adding it. */
7399 splice_child_die (dw_die_ref parent, dw_die_ref child)
7403 /* We want the declaration DIE from inside the class, not the
7404 specification DIE at toplevel. */
7405 if (child->die_parent != parent)
7407 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7413 gcc_assert (child->die_parent == parent
7414 || (child->die_parent
7415 == get_AT_ref (parent, DW_AT_specification)));
7417 for (p = child->die_parent->die_child; ; p = p->die_sib)
7418 if (p->die_sib == child)
7420 remove_child_with_prev (child, p);
7424 add_child_die (parent, child);
7427 /* Return a pointer to a newly created DIE node. */
7429 static inline dw_die_ref
7430 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7432 dw_die_ref die = GGC_CNEW (die_node);
7434 die->die_tag = tag_value;
7436 if (parent_die != NULL)
7437 add_child_die (parent_die, die);
7440 limbo_die_node *limbo_node;
7442 limbo_node = GGC_CNEW (limbo_die_node);
7443 limbo_node->die = die;
7444 limbo_node->created_for = t;
7445 limbo_node->next = limbo_die_list;
7446 limbo_die_list = limbo_node;
7452 /* Return the DIE associated with the given type specifier. */
7454 static inline dw_die_ref
7455 lookup_type_die (tree type)
7457 return TYPE_SYMTAB_DIE (type);
7460 /* Equate a DIE to a given type specifier. */
7463 equate_type_number_to_die (tree type, dw_die_ref type_die)
7465 TYPE_SYMTAB_DIE (type) = type_die;
7468 /* Returns a hash value for X (which really is a die_struct). */
7471 decl_die_table_hash (const void *x)
7473 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7476 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7479 decl_die_table_eq (const void *x, const void *y)
7481 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7484 /* Return the DIE associated with a given declaration. */
7486 static inline dw_die_ref
7487 lookup_decl_die (tree decl)
7489 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7492 /* Returns a hash value for X (which really is a var_loc_list). */
7495 decl_loc_table_hash (const void *x)
7497 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7500 /* Return nonzero if decl_id of var_loc_list X is the same as
7504 decl_loc_table_eq (const void *x, const void *y)
7506 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7509 /* Return the var_loc list associated with a given declaration. */
7511 static inline var_loc_list *
7512 lookup_decl_loc (const_tree decl)
7514 if (!decl_loc_table)
7516 return (var_loc_list *)
7517 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7520 /* Equate a DIE to a particular declaration. */
7523 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7525 unsigned int decl_id = DECL_UID (decl);
7528 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7530 decl_die->decl_id = decl_id;
7533 /* Add a variable location node to the linked list for DECL. */
7536 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7538 unsigned int decl_id = DECL_UID (decl);
7542 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7545 temp = GGC_CNEW (var_loc_list);
7546 temp->decl_id = decl_id;
7550 temp = (var_loc_list *) *slot;
7554 /* If the current location is the same as the end of the list,
7555 and either both or neither of the locations is uninitialized,
7556 we have nothing to do. */
7557 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7558 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7559 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7560 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7561 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7562 == VAR_INIT_STATUS_UNINITIALIZED)
7563 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7564 == VAR_INIT_STATUS_UNINITIALIZED))))
7566 /* Add LOC to the end of list and update LAST. */
7567 temp->last->next = loc;
7571 /* Do not add empty location to the beginning of the list. */
7572 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7579 /* Keep track of the number of spaces used to indent the
7580 output of the debugging routines that print the structure of
7581 the DIE internal representation. */
7582 static int print_indent;
7584 /* Indent the line the number of spaces given by print_indent. */
7587 print_spaces (FILE *outfile)
7589 fprintf (outfile, "%*s", print_indent, "");
7592 /* Print the information associated with a given DIE, and its children.
7593 This routine is a debugging aid only. */
7596 print_die (dw_die_ref die, FILE *outfile)
7602 print_spaces (outfile);
7603 fprintf (outfile, "DIE %4ld: %s\n",
7604 die->die_offset, dwarf_tag_name (die->die_tag));
7605 print_spaces (outfile);
7606 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7607 fprintf (outfile, " offset: %ld\n", die->die_offset);
7609 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7611 print_spaces (outfile);
7612 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7614 switch (AT_class (a))
7616 case dw_val_class_addr:
7617 fprintf (outfile, "address");
7619 case dw_val_class_offset:
7620 fprintf (outfile, "offset");
7622 case dw_val_class_loc:
7623 fprintf (outfile, "location descriptor");
7625 case dw_val_class_loc_list:
7626 fprintf (outfile, "location list -> label:%s",
7627 AT_loc_list (a)->ll_symbol);
7629 case dw_val_class_range_list:
7630 fprintf (outfile, "range list");
7632 case dw_val_class_const:
7633 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7635 case dw_val_class_unsigned_const:
7636 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7638 case dw_val_class_const_double:
7639 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
7640 HOST_WIDE_INT_PRINT_UNSIGNED")",
7641 a->dw_attr_val.v.val_double.high,
7642 a->dw_attr_val.v.val_double.low);
7644 case dw_val_class_vec:
7645 fprintf (outfile, "floating-point or vector constant");
7647 case dw_val_class_flag:
7648 fprintf (outfile, "%u", AT_flag (a));
7650 case dw_val_class_die_ref:
7651 if (AT_ref (a) != NULL)
7653 if (AT_ref (a)->die_symbol)
7654 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7656 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7659 fprintf (outfile, "die -> <null>");
7661 case dw_val_class_lbl_id:
7662 case dw_val_class_lineptr:
7663 case dw_val_class_macptr:
7664 fprintf (outfile, "label: %s", AT_lbl (a));
7666 case dw_val_class_str:
7667 if (AT_string (a) != NULL)
7668 fprintf (outfile, "\"%s\"", AT_string (a));
7670 fprintf (outfile, "<null>");
7672 case dw_val_class_file:
7673 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7674 AT_file (a)->emitted_number);
7680 fprintf (outfile, "\n");
7683 if (die->die_child != NULL)
7686 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7689 if (print_indent == 0)
7690 fprintf (outfile, "\n");
7693 /* Print the contents of the source code line number correspondence table.
7694 This routine is a debugging aid only. */
7697 print_dwarf_line_table (FILE *outfile)
7700 dw_line_info_ref line_info;
7702 fprintf (outfile, "\n\nDWARF source line information\n");
7703 for (i = 1; i < line_info_table_in_use; i++)
7705 line_info = &line_info_table[i];
7706 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7707 line_info->dw_file_num,
7708 line_info->dw_line_num);
7711 fprintf (outfile, "\n\n");
7714 /* Print the information collected for a given DIE. */
7717 debug_dwarf_die (dw_die_ref die)
7719 print_die (die, stderr);
7722 /* Print all DWARF information collected for the compilation unit.
7723 This routine is a debugging aid only. */
7729 print_die (comp_unit_die, stderr);
7730 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7731 print_dwarf_line_table (stderr);
7734 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7735 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7736 DIE that marks the start of the DIEs for this include file. */
7739 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7741 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7742 dw_die_ref new_unit = gen_compile_unit_die (filename);
7744 new_unit->die_sib = old_unit;
7748 /* Close an include-file CU and reopen the enclosing one. */
7751 pop_compile_unit (dw_die_ref old_unit)
7753 dw_die_ref new_unit = old_unit->die_sib;
7755 old_unit->die_sib = NULL;
7759 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7760 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7762 /* Calculate the checksum of a location expression. */
7765 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7769 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7771 CHECKSUM (loc->dw_loc_oprnd1);
7772 CHECKSUM (loc->dw_loc_oprnd2);
7775 /* Calculate the checksum of an attribute. */
7778 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7780 dw_loc_descr_ref loc;
7783 CHECKSUM (at->dw_attr);
7785 /* We don't care that this was compiled with a different compiler
7786 snapshot; if the output is the same, that's what matters. */
7787 if (at->dw_attr == DW_AT_producer)
7790 switch (AT_class (at))
7792 case dw_val_class_const:
7793 CHECKSUM (at->dw_attr_val.v.val_int);
7795 case dw_val_class_unsigned_const:
7796 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7798 case dw_val_class_const_double:
7799 CHECKSUM (at->dw_attr_val.v.val_double);
7801 case dw_val_class_vec:
7802 CHECKSUM (at->dw_attr_val.v.val_vec);
7804 case dw_val_class_flag:
7805 CHECKSUM (at->dw_attr_val.v.val_flag);
7807 case dw_val_class_str:
7808 CHECKSUM_STRING (AT_string (at));
7811 case dw_val_class_addr:
7813 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7814 CHECKSUM_STRING (XSTR (r, 0));
7817 case dw_val_class_offset:
7818 CHECKSUM (at->dw_attr_val.v.val_offset);
7821 case dw_val_class_loc:
7822 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7823 loc_checksum (loc, ctx);
7826 case dw_val_class_die_ref:
7827 die_checksum (AT_ref (at), ctx, mark);
7830 case dw_val_class_fde_ref:
7831 case dw_val_class_lbl_id:
7832 case dw_val_class_lineptr:
7833 case dw_val_class_macptr:
7836 case dw_val_class_file:
7837 CHECKSUM_STRING (AT_file (at)->filename);
7845 /* Calculate the checksum of a DIE. */
7848 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7854 /* To avoid infinite recursion. */
7857 CHECKSUM (die->die_mark);
7860 die->die_mark = ++(*mark);
7862 CHECKSUM (die->die_tag);
7864 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7865 attr_checksum (a, ctx, mark);
7867 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7871 #undef CHECKSUM_STRING
7873 /* Do the location expressions look same? */
7875 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7877 return loc1->dw_loc_opc == loc2->dw_loc_opc
7878 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7879 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7882 /* Do the values look the same? */
7884 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7886 dw_loc_descr_ref loc1, loc2;
7889 if (v1->val_class != v2->val_class)
7892 switch (v1->val_class)
7894 case dw_val_class_const:
7895 return v1->v.val_int == v2->v.val_int;
7896 case dw_val_class_unsigned_const:
7897 return v1->v.val_unsigned == v2->v.val_unsigned;
7898 case dw_val_class_const_double:
7899 return v1->v.val_double.high == v2->v.val_double.high
7900 && v1->v.val_double.low == v2->v.val_double.low;
7901 case dw_val_class_vec:
7902 if (v1->v.val_vec.length != v2->v.val_vec.length
7903 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7905 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7906 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7909 case dw_val_class_flag:
7910 return v1->v.val_flag == v2->v.val_flag;
7911 case dw_val_class_str:
7912 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7914 case dw_val_class_addr:
7915 r1 = v1->v.val_addr;
7916 r2 = v2->v.val_addr;
7917 if (GET_CODE (r1) != GET_CODE (r2))
7919 return !rtx_equal_p (r1, r2);
7921 case dw_val_class_offset:
7922 return v1->v.val_offset == v2->v.val_offset;
7924 case dw_val_class_loc:
7925 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7927 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7928 if (!same_loc_p (loc1, loc2, mark))
7930 return !loc1 && !loc2;
7932 case dw_val_class_die_ref:
7933 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7935 case dw_val_class_fde_ref:
7936 case dw_val_class_lbl_id:
7937 case dw_val_class_lineptr:
7938 case dw_val_class_macptr:
7941 case dw_val_class_file:
7942 return v1->v.val_file == v2->v.val_file;
7949 /* Do the attributes look the same? */
7952 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7954 if (at1->dw_attr != at2->dw_attr)
7957 /* We don't care that this was compiled with a different compiler
7958 snapshot; if the output is the same, that's what matters. */
7959 if (at1->dw_attr == DW_AT_producer)
7962 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7965 /* Do the dies look the same? */
7968 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7974 /* To avoid infinite recursion. */
7976 return die1->die_mark == die2->die_mark;
7977 die1->die_mark = die2->die_mark = ++(*mark);
7979 if (die1->die_tag != die2->die_tag)
7982 if (VEC_length (dw_attr_node, die1->die_attr)
7983 != VEC_length (dw_attr_node, die2->die_attr))
7986 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7987 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7990 c1 = die1->die_child;
7991 c2 = die2->die_child;
8000 if (!same_die_p (c1, c2, mark))
8004 if (c1 == die1->die_child)
8006 if (c2 == die2->die_child)
8016 /* Do the dies look the same? Wrapper around same_die_p. */
8019 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
8022 int ret = same_die_p (die1, die2, &mark);
8024 unmark_all_dies (die1);
8025 unmark_all_dies (die2);
8030 /* The prefix to attach to symbols on DIEs in the current comdat debug
8032 static char *comdat_symbol_id;
8034 /* The index of the current symbol within the current comdat CU. */
8035 static unsigned int comdat_symbol_number;
8037 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8038 children, and set comdat_symbol_id accordingly. */
8041 compute_section_prefix (dw_die_ref unit_die)
8043 const char *die_name = get_AT_string (unit_die, DW_AT_name);
8044 const char *base = die_name ? lbasename (die_name) : "anonymous";
8045 char *name = XALLOCAVEC (char, strlen (base) + 64);
8048 unsigned char checksum[16];
8051 /* Compute the checksum of the DIE, then append part of it as hex digits to
8052 the name filename of the unit. */
8054 md5_init_ctx (&ctx);
8056 die_checksum (unit_die, &ctx, &mark);
8057 unmark_all_dies (unit_die);
8058 md5_finish_ctx (&ctx, checksum);
8060 sprintf (name, "%s.", base);
8061 clean_symbol_name (name);
8063 p = name + strlen (name);
8064 for (i = 0; i < 4; i++)
8066 sprintf (p, "%.2x", checksum[i]);
8070 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
8071 comdat_symbol_number = 0;
8074 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
8077 is_type_die (dw_die_ref die)
8079 switch (die->die_tag)
8081 case DW_TAG_array_type:
8082 case DW_TAG_class_type:
8083 case DW_TAG_interface_type:
8084 case DW_TAG_enumeration_type:
8085 case DW_TAG_pointer_type:
8086 case DW_TAG_reference_type:
8087 case DW_TAG_string_type:
8088 case DW_TAG_structure_type:
8089 case DW_TAG_subroutine_type:
8090 case DW_TAG_union_type:
8091 case DW_TAG_ptr_to_member_type:
8092 case DW_TAG_set_type:
8093 case DW_TAG_subrange_type:
8094 case DW_TAG_base_type:
8095 case DW_TAG_const_type:
8096 case DW_TAG_file_type:
8097 case DW_TAG_packed_type:
8098 case DW_TAG_volatile_type:
8099 case DW_TAG_typedef:
8106 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
8107 Basically, we want to choose the bits that are likely to be shared between
8108 compilations (types) and leave out the bits that are specific to individual
8109 compilations (functions). */
8112 is_comdat_die (dw_die_ref c)
8114 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
8115 we do for stabs. The advantage is a greater likelihood of sharing between
8116 objects that don't include headers in the same order (and therefore would
8117 put the base types in a different comdat). jason 8/28/00 */
8119 if (c->die_tag == DW_TAG_base_type)
8122 if (c->die_tag == DW_TAG_pointer_type
8123 || c->die_tag == DW_TAG_reference_type
8124 || c->die_tag == DW_TAG_const_type
8125 || c->die_tag == DW_TAG_volatile_type)
8127 dw_die_ref t = get_AT_ref (c, DW_AT_type);
8129 return t ? is_comdat_die (t) : 0;
8132 return is_type_die (c);
8135 /* Returns 1 iff C is the sort of DIE that might be referred to from another
8136 compilation unit. */
8139 is_symbol_die (dw_die_ref c)
8141 return (is_type_die (c)
8142 || (get_AT (c, DW_AT_declaration)
8143 && !get_AT (c, DW_AT_specification))
8144 || c->die_tag == DW_TAG_namespace
8145 || c->die_tag == DW_TAG_module);
8149 gen_internal_sym (const char *prefix)
8153 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8154 return xstrdup (buf);
8157 /* Assign symbols to all worthy DIEs under DIE. */
8160 assign_symbol_names (dw_die_ref die)
8164 if (is_symbol_die (die))
8166 if (comdat_symbol_id)
8168 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
8170 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
8171 comdat_symbol_id, comdat_symbol_number++);
8172 die->die_symbol = xstrdup (p);
8175 die->die_symbol = gen_internal_sym ("LDIE");
8178 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
8181 struct cu_hash_table_entry
8184 unsigned min_comdat_num, max_comdat_num;
8185 struct cu_hash_table_entry *next;
8188 /* Routines to manipulate hash table of CUs. */
8190 htab_cu_hash (const void *of)
8192 const struct cu_hash_table_entry *const entry =
8193 (const struct cu_hash_table_entry *) of;
8195 return htab_hash_string (entry->cu->die_symbol);
8199 htab_cu_eq (const void *of1, const void *of2)
8201 const struct cu_hash_table_entry *const entry1 =
8202 (const struct cu_hash_table_entry *) of1;
8203 const struct die_struct *const entry2 = (const struct die_struct *) of2;
8205 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
8209 htab_cu_del (void *what)
8211 struct cu_hash_table_entry *next,
8212 *entry = (struct cu_hash_table_entry *) what;
8222 /* Check whether we have already seen this CU and set up SYM_NUM
8225 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
8227 struct cu_hash_table_entry dummy;
8228 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
8230 dummy.max_comdat_num = 0;
8232 slot = (struct cu_hash_table_entry **)
8233 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8237 for (; entry; last = entry, entry = entry->next)
8239 if (same_die_p_wrap (cu, entry->cu))
8245 *sym_num = entry->min_comdat_num;
8249 entry = XCNEW (struct cu_hash_table_entry);
8251 entry->min_comdat_num = *sym_num = last->max_comdat_num;
8252 entry->next = *slot;
8258 /* Record SYM_NUM to record of CU in HTABLE. */
8260 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
8262 struct cu_hash_table_entry **slot, *entry;
8264 slot = (struct cu_hash_table_entry **)
8265 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8269 entry->max_comdat_num = sym_num;
8272 /* Traverse the DIE (which is always comp_unit_die), and set up
8273 additional compilation units for each of the include files we see
8274 bracketed by BINCL/EINCL. */
8277 break_out_includes (dw_die_ref die)
8280 dw_die_ref unit = NULL;
8281 limbo_die_node *node, **pnode;
8282 htab_t cu_hash_table;
8286 dw_die_ref prev = c;
8288 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
8289 || (unit && is_comdat_die (c)))
8291 dw_die_ref next = c->die_sib;
8293 /* This DIE is for a secondary CU; remove it from the main one. */
8294 remove_child_with_prev (c, prev);
8296 if (c->die_tag == DW_TAG_GNU_BINCL)
8297 unit = push_new_compile_unit (unit, c);
8298 else if (c->die_tag == DW_TAG_GNU_EINCL)
8299 unit = pop_compile_unit (unit);
8301 add_child_die (unit, c);
8303 if (c == die->die_child)
8306 } while (c != die->die_child);
8309 /* We can only use this in debugging, since the frontend doesn't check
8310 to make sure that we leave every include file we enter. */
8314 assign_symbol_names (die);
8315 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
8316 for (node = limbo_die_list, pnode = &limbo_die_list;
8322 compute_section_prefix (node->die);
8323 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
8324 &comdat_symbol_number);
8325 assign_symbol_names (node->die);
8327 *pnode = node->next;
8330 pnode = &node->next;
8331 record_comdat_symbol_number (node->die, cu_hash_table,
8332 comdat_symbol_number);
8335 htab_delete (cu_hash_table);
8338 /* Traverse the DIE and add a sibling attribute if it may have the
8339 effect of speeding up access to siblings. To save some space,
8340 avoid generating sibling attributes for DIE's without children. */
8343 add_sibling_attributes (dw_die_ref die)
8347 if (! die->die_child)
8350 if (die->die_parent && die != die->die_parent->die_child)
8351 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8353 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8356 /* Output all location lists for the DIE and its children. */
8359 output_location_lists (dw_die_ref die)
8365 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8366 if (AT_class (a) == dw_val_class_loc_list)
8367 output_loc_list (AT_loc_list (a));
8369 FOR_EACH_CHILD (die, c, output_location_lists (c));
8372 /* The format of each DIE (and its attribute value pairs) is encoded in an
8373 abbreviation table. This routine builds the abbreviation table and assigns
8374 a unique abbreviation id for each abbreviation entry. The children of each
8375 die are visited recursively. */
8378 build_abbrev_table (dw_die_ref die)
8380 unsigned long abbrev_id;
8381 unsigned int n_alloc;
8386 /* Scan the DIE references, and mark as external any that refer to
8387 DIEs from other CUs (i.e. those which are not marked). */
8388 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8389 if (AT_class (a) == dw_val_class_die_ref
8390 && AT_ref (a)->die_mark == 0)
8392 gcc_assert (AT_ref (a)->die_symbol);
8393 set_AT_ref_external (a, 1);
8396 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8398 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8399 dw_attr_ref die_a, abbrev_a;
8403 if (abbrev->die_tag != die->die_tag)
8405 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8408 if (VEC_length (dw_attr_node, abbrev->die_attr)
8409 != VEC_length (dw_attr_node, die->die_attr))
8412 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
8414 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8415 if ((abbrev_a->dw_attr != die_a->dw_attr)
8416 || (value_format (abbrev_a) != value_format (die_a)))
8426 if (abbrev_id >= abbrev_die_table_in_use)
8428 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8430 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8431 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8434 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8435 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8436 abbrev_die_table_allocated = n_alloc;
8439 ++abbrev_die_table_in_use;
8440 abbrev_die_table[abbrev_id] = die;
8443 die->die_abbrev = abbrev_id;
8444 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8447 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8450 constant_size (unsigned HOST_WIDE_INT value)
8457 log = floor_log2 (value);
8460 log = 1 << (floor_log2 (log) + 1);
8465 /* Return the size of a DIE as it is represented in the
8466 .debug_info section. */
8468 static unsigned long
8469 size_of_die (dw_die_ref die)
8471 unsigned long size = 0;
8475 size += size_of_uleb128 (die->die_abbrev);
8476 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8478 switch (AT_class (a))
8480 case dw_val_class_addr:
8481 size += DWARF2_ADDR_SIZE;
8483 case dw_val_class_offset:
8484 size += DWARF_OFFSET_SIZE;
8486 case dw_val_class_loc:
8488 unsigned long lsize = size_of_locs (AT_loc (a));
8491 size += constant_size (lsize);
8495 case dw_val_class_loc_list:
8496 size += DWARF_OFFSET_SIZE;
8498 case dw_val_class_range_list:
8499 size += DWARF_OFFSET_SIZE;
8501 case dw_val_class_const:
8502 size += size_of_sleb128 (AT_int (a));
8504 case dw_val_class_unsigned_const:
8505 size += constant_size (AT_unsigned (a));
8507 case dw_val_class_const_double:
8508 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
8509 if (HOST_BITS_PER_WIDE_INT >= 64)
8512 case dw_val_class_vec:
8513 size += constant_size (a->dw_attr_val.v.val_vec.length
8514 * a->dw_attr_val.v.val_vec.elt_size)
8515 + a->dw_attr_val.v.val_vec.length
8516 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8518 case dw_val_class_flag:
8521 case dw_val_class_die_ref:
8522 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8523 whereas in DWARF3 it's always sized as an offset. */
8524 if (AT_ref_external (a) && dwarf_version == 2)
8525 size += DWARF2_ADDR_SIZE;
8527 size += DWARF_OFFSET_SIZE;
8529 case dw_val_class_fde_ref:
8530 size += DWARF_OFFSET_SIZE;
8532 case dw_val_class_lbl_id:
8533 size += DWARF2_ADDR_SIZE;
8535 case dw_val_class_lineptr:
8536 case dw_val_class_macptr:
8537 size += DWARF_OFFSET_SIZE;
8539 case dw_val_class_str:
8540 if (AT_string_form (a) == DW_FORM_strp)
8541 size += DWARF_OFFSET_SIZE;
8543 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8545 case dw_val_class_file:
8546 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8556 /* Size the debugging information associated with a given DIE. Visits the
8557 DIE's children recursively. Updates the global variable next_die_offset, on
8558 each time through. Uses the current value of next_die_offset to update the
8559 die_offset field in each DIE. */
8562 calc_die_sizes (dw_die_ref die)
8566 die->die_offset = next_die_offset;
8567 next_die_offset += size_of_die (die);
8569 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8571 if (die->die_child != NULL)
8572 /* Count the null byte used to terminate sibling lists. */
8573 next_die_offset += 1;
8576 /* Set the marks for a die and its children. We do this so
8577 that we know whether or not a reference needs to use FORM_ref_addr; only
8578 DIEs in the same CU will be marked. We used to clear out the offset
8579 and use that as the flag, but ran into ordering problems. */
8582 mark_dies (dw_die_ref die)
8586 gcc_assert (!die->die_mark);
8589 FOR_EACH_CHILD (die, c, mark_dies (c));
8592 /* Clear the marks for a die and its children. */
8595 unmark_dies (dw_die_ref die)
8599 gcc_assert (die->die_mark);
8602 FOR_EACH_CHILD (die, c, unmark_dies (c));
8605 /* Clear the marks for a die, its children and referred dies. */
8608 unmark_all_dies (dw_die_ref die)
8618 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8620 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8621 if (AT_class (a) == dw_val_class_die_ref)
8622 unmark_all_dies (AT_ref (a));
8625 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8626 generated for the compilation unit. */
8628 static unsigned long
8629 size_of_pubnames (VEC (pubname_entry, gc) * names)
8635 size = DWARF_PUBNAMES_HEADER_SIZE;
8636 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8637 if (names != pubtype_table
8638 || p->die->die_offset != 0
8639 || !flag_eliminate_unused_debug_types)
8640 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8642 size += DWARF_OFFSET_SIZE;
8646 /* Return the size of the information in the .debug_aranges section. */
8648 static unsigned long
8649 size_of_aranges (void)
8653 size = DWARF_ARANGES_HEADER_SIZE;
8655 /* Count the address/length pair for this compilation unit. */
8656 if (text_section_used)
8657 size += 2 * DWARF2_ADDR_SIZE;
8658 if (cold_text_section_used)
8659 size += 2 * DWARF2_ADDR_SIZE;
8660 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8662 /* Count the two zero words used to terminated the address range table. */
8663 size += 2 * DWARF2_ADDR_SIZE;
8667 /* Select the encoding of an attribute value. */
8669 static enum dwarf_form
8670 value_format (dw_attr_ref a)
8672 switch (a->dw_attr_val.val_class)
8674 case dw_val_class_addr:
8675 /* Only very few attributes allow DW_FORM_addr. */
8680 case DW_AT_entry_pc:
8681 case DW_AT_trampoline:
8682 return DW_FORM_addr;
8686 switch (DWARF2_ADDR_SIZE)
8689 return DW_FORM_data1;
8691 return DW_FORM_data2;
8693 return DW_FORM_data4;
8695 return DW_FORM_data8;
8699 case dw_val_class_range_list:
8700 case dw_val_class_offset:
8701 case dw_val_class_loc_list:
8702 switch (DWARF_OFFSET_SIZE)
8705 return DW_FORM_data4;
8707 return DW_FORM_data8;
8711 case dw_val_class_loc:
8712 switch (constant_size (size_of_locs (AT_loc (a))))
8715 return DW_FORM_block1;
8717 return DW_FORM_block2;
8721 case dw_val_class_const:
8722 return DW_FORM_sdata;
8723 case dw_val_class_unsigned_const:
8724 switch (constant_size (AT_unsigned (a)))
8727 return DW_FORM_data1;
8729 return DW_FORM_data2;
8731 return DW_FORM_data4;
8733 return DW_FORM_data8;
8737 case dw_val_class_const_double:
8738 switch (HOST_BITS_PER_WIDE_INT)
8741 return DW_FORM_data2;
8743 return DW_FORM_data4;
8745 return DW_FORM_data8;
8748 return DW_FORM_block1;
8750 case dw_val_class_vec:
8751 switch (constant_size (a->dw_attr_val.v.val_vec.length
8752 * a->dw_attr_val.v.val_vec.elt_size))
8755 return DW_FORM_block1;
8757 return DW_FORM_block2;
8759 return DW_FORM_block4;
8763 case dw_val_class_flag:
8764 return DW_FORM_flag;
8765 case dw_val_class_die_ref:
8766 if (AT_ref_external (a))
8767 return DW_FORM_ref_addr;
8770 case dw_val_class_fde_ref:
8771 return DW_FORM_data;
8772 case dw_val_class_lbl_id:
8773 return DW_FORM_addr;
8774 case dw_val_class_lineptr:
8775 case dw_val_class_macptr:
8776 return DW_FORM_data;
8777 case dw_val_class_str:
8778 return AT_string_form (a);
8779 case dw_val_class_file:
8780 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8783 return DW_FORM_data1;
8785 return DW_FORM_data2;
8787 return DW_FORM_data4;
8797 /* Output the encoding of an attribute value. */
8800 output_value_format (dw_attr_ref a)
8802 enum dwarf_form form = value_format (a);
8804 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8807 /* Output the .debug_abbrev section which defines the DIE abbreviation
8811 output_abbrev_section (void)
8813 unsigned long abbrev_id;
8815 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8817 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8821 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8822 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8823 dwarf_tag_name (abbrev->die_tag));
8825 if (abbrev->die_child != NULL)
8826 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8828 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8830 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8833 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8834 dwarf_attr_name (a_attr->dw_attr));
8835 output_value_format (a_attr);
8838 dw2_asm_output_data (1, 0, NULL);
8839 dw2_asm_output_data (1, 0, NULL);
8842 /* Terminate the table. */
8843 dw2_asm_output_data (1, 0, NULL);
8846 /* Output a symbol we can use to refer to this DIE from another CU. */
8849 output_die_symbol (dw_die_ref die)
8851 char *sym = die->die_symbol;
8856 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8857 /* We make these global, not weak; if the target doesn't support
8858 .linkonce, it doesn't support combining the sections, so debugging
8860 targetm.asm_out.globalize_label (asm_out_file, sym);
8862 ASM_OUTPUT_LABEL (asm_out_file, sym);
8865 /* Return a new location list, given the begin and end range, and the
8866 expression. gensym tells us whether to generate a new internal symbol for
8867 this location list node, which is done for the head of the list only. */
8869 static inline dw_loc_list_ref
8870 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8871 const char *section, unsigned int gensym)
8873 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8875 retlist->begin = begin;
8877 retlist->expr = expr;
8878 retlist->section = section;
8880 retlist->ll_symbol = gen_internal_sym ("LLST");
8885 /* Add a location description expression to a location list. */
8888 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8889 const char *begin, const char *end,
8890 const char *section)
8894 /* Find the end of the chain. */
8895 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8898 /* Add a new location list node to the list. */
8899 *d = new_loc_list (descr, begin, end, section, 0);
8902 /* Output the location list given to us. */
8905 output_loc_list (dw_loc_list_ref list_head)
8907 dw_loc_list_ref curr = list_head;
8909 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8911 /* Walk the location list, and output each range + expression. */
8912 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8915 /* Don't output an entry that starts and ends at the same address. */
8916 if (strcmp (curr->begin, curr->end) == 0)
8918 if (!have_multiple_function_sections)
8920 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8921 "Location list begin address (%s)",
8922 list_head->ll_symbol);
8923 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8924 "Location list end address (%s)",
8925 list_head->ll_symbol);
8929 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8930 "Location list begin address (%s)",
8931 list_head->ll_symbol);
8932 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8933 "Location list end address (%s)",
8934 list_head->ll_symbol);
8936 size = size_of_locs (curr->expr);
8938 /* Output the block length for this list of location operations. */
8939 gcc_assert (size <= 0xffff);
8940 dw2_asm_output_data (2, size, "%s", "Location expression size");
8942 output_loc_sequence (curr->expr);
8945 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8946 "Location list terminator begin (%s)",
8947 list_head->ll_symbol);
8948 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8949 "Location list terminator end (%s)",
8950 list_head->ll_symbol);
8953 /* Output the DIE and its attributes. Called recursively to generate
8954 the definitions of each child DIE. */
8957 output_die (dw_die_ref die)
8964 /* If someone in another CU might refer to us, set up a symbol for
8965 them to point to. */
8966 if (die->die_symbol)
8967 output_die_symbol (die);
8969 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8970 (unsigned long)die->die_offset,
8971 dwarf_tag_name (die->die_tag));
8973 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8975 const char *name = dwarf_attr_name (a->dw_attr);
8977 switch (AT_class (a))
8979 case dw_val_class_addr:
8980 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8983 case dw_val_class_offset:
8984 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8988 case dw_val_class_range_list:
8990 char *p = strchr (ranges_section_label, '\0');
8992 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8993 a->dw_attr_val.v.val_offset);
8994 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8995 debug_ranges_section, "%s", name);
9000 case dw_val_class_loc:
9001 size = size_of_locs (AT_loc (a));
9003 /* Output the block length for this list of location operations. */
9004 dw2_asm_output_data (constant_size (size), size, "%s", name);
9006 output_loc_sequence (AT_loc (a));
9009 case dw_val_class_const:
9010 /* ??? It would be slightly more efficient to use a scheme like is
9011 used for unsigned constants below, but gdb 4.x does not sign
9012 extend. Gdb 5.x does sign extend. */
9013 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
9016 case dw_val_class_unsigned_const:
9017 dw2_asm_output_data (constant_size (AT_unsigned (a)),
9018 AT_unsigned (a), "%s", name);
9021 case dw_val_class_const_double:
9023 unsigned HOST_WIDE_INT first, second;
9025 if (HOST_BITS_PER_WIDE_INT >= 64)
9026 dw2_asm_output_data (1,
9027 2 * HOST_BITS_PER_WIDE_INT
9028 / HOST_BITS_PER_CHAR,
9031 if (WORDS_BIG_ENDIAN)
9033 first = a->dw_attr_val.v.val_double.high;
9034 second = a->dw_attr_val.v.val_double.low;
9038 first = a->dw_attr_val.v.val_double.low;
9039 second = a->dw_attr_val.v.val_double.high;
9042 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
9044 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
9049 case dw_val_class_vec:
9051 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
9052 unsigned int len = a->dw_attr_val.v.val_vec.length;
9056 dw2_asm_output_data (constant_size (len * elt_size),
9057 len * elt_size, "%s", name);
9058 if (elt_size > sizeof (HOST_WIDE_INT))
9063 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
9066 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
9067 "fp or vector constant word %u", i);
9071 case dw_val_class_flag:
9072 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9075 case dw_val_class_loc_list:
9077 char *sym = AT_loc_list (a)->ll_symbol;
9080 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
9085 case dw_val_class_die_ref:
9086 if (AT_ref_external (a))
9088 char *sym = AT_ref (a)->die_symbol;
9093 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9094 length, whereas in DWARF3 it's always sized as an offset. */
9095 if (dwarf_version == 2)
9096 size = DWARF2_ADDR_SIZE;
9098 size = DWARF_OFFSET_SIZE;
9099 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
9103 gcc_assert (AT_ref (a)->die_offset);
9104 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9109 case dw_val_class_fde_ref:
9113 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9114 a->dw_attr_val.v.val_fde_index * 2);
9115 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9120 case dw_val_class_lbl_id:
9121 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
9124 case dw_val_class_lineptr:
9125 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9126 debug_line_section, "%s", name);
9129 case dw_val_class_macptr:
9130 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9131 debug_macinfo_section, "%s", name);
9134 case dw_val_class_str:
9135 if (AT_string_form (a) == DW_FORM_strp)
9136 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9137 a->dw_attr_val.v.val_str->label,
9139 "%s: \"%s\"", name, AT_string (a));
9141 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9144 case dw_val_class_file:
9146 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9148 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9149 a->dw_attr_val.v.val_file->filename);
9158 FOR_EACH_CHILD (die, c, output_die (c));
9160 /* Add null byte to terminate sibling list. */
9161 if (die->die_child != NULL)
9162 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
9163 (unsigned long) die->die_offset);
9166 /* Output the compilation unit that appears at the beginning of the
9167 .debug_info section, and precedes the DIE descriptions. */
9170 output_compilation_unit_header (void)
9172 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9173 dw2_asm_output_data (4, 0xffffffff,
9174 "Initial length escape value indicating 64-bit DWARF extension");
9175 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9176 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9177 "Length of Compilation Unit Info");
9178 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
9179 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9180 debug_abbrev_section,
9181 "Offset Into Abbrev. Section");
9182 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9185 /* Output the compilation unit DIE and its children. */
9188 output_comp_unit (dw_die_ref die, int output_if_empty)
9190 const char *secname;
9193 /* Unless we are outputting main CU, we may throw away empty ones. */
9194 if (!output_if_empty && die->die_child == NULL)
9197 /* Even if there are no children of this DIE, we must output the information
9198 about the compilation unit. Otherwise, on an empty translation unit, we
9199 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9200 will then complain when examining the file. First mark all the DIEs in
9201 this CU so we know which get local refs. */
9204 build_abbrev_table (die);
9206 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9207 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9208 calc_die_sizes (die);
9210 oldsym = die->die_symbol;
9213 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9215 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9217 die->die_symbol = NULL;
9218 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9221 switch_to_section (debug_info_section);
9223 /* Output debugging information. */
9224 output_compilation_unit_header ();
9227 /* Leave the marks on the main CU, so we can check them in
9232 die->die_symbol = oldsym;
9236 /* Return the DWARF2/3 pubname associated with a decl. */
9239 dwarf2_name (tree decl, int scope)
9241 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9244 /* Add a new entry to .debug_pubnames if appropriate. */
9247 add_pubname_string (const char *str, dw_die_ref die)
9252 e.name = xstrdup (str);
9253 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9257 add_pubname (tree decl, dw_die_ref die)
9259 if (TREE_PUBLIC (decl))
9260 add_pubname_string (dwarf2_name (decl, 1), die);
9263 /* Add a new entry to .debug_pubtypes if appropriate. */
9266 add_pubtype (tree decl, dw_die_ref die)
9271 if ((TREE_PUBLIC (decl)
9272 || die->die_parent == comp_unit_die)
9273 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9278 if (TYPE_NAME (decl))
9280 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9281 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9282 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9283 && DECL_NAME (TYPE_NAME (decl)))
9284 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9286 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9290 e.name = xstrdup (dwarf2_name (decl, 1));
9292 /* If we don't have a name for the type, there's no point in adding
9294 if (e.name && e.name[0] != '\0')
9295 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9299 /* Output the public names table used to speed up access to externally
9300 visible names; or the public types table used to find type definitions. */
9303 output_pubnames (VEC (pubname_entry, gc) * names)
9306 unsigned long pubnames_length = size_of_pubnames (names);
9309 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9310 dw2_asm_output_data (4, 0xffffffff,
9311 "Initial length escape value indicating 64-bit DWARF extension");
9312 if (names == pubname_table)
9313 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9314 "Length of Public Names Info");
9316 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9317 "Length of Public Type Names Info");
9318 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9319 dw2_asm_output_data (2, 2, "DWARF Version");
9320 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9322 "Offset of Compilation Unit Info");
9323 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9324 "Compilation Unit Length");
9326 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
9328 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9329 if (names == pubname_table)
9330 gcc_assert (pub->die->die_mark);
9332 if (names != pubtype_table
9333 || pub->die->die_offset != 0
9334 || !flag_eliminate_unused_debug_types)
9336 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9339 dw2_asm_output_nstring (pub->name, -1, "external name");
9343 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9346 /* Add a new entry to .debug_aranges if appropriate. */
9349 add_arange (tree decl, dw_die_ref die)
9351 if (! DECL_SECTION_NAME (decl))
9354 if (arange_table_in_use == arange_table_allocated)
9356 arange_table_allocated += ARANGE_TABLE_INCREMENT;
9357 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
9358 arange_table_allocated);
9359 memset (arange_table + arange_table_in_use, 0,
9360 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
9363 arange_table[arange_table_in_use++] = die;
9366 /* Output the information that goes into the .debug_aranges table.
9367 Namely, define the beginning and ending address range of the
9368 text section generated for this compilation unit. */
9371 output_aranges (void)
9374 unsigned long aranges_length = size_of_aranges ();
9376 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9377 dw2_asm_output_data (4, 0xffffffff,
9378 "Initial length escape value indicating 64-bit DWARF extension");
9379 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9380 "Length of Address Ranges Info");
9381 /* Version number for aranges is still 2, even in DWARF3. */
9382 dw2_asm_output_data (2, 2, "DWARF Version");
9383 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9385 "Offset of Compilation Unit Info");
9386 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9387 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9389 /* We need to align to twice the pointer size here. */
9390 if (DWARF_ARANGES_PAD_SIZE)
9392 /* Pad using a 2 byte words so that padding is correct for any
9394 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9395 2 * DWARF2_ADDR_SIZE);
9396 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9397 dw2_asm_output_data (2, 0, NULL);
9400 /* It is necessary not to output these entries if the sections were
9401 not used; if the sections were not used, the length will be 0 and
9402 the address may end up as 0 if the section is discarded by ld
9403 --gc-sections, leaving an invalid (0, 0) entry that can be
9404 confused with the terminator. */
9405 if (text_section_used)
9407 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9408 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9409 text_section_label, "Length");
9411 if (cold_text_section_used)
9413 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9415 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9416 cold_text_section_label, "Length");
9419 for (i = 0; i < arange_table_in_use; i++)
9421 dw_die_ref die = arange_table[i];
9423 /* We shouldn't see aranges for DIEs outside of the main CU. */
9424 gcc_assert (die->die_mark);
9426 if (die->die_tag == DW_TAG_subprogram)
9428 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
9430 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
9431 get_AT_low_pc (die), "Length");
9435 /* A static variable; extract the symbol from DW_AT_location.
9436 Note that this code isn't currently hit, as we only emit
9437 aranges for functions (jason 9/23/99). */
9438 dw_attr_ref a = get_AT (die, DW_AT_location);
9439 dw_loc_descr_ref loc;
9441 gcc_assert (a && AT_class (a) == dw_val_class_loc);
9444 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
9446 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
9447 loc->dw_loc_oprnd1.v.val_addr, "Address");
9448 dw2_asm_output_data (DWARF2_ADDR_SIZE,
9449 get_AT_unsigned (die, DW_AT_byte_size),
9454 /* Output the terminator words. */
9455 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9456 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9459 /* Add a new entry to .debug_ranges. Return the offset at which it
9463 add_ranges_num (int num)
9465 unsigned int in_use = ranges_table_in_use;
9467 if (in_use == ranges_table_allocated)
9469 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9470 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9471 ranges_table_allocated);
9472 memset (ranges_table + ranges_table_in_use, 0,
9473 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9476 ranges_table[in_use].num = num;
9477 ranges_table_in_use = in_use + 1;
9479 return in_use * 2 * DWARF2_ADDR_SIZE;
9482 /* Add a new entry to .debug_ranges corresponding to a block, or a
9483 range terminator if BLOCK is NULL. */
9486 add_ranges (const_tree block)
9488 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9491 /* Add a new entry to .debug_ranges corresponding to a pair of
9495 add_ranges_by_labels (const char *begin, const char *end)
9497 unsigned int in_use = ranges_by_label_in_use;
9499 if (in_use == ranges_by_label_allocated)
9501 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9502 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9504 ranges_by_label_allocated);
9505 memset (ranges_by_label + ranges_by_label_in_use, 0,
9506 RANGES_TABLE_INCREMENT
9507 * sizeof (struct dw_ranges_by_label_struct));
9510 ranges_by_label[in_use].begin = begin;
9511 ranges_by_label[in_use].end = end;
9512 ranges_by_label_in_use = in_use + 1;
9514 return add_ranges_num (-(int)in_use - 1);
9518 output_ranges (void)
9521 static const char *const start_fmt = "Offset 0x%x";
9522 const char *fmt = start_fmt;
9524 for (i = 0; i < ranges_table_in_use; i++)
9526 int block_num = ranges_table[i].num;
9530 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9531 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9533 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9534 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9536 /* If all code is in the text section, then the compilation
9537 unit base address defaults to DW_AT_low_pc, which is the
9538 base of the text section. */
9539 if (!have_multiple_function_sections)
9541 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9543 fmt, i * 2 * DWARF2_ADDR_SIZE);
9544 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9545 text_section_label, NULL);
9548 /* Otherwise, the compilation unit base address is zero,
9549 which allows us to use absolute addresses, and not worry
9550 about whether the target supports cross-section
9554 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9555 fmt, i * 2 * DWARF2_ADDR_SIZE);
9556 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9562 /* Negative block_num stands for an index into ranges_by_label. */
9563 else if (block_num < 0)
9565 int lab_idx = - block_num - 1;
9567 if (!have_multiple_function_sections)
9571 /* If we ever use add_ranges_by_labels () for a single
9572 function section, all we have to do is to take out
9574 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9575 ranges_by_label[lab_idx].begin,
9577 fmt, i * 2 * DWARF2_ADDR_SIZE);
9578 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9579 ranges_by_label[lab_idx].end,
9580 text_section_label, NULL);
9585 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9586 ranges_by_label[lab_idx].begin,
9587 fmt, i * 2 * DWARF2_ADDR_SIZE);
9588 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9589 ranges_by_label[lab_idx].end,
9595 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9596 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9602 /* Data structure containing information about input files. */
9605 const char *path; /* Complete file name. */
9606 const char *fname; /* File name part. */
9607 int length; /* Length of entire string. */
9608 struct dwarf_file_data * file_idx; /* Index in input file table. */
9609 int dir_idx; /* Index in directory table. */
9612 /* Data structure containing information about directories with source
9616 const char *path; /* Path including directory name. */
9617 int length; /* Path length. */
9618 int prefix; /* Index of directory entry which is a prefix. */
9619 int count; /* Number of files in this directory. */
9620 int dir_idx; /* Index of directory used as base. */
9623 /* Callback function for file_info comparison. We sort by looking at
9624 the directories in the path. */
9627 file_info_cmp (const void *p1, const void *p2)
9629 const struct file_info *const s1 = (const struct file_info *) p1;
9630 const struct file_info *const s2 = (const struct file_info *) p2;
9631 const unsigned char *cp1;
9632 const unsigned char *cp2;
9634 /* Take care of file names without directories. We need to make sure that
9635 we return consistent values to qsort since some will get confused if
9636 we return the same value when identical operands are passed in opposite
9637 orders. So if neither has a directory, return 0 and otherwise return
9638 1 or -1 depending on which one has the directory. */
9639 if ((s1->path == s1->fname || s2->path == s2->fname))
9640 return (s2->path == s2->fname) - (s1->path == s1->fname);
9642 cp1 = (const unsigned char *) s1->path;
9643 cp2 = (const unsigned char *) s2->path;
9649 /* Reached the end of the first path? If so, handle like above. */
9650 if ((cp1 == (const unsigned char *) s1->fname)
9651 || (cp2 == (const unsigned char *) s2->fname))
9652 return ((cp2 == (const unsigned char *) s2->fname)
9653 - (cp1 == (const unsigned char *) s1->fname));
9655 /* Character of current path component the same? */
9656 else if (*cp1 != *cp2)
9661 struct file_name_acquire_data
9663 struct file_info *files;
9668 /* Traversal function for the hash table. */
9671 file_name_acquire (void ** slot, void *data)
9673 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9674 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9675 struct file_info *fi;
9678 gcc_assert (fnad->max_files >= d->emitted_number);
9680 if (! d->emitted_number)
9683 gcc_assert (fnad->max_files != fnad->used_files);
9685 fi = fnad->files + fnad->used_files++;
9687 /* Skip all leading "./". */
9689 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9692 /* Create a new array entry. */
9694 fi->length = strlen (f);
9697 /* Search for the file name part. */
9698 f = strrchr (f, DIR_SEPARATOR);
9699 #if defined (DIR_SEPARATOR_2)
9701 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9705 if (f == NULL || f < g)
9711 fi->fname = f == NULL ? fi->path : f + 1;
9715 /* Output the directory table and the file name table. We try to minimize
9716 the total amount of memory needed. A heuristic is used to avoid large
9717 slowdowns with many input files. */
9720 output_file_names (void)
9722 struct file_name_acquire_data fnad;
9724 struct file_info *files;
9725 struct dir_info *dirs;
9734 if (!last_emitted_file)
9736 dw2_asm_output_data (1, 0, "End directory table");
9737 dw2_asm_output_data (1, 0, "End file name table");
9741 numfiles = last_emitted_file->emitted_number;
9743 /* Allocate the various arrays we need. */
9744 files = XALLOCAVEC (struct file_info, numfiles);
9745 dirs = XALLOCAVEC (struct dir_info, numfiles);
9748 fnad.used_files = 0;
9749 fnad.max_files = numfiles;
9750 htab_traverse (file_table, file_name_acquire, &fnad);
9751 gcc_assert (fnad.used_files == fnad.max_files);
9753 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9755 /* Find all the different directories used. */
9756 dirs[0].path = files[0].path;
9757 dirs[0].length = files[0].fname - files[0].path;
9758 dirs[0].prefix = -1;
9760 dirs[0].dir_idx = 0;
9761 files[0].dir_idx = 0;
9764 for (i = 1; i < numfiles; i++)
9765 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9766 && memcmp (dirs[ndirs - 1].path, files[i].path,
9767 dirs[ndirs - 1].length) == 0)
9769 /* Same directory as last entry. */
9770 files[i].dir_idx = ndirs - 1;
9771 ++dirs[ndirs - 1].count;
9777 /* This is a new directory. */
9778 dirs[ndirs].path = files[i].path;
9779 dirs[ndirs].length = files[i].fname - files[i].path;
9780 dirs[ndirs].count = 1;
9781 dirs[ndirs].dir_idx = ndirs;
9782 files[i].dir_idx = ndirs;
9784 /* Search for a prefix. */
9785 dirs[ndirs].prefix = -1;
9786 for (j = 0; j < ndirs; j++)
9787 if (dirs[j].length < dirs[ndirs].length
9788 && dirs[j].length > 1
9789 && (dirs[ndirs].prefix == -1
9790 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9791 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9792 dirs[ndirs].prefix = j;
9797 /* Now to the actual work. We have to find a subset of the directories which
9798 allow expressing the file name using references to the directory table
9799 with the least amount of characters. We do not do an exhaustive search
9800 where we would have to check out every combination of every single
9801 possible prefix. Instead we use a heuristic which provides nearly optimal
9802 results in most cases and never is much off. */
9803 saved = XALLOCAVEC (int, ndirs);
9804 savehere = XALLOCAVEC (int, ndirs);
9806 memset (saved, '\0', ndirs * sizeof (saved[0]));
9807 for (i = 0; i < ndirs; i++)
9812 /* We can always save some space for the current directory. But this
9813 does not mean it will be enough to justify adding the directory. */
9814 savehere[i] = dirs[i].length;
9815 total = (savehere[i] - saved[i]) * dirs[i].count;
9817 for (j = i + 1; j < ndirs; j++)
9820 if (saved[j] < dirs[i].length)
9822 /* Determine whether the dirs[i] path is a prefix of the
9827 while (k != -1 && k != (int) i)
9832 /* Yes it is. We can possibly save some memory by
9833 writing the filenames in dirs[j] relative to
9835 savehere[j] = dirs[i].length;
9836 total += (savehere[j] - saved[j]) * dirs[j].count;
9841 /* Check whether we can save enough to justify adding the dirs[i]
9843 if (total > dirs[i].length + 1)
9845 /* It's worthwhile adding. */
9846 for (j = i; j < ndirs; j++)
9847 if (savehere[j] > 0)
9849 /* Remember how much we saved for this directory so far. */
9850 saved[j] = savehere[j];
9852 /* Remember the prefix directory. */
9853 dirs[j].dir_idx = i;
9858 /* Emit the directory name table. */
9860 idx_offset = dirs[0].length > 0 ? 1 : 0;
9861 for (i = 1 - idx_offset; i < ndirs; i++)
9862 dw2_asm_output_nstring (dirs[i].path,
9864 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9865 "Directory Entry: 0x%x", i + idx_offset);
9867 dw2_asm_output_data (1, 0, "End directory table");
9869 /* We have to emit them in the order of emitted_number since that's
9870 used in the debug info generation. To do this efficiently we
9871 generate a back-mapping of the indices first. */
9872 backmap = XALLOCAVEC (int, numfiles);
9873 for (i = 0; i < numfiles; i++)
9874 backmap[files[i].file_idx->emitted_number - 1] = i;
9876 /* Now write all the file names. */
9877 for (i = 0; i < numfiles; i++)
9879 int file_idx = backmap[i];
9880 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9882 #ifdef VMS_DEBUGGING_INFO
9883 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9885 /* Setting these fields can lead to debugger miscomparisons,
9886 but VMS Debug requires them to be set correctly. */
9891 int maxfilelen = strlen (files[file_idx].path)
9892 + dirs[dir_idx].length
9893 + MAX_VMS_VERSION_LEN + 1;
9894 char *filebuf = XALLOCAVEC (char, maxfilelen);
9896 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9897 snprintf (filebuf, maxfilelen, "%s;%d",
9898 files[file_idx].path + dirs[dir_idx].length, ver);
9900 dw2_asm_output_nstring
9901 (filebuf, -1, "File Entry: 0x%x", (unsigned) i + 1);
9903 /* Include directory index. */
9904 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9906 /* Modification time. */
9907 dw2_asm_output_data_uleb128
9908 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9912 /* File length in bytes. */
9913 dw2_asm_output_data_uleb128
9914 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9918 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9919 "File Entry: 0x%x", (unsigned) i + 1);
9921 /* Include directory index. */
9922 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9924 /* Modification time. */
9925 dw2_asm_output_data_uleb128 (0, NULL);
9927 /* File length in bytes. */
9928 dw2_asm_output_data_uleb128 (0, NULL);
9932 dw2_asm_output_data (1, 0, "End file name table");
9936 /* Output the source line number correspondence information. This
9937 information goes into the .debug_line section. */
9940 output_line_info (void)
9942 char l1[20], l2[20], p1[20], p2[20];
9943 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9944 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9947 unsigned long lt_index;
9948 unsigned long current_line;
9951 unsigned long current_file;
9952 unsigned long function;
9954 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9955 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9956 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9957 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9959 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9960 dw2_asm_output_data (4, 0xffffffff,
9961 "Initial length escape value indicating 64-bit DWARF extension");
9962 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9963 "Length of Source Line Info");
9964 ASM_OUTPUT_LABEL (asm_out_file, l1);
9966 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9967 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9968 ASM_OUTPUT_LABEL (asm_out_file, p1);
9970 /* Define the architecture-dependent minimum instruction length (in
9971 bytes). In this implementation of DWARF, this field is used for
9972 information purposes only. Since GCC generates assembly language,
9973 we have no a priori knowledge of how many instruction bytes are
9974 generated for each source line, and therefore can use only the
9975 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9976 commands. Accordingly, we fix this as `1', which is "correct
9977 enough" for all architectures, and don't let the target override. */
9978 dw2_asm_output_data (1, 1,
9979 "Minimum Instruction Length");
9981 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9982 "Default is_stmt_start flag");
9983 dw2_asm_output_data (1, DWARF_LINE_BASE,
9984 "Line Base Value (Special Opcodes)");
9985 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9986 "Line Range Value (Special Opcodes)");
9987 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9988 "Special Opcode Base");
9990 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9994 case DW_LNS_advance_pc:
9995 case DW_LNS_advance_line:
9996 case DW_LNS_set_file:
9997 case DW_LNS_set_column:
9998 case DW_LNS_fixed_advance_pc:
10006 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
10010 /* Write out the information about the files we use. */
10011 output_file_names ();
10012 ASM_OUTPUT_LABEL (asm_out_file, p2);
10014 /* We used to set the address register to the first location in the text
10015 section here, but that didn't accomplish anything since we already
10016 have a line note for the opening brace of the first function. */
10018 /* Generate the line number to PC correspondence table, encoded as
10019 a series of state machine operations. */
10023 if (cfun && in_cold_section_p)
10024 strcpy (prev_line_label, crtl->subsections.cold_section_label);
10026 strcpy (prev_line_label, text_section_label);
10027 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
10029 dw_line_info_ref line_info = &line_info_table[lt_index];
10032 /* Disable this optimization for now; GDB wants to see two line notes
10033 at the beginning of a function so it can find the end of the
10036 /* Don't emit anything for redundant notes. Just updating the
10037 address doesn't accomplish anything, because we already assume
10038 that anything after the last address is this line. */
10039 if (line_info->dw_line_num == current_line
10040 && line_info->dw_file_num == current_file)
10044 /* Emit debug info for the address of the current line.
10046 Unfortunately, we have little choice here currently, and must always
10047 use the most general form. GCC does not know the address delta
10048 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
10049 attributes which will give an upper bound on the address range. We
10050 could perhaps use length attributes to determine when it is safe to
10051 use DW_LNS_fixed_advance_pc. */
10053 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
10056 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
10057 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10058 "DW_LNS_fixed_advance_pc");
10059 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10063 /* This can handle any delta. This takes
10064 4+DWARF2_ADDR_SIZE bytes. */
10065 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10066 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10067 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10068 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10071 strcpy (prev_line_label, line_label);
10073 /* Emit debug info for the source file of the current line, if
10074 different from the previous line. */
10075 if (line_info->dw_file_num != current_file)
10077 current_file = line_info->dw_file_num;
10078 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10079 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10082 /* Emit debug info for the current line number, choosing the encoding
10083 that uses the least amount of space. */
10084 if (line_info->dw_line_num != current_line)
10086 line_offset = line_info->dw_line_num - current_line;
10087 line_delta = line_offset - DWARF_LINE_BASE;
10088 current_line = line_info->dw_line_num;
10089 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10090 /* This can handle deltas from -10 to 234, using the current
10091 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
10093 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10094 "line %lu", current_line);
10097 /* This can handle any delta. This takes at least 4 bytes,
10098 depending on the value being encoded. */
10099 dw2_asm_output_data (1, DW_LNS_advance_line,
10100 "advance to line %lu", current_line);
10101 dw2_asm_output_data_sleb128 (line_offset, NULL);
10102 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10106 /* We still need to start a new row, so output a copy insn. */
10107 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10110 /* Emit debug info for the address of the end of the function. */
10113 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10114 "DW_LNS_fixed_advance_pc");
10115 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
10119 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10120 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10121 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10122 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
10125 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10126 dw2_asm_output_data_uleb128 (1, NULL);
10127 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10132 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
10134 dw_separate_line_info_ref line_info
10135 = &separate_line_info_table[lt_index];
10138 /* Don't emit anything for redundant notes. */
10139 if (line_info->dw_line_num == current_line
10140 && line_info->dw_file_num == current_file
10141 && line_info->function == function)
10145 /* Emit debug info for the address of the current line. If this is
10146 a new function, or the first line of a function, then we need
10147 to handle it differently. */
10148 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
10150 if (function != line_info->function)
10152 function = line_info->function;
10154 /* Set the address register to the first line in the function. */
10155 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10156 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10157 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10158 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10162 /* ??? See the DW_LNS_advance_pc comment above. */
10165 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10166 "DW_LNS_fixed_advance_pc");
10167 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10171 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10172 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10173 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10174 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10178 strcpy (prev_line_label, line_label);
10180 /* Emit debug info for the source file of the current line, if
10181 different from the previous line. */
10182 if (line_info->dw_file_num != current_file)
10184 current_file = line_info->dw_file_num;
10185 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10186 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10189 /* Emit debug info for the current line number, choosing the encoding
10190 that uses the least amount of space. */
10191 if (line_info->dw_line_num != current_line)
10193 line_offset = line_info->dw_line_num - current_line;
10194 line_delta = line_offset - DWARF_LINE_BASE;
10195 current_line = line_info->dw_line_num;
10196 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10197 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10198 "line %lu", current_line);
10201 dw2_asm_output_data (1, DW_LNS_advance_line,
10202 "advance to line %lu", current_line);
10203 dw2_asm_output_data_sleb128 (line_offset, NULL);
10204 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10208 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10216 /* If we're done with a function, end its sequence. */
10217 if (lt_index == separate_line_info_table_in_use
10218 || separate_line_info_table[lt_index].function != function)
10223 /* Emit debug info for the address of the end of the function. */
10224 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
10227 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10228 "DW_LNS_fixed_advance_pc");
10229 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10233 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10234 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10235 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10236 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10239 /* Output the marker for the end of this sequence. */
10240 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10241 dw2_asm_output_data_uleb128 (1, NULL);
10242 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10246 /* Output the marker for the end of the line number info. */
10247 ASM_OUTPUT_LABEL (asm_out_file, l2);
10250 /* Given a pointer to a tree node for some base type, return a pointer to
10251 a DIE that describes the given type.
10253 This routine must only be called for GCC type nodes that correspond to
10254 Dwarf base (fundamental) types. */
10257 base_type_die (tree type)
10259 dw_die_ref base_type_result;
10260 enum dwarf_type encoding;
10262 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10265 /* If this is a subtype that should not be emitted as a subrange type,
10266 use the base type. See subrange_type_for_debug_p. */
10267 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10268 type = TREE_TYPE (type);
10270 switch (TREE_CODE (type))
10273 if (TYPE_STRING_FLAG (type))
10275 if (TYPE_UNSIGNED (type))
10276 encoding = DW_ATE_unsigned_char;
10278 encoding = DW_ATE_signed_char;
10280 else if (TYPE_UNSIGNED (type))
10281 encoding = DW_ATE_unsigned;
10283 encoding = DW_ATE_signed;
10287 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10289 if (dwarf_version >= 3 || !dwarf_strict)
10290 encoding = DW_ATE_decimal_float;
10292 encoding = DW_ATE_lo_user;
10295 encoding = DW_ATE_float;
10298 case FIXED_POINT_TYPE:
10299 if (!(dwarf_version >= 3 || !dwarf_strict))
10300 encoding = DW_ATE_lo_user;
10301 else if (TYPE_UNSIGNED (type))
10302 encoding = DW_ATE_unsigned_fixed;
10304 encoding = DW_ATE_signed_fixed;
10307 /* Dwarf2 doesn't know anything about complex ints, so use
10308 a user defined type for it. */
10310 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10311 encoding = DW_ATE_complex_float;
10313 encoding = DW_ATE_lo_user;
10317 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10318 encoding = DW_ATE_boolean;
10322 /* No other TREE_CODEs are Dwarf fundamental types. */
10323 gcc_unreachable ();
10326 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
10328 /* This probably indicates a bug. */
10329 if (! TYPE_NAME (type))
10330 add_name_attribute (base_type_result, "__unknown__");
10332 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10333 int_size_in_bytes (type));
10334 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10336 return base_type_result;
10339 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10340 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10343 is_base_type (tree type)
10345 switch (TREE_CODE (type))
10351 case FIXED_POINT_TYPE:
10359 case QUAL_UNION_TYPE:
10360 case ENUMERAL_TYPE:
10361 case FUNCTION_TYPE:
10364 case REFERENCE_TYPE:
10371 gcc_unreachable ();
10377 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10378 node, return the size in bits for the type if it is a constant, or else
10379 return the alignment for the type if the type's size is not constant, or
10380 else return BITS_PER_WORD if the type actually turns out to be an
10381 ERROR_MARK node. */
10383 static inline unsigned HOST_WIDE_INT
10384 simple_type_size_in_bits (const_tree type)
10386 if (TREE_CODE (type) == ERROR_MARK)
10387 return BITS_PER_WORD;
10388 else if (TYPE_SIZE (type) == NULL_TREE)
10390 else if (host_integerp (TYPE_SIZE (type), 1))
10391 return tree_low_cst (TYPE_SIZE (type), 1);
10393 return TYPE_ALIGN (type);
10396 /* Given a pointer to a tree node for a subrange type, return a pointer
10397 to a DIE that describes the given type. */
10400 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10402 dw_die_ref subrange_die;
10403 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10405 if (context_die == NULL)
10406 context_die = comp_unit_die;
10408 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10410 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10412 /* The size of the subrange type and its base type do not match,
10413 so we need to generate a size attribute for the subrange type. */
10414 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10418 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10420 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10422 return subrange_die;
10425 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10426 entry that chains various modifiers in front of the given type. */
10429 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10430 dw_die_ref context_die)
10432 enum tree_code code = TREE_CODE (type);
10433 dw_die_ref mod_type_die;
10434 dw_die_ref sub_die = NULL;
10435 tree item_type = NULL;
10436 tree qualified_type;
10437 tree name, low, high;
10439 if (code == ERROR_MARK)
10442 /* See if we already have the appropriately qualified variant of
10445 = get_qualified_type (type,
10446 ((is_const_type ? TYPE_QUAL_CONST : 0)
10447 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10449 /* If we do, then we can just use its DIE, if it exists. */
10450 if (qualified_type)
10452 mod_type_die = lookup_type_die (qualified_type);
10454 return mod_type_die;
10457 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10459 /* Handle C typedef types. */
10460 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
10462 tree dtype = TREE_TYPE (name);
10464 if (qualified_type == dtype)
10466 /* For a named type, use the typedef. */
10467 gen_type_die (qualified_type, context_die);
10468 return lookup_type_die (qualified_type);
10470 else if (is_const_type < TYPE_READONLY (dtype)
10471 || is_volatile_type < TYPE_VOLATILE (dtype)
10472 || (is_const_type <= TYPE_READONLY (dtype)
10473 && is_volatile_type <= TYPE_VOLATILE (dtype)
10474 && DECL_ORIGINAL_TYPE (name) != type))
10475 /* cv-unqualified version of named type. Just use the unnamed
10476 type to which it refers. */
10477 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10478 is_const_type, is_volatile_type,
10480 /* Else cv-qualified version of named type; fall through. */
10485 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
10486 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10488 else if (is_volatile_type)
10490 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
10491 sub_die = modified_type_die (type, 0, 0, context_die);
10493 else if (code == POINTER_TYPE)
10495 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
10496 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10497 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10498 item_type = TREE_TYPE (type);
10500 else if (code == REFERENCE_TYPE)
10502 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
10503 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10504 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10505 item_type = TREE_TYPE (type);
10507 else if (code == INTEGER_TYPE
10508 && TREE_TYPE (type) != NULL_TREE
10509 && subrange_type_for_debug_p (type, &low, &high))
10511 mod_type_die = subrange_type_die (type, low, high, context_die);
10512 item_type = TREE_TYPE (type);
10514 else if (is_base_type (type))
10515 mod_type_die = base_type_die (type);
10518 gen_type_die (type, context_die);
10520 /* We have to get the type_main_variant here (and pass that to the
10521 `lookup_type_die' routine) because the ..._TYPE node we have
10522 might simply be a *copy* of some original type node (where the
10523 copy was created to help us keep track of typedef names) and
10524 that copy might have a different TYPE_UID from the original
10526 if (TREE_CODE (type) != VECTOR_TYPE)
10527 return lookup_type_die (type_main_variant (type));
10529 /* Vectors have the debugging information in the type,
10530 not the main variant. */
10531 return lookup_type_die (type);
10534 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10535 don't output a DW_TAG_typedef, since there isn't one in the
10536 user's program; just attach a DW_AT_name to the type. */
10538 && (TREE_CODE (name) != TYPE_DECL
10539 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
10541 if (TREE_CODE (name) == TYPE_DECL)
10542 /* Could just call add_name_and_src_coords_attributes here,
10543 but since this is a builtin type it doesn't have any
10544 useful source coordinates anyway. */
10545 name = DECL_NAME (name);
10546 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10549 if (qualified_type)
10550 equate_type_number_to_die (qualified_type, mod_type_die);
10553 /* We must do this after the equate_type_number_to_die call, in case
10554 this is a recursive type. This ensures that the modified_type_die
10555 recursion will terminate even if the type is recursive. Recursive
10556 types are possible in Ada. */
10557 sub_die = modified_type_die (item_type,
10558 TYPE_READONLY (item_type),
10559 TYPE_VOLATILE (item_type),
10562 if (sub_die != NULL)
10563 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10565 return mod_type_die;
10568 /* Generate DIEs for the generic parameters of T.
10569 T must be either a generic type or a generic function.
10570 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10573 gen_generic_params_dies (tree t)
10577 dw_die_ref die = NULL;
10579 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10583 die = lookup_type_die (t);
10584 else if (DECL_P (t))
10585 die = lookup_decl_die (t);
10589 parms = lang_hooks.get_innermost_generic_parms (t);
10591 /* T has no generic parameter. It means T is neither a generic type
10592 or function. End of story. */
10595 parms_num = TREE_VEC_LENGTH (parms);
10596 args = lang_hooks.get_innermost_generic_args (t);
10597 for (i = 0; i < parms_num; i++)
10599 tree parm, arg, arg_pack_elems;
10601 parm = TREE_VEC_ELT (parms, i);
10602 arg = TREE_VEC_ELT (args, i);
10603 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
10604 gcc_assert (parm && TREE_VALUE (parm) && arg);
10606 if (parm && TREE_VALUE (parm) && arg)
10608 /* If PARM represents a template parameter pack,
10609 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10610 by DW_TAG_template_*_parameter DIEs for the argument
10611 pack elements of ARG. Note that ARG would then be
10612 an argument pack. */
10613 if (arg_pack_elems)
10614 template_parameter_pack_die (TREE_VALUE (parm),
10618 generic_parameter_die (TREE_VALUE (parm), arg,
10619 true /* Emit DW_AT_name */, die);
10624 /* Create and return a DIE for PARM which should be
10625 the representation of a generic type parameter.
10626 For instance, in the C++ front end, PARM would be a template parameter.
10627 ARG is the argument to PARM.
10628 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10630 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10631 as a child node. */
10634 generic_parameter_die (tree parm, tree arg,
10636 dw_die_ref parent_die)
10638 dw_die_ref tmpl_die = NULL;
10639 const char *name = NULL;
10641 if (!parm || !DECL_NAME (parm) || !arg)
10644 /* We support non-type generic parameters and arguments,
10645 type generic parameters and arguments, as well as
10646 generic generic parameters (a.k.a. template template parameters in C++)
10648 if (TREE_CODE (parm) == PARM_DECL)
10649 /* PARM is a nontype generic parameter */
10650 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10651 else if (TREE_CODE (parm) == TYPE_DECL)
10652 /* PARM is a type generic parameter. */
10653 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10654 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10655 /* PARM is a generic generic parameter.
10656 Its DIE is a GNU extension. It shall have a
10657 DW_AT_name attribute to represent the name of the template template
10658 parameter, and a DW_AT_GNU_template_name attribute to represent the
10659 name of the template template argument. */
10660 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10663 gcc_unreachable ();
10669 /* If PARM is a generic parameter pack, it means we are
10670 emitting debug info for a template argument pack element.
10671 In other terms, ARG is a template argument pack element.
10672 In that case, we don't emit any DW_AT_name attribute for
10676 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10678 add_AT_string (tmpl_die, DW_AT_name, name);
10681 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10683 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10684 TMPL_DIE should have a child DW_AT_type attribute that is set
10685 to the type of the argument to PARM, which is ARG.
10686 If PARM is a type generic parameter, TMPL_DIE should have a
10687 child DW_AT_type that is set to ARG. */
10688 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10689 add_type_attribute (tmpl_die, tmpl_type, 0,
10690 TREE_THIS_VOLATILE (tmpl_type),
10695 /* So TMPL_DIE is a DIE representing a
10696 a generic generic template parameter, a.k.a template template
10697 parameter in C++ and arg is a template. */
10699 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10700 to the name of the argument. */
10701 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10702 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10705 if (TREE_CODE (parm) == PARM_DECL)
10706 /* So PARM is a non-type generic parameter.
10707 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10708 attribute of TMPL_DIE which value represents the value
10710 We must be careful here:
10711 The value of ARG might reference some function decls.
10712 We might currently be emitting debug info for a generic
10713 type and types are emitted before function decls, we don't
10714 know if the function decls referenced by ARG will actually be
10715 emitted after cgraph computations.
10716 So must defer the generation of the DW_AT_const_value to
10717 after cgraph is ready. */
10718 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10724 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10725 PARM_PACK must be a template parameter pack. The returned DIE
10726 will be child DIE of PARENT_DIE. */
10729 template_parameter_pack_die (tree parm_pack,
10730 tree parm_pack_args,
10731 dw_die_ref parent_die)
10736 gcc_assert (parent_die
10738 && DECL_NAME (parm_pack));
10740 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
10741 add_AT_string (die, DW_AT_name, IDENTIFIER_POINTER (DECL_NAME (parm_pack)));
10743 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
10744 generic_parameter_die (parm_pack,
10745 TREE_VEC_ELT (parm_pack_args, j),
10746 false /* Don't emit DW_AT_name */,
10751 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10752 an enumerated type. */
10755 type_is_enum (const_tree type)
10757 return TREE_CODE (type) == ENUMERAL_TYPE;
10760 /* Return the DBX register number described by a given RTL node. */
10762 static unsigned int
10763 dbx_reg_number (const_rtx rtl)
10765 unsigned regno = REGNO (rtl);
10767 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10769 #ifdef LEAF_REG_REMAP
10770 if (current_function_uses_only_leaf_regs)
10772 int leaf_reg = LEAF_REG_REMAP (regno);
10773 if (leaf_reg != -1)
10774 regno = (unsigned) leaf_reg;
10778 return DBX_REGISTER_NUMBER (regno);
10781 /* Optionally add a DW_OP_piece term to a location description expression.
10782 DW_OP_piece is only added if the location description expression already
10783 doesn't end with DW_OP_piece. */
10786 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10788 dw_loc_descr_ref loc;
10790 if (*list_head != NULL)
10792 /* Find the end of the chain. */
10793 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10796 if (loc->dw_loc_opc != DW_OP_piece)
10797 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10801 /* Return a location descriptor that designates a machine register or
10802 zero if there is none. */
10804 static dw_loc_descr_ref
10805 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10809 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10812 regs = targetm.dwarf_register_span (rtl);
10814 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10815 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10817 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10820 /* Return a location descriptor that designates a machine register for
10821 a given hard register number. */
10823 static dw_loc_descr_ref
10824 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10826 dw_loc_descr_ref reg_loc_descr;
10830 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10832 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10834 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10835 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10837 return reg_loc_descr;
10840 /* Given an RTL of a register, return a location descriptor that
10841 designates a value that spans more than one register. */
10843 static dw_loc_descr_ref
10844 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10845 enum var_init_status initialized)
10847 int nregs, size, i;
10849 dw_loc_descr_ref loc_result = NULL;
10852 #ifdef LEAF_REG_REMAP
10853 if (current_function_uses_only_leaf_regs)
10855 int leaf_reg = LEAF_REG_REMAP (reg);
10856 if (leaf_reg != -1)
10857 reg = (unsigned) leaf_reg;
10860 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10861 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10863 /* Simple, contiguous registers. */
10864 if (regs == NULL_RTX)
10866 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10871 dw_loc_descr_ref t;
10873 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10874 VAR_INIT_STATUS_INITIALIZED);
10875 add_loc_descr (&loc_result, t);
10876 add_loc_descr_op_piece (&loc_result, size);
10882 /* Now onto stupid register sets in non contiguous locations. */
10884 gcc_assert (GET_CODE (regs) == PARALLEL);
10886 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10889 for (i = 0; i < XVECLEN (regs, 0); ++i)
10891 dw_loc_descr_ref t;
10893 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10894 VAR_INIT_STATUS_INITIALIZED);
10895 add_loc_descr (&loc_result, t);
10896 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10897 add_loc_descr_op_piece (&loc_result, size);
10900 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10901 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10905 #endif /* DWARF2_DEBUGGING_INFO */
10907 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10909 /* Return a location descriptor that designates a constant. */
10911 static dw_loc_descr_ref
10912 int_loc_descriptor (HOST_WIDE_INT i)
10914 enum dwarf_location_atom op;
10916 /* Pick the smallest representation of a constant, rather than just
10917 defaulting to the LEB encoding. */
10921 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10922 else if (i <= 0xff)
10923 op = DW_OP_const1u;
10924 else if (i <= 0xffff)
10925 op = DW_OP_const2u;
10926 else if (HOST_BITS_PER_WIDE_INT == 32
10927 || i <= 0xffffffff)
10928 op = DW_OP_const4u;
10935 op = DW_OP_const1s;
10936 else if (i >= -0x8000)
10937 op = DW_OP_const2s;
10938 else if (HOST_BITS_PER_WIDE_INT == 32
10939 || i >= -0x80000000)
10940 op = DW_OP_const4s;
10945 return new_loc_descr (op, i, 0);
10949 #ifdef DWARF2_DEBUGGING_INFO
10950 /* Return loc description representing "address" of integer value.
10951 This can appear only as toplevel expression. */
10953 static dw_loc_descr_ref
10954 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
10957 dw_loc_descr_ref loc_result = NULL;
10959 if (!(dwarf_version >= 4 || !dwarf_strict))
10966 else if (i <= 0xff)
10968 else if (i <= 0xffff)
10970 else if (HOST_BITS_PER_WIDE_INT == 32
10971 || i <= 0xffffffff)
10974 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
10980 else if (i >= -0x8000)
10982 else if (HOST_BITS_PER_WIDE_INT == 32
10983 || i >= -0x80000000)
10986 litsize = 1 + size_of_sleb128 (i);
10988 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10989 is more compact. For DW_OP_stack_value we need:
10990 litsize + 1 (DW_OP_stack_value)
10991 and for DW_OP_implicit_value:
10992 1 (DW_OP_implicit_value) + 1 (length) + size. */
10993 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
10995 loc_result = int_loc_descriptor (i);
10996 add_loc_descr (&loc_result,
10997 new_loc_descr (DW_OP_stack_value, 0, 0));
11001 loc_result = new_loc_descr (DW_OP_implicit_value,
11003 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11004 loc_result->dw_loc_oprnd2.v.val_int = i;
11008 /* Return a location descriptor that designates a base+offset location. */
11010 static dw_loc_descr_ref
11011 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
11012 enum var_init_status initialized)
11014 unsigned int regno;
11015 dw_loc_descr_ref result;
11016 dw_fde_ref fde = current_fde ();
11018 /* We only use "frame base" when we're sure we're talking about the
11019 post-prologue local stack frame. We do this by *not* running
11020 register elimination until this point, and recognizing the special
11021 argument pointer and soft frame pointer rtx's. */
11022 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
11024 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11028 if (GET_CODE (elim) == PLUS)
11030 offset += INTVAL (XEXP (elim, 1));
11031 elim = XEXP (elim, 0);
11033 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11034 && (elim == hard_frame_pointer_rtx
11035 || elim == stack_pointer_rtx))
11036 || elim == (frame_pointer_needed
11037 ? hard_frame_pointer_rtx
11038 : stack_pointer_rtx));
11040 /* If drap register is used to align stack, use frame
11041 pointer + offset to access stack variables. If stack
11042 is aligned without drap, use stack pointer + offset to
11043 access stack variables. */
11044 if (crtl->stack_realign_tried
11045 && reg == frame_pointer_rtx)
11048 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
11049 ? HARD_FRAME_POINTER_REGNUM
11050 : STACK_POINTER_REGNUM);
11051 return new_reg_loc_descr (base_reg, offset);
11054 offset += frame_pointer_fb_offset;
11055 return new_loc_descr (DW_OP_fbreg, offset, 0);
11059 && fde->drap_reg != INVALID_REGNUM
11060 && (fde->drap_reg == REGNO (reg)
11061 || fde->vdrap_reg == REGNO (reg)))
11063 /* Use cfa+offset to represent the location of arguments passed
11064 on stack when drap is used to align stack. */
11065 return new_loc_descr (DW_OP_fbreg, offset, 0);
11068 regno = dbx_reg_number (reg);
11070 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
11073 result = new_loc_descr (DW_OP_bregx, regno, offset);
11075 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11076 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11081 /* Return true if this RTL expression describes a base+offset calculation. */
11084 is_based_loc (const_rtx rtl)
11086 return (GET_CODE (rtl) == PLUS
11087 && ((REG_P (XEXP (rtl, 0))
11088 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
11089 && CONST_INT_P (XEXP (rtl, 1)))));
11092 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11095 static dw_loc_descr_ref
11096 tls_mem_loc_descriptor (rtx mem)
11099 dw_loc_descr_ref loc_result;
11101 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
11104 base = get_base_address (MEM_EXPR (mem));
11106 || TREE_CODE (base) != VAR_DECL
11107 || !DECL_THREAD_LOCAL_P (base))
11110 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
11111 if (loc_result == NULL)
11114 if (INTVAL (MEM_OFFSET (mem)))
11115 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
11120 /* Output debug info about reason why we failed to expand expression as dwarf
11124 expansion_failed (tree expr, rtx rtl, char const *reason)
11126 if (dump_file && (dump_flags & TDF_DETAILS))
11128 fprintf (dump_file, "Failed to expand as dwarf: ");
11130 print_generic_expr (dump_file, expr, dump_flags);
11133 fprintf (dump_file, "\n");
11134 print_rtl (dump_file, rtl);
11136 fprintf (dump_file, "\nReason: %s\n", reason);
11140 /* Helper function for const_ok_for_output, called either directly
11141 or via for_each_rtx. */
11144 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
11148 if (GET_CODE (rtl) != SYMBOL_REF)
11151 if (CONSTANT_POOL_ADDRESS_P (rtl))
11154 get_pool_constant_mark (rtl, &marked);
11155 /* If all references to this pool constant were optimized away,
11156 it was not output and thus we can't represent it. */
11159 expansion_failed (NULL_TREE, rtl,
11160 "Constant was removed from constant pool.\n");
11165 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11168 /* Avoid references to external symbols in debug info, on several targets
11169 the linker might even refuse to link when linking a shared library,
11170 and in many other cases the relocations for .debug_info/.debug_loc are
11171 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11172 to be defined within the same shared library or executable are fine. */
11173 if (SYMBOL_REF_EXTERNAL_P (rtl))
11175 tree decl = SYMBOL_REF_DECL (rtl);
11177 if (decl == NULL || !targetm.binds_local_p (decl))
11179 expansion_failed (NULL_TREE, rtl,
11180 "Symbol not defined in current TU.\n");
11188 /* Return true if constant RTL can be emitted in DW_OP_addr or
11189 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11190 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11193 const_ok_for_output (rtx rtl)
11195 if (GET_CODE (rtl) == SYMBOL_REF)
11196 return const_ok_for_output_1 (&rtl, NULL) == 0;
11198 if (GET_CODE (rtl) == CONST)
11199 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
11204 /* The following routine converts the RTL for a variable or parameter
11205 (resident in memory) into an equivalent Dwarf representation of a
11206 mechanism for getting the address of that same variable onto the top of a
11207 hypothetical "address evaluation" stack.
11209 When creating memory location descriptors, we are effectively transforming
11210 the RTL for a memory-resident object into its Dwarf postfix expression
11211 equivalent. This routine recursively descends an RTL tree, turning
11212 it into Dwarf postfix code as it goes.
11214 MODE is the mode of the memory reference, needed to handle some
11215 autoincrement addressing modes.
11217 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
11218 location list for RTL.
11220 Return 0 if we can't represent the location. */
11222 static dw_loc_descr_ref
11223 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11224 enum var_init_status initialized)
11226 dw_loc_descr_ref mem_loc_result = NULL;
11227 enum dwarf_location_atom op;
11228 dw_loc_descr_ref op0, op1;
11230 /* Note that for a dynamically sized array, the location we will generate a
11231 description of here will be the lowest numbered location which is
11232 actually within the array. That's *not* necessarily the same as the
11233 zeroth element of the array. */
11235 rtl = targetm.delegitimize_address (rtl);
11237 switch (GET_CODE (rtl))
11242 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
11243 just fall into the SUBREG code. */
11245 /* ... fall through ... */
11248 /* The case of a subreg may arise when we have a local (register)
11249 variable or a formal (register) parameter which doesn't quite fill
11250 up an entire register. For now, just assume that it is
11251 legitimate to make the Dwarf info refer to the whole register which
11252 contains the given subreg. */
11253 rtl = XEXP (rtl, 0);
11254 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
11256 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
11260 /* Whenever a register number forms a part of the description of the
11261 method for calculating the (dynamic) address of a memory resident
11262 object, DWARF rules require the register number be referred to as
11263 a "base register". This distinction is not based in any way upon
11264 what category of register the hardware believes the given register
11265 belongs to. This is strictly DWARF terminology we're dealing with
11266 here. Note that in cases where the location of a memory-resident
11267 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11268 OP_CONST (0)) the actual DWARF location descriptor that we generate
11269 may just be OP_BASEREG (basereg). This may look deceptively like
11270 the object in question was allocated to a register (rather than in
11271 memory) so DWARF consumers need to be aware of the subtle
11272 distinction between OP_REG and OP_BASEREG. */
11273 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11274 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11275 else if (stack_realign_drap
11277 && crtl->args.internal_arg_pointer == rtl
11278 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11280 /* If RTL is internal_arg_pointer, which has been optimized
11281 out, use DRAP instead. */
11282 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11283 VAR_INIT_STATUS_INITIALIZED);
11289 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11290 VAR_INIT_STATUS_INITIALIZED);
11295 int shift = DWARF2_ADDR_SIZE
11296 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11297 shift *= BITS_PER_UNIT;
11298 if (GET_CODE (rtl) == SIGN_EXTEND)
11302 mem_loc_result = op0;
11303 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11304 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11305 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11306 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11311 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11312 VAR_INIT_STATUS_INITIALIZED);
11313 if (mem_loc_result == NULL)
11314 mem_loc_result = tls_mem_loc_descriptor (rtl);
11315 if (mem_loc_result != 0)
11316 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11320 rtl = XEXP (rtl, 1);
11322 /* ... fall through ... */
11325 /* Some ports can transform a symbol ref into a label ref, because
11326 the symbol ref is too far away and has to be dumped into a constant
11330 /* Alternatively, the symbol in the constant pool might be referenced
11331 by a different symbol. */
11332 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
11335 rtx tmp = get_pool_constant_mark (rtl, &marked);
11337 if (GET_CODE (tmp) == SYMBOL_REF)
11340 if (CONSTANT_POOL_ADDRESS_P (tmp))
11341 get_pool_constant_mark (tmp, &marked);
11346 /* If all references to this pool constant were optimized away,
11347 it was not output and thus we can't represent it.
11348 FIXME: might try to use DW_OP_const_value here, though
11349 DW_OP_piece complicates it. */
11352 expansion_failed (NULL_TREE, rtl,
11353 "Constant was removed from constant pool.\n");
11358 if (GET_CODE (rtl) == SYMBOL_REF
11359 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11361 dw_loc_descr_ref temp;
11363 /* If this is not defined, we have no way to emit the data. */
11364 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11367 temp = new_loc_descr (DW_OP_addr, 0, 0);
11368 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11369 temp->dw_loc_oprnd1.v.val_addr = rtl;
11370 temp->dtprel = true;
11372 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11373 add_loc_descr (&mem_loc_result, temp);
11378 if (!const_ok_for_output (rtl))
11382 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11383 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11384 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11385 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11391 expansion_failed (NULL_TREE, rtl,
11392 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
11396 /* Extract the PLUS expression nested inside and fall into
11397 PLUS code below. */
11398 rtl = XEXP (rtl, 1);
11403 /* Turn these into a PLUS expression and fall into the PLUS code
11405 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
11406 GEN_INT (GET_CODE (rtl) == PRE_INC
11407 ? GET_MODE_UNIT_SIZE (mode)
11408 : -GET_MODE_UNIT_SIZE (mode)));
11410 /* ... fall through ... */
11414 if (is_based_loc (rtl))
11415 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11416 INTVAL (XEXP (rtl, 1)),
11417 VAR_INIT_STATUS_INITIALIZED);
11420 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
11421 VAR_INIT_STATUS_INITIALIZED);
11422 if (mem_loc_result == 0)
11425 if (CONST_INT_P (XEXP (rtl, 1)))
11426 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11429 dw_loc_descr_ref mem_loc_result2
11430 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11431 VAR_INIT_STATUS_INITIALIZED);
11432 if (mem_loc_result2 == 0)
11434 add_loc_descr (&mem_loc_result, mem_loc_result2);
11435 add_loc_descr (&mem_loc_result,
11436 new_loc_descr (DW_OP_plus, 0, 0));
11441 /* If a pseudo-reg is optimized away, it is possible for it to
11442 be replaced with a MEM containing a multiply or shift. */
11484 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11485 VAR_INIT_STATUS_INITIALIZED);
11486 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11487 VAR_INIT_STATUS_INITIALIZED);
11489 if (op0 == 0 || op1 == 0)
11492 mem_loc_result = op0;
11493 add_loc_descr (&mem_loc_result, op1);
11494 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11510 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11511 VAR_INIT_STATUS_INITIALIZED);
11516 mem_loc_result = op0;
11517 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11521 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11549 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11550 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11551 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11554 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11555 VAR_INIT_STATUS_INITIALIZED);
11556 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11557 VAR_INIT_STATUS_INITIALIZED);
11559 if (op0 == 0 || op1 == 0)
11562 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11564 int shift = DWARF2_ADDR_SIZE
11565 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11566 shift *= BITS_PER_UNIT;
11567 add_loc_descr (&op0, int_loc_descriptor (shift));
11568 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11569 if (CONST_INT_P (XEXP (rtl, 1)))
11570 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
11573 add_loc_descr (&op1, int_loc_descriptor (shift));
11574 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11579 mem_loc_result = op0;
11580 add_loc_descr (&mem_loc_result, op1);
11581 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11582 if (STORE_FLAG_VALUE != 1)
11584 add_loc_descr (&mem_loc_result,
11585 int_loc_descriptor (STORE_FLAG_VALUE));
11586 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11607 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11608 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11609 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11612 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11613 VAR_INIT_STATUS_INITIALIZED);
11614 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11615 VAR_INIT_STATUS_INITIALIZED);
11617 if (op0 == 0 || op1 == 0)
11620 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11622 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11623 add_loc_descr (&op0, int_loc_descriptor (mask));
11624 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11625 if (CONST_INT_P (XEXP (rtl, 1)))
11626 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11629 add_loc_descr (&op1, int_loc_descriptor (mask));
11630 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11635 HOST_WIDE_INT bias = 1;
11636 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11637 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11638 if (CONST_INT_P (XEXP (rtl, 1)))
11639 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11640 + INTVAL (XEXP (rtl, 1)));
11642 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11650 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11651 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11652 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11655 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11656 VAR_INIT_STATUS_INITIALIZED);
11657 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11658 VAR_INIT_STATUS_INITIALIZED);
11660 if (op0 == 0 || op1 == 0)
11663 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11664 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11665 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11666 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11668 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11670 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11671 add_loc_descr (&op0, int_loc_descriptor (mask));
11672 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11673 add_loc_descr (&op1, int_loc_descriptor (mask));
11674 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11678 HOST_WIDE_INT bias = 1;
11679 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11680 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11681 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11684 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11686 int shift = DWARF2_ADDR_SIZE
11687 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11688 shift *= BITS_PER_UNIT;
11689 add_loc_descr (&op0, int_loc_descriptor (shift));
11690 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11691 add_loc_descr (&op1, int_loc_descriptor (shift));
11692 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11695 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11699 mem_loc_result = op0;
11700 add_loc_descr (&mem_loc_result, op1);
11701 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11703 dw_loc_descr_ref bra_node, drop_node;
11705 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11706 add_loc_descr (&mem_loc_result, bra_node);
11707 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
11708 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11709 add_loc_descr (&mem_loc_result, drop_node);
11710 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11711 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11717 if (CONST_INT_P (XEXP (rtl, 1))
11718 && CONST_INT_P (XEXP (rtl, 2))
11719 && ((unsigned) INTVAL (XEXP (rtl, 1))
11720 + (unsigned) INTVAL (XEXP (rtl, 2))
11721 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
11722 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
11723 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
11726 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11727 VAR_INIT_STATUS_INITIALIZED);
11730 if (GET_CODE (rtl) == SIGN_EXTRACT)
11734 mem_loc_result = op0;
11735 size = INTVAL (XEXP (rtl, 1));
11736 shift = INTVAL (XEXP (rtl, 2));
11737 if (BITS_BIG_ENDIAN)
11738 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11740 add_loc_descr (&mem_loc_result,
11741 int_loc_descriptor (DWARF2_ADDR_SIZE - shift - size));
11742 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11743 add_loc_descr (&mem_loc_result,
11744 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
11745 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11754 /* In theory, we could implement the above. */
11755 /* DWARF cannot represent the unsigned compare operations
11771 case FLOAT_TRUNCATE:
11773 case UNSIGNED_FLOAT:
11776 case FRACT_CONVERT:
11777 case UNSIGNED_FRACT_CONVERT:
11779 case UNSIGNED_SAT_FRACT:
11790 /* If delegitimize_address couldn't do anything with the UNSPEC, we
11791 can't express it in the debug info. This can happen e.g. with some
11796 resolve_one_addr (&rtl, NULL);
11800 #ifdef ENABLE_CHECKING
11801 print_rtl (stderr, rtl);
11802 gcc_unreachable ();
11808 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11809 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11811 return mem_loc_result;
11814 /* Return a descriptor that describes the concatenation of two locations.
11815 This is typically a complex variable. */
11817 static dw_loc_descr_ref
11818 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
11820 dw_loc_descr_ref cc_loc_result = NULL;
11821 dw_loc_descr_ref x0_ref
11822 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11823 dw_loc_descr_ref x1_ref
11824 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11826 if (x0_ref == 0 || x1_ref == 0)
11829 cc_loc_result = x0_ref;
11830 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
11832 add_loc_descr (&cc_loc_result, x1_ref);
11833 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
11835 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11836 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11838 return cc_loc_result;
11841 /* Return a descriptor that describes the concatenation of N
11844 static dw_loc_descr_ref
11845 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
11848 dw_loc_descr_ref cc_loc_result = NULL;
11849 unsigned int n = XVECLEN (concatn, 0);
11851 for (i = 0; i < n; ++i)
11853 dw_loc_descr_ref ref;
11854 rtx x = XVECEXP (concatn, 0, i);
11856 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11860 add_loc_descr (&cc_loc_result, ref);
11861 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
11864 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11865 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11867 return cc_loc_result;
11870 /* Output a proper Dwarf location descriptor for a variable or parameter
11871 which is either allocated in a register or in a memory location. For a
11872 register, we just generate an OP_REG and the register number. For a
11873 memory location we provide a Dwarf postfix expression describing how to
11874 generate the (dynamic) address of the object onto the address stack.
11876 MODE is mode of the decl if this loc_descriptor is going to be used in
11877 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
11878 allowed, VOIDmode otherwise.
11880 If we don't know how to describe it, return 0. */
11882 static dw_loc_descr_ref
11883 loc_descriptor (rtx rtl, enum machine_mode mode,
11884 enum var_init_status initialized)
11886 dw_loc_descr_ref loc_result = NULL;
11888 switch (GET_CODE (rtl))
11891 /* The case of a subreg may arise when we have a local (register)
11892 variable or a formal (register) parameter which doesn't quite fill
11893 up an entire register. For now, just assume that it is
11894 legitimate to make the Dwarf info refer to the whole register which
11895 contains the given subreg. */
11896 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
11900 loc_result = reg_loc_descriptor (rtl, initialized);
11905 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11909 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11911 if (loc_result == NULL)
11912 loc_result = tls_mem_loc_descriptor (rtl);
11916 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
11921 loc_result = concatn_loc_descriptor (rtl, initialized);
11926 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
11928 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), mode,
11933 rtl = XEXP (rtl, 1);
11938 rtvec par_elems = XVEC (rtl, 0);
11939 int num_elem = GET_NUM_ELEM (par_elems);
11940 enum machine_mode mode;
11943 /* Create the first one, so we have something to add to. */
11944 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
11945 VOIDmode, initialized);
11946 if (loc_result == NULL)
11948 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
11949 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11950 for (i = 1; i < num_elem; i++)
11952 dw_loc_descr_ref temp;
11954 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
11955 VOIDmode, initialized);
11958 add_loc_descr (&loc_result, temp);
11959 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
11960 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11966 if (mode != VOIDmode && mode != BLKmode)
11967 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
11972 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
11974 /* Note that a CONST_DOUBLE rtx could represent either an integer
11975 or a floating-point constant. A CONST_DOUBLE is used whenever
11976 the constant requires more than one word in order to be
11977 adequately represented. We output CONST_DOUBLEs as blocks. */
11978 if (GET_MODE (rtl) != VOIDmode)
11979 mode = GET_MODE (rtl);
11981 loc_result = new_loc_descr (DW_OP_implicit_value,
11982 GET_MODE_SIZE (mode), 0);
11983 if (SCALAR_FLOAT_MODE_P (mode))
11985 unsigned int length = GET_MODE_SIZE (mode);
11986 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11988 insert_float (rtl, array);
11989 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11990 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
11991 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
11992 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11996 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
11997 loc_result->dw_loc_oprnd2.v.val_double.high
11998 = CONST_DOUBLE_HIGH (rtl);
11999 loc_result->dw_loc_oprnd2.v.val_double.low
12000 = CONST_DOUBLE_LOW (rtl);
12006 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
12008 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
12009 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12010 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
12014 mode = GET_MODE (rtl);
12015 switch (GET_MODE_CLASS (mode))
12017 case MODE_VECTOR_INT:
12018 for (i = 0, p = array; i < length; i++, p += elt_size)
12020 rtx elt = CONST_VECTOR_ELT (rtl, i);
12021 HOST_WIDE_INT lo, hi;
12023 switch (GET_CODE (elt))
12031 lo = CONST_DOUBLE_LOW (elt);
12032 hi = CONST_DOUBLE_HIGH (elt);
12036 gcc_unreachable ();
12039 if (elt_size <= sizeof (HOST_WIDE_INT))
12040 insert_int (lo, elt_size, p);
12043 unsigned char *p0 = p;
12044 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
12046 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12047 if (WORDS_BIG_ENDIAN)
12052 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
12053 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
12058 case MODE_VECTOR_FLOAT:
12059 for (i = 0, p = array; i < length; i++, p += elt_size)
12061 rtx elt = CONST_VECTOR_ELT (rtl, i);
12062 insert_float (elt, p);
12067 gcc_unreachable ();
12070 loc_result = new_loc_descr (DW_OP_implicit_value,
12071 length * elt_size, 0);
12072 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
12073 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
12074 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
12075 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
12080 if (mode == VOIDmode
12081 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
12082 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
12083 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
12085 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
12090 if (!const_ok_for_output (rtl))
12093 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
12094 && (dwarf_version >= 4 || !dwarf_strict))
12096 loc_result = new_loc_descr (DW_OP_implicit_value,
12097 DWARF2_ADDR_SIZE, 0);
12098 loc_result->dw_loc_oprnd2.val_class = dw_val_class_addr;
12099 loc_result->dw_loc_oprnd2.v.val_addr = rtl;
12100 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12105 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
12106 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
12107 && (dwarf_version >= 4 || !dwarf_strict))
12109 /* Value expression. */
12110 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
12112 add_loc_descr (&loc_result,
12113 new_loc_descr (DW_OP_stack_value, 0, 0));
12121 /* We need to figure out what section we should use as the base for the
12122 address ranges where a given location is valid.
12123 1. If this particular DECL has a section associated with it, use that.
12124 2. If this function has a section associated with it, use that.
12125 3. Otherwise, use the text section.
12126 XXX: If you split a variable across multiple sections, we won't notice. */
12128 static const char *
12129 secname_for_decl (const_tree decl)
12131 const char *secname;
12133 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12135 tree sectree = DECL_SECTION_NAME (decl);
12136 secname = TREE_STRING_POINTER (sectree);
12138 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12140 tree sectree = DECL_SECTION_NAME (current_function_decl);
12141 secname = TREE_STRING_POINTER (sectree);
12143 else if (cfun && in_cold_section_p)
12144 secname = crtl->subsections.cold_section_label;
12146 secname = text_section_label;
12151 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
12154 decl_by_reference_p (tree decl)
12156 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
12157 || TREE_CODE (decl) == VAR_DECL)
12158 && DECL_BY_REFERENCE (decl));
12162 /* Dereference a location expression LOC if DECL is passed by invisible
12165 static dw_loc_descr_ref
12166 loc_by_reference (dw_loc_descr_ref loc, tree decl)
12168 HOST_WIDE_INT size;
12169 enum dwarf_location_atom op;
12174 if (!decl_by_reference_p (decl))
12177 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
12178 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
12179 location expression is considered to be address of a memory location,
12180 rather than the register itself. */
12181 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
12182 || loc->dw_loc_opc == DW_OP_regx)
12183 && (loc->dw_loc_next == NULL
12184 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
12185 && loc->dw_loc_next->dw_loc_next == NULL)))
12187 if (loc->dw_loc_opc == DW_OP_regx)
12189 loc->dw_loc_opc = DW_OP_bregx;
12190 loc->dw_loc_oprnd2.v.val_int = 0;
12195 = (enum dwarf_location_atom)
12196 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
12197 loc->dw_loc_oprnd1.v.val_int = 0;
12202 size = int_size_in_bytes (TREE_TYPE (decl));
12203 if (size > DWARF2_ADDR_SIZE || size == -1)
12205 else if (size == DWARF2_ADDR_SIZE)
12208 op = DW_OP_deref_size;
12209 add_loc_descr (&loc, new_loc_descr (op, size, 0));
12213 /* Return single element location list containing loc descr REF. */
12215 static dw_loc_list_ref
12216 single_element_loc_list (dw_loc_descr_ref ref)
12218 return new_loc_list (ref, NULL, NULL, NULL, 0);
12221 /* Return dwarf representation of location list representing for
12222 LOC_LIST of DECL. */
12224 static dw_loc_list_ref
12225 dw_loc_list (var_loc_list * loc_list, tree decl, bool toplevel)
12227 const char *endname, *secname;
12228 dw_loc_list_ref list;
12230 enum var_init_status initialized;
12231 struct var_loc_node *node;
12232 dw_loc_descr_ref descr;
12233 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12235 bool by_reference = decl_by_reference_p (decl);
12237 /* Now that we know what section we are using for a base,
12238 actually construct the list of locations.
12239 The first location information is what is passed to the
12240 function that creates the location list, and the remaining
12241 locations just get added on to that list.
12242 Note that we only know the start address for a location
12243 (IE location changes), so to build the range, we use
12244 the range [current location start, next location start].
12245 This means we have to special case the last node, and generate
12246 a range of [last location start, end of function label]. */
12248 node = loc_list->first;
12249 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12250 secname = secname_for_decl (decl);
12252 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
12253 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12255 initialized = VAR_INIT_STATUS_INITIALIZED;
12257 if (!toplevel || by_reference)
12259 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12261 if (GET_CODE (XEXP (varloc, 1)) != PARALLEL)
12262 descr = loc_by_reference (mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0),
12263 TYPE_MODE (TREE_TYPE (decl)),
12270 descr = loc_descriptor (varloc, DECL_MODE (decl), initialized);
12272 if (loc_list && loc_list->first != loc_list->last)
12273 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
12275 return single_element_loc_list (descr);
12281 for (; node->next; node = node->next)
12282 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12284 /* The variable has a location between NODE->LABEL and
12285 NODE->NEXT->LABEL. */
12286 enum var_init_status initialized =
12287 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12288 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12289 if (!toplevel || by_reference)
12291 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12293 if (GET_CODE (XEXP (varloc, 1)) != PARALLEL)
12294 descr = mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0),
12295 TYPE_MODE (TREE_TYPE (decl)), initialized);
12298 descr = loc_by_reference (descr, decl);
12301 descr = loc_descriptor (varloc, DECL_MODE (decl), initialized);
12302 add_loc_descr_to_loc_list (&list, descr,
12303 node->label, node->next->label, secname);
12306 /* If the variable has a location at the last label
12307 it keeps its location until the end of function. */
12308 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12310 enum var_init_status initialized =
12311 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12313 if (!current_function_decl)
12314 endname = text_end_label;
12317 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12318 current_function_funcdef_no);
12319 endname = ggc_strdup (label_id);
12322 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12323 if (!toplevel || by_reference)
12325 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
12327 if (GET_CODE (XEXP (varloc, 1)) != PARALLEL)
12328 descr = mem_loc_descriptor (XEXP (XEXP (varloc, 1), 0),
12329 TYPE_MODE (TREE_TYPE (decl)), initialized);
12332 descr = loc_by_reference (descr, decl);
12335 descr = loc_descriptor (varloc, DECL_MODE (decl), initialized);
12336 add_loc_descr_to_loc_list (&list, descr, node->label, endname, secname);
12341 /* Return if the loc_list has only single element and thus can be represented
12342 as location description. */
12345 single_element_loc_list_p (dw_loc_list_ref list)
12347 return (!list->dw_loc_next && !list->begin && !list->end);
12350 /* To each location in list LIST add loc descr REF. */
12353 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
12355 dw_loc_descr_ref copy;
12356 add_loc_descr (&list->expr, ref);
12357 list = list->dw_loc_next;
12360 copy = GGC_CNEW (dw_loc_descr_node);
12361 memcpy (copy, ref, sizeof (dw_loc_descr_node));
12362 add_loc_descr (&list->expr, copy);
12363 while (copy->dw_loc_next)
12365 dw_loc_descr_ref new_copy = GGC_CNEW (dw_loc_descr_node);
12366 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
12367 copy->dw_loc_next = new_copy;
12370 list = list->dw_loc_next;
12374 /* Given two lists RET and LIST
12375 produce location list that is result of adding expression in LIST
12376 to expression in RET on each possition in program.
12377 Might be destructive on both RET and LIST.
12379 TODO: We handle only simple cases of RET or LIST having at most one
12380 element. General case would inolve sorting the lists in program order
12381 and merging them that will need some additional work.
12382 Adding that will improve quality of debug info especially for SRA-ed
12386 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
12395 if (!list->dw_loc_next)
12397 add_loc_descr_to_each (*ret, list->expr);
12400 if (!(*ret)->dw_loc_next)
12402 add_loc_descr_to_each (list, (*ret)->expr);
12406 expansion_failed (NULL_TREE, NULL_RTX,
12407 "Don't know how to merge two non-trivial"
12408 " location lists.\n");
12413 /* LOC is constant expression. Try a luck, look it up in constant
12414 pool and return its loc_descr of its address. */
12416 static dw_loc_descr_ref
12417 cst_pool_loc_descr (tree loc)
12419 /* Get an RTL for this, if something has been emitted. */
12420 rtx rtl = lookup_constant_def (loc);
12421 enum machine_mode mode;
12423 if (!rtl || !MEM_P (rtl))
12428 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
12430 /* TODO: We might get more coverage if we was actually delaying expansion
12431 of all expressions till end of compilation when constant pools are fully
12433 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
12435 expansion_failed (loc, NULL_RTX,
12436 "CST value in contant pool but not marked.");
12439 mode = GET_MODE (rtl);
12440 rtl = XEXP (rtl, 0);
12441 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12444 /* Return dw_loc_list representing address of addr_expr LOC
12445 by looking for innder INDIRECT_REF expression and turing it
12446 into simple arithmetics. */
12448 static dw_loc_list_ref
12449 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
12452 HOST_WIDE_INT bitsize, bitpos, bytepos;
12453 enum machine_mode mode;
12455 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
12456 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
12458 obj = get_inner_reference (TREE_OPERAND (loc, 0),
12459 &bitsize, &bitpos, &offset, &mode,
12460 &unsignedp, &volatilep, false);
12462 if (bitpos % BITS_PER_UNIT)
12464 expansion_failed (loc, NULL_RTX, "bitfield access");
12467 if (!INDIRECT_REF_P (obj))
12469 expansion_failed (obj,
12470 NULL_RTX, "no indirect ref in inner refrence");
12473 if (!offset && !bitpos)
12474 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
12476 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
12477 && (dwarf_version >= 4 || !dwarf_strict))
12479 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
12484 /* Variable offset. */
12485 list_ret1 = loc_list_from_tree (offset, 0);
12486 if (list_ret1 == 0)
12488 add_loc_list (&list_ret, list_ret1);
12491 add_loc_descr_to_each (list_ret,
12492 new_loc_descr (DW_OP_plus, 0, 0));
12494 bytepos = bitpos / BITS_PER_UNIT;
12496 add_loc_descr_to_each (list_ret,
12497 new_loc_descr (DW_OP_plus_uconst,
12499 else if (bytepos < 0)
12500 loc_list_plus_const (list_ret, bytepos);
12501 add_loc_descr_to_each (list_ret,
12502 new_loc_descr (DW_OP_stack_value, 0, 0));
12508 /* Generate Dwarf location list representing LOC.
12509 If WANT_ADDRESS is false, expression computing LOC will be computed
12510 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
12511 if WANT_ADDRESS is 2, expression computing address useable in location
12512 will be returned (i.e. DW_OP_reg can be used
12513 to refer to register values)
12514 TODO: Dwarf4 adds types to the stack machine that ought to be used here
12515 DW_OP_stack_value will help in cases where we fail to find address of the
12519 static dw_loc_list_ref
12520 loc_list_from_tree (tree loc, int want_address)
12522 dw_loc_descr_ref ret = NULL, ret1 = NULL;
12523 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
12524 int have_address = 0;
12525 enum dwarf_location_atom op;
12527 /* ??? Most of the time we do not take proper care for sign/zero
12528 extending the values properly. Hopefully this won't be a real
12531 switch (TREE_CODE (loc))
12534 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
12537 case PLACEHOLDER_EXPR:
12538 /* This case involves extracting fields from an object to determine the
12539 position of other fields. We don't try to encode this here. The
12540 only user of this is Ada, which encodes the needed information using
12541 the names of types. */
12542 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
12546 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
12547 /* There are no opcodes for these operations. */
12550 case PREINCREMENT_EXPR:
12551 case PREDECREMENT_EXPR:
12552 case POSTINCREMENT_EXPR:
12553 case POSTDECREMENT_EXPR:
12554 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
12555 /* There are no opcodes for these operations. */
12559 /* If we already want an address, see if there is INDIRECT_REF inside
12560 e.g. for &this->field. */
12563 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
12564 (loc, want_address == 2);
12567 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
12568 && (ret = cst_pool_loc_descr (loc)))
12571 /* Otherwise, process the argument and look for the address. */
12572 if (!list_ret && !ret)
12573 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
12577 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
12583 if (DECL_THREAD_LOCAL_P (loc))
12586 enum dwarf_location_atom first_op;
12587 enum dwarf_location_atom second_op;
12588 bool dtprel = false;
12590 if (targetm.have_tls)
12592 /* If this is not defined, we have no way to emit the
12594 if (!targetm.asm_out.output_dwarf_dtprel)
12597 /* The way DW_OP_GNU_push_tls_address is specified, we
12598 can only look up addresses of objects in the current
12600 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
12602 first_op = DW_OP_addr;
12604 second_op = DW_OP_GNU_push_tls_address;
12608 if (!targetm.emutls.debug_form_tls_address
12609 || !(dwarf_version >= 3 || !dwarf_strict))
12611 loc = emutls_decl (loc);
12612 first_op = DW_OP_addr;
12613 second_op = DW_OP_form_tls_address;
12616 rtl = rtl_for_decl_location (loc);
12617 if (rtl == NULL_RTX)
12622 rtl = XEXP (rtl, 0);
12623 if (! CONSTANT_P (rtl))
12626 ret = new_loc_descr (first_op, 0, 0);
12627 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12628 ret->dw_loc_oprnd1.v.val_addr = rtl;
12629 ret->dtprel = dtprel;
12631 ret1 = new_loc_descr (second_op, 0, 0);
12632 add_loc_descr (&ret, ret1);
12640 if (DECL_HAS_VALUE_EXPR_P (loc))
12641 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
12646 case FUNCTION_DECL:
12648 rtx rtl = rtl_for_decl_location (loc);
12649 var_loc_list *loc_list = lookup_decl_loc (loc);
12651 if (loc_list && loc_list->first
12652 && (list_ret = dw_loc_list (loc_list, loc, want_address == 2)))
12654 else if (rtl == NULL_RTX)
12656 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
12659 else if (CONST_INT_P (rtl))
12661 HOST_WIDE_INT val = INTVAL (rtl);
12662 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
12663 val &= GET_MODE_MASK (DECL_MODE (loc));
12664 ret = int_loc_descriptor (val);
12666 else if (GET_CODE (rtl) == CONST_STRING)
12668 expansion_failed (loc, NULL_RTX, "CONST_STRING");
12671 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
12673 ret = new_loc_descr (DW_OP_addr, 0, 0);
12674 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12675 ret->dw_loc_oprnd1.v.val_addr = rtl;
12679 enum machine_mode mode;
12681 /* Certain constructs can only be represented at top-level. */
12682 if (want_address == 2)
12684 ret = loc_descriptor (rtl, VOIDmode,
12685 VAR_INIT_STATUS_INITIALIZED);
12690 mode = GET_MODE (rtl);
12693 rtl = XEXP (rtl, 0);
12696 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12699 expansion_failed (loc, rtl,
12700 "failed to produce loc descriptor for rtl");
12706 case ALIGN_INDIRECT_REF:
12707 case MISALIGNED_INDIRECT_REF:
12708 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12712 case COMPOUND_EXPR:
12713 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
12716 case VIEW_CONVERT_EXPR:
12719 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
12721 case COMPONENT_REF:
12722 case BIT_FIELD_REF:
12724 case ARRAY_RANGE_REF:
12725 case REALPART_EXPR:
12726 case IMAGPART_EXPR:
12729 HOST_WIDE_INT bitsize, bitpos, bytepos;
12730 enum machine_mode mode;
12732 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
12734 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
12735 &unsignedp, &volatilep, false);
12737 gcc_assert (obj != loc);
12739 list_ret = loc_list_from_tree (obj,
12741 && !bitpos && !offset ? 2 : 1);
12742 /* TODO: We can extract value of the small expression via shifting even
12743 for nonzero bitpos. */
12746 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
12748 expansion_failed (loc, NULL_RTX,
12749 "bitfield access");
12753 if (offset != NULL_TREE)
12755 /* Variable offset. */
12756 list_ret1 = loc_list_from_tree (offset, 0);
12757 if (list_ret1 == 0)
12759 add_loc_list (&list_ret, list_ret1);
12762 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
12765 bytepos = bitpos / BITS_PER_UNIT;
12767 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
12768 else if (bytepos < 0)
12769 loc_list_plus_const (list_ret, bytepos);
12776 if ((want_address || !host_integerp (loc, 0))
12777 && (ret = cst_pool_loc_descr (loc)))
12779 else if (want_address == 2
12780 && host_integerp (loc, 0)
12781 && (ret = address_of_int_loc_descriptor
12782 (int_size_in_bytes (TREE_TYPE (loc)),
12783 tree_low_cst (loc, 0))))
12785 else if (host_integerp (loc, 0))
12786 ret = int_loc_descriptor (tree_low_cst (loc, 0));
12789 expansion_failed (loc, NULL_RTX,
12790 "Integer operand is not host integer");
12799 if ((ret = cst_pool_loc_descr (loc)))
12802 /* We can construct small constants here using int_loc_descriptor. */
12803 expansion_failed (loc, NULL_RTX,
12804 "constructor or constant not in constant pool");
12807 case TRUTH_AND_EXPR:
12808 case TRUTH_ANDIF_EXPR:
12813 case TRUTH_XOR_EXPR:
12818 case TRUTH_OR_EXPR:
12819 case TRUTH_ORIF_EXPR:
12824 case FLOOR_DIV_EXPR:
12825 case CEIL_DIV_EXPR:
12826 case ROUND_DIV_EXPR:
12827 case TRUNC_DIV_EXPR:
12835 case FLOOR_MOD_EXPR:
12836 case CEIL_MOD_EXPR:
12837 case ROUND_MOD_EXPR:
12838 case TRUNC_MOD_EXPR:
12851 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
12854 case POINTER_PLUS_EXPR:
12856 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
12857 && host_integerp (TREE_OPERAND (loc, 1), 0))
12859 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12863 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
12871 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12878 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12885 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12892 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12907 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12908 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
12909 if (list_ret == 0 || list_ret1 == 0)
12912 add_loc_list (&list_ret, list_ret1);
12915 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
12918 case TRUTH_NOT_EXPR:
12932 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12936 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
12942 const enum tree_code code =
12943 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
12945 loc = build3 (COND_EXPR, TREE_TYPE (loc),
12946 build2 (code, integer_type_node,
12947 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
12948 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
12951 /* ... fall through ... */
12955 dw_loc_descr_ref lhs
12956 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
12957 dw_loc_list_ref rhs
12958 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
12959 dw_loc_descr_ref bra_node, jump_node, tmp;
12961 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
12962 if (list_ret == 0 || lhs == 0 || rhs == 0)
12965 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12966 add_loc_descr_to_each (list_ret, bra_node);
12968 add_loc_list (&list_ret, rhs);
12969 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
12970 add_loc_descr_to_each (list_ret, jump_node);
12972 add_loc_descr_to_each (list_ret, lhs);
12973 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12974 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
12976 /* ??? Need a node to point the skip at. Use a nop. */
12977 tmp = new_loc_descr (DW_OP_nop, 0, 0);
12978 add_loc_descr_to_each (list_ret, tmp);
12979 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12980 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
12984 case FIX_TRUNC_EXPR:
12988 /* Leave front-end specific codes as simply unknown. This comes
12989 up, for instance, with the C STMT_EXPR. */
12990 if ((unsigned int) TREE_CODE (loc)
12991 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
12993 expansion_failed (loc, NULL_RTX,
12994 "language specific tree node");
12998 #ifdef ENABLE_CHECKING
12999 /* Otherwise this is a generic code; we should just lists all of
13000 these explicitly. We forgot one. */
13001 gcc_unreachable ();
13003 /* In a release build, we want to degrade gracefully: better to
13004 generate incomplete debugging information than to crash. */
13009 if (!ret && !list_ret)
13012 if (want_address == 2 && !have_address
13013 && (dwarf_version >= 4 || !dwarf_strict))
13015 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
13017 expansion_failed (loc, NULL_RTX,
13018 "DWARF address size mismatch");
13022 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
13024 add_loc_descr_to_each (list_ret,
13025 new_loc_descr (DW_OP_stack_value, 0, 0));
13028 /* Show if we can't fill the request for an address. */
13029 if (want_address && !have_address)
13031 expansion_failed (loc, NULL_RTX,
13032 "Want address and only have value");
13036 gcc_assert (!ret || !list_ret);
13038 /* If we've got an address and don't want one, dereference. */
13039 if (!want_address && have_address)
13041 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
13043 if (size > DWARF2_ADDR_SIZE || size == -1)
13045 expansion_failed (loc, NULL_RTX,
13046 "DWARF address size mismatch");
13049 else if (size == DWARF2_ADDR_SIZE)
13052 op = DW_OP_deref_size;
13055 add_loc_descr (&ret, new_loc_descr (op, size, 0));
13057 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
13060 list_ret = single_element_loc_list (ret);
13065 /* Same as above but return only single location expression. */
13066 static dw_loc_descr_ref
13067 loc_descriptor_from_tree (tree loc, int want_address)
13069 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
13072 if (ret->dw_loc_next)
13074 expansion_failed (loc, NULL_RTX,
13075 "Location list where only loc descriptor needed");
13081 /* Given a value, round it up to the lowest multiple of `boundary'
13082 which is not less than the value itself. */
13084 static inline HOST_WIDE_INT
13085 ceiling (HOST_WIDE_INT value, unsigned int boundary)
13087 return (((value + boundary - 1) / boundary) * boundary);
13090 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
13091 pointer to the declared type for the relevant field variable, or return
13092 `integer_type_node' if the given node turns out to be an
13093 ERROR_MARK node. */
13096 field_type (const_tree decl)
13100 if (TREE_CODE (decl) == ERROR_MARK)
13101 return integer_type_node;
13103 type = DECL_BIT_FIELD_TYPE (decl);
13104 if (type == NULL_TREE)
13105 type = TREE_TYPE (decl);
13110 /* Given a pointer to a tree node, return the alignment in bits for
13111 it, or else return BITS_PER_WORD if the node actually turns out to
13112 be an ERROR_MARK node. */
13114 static inline unsigned
13115 simple_type_align_in_bits (const_tree type)
13117 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
13120 static inline unsigned
13121 simple_decl_align_in_bits (const_tree decl)
13123 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
13126 /* Return the result of rounding T up to ALIGN. */
13128 static inline HOST_WIDE_INT
13129 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
13131 /* We must be careful if T is negative because HOST_WIDE_INT can be
13132 either "above" or "below" unsigned int as per the C promotion
13133 rules, depending on the host, thus making the signedness of the
13134 direct multiplication and division unpredictable. */
13135 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
13141 return (HOST_WIDE_INT) u;
13144 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
13145 lowest addressed byte of the "containing object" for the given FIELD_DECL,
13146 or return 0 if we are unable to determine what that offset is, either
13147 because the argument turns out to be a pointer to an ERROR_MARK node, or
13148 because the offset is actually variable. (We can't handle the latter case
13151 static HOST_WIDE_INT
13152 field_byte_offset (const_tree decl)
13154 HOST_WIDE_INT object_offset_in_bits;
13155 HOST_WIDE_INT bitpos_int;
13157 if (TREE_CODE (decl) == ERROR_MARK)
13160 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
13162 /* We cannot yet cope with fields whose positions are variable, so
13163 for now, when we see such things, we simply return 0. Someday, we may
13164 be able to handle such cases, but it will be damn difficult. */
13165 if (! host_integerp (bit_position (decl), 0))
13168 bitpos_int = int_bit_position (decl);
13170 #ifdef PCC_BITFIELD_TYPE_MATTERS
13171 if (PCC_BITFIELD_TYPE_MATTERS)
13174 tree field_size_tree;
13175 HOST_WIDE_INT deepest_bitpos;
13176 unsigned HOST_WIDE_INT field_size_in_bits;
13177 unsigned int type_align_in_bits;
13178 unsigned int decl_align_in_bits;
13179 unsigned HOST_WIDE_INT type_size_in_bits;
13181 type = field_type (decl);
13182 type_size_in_bits = simple_type_size_in_bits (type);
13183 type_align_in_bits = simple_type_align_in_bits (type);
13185 field_size_tree = DECL_SIZE (decl);
13187 /* The size could be unspecified if there was an error, or for
13188 a flexible array member. */
13189 if (!field_size_tree)
13190 field_size_tree = bitsize_zero_node;
13192 /* If the size of the field is not constant, use the type size. */
13193 if (host_integerp (field_size_tree, 1))
13194 field_size_in_bits = tree_low_cst (field_size_tree, 1);
13196 field_size_in_bits = type_size_in_bits;
13198 decl_align_in_bits = simple_decl_align_in_bits (decl);
13200 /* The GCC front-end doesn't make any attempt to keep track of the
13201 starting bit offset (relative to the start of the containing
13202 structure type) of the hypothetical "containing object" for a
13203 bit-field. Thus, when computing the byte offset value for the
13204 start of the "containing object" of a bit-field, we must deduce
13205 this information on our own. This can be rather tricky to do in
13206 some cases. For example, handling the following structure type
13207 definition when compiling for an i386/i486 target (which only
13208 aligns long long's to 32-bit boundaries) can be very tricky:
13210 struct S { int field1; long long field2:31; };
13212 Fortunately, there is a simple rule-of-thumb which can be used
13213 in such cases. When compiling for an i386/i486, GCC will
13214 allocate 8 bytes for the structure shown above. It decides to
13215 do this based upon one simple rule for bit-field allocation.
13216 GCC allocates each "containing object" for each bit-field at
13217 the first (i.e. lowest addressed) legitimate alignment boundary
13218 (based upon the required minimum alignment for the declared
13219 type of the field) which it can possibly use, subject to the
13220 condition that there is still enough available space remaining
13221 in the containing object (when allocated at the selected point)
13222 to fully accommodate all of the bits of the bit-field itself.
13224 This simple rule makes it obvious why GCC allocates 8 bytes for
13225 each object of the structure type shown above. When looking
13226 for a place to allocate the "containing object" for `field2',
13227 the compiler simply tries to allocate a 64-bit "containing
13228 object" at each successive 32-bit boundary (starting at zero)
13229 until it finds a place to allocate that 64- bit field such that
13230 at least 31 contiguous (and previously unallocated) bits remain
13231 within that selected 64 bit field. (As it turns out, for the
13232 example above, the compiler finds it is OK to allocate the
13233 "containing object" 64-bit field at bit-offset zero within the
13236 Here we attempt to work backwards from the limited set of facts
13237 we're given, and we try to deduce from those facts, where GCC
13238 must have believed that the containing object started (within
13239 the structure type). The value we deduce is then used (by the
13240 callers of this routine) to generate DW_AT_location and
13241 DW_AT_bit_offset attributes for fields (both bit-fields and, in
13242 the case of DW_AT_location, regular fields as well). */
13244 /* Figure out the bit-distance from the start of the structure to
13245 the "deepest" bit of the bit-field. */
13246 deepest_bitpos = bitpos_int + field_size_in_bits;
13248 /* This is the tricky part. Use some fancy footwork to deduce
13249 where the lowest addressed bit of the containing object must
13251 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
13253 /* Round up to type_align by default. This works best for
13255 object_offset_in_bits
13256 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
13258 if (object_offset_in_bits > bitpos_int)
13260 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
13262 /* Round up to decl_align instead. */
13263 object_offset_in_bits
13264 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
13269 object_offset_in_bits = bitpos_int;
13271 return object_offset_in_bits / BITS_PER_UNIT;
13274 /* The following routines define various Dwarf attributes and any data
13275 associated with them. */
13277 /* Add a location description attribute value to a DIE.
13279 This emits location attributes suitable for whole variables and
13280 whole parameters. Note that the location attributes for struct fields are
13281 generated by the routine `data_member_location_attribute' below. */
13284 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
13285 dw_loc_list_ref descr)
13289 if (single_element_loc_list_p (descr))
13290 add_AT_loc (die, attr_kind, descr->expr);
13292 add_AT_loc_list (die, attr_kind, descr);
13295 /* Attach the specialized form of location attribute used for data members of
13296 struct and union types. In the special case of a FIELD_DECL node which
13297 represents a bit-field, the "offset" part of this special location
13298 descriptor must indicate the distance in bytes from the lowest-addressed
13299 byte of the containing struct or union type to the lowest-addressed byte of
13300 the "containing object" for the bit-field. (See the `field_byte_offset'
13303 For any given bit-field, the "containing object" is a hypothetical object
13304 (of some integral or enum type) within which the given bit-field lives. The
13305 type of this hypothetical "containing object" is always the same as the
13306 declared type of the individual bit-field itself (for GCC anyway... the
13307 DWARF spec doesn't actually mandate this). Note that it is the size (in
13308 bytes) of the hypothetical "containing object" which will be given in the
13309 DW_AT_byte_size attribute for this bit-field. (See the
13310 `byte_size_attribute' function below.) It is also used when calculating the
13311 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
13312 function below.) */
13315 add_data_member_location_attribute (dw_die_ref die, tree decl)
13317 HOST_WIDE_INT offset;
13318 dw_loc_descr_ref loc_descr = 0;
13320 if (TREE_CODE (decl) == TREE_BINFO)
13322 /* We're working on the TAG_inheritance for a base class. */
13323 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
13325 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
13326 aren't at a fixed offset from all (sub)objects of the same
13327 type. We need to extract the appropriate offset from our
13328 vtable. The following dwarf expression means
13330 BaseAddr = ObAddr + *((*ObAddr) - Offset)
13332 This is specific to the V3 ABI, of course. */
13334 dw_loc_descr_ref tmp;
13336 /* Make a copy of the object address. */
13337 tmp = new_loc_descr (DW_OP_dup, 0, 0);
13338 add_loc_descr (&loc_descr, tmp);
13340 /* Extract the vtable address. */
13341 tmp = new_loc_descr (DW_OP_deref, 0, 0);
13342 add_loc_descr (&loc_descr, tmp);
13344 /* Calculate the address of the offset. */
13345 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
13346 gcc_assert (offset < 0);
13348 tmp = int_loc_descriptor (-offset);
13349 add_loc_descr (&loc_descr, tmp);
13350 tmp = new_loc_descr (DW_OP_minus, 0, 0);
13351 add_loc_descr (&loc_descr, tmp);
13353 /* Extract the offset. */
13354 tmp = new_loc_descr (DW_OP_deref, 0, 0);
13355 add_loc_descr (&loc_descr, tmp);
13357 /* Add it to the object address. */
13358 tmp = new_loc_descr (DW_OP_plus, 0, 0);
13359 add_loc_descr (&loc_descr, tmp);
13362 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
13365 offset = field_byte_offset (decl);
13369 if (dwarf_version > 2)
13371 /* Don't need to output a location expression, just the constant. */
13372 add_AT_int (die, DW_AT_data_member_location, offset);
13377 enum dwarf_location_atom op;
13379 /* The DWARF2 standard says that we should assume that the structure
13380 address is already on the stack, so we can specify a structure
13381 field address by using DW_OP_plus_uconst. */
13383 #ifdef MIPS_DEBUGGING_INFO
13384 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
13385 operator correctly. It works only if we leave the offset on the
13389 op = DW_OP_plus_uconst;
13392 loc_descr = new_loc_descr (op, offset, 0);
13396 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
13399 /* Writes integer values to dw_vec_const array. */
13402 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
13406 *dest++ = val & 0xff;
13412 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
13414 static HOST_WIDE_INT
13415 extract_int (const unsigned char *src, unsigned int size)
13417 HOST_WIDE_INT val = 0;
13423 val |= *--src & 0xff;
13429 /* Writes floating point values to dw_vec_const array. */
13432 insert_float (const_rtx rtl, unsigned char *array)
13434 REAL_VALUE_TYPE rv;
13438 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
13439 real_to_target (val, &rv, GET_MODE (rtl));
13441 /* real_to_target puts 32-bit pieces in each long. Pack them. */
13442 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
13444 insert_int (val[i], 4, array);
13449 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
13450 does not have a "location" either in memory or in a register. These
13451 things can arise in GNU C when a constant is passed as an actual parameter
13452 to an inlined function. They can also arise in C++ where declared
13453 constants do not necessarily get memory "homes". */
13456 add_const_value_attribute (dw_die_ref die, rtx rtl)
13458 switch (GET_CODE (rtl))
13462 HOST_WIDE_INT val = INTVAL (rtl);
13465 add_AT_int (die, DW_AT_const_value, val);
13467 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
13472 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
13473 floating-point constant. A CONST_DOUBLE is used whenever the
13474 constant requires more than one word in order to be adequately
13477 enum machine_mode mode = GET_MODE (rtl);
13479 if (SCALAR_FLOAT_MODE_P (mode))
13481 unsigned int length = GET_MODE_SIZE (mode);
13482 unsigned char *array = GGC_NEWVEC (unsigned char, length);
13484 insert_float (rtl, array);
13485 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
13488 add_AT_double (die, DW_AT_const_value,
13489 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
13495 enum machine_mode mode = GET_MODE (rtl);
13496 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
13497 unsigned int length = CONST_VECTOR_NUNITS (rtl);
13498 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
13502 switch (GET_MODE_CLASS (mode))
13504 case MODE_VECTOR_INT:
13505 for (i = 0, p = array; i < length; i++, p += elt_size)
13507 rtx elt = CONST_VECTOR_ELT (rtl, i);
13508 HOST_WIDE_INT lo, hi;
13510 switch (GET_CODE (elt))
13518 lo = CONST_DOUBLE_LOW (elt);
13519 hi = CONST_DOUBLE_HIGH (elt);
13523 gcc_unreachable ();
13526 if (elt_size <= sizeof (HOST_WIDE_INT))
13527 insert_int (lo, elt_size, p);
13530 unsigned char *p0 = p;
13531 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
13533 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
13534 if (WORDS_BIG_ENDIAN)
13539 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
13540 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
13545 case MODE_VECTOR_FLOAT:
13546 for (i = 0, p = array; i < length; i++, p += elt_size)
13548 rtx elt = CONST_VECTOR_ELT (rtl, i);
13549 insert_float (elt, p);
13554 gcc_unreachable ();
13557 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
13562 resolve_one_addr (&rtl, NULL);
13563 add_AT_addr (die, DW_AT_const_value, rtl);
13564 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13568 if (CONSTANT_P (XEXP (rtl, 0)))
13569 return add_const_value_attribute (die, XEXP (rtl, 0));
13572 if (!const_ok_for_output (rtl))
13575 add_AT_addr (die, DW_AT_const_value, rtl);
13576 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13580 /* In cases where an inlined instance of an inline function is passed
13581 the address of an `auto' variable (which is local to the caller) we
13582 can get a situation where the DECL_RTL of the artificial local
13583 variable (for the inlining) which acts as a stand-in for the
13584 corresponding formal parameter (of the inline function) will look
13585 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
13586 exactly a compile-time constant expression, but it isn't the address
13587 of the (artificial) local variable either. Rather, it represents the
13588 *value* which the artificial local variable always has during its
13589 lifetime. We currently have no way to represent such quasi-constant
13590 values in Dwarf, so for now we just punt and generate nothing. */
13598 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
13599 && MEM_READONLY_P (rtl)
13600 && GET_MODE (rtl) == BLKmode)
13602 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
13608 /* No other kinds of rtx should be possible here. */
13609 gcc_unreachable ();
13614 /* Determine whether the evaluation of EXPR references any variables
13615 or functions which aren't otherwise used (and therefore may not be
13618 reference_to_unused (tree * tp, int * walk_subtrees,
13619 void * data ATTRIBUTE_UNUSED)
13621 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
13622 *walk_subtrees = 0;
13624 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
13625 && ! TREE_ASM_WRITTEN (*tp))
13627 /* ??? The C++ FE emits debug information for using decls, so
13628 putting gcc_unreachable here falls over. See PR31899. For now
13629 be conservative. */
13630 else if (!cgraph_global_info_ready
13631 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
13633 else if (TREE_CODE (*tp) == VAR_DECL)
13635 struct varpool_node *node = varpool_node (*tp);
13639 else if (TREE_CODE (*tp) == FUNCTION_DECL
13640 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
13642 /* The call graph machinery must have finished analyzing,
13643 optimizing and gimplifying the CU by now.
13644 So if *TP has no call graph node associated
13645 to it, it means *TP will not be emitted. */
13646 if (!cgraph_get_node (*tp))
13649 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
13655 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
13656 for use in a later add_const_value_attribute call. */
13659 rtl_for_decl_init (tree init, tree type)
13661 rtx rtl = NULL_RTX;
13663 /* If a variable is initialized with a string constant without embedded
13664 zeros, build CONST_STRING. */
13665 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
13667 tree enttype = TREE_TYPE (type);
13668 tree domain = TYPE_DOMAIN (type);
13669 enum machine_mode mode = TYPE_MODE (enttype);
13671 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
13673 && integer_zerop (TYPE_MIN_VALUE (domain))
13674 && compare_tree_int (TYPE_MAX_VALUE (domain),
13675 TREE_STRING_LENGTH (init) - 1) == 0
13676 && ((size_t) TREE_STRING_LENGTH (init)
13677 == strlen (TREE_STRING_POINTER (init)) + 1))
13679 rtl = gen_rtx_CONST_STRING (VOIDmode,
13680 ggc_strdup (TREE_STRING_POINTER (init)));
13681 rtl = gen_rtx_MEM (BLKmode, rtl);
13682 MEM_READONLY_P (rtl) = 1;
13685 /* Other aggregates, and complex values, could be represented using
13687 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
13689 /* Vectors only work if their mode is supported by the target.
13690 FIXME: generic vectors ought to work too. */
13691 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
13693 /* If the initializer is something that we know will expand into an
13694 immediate RTL constant, expand it now. We must be careful not to
13695 reference variables which won't be output. */
13696 else if (initializer_constant_valid_p (init, type)
13697 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
13699 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
13701 if (TREE_CODE (type) == VECTOR_TYPE)
13702 switch (TREE_CODE (init))
13707 if (TREE_CONSTANT (init))
13709 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
13710 bool constant_p = true;
13712 unsigned HOST_WIDE_INT ix;
13714 /* Even when ctor is constant, it might contain non-*_CST
13715 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
13716 belong into VECTOR_CST nodes. */
13717 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
13718 if (!CONSTANT_CLASS_P (value))
13720 constant_p = false;
13726 init = build_vector_from_ctor (type, elts);
13736 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
13738 /* If expand_expr returns a MEM, it wasn't immediate. */
13739 gcc_assert (!rtl || !MEM_P (rtl));
13745 /* Generate RTL for the variable DECL to represent its location. */
13748 rtl_for_decl_location (tree decl)
13752 /* Here we have to decide where we are going to say the parameter "lives"
13753 (as far as the debugger is concerned). We only have a couple of
13754 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
13756 DECL_RTL normally indicates where the parameter lives during most of the
13757 activation of the function. If optimization is enabled however, this
13758 could be either NULL or else a pseudo-reg. Both of those cases indicate
13759 that the parameter doesn't really live anywhere (as far as the code
13760 generation parts of GCC are concerned) during most of the function's
13761 activation. That will happen (for example) if the parameter is never
13762 referenced within the function.
13764 We could just generate a location descriptor here for all non-NULL
13765 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
13766 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
13767 where DECL_RTL is NULL or is a pseudo-reg.
13769 Note however that we can only get away with using DECL_INCOMING_RTL as
13770 a backup substitute for DECL_RTL in certain limited cases. In cases
13771 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
13772 we can be sure that the parameter was passed using the same type as it is
13773 declared to have within the function, and that its DECL_INCOMING_RTL
13774 points us to a place where a value of that type is passed.
13776 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
13777 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
13778 because in these cases DECL_INCOMING_RTL points us to a value of some
13779 type which is *different* from the type of the parameter itself. Thus,
13780 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
13781 such cases, the debugger would end up (for example) trying to fetch a
13782 `float' from a place which actually contains the first part of a
13783 `double'. That would lead to really incorrect and confusing
13784 output at debug-time.
13786 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
13787 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
13788 are a couple of exceptions however. On little-endian machines we can
13789 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
13790 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
13791 an integral type that is smaller than TREE_TYPE (decl). These cases arise
13792 when (on a little-endian machine) a non-prototyped function has a
13793 parameter declared to be of type `short' or `char'. In such cases,
13794 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
13795 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
13796 passed `int' value. If the debugger then uses that address to fetch
13797 a `short' or a `char' (on a little-endian machine) the result will be
13798 the correct data, so we allow for such exceptional cases below.
13800 Note that our goal here is to describe the place where the given formal
13801 parameter lives during most of the function's activation (i.e. between the
13802 end of the prologue and the start of the epilogue). We'll do that as best
13803 as we can. Note however that if the given formal parameter is modified
13804 sometime during the execution of the function, then a stack backtrace (at
13805 debug-time) will show the function as having been called with the *new*
13806 value rather than the value which was originally passed in. This happens
13807 rarely enough that it is not a major problem, but it *is* a problem, and
13808 I'd like to fix it.
13810 A future version of dwarf2out.c may generate two additional attributes for
13811 any given DW_TAG_formal_parameter DIE which will describe the "passed
13812 type" and the "passed location" for the given formal parameter in addition
13813 to the attributes we now generate to indicate the "declared type" and the
13814 "active location" for each parameter. This additional set of attributes
13815 could be used by debuggers for stack backtraces. Separately, note that
13816 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
13817 This happens (for example) for inlined-instances of inline function formal
13818 parameters which are never referenced. This really shouldn't be
13819 happening. All PARM_DECL nodes should get valid non-NULL
13820 DECL_INCOMING_RTL values. FIXME. */
13822 /* Use DECL_RTL as the "location" unless we find something better. */
13823 rtl = DECL_RTL_IF_SET (decl);
13825 /* When generating abstract instances, ignore everything except
13826 constants, symbols living in memory, and symbols living in
13827 fixed registers. */
13828 if (! reload_completed)
13831 && (CONSTANT_P (rtl)
13833 && CONSTANT_P (XEXP (rtl, 0)))
13835 && TREE_CODE (decl) == VAR_DECL
13836 && TREE_STATIC (decl))))
13838 rtl = targetm.delegitimize_address (rtl);
13843 else if (TREE_CODE (decl) == PARM_DECL)
13845 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
13847 tree declared_type = TREE_TYPE (decl);
13848 tree passed_type = DECL_ARG_TYPE (decl);
13849 enum machine_mode dmode = TYPE_MODE (declared_type);
13850 enum machine_mode pmode = TYPE_MODE (passed_type);
13852 /* This decl represents a formal parameter which was optimized out.
13853 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
13854 all cases where (rtl == NULL_RTX) just below. */
13855 if (dmode == pmode)
13856 rtl = DECL_INCOMING_RTL (decl);
13857 else if (SCALAR_INT_MODE_P (dmode)
13858 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
13859 && DECL_INCOMING_RTL (decl))
13861 rtx inc = DECL_INCOMING_RTL (decl);
13864 else if (MEM_P (inc))
13866 if (BYTES_BIG_ENDIAN)
13867 rtl = adjust_address_nv (inc, dmode,
13868 GET_MODE_SIZE (pmode)
13869 - GET_MODE_SIZE (dmode));
13876 /* If the parm was passed in registers, but lives on the stack, then
13877 make a big endian correction if the mode of the type of the
13878 parameter is not the same as the mode of the rtl. */
13879 /* ??? This is the same series of checks that are made in dbxout.c before
13880 we reach the big endian correction code there. It isn't clear if all
13881 of these checks are necessary here, but keeping them all is the safe
13883 else if (MEM_P (rtl)
13884 && XEXP (rtl, 0) != const0_rtx
13885 && ! CONSTANT_P (XEXP (rtl, 0))
13886 /* Not passed in memory. */
13887 && !MEM_P (DECL_INCOMING_RTL (decl))
13888 /* Not passed by invisible reference. */
13889 && (!REG_P (XEXP (rtl, 0))
13890 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
13891 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
13892 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
13893 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
13896 /* Big endian correction check. */
13897 && BYTES_BIG_ENDIAN
13898 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
13899 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
13902 int offset = (UNITS_PER_WORD
13903 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
13905 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13906 plus_constant (XEXP (rtl, 0), offset));
13909 else if (TREE_CODE (decl) == VAR_DECL
13912 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
13913 && BYTES_BIG_ENDIAN)
13915 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
13916 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
13918 /* If a variable is declared "register" yet is smaller than
13919 a register, then if we store the variable to memory, it
13920 looks like we're storing a register-sized value, when in
13921 fact we are not. We need to adjust the offset of the
13922 storage location to reflect the actual value's bytes,
13923 else gdb will not be able to display it. */
13925 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13926 plus_constant (XEXP (rtl, 0), rsize-dsize));
13929 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
13930 and will have been substituted directly into all expressions that use it.
13931 C does not have such a concept, but C++ and other languages do. */
13932 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
13933 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
13936 rtl = targetm.delegitimize_address (rtl);
13938 /* If we don't look past the constant pool, we risk emitting a
13939 reference to a constant pool entry that isn't referenced from
13940 code, and thus is not emitted. */
13942 rtl = avoid_constant_pool_reference (rtl);
13947 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
13948 returned. If so, the decl for the COMMON block is returned, and the
13949 value is the offset into the common block for the symbol. */
13952 fortran_common (tree decl, HOST_WIDE_INT *value)
13954 tree val_expr, cvar;
13955 enum machine_mode mode;
13956 HOST_WIDE_INT bitsize, bitpos;
13958 int volatilep = 0, unsignedp = 0;
13960 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
13961 it does not have a value (the offset into the common area), or if it
13962 is thread local (as opposed to global) then it isn't common, and shouldn't
13963 be handled as such. */
13964 if (TREE_CODE (decl) != VAR_DECL
13965 || !TREE_PUBLIC (decl)
13966 || !TREE_STATIC (decl)
13967 || !DECL_HAS_VALUE_EXPR_P (decl)
13971 val_expr = DECL_VALUE_EXPR (decl);
13972 if (TREE_CODE (val_expr) != COMPONENT_REF)
13975 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
13976 &mode, &unsignedp, &volatilep, true);
13978 if (cvar == NULL_TREE
13979 || TREE_CODE (cvar) != VAR_DECL
13980 || DECL_ARTIFICIAL (cvar)
13981 || !TREE_PUBLIC (cvar))
13985 if (offset != NULL)
13987 if (!host_integerp (offset, 0))
13989 *value = tree_low_cst (offset, 0);
13992 *value += bitpos / BITS_PER_UNIT;
13997 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
13998 data attribute for a variable or a parameter. We generate the
13999 DW_AT_const_value attribute only in those cases where the given variable
14000 or parameter does not have a true "location" either in memory or in a
14001 register. This can happen (for example) when a constant is passed as an
14002 actual argument in a call to an inline function. (It's possible that
14003 these things can crop up in other ways also.) Note that one type of
14004 constant value which can be passed into an inlined function is a constant
14005 pointer. This can happen for example if an actual argument in an inlined
14006 function call evaluates to a compile-time constant address. */
14009 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
14010 enum dwarf_attribute attr)
14013 dw_loc_list_ref list;
14014 var_loc_list *loc_list;
14016 if (TREE_CODE (decl) == ERROR_MARK)
14019 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
14020 || TREE_CODE (decl) == RESULT_DECL);
14022 /* Try to get some constant RTL for this decl, and use that as the value of
14025 rtl = rtl_for_decl_location (decl);
14026 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14027 && add_const_value_attribute (die, rtl))
14030 /* See if we have single element location list that is equivalent to
14031 a constant value. That way we are better to use add_const_value_attribute
14032 rather than expanding constant value equivalent. */
14033 loc_list = lookup_decl_loc (decl);
14034 if (loc_list && loc_list->first && loc_list->first == loc_list->last)
14036 enum var_init_status status;
14037 struct var_loc_node *node;
14039 node = loc_list->first;
14040 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
14041 rtl = NOTE_VAR_LOCATION (node->var_loc_note);
14042 if (GET_CODE (rtl) == VAR_LOCATION
14043 && GET_CODE (XEXP (rtl, 1)) != PARALLEL)
14044 rtl = XEXP (XEXP (rtl, 1), 0);
14045 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
14046 && add_const_value_attribute (die, rtl))
14049 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
14052 add_AT_location_description (die, attr, list);
14055 /* None of that worked, so it must not really have a location;
14056 try adding a constant value attribute from the DECL_INITIAL. */
14057 return tree_add_const_value_attribute_for_decl (die, decl);
14060 /* Add VARIABLE and DIE into deferred locations list. */
14063 defer_location (tree variable, dw_die_ref die)
14065 deferred_locations entry;
14066 entry.variable = variable;
14068 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
14071 /* Helper function for tree_add_const_value_attribute. Natively encode
14072 initializer INIT into an array. Return true if successful. */
14075 native_encode_initializer (tree init, unsigned char *array, int size)
14079 if (init == NULL_TREE)
14083 switch (TREE_CODE (init))
14086 type = TREE_TYPE (init);
14087 if (TREE_CODE (type) == ARRAY_TYPE)
14089 tree enttype = TREE_TYPE (type);
14090 enum machine_mode mode = TYPE_MODE (enttype);
14092 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
14094 if (int_size_in_bytes (type) != size)
14096 if (size > TREE_STRING_LENGTH (init))
14098 memcpy (array, TREE_STRING_POINTER (init),
14099 TREE_STRING_LENGTH (init));
14100 memset (array + TREE_STRING_LENGTH (init),
14101 '\0', size - TREE_STRING_LENGTH (init));
14104 memcpy (array, TREE_STRING_POINTER (init), size);
14109 type = TREE_TYPE (init);
14110 if (int_size_in_bytes (type) != size)
14112 if (TREE_CODE (type) == ARRAY_TYPE)
14114 HOST_WIDE_INT min_index;
14115 unsigned HOST_WIDE_INT cnt;
14116 int curpos = 0, fieldsize;
14117 constructor_elt *ce;
14119 if (TYPE_DOMAIN (type) == NULL_TREE
14120 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
14123 fieldsize = int_size_in_bytes (TREE_TYPE (type));
14124 if (fieldsize <= 0)
14127 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
14128 memset (array, '\0', size);
14130 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
14133 tree val = ce->value;
14134 tree index = ce->index;
14136 if (index && TREE_CODE (index) == RANGE_EXPR)
14137 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
14140 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
14145 if (!native_encode_initializer (val, array + pos, fieldsize))
14148 curpos = pos + fieldsize;
14149 if (index && TREE_CODE (index) == RANGE_EXPR)
14151 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
14152 - tree_low_cst (TREE_OPERAND (index, 0), 0);
14156 memcpy (array + curpos, array + pos, fieldsize);
14157 curpos += fieldsize;
14160 gcc_assert (curpos <= size);
14164 else if (TREE_CODE (type) == RECORD_TYPE
14165 || TREE_CODE (type) == UNION_TYPE)
14167 tree field = NULL_TREE;
14168 unsigned HOST_WIDE_INT cnt;
14169 constructor_elt *ce;
14171 if (int_size_in_bytes (type) != size)
14174 if (TREE_CODE (type) == RECORD_TYPE)
14175 field = TYPE_FIELDS (type);
14178 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
14179 cnt++, field = field ? TREE_CHAIN (field) : 0)
14181 tree val = ce->value;
14182 int pos, fieldsize;
14184 if (ce->index != 0)
14190 if (field == NULL_TREE || DECL_BIT_FIELD (field))
14193 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
14194 && TYPE_DOMAIN (TREE_TYPE (field))
14195 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
14197 else if (DECL_SIZE_UNIT (field) == NULL_TREE
14198 || !host_integerp (DECL_SIZE_UNIT (field), 0))
14200 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
14201 pos = int_byte_position (field);
14202 gcc_assert (pos + fieldsize <= size);
14204 && !native_encode_initializer (val, array + pos, fieldsize))
14210 case VIEW_CONVERT_EXPR:
14211 case NON_LVALUE_EXPR:
14212 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
14214 return native_encode_expr (init, array, size) == size;
14218 /* Attach a DW_AT_const_value attribute to DIE. The value of the
14219 attribute is the const value T. */
14222 tree_add_const_value_attribute (dw_die_ref die, tree t)
14225 tree type = TREE_TYPE (t);
14228 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
14232 gcc_assert (!DECL_P (init));
14234 rtl = rtl_for_decl_init (init, type);
14236 return add_const_value_attribute (die, rtl);
14237 /* If the host and target are sane, try harder. */
14238 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
14239 && initializer_constant_valid_p (init, type))
14241 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
14242 if (size > 0 && (int) size == size)
14244 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
14246 if (native_encode_initializer (init, array, size))
14248 add_AT_vec (die, DW_AT_const_value, size, 1, array);
14256 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
14257 attribute is the const value of T, where T is an integral constant
14258 variable with static storage duration
14259 (so it can't be a PARM_DECL or a RESULT_DECL). */
14262 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
14266 || (TREE_CODE (decl) != VAR_DECL
14267 && TREE_CODE (decl) != CONST_DECL))
14270 if (TREE_READONLY (decl)
14271 && ! TREE_THIS_VOLATILE (decl)
14272 && DECL_INITIAL (decl))
14277 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
14280 /* Convert the CFI instructions for the current function into a
14281 location list. This is used for DW_AT_frame_base when we targeting
14282 a dwarf2 consumer that does not support the dwarf3
14283 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
14286 static dw_loc_list_ref
14287 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
14290 dw_loc_list_ref list, *list_tail;
14292 dw_cfa_location last_cfa, next_cfa;
14293 const char *start_label, *last_label, *section;
14294 dw_cfa_location remember;
14296 fde = current_fde ();
14297 gcc_assert (fde != NULL);
14299 section = secname_for_decl (current_function_decl);
14303 memset (&next_cfa, 0, sizeof (next_cfa));
14304 next_cfa.reg = INVALID_REGNUM;
14305 remember = next_cfa;
14307 start_label = fde->dw_fde_begin;
14309 /* ??? Bald assumption that the CIE opcode list does not contain
14310 advance opcodes. */
14311 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
14312 lookup_cfa_1 (cfi, &next_cfa, &remember);
14314 last_cfa = next_cfa;
14315 last_label = start_label;
14317 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
14318 switch (cfi->dw_cfi_opc)
14320 case DW_CFA_set_loc:
14321 case DW_CFA_advance_loc1:
14322 case DW_CFA_advance_loc2:
14323 case DW_CFA_advance_loc4:
14324 if (!cfa_equal_p (&last_cfa, &next_cfa))
14326 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
14327 start_label, last_label, section,
14330 list_tail = &(*list_tail)->dw_loc_next;
14331 last_cfa = next_cfa;
14332 start_label = last_label;
14334 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
14337 case DW_CFA_advance_loc:
14338 /* The encoding is complex enough that we should never emit this. */
14339 gcc_unreachable ();
14342 lookup_cfa_1 (cfi, &next_cfa, &remember);
14346 if (!cfa_equal_p (&last_cfa, &next_cfa))
14348 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
14349 start_label, last_label, section,
14351 list_tail = &(*list_tail)->dw_loc_next;
14352 start_label = last_label;
14354 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
14355 start_label, fde->dw_fde_end, section,
14361 /* Compute a displacement from the "steady-state frame pointer" to the
14362 frame base (often the same as the CFA), and store it in
14363 frame_pointer_fb_offset. OFFSET is added to the displacement
14364 before the latter is negated. */
14367 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
14371 #ifdef FRAME_POINTER_CFA_OFFSET
14372 reg = frame_pointer_rtx;
14373 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
14375 reg = arg_pointer_rtx;
14376 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
14379 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
14380 if (GET_CODE (elim) == PLUS)
14382 offset += INTVAL (XEXP (elim, 1));
14383 elim = XEXP (elim, 0);
14386 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
14387 && (elim == hard_frame_pointer_rtx
14388 || elim == stack_pointer_rtx))
14389 || elim == (frame_pointer_needed
14390 ? hard_frame_pointer_rtx
14391 : stack_pointer_rtx));
14393 frame_pointer_fb_offset = -offset;
14396 /* Generate a DW_AT_name attribute given some string value to be included as
14397 the value of the attribute. */
14400 add_name_attribute (dw_die_ref die, const char *name_string)
14402 if (name_string != NULL && *name_string != 0)
14404 if (demangle_name_func)
14405 name_string = (*demangle_name_func) (name_string);
14407 add_AT_string (die, DW_AT_name, name_string);
14411 /* Generate a DW_AT_comp_dir attribute for DIE. */
14414 add_comp_dir_attribute (dw_die_ref die)
14416 const char *wd = get_src_pwd ();
14422 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
14426 wdlen = strlen (wd);
14427 wd1 = GGC_NEWVEC (char, wdlen + 2);
14429 wd1 [wdlen] = DIR_SEPARATOR;
14430 wd1 [wdlen + 1] = 0;
14434 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
14437 /* Given a tree node describing an array bound (either lower or upper) output
14438 a representation for that bound. */
14441 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
14443 switch (TREE_CODE (bound))
14448 /* All fixed-bounds are represented by INTEGER_CST nodes. */
14451 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
14453 /* Use the default if possible. */
14454 if (bound_attr == DW_AT_lower_bound
14455 && (((is_c_family () || is_java ()) && integer_zerop (bound))
14456 || (is_fortran () && integer_onep (bound))))
14459 /* Otherwise represent the bound as an unsigned value with the
14460 precision of its type. The precision and signedness of the
14461 type will be necessary to re-interpret it unambiguously. */
14462 else if (prec < HOST_BITS_PER_WIDE_INT)
14464 unsigned HOST_WIDE_INT mask
14465 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
14466 add_AT_unsigned (subrange_die, bound_attr,
14467 TREE_INT_CST_LOW (bound) & mask);
14469 else if (prec == HOST_BITS_PER_WIDE_INT
14470 || TREE_INT_CST_HIGH (bound) == 0)
14471 add_AT_unsigned (subrange_die, bound_attr,
14472 TREE_INT_CST_LOW (bound));
14474 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
14475 TREE_INT_CST_LOW (bound));
14480 case VIEW_CONVERT_EXPR:
14481 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
14491 dw_die_ref decl_die = lookup_decl_die (bound);
14492 dw_loc_list_ref loc;
14494 /* ??? Can this happen, or should the variable have been bound
14495 first? Probably it can, since I imagine that we try to create
14496 the types of parameters in the order in which they exist in
14497 the list, and won't have created a forward reference to a
14498 later parameter. */
14499 if (decl_die != NULL)
14500 add_AT_die_ref (subrange_die, bound_attr, decl_die);
14503 loc = loc_list_from_tree (bound, 0);
14504 add_AT_location_description (subrange_die, bound_attr, loc);
14511 /* Otherwise try to create a stack operation procedure to
14512 evaluate the value of the array bound. */
14514 dw_die_ref ctx, decl_die;
14515 dw_loc_list_ref list;
14517 list = loc_list_from_tree (bound, 2);
14521 if (current_function_decl == 0)
14522 ctx = comp_unit_die;
14524 ctx = lookup_decl_die (current_function_decl);
14526 decl_die = new_die (DW_TAG_variable, ctx, bound);
14527 add_AT_flag (decl_die, DW_AT_artificial, 1);
14528 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
14529 if (list->dw_loc_next)
14530 add_AT_loc_list (decl_die, DW_AT_location, list);
14532 add_AT_loc (decl_die, DW_AT_location, list->expr);
14534 add_AT_die_ref (subrange_die, bound_attr, decl_die);
14540 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
14541 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
14542 Note that the block of subscript information for an array type also
14543 includes information about the element type of the given array type. */
14546 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
14548 unsigned dimension_number;
14550 dw_die_ref subrange_die;
14552 for (dimension_number = 0;
14553 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
14554 type = TREE_TYPE (type), dimension_number++)
14556 tree domain = TYPE_DOMAIN (type);
14558 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
14561 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
14562 and (in GNU C only) variable bounds. Handle all three forms
14564 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
14567 /* We have an array type with specified bounds. */
14568 lower = TYPE_MIN_VALUE (domain);
14569 upper = TYPE_MAX_VALUE (domain);
14571 /* Define the index type. */
14572 if (TREE_TYPE (domain))
14574 /* ??? This is probably an Ada unnamed subrange type. Ignore the
14575 TREE_TYPE field. We can't emit debug info for this
14576 because it is an unnamed integral type. */
14577 if (TREE_CODE (domain) == INTEGER_TYPE
14578 && TYPE_NAME (domain) == NULL_TREE
14579 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
14580 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
14583 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
14587 /* ??? If upper is NULL, the array has unspecified length,
14588 but it does have a lower bound. This happens with Fortran
14590 Since the debugger is definitely going to need to know N
14591 to produce useful results, go ahead and output the lower
14592 bound solo, and hope the debugger can cope. */
14594 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
14596 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
14599 /* Otherwise we have an array type with an unspecified length. The
14600 DWARF-2 spec does not say how to handle this; let's just leave out the
14606 add_byte_size_attribute (dw_die_ref die, tree tree_node)
14610 switch (TREE_CODE (tree_node))
14615 case ENUMERAL_TYPE:
14618 case QUAL_UNION_TYPE:
14619 size = int_size_in_bytes (tree_node);
14622 /* For a data member of a struct or union, the DW_AT_byte_size is
14623 generally given as the number of bytes normally allocated for an
14624 object of the *declared* type of the member itself. This is true
14625 even for bit-fields. */
14626 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
14629 gcc_unreachable ();
14632 /* Note that `size' might be -1 when we get to this point. If it is, that
14633 indicates that the byte size of the entity in question is variable. We
14634 have no good way of expressing this fact in Dwarf at the present time,
14635 so just let the -1 pass on through. */
14636 add_AT_unsigned (die, DW_AT_byte_size, size);
14639 /* For a FIELD_DECL node which represents a bit-field, output an attribute
14640 which specifies the distance in bits from the highest order bit of the
14641 "containing object" for the bit-field to the highest order bit of the
14644 For any given bit-field, the "containing object" is a hypothetical object
14645 (of some integral or enum type) within which the given bit-field lives. The
14646 type of this hypothetical "containing object" is always the same as the
14647 declared type of the individual bit-field itself. The determination of the
14648 exact location of the "containing object" for a bit-field is rather
14649 complicated. It's handled by the `field_byte_offset' function (above).
14651 Note that it is the size (in bytes) of the hypothetical "containing object"
14652 which will be given in the DW_AT_byte_size attribute for this bit-field.
14653 (See `byte_size_attribute' above). */
14656 add_bit_offset_attribute (dw_die_ref die, tree decl)
14658 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
14659 tree type = DECL_BIT_FIELD_TYPE (decl);
14660 HOST_WIDE_INT bitpos_int;
14661 HOST_WIDE_INT highest_order_object_bit_offset;
14662 HOST_WIDE_INT highest_order_field_bit_offset;
14663 HOST_WIDE_INT unsigned bit_offset;
14665 /* Must be a field and a bit field. */
14666 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
14668 /* We can't yet handle bit-fields whose offsets are variable, so if we
14669 encounter such things, just return without generating any attribute
14670 whatsoever. Likewise for variable or too large size. */
14671 if (! host_integerp (bit_position (decl), 0)
14672 || ! host_integerp (DECL_SIZE (decl), 1))
14675 bitpos_int = int_bit_position (decl);
14677 /* Note that the bit offset is always the distance (in bits) from the
14678 highest-order bit of the "containing object" to the highest-order bit of
14679 the bit-field itself. Since the "high-order end" of any object or field
14680 is different on big-endian and little-endian machines, the computation
14681 below must take account of these differences. */
14682 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
14683 highest_order_field_bit_offset = bitpos_int;
14685 if (! BYTES_BIG_ENDIAN)
14687 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
14688 highest_order_object_bit_offset += simple_type_size_in_bits (type);
14692 = (! BYTES_BIG_ENDIAN
14693 ? highest_order_object_bit_offset - highest_order_field_bit_offset
14694 : highest_order_field_bit_offset - highest_order_object_bit_offset);
14696 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
14699 /* For a FIELD_DECL node which represents a bit field, output an attribute
14700 which specifies the length in bits of the given field. */
14703 add_bit_size_attribute (dw_die_ref die, tree decl)
14705 /* Must be a field and a bit field. */
14706 gcc_assert (TREE_CODE (decl) == FIELD_DECL
14707 && DECL_BIT_FIELD_TYPE (decl));
14709 if (host_integerp (DECL_SIZE (decl), 1))
14710 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
14713 /* If the compiled language is ANSI C, then add a 'prototyped'
14714 attribute, if arg types are given for the parameters of a function. */
14717 add_prototyped_attribute (dw_die_ref die, tree func_type)
14719 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
14720 && TYPE_ARG_TYPES (func_type) != NULL)
14721 add_AT_flag (die, DW_AT_prototyped, 1);
14724 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
14725 by looking in either the type declaration or object declaration
14728 static inline dw_die_ref
14729 add_abstract_origin_attribute (dw_die_ref die, tree origin)
14731 dw_die_ref origin_die = NULL;
14733 if (TREE_CODE (origin) != FUNCTION_DECL)
14735 /* We may have gotten separated from the block for the inlined
14736 function, if we're in an exception handler or some such; make
14737 sure that the abstract function has been written out.
14739 Doing this for nested functions is wrong, however; functions are
14740 distinct units, and our context might not even be inline. */
14744 fn = TYPE_STUB_DECL (fn);
14746 fn = decl_function_context (fn);
14748 dwarf2out_abstract_function (fn);
14751 if (DECL_P (origin))
14752 origin_die = lookup_decl_die (origin);
14753 else if (TYPE_P (origin))
14754 origin_die = lookup_type_die (origin);
14756 /* XXX: Functions that are never lowered don't always have correct block
14757 trees (in the case of java, they simply have no block tree, in some other
14758 languages). For these functions, there is nothing we can really do to
14759 output correct debug info for inlined functions in all cases. Rather
14760 than die, we'll just produce deficient debug info now, in that we will
14761 have variables without a proper abstract origin. In the future, when all
14762 functions are lowered, we should re-add a gcc_assert (origin_die)
14766 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
14770 /* We do not currently support the pure_virtual attribute. */
14773 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
14775 if (DECL_VINDEX (func_decl))
14777 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14779 if (host_integerp (DECL_VINDEX (func_decl), 0))
14780 add_AT_loc (die, DW_AT_vtable_elem_location,
14781 new_loc_descr (DW_OP_constu,
14782 tree_low_cst (DECL_VINDEX (func_decl), 0),
14785 /* GNU extension: Record what type this method came from originally. */
14786 if (debug_info_level > DINFO_LEVEL_TERSE)
14787 add_AT_die_ref (die, DW_AT_containing_type,
14788 lookup_type_die (DECL_CONTEXT (func_decl)));
14792 /* Add source coordinate attributes for the given decl. */
14795 add_src_coords_attributes (dw_die_ref die, tree decl)
14797 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14799 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
14800 add_AT_unsigned (die, DW_AT_decl_line, s.line);
14803 /* Add a DW_AT_name attribute and source coordinate attribute for the
14804 given decl, but only if it actually has a name. */
14807 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
14811 decl_name = DECL_NAME (decl);
14812 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
14814 add_name_attribute (die, dwarf2_name (decl, 0));
14815 if (! DECL_ARTIFICIAL (decl))
14816 add_src_coords_attributes (die, decl);
14818 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
14819 && TREE_PUBLIC (decl)
14820 && !DECL_ABSTRACT (decl)
14821 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
14824 /* Defer until we have an assembler name set. */
14825 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
14827 limbo_die_node *asm_name;
14829 asm_name = GGC_CNEW (limbo_die_node);
14830 asm_name->die = die;
14831 asm_name->created_for = decl;
14832 asm_name->next = deferred_asm_name;
14833 deferred_asm_name = asm_name;
14835 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
14836 add_AT_string (die, DW_AT_MIPS_linkage_name,
14837 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
14841 #ifdef VMS_DEBUGGING_INFO
14842 /* Get the function's name, as described by its RTL. This may be different
14843 from the DECL_NAME name used in the source file. */
14844 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
14846 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
14847 XEXP (DECL_RTL (decl), 0));
14848 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
14853 /* Push a new declaration scope. */
14856 push_decl_scope (tree scope)
14858 VEC_safe_push (tree, gc, decl_scope_table, scope);
14861 /* Pop a declaration scope. */
14864 pop_decl_scope (void)
14866 VEC_pop (tree, decl_scope_table);
14869 /* Return the DIE for the scope that immediately contains this type.
14870 Non-named types get global scope. Named types nested in other
14871 types get their containing scope if it's open, or global scope
14872 otherwise. All other types (i.e. function-local named types) get
14873 the current active scope. */
14876 scope_die_for (tree t, dw_die_ref context_die)
14878 dw_die_ref scope_die = NULL;
14879 tree containing_scope;
14882 /* Non-types always go in the current scope. */
14883 gcc_assert (TYPE_P (t));
14885 containing_scope = TYPE_CONTEXT (t);
14887 /* Use the containing namespace if it was passed in (for a declaration). */
14888 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
14890 if (context_die == lookup_decl_die (containing_scope))
14893 containing_scope = NULL_TREE;
14896 /* Ignore function type "scopes" from the C frontend. They mean that
14897 a tagged type is local to a parmlist of a function declarator, but
14898 that isn't useful to DWARF. */
14899 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
14900 containing_scope = NULL_TREE;
14902 if (containing_scope == NULL_TREE)
14903 scope_die = comp_unit_die;
14904 else if (TYPE_P (containing_scope))
14906 /* For types, we can just look up the appropriate DIE. But
14907 first we check to see if we're in the middle of emitting it
14908 so we know where the new DIE should go. */
14909 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
14910 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
14915 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
14916 || TREE_ASM_WRITTEN (containing_scope));
14918 /* If none of the current dies are suitable, we get file scope. */
14919 scope_die = comp_unit_die;
14922 scope_die = lookup_type_die (containing_scope);
14925 scope_die = context_die;
14930 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
14933 local_scope_p (dw_die_ref context_die)
14935 for (; context_die; context_die = context_die->die_parent)
14936 if (context_die->die_tag == DW_TAG_inlined_subroutine
14937 || context_die->die_tag == DW_TAG_subprogram)
14943 /* Returns nonzero if CONTEXT_DIE is a class. */
14946 class_scope_p (dw_die_ref context_die)
14948 return (context_die
14949 && (context_die->die_tag == DW_TAG_structure_type
14950 || context_die->die_tag == DW_TAG_class_type
14951 || context_die->die_tag == DW_TAG_interface_type
14952 || context_die->die_tag == DW_TAG_union_type));
14955 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
14956 whether or not to treat a DIE in this context as a declaration. */
14959 class_or_namespace_scope_p (dw_die_ref context_die)
14961 return (class_scope_p (context_die)
14962 || (context_die && context_die->die_tag == DW_TAG_namespace));
14965 /* Many forms of DIEs require a "type description" attribute. This
14966 routine locates the proper "type descriptor" die for the type given
14967 by 'type', and adds a DW_AT_type attribute below the given die. */
14970 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
14971 int decl_volatile, dw_die_ref context_die)
14973 enum tree_code code = TREE_CODE (type);
14974 dw_die_ref type_die = NULL;
14976 /* ??? If this type is an unnamed subrange type of an integral, floating-point
14977 or fixed-point type, use the inner type. This is because we have no
14978 support for unnamed types in base_type_die. This can happen if this is
14979 an Ada subrange type. Correct solution is emit a subrange type die. */
14980 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
14981 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
14982 type = TREE_TYPE (type), code = TREE_CODE (type);
14984 if (code == ERROR_MARK
14985 /* Handle a special case. For functions whose return type is void, we
14986 generate *no* type attribute. (Note that no object may have type
14987 `void', so this only applies to function return types). */
14988 || code == VOID_TYPE)
14991 type_die = modified_type_die (type,
14992 decl_const || TYPE_READONLY (type),
14993 decl_volatile || TYPE_VOLATILE (type),
14996 if (type_die != NULL)
14997 add_AT_die_ref (object_die, DW_AT_type, type_die);
15000 /* Given an object die, add the calling convention attribute for the
15001 function call type. */
15003 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
15005 enum dwarf_calling_convention value = DW_CC_normal;
15007 value = ((enum dwarf_calling_convention)
15008 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
15010 /* DWARF doesn't provide a way to identify a program's source-level
15011 entry point. DW_AT_calling_convention attributes are only meant
15012 to describe functions' calling conventions. However, lacking a
15013 better way to signal the Fortran main program, we use this for the
15014 time being, following existing custom. */
15016 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
15017 value = DW_CC_program;
15019 /* Only add the attribute if the backend requests it, and
15020 is not DW_CC_normal. */
15021 if (value && (value != DW_CC_normal))
15022 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
15025 /* Given a tree pointer to a struct, class, union, or enum type node, return
15026 a pointer to the (string) tag name for the given type, or zero if the type
15027 was declared without a tag. */
15029 static const char *
15030 type_tag (const_tree type)
15032 const char *name = 0;
15034 if (TYPE_NAME (type) != 0)
15038 /* Find the IDENTIFIER_NODE for the type name. */
15039 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
15040 t = TYPE_NAME (type);
15042 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
15043 a TYPE_DECL node, regardless of whether or not a `typedef' was
15045 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
15046 && ! DECL_IGNORED_P (TYPE_NAME (type)))
15048 /* We want to be extra verbose. Don't call dwarf_name if
15049 DECL_NAME isn't set. The default hook for decl_printable_name
15050 doesn't like that, and in this context it's correct to return
15051 0, instead of "<anonymous>" or the like. */
15052 if (DECL_NAME (TYPE_NAME (type)))
15053 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
15056 /* Now get the name as a string, or invent one. */
15057 if (!name && t != 0)
15058 name = IDENTIFIER_POINTER (t);
15061 return (name == 0 || *name == '\0') ? 0 : name;
15064 /* Return the type associated with a data member, make a special check
15065 for bit field types. */
15068 member_declared_type (const_tree member)
15070 return (DECL_BIT_FIELD_TYPE (member)
15071 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
15074 /* Get the decl's label, as described by its RTL. This may be different
15075 from the DECL_NAME name used in the source file. */
15078 static const char *
15079 decl_start_label (tree decl)
15082 const char *fnname;
15084 x = DECL_RTL (decl);
15085 gcc_assert (MEM_P (x));
15088 gcc_assert (GET_CODE (x) == SYMBOL_REF);
15090 fnname = XSTR (x, 0);
15095 /* These routines generate the internal representation of the DIE's for
15096 the compilation unit. Debugging information is collected by walking
15097 the declaration trees passed in from dwarf2out_decl(). */
15100 gen_array_type_die (tree type, dw_die_ref context_die)
15102 dw_die_ref scope_die = scope_die_for (type, context_die);
15103 dw_die_ref array_die;
15105 /* GNU compilers represent multidimensional array types as sequences of one
15106 dimensional array types whose element types are themselves array types.
15107 We sometimes squish that down to a single array_type DIE with multiple
15108 subscripts in the Dwarf debugging info. The draft Dwarf specification
15109 say that we are allowed to do this kind of compression in C, because
15110 there is no difference between an array of arrays and a multidimensional
15111 array. We don't do this for Ada to remain as close as possible to the
15112 actual representation, which is especially important against the language
15113 flexibilty wrt arrays of variable size. */
15115 bool collapse_nested_arrays = !is_ada ();
15118 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
15119 DW_TAG_string_type doesn't have DW_AT_type attribute). */
15120 if (TYPE_STRING_FLAG (type)
15121 && TREE_CODE (type) == ARRAY_TYPE
15123 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
15125 HOST_WIDE_INT size;
15127 array_die = new_die (DW_TAG_string_type, scope_die, type);
15128 add_name_attribute (array_die, type_tag (type));
15129 equate_type_number_to_die (type, array_die);
15130 size = int_size_in_bytes (type);
15132 add_AT_unsigned (array_die, DW_AT_byte_size, size);
15133 else if (TYPE_DOMAIN (type) != NULL_TREE
15134 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
15135 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
15137 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
15138 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
15140 size = int_size_in_bytes (TREE_TYPE (szdecl));
15141 if (loc && size > 0)
15143 add_AT_location_description (array_die, DW_AT_string_length, loc);
15144 if (size != DWARF2_ADDR_SIZE)
15145 add_AT_unsigned (array_die, DW_AT_byte_size, size);
15151 /* ??? The SGI dwarf reader fails for array of array of enum types
15152 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
15153 array type comes before the outer array type. We thus call gen_type_die
15154 before we new_die and must prevent nested array types collapsing for this
15157 #ifdef MIPS_DEBUGGING_INFO
15158 gen_type_die (TREE_TYPE (type), context_die);
15159 collapse_nested_arrays = false;
15162 array_die = new_die (DW_TAG_array_type, scope_die, type);
15163 add_name_attribute (array_die, type_tag (type));
15164 equate_type_number_to_die (type, array_die);
15166 if (TREE_CODE (type) == VECTOR_TYPE)
15168 /* The frontend feeds us a representation for the vector as a struct
15169 containing an array. Pull out the array type. */
15170 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
15171 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
15174 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
15176 && TREE_CODE (type) == ARRAY_TYPE
15177 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
15178 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
15179 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
15182 /* We default the array ordering. SDB will probably do
15183 the right things even if DW_AT_ordering is not present. It's not even
15184 an issue until we start to get into multidimensional arrays anyway. If
15185 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
15186 then we'll have to put the DW_AT_ordering attribute back in. (But if
15187 and when we find out that we need to put these in, we will only do so
15188 for multidimensional arrays. */
15189 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
15192 #ifdef MIPS_DEBUGGING_INFO
15193 /* The SGI compilers handle arrays of unknown bound by setting
15194 AT_declaration and not emitting any subrange DIEs. */
15195 if (! TYPE_DOMAIN (type))
15196 add_AT_flag (array_die, DW_AT_declaration, 1);
15199 add_subscript_info (array_die, type, collapse_nested_arrays);
15201 /* Add representation of the type of the elements of this array type and
15202 emit the corresponding DIE if we haven't done it already. */
15203 element_type = TREE_TYPE (type);
15204 if (collapse_nested_arrays)
15205 while (TREE_CODE (element_type) == ARRAY_TYPE)
15207 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
15209 element_type = TREE_TYPE (element_type);
15212 #ifndef MIPS_DEBUGGING_INFO
15213 gen_type_die (element_type, context_die);
15216 add_type_attribute (array_die, element_type, 0, 0, context_die);
15218 if (get_AT (array_die, DW_AT_name))
15219 add_pubtype (type, array_die);
15222 static dw_loc_descr_ref
15223 descr_info_loc (tree val, tree base_decl)
15225 HOST_WIDE_INT size;
15226 dw_loc_descr_ref loc, loc2;
15227 enum dwarf_location_atom op;
15229 if (val == base_decl)
15230 return new_loc_descr (DW_OP_push_object_address, 0, 0);
15232 switch (TREE_CODE (val))
15235 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15237 return loc_descriptor_from_tree (val, 0);
15239 if (host_integerp (val, 0))
15240 return int_loc_descriptor (tree_low_cst (val, 0));
15243 size = int_size_in_bytes (TREE_TYPE (val));
15246 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15249 if (size == DWARF2_ADDR_SIZE)
15250 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
15252 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
15254 case POINTER_PLUS_EXPR:
15256 if (host_integerp (TREE_OPERAND (val, 1), 1)
15257 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
15260 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15263 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
15269 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
15272 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
15275 add_loc_descr (&loc, loc2);
15276 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
15298 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
15299 tree val, tree base_decl)
15301 dw_loc_descr_ref loc;
15303 if (host_integerp (val, 0))
15305 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
15309 loc = descr_info_loc (val, base_decl);
15313 add_AT_loc (die, attr, loc);
15316 /* This routine generates DIE for array with hidden descriptor, details
15317 are filled into *info by a langhook. */
15320 gen_descr_array_type_die (tree type, struct array_descr_info *info,
15321 dw_die_ref context_die)
15323 dw_die_ref scope_die = scope_die_for (type, context_die);
15324 dw_die_ref array_die;
15327 array_die = new_die (DW_TAG_array_type, scope_die, type);
15328 add_name_attribute (array_die, type_tag (type));
15329 equate_type_number_to_die (type, array_die);
15331 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
15333 && info->ndimensions >= 2)
15334 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
15336 if (info->data_location)
15337 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
15339 if (info->associated)
15340 add_descr_info_field (array_die, DW_AT_associated, info->associated,
15342 if (info->allocated)
15343 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
15346 for (dim = 0; dim < info->ndimensions; dim++)
15348 dw_die_ref subrange_die
15349 = new_die (DW_TAG_subrange_type, array_die, NULL);
15351 if (info->dimen[dim].lower_bound)
15353 /* If it is the default value, omit it. */
15354 if ((is_c_family () || is_java ())
15355 && integer_zerop (info->dimen[dim].lower_bound))
15357 else if (is_fortran ()
15358 && integer_onep (info->dimen[dim].lower_bound))
15361 add_descr_info_field (subrange_die, DW_AT_lower_bound,
15362 info->dimen[dim].lower_bound,
15365 if (info->dimen[dim].upper_bound)
15366 add_descr_info_field (subrange_die, DW_AT_upper_bound,
15367 info->dimen[dim].upper_bound,
15369 if (info->dimen[dim].stride)
15370 add_descr_info_field (subrange_die, DW_AT_byte_stride,
15371 info->dimen[dim].stride,
15375 gen_type_die (info->element_type, context_die);
15376 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
15378 if (get_AT (array_die, DW_AT_name))
15379 add_pubtype (type, array_die);
15384 gen_entry_point_die (tree decl, dw_die_ref context_die)
15386 tree origin = decl_ultimate_origin (decl);
15387 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
15389 if (origin != NULL)
15390 add_abstract_origin_attribute (decl_die, origin);
15393 add_name_and_src_coords_attributes (decl_die, decl);
15394 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
15395 0, 0, context_die);
15398 if (DECL_ABSTRACT (decl))
15399 equate_decl_number_to_die (decl, decl_die);
15401 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
15405 /* Walk through the list of incomplete types again, trying once more to
15406 emit full debugging info for them. */
15409 retry_incomplete_types (void)
15413 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
15414 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
15417 /* Determine what tag to use for a record type. */
15419 static enum dwarf_tag
15420 record_type_tag (tree type)
15422 if (! lang_hooks.types.classify_record)
15423 return DW_TAG_structure_type;
15425 switch (lang_hooks.types.classify_record (type))
15427 case RECORD_IS_STRUCT:
15428 return DW_TAG_structure_type;
15430 case RECORD_IS_CLASS:
15431 return DW_TAG_class_type;
15433 case RECORD_IS_INTERFACE:
15434 if (dwarf_version >= 3 || !dwarf_strict)
15435 return DW_TAG_interface_type;
15436 return DW_TAG_structure_type;
15439 gcc_unreachable ();
15443 /* Generate a DIE to represent an enumeration type. Note that these DIEs
15444 include all of the information about the enumeration values also. Each
15445 enumerated type name/value is listed as a child of the enumerated type
15449 gen_enumeration_type_die (tree type, dw_die_ref context_die)
15451 dw_die_ref type_die = lookup_type_die (type);
15453 if (type_die == NULL)
15455 type_die = new_die (DW_TAG_enumeration_type,
15456 scope_die_for (type, context_die), type);
15457 equate_type_number_to_die (type, type_die);
15458 add_name_attribute (type_die, type_tag (type));
15460 else if (! TYPE_SIZE (type))
15463 remove_AT (type_die, DW_AT_declaration);
15465 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
15466 given enum type is incomplete, do not generate the DW_AT_byte_size
15467 attribute or the DW_AT_element_list attribute. */
15468 if (TYPE_SIZE (type))
15472 TREE_ASM_WRITTEN (type) = 1;
15473 add_byte_size_attribute (type_die, type);
15474 if (TYPE_STUB_DECL (type) != NULL_TREE)
15475 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
15477 /* If the first reference to this type was as the return type of an
15478 inline function, then it may not have a parent. Fix this now. */
15479 if (type_die->die_parent == NULL)
15480 add_child_die (scope_die_for (type, context_die), type_die);
15482 for (link = TYPE_VALUES (type);
15483 link != NULL; link = TREE_CHAIN (link))
15485 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
15486 tree value = TREE_VALUE (link);
15488 add_name_attribute (enum_die,
15489 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
15491 if (TREE_CODE (value) == CONST_DECL)
15492 value = DECL_INITIAL (value);
15494 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
15495 /* DWARF2 does not provide a way of indicating whether or
15496 not enumeration constants are signed or unsigned. GDB
15497 always assumes the values are signed, so we output all
15498 values as if they were signed. That means that
15499 enumeration constants with very large unsigned values
15500 will appear to have negative values in the debugger. */
15501 add_AT_int (enum_die, DW_AT_const_value,
15502 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
15506 add_AT_flag (type_die, DW_AT_declaration, 1);
15508 if (get_AT (type_die, DW_AT_name))
15509 add_pubtype (type, type_die);
15514 /* Generate a DIE to represent either a real live formal parameter decl or to
15515 represent just the type of some formal parameter position in some function
15518 Note that this routine is a bit unusual because its argument may be a
15519 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
15520 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
15521 node. If it's the former then this function is being called to output a
15522 DIE to represent a formal parameter object (or some inlining thereof). If
15523 it's the latter, then this function is only being called to output a
15524 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
15525 argument type of some subprogram type.
15526 If EMIT_NAME_P is true, name and source coordinate attributes
15530 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
15531 dw_die_ref context_die)
15533 tree node_or_origin = node ? node : origin;
15534 dw_die_ref parm_die
15535 = new_die (DW_TAG_formal_parameter, context_die, node);
15537 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
15539 case tcc_declaration:
15541 origin = decl_ultimate_origin (node);
15542 if (origin != NULL)
15543 add_abstract_origin_attribute (parm_die, origin);
15546 tree type = TREE_TYPE (node);
15548 add_name_and_src_coords_attributes (parm_die, node);
15549 if (decl_by_reference_p (node))
15550 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
15553 add_type_attribute (parm_die, type,
15554 TREE_READONLY (node),
15555 TREE_THIS_VOLATILE (node),
15557 if (DECL_ARTIFICIAL (node))
15558 add_AT_flag (parm_die, DW_AT_artificial, 1);
15561 if (node && node != origin)
15562 equate_decl_number_to_die (node, parm_die);
15563 if (! DECL_ABSTRACT (node_or_origin))
15564 add_location_or_const_value_attribute (parm_die, node_or_origin,
15570 /* We were called with some kind of a ..._TYPE node. */
15571 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
15575 gcc_unreachable ();
15581 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
15582 children DW_TAG_formal_parameter DIEs representing the arguments of the
15585 PARM_PACK must be a function parameter pack.
15586 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
15587 must point to the subsequent arguments of the function PACK_ARG belongs to.
15588 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
15589 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
15590 following the last one for which a DIE was generated. */
15593 gen_formal_parameter_pack_die (tree parm_pack,
15595 dw_die_ref subr_die,
15599 dw_die_ref parm_pack_die;
15601 gcc_assert (parm_pack
15602 && lang_hooks.function_parameter_pack_p (parm_pack)
15603 && DECL_NAME (parm_pack)
15606 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
15607 add_AT_string (parm_pack_die, DW_AT_name,
15608 IDENTIFIER_POINTER (DECL_NAME (parm_pack)));
15610 for (arg = pack_arg; arg; arg = TREE_CHAIN (arg))
15612 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
15615 gen_formal_parameter_die (arg, NULL,
15616 false /* Don't emit name attribute. */,
15621 return parm_pack_die;
15624 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
15625 at the end of an (ANSI prototyped) formal parameters list. */
15628 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
15630 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
15633 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
15634 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
15635 parameters as specified in some function type specification (except for
15636 those which appear as part of a function *definition*). */
15639 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
15642 tree formal_type = NULL;
15643 tree first_parm_type;
15646 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
15648 arg = DECL_ARGUMENTS (function_or_method_type);
15649 function_or_method_type = TREE_TYPE (function_or_method_type);
15654 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
15656 /* Make our first pass over the list of formal parameter types and output a
15657 DW_TAG_formal_parameter DIE for each one. */
15658 for (link = first_parm_type; link; )
15660 dw_die_ref parm_die;
15662 formal_type = TREE_VALUE (link);
15663 if (formal_type == void_type_node)
15666 /* Output a (nameless) DIE to represent the formal parameter itself. */
15667 parm_die = gen_formal_parameter_die (formal_type, NULL,
15668 true /* Emit name attribute. */,
15670 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
15671 && link == first_parm_type)
15672 || (arg && DECL_ARTIFICIAL (arg)))
15673 add_AT_flag (parm_die, DW_AT_artificial, 1);
15675 link = TREE_CHAIN (link);
15677 arg = TREE_CHAIN (arg);
15680 /* If this function type has an ellipsis, add a
15681 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
15682 if (formal_type != void_type_node)
15683 gen_unspecified_parameters_die (function_or_method_type, context_die);
15685 /* Make our second (and final) pass over the list of formal parameter types
15686 and output DIEs to represent those types (as necessary). */
15687 for (link = TYPE_ARG_TYPES (function_or_method_type);
15688 link && TREE_VALUE (link);
15689 link = TREE_CHAIN (link))
15690 gen_type_die (TREE_VALUE (link), context_die);
15693 /* We want to generate the DIE for TYPE so that we can generate the
15694 die for MEMBER, which has been defined; we will need to refer back
15695 to the member declaration nested within TYPE. If we're trying to
15696 generate minimal debug info for TYPE, processing TYPE won't do the
15697 trick; we need to attach the member declaration by hand. */
15700 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
15702 gen_type_die (type, context_die);
15704 /* If we're trying to avoid duplicate debug info, we may not have
15705 emitted the member decl for this function. Emit it now. */
15706 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
15707 && ! lookup_decl_die (member))
15709 dw_die_ref type_die;
15710 gcc_assert (!decl_ultimate_origin (member));
15712 push_decl_scope (type);
15713 type_die = lookup_type_die (type);
15714 if (TREE_CODE (member) == FUNCTION_DECL)
15715 gen_subprogram_die (member, type_die);
15716 else if (TREE_CODE (member) == FIELD_DECL)
15718 /* Ignore the nameless fields that are used to skip bits but handle
15719 C++ anonymous unions and structs. */
15720 if (DECL_NAME (member) != NULL_TREE
15721 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
15722 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
15724 gen_type_die (member_declared_type (member), type_die);
15725 gen_field_die (member, type_die);
15729 gen_variable_die (member, NULL_TREE, type_die);
15735 /* Generate the DWARF2 info for the "abstract" instance of a function which we
15736 may later generate inlined and/or out-of-line instances of. */
15739 dwarf2out_abstract_function (tree decl)
15741 dw_die_ref old_die;
15744 int was_abstract = DECL_ABSTRACT (decl);
15745 htab_t old_decl_loc_table;
15747 /* Make sure we have the actual abstract inline, not a clone. */
15748 decl = DECL_ORIGIN (decl);
15750 old_die = lookup_decl_die (decl);
15751 if (old_die && get_AT (old_die, DW_AT_inline))
15752 /* We've already generated the abstract instance. */
15755 /* We can be called while recursively when seeing block defining inlined subroutine
15756 DIE. Be sure to not clobber the outer location table nor use it or we would
15757 get locations in abstract instantces. */
15758 old_decl_loc_table = decl_loc_table;
15759 decl_loc_table = NULL;
15761 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
15762 we don't get confused by DECL_ABSTRACT. */
15763 if (debug_info_level > DINFO_LEVEL_TERSE)
15765 context = decl_class_context (decl);
15767 gen_type_die_for_member
15768 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
15771 /* Pretend we've just finished compiling this function. */
15772 save_fn = current_function_decl;
15773 current_function_decl = decl;
15774 push_cfun (DECL_STRUCT_FUNCTION (decl));
15776 set_decl_abstract_flags (decl, 1);
15777 dwarf2out_decl (decl);
15778 if (! was_abstract)
15779 set_decl_abstract_flags (decl, 0);
15781 current_function_decl = save_fn;
15782 decl_loc_table = old_decl_loc_table;
15786 /* Helper function of premark_used_types() which gets called through
15789 Marks the DIE of a given type in *SLOT as perennial, so it never gets
15790 marked as unused by prune_unused_types. */
15793 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
15798 type = (tree) *slot;
15799 die = lookup_type_die (type);
15801 die->die_perennial_p = 1;
15805 /* Helper function of premark_types_used_by_global_vars which gets called
15806 through htab_traverse.
15808 Marks the DIE of a given type in *SLOT as perennial, so it never gets
15809 marked as unused by prune_unused_types. The DIE of the type is marked
15810 only if the global variable using the type will actually be emitted. */
15813 premark_types_used_by_global_vars_helper (void **slot,
15814 void *data ATTRIBUTE_UNUSED)
15816 struct types_used_by_vars_entry *entry;
15819 entry = (struct types_used_by_vars_entry *) *slot;
15820 gcc_assert (entry->type != NULL
15821 && entry->var_decl != NULL);
15822 die = lookup_type_die (entry->type);
15825 /* Ask cgraph if the global variable really is to be emitted.
15826 If yes, then we'll keep the DIE of ENTRY->TYPE. */
15827 struct varpool_node *node = varpool_node (entry->var_decl);
15830 die->die_perennial_p = 1;
15831 /* Keep the parent DIEs as well. */
15832 while ((die = die->die_parent) && die->die_perennial_p == 0)
15833 die->die_perennial_p = 1;
15839 /* Mark all members of used_types_hash as perennial. */
15842 premark_used_types (void)
15844 if (cfun && cfun->used_types_hash)
15845 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
15848 /* Mark all members of types_used_by_vars_entry as perennial. */
15851 premark_types_used_by_global_vars (void)
15853 if (types_used_by_vars_hash)
15854 htab_traverse (types_used_by_vars_hash,
15855 premark_types_used_by_global_vars_helper, NULL);
15858 /* Generate a DIE to represent a declared function (either file-scope or
15862 gen_subprogram_die (tree decl, dw_die_ref context_die)
15864 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15865 tree origin = decl_ultimate_origin (decl);
15866 dw_die_ref subr_die;
15869 dw_die_ref old_die = lookup_decl_die (decl);
15870 int declaration = (current_function_decl != decl
15871 || class_or_namespace_scope_p (context_die));
15873 premark_used_types ();
15875 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
15876 started to generate the abstract instance of an inline, decided to output
15877 its containing class, and proceeded to emit the declaration of the inline
15878 from the member list for the class. If so, DECLARATION takes priority;
15879 we'll get back to the abstract instance when done with the class. */
15881 /* The class-scope declaration DIE must be the primary DIE. */
15882 if (origin && declaration && class_or_namespace_scope_p (context_die))
15885 gcc_assert (!old_die);
15888 /* Now that the C++ front end lazily declares artificial member fns, we
15889 might need to retrofit the declaration into its class. */
15890 if (!declaration && !origin && !old_die
15891 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
15892 && !class_or_namespace_scope_p (context_die)
15893 && debug_info_level > DINFO_LEVEL_TERSE)
15894 old_die = force_decl_die (decl);
15896 if (origin != NULL)
15898 gcc_assert (!declaration || local_scope_p (context_die));
15900 /* Fixup die_parent for the abstract instance of a nested
15901 inline function. */
15902 if (old_die && old_die->die_parent == NULL)
15903 add_child_die (context_die, old_die);
15905 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15906 add_abstract_origin_attribute (subr_die, origin);
15910 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
15911 struct dwarf_file_data * file_index = lookup_filename (s.file);
15913 if (!get_AT_flag (old_die, DW_AT_declaration)
15914 /* We can have a normal definition following an inline one in the
15915 case of redefinition of GNU C extern inlines.
15916 It seems reasonable to use AT_specification in this case. */
15917 && !get_AT (old_die, DW_AT_inline))
15919 /* Detect and ignore this case, where we are trying to output
15920 something we have already output. */
15924 /* If the definition comes from the same place as the declaration,
15925 maybe use the old DIE. We always want the DIE for this function
15926 that has the *_pc attributes to be under comp_unit_die so the
15927 debugger can find it. We also need to do this for abstract
15928 instances of inlines, since the spec requires the out-of-line copy
15929 to have the same parent. For local class methods, this doesn't
15930 apply; we just use the old DIE. */
15931 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
15932 && (DECL_ARTIFICIAL (decl)
15933 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
15934 && (get_AT_unsigned (old_die, DW_AT_decl_line)
15935 == (unsigned) s.line))))
15937 subr_die = old_die;
15939 /* Clear out the declaration attribute and the formal parameters.
15940 Do not remove all children, because it is possible that this
15941 declaration die was forced using force_decl_die(). In such
15942 cases die that forced declaration die (e.g. TAG_imported_module)
15943 is one of the children that we do not want to remove. */
15944 remove_AT (subr_die, DW_AT_declaration);
15945 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
15949 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15950 add_AT_specification (subr_die, old_die);
15951 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
15952 add_AT_file (subr_die, DW_AT_decl_file, file_index);
15953 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
15954 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
15959 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15961 if (TREE_PUBLIC (decl))
15962 add_AT_flag (subr_die, DW_AT_external, 1);
15964 add_name_and_src_coords_attributes (subr_die, decl);
15965 if (debug_info_level > DINFO_LEVEL_TERSE)
15967 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
15968 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
15969 0, 0, context_die);
15972 add_pure_or_virtual_attribute (subr_die, decl);
15973 if (DECL_ARTIFICIAL (decl))
15974 add_AT_flag (subr_die, DW_AT_artificial, 1);
15976 if (TREE_PROTECTED (decl))
15977 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
15978 else if (TREE_PRIVATE (decl))
15979 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
15984 if (!old_die || !get_AT (old_die, DW_AT_inline))
15986 add_AT_flag (subr_die, DW_AT_declaration, 1);
15988 /* If this is an explicit function declaration then generate
15989 a DW_AT_explicit attribute. */
15990 if (lang_hooks.decls.function_decl_explicit_p (decl)
15991 && (dwarf_version >= 3 || !dwarf_strict))
15992 add_AT_flag (subr_die, DW_AT_explicit, 1);
15994 /* The first time we see a member function, it is in the context of
15995 the class to which it belongs. We make sure of this by emitting
15996 the class first. The next time is the definition, which is
15997 handled above. The two may come from the same source text.
15999 Note that force_decl_die() forces function declaration die. It is
16000 later reused to represent definition. */
16001 equate_decl_number_to_die (decl, subr_die);
16004 else if (DECL_ABSTRACT (decl))
16006 if (DECL_DECLARED_INLINE_P (decl))
16008 if (cgraph_function_possibly_inlined_p (decl))
16009 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
16011 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
16015 if (cgraph_function_possibly_inlined_p (decl))
16016 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
16018 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
16021 if (DECL_DECLARED_INLINE_P (decl)
16022 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
16023 add_AT_flag (subr_die, DW_AT_artificial, 1);
16025 equate_decl_number_to_die (decl, subr_die);
16027 else if (!DECL_EXTERNAL (decl))
16029 HOST_WIDE_INT cfa_fb_offset;
16031 if (!old_die || !get_AT (old_die, DW_AT_inline))
16032 equate_decl_number_to_die (decl, subr_die);
16034 if (!flag_reorder_blocks_and_partition)
16036 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
16037 current_function_funcdef_no);
16038 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
16039 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
16040 current_function_funcdef_no);
16041 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
16043 add_pubname (decl, subr_die);
16044 add_arange (decl, subr_die);
16047 { /* Do nothing for now; maybe need to duplicate die, one for
16048 hot section and one for cold section, then use the hot/cold
16049 section begin/end labels to generate the aranges... */
16051 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
16052 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
16053 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
16054 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
16056 add_pubname (decl, subr_die);
16057 add_arange (decl, subr_die);
16058 add_arange (decl, subr_die);
16062 #ifdef MIPS_DEBUGGING_INFO
16063 /* Add a reference to the FDE for this routine. */
16064 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
16067 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
16069 /* We define the "frame base" as the function's CFA. This is more
16070 convenient for several reasons: (1) It's stable across the prologue
16071 and epilogue, which makes it better than just a frame pointer,
16072 (2) With dwarf3, there exists a one-byte encoding that allows us
16073 to reference the .debug_frame data by proxy, but failing that,
16074 (3) We can at least reuse the code inspection and interpretation
16075 code that determines the CFA position at various points in the
16077 if (dwarf_version >= 3)
16079 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
16080 add_AT_loc (subr_die, DW_AT_frame_base, op);
16084 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
16085 if (list->dw_loc_next)
16086 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
16088 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
16091 /* Compute a displacement from the "steady-state frame pointer" to
16092 the CFA. The former is what all stack slots and argument slots
16093 will reference in the rtl; the later is what we've told the
16094 debugger about. We'll need to adjust all frame_base references
16095 by this displacement. */
16096 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
16098 if (cfun->static_chain_decl)
16099 add_AT_location_description (subr_die, DW_AT_static_link,
16100 loc_list_from_tree (cfun->static_chain_decl, 2));
16103 /* Generate child dies for template paramaters. */
16104 if (debug_info_level > DINFO_LEVEL_TERSE)
16105 gen_generic_params_dies (decl);
16107 /* Now output descriptions of the arguments for this function. This gets
16108 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
16109 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
16110 `...' at the end of the formal parameter list. In order to find out if
16111 there was a trailing ellipsis or not, we must instead look at the type
16112 associated with the FUNCTION_DECL. This will be a node of type
16113 FUNCTION_TYPE. If the chain of type nodes hanging off of this
16114 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
16115 an ellipsis at the end. */
16117 /* In the case where we are describing a mere function declaration, all we
16118 need to do here (and all we *can* do here) is to describe the *types* of
16119 its formal parameters. */
16120 if (debug_info_level <= DINFO_LEVEL_TERSE)
16122 else if (declaration)
16123 gen_formal_types_die (decl, subr_die);
16126 /* Generate DIEs to represent all known formal parameters. */
16127 tree parm = DECL_ARGUMENTS (decl);
16128 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
16129 tree generic_decl_parm = generic_decl
16130 ? DECL_ARGUMENTS (generic_decl)
16133 /* Now we want to walk the list of parameters of the function and
16134 emit their relevant DIEs.
16136 We consider the case of DECL being an instance of a generic function
16137 as well as it being a normal function.
16139 If DECL is an instance of a generic function we walk the
16140 parameters of the generic function declaration _and_ the parameters of
16141 DECL itself. This is useful because we want to emit specific DIEs for
16142 function parameter packs and those are declared as part of the
16143 generic function declaration. In that particular case,
16144 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
16145 That DIE has children DIEs representing the set of arguments
16146 of the pack. Note that the set of pack arguments can be empty.
16147 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
16150 Otherwise, we just consider the parameters of DECL. */
16151 while (generic_decl_parm || parm)
16153 if (generic_decl_parm
16154 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
16155 gen_formal_parameter_pack_die (generic_decl_parm,
16160 gen_decl_die (parm, NULL, subr_die);
16161 parm = TREE_CHAIN (parm);
16164 if (generic_decl_parm)
16165 generic_decl_parm = TREE_CHAIN (generic_decl_parm);
16168 /* Decide whether we need an unspecified_parameters DIE at the end.
16169 There are 2 more cases to do this for: 1) the ansi ... declaration -
16170 this is detectable when the end of the arg list is not a
16171 void_type_node 2) an unprototyped function declaration (not a
16172 definition). This just means that we have no info about the
16173 parameters at all. */
16174 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
16175 if (fn_arg_types != NULL)
16177 /* This is the prototyped case, check for.... */
16178 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
16179 gen_unspecified_parameters_die (decl, subr_die);
16181 else if (DECL_INITIAL (decl) == NULL_TREE)
16182 gen_unspecified_parameters_die (decl, subr_die);
16185 /* Output Dwarf info for all of the stuff within the body of the function
16186 (if it has one - it may be just a declaration). */
16187 outer_scope = DECL_INITIAL (decl);
16189 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
16190 a function. This BLOCK actually represents the outermost binding contour
16191 for the function, i.e. the contour in which the function's formal
16192 parameters and labels get declared. Curiously, it appears that the front
16193 end doesn't actually put the PARM_DECL nodes for the current function onto
16194 the BLOCK_VARS list for this outer scope, but are strung off of the
16195 DECL_ARGUMENTS list for the function instead.
16197 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
16198 the LABEL_DECL nodes for the function however, and we output DWARF info
16199 for those in decls_for_scope. Just within the `outer_scope' there will be
16200 a BLOCK node representing the function's outermost pair of curly braces,
16201 and any blocks used for the base and member initializers of a C++
16202 constructor function. */
16203 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
16205 /* Emit a DW_TAG_variable DIE for a named return value. */
16206 if (DECL_NAME (DECL_RESULT (decl)))
16207 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
16209 current_function_has_inlines = 0;
16210 decls_for_scope (outer_scope, subr_die, 0);
16212 #if 0 && defined (MIPS_DEBUGGING_INFO)
16213 if (current_function_has_inlines)
16215 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
16216 if (! comp_unit_has_inlines)
16218 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
16219 comp_unit_has_inlines = 1;
16224 /* Add the calling convention attribute if requested. */
16225 add_calling_convention_attribute (subr_die, decl);
16229 /* Returns a hash value for X (which really is a die_struct). */
16232 common_block_die_table_hash (const void *x)
16234 const_dw_die_ref d = (const_dw_die_ref) x;
16235 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
16238 /* Return nonzero if decl_id and die_parent of die_struct X is the same
16239 as decl_id and die_parent of die_struct Y. */
16242 common_block_die_table_eq (const void *x, const void *y)
16244 const_dw_die_ref d = (const_dw_die_ref) x;
16245 const_dw_die_ref e = (const_dw_die_ref) y;
16246 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
16249 /* Generate a DIE to represent a declared data object.
16250 Either DECL or ORIGIN must be non-null. */
16253 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
16257 tree decl_or_origin = decl ? decl : origin;
16258 dw_die_ref var_die;
16259 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
16260 dw_die_ref origin_die;
16261 int declaration = (DECL_EXTERNAL (decl_or_origin)
16262 /* If DECL is COMDAT and has not actually been
16263 emitted, we cannot take its address; there
16264 might end up being no definition anywhere in
16265 the program. For example, consider the C++
16269 struct S { static const int i = 7; };
16274 int f() { return S<int>::i; }
16276 Here, S<int>::i is not DECL_EXTERNAL, but no
16277 definition is required, so the compiler will
16278 not emit a definition. */
16279 || (TREE_CODE (decl_or_origin) == VAR_DECL
16280 && DECL_COMDAT (decl_or_origin)
16281 && !TREE_ASM_WRITTEN (decl_or_origin))
16282 || class_or_namespace_scope_p (context_die));
16285 origin = decl_ultimate_origin (decl);
16287 com_decl = fortran_common (decl_or_origin, &off);
16289 /* Symbol in common gets emitted as a child of the common block, in the form
16290 of a data member. */
16294 dw_die_ref com_die;
16295 dw_loc_list_ref loc;
16296 die_node com_die_arg;
16298 var_die = lookup_decl_die (decl_or_origin);
16301 if (get_AT (var_die, DW_AT_location) == NULL)
16303 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
16308 /* Optimize the common case. */
16309 if (single_element_loc_list_p (loc)
16310 && loc->expr->dw_loc_opc == DW_OP_addr
16311 && loc->expr->dw_loc_next == NULL
16312 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
16314 loc->expr->dw_loc_oprnd1.v.val_addr
16315 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
16317 loc_list_plus_const (loc, off);
16319 add_AT_location_description (var_die, DW_AT_location, loc);
16320 remove_AT (var_die, DW_AT_declaration);
16326 if (common_block_die_table == NULL)
16327 common_block_die_table
16328 = htab_create_ggc (10, common_block_die_table_hash,
16329 common_block_die_table_eq, NULL);
16331 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
16332 com_die_arg.decl_id = DECL_UID (com_decl);
16333 com_die_arg.die_parent = context_die;
16334 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
16335 loc = loc_list_from_tree (com_decl, 2);
16336 if (com_die == NULL)
16339 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
16342 com_die = new_die (DW_TAG_common_block, context_die, decl);
16343 add_name_and_src_coords_attributes (com_die, com_decl);
16346 add_AT_location_description (com_die, DW_AT_location, loc);
16347 /* Avoid sharing the same loc descriptor between
16348 DW_TAG_common_block and DW_TAG_variable. */
16349 loc = loc_list_from_tree (com_decl, 2);
16351 else if (DECL_EXTERNAL (decl))
16352 add_AT_flag (com_die, DW_AT_declaration, 1);
16353 add_pubname_string (cnam, com_die); /* ??? needed? */
16354 com_die->decl_id = DECL_UID (com_decl);
16355 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
16356 *slot = (void *) com_die;
16358 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
16360 add_AT_location_description (com_die, DW_AT_location, loc);
16361 loc = loc_list_from_tree (com_decl, 2);
16362 remove_AT (com_die, DW_AT_declaration);
16364 var_die = new_die (DW_TAG_variable, com_die, decl);
16365 add_name_and_src_coords_attributes (var_die, decl);
16366 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
16367 TREE_THIS_VOLATILE (decl), context_die);
16368 add_AT_flag (var_die, DW_AT_external, 1);
16373 /* Optimize the common case. */
16374 if (single_element_loc_list_p (loc)
16375 && loc->expr->dw_loc_opc == DW_OP_addr
16376 && loc->expr->dw_loc_next == NULL
16377 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
16378 loc->expr->dw_loc_oprnd1.v.val_addr
16379 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
16381 loc_list_plus_const (loc, off);
16383 add_AT_location_description (var_die, DW_AT_location, loc);
16385 else if (DECL_EXTERNAL (decl))
16386 add_AT_flag (var_die, DW_AT_declaration, 1);
16387 equate_decl_number_to_die (decl, var_die);
16391 /* If the compiler emitted a definition for the DECL declaration
16392 and if we already emitted a DIE for it, don't emit a second
16393 DIE for it again. */
16396 && old_die->die_parent == context_die)
16399 /* For static data members, the declaration in the class is supposed
16400 to have DW_TAG_member tag; the specification should still be
16401 DW_TAG_variable referencing the DW_TAG_member DIE. */
16402 if (declaration && class_scope_p (context_die))
16403 var_die = new_die (DW_TAG_member, context_die, decl);
16405 var_die = new_die (DW_TAG_variable, context_die, decl);
16408 if (origin != NULL)
16409 origin_die = add_abstract_origin_attribute (var_die, origin);
16411 /* Loop unrolling can create multiple blocks that refer to the same
16412 static variable, so we must test for the DW_AT_declaration flag.
16414 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
16415 copy decls and set the DECL_ABSTRACT flag on them instead of
16418 ??? Duplicated blocks have been rewritten to use .debug_ranges.
16420 ??? The declare_in_namespace support causes us to get two DIEs for one
16421 variable, both of which are declarations. We want to avoid considering
16422 one to be a specification, so we must test that this DIE is not a
16424 else if (old_die && TREE_STATIC (decl) && ! declaration
16425 && get_AT_flag (old_die, DW_AT_declaration) == 1)
16427 /* This is a definition of a C++ class level static. */
16428 add_AT_specification (var_die, old_die);
16429 if (DECL_NAME (decl))
16431 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
16432 struct dwarf_file_data * file_index = lookup_filename (s.file);
16434 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
16435 add_AT_file (var_die, DW_AT_decl_file, file_index);
16437 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
16438 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
16443 tree type = TREE_TYPE (decl);
16445 add_name_and_src_coords_attributes (var_die, decl);
16446 if (decl_by_reference_p (decl))
16447 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
16449 add_type_attribute (var_die, type, TREE_READONLY (decl),
16450 TREE_THIS_VOLATILE (decl), context_die);
16452 if (TREE_PUBLIC (decl))
16453 add_AT_flag (var_die, DW_AT_external, 1);
16455 if (DECL_ARTIFICIAL (decl))
16456 add_AT_flag (var_die, DW_AT_artificial, 1);
16458 if (TREE_PROTECTED (decl))
16459 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
16460 else if (TREE_PRIVATE (decl))
16461 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
16465 add_AT_flag (var_die, DW_AT_declaration, 1);
16467 if (decl && (DECL_ABSTRACT (decl) || declaration))
16468 equate_decl_number_to_die (decl, var_die);
16471 && (! DECL_ABSTRACT (decl_or_origin)
16472 /* Local static vars are shared between all clones/inlines,
16473 so emit DW_AT_location on the abstract DIE if DECL_RTL is
16475 || (TREE_CODE (decl_or_origin) == VAR_DECL
16476 && TREE_STATIC (decl_or_origin)
16477 && DECL_RTL_SET_P (decl_or_origin)))
16478 /* When abstract origin already has DW_AT_location attribute, no need
16479 to add it again. */
16480 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
16482 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
16483 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
16484 defer_location (decl_or_origin, var_die);
16486 add_location_or_const_value_attribute (var_die,
16489 add_pubname (decl_or_origin, var_die);
16492 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
16495 /* Generate a DIE to represent a named constant. */
16498 gen_const_die (tree decl, dw_die_ref context_die)
16500 dw_die_ref const_die;
16501 tree type = TREE_TYPE (decl);
16503 const_die = new_die (DW_TAG_constant, context_die, decl);
16504 add_name_and_src_coords_attributes (const_die, decl);
16505 add_type_attribute (const_die, type, 1, 0, context_die);
16506 if (TREE_PUBLIC (decl))
16507 add_AT_flag (const_die, DW_AT_external, 1);
16508 if (DECL_ARTIFICIAL (decl))
16509 add_AT_flag (const_die, DW_AT_artificial, 1);
16510 tree_add_const_value_attribute_for_decl (const_die, decl);
16513 /* Generate a DIE to represent a label identifier. */
16516 gen_label_die (tree decl, dw_die_ref context_die)
16518 tree origin = decl_ultimate_origin (decl);
16519 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
16521 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16523 if (origin != NULL)
16524 add_abstract_origin_attribute (lbl_die, origin);
16526 add_name_and_src_coords_attributes (lbl_die, decl);
16528 if (DECL_ABSTRACT (decl))
16529 equate_decl_number_to_die (decl, lbl_die);
16532 insn = DECL_RTL_IF_SET (decl);
16534 /* Deleted labels are programmer specified labels which have been
16535 eliminated because of various optimizations. We still emit them
16536 here so that it is possible to put breakpoints on them. */
16540 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
16542 /* When optimization is enabled (via -O) some parts of the compiler
16543 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
16544 represent source-level labels which were explicitly declared by
16545 the user. This really shouldn't be happening though, so catch
16546 it if it ever does happen. */
16547 gcc_assert (!INSN_DELETED_P (insn));
16549 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
16550 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
16555 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
16556 attributes to the DIE for a block STMT, to describe where the inlined
16557 function was called from. This is similar to add_src_coords_attributes. */
16560 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
16562 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
16564 if (dwarf_version >= 3 || !dwarf_strict)
16566 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
16567 add_AT_unsigned (die, DW_AT_call_line, s.line);
16572 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
16573 Add low_pc and high_pc attributes to the DIE for a block STMT. */
16576 add_high_low_attributes (tree stmt, dw_die_ref die)
16578 char label[MAX_ARTIFICIAL_LABEL_BYTES];
16580 if (BLOCK_FRAGMENT_CHAIN (stmt)
16581 && (dwarf_version >= 3 || !dwarf_strict))
16585 if (inlined_function_outer_scope_p (stmt))
16587 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
16588 BLOCK_NUMBER (stmt));
16589 add_AT_lbl_id (die, DW_AT_entry_pc, label);
16592 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
16594 chain = BLOCK_FRAGMENT_CHAIN (stmt);
16597 add_ranges (chain);
16598 chain = BLOCK_FRAGMENT_CHAIN (chain);
16605 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
16606 BLOCK_NUMBER (stmt));
16607 add_AT_lbl_id (die, DW_AT_low_pc, label);
16608 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
16609 BLOCK_NUMBER (stmt));
16610 add_AT_lbl_id (die, DW_AT_high_pc, label);
16614 /* Generate a DIE for a lexical block. */
16617 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
16619 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
16621 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
16622 add_high_low_attributes (stmt, stmt_die);
16624 decls_for_scope (stmt, stmt_die, depth);
16627 /* Generate a DIE for an inlined subprogram. */
16630 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
16634 /* The instance of function that is effectively being inlined shall not
16636 gcc_assert (! BLOCK_ABSTRACT (stmt));
16638 decl = block_ultimate_origin (stmt);
16640 /* Emit info for the abstract instance first, if we haven't yet. We
16641 must emit this even if the block is abstract, otherwise when we
16642 emit the block below (or elsewhere), we may end up trying to emit
16643 a die whose origin die hasn't been emitted, and crashing. */
16644 dwarf2out_abstract_function (decl);
16646 if (! BLOCK_ABSTRACT (stmt))
16648 dw_die_ref subr_die
16649 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
16651 add_abstract_origin_attribute (subr_die, decl);
16652 if (TREE_ASM_WRITTEN (stmt))
16653 add_high_low_attributes (stmt, subr_die);
16654 add_call_src_coords_attributes (stmt, subr_die);
16656 decls_for_scope (stmt, subr_die, depth);
16657 current_function_has_inlines = 1;
16661 /* Generate a DIE for a field in a record, or structure. */
16664 gen_field_die (tree decl, dw_die_ref context_die)
16666 dw_die_ref decl_die;
16668 if (TREE_TYPE (decl) == error_mark_node)
16671 decl_die = new_die (DW_TAG_member, context_die, decl);
16672 add_name_and_src_coords_attributes (decl_die, decl);
16673 add_type_attribute (decl_die, member_declared_type (decl),
16674 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
16677 if (DECL_BIT_FIELD_TYPE (decl))
16679 add_byte_size_attribute (decl_die, decl);
16680 add_bit_size_attribute (decl_die, decl);
16681 add_bit_offset_attribute (decl_die, decl);
16684 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
16685 add_data_member_location_attribute (decl_die, decl);
16687 if (DECL_ARTIFICIAL (decl))
16688 add_AT_flag (decl_die, DW_AT_artificial, 1);
16690 if (TREE_PROTECTED (decl))
16691 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
16692 else if (TREE_PRIVATE (decl))
16693 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
16695 /* Equate decl number to die, so that we can look up this decl later on. */
16696 equate_decl_number_to_die (decl, decl_die);
16700 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16701 Use modified_type_die instead.
16702 We keep this code here just in case these types of DIEs may be needed to
16703 represent certain things in other languages (e.g. Pascal) someday. */
16706 gen_pointer_type_die (tree type, dw_die_ref context_die)
16709 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
16711 equate_type_number_to_die (type, ptr_die);
16712 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16713 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16716 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16717 Use modified_type_die instead.
16718 We keep this code here just in case these types of DIEs may be needed to
16719 represent certain things in other languages (e.g. Pascal) someday. */
16722 gen_reference_type_die (tree type, dw_die_ref context_die)
16725 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
16727 equate_type_number_to_die (type, ref_die);
16728 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
16729 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16733 /* Generate a DIE for a pointer to a member type. */
16736 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
16739 = new_die (DW_TAG_ptr_to_member_type,
16740 scope_die_for (type, context_die), type);
16742 equate_type_number_to_die (type, ptr_die);
16743 add_AT_die_ref (ptr_die, DW_AT_containing_type,
16744 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
16745 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16748 /* Generate the DIE for the compilation unit. */
16751 gen_compile_unit_die (const char *filename)
16754 char producer[250];
16755 const char *language_string = lang_hooks.name;
16758 die = new_die (DW_TAG_compile_unit, NULL, NULL);
16762 add_name_attribute (die, filename);
16763 /* Don't add cwd for <built-in>. */
16764 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
16765 add_comp_dir_attribute (die);
16768 sprintf (producer, "%s %s", language_string, version_string);
16770 #ifdef MIPS_DEBUGGING_INFO
16771 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
16772 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
16773 not appear in the producer string, the debugger reaches the conclusion
16774 that the object file is stripped and has no debugging information.
16775 To get the MIPS/SGI debugger to believe that there is debugging
16776 information in the object file, we add a -g to the producer string. */
16777 if (debug_info_level > DINFO_LEVEL_TERSE)
16778 strcat (producer, " -g");
16781 add_AT_string (die, DW_AT_producer, producer);
16783 language = DW_LANG_C89;
16784 if (strcmp (language_string, "GNU C++") == 0)
16785 language = DW_LANG_C_plus_plus;
16786 else if (strcmp (language_string, "GNU F77") == 0)
16787 language = DW_LANG_Fortran77;
16788 else if (strcmp (language_string, "GNU Pascal") == 0)
16789 language = DW_LANG_Pascal83;
16790 else if (dwarf_version >= 3 || !dwarf_strict)
16792 if (strcmp (language_string, "GNU Ada") == 0)
16793 language = DW_LANG_Ada95;
16794 else if (strcmp (language_string, "GNU Fortran") == 0)
16795 language = DW_LANG_Fortran95;
16796 else if (strcmp (language_string, "GNU Java") == 0)
16797 language = DW_LANG_Java;
16798 else if (strcmp (language_string, "GNU Objective-C") == 0)
16799 language = DW_LANG_ObjC;
16800 else if (strcmp (language_string, "GNU Objective-C++") == 0)
16801 language = DW_LANG_ObjC_plus_plus;
16804 add_AT_unsigned (die, DW_AT_language, language);
16808 /* Generate the DIE for a base class. */
16811 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
16813 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
16815 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
16816 add_data_member_location_attribute (die, binfo);
16818 if (BINFO_VIRTUAL_P (binfo))
16819 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
16821 if (access == access_public_node)
16822 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16823 else if (access == access_protected_node)
16824 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16827 /* Generate a DIE for a class member. */
16830 gen_member_die (tree type, dw_die_ref context_die)
16833 tree binfo = TYPE_BINFO (type);
16836 /* If this is not an incomplete type, output descriptions of each of its
16837 members. Note that as we output the DIEs necessary to represent the
16838 members of this record or union type, we will also be trying to output
16839 DIEs to represent the *types* of those members. However the `type'
16840 function (above) will specifically avoid generating type DIEs for member
16841 types *within* the list of member DIEs for this (containing) type except
16842 for those types (of members) which are explicitly marked as also being
16843 members of this (containing) type themselves. The g++ front- end can
16844 force any given type to be treated as a member of some other (containing)
16845 type by setting the TYPE_CONTEXT of the given (member) type to point to
16846 the TREE node representing the appropriate (containing) type. */
16848 /* First output info about the base classes. */
16851 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
16855 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
16856 gen_inheritance_die (base,
16857 (accesses ? VEC_index (tree, accesses, i)
16858 : access_public_node), context_die);
16861 /* Now output info about the data members and type members. */
16862 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
16864 /* If we thought we were generating minimal debug info for TYPE
16865 and then changed our minds, some of the member declarations
16866 may have already been defined. Don't define them again, but
16867 do put them in the right order. */
16869 child = lookup_decl_die (member);
16871 splice_child_die (context_die, child);
16873 gen_decl_die (member, NULL, context_die);
16876 /* Now output info about the function members (if any). */
16877 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
16879 /* Don't include clones in the member list. */
16880 if (DECL_ABSTRACT_ORIGIN (member))
16883 child = lookup_decl_die (member);
16885 splice_child_die (context_die, child);
16887 gen_decl_die (member, NULL, context_die);
16891 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
16892 is set, we pretend that the type was never defined, so we only get the
16893 member DIEs needed by later specification DIEs. */
16896 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
16897 enum debug_info_usage usage)
16899 dw_die_ref type_die = lookup_type_die (type);
16900 dw_die_ref scope_die = 0;
16902 int complete = (TYPE_SIZE (type)
16903 && (! TYPE_STUB_DECL (type)
16904 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
16905 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
16906 complete = complete && should_emit_struct_debug (type, usage);
16908 if (type_die && ! complete)
16911 if (TYPE_CONTEXT (type) != NULL_TREE
16912 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
16913 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
16916 scope_die = scope_die_for (type, context_die);
16918 if (! type_die || (nested && scope_die == comp_unit_die))
16919 /* First occurrence of type or toplevel definition of nested class. */
16921 dw_die_ref old_die = type_die;
16923 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
16924 ? record_type_tag (type) : DW_TAG_union_type,
16926 equate_type_number_to_die (type, type_die);
16928 add_AT_specification (type_die, old_die);
16930 add_name_attribute (type_die, type_tag (type));
16933 remove_AT (type_die, DW_AT_declaration);
16935 /* Generate child dies for template paramaters. */
16936 if (debug_info_level > DINFO_LEVEL_TERSE
16937 && COMPLETE_TYPE_P (type))
16938 gen_generic_params_dies (type);
16940 /* If this type has been completed, then give it a byte_size attribute and
16941 then give a list of members. */
16942 if (complete && !ns_decl)
16944 /* Prevent infinite recursion in cases where the type of some member of
16945 this type is expressed in terms of this type itself. */
16946 TREE_ASM_WRITTEN (type) = 1;
16947 add_byte_size_attribute (type_die, type);
16948 if (TYPE_STUB_DECL (type) != NULL_TREE)
16949 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16951 /* If the first reference to this type was as the return type of an
16952 inline function, then it may not have a parent. Fix this now. */
16953 if (type_die->die_parent == NULL)
16954 add_child_die (scope_die, type_die);
16956 push_decl_scope (type);
16957 gen_member_die (type, type_die);
16960 /* GNU extension: Record what type our vtable lives in. */
16961 if (TYPE_VFIELD (type))
16963 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
16965 gen_type_die (vtype, context_die);
16966 add_AT_die_ref (type_die, DW_AT_containing_type,
16967 lookup_type_die (vtype));
16972 add_AT_flag (type_die, DW_AT_declaration, 1);
16974 /* We don't need to do this for function-local types. */
16975 if (TYPE_STUB_DECL (type)
16976 && ! decl_function_context (TYPE_STUB_DECL (type)))
16977 VEC_safe_push (tree, gc, incomplete_types, type);
16980 if (get_AT (type_die, DW_AT_name))
16981 add_pubtype (type, type_die);
16984 /* Generate a DIE for a subroutine _type_. */
16987 gen_subroutine_type_die (tree type, dw_die_ref context_die)
16989 tree return_type = TREE_TYPE (type);
16990 dw_die_ref subr_die
16991 = new_die (DW_TAG_subroutine_type,
16992 scope_die_for (type, context_die), type);
16994 equate_type_number_to_die (type, subr_die);
16995 add_prototyped_attribute (subr_die, type);
16996 add_type_attribute (subr_die, return_type, 0, 0, context_die);
16997 gen_formal_types_die (type, subr_die);
16999 if (get_AT (subr_die, DW_AT_name))
17000 add_pubtype (type, subr_die);
17003 /* Generate a DIE for a type definition. */
17006 gen_typedef_die (tree decl, dw_die_ref context_die)
17008 dw_die_ref type_die;
17011 if (TREE_ASM_WRITTEN (decl))
17014 TREE_ASM_WRITTEN (decl) = 1;
17015 type_die = new_die (DW_TAG_typedef, context_die, decl);
17016 origin = decl_ultimate_origin (decl);
17017 if (origin != NULL)
17018 add_abstract_origin_attribute (type_die, origin);
17023 add_name_and_src_coords_attributes (type_die, decl);
17024 if (DECL_ORIGINAL_TYPE (decl))
17026 type = DECL_ORIGINAL_TYPE (decl);
17028 gcc_assert (type != TREE_TYPE (decl));
17029 equate_type_number_to_die (TREE_TYPE (decl), type_die);
17032 type = TREE_TYPE (decl);
17034 add_type_attribute (type_die, type, TREE_READONLY (decl),
17035 TREE_THIS_VOLATILE (decl), context_die);
17038 if (DECL_ABSTRACT (decl))
17039 equate_decl_number_to_die (decl, type_die);
17041 if (get_AT (type_die, DW_AT_name))
17042 add_pubtype (decl, type_die);
17045 /* Generate a type description DIE. */
17048 gen_type_die_with_usage (tree type, dw_die_ref context_die,
17049 enum debug_info_usage usage)
17052 struct array_descr_info info;
17054 if (type == NULL_TREE || type == error_mark_node)
17057 /* If TYPE is a typedef type variant, let's generate debug info
17058 for the parent typedef which TYPE is a type of. */
17059 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
17060 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
17062 if (TREE_ASM_WRITTEN (type))
17065 /* Prevent broken recursion; we can't hand off to the same type. */
17066 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
17068 /* Use the DIE of the containing namespace as the parent DIE of
17069 the type description DIE we want to generate. */
17070 if (DECL_CONTEXT (TYPE_NAME (type))
17071 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
17072 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
17074 TREE_ASM_WRITTEN (type) = 1;
17075 gen_decl_die (TYPE_NAME (type), NULL, context_die);
17079 /* If this is an array type with hidden descriptor, handle it first. */
17080 if (!TREE_ASM_WRITTEN (type)
17081 && lang_hooks.types.get_array_descr_info
17082 && lang_hooks.types.get_array_descr_info (type, &info)
17083 && (dwarf_version >= 3 || !dwarf_strict))
17085 gen_descr_array_type_die (type, &info, context_die);
17086 TREE_ASM_WRITTEN (type) = 1;
17090 /* We are going to output a DIE to represent the unqualified version
17091 of this type (i.e. without any const or volatile qualifiers) so
17092 get the main variant (i.e. the unqualified version) of this type
17093 now. (Vectors are special because the debugging info is in the
17094 cloned type itself). */
17095 if (TREE_CODE (type) != VECTOR_TYPE)
17096 type = type_main_variant (type);
17098 if (TREE_ASM_WRITTEN (type))
17101 switch (TREE_CODE (type))
17107 case REFERENCE_TYPE:
17108 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
17109 ensures that the gen_type_die recursion will terminate even if the
17110 type is recursive. Recursive types are possible in Ada. */
17111 /* ??? We could perhaps do this for all types before the switch
17113 TREE_ASM_WRITTEN (type) = 1;
17115 /* For these types, all that is required is that we output a DIE (or a
17116 set of DIEs) to represent the "basis" type. */
17117 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17118 DINFO_USAGE_IND_USE);
17122 /* This code is used for C++ pointer-to-data-member types.
17123 Output a description of the relevant class type. */
17124 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
17125 DINFO_USAGE_IND_USE);
17127 /* Output a description of the type of the object pointed to. */
17128 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17129 DINFO_USAGE_IND_USE);
17131 /* Now output a DIE to represent this pointer-to-data-member type
17133 gen_ptr_to_mbr_type_die (type, context_die);
17136 case FUNCTION_TYPE:
17137 /* Force out return type (in case it wasn't forced out already). */
17138 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17139 DINFO_USAGE_DIR_USE);
17140 gen_subroutine_type_die (type, context_die);
17144 /* Force out return type (in case it wasn't forced out already). */
17145 gen_type_die_with_usage (TREE_TYPE (type), context_die,
17146 DINFO_USAGE_DIR_USE);
17147 gen_subroutine_type_die (type, context_die);
17151 gen_array_type_die (type, context_die);
17155 gen_array_type_die (type, context_die);
17158 case ENUMERAL_TYPE:
17161 case QUAL_UNION_TYPE:
17162 /* If this is a nested type whose containing class hasn't been written
17163 out yet, writing it out will cover this one, too. This does not apply
17164 to instantiations of member class templates; they need to be added to
17165 the containing class as they are generated. FIXME: This hurts the
17166 idea of combining type decls from multiple TUs, since we can't predict
17167 what set of template instantiations we'll get. */
17168 if (TYPE_CONTEXT (type)
17169 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
17170 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
17172 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
17174 if (TREE_ASM_WRITTEN (type))
17177 /* If that failed, attach ourselves to the stub. */
17178 push_decl_scope (TYPE_CONTEXT (type));
17179 context_die = lookup_type_die (TYPE_CONTEXT (type));
17182 else if (TYPE_CONTEXT (type) != NULL_TREE
17183 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
17185 /* If this type is local to a function that hasn't been written
17186 out yet, use a NULL context for now; it will be fixed up in
17187 decls_for_scope. */
17188 context_die = lookup_decl_die (TYPE_CONTEXT (type));
17193 context_die = declare_in_namespace (type, context_die);
17197 if (TREE_CODE (type) == ENUMERAL_TYPE)
17199 /* This might have been written out by the call to
17200 declare_in_namespace. */
17201 if (!TREE_ASM_WRITTEN (type))
17202 gen_enumeration_type_die (type, context_die);
17205 gen_struct_or_union_type_die (type, context_die, usage);
17210 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
17211 it up if it is ever completed. gen_*_type_die will set it for us
17212 when appropriate. */
17218 case FIXED_POINT_TYPE:
17221 /* No DIEs needed for fundamental types. */
17225 /* No Dwarf representation currently defined. */
17229 gcc_unreachable ();
17232 TREE_ASM_WRITTEN (type) = 1;
17236 gen_type_die (tree type, dw_die_ref context_die)
17238 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
17241 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
17242 things which are local to the given block. */
17245 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
17247 int must_output_die = 0;
17250 /* Ignore blocks that are NULL. */
17251 if (stmt == NULL_TREE)
17254 inlined_func = inlined_function_outer_scope_p (stmt);
17256 /* If the block is one fragment of a non-contiguous block, do not
17257 process the variables, since they will have been done by the
17258 origin block. Do process subblocks. */
17259 if (BLOCK_FRAGMENT_ORIGIN (stmt))
17263 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
17264 gen_block_die (sub, context_die, depth + 1);
17269 /* Determine if we need to output any Dwarf DIEs at all to represent this
17272 /* The outer scopes for inlinings *must* always be represented. We
17273 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
17274 must_output_die = 1;
17277 /* Determine if this block directly contains any "significant"
17278 local declarations which we will need to output DIEs for. */
17279 if (debug_info_level > DINFO_LEVEL_TERSE)
17280 /* We are not in terse mode so *any* local declaration counts
17281 as being a "significant" one. */
17282 must_output_die = ((BLOCK_VARS (stmt) != NULL
17283 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
17284 && (TREE_USED (stmt)
17285 || TREE_ASM_WRITTEN (stmt)
17286 || BLOCK_ABSTRACT (stmt)));
17287 else if ((TREE_USED (stmt)
17288 || TREE_ASM_WRITTEN (stmt)
17289 || BLOCK_ABSTRACT (stmt))
17290 && !dwarf2out_ignore_block (stmt))
17291 must_output_die = 1;
17294 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
17295 DIE for any block which contains no significant local declarations at
17296 all. Rather, in such cases we just call `decls_for_scope' so that any
17297 needed Dwarf info for any sub-blocks will get properly generated. Note
17298 that in terse mode, our definition of what constitutes a "significant"
17299 local declaration gets restricted to include only inlined function
17300 instances and local (nested) function definitions. */
17301 if (must_output_die)
17305 /* If STMT block is abstract, that means we have been called
17306 indirectly from dwarf2out_abstract_function.
17307 That function rightfully marks the descendent blocks (of
17308 the abstract function it is dealing with) as being abstract,
17309 precisely to prevent us from emitting any
17310 DW_TAG_inlined_subroutine DIE as a descendent
17311 of an abstract function instance. So in that case, we should
17312 not call gen_inlined_subroutine_die.
17314 Later though, when cgraph asks dwarf2out to emit info
17315 for the concrete instance of the function decl into which
17316 the concrete instance of STMT got inlined, the later will lead
17317 to the generation of a DW_TAG_inlined_subroutine DIE. */
17318 if (! BLOCK_ABSTRACT (stmt))
17319 gen_inlined_subroutine_die (stmt, context_die, depth);
17322 gen_lexical_block_die (stmt, context_die, depth);
17325 decls_for_scope (stmt, context_die, depth);
17328 /* Process variable DECL (or variable with origin ORIGIN) within
17329 block STMT and add it to CONTEXT_DIE. */
17331 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
17334 tree decl_or_origin = decl ? decl : origin;
17335 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
17337 if (ultimate_origin)
17338 origin = ultimate_origin;
17340 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
17341 die = lookup_decl_die (decl_or_origin);
17342 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
17343 && TYPE_DECL_IS_STUB (decl_or_origin))
17344 die = lookup_type_die (TREE_TYPE (decl_or_origin));
17348 if (die != NULL && die->die_parent == NULL)
17349 add_child_die (context_die, die);
17350 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
17351 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
17352 stmt, context_die);
17354 gen_decl_die (decl, origin, context_die);
17357 /* Generate all of the decls declared within a given scope and (recursively)
17358 all of its sub-blocks. */
17361 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
17367 /* Ignore NULL blocks. */
17368 if (stmt == NULL_TREE)
17371 /* Output the DIEs to represent all of the data objects and typedefs
17372 declared directly within this block but not within any nested
17373 sub-blocks. Also, nested function and tag DIEs have been
17374 generated with a parent of NULL; fix that up now. */
17375 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
17376 process_scope_var (stmt, decl, NULL_TREE, context_die);
17377 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
17378 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
17381 /* If we're at -g1, we're not interested in subblocks. */
17382 if (debug_info_level <= DINFO_LEVEL_TERSE)
17385 /* Output the DIEs to represent all sub-blocks (and the items declared
17386 therein) of this block. */
17387 for (subblocks = BLOCK_SUBBLOCKS (stmt);
17389 subblocks = BLOCK_CHAIN (subblocks))
17390 gen_block_die (subblocks, context_die, depth + 1);
17393 /* Is this a typedef we can avoid emitting? */
17396 is_redundant_typedef (const_tree decl)
17398 if (TYPE_DECL_IS_STUB (decl))
17401 if (DECL_ARTIFICIAL (decl)
17402 && DECL_CONTEXT (decl)
17403 && is_tagged_type (DECL_CONTEXT (decl))
17404 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
17405 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
17406 /* Also ignore the artificial member typedef for the class name. */
17412 /* Returns the DIE for a context. */
17414 static inline dw_die_ref
17415 get_context_die (tree context)
17419 /* Find die that represents this context. */
17420 if (TYPE_P (context))
17421 return force_type_die (context);
17423 return force_decl_die (context);
17425 return comp_unit_die;
17428 /* Returns the DIE for decl. A DIE will always be returned. */
17431 force_decl_die (tree decl)
17433 dw_die_ref decl_die;
17434 unsigned saved_external_flag;
17435 tree save_fn = NULL_TREE;
17436 decl_die = lookup_decl_die (decl);
17439 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
17441 decl_die = lookup_decl_die (decl);
17445 switch (TREE_CODE (decl))
17447 case FUNCTION_DECL:
17448 /* Clear current_function_decl, so that gen_subprogram_die thinks
17449 that this is a declaration. At this point, we just want to force
17450 declaration die. */
17451 save_fn = current_function_decl;
17452 current_function_decl = NULL_TREE;
17453 gen_subprogram_die (decl, context_die);
17454 current_function_decl = save_fn;
17458 /* Set external flag to force declaration die. Restore it after
17459 gen_decl_die() call. */
17460 saved_external_flag = DECL_EXTERNAL (decl);
17461 DECL_EXTERNAL (decl) = 1;
17462 gen_decl_die (decl, NULL, context_die);
17463 DECL_EXTERNAL (decl) = saved_external_flag;
17466 case NAMESPACE_DECL:
17467 if (dwarf_version >= 3 || !dwarf_strict)
17468 dwarf2out_decl (decl);
17470 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
17471 decl_die = comp_unit_die;
17475 gcc_unreachable ();
17478 /* We should be able to find the DIE now. */
17480 decl_die = lookup_decl_die (decl);
17481 gcc_assert (decl_die);
17487 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
17488 always returned. */
17491 force_type_die (tree type)
17493 dw_die_ref type_die;
17495 type_die = lookup_type_die (type);
17498 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
17500 type_die = modified_type_die (type, TYPE_READONLY (type),
17501 TYPE_VOLATILE (type), context_die);
17502 gcc_assert (type_die);
17507 /* Force out any required namespaces to be able to output DECL,
17508 and return the new context_die for it, if it's changed. */
17511 setup_namespace_context (tree thing, dw_die_ref context_die)
17513 tree context = (DECL_P (thing)
17514 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
17515 if (context && TREE_CODE (context) == NAMESPACE_DECL)
17516 /* Force out the namespace. */
17517 context_die = force_decl_die (context);
17519 return context_die;
17522 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
17523 type) within its namespace, if appropriate.
17525 For compatibility with older debuggers, namespace DIEs only contain
17526 declarations; all definitions are emitted at CU scope. */
17529 declare_in_namespace (tree thing, dw_die_ref context_die)
17531 dw_die_ref ns_context;
17533 if (debug_info_level <= DINFO_LEVEL_TERSE)
17534 return context_die;
17536 /* If this decl is from an inlined function, then don't try to emit it in its
17537 namespace, as we will get confused. It would have already been emitted
17538 when the abstract instance of the inline function was emitted anyways. */
17539 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
17540 return context_die;
17542 ns_context = setup_namespace_context (thing, context_die);
17544 if (ns_context != context_die)
17548 if (DECL_P (thing))
17549 gen_decl_die (thing, NULL, ns_context);
17551 gen_type_die (thing, ns_context);
17553 return context_die;
17556 /* Generate a DIE for a namespace or namespace alias. */
17559 gen_namespace_die (tree decl, dw_die_ref context_die)
17561 dw_die_ref namespace_die;
17563 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
17564 they are an alias of. */
17565 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
17567 /* Output a real namespace or module. */
17568 context_die = setup_namespace_context (decl, comp_unit_die);
17569 namespace_die = new_die (is_fortran ()
17570 ? DW_TAG_module : DW_TAG_namespace,
17571 context_die, decl);
17572 /* For Fortran modules defined in different CU don't add src coords. */
17573 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
17574 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
17576 add_name_and_src_coords_attributes (namespace_die, decl);
17577 if (DECL_EXTERNAL (decl))
17578 add_AT_flag (namespace_die, DW_AT_declaration, 1);
17579 equate_decl_number_to_die (decl, namespace_die);
17583 /* Output a namespace alias. */
17585 /* Force out the namespace we are an alias of, if necessary. */
17586 dw_die_ref origin_die
17587 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
17589 if (DECL_CONTEXT (decl) == NULL_TREE
17590 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
17591 context_die = setup_namespace_context (decl, comp_unit_die);
17592 /* Now create the namespace alias DIE. */
17593 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
17594 add_name_and_src_coords_attributes (namespace_die, decl);
17595 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
17596 equate_decl_number_to_die (decl, namespace_die);
17600 /* Generate Dwarf debug information for a decl described by DECL. */
17603 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
17605 tree decl_or_origin = decl ? decl : origin;
17606 tree class_origin = NULL;
17608 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
17611 switch (TREE_CODE (decl_or_origin))
17617 if (!is_fortran ())
17619 /* The individual enumerators of an enum type get output when we output
17620 the Dwarf representation of the relevant enum type itself. */
17624 /* Emit its type. */
17625 gen_type_die (TREE_TYPE (decl), context_die);
17627 /* And its containing namespace. */
17628 context_die = declare_in_namespace (decl, context_die);
17630 gen_const_die (decl, context_die);
17633 case FUNCTION_DECL:
17634 /* Don't output any DIEs to represent mere function declarations,
17635 unless they are class members or explicit block externs. */
17636 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
17637 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
17638 && (current_function_decl == NULL_TREE
17639 || DECL_ARTIFICIAL (decl_or_origin)))
17644 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
17645 on local redeclarations of global functions. That seems broken. */
17646 if (current_function_decl != decl)
17647 /* This is only a declaration. */;
17650 /* If we're emitting a clone, emit info for the abstract instance. */
17651 if (origin || DECL_ORIGIN (decl) != decl)
17652 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
17654 /* If we're emitting an out-of-line copy of an inline function,
17655 emit info for the abstract instance and set up to refer to it. */
17656 else if (cgraph_function_possibly_inlined_p (decl)
17657 && ! DECL_ABSTRACT (decl)
17658 && ! class_or_namespace_scope_p (context_die)
17659 /* dwarf2out_abstract_function won't emit a die if this is just
17660 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
17661 that case, because that works only if we have a die. */
17662 && DECL_INITIAL (decl) != NULL_TREE)
17664 dwarf2out_abstract_function (decl);
17665 set_decl_origin_self (decl);
17668 /* Otherwise we're emitting the primary DIE for this decl. */
17669 else if (debug_info_level > DINFO_LEVEL_TERSE)
17671 /* Before we describe the FUNCTION_DECL itself, make sure that we
17672 have described its return type. */
17673 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
17675 /* And its virtual context. */
17676 if (DECL_VINDEX (decl) != NULL_TREE)
17677 gen_type_die (DECL_CONTEXT (decl), context_die);
17679 /* And its containing type. */
17681 origin = decl_class_context (decl);
17682 if (origin != NULL_TREE)
17683 gen_type_die_for_member (origin, decl, context_die);
17685 /* And its containing namespace. */
17686 context_die = declare_in_namespace (decl, context_die);
17689 /* Now output a DIE to represent the function itself. */
17691 gen_subprogram_die (decl, context_die);
17695 /* If we are in terse mode, don't generate any DIEs to represent any
17696 actual typedefs. */
17697 if (debug_info_level <= DINFO_LEVEL_TERSE)
17700 /* In the special case of a TYPE_DECL node representing the declaration
17701 of some type tag, if the given TYPE_DECL is marked as having been
17702 instantiated from some other (original) TYPE_DECL node (e.g. one which
17703 was generated within the original definition of an inline function) we
17704 used to generate a special (abbreviated) DW_TAG_structure_type,
17705 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
17706 should be actually referencing those DIEs, as variable DIEs with that
17707 type would be emitted already in the abstract origin, so it was always
17708 removed during unused type prunning. Don't add anything in this
17710 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
17713 if (is_redundant_typedef (decl))
17714 gen_type_die (TREE_TYPE (decl), context_die);
17716 /* Output a DIE to represent the typedef itself. */
17717 gen_typedef_die (decl, context_die);
17721 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17722 gen_label_die (decl, context_die);
17727 /* If we are in terse mode, don't generate any DIEs to represent any
17728 variable declarations or definitions. */
17729 if (debug_info_level <= DINFO_LEVEL_TERSE)
17732 /* Output any DIEs that are needed to specify the type of this data
17734 if (decl_by_reference_p (decl_or_origin))
17735 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17737 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17739 /* And its containing type. */
17740 class_origin = decl_class_context (decl_or_origin);
17741 if (class_origin != NULL_TREE)
17742 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
17744 /* And its containing namespace. */
17745 context_die = declare_in_namespace (decl_or_origin, context_die);
17747 /* Now output the DIE to represent the data object itself. This gets
17748 complicated because of the possibility that the VAR_DECL really
17749 represents an inlined instance of a formal parameter for an inline
17752 origin = decl_ultimate_origin (decl);
17753 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
17754 gen_formal_parameter_die (decl, origin,
17755 true /* Emit name attribute. */,
17758 gen_variable_die (decl, origin, context_die);
17762 /* Ignore the nameless fields that are used to skip bits but handle C++
17763 anonymous unions and structs. */
17764 if (DECL_NAME (decl) != NULL_TREE
17765 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
17766 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
17768 gen_type_die (member_declared_type (decl), context_die);
17769 gen_field_die (decl, context_die);
17774 if (DECL_BY_REFERENCE (decl_or_origin))
17775 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17777 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17778 gen_formal_parameter_die (decl, origin,
17779 true /* Emit name attribute. */,
17783 case NAMESPACE_DECL:
17784 case IMPORTED_DECL:
17785 if (dwarf_version >= 3 || !dwarf_strict)
17786 gen_namespace_die (decl, context_die);
17790 /* Probably some frontend-internal decl. Assume we don't care. */
17791 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
17796 /* Output debug information for global decl DECL. Called from toplev.c after
17797 compilation proper has finished. */
17800 dwarf2out_global_decl (tree decl)
17802 /* Output DWARF2 information for file-scope tentative data object
17803 declarations, file-scope (extern) function declarations (which
17804 had no corresponding body) and file-scope tagged type declarations
17805 and definitions which have not yet been forced out. */
17806 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
17807 dwarf2out_decl (decl);
17810 /* Output debug information for type decl DECL. Called from toplev.c
17811 and from language front ends (to record built-in types). */
17813 dwarf2out_type_decl (tree decl, int local)
17816 dwarf2out_decl (decl);
17819 /* Output debug information for imported module or decl DECL.
17820 NAME is non-NULL name in the lexical block if the decl has been renamed.
17821 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
17822 that DECL belongs to.
17823 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
17825 dwarf2out_imported_module_or_decl_1 (tree decl,
17827 tree lexical_block,
17828 dw_die_ref lexical_block_die)
17830 expanded_location xloc;
17831 dw_die_ref imported_die = NULL;
17832 dw_die_ref at_import_die;
17834 if (TREE_CODE (decl) == IMPORTED_DECL)
17836 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
17837 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
17841 xloc = expand_location (input_location);
17843 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
17845 if (is_base_type (TREE_TYPE (decl)))
17846 at_import_die = base_type_die (TREE_TYPE (decl));
17848 at_import_die = force_type_die (TREE_TYPE (decl));
17849 /* For namespace N { typedef void T; } using N::T; base_type_die
17850 returns NULL, but DW_TAG_imported_declaration requires
17851 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
17852 if (!at_import_die)
17854 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
17855 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
17856 at_import_die = lookup_type_die (TREE_TYPE (decl));
17857 gcc_assert (at_import_die);
17862 at_import_die = lookup_decl_die (decl);
17863 if (!at_import_die)
17865 /* If we're trying to avoid duplicate debug info, we may not have
17866 emitted the member decl for this field. Emit it now. */
17867 if (TREE_CODE (decl) == FIELD_DECL)
17869 tree type = DECL_CONTEXT (decl);
17871 if (TYPE_CONTEXT (type)
17872 && TYPE_P (TYPE_CONTEXT (type))
17873 && !should_emit_struct_debug (TYPE_CONTEXT (type),
17874 DINFO_USAGE_DIR_USE))
17876 gen_type_die_for_member (type, decl,
17877 get_context_die (TYPE_CONTEXT (type)));
17879 at_import_die = force_decl_die (decl);
17883 if (TREE_CODE (decl) == NAMESPACE_DECL)
17885 if (dwarf_version >= 3 || !dwarf_strict)
17886 imported_die = new_die (DW_TAG_imported_module,
17893 imported_die = new_die (DW_TAG_imported_declaration,
17897 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
17898 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
17900 add_AT_string (imported_die, DW_AT_name,
17901 IDENTIFIER_POINTER (name));
17902 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
17905 /* Output debug information for imported module or decl DECL.
17906 NAME is non-NULL name in context if the decl has been renamed.
17907 CHILD is true if decl is one of the renamed decls as part of
17908 importing whole module. */
17911 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
17914 /* dw_die_ref at_import_die; */
17915 dw_die_ref scope_die;
17917 if (debug_info_level <= DINFO_LEVEL_TERSE)
17922 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
17923 We need decl DIE for reference and scope die. First, get DIE for the decl
17926 /* Get the scope die for decl context. Use comp_unit_die for global module
17927 or decl. If die is not found for non globals, force new die. */
17929 && TYPE_P (context)
17930 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
17933 if (!(dwarf_version >= 3 || !dwarf_strict))
17936 scope_die = get_context_die (context);
17940 gcc_assert (scope_die->die_child);
17941 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
17942 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
17943 scope_die = scope_die->die_child;
17946 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
17947 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
17951 /* Write the debugging output for DECL. */
17954 dwarf2out_decl (tree decl)
17956 dw_die_ref context_die = comp_unit_die;
17958 switch (TREE_CODE (decl))
17963 case FUNCTION_DECL:
17964 /* What we would really like to do here is to filter out all mere
17965 file-scope declarations of file-scope functions which are never
17966 referenced later within this translation unit (and keep all of ones
17967 that *are* referenced later on) but we aren't clairvoyant, so we have
17968 no idea which functions will be referenced in the future (i.e. later
17969 on within the current translation unit). So here we just ignore all
17970 file-scope function declarations which are not also definitions. If
17971 and when the debugger needs to know something about these functions,
17972 it will have to hunt around and find the DWARF information associated
17973 with the definition of the function.
17975 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
17976 nodes represent definitions and which ones represent mere
17977 declarations. We have to check DECL_INITIAL instead. That's because
17978 the C front-end supports some weird semantics for "extern inline"
17979 function definitions. These can get inlined within the current
17980 translation unit (and thus, we need to generate Dwarf info for their
17981 abstract instances so that the Dwarf info for the concrete inlined
17982 instances can have something to refer to) but the compiler never
17983 generates any out-of-lines instances of such things (despite the fact
17984 that they *are* definitions).
17986 The important point is that the C front-end marks these "extern
17987 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
17988 them anyway. Note that the C++ front-end also plays some similar games
17989 for inline function definitions appearing within include files which
17990 also contain `#pragma interface' pragmas. */
17991 if (DECL_INITIAL (decl) == NULL_TREE)
17994 /* If we're a nested function, initially use a parent of NULL; if we're
17995 a plain function, this will be fixed up in decls_for_scope. If
17996 we're a method, it will be ignored, since we already have a DIE. */
17997 if (decl_function_context (decl)
17998 /* But if we're in terse mode, we don't care about scope. */
17999 && debug_info_level > DINFO_LEVEL_TERSE)
18000 context_die = NULL;
18004 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
18005 declaration and if the declaration was never even referenced from
18006 within this entire compilation unit. We suppress these DIEs in
18007 order to save space in the .debug section (by eliminating entries
18008 which are probably useless). Note that we must not suppress
18009 block-local extern declarations (whether used or not) because that
18010 would screw-up the debugger's name lookup mechanism and cause it to
18011 miss things which really ought to be in scope at a given point. */
18012 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
18015 /* For local statics lookup proper context die. */
18016 if (TREE_STATIC (decl) && decl_function_context (decl))
18017 context_die = lookup_decl_die (DECL_CONTEXT (decl));
18019 /* If we are in terse mode, don't generate any DIEs to represent any
18020 variable declarations or definitions. */
18021 if (debug_info_level <= DINFO_LEVEL_TERSE)
18026 if (debug_info_level <= DINFO_LEVEL_TERSE)
18028 if (!is_fortran ())
18030 if (TREE_STATIC (decl) && decl_function_context (decl))
18031 context_die = lookup_decl_die (DECL_CONTEXT (decl));
18034 case NAMESPACE_DECL:
18035 case IMPORTED_DECL:
18036 if (debug_info_level <= DINFO_LEVEL_TERSE)
18038 if (lookup_decl_die (decl) != NULL)
18043 /* Don't emit stubs for types unless they are needed by other DIEs. */
18044 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
18047 /* Don't bother trying to generate any DIEs to represent any of the
18048 normal built-in types for the language we are compiling. */
18049 if (DECL_IS_BUILTIN (decl))
18051 /* OK, we need to generate one for `bool' so GDB knows what type
18052 comparisons have. */
18054 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
18055 && ! DECL_IGNORED_P (decl))
18056 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
18061 /* If we are in terse mode, don't generate any DIEs for types. */
18062 if (debug_info_level <= DINFO_LEVEL_TERSE)
18065 /* If we're a function-scope tag, initially use a parent of NULL;
18066 this will be fixed up in decls_for_scope. */
18067 if (decl_function_context (decl))
18068 context_die = NULL;
18076 gen_decl_die (decl, NULL, context_die);
18079 /* Output a marker (i.e. a label) for the beginning of the generated code for
18080 a lexical block. */
18083 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
18084 unsigned int blocknum)
18086 switch_to_section (current_function_section ());
18087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
18090 /* Output a marker (i.e. a label) for the end of the generated code for a
18094 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
18096 switch_to_section (current_function_section ());
18097 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
18100 /* Returns nonzero if it is appropriate not to emit any debugging
18101 information for BLOCK, because it doesn't contain any instructions.
18103 Don't allow this for blocks with nested functions or local classes
18104 as we would end up with orphans, and in the presence of scheduling
18105 we may end up calling them anyway. */
18108 dwarf2out_ignore_block (const_tree block)
18113 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
18114 if (TREE_CODE (decl) == FUNCTION_DECL
18115 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
18117 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
18119 decl = BLOCK_NONLOCALIZED_VAR (block, i);
18120 if (TREE_CODE (decl) == FUNCTION_DECL
18121 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
18128 /* Hash table routines for file_hash. */
18131 file_table_eq (const void *p1_p, const void *p2_p)
18133 const struct dwarf_file_data *const p1 =
18134 (const struct dwarf_file_data *) p1_p;
18135 const char *const p2 = (const char *) p2_p;
18136 return strcmp (p1->filename, p2) == 0;
18140 file_table_hash (const void *p_p)
18142 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
18143 return htab_hash_string (p->filename);
18146 /* Lookup FILE_NAME (in the list of filenames that we know about here in
18147 dwarf2out.c) and return its "index". The index of each (known) filename is
18148 just a unique number which is associated with only that one filename. We
18149 need such numbers for the sake of generating labels (in the .debug_sfnames
18150 section) and references to those files numbers (in the .debug_srcinfo
18151 and.debug_macinfo sections). If the filename given as an argument is not
18152 found in our current list, add it to the list and assign it the next
18153 available unique index number. In order to speed up searches, we remember
18154 the index of the filename was looked up last. This handles the majority of
18157 static struct dwarf_file_data *
18158 lookup_filename (const char *file_name)
18161 struct dwarf_file_data * created;
18163 /* Check to see if the file name that was searched on the previous
18164 call matches this file name. If so, return the index. */
18165 if (file_table_last_lookup
18166 && (file_name == file_table_last_lookup->filename
18167 || strcmp (file_table_last_lookup->filename, file_name) == 0))
18168 return file_table_last_lookup;
18170 /* Didn't match the previous lookup, search the table. */
18171 slot = htab_find_slot_with_hash (file_table, file_name,
18172 htab_hash_string (file_name), INSERT);
18174 return (struct dwarf_file_data *) *slot;
18176 created = GGC_NEW (struct dwarf_file_data);
18177 created->filename = file_name;
18178 created->emitted_number = 0;
18183 /* If the assembler will construct the file table, then translate the compiler
18184 internal file table number into the assembler file table number, and emit
18185 a .file directive if we haven't already emitted one yet. The file table
18186 numbers are different because we prune debug info for unused variables and
18187 types, which may include filenames. */
18190 maybe_emit_file (struct dwarf_file_data * fd)
18192 if (! fd->emitted_number)
18194 if (last_emitted_file)
18195 fd->emitted_number = last_emitted_file->emitted_number + 1;
18197 fd->emitted_number = 1;
18198 last_emitted_file = fd;
18200 if (DWARF2_ASM_LINE_DEBUG_INFO)
18202 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
18203 output_quoted_string (asm_out_file,
18204 remap_debug_filename (fd->filename));
18205 fputc ('\n', asm_out_file);
18209 return fd->emitted_number;
18212 /* Schedule generation of a DW_AT_const_value attribute to DIE.
18213 That generation should happen after function debug info has been
18214 generated. The value of the attribute is the constant value of ARG. */
18217 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
18219 die_arg_entry entry;
18224 if (!tmpl_value_parm_die_table)
18225 tmpl_value_parm_die_table
18226 = VEC_alloc (die_arg_entry, gc, 32);
18230 VEC_safe_push (die_arg_entry, gc,
18231 tmpl_value_parm_die_table,
18235 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
18236 by append_entry_to_tmpl_value_parm_die_table. This function must
18237 be called after function DIEs have been generated. */
18240 gen_remaining_tmpl_value_param_die_attribute (void)
18242 if (tmpl_value_parm_die_table)
18248 VEC_iterate (die_arg_entry, tmpl_value_parm_die_table, i, e);
18250 tree_add_const_value_attribute (e->die, e->arg);
18255 /* Replace DW_AT_name for the decl with name. */
18258 dwarf2out_set_name (tree decl, tree name)
18263 die = TYPE_SYMTAB_DIE (decl);
18267 attr = get_AT (die, DW_AT_name);
18270 struct indirect_string_node *node;
18272 node = find_AT_string (dwarf2_name (name, 0));
18273 /* replace the string. */
18274 attr->dw_attr_val.v.val_str = node;
18278 add_name_attribute (die, dwarf2_name (name, 0));
18281 /* Called by the final INSN scan whenever we see a var location. We
18282 use it to drop labels in the right places, and throw the location in
18283 our lookup table. */
18286 dwarf2out_var_location (rtx loc_note)
18288 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
18289 struct var_loc_node *newloc;
18291 static const char *last_label;
18292 static const char *last_postcall_label;
18293 static bool last_in_cold_section_p;
18296 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
18299 next_real = next_real_insn (loc_note);
18300 /* If there are no instructions which would be affected by this note,
18301 don't do anything. */
18302 if (next_real == NULL_RTX)
18305 newloc = GGC_CNEW (struct var_loc_node);
18306 /* If there were no real insns between note we processed last time
18307 and this note, use the label we emitted last time. */
18308 if (last_var_location_insn == NULL_RTX
18309 || last_var_location_insn != next_real
18310 || last_in_cold_section_p != in_cold_section_p)
18312 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
18313 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
18315 last_label = ggc_strdup (loclabel);
18316 if (!NOTE_DURING_CALL_P (loc_note))
18317 last_postcall_label = NULL;
18319 newloc->var_loc_note = loc_note;
18320 newloc->next = NULL;
18322 if (!NOTE_DURING_CALL_P (loc_note))
18323 newloc->label = last_label;
18326 if (!last_postcall_label)
18328 sprintf (loclabel, "%s-1", last_label);
18329 last_postcall_label = ggc_strdup (loclabel);
18331 newloc->label = last_postcall_label;
18334 if (cfun && in_cold_section_p)
18335 newloc->section_label = crtl->subsections.cold_section_label;
18337 newloc->section_label = text_section_label;
18339 last_var_location_insn = next_real;
18340 last_in_cold_section_p = in_cold_section_p;
18341 decl = NOTE_VAR_LOCATION_DECL (loc_note);
18342 add_var_loc_to_decl (decl, newloc);
18345 /* We need to reset the locations at the beginning of each
18346 function. We can't do this in the end_function hook, because the
18347 declarations that use the locations won't have been output when
18348 that hook is called. Also compute have_multiple_function_sections here. */
18351 dwarf2out_begin_function (tree fun)
18353 htab_empty (decl_loc_table);
18355 if (function_section (fun) != text_section)
18356 have_multiple_function_sections = true;
18358 dwarf2out_note_section_used ();
18361 /* Output a label to mark the beginning of a source code line entry
18362 and record information relating to this source line, in
18363 'line_info_table' for later output of the .debug_line section. */
18366 dwarf2out_source_line (unsigned int line, const char *filename,
18367 int discriminator, bool is_stmt)
18369 static bool last_is_stmt = true;
18371 if (debug_info_level >= DINFO_LEVEL_NORMAL
18374 int file_num = maybe_emit_file (lookup_filename (filename));
18376 switch_to_section (current_function_section ());
18378 /* If requested, emit something human-readable. */
18379 if (flag_debug_asm)
18380 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
18383 if (DWARF2_ASM_LINE_DEBUG_INFO)
18385 /* Emit the .loc directive understood by GNU as. */
18386 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
18387 if (is_stmt != last_is_stmt)
18389 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
18390 last_is_stmt = is_stmt;
18392 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
18393 fprintf (asm_out_file, " discriminator %d", discriminator);
18394 fputc ('\n', asm_out_file);
18396 /* Indicate that line number info exists. */
18397 line_info_table_in_use++;
18399 else if (function_section (current_function_decl) != text_section)
18401 dw_separate_line_info_ref line_info;
18402 targetm.asm_out.internal_label (asm_out_file,
18403 SEPARATE_LINE_CODE_LABEL,
18404 separate_line_info_table_in_use);
18406 /* Expand the line info table if necessary. */
18407 if (separate_line_info_table_in_use
18408 == separate_line_info_table_allocated)
18410 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
18411 separate_line_info_table
18412 = GGC_RESIZEVEC (dw_separate_line_info_entry,
18413 separate_line_info_table,
18414 separate_line_info_table_allocated);
18415 memset (separate_line_info_table
18416 + separate_line_info_table_in_use,
18418 (LINE_INFO_TABLE_INCREMENT
18419 * sizeof (dw_separate_line_info_entry)));
18422 /* Add the new entry at the end of the line_info_table. */
18424 = &separate_line_info_table[separate_line_info_table_in_use++];
18425 line_info->dw_file_num = file_num;
18426 line_info->dw_line_num = line;
18427 line_info->function = current_function_funcdef_no;
18431 dw_line_info_ref line_info;
18433 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
18434 line_info_table_in_use);
18436 /* Expand the line info table if necessary. */
18437 if (line_info_table_in_use == line_info_table_allocated)
18439 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
18441 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
18442 line_info_table_allocated);
18443 memset (line_info_table + line_info_table_in_use, 0,
18444 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
18447 /* Add the new entry at the end of the line_info_table. */
18448 line_info = &line_info_table[line_info_table_in_use++];
18449 line_info->dw_file_num = file_num;
18450 line_info->dw_line_num = line;
18455 /* Record the beginning of a new source file. */
18458 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
18460 if (flag_eliminate_dwarf2_dups)
18462 /* Record the beginning of the file for break_out_includes. */
18463 dw_die_ref bincl_die;
18465 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
18466 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
18469 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18471 int file_num = maybe_emit_file (lookup_filename (filename));
18473 switch_to_section (debug_macinfo_section);
18474 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
18475 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
18478 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
18482 /* Record the end of a source file. */
18485 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
18487 if (flag_eliminate_dwarf2_dups)
18488 /* Record the end of the file for break_out_includes. */
18489 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
18491 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18493 switch_to_section (debug_macinfo_section);
18494 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
18498 /* Called from debug_define in toplev.c. The `buffer' parameter contains
18499 the tail part of the directive line, i.e. the part which is past the
18500 initial whitespace, #, whitespace, directive-name, whitespace part. */
18503 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
18504 const char *buffer ATTRIBUTE_UNUSED)
18506 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18508 switch_to_section (debug_macinfo_section);
18509 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
18510 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
18511 dw2_asm_output_nstring (buffer, -1, "The macro");
18515 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
18516 the tail part of the directive line, i.e. the part which is past the
18517 initial whitespace, #, whitespace, directive-name, whitespace part. */
18520 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
18521 const char *buffer ATTRIBUTE_UNUSED)
18523 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18525 switch_to_section (debug_macinfo_section);
18526 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
18527 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
18528 dw2_asm_output_nstring (buffer, -1, "The macro");
18532 /* Set up for Dwarf output at the start of compilation. */
18535 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
18537 /* Allocate the file_table. */
18538 file_table = htab_create_ggc (50, file_table_hash,
18539 file_table_eq, NULL);
18541 /* Allocate the decl_die_table. */
18542 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
18543 decl_die_table_eq, NULL);
18545 /* Allocate the decl_loc_table. */
18546 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
18547 decl_loc_table_eq, NULL);
18549 /* Allocate the initial hunk of the decl_scope_table. */
18550 decl_scope_table = VEC_alloc (tree, gc, 256);
18552 /* Allocate the initial hunk of the abbrev_die_table. */
18553 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
18554 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
18555 /* Zero-th entry is allocated, but unused. */
18556 abbrev_die_table_in_use = 1;
18558 /* Allocate the initial hunk of the line_info_table. */
18559 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
18560 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
18562 /* Zero-th entry is allocated, but unused. */
18563 line_info_table_in_use = 1;
18565 /* Allocate the pubtypes and pubnames vectors. */
18566 pubname_table = VEC_alloc (pubname_entry, gc, 32);
18567 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
18569 /* Generate the initial DIE for the .debug section. Note that the (string)
18570 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
18571 will (typically) be a relative pathname and that this pathname should be
18572 taken as being relative to the directory from which the compiler was
18573 invoked when the given (base) source file was compiled. We will fill
18574 in this value in dwarf2out_finish. */
18575 comp_unit_die = gen_compile_unit_die (NULL);
18577 incomplete_types = VEC_alloc (tree, gc, 64);
18579 used_rtx_array = VEC_alloc (rtx, gc, 32);
18581 debug_info_section = get_section (DEBUG_INFO_SECTION,
18582 SECTION_DEBUG, NULL);
18583 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
18584 SECTION_DEBUG, NULL);
18585 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
18586 SECTION_DEBUG, NULL);
18587 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
18588 SECTION_DEBUG, NULL);
18589 debug_line_section = get_section (DEBUG_LINE_SECTION,
18590 SECTION_DEBUG, NULL);
18591 debug_loc_section = get_section (DEBUG_LOC_SECTION,
18592 SECTION_DEBUG, NULL);
18593 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
18594 SECTION_DEBUG, NULL);
18595 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
18596 SECTION_DEBUG, NULL);
18597 debug_str_section = get_section (DEBUG_STR_SECTION,
18598 DEBUG_STR_SECTION_FLAGS, NULL);
18599 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
18600 SECTION_DEBUG, NULL);
18601 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
18602 SECTION_DEBUG, NULL);
18604 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
18605 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
18606 DEBUG_ABBREV_SECTION_LABEL, 0);
18607 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
18608 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
18609 COLD_TEXT_SECTION_LABEL, 0);
18610 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
18612 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
18613 DEBUG_INFO_SECTION_LABEL, 0);
18614 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
18615 DEBUG_LINE_SECTION_LABEL, 0);
18616 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
18617 DEBUG_RANGES_SECTION_LABEL, 0);
18618 switch_to_section (debug_abbrev_section);
18619 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
18620 switch_to_section (debug_info_section);
18621 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
18622 switch_to_section (debug_line_section);
18623 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
18625 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18627 switch_to_section (debug_macinfo_section);
18628 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
18629 DEBUG_MACINFO_SECTION_LABEL, 0);
18630 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
18633 switch_to_section (text_section);
18634 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
18635 if (flag_reorder_blocks_and_partition)
18637 cold_text_section = unlikely_text_section ();
18638 switch_to_section (cold_text_section);
18639 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
18642 #ifdef HAVE_GAS_CFI_SECTIONS_DIRECTIVE
18643 if (dwarf2out_do_cfi_asm ())
18645 #ifndef TARGET_UNWIND_INFO
18646 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
18648 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
18653 /* A helper function for dwarf2out_finish called through
18654 htab_traverse. Emit one queued .debug_str string. */
18657 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
18659 struct indirect_string_node *node = (struct indirect_string_node *) *h;
18661 if (node->label && node->refcount)
18663 switch_to_section (debug_str_section);
18664 ASM_OUTPUT_LABEL (asm_out_file, node->label);
18665 assemble_string (node->str, strlen (node->str) + 1);
18671 #if ENABLE_ASSERT_CHECKING
18672 /* Verify that all marks are clear. */
18675 verify_marks_clear (dw_die_ref die)
18679 gcc_assert (! die->die_mark);
18680 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
18682 #endif /* ENABLE_ASSERT_CHECKING */
18684 /* Clear the marks for a die and its children.
18685 Be cool if the mark isn't set. */
18688 prune_unmark_dies (dw_die_ref die)
18694 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
18697 /* Given DIE that we're marking as used, find any other dies
18698 it references as attributes and mark them as used. */
18701 prune_unused_types_walk_attribs (dw_die_ref die)
18706 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18708 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
18710 /* A reference to another DIE.
18711 Make sure that it will get emitted. */
18712 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
18714 /* Set the string's refcount to 0 so that prune_unused_types_mark
18715 accounts properly for it. */
18716 if (AT_class (a) == dw_val_class_str)
18717 a->dw_attr_val.v.val_str->refcount = 0;
18722 /* Mark DIE as being used. If DOKIDS is true, then walk down
18723 to DIE's children. */
18726 prune_unused_types_mark (dw_die_ref die, int dokids)
18730 if (die->die_mark == 0)
18732 /* We haven't done this node yet. Mark it as used. */
18735 /* We also have to mark its parents as used.
18736 (But we don't want to mark our parents' kids due to this.) */
18737 if (die->die_parent)
18738 prune_unused_types_mark (die->die_parent, 0);
18740 /* Mark any referenced nodes. */
18741 prune_unused_types_walk_attribs (die);
18743 /* If this node is a specification,
18744 also mark the definition, if it exists. */
18745 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
18746 prune_unused_types_mark (die->die_definition, 1);
18749 if (dokids && die->die_mark != 2)
18751 /* We need to walk the children, but haven't done so yet.
18752 Remember that we've walked the kids. */
18755 /* If this is an array type, we need to make sure our
18756 kids get marked, even if they're types. */
18757 if (die->die_tag == DW_TAG_array_type)
18758 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
18760 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18764 /* For local classes, look if any static member functions were emitted
18765 and if so, mark them. */
18768 prune_unused_types_walk_local_classes (dw_die_ref die)
18772 if (die->die_mark == 2)
18775 switch (die->die_tag)
18777 case DW_TAG_structure_type:
18778 case DW_TAG_union_type:
18779 case DW_TAG_class_type:
18782 case DW_TAG_subprogram:
18783 if (!get_AT_flag (die, DW_AT_declaration)
18784 || die->die_definition != NULL)
18785 prune_unused_types_mark (die, 1);
18792 /* Mark children. */
18793 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
18796 /* Walk the tree DIE and mark types that we actually use. */
18799 prune_unused_types_walk (dw_die_ref die)
18803 /* Don't do anything if this node is already marked and
18804 children have been marked as well. */
18805 if (die->die_mark == 2)
18808 switch (die->die_tag)
18810 case DW_TAG_structure_type:
18811 case DW_TAG_union_type:
18812 case DW_TAG_class_type:
18813 if (die->die_perennial_p)
18816 for (c = die->die_parent; c; c = c->die_parent)
18817 if (c->die_tag == DW_TAG_subprogram)
18820 /* Finding used static member functions inside of classes
18821 is needed just for local classes, because for other classes
18822 static member function DIEs with DW_AT_specification
18823 are emitted outside of the DW_TAG_*_type. If we ever change
18824 it, we'd need to call this even for non-local classes. */
18826 prune_unused_types_walk_local_classes (die);
18828 /* It's a type node --- don't mark it. */
18831 case DW_TAG_const_type:
18832 case DW_TAG_packed_type:
18833 case DW_TAG_pointer_type:
18834 case DW_TAG_reference_type:
18835 case DW_TAG_volatile_type:
18836 case DW_TAG_typedef:
18837 case DW_TAG_array_type:
18838 case DW_TAG_interface_type:
18839 case DW_TAG_friend:
18840 case DW_TAG_variant_part:
18841 case DW_TAG_enumeration_type:
18842 case DW_TAG_subroutine_type:
18843 case DW_TAG_string_type:
18844 case DW_TAG_set_type:
18845 case DW_TAG_subrange_type:
18846 case DW_TAG_ptr_to_member_type:
18847 case DW_TAG_file_type:
18848 if (die->die_perennial_p)
18851 /* It's a type node --- don't mark it. */
18855 /* Mark everything else. */
18859 if (die->die_mark == 0)
18863 /* Now, mark any dies referenced from here. */
18864 prune_unused_types_walk_attribs (die);
18869 /* Mark children. */
18870 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18873 /* Increment the string counts on strings referred to from DIE's
18877 prune_unused_types_update_strings (dw_die_ref die)
18882 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18883 if (AT_class (a) == dw_val_class_str)
18885 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
18887 /* Avoid unnecessarily putting strings that are used less than
18888 twice in the hash table. */
18890 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
18893 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
18894 htab_hash_string (s->str),
18896 gcc_assert (*slot == NULL);
18902 /* Remove from the tree DIE any dies that aren't marked. */
18905 prune_unused_types_prune (dw_die_ref die)
18909 gcc_assert (die->die_mark);
18910 prune_unused_types_update_strings (die);
18912 if (! die->die_child)
18915 c = die->die_child;
18917 dw_die_ref prev = c;
18918 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
18919 if (c == die->die_child)
18921 /* No marked children between 'prev' and the end of the list. */
18923 /* No marked children at all. */
18924 die->die_child = NULL;
18927 prev->die_sib = c->die_sib;
18928 die->die_child = prev;
18933 if (c != prev->die_sib)
18935 prune_unused_types_prune (c);
18936 } while (c != die->die_child);
18939 /* A helper function for dwarf2out_finish called through
18940 htab_traverse. Clear .debug_str strings that we haven't already
18941 decided to emit. */
18944 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
18946 struct indirect_string_node *node = (struct indirect_string_node *) *h;
18948 if (!node->label || !node->refcount)
18949 htab_clear_slot (debug_str_hash, h);
18954 /* Remove dies representing declarations that we never use. */
18957 prune_unused_types (void)
18960 limbo_die_node *node;
18963 #if ENABLE_ASSERT_CHECKING
18964 /* All the marks should already be clear. */
18965 verify_marks_clear (comp_unit_die);
18966 for (node = limbo_die_list; node; node = node->next)
18967 verify_marks_clear (node->die);
18968 #endif /* ENABLE_ASSERT_CHECKING */
18970 /* Mark types that are used in global variables. */
18971 premark_types_used_by_global_vars ();
18973 /* Set the mark on nodes that are actually used. */
18974 prune_unused_types_walk (comp_unit_die);
18975 for (node = limbo_die_list; node; node = node->next)
18976 prune_unused_types_walk (node->die);
18978 /* Also set the mark on nodes referenced from the
18979 pubname_table or arange_table. */
18980 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
18981 prune_unused_types_mark (pub->die, 1);
18982 for (i = 0; i < arange_table_in_use; i++)
18983 prune_unused_types_mark (arange_table[i], 1);
18985 /* Get rid of nodes that aren't marked; and update the string counts. */
18986 if (debug_str_hash && debug_str_hash_forced)
18987 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
18988 else if (debug_str_hash)
18989 htab_empty (debug_str_hash);
18990 prune_unused_types_prune (comp_unit_die);
18991 for (node = limbo_die_list; node; node = node->next)
18992 prune_unused_types_prune (node->die);
18994 /* Leave the marks clear. */
18995 prune_unmark_dies (comp_unit_die);
18996 for (node = limbo_die_list; node; node = node->next)
18997 prune_unmark_dies (node->die);
19000 /* Set the parameter to true if there are any relative pathnames in
19003 file_table_relative_p (void ** slot, void *param)
19005 bool *p = (bool *) param;
19006 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
19007 if (!IS_ABSOLUTE_PATH (d->filename))
19015 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
19016 to the location it would have been added, should we know its
19017 DECL_ASSEMBLER_NAME when we added other attributes. This will
19018 probably improve compactness of debug info, removing equivalent
19019 abbrevs, and hide any differences caused by deferring the
19020 computation of the assembler name, triggered by e.g. PCH. */
19023 move_linkage_attr (dw_die_ref die)
19025 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
19026 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
19028 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
19032 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
19034 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
19038 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
19040 VEC_pop (dw_attr_node, die->die_attr);
19041 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
19045 /* Helper function for resolve_addr, attempt to resolve
19046 one CONST_STRING, return non-zero if not successful. Similarly verify that
19047 SYMBOL_REFs refer to variables emitted in the current CU. */
19050 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
19054 if (GET_CODE (rtl) == CONST_STRING)
19056 size_t len = strlen (XSTR (rtl, 0)) + 1;
19057 tree t = build_string (len, XSTR (rtl, 0));
19058 tree tlen = build_int_cst (NULL_TREE, len - 1);
19060 = build_array_type (char_type_node, build_index_type (tlen));
19061 rtl = lookup_constant_def (t);
19062 if (!rtl || !MEM_P (rtl))
19064 rtl = XEXP (rtl, 0);
19065 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
19070 if (GET_CODE (rtl) == SYMBOL_REF
19071 && SYMBOL_REF_DECL (rtl)
19072 && TREE_CODE (SYMBOL_REF_DECL (rtl)) == VAR_DECL
19073 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
19076 if (GET_CODE (rtl) == CONST
19077 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
19083 /* Helper function for resolve_addr, handle one location
19084 expression, return false if at least one CONST_STRING or SYMBOL_REF in
19085 the location list couldn't be resolved. */
19088 resolve_addr_in_expr (dw_loc_descr_ref loc)
19090 for (; loc; loc = loc->dw_loc_next)
19091 if ((loc->dw_loc_opc == DW_OP_addr
19092 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
19093 || (loc->dw_loc_opc == DW_OP_implicit_value
19094 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
19095 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
19100 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
19101 an address in .rodata section if the string literal is emitted there,
19102 or remove the containing location list or replace DW_AT_const_value
19103 with DW_AT_location and empty location expression, if it isn't found
19104 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
19105 to something that has been emitted in the current CU. */
19108 resolve_addr (dw_die_ref die)
19112 dw_loc_list_ref curr;
19115 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
19116 switch (AT_class (a))
19118 case dw_val_class_loc_list:
19119 for (curr = AT_loc_list (a); curr != NULL; curr = curr->dw_loc_next)
19120 if (!resolve_addr_in_expr (curr->expr))
19123 case dw_val_class_loc:
19124 if (!resolve_addr_in_expr (AT_loc (a)))
19125 a->dw_attr_val.v.val_loc = NULL;
19127 case dw_val_class_addr:
19128 if (a->dw_attr == DW_AT_const_value
19129 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
19131 a->dw_attr = DW_AT_location;
19132 a->dw_attr_val.val_class = dw_val_class_loc;
19133 a->dw_attr_val.v.val_loc = NULL;
19140 FOR_EACH_CHILD (die, c, resolve_addr (c));
19143 /* Output stuff that dwarf requires at the end of every file,
19144 and generate the DWARF-2 debugging info. */
19147 dwarf2out_finish (const char *filename)
19149 limbo_die_node *node, *next_node;
19150 dw_die_ref die = 0;
19153 gen_remaining_tmpl_value_param_die_attribute ();
19155 /* Add the name for the main input file now. We delayed this from
19156 dwarf2out_init to avoid complications with PCH. */
19157 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
19158 if (!IS_ABSOLUTE_PATH (filename))
19159 add_comp_dir_attribute (comp_unit_die);
19160 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
19163 htab_traverse (file_table, file_table_relative_p, &p);
19165 add_comp_dir_attribute (comp_unit_die);
19168 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
19170 add_location_or_const_value_attribute (
19171 VEC_index (deferred_locations, deferred_locations_list, i)->die,
19172 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
19176 /* Traverse the limbo die list, and add parent/child links. The only
19177 dies without parents that should be here are concrete instances of
19178 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
19179 For concrete instances, we can get the parent die from the abstract
19181 for (node = limbo_die_list; node; node = next_node)
19183 next_node = node->next;
19186 if (die->die_parent == NULL)
19188 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
19191 add_child_die (origin->die_parent, die);
19192 else if (die == comp_unit_die)
19194 else if (errorcount > 0 || sorrycount > 0)
19195 /* It's OK to be confused by errors in the input. */
19196 add_child_die (comp_unit_die, die);
19199 /* In certain situations, the lexical block containing a
19200 nested function can be optimized away, which results
19201 in the nested function die being orphaned. Likewise
19202 with the return type of that nested function. Force
19203 this to be a child of the containing function.
19205 It may happen that even the containing function got fully
19206 inlined and optimized out. In that case we are lost and
19207 assign the empty child. This should not be big issue as
19208 the function is likely unreachable too. */
19209 tree context = NULL_TREE;
19211 gcc_assert (node->created_for);
19213 if (DECL_P (node->created_for))
19214 context = DECL_CONTEXT (node->created_for);
19215 else if (TYPE_P (node->created_for))
19216 context = TYPE_CONTEXT (node->created_for);
19218 gcc_assert (context
19219 && (TREE_CODE (context) == FUNCTION_DECL
19220 || TREE_CODE (context) == NAMESPACE_DECL));
19222 origin = lookup_decl_die (context);
19224 add_child_die (origin, die);
19226 add_child_die (comp_unit_die, die);
19231 limbo_die_list = NULL;
19233 resolve_addr (comp_unit_die);
19235 for (node = deferred_asm_name; node; node = node->next)
19237 tree decl = node->created_for;
19238 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
19240 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
19241 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
19242 move_linkage_attr (node->die);
19246 deferred_asm_name = NULL;
19248 /* Walk through the list of incomplete types again, trying once more to
19249 emit full debugging info for them. */
19250 retry_incomplete_types ();
19252 if (flag_eliminate_unused_debug_types)
19253 prune_unused_types ();
19255 /* Generate separate CUs for each of the include files we've seen.
19256 They will go into limbo_die_list. */
19257 if (flag_eliminate_dwarf2_dups)
19258 break_out_includes (comp_unit_die);
19260 /* Traverse the DIE's and add add sibling attributes to those DIE's
19261 that have children. */
19262 add_sibling_attributes (comp_unit_die);
19263 for (node = limbo_die_list; node; node = node->next)
19264 add_sibling_attributes (node->die);
19266 /* Output a terminator label for the .text section. */
19267 switch_to_section (text_section);
19268 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
19269 if (flag_reorder_blocks_and_partition)
19271 switch_to_section (unlikely_text_section ());
19272 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
19275 /* We can only use the low/high_pc attributes if all of the code was
19277 if (!have_multiple_function_sections
19278 || !(dwarf_version >= 3 || !dwarf_strict))
19280 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
19281 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
19286 unsigned fde_idx = 0;
19288 /* We need to give .debug_loc and .debug_ranges an appropriate
19289 "base address". Use zero so that these addresses become
19290 absolute. Historically, we've emitted the unexpected
19291 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
19292 Emit both to give time for other tools to adapt. */
19293 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
19294 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
19296 add_AT_range_list (comp_unit_die, DW_AT_ranges,
19297 add_ranges_by_labels (text_section_label,
19299 if (flag_reorder_blocks_and_partition)
19300 add_ranges_by_labels (cold_text_section_label,
19303 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
19305 dw_fde_ref fde = &fde_table[fde_idx];
19307 if (fde->dw_fde_switched_sections)
19309 if (!fde->in_std_section)
19310 add_ranges_by_labels (fde->dw_fde_hot_section_label,
19311 fde->dw_fde_hot_section_end_label);
19312 if (!fde->cold_in_std_section)
19313 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
19314 fde->dw_fde_unlikely_section_end_label);
19316 else if (!fde->in_std_section)
19317 add_ranges_by_labels (fde->dw_fde_begin,
19324 /* Output location list section if necessary. */
19325 if (have_location_lists)
19327 /* Output the location lists info. */
19328 switch_to_section (debug_loc_section);
19329 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
19330 DEBUG_LOC_SECTION_LABEL, 0);
19331 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
19332 output_location_lists (die);
19335 if (debug_info_level >= DINFO_LEVEL_NORMAL)
19336 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
19337 debug_line_section_label);
19339 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
19340 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
19342 /* Output all of the compilation units. We put the main one last so that
19343 the offsets are available to output_pubnames. */
19344 for (node = limbo_die_list; node; node = node->next)
19345 output_comp_unit (node->die, 0);
19347 /* Output the main compilation unit if non-empty or if .debug_macinfo
19348 has been emitted. */
19349 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
19351 /* Output the abbreviation table. */
19352 switch_to_section (debug_abbrev_section);
19353 output_abbrev_section ();
19355 /* Output public names table if necessary. */
19356 if (!VEC_empty (pubname_entry, pubname_table))
19358 switch_to_section (debug_pubnames_section);
19359 output_pubnames (pubname_table);
19362 /* Output public types table if necessary. */
19363 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
19364 It shouldn't hurt to emit it always, since pure DWARF2 consumers
19365 simply won't look for the section. */
19366 if (!VEC_empty (pubname_entry, pubtype_table))
19368 switch_to_section (debug_pubtypes_section);
19369 output_pubnames (pubtype_table);
19372 /* Output the address range information. We only put functions in the arange
19373 table, so don't write it out if we don't have any. */
19374 if (fde_table_in_use)
19376 switch_to_section (debug_aranges_section);
19380 /* Output ranges section if necessary. */
19381 if (ranges_table_in_use)
19383 switch_to_section (debug_ranges_section);
19384 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
19388 /* Output the source line correspondence table. We must do this
19389 even if there is no line information. Otherwise, on an empty
19390 translation unit, we will generate a present, but empty,
19391 .debug_info section. IRIX 6.5 `nm' will then complain when
19392 examining the file. This is done late so that any filenames
19393 used by the debug_info section are marked as 'used'. */
19394 if (! DWARF2_ASM_LINE_DEBUG_INFO)
19396 switch_to_section (debug_line_section);
19397 output_line_info ();
19400 /* Have to end the macro section. */
19401 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
19403 switch_to_section (debug_macinfo_section);
19404 dw2_asm_output_data (1, 0, "End compilation unit");
19407 /* If we emitted any DW_FORM_strp form attribute, output the string
19409 if (debug_str_hash)
19410 htab_traverse (debug_str_hash, output_indirect_string, NULL);
19414 /* This should never be used, but its address is needed for comparisons. */
19415 const struct gcc_debug_hooks dwarf2_debug_hooks =
19421 0, /* start_source_file */
19422 0, /* end_source_file */
19423 0, /* begin_block */
19425 0, /* ignore_block */
19426 0, /* source_line */
19427 0, /* begin_prologue */
19428 0, /* end_prologue */
19429 0, /* end_epilogue */
19430 0, /* begin_function */
19431 0, /* end_function */
19432 0, /* function_decl */
19433 0, /* global_decl */
19435 0, /* imported_module_or_decl */
19436 0, /* deferred_inline_function */
19437 0, /* outlining_inline_function */
19439 0, /* handle_pch */
19440 0, /* var_location */
19441 0, /* switch_text_section */
19443 0 /* start_end_main_source_file */
19446 #endif /* DWARF2_DEBUGGING_INFO */
19448 #include "gt-dwarf2out.h"