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)
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 /* Personality decl of current unit. Used only when assembler does not support
221 static GTY(()) rtx current_unit_personality;
223 /* How to start an assembler comment. */
224 #ifndef ASM_COMMENT_START
225 #define ASM_COMMENT_START ";#"
228 typedef struct dw_cfi_struct *dw_cfi_ref;
229 typedef struct dw_fde_struct *dw_fde_ref;
230 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
232 /* Call frames are described using a sequence of Call Frame
233 Information instructions. The register number, offset
234 and address fields are provided as possible operands;
235 their use is selected by the opcode field. */
237 enum dw_cfi_oprnd_type {
239 dw_cfi_oprnd_reg_num,
245 typedef union GTY(()) dw_cfi_oprnd_struct {
246 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
247 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
248 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
249 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
253 typedef struct GTY(()) dw_cfi_struct {
254 dw_cfi_ref dw_cfi_next;
255 enum dwarf_call_frame_info dw_cfi_opc;
256 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
258 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
263 /* This is how we define the location of the CFA. We use to handle it
264 as REG + OFFSET all the time, but now it can be more complex.
265 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
266 Instead of passing around REG and OFFSET, we pass a copy
267 of this structure. */
268 typedef struct GTY(()) cfa_loc {
269 HOST_WIDE_INT offset;
270 HOST_WIDE_INT base_offset;
272 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
273 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
276 /* All call frame descriptions (FDE's) in the GCC generated DWARF
277 refer to a single Common Information Entry (CIE), defined at
278 the beginning of the .debug_frame section. This use of a single
279 CIE obviates the need to keep track of multiple CIE's
280 in the DWARF generation routines below. */
282 typedef struct GTY(()) dw_fde_struct {
284 const char *dw_fde_begin;
285 const char *dw_fde_current_label;
286 const char *dw_fde_end;
287 const char *dw_fde_hot_section_label;
288 const char *dw_fde_hot_section_end_label;
289 const char *dw_fde_unlikely_section_label;
290 const char *dw_fde_unlikely_section_end_label;
291 dw_cfi_ref dw_fde_cfi;
292 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
293 unsigned funcdef_number;
294 HOST_WIDE_INT stack_realignment;
295 /* Dynamic realign argument pointer register. */
296 unsigned int drap_reg;
297 /* Virtual dynamic realign argument pointer register. */
298 unsigned int vdrap_reg;
299 unsigned all_throwers_are_sibcalls : 1;
300 unsigned nothrow : 1;
301 unsigned uses_eh_lsda : 1;
302 /* Whether we did stack realign in this call frame. */
303 unsigned stack_realign : 1;
304 /* Whether dynamic realign argument pointer register has been saved. */
305 unsigned drap_reg_saved: 1;
306 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
307 unsigned in_std_section : 1;
308 /* True iff dw_fde_unlikely_section_label is in text_section or
309 cold_text_section. */
310 unsigned cold_in_std_section : 1;
311 /* True iff switched sections. */
312 unsigned dw_fde_switched_sections : 1;
313 /* True iff switching from cold to hot section. */
314 unsigned dw_fde_switched_cold_to_hot : 1;
318 /* Maximum size (in bytes) of an artificially generated label. */
319 #define MAX_ARTIFICIAL_LABEL_BYTES 30
321 /* The size of addresses as they appear in the Dwarf 2 data.
322 Some architectures use word addresses to refer to code locations,
323 but Dwarf 2 info always uses byte addresses. On such machines,
324 Dwarf 2 addresses need to be larger than the architecture's
326 #ifndef DWARF2_ADDR_SIZE
327 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
330 /* The size in bytes of a DWARF field indicating an offset or length
331 relative to a debug info section, specified to be 4 bytes in the
332 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
335 #ifndef DWARF_OFFSET_SIZE
336 #define DWARF_OFFSET_SIZE 4
339 /* According to the (draft) DWARF 3 specification, the initial length
340 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
341 bytes are 0xffffffff, followed by the length stored in the next 8
344 However, the SGI/MIPS ABI uses an initial length which is equal to
345 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
347 #ifndef DWARF_INITIAL_LENGTH_SIZE
348 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
351 /* Round SIZE up to the nearest BOUNDARY. */
352 #define DWARF_ROUND(SIZE,BOUNDARY) \
353 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
355 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
356 #ifndef DWARF_CIE_DATA_ALIGNMENT
357 #ifdef STACK_GROWS_DOWNWARD
358 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
360 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
364 /* CIE identifier. */
365 #if HOST_BITS_PER_WIDE_INT >= 64
366 #define DWARF_CIE_ID \
367 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
369 #define DWARF_CIE_ID DW_CIE_ID
372 /* A pointer to the base of a table that contains frame description
373 information for each routine. */
374 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
376 /* Number of elements currently allocated for fde_table. */
377 static GTY(()) unsigned fde_table_allocated;
379 /* Number of elements in fde_table currently in use. */
380 static GTY(()) unsigned fde_table_in_use;
382 /* Size (in elements) of increments by which we may expand the
384 #define FDE_TABLE_INCREMENT 256
386 /* Get the current fde_table entry we should use. */
388 static inline dw_fde_ref
391 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
394 /* A list of call frame insns for the CIE. */
395 static GTY(()) dw_cfi_ref cie_cfi_head;
397 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
398 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
399 attribute that accelerates the lookup of the FDE associated
400 with the subprogram. This variable holds the table index of the FDE
401 associated with the current function (body) definition. */
402 static unsigned current_funcdef_fde;
405 struct GTY(()) indirect_string_node {
407 unsigned int refcount;
408 enum dwarf_form form;
412 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
414 /* True if the compilation unit has location entries that reference
416 static GTY(()) bool debug_str_hash_forced = false;
418 static GTY(()) int dw2_string_counter;
419 static GTY(()) unsigned long dwarf2out_cfi_label_num;
421 /* True if the compilation unit places functions in more than one section. */
422 static GTY(()) bool have_multiple_function_sections = false;
424 /* Whether the default text and cold text sections have been used at all. */
426 static GTY(()) bool text_section_used = false;
427 static GTY(()) bool cold_text_section_used = false;
429 /* The default cold text section. */
430 static GTY(()) section *cold_text_section;
432 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
434 /* Forward declarations for functions defined in this file. */
436 static char *stripattributes (const char *);
437 static const char *dwarf_cfi_name (unsigned);
438 static dw_cfi_ref new_cfi (void);
439 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
440 static void add_fde_cfi (const char *, dw_cfi_ref);
441 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
442 static void lookup_cfa (dw_cfa_location *);
443 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
444 #ifdef DWARF2_UNWIND_INFO
445 static void initial_return_save (rtx);
447 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
449 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
450 static void output_cfi_directive (dw_cfi_ref);
451 static void output_call_frame_info (int);
452 static void dwarf2out_note_section_used (void);
453 static void dwarf2out_stack_adjust (rtx, bool);
454 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
455 static void flush_queued_reg_saves (void);
456 static bool clobbers_queued_reg_save (const_rtx);
457 static void dwarf2out_frame_debug_expr (rtx, const char *);
459 /* Support for complex CFA locations. */
460 static void output_cfa_loc (dw_cfi_ref);
461 static void output_cfa_loc_raw (dw_cfi_ref);
462 static void get_cfa_from_loc_descr (dw_cfa_location *,
463 struct dw_loc_descr_struct *);
464 static struct dw_loc_descr_struct *build_cfa_loc
465 (dw_cfa_location *, HOST_WIDE_INT);
466 static struct dw_loc_descr_struct *build_cfa_aligned_loc
467 (HOST_WIDE_INT, HOST_WIDE_INT);
468 static void def_cfa_1 (const char *, dw_cfa_location *);
470 /* How to start an assembler comment. */
471 #ifndef ASM_COMMENT_START
472 #define ASM_COMMENT_START ";#"
475 /* Data and reference forms for relocatable data. */
476 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
477 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
479 #ifndef DEBUG_FRAME_SECTION
480 #define DEBUG_FRAME_SECTION ".debug_frame"
483 #ifndef FUNC_BEGIN_LABEL
484 #define FUNC_BEGIN_LABEL "LFB"
487 #ifndef FUNC_END_LABEL
488 #define FUNC_END_LABEL "LFE"
491 #ifndef FRAME_BEGIN_LABEL
492 #define FRAME_BEGIN_LABEL "Lframe"
494 #define CIE_AFTER_SIZE_LABEL "LSCIE"
495 #define CIE_END_LABEL "LECIE"
496 #define FDE_LABEL "LSFDE"
497 #define FDE_AFTER_SIZE_LABEL "LASFDE"
498 #define FDE_END_LABEL "LEFDE"
499 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
500 #define LINE_NUMBER_END_LABEL "LELT"
501 #define LN_PROLOG_AS_LABEL "LASLTP"
502 #define LN_PROLOG_END_LABEL "LELTP"
503 #define DIE_LABEL_PREFIX "DW"
505 /* The DWARF 2 CFA column which tracks the return address. Normally this
506 is the column for PC, or the first column after all of the hard
508 #ifndef DWARF_FRAME_RETURN_COLUMN
510 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
512 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
516 /* The mapping from gcc register number to DWARF 2 CFA column number. By
517 default, we just provide columns for all registers. */
518 #ifndef DWARF_FRAME_REGNUM
519 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
522 /* Hook used by __throw. */
525 expand_builtin_dwarf_sp_column (void)
527 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
528 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
531 /* Return a pointer to a copy of the section string name S with all
532 attributes stripped off, and an asterisk prepended (for assemble_name). */
535 stripattributes (const char *s)
537 char *stripped = XNEWVEC (char, strlen (s) + 2);
542 while (*s && *s != ',')
549 /* MEM is a memory reference for the register size table, each element of
550 which has mode MODE. Initialize column C as a return address column. */
553 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
555 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
556 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
557 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
560 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
562 static inline HOST_WIDE_INT
563 div_data_align (HOST_WIDE_INT off)
565 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
566 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
570 /* Return true if we need a signed version of a given opcode
571 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
574 need_data_align_sf_opcode (HOST_WIDE_INT off)
576 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
579 /* Generate code to initialize the register size table. */
582 expand_builtin_init_dwarf_reg_sizes (tree address)
585 enum machine_mode mode = TYPE_MODE (char_type_node);
586 rtx addr = expand_normal (address);
587 rtx mem = gen_rtx_MEM (BLKmode, addr);
588 bool wrote_return_column = false;
590 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
592 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
594 if (rnum < DWARF_FRAME_REGISTERS)
596 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
597 enum machine_mode save_mode = reg_raw_mode[i];
600 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
601 save_mode = choose_hard_reg_mode (i, 1, true);
602 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
604 if (save_mode == VOIDmode)
606 wrote_return_column = true;
608 size = GET_MODE_SIZE (save_mode);
612 emit_move_insn (adjust_address (mem, mode, offset),
613 gen_int_mode (size, mode));
617 if (!wrote_return_column)
618 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
620 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
621 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
624 targetm.init_dwarf_reg_sizes_extra (address);
627 /* Convert a DWARF call frame info. operation to its string name */
630 dwarf_cfi_name (unsigned int cfi_opc)
634 case DW_CFA_advance_loc:
635 return "DW_CFA_advance_loc";
637 return "DW_CFA_offset";
639 return "DW_CFA_restore";
643 return "DW_CFA_set_loc";
644 case DW_CFA_advance_loc1:
645 return "DW_CFA_advance_loc1";
646 case DW_CFA_advance_loc2:
647 return "DW_CFA_advance_loc2";
648 case DW_CFA_advance_loc4:
649 return "DW_CFA_advance_loc4";
650 case DW_CFA_offset_extended:
651 return "DW_CFA_offset_extended";
652 case DW_CFA_restore_extended:
653 return "DW_CFA_restore_extended";
654 case DW_CFA_undefined:
655 return "DW_CFA_undefined";
656 case DW_CFA_same_value:
657 return "DW_CFA_same_value";
658 case DW_CFA_register:
659 return "DW_CFA_register";
660 case DW_CFA_remember_state:
661 return "DW_CFA_remember_state";
662 case DW_CFA_restore_state:
663 return "DW_CFA_restore_state";
665 return "DW_CFA_def_cfa";
666 case DW_CFA_def_cfa_register:
667 return "DW_CFA_def_cfa_register";
668 case DW_CFA_def_cfa_offset:
669 return "DW_CFA_def_cfa_offset";
672 case DW_CFA_def_cfa_expression:
673 return "DW_CFA_def_cfa_expression";
674 case DW_CFA_expression:
675 return "DW_CFA_expression";
676 case DW_CFA_offset_extended_sf:
677 return "DW_CFA_offset_extended_sf";
678 case DW_CFA_def_cfa_sf:
679 return "DW_CFA_def_cfa_sf";
680 case DW_CFA_def_cfa_offset_sf:
681 return "DW_CFA_def_cfa_offset_sf";
683 /* SGI/MIPS specific */
684 case DW_CFA_MIPS_advance_loc8:
685 return "DW_CFA_MIPS_advance_loc8";
688 case DW_CFA_GNU_window_save:
689 return "DW_CFA_GNU_window_save";
690 case DW_CFA_GNU_args_size:
691 return "DW_CFA_GNU_args_size";
692 case DW_CFA_GNU_negative_offset_extended:
693 return "DW_CFA_GNU_negative_offset_extended";
696 return "DW_CFA_<unknown>";
700 /* Return a pointer to a newly allocated Call Frame Instruction. */
702 static inline dw_cfi_ref
705 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
707 cfi->dw_cfi_next = NULL;
708 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
709 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
714 /* Add a Call Frame Instruction to list of instructions. */
717 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
720 dw_fde_ref fde = current_fde ();
722 /* When DRAP is used, CFA is defined with an expression. Redefine
723 CFA may lead to a different CFA value. */
724 /* ??? Of course, this heuristic fails when we're annotating epilogues,
725 because of course we'll always want to redefine the CFA back to the
726 stack pointer on the way out. Where should we move this check? */
727 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
728 switch (cfi->dw_cfi_opc)
730 case DW_CFA_def_cfa_register:
731 case DW_CFA_def_cfa_offset:
732 case DW_CFA_def_cfa_offset_sf:
734 case DW_CFA_def_cfa_sf:
741 /* Find the end of the chain. */
742 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
748 /* Generate a new label for the CFI info to refer to. FORCE is true
749 if a label needs to be output even when using .cfi_* directives. */
752 dwarf2out_cfi_label (bool force)
754 static char label[20];
756 if (!force && dwarf2out_do_cfi_asm ())
758 /* In this case, we will be emitting the asm directive instead of
759 the label, so just return a placeholder to keep the rest of the
761 strcpy (label, "<do not output>");
765 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
766 ASM_OUTPUT_LABEL (asm_out_file, label);
772 /* True if remember_state should be emitted before following CFI directive. */
773 static bool emit_cfa_remember;
775 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
776 or to the CIE if LABEL is NULL. */
779 add_fde_cfi (const char *label, dw_cfi_ref cfi)
781 dw_cfi_ref *list_head;
783 if (emit_cfa_remember)
785 dw_cfi_ref cfi_remember;
787 /* Emit the state save. */
788 emit_cfa_remember = false;
789 cfi_remember = new_cfi ();
790 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
791 add_fde_cfi (label, cfi_remember);
794 list_head = &cie_cfi_head;
796 if (dwarf2out_do_cfi_asm ())
800 dw_fde_ref fde = current_fde ();
802 gcc_assert (fde != NULL);
804 /* We still have to add the cfi to the list so that lookup_cfa
805 works later on. When -g2 and above we even need to force
806 emitting of CFI labels and add to list a DW_CFA_set_loc for
807 convert_cfa_to_fb_loc_list purposes. If we're generating
808 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
809 convert_cfa_to_fb_loc_list. */
810 if (dwarf_version == 2
811 && debug_info_level > DINFO_LEVEL_TERSE
812 && (write_symbols == DWARF2_DEBUG
813 || write_symbols == VMS_AND_DWARF2_DEBUG))
815 switch (cfi->dw_cfi_opc)
817 case DW_CFA_def_cfa_offset:
818 case DW_CFA_def_cfa_offset_sf:
819 case DW_CFA_def_cfa_register:
821 case DW_CFA_def_cfa_sf:
822 case DW_CFA_def_cfa_expression:
823 case DW_CFA_restore_state:
824 if (*label == 0 || strcmp (label, "<do not output>") == 0)
825 label = dwarf2out_cfi_label (true);
827 if (fde->dw_fde_current_label == NULL
828 || strcmp (label, fde->dw_fde_current_label) != 0)
832 label = xstrdup (label);
834 /* Set the location counter to the new label. */
836 /* It doesn't metter whether DW_CFA_set_loc
837 or DW_CFA_advance_loc4 is added here, those aren't
838 emitted into assembly, only looked up by
839 convert_cfa_to_fb_loc_list. */
840 xcfi->dw_cfi_opc = DW_CFA_set_loc;
841 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
842 add_cfi (&fde->dw_fde_cfi, xcfi);
843 fde->dw_fde_current_label = label;
851 output_cfi_directive (cfi);
853 list_head = &fde->dw_fde_cfi;
855 /* ??? If this is a CFI for the CIE, we don't emit. This
856 assumes that the standard CIE contents that the assembler
857 uses matches the standard CIE contents that the compiler
858 uses. This is probably a bad assumption. I'm not quite
859 sure how to address this for now. */
863 dw_fde_ref fde = current_fde ();
865 gcc_assert (fde != NULL);
868 label = dwarf2out_cfi_label (false);
870 if (fde->dw_fde_current_label == NULL
871 || strcmp (label, fde->dw_fde_current_label) != 0)
875 label = xstrdup (label);
877 /* Set the location counter to the new label. */
879 /* If we have a current label, advance from there, otherwise
880 set the location directly using set_loc. */
881 xcfi->dw_cfi_opc = fde->dw_fde_current_label
882 ? DW_CFA_advance_loc4
884 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
885 add_cfi (&fde->dw_fde_cfi, xcfi);
887 fde->dw_fde_current_label = label;
890 list_head = &fde->dw_fde_cfi;
893 add_cfi (list_head, cfi);
896 /* Subroutine of lookup_cfa. */
899 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
901 switch (cfi->dw_cfi_opc)
903 case DW_CFA_def_cfa_offset:
904 case DW_CFA_def_cfa_offset_sf:
905 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
907 case DW_CFA_def_cfa_register:
908 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
911 case DW_CFA_def_cfa_sf:
912 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
913 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
915 case DW_CFA_def_cfa_expression:
916 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
919 case DW_CFA_remember_state:
920 gcc_assert (!remember->in_use);
922 remember->in_use = 1;
924 case DW_CFA_restore_state:
925 gcc_assert (remember->in_use);
927 remember->in_use = 0;
935 /* Find the previous value for the CFA. */
938 lookup_cfa (dw_cfa_location *loc)
942 dw_cfa_location remember;
944 memset (loc, 0, sizeof (*loc));
945 loc->reg = INVALID_REGNUM;
948 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
949 lookup_cfa_1 (cfi, loc, &remember);
951 fde = current_fde ();
953 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
954 lookup_cfa_1 (cfi, loc, &remember);
957 /* The current rule for calculating the DWARF2 canonical frame address. */
958 static dw_cfa_location cfa;
960 /* The register used for saving registers to the stack, and its offset
962 static dw_cfa_location cfa_store;
964 /* The current save location around an epilogue. */
965 static dw_cfa_location cfa_remember;
967 /* The running total of the size of arguments pushed onto the stack. */
968 static HOST_WIDE_INT args_size;
970 /* The last args_size we actually output. */
971 static HOST_WIDE_INT old_args_size;
973 /* Entry point to update the canonical frame address (CFA).
974 LABEL is passed to add_fde_cfi. The value of CFA is now to be
975 calculated from REG+OFFSET. */
978 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
985 def_cfa_1 (label, &loc);
988 /* Determine if two dw_cfa_location structures define the same data. */
991 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
993 return (loc1->reg == loc2->reg
994 && loc1->offset == loc2->offset
995 && loc1->indirect == loc2->indirect
996 && (loc1->indirect == 0
997 || loc1->base_offset == loc2->base_offset));
1000 /* This routine does the actual work. The CFA is now calculated from
1001 the dw_cfa_location structure. */
1004 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1007 dw_cfa_location old_cfa, loc;
1012 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1013 cfa_store.offset = loc.offset;
1015 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1016 lookup_cfa (&old_cfa);
1018 /* If nothing changed, no need to issue any call frame instructions. */
1019 if (cfa_equal_p (&loc, &old_cfa))
1024 if (loc.reg == old_cfa.reg && !loc.indirect)
1026 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1027 the CFA register did not change but the offset did. The data
1028 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1029 in the assembler via the .cfi_def_cfa_offset directive. */
1031 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1033 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1034 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1037 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1038 else if (loc.offset == old_cfa.offset
1039 && old_cfa.reg != INVALID_REGNUM
1042 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1043 indicating the CFA register has changed to <register> but the
1044 offset has not changed. */
1045 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1046 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1050 else if (loc.indirect == 0)
1052 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1053 indicating the CFA register has changed to <register> with
1054 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1055 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1058 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1060 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1061 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1062 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1066 /* Construct a DW_CFA_def_cfa_expression instruction to
1067 calculate the CFA using a full location expression since no
1068 register-offset pair is available. */
1069 struct dw_loc_descr_struct *loc_list;
1071 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1072 loc_list = build_cfa_loc (&loc, 0);
1073 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1076 add_fde_cfi (label, cfi);
1079 /* Add the CFI for saving a register. REG is the CFA column number.
1080 LABEL is passed to add_fde_cfi.
1081 If SREG is -1, the register is saved at OFFSET from the CFA;
1082 otherwise it is saved in SREG. */
1085 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1087 dw_cfi_ref cfi = new_cfi ();
1088 dw_fde_ref fde = current_fde ();
1090 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1092 /* When stack is aligned, store REG using DW_CFA_expression with
1095 && fde->stack_realign
1096 && sreg == INVALID_REGNUM)
1098 cfi->dw_cfi_opc = DW_CFA_expression;
1099 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1100 cfi->dw_cfi_oprnd1.dw_cfi_loc
1101 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1103 else if (sreg == INVALID_REGNUM)
1105 if (need_data_align_sf_opcode (offset))
1106 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1107 else if (reg & ~0x3f)
1108 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1110 cfi->dw_cfi_opc = DW_CFA_offset;
1111 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1113 else if (sreg == reg)
1114 cfi->dw_cfi_opc = DW_CFA_same_value;
1117 cfi->dw_cfi_opc = DW_CFA_register;
1118 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1121 add_fde_cfi (label, cfi);
1124 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1125 This CFI tells the unwinder that it needs to restore the window registers
1126 from the previous frame's window save area.
1128 ??? Perhaps we should note in the CIE where windows are saved (instead of
1129 assuming 0(cfa)) and what registers are in the window. */
1132 dwarf2out_window_save (const char *label)
1134 dw_cfi_ref cfi = new_cfi ();
1136 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1137 add_fde_cfi (label, cfi);
1140 /* Add a CFI to update the running total of the size of arguments
1141 pushed onto the stack. */
1144 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1148 if (size == old_args_size)
1151 old_args_size = size;
1154 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1155 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1156 add_fde_cfi (label, cfi);
1159 /* Entry point for saving a register to the stack. REG is the GCC register
1160 number. LABEL and OFFSET are passed to reg_save. */
1163 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1165 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1168 /* Entry point for saving the return address in the stack.
1169 LABEL and OFFSET are passed to reg_save. */
1172 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1174 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1177 /* Entry point for saving the return address in a register.
1178 LABEL and SREG are passed to reg_save. */
1181 dwarf2out_return_reg (const char *label, unsigned int sreg)
1183 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1186 #ifdef DWARF2_UNWIND_INFO
1187 /* Record the initial position of the return address. RTL is
1188 INCOMING_RETURN_ADDR_RTX. */
1191 initial_return_save (rtx rtl)
1193 unsigned int reg = INVALID_REGNUM;
1194 HOST_WIDE_INT offset = 0;
1196 switch (GET_CODE (rtl))
1199 /* RA is in a register. */
1200 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1204 /* RA is on the stack. */
1205 rtl = XEXP (rtl, 0);
1206 switch (GET_CODE (rtl))
1209 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1214 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1215 offset = INTVAL (XEXP (rtl, 1));
1219 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1220 offset = -INTVAL (XEXP (rtl, 1));
1230 /* The return address is at some offset from any value we can
1231 actually load. For instance, on the SPARC it is in %i7+8. Just
1232 ignore the offset for now; it doesn't matter for unwinding frames. */
1233 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1234 initial_return_save (XEXP (rtl, 0));
1241 if (reg != DWARF_FRAME_RETURN_COLUMN)
1242 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1246 /* Given a SET, calculate the amount of stack adjustment it
1249 static HOST_WIDE_INT
1250 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1251 HOST_WIDE_INT cur_offset)
1253 const_rtx src = SET_SRC (pattern);
1254 const_rtx dest = SET_DEST (pattern);
1255 HOST_WIDE_INT offset = 0;
1258 if (dest == stack_pointer_rtx)
1260 code = GET_CODE (src);
1262 /* Assume (set (reg sp) (reg whatever)) sets args_size
1264 if (code == REG && src != stack_pointer_rtx)
1266 offset = -cur_args_size;
1267 #ifndef STACK_GROWS_DOWNWARD
1270 return offset - cur_offset;
1273 if (! (code == PLUS || code == MINUS)
1274 || XEXP (src, 0) != stack_pointer_rtx
1275 || !CONST_INT_P (XEXP (src, 1)))
1278 /* (set (reg sp) (plus (reg sp) (const_int))) */
1279 offset = INTVAL (XEXP (src, 1));
1285 if (MEM_P (src) && !MEM_P (dest))
1289 /* (set (mem (pre_dec (reg sp))) (foo)) */
1290 src = XEXP (dest, 0);
1291 code = GET_CODE (src);
1297 if (XEXP (src, 0) == stack_pointer_rtx)
1299 rtx val = XEXP (XEXP (src, 1), 1);
1300 /* We handle only adjustments by constant amount. */
1301 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1302 && CONST_INT_P (val));
1303 offset = -INTVAL (val);
1310 if (XEXP (src, 0) == stack_pointer_rtx)
1312 offset = GET_MODE_SIZE (GET_MODE (dest));
1319 if (XEXP (src, 0) == stack_pointer_rtx)
1321 offset = -GET_MODE_SIZE (GET_MODE (dest));
1336 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1337 indexed by INSN_UID. */
1339 static HOST_WIDE_INT *barrier_args_size;
1341 /* Helper function for compute_barrier_args_size. Handle one insn. */
1343 static HOST_WIDE_INT
1344 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1345 VEC (rtx, heap) **next)
1347 HOST_WIDE_INT offset = 0;
1350 if (! RTX_FRAME_RELATED_P (insn))
1352 if (prologue_epilogue_contains (insn))
1354 else if (GET_CODE (PATTERN (insn)) == SET)
1355 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1356 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1357 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1359 /* There may be stack adjustments inside compound insns. Search
1361 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1362 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1363 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1364 cur_args_size, offset);
1369 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1373 expr = XEXP (expr, 0);
1374 if (GET_CODE (expr) == PARALLEL
1375 || GET_CODE (expr) == SEQUENCE)
1376 for (i = 1; i < XVECLEN (expr, 0); i++)
1378 rtx elem = XVECEXP (expr, 0, i);
1380 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1381 offset += stack_adjust_offset (elem, cur_args_size, offset);
1386 #ifndef STACK_GROWS_DOWNWARD
1390 cur_args_size += offset;
1391 if (cur_args_size < 0)
1396 rtx dest = JUMP_LABEL (insn);
1400 if (barrier_args_size [INSN_UID (dest)] < 0)
1402 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1403 VEC_safe_push (rtx, heap, *next, dest);
1408 return cur_args_size;
1411 /* Walk the whole function and compute args_size on BARRIERs. */
1414 compute_barrier_args_size (void)
1416 int max_uid = get_max_uid (), i;
1418 VEC (rtx, heap) *worklist, *next, *tmp;
1420 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1421 for (i = 0; i < max_uid; i++)
1422 barrier_args_size[i] = -1;
1424 worklist = VEC_alloc (rtx, heap, 20);
1425 next = VEC_alloc (rtx, heap, 20);
1426 insn = get_insns ();
1427 barrier_args_size[INSN_UID (insn)] = 0;
1428 VEC_quick_push (rtx, worklist, insn);
1431 while (!VEC_empty (rtx, worklist))
1433 rtx prev, body, first_insn;
1434 HOST_WIDE_INT cur_args_size;
1436 first_insn = insn = VEC_pop (rtx, worklist);
1437 cur_args_size = barrier_args_size[INSN_UID (insn)];
1438 prev = prev_nonnote_insn (insn);
1439 if (prev && BARRIER_P (prev))
1440 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1442 for (; insn; insn = NEXT_INSN (insn))
1444 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1446 if (BARRIER_P (insn))
1451 if (insn == first_insn)
1453 else if (barrier_args_size[INSN_UID (insn)] < 0)
1455 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1460 /* The insns starting with this label have been
1461 already scanned or are in the worklist. */
1466 body = PATTERN (insn);
1467 if (GET_CODE (body) == SEQUENCE)
1469 HOST_WIDE_INT dest_args_size = cur_args_size;
1470 for (i = 1; i < XVECLEN (body, 0); i++)
1471 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1472 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1474 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1475 dest_args_size, &next);
1478 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1479 cur_args_size, &next);
1481 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1482 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1483 dest_args_size, &next);
1486 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1487 cur_args_size, &next);
1491 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1495 if (VEC_empty (rtx, next))
1498 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1502 VEC_truncate (rtx, next, 0);
1505 VEC_free (rtx, heap, worklist);
1506 VEC_free (rtx, heap, next);
1510 /* Check INSN to see if it looks like a push or a stack adjustment, and
1511 make a note of it if it does. EH uses this information to find out how
1512 much extra space it needs to pop off the stack. */
1515 dwarf2out_stack_adjust (rtx insn, bool after_p)
1517 HOST_WIDE_INT offset;
1521 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1522 with this function. Proper support would require all frame-related
1523 insns to be marked, and to be able to handle saving state around
1524 epilogues textually in the middle of the function. */
1525 if (prologue_epilogue_contains (insn))
1528 /* If INSN is an instruction from target of an annulled branch, the
1529 effects are for the target only and so current argument size
1530 shouldn't change at all. */
1532 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1533 && INSN_FROM_TARGET_P (insn))
1536 /* If only calls can throw, and we have a frame pointer,
1537 save up adjustments until we see the CALL_INSN. */
1538 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1540 if (CALL_P (insn) && !after_p)
1542 /* Extract the size of the args from the CALL rtx itself. */
1543 insn = PATTERN (insn);
1544 if (GET_CODE (insn) == PARALLEL)
1545 insn = XVECEXP (insn, 0, 0);
1546 if (GET_CODE (insn) == SET)
1547 insn = SET_SRC (insn);
1548 gcc_assert (GET_CODE (insn) == CALL);
1549 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1554 if (CALL_P (insn) && !after_p)
1556 if (!flag_asynchronous_unwind_tables)
1557 dwarf2out_args_size ("", args_size);
1560 else if (BARRIER_P (insn))
1562 /* Don't call compute_barrier_args_size () if the only
1563 BARRIER is at the end of function. */
1564 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1565 compute_barrier_args_size ();
1566 if (barrier_args_size == NULL)
1570 offset = barrier_args_size[INSN_UID (insn)];
1575 offset -= args_size;
1576 #ifndef STACK_GROWS_DOWNWARD
1580 else if (GET_CODE (PATTERN (insn)) == SET)
1581 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1582 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1583 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1585 /* There may be stack adjustments inside compound insns. Search
1587 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1588 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1589 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1598 label = dwarf2out_cfi_label (false);
1599 dwarf2out_args_size_adjust (offset, label);
1602 /* Adjust args_size based on stack adjustment OFFSET. */
1605 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1607 if (cfa.reg == STACK_POINTER_REGNUM)
1608 cfa.offset += offset;
1610 if (cfa_store.reg == STACK_POINTER_REGNUM)
1611 cfa_store.offset += offset;
1613 #ifndef STACK_GROWS_DOWNWARD
1617 args_size += offset;
1621 def_cfa_1 (label, &cfa);
1622 if (flag_asynchronous_unwind_tables)
1623 dwarf2out_args_size (label, args_size);
1628 /* We delay emitting a register save until either (a) we reach the end
1629 of the prologue or (b) the register is clobbered. This clusters
1630 register saves so that there are fewer pc advances. */
1632 struct GTY(()) queued_reg_save {
1633 struct queued_reg_save *next;
1635 HOST_WIDE_INT cfa_offset;
1639 static GTY(()) struct queued_reg_save *queued_reg_saves;
1641 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1642 struct GTY(()) reg_saved_in_data {
1647 /* A list of registers saved in other registers.
1648 The list intentionally has a small maximum capacity of 4; if your
1649 port needs more than that, you might consider implementing a
1650 more efficient data structure. */
1651 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1652 static GTY(()) size_t num_regs_saved_in_regs;
1654 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1655 static const char *last_reg_save_label;
1657 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1658 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1661 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1663 struct queued_reg_save *q;
1665 /* Duplicates waste space, but it's also necessary to remove them
1666 for correctness, since the queue gets output in reverse
1668 for (q = queued_reg_saves; q != NULL; q = q->next)
1669 if (REGNO (q->reg) == REGNO (reg))
1674 q = GGC_NEW (struct queued_reg_save);
1675 q->next = queued_reg_saves;
1676 queued_reg_saves = q;
1680 q->cfa_offset = offset;
1681 q->saved_reg = sreg;
1683 last_reg_save_label = label;
1686 /* Output all the entries in QUEUED_REG_SAVES. */
1689 flush_queued_reg_saves (void)
1691 struct queued_reg_save *q;
1693 for (q = queued_reg_saves; q; q = q->next)
1696 unsigned int reg, sreg;
1698 for (i = 0; i < num_regs_saved_in_regs; i++)
1699 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1701 if (q->saved_reg && i == num_regs_saved_in_regs)
1703 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1704 num_regs_saved_in_regs++;
1706 if (i != num_regs_saved_in_regs)
1708 regs_saved_in_regs[i].orig_reg = q->reg;
1709 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1712 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1714 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1716 sreg = INVALID_REGNUM;
1717 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1720 queued_reg_saves = NULL;
1721 last_reg_save_label = NULL;
1724 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1725 location for? Or, does it clobber a register which we've previously
1726 said that some other register is saved in, and for which we now
1727 have a new location for? */
1730 clobbers_queued_reg_save (const_rtx insn)
1732 struct queued_reg_save *q;
1734 for (q = queued_reg_saves; q; q = q->next)
1737 if (modified_in_p (q->reg, insn))
1739 for (i = 0; i < num_regs_saved_in_regs; i++)
1740 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1741 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1748 /* Entry point for saving the first register into the second. */
1751 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1754 unsigned int regno, sregno;
1756 for (i = 0; i < num_regs_saved_in_regs; i++)
1757 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1759 if (i == num_regs_saved_in_regs)
1761 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1762 num_regs_saved_in_regs++;
1764 regs_saved_in_regs[i].orig_reg = reg;
1765 regs_saved_in_regs[i].saved_in_reg = sreg;
1767 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1768 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1769 reg_save (label, regno, sregno, 0);
1772 /* What register, if any, is currently saved in REG? */
1775 reg_saved_in (rtx reg)
1777 unsigned int regn = REGNO (reg);
1779 struct queued_reg_save *q;
1781 for (q = queued_reg_saves; q; q = q->next)
1782 if (q->saved_reg && regn == REGNO (q->saved_reg))
1785 for (i = 0; i < num_regs_saved_in_regs; i++)
1786 if (regs_saved_in_regs[i].saved_in_reg
1787 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1788 return regs_saved_in_regs[i].orig_reg;
1794 /* A temporary register holding an integral value used in adjusting SP
1795 or setting up the store_reg. The "offset" field holds the integer
1796 value, not an offset. */
1797 static dw_cfa_location cfa_temp;
1799 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1802 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1804 memset (&cfa, 0, sizeof (cfa));
1806 switch (GET_CODE (pat))
1809 cfa.reg = REGNO (XEXP (pat, 0));
1810 cfa.offset = INTVAL (XEXP (pat, 1));
1814 cfa.reg = REGNO (pat);
1818 /* Recurse and define an expression. */
1822 def_cfa_1 (label, &cfa);
1825 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1828 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1832 gcc_assert (GET_CODE (pat) == SET);
1833 dest = XEXP (pat, 0);
1834 src = XEXP (pat, 1);
1836 switch (GET_CODE (src))
1839 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1840 cfa.offset -= INTVAL (XEXP (src, 1));
1850 cfa.reg = REGNO (dest);
1851 gcc_assert (cfa.indirect == 0);
1853 def_cfa_1 (label, &cfa);
1856 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1859 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1861 HOST_WIDE_INT offset;
1862 rtx src, addr, span;
1864 src = XEXP (set, 1);
1865 addr = XEXP (set, 0);
1866 gcc_assert (MEM_P (addr));
1867 addr = XEXP (addr, 0);
1869 /* As documented, only consider extremely simple addresses. */
1870 switch (GET_CODE (addr))
1873 gcc_assert (REGNO (addr) == cfa.reg);
1874 offset = -cfa.offset;
1877 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1878 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1884 span = targetm.dwarf_register_span (src);
1886 /* ??? We'd like to use queue_reg_save, but we need to come up with
1887 a different flushing heuristic for epilogues. */
1889 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1892 /* We have a PARALLEL describing where the contents of SRC live.
1893 Queue register saves for each piece of the PARALLEL. */
1896 HOST_WIDE_INT span_offset = offset;
1898 gcc_assert (GET_CODE (span) == PARALLEL);
1900 limit = XVECLEN (span, 0);
1901 for (par_index = 0; par_index < limit; par_index++)
1903 rtx elem = XVECEXP (span, 0, par_index);
1905 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1906 INVALID_REGNUM, span_offset);
1907 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1912 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1915 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1918 unsigned sregno, dregno;
1920 src = XEXP (set, 1);
1921 dest = XEXP (set, 0);
1924 sregno = DWARF_FRAME_RETURN_COLUMN;
1926 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1928 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1930 /* ??? We'd like to use queue_reg_save, but we need to come up with
1931 a different flushing heuristic for epilogues. */
1932 reg_save (label, sregno, dregno, 0);
1935 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1938 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1940 dw_cfi_ref cfi = new_cfi ();
1941 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1943 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1944 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1946 add_fde_cfi (label, cfi);
1949 /* Record call frame debugging information for an expression EXPR,
1950 which either sets SP or FP (adjusting how we calculate the frame
1951 address) or saves a register to the stack or another register.
1952 LABEL indicates the address of EXPR.
1954 This function encodes a state machine mapping rtxes to actions on
1955 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1956 users need not read the source code.
1958 The High-Level Picture
1960 Changes in the register we use to calculate the CFA: Currently we
1961 assume that if you copy the CFA register into another register, we
1962 should take the other one as the new CFA register; this seems to
1963 work pretty well. If it's wrong for some target, it's simple
1964 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1966 Changes in the register we use for saving registers to the stack:
1967 This is usually SP, but not always. Again, we deduce that if you
1968 copy SP into another register (and SP is not the CFA register),
1969 then the new register is the one we will be using for register
1970 saves. This also seems to work.
1972 Register saves: There's not much guesswork about this one; if
1973 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1974 register save, and the register used to calculate the destination
1975 had better be the one we think we're using for this purpose.
1976 It's also assumed that a copy from a call-saved register to another
1977 register is saving that register if RTX_FRAME_RELATED_P is set on
1978 that instruction. If the copy is from a call-saved register to
1979 the *same* register, that means that the register is now the same
1980 value as in the caller.
1982 Except: If the register being saved is the CFA register, and the
1983 offset is nonzero, we are saving the CFA, so we assume we have to
1984 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1985 the intent is to save the value of SP from the previous frame.
1987 In addition, if a register has previously been saved to a different
1990 Invariants / Summaries of Rules
1992 cfa current rule for calculating the CFA. It usually
1993 consists of a register and an offset.
1994 cfa_store register used by prologue code to save things to the stack
1995 cfa_store.offset is the offset from the value of
1996 cfa_store.reg to the actual CFA
1997 cfa_temp register holding an integral value. cfa_temp.offset
1998 stores the value, which will be used to adjust the
1999 stack pointer. cfa_temp is also used like cfa_store,
2000 to track stores to the stack via fp or a temp reg.
2002 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2003 with cfa.reg as the first operand changes the cfa.reg and its
2004 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2007 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2008 expression yielding a constant. This sets cfa_temp.reg
2009 and cfa_temp.offset.
2011 Rule 5: Create a new register cfa_store used to save items to the
2014 Rules 10-14: Save a register to the stack. Define offset as the
2015 difference of the original location and cfa_store's
2016 location (or cfa_temp's location if cfa_temp is used).
2018 Rules 16-20: If AND operation happens on sp in prologue, we assume
2019 stack is realigned. We will use a group of DW_OP_XXX
2020 expressions to represent the location of the stored
2021 register instead of CFA+offset.
2025 "{a,b}" indicates a choice of a xor b.
2026 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2029 (set <reg1> <reg2>:cfa.reg)
2030 effects: cfa.reg = <reg1>
2031 cfa.offset unchanged
2032 cfa_temp.reg = <reg1>
2033 cfa_temp.offset = cfa.offset
2036 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2037 {<const_int>,<reg>:cfa_temp.reg}))
2038 effects: cfa.reg = sp if fp used
2039 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2040 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2041 if cfa_store.reg==sp
2044 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2045 effects: cfa.reg = fp
2046 cfa_offset += +/- <const_int>
2049 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2050 constraints: <reg1> != fp
2052 effects: cfa.reg = <reg1>
2053 cfa_temp.reg = <reg1>
2054 cfa_temp.offset = cfa.offset
2057 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2058 constraints: <reg1> != fp
2060 effects: cfa_store.reg = <reg1>
2061 cfa_store.offset = cfa.offset - cfa_temp.offset
2064 (set <reg> <const_int>)
2065 effects: cfa_temp.reg = <reg>
2066 cfa_temp.offset = <const_int>
2069 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2070 effects: cfa_temp.reg = <reg1>
2071 cfa_temp.offset |= <const_int>
2074 (set <reg> (high <exp>))
2078 (set <reg> (lo_sum <exp> <const_int>))
2079 effects: cfa_temp.reg = <reg>
2080 cfa_temp.offset = <const_int>
2083 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2084 effects: cfa_store.offset -= <const_int>
2085 cfa.offset = cfa_store.offset if cfa.reg == sp
2087 cfa.base_offset = -cfa_store.offset
2090 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
2091 effects: cfa_store.offset += -/+ mode_size(mem)
2092 cfa.offset = cfa_store.offset if cfa.reg == sp
2094 cfa.base_offset = -cfa_store.offset
2097 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2100 effects: cfa.reg = <reg1>
2101 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2104 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2105 effects: cfa.reg = <reg1>
2106 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2109 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
2110 effects: cfa.reg = <reg1>
2111 cfa.base_offset = -cfa_temp.offset
2112 cfa_temp.offset -= mode_size(mem)
2115 (set <reg> {unspec, unspec_volatile})
2116 effects: target-dependent
2119 (set sp (and: sp <const_int>))
2120 constraints: cfa_store.reg == sp
2121 effects: current_fde.stack_realign = 1
2122 cfa_store.offset = 0
2123 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2126 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2127 effects: cfa_store.offset += -/+ mode_size(mem)
2130 (set (mem ({pre_inc, pre_dec} sp)) fp)
2131 constraints: fde->stack_realign == 1
2132 effects: cfa_store.offset = 0
2133 cfa.reg != HARD_FRAME_POINTER_REGNUM
2136 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2137 constraints: fde->stack_realign == 1
2139 && cfa.indirect == 0
2140 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2141 effects: Use DW_CFA_def_cfa_expression to define cfa
2142 cfa.reg == fde->drap_reg
2145 (set reg fde->drap_reg)
2146 constraints: fde->vdrap_reg == INVALID_REGNUM
2147 effects: fde->vdrap_reg = reg.
2148 (set mem fde->drap_reg)
2149 constraints: fde->drap_reg_saved == 1
2153 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2155 rtx src, dest, span;
2156 HOST_WIDE_INT offset;
2159 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2160 the PARALLEL independently. The first element is always processed if
2161 it is a SET. This is for backward compatibility. Other elements
2162 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2163 flag is set in them. */
2164 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2167 int limit = XVECLEN (expr, 0);
2170 /* PARALLELs have strict read-modify-write semantics, so we
2171 ought to evaluate every rvalue before changing any lvalue.
2172 It's cumbersome to do that in general, but there's an
2173 easy approximation that is enough for all current users:
2174 handle register saves before register assignments. */
2175 if (GET_CODE (expr) == PARALLEL)
2176 for (par_index = 0; par_index < limit; par_index++)
2178 elem = XVECEXP (expr, 0, par_index);
2179 if (GET_CODE (elem) == SET
2180 && MEM_P (SET_DEST (elem))
2181 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2182 dwarf2out_frame_debug_expr (elem, label);
2185 for (par_index = 0; par_index < limit; par_index++)
2187 elem = XVECEXP (expr, 0, par_index);
2188 if (GET_CODE (elem) == SET
2189 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2190 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2191 dwarf2out_frame_debug_expr (elem, label);
2192 else if (GET_CODE (elem) == SET
2194 && !RTX_FRAME_RELATED_P (elem))
2196 /* Stack adjustment combining might combine some post-prologue
2197 stack adjustment into a prologue stack adjustment. */
2198 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2201 dwarf2out_args_size_adjust (offset, label);
2207 gcc_assert (GET_CODE (expr) == SET);
2209 src = SET_SRC (expr);
2210 dest = SET_DEST (expr);
2214 rtx rsi = reg_saved_in (src);
2219 fde = current_fde ();
2223 && fde->drap_reg == REGNO (src)
2224 && (fde->drap_reg_saved
2228 /* If we are saving dynamic realign argument pointer to a
2229 register, the destination is virtual dynamic realign
2230 argument pointer. It may be used to access argument. */
2233 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2234 fde->vdrap_reg = REGNO (dest);
2239 switch (GET_CODE (dest))
2242 switch (GET_CODE (src))
2244 /* Setting FP from SP. */
2246 if (cfa.reg == (unsigned) REGNO (src))
2249 /* Update the CFA rule wrt SP or FP. Make sure src is
2250 relative to the current CFA register.
2252 We used to require that dest be either SP or FP, but the
2253 ARM copies SP to a temporary register, and from there to
2254 FP. So we just rely on the backends to only set
2255 RTX_FRAME_RELATED_P on appropriate insns. */
2256 cfa.reg = REGNO (dest);
2257 cfa_temp.reg = cfa.reg;
2258 cfa_temp.offset = cfa.offset;
2262 /* Saving a register in a register. */
2263 gcc_assert (!fixed_regs [REGNO (dest)]
2264 /* For the SPARC and its register window. */
2265 || (DWARF_FRAME_REGNUM (REGNO (src))
2266 == DWARF_FRAME_RETURN_COLUMN));
2268 /* After stack is aligned, we can only save SP in FP
2269 if drap register is used. In this case, we have
2270 to restore stack pointer with the CFA value and we
2271 don't generate this DWARF information. */
2273 && fde->stack_realign
2274 && REGNO (src) == STACK_POINTER_REGNUM)
2275 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2276 && fde->drap_reg != INVALID_REGNUM
2277 && cfa.reg != REGNO (src));
2279 queue_reg_save (label, src, dest, 0);
2286 if (dest == stack_pointer_rtx)
2290 switch (GET_CODE (XEXP (src, 1)))
2293 offset = INTVAL (XEXP (src, 1));
2296 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2298 offset = cfa_temp.offset;
2304 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2306 /* Restoring SP from FP in the epilogue. */
2307 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2308 cfa.reg = STACK_POINTER_REGNUM;
2310 else if (GET_CODE (src) == LO_SUM)
2311 /* Assume we've set the source reg of the LO_SUM from sp. */
2314 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2316 if (GET_CODE (src) != MINUS)
2318 if (cfa.reg == STACK_POINTER_REGNUM)
2319 cfa.offset += offset;
2320 if (cfa_store.reg == STACK_POINTER_REGNUM)
2321 cfa_store.offset += offset;
2323 else if (dest == hard_frame_pointer_rtx)
2326 /* Either setting the FP from an offset of the SP,
2327 or adjusting the FP */
2328 gcc_assert (frame_pointer_needed);
2330 gcc_assert (REG_P (XEXP (src, 0))
2331 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2332 && CONST_INT_P (XEXP (src, 1)));
2333 offset = INTVAL (XEXP (src, 1));
2334 if (GET_CODE (src) != MINUS)
2336 cfa.offset += offset;
2337 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2341 gcc_assert (GET_CODE (src) != MINUS);
2344 if (REG_P (XEXP (src, 0))
2345 && REGNO (XEXP (src, 0)) == cfa.reg
2346 && CONST_INT_P (XEXP (src, 1)))
2348 /* Setting a temporary CFA register that will be copied
2349 into the FP later on. */
2350 offset = - INTVAL (XEXP (src, 1));
2351 cfa.offset += offset;
2352 cfa.reg = REGNO (dest);
2353 /* Or used to save regs to the stack. */
2354 cfa_temp.reg = cfa.reg;
2355 cfa_temp.offset = cfa.offset;
2359 else if (REG_P (XEXP (src, 0))
2360 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2361 && XEXP (src, 1) == stack_pointer_rtx)
2363 /* Setting a scratch register that we will use instead
2364 of SP for saving registers to the stack. */
2365 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2366 cfa_store.reg = REGNO (dest);
2367 cfa_store.offset = cfa.offset - cfa_temp.offset;
2371 else if (GET_CODE (src) == LO_SUM
2372 && CONST_INT_P (XEXP (src, 1)))
2374 cfa_temp.reg = REGNO (dest);
2375 cfa_temp.offset = INTVAL (XEXP (src, 1));
2384 cfa_temp.reg = REGNO (dest);
2385 cfa_temp.offset = INTVAL (src);
2390 gcc_assert (REG_P (XEXP (src, 0))
2391 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2392 && CONST_INT_P (XEXP (src, 1)));
2394 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2395 cfa_temp.reg = REGNO (dest);
2396 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2399 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2400 which will fill in all of the bits. */
2407 case UNSPEC_VOLATILE:
2408 gcc_assert (targetm.dwarf_handle_frame_unspec);
2409 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2414 /* If this AND operation happens on stack pointer in prologue,
2415 we assume the stack is realigned and we extract the
2417 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2419 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2420 fde->stack_realign = 1;
2421 fde->stack_realignment = INTVAL (XEXP (src, 1));
2422 cfa_store.offset = 0;
2424 if (cfa.reg != STACK_POINTER_REGNUM
2425 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2426 fde->drap_reg = cfa.reg;
2434 def_cfa_1 (label, &cfa);
2439 /* Saving a register to the stack. Make sure dest is relative to the
2441 switch (GET_CODE (XEXP (dest, 0)))
2446 /* We can't handle variable size modifications. */
2447 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2449 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2451 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2452 && cfa_store.reg == STACK_POINTER_REGNUM);
2454 cfa_store.offset += offset;
2455 if (cfa.reg == STACK_POINTER_REGNUM)
2456 cfa.offset = cfa_store.offset;
2458 offset = -cfa_store.offset;
2464 offset = GET_MODE_SIZE (GET_MODE (dest));
2465 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2468 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2469 == STACK_POINTER_REGNUM)
2470 && cfa_store.reg == STACK_POINTER_REGNUM);
2472 cfa_store.offset += offset;
2474 /* Rule 18: If stack is aligned, we will use FP as a
2475 reference to represent the address of the stored
2478 && fde->stack_realign
2479 && src == hard_frame_pointer_rtx)
2481 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2482 cfa_store.offset = 0;
2485 if (cfa.reg == STACK_POINTER_REGNUM)
2486 cfa.offset = cfa_store.offset;
2488 offset = -cfa_store.offset;
2492 /* With an offset. */
2499 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2500 && REG_P (XEXP (XEXP (dest, 0), 0)));
2501 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2502 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2505 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2507 if (cfa_store.reg == (unsigned) regno)
2508 offset -= cfa_store.offset;
2511 gcc_assert (cfa_temp.reg == (unsigned) regno);
2512 offset -= cfa_temp.offset;
2518 /* Without an offset. */
2521 int regno = REGNO (XEXP (dest, 0));
2523 if (cfa_store.reg == (unsigned) regno)
2524 offset = -cfa_store.offset;
2527 gcc_assert (cfa_temp.reg == (unsigned) regno);
2528 offset = -cfa_temp.offset;
2535 gcc_assert (cfa_temp.reg
2536 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2537 offset = -cfa_temp.offset;
2538 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2546 /* If the source operand of this MEM operation is not a
2547 register, basically the source is return address. Here
2548 we only care how much stack grew and we don't save it. */
2552 if (REGNO (src) != STACK_POINTER_REGNUM
2553 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2554 && (unsigned) REGNO (src) == cfa.reg)
2556 /* We're storing the current CFA reg into the stack. */
2558 if (cfa.offset == 0)
2561 /* If stack is aligned, putting CFA reg into stack means
2562 we can no longer use reg + offset to represent CFA.
2563 Here we use DW_CFA_def_cfa_expression instead. The
2564 result of this expression equals to the original CFA
2567 && fde->stack_realign
2568 && cfa.indirect == 0
2569 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2571 dw_cfa_location cfa_exp;
2573 gcc_assert (fde->drap_reg == cfa.reg);
2575 cfa_exp.indirect = 1;
2576 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2577 cfa_exp.base_offset = offset;
2580 fde->drap_reg_saved = 1;
2582 def_cfa_1 (label, &cfa_exp);
2586 /* If the source register is exactly the CFA, assume
2587 we're saving SP like any other register; this happens
2589 def_cfa_1 (label, &cfa);
2590 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2595 /* Otherwise, we'll need to look in the stack to
2596 calculate the CFA. */
2597 rtx x = XEXP (dest, 0);
2601 gcc_assert (REG_P (x));
2603 cfa.reg = REGNO (x);
2604 cfa.base_offset = offset;
2606 def_cfa_1 (label, &cfa);
2611 def_cfa_1 (label, &cfa);
2613 span = targetm.dwarf_register_span (src);
2616 queue_reg_save (label, src, NULL_RTX, offset);
2619 /* We have a PARALLEL describing where the contents of SRC
2620 live. Queue register saves for each piece of the
2624 HOST_WIDE_INT span_offset = offset;
2626 gcc_assert (GET_CODE (span) == PARALLEL);
2628 limit = XVECLEN (span, 0);
2629 for (par_index = 0; par_index < limit; par_index++)
2631 rtx elem = XVECEXP (span, 0, par_index);
2633 queue_reg_save (label, elem, NULL_RTX, span_offset);
2634 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2645 /* Record call frame debugging information for INSN, which either
2646 sets SP or FP (adjusting how we calculate the frame address) or saves a
2647 register to the stack. If INSN is NULL_RTX, initialize our state.
2649 If AFTER_P is false, we're being called before the insn is emitted,
2650 otherwise after. Call instructions get invoked twice. */
2653 dwarf2out_frame_debug (rtx insn, bool after_p)
2657 bool handled_one = false;
2659 if (insn == NULL_RTX)
2663 /* Flush any queued register saves. */
2664 flush_queued_reg_saves ();
2666 /* Set up state for generating call frame debug info. */
2669 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2671 cfa.reg = STACK_POINTER_REGNUM;
2674 cfa_temp.offset = 0;
2676 for (i = 0; i < num_regs_saved_in_regs; i++)
2678 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2679 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2681 num_regs_saved_in_regs = 0;
2683 if (barrier_args_size)
2685 XDELETEVEC (barrier_args_size);
2686 barrier_args_size = NULL;
2691 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2692 flush_queued_reg_saves ();
2694 if (! RTX_FRAME_RELATED_P (insn))
2696 if (!ACCUMULATE_OUTGOING_ARGS)
2697 dwarf2out_stack_adjust (insn, after_p);
2701 label = dwarf2out_cfi_label (false);
2703 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2704 switch (REG_NOTE_KIND (note))
2706 case REG_FRAME_RELATED_EXPR:
2707 insn = XEXP (note, 0);
2710 case REG_CFA_DEF_CFA:
2711 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2715 case REG_CFA_ADJUST_CFA:
2720 if (GET_CODE (n) == PARALLEL)
2721 n = XVECEXP (n, 0, 0);
2723 dwarf2out_frame_debug_adjust_cfa (n, label);
2727 case REG_CFA_OFFSET:
2730 n = single_set (insn);
2731 dwarf2out_frame_debug_cfa_offset (n, label);
2735 case REG_CFA_REGISTER:
2740 if (GET_CODE (n) == PARALLEL)
2741 n = XVECEXP (n, 0, 0);
2743 dwarf2out_frame_debug_cfa_register (n, label);
2747 case REG_CFA_RESTORE:
2752 if (GET_CODE (n) == PARALLEL)
2753 n = XVECEXP (n, 0, 0);
2756 dwarf2out_frame_debug_cfa_restore (n, label);
2766 insn = PATTERN (insn);
2768 dwarf2out_frame_debug_expr (insn, label);
2771 /* Determine if we need to save and restore CFI information around this
2772 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2773 we do need to save/restore, then emit the save now, and insert a
2774 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2777 dwarf2out_begin_epilogue (rtx insn)
2779 bool saw_frp = false;
2782 /* Scan forward to the return insn, noticing if there are possible
2783 frame related insns. */
2784 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2789 /* Look for both regular and sibcalls to end the block. */
2790 if (returnjump_p (i))
2792 if (CALL_P (i) && SIBLING_CALL_P (i))
2795 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2798 rtx seq = PATTERN (i);
2800 if (returnjump_p (XVECEXP (seq, 0, 0)))
2802 if (CALL_P (XVECEXP (seq, 0, 0))
2803 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2806 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2807 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2811 if (RTX_FRAME_RELATED_P (i))
2815 /* If the port doesn't emit epilogue unwind info, we don't need a
2816 save/restore pair. */
2820 /* Otherwise, search forward to see if the return insn was the last
2821 basic block of the function. If so, we don't need save/restore. */
2822 gcc_assert (i != NULL);
2823 i = next_real_insn (i);
2827 /* Insert the restore before that next real insn in the stream, and before
2828 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2829 properly nested. This should be after any label or alignment. This
2830 will be pushed into the CFI stream by the function below. */
2833 rtx p = PREV_INSN (i);
2836 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2840 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2842 emit_cfa_remember = true;
2844 /* And emulate the state save. */
2845 gcc_assert (!cfa_remember.in_use);
2847 cfa_remember.in_use = 1;
2850 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2853 dwarf2out_frame_debug_restore_state (void)
2855 dw_cfi_ref cfi = new_cfi ();
2856 const char *label = dwarf2out_cfi_label (false);
2858 cfi->dw_cfi_opc = DW_CFA_restore_state;
2859 add_fde_cfi (label, cfi);
2861 gcc_assert (cfa_remember.in_use);
2863 cfa_remember.in_use = 0;
2868 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2869 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2870 (enum dwarf_call_frame_info cfi);
2872 static enum dw_cfi_oprnd_type
2873 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2878 case DW_CFA_GNU_window_save:
2879 case DW_CFA_remember_state:
2880 case DW_CFA_restore_state:
2881 return dw_cfi_oprnd_unused;
2883 case DW_CFA_set_loc:
2884 case DW_CFA_advance_loc1:
2885 case DW_CFA_advance_loc2:
2886 case DW_CFA_advance_loc4:
2887 case DW_CFA_MIPS_advance_loc8:
2888 return dw_cfi_oprnd_addr;
2891 case DW_CFA_offset_extended:
2892 case DW_CFA_def_cfa:
2893 case DW_CFA_offset_extended_sf:
2894 case DW_CFA_def_cfa_sf:
2895 case DW_CFA_restore:
2896 case DW_CFA_restore_extended:
2897 case DW_CFA_undefined:
2898 case DW_CFA_same_value:
2899 case DW_CFA_def_cfa_register:
2900 case DW_CFA_register:
2901 return dw_cfi_oprnd_reg_num;
2903 case DW_CFA_def_cfa_offset:
2904 case DW_CFA_GNU_args_size:
2905 case DW_CFA_def_cfa_offset_sf:
2906 return dw_cfi_oprnd_offset;
2908 case DW_CFA_def_cfa_expression:
2909 case DW_CFA_expression:
2910 return dw_cfi_oprnd_loc;
2917 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2918 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2919 (enum dwarf_call_frame_info cfi);
2921 static enum dw_cfi_oprnd_type
2922 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2926 case DW_CFA_def_cfa:
2927 case DW_CFA_def_cfa_sf:
2929 case DW_CFA_offset_extended_sf:
2930 case DW_CFA_offset_extended:
2931 return dw_cfi_oprnd_offset;
2933 case DW_CFA_register:
2934 return dw_cfi_oprnd_reg_num;
2937 return dw_cfi_oprnd_unused;
2941 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2943 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
2944 switch to the data section instead, and write out a synthetic start label
2945 for collect2 the first time around. */
2948 switch_to_eh_frame_section (bool back)
2952 #ifdef EH_FRAME_SECTION_NAME
2953 if (eh_frame_section == 0)
2957 if (EH_TABLES_CAN_BE_READ_ONLY)
2963 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2965 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2967 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2969 flags = ((! flag_pic
2970 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2971 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2972 && (per_encoding & 0x70) != DW_EH_PE_absptr
2973 && (per_encoding & 0x70) != DW_EH_PE_aligned
2974 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2975 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2976 ? 0 : SECTION_WRITE);
2979 flags = SECTION_WRITE;
2980 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2984 if (eh_frame_section)
2985 switch_to_section (eh_frame_section);
2988 /* We have no special eh_frame section. Put the information in
2989 the data section and emit special labels to guide collect2. */
2990 switch_to_section (data_section);
2994 label = get_file_function_name ("F");
2995 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2996 targetm.asm_out.globalize_label (asm_out_file,
2997 IDENTIFIER_POINTER (label));
2998 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3003 /* Switch [BACK] to the eh or debug frame table section, depending on
3007 switch_to_frame_table_section (int for_eh, bool back)
3010 switch_to_eh_frame_section (back);
3013 if (!debug_frame_section)
3014 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3015 SECTION_DEBUG, NULL);
3016 switch_to_section (debug_frame_section);
3020 /* Output a Call Frame Information opcode and its operand(s). */
3023 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3028 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3029 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3030 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3031 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3032 ((unsigned HOST_WIDE_INT)
3033 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3034 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3036 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3037 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3038 "DW_CFA_offset, column 0x%lx", r);
3039 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3040 dw2_asm_output_data_uleb128 (off, NULL);
3042 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3044 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3045 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3046 "DW_CFA_restore, column 0x%lx", r);
3050 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3051 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3053 switch (cfi->dw_cfi_opc)
3055 case DW_CFA_set_loc:
3057 dw2_asm_output_encoded_addr_rtx (
3058 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3059 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3062 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3063 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3064 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3067 case DW_CFA_advance_loc1:
3068 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3069 fde->dw_fde_current_label, NULL);
3070 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3073 case DW_CFA_advance_loc2:
3074 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3075 fde->dw_fde_current_label, NULL);
3076 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3079 case DW_CFA_advance_loc4:
3080 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3081 fde->dw_fde_current_label, NULL);
3082 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3085 case DW_CFA_MIPS_advance_loc8:
3086 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3087 fde->dw_fde_current_label, NULL);
3088 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3091 case DW_CFA_offset_extended:
3092 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3093 dw2_asm_output_data_uleb128 (r, NULL);
3094 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3095 dw2_asm_output_data_uleb128 (off, NULL);
3098 case DW_CFA_def_cfa:
3099 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3100 dw2_asm_output_data_uleb128 (r, NULL);
3101 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3104 case DW_CFA_offset_extended_sf:
3105 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3106 dw2_asm_output_data_uleb128 (r, NULL);
3107 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3108 dw2_asm_output_data_sleb128 (off, NULL);
3111 case DW_CFA_def_cfa_sf:
3112 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3113 dw2_asm_output_data_uleb128 (r, NULL);
3114 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3115 dw2_asm_output_data_sleb128 (off, NULL);
3118 case DW_CFA_restore_extended:
3119 case DW_CFA_undefined:
3120 case DW_CFA_same_value:
3121 case DW_CFA_def_cfa_register:
3122 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3123 dw2_asm_output_data_uleb128 (r, NULL);
3126 case DW_CFA_register:
3127 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3128 dw2_asm_output_data_uleb128 (r, NULL);
3129 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3130 dw2_asm_output_data_uleb128 (r, NULL);
3133 case DW_CFA_def_cfa_offset:
3134 case DW_CFA_GNU_args_size:
3135 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3138 case DW_CFA_def_cfa_offset_sf:
3139 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3140 dw2_asm_output_data_sleb128 (off, NULL);
3143 case DW_CFA_GNU_window_save:
3146 case DW_CFA_def_cfa_expression:
3147 case DW_CFA_expression:
3148 output_cfa_loc (cfi);
3151 case DW_CFA_GNU_negative_offset_extended:
3152 /* Obsoleted by DW_CFA_offset_extended_sf. */
3161 /* Similar, but do it via assembler directives instead. */
3164 output_cfi_directive (dw_cfi_ref cfi)
3166 unsigned long r, r2;
3168 switch (cfi->dw_cfi_opc)
3170 case DW_CFA_advance_loc:
3171 case DW_CFA_advance_loc1:
3172 case DW_CFA_advance_loc2:
3173 case DW_CFA_advance_loc4:
3174 case DW_CFA_MIPS_advance_loc8:
3175 case DW_CFA_set_loc:
3176 /* Should only be created by add_fde_cfi in a code path not
3177 followed when emitting via directives. The assembler is
3178 going to take care of this for us. */
3182 case DW_CFA_offset_extended:
3183 case DW_CFA_offset_extended_sf:
3184 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3185 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3186 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3189 case DW_CFA_restore:
3190 case DW_CFA_restore_extended:
3191 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3192 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3195 case DW_CFA_undefined:
3196 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3197 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3200 case DW_CFA_same_value:
3201 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3202 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3205 case DW_CFA_def_cfa:
3206 case DW_CFA_def_cfa_sf:
3207 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3208 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3209 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3212 case DW_CFA_def_cfa_register:
3213 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3214 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3217 case DW_CFA_register:
3218 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3219 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3220 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3223 case DW_CFA_def_cfa_offset:
3224 case DW_CFA_def_cfa_offset_sf:
3225 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3226 HOST_WIDE_INT_PRINT_DEC"\n",
3227 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3230 case DW_CFA_remember_state:
3231 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3233 case DW_CFA_restore_state:
3234 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3237 case DW_CFA_GNU_args_size:
3238 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3239 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3241 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3242 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3243 fputc ('\n', asm_out_file);
3246 case DW_CFA_GNU_window_save:
3247 fprintf (asm_out_file, "\t.cfi_window_save\n");
3250 case DW_CFA_def_cfa_expression:
3251 case DW_CFA_expression:
3252 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3253 output_cfa_loc_raw (cfi);
3254 fputc ('\n', asm_out_file);
3262 DEF_VEC_P (dw_cfi_ref);
3263 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3265 /* Output CFIs to bring current FDE to the same state as after executing
3266 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3267 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3268 other arguments to pass to output_cfi. */
3271 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3273 struct dw_cfi_struct cfi_buf;
3275 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3276 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3277 unsigned int len, idx;
3279 for (;; cfi = cfi->dw_cfi_next)
3280 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3282 case DW_CFA_advance_loc:
3283 case DW_CFA_advance_loc1:
3284 case DW_CFA_advance_loc2:
3285 case DW_CFA_advance_loc4:
3286 case DW_CFA_MIPS_advance_loc8:
3287 case DW_CFA_set_loc:
3288 /* All advances should be ignored. */
3290 case DW_CFA_remember_state:
3292 dw_cfi_ref args_size = cfi_args_size;
3294 /* Skip everything between .cfi_remember_state and
3295 .cfi_restore_state. */
3296 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3297 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3299 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3302 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3309 cfi_args_size = args_size;
3313 case DW_CFA_GNU_args_size:
3314 cfi_args_size = cfi;
3316 case DW_CFA_GNU_window_save:
3319 case DW_CFA_offset_extended:
3320 case DW_CFA_offset_extended_sf:
3321 case DW_CFA_restore:
3322 case DW_CFA_restore_extended:
3323 case DW_CFA_undefined:
3324 case DW_CFA_same_value:
3325 case DW_CFA_register:
3326 case DW_CFA_val_offset:
3327 case DW_CFA_val_offset_sf:
3328 case DW_CFA_expression:
3329 case DW_CFA_val_expression:
3330 case DW_CFA_GNU_negative_offset_extended:
3331 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3332 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3333 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3334 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3336 case DW_CFA_def_cfa:
3337 case DW_CFA_def_cfa_sf:
3338 case DW_CFA_def_cfa_expression:
3340 cfi_cfa_offset = cfi;
3342 case DW_CFA_def_cfa_register:
3345 case DW_CFA_def_cfa_offset:
3346 case DW_CFA_def_cfa_offset_sf:
3347 cfi_cfa_offset = cfi;
3350 gcc_assert (cfi == NULL);
3352 len = VEC_length (dw_cfi_ref, regs);
3353 for (idx = 0; idx < len; idx++)
3355 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3357 && cfi2->dw_cfi_opc != DW_CFA_restore
3358 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3361 output_cfi_directive (cfi2);
3363 output_cfi (cfi2, fde, for_eh);
3366 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3368 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3370 switch (cfi_cfa_offset->dw_cfi_opc)
3372 case DW_CFA_def_cfa_offset:
3373 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3374 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3376 case DW_CFA_def_cfa_offset_sf:
3377 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3378 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3380 case DW_CFA_def_cfa:
3381 case DW_CFA_def_cfa_sf:
3382 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3383 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3390 else if (cfi_cfa_offset)
3391 cfi_cfa = cfi_cfa_offset;
3395 output_cfi_directive (cfi_cfa);
3397 output_cfi (cfi_cfa, fde, for_eh);
3400 cfi_cfa_offset = NULL;
3402 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3405 output_cfi_directive (cfi_args_size);
3407 output_cfi (cfi_args_size, fde, for_eh);
3409 cfi_args_size = NULL;
3412 VEC_free (dw_cfi_ref, heap, regs);
3415 else if (do_cfi_asm)
3416 output_cfi_directive (cfi);
3418 output_cfi (cfi, fde, for_eh);
3425 /* Output one FDE. */
3428 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3429 char *section_start_label, int fde_encoding, char *augmentation,
3430 bool any_lsda_needed, int lsda_encoding)
3432 const char *begin, *end;
3433 static unsigned int j;
3434 char l1[20], l2[20];
3437 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh,
3439 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3441 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3442 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3443 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3444 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3445 " indicating 64-bit DWARF extension");
3446 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3448 ASM_OUTPUT_LABEL (asm_out_file, l1);
3451 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3453 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3454 debug_frame_section, "FDE CIE offset");
3456 if (!fde->dw_fde_switched_sections)
3458 begin = fde->dw_fde_begin;
3459 end = fde->dw_fde_end;
3463 /* For the first section, prefer dw_fde_begin over
3464 dw_fde_{hot,cold}_section_label, as the latter
3465 might be separated from the real start of the
3466 function by alignment padding. */
3468 begin = fde->dw_fde_begin;
3469 else if (fde->dw_fde_switched_cold_to_hot)
3470 begin = fde->dw_fde_hot_section_label;
3472 begin = fde->dw_fde_unlikely_section_label;
3473 if (second ^ fde->dw_fde_switched_cold_to_hot)
3474 end = fde->dw_fde_unlikely_section_end_label;
3476 end = fde->dw_fde_hot_section_end_label;
3481 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3482 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3483 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3484 "FDE initial location");
3485 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3486 end, begin, "FDE address range");
3490 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3491 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3494 if (augmentation[0])
3496 if (any_lsda_needed)
3498 int size = size_of_encoded_value (lsda_encoding);
3500 if (lsda_encoding == DW_EH_PE_aligned)
3502 int offset = ( 4 /* Length */
3503 + 4 /* CIE offset */
3504 + 2 * size_of_encoded_value (fde_encoding)
3505 + 1 /* Augmentation size */ );
3506 int pad = -offset & (PTR_SIZE - 1);
3509 gcc_assert (size_of_uleb128 (size) == 1);
3512 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3514 if (fde->uses_eh_lsda)
3516 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3517 fde->funcdef_number);
3518 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3519 gen_rtx_SYMBOL_REF (Pmode, l1),
3521 "Language Specific Data Area");
3525 if (lsda_encoding == DW_EH_PE_aligned)
3526 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3527 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3528 "Language Specific Data Area (none)");
3532 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3535 /* Loop through the Call Frame Instructions associated with
3537 fde->dw_fde_current_label = begin;
3538 if (!fde->dw_fde_switched_sections)
3539 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3540 output_cfi (cfi, fde, for_eh);
3543 if (fde->dw_fde_switch_cfi)
3544 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3546 output_cfi (cfi, fde, for_eh);
3547 if (cfi == fde->dw_fde_switch_cfi)
3553 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3555 if (fde->dw_fde_switch_cfi)
3557 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3558 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3559 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3560 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3562 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3563 output_cfi (cfi, fde, for_eh);
3566 /* If we are to emit a ref/link from function bodies to their frame tables,
3567 do it now. This is typically performed to make sure that tables
3568 associated with functions are dragged with them and not discarded in
3569 garbage collecting links. We need to do this on a per function basis to
3570 cope with -ffunction-sections. */
3572 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3573 /* Switch to the function section, emit the ref to the tables, and
3574 switch *back* into the table section. */
3575 switch_to_section (function_section (fde->decl));
3576 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3577 switch_to_frame_table_section (for_eh, true);
3580 /* Pad the FDE out to an address sized boundary. */
3581 ASM_OUTPUT_ALIGN (asm_out_file,
3582 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3583 ASM_OUTPUT_LABEL (asm_out_file, l2);
3588 /* Output the call frame information used to record information
3589 that relates to calculating the frame pointer, and records the
3590 location of saved registers. */
3593 output_call_frame_info (int for_eh)
3598 char l1[20], l2[20], section_start_label[20];
3599 bool any_lsda_needed = false;
3600 char augmentation[6];
3601 int augmentation_size;
3602 int fde_encoding = DW_EH_PE_absptr;
3603 int per_encoding = DW_EH_PE_absptr;
3604 int lsda_encoding = DW_EH_PE_absptr;
3606 rtx personality = NULL;
3609 /* Don't emit a CIE if there won't be any FDEs. */
3610 if (fde_table_in_use == 0)
3613 /* Nothing to do if the assembler's doing it all. */
3614 if (dwarf2out_do_cfi_asm ())
3617 /* If we make FDEs linkonce, we may have to emit an empty label for
3618 an FDE that wouldn't otherwise be emitted. We want to avoid
3619 having an FDE kept around when the function it refers to is
3620 discarded. Example where this matters: a primary function
3621 template in C++ requires EH information, but an explicit
3622 specialization doesn't. */
3623 if (TARGET_USES_WEAK_UNWIND_INFO
3624 && ! flag_asynchronous_unwind_tables
3627 for (i = 0; i < fde_table_in_use; i++)
3628 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3629 && !fde_table[i].uses_eh_lsda
3630 && ! DECL_WEAK (fde_table[i].decl))
3631 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3632 for_eh, /* empty */ 1);
3634 /* If we don't have any functions we'll want to unwind out of, don't
3635 emit any EH unwind information. Note that if exceptions aren't
3636 enabled, we won't have collected nothrow information, and if we
3637 asked for asynchronous tables, we always want this info. */
3640 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3642 for (i = 0; i < fde_table_in_use; i++)
3643 if (fde_table[i].uses_eh_lsda)
3644 any_eh_needed = any_lsda_needed = true;
3645 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3646 any_eh_needed = true;
3647 else if (! fde_table[i].nothrow
3648 && ! fde_table[i].all_throwers_are_sibcalls)
3649 any_eh_needed = true;
3651 if (! any_eh_needed)
3655 /* We're going to be generating comments, so turn on app. */
3659 /* Switch to the proper frame section, first time. */
3660 switch_to_frame_table_section (for_eh, false);
3662 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3663 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3665 /* Output the CIE. */
3666 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3667 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3668 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3669 dw2_asm_output_data (4, 0xffffffff,
3670 "Initial length escape value indicating 64-bit DWARF extension");
3671 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3672 "Length of Common Information Entry");
3673 ASM_OUTPUT_LABEL (asm_out_file, l1);
3675 /* Now that the CIE pointer is PC-relative for EH,
3676 use 0 to identify the CIE. */
3677 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3678 (for_eh ? 0 : DWARF_CIE_ID),
3679 "CIE Identifier Tag");
3681 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3682 use CIE version 1, unless that would produce incorrect results
3683 due to overflowing the return register column. */
3684 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3686 if (return_reg >= 256 || dwarf_version > 2)
3688 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3690 augmentation[0] = 0;
3691 augmentation_size = 0;
3693 personality = current_unit_personality;
3699 z Indicates that a uleb128 is present to size the
3700 augmentation section.
3701 L Indicates the encoding (and thus presence) of
3702 an LSDA pointer in the FDE augmentation.
3703 R Indicates a non-default pointer encoding for
3705 P Indicates the presence of an encoding + language
3706 personality routine in the CIE augmentation. */
3708 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3709 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3710 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3712 p = augmentation + 1;
3716 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3717 assemble_external_libcall (personality);
3719 if (any_lsda_needed)
3722 augmentation_size += 1;
3724 if (fde_encoding != DW_EH_PE_absptr)
3727 augmentation_size += 1;
3729 if (p > augmentation + 1)
3731 augmentation[0] = 'z';
3735 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3736 if (personality && per_encoding == DW_EH_PE_aligned)
3738 int offset = ( 4 /* Length */
3740 + 1 /* CIE version */
3741 + strlen (augmentation) + 1 /* Augmentation */
3742 + size_of_uleb128 (1) /* Code alignment */
3743 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3745 + 1 /* Augmentation size */
3746 + 1 /* Personality encoding */ );
3747 int pad = -offset & (PTR_SIZE - 1);
3749 augmentation_size += pad;
3751 /* Augmentations should be small, so there's scarce need to
3752 iterate for a solution. Die if we exceed one uleb128 byte. */
3753 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3757 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3758 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3759 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3760 "CIE Data Alignment Factor");
3762 if (dw_cie_version == 1)
3763 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3765 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3767 if (augmentation[0])
3769 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3772 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3773 eh_data_format_name (per_encoding));
3774 dw2_asm_output_encoded_addr_rtx (per_encoding,
3779 if (any_lsda_needed)
3780 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3781 eh_data_format_name (lsda_encoding));
3783 if (fde_encoding != DW_EH_PE_absptr)
3784 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3785 eh_data_format_name (fde_encoding));
3788 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3789 output_cfi (cfi, NULL, for_eh);
3791 /* Pad the CIE out to an address sized boundary. */
3792 ASM_OUTPUT_ALIGN (asm_out_file,
3793 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3794 ASM_OUTPUT_LABEL (asm_out_file, l2);
3796 /* Loop through all of the FDE's. */
3797 for (i = 0; i < fde_table_in_use; i++)
3800 fde = &fde_table[i];
3802 /* Don't emit EH unwind info for leaf functions that don't need it. */
3803 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3804 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3805 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3806 && !fde->uses_eh_lsda)
3809 for (k = 0; k < (fde->dw_fde_switched_sections ? 2 : 1); k++)
3810 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3811 augmentation, any_lsda_needed, lsda_encoding);
3814 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3815 dw2_asm_output_data (4, 0, "End of Table");
3816 #ifdef MIPS_DEBUGGING_INFO
3817 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3818 get a value of 0. Putting .align 0 after the label fixes it. */
3819 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3822 /* Turn off app to make assembly quicker. */
3827 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3830 dwarf2out_do_cfi_startproc (bool second)
3834 rtx personality = get_personality_function (current_function_decl);
3836 fprintf (asm_out_file, "\t.cfi_startproc\n");
3840 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3843 /* ??? The GAS support isn't entirely consistent. We have to
3844 handle indirect support ourselves, but PC-relative is done
3845 in the assembler. Further, the assembler can't handle any
3846 of the weirder relocation types. */
3847 if (enc & DW_EH_PE_indirect)
3848 ref = dw2_force_const_mem (ref, true);
3850 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3851 output_addr_const (asm_out_file, ref);
3852 fputc ('\n', asm_out_file);
3855 if (crtl->uses_eh_lsda)
3859 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3860 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
3861 current_function_funcdef_no);
3862 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3863 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3865 if (enc & DW_EH_PE_indirect)
3866 ref = dw2_force_const_mem (ref, true);
3868 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3869 output_addr_const (asm_out_file, ref);
3870 fputc ('\n', asm_out_file);
3874 /* Output a marker (i.e. a label) for the beginning of a function, before
3878 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3879 const char *file ATTRIBUTE_UNUSED)
3881 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3886 current_function_func_begin_label = NULL;
3888 #ifdef TARGET_UNWIND_INFO
3889 /* ??? current_function_func_begin_label is also used by except.c
3890 for call-site information. We must emit this label if it might
3892 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3893 && ! dwarf2out_do_frame ())
3896 if (! dwarf2out_do_frame ())
3900 fnsec = function_section (current_function_decl);
3901 switch_to_section (fnsec);
3902 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3903 current_function_funcdef_no);
3904 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3905 current_function_funcdef_no);
3906 dup_label = xstrdup (label);
3907 current_function_func_begin_label = dup_label;
3909 #ifdef TARGET_UNWIND_INFO
3910 /* We can elide the fde allocation if we're not emitting debug info. */
3911 if (! dwarf2out_do_frame ())
3915 /* Expand the fde table if necessary. */
3916 if (fde_table_in_use == fde_table_allocated)
3918 fde_table_allocated += FDE_TABLE_INCREMENT;
3919 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3920 memset (fde_table + fde_table_in_use, 0,
3921 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3924 /* Record the FDE associated with this function. */
3925 current_funcdef_fde = fde_table_in_use;
3927 /* Add the new FDE at the end of the fde_table. */
3928 fde = &fde_table[fde_table_in_use++];
3929 fde->decl = current_function_decl;
3930 fde->dw_fde_begin = dup_label;
3931 fde->dw_fde_current_label = dup_label;
3932 fde->dw_fde_hot_section_label = NULL;
3933 fde->dw_fde_hot_section_end_label = NULL;
3934 fde->dw_fde_unlikely_section_label = NULL;
3935 fde->dw_fde_unlikely_section_end_label = NULL;
3936 fde->dw_fde_switched_sections = 0;
3937 fde->dw_fde_switched_cold_to_hot = 0;
3938 fde->dw_fde_end = NULL;
3939 fde->dw_fde_cfi = NULL;
3940 fde->dw_fde_switch_cfi = NULL;
3941 fde->funcdef_number = current_function_funcdef_no;
3942 fde->nothrow = crtl->nothrow;
3943 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3944 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3945 fde->drap_reg = INVALID_REGNUM;
3946 fde->vdrap_reg = INVALID_REGNUM;
3947 if (flag_reorder_blocks_and_partition)
3949 section *unlikelysec;
3950 if (first_function_block_is_cold)
3951 fde->in_std_section = 1;
3954 = (fnsec == text_section
3955 || (cold_text_section && fnsec == cold_text_section));
3956 unlikelysec = unlikely_text_section ();
3957 fde->cold_in_std_section
3958 = (unlikelysec == text_section
3959 || (cold_text_section && unlikelysec == cold_text_section));
3964 = (fnsec == text_section
3965 || (cold_text_section && fnsec == cold_text_section));
3966 fde->cold_in_std_section = 0;
3969 args_size = old_args_size = 0;
3971 /* We only want to output line number information for the genuine dwarf2
3972 prologue case, not the eh frame case. */
3973 #ifdef DWARF2_DEBUGGING_INFO
3975 dwarf2out_source_line (line, file, 0, true);
3978 if (dwarf2out_do_cfi_asm ())
3979 dwarf2out_do_cfi_startproc (false);
3982 rtx personality = get_personality_function (current_function_decl);
3983 if (!current_unit_personality)
3984 current_unit_personality = personality;
3986 /* We cannot keep a current personality per function as without CFI
3987 asm at the point where we emit the CFI data there is no current
3988 function anymore. */
3990 && current_unit_personality != personality)
3991 sorry ("Multiple EH personalities are supported only with assemblers "
3992 "supporting .cfi.personality directive.");
3996 /* Output a marker (i.e. a label) for the absolute end of the generated code
3997 for a function definition. This gets called *after* the epilogue code has
4001 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4002 const char *file ATTRIBUTE_UNUSED)
4005 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4007 #ifdef DWARF2_DEBUGGING_INFO
4008 last_var_location_insn = NULL_RTX;
4011 if (dwarf2out_do_cfi_asm ())
4012 fprintf (asm_out_file, "\t.cfi_endproc\n");
4014 /* Output a label to mark the endpoint of the code generated for this
4016 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4017 current_function_funcdef_no);
4018 ASM_OUTPUT_LABEL (asm_out_file, label);
4019 fde = current_fde ();
4020 gcc_assert (fde != NULL);
4021 fde->dw_fde_end = xstrdup (label);
4025 dwarf2out_frame_init (void)
4027 /* Allocate the initial hunk of the fde_table. */
4028 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
4029 fde_table_allocated = FDE_TABLE_INCREMENT;
4030 fde_table_in_use = 0;
4032 /* Generate the CFA instructions common to all FDE's. Do it now for the
4033 sake of lookup_cfa. */
4035 /* On entry, the Canonical Frame Address is at SP. */
4036 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4038 #ifdef DWARF2_UNWIND_INFO
4039 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4040 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4045 dwarf2out_frame_finish (void)
4047 /* Output call frame information. */
4048 if (DWARF2_FRAME_INFO)
4049 output_call_frame_info (0);
4051 #ifndef TARGET_UNWIND_INFO
4052 /* Output another copy for the unwinder. */
4053 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4054 output_call_frame_info (1);
4058 /* Note that the current function section is being used for code. */
4061 dwarf2out_note_section_used (void)
4063 section *sec = current_function_section ();
4064 if (sec == text_section)
4065 text_section_used = true;
4066 else if (sec == cold_text_section)
4067 cold_text_section_used = true;
4071 dwarf2out_switch_text_section (void)
4073 dw_fde_ref fde = current_fde ();
4075 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4077 fde->dw_fde_switched_sections = 1;
4078 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4080 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4081 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4082 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4083 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4084 have_multiple_function_sections = true;
4086 /* Reset the current label on switching text sections, so that we
4087 don't attempt to advance_loc4 between labels in different sections. */
4088 fde->dw_fde_current_label = NULL;
4090 /* There is no need to mark used sections when not debugging. */
4091 if (cold_text_section != NULL)
4092 dwarf2out_note_section_used ();
4094 if (dwarf2out_do_cfi_asm ())
4095 fprintf (asm_out_file, "\t.cfi_endproc\n");
4097 /* Now do the real section switch. */
4098 switch_to_section (current_function_section ());
4100 if (dwarf2out_do_cfi_asm ())
4102 dwarf2out_do_cfi_startproc (true);
4103 /* As this is a different FDE, insert all current CFI instructions
4105 output_cfis (fde->dw_fde_cfi, true, fde, true);
4109 dw_cfi_ref cfi = fde->dw_fde_cfi;
4111 cfi = fde->dw_fde_cfi;
4113 while (cfi->dw_cfi_next != NULL)
4114 cfi = cfi->dw_cfi_next;
4115 fde->dw_fde_switch_cfi = cfi;
4120 /* And now, the subset of the debugging information support code necessary
4121 for emitting location expressions. */
4123 /* Data about a single source file. */
4124 struct GTY(()) dwarf_file_data {
4125 const char * filename;
4129 typedef struct dw_val_struct *dw_val_ref;
4130 typedef struct die_struct *dw_die_ref;
4131 typedef const struct die_struct *const_dw_die_ref;
4132 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4133 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4135 typedef struct GTY(()) deferred_locations_struct
4139 } deferred_locations;
4141 DEF_VEC_O(deferred_locations);
4142 DEF_VEC_ALLOC_O(deferred_locations,gc);
4144 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4146 /* Each DIE may have a series of attribute/value pairs. Values
4147 can take on several forms. The forms that are used in this
4148 implementation are listed below. */
4153 dw_val_class_offset,
4155 dw_val_class_loc_list,
4156 dw_val_class_range_list,
4158 dw_val_class_unsigned_const,
4159 dw_val_class_long_long,
4162 dw_val_class_die_ref,
4163 dw_val_class_fde_ref,
4164 dw_val_class_lbl_id,
4165 dw_val_class_lineptr,
4167 dw_val_class_macptr,
4171 /* Describe a floating point constant value, or a vector constant value. */
4173 typedef struct GTY(()) dw_vec_struct {
4174 unsigned char * GTY((length ("%h.length"))) array;
4180 /* The dw_val_node describes an attribute's value, as it is
4181 represented internally. */
4183 typedef struct GTY(()) dw_val_struct {
4184 enum dw_val_class val_class;
4185 union dw_val_struct_union
4187 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4188 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4189 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4190 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4191 HOST_WIDE_INT GTY ((default)) val_int;
4192 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4193 rtx GTY ((tag ("dw_val_class_long_long"))) val_long_long;
4194 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4195 struct dw_val_die_union
4199 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4200 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4201 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4202 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4203 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4204 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4206 GTY ((desc ("%1.val_class"))) v;
4210 /* Locations in memory are described using a sequence of stack machine
4213 typedef struct GTY(()) dw_loc_descr_struct {
4214 dw_loc_descr_ref dw_loc_next;
4215 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4216 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4217 from DW_OP_addr with a dtp-relative symbol relocation. */
4218 unsigned int dtprel : 1;
4220 dw_val_node dw_loc_oprnd1;
4221 dw_val_node dw_loc_oprnd2;
4225 /* Location lists are ranges + location descriptions for that range,
4226 so you can track variables that are in different places over
4227 their entire life. */
4228 typedef struct GTY(()) dw_loc_list_struct {
4229 dw_loc_list_ref dw_loc_next;
4230 const char *begin; /* Label for begin address of range */
4231 const char *end; /* Label for end address of range */
4232 char *ll_symbol; /* Label for beginning of location list.
4233 Only on head of list */
4234 const char *section; /* Section this loclist is relative to */
4235 dw_loc_descr_ref expr;
4238 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
4240 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4242 /* Convert a DWARF stack opcode into its string name. */
4245 dwarf_stack_op_name (unsigned int op)
4250 return "DW_OP_addr";
4252 return "DW_OP_deref";
4254 return "DW_OP_const1u";
4256 return "DW_OP_const1s";
4258 return "DW_OP_const2u";
4260 return "DW_OP_const2s";
4262 return "DW_OP_const4u";
4264 return "DW_OP_const4s";
4266 return "DW_OP_const8u";
4268 return "DW_OP_const8s";
4270 return "DW_OP_constu";
4272 return "DW_OP_consts";
4276 return "DW_OP_drop";
4278 return "DW_OP_over";
4280 return "DW_OP_pick";
4282 return "DW_OP_swap";
4286 return "DW_OP_xderef";
4294 return "DW_OP_minus";
4306 return "DW_OP_plus";
4307 case DW_OP_plus_uconst:
4308 return "DW_OP_plus_uconst";
4314 return "DW_OP_shra";
4332 return "DW_OP_skip";
4334 return "DW_OP_lit0";
4336 return "DW_OP_lit1";
4338 return "DW_OP_lit2";
4340 return "DW_OP_lit3";
4342 return "DW_OP_lit4";
4344 return "DW_OP_lit5";
4346 return "DW_OP_lit6";
4348 return "DW_OP_lit7";
4350 return "DW_OP_lit8";
4352 return "DW_OP_lit9";
4354 return "DW_OP_lit10";
4356 return "DW_OP_lit11";
4358 return "DW_OP_lit12";
4360 return "DW_OP_lit13";
4362 return "DW_OP_lit14";
4364 return "DW_OP_lit15";
4366 return "DW_OP_lit16";
4368 return "DW_OP_lit17";
4370 return "DW_OP_lit18";
4372 return "DW_OP_lit19";
4374 return "DW_OP_lit20";
4376 return "DW_OP_lit21";
4378 return "DW_OP_lit22";
4380 return "DW_OP_lit23";
4382 return "DW_OP_lit24";
4384 return "DW_OP_lit25";
4386 return "DW_OP_lit26";
4388 return "DW_OP_lit27";
4390 return "DW_OP_lit28";
4392 return "DW_OP_lit29";
4394 return "DW_OP_lit30";
4396 return "DW_OP_lit31";
4398 return "DW_OP_reg0";
4400 return "DW_OP_reg1";
4402 return "DW_OP_reg2";
4404 return "DW_OP_reg3";
4406 return "DW_OP_reg4";
4408 return "DW_OP_reg5";
4410 return "DW_OP_reg6";
4412 return "DW_OP_reg7";
4414 return "DW_OP_reg8";
4416 return "DW_OP_reg9";
4418 return "DW_OP_reg10";
4420 return "DW_OP_reg11";
4422 return "DW_OP_reg12";
4424 return "DW_OP_reg13";
4426 return "DW_OP_reg14";
4428 return "DW_OP_reg15";
4430 return "DW_OP_reg16";
4432 return "DW_OP_reg17";
4434 return "DW_OP_reg18";
4436 return "DW_OP_reg19";
4438 return "DW_OP_reg20";
4440 return "DW_OP_reg21";
4442 return "DW_OP_reg22";
4444 return "DW_OP_reg23";
4446 return "DW_OP_reg24";
4448 return "DW_OP_reg25";
4450 return "DW_OP_reg26";
4452 return "DW_OP_reg27";
4454 return "DW_OP_reg28";
4456 return "DW_OP_reg29";
4458 return "DW_OP_reg30";
4460 return "DW_OP_reg31";
4462 return "DW_OP_breg0";
4464 return "DW_OP_breg1";
4466 return "DW_OP_breg2";
4468 return "DW_OP_breg3";
4470 return "DW_OP_breg4";
4472 return "DW_OP_breg5";
4474 return "DW_OP_breg6";
4476 return "DW_OP_breg7";
4478 return "DW_OP_breg8";
4480 return "DW_OP_breg9";
4482 return "DW_OP_breg10";
4484 return "DW_OP_breg11";
4486 return "DW_OP_breg12";
4488 return "DW_OP_breg13";
4490 return "DW_OP_breg14";
4492 return "DW_OP_breg15";
4494 return "DW_OP_breg16";
4496 return "DW_OP_breg17";
4498 return "DW_OP_breg18";
4500 return "DW_OP_breg19";
4502 return "DW_OP_breg20";
4504 return "DW_OP_breg21";
4506 return "DW_OP_breg22";
4508 return "DW_OP_breg23";
4510 return "DW_OP_breg24";
4512 return "DW_OP_breg25";
4514 return "DW_OP_breg26";
4516 return "DW_OP_breg27";
4518 return "DW_OP_breg28";
4520 return "DW_OP_breg29";
4522 return "DW_OP_breg30";
4524 return "DW_OP_breg31";
4526 return "DW_OP_regx";
4528 return "DW_OP_fbreg";
4530 return "DW_OP_bregx";
4532 return "DW_OP_piece";
4533 case DW_OP_deref_size:
4534 return "DW_OP_deref_size";
4535 case DW_OP_xderef_size:
4536 return "DW_OP_xderef_size";
4540 case DW_OP_push_object_address:
4541 return "DW_OP_push_object_address";
4543 return "DW_OP_call2";
4545 return "DW_OP_call4";
4546 case DW_OP_call_ref:
4547 return "DW_OP_call_ref";
4548 case DW_OP_implicit_value:
4549 return "DW_OP_implicit_value";
4550 case DW_OP_stack_value:
4551 return "DW_OP_stack_value";
4552 case DW_OP_form_tls_address:
4553 return "DW_OP_form_tls_address";
4554 case DW_OP_call_frame_cfa:
4555 return "DW_OP_call_frame_cfa";
4556 case DW_OP_bit_piece:
4557 return "DW_OP_bit_piece";
4559 case DW_OP_GNU_push_tls_address:
4560 return "DW_OP_GNU_push_tls_address";
4561 case DW_OP_GNU_uninit:
4562 return "DW_OP_GNU_uninit";
4563 case DW_OP_GNU_encoded_addr:
4564 return "DW_OP_GNU_encoded_addr";
4567 return "OP_<unknown>";
4571 /* Return a pointer to a newly allocated location description. Location
4572 descriptions are simple expression terms that can be strung
4573 together to form more complicated location (address) descriptions. */
4575 static inline dw_loc_descr_ref
4576 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4577 unsigned HOST_WIDE_INT oprnd2)
4579 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4581 descr->dw_loc_opc = op;
4582 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4583 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4584 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4585 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4590 /* Return a pointer to a newly allocated location description for
4593 static inline dw_loc_descr_ref
4594 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4597 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4600 return new_loc_descr (DW_OP_bregx, reg, offset);
4603 /* Add a location description term to a location description expression. */
4606 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4608 dw_loc_descr_ref *d;
4610 /* Find the end of the chain. */
4611 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4617 /* Add a constant OFFSET to a location expression. */
4620 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4622 dw_loc_descr_ref loc;
4625 gcc_assert (*list_head != NULL);
4630 /* Find the end of the chain. */
4631 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4635 if (loc->dw_loc_opc == DW_OP_fbreg
4636 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4637 p = &loc->dw_loc_oprnd1.v.val_int;
4638 else if (loc->dw_loc_opc == DW_OP_bregx)
4639 p = &loc->dw_loc_oprnd2.v.val_int;
4641 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4642 offset. Don't optimize if an signed integer overflow would happen. */
4644 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4645 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4648 else if (offset > 0)
4649 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4653 loc->dw_loc_next = int_loc_descriptor (offset);
4654 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4658 /* Return the size of a location descriptor. */
4660 static unsigned long
4661 size_of_loc_descr (dw_loc_descr_ref loc)
4663 unsigned long size = 1;
4665 switch (loc->dw_loc_opc)
4668 size += DWARF2_ADDR_SIZE;
4687 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4690 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4695 case DW_OP_plus_uconst:
4696 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4734 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4737 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4740 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4743 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4744 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4747 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4749 case DW_OP_deref_size:
4750 case DW_OP_xderef_size:
4759 case DW_OP_call_ref:
4760 size += DWARF2_ADDR_SIZE;
4762 case DW_OP_implicit_value:
4763 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4764 + loc->dw_loc_oprnd1.v.val_unsigned;
4773 /* Return the size of a series of location descriptors. */
4775 static unsigned long
4776 size_of_locs (dw_loc_descr_ref loc)
4781 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4782 field, to avoid writing to a PCH file. */
4783 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4785 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4787 size += size_of_loc_descr (l);
4792 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4794 l->dw_loc_addr = size;
4795 size += size_of_loc_descr (l);
4801 #ifdef DWARF2_DEBUGGING_INFO
4802 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4805 /* Output location description stack opcode's operands (if any). */
4808 output_loc_operands (dw_loc_descr_ref loc)
4810 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4811 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4813 switch (loc->dw_loc_opc)
4815 #ifdef DWARF2_DEBUGGING_INFO
4818 dw2_asm_output_data (2, val1->v.val_int, NULL);
4822 dw2_asm_output_data (4, val1->v.val_int, NULL);
4826 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
4827 dw2_asm_output_data (8, val1->v.val_int, NULL);
4834 gcc_assert (val1->val_class == dw_val_class_loc);
4835 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4837 dw2_asm_output_data (2, offset, NULL);
4840 case DW_OP_implicit_value:
4841 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4842 switch (val2->val_class)
4844 case dw_val_class_const:
4845 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
4847 case dw_val_class_vec:
4849 unsigned int elt_size = val2->v.val_vec.elt_size;
4850 unsigned int len = val2->v.val_vec.length;
4854 if (elt_size > sizeof (HOST_WIDE_INT))
4859 for (i = 0, p = val2->v.val_vec.array;
4862 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
4863 "fp or vector constant word %u", i);
4866 case dw_val_class_long_long:
4868 unsigned HOST_WIDE_INT first, second;
4870 if (WORDS_BIG_ENDIAN)
4872 first = CONST_DOUBLE_HIGH (val2->v.val_long_long);
4873 second = CONST_DOUBLE_LOW (val2->v.val_long_long);
4877 first = CONST_DOUBLE_LOW (val2->v.val_long_long);
4878 second = CONST_DOUBLE_HIGH (val2->v.val_long_long);
4880 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4881 first, "long long constant");
4882 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4886 case dw_val_class_addr:
4887 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
4888 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
4903 case DW_OP_implicit_value:
4904 /* We currently don't make any attempt to make sure these are
4905 aligned properly like we do for the main unwind info, so
4906 don't support emitting things larger than a byte if we're
4907 only doing unwinding. */
4912 dw2_asm_output_data (1, val1->v.val_int, NULL);
4915 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4918 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4921 dw2_asm_output_data (1, val1->v.val_int, NULL);
4923 case DW_OP_plus_uconst:
4924 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4958 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4961 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4964 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4967 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4968 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4971 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4973 case DW_OP_deref_size:
4974 case DW_OP_xderef_size:
4975 dw2_asm_output_data (1, val1->v.val_int, NULL);
4981 if (targetm.asm_out.output_dwarf_dtprel)
4983 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4986 fputc ('\n', asm_out_file);
4993 #ifdef DWARF2_DEBUGGING_INFO
4994 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5002 /* Other codes have no operands. */
5007 /* Output a sequence of location operations. */
5010 output_loc_sequence (dw_loc_descr_ref loc)
5012 for (; loc != NULL; loc = loc->dw_loc_next)
5014 /* Output the opcode. */
5015 dw2_asm_output_data (1, loc->dw_loc_opc,
5016 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5018 /* Output the operand(s) (if any). */
5019 output_loc_operands (loc);
5023 /* Output location description stack opcode's operands (if any).
5024 The output is single bytes on a line, suitable for .cfi_escape. */
5027 output_loc_operands_raw (dw_loc_descr_ref loc)
5029 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5030 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5032 switch (loc->dw_loc_opc)
5035 case DW_OP_implicit_value:
5036 /* We cannot output addresses in .cfi_escape, only bytes. */
5042 case DW_OP_deref_size:
5043 case DW_OP_xderef_size:
5044 fputc (',', asm_out_file);
5045 dw2_asm_output_data_raw (1, val1->v.val_int);
5050 fputc (',', asm_out_file);
5051 dw2_asm_output_data_raw (2, val1->v.val_int);
5056 fputc (',', asm_out_file);
5057 dw2_asm_output_data_raw (4, val1->v.val_int);
5062 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5063 fputc (',', asm_out_file);
5064 dw2_asm_output_data_raw (8, val1->v.val_int);
5072 gcc_assert (val1->val_class == dw_val_class_loc);
5073 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5075 fputc (',', asm_out_file);
5076 dw2_asm_output_data_raw (2, offset);
5081 case DW_OP_plus_uconst:
5084 fputc (',', asm_out_file);
5085 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5122 fputc (',', asm_out_file);
5123 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5127 fputc (',', asm_out_file);
5128 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5129 fputc (',', asm_out_file);
5130 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5134 /* Other codes have no operands. */
5140 output_loc_sequence_raw (dw_loc_descr_ref loc)
5144 /* Output the opcode. */
5145 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
5146 output_loc_operands_raw (loc);
5148 if (!loc->dw_loc_next)
5150 loc = loc->dw_loc_next;
5152 fputc (',', asm_out_file);
5156 /* This routine will generate the correct assembly data for a location
5157 description based on a cfi entry with a complex address. */
5160 output_cfa_loc (dw_cfi_ref cfi)
5162 dw_loc_descr_ref loc;
5165 if (cfi->dw_cfi_opc == DW_CFA_expression)
5166 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
5168 /* Output the size of the block. */
5169 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5170 size = size_of_locs (loc);
5171 dw2_asm_output_data_uleb128 (size, NULL);
5173 /* Now output the operations themselves. */
5174 output_loc_sequence (loc);
5177 /* Similar, but used for .cfi_escape. */
5180 output_cfa_loc_raw (dw_cfi_ref cfi)
5182 dw_loc_descr_ref loc;
5185 if (cfi->dw_cfi_opc == DW_CFA_expression)
5186 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
5188 /* Output the size of the block. */
5189 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5190 size = size_of_locs (loc);
5191 dw2_asm_output_data_uleb128_raw (size);
5192 fputc (',', asm_out_file);
5194 /* Now output the operations themselves. */
5195 output_loc_sequence_raw (loc);
5198 /* This function builds a dwarf location descriptor sequence from a
5199 dw_cfa_location, adding the given OFFSET to the result of the
5202 static struct dw_loc_descr_struct *
5203 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5205 struct dw_loc_descr_struct *head, *tmp;
5207 offset += cfa->offset;
5211 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5212 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5213 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5214 add_loc_descr (&head, tmp);
5217 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5218 add_loc_descr (&head, tmp);
5222 head = new_reg_loc_descr (cfa->reg, offset);
5227 /* This function builds a dwarf location descriptor sequence for
5228 the address at OFFSET from the CFA when stack is aligned to
5231 static struct dw_loc_descr_struct *
5232 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5234 struct dw_loc_descr_struct *head;
5235 unsigned int dwarf_fp
5236 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5238 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5239 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5241 head = new_reg_loc_descr (dwarf_fp, 0);
5242 add_loc_descr (&head, int_loc_descriptor (alignment));
5243 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5244 loc_descr_plus_const (&head, offset);
5247 head = new_reg_loc_descr (dwarf_fp, offset);
5251 /* This function fills in aa dw_cfa_location structure from a dwarf location
5252 descriptor sequence. */
5255 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5257 struct dw_loc_descr_struct *ptr;
5259 cfa->base_offset = 0;
5263 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5265 enum dwarf_location_atom op = ptr->dw_loc_opc;
5301 cfa->reg = op - DW_OP_reg0;
5304 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5338 cfa->reg = op - DW_OP_breg0;
5339 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5342 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5343 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5348 case DW_OP_plus_uconst:
5349 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5352 internal_error ("DW_LOC_OP %s not implemented",
5353 dwarf_stack_op_name (ptr->dw_loc_opc));
5357 #endif /* .debug_frame support */
5359 /* And now, the support for symbolic debugging information. */
5360 #ifdef DWARF2_DEBUGGING_INFO
5362 /* .debug_str support. */
5363 static int output_indirect_string (void **, void *);
5365 static void dwarf2out_init (const char *);
5366 static void dwarf2out_finish (const char *);
5367 static void dwarf2out_define (unsigned int, const char *);
5368 static void dwarf2out_undef (unsigned int, const char *);
5369 static void dwarf2out_start_source_file (unsigned, const char *);
5370 static void dwarf2out_end_source_file (unsigned);
5371 static void dwarf2out_begin_block (unsigned, unsigned);
5372 static void dwarf2out_end_block (unsigned, unsigned);
5373 static bool dwarf2out_ignore_block (const_tree);
5374 static void dwarf2out_global_decl (tree);
5375 static void dwarf2out_type_decl (tree, int);
5376 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5377 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5379 static void dwarf2out_abstract_function (tree);
5380 static void dwarf2out_var_location (rtx);
5381 static void dwarf2out_begin_function (tree);
5382 static void dwarf2out_set_name (tree, tree);
5384 /* The debug hooks structure. */
5386 const struct gcc_debug_hooks dwarf2_debug_hooks =
5392 dwarf2out_start_source_file,
5393 dwarf2out_end_source_file,
5394 dwarf2out_begin_block,
5395 dwarf2out_end_block,
5396 dwarf2out_ignore_block,
5397 dwarf2out_source_line,
5398 dwarf2out_begin_prologue,
5399 debug_nothing_int_charstar, /* end_prologue */
5400 dwarf2out_end_epilogue,
5401 dwarf2out_begin_function,
5402 debug_nothing_int, /* end_function */
5403 dwarf2out_decl, /* function_decl */
5404 dwarf2out_global_decl,
5405 dwarf2out_type_decl, /* type_decl */
5406 dwarf2out_imported_module_or_decl,
5407 debug_nothing_tree, /* deferred_inline_function */
5408 /* The DWARF 2 backend tries to reduce debugging bloat by not
5409 emitting the abstract description of inline functions until
5410 something tries to reference them. */
5411 dwarf2out_abstract_function, /* outlining_inline_function */
5412 debug_nothing_rtx, /* label */
5413 debug_nothing_int, /* handle_pch */
5414 dwarf2out_var_location,
5415 dwarf2out_switch_text_section,
5417 1 /* start_end_main_source_file */
5421 /* NOTE: In the comments in this file, many references are made to
5422 "Debugging Information Entries". This term is abbreviated as `DIE'
5423 throughout the remainder of this file. */
5425 /* An internal representation of the DWARF output is built, and then
5426 walked to generate the DWARF debugging info. The walk of the internal
5427 representation is done after the entire program has been compiled.
5428 The types below are used to describe the internal representation. */
5430 /* Various DIE's use offsets relative to the beginning of the
5431 .debug_info section to refer to each other. */
5433 typedef long int dw_offset;
5435 /* Define typedefs here to avoid circular dependencies. */
5437 typedef struct dw_attr_struct *dw_attr_ref;
5438 typedef struct dw_line_info_struct *dw_line_info_ref;
5439 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5440 typedef struct pubname_struct *pubname_ref;
5441 typedef struct dw_ranges_struct *dw_ranges_ref;
5442 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5444 /* Each entry in the line_info_table maintains the file and
5445 line number associated with the label generated for that
5446 entry. The label gives the PC value associated with
5447 the line number entry. */
5449 typedef struct GTY(()) dw_line_info_struct {
5450 unsigned long dw_file_num;
5451 unsigned long dw_line_num;
5455 /* Line information for functions in separate sections; each one gets its
5457 typedef struct GTY(()) dw_separate_line_info_struct {
5458 unsigned long dw_file_num;
5459 unsigned long dw_line_num;
5460 unsigned long function;
5462 dw_separate_line_info_entry;
5464 /* Each DIE attribute has a field specifying the attribute kind,
5465 a link to the next attribute in the chain, and an attribute value.
5466 Attributes are typically linked below the DIE they modify. */
5468 typedef struct GTY(()) dw_attr_struct {
5469 enum dwarf_attribute dw_attr;
5470 dw_val_node dw_attr_val;
5474 DEF_VEC_O(dw_attr_node);
5475 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5477 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5478 The children of each node form a circular list linked by
5479 die_sib. die_child points to the node *before* the "first" child node. */
5481 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5482 enum dwarf_tag die_tag;
5484 VEC(dw_attr_node,gc) * die_attr;
5485 dw_die_ref die_parent;
5486 dw_die_ref die_child;
5488 dw_die_ref die_definition; /* ref from a specification to its definition */
5489 dw_offset die_offset;
5490 unsigned long die_abbrev;
5492 /* Die is used and must not be pruned as unused. */
5493 int die_perennial_p;
5494 unsigned int decl_id;
5498 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5499 #define FOR_EACH_CHILD(die, c, expr) do { \
5500 c = die->die_child; \
5504 } while (c != die->die_child); \
5507 /* The pubname structure */
5509 typedef struct GTY(()) pubname_struct {
5515 DEF_VEC_O(pubname_entry);
5516 DEF_VEC_ALLOC_O(pubname_entry, gc);
5518 struct GTY(()) dw_ranges_struct {
5519 /* If this is positive, it's a block number, otherwise it's a
5520 bitwise-negated index into dw_ranges_by_label. */
5524 struct GTY(()) dw_ranges_by_label_struct {
5529 /* The limbo die list structure. */
5530 typedef struct GTY(()) limbo_die_struct {
5533 struct limbo_die_struct *next;
5537 /* How to start an assembler comment. */
5538 #ifndef ASM_COMMENT_START
5539 #define ASM_COMMENT_START ";#"
5542 /* Define a macro which returns nonzero for a TYPE_DECL which was
5543 implicitly generated for a tagged type.
5545 Note that unlike the gcc front end (which generates a NULL named
5546 TYPE_DECL node for each complete tagged type, each array type, and
5547 each function type node created) the g++ front end generates a
5548 _named_ TYPE_DECL node for each tagged type node created.
5549 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5550 generate a DW_TAG_typedef DIE for them. */
5552 #define TYPE_DECL_IS_STUB(decl) \
5553 (DECL_NAME (decl) == NULL_TREE \
5554 || (DECL_ARTIFICIAL (decl) \
5555 && is_tagged_type (TREE_TYPE (decl)) \
5556 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5557 /* This is necessary for stub decls that \
5558 appear in nested inline functions. */ \
5559 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5560 && (decl_ultimate_origin (decl) \
5561 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5563 /* Information concerning the compilation unit's programming
5564 language, and compiler version. */
5566 /* Fixed size portion of the DWARF compilation unit header. */
5567 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5568 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5570 /* Fixed size portion of public names info. */
5571 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5573 /* Fixed size portion of the address range info. */
5574 #define DWARF_ARANGES_HEADER_SIZE \
5575 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5576 DWARF2_ADDR_SIZE * 2) \
5577 - DWARF_INITIAL_LENGTH_SIZE)
5579 /* Size of padding portion in the address range info. It must be
5580 aligned to twice the pointer size. */
5581 #define DWARF_ARANGES_PAD_SIZE \
5582 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5583 DWARF2_ADDR_SIZE * 2) \
5584 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5586 /* Use assembler line directives if available. */
5587 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5588 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5589 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5591 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5595 /* Minimum line offset in a special line info. opcode.
5596 This value was chosen to give a reasonable range of values. */
5597 #define DWARF_LINE_BASE -10
5599 /* First special line opcode - leave room for the standard opcodes. */
5600 #define DWARF_LINE_OPCODE_BASE 10
5602 /* Range of line offsets in a special line info. opcode. */
5603 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5605 /* Flag that indicates the initial value of the is_stmt_start flag.
5606 In the present implementation, we do not mark any lines as
5607 the beginning of a source statement, because that information
5608 is not made available by the GCC front-end. */
5609 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5611 #ifdef DWARF2_DEBUGGING_INFO
5612 /* This location is used by calc_die_sizes() to keep track
5613 the offset of each DIE within the .debug_info section. */
5614 static unsigned long next_die_offset;
5617 /* Record the root of the DIE's built for the current compilation unit. */
5618 static GTY(()) dw_die_ref comp_unit_die;
5620 /* A list of DIEs with a NULL parent waiting to be relocated. */
5621 static GTY(()) limbo_die_node *limbo_die_list;
5623 /* A list of DIEs for which we may have to generate
5624 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5626 static GTY(()) limbo_die_node *deferred_asm_name;
5628 /* Filenames referenced by this compilation unit. */
5629 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5631 /* A hash table of references to DIE's that describe declarations.
5632 The key is a DECL_UID() which is a unique number identifying each decl. */
5633 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5635 /* A hash table of references to DIE's that describe COMMON blocks.
5636 The key is DECL_UID() ^ die_parent. */
5637 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5639 typedef struct GTY(()) die_arg_entry_struct {
5644 DEF_VEC_O(die_arg_entry);
5645 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5647 /* Node of the variable location list. */
5648 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5649 rtx GTY (()) var_loc_note;
5650 const char * GTY (()) label;
5651 const char * GTY (()) section_label;
5652 struct var_loc_node * GTY (()) next;
5655 /* Variable location list. */
5656 struct GTY (()) var_loc_list_def {
5657 struct var_loc_node * GTY (()) first;
5659 /* Do not mark the last element of the chained list because
5660 it is marked through the chain. */
5661 struct var_loc_node * GTY ((skip ("%h"))) last;
5663 /* DECL_UID of the variable decl. */
5664 unsigned int decl_id;
5666 typedef struct var_loc_list_def var_loc_list;
5669 /* Table of decl location linked lists. */
5670 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5672 /* A pointer to the base of a list of references to DIE's that
5673 are uniquely identified by their tag, presence/absence of
5674 children DIE's, and list of attribute/value pairs. */
5675 static GTY((length ("abbrev_die_table_allocated")))
5676 dw_die_ref *abbrev_die_table;
5678 /* Number of elements currently allocated for abbrev_die_table. */
5679 static GTY(()) unsigned abbrev_die_table_allocated;
5681 /* Number of elements in type_die_table currently in use. */
5682 static GTY(()) unsigned abbrev_die_table_in_use;
5684 /* Size (in elements) of increments by which we may expand the
5685 abbrev_die_table. */
5686 #define ABBREV_DIE_TABLE_INCREMENT 256
5688 /* A pointer to the base of a table that contains line information
5689 for each source code line in .text in the compilation unit. */
5690 static GTY((length ("line_info_table_allocated")))
5691 dw_line_info_ref line_info_table;
5693 /* Number of elements currently allocated for line_info_table. */
5694 static GTY(()) unsigned line_info_table_allocated;
5696 /* Number of elements in line_info_table currently in use. */
5697 static GTY(()) unsigned line_info_table_in_use;
5699 /* A pointer to the base of a table that contains line information
5700 for each source code line outside of .text in the compilation unit. */
5701 static GTY ((length ("separate_line_info_table_allocated")))
5702 dw_separate_line_info_ref separate_line_info_table;
5704 /* Number of elements currently allocated for separate_line_info_table. */
5705 static GTY(()) unsigned separate_line_info_table_allocated;
5707 /* Number of elements in separate_line_info_table currently in use. */
5708 static GTY(()) unsigned separate_line_info_table_in_use;
5710 /* Size (in elements) of increments by which we may expand the
5712 #define LINE_INFO_TABLE_INCREMENT 1024
5714 /* A pointer to the base of a table that contains a list of publicly
5715 accessible names. */
5716 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5718 /* A pointer to the base of a table that contains a list of publicly
5719 accessible types. */
5720 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5722 /* Array of dies for which we should generate .debug_arange info. */
5723 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5725 /* Number of elements currently allocated for arange_table. */
5726 static GTY(()) unsigned arange_table_allocated;
5728 /* Number of elements in arange_table currently in use. */
5729 static GTY(()) unsigned arange_table_in_use;
5731 /* Size (in elements) of increments by which we may expand the
5733 #define ARANGE_TABLE_INCREMENT 64
5735 /* Array of dies for which we should generate .debug_ranges info. */
5736 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5738 /* Number of elements currently allocated for ranges_table. */
5739 static GTY(()) unsigned ranges_table_allocated;
5741 /* Number of elements in ranges_table currently in use. */
5742 static GTY(()) unsigned ranges_table_in_use;
5744 /* Array of pairs of labels referenced in ranges_table. */
5745 static GTY ((length ("ranges_by_label_allocated")))
5746 dw_ranges_by_label_ref ranges_by_label;
5748 /* Number of elements currently allocated for ranges_by_label. */
5749 static GTY(()) unsigned ranges_by_label_allocated;
5751 /* Number of elements in ranges_by_label currently in use. */
5752 static GTY(()) unsigned ranges_by_label_in_use;
5754 /* Size (in elements) of increments by which we may expand the
5756 #define RANGES_TABLE_INCREMENT 64
5758 /* Whether we have location lists that need outputting */
5759 static GTY(()) bool have_location_lists;
5761 /* Unique label counter. */
5762 static GTY(()) unsigned int loclabel_num;
5764 #ifdef DWARF2_DEBUGGING_INFO
5765 /* Record whether the function being analyzed contains inlined functions. */
5766 static int current_function_has_inlines;
5768 #if 0 && defined (MIPS_DEBUGGING_INFO)
5769 static int comp_unit_has_inlines;
5772 /* The last file entry emitted by maybe_emit_file(). */
5773 static GTY(()) struct dwarf_file_data * last_emitted_file;
5775 /* Number of internal labels generated by gen_internal_sym(). */
5776 static GTY(()) int label_num;
5778 /* Cached result of previous call to lookup_filename. */
5779 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5781 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
5783 #ifdef DWARF2_DEBUGGING_INFO
5785 /* Offset from the "steady-state frame pointer" to the frame base,
5786 within the current function. */
5787 static HOST_WIDE_INT frame_pointer_fb_offset;
5789 /* Forward declarations for functions defined in this file. */
5791 static int is_pseudo_reg (const_rtx);
5792 static tree type_main_variant (tree);
5793 static int is_tagged_type (const_tree);
5794 static const char *dwarf_tag_name (unsigned);
5795 static const char *dwarf_attr_name (unsigned);
5796 static const char *dwarf_form_name (unsigned);
5797 static tree decl_ultimate_origin (const_tree);
5798 static tree decl_class_context (tree);
5799 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5800 static inline enum dw_val_class AT_class (dw_attr_ref);
5801 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5802 static inline unsigned AT_flag (dw_attr_ref);
5803 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5804 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5805 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5806 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5807 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, rtx);
5808 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5809 unsigned int, unsigned char *);
5810 static hashval_t debug_str_do_hash (const void *);
5811 static int debug_str_eq (const void *, const void *);
5812 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5813 static inline const char *AT_string (dw_attr_ref);
5814 static enum dwarf_form AT_string_form (dw_attr_ref);
5815 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5816 static void add_AT_specification (dw_die_ref, dw_die_ref);
5817 static inline dw_die_ref AT_ref (dw_attr_ref);
5818 static inline int AT_ref_external (dw_attr_ref);
5819 static inline void set_AT_ref_external (dw_attr_ref, int);
5820 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5821 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5822 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5823 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5825 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5826 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5827 static inline rtx AT_addr (dw_attr_ref);
5828 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5829 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5830 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5831 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5832 unsigned HOST_WIDE_INT);
5833 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5835 static inline const char *AT_lbl (dw_attr_ref);
5836 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5837 static const char *get_AT_low_pc (dw_die_ref);
5838 static const char *get_AT_hi_pc (dw_die_ref);
5839 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5840 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5841 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5842 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5843 static bool is_c_family (void);
5844 static bool is_cxx (void);
5845 static bool is_java (void);
5846 static bool is_fortran (void);
5847 static bool is_ada (void);
5848 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5849 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5850 static void add_child_die (dw_die_ref, dw_die_ref);
5851 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5852 static dw_die_ref lookup_type_die (tree);
5853 static void equate_type_number_to_die (tree, dw_die_ref);
5854 static hashval_t decl_die_table_hash (const void *);
5855 static int decl_die_table_eq (const void *, const void *);
5856 static dw_die_ref lookup_decl_die (tree);
5857 static hashval_t common_block_die_table_hash (const void *);
5858 static int common_block_die_table_eq (const void *, const void *);
5859 static hashval_t decl_loc_table_hash (const void *);
5860 static int decl_loc_table_eq (const void *, const void *);
5861 static var_loc_list *lookup_decl_loc (const_tree);
5862 static void equate_decl_number_to_die (tree, dw_die_ref);
5863 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5864 static void print_spaces (FILE *);
5865 static void print_die (dw_die_ref, FILE *);
5866 static void print_dwarf_line_table (FILE *);
5867 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5868 static dw_die_ref pop_compile_unit (dw_die_ref);
5869 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5870 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5871 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5872 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5873 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5874 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5875 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5876 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5877 static void compute_section_prefix (dw_die_ref);
5878 static int is_type_die (dw_die_ref);
5879 static int is_comdat_die (dw_die_ref);
5880 static int is_symbol_die (dw_die_ref);
5881 static void assign_symbol_names (dw_die_ref);
5882 static void break_out_includes (dw_die_ref);
5883 static hashval_t htab_cu_hash (const void *);
5884 static int htab_cu_eq (const void *, const void *);
5885 static void htab_cu_del (void *);
5886 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5887 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5888 static void add_sibling_attributes (dw_die_ref);
5889 static void build_abbrev_table (dw_die_ref);
5890 static void output_location_lists (dw_die_ref);
5891 static int constant_size (unsigned HOST_WIDE_INT);
5892 static unsigned long size_of_die (dw_die_ref);
5893 static void calc_die_sizes (dw_die_ref);
5894 static void mark_dies (dw_die_ref);
5895 static void unmark_dies (dw_die_ref);
5896 static void unmark_all_dies (dw_die_ref);
5897 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5898 static unsigned long size_of_aranges (void);
5899 static enum dwarf_form value_format (dw_attr_ref);
5900 static void output_value_format (dw_attr_ref);
5901 static void output_abbrev_section (void);
5902 static void output_die_symbol (dw_die_ref);
5903 static void output_die (dw_die_ref);
5904 static void output_compilation_unit_header (void);
5905 static void output_comp_unit (dw_die_ref, int);
5906 static const char *dwarf2_name (tree, int);
5907 static void add_pubname (tree, dw_die_ref);
5908 static void add_pubname_string (const char *, dw_die_ref);
5909 static void add_pubtype (tree, dw_die_ref);
5910 static void output_pubnames (VEC (pubname_entry,gc) *);
5911 static void add_arange (tree, dw_die_ref);
5912 static void output_aranges (void);
5913 static unsigned int add_ranges_num (int);
5914 static unsigned int add_ranges (const_tree);
5915 static unsigned int add_ranges_by_labels (const char *, const char *);
5916 static void output_ranges (void);
5917 static void output_line_info (void);
5918 static void output_file_names (void);
5919 static dw_die_ref base_type_die (tree);
5920 static int is_base_type (tree);
5921 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5922 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5923 static dw_die_ref generic_parameter_die (tree, tree, dw_die_ref, int);
5924 static int type_is_enum (const_tree);
5925 static unsigned int dbx_reg_number (const_rtx);
5926 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5927 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5928 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5929 enum var_init_status);
5930 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5931 enum var_init_status);
5932 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5933 enum var_init_status);
5934 static int is_based_loc (const_rtx);
5935 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5936 enum var_init_status);
5937 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5938 enum var_init_status);
5939 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
5940 enum var_init_status);
5941 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5942 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5943 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5944 static tree field_type (const_tree);
5945 static unsigned int simple_type_align_in_bits (const_tree);
5946 static unsigned int simple_decl_align_in_bits (const_tree);
5947 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5948 static HOST_WIDE_INT field_byte_offset (const_tree);
5949 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5951 static void add_data_member_location_attribute (dw_die_ref, tree);
5952 static void add_const_value_attribute (dw_die_ref, rtx);
5953 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5954 static void insert_float (const_rtx, unsigned char *);
5955 static rtx rtl_for_decl_location (tree);
5956 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5957 enum dwarf_attribute);
5958 static void tree_add_const_value_attribute (dw_die_ref, tree);
5959 static void tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
5960 static void add_name_attribute (dw_die_ref, const char *);
5961 static void add_comp_dir_attribute (dw_die_ref);
5962 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5963 static void add_subscript_info (dw_die_ref, tree, bool);
5964 static void add_byte_size_attribute (dw_die_ref, tree);
5965 static void add_bit_offset_attribute (dw_die_ref, tree);
5966 static void add_bit_size_attribute (dw_die_ref, tree);
5967 static void add_prototyped_attribute (dw_die_ref, tree);
5968 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5969 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5970 static void add_src_coords_attributes (dw_die_ref, tree);
5971 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5972 static void push_decl_scope (tree);
5973 static void pop_decl_scope (void);
5974 static dw_die_ref scope_die_for (tree, dw_die_ref);
5975 static inline int local_scope_p (dw_die_ref);
5976 static inline int class_scope_p (dw_die_ref);
5977 static inline int class_or_namespace_scope_p (dw_die_ref);
5978 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5979 static void add_calling_convention_attribute (dw_die_ref, tree);
5980 static const char *type_tag (const_tree);
5981 static tree member_declared_type (const_tree);
5983 static const char *decl_start_label (tree);
5985 static void gen_array_type_die (tree, dw_die_ref);
5986 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5988 static void gen_entry_point_die (tree, dw_die_ref);
5990 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5991 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5992 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5993 static void gen_formal_types_die (tree, dw_die_ref);
5994 static void gen_subprogram_die (tree, dw_die_ref);
5995 static void gen_variable_die (tree, tree, dw_die_ref);
5996 static void gen_const_die (tree, dw_die_ref);
5997 static void gen_label_die (tree, dw_die_ref);
5998 static void gen_lexical_block_die (tree, dw_die_ref, int);
5999 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6000 static void gen_field_die (tree, dw_die_ref);
6001 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6002 static dw_die_ref gen_compile_unit_die (const char *);
6003 static void gen_inheritance_die (tree, tree, dw_die_ref);
6004 static void gen_member_die (tree, dw_die_ref);
6005 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6006 enum debug_info_usage);
6007 static void gen_subroutine_type_die (tree, dw_die_ref);
6008 static void gen_typedef_die (tree, dw_die_ref);
6009 static void gen_type_die (tree, dw_die_ref);
6010 static void gen_block_die (tree, dw_die_ref, int);
6011 static void decls_for_scope (tree, dw_die_ref, int);
6012 static int is_redundant_typedef (const_tree);
6013 static inline dw_die_ref get_context_die (tree);
6014 static void gen_namespace_die (tree, dw_die_ref);
6015 static void gen_decl_die (tree, tree, dw_die_ref);
6016 static dw_die_ref force_decl_die (tree);
6017 static dw_die_ref force_type_die (tree);
6018 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6019 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6020 static struct dwarf_file_data * lookup_filename (const char *);
6021 static void retry_incomplete_types (void);
6022 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6023 static tree make_ith_pack_parameter_name (tree, int);
6024 static void gen_generic_params_dies (tree);
6025 static void splice_child_die (dw_die_ref, dw_die_ref);
6026 static int file_info_cmp (const void *, const void *);
6027 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6028 const char *, const char *, unsigned);
6029 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
6030 const char *, const char *,
6032 static void output_loc_list (dw_loc_list_ref);
6033 static char *gen_internal_sym (const char *);
6035 static void prune_unmark_dies (dw_die_ref);
6036 static void prune_unused_types_mark (dw_die_ref, int);
6037 static void prune_unused_types_walk (dw_die_ref);
6038 static void prune_unused_types_walk_attribs (dw_die_ref);
6039 static void prune_unused_types_prune (dw_die_ref);
6040 static void prune_unused_types (void);
6041 static int maybe_emit_file (struct dwarf_file_data *fd);
6042 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6043 static void gen_remaining_tmpl_value_param_die_attribute (void);
6045 /* Section names used to hold DWARF debugging information. */
6046 #ifndef DEBUG_INFO_SECTION
6047 #define DEBUG_INFO_SECTION ".debug_info"
6049 #ifndef DEBUG_ABBREV_SECTION
6050 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6052 #ifndef DEBUG_ARANGES_SECTION
6053 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6055 #ifndef DEBUG_MACINFO_SECTION
6056 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6058 #ifndef DEBUG_LINE_SECTION
6059 #define DEBUG_LINE_SECTION ".debug_line"
6061 #ifndef DEBUG_LOC_SECTION
6062 #define DEBUG_LOC_SECTION ".debug_loc"
6064 #ifndef DEBUG_PUBNAMES_SECTION
6065 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6067 #ifndef DEBUG_PUBTYPES_SECTION
6068 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6070 #ifndef DEBUG_STR_SECTION
6071 #define DEBUG_STR_SECTION ".debug_str"
6073 #ifndef DEBUG_RANGES_SECTION
6074 #define DEBUG_RANGES_SECTION ".debug_ranges"
6077 /* Standard ELF section names for compiled code and data. */
6078 #ifndef TEXT_SECTION_NAME
6079 #define TEXT_SECTION_NAME ".text"
6082 /* Section flags for .debug_str section. */
6083 #define DEBUG_STR_SECTION_FLAGS \
6084 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6085 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6088 /* Labels we insert at beginning sections we can reference instead of
6089 the section names themselves. */
6091 #ifndef TEXT_SECTION_LABEL
6092 #define TEXT_SECTION_LABEL "Ltext"
6094 #ifndef COLD_TEXT_SECTION_LABEL
6095 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6097 #ifndef DEBUG_LINE_SECTION_LABEL
6098 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6100 #ifndef DEBUG_INFO_SECTION_LABEL
6101 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6103 #ifndef DEBUG_ABBREV_SECTION_LABEL
6104 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6106 #ifndef DEBUG_LOC_SECTION_LABEL
6107 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6109 #ifndef DEBUG_RANGES_SECTION_LABEL
6110 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6112 #ifndef DEBUG_MACINFO_SECTION_LABEL
6113 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6116 /* Definitions of defaults for formats and names of various special
6117 (artificial) labels which may be generated within this file (when the -g
6118 options is used and DWARF2_DEBUGGING_INFO is in effect.
6119 If necessary, these may be overridden from within the tm.h file, but
6120 typically, overriding these defaults is unnecessary. */
6122 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6123 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6124 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6125 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6126 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6127 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6128 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6129 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6130 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6131 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6133 #ifndef TEXT_END_LABEL
6134 #define TEXT_END_LABEL "Letext"
6136 #ifndef COLD_END_LABEL
6137 #define COLD_END_LABEL "Letext_cold"
6139 #ifndef BLOCK_BEGIN_LABEL
6140 #define BLOCK_BEGIN_LABEL "LBB"
6142 #ifndef BLOCK_END_LABEL
6143 #define BLOCK_END_LABEL "LBE"
6145 #ifndef LINE_CODE_LABEL
6146 #define LINE_CODE_LABEL "LM"
6148 #ifndef SEPARATE_LINE_CODE_LABEL
6149 #define SEPARATE_LINE_CODE_LABEL "LSM"
6153 /* We allow a language front-end to designate a function that is to be
6154 called to "demangle" any name before it is put into a DIE. */
6156 static const char *(*demangle_name_func) (const char *);
6159 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6161 demangle_name_func = func;
6164 /* Test if rtl node points to a pseudo register. */
6167 is_pseudo_reg (const_rtx rtl)
6169 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6170 || (GET_CODE (rtl) == SUBREG
6171 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6174 /* Return a reference to a type, with its const and volatile qualifiers
6178 type_main_variant (tree type)
6180 type = TYPE_MAIN_VARIANT (type);
6182 /* ??? There really should be only one main variant among any group of
6183 variants of a given type (and all of the MAIN_VARIANT values for all
6184 members of the group should point to that one type) but sometimes the C
6185 front-end messes this up for array types, so we work around that bug
6187 if (TREE_CODE (type) == ARRAY_TYPE)
6188 while (type != TYPE_MAIN_VARIANT (type))
6189 type = TYPE_MAIN_VARIANT (type);
6194 /* Return nonzero if the given type node represents a tagged type. */
6197 is_tagged_type (const_tree type)
6199 enum tree_code code = TREE_CODE (type);
6201 return (code == RECORD_TYPE || code == UNION_TYPE
6202 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6205 /* Convert a DIE tag into its string name. */
6208 dwarf_tag_name (unsigned int tag)
6212 case DW_TAG_padding:
6213 return "DW_TAG_padding";
6214 case DW_TAG_array_type:
6215 return "DW_TAG_array_type";
6216 case DW_TAG_class_type:
6217 return "DW_TAG_class_type";
6218 case DW_TAG_entry_point:
6219 return "DW_TAG_entry_point";
6220 case DW_TAG_enumeration_type:
6221 return "DW_TAG_enumeration_type";
6222 case DW_TAG_formal_parameter:
6223 return "DW_TAG_formal_parameter";
6224 case DW_TAG_imported_declaration:
6225 return "DW_TAG_imported_declaration";
6227 return "DW_TAG_label";
6228 case DW_TAG_lexical_block:
6229 return "DW_TAG_lexical_block";
6231 return "DW_TAG_member";
6232 case DW_TAG_pointer_type:
6233 return "DW_TAG_pointer_type";
6234 case DW_TAG_reference_type:
6235 return "DW_TAG_reference_type";
6236 case DW_TAG_compile_unit:
6237 return "DW_TAG_compile_unit";
6238 case DW_TAG_string_type:
6239 return "DW_TAG_string_type";
6240 case DW_TAG_structure_type:
6241 return "DW_TAG_structure_type";
6242 case DW_TAG_subroutine_type:
6243 return "DW_TAG_subroutine_type";
6244 case DW_TAG_typedef:
6245 return "DW_TAG_typedef";
6246 case DW_TAG_union_type:
6247 return "DW_TAG_union_type";
6248 case DW_TAG_unspecified_parameters:
6249 return "DW_TAG_unspecified_parameters";
6250 case DW_TAG_variant:
6251 return "DW_TAG_variant";
6252 case DW_TAG_common_block:
6253 return "DW_TAG_common_block";
6254 case DW_TAG_common_inclusion:
6255 return "DW_TAG_common_inclusion";
6256 case DW_TAG_inheritance:
6257 return "DW_TAG_inheritance";
6258 case DW_TAG_inlined_subroutine:
6259 return "DW_TAG_inlined_subroutine";
6261 return "DW_TAG_module";
6262 case DW_TAG_ptr_to_member_type:
6263 return "DW_TAG_ptr_to_member_type";
6264 case DW_TAG_set_type:
6265 return "DW_TAG_set_type";
6266 case DW_TAG_subrange_type:
6267 return "DW_TAG_subrange_type";
6268 case DW_TAG_with_stmt:
6269 return "DW_TAG_with_stmt";
6270 case DW_TAG_access_declaration:
6271 return "DW_TAG_access_declaration";
6272 case DW_TAG_base_type:
6273 return "DW_TAG_base_type";
6274 case DW_TAG_catch_block:
6275 return "DW_TAG_catch_block";
6276 case DW_TAG_const_type:
6277 return "DW_TAG_const_type";
6278 case DW_TAG_constant:
6279 return "DW_TAG_constant";
6280 case DW_TAG_enumerator:
6281 return "DW_TAG_enumerator";
6282 case DW_TAG_file_type:
6283 return "DW_TAG_file_type";
6285 return "DW_TAG_friend";
6286 case DW_TAG_namelist:
6287 return "DW_TAG_namelist";
6288 case DW_TAG_namelist_item:
6289 return "DW_TAG_namelist_item";
6290 case DW_TAG_packed_type:
6291 return "DW_TAG_packed_type";
6292 case DW_TAG_subprogram:
6293 return "DW_TAG_subprogram";
6294 case DW_TAG_template_type_param:
6295 return "DW_TAG_template_type_param";
6296 case DW_TAG_template_value_param:
6297 return "DW_TAG_template_value_param";
6298 case DW_TAG_thrown_type:
6299 return "DW_TAG_thrown_type";
6300 case DW_TAG_try_block:
6301 return "DW_TAG_try_block";
6302 case DW_TAG_variant_part:
6303 return "DW_TAG_variant_part";
6304 case DW_TAG_variable:
6305 return "DW_TAG_variable";
6306 case DW_TAG_volatile_type:
6307 return "DW_TAG_volatile_type";
6308 case DW_TAG_dwarf_procedure:
6309 return "DW_TAG_dwarf_procedure";
6310 case DW_TAG_restrict_type:
6311 return "DW_TAG_restrict_type";
6312 case DW_TAG_interface_type:
6313 return "DW_TAG_interface_type";
6314 case DW_TAG_namespace:
6315 return "DW_TAG_namespace";
6316 case DW_TAG_imported_module:
6317 return "DW_TAG_imported_module";
6318 case DW_TAG_unspecified_type:
6319 return "DW_TAG_unspecified_type";
6320 case DW_TAG_partial_unit:
6321 return "DW_TAG_partial_unit";
6322 case DW_TAG_imported_unit:
6323 return "DW_TAG_imported_unit";
6324 case DW_TAG_condition:
6325 return "DW_TAG_condition";
6326 case DW_TAG_shared_type:
6327 return "DW_TAG_shared_type";
6328 case DW_TAG_MIPS_loop:
6329 return "DW_TAG_MIPS_loop";
6330 case DW_TAG_format_label:
6331 return "DW_TAG_format_label";
6332 case DW_TAG_function_template:
6333 return "DW_TAG_function_template";
6334 case DW_TAG_class_template:
6335 return "DW_TAG_class_template";
6336 case DW_TAG_GNU_BINCL:
6337 return "DW_TAG_GNU_BINCL";
6338 case DW_TAG_GNU_EINCL:
6339 return "DW_TAG_GNU_EINCL";
6340 case DW_TAG_GNU_template_template_param:
6341 return "DW_TAG_GNU_template_template_param";
6343 return "DW_TAG_<unknown>";
6347 /* Convert a DWARF attribute code into its string name. */
6350 dwarf_attr_name (unsigned int attr)
6355 return "DW_AT_sibling";
6356 case DW_AT_location:
6357 return "DW_AT_location";
6359 return "DW_AT_name";
6360 case DW_AT_ordering:
6361 return "DW_AT_ordering";
6362 case DW_AT_subscr_data:
6363 return "DW_AT_subscr_data";
6364 case DW_AT_byte_size:
6365 return "DW_AT_byte_size";
6366 case DW_AT_bit_offset:
6367 return "DW_AT_bit_offset";
6368 case DW_AT_bit_size:
6369 return "DW_AT_bit_size";
6370 case DW_AT_element_list:
6371 return "DW_AT_element_list";
6372 case DW_AT_stmt_list:
6373 return "DW_AT_stmt_list";
6375 return "DW_AT_low_pc";
6377 return "DW_AT_high_pc";
6378 case DW_AT_language:
6379 return "DW_AT_language";
6381 return "DW_AT_member";
6383 return "DW_AT_discr";
6384 case DW_AT_discr_value:
6385 return "DW_AT_discr_value";
6386 case DW_AT_visibility:
6387 return "DW_AT_visibility";
6389 return "DW_AT_import";
6390 case DW_AT_string_length:
6391 return "DW_AT_string_length";
6392 case DW_AT_common_reference:
6393 return "DW_AT_common_reference";
6394 case DW_AT_comp_dir:
6395 return "DW_AT_comp_dir";
6396 case DW_AT_const_value:
6397 return "DW_AT_const_value";
6398 case DW_AT_containing_type:
6399 return "DW_AT_containing_type";
6400 case DW_AT_default_value:
6401 return "DW_AT_default_value";
6403 return "DW_AT_inline";
6404 case DW_AT_is_optional:
6405 return "DW_AT_is_optional";
6406 case DW_AT_lower_bound:
6407 return "DW_AT_lower_bound";
6408 case DW_AT_producer:
6409 return "DW_AT_producer";
6410 case DW_AT_prototyped:
6411 return "DW_AT_prototyped";
6412 case DW_AT_return_addr:
6413 return "DW_AT_return_addr";
6414 case DW_AT_start_scope:
6415 return "DW_AT_start_scope";
6416 case DW_AT_bit_stride:
6417 return "DW_AT_bit_stride";
6418 case DW_AT_upper_bound:
6419 return "DW_AT_upper_bound";
6420 case DW_AT_abstract_origin:
6421 return "DW_AT_abstract_origin";
6422 case DW_AT_accessibility:
6423 return "DW_AT_accessibility";
6424 case DW_AT_address_class:
6425 return "DW_AT_address_class";
6426 case DW_AT_artificial:
6427 return "DW_AT_artificial";
6428 case DW_AT_base_types:
6429 return "DW_AT_base_types";
6430 case DW_AT_calling_convention:
6431 return "DW_AT_calling_convention";
6433 return "DW_AT_count";
6434 case DW_AT_data_member_location:
6435 return "DW_AT_data_member_location";
6436 case DW_AT_decl_column:
6437 return "DW_AT_decl_column";
6438 case DW_AT_decl_file:
6439 return "DW_AT_decl_file";
6440 case DW_AT_decl_line:
6441 return "DW_AT_decl_line";
6442 case DW_AT_declaration:
6443 return "DW_AT_declaration";
6444 case DW_AT_discr_list:
6445 return "DW_AT_discr_list";
6446 case DW_AT_encoding:
6447 return "DW_AT_encoding";
6448 case DW_AT_external:
6449 return "DW_AT_external";
6450 case DW_AT_explicit:
6451 return "DW_AT_explicit";
6452 case DW_AT_frame_base:
6453 return "DW_AT_frame_base";
6455 return "DW_AT_friend";
6456 case DW_AT_identifier_case:
6457 return "DW_AT_identifier_case";
6458 case DW_AT_macro_info:
6459 return "DW_AT_macro_info";
6460 case DW_AT_namelist_items:
6461 return "DW_AT_namelist_items";
6462 case DW_AT_priority:
6463 return "DW_AT_priority";
6465 return "DW_AT_segment";
6466 case DW_AT_specification:
6467 return "DW_AT_specification";
6468 case DW_AT_static_link:
6469 return "DW_AT_static_link";
6471 return "DW_AT_type";
6472 case DW_AT_use_location:
6473 return "DW_AT_use_location";
6474 case DW_AT_variable_parameter:
6475 return "DW_AT_variable_parameter";
6476 case DW_AT_virtuality:
6477 return "DW_AT_virtuality";
6478 case DW_AT_vtable_elem_location:
6479 return "DW_AT_vtable_elem_location";
6481 case DW_AT_allocated:
6482 return "DW_AT_allocated";
6483 case DW_AT_associated:
6484 return "DW_AT_associated";
6485 case DW_AT_data_location:
6486 return "DW_AT_data_location";
6487 case DW_AT_byte_stride:
6488 return "DW_AT_byte_stride";
6489 case DW_AT_entry_pc:
6490 return "DW_AT_entry_pc";
6491 case DW_AT_use_UTF8:
6492 return "DW_AT_use_UTF8";
6493 case DW_AT_extension:
6494 return "DW_AT_extension";
6496 return "DW_AT_ranges";
6497 case DW_AT_trampoline:
6498 return "DW_AT_trampoline";
6499 case DW_AT_call_column:
6500 return "DW_AT_call_column";
6501 case DW_AT_call_file:
6502 return "DW_AT_call_file";
6503 case DW_AT_call_line:
6504 return "DW_AT_call_line";
6506 case DW_AT_MIPS_fde:
6507 return "DW_AT_MIPS_fde";
6508 case DW_AT_MIPS_loop_begin:
6509 return "DW_AT_MIPS_loop_begin";
6510 case DW_AT_MIPS_tail_loop_begin:
6511 return "DW_AT_MIPS_tail_loop_begin";
6512 case DW_AT_MIPS_epilog_begin:
6513 return "DW_AT_MIPS_epilog_begin";
6514 case DW_AT_MIPS_loop_unroll_factor:
6515 return "DW_AT_MIPS_loop_unroll_factor";
6516 case DW_AT_MIPS_software_pipeline_depth:
6517 return "DW_AT_MIPS_software_pipeline_depth";
6518 case DW_AT_MIPS_linkage_name:
6519 return "DW_AT_MIPS_linkage_name";
6520 case DW_AT_MIPS_stride:
6521 return "DW_AT_MIPS_stride";
6522 case DW_AT_MIPS_abstract_name:
6523 return "DW_AT_MIPS_abstract_name";
6524 case DW_AT_MIPS_clone_origin:
6525 return "DW_AT_MIPS_clone_origin";
6526 case DW_AT_MIPS_has_inlines:
6527 return "DW_AT_MIPS_has_inlines";
6529 case DW_AT_sf_names:
6530 return "DW_AT_sf_names";
6531 case DW_AT_src_info:
6532 return "DW_AT_src_info";
6533 case DW_AT_mac_info:
6534 return "DW_AT_mac_info";
6535 case DW_AT_src_coords:
6536 return "DW_AT_src_coords";
6537 case DW_AT_body_begin:
6538 return "DW_AT_body_begin";
6539 case DW_AT_body_end:
6540 return "DW_AT_body_end";
6541 case DW_AT_GNU_vector:
6542 return "DW_AT_GNU_vector";
6543 case DW_AT_GNU_template_name:
6544 return "DW_AT_GNU_template_name";
6546 case DW_AT_VMS_rtnbeg_pd_address:
6547 return "DW_AT_VMS_rtnbeg_pd_address";
6550 return "DW_AT_<unknown>";
6554 /* Convert a DWARF value form code into its string name. */
6557 dwarf_form_name (unsigned int form)
6562 return "DW_FORM_addr";
6563 case DW_FORM_block2:
6564 return "DW_FORM_block2";
6565 case DW_FORM_block4:
6566 return "DW_FORM_block4";
6568 return "DW_FORM_data2";
6570 return "DW_FORM_data4";
6572 return "DW_FORM_data8";
6573 case DW_FORM_string:
6574 return "DW_FORM_string";
6576 return "DW_FORM_block";
6577 case DW_FORM_block1:
6578 return "DW_FORM_block1";
6580 return "DW_FORM_data1";
6582 return "DW_FORM_flag";
6584 return "DW_FORM_sdata";
6586 return "DW_FORM_strp";
6588 return "DW_FORM_udata";
6589 case DW_FORM_ref_addr:
6590 return "DW_FORM_ref_addr";
6592 return "DW_FORM_ref1";
6594 return "DW_FORM_ref2";
6596 return "DW_FORM_ref4";
6598 return "DW_FORM_ref8";
6599 case DW_FORM_ref_udata:
6600 return "DW_FORM_ref_udata";
6601 case DW_FORM_indirect:
6602 return "DW_FORM_indirect";
6604 return "DW_FORM_<unknown>";
6608 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6609 instance of an inlined instance of a decl which is local to an inline
6610 function, so we have to trace all of the way back through the origin chain
6611 to find out what sort of node actually served as the original seed for the
6615 decl_ultimate_origin (const_tree decl)
6617 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6620 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6621 nodes in the function to point to themselves; ignore that if
6622 we're trying to output the abstract instance of this function. */
6623 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6626 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6627 most distant ancestor, this should never happen. */
6628 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6630 return DECL_ABSTRACT_ORIGIN (decl);
6633 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6634 of a virtual function may refer to a base class, so we check the 'this'
6638 decl_class_context (tree decl)
6640 tree context = NULL_TREE;
6642 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6643 context = DECL_CONTEXT (decl);
6645 context = TYPE_MAIN_VARIANT
6646 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6648 if (context && !TYPE_P (context))
6649 context = NULL_TREE;
6654 /* Add an attribute/value pair to a DIE. */
6657 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6659 /* Maybe this should be an assert? */
6663 if (die->die_attr == NULL)
6664 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6665 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6668 static inline enum dw_val_class
6669 AT_class (dw_attr_ref a)
6671 return a->dw_attr_val.val_class;
6674 /* Add a flag value attribute to a DIE. */
6677 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6681 attr.dw_attr = attr_kind;
6682 attr.dw_attr_val.val_class = dw_val_class_flag;
6683 attr.dw_attr_val.v.val_flag = flag;
6684 add_dwarf_attr (die, &attr);
6687 static inline unsigned
6688 AT_flag (dw_attr_ref a)
6690 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6691 return a->dw_attr_val.v.val_flag;
6694 /* Add a signed integer attribute value to a DIE. */
6697 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6701 attr.dw_attr = attr_kind;
6702 attr.dw_attr_val.val_class = dw_val_class_const;
6703 attr.dw_attr_val.v.val_int = int_val;
6704 add_dwarf_attr (die, &attr);
6707 static inline HOST_WIDE_INT
6708 AT_int (dw_attr_ref a)
6710 gcc_assert (a && AT_class (a) == dw_val_class_const);
6711 return a->dw_attr_val.v.val_int;
6714 /* Add an unsigned integer attribute value to a DIE. */
6717 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6718 unsigned HOST_WIDE_INT unsigned_val)
6722 attr.dw_attr = attr_kind;
6723 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6724 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6725 add_dwarf_attr (die, &attr);
6728 static inline unsigned HOST_WIDE_INT
6729 AT_unsigned (dw_attr_ref a)
6731 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6732 return a->dw_attr_val.v.val_unsigned;
6735 /* Add an unsigned double integer attribute value to a DIE. */
6738 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
6739 rtx val_const_double)
6743 attr.dw_attr = attr_kind;
6744 attr.dw_attr_val.val_class = dw_val_class_long_long;
6745 attr.dw_attr_val.v.val_long_long = val_const_double;
6746 add_dwarf_attr (die, &attr);
6749 /* Add a floating point attribute value to a DIE and return it. */
6752 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6753 unsigned int length, unsigned int elt_size, unsigned char *array)
6757 attr.dw_attr = attr_kind;
6758 attr.dw_attr_val.val_class = dw_val_class_vec;
6759 attr.dw_attr_val.v.val_vec.length = length;
6760 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6761 attr.dw_attr_val.v.val_vec.array = array;
6762 add_dwarf_attr (die, &attr);
6765 /* Hash and equality functions for debug_str_hash. */
6768 debug_str_do_hash (const void *x)
6770 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6774 debug_str_eq (const void *x1, const void *x2)
6776 return strcmp ((((const struct indirect_string_node *)x1)->str),
6777 (const char *)x2) == 0;
6780 /* Add STR to the indirect string hash table. */
6782 static struct indirect_string_node *
6783 find_AT_string (const char *str)
6785 struct indirect_string_node *node;
6788 if (! debug_str_hash)
6789 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6790 debug_str_eq, NULL);
6792 slot = htab_find_slot_with_hash (debug_str_hash, str,
6793 htab_hash_string (str), INSERT);
6796 node = (struct indirect_string_node *)
6797 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6798 node->str = ggc_strdup (str);
6802 node = (struct indirect_string_node *) *slot;
6808 /* Add a string attribute value to a DIE. */
6811 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6814 struct indirect_string_node *node;
6816 node = find_AT_string (str);
6818 attr.dw_attr = attr_kind;
6819 attr.dw_attr_val.val_class = dw_val_class_str;
6820 attr.dw_attr_val.v.val_str = node;
6821 add_dwarf_attr (die, &attr);
6824 /* Create a label for an indirect string node, ensuring it is going to
6825 be output, unless its reference count goes down to zero. */
6828 gen_label_for_indirect_string (struct indirect_string_node *node)
6835 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6836 ++dw2_string_counter;
6837 node->label = xstrdup (label);
6840 /* Create a SYMBOL_REF rtx whose value is the initial address of a
6841 debug string STR. */
6844 get_debug_string_label (const char *str)
6846 struct indirect_string_node *node = find_AT_string (str);
6848 debug_str_hash_forced = true;
6850 gen_label_for_indirect_string (node);
6852 return gen_rtx_SYMBOL_REF (Pmode, node->label);
6855 static inline const char *
6856 AT_string (dw_attr_ref a)
6858 gcc_assert (a && AT_class (a) == dw_val_class_str);
6859 return a->dw_attr_val.v.val_str->str;
6862 /* Find out whether a string should be output inline in DIE
6863 or out-of-line in .debug_str section. */
6865 static enum dwarf_form
6866 AT_string_form (dw_attr_ref a)
6868 struct indirect_string_node *node;
6871 gcc_assert (a && AT_class (a) == dw_val_class_str);
6873 node = a->dw_attr_val.v.val_str;
6877 len = strlen (node->str) + 1;
6879 /* If the string is shorter or equal to the size of the reference, it is
6880 always better to put it inline. */
6881 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6882 return node->form = DW_FORM_string;
6884 /* If we cannot expect the linker to merge strings in .debug_str
6885 section, only put it into .debug_str if it is worth even in this
6887 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
6888 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
6889 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
6890 return node->form = DW_FORM_string;
6892 gen_label_for_indirect_string (node);
6894 return node->form = DW_FORM_strp;
6897 /* Add a DIE reference attribute value to a DIE. */
6900 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6904 attr.dw_attr = attr_kind;
6905 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6906 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6907 attr.dw_attr_val.v.val_die_ref.external = 0;
6908 add_dwarf_attr (die, &attr);
6911 /* Add an AT_specification attribute to a DIE, and also make the back
6912 pointer from the specification to the definition. */
6915 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6917 add_AT_die_ref (die, DW_AT_specification, targ_die);
6918 gcc_assert (!targ_die->die_definition);
6919 targ_die->die_definition = die;
6922 static inline dw_die_ref
6923 AT_ref (dw_attr_ref a)
6925 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6926 return a->dw_attr_val.v.val_die_ref.die;
6930 AT_ref_external (dw_attr_ref a)
6932 if (a && AT_class (a) == dw_val_class_die_ref)
6933 return a->dw_attr_val.v.val_die_ref.external;
6939 set_AT_ref_external (dw_attr_ref a, int i)
6941 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6942 a->dw_attr_val.v.val_die_ref.external = i;
6945 /* Add an FDE reference attribute value to a DIE. */
6948 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6952 attr.dw_attr = attr_kind;
6953 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6954 attr.dw_attr_val.v.val_fde_index = targ_fde;
6955 add_dwarf_attr (die, &attr);
6958 /* Add a location description attribute value to a DIE. */
6961 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6965 attr.dw_attr = attr_kind;
6966 attr.dw_attr_val.val_class = dw_val_class_loc;
6967 attr.dw_attr_val.v.val_loc = loc;
6968 add_dwarf_attr (die, &attr);
6971 static inline dw_loc_descr_ref
6972 AT_loc (dw_attr_ref a)
6974 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6975 return a->dw_attr_val.v.val_loc;
6979 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6983 attr.dw_attr = attr_kind;
6984 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6985 attr.dw_attr_val.v.val_loc_list = loc_list;
6986 add_dwarf_attr (die, &attr);
6987 have_location_lists = true;
6990 static inline dw_loc_list_ref
6991 AT_loc_list (dw_attr_ref a)
6993 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6994 return a->dw_attr_val.v.val_loc_list;
6997 /* Add an address constant attribute value to a DIE. */
7000 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7004 attr.dw_attr = attr_kind;
7005 attr.dw_attr_val.val_class = dw_val_class_addr;
7006 attr.dw_attr_val.v.val_addr = addr;
7007 add_dwarf_attr (die, &attr);
7010 /* Get the RTX from to an address DIE attribute. */
7013 AT_addr (dw_attr_ref a)
7015 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7016 return a->dw_attr_val.v.val_addr;
7019 /* Add a file attribute value to a DIE. */
7022 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7023 struct dwarf_file_data *fd)
7027 attr.dw_attr = attr_kind;
7028 attr.dw_attr_val.val_class = dw_val_class_file;
7029 attr.dw_attr_val.v.val_file = fd;
7030 add_dwarf_attr (die, &attr);
7033 /* Get the dwarf_file_data from a file DIE attribute. */
7035 static inline struct dwarf_file_data *
7036 AT_file (dw_attr_ref a)
7038 gcc_assert (a && AT_class (a) == dw_val_class_file);
7039 return a->dw_attr_val.v.val_file;
7042 /* Add a label identifier attribute value to a DIE. */
7045 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7049 attr.dw_attr = attr_kind;
7050 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7051 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7052 add_dwarf_attr (die, &attr);
7055 /* Add a section offset attribute value to a DIE, an offset into the
7056 debug_line section. */
7059 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7064 attr.dw_attr = attr_kind;
7065 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7066 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7067 add_dwarf_attr (die, &attr);
7070 /* Add a section offset attribute value to a DIE, an offset into the
7071 debug_macinfo section. */
7074 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7079 attr.dw_attr = attr_kind;
7080 attr.dw_attr_val.val_class = dw_val_class_macptr;
7081 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7082 add_dwarf_attr (die, &attr);
7085 /* Add an offset attribute value to a DIE. */
7088 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7089 unsigned HOST_WIDE_INT offset)
7093 attr.dw_attr = attr_kind;
7094 attr.dw_attr_val.val_class = dw_val_class_offset;
7095 attr.dw_attr_val.v.val_offset = offset;
7096 add_dwarf_attr (die, &attr);
7099 /* Add an range_list attribute value to a DIE. */
7102 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7103 long unsigned int offset)
7107 attr.dw_attr = attr_kind;
7108 attr.dw_attr_val.val_class = dw_val_class_range_list;
7109 attr.dw_attr_val.v.val_offset = offset;
7110 add_dwarf_attr (die, &attr);
7113 static inline const char *
7114 AT_lbl (dw_attr_ref a)
7116 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7117 || AT_class (a) == dw_val_class_lineptr
7118 || AT_class (a) == dw_val_class_macptr));
7119 return a->dw_attr_val.v.val_lbl_id;
7122 /* Get the attribute of type attr_kind. */
7125 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7129 dw_die_ref spec = NULL;
7134 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7135 if (a->dw_attr == attr_kind)
7137 else if (a->dw_attr == DW_AT_specification
7138 || a->dw_attr == DW_AT_abstract_origin)
7142 return get_AT (spec, attr_kind);
7147 /* Return the "low pc" attribute value, typically associated with a subprogram
7148 DIE. Return null if the "low pc" attribute is either not present, or if it
7149 cannot be represented as an assembler label identifier. */
7151 static inline const char *
7152 get_AT_low_pc (dw_die_ref die)
7154 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7156 return a ? AT_lbl (a) : NULL;
7159 /* Return the "high pc" attribute value, typically associated with a subprogram
7160 DIE. Return null if the "high pc" attribute is either not present, or if it
7161 cannot be represented as an assembler label identifier. */
7163 static inline const char *
7164 get_AT_hi_pc (dw_die_ref die)
7166 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7168 return a ? AT_lbl (a) : NULL;
7171 /* Return the value of the string attribute designated by ATTR_KIND, or
7172 NULL if it is not present. */
7174 static inline const char *
7175 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7177 dw_attr_ref a = get_AT (die, attr_kind);
7179 return a ? AT_string (a) : NULL;
7182 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7183 if it is not present. */
7186 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7188 dw_attr_ref a = get_AT (die, attr_kind);
7190 return a ? AT_flag (a) : 0;
7193 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7194 if it is not present. */
7196 static inline unsigned
7197 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7199 dw_attr_ref a = get_AT (die, attr_kind);
7201 return a ? AT_unsigned (a) : 0;
7204 static inline dw_die_ref
7205 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7207 dw_attr_ref a = get_AT (die, attr_kind);
7209 return a ? AT_ref (a) : NULL;
7212 static inline struct dwarf_file_data *
7213 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7215 dw_attr_ref a = get_AT (die, attr_kind);
7217 return a ? AT_file (a) : NULL;
7220 /* Return TRUE if the language is C or C++. */
7225 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7227 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
7228 || lang == DW_LANG_C99
7229 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
7232 /* Return TRUE if the language is C++. */
7237 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7239 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7242 /* Return TRUE if the language is Fortran. */
7247 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7249 return (lang == DW_LANG_Fortran77
7250 || lang == DW_LANG_Fortran90
7251 || lang == DW_LANG_Fortran95);
7254 /* Return TRUE if the language is Java. */
7259 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7261 return lang == DW_LANG_Java;
7264 /* Return TRUE if the language is Ada. */
7269 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7271 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7274 /* Remove the specified attribute if present. */
7277 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7285 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7286 if (a->dw_attr == attr_kind)
7288 if (AT_class (a) == dw_val_class_str)
7289 if (a->dw_attr_val.v.val_str->refcount)
7290 a->dw_attr_val.v.val_str->refcount--;
7292 /* VEC_ordered_remove should help reduce the number of abbrevs
7294 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7299 /* Remove CHILD from its parent. PREV must have the property that
7300 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7303 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7305 gcc_assert (child->die_parent == prev->die_parent);
7306 gcc_assert (prev->die_sib == child);
7309 gcc_assert (child->die_parent->die_child == child);
7313 prev->die_sib = child->die_sib;
7314 if (child->die_parent->die_child == child)
7315 child->die_parent->die_child = prev;
7318 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7322 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7328 dw_die_ref prev = c;
7330 while (c->die_tag == tag)
7332 remove_child_with_prev (c, prev);
7333 /* Might have removed every child. */
7334 if (c == c->die_sib)
7338 } while (c != die->die_child);
7341 /* Add a CHILD_DIE as the last child of DIE. */
7344 add_child_die (dw_die_ref die, dw_die_ref child_die)
7346 /* FIXME this should probably be an assert. */
7347 if (! die || ! child_die)
7349 gcc_assert (die != child_die);
7351 child_die->die_parent = die;
7354 child_die->die_sib = die->die_child->die_sib;
7355 die->die_child->die_sib = child_die;
7358 child_die->die_sib = child_die;
7359 die->die_child = child_die;
7362 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7363 is the specification, to the end of PARENT's list of children.
7364 This is done by removing and re-adding it. */
7367 splice_child_die (dw_die_ref parent, dw_die_ref child)
7371 /* We want the declaration DIE from inside the class, not the
7372 specification DIE at toplevel. */
7373 if (child->die_parent != parent)
7375 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7381 gcc_assert (child->die_parent == parent
7382 || (child->die_parent
7383 == get_AT_ref (parent, DW_AT_specification)));
7385 for (p = child->die_parent->die_child; ; p = p->die_sib)
7386 if (p->die_sib == child)
7388 remove_child_with_prev (child, p);
7392 add_child_die (parent, child);
7395 /* Return a pointer to a newly created DIE node. */
7397 static inline dw_die_ref
7398 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7400 dw_die_ref die = GGC_CNEW (die_node);
7402 die->die_tag = tag_value;
7404 if (parent_die != NULL)
7405 add_child_die (parent_die, die);
7408 limbo_die_node *limbo_node;
7410 limbo_node = GGC_CNEW (limbo_die_node);
7411 limbo_node->die = die;
7412 limbo_node->created_for = t;
7413 limbo_node->next = limbo_die_list;
7414 limbo_die_list = limbo_node;
7420 /* Return the DIE associated with the given type specifier. */
7422 static inline dw_die_ref
7423 lookup_type_die (tree type)
7425 return TYPE_SYMTAB_DIE (type);
7428 /* Equate a DIE to a given type specifier. */
7431 equate_type_number_to_die (tree type, dw_die_ref type_die)
7433 TYPE_SYMTAB_DIE (type) = type_die;
7436 /* Returns a hash value for X (which really is a die_struct). */
7439 decl_die_table_hash (const void *x)
7441 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7444 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7447 decl_die_table_eq (const void *x, const void *y)
7449 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7452 /* Return the DIE associated with a given declaration. */
7454 static inline dw_die_ref
7455 lookup_decl_die (tree decl)
7457 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7460 /* Returns a hash value for X (which really is a var_loc_list). */
7463 decl_loc_table_hash (const void *x)
7465 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7468 /* Return nonzero if decl_id of var_loc_list X is the same as
7472 decl_loc_table_eq (const void *x, const void *y)
7474 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7477 /* Return the var_loc list associated with a given declaration. */
7479 static inline var_loc_list *
7480 lookup_decl_loc (const_tree decl)
7482 return (var_loc_list *)
7483 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7486 /* Equate a DIE to a particular declaration. */
7489 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7491 unsigned int decl_id = DECL_UID (decl);
7494 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7496 decl_die->decl_id = decl_id;
7499 /* Add a variable location node to the linked list for DECL. */
7502 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7504 unsigned int decl_id = DECL_UID (decl);
7508 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7511 temp = GGC_CNEW (var_loc_list);
7512 temp->decl_id = decl_id;
7516 temp = (var_loc_list *) *slot;
7520 /* If the current location is the same as the end of the list,
7521 and either both or neither of the locations is uninitialized,
7522 we have nothing to do. */
7523 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7524 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7525 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7526 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7527 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7528 == VAR_INIT_STATUS_UNINITIALIZED)
7529 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7530 == VAR_INIT_STATUS_UNINITIALIZED))))
7532 /* Add LOC to the end of list and update LAST. */
7533 temp->last->next = loc;
7537 /* Do not add empty location to the beginning of the list. */
7538 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7545 /* Keep track of the number of spaces used to indent the
7546 output of the debugging routines that print the structure of
7547 the DIE internal representation. */
7548 static int print_indent;
7550 /* Indent the line the number of spaces given by print_indent. */
7553 print_spaces (FILE *outfile)
7555 fprintf (outfile, "%*s", print_indent, "");
7558 /* Print the information associated with a given DIE, and its children.
7559 This routine is a debugging aid only. */
7562 print_die (dw_die_ref die, FILE *outfile)
7568 print_spaces (outfile);
7569 fprintf (outfile, "DIE %4ld: %s\n",
7570 die->die_offset, dwarf_tag_name (die->die_tag));
7571 print_spaces (outfile);
7572 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7573 fprintf (outfile, " offset: %ld\n", die->die_offset);
7575 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7577 print_spaces (outfile);
7578 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7580 switch (AT_class (a))
7582 case dw_val_class_addr:
7583 fprintf (outfile, "address");
7585 case dw_val_class_offset:
7586 fprintf (outfile, "offset");
7588 case dw_val_class_loc:
7589 fprintf (outfile, "location descriptor");
7591 case dw_val_class_loc_list:
7592 fprintf (outfile, "location list -> label:%s",
7593 AT_loc_list (a)->ll_symbol);
7595 case dw_val_class_range_list:
7596 fprintf (outfile, "range list");
7598 case dw_val_class_const:
7599 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7601 case dw_val_class_unsigned_const:
7602 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7604 case dw_val_class_long_long:
7605 fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_UNSIGNED
7606 "," HOST_WIDE_INT_PRINT_UNSIGNED ")",
7607 CONST_DOUBLE_HIGH (a->dw_attr_val.v.val_long_long),
7608 CONST_DOUBLE_LOW (a->dw_attr_val.v.val_long_long));
7610 case dw_val_class_vec:
7611 fprintf (outfile, "floating-point or vector constant");
7613 case dw_val_class_flag:
7614 fprintf (outfile, "%u", AT_flag (a));
7616 case dw_val_class_die_ref:
7617 if (AT_ref (a) != NULL)
7619 if (AT_ref (a)->die_symbol)
7620 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7622 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7625 fprintf (outfile, "die -> <null>");
7627 case dw_val_class_lbl_id:
7628 case dw_val_class_lineptr:
7629 case dw_val_class_macptr:
7630 fprintf (outfile, "label: %s", AT_lbl (a));
7632 case dw_val_class_str:
7633 if (AT_string (a) != NULL)
7634 fprintf (outfile, "\"%s\"", AT_string (a));
7636 fprintf (outfile, "<null>");
7638 case dw_val_class_file:
7639 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7640 AT_file (a)->emitted_number);
7646 fprintf (outfile, "\n");
7649 if (die->die_child != NULL)
7652 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7655 if (print_indent == 0)
7656 fprintf (outfile, "\n");
7659 /* Print the contents of the source code line number correspondence table.
7660 This routine is a debugging aid only. */
7663 print_dwarf_line_table (FILE *outfile)
7666 dw_line_info_ref line_info;
7668 fprintf (outfile, "\n\nDWARF source line information\n");
7669 for (i = 1; i < line_info_table_in_use; i++)
7671 line_info = &line_info_table[i];
7672 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7673 line_info->dw_file_num,
7674 line_info->dw_line_num);
7677 fprintf (outfile, "\n\n");
7680 /* Print the information collected for a given DIE. */
7683 debug_dwarf_die (dw_die_ref die)
7685 print_die (die, stderr);
7688 /* Print all DWARF information collected for the compilation unit.
7689 This routine is a debugging aid only. */
7695 print_die (comp_unit_die, stderr);
7696 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7697 print_dwarf_line_table (stderr);
7700 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7701 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7702 DIE that marks the start of the DIEs for this include file. */
7705 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7707 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7708 dw_die_ref new_unit = gen_compile_unit_die (filename);
7710 new_unit->die_sib = old_unit;
7714 /* Close an include-file CU and reopen the enclosing one. */
7717 pop_compile_unit (dw_die_ref old_unit)
7719 dw_die_ref new_unit = old_unit->die_sib;
7721 old_unit->die_sib = NULL;
7725 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7726 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7728 /* Calculate the checksum of a location expression. */
7731 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7735 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7737 CHECKSUM (loc->dw_loc_oprnd1);
7738 CHECKSUM (loc->dw_loc_oprnd2);
7741 /* Calculate the checksum of an attribute. */
7744 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7746 dw_loc_descr_ref loc;
7749 CHECKSUM (at->dw_attr);
7751 /* We don't care that this was compiled with a different compiler
7752 snapshot; if the output is the same, that's what matters. */
7753 if (at->dw_attr == DW_AT_producer)
7756 switch (AT_class (at))
7758 case dw_val_class_const:
7759 CHECKSUM (at->dw_attr_val.v.val_int);
7761 case dw_val_class_unsigned_const:
7762 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7764 case dw_val_class_long_long:
7765 CHECKSUM (CONST_DOUBLE_HIGH (at->dw_attr_val.v.val_long_long));
7766 CHECKSUM (CONST_DOUBLE_LOW (at->dw_attr_val.v.val_long_long));
7768 case dw_val_class_vec:
7769 CHECKSUM (at->dw_attr_val.v.val_vec);
7771 case dw_val_class_flag:
7772 CHECKSUM (at->dw_attr_val.v.val_flag);
7774 case dw_val_class_str:
7775 CHECKSUM_STRING (AT_string (at));
7778 case dw_val_class_addr:
7780 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7781 CHECKSUM_STRING (XSTR (r, 0));
7784 case dw_val_class_offset:
7785 CHECKSUM (at->dw_attr_val.v.val_offset);
7788 case dw_val_class_loc:
7789 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7790 loc_checksum (loc, ctx);
7793 case dw_val_class_die_ref:
7794 die_checksum (AT_ref (at), ctx, mark);
7797 case dw_val_class_fde_ref:
7798 case dw_val_class_lbl_id:
7799 case dw_val_class_lineptr:
7800 case dw_val_class_macptr:
7803 case dw_val_class_file:
7804 CHECKSUM_STRING (AT_file (at)->filename);
7812 /* Calculate the checksum of a DIE. */
7815 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7821 /* To avoid infinite recursion. */
7824 CHECKSUM (die->die_mark);
7827 die->die_mark = ++(*mark);
7829 CHECKSUM (die->die_tag);
7831 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7832 attr_checksum (a, ctx, mark);
7834 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7838 #undef CHECKSUM_STRING
7840 /* Do the location expressions look same? */
7842 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7844 return loc1->dw_loc_opc == loc2->dw_loc_opc
7845 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7846 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7849 /* Do the values look the same? */
7851 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7853 dw_loc_descr_ref loc1, loc2;
7856 if (v1->val_class != v2->val_class)
7859 switch (v1->val_class)
7861 case dw_val_class_const:
7862 return v1->v.val_int == v2->v.val_int;
7863 case dw_val_class_unsigned_const:
7864 return v1->v.val_unsigned == v2->v.val_unsigned;
7865 case dw_val_class_long_long:
7866 return CONST_DOUBLE_HIGH (v1->v.val_long_long)
7867 == CONST_DOUBLE_HIGH (v2->v.val_long_long)
7868 && CONST_DOUBLE_LOW (v1->v.val_long_long)
7869 == CONST_DOUBLE_LOW (v2->v.val_long_long);
7870 case dw_val_class_vec:
7871 if (v1->v.val_vec.length != v2->v.val_vec.length
7872 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7874 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7875 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7878 case dw_val_class_flag:
7879 return v1->v.val_flag == v2->v.val_flag;
7880 case dw_val_class_str:
7881 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7883 case dw_val_class_addr:
7884 r1 = v1->v.val_addr;
7885 r2 = v2->v.val_addr;
7886 if (GET_CODE (r1) != GET_CODE (r2))
7888 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7889 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7891 case dw_val_class_offset:
7892 return v1->v.val_offset == v2->v.val_offset;
7894 case dw_val_class_loc:
7895 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7897 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7898 if (!same_loc_p (loc1, loc2, mark))
7900 return !loc1 && !loc2;
7902 case dw_val_class_die_ref:
7903 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7905 case dw_val_class_fde_ref:
7906 case dw_val_class_lbl_id:
7907 case dw_val_class_lineptr:
7908 case dw_val_class_macptr:
7911 case dw_val_class_file:
7912 return v1->v.val_file == v2->v.val_file;
7919 /* Do the attributes look the same? */
7922 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7924 if (at1->dw_attr != at2->dw_attr)
7927 /* We don't care that this was compiled with a different compiler
7928 snapshot; if the output is the same, that's what matters. */
7929 if (at1->dw_attr == DW_AT_producer)
7932 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7935 /* Do the dies look the same? */
7938 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7944 /* To avoid infinite recursion. */
7946 return die1->die_mark == die2->die_mark;
7947 die1->die_mark = die2->die_mark = ++(*mark);
7949 if (die1->die_tag != die2->die_tag)
7952 if (VEC_length (dw_attr_node, die1->die_attr)
7953 != VEC_length (dw_attr_node, die2->die_attr))
7956 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7957 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7960 c1 = die1->die_child;
7961 c2 = die2->die_child;
7970 if (!same_die_p (c1, c2, mark))
7974 if (c1 == die1->die_child)
7976 if (c2 == die2->die_child)
7986 /* Do the dies look the same? Wrapper around same_die_p. */
7989 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7992 int ret = same_die_p (die1, die2, &mark);
7994 unmark_all_dies (die1);
7995 unmark_all_dies (die2);
8000 /* The prefix to attach to symbols on DIEs in the current comdat debug
8002 static char *comdat_symbol_id;
8004 /* The index of the current symbol within the current comdat CU. */
8005 static unsigned int comdat_symbol_number;
8007 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8008 children, and set comdat_symbol_id accordingly. */
8011 compute_section_prefix (dw_die_ref unit_die)
8013 const char *die_name = get_AT_string (unit_die, DW_AT_name);
8014 const char *base = die_name ? lbasename (die_name) : "anonymous";
8015 char *name = XALLOCAVEC (char, strlen (base) + 64);
8018 unsigned char checksum[16];
8021 /* Compute the checksum of the DIE, then append part of it as hex digits to
8022 the name filename of the unit. */
8024 md5_init_ctx (&ctx);
8026 die_checksum (unit_die, &ctx, &mark);
8027 unmark_all_dies (unit_die);
8028 md5_finish_ctx (&ctx, checksum);
8030 sprintf (name, "%s.", base);
8031 clean_symbol_name (name);
8033 p = name + strlen (name);
8034 for (i = 0; i < 4; i++)
8036 sprintf (p, "%.2x", checksum[i]);
8040 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
8041 comdat_symbol_number = 0;
8044 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
8047 is_type_die (dw_die_ref die)
8049 switch (die->die_tag)
8051 case DW_TAG_array_type:
8052 case DW_TAG_class_type:
8053 case DW_TAG_interface_type:
8054 case DW_TAG_enumeration_type:
8055 case DW_TAG_pointer_type:
8056 case DW_TAG_reference_type:
8057 case DW_TAG_string_type:
8058 case DW_TAG_structure_type:
8059 case DW_TAG_subroutine_type:
8060 case DW_TAG_union_type:
8061 case DW_TAG_ptr_to_member_type:
8062 case DW_TAG_set_type:
8063 case DW_TAG_subrange_type:
8064 case DW_TAG_base_type:
8065 case DW_TAG_const_type:
8066 case DW_TAG_file_type:
8067 case DW_TAG_packed_type:
8068 case DW_TAG_volatile_type:
8069 case DW_TAG_typedef:
8076 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
8077 Basically, we want to choose the bits that are likely to be shared between
8078 compilations (types) and leave out the bits that are specific to individual
8079 compilations (functions). */
8082 is_comdat_die (dw_die_ref c)
8084 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
8085 we do for stabs. The advantage is a greater likelihood of sharing between
8086 objects that don't include headers in the same order (and therefore would
8087 put the base types in a different comdat). jason 8/28/00 */
8089 if (c->die_tag == DW_TAG_base_type)
8092 if (c->die_tag == DW_TAG_pointer_type
8093 || c->die_tag == DW_TAG_reference_type
8094 || c->die_tag == DW_TAG_const_type
8095 || c->die_tag == DW_TAG_volatile_type)
8097 dw_die_ref t = get_AT_ref (c, DW_AT_type);
8099 return t ? is_comdat_die (t) : 0;
8102 return is_type_die (c);
8105 /* Returns 1 iff C is the sort of DIE that might be referred to from another
8106 compilation unit. */
8109 is_symbol_die (dw_die_ref c)
8111 return (is_type_die (c)
8112 || (get_AT (c, DW_AT_declaration)
8113 && !get_AT (c, DW_AT_specification))
8114 || c->die_tag == DW_TAG_namespace
8115 || c->die_tag == DW_TAG_module);
8119 gen_internal_sym (const char *prefix)
8123 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8124 return xstrdup (buf);
8127 /* Assign symbols to all worthy DIEs under DIE. */
8130 assign_symbol_names (dw_die_ref die)
8134 if (is_symbol_die (die))
8136 if (comdat_symbol_id)
8138 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
8140 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
8141 comdat_symbol_id, comdat_symbol_number++);
8142 die->die_symbol = xstrdup (p);
8145 die->die_symbol = gen_internal_sym ("LDIE");
8148 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
8151 struct cu_hash_table_entry
8154 unsigned min_comdat_num, max_comdat_num;
8155 struct cu_hash_table_entry *next;
8158 /* Routines to manipulate hash table of CUs. */
8160 htab_cu_hash (const void *of)
8162 const struct cu_hash_table_entry *const entry =
8163 (const struct cu_hash_table_entry *) of;
8165 return htab_hash_string (entry->cu->die_symbol);
8169 htab_cu_eq (const void *of1, const void *of2)
8171 const struct cu_hash_table_entry *const entry1 =
8172 (const struct cu_hash_table_entry *) of1;
8173 const struct die_struct *const entry2 = (const struct die_struct *) of2;
8175 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
8179 htab_cu_del (void *what)
8181 struct cu_hash_table_entry *next,
8182 *entry = (struct cu_hash_table_entry *) what;
8192 /* Check whether we have already seen this CU and set up SYM_NUM
8195 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
8197 struct cu_hash_table_entry dummy;
8198 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
8200 dummy.max_comdat_num = 0;
8202 slot = (struct cu_hash_table_entry **)
8203 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8207 for (; entry; last = entry, entry = entry->next)
8209 if (same_die_p_wrap (cu, entry->cu))
8215 *sym_num = entry->min_comdat_num;
8219 entry = XCNEW (struct cu_hash_table_entry);
8221 entry->min_comdat_num = *sym_num = last->max_comdat_num;
8222 entry->next = *slot;
8228 /* Record SYM_NUM to record of CU in HTABLE. */
8230 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
8232 struct cu_hash_table_entry **slot, *entry;
8234 slot = (struct cu_hash_table_entry **)
8235 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8239 entry->max_comdat_num = sym_num;
8242 /* Traverse the DIE (which is always comp_unit_die), and set up
8243 additional compilation units for each of the include files we see
8244 bracketed by BINCL/EINCL. */
8247 break_out_includes (dw_die_ref die)
8250 dw_die_ref unit = NULL;
8251 limbo_die_node *node, **pnode;
8252 htab_t cu_hash_table;
8256 dw_die_ref prev = c;
8258 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
8259 || (unit && is_comdat_die (c)))
8261 dw_die_ref next = c->die_sib;
8263 /* This DIE is for a secondary CU; remove it from the main one. */
8264 remove_child_with_prev (c, prev);
8266 if (c->die_tag == DW_TAG_GNU_BINCL)
8267 unit = push_new_compile_unit (unit, c);
8268 else if (c->die_tag == DW_TAG_GNU_EINCL)
8269 unit = pop_compile_unit (unit);
8271 add_child_die (unit, c);
8273 if (c == die->die_child)
8276 } while (c != die->die_child);
8279 /* We can only use this in debugging, since the frontend doesn't check
8280 to make sure that we leave every include file we enter. */
8284 assign_symbol_names (die);
8285 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
8286 for (node = limbo_die_list, pnode = &limbo_die_list;
8292 compute_section_prefix (node->die);
8293 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
8294 &comdat_symbol_number);
8295 assign_symbol_names (node->die);
8297 *pnode = node->next;
8300 pnode = &node->next;
8301 record_comdat_symbol_number (node->die, cu_hash_table,
8302 comdat_symbol_number);
8305 htab_delete (cu_hash_table);
8308 /* Traverse the DIE and add a sibling attribute if it may have the
8309 effect of speeding up access to siblings. To save some space,
8310 avoid generating sibling attributes for DIE's without children. */
8313 add_sibling_attributes (dw_die_ref die)
8317 if (! die->die_child)
8320 if (die->die_parent && die != die->die_parent->die_child)
8321 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8323 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8326 /* Output all location lists for the DIE and its children. */
8329 output_location_lists (dw_die_ref die)
8335 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8336 if (AT_class (a) == dw_val_class_loc_list)
8337 output_loc_list (AT_loc_list (a));
8339 FOR_EACH_CHILD (die, c, output_location_lists (c));
8342 /* The format of each DIE (and its attribute value pairs) is encoded in an
8343 abbreviation table. This routine builds the abbreviation table and assigns
8344 a unique abbreviation id for each abbreviation entry. The children of each
8345 die are visited recursively. */
8348 build_abbrev_table (dw_die_ref die)
8350 unsigned long abbrev_id;
8351 unsigned int n_alloc;
8356 /* Scan the DIE references, and mark as external any that refer to
8357 DIEs from other CUs (i.e. those which are not marked). */
8358 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8359 if (AT_class (a) == dw_val_class_die_ref
8360 && AT_ref (a)->die_mark == 0)
8362 gcc_assert (AT_ref (a)->die_symbol);
8363 set_AT_ref_external (a, 1);
8366 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8368 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8369 dw_attr_ref die_a, abbrev_a;
8373 if (abbrev->die_tag != die->die_tag)
8375 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8378 if (VEC_length (dw_attr_node, abbrev->die_attr)
8379 != VEC_length (dw_attr_node, die->die_attr))
8382 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
8384 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8385 if ((abbrev_a->dw_attr != die_a->dw_attr)
8386 || (value_format (abbrev_a) != value_format (die_a)))
8396 if (abbrev_id >= abbrev_die_table_in_use)
8398 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8400 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8401 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8404 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8405 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8406 abbrev_die_table_allocated = n_alloc;
8409 ++abbrev_die_table_in_use;
8410 abbrev_die_table[abbrev_id] = die;
8413 die->die_abbrev = abbrev_id;
8414 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8417 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8420 constant_size (unsigned HOST_WIDE_INT value)
8427 log = floor_log2 (value);
8430 log = 1 << (floor_log2 (log) + 1);
8435 /* Return the size of a DIE as it is represented in the
8436 .debug_info section. */
8438 static unsigned long
8439 size_of_die (dw_die_ref die)
8441 unsigned long size = 0;
8445 size += size_of_uleb128 (die->die_abbrev);
8446 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8448 switch (AT_class (a))
8450 case dw_val_class_addr:
8451 size += DWARF2_ADDR_SIZE;
8453 case dw_val_class_offset:
8454 size += DWARF_OFFSET_SIZE;
8456 case dw_val_class_loc:
8458 unsigned long lsize = size_of_locs (AT_loc (a));
8461 size += constant_size (lsize);
8465 case dw_val_class_loc_list:
8466 size += DWARF_OFFSET_SIZE;
8468 case dw_val_class_range_list:
8469 size += DWARF_OFFSET_SIZE;
8471 case dw_val_class_const:
8472 size += size_of_sleb128 (AT_int (a));
8474 case dw_val_class_unsigned_const:
8475 size += constant_size (AT_unsigned (a));
8477 case dw_val_class_long_long:
8478 size += 1 + 2*HOST_BITS_PER_WIDE_INT/HOST_BITS_PER_CHAR; /* block */
8480 case dw_val_class_vec:
8481 size += constant_size (a->dw_attr_val.v.val_vec.length
8482 * a->dw_attr_val.v.val_vec.elt_size)
8483 + a->dw_attr_val.v.val_vec.length
8484 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8486 case dw_val_class_flag:
8489 case dw_val_class_die_ref:
8490 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8491 whereas in DWARF3 it's always sized as an offset. */
8492 if (AT_ref_external (a) && dwarf_version == 2)
8493 size += DWARF2_ADDR_SIZE;
8495 size += DWARF_OFFSET_SIZE;
8497 case dw_val_class_fde_ref:
8498 size += DWARF_OFFSET_SIZE;
8500 case dw_val_class_lbl_id:
8501 size += DWARF2_ADDR_SIZE;
8503 case dw_val_class_lineptr:
8504 case dw_val_class_macptr:
8505 size += DWARF_OFFSET_SIZE;
8507 case dw_val_class_str:
8508 if (AT_string_form (a) == DW_FORM_strp)
8509 size += DWARF_OFFSET_SIZE;
8511 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8513 case dw_val_class_file:
8514 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8524 /* Size the debugging information associated with a given DIE. Visits the
8525 DIE's children recursively. Updates the global variable next_die_offset, on
8526 each time through. Uses the current value of next_die_offset to update the
8527 die_offset field in each DIE. */
8530 calc_die_sizes (dw_die_ref die)
8534 die->die_offset = next_die_offset;
8535 next_die_offset += size_of_die (die);
8537 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8539 if (die->die_child != NULL)
8540 /* Count the null byte used to terminate sibling lists. */
8541 next_die_offset += 1;
8544 /* Set the marks for a die and its children. We do this so
8545 that we know whether or not a reference needs to use FORM_ref_addr; only
8546 DIEs in the same CU will be marked. We used to clear out the offset
8547 and use that as the flag, but ran into ordering problems. */
8550 mark_dies (dw_die_ref die)
8554 gcc_assert (!die->die_mark);
8557 FOR_EACH_CHILD (die, c, mark_dies (c));
8560 /* Clear the marks for a die and its children. */
8563 unmark_dies (dw_die_ref die)
8567 gcc_assert (die->die_mark);
8570 FOR_EACH_CHILD (die, c, unmark_dies (c));
8573 /* Clear the marks for a die, its children and referred dies. */
8576 unmark_all_dies (dw_die_ref die)
8586 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8588 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8589 if (AT_class (a) == dw_val_class_die_ref)
8590 unmark_all_dies (AT_ref (a));
8593 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8594 generated for the compilation unit. */
8596 static unsigned long
8597 size_of_pubnames (VEC (pubname_entry, gc) * names)
8603 size = DWARF_PUBNAMES_HEADER_SIZE;
8604 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8605 if (names != pubtype_table
8606 || p->die->die_offset != 0
8607 || !flag_eliminate_unused_debug_types)
8608 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8610 size += DWARF_OFFSET_SIZE;
8614 /* Return the size of the information in the .debug_aranges section. */
8616 static unsigned long
8617 size_of_aranges (void)
8621 size = DWARF_ARANGES_HEADER_SIZE;
8623 /* Count the address/length pair for this compilation unit. */
8624 if (text_section_used)
8625 size += 2 * DWARF2_ADDR_SIZE;
8626 if (cold_text_section_used)
8627 size += 2 * DWARF2_ADDR_SIZE;
8628 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8630 /* Count the two zero words used to terminated the address range table. */
8631 size += 2 * DWARF2_ADDR_SIZE;
8635 /* Select the encoding of an attribute value. */
8637 static enum dwarf_form
8638 value_format (dw_attr_ref a)
8640 switch (a->dw_attr_val.val_class)
8642 case dw_val_class_addr:
8643 return DW_FORM_addr;
8644 case dw_val_class_range_list:
8645 case dw_val_class_offset:
8646 case dw_val_class_loc_list:
8647 switch (DWARF_OFFSET_SIZE)
8650 return DW_FORM_data4;
8652 return DW_FORM_data8;
8656 case dw_val_class_loc:
8657 switch (constant_size (size_of_locs (AT_loc (a))))
8660 return DW_FORM_block1;
8662 return DW_FORM_block2;
8666 case dw_val_class_const:
8667 return DW_FORM_sdata;
8668 case dw_val_class_unsigned_const:
8669 switch (constant_size (AT_unsigned (a)))
8672 return DW_FORM_data1;
8674 return DW_FORM_data2;
8676 return DW_FORM_data4;
8678 return DW_FORM_data8;
8682 case dw_val_class_long_long:
8683 return DW_FORM_block1;
8684 case dw_val_class_vec:
8685 switch (constant_size (a->dw_attr_val.v.val_vec.length
8686 * a->dw_attr_val.v.val_vec.elt_size))
8689 return DW_FORM_block1;
8691 return DW_FORM_block2;
8693 return DW_FORM_block4;
8697 case dw_val_class_flag:
8698 return DW_FORM_flag;
8699 case dw_val_class_die_ref:
8700 if (AT_ref_external (a))
8701 return DW_FORM_ref_addr;
8704 case dw_val_class_fde_ref:
8705 return DW_FORM_data;
8706 case dw_val_class_lbl_id:
8707 return DW_FORM_addr;
8708 case dw_val_class_lineptr:
8709 case dw_val_class_macptr:
8710 return DW_FORM_data;
8711 case dw_val_class_str:
8712 return AT_string_form (a);
8713 case dw_val_class_file:
8714 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8717 return DW_FORM_data1;
8719 return DW_FORM_data2;
8721 return DW_FORM_data4;
8731 /* Output the encoding of an attribute value. */
8734 output_value_format (dw_attr_ref a)
8736 enum dwarf_form form = value_format (a);
8738 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8741 /* Output the .debug_abbrev section which defines the DIE abbreviation
8745 output_abbrev_section (void)
8747 unsigned long abbrev_id;
8749 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8751 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8755 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8756 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8757 dwarf_tag_name (abbrev->die_tag));
8759 if (abbrev->die_child != NULL)
8760 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8762 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8764 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8767 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8768 dwarf_attr_name (a_attr->dw_attr));
8769 output_value_format (a_attr);
8772 dw2_asm_output_data (1, 0, NULL);
8773 dw2_asm_output_data (1, 0, NULL);
8776 /* Terminate the table. */
8777 dw2_asm_output_data (1, 0, NULL);
8780 /* Output a symbol we can use to refer to this DIE from another CU. */
8783 output_die_symbol (dw_die_ref die)
8785 char *sym = die->die_symbol;
8790 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8791 /* We make these global, not weak; if the target doesn't support
8792 .linkonce, it doesn't support combining the sections, so debugging
8794 targetm.asm_out.globalize_label (asm_out_file, sym);
8796 ASM_OUTPUT_LABEL (asm_out_file, sym);
8799 /* Return a new location list, given the begin and end range, and the
8800 expression. gensym tells us whether to generate a new internal symbol for
8801 this location list node, which is done for the head of the list only. */
8803 static inline dw_loc_list_ref
8804 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8805 const char *section, unsigned int gensym)
8807 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8809 retlist->begin = begin;
8811 retlist->expr = expr;
8812 retlist->section = section;
8814 retlist->ll_symbol = gen_internal_sym ("LLST");
8819 /* Add a location description expression to a location list. */
8822 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8823 const char *begin, const char *end,
8824 const char *section)
8828 /* Find the end of the chain. */
8829 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8832 /* Add a new location list node to the list. */
8833 *d = new_loc_list (descr, begin, end, section, 0);
8836 /* Output the location list given to us. */
8839 output_loc_list (dw_loc_list_ref list_head)
8841 dw_loc_list_ref curr = list_head;
8843 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8845 /* Walk the location list, and output each range + expression. */
8846 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8849 /* Don't output an entry that starts and ends at the same address. */
8850 if (strcmp (curr->begin, curr->end) == 0)
8852 if (!have_multiple_function_sections)
8854 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8855 "Location list begin address (%s)",
8856 list_head->ll_symbol);
8857 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8858 "Location list end address (%s)",
8859 list_head->ll_symbol);
8863 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8864 "Location list begin address (%s)",
8865 list_head->ll_symbol);
8866 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8867 "Location list end address (%s)",
8868 list_head->ll_symbol);
8870 size = size_of_locs (curr->expr);
8872 /* Output the block length for this list of location operations. */
8873 gcc_assert (size <= 0xffff);
8874 dw2_asm_output_data (2, size, "%s", "Location expression size");
8876 output_loc_sequence (curr->expr);
8879 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8880 "Location list terminator begin (%s)",
8881 list_head->ll_symbol);
8882 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8883 "Location list terminator end (%s)",
8884 list_head->ll_symbol);
8887 /* Output the DIE and its attributes. Called recursively to generate
8888 the definitions of each child DIE. */
8891 output_die (dw_die_ref die)
8898 /* If someone in another CU might refer to us, set up a symbol for
8899 them to point to. */
8900 if (die->die_symbol)
8901 output_die_symbol (die);
8903 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8904 (unsigned long)die->die_offset,
8905 dwarf_tag_name (die->die_tag));
8907 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8909 const char *name = dwarf_attr_name (a->dw_attr);
8911 switch (AT_class (a))
8913 case dw_val_class_addr:
8914 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8917 case dw_val_class_offset:
8918 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8922 case dw_val_class_range_list:
8924 char *p = strchr (ranges_section_label, '\0');
8926 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8927 a->dw_attr_val.v.val_offset);
8928 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8929 debug_ranges_section, "%s", name);
8934 case dw_val_class_loc:
8935 size = size_of_locs (AT_loc (a));
8937 /* Output the block length for this list of location operations. */
8938 dw2_asm_output_data (constant_size (size), size, "%s", name);
8940 output_loc_sequence (AT_loc (a));
8943 case dw_val_class_const:
8944 /* ??? It would be slightly more efficient to use a scheme like is
8945 used for unsigned constants below, but gdb 4.x does not sign
8946 extend. Gdb 5.x does sign extend. */
8947 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8950 case dw_val_class_unsigned_const:
8951 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8952 AT_unsigned (a), "%s", name);
8955 case dw_val_class_long_long:
8957 unsigned HOST_WIDE_INT first, second;
8959 dw2_asm_output_data (1,
8960 2 * HOST_BITS_PER_WIDE_INT
8961 / HOST_BITS_PER_CHAR,
8964 if (WORDS_BIG_ENDIAN)
8966 first = CONST_DOUBLE_HIGH (a->dw_attr_val.v.val_long_long);
8967 second = CONST_DOUBLE_LOW (a->dw_attr_val.v.val_long_long);
8971 first = CONST_DOUBLE_LOW (a->dw_attr_val.v.val_long_long);
8972 second = CONST_DOUBLE_HIGH (a->dw_attr_val.v.val_long_long);
8975 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8976 first, "long long constant");
8977 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8982 case dw_val_class_vec:
8984 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8985 unsigned int len = a->dw_attr_val.v.val_vec.length;
8989 dw2_asm_output_data (constant_size (len * elt_size),
8990 len * elt_size, "%s", name);
8991 if (elt_size > sizeof (HOST_WIDE_INT))
8996 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8999 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
9000 "fp or vector constant word %u", i);
9004 case dw_val_class_flag:
9005 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9008 case dw_val_class_loc_list:
9010 char *sym = AT_loc_list (a)->ll_symbol;
9013 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
9018 case dw_val_class_die_ref:
9019 if (AT_ref_external (a))
9021 char *sym = AT_ref (a)->die_symbol;
9026 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9027 length, whereas in DWARF3 it's always sized as an offset. */
9028 if (dwarf_version == 2)
9029 size = DWARF2_ADDR_SIZE;
9031 size = DWARF_OFFSET_SIZE;
9032 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
9036 gcc_assert (AT_ref (a)->die_offset);
9037 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9042 case dw_val_class_fde_ref:
9046 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9047 a->dw_attr_val.v.val_fde_index * 2);
9048 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9053 case dw_val_class_lbl_id:
9054 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
9057 case dw_val_class_lineptr:
9058 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9059 debug_line_section, "%s", name);
9062 case dw_val_class_macptr:
9063 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9064 debug_macinfo_section, "%s", name);
9067 case dw_val_class_str:
9068 if (AT_string_form (a) == DW_FORM_strp)
9069 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9070 a->dw_attr_val.v.val_str->label,
9072 "%s: \"%s\"", name, AT_string (a));
9074 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9077 case dw_val_class_file:
9079 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9081 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9082 a->dw_attr_val.v.val_file->filename);
9091 FOR_EACH_CHILD (die, c, output_die (c));
9093 /* Add null byte to terminate sibling list. */
9094 if (die->die_child != NULL)
9095 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
9096 (unsigned long) die->die_offset);
9099 /* Output the compilation unit that appears at the beginning of the
9100 .debug_info section, and precedes the DIE descriptions. */
9103 output_compilation_unit_header (void)
9105 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9106 dw2_asm_output_data (4, 0xffffffff,
9107 "Initial length escape value indicating 64-bit DWARF extension");
9108 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9109 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9110 "Length of Compilation Unit Info");
9111 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
9112 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9113 debug_abbrev_section,
9114 "Offset Into Abbrev. Section");
9115 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9118 /* Output the compilation unit DIE and its children. */
9121 output_comp_unit (dw_die_ref die, int output_if_empty)
9123 const char *secname;
9126 /* Unless we are outputting main CU, we may throw away empty ones. */
9127 if (!output_if_empty && die->die_child == NULL)
9130 /* Even if there are no children of this DIE, we must output the information
9131 about the compilation unit. Otherwise, on an empty translation unit, we
9132 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9133 will then complain when examining the file. First mark all the DIEs in
9134 this CU so we know which get local refs. */
9137 build_abbrev_table (die);
9139 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9140 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9141 calc_die_sizes (die);
9143 oldsym = die->die_symbol;
9146 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9148 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9150 die->die_symbol = NULL;
9151 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9154 switch_to_section (debug_info_section);
9156 /* Output debugging information. */
9157 output_compilation_unit_header ();
9160 /* Leave the marks on the main CU, so we can check them in
9165 die->die_symbol = oldsym;
9169 /* Return the DWARF2/3 pubname associated with a decl. */
9172 dwarf2_name (tree decl, int scope)
9174 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9177 /* Add a new entry to .debug_pubnames if appropriate. */
9180 add_pubname_string (const char *str, dw_die_ref die)
9185 e.name = xstrdup (str);
9186 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9190 add_pubname (tree decl, dw_die_ref die)
9192 if (TREE_PUBLIC (decl))
9193 add_pubname_string (dwarf2_name (decl, 1), die);
9196 /* Add a new entry to .debug_pubtypes if appropriate. */
9199 add_pubtype (tree decl, dw_die_ref die)
9204 if ((TREE_PUBLIC (decl)
9205 || die->die_parent == comp_unit_die)
9206 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9211 if (TYPE_NAME (decl))
9213 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9214 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9215 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9216 && DECL_NAME (TYPE_NAME (decl)))
9217 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9219 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9223 e.name = xstrdup (dwarf2_name (decl, 1));
9225 /* If we don't have a name for the type, there's no point in adding
9227 if (e.name && e.name[0] != '\0')
9228 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9232 /* Output the public names table used to speed up access to externally
9233 visible names; or the public types table used to find type definitions. */
9236 output_pubnames (VEC (pubname_entry, gc) * names)
9239 unsigned long pubnames_length = size_of_pubnames (names);
9242 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9243 dw2_asm_output_data (4, 0xffffffff,
9244 "Initial length escape value indicating 64-bit DWARF extension");
9245 if (names == pubname_table)
9246 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9247 "Length of Public Names Info");
9249 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9250 "Length of Public Type Names Info");
9251 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9252 dw2_asm_output_data (2, 2, "DWARF Version");
9253 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9255 "Offset of Compilation Unit Info");
9256 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9257 "Compilation Unit Length");
9259 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
9261 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9262 if (names == pubname_table)
9263 gcc_assert (pub->die->die_mark);
9265 if (names != pubtype_table
9266 || pub->die->die_offset != 0
9267 || !flag_eliminate_unused_debug_types)
9269 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9272 dw2_asm_output_nstring (pub->name, -1, "external name");
9276 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9279 /* Add a new entry to .debug_aranges if appropriate. */
9282 add_arange (tree decl, dw_die_ref die)
9284 if (! DECL_SECTION_NAME (decl))
9287 if (arange_table_in_use == arange_table_allocated)
9289 arange_table_allocated += ARANGE_TABLE_INCREMENT;
9290 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
9291 arange_table_allocated);
9292 memset (arange_table + arange_table_in_use, 0,
9293 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
9296 arange_table[arange_table_in_use++] = die;
9299 /* Output the information that goes into the .debug_aranges table.
9300 Namely, define the beginning and ending address range of the
9301 text section generated for this compilation unit. */
9304 output_aranges (void)
9307 unsigned long aranges_length = size_of_aranges ();
9309 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9310 dw2_asm_output_data (4, 0xffffffff,
9311 "Initial length escape value indicating 64-bit DWARF extension");
9312 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9313 "Length of Address Ranges Info");
9314 /* Version number for aranges is still 2, even in DWARF3. */
9315 dw2_asm_output_data (2, 2, "DWARF Version");
9316 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9318 "Offset of Compilation Unit Info");
9319 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9320 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9322 /* We need to align to twice the pointer size here. */
9323 if (DWARF_ARANGES_PAD_SIZE)
9325 /* Pad using a 2 byte words so that padding is correct for any
9327 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9328 2 * DWARF2_ADDR_SIZE);
9329 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9330 dw2_asm_output_data (2, 0, NULL);
9333 /* It is necessary not to output these entries if the sections were
9334 not used; if the sections were not used, the length will be 0 and
9335 the address may end up as 0 if the section is discarded by ld
9336 --gc-sections, leaving an invalid (0, 0) entry that can be
9337 confused with the terminator. */
9338 if (text_section_used)
9340 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9341 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9342 text_section_label, "Length");
9344 if (cold_text_section_used)
9346 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9348 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9349 cold_text_section_label, "Length");
9352 for (i = 0; i < arange_table_in_use; i++)
9354 dw_die_ref die = arange_table[i];
9356 /* We shouldn't see aranges for DIEs outside of the main CU. */
9357 gcc_assert (die->die_mark);
9359 if (die->die_tag == DW_TAG_subprogram)
9361 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
9363 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
9364 get_AT_low_pc (die), "Length");
9368 /* A static variable; extract the symbol from DW_AT_location.
9369 Note that this code isn't currently hit, as we only emit
9370 aranges for functions (jason 9/23/99). */
9371 dw_attr_ref a = get_AT (die, DW_AT_location);
9372 dw_loc_descr_ref loc;
9374 gcc_assert (a && AT_class (a) == dw_val_class_loc);
9377 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
9379 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
9380 loc->dw_loc_oprnd1.v.val_addr, "Address");
9381 dw2_asm_output_data (DWARF2_ADDR_SIZE,
9382 get_AT_unsigned (die, DW_AT_byte_size),
9387 /* Output the terminator words. */
9388 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9389 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9392 /* Add a new entry to .debug_ranges. Return the offset at which it
9396 add_ranges_num (int num)
9398 unsigned int in_use = ranges_table_in_use;
9400 if (in_use == ranges_table_allocated)
9402 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9403 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9404 ranges_table_allocated);
9405 memset (ranges_table + ranges_table_in_use, 0,
9406 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9409 ranges_table[in_use].num = num;
9410 ranges_table_in_use = in_use + 1;
9412 return in_use * 2 * DWARF2_ADDR_SIZE;
9415 /* Add a new entry to .debug_ranges corresponding to a block, or a
9416 range terminator if BLOCK is NULL. */
9419 add_ranges (const_tree block)
9421 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9424 /* Add a new entry to .debug_ranges corresponding to a pair of
9428 add_ranges_by_labels (const char *begin, const char *end)
9430 unsigned int in_use = ranges_by_label_in_use;
9432 if (in_use == ranges_by_label_allocated)
9434 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9435 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9437 ranges_by_label_allocated);
9438 memset (ranges_by_label + ranges_by_label_in_use, 0,
9439 RANGES_TABLE_INCREMENT
9440 * sizeof (struct dw_ranges_by_label_struct));
9443 ranges_by_label[in_use].begin = begin;
9444 ranges_by_label[in_use].end = end;
9445 ranges_by_label_in_use = in_use + 1;
9447 return add_ranges_num (-(int)in_use - 1);
9451 output_ranges (void)
9454 static const char *const start_fmt = "Offset 0x%x";
9455 const char *fmt = start_fmt;
9457 for (i = 0; i < ranges_table_in_use; i++)
9459 int block_num = ranges_table[i].num;
9463 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9464 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9466 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9467 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9469 /* If all code is in the text section, then the compilation
9470 unit base address defaults to DW_AT_low_pc, which is the
9471 base of the text section. */
9472 if (!have_multiple_function_sections)
9474 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9476 fmt, i * 2 * DWARF2_ADDR_SIZE);
9477 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9478 text_section_label, NULL);
9481 /* Otherwise, the compilation unit base address is zero,
9482 which allows us to use absolute addresses, and not worry
9483 about whether the target supports cross-section
9487 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9488 fmt, i * 2 * DWARF2_ADDR_SIZE);
9489 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9495 /* Negative block_num stands for an index into ranges_by_label. */
9496 else if (block_num < 0)
9498 int lab_idx = - block_num - 1;
9500 if (!have_multiple_function_sections)
9504 /* If we ever use add_ranges_by_labels () for a single
9505 function section, all we have to do is to take out
9507 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9508 ranges_by_label[lab_idx].begin,
9510 fmt, i * 2 * DWARF2_ADDR_SIZE);
9511 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9512 ranges_by_label[lab_idx].end,
9513 text_section_label, NULL);
9518 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9519 ranges_by_label[lab_idx].begin,
9520 fmt, i * 2 * DWARF2_ADDR_SIZE);
9521 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9522 ranges_by_label[lab_idx].end,
9528 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9529 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9535 /* Data structure containing information about input files. */
9538 const char *path; /* Complete file name. */
9539 const char *fname; /* File name part. */
9540 int length; /* Length of entire string. */
9541 struct dwarf_file_data * file_idx; /* Index in input file table. */
9542 int dir_idx; /* Index in directory table. */
9545 /* Data structure containing information about directories with source
9549 const char *path; /* Path including directory name. */
9550 int length; /* Path length. */
9551 int prefix; /* Index of directory entry which is a prefix. */
9552 int count; /* Number of files in this directory. */
9553 int dir_idx; /* Index of directory used as base. */
9556 /* Callback function for file_info comparison. We sort by looking at
9557 the directories in the path. */
9560 file_info_cmp (const void *p1, const void *p2)
9562 const struct file_info *const s1 = (const struct file_info *) p1;
9563 const struct file_info *const s2 = (const struct file_info *) p2;
9564 const unsigned char *cp1;
9565 const unsigned char *cp2;
9567 /* Take care of file names without directories. We need to make sure that
9568 we return consistent values to qsort since some will get confused if
9569 we return the same value when identical operands are passed in opposite
9570 orders. So if neither has a directory, return 0 and otherwise return
9571 1 or -1 depending on which one has the directory. */
9572 if ((s1->path == s1->fname || s2->path == s2->fname))
9573 return (s2->path == s2->fname) - (s1->path == s1->fname);
9575 cp1 = (const unsigned char *) s1->path;
9576 cp2 = (const unsigned char *) s2->path;
9582 /* Reached the end of the first path? If so, handle like above. */
9583 if ((cp1 == (const unsigned char *) s1->fname)
9584 || (cp2 == (const unsigned char *) s2->fname))
9585 return ((cp2 == (const unsigned char *) s2->fname)
9586 - (cp1 == (const unsigned char *) s1->fname));
9588 /* Character of current path component the same? */
9589 else if (*cp1 != *cp2)
9594 struct file_name_acquire_data
9596 struct file_info *files;
9601 /* Traversal function for the hash table. */
9604 file_name_acquire (void ** slot, void *data)
9606 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9607 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9608 struct file_info *fi;
9611 gcc_assert (fnad->max_files >= d->emitted_number);
9613 if (! d->emitted_number)
9616 gcc_assert (fnad->max_files != fnad->used_files);
9618 fi = fnad->files + fnad->used_files++;
9620 /* Skip all leading "./". */
9622 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9625 /* Create a new array entry. */
9627 fi->length = strlen (f);
9630 /* Search for the file name part. */
9631 f = strrchr (f, DIR_SEPARATOR);
9632 #if defined (DIR_SEPARATOR_2)
9634 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9638 if (f == NULL || f < g)
9644 fi->fname = f == NULL ? fi->path : f + 1;
9648 /* Output the directory table and the file name table. We try to minimize
9649 the total amount of memory needed. A heuristic is used to avoid large
9650 slowdowns with many input files. */
9653 output_file_names (void)
9655 struct file_name_acquire_data fnad;
9657 struct file_info *files;
9658 struct dir_info *dirs;
9667 if (!last_emitted_file)
9669 dw2_asm_output_data (1, 0, "End directory table");
9670 dw2_asm_output_data (1, 0, "End file name table");
9674 numfiles = last_emitted_file->emitted_number;
9676 /* Allocate the various arrays we need. */
9677 files = XALLOCAVEC (struct file_info, numfiles);
9678 dirs = XALLOCAVEC (struct dir_info, numfiles);
9681 fnad.used_files = 0;
9682 fnad.max_files = numfiles;
9683 htab_traverse (file_table, file_name_acquire, &fnad);
9684 gcc_assert (fnad.used_files == fnad.max_files);
9686 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9688 /* Find all the different directories used. */
9689 dirs[0].path = files[0].path;
9690 dirs[0].length = files[0].fname - files[0].path;
9691 dirs[0].prefix = -1;
9693 dirs[0].dir_idx = 0;
9694 files[0].dir_idx = 0;
9697 for (i = 1; i < numfiles; i++)
9698 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9699 && memcmp (dirs[ndirs - 1].path, files[i].path,
9700 dirs[ndirs - 1].length) == 0)
9702 /* Same directory as last entry. */
9703 files[i].dir_idx = ndirs - 1;
9704 ++dirs[ndirs - 1].count;
9710 /* This is a new directory. */
9711 dirs[ndirs].path = files[i].path;
9712 dirs[ndirs].length = files[i].fname - files[i].path;
9713 dirs[ndirs].count = 1;
9714 dirs[ndirs].dir_idx = ndirs;
9715 files[i].dir_idx = ndirs;
9717 /* Search for a prefix. */
9718 dirs[ndirs].prefix = -1;
9719 for (j = 0; j < ndirs; j++)
9720 if (dirs[j].length < dirs[ndirs].length
9721 && dirs[j].length > 1
9722 && (dirs[ndirs].prefix == -1
9723 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9724 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9725 dirs[ndirs].prefix = j;
9730 /* Now to the actual work. We have to find a subset of the directories which
9731 allow expressing the file name using references to the directory table
9732 with the least amount of characters. We do not do an exhaustive search
9733 where we would have to check out every combination of every single
9734 possible prefix. Instead we use a heuristic which provides nearly optimal
9735 results in most cases and never is much off. */
9736 saved = XALLOCAVEC (int, ndirs);
9737 savehere = XALLOCAVEC (int, ndirs);
9739 memset (saved, '\0', ndirs * sizeof (saved[0]));
9740 for (i = 0; i < ndirs; i++)
9745 /* We can always save some space for the current directory. But this
9746 does not mean it will be enough to justify adding the directory. */
9747 savehere[i] = dirs[i].length;
9748 total = (savehere[i] - saved[i]) * dirs[i].count;
9750 for (j = i + 1; j < ndirs; j++)
9753 if (saved[j] < dirs[i].length)
9755 /* Determine whether the dirs[i] path is a prefix of the
9760 while (k != -1 && k != (int) i)
9765 /* Yes it is. We can possibly save some memory by
9766 writing the filenames in dirs[j] relative to
9768 savehere[j] = dirs[i].length;
9769 total += (savehere[j] - saved[j]) * dirs[j].count;
9774 /* Check whether we can save enough to justify adding the dirs[i]
9776 if (total > dirs[i].length + 1)
9778 /* It's worthwhile adding. */
9779 for (j = i; j < ndirs; j++)
9780 if (savehere[j] > 0)
9782 /* Remember how much we saved for this directory so far. */
9783 saved[j] = savehere[j];
9785 /* Remember the prefix directory. */
9786 dirs[j].dir_idx = i;
9791 /* Emit the directory name table. */
9793 idx_offset = dirs[0].length > 0 ? 1 : 0;
9794 for (i = 1 - idx_offset; i < ndirs; i++)
9795 dw2_asm_output_nstring (dirs[i].path,
9797 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9798 "Directory Entry: 0x%x", i + idx_offset);
9800 dw2_asm_output_data (1, 0, "End directory table");
9802 /* We have to emit them in the order of emitted_number since that's
9803 used in the debug info generation. To do this efficiently we
9804 generate a back-mapping of the indices first. */
9805 backmap = XALLOCAVEC (int, numfiles);
9806 for (i = 0; i < numfiles; i++)
9807 backmap[files[i].file_idx->emitted_number - 1] = i;
9809 /* Now write all the file names. */
9810 for (i = 0; i < numfiles; i++)
9812 int file_idx = backmap[i];
9813 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9815 #ifdef VMS_DEBUGGING_INFO
9816 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9818 /* Setting these fields can lead to debugger miscomparisons,
9819 but VMS Debug requires them to be set correctly. */
9824 int maxfilelen = strlen (files[file_idx].path)
9825 + dirs[dir_idx].length
9826 + MAX_VMS_VERSION_LEN + 1;
9827 char *filebuf = XALLOCAVEC (char, maxfilelen);
9829 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9830 snprintf (filebuf, maxfilelen, "%s;%d",
9831 files[file_idx].path + dirs[dir_idx].length, ver);
9833 dw2_asm_output_nstring
9834 (filebuf, -1, "File Entry: 0x%x", (unsigned) i + 1);
9836 /* Include directory index. */
9837 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9839 /* Modification time. */
9840 dw2_asm_output_data_uleb128
9841 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9845 /* File length in bytes. */
9846 dw2_asm_output_data_uleb128
9847 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9851 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9852 "File Entry: 0x%x", (unsigned) i + 1);
9854 /* Include directory index. */
9855 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9857 /* Modification time. */
9858 dw2_asm_output_data_uleb128 (0, NULL);
9860 /* File length in bytes. */
9861 dw2_asm_output_data_uleb128 (0, NULL);
9865 dw2_asm_output_data (1, 0, "End file name table");
9869 /* Output the source line number correspondence information. This
9870 information goes into the .debug_line section. */
9873 output_line_info (void)
9875 char l1[20], l2[20], p1[20], p2[20];
9876 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9877 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9880 unsigned long lt_index;
9881 unsigned long current_line;
9884 unsigned long current_file;
9885 unsigned long function;
9887 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9888 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9889 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9890 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9892 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9893 dw2_asm_output_data (4, 0xffffffff,
9894 "Initial length escape value indicating 64-bit DWARF extension");
9895 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9896 "Length of Source Line Info");
9897 ASM_OUTPUT_LABEL (asm_out_file, l1);
9899 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9900 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9901 ASM_OUTPUT_LABEL (asm_out_file, p1);
9903 /* Define the architecture-dependent minimum instruction length (in
9904 bytes). In this implementation of DWARF, this field is used for
9905 information purposes only. Since GCC generates assembly language,
9906 we have no a priori knowledge of how many instruction bytes are
9907 generated for each source line, and therefore can use only the
9908 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9909 commands. Accordingly, we fix this as `1', which is "correct
9910 enough" for all architectures, and don't let the target override. */
9911 dw2_asm_output_data (1, 1,
9912 "Minimum Instruction Length");
9914 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9915 "Default is_stmt_start flag");
9916 dw2_asm_output_data (1, DWARF_LINE_BASE,
9917 "Line Base Value (Special Opcodes)");
9918 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9919 "Line Range Value (Special Opcodes)");
9920 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9921 "Special Opcode Base");
9923 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9927 case DW_LNS_advance_pc:
9928 case DW_LNS_advance_line:
9929 case DW_LNS_set_file:
9930 case DW_LNS_set_column:
9931 case DW_LNS_fixed_advance_pc:
9939 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9943 /* Write out the information about the files we use. */
9944 output_file_names ();
9945 ASM_OUTPUT_LABEL (asm_out_file, p2);
9947 /* We used to set the address register to the first location in the text
9948 section here, but that didn't accomplish anything since we already
9949 have a line note for the opening brace of the first function. */
9951 /* Generate the line number to PC correspondence table, encoded as
9952 a series of state machine operations. */
9956 if (cfun && in_cold_section_p)
9957 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9959 strcpy (prev_line_label, text_section_label);
9960 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9962 dw_line_info_ref line_info = &line_info_table[lt_index];
9965 /* Disable this optimization for now; GDB wants to see two line notes
9966 at the beginning of a function so it can find the end of the
9969 /* Don't emit anything for redundant notes. Just updating the
9970 address doesn't accomplish anything, because we already assume
9971 that anything after the last address is this line. */
9972 if (line_info->dw_line_num == current_line
9973 && line_info->dw_file_num == current_file)
9977 /* Emit debug info for the address of the current line.
9979 Unfortunately, we have little choice here currently, and must always
9980 use the most general form. GCC does not know the address delta
9981 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9982 attributes which will give an upper bound on the address range. We
9983 could perhaps use length attributes to determine when it is safe to
9984 use DW_LNS_fixed_advance_pc. */
9986 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9989 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9990 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9991 "DW_LNS_fixed_advance_pc");
9992 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9996 /* This can handle any delta. This takes
9997 4+DWARF2_ADDR_SIZE bytes. */
9998 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9999 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10000 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10001 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10004 strcpy (prev_line_label, line_label);
10006 /* Emit debug info for the source file of the current line, if
10007 different from the previous line. */
10008 if (line_info->dw_file_num != current_file)
10010 current_file = line_info->dw_file_num;
10011 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10012 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10015 /* Emit debug info for the current line number, choosing the encoding
10016 that uses the least amount of space. */
10017 if (line_info->dw_line_num != current_line)
10019 line_offset = line_info->dw_line_num - current_line;
10020 line_delta = line_offset - DWARF_LINE_BASE;
10021 current_line = line_info->dw_line_num;
10022 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10023 /* This can handle deltas from -10 to 234, using the current
10024 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
10026 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10027 "line %lu", current_line);
10030 /* This can handle any delta. This takes at least 4 bytes,
10031 depending on the value being encoded. */
10032 dw2_asm_output_data (1, DW_LNS_advance_line,
10033 "advance to line %lu", current_line);
10034 dw2_asm_output_data_sleb128 (line_offset, NULL);
10035 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10039 /* We still need to start a new row, so output a copy insn. */
10040 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10043 /* Emit debug info for the address of the end of the function. */
10046 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10047 "DW_LNS_fixed_advance_pc");
10048 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
10052 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10053 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10054 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10055 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
10058 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10059 dw2_asm_output_data_uleb128 (1, NULL);
10060 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10065 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
10067 dw_separate_line_info_ref line_info
10068 = &separate_line_info_table[lt_index];
10071 /* Don't emit anything for redundant notes. */
10072 if (line_info->dw_line_num == current_line
10073 && line_info->dw_file_num == current_file
10074 && line_info->function == function)
10078 /* Emit debug info for the address of the current line. If this is
10079 a new function, or the first line of a function, then we need
10080 to handle it differently. */
10081 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
10083 if (function != line_info->function)
10085 function = line_info->function;
10087 /* Set the address register to the first line in the function. */
10088 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10089 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10090 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10091 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10095 /* ??? See the DW_LNS_advance_pc comment above. */
10098 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10099 "DW_LNS_fixed_advance_pc");
10100 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10104 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10105 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10106 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10107 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10111 strcpy (prev_line_label, line_label);
10113 /* Emit debug info for the source file of the current line, if
10114 different from the previous line. */
10115 if (line_info->dw_file_num != current_file)
10117 current_file = line_info->dw_file_num;
10118 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10119 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10122 /* Emit debug info for the current line number, choosing the encoding
10123 that uses the least amount of space. */
10124 if (line_info->dw_line_num != current_line)
10126 line_offset = line_info->dw_line_num - current_line;
10127 line_delta = line_offset - DWARF_LINE_BASE;
10128 current_line = line_info->dw_line_num;
10129 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10130 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10131 "line %lu", current_line);
10134 dw2_asm_output_data (1, DW_LNS_advance_line,
10135 "advance to line %lu", current_line);
10136 dw2_asm_output_data_sleb128 (line_offset, NULL);
10137 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10141 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10149 /* If we're done with a function, end its sequence. */
10150 if (lt_index == separate_line_info_table_in_use
10151 || separate_line_info_table[lt_index].function != function)
10156 /* Emit debug info for the address of the end of the function. */
10157 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
10160 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10161 "DW_LNS_fixed_advance_pc");
10162 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10166 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10167 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10168 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10169 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10172 /* Output the marker for the end of this sequence. */
10173 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10174 dw2_asm_output_data_uleb128 (1, NULL);
10175 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10179 /* Output the marker for the end of the line number info. */
10180 ASM_OUTPUT_LABEL (asm_out_file, l2);
10183 /* Given a pointer to a tree node for some base type, return a pointer to
10184 a DIE that describes the given type.
10186 This routine must only be called for GCC type nodes that correspond to
10187 Dwarf base (fundamental) types. */
10190 base_type_die (tree type)
10192 dw_die_ref base_type_result;
10193 enum dwarf_type encoding;
10195 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10198 /* If this is a subtype that should not be emitted as a subrange type,
10199 use the base type. See subrange_type_for_debug_p. */
10200 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10201 type = TREE_TYPE (type);
10203 switch (TREE_CODE (type))
10206 if (TYPE_STRING_FLAG (type))
10208 if (TYPE_UNSIGNED (type))
10209 encoding = DW_ATE_unsigned_char;
10211 encoding = DW_ATE_signed_char;
10213 else if (TYPE_UNSIGNED (type))
10214 encoding = DW_ATE_unsigned;
10216 encoding = DW_ATE_signed;
10220 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10221 encoding = DW_ATE_decimal_float;
10223 encoding = DW_ATE_float;
10226 case FIXED_POINT_TYPE:
10227 if (TYPE_UNSIGNED (type))
10228 encoding = DW_ATE_unsigned_fixed;
10230 encoding = DW_ATE_signed_fixed;
10233 /* Dwarf2 doesn't know anything about complex ints, so use
10234 a user defined type for it. */
10236 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10237 encoding = DW_ATE_complex_float;
10239 encoding = DW_ATE_lo_user;
10243 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10244 encoding = DW_ATE_boolean;
10248 /* No other TREE_CODEs are Dwarf fundamental types. */
10249 gcc_unreachable ();
10252 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
10254 /* This probably indicates a bug. */
10255 if (! TYPE_NAME (type))
10256 add_name_attribute (base_type_result, "__unknown__");
10258 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10259 int_size_in_bytes (type));
10260 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10262 return base_type_result;
10265 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10266 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10269 is_base_type (tree type)
10271 switch (TREE_CODE (type))
10277 case FIXED_POINT_TYPE:
10285 case QUAL_UNION_TYPE:
10286 case ENUMERAL_TYPE:
10287 case FUNCTION_TYPE:
10290 case REFERENCE_TYPE:
10297 gcc_unreachable ();
10303 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10304 node, return the size in bits for the type if it is a constant, or else
10305 return the alignment for the type if the type's size is not constant, or
10306 else return BITS_PER_WORD if the type actually turns out to be an
10307 ERROR_MARK node. */
10309 static inline unsigned HOST_WIDE_INT
10310 simple_type_size_in_bits (const_tree type)
10312 if (TREE_CODE (type) == ERROR_MARK)
10313 return BITS_PER_WORD;
10314 else if (TYPE_SIZE (type) == NULL_TREE)
10316 else if (host_integerp (TYPE_SIZE (type), 1))
10317 return tree_low_cst (TYPE_SIZE (type), 1);
10319 return TYPE_ALIGN (type);
10322 /* Given a pointer to a tree node for a subrange type, return a pointer
10323 to a DIE that describes the given type. */
10326 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10328 dw_die_ref subrange_die;
10329 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10331 if (context_die == NULL)
10332 context_die = comp_unit_die;
10334 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10336 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10338 /* The size of the subrange type and its base type do not match,
10339 so we need to generate a size attribute for the subrange type. */
10340 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10344 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10346 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10348 return subrange_die;
10351 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10352 entry that chains various modifiers in front of the given type. */
10355 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10356 dw_die_ref context_die)
10358 enum tree_code code = TREE_CODE (type);
10359 dw_die_ref mod_type_die;
10360 dw_die_ref sub_die = NULL;
10361 tree item_type = NULL;
10362 tree qualified_type;
10363 tree name, low, high;
10365 if (code == ERROR_MARK)
10368 /* See if we already have the appropriately qualified variant of
10371 = get_qualified_type (type,
10372 ((is_const_type ? TYPE_QUAL_CONST : 0)
10373 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10375 /* If we do, then we can just use its DIE, if it exists. */
10376 if (qualified_type)
10378 mod_type_die = lookup_type_die (qualified_type);
10380 return mod_type_die;
10383 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10385 /* Handle C typedef types. */
10386 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
10388 tree dtype = TREE_TYPE (name);
10390 if (qualified_type == dtype)
10392 /* For a named type, use the typedef. */
10393 gen_type_die (qualified_type, context_die);
10394 return lookup_type_die (qualified_type);
10396 else if (is_const_type < TYPE_READONLY (dtype)
10397 || is_volatile_type < TYPE_VOLATILE (dtype)
10398 || (is_const_type <= TYPE_READONLY (dtype)
10399 && is_volatile_type <= TYPE_VOLATILE (dtype)
10400 && DECL_ORIGINAL_TYPE (name) != type))
10401 /* cv-unqualified version of named type. Just use the unnamed
10402 type to which it refers. */
10403 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10404 is_const_type, is_volatile_type,
10406 /* Else cv-qualified version of named type; fall through. */
10411 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
10412 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10414 else if (is_volatile_type)
10416 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
10417 sub_die = modified_type_die (type, 0, 0, context_die);
10419 else if (code == POINTER_TYPE)
10421 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
10422 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10423 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10424 item_type = TREE_TYPE (type);
10426 else if (code == REFERENCE_TYPE)
10428 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
10429 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10430 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10431 item_type = TREE_TYPE (type);
10433 else if (code == INTEGER_TYPE
10434 && TREE_TYPE (type) != NULL_TREE
10435 && subrange_type_for_debug_p (type, &low, &high))
10437 mod_type_die = subrange_type_die (type, low, high, context_die);
10438 item_type = TREE_TYPE (type);
10440 else if (is_base_type (type))
10441 mod_type_die = base_type_die (type);
10444 gen_type_die (type, context_die);
10446 /* We have to get the type_main_variant here (and pass that to the
10447 `lookup_type_die' routine) because the ..._TYPE node we have
10448 might simply be a *copy* of some original type node (where the
10449 copy was created to help us keep track of typedef names) and
10450 that copy might have a different TYPE_UID from the original
10452 if (TREE_CODE (type) != VECTOR_TYPE)
10453 return lookup_type_die (type_main_variant (type));
10455 /* Vectors have the debugging information in the type,
10456 not the main variant. */
10457 return lookup_type_die (type);
10460 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10461 don't output a DW_TAG_typedef, since there isn't one in the
10462 user's program; just attach a DW_AT_name to the type. */
10464 && (TREE_CODE (name) != TYPE_DECL
10465 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
10467 if (TREE_CODE (name) == TYPE_DECL)
10468 /* Could just call add_name_and_src_coords_attributes here,
10469 but since this is a builtin type it doesn't have any
10470 useful source coordinates anyway. */
10471 name = DECL_NAME (name);
10472 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10475 if (qualified_type)
10476 equate_type_number_to_die (qualified_type, mod_type_die);
10479 /* We must do this after the equate_type_number_to_die call, in case
10480 this is a recursive type. This ensures that the modified_type_die
10481 recursion will terminate even if the type is recursive. Recursive
10482 types are possible in Ada. */
10483 sub_die = modified_type_die (item_type,
10484 TYPE_READONLY (item_type),
10485 TYPE_VOLATILE (item_type),
10488 if (sub_die != NULL)
10489 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10491 return mod_type_die;
10494 /* Generate a new name for the parameter pack name NAME (an
10495 IDENTIFIER_NODE) that incorporates its */
10498 make_ith_pack_parameter_name (tree name, int i)
10500 /* Munge the name to include the parameter index. */
10501 #define NUMBUF_LEN 128
10502 char numbuf[NUMBUF_LEN];
10506 snprintf (numbuf, NUMBUF_LEN, "%i", i);
10507 newname_len = IDENTIFIER_LENGTH (name)
10508 + strlen (numbuf) + 2;
10509 newname = (char*) alloca (newname_len);
10510 snprintf (newname, newname_len,
10511 "%s#%i", IDENTIFIER_POINTER (name), i);
10512 return get_identifier (newname);
10515 /* Generate DIEs for the generic parameters of T.
10516 T must be either a generic type or a generic function.
10517 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10520 gen_generic_params_dies (tree t)
10524 dw_die_ref die = NULL;
10526 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10530 die = lookup_type_die (t);
10531 else if (DECL_P (t))
10532 die = lookup_decl_die (t);
10536 parms = lang_hooks.get_innermost_generic_parms (t);
10538 /* T has no generic parameter. It means T is neither a generic type
10539 or function. End of story. */
10542 parms_num = TREE_VEC_LENGTH (parms);
10543 args = lang_hooks.get_innermost_generic_args (t);
10544 for (i = 0; i < parms_num; i++)
10548 parm = TREE_VEC_ELT (parms, i);
10549 arg = TREE_VEC_ELT (args, i);
10550 if (parm && TREE_VALUE (parm) && arg)
10553 lang_hooks.types.get_argument_pack_elems (arg);
10556 /* So ARG is an argument pack and the elements of that pack
10557 are stored in PACK_ELEMS. */
10560 len = TREE_VEC_LENGTH (pack_elems);
10561 for (i = 0; i < len; i++)
10562 generic_parameter_die (TREE_VALUE (parm),
10563 TREE_VEC_ELT (pack_elems, i),
10566 else /* Arg is not an argument pack. */
10567 generic_parameter_die (TREE_VALUE (parm),
10569 -1/* Not a param pack. */);
10574 /* Create and return a DIE for PARM which should be
10575 the representation of a generic type parameter.
10576 For instance, in the C++ front end, PARM would be a template parameter.
10577 ARG is the argument to PARM.
10578 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10580 PACK_ELEM_INDEX is >= 0 if PARM is a generic parameter pack, and if ARG
10581 is one of the unpacked elements of the parameter PACK. In that case,
10582 PACK_ELEM_INDEX is the index of ARG in the parameter pack. */
10585 generic_parameter_die (tree parm, tree arg, dw_die_ref parent_die,
10586 int pack_elem_index)
10588 dw_die_ref tmpl_die = NULL;
10589 const char *name = NULL;
10591 if (!parm || !DECL_NAME (parm) || !arg)
10594 /* We support non-type generic parameters and arguments,
10595 type generic parameters and arguments, as well as
10596 generic generic parameters (a.k.a. template template parameters in C++)
10598 if (TREE_CODE (parm) == PARM_DECL)
10599 /* PARM is a nontype generic parameter */
10600 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10601 else if (TREE_CODE (parm) == TYPE_DECL)
10602 /* PARM is a type generic parameter. */
10603 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10604 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10605 /* PARM is a generic generic parameter.
10606 Its DIE is a GNU extension. It shall have a
10607 DW_AT_name attribute to represent the name of the template template
10608 parameter, and a DW_AT_GNU_template_name attribute to represent the
10609 name of the template template argument. */
10610 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10613 gcc_unreachable ();
10619 if (pack_elem_index >= 0)
10621 /* PARM is an element of a parameter pack.
10622 Generate a name for it. */
10623 tree identifier = make_ith_pack_parameter_name (DECL_NAME (parm),
10626 name = IDENTIFIER_POINTER (identifier);
10629 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10632 add_AT_string (tmpl_die, DW_AT_name, name);
10634 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10636 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10637 TMPL_DIE should have a child DW_AT_type attribute that is set
10638 to the type of the argument to PARM, which is ARG.
10639 If PARM is a type generic parameter, TMPL_DIE should have a
10640 child DW_AT_type that is set to ARG. */
10641 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10642 add_type_attribute (tmpl_die, tmpl_type, 0,
10643 TREE_THIS_VOLATILE (tmpl_type),
10648 /* So TMPL_DIE is a DIE representing a
10649 a generic generic template parameter, a.k.a template template
10650 parameter in C++ and arg is a template. */
10652 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10653 to the name of the argument. */
10654 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10655 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10658 if (TREE_CODE (parm) == PARM_DECL)
10659 /* So PARM is a non-type generic parameter.
10660 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10661 attribute of TMPL_DIE which value represents the value
10663 We must be careful here:
10664 The value of ARG might reference some function decls.
10665 We might currently be emitting debug info for a generic
10666 type and types are emitted before function decls, we don't
10667 know if the function decls referenced by ARG will actually be
10668 emitted after cgraph computations.
10669 So must defer the generation of the DW_AT_const_value to
10670 after cgraph is ready. */
10671 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10677 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10678 an enumerated type. */
10681 type_is_enum (const_tree type)
10683 return TREE_CODE (type) == ENUMERAL_TYPE;
10686 /* Return the DBX register number described by a given RTL node. */
10688 static unsigned int
10689 dbx_reg_number (const_rtx rtl)
10691 unsigned regno = REGNO (rtl);
10693 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10695 #ifdef LEAF_REG_REMAP
10696 if (current_function_uses_only_leaf_regs)
10698 int leaf_reg = LEAF_REG_REMAP (regno);
10699 if (leaf_reg != -1)
10700 regno = (unsigned) leaf_reg;
10704 return DBX_REGISTER_NUMBER (regno);
10707 /* Optionally add a DW_OP_piece term to a location description expression.
10708 DW_OP_piece is only added if the location description expression already
10709 doesn't end with DW_OP_piece. */
10712 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10714 dw_loc_descr_ref loc;
10716 if (*list_head != NULL)
10718 /* Find the end of the chain. */
10719 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10722 if (loc->dw_loc_opc != DW_OP_piece)
10723 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10727 /* Return a location descriptor that designates a machine register or
10728 zero if there is none. */
10730 static dw_loc_descr_ref
10731 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10735 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10738 regs = targetm.dwarf_register_span (rtl);
10740 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10741 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10743 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10746 /* Return a location descriptor that designates a machine register for
10747 a given hard register number. */
10749 static dw_loc_descr_ref
10750 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10752 dw_loc_descr_ref reg_loc_descr;
10756 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10758 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10760 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10761 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10763 return reg_loc_descr;
10766 /* Given an RTL of a register, return a location descriptor that
10767 designates a value that spans more than one register. */
10769 static dw_loc_descr_ref
10770 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10771 enum var_init_status initialized)
10773 int nregs, size, i;
10775 dw_loc_descr_ref loc_result = NULL;
10778 #ifdef LEAF_REG_REMAP
10779 if (current_function_uses_only_leaf_regs)
10781 int leaf_reg = LEAF_REG_REMAP (reg);
10782 if (leaf_reg != -1)
10783 reg = (unsigned) leaf_reg;
10786 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10787 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10789 /* Simple, contiguous registers. */
10790 if (regs == NULL_RTX)
10792 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10797 dw_loc_descr_ref t;
10799 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10800 VAR_INIT_STATUS_INITIALIZED);
10801 add_loc_descr (&loc_result, t);
10802 add_loc_descr_op_piece (&loc_result, size);
10808 /* Now onto stupid register sets in non contiguous locations. */
10810 gcc_assert (GET_CODE (regs) == PARALLEL);
10812 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10815 for (i = 0; i < XVECLEN (regs, 0); ++i)
10817 dw_loc_descr_ref t;
10819 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10820 VAR_INIT_STATUS_INITIALIZED);
10821 add_loc_descr (&loc_result, t);
10822 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10823 add_loc_descr_op_piece (&loc_result, size);
10826 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10827 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10831 #endif /* DWARF2_DEBUGGING_INFO */
10833 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10835 /* Return a location descriptor that designates a constant. */
10837 static dw_loc_descr_ref
10838 int_loc_descriptor (HOST_WIDE_INT i)
10840 enum dwarf_location_atom op;
10842 /* Pick the smallest representation of a constant, rather than just
10843 defaulting to the LEB encoding. */
10847 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10848 else if (i <= 0xff)
10849 op = DW_OP_const1u;
10850 else if (i <= 0xffff)
10851 op = DW_OP_const2u;
10852 else if (HOST_BITS_PER_WIDE_INT == 32
10853 || i <= 0xffffffff)
10854 op = DW_OP_const4u;
10861 op = DW_OP_const1s;
10862 else if (i >= -0x8000)
10863 op = DW_OP_const2s;
10864 else if (HOST_BITS_PER_WIDE_INT == 32
10865 || i >= -0x80000000)
10866 op = DW_OP_const4s;
10871 return new_loc_descr (op, i, 0);
10875 #ifdef DWARF2_DEBUGGING_INFO
10877 /* Return a location descriptor that designates a base+offset location. */
10879 static dw_loc_descr_ref
10880 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10881 enum var_init_status initialized)
10883 unsigned int regno;
10884 dw_loc_descr_ref result;
10885 dw_fde_ref fde = current_fde ();
10887 /* We only use "frame base" when we're sure we're talking about the
10888 post-prologue local stack frame. We do this by *not* running
10889 register elimination until this point, and recognizing the special
10890 argument pointer and soft frame pointer rtx's. */
10891 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10893 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10897 if (GET_CODE (elim) == PLUS)
10899 offset += INTVAL (XEXP (elim, 1));
10900 elim = XEXP (elim, 0);
10902 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10903 && (elim == hard_frame_pointer_rtx
10904 || elim == stack_pointer_rtx))
10905 || elim == (frame_pointer_needed
10906 ? hard_frame_pointer_rtx
10907 : stack_pointer_rtx));
10909 /* If drap register is used to align stack, use frame
10910 pointer + offset to access stack variables. If stack
10911 is aligned without drap, use stack pointer + offset to
10912 access stack variables. */
10913 if (crtl->stack_realign_tried
10914 && reg == frame_pointer_rtx)
10917 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10918 ? HARD_FRAME_POINTER_REGNUM
10919 : STACK_POINTER_REGNUM);
10920 return new_reg_loc_descr (base_reg, offset);
10923 offset += frame_pointer_fb_offset;
10924 return new_loc_descr (DW_OP_fbreg, offset, 0);
10928 && fde->drap_reg != INVALID_REGNUM
10929 && (fde->drap_reg == REGNO (reg)
10930 || fde->vdrap_reg == REGNO (reg)))
10932 /* Use cfa+offset to represent the location of arguments passed
10933 on stack when drap is used to align stack. */
10934 return new_loc_descr (DW_OP_fbreg, offset, 0);
10937 regno = dbx_reg_number (reg);
10939 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10942 result = new_loc_descr (DW_OP_bregx, regno, offset);
10944 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10945 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10950 /* Return true if this RTL expression describes a base+offset calculation. */
10953 is_based_loc (const_rtx rtl)
10955 return (GET_CODE (rtl) == PLUS
10956 && ((REG_P (XEXP (rtl, 0))
10957 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10958 && CONST_INT_P (XEXP (rtl, 1)))));
10961 /* Return a descriptor that describes the concatenation of N locations
10962 used to form the address of a memory location. */
10964 static dw_loc_descr_ref
10965 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
10966 enum var_init_status initialized)
10969 dw_loc_descr_ref cc_loc_result = NULL;
10970 unsigned int n = XVECLEN (concatn, 0);
10972 for (i = 0; i < n; ++i)
10974 dw_loc_descr_ref ref;
10975 rtx x = XVECEXP (concatn, 0, i);
10977 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
10981 add_loc_descr (&cc_loc_result, ref);
10982 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10985 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10986 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10988 return cc_loc_result;
10991 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10994 static dw_loc_descr_ref
10995 tls_mem_loc_descriptor (rtx mem)
10998 dw_loc_descr_ref loc_result;
11000 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
11003 base = get_base_address (MEM_EXPR (mem));
11005 || TREE_CODE (base) != VAR_DECL
11006 || !DECL_THREAD_LOCAL_P (base))
11009 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
11010 if (loc_result == NULL)
11013 if (INTVAL (MEM_OFFSET (mem)))
11014 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
11019 /* The following routine converts the RTL for a variable or parameter
11020 (resident in memory) into an equivalent Dwarf representation of a
11021 mechanism for getting the address of that same variable onto the top of a
11022 hypothetical "address evaluation" stack.
11024 When creating memory location descriptors, we are effectively transforming
11025 the RTL for a memory-resident object into its Dwarf postfix expression
11026 equivalent. This routine recursively descends an RTL tree, turning
11027 it into Dwarf postfix code as it goes.
11029 MODE is the mode of the memory reference, needed to handle some
11030 autoincrement addressing modes.
11032 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
11033 location list for RTL.
11035 Return 0 if we can't represent the location. */
11037 static dw_loc_descr_ref
11038 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11039 enum var_init_status initialized)
11041 dw_loc_descr_ref mem_loc_result = NULL;
11042 enum dwarf_location_atom op;
11043 dw_loc_descr_ref op0, op1;
11045 /* Note that for a dynamically sized array, the location we will generate a
11046 description of here will be the lowest numbered location which is
11047 actually within the array. That's *not* necessarily the same as the
11048 zeroth element of the array. */
11050 rtl = targetm.delegitimize_address (rtl);
11052 switch (GET_CODE (rtl))
11057 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
11058 just fall into the SUBREG code. */
11060 /* ... fall through ... */
11063 /* The case of a subreg may arise when we have a local (register)
11064 variable or a formal (register) parameter which doesn't quite fill
11065 up an entire register. For now, just assume that it is
11066 legitimate to make the Dwarf info refer to the whole register which
11067 contains the given subreg. */
11068 rtl = XEXP (rtl, 0);
11069 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
11072 /* ... fall through ... */
11075 /* Whenever a register number forms a part of the description of the
11076 method for calculating the (dynamic) address of a memory resident
11077 object, DWARF rules require the register number be referred to as
11078 a "base register". This distinction is not based in any way upon
11079 what category of register the hardware believes the given register
11080 belongs to. This is strictly DWARF terminology we're dealing with
11081 here. Note that in cases where the location of a memory-resident
11082 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11083 OP_CONST (0)) the actual DWARF location descriptor that we generate
11084 may just be OP_BASEREG (basereg). This may look deceptively like
11085 the object in question was allocated to a register (rather than in
11086 memory) so DWARF consumers need to be aware of the subtle
11087 distinction between OP_REG and OP_BASEREG. */
11088 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11089 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11090 else if (stack_realign_drap
11092 && crtl->args.internal_arg_pointer == rtl
11093 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11095 /* If RTL is internal_arg_pointer, which has been optimized
11096 out, use DRAP instead. */
11097 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11098 VAR_INIT_STATUS_INITIALIZED);
11104 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11105 VAR_INIT_STATUS_INITIALIZED);
11110 int shift = DWARF2_ADDR_SIZE
11111 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11112 shift *= BITS_PER_UNIT;
11113 if (GET_CODE (rtl) == SIGN_EXTEND)
11117 mem_loc_result = op0;
11118 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11119 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11120 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11121 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11126 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11127 VAR_INIT_STATUS_INITIALIZED);
11128 if (mem_loc_result == NULL)
11129 mem_loc_result = tls_mem_loc_descriptor (rtl);
11130 if (mem_loc_result != 0)
11131 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11135 rtl = XEXP (rtl, 1);
11137 /* ... fall through ... */
11140 /* Some ports can transform a symbol ref into a label ref, because
11141 the symbol ref is too far away and has to be dumped into a constant
11145 /* Alternatively, the symbol in the constant pool might be referenced
11146 by a different symbol. */
11147 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
11150 rtx tmp = get_pool_constant_mark (rtl, &marked);
11152 if (GET_CODE (tmp) == SYMBOL_REF)
11155 if (CONSTANT_POOL_ADDRESS_P (tmp))
11156 get_pool_constant_mark (tmp, &marked);
11161 /* If all references to this pool constant were optimized away,
11162 it was not output and thus we can't represent it.
11163 FIXME: might try to use DW_OP_const_value here, though
11164 DW_OP_piece complicates it. */
11169 if (GET_CODE (rtl) == SYMBOL_REF
11170 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11172 dw_loc_descr_ref temp;
11174 /* If this is not defined, we have no way to emit the data. */
11175 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11178 temp = new_loc_descr (DW_OP_addr, 0, 0);
11179 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11180 temp->dw_loc_oprnd1.v.val_addr = rtl;
11181 temp->dtprel = true;
11183 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11184 add_loc_descr (&mem_loc_result, temp);
11190 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11191 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11192 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11193 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11197 /* Extract the PLUS expression nested inside and fall into
11198 PLUS code below. */
11199 rtl = XEXP (rtl, 1);
11204 /* Turn these into a PLUS expression and fall into the PLUS code
11206 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
11207 GEN_INT (GET_CODE (rtl) == PRE_INC
11208 ? GET_MODE_UNIT_SIZE (mode)
11209 : -GET_MODE_UNIT_SIZE (mode)));
11211 /* ... fall through ... */
11215 if (is_based_loc (rtl))
11216 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11217 INTVAL (XEXP (rtl, 1)),
11218 VAR_INIT_STATUS_INITIALIZED);
11221 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
11222 VAR_INIT_STATUS_INITIALIZED);
11223 if (mem_loc_result == 0)
11226 if (CONST_INT_P (XEXP (rtl, 1)))
11227 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11230 dw_loc_descr_ref mem_loc_result2
11231 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11232 VAR_INIT_STATUS_INITIALIZED);
11233 if (mem_loc_result2 == 0)
11235 add_loc_descr (&mem_loc_result, mem_loc_result2);
11236 add_loc_descr (&mem_loc_result,
11237 new_loc_descr (DW_OP_plus, 0, 0));
11242 /* If a pseudo-reg is optimized away, it is possible for it to
11243 be replaced with a MEM containing a multiply or shift. */
11285 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11286 VAR_INIT_STATUS_INITIALIZED);
11287 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11288 VAR_INIT_STATUS_INITIALIZED);
11290 if (op0 == 0 || op1 == 0)
11293 mem_loc_result = op0;
11294 add_loc_descr (&mem_loc_result, op1);
11295 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11311 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11312 VAR_INIT_STATUS_INITIALIZED);
11317 mem_loc_result = op0;
11318 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11322 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11326 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
11327 VAR_INIT_STATUS_INITIALIZED);
11355 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11356 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11357 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11360 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11361 VAR_INIT_STATUS_INITIALIZED);
11362 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11363 VAR_INIT_STATUS_INITIALIZED);
11365 if (op0 == 0 || op1 == 0)
11368 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11370 int shift = DWARF2_ADDR_SIZE
11371 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11372 shift *= BITS_PER_UNIT;
11373 add_loc_descr (&op0, int_loc_descriptor (shift));
11374 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11375 if (CONST_INT_P (XEXP (rtl, 1)))
11376 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
11379 add_loc_descr (&op1, int_loc_descriptor (shift));
11380 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11385 mem_loc_result = op0;
11386 add_loc_descr (&mem_loc_result, op1);
11387 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11388 if (STORE_FLAG_VALUE != 1)
11390 add_loc_descr (&mem_loc_result,
11391 int_loc_descriptor (STORE_FLAG_VALUE));
11392 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11413 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11414 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11415 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11418 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11419 VAR_INIT_STATUS_INITIALIZED);
11420 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11421 VAR_INIT_STATUS_INITIALIZED);
11423 if (op0 == 0 || op1 == 0)
11426 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11428 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11429 add_loc_descr (&op0, int_loc_descriptor (mask));
11430 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11431 if (CONST_INT_P (XEXP (rtl, 1)))
11432 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11435 add_loc_descr (&op1, int_loc_descriptor (mask));
11436 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11441 HOST_WIDE_INT bias = 1;
11442 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11443 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11444 if (CONST_INT_P (XEXP (rtl, 1)))
11445 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11446 + INTVAL (XEXP (rtl, 1)));
11448 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11456 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11457 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11458 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11461 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11462 VAR_INIT_STATUS_INITIALIZED);
11463 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11464 VAR_INIT_STATUS_INITIALIZED);
11466 if (op0 == 0 || op1 == 0)
11469 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11470 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11471 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11472 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11474 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11476 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11477 add_loc_descr (&op0, int_loc_descriptor (mask));
11478 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11479 add_loc_descr (&op1, int_loc_descriptor (mask));
11480 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11484 HOST_WIDE_INT bias = 1;
11485 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11486 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11487 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11490 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11492 int shift = DWARF2_ADDR_SIZE
11493 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11494 shift *= BITS_PER_UNIT;
11495 add_loc_descr (&op0, int_loc_descriptor (shift));
11496 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11497 add_loc_descr (&op1, int_loc_descriptor (shift));
11498 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11501 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11505 mem_loc_result = op0;
11506 add_loc_descr (&mem_loc_result, op1);
11507 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11509 dw_loc_descr_ref bra_node, drop_node;
11511 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11512 add_loc_descr (&mem_loc_result, bra_node);
11513 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
11514 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11515 add_loc_descr (&mem_loc_result, drop_node);
11516 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11517 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11523 if (CONST_INT_P (XEXP (rtl, 1))
11524 && CONST_INT_P (XEXP (rtl, 2))
11525 && ((unsigned) INTVAL (XEXP (rtl, 1))
11526 + (unsigned) INTVAL (XEXP (rtl, 2))
11527 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
11528 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
11529 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
11532 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11533 VAR_INIT_STATUS_INITIALIZED);
11536 if (GET_CODE (rtl) == SIGN_EXTRACT)
11540 mem_loc_result = op0;
11541 size = INTVAL (XEXP (rtl, 1));
11542 shift = INTVAL (XEXP (rtl, 2));
11543 if (BITS_BIG_ENDIAN)
11544 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11546 add_loc_descr (&mem_loc_result,
11547 int_loc_descriptor (DWARF2_ADDR_SIZE - shift - size));
11548 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11549 add_loc_descr (&mem_loc_result,
11550 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
11551 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11560 /* In theory, we could implement the above. */
11561 /* DWARF cannot represent the unsigned compare operations
11577 case FLOAT_TRUNCATE:
11579 case UNSIGNED_FLOAT:
11582 case FRACT_CONVERT:
11583 case UNSIGNED_FRACT_CONVERT:
11585 case UNSIGNED_SAT_FRACT:
11595 /* If delegitimize_address couldn't do anything with the UNSPEC, we
11596 can't express it in the debug info. This can happen e.g. with some
11601 rtl = get_debug_string_label (XSTR (rtl, 0));
11605 #ifdef ENABLE_CHECKING
11606 print_rtl (stderr, rtl);
11607 gcc_unreachable ();
11613 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11614 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11616 return mem_loc_result;
11619 /* Return a descriptor that describes the concatenation of two locations.
11620 This is typically a complex variable. */
11622 static dw_loc_descr_ref
11623 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
11625 dw_loc_descr_ref cc_loc_result = NULL;
11626 dw_loc_descr_ref x0_ref
11627 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11628 dw_loc_descr_ref x1_ref
11629 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11631 if (x0_ref == 0 || x1_ref == 0)
11634 cc_loc_result = x0_ref;
11635 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
11637 add_loc_descr (&cc_loc_result, x1_ref);
11638 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
11640 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11641 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11643 return cc_loc_result;
11646 /* Return a descriptor that describes the concatenation of N
11649 static dw_loc_descr_ref
11650 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
11653 dw_loc_descr_ref cc_loc_result = NULL;
11654 unsigned int n = XVECLEN (concatn, 0);
11656 for (i = 0; i < n; ++i)
11658 dw_loc_descr_ref ref;
11659 rtx x = XVECEXP (concatn, 0, i);
11661 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11665 add_loc_descr (&cc_loc_result, ref);
11666 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
11669 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11670 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11672 return cc_loc_result;
11675 /* Output a proper Dwarf location descriptor for a variable or parameter
11676 which is either allocated in a register or in a memory location. For a
11677 register, we just generate an OP_REG and the register number. For a
11678 memory location we provide a Dwarf postfix expression describing how to
11679 generate the (dynamic) address of the object onto the address stack.
11681 MODE is mode of the decl if this loc_descriptor is going to be used in
11682 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
11683 allowed, VOIDmode otherwise.
11685 If we don't know how to describe it, return 0. */
11687 static dw_loc_descr_ref
11688 loc_descriptor (rtx rtl, enum machine_mode mode,
11689 enum var_init_status initialized)
11691 dw_loc_descr_ref loc_result = NULL;
11693 switch (GET_CODE (rtl))
11696 /* The case of a subreg may arise when we have a local (register)
11697 variable or a formal (register) parameter which doesn't quite fill
11698 up an entire register. For now, just assume that it is
11699 legitimate to make the Dwarf info refer to the whole register which
11700 contains the given subreg. */
11701 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
11705 loc_result = reg_loc_descriptor (rtl, initialized);
11710 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11714 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11716 if (loc_result == NULL)
11717 loc_result = tls_mem_loc_descriptor (rtl);
11721 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
11726 loc_result = concatn_loc_descriptor (rtl, initialized);
11731 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
11733 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), mode,
11738 rtl = XEXP (rtl, 1);
11743 rtvec par_elems = XVEC (rtl, 0);
11744 int num_elem = GET_NUM_ELEM (par_elems);
11745 enum machine_mode mode;
11748 /* Create the first one, so we have something to add to. */
11749 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
11750 VOIDmode, initialized);
11751 if (loc_result == NULL)
11753 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
11754 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11755 for (i = 1; i < num_elem; i++)
11757 dw_loc_descr_ref temp;
11759 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
11760 VOIDmode, initialized);
11763 add_loc_descr (&loc_result, temp);
11764 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
11765 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11771 if (mode != VOIDmode && mode != BLKmode && dwarf_version >= 4)
11773 HOST_WIDE_INT i = INTVAL (rtl);
11779 else if (i <= 0xff)
11781 else if (i <= 0xffff)
11783 else if (HOST_BITS_PER_WIDE_INT == 32
11784 || i <= 0xffffffff)
11787 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
11793 else if (i >= -0x8000)
11795 else if (HOST_BITS_PER_WIDE_INT == 32
11796 || i >= -0x80000000)
11799 litsize = 1 + size_of_sleb128 (i);
11801 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11802 is more compact. For DW_OP_stack_value we need:
11803 litsize + 1 (DW_OP_stack_value) + 1 (DW_OP_bit_size)
11805 and for DW_OP_implicit_value:
11806 1 (DW_OP_implicit_value) + 1 (length) + mode_size. */
11807 if (DWARF2_ADDR_SIZE >= GET_MODE_SIZE (mode)
11808 && litsize + 1 + 1 + 1 < 1 + 1 + GET_MODE_SIZE (mode))
11810 loc_result = int_loc_descriptor (i);
11811 add_loc_descr (&loc_result,
11812 new_loc_descr (DW_OP_stack_value, 0, 0));
11813 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11817 loc_result = new_loc_descr (DW_OP_implicit_value,
11818 GET_MODE_SIZE (mode), 0);
11819 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11820 loc_result->dw_loc_oprnd2.v.val_int = i;
11825 if (mode != VOIDmode && dwarf_version >= 4)
11827 /* Note that a CONST_DOUBLE rtx could represent either an integer
11828 or a floating-point constant. A CONST_DOUBLE is used whenever
11829 the constant requires more than one word in order to be
11830 adequately represented. We output CONST_DOUBLEs as blocks. */
11831 if (GET_MODE (rtl) != VOIDmode)
11832 mode = GET_MODE (rtl);
11834 loc_result = new_loc_descr (DW_OP_implicit_value,
11835 GET_MODE_SIZE (mode), 0);
11836 if (SCALAR_FLOAT_MODE_P (mode))
11838 unsigned int length = GET_MODE_SIZE (mode);
11839 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11841 insert_float (rtl, array);
11842 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11843 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
11844 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
11845 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11849 loc_result->dw_loc_oprnd2.val_class = dw_val_class_long_long;
11850 loc_result->dw_loc_oprnd2.v.val_long_long = rtl;
11856 if (mode != VOIDmode && dwarf_version >= 4)
11858 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
11859 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11860 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11864 mode = GET_MODE (rtl);
11865 switch (GET_MODE_CLASS (mode))
11867 case MODE_VECTOR_INT:
11868 for (i = 0, p = array; i < length; i++, p += elt_size)
11870 rtx elt = CONST_VECTOR_ELT (rtl, i);
11871 HOST_WIDE_INT lo, hi;
11873 switch (GET_CODE (elt))
11881 lo = CONST_DOUBLE_LOW (elt);
11882 hi = CONST_DOUBLE_HIGH (elt);
11886 gcc_unreachable ();
11889 if (elt_size <= sizeof (HOST_WIDE_INT))
11890 insert_int (lo, elt_size, p);
11893 unsigned char *p0 = p;
11894 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11896 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11897 if (WORDS_BIG_ENDIAN)
11902 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11903 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11908 case MODE_VECTOR_FLOAT:
11909 for (i = 0, p = array; i < length; i++, p += elt_size)
11911 rtx elt = CONST_VECTOR_ELT (rtl, i);
11912 insert_float (elt, p);
11917 gcc_unreachable ();
11920 loc_result = new_loc_descr (DW_OP_implicit_value,
11921 length * elt_size, 0);
11922 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11923 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
11924 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
11925 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11930 if (mode == VOIDmode
11931 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
11932 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
11933 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
11935 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11940 if (GET_CODE (rtl) == SYMBOL_REF
11941 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11944 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
11945 && dwarf_version >= 4)
11947 loc_result = new_loc_descr (DW_OP_implicit_value,
11948 DWARF2_ADDR_SIZE, 0);
11949 loc_result->dw_loc_oprnd2.val_class = dw_val_class_addr;
11950 loc_result->dw_loc_oprnd2.v.val_addr = rtl;
11951 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11956 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
11957 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
11958 && dwarf_version >= 4)
11960 /* Value expression. */
11961 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
11964 add_loc_descr (&loc_result,
11965 new_loc_descr (DW_OP_stack_value, 0, 0));
11966 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11975 /* Similar, but generate the descriptor from trees instead of rtl. This comes
11976 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
11977 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
11978 top-level invocation, and we require the address of LOC; is 0 if we require
11979 the value of LOC. */
11981 static dw_loc_descr_ref
11982 loc_descriptor_from_tree_1 (tree loc, int want_address)
11984 dw_loc_descr_ref ret, ret1;
11985 int have_address = 0;
11986 enum dwarf_location_atom op;
11988 /* ??? Most of the time we do not take proper care for sign/zero
11989 extending the values properly. Hopefully this won't be a real
11992 switch (TREE_CODE (loc))
11997 case PLACEHOLDER_EXPR:
11998 /* This case involves extracting fields from an object to determine the
11999 position of other fields. We don't try to encode this here. The
12000 only user of this is Ada, which encodes the needed information using
12001 the names of types. */
12007 case PREINCREMENT_EXPR:
12008 case PREDECREMENT_EXPR:
12009 case POSTINCREMENT_EXPR:
12010 case POSTDECREMENT_EXPR:
12011 /* There are no opcodes for these operations. */
12015 /* If we already want an address, there's nothing we can do. */
12019 /* Otherwise, process the argument and look for the address. */
12020 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
12023 if (DECL_THREAD_LOCAL_P (loc))
12026 enum dwarf_location_atom first_op;
12027 enum dwarf_location_atom second_op;
12028 bool dtprel = false;
12030 if (targetm.have_tls)
12032 /* If this is not defined, we have no way to emit the
12034 if (!targetm.asm_out.output_dwarf_dtprel)
12037 /* The way DW_OP_GNU_push_tls_address is specified, we
12038 can only look up addresses of objects in the current
12040 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
12042 first_op = DW_OP_addr;
12044 second_op = DW_OP_GNU_push_tls_address;
12048 if (!targetm.emutls.debug_form_tls_address)
12050 loc = emutls_decl (loc);
12051 first_op = DW_OP_addr;
12052 second_op = DW_OP_form_tls_address;
12055 rtl = rtl_for_decl_location (loc);
12056 if (rtl == NULL_RTX)
12061 rtl = XEXP (rtl, 0);
12062 if (! CONSTANT_P (rtl))
12065 ret = new_loc_descr (first_op, 0, 0);
12066 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12067 ret->dw_loc_oprnd1.v.val_addr = rtl;
12068 ret->dtprel = dtprel;
12070 ret1 = new_loc_descr (second_op, 0, 0);
12071 add_loc_descr (&ret, ret1);
12079 if (DECL_HAS_VALUE_EXPR_P (loc))
12080 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
12085 case FUNCTION_DECL:
12087 rtx rtl = rtl_for_decl_location (loc);
12089 if (rtl == NULL_RTX)
12091 else if (CONST_INT_P (rtl))
12093 HOST_WIDE_INT val = INTVAL (rtl);
12094 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
12095 val &= GET_MODE_MASK (DECL_MODE (loc));
12096 ret = int_loc_descriptor (val);
12098 else if (GET_CODE (rtl) == CONST_STRING)
12100 else if (CONSTANT_P (rtl))
12102 ret = new_loc_descr (DW_OP_addr, 0, 0);
12103 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12104 ret->dw_loc_oprnd1.v.val_addr = rtl;
12108 enum machine_mode mode;
12110 /* Certain constructs can only be represented at top-level. */
12111 if (want_address == 2)
12112 return loc_descriptor (rtl, VOIDmode,
12113 VAR_INIT_STATUS_INITIALIZED);
12115 mode = GET_MODE (rtl);
12118 rtl = XEXP (rtl, 0);
12121 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12127 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12131 case COMPOUND_EXPR:
12132 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
12135 case VIEW_CONVERT_EXPR:
12138 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
12140 case COMPONENT_REF:
12141 case BIT_FIELD_REF:
12143 case ARRAY_RANGE_REF:
12146 HOST_WIDE_INT bitsize, bitpos, bytepos;
12147 enum machine_mode mode;
12149 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
12151 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
12152 &unsignedp, &volatilep, false);
12157 ret = loc_descriptor_from_tree_1 (obj, 1);
12159 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
12162 if (offset != NULL_TREE)
12164 /* Variable offset. */
12165 ret1 = loc_descriptor_from_tree_1 (offset, 0);
12168 add_loc_descr (&ret, ret1);
12169 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
12172 bytepos = bitpos / BITS_PER_UNIT;
12173 loc_descr_plus_const (&ret, bytepos);
12180 if (host_integerp (loc, 0))
12181 ret = int_loc_descriptor (tree_low_cst (loc, 0));
12188 /* Get an RTL for this, if something has been emitted. */
12189 rtx rtl = lookup_constant_def (loc);
12190 enum machine_mode mode;
12192 if (!rtl || !MEM_P (rtl))
12194 mode = GET_MODE (rtl);
12195 rtl = XEXP (rtl, 0);
12196 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12201 case TRUTH_AND_EXPR:
12202 case TRUTH_ANDIF_EXPR:
12207 case TRUTH_XOR_EXPR:
12212 case TRUTH_OR_EXPR:
12213 case TRUTH_ORIF_EXPR:
12218 case FLOOR_DIV_EXPR:
12219 case CEIL_DIV_EXPR:
12220 case ROUND_DIV_EXPR:
12221 case TRUNC_DIV_EXPR:
12229 case FLOOR_MOD_EXPR:
12230 case CEIL_MOD_EXPR:
12231 case ROUND_MOD_EXPR:
12232 case TRUNC_MOD_EXPR:
12245 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
12248 case POINTER_PLUS_EXPR:
12250 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
12251 && host_integerp (TREE_OPERAND (loc, 1), 0))
12253 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12257 loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
12265 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12272 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12279 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12286 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12301 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12302 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
12303 if (ret == 0 || ret1 == 0)
12306 add_loc_descr (&ret, ret1);
12307 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12310 case TRUTH_NOT_EXPR:
12324 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12328 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12334 const enum tree_code code =
12335 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
12337 loc = build3 (COND_EXPR, TREE_TYPE (loc),
12338 build2 (code, integer_type_node,
12339 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
12340 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
12343 /* ... fall through ... */
12347 dw_loc_descr_ref lhs
12348 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
12349 dw_loc_descr_ref rhs
12350 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
12351 dw_loc_descr_ref bra_node, jump_node, tmp;
12353 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12354 if (ret == 0 || lhs == 0 || rhs == 0)
12357 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12358 add_loc_descr (&ret, bra_node);
12360 add_loc_descr (&ret, rhs);
12361 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
12362 add_loc_descr (&ret, jump_node);
12364 add_loc_descr (&ret, lhs);
12365 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12366 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
12368 /* ??? Need a node to point the skip at. Use a nop. */
12369 tmp = new_loc_descr (DW_OP_nop, 0, 0);
12370 add_loc_descr (&ret, tmp);
12371 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12372 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
12376 case FIX_TRUNC_EXPR:
12380 /* Leave front-end specific codes as simply unknown. This comes
12381 up, for instance, with the C STMT_EXPR. */
12382 if ((unsigned int) TREE_CODE (loc)
12383 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
12386 #ifdef ENABLE_CHECKING
12387 /* Otherwise this is a generic code; we should just lists all of
12388 these explicitly. We forgot one. */
12389 gcc_unreachable ();
12391 /* In a release build, we want to degrade gracefully: better to
12392 generate incomplete debugging information than to crash. */
12397 /* Show if we can't fill the request for an address. */
12398 if (want_address && !have_address)
12401 /* If we've got an address and don't want one, dereference. */
12402 if (!want_address && have_address && ret)
12404 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12406 if (size > DWARF2_ADDR_SIZE || size == -1)
12408 else if (size == DWARF2_ADDR_SIZE)
12411 op = DW_OP_deref_size;
12413 add_loc_descr (&ret, new_loc_descr (op, size, 0));
12419 static inline dw_loc_descr_ref
12420 loc_descriptor_from_tree (tree loc)
12422 return loc_descriptor_from_tree_1 (loc, 2);
12425 /* Given a value, round it up to the lowest multiple of `boundary'
12426 which is not less than the value itself. */
12428 static inline HOST_WIDE_INT
12429 ceiling (HOST_WIDE_INT value, unsigned int boundary)
12431 return (((value + boundary - 1) / boundary) * boundary);
12434 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
12435 pointer to the declared type for the relevant field variable, or return
12436 `integer_type_node' if the given node turns out to be an
12437 ERROR_MARK node. */
12440 field_type (const_tree decl)
12444 if (TREE_CODE (decl) == ERROR_MARK)
12445 return integer_type_node;
12447 type = DECL_BIT_FIELD_TYPE (decl);
12448 if (type == NULL_TREE)
12449 type = TREE_TYPE (decl);
12454 /* Given a pointer to a tree node, return the alignment in bits for
12455 it, or else return BITS_PER_WORD if the node actually turns out to
12456 be an ERROR_MARK node. */
12458 static inline unsigned
12459 simple_type_align_in_bits (const_tree type)
12461 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
12464 static inline unsigned
12465 simple_decl_align_in_bits (const_tree decl)
12467 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
12470 /* Return the result of rounding T up to ALIGN. */
12472 static inline HOST_WIDE_INT
12473 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
12475 /* We must be careful if T is negative because HOST_WIDE_INT can be
12476 either "above" or "below" unsigned int as per the C promotion
12477 rules, depending on the host, thus making the signedness of the
12478 direct multiplication and division unpredictable. */
12479 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
12485 return (HOST_WIDE_INT) u;
12488 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
12489 lowest addressed byte of the "containing object" for the given FIELD_DECL,
12490 or return 0 if we are unable to determine what that offset is, either
12491 because the argument turns out to be a pointer to an ERROR_MARK node, or
12492 because the offset is actually variable. (We can't handle the latter case
12495 static HOST_WIDE_INT
12496 field_byte_offset (const_tree decl)
12498 HOST_WIDE_INT object_offset_in_bits;
12499 HOST_WIDE_INT bitpos_int;
12501 if (TREE_CODE (decl) == ERROR_MARK)
12504 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
12506 /* We cannot yet cope with fields whose positions are variable, so
12507 for now, when we see such things, we simply return 0. Someday, we may
12508 be able to handle such cases, but it will be damn difficult. */
12509 if (! host_integerp (bit_position (decl), 0))
12512 bitpos_int = int_bit_position (decl);
12514 #ifdef PCC_BITFIELD_TYPE_MATTERS
12515 if (PCC_BITFIELD_TYPE_MATTERS)
12518 tree field_size_tree;
12519 HOST_WIDE_INT deepest_bitpos;
12520 unsigned HOST_WIDE_INT field_size_in_bits;
12521 unsigned int type_align_in_bits;
12522 unsigned int decl_align_in_bits;
12523 unsigned HOST_WIDE_INT type_size_in_bits;
12525 type = field_type (decl);
12526 type_size_in_bits = simple_type_size_in_bits (type);
12527 type_align_in_bits = simple_type_align_in_bits (type);
12529 field_size_tree = DECL_SIZE (decl);
12531 /* The size could be unspecified if there was an error, or for
12532 a flexible array member. */
12533 if (!field_size_tree)
12534 field_size_tree = bitsize_zero_node;
12536 /* If the size of the field is not constant, use the type size. */
12537 if (host_integerp (field_size_tree, 1))
12538 field_size_in_bits = tree_low_cst (field_size_tree, 1);
12540 field_size_in_bits = type_size_in_bits;
12542 decl_align_in_bits = simple_decl_align_in_bits (decl);
12544 /* The GCC front-end doesn't make any attempt to keep track of the
12545 starting bit offset (relative to the start of the containing
12546 structure type) of the hypothetical "containing object" for a
12547 bit-field. Thus, when computing the byte offset value for the
12548 start of the "containing object" of a bit-field, we must deduce
12549 this information on our own. This can be rather tricky to do in
12550 some cases. For example, handling the following structure type
12551 definition when compiling for an i386/i486 target (which only
12552 aligns long long's to 32-bit boundaries) can be very tricky:
12554 struct S { int field1; long long field2:31; };
12556 Fortunately, there is a simple rule-of-thumb which can be used
12557 in such cases. When compiling for an i386/i486, GCC will
12558 allocate 8 bytes for the structure shown above. It decides to
12559 do this based upon one simple rule for bit-field allocation.
12560 GCC allocates each "containing object" for each bit-field at
12561 the first (i.e. lowest addressed) legitimate alignment boundary
12562 (based upon the required minimum alignment for the declared
12563 type of the field) which it can possibly use, subject to the
12564 condition that there is still enough available space remaining
12565 in the containing object (when allocated at the selected point)
12566 to fully accommodate all of the bits of the bit-field itself.
12568 This simple rule makes it obvious why GCC allocates 8 bytes for
12569 each object of the structure type shown above. When looking
12570 for a place to allocate the "containing object" for `field2',
12571 the compiler simply tries to allocate a 64-bit "containing
12572 object" at each successive 32-bit boundary (starting at zero)
12573 until it finds a place to allocate that 64- bit field such that
12574 at least 31 contiguous (and previously unallocated) bits remain
12575 within that selected 64 bit field. (As it turns out, for the
12576 example above, the compiler finds it is OK to allocate the
12577 "containing object" 64-bit field at bit-offset zero within the
12580 Here we attempt to work backwards from the limited set of facts
12581 we're given, and we try to deduce from those facts, where GCC
12582 must have believed that the containing object started (within
12583 the structure type). The value we deduce is then used (by the
12584 callers of this routine) to generate DW_AT_location and
12585 DW_AT_bit_offset attributes for fields (both bit-fields and, in
12586 the case of DW_AT_location, regular fields as well). */
12588 /* Figure out the bit-distance from the start of the structure to
12589 the "deepest" bit of the bit-field. */
12590 deepest_bitpos = bitpos_int + field_size_in_bits;
12592 /* This is the tricky part. Use some fancy footwork to deduce
12593 where the lowest addressed bit of the containing object must
12595 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
12597 /* Round up to type_align by default. This works best for
12599 object_offset_in_bits
12600 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
12602 if (object_offset_in_bits > bitpos_int)
12604 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
12606 /* Round up to decl_align instead. */
12607 object_offset_in_bits
12608 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
12613 object_offset_in_bits = bitpos_int;
12615 return object_offset_in_bits / BITS_PER_UNIT;
12618 /* The following routines define various Dwarf attributes and any data
12619 associated with them. */
12621 /* Add a location description attribute value to a DIE.
12623 This emits location attributes suitable for whole variables and
12624 whole parameters. Note that the location attributes for struct fields are
12625 generated by the routine `data_member_location_attribute' below. */
12628 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
12629 dw_loc_descr_ref descr)
12632 add_AT_loc (die, attr_kind, descr);
12635 /* Attach the specialized form of location attribute used for data members of
12636 struct and union types. In the special case of a FIELD_DECL node which
12637 represents a bit-field, the "offset" part of this special location
12638 descriptor must indicate the distance in bytes from the lowest-addressed
12639 byte of the containing struct or union type to the lowest-addressed byte of
12640 the "containing object" for the bit-field. (See the `field_byte_offset'
12643 For any given bit-field, the "containing object" is a hypothetical object
12644 (of some integral or enum type) within which the given bit-field lives. The
12645 type of this hypothetical "containing object" is always the same as the
12646 declared type of the individual bit-field itself (for GCC anyway... the
12647 DWARF spec doesn't actually mandate this). Note that it is the size (in
12648 bytes) of the hypothetical "containing object" which will be given in the
12649 DW_AT_byte_size attribute for this bit-field. (See the
12650 `byte_size_attribute' function below.) It is also used when calculating the
12651 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
12652 function below.) */
12655 add_data_member_location_attribute (dw_die_ref die, tree decl)
12657 HOST_WIDE_INT offset;
12658 dw_loc_descr_ref loc_descr = 0;
12660 if (TREE_CODE (decl) == TREE_BINFO)
12662 /* We're working on the TAG_inheritance for a base class. */
12663 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
12665 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
12666 aren't at a fixed offset from all (sub)objects of the same
12667 type. We need to extract the appropriate offset from our
12668 vtable. The following dwarf expression means
12670 BaseAddr = ObAddr + *((*ObAddr) - Offset)
12672 This is specific to the V3 ABI, of course. */
12674 dw_loc_descr_ref tmp;
12676 /* Make a copy of the object address. */
12677 tmp = new_loc_descr (DW_OP_dup, 0, 0);
12678 add_loc_descr (&loc_descr, tmp);
12680 /* Extract the vtable address. */
12681 tmp = new_loc_descr (DW_OP_deref, 0, 0);
12682 add_loc_descr (&loc_descr, tmp);
12684 /* Calculate the address of the offset. */
12685 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
12686 gcc_assert (offset < 0);
12688 tmp = int_loc_descriptor (-offset);
12689 add_loc_descr (&loc_descr, tmp);
12690 tmp = new_loc_descr (DW_OP_minus, 0, 0);
12691 add_loc_descr (&loc_descr, tmp);
12693 /* Extract the offset. */
12694 tmp = new_loc_descr (DW_OP_deref, 0, 0);
12695 add_loc_descr (&loc_descr, tmp);
12697 /* Add it to the object address. */
12698 tmp = new_loc_descr (DW_OP_plus, 0, 0);
12699 add_loc_descr (&loc_descr, tmp);
12702 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
12705 offset = field_byte_offset (decl);
12709 if (dwarf_version > 2)
12711 /* Don't need to output a location expression, just the constant. */
12712 add_AT_int (die, DW_AT_data_member_location, offset);
12717 enum dwarf_location_atom op;
12719 /* The DWARF2 standard says that we should assume that the structure
12720 address is already on the stack, so we can specify a structure
12721 field address by using DW_OP_plus_uconst. */
12723 #ifdef MIPS_DEBUGGING_INFO
12724 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
12725 operator correctly. It works only if we leave the offset on the
12729 op = DW_OP_plus_uconst;
12732 loc_descr = new_loc_descr (op, offset, 0);
12736 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
12739 /* Writes integer values to dw_vec_const array. */
12742 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
12746 *dest++ = val & 0xff;
12752 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
12754 static HOST_WIDE_INT
12755 extract_int (const unsigned char *src, unsigned int size)
12757 HOST_WIDE_INT val = 0;
12763 val |= *--src & 0xff;
12769 /* Writes floating point values to dw_vec_const array. */
12772 insert_float (const_rtx rtl, unsigned char *array)
12774 REAL_VALUE_TYPE rv;
12778 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
12779 real_to_target (val, &rv, GET_MODE (rtl));
12781 /* real_to_target puts 32-bit pieces in each long. Pack them. */
12782 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
12784 insert_int (val[i], 4, array);
12789 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
12790 does not have a "location" either in memory or in a register. These
12791 things can arise in GNU C when a constant is passed as an actual parameter
12792 to an inlined function. They can also arise in C++ where declared
12793 constants do not necessarily get memory "homes". */
12796 add_const_value_attribute (dw_die_ref die, rtx rtl)
12798 switch (GET_CODE (rtl))
12802 HOST_WIDE_INT val = INTVAL (rtl);
12805 add_AT_int (die, DW_AT_const_value, val);
12807 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
12812 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
12813 floating-point constant. A CONST_DOUBLE is used whenever the
12814 constant requires more than one word in order to be adequately
12815 represented. We output CONST_DOUBLEs as blocks. */
12817 enum machine_mode mode = GET_MODE (rtl);
12819 if (SCALAR_FLOAT_MODE_P (mode))
12821 unsigned int length = GET_MODE_SIZE (mode);
12822 unsigned char *array = GGC_NEWVEC (unsigned char, length);
12824 insert_float (rtl, array);
12825 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
12828 add_AT_long_long (die, DW_AT_const_value, rtl);
12834 enum machine_mode mode = GET_MODE (rtl);
12835 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
12836 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12837 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
12841 switch (GET_MODE_CLASS (mode))
12843 case MODE_VECTOR_INT:
12844 for (i = 0, p = array; i < length; i++, p += elt_size)
12846 rtx elt = CONST_VECTOR_ELT (rtl, i);
12847 HOST_WIDE_INT lo, hi;
12849 switch (GET_CODE (elt))
12857 lo = CONST_DOUBLE_LOW (elt);
12858 hi = CONST_DOUBLE_HIGH (elt);
12862 gcc_unreachable ();
12865 if (elt_size <= sizeof (HOST_WIDE_INT))
12866 insert_int (lo, elt_size, p);
12869 unsigned char *p0 = p;
12870 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
12872 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12873 if (WORDS_BIG_ENDIAN)
12878 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
12879 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
12884 case MODE_VECTOR_FLOAT:
12885 for (i = 0, p = array; i < length; i++, p += elt_size)
12887 rtx elt = CONST_VECTOR_ELT (rtl, i);
12888 insert_float (elt, p);
12893 gcc_unreachable ();
12896 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
12901 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
12905 if (CONSTANT_P (XEXP (rtl, 0)))
12907 add_const_value_attribute (die, XEXP (rtl, 0));
12912 if (GET_CODE (rtl) == SYMBOL_REF
12913 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12916 add_AT_addr (die, DW_AT_const_value, rtl);
12917 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12921 /* In cases where an inlined instance of an inline function is passed
12922 the address of an `auto' variable (which is local to the caller) we
12923 can get a situation where the DECL_RTL of the artificial local
12924 variable (for the inlining) which acts as a stand-in for the
12925 corresponding formal parameter (of the inline function) will look
12926 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
12927 exactly a compile-time constant expression, but it isn't the address
12928 of the (artificial) local variable either. Rather, it represents the
12929 *value* which the artificial local variable always has during its
12930 lifetime. We currently have no way to represent such quasi-constant
12931 values in Dwarf, so for now we just punt and generate nothing. */
12935 /* No other kinds of rtx should be possible here. */
12936 gcc_unreachable ();
12941 /* Determine whether the evaluation of EXPR references any variables
12942 or functions which aren't otherwise used (and therefore may not be
12945 reference_to_unused (tree * tp, int * walk_subtrees,
12946 void * data ATTRIBUTE_UNUSED)
12948 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
12949 *walk_subtrees = 0;
12951 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
12952 && ! TREE_ASM_WRITTEN (*tp))
12954 /* ??? The C++ FE emits debug information for using decls, so
12955 putting gcc_unreachable here falls over. See PR31899. For now
12956 be conservative. */
12957 else if (!cgraph_global_info_ready
12958 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
12960 else if (TREE_CODE (*tp) == VAR_DECL)
12962 struct varpool_node *node = varpool_node (*tp);
12966 else if (TREE_CODE (*tp) == FUNCTION_DECL
12967 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
12969 /* The call graph machinery must have finished analyzing,
12970 optimizing and gimplifying the CU by now.
12971 So if *TP has no call graph node associated
12972 to it, it means *TP will not be emitted. */
12973 if (!cgraph_get_node (*tp))
12976 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
12982 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
12983 for use in a later add_const_value_attribute call. */
12986 rtl_for_decl_init (tree init, tree type)
12988 rtx rtl = NULL_RTX;
12990 /* If a variable is initialized with a string constant without embedded
12991 zeros, build CONST_STRING. */
12992 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
12994 tree enttype = TREE_TYPE (type);
12995 tree domain = TYPE_DOMAIN (type);
12996 enum machine_mode mode = TYPE_MODE (enttype);
12998 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
13000 && integer_zerop (TYPE_MIN_VALUE (domain))
13001 && compare_tree_int (TYPE_MAX_VALUE (domain),
13002 TREE_STRING_LENGTH (init) - 1) == 0
13003 && ((size_t) TREE_STRING_LENGTH (init)
13004 == strlen (TREE_STRING_POINTER (init)) + 1))
13005 rtl = gen_rtx_CONST_STRING (VOIDmode,
13006 ggc_strdup (TREE_STRING_POINTER (init)));
13008 /* Other aggregates, and complex values, could be represented using
13010 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
13012 /* Vectors only work if their mode is supported by the target.
13013 FIXME: generic vectors ought to work too. */
13014 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
13016 /* If the initializer is something that we know will expand into an
13017 immediate RTL constant, expand it now. We must be careful not to
13018 reference variables which won't be output. */
13019 else if (initializer_constant_valid_p (init, type)
13020 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
13022 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
13024 if (TREE_CODE (type) == VECTOR_TYPE)
13025 switch (TREE_CODE (init))
13030 if (TREE_CONSTANT (init))
13032 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
13033 bool constant_p = true;
13035 unsigned HOST_WIDE_INT ix;
13037 /* Even when ctor is constant, it might contain non-*_CST
13038 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
13039 belong into VECTOR_CST nodes. */
13040 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
13041 if (!CONSTANT_CLASS_P (value))
13043 constant_p = false;
13049 init = build_vector_from_ctor (type, elts);
13059 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
13061 /* If expand_expr returns a MEM, it wasn't immediate. */
13062 gcc_assert (!rtl || !MEM_P (rtl));
13068 /* Generate RTL for the variable DECL to represent its location. */
13071 rtl_for_decl_location (tree decl)
13075 /* Here we have to decide where we are going to say the parameter "lives"
13076 (as far as the debugger is concerned). We only have a couple of
13077 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
13079 DECL_RTL normally indicates where the parameter lives during most of the
13080 activation of the function. If optimization is enabled however, this
13081 could be either NULL or else a pseudo-reg. Both of those cases indicate
13082 that the parameter doesn't really live anywhere (as far as the code
13083 generation parts of GCC are concerned) during most of the function's
13084 activation. That will happen (for example) if the parameter is never
13085 referenced within the function.
13087 We could just generate a location descriptor here for all non-NULL
13088 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
13089 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
13090 where DECL_RTL is NULL or is a pseudo-reg.
13092 Note however that we can only get away with using DECL_INCOMING_RTL as
13093 a backup substitute for DECL_RTL in certain limited cases. In cases
13094 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
13095 we can be sure that the parameter was passed using the same type as it is
13096 declared to have within the function, and that its DECL_INCOMING_RTL
13097 points us to a place where a value of that type is passed.
13099 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
13100 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
13101 because in these cases DECL_INCOMING_RTL points us to a value of some
13102 type which is *different* from the type of the parameter itself. Thus,
13103 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
13104 such cases, the debugger would end up (for example) trying to fetch a
13105 `float' from a place which actually contains the first part of a
13106 `double'. That would lead to really incorrect and confusing
13107 output at debug-time.
13109 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
13110 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
13111 are a couple of exceptions however. On little-endian machines we can
13112 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
13113 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
13114 an integral type that is smaller than TREE_TYPE (decl). These cases arise
13115 when (on a little-endian machine) a non-prototyped function has a
13116 parameter declared to be of type `short' or `char'. In such cases,
13117 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
13118 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
13119 passed `int' value. If the debugger then uses that address to fetch
13120 a `short' or a `char' (on a little-endian machine) the result will be
13121 the correct data, so we allow for such exceptional cases below.
13123 Note that our goal here is to describe the place where the given formal
13124 parameter lives during most of the function's activation (i.e. between the
13125 end of the prologue and the start of the epilogue). We'll do that as best
13126 as we can. Note however that if the given formal parameter is modified
13127 sometime during the execution of the function, then a stack backtrace (at
13128 debug-time) will show the function as having been called with the *new*
13129 value rather than the value which was originally passed in. This happens
13130 rarely enough that it is not a major problem, but it *is* a problem, and
13131 I'd like to fix it.
13133 A future version of dwarf2out.c may generate two additional attributes for
13134 any given DW_TAG_formal_parameter DIE which will describe the "passed
13135 type" and the "passed location" for the given formal parameter in addition
13136 to the attributes we now generate to indicate the "declared type" and the
13137 "active location" for each parameter. This additional set of attributes
13138 could be used by debuggers for stack backtraces. Separately, note that
13139 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
13140 This happens (for example) for inlined-instances of inline function formal
13141 parameters which are never referenced. This really shouldn't be
13142 happening. All PARM_DECL nodes should get valid non-NULL
13143 DECL_INCOMING_RTL values. FIXME. */
13145 /* Use DECL_RTL as the "location" unless we find something better. */
13146 rtl = DECL_RTL_IF_SET (decl);
13148 /* When generating abstract instances, ignore everything except
13149 constants, symbols living in memory, and symbols living in
13150 fixed registers. */
13151 if (! reload_completed)
13154 && (CONSTANT_P (rtl)
13156 && CONSTANT_P (XEXP (rtl, 0)))
13158 && TREE_CODE (decl) == VAR_DECL
13159 && TREE_STATIC (decl))))
13161 rtl = targetm.delegitimize_address (rtl);
13166 else if (TREE_CODE (decl) == PARM_DECL)
13168 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
13170 tree declared_type = TREE_TYPE (decl);
13171 tree passed_type = DECL_ARG_TYPE (decl);
13172 enum machine_mode dmode = TYPE_MODE (declared_type);
13173 enum machine_mode pmode = TYPE_MODE (passed_type);
13175 /* This decl represents a formal parameter which was optimized out.
13176 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
13177 all cases where (rtl == NULL_RTX) just below. */
13178 if (dmode == pmode)
13179 rtl = DECL_INCOMING_RTL (decl);
13180 else if (SCALAR_INT_MODE_P (dmode)
13181 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
13182 && DECL_INCOMING_RTL (decl))
13184 rtx inc = DECL_INCOMING_RTL (decl);
13187 else if (MEM_P (inc))
13189 if (BYTES_BIG_ENDIAN)
13190 rtl = adjust_address_nv (inc, dmode,
13191 GET_MODE_SIZE (pmode)
13192 - GET_MODE_SIZE (dmode));
13199 /* If the parm was passed in registers, but lives on the stack, then
13200 make a big endian correction if the mode of the type of the
13201 parameter is not the same as the mode of the rtl. */
13202 /* ??? This is the same series of checks that are made in dbxout.c before
13203 we reach the big endian correction code there. It isn't clear if all
13204 of these checks are necessary here, but keeping them all is the safe
13206 else if (MEM_P (rtl)
13207 && XEXP (rtl, 0) != const0_rtx
13208 && ! CONSTANT_P (XEXP (rtl, 0))
13209 /* Not passed in memory. */
13210 && !MEM_P (DECL_INCOMING_RTL (decl))
13211 /* Not passed by invisible reference. */
13212 && (!REG_P (XEXP (rtl, 0))
13213 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
13214 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
13215 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
13216 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
13219 /* Big endian correction check. */
13220 && BYTES_BIG_ENDIAN
13221 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
13222 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
13225 int offset = (UNITS_PER_WORD
13226 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
13228 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13229 plus_constant (XEXP (rtl, 0), offset));
13232 else if (TREE_CODE (decl) == VAR_DECL
13235 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
13236 && BYTES_BIG_ENDIAN)
13238 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
13239 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
13241 /* If a variable is declared "register" yet is smaller than
13242 a register, then if we store the variable to memory, it
13243 looks like we're storing a register-sized value, when in
13244 fact we are not. We need to adjust the offset of the
13245 storage location to reflect the actual value's bytes,
13246 else gdb will not be able to display it. */
13248 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13249 plus_constant (XEXP (rtl, 0), rsize-dsize));
13252 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
13253 and will have been substituted directly into all expressions that use it.
13254 C does not have such a concept, but C++ and other languages do. */
13255 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
13256 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
13259 rtl = targetm.delegitimize_address (rtl);
13261 /* If we don't look past the constant pool, we risk emitting a
13262 reference to a constant pool entry that isn't referenced from
13263 code, and thus is not emitted. */
13265 rtl = avoid_constant_pool_reference (rtl);
13270 /* We need to figure out what section we should use as the base for the
13271 address ranges where a given location is valid.
13272 1. If this particular DECL has a section associated with it, use that.
13273 2. If this function has a section associated with it, use that.
13274 3. Otherwise, use the text section.
13275 XXX: If you split a variable across multiple sections, we won't notice. */
13277 static const char *
13278 secname_for_decl (const_tree decl)
13280 const char *secname;
13282 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
13284 tree sectree = DECL_SECTION_NAME (decl);
13285 secname = TREE_STRING_POINTER (sectree);
13287 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
13289 tree sectree = DECL_SECTION_NAME (current_function_decl);
13290 secname = TREE_STRING_POINTER (sectree);
13292 else if (cfun && in_cold_section_p)
13293 secname = crtl->subsections.cold_section_label;
13295 secname = text_section_label;
13300 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
13301 returned. If so, the decl for the COMMON block is returned, and the
13302 value is the offset into the common block for the symbol. */
13305 fortran_common (tree decl, HOST_WIDE_INT *value)
13307 tree val_expr, cvar;
13308 enum machine_mode mode;
13309 HOST_WIDE_INT bitsize, bitpos;
13311 int volatilep = 0, unsignedp = 0;
13313 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
13314 it does not have a value (the offset into the common area), or if it
13315 is thread local (as opposed to global) then it isn't common, and shouldn't
13316 be handled as such. */
13317 if (TREE_CODE (decl) != VAR_DECL
13318 || !TREE_PUBLIC (decl)
13319 || !TREE_STATIC (decl)
13320 || !DECL_HAS_VALUE_EXPR_P (decl)
13324 val_expr = DECL_VALUE_EXPR (decl);
13325 if (TREE_CODE (val_expr) != COMPONENT_REF)
13328 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
13329 &mode, &unsignedp, &volatilep, true);
13331 if (cvar == NULL_TREE
13332 || TREE_CODE (cvar) != VAR_DECL
13333 || DECL_ARTIFICIAL (cvar)
13334 || !TREE_PUBLIC (cvar))
13338 if (offset != NULL)
13340 if (!host_integerp (offset, 0))
13342 *value = tree_low_cst (offset, 0);
13345 *value += bitpos / BITS_PER_UNIT;
13350 /* Dereference a location expression LOC if DECL is passed by invisible
13353 static dw_loc_descr_ref
13354 loc_by_reference (dw_loc_descr_ref loc, tree decl)
13356 HOST_WIDE_INT size;
13357 enum dwarf_location_atom op;
13362 if ((TREE_CODE (decl) != PARM_DECL
13363 && TREE_CODE (decl) != RESULT_DECL
13364 && TREE_CODE (decl) != VAR_DECL)
13365 || !DECL_BY_REFERENCE (decl))
13368 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
13369 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
13370 location expression is considered to be address of a memory location,
13371 rather than the register itself. */
13372 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
13373 || loc->dw_loc_opc == DW_OP_regx)
13374 && (loc->dw_loc_next == NULL
13375 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
13376 && loc->dw_loc_next->dw_loc_next == NULL)))
13378 if (loc->dw_loc_opc == DW_OP_regx)
13380 loc->dw_loc_opc = DW_OP_bregx;
13381 loc->dw_loc_oprnd2.v.val_int = 0;
13386 = (enum dwarf_location_atom)
13387 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
13388 loc->dw_loc_oprnd1.v.val_int = 0;
13393 size = int_size_in_bytes (TREE_TYPE (decl));
13394 if (size > DWARF2_ADDR_SIZE || size == -1)
13396 else if (size == DWARF2_ADDR_SIZE)
13399 op = DW_OP_deref_size;
13400 add_loc_descr (&loc, new_loc_descr (op, size, 0));
13404 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
13405 data attribute for a variable or a parameter. We generate the
13406 DW_AT_const_value attribute only in those cases where the given variable
13407 or parameter does not have a true "location" either in memory or in a
13408 register. This can happen (for example) when a constant is passed as an
13409 actual argument in a call to an inline function. (It's possible that
13410 these things can crop up in other ways also.) Note that one type of
13411 constant value which can be passed into an inlined function is a constant
13412 pointer. This can happen for example if an actual argument in an inlined
13413 function call evaluates to a compile-time constant address. */
13416 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
13417 enum dwarf_attribute attr)
13420 dw_loc_descr_ref descr;
13421 var_loc_list *loc_list;
13422 struct var_loc_node *node;
13423 if (TREE_CODE (decl) == ERROR_MARK)
13426 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
13427 || TREE_CODE (decl) == RESULT_DECL);
13429 /* See if we possibly have multiple locations for this variable. */
13430 loc_list = lookup_decl_loc (decl);
13432 /* If it truly has multiple locations, the first and last node will
13434 if (loc_list && loc_list->first != loc_list->last)
13436 const char *endname, *secname;
13437 dw_loc_list_ref list;
13439 enum var_init_status initialized;
13441 /* Now that we know what section we are using for a base,
13442 actually construct the list of locations.
13443 The first location information is what is passed to the
13444 function that creates the location list, and the remaining
13445 locations just get added on to that list.
13446 Note that we only know the start address for a location
13447 (IE location changes), so to build the range, we use
13448 the range [current location start, next location start].
13449 This means we have to special case the last node, and generate
13450 a range of [last location start, end of function label]. */
13452 node = loc_list->first;
13453 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
13454 secname = secname_for_decl (decl);
13456 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
13457 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13459 initialized = VAR_INIT_STATUS_INITIALIZED;
13461 descr = loc_by_reference (loc_descriptor (varloc, DECL_MODE (decl),
13462 initialized), decl);
13463 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
13466 for (; node->next; node = node->next)
13467 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
13469 /* The variable has a location between NODE->LABEL and
13470 NODE->NEXT->LABEL. */
13471 enum var_init_status initialized =
13472 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13473 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
13474 descr = loc_by_reference (loc_descriptor (varloc, DECL_MODE (decl),
13475 initialized), decl);
13476 add_loc_descr_to_loc_list (&list, descr,
13477 node->label, node->next->label, secname);
13480 /* If the variable has a location at the last label
13481 it keeps its location until the end of function. */
13482 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
13484 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13485 enum var_init_status initialized =
13486 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13488 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
13489 if (!current_function_decl)
13490 endname = text_end_label;
13493 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13494 current_function_funcdef_no);
13495 endname = ggc_strdup (label_id);
13497 descr = loc_by_reference (loc_descriptor (varloc,
13501 add_loc_descr_to_loc_list (&list, descr,
13502 node->label, endname, secname);
13505 /* Finally, add the location list to the DIE, and we are done. */
13506 add_AT_loc_list (die, attr, list);
13510 /* Try to get some constant RTL for this decl, and use that as the value of
13513 rtl = rtl_for_decl_location (decl);
13514 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
13516 add_const_value_attribute (die, rtl);
13520 /* If we have tried to generate the location otherwise, and it
13521 didn't work out (we wouldn't be here if we did), and we have a one entry
13522 location list, try generating a location from that. */
13523 if (loc_list && loc_list->first)
13525 enum var_init_status status;
13526 node = loc_list->first;
13527 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13528 rtl = NOTE_VAR_LOCATION (node->var_loc_note);
13529 if (GET_CODE (rtl) == VAR_LOCATION
13530 && GET_CODE (XEXP (rtl, 1)) != PARALLEL)
13531 rtl = XEXP (XEXP (rtl, 1), 0);
13532 if (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
13534 add_const_value_attribute (die, rtl);
13537 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note),
13538 DECL_MODE (decl), status);
13541 descr = loc_by_reference (descr, decl);
13542 add_AT_location_description (die, attr, descr);
13547 /* We couldn't get any rtl, so try directly generating the location
13548 description from the tree. */
13549 descr = loc_descriptor_from_tree (decl);
13552 descr = loc_by_reference (descr, decl);
13553 add_AT_location_description (die, attr, descr);
13556 /* None of that worked, so it must not really have a location;
13557 try adding a constant value attribute from the DECL_INITIAL. */
13558 tree_add_const_value_attribute_for_decl (die, decl);
13561 /* Add VARIABLE and DIE into deferred locations list. */
13564 defer_location (tree variable, dw_die_ref die)
13566 deferred_locations entry;
13567 entry.variable = variable;
13569 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
13572 /* Helper function for tree_add_const_value_attribute. Natively encode
13573 initializer INIT into an array. Return true if successful. */
13576 native_encode_initializer (tree init, unsigned char *array, int size)
13580 if (init == NULL_TREE)
13584 switch (TREE_CODE (init))
13587 type = TREE_TYPE (init);
13588 if (TREE_CODE (type) == ARRAY_TYPE)
13590 tree enttype = TREE_TYPE (type);
13591 enum machine_mode mode = TYPE_MODE (enttype);
13593 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
13595 if (int_size_in_bytes (type) != size)
13597 if (size > TREE_STRING_LENGTH (init))
13599 memcpy (array, TREE_STRING_POINTER (init),
13600 TREE_STRING_LENGTH (init));
13601 memset (array + TREE_STRING_LENGTH (init),
13602 '\0', size - TREE_STRING_LENGTH (init));
13605 memcpy (array, TREE_STRING_POINTER (init), size);
13610 type = TREE_TYPE (init);
13611 if (int_size_in_bytes (type) != size)
13613 if (TREE_CODE (type) == ARRAY_TYPE)
13615 HOST_WIDE_INT min_index;
13616 unsigned HOST_WIDE_INT cnt;
13617 int curpos = 0, fieldsize;
13618 constructor_elt *ce;
13620 if (TYPE_DOMAIN (type) == NULL_TREE
13621 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
13624 fieldsize = int_size_in_bytes (TREE_TYPE (type));
13625 if (fieldsize <= 0)
13628 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
13629 memset (array, '\0', size);
13631 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
13634 tree val = ce->value;
13635 tree index = ce->index;
13637 if (index && TREE_CODE (index) == RANGE_EXPR)
13638 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
13641 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
13646 if (!native_encode_initializer (val, array + pos, fieldsize))
13649 curpos = pos + fieldsize;
13650 if (index && TREE_CODE (index) == RANGE_EXPR)
13652 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
13653 - tree_low_cst (TREE_OPERAND (index, 0), 0);
13657 memcpy (array + curpos, array + pos, fieldsize);
13658 curpos += fieldsize;
13661 gcc_assert (curpos <= size);
13665 else if (TREE_CODE (type) == RECORD_TYPE
13666 || TREE_CODE (type) == UNION_TYPE)
13668 tree field = NULL_TREE;
13669 unsigned HOST_WIDE_INT cnt;
13670 constructor_elt *ce;
13672 if (int_size_in_bytes (type) != size)
13675 if (TREE_CODE (type) == RECORD_TYPE)
13676 field = TYPE_FIELDS (type);
13679 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
13680 cnt++, field = field ? TREE_CHAIN (field) : 0)
13682 tree val = ce->value;
13683 int pos, fieldsize;
13685 if (ce->index != 0)
13691 if (field == NULL_TREE || DECL_BIT_FIELD (field))
13694 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
13695 && TYPE_DOMAIN (TREE_TYPE (field))
13696 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
13698 else if (DECL_SIZE_UNIT (field) == NULL_TREE
13699 || !host_integerp (DECL_SIZE_UNIT (field), 0))
13701 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
13702 pos = int_byte_position (field);
13703 gcc_assert (pos + fieldsize <= size);
13705 && !native_encode_initializer (val, array + pos, fieldsize))
13711 case VIEW_CONVERT_EXPR:
13712 case NON_LVALUE_EXPR:
13713 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
13715 return native_encode_expr (init, array, size) == size;
13719 /* Attach a DW_AT_const_value attribute to DIE. The value of the
13720 attribute is the const value T. */
13723 tree_add_const_value_attribute (dw_die_ref die, tree t)
13726 tree type = TREE_TYPE (t);
13729 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
13733 gcc_assert (!DECL_P (init));
13735 rtl = rtl_for_decl_init (init, type);
13737 add_const_value_attribute (die, rtl);
13738 /* If the host and target are sane, try harder. */
13739 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
13740 && initializer_constant_valid_p (init, type))
13742 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
13743 if (size > 0 && (int) size == size)
13745 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
13747 if (native_encode_initializer (init, array, size))
13748 add_AT_vec (die, DW_AT_const_value, size, 1, array);
13753 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
13754 attribute is the const value of T, where T is an integral constant
13755 variable with static storage duration
13756 (so it can't be a PARM_DECL or a RESULT_DECL). */
13759 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
13763 || (TREE_CODE (decl) != VAR_DECL
13764 && TREE_CODE (decl) != CONST_DECL))
13767 if (TREE_READONLY (decl)
13768 && ! TREE_THIS_VOLATILE (decl)
13769 && DECL_INITIAL (decl))
13774 tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
13777 /* Convert the CFI instructions for the current function into a
13778 location list. This is used for DW_AT_frame_base when we targeting
13779 a dwarf2 consumer that does not support the dwarf3
13780 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
13783 static dw_loc_list_ref
13784 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
13787 dw_loc_list_ref list, *list_tail;
13789 dw_cfa_location last_cfa, next_cfa;
13790 const char *start_label, *last_label, *section;
13791 dw_cfa_location remember;
13793 fde = current_fde ();
13794 gcc_assert (fde != NULL);
13796 section = secname_for_decl (current_function_decl);
13800 memset (&next_cfa, 0, sizeof (next_cfa));
13801 next_cfa.reg = INVALID_REGNUM;
13802 remember = next_cfa;
13804 start_label = fde->dw_fde_begin;
13806 /* ??? Bald assumption that the CIE opcode list does not contain
13807 advance opcodes. */
13808 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
13809 lookup_cfa_1 (cfi, &next_cfa, &remember);
13811 last_cfa = next_cfa;
13812 last_label = start_label;
13814 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
13815 switch (cfi->dw_cfi_opc)
13817 case DW_CFA_set_loc:
13818 case DW_CFA_advance_loc1:
13819 case DW_CFA_advance_loc2:
13820 case DW_CFA_advance_loc4:
13821 if (!cfa_equal_p (&last_cfa, &next_cfa))
13823 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
13824 start_label, last_label, section,
13827 list_tail = &(*list_tail)->dw_loc_next;
13828 last_cfa = next_cfa;
13829 start_label = last_label;
13831 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
13834 case DW_CFA_advance_loc:
13835 /* The encoding is complex enough that we should never emit this. */
13836 gcc_unreachable ();
13839 lookup_cfa_1 (cfi, &next_cfa, &remember);
13843 if (!cfa_equal_p (&last_cfa, &next_cfa))
13845 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
13846 start_label, last_label, section,
13848 list_tail = &(*list_tail)->dw_loc_next;
13849 start_label = last_label;
13851 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
13852 start_label, fde->dw_fde_end, section,
13858 /* Compute a displacement from the "steady-state frame pointer" to the
13859 frame base (often the same as the CFA), and store it in
13860 frame_pointer_fb_offset. OFFSET is added to the displacement
13861 before the latter is negated. */
13864 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
13868 #ifdef FRAME_POINTER_CFA_OFFSET
13869 reg = frame_pointer_rtx;
13870 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
13872 reg = arg_pointer_rtx;
13873 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
13876 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13877 if (GET_CODE (elim) == PLUS)
13879 offset += INTVAL (XEXP (elim, 1));
13880 elim = XEXP (elim, 0);
13883 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13884 && (elim == hard_frame_pointer_rtx
13885 || elim == stack_pointer_rtx))
13886 || elim == (frame_pointer_needed
13887 ? hard_frame_pointer_rtx
13888 : stack_pointer_rtx));
13890 frame_pointer_fb_offset = -offset;
13893 /* Generate a DW_AT_name attribute given some string value to be included as
13894 the value of the attribute. */
13897 add_name_attribute (dw_die_ref die, const char *name_string)
13899 if (name_string != NULL && *name_string != 0)
13901 if (demangle_name_func)
13902 name_string = (*demangle_name_func) (name_string);
13904 add_AT_string (die, DW_AT_name, name_string);
13908 /* Generate a DW_AT_comp_dir attribute for DIE. */
13911 add_comp_dir_attribute (dw_die_ref die)
13913 const char *wd = get_src_pwd ();
13919 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
13923 wdlen = strlen (wd);
13924 wd1 = GGC_NEWVEC (char, wdlen + 2);
13926 wd1 [wdlen] = DIR_SEPARATOR;
13927 wd1 [wdlen + 1] = 0;
13931 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
13934 /* Given a tree node describing an array bound (either lower or upper) output
13935 a representation for that bound. */
13938 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
13940 switch (TREE_CODE (bound))
13945 /* All fixed-bounds are represented by INTEGER_CST nodes. */
13947 if (! host_integerp (bound, 0)
13948 || (bound_attr == DW_AT_lower_bound
13949 && (((is_c_family () || is_java ()) && integer_zerop (bound))
13950 || (is_fortran () && integer_onep (bound)))))
13951 /* Use the default. */
13954 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
13958 case VIEW_CONVERT_EXPR:
13959 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
13969 dw_die_ref decl_die = lookup_decl_die (bound);
13970 dw_loc_descr_ref loc;
13972 /* ??? Can this happen, or should the variable have been bound
13973 first? Probably it can, since I imagine that we try to create
13974 the types of parameters in the order in which they exist in
13975 the list, and won't have created a forward reference to a
13976 later parameter. */
13977 if (decl_die != NULL)
13978 add_AT_die_ref (subrange_die, bound_attr, decl_die);
13981 loc = loc_descriptor_from_tree_1 (bound, 0);
13982 add_AT_location_description (subrange_die, bound_attr, loc);
13989 /* Otherwise try to create a stack operation procedure to
13990 evaluate the value of the array bound. */
13992 dw_die_ref ctx, decl_die;
13993 dw_loc_descr_ref loc;
13995 loc = loc_descriptor_from_tree (bound);
13999 if (current_function_decl == 0)
14000 ctx = comp_unit_die;
14002 ctx = lookup_decl_die (current_function_decl);
14004 decl_die = new_die (DW_TAG_variable, ctx, bound);
14005 add_AT_flag (decl_die, DW_AT_artificial, 1);
14006 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
14007 add_AT_loc (decl_die, DW_AT_location, loc);
14009 add_AT_die_ref (subrange_die, bound_attr, decl_die);
14015 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
14016 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
14017 Note that the block of subscript information for an array type also
14018 includes information about the element type of the given array type. */
14021 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
14023 unsigned dimension_number;
14025 dw_die_ref subrange_die;
14027 for (dimension_number = 0;
14028 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
14029 type = TREE_TYPE (type), dimension_number++)
14031 tree domain = TYPE_DOMAIN (type);
14033 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
14036 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
14037 and (in GNU C only) variable bounds. Handle all three forms
14039 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
14042 /* We have an array type with specified bounds. */
14043 lower = TYPE_MIN_VALUE (domain);
14044 upper = TYPE_MAX_VALUE (domain);
14046 /* Define the index type. */
14047 if (TREE_TYPE (domain))
14049 /* ??? This is probably an Ada unnamed subrange type. Ignore the
14050 TREE_TYPE field. We can't emit debug info for this
14051 because it is an unnamed integral type. */
14052 if (TREE_CODE (domain) == INTEGER_TYPE
14053 && TYPE_NAME (domain) == NULL_TREE
14054 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
14055 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
14058 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
14062 /* ??? If upper is NULL, the array has unspecified length,
14063 but it does have a lower bound. This happens with Fortran
14065 Since the debugger is definitely going to need to know N
14066 to produce useful results, go ahead and output the lower
14067 bound solo, and hope the debugger can cope. */
14069 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
14071 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
14074 /* Otherwise we have an array type with an unspecified length. The
14075 DWARF-2 spec does not say how to handle this; let's just leave out the
14081 add_byte_size_attribute (dw_die_ref die, tree tree_node)
14085 switch (TREE_CODE (tree_node))
14090 case ENUMERAL_TYPE:
14093 case QUAL_UNION_TYPE:
14094 size = int_size_in_bytes (tree_node);
14097 /* For a data member of a struct or union, the DW_AT_byte_size is
14098 generally given as the number of bytes normally allocated for an
14099 object of the *declared* type of the member itself. This is true
14100 even for bit-fields. */
14101 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
14104 gcc_unreachable ();
14107 /* Note that `size' might be -1 when we get to this point. If it is, that
14108 indicates that the byte size of the entity in question is variable. We
14109 have no good way of expressing this fact in Dwarf at the present time,
14110 so just let the -1 pass on through. */
14111 add_AT_unsigned (die, DW_AT_byte_size, size);
14114 /* For a FIELD_DECL node which represents a bit-field, output an attribute
14115 which specifies the distance in bits from the highest order bit of the
14116 "containing object" for the bit-field to the highest order bit of the
14119 For any given bit-field, the "containing object" is a hypothetical object
14120 (of some integral or enum type) within which the given bit-field lives. The
14121 type of this hypothetical "containing object" is always the same as the
14122 declared type of the individual bit-field itself. The determination of the
14123 exact location of the "containing object" for a bit-field is rather
14124 complicated. It's handled by the `field_byte_offset' function (above).
14126 Note that it is the size (in bytes) of the hypothetical "containing object"
14127 which will be given in the DW_AT_byte_size attribute for this bit-field.
14128 (See `byte_size_attribute' above). */
14131 add_bit_offset_attribute (dw_die_ref die, tree decl)
14133 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
14134 tree type = DECL_BIT_FIELD_TYPE (decl);
14135 HOST_WIDE_INT bitpos_int;
14136 HOST_WIDE_INT highest_order_object_bit_offset;
14137 HOST_WIDE_INT highest_order_field_bit_offset;
14138 HOST_WIDE_INT unsigned bit_offset;
14140 /* Must be a field and a bit field. */
14141 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
14143 /* We can't yet handle bit-fields whose offsets are variable, so if we
14144 encounter such things, just return without generating any attribute
14145 whatsoever. Likewise for variable or too large size. */
14146 if (! host_integerp (bit_position (decl), 0)
14147 || ! host_integerp (DECL_SIZE (decl), 1))
14150 bitpos_int = int_bit_position (decl);
14152 /* Note that the bit offset is always the distance (in bits) from the
14153 highest-order bit of the "containing object" to the highest-order bit of
14154 the bit-field itself. Since the "high-order end" of any object or field
14155 is different on big-endian and little-endian machines, the computation
14156 below must take account of these differences. */
14157 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
14158 highest_order_field_bit_offset = bitpos_int;
14160 if (! BYTES_BIG_ENDIAN)
14162 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
14163 highest_order_object_bit_offset += simple_type_size_in_bits (type);
14167 = (! BYTES_BIG_ENDIAN
14168 ? highest_order_object_bit_offset - highest_order_field_bit_offset
14169 : highest_order_field_bit_offset - highest_order_object_bit_offset);
14171 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
14174 /* For a FIELD_DECL node which represents a bit field, output an attribute
14175 which specifies the length in bits of the given field. */
14178 add_bit_size_attribute (dw_die_ref die, tree decl)
14180 /* Must be a field and a bit field. */
14181 gcc_assert (TREE_CODE (decl) == FIELD_DECL
14182 && DECL_BIT_FIELD_TYPE (decl));
14184 if (host_integerp (DECL_SIZE (decl), 1))
14185 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
14188 /* If the compiled language is ANSI C, then add a 'prototyped'
14189 attribute, if arg types are given for the parameters of a function. */
14192 add_prototyped_attribute (dw_die_ref die, tree func_type)
14194 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
14195 && TYPE_ARG_TYPES (func_type) != NULL)
14196 add_AT_flag (die, DW_AT_prototyped, 1);
14199 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
14200 by looking in either the type declaration or object declaration
14203 static inline dw_die_ref
14204 add_abstract_origin_attribute (dw_die_ref die, tree origin)
14206 dw_die_ref origin_die = NULL;
14208 if (TREE_CODE (origin) != FUNCTION_DECL)
14210 /* We may have gotten separated from the block for the inlined
14211 function, if we're in an exception handler or some such; make
14212 sure that the abstract function has been written out.
14214 Doing this for nested functions is wrong, however; functions are
14215 distinct units, and our context might not even be inline. */
14219 fn = TYPE_STUB_DECL (fn);
14221 fn = decl_function_context (fn);
14223 dwarf2out_abstract_function (fn);
14226 if (DECL_P (origin))
14227 origin_die = lookup_decl_die (origin);
14228 else if (TYPE_P (origin))
14229 origin_die = lookup_type_die (origin);
14231 /* XXX: Functions that are never lowered don't always have correct block
14232 trees (in the case of java, they simply have no block tree, in some other
14233 languages). For these functions, there is nothing we can really do to
14234 output correct debug info for inlined functions in all cases. Rather
14235 than die, we'll just produce deficient debug info now, in that we will
14236 have variables without a proper abstract origin. In the future, when all
14237 functions are lowered, we should re-add a gcc_assert (origin_die)
14241 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
14245 /* We do not currently support the pure_virtual attribute. */
14248 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
14250 if (DECL_VINDEX (func_decl))
14252 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14254 if (host_integerp (DECL_VINDEX (func_decl), 0))
14255 add_AT_loc (die, DW_AT_vtable_elem_location,
14256 new_loc_descr (DW_OP_constu,
14257 tree_low_cst (DECL_VINDEX (func_decl), 0),
14260 /* GNU extension: Record what type this method came from originally. */
14261 if (debug_info_level > DINFO_LEVEL_TERSE)
14262 add_AT_die_ref (die, DW_AT_containing_type,
14263 lookup_type_die (DECL_CONTEXT (func_decl)));
14267 /* Add source coordinate attributes for the given decl. */
14270 add_src_coords_attributes (dw_die_ref die, tree decl)
14272 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14274 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
14275 add_AT_unsigned (die, DW_AT_decl_line, s.line);
14278 /* Add a DW_AT_name attribute and source coordinate attribute for the
14279 given decl, but only if it actually has a name. */
14282 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
14286 decl_name = DECL_NAME (decl);
14287 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
14289 add_name_attribute (die, dwarf2_name (decl, 0));
14290 if (! DECL_ARTIFICIAL (decl))
14291 add_src_coords_attributes (die, decl);
14293 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
14294 && TREE_PUBLIC (decl)
14295 && !DECL_ABSTRACT (decl)
14296 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
14299 /* Defer until we have an assembler name set. */
14300 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
14302 limbo_die_node *asm_name;
14304 asm_name = GGC_CNEW (limbo_die_node);
14305 asm_name->die = die;
14306 asm_name->created_for = decl;
14307 asm_name->next = deferred_asm_name;
14308 deferred_asm_name = asm_name;
14310 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
14311 add_AT_string (die, DW_AT_MIPS_linkage_name,
14312 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
14316 #ifdef VMS_DEBUGGING_INFO
14317 /* Get the function's name, as described by its RTL. This may be different
14318 from the DECL_NAME name used in the source file. */
14319 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
14321 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
14322 XEXP (DECL_RTL (decl), 0));
14323 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
14328 /* Push a new declaration scope. */
14331 push_decl_scope (tree scope)
14333 VEC_safe_push (tree, gc, decl_scope_table, scope);
14336 /* Pop a declaration scope. */
14339 pop_decl_scope (void)
14341 VEC_pop (tree, decl_scope_table);
14344 /* Return the DIE for the scope that immediately contains this type.
14345 Non-named types get global scope. Named types nested in other
14346 types get their containing scope if it's open, or global scope
14347 otherwise. All other types (i.e. function-local named types) get
14348 the current active scope. */
14351 scope_die_for (tree t, dw_die_ref context_die)
14353 dw_die_ref scope_die = NULL;
14354 tree containing_scope;
14357 /* Non-types always go in the current scope. */
14358 gcc_assert (TYPE_P (t));
14360 containing_scope = TYPE_CONTEXT (t);
14362 /* Use the containing namespace if it was passed in (for a declaration). */
14363 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
14365 if (context_die == lookup_decl_die (containing_scope))
14368 containing_scope = NULL_TREE;
14371 /* Ignore function type "scopes" from the C frontend. They mean that
14372 a tagged type is local to a parmlist of a function declarator, but
14373 that isn't useful to DWARF. */
14374 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
14375 containing_scope = NULL_TREE;
14377 if (containing_scope == NULL_TREE)
14378 scope_die = comp_unit_die;
14379 else if (TYPE_P (containing_scope))
14381 /* For types, we can just look up the appropriate DIE. But
14382 first we check to see if we're in the middle of emitting it
14383 so we know where the new DIE should go. */
14384 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
14385 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
14390 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
14391 || TREE_ASM_WRITTEN (containing_scope));
14393 /* If none of the current dies are suitable, we get file scope. */
14394 scope_die = comp_unit_die;
14397 scope_die = lookup_type_die (containing_scope);
14400 scope_die = context_die;
14405 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
14408 local_scope_p (dw_die_ref context_die)
14410 for (; context_die; context_die = context_die->die_parent)
14411 if (context_die->die_tag == DW_TAG_inlined_subroutine
14412 || context_die->die_tag == DW_TAG_subprogram)
14418 /* Returns nonzero if CONTEXT_DIE is a class. */
14421 class_scope_p (dw_die_ref context_die)
14423 return (context_die
14424 && (context_die->die_tag == DW_TAG_structure_type
14425 || context_die->die_tag == DW_TAG_class_type
14426 || context_die->die_tag == DW_TAG_interface_type
14427 || context_die->die_tag == DW_TAG_union_type));
14430 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
14431 whether or not to treat a DIE in this context as a declaration. */
14434 class_or_namespace_scope_p (dw_die_ref context_die)
14436 return (class_scope_p (context_die)
14437 || (context_die && context_die->die_tag == DW_TAG_namespace));
14440 /* Many forms of DIEs require a "type description" attribute. This
14441 routine locates the proper "type descriptor" die for the type given
14442 by 'type', and adds a DW_AT_type attribute below the given die. */
14445 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
14446 int decl_volatile, dw_die_ref context_die)
14448 enum tree_code code = TREE_CODE (type);
14449 dw_die_ref type_die = NULL;
14451 /* ??? If this type is an unnamed subrange type of an integral, floating-point
14452 or fixed-point type, use the inner type. This is because we have no
14453 support for unnamed types in base_type_die. This can happen if this is
14454 an Ada subrange type. Correct solution is emit a subrange type die. */
14455 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
14456 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
14457 type = TREE_TYPE (type), code = TREE_CODE (type);
14459 if (code == ERROR_MARK
14460 /* Handle a special case. For functions whose return type is void, we
14461 generate *no* type attribute. (Note that no object may have type
14462 `void', so this only applies to function return types). */
14463 || code == VOID_TYPE)
14466 type_die = modified_type_die (type,
14467 decl_const || TYPE_READONLY (type),
14468 decl_volatile || TYPE_VOLATILE (type),
14471 if (type_die != NULL)
14472 add_AT_die_ref (object_die, DW_AT_type, type_die);
14475 /* Given an object die, add the calling convention attribute for the
14476 function call type. */
14478 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
14480 enum dwarf_calling_convention value = DW_CC_normal;
14482 value = ((enum dwarf_calling_convention)
14483 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
14485 /* DWARF doesn't provide a way to identify a program's source-level
14486 entry point. DW_AT_calling_convention attributes are only meant
14487 to describe functions' calling conventions. However, lacking a
14488 better way to signal the Fortran main program, we use this for the
14489 time being, following existing custom. */
14491 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
14492 value = DW_CC_program;
14494 /* Only add the attribute if the backend requests it, and
14495 is not DW_CC_normal. */
14496 if (value && (value != DW_CC_normal))
14497 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
14500 /* Given a tree pointer to a struct, class, union, or enum type node, return
14501 a pointer to the (string) tag name for the given type, or zero if the type
14502 was declared without a tag. */
14504 static const char *
14505 type_tag (const_tree type)
14507 const char *name = 0;
14509 if (TYPE_NAME (type) != 0)
14513 /* Find the IDENTIFIER_NODE for the type name. */
14514 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
14515 t = TYPE_NAME (type);
14517 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
14518 a TYPE_DECL node, regardless of whether or not a `typedef' was
14520 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14521 && ! DECL_IGNORED_P (TYPE_NAME (type)))
14523 /* We want to be extra verbose. Don't call dwarf_name if
14524 DECL_NAME isn't set. The default hook for decl_printable_name
14525 doesn't like that, and in this context it's correct to return
14526 0, instead of "<anonymous>" or the like. */
14527 if (DECL_NAME (TYPE_NAME (type)))
14528 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
14531 /* Now get the name as a string, or invent one. */
14532 if (!name && t != 0)
14533 name = IDENTIFIER_POINTER (t);
14536 return (name == 0 || *name == '\0') ? 0 : name;
14539 /* Return the type associated with a data member, make a special check
14540 for bit field types. */
14543 member_declared_type (const_tree member)
14545 return (DECL_BIT_FIELD_TYPE (member)
14546 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
14549 /* Get the decl's label, as described by its RTL. This may be different
14550 from the DECL_NAME name used in the source file. */
14553 static const char *
14554 decl_start_label (tree decl)
14557 const char *fnname;
14559 x = DECL_RTL (decl);
14560 gcc_assert (MEM_P (x));
14563 gcc_assert (GET_CODE (x) == SYMBOL_REF);
14565 fnname = XSTR (x, 0);
14570 /* These routines generate the internal representation of the DIE's for
14571 the compilation unit. Debugging information is collected by walking
14572 the declaration trees passed in from dwarf2out_decl(). */
14575 gen_array_type_die (tree type, dw_die_ref context_die)
14577 dw_die_ref scope_die = scope_die_for (type, context_die);
14578 dw_die_ref array_die;
14580 /* GNU compilers represent multidimensional array types as sequences of one
14581 dimensional array types whose element types are themselves array types.
14582 We sometimes squish that down to a single array_type DIE with multiple
14583 subscripts in the Dwarf debugging info. The draft Dwarf specification
14584 say that we are allowed to do this kind of compression in C, because
14585 there is no difference between an array of arrays and a multidimensional
14586 array. We don't do this for Ada to remain as close as possible to the
14587 actual representation, which is especially important against the language
14588 flexibilty wrt arrays of variable size. */
14590 bool collapse_nested_arrays = !is_ada ();
14593 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
14594 DW_TAG_string_type doesn't have DW_AT_type attribute). */
14595 if (TYPE_STRING_FLAG (type)
14596 && TREE_CODE (type) == ARRAY_TYPE
14598 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
14600 HOST_WIDE_INT size;
14602 array_die = new_die (DW_TAG_string_type, scope_die, type);
14603 add_name_attribute (array_die, type_tag (type));
14604 equate_type_number_to_die (type, array_die);
14605 size = int_size_in_bytes (type);
14607 add_AT_unsigned (array_die, DW_AT_byte_size, size);
14608 else if (TYPE_DOMAIN (type) != NULL_TREE
14609 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
14610 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
14612 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
14613 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
14615 size = int_size_in_bytes (TREE_TYPE (szdecl));
14616 if (loc && size > 0)
14618 add_AT_loc (array_die, DW_AT_string_length, loc);
14619 if (size != DWARF2_ADDR_SIZE)
14620 add_AT_unsigned (array_die, DW_AT_byte_size, size);
14626 /* ??? The SGI dwarf reader fails for array of array of enum types
14627 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
14628 array type comes before the outer array type. We thus call gen_type_die
14629 before we new_die and must prevent nested array types collapsing for this
14632 #ifdef MIPS_DEBUGGING_INFO
14633 gen_type_die (TREE_TYPE (type), context_die);
14634 collapse_nested_arrays = false;
14637 array_die = new_die (DW_TAG_array_type, scope_die, type);
14638 add_name_attribute (array_die, type_tag (type));
14639 equate_type_number_to_die (type, array_die);
14641 if (TREE_CODE (type) == VECTOR_TYPE)
14643 /* The frontend feeds us a representation for the vector as a struct
14644 containing an array. Pull out the array type. */
14645 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
14646 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
14649 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
14651 && TREE_CODE (type) == ARRAY_TYPE
14652 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
14653 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
14654 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
14657 /* We default the array ordering. SDB will probably do
14658 the right things even if DW_AT_ordering is not present. It's not even
14659 an issue until we start to get into multidimensional arrays anyway. If
14660 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
14661 then we'll have to put the DW_AT_ordering attribute back in. (But if
14662 and when we find out that we need to put these in, we will only do so
14663 for multidimensional arrays. */
14664 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
14667 #ifdef MIPS_DEBUGGING_INFO
14668 /* The SGI compilers handle arrays of unknown bound by setting
14669 AT_declaration and not emitting any subrange DIEs. */
14670 if (! TYPE_DOMAIN (type))
14671 add_AT_flag (array_die, DW_AT_declaration, 1);
14674 add_subscript_info (array_die, type, collapse_nested_arrays);
14676 /* Add representation of the type of the elements of this array type and
14677 emit the corresponding DIE if we haven't done it already. */
14678 element_type = TREE_TYPE (type);
14679 if (collapse_nested_arrays)
14680 while (TREE_CODE (element_type) == ARRAY_TYPE)
14682 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
14684 element_type = TREE_TYPE (element_type);
14687 #ifndef MIPS_DEBUGGING_INFO
14688 gen_type_die (element_type, context_die);
14691 add_type_attribute (array_die, element_type, 0, 0, context_die);
14693 if (get_AT (array_die, DW_AT_name))
14694 add_pubtype (type, array_die);
14697 static dw_loc_descr_ref
14698 descr_info_loc (tree val, tree base_decl)
14700 HOST_WIDE_INT size;
14701 dw_loc_descr_ref loc, loc2;
14702 enum dwarf_location_atom op;
14704 if (val == base_decl)
14705 return new_loc_descr (DW_OP_push_object_address, 0, 0);
14707 switch (TREE_CODE (val))
14710 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14712 return loc_descriptor_from_tree_1 (val, 0);
14714 if (host_integerp (val, 0))
14715 return int_loc_descriptor (tree_low_cst (val, 0));
14718 size = int_size_in_bytes (TREE_TYPE (val));
14721 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14724 if (size == DWARF2_ADDR_SIZE)
14725 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
14727 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
14729 case POINTER_PLUS_EXPR:
14731 if (host_integerp (TREE_OPERAND (val, 1), 1)
14732 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
14735 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14738 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
14744 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14747 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
14750 add_loc_descr (&loc, loc2);
14751 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
14773 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
14774 tree val, tree base_decl)
14776 dw_loc_descr_ref loc;
14778 if (host_integerp (val, 0))
14780 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
14784 loc = descr_info_loc (val, base_decl);
14788 add_AT_loc (die, attr, loc);
14791 /* This routine generates DIE for array with hidden descriptor, details
14792 are filled into *info by a langhook. */
14795 gen_descr_array_type_die (tree type, struct array_descr_info *info,
14796 dw_die_ref context_die)
14798 dw_die_ref scope_die = scope_die_for (type, context_die);
14799 dw_die_ref array_die;
14802 array_die = new_die (DW_TAG_array_type, scope_die, type);
14803 add_name_attribute (array_die, type_tag (type));
14804 equate_type_number_to_die (type, array_die);
14806 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
14808 && info->ndimensions >= 2)
14809 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
14811 if (info->data_location)
14812 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
14814 if (info->associated)
14815 add_descr_info_field (array_die, DW_AT_associated, info->associated,
14817 if (info->allocated)
14818 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
14821 for (dim = 0; dim < info->ndimensions; dim++)
14823 dw_die_ref subrange_die
14824 = new_die (DW_TAG_subrange_type, array_die, NULL);
14826 if (info->dimen[dim].lower_bound)
14828 /* If it is the default value, omit it. */
14829 if ((is_c_family () || is_java ())
14830 && integer_zerop (info->dimen[dim].lower_bound))
14832 else if (is_fortran ()
14833 && integer_onep (info->dimen[dim].lower_bound))
14836 add_descr_info_field (subrange_die, DW_AT_lower_bound,
14837 info->dimen[dim].lower_bound,
14840 if (info->dimen[dim].upper_bound)
14841 add_descr_info_field (subrange_die, DW_AT_upper_bound,
14842 info->dimen[dim].upper_bound,
14844 if (info->dimen[dim].stride)
14845 add_descr_info_field (subrange_die, DW_AT_byte_stride,
14846 info->dimen[dim].stride,
14850 gen_type_die (info->element_type, context_die);
14851 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
14853 if (get_AT (array_die, DW_AT_name))
14854 add_pubtype (type, array_die);
14859 gen_entry_point_die (tree decl, dw_die_ref context_die)
14861 tree origin = decl_ultimate_origin (decl);
14862 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
14864 if (origin != NULL)
14865 add_abstract_origin_attribute (decl_die, origin);
14868 add_name_and_src_coords_attributes (decl_die, decl);
14869 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
14870 0, 0, context_die);
14873 if (DECL_ABSTRACT (decl))
14874 equate_decl_number_to_die (decl, decl_die);
14876 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
14880 /* Walk through the list of incomplete types again, trying once more to
14881 emit full debugging info for them. */
14884 retry_incomplete_types (void)
14888 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
14889 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
14892 /* Determine what tag to use for a record type. */
14894 static enum dwarf_tag
14895 record_type_tag (tree type)
14897 if (! lang_hooks.types.classify_record)
14898 return DW_TAG_structure_type;
14900 switch (lang_hooks.types.classify_record (type))
14902 case RECORD_IS_STRUCT:
14903 return DW_TAG_structure_type;
14905 case RECORD_IS_CLASS:
14906 return DW_TAG_class_type;
14908 case RECORD_IS_INTERFACE:
14909 return DW_TAG_interface_type;
14912 gcc_unreachable ();
14916 /* Generate a DIE to represent an enumeration type. Note that these DIEs
14917 include all of the information about the enumeration values also. Each
14918 enumerated type name/value is listed as a child of the enumerated type
14922 gen_enumeration_type_die (tree type, dw_die_ref context_die)
14924 dw_die_ref type_die = lookup_type_die (type);
14926 if (type_die == NULL)
14928 type_die = new_die (DW_TAG_enumeration_type,
14929 scope_die_for (type, context_die), type);
14930 equate_type_number_to_die (type, type_die);
14931 add_name_attribute (type_die, type_tag (type));
14933 else if (! TYPE_SIZE (type))
14936 remove_AT (type_die, DW_AT_declaration);
14938 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
14939 given enum type is incomplete, do not generate the DW_AT_byte_size
14940 attribute or the DW_AT_element_list attribute. */
14941 if (TYPE_SIZE (type))
14945 TREE_ASM_WRITTEN (type) = 1;
14946 add_byte_size_attribute (type_die, type);
14947 if (TYPE_STUB_DECL (type) != NULL_TREE)
14948 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14950 /* If the first reference to this type was as the return type of an
14951 inline function, then it may not have a parent. Fix this now. */
14952 if (type_die->die_parent == NULL)
14953 add_child_die (scope_die_for (type, context_die), type_die);
14955 for (link = TYPE_VALUES (type);
14956 link != NULL; link = TREE_CHAIN (link))
14958 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
14959 tree value = TREE_VALUE (link);
14961 add_name_attribute (enum_die,
14962 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
14964 if (TREE_CODE (value) == CONST_DECL)
14965 value = DECL_INITIAL (value);
14967 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
14968 /* DWARF2 does not provide a way of indicating whether or
14969 not enumeration constants are signed or unsigned. GDB
14970 always assumes the values are signed, so we output all
14971 values as if they were signed. That means that
14972 enumeration constants with very large unsigned values
14973 will appear to have negative values in the debugger. */
14974 add_AT_int (enum_die, DW_AT_const_value,
14975 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
14979 add_AT_flag (type_die, DW_AT_declaration, 1);
14981 if (get_AT (type_die, DW_AT_name))
14982 add_pubtype (type, type_die);
14987 /* Generate a DIE to represent either a real live formal parameter decl or to
14988 represent just the type of some formal parameter position in some function
14991 Note that this routine is a bit unusual because its argument may be a
14992 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
14993 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
14994 node. If it's the former then this function is being called to output a
14995 DIE to represent a formal parameter object (or some inlining thereof). If
14996 it's the latter, then this function is only being called to output a
14997 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
14998 argument type of some subprogram type. */
15001 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
15003 tree node_or_origin = node ? node : origin;
15004 dw_die_ref parm_die
15005 = new_die (DW_TAG_formal_parameter, context_die, node);
15007 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
15009 case tcc_declaration:
15011 origin = decl_ultimate_origin (node);
15012 if (origin != NULL)
15013 add_abstract_origin_attribute (parm_die, origin);
15016 tree type = TREE_TYPE (node);
15017 add_name_and_src_coords_attributes (parm_die, node);
15018 if (DECL_BY_REFERENCE (node))
15019 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
15022 add_type_attribute (parm_die, type,
15023 TREE_READONLY (node),
15024 TREE_THIS_VOLATILE (node),
15026 if (DECL_ARTIFICIAL (node))
15027 add_AT_flag (parm_die, DW_AT_artificial, 1);
15030 if (node && node != origin)
15031 equate_decl_number_to_die (node, parm_die);
15032 if (! DECL_ABSTRACT (node_or_origin))
15033 add_location_or_const_value_attribute (parm_die, node_or_origin,
15039 /* We were called with some kind of a ..._TYPE node. */
15040 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
15044 gcc_unreachable ();
15050 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
15051 at the end of an (ANSI prototyped) formal parameters list. */
15054 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
15056 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
15059 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
15060 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
15061 parameters as specified in some function type specification (except for
15062 those which appear as part of a function *definition*). */
15065 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
15068 tree formal_type = NULL;
15069 tree first_parm_type;
15072 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
15074 arg = DECL_ARGUMENTS (function_or_method_type);
15075 function_or_method_type = TREE_TYPE (function_or_method_type);
15080 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
15082 /* Make our first pass over the list of formal parameter types and output a
15083 DW_TAG_formal_parameter DIE for each one. */
15084 for (link = first_parm_type; link; )
15086 dw_die_ref parm_die;
15088 formal_type = TREE_VALUE (link);
15089 if (formal_type == void_type_node)
15092 /* Output a (nameless) DIE to represent the formal parameter itself. */
15093 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
15094 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
15095 && link == first_parm_type)
15096 || (arg && DECL_ARTIFICIAL (arg)))
15097 add_AT_flag (parm_die, DW_AT_artificial, 1);
15099 link = TREE_CHAIN (link);
15101 arg = TREE_CHAIN (arg);
15104 /* If this function type has an ellipsis, add a
15105 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
15106 if (formal_type != void_type_node)
15107 gen_unspecified_parameters_die (function_or_method_type, context_die);
15109 /* Make our second (and final) pass over the list of formal parameter types
15110 and output DIEs to represent those types (as necessary). */
15111 for (link = TYPE_ARG_TYPES (function_or_method_type);
15112 link && TREE_VALUE (link);
15113 link = TREE_CHAIN (link))
15114 gen_type_die (TREE_VALUE (link), context_die);
15117 /* We want to generate the DIE for TYPE so that we can generate the
15118 die for MEMBER, which has been defined; we will need to refer back
15119 to the member declaration nested within TYPE. If we're trying to
15120 generate minimal debug info for TYPE, processing TYPE won't do the
15121 trick; we need to attach the member declaration by hand. */
15124 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
15126 gen_type_die (type, context_die);
15128 /* If we're trying to avoid duplicate debug info, we may not have
15129 emitted the member decl for this function. Emit it now. */
15130 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
15131 && ! lookup_decl_die (member))
15133 dw_die_ref type_die;
15134 gcc_assert (!decl_ultimate_origin (member));
15136 push_decl_scope (type);
15137 type_die = lookup_type_die (type);
15138 if (TREE_CODE (member) == FUNCTION_DECL)
15139 gen_subprogram_die (member, type_die);
15140 else if (TREE_CODE (member) == FIELD_DECL)
15142 /* Ignore the nameless fields that are used to skip bits but handle
15143 C++ anonymous unions and structs. */
15144 if (DECL_NAME (member) != NULL_TREE
15145 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
15146 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
15148 gen_type_die (member_declared_type (member), type_die);
15149 gen_field_die (member, type_die);
15153 gen_variable_die (member, NULL_TREE, type_die);
15159 /* Generate the DWARF2 info for the "abstract" instance of a function which we
15160 may later generate inlined and/or out-of-line instances of. */
15163 dwarf2out_abstract_function (tree decl)
15165 dw_die_ref old_die;
15168 int was_abstract = DECL_ABSTRACT (decl);
15170 /* Make sure we have the actual abstract inline, not a clone. */
15171 decl = DECL_ORIGIN (decl);
15172 htab_empty (decl_loc_table);
15174 old_die = lookup_decl_die (decl);
15175 if (old_die && get_AT (old_die, DW_AT_inline))
15176 /* We've already generated the abstract instance. */
15179 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
15180 we don't get confused by DECL_ABSTRACT. */
15181 if (debug_info_level > DINFO_LEVEL_TERSE)
15183 context = decl_class_context (decl);
15185 gen_type_die_for_member
15186 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
15189 /* Pretend we've just finished compiling this function. */
15190 save_fn = current_function_decl;
15191 current_function_decl = decl;
15192 push_cfun (DECL_STRUCT_FUNCTION (decl));
15194 set_decl_abstract_flags (decl, 1);
15195 dwarf2out_decl (decl);
15196 if (! was_abstract)
15197 set_decl_abstract_flags (decl, 0);
15199 current_function_decl = save_fn;
15203 /* Helper function of premark_used_types() which gets called through
15204 htab_traverse_resize().
15206 Marks the DIE of a given type in *SLOT as perennial, so it never gets
15207 marked as unused by prune_unused_types. */
15209 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
15214 type = (tree) *slot;
15215 die = lookup_type_die (type);
15217 die->die_perennial_p = 1;
15221 /* Mark all members of used_types_hash as perennial. */
15223 premark_used_types (void)
15225 if (cfun && cfun->used_types_hash)
15226 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
15229 /* Generate a DIE to represent a declared function (either file-scope or
15233 gen_subprogram_die (tree decl, dw_die_ref context_die)
15235 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15236 tree origin = decl_ultimate_origin (decl);
15237 dw_die_ref subr_die;
15240 dw_die_ref old_die = lookup_decl_die (decl);
15241 int declaration = (current_function_decl != decl
15242 || class_or_namespace_scope_p (context_die));
15244 premark_used_types ();
15246 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
15247 started to generate the abstract instance of an inline, decided to output
15248 its containing class, and proceeded to emit the declaration of the inline
15249 from the member list for the class. If so, DECLARATION takes priority;
15250 we'll get back to the abstract instance when done with the class. */
15252 /* The class-scope declaration DIE must be the primary DIE. */
15253 if (origin && declaration && class_or_namespace_scope_p (context_die))
15256 gcc_assert (!old_die);
15259 /* Now that the C++ front end lazily declares artificial member fns, we
15260 might need to retrofit the declaration into its class. */
15261 if (!declaration && !origin && !old_die
15262 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
15263 && !class_or_namespace_scope_p (context_die)
15264 && debug_info_level > DINFO_LEVEL_TERSE)
15265 old_die = force_decl_die (decl);
15267 if (origin != NULL)
15269 gcc_assert (!declaration || local_scope_p (context_die));
15271 /* Fixup die_parent for the abstract instance of a nested
15272 inline function. */
15273 if (old_die && old_die->die_parent == NULL)
15274 add_child_die (context_die, old_die);
15276 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15277 add_abstract_origin_attribute (subr_die, origin);
15281 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
15282 struct dwarf_file_data * file_index = lookup_filename (s.file);
15284 if (!get_AT_flag (old_die, DW_AT_declaration)
15285 /* We can have a normal definition following an inline one in the
15286 case of redefinition of GNU C extern inlines.
15287 It seems reasonable to use AT_specification in this case. */
15288 && !get_AT (old_die, DW_AT_inline))
15290 /* Detect and ignore this case, where we are trying to output
15291 something we have already output. */
15295 /* If the definition comes from the same place as the declaration,
15296 maybe use the old DIE. We always want the DIE for this function
15297 that has the *_pc attributes to be under comp_unit_die so the
15298 debugger can find it. We also need to do this for abstract
15299 instances of inlines, since the spec requires the out-of-line copy
15300 to have the same parent. For local class methods, this doesn't
15301 apply; we just use the old DIE. */
15302 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
15303 && (DECL_ARTIFICIAL (decl)
15304 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
15305 && (get_AT_unsigned (old_die, DW_AT_decl_line)
15306 == (unsigned) s.line))))
15308 subr_die = old_die;
15310 /* Clear out the declaration attribute and the formal parameters.
15311 Do not remove all children, because it is possible that this
15312 declaration die was forced using force_decl_die(). In such
15313 cases die that forced declaration die (e.g. TAG_imported_module)
15314 is one of the children that we do not want to remove. */
15315 remove_AT (subr_die, DW_AT_declaration);
15316 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
15320 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15321 add_AT_specification (subr_die, old_die);
15322 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
15323 add_AT_file (subr_die, DW_AT_decl_file, file_index);
15324 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
15325 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
15330 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15332 if (TREE_PUBLIC (decl))
15333 add_AT_flag (subr_die, DW_AT_external, 1);
15335 add_name_and_src_coords_attributes (subr_die, decl);
15336 if (debug_info_level > DINFO_LEVEL_TERSE)
15338 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
15339 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
15340 0, 0, context_die);
15343 add_pure_or_virtual_attribute (subr_die, decl);
15344 if (DECL_ARTIFICIAL (decl))
15345 add_AT_flag (subr_die, DW_AT_artificial, 1);
15347 if (TREE_PROTECTED (decl))
15348 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
15349 else if (TREE_PRIVATE (decl))
15350 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
15355 if (!old_die || !get_AT (old_die, DW_AT_inline))
15357 add_AT_flag (subr_die, DW_AT_declaration, 1);
15359 /* If this is an explicit function declaration then generate
15360 a DW_AT_explicit attribute. */
15361 if (lang_hooks.decls.function_decl_explicit_p (decl))
15362 add_AT_flag (subr_die, DW_AT_explicit, 1);
15364 /* The first time we see a member function, it is in the context of
15365 the class to which it belongs. We make sure of this by emitting
15366 the class first. The next time is the definition, which is
15367 handled above. The two may come from the same source text.
15369 Note that force_decl_die() forces function declaration die. It is
15370 later reused to represent definition. */
15371 equate_decl_number_to_die (decl, subr_die);
15374 else if (DECL_ABSTRACT (decl))
15376 if (DECL_DECLARED_INLINE_P (decl))
15378 if (cgraph_function_possibly_inlined_p (decl))
15379 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
15381 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
15385 if (cgraph_function_possibly_inlined_p (decl))
15386 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
15388 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
15391 if (DECL_DECLARED_INLINE_P (decl)
15392 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
15393 add_AT_flag (subr_die, DW_AT_artificial, 1);
15395 equate_decl_number_to_die (decl, subr_die);
15397 else if (!DECL_EXTERNAL (decl))
15399 HOST_WIDE_INT cfa_fb_offset;
15401 if (!old_die || !get_AT (old_die, DW_AT_inline))
15402 equate_decl_number_to_die (decl, subr_die);
15404 if (!flag_reorder_blocks_and_partition)
15406 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
15407 current_function_funcdef_no);
15408 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
15409 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15410 current_function_funcdef_no);
15411 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
15413 add_pubname (decl, subr_die);
15414 add_arange (decl, subr_die);
15417 { /* Do nothing for now; maybe need to duplicate die, one for
15418 hot section and one for cold section, then use the hot/cold
15419 section begin/end labels to generate the aranges... */
15421 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
15422 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
15423 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
15424 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
15426 add_pubname (decl, subr_die);
15427 add_arange (decl, subr_die);
15428 add_arange (decl, subr_die);
15432 #ifdef MIPS_DEBUGGING_INFO
15433 /* Add a reference to the FDE for this routine. */
15434 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
15437 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
15439 /* We define the "frame base" as the function's CFA. This is more
15440 convenient for several reasons: (1) It's stable across the prologue
15441 and epilogue, which makes it better than just a frame pointer,
15442 (2) With dwarf3, there exists a one-byte encoding that allows us
15443 to reference the .debug_frame data by proxy, but failing that,
15444 (3) We can at least reuse the code inspection and interpretation
15445 code that determines the CFA position at various points in the
15447 if (dwarf_version >= 3)
15449 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
15450 add_AT_loc (subr_die, DW_AT_frame_base, op);
15454 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
15455 if (list->dw_loc_next)
15456 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
15458 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
15461 /* Compute a displacement from the "steady-state frame pointer" to
15462 the CFA. The former is what all stack slots and argument slots
15463 will reference in the rtl; the later is what we've told the
15464 debugger about. We'll need to adjust all frame_base references
15465 by this displacement. */
15466 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
15468 if (cfun->static_chain_decl)
15469 add_AT_location_description (subr_die, DW_AT_static_link,
15470 loc_descriptor_from_tree (cfun->static_chain_decl));
15473 /* Generate child dies for template paramaters. */
15474 if (debug_info_level > DINFO_LEVEL_TERSE)
15475 gen_generic_params_dies (decl);
15477 /* Now output descriptions of the arguments for this function. This gets
15478 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
15479 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
15480 `...' at the end of the formal parameter list. In order to find out if
15481 there was a trailing ellipsis or not, we must instead look at the type
15482 associated with the FUNCTION_DECL. This will be a node of type
15483 FUNCTION_TYPE. If the chain of type nodes hanging off of this
15484 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
15485 an ellipsis at the end. */
15487 /* In the case where we are describing a mere function declaration, all we
15488 need to do here (and all we *can* do here) is to describe the *types* of
15489 its formal parameters. */
15490 if (debug_info_level <= DINFO_LEVEL_TERSE)
15492 else if (declaration)
15493 gen_formal_types_die (decl, subr_die);
15496 /* Generate DIEs to represent all known formal parameters. */
15497 tree arg_decls = DECL_ARGUMENTS (decl);
15500 /* When generating DIEs, generate the unspecified_parameters DIE
15501 instead if we come across the arg "__builtin_va_alist" */
15502 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
15503 if (TREE_CODE (parm) == PARM_DECL)
15505 if (DECL_NAME (parm)
15506 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
15507 "__builtin_va_alist"))
15508 gen_unspecified_parameters_die (parm, subr_die);
15510 gen_decl_die (parm, NULL, subr_die);
15513 /* Decide whether we need an unspecified_parameters DIE at the end.
15514 There are 2 more cases to do this for: 1) the ansi ... declaration -
15515 this is detectable when the end of the arg list is not a
15516 void_type_node 2) an unprototyped function declaration (not a
15517 definition). This just means that we have no info about the
15518 parameters at all. */
15519 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
15520 if (fn_arg_types != NULL)
15522 /* This is the prototyped case, check for.... */
15523 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
15524 gen_unspecified_parameters_die (decl, subr_die);
15526 else if (DECL_INITIAL (decl) == NULL_TREE)
15527 gen_unspecified_parameters_die (decl, subr_die);
15530 /* Output Dwarf info for all of the stuff within the body of the function
15531 (if it has one - it may be just a declaration). */
15532 outer_scope = DECL_INITIAL (decl);
15534 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
15535 a function. This BLOCK actually represents the outermost binding contour
15536 for the function, i.e. the contour in which the function's formal
15537 parameters and labels get declared. Curiously, it appears that the front
15538 end doesn't actually put the PARM_DECL nodes for the current function onto
15539 the BLOCK_VARS list for this outer scope, but are strung off of the
15540 DECL_ARGUMENTS list for the function instead.
15542 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
15543 the LABEL_DECL nodes for the function however, and we output DWARF info
15544 for those in decls_for_scope. Just within the `outer_scope' there will be
15545 a BLOCK node representing the function's outermost pair of curly braces,
15546 and any blocks used for the base and member initializers of a C++
15547 constructor function. */
15548 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
15550 /* Emit a DW_TAG_variable DIE for a named return value. */
15551 if (DECL_NAME (DECL_RESULT (decl)))
15552 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
15554 current_function_has_inlines = 0;
15555 decls_for_scope (outer_scope, subr_die, 0);
15557 #if 0 && defined (MIPS_DEBUGGING_INFO)
15558 if (current_function_has_inlines)
15560 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
15561 if (! comp_unit_has_inlines)
15563 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
15564 comp_unit_has_inlines = 1;
15569 /* Add the calling convention attribute if requested. */
15570 add_calling_convention_attribute (subr_die, decl);
15574 /* Returns a hash value for X (which really is a die_struct). */
15577 common_block_die_table_hash (const void *x)
15579 const_dw_die_ref d = (const_dw_die_ref) x;
15580 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
15583 /* Return nonzero if decl_id and die_parent of die_struct X is the same
15584 as decl_id and die_parent of die_struct Y. */
15587 common_block_die_table_eq (const void *x, const void *y)
15589 const_dw_die_ref d = (const_dw_die_ref) x;
15590 const_dw_die_ref e = (const_dw_die_ref) y;
15591 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
15594 /* Generate a DIE to represent a declared data object.
15595 Either DECL or ORIGIN must be non-null. */
15598 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
15602 tree decl_or_origin = decl ? decl : origin;
15603 dw_die_ref var_die;
15604 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
15605 dw_die_ref origin_die;
15606 int declaration = (DECL_EXTERNAL (decl_or_origin)
15607 /* If DECL is COMDAT and has not actually been
15608 emitted, we cannot take its address; there
15609 might end up being no definition anywhere in
15610 the program. For example, consider the C++
15614 struct S { static const int i = 7; };
15619 int f() { return S<int>::i; }
15621 Here, S<int>::i is not DECL_EXTERNAL, but no
15622 definition is required, so the compiler will
15623 not emit a definition. */
15624 || (TREE_CODE (decl_or_origin) == VAR_DECL
15625 && DECL_COMDAT (decl_or_origin)
15626 && !TREE_ASM_WRITTEN (decl_or_origin))
15627 || class_or_namespace_scope_p (context_die));
15630 origin = decl_ultimate_origin (decl);
15632 com_decl = fortran_common (decl_or_origin, &off);
15634 /* Symbol in common gets emitted as a child of the common block, in the form
15635 of a data member. */
15639 dw_die_ref com_die;
15640 dw_loc_descr_ref loc;
15641 die_node com_die_arg;
15643 var_die = lookup_decl_die (decl_or_origin);
15646 if (get_AT (var_die, DW_AT_location) == NULL)
15648 loc = loc_descriptor_from_tree (com_decl);
15653 /* Optimize the common case. */
15654 if (loc->dw_loc_opc == DW_OP_addr
15655 && loc->dw_loc_next == NULL
15656 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
15658 loc->dw_loc_oprnd1.v.val_addr
15659 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
15661 loc_descr_plus_const (&loc, off);
15663 add_AT_loc (var_die, DW_AT_location, loc);
15664 remove_AT (var_die, DW_AT_declaration);
15670 if (common_block_die_table == NULL)
15671 common_block_die_table
15672 = htab_create_ggc (10, common_block_die_table_hash,
15673 common_block_die_table_eq, NULL);
15675 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
15676 com_die_arg.decl_id = DECL_UID (com_decl);
15677 com_die_arg.die_parent = context_die;
15678 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
15679 loc = loc_descriptor_from_tree (com_decl);
15680 if (com_die == NULL)
15683 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
15686 com_die = new_die (DW_TAG_common_block, context_die, decl);
15687 add_name_and_src_coords_attributes (com_die, com_decl);
15690 add_AT_loc (com_die, DW_AT_location, loc);
15691 /* Avoid sharing the same loc descriptor between
15692 DW_TAG_common_block and DW_TAG_variable. */
15693 loc = loc_descriptor_from_tree (com_decl);
15695 else if (DECL_EXTERNAL (decl))
15696 add_AT_flag (com_die, DW_AT_declaration, 1);
15697 add_pubname_string (cnam, com_die); /* ??? needed? */
15698 com_die->decl_id = DECL_UID (com_decl);
15699 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
15700 *slot = (void *) com_die;
15702 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
15704 add_AT_loc (com_die, DW_AT_location, loc);
15705 loc = loc_descriptor_from_tree (com_decl);
15706 remove_AT (com_die, DW_AT_declaration);
15708 var_die = new_die (DW_TAG_variable, com_die, decl);
15709 add_name_and_src_coords_attributes (var_die, decl);
15710 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
15711 TREE_THIS_VOLATILE (decl), context_die);
15712 add_AT_flag (var_die, DW_AT_external, 1);
15717 /* Optimize the common case. */
15718 if (loc->dw_loc_opc == DW_OP_addr
15719 && loc->dw_loc_next == NULL
15720 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
15721 loc->dw_loc_oprnd1.v.val_addr
15722 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
15724 loc_descr_plus_const (&loc, off);
15726 add_AT_loc (var_die, DW_AT_location, loc);
15728 else if (DECL_EXTERNAL (decl))
15729 add_AT_flag (var_die, DW_AT_declaration, 1);
15730 equate_decl_number_to_die (decl, var_die);
15734 /* If the compiler emitted a definition for the DECL declaration
15735 and if we already emitted a DIE for it, don't emit a second
15736 DIE for it again. */
15739 && old_die->die_parent == context_die)
15742 /* For static data members, the declaration in the class is supposed
15743 to have DW_TAG_member tag; the specification should still be
15744 DW_TAG_variable referencing the DW_TAG_member DIE. */
15745 if (declaration && class_scope_p (context_die))
15746 var_die = new_die (DW_TAG_member, context_die, decl);
15748 var_die = new_die (DW_TAG_variable, context_die, decl);
15751 if (origin != NULL)
15752 origin_die = add_abstract_origin_attribute (var_die, origin);
15754 /* Loop unrolling can create multiple blocks that refer to the same
15755 static variable, so we must test for the DW_AT_declaration flag.
15757 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
15758 copy decls and set the DECL_ABSTRACT flag on them instead of
15761 ??? Duplicated blocks have been rewritten to use .debug_ranges.
15763 ??? The declare_in_namespace support causes us to get two DIEs for one
15764 variable, both of which are declarations. We want to avoid considering
15765 one to be a specification, so we must test that this DIE is not a
15767 else if (old_die && TREE_STATIC (decl) && ! declaration
15768 && get_AT_flag (old_die, DW_AT_declaration) == 1)
15770 /* This is a definition of a C++ class level static. */
15771 add_AT_specification (var_die, old_die);
15772 if (DECL_NAME (decl))
15774 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
15775 struct dwarf_file_data * file_index = lookup_filename (s.file);
15777 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
15778 add_AT_file (var_die, DW_AT_decl_file, file_index);
15780 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
15781 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
15786 tree type = TREE_TYPE (decl);
15788 add_name_and_src_coords_attributes (var_die, decl);
15789 if ((TREE_CODE (decl) == PARM_DECL
15790 || TREE_CODE (decl) == RESULT_DECL
15791 || TREE_CODE (decl) == VAR_DECL)
15792 && DECL_BY_REFERENCE (decl))
15793 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
15795 add_type_attribute (var_die, type, TREE_READONLY (decl),
15796 TREE_THIS_VOLATILE (decl), context_die);
15798 if (TREE_PUBLIC (decl))
15799 add_AT_flag (var_die, DW_AT_external, 1);
15801 if (DECL_ARTIFICIAL (decl))
15802 add_AT_flag (var_die, DW_AT_artificial, 1);
15804 if (TREE_PROTECTED (decl))
15805 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
15806 else if (TREE_PRIVATE (decl))
15807 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
15811 add_AT_flag (var_die, DW_AT_declaration, 1);
15813 if (decl && (DECL_ABSTRACT (decl) || declaration))
15814 equate_decl_number_to_die (decl, var_die);
15817 && (! DECL_ABSTRACT (decl_or_origin)
15818 /* Local static vars are shared between all clones/inlines,
15819 so emit DW_AT_location on the abstract DIE if DECL_RTL is
15821 || (TREE_CODE (decl_or_origin) == VAR_DECL
15822 && TREE_STATIC (decl_or_origin)
15823 && DECL_RTL_SET_P (decl_or_origin)))
15824 /* When abstract origin already has DW_AT_location attribute, no need
15825 to add it again. */
15826 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
15828 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
15829 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
15830 defer_location (decl_or_origin, var_die);
15832 add_location_or_const_value_attribute (var_die,
15835 add_pubname (decl_or_origin, var_die);
15838 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
15841 /* Generate a DIE to represent a named constant. */
15844 gen_const_die (tree decl, dw_die_ref context_die)
15846 dw_die_ref const_die;
15847 tree type = TREE_TYPE (decl);
15849 const_die = new_die (DW_TAG_constant, context_die, decl);
15850 add_name_and_src_coords_attributes (const_die, decl);
15851 add_type_attribute (const_die, type, 1, 0, context_die);
15852 if (TREE_PUBLIC (decl))
15853 add_AT_flag (const_die, DW_AT_external, 1);
15854 if (DECL_ARTIFICIAL (decl))
15855 add_AT_flag (const_die, DW_AT_artificial, 1);
15856 tree_add_const_value_attribute_for_decl (const_die, decl);
15859 /* Generate a DIE to represent a label identifier. */
15862 gen_label_die (tree decl, dw_die_ref context_die)
15864 tree origin = decl_ultimate_origin (decl);
15865 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
15867 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15869 if (origin != NULL)
15870 add_abstract_origin_attribute (lbl_die, origin);
15872 add_name_and_src_coords_attributes (lbl_die, decl);
15874 if (DECL_ABSTRACT (decl))
15875 equate_decl_number_to_die (decl, lbl_die);
15878 insn = DECL_RTL_IF_SET (decl);
15880 /* Deleted labels are programmer specified labels which have been
15881 eliminated because of various optimizations. We still emit them
15882 here so that it is possible to put breakpoints on them. */
15886 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
15888 /* When optimization is enabled (via -O) some parts of the compiler
15889 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
15890 represent source-level labels which were explicitly declared by
15891 the user. This really shouldn't be happening though, so catch
15892 it if it ever does happen. */
15893 gcc_assert (!INSN_DELETED_P (insn));
15895 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
15896 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
15901 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
15902 attributes to the DIE for a block STMT, to describe where the inlined
15903 function was called from. This is similar to add_src_coords_attributes. */
15906 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
15908 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
15910 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
15911 add_AT_unsigned (die, DW_AT_call_line, s.line);
15915 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
15916 Add low_pc and high_pc attributes to the DIE for a block STMT. */
15919 add_high_low_attributes (tree stmt, dw_die_ref die)
15921 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15923 if (BLOCK_FRAGMENT_CHAIN (stmt))
15927 if (inlined_function_outer_scope_p (stmt))
15929 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
15930 BLOCK_NUMBER (stmt));
15931 add_AT_lbl_id (die, DW_AT_entry_pc, label);
15934 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
15936 chain = BLOCK_FRAGMENT_CHAIN (stmt);
15939 add_ranges (chain);
15940 chain = BLOCK_FRAGMENT_CHAIN (chain);
15947 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
15948 BLOCK_NUMBER (stmt));
15949 add_AT_lbl_id (die, DW_AT_low_pc, label);
15950 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
15951 BLOCK_NUMBER (stmt));
15952 add_AT_lbl_id (die, DW_AT_high_pc, label);
15956 /* Generate a DIE for a lexical block. */
15959 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
15961 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
15963 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
15964 add_high_low_attributes (stmt, stmt_die);
15966 decls_for_scope (stmt, stmt_die, depth);
15969 /* Generate a DIE for an inlined subprogram. */
15972 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
15976 /* The instance of function that is effectively being inlined shall not
15978 gcc_assert (! BLOCK_ABSTRACT (stmt));
15980 decl = block_ultimate_origin (stmt);
15982 /* Emit info for the abstract instance first, if we haven't yet. We
15983 must emit this even if the block is abstract, otherwise when we
15984 emit the block below (or elsewhere), we may end up trying to emit
15985 a die whose origin die hasn't been emitted, and crashing. */
15986 dwarf2out_abstract_function (decl);
15988 if (! BLOCK_ABSTRACT (stmt))
15990 dw_die_ref subr_die
15991 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
15993 add_abstract_origin_attribute (subr_die, decl);
15994 if (TREE_ASM_WRITTEN (stmt))
15995 add_high_low_attributes (stmt, subr_die);
15996 add_call_src_coords_attributes (stmt, subr_die);
15998 decls_for_scope (stmt, subr_die, depth);
15999 current_function_has_inlines = 1;
16003 /* Generate a DIE for a field in a record, or structure. */
16006 gen_field_die (tree decl, dw_die_ref context_die)
16008 dw_die_ref decl_die;
16010 if (TREE_TYPE (decl) == error_mark_node)
16013 decl_die = new_die (DW_TAG_member, context_die, decl);
16014 add_name_and_src_coords_attributes (decl_die, decl);
16015 add_type_attribute (decl_die, member_declared_type (decl),
16016 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
16019 if (DECL_BIT_FIELD_TYPE (decl))
16021 add_byte_size_attribute (decl_die, decl);
16022 add_bit_size_attribute (decl_die, decl);
16023 add_bit_offset_attribute (decl_die, decl);
16026 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
16027 add_data_member_location_attribute (decl_die, decl);
16029 if (DECL_ARTIFICIAL (decl))
16030 add_AT_flag (decl_die, DW_AT_artificial, 1);
16032 if (TREE_PROTECTED (decl))
16033 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
16034 else if (TREE_PRIVATE (decl))
16035 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
16037 /* Equate decl number to die, so that we can look up this decl later on. */
16038 equate_decl_number_to_die (decl, decl_die);
16042 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16043 Use modified_type_die instead.
16044 We keep this code here just in case these types of DIEs may be needed to
16045 represent certain things in other languages (e.g. Pascal) someday. */
16048 gen_pointer_type_die (tree type, dw_die_ref context_die)
16051 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
16053 equate_type_number_to_die (type, ptr_die);
16054 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16055 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16058 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16059 Use modified_type_die instead.
16060 We keep this code here just in case these types of DIEs may be needed to
16061 represent certain things in other languages (e.g. Pascal) someday. */
16064 gen_reference_type_die (tree type, dw_die_ref context_die)
16067 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
16069 equate_type_number_to_die (type, ref_die);
16070 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
16071 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16075 /* Generate a DIE for a pointer to a member type. */
16078 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
16081 = new_die (DW_TAG_ptr_to_member_type,
16082 scope_die_for (type, context_die), type);
16084 equate_type_number_to_die (type, ptr_die);
16085 add_AT_die_ref (ptr_die, DW_AT_containing_type,
16086 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
16087 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16090 /* Generate the DIE for the compilation unit. */
16093 gen_compile_unit_die (const char *filename)
16096 char producer[250];
16097 const char *language_string = lang_hooks.name;
16100 die = new_die (DW_TAG_compile_unit, NULL, NULL);
16104 add_name_attribute (die, filename);
16105 /* Don't add cwd for <built-in>. */
16106 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
16107 add_comp_dir_attribute (die);
16110 sprintf (producer, "%s %s", language_string, version_string);
16112 #ifdef MIPS_DEBUGGING_INFO
16113 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
16114 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
16115 not appear in the producer string, the debugger reaches the conclusion
16116 that the object file is stripped and has no debugging information.
16117 To get the MIPS/SGI debugger to believe that there is debugging
16118 information in the object file, we add a -g to the producer string. */
16119 if (debug_info_level > DINFO_LEVEL_TERSE)
16120 strcat (producer, " -g");
16123 add_AT_string (die, DW_AT_producer, producer);
16125 if (strcmp (language_string, "GNU C++") == 0)
16126 language = DW_LANG_C_plus_plus;
16127 else if (strcmp (language_string, "GNU Ada") == 0)
16128 language = DW_LANG_Ada95;
16129 else if (strcmp (language_string, "GNU F77") == 0)
16130 language = DW_LANG_Fortran77;
16131 else if (strcmp (language_string, "GNU Fortran") == 0)
16132 language = DW_LANG_Fortran95;
16133 else if (strcmp (language_string, "GNU Pascal") == 0)
16134 language = DW_LANG_Pascal83;
16135 else if (strcmp (language_string, "GNU Java") == 0)
16136 language = DW_LANG_Java;
16137 else if (strcmp (language_string, "GNU Objective-C") == 0)
16138 language = DW_LANG_ObjC;
16139 else if (strcmp (language_string, "GNU Objective-C++") == 0)
16140 language = DW_LANG_ObjC_plus_plus;
16142 language = DW_LANG_C89;
16144 add_AT_unsigned (die, DW_AT_language, language);
16148 /* Generate the DIE for a base class. */
16151 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
16153 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
16155 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
16156 add_data_member_location_attribute (die, binfo);
16158 if (BINFO_VIRTUAL_P (binfo))
16159 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
16161 if (access == access_public_node)
16162 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16163 else if (access == access_protected_node)
16164 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16167 /* Generate a DIE for a class member. */
16170 gen_member_die (tree type, dw_die_ref context_die)
16173 tree binfo = TYPE_BINFO (type);
16176 /* If this is not an incomplete type, output descriptions of each of its
16177 members. Note that as we output the DIEs necessary to represent the
16178 members of this record or union type, we will also be trying to output
16179 DIEs to represent the *types* of those members. However the `type'
16180 function (above) will specifically avoid generating type DIEs for member
16181 types *within* the list of member DIEs for this (containing) type except
16182 for those types (of members) which are explicitly marked as also being
16183 members of this (containing) type themselves. The g++ front- end can
16184 force any given type to be treated as a member of some other (containing)
16185 type by setting the TYPE_CONTEXT of the given (member) type to point to
16186 the TREE node representing the appropriate (containing) type. */
16188 /* First output info about the base classes. */
16191 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
16195 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
16196 gen_inheritance_die (base,
16197 (accesses ? VEC_index (tree, accesses, i)
16198 : access_public_node), context_die);
16201 /* Now output info about the data members and type members. */
16202 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
16204 /* If we thought we were generating minimal debug info for TYPE
16205 and then changed our minds, some of the member declarations
16206 may have already been defined. Don't define them again, but
16207 do put them in the right order. */
16209 child = lookup_decl_die (member);
16211 splice_child_die (context_die, child);
16213 gen_decl_die (member, NULL, context_die);
16216 /* Now output info about the function members (if any). */
16217 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
16219 /* Don't include clones in the member list. */
16220 if (DECL_ABSTRACT_ORIGIN (member))
16223 child = lookup_decl_die (member);
16225 splice_child_die (context_die, child);
16227 gen_decl_die (member, NULL, context_die);
16231 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
16232 is set, we pretend that the type was never defined, so we only get the
16233 member DIEs needed by later specification DIEs. */
16236 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
16237 enum debug_info_usage usage)
16239 dw_die_ref type_die = lookup_type_die (type);
16240 dw_die_ref scope_die = 0;
16242 int complete = (TYPE_SIZE (type)
16243 && (! TYPE_STUB_DECL (type)
16244 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
16245 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
16246 complete = complete && should_emit_struct_debug (type, usage);
16248 if (type_die && ! complete)
16251 if (TYPE_CONTEXT (type) != NULL_TREE
16252 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
16253 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
16256 scope_die = scope_die_for (type, context_die);
16258 if (! type_die || (nested && scope_die == comp_unit_die))
16259 /* First occurrence of type or toplevel definition of nested class. */
16261 dw_die_ref old_die = type_die;
16263 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
16264 ? record_type_tag (type) : DW_TAG_union_type,
16266 equate_type_number_to_die (type, type_die);
16268 add_AT_specification (type_die, old_die);
16270 add_name_attribute (type_die, type_tag (type));
16273 remove_AT (type_die, DW_AT_declaration);
16275 /* Generate child dies for template paramaters. */
16276 if (debug_info_level > DINFO_LEVEL_TERSE
16277 && COMPLETE_TYPE_P (type))
16278 gen_generic_params_dies (type);
16280 /* If this type has been completed, then give it a byte_size attribute and
16281 then give a list of members. */
16282 if (complete && !ns_decl)
16284 /* Prevent infinite recursion in cases where the type of some member of
16285 this type is expressed in terms of this type itself. */
16286 TREE_ASM_WRITTEN (type) = 1;
16287 add_byte_size_attribute (type_die, type);
16288 if (TYPE_STUB_DECL (type) != NULL_TREE)
16289 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16291 /* If the first reference to this type was as the return type of an
16292 inline function, then it may not have a parent. Fix this now. */
16293 if (type_die->die_parent == NULL)
16294 add_child_die (scope_die, type_die);
16296 push_decl_scope (type);
16297 gen_member_die (type, type_die);
16300 /* GNU extension: Record what type our vtable lives in. */
16301 if (TYPE_VFIELD (type))
16303 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
16305 gen_type_die (vtype, context_die);
16306 add_AT_die_ref (type_die, DW_AT_containing_type,
16307 lookup_type_die (vtype));
16312 add_AT_flag (type_die, DW_AT_declaration, 1);
16314 /* We don't need to do this for function-local types. */
16315 if (TYPE_STUB_DECL (type)
16316 && ! decl_function_context (TYPE_STUB_DECL (type)))
16317 VEC_safe_push (tree, gc, incomplete_types, type);
16320 if (get_AT (type_die, DW_AT_name))
16321 add_pubtype (type, type_die);
16324 /* Generate a DIE for a subroutine _type_. */
16327 gen_subroutine_type_die (tree type, dw_die_ref context_die)
16329 tree return_type = TREE_TYPE (type);
16330 dw_die_ref subr_die
16331 = new_die (DW_TAG_subroutine_type,
16332 scope_die_for (type, context_die), type);
16334 equate_type_number_to_die (type, subr_die);
16335 add_prototyped_attribute (subr_die, type);
16336 add_type_attribute (subr_die, return_type, 0, 0, context_die);
16337 gen_formal_types_die (type, subr_die);
16339 if (get_AT (subr_die, DW_AT_name))
16340 add_pubtype (type, subr_die);
16343 /* Generate a DIE for a type definition. */
16346 gen_typedef_die (tree decl, dw_die_ref context_die)
16348 dw_die_ref type_die;
16351 if (TREE_ASM_WRITTEN (decl))
16354 TREE_ASM_WRITTEN (decl) = 1;
16355 type_die = new_die (DW_TAG_typedef, context_die, decl);
16356 origin = decl_ultimate_origin (decl);
16357 if (origin != NULL)
16358 add_abstract_origin_attribute (type_die, origin);
16363 add_name_and_src_coords_attributes (type_die, decl);
16364 if (DECL_ORIGINAL_TYPE (decl))
16366 type = DECL_ORIGINAL_TYPE (decl);
16368 gcc_assert (type != TREE_TYPE (decl));
16369 equate_type_number_to_die (TREE_TYPE (decl), type_die);
16372 type = TREE_TYPE (decl);
16374 add_type_attribute (type_die, type, TREE_READONLY (decl),
16375 TREE_THIS_VOLATILE (decl), context_die);
16378 if (DECL_ABSTRACT (decl))
16379 equate_decl_number_to_die (decl, type_die);
16381 if (get_AT (type_die, DW_AT_name))
16382 add_pubtype (decl, type_die);
16385 /* Generate a type description DIE. */
16388 gen_type_die_with_usage (tree type, dw_die_ref context_die,
16389 enum debug_info_usage usage)
16392 struct array_descr_info info;
16394 if (type == NULL_TREE || type == error_mark_node)
16397 /* If TYPE is a typedef type variant, let's generate debug info
16398 for the parent typedef which TYPE is a type of. */
16399 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16400 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
16402 if (TREE_ASM_WRITTEN (type))
16405 /* Prevent broken recursion; we can't hand off to the same type. */
16406 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
16408 /* Use the DIE of the containing namespace as the parent DIE of
16409 the type description DIE we want to generate. */
16410 if (DECL_CONTEXT (TYPE_NAME (type))
16411 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
16412 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
16414 TREE_ASM_WRITTEN (type) = 1;
16415 gen_decl_die (TYPE_NAME (type), NULL, context_die);
16419 /* If this is an array type with hidden descriptor, handle it first. */
16420 if (!TREE_ASM_WRITTEN (type)
16421 && lang_hooks.types.get_array_descr_info
16422 && lang_hooks.types.get_array_descr_info (type, &info))
16424 gen_descr_array_type_die (type, &info, context_die);
16425 TREE_ASM_WRITTEN (type) = 1;
16429 /* We are going to output a DIE to represent the unqualified version
16430 of this type (i.e. without any const or volatile qualifiers) so
16431 get the main variant (i.e. the unqualified version) of this type
16432 now. (Vectors are special because the debugging info is in the
16433 cloned type itself). */
16434 if (TREE_CODE (type) != VECTOR_TYPE)
16435 type = type_main_variant (type);
16437 if (TREE_ASM_WRITTEN (type))
16440 switch (TREE_CODE (type))
16446 case REFERENCE_TYPE:
16447 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
16448 ensures that the gen_type_die recursion will terminate even if the
16449 type is recursive. Recursive types are possible in Ada. */
16450 /* ??? We could perhaps do this for all types before the switch
16452 TREE_ASM_WRITTEN (type) = 1;
16454 /* For these types, all that is required is that we output a DIE (or a
16455 set of DIEs) to represent the "basis" type. */
16456 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16457 DINFO_USAGE_IND_USE);
16461 /* This code is used for C++ pointer-to-data-member types.
16462 Output a description of the relevant class type. */
16463 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
16464 DINFO_USAGE_IND_USE);
16466 /* Output a description of the type of the object pointed to. */
16467 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16468 DINFO_USAGE_IND_USE);
16470 /* Now output a DIE to represent this pointer-to-data-member type
16472 gen_ptr_to_mbr_type_die (type, context_die);
16475 case FUNCTION_TYPE:
16476 /* Force out return type (in case it wasn't forced out already). */
16477 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16478 DINFO_USAGE_DIR_USE);
16479 gen_subroutine_type_die (type, context_die);
16483 /* Force out return type (in case it wasn't forced out already). */
16484 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16485 DINFO_USAGE_DIR_USE);
16486 gen_subroutine_type_die (type, context_die);
16490 gen_array_type_die (type, context_die);
16494 gen_array_type_die (type, context_die);
16497 case ENUMERAL_TYPE:
16500 case QUAL_UNION_TYPE:
16501 /* If this is a nested type whose containing class hasn't been written
16502 out yet, writing it out will cover this one, too. This does not apply
16503 to instantiations of member class templates; they need to be added to
16504 the containing class as they are generated. FIXME: This hurts the
16505 idea of combining type decls from multiple TUs, since we can't predict
16506 what set of template instantiations we'll get. */
16507 if (TYPE_CONTEXT (type)
16508 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
16509 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
16511 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
16513 if (TREE_ASM_WRITTEN (type))
16516 /* If that failed, attach ourselves to the stub. */
16517 push_decl_scope (TYPE_CONTEXT (type));
16518 context_die = lookup_type_die (TYPE_CONTEXT (type));
16521 else if (TYPE_CONTEXT (type) != NULL_TREE
16522 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
16524 /* If this type is local to a function that hasn't been written
16525 out yet, use a NULL context for now; it will be fixed up in
16526 decls_for_scope. */
16527 context_die = lookup_decl_die (TYPE_CONTEXT (type));
16532 context_die = declare_in_namespace (type, context_die);
16536 if (TREE_CODE (type) == ENUMERAL_TYPE)
16538 /* This might have been written out by the call to
16539 declare_in_namespace. */
16540 if (!TREE_ASM_WRITTEN (type))
16541 gen_enumeration_type_die (type, context_die);
16544 gen_struct_or_union_type_die (type, context_die, usage);
16549 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
16550 it up if it is ever completed. gen_*_type_die will set it for us
16551 when appropriate. */
16557 case FIXED_POINT_TYPE:
16560 /* No DIEs needed for fundamental types. */
16564 /* No Dwarf representation currently defined. */
16568 gcc_unreachable ();
16571 TREE_ASM_WRITTEN (type) = 1;
16575 gen_type_die (tree type, dw_die_ref context_die)
16577 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
16580 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
16581 things which are local to the given block. */
16584 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
16586 int must_output_die = 0;
16589 /* Ignore blocks that are NULL. */
16590 if (stmt == NULL_TREE)
16593 inlined_func = inlined_function_outer_scope_p (stmt);
16595 /* If the block is one fragment of a non-contiguous block, do not
16596 process the variables, since they will have been done by the
16597 origin block. Do process subblocks. */
16598 if (BLOCK_FRAGMENT_ORIGIN (stmt))
16602 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
16603 gen_block_die (sub, context_die, depth + 1);
16608 /* Determine if we need to output any Dwarf DIEs at all to represent this
16611 /* The outer scopes for inlinings *must* always be represented. We
16612 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
16613 must_output_die = 1;
16616 /* Determine if this block directly contains any "significant"
16617 local declarations which we will need to output DIEs for. */
16618 if (debug_info_level > DINFO_LEVEL_TERSE)
16619 /* We are not in terse mode so *any* local declaration counts
16620 as being a "significant" one. */
16621 must_output_die = ((BLOCK_VARS (stmt) != NULL
16622 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
16623 && (TREE_USED (stmt)
16624 || TREE_ASM_WRITTEN (stmt)
16625 || BLOCK_ABSTRACT (stmt)));
16626 else if ((TREE_USED (stmt)
16627 || TREE_ASM_WRITTEN (stmt)
16628 || BLOCK_ABSTRACT (stmt))
16629 && !dwarf2out_ignore_block (stmt))
16630 must_output_die = 1;
16633 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
16634 DIE for any block which contains no significant local declarations at
16635 all. Rather, in such cases we just call `decls_for_scope' so that any
16636 needed Dwarf info for any sub-blocks will get properly generated. Note
16637 that in terse mode, our definition of what constitutes a "significant"
16638 local declaration gets restricted to include only inlined function
16639 instances and local (nested) function definitions. */
16640 if (must_output_die)
16644 /* If STMT block is abstract, that means we have been called
16645 indirectly from dwarf2out_abstract_function.
16646 That function rightfully marks the descendent blocks (of
16647 the abstract function it is dealing with) as being abstract,
16648 precisely to prevent us from emitting any
16649 DW_TAG_inlined_subroutine DIE as a descendent
16650 of an abstract function instance. So in that case, we should
16651 not call gen_inlined_subroutine_die.
16653 Later though, when cgraph asks dwarf2out to emit info
16654 for the concrete instance of the function decl into which
16655 the concrete instance of STMT got inlined, the later will lead
16656 to the generation of a DW_TAG_inlined_subroutine DIE. */
16657 if (! BLOCK_ABSTRACT (stmt))
16658 gen_inlined_subroutine_die (stmt, context_die, depth);
16661 gen_lexical_block_die (stmt, context_die, depth);
16664 decls_for_scope (stmt, context_die, depth);
16667 /* Process variable DECL (or variable with origin ORIGIN) within
16668 block STMT and add it to CONTEXT_DIE. */
16670 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
16673 tree decl_or_origin = decl ? decl : origin;
16674 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
16676 if (ultimate_origin)
16677 origin = ultimate_origin;
16679 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
16680 die = lookup_decl_die (decl_or_origin);
16681 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
16682 && TYPE_DECL_IS_STUB (decl_or_origin))
16683 die = lookup_type_die (TREE_TYPE (decl_or_origin));
16687 if (die != NULL && die->die_parent == NULL)
16688 add_child_die (context_die, die);
16689 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
16690 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
16691 stmt, context_die);
16693 gen_decl_die (decl, origin, context_die);
16696 /* Generate all of the decls declared within a given scope and (recursively)
16697 all of its sub-blocks. */
16700 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
16706 /* Ignore NULL blocks. */
16707 if (stmt == NULL_TREE)
16710 /* Output the DIEs to represent all of the data objects and typedefs
16711 declared directly within this block but not within any nested
16712 sub-blocks. Also, nested function and tag DIEs have been
16713 generated with a parent of NULL; fix that up now. */
16714 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
16715 process_scope_var (stmt, decl, NULL_TREE, context_die);
16716 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
16717 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
16720 /* If we're at -g1, we're not interested in subblocks. */
16721 if (debug_info_level <= DINFO_LEVEL_TERSE)
16724 /* Output the DIEs to represent all sub-blocks (and the items declared
16725 therein) of this block. */
16726 for (subblocks = BLOCK_SUBBLOCKS (stmt);
16728 subblocks = BLOCK_CHAIN (subblocks))
16729 gen_block_die (subblocks, context_die, depth + 1);
16732 /* Is this a typedef we can avoid emitting? */
16735 is_redundant_typedef (const_tree decl)
16737 if (TYPE_DECL_IS_STUB (decl))
16740 if (DECL_ARTIFICIAL (decl)
16741 && DECL_CONTEXT (decl)
16742 && is_tagged_type (DECL_CONTEXT (decl))
16743 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
16744 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
16745 /* Also ignore the artificial member typedef for the class name. */
16751 /* Returns the DIE for a context. */
16753 static inline dw_die_ref
16754 get_context_die (tree context)
16758 /* Find die that represents this context. */
16759 if (TYPE_P (context))
16760 return force_type_die (context);
16762 return force_decl_die (context);
16764 return comp_unit_die;
16767 /* Returns the DIE for decl. A DIE will always be returned. */
16770 force_decl_die (tree decl)
16772 dw_die_ref decl_die;
16773 unsigned saved_external_flag;
16774 tree save_fn = NULL_TREE;
16775 decl_die = lookup_decl_die (decl);
16778 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
16780 decl_die = lookup_decl_die (decl);
16784 switch (TREE_CODE (decl))
16786 case FUNCTION_DECL:
16787 /* Clear current_function_decl, so that gen_subprogram_die thinks
16788 that this is a declaration. At this point, we just want to force
16789 declaration die. */
16790 save_fn = current_function_decl;
16791 current_function_decl = NULL_TREE;
16792 gen_subprogram_die (decl, context_die);
16793 current_function_decl = save_fn;
16797 /* Set external flag to force declaration die. Restore it after
16798 gen_decl_die() call. */
16799 saved_external_flag = DECL_EXTERNAL (decl);
16800 DECL_EXTERNAL (decl) = 1;
16801 gen_decl_die (decl, NULL, context_die);
16802 DECL_EXTERNAL (decl) = saved_external_flag;
16805 case NAMESPACE_DECL:
16806 dwarf2out_decl (decl);
16810 gcc_unreachable ();
16813 /* We should be able to find the DIE now. */
16815 decl_die = lookup_decl_die (decl);
16816 gcc_assert (decl_die);
16822 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
16823 always returned. */
16826 force_type_die (tree type)
16828 dw_die_ref type_die;
16830 type_die = lookup_type_die (type);
16833 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
16835 type_die = modified_type_die (type, TYPE_READONLY (type),
16836 TYPE_VOLATILE (type), context_die);
16837 gcc_assert (type_die);
16842 /* Force out any required namespaces to be able to output DECL,
16843 and return the new context_die for it, if it's changed. */
16846 setup_namespace_context (tree thing, dw_die_ref context_die)
16848 tree context = (DECL_P (thing)
16849 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
16850 if (context && TREE_CODE (context) == NAMESPACE_DECL)
16851 /* Force out the namespace. */
16852 context_die = force_decl_die (context);
16854 return context_die;
16857 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
16858 type) within its namespace, if appropriate.
16860 For compatibility with older debuggers, namespace DIEs only contain
16861 declarations; all definitions are emitted at CU scope. */
16864 declare_in_namespace (tree thing, dw_die_ref context_die)
16866 dw_die_ref ns_context;
16868 if (debug_info_level <= DINFO_LEVEL_TERSE)
16869 return context_die;
16871 /* If this decl is from an inlined function, then don't try to emit it in its
16872 namespace, as we will get confused. It would have already been emitted
16873 when the abstract instance of the inline function was emitted anyways. */
16874 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
16875 return context_die;
16877 ns_context = setup_namespace_context (thing, context_die);
16879 if (ns_context != context_die)
16883 if (DECL_P (thing))
16884 gen_decl_die (thing, NULL, ns_context);
16886 gen_type_die (thing, ns_context);
16888 return context_die;
16891 /* Generate a DIE for a namespace or namespace alias. */
16894 gen_namespace_die (tree decl, dw_die_ref context_die)
16896 dw_die_ref namespace_die;
16898 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
16899 they are an alias of. */
16900 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
16902 /* Output a real namespace or module. */
16903 context_die = setup_namespace_context (decl, comp_unit_die);
16904 namespace_die = new_die (is_fortran ()
16905 ? DW_TAG_module : DW_TAG_namespace,
16906 context_die, decl);
16907 /* For Fortran modules defined in different CU don't add src coords. */
16908 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
16909 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
16911 add_name_and_src_coords_attributes (namespace_die, decl);
16912 if (DECL_EXTERNAL (decl))
16913 add_AT_flag (namespace_die, DW_AT_declaration, 1);
16914 equate_decl_number_to_die (decl, namespace_die);
16918 /* Output a namespace alias. */
16920 /* Force out the namespace we are an alias of, if necessary. */
16921 dw_die_ref origin_die
16922 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
16924 if (DECL_CONTEXT (decl) == NULL_TREE
16925 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
16926 context_die = setup_namespace_context (decl, comp_unit_die);
16927 /* Now create the namespace alias DIE. */
16928 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
16929 add_name_and_src_coords_attributes (namespace_die, decl);
16930 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
16931 equate_decl_number_to_die (decl, namespace_die);
16935 /* Generate Dwarf debug information for a decl described by DECL. */
16938 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
16940 tree decl_or_origin = decl ? decl : origin;
16941 tree class_origin = NULL;
16943 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
16946 switch (TREE_CODE (decl_or_origin))
16952 if (!is_fortran ())
16954 /* The individual enumerators of an enum type get output when we output
16955 the Dwarf representation of the relevant enum type itself. */
16959 /* Emit its type. */
16960 gen_type_die (TREE_TYPE (decl), context_die);
16962 /* And its containing namespace. */
16963 context_die = declare_in_namespace (decl, context_die);
16965 gen_const_die (decl, context_die);
16968 case FUNCTION_DECL:
16969 /* Don't output any DIEs to represent mere function declarations,
16970 unless they are class members or explicit block externs. */
16971 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
16972 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
16973 && (current_function_decl == NULL_TREE
16974 || DECL_ARTIFICIAL (decl_or_origin)))
16979 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
16980 on local redeclarations of global functions. That seems broken. */
16981 if (current_function_decl != decl)
16982 /* This is only a declaration. */;
16985 /* If we're emitting a clone, emit info for the abstract instance. */
16986 if (origin || DECL_ORIGIN (decl) != decl)
16987 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
16989 /* If we're emitting an out-of-line copy of an inline function,
16990 emit info for the abstract instance and set up to refer to it. */
16991 else if (cgraph_function_possibly_inlined_p (decl)
16992 && ! DECL_ABSTRACT (decl)
16993 && ! class_or_namespace_scope_p (context_die)
16994 /* dwarf2out_abstract_function won't emit a die if this is just
16995 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
16996 that case, because that works only if we have a die. */
16997 && DECL_INITIAL (decl) != NULL_TREE)
16999 dwarf2out_abstract_function (decl);
17000 set_decl_origin_self (decl);
17003 /* Otherwise we're emitting the primary DIE for this decl. */
17004 else if (debug_info_level > DINFO_LEVEL_TERSE)
17006 /* Before we describe the FUNCTION_DECL itself, make sure that we
17007 have described its return type. */
17008 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
17010 /* And its virtual context. */
17011 if (DECL_VINDEX (decl) != NULL_TREE)
17012 gen_type_die (DECL_CONTEXT (decl), context_die);
17014 /* And its containing type. */
17016 origin = decl_class_context (decl);
17017 if (origin != NULL_TREE)
17018 gen_type_die_for_member (origin, decl, context_die);
17020 /* And its containing namespace. */
17021 context_die = declare_in_namespace (decl, context_die);
17024 /* Now output a DIE to represent the function itself. */
17026 gen_subprogram_die (decl, context_die);
17030 /* If we are in terse mode, don't generate any DIEs to represent any
17031 actual typedefs. */
17032 if (debug_info_level <= DINFO_LEVEL_TERSE)
17035 /* In the special case of a TYPE_DECL node representing the declaration
17036 of some type tag, if the given TYPE_DECL is marked as having been
17037 instantiated from some other (original) TYPE_DECL node (e.g. one which
17038 was generated within the original definition of an inline function) we
17039 used to generate a special (abbreviated) DW_TAG_structure_type,
17040 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
17041 should be actually referencing those DIEs, as variable DIEs with that
17042 type would be emitted already in the abstract origin, so it was always
17043 removed during unused type prunning. Don't add anything in this
17045 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
17048 if (is_redundant_typedef (decl))
17049 gen_type_die (TREE_TYPE (decl), context_die);
17051 /* Output a DIE to represent the typedef itself. */
17052 gen_typedef_die (decl, context_die);
17056 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17057 gen_label_die (decl, context_die);
17062 /* If we are in terse mode, don't generate any DIEs to represent any
17063 variable declarations or definitions. */
17064 if (debug_info_level <= DINFO_LEVEL_TERSE)
17067 /* Output any DIEs that are needed to specify the type of this data
17069 if ((TREE_CODE (decl_or_origin) == RESULT_DECL
17070 || TREE_CODE (decl_or_origin) == VAR_DECL)
17071 && DECL_BY_REFERENCE (decl_or_origin))
17072 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17074 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17076 /* And its containing type. */
17077 class_origin = decl_class_context (decl_or_origin);
17078 if (class_origin != NULL_TREE)
17079 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
17081 /* And its containing namespace. */
17082 context_die = declare_in_namespace (decl_or_origin, context_die);
17084 /* Now output the DIE to represent the data object itself. This gets
17085 complicated because of the possibility that the VAR_DECL really
17086 represents an inlined instance of a formal parameter for an inline
17089 origin = decl_ultimate_origin (decl);
17090 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
17091 gen_formal_parameter_die (decl, origin, context_die);
17093 gen_variable_die (decl, origin, context_die);
17097 /* Ignore the nameless fields that are used to skip bits but handle C++
17098 anonymous unions and structs. */
17099 if (DECL_NAME (decl) != NULL_TREE
17100 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
17101 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
17103 gen_type_die (member_declared_type (decl), context_die);
17104 gen_field_die (decl, context_die);
17109 if (DECL_BY_REFERENCE (decl_or_origin))
17110 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17112 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17113 gen_formal_parameter_die (decl, origin, context_die);
17116 case NAMESPACE_DECL:
17117 case IMPORTED_DECL:
17118 gen_namespace_die (decl, context_die);
17122 /* Probably some frontend-internal decl. Assume we don't care. */
17123 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
17128 /* Output debug information for global decl DECL. Called from toplev.c after
17129 compilation proper has finished. */
17132 dwarf2out_global_decl (tree decl)
17134 /* Output DWARF2 information for file-scope tentative data object
17135 declarations, file-scope (extern) function declarations (which
17136 had no corresponding body) and file-scope tagged type declarations
17137 and definitions which have not yet been forced out. */
17138 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
17139 dwarf2out_decl (decl);
17142 /* Output debug information for type decl DECL. Called from toplev.c
17143 and from language front ends (to record built-in types). */
17145 dwarf2out_type_decl (tree decl, int local)
17148 dwarf2out_decl (decl);
17151 /* Output debug information for imported module or decl DECL.
17152 NAME is non-NULL name in the lexical block if the decl has been renamed.
17153 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
17154 that DECL belongs to.
17155 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
17157 dwarf2out_imported_module_or_decl_1 (tree decl,
17159 tree lexical_block,
17160 dw_die_ref lexical_block_die)
17162 expanded_location xloc;
17163 dw_die_ref imported_die = NULL;
17164 dw_die_ref at_import_die;
17166 if (TREE_CODE (decl) == IMPORTED_DECL)
17168 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
17169 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
17173 xloc = expand_location (input_location);
17175 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
17177 if (is_base_type (TREE_TYPE (decl)))
17178 at_import_die = base_type_die (TREE_TYPE (decl));
17180 at_import_die = force_type_die (TREE_TYPE (decl));
17181 /* For namespace N { typedef void T; } using N::T; base_type_die
17182 returns NULL, but DW_TAG_imported_declaration requires
17183 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
17184 if (!at_import_die)
17186 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
17187 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
17188 at_import_die = lookup_type_die (TREE_TYPE (decl));
17189 gcc_assert (at_import_die);
17194 at_import_die = lookup_decl_die (decl);
17195 if (!at_import_die)
17197 /* If we're trying to avoid duplicate debug info, we may not have
17198 emitted the member decl for this field. Emit it now. */
17199 if (TREE_CODE (decl) == FIELD_DECL)
17201 tree type = DECL_CONTEXT (decl);
17203 if (TYPE_CONTEXT (type)
17204 && TYPE_P (TYPE_CONTEXT (type))
17205 && !should_emit_struct_debug (TYPE_CONTEXT (type),
17206 DINFO_USAGE_DIR_USE))
17208 gen_type_die_for_member (type, decl,
17209 get_context_die (TYPE_CONTEXT (type)));
17211 at_import_die = force_decl_die (decl);
17215 if (TREE_CODE (decl) == NAMESPACE_DECL)
17216 imported_die = new_die (DW_TAG_imported_module,
17220 imported_die = new_die (DW_TAG_imported_declaration,
17224 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
17225 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
17227 add_AT_string (imported_die, DW_AT_name,
17228 IDENTIFIER_POINTER (name));
17229 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
17232 /* Output debug information for imported module or decl DECL.
17233 NAME is non-NULL name in context if the decl has been renamed.
17234 CHILD is true if decl is one of the renamed decls as part of
17235 importing whole module. */
17238 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
17241 /* dw_die_ref at_import_die; */
17242 dw_die_ref scope_die;
17244 if (debug_info_level <= DINFO_LEVEL_TERSE)
17249 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
17250 We need decl DIE for reference and scope die. First, get DIE for the decl
17253 /* Get the scope die for decl context. Use comp_unit_die for global module
17254 or decl. If die is not found for non globals, force new die. */
17256 && TYPE_P (context)
17257 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
17259 scope_die = get_context_die (context);
17263 gcc_assert (scope_die->die_child);
17264 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
17265 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
17266 scope_die = scope_die->die_child;
17269 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
17270 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
17274 /* Write the debugging output for DECL. */
17277 dwarf2out_decl (tree decl)
17279 dw_die_ref context_die = comp_unit_die;
17281 switch (TREE_CODE (decl))
17286 case FUNCTION_DECL:
17287 /* What we would really like to do here is to filter out all mere
17288 file-scope declarations of file-scope functions which are never
17289 referenced later within this translation unit (and keep all of ones
17290 that *are* referenced later on) but we aren't clairvoyant, so we have
17291 no idea which functions will be referenced in the future (i.e. later
17292 on within the current translation unit). So here we just ignore all
17293 file-scope function declarations which are not also definitions. If
17294 and when the debugger needs to know something about these functions,
17295 it will have to hunt around and find the DWARF information associated
17296 with the definition of the function.
17298 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
17299 nodes represent definitions and which ones represent mere
17300 declarations. We have to check DECL_INITIAL instead. That's because
17301 the C front-end supports some weird semantics for "extern inline"
17302 function definitions. These can get inlined within the current
17303 translation unit (and thus, we need to generate Dwarf info for their
17304 abstract instances so that the Dwarf info for the concrete inlined
17305 instances can have something to refer to) but the compiler never
17306 generates any out-of-lines instances of such things (despite the fact
17307 that they *are* definitions).
17309 The important point is that the C front-end marks these "extern
17310 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
17311 them anyway. Note that the C++ front-end also plays some similar games
17312 for inline function definitions appearing within include files which
17313 also contain `#pragma interface' pragmas. */
17314 if (DECL_INITIAL (decl) == NULL_TREE)
17317 /* If we're a nested function, initially use a parent of NULL; if we're
17318 a plain function, this will be fixed up in decls_for_scope. If
17319 we're a method, it will be ignored, since we already have a DIE. */
17320 if (decl_function_context (decl)
17321 /* But if we're in terse mode, we don't care about scope. */
17322 && debug_info_level > DINFO_LEVEL_TERSE)
17323 context_die = NULL;
17327 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
17328 declaration and if the declaration was never even referenced from
17329 within this entire compilation unit. We suppress these DIEs in
17330 order to save space in the .debug section (by eliminating entries
17331 which are probably useless). Note that we must not suppress
17332 block-local extern declarations (whether used or not) because that
17333 would screw-up the debugger's name lookup mechanism and cause it to
17334 miss things which really ought to be in scope at a given point. */
17335 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
17338 /* For local statics lookup proper context die. */
17339 if (TREE_STATIC (decl) && decl_function_context (decl))
17340 context_die = lookup_decl_die (DECL_CONTEXT (decl));
17342 /* If we are in terse mode, don't generate any DIEs to represent any
17343 variable declarations or definitions. */
17344 if (debug_info_level <= DINFO_LEVEL_TERSE)
17349 if (debug_info_level <= DINFO_LEVEL_TERSE)
17351 if (!is_fortran ())
17353 if (TREE_STATIC (decl) && decl_function_context (decl))
17354 context_die = lookup_decl_die (DECL_CONTEXT (decl));
17357 case NAMESPACE_DECL:
17358 case IMPORTED_DECL:
17359 if (debug_info_level <= DINFO_LEVEL_TERSE)
17361 if (lookup_decl_die (decl) != NULL)
17366 /* Don't emit stubs for types unless they are needed by other DIEs. */
17367 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
17370 /* Don't bother trying to generate any DIEs to represent any of the
17371 normal built-in types for the language we are compiling. */
17372 if (DECL_IS_BUILTIN (decl))
17374 /* OK, we need to generate one for `bool' so GDB knows what type
17375 comparisons have. */
17377 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
17378 && ! DECL_IGNORED_P (decl))
17379 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
17384 /* If we are in terse mode, don't generate any DIEs for types. */
17385 if (debug_info_level <= DINFO_LEVEL_TERSE)
17388 /* If we're a function-scope tag, initially use a parent of NULL;
17389 this will be fixed up in decls_for_scope. */
17390 if (decl_function_context (decl))
17391 context_die = NULL;
17399 gen_decl_die (decl, NULL, context_die);
17402 /* Output a marker (i.e. a label) for the beginning of the generated code for
17403 a lexical block. */
17406 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
17407 unsigned int blocknum)
17409 switch_to_section (current_function_section ());
17410 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
17413 /* Output a marker (i.e. a label) for the end of the generated code for a
17417 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
17419 switch_to_section (current_function_section ());
17420 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
17423 /* Returns nonzero if it is appropriate not to emit any debugging
17424 information for BLOCK, because it doesn't contain any instructions.
17426 Don't allow this for blocks with nested functions or local classes
17427 as we would end up with orphans, and in the presence of scheduling
17428 we may end up calling them anyway. */
17431 dwarf2out_ignore_block (const_tree block)
17436 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
17437 if (TREE_CODE (decl) == FUNCTION_DECL
17438 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
17440 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
17442 decl = BLOCK_NONLOCALIZED_VAR (block, i);
17443 if (TREE_CODE (decl) == FUNCTION_DECL
17444 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
17451 /* Hash table routines for file_hash. */
17454 file_table_eq (const void *p1_p, const void *p2_p)
17456 const struct dwarf_file_data *const p1 =
17457 (const struct dwarf_file_data *) p1_p;
17458 const char *const p2 = (const char *) p2_p;
17459 return strcmp (p1->filename, p2) == 0;
17463 file_table_hash (const void *p_p)
17465 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
17466 return htab_hash_string (p->filename);
17469 /* Lookup FILE_NAME (in the list of filenames that we know about here in
17470 dwarf2out.c) and return its "index". The index of each (known) filename is
17471 just a unique number which is associated with only that one filename. We
17472 need such numbers for the sake of generating labels (in the .debug_sfnames
17473 section) and references to those files numbers (in the .debug_srcinfo
17474 and.debug_macinfo sections). If the filename given as an argument is not
17475 found in our current list, add it to the list and assign it the next
17476 available unique index number. In order to speed up searches, we remember
17477 the index of the filename was looked up last. This handles the majority of
17480 static struct dwarf_file_data *
17481 lookup_filename (const char *file_name)
17484 struct dwarf_file_data * created;
17486 /* Check to see if the file name that was searched on the previous
17487 call matches this file name. If so, return the index. */
17488 if (file_table_last_lookup
17489 && (file_name == file_table_last_lookup->filename
17490 || strcmp (file_table_last_lookup->filename, file_name) == 0))
17491 return file_table_last_lookup;
17493 /* Didn't match the previous lookup, search the table. */
17494 slot = htab_find_slot_with_hash (file_table, file_name,
17495 htab_hash_string (file_name), INSERT);
17497 return (struct dwarf_file_data *) *slot;
17499 created = GGC_NEW (struct dwarf_file_data);
17500 created->filename = file_name;
17501 created->emitted_number = 0;
17506 /* If the assembler will construct the file table, then translate the compiler
17507 internal file table number into the assembler file table number, and emit
17508 a .file directive if we haven't already emitted one yet. The file table
17509 numbers are different because we prune debug info for unused variables and
17510 types, which may include filenames. */
17513 maybe_emit_file (struct dwarf_file_data * fd)
17515 if (! fd->emitted_number)
17517 if (last_emitted_file)
17518 fd->emitted_number = last_emitted_file->emitted_number + 1;
17520 fd->emitted_number = 1;
17521 last_emitted_file = fd;
17523 if (DWARF2_ASM_LINE_DEBUG_INFO)
17525 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
17526 output_quoted_string (asm_out_file,
17527 remap_debug_filename (fd->filename));
17528 fputc ('\n', asm_out_file);
17532 return fd->emitted_number;
17535 /* Schedule generation of a DW_AT_const_value attribute to DIE.
17536 That generation should happen after function debug info has been
17537 generated. The value of the attribute is the constant value of ARG. */
17540 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
17542 die_arg_entry entry;
17547 if (!tmpl_value_parm_die_table)
17548 tmpl_value_parm_die_table
17549 = VEC_alloc (die_arg_entry, gc, 32);
17553 VEC_safe_push (die_arg_entry, gc,
17554 tmpl_value_parm_die_table,
17558 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
17559 by append_entry_to_tmpl_value_parm_die_table. This function must
17560 be called after function DIEs have been generated. */
17563 gen_remaining_tmpl_value_param_die_attribute (void)
17565 if (tmpl_value_parm_die_table)
17571 VEC_iterate (die_arg_entry, tmpl_value_parm_die_table, i, e);
17573 tree_add_const_value_attribute (e->die, e->arg);
17578 /* Replace DW_AT_name for the decl with name. */
17581 dwarf2out_set_name (tree decl, tree name)
17586 die = TYPE_SYMTAB_DIE (decl);
17590 attr = get_AT (die, DW_AT_name);
17593 struct indirect_string_node *node;
17595 node = find_AT_string (dwarf2_name (name, 0));
17596 /* replace the string. */
17597 attr->dw_attr_val.v.val_str = node;
17601 add_name_attribute (die, dwarf2_name (name, 0));
17604 /* Called by the final INSN scan whenever we see a var location. We
17605 use it to drop labels in the right places, and throw the location in
17606 our lookup table. */
17609 dwarf2out_var_location (rtx loc_note)
17611 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
17612 struct var_loc_node *newloc;
17614 static const char *last_label;
17615 static const char *last_postcall_label;
17616 static bool last_in_cold_section_p;
17619 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
17622 next_real = next_real_insn (loc_note);
17623 /* If there are no instructions which would be affected by this note,
17624 don't do anything. */
17625 if (next_real == NULL_RTX)
17628 newloc = GGC_CNEW (struct var_loc_node);
17629 /* If there were no real insns between note we processed last time
17630 and this note, use the label we emitted last time. */
17631 if (last_var_location_insn == NULL_RTX
17632 || last_var_location_insn != next_real
17633 || last_in_cold_section_p != in_cold_section_p)
17635 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
17636 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
17638 last_label = ggc_strdup (loclabel);
17639 if (!NOTE_DURING_CALL_P (loc_note))
17640 last_postcall_label = NULL;
17642 newloc->var_loc_note = loc_note;
17643 newloc->next = NULL;
17645 if (!NOTE_DURING_CALL_P (loc_note))
17646 newloc->label = last_label;
17649 if (!last_postcall_label)
17651 sprintf (loclabel, "%s-1", last_label);
17652 last_postcall_label = ggc_strdup (loclabel);
17654 newloc->label = last_postcall_label;
17657 if (cfun && in_cold_section_p)
17658 newloc->section_label = crtl->subsections.cold_section_label;
17660 newloc->section_label = text_section_label;
17662 last_var_location_insn = next_real;
17663 last_in_cold_section_p = in_cold_section_p;
17664 decl = NOTE_VAR_LOCATION_DECL (loc_note);
17665 add_var_loc_to_decl (decl, newloc);
17668 /* We need to reset the locations at the beginning of each
17669 function. We can't do this in the end_function hook, because the
17670 declarations that use the locations won't have been output when
17671 that hook is called. Also compute have_multiple_function_sections here. */
17674 dwarf2out_begin_function (tree fun)
17676 htab_empty (decl_loc_table);
17678 if (function_section (fun) != text_section)
17679 have_multiple_function_sections = true;
17681 dwarf2out_note_section_used ();
17684 /* Output a label to mark the beginning of a source code line entry
17685 and record information relating to this source line, in
17686 'line_info_table' for later output of the .debug_line section. */
17689 dwarf2out_source_line (unsigned int line, const char *filename,
17690 int discriminator, bool is_stmt)
17692 static bool last_is_stmt = true;
17694 if (debug_info_level >= DINFO_LEVEL_NORMAL
17697 int file_num = maybe_emit_file (lookup_filename (filename));
17699 switch_to_section (current_function_section ());
17701 /* If requested, emit something human-readable. */
17702 if (flag_debug_asm)
17703 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
17706 if (DWARF2_ASM_LINE_DEBUG_INFO)
17708 /* Emit the .loc directive understood by GNU as. */
17709 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
17710 if (is_stmt != last_is_stmt)
17712 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
17713 last_is_stmt = is_stmt;
17715 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
17716 fprintf (asm_out_file, " discriminator %d", discriminator);
17717 fputc ('\n', asm_out_file);
17719 /* Indicate that line number info exists. */
17720 line_info_table_in_use++;
17722 else if (function_section (current_function_decl) != text_section)
17724 dw_separate_line_info_ref line_info;
17725 targetm.asm_out.internal_label (asm_out_file,
17726 SEPARATE_LINE_CODE_LABEL,
17727 separate_line_info_table_in_use);
17729 /* Expand the line info table if necessary. */
17730 if (separate_line_info_table_in_use
17731 == separate_line_info_table_allocated)
17733 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
17734 separate_line_info_table
17735 = GGC_RESIZEVEC (dw_separate_line_info_entry,
17736 separate_line_info_table,
17737 separate_line_info_table_allocated);
17738 memset (separate_line_info_table
17739 + separate_line_info_table_in_use,
17741 (LINE_INFO_TABLE_INCREMENT
17742 * sizeof (dw_separate_line_info_entry)));
17745 /* Add the new entry at the end of the line_info_table. */
17747 = &separate_line_info_table[separate_line_info_table_in_use++];
17748 line_info->dw_file_num = file_num;
17749 line_info->dw_line_num = line;
17750 line_info->function = current_function_funcdef_no;
17754 dw_line_info_ref line_info;
17756 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
17757 line_info_table_in_use);
17759 /* Expand the line info table if necessary. */
17760 if (line_info_table_in_use == line_info_table_allocated)
17762 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
17764 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
17765 line_info_table_allocated);
17766 memset (line_info_table + line_info_table_in_use, 0,
17767 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
17770 /* Add the new entry at the end of the line_info_table. */
17771 line_info = &line_info_table[line_info_table_in_use++];
17772 line_info->dw_file_num = file_num;
17773 line_info->dw_line_num = line;
17778 /* Record the beginning of a new source file. */
17781 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
17783 if (flag_eliminate_dwarf2_dups)
17785 /* Record the beginning of the file for break_out_includes. */
17786 dw_die_ref bincl_die;
17788 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
17789 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
17792 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17794 int file_num = maybe_emit_file (lookup_filename (filename));
17796 switch_to_section (debug_macinfo_section);
17797 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
17798 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
17801 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
17805 /* Record the end of a source file. */
17808 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
17810 if (flag_eliminate_dwarf2_dups)
17811 /* Record the end of the file for break_out_includes. */
17812 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
17814 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17816 switch_to_section (debug_macinfo_section);
17817 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
17821 /* Called from debug_define in toplev.c. The `buffer' parameter contains
17822 the tail part of the directive line, i.e. the part which is past the
17823 initial whitespace, #, whitespace, directive-name, whitespace part. */
17826 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
17827 const char *buffer ATTRIBUTE_UNUSED)
17829 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17831 switch_to_section (debug_macinfo_section);
17832 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
17833 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
17834 dw2_asm_output_nstring (buffer, -1, "The macro");
17838 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
17839 the tail part of the directive line, i.e. the part which is past the
17840 initial whitespace, #, whitespace, directive-name, whitespace part. */
17843 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
17844 const char *buffer ATTRIBUTE_UNUSED)
17846 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17848 switch_to_section (debug_macinfo_section);
17849 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
17850 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
17851 dw2_asm_output_nstring (buffer, -1, "The macro");
17855 /* Set up for Dwarf output at the start of compilation. */
17858 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
17860 /* Allocate the file_table. */
17861 file_table = htab_create_ggc (50, file_table_hash,
17862 file_table_eq, NULL);
17864 /* Allocate the decl_die_table. */
17865 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
17866 decl_die_table_eq, NULL);
17868 /* Allocate the decl_loc_table. */
17869 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
17870 decl_loc_table_eq, NULL);
17872 /* Allocate the initial hunk of the decl_scope_table. */
17873 decl_scope_table = VEC_alloc (tree, gc, 256);
17875 /* Allocate the initial hunk of the abbrev_die_table. */
17876 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
17877 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
17878 /* Zero-th entry is allocated, but unused. */
17879 abbrev_die_table_in_use = 1;
17881 /* Allocate the initial hunk of the line_info_table. */
17882 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
17883 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
17885 /* Zero-th entry is allocated, but unused. */
17886 line_info_table_in_use = 1;
17888 /* Allocate the pubtypes and pubnames vectors. */
17889 pubname_table = VEC_alloc (pubname_entry, gc, 32);
17890 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
17892 /* Generate the initial DIE for the .debug section. Note that the (string)
17893 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
17894 will (typically) be a relative pathname and that this pathname should be
17895 taken as being relative to the directory from which the compiler was
17896 invoked when the given (base) source file was compiled. We will fill
17897 in this value in dwarf2out_finish. */
17898 comp_unit_die = gen_compile_unit_die (NULL);
17900 incomplete_types = VEC_alloc (tree, gc, 64);
17902 used_rtx_array = VEC_alloc (rtx, gc, 32);
17904 debug_info_section = get_section (DEBUG_INFO_SECTION,
17905 SECTION_DEBUG, NULL);
17906 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
17907 SECTION_DEBUG, NULL);
17908 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
17909 SECTION_DEBUG, NULL);
17910 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
17911 SECTION_DEBUG, NULL);
17912 debug_line_section = get_section (DEBUG_LINE_SECTION,
17913 SECTION_DEBUG, NULL);
17914 debug_loc_section = get_section (DEBUG_LOC_SECTION,
17915 SECTION_DEBUG, NULL);
17916 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
17917 SECTION_DEBUG, NULL);
17918 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
17919 SECTION_DEBUG, NULL);
17920 debug_str_section = get_section (DEBUG_STR_SECTION,
17921 DEBUG_STR_SECTION_FLAGS, NULL);
17922 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
17923 SECTION_DEBUG, NULL);
17924 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
17925 SECTION_DEBUG, NULL);
17927 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
17928 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
17929 DEBUG_ABBREV_SECTION_LABEL, 0);
17930 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
17931 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
17932 COLD_TEXT_SECTION_LABEL, 0);
17933 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
17935 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
17936 DEBUG_INFO_SECTION_LABEL, 0);
17937 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
17938 DEBUG_LINE_SECTION_LABEL, 0);
17939 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
17940 DEBUG_RANGES_SECTION_LABEL, 0);
17941 switch_to_section (debug_abbrev_section);
17942 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
17943 switch_to_section (debug_info_section);
17944 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
17945 switch_to_section (debug_line_section);
17946 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
17948 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17950 switch_to_section (debug_macinfo_section);
17951 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
17952 DEBUG_MACINFO_SECTION_LABEL, 0);
17953 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
17956 switch_to_section (text_section);
17957 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
17958 if (flag_reorder_blocks_and_partition)
17960 cold_text_section = unlikely_text_section ();
17961 switch_to_section (cold_text_section);
17962 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
17966 /* A helper function for dwarf2out_finish called through
17967 htab_traverse. Emit one queued .debug_str string. */
17970 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
17972 struct indirect_string_node *node = (struct indirect_string_node *) *h;
17974 if (node->label && node->refcount)
17976 switch_to_section (debug_str_section);
17977 ASM_OUTPUT_LABEL (asm_out_file, node->label);
17978 assemble_string (node->str, strlen (node->str) + 1);
17984 #if ENABLE_ASSERT_CHECKING
17985 /* Verify that all marks are clear. */
17988 verify_marks_clear (dw_die_ref die)
17992 gcc_assert (! die->die_mark);
17993 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
17995 #endif /* ENABLE_ASSERT_CHECKING */
17997 /* Clear the marks for a die and its children.
17998 Be cool if the mark isn't set. */
18001 prune_unmark_dies (dw_die_ref die)
18007 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
18010 /* Given DIE that we're marking as used, find any other dies
18011 it references as attributes and mark them as used. */
18014 prune_unused_types_walk_attribs (dw_die_ref die)
18019 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18021 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
18023 /* A reference to another DIE.
18024 Make sure that it will get emitted. */
18025 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
18027 /* Set the string's refcount to 0 so that prune_unused_types_mark
18028 accounts properly for it. */
18029 if (AT_class (a) == dw_val_class_str)
18030 a->dw_attr_val.v.val_str->refcount = 0;
18035 /* Mark DIE as being used. If DOKIDS is true, then walk down
18036 to DIE's children. */
18039 prune_unused_types_mark (dw_die_ref die, int dokids)
18043 if (die->die_mark == 0)
18045 /* We haven't done this node yet. Mark it as used. */
18048 /* We also have to mark its parents as used.
18049 (But we don't want to mark our parents' kids due to this.) */
18050 if (die->die_parent)
18051 prune_unused_types_mark (die->die_parent, 0);
18053 /* Mark any referenced nodes. */
18054 prune_unused_types_walk_attribs (die);
18056 /* If this node is a specification,
18057 also mark the definition, if it exists. */
18058 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
18059 prune_unused_types_mark (die->die_definition, 1);
18062 if (dokids && die->die_mark != 2)
18064 /* We need to walk the children, but haven't done so yet.
18065 Remember that we've walked the kids. */
18068 /* If this is an array type, we need to make sure our
18069 kids get marked, even if they're types. */
18070 if (die->die_tag == DW_TAG_array_type)
18071 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
18073 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18077 /* For local classes, look if any static member functions were emitted
18078 and if so, mark them. */
18081 prune_unused_types_walk_local_classes (dw_die_ref die)
18085 if (die->die_mark == 2)
18088 switch (die->die_tag)
18090 case DW_TAG_structure_type:
18091 case DW_TAG_union_type:
18092 case DW_TAG_class_type:
18095 case DW_TAG_subprogram:
18096 if (!get_AT_flag (die, DW_AT_declaration)
18097 || die->die_definition != NULL)
18098 prune_unused_types_mark (die, 1);
18105 /* Mark children. */
18106 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
18109 /* Walk the tree DIE and mark types that we actually use. */
18112 prune_unused_types_walk (dw_die_ref die)
18116 /* Don't do anything if this node is already marked and
18117 children have been marked as well. */
18118 if (die->die_mark == 2)
18121 switch (die->die_tag)
18123 case DW_TAG_structure_type:
18124 case DW_TAG_union_type:
18125 case DW_TAG_class_type:
18126 if (die->die_perennial_p)
18129 for (c = die->die_parent; c; c = c->die_parent)
18130 if (c->die_tag == DW_TAG_subprogram)
18133 /* Finding used static member functions inside of classes
18134 is needed just for local classes, because for other classes
18135 static member function DIEs with DW_AT_specification
18136 are emitted outside of the DW_TAG_*_type. If we ever change
18137 it, we'd need to call this even for non-local classes. */
18139 prune_unused_types_walk_local_classes (die);
18141 /* It's a type node --- don't mark it. */
18144 case DW_TAG_const_type:
18145 case DW_TAG_packed_type:
18146 case DW_TAG_pointer_type:
18147 case DW_TAG_reference_type:
18148 case DW_TAG_volatile_type:
18149 case DW_TAG_typedef:
18150 case DW_TAG_array_type:
18151 case DW_TAG_interface_type:
18152 case DW_TAG_friend:
18153 case DW_TAG_variant_part:
18154 case DW_TAG_enumeration_type:
18155 case DW_TAG_subroutine_type:
18156 case DW_TAG_string_type:
18157 case DW_TAG_set_type:
18158 case DW_TAG_subrange_type:
18159 case DW_TAG_ptr_to_member_type:
18160 case DW_TAG_file_type:
18161 if (die->die_perennial_p)
18164 /* It's a type node --- don't mark it. */
18168 /* Mark everything else. */
18172 if (die->die_mark == 0)
18176 /* Now, mark any dies referenced from here. */
18177 prune_unused_types_walk_attribs (die);
18182 /* Mark children. */
18183 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18186 /* Increment the string counts on strings referred to from DIE's
18190 prune_unused_types_update_strings (dw_die_ref die)
18195 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18196 if (AT_class (a) == dw_val_class_str)
18198 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
18200 /* Avoid unnecessarily putting strings that are used less than
18201 twice in the hash table. */
18203 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
18206 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
18207 htab_hash_string (s->str),
18209 gcc_assert (*slot == NULL);
18215 /* Remove from the tree DIE any dies that aren't marked. */
18218 prune_unused_types_prune (dw_die_ref die)
18222 gcc_assert (die->die_mark);
18223 prune_unused_types_update_strings (die);
18225 if (! die->die_child)
18228 c = die->die_child;
18230 dw_die_ref prev = c;
18231 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
18232 if (c == die->die_child)
18234 /* No marked children between 'prev' and the end of the list. */
18236 /* No marked children at all. */
18237 die->die_child = NULL;
18240 prev->die_sib = c->die_sib;
18241 die->die_child = prev;
18246 if (c != prev->die_sib)
18248 prune_unused_types_prune (c);
18249 } while (c != die->die_child);
18252 /* A helper function for dwarf2out_finish called through
18253 htab_traverse. Clear .debug_str strings that we haven't already
18254 decided to emit. */
18257 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
18259 struct indirect_string_node *node = (struct indirect_string_node *) *h;
18261 if (!node->label || !node->refcount)
18262 htab_clear_slot (debug_str_hash, h);
18267 /* Remove dies representing declarations that we never use. */
18270 prune_unused_types (void)
18273 limbo_die_node *node;
18276 #if ENABLE_ASSERT_CHECKING
18277 /* All the marks should already be clear. */
18278 verify_marks_clear (comp_unit_die);
18279 for (node = limbo_die_list; node; node = node->next)
18280 verify_marks_clear (node->die);
18281 #endif /* ENABLE_ASSERT_CHECKING */
18283 /* Set the mark on nodes that are actually used. */
18284 prune_unused_types_walk (comp_unit_die);
18285 for (node = limbo_die_list; node; node = node->next)
18286 prune_unused_types_walk (node->die);
18288 /* Also set the mark on nodes referenced from the
18289 pubname_table or arange_table. */
18290 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
18291 prune_unused_types_mark (pub->die, 1);
18292 for (i = 0; i < arange_table_in_use; i++)
18293 prune_unused_types_mark (arange_table[i], 1);
18295 /* Get rid of nodes that aren't marked; and update the string counts. */
18296 if (debug_str_hash && debug_str_hash_forced)
18297 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
18298 else if (debug_str_hash)
18299 htab_empty (debug_str_hash);
18300 prune_unused_types_prune (comp_unit_die);
18301 for (node = limbo_die_list; node; node = node->next)
18302 prune_unused_types_prune (node->die);
18304 /* Leave the marks clear. */
18305 prune_unmark_dies (comp_unit_die);
18306 for (node = limbo_die_list; node; node = node->next)
18307 prune_unmark_dies (node->die);
18310 /* Set the parameter to true if there are any relative pathnames in
18313 file_table_relative_p (void ** slot, void *param)
18315 bool *p = (bool *) param;
18316 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
18317 if (!IS_ABSOLUTE_PATH (d->filename))
18325 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
18326 to the location it would have been added, should we know its
18327 DECL_ASSEMBLER_NAME when we added other attributes. This will
18328 probably improve compactness of debug info, removing equivalent
18329 abbrevs, and hide any differences caused by deferring the
18330 computation of the assembler name, triggered by e.g. PCH. */
18333 move_linkage_attr (dw_die_ref die)
18335 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
18336 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
18338 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
18342 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
18344 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
18348 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
18350 VEC_pop (dw_attr_node, die->die_attr);
18351 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
18355 /* Output stuff that dwarf requires at the end of every file,
18356 and generate the DWARF-2 debugging info. */
18359 dwarf2out_finish (const char *filename)
18361 limbo_die_node *node, *next_node;
18362 dw_die_ref die = 0;
18365 gen_remaining_tmpl_value_param_die_attribute ();
18367 /* Add the name for the main input file now. We delayed this from
18368 dwarf2out_init to avoid complications with PCH. */
18369 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
18370 if (!IS_ABSOLUTE_PATH (filename))
18371 add_comp_dir_attribute (comp_unit_die);
18372 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
18375 htab_traverse (file_table, file_table_relative_p, &p);
18377 add_comp_dir_attribute (comp_unit_die);
18380 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
18382 add_location_or_const_value_attribute (
18383 VEC_index (deferred_locations, deferred_locations_list, i)->die,
18384 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
18388 /* Traverse the limbo die list, and add parent/child links. The only
18389 dies without parents that should be here are concrete instances of
18390 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
18391 For concrete instances, we can get the parent die from the abstract
18393 for (node = limbo_die_list; node; node = next_node)
18395 next_node = node->next;
18398 if (die->die_parent == NULL)
18400 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
18403 add_child_die (origin->die_parent, die);
18404 else if (die == comp_unit_die)
18406 else if (errorcount > 0 || sorrycount > 0)
18407 /* It's OK to be confused by errors in the input. */
18408 add_child_die (comp_unit_die, die);
18411 /* In certain situations, the lexical block containing a
18412 nested function can be optimized away, which results
18413 in the nested function die being orphaned. Likewise
18414 with the return type of that nested function. Force
18415 this to be a child of the containing function.
18417 It may happen that even the containing function got fully
18418 inlined and optimized out. In that case we are lost and
18419 assign the empty child. This should not be big issue as
18420 the function is likely unreachable too. */
18421 tree context = NULL_TREE;
18423 gcc_assert (node->created_for);
18425 if (DECL_P (node->created_for))
18426 context = DECL_CONTEXT (node->created_for);
18427 else if (TYPE_P (node->created_for))
18428 context = TYPE_CONTEXT (node->created_for);
18430 gcc_assert (context
18431 && (TREE_CODE (context) == FUNCTION_DECL
18432 || TREE_CODE (context) == NAMESPACE_DECL));
18434 origin = lookup_decl_die (context);
18436 add_child_die (origin, die);
18438 add_child_die (comp_unit_die, die);
18443 limbo_die_list = NULL;
18445 for (node = deferred_asm_name; node; node = node->next)
18447 tree decl = node->created_for;
18448 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
18450 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
18451 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
18452 move_linkage_attr (node->die);
18456 deferred_asm_name = NULL;
18458 /* Walk through the list of incomplete types again, trying once more to
18459 emit full debugging info for them. */
18460 retry_incomplete_types ();
18462 if (flag_eliminate_unused_debug_types)
18463 prune_unused_types ();
18465 /* Generate separate CUs for each of the include files we've seen.
18466 They will go into limbo_die_list. */
18467 if (flag_eliminate_dwarf2_dups)
18468 break_out_includes (comp_unit_die);
18470 /* Traverse the DIE's and add add sibling attributes to those DIE's
18471 that have children. */
18472 add_sibling_attributes (comp_unit_die);
18473 for (node = limbo_die_list; node; node = node->next)
18474 add_sibling_attributes (node->die);
18476 /* Output a terminator label for the .text section. */
18477 switch_to_section (text_section);
18478 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
18479 if (flag_reorder_blocks_and_partition)
18481 switch_to_section (unlikely_text_section ());
18482 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
18485 /* We can only use the low/high_pc attributes if all of the code was
18487 if (!have_multiple_function_sections)
18489 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
18490 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
18495 unsigned fde_idx = 0;
18497 /* We need to give .debug_loc and .debug_ranges an appropriate
18498 "base address". Use zero so that these addresses become
18499 absolute. Historically, we've emitted the unexpected
18500 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
18501 Emit both to give time for other tools to adapt. */
18502 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
18503 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
18505 add_AT_range_list (comp_unit_die, DW_AT_ranges,
18506 add_ranges_by_labels (text_section_label,
18508 if (flag_reorder_blocks_and_partition)
18509 add_ranges_by_labels (cold_text_section_label,
18512 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
18514 dw_fde_ref fde = &fde_table[fde_idx];
18516 if (fde->dw_fde_switched_sections)
18518 if (!fde->in_std_section)
18519 add_ranges_by_labels (fde->dw_fde_hot_section_label,
18520 fde->dw_fde_hot_section_end_label);
18521 if (!fde->cold_in_std_section)
18522 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
18523 fde->dw_fde_unlikely_section_end_label);
18525 else if (!fde->in_std_section)
18526 add_ranges_by_labels (fde->dw_fde_begin,
18533 /* Output location list section if necessary. */
18534 if (have_location_lists)
18536 /* Output the location lists info. */
18537 switch_to_section (debug_loc_section);
18538 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
18539 DEBUG_LOC_SECTION_LABEL, 0);
18540 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
18541 output_location_lists (die);
18544 if (debug_info_level >= DINFO_LEVEL_NORMAL)
18545 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
18546 debug_line_section_label);
18548 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18549 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
18551 /* Output all of the compilation units. We put the main one last so that
18552 the offsets are available to output_pubnames. */
18553 for (node = limbo_die_list; node; node = node->next)
18554 output_comp_unit (node->die, 0);
18556 /* Output the main compilation unit if non-empty or if .debug_macinfo
18557 has been emitted. */
18558 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
18560 /* Output the abbreviation table. */
18561 switch_to_section (debug_abbrev_section);
18562 output_abbrev_section ();
18564 /* Output public names table if necessary. */
18565 if (!VEC_empty (pubname_entry, pubname_table))
18567 switch_to_section (debug_pubnames_section);
18568 output_pubnames (pubname_table);
18571 /* Output public types table if necessary. */
18572 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
18573 It shouldn't hurt to emit it always, since pure DWARF2 consumers
18574 simply won't look for the section. */
18575 if (!VEC_empty (pubname_entry, pubtype_table))
18577 switch_to_section (debug_pubtypes_section);
18578 output_pubnames (pubtype_table);
18581 /* Output the address range information. We only put functions in the arange
18582 table, so don't write it out if we don't have any. */
18583 if (fde_table_in_use)
18585 switch_to_section (debug_aranges_section);
18589 /* Output ranges section if necessary. */
18590 if (ranges_table_in_use)
18592 switch_to_section (debug_ranges_section);
18593 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
18597 /* Output the source line correspondence table. We must do this
18598 even if there is no line information. Otherwise, on an empty
18599 translation unit, we will generate a present, but empty,
18600 .debug_info section. IRIX 6.5 `nm' will then complain when
18601 examining the file. This is done late so that any filenames
18602 used by the debug_info section are marked as 'used'. */
18603 if (! DWARF2_ASM_LINE_DEBUG_INFO)
18605 switch_to_section (debug_line_section);
18606 output_line_info ();
18609 /* Have to end the macro section. */
18610 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18612 switch_to_section (debug_macinfo_section);
18613 dw2_asm_output_data (1, 0, "End compilation unit");
18616 /* If we emitted any DW_FORM_strp form attribute, output the string
18618 if (debug_str_hash)
18619 htab_traverse (debug_str_hash, output_indirect_string, NULL);
18623 /* This should never be used, but its address is needed for comparisons. */
18624 const struct gcc_debug_hooks dwarf2_debug_hooks =
18630 0, /* start_source_file */
18631 0, /* end_source_file */
18632 0, /* begin_block */
18634 0, /* ignore_block */
18635 0, /* source_line */
18636 0, /* begin_prologue */
18637 0, /* end_prologue */
18638 0, /* end_epilogue */
18639 0, /* begin_function */
18640 0, /* end_function */
18641 0, /* function_decl */
18642 0, /* global_decl */
18644 0, /* imported_module_or_decl */
18645 0, /* deferred_inline_function */
18646 0, /* outlining_inline_function */
18648 0, /* handle_pch */
18649 0, /* var_location */
18650 0, /* switch_text_section */
18652 0 /* start_end_main_source_file */
18655 #endif /* DWARF2_DEBUGGING_INFO */
18657 #include "gt-dwarf2out.h"