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];
3887 current_function_func_begin_label = NULL;
3889 #ifdef TARGET_UNWIND_INFO
3890 /* ??? current_function_func_begin_label is also used by except.c
3891 for call-site information. We must emit this label if it might
3893 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3894 && ! dwarf2out_do_frame ())
3897 if (! dwarf2out_do_frame ())
3901 fnsec = function_section (current_function_decl);
3902 switch_to_section (fnsec);
3903 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3904 current_function_funcdef_no);
3905 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3906 current_function_funcdef_no);
3907 dup_label = xstrdup (label);
3908 current_function_func_begin_label = dup_label;
3910 #ifdef TARGET_UNWIND_INFO
3911 /* We can elide the fde allocation if we're not emitting debug info. */
3912 if (! dwarf2out_do_frame ())
3916 /* Expand the fde table if necessary. */
3917 if (fde_table_in_use == fde_table_allocated)
3919 fde_table_allocated += FDE_TABLE_INCREMENT;
3920 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3921 memset (fde_table + fde_table_in_use, 0,
3922 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3925 /* Record the FDE associated with this function. */
3926 current_funcdef_fde = fde_table_in_use;
3928 /* Add the new FDE at the end of the fde_table. */
3929 fde = &fde_table[fde_table_in_use++];
3930 fde->decl = current_function_decl;
3931 fde->dw_fde_begin = dup_label;
3932 fde->dw_fde_current_label = dup_label;
3933 fde->dw_fde_hot_section_label = NULL;
3934 fde->dw_fde_hot_section_end_label = NULL;
3935 fde->dw_fde_unlikely_section_label = NULL;
3936 fde->dw_fde_unlikely_section_end_label = NULL;
3937 fde->dw_fde_switched_sections = 0;
3938 fde->dw_fde_switched_cold_to_hot = 0;
3939 fde->dw_fde_end = NULL;
3940 fde->dw_fde_cfi = NULL;
3941 fde->dw_fde_switch_cfi = NULL;
3942 fde->funcdef_number = current_function_funcdef_no;
3943 fde->nothrow = crtl->nothrow;
3944 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3945 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3946 fde->drap_reg = INVALID_REGNUM;
3947 fde->vdrap_reg = INVALID_REGNUM;
3948 if (flag_reorder_blocks_and_partition)
3950 section *unlikelysec;
3951 if (first_function_block_is_cold)
3952 fde->in_std_section = 1;
3955 = (fnsec == text_section
3956 || (cold_text_section && fnsec == cold_text_section));
3957 unlikelysec = unlikely_text_section ();
3958 fde->cold_in_std_section
3959 = (unlikelysec == text_section
3960 || (cold_text_section && unlikelysec == cold_text_section));
3965 = (fnsec == text_section
3966 || (cold_text_section && fnsec == cold_text_section));
3967 fde->cold_in_std_section = 0;
3970 args_size = old_args_size = 0;
3972 /* We only want to output line number information for the genuine dwarf2
3973 prologue case, not the eh frame case. */
3974 #ifdef DWARF2_DEBUGGING_INFO
3976 dwarf2out_source_line (line, file, 0, true);
3979 personality = get_personality_function (current_function_decl);
3980 if (dwarf2out_do_cfi_asm ())
3981 dwarf2out_do_cfi_startproc (false);
3984 if (!current_unit_personality || current_unit_personality == personality)
3985 current_unit_personality = personality;
3987 sorry ("Multiple EH personalities are supported only with assemblers "
3988 "supporting .cfi.personality directive.");
3992 /* Output a marker (i.e. a label) for the absolute end of the generated code
3993 for a function definition. This gets called *after* the epilogue code has
3997 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3998 const char *file ATTRIBUTE_UNUSED)
4001 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4003 #ifdef DWARF2_DEBUGGING_INFO
4004 last_var_location_insn = NULL_RTX;
4007 if (dwarf2out_do_cfi_asm ())
4008 fprintf (asm_out_file, "\t.cfi_endproc\n");
4010 /* Output a label to mark the endpoint of the code generated for this
4012 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4013 current_function_funcdef_no);
4014 ASM_OUTPUT_LABEL (asm_out_file, label);
4015 fde = current_fde ();
4016 gcc_assert (fde != NULL);
4017 fde->dw_fde_end = xstrdup (label);
4021 dwarf2out_frame_init (void)
4023 /* Allocate the initial hunk of the fde_table. */
4024 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
4025 fde_table_allocated = FDE_TABLE_INCREMENT;
4026 fde_table_in_use = 0;
4028 /* Generate the CFA instructions common to all FDE's. Do it now for the
4029 sake of lookup_cfa. */
4031 /* On entry, the Canonical Frame Address is at SP. */
4032 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4034 #ifdef DWARF2_UNWIND_INFO
4035 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
4036 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4041 dwarf2out_frame_finish (void)
4043 /* Output call frame information. */
4044 if (DWARF2_FRAME_INFO)
4045 output_call_frame_info (0);
4047 #ifndef TARGET_UNWIND_INFO
4048 /* Output another copy for the unwinder. */
4049 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
4050 output_call_frame_info (1);
4054 /* Note that the current function section is being used for code. */
4057 dwarf2out_note_section_used (void)
4059 section *sec = current_function_section ();
4060 if (sec == text_section)
4061 text_section_used = true;
4062 else if (sec == cold_text_section)
4063 cold_text_section_used = true;
4067 dwarf2out_switch_text_section (void)
4069 dw_fde_ref fde = current_fde ();
4071 gcc_assert (cfun && fde && !fde->dw_fde_switched_sections);
4073 fde->dw_fde_switched_sections = 1;
4074 fde->dw_fde_switched_cold_to_hot = !in_cold_section_p;
4076 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
4077 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
4078 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
4079 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
4080 have_multiple_function_sections = true;
4082 /* Reset the current label on switching text sections, so that we
4083 don't attempt to advance_loc4 between labels in different sections. */
4084 fde->dw_fde_current_label = NULL;
4086 /* There is no need to mark used sections when not debugging. */
4087 if (cold_text_section != NULL)
4088 dwarf2out_note_section_used ();
4090 if (dwarf2out_do_cfi_asm ())
4091 fprintf (asm_out_file, "\t.cfi_endproc\n");
4093 /* Now do the real section switch. */
4094 switch_to_section (current_function_section ());
4096 if (dwarf2out_do_cfi_asm ())
4098 dwarf2out_do_cfi_startproc (true);
4099 /* As this is a different FDE, insert all current CFI instructions
4101 output_cfis (fde->dw_fde_cfi, true, fde, true);
4105 dw_cfi_ref cfi = fde->dw_fde_cfi;
4107 cfi = fde->dw_fde_cfi;
4109 while (cfi->dw_cfi_next != NULL)
4110 cfi = cfi->dw_cfi_next;
4111 fde->dw_fde_switch_cfi = cfi;
4116 /* And now, the subset of the debugging information support code necessary
4117 for emitting location expressions. */
4119 /* Data about a single source file. */
4120 struct GTY(()) dwarf_file_data {
4121 const char * filename;
4125 typedef struct dw_val_struct *dw_val_ref;
4126 typedef struct die_struct *dw_die_ref;
4127 typedef const struct die_struct *const_dw_die_ref;
4128 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4129 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4131 typedef struct GTY(()) deferred_locations_struct
4135 } deferred_locations;
4137 DEF_VEC_O(deferred_locations);
4138 DEF_VEC_ALLOC_O(deferred_locations,gc);
4140 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4142 /* Each DIE may have a series of attribute/value pairs. Values
4143 can take on several forms. The forms that are used in this
4144 implementation are listed below. */
4149 dw_val_class_offset,
4151 dw_val_class_loc_list,
4152 dw_val_class_range_list,
4154 dw_val_class_unsigned_const,
4155 dw_val_class_long_long,
4158 dw_val_class_die_ref,
4159 dw_val_class_fde_ref,
4160 dw_val_class_lbl_id,
4161 dw_val_class_lineptr,
4163 dw_val_class_macptr,
4167 /* Describe a floating point constant value, or a vector constant value. */
4169 typedef struct GTY(()) dw_vec_struct {
4170 unsigned char * GTY((length ("%h.length"))) array;
4176 /* The dw_val_node describes an attribute's value, as it is
4177 represented internally. */
4179 typedef struct GTY(()) dw_val_struct {
4180 enum dw_val_class val_class;
4181 union dw_val_struct_union
4183 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4184 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4185 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4186 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4187 HOST_WIDE_INT GTY ((default)) val_int;
4188 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4189 rtx GTY ((tag ("dw_val_class_long_long"))) val_long_long;
4190 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4191 struct dw_val_die_union
4195 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4196 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4197 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4198 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4199 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4200 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4202 GTY ((desc ("%1.val_class"))) v;
4206 /* Locations in memory are described using a sequence of stack machine
4209 typedef struct GTY(()) dw_loc_descr_struct {
4210 dw_loc_descr_ref dw_loc_next;
4211 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4212 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4213 from DW_OP_addr with a dtp-relative symbol relocation. */
4214 unsigned int dtprel : 1;
4216 dw_val_node dw_loc_oprnd1;
4217 dw_val_node dw_loc_oprnd2;
4221 /* Location lists are ranges + location descriptions for that range,
4222 so you can track variables that are in different places over
4223 their entire life. */
4224 typedef struct GTY(()) dw_loc_list_struct {
4225 dw_loc_list_ref dw_loc_next;
4226 const char *begin; /* Label for begin address of range */
4227 const char *end; /* Label for end address of range */
4228 char *ll_symbol; /* Label for beginning of location list.
4229 Only on head of list */
4230 const char *section; /* Section this loclist is relative to */
4231 dw_loc_descr_ref expr;
4234 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
4236 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4238 /* Convert a DWARF stack opcode into its string name. */
4241 dwarf_stack_op_name (unsigned int op)
4246 return "DW_OP_addr";
4248 return "DW_OP_deref";
4250 return "DW_OP_const1u";
4252 return "DW_OP_const1s";
4254 return "DW_OP_const2u";
4256 return "DW_OP_const2s";
4258 return "DW_OP_const4u";
4260 return "DW_OP_const4s";
4262 return "DW_OP_const8u";
4264 return "DW_OP_const8s";
4266 return "DW_OP_constu";
4268 return "DW_OP_consts";
4272 return "DW_OP_drop";
4274 return "DW_OP_over";
4276 return "DW_OP_pick";
4278 return "DW_OP_swap";
4282 return "DW_OP_xderef";
4290 return "DW_OP_minus";
4302 return "DW_OP_plus";
4303 case DW_OP_plus_uconst:
4304 return "DW_OP_plus_uconst";
4310 return "DW_OP_shra";
4328 return "DW_OP_skip";
4330 return "DW_OP_lit0";
4332 return "DW_OP_lit1";
4334 return "DW_OP_lit2";
4336 return "DW_OP_lit3";
4338 return "DW_OP_lit4";
4340 return "DW_OP_lit5";
4342 return "DW_OP_lit6";
4344 return "DW_OP_lit7";
4346 return "DW_OP_lit8";
4348 return "DW_OP_lit9";
4350 return "DW_OP_lit10";
4352 return "DW_OP_lit11";
4354 return "DW_OP_lit12";
4356 return "DW_OP_lit13";
4358 return "DW_OP_lit14";
4360 return "DW_OP_lit15";
4362 return "DW_OP_lit16";
4364 return "DW_OP_lit17";
4366 return "DW_OP_lit18";
4368 return "DW_OP_lit19";
4370 return "DW_OP_lit20";
4372 return "DW_OP_lit21";
4374 return "DW_OP_lit22";
4376 return "DW_OP_lit23";
4378 return "DW_OP_lit24";
4380 return "DW_OP_lit25";
4382 return "DW_OP_lit26";
4384 return "DW_OP_lit27";
4386 return "DW_OP_lit28";
4388 return "DW_OP_lit29";
4390 return "DW_OP_lit30";
4392 return "DW_OP_lit31";
4394 return "DW_OP_reg0";
4396 return "DW_OP_reg1";
4398 return "DW_OP_reg2";
4400 return "DW_OP_reg3";
4402 return "DW_OP_reg4";
4404 return "DW_OP_reg5";
4406 return "DW_OP_reg6";
4408 return "DW_OP_reg7";
4410 return "DW_OP_reg8";
4412 return "DW_OP_reg9";
4414 return "DW_OP_reg10";
4416 return "DW_OP_reg11";
4418 return "DW_OP_reg12";
4420 return "DW_OP_reg13";
4422 return "DW_OP_reg14";
4424 return "DW_OP_reg15";
4426 return "DW_OP_reg16";
4428 return "DW_OP_reg17";
4430 return "DW_OP_reg18";
4432 return "DW_OP_reg19";
4434 return "DW_OP_reg20";
4436 return "DW_OP_reg21";
4438 return "DW_OP_reg22";
4440 return "DW_OP_reg23";
4442 return "DW_OP_reg24";
4444 return "DW_OP_reg25";
4446 return "DW_OP_reg26";
4448 return "DW_OP_reg27";
4450 return "DW_OP_reg28";
4452 return "DW_OP_reg29";
4454 return "DW_OP_reg30";
4456 return "DW_OP_reg31";
4458 return "DW_OP_breg0";
4460 return "DW_OP_breg1";
4462 return "DW_OP_breg2";
4464 return "DW_OP_breg3";
4466 return "DW_OP_breg4";
4468 return "DW_OP_breg5";
4470 return "DW_OP_breg6";
4472 return "DW_OP_breg7";
4474 return "DW_OP_breg8";
4476 return "DW_OP_breg9";
4478 return "DW_OP_breg10";
4480 return "DW_OP_breg11";
4482 return "DW_OP_breg12";
4484 return "DW_OP_breg13";
4486 return "DW_OP_breg14";
4488 return "DW_OP_breg15";
4490 return "DW_OP_breg16";
4492 return "DW_OP_breg17";
4494 return "DW_OP_breg18";
4496 return "DW_OP_breg19";
4498 return "DW_OP_breg20";
4500 return "DW_OP_breg21";
4502 return "DW_OP_breg22";
4504 return "DW_OP_breg23";
4506 return "DW_OP_breg24";
4508 return "DW_OP_breg25";
4510 return "DW_OP_breg26";
4512 return "DW_OP_breg27";
4514 return "DW_OP_breg28";
4516 return "DW_OP_breg29";
4518 return "DW_OP_breg30";
4520 return "DW_OP_breg31";
4522 return "DW_OP_regx";
4524 return "DW_OP_fbreg";
4526 return "DW_OP_bregx";
4528 return "DW_OP_piece";
4529 case DW_OP_deref_size:
4530 return "DW_OP_deref_size";
4531 case DW_OP_xderef_size:
4532 return "DW_OP_xderef_size";
4536 case DW_OP_push_object_address:
4537 return "DW_OP_push_object_address";
4539 return "DW_OP_call2";
4541 return "DW_OP_call4";
4542 case DW_OP_call_ref:
4543 return "DW_OP_call_ref";
4544 case DW_OP_implicit_value:
4545 return "DW_OP_implicit_value";
4546 case DW_OP_stack_value:
4547 return "DW_OP_stack_value";
4548 case DW_OP_form_tls_address:
4549 return "DW_OP_form_tls_address";
4550 case DW_OP_call_frame_cfa:
4551 return "DW_OP_call_frame_cfa";
4552 case DW_OP_bit_piece:
4553 return "DW_OP_bit_piece";
4555 case DW_OP_GNU_push_tls_address:
4556 return "DW_OP_GNU_push_tls_address";
4557 case DW_OP_GNU_uninit:
4558 return "DW_OP_GNU_uninit";
4559 case DW_OP_GNU_encoded_addr:
4560 return "DW_OP_GNU_encoded_addr";
4563 return "OP_<unknown>";
4567 /* Return a pointer to a newly allocated location description. Location
4568 descriptions are simple expression terms that can be strung
4569 together to form more complicated location (address) descriptions. */
4571 static inline dw_loc_descr_ref
4572 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4573 unsigned HOST_WIDE_INT oprnd2)
4575 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4577 descr->dw_loc_opc = op;
4578 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4579 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4580 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4581 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4586 /* Return a pointer to a newly allocated location description for
4589 static inline dw_loc_descr_ref
4590 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4593 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4596 return new_loc_descr (DW_OP_bregx, reg, offset);
4599 /* Add a location description term to a location description expression. */
4602 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4604 dw_loc_descr_ref *d;
4606 /* Find the end of the chain. */
4607 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4613 /* Add a constant OFFSET to a location expression. */
4616 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4618 dw_loc_descr_ref loc;
4621 gcc_assert (*list_head != NULL);
4626 /* Find the end of the chain. */
4627 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4631 if (loc->dw_loc_opc == DW_OP_fbreg
4632 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4633 p = &loc->dw_loc_oprnd1.v.val_int;
4634 else if (loc->dw_loc_opc == DW_OP_bregx)
4635 p = &loc->dw_loc_oprnd2.v.val_int;
4637 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4638 offset. Don't optimize if an signed integer overflow would happen. */
4640 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4641 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4644 else if (offset > 0)
4645 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4649 loc->dw_loc_next = int_loc_descriptor (offset);
4650 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4654 /* Return the size of a location descriptor. */
4656 static unsigned long
4657 size_of_loc_descr (dw_loc_descr_ref loc)
4659 unsigned long size = 1;
4661 switch (loc->dw_loc_opc)
4664 size += DWARF2_ADDR_SIZE;
4683 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4686 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4691 case DW_OP_plus_uconst:
4692 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4730 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4733 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4736 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4739 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4740 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4743 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4745 case DW_OP_deref_size:
4746 case DW_OP_xderef_size:
4755 case DW_OP_call_ref:
4756 size += DWARF2_ADDR_SIZE;
4758 case DW_OP_implicit_value:
4759 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4760 + loc->dw_loc_oprnd1.v.val_unsigned;
4769 /* Return the size of a series of location descriptors. */
4771 static unsigned long
4772 size_of_locs (dw_loc_descr_ref loc)
4777 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4778 field, to avoid writing to a PCH file. */
4779 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4781 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4783 size += size_of_loc_descr (l);
4788 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4790 l->dw_loc_addr = size;
4791 size += size_of_loc_descr (l);
4797 #ifdef DWARF2_DEBUGGING_INFO
4798 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4801 /* Output location description stack opcode's operands (if any). */
4804 output_loc_operands (dw_loc_descr_ref loc)
4806 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4807 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4809 switch (loc->dw_loc_opc)
4811 #ifdef DWARF2_DEBUGGING_INFO
4814 dw2_asm_output_data (2, val1->v.val_int, NULL);
4818 dw2_asm_output_data (4, val1->v.val_int, NULL);
4822 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
4823 dw2_asm_output_data (8, val1->v.val_int, NULL);
4830 gcc_assert (val1->val_class == dw_val_class_loc);
4831 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4833 dw2_asm_output_data (2, offset, NULL);
4836 case DW_OP_implicit_value:
4837 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4838 switch (val2->val_class)
4840 case dw_val_class_const:
4841 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
4843 case dw_val_class_vec:
4845 unsigned int elt_size = val2->v.val_vec.elt_size;
4846 unsigned int len = val2->v.val_vec.length;
4850 if (elt_size > sizeof (HOST_WIDE_INT))
4855 for (i = 0, p = val2->v.val_vec.array;
4858 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
4859 "fp or vector constant word %u", i);
4862 case dw_val_class_long_long:
4864 unsigned HOST_WIDE_INT first, second;
4866 if (WORDS_BIG_ENDIAN)
4868 first = CONST_DOUBLE_HIGH (val2->v.val_long_long);
4869 second = CONST_DOUBLE_LOW (val2->v.val_long_long);
4873 first = CONST_DOUBLE_LOW (val2->v.val_long_long);
4874 second = CONST_DOUBLE_HIGH (val2->v.val_long_long);
4876 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4877 first, "long long constant");
4878 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
4882 case dw_val_class_addr:
4883 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
4884 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
4899 case DW_OP_implicit_value:
4900 /* We currently don't make any attempt to make sure these are
4901 aligned properly like we do for the main unwind info, so
4902 don't support emitting things larger than a byte if we're
4903 only doing unwinding. */
4908 dw2_asm_output_data (1, val1->v.val_int, NULL);
4911 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4914 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4917 dw2_asm_output_data (1, val1->v.val_int, NULL);
4919 case DW_OP_plus_uconst:
4920 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4954 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4957 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4960 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4963 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4964 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4967 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4969 case DW_OP_deref_size:
4970 case DW_OP_xderef_size:
4971 dw2_asm_output_data (1, val1->v.val_int, NULL);
4977 if (targetm.asm_out.output_dwarf_dtprel)
4979 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4982 fputc ('\n', asm_out_file);
4989 #ifdef DWARF2_DEBUGGING_INFO
4990 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4998 /* Other codes have no operands. */
5003 /* Output a sequence of location operations. */
5006 output_loc_sequence (dw_loc_descr_ref loc)
5008 for (; loc != NULL; loc = loc->dw_loc_next)
5010 /* Output the opcode. */
5011 dw2_asm_output_data (1, loc->dw_loc_opc,
5012 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
5014 /* Output the operand(s) (if any). */
5015 output_loc_operands (loc);
5019 /* Output location description stack opcode's operands (if any).
5020 The output is single bytes on a line, suitable for .cfi_escape. */
5023 output_loc_operands_raw (dw_loc_descr_ref loc)
5025 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5026 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5028 switch (loc->dw_loc_opc)
5031 case DW_OP_implicit_value:
5032 /* We cannot output addresses in .cfi_escape, only bytes. */
5038 case DW_OP_deref_size:
5039 case DW_OP_xderef_size:
5040 fputc (',', asm_out_file);
5041 dw2_asm_output_data_raw (1, val1->v.val_int);
5046 fputc (',', asm_out_file);
5047 dw2_asm_output_data_raw (2, val1->v.val_int);
5052 fputc (',', asm_out_file);
5053 dw2_asm_output_data_raw (4, val1->v.val_int);
5058 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5059 fputc (',', asm_out_file);
5060 dw2_asm_output_data_raw (8, val1->v.val_int);
5068 gcc_assert (val1->val_class == dw_val_class_loc);
5069 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5071 fputc (',', asm_out_file);
5072 dw2_asm_output_data_raw (2, offset);
5077 case DW_OP_plus_uconst:
5080 fputc (',', asm_out_file);
5081 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5118 fputc (',', asm_out_file);
5119 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5123 fputc (',', asm_out_file);
5124 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5125 fputc (',', asm_out_file);
5126 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5130 /* Other codes have no operands. */
5136 output_loc_sequence_raw (dw_loc_descr_ref loc)
5140 /* Output the opcode. */
5141 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
5142 output_loc_operands_raw (loc);
5144 if (!loc->dw_loc_next)
5146 loc = loc->dw_loc_next;
5148 fputc (',', asm_out_file);
5152 /* This routine will generate the correct assembly data for a location
5153 description based on a cfi entry with a complex address. */
5156 output_cfa_loc (dw_cfi_ref cfi)
5158 dw_loc_descr_ref loc;
5161 if (cfi->dw_cfi_opc == DW_CFA_expression)
5162 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
5164 /* Output the size of the block. */
5165 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5166 size = size_of_locs (loc);
5167 dw2_asm_output_data_uleb128 (size, NULL);
5169 /* Now output the operations themselves. */
5170 output_loc_sequence (loc);
5173 /* Similar, but used for .cfi_escape. */
5176 output_cfa_loc_raw (dw_cfi_ref cfi)
5178 dw_loc_descr_ref loc;
5181 if (cfi->dw_cfi_opc == DW_CFA_expression)
5182 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
5184 /* Output the size of the block. */
5185 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5186 size = size_of_locs (loc);
5187 dw2_asm_output_data_uleb128_raw (size);
5188 fputc (',', asm_out_file);
5190 /* Now output the operations themselves. */
5191 output_loc_sequence_raw (loc);
5194 /* This function builds a dwarf location descriptor sequence from a
5195 dw_cfa_location, adding the given OFFSET to the result of the
5198 static struct dw_loc_descr_struct *
5199 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5201 struct dw_loc_descr_struct *head, *tmp;
5203 offset += cfa->offset;
5207 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5208 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5209 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5210 add_loc_descr (&head, tmp);
5213 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5214 add_loc_descr (&head, tmp);
5218 head = new_reg_loc_descr (cfa->reg, offset);
5223 /* This function builds a dwarf location descriptor sequence for
5224 the address at OFFSET from the CFA when stack is aligned to
5227 static struct dw_loc_descr_struct *
5228 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5230 struct dw_loc_descr_struct *head;
5231 unsigned int dwarf_fp
5232 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5234 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5235 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5237 head = new_reg_loc_descr (dwarf_fp, 0);
5238 add_loc_descr (&head, int_loc_descriptor (alignment));
5239 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5240 loc_descr_plus_const (&head, offset);
5243 head = new_reg_loc_descr (dwarf_fp, offset);
5247 /* This function fills in aa dw_cfa_location structure from a dwarf location
5248 descriptor sequence. */
5251 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5253 struct dw_loc_descr_struct *ptr;
5255 cfa->base_offset = 0;
5259 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5261 enum dwarf_location_atom op = ptr->dw_loc_opc;
5297 cfa->reg = op - DW_OP_reg0;
5300 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5334 cfa->reg = op - DW_OP_breg0;
5335 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5338 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5339 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5344 case DW_OP_plus_uconst:
5345 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5348 internal_error ("DW_LOC_OP %s not implemented",
5349 dwarf_stack_op_name (ptr->dw_loc_opc));
5353 #endif /* .debug_frame support */
5355 /* And now, the support for symbolic debugging information. */
5356 #ifdef DWARF2_DEBUGGING_INFO
5358 /* .debug_str support. */
5359 static int output_indirect_string (void **, void *);
5361 static void dwarf2out_init (const char *);
5362 static void dwarf2out_finish (const char *);
5363 static void dwarf2out_define (unsigned int, const char *);
5364 static void dwarf2out_undef (unsigned int, const char *);
5365 static void dwarf2out_start_source_file (unsigned, const char *);
5366 static void dwarf2out_end_source_file (unsigned);
5367 static void dwarf2out_begin_block (unsigned, unsigned);
5368 static void dwarf2out_end_block (unsigned, unsigned);
5369 static bool dwarf2out_ignore_block (const_tree);
5370 static void dwarf2out_global_decl (tree);
5371 static void dwarf2out_type_decl (tree, int);
5372 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5373 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5375 static void dwarf2out_abstract_function (tree);
5376 static void dwarf2out_var_location (rtx);
5377 static void dwarf2out_begin_function (tree);
5378 static void dwarf2out_set_name (tree, tree);
5380 /* The debug hooks structure. */
5382 const struct gcc_debug_hooks dwarf2_debug_hooks =
5388 dwarf2out_start_source_file,
5389 dwarf2out_end_source_file,
5390 dwarf2out_begin_block,
5391 dwarf2out_end_block,
5392 dwarf2out_ignore_block,
5393 dwarf2out_source_line,
5394 dwarf2out_begin_prologue,
5395 debug_nothing_int_charstar, /* end_prologue */
5396 dwarf2out_end_epilogue,
5397 dwarf2out_begin_function,
5398 debug_nothing_int, /* end_function */
5399 dwarf2out_decl, /* function_decl */
5400 dwarf2out_global_decl,
5401 dwarf2out_type_decl, /* type_decl */
5402 dwarf2out_imported_module_or_decl,
5403 debug_nothing_tree, /* deferred_inline_function */
5404 /* The DWARF 2 backend tries to reduce debugging bloat by not
5405 emitting the abstract description of inline functions until
5406 something tries to reference them. */
5407 dwarf2out_abstract_function, /* outlining_inline_function */
5408 debug_nothing_rtx, /* label */
5409 debug_nothing_int, /* handle_pch */
5410 dwarf2out_var_location,
5411 dwarf2out_switch_text_section,
5413 1 /* start_end_main_source_file */
5417 /* NOTE: In the comments in this file, many references are made to
5418 "Debugging Information Entries". This term is abbreviated as `DIE'
5419 throughout the remainder of this file. */
5421 /* An internal representation of the DWARF output is built, and then
5422 walked to generate the DWARF debugging info. The walk of the internal
5423 representation is done after the entire program has been compiled.
5424 The types below are used to describe the internal representation. */
5426 /* Various DIE's use offsets relative to the beginning of the
5427 .debug_info section to refer to each other. */
5429 typedef long int dw_offset;
5431 /* Define typedefs here to avoid circular dependencies. */
5433 typedef struct dw_attr_struct *dw_attr_ref;
5434 typedef struct dw_line_info_struct *dw_line_info_ref;
5435 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
5436 typedef struct pubname_struct *pubname_ref;
5437 typedef struct dw_ranges_struct *dw_ranges_ref;
5438 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5440 /* Each entry in the line_info_table maintains the file and
5441 line number associated with the label generated for that
5442 entry. The label gives the PC value associated with
5443 the line number entry. */
5445 typedef struct GTY(()) dw_line_info_struct {
5446 unsigned long dw_file_num;
5447 unsigned long dw_line_num;
5451 /* Line information for functions in separate sections; each one gets its
5453 typedef struct GTY(()) dw_separate_line_info_struct {
5454 unsigned long dw_file_num;
5455 unsigned long dw_line_num;
5456 unsigned long function;
5458 dw_separate_line_info_entry;
5460 /* Each DIE attribute has a field specifying the attribute kind,
5461 a link to the next attribute in the chain, and an attribute value.
5462 Attributes are typically linked below the DIE they modify. */
5464 typedef struct GTY(()) dw_attr_struct {
5465 enum dwarf_attribute dw_attr;
5466 dw_val_node dw_attr_val;
5470 DEF_VEC_O(dw_attr_node);
5471 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5473 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5474 The children of each node form a circular list linked by
5475 die_sib. die_child points to the node *before* the "first" child node. */
5477 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5478 enum dwarf_tag die_tag;
5480 VEC(dw_attr_node,gc) * die_attr;
5481 dw_die_ref die_parent;
5482 dw_die_ref die_child;
5484 dw_die_ref die_definition; /* ref from a specification to its definition */
5485 dw_offset die_offset;
5486 unsigned long die_abbrev;
5488 /* Die is used and must not be pruned as unused. */
5489 int die_perennial_p;
5490 unsigned int decl_id;
5494 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5495 #define FOR_EACH_CHILD(die, c, expr) do { \
5496 c = die->die_child; \
5500 } while (c != die->die_child); \
5503 /* The pubname structure */
5505 typedef struct GTY(()) pubname_struct {
5511 DEF_VEC_O(pubname_entry);
5512 DEF_VEC_ALLOC_O(pubname_entry, gc);
5514 struct GTY(()) dw_ranges_struct {
5515 /* If this is positive, it's a block number, otherwise it's a
5516 bitwise-negated index into dw_ranges_by_label. */
5520 struct GTY(()) dw_ranges_by_label_struct {
5525 /* The limbo die list structure. */
5526 typedef struct GTY(()) limbo_die_struct {
5529 struct limbo_die_struct *next;
5533 /* How to start an assembler comment. */
5534 #ifndef ASM_COMMENT_START
5535 #define ASM_COMMENT_START ";#"
5538 /* Define a macro which returns nonzero for a TYPE_DECL which was
5539 implicitly generated for a tagged type.
5541 Note that unlike the gcc front end (which generates a NULL named
5542 TYPE_DECL node for each complete tagged type, each array type, and
5543 each function type node created) the g++ front end generates a
5544 _named_ TYPE_DECL node for each tagged type node created.
5545 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5546 generate a DW_TAG_typedef DIE for them. */
5548 #define TYPE_DECL_IS_STUB(decl) \
5549 (DECL_NAME (decl) == NULL_TREE \
5550 || (DECL_ARTIFICIAL (decl) \
5551 && is_tagged_type (TREE_TYPE (decl)) \
5552 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5553 /* This is necessary for stub decls that \
5554 appear in nested inline functions. */ \
5555 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5556 && (decl_ultimate_origin (decl) \
5557 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5559 /* Information concerning the compilation unit's programming
5560 language, and compiler version. */
5562 /* Fixed size portion of the DWARF compilation unit header. */
5563 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5564 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5566 /* Fixed size portion of public names info. */
5567 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5569 /* Fixed size portion of the address range info. */
5570 #define DWARF_ARANGES_HEADER_SIZE \
5571 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5572 DWARF2_ADDR_SIZE * 2) \
5573 - DWARF_INITIAL_LENGTH_SIZE)
5575 /* Size of padding portion in the address range info. It must be
5576 aligned to twice the pointer size. */
5577 #define DWARF_ARANGES_PAD_SIZE \
5578 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5579 DWARF2_ADDR_SIZE * 2) \
5580 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5582 /* Use assembler line directives if available. */
5583 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5584 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5585 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5587 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5591 /* Minimum line offset in a special line info. opcode.
5592 This value was chosen to give a reasonable range of values. */
5593 #define DWARF_LINE_BASE -10
5595 /* First special line opcode - leave room for the standard opcodes. */
5596 #define DWARF_LINE_OPCODE_BASE 10
5598 /* Range of line offsets in a special line info. opcode. */
5599 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5601 /* Flag that indicates the initial value of the is_stmt_start flag.
5602 In the present implementation, we do not mark any lines as
5603 the beginning of a source statement, because that information
5604 is not made available by the GCC front-end. */
5605 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5607 #ifdef DWARF2_DEBUGGING_INFO
5608 /* This location is used by calc_die_sizes() to keep track
5609 the offset of each DIE within the .debug_info section. */
5610 static unsigned long next_die_offset;
5613 /* Record the root of the DIE's built for the current compilation unit. */
5614 static GTY(()) dw_die_ref comp_unit_die;
5616 /* A list of DIEs with a NULL parent waiting to be relocated. */
5617 static GTY(()) limbo_die_node *limbo_die_list;
5619 /* A list of DIEs for which we may have to generate
5620 DW_AT_MIPS_linkage_name once their DECL_ASSEMBLER_NAMEs are
5622 static GTY(()) limbo_die_node *deferred_asm_name;
5624 /* Filenames referenced by this compilation unit. */
5625 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5627 /* A hash table of references to DIE's that describe declarations.
5628 The key is a DECL_UID() which is a unique number identifying each decl. */
5629 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5631 /* A hash table of references to DIE's that describe COMMON blocks.
5632 The key is DECL_UID() ^ die_parent. */
5633 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5635 typedef struct GTY(()) die_arg_entry_struct {
5640 DEF_VEC_O(die_arg_entry);
5641 DEF_VEC_ALLOC_O(die_arg_entry,gc);
5643 /* Node of the variable location list. */
5644 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5645 rtx GTY (()) var_loc_note;
5646 const char * GTY (()) label;
5647 const char * GTY (()) section_label;
5648 struct var_loc_node * GTY (()) next;
5651 /* Variable location list. */
5652 struct GTY (()) var_loc_list_def {
5653 struct var_loc_node * GTY (()) first;
5655 /* Do not mark the last element of the chained list because
5656 it is marked through the chain. */
5657 struct var_loc_node * GTY ((skip ("%h"))) last;
5659 /* DECL_UID of the variable decl. */
5660 unsigned int decl_id;
5662 typedef struct var_loc_list_def var_loc_list;
5665 /* Table of decl location linked lists. */
5666 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5668 /* A pointer to the base of a list of references to DIE's that
5669 are uniquely identified by their tag, presence/absence of
5670 children DIE's, and list of attribute/value pairs. */
5671 static GTY((length ("abbrev_die_table_allocated")))
5672 dw_die_ref *abbrev_die_table;
5674 /* Number of elements currently allocated for abbrev_die_table. */
5675 static GTY(()) unsigned abbrev_die_table_allocated;
5677 /* Number of elements in type_die_table currently in use. */
5678 static GTY(()) unsigned abbrev_die_table_in_use;
5680 /* Size (in elements) of increments by which we may expand the
5681 abbrev_die_table. */
5682 #define ABBREV_DIE_TABLE_INCREMENT 256
5684 /* A pointer to the base of a table that contains line information
5685 for each source code line in .text in the compilation unit. */
5686 static GTY((length ("line_info_table_allocated")))
5687 dw_line_info_ref line_info_table;
5689 /* Number of elements currently allocated for line_info_table. */
5690 static GTY(()) unsigned line_info_table_allocated;
5692 /* Number of elements in line_info_table currently in use. */
5693 static GTY(()) unsigned line_info_table_in_use;
5695 /* A pointer to the base of a table that contains line information
5696 for each source code line outside of .text in the compilation unit. */
5697 static GTY ((length ("separate_line_info_table_allocated")))
5698 dw_separate_line_info_ref separate_line_info_table;
5700 /* Number of elements currently allocated for separate_line_info_table. */
5701 static GTY(()) unsigned separate_line_info_table_allocated;
5703 /* Number of elements in separate_line_info_table currently in use. */
5704 static GTY(()) unsigned separate_line_info_table_in_use;
5706 /* Size (in elements) of increments by which we may expand the
5708 #define LINE_INFO_TABLE_INCREMENT 1024
5710 /* A pointer to the base of a table that contains a list of publicly
5711 accessible names. */
5712 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5714 /* A pointer to the base of a table that contains a list of publicly
5715 accessible types. */
5716 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5718 /* Array of dies for which we should generate .debug_arange info. */
5719 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5721 /* Number of elements currently allocated for arange_table. */
5722 static GTY(()) unsigned arange_table_allocated;
5724 /* Number of elements in arange_table currently in use. */
5725 static GTY(()) unsigned arange_table_in_use;
5727 /* Size (in elements) of increments by which we may expand the
5729 #define ARANGE_TABLE_INCREMENT 64
5731 /* Array of dies for which we should generate .debug_ranges info. */
5732 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5734 /* Number of elements currently allocated for ranges_table. */
5735 static GTY(()) unsigned ranges_table_allocated;
5737 /* Number of elements in ranges_table currently in use. */
5738 static GTY(()) unsigned ranges_table_in_use;
5740 /* Array of pairs of labels referenced in ranges_table. */
5741 static GTY ((length ("ranges_by_label_allocated")))
5742 dw_ranges_by_label_ref ranges_by_label;
5744 /* Number of elements currently allocated for ranges_by_label. */
5745 static GTY(()) unsigned ranges_by_label_allocated;
5747 /* Number of elements in ranges_by_label currently in use. */
5748 static GTY(()) unsigned ranges_by_label_in_use;
5750 /* Size (in elements) of increments by which we may expand the
5752 #define RANGES_TABLE_INCREMENT 64
5754 /* Whether we have location lists that need outputting */
5755 static GTY(()) bool have_location_lists;
5757 /* Unique label counter. */
5758 static GTY(()) unsigned int loclabel_num;
5760 #ifdef DWARF2_DEBUGGING_INFO
5761 /* Record whether the function being analyzed contains inlined functions. */
5762 static int current_function_has_inlines;
5764 #if 0 && defined (MIPS_DEBUGGING_INFO)
5765 static int comp_unit_has_inlines;
5768 /* The last file entry emitted by maybe_emit_file(). */
5769 static GTY(()) struct dwarf_file_data * last_emitted_file;
5771 /* Number of internal labels generated by gen_internal_sym(). */
5772 static GTY(()) int label_num;
5774 /* Cached result of previous call to lookup_filename. */
5775 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5777 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
5779 #ifdef DWARF2_DEBUGGING_INFO
5781 /* Offset from the "steady-state frame pointer" to the frame base,
5782 within the current function. */
5783 static HOST_WIDE_INT frame_pointer_fb_offset;
5785 /* Forward declarations for functions defined in this file. */
5787 static int is_pseudo_reg (const_rtx);
5788 static tree type_main_variant (tree);
5789 static int is_tagged_type (const_tree);
5790 static const char *dwarf_tag_name (unsigned);
5791 static const char *dwarf_attr_name (unsigned);
5792 static const char *dwarf_form_name (unsigned);
5793 static tree decl_ultimate_origin (const_tree);
5794 static tree decl_class_context (tree);
5795 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5796 static inline enum dw_val_class AT_class (dw_attr_ref);
5797 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5798 static inline unsigned AT_flag (dw_attr_ref);
5799 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5800 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5801 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5802 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5803 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, rtx);
5804 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5805 unsigned int, unsigned char *);
5806 static hashval_t debug_str_do_hash (const void *);
5807 static int debug_str_eq (const void *, const void *);
5808 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5809 static inline const char *AT_string (dw_attr_ref);
5810 static enum dwarf_form AT_string_form (dw_attr_ref);
5811 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5812 static void add_AT_specification (dw_die_ref, dw_die_ref);
5813 static inline dw_die_ref AT_ref (dw_attr_ref);
5814 static inline int AT_ref_external (dw_attr_ref);
5815 static inline void set_AT_ref_external (dw_attr_ref, int);
5816 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5817 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5818 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5819 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5821 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5822 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5823 static inline rtx AT_addr (dw_attr_ref);
5824 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5825 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5826 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5827 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5828 unsigned HOST_WIDE_INT);
5829 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5831 static inline const char *AT_lbl (dw_attr_ref);
5832 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5833 static const char *get_AT_low_pc (dw_die_ref);
5834 static const char *get_AT_hi_pc (dw_die_ref);
5835 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5836 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5837 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5838 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5839 static bool is_c_family (void);
5840 static bool is_cxx (void);
5841 static bool is_java (void);
5842 static bool is_fortran (void);
5843 static bool is_ada (void);
5844 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5845 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5846 static void add_child_die (dw_die_ref, dw_die_ref);
5847 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5848 static dw_die_ref lookup_type_die (tree);
5849 static void equate_type_number_to_die (tree, dw_die_ref);
5850 static hashval_t decl_die_table_hash (const void *);
5851 static int decl_die_table_eq (const void *, const void *);
5852 static dw_die_ref lookup_decl_die (tree);
5853 static hashval_t common_block_die_table_hash (const void *);
5854 static int common_block_die_table_eq (const void *, const void *);
5855 static hashval_t decl_loc_table_hash (const void *);
5856 static int decl_loc_table_eq (const void *, const void *);
5857 static var_loc_list *lookup_decl_loc (const_tree);
5858 static void equate_decl_number_to_die (tree, dw_die_ref);
5859 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5860 static void print_spaces (FILE *);
5861 static void print_die (dw_die_ref, FILE *);
5862 static void print_dwarf_line_table (FILE *);
5863 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5864 static dw_die_ref pop_compile_unit (dw_die_ref);
5865 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5866 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5867 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5868 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5869 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5870 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5871 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5872 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5873 static void compute_section_prefix (dw_die_ref);
5874 static int is_type_die (dw_die_ref);
5875 static int is_comdat_die (dw_die_ref);
5876 static int is_symbol_die (dw_die_ref);
5877 static void assign_symbol_names (dw_die_ref);
5878 static void break_out_includes (dw_die_ref);
5879 static hashval_t htab_cu_hash (const void *);
5880 static int htab_cu_eq (const void *, const void *);
5881 static void htab_cu_del (void *);
5882 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5883 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5884 static void add_sibling_attributes (dw_die_ref);
5885 static void build_abbrev_table (dw_die_ref);
5886 static void output_location_lists (dw_die_ref);
5887 static int constant_size (unsigned HOST_WIDE_INT);
5888 static unsigned long size_of_die (dw_die_ref);
5889 static void calc_die_sizes (dw_die_ref);
5890 static void mark_dies (dw_die_ref);
5891 static void unmark_dies (dw_die_ref);
5892 static void unmark_all_dies (dw_die_ref);
5893 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5894 static unsigned long size_of_aranges (void);
5895 static enum dwarf_form value_format (dw_attr_ref);
5896 static void output_value_format (dw_attr_ref);
5897 static void output_abbrev_section (void);
5898 static void output_die_symbol (dw_die_ref);
5899 static void output_die (dw_die_ref);
5900 static void output_compilation_unit_header (void);
5901 static void output_comp_unit (dw_die_ref, int);
5902 static const char *dwarf2_name (tree, int);
5903 static void add_pubname (tree, dw_die_ref);
5904 static void add_pubname_string (const char *, dw_die_ref);
5905 static void add_pubtype (tree, dw_die_ref);
5906 static void output_pubnames (VEC (pubname_entry,gc) *);
5907 static void add_arange (tree, dw_die_ref);
5908 static void output_aranges (void);
5909 static unsigned int add_ranges_num (int);
5910 static unsigned int add_ranges (const_tree);
5911 static unsigned int add_ranges_by_labels (const char *, const char *);
5912 static void output_ranges (void);
5913 static void output_line_info (void);
5914 static void output_file_names (void);
5915 static dw_die_ref base_type_die (tree);
5916 static int is_base_type (tree);
5917 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5918 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5919 static dw_die_ref generic_parameter_die (tree, tree, dw_die_ref, int);
5920 static int type_is_enum (const_tree);
5921 static unsigned int dbx_reg_number (const_rtx);
5922 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5923 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5924 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5925 enum var_init_status);
5926 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5927 enum var_init_status);
5928 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5929 enum var_init_status);
5930 static int is_based_loc (const_rtx);
5931 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5932 enum var_init_status);
5933 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5934 enum var_init_status);
5935 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
5936 enum var_init_status);
5937 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5938 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5939 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5940 static tree field_type (const_tree);
5941 static unsigned int simple_type_align_in_bits (const_tree);
5942 static unsigned int simple_decl_align_in_bits (const_tree);
5943 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5944 static HOST_WIDE_INT field_byte_offset (const_tree);
5945 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5947 static void add_data_member_location_attribute (dw_die_ref, tree);
5948 static void add_const_value_attribute (dw_die_ref, rtx);
5949 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5950 static void insert_float (const_rtx, unsigned char *);
5951 static rtx rtl_for_decl_location (tree);
5952 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5953 enum dwarf_attribute);
5954 static void tree_add_const_value_attribute (dw_die_ref, tree);
5955 static void tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
5956 static void add_name_attribute (dw_die_ref, const char *);
5957 static void add_comp_dir_attribute (dw_die_ref);
5958 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5959 static void add_subscript_info (dw_die_ref, tree, bool);
5960 static void add_byte_size_attribute (dw_die_ref, tree);
5961 static void add_bit_offset_attribute (dw_die_ref, tree);
5962 static void add_bit_size_attribute (dw_die_ref, tree);
5963 static void add_prototyped_attribute (dw_die_ref, tree);
5964 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5965 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5966 static void add_src_coords_attributes (dw_die_ref, tree);
5967 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5968 static void push_decl_scope (tree);
5969 static void pop_decl_scope (void);
5970 static dw_die_ref scope_die_for (tree, dw_die_ref);
5971 static inline int local_scope_p (dw_die_ref);
5972 static inline int class_scope_p (dw_die_ref);
5973 static inline int class_or_namespace_scope_p (dw_die_ref);
5974 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5975 static void add_calling_convention_attribute (dw_die_ref, tree);
5976 static const char *type_tag (const_tree);
5977 static tree member_declared_type (const_tree);
5979 static const char *decl_start_label (tree);
5981 static void gen_array_type_die (tree, dw_die_ref);
5982 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5984 static void gen_entry_point_die (tree, dw_die_ref);
5986 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5987 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5988 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5989 static void gen_formal_types_die (tree, dw_die_ref);
5990 static void gen_subprogram_die (tree, dw_die_ref);
5991 static void gen_variable_die (tree, tree, dw_die_ref);
5992 static void gen_const_die (tree, dw_die_ref);
5993 static void gen_label_die (tree, dw_die_ref);
5994 static void gen_lexical_block_die (tree, dw_die_ref, int);
5995 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5996 static void gen_field_die (tree, dw_die_ref);
5997 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5998 static dw_die_ref gen_compile_unit_die (const char *);
5999 static void gen_inheritance_die (tree, tree, dw_die_ref);
6000 static void gen_member_die (tree, dw_die_ref);
6001 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6002 enum debug_info_usage);
6003 static void gen_subroutine_type_die (tree, dw_die_ref);
6004 static void gen_typedef_die (tree, dw_die_ref);
6005 static void gen_type_die (tree, dw_die_ref);
6006 static void gen_block_die (tree, dw_die_ref, int);
6007 static void decls_for_scope (tree, dw_die_ref, int);
6008 static int is_redundant_typedef (const_tree);
6009 static inline dw_die_ref get_context_die (tree);
6010 static void gen_namespace_die (tree, dw_die_ref);
6011 static void gen_decl_die (tree, tree, dw_die_ref);
6012 static dw_die_ref force_decl_die (tree);
6013 static dw_die_ref force_type_die (tree);
6014 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6015 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6016 static struct dwarf_file_data * lookup_filename (const char *);
6017 static void retry_incomplete_types (void);
6018 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6019 static tree make_ith_pack_parameter_name (tree, int);
6020 static void gen_generic_params_dies (tree);
6021 static void splice_child_die (dw_die_ref, dw_die_ref);
6022 static int file_info_cmp (const void *, const void *);
6023 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6024 const char *, const char *, unsigned);
6025 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
6026 const char *, const char *,
6028 static void output_loc_list (dw_loc_list_ref);
6029 static char *gen_internal_sym (const char *);
6031 static void prune_unmark_dies (dw_die_ref);
6032 static void prune_unused_types_mark (dw_die_ref, int);
6033 static void prune_unused_types_walk (dw_die_ref);
6034 static void prune_unused_types_walk_attribs (dw_die_ref);
6035 static void prune_unused_types_prune (dw_die_ref);
6036 static void prune_unused_types (void);
6037 static int maybe_emit_file (struct dwarf_file_data *fd);
6038 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6039 static void gen_remaining_tmpl_value_param_die_attribute (void);
6041 /* Section names used to hold DWARF debugging information. */
6042 #ifndef DEBUG_INFO_SECTION
6043 #define DEBUG_INFO_SECTION ".debug_info"
6045 #ifndef DEBUG_ABBREV_SECTION
6046 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6048 #ifndef DEBUG_ARANGES_SECTION
6049 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6051 #ifndef DEBUG_MACINFO_SECTION
6052 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6054 #ifndef DEBUG_LINE_SECTION
6055 #define DEBUG_LINE_SECTION ".debug_line"
6057 #ifndef DEBUG_LOC_SECTION
6058 #define DEBUG_LOC_SECTION ".debug_loc"
6060 #ifndef DEBUG_PUBNAMES_SECTION
6061 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6063 #ifndef DEBUG_PUBTYPES_SECTION
6064 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6066 #ifndef DEBUG_STR_SECTION
6067 #define DEBUG_STR_SECTION ".debug_str"
6069 #ifndef DEBUG_RANGES_SECTION
6070 #define DEBUG_RANGES_SECTION ".debug_ranges"
6073 /* Standard ELF section names for compiled code and data. */
6074 #ifndef TEXT_SECTION_NAME
6075 #define TEXT_SECTION_NAME ".text"
6078 /* Section flags for .debug_str section. */
6079 #define DEBUG_STR_SECTION_FLAGS \
6080 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6081 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6084 /* Labels we insert at beginning sections we can reference instead of
6085 the section names themselves. */
6087 #ifndef TEXT_SECTION_LABEL
6088 #define TEXT_SECTION_LABEL "Ltext"
6090 #ifndef COLD_TEXT_SECTION_LABEL
6091 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6093 #ifndef DEBUG_LINE_SECTION_LABEL
6094 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6096 #ifndef DEBUG_INFO_SECTION_LABEL
6097 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6099 #ifndef DEBUG_ABBREV_SECTION_LABEL
6100 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6102 #ifndef DEBUG_LOC_SECTION_LABEL
6103 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6105 #ifndef DEBUG_RANGES_SECTION_LABEL
6106 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6108 #ifndef DEBUG_MACINFO_SECTION_LABEL
6109 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6112 /* Definitions of defaults for formats and names of various special
6113 (artificial) labels which may be generated within this file (when the -g
6114 options is used and DWARF2_DEBUGGING_INFO is in effect.
6115 If necessary, these may be overridden from within the tm.h file, but
6116 typically, overriding these defaults is unnecessary. */
6118 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6119 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6120 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6121 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6122 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6123 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6124 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6125 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6126 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6127 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6129 #ifndef TEXT_END_LABEL
6130 #define TEXT_END_LABEL "Letext"
6132 #ifndef COLD_END_LABEL
6133 #define COLD_END_LABEL "Letext_cold"
6135 #ifndef BLOCK_BEGIN_LABEL
6136 #define BLOCK_BEGIN_LABEL "LBB"
6138 #ifndef BLOCK_END_LABEL
6139 #define BLOCK_END_LABEL "LBE"
6141 #ifndef LINE_CODE_LABEL
6142 #define LINE_CODE_LABEL "LM"
6144 #ifndef SEPARATE_LINE_CODE_LABEL
6145 #define SEPARATE_LINE_CODE_LABEL "LSM"
6149 /* We allow a language front-end to designate a function that is to be
6150 called to "demangle" any name before it is put into a DIE. */
6152 static const char *(*demangle_name_func) (const char *);
6155 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6157 demangle_name_func = func;
6160 /* Test if rtl node points to a pseudo register. */
6163 is_pseudo_reg (const_rtx rtl)
6165 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6166 || (GET_CODE (rtl) == SUBREG
6167 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6170 /* Return a reference to a type, with its const and volatile qualifiers
6174 type_main_variant (tree type)
6176 type = TYPE_MAIN_VARIANT (type);
6178 /* ??? There really should be only one main variant among any group of
6179 variants of a given type (and all of the MAIN_VARIANT values for all
6180 members of the group should point to that one type) but sometimes the C
6181 front-end messes this up for array types, so we work around that bug
6183 if (TREE_CODE (type) == ARRAY_TYPE)
6184 while (type != TYPE_MAIN_VARIANT (type))
6185 type = TYPE_MAIN_VARIANT (type);
6190 /* Return nonzero if the given type node represents a tagged type. */
6193 is_tagged_type (const_tree type)
6195 enum tree_code code = TREE_CODE (type);
6197 return (code == RECORD_TYPE || code == UNION_TYPE
6198 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6201 /* Convert a DIE tag into its string name. */
6204 dwarf_tag_name (unsigned int tag)
6208 case DW_TAG_padding:
6209 return "DW_TAG_padding";
6210 case DW_TAG_array_type:
6211 return "DW_TAG_array_type";
6212 case DW_TAG_class_type:
6213 return "DW_TAG_class_type";
6214 case DW_TAG_entry_point:
6215 return "DW_TAG_entry_point";
6216 case DW_TAG_enumeration_type:
6217 return "DW_TAG_enumeration_type";
6218 case DW_TAG_formal_parameter:
6219 return "DW_TAG_formal_parameter";
6220 case DW_TAG_imported_declaration:
6221 return "DW_TAG_imported_declaration";
6223 return "DW_TAG_label";
6224 case DW_TAG_lexical_block:
6225 return "DW_TAG_lexical_block";
6227 return "DW_TAG_member";
6228 case DW_TAG_pointer_type:
6229 return "DW_TAG_pointer_type";
6230 case DW_TAG_reference_type:
6231 return "DW_TAG_reference_type";
6232 case DW_TAG_compile_unit:
6233 return "DW_TAG_compile_unit";
6234 case DW_TAG_string_type:
6235 return "DW_TAG_string_type";
6236 case DW_TAG_structure_type:
6237 return "DW_TAG_structure_type";
6238 case DW_TAG_subroutine_type:
6239 return "DW_TAG_subroutine_type";
6240 case DW_TAG_typedef:
6241 return "DW_TAG_typedef";
6242 case DW_TAG_union_type:
6243 return "DW_TAG_union_type";
6244 case DW_TAG_unspecified_parameters:
6245 return "DW_TAG_unspecified_parameters";
6246 case DW_TAG_variant:
6247 return "DW_TAG_variant";
6248 case DW_TAG_common_block:
6249 return "DW_TAG_common_block";
6250 case DW_TAG_common_inclusion:
6251 return "DW_TAG_common_inclusion";
6252 case DW_TAG_inheritance:
6253 return "DW_TAG_inheritance";
6254 case DW_TAG_inlined_subroutine:
6255 return "DW_TAG_inlined_subroutine";
6257 return "DW_TAG_module";
6258 case DW_TAG_ptr_to_member_type:
6259 return "DW_TAG_ptr_to_member_type";
6260 case DW_TAG_set_type:
6261 return "DW_TAG_set_type";
6262 case DW_TAG_subrange_type:
6263 return "DW_TAG_subrange_type";
6264 case DW_TAG_with_stmt:
6265 return "DW_TAG_with_stmt";
6266 case DW_TAG_access_declaration:
6267 return "DW_TAG_access_declaration";
6268 case DW_TAG_base_type:
6269 return "DW_TAG_base_type";
6270 case DW_TAG_catch_block:
6271 return "DW_TAG_catch_block";
6272 case DW_TAG_const_type:
6273 return "DW_TAG_const_type";
6274 case DW_TAG_constant:
6275 return "DW_TAG_constant";
6276 case DW_TAG_enumerator:
6277 return "DW_TAG_enumerator";
6278 case DW_TAG_file_type:
6279 return "DW_TAG_file_type";
6281 return "DW_TAG_friend";
6282 case DW_TAG_namelist:
6283 return "DW_TAG_namelist";
6284 case DW_TAG_namelist_item:
6285 return "DW_TAG_namelist_item";
6286 case DW_TAG_packed_type:
6287 return "DW_TAG_packed_type";
6288 case DW_TAG_subprogram:
6289 return "DW_TAG_subprogram";
6290 case DW_TAG_template_type_param:
6291 return "DW_TAG_template_type_param";
6292 case DW_TAG_template_value_param:
6293 return "DW_TAG_template_value_param";
6294 case DW_TAG_thrown_type:
6295 return "DW_TAG_thrown_type";
6296 case DW_TAG_try_block:
6297 return "DW_TAG_try_block";
6298 case DW_TAG_variant_part:
6299 return "DW_TAG_variant_part";
6300 case DW_TAG_variable:
6301 return "DW_TAG_variable";
6302 case DW_TAG_volatile_type:
6303 return "DW_TAG_volatile_type";
6304 case DW_TAG_dwarf_procedure:
6305 return "DW_TAG_dwarf_procedure";
6306 case DW_TAG_restrict_type:
6307 return "DW_TAG_restrict_type";
6308 case DW_TAG_interface_type:
6309 return "DW_TAG_interface_type";
6310 case DW_TAG_namespace:
6311 return "DW_TAG_namespace";
6312 case DW_TAG_imported_module:
6313 return "DW_TAG_imported_module";
6314 case DW_TAG_unspecified_type:
6315 return "DW_TAG_unspecified_type";
6316 case DW_TAG_partial_unit:
6317 return "DW_TAG_partial_unit";
6318 case DW_TAG_imported_unit:
6319 return "DW_TAG_imported_unit";
6320 case DW_TAG_condition:
6321 return "DW_TAG_condition";
6322 case DW_TAG_shared_type:
6323 return "DW_TAG_shared_type";
6324 case DW_TAG_MIPS_loop:
6325 return "DW_TAG_MIPS_loop";
6326 case DW_TAG_format_label:
6327 return "DW_TAG_format_label";
6328 case DW_TAG_function_template:
6329 return "DW_TAG_function_template";
6330 case DW_TAG_class_template:
6331 return "DW_TAG_class_template";
6332 case DW_TAG_GNU_BINCL:
6333 return "DW_TAG_GNU_BINCL";
6334 case DW_TAG_GNU_EINCL:
6335 return "DW_TAG_GNU_EINCL";
6336 case DW_TAG_GNU_template_template_param:
6337 return "DW_TAG_GNU_template_template_param";
6339 return "DW_TAG_<unknown>";
6343 /* Convert a DWARF attribute code into its string name. */
6346 dwarf_attr_name (unsigned int attr)
6351 return "DW_AT_sibling";
6352 case DW_AT_location:
6353 return "DW_AT_location";
6355 return "DW_AT_name";
6356 case DW_AT_ordering:
6357 return "DW_AT_ordering";
6358 case DW_AT_subscr_data:
6359 return "DW_AT_subscr_data";
6360 case DW_AT_byte_size:
6361 return "DW_AT_byte_size";
6362 case DW_AT_bit_offset:
6363 return "DW_AT_bit_offset";
6364 case DW_AT_bit_size:
6365 return "DW_AT_bit_size";
6366 case DW_AT_element_list:
6367 return "DW_AT_element_list";
6368 case DW_AT_stmt_list:
6369 return "DW_AT_stmt_list";
6371 return "DW_AT_low_pc";
6373 return "DW_AT_high_pc";
6374 case DW_AT_language:
6375 return "DW_AT_language";
6377 return "DW_AT_member";
6379 return "DW_AT_discr";
6380 case DW_AT_discr_value:
6381 return "DW_AT_discr_value";
6382 case DW_AT_visibility:
6383 return "DW_AT_visibility";
6385 return "DW_AT_import";
6386 case DW_AT_string_length:
6387 return "DW_AT_string_length";
6388 case DW_AT_common_reference:
6389 return "DW_AT_common_reference";
6390 case DW_AT_comp_dir:
6391 return "DW_AT_comp_dir";
6392 case DW_AT_const_value:
6393 return "DW_AT_const_value";
6394 case DW_AT_containing_type:
6395 return "DW_AT_containing_type";
6396 case DW_AT_default_value:
6397 return "DW_AT_default_value";
6399 return "DW_AT_inline";
6400 case DW_AT_is_optional:
6401 return "DW_AT_is_optional";
6402 case DW_AT_lower_bound:
6403 return "DW_AT_lower_bound";
6404 case DW_AT_producer:
6405 return "DW_AT_producer";
6406 case DW_AT_prototyped:
6407 return "DW_AT_prototyped";
6408 case DW_AT_return_addr:
6409 return "DW_AT_return_addr";
6410 case DW_AT_start_scope:
6411 return "DW_AT_start_scope";
6412 case DW_AT_bit_stride:
6413 return "DW_AT_bit_stride";
6414 case DW_AT_upper_bound:
6415 return "DW_AT_upper_bound";
6416 case DW_AT_abstract_origin:
6417 return "DW_AT_abstract_origin";
6418 case DW_AT_accessibility:
6419 return "DW_AT_accessibility";
6420 case DW_AT_address_class:
6421 return "DW_AT_address_class";
6422 case DW_AT_artificial:
6423 return "DW_AT_artificial";
6424 case DW_AT_base_types:
6425 return "DW_AT_base_types";
6426 case DW_AT_calling_convention:
6427 return "DW_AT_calling_convention";
6429 return "DW_AT_count";
6430 case DW_AT_data_member_location:
6431 return "DW_AT_data_member_location";
6432 case DW_AT_decl_column:
6433 return "DW_AT_decl_column";
6434 case DW_AT_decl_file:
6435 return "DW_AT_decl_file";
6436 case DW_AT_decl_line:
6437 return "DW_AT_decl_line";
6438 case DW_AT_declaration:
6439 return "DW_AT_declaration";
6440 case DW_AT_discr_list:
6441 return "DW_AT_discr_list";
6442 case DW_AT_encoding:
6443 return "DW_AT_encoding";
6444 case DW_AT_external:
6445 return "DW_AT_external";
6446 case DW_AT_explicit:
6447 return "DW_AT_explicit";
6448 case DW_AT_frame_base:
6449 return "DW_AT_frame_base";
6451 return "DW_AT_friend";
6452 case DW_AT_identifier_case:
6453 return "DW_AT_identifier_case";
6454 case DW_AT_macro_info:
6455 return "DW_AT_macro_info";
6456 case DW_AT_namelist_items:
6457 return "DW_AT_namelist_items";
6458 case DW_AT_priority:
6459 return "DW_AT_priority";
6461 return "DW_AT_segment";
6462 case DW_AT_specification:
6463 return "DW_AT_specification";
6464 case DW_AT_static_link:
6465 return "DW_AT_static_link";
6467 return "DW_AT_type";
6468 case DW_AT_use_location:
6469 return "DW_AT_use_location";
6470 case DW_AT_variable_parameter:
6471 return "DW_AT_variable_parameter";
6472 case DW_AT_virtuality:
6473 return "DW_AT_virtuality";
6474 case DW_AT_vtable_elem_location:
6475 return "DW_AT_vtable_elem_location";
6477 case DW_AT_allocated:
6478 return "DW_AT_allocated";
6479 case DW_AT_associated:
6480 return "DW_AT_associated";
6481 case DW_AT_data_location:
6482 return "DW_AT_data_location";
6483 case DW_AT_byte_stride:
6484 return "DW_AT_byte_stride";
6485 case DW_AT_entry_pc:
6486 return "DW_AT_entry_pc";
6487 case DW_AT_use_UTF8:
6488 return "DW_AT_use_UTF8";
6489 case DW_AT_extension:
6490 return "DW_AT_extension";
6492 return "DW_AT_ranges";
6493 case DW_AT_trampoline:
6494 return "DW_AT_trampoline";
6495 case DW_AT_call_column:
6496 return "DW_AT_call_column";
6497 case DW_AT_call_file:
6498 return "DW_AT_call_file";
6499 case DW_AT_call_line:
6500 return "DW_AT_call_line";
6502 case DW_AT_MIPS_fde:
6503 return "DW_AT_MIPS_fde";
6504 case DW_AT_MIPS_loop_begin:
6505 return "DW_AT_MIPS_loop_begin";
6506 case DW_AT_MIPS_tail_loop_begin:
6507 return "DW_AT_MIPS_tail_loop_begin";
6508 case DW_AT_MIPS_epilog_begin:
6509 return "DW_AT_MIPS_epilog_begin";
6510 case DW_AT_MIPS_loop_unroll_factor:
6511 return "DW_AT_MIPS_loop_unroll_factor";
6512 case DW_AT_MIPS_software_pipeline_depth:
6513 return "DW_AT_MIPS_software_pipeline_depth";
6514 case DW_AT_MIPS_linkage_name:
6515 return "DW_AT_MIPS_linkage_name";
6516 case DW_AT_MIPS_stride:
6517 return "DW_AT_MIPS_stride";
6518 case DW_AT_MIPS_abstract_name:
6519 return "DW_AT_MIPS_abstract_name";
6520 case DW_AT_MIPS_clone_origin:
6521 return "DW_AT_MIPS_clone_origin";
6522 case DW_AT_MIPS_has_inlines:
6523 return "DW_AT_MIPS_has_inlines";
6525 case DW_AT_sf_names:
6526 return "DW_AT_sf_names";
6527 case DW_AT_src_info:
6528 return "DW_AT_src_info";
6529 case DW_AT_mac_info:
6530 return "DW_AT_mac_info";
6531 case DW_AT_src_coords:
6532 return "DW_AT_src_coords";
6533 case DW_AT_body_begin:
6534 return "DW_AT_body_begin";
6535 case DW_AT_body_end:
6536 return "DW_AT_body_end";
6537 case DW_AT_GNU_vector:
6538 return "DW_AT_GNU_vector";
6539 case DW_AT_GNU_template_name:
6540 return "DW_AT_GNU_template_name";
6542 case DW_AT_VMS_rtnbeg_pd_address:
6543 return "DW_AT_VMS_rtnbeg_pd_address";
6546 return "DW_AT_<unknown>";
6550 /* Convert a DWARF value form code into its string name. */
6553 dwarf_form_name (unsigned int form)
6558 return "DW_FORM_addr";
6559 case DW_FORM_block2:
6560 return "DW_FORM_block2";
6561 case DW_FORM_block4:
6562 return "DW_FORM_block4";
6564 return "DW_FORM_data2";
6566 return "DW_FORM_data4";
6568 return "DW_FORM_data8";
6569 case DW_FORM_string:
6570 return "DW_FORM_string";
6572 return "DW_FORM_block";
6573 case DW_FORM_block1:
6574 return "DW_FORM_block1";
6576 return "DW_FORM_data1";
6578 return "DW_FORM_flag";
6580 return "DW_FORM_sdata";
6582 return "DW_FORM_strp";
6584 return "DW_FORM_udata";
6585 case DW_FORM_ref_addr:
6586 return "DW_FORM_ref_addr";
6588 return "DW_FORM_ref1";
6590 return "DW_FORM_ref2";
6592 return "DW_FORM_ref4";
6594 return "DW_FORM_ref8";
6595 case DW_FORM_ref_udata:
6596 return "DW_FORM_ref_udata";
6597 case DW_FORM_indirect:
6598 return "DW_FORM_indirect";
6600 return "DW_FORM_<unknown>";
6604 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6605 instance of an inlined instance of a decl which is local to an inline
6606 function, so we have to trace all of the way back through the origin chain
6607 to find out what sort of node actually served as the original seed for the
6611 decl_ultimate_origin (const_tree decl)
6613 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6616 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6617 nodes in the function to point to themselves; ignore that if
6618 we're trying to output the abstract instance of this function. */
6619 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6622 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6623 most distant ancestor, this should never happen. */
6624 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6626 return DECL_ABSTRACT_ORIGIN (decl);
6629 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6630 of a virtual function may refer to a base class, so we check the 'this'
6634 decl_class_context (tree decl)
6636 tree context = NULL_TREE;
6638 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6639 context = DECL_CONTEXT (decl);
6641 context = TYPE_MAIN_VARIANT
6642 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6644 if (context && !TYPE_P (context))
6645 context = NULL_TREE;
6650 /* Add an attribute/value pair to a DIE. */
6653 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6655 /* Maybe this should be an assert? */
6659 if (die->die_attr == NULL)
6660 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6661 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6664 static inline enum dw_val_class
6665 AT_class (dw_attr_ref a)
6667 return a->dw_attr_val.val_class;
6670 /* Add a flag value attribute to a DIE. */
6673 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6677 attr.dw_attr = attr_kind;
6678 attr.dw_attr_val.val_class = dw_val_class_flag;
6679 attr.dw_attr_val.v.val_flag = flag;
6680 add_dwarf_attr (die, &attr);
6683 static inline unsigned
6684 AT_flag (dw_attr_ref a)
6686 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6687 return a->dw_attr_val.v.val_flag;
6690 /* Add a signed integer attribute value to a DIE. */
6693 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6697 attr.dw_attr = attr_kind;
6698 attr.dw_attr_val.val_class = dw_val_class_const;
6699 attr.dw_attr_val.v.val_int = int_val;
6700 add_dwarf_attr (die, &attr);
6703 static inline HOST_WIDE_INT
6704 AT_int (dw_attr_ref a)
6706 gcc_assert (a && AT_class (a) == dw_val_class_const);
6707 return a->dw_attr_val.v.val_int;
6710 /* Add an unsigned integer attribute value to a DIE. */
6713 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6714 unsigned HOST_WIDE_INT unsigned_val)
6718 attr.dw_attr = attr_kind;
6719 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6720 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6721 add_dwarf_attr (die, &attr);
6724 static inline unsigned HOST_WIDE_INT
6725 AT_unsigned (dw_attr_ref a)
6727 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6728 return a->dw_attr_val.v.val_unsigned;
6731 /* Add an unsigned double integer attribute value to a DIE. */
6734 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
6735 rtx val_const_double)
6739 attr.dw_attr = attr_kind;
6740 attr.dw_attr_val.val_class = dw_val_class_long_long;
6741 attr.dw_attr_val.v.val_long_long = val_const_double;
6742 add_dwarf_attr (die, &attr);
6745 /* Add a floating point attribute value to a DIE and return it. */
6748 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6749 unsigned int length, unsigned int elt_size, unsigned char *array)
6753 attr.dw_attr = attr_kind;
6754 attr.dw_attr_val.val_class = dw_val_class_vec;
6755 attr.dw_attr_val.v.val_vec.length = length;
6756 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6757 attr.dw_attr_val.v.val_vec.array = array;
6758 add_dwarf_attr (die, &attr);
6761 /* Hash and equality functions for debug_str_hash. */
6764 debug_str_do_hash (const void *x)
6766 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6770 debug_str_eq (const void *x1, const void *x2)
6772 return strcmp ((((const struct indirect_string_node *)x1)->str),
6773 (const char *)x2) == 0;
6776 /* Add STR to the indirect string hash table. */
6778 static struct indirect_string_node *
6779 find_AT_string (const char *str)
6781 struct indirect_string_node *node;
6784 if (! debug_str_hash)
6785 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6786 debug_str_eq, NULL);
6788 slot = htab_find_slot_with_hash (debug_str_hash, str,
6789 htab_hash_string (str), INSERT);
6792 node = (struct indirect_string_node *)
6793 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6794 node->str = ggc_strdup (str);
6798 node = (struct indirect_string_node *) *slot;
6804 /* Add a string attribute value to a DIE. */
6807 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6810 struct indirect_string_node *node;
6812 node = find_AT_string (str);
6814 attr.dw_attr = attr_kind;
6815 attr.dw_attr_val.val_class = dw_val_class_str;
6816 attr.dw_attr_val.v.val_str = node;
6817 add_dwarf_attr (die, &attr);
6820 /* Create a label for an indirect string node, ensuring it is going to
6821 be output, unless its reference count goes down to zero. */
6824 gen_label_for_indirect_string (struct indirect_string_node *node)
6831 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6832 ++dw2_string_counter;
6833 node->label = xstrdup (label);
6836 /* Create a SYMBOL_REF rtx whose value is the initial address of a
6837 debug string STR. */
6840 get_debug_string_label (const char *str)
6842 struct indirect_string_node *node = find_AT_string (str);
6844 debug_str_hash_forced = true;
6846 gen_label_for_indirect_string (node);
6848 return gen_rtx_SYMBOL_REF (Pmode, node->label);
6851 static inline const char *
6852 AT_string (dw_attr_ref a)
6854 gcc_assert (a && AT_class (a) == dw_val_class_str);
6855 return a->dw_attr_val.v.val_str->str;
6858 /* Find out whether a string should be output inline in DIE
6859 or out-of-line in .debug_str section. */
6861 static enum dwarf_form
6862 AT_string_form (dw_attr_ref a)
6864 struct indirect_string_node *node;
6867 gcc_assert (a && AT_class (a) == dw_val_class_str);
6869 node = a->dw_attr_val.v.val_str;
6873 len = strlen (node->str) + 1;
6875 /* If the string is shorter or equal to the size of the reference, it is
6876 always better to put it inline. */
6877 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6878 return node->form = DW_FORM_string;
6880 /* If we cannot expect the linker to merge strings in .debug_str
6881 section, only put it into .debug_str if it is worth even in this
6883 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
6884 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
6885 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
6886 return node->form = DW_FORM_string;
6888 gen_label_for_indirect_string (node);
6890 return node->form = DW_FORM_strp;
6893 /* Add a DIE reference attribute value to a DIE. */
6896 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6900 attr.dw_attr = attr_kind;
6901 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6902 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6903 attr.dw_attr_val.v.val_die_ref.external = 0;
6904 add_dwarf_attr (die, &attr);
6907 /* Add an AT_specification attribute to a DIE, and also make the back
6908 pointer from the specification to the definition. */
6911 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6913 add_AT_die_ref (die, DW_AT_specification, targ_die);
6914 gcc_assert (!targ_die->die_definition);
6915 targ_die->die_definition = die;
6918 static inline dw_die_ref
6919 AT_ref (dw_attr_ref a)
6921 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6922 return a->dw_attr_val.v.val_die_ref.die;
6926 AT_ref_external (dw_attr_ref a)
6928 if (a && AT_class (a) == dw_val_class_die_ref)
6929 return a->dw_attr_val.v.val_die_ref.external;
6935 set_AT_ref_external (dw_attr_ref a, int i)
6937 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6938 a->dw_attr_val.v.val_die_ref.external = i;
6941 /* Add an FDE reference attribute value to a DIE. */
6944 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6948 attr.dw_attr = attr_kind;
6949 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6950 attr.dw_attr_val.v.val_fde_index = targ_fde;
6951 add_dwarf_attr (die, &attr);
6954 /* Add a location description attribute value to a DIE. */
6957 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6961 attr.dw_attr = attr_kind;
6962 attr.dw_attr_val.val_class = dw_val_class_loc;
6963 attr.dw_attr_val.v.val_loc = loc;
6964 add_dwarf_attr (die, &attr);
6967 static inline dw_loc_descr_ref
6968 AT_loc (dw_attr_ref a)
6970 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6971 return a->dw_attr_val.v.val_loc;
6975 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6979 attr.dw_attr = attr_kind;
6980 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6981 attr.dw_attr_val.v.val_loc_list = loc_list;
6982 add_dwarf_attr (die, &attr);
6983 have_location_lists = true;
6986 static inline dw_loc_list_ref
6987 AT_loc_list (dw_attr_ref a)
6989 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6990 return a->dw_attr_val.v.val_loc_list;
6993 /* Add an address constant attribute value to a DIE. */
6996 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7000 attr.dw_attr = attr_kind;
7001 attr.dw_attr_val.val_class = dw_val_class_addr;
7002 attr.dw_attr_val.v.val_addr = addr;
7003 add_dwarf_attr (die, &attr);
7006 /* Get the RTX from to an address DIE attribute. */
7009 AT_addr (dw_attr_ref a)
7011 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7012 return a->dw_attr_val.v.val_addr;
7015 /* Add a file attribute value to a DIE. */
7018 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7019 struct dwarf_file_data *fd)
7023 attr.dw_attr = attr_kind;
7024 attr.dw_attr_val.val_class = dw_val_class_file;
7025 attr.dw_attr_val.v.val_file = fd;
7026 add_dwarf_attr (die, &attr);
7029 /* Get the dwarf_file_data from a file DIE attribute. */
7031 static inline struct dwarf_file_data *
7032 AT_file (dw_attr_ref a)
7034 gcc_assert (a && AT_class (a) == dw_val_class_file);
7035 return a->dw_attr_val.v.val_file;
7038 /* Add a label identifier attribute value to a DIE. */
7041 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7045 attr.dw_attr = attr_kind;
7046 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7047 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7048 add_dwarf_attr (die, &attr);
7051 /* Add a section offset attribute value to a DIE, an offset into the
7052 debug_line section. */
7055 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7060 attr.dw_attr = attr_kind;
7061 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7062 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7063 add_dwarf_attr (die, &attr);
7066 /* Add a section offset attribute value to a DIE, an offset into the
7067 debug_macinfo section. */
7070 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7075 attr.dw_attr = attr_kind;
7076 attr.dw_attr_val.val_class = dw_val_class_macptr;
7077 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7078 add_dwarf_attr (die, &attr);
7081 /* Add an offset attribute value to a DIE. */
7084 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7085 unsigned HOST_WIDE_INT offset)
7089 attr.dw_attr = attr_kind;
7090 attr.dw_attr_val.val_class = dw_val_class_offset;
7091 attr.dw_attr_val.v.val_offset = offset;
7092 add_dwarf_attr (die, &attr);
7095 /* Add an range_list attribute value to a DIE. */
7098 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7099 long unsigned int offset)
7103 attr.dw_attr = attr_kind;
7104 attr.dw_attr_val.val_class = dw_val_class_range_list;
7105 attr.dw_attr_val.v.val_offset = offset;
7106 add_dwarf_attr (die, &attr);
7109 static inline const char *
7110 AT_lbl (dw_attr_ref a)
7112 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7113 || AT_class (a) == dw_val_class_lineptr
7114 || AT_class (a) == dw_val_class_macptr));
7115 return a->dw_attr_val.v.val_lbl_id;
7118 /* Get the attribute of type attr_kind. */
7121 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7125 dw_die_ref spec = NULL;
7130 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7131 if (a->dw_attr == attr_kind)
7133 else if (a->dw_attr == DW_AT_specification
7134 || a->dw_attr == DW_AT_abstract_origin)
7138 return get_AT (spec, attr_kind);
7143 /* Return the "low pc" attribute value, typically associated with a subprogram
7144 DIE. Return null if the "low pc" attribute is either not present, or if it
7145 cannot be represented as an assembler label identifier. */
7147 static inline const char *
7148 get_AT_low_pc (dw_die_ref die)
7150 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7152 return a ? AT_lbl (a) : NULL;
7155 /* Return the "high pc" attribute value, typically associated with a subprogram
7156 DIE. Return null if the "high pc" attribute is either not present, or if it
7157 cannot be represented as an assembler label identifier. */
7159 static inline const char *
7160 get_AT_hi_pc (dw_die_ref die)
7162 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7164 return a ? AT_lbl (a) : NULL;
7167 /* Return the value of the string attribute designated by ATTR_KIND, or
7168 NULL if it is not present. */
7170 static inline const char *
7171 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7173 dw_attr_ref a = get_AT (die, attr_kind);
7175 return a ? AT_string (a) : NULL;
7178 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7179 if it is not present. */
7182 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7184 dw_attr_ref a = get_AT (die, attr_kind);
7186 return a ? AT_flag (a) : 0;
7189 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7190 if it is not present. */
7192 static inline unsigned
7193 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7195 dw_attr_ref a = get_AT (die, attr_kind);
7197 return a ? AT_unsigned (a) : 0;
7200 static inline dw_die_ref
7201 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7203 dw_attr_ref a = get_AT (die, attr_kind);
7205 return a ? AT_ref (a) : NULL;
7208 static inline struct dwarf_file_data *
7209 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7211 dw_attr_ref a = get_AT (die, attr_kind);
7213 return a ? AT_file (a) : NULL;
7216 /* Return TRUE if the language is C or C++. */
7221 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7223 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
7224 || lang == DW_LANG_C99
7225 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
7228 /* Return TRUE if the language is C++. */
7233 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7235 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7238 /* Return TRUE if the language is Fortran. */
7243 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7245 return (lang == DW_LANG_Fortran77
7246 || lang == DW_LANG_Fortran90
7247 || lang == DW_LANG_Fortran95);
7250 /* Return TRUE if the language is Java. */
7255 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7257 return lang == DW_LANG_Java;
7260 /* Return TRUE if the language is Ada. */
7265 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
7267 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7270 /* Remove the specified attribute if present. */
7273 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7281 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7282 if (a->dw_attr == attr_kind)
7284 if (AT_class (a) == dw_val_class_str)
7285 if (a->dw_attr_val.v.val_str->refcount)
7286 a->dw_attr_val.v.val_str->refcount--;
7288 /* VEC_ordered_remove should help reduce the number of abbrevs
7290 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7295 /* Remove CHILD from its parent. PREV must have the property that
7296 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7299 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7301 gcc_assert (child->die_parent == prev->die_parent);
7302 gcc_assert (prev->die_sib == child);
7305 gcc_assert (child->die_parent->die_child == child);
7309 prev->die_sib = child->die_sib;
7310 if (child->die_parent->die_child == child)
7311 child->die_parent->die_child = prev;
7314 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
7318 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
7324 dw_die_ref prev = c;
7326 while (c->die_tag == tag)
7328 remove_child_with_prev (c, prev);
7329 /* Might have removed every child. */
7330 if (c == c->die_sib)
7334 } while (c != die->die_child);
7337 /* Add a CHILD_DIE as the last child of DIE. */
7340 add_child_die (dw_die_ref die, dw_die_ref child_die)
7342 /* FIXME this should probably be an assert. */
7343 if (! die || ! child_die)
7345 gcc_assert (die != child_die);
7347 child_die->die_parent = die;
7350 child_die->die_sib = die->die_child->die_sib;
7351 die->die_child->die_sib = child_die;
7354 child_die->die_sib = child_die;
7355 die->die_child = child_die;
7358 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
7359 is the specification, to the end of PARENT's list of children.
7360 This is done by removing and re-adding it. */
7363 splice_child_die (dw_die_ref parent, dw_die_ref child)
7367 /* We want the declaration DIE from inside the class, not the
7368 specification DIE at toplevel. */
7369 if (child->die_parent != parent)
7371 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
7377 gcc_assert (child->die_parent == parent
7378 || (child->die_parent
7379 == get_AT_ref (parent, DW_AT_specification)));
7381 for (p = child->die_parent->die_child; ; p = p->die_sib)
7382 if (p->die_sib == child)
7384 remove_child_with_prev (child, p);
7388 add_child_die (parent, child);
7391 /* Return a pointer to a newly created DIE node. */
7393 static inline dw_die_ref
7394 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
7396 dw_die_ref die = GGC_CNEW (die_node);
7398 die->die_tag = tag_value;
7400 if (parent_die != NULL)
7401 add_child_die (parent_die, die);
7404 limbo_die_node *limbo_node;
7406 limbo_node = GGC_CNEW (limbo_die_node);
7407 limbo_node->die = die;
7408 limbo_node->created_for = t;
7409 limbo_node->next = limbo_die_list;
7410 limbo_die_list = limbo_node;
7416 /* Return the DIE associated with the given type specifier. */
7418 static inline dw_die_ref
7419 lookup_type_die (tree type)
7421 return TYPE_SYMTAB_DIE (type);
7424 /* Equate a DIE to a given type specifier. */
7427 equate_type_number_to_die (tree type, dw_die_ref type_die)
7429 TYPE_SYMTAB_DIE (type) = type_die;
7432 /* Returns a hash value for X (which really is a die_struct). */
7435 decl_die_table_hash (const void *x)
7437 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
7440 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
7443 decl_die_table_eq (const void *x, const void *y)
7445 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
7448 /* Return the DIE associated with a given declaration. */
7450 static inline dw_die_ref
7451 lookup_decl_die (tree decl)
7453 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
7456 /* Returns a hash value for X (which really is a var_loc_list). */
7459 decl_loc_table_hash (const void *x)
7461 return (hashval_t) ((const var_loc_list *) x)->decl_id;
7464 /* Return nonzero if decl_id of var_loc_list X is the same as
7468 decl_loc_table_eq (const void *x, const void *y)
7470 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
7473 /* Return the var_loc list associated with a given declaration. */
7475 static inline var_loc_list *
7476 lookup_decl_loc (const_tree decl)
7478 return (var_loc_list *)
7479 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
7482 /* Equate a DIE to a particular declaration. */
7485 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
7487 unsigned int decl_id = DECL_UID (decl);
7490 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
7492 decl_die->decl_id = decl_id;
7495 /* Add a variable location node to the linked list for DECL. */
7498 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
7500 unsigned int decl_id = DECL_UID (decl);
7504 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
7507 temp = GGC_CNEW (var_loc_list);
7508 temp->decl_id = decl_id;
7512 temp = (var_loc_list *) *slot;
7516 /* If the current location is the same as the end of the list,
7517 and either both or neither of the locations is uninitialized,
7518 we have nothing to do. */
7519 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
7520 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
7521 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7522 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
7523 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
7524 == VAR_INIT_STATUS_UNINITIALIZED)
7525 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
7526 == VAR_INIT_STATUS_UNINITIALIZED))))
7528 /* Add LOC to the end of list and update LAST. */
7529 temp->last->next = loc;
7533 /* Do not add empty location to the beginning of the list. */
7534 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7541 /* Keep track of the number of spaces used to indent the
7542 output of the debugging routines that print the structure of
7543 the DIE internal representation. */
7544 static int print_indent;
7546 /* Indent the line the number of spaces given by print_indent. */
7549 print_spaces (FILE *outfile)
7551 fprintf (outfile, "%*s", print_indent, "");
7554 /* Print the information associated with a given DIE, and its children.
7555 This routine is a debugging aid only. */
7558 print_die (dw_die_ref die, FILE *outfile)
7564 print_spaces (outfile);
7565 fprintf (outfile, "DIE %4ld: %s\n",
7566 die->die_offset, dwarf_tag_name (die->die_tag));
7567 print_spaces (outfile);
7568 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7569 fprintf (outfile, " offset: %ld\n", die->die_offset);
7571 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7573 print_spaces (outfile);
7574 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7576 switch (AT_class (a))
7578 case dw_val_class_addr:
7579 fprintf (outfile, "address");
7581 case dw_val_class_offset:
7582 fprintf (outfile, "offset");
7584 case dw_val_class_loc:
7585 fprintf (outfile, "location descriptor");
7587 case dw_val_class_loc_list:
7588 fprintf (outfile, "location list -> label:%s",
7589 AT_loc_list (a)->ll_symbol);
7591 case dw_val_class_range_list:
7592 fprintf (outfile, "range list");
7594 case dw_val_class_const:
7595 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7597 case dw_val_class_unsigned_const:
7598 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7600 case dw_val_class_long_long:
7601 fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_UNSIGNED
7602 "," HOST_WIDE_INT_PRINT_UNSIGNED ")",
7603 CONST_DOUBLE_HIGH (a->dw_attr_val.v.val_long_long),
7604 CONST_DOUBLE_LOW (a->dw_attr_val.v.val_long_long));
7606 case dw_val_class_vec:
7607 fprintf (outfile, "floating-point or vector constant");
7609 case dw_val_class_flag:
7610 fprintf (outfile, "%u", AT_flag (a));
7612 case dw_val_class_die_ref:
7613 if (AT_ref (a) != NULL)
7615 if (AT_ref (a)->die_symbol)
7616 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7618 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7621 fprintf (outfile, "die -> <null>");
7623 case dw_val_class_lbl_id:
7624 case dw_val_class_lineptr:
7625 case dw_val_class_macptr:
7626 fprintf (outfile, "label: %s", AT_lbl (a));
7628 case dw_val_class_str:
7629 if (AT_string (a) != NULL)
7630 fprintf (outfile, "\"%s\"", AT_string (a));
7632 fprintf (outfile, "<null>");
7634 case dw_val_class_file:
7635 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7636 AT_file (a)->emitted_number);
7642 fprintf (outfile, "\n");
7645 if (die->die_child != NULL)
7648 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7651 if (print_indent == 0)
7652 fprintf (outfile, "\n");
7655 /* Print the contents of the source code line number correspondence table.
7656 This routine is a debugging aid only. */
7659 print_dwarf_line_table (FILE *outfile)
7662 dw_line_info_ref line_info;
7664 fprintf (outfile, "\n\nDWARF source line information\n");
7665 for (i = 1; i < line_info_table_in_use; i++)
7667 line_info = &line_info_table[i];
7668 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7669 line_info->dw_file_num,
7670 line_info->dw_line_num);
7673 fprintf (outfile, "\n\n");
7676 /* Print the information collected for a given DIE. */
7679 debug_dwarf_die (dw_die_ref die)
7681 print_die (die, stderr);
7684 /* Print all DWARF information collected for the compilation unit.
7685 This routine is a debugging aid only. */
7691 print_die (comp_unit_die, stderr);
7692 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7693 print_dwarf_line_table (stderr);
7696 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7697 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7698 DIE that marks the start of the DIEs for this include file. */
7701 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7703 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7704 dw_die_ref new_unit = gen_compile_unit_die (filename);
7706 new_unit->die_sib = old_unit;
7710 /* Close an include-file CU and reopen the enclosing one. */
7713 pop_compile_unit (dw_die_ref old_unit)
7715 dw_die_ref new_unit = old_unit->die_sib;
7717 old_unit->die_sib = NULL;
7721 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7722 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7724 /* Calculate the checksum of a location expression. */
7727 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7731 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7733 CHECKSUM (loc->dw_loc_oprnd1);
7734 CHECKSUM (loc->dw_loc_oprnd2);
7737 /* Calculate the checksum of an attribute. */
7740 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7742 dw_loc_descr_ref loc;
7745 CHECKSUM (at->dw_attr);
7747 /* We don't care that this was compiled with a different compiler
7748 snapshot; if the output is the same, that's what matters. */
7749 if (at->dw_attr == DW_AT_producer)
7752 switch (AT_class (at))
7754 case dw_val_class_const:
7755 CHECKSUM (at->dw_attr_val.v.val_int);
7757 case dw_val_class_unsigned_const:
7758 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7760 case dw_val_class_long_long:
7761 CHECKSUM (CONST_DOUBLE_HIGH (at->dw_attr_val.v.val_long_long));
7762 CHECKSUM (CONST_DOUBLE_LOW (at->dw_attr_val.v.val_long_long));
7764 case dw_val_class_vec:
7765 CHECKSUM (at->dw_attr_val.v.val_vec);
7767 case dw_val_class_flag:
7768 CHECKSUM (at->dw_attr_val.v.val_flag);
7770 case dw_val_class_str:
7771 CHECKSUM_STRING (AT_string (at));
7774 case dw_val_class_addr:
7776 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7777 CHECKSUM_STRING (XSTR (r, 0));
7780 case dw_val_class_offset:
7781 CHECKSUM (at->dw_attr_val.v.val_offset);
7784 case dw_val_class_loc:
7785 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7786 loc_checksum (loc, ctx);
7789 case dw_val_class_die_ref:
7790 die_checksum (AT_ref (at), ctx, mark);
7793 case dw_val_class_fde_ref:
7794 case dw_val_class_lbl_id:
7795 case dw_val_class_lineptr:
7796 case dw_val_class_macptr:
7799 case dw_val_class_file:
7800 CHECKSUM_STRING (AT_file (at)->filename);
7808 /* Calculate the checksum of a DIE. */
7811 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7817 /* To avoid infinite recursion. */
7820 CHECKSUM (die->die_mark);
7823 die->die_mark = ++(*mark);
7825 CHECKSUM (die->die_tag);
7827 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7828 attr_checksum (a, ctx, mark);
7830 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7834 #undef CHECKSUM_STRING
7836 /* Do the location expressions look same? */
7838 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7840 return loc1->dw_loc_opc == loc2->dw_loc_opc
7841 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7842 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7845 /* Do the values look the same? */
7847 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7849 dw_loc_descr_ref loc1, loc2;
7852 if (v1->val_class != v2->val_class)
7855 switch (v1->val_class)
7857 case dw_val_class_const:
7858 return v1->v.val_int == v2->v.val_int;
7859 case dw_val_class_unsigned_const:
7860 return v1->v.val_unsigned == v2->v.val_unsigned;
7861 case dw_val_class_long_long:
7862 return CONST_DOUBLE_HIGH (v1->v.val_long_long)
7863 == CONST_DOUBLE_HIGH (v2->v.val_long_long)
7864 && CONST_DOUBLE_LOW (v1->v.val_long_long)
7865 == CONST_DOUBLE_LOW (v2->v.val_long_long);
7866 case dw_val_class_vec:
7867 if (v1->v.val_vec.length != v2->v.val_vec.length
7868 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7870 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7871 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7874 case dw_val_class_flag:
7875 return v1->v.val_flag == v2->v.val_flag;
7876 case dw_val_class_str:
7877 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7879 case dw_val_class_addr:
7880 r1 = v1->v.val_addr;
7881 r2 = v2->v.val_addr;
7882 if (GET_CODE (r1) != GET_CODE (r2))
7884 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7885 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7887 case dw_val_class_offset:
7888 return v1->v.val_offset == v2->v.val_offset;
7890 case dw_val_class_loc:
7891 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7893 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7894 if (!same_loc_p (loc1, loc2, mark))
7896 return !loc1 && !loc2;
7898 case dw_val_class_die_ref:
7899 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7901 case dw_val_class_fde_ref:
7902 case dw_val_class_lbl_id:
7903 case dw_val_class_lineptr:
7904 case dw_val_class_macptr:
7907 case dw_val_class_file:
7908 return v1->v.val_file == v2->v.val_file;
7915 /* Do the attributes look the same? */
7918 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7920 if (at1->dw_attr != at2->dw_attr)
7923 /* We don't care that this was compiled with a different compiler
7924 snapshot; if the output is the same, that's what matters. */
7925 if (at1->dw_attr == DW_AT_producer)
7928 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7931 /* Do the dies look the same? */
7934 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7940 /* To avoid infinite recursion. */
7942 return die1->die_mark == die2->die_mark;
7943 die1->die_mark = die2->die_mark = ++(*mark);
7945 if (die1->die_tag != die2->die_tag)
7948 if (VEC_length (dw_attr_node, die1->die_attr)
7949 != VEC_length (dw_attr_node, die2->die_attr))
7952 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7953 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7956 c1 = die1->die_child;
7957 c2 = die2->die_child;
7966 if (!same_die_p (c1, c2, mark))
7970 if (c1 == die1->die_child)
7972 if (c2 == die2->die_child)
7982 /* Do the dies look the same? Wrapper around same_die_p. */
7985 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7988 int ret = same_die_p (die1, die2, &mark);
7990 unmark_all_dies (die1);
7991 unmark_all_dies (die2);
7996 /* The prefix to attach to symbols on DIEs in the current comdat debug
7998 static char *comdat_symbol_id;
8000 /* The index of the current symbol within the current comdat CU. */
8001 static unsigned int comdat_symbol_number;
8003 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8004 children, and set comdat_symbol_id accordingly. */
8007 compute_section_prefix (dw_die_ref unit_die)
8009 const char *die_name = get_AT_string (unit_die, DW_AT_name);
8010 const char *base = die_name ? lbasename (die_name) : "anonymous";
8011 char *name = XALLOCAVEC (char, strlen (base) + 64);
8014 unsigned char checksum[16];
8017 /* Compute the checksum of the DIE, then append part of it as hex digits to
8018 the name filename of the unit. */
8020 md5_init_ctx (&ctx);
8022 die_checksum (unit_die, &ctx, &mark);
8023 unmark_all_dies (unit_die);
8024 md5_finish_ctx (&ctx, checksum);
8026 sprintf (name, "%s.", base);
8027 clean_symbol_name (name);
8029 p = name + strlen (name);
8030 for (i = 0; i < 4; i++)
8032 sprintf (p, "%.2x", checksum[i]);
8036 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
8037 comdat_symbol_number = 0;
8040 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
8043 is_type_die (dw_die_ref die)
8045 switch (die->die_tag)
8047 case DW_TAG_array_type:
8048 case DW_TAG_class_type:
8049 case DW_TAG_interface_type:
8050 case DW_TAG_enumeration_type:
8051 case DW_TAG_pointer_type:
8052 case DW_TAG_reference_type:
8053 case DW_TAG_string_type:
8054 case DW_TAG_structure_type:
8055 case DW_TAG_subroutine_type:
8056 case DW_TAG_union_type:
8057 case DW_TAG_ptr_to_member_type:
8058 case DW_TAG_set_type:
8059 case DW_TAG_subrange_type:
8060 case DW_TAG_base_type:
8061 case DW_TAG_const_type:
8062 case DW_TAG_file_type:
8063 case DW_TAG_packed_type:
8064 case DW_TAG_volatile_type:
8065 case DW_TAG_typedef:
8072 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
8073 Basically, we want to choose the bits that are likely to be shared between
8074 compilations (types) and leave out the bits that are specific to individual
8075 compilations (functions). */
8078 is_comdat_die (dw_die_ref c)
8080 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
8081 we do for stabs. The advantage is a greater likelihood of sharing between
8082 objects that don't include headers in the same order (and therefore would
8083 put the base types in a different comdat). jason 8/28/00 */
8085 if (c->die_tag == DW_TAG_base_type)
8088 if (c->die_tag == DW_TAG_pointer_type
8089 || c->die_tag == DW_TAG_reference_type
8090 || c->die_tag == DW_TAG_const_type
8091 || c->die_tag == DW_TAG_volatile_type)
8093 dw_die_ref t = get_AT_ref (c, DW_AT_type);
8095 return t ? is_comdat_die (t) : 0;
8098 return is_type_die (c);
8101 /* Returns 1 iff C is the sort of DIE that might be referred to from another
8102 compilation unit. */
8105 is_symbol_die (dw_die_ref c)
8107 return (is_type_die (c)
8108 || (get_AT (c, DW_AT_declaration)
8109 && !get_AT (c, DW_AT_specification))
8110 || c->die_tag == DW_TAG_namespace
8111 || c->die_tag == DW_TAG_module);
8115 gen_internal_sym (const char *prefix)
8119 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8120 return xstrdup (buf);
8123 /* Assign symbols to all worthy DIEs under DIE. */
8126 assign_symbol_names (dw_die_ref die)
8130 if (is_symbol_die (die))
8132 if (comdat_symbol_id)
8134 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
8136 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
8137 comdat_symbol_id, comdat_symbol_number++);
8138 die->die_symbol = xstrdup (p);
8141 die->die_symbol = gen_internal_sym ("LDIE");
8144 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
8147 struct cu_hash_table_entry
8150 unsigned min_comdat_num, max_comdat_num;
8151 struct cu_hash_table_entry *next;
8154 /* Routines to manipulate hash table of CUs. */
8156 htab_cu_hash (const void *of)
8158 const struct cu_hash_table_entry *const entry =
8159 (const struct cu_hash_table_entry *) of;
8161 return htab_hash_string (entry->cu->die_symbol);
8165 htab_cu_eq (const void *of1, const void *of2)
8167 const struct cu_hash_table_entry *const entry1 =
8168 (const struct cu_hash_table_entry *) of1;
8169 const struct die_struct *const entry2 = (const struct die_struct *) of2;
8171 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
8175 htab_cu_del (void *what)
8177 struct cu_hash_table_entry *next,
8178 *entry = (struct cu_hash_table_entry *) what;
8188 /* Check whether we have already seen this CU and set up SYM_NUM
8191 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
8193 struct cu_hash_table_entry dummy;
8194 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
8196 dummy.max_comdat_num = 0;
8198 slot = (struct cu_hash_table_entry **)
8199 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8203 for (; entry; last = entry, entry = entry->next)
8205 if (same_die_p_wrap (cu, entry->cu))
8211 *sym_num = entry->min_comdat_num;
8215 entry = XCNEW (struct cu_hash_table_entry);
8217 entry->min_comdat_num = *sym_num = last->max_comdat_num;
8218 entry->next = *slot;
8224 /* Record SYM_NUM to record of CU in HTABLE. */
8226 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
8228 struct cu_hash_table_entry **slot, *entry;
8230 slot = (struct cu_hash_table_entry **)
8231 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
8235 entry->max_comdat_num = sym_num;
8238 /* Traverse the DIE (which is always comp_unit_die), and set up
8239 additional compilation units for each of the include files we see
8240 bracketed by BINCL/EINCL. */
8243 break_out_includes (dw_die_ref die)
8246 dw_die_ref unit = NULL;
8247 limbo_die_node *node, **pnode;
8248 htab_t cu_hash_table;
8252 dw_die_ref prev = c;
8254 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
8255 || (unit && is_comdat_die (c)))
8257 dw_die_ref next = c->die_sib;
8259 /* This DIE is for a secondary CU; remove it from the main one. */
8260 remove_child_with_prev (c, prev);
8262 if (c->die_tag == DW_TAG_GNU_BINCL)
8263 unit = push_new_compile_unit (unit, c);
8264 else if (c->die_tag == DW_TAG_GNU_EINCL)
8265 unit = pop_compile_unit (unit);
8267 add_child_die (unit, c);
8269 if (c == die->die_child)
8272 } while (c != die->die_child);
8275 /* We can only use this in debugging, since the frontend doesn't check
8276 to make sure that we leave every include file we enter. */
8280 assign_symbol_names (die);
8281 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
8282 for (node = limbo_die_list, pnode = &limbo_die_list;
8288 compute_section_prefix (node->die);
8289 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
8290 &comdat_symbol_number);
8291 assign_symbol_names (node->die);
8293 *pnode = node->next;
8296 pnode = &node->next;
8297 record_comdat_symbol_number (node->die, cu_hash_table,
8298 comdat_symbol_number);
8301 htab_delete (cu_hash_table);
8304 /* Traverse the DIE and add a sibling attribute if it may have the
8305 effect of speeding up access to siblings. To save some space,
8306 avoid generating sibling attributes for DIE's without children. */
8309 add_sibling_attributes (dw_die_ref die)
8313 if (! die->die_child)
8316 if (die->die_parent && die != die->die_parent->die_child)
8317 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8319 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8322 /* Output all location lists for the DIE and its children. */
8325 output_location_lists (dw_die_ref die)
8331 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8332 if (AT_class (a) == dw_val_class_loc_list)
8333 output_loc_list (AT_loc_list (a));
8335 FOR_EACH_CHILD (die, c, output_location_lists (c));
8338 /* The format of each DIE (and its attribute value pairs) is encoded in an
8339 abbreviation table. This routine builds the abbreviation table and assigns
8340 a unique abbreviation id for each abbreviation entry. The children of each
8341 die are visited recursively. */
8344 build_abbrev_table (dw_die_ref die)
8346 unsigned long abbrev_id;
8347 unsigned int n_alloc;
8352 /* Scan the DIE references, and mark as external any that refer to
8353 DIEs from other CUs (i.e. those which are not marked). */
8354 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8355 if (AT_class (a) == dw_val_class_die_ref
8356 && AT_ref (a)->die_mark == 0)
8358 gcc_assert (AT_ref (a)->die_symbol);
8359 set_AT_ref_external (a, 1);
8362 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8364 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8365 dw_attr_ref die_a, abbrev_a;
8369 if (abbrev->die_tag != die->die_tag)
8371 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
8374 if (VEC_length (dw_attr_node, abbrev->die_attr)
8375 != VEC_length (dw_attr_node, die->die_attr))
8378 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
8380 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
8381 if ((abbrev_a->dw_attr != die_a->dw_attr)
8382 || (value_format (abbrev_a) != value_format (die_a)))
8392 if (abbrev_id >= abbrev_die_table_in_use)
8394 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
8396 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
8397 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
8400 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
8401 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
8402 abbrev_die_table_allocated = n_alloc;
8405 ++abbrev_die_table_in_use;
8406 abbrev_die_table[abbrev_id] = die;
8409 die->die_abbrev = abbrev_id;
8410 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
8413 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8416 constant_size (unsigned HOST_WIDE_INT value)
8423 log = floor_log2 (value);
8426 log = 1 << (floor_log2 (log) + 1);
8431 /* Return the size of a DIE as it is represented in the
8432 .debug_info section. */
8434 static unsigned long
8435 size_of_die (dw_die_ref die)
8437 unsigned long size = 0;
8441 size += size_of_uleb128 (die->die_abbrev);
8442 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8444 switch (AT_class (a))
8446 case dw_val_class_addr:
8447 size += DWARF2_ADDR_SIZE;
8449 case dw_val_class_offset:
8450 size += DWARF_OFFSET_SIZE;
8452 case dw_val_class_loc:
8454 unsigned long lsize = size_of_locs (AT_loc (a));
8457 size += constant_size (lsize);
8461 case dw_val_class_loc_list:
8462 size += DWARF_OFFSET_SIZE;
8464 case dw_val_class_range_list:
8465 size += DWARF_OFFSET_SIZE;
8467 case dw_val_class_const:
8468 size += size_of_sleb128 (AT_int (a));
8470 case dw_val_class_unsigned_const:
8471 size += constant_size (AT_unsigned (a));
8473 case dw_val_class_long_long:
8474 size += 1 + 2*HOST_BITS_PER_WIDE_INT/HOST_BITS_PER_CHAR; /* block */
8476 case dw_val_class_vec:
8477 size += constant_size (a->dw_attr_val.v.val_vec.length
8478 * a->dw_attr_val.v.val_vec.elt_size)
8479 + a->dw_attr_val.v.val_vec.length
8480 * a->dw_attr_val.v.val_vec.elt_size; /* block */
8482 case dw_val_class_flag:
8485 case dw_val_class_die_ref:
8486 /* In DWARF2, DW_FORM_ref_addr is sized by target address length,
8487 whereas in DWARF3 it's always sized as an offset. */
8488 if (AT_ref_external (a) && dwarf_version == 2)
8489 size += DWARF2_ADDR_SIZE;
8491 size += DWARF_OFFSET_SIZE;
8493 case dw_val_class_fde_ref:
8494 size += DWARF_OFFSET_SIZE;
8496 case dw_val_class_lbl_id:
8497 size += DWARF2_ADDR_SIZE;
8499 case dw_val_class_lineptr:
8500 case dw_val_class_macptr:
8501 size += DWARF_OFFSET_SIZE;
8503 case dw_val_class_str:
8504 if (AT_string_form (a) == DW_FORM_strp)
8505 size += DWARF_OFFSET_SIZE;
8507 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
8509 case dw_val_class_file:
8510 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
8520 /* Size the debugging information associated with a given DIE. Visits the
8521 DIE's children recursively. Updates the global variable next_die_offset, on
8522 each time through. Uses the current value of next_die_offset to update the
8523 die_offset field in each DIE. */
8526 calc_die_sizes (dw_die_ref die)
8530 die->die_offset = next_die_offset;
8531 next_die_offset += size_of_die (die);
8533 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
8535 if (die->die_child != NULL)
8536 /* Count the null byte used to terminate sibling lists. */
8537 next_die_offset += 1;
8540 /* Set the marks for a die and its children. We do this so
8541 that we know whether or not a reference needs to use FORM_ref_addr; only
8542 DIEs in the same CU will be marked. We used to clear out the offset
8543 and use that as the flag, but ran into ordering problems. */
8546 mark_dies (dw_die_ref die)
8550 gcc_assert (!die->die_mark);
8553 FOR_EACH_CHILD (die, c, mark_dies (c));
8556 /* Clear the marks for a die and its children. */
8559 unmark_dies (dw_die_ref die)
8563 gcc_assert (die->die_mark);
8566 FOR_EACH_CHILD (die, c, unmark_dies (c));
8569 /* Clear the marks for a die, its children and referred dies. */
8572 unmark_all_dies (dw_die_ref die)
8582 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8584 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8585 if (AT_class (a) == dw_val_class_die_ref)
8586 unmark_all_dies (AT_ref (a));
8589 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8590 generated for the compilation unit. */
8592 static unsigned long
8593 size_of_pubnames (VEC (pubname_entry, gc) * names)
8599 size = DWARF_PUBNAMES_HEADER_SIZE;
8600 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8601 if (names != pubtype_table
8602 || p->die->die_offset != 0
8603 || !flag_eliminate_unused_debug_types)
8604 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8606 size += DWARF_OFFSET_SIZE;
8610 /* Return the size of the information in the .debug_aranges section. */
8612 static unsigned long
8613 size_of_aranges (void)
8617 size = DWARF_ARANGES_HEADER_SIZE;
8619 /* Count the address/length pair for this compilation unit. */
8620 if (text_section_used)
8621 size += 2 * DWARF2_ADDR_SIZE;
8622 if (cold_text_section_used)
8623 size += 2 * DWARF2_ADDR_SIZE;
8624 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8626 /* Count the two zero words used to terminated the address range table. */
8627 size += 2 * DWARF2_ADDR_SIZE;
8631 /* Select the encoding of an attribute value. */
8633 static enum dwarf_form
8634 value_format (dw_attr_ref a)
8636 switch (a->dw_attr_val.val_class)
8638 case dw_val_class_addr:
8639 return DW_FORM_addr;
8640 case dw_val_class_range_list:
8641 case dw_val_class_offset:
8642 case dw_val_class_loc_list:
8643 switch (DWARF_OFFSET_SIZE)
8646 return DW_FORM_data4;
8648 return DW_FORM_data8;
8652 case dw_val_class_loc:
8653 switch (constant_size (size_of_locs (AT_loc (a))))
8656 return DW_FORM_block1;
8658 return DW_FORM_block2;
8662 case dw_val_class_const:
8663 return DW_FORM_sdata;
8664 case dw_val_class_unsigned_const:
8665 switch (constant_size (AT_unsigned (a)))
8668 return DW_FORM_data1;
8670 return DW_FORM_data2;
8672 return DW_FORM_data4;
8674 return DW_FORM_data8;
8678 case dw_val_class_long_long:
8679 return DW_FORM_block1;
8680 case dw_val_class_vec:
8681 switch (constant_size (a->dw_attr_val.v.val_vec.length
8682 * a->dw_attr_val.v.val_vec.elt_size))
8685 return DW_FORM_block1;
8687 return DW_FORM_block2;
8689 return DW_FORM_block4;
8693 case dw_val_class_flag:
8694 return DW_FORM_flag;
8695 case dw_val_class_die_ref:
8696 if (AT_ref_external (a))
8697 return DW_FORM_ref_addr;
8700 case dw_val_class_fde_ref:
8701 return DW_FORM_data;
8702 case dw_val_class_lbl_id:
8703 return DW_FORM_addr;
8704 case dw_val_class_lineptr:
8705 case dw_val_class_macptr:
8706 return DW_FORM_data;
8707 case dw_val_class_str:
8708 return AT_string_form (a);
8709 case dw_val_class_file:
8710 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8713 return DW_FORM_data1;
8715 return DW_FORM_data2;
8717 return DW_FORM_data4;
8727 /* Output the encoding of an attribute value. */
8730 output_value_format (dw_attr_ref a)
8732 enum dwarf_form form = value_format (a);
8734 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8737 /* Output the .debug_abbrev section which defines the DIE abbreviation
8741 output_abbrev_section (void)
8743 unsigned long abbrev_id;
8745 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8747 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8751 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8752 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8753 dwarf_tag_name (abbrev->die_tag));
8755 if (abbrev->die_child != NULL)
8756 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8758 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8760 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8763 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8764 dwarf_attr_name (a_attr->dw_attr));
8765 output_value_format (a_attr);
8768 dw2_asm_output_data (1, 0, NULL);
8769 dw2_asm_output_data (1, 0, NULL);
8772 /* Terminate the table. */
8773 dw2_asm_output_data (1, 0, NULL);
8776 /* Output a symbol we can use to refer to this DIE from another CU. */
8779 output_die_symbol (dw_die_ref die)
8781 char *sym = die->die_symbol;
8786 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8787 /* We make these global, not weak; if the target doesn't support
8788 .linkonce, it doesn't support combining the sections, so debugging
8790 targetm.asm_out.globalize_label (asm_out_file, sym);
8792 ASM_OUTPUT_LABEL (asm_out_file, sym);
8795 /* Return a new location list, given the begin and end range, and the
8796 expression. gensym tells us whether to generate a new internal symbol for
8797 this location list node, which is done for the head of the list only. */
8799 static inline dw_loc_list_ref
8800 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8801 const char *section, unsigned int gensym)
8803 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8805 retlist->begin = begin;
8807 retlist->expr = expr;
8808 retlist->section = section;
8810 retlist->ll_symbol = gen_internal_sym ("LLST");
8815 /* Add a location description expression to a location list. */
8818 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8819 const char *begin, const char *end,
8820 const char *section)
8824 /* Find the end of the chain. */
8825 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8828 /* Add a new location list node to the list. */
8829 *d = new_loc_list (descr, begin, end, section, 0);
8832 /* Output the location list given to us. */
8835 output_loc_list (dw_loc_list_ref list_head)
8837 dw_loc_list_ref curr = list_head;
8839 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8841 /* Walk the location list, and output each range + expression. */
8842 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8845 /* Don't output an entry that starts and ends at the same address. */
8846 if (strcmp (curr->begin, curr->end) == 0)
8848 if (!have_multiple_function_sections)
8850 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8851 "Location list begin address (%s)",
8852 list_head->ll_symbol);
8853 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8854 "Location list end address (%s)",
8855 list_head->ll_symbol);
8859 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8860 "Location list begin address (%s)",
8861 list_head->ll_symbol);
8862 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8863 "Location list end address (%s)",
8864 list_head->ll_symbol);
8866 size = size_of_locs (curr->expr);
8868 /* Output the block length for this list of location operations. */
8869 gcc_assert (size <= 0xffff);
8870 dw2_asm_output_data (2, size, "%s", "Location expression size");
8872 output_loc_sequence (curr->expr);
8875 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8876 "Location list terminator begin (%s)",
8877 list_head->ll_symbol);
8878 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8879 "Location list terminator end (%s)",
8880 list_head->ll_symbol);
8883 /* Output the DIE and its attributes. Called recursively to generate
8884 the definitions of each child DIE. */
8887 output_die (dw_die_ref die)
8894 /* If someone in another CU might refer to us, set up a symbol for
8895 them to point to. */
8896 if (die->die_symbol)
8897 output_die_symbol (die);
8899 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8900 (unsigned long)die->die_offset,
8901 dwarf_tag_name (die->die_tag));
8903 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8905 const char *name = dwarf_attr_name (a->dw_attr);
8907 switch (AT_class (a))
8909 case dw_val_class_addr:
8910 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8913 case dw_val_class_offset:
8914 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8918 case dw_val_class_range_list:
8920 char *p = strchr (ranges_section_label, '\0');
8922 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8923 a->dw_attr_val.v.val_offset);
8924 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8925 debug_ranges_section, "%s", name);
8930 case dw_val_class_loc:
8931 size = size_of_locs (AT_loc (a));
8933 /* Output the block length for this list of location operations. */
8934 dw2_asm_output_data (constant_size (size), size, "%s", name);
8936 output_loc_sequence (AT_loc (a));
8939 case dw_val_class_const:
8940 /* ??? It would be slightly more efficient to use a scheme like is
8941 used for unsigned constants below, but gdb 4.x does not sign
8942 extend. Gdb 5.x does sign extend. */
8943 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8946 case dw_val_class_unsigned_const:
8947 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8948 AT_unsigned (a), "%s", name);
8951 case dw_val_class_long_long:
8953 unsigned HOST_WIDE_INT first, second;
8955 dw2_asm_output_data (1,
8956 2 * HOST_BITS_PER_WIDE_INT
8957 / HOST_BITS_PER_CHAR,
8960 if (WORDS_BIG_ENDIAN)
8962 first = CONST_DOUBLE_HIGH (a->dw_attr_val.v.val_long_long);
8963 second = CONST_DOUBLE_LOW (a->dw_attr_val.v.val_long_long);
8967 first = CONST_DOUBLE_LOW (a->dw_attr_val.v.val_long_long);
8968 second = CONST_DOUBLE_HIGH (a->dw_attr_val.v.val_long_long);
8971 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8972 first, "long long constant");
8973 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
8978 case dw_val_class_vec:
8980 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8981 unsigned int len = a->dw_attr_val.v.val_vec.length;
8985 dw2_asm_output_data (constant_size (len * elt_size),
8986 len * elt_size, "%s", name);
8987 if (elt_size > sizeof (HOST_WIDE_INT))
8992 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8995 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8996 "fp or vector constant word %u", i);
9000 case dw_val_class_flag:
9001 dw2_asm_output_data (1, AT_flag (a), "%s", name);
9004 case dw_val_class_loc_list:
9006 char *sym = AT_loc_list (a)->ll_symbol;
9009 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
9014 case dw_val_class_die_ref:
9015 if (AT_ref_external (a))
9017 char *sym = AT_ref (a)->die_symbol;
9022 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9023 length, whereas in DWARF3 it's always sized as an offset. */
9024 if (dwarf_version == 2)
9025 size = DWARF2_ADDR_SIZE;
9027 size = DWARF_OFFSET_SIZE;
9028 dw2_asm_output_offset (size, sym, debug_info_section, "%s", name);
9032 gcc_assert (AT_ref (a)->die_offset);
9033 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
9038 case dw_val_class_fde_ref:
9042 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
9043 a->dw_attr_val.v.val_fde_index * 2);
9044 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
9049 case dw_val_class_lbl_id:
9050 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
9053 case dw_val_class_lineptr:
9054 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9055 debug_line_section, "%s", name);
9058 case dw_val_class_macptr:
9059 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
9060 debug_macinfo_section, "%s", name);
9063 case dw_val_class_str:
9064 if (AT_string_form (a) == DW_FORM_strp)
9065 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
9066 a->dw_attr_val.v.val_str->label,
9068 "%s: \"%s\"", name, AT_string (a));
9070 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
9073 case dw_val_class_file:
9075 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
9077 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
9078 a->dw_attr_val.v.val_file->filename);
9087 FOR_EACH_CHILD (die, c, output_die (c));
9089 /* Add null byte to terminate sibling list. */
9090 if (die->die_child != NULL)
9091 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
9092 (unsigned long) die->die_offset);
9095 /* Output the compilation unit that appears at the beginning of the
9096 .debug_info section, and precedes the DIE descriptions. */
9099 output_compilation_unit_header (void)
9101 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9102 dw2_asm_output_data (4, 0xffffffff,
9103 "Initial length escape value indicating 64-bit DWARF extension");
9104 dw2_asm_output_data (DWARF_OFFSET_SIZE,
9105 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
9106 "Length of Compilation Unit Info");
9107 dw2_asm_output_data (2, dwarf_version, "DWARF version number");
9108 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
9109 debug_abbrev_section,
9110 "Offset Into Abbrev. Section");
9111 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
9114 /* Output the compilation unit DIE and its children. */
9117 output_comp_unit (dw_die_ref die, int output_if_empty)
9119 const char *secname;
9122 /* Unless we are outputting main CU, we may throw away empty ones. */
9123 if (!output_if_empty && die->die_child == NULL)
9126 /* Even if there are no children of this DIE, we must output the information
9127 about the compilation unit. Otherwise, on an empty translation unit, we
9128 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9129 will then complain when examining the file. First mark all the DIEs in
9130 this CU so we know which get local refs. */
9133 build_abbrev_table (die);
9135 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9136 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9137 calc_die_sizes (die);
9139 oldsym = die->die_symbol;
9142 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
9144 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
9146 die->die_symbol = NULL;
9147 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
9150 switch_to_section (debug_info_section);
9152 /* Output debugging information. */
9153 output_compilation_unit_header ();
9156 /* Leave the marks on the main CU, so we can check them in
9161 die->die_symbol = oldsym;
9165 /* Return the DWARF2/3 pubname associated with a decl. */
9168 dwarf2_name (tree decl, int scope)
9170 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
9173 /* Add a new entry to .debug_pubnames if appropriate. */
9176 add_pubname_string (const char *str, dw_die_ref die)
9181 e.name = xstrdup (str);
9182 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
9186 add_pubname (tree decl, dw_die_ref die)
9188 if (TREE_PUBLIC (decl))
9189 add_pubname_string (dwarf2_name (decl, 1), die);
9192 /* Add a new entry to .debug_pubtypes if appropriate. */
9195 add_pubtype (tree decl, dw_die_ref die)
9200 if ((TREE_PUBLIC (decl)
9201 || die->die_parent == comp_unit_die)
9202 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
9207 if (TYPE_NAME (decl))
9209 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
9210 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
9211 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
9212 && DECL_NAME (TYPE_NAME (decl)))
9213 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
9215 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
9219 e.name = xstrdup (dwarf2_name (decl, 1));
9221 /* If we don't have a name for the type, there's no point in adding
9223 if (e.name && e.name[0] != '\0')
9224 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
9228 /* Output the public names table used to speed up access to externally
9229 visible names; or the public types table used to find type definitions. */
9232 output_pubnames (VEC (pubname_entry, gc) * names)
9235 unsigned long pubnames_length = size_of_pubnames (names);
9238 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9239 dw2_asm_output_data (4, 0xffffffff,
9240 "Initial length escape value indicating 64-bit DWARF extension");
9241 if (names == pubname_table)
9242 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9243 "Length of Public Names Info");
9245 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
9246 "Length of Public Type Names Info");
9247 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9248 dw2_asm_output_data (2, 2, "DWARF Version");
9249 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9251 "Offset of Compilation Unit Info");
9252 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
9253 "Compilation Unit Length");
9255 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
9257 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9258 if (names == pubname_table)
9259 gcc_assert (pub->die->die_mark);
9261 if (names != pubtype_table
9262 || pub->die->die_offset != 0
9263 || !flag_eliminate_unused_debug_types)
9265 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
9268 dw2_asm_output_nstring (pub->name, -1, "external name");
9272 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
9275 /* Add a new entry to .debug_aranges if appropriate. */
9278 add_arange (tree decl, dw_die_ref die)
9280 if (! DECL_SECTION_NAME (decl))
9283 if (arange_table_in_use == arange_table_allocated)
9285 arange_table_allocated += ARANGE_TABLE_INCREMENT;
9286 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
9287 arange_table_allocated);
9288 memset (arange_table + arange_table_in_use, 0,
9289 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
9292 arange_table[arange_table_in_use++] = die;
9295 /* Output the information that goes into the .debug_aranges table.
9296 Namely, define the beginning and ending address range of the
9297 text section generated for this compilation unit. */
9300 output_aranges (void)
9303 unsigned long aranges_length = size_of_aranges ();
9305 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9306 dw2_asm_output_data (4, 0xffffffff,
9307 "Initial length escape value indicating 64-bit DWARF extension");
9308 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
9309 "Length of Address Ranges Info");
9310 /* Version number for aranges is still 2, even in DWARF3. */
9311 dw2_asm_output_data (2, 2, "DWARF Version");
9312 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
9314 "Offset of Compilation Unit Info");
9315 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
9316 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9318 /* We need to align to twice the pointer size here. */
9319 if (DWARF_ARANGES_PAD_SIZE)
9321 /* Pad using a 2 byte words so that padding is correct for any
9323 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9324 2 * DWARF2_ADDR_SIZE);
9325 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
9326 dw2_asm_output_data (2, 0, NULL);
9329 /* It is necessary not to output these entries if the sections were
9330 not used; if the sections were not used, the length will be 0 and
9331 the address may end up as 0 if the section is discarded by ld
9332 --gc-sections, leaving an invalid (0, 0) entry that can be
9333 confused with the terminator. */
9334 if (text_section_used)
9336 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
9337 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
9338 text_section_label, "Length");
9340 if (cold_text_section_used)
9342 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
9344 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
9345 cold_text_section_label, "Length");
9348 for (i = 0; i < arange_table_in_use; i++)
9350 dw_die_ref die = arange_table[i];
9352 /* We shouldn't see aranges for DIEs outside of the main CU. */
9353 gcc_assert (die->die_mark);
9355 if (die->die_tag == DW_TAG_subprogram)
9357 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
9359 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
9360 get_AT_low_pc (die), "Length");
9364 /* A static variable; extract the symbol from DW_AT_location.
9365 Note that this code isn't currently hit, as we only emit
9366 aranges for functions (jason 9/23/99). */
9367 dw_attr_ref a = get_AT (die, DW_AT_location);
9368 dw_loc_descr_ref loc;
9370 gcc_assert (a && AT_class (a) == dw_val_class_loc);
9373 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
9375 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
9376 loc->dw_loc_oprnd1.v.val_addr, "Address");
9377 dw2_asm_output_data (DWARF2_ADDR_SIZE,
9378 get_AT_unsigned (die, DW_AT_byte_size),
9383 /* Output the terminator words. */
9384 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9385 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9388 /* Add a new entry to .debug_ranges. Return the offset at which it
9392 add_ranges_num (int num)
9394 unsigned int in_use = ranges_table_in_use;
9396 if (in_use == ranges_table_allocated)
9398 ranges_table_allocated += RANGES_TABLE_INCREMENT;
9399 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
9400 ranges_table_allocated);
9401 memset (ranges_table + ranges_table_in_use, 0,
9402 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
9405 ranges_table[in_use].num = num;
9406 ranges_table_in_use = in_use + 1;
9408 return in_use * 2 * DWARF2_ADDR_SIZE;
9411 /* Add a new entry to .debug_ranges corresponding to a block, or a
9412 range terminator if BLOCK is NULL. */
9415 add_ranges (const_tree block)
9417 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
9420 /* Add a new entry to .debug_ranges corresponding to a pair of
9424 add_ranges_by_labels (const char *begin, const char *end)
9426 unsigned int in_use = ranges_by_label_in_use;
9428 if (in_use == ranges_by_label_allocated)
9430 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
9431 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
9433 ranges_by_label_allocated);
9434 memset (ranges_by_label + ranges_by_label_in_use, 0,
9435 RANGES_TABLE_INCREMENT
9436 * sizeof (struct dw_ranges_by_label_struct));
9439 ranges_by_label[in_use].begin = begin;
9440 ranges_by_label[in_use].end = end;
9441 ranges_by_label_in_use = in_use + 1;
9443 return add_ranges_num (-(int)in_use - 1);
9447 output_ranges (void)
9450 static const char *const start_fmt = "Offset 0x%x";
9451 const char *fmt = start_fmt;
9453 for (i = 0; i < ranges_table_in_use; i++)
9455 int block_num = ranges_table[i].num;
9459 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
9460 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
9462 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
9463 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
9465 /* If all code is in the text section, then the compilation
9466 unit base address defaults to DW_AT_low_pc, which is the
9467 base of the text section. */
9468 if (!have_multiple_function_sections)
9470 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
9472 fmt, i * 2 * DWARF2_ADDR_SIZE);
9473 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
9474 text_section_label, NULL);
9477 /* Otherwise, the compilation unit base address is zero,
9478 which allows us to use absolute addresses, and not worry
9479 about whether the target supports cross-section
9483 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
9484 fmt, i * 2 * DWARF2_ADDR_SIZE);
9485 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
9491 /* Negative block_num stands for an index into ranges_by_label. */
9492 else if (block_num < 0)
9494 int lab_idx = - block_num - 1;
9496 if (!have_multiple_function_sections)
9500 /* If we ever use add_ranges_by_labels () for a single
9501 function section, all we have to do is to take out
9503 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9504 ranges_by_label[lab_idx].begin,
9506 fmt, i * 2 * DWARF2_ADDR_SIZE);
9507 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
9508 ranges_by_label[lab_idx].end,
9509 text_section_label, NULL);
9514 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9515 ranges_by_label[lab_idx].begin,
9516 fmt, i * 2 * DWARF2_ADDR_SIZE);
9517 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
9518 ranges_by_label[lab_idx].end,
9524 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9525 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
9531 /* Data structure containing information about input files. */
9534 const char *path; /* Complete file name. */
9535 const char *fname; /* File name part. */
9536 int length; /* Length of entire string. */
9537 struct dwarf_file_data * file_idx; /* Index in input file table. */
9538 int dir_idx; /* Index in directory table. */
9541 /* Data structure containing information about directories with source
9545 const char *path; /* Path including directory name. */
9546 int length; /* Path length. */
9547 int prefix; /* Index of directory entry which is a prefix. */
9548 int count; /* Number of files in this directory. */
9549 int dir_idx; /* Index of directory used as base. */
9552 /* Callback function for file_info comparison. We sort by looking at
9553 the directories in the path. */
9556 file_info_cmp (const void *p1, const void *p2)
9558 const struct file_info *const s1 = (const struct file_info *) p1;
9559 const struct file_info *const s2 = (const struct file_info *) p2;
9560 const unsigned char *cp1;
9561 const unsigned char *cp2;
9563 /* Take care of file names without directories. We need to make sure that
9564 we return consistent values to qsort since some will get confused if
9565 we return the same value when identical operands are passed in opposite
9566 orders. So if neither has a directory, return 0 and otherwise return
9567 1 or -1 depending on which one has the directory. */
9568 if ((s1->path == s1->fname || s2->path == s2->fname))
9569 return (s2->path == s2->fname) - (s1->path == s1->fname);
9571 cp1 = (const unsigned char *) s1->path;
9572 cp2 = (const unsigned char *) s2->path;
9578 /* Reached the end of the first path? If so, handle like above. */
9579 if ((cp1 == (const unsigned char *) s1->fname)
9580 || (cp2 == (const unsigned char *) s2->fname))
9581 return ((cp2 == (const unsigned char *) s2->fname)
9582 - (cp1 == (const unsigned char *) s1->fname));
9584 /* Character of current path component the same? */
9585 else if (*cp1 != *cp2)
9590 struct file_name_acquire_data
9592 struct file_info *files;
9597 /* Traversal function for the hash table. */
9600 file_name_acquire (void ** slot, void *data)
9602 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9603 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9604 struct file_info *fi;
9607 gcc_assert (fnad->max_files >= d->emitted_number);
9609 if (! d->emitted_number)
9612 gcc_assert (fnad->max_files != fnad->used_files);
9614 fi = fnad->files + fnad->used_files++;
9616 /* Skip all leading "./". */
9618 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9621 /* Create a new array entry. */
9623 fi->length = strlen (f);
9626 /* Search for the file name part. */
9627 f = strrchr (f, DIR_SEPARATOR);
9628 #if defined (DIR_SEPARATOR_2)
9630 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9634 if (f == NULL || f < g)
9640 fi->fname = f == NULL ? fi->path : f + 1;
9644 /* Output the directory table and the file name table. We try to minimize
9645 the total amount of memory needed. A heuristic is used to avoid large
9646 slowdowns with many input files. */
9649 output_file_names (void)
9651 struct file_name_acquire_data fnad;
9653 struct file_info *files;
9654 struct dir_info *dirs;
9663 if (!last_emitted_file)
9665 dw2_asm_output_data (1, 0, "End directory table");
9666 dw2_asm_output_data (1, 0, "End file name table");
9670 numfiles = last_emitted_file->emitted_number;
9672 /* Allocate the various arrays we need. */
9673 files = XALLOCAVEC (struct file_info, numfiles);
9674 dirs = XALLOCAVEC (struct dir_info, numfiles);
9677 fnad.used_files = 0;
9678 fnad.max_files = numfiles;
9679 htab_traverse (file_table, file_name_acquire, &fnad);
9680 gcc_assert (fnad.used_files == fnad.max_files);
9682 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9684 /* Find all the different directories used. */
9685 dirs[0].path = files[0].path;
9686 dirs[0].length = files[0].fname - files[0].path;
9687 dirs[0].prefix = -1;
9689 dirs[0].dir_idx = 0;
9690 files[0].dir_idx = 0;
9693 for (i = 1; i < numfiles; i++)
9694 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9695 && memcmp (dirs[ndirs - 1].path, files[i].path,
9696 dirs[ndirs - 1].length) == 0)
9698 /* Same directory as last entry. */
9699 files[i].dir_idx = ndirs - 1;
9700 ++dirs[ndirs - 1].count;
9706 /* This is a new directory. */
9707 dirs[ndirs].path = files[i].path;
9708 dirs[ndirs].length = files[i].fname - files[i].path;
9709 dirs[ndirs].count = 1;
9710 dirs[ndirs].dir_idx = ndirs;
9711 files[i].dir_idx = ndirs;
9713 /* Search for a prefix. */
9714 dirs[ndirs].prefix = -1;
9715 for (j = 0; j < ndirs; j++)
9716 if (dirs[j].length < dirs[ndirs].length
9717 && dirs[j].length > 1
9718 && (dirs[ndirs].prefix == -1
9719 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9720 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9721 dirs[ndirs].prefix = j;
9726 /* Now to the actual work. We have to find a subset of the directories which
9727 allow expressing the file name using references to the directory table
9728 with the least amount of characters. We do not do an exhaustive search
9729 where we would have to check out every combination of every single
9730 possible prefix. Instead we use a heuristic which provides nearly optimal
9731 results in most cases and never is much off. */
9732 saved = XALLOCAVEC (int, ndirs);
9733 savehere = XALLOCAVEC (int, ndirs);
9735 memset (saved, '\0', ndirs * sizeof (saved[0]));
9736 for (i = 0; i < ndirs; i++)
9741 /* We can always save some space for the current directory. But this
9742 does not mean it will be enough to justify adding the directory. */
9743 savehere[i] = dirs[i].length;
9744 total = (savehere[i] - saved[i]) * dirs[i].count;
9746 for (j = i + 1; j < ndirs; j++)
9749 if (saved[j] < dirs[i].length)
9751 /* Determine whether the dirs[i] path is a prefix of the
9756 while (k != -1 && k != (int) i)
9761 /* Yes it is. We can possibly save some memory by
9762 writing the filenames in dirs[j] relative to
9764 savehere[j] = dirs[i].length;
9765 total += (savehere[j] - saved[j]) * dirs[j].count;
9770 /* Check whether we can save enough to justify adding the dirs[i]
9772 if (total > dirs[i].length + 1)
9774 /* It's worthwhile adding. */
9775 for (j = i; j < ndirs; j++)
9776 if (savehere[j] > 0)
9778 /* Remember how much we saved for this directory so far. */
9779 saved[j] = savehere[j];
9781 /* Remember the prefix directory. */
9782 dirs[j].dir_idx = i;
9787 /* Emit the directory name table. */
9789 idx_offset = dirs[0].length > 0 ? 1 : 0;
9790 for (i = 1 - idx_offset; i < ndirs; i++)
9791 dw2_asm_output_nstring (dirs[i].path,
9793 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
9794 "Directory Entry: 0x%x", i + idx_offset);
9796 dw2_asm_output_data (1, 0, "End directory table");
9798 /* We have to emit them in the order of emitted_number since that's
9799 used in the debug info generation. To do this efficiently we
9800 generate a back-mapping of the indices first. */
9801 backmap = XALLOCAVEC (int, numfiles);
9802 for (i = 0; i < numfiles; i++)
9803 backmap[files[i].file_idx->emitted_number - 1] = i;
9805 /* Now write all the file names. */
9806 for (i = 0; i < numfiles; i++)
9808 int file_idx = backmap[i];
9809 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9811 #ifdef VMS_DEBUGGING_INFO
9812 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9814 /* Setting these fields can lead to debugger miscomparisons,
9815 but VMS Debug requires them to be set correctly. */
9820 int maxfilelen = strlen (files[file_idx].path)
9821 + dirs[dir_idx].length
9822 + MAX_VMS_VERSION_LEN + 1;
9823 char *filebuf = XALLOCAVEC (char, maxfilelen);
9825 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
9826 snprintf (filebuf, maxfilelen, "%s;%d",
9827 files[file_idx].path + dirs[dir_idx].length, ver);
9829 dw2_asm_output_nstring
9830 (filebuf, -1, "File Entry: 0x%x", (unsigned) i + 1);
9832 /* Include directory index. */
9833 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9835 /* Modification time. */
9836 dw2_asm_output_data_uleb128
9837 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
9841 /* File length in bytes. */
9842 dw2_asm_output_data_uleb128
9843 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
9847 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9848 "File Entry: 0x%x", (unsigned) i + 1);
9850 /* Include directory index. */
9851 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9853 /* Modification time. */
9854 dw2_asm_output_data_uleb128 (0, NULL);
9856 /* File length in bytes. */
9857 dw2_asm_output_data_uleb128 (0, NULL);
9861 dw2_asm_output_data (1, 0, "End file name table");
9865 /* Output the source line number correspondence information. This
9866 information goes into the .debug_line section. */
9869 output_line_info (void)
9871 char l1[20], l2[20], p1[20], p2[20];
9872 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9873 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9876 unsigned long lt_index;
9877 unsigned long current_line;
9880 unsigned long current_file;
9881 unsigned long function;
9883 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9884 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9885 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9886 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9888 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9889 dw2_asm_output_data (4, 0xffffffff,
9890 "Initial length escape value indicating 64-bit DWARF extension");
9891 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9892 "Length of Source Line Info");
9893 ASM_OUTPUT_LABEL (asm_out_file, l1);
9895 dw2_asm_output_data (2, dwarf_version, "DWARF Version");
9896 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9897 ASM_OUTPUT_LABEL (asm_out_file, p1);
9899 /* Define the architecture-dependent minimum instruction length (in
9900 bytes). In this implementation of DWARF, this field is used for
9901 information purposes only. Since GCC generates assembly language,
9902 we have no a priori knowledge of how many instruction bytes are
9903 generated for each source line, and therefore can use only the
9904 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9905 commands. Accordingly, we fix this as `1', which is "correct
9906 enough" for all architectures, and don't let the target override. */
9907 dw2_asm_output_data (1, 1,
9908 "Minimum Instruction Length");
9910 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9911 "Default is_stmt_start flag");
9912 dw2_asm_output_data (1, DWARF_LINE_BASE,
9913 "Line Base Value (Special Opcodes)");
9914 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9915 "Line Range Value (Special Opcodes)");
9916 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9917 "Special Opcode Base");
9919 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9923 case DW_LNS_advance_pc:
9924 case DW_LNS_advance_line:
9925 case DW_LNS_set_file:
9926 case DW_LNS_set_column:
9927 case DW_LNS_fixed_advance_pc:
9935 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9939 /* Write out the information about the files we use. */
9940 output_file_names ();
9941 ASM_OUTPUT_LABEL (asm_out_file, p2);
9943 /* We used to set the address register to the first location in the text
9944 section here, but that didn't accomplish anything since we already
9945 have a line note for the opening brace of the first function. */
9947 /* Generate the line number to PC correspondence table, encoded as
9948 a series of state machine operations. */
9952 if (cfun && in_cold_section_p)
9953 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9955 strcpy (prev_line_label, text_section_label);
9956 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9958 dw_line_info_ref line_info = &line_info_table[lt_index];
9961 /* Disable this optimization for now; GDB wants to see two line notes
9962 at the beginning of a function so it can find the end of the
9965 /* Don't emit anything for redundant notes. Just updating the
9966 address doesn't accomplish anything, because we already assume
9967 that anything after the last address is this line. */
9968 if (line_info->dw_line_num == current_line
9969 && line_info->dw_file_num == current_file)
9973 /* Emit debug info for the address of the current line.
9975 Unfortunately, we have little choice here currently, and must always
9976 use the most general form. GCC does not know the address delta
9977 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9978 attributes which will give an upper bound on the address range. We
9979 could perhaps use length attributes to determine when it is safe to
9980 use DW_LNS_fixed_advance_pc. */
9982 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9985 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9986 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9987 "DW_LNS_fixed_advance_pc");
9988 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9992 /* This can handle any delta. This takes
9993 4+DWARF2_ADDR_SIZE bytes. */
9994 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9995 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9996 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9997 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10000 strcpy (prev_line_label, line_label);
10002 /* Emit debug info for the source file of the current line, if
10003 different from the previous line. */
10004 if (line_info->dw_file_num != current_file)
10006 current_file = line_info->dw_file_num;
10007 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10008 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10011 /* Emit debug info for the current line number, choosing the encoding
10012 that uses the least amount of space. */
10013 if (line_info->dw_line_num != current_line)
10015 line_offset = line_info->dw_line_num - current_line;
10016 line_delta = line_offset - DWARF_LINE_BASE;
10017 current_line = line_info->dw_line_num;
10018 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10019 /* This can handle deltas from -10 to 234, using the current
10020 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
10022 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10023 "line %lu", current_line);
10026 /* This can handle any delta. This takes at least 4 bytes,
10027 depending on the value being encoded. */
10028 dw2_asm_output_data (1, DW_LNS_advance_line,
10029 "advance to line %lu", current_line);
10030 dw2_asm_output_data_sleb128 (line_offset, NULL);
10031 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10035 /* We still need to start a new row, so output a copy insn. */
10036 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10039 /* Emit debug info for the address of the end of the function. */
10042 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10043 "DW_LNS_fixed_advance_pc");
10044 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
10048 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10049 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10050 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10051 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
10054 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10055 dw2_asm_output_data_uleb128 (1, NULL);
10056 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10061 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
10063 dw_separate_line_info_ref line_info
10064 = &separate_line_info_table[lt_index];
10067 /* Don't emit anything for redundant notes. */
10068 if (line_info->dw_line_num == current_line
10069 && line_info->dw_file_num == current_file
10070 && line_info->function == function)
10074 /* Emit debug info for the address of the current line. If this is
10075 a new function, or the first line of a function, then we need
10076 to handle it differently. */
10077 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
10079 if (function != line_info->function)
10081 function = line_info->function;
10083 /* Set the address register to the first line in the function. */
10084 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10085 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10086 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10087 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10091 /* ??? See the DW_LNS_advance_pc comment above. */
10094 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10095 "DW_LNS_fixed_advance_pc");
10096 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10100 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10101 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10102 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10103 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10107 strcpy (prev_line_label, line_label);
10109 /* Emit debug info for the source file of the current line, if
10110 different from the previous line. */
10111 if (line_info->dw_file_num != current_file)
10113 current_file = line_info->dw_file_num;
10114 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
10115 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
10118 /* Emit debug info for the current line number, choosing the encoding
10119 that uses the least amount of space. */
10120 if (line_info->dw_line_num != current_line)
10122 line_offset = line_info->dw_line_num - current_line;
10123 line_delta = line_offset - DWARF_LINE_BASE;
10124 current_line = line_info->dw_line_num;
10125 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
10126 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
10127 "line %lu", current_line);
10130 dw2_asm_output_data (1, DW_LNS_advance_line,
10131 "advance to line %lu", current_line);
10132 dw2_asm_output_data_sleb128 (line_offset, NULL);
10133 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10137 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
10145 /* If we're done with a function, end its sequence. */
10146 if (lt_index == separate_line_info_table_in_use
10147 || separate_line_info_table[lt_index].function != function)
10152 /* Emit debug info for the address of the end of the function. */
10153 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
10156 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
10157 "DW_LNS_fixed_advance_pc");
10158 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
10162 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
10163 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
10164 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
10165 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
10168 /* Output the marker for the end of this sequence. */
10169 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
10170 dw2_asm_output_data_uleb128 (1, NULL);
10171 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
10175 /* Output the marker for the end of the line number info. */
10176 ASM_OUTPUT_LABEL (asm_out_file, l2);
10179 /* Given a pointer to a tree node for some base type, return a pointer to
10180 a DIE that describes the given type.
10182 This routine must only be called for GCC type nodes that correspond to
10183 Dwarf base (fundamental) types. */
10186 base_type_die (tree type)
10188 dw_die_ref base_type_result;
10189 enum dwarf_type encoding;
10191 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
10194 /* If this is a subtype that should not be emitted as a subrange type,
10195 use the base type. See subrange_type_for_debug_p. */
10196 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
10197 type = TREE_TYPE (type);
10199 switch (TREE_CODE (type))
10202 if (TYPE_STRING_FLAG (type))
10204 if (TYPE_UNSIGNED (type))
10205 encoding = DW_ATE_unsigned_char;
10207 encoding = DW_ATE_signed_char;
10209 else if (TYPE_UNSIGNED (type))
10210 encoding = DW_ATE_unsigned;
10212 encoding = DW_ATE_signed;
10216 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
10217 encoding = DW_ATE_decimal_float;
10219 encoding = DW_ATE_float;
10222 case FIXED_POINT_TYPE:
10223 if (TYPE_UNSIGNED (type))
10224 encoding = DW_ATE_unsigned_fixed;
10226 encoding = DW_ATE_signed_fixed;
10229 /* Dwarf2 doesn't know anything about complex ints, so use
10230 a user defined type for it. */
10232 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
10233 encoding = DW_ATE_complex_float;
10235 encoding = DW_ATE_lo_user;
10239 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10240 encoding = DW_ATE_boolean;
10244 /* No other TREE_CODEs are Dwarf fundamental types. */
10245 gcc_unreachable ();
10248 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
10250 /* This probably indicates a bug. */
10251 if (! TYPE_NAME (type))
10252 add_name_attribute (base_type_result, "__unknown__");
10254 add_AT_unsigned (base_type_result, DW_AT_byte_size,
10255 int_size_in_bytes (type));
10256 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
10258 return base_type_result;
10261 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10262 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10265 is_base_type (tree type)
10267 switch (TREE_CODE (type))
10273 case FIXED_POINT_TYPE:
10281 case QUAL_UNION_TYPE:
10282 case ENUMERAL_TYPE:
10283 case FUNCTION_TYPE:
10286 case REFERENCE_TYPE:
10293 gcc_unreachable ();
10299 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10300 node, return the size in bits for the type if it is a constant, or else
10301 return the alignment for the type if the type's size is not constant, or
10302 else return BITS_PER_WORD if the type actually turns out to be an
10303 ERROR_MARK node. */
10305 static inline unsigned HOST_WIDE_INT
10306 simple_type_size_in_bits (const_tree type)
10308 if (TREE_CODE (type) == ERROR_MARK)
10309 return BITS_PER_WORD;
10310 else if (TYPE_SIZE (type) == NULL_TREE)
10312 else if (host_integerp (TYPE_SIZE (type), 1))
10313 return tree_low_cst (TYPE_SIZE (type), 1);
10315 return TYPE_ALIGN (type);
10318 /* Given a pointer to a tree node for a subrange type, return a pointer
10319 to a DIE that describes the given type. */
10322 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
10324 dw_die_ref subrange_die;
10325 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
10327 if (context_die == NULL)
10328 context_die = comp_unit_die;
10330 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
10332 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
10334 /* The size of the subrange type and its base type do not match,
10335 so we need to generate a size attribute for the subrange type. */
10336 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
10340 add_bound_info (subrange_die, DW_AT_lower_bound, low);
10342 add_bound_info (subrange_die, DW_AT_upper_bound, high);
10344 return subrange_die;
10347 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10348 entry that chains various modifiers in front of the given type. */
10351 modified_type_die (tree type, int is_const_type, int is_volatile_type,
10352 dw_die_ref context_die)
10354 enum tree_code code = TREE_CODE (type);
10355 dw_die_ref mod_type_die;
10356 dw_die_ref sub_die = NULL;
10357 tree item_type = NULL;
10358 tree qualified_type;
10359 tree name, low, high;
10361 if (code == ERROR_MARK)
10364 /* See if we already have the appropriately qualified variant of
10367 = get_qualified_type (type,
10368 ((is_const_type ? TYPE_QUAL_CONST : 0)
10369 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
10371 /* If we do, then we can just use its DIE, if it exists. */
10372 if (qualified_type)
10374 mod_type_die = lookup_type_die (qualified_type);
10376 return mod_type_die;
10379 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
10381 /* Handle C typedef types. */
10382 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
10384 tree dtype = TREE_TYPE (name);
10386 if (qualified_type == dtype)
10388 /* For a named type, use the typedef. */
10389 gen_type_die (qualified_type, context_die);
10390 return lookup_type_die (qualified_type);
10392 else if (is_const_type < TYPE_READONLY (dtype)
10393 || is_volatile_type < TYPE_VOLATILE (dtype)
10394 || (is_const_type <= TYPE_READONLY (dtype)
10395 && is_volatile_type <= TYPE_VOLATILE (dtype)
10396 && DECL_ORIGINAL_TYPE (name) != type))
10397 /* cv-unqualified version of named type. Just use the unnamed
10398 type to which it refers. */
10399 return modified_type_die (DECL_ORIGINAL_TYPE (name),
10400 is_const_type, is_volatile_type,
10402 /* Else cv-qualified version of named type; fall through. */
10407 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
10408 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
10410 else if (is_volatile_type)
10412 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
10413 sub_die = modified_type_die (type, 0, 0, context_die);
10415 else if (code == POINTER_TYPE)
10417 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
10418 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10419 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10420 item_type = TREE_TYPE (type);
10422 else if (code == REFERENCE_TYPE)
10424 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
10425 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
10426 simple_type_size_in_bits (type) / BITS_PER_UNIT);
10427 item_type = TREE_TYPE (type);
10429 else if (code == INTEGER_TYPE
10430 && TREE_TYPE (type) != NULL_TREE
10431 && subrange_type_for_debug_p (type, &low, &high))
10433 mod_type_die = subrange_type_die (type, low, high, context_die);
10434 item_type = TREE_TYPE (type);
10436 else if (is_base_type (type))
10437 mod_type_die = base_type_die (type);
10440 gen_type_die (type, context_die);
10442 /* We have to get the type_main_variant here (and pass that to the
10443 `lookup_type_die' routine) because the ..._TYPE node we have
10444 might simply be a *copy* of some original type node (where the
10445 copy was created to help us keep track of typedef names) and
10446 that copy might have a different TYPE_UID from the original
10448 if (TREE_CODE (type) != VECTOR_TYPE)
10449 return lookup_type_die (type_main_variant (type));
10451 /* Vectors have the debugging information in the type,
10452 not the main variant. */
10453 return lookup_type_die (type);
10456 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10457 don't output a DW_TAG_typedef, since there isn't one in the
10458 user's program; just attach a DW_AT_name to the type. */
10460 && (TREE_CODE (name) != TYPE_DECL
10461 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
10463 if (TREE_CODE (name) == TYPE_DECL)
10464 /* Could just call add_name_and_src_coords_attributes here,
10465 but since this is a builtin type it doesn't have any
10466 useful source coordinates anyway. */
10467 name = DECL_NAME (name);
10468 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
10471 if (qualified_type)
10472 equate_type_number_to_die (qualified_type, mod_type_die);
10475 /* We must do this after the equate_type_number_to_die call, in case
10476 this is a recursive type. This ensures that the modified_type_die
10477 recursion will terminate even if the type is recursive. Recursive
10478 types are possible in Ada. */
10479 sub_die = modified_type_die (item_type,
10480 TYPE_READONLY (item_type),
10481 TYPE_VOLATILE (item_type),
10484 if (sub_die != NULL)
10485 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
10487 return mod_type_die;
10490 /* Generate a new name for the parameter pack name NAME (an
10491 IDENTIFIER_NODE) that incorporates its */
10494 make_ith_pack_parameter_name (tree name, int i)
10496 /* Munge the name to include the parameter index. */
10497 #define NUMBUF_LEN 128
10498 char numbuf[NUMBUF_LEN];
10502 snprintf (numbuf, NUMBUF_LEN, "%i", i);
10503 newname_len = IDENTIFIER_LENGTH (name)
10504 + strlen (numbuf) + 2;
10505 newname = (char*) alloca (newname_len);
10506 snprintf (newname, newname_len,
10507 "%s#%i", IDENTIFIER_POINTER (name), i);
10508 return get_identifier (newname);
10511 /* Generate DIEs for the generic parameters of T.
10512 T must be either a generic type or a generic function.
10513 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10516 gen_generic_params_dies (tree t)
10520 dw_die_ref die = NULL;
10522 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
10526 die = lookup_type_die (t);
10527 else if (DECL_P (t))
10528 die = lookup_decl_die (t);
10532 parms = lang_hooks.get_innermost_generic_parms (t);
10534 /* T has no generic parameter. It means T is neither a generic type
10535 or function. End of story. */
10538 parms_num = TREE_VEC_LENGTH (parms);
10539 args = lang_hooks.get_innermost_generic_args (t);
10540 for (i = 0; i < parms_num; i++)
10544 parm = TREE_VEC_ELT (parms, i);
10545 arg = TREE_VEC_ELT (args, i);
10546 if (parm && TREE_VALUE (parm) && arg)
10549 lang_hooks.types.get_argument_pack_elems (arg);
10552 /* So ARG is an argument pack and the elements of that pack
10553 are stored in PACK_ELEMS. */
10556 len = TREE_VEC_LENGTH (pack_elems);
10557 for (i = 0; i < len; i++)
10558 generic_parameter_die (TREE_VALUE (parm),
10559 TREE_VEC_ELT (pack_elems, i),
10562 else /* Arg is not an argument pack. */
10563 generic_parameter_die (TREE_VALUE (parm),
10565 -1/* Not a param pack. */);
10570 /* Create and return a DIE for PARM which should be
10571 the representation of a generic type parameter.
10572 For instance, in the C++ front end, PARM would be a template parameter.
10573 ARG is the argument to PARM.
10574 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10576 PACK_ELEM_INDEX is >= 0 if PARM is a generic parameter pack, and if ARG
10577 is one of the unpacked elements of the parameter PACK. In that case,
10578 PACK_ELEM_INDEX is the index of ARG in the parameter pack. */
10581 generic_parameter_die (tree parm, tree arg, dw_die_ref parent_die,
10582 int pack_elem_index)
10584 dw_die_ref tmpl_die = NULL;
10585 const char *name = NULL;
10587 if (!parm || !DECL_NAME (parm) || !arg)
10590 /* We support non-type generic parameters and arguments,
10591 type generic parameters and arguments, as well as
10592 generic generic parameters (a.k.a. template template parameters in C++)
10594 if (TREE_CODE (parm) == PARM_DECL)
10595 /* PARM is a nontype generic parameter */
10596 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
10597 else if (TREE_CODE (parm) == TYPE_DECL)
10598 /* PARM is a type generic parameter. */
10599 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
10600 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10601 /* PARM is a generic generic parameter.
10602 Its DIE is a GNU extension. It shall have a
10603 DW_AT_name attribute to represent the name of the template template
10604 parameter, and a DW_AT_GNU_template_name attribute to represent the
10605 name of the template template argument. */
10606 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
10609 gcc_unreachable ();
10615 if (pack_elem_index >= 0)
10617 /* PARM is an element of a parameter pack.
10618 Generate a name for it. */
10619 tree identifier = make_ith_pack_parameter_name (DECL_NAME (parm),
10622 name = IDENTIFIER_POINTER (identifier);
10625 name = IDENTIFIER_POINTER (DECL_NAME (parm));
10628 add_AT_string (tmpl_die, DW_AT_name, name);
10630 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
10632 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10633 TMPL_DIE should have a child DW_AT_type attribute that is set
10634 to the type of the argument to PARM, which is ARG.
10635 If PARM is a type generic parameter, TMPL_DIE should have a
10636 child DW_AT_type that is set to ARG. */
10637 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
10638 add_type_attribute (tmpl_die, tmpl_type, 0,
10639 TREE_THIS_VOLATILE (tmpl_type),
10644 /* So TMPL_DIE is a DIE representing a
10645 a generic generic template parameter, a.k.a template template
10646 parameter in C++ and arg is a template. */
10648 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10649 to the name of the argument. */
10650 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
10651 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
10654 if (TREE_CODE (parm) == PARM_DECL)
10655 /* So PARM is a non-type generic parameter.
10656 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10657 attribute of TMPL_DIE which value represents the value
10659 We must be careful here:
10660 The value of ARG might reference some function decls.
10661 We might currently be emitting debug info for a generic
10662 type and types are emitted before function decls, we don't
10663 know if the function decls referenced by ARG will actually be
10664 emitted after cgraph computations.
10665 So must defer the generation of the DW_AT_const_value to
10666 after cgraph is ready. */
10667 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
10673 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10674 an enumerated type. */
10677 type_is_enum (const_tree type)
10679 return TREE_CODE (type) == ENUMERAL_TYPE;
10682 /* Return the DBX register number described by a given RTL node. */
10684 static unsigned int
10685 dbx_reg_number (const_rtx rtl)
10687 unsigned regno = REGNO (rtl);
10689 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
10691 #ifdef LEAF_REG_REMAP
10692 if (current_function_uses_only_leaf_regs)
10694 int leaf_reg = LEAF_REG_REMAP (regno);
10695 if (leaf_reg != -1)
10696 regno = (unsigned) leaf_reg;
10700 return DBX_REGISTER_NUMBER (regno);
10703 /* Optionally add a DW_OP_piece term to a location description expression.
10704 DW_OP_piece is only added if the location description expression already
10705 doesn't end with DW_OP_piece. */
10708 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
10710 dw_loc_descr_ref loc;
10712 if (*list_head != NULL)
10714 /* Find the end of the chain. */
10715 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
10718 if (loc->dw_loc_opc != DW_OP_piece)
10719 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
10723 /* Return a location descriptor that designates a machine register or
10724 zero if there is none. */
10726 static dw_loc_descr_ref
10727 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
10731 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
10734 regs = targetm.dwarf_register_span (rtl);
10736 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
10737 return multiple_reg_loc_descriptor (rtl, regs, initialized);
10739 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
10742 /* Return a location descriptor that designates a machine register for
10743 a given hard register number. */
10745 static dw_loc_descr_ref
10746 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
10748 dw_loc_descr_ref reg_loc_descr;
10752 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
10754 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
10756 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10757 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10759 return reg_loc_descr;
10762 /* Given an RTL of a register, return a location descriptor that
10763 designates a value that spans more than one register. */
10765 static dw_loc_descr_ref
10766 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
10767 enum var_init_status initialized)
10769 int nregs, size, i;
10771 dw_loc_descr_ref loc_result = NULL;
10774 #ifdef LEAF_REG_REMAP
10775 if (current_function_uses_only_leaf_regs)
10777 int leaf_reg = LEAF_REG_REMAP (reg);
10778 if (leaf_reg != -1)
10779 reg = (unsigned) leaf_reg;
10782 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10783 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10785 /* Simple, contiguous registers. */
10786 if (regs == NULL_RTX)
10788 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10793 dw_loc_descr_ref t;
10795 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10796 VAR_INIT_STATUS_INITIALIZED);
10797 add_loc_descr (&loc_result, t);
10798 add_loc_descr_op_piece (&loc_result, size);
10804 /* Now onto stupid register sets in non contiguous locations. */
10806 gcc_assert (GET_CODE (regs) == PARALLEL);
10808 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10811 for (i = 0; i < XVECLEN (regs, 0); ++i)
10813 dw_loc_descr_ref t;
10815 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10816 VAR_INIT_STATUS_INITIALIZED);
10817 add_loc_descr (&loc_result, t);
10818 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10819 add_loc_descr_op_piece (&loc_result, size);
10822 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10823 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10827 #endif /* DWARF2_DEBUGGING_INFO */
10829 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10831 /* Return a location descriptor that designates a constant. */
10833 static dw_loc_descr_ref
10834 int_loc_descriptor (HOST_WIDE_INT i)
10836 enum dwarf_location_atom op;
10838 /* Pick the smallest representation of a constant, rather than just
10839 defaulting to the LEB encoding. */
10843 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10844 else if (i <= 0xff)
10845 op = DW_OP_const1u;
10846 else if (i <= 0xffff)
10847 op = DW_OP_const2u;
10848 else if (HOST_BITS_PER_WIDE_INT == 32
10849 || i <= 0xffffffff)
10850 op = DW_OP_const4u;
10857 op = DW_OP_const1s;
10858 else if (i >= -0x8000)
10859 op = DW_OP_const2s;
10860 else if (HOST_BITS_PER_WIDE_INT == 32
10861 || i >= -0x80000000)
10862 op = DW_OP_const4s;
10867 return new_loc_descr (op, i, 0);
10871 #ifdef DWARF2_DEBUGGING_INFO
10873 /* Return a location descriptor that designates a base+offset location. */
10875 static dw_loc_descr_ref
10876 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10877 enum var_init_status initialized)
10879 unsigned int regno;
10880 dw_loc_descr_ref result;
10881 dw_fde_ref fde = current_fde ();
10883 /* We only use "frame base" when we're sure we're talking about the
10884 post-prologue local stack frame. We do this by *not* running
10885 register elimination until this point, and recognizing the special
10886 argument pointer and soft frame pointer rtx's. */
10887 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10889 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10893 if (GET_CODE (elim) == PLUS)
10895 offset += INTVAL (XEXP (elim, 1));
10896 elim = XEXP (elim, 0);
10898 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10899 && (elim == hard_frame_pointer_rtx
10900 || elim == stack_pointer_rtx))
10901 || elim == (frame_pointer_needed
10902 ? hard_frame_pointer_rtx
10903 : stack_pointer_rtx));
10905 /* If drap register is used to align stack, use frame
10906 pointer + offset to access stack variables. If stack
10907 is aligned without drap, use stack pointer + offset to
10908 access stack variables. */
10909 if (crtl->stack_realign_tried
10910 && reg == frame_pointer_rtx)
10913 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
10914 ? HARD_FRAME_POINTER_REGNUM
10915 : STACK_POINTER_REGNUM);
10916 return new_reg_loc_descr (base_reg, offset);
10919 offset += frame_pointer_fb_offset;
10920 return new_loc_descr (DW_OP_fbreg, offset, 0);
10924 && fde->drap_reg != INVALID_REGNUM
10925 && (fde->drap_reg == REGNO (reg)
10926 || fde->vdrap_reg == REGNO (reg)))
10928 /* Use cfa+offset to represent the location of arguments passed
10929 on stack when drap is used to align stack. */
10930 return new_loc_descr (DW_OP_fbreg, offset, 0);
10933 regno = dbx_reg_number (reg);
10935 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10938 result = new_loc_descr (DW_OP_bregx, regno, offset);
10940 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10941 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10946 /* Return true if this RTL expression describes a base+offset calculation. */
10949 is_based_loc (const_rtx rtl)
10951 return (GET_CODE (rtl) == PLUS
10952 && ((REG_P (XEXP (rtl, 0))
10953 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10954 && CONST_INT_P (XEXP (rtl, 1)))));
10957 /* Return a descriptor that describes the concatenation of N locations
10958 used to form the address of a memory location. */
10960 static dw_loc_descr_ref
10961 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
10962 enum var_init_status initialized)
10965 dw_loc_descr_ref cc_loc_result = NULL;
10966 unsigned int n = XVECLEN (concatn, 0);
10968 for (i = 0; i < n; ++i)
10970 dw_loc_descr_ref ref;
10971 rtx x = XVECEXP (concatn, 0, i);
10973 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
10977 add_loc_descr (&cc_loc_result, ref);
10978 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10981 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10982 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10984 return cc_loc_result;
10987 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10990 static dw_loc_descr_ref
10991 tls_mem_loc_descriptor (rtx mem)
10994 dw_loc_descr_ref loc_result;
10996 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
10999 base = get_base_address (MEM_EXPR (mem));
11001 || TREE_CODE (base) != VAR_DECL
11002 || !DECL_THREAD_LOCAL_P (base))
11005 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
11006 if (loc_result == NULL)
11009 if (INTVAL (MEM_OFFSET (mem)))
11010 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
11015 /* The following routine converts the RTL for a variable or parameter
11016 (resident in memory) into an equivalent Dwarf representation of a
11017 mechanism for getting the address of that same variable onto the top of a
11018 hypothetical "address evaluation" stack.
11020 When creating memory location descriptors, we are effectively transforming
11021 the RTL for a memory-resident object into its Dwarf postfix expression
11022 equivalent. This routine recursively descends an RTL tree, turning
11023 it into Dwarf postfix code as it goes.
11025 MODE is the mode of the memory reference, needed to handle some
11026 autoincrement addressing modes.
11028 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
11029 location list for RTL.
11031 Return 0 if we can't represent the location. */
11033 static dw_loc_descr_ref
11034 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
11035 enum var_init_status initialized)
11037 dw_loc_descr_ref mem_loc_result = NULL;
11038 enum dwarf_location_atom op;
11039 dw_loc_descr_ref op0, op1;
11041 /* Note that for a dynamically sized array, the location we will generate a
11042 description of here will be the lowest numbered location which is
11043 actually within the array. That's *not* necessarily the same as the
11044 zeroth element of the array. */
11046 rtl = targetm.delegitimize_address (rtl);
11048 switch (GET_CODE (rtl))
11053 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
11054 just fall into the SUBREG code. */
11056 /* ... fall through ... */
11059 /* The case of a subreg may arise when we have a local (register)
11060 variable or a formal (register) parameter which doesn't quite fill
11061 up an entire register. For now, just assume that it is
11062 legitimate to make the Dwarf info refer to the whole register which
11063 contains the given subreg. */
11064 rtl = XEXP (rtl, 0);
11065 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
11068 /* ... fall through ... */
11071 /* Whenever a register number forms a part of the description of the
11072 method for calculating the (dynamic) address of a memory resident
11073 object, DWARF rules require the register number be referred to as
11074 a "base register". This distinction is not based in any way upon
11075 what category of register the hardware believes the given register
11076 belongs to. This is strictly DWARF terminology we're dealing with
11077 here. Note that in cases where the location of a memory-resident
11078 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11079 OP_CONST (0)) the actual DWARF location descriptor that we generate
11080 may just be OP_BASEREG (basereg). This may look deceptively like
11081 the object in question was allocated to a register (rather than in
11082 memory) so DWARF consumers need to be aware of the subtle
11083 distinction between OP_REG and OP_BASEREG. */
11084 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
11085 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
11086 else if (stack_realign_drap
11088 && crtl->args.internal_arg_pointer == rtl
11089 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
11091 /* If RTL is internal_arg_pointer, which has been optimized
11092 out, use DRAP instead. */
11093 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
11094 VAR_INIT_STATUS_INITIALIZED);
11100 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11101 VAR_INIT_STATUS_INITIALIZED);
11106 int shift = DWARF2_ADDR_SIZE
11107 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11108 shift *= BITS_PER_UNIT;
11109 if (GET_CODE (rtl) == SIGN_EXTEND)
11113 mem_loc_result = op0;
11114 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11115 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11116 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
11117 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11122 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11123 VAR_INIT_STATUS_INITIALIZED);
11124 if (mem_loc_result == NULL)
11125 mem_loc_result = tls_mem_loc_descriptor (rtl);
11126 if (mem_loc_result != 0)
11127 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
11131 rtl = XEXP (rtl, 1);
11133 /* ... fall through ... */
11136 /* Some ports can transform a symbol ref into a label ref, because
11137 the symbol ref is too far away and has to be dumped into a constant
11141 /* Alternatively, the symbol in the constant pool might be referenced
11142 by a different symbol. */
11143 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
11146 rtx tmp = get_pool_constant_mark (rtl, &marked);
11148 if (GET_CODE (tmp) == SYMBOL_REF)
11151 if (CONSTANT_POOL_ADDRESS_P (tmp))
11152 get_pool_constant_mark (tmp, &marked);
11157 /* If all references to this pool constant were optimized away,
11158 it was not output and thus we can't represent it.
11159 FIXME: might try to use DW_OP_const_value here, though
11160 DW_OP_piece complicates it. */
11165 if (GET_CODE (rtl) == SYMBOL_REF
11166 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11168 dw_loc_descr_ref temp;
11170 /* If this is not defined, we have no way to emit the data. */
11171 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
11174 temp = new_loc_descr (DW_OP_addr, 0, 0);
11175 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
11176 temp->dw_loc_oprnd1.v.val_addr = rtl;
11177 temp->dtprel = true;
11179 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
11180 add_loc_descr (&mem_loc_result, temp);
11186 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
11187 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
11188 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
11189 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11193 /* Extract the PLUS expression nested inside and fall into
11194 PLUS code below. */
11195 rtl = XEXP (rtl, 1);
11200 /* Turn these into a PLUS expression and fall into the PLUS code
11202 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
11203 GEN_INT (GET_CODE (rtl) == PRE_INC
11204 ? GET_MODE_UNIT_SIZE (mode)
11205 : -GET_MODE_UNIT_SIZE (mode)));
11207 /* ... fall through ... */
11211 if (is_based_loc (rtl))
11212 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
11213 INTVAL (XEXP (rtl, 1)),
11214 VAR_INIT_STATUS_INITIALIZED);
11217 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
11218 VAR_INIT_STATUS_INITIALIZED);
11219 if (mem_loc_result == 0)
11222 if (CONST_INT_P (XEXP (rtl, 1)))
11223 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
11226 dw_loc_descr_ref mem_loc_result2
11227 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11228 VAR_INIT_STATUS_INITIALIZED);
11229 if (mem_loc_result2 == 0)
11231 add_loc_descr (&mem_loc_result, mem_loc_result2);
11232 add_loc_descr (&mem_loc_result,
11233 new_loc_descr (DW_OP_plus, 0, 0));
11238 /* If a pseudo-reg is optimized away, it is possible for it to
11239 be replaced with a MEM containing a multiply or shift. */
11281 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11282 VAR_INIT_STATUS_INITIALIZED);
11283 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11284 VAR_INIT_STATUS_INITIALIZED);
11286 if (op0 == 0 || op1 == 0)
11289 mem_loc_result = op0;
11290 add_loc_descr (&mem_loc_result, op1);
11291 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11307 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11308 VAR_INIT_STATUS_INITIALIZED);
11313 mem_loc_result = op0;
11314 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11318 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
11322 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
11323 VAR_INIT_STATUS_INITIALIZED);
11351 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11352 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11353 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11356 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11357 VAR_INIT_STATUS_INITIALIZED);
11358 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11359 VAR_INIT_STATUS_INITIALIZED);
11361 if (op0 == 0 || op1 == 0)
11364 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11366 int shift = DWARF2_ADDR_SIZE
11367 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11368 shift *= BITS_PER_UNIT;
11369 add_loc_descr (&op0, int_loc_descriptor (shift));
11370 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11371 if (CONST_INT_P (XEXP (rtl, 1)))
11372 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
11375 add_loc_descr (&op1, int_loc_descriptor (shift));
11376 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11381 mem_loc_result = op0;
11382 add_loc_descr (&mem_loc_result, op1);
11383 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11384 if (STORE_FLAG_VALUE != 1)
11386 add_loc_descr (&mem_loc_result,
11387 int_loc_descriptor (STORE_FLAG_VALUE));
11388 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
11409 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11410 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11411 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11414 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11415 VAR_INIT_STATUS_INITIALIZED);
11416 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11417 VAR_INIT_STATUS_INITIALIZED);
11419 if (op0 == 0 || op1 == 0)
11422 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11424 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11425 add_loc_descr (&op0, int_loc_descriptor (mask));
11426 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11427 if (CONST_INT_P (XEXP (rtl, 1)))
11428 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
11431 add_loc_descr (&op1, int_loc_descriptor (mask));
11432 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11437 HOST_WIDE_INT bias = 1;
11438 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11439 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11440 if (CONST_INT_P (XEXP (rtl, 1)))
11441 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
11442 + INTVAL (XEXP (rtl, 1)));
11444 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11452 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
11453 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
11454 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
11457 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11458 VAR_INIT_STATUS_INITIALIZED);
11459 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
11460 VAR_INIT_STATUS_INITIALIZED);
11462 if (op0 == 0 || op1 == 0)
11465 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
11466 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
11467 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
11468 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
11470 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11472 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
11473 add_loc_descr (&op0, int_loc_descriptor (mask));
11474 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
11475 add_loc_descr (&op1, int_loc_descriptor (mask));
11476 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
11480 HOST_WIDE_INT bias = 1;
11481 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
11482 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11483 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
11486 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
11488 int shift = DWARF2_ADDR_SIZE
11489 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
11490 shift *= BITS_PER_UNIT;
11491 add_loc_descr (&op0, int_loc_descriptor (shift));
11492 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
11493 add_loc_descr (&op1, int_loc_descriptor (shift));
11494 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
11497 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
11501 mem_loc_result = op0;
11502 add_loc_descr (&mem_loc_result, op1);
11503 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11505 dw_loc_descr_ref bra_node, drop_node;
11507 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
11508 add_loc_descr (&mem_loc_result, bra_node);
11509 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
11510 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
11511 add_loc_descr (&mem_loc_result, drop_node);
11512 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11513 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
11519 if (CONST_INT_P (XEXP (rtl, 1))
11520 && CONST_INT_P (XEXP (rtl, 2))
11521 && ((unsigned) INTVAL (XEXP (rtl, 1))
11522 + (unsigned) INTVAL (XEXP (rtl, 2))
11523 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
11524 && GET_MODE_BITSIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
11525 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
11528 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
11529 VAR_INIT_STATUS_INITIALIZED);
11532 if (GET_CODE (rtl) == SIGN_EXTRACT)
11536 mem_loc_result = op0;
11537 size = INTVAL (XEXP (rtl, 1));
11538 shift = INTVAL (XEXP (rtl, 2));
11539 if (BITS_BIG_ENDIAN)
11540 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
11542 add_loc_descr (&mem_loc_result,
11543 int_loc_descriptor (DWARF2_ADDR_SIZE - shift - size));
11544 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
11545 add_loc_descr (&mem_loc_result,
11546 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
11547 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
11556 /* In theory, we could implement the above. */
11557 /* DWARF cannot represent the unsigned compare operations
11573 case FLOAT_TRUNCATE:
11575 case UNSIGNED_FLOAT:
11578 case FRACT_CONVERT:
11579 case UNSIGNED_FRACT_CONVERT:
11581 case UNSIGNED_SAT_FRACT:
11591 /* If delegitimize_address couldn't do anything with the UNSPEC, we
11592 can't express it in the debug info. This can happen e.g. with some
11597 rtl = get_debug_string_label (XSTR (rtl, 0));
11601 #ifdef ENABLE_CHECKING
11602 print_rtl (stderr, rtl);
11603 gcc_unreachable ();
11609 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11610 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11612 return mem_loc_result;
11615 /* Return a descriptor that describes the concatenation of two locations.
11616 This is typically a complex variable. */
11618 static dw_loc_descr_ref
11619 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
11621 dw_loc_descr_ref cc_loc_result = NULL;
11622 dw_loc_descr_ref x0_ref
11623 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11624 dw_loc_descr_ref x1_ref
11625 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11627 if (x0_ref == 0 || x1_ref == 0)
11630 cc_loc_result = x0_ref;
11631 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
11633 add_loc_descr (&cc_loc_result, x1_ref);
11634 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
11636 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
11637 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11639 return cc_loc_result;
11642 /* Return a descriptor that describes the concatenation of N
11645 static dw_loc_descr_ref
11646 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
11649 dw_loc_descr_ref cc_loc_result = NULL;
11650 unsigned int n = XVECLEN (concatn, 0);
11652 for (i = 0; i < n; ++i)
11654 dw_loc_descr_ref ref;
11655 rtx x = XVECEXP (concatn, 0, i);
11657 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
11661 add_loc_descr (&cc_loc_result, ref);
11662 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
11665 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
11666 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
11668 return cc_loc_result;
11671 /* Output a proper Dwarf location descriptor for a variable or parameter
11672 which is either allocated in a register or in a memory location. For a
11673 register, we just generate an OP_REG and the register number. For a
11674 memory location we provide a Dwarf postfix expression describing how to
11675 generate the (dynamic) address of the object onto the address stack.
11677 MODE is mode of the decl if this loc_descriptor is going to be used in
11678 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
11679 allowed, VOIDmode otherwise.
11681 If we don't know how to describe it, return 0. */
11683 static dw_loc_descr_ref
11684 loc_descriptor (rtx rtl, enum machine_mode mode,
11685 enum var_init_status initialized)
11687 dw_loc_descr_ref loc_result = NULL;
11689 switch (GET_CODE (rtl))
11692 /* The case of a subreg may arise when we have a local (register)
11693 variable or a formal (register) parameter which doesn't quite fill
11694 up an entire register. For now, just assume that it is
11695 legitimate to make the Dwarf info refer to the whole register which
11696 contains the given subreg. */
11697 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
11701 loc_result = reg_loc_descriptor (rtl, initialized);
11706 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11710 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
11712 if (loc_result == NULL)
11713 loc_result = tls_mem_loc_descriptor (rtl);
11717 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
11722 loc_result = concatn_loc_descriptor (rtl, initialized);
11727 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
11729 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), mode,
11734 rtl = XEXP (rtl, 1);
11739 rtvec par_elems = XVEC (rtl, 0);
11740 int num_elem = GET_NUM_ELEM (par_elems);
11741 enum machine_mode mode;
11744 /* Create the first one, so we have something to add to. */
11745 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
11746 VOIDmode, initialized);
11747 if (loc_result == NULL)
11749 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
11750 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11751 for (i = 1; i < num_elem; i++)
11753 dw_loc_descr_ref temp;
11755 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
11756 VOIDmode, initialized);
11759 add_loc_descr (&loc_result, temp);
11760 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
11761 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11767 if (mode != VOIDmode && mode != BLKmode && dwarf_version >= 4)
11769 HOST_WIDE_INT i = INTVAL (rtl);
11775 else if (i <= 0xff)
11777 else if (i <= 0xffff)
11779 else if (HOST_BITS_PER_WIDE_INT == 32
11780 || i <= 0xffffffff)
11783 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
11789 else if (i >= -0x8000)
11791 else if (HOST_BITS_PER_WIDE_INT == 32
11792 || i >= -0x80000000)
11795 litsize = 1 + size_of_sleb128 (i);
11797 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11798 is more compact. For DW_OP_stack_value we need:
11799 litsize + 1 (DW_OP_stack_value) + 1 (DW_OP_bit_size)
11801 and for DW_OP_implicit_value:
11802 1 (DW_OP_implicit_value) + 1 (length) + mode_size. */
11803 if (DWARF2_ADDR_SIZE >= GET_MODE_SIZE (mode)
11804 && litsize + 1 + 1 + 1 < 1 + 1 + GET_MODE_SIZE (mode))
11806 loc_result = int_loc_descriptor (i);
11807 add_loc_descr (&loc_result,
11808 new_loc_descr (DW_OP_stack_value, 0, 0));
11809 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11813 loc_result = new_loc_descr (DW_OP_implicit_value,
11814 GET_MODE_SIZE (mode), 0);
11815 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
11816 loc_result->dw_loc_oprnd2.v.val_int = i;
11821 if (mode != VOIDmode && dwarf_version >= 4)
11823 /* Note that a CONST_DOUBLE rtx could represent either an integer
11824 or a floating-point constant. A CONST_DOUBLE is used whenever
11825 the constant requires more than one word in order to be
11826 adequately represented. We output CONST_DOUBLEs as blocks. */
11827 if (GET_MODE (rtl) != VOIDmode)
11828 mode = GET_MODE (rtl);
11830 loc_result = new_loc_descr (DW_OP_implicit_value,
11831 GET_MODE_SIZE (mode), 0);
11832 if (SCALAR_FLOAT_MODE_P (mode))
11834 unsigned int length = GET_MODE_SIZE (mode);
11835 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11837 insert_float (rtl, array);
11838 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11839 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
11840 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
11841 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11845 loc_result->dw_loc_oprnd2.val_class = dw_val_class_long_long;
11846 loc_result->dw_loc_oprnd2.v.val_long_long = rtl;
11852 if (mode != VOIDmode && dwarf_version >= 4)
11854 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
11855 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11856 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11860 mode = GET_MODE (rtl);
11861 switch (GET_MODE_CLASS (mode))
11863 case MODE_VECTOR_INT:
11864 for (i = 0, p = array; i < length; i++, p += elt_size)
11866 rtx elt = CONST_VECTOR_ELT (rtl, i);
11867 HOST_WIDE_INT lo, hi;
11869 switch (GET_CODE (elt))
11877 lo = CONST_DOUBLE_LOW (elt);
11878 hi = CONST_DOUBLE_HIGH (elt);
11882 gcc_unreachable ();
11885 if (elt_size <= sizeof (HOST_WIDE_INT))
11886 insert_int (lo, elt_size, p);
11889 unsigned char *p0 = p;
11890 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11892 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11893 if (WORDS_BIG_ENDIAN)
11898 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11899 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11904 case MODE_VECTOR_FLOAT:
11905 for (i = 0, p = array; i < length; i++, p += elt_size)
11907 rtx elt = CONST_VECTOR_ELT (rtl, i);
11908 insert_float (elt, p);
11913 gcc_unreachable ();
11916 loc_result = new_loc_descr (DW_OP_implicit_value,
11917 length * elt_size, 0);
11918 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
11919 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
11920 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
11921 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
11926 if (mode == VOIDmode
11927 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
11928 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
11929 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
11931 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
11936 if (GET_CODE (rtl) == SYMBOL_REF
11937 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
11940 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
11941 && dwarf_version >= 4)
11943 loc_result = new_loc_descr (DW_OP_implicit_value,
11944 DWARF2_ADDR_SIZE, 0);
11945 loc_result->dw_loc_oprnd2.val_class = dw_val_class_addr;
11946 loc_result->dw_loc_oprnd2.v.val_addr = rtl;
11947 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11952 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
11953 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
11954 && dwarf_version >= 4)
11956 /* Value expression. */
11957 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
11960 add_loc_descr (&loc_result,
11961 new_loc_descr (DW_OP_stack_value, 0, 0));
11962 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
11971 /* Similar, but generate the descriptor from trees instead of rtl. This comes
11972 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
11973 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
11974 top-level invocation, and we require the address of LOC; is 0 if we require
11975 the value of LOC. */
11977 static dw_loc_descr_ref
11978 loc_descriptor_from_tree_1 (tree loc, int want_address)
11980 dw_loc_descr_ref ret, ret1;
11981 int have_address = 0;
11982 enum dwarf_location_atom op;
11984 /* ??? Most of the time we do not take proper care for sign/zero
11985 extending the values properly. Hopefully this won't be a real
11988 switch (TREE_CODE (loc))
11993 case PLACEHOLDER_EXPR:
11994 /* This case involves extracting fields from an object to determine the
11995 position of other fields. We don't try to encode this here. The
11996 only user of this is Ada, which encodes the needed information using
11997 the names of types. */
12003 case PREINCREMENT_EXPR:
12004 case PREDECREMENT_EXPR:
12005 case POSTINCREMENT_EXPR:
12006 case POSTDECREMENT_EXPR:
12007 /* There are no opcodes for these operations. */
12011 /* If we already want an address, there's nothing we can do. */
12015 /* Otherwise, process the argument and look for the address. */
12016 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
12019 if (DECL_THREAD_LOCAL_P (loc))
12022 enum dwarf_location_atom first_op;
12023 enum dwarf_location_atom second_op;
12024 bool dtprel = false;
12026 if (targetm.have_tls)
12028 /* If this is not defined, we have no way to emit the
12030 if (!targetm.asm_out.output_dwarf_dtprel)
12033 /* The way DW_OP_GNU_push_tls_address is specified, we
12034 can only look up addresses of objects in the current
12036 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
12038 first_op = DW_OP_addr;
12040 second_op = DW_OP_GNU_push_tls_address;
12044 if (!targetm.emutls.debug_form_tls_address)
12046 loc = emutls_decl (loc);
12047 first_op = DW_OP_addr;
12048 second_op = DW_OP_form_tls_address;
12051 rtl = rtl_for_decl_location (loc);
12052 if (rtl == NULL_RTX)
12057 rtl = XEXP (rtl, 0);
12058 if (! CONSTANT_P (rtl))
12061 ret = new_loc_descr (first_op, 0, 0);
12062 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12063 ret->dw_loc_oprnd1.v.val_addr = rtl;
12064 ret->dtprel = dtprel;
12066 ret1 = new_loc_descr (second_op, 0, 0);
12067 add_loc_descr (&ret, ret1);
12075 if (DECL_HAS_VALUE_EXPR_P (loc))
12076 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
12081 case FUNCTION_DECL:
12083 rtx rtl = rtl_for_decl_location (loc);
12085 if (rtl == NULL_RTX)
12087 else if (CONST_INT_P (rtl))
12089 HOST_WIDE_INT val = INTVAL (rtl);
12090 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
12091 val &= GET_MODE_MASK (DECL_MODE (loc));
12092 ret = int_loc_descriptor (val);
12094 else if (GET_CODE (rtl) == CONST_STRING)
12096 else if (CONSTANT_P (rtl))
12098 ret = new_loc_descr (DW_OP_addr, 0, 0);
12099 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
12100 ret->dw_loc_oprnd1.v.val_addr = rtl;
12104 enum machine_mode mode;
12106 /* Certain constructs can only be represented at top-level. */
12107 if (want_address == 2)
12108 return loc_descriptor (rtl, VOIDmode,
12109 VAR_INIT_STATUS_INITIALIZED);
12111 mode = GET_MODE (rtl);
12114 rtl = XEXP (rtl, 0);
12117 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12123 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12127 case COMPOUND_EXPR:
12128 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
12131 case VIEW_CONVERT_EXPR:
12134 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
12136 case COMPONENT_REF:
12137 case BIT_FIELD_REF:
12139 case ARRAY_RANGE_REF:
12142 HOST_WIDE_INT bitsize, bitpos, bytepos;
12143 enum machine_mode mode;
12145 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
12147 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
12148 &unsignedp, &volatilep, false);
12153 ret = loc_descriptor_from_tree_1 (obj, 1);
12155 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
12158 if (offset != NULL_TREE)
12160 /* Variable offset. */
12161 ret1 = loc_descriptor_from_tree_1 (offset, 0);
12164 add_loc_descr (&ret, ret1);
12165 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
12168 bytepos = bitpos / BITS_PER_UNIT;
12169 loc_descr_plus_const (&ret, bytepos);
12176 if (host_integerp (loc, 0))
12177 ret = int_loc_descriptor (tree_low_cst (loc, 0));
12184 /* Get an RTL for this, if something has been emitted. */
12185 rtx rtl = lookup_constant_def (loc);
12186 enum machine_mode mode;
12188 if (!rtl || !MEM_P (rtl))
12190 mode = GET_MODE (rtl);
12191 rtl = XEXP (rtl, 0);
12192 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
12197 case TRUTH_AND_EXPR:
12198 case TRUTH_ANDIF_EXPR:
12203 case TRUTH_XOR_EXPR:
12208 case TRUTH_OR_EXPR:
12209 case TRUTH_ORIF_EXPR:
12214 case FLOOR_DIV_EXPR:
12215 case CEIL_DIV_EXPR:
12216 case ROUND_DIV_EXPR:
12217 case TRUNC_DIV_EXPR:
12225 case FLOOR_MOD_EXPR:
12226 case CEIL_MOD_EXPR:
12227 case ROUND_MOD_EXPR:
12228 case TRUNC_MOD_EXPR:
12241 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
12244 case POINTER_PLUS_EXPR:
12246 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
12247 && host_integerp (TREE_OPERAND (loc, 1), 0))
12249 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12253 loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
12261 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12268 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12275 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12282 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
12297 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12298 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
12299 if (ret == 0 || ret1 == 0)
12302 add_loc_descr (&ret, ret1);
12303 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12306 case TRUTH_NOT_EXPR:
12320 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12324 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
12330 const enum tree_code code =
12331 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
12333 loc = build3 (COND_EXPR, TREE_TYPE (loc),
12334 build2 (code, integer_type_node,
12335 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
12336 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
12339 /* ... fall through ... */
12343 dw_loc_descr_ref lhs
12344 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
12345 dw_loc_descr_ref rhs
12346 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
12347 dw_loc_descr_ref bra_node, jump_node, tmp;
12349 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
12350 if (ret == 0 || lhs == 0 || rhs == 0)
12353 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
12354 add_loc_descr (&ret, bra_node);
12356 add_loc_descr (&ret, rhs);
12357 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
12358 add_loc_descr (&ret, jump_node);
12360 add_loc_descr (&ret, lhs);
12361 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12362 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
12364 /* ??? Need a node to point the skip at. Use a nop. */
12365 tmp = new_loc_descr (DW_OP_nop, 0, 0);
12366 add_loc_descr (&ret, tmp);
12367 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
12368 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
12372 case FIX_TRUNC_EXPR:
12376 /* Leave front-end specific codes as simply unknown. This comes
12377 up, for instance, with the C STMT_EXPR. */
12378 if ((unsigned int) TREE_CODE (loc)
12379 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
12382 #ifdef ENABLE_CHECKING
12383 /* Otherwise this is a generic code; we should just lists all of
12384 these explicitly. We forgot one. */
12385 gcc_unreachable ();
12387 /* In a release build, we want to degrade gracefully: better to
12388 generate incomplete debugging information than to crash. */
12393 /* Show if we can't fill the request for an address. */
12394 if (want_address && !have_address)
12397 /* If we've got an address and don't want one, dereference. */
12398 if (!want_address && have_address && ret)
12400 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
12402 if (size > DWARF2_ADDR_SIZE || size == -1)
12404 else if (size == DWARF2_ADDR_SIZE)
12407 op = DW_OP_deref_size;
12409 add_loc_descr (&ret, new_loc_descr (op, size, 0));
12415 static inline dw_loc_descr_ref
12416 loc_descriptor_from_tree (tree loc)
12418 return loc_descriptor_from_tree_1 (loc, 2);
12421 /* Given a value, round it up to the lowest multiple of `boundary'
12422 which is not less than the value itself. */
12424 static inline HOST_WIDE_INT
12425 ceiling (HOST_WIDE_INT value, unsigned int boundary)
12427 return (((value + boundary - 1) / boundary) * boundary);
12430 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
12431 pointer to the declared type for the relevant field variable, or return
12432 `integer_type_node' if the given node turns out to be an
12433 ERROR_MARK node. */
12436 field_type (const_tree decl)
12440 if (TREE_CODE (decl) == ERROR_MARK)
12441 return integer_type_node;
12443 type = DECL_BIT_FIELD_TYPE (decl);
12444 if (type == NULL_TREE)
12445 type = TREE_TYPE (decl);
12450 /* Given a pointer to a tree node, return the alignment in bits for
12451 it, or else return BITS_PER_WORD if the node actually turns out to
12452 be an ERROR_MARK node. */
12454 static inline unsigned
12455 simple_type_align_in_bits (const_tree type)
12457 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
12460 static inline unsigned
12461 simple_decl_align_in_bits (const_tree decl)
12463 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
12466 /* Return the result of rounding T up to ALIGN. */
12468 static inline HOST_WIDE_INT
12469 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
12471 /* We must be careful if T is negative because HOST_WIDE_INT can be
12472 either "above" or "below" unsigned int as per the C promotion
12473 rules, depending on the host, thus making the signedness of the
12474 direct multiplication and division unpredictable. */
12475 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
12481 return (HOST_WIDE_INT) u;
12484 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
12485 lowest addressed byte of the "containing object" for the given FIELD_DECL,
12486 or return 0 if we are unable to determine what that offset is, either
12487 because the argument turns out to be a pointer to an ERROR_MARK node, or
12488 because the offset is actually variable. (We can't handle the latter case
12491 static HOST_WIDE_INT
12492 field_byte_offset (const_tree decl)
12494 HOST_WIDE_INT object_offset_in_bits;
12495 HOST_WIDE_INT bitpos_int;
12497 if (TREE_CODE (decl) == ERROR_MARK)
12500 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
12502 /* We cannot yet cope with fields whose positions are variable, so
12503 for now, when we see such things, we simply return 0. Someday, we may
12504 be able to handle such cases, but it will be damn difficult. */
12505 if (! host_integerp (bit_position (decl), 0))
12508 bitpos_int = int_bit_position (decl);
12510 #ifdef PCC_BITFIELD_TYPE_MATTERS
12511 if (PCC_BITFIELD_TYPE_MATTERS)
12514 tree field_size_tree;
12515 HOST_WIDE_INT deepest_bitpos;
12516 unsigned HOST_WIDE_INT field_size_in_bits;
12517 unsigned int type_align_in_bits;
12518 unsigned int decl_align_in_bits;
12519 unsigned HOST_WIDE_INT type_size_in_bits;
12521 type = field_type (decl);
12522 type_size_in_bits = simple_type_size_in_bits (type);
12523 type_align_in_bits = simple_type_align_in_bits (type);
12525 field_size_tree = DECL_SIZE (decl);
12527 /* The size could be unspecified if there was an error, or for
12528 a flexible array member. */
12529 if (!field_size_tree)
12530 field_size_tree = bitsize_zero_node;
12532 /* If the size of the field is not constant, use the type size. */
12533 if (host_integerp (field_size_tree, 1))
12534 field_size_in_bits = tree_low_cst (field_size_tree, 1);
12536 field_size_in_bits = type_size_in_bits;
12538 decl_align_in_bits = simple_decl_align_in_bits (decl);
12540 /* The GCC front-end doesn't make any attempt to keep track of the
12541 starting bit offset (relative to the start of the containing
12542 structure type) of the hypothetical "containing object" for a
12543 bit-field. Thus, when computing the byte offset value for the
12544 start of the "containing object" of a bit-field, we must deduce
12545 this information on our own. This can be rather tricky to do in
12546 some cases. For example, handling the following structure type
12547 definition when compiling for an i386/i486 target (which only
12548 aligns long long's to 32-bit boundaries) can be very tricky:
12550 struct S { int field1; long long field2:31; };
12552 Fortunately, there is a simple rule-of-thumb which can be used
12553 in such cases. When compiling for an i386/i486, GCC will
12554 allocate 8 bytes for the structure shown above. It decides to
12555 do this based upon one simple rule for bit-field allocation.
12556 GCC allocates each "containing object" for each bit-field at
12557 the first (i.e. lowest addressed) legitimate alignment boundary
12558 (based upon the required minimum alignment for the declared
12559 type of the field) which it can possibly use, subject to the
12560 condition that there is still enough available space remaining
12561 in the containing object (when allocated at the selected point)
12562 to fully accommodate all of the bits of the bit-field itself.
12564 This simple rule makes it obvious why GCC allocates 8 bytes for
12565 each object of the structure type shown above. When looking
12566 for a place to allocate the "containing object" for `field2',
12567 the compiler simply tries to allocate a 64-bit "containing
12568 object" at each successive 32-bit boundary (starting at zero)
12569 until it finds a place to allocate that 64- bit field such that
12570 at least 31 contiguous (and previously unallocated) bits remain
12571 within that selected 64 bit field. (As it turns out, for the
12572 example above, the compiler finds it is OK to allocate the
12573 "containing object" 64-bit field at bit-offset zero within the
12576 Here we attempt to work backwards from the limited set of facts
12577 we're given, and we try to deduce from those facts, where GCC
12578 must have believed that the containing object started (within
12579 the structure type). The value we deduce is then used (by the
12580 callers of this routine) to generate DW_AT_location and
12581 DW_AT_bit_offset attributes for fields (both bit-fields and, in
12582 the case of DW_AT_location, regular fields as well). */
12584 /* Figure out the bit-distance from the start of the structure to
12585 the "deepest" bit of the bit-field. */
12586 deepest_bitpos = bitpos_int + field_size_in_bits;
12588 /* This is the tricky part. Use some fancy footwork to deduce
12589 where the lowest addressed bit of the containing object must
12591 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
12593 /* Round up to type_align by default. This works best for
12595 object_offset_in_bits
12596 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
12598 if (object_offset_in_bits > bitpos_int)
12600 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
12602 /* Round up to decl_align instead. */
12603 object_offset_in_bits
12604 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
12609 object_offset_in_bits = bitpos_int;
12611 return object_offset_in_bits / BITS_PER_UNIT;
12614 /* The following routines define various Dwarf attributes and any data
12615 associated with them. */
12617 /* Add a location description attribute value to a DIE.
12619 This emits location attributes suitable for whole variables and
12620 whole parameters. Note that the location attributes for struct fields are
12621 generated by the routine `data_member_location_attribute' below. */
12624 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
12625 dw_loc_descr_ref descr)
12628 add_AT_loc (die, attr_kind, descr);
12631 /* Attach the specialized form of location attribute used for data members of
12632 struct and union types. In the special case of a FIELD_DECL node which
12633 represents a bit-field, the "offset" part of this special location
12634 descriptor must indicate the distance in bytes from the lowest-addressed
12635 byte of the containing struct or union type to the lowest-addressed byte of
12636 the "containing object" for the bit-field. (See the `field_byte_offset'
12639 For any given bit-field, the "containing object" is a hypothetical object
12640 (of some integral or enum type) within which the given bit-field lives. The
12641 type of this hypothetical "containing object" is always the same as the
12642 declared type of the individual bit-field itself (for GCC anyway... the
12643 DWARF spec doesn't actually mandate this). Note that it is the size (in
12644 bytes) of the hypothetical "containing object" which will be given in the
12645 DW_AT_byte_size attribute for this bit-field. (See the
12646 `byte_size_attribute' function below.) It is also used when calculating the
12647 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
12648 function below.) */
12651 add_data_member_location_attribute (dw_die_ref die, tree decl)
12653 HOST_WIDE_INT offset;
12654 dw_loc_descr_ref loc_descr = 0;
12656 if (TREE_CODE (decl) == TREE_BINFO)
12658 /* We're working on the TAG_inheritance for a base class. */
12659 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
12661 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
12662 aren't at a fixed offset from all (sub)objects of the same
12663 type. We need to extract the appropriate offset from our
12664 vtable. The following dwarf expression means
12666 BaseAddr = ObAddr + *((*ObAddr) - Offset)
12668 This is specific to the V3 ABI, of course. */
12670 dw_loc_descr_ref tmp;
12672 /* Make a copy of the object address. */
12673 tmp = new_loc_descr (DW_OP_dup, 0, 0);
12674 add_loc_descr (&loc_descr, tmp);
12676 /* Extract the vtable address. */
12677 tmp = new_loc_descr (DW_OP_deref, 0, 0);
12678 add_loc_descr (&loc_descr, tmp);
12680 /* Calculate the address of the offset. */
12681 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
12682 gcc_assert (offset < 0);
12684 tmp = int_loc_descriptor (-offset);
12685 add_loc_descr (&loc_descr, tmp);
12686 tmp = new_loc_descr (DW_OP_minus, 0, 0);
12687 add_loc_descr (&loc_descr, tmp);
12689 /* Extract the offset. */
12690 tmp = new_loc_descr (DW_OP_deref, 0, 0);
12691 add_loc_descr (&loc_descr, tmp);
12693 /* Add it to the object address. */
12694 tmp = new_loc_descr (DW_OP_plus, 0, 0);
12695 add_loc_descr (&loc_descr, tmp);
12698 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
12701 offset = field_byte_offset (decl);
12705 if (dwarf_version > 2)
12707 /* Don't need to output a location expression, just the constant. */
12708 add_AT_int (die, DW_AT_data_member_location, offset);
12713 enum dwarf_location_atom op;
12715 /* The DWARF2 standard says that we should assume that the structure
12716 address is already on the stack, so we can specify a structure
12717 field address by using DW_OP_plus_uconst. */
12719 #ifdef MIPS_DEBUGGING_INFO
12720 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
12721 operator correctly. It works only if we leave the offset on the
12725 op = DW_OP_plus_uconst;
12728 loc_descr = new_loc_descr (op, offset, 0);
12732 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
12735 /* Writes integer values to dw_vec_const array. */
12738 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
12742 *dest++ = val & 0xff;
12748 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
12750 static HOST_WIDE_INT
12751 extract_int (const unsigned char *src, unsigned int size)
12753 HOST_WIDE_INT val = 0;
12759 val |= *--src & 0xff;
12765 /* Writes floating point values to dw_vec_const array. */
12768 insert_float (const_rtx rtl, unsigned char *array)
12770 REAL_VALUE_TYPE rv;
12774 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
12775 real_to_target (val, &rv, GET_MODE (rtl));
12777 /* real_to_target puts 32-bit pieces in each long. Pack them. */
12778 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
12780 insert_int (val[i], 4, array);
12785 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
12786 does not have a "location" either in memory or in a register. These
12787 things can arise in GNU C when a constant is passed as an actual parameter
12788 to an inlined function. They can also arise in C++ where declared
12789 constants do not necessarily get memory "homes". */
12792 add_const_value_attribute (dw_die_ref die, rtx rtl)
12794 switch (GET_CODE (rtl))
12798 HOST_WIDE_INT val = INTVAL (rtl);
12801 add_AT_int (die, DW_AT_const_value, val);
12803 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
12808 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
12809 floating-point constant. A CONST_DOUBLE is used whenever the
12810 constant requires more than one word in order to be adequately
12811 represented. We output CONST_DOUBLEs as blocks. */
12813 enum machine_mode mode = GET_MODE (rtl);
12815 if (SCALAR_FLOAT_MODE_P (mode))
12817 unsigned int length = GET_MODE_SIZE (mode);
12818 unsigned char *array = GGC_NEWVEC (unsigned char, length);
12820 insert_float (rtl, array);
12821 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
12824 add_AT_long_long (die, DW_AT_const_value, rtl);
12830 enum machine_mode mode = GET_MODE (rtl);
12831 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
12832 unsigned int length = CONST_VECTOR_NUNITS (rtl);
12833 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
12837 switch (GET_MODE_CLASS (mode))
12839 case MODE_VECTOR_INT:
12840 for (i = 0, p = array; i < length; i++, p += elt_size)
12842 rtx elt = CONST_VECTOR_ELT (rtl, i);
12843 HOST_WIDE_INT lo, hi;
12845 switch (GET_CODE (elt))
12853 lo = CONST_DOUBLE_LOW (elt);
12854 hi = CONST_DOUBLE_HIGH (elt);
12858 gcc_unreachable ();
12861 if (elt_size <= sizeof (HOST_WIDE_INT))
12862 insert_int (lo, elt_size, p);
12865 unsigned char *p0 = p;
12866 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
12868 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
12869 if (WORDS_BIG_ENDIAN)
12874 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
12875 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
12880 case MODE_VECTOR_FLOAT:
12881 for (i = 0, p = array; i < length; i++, p += elt_size)
12883 rtx elt = CONST_VECTOR_ELT (rtl, i);
12884 insert_float (elt, p);
12889 gcc_unreachable ();
12892 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
12897 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
12901 if (CONSTANT_P (XEXP (rtl, 0)))
12903 add_const_value_attribute (die, XEXP (rtl, 0));
12908 if (GET_CODE (rtl) == SYMBOL_REF
12909 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
12912 add_AT_addr (die, DW_AT_const_value, rtl);
12913 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
12917 /* In cases where an inlined instance of an inline function is passed
12918 the address of an `auto' variable (which is local to the caller) we
12919 can get a situation where the DECL_RTL of the artificial local
12920 variable (for the inlining) which acts as a stand-in for the
12921 corresponding formal parameter (of the inline function) will look
12922 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
12923 exactly a compile-time constant expression, but it isn't the address
12924 of the (artificial) local variable either. Rather, it represents the
12925 *value* which the artificial local variable always has during its
12926 lifetime. We currently have no way to represent such quasi-constant
12927 values in Dwarf, so for now we just punt and generate nothing. */
12931 /* No other kinds of rtx should be possible here. */
12932 gcc_unreachable ();
12937 /* Determine whether the evaluation of EXPR references any variables
12938 or functions which aren't otherwise used (and therefore may not be
12941 reference_to_unused (tree * tp, int * walk_subtrees,
12942 void * data ATTRIBUTE_UNUSED)
12944 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
12945 *walk_subtrees = 0;
12947 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
12948 && ! TREE_ASM_WRITTEN (*tp))
12950 /* ??? The C++ FE emits debug information for using decls, so
12951 putting gcc_unreachable here falls over. See PR31899. For now
12952 be conservative. */
12953 else if (!cgraph_global_info_ready
12954 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
12956 else if (TREE_CODE (*tp) == VAR_DECL)
12958 struct varpool_node *node = varpool_node (*tp);
12962 else if (TREE_CODE (*tp) == FUNCTION_DECL
12963 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
12965 /* The call graph machinery must have finished analyzing,
12966 optimizing and gimplifying the CU by now.
12967 So if *TP has no call graph node associated
12968 to it, it means *TP will not be emitted. */
12969 if (!cgraph_get_node (*tp))
12972 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
12978 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
12979 for use in a later add_const_value_attribute call. */
12982 rtl_for_decl_init (tree init, tree type)
12984 rtx rtl = NULL_RTX;
12986 /* If a variable is initialized with a string constant without embedded
12987 zeros, build CONST_STRING. */
12988 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
12990 tree enttype = TREE_TYPE (type);
12991 tree domain = TYPE_DOMAIN (type);
12992 enum machine_mode mode = TYPE_MODE (enttype);
12994 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
12996 && integer_zerop (TYPE_MIN_VALUE (domain))
12997 && compare_tree_int (TYPE_MAX_VALUE (domain),
12998 TREE_STRING_LENGTH (init) - 1) == 0
12999 && ((size_t) TREE_STRING_LENGTH (init)
13000 == strlen (TREE_STRING_POINTER (init)) + 1))
13001 rtl = gen_rtx_CONST_STRING (VOIDmode,
13002 ggc_strdup (TREE_STRING_POINTER (init)));
13004 /* Other aggregates, and complex values, could be represented using
13006 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
13008 /* Vectors only work if their mode is supported by the target.
13009 FIXME: generic vectors ought to work too. */
13010 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
13012 /* If the initializer is something that we know will expand into an
13013 immediate RTL constant, expand it now. We must be careful not to
13014 reference variables which won't be output. */
13015 else if (initializer_constant_valid_p (init, type)
13016 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
13018 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
13020 if (TREE_CODE (type) == VECTOR_TYPE)
13021 switch (TREE_CODE (init))
13026 if (TREE_CONSTANT (init))
13028 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
13029 bool constant_p = true;
13031 unsigned HOST_WIDE_INT ix;
13033 /* Even when ctor is constant, it might contain non-*_CST
13034 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
13035 belong into VECTOR_CST nodes. */
13036 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
13037 if (!CONSTANT_CLASS_P (value))
13039 constant_p = false;
13045 init = build_vector_from_ctor (type, elts);
13055 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
13057 /* If expand_expr returns a MEM, it wasn't immediate. */
13058 gcc_assert (!rtl || !MEM_P (rtl));
13064 /* Generate RTL for the variable DECL to represent its location. */
13067 rtl_for_decl_location (tree decl)
13071 /* Here we have to decide where we are going to say the parameter "lives"
13072 (as far as the debugger is concerned). We only have a couple of
13073 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
13075 DECL_RTL normally indicates where the parameter lives during most of the
13076 activation of the function. If optimization is enabled however, this
13077 could be either NULL or else a pseudo-reg. Both of those cases indicate
13078 that the parameter doesn't really live anywhere (as far as the code
13079 generation parts of GCC are concerned) during most of the function's
13080 activation. That will happen (for example) if the parameter is never
13081 referenced within the function.
13083 We could just generate a location descriptor here for all non-NULL
13084 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
13085 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
13086 where DECL_RTL is NULL or is a pseudo-reg.
13088 Note however that we can only get away with using DECL_INCOMING_RTL as
13089 a backup substitute for DECL_RTL in certain limited cases. In cases
13090 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
13091 we can be sure that the parameter was passed using the same type as it is
13092 declared to have within the function, and that its DECL_INCOMING_RTL
13093 points us to a place where a value of that type is passed.
13095 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
13096 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
13097 because in these cases DECL_INCOMING_RTL points us to a value of some
13098 type which is *different* from the type of the parameter itself. Thus,
13099 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
13100 such cases, the debugger would end up (for example) trying to fetch a
13101 `float' from a place which actually contains the first part of a
13102 `double'. That would lead to really incorrect and confusing
13103 output at debug-time.
13105 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
13106 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
13107 are a couple of exceptions however. On little-endian machines we can
13108 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
13109 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
13110 an integral type that is smaller than TREE_TYPE (decl). These cases arise
13111 when (on a little-endian machine) a non-prototyped function has a
13112 parameter declared to be of type `short' or `char'. In such cases,
13113 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
13114 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
13115 passed `int' value. If the debugger then uses that address to fetch
13116 a `short' or a `char' (on a little-endian machine) the result will be
13117 the correct data, so we allow for such exceptional cases below.
13119 Note that our goal here is to describe the place where the given formal
13120 parameter lives during most of the function's activation (i.e. between the
13121 end of the prologue and the start of the epilogue). We'll do that as best
13122 as we can. Note however that if the given formal parameter is modified
13123 sometime during the execution of the function, then a stack backtrace (at
13124 debug-time) will show the function as having been called with the *new*
13125 value rather than the value which was originally passed in. This happens
13126 rarely enough that it is not a major problem, but it *is* a problem, and
13127 I'd like to fix it.
13129 A future version of dwarf2out.c may generate two additional attributes for
13130 any given DW_TAG_formal_parameter DIE which will describe the "passed
13131 type" and the "passed location" for the given formal parameter in addition
13132 to the attributes we now generate to indicate the "declared type" and the
13133 "active location" for each parameter. This additional set of attributes
13134 could be used by debuggers for stack backtraces. Separately, note that
13135 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
13136 This happens (for example) for inlined-instances of inline function formal
13137 parameters which are never referenced. This really shouldn't be
13138 happening. All PARM_DECL nodes should get valid non-NULL
13139 DECL_INCOMING_RTL values. FIXME. */
13141 /* Use DECL_RTL as the "location" unless we find something better. */
13142 rtl = DECL_RTL_IF_SET (decl);
13144 /* When generating abstract instances, ignore everything except
13145 constants, symbols living in memory, and symbols living in
13146 fixed registers. */
13147 if (! reload_completed)
13150 && (CONSTANT_P (rtl)
13152 && CONSTANT_P (XEXP (rtl, 0)))
13154 && TREE_CODE (decl) == VAR_DECL
13155 && TREE_STATIC (decl))))
13157 rtl = targetm.delegitimize_address (rtl);
13162 else if (TREE_CODE (decl) == PARM_DECL)
13164 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
13166 tree declared_type = TREE_TYPE (decl);
13167 tree passed_type = DECL_ARG_TYPE (decl);
13168 enum machine_mode dmode = TYPE_MODE (declared_type);
13169 enum machine_mode pmode = TYPE_MODE (passed_type);
13171 /* This decl represents a formal parameter which was optimized out.
13172 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
13173 all cases where (rtl == NULL_RTX) just below. */
13174 if (dmode == pmode)
13175 rtl = DECL_INCOMING_RTL (decl);
13176 else if (SCALAR_INT_MODE_P (dmode)
13177 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
13178 && DECL_INCOMING_RTL (decl))
13180 rtx inc = DECL_INCOMING_RTL (decl);
13183 else if (MEM_P (inc))
13185 if (BYTES_BIG_ENDIAN)
13186 rtl = adjust_address_nv (inc, dmode,
13187 GET_MODE_SIZE (pmode)
13188 - GET_MODE_SIZE (dmode));
13195 /* If the parm was passed in registers, but lives on the stack, then
13196 make a big endian correction if the mode of the type of the
13197 parameter is not the same as the mode of the rtl. */
13198 /* ??? This is the same series of checks that are made in dbxout.c before
13199 we reach the big endian correction code there. It isn't clear if all
13200 of these checks are necessary here, but keeping them all is the safe
13202 else if (MEM_P (rtl)
13203 && XEXP (rtl, 0) != const0_rtx
13204 && ! CONSTANT_P (XEXP (rtl, 0))
13205 /* Not passed in memory. */
13206 && !MEM_P (DECL_INCOMING_RTL (decl))
13207 /* Not passed by invisible reference. */
13208 && (!REG_P (XEXP (rtl, 0))
13209 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
13210 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
13211 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
13212 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
13215 /* Big endian correction check. */
13216 && BYTES_BIG_ENDIAN
13217 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
13218 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
13221 int offset = (UNITS_PER_WORD
13222 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
13224 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13225 plus_constant (XEXP (rtl, 0), offset));
13228 else if (TREE_CODE (decl) == VAR_DECL
13231 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
13232 && BYTES_BIG_ENDIAN)
13234 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
13235 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
13237 /* If a variable is declared "register" yet is smaller than
13238 a register, then if we store the variable to memory, it
13239 looks like we're storing a register-sized value, when in
13240 fact we are not. We need to adjust the offset of the
13241 storage location to reflect the actual value's bytes,
13242 else gdb will not be able to display it. */
13244 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
13245 plus_constant (XEXP (rtl, 0), rsize-dsize));
13248 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
13249 and will have been substituted directly into all expressions that use it.
13250 C does not have such a concept, but C++ and other languages do. */
13251 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
13252 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
13255 rtl = targetm.delegitimize_address (rtl);
13257 /* If we don't look past the constant pool, we risk emitting a
13258 reference to a constant pool entry that isn't referenced from
13259 code, and thus is not emitted. */
13261 rtl = avoid_constant_pool_reference (rtl);
13266 /* We need to figure out what section we should use as the base for the
13267 address ranges where a given location is valid.
13268 1. If this particular DECL has a section associated with it, use that.
13269 2. If this function has a section associated with it, use that.
13270 3. Otherwise, use the text section.
13271 XXX: If you split a variable across multiple sections, we won't notice. */
13273 static const char *
13274 secname_for_decl (const_tree decl)
13276 const char *secname;
13278 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
13280 tree sectree = DECL_SECTION_NAME (decl);
13281 secname = TREE_STRING_POINTER (sectree);
13283 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
13285 tree sectree = DECL_SECTION_NAME (current_function_decl);
13286 secname = TREE_STRING_POINTER (sectree);
13288 else if (cfun && in_cold_section_p)
13289 secname = crtl->subsections.cold_section_label;
13291 secname = text_section_label;
13296 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
13297 returned. If so, the decl for the COMMON block is returned, and the
13298 value is the offset into the common block for the symbol. */
13301 fortran_common (tree decl, HOST_WIDE_INT *value)
13303 tree val_expr, cvar;
13304 enum machine_mode mode;
13305 HOST_WIDE_INT bitsize, bitpos;
13307 int volatilep = 0, unsignedp = 0;
13309 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
13310 it does not have a value (the offset into the common area), or if it
13311 is thread local (as opposed to global) then it isn't common, and shouldn't
13312 be handled as such. */
13313 if (TREE_CODE (decl) != VAR_DECL
13314 || !TREE_PUBLIC (decl)
13315 || !TREE_STATIC (decl)
13316 || !DECL_HAS_VALUE_EXPR_P (decl)
13320 val_expr = DECL_VALUE_EXPR (decl);
13321 if (TREE_CODE (val_expr) != COMPONENT_REF)
13324 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
13325 &mode, &unsignedp, &volatilep, true);
13327 if (cvar == NULL_TREE
13328 || TREE_CODE (cvar) != VAR_DECL
13329 || DECL_ARTIFICIAL (cvar)
13330 || !TREE_PUBLIC (cvar))
13334 if (offset != NULL)
13336 if (!host_integerp (offset, 0))
13338 *value = tree_low_cst (offset, 0);
13341 *value += bitpos / BITS_PER_UNIT;
13346 /* Dereference a location expression LOC if DECL is passed by invisible
13349 static dw_loc_descr_ref
13350 loc_by_reference (dw_loc_descr_ref loc, tree decl)
13352 HOST_WIDE_INT size;
13353 enum dwarf_location_atom op;
13358 if ((TREE_CODE (decl) != PARM_DECL
13359 && TREE_CODE (decl) != RESULT_DECL
13360 && TREE_CODE (decl) != VAR_DECL)
13361 || !DECL_BY_REFERENCE (decl))
13364 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
13365 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
13366 location expression is considered to be address of a memory location,
13367 rather than the register itself. */
13368 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
13369 || loc->dw_loc_opc == DW_OP_regx)
13370 && (loc->dw_loc_next == NULL
13371 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
13372 && loc->dw_loc_next->dw_loc_next == NULL)))
13374 if (loc->dw_loc_opc == DW_OP_regx)
13376 loc->dw_loc_opc = DW_OP_bregx;
13377 loc->dw_loc_oprnd2.v.val_int = 0;
13382 = (enum dwarf_location_atom)
13383 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
13384 loc->dw_loc_oprnd1.v.val_int = 0;
13389 size = int_size_in_bytes (TREE_TYPE (decl));
13390 if (size > DWARF2_ADDR_SIZE || size == -1)
13392 else if (size == DWARF2_ADDR_SIZE)
13395 op = DW_OP_deref_size;
13396 add_loc_descr (&loc, new_loc_descr (op, size, 0));
13400 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
13401 data attribute for a variable or a parameter. We generate the
13402 DW_AT_const_value attribute only in those cases where the given variable
13403 or parameter does not have a true "location" either in memory or in a
13404 register. This can happen (for example) when a constant is passed as an
13405 actual argument in a call to an inline function. (It's possible that
13406 these things can crop up in other ways also.) Note that one type of
13407 constant value which can be passed into an inlined function is a constant
13408 pointer. This can happen for example if an actual argument in an inlined
13409 function call evaluates to a compile-time constant address. */
13412 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
13413 enum dwarf_attribute attr)
13416 dw_loc_descr_ref descr;
13417 var_loc_list *loc_list;
13418 struct var_loc_node *node;
13419 if (TREE_CODE (decl) == ERROR_MARK)
13422 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
13423 || TREE_CODE (decl) == RESULT_DECL);
13425 /* See if we possibly have multiple locations for this variable. */
13426 loc_list = lookup_decl_loc (decl);
13428 /* If it truly has multiple locations, the first and last node will
13430 if (loc_list && loc_list->first != loc_list->last)
13432 const char *endname, *secname;
13433 dw_loc_list_ref list;
13435 enum var_init_status initialized;
13437 /* Now that we know what section we are using for a base,
13438 actually construct the list of locations.
13439 The first location information is what is passed to the
13440 function that creates the location list, and the remaining
13441 locations just get added on to that list.
13442 Note that we only know the start address for a location
13443 (IE location changes), so to build the range, we use
13444 the range [current location start, next location start].
13445 This means we have to special case the last node, and generate
13446 a range of [last location start, end of function label]. */
13448 node = loc_list->first;
13449 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
13450 secname = secname_for_decl (decl);
13452 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
13453 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13455 initialized = VAR_INIT_STATUS_INITIALIZED;
13457 descr = loc_by_reference (loc_descriptor (varloc, DECL_MODE (decl),
13458 initialized), decl);
13459 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
13462 for (; node->next; node = node->next)
13463 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
13465 /* The variable has a location between NODE->LABEL and
13466 NODE->NEXT->LABEL. */
13467 enum var_init_status initialized =
13468 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13469 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
13470 descr = loc_by_reference (loc_descriptor (varloc, DECL_MODE (decl),
13471 initialized), decl);
13472 add_loc_descr_to_loc_list (&list, descr,
13473 node->label, node->next->label, secname);
13476 /* If the variable has a location at the last label
13477 it keeps its location until the end of function. */
13478 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
13480 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13481 enum var_init_status initialized =
13482 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13484 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
13485 if (!current_function_decl)
13486 endname = text_end_label;
13489 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13490 current_function_funcdef_no);
13491 endname = ggc_strdup (label_id);
13493 descr = loc_by_reference (loc_descriptor (varloc,
13497 add_loc_descr_to_loc_list (&list, descr,
13498 node->label, endname, secname);
13501 /* Finally, add the location list to the DIE, and we are done. */
13502 add_AT_loc_list (die, attr, list);
13506 /* Try to get some constant RTL for this decl, and use that as the value of
13509 rtl = rtl_for_decl_location (decl);
13510 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
13512 add_const_value_attribute (die, rtl);
13516 /* If we have tried to generate the location otherwise, and it
13517 didn't work out (we wouldn't be here if we did), and we have a one entry
13518 location list, try generating a location from that. */
13519 if (loc_list && loc_list->first)
13521 enum var_init_status status;
13522 node = loc_list->first;
13523 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
13524 rtl = NOTE_VAR_LOCATION (node->var_loc_note);
13525 if (GET_CODE (rtl) == VAR_LOCATION
13526 && GET_CODE (XEXP (rtl, 1)) != PARALLEL)
13527 rtl = XEXP (XEXP (rtl, 1), 0);
13528 if (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
13530 add_const_value_attribute (die, rtl);
13533 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note),
13534 DECL_MODE (decl), status);
13537 descr = loc_by_reference (descr, decl);
13538 add_AT_location_description (die, attr, descr);
13543 /* We couldn't get any rtl, so try directly generating the location
13544 description from the tree. */
13545 descr = loc_descriptor_from_tree (decl);
13548 descr = loc_by_reference (descr, decl);
13549 add_AT_location_description (die, attr, descr);
13552 /* None of that worked, so it must not really have a location;
13553 try adding a constant value attribute from the DECL_INITIAL. */
13554 tree_add_const_value_attribute_for_decl (die, decl);
13557 /* Add VARIABLE and DIE into deferred locations list. */
13560 defer_location (tree variable, dw_die_ref die)
13562 deferred_locations entry;
13563 entry.variable = variable;
13565 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
13568 /* Helper function for tree_add_const_value_attribute. Natively encode
13569 initializer INIT into an array. Return true if successful. */
13572 native_encode_initializer (tree init, unsigned char *array, int size)
13576 if (init == NULL_TREE)
13580 switch (TREE_CODE (init))
13583 type = TREE_TYPE (init);
13584 if (TREE_CODE (type) == ARRAY_TYPE)
13586 tree enttype = TREE_TYPE (type);
13587 enum machine_mode mode = TYPE_MODE (enttype);
13589 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
13591 if (int_size_in_bytes (type) != size)
13593 if (size > TREE_STRING_LENGTH (init))
13595 memcpy (array, TREE_STRING_POINTER (init),
13596 TREE_STRING_LENGTH (init));
13597 memset (array + TREE_STRING_LENGTH (init),
13598 '\0', size - TREE_STRING_LENGTH (init));
13601 memcpy (array, TREE_STRING_POINTER (init), size);
13606 type = TREE_TYPE (init);
13607 if (int_size_in_bytes (type) != size)
13609 if (TREE_CODE (type) == ARRAY_TYPE)
13611 HOST_WIDE_INT min_index;
13612 unsigned HOST_WIDE_INT cnt;
13613 int curpos = 0, fieldsize;
13614 constructor_elt *ce;
13616 if (TYPE_DOMAIN (type) == NULL_TREE
13617 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
13620 fieldsize = int_size_in_bytes (TREE_TYPE (type));
13621 if (fieldsize <= 0)
13624 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
13625 memset (array, '\0', size);
13627 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
13630 tree val = ce->value;
13631 tree index = ce->index;
13633 if (index && TREE_CODE (index) == RANGE_EXPR)
13634 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
13637 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
13642 if (!native_encode_initializer (val, array + pos, fieldsize))
13645 curpos = pos + fieldsize;
13646 if (index && TREE_CODE (index) == RANGE_EXPR)
13648 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
13649 - tree_low_cst (TREE_OPERAND (index, 0), 0);
13653 memcpy (array + curpos, array + pos, fieldsize);
13654 curpos += fieldsize;
13657 gcc_assert (curpos <= size);
13661 else if (TREE_CODE (type) == RECORD_TYPE
13662 || TREE_CODE (type) == UNION_TYPE)
13664 tree field = NULL_TREE;
13665 unsigned HOST_WIDE_INT cnt;
13666 constructor_elt *ce;
13668 if (int_size_in_bytes (type) != size)
13671 if (TREE_CODE (type) == RECORD_TYPE)
13672 field = TYPE_FIELDS (type);
13675 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
13676 cnt++, field = field ? TREE_CHAIN (field) : 0)
13678 tree val = ce->value;
13679 int pos, fieldsize;
13681 if (ce->index != 0)
13687 if (field == NULL_TREE || DECL_BIT_FIELD (field))
13690 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
13691 && TYPE_DOMAIN (TREE_TYPE (field))
13692 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
13694 else if (DECL_SIZE_UNIT (field) == NULL_TREE
13695 || !host_integerp (DECL_SIZE_UNIT (field), 0))
13697 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
13698 pos = int_byte_position (field);
13699 gcc_assert (pos + fieldsize <= size);
13701 && !native_encode_initializer (val, array + pos, fieldsize))
13707 case VIEW_CONVERT_EXPR:
13708 case NON_LVALUE_EXPR:
13709 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
13711 return native_encode_expr (init, array, size) == size;
13715 /* Attach a DW_AT_const_value attribute to DIE. The value of the
13716 attribute is the const value T. */
13719 tree_add_const_value_attribute (dw_die_ref die, tree t)
13722 tree type = TREE_TYPE (t);
13725 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
13729 gcc_assert (!DECL_P (init));
13731 rtl = rtl_for_decl_init (init, type);
13733 add_const_value_attribute (die, rtl);
13734 /* If the host and target are sane, try harder. */
13735 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
13736 && initializer_constant_valid_p (init, type))
13738 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
13739 if (size > 0 && (int) size == size)
13741 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
13743 if (native_encode_initializer (init, array, size))
13744 add_AT_vec (die, DW_AT_const_value, size, 1, array);
13749 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
13750 attribute is the const value of T, where T is an integral constant
13751 variable with static storage duration
13752 (so it can't be a PARM_DECL or a RESULT_DECL). */
13755 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
13759 || (TREE_CODE (decl) != VAR_DECL
13760 && TREE_CODE (decl) != CONST_DECL))
13763 if (TREE_READONLY (decl)
13764 && ! TREE_THIS_VOLATILE (decl)
13765 && DECL_INITIAL (decl))
13770 tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
13773 /* Convert the CFI instructions for the current function into a
13774 location list. This is used for DW_AT_frame_base when we targeting
13775 a dwarf2 consumer that does not support the dwarf3
13776 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
13779 static dw_loc_list_ref
13780 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
13783 dw_loc_list_ref list, *list_tail;
13785 dw_cfa_location last_cfa, next_cfa;
13786 const char *start_label, *last_label, *section;
13787 dw_cfa_location remember;
13789 fde = current_fde ();
13790 gcc_assert (fde != NULL);
13792 section = secname_for_decl (current_function_decl);
13796 memset (&next_cfa, 0, sizeof (next_cfa));
13797 next_cfa.reg = INVALID_REGNUM;
13798 remember = next_cfa;
13800 start_label = fde->dw_fde_begin;
13802 /* ??? Bald assumption that the CIE opcode list does not contain
13803 advance opcodes. */
13804 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
13805 lookup_cfa_1 (cfi, &next_cfa, &remember);
13807 last_cfa = next_cfa;
13808 last_label = start_label;
13810 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
13811 switch (cfi->dw_cfi_opc)
13813 case DW_CFA_set_loc:
13814 case DW_CFA_advance_loc1:
13815 case DW_CFA_advance_loc2:
13816 case DW_CFA_advance_loc4:
13817 if (!cfa_equal_p (&last_cfa, &next_cfa))
13819 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
13820 start_label, last_label, section,
13823 list_tail = &(*list_tail)->dw_loc_next;
13824 last_cfa = next_cfa;
13825 start_label = last_label;
13827 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
13830 case DW_CFA_advance_loc:
13831 /* The encoding is complex enough that we should never emit this. */
13832 gcc_unreachable ();
13835 lookup_cfa_1 (cfi, &next_cfa, &remember);
13839 if (!cfa_equal_p (&last_cfa, &next_cfa))
13841 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
13842 start_label, last_label, section,
13844 list_tail = &(*list_tail)->dw_loc_next;
13845 start_label = last_label;
13847 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
13848 start_label, fde->dw_fde_end, section,
13854 /* Compute a displacement from the "steady-state frame pointer" to the
13855 frame base (often the same as the CFA), and store it in
13856 frame_pointer_fb_offset. OFFSET is added to the displacement
13857 before the latter is negated. */
13860 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
13864 #ifdef FRAME_POINTER_CFA_OFFSET
13865 reg = frame_pointer_rtx;
13866 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
13868 reg = arg_pointer_rtx;
13869 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
13872 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13873 if (GET_CODE (elim) == PLUS)
13875 offset += INTVAL (XEXP (elim, 1));
13876 elim = XEXP (elim, 0);
13879 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13880 && (elim == hard_frame_pointer_rtx
13881 || elim == stack_pointer_rtx))
13882 || elim == (frame_pointer_needed
13883 ? hard_frame_pointer_rtx
13884 : stack_pointer_rtx));
13886 frame_pointer_fb_offset = -offset;
13889 /* Generate a DW_AT_name attribute given some string value to be included as
13890 the value of the attribute. */
13893 add_name_attribute (dw_die_ref die, const char *name_string)
13895 if (name_string != NULL && *name_string != 0)
13897 if (demangle_name_func)
13898 name_string = (*demangle_name_func) (name_string);
13900 add_AT_string (die, DW_AT_name, name_string);
13904 /* Generate a DW_AT_comp_dir attribute for DIE. */
13907 add_comp_dir_attribute (dw_die_ref die)
13909 const char *wd = get_src_pwd ();
13915 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
13919 wdlen = strlen (wd);
13920 wd1 = GGC_NEWVEC (char, wdlen + 2);
13922 wd1 [wdlen] = DIR_SEPARATOR;
13923 wd1 [wdlen + 1] = 0;
13927 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
13930 /* Given a tree node describing an array bound (either lower or upper) output
13931 a representation for that bound. */
13934 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
13936 switch (TREE_CODE (bound))
13941 /* All fixed-bounds are represented by INTEGER_CST nodes. */
13943 if (! host_integerp (bound, 0)
13944 || (bound_attr == DW_AT_lower_bound
13945 && (((is_c_family () || is_java ()) && integer_zerop (bound))
13946 || (is_fortran () && integer_onep (bound)))))
13947 /* Use the default. */
13950 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
13954 case VIEW_CONVERT_EXPR:
13955 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
13965 dw_die_ref decl_die = lookup_decl_die (bound);
13966 dw_loc_descr_ref loc;
13968 /* ??? Can this happen, or should the variable have been bound
13969 first? Probably it can, since I imagine that we try to create
13970 the types of parameters in the order in which they exist in
13971 the list, and won't have created a forward reference to a
13972 later parameter. */
13973 if (decl_die != NULL)
13974 add_AT_die_ref (subrange_die, bound_attr, decl_die);
13977 loc = loc_descriptor_from_tree_1 (bound, 0);
13978 add_AT_location_description (subrange_die, bound_attr, loc);
13985 /* Otherwise try to create a stack operation procedure to
13986 evaluate the value of the array bound. */
13988 dw_die_ref ctx, decl_die;
13989 dw_loc_descr_ref loc;
13991 loc = loc_descriptor_from_tree (bound);
13995 if (current_function_decl == 0)
13996 ctx = comp_unit_die;
13998 ctx = lookup_decl_die (current_function_decl);
14000 decl_die = new_die (DW_TAG_variable, ctx, bound);
14001 add_AT_flag (decl_die, DW_AT_artificial, 1);
14002 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
14003 add_AT_loc (decl_die, DW_AT_location, loc);
14005 add_AT_die_ref (subrange_die, bound_attr, decl_die);
14011 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
14012 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
14013 Note that the block of subscript information for an array type also
14014 includes information about the element type of the given array type. */
14017 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
14019 unsigned dimension_number;
14021 dw_die_ref subrange_die;
14023 for (dimension_number = 0;
14024 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
14025 type = TREE_TYPE (type), dimension_number++)
14027 tree domain = TYPE_DOMAIN (type);
14029 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
14032 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
14033 and (in GNU C only) variable bounds. Handle all three forms
14035 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
14038 /* We have an array type with specified bounds. */
14039 lower = TYPE_MIN_VALUE (domain);
14040 upper = TYPE_MAX_VALUE (domain);
14042 /* Define the index type. */
14043 if (TREE_TYPE (domain))
14045 /* ??? This is probably an Ada unnamed subrange type. Ignore the
14046 TREE_TYPE field. We can't emit debug info for this
14047 because it is an unnamed integral type. */
14048 if (TREE_CODE (domain) == INTEGER_TYPE
14049 && TYPE_NAME (domain) == NULL_TREE
14050 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
14051 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
14054 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
14058 /* ??? If upper is NULL, the array has unspecified length,
14059 but it does have a lower bound. This happens with Fortran
14061 Since the debugger is definitely going to need to know N
14062 to produce useful results, go ahead and output the lower
14063 bound solo, and hope the debugger can cope. */
14065 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
14067 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
14070 /* Otherwise we have an array type with an unspecified length. The
14071 DWARF-2 spec does not say how to handle this; let's just leave out the
14077 add_byte_size_attribute (dw_die_ref die, tree tree_node)
14081 switch (TREE_CODE (tree_node))
14086 case ENUMERAL_TYPE:
14089 case QUAL_UNION_TYPE:
14090 size = int_size_in_bytes (tree_node);
14093 /* For a data member of a struct or union, the DW_AT_byte_size is
14094 generally given as the number of bytes normally allocated for an
14095 object of the *declared* type of the member itself. This is true
14096 even for bit-fields. */
14097 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
14100 gcc_unreachable ();
14103 /* Note that `size' might be -1 when we get to this point. If it is, that
14104 indicates that the byte size of the entity in question is variable. We
14105 have no good way of expressing this fact in Dwarf at the present time,
14106 so just let the -1 pass on through. */
14107 add_AT_unsigned (die, DW_AT_byte_size, size);
14110 /* For a FIELD_DECL node which represents a bit-field, output an attribute
14111 which specifies the distance in bits from the highest order bit of the
14112 "containing object" for the bit-field to the highest order bit of the
14115 For any given bit-field, the "containing object" is a hypothetical object
14116 (of some integral or enum type) within which the given bit-field lives. The
14117 type of this hypothetical "containing object" is always the same as the
14118 declared type of the individual bit-field itself. The determination of the
14119 exact location of the "containing object" for a bit-field is rather
14120 complicated. It's handled by the `field_byte_offset' function (above).
14122 Note that it is the size (in bytes) of the hypothetical "containing object"
14123 which will be given in the DW_AT_byte_size attribute for this bit-field.
14124 (See `byte_size_attribute' above). */
14127 add_bit_offset_attribute (dw_die_ref die, tree decl)
14129 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
14130 tree type = DECL_BIT_FIELD_TYPE (decl);
14131 HOST_WIDE_INT bitpos_int;
14132 HOST_WIDE_INT highest_order_object_bit_offset;
14133 HOST_WIDE_INT highest_order_field_bit_offset;
14134 HOST_WIDE_INT unsigned bit_offset;
14136 /* Must be a field and a bit field. */
14137 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
14139 /* We can't yet handle bit-fields whose offsets are variable, so if we
14140 encounter such things, just return without generating any attribute
14141 whatsoever. Likewise for variable or too large size. */
14142 if (! host_integerp (bit_position (decl), 0)
14143 || ! host_integerp (DECL_SIZE (decl), 1))
14146 bitpos_int = int_bit_position (decl);
14148 /* Note that the bit offset is always the distance (in bits) from the
14149 highest-order bit of the "containing object" to the highest-order bit of
14150 the bit-field itself. Since the "high-order end" of any object or field
14151 is different on big-endian and little-endian machines, the computation
14152 below must take account of these differences. */
14153 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
14154 highest_order_field_bit_offset = bitpos_int;
14156 if (! BYTES_BIG_ENDIAN)
14158 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
14159 highest_order_object_bit_offset += simple_type_size_in_bits (type);
14163 = (! BYTES_BIG_ENDIAN
14164 ? highest_order_object_bit_offset - highest_order_field_bit_offset
14165 : highest_order_field_bit_offset - highest_order_object_bit_offset);
14167 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
14170 /* For a FIELD_DECL node which represents a bit field, output an attribute
14171 which specifies the length in bits of the given field. */
14174 add_bit_size_attribute (dw_die_ref die, tree decl)
14176 /* Must be a field and a bit field. */
14177 gcc_assert (TREE_CODE (decl) == FIELD_DECL
14178 && DECL_BIT_FIELD_TYPE (decl));
14180 if (host_integerp (DECL_SIZE (decl), 1))
14181 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
14184 /* If the compiled language is ANSI C, then add a 'prototyped'
14185 attribute, if arg types are given for the parameters of a function. */
14188 add_prototyped_attribute (dw_die_ref die, tree func_type)
14190 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
14191 && TYPE_ARG_TYPES (func_type) != NULL)
14192 add_AT_flag (die, DW_AT_prototyped, 1);
14195 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
14196 by looking in either the type declaration or object declaration
14199 static inline dw_die_ref
14200 add_abstract_origin_attribute (dw_die_ref die, tree origin)
14202 dw_die_ref origin_die = NULL;
14204 if (TREE_CODE (origin) != FUNCTION_DECL)
14206 /* We may have gotten separated from the block for the inlined
14207 function, if we're in an exception handler or some such; make
14208 sure that the abstract function has been written out.
14210 Doing this for nested functions is wrong, however; functions are
14211 distinct units, and our context might not even be inline. */
14215 fn = TYPE_STUB_DECL (fn);
14217 fn = decl_function_context (fn);
14219 dwarf2out_abstract_function (fn);
14222 if (DECL_P (origin))
14223 origin_die = lookup_decl_die (origin);
14224 else if (TYPE_P (origin))
14225 origin_die = lookup_type_die (origin);
14227 /* XXX: Functions that are never lowered don't always have correct block
14228 trees (in the case of java, they simply have no block tree, in some other
14229 languages). For these functions, there is nothing we can really do to
14230 output correct debug info for inlined functions in all cases. Rather
14231 than die, we'll just produce deficient debug info now, in that we will
14232 have variables without a proper abstract origin. In the future, when all
14233 functions are lowered, we should re-add a gcc_assert (origin_die)
14237 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
14241 /* We do not currently support the pure_virtual attribute. */
14244 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
14246 if (DECL_VINDEX (func_decl))
14248 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14250 if (host_integerp (DECL_VINDEX (func_decl), 0))
14251 add_AT_loc (die, DW_AT_vtable_elem_location,
14252 new_loc_descr (DW_OP_constu,
14253 tree_low_cst (DECL_VINDEX (func_decl), 0),
14256 /* GNU extension: Record what type this method came from originally. */
14257 if (debug_info_level > DINFO_LEVEL_TERSE)
14258 add_AT_die_ref (die, DW_AT_containing_type,
14259 lookup_type_die (DECL_CONTEXT (func_decl)));
14263 /* Add source coordinate attributes for the given decl. */
14266 add_src_coords_attributes (dw_die_ref die, tree decl)
14268 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14270 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
14271 add_AT_unsigned (die, DW_AT_decl_line, s.line);
14274 /* Add a DW_AT_name attribute and source coordinate attribute for the
14275 given decl, but only if it actually has a name. */
14278 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
14282 decl_name = DECL_NAME (decl);
14283 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
14285 add_name_attribute (die, dwarf2_name (decl, 0));
14286 if (! DECL_ARTIFICIAL (decl))
14287 add_src_coords_attributes (die, decl);
14289 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
14290 && TREE_PUBLIC (decl)
14291 && !DECL_ABSTRACT (decl)
14292 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
14295 /* Defer until we have an assembler name set. */
14296 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
14298 limbo_die_node *asm_name;
14300 asm_name = GGC_CNEW (limbo_die_node);
14301 asm_name->die = die;
14302 asm_name->created_for = decl;
14303 asm_name->next = deferred_asm_name;
14304 deferred_asm_name = asm_name;
14306 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
14307 add_AT_string (die, DW_AT_MIPS_linkage_name,
14308 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
14312 #ifdef VMS_DEBUGGING_INFO
14313 /* Get the function's name, as described by its RTL. This may be different
14314 from the DECL_NAME name used in the source file. */
14315 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
14317 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
14318 XEXP (DECL_RTL (decl), 0));
14319 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
14324 /* Push a new declaration scope. */
14327 push_decl_scope (tree scope)
14329 VEC_safe_push (tree, gc, decl_scope_table, scope);
14332 /* Pop a declaration scope. */
14335 pop_decl_scope (void)
14337 VEC_pop (tree, decl_scope_table);
14340 /* Return the DIE for the scope that immediately contains this type.
14341 Non-named types get global scope. Named types nested in other
14342 types get their containing scope if it's open, or global scope
14343 otherwise. All other types (i.e. function-local named types) get
14344 the current active scope. */
14347 scope_die_for (tree t, dw_die_ref context_die)
14349 dw_die_ref scope_die = NULL;
14350 tree containing_scope;
14353 /* Non-types always go in the current scope. */
14354 gcc_assert (TYPE_P (t));
14356 containing_scope = TYPE_CONTEXT (t);
14358 /* Use the containing namespace if it was passed in (for a declaration). */
14359 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
14361 if (context_die == lookup_decl_die (containing_scope))
14364 containing_scope = NULL_TREE;
14367 /* Ignore function type "scopes" from the C frontend. They mean that
14368 a tagged type is local to a parmlist of a function declarator, but
14369 that isn't useful to DWARF. */
14370 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
14371 containing_scope = NULL_TREE;
14373 if (containing_scope == NULL_TREE)
14374 scope_die = comp_unit_die;
14375 else if (TYPE_P (containing_scope))
14377 /* For types, we can just look up the appropriate DIE. But
14378 first we check to see if we're in the middle of emitting it
14379 so we know where the new DIE should go. */
14380 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
14381 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
14386 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
14387 || TREE_ASM_WRITTEN (containing_scope));
14389 /* If none of the current dies are suitable, we get file scope. */
14390 scope_die = comp_unit_die;
14393 scope_die = lookup_type_die (containing_scope);
14396 scope_die = context_die;
14401 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
14404 local_scope_p (dw_die_ref context_die)
14406 for (; context_die; context_die = context_die->die_parent)
14407 if (context_die->die_tag == DW_TAG_inlined_subroutine
14408 || context_die->die_tag == DW_TAG_subprogram)
14414 /* Returns nonzero if CONTEXT_DIE is a class. */
14417 class_scope_p (dw_die_ref context_die)
14419 return (context_die
14420 && (context_die->die_tag == DW_TAG_structure_type
14421 || context_die->die_tag == DW_TAG_class_type
14422 || context_die->die_tag == DW_TAG_interface_type
14423 || context_die->die_tag == DW_TAG_union_type));
14426 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
14427 whether or not to treat a DIE in this context as a declaration. */
14430 class_or_namespace_scope_p (dw_die_ref context_die)
14432 return (class_scope_p (context_die)
14433 || (context_die && context_die->die_tag == DW_TAG_namespace));
14436 /* Many forms of DIEs require a "type description" attribute. This
14437 routine locates the proper "type descriptor" die for the type given
14438 by 'type', and adds a DW_AT_type attribute below the given die. */
14441 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
14442 int decl_volatile, dw_die_ref context_die)
14444 enum tree_code code = TREE_CODE (type);
14445 dw_die_ref type_die = NULL;
14447 /* ??? If this type is an unnamed subrange type of an integral, floating-point
14448 or fixed-point type, use the inner type. This is because we have no
14449 support for unnamed types in base_type_die. This can happen if this is
14450 an Ada subrange type. Correct solution is emit a subrange type die. */
14451 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
14452 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
14453 type = TREE_TYPE (type), code = TREE_CODE (type);
14455 if (code == ERROR_MARK
14456 /* Handle a special case. For functions whose return type is void, we
14457 generate *no* type attribute. (Note that no object may have type
14458 `void', so this only applies to function return types). */
14459 || code == VOID_TYPE)
14462 type_die = modified_type_die (type,
14463 decl_const || TYPE_READONLY (type),
14464 decl_volatile || TYPE_VOLATILE (type),
14467 if (type_die != NULL)
14468 add_AT_die_ref (object_die, DW_AT_type, type_die);
14471 /* Given an object die, add the calling convention attribute for the
14472 function call type. */
14474 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
14476 enum dwarf_calling_convention value = DW_CC_normal;
14478 value = ((enum dwarf_calling_convention)
14479 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
14481 /* DWARF doesn't provide a way to identify a program's source-level
14482 entry point. DW_AT_calling_convention attributes are only meant
14483 to describe functions' calling conventions. However, lacking a
14484 better way to signal the Fortran main program, we use this for the
14485 time being, following existing custom. */
14487 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
14488 value = DW_CC_program;
14490 /* Only add the attribute if the backend requests it, and
14491 is not DW_CC_normal. */
14492 if (value && (value != DW_CC_normal))
14493 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
14496 /* Given a tree pointer to a struct, class, union, or enum type node, return
14497 a pointer to the (string) tag name for the given type, or zero if the type
14498 was declared without a tag. */
14500 static const char *
14501 type_tag (const_tree type)
14503 const char *name = 0;
14505 if (TYPE_NAME (type) != 0)
14509 /* Find the IDENTIFIER_NODE for the type name. */
14510 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
14511 t = TYPE_NAME (type);
14513 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
14514 a TYPE_DECL node, regardless of whether or not a `typedef' was
14516 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14517 && ! DECL_IGNORED_P (TYPE_NAME (type)))
14519 /* We want to be extra verbose. Don't call dwarf_name if
14520 DECL_NAME isn't set. The default hook for decl_printable_name
14521 doesn't like that, and in this context it's correct to return
14522 0, instead of "<anonymous>" or the like. */
14523 if (DECL_NAME (TYPE_NAME (type)))
14524 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
14527 /* Now get the name as a string, or invent one. */
14528 if (!name && t != 0)
14529 name = IDENTIFIER_POINTER (t);
14532 return (name == 0 || *name == '\0') ? 0 : name;
14535 /* Return the type associated with a data member, make a special check
14536 for bit field types. */
14539 member_declared_type (const_tree member)
14541 return (DECL_BIT_FIELD_TYPE (member)
14542 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
14545 /* Get the decl's label, as described by its RTL. This may be different
14546 from the DECL_NAME name used in the source file. */
14549 static const char *
14550 decl_start_label (tree decl)
14553 const char *fnname;
14555 x = DECL_RTL (decl);
14556 gcc_assert (MEM_P (x));
14559 gcc_assert (GET_CODE (x) == SYMBOL_REF);
14561 fnname = XSTR (x, 0);
14566 /* These routines generate the internal representation of the DIE's for
14567 the compilation unit. Debugging information is collected by walking
14568 the declaration trees passed in from dwarf2out_decl(). */
14571 gen_array_type_die (tree type, dw_die_ref context_die)
14573 dw_die_ref scope_die = scope_die_for (type, context_die);
14574 dw_die_ref array_die;
14576 /* GNU compilers represent multidimensional array types as sequences of one
14577 dimensional array types whose element types are themselves array types.
14578 We sometimes squish that down to a single array_type DIE with multiple
14579 subscripts in the Dwarf debugging info. The draft Dwarf specification
14580 say that we are allowed to do this kind of compression in C, because
14581 there is no difference between an array of arrays and a multidimensional
14582 array. We don't do this for Ada to remain as close as possible to the
14583 actual representation, which is especially important against the language
14584 flexibilty wrt arrays of variable size. */
14586 bool collapse_nested_arrays = !is_ada ();
14589 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
14590 DW_TAG_string_type doesn't have DW_AT_type attribute). */
14591 if (TYPE_STRING_FLAG (type)
14592 && TREE_CODE (type) == ARRAY_TYPE
14594 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
14596 HOST_WIDE_INT size;
14598 array_die = new_die (DW_TAG_string_type, scope_die, type);
14599 add_name_attribute (array_die, type_tag (type));
14600 equate_type_number_to_die (type, array_die);
14601 size = int_size_in_bytes (type);
14603 add_AT_unsigned (array_die, DW_AT_byte_size, size);
14604 else if (TYPE_DOMAIN (type) != NULL_TREE
14605 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
14606 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
14608 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
14609 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
14611 size = int_size_in_bytes (TREE_TYPE (szdecl));
14612 if (loc && size > 0)
14614 add_AT_loc (array_die, DW_AT_string_length, loc);
14615 if (size != DWARF2_ADDR_SIZE)
14616 add_AT_unsigned (array_die, DW_AT_byte_size, size);
14622 /* ??? The SGI dwarf reader fails for array of array of enum types
14623 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
14624 array type comes before the outer array type. We thus call gen_type_die
14625 before we new_die and must prevent nested array types collapsing for this
14628 #ifdef MIPS_DEBUGGING_INFO
14629 gen_type_die (TREE_TYPE (type), context_die);
14630 collapse_nested_arrays = false;
14633 array_die = new_die (DW_TAG_array_type, scope_die, type);
14634 add_name_attribute (array_die, type_tag (type));
14635 equate_type_number_to_die (type, array_die);
14637 if (TREE_CODE (type) == VECTOR_TYPE)
14639 /* The frontend feeds us a representation for the vector as a struct
14640 containing an array. Pull out the array type. */
14641 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
14642 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
14645 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
14647 && TREE_CODE (type) == ARRAY_TYPE
14648 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
14649 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
14650 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
14653 /* We default the array ordering. SDB will probably do
14654 the right things even if DW_AT_ordering is not present. It's not even
14655 an issue until we start to get into multidimensional arrays anyway. If
14656 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
14657 then we'll have to put the DW_AT_ordering attribute back in. (But if
14658 and when we find out that we need to put these in, we will only do so
14659 for multidimensional arrays. */
14660 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
14663 #ifdef MIPS_DEBUGGING_INFO
14664 /* The SGI compilers handle arrays of unknown bound by setting
14665 AT_declaration and not emitting any subrange DIEs. */
14666 if (! TYPE_DOMAIN (type))
14667 add_AT_flag (array_die, DW_AT_declaration, 1);
14670 add_subscript_info (array_die, type, collapse_nested_arrays);
14672 /* Add representation of the type of the elements of this array type and
14673 emit the corresponding DIE if we haven't done it already. */
14674 element_type = TREE_TYPE (type);
14675 if (collapse_nested_arrays)
14676 while (TREE_CODE (element_type) == ARRAY_TYPE)
14678 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
14680 element_type = TREE_TYPE (element_type);
14683 #ifndef MIPS_DEBUGGING_INFO
14684 gen_type_die (element_type, context_die);
14687 add_type_attribute (array_die, element_type, 0, 0, context_die);
14689 if (get_AT (array_die, DW_AT_name))
14690 add_pubtype (type, array_die);
14693 static dw_loc_descr_ref
14694 descr_info_loc (tree val, tree base_decl)
14696 HOST_WIDE_INT size;
14697 dw_loc_descr_ref loc, loc2;
14698 enum dwarf_location_atom op;
14700 if (val == base_decl)
14701 return new_loc_descr (DW_OP_push_object_address, 0, 0);
14703 switch (TREE_CODE (val))
14706 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14708 return loc_descriptor_from_tree_1 (val, 0);
14710 if (host_integerp (val, 0))
14711 return int_loc_descriptor (tree_low_cst (val, 0));
14714 size = int_size_in_bytes (TREE_TYPE (val));
14717 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14720 if (size == DWARF2_ADDR_SIZE)
14721 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
14723 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
14725 case POINTER_PLUS_EXPR:
14727 if (host_integerp (TREE_OPERAND (val, 1), 1)
14728 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
14731 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14734 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
14740 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
14743 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
14746 add_loc_descr (&loc, loc2);
14747 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
14769 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
14770 tree val, tree base_decl)
14772 dw_loc_descr_ref loc;
14774 if (host_integerp (val, 0))
14776 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
14780 loc = descr_info_loc (val, base_decl);
14784 add_AT_loc (die, attr, loc);
14787 /* This routine generates DIE for array with hidden descriptor, details
14788 are filled into *info by a langhook. */
14791 gen_descr_array_type_die (tree type, struct array_descr_info *info,
14792 dw_die_ref context_die)
14794 dw_die_ref scope_die = scope_die_for (type, context_die);
14795 dw_die_ref array_die;
14798 array_die = new_die (DW_TAG_array_type, scope_die, type);
14799 add_name_attribute (array_die, type_tag (type));
14800 equate_type_number_to_die (type, array_die);
14802 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
14804 && info->ndimensions >= 2)
14805 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
14807 if (info->data_location)
14808 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
14810 if (info->associated)
14811 add_descr_info_field (array_die, DW_AT_associated, info->associated,
14813 if (info->allocated)
14814 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
14817 for (dim = 0; dim < info->ndimensions; dim++)
14819 dw_die_ref subrange_die
14820 = new_die (DW_TAG_subrange_type, array_die, NULL);
14822 if (info->dimen[dim].lower_bound)
14824 /* If it is the default value, omit it. */
14825 if ((is_c_family () || is_java ())
14826 && integer_zerop (info->dimen[dim].lower_bound))
14828 else if (is_fortran ()
14829 && integer_onep (info->dimen[dim].lower_bound))
14832 add_descr_info_field (subrange_die, DW_AT_lower_bound,
14833 info->dimen[dim].lower_bound,
14836 if (info->dimen[dim].upper_bound)
14837 add_descr_info_field (subrange_die, DW_AT_upper_bound,
14838 info->dimen[dim].upper_bound,
14840 if (info->dimen[dim].stride)
14841 add_descr_info_field (subrange_die, DW_AT_byte_stride,
14842 info->dimen[dim].stride,
14846 gen_type_die (info->element_type, context_die);
14847 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
14849 if (get_AT (array_die, DW_AT_name))
14850 add_pubtype (type, array_die);
14855 gen_entry_point_die (tree decl, dw_die_ref context_die)
14857 tree origin = decl_ultimate_origin (decl);
14858 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
14860 if (origin != NULL)
14861 add_abstract_origin_attribute (decl_die, origin);
14864 add_name_and_src_coords_attributes (decl_die, decl);
14865 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
14866 0, 0, context_die);
14869 if (DECL_ABSTRACT (decl))
14870 equate_decl_number_to_die (decl, decl_die);
14872 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
14876 /* Walk through the list of incomplete types again, trying once more to
14877 emit full debugging info for them. */
14880 retry_incomplete_types (void)
14884 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
14885 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
14888 /* Determine what tag to use for a record type. */
14890 static enum dwarf_tag
14891 record_type_tag (tree type)
14893 if (! lang_hooks.types.classify_record)
14894 return DW_TAG_structure_type;
14896 switch (lang_hooks.types.classify_record (type))
14898 case RECORD_IS_STRUCT:
14899 return DW_TAG_structure_type;
14901 case RECORD_IS_CLASS:
14902 return DW_TAG_class_type;
14904 case RECORD_IS_INTERFACE:
14905 return DW_TAG_interface_type;
14908 gcc_unreachable ();
14912 /* Generate a DIE to represent an enumeration type. Note that these DIEs
14913 include all of the information about the enumeration values also. Each
14914 enumerated type name/value is listed as a child of the enumerated type
14918 gen_enumeration_type_die (tree type, dw_die_ref context_die)
14920 dw_die_ref type_die = lookup_type_die (type);
14922 if (type_die == NULL)
14924 type_die = new_die (DW_TAG_enumeration_type,
14925 scope_die_for (type, context_die), type);
14926 equate_type_number_to_die (type, type_die);
14927 add_name_attribute (type_die, type_tag (type));
14929 else if (! TYPE_SIZE (type))
14932 remove_AT (type_die, DW_AT_declaration);
14934 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
14935 given enum type is incomplete, do not generate the DW_AT_byte_size
14936 attribute or the DW_AT_element_list attribute. */
14937 if (TYPE_SIZE (type))
14941 TREE_ASM_WRITTEN (type) = 1;
14942 add_byte_size_attribute (type_die, type);
14943 if (TYPE_STUB_DECL (type) != NULL_TREE)
14944 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14946 /* If the first reference to this type was as the return type of an
14947 inline function, then it may not have a parent. Fix this now. */
14948 if (type_die->die_parent == NULL)
14949 add_child_die (scope_die_for (type, context_die), type_die);
14951 for (link = TYPE_VALUES (type);
14952 link != NULL; link = TREE_CHAIN (link))
14954 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
14955 tree value = TREE_VALUE (link);
14957 add_name_attribute (enum_die,
14958 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
14960 if (TREE_CODE (value) == CONST_DECL)
14961 value = DECL_INITIAL (value);
14963 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
14964 /* DWARF2 does not provide a way of indicating whether or
14965 not enumeration constants are signed or unsigned. GDB
14966 always assumes the values are signed, so we output all
14967 values as if they were signed. That means that
14968 enumeration constants with very large unsigned values
14969 will appear to have negative values in the debugger. */
14970 add_AT_int (enum_die, DW_AT_const_value,
14971 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
14975 add_AT_flag (type_die, DW_AT_declaration, 1);
14977 if (get_AT (type_die, DW_AT_name))
14978 add_pubtype (type, type_die);
14983 /* Generate a DIE to represent either a real live formal parameter decl or to
14984 represent just the type of some formal parameter position in some function
14987 Note that this routine is a bit unusual because its argument may be a
14988 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
14989 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
14990 node. If it's the former then this function is being called to output a
14991 DIE to represent a formal parameter object (or some inlining thereof). If
14992 it's the latter, then this function is only being called to output a
14993 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
14994 argument type of some subprogram type. */
14997 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
14999 tree node_or_origin = node ? node : origin;
15000 dw_die_ref parm_die
15001 = new_die (DW_TAG_formal_parameter, context_die, node);
15003 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
15005 case tcc_declaration:
15007 origin = decl_ultimate_origin (node);
15008 if (origin != NULL)
15009 add_abstract_origin_attribute (parm_die, origin);
15012 tree type = TREE_TYPE (node);
15013 add_name_and_src_coords_attributes (parm_die, node);
15014 if (DECL_BY_REFERENCE (node))
15015 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
15018 add_type_attribute (parm_die, type,
15019 TREE_READONLY (node),
15020 TREE_THIS_VOLATILE (node),
15022 if (DECL_ARTIFICIAL (node))
15023 add_AT_flag (parm_die, DW_AT_artificial, 1);
15026 if (node && node != origin)
15027 equate_decl_number_to_die (node, parm_die);
15028 if (! DECL_ABSTRACT (node_or_origin))
15029 add_location_or_const_value_attribute (parm_die, node_or_origin,
15035 /* We were called with some kind of a ..._TYPE node. */
15036 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
15040 gcc_unreachable ();
15046 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
15047 at the end of an (ANSI prototyped) formal parameters list. */
15050 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
15052 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
15055 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
15056 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
15057 parameters as specified in some function type specification (except for
15058 those which appear as part of a function *definition*). */
15061 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
15064 tree formal_type = NULL;
15065 tree first_parm_type;
15068 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
15070 arg = DECL_ARGUMENTS (function_or_method_type);
15071 function_or_method_type = TREE_TYPE (function_or_method_type);
15076 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
15078 /* Make our first pass over the list of formal parameter types and output a
15079 DW_TAG_formal_parameter DIE for each one. */
15080 for (link = first_parm_type; link; )
15082 dw_die_ref parm_die;
15084 formal_type = TREE_VALUE (link);
15085 if (formal_type == void_type_node)
15088 /* Output a (nameless) DIE to represent the formal parameter itself. */
15089 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
15090 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
15091 && link == first_parm_type)
15092 || (arg && DECL_ARTIFICIAL (arg)))
15093 add_AT_flag (parm_die, DW_AT_artificial, 1);
15095 link = TREE_CHAIN (link);
15097 arg = TREE_CHAIN (arg);
15100 /* If this function type has an ellipsis, add a
15101 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
15102 if (formal_type != void_type_node)
15103 gen_unspecified_parameters_die (function_or_method_type, context_die);
15105 /* Make our second (and final) pass over the list of formal parameter types
15106 and output DIEs to represent those types (as necessary). */
15107 for (link = TYPE_ARG_TYPES (function_or_method_type);
15108 link && TREE_VALUE (link);
15109 link = TREE_CHAIN (link))
15110 gen_type_die (TREE_VALUE (link), context_die);
15113 /* We want to generate the DIE for TYPE so that we can generate the
15114 die for MEMBER, which has been defined; we will need to refer back
15115 to the member declaration nested within TYPE. If we're trying to
15116 generate minimal debug info for TYPE, processing TYPE won't do the
15117 trick; we need to attach the member declaration by hand. */
15120 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
15122 gen_type_die (type, context_die);
15124 /* If we're trying to avoid duplicate debug info, we may not have
15125 emitted the member decl for this function. Emit it now. */
15126 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
15127 && ! lookup_decl_die (member))
15129 dw_die_ref type_die;
15130 gcc_assert (!decl_ultimate_origin (member));
15132 push_decl_scope (type);
15133 type_die = lookup_type_die (type);
15134 if (TREE_CODE (member) == FUNCTION_DECL)
15135 gen_subprogram_die (member, type_die);
15136 else if (TREE_CODE (member) == FIELD_DECL)
15138 /* Ignore the nameless fields that are used to skip bits but handle
15139 C++ anonymous unions and structs. */
15140 if (DECL_NAME (member) != NULL_TREE
15141 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
15142 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
15144 gen_type_die (member_declared_type (member), type_die);
15145 gen_field_die (member, type_die);
15149 gen_variable_die (member, NULL_TREE, type_die);
15155 /* Generate the DWARF2 info for the "abstract" instance of a function which we
15156 may later generate inlined and/or out-of-line instances of. */
15159 dwarf2out_abstract_function (tree decl)
15161 dw_die_ref old_die;
15164 int was_abstract = DECL_ABSTRACT (decl);
15166 /* Make sure we have the actual abstract inline, not a clone. */
15167 decl = DECL_ORIGIN (decl);
15168 htab_empty (decl_loc_table);
15170 old_die = lookup_decl_die (decl);
15171 if (old_die && get_AT (old_die, DW_AT_inline))
15172 /* We've already generated the abstract instance. */
15175 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
15176 we don't get confused by DECL_ABSTRACT. */
15177 if (debug_info_level > DINFO_LEVEL_TERSE)
15179 context = decl_class_context (decl);
15181 gen_type_die_for_member
15182 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
15185 /* Pretend we've just finished compiling this function. */
15186 save_fn = current_function_decl;
15187 current_function_decl = decl;
15188 push_cfun (DECL_STRUCT_FUNCTION (decl));
15190 set_decl_abstract_flags (decl, 1);
15191 dwarf2out_decl (decl);
15192 if (! was_abstract)
15193 set_decl_abstract_flags (decl, 0);
15195 current_function_decl = save_fn;
15199 /* Helper function of premark_used_types() which gets called through
15200 htab_traverse_resize().
15202 Marks the DIE of a given type in *SLOT as perennial, so it never gets
15203 marked as unused by prune_unused_types. */
15205 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
15210 type = (tree) *slot;
15211 die = lookup_type_die (type);
15213 die->die_perennial_p = 1;
15217 /* Mark all members of used_types_hash as perennial. */
15219 premark_used_types (void)
15221 if (cfun && cfun->used_types_hash)
15222 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
15225 /* Generate a DIE to represent a declared function (either file-scope or
15229 gen_subprogram_die (tree decl, dw_die_ref context_die)
15231 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
15232 tree origin = decl_ultimate_origin (decl);
15233 dw_die_ref subr_die;
15236 dw_die_ref old_die = lookup_decl_die (decl);
15237 int declaration = (current_function_decl != decl
15238 || class_or_namespace_scope_p (context_die));
15240 premark_used_types ();
15242 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
15243 started to generate the abstract instance of an inline, decided to output
15244 its containing class, and proceeded to emit the declaration of the inline
15245 from the member list for the class. If so, DECLARATION takes priority;
15246 we'll get back to the abstract instance when done with the class. */
15248 /* The class-scope declaration DIE must be the primary DIE. */
15249 if (origin && declaration && class_or_namespace_scope_p (context_die))
15252 gcc_assert (!old_die);
15255 /* Now that the C++ front end lazily declares artificial member fns, we
15256 might need to retrofit the declaration into its class. */
15257 if (!declaration && !origin && !old_die
15258 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
15259 && !class_or_namespace_scope_p (context_die)
15260 && debug_info_level > DINFO_LEVEL_TERSE)
15261 old_die = force_decl_die (decl);
15263 if (origin != NULL)
15265 gcc_assert (!declaration || local_scope_p (context_die));
15267 /* Fixup die_parent for the abstract instance of a nested
15268 inline function. */
15269 if (old_die && old_die->die_parent == NULL)
15270 add_child_die (context_die, old_die);
15272 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15273 add_abstract_origin_attribute (subr_die, origin);
15277 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
15278 struct dwarf_file_data * file_index = lookup_filename (s.file);
15280 if (!get_AT_flag (old_die, DW_AT_declaration)
15281 /* We can have a normal definition following an inline one in the
15282 case of redefinition of GNU C extern inlines.
15283 It seems reasonable to use AT_specification in this case. */
15284 && !get_AT (old_die, DW_AT_inline))
15286 /* Detect and ignore this case, where we are trying to output
15287 something we have already output. */
15291 /* If the definition comes from the same place as the declaration,
15292 maybe use the old DIE. We always want the DIE for this function
15293 that has the *_pc attributes to be under comp_unit_die so the
15294 debugger can find it. We also need to do this for abstract
15295 instances of inlines, since the spec requires the out-of-line copy
15296 to have the same parent. For local class methods, this doesn't
15297 apply; we just use the old DIE. */
15298 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
15299 && (DECL_ARTIFICIAL (decl)
15300 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
15301 && (get_AT_unsigned (old_die, DW_AT_decl_line)
15302 == (unsigned) s.line))))
15304 subr_die = old_die;
15306 /* Clear out the declaration attribute and the formal parameters.
15307 Do not remove all children, because it is possible that this
15308 declaration die was forced using force_decl_die(). In such
15309 cases die that forced declaration die (e.g. TAG_imported_module)
15310 is one of the children that we do not want to remove. */
15311 remove_AT (subr_die, DW_AT_declaration);
15312 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
15316 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15317 add_AT_specification (subr_die, old_die);
15318 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
15319 add_AT_file (subr_die, DW_AT_decl_file, file_index);
15320 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
15321 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
15326 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
15328 if (TREE_PUBLIC (decl))
15329 add_AT_flag (subr_die, DW_AT_external, 1);
15331 add_name_and_src_coords_attributes (subr_die, decl);
15332 if (debug_info_level > DINFO_LEVEL_TERSE)
15334 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
15335 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
15336 0, 0, context_die);
15339 add_pure_or_virtual_attribute (subr_die, decl);
15340 if (DECL_ARTIFICIAL (decl))
15341 add_AT_flag (subr_die, DW_AT_artificial, 1);
15343 if (TREE_PROTECTED (decl))
15344 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
15345 else if (TREE_PRIVATE (decl))
15346 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
15351 if (!old_die || !get_AT (old_die, DW_AT_inline))
15353 add_AT_flag (subr_die, DW_AT_declaration, 1);
15355 /* If this is an explicit function declaration then generate
15356 a DW_AT_explicit attribute. */
15357 if (lang_hooks.decls.function_decl_explicit_p (decl))
15358 add_AT_flag (subr_die, DW_AT_explicit, 1);
15360 /* The first time we see a member function, it is in the context of
15361 the class to which it belongs. We make sure of this by emitting
15362 the class first. The next time is the definition, which is
15363 handled above. The two may come from the same source text.
15365 Note that force_decl_die() forces function declaration die. It is
15366 later reused to represent definition. */
15367 equate_decl_number_to_die (decl, subr_die);
15370 else if (DECL_ABSTRACT (decl))
15372 if (DECL_DECLARED_INLINE_P (decl))
15374 if (cgraph_function_possibly_inlined_p (decl))
15375 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
15377 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
15381 if (cgraph_function_possibly_inlined_p (decl))
15382 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
15384 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
15387 if (DECL_DECLARED_INLINE_P (decl)
15388 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
15389 add_AT_flag (subr_die, DW_AT_artificial, 1);
15391 equate_decl_number_to_die (decl, subr_die);
15393 else if (!DECL_EXTERNAL (decl))
15395 HOST_WIDE_INT cfa_fb_offset;
15397 if (!old_die || !get_AT (old_die, DW_AT_inline))
15398 equate_decl_number_to_die (decl, subr_die);
15400 if (!flag_reorder_blocks_and_partition)
15402 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
15403 current_function_funcdef_no);
15404 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
15405 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15406 current_function_funcdef_no);
15407 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
15409 add_pubname (decl, subr_die);
15410 add_arange (decl, subr_die);
15413 { /* Do nothing for now; maybe need to duplicate die, one for
15414 hot section and one for cold section, then use the hot/cold
15415 section begin/end labels to generate the aranges... */
15417 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
15418 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
15419 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
15420 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
15422 add_pubname (decl, subr_die);
15423 add_arange (decl, subr_die);
15424 add_arange (decl, subr_die);
15428 #ifdef MIPS_DEBUGGING_INFO
15429 /* Add a reference to the FDE for this routine. */
15430 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
15433 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
15435 /* We define the "frame base" as the function's CFA. This is more
15436 convenient for several reasons: (1) It's stable across the prologue
15437 and epilogue, which makes it better than just a frame pointer,
15438 (2) With dwarf3, there exists a one-byte encoding that allows us
15439 to reference the .debug_frame data by proxy, but failing that,
15440 (3) We can at least reuse the code inspection and interpretation
15441 code that determines the CFA position at various points in the
15443 if (dwarf_version >= 3)
15445 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
15446 add_AT_loc (subr_die, DW_AT_frame_base, op);
15450 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
15451 if (list->dw_loc_next)
15452 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
15454 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
15457 /* Compute a displacement from the "steady-state frame pointer" to
15458 the CFA. The former is what all stack slots and argument slots
15459 will reference in the rtl; the later is what we've told the
15460 debugger about. We'll need to adjust all frame_base references
15461 by this displacement. */
15462 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
15464 if (cfun->static_chain_decl)
15465 add_AT_location_description (subr_die, DW_AT_static_link,
15466 loc_descriptor_from_tree (cfun->static_chain_decl));
15469 /* Generate child dies for template paramaters. */
15470 if (debug_info_level > DINFO_LEVEL_TERSE)
15471 gen_generic_params_dies (decl);
15473 /* Now output descriptions of the arguments for this function. This gets
15474 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
15475 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
15476 `...' at the end of the formal parameter list. In order to find out if
15477 there was a trailing ellipsis or not, we must instead look at the type
15478 associated with the FUNCTION_DECL. This will be a node of type
15479 FUNCTION_TYPE. If the chain of type nodes hanging off of this
15480 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
15481 an ellipsis at the end. */
15483 /* In the case where we are describing a mere function declaration, all we
15484 need to do here (and all we *can* do here) is to describe the *types* of
15485 its formal parameters. */
15486 if (debug_info_level <= DINFO_LEVEL_TERSE)
15488 else if (declaration)
15489 gen_formal_types_die (decl, subr_die);
15492 /* Generate DIEs to represent all known formal parameters. */
15493 tree arg_decls = DECL_ARGUMENTS (decl);
15496 /* When generating DIEs, generate the unspecified_parameters DIE
15497 instead if we come across the arg "__builtin_va_alist" */
15498 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
15499 if (TREE_CODE (parm) == PARM_DECL)
15501 if (DECL_NAME (parm)
15502 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
15503 "__builtin_va_alist"))
15504 gen_unspecified_parameters_die (parm, subr_die);
15506 gen_decl_die (parm, NULL, subr_die);
15509 /* Decide whether we need an unspecified_parameters DIE at the end.
15510 There are 2 more cases to do this for: 1) the ansi ... declaration -
15511 this is detectable when the end of the arg list is not a
15512 void_type_node 2) an unprototyped function declaration (not a
15513 definition). This just means that we have no info about the
15514 parameters at all. */
15515 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
15516 if (fn_arg_types != NULL)
15518 /* This is the prototyped case, check for.... */
15519 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
15520 gen_unspecified_parameters_die (decl, subr_die);
15522 else if (DECL_INITIAL (decl) == NULL_TREE)
15523 gen_unspecified_parameters_die (decl, subr_die);
15526 /* Output Dwarf info for all of the stuff within the body of the function
15527 (if it has one - it may be just a declaration). */
15528 outer_scope = DECL_INITIAL (decl);
15530 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
15531 a function. This BLOCK actually represents the outermost binding contour
15532 for the function, i.e. the contour in which the function's formal
15533 parameters and labels get declared. Curiously, it appears that the front
15534 end doesn't actually put the PARM_DECL nodes for the current function onto
15535 the BLOCK_VARS list for this outer scope, but are strung off of the
15536 DECL_ARGUMENTS list for the function instead.
15538 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
15539 the LABEL_DECL nodes for the function however, and we output DWARF info
15540 for those in decls_for_scope. Just within the `outer_scope' there will be
15541 a BLOCK node representing the function's outermost pair of curly braces,
15542 and any blocks used for the base and member initializers of a C++
15543 constructor function. */
15544 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
15546 /* Emit a DW_TAG_variable DIE for a named return value. */
15547 if (DECL_NAME (DECL_RESULT (decl)))
15548 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
15550 current_function_has_inlines = 0;
15551 decls_for_scope (outer_scope, subr_die, 0);
15553 #if 0 && defined (MIPS_DEBUGGING_INFO)
15554 if (current_function_has_inlines)
15556 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
15557 if (! comp_unit_has_inlines)
15559 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
15560 comp_unit_has_inlines = 1;
15565 /* Add the calling convention attribute if requested. */
15566 add_calling_convention_attribute (subr_die, decl);
15570 /* Returns a hash value for X (which really is a die_struct). */
15573 common_block_die_table_hash (const void *x)
15575 const_dw_die_ref d = (const_dw_die_ref) x;
15576 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
15579 /* Return nonzero if decl_id and die_parent of die_struct X is the same
15580 as decl_id and die_parent of die_struct Y. */
15583 common_block_die_table_eq (const void *x, const void *y)
15585 const_dw_die_ref d = (const_dw_die_ref) x;
15586 const_dw_die_ref e = (const_dw_die_ref) y;
15587 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
15590 /* Generate a DIE to represent a declared data object.
15591 Either DECL or ORIGIN must be non-null. */
15594 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
15598 tree decl_or_origin = decl ? decl : origin;
15599 dw_die_ref var_die;
15600 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
15601 dw_die_ref origin_die;
15602 int declaration = (DECL_EXTERNAL (decl_or_origin)
15603 /* If DECL is COMDAT and has not actually been
15604 emitted, we cannot take its address; there
15605 might end up being no definition anywhere in
15606 the program. For example, consider the C++
15610 struct S { static const int i = 7; };
15615 int f() { return S<int>::i; }
15617 Here, S<int>::i is not DECL_EXTERNAL, but no
15618 definition is required, so the compiler will
15619 not emit a definition. */
15620 || (TREE_CODE (decl_or_origin) == VAR_DECL
15621 && DECL_COMDAT (decl_or_origin)
15622 && !TREE_ASM_WRITTEN (decl_or_origin))
15623 || class_or_namespace_scope_p (context_die));
15626 origin = decl_ultimate_origin (decl);
15628 com_decl = fortran_common (decl_or_origin, &off);
15630 /* Symbol in common gets emitted as a child of the common block, in the form
15631 of a data member. */
15635 dw_die_ref com_die;
15636 dw_loc_descr_ref loc;
15637 die_node com_die_arg;
15639 var_die = lookup_decl_die (decl_or_origin);
15642 if (get_AT (var_die, DW_AT_location) == NULL)
15644 loc = loc_descriptor_from_tree (com_decl);
15649 /* Optimize the common case. */
15650 if (loc->dw_loc_opc == DW_OP_addr
15651 && loc->dw_loc_next == NULL
15652 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
15654 loc->dw_loc_oprnd1.v.val_addr
15655 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
15657 loc_descr_plus_const (&loc, off);
15659 add_AT_loc (var_die, DW_AT_location, loc);
15660 remove_AT (var_die, DW_AT_declaration);
15666 if (common_block_die_table == NULL)
15667 common_block_die_table
15668 = htab_create_ggc (10, common_block_die_table_hash,
15669 common_block_die_table_eq, NULL);
15671 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
15672 com_die_arg.decl_id = DECL_UID (com_decl);
15673 com_die_arg.die_parent = context_die;
15674 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
15675 loc = loc_descriptor_from_tree (com_decl);
15676 if (com_die == NULL)
15679 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
15682 com_die = new_die (DW_TAG_common_block, context_die, decl);
15683 add_name_and_src_coords_attributes (com_die, com_decl);
15686 add_AT_loc (com_die, DW_AT_location, loc);
15687 /* Avoid sharing the same loc descriptor between
15688 DW_TAG_common_block and DW_TAG_variable. */
15689 loc = loc_descriptor_from_tree (com_decl);
15691 else if (DECL_EXTERNAL (decl))
15692 add_AT_flag (com_die, DW_AT_declaration, 1);
15693 add_pubname_string (cnam, com_die); /* ??? needed? */
15694 com_die->decl_id = DECL_UID (com_decl);
15695 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
15696 *slot = (void *) com_die;
15698 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
15700 add_AT_loc (com_die, DW_AT_location, loc);
15701 loc = loc_descriptor_from_tree (com_decl);
15702 remove_AT (com_die, DW_AT_declaration);
15704 var_die = new_die (DW_TAG_variable, com_die, decl);
15705 add_name_and_src_coords_attributes (var_die, decl);
15706 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
15707 TREE_THIS_VOLATILE (decl), context_die);
15708 add_AT_flag (var_die, DW_AT_external, 1);
15713 /* Optimize the common case. */
15714 if (loc->dw_loc_opc == DW_OP_addr
15715 && loc->dw_loc_next == NULL
15716 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
15717 loc->dw_loc_oprnd1.v.val_addr
15718 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
15720 loc_descr_plus_const (&loc, off);
15722 add_AT_loc (var_die, DW_AT_location, loc);
15724 else if (DECL_EXTERNAL (decl))
15725 add_AT_flag (var_die, DW_AT_declaration, 1);
15726 equate_decl_number_to_die (decl, var_die);
15730 /* If the compiler emitted a definition for the DECL declaration
15731 and if we already emitted a DIE for it, don't emit a second
15732 DIE for it again. */
15735 && old_die->die_parent == context_die)
15738 /* For static data members, the declaration in the class is supposed
15739 to have DW_TAG_member tag; the specification should still be
15740 DW_TAG_variable referencing the DW_TAG_member DIE. */
15741 if (declaration && class_scope_p (context_die))
15742 var_die = new_die (DW_TAG_member, context_die, decl);
15744 var_die = new_die (DW_TAG_variable, context_die, decl);
15747 if (origin != NULL)
15748 origin_die = add_abstract_origin_attribute (var_die, origin);
15750 /* Loop unrolling can create multiple blocks that refer to the same
15751 static variable, so we must test for the DW_AT_declaration flag.
15753 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
15754 copy decls and set the DECL_ABSTRACT flag on them instead of
15757 ??? Duplicated blocks have been rewritten to use .debug_ranges.
15759 ??? The declare_in_namespace support causes us to get two DIEs for one
15760 variable, both of which are declarations. We want to avoid considering
15761 one to be a specification, so we must test that this DIE is not a
15763 else if (old_die && TREE_STATIC (decl) && ! declaration
15764 && get_AT_flag (old_die, DW_AT_declaration) == 1)
15766 /* This is a definition of a C++ class level static. */
15767 add_AT_specification (var_die, old_die);
15768 if (DECL_NAME (decl))
15770 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
15771 struct dwarf_file_data * file_index = lookup_filename (s.file);
15773 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
15774 add_AT_file (var_die, DW_AT_decl_file, file_index);
15776 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
15777 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
15782 tree type = TREE_TYPE (decl);
15784 add_name_and_src_coords_attributes (var_die, decl);
15785 if ((TREE_CODE (decl) == PARM_DECL
15786 || TREE_CODE (decl) == RESULT_DECL
15787 || TREE_CODE (decl) == VAR_DECL)
15788 && DECL_BY_REFERENCE (decl))
15789 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
15791 add_type_attribute (var_die, type, TREE_READONLY (decl),
15792 TREE_THIS_VOLATILE (decl), context_die);
15794 if (TREE_PUBLIC (decl))
15795 add_AT_flag (var_die, DW_AT_external, 1);
15797 if (DECL_ARTIFICIAL (decl))
15798 add_AT_flag (var_die, DW_AT_artificial, 1);
15800 if (TREE_PROTECTED (decl))
15801 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
15802 else if (TREE_PRIVATE (decl))
15803 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
15807 add_AT_flag (var_die, DW_AT_declaration, 1);
15809 if (decl && (DECL_ABSTRACT (decl) || declaration))
15810 equate_decl_number_to_die (decl, var_die);
15813 && (! DECL_ABSTRACT (decl_or_origin)
15814 /* Local static vars are shared between all clones/inlines,
15815 so emit DW_AT_location on the abstract DIE if DECL_RTL is
15817 || (TREE_CODE (decl_or_origin) == VAR_DECL
15818 && TREE_STATIC (decl_or_origin)
15819 && DECL_RTL_SET_P (decl_or_origin)))
15820 /* When abstract origin already has DW_AT_location attribute, no need
15821 to add it again. */
15822 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
15824 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
15825 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
15826 defer_location (decl_or_origin, var_die);
15828 add_location_or_const_value_attribute (var_die,
15831 add_pubname (decl_or_origin, var_die);
15834 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
15837 /* Generate a DIE to represent a named constant. */
15840 gen_const_die (tree decl, dw_die_ref context_die)
15842 dw_die_ref const_die;
15843 tree type = TREE_TYPE (decl);
15845 const_die = new_die (DW_TAG_constant, context_die, decl);
15846 add_name_and_src_coords_attributes (const_die, decl);
15847 add_type_attribute (const_die, type, 1, 0, context_die);
15848 if (TREE_PUBLIC (decl))
15849 add_AT_flag (const_die, DW_AT_external, 1);
15850 if (DECL_ARTIFICIAL (decl))
15851 add_AT_flag (const_die, DW_AT_artificial, 1);
15852 tree_add_const_value_attribute_for_decl (const_die, decl);
15855 /* Generate a DIE to represent a label identifier. */
15858 gen_label_die (tree decl, dw_die_ref context_die)
15860 tree origin = decl_ultimate_origin (decl);
15861 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
15863 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15865 if (origin != NULL)
15866 add_abstract_origin_attribute (lbl_die, origin);
15868 add_name_and_src_coords_attributes (lbl_die, decl);
15870 if (DECL_ABSTRACT (decl))
15871 equate_decl_number_to_die (decl, lbl_die);
15874 insn = DECL_RTL_IF_SET (decl);
15876 /* Deleted labels are programmer specified labels which have been
15877 eliminated because of various optimizations. We still emit them
15878 here so that it is possible to put breakpoints on them. */
15882 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
15884 /* When optimization is enabled (via -O) some parts of the compiler
15885 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
15886 represent source-level labels which were explicitly declared by
15887 the user. This really shouldn't be happening though, so catch
15888 it if it ever does happen. */
15889 gcc_assert (!INSN_DELETED_P (insn));
15891 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
15892 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
15897 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
15898 attributes to the DIE for a block STMT, to describe where the inlined
15899 function was called from. This is similar to add_src_coords_attributes. */
15902 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
15904 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
15906 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
15907 add_AT_unsigned (die, DW_AT_call_line, s.line);
15911 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
15912 Add low_pc and high_pc attributes to the DIE for a block STMT. */
15915 add_high_low_attributes (tree stmt, dw_die_ref die)
15917 char label[MAX_ARTIFICIAL_LABEL_BYTES];
15919 if (BLOCK_FRAGMENT_CHAIN (stmt))
15923 if (inlined_function_outer_scope_p (stmt))
15925 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
15926 BLOCK_NUMBER (stmt));
15927 add_AT_lbl_id (die, DW_AT_entry_pc, label);
15930 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
15932 chain = BLOCK_FRAGMENT_CHAIN (stmt);
15935 add_ranges (chain);
15936 chain = BLOCK_FRAGMENT_CHAIN (chain);
15943 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
15944 BLOCK_NUMBER (stmt));
15945 add_AT_lbl_id (die, DW_AT_low_pc, label);
15946 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
15947 BLOCK_NUMBER (stmt));
15948 add_AT_lbl_id (die, DW_AT_high_pc, label);
15952 /* Generate a DIE for a lexical block. */
15955 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
15957 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
15959 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
15960 add_high_low_attributes (stmt, stmt_die);
15962 decls_for_scope (stmt, stmt_die, depth);
15965 /* Generate a DIE for an inlined subprogram. */
15968 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
15972 /* The instance of function that is effectively being inlined shall not
15974 gcc_assert (! BLOCK_ABSTRACT (stmt));
15976 decl = block_ultimate_origin (stmt);
15978 /* Emit info for the abstract instance first, if we haven't yet. We
15979 must emit this even if the block is abstract, otherwise when we
15980 emit the block below (or elsewhere), we may end up trying to emit
15981 a die whose origin die hasn't been emitted, and crashing. */
15982 dwarf2out_abstract_function (decl);
15984 if (! BLOCK_ABSTRACT (stmt))
15986 dw_die_ref subr_die
15987 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
15989 add_abstract_origin_attribute (subr_die, decl);
15990 if (TREE_ASM_WRITTEN (stmt))
15991 add_high_low_attributes (stmt, subr_die);
15992 add_call_src_coords_attributes (stmt, subr_die);
15994 decls_for_scope (stmt, subr_die, depth);
15995 current_function_has_inlines = 1;
15999 /* Generate a DIE for a field in a record, or structure. */
16002 gen_field_die (tree decl, dw_die_ref context_die)
16004 dw_die_ref decl_die;
16006 if (TREE_TYPE (decl) == error_mark_node)
16009 decl_die = new_die (DW_TAG_member, context_die, decl);
16010 add_name_and_src_coords_attributes (decl_die, decl);
16011 add_type_attribute (decl_die, member_declared_type (decl),
16012 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
16015 if (DECL_BIT_FIELD_TYPE (decl))
16017 add_byte_size_attribute (decl_die, decl);
16018 add_bit_size_attribute (decl_die, decl);
16019 add_bit_offset_attribute (decl_die, decl);
16022 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
16023 add_data_member_location_attribute (decl_die, decl);
16025 if (DECL_ARTIFICIAL (decl))
16026 add_AT_flag (decl_die, DW_AT_artificial, 1);
16028 if (TREE_PROTECTED (decl))
16029 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
16030 else if (TREE_PRIVATE (decl))
16031 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
16033 /* Equate decl number to die, so that we can look up this decl later on. */
16034 equate_decl_number_to_die (decl, decl_die);
16038 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16039 Use modified_type_die instead.
16040 We keep this code here just in case these types of DIEs may be needed to
16041 represent certain things in other languages (e.g. Pascal) someday. */
16044 gen_pointer_type_die (tree type, dw_die_ref context_die)
16047 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
16049 equate_type_number_to_die (type, ptr_die);
16050 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16051 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16054 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
16055 Use modified_type_die instead.
16056 We keep this code here just in case these types of DIEs may be needed to
16057 represent certain things in other languages (e.g. Pascal) someday. */
16060 gen_reference_type_die (tree type, dw_die_ref context_die)
16063 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
16065 equate_type_number_to_die (type, ref_die);
16066 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
16067 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
16071 /* Generate a DIE for a pointer to a member type. */
16074 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
16077 = new_die (DW_TAG_ptr_to_member_type,
16078 scope_die_for (type, context_die), type);
16080 equate_type_number_to_die (type, ptr_die);
16081 add_AT_die_ref (ptr_die, DW_AT_containing_type,
16082 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
16083 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
16086 /* Generate the DIE for the compilation unit. */
16089 gen_compile_unit_die (const char *filename)
16092 char producer[250];
16093 const char *language_string = lang_hooks.name;
16096 die = new_die (DW_TAG_compile_unit, NULL, NULL);
16100 add_name_attribute (die, filename);
16101 /* Don't add cwd for <built-in>. */
16102 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
16103 add_comp_dir_attribute (die);
16106 sprintf (producer, "%s %s", language_string, version_string);
16108 #ifdef MIPS_DEBUGGING_INFO
16109 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
16110 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
16111 not appear in the producer string, the debugger reaches the conclusion
16112 that the object file is stripped and has no debugging information.
16113 To get the MIPS/SGI debugger to believe that there is debugging
16114 information in the object file, we add a -g to the producer string. */
16115 if (debug_info_level > DINFO_LEVEL_TERSE)
16116 strcat (producer, " -g");
16119 add_AT_string (die, DW_AT_producer, producer);
16121 if (strcmp (language_string, "GNU C++") == 0)
16122 language = DW_LANG_C_plus_plus;
16123 else if (strcmp (language_string, "GNU Ada") == 0)
16124 language = DW_LANG_Ada95;
16125 else if (strcmp (language_string, "GNU F77") == 0)
16126 language = DW_LANG_Fortran77;
16127 else if (strcmp (language_string, "GNU Fortran") == 0)
16128 language = DW_LANG_Fortran95;
16129 else if (strcmp (language_string, "GNU Pascal") == 0)
16130 language = DW_LANG_Pascal83;
16131 else if (strcmp (language_string, "GNU Java") == 0)
16132 language = DW_LANG_Java;
16133 else if (strcmp (language_string, "GNU Objective-C") == 0)
16134 language = DW_LANG_ObjC;
16135 else if (strcmp (language_string, "GNU Objective-C++") == 0)
16136 language = DW_LANG_ObjC_plus_plus;
16138 language = DW_LANG_C89;
16140 add_AT_unsigned (die, DW_AT_language, language);
16144 /* Generate the DIE for a base class. */
16147 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
16149 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
16151 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
16152 add_data_member_location_attribute (die, binfo);
16154 if (BINFO_VIRTUAL_P (binfo))
16155 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
16157 if (access == access_public_node)
16158 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16159 else if (access == access_protected_node)
16160 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16163 /* Generate a DIE for a class member. */
16166 gen_member_die (tree type, dw_die_ref context_die)
16169 tree binfo = TYPE_BINFO (type);
16172 /* If this is not an incomplete type, output descriptions of each of its
16173 members. Note that as we output the DIEs necessary to represent the
16174 members of this record or union type, we will also be trying to output
16175 DIEs to represent the *types* of those members. However the `type'
16176 function (above) will specifically avoid generating type DIEs for member
16177 types *within* the list of member DIEs for this (containing) type except
16178 for those types (of members) which are explicitly marked as also being
16179 members of this (containing) type themselves. The g++ front- end can
16180 force any given type to be treated as a member of some other (containing)
16181 type by setting the TYPE_CONTEXT of the given (member) type to point to
16182 the TREE node representing the appropriate (containing) type. */
16184 /* First output info about the base classes. */
16187 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
16191 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
16192 gen_inheritance_die (base,
16193 (accesses ? VEC_index (tree, accesses, i)
16194 : access_public_node), context_die);
16197 /* Now output info about the data members and type members. */
16198 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
16200 /* If we thought we were generating minimal debug info for TYPE
16201 and then changed our minds, some of the member declarations
16202 may have already been defined. Don't define them again, but
16203 do put them in the right order. */
16205 child = lookup_decl_die (member);
16207 splice_child_die (context_die, child);
16209 gen_decl_die (member, NULL, context_die);
16212 /* Now output info about the function members (if any). */
16213 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
16215 /* Don't include clones in the member list. */
16216 if (DECL_ABSTRACT_ORIGIN (member))
16219 child = lookup_decl_die (member);
16221 splice_child_die (context_die, child);
16223 gen_decl_die (member, NULL, context_die);
16227 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
16228 is set, we pretend that the type was never defined, so we only get the
16229 member DIEs needed by later specification DIEs. */
16232 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
16233 enum debug_info_usage usage)
16235 dw_die_ref type_die = lookup_type_die (type);
16236 dw_die_ref scope_die = 0;
16238 int complete = (TYPE_SIZE (type)
16239 && (! TYPE_STUB_DECL (type)
16240 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
16241 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
16242 complete = complete && should_emit_struct_debug (type, usage);
16244 if (type_die && ! complete)
16247 if (TYPE_CONTEXT (type) != NULL_TREE
16248 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
16249 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
16252 scope_die = scope_die_for (type, context_die);
16254 if (! type_die || (nested && scope_die == comp_unit_die))
16255 /* First occurrence of type or toplevel definition of nested class. */
16257 dw_die_ref old_die = type_die;
16259 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
16260 ? record_type_tag (type) : DW_TAG_union_type,
16262 equate_type_number_to_die (type, type_die);
16264 add_AT_specification (type_die, old_die);
16266 add_name_attribute (type_die, type_tag (type));
16269 remove_AT (type_die, DW_AT_declaration);
16271 /* Generate child dies for template paramaters. */
16272 if (debug_info_level > DINFO_LEVEL_TERSE
16273 && COMPLETE_TYPE_P (type))
16274 gen_generic_params_dies (type);
16276 /* If this type has been completed, then give it a byte_size attribute and
16277 then give a list of members. */
16278 if (complete && !ns_decl)
16280 /* Prevent infinite recursion in cases where the type of some member of
16281 this type is expressed in terms of this type itself. */
16282 TREE_ASM_WRITTEN (type) = 1;
16283 add_byte_size_attribute (type_die, type);
16284 if (TYPE_STUB_DECL (type) != NULL_TREE)
16285 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
16287 /* If the first reference to this type was as the return type of an
16288 inline function, then it may not have a parent. Fix this now. */
16289 if (type_die->die_parent == NULL)
16290 add_child_die (scope_die, type_die);
16292 push_decl_scope (type);
16293 gen_member_die (type, type_die);
16296 /* GNU extension: Record what type our vtable lives in. */
16297 if (TYPE_VFIELD (type))
16299 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
16301 gen_type_die (vtype, context_die);
16302 add_AT_die_ref (type_die, DW_AT_containing_type,
16303 lookup_type_die (vtype));
16308 add_AT_flag (type_die, DW_AT_declaration, 1);
16310 /* We don't need to do this for function-local types. */
16311 if (TYPE_STUB_DECL (type)
16312 && ! decl_function_context (TYPE_STUB_DECL (type)))
16313 VEC_safe_push (tree, gc, incomplete_types, type);
16316 if (get_AT (type_die, DW_AT_name))
16317 add_pubtype (type, type_die);
16320 /* Generate a DIE for a subroutine _type_. */
16323 gen_subroutine_type_die (tree type, dw_die_ref context_die)
16325 tree return_type = TREE_TYPE (type);
16326 dw_die_ref subr_die
16327 = new_die (DW_TAG_subroutine_type,
16328 scope_die_for (type, context_die), type);
16330 equate_type_number_to_die (type, subr_die);
16331 add_prototyped_attribute (subr_die, type);
16332 add_type_attribute (subr_die, return_type, 0, 0, context_die);
16333 gen_formal_types_die (type, subr_die);
16335 if (get_AT (subr_die, DW_AT_name))
16336 add_pubtype (type, subr_die);
16339 /* Generate a DIE for a type definition. */
16342 gen_typedef_die (tree decl, dw_die_ref context_die)
16344 dw_die_ref type_die;
16347 if (TREE_ASM_WRITTEN (decl))
16350 TREE_ASM_WRITTEN (decl) = 1;
16351 type_die = new_die (DW_TAG_typedef, context_die, decl);
16352 origin = decl_ultimate_origin (decl);
16353 if (origin != NULL)
16354 add_abstract_origin_attribute (type_die, origin);
16359 add_name_and_src_coords_attributes (type_die, decl);
16360 if (DECL_ORIGINAL_TYPE (decl))
16362 type = DECL_ORIGINAL_TYPE (decl);
16364 gcc_assert (type != TREE_TYPE (decl));
16365 equate_type_number_to_die (TREE_TYPE (decl), type_die);
16368 type = TREE_TYPE (decl);
16370 add_type_attribute (type_die, type, TREE_READONLY (decl),
16371 TREE_THIS_VOLATILE (decl), context_die);
16374 if (DECL_ABSTRACT (decl))
16375 equate_decl_number_to_die (decl, type_die);
16377 if (get_AT (type_die, DW_AT_name))
16378 add_pubtype (decl, type_die);
16381 /* Generate a type description DIE. */
16384 gen_type_die_with_usage (tree type, dw_die_ref context_die,
16385 enum debug_info_usage usage)
16388 struct array_descr_info info;
16390 if (type == NULL_TREE || type == error_mark_node)
16393 /* If TYPE is a typedef type variant, let's generate debug info
16394 for the parent typedef which TYPE is a type of. */
16395 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16396 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
16398 if (TREE_ASM_WRITTEN (type))
16401 /* Prevent broken recursion; we can't hand off to the same type. */
16402 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
16404 /* Use the DIE of the containing namespace as the parent DIE of
16405 the type description DIE we want to generate. */
16406 if (DECL_CONTEXT (TYPE_NAME (type))
16407 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
16408 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
16410 TREE_ASM_WRITTEN (type) = 1;
16411 gen_decl_die (TYPE_NAME (type), NULL, context_die);
16415 /* If this is an array type with hidden descriptor, handle it first. */
16416 if (!TREE_ASM_WRITTEN (type)
16417 && lang_hooks.types.get_array_descr_info
16418 && lang_hooks.types.get_array_descr_info (type, &info))
16420 gen_descr_array_type_die (type, &info, context_die);
16421 TREE_ASM_WRITTEN (type) = 1;
16425 /* We are going to output a DIE to represent the unqualified version
16426 of this type (i.e. without any const or volatile qualifiers) so
16427 get the main variant (i.e. the unqualified version) of this type
16428 now. (Vectors are special because the debugging info is in the
16429 cloned type itself). */
16430 if (TREE_CODE (type) != VECTOR_TYPE)
16431 type = type_main_variant (type);
16433 if (TREE_ASM_WRITTEN (type))
16436 switch (TREE_CODE (type))
16442 case REFERENCE_TYPE:
16443 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
16444 ensures that the gen_type_die recursion will terminate even if the
16445 type is recursive. Recursive types are possible in Ada. */
16446 /* ??? We could perhaps do this for all types before the switch
16448 TREE_ASM_WRITTEN (type) = 1;
16450 /* For these types, all that is required is that we output a DIE (or a
16451 set of DIEs) to represent the "basis" type. */
16452 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16453 DINFO_USAGE_IND_USE);
16457 /* This code is used for C++ pointer-to-data-member types.
16458 Output a description of the relevant class type. */
16459 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
16460 DINFO_USAGE_IND_USE);
16462 /* Output a description of the type of the object pointed to. */
16463 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16464 DINFO_USAGE_IND_USE);
16466 /* Now output a DIE to represent this pointer-to-data-member type
16468 gen_ptr_to_mbr_type_die (type, context_die);
16471 case FUNCTION_TYPE:
16472 /* Force out return type (in case it wasn't forced out already). */
16473 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16474 DINFO_USAGE_DIR_USE);
16475 gen_subroutine_type_die (type, context_die);
16479 /* Force out return type (in case it wasn't forced out already). */
16480 gen_type_die_with_usage (TREE_TYPE (type), context_die,
16481 DINFO_USAGE_DIR_USE);
16482 gen_subroutine_type_die (type, context_die);
16486 gen_array_type_die (type, context_die);
16490 gen_array_type_die (type, context_die);
16493 case ENUMERAL_TYPE:
16496 case QUAL_UNION_TYPE:
16497 /* If this is a nested type whose containing class hasn't been written
16498 out yet, writing it out will cover this one, too. This does not apply
16499 to instantiations of member class templates; they need to be added to
16500 the containing class as they are generated. FIXME: This hurts the
16501 idea of combining type decls from multiple TUs, since we can't predict
16502 what set of template instantiations we'll get. */
16503 if (TYPE_CONTEXT (type)
16504 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
16505 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
16507 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
16509 if (TREE_ASM_WRITTEN (type))
16512 /* If that failed, attach ourselves to the stub. */
16513 push_decl_scope (TYPE_CONTEXT (type));
16514 context_die = lookup_type_die (TYPE_CONTEXT (type));
16517 else if (TYPE_CONTEXT (type) != NULL_TREE
16518 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
16520 /* If this type is local to a function that hasn't been written
16521 out yet, use a NULL context for now; it will be fixed up in
16522 decls_for_scope. */
16523 context_die = lookup_decl_die (TYPE_CONTEXT (type));
16528 context_die = declare_in_namespace (type, context_die);
16532 if (TREE_CODE (type) == ENUMERAL_TYPE)
16534 /* This might have been written out by the call to
16535 declare_in_namespace. */
16536 if (!TREE_ASM_WRITTEN (type))
16537 gen_enumeration_type_die (type, context_die);
16540 gen_struct_or_union_type_die (type, context_die, usage);
16545 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
16546 it up if it is ever completed. gen_*_type_die will set it for us
16547 when appropriate. */
16553 case FIXED_POINT_TYPE:
16556 /* No DIEs needed for fundamental types. */
16560 /* No Dwarf representation currently defined. */
16564 gcc_unreachable ();
16567 TREE_ASM_WRITTEN (type) = 1;
16571 gen_type_die (tree type, dw_die_ref context_die)
16573 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
16576 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
16577 things which are local to the given block. */
16580 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
16582 int must_output_die = 0;
16585 /* Ignore blocks that are NULL. */
16586 if (stmt == NULL_TREE)
16589 inlined_func = inlined_function_outer_scope_p (stmt);
16591 /* If the block is one fragment of a non-contiguous block, do not
16592 process the variables, since they will have been done by the
16593 origin block. Do process subblocks. */
16594 if (BLOCK_FRAGMENT_ORIGIN (stmt))
16598 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
16599 gen_block_die (sub, context_die, depth + 1);
16604 /* Determine if we need to output any Dwarf DIEs at all to represent this
16607 /* The outer scopes for inlinings *must* always be represented. We
16608 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
16609 must_output_die = 1;
16612 /* Determine if this block directly contains any "significant"
16613 local declarations which we will need to output DIEs for. */
16614 if (debug_info_level > DINFO_LEVEL_TERSE)
16615 /* We are not in terse mode so *any* local declaration counts
16616 as being a "significant" one. */
16617 must_output_die = ((BLOCK_VARS (stmt) != NULL
16618 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
16619 && (TREE_USED (stmt)
16620 || TREE_ASM_WRITTEN (stmt)
16621 || BLOCK_ABSTRACT (stmt)));
16622 else if ((TREE_USED (stmt)
16623 || TREE_ASM_WRITTEN (stmt)
16624 || BLOCK_ABSTRACT (stmt))
16625 && !dwarf2out_ignore_block (stmt))
16626 must_output_die = 1;
16629 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
16630 DIE for any block which contains no significant local declarations at
16631 all. Rather, in such cases we just call `decls_for_scope' so that any
16632 needed Dwarf info for any sub-blocks will get properly generated. Note
16633 that in terse mode, our definition of what constitutes a "significant"
16634 local declaration gets restricted to include only inlined function
16635 instances and local (nested) function definitions. */
16636 if (must_output_die)
16640 /* If STMT block is abstract, that means we have been called
16641 indirectly from dwarf2out_abstract_function.
16642 That function rightfully marks the descendent blocks (of
16643 the abstract function it is dealing with) as being abstract,
16644 precisely to prevent us from emitting any
16645 DW_TAG_inlined_subroutine DIE as a descendent
16646 of an abstract function instance. So in that case, we should
16647 not call gen_inlined_subroutine_die.
16649 Later though, when cgraph asks dwarf2out to emit info
16650 for the concrete instance of the function decl into which
16651 the concrete instance of STMT got inlined, the later will lead
16652 to the generation of a DW_TAG_inlined_subroutine DIE. */
16653 if (! BLOCK_ABSTRACT (stmt))
16654 gen_inlined_subroutine_die (stmt, context_die, depth);
16657 gen_lexical_block_die (stmt, context_die, depth);
16660 decls_for_scope (stmt, context_die, depth);
16663 /* Process variable DECL (or variable with origin ORIGIN) within
16664 block STMT and add it to CONTEXT_DIE. */
16666 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
16669 tree decl_or_origin = decl ? decl : origin;
16670 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
16672 if (ultimate_origin)
16673 origin = ultimate_origin;
16675 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
16676 die = lookup_decl_die (decl_or_origin);
16677 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
16678 && TYPE_DECL_IS_STUB (decl_or_origin))
16679 die = lookup_type_die (TREE_TYPE (decl_or_origin));
16683 if (die != NULL && die->die_parent == NULL)
16684 add_child_die (context_die, die);
16685 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
16686 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
16687 stmt, context_die);
16689 gen_decl_die (decl, origin, context_die);
16692 /* Generate all of the decls declared within a given scope and (recursively)
16693 all of its sub-blocks. */
16696 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
16702 /* Ignore NULL blocks. */
16703 if (stmt == NULL_TREE)
16706 /* Output the DIEs to represent all of the data objects and typedefs
16707 declared directly within this block but not within any nested
16708 sub-blocks. Also, nested function and tag DIEs have been
16709 generated with a parent of NULL; fix that up now. */
16710 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
16711 process_scope_var (stmt, decl, NULL_TREE, context_die);
16712 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
16713 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
16716 /* If we're at -g1, we're not interested in subblocks. */
16717 if (debug_info_level <= DINFO_LEVEL_TERSE)
16720 /* Output the DIEs to represent all sub-blocks (and the items declared
16721 therein) of this block. */
16722 for (subblocks = BLOCK_SUBBLOCKS (stmt);
16724 subblocks = BLOCK_CHAIN (subblocks))
16725 gen_block_die (subblocks, context_die, depth + 1);
16728 /* Is this a typedef we can avoid emitting? */
16731 is_redundant_typedef (const_tree decl)
16733 if (TYPE_DECL_IS_STUB (decl))
16736 if (DECL_ARTIFICIAL (decl)
16737 && DECL_CONTEXT (decl)
16738 && is_tagged_type (DECL_CONTEXT (decl))
16739 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
16740 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
16741 /* Also ignore the artificial member typedef for the class name. */
16747 /* Returns the DIE for a context. */
16749 static inline dw_die_ref
16750 get_context_die (tree context)
16754 /* Find die that represents this context. */
16755 if (TYPE_P (context))
16756 return force_type_die (context);
16758 return force_decl_die (context);
16760 return comp_unit_die;
16763 /* Returns the DIE for decl. A DIE will always be returned. */
16766 force_decl_die (tree decl)
16768 dw_die_ref decl_die;
16769 unsigned saved_external_flag;
16770 tree save_fn = NULL_TREE;
16771 decl_die = lookup_decl_die (decl);
16774 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
16776 decl_die = lookup_decl_die (decl);
16780 switch (TREE_CODE (decl))
16782 case FUNCTION_DECL:
16783 /* Clear current_function_decl, so that gen_subprogram_die thinks
16784 that this is a declaration. At this point, we just want to force
16785 declaration die. */
16786 save_fn = current_function_decl;
16787 current_function_decl = NULL_TREE;
16788 gen_subprogram_die (decl, context_die);
16789 current_function_decl = save_fn;
16793 /* Set external flag to force declaration die. Restore it after
16794 gen_decl_die() call. */
16795 saved_external_flag = DECL_EXTERNAL (decl);
16796 DECL_EXTERNAL (decl) = 1;
16797 gen_decl_die (decl, NULL, context_die);
16798 DECL_EXTERNAL (decl) = saved_external_flag;
16801 case NAMESPACE_DECL:
16802 dwarf2out_decl (decl);
16806 gcc_unreachable ();
16809 /* We should be able to find the DIE now. */
16811 decl_die = lookup_decl_die (decl);
16812 gcc_assert (decl_die);
16818 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
16819 always returned. */
16822 force_type_die (tree type)
16824 dw_die_ref type_die;
16826 type_die = lookup_type_die (type);
16829 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
16831 type_die = modified_type_die (type, TYPE_READONLY (type),
16832 TYPE_VOLATILE (type), context_die);
16833 gcc_assert (type_die);
16838 /* Force out any required namespaces to be able to output DECL,
16839 and return the new context_die for it, if it's changed. */
16842 setup_namespace_context (tree thing, dw_die_ref context_die)
16844 tree context = (DECL_P (thing)
16845 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
16846 if (context && TREE_CODE (context) == NAMESPACE_DECL)
16847 /* Force out the namespace. */
16848 context_die = force_decl_die (context);
16850 return context_die;
16853 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
16854 type) within its namespace, if appropriate.
16856 For compatibility with older debuggers, namespace DIEs only contain
16857 declarations; all definitions are emitted at CU scope. */
16860 declare_in_namespace (tree thing, dw_die_ref context_die)
16862 dw_die_ref ns_context;
16864 if (debug_info_level <= DINFO_LEVEL_TERSE)
16865 return context_die;
16867 /* If this decl is from an inlined function, then don't try to emit it in its
16868 namespace, as we will get confused. It would have already been emitted
16869 when the abstract instance of the inline function was emitted anyways. */
16870 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
16871 return context_die;
16873 ns_context = setup_namespace_context (thing, context_die);
16875 if (ns_context != context_die)
16879 if (DECL_P (thing))
16880 gen_decl_die (thing, NULL, ns_context);
16882 gen_type_die (thing, ns_context);
16884 return context_die;
16887 /* Generate a DIE for a namespace or namespace alias. */
16890 gen_namespace_die (tree decl, dw_die_ref context_die)
16892 dw_die_ref namespace_die;
16894 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
16895 they are an alias of. */
16896 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
16898 /* Output a real namespace or module. */
16899 context_die = setup_namespace_context (decl, comp_unit_die);
16900 namespace_die = new_die (is_fortran ()
16901 ? DW_TAG_module : DW_TAG_namespace,
16902 context_die, decl);
16903 /* For Fortran modules defined in different CU don't add src coords. */
16904 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
16905 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
16907 add_name_and_src_coords_attributes (namespace_die, decl);
16908 if (DECL_EXTERNAL (decl))
16909 add_AT_flag (namespace_die, DW_AT_declaration, 1);
16910 equate_decl_number_to_die (decl, namespace_die);
16914 /* Output a namespace alias. */
16916 /* Force out the namespace we are an alias of, if necessary. */
16917 dw_die_ref origin_die
16918 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
16920 if (DECL_CONTEXT (decl) == NULL_TREE
16921 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
16922 context_die = setup_namespace_context (decl, comp_unit_die);
16923 /* Now create the namespace alias DIE. */
16924 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
16925 add_name_and_src_coords_attributes (namespace_die, decl);
16926 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
16927 equate_decl_number_to_die (decl, namespace_die);
16931 /* Generate Dwarf debug information for a decl described by DECL. */
16934 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
16936 tree decl_or_origin = decl ? decl : origin;
16937 tree class_origin = NULL;
16939 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
16942 switch (TREE_CODE (decl_or_origin))
16948 if (!is_fortran ())
16950 /* The individual enumerators of an enum type get output when we output
16951 the Dwarf representation of the relevant enum type itself. */
16955 /* Emit its type. */
16956 gen_type_die (TREE_TYPE (decl), context_die);
16958 /* And its containing namespace. */
16959 context_die = declare_in_namespace (decl, context_die);
16961 gen_const_die (decl, context_die);
16964 case FUNCTION_DECL:
16965 /* Don't output any DIEs to represent mere function declarations,
16966 unless they are class members or explicit block externs. */
16967 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
16968 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
16969 && (current_function_decl == NULL_TREE
16970 || DECL_ARTIFICIAL (decl_or_origin)))
16975 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
16976 on local redeclarations of global functions. That seems broken. */
16977 if (current_function_decl != decl)
16978 /* This is only a declaration. */;
16981 /* If we're emitting a clone, emit info for the abstract instance. */
16982 if (origin || DECL_ORIGIN (decl) != decl)
16983 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
16985 /* If we're emitting an out-of-line copy of an inline function,
16986 emit info for the abstract instance and set up to refer to it. */
16987 else if (cgraph_function_possibly_inlined_p (decl)
16988 && ! DECL_ABSTRACT (decl)
16989 && ! class_or_namespace_scope_p (context_die)
16990 /* dwarf2out_abstract_function won't emit a die if this is just
16991 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
16992 that case, because that works only if we have a die. */
16993 && DECL_INITIAL (decl) != NULL_TREE)
16995 dwarf2out_abstract_function (decl);
16996 set_decl_origin_self (decl);
16999 /* Otherwise we're emitting the primary DIE for this decl. */
17000 else if (debug_info_level > DINFO_LEVEL_TERSE)
17002 /* Before we describe the FUNCTION_DECL itself, make sure that we
17003 have described its return type. */
17004 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
17006 /* And its virtual context. */
17007 if (DECL_VINDEX (decl) != NULL_TREE)
17008 gen_type_die (DECL_CONTEXT (decl), context_die);
17010 /* And its containing type. */
17012 origin = decl_class_context (decl);
17013 if (origin != NULL_TREE)
17014 gen_type_die_for_member (origin, decl, context_die);
17016 /* And its containing namespace. */
17017 context_die = declare_in_namespace (decl, context_die);
17020 /* Now output a DIE to represent the function itself. */
17022 gen_subprogram_die (decl, context_die);
17026 /* If we are in terse mode, don't generate any DIEs to represent any
17027 actual typedefs. */
17028 if (debug_info_level <= DINFO_LEVEL_TERSE)
17031 /* In the special case of a TYPE_DECL node representing the declaration
17032 of some type tag, if the given TYPE_DECL is marked as having been
17033 instantiated from some other (original) TYPE_DECL node (e.g. one which
17034 was generated within the original definition of an inline function) we
17035 used to generate a special (abbreviated) DW_TAG_structure_type,
17036 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
17037 should be actually referencing those DIEs, as variable DIEs with that
17038 type would be emitted already in the abstract origin, so it was always
17039 removed during unused type prunning. Don't add anything in this
17041 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
17044 if (is_redundant_typedef (decl))
17045 gen_type_die (TREE_TYPE (decl), context_die);
17047 /* Output a DIE to represent the typedef itself. */
17048 gen_typedef_die (decl, context_die);
17052 if (debug_info_level >= DINFO_LEVEL_NORMAL)
17053 gen_label_die (decl, context_die);
17058 /* If we are in terse mode, don't generate any DIEs to represent any
17059 variable declarations or definitions. */
17060 if (debug_info_level <= DINFO_LEVEL_TERSE)
17063 /* Output any DIEs that are needed to specify the type of this data
17065 if ((TREE_CODE (decl_or_origin) == RESULT_DECL
17066 || TREE_CODE (decl_or_origin) == VAR_DECL)
17067 && DECL_BY_REFERENCE (decl_or_origin))
17068 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17070 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17072 /* And its containing type. */
17073 class_origin = decl_class_context (decl_or_origin);
17074 if (class_origin != NULL_TREE)
17075 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
17077 /* And its containing namespace. */
17078 context_die = declare_in_namespace (decl_or_origin, context_die);
17080 /* Now output the DIE to represent the data object itself. This gets
17081 complicated because of the possibility that the VAR_DECL really
17082 represents an inlined instance of a formal parameter for an inline
17085 origin = decl_ultimate_origin (decl);
17086 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
17087 gen_formal_parameter_die (decl, origin, context_die);
17089 gen_variable_die (decl, origin, context_die);
17093 /* Ignore the nameless fields that are used to skip bits but handle C++
17094 anonymous unions and structs. */
17095 if (DECL_NAME (decl) != NULL_TREE
17096 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
17097 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
17099 gen_type_die (member_declared_type (decl), context_die);
17100 gen_field_die (decl, context_die);
17105 if (DECL_BY_REFERENCE (decl_or_origin))
17106 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
17108 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
17109 gen_formal_parameter_die (decl, origin, context_die);
17112 case NAMESPACE_DECL:
17113 case IMPORTED_DECL:
17114 gen_namespace_die (decl, context_die);
17118 /* Probably some frontend-internal decl. Assume we don't care. */
17119 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
17124 /* Output debug information for global decl DECL. Called from toplev.c after
17125 compilation proper has finished. */
17128 dwarf2out_global_decl (tree decl)
17130 /* Output DWARF2 information for file-scope tentative data object
17131 declarations, file-scope (extern) function declarations (which
17132 had no corresponding body) and file-scope tagged type declarations
17133 and definitions which have not yet been forced out. */
17134 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
17135 dwarf2out_decl (decl);
17138 /* Output debug information for type decl DECL. Called from toplev.c
17139 and from language front ends (to record built-in types). */
17141 dwarf2out_type_decl (tree decl, int local)
17144 dwarf2out_decl (decl);
17147 /* Output debug information for imported module or decl DECL.
17148 NAME is non-NULL name in the lexical block if the decl has been renamed.
17149 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
17150 that DECL belongs to.
17151 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
17153 dwarf2out_imported_module_or_decl_1 (tree decl,
17155 tree lexical_block,
17156 dw_die_ref lexical_block_die)
17158 expanded_location xloc;
17159 dw_die_ref imported_die = NULL;
17160 dw_die_ref at_import_die;
17162 if (TREE_CODE (decl) == IMPORTED_DECL)
17164 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
17165 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
17169 xloc = expand_location (input_location);
17171 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
17173 if (is_base_type (TREE_TYPE (decl)))
17174 at_import_die = base_type_die (TREE_TYPE (decl));
17176 at_import_die = force_type_die (TREE_TYPE (decl));
17177 /* For namespace N { typedef void T; } using N::T; base_type_die
17178 returns NULL, but DW_TAG_imported_declaration requires
17179 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
17180 if (!at_import_die)
17182 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
17183 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
17184 at_import_die = lookup_type_die (TREE_TYPE (decl));
17185 gcc_assert (at_import_die);
17190 at_import_die = lookup_decl_die (decl);
17191 if (!at_import_die)
17193 /* If we're trying to avoid duplicate debug info, we may not have
17194 emitted the member decl for this field. Emit it now. */
17195 if (TREE_CODE (decl) == FIELD_DECL)
17197 tree type = DECL_CONTEXT (decl);
17199 if (TYPE_CONTEXT (type)
17200 && TYPE_P (TYPE_CONTEXT (type))
17201 && !should_emit_struct_debug (TYPE_CONTEXT (type),
17202 DINFO_USAGE_DIR_USE))
17204 gen_type_die_for_member (type, decl,
17205 get_context_die (TYPE_CONTEXT (type)));
17207 at_import_die = force_decl_die (decl);
17211 if (TREE_CODE (decl) == NAMESPACE_DECL)
17212 imported_die = new_die (DW_TAG_imported_module,
17216 imported_die = new_die (DW_TAG_imported_declaration,
17220 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
17221 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
17223 add_AT_string (imported_die, DW_AT_name,
17224 IDENTIFIER_POINTER (name));
17225 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
17228 /* Output debug information for imported module or decl DECL.
17229 NAME is non-NULL name in context if the decl has been renamed.
17230 CHILD is true if decl is one of the renamed decls as part of
17231 importing whole module. */
17234 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
17237 /* dw_die_ref at_import_die; */
17238 dw_die_ref scope_die;
17240 if (debug_info_level <= DINFO_LEVEL_TERSE)
17245 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
17246 We need decl DIE for reference and scope die. First, get DIE for the decl
17249 /* Get the scope die for decl context. Use comp_unit_die for global module
17250 or decl. If die is not found for non globals, force new die. */
17252 && TYPE_P (context)
17253 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
17255 scope_die = get_context_die (context);
17259 gcc_assert (scope_die->die_child);
17260 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
17261 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
17262 scope_die = scope_die->die_child;
17265 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
17266 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
17270 /* Write the debugging output for DECL. */
17273 dwarf2out_decl (tree decl)
17275 dw_die_ref context_die = comp_unit_die;
17277 switch (TREE_CODE (decl))
17282 case FUNCTION_DECL:
17283 /* What we would really like to do here is to filter out all mere
17284 file-scope declarations of file-scope functions which are never
17285 referenced later within this translation unit (and keep all of ones
17286 that *are* referenced later on) but we aren't clairvoyant, so we have
17287 no idea which functions will be referenced in the future (i.e. later
17288 on within the current translation unit). So here we just ignore all
17289 file-scope function declarations which are not also definitions. If
17290 and when the debugger needs to know something about these functions,
17291 it will have to hunt around and find the DWARF information associated
17292 with the definition of the function.
17294 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
17295 nodes represent definitions and which ones represent mere
17296 declarations. We have to check DECL_INITIAL instead. That's because
17297 the C front-end supports some weird semantics for "extern inline"
17298 function definitions. These can get inlined within the current
17299 translation unit (and thus, we need to generate Dwarf info for their
17300 abstract instances so that the Dwarf info for the concrete inlined
17301 instances can have something to refer to) but the compiler never
17302 generates any out-of-lines instances of such things (despite the fact
17303 that they *are* definitions).
17305 The important point is that the C front-end marks these "extern
17306 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
17307 them anyway. Note that the C++ front-end also plays some similar games
17308 for inline function definitions appearing within include files which
17309 also contain `#pragma interface' pragmas. */
17310 if (DECL_INITIAL (decl) == NULL_TREE)
17313 /* If we're a nested function, initially use a parent of NULL; if we're
17314 a plain function, this will be fixed up in decls_for_scope. If
17315 we're a method, it will be ignored, since we already have a DIE. */
17316 if (decl_function_context (decl)
17317 /* But if we're in terse mode, we don't care about scope. */
17318 && debug_info_level > DINFO_LEVEL_TERSE)
17319 context_die = NULL;
17323 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
17324 declaration and if the declaration was never even referenced from
17325 within this entire compilation unit. We suppress these DIEs in
17326 order to save space in the .debug section (by eliminating entries
17327 which are probably useless). Note that we must not suppress
17328 block-local extern declarations (whether used or not) because that
17329 would screw-up the debugger's name lookup mechanism and cause it to
17330 miss things which really ought to be in scope at a given point. */
17331 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
17334 /* For local statics lookup proper context die. */
17335 if (TREE_STATIC (decl) && decl_function_context (decl))
17336 context_die = lookup_decl_die (DECL_CONTEXT (decl));
17338 /* If we are in terse mode, don't generate any DIEs to represent any
17339 variable declarations or definitions. */
17340 if (debug_info_level <= DINFO_LEVEL_TERSE)
17345 if (debug_info_level <= DINFO_LEVEL_TERSE)
17347 if (!is_fortran ())
17349 if (TREE_STATIC (decl) && decl_function_context (decl))
17350 context_die = lookup_decl_die (DECL_CONTEXT (decl));
17353 case NAMESPACE_DECL:
17354 case IMPORTED_DECL:
17355 if (debug_info_level <= DINFO_LEVEL_TERSE)
17357 if (lookup_decl_die (decl) != NULL)
17362 /* Don't emit stubs for types unless they are needed by other DIEs. */
17363 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
17366 /* Don't bother trying to generate any DIEs to represent any of the
17367 normal built-in types for the language we are compiling. */
17368 if (DECL_IS_BUILTIN (decl))
17370 /* OK, we need to generate one for `bool' so GDB knows what type
17371 comparisons have. */
17373 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
17374 && ! DECL_IGNORED_P (decl))
17375 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
17380 /* If we are in terse mode, don't generate any DIEs for types. */
17381 if (debug_info_level <= DINFO_LEVEL_TERSE)
17384 /* If we're a function-scope tag, initially use a parent of NULL;
17385 this will be fixed up in decls_for_scope. */
17386 if (decl_function_context (decl))
17387 context_die = NULL;
17395 gen_decl_die (decl, NULL, context_die);
17398 /* Output a marker (i.e. a label) for the beginning of the generated code for
17399 a lexical block. */
17402 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
17403 unsigned int blocknum)
17405 switch_to_section (current_function_section ());
17406 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
17409 /* Output a marker (i.e. a label) for the end of the generated code for a
17413 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
17415 switch_to_section (current_function_section ());
17416 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
17419 /* Returns nonzero if it is appropriate not to emit any debugging
17420 information for BLOCK, because it doesn't contain any instructions.
17422 Don't allow this for blocks with nested functions or local classes
17423 as we would end up with orphans, and in the presence of scheduling
17424 we may end up calling them anyway. */
17427 dwarf2out_ignore_block (const_tree block)
17432 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
17433 if (TREE_CODE (decl) == FUNCTION_DECL
17434 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
17436 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
17438 decl = BLOCK_NONLOCALIZED_VAR (block, i);
17439 if (TREE_CODE (decl) == FUNCTION_DECL
17440 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
17447 /* Hash table routines for file_hash. */
17450 file_table_eq (const void *p1_p, const void *p2_p)
17452 const struct dwarf_file_data *const p1 =
17453 (const struct dwarf_file_data *) p1_p;
17454 const char *const p2 = (const char *) p2_p;
17455 return strcmp (p1->filename, p2) == 0;
17459 file_table_hash (const void *p_p)
17461 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
17462 return htab_hash_string (p->filename);
17465 /* Lookup FILE_NAME (in the list of filenames that we know about here in
17466 dwarf2out.c) and return its "index". The index of each (known) filename is
17467 just a unique number which is associated with only that one filename. We
17468 need such numbers for the sake of generating labels (in the .debug_sfnames
17469 section) and references to those files numbers (in the .debug_srcinfo
17470 and.debug_macinfo sections). If the filename given as an argument is not
17471 found in our current list, add it to the list and assign it the next
17472 available unique index number. In order to speed up searches, we remember
17473 the index of the filename was looked up last. This handles the majority of
17476 static struct dwarf_file_data *
17477 lookup_filename (const char *file_name)
17480 struct dwarf_file_data * created;
17482 /* Check to see if the file name that was searched on the previous
17483 call matches this file name. If so, return the index. */
17484 if (file_table_last_lookup
17485 && (file_name == file_table_last_lookup->filename
17486 || strcmp (file_table_last_lookup->filename, file_name) == 0))
17487 return file_table_last_lookup;
17489 /* Didn't match the previous lookup, search the table. */
17490 slot = htab_find_slot_with_hash (file_table, file_name,
17491 htab_hash_string (file_name), INSERT);
17493 return (struct dwarf_file_data *) *slot;
17495 created = GGC_NEW (struct dwarf_file_data);
17496 created->filename = file_name;
17497 created->emitted_number = 0;
17502 /* If the assembler will construct the file table, then translate the compiler
17503 internal file table number into the assembler file table number, and emit
17504 a .file directive if we haven't already emitted one yet. The file table
17505 numbers are different because we prune debug info for unused variables and
17506 types, which may include filenames. */
17509 maybe_emit_file (struct dwarf_file_data * fd)
17511 if (! fd->emitted_number)
17513 if (last_emitted_file)
17514 fd->emitted_number = last_emitted_file->emitted_number + 1;
17516 fd->emitted_number = 1;
17517 last_emitted_file = fd;
17519 if (DWARF2_ASM_LINE_DEBUG_INFO)
17521 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
17522 output_quoted_string (asm_out_file,
17523 remap_debug_filename (fd->filename));
17524 fputc ('\n', asm_out_file);
17528 return fd->emitted_number;
17531 /* Schedule generation of a DW_AT_const_value attribute to DIE.
17532 That generation should happen after function debug info has been
17533 generated. The value of the attribute is the constant value of ARG. */
17536 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
17538 die_arg_entry entry;
17543 if (!tmpl_value_parm_die_table)
17544 tmpl_value_parm_die_table
17545 = VEC_alloc (die_arg_entry, gc, 32);
17549 VEC_safe_push (die_arg_entry, gc,
17550 tmpl_value_parm_die_table,
17554 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
17555 by append_entry_to_tmpl_value_parm_die_table. This function must
17556 be called after function DIEs have been generated. */
17559 gen_remaining_tmpl_value_param_die_attribute (void)
17561 if (tmpl_value_parm_die_table)
17567 VEC_iterate (die_arg_entry, tmpl_value_parm_die_table, i, e);
17569 tree_add_const_value_attribute (e->die, e->arg);
17574 /* Replace DW_AT_name for the decl with name. */
17577 dwarf2out_set_name (tree decl, tree name)
17582 die = TYPE_SYMTAB_DIE (decl);
17586 attr = get_AT (die, DW_AT_name);
17589 struct indirect_string_node *node;
17591 node = find_AT_string (dwarf2_name (name, 0));
17592 /* replace the string. */
17593 attr->dw_attr_val.v.val_str = node;
17597 add_name_attribute (die, dwarf2_name (name, 0));
17600 /* Called by the final INSN scan whenever we see a var location. We
17601 use it to drop labels in the right places, and throw the location in
17602 our lookup table. */
17605 dwarf2out_var_location (rtx loc_note)
17607 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
17608 struct var_loc_node *newloc;
17610 static const char *last_label;
17611 static const char *last_postcall_label;
17612 static bool last_in_cold_section_p;
17615 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
17618 next_real = next_real_insn (loc_note);
17619 /* If there are no instructions which would be affected by this note,
17620 don't do anything. */
17621 if (next_real == NULL_RTX)
17624 newloc = GGC_CNEW (struct var_loc_node);
17625 /* If there were no real insns between note we processed last time
17626 and this note, use the label we emitted last time. */
17627 if (last_var_location_insn == NULL_RTX
17628 || last_var_location_insn != next_real
17629 || last_in_cold_section_p != in_cold_section_p)
17631 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
17632 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
17634 last_label = ggc_strdup (loclabel);
17635 if (!NOTE_DURING_CALL_P (loc_note))
17636 last_postcall_label = NULL;
17638 newloc->var_loc_note = loc_note;
17639 newloc->next = NULL;
17641 if (!NOTE_DURING_CALL_P (loc_note))
17642 newloc->label = last_label;
17645 if (!last_postcall_label)
17647 sprintf (loclabel, "%s-1", last_label);
17648 last_postcall_label = ggc_strdup (loclabel);
17650 newloc->label = last_postcall_label;
17653 if (cfun && in_cold_section_p)
17654 newloc->section_label = crtl->subsections.cold_section_label;
17656 newloc->section_label = text_section_label;
17658 last_var_location_insn = next_real;
17659 last_in_cold_section_p = in_cold_section_p;
17660 decl = NOTE_VAR_LOCATION_DECL (loc_note);
17661 add_var_loc_to_decl (decl, newloc);
17664 /* We need to reset the locations at the beginning of each
17665 function. We can't do this in the end_function hook, because the
17666 declarations that use the locations won't have been output when
17667 that hook is called. Also compute have_multiple_function_sections here. */
17670 dwarf2out_begin_function (tree fun)
17672 htab_empty (decl_loc_table);
17674 if (function_section (fun) != text_section)
17675 have_multiple_function_sections = true;
17677 dwarf2out_note_section_used ();
17680 /* Output a label to mark the beginning of a source code line entry
17681 and record information relating to this source line, in
17682 'line_info_table' for later output of the .debug_line section. */
17685 dwarf2out_source_line (unsigned int line, const char *filename,
17686 int discriminator, bool is_stmt)
17688 static bool last_is_stmt = true;
17690 if (debug_info_level >= DINFO_LEVEL_NORMAL
17693 int file_num = maybe_emit_file (lookup_filename (filename));
17695 switch_to_section (current_function_section ());
17697 /* If requested, emit something human-readable. */
17698 if (flag_debug_asm)
17699 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
17702 if (DWARF2_ASM_LINE_DEBUG_INFO)
17704 /* Emit the .loc directive understood by GNU as. */
17705 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
17706 if (is_stmt != last_is_stmt)
17708 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
17709 last_is_stmt = is_stmt;
17711 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
17712 fprintf (asm_out_file, " discriminator %d", discriminator);
17713 fputc ('\n', asm_out_file);
17715 /* Indicate that line number info exists. */
17716 line_info_table_in_use++;
17718 else if (function_section (current_function_decl) != text_section)
17720 dw_separate_line_info_ref line_info;
17721 targetm.asm_out.internal_label (asm_out_file,
17722 SEPARATE_LINE_CODE_LABEL,
17723 separate_line_info_table_in_use);
17725 /* Expand the line info table if necessary. */
17726 if (separate_line_info_table_in_use
17727 == separate_line_info_table_allocated)
17729 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
17730 separate_line_info_table
17731 = GGC_RESIZEVEC (dw_separate_line_info_entry,
17732 separate_line_info_table,
17733 separate_line_info_table_allocated);
17734 memset (separate_line_info_table
17735 + separate_line_info_table_in_use,
17737 (LINE_INFO_TABLE_INCREMENT
17738 * sizeof (dw_separate_line_info_entry)));
17741 /* Add the new entry at the end of the line_info_table. */
17743 = &separate_line_info_table[separate_line_info_table_in_use++];
17744 line_info->dw_file_num = file_num;
17745 line_info->dw_line_num = line;
17746 line_info->function = current_function_funcdef_no;
17750 dw_line_info_ref line_info;
17752 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
17753 line_info_table_in_use);
17755 /* Expand the line info table if necessary. */
17756 if (line_info_table_in_use == line_info_table_allocated)
17758 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
17760 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
17761 line_info_table_allocated);
17762 memset (line_info_table + line_info_table_in_use, 0,
17763 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
17766 /* Add the new entry at the end of the line_info_table. */
17767 line_info = &line_info_table[line_info_table_in_use++];
17768 line_info->dw_file_num = file_num;
17769 line_info->dw_line_num = line;
17774 /* Record the beginning of a new source file. */
17777 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
17779 if (flag_eliminate_dwarf2_dups)
17781 /* Record the beginning of the file for break_out_includes. */
17782 dw_die_ref bincl_die;
17784 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
17785 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
17788 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17790 int file_num = maybe_emit_file (lookup_filename (filename));
17792 switch_to_section (debug_macinfo_section);
17793 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
17794 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
17797 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
17801 /* Record the end of a source file. */
17804 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
17806 if (flag_eliminate_dwarf2_dups)
17807 /* Record the end of the file for break_out_includes. */
17808 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
17810 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17812 switch_to_section (debug_macinfo_section);
17813 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
17817 /* Called from debug_define in toplev.c. The `buffer' parameter contains
17818 the tail part of the directive line, i.e. the part which is past the
17819 initial whitespace, #, whitespace, directive-name, whitespace part. */
17822 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
17823 const char *buffer ATTRIBUTE_UNUSED)
17825 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17827 switch_to_section (debug_macinfo_section);
17828 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
17829 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
17830 dw2_asm_output_nstring (buffer, -1, "The macro");
17834 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
17835 the tail part of the directive line, i.e. the part which is past the
17836 initial whitespace, #, whitespace, directive-name, whitespace part. */
17839 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
17840 const char *buffer ATTRIBUTE_UNUSED)
17842 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17844 switch_to_section (debug_macinfo_section);
17845 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
17846 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
17847 dw2_asm_output_nstring (buffer, -1, "The macro");
17851 /* Set up for Dwarf output at the start of compilation. */
17854 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
17856 /* Allocate the file_table. */
17857 file_table = htab_create_ggc (50, file_table_hash,
17858 file_table_eq, NULL);
17860 /* Allocate the decl_die_table. */
17861 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
17862 decl_die_table_eq, NULL);
17864 /* Allocate the decl_loc_table. */
17865 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
17866 decl_loc_table_eq, NULL);
17868 /* Allocate the initial hunk of the decl_scope_table. */
17869 decl_scope_table = VEC_alloc (tree, gc, 256);
17871 /* Allocate the initial hunk of the abbrev_die_table. */
17872 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
17873 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
17874 /* Zero-th entry is allocated, but unused. */
17875 abbrev_die_table_in_use = 1;
17877 /* Allocate the initial hunk of the line_info_table. */
17878 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
17879 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
17881 /* Zero-th entry is allocated, but unused. */
17882 line_info_table_in_use = 1;
17884 /* Allocate the pubtypes and pubnames vectors. */
17885 pubname_table = VEC_alloc (pubname_entry, gc, 32);
17886 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
17888 /* Generate the initial DIE for the .debug section. Note that the (string)
17889 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
17890 will (typically) be a relative pathname and that this pathname should be
17891 taken as being relative to the directory from which the compiler was
17892 invoked when the given (base) source file was compiled. We will fill
17893 in this value in dwarf2out_finish. */
17894 comp_unit_die = gen_compile_unit_die (NULL);
17896 incomplete_types = VEC_alloc (tree, gc, 64);
17898 used_rtx_array = VEC_alloc (rtx, gc, 32);
17900 debug_info_section = get_section (DEBUG_INFO_SECTION,
17901 SECTION_DEBUG, NULL);
17902 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
17903 SECTION_DEBUG, NULL);
17904 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
17905 SECTION_DEBUG, NULL);
17906 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
17907 SECTION_DEBUG, NULL);
17908 debug_line_section = get_section (DEBUG_LINE_SECTION,
17909 SECTION_DEBUG, NULL);
17910 debug_loc_section = get_section (DEBUG_LOC_SECTION,
17911 SECTION_DEBUG, NULL);
17912 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
17913 SECTION_DEBUG, NULL);
17914 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
17915 SECTION_DEBUG, NULL);
17916 debug_str_section = get_section (DEBUG_STR_SECTION,
17917 DEBUG_STR_SECTION_FLAGS, NULL);
17918 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
17919 SECTION_DEBUG, NULL);
17920 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
17921 SECTION_DEBUG, NULL);
17923 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
17924 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
17925 DEBUG_ABBREV_SECTION_LABEL, 0);
17926 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
17927 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
17928 COLD_TEXT_SECTION_LABEL, 0);
17929 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
17931 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
17932 DEBUG_INFO_SECTION_LABEL, 0);
17933 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
17934 DEBUG_LINE_SECTION_LABEL, 0);
17935 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
17936 DEBUG_RANGES_SECTION_LABEL, 0);
17937 switch_to_section (debug_abbrev_section);
17938 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
17939 switch_to_section (debug_info_section);
17940 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
17941 switch_to_section (debug_line_section);
17942 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
17944 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17946 switch_to_section (debug_macinfo_section);
17947 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
17948 DEBUG_MACINFO_SECTION_LABEL, 0);
17949 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
17952 switch_to_section (text_section);
17953 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
17954 if (flag_reorder_blocks_and_partition)
17956 cold_text_section = unlikely_text_section ();
17957 switch_to_section (cold_text_section);
17958 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
17962 /* A helper function for dwarf2out_finish called through
17963 htab_traverse. Emit one queued .debug_str string. */
17966 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
17968 struct indirect_string_node *node = (struct indirect_string_node *) *h;
17970 if (node->label && node->refcount)
17972 switch_to_section (debug_str_section);
17973 ASM_OUTPUT_LABEL (asm_out_file, node->label);
17974 assemble_string (node->str, strlen (node->str) + 1);
17980 #if ENABLE_ASSERT_CHECKING
17981 /* Verify that all marks are clear. */
17984 verify_marks_clear (dw_die_ref die)
17988 gcc_assert (! die->die_mark);
17989 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
17991 #endif /* ENABLE_ASSERT_CHECKING */
17993 /* Clear the marks for a die and its children.
17994 Be cool if the mark isn't set. */
17997 prune_unmark_dies (dw_die_ref die)
18003 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
18006 /* Given DIE that we're marking as used, find any other dies
18007 it references as attributes and mark them as used. */
18010 prune_unused_types_walk_attribs (dw_die_ref die)
18015 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18017 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
18019 /* A reference to another DIE.
18020 Make sure that it will get emitted. */
18021 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
18023 /* Set the string's refcount to 0 so that prune_unused_types_mark
18024 accounts properly for it. */
18025 if (AT_class (a) == dw_val_class_str)
18026 a->dw_attr_val.v.val_str->refcount = 0;
18031 /* Mark DIE as being used. If DOKIDS is true, then walk down
18032 to DIE's children. */
18035 prune_unused_types_mark (dw_die_ref die, int dokids)
18039 if (die->die_mark == 0)
18041 /* We haven't done this node yet. Mark it as used. */
18044 /* We also have to mark its parents as used.
18045 (But we don't want to mark our parents' kids due to this.) */
18046 if (die->die_parent)
18047 prune_unused_types_mark (die->die_parent, 0);
18049 /* Mark any referenced nodes. */
18050 prune_unused_types_walk_attribs (die);
18052 /* If this node is a specification,
18053 also mark the definition, if it exists. */
18054 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
18055 prune_unused_types_mark (die->die_definition, 1);
18058 if (dokids && die->die_mark != 2)
18060 /* We need to walk the children, but haven't done so yet.
18061 Remember that we've walked the kids. */
18064 /* If this is an array type, we need to make sure our
18065 kids get marked, even if they're types. */
18066 if (die->die_tag == DW_TAG_array_type)
18067 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
18069 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18073 /* For local classes, look if any static member functions were emitted
18074 and if so, mark them. */
18077 prune_unused_types_walk_local_classes (dw_die_ref die)
18081 if (die->die_mark == 2)
18084 switch (die->die_tag)
18086 case DW_TAG_structure_type:
18087 case DW_TAG_union_type:
18088 case DW_TAG_class_type:
18091 case DW_TAG_subprogram:
18092 if (!get_AT_flag (die, DW_AT_declaration)
18093 || die->die_definition != NULL)
18094 prune_unused_types_mark (die, 1);
18101 /* Mark children. */
18102 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
18105 /* Walk the tree DIE and mark types that we actually use. */
18108 prune_unused_types_walk (dw_die_ref die)
18112 /* Don't do anything if this node is already marked and
18113 children have been marked as well. */
18114 if (die->die_mark == 2)
18117 switch (die->die_tag)
18119 case DW_TAG_structure_type:
18120 case DW_TAG_union_type:
18121 case DW_TAG_class_type:
18122 if (die->die_perennial_p)
18125 for (c = die->die_parent; c; c = c->die_parent)
18126 if (c->die_tag == DW_TAG_subprogram)
18129 /* Finding used static member functions inside of classes
18130 is needed just for local classes, because for other classes
18131 static member function DIEs with DW_AT_specification
18132 are emitted outside of the DW_TAG_*_type. If we ever change
18133 it, we'd need to call this even for non-local classes. */
18135 prune_unused_types_walk_local_classes (die);
18137 /* It's a type node --- don't mark it. */
18140 case DW_TAG_const_type:
18141 case DW_TAG_packed_type:
18142 case DW_TAG_pointer_type:
18143 case DW_TAG_reference_type:
18144 case DW_TAG_volatile_type:
18145 case DW_TAG_typedef:
18146 case DW_TAG_array_type:
18147 case DW_TAG_interface_type:
18148 case DW_TAG_friend:
18149 case DW_TAG_variant_part:
18150 case DW_TAG_enumeration_type:
18151 case DW_TAG_subroutine_type:
18152 case DW_TAG_string_type:
18153 case DW_TAG_set_type:
18154 case DW_TAG_subrange_type:
18155 case DW_TAG_ptr_to_member_type:
18156 case DW_TAG_file_type:
18157 if (die->die_perennial_p)
18160 /* It's a type node --- don't mark it. */
18164 /* Mark everything else. */
18168 if (die->die_mark == 0)
18172 /* Now, mark any dies referenced from here. */
18173 prune_unused_types_walk_attribs (die);
18178 /* Mark children. */
18179 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
18182 /* Increment the string counts on strings referred to from DIE's
18186 prune_unused_types_update_strings (dw_die_ref die)
18191 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
18192 if (AT_class (a) == dw_val_class_str)
18194 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
18196 /* Avoid unnecessarily putting strings that are used less than
18197 twice in the hash table. */
18199 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
18202 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
18203 htab_hash_string (s->str),
18205 gcc_assert (*slot == NULL);
18211 /* Remove from the tree DIE any dies that aren't marked. */
18214 prune_unused_types_prune (dw_die_ref die)
18218 gcc_assert (die->die_mark);
18219 prune_unused_types_update_strings (die);
18221 if (! die->die_child)
18224 c = die->die_child;
18226 dw_die_ref prev = c;
18227 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
18228 if (c == die->die_child)
18230 /* No marked children between 'prev' and the end of the list. */
18232 /* No marked children at all. */
18233 die->die_child = NULL;
18236 prev->die_sib = c->die_sib;
18237 die->die_child = prev;
18242 if (c != prev->die_sib)
18244 prune_unused_types_prune (c);
18245 } while (c != die->die_child);
18248 /* A helper function for dwarf2out_finish called through
18249 htab_traverse. Clear .debug_str strings that we haven't already
18250 decided to emit. */
18253 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
18255 struct indirect_string_node *node = (struct indirect_string_node *) *h;
18257 if (!node->label || !node->refcount)
18258 htab_clear_slot (debug_str_hash, h);
18263 /* Remove dies representing declarations that we never use. */
18266 prune_unused_types (void)
18269 limbo_die_node *node;
18272 #if ENABLE_ASSERT_CHECKING
18273 /* All the marks should already be clear. */
18274 verify_marks_clear (comp_unit_die);
18275 for (node = limbo_die_list; node; node = node->next)
18276 verify_marks_clear (node->die);
18277 #endif /* ENABLE_ASSERT_CHECKING */
18279 /* Set the mark on nodes that are actually used. */
18280 prune_unused_types_walk (comp_unit_die);
18281 for (node = limbo_die_list; node; node = node->next)
18282 prune_unused_types_walk (node->die);
18284 /* Also set the mark on nodes referenced from the
18285 pubname_table or arange_table. */
18286 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
18287 prune_unused_types_mark (pub->die, 1);
18288 for (i = 0; i < arange_table_in_use; i++)
18289 prune_unused_types_mark (arange_table[i], 1);
18291 /* Get rid of nodes that aren't marked; and update the string counts. */
18292 if (debug_str_hash && debug_str_hash_forced)
18293 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
18294 else if (debug_str_hash)
18295 htab_empty (debug_str_hash);
18296 prune_unused_types_prune (comp_unit_die);
18297 for (node = limbo_die_list; node; node = node->next)
18298 prune_unused_types_prune (node->die);
18300 /* Leave the marks clear. */
18301 prune_unmark_dies (comp_unit_die);
18302 for (node = limbo_die_list; node; node = node->next)
18303 prune_unmark_dies (node->die);
18306 /* Set the parameter to true if there are any relative pathnames in
18309 file_table_relative_p (void ** slot, void *param)
18311 bool *p = (bool *) param;
18312 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
18313 if (!IS_ABSOLUTE_PATH (d->filename))
18321 /* Move a DW_AT_MIPS_linkage_name attribute just added to dw_die_ref
18322 to the location it would have been added, should we know its
18323 DECL_ASSEMBLER_NAME when we added other attributes. This will
18324 probably improve compactness of debug info, removing equivalent
18325 abbrevs, and hide any differences caused by deferring the
18326 computation of the assembler name, triggered by e.g. PCH. */
18329 move_linkage_attr (dw_die_ref die)
18331 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
18332 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
18334 gcc_assert (linkage.dw_attr == DW_AT_MIPS_linkage_name);
18338 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
18340 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
18344 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
18346 VEC_pop (dw_attr_node, die->die_attr);
18347 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
18351 /* Output stuff that dwarf requires at the end of every file,
18352 and generate the DWARF-2 debugging info. */
18355 dwarf2out_finish (const char *filename)
18357 limbo_die_node *node, *next_node;
18358 dw_die_ref die = 0;
18361 gen_remaining_tmpl_value_param_die_attribute ();
18363 /* Add the name for the main input file now. We delayed this from
18364 dwarf2out_init to avoid complications with PCH. */
18365 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
18366 if (!IS_ABSOLUTE_PATH (filename))
18367 add_comp_dir_attribute (comp_unit_die);
18368 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
18371 htab_traverse (file_table, file_table_relative_p, &p);
18373 add_comp_dir_attribute (comp_unit_die);
18376 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
18378 add_location_or_const_value_attribute (
18379 VEC_index (deferred_locations, deferred_locations_list, i)->die,
18380 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
18384 /* Traverse the limbo die list, and add parent/child links. The only
18385 dies without parents that should be here are concrete instances of
18386 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
18387 For concrete instances, we can get the parent die from the abstract
18389 for (node = limbo_die_list; node; node = next_node)
18391 next_node = node->next;
18394 if (die->die_parent == NULL)
18396 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
18399 add_child_die (origin->die_parent, die);
18400 else if (die == comp_unit_die)
18402 else if (errorcount > 0 || sorrycount > 0)
18403 /* It's OK to be confused by errors in the input. */
18404 add_child_die (comp_unit_die, die);
18407 /* In certain situations, the lexical block containing a
18408 nested function can be optimized away, which results
18409 in the nested function die being orphaned. Likewise
18410 with the return type of that nested function. Force
18411 this to be a child of the containing function.
18413 It may happen that even the containing function got fully
18414 inlined and optimized out. In that case we are lost and
18415 assign the empty child. This should not be big issue as
18416 the function is likely unreachable too. */
18417 tree context = NULL_TREE;
18419 gcc_assert (node->created_for);
18421 if (DECL_P (node->created_for))
18422 context = DECL_CONTEXT (node->created_for);
18423 else if (TYPE_P (node->created_for))
18424 context = TYPE_CONTEXT (node->created_for);
18426 gcc_assert (context
18427 && (TREE_CODE (context) == FUNCTION_DECL
18428 || TREE_CODE (context) == NAMESPACE_DECL));
18430 origin = lookup_decl_die (context);
18432 add_child_die (origin, die);
18434 add_child_die (comp_unit_die, die);
18439 limbo_die_list = NULL;
18441 for (node = deferred_asm_name; node; node = node->next)
18443 tree decl = node->created_for;
18444 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
18446 add_AT_string (node->die, DW_AT_MIPS_linkage_name,
18447 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
18448 move_linkage_attr (node->die);
18452 deferred_asm_name = NULL;
18454 /* Walk through the list of incomplete types again, trying once more to
18455 emit full debugging info for them. */
18456 retry_incomplete_types ();
18458 if (flag_eliminate_unused_debug_types)
18459 prune_unused_types ();
18461 /* Generate separate CUs for each of the include files we've seen.
18462 They will go into limbo_die_list. */
18463 if (flag_eliminate_dwarf2_dups)
18464 break_out_includes (comp_unit_die);
18466 /* Traverse the DIE's and add add sibling attributes to those DIE's
18467 that have children. */
18468 add_sibling_attributes (comp_unit_die);
18469 for (node = limbo_die_list; node; node = node->next)
18470 add_sibling_attributes (node->die);
18472 /* Output a terminator label for the .text section. */
18473 switch_to_section (text_section);
18474 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
18475 if (flag_reorder_blocks_and_partition)
18477 switch_to_section (unlikely_text_section ());
18478 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
18481 /* We can only use the low/high_pc attributes if all of the code was
18483 if (!have_multiple_function_sections)
18485 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
18486 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
18491 unsigned fde_idx = 0;
18493 /* We need to give .debug_loc and .debug_ranges an appropriate
18494 "base address". Use zero so that these addresses become
18495 absolute. Historically, we've emitted the unexpected
18496 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
18497 Emit both to give time for other tools to adapt. */
18498 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
18499 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
18501 add_AT_range_list (comp_unit_die, DW_AT_ranges,
18502 add_ranges_by_labels (text_section_label,
18504 if (flag_reorder_blocks_and_partition)
18505 add_ranges_by_labels (cold_text_section_label,
18508 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
18510 dw_fde_ref fde = &fde_table[fde_idx];
18512 if (fde->dw_fde_switched_sections)
18514 if (!fde->in_std_section)
18515 add_ranges_by_labels (fde->dw_fde_hot_section_label,
18516 fde->dw_fde_hot_section_end_label);
18517 if (!fde->cold_in_std_section)
18518 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
18519 fde->dw_fde_unlikely_section_end_label);
18521 else if (!fde->in_std_section)
18522 add_ranges_by_labels (fde->dw_fde_begin,
18529 /* Output location list section if necessary. */
18530 if (have_location_lists)
18532 /* Output the location lists info. */
18533 switch_to_section (debug_loc_section);
18534 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
18535 DEBUG_LOC_SECTION_LABEL, 0);
18536 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
18537 output_location_lists (die);
18540 if (debug_info_level >= DINFO_LEVEL_NORMAL)
18541 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
18542 debug_line_section_label);
18544 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18545 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
18547 /* Output all of the compilation units. We put the main one last so that
18548 the offsets are available to output_pubnames. */
18549 for (node = limbo_die_list; node; node = node->next)
18550 output_comp_unit (node->die, 0);
18552 /* Output the main compilation unit if non-empty or if .debug_macinfo
18553 has been emitted. */
18554 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
18556 /* Output the abbreviation table. */
18557 switch_to_section (debug_abbrev_section);
18558 output_abbrev_section ();
18560 /* Output public names table if necessary. */
18561 if (!VEC_empty (pubname_entry, pubname_table))
18563 switch_to_section (debug_pubnames_section);
18564 output_pubnames (pubname_table);
18567 /* Output public types table if necessary. */
18568 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
18569 It shouldn't hurt to emit it always, since pure DWARF2 consumers
18570 simply won't look for the section. */
18571 if (!VEC_empty (pubname_entry, pubtype_table))
18573 switch_to_section (debug_pubtypes_section);
18574 output_pubnames (pubtype_table);
18577 /* Output the address range information. We only put functions in the arange
18578 table, so don't write it out if we don't have any. */
18579 if (fde_table_in_use)
18581 switch_to_section (debug_aranges_section);
18585 /* Output ranges section if necessary. */
18586 if (ranges_table_in_use)
18588 switch_to_section (debug_ranges_section);
18589 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
18593 /* Output the source line correspondence table. We must do this
18594 even if there is no line information. Otherwise, on an empty
18595 translation unit, we will generate a present, but empty,
18596 .debug_info section. IRIX 6.5 `nm' will then complain when
18597 examining the file. This is done late so that any filenames
18598 used by the debug_info section are marked as 'used'. */
18599 if (! DWARF2_ASM_LINE_DEBUG_INFO)
18601 switch_to_section (debug_line_section);
18602 output_line_info ();
18605 /* Have to end the macro section. */
18606 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
18608 switch_to_section (debug_macinfo_section);
18609 dw2_asm_output_data (1, 0, "End compilation unit");
18612 /* If we emitted any DW_FORM_strp form attribute, output the string
18614 if (debug_str_hash)
18615 htab_traverse (debug_str_hash, output_indirect_string, NULL);
18619 /* This should never be used, but its address is needed for comparisons. */
18620 const struct gcc_debug_hooks dwarf2_debug_hooks =
18626 0, /* start_source_file */
18627 0, /* end_source_file */
18628 0, /* begin_block */
18630 0, /* ignore_block */
18631 0, /* source_line */
18632 0, /* begin_prologue */
18633 0, /* end_prologue */
18634 0, /* end_epilogue */
18635 0, /* begin_function */
18636 0, /* end_function */
18637 0, /* function_decl */
18638 0, /* global_decl */
18640 0, /* imported_module_or_decl */
18641 0, /* deferred_inline_function */
18642 0, /* outlining_inline_function */
18644 0, /* handle_pch */
18645 0, /* var_location */
18646 0, /* switch_text_section */
18648 0 /* start_end_main_source_file */
18651 #endif /* DWARF2_DEBUGGING_INFO */
18653 #include "gt-dwarf2out.h"