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 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
96 static rtx last_var_location_insn;
99 #ifdef VMS_DEBUGGING_INFO
100 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
102 /* Define this macro to be a nonzero value if the directory specifications
103 which are output in the debug info should end with a separator. */
104 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
105 /* Define this macro to evaluate to a nonzero value if GCC should refrain
106 from generating indirect strings in DWARF2 debug information, for instance
107 if your target is stuck with an old version of GDB that is unable to
108 process them properly or uses VMS Debug. */
109 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
115 #ifndef DWARF2_FRAME_INFO
116 # ifdef DWARF2_DEBUGGING_INFO
117 # define DWARF2_FRAME_INFO \
118 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
120 # define DWARF2_FRAME_INFO 0
124 /* Map register numbers held in the call frame info that gcc has
125 collected using DWARF_FRAME_REGNUM to those that should be output in
126 .debug_frame and .eh_frame. */
127 #ifndef DWARF2_FRAME_REG_OUT
128 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
131 /* Save the result of dwarf2out_do_frame across PCH. */
132 static GTY(()) bool saved_do_cfi_asm = 0;
134 /* Decide whether we want to emit frame unwind information for the current
138 dwarf2out_do_frame (void)
140 /* We want to emit correct CFA location expressions or lists, so we
141 have to return true if we're going to output debug info, even if
142 we're not going to output frame or unwind info. */
143 return (write_symbols == DWARF2_DEBUG
144 || write_symbols == VMS_AND_DWARF2_DEBUG
145 || DWARF2_FRAME_INFO || saved_do_cfi_asm
146 #ifdef DWARF2_UNWIND_INFO
147 || (DWARF2_UNWIND_INFO
148 && (flag_unwind_tables
149 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
154 /* Decide whether to emit frame unwind via assembler directives. */
157 dwarf2out_do_cfi_asm (void)
161 #ifdef MIPS_DEBUGGING_INFO
164 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
166 if (saved_do_cfi_asm || !eh_personality_libfunc)
168 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
171 /* Make sure the personality encoding is one the assembler can support.
172 In particular, aligned addresses can't be handled. */
173 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
174 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
176 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
177 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
180 saved_do_cfi_asm = true;
184 /* The size of the target's pointer type. */
186 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
189 /* Array of RTXes referenced by the debugging information, which therefore
190 must be kept around forever. */
191 static GTY(()) VEC(rtx,gc) *used_rtx_array;
193 /* A pointer to the base of a list of incomplete types which might be
194 completed at some later time. incomplete_types_list needs to be a
195 VEC(tree,gc) because we want to tell the garbage collector about
197 static GTY(()) VEC(tree,gc) *incomplete_types;
199 /* A pointer to the base of a table of references to declaration
200 scopes. This table is a display which tracks the nesting
201 of declaration scopes at the current scope and containing
202 scopes. This table is used to find the proper place to
203 define type declaration DIE's. */
204 static GTY(()) VEC(tree,gc) *decl_scope_table;
206 /* Pointers to various DWARF2 sections. */
207 static GTY(()) section *debug_info_section;
208 static GTY(()) section *debug_abbrev_section;
209 static GTY(()) section *debug_aranges_section;
210 static GTY(()) section *debug_macinfo_section;
211 static GTY(()) section *debug_line_section;
212 static GTY(()) section *debug_loc_section;
213 static GTY(()) section *debug_pubnames_section;
214 static GTY(()) section *debug_pubtypes_section;
215 static GTY(()) section *debug_str_section;
216 static GTY(()) section *debug_ranges_section;
217 static GTY(()) section *debug_frame_section;
219 /* How to start an assembler comment. */
220 #ifndef ASM_COMMENT_START
221 #define ASM_COMMENT_START ";#"
224 typedef struct dw_cfi_struct *dw_cfi_ref;
225 typedef struct dw_fde_struct *dw_fde_ref;
226 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
228 /* Call frames are described using a sequence of Call Frame
229 Information instructions. The register number, offset
230 and address fields are provided as possible operands;
231 their use is selected by the opcode field. */
233 enum dw_cfi_oprnd_type {
235 dw_cfi_oprnd_reg_num,
241 typedef union GTY(()) dw_cfi_oprnd_struct {
242 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
243 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
244 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
245 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
249 typedef struct GTY(()) dw_cfi_struct {
250 dw_cfi_ref dw_cfi_next;
251 enum dwarf_call_frame_info dw_cfi_opc;
252 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
254 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
259 /* This is how we define the location of the CFA. We use to handle it
260 as REG + OFFSET all the time, but now it can be more complex.
261 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
262 Instead of passing around REG and OFFSET, we pass a copy
263 of this structure. */
264 typedef struct GTY(()) cfa_loc {
265 HOST_WIDE_INT offset;
266 HOST_WIDE_INT base_offset;
268 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
269 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
272 /* All call frame descriptions (FDE's) in the GCC generated DWARF
273 refer to a single Common Information Entry (CIE), defined at
274 the beginning of the .debug_frame section. This use of a single
275 CIE obviates the need to keep track of multiple CIE's
276 in the DWARF generation routines below. */
278 typedef struct GTY(()) dw_fde_struct {
280 const char *dw_fde_begin;
281 const char *dw_fde_current_label;
282 const char *dw_fde_end;
283 const char *dw_fde_hot_section_label;
284 const char *dw_fde_hot_section_end_label;
285 const char *dw_fde_unlikely_section_label;
286 const char *dw_fde_unlikely_section_end_label;
287 dw_cfi_ref dw_fde_cfi;
288 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
289 unsigned funcdef_number;
290 HOST_WIDE_INT stack_realignment;
291 /* Dynamic realign argument pointer register. */
292 unsigned int drap_reg;
293 /* Virtual dynamic realign argument pointer register. */
294 unsigned int vdrap_reg;
295 unsigned all_throwers_are_sibcalls : 1;
296 unsigned nothrow : 1;
297 unsigned uses_eh_lsda : 1;
298 /* Whether we did stack realign in this call frame. */
299 unsigned stack_realign : 1;
300 /* Whether dynamic realign argument pointer register has been saved. */
301 unsigned drap_reg_saved: 1;
302 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
303 unsigned in_std_section : 1;
304 /* True iff dw_fde_unlikely_section_label is in text_section or
305 cold_text_section. */
306 unsigned cold_in_std_section : 1;
307 /* True iff switched sections. */
308 unsigned dw_fde_switched_sections : 1;
309 /* True iff switching from cold to hot section. */
310 unsigned dw_fde_switched_cold_to_hot : 1;
314 /* Maximum size (in bytes) of an artificially generated label. */
315 #define MAX_ARTIFICIAL_LABEL_BYTES 30
317 /* The size of addresses as they appear in the Dwarf 2 data.
318 Some architectures use word addresses to refer to code locations,
319 but Dwarf 2 info always uses byte addresses. On such machines,
320 Dwarf 2 addresses need to be larger than the architecture's
322 #ifndef DWARF2_ADDR_SIZE
323 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
326 /* The size in bytes of a DWARF field indicating an offset or length
327 relative to a debug info section, specified to be 4 bytes in the
328 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
331 #ifndef DWARF_OFFSET_SIZE
332 #define DWARF_OFFSET_SIZE 4
335 /* According to the (draft) DWARF 3 specification, the initial length
336 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
337 bytes are 0xffffffff, followed by the length stored in the next 8
340 However, the SGI/MIPS ABI uses an initial length which is equal to
341 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
343 #ifndef DWARF_INITIAL_LENGTH_SIZE
344 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
347 /* Round SIZE up to the nearest BOUNDARY. */
348 #define DWARF_ROUND(SIZE,BOUNDARY) \
349 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
351 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
352 #ifndef DWARF_CIE_DATA_ALIGNMENT
353 #ifdef STACK_GROWS_DOWNWARD
354 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
356 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
360 /* CIE identifier. */
361 #if HOST_BITS_PER_WIDE_INT >= 64
362 #define DWARF_CIE_ID \
363 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
365 #define DWARF_CIE_ID DW_CIE_ID
368 /* A pointer to the base of a table that contains frame description
369 information for each routine. */
370 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
372 /* Number of elements currently allocated for fde_table. */
373 static GTY(()) unsigned fde_table_allocated;
375 /* Number of elements in fde_table currently in use. */
376 static GTY(()) unsigned fde_table_in_use;
378 /* Size (in elements) of increments by which we may expand the
380 #define FDE_TABLE_INCREMENT 256
382 /* Get the current fde_table entry we should use. */
384 static inline dw_fde_ref
387 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
390 /* A list of call frame insns for the CIE. */
391 static GTY(()) dw_cfi_ref cie_cfi_head;
393 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
394 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
395 attribute that accelerates the lookup of the FDE associated
396 with the subprogram. This variable holds the table index of the FDE
397 associated with the current function (body) definition. */
398 static unsigned current_funcdef_fde;
401 struct GTY(()) indirect_string_node {
403 unsigned int refcount;
404 enum dwarf_form form;
408 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
410 static GTY(()) int dw2_string_counter;
411 static GTY(()) unsigned long dwarf2out_cfi_label_num;
413 /* True if the compilation unit places functions in more than one section. */
414 static GTY(()) bool have_multiple_function_sections = false;
416 /* Whether the default text and cold text sections have been used at all. */
418 static GTY(()) bool text_section_used = false;
419 static GTY(()) bool cold_text_section_used = false;
421 /* The default cold text section. */
422 static GTY(()) section *cold_text_section;
424 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
426 /* Forward declarations for functions defined in this file. */
428 static char *stripattributes (const char *);
429 static const char *dwarf_cfi_name (unsigned);
430 static dw_cfi_ref new_cfi (void);
431 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
432 static void add_fde_cfi (const char *, dw_cfi_ref);
433 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
434 static void lookup_cfa (dw_cfa_location *);
435 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
436 #ifdef DWARF2_UNWIND_INFO
437 static void initial_return_save (rtx);
439 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
441 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
442 static void output_cfi_directive (dw_cfi_ref);
443 static void output_call_frame_info (int);
444 static void dwarf2out_note_section_used (void);
445 static void dwarf2out_stack_adjust (rtx, bool);
446 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
447 static void flush_queued_reg_saves (void);
448 static bool clobbers_queued_reg_save (const_rtx);
449 static void dwarf2out_frame_debug_expr (rtx, const char *);
451 /* Support for complex CFA locations. */
452 static void output_cfa_loc (dw_cfi_ref);
453 static void output_cfa_loc_raw (dw_cfi_ref);
454 static void get_cfa_from_loc_descr (dw_cfa_location *,
455 struct dw_loc_descr_struct *);
456 static struct dw_loc_descr_struct *build_cfa_loc
457 (dw_cfa_location *, HOST_WIDE_INT);
458 static struct dw_loc_descr_struct *build_cfa_aligned_loc
459 (HOST_WIDE_INT, HOST_WIDE_INT);
460 static void def_cfa_1 (const char *, dw_cfa_location *);
462 /* How to start an assembler comment. */
463 #ifndef ASM_COMMENT_START
464 #define ASM_COMMENT_START ";#"
467 /* Data and reference forms for relocatable data. */
468 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
469 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
471 #ifndef DEBUG_FRAME_SECTION
472 #define DEBUG_FRAME_SECTION ".debug_frame"
475 #ifndef FUNC_BEGIN_LABEL
476 #define FUNC_BEGIN_LABEL "LFB"
479 #ifndef FUNC_END_LABEL
480 #define FUNC_END_LABEL "LFE"
483 #ifndef FRAME_BEGIN_LABEL
484 #define FRAME_BEGIN_LABEL "Lframe"
486 #define CIE_AFTER_SIZE_LABEL "LSCIE"
487 #define CIE_END_LABEL "LECIE"
488 #define FDE_LABEL "LSFDE"
489 #define FDE_AFTER_SIZE_LABEL "LASFDE"
490 #define FDE_END_LABEL "LEFDE"
491 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
492 #define LINE_NUMBER_END_LABEL "LELT"
493 #define LN_PROLOG_AS_LABEL "LASLTP"
494 #define LN_PROLOG_END_LABEL "LELTP"
495 #define DIE_LABEL_PREFIX "DW"
497 /* The DWARF 2 CFA column which tracks the return address. Normally this
498 is the column for PC, or the first column after all of the hard
500 #ifndef DWARF_FRAME_RETURN_COLUMN
502 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
504 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
508 /* The mapping from gcc register number to DWARF 2 CFA column number. By
509 default, we just provide columns for all registers. */
510 #ifndef DWARF_FRAME_REGNUM
511 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
514 /* Hook used by __throw. */
517 expand_builtin_dwarf_sp_column (void)
519 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
520 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
523 /* Return a pointer to a copy of the section string name S with all
524 attributes stripped off, and an asterisk prepended (for assemble_name). */
527 stripattributes (const char *s)
529 char *stripped = XNEWVEC (char, strlen (s) + 2);
534 while (*s && *s != ',')
541 /* MEM is a memory reference for the register size table, each element of
542 which has mode MODE. Initialize column C as a return address column. */
545 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
547 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
548 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
549 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
552 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
554 static inline HOST_WIDE_INT
555 div_data_align (HOST_WIDE_INT off)
557 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
558 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
562 /* Return true if we need a signed version of a given opcode
563 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
566 need_data_align_sf_opcode (HOST_WIDE_INT off)
568 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
571 /* Generate code to initialize the register size table. */
574 expand_builtin_init_dwarf_reg_sizes (tree address)
577 enum machine_mode mode = TYPE_MODE (char_type_node);
578 rtx addr = expand_normal (address);
579 rtx mem = gen_rtx_MEM (BLKmode, addr);
580 bool wrote_return_column = false;
582 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
584 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
586 if (rnum < DWARF_FRAME_REGISTERS)
588 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
589 enum machine_mode save_mode = reg_raw_mode[i];
592 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
593 save_mode = choose_hard_reg_mode (i, 1, true);
594 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
596 if (save_mode == VOIDmode)
598 wrote_return_column = true;
600 size = GET_MODE_SIZE (save_mode);
604 emit_move_insn (adjust_address (mem, mode, offset),
605 gen_int_mode (size, mode));
609 if (!wrote_return_column)
610 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
612 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
613 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
616 targetm.init_dwarf_reg_sizes_extra (address);
619 /* Convert a DWARF call frame info. operation to its string name */
622 dwarf_cfi_name (unsigned int cfi_opc)
626 case DW_CFA_advance_loc:
627 return "DW_CFA_advance_loc";
629 return "DW_CFA_offset";
631 return "DW_CFA_restore";
635 return "DW_CFA_set_loc";
636 case DW_CFA_advance_loc1:
637 return "DW_CFA_advance_loc1";
638 case DW_CFA_advance_loc2:
639 return "DW_CFA_advance_loc2";
640 case DW_CFA_advance_loc4:
641 return "DW_CFA_advance_loc4";
642 case DW_CFA_offset_extended:
643 return "DW_CFA_offset_extended";
644 case DW_CFA_restore_extended:
645 return "DW_CFA_restore_extended";
646 case DW_CFA_undefined:
647 return "DW_CFA_undefined";
648 case DW_CFA_same_value:
649 return "DW_CFA_same_value";
650 case DW_CFA_register:
651 return "DW_CFA_register";
652 case DW_CFA_remember_state:
653 return "DW_CFA_remember_state";
654 case DW_CFA_restore_state:
655 return "DW_CFA_restore_state";
657 return "DW_CFA_def_cfa";
658 case DW_CFA_def_cfa_register:
659 return "DW_CFA_def_cfa_register";
660 case DW_CFA_def_cfa_offset:
661 return "DW_CFA_def_cfa_offset";
664 case DW_CFA_def_cfa_expression:
665 return "DW_CFA_def_cfa_expression";
666 case DW_CFA_expression:
667 return "DW_CFA_expression";
668 case DW_CFA_offset_extended_sf:
669 return "DW_CFA_offset_extended_sf";
670 case DW_CFA_def_cfa_sf:
671 return "DW_CFA_def_cfa_sf";
672 case DW_CFA_def_cfa_offset_sf:
673 return "DW_CFA_def_cfa_offset_sf";
675 /* SGI/MIPS specific */
676 case DW_CFA_MIPS_advance_loc8:
677 return "DW_CFA_MIPS_advance_loc8";
680 case DW_CFA_GNU_window_save:
681 return "DW_CFA_GNU_window_save";
682 case DW_CFA_GNU_args_size:
683 return "DW_CFA_GNU_args_size";
684 case DW_CFA_GNU_negative_offset_extended:
685 return "DW_CFA_GNU_negative_offset_extended";
688 return "DW_CFA_<unknown>";
692 /* Return a pointer to a newly allocated Call Frame Instruction. */
694 static inline dw_cfi_ref
697 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
699 cfi->dw_cfi_next = NULL;
700 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
701 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
706 /* Add a Call Frame Instruction to list of instructions. */
709 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
712 dw_fde_ref fde = current_fde ();
714 /* When DRAP is used, CFA is defined with an expression. Redefine
715 CFA may lead to a different CFA value. */
716 /* ??? Of course, this heuristic fails when we're annotating epilogues,
717 because of course we'll always want to redefine the CFA back to the
718 stack pointer on the way out. Where should we move this check? */
719 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
720 switch (cfi->dw_cfi_opc)
722 case DW_CFA_def_cfa_register:
723 case DW_CFA_def_cfa_offset:
724 case DW_CFA_def_cfa_offset_sf:
726 case DW_CFA_def_cfa_sf:
733 /* Find the end of the chain. */
734 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
740 /* Generate a new label for the CFI info to refer to. FORCE is true
741 if a label needs to be output even when using .cfi_* directives. */
744 dwarf2out_cfi_label (bool force)
746 static char label[20];
748 if (!force && dwarf2out_do_cfi_asm ())
750 /* In this case, we will be emitting the asm directive instead of
751 the label, so just return a placeholder to keep the rest of the
753 strcpy (label, "<do not output>");
757 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
758 ASM_OUTPUT_LABEL (asm_out_file, label);
764 /* True if remember_state should be emitted before following CFI directive. */
765 static bool emit_cfa_remember;
767 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
768 or to the CIE if LABEL is NULL. */
771 add_fde_cfi (const char *label, dw_cfi_ref cfi)
773 dw_cfi_ref *list_head;
775 if (emit_cfa_remember)
777 dw_cfi_ref cfi_remember;
779 /* Emit the state save. */
780 emit_cfa_remember = false;
781 cfi_remember = new_cfi ();
782 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
783 add_fde_cfi (label, cfi_remember);
786 list_head = &cie_cfi_head;
788 if (dwarf2out_do_cfi_asm ())
792 dw_fde_ref fde = current_fde ();
794 gcc_assert (fde != NULL);
796 /* We still have to add the cfi to the list so that lookup_cfa
797 works later on. When -g2 and above we even need to force
798 emitting of CFI labels and add to list a DW_CFA_set_loc for
799 convert_cfa_to_fb_loc_list purposes. If we're generating
800 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
801 convert_cfa_to_fb_loc_list. */
802 if (dwarf_version == 2
803 && debug_info_level > DINFO_LEVEL_TERSE
804 && (write_symbols == DWARF2_DEBUG
805 || write_symbols == VMS_AND_DWARF2_DEBUG))
807 switch (cfi->dw_cfi_opc)
809 case DW_CFA_def_cfa_offset:
810 case DW_CFA_def_cfa_offset_sf:
811 case DW_CFA_def_cfa_register:
813 case DW_CFA_def_cfa_sf:
814 case DW_CFA_def_cfa_expression:
815 case DW_CFA_restore_state:
816 if (*label == 0 || strcmp (label, "<do not output>") == 0)
817 label = dwarf2out_cfi_label (true);
819 if (fde->dw_fde_current_label == NULL
820 || strcmp (label, fde->dw_fde_current_label) != 0)
824 label = xstrdup (label);
826 /* Set the location counter to the new label. */
828 /* It doesn't metter whether DW_CFA_set_loc
829 or DW_CFA_advance_loc4 is added here, those aren't
830 emitted into assembly, only looked up by
831 convert_cfa_to_fb_loc_list. */
832 xcfi->dw_cfi_opc = DW_CFA_set_loc;
833 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
834 add_cfi (&fde->dw_fde_cfi, xcfi);
835 fde->dw_fde_current_label = label;
843 output_cfi_directive (cfi);
845 list_head = &fde->dw_fde_cfi;
847 /* ??? If this is a CFI for the CIE, we don't emit. This
848 assumes that the standard CIE contents that the assembler
849 uses matches the standard CIE contents that the compiler
850 uses. This is probably a bad assumption. I'm not quite
851 sure how to address this for now. */
855 dw_fde_ref fde = current_fde ();
857 gcc_assert (fde != NULL);
860 label = dwarf2out_cfi_label (false);
862 if (fde->dw_fde_current_label == NULL
863 || strcmp (label, fde->dw_fde_current_label) != 0)
867 label = xstrdup (label);
869 /* Set the location counter to the new label. */
871 /* If we have a current label, advance from there, otherwise
872 set the location directly using set_loc. */
873 xcfi->dw_cfi_opc = fde->dw_fde_current_label
874 ? DW_CFA_advance_loc4
876 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
877 add_cfi (&fde->dw_fde_cfi, xcfi);
879 fde->dw_fde_current_label = label;
882 list_head = &fde->dw_fde_cfi;
885 add_cfi (list_head, cfi);
888 /* Subroutine of lookup_cfa. */
891 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
893 switch (cfi->dw_cfi_opc)
895 case DW_CFA_def_cfa_offset:
896 case DW_CFA_def_cfa_offset_sf:
897 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
899 case DW_CFA_def_cfa_register:
900 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
903 case DW_CFA_def_cfa_sf:
904 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
905 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
907 case DW_CFA_def_cfa_expression:
908 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
911 case DW_CFA_remember_state:
912 gcc_assert (!remember->in_use);
914 remember->in_use = 1;
916 case DW_CFA_restore_state:
917 gcc_assert (remember->in_use);
919 remember->in_use = 0;
927 /* Find the previous value for the CFA. */
930 lookup_cfa (dw_cfa_location *loc)
934 dw_cfa_location remember;
936 memset (loc, 0, sizeof (*loc));
937 loc->reg = INVALID_REGNUM;
940 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
941 lookup_cfa_1 (cfi, loc, &remember);
943 fde = current_fde ();
945 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
946 lookup_cfa_1 (cfi, loc, &remember);
949 /* The current rule for calculating the DWARF2 canonical frame address. */
950 static dw_cfa_location cfa;
952 /* The register used for saving registers to the stack, and its offset
954 static dw_cfa_location cfa_store;
956 /* The current save location around an epilogue. */
957 static dw_cfa_location cfa_remember;
959 /* The running total of the size of arguments pushed onto the stack. */
960 static HOST_WIDE_INT args_size;
962 /* The last args_size we actually output. */
963 static HOST_WIDE_INT old_args_size;
965 /* Entry point to update the canonical frame address (CFA).
966 LABEL is passed to add_fde_cfi. The value of CFA is now to be
967 calculated from REG+OFFSET. */
970 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
977 def_cfa_1 (label, &loc);
980 /* Determine if two dw_cfa_location structures define the same data. */
983 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
985 return (loc1->reg == loc2->reg
986 && loc1->offset == loc2->offset
987 && loc1->indirect == loc2->indirect
988 && (loc1->indirect == 0
989 || loc1->base_offset == loc2->base_offset));
992 /* This routine does the actual work. The CFA is now calculated from
993 the dw_cfa_location structure. */
996 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
999 dw_cfa_location old_cfa, loc;
1004 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1005 cfa_store.offset = loc.offset;
1007 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1008 lookup_cfa (&old_cfa);
1010 /* If nothing changed, no need to issue any call frame instructions. */
1011 if (cfa_equal_p (&loc, &old_cfa))
1016 if (loc.reg == old_cfa.reg && !loc.indirect)
1018 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1019 the CFA register did not change but the offset did. The data
1020 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1021 in the assembler via the .cfi_def_cfa_offset directive. */
1023 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1025 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1026 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1029 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1030 else if (loc.offset == old_cfa.offset
1031 && old_cfa.reg != INVALID_REGNUM
1034 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1035 indicating the CFA register has changed to <register> but the
1036 offset has not changed. */
1037 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1038 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1042 else if (loc.indirect == 0)
1044 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1045 indicating the CFA register has changed to <register> with
1046 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1047 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1050 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1052 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1053 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1054 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1058 /* Construct a DW_CFA_def_cfa_expression instruction to
1059 calculate the CFA using a full location expression since no
1060 register-offset pair is available. */
1061 struct dw_loc_descr_struct *loc_list;
1063 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1064 loc_list = build_cfa_loc (&loc, 0);
1065 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1068 add_fde_cfi (label, cfi);
1071 /* Add the CFI for saving a register. REG is the CFA column number.
1072 LABEL is passed to add_fde_cfi.
1073 If SREG is -1, the register is saved at OFFSET from the CFA;
1074 otherwise it is saved in SREG. */
1077 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1079 dw_cfi_ref cfi = new_cfi ();
1080 dw_fde_ref fde = current_fde ();
1082 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1084 /* When stack is aligned, store REG using DW_CFA_expression with
1087 && fde->stack_realign
1088 && sreg == INVALID_REGNUM)
1090 cfi->dw_cfi_opc = DW_CFA_expression;
1091 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1092 cfi->dw_cfi_oprnd1.dw_cfi_loc
1093 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1095 else if (sreg == INVALID_REGNUM)
1097 if (need_data_align_sf_opcode (offset))
1098 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1099 else if (reg & ~0x3f)
1100 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1102 cfi->dw_cfi_opc = DW_CFA_offset;
1103 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1105 else if (sreg == reg)
1106 cfi->dw_cfi_opc = DW_CFA_same_value;
1109 cfi->dw_cfi_opc = DW_CFA_register;
1110 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1113 add_fde_cfi (label, cfi);
1116 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1117 This CFI tells the unwinder that it needs to restore the window registers
1118 from the previous frame's window save area.
1120 ??? Perhaps we should note in the CIE where windows are saved (instead of
1121 assuming 0(cfa)) and what registers are in the window. */
1124 dwarf2out_window_save (const char *label)
1126 dw_cfi_ref cfi = new_cfi ();
1128 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1129 add_fde_cfi (label, cfi);
1132 /* Add a CFI to update the running total of the size of arguments
1133 pushed onto the stack. */
1136 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1140 if (size == old_args_size)
1143 old_args_size = size;
1146 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1147 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1148 add_fde_cfi (label, cfi);
1151 /* Entry point for saving a register to the stack. REG is the GCC register
1152 number. LABEL and OFFSET are passed to reg_save. */
1155 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1157 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1160 /* Entry point for saving the return address in the stack.
1161 LABEL and OFFSET are passed to reg_save. */
1164 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1166 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1169 /* Entry point for saving the return address in a register.
1170 LABEL and SREG are passed to reg_save. */
1173 dwarf2out_return_reg (const char *label, unsigned int sreg)
1175 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1178 #ifdef DWARF2_UNWIND_INFO
1179 /* Record the initial position of the return address. RTL is
1180 INCOMING_RETURN_ADDR_RTX. */
1183 initial_return_save (rtx rtl)
1185 unsigned int reg = INVALID_REGNUM;
1186 HOST_WIDE_INT offset = 0;
1188 switch (GET_CODE (rtl))
1191 /* RA is in a register. */
1192 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1196 /* RA is on the stack. */
1197 rtl = XEXP (rtl, 0);
1198 switch (GET_CODE (rtl))
1201 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1206 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1207 offset = INTVAL (XEXP (rtl, 1));
1211 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1212 offset = -INTVAL (XEXP (rtl, 1));
1222 /* The return address is at some offset from any value we can
1223 actually load. For instance, on the SPARC it is in %i7+8. Just
1224 ignore the offset for now; it doesn't matter for unwinding frames. */
1225 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1226 initial_return_save (XEXP (rtl, 0));
1233 if (reg != DWARF_FRAME_RETURN_COLUMN)
1234 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1238 /* Given a SET, calculate the amount of stack adjustment it
1241 static HOST_WIDE_INT
1242 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1243 HOST_WIDE_INT cur_offset)
1245 const_rtx src = SET_SRC (pattern);
1246 const_rtx dest = SET_DEST (pattern);
1247 HOST_WIDE_INT offset = 0;
1250 if (dest == stack_pointer_rtx)
1252 code = GET_CODE (src);
1254 /* Assume (set (reg sp) (reg whatever)) sets args_size
1256 if (code == REG && src != stack_pointer_rtx)
1258 offset = -cur_args_size;
1259 #ifndef STACK_GROWS_DOWNWARD
1262 return offset - cur_offset;
1265 if (! (code == PLUS || code == MINUS)
1266 || XEXP (src, 0) != stack_pointer_rtx
1267 || !CONST_INT_P (XEXP (src, 1)))
1270 /* (set (reg sp) (plus (reg sp) (const_int))) */
1271 offset = INTVAL (XEXP (src, 1));
1277 if (MEM_P (src) && !MEM_P (dest))
1281 /* (set (mem (pre_dec (reg sp))) (foo)) */
1282 src = XEXP (dest, 0);
1283 code = GET_CODE (src);
1289 if (XEXP (src, 0) == stack_pointer_rtx)
1291 rtx val = XEXP (XEXP (src, 1), 1);
1292 /* We handle only adjustments by constant amount. */
1293 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1294 && CONST_INT_P (val));
1295 offset = -INTVAL (val);
1302 if (XEXP (src, 0) == stack_pointer_rtx)
1304 offset = GET_MODE_SIZE (GET_MODE (dest));
1311 if (XEXP (src, 0) == stack_pointer_rtx)
1313 offset = -GET_MODE_SIZE (GET_MODE (dest));
1328 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1329 indexed by INSN_UID. */
1331 static HOST_WIDE_INT *barrier_args_size;
1333 /* Helper function for compute_barrier_args_size. Handle one insn. */
1335 static HOST_WIDE_INT
1336 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1337 VEC (rtx, heap) **next)
1339 HOST_WIDE_INT offset = 0;
1342 if (! RTX_FRAME_RELATED_P (insn))
1344 if (prologue_epilogue_contains (insn))
1346 else if (GET_CODE (PATTERN (insn)) == SET)
1347 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1348 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1349 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1351 /* There may be stack adjustments inside compound insns. Search
1353 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1354 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1355 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1356 cur_args_size, offset);
1361 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1365 expr = XEXP (expr, 0);
1366 if (GET_CODE (expr) == PARALLEL
1367 || GET_CODE (expr) == SEQUENCE)
1368 for (i = 1; i < XVECLEN (expr, 0); i++)
1370 rtx elem = XVECEXP (expr, 0, i);
1372 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1373 offset += stack_adjust_offset (elem, cur_args_size, offset);
1378 #ifndef STACK_GROWS_DOWNWARD
1382 cur_args_size += offset;
1383 if (cur_args_size < 0)
1388 rtx dest = JUMP_LABEL (insn);
1392 if (barrier_args_size [INSN_UID (dest)] < 0)
1394 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1395 VEC_safe_push (rtx, heap, *next, dest);
1400 return cur_args_size;
1403 /* Walk the whole function and compute args_size on BARRIERs. */
1406 compute_barrier_args_size (void)
1408 int max_uid = get_max_uid (), i;
1410 VEC (rtx, heap) *worklist, *next, *tmp;
1412 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1413 for (i = 0; i < max_uid; i++)
1414 barrier_args_size[i] = -1;
1416 worklist = VEC_alloc (rtx, heap, 20);
1417 next = VEC_alloc (rtx, heap, 20);
1418 insn = get_insns ();
1419 barrier_args_size[INSN_UID (insn)] = 0;
1420 VEC_quick_push (rtx, worklist, insn);
1423 while (!VEC_empty (rtx, worklist))
1425 rtx prev, body, first_insn;
1426 HOST_WIDE_INT cur_args_size;
1428 first_insn = insn = VEC_pop (rtx, worklist);
1429 cur_args_size = barrier_args_size[INSN_UID (insn)];
1430 prev = prev_nonnote_insn (insn);
1431 if (prev && BARRIER_P (prev))
1432 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1434 for (; insn; insn = NEXT_INSN (insn))
1436 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1438 if (BARRIER_P (insn))
1443 if (insn == first_insn)
1445 else if (barrier_args_size[INSN_UID (insn)] < 0)
1447 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1452 /* The insns starting with this label have been
1453 already scanned or are in the worklist. */
1458 body = PATTERN (insn);
1459 if (GET_CODE (body) == SEQUENCE)
1461 HOST_WIDE_INT dest_args_size = cur_args_size;
1462 for (i = 1; i < XVECLEN (body, 0); i++)
1463 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1464 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1466 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1467 dest_args_size, &next);
1470 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1471 cur_args_size, &next);
1473 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1474 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1475 dest_args_size, &next);
1478 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1479 cur_args_size, &next);
1483 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1487 if (VEC_empty (rtx, next))
1490 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1494 VEC_truncate (rtx, next, 0);
1497 VEC_free (rtx, heap, worklist);
1498 VEC_free (rtx, heap, next);
1502 /* Check INSN to see if it looks like a push or a stack adjustment, and
1503 make a note of it if it does. EH uses this information to find out how
1504 much extra space it needs to pop off the stack. */
1507 dwarf2out_stack_adjust (rtx insn, bool after_p)
1509 HOST_WIDE_INT offset;
1513 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1514 with this function. Proper support would require all frame-related
1515 insns to be marked, and to be able to handle saving state around
1516 epilogues textually in the middle of the function. */
1517 if (prologue_epilogue_contains (insn))
1520 /* If INSN is an instruction from target of an annulled branch, the
1521 effects are for the target only and so current argument size
1522 shouldn't change at all. */
1524 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1525 && INSN_FROM_TARGET_P (insn))
1528 /* If only calls can throw, and we have a frame pointer,
1529 save up adjustments until we see the CALL_INSN. */
1530 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1532 if (CALL_P (insn) && !after_p)
1534 /* Extract the size of the args from the CALL rtx itself. */
1535 insn = PATTERN (insn);
1536 if (GET_CODE (insn) == PARALLEL)
1537 insn = XVECEXP (insn, 0, 0);
1538 if (GET_CODE (insn) == SET)
1539 insn = SET_SRC (insn);
1540 gcc_assert (GET_CODE (insn) == CALL);
1541 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1546 if (CALL_P (insn) && !after_p)
1548 if (!flag_asynchronous_unwind_tables)
1549 dwarf2out_args_size ("", args_size);
1552 else if (BARRIER_P (insn))
1554 /* Don't call compute_barrier_args_size () if the only
1555 BARRIER is at the end of function. */
1556 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1557 compute_barrier_args_size ();
1558 if (barrier_args_size == NULL)
1562 offset = barrier_args_size[INSN_UID (insn)];
1567 offset -= args_size;
1568 #ifndef STACK_GROWS_DOWNWARD
1572 else if (GET_CODE (PATTERN (insn)) == SET)
1573 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1574 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1575 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1577 /* There may be stack adjustments inside compound insns. Search
1579 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1580 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1581 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1590 label = dwarf2out_cfi_label (false);
1591 dwarf2out_args_size_adjust (offset, label);
1594 /* Adjust args_size based on stack adjustment OFFSET. */
1597 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1599 if (cfa.reg == STACK_POINTER_REGNUM)
1600 cfa.offset += offset;
1602 if (cfa_store.reg == STACK_POINTER_REGNUM)
1603 cfa_store.offset += offset;
1605 #ifndef STACK_GROWS_DOWNWARD
1609 args_size += offset;
1613 def_cfa_1 (label, &cfa);
1614 if (flag_asynchronous_unwind_tables)
1615 dwarf2out_args_size (label, args_size);
1620 /* We delay emitting a register save until either (a) we reach the end
1621 of the prologue or (b) the register is clobbered. This clusters
1622 register saves so that there are fewer pc advances. */
1624 struct GTY(()) queued_reg_save {
1625 struct queued_reg_save *next;
1627 HOST_WIDE_INT cfa_offset;
1631 static GTY(()) struct queued_reg_save *queued_reg_saves;
1633 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1634 struct GTY(()) reg_saved_in_data {
1639 /* A list of registers saved in other registers.
1640 The list intentionally has a small maximum capacity of 4; if your
1641 port needs more than that, you might consider implementing a
1642 more efficient data structure. */
1643 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1644 static GTY(()) size_t num_regs_saved_in_regs;
1646 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1647 static const char *last_reg_save_label;
1649 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1650 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1653 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1655 struct queued_reg_save *q;
1657 /* Duplicates waste space, but it's also necessary to remove them
1658 for correctness, since the queue gets output in reverse
1660 for (q = queued_reg_saves; q != NULL; q = q->next)
1661 if (REGNO (q->reg) == REGNO (reg))
1666 q = GGC_NEW (struct queued_reg_save);
1667 q->next = queued_reg_saves;
1668 queued_reg_saves = q;
1672 q->cfa_offset = offset;
1673 q->saved_reg = sreg;
1675 last_reg_save_label = label;
1678 /* Output all the entries in QUEUED_REG_SAVES. */
1681 flush_queued_reg_saves (void)
1683 struct queued_reg_save *q;
1685 for (q = queued_reg_saves; q; q = q->next)
1688 unsigned int reg, sreg;
1690 for (i = 0; i < num_regs_saved_in_regs; i++)
1691 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1693 if (q->saved_reg && i == num_regs_saved_in_regs)
1695 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1696 num_regs_saved_in_regs++;
1698 if (i != num_regs_saved_in_regs)
1700 regs_saved_in_regs[i].orig_reg = q->reg;
1701 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1704 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1706 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1708 sreg = INVALID_REGNUM;
1709 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1712 queued_reg_saves = NULL;
1713 last_reg_save_label = NULL;
1716 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1717 location for? Or, does it clobber a register which we've previously
1718 said that some other register is saved in, and for which we now
1719 have a new location for? */
1722 clobbers_queued_reg_save (const_rtx insn)
1724 struct queued_reg_save *q;
1726 for (q = queued_reg_saves; q; q = q->next)
1729 if (modified_in_p (q->reg, insn))
1731 for (i = 0; i < num_regs_saved_in_regs; i++)
1732 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1733 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1740 /* Entry point for saving the first register into the second. */
1743 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1746 unsigned int regno, sregno;
1748 for (i = 0; i < num_regs_saved_in_regs; i++)
1749 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1751 if (i == num_regs_saved_in_regs)
1753 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1754 num_regs_saved_in_regs++;
1756 regs_saved_in_regs[i].orig_reg = reg;
1757 regs_saved_in_regs[i].saved_in_reg = sreg;
1759 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1760 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1761 reg_save (label, regno, sregno, 0);
1764 /* What register, if any, is currently saved in REG? */
1767 reg_saved_in (rtx reg)
1769 unsigned int regn = REGNO (reg);
1771 struct queued_reg_save *q;
1773 for (q = queued_reg_saves; q; q = q->next)
1774 if (q->saved_reg && regn == REGNO (q->saved_reg))
1777 for (i = 0; i < num_regs_saved_in_regs; i++)
1778 if (regs_saved_in_regs[i].saved_in_reg
1779 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1780 return regs_saved_in_regs[i].orig_reg;
1786 /* A temporary register holding an integral value used in adjusting SP
1787 or setting up the store_reg. The "offset" field holds the integer
1788 value, not an offset. */
1789 static dw_cfa_location cfa_temp;
1791 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1794 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1796 memset (&cfa, 0, sizeof (cfa));
1798 switch (GET_CODE (pat))
1801 cfa.reg = REGNO (XEXP (pat, 0));
1802 cfa.offset = INTVAL (XEXP (pat, 1));
1806 cfa.reg = REGNO (pat);
1810 /* Recurse and define an expression. */
1814 def_cfa_1 (label, &cfa);
1817 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1820 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1824 gcc_assert (GET_CODE (pat) == SET);
1825 dest = XEXP (pat, 0);
1826 src = XEXP (pat, 1);
1828 switch (GET_CODE (src))
1831 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1832 cfa.offset -= INTVAL (XEXP (src, 1));
1842 cfa.reg = REGNO (dest);
1843 gcc_assert (cfa.indirect == 0);
1845 def_cfa_1 (label, &cfa);
1848 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1851 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1853 HOST_WIDE_INT offset;
1854 rtx src, addr, span;
1856 src = XEXP (set, 1);
1857 addr = XEXP (set, 0);
1858 gcc_assert (MEM_P (addr));
1859 addr = XEXP (addr, 0);
1861 /* As documented, only consider extremely simple addresses. */
1862 switch (GET_CODE (addr))
1865 gcc_assert (REGNO (addr) == cfa.reg);
1866 offset = -cfa.offset;
1869 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1870 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1876 span = targetm.dwarf_register_span (src);
1878 /* ??? We'd like to use queue_reg_save, but we need to come up with
1879 a different flushing heuristic for epilogues. */
1881 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1884 /* We have a PARALLEL describing where the contents of SRC live.
1885 Queue register saves for each piece of the PARALLEL. */
1888 HOST_WIDE_INT span_offset = offset;
1890 gcc_assert (GET_CODE (span) == PARALLEL);
1892 limit = XVECLEN (span, 0);
1893 for (par_index = 0; par_index < limit; par_index++)
1895 rtx elem = XVECEXP (span, 0, par_index);
1897 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1898 INVALID_REGNUM, span_offset);
1899 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1904 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1907 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1910 unsigned sregno, dregno;
1912 src = XEXP (set, 1);
1913 dest = XEXP (set, 0);
1916 sregno = DWARF_FRAME_RETURN_COLUMN;
1918 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1920 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1922 /* ??? We'd like to use queue_reg_save, but we need to come up with
1923 a different flushing heuristic for epilogues. */
1924 reg_save (label, sregno, dregno, 0);
1927 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1930 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1932 dw_cfi_ref cfi = new_cfi ();
1933 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1935 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1936 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1938 add_fde_cfi (label, cfi);
1941 /* Record call frame debugging information for an expression EXPR,
1942 which either sets SP or FP (adjusting how we calculate the frame
1943 address) or saves a register to the stack or another register.
1944 LABEL indicates the address of EXPR.
1946 This function encodes a state machine mapping rtxes to actions on
1947 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1948 users need not read the source code.
1950 The High-Level Picture
1952 Changes in the register we use to calculate the CFA: Currently we
1953 assume that if you copy the CFA register into another register, we
1954 should take the other one as the new CFA register; this seems to
1955 work pretty well. If it's wrong for some target, it's simple
1956 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1958 Changes in the register we use for saving registers to the stack:
1959 This is usually SP, but not always. Again, we deduce that if you
1960 copy SP into another register (and SP is not the CFA register),
1961 then the new register is the one we will be using for register
1962 saves. This also seems to work.
1964 Register saves: There's not much guesswork about this one; if
1965 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1966 register save, and the register used to calculate the destination
1967 had better be the one we think we're using for this purpose.
1968 It's also assumed that a copy from a call-saved register to another
1969 register is saving that register if RTX_FRAME_RELATED_P is set on
1970 that instruction. If the copy is from a call-saved register to
1971 the *same* register, that means that the register is now the same
1972 value as in the caller.
1974 Except: If the register being saved is the CFA register, and the
1975 offset is nonzero, we are saving the CFA, so we assume we have to
1976 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1977 the intent is to save the value of SP from the previous frame.
1979 In addition, if a register has previously been saved to a different
1982 Invariants / Summaries of Rules
1984 cfa current rule for calculating the CFA. It usually
1985 consists of a register and an offset.
1986 cfa_store register used by prologue code to save things to the stack
1987 cfa_store.offset is the offset from the value of
1988 cfa_store.reg to the actual CFA
1989 cfa_temp register holding an integral value. cfa_temp.offset
1990 stores the value, which will be used to adjust the
1991 stack pointer. cfa_temp is also used like cfa_store,
1992 to track stores to the stack via fp or a temp reg.
1994 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1995 with cfa.reg as the first operand changes the cfa.reg and its
1996 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1999 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2000 expression yielding a constant. This sets cfa_temp.reg
2001 and cfa_temp.offset.
2003 Rule 5: Create a new register cfa_store used to save items to the
2006 Rules 10-14: Save a register to the stack. Define offset as the
2007 difference of the original location and cfa_store's
2008 location (or cfa_temp's location if cfa_temp is used).
2010 Rules 16-20: If AND operation happens on sp in prologue, we assume
2011 stack is realigned. We will use a group of DW_OP_XXX
2012 expressions to represent the location of the stored
2013 register instead of CFA+offset.
2017 "{a,b}" indicates a choice of a xor b.
2018 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2021 (set <reg1> <reg2>:cfa.reg)
2022 effects: cfa.reg = <reg1>
2023 cfa.offset unchanged
2024 cfa_temp.reg = <reg1>
2025 cfa_temp.offset = cfa.offset
2028 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2029 {<const_int>,<reg>:cfa_temp.reg}))
2030 effects: cfa.reg = sp if fp used
2031 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2032 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2033 if cfa_store.reg==sp
2036 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2037 effects: cfa.reg = fp
2038 cfa_offset += +/- <const_int>
2041 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2042 constraints: <reg1> != fp
2044 effects: cfa.reg = <reg1>
2045 cfa_temp.reg = <reg1>
2046 cfa_temp.offset = cfa.offset
2049 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2050 constraints: <reg1> != fp
2052 effects: cfa_store.reg = <reg1>
2053 cfa_store.offset = cfa.offset - cfa_temp.offset
2056 (set <reg> <const_int>)
2057 effects: cfa_temp.reg = <reg>
2058 cfa_temp.offset = <const_int>
2061 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2062 effects: cfa_temp.reg = <reg1>
2063 cfa_temp.offset |= <const_int>
2066 (set <reg> (high <exp>))
2070 (set <reg> (lo_sum <exp> <const_int>))
2071 effects: cfa_temp.reg = <reg>
2072 cfa_temp.offset = <const_int>
2075 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2076 effects: cfa_store.offset -= <const_int>
2077 cfa.offset = cfa_store.offset if cfa.reg == sp
2079 cfa.base_offset = -cfa_store.offset
2082 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2083 effects: cfa_store.offset += -/+ mode_size(mem)
2084 cfa.offset = cfa_store.offset if cfa.reg == sp
2086 cfa.base_offset = -cfa_store.offset
2089 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2092 effects: cfa.reg = <reg1>
2093 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2096 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2097 effects: cfa.reg = <reg1>
2098 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2101 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2102 effects: cfa.reg = <reg1>
2103 cfa.base_offset = -cfa_temp.offset
2104 cfa_temp.offset -= mode_size(mem)
2107 (set <reg> {unspec, unspec_volatile})
2108 effects: target-dependent
2111 (set sp (and: sp <const_int>))
2112 constraints: cfa_store.reg == sp
2113 effects: current_fde.stack_realign = 1
2114 cfa_store.offset = 0
2115 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2118 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2119 effects: cfa_store.offset += -/+ mode_size(mem)
2122 (set (mem ({pre_inc, pre_dec} sp)) fp)
2123 constraints: fde->stack_realign == 1
2124 effects: cfa_store.offset = 0
2125 cfa.reg != HARD_FRAME_POINTER_REGNUM
2128 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2129 constraints: fde->stack_realign == 1
2131 && cfa.indirect == 0
2132 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2133 effects: Use DW_CFA_def_cfa_expression to define cfa
2134 cfa.reg == fde->drap_reg
2137 (set reg fde->drap_reg)
2138 constraints: fde->vdrap_reg == INVALID_REGNUM
2139 effects: fde->vdrap_reg = reg.
2140 (set mem fde->drap_reg)
2141 constraints: fde->drap_reg_saved == 1
2145 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2147 rtx src, dest, span;
2148 HOST_WIDE_INT offset;
2151 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2152 the PARALLEL independently. The first element is always processed if
2153 it is a SET. This is for backward compatibility. Other elements
2154 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2155 flag is set in them. */
2156 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2159 int limit = XVECLEN (expr, 0);
2162 /* PARALLELs have strict read-modify-write semantics, so we
2163 ought to evaluate every rvalue before changing any lvalue.
2164 It's cumbersome to do that in general, but there's an
2165 easy approximation that is enough for all current users:
2166 handle register saves before register assignments. */
2167 if (GET_CODE (expr) == PARALLEL)
2168 for (par_index = 0; par_index < limit; par_index++)
2170 elem = XVECEXP (expr, 0, par_index);
2171 if (GET_CODE (elem) == SET
2172 && MEM_P (SET_DEST (elem))
2173 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2174 dwarf2out_frame_debug_expr (elem, label);
2177 for (par_index = 0; par_index < limit; par_index++)
2179 elem = XVECEXP (expr, 0, par_index);
2180 if (GET_CODE (elem) == SET
2181 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2182 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2183 dwarf2out_frame_debug_expr (elem, label);
2184 else if (GET_CODE (elem) == SET
2186 && !RTX_FRAME_RELATED_P (elem))
2188 /* Stack adjustment combining might combine some post-prologue
2189 stack adjustment into a prologue stack adjustment. */
2190 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2193 dwarf2out_args_size_adjust (offset, label);
2199 gcc_assert (GET_CODE (expr) == SET);
2201 src = SET_SRC (expr);
2202 dest = SET_DEST (expr);
2206 rtx rsi = reg_saved_in (src);
2211 fde = current_fde ();
2215 && fde->drap_reg == REGNO (src)
2216 && (fde->drap_reg_saved
2220 /* If we are saving dynamic realign argument pointer to a
2221 register, the destination is virtual dynamic realign
2222 argument pointer. It may be used to access argument. */
2225 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2226 fde->vdrap_reg = REGNO (dest);
2231 switch (GET_CODE (dest))
2234 switch (GET_CODE (src))
2236 /* Setting FP from SP. */
2238 if (cfa.reg == (unsigned) REGNO (src))
2241 /* Update the CFA rule wrt SP or FP. Make sure src is
2242 relative to the current CFA register.
2244 We used to require that dest be either SP or FP, but the
2245 ARM copies SP to a temporary register, and from there to
2246 FP. So we just rely on the backends to only set
2247 RTX_FRAME_RELATED_P on appropriate insns. */
2248 cfa.reg = REGNO (dest);
2249 cfa_temp.reg = cfa.reg;
2250 cfa_temp.offset = cfa.offset;
2254 /* Saving a register in a register. */
2255 gcc_assert (!fixed_regs [REGNO (dest)]
2256 /* For the SPARC and its register window. */
2257 || (DWARF_FRAME_REGNUM (REGNO (src))
2258 == DWARF_FRAME_RETURN_COLUMN));
2260 /* After stack is aligned, we can only save SP in FP
2261 if drap register is used. In this case, we have
2262 to restore stack pointer with the CFA value and we
2263 don't generate this DWARF information. */
2265 && fde->stack_realign
2266 && REGNO (src) == STACK_POINTER_REGNUM)
2267 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2268 && fde->drap_reg != INVALID_REGNUM
2269 && cfa.reg != REGNO (src));
2271 queue_reg_save (label, src, dest, 0);
2278 if (dest == stack_pointer_rtx)
2282 switch (GET_CODE (XEXP (src, 1)))
2285 offset = INTVAL (XEXP (src, 1));
2288 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2290 offset = cfa_temp.offset;
2296 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2298 /* Restoring SP from FP in the epilogue. */
2299 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2300 cfa.reg = STACK_POINTER_REGNUM;
2302 else if (GET_CODE (src) == LO_SUM)
2303 /* Assume we've set the source reg of the LO_SUM from sp. */
2306 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2308 if (GET_CODE (src) != MINUS)
2310 if (cfa.reg == STACK_POINTER_REGNUM)
2311 cfa.offset += offset;
2312 if (cfa_store.reg == STACK_POINTER_REGNUM)
2313 cfa_store.offset += offset;
2315 else if (dest == hard_frame_pointer_rtx)
2318 /* Either setting the FP from an offset of the SP,
2319 or adjusting the FP */
2320 gcc_assert (frame_pointer_needed);
2322 gcc_assert (REG_P (XEXP (src, 0))
2323 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2324 && CONST_INT_P (XEXP (src, 1)));
2325 offset = INTVAL (XEXP (src, 1));
2326 if (GET_CODE (src) != MINUS)
2328 cfa.offset += offset;
2329 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2333 gcc_assert (GET_CODE (src) != MINUS);
2336 if (REG_P (XEXP (src, 0))
2337 && REGNO (XEXP (src, 0)) == cfa.reg
2338 && CONST_INT_P (XEXP (src, 1)))
2340 /* Setting a temporary CFA register that will be copied
2341 into the FP later on. */
2342 offset = - INTVAL (XEXP (src, 1));
2343 cfa.offset += offset;
2344 cfa.reg = REGNO (dest);
2345 /* Or used to save regs to the stack. */
2346 cfa_temp.reg = cfa.reg;
2347 cfa_temp.offset = cfa.offset;
2351 else if (REG_P (XEXP (src, 0))
2352 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2353 && XEXP (src, 1) == stack_pointer_rtx)
2355 /* Setting a scratch register that we will use instead
2356 of SP for saving registers to the stack. */
2357 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2358 cfa_store.reg = REGNO (dest);
2359 cfa_store.offset = cfa.offset - cfa_temp.offset;
2363 else if (GET_CODE (src) == LO_SUM
2364 && CONST_INT_P (XEXP (src, 1)))
2366 cfa_temp.reg = REGNO (dest);
2367 cfa_temp.offset = INTVAL (XEXP (src, 1));
2376 cfa_temp.reg = REGNO (dest);
2377 cfa_temp.offset = INTVAL (src);
2382 gcc_assert (REG_P (XEXP (src, 0))
2383 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2384 && CONST_INT_P (XEXP (src, 1)));
2386 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2387 cfa_temp.reg = REGNO (dest);
2388 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2391 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2392 which will fill in all of the bits. */
2399 case UNSPEC_VOLATILE:
2400 gcc_assert (targetm.dwarf_handle_frame_unspec);
2401 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2406 /* If this AND operation happens on stack pointer in prologue,
2407 we assume the stack is realigned and we extract the
2409 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2411 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2412 fde->stack_realign = 1;
2413 fde->stack_realignment = INTVAL (XEXP (src, 1));
2414 cfa_store.offset = 0;
2416 if (cfa.reg != STACK_POINTER_REGNUM
2417 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2418 fde->drap_reg = cfa.reg;
2426 def_cfa_1 (label, &cfa);
2431 /* Saving a register to the stack. Make sure dest is relative to the
2433 switch (GET_CODE (XEXP (dest, 0)))
2438 /* We can't handle variable size modifications. */
2439 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2441 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2443 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2444 && cfa_store.reg == STACK_POINTER_REGNUM);
2446 cfa_store.offset += offset;
2447 if (cfa.reg == STACK_POINTER_REGNUM)
2448 cfa.offset = cfa_store.offset;
2450 offset = -cfa_store.offset;
2456 offset = GET_MODE_SIZE (GET_MODE (dest));
2457 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2460 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2461 == STACK_POINTER_REGNUM)
2462 && cfa_store.reg == STACK_POINTER_REGNUM);
2464 cfa_store.offset += offset;
2466 /* Rule 18: If stack is aligned, we will use FP as a
2467 reference to represent the address of the stored
2470 && fde->stack_realign
2471 && src == hard_frame_pointer_rtx)
2473 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2474 cfa_store.offset = 0;
2477 if (cfa.reg == STACK_POINTER_REGNUM)
2478 cfa.offset = cfa_store.offset;
2480 offset = -cfa_store.offset;
2484 /* With an offset. */
2491 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2492 && REG_P (XEXP (XEXP (dest, 0), 0)));
2493 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2494 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2497 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2499 if (cfa_store.reg == (unsigned) regno)
2500 offset -= cfa_store.offset;
2503 gcc_assert (cfa_temp.reg == (unsigned) regno);
2504 offset -= cfa_temp.offset;
2510 /* Without an offset. */
2513 int regno = REGNO (XEXP (dest, 0));
2515 if (cfa_store.reg == (unsigned) regno)
2516 offset = -cfa_store.offset;
2519 gcc_assert (cfa_temp.reg == (unsigned) regno);
2520 offset = -cfa_temp.offset;
2527 gcc_assert (cfa_temp.reg
2528 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2529 offset = -cfa_temp.offset;
2530 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2538 /* If the source operand of this MEM operation is not a
2539 register, basically the source is return address. Here
2540 we only care how much stack grew and we don't save it. */
2544 if (REGNO (src) != STACK_POINTER_REGNUM
2545 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2546 && (unsigned) REGNO (src) == cfa.reg)
2548 /* We're storing the current CFA reg into the stack. */
2550 if (cfa.offset == 0)
2553 /* If stack is aligned, putting CFA reg into stack means
2554 we can no longer use reg + offset to represent CFA.
2555 Here we use DW_CFA_def_cfa_expression instead. The
2556 result of this expression equals to the original CFA
2559 && fde->stack_realign
2560 && cfa.indirect == 0
2561 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2563 dw_cfa_location cfa_exp;
2565 gcc_assert (fde->drap_reg == cfa.reg);
2567 cfa_exp.indirect = 1;
2568 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2569 cfa_exp.base_offset = offset;
2572 fde->drap_reg_saved = 1;
2574 def_cfa_1 (label, &cfa_exp);
2578 /* If the source register is exactly the CFA, assume
2579 we're saving SP like any other register; this happens
2581 def_cfa_1 (label, &cfa);
2582 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2587 /* Otherwise, we'll need to look in the stack to
2588 calculate the CFA. */
2589 rtx x = XEXP (dest, 0);
2593 gcc_assert (REG_P (x));
2595 cfa.reg = REGNO (x);
2596 cfa.base_offset = offset;
2598 def_cfa_1 (label, &cfa);
2603 def_cfa_1 (label, &cfa);
2605 span = targetm.dwarf_register_span (src);
2608 queue_reg_save (label, src, NULL_RTX, offset);
2611 /* We have a PARALLEL describing where the contents of SRC
2612 live. Queue register saves for each piece of the
2616 HOST_WIDE_INT span_offset = offset;
2618 gcc_assert (GET_CODE (span) == PARALLEL);
2620 limit = XVECLEN (span, 0);
2621 for (par_index = 0; par_index < limit; par_index++)
2623 rtx elem = XVECEXP (span, 0, par_index);
2625 queue_reg_save (label, elem, NULL_RTX, span_offset);
2626 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2637 /* Record call frame debugging information for INSN, which either
2638 sets SP or FP (adjusting how we calculate the frame address) or saves a
2639 register to the stack. If INSN is NULL_RTX, initialize our state.
2641 If AFTER_P is false, we're being called before the insn is emitted,
2642 otherwise after. Call instructions get invoked twice. */
2645 dwarf2out_frame_debug (rtx insn, bool after_p)
2649 bool handled_one = false;
2651 if (insn == NULL_RTX)
2655 /* Flush any queued register saves. */
2656 flush_queued_reg_saves ();
2658 /* Set up state for generating call frame debug info. */
2661 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2663 cfa.reg = STACK_POINTER_REGNUM;
2666 cfa_temp.offset = 0;
2668 for (i = 0; i < num_regs_saved_in_regs; i++)
2670 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2671 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2673 num_regs_saved_in_regs = 0;
2675 if (barrier_args_size)
2677 XDELETEVEC (barrier_args_size);
2678 barrier_args_size = NULL;
2683 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2684 flush_queued_reg_saves ();
2686 if (! RTX_FRAME_RELATED_P (insn))
2688 if (!ACCUMULATE_OUTGOING_ARGS)
2689 dwarf2out_stack_adjust (insn, after_p);
2693 label = dwarf2out_cfi_label (false);
2695 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2696 switch (REG_NOTE_KIND (note))
2698 case REG_FRAME_RELATED_EXPR:
2699 insn = XEXP (note, 0);
2702 case REG_CFA_DEF_CFA:
2703 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2707 case REG_CFA_ADJUST_CFA:
2712 if (GET_CODE (n) == PARALLEL)
2713 n = XVECEXP (n, 0, 0);
2715 dwarf2out_frame_debug_adjust_cfa (n, label);
2719 case REG_CFA_OFFSET:
2722 n = single_set (insn);
2723 dwarf2out_frame_debug_cfa_offset (n, label);
2727 case REG_CFA_REGISTER:
2732 if (GET_CODE (n) == PARALLEL)
2733 n = XVECEXP (n, 0, 0);
2735 dwarf2out_frame_debug_cfa_register (n, label);
2739 case REG_CFA_RESTORE:
2744 if (GET_CODE (n) == PARALLEL)
2745 n = XVECEXP (n, 0, 0);
2748 dwarf2out_frame_debug_cfa_restore (n, label);
2758 insn = PATTERN (insn);
2760 dwarf2out_frame_debug_expr (insn, label);
2763 /* Determine if we need to save and restore CFI information around this
2764 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2765 we do need to save/restore, then emit the save now, and insert a
2766 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2769 dwarf2out_begin_epilogue (rtx insn)
2771 bool saw_frp = false;
2774 /* Scan forward to the return insn, noticing if there are possible
2775 frame related insns. */
2776 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2781 /* Look for both regular and sibcalls to end the block. */
2782 if (returnjump_p (i))
2784 if (CALL_P (i) && SIBLING_CALL_P (i))
2787 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2790 rtx seq = PATTERN (i);
2792 if (returnjump_p (XVECEXP (seq, 0, 0)))
2794 if (CALL_P (XVECEXP (seq, 0, 0))
2795 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2798 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2799 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2803 if (RTX_FRAME_RELATED_P (i))
2807 /* If the port doesn't emit epilogue unwind info, we don't need a
2808 save/restore pair. */
2812 /* Otherwise, search forward to see if the return insn was the last
2813 basic block of the function. If so, we don't need save/restore. */
2814 gcc_assert (i != NULL);
2815 i = next_real_insn (i);
2819 /* Insert the restore before that next real insn in the stream, and before
2820 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2821 properly nested. This should be after any label or alignment. This
2822 will be pushed into the CFI stream by the function below. */
2825 rtx p = PREV_INSN (i);
2828 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2832 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2834 emit_cfa_remember = true;
2836 /* And emulate the state save. */
2837 gcc_assert (!cfa_remember.in_use);
2839 cfa_remember.in_use = 1;
2842 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2845 dwarf2out_frame_debug_restore_state (void)
2847 dw_cfi_ref cfi = new_cfi ();
2848 const char *label = dwarf2out_cfi_label (false);
2850 cfi->dw_cfi_opc = DW_CFA_restore_state;
2851 add_fde_cfi (label, cfi);
2853 gcc_assert (cfa_remember.in_use);
2855 cfa_remember.in_use = 0;
2860 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2861 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2862 (enum dwarf_call_frame_info cfi);
2864 static enum dw_cfi_oprnd_type
2865 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2870 case DW_CFA_GNU_window_save:
2871 case DW_CFA_remember_state:
2872 case DW_CFA_restore_state:
2873 return dw_cfi_oprnd_unused;
2875 case DW_CFA_set_loc:
2876 case DW_CFA_advance_loc1:
2877 case DW_CFA_advance_loc2:
2878 case DW_CFA_advance_loc4:
2879 case DW_CFA_MIPS_advance_loc8:
2880 return dw_cfi_oprnd_addr;
2883 case DW_CFA_offset_extended:
2884 case DW_CFA_def_cfa:
2885 case DW_CFA_offset_extended_sf:
2886 case DW_CFA_def_cfa_sf:
2887 case DW_CFA_restore:
2888 case DW_CFA_restore_extended:
2889 case DW_CFA_undefined:
2890 case DW_CFA_same_value:
2891 case DW_CFA_def_cfa_register:
2892 case DW_CFA_register:
2893 return dw_cfi_oprnd_reg_num;
2895 case DW_CFA_def_cfa_offset:
2896 case DW_CFA_GNU_args_size:
2897 case DW_CFA_def_cfa_offset_sf:
2898 return dw_cfi_oprnd_offset;
2900 case DW_CFA_def_cfa_expression:
2901 case DW_CFA_expression:
2902 return dw_cfi_oprnd_loc;
2909 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2910 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2911 (enum dwarf_call_frame_info cfi);
2913 static enum dw_cfi_oprnd_type
2914 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2918 case DW_CFA_def_cfa:
2919 case DW_CFA_def_cfa_sf:
2921 case DW_CFA_offset_extended_sf:
2922 case DW_CFA_offset_extended:
2923 return dw_cfi_oprnd_offset;
2925 case DW_CFA_register:
2926 return dw_cfi_oprnd_reg_num;
2929 return dw_cfi_oprnd_unused;
2933 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2935 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2936 switch to the data section instead, and write out a synthetic label
2940 switch_to_eh_frame_section (void)
2944 #ifdef EH_FRAME_SECTION_NAME
2945 if (eh_frame_section == 0)
2949 if (EH_TABLES_CAN_BE_READ_ONLY)
2955 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2957 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2959 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2961 flags = ((! flag_pic
2962 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2963 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2964 && (per_encoding & 0x70) != DW_EH_PE_absptr
2965 && (per_encoding & 0x70) != DW_EH_PE_aligned
2966 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2967 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2968 ? 0 : SECTION_WRITE);
2971 flags = SECTION_WRITE;
2972 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2976 if (eh_frame_section)
2977 switch_to_section (eh_frame_section);
2980 /* We have no special eh_frame section. Put the information in
2981 the data section and emit special labels to guide collect2. */
2982 switch_to_section (data_section);
2983 label = get_file_function_name ("F");
2984 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2985 targetm.asm_out.globalize_label (asm_out_file,
2986 IDENTIFIER_POINTER (label));
2987 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2991 /* Output a Call Frame Information opcode and its operand(s). */
2994 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2999 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3000 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3001 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3002 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3003 ((unsigned HOST_WIDE_INT)
3004 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3005 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3007 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3008 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3009 "DW_CFA_offset, column 0x%lx", r);
3010 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3011 dw2_asm_output_data_uleb128 (off, NULL);
3013 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3015 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3016 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3017 "DW_CFA_restore, column 0x%lx", r);
3021 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3022 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3024 switch (cfi->dw_cfi_opc)
3026 case DW_CFA_set_loc:
3028 dw2_asm_output_encoded_addr_rtx (
3029 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3030 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3033 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3034 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3035 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3038 case DW_CFA_advance_loc1:
3039 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3040 fde->dw_fde_current_label, NULL);
3041 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3044 case DW_CFA_advance_loc2:
3045 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3046 fde->dw_fde_current_label, NULL);
3047 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3050 case DW_CFA_advance_loc4:
3051 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3052 fde->dw_fde_current_label, NULL);
3053 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3056 case DW_CFA_MIPS_advance_loc8:
3057 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3058 fde->dw_fde_current_label, NULL);
3059 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3062 case DW_CFA_offset_extended:
3063 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3064 dw2_asm_output_data_uleb128 (r, NULL);
3065 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3066 dw2_asm_output_data_uleb128 (off, NULL);
3069 case DW_CFA_def_cfa:
3070 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3071 dw2_asm_output_data_uleb128 (r, NULL);
3072 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3075 case DW_CFA_offset_extended_sf:
3076 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3077 dw2_asm_output_data_uleb128 (r, NULL);
3078 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3079 dw2_asm_output_data_sleb128 (off, NULL);
3082 case DW_CFA_def_cfa_sf:
3083 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3084 dw2_asm_output_data_uleb128 (r, NULL);
3085 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3086 dw2_asm_output_data_sleb128 (off, NULL);
3089 case DW_CFA_restore_extended:
3090 case DW_CFA_undefined:
3091 case DW_CFA_same_value:
3092 case DW_CFA_def_cfa_register:
3093 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3094 dw2_asm_output_data_uleb128 (r, NULL);
3097 case DW_CFA_register:
3098 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3099 dw2_asm_output_data_uleb128 (r, NULL);
3100 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3101 dw2_asm_output_data_uleb128 (r, NULL);
3104 case DW_CFA_def_cfa_offset:
3105 case DW_CFA_GNU_args_size:
3106 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3109 case DW_CFA_def_cfa_offset_sf:
3110 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3111 dw2_asm_output_data_sleb128 (off, NULL);
3114 case DW_CFA_GNU_window_save:
3117 case DW_CFA_def_cfa_expression:
3118 case DW_CFA_expression:
3119 output_cfa_loc (cfi);
3122 case DW_CFA_GNU_negative_offset_extended:
3123 /* Obsoleted by DW_CFA_offset_extended_sf. */
3132 /* Similar, but do it via assembler directives instead. */
3135 output_cfi_directive (dw_cfi_ref cfi)
3137 unsigned long r, r2;
3139 switch (cfi->dw_cfi_opc)
3141 case DW_CFA_advance_loc:
3142 case DW_CFA_advance_loc1:
3143 case DW_CFA_advance_loc2:
3144 case DW_CFA_advance_loc4:
3145 case DW_CFA_MIPS_advance_loc8:
3146 case DW_CFA_set_loc:
3147 /* Should only be created by add_fde_cfi in a code path not
3148 followed when emitting via directives. The assembler is
3149 going to take care of this for us. */
3153 case DW_CFA_offset_extended:
3154 case DW_CFA_offset_extended_sf:
3155 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3156 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3157 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3160 case DW_CFA_restore:
3161 case DW_CFA_restore_extended:
3162 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3163 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3166 case DW_CFA_undefined:
3167 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3168 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3171 case DW_CFA_same_value:
3172 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3173 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3176 case DW_CFA_def_cfa:
3177 case DW_CFA_def_cfa_sf:
3178 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3179 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3180 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3183 case DW_CFA_def_cfa_register:
3184 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3185 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3188 case DW_CFA_register:
3189 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3190 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3191 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3194 case DW_CFA_def_cfa_offset:
3195 case DW_CFA_def_cfa_offset_sf:
3196 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3197 HOST_WIDE_INT_PRINT_DEC"\n",
3198 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3201 case DW_CFA_remember_state:
3202 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3204 case DW_CFA_restore_state:
3205 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3208 case DW_CFA_GNU_args_size:
3209 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3210 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3212 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3213 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3214 fputc ('\n', asm_out_file);
3217 case DW_CFA_GNU_window_save:
3218 fprintf (asm_out_file, "\t.cfi_window_save\n");
3221 case DW_CFA_def_cfa_expression:
3222 case DW_CFA_expression:
3223 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3224 output_cfa_loc_raw (cfi);
3225 fputc ('\n', asm_out_file);
3233 DEF_VEC_P (dw_cfi_ref);
3234 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3236 /* Output CFIs to bring current FDE to the same state as after executing
3237 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3238 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3239 other arguments to pass to output_cfi. */
3242 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3244 struct dw_cfi_struct cfi_buf;
3246 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3247 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3248 unsigned int len, idx;
3250 for (;; cfi = cfi->dw_cfi_next)
3251 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3253 case DW_CFA_advance_loc:
3254 case DW_CFA_advance_loc1:
3255 case DW_CFA_advance_loc2:
3256 case DW_CFA_advance_loc4:
3257 case DW_CFA_MIPS_advance_loc8:
3258 case DW_CFA_set_loc:
3259 /* All advances should be ignored. */
3261 case DW_CFA_remember_state:
3263 dw_cfi_ref args_size = cfi_args_size;
3265 /* Skip everything between .cfi_remember_state and
3266 .cfi_restore_state. */
3267 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3268 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3270 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3273 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3280 cfi_args_size = args_size;
3284 case DW_CFA_GNU_args_size:
3285 cfi_args_size = cfi;
3287 case DW_CFA_GNU_window_save:
3290 case DW_CFA_offset_extended:
3291 case DW_CFA_offset_extended_sf:
3292 case DW_CFA_restore:
3293 case DW_CFA_restore_extended:
3294 case DW_CFA_undefined:
3295 case DW_CFA_same_value:
3296 case DW_CFA_register:
3297 case DW_CFA_val_offset:
3298 case DW_CFA_val_offset_sf:
3299 case DW_CFA_expression:
3300 case DW_CFA_val_expression:
3301 case DW_CFA_GNU_negative_offset_extended:
3302 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3303 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3304 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3305 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3307 case DW_CFA_def_cfa:
3308 case DW_CFA_def_cfa_sf:
3309 case DW_CFA_def_cfa_expression:
3311 cfi_cfa_offset = cfi;
3313 case DW_CFA_def_cfa_register:
3316 case DW_CFA_def_cfa_offset:
3317 case DW_CFA_def_cfa_offset_sf:
3318 cfi_cfa_offset = cfi;
3321 gcc_assert (cfi == NULL);
3323 len = VEC_length (dw_cfi_ref, regs);
3324 for (idx = 0; idx < len; idx++)
3326 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3328 && cfi2->dw_cfi_opc != DW_CFA_restore
3329 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3332 output_cfi_directive (cfi2);
3334 output_cfi (cfi2, fde, for_eh);
3337 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3339 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3341 switch (cfi_cfa_offset->dw_cfi_opc)
3343 case DW_CFA_def_cfa_offset:
3344 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3345 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3347 case DW_CFA_def_cfa_offset_sf:
3348 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3349 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3351 case DW_CFA_def_cfa:
3352 case DW_CFA_def_cfa_sf:
3353 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3354 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3361 else if (cfi_cfa_offset)
3362 cfi_cfa = cfi_cfa_offset;
3366 output_cfi_directive (cfi_cfa);
3368 output_cfi (cfi_cfa, fde, for_eh);
3371 cfi_cfa_offset = NULL;
3373 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3376 output_cfi_directive (cfi_args_size);
3378 output_cfi (cfi_args_size, fde, for_eh);
3380 cfi_args_size = NULL;
3383 VEC_free (dw_cfi_ref, heap, regs);
3386 else if (do_cfi_asm)
3387 output_cfi_directive (cfi);
3389 output_cfi (cfi, fde, for_eh);
3396 /* Output one FDE. */
3399 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3400 char *section_start_label, int fde_encoding, char *augmentation,
3401 bool any_lsda_needed, int lsda_encoding)
3403 const char *begin, *end;
3404 static unsigned int j;
3405 char l1[20], l2[20];
3408 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3410 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3412 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3413 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3414 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3415 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3416 " indicating 64-bit DWARF extension");
3417 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3419 ASM_OUTPUT_LABEL (asm_out_file, l1);
3422 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3424 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3425 debug_frame_section, "FDE CIE offset");
3427 if (!fde->dw_fde_switched_sections)
3429 begin = fde->dw_fde_begin;
3430 end = fde->dw_fde_end;
3434 /* For the first section, prefer dw_fde_begin over
3435 dw_fde_{hot,cold}_section_label, as the latter
3436 might be separated from the real start of the
3437 function by alignment padding. */
3439 begin = fde->dw_fde_begin;
3440 else if (fde->dw_fde_switched_cold_to_hot)
3441 begin = fde->dw_fde_hot_section_label;
3443 begin = fde->dw_fde_unlikely_section_label;
3444 if (second ^ fde->dw_fde_switched_cold_to_hot)
3445 end = fde->dw_fde_unlikely_section_end_label;
3447 end = fde->dw_fde_hot_section_end_label;
3452 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3453 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3454 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3455 "FDE initial location");
3456 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3457 end, begin, "FDE address range");
3461 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3462 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3465 if (augmentation[0])
3467 if (any_lsda_needed)
3469 int size = size_of_encoded_value (lsda_encoding);
3471 if (lsda_encoding == DW_EH_PE_aligned)
3473 int offset = ( 4 /* Length */
3474 + 4 /* CIE offset */
3475 + 2 * size_of_encoded_value (fde_encoding)
3476 + 1 /* Augmentation size */ );
3477 int pad = -offset & (PTR_SIZE - 1);
3480 gcc_assert (size_of_uleb128 (size) == 1);
3483 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3485 if (fde->uses_eh_lsda)
3487 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3488 fde->funcdef_number);
3489 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3490 gen_rtx_SYMBOL_REF (Pmode, l1),
3492 "Language Specific Data Area");
3496 if (lsda_encoding == DW_EH_PE_aligned)
3497 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3498 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3499 "Language Specific Data Area (none)");
3503 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3506 /* Loop through the Call Frame Instructions associated with
3508 fde->dw_fde_current_label = begin;
3509 if (!fde->dw_fde_switched_sections)
3510 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3511 output_cfi (cfi, fde, for_eh);
3514 if (fde->dw_fde_switch_cfi)
3515 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3517 output_cfi (cfi, fde, for_eh);
3518 if (cfi == fde->dw_fde_switch_cfi)
3524 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3526 if (fde->dw_fde_switch_cfi)
3528 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3529 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3530 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3531 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3533 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3534 output_cfi (cfi, fde, for_eh);
3537 /* Pad the FDE out to an address sized boundary. */
3538 ASM_OUTPUT_ALIGN (asm_out_file,
3539 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3540 ASM_OUTPUT_LABEL (asm_out_file, l2);
3546 /* Output the call frame information used to record information
3547 that relates to calculating the frame pointer, and records the
3548 location of saved registers. */
3551 output_call_frame_info (int for_eh)
3556 char l1[20], l2[20], section_start_label[20];
3557 bool any_lsda_needed = false;
3558 char augmentation[6];
3559 int augmentation_size;
3560 int fde_encoding = DW_EH_PE_absptr;
3561 int per_encoding = DW_EH_PE_absptr;
3562 int lsda_encoding = DW_EH_PE_absptr;
3566 /* Don't emit a CIE if there won't be any FDEs. */
3567 if (fde_table_in_use == 0)
3570 /* Nothing to do if the assembler's doing it all. */
3571 if (dwarf2out_do_cfi_asm ())
3574 /* If we make FDEs linkonce, we may have to emit an empty label for
3575 an FDE that wouldn't otherwise be emitted. We want to avoid
3576 having an FDE kept around when the function it refers to is
3577 discarded. Example where this matters: a primary function
3578 template in C++ requires EH information, but an explicit
3579 specialization doesn't. */
3580 if (TARGET_USES_WEAK_UNWIND_INFO
3581 && ! flag_asynchronous_unwind_tables
3584 for (i = 0; i < fde_table_in_use; i++)
3585 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3586 && !fde_table[i].uses_eh_lsda
3587 && ! DECL_WEAK (fde_table[i].decl))
3588 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3589 for_eh, /* empty */ 1);
3591 /* If we don't have any functions we'll want to unwind out of, don't
3592 emit any EH unwind information. Note that if exceptions aren't
3593 enabled, we won't have collected nothrow information, and if we
3594 asked for asynchronous tables, we always want this info. */
3597 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3599 for (i = 0; i < fde_table_in_use; i++)
3600 if (fde_table[i].uses_eh_lsda)
3601 any_eh_needed = any_lsda_needed = true;
3602 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3603 any_eh_needed = true;
3604 else if (! fde_table[i].nothrow
3605 && ! fde_table[i].all_throwers_are_sibcalls)
3606 any_eh_needed = true;
3608 if (! any_eh_needed)
3612 /* We're going to be generating comments, so turn on app. */
3617 switch_to_eh_frame_section ();
3620 if (!debug_frame_section)
3621 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3622 SECTION_DEBUG, NULL);
3623 switch_to_section (debug_frame_section);
3626 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3627 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3629 /* Output the CIE. */
3630 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3631 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3632 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3633 dw2_asm_output_data (4, 0xffffffff,
3634 "Initial length escape value indicating 64-bit DWARF extension");
3635 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3636 "Length of Common Information Entry");
3637 ASM_OUTPUT_LABEL (asm_out_file, l1);
3639 /* Now that the CIE pointer is PC-relative for EH,
3640 use 0 to identify the CIE. */
3641 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3642 (for_eh ? 0 : DWARF_CIE_ID),
3643 "CIE Identifier Tag");
3645 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3646 use CIE version 1, unless that would produce incorrect results
3647 due to overflowing the return register column. */
3648 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3650 if (return_reg >= 256 || dwarf_version > 2)
3652 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3654 augmentation[0] = 0;
3655 augmentation_size = 0;
3661 z Indicates that a uleb128 is present to size the
3662 augmentation section.
3663 L Indicates the encoding (and thus presence) of
3664 an LSDA pointer in the FDE augmentation.
3665 R Indicates a non-default pointer encoding for
3667 P Indicates the presence of an encoding + language
3668 personality routine in the CIE augmentation. */
3670 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3671 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3672 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3674 p = augmentation + 1;
3675 if (eh_personality_libfunc)
3678 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3679 assemble_external_libcall (eh_personality_libfunc);
3681 if (any_lsda_needed)
3684 augmentation_size += 1;
3686 if (fde_encoding != DW_EH_PE_absptr)
3689 augmentation_size += 1;
3691 if (p > augmentation + 1)
3693 augmentation[0] = 'z';
3697 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3698 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
3700 int offset = ( 4 /* Length */
3702 + 1 /* CIE version */
3703 + strlen (augmentation) + 1 /* Augmentation */
3704 + size_of_uleb128 (1) /* Code alignment */
3705 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3707 + 1 /* Augmentation size */
3708 + 1 /* Personality encoding */ );
3709 int pad = -offset & (PTR_SIZE - 1);
3711 augmentation_size += pad;
3713 /* Augmentations should be small, so there's scarce need to
3714 iterate for a solution. Die if we exceed one uleb128 byte. */
3715 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3719 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3720 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3721 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3722 "CIE Data Alignment Factor");
3724 if (dw_cie_version == 1)
3725 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3727 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3729 if (augmentation[0])
3731 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3732 if (eh_personality_libfunc)
3734 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3735 eh_data_format_name (per_encoding));
3736 dw2_asm_output_encoded_addr_rtx (per_encoding,
3737 eh_personality_libfunc,
3741 if (any_lsda_needed)
3742 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3743 eh_data_format_name (lsda_encoding));
3745 if (fde_encoding != DW_EH_PE_absptr)
3746 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3747 eh_data_format_name (fde_encoding));
3750 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3751 output_cfi (cfi, NULL, for_eh);
3753 /* Pad the CIE out to an address sized boundary. */
3754 ASM_OUTPUT_ALIGN (asm_out_file,
3755 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3756 ASM_OUTPUT_LABEL (asm_out_file, l2);
3758 /* Loop through all of the FDE's. */
3759 for (i = 0; i < fde_table_in_use; i++)
3762 fde = &fde_table[i];
3764 /* Don't emit EH unwind info for leaf functions that don't need it. */
3765 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3766 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3767 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3768 && !fde->uses_eh_lsda)
3771 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3772 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3773 augmentation, any_lsda_needed, lsda_encoding);
3776 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3777 dw2_asm_output_data (4, 0, "End of Table");
3778 #ifdef MIPS_DEBUGGING_INFO
3779 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3780 get a value of 0. Putting .align 0 after the label fixes it. */
3781 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3784 /* Turn off app to make assembly quicker. */
3789 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3792 dwarf2out_do_cfi_startproc (bool second)
3797 fprintf (asm_out_file, "\t.cfi_startproc\n");
3799 if (eh_personality_libfunc)
3801 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3802 ref = eh_personality_libfunc;
3804 /* ??? The GAS support isn't entirely consistent. We have to
3805 handle indirect support ourselves, but PC-relative is done
3806 in the assembler. Further, the assembler can't handle any
3807 of the weirder relocation types. */
3808 if (enc & DW_EH_PE_indirect)
3809 ref = dw2_force_const_mem (ref, true);
3811 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3812 output_addr_const (asm_out_file, ref);
3813 fputc ('\n', asm_out_file);
3816 if (crtl->uses_eh_lsda)
3820 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3821 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3822 current_function_funcdef_no);
3823 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3824 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3826 if (enc & DW_EH_PE_indirect)
3827 ref = dw2_force_const_mem (ref, true);
3829 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3830 output_addr_const (asm_out_file, ref);
3831 fputc ('\n', asm_out_file);
3835 /* Output a marker (i.e. a label) for the beginning of a function, before
3839 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3840 const char *file ATTRIBUTE_UNUSED)
3842 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3847 current_function_func_begin_label = NULL;
3849 #ifdef TARGET_UNWIND_INFO
3850 /* ??? current_function_func_begin_label is also used by except.c
3851 for call-site information. We must emit this label if it might
3853 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3854 && ! dwarf2out_do_frame ())
3857 if (! dwarf2out_do_frame ())
3861 fnsec = function_section (current_function_decl);
3862 switch_to_section (fnsec);
3863 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3864 current_function_funcdef_no);
3865 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3866 current_function_funcdef_no);
3867 dup_label = xstrdup (label);
3868 current_function_func_begin_label = dup_label;
3870 #ifdef TARGET_UNWIND_INFO
3871 /* We can elide the fde allocation if we're not emitting debug info. */
3872 if (! dwarf2out_do_frame ())
3876 /* Expand the fde table if necessary. */
3877 if (fde_table_in_use == fde_table_allocated)
3879 fde_table_allocated += FDE_TABLE_INCREMENT;
3880 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3881 memset (fde_table + fde_table_in_use, 0,
3882 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3885 /* Record the FDE associated with this function. */
3886 current_funcdef_fde = fde_table_in_use;
3888 /* Add the new FDE at the end of the fde_table. */
3889 fde = &fde_table[fde_table_in_use++];
3890 fde->decl = current_function_decl;
3891 fde->dw_fde_begin = dup_label;
3892 fde->dw_fde_current_label = dup_label;
3893 fde->dw_fde_hot_section_label = NULL;
3894 fde->dw_fde_hot_section_end_label = NULL;
3895 fde->dw_fde_unlikely_section_label = NULL;
3896 fde->dw_fde_unlikely_section_end_label = NULL;
3897 fde->dw_fde_switched_sections = 0;
3898 fde->dw_fde_switched_cold_to_hot = 0;
3899 fde->dw_fde_end = NULL;
3900 fde->dw_fde_cfi = NULL;
3901 fde->dw_fde_switch_cfi = NULL;
3902 fde->funcdef_number = current_function_funcdef_no;
3903 fde->nothrow = crtl->nothrow;
3904 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3905 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3906 fde->drap_reg = INVALID_REGNUM;
3907 fde->vdrap_reg = INVALID_REGNUM;
3908 if (flag_reorder_blocks_and_partition)
3910 section *unlikelysec;
3911 if (first_function_block_is_cold)
3912 fde->in_std_section = 1;
3915 = (fnsec == text_section
3916 || (cold_text_section && fnsec == cold_text_section));
3917 unlikelysec = unlikely_text_section ();
3918 fde->cold_in_std_section
3919 = (unlikelysec == text_section
3920 || (cold_text_section && unlikelysec == cold_text_section));
3925 = (fnsec == text_section
3926 || (cold_text_section && fnsec == cold_text_section));
3927 fde->cold_in_std_section = 0;
3930 args_size = old_args_size = 0;
3932 /* We only want to output line number information for the genuine dwarf2
3933 prologue case, not the eh frame case. */
3934 #ifdef DWARF2_DEBUGGING_INFO
3936 dwarf2out_source_line (line, file, 0, true);
3939 if (dwarf2out_do_cfi_asm ())
3940 dwarf2out_do_cfi_startproc (false);
3943 /* Output a marker (i.e. a label) for the absolute end of the generated code
3944 for a function definition. This gets called *after* the epilogue code has
3948 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3949 const char *file ATTRIBUTE_UNUSED)
3952 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3954 #ifdef DWARF2_DEBUGGING_INFO
3955 last_var_location_insn = NULL_RTX;
3958 if (dwarf2out_do_cfi_asm ())
3959 fprintf (asm_out_file, "\t.cfi_endproc\n");
3961 /* Output a label to mark the endpoint of the code generated for this
3963 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3964 current_function_funcdef_no);
3965 ASM_OUTPUT_LABEL (asm_out_file, label);
3966 fde = current_fde ();
3967 gcc_assert (fde != NULL);
3968 fde->dw_fde_end = xstrdup (label);
3972 dwarf2out_frame_init (void)
3974 /* Allocate the initial hunk of the fde_table. */
3975 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3976 fde_table_allocated = FDE_TABLE_INCREMENT;
3977 fde_table_in_use = 0;
3979 /* Generate the CFA instructions common to all FDE's. Do it now for the
3980 sake of lookup_cfa. */
3982 /* On entry, the Canonical Frame Address is at SP. */
3983 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3985 #ifdef DWARF2_UNWIND_INFO
3986 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3987 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3992 dwarf2out_frame_finish (void)
3994 /* Output call frame information. */
3995 if (DWARF2_FRAME_INFO)
3996 output_call_frame_info (0);
3998 #ifndef TARGET_UNWIND_INFO
3999 /* Output another copy for the unwinder. */
4000 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4001 output_call_frame_info (1);
4005 /* Note that the current function section is being used for code. */
4008 dwarf2out_note_section_used (void)
4010 section *sec = current_function_section ();
4011 if (sec == text_section)
4012 text_section_used = true;
4013 else if (sec == cold_text_section)
4014 cold_text_section_used = true;
4018 dwarf2out_switch_text_section (void)
4020 dw_fde_ref fde = current_fde ();
4022 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4024 fde->dw_fde_switched_sections = 1;
4025 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4027 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4028 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4029 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4030 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4031 have_multiple_function_sections = true;
4033 /* Reset the current label on switching text sections, so that we
4034 don't attempt to advance_loc4 between labels in different sections. */
4035 fde->dw_fde_current_label = NULL;
4037 /* There is no need to mark used sections when not debugging. */
4038 if (cold_text_section != NULL)
4039 dwarf2out_note_section_used ();
4041 if (dwarf2out_do_cfi_asm ())
4042 fprintf (asm_out_file, "\t.cfi_endproc\n");
4044 /* Now do the real section switch. */
4045 switch_to_section (current_function_section ());
4047 if (dwarf2out_do_cfi_asm ())
4049 dwarf2out_do_cfi_startproc (true);
4050 /* As this is a different FDE, insert all current CFI instructions
4052 output_cfis (fde->dw_fde_cfi, true, fde, true);
4056 dw_cfi_ref cfi = fde->dw_fde_cfi;
4058 cfi = fde->dw_fde_cfi;
4060 while (cfi->dw_cfi_next != NULL)
4061 cfi = cfi->dw_cfi_next;
4062 fde->dw_fde_switch_cfi = cfi;
4067 /* And now, the subset of the debugging information support code necessary
4068 for emitting location expressions. */
4070 /* Data about a single source file. */
4071 struct GTY(()) dwarf_file_data {
4072 const char * filename;
4076 typedef struct dw_val_struct *dw_val_ref;
4077 typedef struct die_struct *dw_die_ref;
4078 typedef const struct die_struct *const_dw_die_ref;
4079 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4080 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4082 typedef struct GTY(()) deferred_locations_struct
4086 } deferred_locations;
4088 DEF_VEC_O(deferred_locations);
4089 DEF_VEC_ALLOC_O(deferred_locations,gc);
4091 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4093 /* Each DIE may have a series of attribute/value pairs. Values
4094 can take on several forms. The forms that are used in this
4095 implementation are listed below. */
4100 dw_val_class_offset,
4102 dw_val_class_loc_list,
4103 dw_val_class_range_list,
4105 dw_val_class_unsigned_const,
4106 dw_val_class_long_long,
4109 dw_val_class_die_ref,
4110 dw_val_class_fde_ref,
4111 dw_val_class_lbl_id,
4112 dw_val_class_lineptr,
4114 dw_val_class_macptr,
4118 /* Describe a double word constant value. */
4119 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
4121 typedef struct GTY(()) dw_long_long_struct {
4127 /* Describe a floating point constant value, or a vector constant value. */
4129 typedef struct GTY(()) dw_vec_struct {
4130 unsigned char * GTY((length ("%h.length"))) array;
4136 /* The dw_val_node describes an attribute's value, as it is
4137 represented internally. */
4139 typedef struct GTY(()) dw_val_struct {
4140 enum dw_val_class val_class;
4141 union dw_val_struct_union
4143 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4144 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4145 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4146 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4147 HOST_WIDE_INT GTY ((default)) val_int;
4148 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4149 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
4150 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4151 struct dw_val_die_union
4155 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4156 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4157 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4158 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4159 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4160 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4162 GTY ((desc ("%1.val_class"))) v;
4166 /* Locations in memory are described using a sequence of stack machine
4169 typedef struct GTY(()) dw_loc_descr_struct {
4170 dw_loc_descr_ref dw_loc_next;
4171 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4172 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4173 from DW_OP_addr with a dtp-relative symbol relocation. */
4174 unsigned int dtprel : 1;
4176 dw_val_node dw_loc_oprnd1;
4177 dw_val_node dw_loc_oprnd2;
4181 /* Location lists are ranges + location descriptions for that range,
4182 so you can track variables that are in different places over
4183 their entire life. */
4184 typedef struct GTY(()) dw_loc_list_struct {
4185 dw_loc_list_ref dw_loc_next;
4186 const char *begin; /* Label for begin address of range */
4187 const char *end; /* Label for end address of range */
4188 char *ll_symbol; /* Label for beginning of location list.
4189 Only on head of list */
4190 const char *section; /* Section this loclist is relative to */
4191 dw_loc_descr_ref expr;
4194 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
4196 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4198 /* Convert a DWARF stack opcode into its string name. */
4201 dwarf_stack_op_name (unsigned int op)
4206 return "DW_OP_addr";
4208 return "DW_OP_deref";
4210 return "DW_OP_const1u";
4212 return "DW_OP_const1s";
4214 return "DW_OP_const2u";
4216 return "DW_OP_const2s";
4218 return "DW_OP_const4u";
4220 return "DW_OP_const4s";
4222 return "DW_OP_const8u";
4224 return "DW_OP_const8s";
4226 return "DW_OP_constu";
4228 return "DW_OP_consts";
4232 return "DW_OP_drop";
4234 return "DW_OP_over";
4236 return "DW_OP_pick";
4238 return "DW_OP_swap";
4242 return "DW_OP_xderef";
4250 return "DW_OP_minus";
4262 return "DW_OP_plus";
4263 case DW_OP_plus_uconst:
4264 return "DW_OP_plus_uconst";
4270 return "DW_OP_shra";
4288 return "DW_OP_skip";
4290 return "DW_OP_lit0";
4292 return "DW_OP_lit1";
4294 return "DW_OP_lit2";
4296 return "DW_OP_lit3";
4298 return "DW_OP_lit4";
4300 return "DW_OP_lit5";
4302 return "DW_OP_lit6";
4304 return "DW_OP_lit7";
4306 return "DW_OP_lit8";
4308 return "DW_OP_lit9";
4310 return "DW_OP_lit10";
4312 return "DW_OP_lit11";
4314 return "DW_OP_lit12";
4316 return "DW_OP_lit13";
4318 return "DW_OP_lit14";
4320 return "DW_OP_lit15";
4322 return "DW_OP_lit16";
4324 return "DW_OP_lit17";
4326 return "DW_OP_lit18";
4328 return "DW_OP_lit19";
4330 return "DW_OP_lit20";
4332 return "DW_OP_lit21";
4334 return "DW_OP_lit22";
4336 return "DW_OP_lit23";
4338 return "DW_OP_lit24";
4340 return "DW_OP_lit25";
4342 return "DW_OP_lit26";
4344 return "DW_OP_lit27";
4346 return "DW_OP_lit28";
4348 return "DW_OP_lit29";
4350 return "DW_OP_lit30";
4352 return "DW_OP_lit31";
4354 return "DW_OP_reg0";
4356 return "DW_OP_reg1";
4358 return "DW_OP_reg2";
4360 return "DW_OP_reg3";
4362 return "DW_OP_reg4";
4364 return "DW_OP_reg5";
4366 return "DW_OP_reg6";
4368 return "DW_OP_reg7";
4370 return "DW_OP_reg8";
4372 return "DW_OP_reg9";
4374 return "DW_OP_reg10";
4376 return "DW_OP_reg11";
4378 return "DW_OP_reg12";
4380 return "DW_OP_reg13";
4382 return "DW_OP_reg14";
4384 return "DW_OP_reg15";
4386 return "DW_OP_reg16";
4388 return "DW_OP_reg17";
4390 return "DW_OP_reg18";
4392 return "DW_OP_reg19";
4394 return "DW_OP_reg20";
4396 return "DW_OP_reg21";
4398 return "DW_OP_reg22";
4400 return "DW_OP_reg23";
4402 return "DW_OP_reg24";
4404 return "DW_OP_reg25";
4406 return "DW_OP_reg26";
4408 return "DW_OP_reg27";
4410 return "DW_OP_reg28";
4412 return "DW_OP_reg29";
4414 return "DW_OP_reg30";
4416 return "DW_OP_reg31";
4418 return "DW_OP_breg0";
4420 return "DW_OP_breg1";
4422 return "DW_OP_breg2";
4424 return "DW_OP_breg3";
4426 return "DW_OP_breg4";
4428 return "DW_OP_breg5";
4430 return "DW_OP_breg6";
4432 return "DW_OP_breg7";
4434 return "DW_OP_breg8";
4436 return "DW_OP_breg9";
4438 return "DW_OP_breg10";
4440 return "DW_OP_breg11";
4442 return "DW_OP_breg12";
4444 return "DW_OP_breg13";
4446 return "DW_OP_breg14";
4448 return "DW_OP_breg15";
4450 return "DW_OP_breg16";
4452 return "DW_OP_breg17";
4454 return "DW_OP_breg18";
4456 return "DW_OP_breg19";
4458 return "DW_OP_breg20";
4460 return "DW_OP_breg21";
4462 return "DW_OP_breg22";
4464 return "DW_OP_breg23";
4466 return "DW_OP_breg24";
4468 return "DW_OP_breg25";
4470 return "DW_OP_breg26";
4472 return "DW_OP_breg27";
4474 return "DW_OP_breg28";
4476 return "DW_OP_breg29";
4478 return "DW_OP_breg30";
4480 return "DW_OP_breg31";
4482 return "DW_OP_regx";
4484 return "DW_OP_fbreg";
4486 return "DW_OP_bregx";
4488 return "DW_OP_piece";
4489 case DW_OP_deref_size:
4490 return "DW_OP_deref_size";
4491 case DW_OP_xderef_size:
4492 return "DW_OP_xderef_size";
4496 case DW_OP_push_object_address:
4497 return "DW_OP_push_object_address";
4499 return "DW_OP_call2";
4501 return "DW_OP_call4";
4502 case DW_OP_call_ref:
4503 return "DW_OP_call_ref";
4504 case DW_OP_form_tls_address:
4505 return "DW_OP_form_tls_address";
4506 case DW_OP_call_frame_cfa:
4507 return "DW_OP_call_frame_cfa";
4508 case DW_OP_bit_piece:
4509 return "DW_OP_bit_piece";
4511 case DW_OP_GNU_push_tls_address:
4512 return "DW_OP_GNU_push_tls_address";
4513 case DW_OP_GNU_uninit:
4514 return "DW_OP_GNU_uninit";
4515 case DW_OP_GNU_encoded_addr:
4516 return "DW_OP_GNU_encoded_addr";
4519 return "OP_<unknown>";
4523 /* Return a pointer to a newly allocated location description. Location
4524 descriptions are simple expression terms that can be strung
4525 together to form more complicated location (address) descriptions. */
4527 static inline dw_loc_descr_ref
4528 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4529 unsigned HOST_WIDE_INT oprnd2)
4531 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4533 descr->dw_loc_opc = op;
4534 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4535 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4536 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4537 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4542 /* Return a pointer to a newly allocated location description for
4545 static inline dw_loc_descr_ref
4546 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4549 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4552 return new_loc_descr (DW_OP_bregx, reg, offset);
4555 /* Add a location description term to a location description expression. */
4558 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4560 dw_loc_descr_ref *d;
4562 /* Find the end of the chain. */
4563 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4569 /* Add a constant OFFSET to a location expression. */
4572 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4574 dw_loc_descr_ref loc;
4577 gcc_assert (*list_head != NULL);
4582 /* Find the end of the chain. */
4583 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4587 if (loc->dw_loc_opc == DW_OP_fbreg
4588 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4589 p = &loc->dw_loc_oprnd1.v.val_int;
4590 else if (loc->dw_loc_opc == DW_OP_bregx)
4591 p = &loc->dw_loc_oprnd2.v.val_int;
4593 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4594 offset. Don't optimize if an signed integer overflow would happen. */
4596 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4597 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4600 else if (offset > 0)
4601 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4605 loc->dw_loc_next = int_loc_descriptor (offset);
4606 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4610 /* Return the size of a location descriptor. */
4612 static unsigned long
4613 size_of_loc_descr (dw_loc_descr_ref loc)
4615 unsigned long size = 1;
4617 switch (loc->dw_loc_opc)
4620 size += DWARF2_ADDR_SIZE;
4639 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4642 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4647 case DW_OP_plus_uconst:
4648 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4686 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4689 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4692 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4695 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4696 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4699 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4701 case DW_OP_deref_size:
4702 case DW_OP_xderef_size:
4711 case DW_OP_call_ref:
4712 size += DWARF2_ADDR_SIZE;
4721 /* Return the size of a series of location descriptors. */
4723 static unsigned long
4724 size_of_locs (dw_loc_descr_ref loc)
4729 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4730 field, to avoid writing to a PCH file. */
4731 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4733 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4735 size += size_of_loc_descr (l);
4740 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4742 l->dw_loc_addr = size;
4743 size += size_of_loc_descr (l);
4749 /* Output location description stack opcode's operands (if any). */
4752 output_loc_operands (dw_loc_descr_ref loc)
4754 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4755 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4757 switch (loc->dw_loc_opc)
4759 #ifdef DWARF2_DEBUGGING_INFO
4762 dw2_asm_output_data (2, val1->v.val_int, NULL);
4766 dw2_asm_output_data (4, val1->v.val_int, NULL);
4770 gcc_assert (HOST_BITS_PER_LONG >= 64);
4771 dw2_asm_output_data (8, val1->v.val_int, NULL);
4778 gcc_assert (val1->val_class == dw_val_class_loc);
4779 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4781 dw2_asm_output_data (2, offset, NULL);
4793 /* We currently don't make any attempt to make sure these are
4794 aligned properly like we do for the main unwind info, so
4795 don't support emitting things larger than a byte if we're
4796 only doing unwinding. */
4801 dw2_asm_output_data (1, val1->v.val_int, NULL);
4804 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4807 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4810 dw2_asm_output_data (1, val1->v.val_int, NULL);
4812 case DW_OP_plus_uconst:
4813 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4847 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4850 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4853 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4856 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4857 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4860 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4862 case DW_OP_deref_size:
4863 case DW_OP_xderef_size:
4864 dw2_asm_output_data (1, val1->v.val_int, NULL);
4870 if (targetm.asm_out.output_dwarf_dtprel)
4872 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4875 fputc ('\n', asm_out_file);
4882 #ifdef DWARF2_DEBUGGING_INFO
4883 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4891 /* Other codes have no operands. */
4896 /* Output a sequence of location operations. */
4899 output_loc_sequence (dw_loc_descr_ref loc)
4901 for (; loc != NULL; loc = loc->dw_loc_next)
4903 /* Output the opcode. */
4904 dw2_asm_output_data (1, loc->dw_loc_opc,
4905 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4907 /* Output the operand(s) (if any). */
4908 output_loc_operands (loc);
4912 /* Output location description stack opcode's operands (if any).
4913 The output is single bytes on a line, suitable for .cfi_escape. */
4916 output_loc_operands_raw (dw_loc_descr_ref loc)
4918 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4919 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4921 switch (loc->dw_loc_opc)
4924 /* We cannot output addresses in .cfi_escape, only bytes. */
4930 case DW_OP_deref_size:
4931 case DW_OP_xderef_size:
4932 fputc (',', asm_out_file);
4933 dw2_asm_output_data_raw (1, val1->v.val_int);
4938 fputc (',', asm_out_file);
4939 dw2_asm_output_data_raw (2, val1->v.val_int);
4944 fputc (',', asm_out_file);
4945 dw2_asm_output_data_raw (4, val1->v.val_int);
4950 gcc_assert (HOST_BITS_PER_LONG >= 64);
4951 fputc (',', asm_out_file);
4952 dw2_asm_output_data_raw (8, val1->v.val_int);
4960 gcc_assert (val1->val_class == dw_val_class_loc);
4961 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4963 fputc (',', asm_out_file);
4964 dw2_asm_output_data_raw (2, offset);
4969 case DW_OP_plus_uconst:
4972 fputc (',', asm_out_file);
4973 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5010 fputc (',', asm_out_file);
5011 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5015 fputc (',', asm_out_file);
5016 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5017 fputc (',', asm_out_file);
5018 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5022 /* Other codes have no operands. */
5028 output_loc_sequence_raw (dw_loc_descr_ref loc)
5032 /* Output the opcode. */
5033 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
5034 output_loc_operands_raw (loc);
5036 if (!loc->dw_loc_next)
5038 loc = loc->dw_loc_next;
5040 fputc (',', asm_out_file);
5044 /* This routine will generate the correct assembly data for a location
5045 description based on a cfi entry with a complex address. */
5048 output_cfa_loc (dw_cfi_ref cfi)
5050 dw_loc_descr_ref loc;
5053 if (cfi->dw_cfi_opc == DW_CFA_expression)
5054 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
5056 /* Output the size of the block. */
5057 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5058 size = size_of_locs (loc);
5059 dw2_asm_output_data_uleb128 (size, NULL);
5061 /* Now output the operations themselves. */
5062 output_loc_sequence (loc);
5065 /* Similar, but used for .cfi_escape. */
5068 output_cfa_loc_raw (dw_cfi_ref cfi)
5070 dw_loc_descr_ref loc;
5073 if (cfi->dw_cfi_opc == DW_CFA_expression)
5074 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
5076 /* Output the size of the block. */
5077 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5078 size = size_of_locs (loc);
5079 dw2_asm_output_data_uleb128_raw (size);
5080 fputc (',', asm_out_file);
5082 /* Now output the operations themselves. */
5083 output_loc_sequence_raw (loc);
5086 /* This function builds a dwarf location descriptor sequence from a
5087 dw_cfa_location, adding the given OFFSET to the result of the
5090 static struct dw_loc_descr_struct *
5091 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5093 struct dw_loc_descr_struct *head, *tmp;
5095 offset += cfa->offset;
5099 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5100 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5101 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5102 add_loc_descr (&head, tmp);
5105 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5106 add_loc_descr (&head, tmp);
5110 head = new_reg_loc_descr (cfa->reg, offset);
5115 /* This function builds a dwarf location descriptor sequence for
5116 the address at OFFSET from the CFA when stack is aligned to
5119 static struct dw_loc_descr_struct *
5120 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5122 struct dw_loc_descr_struct *head;
5123 unsigned int dwarf_fp
5124 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5126 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5127 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5129 head = new_reg_loc_descr (dwarf_fp, 0);
5130 add_loc_descr (&head, int_loc_descriptor (alignment));
5131 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5132 loc_descr_plus_const (&head, offset);
5135 head = new_reg_loc_descr (dwarf_fp, offset);
5139 /* This function fills in aa dw_cfa_location structure from a dwarf location
5140 descriptor sequence. */
5143 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5145 struct dw_loc_descr_struct *ptr;
5147 cfa->base_offset = 0;
5151 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5153 enum dwarf_location_atom op = ptr->dw_loc_opc;
5189 cfa->reg = op - DW_OP_reg0;
5192 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5226 cfa->reg = op - DW_OP_breg0;
5227 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5230 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5231 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5236 case DW_OP_plus_uconst:
5237 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5240 internal_error ("DW_LOC_OP %s not implemented",
5241 dwarf_stack_op_name (ptr->dw_loc_opc));
5245 #endif /* .debug_frame support */
5247 /* And now, the support for symbolic debugging information. */
5248 #ifdef DWARF2_DEBUGGING_INFO
5250 /* .debug_str support. */
5251 static int output_indirect_string (void **, void *);
5253 static void dwarf2out_init (const char *);
5254 static void dwarf2out_finish (const char *);
5255 static void dwarf2out_define (unsigned int, const char *);
5256 static void dwarf2out_undef (unsigned int, const char *);
5257 static void dwarf2out_start_source_file (unsigned, const char *);
5258 static void dwarf2out_end_source_file (unsigned);
5259 static void dwarf2out_begin_block (unsigned, unsigned);
5260 static void dwarf2out_end_block (unsigned, unsigned);
5261 static bool dwarf2out_ignore_block (const_tree);
5262 static void dwarf2out_global_decl (tree);
5263 static void dwarf2out_type_decl (tree, int);
5264 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5265 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5267 static void dwarf2out_abstract_function (tree);
5268 static void dwarf2out_var_location (rtx);
5269 static void dwarf2out_begin_function (tree);
5270 static void dwarf2out_set_name (tree, tree);
5272 /* The debug hooks structure. */
5274 const struct gcc_debug_hooks dwarf2_debug_hooks =
5280 dwarf2out_start_source_file,
5281 dwarf2out_end_source_file,
5282 dwarf2out_begin_block,
5283 dwarf2out_end_block,
5284 dwarf2out_ignore_block,
5285 dwarf2out_source_line,
5286 dwarf2out_begin_prologue,
5287 debug_nothing_int_charstar, /* end_prologue */
5288 dwarf2out_end_epilogue,
5289 dwarf2out_begin_function,
5290 debug_nothing_int, /* end_function */
5291 dwarf2out_decl, /* function_decl */
5292 dwarf2out_global_decl,
5293 dwarf2out_type_decl, /* type_decl */
5294 dwarf2out_imported_module_or_decl,
5295 debug_nothing_tree, /* deferred_inline_function */
5296 /* The DWARF 2 backend tries to reduce debugging bloat by not
5297 emitting the abstract description of inline functions until
5298 something tries to reference them. */
5299 dwarf2out_abstract_function, /* outlining_inline_function */
5300 debug_nothing_rtx, /* label */
5301 debug_nothing_int, /* handle_pch */
5302 dwarf2out_var_location,
5303 dwarf2out_switch_text_section,
5305 1 /* start_end_main_source_file */
5309 /* NOTE: In the comments in this file, many references are made to
5310 "Debugging Information Entries". This term is abbreviated as `DIE'
5311 throughout the remainder of this file. */
5313 /* An internal representation of the DWARF output is built, and then
5314 walked to generate the DWARF debugging info. The walk of the internal
5315 representation is done after the entire program has been compiled.
5316 The types below are used to describe the internal representation. */
5318 /* Various DIE's use offsets relative to the beginning of the
5319 .debug_info section to refer to each other. */
5321 typedef long int dw_offset;
5323 /* Define typedefs here to avoid circular dependencies. */
5325 typedef struct dw_attr_struct *dw_attr_ref;
5326 typedef struct dw_line_info_struct *dw_line_info_ref;
5327 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5328 typedef struct pubname_struct *pubname_ref;
5329 typedef struct dw_ranges_struct *dw_ranges_ref;
5330 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5332 /* Each entry in the line_info_table maintains the file and
5333 line number associated with the label generated for that
5334 entry. The label gives the PC value associated with
5335 the line number entry. */
5337 typedef struct GTY(()) dw_line_info_struct {
5338 unsigned long dw_file_num;
5339 unsigned long dw_line_num;
5343 /* Line information for functions in separate sections; each one gets its
5345 typedef struct GTY(()) dw_separate_line_info_struct {
5346 unsigned long dw_file_num;
5347 unsigned long dw_line_num;
5348 unsigned long function;
5350 dw_separate_line_info_entry;
5352 /* Each DIE attribute has a field specifying the attribute kind,
5353 a link to the next attribute in the chain, and an attribute value.
5354 Attributes are typically linked below the DIE they modify. */
5356 typedef struct GTY(()) dw_attr_struct {
5357 enum dwarf_attribute dw_attr;
5358 dw_val_node dw_attr_val;
5362 DEF_VEC_O(dw_attr_node);
5363 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5365 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5366 The children of each node form a circular list linked by
5367 die_sib. die_child points to the node *before* the "first" child node. */
5369 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5370 enum dwarf_tag die_tag;
5372 VEC(dw_attr_node,gc) * die_attr;
5373 dw_die_ref die_parent;
5374 dw_die_ref die_child;
5376 dw_die_ref die_definition; /* ref from a specification to its definition */
5377 dw_offset die_offset;
5378 unsigned long die_abbrev;
5380 /* Die is used and must not be pruned as unused. */
5381 int die_perennial_p;
5382 unsigned int decl_id;
5386 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5387 #define FOR_EACH_CHILD(die, c, expr) do { \
5388 c = die->die_child; \
5392 } while (c != die->die_child); \
5395 /* The pubname structure */
5397 typedef struct GTY(()) pubname_struct {
5403 DEF_VEC_O(pubname_entry);
5404 DEF_VEC_ALLOC_O(pubname_entry, gc);
5406 struct GTY(()) dw_ranges_struct {
5407 /* If this is positive, it's a block number, otherwise it's a
5408 bitwise-negated index into dw_ranges_by_label. */
5412 struct GTY(()) dw_ranges_by_label_struct {
5417 /* The limbo die list structure. */
5418 typedef struct GTY(()) limbo_die_struct {
5421 struct limbo_die_struct *next;
5425 /* How to start an assembler comment. */
5426 #ifndef ASM_COMMENT_START
5427 #define ASM_COMMENT_START ";#"
5430 /* Define a macro which returns nonzero for a TYPE_DECL which was
5431 implicitly generated for a tagged type.
5433 Note that unlike the gcc front end (which generates a NULL named
5434 TYPE_DECL node for each complete tagged type, each array type, and
5435 each function type node created) the g++ front end generates a
5436 _named_ TYPE_DECL node for each tagged type node created.
5437 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5438 generate a DW_TAG_typedef DIE for them. */
5440 #define TYPE_DECL_IS_STUB(decl) \
5441 (DECL_NAME (decl) == NULL_TREE \
5442 || (DECL_ARTIFICIAL (decl) \
5443 && is_tagged_type (TREE_TYPE (decl)) \
5444 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5445 /* This is necessary for stub decls that \
5446 appear in nested inline functions. */ \
5447 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5448 && (decl_ultimate_origin (decl) \
5449 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5451 /* Information concerning the compilation unit's programming
5452 language, and compiler version. */
5454 /* Fixed size portion of the DWARF compilation unit header. */
5455 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5456 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5458 /* Fixed size portion of public names info. */
5459 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5461 /* Fixed size portion of the address range info. */
5462 #define DWARF_ARANGES_HEADER_SIZE \
5463 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5464 DWARF2_ADDR_SIZE * 2) \
5465 - DWARF_INITIAL_LENGTH_SIZE)
5467 /* Size of padding portion in the address range info. It must be
5468 aligned to twice the pointer size. */
5469 #define DWARF_ARANGES_PAD_SIZE \
5470 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5471 DWARF2_ADDR_SIZE * 2) \
5472 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5474 /* Use assembler line directives if available. */
5475 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5476 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5477 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5479 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5483 /* Minimum line offset in a special line info. opcode.
5484 This value was chosen to give a reasonable range of values. */
5485 #define DWARF_LINE_BASE -10
5487 /* First special line opcode - leave room for the standard opcodes. */
5488 #define DWARF_LINE_OPCODE_BASE 10
5490 /* Range of line offsets in a special line info. opcode. */
5491 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5493 /* Flag that indicates the initial value of the is_stmt_start flag.
5494 In the present implementation, we do not mark any lines as
5495 the beginning of a source statement, because that information
5496 is not made available by the GCC front-end. */
5497 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5499 #ifdef DWARF2_DEBUGGING_INFO
5500 /* This location is used by calc_die_sizes() to keep track
5501 the offset of each DIE within the .debug_info section. */
5502 static unsigned long next_die_offset;
5505 /* Record the root of the DIE's built for the current compilation unit. */
5506 static GTY(()) dw_die_ref comp_unit_die;
5508 /* A list of DIEs with a NULL parent waiting to be relocated. */
5509 static GTY(()) limbo_die_node *limbo_die_list;
5511 /* A list of DIEs for which we may have to generate
5512 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5514 static GTY(()) limbo_die_node *deferred_asm_name;
5516 /* Filenames referenced by this compilation unit. */
5517 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5519 /* A hash table of references to DIE's that describe declarations.
5520 The key is a DECL_UID() which is a unique number identifying each decl. */
5521 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5523 /* A hash table of references to DIE's that describe COMMON blocks.
5524 The key is DECL_UID() ^ die_parent. */
5525 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5527 /* Node of the variable location list. */
5528 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5529 rtx GTY (()) var_loc_note;
5530 const char * GTY (()) label;
5531 const char * GTY (()) section_label;
5532 struct var_loc_node * GTY (()) next;
5535 /* Variable location list. */
5536 struct GTY (()) var_loc_list_def {
5537 struct var_loc_node * GTY (()) first;
5539 /* Do not mark the last element of the chained list because
5540 it is marked through the chain. */
5541 struct var_loc_node * GTY ((skip ("%h"))) last;
5543 /* DECL_UID of the variable decl. */
5544 unsigned int decl_id;
5546 typedef struct var_loc_list_def var_loc_list;
5549 /* Table of decl location linked lists. */
5550 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5552 /* A pointer to the base of a list of references to DIE's that
5553 are uniquely identified by their tag, presence/absence of
5554 children DIE's, and list of attribute/value pairs. */
5555 static GTY((length ("abbrev_die_table_allocated")))
5556 dw_die_ref *abbrev_die_table;
5558 /* Number of elements currently allocated for abbrev_die_table. */
5559 static GTY(()) unsigned abbrev_die_table_allocated;
5561 /* Number of elements in type_die_table currently in use. */
5562 static GTY(()) unsigned abbrev_die_table_in_use;
5564 /* Size (in elements) of increments by which we may expand the
5565 abbrev_die_table. */
5566 #define ABBREV_DIE_TABLE_INCREMENT 256
5568 /* A pointer to the base of a table that contains line information
5569 for each source code line in .text in the compilation unit. */
5570 static GTY((length ("line_info_table_allocated")))
5571 dw_line_info_ref line_info_table;
5573 /* Number of elements currently allocated for line_info_table. */
5574 static GTY(()) unsigned line_info_table_allocated;
5576 /* Number of elements in line_info_table currently in use. */
5577 static GTY(()) unsigned line_info_table_in_use;
5579 /* A pointer to the base of a table that contains line information
5580 for each source code line outside of .text in the compilation unit. */
5581 static GTY ((length ("separate_line_info_table_allocated")))
5582 dw_separate_line_info_ref separate_line_info_table;
5584 /* Number of elements currently allocated for separate_line_info_table. */
5585 static GTY(()) unsigned separate_line_info_table_allocated;
5587 /* Number of elements in separate_line_info_table currently in use. */
5588 static GTY(()) unsigned separate_line_info_table_in_use;
5590 /* Size (in elements) of increments by which we may expand the
5592 #define LINE_INFO_TABLE_INCREMENT 1024
5594 /* A pointer to the base of a table that contains a list of publicly
5595 accessible names. */
5596 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5598 /* A pointer to the base of a table that contains a list of publicly
5599 accessible types. */
5600 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5602 /* Array of dies for which we should generate .debug_arange info. */
5603 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5605 /* Number of elements currently allocated for arange_table. */
5606 static GTY(()) unsigned arange_table_allocated;
5608 /* Number of elements in arange_table currently in use. */
5609 static GTY(()) unsigned arange_table_in_use;
5611 /* Size (in elements) of increments by which we may expand the
5613 #define ARANGE_TABLE_INCREMENT 64
5615 /* Array of dies for which we should generate .debug_ranges info. */
5616 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5618 /* Number of elements currently allocated for ranges_table. */
5619 static GTY(()) unsigned ranges_table_allocated;
5621 /* Number of elements in ranges_table currently in use. */
5622 static GTY(()) unsigned ranges_table_in_use;
5624 /* Array of pairs of labels referenced in ranges_table. */
5625 static GTY ((length ("ranges_by_label_allocated")))
5626 dw_ranges_by_label_ref ranges_by_label;
5628 /* Number of elements currently allocated for ranges_by_label. */
5629 static GTY(()) unsigned ranges_by_label_allocated;
5631 /* Number of elements in ranges_by_label currently in use. */
5632 static GTY(()) unsigned ranges_by_label_in_use;
5634 /* Size (in elements) of increments by which we may expand the
5636 #define RANGES_TABLE_INCREMENT 64
5638 /* Whether we have location lists that need outputting */
5639 static GTY(()) bool have_location_lists;
5641 /* Unique label counter. */
5642 static GTY(()) unsigned int loclabel_num;
5644 #ifdef DWARF2_DEBUGGING_INFO
5645 /* Record whether the function being analyzed contains inlined functions. */
5646 static int current_function_has_inlines;
5648 #if 0 && defined (MIPS_DEBUGGING_INFO)
5649 static int comp_unit_has_inlines;
5652 /* The last file entry emitted by maybe_emit_file(). */
5653 static GTY(()) struct dwarf_file_data * last_emitted_file;
5655 /* Number of internal labels generated by gen_internal_sym(). */
5656 static GTY(()) int label_num;
5658 /* Cached result of previous call to lookup_filename. */
5659 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5661 #ifdef DWARF2_DEBUGGING_INFO
5663 /* Offset from the "steady-state frame pointer" to the frame base,
5664 within the current function. */
5665 static HOST_WIDE_INT frame_pointer_fb_offset;
5667 /* Forward declarations for functions defined in this file. */
5669 static int is_pseudo_reg (const_rtx);
5670 static tree type_main_variant (tree);
5671 static int is_tagged_type (const_tree);
5672 static const char *dwarf_tag_name (unsigned);
5673 static const char *dwarf_attr_name (unsigned);
5674 static const char *dwarf_form_name (unsigned);
5675 static tree decl_ultimate_origin (const_tree);
5676 static tree decl_class_context (tree);
5677 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5678 static inline enum dw_val_class AT_class (dw_attr_ref);
5679 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5680 static inline unsigned AT_flag (dw_attr_ref);
5681 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5682 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5683 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5684 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5685 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
5687 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5688 unsigned int, unsigned char *);
5689 static hashval_t debug_str_do_hash (const void *);
5690 static int debug_str_eq (const void *, const void *);
5691 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5692 static inline const char *AT_string (dw_attr_ref);
5693 static enum dwarf_form AT_string_form (dw_attr_ref);
5694 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5695 static void add_AT_specification (dw_die_ref, dw_die_ref);
5696 static inline dw_die_ref AT_ref (dw_attr_ref);
5697 static inline int AT_ref_external (dw_attr_ref);
5698 static inline void set_AT_ref_external (dw_attr_ref, int);
5699 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5700 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5701 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5702 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5704 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5705 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5706 static inline rtx AT_addr (dw_attr_ref);
5707 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5708 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5709 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5710 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5711 unsigned HOST_WIDE_INT);
5712 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5714 static inline const char *AT_lbl (dw_attr_ref);
5715 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5716 static const char *get_AT_low_pc (dw_die_ref);
5717 static const char *get_AT_hi_pc (dw_die_ref);
5718 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5719 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5720 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5721 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5722 static bool is_c_family (void);
5723 static bool is_cxx (void);
5724 static bool is_java (void);
5725 static bool is_fortran (void);
5726 static bool is_ada (void);
5727 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5728 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5729 static void add_child_die (dw_die_ref, dw_die_ref);
5730 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5731 static dw_die_ref lookup_type_die (tree);
5732 static void equate_type_number_to_die (tree, dw_die_ref);
5733 static hashval_t decl_die_table_hash (const void *);
5734 static int decl_die_table_eq (const void *, const void *);
5735 static dw_die_ref lookup_decl_die (tree);
5736 static hashval_t common_block_die_table_hash (const void *);
5737 static int common_block_die_table_eq (const void *, const void *);
5738 static hashval_t decl_loc_table_hash (const void *);
5739 static int decl_loc_table_eq (const void *, const void *);
5740 static var_loc_list *lookup_decl_loc (const_tree);
5741 static void equate_decl_number_to_die (tree, dw_die_ref);
5742 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5743 static void print_spaces (FILE *);
5744 static void print_die (dw_die_ref, FILE *);
5745 static void print_dwarf_line_table (FILE *);
5746 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5747 static dw_die_ref pop_compile_unit (dw_die_ref);
5748 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5749 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5750 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5751 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5752 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5753 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5754 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5755 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5756 static void compute_section_prefix (dw_die_ref);
5757 static int is_type_die (dw_die_ref);
5758 static int is_comdat_die (dw_die_ref);
5759 static int is_symbol_die (dw_die_ref);
5760 static void assign_symbol_names (dw_die_ref);
5761 static void break_out_includes (dw_die_ref);
5762 static hashval_t htab_cu_hash (const void *);
5763 static int htab_cu_eq (const void *, const void *);
5764 static void htab_cu_del (void *);
5765 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5766 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5767 static void add_sibling_attributes (dw_die_ref);
5768 static void build_abbrev_table (dw_die_ref);
5769 static void output_location_lists (dw_die_ref);
5770 static int constant_size (unsigned HOST_WIDE_INT);
5771 static unsigned long size_of_die (dw_die_ref);
5772 static void calc_die_sizes (dw_die_ref);
5773 static void mark_dies (dw_die_ref);
5774 static void unmark_dies (dw_die_ref);
5775 static void unmark_all_dies (dw_die_ref);
5776 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5777 static unsigned long size_of_aranges (void);
5778 static enum dwarf_form value_format (dw_attr_ref);
5779 static void output_value_format (dw_attr_ref);
5780 static void output_abbrev_section (void);
5781 static void output_die_symbol (dw_die_ref);
5782 static void output_die (dw_die_ref);
5783 static void output_compilation_unit_header (void);
5784 static void output_comp_unit (dw_die_ref, int);
5785 static const char *dwarf2_name (tree, int);
5786 static void add_pubname (tree, dw_die_ref);
5787 static void add_pubname_string (const char *, dw_die_ref);
5788 static void add_pubtype (tree, dw_die_ref);
5789 static void output_pubnames (VEC (pubname_entry,gc) *);
5790 static void add_arange (tree, dw_die_ref);
5791 static void output_aranges (void);
5792 static unsigned int add_ranges_num (int);
5793 static unsigned int add_ranges (const_tree);
5794 static unsigned int add_ranges_by_labels (const char *, const char *);
5795 static void output_ranges (void);
5796 static void output_line_info (void);
5797 static void output_file_names (void);
5798 static dw_die_ref base_type_die (tree);
5799 static int is_base_type (tree);
5800 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5801 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5802 static int type_is_enum (const_tree);
5803 static unsigned int dbx_reg_number (const_rtx);
5804 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5805 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5806 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5807 enum var_init_status);
5808 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5809 enum var_init_status);
5810 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5811 enum var_init_status);
5812 static int is_based_loc (const_rtx);
5813 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5814 enum var_init_status);
5815 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5816 enum var_init_status);
5817 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5818 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5819 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5820 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5821 static tree field_type (const_tree);
5822 static unsigned int simple_type_align_in_bits (const_tree);
5823 static unsigned int simple_decl_align_in_bits (const_tree);
5824 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5825 static HOST_WIDE_INT field_byte_offset (const_tree);
5826 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5828 static void add_data_member_location_attribute (dw_die_ref, tree);
5829 static void add_const_value_attribute (dw_die_ref, rtx);
5830 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5831 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5832 static void insert_float (const_rtx, unsigned char *);
5833 static rtx rtl_for_decl_location (tree);
5834 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5835 enum dwarf_attribute);
5836 static void tree_add_const_value_attribute (dw_die_ref, tree);
5837 static void add_name_attribute (dw_die_ref, const char *);
5838 static void add_comp_dir_attribute (dw_die_ref);
5839 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5840 static void add_subscript_info (dw_die_ref, tree, bool);
5841 static void add_byte_size_attribute (dw_die_ref, tree);
5842 static void add_bit_offset_attribute (dw_die_ref, tree);
5843 static void add_bit_size_attribute (dw_die_ref, tree);
5844 static void add_prototyped_attribute (dw_die_ref, tree);
5845 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5846 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5847 static void add_src_coords_attributes (dw_die_ref, tree);
5848 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5849 static void push_decl_scope (tree);
5850 static void pop_decl_scope (void);
5851 static dw_die_ref scope_die_for (tree, dw_die_ref);
5852 static inline int local_scope_p (dw_die_ref);
5853 static inline int class_scope_p (dw_die_ref);
5854 static inline int class_or_namespace_scope_p (dw_die_ref);
5855 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5856 static void add_calling_convention_attribute (dw_die_ref, tree);
5857 static const char *type_tag (const_tree);
5858 static tree member_declared_type (const_tree);
5860 static const char *decl_start_label (tree);
5862 static void gen_array_type_die (tree, dw_die_ref);
5863 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5865 static void gen_entry_point_die (tree, dw_die_ref);
5867 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5868 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5869 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5870 static void gen_formal_types_die (tree, dw_die_ref);
5871 static void gen_subprogram_die (tree, dw_die_ref);
5872 static void gen_variable_die (tree, tree, dw_die_ref);
5873 static void gen_const_die (tree, dw_die_ref);
5874 static void gen_label_die (tree, dw_die_ref);
5875 static void gen_lexical_block_die (tree, dw_die_ref, int);
5876 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5877 static void gen_field_die (tree, dw_die_ref);
5878 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5879 static dw_die_ref gen_compile_unit_die (const char *);
5880 static void gen_inheritance_die (tree, tree, dw_die_ref);
5881 static void gen_member_die (tree, dw_die_ref);
5882 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5883 enum debug_info_usage);
5884 static void gen_subroutine_type_die (tree, dw_die_ref);
5885 static void gen_typedef_die (tree, dw_die_ref);
5886 static void gen_type_die (tree, dw_die_ref);
5887 static void gen_block_die (tree, dw_die_ref, int);
5888 static void decls_for_scope (tree, dw_die_ref, int);
5889 static int is_redundant_typedef (const_tree);
5890 static void gen_namespace_die (tree, dw_die_ref);
5891 static void gen_decl_die (tree, tree, dw_die_ref);
5892 static dw_die_ref force_decl_die (tree);
5893 static dw_die_ref force_type_die (tree);
5894 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5895 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5896 static struct dwarf_file_data * lookup_filename (const char *);
5897 static void retry_incomplete_types (void);
5898 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5899 static void splice_child_die (dw_die_ref, dw_die_ref);
5900 static int file_info_cmp (const void *, const void *);
5901 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5902 const char *, const char *, unsigned);
5903 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5904 const char *, const char *,
5906 static void output_loc_list (dw_loc_list_ref);
5907 static char *gen_internal_sym (const char *);
5909 static void prune_unmark_dies (dw_die_ref);
5910 static void prune_unused_types_mark (dw_die_ref, int);
5911 static void prune_unused_types_walk (dw_die_ref);
5912 static void prune_unused_types_walk_attribs (dw_die_ref);
5913 static void prune_unused_types_prune (dw_die_ref);
5914 static void prune_unused_types (void);
5915 static int maybe_emit_file (struct dwarf_file_data *fd);
5917 /* Section names used to hold DWARF debugging information. */
5918 #ifndef DEBUG_INFO_SECTION
5919 #define DEBUG_INFO_SECTION ".debug_info"
5921 #ifndef DEBUG_ABBREV_SECTION
5922 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5924 #ifndef DEBUG_ARANGES_SECTION
5925 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5927 #ifndef DEBUG_MACINFO_SECTION
5928 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5930 #ifndef DEBUG_LINE_SECTION
5931 #define DEBUG_LINE_SECTION ".debug_line"
5933 #ifndef DEBUG_LOC_SECTION
5934 #define DEBUG_LOC_SECTION ".debug_loc"
5936 #ifndef DEBUG_PUBNAMES_SECTION
5937 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5939 #ifndef DEBUG_PUBTYPES_SECTION
5940 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
5942 #ifndef DEBUG_STR_SECTION
5943 #define DEBUG_STR_SECTION ".debug_str"
5945 #ifndef DEBUG_RANGES_SECTION
5946 #define DEBUG_RANGES_SECTION ".debug_ranges"
5949 /* Standard ELF section names for compiled code and data. */
5950 #ifndef TEXT_SECTION_NAME
5951 #define TEXT_SECTION_NAME ".text"
5954 /* Section flags for .debug_str section. */
5955 #define DEBUG_STR_SECTION_FLAGS \
5956 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5957 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5960 /* Labels we insert at beginning sections we can reference instead of
5961 the section names themselves. */
5963 #ifndef TEXT_SECTION_LABEL
5964 #define TEXT_SECTION_LABEL "Ltext"
5966 #ifndef COLD_TEXT_SECTION_LABEL
5967 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5969 #ifndef DEBUG_LINE_SECTION_LABEL
5970 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5972 #ifndef DEBUG_INFO_SECTION_LABEL
5973 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5975 #ifndef DEBUG_ABBREV_SECTION_LABEL
5976 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5978 #ifndef DEBUG_LOC_SECTION_LABEL
5979 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5981 #ifndef DEBUG_RANGES_SECTION_LABEL
5982 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5984 #ifndef DEBUG_MACINFO_SECTION_LABEL
5985 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5988 /* Definitions of defaults for formats and names of various special
5989 (artificial) labels which may be generated within this file (when the -g
5990 options is used and DWARF2_DEBUGGING_INFO is in effect.
5991 If necessary, these may be overridden from within the tm.h file, but
5992 typically, overriding these defaults is unnecessary. */
5994 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5995 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5996 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5997 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5998 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5999 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6000 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6001 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6002 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6003 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6005 #ifndef TEXT_END_LABEL
6006 #define TEXT_END_LABEL "Letext"
6008 #ifndef COLD_END_LABEL
6009 #define COLD_END_LABEL "Letext_cold"
6011 #ifndef BLOCK_BEGIN_LABEL
6012 #define BLOCK_BEGIN_LABEL "LBB"
6014 #ifndef BLOCK_END_LABEL
6015 #define BLOCK_END_LABEL "LBE"
6017 #ifndef LINE_CODE_LABEL
6018 #define LINE_CODE_LABEL "LM"
6020 #ifndef SEPARATE_LINE_CODE_LABEL
6021 #define SEPARATE_LINE_CODE_LABEL "LSM"
6025 /* We allow a language front-end to designate a function that is to be
6026 called to "demangle" any name before it is put into a DIE. */
6028 static const char *(*demangle_name_func) (const char *);
6031 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6033 demangle_name_func = func;
6036 /* Test if rtl node points to a pseudo register. */
6039 is_pseudo_reg (const_rtx rtl)
6041 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6042 || (GET_CODE (rtl) == SUBREG
6043 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6046 /* Return a reference to a type, with its const and volatile qualifiers
6050 type_main_variant (tree type)
6052 type = TYPE_MAIN_VARIANT (type);
6054 /* ??? There really should be only one main variant among any group of
6055 variants of a given type (and all of the MAIN_VARIANT values for all
6056 members of the group should point to that one type) but sometimes the C
6057 front-end messes this up for array types, so we work around that bug
6059 if (TREE_CODE (type) == ARRAY_TYPE)
6060 while (type != TYPE_MAIN_VARIANT (type))
6061 type = TYPE_MAIN_VARIANT (type);
6066 /* Return nonzero if the given type node represents a tagged type. */
6069 is_tagged_type (const_tree type)
6071 enum tree_code code = TREE_CODE (type);
6073 return (code == RECORD_TYPE || code == UNION_TYPE
6074 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6077 /* Convert a DIE tag into its string name. */
6080 dwarf_tag_name (unsigned int tag)
6084 case DW_TAG_padding:
6085 return "DW_TAG_padding";
6086 case DW_TAG_array_type:
6087 return "DW_TAG_array_type";
6088 case DW_TAG_class_type:
6089 return "DW_TAG_class_type";
6090 case DW_TAG_entry_point:
6091 return "DW_TAG_entry_point";
6092 case DW_TAG_enumeration_type:
6093 return "DW_TAG_enumeration_type";
6094 case DW_TAG_formal_parameter:
6095 return "DW_TAG_formal_parameter";
6096 case DW_TAG_imported_declaration:
6097 return "DW_TAG_imported_declaration";
6099 return "DW_TAG_label";
6100 case DW_TAG_lexical_block:
6101 return "DW_TAG_lexical_block";
6103 return "DW_TAG_member";
6104 case DW_TAG_pointer_type:
6105 return "DW_TAG_pointer_type";
6106 case DW_TAG_reference_type:
6107 return "DW_TAG_reference_type";
6108 case DW_TAG_compile_unit:
6109 return "DW_TAG_compile_unit";
6110 case DW_TAG_string_type:
6111 return "DW_TAG_string_type";
6112 case DW_TAG_structure_type:
6113 return "DW_TAG_structure_type";
6114 case DW_TAG_subroutine_type:
6115 return "DW_TAG_subroutine_type";
6116 case DW_TAG_typedef:
6117 return "DW_TAG_typedef";
6118 case DW_TAG_union_type:
6119 return "DW_TAG_union_type";
6120 case DW_TAG_unspecified_parameters:
6121 return "DW_TAG_unspecified_parameters";
6122 case DW_TAG_variant:
6123 return "DW_TAG_variant";
6124 case DW_TAG_common_block:
6125 return "DW_TAG_common_block";
6126 case DW_TAG_common_inclusion:
6127 return "DW_TAG_common_inclusion";
6128 case DW_TAG_inheritance:
6129 return "DW_TAG_inheritance";
6130 case DW_TAG_inlined_subroutine:
6131 return "DW_TAG_inlined_subroutine";
6133 return "DW_TAG_module";
6134 case DW_TAG_ptr_to_member_type:
6135 return "DW_TAG_ptr_to_member_type";
6136 case DW_TAG_set_type:
6137 return "DW_TAG_set_type";
6138 case DW_TAG_subrange_type:
6139 return "DW_TAG_subrange_type";
6140 case DW_TAG_with_stmt:
6141 return "DW_TAG_with_stmt";
6142 case DW_TAG_access_declaration:
6143 return "DW_TAG_access_declaration";
6144 case DW_TAG_base_type:
6145 return "DW_TAG_base_type";
6146 case DW_TAG_catch_block:
6147 return "DW_TAG_catch_block";
6148 case DW_TAG_const_type:
6149 return "DW_TAG_const_type";
6150 case DW_TAG_constant:
6151 return "DW_TAG_constant";
6152 case DW_TAG_enumerator:
6153 return "DW_TAG_enumerator";
6154 case DW_TAG_file_type:
6155 return "DW_TAG_file_type";
6157 return "DW_TAG_friend";
6158 case DW_TAG_namelist:
6159 return "DW_TAG_namelist";
6160 case DW_TAG_namelist_item:
6161 return "DW_TAG_namelist_item";
6162 case DW_TAG_packed_type:
6163 return "DW_TAG_packed_type";
6164 case DW_TAG_subprogram:
6165 return "DW_TAG_subprogram";
6166 case DW_TAG_template_type_param:
6167 return "DW_TAG_template_type_param";
6168 case DW_TAG_template_value_param:
6169 return "DW_TAG_template_value_param";
6170 case DW_TAG_thrown_type:
6171 return "DW_TAG_thrown_type";
6172 case DW_TAG_try_block:
6173 return "DW_TAG_try_block";
6174 case DW_TAG_variant_part:
6175 return "DW_TAG_variant_part";
6176 case DW_TAG_variable:
6177 return "DW_TAG_variable";
6178 case DW_TAG_volatile_type:
6179 return "DW_TAG_volatile_type";
6180 case DW_TAG_dwarf_procedure:
6181 return "DW_TAG_dwarf_procedure";
6182 case DW_TAG_restrict_type:
6183 return "DW_TAG_restrict_type";
6184 case DW_TAG_interface_type:
6185 return "DW_TAG_interface_type";
6186 case DW_TAG_namespace:
6187 return "DW_TAG_namespace";
6188 case DW_TAG_imported_module:
6189 return "DW_TAG_imported_module";
6190 case DW_TAG_unspecified_type:
6191 return "DW_TAG_unspecified_type";
6192 case DW_TAG_partial_unit:
6193 return "DW_TAG_partial_unit";
6194 case DW_TAG_imported_unit:
6195 return "DW_TAG_imported_unit";
6196 case DW_TAG_condition:
6197 return "DW_TAG_condition";
6198 case DW_TAG_shared_type:
6199 return "DW_TAG_shared_type";
6200 case DW_TAG_MIPS_loop:
6201 return "DW_TAG_MIPS_loop";
6202 case DW_TAG_format_label:
6203 return "DW_TAG_format_label";
6204 case DW_TAG_function_template:
6205 return "DW_TAG_function_template";
6206 case DW_TAG_class_template:
6207 return "DW_TAG_class_template";
6208 case DW_TAG_GNU_BINCL:
6209 return "DW_TAG_GNU_BINCL";
6210 case DW_TAG_GNU_EINCL:
6211 return "DW_TAG_GNU_EINCL";
6213 return "DW_TAG_<unknown>";
6217 /* Convert a DWARF attribute code into its string name. */
6220 dwarf_attr_name (unsigned int attr)
6225 return "DW_AT_sibling";
6226 case DW_AT_location:
6227 return "DW_AT_location";
6229 return "DW_AT_name";
6230 case DW_AT_ordering:
6231 return "DW_AT_ordering";
6232 case DW_AT_subscr_data:
6233 return "DW_AT_subscr_data";
6234 case DW_AT_byte_size:
6235 return "DW_AT_byte_size";
6236 case DW_AT_bit_offset:
6237 return "DW_AT_bit_offset";
6238 case DW_AT_bit_size:
6239 return "DW_AT_bit_size";
6240 case DW_AT_element_list:
6241 return "DW_AT_element_list";
6242 case DW_AT_stmt_list:
6243 return "DW_AT_stmt_list";
6245 return "DW_AT_low_pc";
6247 return "DW_AT_high_pc";
6248 case DW_AT_language:
6249 return "DW_AT_language";
6251 return "DW_AT_member";
6253 return "DW_AT_discr";
6254 case DW_AT_discr_value:
6255 return "DW_AT_discr_value";
6256 case DW_AT_visibility:
6257 return "DW_AT_visibility";
6259 return "DW_AT_import";
6260 case DW_AT_string_length:
6261 return "DW_AT_string_length";
6262 case DW_AT_common_reference:
6263 return "DW_AT_common_reference";
6264 case DW_AT_comp_dir:
6265 return "DW_AT_comp_dir";
6266 case DW_AT_const_value:
6267 return "DW_AT_const_value";
6268 case DW_AT_containing_type:
6269 return "DW_AT_containing_type";
6270 case DW_AT_default_value:
6271 return "DW_AT_default_value";
6273 return "DW_AT_inline";
6274 case DW_AT_is_optional:
6275 return "DW_AT_is_optional";
6276 case DW_AT_lower_bound:
6277 return "DW_AT_lower_bound";
6278 case DW_AT_producer:
6279 return "DW_AT_producer";
6280 case DW_AT_prototyped:
6281 return "DW_AT_prototyped";
6282 case DW_AT_return_addr:
6283 return "DW_AT_return_addr";
6284 case DW_AT_start_scope:
6285 return "DW_AT_start_scope";
6286 case DW_AT_bit_stride:
6287 return "DW_AT_bit_stride";
6288 case DW_AT_upper_bound:
6289 return "DW_AT_upper_bound";
6290 case DW_AT_abstract_origin:
6291 return "DW_AT_abstract_origin";
6292 case DW_AT_accessibility:
6293 return "DW_AT_accessibility";
6294 case DW_AT_address_class:
6295 return "DW_AT_address_class";
6296 case DW_AT_artificial:
6297 return "DW_AT_artificial";
6298 case DW_AT_base_types:
6299 return "DW_AT_base_types";
6300 case DW_AT_calling_convention:
6301 return "DW_AT_calling_convention";
6303 return "DW_AT_count";
6304 case DW_AT_data_member_location:
6305 return "DW_AT_data_member_location";
6306 case DW_AT_decl_column:
6307 return "DW_AT_decl_column";
6308 case DW_AT_decl_file:
6309 return "DW_AT_decl_file";
6310 case DW_AT_decl_line:
6311 return "DW_AT_decl_line";
6312 case DW_AT_declaration:
6313 return "DW_AT_declaration";
6314 case DW_AT_discr_list:
6315 return "DW_AT_discr_list";
6316 case DW_AT_encoding:
6317 return "DW_AT_encoding";
6318 case DW_AT_external:
6319 return "DW_AT_external";
6320 case DW_AT_explicit:
6321 return "DW_AT_explicit";
6322 case DW_AT_frame_base:
6323 return "DW_AT_frame_base";
6325 return "DW_AT_friend";
6326 case DW_AT_identifier_case:
6327 return "DW_AT_identifier_case";
6328 case DW_AT_macro_info:
6329 return "DW_AT_macro_info";
6330 case DW_AT_namelist_items:
6331 return "DW_AT_namelist_items";
6332 case DW_AT_priority:
6333 return "DW_AT_priority";
6335 return "DW_AT_segment";
6336 case DW_AT_specification:
6337 return "DW_AT_specification";
6338 case DW_AT_static_link:
6339 return "DW_AT_static_link";
6341 return "DW_AT_type";
6342 case DW_AT_use_location:
6343 return "DW_AT_use_location";
6344 case DW_AT_variable_parameter:
6345 return "DW_AT_variable_parameter";
6346 case DW_AT_virtuality:
6347 return "DW_AT_virtuality";
6348 case DW_AT_vtable_elem_location:
6349 return "DW_AT_vtable_elem_location";
6351 case DW_AT_allocated:
6352 return "DW_AT_allocated";
6353 case DW_AT_associated:
6354 return "DW_AT_associated";
6355 case DW_AT_data_location:
6356 return "DW_AT_data_location";
6357 case DW_AT_byte_stride:
6358 return "DW_AT_byte_stride";
6359 case DW_AT_entry_pc:
6360 return "DW_AT_entry_pc";
6361 case DW_AT_use_UTF8:
6362 return "DW_AT_use_UTF8";
6363 case DW_AT_extension:
6364 return "DW_AT_extension";
6366 return "DW_AT_ranges";
6367 case DW_AT_trampoline:
6368 return "DW_AT_trampoline";
6369 case DW_AT_call_column:
6370 return "DW_AT_call_column";
6371 case DW_AT_call_file:
6372 return "DW_AT_call_file";
6373 case DW_AT_call_line:
6374 return "DW_AT_call_line";
6376 case DW_AT_MIPS_fde:
6377 return "DW_AT_MIPS_fde";
6378 case DW_AT_MIPS_loop_begin:
6379 return "DW_AT_MIPS_loop_begin";
6380 case DW_AT_MIPS_tail_loop_begin:
6381 return "DW_AT_MIPS_tail_loop_begin";
6382 case DW_AT_MIPS_epilog_begin:
6383 return "DW_AT_MIPS_epilog_begin";
6384 case DW_AT_MIPS_loop_unroll_factor:
6385 return "DW_AT_MIPS_loop_unroll_factor";
6386 case DW_AT_MIPS_software_pipeline_depth:
6387 return "DW_AT_MIPS_software_pipeline_depth";
6388 case DW_AT_MIPS_linkage_name:
6389 return "DW_AT_MIPS_linkage_name";
6390 case DW_AT_MIPS_stride:
6391 return "DW_AT_MIPS_stride";
6392 case DW_AT_MIPS_abstract_name:
6393 return "DW_AT_MIPS_abstract_name";
6394 case DW_AT_MIPS_clone_origin:
6395 return "DW_AT_MIPS_clone_origin";
6396 case DW_AT_MIPS_has_inlines:
6397 return "DW_AT_MIPS_has_inlines";
6399 case DW_AT_sf_names:
6400 return "DW_AT_sf_names";
6401 case DW_AT_src_info:
6402 return "DW_AT_src_info";
6403 case DW_AT_mac_info:
6404 return "DW_AT_mac_info";
6405 case DW_AT_src_coords:
6406 return "DW_AT_src_coords";
6407 case DW_AT_body_begin:
6408 return "DW_AT_body_begin";
6409 case DW_AT_body_end:
6410 return "DW_AT_body_end";
6411 case DW_AT_GNU_vector:
6412 return "DW_AT_GNU_vector";
6414 case DW_AT_VMS_rtnbeg_pd_address:
6415 return "DW_AT_VMS_rtnbeg_pd_address";
6418 return "DW_AT_<unknown>";
6422 /* Convert a DWARF value form code into its string name. */
6425 dwarf_form_name (unsigned int form)
6430 return "DW_FORM_addr";
6431 case DW_FORM_block2:
6432 return "DW_FORM_block2";
6433 case DW_FORM_block4:
6434 return "DW_FORM_block4";
6436 return "DW_FORM_data2";
6438 return "DW_FORM_data4";
6440 return "DW_FORM_data8";
6441 case DW_FORM_string:
6442 return "DW_FORM_string";
6444 return "DW_FORM_block";
6445 case DW_FORM_block1:
6446 return "DW_FORM_block1";
6448 return "DW_FORM_data1";
6450 return "DW_FORM_flag";
6452 return "DW_FORM_sdata";
6454 return "DW_FORM_strp";
6456 return "DW_FORM_udata";
6457 case DW_FORM_ref_addr:
6458 return "DW_FORM_ref_addr";
6460 return "DW_FORM_ref1";
6462 return "DW_FORM_ref2";
6464 return "DW_FORM_ref4";
6466 return "DW_FORM_ref8";
6467 case DW_FORM_ref_udata:
6468 return "DW_FORM_ref_udata";
6469 case DW_FORM_indirect:
6470 return "DW_FORM_indirect";
6472 return "DW_FORM_<unknown>";
6476 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6477 instance of an inlined instance of a decl which is local to an inline
6478 function, so we have to trace all of the way back through the origin chain
6479 to find out what sort of node actually served as the original seed for the
6483 decl_ultimate_origin (const_tree decl)
6485 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6488 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6489 nodes in the function to point to themselves; ignore that if
6490 we're trying to output the abstract instance of this function. */
6491 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6494 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6495 most distant ancestor, this should never happen. */
6496 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6498 return DECL_ABSTRACT_ORIGIN (decl);
6501 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6502 of a virtual function may refer to a base class, so we check the 'this'
6506 decl_class_context (tree decl)
6508 tree context = NULL_TREE;
6510 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6511 context = DECL_CONTEXT (decl);
6513 context = TYPE_MAIN_VARIANT
6514 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6516 if (context && !TYPE_P (context))
6517 context = NULL_TREE;
6522 /* Add an attribute/value pair to a DIE. */
6525 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6527 /* Maybe this should be an assert? */
6531 if (die->die_attr == NULL)
6532 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6533 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6536 static inline enum dw_val_class
6537 AT_class (dw_attr_ref a)
6539 return a->dw_attr_val.val_class;
6542 /* Add a flag value attribute to a DIE. */
6545 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6549 attr.dw_attr = attr_kind;
6550 attr.dw_attr_val.val_class = dw_val_class_flag;
6551 attr.dw_attr_val.v.val_flag = flag;
6552 add_dwarf_attr (die, &attr);
6555 static inline unsigned
6556 AT_flag (dw_attr_ref a)
6558 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6559 return a->dw_attr_val.v.val_flag;
6562 /* Add a signed integer attribute value to a DIE. */
6565 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6569 attr.dw_attr = attr_kind;
6570 attr.dw_attr_val.val_class = dw_val_class_const;
6571 attr.dw_attr_val.v.val_int = int_val;
6572 add_dwarf_attr (die, &attr);
6575 static inline HOST_WIDE_INT
6576 AT_int (dw_attr_ref a)
6578 gcc_assert (a && AT_class (a) == dw_val_class_const);
6579 return a->dw_attr_val.v.val_int;
6582 /* Add an unsigned integer attribute value to a DIE. */
6585 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6586 unsigned HOST_WIDE_INT unsigned_val)
6590 attr.dw_attr = attr_kind;
6591 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6592 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6593 add_dwarf_attr (die, &attr);
6596 static inline unsigned HOST_WIDE_INT
6597 AT_unsigned (dw_attr_ref a)
6599 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6600 return a->dw_attr_val.v.val_unsigned;
6603 /* Add an unsigned double integer attribute value to a DIE. */
6606 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
6607 long unsigned int val_hi, long unsigned int val_low)
6611 attr.dw_attr = attr_kind;
6612 attr.dw_attr_val.val_class = dw_val_class_long_long;
6613 attr.dw_attr_val.v.val_long_long.hi = val_hi;
6614 attr.dw_attr_val.v.val_long_long.low = val_low;
6615 add_dwarf_attr (die, &attr);
6618 /* Add a floating point attribute value to a DIE and return it. */
6621 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6622 unsigned int length, unsigned int elt_size, unsigned char *array)
6626 attr.dw_attr = attr_kind;
6627 attr.dw_attr_val.val_class = dw_val_class_vec;
6628 attr.dw_attr_val.v.val_vec.length = length;
6629 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6630 attr.dw_attr_val.v.val_vec.array = array;
6631 add_dwarf_attr (die, &attr);
6634 /* Hash and equality functions for debug_str_hash. */
6637 debug_str_do_hash (const void *x)
6639 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6643 debug_str_eq (const void *x1, const void *x2)
6645 return strcmp ((((const struct indirect_string_node *)x1)->str),
6646 (const char *)x2) == 0;
6649 static struct indirect_string_node *
6650 find_AT_string (const char *str)
6652 struct indirect_string_node *node;
6655 if (! debug_str_hash)
6656 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6657 debug_str_eq, NULL);
6659 slot = htab_find_slot_with_hash (debug_str_hash, str,
6660 htab_hash_string (str), INSERT);
6663 node = (struct indirect_string_node *)
6664 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6665 node->str = ggc_strdup (str);
6669 node = (struct indirect_string_node *) *slot;
6675 /* Add a string attribute value to a DIE. */
6678 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6681 struct indirect_string_node *node;
6683 node = find_AT_string (str);
6685 attr.dw_attr = attr_kind;
6686 attr.dw_attr_val.val_class = dw_val_class_str;
6687 attr.dw_attr_val.v.val_str = node;
6688 add_dwarf_attr (die, &attr);
6691 static inline const char *
6692 AT_string (dw_attr_ref a)
6694 gcc_assert (a && AT_class (a) == dw_val_class_str);
6695 return a->dw_attr_val.v.val_str->str;
6698 /* Find out whether a string should be output inline in DIE
6699 or out-of-line in .debug_str section. */
6701 static enum dwarf_form
6702 AT_string_form (dw_attr_ref a)
6704 struct indirect_string_node *node;
6708 gcc_assert (a && AT_class (a) == dw_val_class_str);
6710 node = a->dw_attr_val.v.val_str;
6714 len = strlen (node->str) + 1;
6716 /* If the string is shorter or equal to the size of the reference, it is
6717 always better to put it inline. */
6718 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6719 return node->form = DW_FORM_string;
6721 /* If we cannot expect the linker to merge strings in .debug_str
6722 section, only put it into .debug_str if it is worth even in this
6724 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
6725 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
6726 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
6727 return node->form = DW_FORM_string;
6729 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6730 ++dw2_string_counter;
6731 node->label = xstrdup (label);
6733 return node->form = DW_FORM_strp;
6736 /* Add a DIE reference attribute value to a DIE. */
6739 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6743 attr.dw_attr = attr_kind;
6744 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6745 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6746 attr.dw_attr_val.v.val_die_ref.external = 0;
6747 add_dwarf_attr (die, &attr);
6750 /* Add an AT_specification attribute to a DIE, and also make the back
6751 pointer from the specification to the definition. */
6754 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6756 add_AT_die_ref (die, DW_AT_specification, targ_die);
6757 gcc_assert (!targ_die->die_definition);
6758 targ_die->die_definition = die;
6761 static inline dw_die_ref
6762 AT_ref (dw_attr_ref a)
6764 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6765 return a->dw_attr_val.v.val_die_ref.die;
6769 AT_ref_external (dw_attr_ref a)
6771 if (a && AT_class (a) == dw_val_class_die_ref)
6772 return a->dw_attr_val.v.val_die_ref.external;
6778 set_AT_ref_external (dw_attr_ref a, int i)
6780 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6781 a->dw_attr_val.v.val_die_ref.external = i;
6784 /* Add an FDE reference attribute value to a DIE. */
6787 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6791 attr.dw_attr = attr_kind;
6792 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6793 attr.dw_attr_val.v.val_fde_index = targ_fde;
6794 add_dwarf_attr (die, &attr);
6797 /* Add a location description attribute value to a DIE. */
6800 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6804 attr.dw_attr = attr_kind;
6805 attr.dw_attr_val.val_class = dw_val_class_loc;
6806 attr.dw_attr_val.v.val_loc = loc;
6807 add_dwarf_attr (die, &attr);
6810 static inline dw_loc_descr_ref
6811 AT_loc (dw_attr_ref a)
6813 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6814 return a->dw_attr_val.v.val_loc;
6818 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6822 attr.dw_attr = attr_kind;
6823 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6824 attr.dw_attr_val.v.val_loc_list = loc_list;
6825 add_dwarf_attr (die, &attr);
6826 have_location_lists = true;
6829 static inline dw_loc_list_ref
6830 AT_loc_list (dw_attr_ref a)
6832 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6833 return a->dw_attr_val.v.val_loc_list;
6836 /* Add an address constant attribute value to a DIE. */
6839 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6843 attr.dw_attr = attr_kind;
6844 attr.dw_attr_val.val_class = dw_val_class_addr;
6845 attr.dw_attr_val.v.val_addr = addr;
6846 add_dwarf_attr (die, &attr);
6849 /* Get the RTX from to an address DIE attribute. */
6852 AT_addr (dw_attr_ref a)
6854 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6855 return a->dw_attr_val.v.val_addr;
6858 /* Add a file attribute value to a DIE. */
6861 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6862 struct dwarf_file_data *fd)
6866 attr.dw_attr = attr_kind;
6867 attr.dw_attr_val.val_class = dw_val_class_file;
6868 attr.dw_attr_val.v.val_file = fd;
6869 add_dwarf_attr (die, &attr);
6872 /* Get the dwarf_file_data from a file DIE attribute. */
6874 static inline struct dwarf_file_data *
6875 AT_file (dw_attr_ref a)
6877 gcc_assert (a && AT_class (a) == dw_val_class_file);
6878 return a->dw_attr_val.v.val_file;
6881 /* Add a label identifier attribute value to a DIE. */
6884 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6888 attr.dw_attr = attr_kind;
6889 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6890 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6891 add_dwarf_attr (die, &attr);
6894 /* Add a section offset attribute value to a DIE, an offset into the
6895 debug_line section. */
6898 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6903 attr.dw_attr = attr_kind;
6904 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6905 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6906 add_dwarf_attr (die, &attr);
6909 /* Add a section offset attribute value to a DIE, an offset into the
6910 debug_macinfo section. */
6913 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6918 attr.dw_attr = attr_kind;
6919 attr.dw_attr_val.val_class = dw_val_class_macptr;
6920 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6921 add_dwarf_attr (die, &attr);
6924 /* Add an offset attribute value to a DIE. */
6927 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6928 unsigned HOST_WIDE_INT offset)
6932 attr.dw_attr = attr_kind;
6933 attr.dw_attr_val.val_class = dw_val_class_offset;
6934 attr.dw_attr_val.v.val_offset = offset;
6935 add_dwarf_attr (die, &attr);
6938 /* Add an range_list attribute value to a DIE. */
6941 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6942 long unsigned int offset)
6946 attr.dw_attr = attr_kind;
6947 attr.dw_attr_val.val_class = dw_val_class_range_list;
6948 attr.dw_attr_val.v.val_offset = offset;
6949 add_dwarf_attr (die, &attr);
6952 static inline const char *
6953 AT_lbl (dw_attr_ref a)
6955 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6956 || AT_class (a) == dw_val_class_lineptr
6957 || AT_class (a) == dw_val_class_macptr));
6958 return a->dw_attr_val.v.val_lbl_id;
6961 /* Get the attribute of type attr_kind. */
6964 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6968 dw_die_ref spec = NULL;
6973 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6974 if (a->dw_attr == attr_kind)
6976 else if (a->dw_attr == DW_AT_specification
6977 || a->dw_attr == DW_AT_abstract_origin)
6981 return get_AT (spec, attr_kind);
6986 /* Return the "low pc" attribute value, typically associated with a subprogram
6987 DIE. Return null if the "low pc" attribute is either not present, or if it
6988 cannot be represented as an assembler label identifier. */
6990 static inline const char *
6991 get_AT_low_pc (dw_die_ref die)
6993 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6995 return a ? AT_lbl (a) : NULL;
6998 /* Return the "high pc" attribute value, typically associated with a subprogram
6999 DIE. Return null if the "high pc" attribute is either not present, or if it
7000 cannot be represented as an assembler label identifier. */
7002 static inline const char *
7003 get_AT_hi_pc (dw_die_ref die)
7005 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7007 return a ? AT_lbl (a) : NULL;
7010 /* Return the value of the string attribute designated by ATTR_KIND, or
7011 NULL if it is not present. */
7013 static inline const char *
7014 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7016 dw_attr_ref a = get_AT (die, attr_kind);
7018 return a ? AT_string (a) : NULL;
7021 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7022 if it is not present. */
7025 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7027 dw_attr_ref a = get_AT (die, attr_kind);
7029 return a ? AT_flag (a) : 0;
7032 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7033 if it is not present. */
7035 static inline unsigned
7036 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7038 dw_attr_ref a = get_AT (die, attr_kind);
7040 return a ? AT_unsigned (a) : 0;
7043 static inline dw_die_ref
7044 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7046 dw_attr_ref a = get_AT (die, attr_kind);
7048 return a ? AT_ref (a) : NULL;
7051 static inline struct dwarf_file_data *
7052 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7054 dw_attr_ref a = get_AT (die, attr_kind);
7056 return a ? AT_file (a) : NULL;
7059 /* Return TRUE if the language is C or C++. */
7064 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7066 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
7067 || lang == DW_LANG_C99
7068 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
7071 /* Return TRUE if the language is C++. */
7076 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7078 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7081 /* Return TRUE if the language is Fortran. */
7086 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7088 return (lang == DW_LANG_Fortran77
7089 || lang == DW_LANG_Fortran90
7090 || lang == DW_LANG_Fortran95);
7093 /* Return TRUE if the language is Java. */
7098 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7100 return lang == DW_LANG_Java;
7103 /* Return TRUE if the language is Ada. */
7108 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7110 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7113 /* Remove the specified attribute if present. */
7116 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7124 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7125 if (a->dw_attr == attr_kind)
7127 if (AT_class (a) == dw_val_class_str)
7128 if (a->dw_attr_val.v.val_str->refcount)
7129 a->dw_attr_val.v.val_str->refcount--;
7131 /* VEC_ordered_remove should help reduce the number of abbrevs
7133 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7138 /* Remove CHILD from its parent. PREV must have the property that
7139 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7142 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7144 gcc_assert (child->die_parent == prev->die_parent);
7145 gcc_assert (prev->die_sib == child);
7148 gcc_assert (child->die_parent->die_child == child);
7152 prev->die_sib = child->die_sib;
7153 if (child->die_parent->die_child == child)
7154 child->die_parent->die_child = prev;
7157 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7161 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7167 dw_die_ref prev = c;
7169 while (c->die_tag == tag)
7171 remove_child_with_prev (c, prev);
7172 /* Might have removed every child. */
7173 if (c == c->die_sib)
7177 } while (c != die->die_child);
7180 /* Add a CHILD_DIE as the last child of DIE. */
7183 add_child_die (dw_die_ref die, dw_die_ref child_die)
7185 /* FIXME this should probably be an assert. */
7186 if (! die || ! child_die)
7188 gcc_assert (die != child_die);
7190 child_die->die_parent = die;
7193 child_die->die_sib = die->die_child->die_sib;
7194 die->die_child->die_sib = child_die;
7197 child_die->die_sib = child_die;
7198 die->die_child = child_die;
7201 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7202 is the specification, to the end of PARENT's list of children.
7203 This is done by removing and re-adding it. */
7206 splice_child_die (dw_die_ref parent, dw_die_ref child)
7210 /* We want the declaration DIE from inside the class, not the
7211 specification DIE at toplevel. */
7212 if (child->die_parent != parent)
7214 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7220 gcc_assert (child->die_parent == parent
7221 || (child->die_parent
7222 == get_AT_ref (parent, DW_AT_specification)));
7224 for (p = child->die_parent->die_child; ; p = p->die_sib)
7225 if (p->die_sib == child)
7227 remove_child_with_prev (child, p);
7231 add_child_die (parent, child);
7234 /* Return a pointer to a newly created DIE node. */
7236 static inline dw_die_ref
7237 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7239 dw_die_ref die = GGC_CNEW (die_node);
7241 die->die_tag = tag_value;
7243 if (parent_die != NULL)
7244 add_child_die (parent_die, die);
7247 limbo_die_node *limbo_node;
7249 limbo_node = GGC_CNEW (limbo_die_node);
7250 limbo_node->die = die;
7251 limbo_node->created_for = t;
7252 limbo_node->next = limbo_die_list;
7253 limbo_die_list = limbo_node;
7259 /* Return the DIE associated with the given type specifier. */
7261 static inline dw_die_ref
7262 lookup_type_die (tree type)
7264 return TYPE_SYMTAB_DIE (type);
7267 /* Equate a DIE to a given type specifier. */
7270 equate_type_number_to_die (tree type, dw_die_ref type_die)
7272 TYPE_SYMTAB_DIE (type) = type_die;
7275 /* Returns a hash value for X (which really is a die_struct). */
7278 decl_die_table_hash (const void *x)
7280 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7283 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7286 decl_die_table_eq (const void *x, const void *y)
7288 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7291 /* Return the DIE associated with a given declaration. */
7293 static inline dw_die_ref
7294 lookup_decl_die (tree decl)
7296 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7299 /* Returns a hash value for X (which really is a var_loc_list). */
7302 decl_loc_table_hash (const void *x)
7304 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7307 /* Return nonzero if decl_id of var_loc_list X is the same as
7311 decl_loc_table_eq (const void *x, const void *y)
7313 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7316 /* Return the var_loc list associated with a given declaration. */
7318 static inline var_loc_list *
7319 lookup_decl_loc (const_tree decl)
7321 return (var_loc_list *)
7322 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7325 /* Equate a DIE to a particular declaration. */
7328 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7330 unsigned int decl_id = DECL_UID (decl);
7333 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7335 decl_die->decl_id = decl_id;
7338 /* Add a variable location node to the linked list for DECL. */
7341 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7343 unsigned int decl_id = DECL_UID (decl);
7347 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7350 temp = GGC_CNEW (var_loc_list);
7351 temp->decl_id = decl_id;
7355 temp = (var_loc_list *) *slot;
7359 /* If the current location is the same as the end of the list,
7360 and either both or neither of the locations is uninitialized,
7361 we have nothing to do. */
7362 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7363 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7364 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7365 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7366 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7367 == VAR_INIT_STATUS_UNINITIALIZED)
7368 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7369 == VAR_INIT_STATUS_UNINITIALIZED))))
7371 /* Add LOC to the end of list and update LAST. */
7372 temp->last->next = loc;
7376 /* Do not add empty location to the beginning of the list. */
7377 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7384 /* Keep track of the number of spaces used to indent the
7385 output of the debugging routines that print the structure of
7386 the DIE internal representation. */
7387 static int print_indent;
7389 /* Indent the line the number of spaces given by print_indent. */
7392 print_spaces (FILE *outfile)
7394 fprintf (outfile, "%*s", print_indent, "");
7397 /* Print the information associated with a given DIE, and its children.
7398 This routine is a debugging aid only. */
7401 print_die (dw_die_ref die, FILE *outfile)
7407 print_spaces (outfile);
7408 fprintf (outfile, "DIE %4ld: %s\n",
7409 die->die_offset, dwarf_tag_name (die->die_tag));
7410 print_spaces (outfile);
7411 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7412 fprintf (outfile, " offset: %ld\n", die->die_offset);
7414 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7416 print_spaces (outfile);
7417 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7419 switch (AT_class (a))
7421 case dw_val_class_addr:
7422 fprintf (outfile, "address");
7424 case dw_val_class_offset:
7425 fprintf (outfile, "offset");
7427 case dw_val_class_loc:
7428 fprintf (outfile, "location descriptor");
7430 case dw_val_class_loc_list:
7431 fprintf (outfile, "location list -> label:%s",
7432 AT_loc_list (a)->ll_symbol);
7434 case dw_val_class_range_list:
7435 fprintf (outfile, "range list");
7437 case dw_val_class_const:
7438 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7440 case dw_val_class_unsigned_const:
7441 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7443 case dw_val_class_long_long:
7444 fprintf (outfile, "constant (%lu,%lu)",
7445 a->dw_attr_val.v.val_long_long.hi,
7446 a->dw_attr_val.v.val_long_long.low);
7448 case dw_val_class_vec:
7449 fprintf (outfile, "floating-point or vector constant");
7451 case dw_val_class_flag:
7452 fprintf (outfile, "%u", AT_flag (a));
7454 case dw_val_class_die_ref:
7455 if (AT_ref (a) != NULL)
7457 if (AT_ref (a)->die_symbol)
7458 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7460 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7463 fprintf (outfile, "die -> <null>");
7465 case dw_val_class_lbl_id:
7466 case dw_val_class_lineptr:
7467 case dw_val_class_macptr:
7468 fprintf (outfile, "label: %s", AT_lbl (a));
7470 case dw_val_class_str:
7471 if (AT_string (a) != NULL)
7472 fprintf (outfile, "\"%s\"", AT_string (a));
7474 fprintf (outfile, "<null>");
7476 case dw_val_class_file:
7477 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7478 AT_file (a)->emitted_number);
7484 fprintf (outfile, "\n");
7487 if (die->die_child != NULL)
7490 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7493 if (print_indent == 0)
7494 fprintf (outfile, "\n");
7497 /* Print the contents of the source code line number correspondence table.
7498 This routine is a debugging aid only. */
7501 print_dwarf_line_table (FILE *outfile)
7504 dw_line_info_ref line_info;
7506 fprintf (outfile, "\n\nDWARF source line information\n");
7507 for (i = 1; i < line_info_table_in_use; i++)
7509 line_info = &line_info_table[i];
7510 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7511 line_info->dw_file_num,
7512 line_info->dw_line_num);
7515 fprintf (outfile, "\n\n");
7518 /* Print the information collected for a given DIE. */
7521 debug_dwarf_die (dw_die_ref die)
7523 print_die (die, stderr);
7526 /* Print all DWARF information collected for the compilation unit.
7527 This routine is a debugging aid only. */
7533 print_die (comp_unit_die, stderr);
7534 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7535 print_dwarf_line_table (stderr);
7538 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7539 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7540 DIE that marks the start of the DIEs for this include file. */
7543 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7545 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7546 dw_die_ref new_unit = gen_compile_unit_die (filename);
7548 new_unit->die_sib = old_unit;
7552 /* Close an include-file CU and reopen the enclosing one. */
7555 pop_compile_unit (dw_die_ref old_unit)
7557 dw_die_ref new_unit = old_unit->die_sib;
7559 old_unit->die_sib = NULL;
7563 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7564 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7566 /* Calculate the checksum of a location expression. */
7569 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7573 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7575 CHECKSUM (loc->dw_loc_oprnd1);
7576 CHECKSUM (loc->dw_loc_oprnd2);
7579 /* Calculate the checksum of an attribute. */
7582 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7584 dw_loc_descr_ref loc;
7587 CHECKSUM (at->dw_attr);
7589 /* We don't care that this was compiled with a different compiler
7590 snapshot; if the output is the same, that's what matters. */
7591 if (at->dw_attr == DW_AT_producer)
7594 switch (AT_class (at))
7596 case dw_val_class_const:
7597 CHECKSUM (at->dw_attr_val.v.val_int);
7599 case dw_val_class_unsigned_const:
7600 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7602 case dw_val_class_long_long:
7603 CHECKSUM (at->dw_attr_val.v.val_long_long);
7605 case dw_val_class_vec:
7606 CHECKSUM (at->dw_attr_val.v.val_vec);
7608 case dw_val_class_flag:
7609 CHECKSUM (at->dw_attr_val.v.val_flag);
7611 case dw_val_class_str:
7612 CHECKSUM_STRING (AT_string (at));
7615 case dw_val_class_addr:
7617 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7618 CHECKSUM_STRING (XSTR (r, 0));
7621 case dw_val_class_offset:
7622 CHECKSUM (at->dw_attr_val.v.val_offset);
7625 case dw_val_class_loc:
7626 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7627 loc_checksum (loc, ctx);
7630 case dw_val_class_die_ref:
7631 die_checksum (AT_ref (at), ctx, mark);
7634 case dw_val_class_fde_ref:
7635 case dw_val_class_lbl_id:
7636 case dw_val_class_lineptr:
7637 case dw_val_class_macptr:
7640 case dw_val_class_file:
7641 CHECKSUM_STRING (AT_file (at)->filename);
7649 /* Calculate the checksum of a DIE. */
7652 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7658 /* To avoid infinite recursion. */
7661 CHECKSUM (die->die_mark);
7664 die->die_mark = ++(*mark);
7666 CHECKSUM (die->die_tag);
7668 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7669 attr_checksum (a, ctx, mark);
7671 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7675 #undef CHECKSUM_STRING
7677 /* Do the location expressions look same? */
7679 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7681 return loc1->dw_loc_opc == loc2->dw_loc_opc
7682 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7683 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7686 /* Do the values look the same? */
7688 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7690 dw_loc_descr_ref loc1, loc2;
7693 if (v1->val_class != v2->val_class)
7696 switch (v1->val_class)
7698 case dw_val_class_const:
7699 return v1->v.val_int == v2->v.val_int;
7700 case dw_val_class_unsigned_const:
7701 return v1->v.val_unsigned == v2->v.val_unsigned;
7702 case dw_val_class_long_long:
7703 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
7704 && v1->v.val_long_long.low == v2->v.val_long_long.low;
7705 case dw_val_class_vec:
7706 if (v1->v.val_vec.length != v2->v.val_vec.length
7707 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7709 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7710 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7713 case dw_val_class_flag:
7714 return v1->v.val_flag == v2->v.val_flag;
7715 case dw_val_class_str:
7716 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7718 case dw_val_class_addr:
7719 r1 = v1->v.val_addr;
7720 r2 = v2->v.val_addr;
7721 if (GET_CODE (r1) != GET_CODE (r2))
7723 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7724 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7726 case dw_val_class_offset:
7727 return v1->v.val_offset == v2->v.val_offset;
7729 case dw_val_class_loc:
7730 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7732 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7733 if (!same_loc_p (loc1, loc2, mark))
7735 return !loc1 && !loc2;
7737 case dw_val_class_die_ref:
7738 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7740 case dw_val_class_fde_ref:
7741 case dw_val_class_lbl_id:
7742 case dw_val_class_lineptr:
7743 case dw_val_class_macptr:
7746 case dw_val_class_file:
7747 return v1->v.val_file == v2->v.val_file;
7754 /* Do the attributes look the same? */
7757 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7759 if (at1->dw_attr != at2->dw_attr)
7762 /* We don't care that this was compiled with a different compiler
7763 snapshot; if the output is the same, that's what matters. */
7764 if (at1->dw_attr == DW_AT_producer)
7767 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7770 /* Do the dies look the same? */
7773 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7779 /* To avoid infinite recursion. */
7781 return die1->die_mark == die2->die_mark;
7782 die1->die_mark = die2->die_mark = ++(*mark);
7784 if (die1->die_tag != die2->die_tag)
7787 if (VEC_length (dw_attr_node, die1->die_attr)
7788 != VEC_length (dw_attr_node, die2->die_attr))
7791 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7792 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7795 c1 = die1->die_child;
7796 c2 = die2->die_child;
7805 if (!same_die_p (c1, c2, mark))
7809 if (c1 == die1->die_child)
7811 if (c2 == die2->die_child)
7821 /* Do the dies look the same? Wrapper around same_die_p. */
7824 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7827 int ret = same_die_p (die1, die2, &mark);
7829 unmark_all_dies (die1);
7830 unmark_all_dies (die2);
7835 /* The prefix to attach to symbols on DIEs in the current comdat debug
7837 static char *comdat_symbol_id;
7839 /* The index of the current symbol within the current comdat CU. */
7840 static unsigned int comdat_symbol_number;
7842 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7843 children, and set comdat_symbol_id accordingly. */
7846 compute_section_prefix (dw_die_ref unit_die)
7848 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7849 const char *base = die_name ? lbasename (die_name) : "anonymous";
7850 char *name = XALLOCAVEC (char, strlen (base) + 64);
7853 unsigned char checksum[16];
7856 /* Compute the checksum of the DIE, then append part of it as hex digits to
7857 the name filename of the unit. */
7859 md5_init_ctx (&ctx);
7861 die_checksum (unit_die, &ctx, &mark);
7862 unmark_all_dies (unit_die);
7863 md5_finish_ctx (&ctx, checksum);
7865 sprintf (name, "%s.", base);
7866 clean_symbol_name (name);
7868 p = name + strlen (name);
7869 for (i = 0; i < 4; i++)
7871 sprintf (p, "%.2x", checksum[i]);
7875 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7876 comdat_symbol_number = 0;
7879 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7882 is_type_die (dw_die_ref die)
7884 switch (die->die_tag)
7886 case DW_TAG_array_type:
7887 case DW_TAG_class_type:
7888 case DW_TAG_interface_type:
7889 case DW_TAG_enumeration_type:
7890 case DW_TAG_pointer_type:
7891 case DW_TAG_reference_type:
7892 case DW_TAG_string_type:
7893 case DW_TAG_structure_type:
7894 case DW_TAG_subroutine_type:
7895 case DW_TAG_union_type:
7896 case DW_TAG_ptr_to_member_type:
7897 case DW_TAG_set_type:
7898 case DW_TAG_subrange_type:
7899 case DW_TAG_base_type:
7900 case DW_TAG_const_type:
7901 case DW_TAG_file_type:
7902 case DW_TAG_packed_type:
7903 case DW_TAG_volatile_type:
7904 case DW_TAG_typedef:
7911 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7912 Basically, we want to choose the bits that are likely to be shared between
7913 compilations (types) and leave out the bits that are specific to individual
7914 compilations (functions). */
7917 is_comdat_die (dw_die_ref c)
7919 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7920 we do for stabs. The advantage is a greater likelihood of sharing between
7921 objects that don't include headers in the same order (and therefore would
7922 put the base types in a different comdat). jason 8/28/00 */
7924 if (c->die_tag == DW_TAG_base_type)
7927 if (c->die_tag == DW_TAG_pointer_type
7928 || c->die_tag == DW_TAG_reference_type
7929 || c->die_tag == DW_TAG_const_type
7930 || c->die_tag == DW_TAG_volatile_type)
7932 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7934 return t ? is_comdat_die (t) : 0;
7937 return is_type_die (c);
7940 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7941 compilation unit. */
7944 is_symbol_die (dw_die_ref c)
7946 return (is_type_die (c)
7947 || (get_AT (c, DW_AT_declaration)
7948 && !get_AT (c, DW_AT_specification))
7949 || c->die_tag == DW_TAG_namespace
7950 || c->die_tag == DW_TAG_module);
7954 gen_internal_sym (const char *prefix)
7958 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7959 return xstrdup (buf);
7962 /* Assign symbols to all worthy DIEs under DIE. */
7965 assign_symbol_names (dw_die_ref die)
7969 if (is_symbol_die (die))
7971 if (comdat_symbol_id)
7973 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7975 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7976 comdat_symbol_id, comdat_symbol_number++);
7977 die->die_symbol = xstrdup (p);
7980 die->die_symbol = gen_internal_sym ("LDIE");
7983 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7986 struct cu_hash_table_entry
7989 unsigned min_comdat_num, max_comdat_num;
7990 struct cu_hash_table_entry *next;
7993 /* Routines to manipulate hash table of CUs. */
7995 htab_cu_hash (const void *of)
7997 const struct cu_hash_table_entry *const entry =
7998 (const struct cu_hash_table_entry *) of;
8000 return htab_hash_string (entry->cu->die_symbol);
8004 htab_cu_eq (const void *of1, const void *of2)
8006 const struct cu_hash_table_entry *const entry1 =
8007 (const struct cu_hash_table_entry *) of1;
8008 const struct die_struct *const entry2 = (const struct die_struct *) of2;
8010 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
8014 htab_cu_del (void *what)
8016 struct cu_hash_table_entry *next,
8017 *entry = (struct cu_hash_table_entry *) what;
8027 /* Check whether we have already seen this CU and set up SYM_NUM
8030 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
8032 struct cu_hash_table_entry dummy;
8033 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
8035 dummy.max_comdat_num = 0;
8037 slot = (struct cu_hash_table_entry **)
8038 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8042 for (; entry; last = entry, entry = entry->next)
8044 if (same_die_p_wrap (cu, entry->cu))
8050 *sym_num = entry->min_comdat_num;
8054 entry = XCNEW (struct cu_hash_table_entry);
8056 entry->min_comdat_num = *sym_num = last->max_comdat_num;
8057 entry->next = *slot;
8063 /* Record SYM_NUM to record of CU in HTABLE. */
8065 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
8067 struct cu_hash_table_entry **slot, *entry;
8069 slot = (struct cu_hash_table_entry **)
8070 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8074 entry->max_comdat_num = sym_num;
8077 /* Traverse the DIE (which is always comp_unit_die), and set up
8078 additional compilation units for each of the include files we see
8079 bracketed by BINCL/EINCL. */
8082 break_out_includes (dw_die_ref die)
8085 dw_die_ref unit = NULL;
8086 limbo_die_node *node, **pnode;
8087 htab_t cu_hash_table;
8091 dw_die_ref prev = c;
8093 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
8094 || (unit && is_comdat_die (c)))
8096 dw_die_ref next = c->die_sib;
8098 /* This DIE is for a secondary CU; remove it from the main one. */
8099 remove_child_with_prev (c, prev);
8101 if (c->die_tag == DW_TAG_GNU_BINCL)
8102 unit = push_new_compile_unit (unit, c);
8103 else if (c->die_tag == DW_TAG_GNU_EINCL)
8104 unit = pop_compile_unit (unit);
8106 add_child_die (unit, c);
8108 if (c == die->die_child)
8111 } while (c != die->die_child);
8114 /* We can only use this in debugging, since the frontend doesn't check
8115 to make sure that we leave every include file we enter. */
8119 assign_symbol_names (die);
8120 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
8121 for (node = limbo_die_list, pnode = &limbo_die_list;
8127 compute_section_prefix (node->die);
8128 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
8129 &comdat_symbol_number);
8130 assign_symbol_names (node->die);
8132 *pnode = node->next;
8135 pnode = &node->next;
8136 record_comdat_symbol_number (node->die, cu_hash_table,
8137 comdat_symbol_number);
8140 htab_delete (cu_hash_table);
8143 /* Traverse the DIE and add a sibling attribute if it may have the
8144 effect of speeding up access to siblings. To save some space,
8145 avoid generating sibling attributes for DIE's without children. */
8148 add_sibling_attributes (dw_die_ref die)
8152 if (! die->die_child)
8155 if (die->die_parent && die != die->die_parent->die_child)
8156 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8158 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8161 /* Output all location lists for the DIE and its children. */
8164 output_location_lists (dw_die_ref die)
8170 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8171 if (AT_class (a) == dw_val_class_loc_list)
8172 output_loc_list (AT_loc_list (a));
8174 FOR_EACH_CHILD (die, c, output_location_lists (c));
8177 /* The format of each DIE (and its attribute value pairs) is encoded in an
8178 abbreviation table. This routine builds the abbreviation table and assigns
8179 a unique abbreviation id for each abbreviation entry. The children of each
8180 die are visited recursively. */
8183 build_abbrev_table (dw_die_ref die)
8185 unsigned long abbrev_id;
8186 unsigned int n_alloc;
8191 /* Scan the DIE references, and mark as external any that refer to
8192 DIEs from other CUs (i.e. those which are not marked). */
8193 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8194 if (AT_class (a) == dw_val_class_die_ref
8195 && AT_ref (a)->die_mark == 0)
8197 gcc_assert (AT_ref (a)->die_symbol);
8198 set_AT_ref_external (a, 1);
8201 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8203 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8204 dw_attr_ref die_a, abbrev_a;
8208 if (abbrev->die_tag != die->die_tag)
8210 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8213 if (VEC_length (dw_attr_node, abbrev->die_attr)
8214 != VEC_length (dw_attr_node, die->die_attr))
8217 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
8219 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8220 if ((abbrev_a->dw_attr != die_a->dw_attr)
8221 || (value_format (abbrev_a) != value_format (die_a)))
8231 if (abbrev_id >= abbrev_die_table_in_use)
8233 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8235 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8236 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8239 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8240 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8241 abbrev_die_table_allocated = n_alloc;
8244 ++abbrev_die_table_in_use;
8245 abbrev_die_table[abbrev_id] = die;
8248 die->die_abbrev = abbrev_id;
8249 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8252 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8255 constant_size (unsigned HOST_WIDE_INT value)
8262 log = floor_log2 (value);
8265 log = 1 << (floor_log2 (log) + 1);
8270 /* Return the size of a DIE as it is represented in the
8271 .debug_info section. */
8273 static unsigned long
8274 size_of_die (dw_die_ref die)
8276 unsigned long size = 0;
8280 size += size_of_uleb128 (die->die_abbrev);
8281 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8283 switch (AT_class (a))
8285 case dw_val_class_addr:
8286 size += DWARF2_ADDR_SIZE;
8288 case dw_val_class_offset:
8289 size += DWARF_OFFSET_SIZE;
8291 case dw_val_class_loc:
8293 unsigned long lsize = size_of_locs (AT_loc (a));
8296 size += constant_size (lsize);
8300 case dw_val_class_loc_list:
8301 size += DWARF_OFFSET_SIZE;
8303 case dw_val_class_range_list:
8304 size += DWARF_OFFSET_SIZE;
8306 case dw_val_class_const:
8307 size += size_of_sleb128 (AT_int (a));
8309 case dw_val_class_unsigned_const:
8310 size += constant_size (AT_unsigned (a));
8312 case dw_val_class_long_long:
8313 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
8315 case dw_val_class_vec:
8316 size += constant_size (a->dw_attr_val.v.val_vec.length
8317 * a->dw_attr_val.v.val_vec.elt_size)
8318 + a->dw_attr_val.v.val_vec.length
8319 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8321 case dw_val_class_flag:
8324 case dw_val_class_die_ref:
8325 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8326 whereas in DWARF3 it's always sized as an offset. */
8327 if (AT_ref_external (a) && dwarf_version == 2)
8328 size += DWARF2_ADDR_SIZE;
8330 size += DWARF_OFFSET_SIZE;
8332 case dw_val_class_fde_ref:
8333 size += DWARF_OFFSET_SIZE;
8335 case dw_val_class_lbl_id:
8336 size += DWARF2_ADDR_SIZE;
8338 case dw_val_class_lineptr:
8339 case dw_val_class_macptr:
8340 size += DWARF_OFFSET_SIZE;
8342 case dw_val_class_str:
8343 if (AT_string_form (a) == DW_FORM_strp)
8344 size += DWARF_OFFSET_SIZE;
8346 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8348 case dw_val_class_file:
8349 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8359 /* Size the debugging information associated with a given DIE. Visits the
8360 DIE's children recursively. Updates the global variable next_die_offset, on
8361 each time through. Uses the current value of next_die_offset to update the
8362 die_offset field in each DIE. */
8365 calc_die_sizes (dw_die_ref die)
8369 die->die_offset = next_die_offset;
8370 next_die_offset += size_of_die (die);
8372 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8374 if (die->die_child != NULL)
8375 /* Count the null byte used to terminate sibling lists. */
8376 next_die_offset += 1;
8379 /* Set the marks for a die and its children. We do this so
8380 that we know whether or not a reference needs to use FORM_ref_addr; only
8381 DIEs in the same CU will be marked. We used to clear out the offset
8382 and use that as the flag, but ran into ordering problems. */
8385 mark_dies (dw_die_ref die)
8389 gcc_assert (!die->die_mark);
8392 FOR_EACH_CHILD (die, c, mark_dies (c));
8395 /* Clear the marks for a die and its children. */
8398 unmark_dies (dw_die_ref die)
8402 gcc_assert (die->die_mark);
8405 FOR_EACH_CHILD (die, c, unmark_dies (c));
8408 /* Clear the marks for a die, its children and referred dies. */
8411 unmark_all_dies (dw_die_ref die)
8421 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8423 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8424 if (AT_class (a) == dw_val_class_die_ref)
8425 unmark_all_dies (AT_ref (a));
8428 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8429 generated for the compilation unit. */
8431 static unsigned long
8432 size_of_pubnames (VEC (pubname_entry, gc) * names)
8438 size = DWARF_PUBNAMES_HEADER_SIZE;
8439 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8440 if (names != pubtype_table
8441 || p->die->die_offset != 0
8442 || !flag_eliminate_unused_debug_types)
8443 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8445 size += DWARF_OFFSET_SIZE;
8449 /* Return the size of the information in the .debug_aranges section. */
8451 static unsigned long
8452 size_of_aranges (void)
8456 size = DWARF_ARANGES_HEADER_SIZE;
8458 /* Count the address/length pair for this compilation unit. */
8459 if (text_section_used)
8460 size += 2 * DWARF2_ADDR_SIZE;
8461 if (cold_text_section_used)
8462 size += 2 * DWARF2_ADDR_SIZE;
8463 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8465 /* Count the two zero words used to terminated the address range table. */
8466 size += 2 * DWARF2_ADDR_SIZE;
8470 /* Select the encoding of an attribute value. */
8472 static enum dwarf_form
8473 value_format (dw_attr_ref a)
8475 switch (a->dw_attr_val.val_class)
8477 case dw_val_class_addr:
8478 return DW_FORM_addr;
8479 case dw_val_class_range_list:
8480 case dw_val_class_offset:
8481 case dw_val_class_loc_list:
8482 switch (DWARF_OFFSET_SIZE)
8485 return DW_FORM_data4;
8487 return DW_FORM_data8;
8491 case dw_val_class_loc:
8492 switch (constant_size (size_of_locs (AT_loc (a))))
8495 return DW_FORM_block1;
8497 return DW_FORM_block2;
8501 case dw_val_class_const:
8502 return DW_FORM_sdata;
8503 case dw_val_class_unsigned_const:
8504 switch (constant_size (AT_unsigned (a)))
8507 return DW_FORM_data1;
8509 return DW_FORM_data2;
8511 return DW_FORM_data4;
8513 return DW_FORM_data8;
8517 case dw_val_class_long_long:
8518 return DW_FORM_block1;
8519 case dw_val_class_vec:
8520 switch (constant_size (a->dw_attr_val.v.val_vec.length
8521 * a->dw_attr_val.v.val_vec.elt_size))
8524 return DW_FORM_block1;
8526 return DW_FORM_block2;
8528 return DW_FORM_block4;
8532 case dw_val_class_flag:
8533 return DW_FORM_flag;
8534 case dw_val_class_die_ref:
8535 if (AT_ref_external (a))
8536 return DW_FORM_ref_addr;
8539 case dw_val_class_fde_ref:
8540 return DW_FORM_data;
8541 case dw_val_class_lbl_id:
8542 return DW_FORM_addr;
8543 case dw_val_class_lineptr:
8544 case dw_val_class_macptr:
8545 return DW_FORM_data;
8546 case dw_val_class_str:
8547 return AT_string_form (a);
8548 case dw_val_class_file:
8549 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8552 return DW_FORM_data1;
8554 return DW_FORM_data2;
8556 return DW_FORM_data4;
8566 /* Output the encoding of an attribute value. */
8569 output_value_format (dw_attr_ref a)
8571 enum dwarf_form form = value_format (a);
8573 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8576 /* Output the .debug_abbrev section which defines the DIE abbreviation
8580 output_abbrev_section (void)
8582 unsigned long abbrev_id;
8584 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8586 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8590 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8591 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8592 dwarf_tag_name (abbrev->die_tag));
8594 if (abbrev->die_child != NULL)
8595 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8597 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8599 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8602 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8603 dwarf_attr_name (a_attr->dw_attr));
8604 output_value_format (a_attr);
8607 dw2_asm_output_data (1, 0, NULL);
8608 dw2_asm_output_data (1, 0, NULL);
8611 /* Terminate the table. */
8612 dw2_asm_output_data (1, 0, NULL);
8615 /* Output a symbol we can use to refer to this DIE from another CU. */
8618 output_die_symbol (dw_die_ref die)
8620 char *sym = die->die_symbol;
8625 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8626 /* We make these global, not weak; if the target doesn't support
8627 .linkonce, it doesn't support combining the sections, so debugging
8629 targetm.asm_out.globalize_label (asm_out_file, sym);
8631 ASM_OUTPUT_LABEL (asm_out_file, sym);
8634 /* Return a new location list, given the begin and end range, and the
8635 expression. gensym tells us whether to generate a new internal symbol for
8636 this location list node, which is done for the head of the list only. */
8638 static inline dw_loc_list_ref
8639 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8640 const char *section, unsigned int gensym)
8642 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8644 retlist->begin = begin;
8646 retlist->expr = expr;
8647 retlist->section = section;
8649 retlist->ll_symbol = gen_internal_sym ("LLST");
8654 /* Add a location description expression to a location list. */
8657 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8658 const char *begin, const char *end,
8659 const char *section)
8663 /* Find the end of the chain. */
8664 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8667 /* Add a new location list node to the list. */
8668 *d = new_loc_list (descr, begin, end, section, 0);
8671 /* Output the location list given to us. */
8674 output_loc_list (dw_loc_list_ref list_head)
8676 dw_loc_list_ref curr = list_head;
8678 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8680 /* Walk the location list, and output each range + expression. */
8681 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8684 /* Don't output an entry that starts and ends at the same address. */
8685 if (strcmp (curr->begin, curr->end) == 0)
8687 if (!have_multiple_function_sections)
8689 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8690 "Location list begin address (%s)",
8691 list_head->ll_symbol);
8692 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8693 "Location list end address (%s)",
8694 list_head->ll_symbol);
8698 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8699 "Location list begin address (%s)",
8700 list_head->ll_symbol);
8701 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8702 "Location list end address (%s)",
8703 list_head->ll_symbol);
8705 size = size_of_locs (curr->expr);
8707 /* Output the block length for this list of location operations. */
8708 gcc_assert (size <= 0xffff);
8709 dw2_asm_output_data (2, size, "%s", "Location expression size");
8711 output_loc_sequence (curr->expr);
8714 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8715 "Location list terminator begin (%s)",
8716 list_head->ll_symbol);
8717 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8718 "Location list terminator end (%s)",
8719 list_head->ll_symbol);
8722 /* Output the DIE and its attributes. Called recursively to generate
8723 the definitions of each child DIE. */
8726 output_die (dw_die_ref die)
8733 /* If someone in another CU might refer to us, set up a symbol for
8734 them to point to. */
8735 if (die->die_symbol)
8736 output_die_symbol (die);
8738 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8739 (unsigned long)die->die_offset,
8740 dwarf_tag_name (die->die_tag));
8742 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8744 const char *name = dwarf_attr_name (a->dw_attr);
8746 switch (AT_class (a))
8748 case dw_val_class_addr:
8749 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8752 case dw_val_class_offset:
8753 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8757 case dw_val_class_range_list:
8759 char *p = strchr (ranges_section_label, '\0');
8761 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8762 a->dw_attr_val.v.val_offset);
8763 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8764 debug_ranges_section, "%s", name);
8769 case dw_val_class_loc:
8770 size = size_of_locs (AT_loc (a));
8772 /* Output the block length for this list of location operations. */
8773 dw2_asm_output_data (constant_size (size), size, "%s", name);
8775 output_loc_sequence (AT_loc (a));
8778 case dw_val_class_const:
8779 /* ??? It would be slightly more efficient to use a scheme like is
8780 used for unsigned constants below, but gdb 4.x does not sign
8781 extend. Gdb 5.x does sign extend. */
8782 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8785 case dw_val_class_unsigned_const:
8786 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8787 AT_unsigned (a), "%s", name);
8790 case dw_val_class_long_long:
8792 unsigned HOST_WIDE_INT first, second;
8794 dw2_asm_output_data (1,
8795 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8798 if (WORDS_BIG_ENDIAN)
8800 first = a->dw_attr_val.v.val_long_long.hi;
8801 second = a->dw_attr_val.v.val_long_long.low;
8805 first = a->dw_attr_val.v.val_long_long.low;
8806 second = a->dw_attr_val.v.val_long_long.hi;
8809 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8810 first, "long long constant");
8811 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8816 case dw_val_class_vec:
8818 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8819 unsigned int len = a->dw_attr_val.v.val_vec.length;
8823 dw2_asm_output_data (constant_size (len * elt_size),
8824 len * elt_size, "%s", name);
8825 if (elt_size > sizeof (HOST_WIDE_INT))
8830 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8833 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8834 "fp or vector constant word %u", i);
8838 case dw_val_class_flag:
8839 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8842 case dw_val_class_loc_list:
8844 char *sym = AT_loc_list (a)->ll_symbol;
8847 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8852 case dw_val_class_die_ref:
8853 if (AT_ref_external (a))
8855 char *sym = AT_ref (a)->die_symbol;
8860 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8861 length, whereas in DWARF3 it's always sized as an offset. */
8862 if (dwarf_version == 2)
8863 size = DWARF2_ADDR_SIZE;
8865 size = DWARF_OFFSET_SIZE;
8866 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
8870 gcc_assert (AT_ref (a)->die_offset);
8871 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8876 case dw_val_class_fde_ref:
8880 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8881 a->dw_attr_val.v.val_fde_index * 2);
8882 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8887 case dw_val_class_lbl_id:
8888 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8891 case dw_val_class_lineptr:
8892 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8893 debug_line_section, "%s", name);
8896 case dw_val_class_macptr:
8897 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8898 debug_macinfo_section, "%s", name);
8901 case dw_val_class_str:
8902 if (AT_string_form (a) == DW_FORM_strp)
8903 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8904 a->dw_attr_val.v.val_str->label,
8906 "%s: \"%s\"", name, AT_string (a));
8908 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8911 case dw_val_class_file:
8913 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8915 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8916 a->dw_attr_val.v.val_file->filename);
8925 FOR_EACH_CHILD (die, c, output_die (c));
8927 /* Add null byte to terminate sibling list. */
8928 if (die->die_child != NULL)
8929 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8930 (unsigned long) die->die_offset);
8933 /* Output the compilation unit that appears at the beginning of the
8934 .debug_info section, and precedes the DIE descriptions. */
8937 output_compilation_unit_header (void)
8939 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8940 dw2_asm_output_data (4, 0xffffffff,
8941 "Initial length escape value indicating 64-bit DWARF extension");
8942 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8943 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8944 "Length of Compilation Unit Info");
8945 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
8946 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8947 debug_abbrev_section,
8948 "Offset Into Abbrev. Section");
8949 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8952 /* Output the compilation unit DIE and its children. */
8955 output_comp_unit (dw_die_ref die, int output_if_empty)
8957 const char *secname;
8960 /* Unless we are outputting main CU, we may throw away empty ones. */
8961 if (!output_if_empty && die->die_child == NULL)
8964 /* Even if there are no children of this DIE, we must output the information
8965 about the compilation unit. Otherwise, on an empty translation unit, we
8966 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8967 will then complain when examining the file. First mark all the DIEs in
8968 this CU so we know which get local refs. */
8971 build_abbrev_table (die);
8973 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8974 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8975 calc_die_sizes (die);
8977 oldsym = die->die_symbol;
8980 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8982 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8984 die->die_symbol = NULL;
8985 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8988 switch_to_section (debug_info_section);
8990 /* Output debugging information. */
8991 output_compilation_unit_header ();
8994 /* Leave the marks on the main CU, so we can check them in
8999 die->die_symbol = oldsym;
9003 /* Return the DWARF2/3 pubname associated with a decl. */
9006 dwarf2_name (tree decl, int scope)
9008 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9011 /* Add a new entry to .debug_pubnames if appropriate. */
9014 add_pubname_string (const char *str, dw_die_ref die)
9019 e.name = xstrdup (str);
9020 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9024 add_pubname (tree decl, dw_die_ref die)
9026 if (TREE_PUBLIC (decl))
9027 add_pubname_string (dwarf2_name (decl, 1), die);
9030 /* Add a new entry to .debug_pubtypes if appropriate. */
9033 add_pubtype (tree decl, dw_die_ref die)
9038 if ((TREE_PUBLIC (decl)
9039 || die->die_parent == comp_unit_die)
9040 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9045 if (TYPE_NAME (decl))
9047 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9048 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9049 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9050 && DECL_NAME (TYPE_NAME (decl)))
9051 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9053 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9057 e.name = xstrdup (dwarf2_name (decl, 1));
9059 /* If we don't have a name for the type, there's no point in adding
9061 if (e.name && e.name[0] != '\0')
9062 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9066 /* Output the public names table used to speed up access to externally
9067 visible names; or the public types table used to find type definitions. */
9070 output_pubnames (VEC (pubname_entry, gc) * names)
9073 unsigned long pubnames_length = size_of_pubnames (names);
9076 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9077 dw2_asm_output_data (4, 0xffffffff,
9078 "Initial length escape value indicating 64-bit DWARF extension");
9079 if (names == pubname_table)
9080 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9081 "Length of Public Names Info");
9083 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9084 "Length of Public Type Names Info");
9085 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9086 dw2_asm_output_data (2, 2, "DWARF Version");
9087 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9089 "Offset of Compilation Unit Info");
9090 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9091 "Compilation Unit Length");
9093 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
9095 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9096 if (names == pubname_table)
9097 gcc_assert (pub->die->die_mark);
9099 if (names != pubtype_table
9100 || pub->die->die_offset != 0
9101 || !flag_eliminate_unused_debug_types)
9103 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9106 dw2_asm_output_nstring (pub->name, -1, "external name");
9110 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9113 /* Add a new entry to .debug_aranges if appropriate. */
9116 add_arange (tree decl, dw_die_ref die)
9118 if (! DECL_SECTION_NAME (decl))
9121 if (arange_table_in_use == arange_table_allocated)
9123 arange_table_allocated += ARANGE_TABLE_INCREMENT;
9124 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
9125 arange_table_allocated);
9126 memset (arange_table + arange_table_in_use, 0,
9127 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
9130 arange_table[arange_table_in_use++] = die;
9133 /* Output the information that goes into the .debug_aranges table.
9134 Namely, define the beginning and ending address range of the
9135 text section generated for this compilation unit. */
9138 output_aranges (void)
9141 unsigned long aranges_length = size_of_aranges ();
9143 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9144 dw2_asm_output_data (4, 0xffffffff,
9145 "Initial length escape value indicating 64-bit DWARF extension");
9146 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9147 "Length of Address Ranges Info");
9148 /* Version number for aranges is still 2, even in DWARF3. */
9149 dw2_asm_output_data (2, 2, "DWARF Version");
9150 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9152 "Offset of Compilation Unit Info");
9153 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9154 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9156 /* We need to align to twice the pointer size here. */
9157 if (DWARF_ARANGES_PAD_SIZE)
9159 /* Pad using a 2 byte words so that padding is correct for any
9161 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9162 2 * DWARF2_ADDR_SIZE);
9163 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9164 dw2_asm_output_data (2, 0, NULL);
9167 /* It is necessary not to output these entries if the sections were
9168 not used; if the sections were not used, the length will be 0 and
9169 the address may end up as 0 if the section is discarded by ld
9170 --gc-sections, leaving an invalid (0, 0) entry that can be
9171 confused with the terminator. */
9172 if (text_section_used)
9174 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9175 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9176 text_section_label, "Length");
9178 if (cold_text_section_used)
9180 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9182 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9183 cold_text_section_label, "Length");
9186 for (i = 0; i < arange_table_in_use; i++)
9188 dw_die_ref die = arange_table[i];
9190 /* We shouldn't see aranges for DIEs outside of the main CU. */
9191 gcc_assert (die->die_mark);
9193 if (die->die_tag == DW_TAG_subprogram)
9195 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
9197 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
9198 get_AT_low_pc (die), "Length");
9202 /* A static variable; extract the symbol from DW_AT_location.
9203 Note that this code isn't currently hit, as we only emit
9204 aranges for functions (jason 9/23/99). */
9205 dw_attr_ref a = get_AT (die, DW_AT_location);
9206 dw_loc_descr_ref loc;
9208 gcc_assert (a && AT_class (a) == dw_val_class_loc);
9211 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
9213 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
9214 loc->dw_loc_oprnd1.v.val_addr, "Address");
9215 dw2_asm_output_data (DWARF2_ADDR_SIZE,
9216 get_AT_unsigned (die, DW_AT_byte_size),
9221 /* Output the terminator words. */
9222 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9223 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9226 /* Add a new entry to .debug_ranges. Return the offset at which it
9230 add_ranges_num (int num)
9232 unsigned int in_use = ranges_table_in_use;
9234 if (in_use == ranges_table_allocated)
9236 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9237 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9238 ranges_table_allocated);
9239 memset (ranges_table + ranges_table_in_use, 0,
9240 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9243 ranges_table[in_use].num = num;
9244 ranges_table_in_use = in_use + 1;
9246 return in_use * 2 * DWARF2_ADDR_SIZE;
9249 /* Add a new entry to .debug_ranges corresponding to a block, or a
9250 range terminator if BLOCK is NULL. */
9253 add_ranges (const_tree block)
9255 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9258 /* Add a new entry to .debug_ranges corresponding to a pair of
9262 add_ranges_by_labels (const char *begin, const char *end)
9264 unsigned int in_use = ranges_by_label_in_use;
9266 if (in_use == ranges_by_label_allocated)
9268 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9269 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9271 ranges_by_label_allocated);
9272 memset (ranges_by_label + ranges_by_label_in_use, 0,
9273 RANGES_TABLE_INCREMENT
9274 * sizeof (struct dw_ranges_by_label_struct));
9277 ranges_by_label[in_use].begin = begin;
9278 ranges_by_label[in_use].end = end;
9279 ranges_by_label_in_use = in_use + 1;
9281 return add_ranges_num (-(int)in_use - 1);
9285 output_ranges (void)
9288 static const char *const start_fmt = "Offset 0x%x";
9289 const char *fmt = start_fmt;
9291 for (i = 0; i < ranges_table_in_use; i++)
9293 int block_num = ranges_table[i].num;
9297 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9298 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9300 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9301 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9303 /* If all code is in the text section, then the compilation
9304 unit base address defaults to DW_AT_low_pc, which is the
9305 base of the text section. */
9306 if (!have_multiple_function_sections)
9308 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9310 fmt, i * 2 * DWARF2_ADDR_SIZE);
9311 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9312 text_section_label, NULL);
9315 /* Otherwise, the compilation unit base address is zero,
9316 which allows us to use absolute addresses, and not worry
9317 about whether the target supports cross-section
9321 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9322 fmt, i * 2 * DWARF2_ADDR_SIZE);
9323 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9329 /* Negative block_num stands for an index into ranges_by_label. */
9330 else if (block_num < 0)
9332 int lab_idx = - block_num - 1;
9334 if (!have_multiple_function_sections)
9338 /* If we ever use add_ranges_by_labels () for a single
9339 function section, all we have to do is to take out
9341 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9342 ranges_by_label[lab_idx].begin,
9344 fmt, i * 2 * DWARF2_ADDR_SIZE);
9345 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9346 ranges_by_label[lab_idx].end,
9347 text_section_label, NULL);
9352 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9353 ranges_by_label[lab_idx].begin,
9354 fmt, i * 2 * DWARF2_ADDR_SIZE);
9355 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9356 ranges_by_label[lab_idx].end,
9362 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9363 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9369 /* Data structure containing information about input files. */
9372 const char *path; /* Complete file name. */
9373 const char *fname; /* File name part. */
9374 int length; /* Length of entire string. */
9375 struct dwarf_file_data * file_idx; /* Index in input file table. */
9376 int dir_idx; /* Index in directory table. */
9379 /* Data structure containing information about directories with source
9383 const char *path; /* Path including directory name. */
9384 int length; /* Path length. */
9385 int prefix; /* Index of directory entry which is a prefix. */
9386 int count; /* Number of files in this directory. */
9387 int dir_idx; /* Index of directory used as base. */
9390 /* Callback function for file_info comparison. We sort by looking at
9391 the directories in the path. */
9394 file_info_cmp (const void *p1, const void *p2)
9396 const struct file_info *const s1 = (const struct file_info *) p1;
9397 const struct file_info *const s2 = (const struct file_info *) p2;
9398 const unsigned char *cp1;
9399 const unsigned char *cp2;
9401 /* Take care of file names without directories. We need to make sure that
9402 we return consistent values to qsort since some will get confused if
9403 we return the same value when identical operands are passed in opposite
9404 orders. So if neither has a directory, return 0 and otherwise return
9405 1 or -1 depending on which one has the directory. */
9406 if ((s1->path == s1->fname || s2->path == s2->fname))
9407 return (s2->path == s2->fname) - (s1->path == s1->fname);
9409 cp1 = (const unsigned char *) s1->path;
9410 cp2 = (const unsigned char *) s2->path;
9416 /* Reached the end of the first path? If so, handle like above. */
9417 if ((cp1 == (const unsigned char *) s1->fname)
9418 || (cp2 == (const unsigned char *) s2->fname))
9419 return ((cp2 == (const unsigned char *) s2->fname)
9420 - (cp1 == (const unsigned char *) s1->fname));
9422 /* Character of current path component the same? */
9423 else if (*cp1 != *cp2)
9428 struct file_name_acquire_data
9430 struct file_info *files;
9435 /* Traversal function for the hash table. */
9438 file_name_acquire (void ** slot, void *data)
9440 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9441 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9442 struct file_info *fi;
9445 gcc_assert (fnad->max_files >= d->emitted_number);
9447 if (! d->emitted_number)
9450 gcc_assert (fnad->max_files != fnad->used_files);
9452 fi = fnad->files + fnad->used_files++;
9454 /* Skip all leading "./". */
9456 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9459 /* Create a new array entry. */
9461 fi->length = strlen (f);
9464 /* Search for the file name part. */
9465 f = strrchr (f, DIR_SEPARATOR);
9466 #if defined (DIR_SEPARATOR_2)
9468 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9472 if (f == NULL || f < g)
9478 fi->fname = f == NULL ? fi->path : f + 1;
9482 /* Output the directory table and the file name table. We try to minimize
9483 the total amount of memory needed. A heuristic is used to avoid large
9484 slowdowns with many input files. */
9487 output_file_names (void)
9489 struct file_name_acquire_data fnad;
9491 struct file_info *files;
9492 struct dir_info *dirs;
9501 if (!last_emitted_file)
9503 dw2_asm_output_data (1, 0, "End directory table");
9504 dw2_asm_output_data (1, 0, "End file name table");
9508 numfiles = last_emitted_file->emitted_number;
9510 /* Allocate the various arrays we need. */
9511 files = XALLOCAVEC (struct file_info, numfiles);
9512 dirs = XALLOCAVEC (struct dir_info, numfiles);
9515 fnad.used_files = 0;
9516 fnad.max_files = numfiles;
9517 htab_traverse (file_table, file_name_acquire, &fnad);
9518 gcc_assert (fnad.used_files == fnad.max_files);
9520 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9522 /* Find all the different directories used. */
9523 dirs[0].path = files[0].path;
9524 dirs[0].length = files[0].fname - files[0].path;
9525 dirs[0].prefix = -1;
9527 dirs[0].dir_idx = 0;
9528 files[0].dir_idx = 0;
9531 for (i = 1; i < numfiles; i++)
9532 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9533 && memcmp (dirs[ndirs - 1].path, files[i].path,
9534 dirs[ndirs - 1].length) == 0)
9536 /* Same directory as last entry. */
9537 files[i].dir_idx = ndirs - 1;
9538 ++dirs[ndirs - 1].count;
9544 /* This is a new directory. */
9545 dirs[ndirs].path = files[i].path;
9546 dirs[ndirs].length = files[i].fname - files[i].path;
9547 dirs[ndirs].count = 1;
9548 dirs[ndirs].dir_idx = ndirs;
9549 files[i].dir_idx = ndirs;
9551 /* Search for a prefix. */
9552 dirs[ndirs].prefix = -1;
9553 for (j = 0; j < ndirs; j++)
9554 if (dirs[j].length < dirs[ndirs].length
9555 && dirs[j].length > 1
9556 && (dirs[ndirs].prefix == -1
9557 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9558 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9559 dirs[ndirs].prefix = j;
9564 /* Now to the actual work. We have to find a subset of the directories which
9565 allow expressing the file name using references to the directory table
9566 with the least amount of characters. We do not do an exhaustive search
9567 where we would have to check out every combination of every single
9568 possible prefix. Instead we use a heuristic which provides nearly optimal
9569 results in most cases and never is much off. */
9570 saved = XALLOCAVEC (int, ndirs);
9571 savehere = XALLOCAVEC (int, ndirs);
9573 memset (saved, '\0', ndirs * sizeof (saved[0]));
9574 for (i = 0; i < ndirs; i++)
9579 /* We can always save some space for the current directory. But this
9580 does not mean it will be enough to justify adding the directory. */
9581 savehere[i] = dirs[i].length;
9582 total = (savehere[i] - saved[i]) * dirs[i].count;
9584 for (j = i + 1; j < ndirs; j++)
9587 if (saved[j] < dirs[i].length)
9589 /* Determine whether the dirs[i] path is a prefix of the
9594 while (k != -1 && k != (int) i)
9599 /* Yes it is. We can possibly save some memory by
9600 writing the filenames in dirs[j] relative to
9602 savehere[j] = dirs[i].length;
9603 total += (savehere[j] - saved[j]) * dirs[j].count;
9608 /* Check whether we can save enough to justify adding the dirs[i]
9610 if (total > dirs[i].length + 1)
9612 /* It's worthwhile adding. */
9613 for (j = i; j < ndirs; j++)
9614 if (savehere[j] > 0)
9616 /* Remember how much we saved for this directory so far. */
9617 saved[j] = savehere[j];
9619 /* Remember the prefix directory. */
9620 dirs[j].dir_idx = i;
9625 /* Emit the directory name table. */
9627 idx_offset = dirs[0].length > 0 ? 1 : 0;
9628 for (i = 1 - idx_offset; i < ndirs; i++)
9629 dw2_asm_output_nstring (dirs[i].path,
9631 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9632 "Directory Entry: 0x%x", i + idx_offset);
9634 dw2_asm_output_data (1, 0, "End directory table");
9636 /* We have to emit them in the order of emitted_number since that's
9637 used in the debug info generation. To do this efficiently we
9638 generate a back-mapping of the indices first. */
9639 backmap = XALLOCAVEC (int, numfiles);
9640 for (i = 0; i < numfiles; i++)
9641 backmap[files[i].file_idx->emitted_number - 1] = i;
9643 /* Now write all the file names. */
9644 for (i = 0; i < numfiles; i++)
9646 int file_idx = backmap[i];
9647 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9649 #ifdef VMS_DEBUGGING_INFO
9650 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9652 /* Setting these fields can lead to debugger miscomparisons,
9653 but VMS Debug requires them to be set correctly. */
9658 int maxfilelen = strlen (files[file_idx].path)
9659 + dirs[dir_idx].length
9660 + MAX_VMS_VERSION_LEN + 1;
9661 char *filebuf = XALLOCAVEC (char, maxfilelen);
9663 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9664 snprintf (filebuf, maxfilelen, "%s;%d",
9665 files[file_idx].path + dirs[dir_idx].length, ver);
9667 dw2_asm_output_nstring
9668 (filebuf, -1, "File Entry: 0x%x", (unsigned) i + 1);
9670 /* Include directory index. */
9671 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9673 /* Modification time. */
9674 dw2_asm_output_data_uleb128
9675 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9679 /* File length in bytes. */
9680 dw2_asm_output_data_uleb128
9681 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9685 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9686 "File Entry: 0x%x", (unsigned) i + 1);
9688 /* Include directory index. */
9689 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9691 /* Modification time. */
9692 dw2_asm_output_data_uleb128 (0, NULL);
9694 /* File length in bytes. */
9695 dw2_asm_output_data_uleb128 (0, NULL);
9699 dw2_asm_output_data (1, 0, "End file name table");
9703 /* Output the source line number correspondence information. This
9704 information goes into the .debug_line section. */
9707 output_line_info (void)
9709 char l1[20], l2[20], p1[20], p2[20];
9710 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9711 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9714 unsigned long lt_index;
9715 unsigned long current_line;
9718 unsigned long current_file;
9719 unsigned long function;
9721 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9722 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9723 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9724 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9726 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9727 dw2_asm_output_data (4, 0xffffffff,
9728 "Initial length escape value indicating 64-bit DWARF extension");
9729 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9730 "Length of Source Line Info");
9731 ASM_OUTPUT_LABEL (asm_out_file, l1);
9733 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9734 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9735 ASM_OUTPUT_LABEL (asm_out_file, p1);
9737 /* Define the architecture-dependent minimum instruction length (in
9738 bytes). In this implementation of DWARF, this field is used for
9739 information purposes only. Since GCC generates assembly language,
9740 we have no a priori knowledge of how many instruction bytes are
9741 generated for each source line, and therefore can use only the
9742 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9743 commands. Accordingly, we fix this as `1', which is "correct
9744 enough" for all architectures, and don't let the target override. */
9745 dw2_asm_output_data (1, 1,
9746 "Minimum Instruction Length");
9748 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9749 "Default is_stmt_start flag");
9750 dw2_asm_output_data (1, DWARF_LINE_BASE,
9751 "Line Base Value (Special Opcodes)");
9752 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9753 "Line Range Value (Special Opcodes)");
9754 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9755 "Special Opcode Base");
9757 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9761 case DW_LNS_advance_pc:
9762 case DW_LNS_advance_line:
9763 case DW_LNS_set_file:
9764 case DW_LNS_set_column:
9765 case DW_LNS_fixed_advance_pc:
9773 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9777 /* Write out the information about the files we use. */
9778 output_file_names ();
9779 ASM_OUTPUT_LABEL (asm_out_file, p2);
9781 /* We used to set the address register to the first location in the text
9782 section here, but that didn't accomplish anything since we already
9783 have a line note for the opening brace of the first function. */
9785 /* Generate the line number to PC correspondence table, encoded as
9786 a series of state machine operations. */
9790 if (cfun && in_cold_section_p)
9791 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9793 strcpy (prev_line_label, text_section_label);
9794 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9796 dw_line_info_ref line_info = &line_info_table[lt_index];
9799 /* Disable this optimization for now; GDB wants to see two line notes
9800 at the beginning of a function so it can find the end of the
9803 /* Don't emit anything for redundant notes. Just updating the
9804 address doesn't accomplish anything, because we already assume
9805 that anything after the last address is this line. */
9806 if (line_info->dw_line_num == current_line
9807 && line_info->dw_file_num == current_file)
9811 /* Emit debug info for the address of the current line.
9813 Unfortunately, we have little choice here currently, and must always
9814 use the most general form. GCC does not know the address delta
9815 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9816 attributes which will give an upper bound on the address range. We
9817 could perhaps use length attributes to determine when it is safe to
9818 use DW_LNS_fixed_advance_pc. */
9820 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9823 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9824 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9825 "DW_LNS_fixed_advance_pc");
9826 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9830 /* This can handle any delta. This takes
9831 4+DWARF2_ADDR_SIZE bytes. */
9832 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9833 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9834 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9835 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9838 strcpy (prev_line_label, line_label);
9840 /* Emit debug info for the source file of the current line, if
9841 different from the previous line. */
9842 if (line_info->dw_file_num != current_file)
9844 current_file = line_info->dw_file_num;
9845 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9846 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9849 /* Emit debug info for the current line number, choosing the encoding
9850 that uses the least amount of space. */
9851 if (line_info->dw_line_num != current_line)
9853 line_offset = line_info->dw_line_num - current_line;
9854 line_delta = line_offset - DWARF_LINE_BASE;
9855 current_line = line_info->dw_line_num;
9856 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9857 /* This can handle deltas from -10 to 234, using the current
9858 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9860 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9861 "line %lu", current_line);
9864 /* This can handle any delta. This takes at least 4 bytes,
9865 depending on the value being encoded. */
9866 dw2_asm_output_data (1, DW_LNS_advance_line,
9867 "advance to line %lu", current_line);
9868 dw2_asm_output_data_sleb128 (line_offset, NULL);
9869 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9873 /* We still need to start a new row, so output a copy insn. */
9874 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9877 /* Emit debug info for the address of the end of the function. */
9880 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9881 "DW_LNS_fixed_advance_pc");
9882 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9886 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9887 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9888 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9889 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9892 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9893 dw2_asm_output_data_uleb128 (1, NULL);
9894 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9899 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9901 dw_separate_line_info_ref line_info
9902 = &separate_line_info_table[lt_index];
9905 /* Don't emit anything for redundant notes. */
9906 if (line_info->dw_line_num == current_line
9907 && line_info->dw_file_num == current_file
9908 && line_info->function == function)
9912 /* Emit debug info for the address of the current line. If this is
9913 a new function, or the first line of a function, then we need
9914 to handle it differently. */
9915 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9917 if (function != line_info->function)
9919 function = line_info->function;
9921 /* Set the address register to the first line in the function. */
9922 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9923 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9924 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9925 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9929 /* ??? See the DW_LNS_advance_pc comment above. */
9932 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9933 "DW_LNS_fixed_advance_pc");
9934 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9938 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9939 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9940 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9941 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9945 strcpy (prev_line_label, line_label);
9947 /* Emit debug info for the source file of the current line, if
9948 different from the previous line. */
9949 if (line_info->dw_file_num != current_file)
9951 current_file = line_info->dw_file_num;
9952 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9953 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9956 /* Emit debug info for the current line number, choosing the encoding
9957 that uses the least amount of space. */
9958 if (line_info->dw_line_num != current_line)
9960 line_offset = line_info->dw_line_num - current_line;
9961 line_delta = line_offset - DWARF_LINE_BASE;
9962 current_line = line_info->dw_line_num;
9963 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9964 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9965 "line %lu", current_line);
9968 dw2_asm_output_data (1, DW_LNS_advance_line,
9969 "advance to line %lu", current_line);
9970 dw2_asm_output_data_sleb128 (line_offset, NULL);
9971 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9975 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9983 /* If we're done with a function, end its sequence. */
9984 if (lt_index == separate_line_info_table_in_use
9985 || separate_line_info_table[lt_index].function != function)
9990 /* Emit debug info for the address of the end of the function. */
9991 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9994 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9995 "DW_LNS_fixed_advance_pc");
9996 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10000 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10001 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10002 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10003 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10006 /* Output the marker for the end of this sequence. */
10007 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10008 dw2_asm_output_data_uleb128 (1, NULL);
10009 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10013 /* Output the marker for the end of the line number info. */
10014 ASM_OUTPUT_LABEL (asm_out_file, l2);
10017 /* Given a pointer to a tree node for some base type, return a pointer to
10018 a DIE that describes the given type.
10020 This routine must only be called for GCC type nodes that correspond to
10021 Dwarf base (fundamental) types. */
10024 base_type_die (tree type)
10026 dw_die_ref base_type_result;
10027 enum dwarf_type encoding;
10029 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10032 /* If this is a subtype that should not be emitted as a subrange type,
10033 use the base type. See subrange_type_for_debug_p. */
10034 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10035 type = TREE_TYPE (type);
10037 switch (TREE_CODE (type))
10040 if (TYPE_STRING_FLAG (type))
10042 if (TYPE_UNSIGNED (type))
10043 encoding = DW_ATE_unsigned_char;
10045 encoding = DW_ATE_signed_char;
10047 else if (TYPE_UNSIGNED (type))
10048 encoding = DW_ATE_unsigned;
10050 encoding = DW_ATE_signed;
10054 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10055 encoding = DW_ATE_decimal_float;
10057 encoding = DW_ATE_float;
10060 case FIXED_POINT_TYPE:
10061 if (TYPE_UNSIGNED (type))
10062 encoding = DW_ATE_unsigned_fixed;
10064 encoding = DW_ATE_signed_fixed;
10067 /* Dwarf2 doesn't know anything about complex ints, so use
10068 a user defined type for it. */
10070 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10071 encoding = DW_ATE_complex_float;
10073 encoding = DW_ATE_lo_user;
10077 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10078 encoding = DW_ATE_boolean;
10082 /* No other TREE_CODEs are Dwarf fundamental types. */
10083 gcc_unreachable ();
10086 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
10088 /* This probably indicates a bug. */
10089 if (! TYPE_NAME (type))
10090 add_name_attribute (base_type_result, "__unknown__");
10092 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10093 int_size_in_bytes (type));
10094 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10096 return base_type_result;
10099 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10100 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10103 is_base_type (tree type)
10105 switch (TREE_CODE (type))
10111 case FIXED_POINT_TYPE:
10119 case QUAL_UNION_TYPE:
10120 case ENUMERAL_TYPE:
10121 case FUNCTION_TYPE:
10124 case REFERENCE_TYPE:
10131 gcc_unreachable ();
10137 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10138 node, return the size in bits for the type if it is a constant, or else
10139 return the alignment for the type if the type's size is not constant, or
10140 else return BITS_PER_WORD if the type actually turns out to be an
10141 ERROR_MARK node. */
10143 static inline unsigned HOST_WIDE_INT
10144 simple_type_size_in_bits (const_tree type)
10146 if (TREE_CODE (type) == ERROR_MARK)
10147 return BITS_PER_WORD;
10148 else if (TYPE_SIZE (type) == NULL_TREE)
10150 else if (host_integerp (TYPE_SIZE (type), 1))
10151 return tree_low_cst (TYPE_SIZE (type), 1);
10153 return TYPE_ALIGN (type);
10156 /* Given a pointer to a tree node for a subrange type, return a pointer
10157 to a DIE that describes the given type. */
10160 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10162 dw_die_ref subrange_die;
10163 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10165 if (context_die == NULL)
10166 context_die = comp_unit_die;
10168 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10170 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10172 /* The size of the subrange type and its base type do not match,
10173 so we need to generate a size attribute for the subrange type. */
10174 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10178 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10180 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10182 return subrange_die;
10185 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10186 entry that chains various modifiers in front of the given type. */
10189 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10190 dw_die_ref context_die)
10192 enum tree_code code = TREE_CODE (type);
10193 dw_die_ref mod_type_die;
10194 dw_die_ref sub_die = NULL;
10195 tree item_type = NULL;
10196 tree qualified_type;
10197 tree name, low, high;
10199 if (code == ERROR_MARK)
10202 /* See if we already have the appropriately qualified variant of
10205 = get_qualified_type (type,
10206 ((is_const_type ? TYPE_QUAL_CONST : 0)
10207 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10209 /* If we do, then we can just use its DIE, if it exists. */
10210 if (qualified_type)
10212 mod_type_die = lookup_type_die (qualified_type);
10214 return mod_type_die;
10217 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10219 /* Handle C typedef types. */
10220 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
10222 tree dtype = TREE_TYPE (name);
10224 if (qualified_type == dtype)
10226 /* For a named type, use the typedef. */
10227 gen_type_die (qualified_type, context_die);
10228 return lookup_type_die (qualified_type);
10230 else if (is_const_type < TYPE_READONLY (dtype)
10231 || is_volatile_type < TYPE_VOLATILE (dtype)
10232 || (is_const_type <= TYPE_READONLY (dtype)
10233 && is_volatile_type <= TYPE_VOLATILE (dtype)
10234 && DECL_ORIGINAL_TYPE (name) != type))
10235 /* cv-unqualified version of named type. Just use the unnamed
10236 type to which it refers. */
10237 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10238 is_const_type, is_volatile_type,
10240 /* Else cv-qualified version of named type; fall through. */
10245 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
10246 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10248 else if (is_volatile_type)
10250 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
10251 sub_die = modified_type_die (type, 0, 0, context_die);
10253 else if (code == POINTER_TYPE)
10255 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
10256 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10257 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10258 item_type = TREE_TYPE (type);
10260 else if (code == REFERENCE_TYPE)
10262 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
10263 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10264 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10265 item_type = TREE_TYPE (type);
10267 else if (code == INTEGER_TYPE
10268 && TREE_TYPE (type) != NULL_TREE
10269 && subrange_type_for_debug_p (type, &low, &high))
10271 mod_type_die = subrange_type_die (type, low, high, context_die);
10272 item_type = TREE_TYPE (type);
10274 else if (is_base_type (type))
10275 mod_type_die = base_type_die (type);
10278 gen_type_die (type, context_die);
10280 /* We have to get the type_main_variant here (and pass that to the
10281 `lookup_type_die' routine) because the ..._TYPE node we have
10282 might simply be a *copy* of some original type node (where the
10283 copy was created to help us keep track of typedef names) and
10284 that copy might have a different TYPE_UID from the original
10286 if (TREE_CODE (type) != VECTOR_TYPE)
10287 return lookup_type_die (type_main_variant (type));
10289 /* Vectors have the debugging information in the type,
10290 not the main variant. */
10291 return lookup_type_die (type);
10294 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10295 don't output a DW_TAG_typedef, since there isn't one in the
10296 user's program; just attach a DW_AT_name to the type. */
10298 && (TREE_CODE (name) != TYPE_DECL
10299 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
10301 if (TREE_CODE (name) == TYPE_DECL)
10302 /* Could just call add_name_and_src_coords_attributes here,
10303 but since this is a builtin type it doesn't have any
10304 useful source coordinates anyway. */
10305 name = DECL_NAME (name);
10306 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10309 if (qualified_type)
10310 equate_type_number_to_die (qualified_type, mod_type_die);
10313 /* We must do this after the equate_type_number_to_die call, in case
10314 this is a recursive type. This ensures that the modified_type_die
10315 recursion will terminate even if the type is recursive. Recursive
10316 types are possible in Ada. */
10317 sub_die = modified_type_die (item_type,
10318 TYPE_READONLY (item_type),
10319 TYPE_VOLATILE (item_type),
10322 if (sub_die != NULL)
10323 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10325 return mod_type_die;
10328 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10329 an enumerated type. */
10332 type_is_enum (const_tree type)
10334 return TREE_CODE (type) == ENUMERAL_TYPE;
10337 /* Return the DBX register number described by a given RTL node. */
10339 static unsigned int
10340 dbx_reg_number (const_rtx rtl)
10342 unsigned regno = REGNO (rtl);
10344 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10346 #ifdef LEAF_REG_REMAP
10347 if (current_function_uses_only_leaf_regs)
10349 int leaf_reg = LEAF_REG_REMAP (regno);
10350 if (leaf_reg != -1)
10351 regno = (unsigned) leaf_reg;
10355 return DBX_REGISTER_NUMBER (regno);
10358 /* Optionally add a DW_OP_piece term to a location description expression.
10359 DW_OP_piece is only added if the location description expression already
10360 doesn't end with DW_OP_piece. */
10363 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10365 dw_loc_descr_ref loc;
10367 if (*list_head != NULL)
10369 /* Find the end of the chain. */
10370 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10373 if (loc->dw_loc_opc != DW_OP_piece)
10374 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10378 /* Return a location descriptor that designates a machine register or
10379 zero if there is none. */
10381 static dw_loc_descr_ref
10382 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10386 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10389 regs = targetm.dwarf_register_span (rtl);
10391 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10392 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10394 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10397 /* Return a location descriptor that designates a machine register for
10398 a given hard register number. */
10400 static dw_loc_descr_ref
10401 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10403 dw_loc_descr_ref reg_loc_descr;
10407 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10409 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10411 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10412 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10414 return reg_loc_descr;
10417 /* Given an RTL of a register, return a location descriptor that
10418 designates a value that spans more than one register. */
10420 static dw_loc_descr_ref
10421 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10422 enum var_init_status initialized)
10424 int nregs, size, i;
10426 dw_loc_descr_ref loc_result = NULL;
10429 #ifdef LEAF_REG_REMAP
10430 if (current_function_uses_only_leaf_regs)
10432 int leaf_reg = LEAF_REG_REMAP (reg);
10433 if (leaf_reg != -1)
10434 reg = (unsigned) leaf_reg;
10437 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10438 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10440 /* Simple, contiguous registers. */
10441 if (regs == NULL_RTX)
10443 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10448 dw_loc_descr_ref t;
10450 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10451 VAR_INIT_STATUS_INITIALIZED);
10452 add_loc_descr (&loc_result, t);
10453 add_loc_descr_op_piece (&loc_result, size);
10459 /* Now onto stupid register sets in non contiguous locations. */
10461 gcc_assert (GET_CODE (regs) == PARALLEL);
10463 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10466 for (i = 0; i < XVECLEN (regs, 0); ++i)
10468 dw_loc_descr_ref t;
10470 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10471 VAR_INIT_STATUS_INITIALIZED);
10472 add_loc_descr (&loc_result, t);
10473 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10474 add_loc_descr_op_piece (&loc_result, size);
10477 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10478 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10482 #endif /* DWARF2_DEBUGGING_INFO */
10484 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10486 /* Return a location descriptor that designates a constant. */
10488 static dw_loc_descr_ref
10489 int_loc_descriptor (HOST_WIDE_INT i)
10491 enum dwarf_location_atom op;
10493 /* Pick the smallest representation of a constant, rather than just
10494 defaulting to the LEB encoding. */
10498 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10499 else if (i <= 0xff)
10500 op = DW_OP_const1u;
10501 else if (i <= 0xffff)
10502 op = DW_OP_const2u;
10503 else if (HOST_BITS_PER_WIDE_INT == 32
10504 || i <= 0xffffffff)
10505 op = DW_OP_const4u;
10512 op = DW_OP_const1s;
10513 else if (i >= -0x8000)
10514 op = DW_OP_const2s;
10515 else if (HOST_BITS_PER_WIDE_INT == 32
10516 || i >= -0x80000000)
10517 op = DW_OP_const4s;
10522 return new_loc_descr (op, i, 0);
10526 #ifdef DWARF2_DEBUGGING_INFO
10528 /* Return a location descriptor that designates a base+offset location. */
10530 static dw_loc_descr_ref
10531 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10532 enum var_init_status initialized)
10534 unsigned int regno;
10535 dw_loc_descr_ref result;
10536 dw_fde_ref fde = current_fde ();
10538 /* We only use "frame base" when we're sure we're talking about the
10539 post-prologue local stack frame. We do this by *not* running
10540 register elimination until this point, and recognizing the special
10541 argument pointer and soft frame pointer rtx's. */
10542 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10544 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10548 if (GET_CODE (elim) == PLUS)
10550 offset += INTVAL (XEXP (elim, 1));
10551 elim = XEXP (elim, 0);
10553 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10554 && (elim == hard_frame_pointer_rtx
10555 || elim == stack_pointer_rtx))
10556 || elim == (frame_pointer_needed
10557 ? hard_frame_pointer_rtx
10558 : stack_pointer_rtx));
10560 /* If drap register is used to align stack, use frame
10561 pointer + offset to access stack variables. If stack
10562 is aligned without drap, use stack pointer + offset to
10563 access stack variables. */
10564 if (crtl->stack_realign_tried
10565 && reg == frame_pointer_rtx)
10568 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10569 ? HARD_FRAME_POINTER_REGNUM
10570 : STACK_POINTER_REGNUM);
10571 return new_reg_loc_descr (base_reg, offset);
10574 offset += frame_pointer_fb_offset;
10575 return new_loc_descr (DW_OP_fbreg, offset, 0);
10579 && fde->drap_reg != INVALID_REGNUM
10580 && (fde->drap_reg == REGNO (reg)
10581 || fde->vdrap_reg == REGNO (reg)))
10583 /* Use cfa+offset to represent the location of arguments passed
10584 on stack when drap is used to align stack. */
10585 return new_loc_descr (DW_OP_fbreg, offset, 0);
10588 regno = dbx_reg_number (reg);
10590 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10593 result = new_loc_descr (DW_OP_bregx, regno, offset);
10595 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10596 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10601 /* Return true if this RTL expression describes a base+offset calculation. */
10604 is_based_loc (const_rtx rtl)
10606 return (GET_CODE (rtl) == PLUS
10607 && ((REG_P (XEXP (rtl, 0))
10608 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10609 && CONST_INT_P (XEXP (rtl, 1)))));
10612 /* Return a descriptor that describes the concatenation of N locations
10613 used to form the address of a memory location. */
10615 static dw_loc_descr_ref
10616 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
10617 enum var_init_status initialized)
10620 dw_loc_descr_ref cc_loc_result = NULL;
10621 unsigned int n = XVECLEN (concatn, 0);
10623 for (i = 0; i < n; ++i)
10625 dw_loc_descr_ref ref;
10626 rtx x = XVECEXP (concatn, 0, i);
10628 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
10632 add_loc_descr (&cc_loc_result, ref);
10633 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10636 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10637 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10639 return cc_loc_result;
10642 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10645 static dw_loc_descr_ref
10646 tls_mem_loc_descriptor (rtx mem)
10649 dw_loc_descr_ref loc_result;
10651 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
10654 base = get_base_address (MEM_EXPR (mem));
10656 || TREE_CODE (base) != VAR_DECL
10657 || !DECL_THREAD_LOCAL_P (base))
10660 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
10661 if (loc_result == NULL)
10664 if (INTVAL (MEM_OFFSET (mem)))
10665 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
10670 /* The following routine converts the RTL for a variable or parameter
10671 (resident in memory) into an equivalent Dwarf representation of a
10672 mechanism for getting the address of that same variable onto the top of a
10673 hypothetical "address evaluation" stack.
10675 When creating memory location descriptors, we are effectively transforming
10676 the RTL for a memory-resident object into its Dwarf postfix expression
10677 equivalent. This routine recursively descends an RTL tree, turning
10678 it into Dwarf postfix code as it goes.
10680 MODE is the mode of the memory reference, needed to handle some
10681 autoincrement addressing modes.
10683 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
10684 location list for RTL.
10686 Return 0 if we can't represent the location. */
10688 static dw_loc_descr_ref
10689 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
10690 enum var_init_status initialized)
10692 dw_loc_descr_ref mem_loc_result = NULL;
10693 enum dwarf_location_atom op;
10695 /* Note that for a dynamically sized array, the location we will generate a
10696 description of here will be the lowest numbered location which is
10697 actually within the array. That's *not* necessarily the same as the
10698 zeroth element of the array. */
10700 rtl = targetm.delegitimize_address (rtl);
10702 switch (GET_CODE (rtl))
10707 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
10708 just fall into the SUBREG code. */
10710 /* ... fall through ... */
10713 /* The case of a subreg may arise when we have a local (register)
10714 variable or a formal (register) parameter which doesn't quite fill
10715 up an entire register. For now, just assume that it is
10716 legitimate to make the Dwarf info refer to the whole register which
10717 contains the given subreg. */
10718 rtl = XEXP (rtl, 0);
10720 /* ... fall through ... */
10723 /* Whenever a register number forms a part of the description of the
10724 method for calculating the (dynamic) address of a memory resident
10725 object, DWARF rules require the register number be referred to as
10726 a "base register". This distinction is not based in any way upon
10727 what category of register the hardware believes the given register
10728 belongs to. This is strictly DWARF terminology we're dealing with
10729 here. Note that in cases where the location of a memory-resident
10730 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10731 OP_CONST (0)) the actual DWARF location descriptor that we generate
10732 may just be OP_BASEREG (basereg). This may look deceptively like
10733 the object in question was allocated to a register (rather than in
10734 memory) so DWARF consumers need to be aware of the subtle
10735 distinction between OP_REG and OP_BASEREG. */
10736 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
10737 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
10738 else if (stack_realign_drap
10740 && crtl->args.internal_arg_pointer == rtl
10741 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
10743 /* If RTL is internal_arg_pointer, which has been optimized
10744 out, use DRAP instead. */
10745 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
10746 VAR_INIT_STATUS_INITIALIZED);
10751 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10752 VAR_INIT_STATUS_INITIALIZED);
10753 if (mem_loc_result == NULL)
10754 mem_loc_result = tls_mem_loc_descriptor (rtl);
10755 if (mem_loc_result != 0)
10756 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
10760 rtl = XEXP (rtl, 1);
10762 /* ... fall through ... */
10765 /* Some ports can transform a symbol ref into a label ref, because
10766 the symbol ref is too far away and has to be dumped into a constant
10770 /* Alternatively, the symbol in the constant pool might be referenced
10771 by a different symbol. */
10772 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
10775 rtx tmp = get_pool_constant_mark (rtl, &marked);
10777 if (GET_CODE (tmp) == SYMBOL_REF)
10780 if (CONSTANT_POOL_ADDRESS_P (tmp))
10781 get_pool_constant_mark (tmp, &marked);
10786 /* If all references to this pool constant were optimized away,
10787 it was not output and thus we can't represent it.
10788 FIXME: might try to use DW_OP_const_value here, though
10789 DW_OP_piece complicates it. */
10794 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
10795 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
10796 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10797 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10801 /* Extract the PLUS expression nested inside and fall into
10802 PLUS code below. */
10803 rtl = XEXP (rtl, 1);
10808 /* Turn these into a PLUS expression and fall into the PLUS code
10810 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10811 GEN_INT (GET_CODE (rtl) == PRE_INC
10812 ? GET_MODE_UNIT_SIZE (mode)
10813 : -GET_MODE_UNIT_SIZE (mode)));
10815 /* ... fall through ... */
10819 if (is_based_loc (rtl))
10820 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10821 INTVAL (XEXP (rtl, 1)),
10822 VAR_INIT_STATUS_INITIALIZED);
10825 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10826 VAR_INIT_STATUS_INITIALIZED);
10827 if (mem_loc_result == 0)
10830 if (CONST_INT_P (XEXP (rtl, 1)))
10831 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
10834 dw_loc_descr_ref mem_loc_result2
10835 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10836 VAR_INIT_STATUS_INITIALIZED);
10837 if (mem_loc_result2 == 0)
10839 add_loc_descr (&mem_loc_result, mem_loc_result2);
10840 add_loc_descr (&mem_loc_result,
10841 new_loc_descr (DW_OP_plus, 0, 0));
10846 /* If a pseudo-reg is optimized away, it is possible for it to
10847 be replaced with a MEM containing a multiply or shift. */
10866 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10867 VAR_INIT_STATUS_INITIALIZED);
10868 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10869 VAR_INIT_STATUS_INITIALIZED);
10871 if (op0 == 0 || op1 == 0)
10874 mem_loc_result = op0;
10875 add_loc_descr (&mem_loc_result, op1);
10876 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10881 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10885 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10886 VAR_INIT_STATUS_INITIALIZED);
10890 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10891 can't express it in the debug info. This can happen e.g. with some
10896 gcc_unreachable ();
10899 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10900 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10902 return mem_loc_result;
10905 /* Return a descriptor that describes the concatenation of two locations.
10906 This is typically a complex variable. */
10908 static dw_loc_descr_ref
10909 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10911 dw_loc_descr_ref cc_loc_result = NULL;
10912 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10913 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10915 if (x0_ref == 0 || x1_ref == 0)
10918 cc_loc_result = x0_ref;
10919 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10921 add_loc_descr (&cc_loc_result, x1_ref);
10922 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10924 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10925 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10927 return cc_loc_result;
10930 /* Return a descriptor that describes the concatenation of N
10933 static dw_loc_descr_ref
10934 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10937 dw_loc_descr_ref cc_loc_result = NULL;
10938 unsigned int n = XVECLEN (concatn, 0);
10940 for (i = 0; i < n; ++i)
10942 dw_loc_descr_ref ref;
10943 rtx x = XVECEXP (concatn, 0, i);
10945 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10949 add_loc_descr (&cc_loc_result, ref);
10950 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10953 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10954 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10956 return cc_loc_result;
10959 /* Output a proper Dwarf location descriptor for a variable or parameter
10960 which is either allocated in a register or in a memory location. For a
10961 register, we just generate an OP_REG and the register number. For a
10962 memory location we provide a Dwarf postfix expression describing how to
10963 generate the (dynamic) address of the object onto the address stack.
10965 If we don't know how to describe it, return 0. */
10967 static dw_loc_descr_ref
10968 loc_descriptor (rtx rtl, enum var_init_status initialized)
10970 dw_loc_descr_ref loc_result = NULL;
10972 switch (GET_CODE (rtl))
10975 /* The case of a subreg may arise when we have a local (register)
10976 variable or a formal (register) parameter which doesn't quite fill
10977 up an entire register. For now, just assume that it is
10978 legitimate to make the Dwarf info refer to the whole register which
10979 contains the given subreg. */
10980 rtl = SUBREG_REG (rtl);
10982 /* ... fall through ... */
10985 loc_result = reg_loc_descriptor (rtl, initialized);
10989 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10991 if (loc_result == NULL)
10992 loc_result = tls_mem_loc_descriptor (rtl);
10996 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
11001 loc_result = concatn_loc_descriptor (rtl, initialized);
11006 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
11008 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
11012 rtl = XEXP (rtl, 1);
11017 rtvec par_elems = XVEC (rtl, 0);
11018 int num_elem = GET_NUM_ELEM (par_elems);
11019 enum machine_mode mode;
11022 /* Create the first one, so we have something to add to. */
11023 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
11025 if (loc_result == NULL)
11027 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
11028 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11029 for (i = 1; i < num_elem; i++)
11031 dw_loc_descr_ref temp;
11033 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
11037 add_loc_descr (&loc_result, temp);
11038 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
11039 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11045 gcc_unreachable ();
11051 /* Similar, but generate the descriptor from trees instead of rtl. This comes
11052 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
11053 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
11054 top-level invocation, and we require the address of LOC; is 0 if we require
11055 the value of LOC. */
11057 static dw_loc_descr_ref
11058 loc_descriptor_from_tree_1 (tree loc, int want_address)
11060 dw_loc_descr_ref ret, ret1;
11061 int have_address = 0;
11062 enum dwarf_location_atom op;
11064 /* ??? Most of the time we do not take proper care for sign/zero
11065 extending the values properly. Hopefully this won't be a real
11068 switch (TREE_CODE (loc))
11073 case PLACEHOLDER_EXPR:
11074 /* This case involves extracting fields from an object to determine the
11075 position of other fields. We don't try to encode this here. The
11076 only user of this is Ada, which encodes the needed information using
11077 the names of types. */
11083 case PREINCREMENT_EXPR:
11084 case PREDECREMENT_EXPR:
11085 case POSTINCREMENT_EXPR:
11086 case POSTDECREMENT_EXPR:
11087 /* There are no opcodes for these operations. */
11091 /* If we already want an address, there's nothing we can do. */
11095 /* Otherwise, process the argument and look for the address. */
11096 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
11099 if (DECL_THREAD_LOCAL_P (loc))
11102 enum dwarf_location_atom first_op;
11103 enum dwarf_location_atom second_op;
11104 bool dtprel = false;
11106 if (targetm.have_tls)
11108 /* If this is not defined, we have no way to emit the
11110 if (!targetm.asm_out.output_dwarf_dtprel)
11113 /* The way DW_OP_GNU_push_tls_address is specified, we
11114 can only look up addresses of objects in the current
11116 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
11118 first_op = DW_OP_addr;
11120 second_op = DW_OP_GNU_push_tls_address;
11124 if (!targetm.emutls.debug_form_tls_address)
11126 loc = emutls_decl (loc);
11127 first_op = DW_OP_addr;
11128 second_op = DW_OP_form_tls_address;
11131 rtl = rtl_for_decl_location (loc);
11132 if (rtl == NULL_RTX)
11137 rtl = XEXP (rtl, 0);
11138 if (! CONSTANT_P (rtl))
11141 ret = new_loc_descr (first_op, 0, 0);
11142 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
11143 ret->dw_loc_oprnd1.v.val_addr = rtl;
11144 ret->dtprel = dtprel;
11146 ret1 = new_loc_descr (second_op, 0, 0);
11147 add_loc_descr (&ret, ret1);
11155 if (DECL_HAS_VALUE_EXPR_P (loc))
11156 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
11161 case FUNCTION_DECL:
11163 rtx rtl = rtl_for_decl_location (loc);
11165 if (rtl == NULL_RTX)
11167 else if (CONST_INT_P (rtl))
11169 HOST_WIDE_INT val = INTVAL (rtl);
11170 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
11171 val &= GET_MODE_MASK (DECL_MODE (loc));
11172 ret = int_loc_descriptor (val);
11174 else if (GET_CODE (rtl) == CONST_STRING)
11176 else if (CONSTANT_P (rtl))
11178 ret = new_loc_descr (DW_OP_addr, 0, 0);
11179 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
11180 ret->dw_loc_oprnd1.v.val_addr = rtl;
11184 enum machine_mode mode;
11186 /* Certain constructs can only be represented at top-level. */
11187 if (want_address == 2)
11188 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
11190 mode = GET_MODE (rtl);
11193 rtl = XEXP (rtl, 0);
11196 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
11202 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11206 case COMPOUND_EXPR:
11207 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
11210 case VIEW_CONVERT_EXPR:
11213 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
11215 case COMPONENT_REF:
11216 case BIT_FIELD_REF:
11218 case ARRAY_RANGE_REF:
11221 HOST_WIDE_INT bitsize, bitpos, bytepos;
11222 enum machine_mode mode;
11224 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
11226 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
11227 &unsignedp, &volatilep, false);
11232 ret = loc_descriptor_from_tree_1 (obj, 1);
11234 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
11237 if (offset != NULL_TREE)
11239 /* Variable offset. */
11240 ret1 = loc_descriptor_from_tree_1 (offset, 0);
11243 add_loc_descr (&ret, ret1);
11244 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
11247 bytepos = bitpos / BITS_PER_UNIT;
11248 loc_descr_plus_const (&ret, bytepos);
11255 if (host_integerp (loc, 0))
11256 ret = int_loc_descriptor (tree_low_cst (loc, 0));
11263 /* Get an RTL for this, if something has been emitted. */
11264 rtx rtl = lookup_constant_def (loc);
11265 enum machine_mode mode;
11267 if (!rtl || !MEM_P (rtl))
11269 mode = GET_MODE (rtl);
11270 rtl = XEXP (rtl, 0);
11271 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
11276 case TRUTH_AND_EXPR:
11277 case TRUTH_ANDIF_EXPR:
11282 case TRUTH_XOR_EXPR:
11287 case TRUTH_OR_EXPR:
11288 case TRUTH_ORIF_EXPR:
11293 case FLOOR_DIV_EXPR:
11294 case CEIL_DIV_EXPR:
11295 case ROUND_DIV_EXPR:
11296 case TRUNC_DIV_EXPR:
11304 case FLOOR_MOD_EXPR:
11305 case CEIL_MOD_EXPR:
11306 case ROUND_MOD_EXPR:
11307 case TRUNC_MOD_EXPR:
11320 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
11323 case POINTER_PLUS_EXPR:
11325 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
11326 && host_integerp (TREE_OPERAND (loc, 1), 0))
11328 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11332 loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
11340 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11347 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11354 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11361 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
11376 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11377 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
11378 if (ret == 0 || ret1 == 0)
11381 add_loc_descr (&ret, ret1);
11382 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11385 case TRUTH_NOT_EXPR:
11399 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11403 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
11409 const enum tree_code code =
11410 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
11412 loc = build3 (COND_EXPR, TREE_TYPE (loc),
11413 build2 (code, integer_type_node,
11414 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
11415 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
11418 /* ... fall through ... */
11422 dw_loc_descr_ref lhs
11423 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
11424 dw_loc_descr_ref rhs
11425 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
11426 dw_loc_descr_ref bra_node, jump_node, tmp;
11428 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
11429 if (ret == 0 || lhs == 0 || rhs == 0)
11432 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11433 add_loc_descr (&ret, bra_node);
11435 add_loc_descr (&ret, rhs);
11436 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
11437 add_loc_descr (&ret, jump_node);
11439 add_loc_descr (&ret, lhs);
11440 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11441 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
11443 /* ??? Need a node to point the skip at. Use a nop. */
11444 tmp = new_loc_descr (DW_OP_nop, 0, 0);
11445 add_loc_descr (&ret, tmp);
11446 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11447 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
11451 case FIX_TRUNC_EXPR:
11455 /* Leave front-end specific codes as simply unknown. This comes
11456 up, for instance, with the C STMT_EXPR. */
11457 if ((unsigned int) TREE_CODE (loc)
11458 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
11461 #ifdef ENABLE_CHECKING
11462 /* Otherwise this is a generic code; we should just lists all of
11463 these explicitly. We forgot one. */
11464 gcc_unreachable ();
11466 /* In a release build, we want to degrade gracefully: better to
11467 generate incomplete debugging information than to crash. */
11472 /* Show if we can't fill the request for an address. */
11473 if (want_address && !have_address)
11476 /* If we've got an address and don't want one, dereference. */
11477 if (!want_address && have_address && ret)
11479 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
11481 if (size > DWARF2_ADDR_SIZE || size == -1)
11483 else if (size == DWARF2_ADDR_SIZE)
11486 op = DW_OP_deref_size;
11488 add_loc_descr (&ret, new_loc_descr (op, size, 0));
11494 static inline dw_loc_descr_ref
11495 loc_descriptor_from_tree (tree loc)
11497 return loc_descriptor_from_tree_1 (loc, 2);
11500 /* Given a value, round it up to the lowest multiple of `boundary'
11501 which is not less than the value itself. */
11503 static inline HOST_WIDE_INT
11504 ceiling (HOST_WIDE_INT value, unsigned int boundary)
11506 return (((value + boundary - 1) / boundary) * boundary);
11509 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
11510 pointer to the declared type for the relevant field variable, or return
11511 `integer_type_node' if the given node turns out to be an
11512 ERROR_MARK node. */
11515 field_type (const_tree decl)
11519 if (TREE_CODE (decl) == ERROR_MARK)
11520 return integer_type_node;
11522 type = DECL_BIT_FIELD_TYPE (decl);
11523 if (type == NULL_TREE)
11524 type = TREE_TYPE (decl);
11529 /* Given a pointer to a tree node, return the alignment in bits for
11530 it, or else return BITS_PER_WORD if the node actually turns out to
11531 be an ERROR_MARK node. */
11533 static inline unsigned
11534 simple_type_align_in_bits (const_tree type)
11536 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
11539 static inline unsigned
11540 simple_decl_align_in_bits (const_tree decl)
11542 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
11545 /* Return the result of rounding T up to ALIGN. */
11547 static inline HOST_WIDE_INT
11548 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
11550 /* We must be careful if T is negative because HOST_WIDE_INT can be
11551 either "above" or "below" unsigned int as per the C promotion
11552 rules, depending on the host, thus making the signedness of the
11553 direct multiplication and division unpredictable. */
11554 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
11560 return (HOST_WIDE_INT) u;
11563 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
11564 lowest addressed byte of the "containing object" for the given FIELD_DECL,
11565 or return 0 if we are unable to determine what that offset is, either
11566 because the argument turns out to be a pointer to an ERROR_MARK node, or
11567 because the offset is actually variable. (We can't handle the latter case
11570 static HOST_WIDE_INT
11571 field_byte_offset (const_tree decl)
11573 HOST_WIDE_INT object_offset_in_bits;
11574 HOST_WIDE_INT bitpos_int;
11576 if (TREE_CODE (decl) == ERROR_MARK)
11579 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
11581 /* We cannot yet cope with fields whose positions are variable, so
11582 for now, when we see such things, we simply return 0. Someday, we may
11583 be able to handle such cases, but it will be damn difficult. */
11584 if (! host_integerp (bit_position (decl), 0))
11587 bitpos_int = int_bit_position (decl);
11589 #ifdef PCC_BITFIELD_TYPE_MATTERS
11590 if (PCC_BITFIELD_TYPE_MATTERS)
11593 tree field_size_tree;
11594 HOST_WIDE_INT deepest_bitpos;
11595 unsigned HOST_WIDE_INT field_size_in_bits;
11596 unsigned int type_align_in_bits;
11597 unsigned int decl_align_in_bits;
11598 unsigned HOST_WIDE_INT type_size_in_bits;
11600 type = field_type (decl);
11601 type_size_in_bits = simple_type_size_in_bits (type);
11602 type_align_in_bits = simple_type_align_in_bits (type);
11604 field_size_tree = DECL_SIZE (decl);
11606 /* The size could be unspecified if there was an error, or for
11607 a flexible array member. */
11608 if (!field_size_tree)
11609 field_size_tree = bitsize_zero_node;
11611 /* If the size of the field is not constant, use the type size. */
11612 if (host_integerp (field_size_tree, 1))
11613 field_size_in_bits = tree_low_cst (field_size_tree, 1);
11615 field_size_in_bits = type_size_in_bits;
11617 decl_align_in_bits = simple_decl_align_in_bits (decl);
11619 /* The GCC front-end doesn't make any attempt to keep track of the
11620 starting bit offset (relative to the start of the containing
11621 structure type) of the hypothetical "containing object" for a
11622 bit-field. Thus, when computing the byte offset value for the
11623 start of the "containing object" of a bit-field, we must deduce
11624 this information on our own. This can be rather tricky to do in
11625 some cases. For example, handling the following structure type
11626 definition when compiling for an i386/i486 target (which only
11627 aligns long long's to 32-bit boundaries) can be very tricky:
11629 struct S { int field1; long long field2:31; };
11631 Fortunately, there is a simple rule-of-thumb which can be used
11632 in such cases. When compiling for an i386/i486, GCC will
11633 allocate 8 bytes for the structure shown above. It decides to
11634 do this based upon one simple rule for bit-field allocation.
11635 GCC allocates each "containing object" for each bit-field at
11636 the first (i.e. lowest addressed) legitimate alignment boundary
11637 (based upon the required minimum alignment for the declared
11638 type of the field) which it can possibly use, subject to the
11639 condition that there is still enough available space remaining
11640 in the containing object (when allocated at the selected point)
11641 to fully accommodate all of the bits of the bit-field itself.
11643 This simple rule makes it obvious why GCC allocates 8 bytes for
11644 each object of the structure type shown above. When looking
11645 for a place to allocate the "containing object" for `field2',
11646 the compiler simply tries to allocate a 64-bit "containing
11647 object" at each successive 32-bit boundary (starting at zero)
11648 until it finds a place to allocate that 64- bit field such that
11649 at least 31 contiguous (and previously unallocated) bits remain
11650 within that selected 64 bit field. (As it turns out, for the
11651 example above, the compiler finds it is OK to allocate the
11652 "containing object" 64-bit field at bit-offset zero within the
11655 Here we attempt to work backwards from the limited set of facts
11656 we're given, and we try to deduce from those facts, where GCC
11657 must have believed that the containing object started (within
11658 the structure type). The value we deduce is then used (by the
11659 callers of this routine) to generate DW_AT_location and
11660 DW_AT_bit_offset attributes for fields (both bit-fields and, in
11661 the case of DW_AT_location, regular fields as well). */
11663 /* Figure out the bit-distance from the start of the structure to
11664 the "deepest" bit of the bit-field. */
11665 deepest_bitpos = bitpos_int + field_size_in_bits;
11667 /* This is the tricky part. Use some fancy footwork to deduce
11668 where the lowest addressed bit of the containing object must
11670 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11672 /* Round up to type_align by default. This works best for
11674 object_offset_in_bits
11675 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
11677 if (object_offset_in_bits > bitpos_int)
11679 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11681 /* Round up to decl_align instead. */
11682 object_offset_in_bits
11683 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
11688 object_offset_in_bits = bitpos_int;
11690 return object_offset_in_bits / BITS_PER_UNIT;
11693 /* The following routines define various Dwarf attributes and any data
11694 associated with them. */
11696 /* Add a location description attribute value to a DIE.
11698 This emits location attributes suitable for whole variables and
11699 whole parameters. Note that the location attributes for struct fields are
11700 generated by the routine `data_member_location_attribute' below. */
11703 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
11704 dw_loc_descr_ref descr)
11707 add_AT_loc (die, attr_kind, descr);
11710 /* Attach the specialized form of location attribute used for data members of
11711 struct and union types. In the special case of a FIELD_DECL node which
11712 represents a bit-field, the "offset" part of this special location
11713 descriptor must indicate the distance in bytes from the lowest-addressed
11714 byte of the containing struct or union type to the lowest-addressed byte of
11715 the "containing object" for the bit-field. (See the `field_byte_offset'
11718 For any given bit-field, the "containing object" is a hypothetical object
11719 (of some integral or enum type) within which the given bit-field lives. The
11720 type of this hypothetical "containing object" is always the same as the
11721 declared type of the individual bit-field itself (for GCC anyway... the
11722 DWARF spec doesn't actually mandate this). Note that it is the size (in
11723 bytes) of the hypothetical "containing object" which will be given in the
11724 DW_AT_byte_size attribute for this bit-field. (See the
11725 `byte_size_attribute' function below.) It is also used when calculating the
11726 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11727 function below.) */
11730 add_data_member_location_attribute (dw_die_ref die, tree decl)
11732 HOST_WIDE_INT offset;
11733 dw_loc_descr_ref loc_descr = 0;
11735 if (TREE_CODE (decl) == TREE_BINFO)
11737 /* We're working on the TAG_inheritance for a base class. */
11738 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
11740 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11741 aren't at a fixed offset from all (sub)objects of the same
11742 type. We need to extract the appropriate offset from our
11743 vtable. The following dwarf expression means
11745 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11747 This is specific to the V3 ABI, of course. */
11749 dw_loc_descr_ref tmp;
11751 /* Make a copy of the object address. */
11752 tmp = new_loc_descr (DW_OP_dup, 0, 0);
11753 add_loc_descr (&loc_descr, tmp);
11755 /* Extract the vtable address. */
11756 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11757 add_loc_descr (&loc_descr, tmp);
11759 /* Calculate the address of the offset. */
11760 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
11761 gcc_assert (offset < 0);
11763 tmp = int_loc_descriptor (-offset);
11764 add_loc_descr (&loc_descr, tmp);
11765 tmp = new_loc_descr (DW_OP_minus, 0, 0);
11766 add_loc_descr (&loc_descr, tmp);
11768 /* Extract the offset. */
11769 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11770 add_loc_descr (&loc_descr, tmp);
11772 /* Add it to the object address. */
11773 tmp = new_loc_descr (DW_OP_plus, 0, 0);
11774 add_loc_descr (&loc_descr, tmp);
11777 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
11780 offset = field_byte_offset (decl);
11784 if (dwarf_version > 2)
11786 /* Don't need to output a location expression, just the constant. */
11787 add_AT_int (die, DW_AT_data_member_location, offset);
11792 enum dwarf_location_atom op;
11794 /* The DWARF2 standard says that we should assume that the structure
11795 address is already on the stack, so we can specify a structure
11796 field address by using DW_OP_plus_uconst. */
11798 #ifdef MIPS_DEBUGGING_INFO
11799 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11800 operator correctly. It works only if we leave the offset on the
11804 op = DW_OP_plus_uconst;
11807 loc_descr = new_loc_descr (op, offset, 0);
11811 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
11814 /* Writes integer values to dw_vec_const array. */
11817 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11821 *dest++ = val & 0xff;
11827 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11829 static HOST_WIDE_INT
11830 extract_int (const unsigned char *src, unsigned int size)
11832 HOST_WIDE_INT val = 0;
11838 val |= *--src & 0xff;
11844 /* Writes floating point values to dw_vec_const array. */
11847 insert_float (const_rtx rtl, unsigned char *array)
11849 REAL_VALUE_TYPE rv;
11853 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11854 real_to_target (val, &rv, GET_MODE (rtl));
11856 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11857 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11859 insert_int (val[i], 4, array);
11864 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11865 does not have a "location" either in memory or in a register. These
11866 things can arise in GNU C when a constant is passed as an actual parameter
11867 to an inlined function. They can also arise in C++ where declared
11868 constants do not necessarily get memory "homes". */
11871 add_const_value_attribute (dw_die_ref die, rtx rtl)
11873 switch (GET_CODE (rtl))
11877 HOST_WIDE_INT val = INTVAL (rtl);
11880 add_AT_int (die, DW_AT_const_value, val);
11882 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11887 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11888 floating-point constant. A CONST_DOUBLE is used whenever the
11889 constant requires more than one word in order to be adequately
11890 represented. We output CONST_DOUBLEs as blocks. */
11892 enum machine_mode mode = GET_MODE (rtl);
11894 if (SCALAR_FLOAT_MODE_P (mode))
11896 unsigned int length = GET_MODE_SIZE (mode);
11897 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11899 insert_float (rtl, array);
11900 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11904 /* ??? We really should be using HOST_WIDE_INT throughout. */
11905 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11907 add_AT_long_long (die, DW_AT_const_value,
11908 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11915 enum machine_mode mode = GET_MODE (rtl);
11916 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11917 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11918 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11922 switch (GET_MODE_CLASS (mode))
11924 case MODE_VECTOR_INT:
11925 for (i = 0, p = array; i < length; i++, p += elt_size)
11927 rtx elt = CONST_VECTOR_ELT (rtl, i);
11928 HOST_WIDE_INT lo, hi;
11930 switch (GET_CODE (elt))
11938 lo = CONST_DOUBLE_LOW (elt);
11939 hi = CONST_DOUBLE_HIGH (elt);
11943 gcc_unreachable ();
11946 if (elt_size <= sizeof (HOST_WIDE_INT))
11947 insert_int (lo, elt_size, p);
11950 unsigned char *p0 = p;
11951 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11953 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11954 if (WORDS_BIG_ENDIAN)
11959 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11960 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11965 case MODE_VECTOR_FLOAT:
11966 for (i = 0, p = array; i < length; i++, p += elt_size)
11968 rtx elt = CONST_VECTOR_ELT (rtl, i);
11969 insert_float (elt, p);
11974 gcc_unreachable ();
11977 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11982 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11988 add_AT_addr (die, DW_AT_const_value, rtl);
11989 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11993 /* In cases where an inlined instance of an inline function is passed
11994 the address of an `auto' variable (which is local to the caller) we
11995 can get a situation where the DECL_RTL of the artificial local
11996 variable (for the inlining) which acts as a stand-in for the
11997 corresponding formal parameter (of the inline function) will look
11998 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11999 exactly a compile-time constant expression, but it isn't the address
12000 of the (artificial) local variable either. Rather, it represents the
12001 *value* which the artificial local variable always has during its
12002 lifetime. We currently have no way to represent such quasi-constant
12003 values in Dwarf, so for now we just punt and generate nothing. */
12007 /* No other kinds of rtx should be possible here. */
12008 gcc_unreachable ();
12013 /* Determine whether the evaluation of EXPR references any variables
12014 or functions which aren't otherwise used (and therefore may not be
12017 reference_to_unused (tree * tp, int * walk_subtrees,
12018 void * data ATTRIBUTE_UNUSED)
12020 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
12021 *walk_subtrees = 0;
12023 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
12024 && ! TREE_ASM_WRITTEN (*tp))
12026 /* ??? The C++ FE emits debug information for using decls, so
12027 putting gcc_unreachable here falls over. See PR31899. For now
12028 be conservative. */
12029 else if (!cgraph_global_info_ready
12030 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
12032 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
12034 struct varpool_node *node = varpool_node (*tp);
12038 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
12039 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
12041 struct cgraph_node *node = cgraph_node (*tp);
12042 if (node->process || TREE_ASM_WRITTEN (*tp))
12045 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
12051 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
12052 for use in a later add_const_value_attribute call. */
12055 rtl_for_decl_init (tree init, tree type)
12057 rtx rtl = NULL_RTX;
12059 /* If a variable is initialized with a string constant without embedded
12060 zeros, build CONST_STRING. */
12061 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
12063 tree enttype = TREE_TYPE (type);
12064 tree domain = TYPE_DOMAIN (type);
12065 enum machine_mode mode = TYPE_MODE (enttype);
12067 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
12069 && integer_zerop (TYPE_MIN_VALUE (domain))
12070 && compare_tree_int (TYPE_MAX_VALUE (domain),
12071 TREE_STRING_LENGTH (init) - 1) == 0
12072 && ((size_t) TREE_STRING_LENGTH (init)
12073 == strlen (TREE_STRING_POINTER (init)) + 1))
12074 rtl = gen_rtx_CONST_STRING (VOIDmode,
12075 ggc_strdup (TREE_STRING_POINTER (init)));
12077 /* Other aggregates, and complex values, could be represented using
12079 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
12081 /* Vectors only work if their mode is supported by the target.
12082 FIXME: generic vectors ought to work too. */
12083 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
12085 /* If the initializer is something that we know will expand into an
12086 immediate RTL constant, expand it now. We must be careful not to
12087 reference variables which won't be output. */
12088 else if (initializer_constant_valid_p (init, type)
12089 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
12091 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
12093 if (TREE_CODE (type) == VECTOR_TYPE)
12094 switch (TREE_CODE (init))
12099 if (TREE_CONSTANT (init))
12101 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
12102 bool constant_p = true;
12104 unsigned HOST_WIDE_INT ix;
12106 /* Even when ctor is constant, it might contain non-*_CST
12107 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
12108 belong into VECTOR_CST nodes. */
12109 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
12110 if (!CONSTANT_CLASS_P (value))
12112 constant_p = false;
12118 init = build_vector_from_ctor (type, elts);
12128 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
12130 /* If expand_expr returns a MEM, it wasn't immediate. */
12131 gcc_assert (!rtl || !MEM_P (rtl));
12137 /* Generate RTL for the variable DECL to represent its location. */
12140 rtl_for_decl_location (tree decl)
12144 /* Here we have to decide where we are going to say the parameter "lives"
12145 (as far as the debugger is concerned). We only have a couple of
12146 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
12148 DECL_RTL normally indicates where the parameter lives during most of the
12149 activation of the function. If optimization is enabled however, this
12150 could be either NULL or else a pseudo-reg. Both of those cases indicate
12151 that the parameter doesn't really live anywhere (as far as the code
12152 generation parts of GCC are concerned) during most of the function's
12153 activation. That will happen (for example) if the parameter is never
12154 referenced within the function.
12156 We could just generate a location descriptor here for all non-NULL
12157 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
12158 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
12159 where DECL_RTL is NULL or is a pseudo-reg.
12161 Note however that we can only get away with using DECL_INCOMING_RTL as
12162 a backup substitute for DECL_RTL in certain limited cases. In cases
12163 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
12164 we can be sure that the parameter was passed using the same type as it is
12165 declared to have within the function, and that its DECL_INCOMING_RTL
12166 points us to a place where a value of that type is passed.
12168 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
12169 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
12170 because in these cases DECL_INCOMING_RTL points us to a value of some
12171 type which is *different* from the type of the parameter itself. Thus,
12172 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
12173 such cases, the debugger would end up (for example) trying to fetch a
12174 `float' from a place which actually contains the first part of a
12175 `double'. That would lead to really incorrect and confusing
12176 output at debug-time.
12178 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
12179 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
12180 are a couple of exceptions however. On little-endian machines we can
12181 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
12182 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
12183 an integral type that is smaller than TREE_TYPE (decl). These cases arise
12184 when (on a little-endian machine) a non-prototyped function has a
12185 parameter declared to be of type `short' or `char'. In such cases,
12186 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
12187 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
12188 passed `int' value. If the debugger then uses that address to fetch
12189 a `short' or a `char' (on a little-endian machine) the result will be
12190 the correct data, so we allow for such exceptional cases below.
12192 Note that our goal here is to describe the place where the given formal
12193 parameter lives during most of the function's activation (i.e. between the
12194 end of the prologue and the start of the epilogue). We'll do that as best
12195 as we can. Note however that if the given formal parameter is modified
12196 sometime during the execution of the function, then a stack backtrace (at
12197 debug-time) will show the function as having been called with the *new*
12198 value rather than the value which was originally passed in. This happens
12199 rarely enough that it is not a major problem, but it *is* a problem, and
12200 I'd like to fix it.
12202 A future version of dwarf2out.c may generate two additional attributes for
12203 any given DW_TAG_formal_parameter DIE which will describe the "passed
12204 type" and the "passed location" for the given formal parameter in addition
12205 to the attributes we now generate to indicate the "declared type" and the
12206 "active location" for each parameter. This additional set of attributes
12207 could be used by debuggers for stack backtraces. Separately, note that
12208 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
12209 This happens (for example) for inlined-instances of inline function formal
12210 parameters which are never referenced. This really shouldn't be
12211 happening. All PARM_DECL nodes should get valid non-NULL
12212 DECL_INCOMING_RTL values. FIXME. */
12214 /* Use DECL_RTL as the "location" unless we find something better. */
12215 rtl = DECL_RTL_IF_SET (decl);
12217 /* When generating abstract instances, ignore everything except
12218 constants, symbols living in memory, and symbols living in
12219 fixed registers. */
12220 if (! reload_completed)
12223 && (CONSTANT_P (rtl)
12225 && CONSTANT_P (XEXP (rtl, 0)))
12227 && TREE_CODE (decl) == VAR_DECL
12228 && TREE_STATIC (decl))))
12230 rtl = targetm.delegitimize_address (rtl);
12235 else if (TREE_CODE (decl) == PARM_DECL)
12237 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
12239 tree declared_type = TREE_TYPE (decl);
12240 tree passed_type = DECL_ARG_TYPE (decl);
12241 enum machine_mode dmode = TYPE_MODE (declared_type);
12242 enum machine_mode pmode = TYPE_MODE (passed_type);
12244 /* This decl represents a formal parameter which was optimized out.
12245 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
12246 all cases where (rtl == NULL_RTX) just below. */
12247 if (dmode == pmode)
12248 rtl = DECL_INCOMING_RTL (decl);
12249 else if (SCALAR_INT_MODE_P (dmode)
12250 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
12251 && DECL_INCOMING_RTL (decl))
12253 rtx inc = DECL_INCOMING_RTL (decl);
12256 else if (MEM_P (inc))
12258 if (BYTES_BIG_ENDIAN)
12259 rtl = adjust_address_nv (inc, dmode,
12260 GET_MODE_SIZE (pmode)
12261 - GET_MODE_SIZE (dmode));
12268 /* If the parm was passed in registers, but lives on the stack, then
12269 make a big endian correction if the mode of the type of the
12270 parameter is not the same as the mode of the rtl. */
12271 /* ??? This is the same series of checks that are made in dbxout.c before
12272 we reach the big endian correction code there. It isn't clear if all
12273 of these checks are necessary here, but keeping them all is the safe
12275 else if (MEM_P (rtl)
12276 && XEXP (rtl, 0) != const0_rtx
12277 && ! CONSTANT_P (XEXP (rtl, 0))
12278 /* Not passed in memory. */
12279 && !MEM_P (DECL_INCOMING_RTL (decl))
12280 /* Not passed by invisible reference. */
12281 && (!REG_P (XEXP (rtl, 0))
12282 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
12283 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
12284 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
12285 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
12288 /* Big endian correction check. */
12289 && BYTES_BIG_ENDIAN
12290 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
12291 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
12294 int offset = (UNITS_PER_WORD
12295 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
12297 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
12298 plus_constant (XEXP (rtl, 0), offset));
12301 else if (TREE_CODE (decl) == VAR_DECL
12304 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
12305 && BYTES_BIG_ENDIAN)
12307 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
12308 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
12310 /* If a variable is declared "register" yet is smaller than
12311 a register, then if we store the variable to memory, it
12312 looks like we're storing a register-sized value, when in
12313 fact we are not. We need to adjust the offset of the
12314 storage location to reflect the actual value's bytes,
12315 else gdb will not be able to display it. */
12317 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
12318 plus_constant (XEXP (rtl, 0), rsize-dsize));
12321 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
12322 and will have been substituted directly into all expressions that use it.
12323 C does not have such a concept, but C++ and other languages do. */
12324 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
12325 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
12328 rtl = targetm.delegitimize_address (rtl);
12330 /* If we don't look past the constant pool, we risk emitting a
12331 reference to a constant pool entry that isn't referenced from
12332 code, and thus is not emitted. */
12334 rtl = avoid_constant_pool_reference (rtl);
12339 /* We need to figure out what section we should use as the base for the
12340 address ranges where a given location is valid.
12341 1. If this particular DECL has a section associated with it, use that.
12342 2. If this function has a section associated with it, use that.
12343 3. Otherwise, use the text section.
12344 XXX: If you split a variable across multiple sections, we won't notice. */
12346 static const char *
12347 secname_for_decl (const_tree decl)
12349 const char *secname;
12351 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
12353 tree sectree = DECL_SECTION_NAME (decl);
12354 secname = TREE_STRING_POINTER (sectree);
12356 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
12358 tree sectree = DECL_SECTION_NAME (current_function_decl);
12359 secname = TREE_STRING_POINTER (sectree);
12361 else if (cfun && in_cold_section_p)
12362 secname = crtl->subsections.cold_section_label;
12364 secname = text_section_label;
12369 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
12370 returned. If so, the decl for the COMMON block is returned, and the
12371 value is the offset into the common block for the symbol. */
12374 fortran_common (tree decl, HOST_WIDE_INT *value)
12376 tree val_expr, cvar;
12377 enum machine_mode mode;
12378 HOST_WIDE_INT bitsize, bitpos;
12380 int volatilep = 0, unsignedp = 0;
12382 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
12383 it does not have a value (the offset into the common area), or if it
12384 is thread local (as opposed to global) then it isn't common, and shouldn't
12385 be handled as such. */
12386 if (TREE_CODE (decl) != VAR_DECL
12387 || !TREE_PUBLIC (decl)
12388 || !TREE_STATIC (decl)
12389 || !DECL_HAS_VALUE_EXPR_P (decl)
12393 val_expr = DECL_VALUE_EXPR (decl);
12394 if (TREE_CODE (val_expr) != COMPONENT_REF)
12397 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
12398 &mode, &unsignedp, &volatilep, true);
12400 if (cvar == NULL_TREE
12401 || TREE_CODE (cvar) != VAR_DECL
12402 || DECL_ARTIFICIAL (cvar)
12403 || !TREE_PUBLIC (cvar))
12407 if (offset != NULL)
12409 if (!host_integerp (offset, 0))
12411 *value = tree_low_cst (offset, 0);
12414 *value += bitpos / BITS_PER_UNIT;
12419 /* Dereference a location expression LOC if DECL is passed by invisible
12422 static dw_loc_descr_ref
12423 loc_by_reference (dw_loc_descr_ref loc, tree decl)
12425 HOST_WIDE_INT size;
12426 enum dwarf_location_atom op;
12431 if ((TREE_CODE (decl) != PARM_DECL
12432 && TREE_CODE (decl) != RESULT_DECL
12433 && TREE_CODE (decl) != VAR_DECL)
12434 || !DECL_BY_REFERENCE (decl))
12437 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
12438 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
12439 location expression is considered to be address of a memory location,
12440 rather than the register itself. */
12441 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
12442 || loc->dw_loc_opc == DW_OP_regx)
12443 && (loc->dw_loc_next == NULL
12444 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
12445 && loc->dw_loc_next->dw_loc_next == NULL)))
12447 if (loc->dw_loc_opc == DW_OP_regx)
12449 loc->dw_loc_opc = DW_OP_bregx;
12450 loc->dw_loc_oprnd2.v.val_int = 0;
12455 = (enum dwarf_location_atom)
12456 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
12457 loc->dw_loc_oprnd1.v.val_int = 0;
12462 size = int_size_in_bytes (TREE_TYPE (decl));
12463 if (size > DWARF2_ADDR_SIZE || size == -1)
12465 else if (size == DWARF2_ADDR_SIZE)
12468 op = DW_OP_deref_size;
12469 add_loc_descr (&loc, new_loc_descr (op, size, 0));
12473 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
12474 data attribute for a variable or a parameter. We generate the
12475 DW_AT_const_value attribute only in those cases where the given variable
12476 or parameter does not have a true "location" either in memory or in a
12477 register. This can happen (for example) when a constant is passed as an
12478 actual argument in a call to an inline function. (It's possible that
12479 these things can crop up in other ways also.) Note that one type of
12480 constant value which can be passed into an inlined function is a constant
12481 pointer. This can happen for example if an actual argument in an inlined
12482 function call evaluates to a compile-time constant address. */
12485 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
12486 enum dwarf_attribute attr)
12489 dw_loc_descr_ref descr;
12490 var_loc_list *loc_list;
12491 struct var_loc_node *node;
12492 if (TREE_CODE (decl) == ERROR_MARK)
12495 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
12496 || TREE_CODE (decl) == RESULT_DECL);
12498 /* See if we possibly have multiple locations for this variable. */
12499 loc_list = lookup_decl_loc (decl);
12501 /* If it truly has multiple locations, the first and last node will
12503 if (loc_list && loc_list->first != loc_list->last)
12505 const char *endname, *secname;
12506 dw_loc_list_ref list;
12508 enum var_init_status initialized;
12510 /* Now that we know what section we are using for a base,
12511 actually construct the list of locations.
12512 The first location information is what is passed to the
12513 function that creates the location list, and the remaining
12514 locations just get added on to that list.
12515 Note that we only know the start address for a location
12516 (IE location changes), so to build the range, we use
12517 the range [current location start, next location start].
12518 This means we have to special case the last node, and generate
12519 a range of [last location start, end of function label]. */
12521 node = loc_list->first;
12522 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12523 secname = secname_for_decl (decl);
12525 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
12526 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12528 initialized = VAR_INIT_STATUS_INITIALIZED;
12530 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
12531 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
12534 for (; node->next; node = node->next)
12535 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12537 /* The variable has a location between NODE->LABEL and
12538 NODE->NEXT->LABEL. */
12539 enum var_init_status initialized =
12540 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12541 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12542 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12544 add_loc_descr_to_loc_list (&list, descr,
12545 node->label, node->next->label, secname);
12548 /* If the variable has a location at the last label
12549 it keeps its location until the end of function. */
12550 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12552 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12553 enum var_init_status initialized =
12554 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12556 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12557 if (!current_function_decl)
12558 endname = text_end_label;
12561 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12562 current_function_funcdef_no);
12563 endname = ggc_strdup (label_id);
12565 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12567 add_loc_descr_to_loc_list (&list, descr,
12568 node->label, endname, secname);
12571 /* Finally, add the location list to the DIE, and we are done. */
12572 add_AT_loc_list (die, attr, list);
12576 /* Try to get some constant RTL for this decl, and use that as the value of
12579 rtl = rtl_for_decl_location (decl);
12580 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
12582 add_const_value_attribute (die, rtl);
12586 /* If we have tried to generate the location otherwise, and it
12587 didn't work out (we wouldn't be here if we did), and we have a one entry
12588 location list, try generating a location from that. */
12589 if (loc_list && loc_list->first)
12591 enum var_init_status status;
12592 node = loc_list->first;
12593 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12594 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
12597 descr = loc_by_reference (descr, decl);
12598 add_AT_location_description (die, attr, descr);
12603 /* We couldn't get any rtl, so try directly generating the location
12604 description from the tree. */
12605 descr = loc_descriptor_from_tree (decl);
12608 descr = loc_by_reference (descr, decl);
12609 add_AT_location_description (die, attr, descr);
12612 /* None of that worked, so it must not really have a location;
12613 try adding a constant value attribute from the DECL_INITIAL. */
12614 tree_add_const_value_attribute (die, decl);
12617 /* Add VARIABLE and DIE into deferred locations list. */
12620 defer_location (tree variable, dw_die_ref die)
12622 deferred_locations entry;
12623 entry.variable = variable;
12625 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
12628 /* Helper function for tree_add_const_value_attribute. Natively encode
12629 initializer INIT into an array. Return true if successful. */
12632 native_encode_initializer (tree init, unsigned char *array, int size)
12636 if (init == NULL_TREE)
12640 switch (TREE_CODE (init))
12643 type = TREE_TYPE (init);
12644 if (TREE_CODE (type) == ARRAY_TYPE)
12646 tree enttype = TREE_TYPE (type);
12647 enum machine_mode mode = TYPE_MODE (enttype);
12649 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
12651 if (int_size_in_bytes (type) != size)
12653 if (size > TREE_STRING_LENGTH (init))
12655 memcpy (array, TREE_STRING_POINTER (init),
12656 TREE_STRING_LENGTH (init));
12657 memset (array + TREE_STRING_LENGTH (init),
12658 '\0', size - TREE_STRING_LENGTH (init));
12661 memcpy (array, TREE_STRING_POINTER (init), size);
12666 type = TREE_TYPE (init);
12667 if (int_size_in_bytes (type) != size)
12669 if (TREE_CODE (type) == ARRAY_TYPE)
12671 HOST_WIDE_INT min_index;
12672 unsigned HOST_WIDE_INT cnt;
12673 int curpos = 0, fieldsize;
12674 constructor_elt *ce;
12676 if (TYPE_DOMAIN (type) == NULL_TREE
12677 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
12680 fieldsize = int_size_in_bytes (TREE_TYPE (type));
12681 if (fieldsize <= 0)
12684 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
12685 memset (array, '\0', size);
12687 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12690 tree val = ce->value;
12691 tree index = ce->index;
12693 if (index && TREE_CODE (index) == RANGE_EXPR)
12694 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
12697 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
12702 if (!native_encode_initializer (val, array + pos, fieldsize))
12705 curpos = pos + fieldsize;
12706 if (index && TREE_CODE (index) == RANGE_EXPR)
12708 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
12709 - tree_low_cst (TREE_OPERAND (index, 0), 0);
12713 memcpy (array + curpos, array + pos, fieldsize);
12714 curpos += fieldsize;
12717 gcc_assert (curpos <= size);
12721 else if (TREE_CODE (type) == RECORD_TYPE
12722 || TREE_CODE (type) == UNION_TYPE)
12724 tree field = NULL_TREE;
12725 unsigned HOST_WIDE_INT cnt;
12726 constructor_elt *ce;
12728 if (int_size_in_bytes (type) != size)
12731 if (TREE_CODE (type) == RECORD_TYPE)
12732 field = TYPE_FIELDS (type);
12735 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12736 cnt++, field = field ? TREE_CHAIN (field) : 0)
12738 tree val = ce->value;
12739 int pos, fieldsize;
12741 if (ce->index != 0)
12747 if (field == NULL_TREE || DECL_BIT_FIELD (field))
12750 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
12751 && TYPE_DOMAIN (TREE_TYPE (field))
12752 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
12754 else if (DECL_SIZE_UNIT (field) == NULL_TREE
12755 || !host_integerp (DECL_SIZE_UNIT (field), 0))
12757 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
12758 pos = int_byte_position (field);
12759 gcc_assert (pos + fieldsize <= size);
12761 && !native_encode_initializer (val, array + pos, fieldsize))
12767 case VIEW_CONVERT_EXPR:
12768 case NON_LVALUE_EXPR:
12769 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
12771 return native_encode_expr (init, array, size) == size;
12775 /* If we don't have a copy of this variable in memory for some reason (such
12776 as a C++ member constant that doesn't have an out-of-line definition),
12777 we should tell the debugger about the constant value. */
12780 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
12783 tree type = TREE_TYPE (decl);
12786 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
12789 init = DECL_INITIAL (decl);
12790 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
12795 rtl = rtl_for_decl_init (init, type);
12797 add_const_value_attribute (var_die, rtl);
12798 /* If the host and target are sane, try harder. */
12799 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
12800 && initializer_constant_valid_p (init, type))
12802 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
12803 if (size > 0 && (int) size == size)
12805 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
12807 if (native_encode_initializer (init, array, size))
12808 add_AT_vec (var_die, DW_AT_const_value, size, 1, array);
12813 /* Convert the CFI instructions for the current function into a
12814 location list. This is used for DW_AT_frame_base when we targeting
12815 a dwarf2 consumer that does not support the dwarf3
12816 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12819 static dw_loc_list_ref
12820 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
12823 dw_loc_list_ref list, *list_tail;
12825 dw_cfa_location last_cfa, next_cfa;
12826 const char *start_label, *last_label, *section;
12827 dw_cfa_location remember;
12829 fde = current_fde ();
12830 gcc_assert (fde != NULL);
12832 section = secname_for_decl (current_function_decl);
12836 memset (&next_cfa, 0, sizeof (next_cfa));
12837 next_cfa.reg = INVALID_REGNUM;
12838 remember = next_cfa;
12840 start_label = fde->dw_fde_begin;
12842 /* ??? Bald assumption that the CIE opcode list does not contain
12843 advance opcodes. */
12844 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
12845 lookup_cfa_1 (cfi, &next_cfa, &remember);
12847 last_cfa = next_cfa;
12848 last_label = start_label;
12850 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
12851 switch (cfi->dw_cfi_opc)
12853 case DW_CFA_set_loc:
12854 case DW_CFA_advance_loc1:
12855 case DW_CFA_advance_loc2:
12856 case DW_CFA_advance_loc4:
12857 if (!cfa_equal_p (&last_cfa, &next_cfa))
12859 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12860 start_label, last_label, section,
12863 list_tail = &(*list_tail)->dw_loc_next;
12864 last_cfa = next_cfa;
12865 start_label = last_label;
12867 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
12870 case DW_CFA_advance_loc:
12871 /* The encoding is complex enough that we should never emit this. */
12872 gcc_unreachable ();
12875 lookup_cfa_1 (cfi, &next_cfa, &remember);
12879 if (!cfa_equal_p (&last_cfa, &next_cfa))
12881 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12882 start_label, last_label, section,
12884 list_tail = &(*list_tail)->dw_loc_next;
12885 start_label = last_label;
12887 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
12888 start_label, fde->dw_fde_end, section,
12894 /* Compute a displacement from the "steady-state frame pointer" to the
12895 frame base (often the same as the CFA), and store it in
12896 frame_pointer_fb_offset. OFFSET is added to the displacement
12897 before the latter is negated. */
12900 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
12904 #ifdef FRAME_POINTER_CFA_OFFSET
12905 reg = frame_pointer_rtx;
12906 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
12908 reg = arg_pointer_rtx;
12909 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
12912 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
12913 if (GET_CODE (elim) == PLUS)
12915 offset += INTVAL (XEXP (elim, 1));
12916 elim = XEXP (elim, 0);
12919 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12920 && (elim == hard_frame_pointer_rtx
12921 || elim == stack_pointer_rtx))
12922 || elim == (frame_pointer_needed
12923 ? hard_frame_pointer_rtx
12924 : stack_pointer_rtx));
12926 frame_pointer_fb_offset = -offset;
12929 /* Generate a DW_AT_name attribute given some string value to be included as
12930 the value of the attribute. */
12933 add_name_attribute (dw_die_ref die, const char *name_string)
12935 if (name_string != NULL && *name_string != 0)
12937 if (demangle_name_func)
12938 name_string = (*demangle_name_func) (name_string);
12940 add_AT_string (die, DW_AT_name, name_string);
12944 /* Generate a DW_AT_comp_dir attribute for DIE. */
12947 add_comp_dir_attribute (dw_die_ref die)
12949 const char *wd = get_src_pwd ();
12955 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
12959 wdlen = strlen (wd);
12960 wd1 = GGC_NEWVEC (char, wdlen + 2);
12962 wd1 [wdlen] = DIR_SEPARATOR;
12963 wd1 [wdlen + 1] = 0;
12967 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
12970 /* Given a tree node describing an array bound (either lower or upper) output
12971 a representation for that bound. */
12974 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
12976 switch (TREE_CODE (bound))
12981 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12983 if (! host_integerp (bound, 0)
12984 || (bound_attr == DW_AT_lower_bound
12985 && (((is_c_family () || is_java ()) && integer_zerop (bound))
12986 || (is_fortran () && integer_onep (bound)))))
12987 /* Use the default. */
12990 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
12994 case VIEW_CONVERT_EXPR:
12995 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
13005 dw_die_ref decl_die = lookup_decl_die (bound);
13006 dw_loc_descr_ref loc;
13008 /* ??? Can this happen, or should the variable have been bound
13009 first? Probably it can, since I imagine that we try to create
13010 the types of parameters in the order in which they exist in
13011 the list, and won't have created a forward reference to a
13012 later parameter. */
13013 if (decl_die != NULL)
13014 add_AT_die_ref (subrange_die, bound_attr, decl_die);
13017 loc = loc_descriptor_from_tree_1 (bound, 0);
13018 add_AT_location_description (subrange_die, bound_attr, loc);
13025 /* Otherwise try to create a stack operation procedure to
13026 evaluate the value of the array bound. */
13028 dw_die_ref ctx, decl_die;
13029 dw_loc_descr_ref loc;
13031 loc = loc_descriptor_from_tree (bound);
13035 if (current_function_decl == 0)
13036 ctx = comp_unit_die;
13038 ctx = lookup_decl_die (current_function_decl);
13040 decl_die = new_die (DW_TAG_variable, ctx, bound);
13041 add_AT_flag (decl_die, DW_AT_artificial, 1);
13042 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
13043 add_AT_loc (decl_die, DW_AT_location, loc);
13045 add_AT_die_ref (subrange_die, bound_attr, decl_die);
13051 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
13052 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
13053 Note that the block of subscript information for an array type also
13054 includes information about the element type of the given array type. */
13057 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
13059 unsigned dimension_number;
13061 dw_die_ref subrange_die;
13063 for (dimension_number = 0;
13064 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
13065 type = TREE_TYPE (type), dimension_number++)
13067 tree domain = TYPE_DOMAIN (type);
13069 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
13072 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
13073 and (in GNU C only) variable bounds. Handle all three forms
13075 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
13078 /* We have an array type with specified bounds. */
13079 lower = TYPE_MIN_VALUE (domain);
13080 upper = TYPE_MAX_VALUE (domain);
13082 /* Define the index type. */
13083 if (TREE_TYPE (domain))
13085 /* ??? This is probably an Ada unnamed subrange type. Ignore the
13086 TREE_TYPE field. We can't emit debug info for this
13087 because it is an unnamed integral type. */
13088 if (TREE_CODE (domain) == INTEGER_TYPE
13089 && TYPE_NAME (domain) == NULL_TREE
13090 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
13091 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
13094 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
13098 /* ??? If upper is NULL, the array has unspecified length,
13099 but it does have a lower bound. This happens with Fortran
13101 Since the debugger is definitely going to need to know N
13102 to produce useful results, go ahead and output the lower
13103 bound solo, and hope the debugger can cope. */
13105 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
13107 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
13110 /* Otherwise we have an array type with an unspecified length. The
13111 DWARF-2 spec does not say how to handle this; let's just leave out the
13117 add_byte_size_attribute (dw_die_ref die, tree tree_node)
13121 switch (TREE_CODE (tree_node))
13126 case ENUMERAL_TYPE:
13129 case QUAL_UNION_TYPE:
13130 size = int_size_in_bytes (tree_node);
13133 /* For a data member of a struct or union, the DW_AT_byte_size is
13134 generally given as the number of bytes normally allocated for an
13135 object of the *declared* type of the member itself. This is true
13136 even for bit-fields. */
13137 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
13140 gcc_unreachable ();
13143 /* Note that `size' might be -1 when we get to this point. If it is, that
13144 indicates that the byte size of the entity in question is variable. We
13145 have no good way of expressing this fact in Dwarf at the present time,
13146 so just let the -1 pass on through. */
13147 add_AT_unsigned (die, DW_AT_byte_size, size);
13150 /* For a FIELD_DECL node which represents a bit-field, output an attribute
13151 which specifies the distance in bits from the highest order bit of the
13152 "containing object" for the bit-field to the highest order bit of the
13155 For any given bit-field, the "containing object" is a hypothetical object
13156 (of some integral or enum type) within which the given bit-field lives. The
13157 type of this hypothetical "containing object" is always the same as the
13158 declared type of the individual bit-field itself. The determination of the
13159 exact location of the "containing object" for a bit-field is rather
13160 complicated. It's handled by the `field_byte_offset' function (above).
13162 Note that it is the size (in bytes) of the hypothetical "containing object"
13163 which will be given in the DW_AT_byte_size attribute for this bit-field.
13164 (See `byte_size_attribute' above). */
13167 add_bit_offset_attribute (dw_die_ref die, tree decl)
13169 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
13170 tree type = DECL_BIT_FIELD_TYPE (decl);
13171 HOST_WIDE_INT bitpos_int;
13172 HOST_WIDE_INT highest_order_object_bit_offset;
13173 HOST_WIDE_INT highest_order_field_bit_offset;
13174 HOST_WIDE_INT unsigned bit_offset;
13176 /* Must be a field and a bit field. */
13177 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
13179 /* We can't yet handle bit-fields whose offsets are variable, so if we
13180 encounter such things, just return without generating any attribute
13181 whatsoever. Likewise for variable or too large size. */
13182 if (! host_integerp (bit_position (decl), 0)
13183 || ! host_integerp (DECL_SIZE (decl), 1))
13186 bitpos_int = int_bit_position (decl);
13188 /* Note that the bit offset is always the distance (in bits) from the
13189 highest-order bit of the "containing object" to the highest-order bit of
13190 the bit-field itself. Since the "high-order end" of any object or field
13191 is different on big-endian and little-endian machines, the computation
13192 below must take account of these differences. */
13193 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
13194 highest_order_field_bit_offset = bitpos_int;
13196 if (! BYTES_BIG_ENDIAN)
13198 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
13199 highest_order_object_bit_offset += simple_type_size_in_bits (type);
13203 = (! BYTES_BIG_ENDIAN
13204 ? highest_order_object_bit_offset - highest_order_field_bit_offset
13205 : highest_order_field_bit_offset - highest_order_object_bit_offset);
13207 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
13210 /* For a FIELD_DECL node which represents a bit field, output an attribute
13211 which specifies the length in bits of the given field. */
13214 add_bit_size_attribute (dw_die_ref die, tree decl)
13216 /* Must be a field and a bit field. */
13217 gcc_assert (TREE_CODE (decl) == FIELD_DECL
13218 && DECL_BIT_FIELD_TYPE (decl));
13220 if (host_integerp (DECL_SIZE (decl), 1))
13221 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
13224 /* If the compiled language is ANSI C, then add a 'prototyped'
13225 attribute, if arg types are given for the parameters of a function. */
13228 add_prototyped_attribute (dw_die_ref die, tree func_type)
13230 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
13231 && TYPE_ARG_TYPES (func_type) != NULL)
13232 add_AT_flag (die, DW_AT_prototyped, 1);
13235 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
13236 by looking in either the type declaration or object declaration
13239 static inline dw_die_ref
13240 add_abstract_origin_attribute (dw_die_ref die, tree origin)
13242 dw_die_ref origin_die = NULL;
13244 if (TREE_CODE (origin) != FUNCTION_DECL)
13246 /* We may have gotten separated from the block for the inlined
13247 function, if we're in an exception handler or some such; make
13248 sure that the abstract function has been written out.
13250 Doing this for nested functions is wrong, however; functions are
13251 distinct units, and our context might not even be inline. */
13255 fn = TYPE_STUB_DECL (fn);
13257 fn = decl_function_context (fn);
13259 dwarf2out_abstract_function (fn);
13262 if (DECL_P (origin))
13263 origin_die = lookup_decl_die (origin);
13264 else if (TYPE_P (origin))
13265 origin_die = lookup_type_die (origin);
13267 /* XXX: Functions that are never lowered don't always have correct block
13268 trees (in the case of java, they simply have no block tree, in some other
13269 languages). For these functions, there is nothing we can really do to
13270 output correct debug info for inlined functions in all cases. Rather
13271 than die, we'll just produce deficient debug info now, in that we will
13272 have variables without a proper abstract origin. In the future, when all
13273 functions are lowered, we should re-add a gcc_assert (origin_die)
13277 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
13281 /* We do not currently support the pure_virtual attribute. */
13284 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
13286 if (DECL_VINDEX (func_decl))
13288 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13290 if (host_integerp (DECL_VINDEX (func_decl), 0))
13291 add_AT_loc (die, DW_AT_vtable_elem_location,
13292 new_loc_descr (DW_OP_constu,
13293 tree_low_cst (DECL_VINDEX (func_decl), 0),
13296 /* GNU extension: Record what type this method came from originally. */
13297 if (debug_info_level > DINFO_LEVEL_TERSE)
13298 add_AT_die_ref (die, DW_AT_containing_type,
13299 lookup_type_die (DECL_CONTEXT (func_decl)));
13303 /* Add source coordinate attributes for the given decl. */
13306 add_src_coords_attributes (dw_die_ref die, tree decl)
13308 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13310 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
13311 add_AT_unsigned (die, DW_AT_decl_line, s.line);
13314 /* Add a DW_AT_name attribute and source coordinate attribute for the
13315 given decl, but only if it actually has a name. */
13318 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
13322 decl_name = DECL_NAME (decl);
13323 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
13325 add_name_attribute (die, dwarf2_name (decl, 0));
13326 if (! DECL_ARTIFICIAL (decl))
13327 add_src_coords_attributes (die, decl);
13329 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
13330 && TREE_PUBLIC (decl)
13331 && !DECL_ABSTRACT (decl)
13332 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
13335 /* Defer until we have an assembler name set. */
13336 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
13338 limbo_die_node *asm_name;
13340 asm_name = GGC_CNEW (limbo_die_node);
13341 asm_name->die = die;
13342 asm_name->created_for = decl;
13343 asm_name->next = deferred_asm_name;
13344 deferred_asm_name = asm_name;
13346 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
13347 add_AT_string (die, DW_AT_MIPS_linkage_name,
13348 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
13352 #ifdef VMS_DEBUGGING_INFO
13353 /* Get the function's name, as described by its RTL. This may be different
13354 from the DECL_NAME name used in the source file. */
13355 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
13357 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
13358 XEXP (DECL_RTL (decl), 0));
13359 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
13364 /* Push a new declaration scope. */
13367 push_decl_scope (tree scope)
13369 VEC_safe_push (tree, gc, decl_scope_table, scope);
13372 /* Pop a declaration scope. */
13375 pop_decl_scope (void)
13377 VEC_pop (tree, decl_scope_table);
13380 /* Return the DIE for the scope that immediately contains this type.
13381 Non-named types get global scope. Named types nested in other
13382 types get their containing scope if it's open, or global scope
13383 otherwise. All other types (i.e. function-local named types) get
13384 the current active scope. */
13387 scope_die_for (tree t, dw_die_ref context_die)
13389 dw_die_ref scope_die = NULL;
13390 tree containing_scope;
13393 /* Non-types always go in the current scope. */
13394 gcc_assert (TYPE_P (t));
13396 containing_scope = TYPE_CONTEXT (t);
13398 /* Use the containing namespace if it was passed in (for a declaration). */
13399 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
13401 if (context_die == lookup_decl_die (containing_scope))
13404 containing_scope = NULL_TREE;
13407 /* Ignore function type "scopes" from the C frontend. They mean that
13408 a tagged type is local to a parmlist of a function declarator, but
13409 that isn't useful to DWARF. */
13410 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
13411 containing_scope = NULL_TREE;
13413 if (containing_scope == NULL_TREE)
13414 scope_die = comp_unit_die;
13415 else if (TYPE_P (containing_scope))
13417 /* For types, we can just look up the appropriate DIE. But
13418 first we check to see if we're in the middle of emitting it
13419 so we know where the new DIE should go. */
13420 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
13421 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
13426 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
13427 || TREE_ASM_WRITTEN (containing_scope));
13429 /* If none of the current dies are suitable, we get file scope. */
13430 scope_die = comp_unit_die;
13433 scope_die = lookup_type_die (containing_scope);
13436 scope_die = context_die;
13441 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
13444 local_scope_p (dw_die_ref context_die)
13446 for (; context_die; context_die = context_die->die_parent)
13447 if (context_die->die_tag == DW_TAG_inlined_subroutine
13448 || context_die->die_tag == DW_TAG_subprogram)
13454 /* Returns nonzero if CONTEXT_DIE is a class. */
13457 class_scope_p (dw_die_ref context_die)
13459 return (context_die
13460 && (context_die->die_tag == DW_TAG_structure_type
13461 || context_die->die_tag == DW_TAG_class_type
13462 || context_die->die_tag == DW_TAG_interface_type
13463 || context_die->die_tag == DW_TAG_union_type));
13466 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
13467 whether or not to treat a DIE in this context as a declaration. */
13470 class_or_namespace_scope_p (dw_die_ref context_die)
13472 return (class_scope_p (context_die)
13473 || (context_die && context_die->die_tag == DW_TAG_namespace));
13476 /* Many forms of DIEs require a "type description" attribute. This
13477 routine locates the proper "type descriptor" die for the type given
13478 by 'type', and adds a DW_AT_type attribute below the given die. */
13481 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
13482 int decl_volatile, dw_die_ref context_die)
13484 enum tree_code code = TREE_CODE (type);
13485 dw_die_ref type_die = NULL;
13487 /* ??? If this type is an unnamed subrange type of an integral, floating-point
13488 or fixed-point type, use the inner type. This is because we have no
13489 support for unnamed types in base_type_die. This can happen if this is
13490 an Ada subrange type. Correct solution is emit a subrange type die. */
13491 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
13492 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
13493 type = TREE_TYPE (type), code = TREE_CODE (type);
13495 if (code == ERROR_MARK
13496 /* Handle a special case. For functions whose return type is void, we
13497 generate *no* type attribute. (Note that no object may have type
13498 `void', so this only applies to function return types). */
13499 || code == VOID_TYPE)
13502 type_die = modified_type_die (type,
13503 decl_const || TYPE_READONLY (type),
13504 decl_volatile || TYPE_VOLATILE (type),
13507 if (type_die != NULL)
13508 add_AT_die_ref (object_die, DW_AT_type, type_die);
13511 /* Given an object die, add the calling convention attribute for the
13512 function call type. */
13514 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
13516 enum dwarf_calling_convention value = DW_CC_normal;
13518 value = ((enum dwarf_calling_convention)
13519 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
13521 /* DWARF doesn't provide a way to identify a program's source-level
13522 entry point. DW_AT_calling_convention attributes are only meant
13523 to describe functions' calling conventions. However, lacking a
13524 better way to signal the Fortran main program, we use this for the
13525 time being, following existing custom. */
13527 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
13528 value = DW_CC_program;
13530 /* Only add the attribute if the backend requests it, and
13531 is not DW_CC_normal. */
13532 if (value && (value != DW_CC_normal))
13533 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
13536 /* Given a tree pointer to a struct, class, union, or enum type node, return
13537 a pointer to the (string) tag name for the given type, or zero if the type
13538 was declared without a tag. */
13540 static const char *
13541 type_tag (const_tree type)
13543 const char *name = 0;
13545 if (TYPE_NAME (type) != 0)
13549 /* Find the IDENTIFIER_NODE for the type name. */
13550 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
13551 t = TYPE_NAME (type);
13553 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
13554 a TYPE_DECL node, regardless of whether or not a `typedef' was
13556 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13557 && ! DECL_IGNORED_P (TYPE_NAME (type)))
13559 /* We want to be extra verbose. Don't call dwarf_name if
13560 DECL_NAME isn't set. The default hook for decl_printable_name
13561 doesn't like that, and in this context it's correct to return
13562 0, instead of "<anonymous>" or the like. */
13563 if (DECL_NAME (TYPE_NAME (type)))
13564 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
13567 /* Now get the name as a string, or invent one. */
13568 if (!name && t != 0)
13569 name = IDENTIFIER_POINTER (t);
13572 return (name == 0 || *name == '\0') ? 0 : name;
13575 /* Return the type associated with a data member, make a special check
13576 for bit field types. */
13579 member_declared_type (const_tree member)
13581 return (DECL_BIT_FIELD_TYPE (member)
13582 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
13585 /* Get the decl's label, as described by its RTL. This may be different
13586 from the DECL_NAME name used in the source file. */
13589 static const char *
13590 decl_start_label (tree decl)
13593 const char *fnname;
13595 x = DECL_RTL (decl);
13596 gcc_assert (MEM_P (x));
13599 gcc_assert (GET_CODE (x) == SYMBOL_REF);
13601 fnname = XSTR (x, 0);
13606 /* These routines generate the internal representation of the DIE's for
13607 the compilation unit. Debugging information is collected by walking
13608 the declaration trees passed in from dwarf2out_decl(). */
13611 gen_array_type_die (tree type, dw_die_ref context_die)
13613 dw_die_ref scope_die = scope_die_for (type, context_die);
13614 dw_die_ref array_die;
13616 /* GNU compilers represent multidimensional array types as sequences of one
13617 dimensional array types whose element types are themselves array types.
13618 We sometimes squish that down to a single array_type DIE with multiple
13619 subscripts in the Dwarf debugging info. The draft Dwarf specification
13620 say that we are allowed to do this kind of compression in C, because
13621 there is no difference between an array of arrays and a multidimensional
13622 array. We don't do this for Ada to remain as close as possible to the
13623 actual representation, which is especially important against the language
13624 flexibilty wrt arrays of variable size. */
13626 bool collapse_nested_arrays = !is_ada ();
13629 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
13630 DW_TAG_string_type doesn't have DW_AT_type attribute). */
13631 if (TYPE_STRING_FLAG (type)
13632 && TREE_CODE (type) == ARRAY_TYPE
13634 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
13636 HOST_WIDE_INT size;
13638 array_die = new_die (DW_TAG_string_type, scope_die, type);
13639 add_name_attribute (array_die, type_tag (type));
13640 equate_type_number_to_die (type, array_die);
13641 size = int_size_in_bytes (type);
13643 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13644 else if (TYPE_DOMAIN (type) != NULL_TREE
13645 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
13646 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
13648 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
13649 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
13651 size = int_size_in_bytes (TREE_TYPE (szdecl));
13652 if (loc && size > 0)
13654 add_AT_loc (array_die, DW_AT_string_length, loc);
13655 if (size != DWARF2_ADDR_SIZE)
13656 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13662 /* ??? The SGI dwarf reader fails for array of array of enum types
13663 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
13664 array type comes before the outer array type. We thus call gen_type_die
13665 before we new_die and must prevent nested array types collapsing for this
13668 #ifdef MIPS_DEBUGGING_INFO
13669 gen_type_die (TREE_TYPE (type), context_die);
13670 collapse_nested_arrays = false;
13673 array_die = new_die (DW_TAG_array_type, scope_die, type);
13674 add_name_attribute (array_die, type_tag (type));
13675 equate_type_number_to_die (type, array_die);
13677 if (TREE_CODE (type) == VECTOR_TYPE)
13679 /* The frontend feeds us a representation for the vector as a struct
13680 containing an array. Pull out the array type. */
13681 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
13682 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
13685 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13687 && TREE_CODE (type) == ARRAY_TYPE
13688 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
13689 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
13690 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13693 /* We default the array ordering. SDB will probably do
13694 the right things even if DW_AT_ordering is not present. It's not even
13695 an issue until we start to get into multidimensional arrays anyway. If
13696 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
13697 then we'll have to put the DW_AT_ordering attribute back in. (But if
13698 and when we find out that we need to put these in, we will only do so
13699 for multidimensional arrays. */
13700 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
13703 #ifdef MIPS_DEBUGGING_INFO
13704 /* The SGI compilers handle arrays of unknown bound by setting
13705 AT_declaration and not emitting any subrange DIEs. */
13706 if (! TYPE_DOMAIN (type))
13707 add_AT_flag (array_die, DW_AT_declaration, 1);
13710 add_subscript_info (array_die, type, collapse_nested_arrays);
13712 /* Add representation of the type of the elements of this array type and
13713 emit the corresponding DIE if we haven't done it already. */
13714 element_type = TREE_TYPE (type);
13715 if (collapse_nested_arrays)
13716 while (TREE_CODE (element_type) == ARRAY_TYPE)
13718 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
13720 element_type = TREE_TYPE (element_type);
13723 #ifndef MIPS_DEBUGGING_INFO
13724 gen_type_die (element_type, context_die);
13727 add_type_attribute (array_die, element_type, 0, 0, context_die);
13729 if (get_AT (array_die, DW_AT_name))
13730 add_pubtype (type, array_die);
13733 static dw_loc_descr_ref
13734 descr_info_loc (tree val, tree base_decl)
13736 HOST_WIDE_INT size;
13737 dw_loc_descr_ref loc, loc2;
13738 enum dwarf_location_atom op;
13740 if (val == base_decl)
13741 return new_loc_descr (DW_OP_push_object_address, 0, 0);
13743 switch (TREE_CODE (val))
13746 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13748 return loc_descriptor_from_tree_1 (val, 0);
13750 if (host_integerp (val, 0))
13751 return int_loc_descriptor (tree_low_cst (val, 0));
13754 size = int_size_in_bytes (TREE_TYPE (val));
13757 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13760 if (size == DWARF2_ADDR_SIZE)
13761 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
13763 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
13765 case POINTER_PLUS_EXPR:
13767 if (host_integerp (TREE_OPERAND (val, 1), 1)
13768 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
13771 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13774 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
13780 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13783 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
13786 add_loc_descr (&loc, loc2);
13787 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
13809 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
13810 tree val, tree base_decl)
13812 dw_loc_descr_ref loc;
13814 if (host_integerp (val, 0))
13816 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
13820 loc = descr_info_loc (val, base_decl);
13824 add_AT_loc (die, attr, loc);
13827 /* This routine generates DIE for array with hidden descriptor, details
13828 are filled into *info by a langhook. */
13831 gen_descr_array_type_die (tree type, struct array_descr_info *info,
13832 dw_die_ref context_die)
13834 dw_die_ref scope_die = scope_die_for (type, context_die);
13835 dw_die_ref array_die;
13838 array_die = new_die (DW_TAG_array_type, scope_die, type);
13839 add_name_attribute (array_die, type_tag (type));
13840 equate_type_number_to_die (type, array_die);
13842 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13844 && info->ndimensions >= 2)
13845 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13847 if (info->data_location)
13848 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
13850 if (info->associated)
13851 add_descr_info_field (array_die, DW_AT_associated, info->associated,
13853 if (info->allocated)
13854 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
13857 for (dim = 0; dim < info->ndimensions; dim++)
13859 dw_die_ref subrange_die
13860 = new_die (DW_TAG_subrange_type, array_die, NULL);
13862 if (info->dimen[dim].lower_bound)
13864 /* If it is the default value, omit it. */
13865 if ((is_c_family () || is_java ())
13866 && integer_zerop (info->dimen[dim].lower_bound))
13868 else if (is_fortran ()
13869 && integer_onep (info->dimen[dim].lower_bound))
13872 add_descr_info_field (subrange_die, DW_AT_lower_bound,
13873 info->dimen[dim].lower_bound,
13876 if (info->dimen[dim].upper_bound)
13877 add_descr_info_field (subrange_die, DW_AT_upper_bound,
13878 info->dimen[dim].upper_bound,
13880 if (info->dimen[dim].stride)
13881 add_descr_info_field (subrange_die, DW_AT_byte_stride,
13882 info->dimen[dim].stride,
13886 gen_type_die (info->element_type, context_die);
13887 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
13889 if (get_AT (array_die, DW_AT_name))
13890 add_pubtype (type, array_die);
13895 gen_entry_point_die (tree decl, dw_die_ref context_die)
13897 tree origin = decl_ultimate_origin (decl);
13898 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
13900 if (origin != NULL)
13901 add_abstract_origin_attribute (decl_die, origin);
13904 add_name_and_src_coords_attributes (decl_die, decl);
13905 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
13906 0, 0, context_die);
13909 if (DECL_ABSTRACT (decl))
13910 equate_decl_number_to_die (decl, decl_die);
13912 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
13916 /* Walk through the list of incomplete types again, trying once more to
13917 emit full debugging info for them. */
13920 retry_incomplete_types (void)
13924 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
13925 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
13928 /* Determine what tag to use for a record type. */
13930 static enum dwarf_tag
13931 record_type_tag (tree type)
13933 if (! lang_hooks.types.classify_record)
13934 return DW_TAG_structure_type;
13936 switch (lang_hooks.types.classify_record (type))
13938 case RECORD_IS_STRUCT:
13939 return DW_TAG_structure_type;
13941 case RECORD_IS_CLASS:
13942 return DW_TAG_class_type;
13944 case RECORD_IS_INTERFACE:
13945 return DW_TAG_interface_type;
13948 gcc_unreachable ();
13952 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13953 include all of the information about the enumeration values also. Each
13954 enumerated type name/value is listed as a child of the enumerated type
13958 gen_enumeration_type_die (tree type, dw_die_ref context_die)
13960 dw_die_ref type_die = lookup_type_die (type);
13962 if (type_die == NULL)
13964 type_die = new_die (DW_TAG_enumeration_type,
13965 scope_die_for (type, context_die), type);
13966 equate_type_number_to_die (type, type_die);
13967 add_name_attribute (type_die, type_tag (type));
13969 else if (! TYPE_SIZE (type))
13972 remove_AT (type_die, DW_AT_declaration);
13974 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13975 given enum type is incomplete, do not generate the DW_AT_byte_size
13976 attribute or the DW_AT_element_list attribute. */
13977 if (TYPE_SIZE (type))
13981 TREE_ASM_WRITTEN (type) = 1;
13982 add_byte_size_attribute (type_die, type);
13983 if (TYPE_STUB_DECL (type) != NULL_TREE)
13984 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13986 /* If the first reference to this type was as the return type of an
13987 inline function, then it may not have a parent. Fix this now. */
13988 if (type_die->die_parent == NULL)
13989 add_child_die (scope_die_for (type, context_die), type_die);
13991 for (link = TYPE_VALUES (type);
13992 link != NULL; link = TREE_CHAIN (link))
13994 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
13995 tree value = TREE_VALUE (link);
13997 add_name_attribute (enum_die,
13998 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
14000 if (TREE_CODE (value) == CONST_DECL)
14001 value = DECL_INITIAL (value);
14003 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
14004 /* DWARF2 does not provide a way of indicating whether or
14005 not enumeration constants are signed or unsigned. GDB
14006 always assumes the values are signed, so we output all
14007 values as if they were signed. That means that
14008 enumeration constants with very large unsigned values
14009 will appear to have negative values in the debugger. */
14010 add_AT_int (enum_die, DW_AT_const_value,
14011 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
14015 add_AT_flag (type_die, DW_AT_declaration, 1);
14017 if (get_AT (type_die, DW_AT_name))
14018 add_pubtype (type, type_die);
14023 /* Generate a DIE to represent either a real live formal parameter decl or to
14024 represent just the type of some formal parameter position in some function
14027 Note that this routine is a bit unusual because its argument may be a
14028 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
14029 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
14030 node. If it's the former then this function is being called to output a
14031 DIE to represent a formal parameter object (or some inlining thereof). If
14032 it's the latter, then this function is only being called to output a
14033 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
14034 argument type of some subprogram type. */
14037 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
14039 tree node_or_origin = node ? node : origin;
14040 dw_die_ref parm_die
14041 = new_die (DW_TAG_formal_parameter, context_die, node);
14043 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
14045 case tcc_declaration:
14047 origin = decl_ultimate_origin (node);
14048 if (origin != NULL)
14049 add_abstract_origin_attribute (parm_die, origin);
14052 tree type = TREE_TYPE (node);
14053 add_name_and_src_coords_attributes (parm_die, node);
14054 if (DECL_BY_REFERENCE (node))
14055 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
14058 add_type_attribute (parm_die, type,
14059 TREE_READONLY (node),
14060 TREE_THIS_VOLATILE (node),
14062 if (DECL_ARTIFICIAL (node))
14063 add_AT_flag (parm_die, DW_AT_artificial, 1);
14066 if (node && node != origin)
14067 equate_decl_number_to_die (node, parm_die);
14068 if (! DECL_ABSTRACT (node_or_origin))
14069 add_location_or_const_value_attribute (parm_die, node_or_origin,
14075 /* We were called with some kind of a ..._TYPE node. */
14076 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
14080 gcc_unreachable ();
14086 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
14087 at the end of an (ANSI prototyped) formal parameters list. */
14090 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
14092 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
14095 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
14096 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
14097 parameters as specified in some function type specification (except for
14098 those which appear as part of a function *definition*). */
14101 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
14104 tree formal_type = NULL;
14105 tree first_parm_type;
14108 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
14110 arg = DECL_ARGUMENTS (function_or_method_type);
14111 function_or_method_type = TREE_TYPE (function_or_method_type);
14116 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
14118 /* Make our first pass over the list of formal parameter types and output a
14119 DW_TAG_formal_parameter DIE for each one. */
14120 for (link = first_parm_type; link; )
14122 dw_die_ref parm_die;
14124 formal_type = TREE_VALUE (link);
14125 if (formal_type == void_type_node)
14128 /* Output a (nameless) DIE to represent the formal parameter itself. */
14129 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
14130 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
14131 && link == first_parm_type)
14132 || (arg && DECL_ARTIFICIAL (arg)))
14133 add_AT_flag (parm_die, DW_AT_artificial, 1);
14135 link = TREE_CHAIN (link);
14137 arg = TREE_CHAIN (arg);
14140 /* If this function type has an ellipsis, add a
14141 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
14142 if (formal_type != void_type_node)
14143 gen_unspecified_parameters_die (function_or_method_type, context_die);
14145 /* Make our second (and final) pass over the list of formal parameter types
14146 and output DIEs to represent those types (as necessary). */
14147 for (link = TYPE_ARG_TYPES (function_or_method_type);
14148 link && TREE_VALUE (link);
14149 link = TREE_CHAIN (link))
14150 gen_type_die (TREE_VALUE (link), context_die);
14153 /* We want to generate the DIE for TYPE so that we can generate the
14154 die for MEMBER, which has been defined; we will need to refer back
14155 to the member declaration nested within TYPE. If we're trying to
14156 generate minimal debug info for TYPE, processing TYPE won't do the
14157 trick; we need to attach the member declaration by hand. */
14160 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
14162 gen_type_die (type, context_die);
14164 /* If we're trying to avoid duplicate debug info, we may not have
14165 emitted the member decl for this function. Emit it now. */
14166 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
14167 && ! lookup_decl_die (member))
14169 dw_die_ref type_die;
14170 gcc_assert (!decl_ultimate_origin (member));
14172 push_decl_scope (type);
14173 type_die = lookup_type_die (type);
14174 if (TREE_CODE (member) == FUNCTION_DECL)
14175 gen_subprogram_die (member, type_die);
14176 else if (TREE_CODE (member) == FIELD_DECL)
14178 /* Ignore the nameless fields that are used to skip bits but handle
14179 C++ anonymous unions and structs. */
14180 if (DECL_NAME (member) != NULL_TREE
14181 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
14182 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
14184 gen_type_die (member_declared_type (member), type_die);
14185 gen_field_die (member, type_die);
14189 gen_variable_die (member, NULL_TREE, type_die);
14195 /* Generate the DWARF2 info for the "abstract" instance of a function which we
14196 may later generate inlined and/or out-of-line instances of. */
14199 dwarf2out_abstract_function (tree decl)
14201 dw_die_ref old_die;
14204 int was_abstract = DECL_ABSTRACT (decl);
14206 /* Make sure we have the actual abstract inline, not a clone. */
14207 decl = DECL_ORIGIN (decl);
14208 htab_empty (decl_loc_table);
14210 old_die = lookup_decl_die (decl);
14211 if (old_die && get_AT (old_die, DW_AT_inline))
14212 /* We've already generated the abstract instance. */
14215 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
14216 we don't get confused by DECL_ABSTRACT. */
14217 if (debug_info_level > DINFO_LEVEL_TERSE)
14219 context = decl_class_context (decl);
14221 gen_type_die_for_member
14222 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
14225 /* Pretend we've just finished compiling this function. */
14226 save_fn = current_function_decl;
14227 current_function_decl = decl;
14228 push_cfun (DECL_STRUCT_FUNCTION (decl));
14230 set_decl_abstract_flags (decl, 1);
14231 dwarf2out_decl (decl);
14232 if (! was_abstract)
14233 set_decl_abstract_flags (decl, 0);
14235 current_function_decl = save_fn;
14239 /* Helper function of premark_used_types() which gets called through
14240 htab_traverse_resize().
14242 Marks the DIE of a given type in *SLOT as perennial, so it never gets
14243 marked as unused by prune_unused_types. */
14245 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
14250 type = (tree) *slot;
14251 die = lookup_type_die (type);
14253 die->die_perennial_p = 1;
14257 /* Mark all members of used_types_hash as perennial. */
14259 premark_used_types (void)
14261 if (cfun && cfun->used_types_hash)
14262 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
14265 /* Generate a DIE to represent a declared function (either file-scope or
14269 gen_subprogram_die (tree decl, dw_die_ref context_die)
14271 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14272 tree origin = decl_ultimate_origin (decl);
14273 dw_die_ref subr_die;
14276 dw_die_ref old_die = lookup_decl_die (decl);
14277 int declaration = (current_function_decl != decl
14278 || class_or_namespace_scope_p (context_die));
14280 premark_used_types ();
14282 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
14283 started to generate the abstract instance of an inline, decided to output
14284 its containing class, and proceeded to emit the declaration of the inline
14285 from the member list for the class. If so, DECLARATION takes priority;
14286 we'll get back to the abstract instance when done with the class. */
14288 /* The class-scope declaration DIE must be the primary DIE. */
14289 if (origin && declaration && class_or_namespace_scope_p (context_die))
14292 gcc_assert (!old_die);
14295 /* Now that the C++ front end lazily declares artificial member fns, we
14296 might need to retrofit the declaration into its class. */
14297 if (!declaration && !origin && !old_die
14298 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
14299 && !class_or_namespace_scope_p (context_die)
14300 && debug_info_level > DINFO_LEVEL_TERSE)
14301 old_die = force_decl_die (decl);
14303 if (origin != NULL)
14305 gcc_assert (!declaration || local_scope_p (context_die));
14307 /* Fixup die_parent for the abstract instance of a nested
14308 inline function. */
14309 if (old_die && old_die->die_parent == NULL)
14310 add_child_die (context_die, old_die);
14312 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14313 add_abstract_origin_attribute (subr_die, origin);
14317 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14318 struct dwarf_file_data * file_index = lookup_filename (s.file);
14320 if (!get_AT_flag (old_die, DW_AT_declaration)
14321 /* We can have a normal definition following an inline one in the
14322 case of redefinition of GNU C extern inlines.
14323 It seems reasonable to use AT_specification in this case. */
14324 && !get_AT (old_die, DW_AT_inline))
14326 /* Detect and ignore this case, where we are trying to output
14327 something we have already output. */
14331 /* If the definition comes from the same place as the declaration,
14332 maybe use the old DIE. We always want the DIE for this function
14333 that has the *_pc attributes to be under comp_unit_die so the
14334 debugger can find it. We also need to do this for abstract
14335 instances of inlines, since the spec requires the out-of-line copy
14336 to have the same parent. For local class methods, this doesn't
14337 apply; we just use the old DIE. */
14338 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
14339 && (DECL_ARTIFICIAL (decl)
14340 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
14341 && (get_AT_unsigned (old_die, DW_AT_decl_line)
14342 == (unsigned) s.line))))
14344 subr_die = old_die;
14346 /* Clear out the declaration attribute and the formal parameters.
14347 Do not remove all children, because it is possible that this
14348 declaration die was forced using force_decl_die(). In such
14349 cases die that forced declaration die (e.g. TAG_imported_module)
14350 is one of the children that we do not want to remove. */
14351 remove_AT (subr_die, DW_AT_declaration);
14352 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
14356 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14357 add_AT_specification (subr_die, old_die);
14358 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14359 add_AT_file (subr_die, DW_AT_decl_file, file_index);
14360 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14361 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
14366 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
14368 if (TREE_PUBLIC (decl))
14369 add_AT_flag (subr_die, DW_AT_external, 1);
14371 add_name_and_src_coords_attributes (subr_die, decl);
14372 if (debug_info_level > DINFO_LEVEL_TERSE)
14374 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
14375 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
14376 0, 0, context_die);
14379 add_pure_or_virtual_attribute (subr_die, decl);
14380 if (DECL_ARTIFICIAL (decl))
14381 add_AT_flag (subr_die, DW_AT_artificial, 1);
14383 if (TREE_PROTECTED (decl))
14384 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
14385 else if (TREE_PRIVATE (decl))
14386 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
14391 if (!old_die || !get_AT (old_die, DW_AT_inline))
14393 add_AT_flag (subr_die, DW_AT_declaration, 1);
14395 /* If this is an explicit function declaration then generate
14396 a DW_AT_explicit attribute. */
14397 if (lang_hooks.decls.function_decl_explicit_p (decl))
14398 add_AT_flag (subr_die, DW_AT_explicit, 1);
14400 /* The first time we see a member function, it is in the context of
14401 the class to which it belongs. We make sure of this by emitting
14402 the class first. The next time is the definition, which is
14403 handled above. The two may come from the same source text.
14405 Note that force_decl_die() forces function declaration die. It is
14406 later reused to represent definition. */
14407 equate_decl_number_to_die (decl, subr_die);
14410 else if (DECL_ABSTRACT (decl))
14412 if (DECL_DECLARED_INLINE_P (decl))
14414 if (cgraph_function_possibly_inlined_p (decl))
14415 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
14417 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
14421 if (cgraph_function_possibly_inlined_p (decl))
14422 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
14424 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
14427 if (DECL_DECLARED_INLINE_P (decl)
14428 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
14429 add_AT_flag (subr_die, DW_AT_artificial, 1);
14431 equate_decl_number_to_die (decl, subr_die);
14433 else if (!DECL_EXTERNAL (decl))
14435 HOST_WIDE_INT cfa_fb_offset;
14437 if (!old_die || !get_AT (old_die, DW_AT_inline))
14438 equate_decl_number_to_die (decl, subr_die);
14440 if (!flag_reorder_blocks_and_partition)
14442 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
14443 current_function_funcdef_no);
14444 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
14445 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
14446 current_function_funcdef_no);
14447 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
14449 add_pubname (decl, subr_die);
14450 add_arange (decl, subr_die);
14453 { /* Do nothing for now; maybe need to duplicate die, one for
14454 hot section and one for cold section, then use the hot/cold
14455 section begin/end labels to generate the aranges... */
14457 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
14458 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
14459 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
14460 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
14462 add_pubname (decl, subr_die);
14463 add_arange (decl, subr_die);
14464 add_arange (decl, subr_die);
14468 #ifdef MIPS_DEBUGGING_INFO
14469 /* Add a reference to the FDE for this routine. */
14470 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
14473 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
14475 /* We define the "frame base" as the function's CFA. This is more
14476 convenient for several reasons: (1) It's stable across the prologue
14477 and epilogue, which makes it better than just a frame pointer,
14478 (2) With dwarf3, there exists a one-byte encoding that allows us
14479 to reference the .debug_frame data by proxy, but failing that,
14480 (3) We can at least reuse the code inspection and interpretation
14481 code that determines the CFA position at various points in the
14483 if (dwarf_version >= 3)
14485 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
14486 add_AT_loc (subr_die, DW_AT_frame_base, op);
14490 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
14491 if (list->dw_loc_next)
14492 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
14494 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
14497 /* Compute a displacement from the "steady-state frame pointer" to
14498 the CFA. The former is what all stack slots and argument slots
14499 will reference in the rtl; the later is what we've told the
14500 debugger about. We'll need to adjust all frame_base references
14501 by this displacement. */
14502 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
14504 if (cfun->static_chain_decl)
14505 add_AT_location_description (subr_die, DW_AT_static_link,
14506 loc_descriptor_from_tree (cfun->static_chain_decl));
14509 /* Now output descriptions of the arguments for this function. This gets
14510 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
14511 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
14512 `...' at the end of the formal parameter list. In order to find out if
14513 there was a trailing ellipsis or not, we must instead look at the type
14514 associated with the FUNCTION_DECL. This will be a node of type
14515 FUNCTION_TYPE. If the chain of type nodes hanging off of this
14516 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
14517 an ellipsis at the end. */
14519 /* In the case where we are describing a mere function declaration, all we
14520 need to do here (and all we *can* do here) is to describe the *types* of
14521 its formal parameters. */
14522 if (debug_info_level <= DINFO_LEVEL_TERSE)
14524 else if (declaration)
14525 gen_formal_types_die (decl, subr_die);
14528 /* Generate DIEs to represent all known formal parameters. */
14529 tree arg_decls = DECL_ARGUMENTS (decl);
14532 /* When generating DIEs, generate the unspecified_parameters DIE
14533 instead if we come across the arg "__builtin_va_alist" */
14534 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
14535 if (TREE_CODE (parm) == PARM_DECL)
14537 if (DECL_NAME (parm)
14538 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
14539 "__builtin_va_alist"))
14540 gen_unspecified_parameters_die (parm, subr_die);
14542 gen_decl_die (parm, NULL, subr_die);
14545 /* Decide whether we need an unspecified_parameters DIE at the end.
14546 There are 2 more cases to do this for: 1) the ansi ... declaration -
14547 this is detectable when the end of the arg list is not a
14548 void_type_node 2) an unprototyped function declaration (not a
14549 definition). This just means that we have no info about the
14550 parameters at all. */
14551 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
14552 if (fn_arg_types != NULL)
14554 /* This is the prototyped case, check for.... */
14555 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
14556 gen_unspecified_parameters_die (decl, subr_die);
14558 else if (DECL_INITIAL (decl) == NULL_TREE)
14559 gen_unspecified_parameters_die (decl, subr_die);
14562 /* Output Dwarf info for all of the stuff within the body of the function
14563 (if it has one - it may be just a declaration). */
14564 outer_scope = DECL_INITIAL (decl);
14566 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
14567 a function. This BLOCK actually represents the outermost binding contour
14568 for the function, i.e. the contour in which the function's formal
14569 parameters and labels get declared. Curiously, it appears that the front
14570 end doesn't actually put the PARM_DECL nodes for the current function onto
14571 the BLOCK_VARS list for this outer scope, but are strung off of the
14572 DECL_ARGUMENTS list for the function instead.
14574 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
14575 the LABEL_DECL nodes for the function however, and we output DWARF info
14576 for those in decls_for_scope. Just within the `outer_scope' there will be
14577 a BLOCK node representing the function's outermost pair of curly braces,
14578 and any blocks used for the base and member initializers of a C++
14579 constructor function. */
14580 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
14582 /* Emit a DW_TAG_variable DIE for a named return value. */
14583 if (DECL_NAME (DECL_RESULT (decl)))
14584 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
14586 current_function_has_inlines = 0;
14587 decls_for_scope (outer_scope, subr_die, 0);
14589 #if 0 && defined (MIPS_DEBUGGING_INFO)
14590 if (current_function_has_inlines)
14592 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
14593 if (! comp_unit_has_inlines)
14595 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
14596 comp_unit_has_inlines = 1;
14601 /* Add the calling convention attribute if requested. */
14602 add_calling_convention_attribute (subr_die, decl);
14606 /* Returns a hash value for X (which really is a die_struct). */
14609 common_block_die_table_hash (const void *x)
14611 const_dw_die_ref d = (const_dw_die_ref) x;
14612 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
14615 /* Return nonzero if decl_id and die_parent of die_struct X is the same
14616 as decl_id and die_parent of die_struct Y. */
14619 common_block_die_table_eq (const void *x, const void *y)
14621 const_dw_die_ref d = (const_dw_die_ref) x;
14622 const_dw_die_ref e = (const_dw_die_ref) y;
14623 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
14626 /* Generate a DIE to represent a declared data object.
14627 Either DECL or ORIGIN must be non-null. */
14630 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
14634 tree decl_or_origin = decl ? decl : origin;
14635 dw_die_ref var_die;
14636 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
14637 dw_die_ref origin_die;
14638 int declaration = (DECL_EXTERNAL (decl_or_origin)
14639 /* If DECL is COMDAT and has not actually been
14640 emitted, we cannot take its address; there
14641 might end up being no definition anywhere in
14642 the program. For example, consider the C++
14646 struct S { static const int i = 7; };
14651 int f() { return S<int>::i; }
14653 Here, S<int>::i is not DECL_EXTERNAL, but no
14654 definition is required, so the compiler will
14655 not emit a definition. */
14656 || (TREE_CODE (decl_or_origin) == VAR_DECL
14657 && DECL_COMDAT (decl_or_origin)
14658 && !TREE_ASM_WRITTEN (decl_or_origin))
14659 || class_or_namespace_scope_p (context_die));
14662 origin = decl_ultimate_origin (decl);
14664 com_decl = fortran_common (decl_or_origin, &off);
14666 /* Symbol in common gets emitted as a child of the common block, in the form
14667 of a data member. */
14671 dw_die_ref com_die;
14672 dw_loc_descr_ref loc;
14673 die_node com_die_arg;
14675 var_die = lookup_decl_die (decl_or_origin);
14678 if (get_AT (var_die, DW_AT_location) == NULL)
14680 loc = loc_descriptor_from_tree (com_decl);
14685 /* Optimize the common case. */
14686 if (loc->dw_loc_opc == DW_OP_addr
14687 && loc->dw_loc_next == NULL
14688 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
14690 loc->dw_loc_oprnd1.v.val_addr
14691 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14693 loc_descr_plus_const (&loc, off);
14695 add_AT_loc (var_die, DW_AT_location, loc);
14696 remove_AT (var_die, DW_AT_declaration);
14702 if (common_block_die_table == NULL)
14703 common_block_die_table
14704 = htab_create_ggc (10, common_block_die_table_hash,
14705 common_block_die_table_eq, NULL);
14707 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
14708 com_die_arg.decl_id = DECL_UID (com_decl);
14709 com_die_arg.die_parent = context_die;
14710 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
14711 loc = loc_descriptor_from_tree (com_decl);
14712 if (com_die == NULL)
14715 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
14718 com_die = new_die (DW_TAG_common_block, context_die, decl);
14719 add_name_and_src_coords_attributes (com_die, com_decl);
14722 add_AT_loc (com_die, DW_AT_location, loc);
14723 /* Avoid sharing the same loc descriptor between
14724 DW_TAG_common_block and DW_TAG_variable. */
14725 loc = loc_descriptor_from_tree (com_decl);
14727 else if (DECL_EXTERNAL (decl))
14728 add_AT_flag (com_die, DW_AT_declaration, 1);
14729 add_pubname_string (cnam, com_die); /* ??? needed? */
14730 com_die->decl_id = DECL_UID (com_decl);
14731 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
14732 *slot = (void *) com_die;
14734 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
14736 add_AT_loc (com_die, DW_AT_location, loc);
14737 loc = loc_descriptor_from_tree (com_decl);
14738 remove_AT (com_die, DW_AT_declaration);
14740 var_die = new_die (DW_TAG_variable, com_die, decl);
14741 add_name_and_src_coords_attributes (var_die, decl);
14742 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
14743 TREE_THIS_VOLATILE (decl), context_die);
14744 add_AT_flag (var_die, DW_AT_external, 1);
14749 /* Optimize the common case. */
14750 if (loc->dw_loc_opc == DW_OP_addr
14751 && loc->dw_loc_next == NULL
14752 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
14753 loc->dw_loc_oprnd1.v.val_addr
14754 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14756 loc_descr_plus_const (&loc, off);
14758 add_AT_loc (var_die, DW_AT_location, loc);
14760 else if (DECL_EXTERNAL (decl))
14761 add_AT_flag (var_die, DW_AT_declaration, 1);
14762 equate_decl_number_to_die (decl, var_die);
14766 /* If the compiler emitted a definition for the DECL declaration
14767 and if we already emitted a DIE for it, don't emit a second
14768 DIE for it again. */
14771 && old_die->die_parent == context_die)
14774 /* For static data members, the declaration in the class is supposed
14775 to have DW_TAG_member tag; the specification should still be
14776 DW_TAG_variable referencing the DW_TAG_member DIE. */
14777 if (declaration && class_scope_p (context_die))
14778 var_die = new_die (DW_TAG_member, context_die, decl);
14780 var_die = new_die (DW_TAG_variable, context_die, decl);
14783 if (origin != NULL)
14784 origin_die = add_abstract_origin_attribute (var_die, origin);
14786 /* Loop unrolling can create multiple blocks that refer to the same
14787 static variable, so we must test for the DW_AT_declaration flag.
14789 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14790 copy decls and set the DECL_ABSTRACT flag on them instead of
14793 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14795 ??? The declare_in_namespace support causes us to get two DIEs for one
14796 variable, both of which are declarations. We want to avoid considering
14797 one to be a specification, so we must test that this DIE is not a
14799 else if (old_die && TREE_STATIC (decl) && ! declaration
14800 && get_AT_flag (old_die, DW_AT_declaration) == 1)
14802 /* This is a definition of a C++ class level static. */
14803 add_AT_specification (var_die, old_die);
14804 if (DECL_NAME (decl))
14806 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14807 struct dwarf_file_data * file_index = lookup_filename (s.file);
14809 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14810 add_AT_file (var_die, DW_AT_decl_file, file_index);
14812 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14813 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
14818 tree type = TREE_TYPE (decl);
14820 add_name_and_src_coords_attributes (var_die, decl);
14821 if ((TREE_CODE (decl) == PARM_DECL
14822 || TREE_CODE (decl) == RESULT_DECL
14823 || TREE_CODE (decl) == VAR_DECL)
14824 && DECL_BY_REFERENCE (decl))
14825 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
14827 add_type_attribute (var_die, type, TREE_READONLY (decl),
14828 TREE_THIS_VOLATILE (decl), context_die);
14830 if (TREE_PUBLIC (decl))
14831 add_AT_flag (var_die, DW_AT_external, 1);
14833 if (DECL_ARTIFICIAL (decl))
14834 add_AT_flag (var_die, DW_AT_artificial, 1);
14836 if (TREE_PROTECTED (decl))
14837 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
14838 else if (TREE_PRIVATE (decl))
14839 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
14843 add_AT_flag (var_die, DW_AT_declaration, 1);
14845 if (decl && (DECL_ABSTRACT (decl) || declaration))
14846 equate_decl_number_to_die (decl, var_die);
14849 && (! DECL_ABSTRACT (decl_or_origin)
14850 /* Local static vars are shared between all clones/inlines,
14851 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14853 || (TREE_CODE (decl_or_origin) == VAR_DECL
14854 && TREE_STATIC (decl_or_origin)
14855 && DECL_RTL_SET_P (decl_or_origin)))
14856 /* When abstract origin already has DW_AT_location attribute, no need
14857 to add it again. */
14858 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
14860 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
14861 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
14862 defer_location (decl_or_origin, var_die);
14864 add_location_or_const_value_attribute (var_die,
14867 add_pubname (decl_or_origin, var_die);
14870 tree_add_const_value_attribute (var_die, decl_or_origin);
14873 /* Generate a DIE to represent a named constant. */
14876 gen_const_die (tree decl, dw_die_ref context_die)
14878 dw_die_ref const_die;
14879 tree type = TREE_TYPE (decl);
14881 const_die = new_die (DW_TAG_constant, context_die, decl);
14882 add_name_and_src_coords_attributes (const_die, decl);
14883 add_type_attribute (const_die, type, 1, 0, context_die);
14884 if (TREE_PUBLIC (decl))
14885 add_AT_flag (const_die, DW_AT_external, 1);
14886 if (DECL_ARTIFICIAL (decl))
14887 add_AT_flag (const_die, DW_AT_artificial, 1);
14888 tree_add_const_value_attribute (const_die, decl);
14891 /* Generate a DIE to represent a label identifier. */
14894 gen_label_die (tree decl, dw_die_ref context_die)
14896 tree origin = decl_ultimate_origin (decl);
14897 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
14899 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14901 if (origin != NULL)
14902 add_abstract_origin_attribute (lbl_die, origin);
14904 add_name_and_src_coords_attributes (lbl_die, decl);
14906 if (DECL_ABSTRACT (decl))
14907 equate_decl_number_to_die (decl, lbl_die);
14910 insn = DECL_RTL_IF_SET (decl);
14912 /* Deleted labels are programmer specified labels which have been
14913 eliminated because of various optimizations. We still emit them
14914 here so that it is possible to put breakpoints on them. */
14918 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
14920 /* When optimization is enabled (via -O) some parts of the compiler
14921 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14922 represent source-level labels which were explicitly declared by
14923 the user. This really shouldn't be happening though, so catch
14924 it if it ever does happen. */
14925 gcc_assert (!INSN_DELETED_P (insn));
14927 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
14928 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
14933 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14934 attributes to the DIE for a block STMT, to describe where the inlined
14935 function was called from. This is similar to add_src_coords_attributes. */
14938 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
14940 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
14942 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
14943 add_AT_unsigned (die, DW_AT_call_line, s.line);
14947 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14948 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14951 add_high_low_attributes (tree stmt, dw_die_ref die)
14953 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14955 if (BLOCK_FRAGMENT_CHAIN (stmt))
14959 if (inlined_function_outer_scope_p (stmt))
14961 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14962 BLOCK_NUMBER (stmt));
14963 add_AT_lbl_id (die, DW_AT_entry_pc, label);
14966 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
14968 chain = BLOCK_FRAGMENT_CHAIN (stmt);
14971 add_ranges (chain);
14972 chain = BLOCK_FRAGMENT_CHAIN (chain);
14979 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14980 BLOCK_NUMBER (stmt));
14981 add_AT_lbl_id (die, DW_AT_low_pc, label);
14982 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
14983 BLOCK_NUMBER (stmt));
14984 add_AT_lbl_id (die, DW_AT_high_pc, label);
14988 /* Generate a DIE for a lexical block. */
14991 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
14993 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
14995 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
14996 add_high_low_attributes (stmt, stmt_die);
14998 decls_for_scope (stmt, stmt_die, depth);
15001 /* Generate a DIE for an inlined subprogram. */
15004 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
15008 /* The instance of function that is effectively being inlined shall not
15010 gcc_assert (! BLOCK_ABSTRACT (stmt));
15012 decl = block_ultimate_origin (stmt);
15014 /* Emit info for the abstract instance first, if we haven't yet. We
15015 must emit this even if the block is abstract, otherwise when we
15016 emit the block below (or elsewhere), we may end up trying to emit
15017 a die whose origin die hasn't been emitted, and crashing. */
15018 dwarf2out_abstract_function (decl);
15020 if (! BLOCK_ABSTRACT (stmt))
15022 dw_die_ref subr_die
15023 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
15025 add_abstract_origin_attribute (subr_die, decl);
15026 if (TREE_ASM_WRITTEN (stmt))
15027 add_high_low_attributes (stmt, subr_die);
15028 add_call_src_coords_attributes (stmt, subr_die);
15030 decls_for_scope (stmt, subr_die, depth);
15031 current_function_has_inlines = 1;
15035 /* Generate a DIE for a field in a record, or structure. */
15038 gen_field_die (tree decl, dw_die_ref context_die)
15040 dw_die_ref decl_die;
15042 if (TREE_TYPE (decl) == error_mark_node)
15045 decl_die = new_die (DW_TAG_member, context_die, decl);
15046 add_name_and_src_coords_attributes (decl_die, decl);
15047 add_type_attribute (decl_die, member_declared_type (decl),
15048 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
15051 if (DECL_BIT_FIELD_TYPE (decl))
15053 add_byte_size_attribute (decl_die, decl);
15054 add_bit_size_attribute (decl_die, decl);
15055 add_bit_offset_attribute (decl_die, decl);
15058 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
15059 add_data_member_location_attribute (decl_die, decl);
15061 if (DECL_ARTIFICIAL (decl))
15062 add_AT_flag (decl_die, DW_AT_artificial, 1);
15064 if (TREE_PROTECTED (decl))
15065 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
15066 else if (TREE_PRIVATE (decl))
15067 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
15069 /* Equate decl number to die, so that we can look up this decl later on. */
15070 equate_decl_number_to_die (decl, decl_die);
15074 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
15075 Use modified_type_die instead.
15076 We keep this code here just in case these types of DIEs may be needed to
15077 represent certain things in other languages (e.g. Pascal) someday. */
15080 gen_pointer_type_die (tree type, dw_die_ref context_die)
15083 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
15085 equate_type_number_to_die (type, ptr_die);
15086 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
15087 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
15090 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
15091 Use modified_type_die instead.
15092 We keep this code here just in case these types of DIEs may be needed to
15093 represent certain things in other languages (e.g. Pascal) someday. */
15096 gen_reference_type_die (tree type, dw_die_ref context_die)
15099 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
15101 equate_type_number_to_die (type, ref_die);
15102 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
15103 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
15107 /* Generate a DIE for a pointer to a member type. */
15110 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
15113 = new_die (DW_TAG_ptr_to_member_type,
15114 scope_die_for (type, context_die), type);
15116 equate_type_number_to_die (type, ptr_die);
15117 add_AT_die_ref (ptr_die, DW_AT_containing_type,
15118 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
15119 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
15122 /* Generate the DIE for the compilation unit. */
15125 gen_compile_unit_die (const char *filename)
15128 char producer[250];
15129 const char *language_string = lang_hooks.name;
15132 die = new_die (DW_TAG_compile_unit, NULL, NULL);
15136 add_name_attribute (die, filename);
15137 /* Don't add cwd for <built-in>. */
15138 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
15139 add_comp_dir_attribute (die);
15142 sprintf (producer, "%s %s", language_string, version_string);
15144 #ifdef MIPS_DEBUGGING_INFO
15145 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
15146 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
15147 not appear in the producer string, the debugger reaches the conclusion
15148 that the object file is stripped and has no debugging information.
15149 To get the MIPS/SGI debugger to believe that there is debugging
15150 information in the object file, we add a -g to the producer string. */
15151 if (debug_info_level > DINFO_LEVEL_TERSE)
15152 strcat (producer, " -g");
15155 add_AT_string (die, DW_AT_producer, producer);
15157 if (strcmp (language_string, "GNU C++") == 0)
15158 language = DW_LANG_C_plus_plus;
15159 else if (strcmp (language_string, "GNU Ada") == 0)
15160 language = DW_LANG_Ada95;
15161 else if (strcmp (language_string, "GNU F77") == 0)
15162 language = DW_LANG_Fortran77;
15163 else if (strcmp (language_string, "GNU Fortran") == 0)
15164 language = DW_LANG_Fortran95;
15165 else if (strcmp (language_string, "GNU Pascal") == 0)
15166 language = DW_LANG_Pascal83;
15167 else if (strcmp (language_string, "GNU Java") == 0)
15168 language = DW_LANG_Java;
15169 else if (strcmp (language_string, "GNU Objective-C") == 0)
15170 language = DW_LANG_ObjC;
15171 else if (strcmp (language_string, "GNU Objective-C++") == 0)
15172 language = DW_LANG_ObjC_plus_plus;
15174 language = DW_LANG_C89;
15176 add_AT_unsigned (die, DW_AT_language, language);
15180 /* Generate the DIE for a base class. */
15183 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
15185 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
15187 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
15188 add_data_member_location_attribute (die, binfo);
15190 if (BINFO_VIRTUAL_P (binfo))
15191 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
15193 if (access == access_public_node)
15194 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
15195 else if (access == access_protected_node)
15196 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
15199 /* Generate a DIE for a class member. */
15202 gen_member_die (tree type, dw_die_ref context_die)
15205 tree binfo = TYPE_BINFO (type);
15208 /* If this is not an incomplete type, output descriptions of each of its
15209 members. Note that as we output the DIEs necessary to represent the
15210 members of this record or union type, we will also be trying to output
15211 DIEs to represent the *types* of those members. However the `type'
15212 function (above) will specifically avoid generating type DIEs for member
15213 types *within* the list of member DIEs for this (containing) type except
15214 for those types (of members) which are explicitly marked as also being
15215 members of this (containing) type themselves. The g++ front- end can
15216 force any given type to be treated as a member of some other (containing)
15217 type by setting the TYPE_CONTEXT of the given (member) type to point to
15218 the TREE node representing the appropriate (containing) type. */
15220 /* First output info about the base classes. */
15223 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
15227 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
15228 gen_inheritance_die (base,
15229 (accesses ? VEC_index (tree, accesses, i)
15230 : access_public_node), context_die);
15233 /* Now output info about the data members and type members. */
15234 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
15236 /* If we thought we were generating minimal debug info for TYPE
15237 and then changed our minds, some of the member declarations
15238 may have already been defined. Don't define them again, but
15239 do put them in the right order. */
15241 child = lookup_decl_die (member);
15243 splice_child_die (context_die, child);
15245 gen_decl_die (member, NULL, context_die);
15248 /* Now output info about the function members (if any). */
15249 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
15251 /* Don't include clones in the member list. */
15252 if (DECL_ABSTRACT_ORIGIN (member))
15255 child = lookup_decl_die (member);
15257 splice_child_die (context_die, child);
15259 gen_decl_die (member, NULL, context_die);
15263 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
15264 is set, we pretend that the type was never defined, so we only get the
15265 member DIEs needed by later specification DIEs. */
15268 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
15269 enum debug_info_usage usage)
15271 dw_die_ref type_die = lookup_type_die (type);
15272 dw_die_ref scope_die = 0;
15274 int complete = (TYPE_SIZE (type)
15275 && (! TYPE_STUB_DECL (type)
15276 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
15277 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
15278 complete = complete && should_emit_struct_debug (type, usage);
15280 if (type_die && ! complete)
15283 if (TYPE_CONTEXT (type) != NULL_TREE
15284 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
15285 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
15288 scope_die = scope_die_for (type, context_die);
15290 if (! type_die || (nested && scope_die == comp_unit_die))
15291 /* First occurrence of type or toplevel definition of nested class. */
15293 dw_die_ref old_die = type_die;
15295 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
15296 ? record_type_tag (type) : DW_TAG_union_type,
15298 equate_type_number_to_die (type, type_die);
15300 add_AT_specification (type_die, old_die);
15302 add_name_attribute (type_die, type_tag (type));
15305 remove_AT (type_die, DW_AT_declaration);
15307 /* If this type has been completed, then give it a byte_size attribute and
15308 then give a list of members. */
15309 if (complete && !ns_decl)
15311 /* Prevent infinite recursion in cases where the type of some member of
15312 this type is expressed in terms of this type itself. */
15313 TREE_ASM_WRITTEN (type) = 1;
15314 add_byte_size_attribute (type_die, type);
15315 if (TYPE_STUB_DECL (type) != NULL_TREE)
15316 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
15318 /* If the first reference to this type was as the return type of an
15319 inline function, then it may not have a parent. Fix this now. */
15320 if (type_die->die_parent == NULL)
15321 add_child_die (scope_die, type_die);
15323 push_decl_scope (type);
15324 gen_member_die (type, type_die);
15327 /* GNU extension: Record what type our vtable lives in. */
15328 if (TYPE_VFIELD (type))
15330 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
15332 gen_type_die (vtype, context_die);
15333 add_AT_die_ref (type_die, DW_AT_containing_type,
15334 lookup_type_die (vtype));
15339 add_AT_flag (type_die, DW_AT_declaration, 1);
15341 /* We don't need to do this for function-local types. */
15342 if (TYPE_STUB_DECL (type)
15343 && ! decl_function_context (TYPE_STUB_DECL (type)))
15344 VEC_safe_push (tree, gc, incomplete_types, type);
15347 if (get_AT (type_die, DW_AT_name))
15348 add_pubtype (type, type_die);
15351 /* Generate a DIE for a subroutine _type_. */
15354 gen_subroutine_type_die (tree type, dw_die_ref context_die)
15356 tree return_type = TREE_TYPE (type);
15357 dw_die_ref subr_die
15358 = new_die (DW_TAG_subroutine_type,
15359 scope_die_for (type, context_die), type);
15361 equate_type_number_to_die (type, subr_die);
15362 add_prototyped_attribute (subr_die, type);
15363 add_type_attribute (subr_die, return_type, 0, 0, context_die);
15364 gen_formal_types_die (type, subr_die);
15366 if (get_AT (subr_die, DW_AT_name))
15367 add_pubtype (type, subr_die);
15370 /* Generate a DIE for a type definition. */
15373 gen_typedef_die (tree decl, dw_die_ref context_die)
15375 dw_die_ref type_die;
15378 if (TREE_ASM_WRITTEN (decl))
15381 TREE_ASM_WRITTEN (decl) = 1;
15382 type_die = new_die (DW_TAG_typedef, context_die, decl);
15383 origin = decl_ultimate_origin (decl);
15384 if (origin != NULL)
15385 add_abstract_origin_attribute (type_die, origin);
15390 add_name_and_src_coords_attributes (type_die, decl);
15391 if (DECL_ORIGINAL_TYPE (decl))
15393 type = DECL_ORIGINAL_TYPE (decl);
15395 gcc_assert (type != TREE_TYPE (decl));
15396 equate_type_number_to_die (TREE_TYPE (decl), type_die);
15399 type = TREE_TYPE (decl);
15401 add_type_attribute (type_die, type, TREE_READONLY (decl),
15402 TREE_THIS_VOLATILE (decl), context_die);
15405 if (DECL_ABSTRACT (decl))
15406 equate_decl_number_to_die (decl, type_die);
15408 if (get_AT (type_die, DW_AT_name))
15409 add_pubtype (decl, type_die);
15412 /* Generate a type description DIE. */
15415 gen_type_die_with_usage (tree type, dw_die_ref context_die,
15416 enum debug_info_usage usage)
15419 struct array_descr_info info;
15421 if (type == NULL_TREE || type == error_mark_node)
15424 /* If TYPE is a typedef type variant, let's generate debug info
15425 for the parent typedef which TYPE is a type of. */
15426 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
15427 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
15429 if (TREE_ASM_WRITTEN (type))
15432 /* Prevent broken recursion; we can't hand off to the same type. */
15433 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
15435 /* Use the DIE of the containing namespace as the parent DIE of
15436 the type description DIE we want to generate. */
15437 if (DECL_CONTEXT (TYPE_NAME (type))
15438 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
15439 context_die = lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type)));
15441 TREE_ASM_WRITTEN (type) = 1;
15442 gen_decl_die (TYPE_NAME (type), NULL, context_die);
15446 /* If this is an array type with hidden descriptor, handle it first. */
15447 if (!TREE_ASM_WRITTEN (type)
15448 && lang_hooks.types.get_array_descr_info
15449 && lang_hooks.types.get_array_descr_info (type, &info))
15451 gen_descr_array_type_die (type, &info, context_die);
15452 TREE_ASM_WRITTEN (type) = 1;
15456 /* We are going to output a DIE to represent the unqualified version
15457 of this type (i.e. without any const or volatile qualifiers) so
15458 get the main variant (i.e. the unqualified version) of this type
15459 now. (Vectors are special because the debugging info is in the
15460 cloned type itself). */
15461 if (TREE_CODE (type) != VECTOR_TYPE)
15462 type = type_main_variant (type);
15464 if (TREE_ASM_WRITTEN (type))
15467 switch (TREE_CODE (type))
15473 case REFERENCE_TYPE:
15474 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
15475 ensures that the gen_type_die recursion will terminate even if the
15476 type is recursive. Recursive types are possible in Ada. */
15477 /* ??? We could perhaps do this for all types before the switch
15479 TREE_ASM_WRITTEN (type) = 1;
15481 /* For these types, all that is required is that we output a DIE (or a
15482 set of DIEs) to represent the "basis" type. */
15483 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15484 DINFO_USAGE_IND_USE);
15488 /* This code is used for C++ pointer-to-data-member types.
15489 Output a description of the relevant class type. */
15490 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
15491 DINFO_USAGE_IND_USE);
15493 /* Output a description of the type of the object pointed to. */
15494 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15495 DINFO_USAGE_IND_USE);
15497 /* Now output a DIE to represent this pointer-to-data-member type
15499 gen_ptr_to_mbr_type_die (type, context_die);
15502 case FUNCTION_TYPE:
15503 /* Force out return type (in case it wasn't forced out already). */
15504 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15505 DINFO_USAGE_DIR_USE);
15506 gen_subroutine_type_die (type, context_die);
15510 /* Force out return type (in case it wasn't forced out already). */
15511 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15512 DINFO_USAGE_DIR_USE);
15513 gen_subroutine_type_die (type, context_die);
15517 gen_array_type_die (type, context_die);
15521 gen_array_type_die (type, context_die);
15524 case ENUMERAL_TYPE:
15527 case QUAL_UNION_TYPE:
15528 /* If this is a nested type whose containing class hasn't been written
15529 out yet, writing it out will cover this one, too. This does not apply
15530 to instantiations of member class templates; they need to be added to
15531 the containing class as they are generated. FIXME: This hurts the
15532 idea of combining type decls from multiple TUs, since we can't predict
15533 what set of template instantiations we'll get. */
15534 if (TYPE_CONTEXT (type)
15535 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
15536 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
15538 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
15540 if (TREE_ASM_WRITTEN (type))
15543 /* If that failed, attach ourselves to the stub. */
15544 push_decl_scope (TYPE_CONTEXT (type));
15545 context_die = lookup_type_die (TYPE_CONTEXT (type));
15550 context_die = declare_in_namespace (type, context_die);
15554 if (TREE_CODE (type) == ENUMERAL_TYPE)
15556 /* This might have been written out by the call to
15557 declare_in_namespace. */
15558 if (!TREE_ASM_WRITTEN (type))
15559 gen_enumeration_type_die (type, context_die);
15562 gen_struct_or_union_type_die (type, context_die, usage);
15567 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
15568 it up if it is ever completed. gen_*_type_die will set it for us
15569 when appropriate. */
15575 case FIXED_POINT_TYPE:
15578 /* No DIEs needed for fundamental types. */
15582 /* No Dwarf representation currently defined. */
15586 gcc_unreachable ();
15589 TREE_ASM_WRITTEN (type) = 1;
15593 gen_type_die (tree type, dw_die_ref context_die)
15595 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
15598 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
15599 things which are local to the given block. */
15602 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
15604 int must_output_die = 0;
15607 /* Ignore blocks that are NULL. */
15608 if (stmt == NULL_TREE)
15611 inlined_func = inlined_function_outer_scope_p (stmt);
15613 /* If the block is one fragment of a non-contiguous block, do not
15614 process the variables, since they will have been done by the
15615 origin block. Do process subblocks. */
15616 if (BLOCK_FRAGMENT_ORIGIN (stmt))
15620 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
15621 gen_block_die (sub, context_die, depth + 1);
15626 /* Determine if we need to output any Dwarf DIEs at all to represent this
15629 /* The outer scopes for inlinings *must* always be represented. We
15630 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
15631 must_output_die = 1;
15634 /* Determine if this block directly contains any "significant"
15635 local declarations which we will need to output DIEs for. */
15636 if (debug_info_level > DINFO_LEVEL_TERSE)
15637 /* We are not in terse mode so *any* local declaration counts
15638 as being a "significant" one. */
15639 must_output_die = ((BLOCK_VARS (stmt) != NULL
15640 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
15641 && (TREE_USED (stmt)
15642 || TREE_ASM_WRITTEN (stmt)
15643 || BLOCK_ABSTRACT (stmt)));
15644 else if ((TREE_USED (stmt)
15645 || TREE_ASM_WRITTEN (stmt)
15646 || BLOCK_ABSTRACT (stmt))
15647 && !dwarf2out_ignore_block (stmt))
15648 must_output_die = 1;
15651 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
15652 DIE for any block which contains no significant local declarations at
15653 all. Rather, in such cases we just call `decls_for_scope' so that any
15654 needed Dwarf info for any sub-blocks will get properly generated. Note
15655 that in terse mode, our definition of what constitutes a "significant"
15656 local declaration gets restricted to include only inlined function
15657 instances and local (nested) function definitions. */
15658 if (must_output_die)
15662 /* If STMT block is abstract, that means we have been called
15663 indirectly from dwarf2out_abstract_function.
15664 That function rightfully marks the descendent blocks (of
15665 the abstract function it is dealing with) as being abstract,
15666 precisely to prevent us from emitting any
15667 DW_TAG_inlined_subroutine DIE as a descendent
15668 of an abstract function instance. So in that case, we should
15669 not call gen_inlined_subroutine_die.
15671 Later though, when cgraph asks dwarf2out to emit info
15672 for the concrete instance of the function decl into which
15673 the concrete instance of STMT got inlined, the later will lead
15674 to the generation of a DW_TAG_inlined_subroutine DIE. */
15675 if (! BLOCK_ABSTRACT (stmt))
15676 gen_inlined_subroutine_die (stmt, context_die, depth);
15679 gen_lexical_block_die (stmt, context_die, depth);
15682 decls_for_scope (stmt, context_die, depth);
15685 /* Process variable DECL (or variable with origin ORIGIN) within
15686 block STMT and add it to CONTEXT_DIE. */
15688 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
15691 tree decl_or_origin = decl ? decl : origin;
15692 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
15694 if (ultimate_origin)
15695 origin = ultimate_origin;
15697 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
15698 die = lookup_decl_die (decl_or_origin);
15699 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
15700 && TYPE_DECL_IS_STUB (decl_or_origin))
15701 die = lookup_type_die (TREE_TYPE (decl_or_origin));
15705 if (die != NULL && die->die_parent == NULL)
15706 add_child_die (context_die, die);
15707 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
15708 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
15709 stmt, context_die);
15711 gen_decl_die (decl, origin, context_die);
15714 /* Generate all of the decls declared within a given scope and (recursively)
15715 all of its sub-blocks. */
15718 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
15724 /* Ignore NULL blocks. */
15725 if (stmt == NULL_TREE)
15728 /* Output the DIEs to represent all of the data objects and typedefs
15729 declared directly within this block but not within any nested
15730 sub-blocks. Also, nested function and tag DIEs have been
15731 generated with a parent of NULL; fix that up now. */
15732 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
15733 process_scope_var (stmt, decl, NULL_TREE, context_die);
15734 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
15735 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
15738 /* If we're at -g1, we're not interested in subblocks. */
15739 if (debug_info_level <= DINFO_LEVEL_TERSE)
15742 /* Output the DIEs to represent all sub-blocks (and the items declared
15743 therein) of this block. */
15744 for (subblocks = BLOCK_SUBBLOCKS (stmt);
15746 subblocks = BLOCK_CHAIN (subblocks))
15747 gen_block_die (subblocks, context_die, depth + 1);
15750 /* Is this a typedef we can avoid emitting? */
15753 is_redundant_typedef (const_tree decl)
15755 if (TYPE_DECL_IS_STUB (decl))
15758 if (DECL_ARTIFICIAL (decl)
15759 && DECL_CONTEXT (decl)
15760 && is_tagged_type (DECL_CONTEXT (decl))
15761 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
15762 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
15763 /* Also ignore the artificial member typedef for the class name. */
15769 /* Returns the DIE for a context. */
15771 static inline dw_die_ref
15772 get_context_die (tree context)
15776 /* Find die that represents this context. */
15777 if (TYPE_P (context))
15778 return force_type_die (context);
15780 return force_decl_die (context);
15782 return comp_unit_die;
15785 /* Returns the DIE for decl. A DIE will always be returned. */
15788 force_decl_die (tree decl)
15790 dw_die_ref decl_die;
15791 unsigned saved_external_flag;
15792 tree save_fn = NULL_TREE;
15793 decl_die = lookup_decl_die (decl);
15796 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
15798 decl_die = lookup_decl_die (decl);
15802 switch (TREE_CODE (decl))
15804 case FUNCTION_DECL:
15805 /* Clear current_function_decl, so that gen_subprogram_die thinks
15806 that this is a declaration. At this point, we just want to force
15807 declaration die. */
15808 save_fn = current_function_decl;
15809 current_function_decl = NULL_TREE;
15810 gen_subprogram_die (decl, context_die);
15811 current_function_decl = save_fn;
15815 /* Set external flag to force declaration die. Restore it after
15816 gen_decl_die() call. */
15817 saved_external_flag = DECL_EXTERNAL (decl);
15818 DECL_EXTERNAL (decl) = 1;
15819 gen_decl_die (decl, NULL, context_die);
15820 DECL_EXTERNAL (decl) = saved_external_flag;
15823 case NAMESPACE_DECL:
15824 dwarf2out_decl (decl);
15828 gcc_unreachable ();
15831 /* We should be able to find the DIE now. */
15833 decl_die = lookup_decl_die (decl);
15834 gcc_assert (decl_die);
15840 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15841 always returned. */
15844 force_type_die (tree type)
15846 dw_die_ref type_die;
15848 type_die = lookup_type_die (type);
15851 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
15853 type_die = modified_type_die (type, TYPE_READONLY (type),
15854 TYPE_VOLATILE (type), context_die);
15855 gcc_assert (type_die);
15860 /* Force out any required namespaces to be able to output DECL,
15861 and return the new context_die for it, if it's changed. */
15864 setup_namespace_context (tree thing, dw_die_ref context_die)
15866 tree context = (DECL_P (thing)
15867 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
15868 if (context && TREE_CODE (context) == NAMESPACE_DECL)
15869 /* Force out the namespace. */
15870 context_die = force_decl_die (context);
15872 return context_die;
15875 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15876 type) within its namespace, if appropriate.
15878 For compatibility with older debuggers, namespace DIEs only contain
15879 declarations; all definitions are emitted at CU scope. */
15882 declare_in_namespace (tree thing, dw_die_ref context_die)
15884 dw_die_ref ns_context;
15886 if (debug_info_level <= DINFO_LEVEL_TERSE)
15887 return context_die;
15889 /* If this decl is from an inlined function, then don't try to emit it in its
15890 namespace, as we will get confused. It would have already been emitted
15891 when the abstract instance of the inline function was emitted anyways. */
15892 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
15893 return context_die;
15895 ns_context = setup_namespace_context (thing, context_die);
15897 if (ns_context != context_die)
15901 if (DECL_P (thing))
15902 gen_decl_die (thing, NULL, ns_context);
15904 gen_type_die (thing, ns_context);
15906 return context_die;
15909 /* Generate a DIE for a namespace or namespace alias. */
15912 gen_namespace_die (tree decl, dw_die_ref context_die)
15914 dw_die_ref namespace_die;
15916 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15917 they are an alias of. */
15918 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
15920 /* Output a real namespace or module. */
15921 context_die = setup_namespace_context (decl, comp_unit_die);
15922 namespace_die = new_die (is_fortran ()
15923 ? DW_TAG_module : DW_TAG_namespace,
15924 context_die, decl);
15925 /* For Fortran modules defined in different CU don't add src coords. */
15926 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
15927 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
15929 add_name_and_src_coords_attributes (namespace_die, decl);
15930 if (DECL_EXTERNAL (decl))
15931 add_AT_flag (namespace_die, DW_AT_declaration, 1);
15932 equate_decl_number_to_die (decl, namespace_die);
15936 /* Output a namespace alias. */
15938 /* Force out the namespace we are an alias of, if necessary. */
15939 dw_die_ref origin_die
15940 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
15942 if (DECL_CONTEXT (decl) == NULL_TREE
15943 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
15944 context_die = setup_namespace_context (decl, comp_unit_die);
15945 /* Now create the namespace alias DIE. */
15946 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
15947 add_name_and_src_coords_attributes (namespace_die, decl);
15948 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
15949 equate_decl_number_to_die (decl, namespace_die);
15953 /* Generate Dwarf debug information for a decl described by DECL. */
15956 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
15958 tree decl_or_origin = decl ? decl : origin;
15959 tree class_origin = NULL;
15961 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
15964 switch (TREE_CODE (decl_or_origin))
15970 if (!is_fortran ())
15972 /* The individual enumerators of an enum type get output when we output
15973 the Dwarf representation of the relevant enum type itself. */
15977 /* Emit its type. */
15978 gen_type_die (TREE_TYPE (decl), context_die);
15980 /* And its containing namespace. */
15981 context_die = declare_in_namespace (decl, context_die);
15983 gen_const_die (decl, context_die);
15986 case FUNCTION_DECL:
15987 /* Don't output any DIEs to represent mere function declarations,
15988 unless they are class members or explicit block externs. */
15989 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
15990 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
15991 && (current_function_decl == NULL_TREE
15992 || DECL_ARTIFICIAL (decl_or_origin)))
15997 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15998 on local redeclarations of global functions. That seems broken. */
15999 if (current_function_decl != decl)
16000 /* This is only a declaration. */;
16003 /* If we're emitting a clone, emit info for the abstract instance. */
16004 if (origin || DECL_ORIGIN (decl) != decl)
16005 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
16007 /* If we're emitting an out-of-line copy of an inline function,
16008 emit info for the abstract instance and set up to refer to it. */
16009 else if (cgraph_function_possibly_inlined_p (decl)
16010 && ! DECL_ABSTRACT (decl)
16011 && ! class_or_namespace_scope_p (context_die)
16012 /* dwarf2out_abstract_function won't emit a die if this is just
16013 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
16014 that case, because that works only if we have a die. */
16015 && DECL_INITIAL (decl) != NULL_TREE)
16017 dwarf2out_abstract_function (decl);
16018 set_decl_origin_self (decl);
16021 /* Otherwise we're emitting the primary DIE for this decl. */
16022 else if (debug_info_level > DINFO_LEVEL_TERSE)
16024 /* Before we describe the FUNCTION_DECL itself, make sure that we
16025 have described its return type. */
16026 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
16028 /* And its virtual context. */
16029 if (DECL_VINDEX (decl) != NULL_TREE)
16030 gen_type_die (DECL_CONTEXT (decl), context_die);
16032 /* And its containing type. */
16034 origin = decl_class_context (decl);
16035 if (origin != NULL_TREE)
16036 gen_type_die_for_member (origin, decl, context_die);
16038 /* And its containing namespace. */
16039 context_die = declare_in_namespace (decl, context_die);
16042 /* Now output a DIE to represent the function itself. */
16044 gen_subprogram_die (decl, context_die);
16048 /* If we are in terse mode, don't generate any DIEs to represent any
16049 actual typedefs. */
16050 if (debug_info_level <= DINFO_LEVEL_TERSE)
16053 /* In the special case of a TYPE_DECL node representing the declaration
16054 of some type tag, if the given TYPE_DECL is marked as having been
16055 instantiated from some other (original) TYPE_DECL node (e.g. one which
16056 was generated within the original definition of an inline function) we
16057 used to generate a special (abbreviated) DW_TAG_structure_type,
16058 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
16059 should be actually referencing those DIEs, as variable DIEs with that
16060 type would be emitted already in the abstract origin, so it was always
16061 removed during unused type prunning. Don't add anything in this
16063 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
16066 if (is_redundant_typedef (decl))
16067 gen_type_die (TREE_TYPE (decl), context_die);
16069 /* Output a DIE to represent the typedef itself. */
16070 gen_typedef_die (decl, context_die);
16074 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16075 gen_label_die (decl, context_die);
16080 /* If we are in terse mode, don't generate any DIEs to represent any
16081 variable declarations or definitions. */
16082 if (debug_info_level <= DINFO_LEVEL_TERSE)
16085 /* Output any DIEs that are needed to specify the type of this data
16087 if ((TREE_CODE (decl_or_origin) == RESULT_DECL
16088 || TREE_CODE (decl_or_origin) == VAR_DECL)
16089 && DECL_BY_REFERENCE (decl_or_origin))
16090 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
16092 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
16094 /* And its containing type. */
16095 class_origin = decl_class_context (decl_or_origin);
16096 if (class_origin != NULL_TREE)
16097 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
16099 /* And its containing namespace. */
16100 context_die = declare_in_namespace (decl_or_origin, context_die);
16102 /* Now output the DIE to represent the data object itself. This gets
16103 complicated because of the possibility that the VAR_DECL really
16104 represents an inlined instance of a formal parameter for an inline
16107 origin = decl_ultimate_origin (decl);
16108 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
16109 gen_formal_parameter_die (decl, origin, context_die);
16111 gen_variable_die (decl, origin, context_die);
16115 /* Ignore the nameless fields that are used to skip bits but handle C++
16116 anonymous unions and structs. */
16117 if (DECL_NAME (decl) != NULL_TREE
16118 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
16119 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
16121 gen_type_die (member_declared_type (decl), context_die);
16122 gen_field_die (decl, context_die);
16127 if (DECL_BY_REFERENCE (decl_or_origin))
16128 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
16130 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
16131 gen_formal_parameter_die (decl, origin, context_die);
16134 case NAMESPACE_DECL:
16135 case IMPORTED_DECL:
16136 gen_namespace_die (decl, context_die);
16140 /* Probably some frontend-internal decl. Assume we don't care. */
16141 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
16146 /* Output debug information for global decl DECL. Called from toplev.c after
16147 compilation proper has finished. */
16150 dwarf2out_global_decl (tree decl)
16152 /* Output DWARF2 information for file-scope tentative data object
16153 declarations, file-scope (extern) function declarations (which
16154 had no corresponding body) and file-scope tagged type declarations
16155 and definitions which have not yet been forced out. */
16156 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
16157 dwarf2out_decl (decl);
16160 /* Output debug information for type decl DECL. Called from toplev.c
16161 and from language front ends (to record built-in types). */
16163 dwarf2out_type_decl (tree decl, int local)
16166 dwarf2out_decl (decl);
16169 /* Output debug information for imported module or decl DECL.
16170 NAME is non-NULL name in the lexical block if the decl has been renamed.
16171 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
16172 that DECL belongs to.
16173 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
16175 dwarf2out_imported_module_or_decl_1 (tree decl,
16177 tree lexical_block,
16178 dw_die_ref lexical_block_die)
16180 expanded_location xloc;
16181 dw_die_ref imported_die = NULL;
16182 dw_die_ref at_import_die;
16184 if (TREE_CODE (decl) == IMPORTED_DECL)
16186 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
16187 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
16191 xloc = expand_location (input_location);
16193 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
16195 if (is_base_type (TREE_TYPE (decl)))
16196 at_import_die = base_type_die (TREE_TYPE (decl));
16198 at_import_die = force_type_die (TREE_TYPE (decl));
16199 /* For namespace N { typedef void T; } using N::T; base_type_die
16200 returns NULL, but DW_TAG_imported_declaration requires
16201 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
16202 if (!at_import_die)
16204 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
16205 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
16206 at_import_die = lookup_type_die (TREE_TYPE (decl));
16207 gcc_assert (at_import_die);
16212 at_import_die = lookup_decl_die (decl);
16213 if (!at_import_die)
16215 /* If we're trying to avoid duplicate debug info, we may not have
16216 emitted the member decl for this field. Emit it now. */
16217 if (TREE_CODE (decl) == FIELD_DECL)
16219 tree type = DECL_CONTEXT (decl);
16221 if (TYPE_CONTEXT (type)
16222 && TYPE_P (TYPE_CONTEXT (type))
16223 && !should_emit_struct_debug (TYPE_CONTEXT (type),
16224 DINFO_USAGE_DIR_USE))
16226 gen_type_die_for_member (type, decl,
16227 get_context_die (TYPE_CONTEXT (type)));
16229 at_import_die = force_decl_die (decl);
16233 if (TREE_CODE (decl) == NAMESPACE_DECL)
16234 imported_die = new_die (DW_TAG_imported_module,
16238 imported_die = new_die (DW_TAG_imported_declaration,
16242 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
16243 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
16245 add_AT_string (imported_die, DW_AT_name,
16246 IDENTIFIER_POINTER (name));
16247 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
16250 /* Output debug information for imported module or decl DECL.
16251 NAME is non-NULL name in context if the decl has been renamed.
16252 CHILD is true if decl is one of the renamed decls as part of
16253 importing whole module. */
16256 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
16259 /* dw_die_ref at_import_die; */
16260 dw_die_ref scope_die;
16262 if (debug_info_level <= DINFO_LEVEL_TERSE)
16267 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
16268 We need decl DIE for reference and scope die. First, get DIE for the decl
16271 /* Get the scope die for decl context. Use comp_unit_die for global module
16272 or decl. If die is not found for non globals, force new die. */
16274 && TYPE_P (context)
16275 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
16277 scope_die = get_context_die (context);
16281 gcc_assert (scope_die->die_child);
16282 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
16283 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
16284 scope_die = scope_die->die_child;
16287 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
16288 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
16292 /* Write the debugging output for DECL. */
16295 dwarf2out_decl (tree decl)
16297 dw_die_ref context_die = comp_unit_die;
16299 switch (TREE_CODE (decl))
16304 case FUNCTION_DECL:
16305 /* What we would really like to do here is to filter out all mere
16306 file-scope declarations of file-scope functions which are never
16307 referenced later within this translation unit (and keep all of ones
16308 that *are* referenced later on) but we aren't clairvoyant, so we have
16309 no idea which functions will be referenced in the future (i.e. later
16310 on within the current translation unit). So here we just ignore all
16311 file-scope function declarations which are not also definitions. If
16312 and when the debugger needs to know something about these functions,
16313 it will have to hunt around and find the DWARF information associated
16314 with the definition of the function.
16316 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
16317 nodes represent definitions and which ones represent mere
16318 declarations. We have to check DECL_INITIAL instead. That's because
16319 the C front-end supports some weird semantics for "extern inline"
16320 function definitions. These can get inlined within the current
16321 translation unit (and thus, we need to generate Dwarf info for their
16322 abstract instances so that the Dwarf info for the concrete inlined
16323 instances can have something to refer to) but the compiler never
16324 generates any out-of-lines instances of such things (despite the fact
16325 that they *are* definitions).
16327 The important point is that the C front-end marks these "extern
16328 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
16329 them anyway. Note that the C++ front-end also plays some similar games
16330 for inline function definitions appearing within include files which
16331 also contain `#pragma interface' pragmas. */
16332 if (DECL_INITIAL (decl) == NULL_TREE)
16335 /* If we're a nested function, initially use a parent of NULL; if we're
16336 a plain function, this will be fixed up in decls_for_scope. If
16337 we're a method, it will be ignored, since we already have a DIE. */
16338 if (decl_function_context (decl)
16339 /* But if we're in terse mode, we don't care about scope. */
16340 && debug_info_level > DINFO_LEVEL_TERSE)
16341 context_die = NULL;
16345 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
16346 declaration and if the declaration was never even referenced from
16347 within this entire compilation unit. We suppress these DIEs in
16348 order to save space in the .debug section (by eliminating entries
16349 which are probably useless). Note that we must not suppress
16350 block-local extern declarations (whether used or not) because that
16351 would screw-up the debugger's name lookup mechanism and cause it to
16352 miss things which really ought to be in scope at a given point. */
16353 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
16356 /* For local statics lookup proper context die. */
16357 if (TREE_STATIC (decl) && decl_function_context (decl))
16358 context_die = lookup_decl_die (DECL_CONTEXT (decl));
16360 /* If we are in terse mode, don't generate any DIEs to represent any
16361 variable declarations or definitions. */
16362 if (debug_info_level <= DINFO_LEVEL_TERSE)
16367 if (debug_info_level <= DINFO_LEVEL_TERSE)
16369 if (!is_fortran ())
16371 if (TREE_STATIC (decl) && decl_function_context (decl))
16372 context_die = lookup_decl_die (DECL_CONTEXT (decl));
16375 case NAMESPACE_DECL:
16376 case IMPORTED_DECL:
16377 if (debug_info_level <= DINFO_LEVEL_TERSE)
16379 if (lookup_decl_die (decl) != NULL)
16384 /* Don't emit stubs for types unless they are needed by other DIEs. */
16385 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
16388 /* Don't bother trying to generate any DIEs to represent any of the
16389 normal built-in types for the language we are compiling. */
16390 if (DECL_IS_BUILTIN (decl))
16392 /* OK, we need to generate one for `bool' so GDB knows what type
16393 comparisons have. */
16395 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
16396 && ! DECL_IGNORED_P (decl))
16397 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
16402 /* If we are in terse mode, don't generate any DIEs for types. */
16403 if (debug_info_level <= DINFO_LEVEL_TERSE)
16406 /* If we're a function-scope tag, initially use a parent of NULL;
16407 this will be fixed up in decls_for_scope. */
16408 if (decl_function_context (decl))
16409 context_die = NULL;
16417 gen_decl_die (decl, NULL, context_die);
16420 /* Output a marker (i.e. a label) for the beginning of the generated code for
16421 a lexical block. */
16424 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
16425 unsigned int blocknum)
16427 switch_to_section (current_function_section ());
16428 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
16431 /* Output a marker (i.e. a label) for the end of the generated code for a
16435 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
16437 switch_to_section (current_function_section ());
16438 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
16441 /* Returns nonzero if it is appropriate not to emit any debugging
16442 information for BLOCK, because it doesn't contain any instructions.
16444 Don't allow this for blocks with nested functions or local classes
16445 as we would end up with orphans, and in the presence of scheduling
16446 we may end up calling them anyway. */
16449 dwarf2out_ignore_block (const_tree block)
16454 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
16455 if (TREE_CODE (decl) == FUNCTION_DECL
16456 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
16458 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
16460 decl = BLOCK_NONLOCALIZED_VAR (block, i);
16461 if (TREE_CODE (decl) == FUNCTION_DECL
16462 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
16469 /* Hash table routines for file_hash. */
16472 file_table_eq (const void *p1_p, const void *p2_p)
16474 const struct dwarf_file_data *const p1 =
16475 (const struct dwarf_file_data *) p1_p;
16476 const char *const p2 = (const char *) p2_p;
16477 return strcmp (p1->filename, p2) == 0;
16481 file_table_hash (const void *p_p)
16483 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
16484 return htab_hash_string (p->filename);
16487 /* Lookup FILE_NAME (in the list of filenames that we know about here in
16488 dwarf2out.c) and return its "index". The index of each (known) filename is
16489 just a unique number which is associated with only that one filename. We
16490 need such numbers for the sake of generating labels (in the .debug_sfnames
16491 section) and references to those files numbers (in the .debug_srcinfo
16492 and.debug_macinfo sections). If the filename given as an argument is not
16493 found in our current list, add it to the list and assign it the next
16494 available unique index number. In order to speed up searches, we remember
16495 the index of the filename was looked up last. This handles the majority of
16498 static struct dwarf_file_data *
16499 lookup_filename (const char *file_name)
16502 struct dwarf_file_data * created;
16504 /* Check to see if the file name that was searched on the previous
16505 call matches this file name. If so, return the index. */
16506 if (file_table_last_lookup
16507 && (file_name == file_table_last_lookup->filename
16508 || strcmp (file_table_last_lookup->filename, file_name) == 0))
16509 return file_table_last_lookup;
16511 /* Didn't match the previous lookup, search the table. */
16512 slot = htab_find_slot_with_hash (file_table, file_name,
16513 htab_hash_string (file_name), INSERT);
16515 return (struct dwarf_file_data *) *slot;
16517 created = GGC_NEW (struct dwarf_file_data);
16518 created->filename = file_name;
16519 created->emitted_number = 0;
16524 /* If the assembler will construct the file table, then translate the compiler
16525 internal file table number into the assembler file table number, and emit
16526 a .file directive if we haven't already emitted one yet. The file table
16527 numbers are different because we prune debug info for unused variables and
16528 types, which may include filenames. */
16531 maybe_emit_file (struct dwarf_file_data * fd)
16533 if (! fd->emitted_number)
16535 if (last_emitted_file)
16536 fd->emitted_number = last_emitted_file->emitted_number + 1;
16538 fd->emitted_number = 1;
16539 last_emitted_file = fd;
16541 if (DWARF2_ASM_LINE_DEBUG_INFO)
16543 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
16544 output_quoted_string (asm_out_file,
16545 remap_debug_filename (fd->filename));
16546 fputc ('\n', asm_out_file);
16550 return fd->emitted_number;
16553 /* Replace DW_AT_name for the decl with name. */
16556 dwarf2out_set_name (tree decl, tree name)
16561 die = TYPE_SYMTAB_DIE (decl);
16565 attr = get_AT (die, DW_AT_name);
16568 struct indirect_string_node *node;
16570 node = find_AT_string (dwarf2_name (name, 0));
16571 /* replace the string. */
16572 attr->dw_attr_val.v.val_str = node;
16576 add_name_attribute (die, dwarf2_name (name, 0));
16579 /* Called by the final INSN scan whenever we see a var location. We
16580 use it to drop labels in the right places, and throw the location in
16581 our lookup table. */
16584 dwarf2out_var_location (rtx loc_note)
16586 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
16587 struct var_loc_node *newloc;
16589 static const char *last_label;
16590 static bool last_in_cold_section_p;
16593 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
16596 next_real = next_real_insn (loc_note);
16597 /* If there are no instructions which would be affected by this note,
16598 don't do anything. */
16599 if (next_real == NULL_RTX)
16602 newloc = GGC_CNEW (struct var_loc_node);
16603 /* If there were no real insns between note we processed last time
16604 and this note, use the label we emitted last time. */
16605 if (last_var_location_insn != NULL_RTX
16606 && last_var_location_insn == next_real
16607 && last_in_cold_section_p == in_cold_section_p)
16608 newloc->label = last_label;
16611 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
16612 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
16614 newloc->label = ggc_strdup (loclabel);
16616 newloc->var_loc_note = loc_note;
16617 newloc->next = NULL;
16619 if (cfun && in_cold_section_p)
16620 newloc->section_label = crtl->subsections.cold_section_label;
16622 newloc->section_label = text_section_label;
16624 last_var_location_insn = next_real;
16625 last_label = newloc->label;
16626 last_in_cold_section_p = in_cold_section_p;
16627 decl = NOTE_VAR_LOCATION_DECL (loc_note);
16628 add_var_loc_to_decl (decl, newloc);
16631 /* We need to reset the locations at the beginning of each
16632 function. We can't do this in the end_function hook, because the
16633 declarations that use the locations won't have been output when
16634 that hook is called. Also compute have_multiple_function_sections here. */
16637 dwarf2out_begin_function (tree fun)
16639 htab_empty (decl_loc_table);
16641 if (function_section (fun) != text_section)
16642 have_multiple_function_sections = true;
16644 dwarf2out_note_section_used ();
16647 /* Output a label to mark the beginning of a source code line entry
16648 and record information relating to this source line, in
16649 'line_info_table' for later output of the .debug_line section. */
16652 dwarf2out_source_line (unsigned int line, const char *filename,
16653 int discriminator, bool is_stmt)
16655 static bool last_is_stmt = true;
16657 if (debug_info_level >= DINFO_LEVEL_NORMAL
16660 int file_num = maybe_emit_file (lookup_filename (filename));
16662 switch_to_section (current_function_section ());
16664 /* If requested, emit something human-readable. */
16665 if (flag_debug_asm)
16666 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
16669 if (DWARF2_ASM_LINE_DEBUG_INFO)
16671 /* Emit the .loc directive understood by GNU as. */
16672 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
16673 if (is_stmt != last_is_stmt)
16675 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
16676 last_is_stmt = is_stmt;
16678 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
16679 fprintf (asm_out_file, " discriminator %d", discriminator);
16680 fputc ('\n', asm_out_file);
16682 /* Indicate that line number info exists. */
16683 line_info_table_in_use++;
16685 else if (function_section (current_function_decl) != text_section)
16687 dw_separate_line_info_ref line_info;
16688 targetm.asm_out.internal_label (asm_out_file,
16689 SEPARATE_LINE_CODE_LABEL,
16690 separate_line_info_table_in_use);
16692 /* Expand the line info table if necessary. */
16693 if (separate_line_info_table_in_use
16694 == separate_line_info_table_allocated)
16696 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16697 separate_line_info_table
16698 = GGC_RESIZEVEC (dw_separate_line_info_entry,
16699 separate_line_info_table,
16700 separate_line_info_table_allocated);
16701 memset (separate_line_info_table
16702 + separate_line_info_table_in_use,
16704 (LINE_INFO_TABLE_INCREMENT
16705 * sizeof (dw_separate_line_info_entry)));
16708 /* Add the new entry at the end of the line_info_table. */
16710 = &separate_line_info_table[separate_line_info_table_in_use++];
16711 line_info->dw_file_num = file_num;
16712 line_info->dw_line_num = line;
16713 line_info->function = current_function_funcdef_no;
16717 dw_line_info_ref line_info;
16719 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
16720 line_info_table_in_use);
16722 /* Expand the line info table if necessary. */
16723 if (line_info_table_in_use == line_info_table_allocated)
16725 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16727 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
16728 line_info_table_allocated);
16729 memset (line_info_table + line_info_table_in_use, 0,
16730 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
16733 /* Add the new entry at the end of the line_info_table. */
16734 line_info = &line_info_table[line_info_table_in_use++];
16735 line_info->dw_file_num = file_num;
16736 line_info->dw_line_num = line;
16741 /* Record the beginning of a new source file. */
16744 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
16746 if (flag_eliminate_dwarf2_dups)
16748 /* Record the beginning of the file for break_out_includes. */
16749 dw_die_ref bincl_die;
16751 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
16752 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
16755 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16757 int file_num = maybe_emit_file (lookup_filename (filename));
16759 switch_to_section (debug_macinfo_section);
16760 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
16761 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
16764 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
16768 /* Record the end of a source file. */
16771 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
16773 if (flag_eliminate_dwarf2_dups)
16774 /* Record the end of the file for break_out_includes. */
16775 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
16777 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16779 switch_to_section (debug_macinfo_section);
16780 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
16784 /* Called from debug_define in toplev.c. The `buffer' parameter contains
16785 the tail part of the directive line, i.e. the part which is past the
16786 initial whitespace, #, whitespace, directive-name, whitespace part. */
16789 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
16790 const char *buffer ATTRIBUTE_UNUSED)
16792 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16794 switch_to_section (debug_macinfo_section);
16795 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
16796 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16797 dw2_asm_output_nstring (buffer, -1, "The macro");
16801 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
16802 the tail part of the directive line, i.e. the part which is past the
16803 initial whitespace, #, whitespace, directive-name, whitespace part. */
16806 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
16807 const char *buffer ATTRIBUTE_UNUSED)
16809 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16811 switch_to_section (debug_macinfo_section);
16812 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
16813 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16814 dw2_asm_output_nstring (buffer, -1, "The macro");
16818 /* Set up for Dwarf output at the start of compilation. */
16821 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
16823 /* Allocate the file_table. */
16824 file_table = htab_create_ggc (50, file_table_hash,
16825 file_table_eq, NULL);
16827 /* Allocate the decl_die_table. */
16828 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
16829 decl_die_table_eq, NULL);
16831 /* Allocate the decl_loc_table. */
16832 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
16833 decl_loc_table_eq, NULL);
16835 /* Allocate the initial hunk of the decl_scope_table. */
16836 decl_scope_table = VEC_alloc (tree, gc, 256);
16838 /* Allocate the initial hunk of the abbrev_die_table. */
16839 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
16840 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
16841 /* Zero-th entry is allocated, but unused. */
16842 abbrev_die_table_in_use = 1;
16844 /* Allocate the initial hunk of the line_info_table. */
16845 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
16846 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
16848 /* Zero-th entry is allocated, but unused. */
16849 line_info_table_in_use = 1;
16851 /* Allocate the pubtypes and pubnames vectors. */
16852 pubname_table = VEC_alloc (pubname_entry, gc, 32);
16853 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
16855 /* Generate the initial DIE for the .debug section. Note that the (string)
16856 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16857 will (typically) be a relative pathname and that this pathname should be
16858 taken as being relative to the directory from which the compiler was
16859 invoked when the given (base) source file was compiled. We will fill
16860 in this value in dwarf2out_finish. */
16861 comp_unit_die = gen_compile_unit_die (NULL);
16863 incomplete_types = VEC_alloc (tree, gc, 64);
16865 used_rtx_array = VEC_alloc (rtx, gc, 32);
16867 debug_info_section = get_section (DEBUG_INFO_SECTION,
16868 SECTION_DEBUG, NULL);
16869 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
16870 SECTION_DEBUG, NULL);
16871 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
16872 SECTION_DEBUG, NULL);
16873 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
16874 SECTION_DEBUG, NULL);
16875 debug_line_section = get_section (DEBUG_LINE_SECTION,
16876 SECTION_DEBUG, NULL);
16877 debug_loc_section = get_section (DEBUG_LOC_SECTION,
16878 SECTION_DEBUG, NULL);
16879 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
16880 SECTION_DEBUG, NULL);
16881 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
16882 SECTION_DEBUG, NULL);
16883 debug_str_section = get_section (DEBUG_STR_SECTION,
16884 DEBUG_STR_SECTION_FLAGS, NULL);
16885 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
16886 SECTION_DEBUG, NULL);
16887 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
16888 SECTION_DEBUG, NULL);
16890 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
16891 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
16892 DEBUG_ABBREV_SECTION_LABEL, 0);
16893 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
16894 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
16895 COLD_TEXT_SECTION_LABEL, 0);
16896 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
16898 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
16899 DEBUG_INFO_SECTION_LABEL, 0);
16900 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
16901 DEBUG_LINE_SECTION_LABEL, 0);
16902 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
16903 DEBUG_RANGES_SECTION_LABEL, 0);
16904 switch_to_section (debug_abbrev_section);
16905 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
16906 switch_to_section (debug_info_section);
16907 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
16908 switch_to_section (debug_line_section);
16909 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
16911 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16913 switch_to_section (debug_macinfo_section);
16914 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
16915 DEBUG_MACINFO_SECTION_LABEL, 0);
16916 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
16919 switch_to_section (text_section);
16920 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
16921 if (flag_reorder_blocks_and_partition)
16923 cold_text_section = unlikely_text_section ();
16924 switch_to_section (cold_text_section);
16925 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
16929 /* A helper function for dwarf2out_finish called through
16930 ht_forall. Emit one queued .debug_str string. */
16933 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
16935 struct indirect_string_node *node = (struct indirect_string_node *) *h;
16937 if (node->form == DW_FORM_strp)
16939 switch_to_section (debug_str_section);
16940 ASM_OUTPUT_LABEL (asm_out_file, node->label);
16941 assemble_string (node->str, strlen (node->str) + 1);
16947 #if ENABLE_ASSERT_CHECKING
16948 /* Verify that all marks are clear. */
16951 verify_marks_clear (dw_die_ref die)
16955 gcc_assert (! die->die_mark);
16956 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
16958 #endif /* ENABLE_ASSERT_CHECKING */
16960 /* Clear the marks for a die and its children.
16961 Be cool if the mark isn't set. */
16964 prune_unmark_dies (dw_die_ref die)
16970 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
16973 /* Given DIE that we're marking as used, find any other dies
16974 it references as attributes and mark them as used. */
16977 prune_unused_types_walk_attribs (dw_die_ref die)
16982 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16984 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
16986 /* A reference to another DIE.
16987 Make sure that it will get emitted. */
16988 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
16990 /* Set the string's refcount to 0 so that prune_unused_types_mark
16991 accounts properly for it. */
16992 if (AT_class (a) == dw_val_class_str)
16993 a->dw_attr_val.v.val_str->refcount = 0;
16998 /* Mark DIE as being used. If DOKIDS is true, then walk down
16999 to DIE's children. */
17002 prune_unused_types_mark (dw_die_ref die, int dokids)
17006 if (die->die_mark == 0)
17008 /* We haven't done this node yet. Mark it as used. */
17011 /* We also have to mark its parents as used.
17012 (But we don't want to mark our parents' kids due to this.) */
17013 if (die->die_parent)
17014 prune_unused_types_mark (die->die_parent, 0);
17016 /* Mark any referenced nodes. */
17017 prune_unused_types_walk_attribs (die);
17019 /* If this node is a specification,
17020 also mark the definition, if it exists. */
17021 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
17022 prune_unused_types_mark (die->die_definition, 1);
17025 if (dokids && die->die_mark != 2)
17027 /* We need to walk the children, but haven't done so yet.
17028 Remember that we've walked the kids. */
17031 /* If this is an array type, we need to make sure our
17032 kids get marked, even if they're types. */
17033 if (die->die_tag == DW_TAG_array_type)
17034 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
17036 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
17040 /* For local classes, look if any static member functions were emitted
17041 and if so, mark them. */
17044 prune_unused_types_walk_local_classes (dw_die_ref die)
17048 if (die->die_mark == 2)
17051 switch (die->die_tag)
17053 case DW_TAG_structure_type:
17054 case DW_TAG_union_type:
17055 case DW_TAG_class_type:
17058 case DW_TAG_subprogram:
17059 if (!get_AT_flag (die, DW_AT_declaration)
17060 || die->die_definition != NULL)
17061 prune_unused_types_mark (die, 1);
17068 /* Mark children. */
17069 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
17072 /* Walk the tree DIE and mark types that we actually use. */
17075 prune_unused_types_walk (dw_die_ref die)
17079 /* Don't do anything if this node is already marked and
17080 children have been marked as well. */
17081 if (die->die_mark == 2)
17084 switch (die->die_tag)
17086 case DW_TAG_structure_type:
17087 case DW_TAG_union_type:
17088 case DW_TAG_class_type:
17089 if (die->die_perennial_p)
17092 for (c = die->die_parent; c; c = c->die_parent)
17093 if (c->die_tag == DW_TAG_subprogram)
17096 /* Finding used static member functions inside of classes
17097 is needed just for local classes, because for other classes
17098 static member function DIEs with DW_AT_specification
17099 are emitted outside of the DW_TAG_*_type. If we ever change
17100 it, we'd need to call this even for non-local classes. */
17102 prune_unused_types_walk_local_classes (die);
17104 /* It's a type node --- don't mark it. */
17107 case DW_TAG_const_type:
17108 case DW_TAG_packed_type:
17109 case DW_TAG_pointer_type:
17110 case DW_TAG_reference_type:
17111 case DW_TAG_volatile_type:
17112 case DW_TAG_typedef:
17113 case DW_TAG_array_type:
17114 case DW_TAG_interface_type:
17115 case DW_TAG_friend:
17116 case DW_TAG_variant_part:
17117 case DW_TAG_enumeration_type:
17118 case DW_TAG_subroutine_type:
17119 case DW_TAG_string_type:
17120 case DW_TAG_set_type:
17121 case DW_TAG_subrange_type:
17122 case DW_TAG_ptr_to_member_type:
17123 case DW_TAG_file_type:
17124 if (die->die_perennial_p)
17127 /* It's a type node --- don't mark it. */
17131 /* Mark everything else. */
17135 if (die->die_mark == 0)
17139 /* Now, mark any dies referenced from here. */
17140 prune_unused_types_walk_attribs (die);
17145 /* Mark children. */
17146 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
17149 /* Increment the string counts on strings referred to from DIE's
17153 prune_unused_types_update_strings (dw_die_ref die)
17158 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
17159 if (AT_class (a) == dw_val_class_str)
17161 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
17163 /* Avoid unnecessarily putting strings that are used less than
17164 twice in the hash table. */
17166 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
17169 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
17170 htab_hash_string (s->str),
17172 gcc_assert (*slot == NULL);
17178 /* Remove from the tree DIE any dies that aren't marked. */
17181 prune_unused_types_prune (dw_die_ref die)
17185 gcc_assert (die->die_mark);
17186 prune_unused_types_update_strings (die);
17188 if (! die->die_child)
17191 c = die->die_child;
17193 dw_die_ref prev = c;
17194 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
17195 if (c == die->die_child)
17197 /* No marked children between 'prev' and the end of the list. */
17199 /* No marked children at all. */
17200 die->die_child = NULL;
17203 prev->die_sib = c->die_sib;
17204 die->die_child = prev;
17209 if (c != prev->die_sib)
17211 prune_unused_types_prune (c);
17212 } while (c != die->die_child);
17216 /* Remove dies representing declarations that we never use. */
17219 prune_unused_types (void)
17222 limbo_die_node *node;
17225 #if ENABLE_ASSERT_CHECKING
17226 /* All the marks should already be clear. */
17227 verify_marks_clear (comp_unit_die);
17228 for (node = limbo_die_list; node; node = node->next)
17229 verify_marks_clear (node->die);
17230 #endif /* ENABLE_ASSERT_CHECKING */
17232 /* Set the mark on nodes that are actually used. */
17233 prune_unused_types_walk (comp_unit_die);
17234 for (node = limbo_die_list; node; node = node->next)
17235 prune_unused_types_walk (node->die);
17237 /* Also set the mark on nodes referenced from the
17238 pubname_table or arange_table. */
17239 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
17240 prune_unused_types_mark (pub->die, 1);
17241 for (i = 0; i < arange_table_in_use; i++)
17242 prune_unused_types_mark (arange_table[i], 1);
17244 /* Get rid of nodes that aren't marked; and update the string counts. */
17245 if (debug_str_hash)
17246 htab_empty (debug_str_hash);
17247 prune_unused_types_prune (comp_unit_die);
17248 for (node = limbo_die_list; node; node = node->next)
17249 prune_unused_types_prune (node->die);
17251 /* Leave the marks clear. */
17252 prune_unmark_dies (comp_unit_die);
17253 for (node = limbo_die_list; node; node = node->next)
17254 prune_unmark_dies (node->die);
17257 /* Set the parameter to true if there are any relative pathnames in
17260 file_table_relative_p (void ** slot, void *param)
17262 bool *p = (bool *) param;
17263 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
17264 if (!IS_ABSOLUTE_PATH (d->filename))
17272 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
17273 to the location it would have been added, should we know its
17274 DECL_ASSEMBLER_NAME when we added other attributes. This will
17275 probably improve compactness of debug info, removing equivalent
17276 abbrevs, and hide any differences caused by deferring the
17277 computation of the assembler name, triggered by e.g. PCH. */
17280 move_linkage_attr (dw_die_ref die)
17282 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
17283 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
17285 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
17289 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
17291 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
17295 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
17297 VEC_pop (dw_attr_node, die->die_attr);
17298 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
17302 /* Output stuff that dwarf requires at the end of every file,
17303 and generate the DWARF-2 debugging info. */
17306 dwarf2out_finish (const char *filename)
17308 limbo_die_node *node, *next_node;
17309 dw_die_ref die = 0;
17312 /* Add the name for the main input file now. We delayed this from
17313 dwarf2out_init to avoid complications with PCH. */
17314 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
17315 if (!IS_ABSOLUTE_PATH (filename))
17316 add_comp_dir_attribute (comp_unit_die);
17317 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
17320 htab_traverse (file_table, file_table_relative_p, &p);
17322 add_comp_dir_attribute (comp_unit_die);
17325 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
17327 add_location_or_const_value_attribute (
17328 VEC_index (deferred_locations, deferred_locations_list, i)->die,
17329 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
17333 /* Traverse the limbo die list, and add parent/child links. The only
17334 dies without parents that should be here are concrete instances of
17335 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
17336 For concrete instances, we can get the parent die from the abstract
17338 for (node = limbo_die_list; node; node = next_node)
17340 next_node = node->next;
17343 if (die->die_parent == NULL)
17345 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
17348 add_child_die (origin->die_parent, die);
17349 else if (die == comp_unit_die)
17351 else if (errorcount > 0 || sorrycount > 0)
17352 /* It's OK to be confused by errors in the input. */
17353 add_child_die (comp_unit_die, die);
17356 /* In certain situations, the lexical block containing a
17357 nested function can be optimized away, which results
17358 in the nested function die being orphaned. Likewise
17359 with the return type of that nested function. Force
17360 this to be a child of the containing function.
17362 It may happen that even the containing function got fully
17363 inlined and optimized out. In that case we are lost and
17364 assign the empty child. This should not be big issue as
17365 the function is likely unreachable too. */
17366 tree context = NULL_TREE;
17368 gcc_assert (node->created_for);
17370 if (DECL_P (node->created_for))
17371 context = DECL_CONTEXT (node->created_for);
17372 else if (TYPE_P (node->created_for))
17373 context = TYPE_CONTEXT (node->created_for);
17375 gcc_assert (context
17376 && (TREE_CODE (context) == FUNCTION_DECL
17377 || TREE_CODE (context) == NAMESPACE_DECL));
17379 origin = lookup_decl_die (context);
17381 add_child_die (origin, die);
17383 add_child_die (comp_unit_die, die);
17388 limbo_die_list = NULL;
17390 for (node = deferred_asm_name; node; node = node->next)
17392 tree decl = node->created_for;
17393 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17395 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
17396 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
17397 move_linkage_attr (node->die);
17401 deferred_asm_name = NULL;
17403 /* Walk through the list of incomplete types again, trying once more to
17404 emit full debugging info for them. */
17405 retry_incomplete_types ();
17407 if (flag_eliminate_unused_debug_types)
17408 prune_unused_types ();
17410 /* Generate separate CUs for each of the include files we've seen.
17411 They will go into limbo_die_list. */
17412 if (flag_eliminate_dwarf2_dups)
17413 break_out_includes (comp_unit_die);
17415 /* Traverse the DIE's and add add sibling attributes to those DIE's
17416 that have children. */
17417 add_sibling_attributes (comp_unit_die);
17418 for (node = limbo_die_list; node; node = node->next)
17419 add_sibling_attributes (node->die);
17421 /* Output a terminator label for the .text section. */
17422 switch_to_section (text_section);
17423 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
17424 if (flag_reorder_blocks_and_partition)
17426 switch_to_section (unlikely_text_section ());
17427 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
17430 /* We can only use the low/high_pc attributes if all of the code was
17432 if (!have_multiple_function_sections)
17434 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
17435 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
17440 unsigned fde_idx = 0;
17442 /* We need to give .debug_loc and .debug_ranges an appropriate
17443 "base address". Use zero so that these addresses become
17444 absolute. Historically, we've emitted the unexpected
17445 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
17446 Emit both to give time for other tools to adapt. */
17447 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
17448 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
17450 add_AT_range_list (comp_unit_die, DW_AT_ranges,
17451 add_ranges_by_labels (text_section_label,
17453 if (flag_reorder_blocks_and_partition)
17454 add_ranges_by_labels (cold_text_section_label,
17457 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
17459 dw_fde_ref fde = &fde_table[fde_idx];
17461 if (fde->dw_fde_switched_sections)
17463 if (!fde->in_std_section)
17464 add_ranges_by_labels (fde->dw_fde_hot_section_label,
17465 fde->dw_fde_hot_section_end_label);
17466 if (!fde->cold_in_std_section)
17467 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
17468 fde->dw_fde_unlikely_section_end_label);
17470 else if (!fde->in_std_section)
17471 add_ranges_by_labels (fde->dw_fde_begin,
17478 /* Output location list section if necessary. */
17479 if (have_location_lists)
17481 /* Output the location lists info. */
17482 switch_to_section (debug_loc_section);
17483 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
17484 DEBUG_LOC_SECTION_LABEL, 0);
17485 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
17486 output_location_lists (die);
17489 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17490 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
17491 debug_line_section_label);
17493 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17494 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
17496 /* Output all of the compilation units. We put the main one last so that
17497 the offsets are available to output_pubnames. */
17498 for (node = limbo_die_list; node; node = node->next)
17499 output_comp_unit (node->die, 0);
17501 /* Output the main compilation unit if non-empty or if .debug_macinfo
17502 has been emitted. */
17503 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
17505 /* Output the abbreviation table. */
17506 switch_to_section (debug_abbrev_section);
17507 output_abbrev_section ();
17509 /* Output public names table if necessary. */
17510 if (!VEC_empty (pubname_entry, pubname_table))
17512 switch_to_section (debug_pubnames_section);
17513 output_pubnames (pubname_table);
17516 /* Output public types table if necessary. */
17517 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
17518 It shouldn't hurt to emit it always, since pure DWARF2 consumers
17519 simply won't look for the section. */
17520 if (!VEC_empty (pubname_entry, pubtype_table))
17522 switch_to_section (debug_pubtypes_section);
17523 output_pubnames (pubtype_table);
17526 /* Output the address range information. We only put functions in the arange
17527 table, so don't write it out if we don't have any. */
17528 if (fde_table_in_use)
17530 switch_to_section (debug_aranges_section);
17534 /* Output ranges section if necessary. */
17535 if (ranges_table_in_use)
17537 switch_to_section (debug_ranges_section);
17538 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
17542 /* Output the source line correspondence table. We must do this
17543 even if there is no line information. Otherwise, on an empty
17544 translation unit, we will generate a present, but empty,
17545 .debug_info section. IRIX 6.5 `nm' will then complain when
17546 examining the file. This is done late so that any filenames
17547 used by the debug_info section are marked as 'used'. */
17548 if (! DWARF2_ASM_LINE_DEBUG_INFO)
17550 switch_to_section (debug_line_section);
17551 output_line_info ();
17554 /* Have to end the macro section. */
17555 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17557 switch_to_section (debug_macinfo_section);
17558 dw2_asm_output_data (1, 0, "End compilation unit");
17561 /* If we emitted any DW_FORM_strp form attribute, output the string
17563 if (debug_str_hash)
17564 htab_traverse (debug_str_hash, output_indirect_string, NULL);
17568 /* This should never be used, but its address is needed for comparisons. */
17569 const struct gcc_debug_hooks dwarf2_debug_hooks =
17575 0, /* start_source_file */
17576 0, /* end_source_file */
17577 0, /* begin_block */
17579 0, /* ignore_block */
17580 0, /* source_line */
17581 0, /* begin_prologue */
17582 0, /* end_prologue */
17583 0, /* end_epilogue */
17584 0, /* begin_function */
17585 0, /* end_function */
17586 0, /* function_decl */
17587 0, /* global_decl */
17589 0, /* imported_module_or_decl */
17590 0, /* deferred_inline_function */
17591 0, /* outlining_inline_function */
17593 0, /* handle_pch */
17594 0, /* var_location */
17595 0, /* switch_text_section */
17597 0 /* start_end_main_source_file */
17600 #endif /* DWARF2_DEBUGGING_INFO */
17602 #include "gt-dwarf2out.h"