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, 2010
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
69 #include "hard-reg-set.h"
71 #include "insn-config.h"
79 #include "dwarf2out.h"
80 #include "dwarf2asm.h"
86 #include "diagnostic.h"
89 #include "langhooks.h"
94 #ifdef DWARF2_DEBUGGING_INFO
95 static void dwarf2out_source_line (unsigned int, const char *);
98 #ifndef DWARF2_FRAME_INFO
99 # ifdef DWARF2_DEBUGGING_INFO
100 # define DWARF2_FRAME_INFO \
101 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
103 # define DWARF2_FRAME_INFO 0
107 /* Map register numbers held in the call frame info that gcc has
108 collected using DWARF_FRAME_REGNUM to those that should be output in
109 .debug_frame and .eh_frame. */
110 #ifndef DWARF2_FRAME_REG_OUT
111 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
114 /* Save the result of dwarf2out_do_frame across PCH. */
115 static GTY(()) bool saved_do_cfi_asm = 0;
117 /* Decide whether we want to emit frame unwind information for the current
121 dwarf2out_do_frame (void)
123 /* We want to emit correct CFA location expressions or lists, so we
124 have to return true if we're going to output debug info, even if
125 we're not going to output frame or unwind info. */
126 return (write_symbols == DWARF2_DEBUG
127 || write_symbols == VMS_AND_DWARF2_DEBUG
128 || DWARF2_FRAME_INFO || saved_do_cfi_asm
129 #ifdef DWARF2_UNWIND_INFO
130 || (DWARF2_UNWIND_INFO
131 && (flag_unwind_tables
132 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
137 /* Decide whether to emit frame unwind via assembler directives. */
140 dwarf2out_do_cfi_asm (void)
144 #ifdef MIPS_DEBUGGING_INFO
147 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
149 if (saved_do_cfi_asm)
151 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE)
153 #ifdef TARGET_UNWIND_INFO
156 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
160 if (!eh_personality_libfunc)
162 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
165 /* Make sure the personality encoding is one the assembler can support.
166 In particular, aligned addresses can't be handled. */
167 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
168 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
170 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
171 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
174 saved_do_cfi_asm = true;
178 /* The size of the target's pointer type. */
180 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
183 /* Array of RTXes referenced by the debugging information, which therefore
184 must be kept around forever. */
185 static GTY(()) VEC(rtx,gc) *used_rtx_array;
187 /* A pointer to the base of a list of incomplete types which might be
188 completed at some later time. incomplete_types_list needs to be a
189 VEC(tree,gc) because we want to tell the garbage collector about
191 static GTY(()) VEC(tree,gc) *incomplete_types;
193 /* A pointer to the base of a table of references to declaration
194 scopes. This table is a display which tracks the nesting
195 of declaration scopes at the current scope and containing
196 scopes. This table is used to find the proper place to
197 define type declaration DIE's. */
198 static GTY(()) VEC(tree,gc) *decl_scope_table;
200 /* Pointers to various DWARF2 sections. */
201 static GTY(()) section *debug_info_section;
202 static GTY(()) section *debug_abbrev_section;
203 static GTY(()) section *debug_aranges_section;
204 static GTY(()) section *debug_macinfo_section;
205 static GTY(()) section *debug_line_section;
206 static GTY(()) section *debug_loc_section;
207 static GTY(()) section *debug_pubnames_section;
208 static GTY(()) section *debug_pubtypes_section;
209 static GTY(()) section *debug_str_section;
210 static GTY(()) section *debug_ranges_section;
211 static GTY(()) section *debug_frame_section;
213 /* How to start an assembler comment. */
214 #ifndef ASM_COMMENT_START
215 #define ASM_COMMENT_START ";#"
218 typedef struct dw_cfi_struct *dw_cfi_ref;
219 typedef struct dw_fde_struct *dw_fde_ref;
220 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
222 /* Call frames are described using a sequence of Call Frame
223 Information instructions. The register number, offset
224 and address fields are provided as possible operands;
225 their use is selected by the opcode field. */
227 enum dw_cfi_oprnd_type {
229 dw_cfi_oprnd_reg_num,
235 typedef union dw_cfi_oprnd_struct GTY(())
237 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
238 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
239 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
240 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
244 typedef struct dw_cfi_struct GTY(())
246 dw_cfi_ref dw_cfi_next;
247 enum dwarf_call_frame_info dw_cfi_opc;
248 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
250 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
255 /* This is how we define the location of the CFA. We use to handle it
256 as REG + OFFSET all the time, but now it can be more complex.
257 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
258 Instead of passing around REG and OFFSET, we pass a copy
259 of this structure. */
260 typedef struct cfa_loc GTY(())
262 HOST_WIDE_INT offset;
263 HOST_WIDE_INT base_offset;
265 int indirect; /* 1 if CFA is accessed via a dereference. */
268 /* All call frame descriptions (FDE's) in the GCC generated DWARF
269 refer to a single Common Information Entry (CIE), defined at
270 the beginning of the .debug_frame section. This use of a single
271 CIE obviates the need to keep track of multiple CIE's
272 in the DWARF generation routines below. */
274 typedef struct dw_fde_struct GTY(())
277 const char *dw_fde_begin;
278 const char *dw_fde_current_label;
279 const char *dw_fde_end;
280 const char *dw_fde_hot_section_label;
281 const char *dw_fde_hot_section_end_label;
282 const char *dw_fde_unlikely_section_label;
283 const char *dw_fde_unlikely_section_end_label;
284 bool dw_fde_switched_sections;
285 dw_cfi_ref dw_fde_cfi;
286 unsigned funcdef_number;
287 HOST_WIDE_INT stack_realignment;
288 /* Dynamic realign argument pointer register. */
289 unsigned int drap_reg;
290 /* Virtual dynamic realign argument pointer register. */
291 unsigned int vdrap_reg;
292 unsigned all_throwers_are_sibcalls : 1;
293 unsigned nothrow : 1;
294 unsigned uses_eh_lsda : 1;
295 /* Whether we did stack realign in this call frame. */
296 unsigned stack_realign : 1;
297 /* Whether dynamic realign argument pointer register has been saved. */
298 unsigned drap_reg_saved: 1;
302 /* Maximum size (in bytes) of an artificially generated label. */
303 #define MAX_ARTIFICIAL_LABEL_BYTES 30
305 /* The size of addresses as they appear in the Dwarf 2 data.
306 Some architectures use word addresses to refer to code locations,
307 but Dwarf 2 info always uses byte addresses. On such machines,
308 Dwarf 2 addresses need to be larger than the architecture's
310 #ifndef DWARF2_ADDR_SIZE
311 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
314 /* The size in bytes of a DWARF field indicating an offset or length
315 relative to a debug info section, specified to be 4 bytes in the
316 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
319 #ifndef DWARF_OFFSET_SIZE
320 #define DWARF_OFFSET_SIZE 4
323 /* According to the (draft) DWARF 3 specification, the initial length
324 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
325 bytes are 0xffffffff, followed by the length stored in the next 8
328 However, the SGI/MIPS ABI uses an initial length which is equal to
329 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
331 #ifndef DWARF_INITIAL_LENGTH_SIZE
332 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
335 #define DWARF_VERSION 2
337 /* Round SIZE up to the nearest BOUNDARY. */
338 #define DWARF_ROUND(SIZE,BOUNDARY) \
339 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
341 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
342 #ifndef DWARF_CIE_DATA_ALIGNMENT
343 #ifdef STACK_GROWS_DOWNWARD
344 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
346 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
350 /* CIE identifier. */
351 #if HOST_BITS_PER_WIDE_INT >= 64
352 #define DWARF_CIE_ID \
353 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
355 #define DWARF_CIE_ID DW_CIE_ID
358 /* A pointer to the base of a table that contains frame description
359 information for each routine. */
360 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
362 /* Number of elements currently allocated for fde_table. */
363 static GTY(()) unsigned fde_table_allocated;
365 /* Number of elements in fde_table currently in use. */
366 static GTY(()) unsigned fde_table_in_use;
368 /* Size (in elements) of increments by which we may expand the
370 #define FDE_TABLE_INCREMENT 256
372 /* Get the current fde_table entry we should use. */
374 static inline dw_fde_ref
377 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
380 /* A list of call frame insns for the CIE. */
381 static GTY(()) dw_cfi_ref cie_cfi_head;
383 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
384 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
385 attribute that accelerates the lookup of the FDE associated
386 with the subprogram. This variable holds the table index of the FDE
387 associated with the current function (body) definition. */
388 static unsigned current_funcdef_fde;
391 struct indirect_string_node GTY(())
394 unsigned int refcount;
399 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
401 static GTY(()) int dw2_string_counter;
402 static GTY(()) unsigned long dwarf2out_cfi_label_num;
404 /* True if the compilation unit places functions in more than one section. */
405 static GTY(()) bool have_multiple_function_sections = false;
407 /* Whether the default text and cold text sections have been used at all. */
409 static GTY(()) bool text_section_used = false;
410 static GTY(()) bool cold_text_section_used = false;
412 /* The default cold text section. */
413 static GTY(()) section *cold_text_section;
415 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
417 /* Forward declarations for functions defined in this file. */
419 static char *stripattributes (const char *);
420 static const char *dwarf_cfi_name (unsigned);
421 static dw_cfi_ref new_cfi (void);
422 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
423 static void add_fde_cfi (const char *, dw_cfi_ref);
424 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
425 static void lookup_cfa (dw_cfa_location *);
426 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
427 #ifdef DWARF2_UNWIND_INFO
428 static void initial_return_save (rtx);
430 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
432 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
433 static void output_cfi_directive (dw_cfi_ref);
434 static void output_call_frame_info (int);
435 static void dwarf2out_note_section_used (void);
436 static void dwarf2out_stack_adjust (rtx, bool);
437 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
438 static void flush_queued_reg_saves (void);
439 static bool clobbers_queued_reg_save (const_rtx);
440 static void dwarf2out_frame_debug_expr (rtx, const char *);
442 /* Support for complex CFA locations. */
443 static void output_cfa_loc (dw_cfi_ref);
444 static void output_cfa_loc_raw (dw_cfi_ref);
445 static void get_cfa_from_loc_descr (dw_cfa_location *,
446 struct dw_loc_descr_struct *);
447 static struct dw_loc_descr_struct *build_cfa_loc
448 (dw_cfa_location *, HOST_WIDE_INT);
449 static struct dw_loc_descr_struct *build_cfa_aligned_loc
450 (HOST_WIDE_INT, HOST_WIDE_INT);
451 static void def_cfa_1 (const char *, dw_cfa_location *);
453 /* How to start an assembler comment. */
454 #ifndef ASM_COMMENT_START
455 #define ASM_COMMENT_START ";#"
458 /* Data and reference forms for relocatable data. */
459 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
460 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
462 #ifndef DEBUG_FRAME_SECTION
463 #define DEBUG_FRAME_SECTION ".debug_frame"
466 #ifndef FUNC_BEGIN_LABEL
467 #define FUNC_BEGIN_LABEL "LFB"
470 #ifndef FUNC_END_LABEL
471 #define FUNC_END_LABEL "LFE"
474 #ifndef FRAME_BEGIN_LABEL
475 #define FRAME_BEGIN_LABEL "Lframe"
477 #define CIE_AFTER_SIZE_LABEL "LSCIE"
478 #define CIE_END_LABEL "LECIE"
479 #define FDE_LABEL "LSFDE"
480 #define FDE_AFTER_SIZE_LABEL "LASFDE"
481 #define FDE_END_LABEL "LEFDE"
482 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
483 #define LINE_NUMBER_END_LABEL "LELT"
484 #define LN_PROLOG_AS_LABEL "LASLTP"
485 #define LN_PROLOG_END_LABEL "LELTP"
486 #define DIE_LABEL_PREFIX "DW"
488 /* The DWARF 2 CFA column which tracks the return address. Normally this
489 is the column for PC, or the first column after all of the hard
491 #ifndef DWARF_FRAME_RETURN_COLUMN
493 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
495 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
499 /* The mapping from gcc register number to DWARF 2 CFA column number. By
500 default, we just provide columns for all registers. */
501 #ifndef DWARF_FRAME_REGNUM
502 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
505 /* Hook used by __throw. */
508 expand_builtin_dwarf_sp_column (void)
510 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
511 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
514 /* Return a pointer to a copy of the section string name S with all
515 attributes stripped off, and an asterisk prepended (for assemble_name). */
518 stripattributes (const char *s)
520 char *stripped = XNEWVEC (char, strlen (s) + 2);
525 while (*s && *s != ',')
532 /* MEM is a memory reference for the register size table, each element of
533 which has mode MODE. Initialize column C as a return address column. */
536 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
538 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
539 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
540 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
543 /* Generate code to initialize the register size table. */
546 expand_builtin_init_dwarf_reg_sizes (tree address)
549 enum machine_mode mode = TYPE_MODE (char_type_node);
550 rtx addr = expand_normal (address);
551 rtx mem = gen_rtx_MEM (BLKmode, addr);
552 bool wrote_return_column = false;
554 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
556 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
558 if (rnum < DWARF_FRAME_REGISTERS)
560 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
561 enum machine_mode save_mode = reg_raw_mode[i];
564 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
565 save_mode = choose_hard_reg_mode (i, 1, true);
566 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
568 if (save_mode == VOIDmode)
570 wrote_return_column = true;
572 size = GET_MODE_SIZE (save_mode);
576 emit_move_insn (adjust_address (mem, mode, offset),
577 gen_int_mode (size, mode));
581 if (!wrote_return_column)
582 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
584 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
585 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
588 targetm.init_dwarf_reg_sizes_extra (address);
591 /* Convert a DWARF call frame info. operation to its string name */
594 dwarf_cfi_name (unsigned int cfi_opc)
598 case DW_CFA_advance_loc:
599 return "DW_CFA_advance_loc";
601 return "DW_CFA_offset";
603 return "DW_CFA_restore";
607 return "DW_CFA_set_loc";
608 case DW_CFA_advance_loc1:
609 return "DW_CFA_advance_loc1";
610 case DW_CFA_advance_loc2:
611 return "DW_CFA_advance_loc2";
612 case DW_CFA_advance_loc4:
613 return "DW_CFA_advance_loc4";
614 case DW_CFA_offset_extended:
615 return "DW_CFA_offset_extended";
616 case DW_CFA_restore_extended:
617 return "DW_CFA_restore_extended";
618 case DW_CFA_undefined:
619 return "DW_CFA_undefined";
620 case DW_CFA_same_value:
621 return "DW_CFA_same_value";
622 case DW_CFA_register:
623 return "DW_CFA_register";
624 case DW_CFA_remember_state:
625 return "DW_CFA_remember_state";
626 case DW_CFA_restore_state:
627 return "DW_CFA_restore_state";
629 return "DW_CFA_def_cfa";
630 case DW_CFA_def_cfa_register:
631 return "DW_CFA_def_cfa_register";
632 case DW_CFA_def_cfa_offset:
633 return "DW_CFA_def_cfa_offset";
636 case DW_CFA_def_cfa_expression:
637 return "DW_CFA_def_cfa_expression";
638 case DW_CFA_expression:
639 return "DW_CFA_expression";
640 case DW_CFA_offset_extended_sf:
641 return "DW_CFA_offset_extended_sf";
642 case DW_CFA_def_cfa_sf:
643 return "DW_CFA_def_cfa_sf";
644 case DW_CFA_def_cfa_offset_sf:
645 return "DW_CFA_def_cfa_offset_sf";
647 /* SGI/MIPS specific */
648 case DW_CFA_MIPS_advance_loc8:
649 return "DW_CFA_MIPS_advance_loc8";
652 case DW_CFA_GNU_window_save:
653 return "DW_CFA_GNU_window_save";
654 case DW_CFA_GNU_args_size:
655 return "DW_CFA_GNU_args_size";
656 case DW_CFA_GNU_negative_offset_extended:
657 return "DW_CFA_GNU_negative_offset_extended";
660 return "DW_CFA_<unknown>";
664 /* Return a pointer to a newly allocated Call Frame Instruction. */
666 static inline dw_cfi_ref
669 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
671 cfi->dw_cfi_next = NULL;
672 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
673 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
678 /* Add a Call Frame Instruction to list of instructions. */
681 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
684 dw_fde_ref fde = current_fde ();
686 /* When DRAP is used, CFA is defined with an expression. Redefine
687 CFA may lead to a different CFA value. */
688 if (fde && fde->drap_reg != INVALID_REGNUM)
689 switch (cfi->dw_cfi_opc)
691 case DW_CFA_def_cfa_register:
692 case DW_CFA_def_cfa_offset:
693 case DW_CFA_def_cfa_offset_sf:
695 case DW_CFA_def_cfa_sf:
702 /* Find the end of the chain. */
703 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
709 /* Generate a new label for the CFI info to refer to. FORCE is true
710 if a label needs to be output even when using .cfi_* directives. */
713 dwarf2out_cfi_label (bool force)
715 static char label[20];
717 if (!force && dwarf2out_do_cfi_asm ())
719 /* In this case, we will be emitting the asm directive instead of
720 the label, so just return a placeholder to keep the rest of the
722 strcpy (label, "<do not output>");
726 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
727 ASM_OUTPUT_LABEL (asm_out_file, label);
733 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
734 or to the CIE if LABEL is NULL. */
737 add_fde_cfi (const char *label, dw_cfi_ref cfi)
739 dw_cfi_ref *list_head = &cie_cfi_head;
741 if (dwarf2out_do_cfi_asm ())
745 dw_fde_ref fde = current_fde ();
747 gcc_assert (fde != NULL);
749 /* We still have to add the cfi to the list so that
750 lookup_cfa works later on. When -g2 and above we
751 even need to force emitting of CFI labels and
752 add to list a DW_CFA_set_loc for convert_cfa_to_fb_loc_list
754 switch (cfi->dw_cfi_opc)
756 case DW_CFA_def_cfa_offset:
757 case DW_CFA_def_cfa_offset_sf:
758 case DW_CFA_def_cfa_register:
760 case DW_CFA_def_cfa_sf:
761 case DW_CFA_def_cfa_expression:
762 case DW_CFA_restore_state:
763 if (write_symbols != DWARF2_DEBUG
764 && write_symbols != VMS_AND_DWARF2_DEBUG)
766 if (debug_info_level <= DINFO_LEVEL_TERSE)
769 if (*label == 0 || strcmp (label, "<do not output>") == 0)
770 label = dwarf2out_cfi_label (true);
772 if (fde->dw_fde_current_label == NULL
773 || strcmp (label, fde->dw_fde_current_label) != 0)
777 label = xstrdup (label);
779 /* Set the location counter to the new label. */
781 /* It doesn't metter whether DW_CFA_set_loc
782 or DW_CFA_advance_loc4 is added here, those aren't
783 emitted into assembly, only looked up by
784 convert_cfa_to_fb_loc_list. */
785 xcfi->dw_cfi_opc = DW_CFA_set_loc;
786 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
787 add_cfi (&fde->dw_fde_cfi, xcfi);
788 fde->dw_fde_current_label = label;
795 output_cfi_directive (cfi);
797 list_head = &fde->dw_fde_cfi;
799 /* ??? If this is a CFI for the CIE, we don't emit. This
800 assumes that the standard CIE contents that the assembler
801 uses matches the standard CIE contents that the compiler
802 uses. This is probably a bad assumption. I'm not quite
803 sure how to address this for now. */
807 dw_fde_ref fde = current_fde ();
809 gcc_assert (fde != NULL);
812 label = dwarf2out_cfi_label (false);
814 if (fde->dw_fde_current_label == NULL
815 || strcmp (label, fde->dw_fde_current_label) != 0)
819 label = xstrdup (label);
821 /* Set the location counter to the new label. */
823 /* If we have a current label, advance from there, otherwise
824 set the location directly using set_loc. */
825 xcfi->dw_cfi_opc = fde->dw_fde_current_label
826 ? DW_CFA_advance_loc4
828 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
829 add_cfi (&fde->dw_fde_cfi, xcfi);
831 fde->dw_fde_current_label = label;
834 list_head = &fde->dw_fde_cfi;
837 add_cfi (list_head, cfi);
840 /* Subroutine of lookup_cfa. */
843 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
845 switch (cfi->dw_cfi_opc)
847 case DW_CFA_def_cfa_offset:
848 case DW_CFA_def_cfa_offset_sf:
849 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
851 case DW_CFA_def_cfa_register:
852 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
855 case DW_CFA_def_cfa_sf:
856 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
857 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
859 case DW_CFA_def_cfa_expression:
860 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
867 /* Find the previous value for the CFA. */
870 lookup_cfa (dw_cfa_location *loc)
875 loc->reg = INVALID_REGNUM;
878 loc->base_offset = 0;
880 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
881 lookup_cfa_1 (cfi, loc);
883 fde = current_fde ();
885 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
886 lookup_cfa_1 (cfi, loc);
889 /* The current rule for calculating the DWARF2 canonical frame address. */
890 static dw_cfa_location cfa;
892 /* The register used for saving registers to the stack, and its offset
894 static dw_cfa_location cfa_store;
896 /* The running total of the size of arguments pushed onto the stack. */
897 static HOST_WIDE_INT args_size;
899 /* The last args_size we actually output. */
900 static HOST_WIDE_INT old_args_size;
902 /* Entry point to update the canonical frame address (CFA).
903 LABEL is passed to add_fde_cfi. The value of CFA is now to be
904 calculated from REG+OFFSET. */
907 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
914 def_cfa_1 (label, &loc);
917 /* Determine if two dw_cfa_location structures define the same data. */
920 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
922 return (loc1->reg == loc2->reg
923 && loc1->offset == loc2->offset
924 && loc1->indirect == loc2->indirect
925 && (loc1->indirect == 0
926 || loc1->base_offset == loc2->base_offset));
929 /* This routine does the actual work. The CFA is now calculated from
930 the dw_cfa_location structure. */
933 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
936 dw_cfa_location old_cfa, loc;
941 if (cfa_store.reg == loc.reg && loc.indirect == 0)
942 cfa_store.offset = loc.offset;
944 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
945 lookup_cfa (&old_cfa);
947 /* If nothing changed, no need to issue any call frame instructions. */
948 if (cfa_equal_p (&loc, &old_cfa))
953 if (loc.reg == old_cfa.reg && !loc.indirect)
955 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
956 the CFA register did not change but the offset did. The data
957 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
958 in the assembler via the .cfi_def_cfa_offset directive. */
960 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
962 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
963 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
966 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
967 else if (loc.offset == old_cfa.offset
968 && old_cfa.reg != INVALID_REGNUM
971 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
972 indicating the CFA register has changed to <register> but the
973 offset has not changed. */
974 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
975 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
979 else if (loc.indirect == 0)
981 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
982 indicating the CFA register has changed to <register> with
983 the specified offset. The data factoring for DW_CFA_def_cfa_sf
984 happens in output_cfi, or in the assembler via the .cfi_def_cfa
987 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
989 cfi->dw_cfi_opc = DW_CFA_def_cfa;
990 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
991 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
995 /* Construct a DW_CFA_def_cfa_expression instruction to
996 calculate the CFA using a full location expression since no
997 register-offset pair is available. */
998 struct dw_loc_descr_struct *loc_list;
1000 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1001 loc_list = build_cfa_loc (&loc, 0);
1002 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1005 add_fde_cfi (label, cfi);
1008 /* Add the CFI for saving a register. REG is the CFA column number.
1009 LABEL is passed to add_fde_cfi.
1010 If SREG is -1, the register is saved at OFFSET from the CFA;
1011 otherwise it is saved in SREG. */
1014 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1016 dw_cfi_ref cfi = new_cfi ();
1017 dw_fde_ref fde = current_fde ();
1019 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1021 /* When stack is aligned, store REG using DW_CFA_expression with
1024 && fde->stack_realign
1025 && sreg == INVALID_REGNUM)
1027 cfi->dw_cfi_opc = DW_CFA_expression;
1028 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
1029 cfi->dw_cfi_oprnd1.dw_cfi_loc
1030 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1032 else if (sreg == INVALID_REGNUM)
1035 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1036 else if (reg & ~0x3f)
1037 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1039 cfi->dw_cfi_opc = DW_CFA_offset;
1040 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1042 else if (sreg == reg)
1043 cfi->dw_cfi_opc = DW_CFA_same_value;
1046 cfi->dw_cfi_opc = DW_CFA_register;
1047 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1050 add_fde_cfi (label, cfi);
1053 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1054 This CFI tells the unwinder that it needs to restore the window registers
1055 from the previous frame's window save area.
1057 ??? Perhaps we should note in the CIE where windows are saved (instead of
1058 assuming 0(cfa)) and what registers are in the window. */
1061 dwarf2out_window_save (const char *label)
1063 dw_cfi_ref cfi = new_cfi ();
1065 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1066 add_fde_cfi (label, cfi);
1069 /* Add a CFI to update the running total of the size of arguments
1070 pushed onto the stack. */
1073 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1077 if (size == old_args_size)
1080 old_args_size = size;
1083 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1084 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1085 add_fde_cfi (label, cfi);
1088 /* Entry point for saving a register to the stack. REG is the GCC register
1089 number. LABEL and OFFSET are passed to reg_save. */
1092 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1094 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1097 /* Entry point for saving the return address in the stack.
1098 LABEL and OFFSET are passed to reg_save. */
1101 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1103 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1106 /* Entry point for saving the return address in a register.
1107 LABEL and SREG are passed to reg_save. */
1110 dwarf2out_return_reg (const char *label, unsigned int sreg)
1112 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1115 #ifdef DWARF2_UNWIND_INFO
1116 /* Record the initial position of the return address. RTL is
1117 INCOMING_RETURN_ADDR_RTX. */
1120 initial_return_save (rtx rtl)
1122 unsigned int reg = INVALID_REGNUM;
1123 HOST_WIDE_INT offset = 0;
1125 switch (GET_CODE (rtl))
1128 /* RA is in a register. */
1129 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1133 /* RA is on the stack. */
1134 rtl = XEXP (rtl, 0);
1135 switch (GET_CODE (rtl))
1138 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1143 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1144 offset = INTVAL (XEXP (rtl, 1));
1148 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1149 offset = -INTVAL (XEXP (rtl, 1));
1159 /* The return address is at some offset from any value we can
1160 actually load. For instance, on the SPARC it is in %i7+8. Just
1161 ignore the offset for now; it doesn't matter for unwinding frames. */
1162 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1163 initial_return_save (XEXP (rtl, 0));
1170 if (reg != DWARF_FRAME_RETURN_COLUMN)
1171 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1175 /* Given a SET, calculate the amount of stack adjustment it
1178 static HOST_WIDE_INT
1179 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1180 HOST_WIDE_INT cur_offset)
1182 const_rtx src = SET_SRC (pattern);
1183 const_rtx dest = SET_DEST (pattern);
1184 HOST_WIDE_INT offset = 0;
1187 if (dest == stack_pointer_rtx)
1189 code = GET_CODE (src);
1191 /* Assume (set (reg sp) (reg whatever)) sets args_size
1193 if (code == REG && src != stack_pointer_rtx)
1195 offset = -cur_args_size;
1196 #ifndef STACK_GROWS_DOWNWARD
1199 return offset - cur_offset;
1202 if (! (code == PLUS || code == MINUS)
1203 || XEXP (src, 0) != stack_pointer_rtx
1204 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1207 /* (set (reg sp) (plus (reg sp) (const_int))) */
1208 offset = INTVAL (XEXP (src, 1));
1214 if (MEM_P (src) && !MEM_P (dest))
1218 /* (set (mem (pre_dec (reg sp))) (foo)) */
1219 src = XEXP (dest, 0);
1220 code = GET_CODE (src);
1226 if (XEXP (src, 0) == stack_pointer_rtx)
1228 rtx val = XEXP (XEXP (src, 1), 1);
1229 /* We handle only adjustments by constant amount. */
1230 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1231 && GET_CODE (val) == CONST_INT);
1232 offset = -INTVAL (val);
1239 if (XEXP (src, 0) == stack_pointer_rtx)
1241 offset = GET_MODE_SIZE (GET_MODE (dest));
1248 if (XEXP (src, 0) == stack_pointer_rtx)
1250 offset = -GET_MODE_SIZE (GET_MODE (dest));
1265 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1266 indexed by INSN_UID. */
1268 static HOST_WIDE_INT *barrier_args_size;
1270 /* Helper function for compute_barrier_args_size. Handle one insn. */
1272 static HOST_WIDE_INT
1273 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1274 VEC (rtx, heap) **next)
1276 HOST_WIDE_INT offset = 0;
1279 if (! RTX_FRAME_RELATED_P (insn))
1281 if (prologue_epilogue_contains (insn)
1282 || sibcall_epilogue_contains (insn))
1284 else if (GET_CODE (PATTERN (insn)) == SET)
1285 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1286 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1287 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1289 /* There may be stack adjustments inside compound insns. Search
1291 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1292 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1293 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1294 cur_args_size, offset);
1299 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1303 expr = XEXP (expr, 0);
1304 if (GET_CODE (expr) == PARALLEL
1305 || GET_CODE (expr) == SEQUENCE)
1306 for (i = 1; i < XVECLEN (expr, 0); i++)
1308 rtx elem = XVECEXP (expr, 0, i);
1310 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1311 offset += stack_adjust_offset (elem, cur_args_size, offset);
1316 #ifndef STACK_GROWS_DOWNWARD
1320 cur_args_size += offset;
1321 if (cur_args_size < 0)
1326 rtx dest = JUMP_LABEL (insn);
1330 if (barrier_args_size [INSN_UID (dest)] < 0)
1332 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1333 VEC_safe_push (rtx, heap, *next, dest);
1338 return cur_args_size;
1341 /* Walk the whole function and compute args_size on BARRIERs. */
1344 compute_barrier_args_size (void)
1346 int max_uid = get_max_uid (), i;
1348 VEC (rtx, heap) *worklist, *next, *tmp;
1350 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1351 for (i = 0; i < max_uid; i++)
1352 barrier_args_size[i] = -1;
1354 worklist = VEC_alloc (rtx, heap, 20);
1355 next = VEC_alloc (rtx, heap, 20);
1356 insn = get_insns ();
1357 barrier_args_size[INSN_UID (insn)] = 0;
1358 VEC_quick_push (rtx, worklist, insn);
1361 while (!VEC_empty (rtx, worklist))
1363 rtx prev, body, first_insn;
1364 HOST_WIDE_INT cur_args_size;
1366 first_insn = insn = VEC_pop (rtx, worklist);
1367 cur_args_size = barrier_args_size[INSN_UID (insn)];
1368 prev = prev_nonnote_insn (insn);
1369 if (prev && BARRIER_P (prev))
1370 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1372 for (; insn; insn = NEXT_INSN (insn))
1374 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1376 if (BARRIER_P (insn))
1381 if (insn == first_insn)
1383 else if (barrier_args_size[INSN_UID (insn)] < 0)
1385 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1390 /* The insns starting with this label have been
1391 already scanned or are in the worklist. */
1396 body = PATTERN (insn);
1397 if (GET_CODE (body) == SEQUENCE)
1399 HOST_WIDE_INT dest_args_size = cur_args_size;
1400 for (i = 1; i < XVECLEN (body, 0); i++)
1401 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1402 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1404 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1405 dest_args_size, &next);
1408 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1409 cur_args_size, &next);
1411 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1412 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1413 dest_args_size, &next);
1416 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1417 cur_args_size, &next);
1421 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1425 if (VEC_empty (rtx, next))
1428 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1432 VEC_truncate (rtx, next, 0);
1435 VEC_free (rtx, heap, worklist);
1436 VEC_free (rtx, heap, next);
1440 /* Check INSN to see if it looks like a push or a stack adjustment, and
1441 make a note of it if it does. EH uses this information to find out how
1442 much extra space it needs to pop off the stack. */
1445 dwarf2out_stack_adjust (rtx insn, bool after_p)
1447 HOST_WIDE_INT offset;
1451 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1452 with this function. Proper support would require all frame-related
1453 insns to be marked, and to be able to handle saving state around
1454 epilogues textually in the middle of the function. */
1455 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1458 /* If INSN is an instruction from target of an annulled branch, the
1459 effects are for the target only and so current argument size
1460 shouldn't change at all. */
1462 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1463 && INSN_FROM_TARGET_P (insn))
1466 /* If only calls can throw, and we have a frame pointer,
1467 save up adjustments until we see the CALL_INSN. */
1468 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1470 if (CALL_P (insn) && !after_p)
1472 /* Extract the size of the args from the CALL rtx itself. */
1473 insn = PATTERN (insn);
1474 if (GET_CODE (insn) == PARALLEL)
1475 insn = XVECEXP (insn, 0, 0);
1476 if (GET_CODE (insn) == SET)
1477 insn = SET_SRC (insn);
1478 gcc_assert (GET_CODE (insn) == CALL);
1479 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1484 if (CALL_P (insn) && !after_p)
1486 if (!flag_asynchronous_unwind_tables)
1487 dwarf2out_args_size ("", args_size);
1490 else if (BARRIER_P (insn))
1492 /* Don't call compute_barrier_args_size () if the only
1493 BARRIER is at the end of function. */
1494 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1495 compute_barrier_args_size ();
1496 if (barrier_args_size == NULL)
1500 offset = barrier_args_size[INSN_UID (insn)];
1505 offset -= args_size;
1506 #ifndef STACK_GROWS_DOWNWARD
1510 else if (GET_CODE (PATTERN (insn)) == SET)
1511 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1512 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1513 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1515 /* There may be stack adjustments inside compound insns. Search
1517 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1518 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1519 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1528 label = dwarf2out_cfi_label (false);
1529 dwarf2out_args_size_adjust (offset, label);
1532 /* Adjust args_size based on stack adjustment OFFSET. */
1535 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1537 if (cfa.reg == STACK_POINTER_REGNUM)
1538 cfa.offset += offset;
1540 if (cfa_store.reg == STACK_POINTER_REGNUM)
1541 cfa_store.offset += offset;
1543 #ifndef STACK_GROWS_DOWNWARD
1547 args_size += offset;
1551 def_cfa_1 (label, &cfa);
1552 if (flag_asynchronous_unwind_tables)
1553 dwarf2out_args_size (label, args_size);
1558 /* We delay emitting a register save until either (a) we reach the end
1559 of the prologue or (b) the register is clobbered. This clusters
1560 register saves so that there are fewer pc advances. */
1562 struct queued_reg_save GTY(())
1564 struct queued_reg_save *next;
1566 HOST_WIDE_INT cfa_offset;
1570 static GTY(()) struct queued_reg_save *queued_reg_saves;
1572 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1573 struct reg_saved_in_data GTY(()) {
1578 /* A list of registers saved in other registers.
1579 The list intentionally has a small maximum capacity of 4; if your
1580 port needs more than that, you might consider implementing a
1581 more efficient data structure. */
1582 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1583 static GTY(()) size_t num_regs_saved_in_regs;
1585 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1586 static const char *last_reg_save_label;
1588 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1589 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1592 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1594 struct queued_reg_save *q;
1596 /* Duplicates waste space, but it's also necessary to remove them
1597 for correctness, since the queue gets output in reverse
1599 for (q = queued_reg_saves; q != NULL; q = q->next)
1600 if (REGNO (q->reg) == REGNO (reg))
1605 q = GGC_NEW (struct queued_reg_save);
1606 q->next = queued_reg_saves;
1607 queued_reg_saves = q;
1611 q->cfa_offset = offset;
1612 q->saved_reg = sreg;
1614 last_reg_save_label = label;
1617 /* Output all the entries in QUEUED_REG_SAVES. */
1620 flush_queued_reg_saves (void)
1622 struct queued_reg_save *q;
1624 for (q = queued_reg_saves; q; q = q->next)
1627 unsigned int reg, sreg;
1629 for (i = 0; i < num_regs_saved_in_regs; i++)
1630 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1632 if (q->saved_reg && i == num_regs_saved_in_regs)
1634 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1635 num_regs_saved_in_regs++;
1637 if (i != num_regs_saved_in_regs)
1639 regs_saved_in_regs[i].orig_reg = q->reg;
1640 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1643 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1645 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1647 sreg = INVALID_REGNUM;
1648 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1651 queued_reg_saves = NULL;
1652 last_reg_save_label = NULL;
1655 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1656 location for? Or, does it clobber a register which we've previously
1657 said that some other register is saved in, and for which we now
1658 have a new location for? */
1661 clobbers_queued_reg_save (const_rtx insn)
1663 struct queued_reg_save *q;
1665 for (q = queued_reg_saves; q; q = q->next)
1668 if (modified_in_p (q->reg, insn))
1670 for (i = 0; i < num_regs_saved_in_regs; i++)
1671 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1672 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1679 /* Entry point for saving the first register into the second. */
1682 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1685 unsigned int regno, sregno;
1687 for (i = 0; i < num_regs_saved_in_regs; i++)
1688 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1690 if (i == num_regs_saved_in_regs)
1692 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1693 num_regs_saved_in_regs++;
1695 regs_saved_in_regs[i].orig_reg = reg;
1696 regs_saved_in_regs[i].saved_in_reg = sreg;
1698 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1699 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1700 reg_save (label, regno, sregno, 0);
1703 /* What register, if any, is currently saved in REG? */
1706 reg_saved_in (rtx reg)
1708 unsigned int regn = REGNO (reg);
1710 struct queued_reg_save *q;
1712 for (q = queued_reg_saves; q; q = q->next)
1713 if (q->saved_reg && regn == REGNO (q->saved_reg))
1716 for (i = 0; i < num_regs_saved_in_regs; i++)
1717 if (regs_saved_in_regs[i].saved_in_reg
1718 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1719 return regs_saved_in_regs[i].orig_reg;
1725 /* A temporary register holding an integral value used in adjusting SP
1726 or setting up the store_reg. The "offset" field holds the integer
1727 value, not an offset. */
1728 static dw_cfa_location cfa_temp;
1730 /* Record call frame debugging information for an expression EXPR,
1731 which either sets SP or FP (adjusting how we calculate the frame
1732 address) or saves a register to the stack or another register.
1733 LABEL indicates the address of EXPR.
1735 This function encodes a state machine mapping rtxes to actions on
1736 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1737 users need not read the source code.
1739 The High-Level Picture
1741 Changes in the register we use to calculate the CFA: Currently we
1742 assume that if you copy the CFA register into another register, we
1743 should take the other one as the new CFA register; this seems to
1744 work pretty well. If it's wrong for some target, it's simple
1745 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1747 Changes in the register we use for saving registers to the stack:
1748 This is usually SP, but not always. Again, we deduce that if you
1749 copy SP into another register (and SP is not the CFA register),
1750 then the new register is the one we will be using for register
1751 saves. This also seems to work.
1753 Register saves: There's not much guesswork about this one; if
1754 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1755 register save, and the register used to calculate the destination
1756 had better be the one we think we're using for this purpose.
1757 It's also assumed that a copy from a call-saved register to another
1758 register is saving that register if RTX_FRAME_RELATED_P is set on
1759 that instruction. If the copy is from a call-saved register to
1760 the *same* register, that means that the register is now the same
1761 value as in the caller.
1763 Except: If the register being saved is the CFA register, and the
1764 offset is nonzero, we are saving the CFA, so we assume we have to
1765 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1766 the intent is to save the value of SP from the previous frame.
1768 In addition, if a register has previously been saved to a different
1771 Invariants / Summaries of Rules
1773 cfa current rule for calculating the CFA. It usually
1774 consists of a register and an offset.
1775 cfa_store register used by prologue code to save things to the stack
1776 cfa_store.offset is the offset from the value of
1777 cfa_store.reg to the actual CFA
1778 cfa_temp register holding an integral value. cfa_temp.offset
1779 stores the value, which will be used to adjust the
1780 stack pointer. cfa_temp is also used like cfa_store,
1781 to track stores to the stack via fp or a temp reg.
1783 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1784 with cfa.reg as the first operand changes the cfa.reg and its
1785 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1788 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1789 expression yielding a constant. This sets cfa_temp.reg
1790 and cfa_temp.offset.
1792 Rule 5: Create a new register cfa_store used to save items to the
1795 Rules 10-14: Save a register to the stack. Define offset as the
1796 difference of the original location and cfa_store's
1797 location (or cfa_temp's location if cfa_temp is used).
1799 Rules 16-20: If AND operation happens on sp in prologue, we assume
1800 stack is realigned. We will use a group of DW_OP_XXX
1801 expressions to represent the location of the stored
1802 register instead of CFA+offset.
1806 "{a,b}" indicates a choice of a xor b.
1807 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1810 (set <reg1> <reg2>:cfa.reg)
1811 effects: cfa.reg = <reg1>
1812 cfa.offset unchanged
1813 cfa_temp.reg = <reg1>
1814 cfa_temp.offset = cfa.offset
1817 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1818 {<const_int>,<reg>:cfa_temp.reg}))
1819 effects: cfa.reg = sp if fp used
1820 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1821 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1822 if cfa_store.reg==sp
1825 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1826 effects: cfa.reg = fp
1827 cfa_offset += +/- <const_int>
1830 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1831 constraints: <reg1> != fp
1833 effects: cfa.reg = <reg1>
1834 cfa_temp.reg = <reg1>
1835 cfa_temp.offset = cfa.offset
1838 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1839 constraints: <reg1> != fp
1841 effects: cfa_store.reg = <reg1>
1842 cfa_store.offset = cfa.offset - cfa_temp.offset
1845 (set <reg> <const_int>)
1846 effects: cfa_temp.reg = <reg>
1847 cfa_temp.offset = <const_int>
1850 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1851 effects: cfa_temp.reg = <reg1>
1852 cfa_temp.offset |= <const_int>
1855 (set <reg> (high <exp>))
1859 (set <reg> (lo_sum <exp> <const_int>))
1860 effects: cfa_temp.reg = <reg>
1861 cfa_temp.offset = <const_int>
1864 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1865 effects: cfa_store.offset -= <const_int>
1866 cfa.offset = cfa_store.offset if cfa.reg == sp
1868 cfa.base_offset = -cfa_store.offset
1871 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1872 effects: cfa_store.offset += -/+ mode_size(mem)
1873 cfa.offset = cfa_store.offset if cfa.reg == sp
1875 cfa.base_offset = -cfa_store.offset
1878 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1881 effects: cfa.reg = <reg1>
1882 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1885 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1886 effects: cfa.reg = <reg1>
1887 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1890 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1891 effects: cfa.reg = <reg1>
1892 cfa.base_offset = -cfa_temp.offset
1893 cfa_temp.offset -= mode_size(mem)
1896 (set <reg> {unspec, unspec_volatile})
1897 effects: target-dependent
1900 (set sp (and: sp <const_int>))
1901 constraints: cfa_store.reg == sp
1902 effects: current_fde.stack_realign = 1
1903 cfa_store.offset = 0
1904 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1907 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1908 effects: cfa_store.offset += -/+ mode_size(mem)
1911 (set (mem ({pre_inc, pre_dec} sp)) fp)
1912 constraints: fde->stack_realign == 1
1913 effects: cfa_store.offset = 0
1914 cfa.reg != HARD_FRAME_POINTER_REGNUM
1917 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1918 constraints: fde->stack_realign == 1
1920 && cfa.indirect == 0
1921 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1922 effects: Use DW_CFA_def_cfa_expression to define cfa
1923 cfa.reg == fde->drap_reg
1926 (set reg fde->drap_reg)
1927 constraints: fde->vdrap_reg == INVALID_REGNUM
1928 effects: fde->vdrap_reg = reg.
1929 (set mem fde->drap_reg)
1930 constraints: fde->drap_reg_saved == 1
1934 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1936 rtx src, dest, span;
1937 HOST_WIDE_INT offset;
1940 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1941 the PARALLEL independently. The first element is always processed if
1942 it is a SET. This is for backward compatibility. Other elements
1943 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1944 flag is set in them. */
1945 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1948 int limit = XVECLEN (expr, 0);
1951 /* PARALLELs have strict read-modify-write semantics, so we
1952 ought to evaluate every rvalue before changing any lvalue.
1953 It's cumbersome to do that in general, but there's an
1954 easy approximation that is enough for all current users:
1955 handle register saves before register assignments. */
1956 if (GET_CODE (expr) == PARALLEL)
1957 for (par_index = 0; par_index < limit; par_index++)
1959 elem = XVECEXP (expr, 0, par_index);
1960 if (GET_CODE (elem) == SET
1961 && MEM_P (SET_DEST (elem))
1962 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1963 dwarf2out_frame_debug_expr (elem, label);
1966 for (par_index = 0; par_index < limit; par_index++)
1968 elem = XVECEXP (expr, 0, par_index);
1969 if (GET_CODE (elem) == SET
1970 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1971 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1972 dwarf2out_frame_debug_expr (elem, label);
1973 else if (GET_CODE (elem) == SET
1975 && !RTX_FRAME_RELATED_P (elem))
1977 /* Stack adjustment combining might combine some post-prologue
1978 stack adjustment into a prologue stack adjustment. */
1979 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
1982 dwarf2out_args_size_adjust (offset, label);
1988 gcc_assert (GET_CODE (expr) == SET);
1990 src = SET_SRC (expr);
1991 dest = SET_DEST (expr);
1995 rtx rsi = reg_saved_in (src);
2000 fde = current_fde ();
2002 if (GET_CODE (src) == REG
2004 && fde->drap_reg == REGNO (src)
2005 && (fde->drap_reg_saved
2006 || GET_CODE (dest) == REG))
2009 /* If we are saving dynamic realign argument pointer to a
2010 register, the destination is virtual dynamic realign
2011 argument pointer. It may be used to access argument. */
2012 if (GET_CODE (dest) == REG)
2014 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2015 fde->vdrap_reg = REGNO (dest);
2020 switch (GET_CODE (dest))
2023 switch (GET_CODE (src))
2025 /* Setting FP from SP. */
2027 if (cfa.reg == (unsigned) REGNO (src))
2030 /* Update the CFA rule wrt SP or FP. Make sure src is
2031 relative to the current CFA register.
2033 We used to require that dest be either SP or FP, but the
2034 ARM copies SP to a temporary register, and from there to
2035 FP. So we just rely on the backends to only set
2036 RTX_FRAME_RELATED_P on appropriate insns. */
2037 cfa.reg = REGNO (dest);
2038 cfa_temp.reg = cfa.reg;
2039 cfa_temp.offset = cfa.offset;
2043 /* Saving a register in a register. */
2044 gcc_assert (!fixed_regs [REGNO (dest)]
2045 /* For the SPARC and its register window. */
2046 || (DWARF_FRAME_REGNUM (REGNO (src))
2047 == DWARF_FRAME_RETURN_COLUMN));
2049 /* After stack is aligned, we can only save SP in FP
2050 if drap register is used. In this case, we have
2051 to restore stack pointer with the CFA value and we
2052 don't generate this DWARF information. */
2054 && fde->stack_realign
2055 && REGNO (src) == STACK_POINTER_REGNUM)
2056 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2057 && fde->drap_reg != INVALID_REGNUM
2058 && cfa.reg != REGNO (src));
2060 queue_reg_save (label, src, dest, 0);
2067 if (dest == stack_pointer_rtx)
2071 switch (GET_CODE (XEXP (src, 1)))
2074 offset = INTVAL (XEXP (src, 1));
2077 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2079 offset = cfa_temp.offset;
2085 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2087 /* Restoring SP from FP in the epilogue. */
2088 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2089 cfa.reg = STACK_POINTER_REGNUM;
2091 else if (GET_CODE (src) == LO_SUM)
2092 /* Assume we've set the source reg of the LO_SUM from sp. */
2095 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2097 if (GET_CODE (src) != MINUS)
2099 if (cfa.reg == STACK_POINTER_REGNUM)
2100 cfa.offset += offset;
2101 if (cfa_store.reg == STACK_POINTER_REGNUM)
2102 cfa_store.offset += offset;
2104 else if (dest == hard_frame_pointer_rtx)
2107 /* Either setting the FP from an offset of the SP,
2108 or adjusting the FP */
2109 gcc_assert (frame_pointer_needed);
2111 gcc_assert (REG_P (XEXP (src, 0))
2112 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2113 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2114 offset = INTVAL (XEXP (src, 1));
2115 if (GET_CODE (src) != MINUS)
2117 cfa.offset += offset;
2118 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2122 gcc_assert (GET_CODE (src) != MINUS);
2125 if (REG_P (XEXP (src, 0))
2126 && REGNO (XEXP (src, 0)) == cfa.reg
2127 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2129 /* Setting a temporary CFA register that will be copied
2130 into the FP later on. */
2131 offset = - INTVAL (XEXP (src, 1));
2132 cfa.offset += offset;
2133 cfa.reg = REGNO (dest);
2134 /* Or used to save regs to the stack. */
2135 cfa_temp.reg = cfa.reg;
2136 cfa_temp.offset = cfa.offset;
2140 else if (REG_P (XEXP (src, 0))
2141 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2142 && XEXP (src, 1) == stack_pointer_rtx)
2144 /* Setting a scratch register that we will use instead
2145 of SP for saving registers to the stack. */
2146 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2147 cfa_store.reg = REGNO (dest);
2148 cfa_store.offset = cfa.offset - cfa_temp.offset;
2152 else if (GET_CODE (src) == LO_SUM
2153 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2155 cfa_temp.reg = REGNO (dest);
2156 cfa_temp.offset = INTVAL (XEXP (src, 1));
2165 cfa_temp.reg = REGNO (dest);
2166 cfa_temp.offset = INTVAL (src);
2171 gcc_assert (REG_P (XEXP (src, 0))
2172 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2173 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2175 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2176 cfa_temp.reg = REGNO (dest);
2177 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2180 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2181 which will fill in all of the bits. */
2188 case UNSPEC_VOLATILE:
2189 gcc_assert (targetm.dwarf_handle_frame_unspec);
2190 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2195 /* If this AND operation happens on stack pointer in prologue,
2196 we assume the stack is realigned and we extract the
2198 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2200 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2201 fde->stack_realign = 1;
2202 fde->stack_realignment = INTVAL (XEXP (src, 1));
2203 cfa_store.offset = 0;
2205 if (cfa.reg != STACK_POINTER_REGNUM
2206 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2207 fde->drap_reg = cfa.reg;
2215 def_cfa_1 (label, &cfa);
2220 /* Saving a register to the stack. Make sure dest is relative to the
2222 switch (GET_CODE (XEXP (dest, 0)))
2227 /* We can't handle variable size modifications. */
2228 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2230 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2232 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2233 && cfa_store.reg == STACK_POINTER_REGNUM);
2235 cfa_store.offset += offset;
2236 if (cfa.reg == STACK_POINTER_REGNUM)
2237 cfa.offset = cfa_store.offset;
2239 offset = -cfa_store.offset;
2245 offset = GET_MODE_SIZE (GET_MODE (dest));
2246 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2249 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2250 == STACK_POINTER_REGNUM)
2251 && cfa_store.reg == STACK_POINTER_REGNUM);
2253 cfa_store.offset += offset;
2255 /* Rule 18: If stack is aligned, we will use FP as a
2256 reference to represent the address of the stored
2259 && fde->stack_realign
2260 && src == hard_frame_pointer_rtx)
2262 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2263 cfa_store.offset = 0;
2266 if (cfa.reg == STACK_POINTER_REGNUM)
2267 cfa.offset = cfa_store.offset;
2269 offset = -cfa_store.offset;
2273 /* With an offset. */
2280 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
2281 && REG_P (XEXP (XEXP (dest, 0), 0)));
2282 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2283 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2286 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2288 if (cfa_store.reg == (unsigned) regno)
2289 offset -= cfa_store.offset;
2292 gcc_assert (cfa_temp.reg == (unsigned) regno);
2293 offset -= cfa_temp.offset;
2299 /* Without an offset. */
2302 int regno = REGNO (XEXP (dest, 0));
2304 if (cfa_store.reg == (unsigned) regno)
2305 offset = -cfa_store.offset;
2308 gcc_assert (cfa_temp.reg == (unsigned) regno);
2309 offset = -cfa_temp.offset;
2316 gcc_assert (cfa_temp.reg
2317 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2318 offset = -cfa_temp.offset;
2319 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2327 /* If the source operand of this MEM operation is not a
2328 register, basically the source is return address. Here
2329 we only care how much stack grew and we don't save it. */
2333 if (REGNO (src) != STACK_POINTER_REGNUM
2334 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2335 && (unsigned) REGNO (src) == cfa.reg)
2337 /* We're storing the current CFA reg into the stack. */
2339 if (cfa.offset == 0)
2342 /* If stack is aligned, putting CFA reg into stack means
2343 we can no longer use reg + offset to represent CFA.
2344 Here we use DW_CFA_def_cfa_expression instead. The
2345 result of this expression equals to the original CFA
2348 && fde->stack_realign
2349 && cfa.indirect == 0
2350 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2352 dw_cfa_location cfa_exp;
2354 gcc_assert (fde->drap_reg == cfa.reg);
2356 cfa_exp.indirect = 1;
2357 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2358 cfa_exp.base_offset = offset;
2361 fde->drap_reg_saved = 1;
2363 def_cfa_1 (label, &cfa_exp);
2367 /* If the source register is exactly the CFA, assume
2368 we're saving SP like any other register; this happens
2370 def_cfa_1 (label, &cfa);
2371 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2376 /* Otherwise, we'll need to look in the stack to
2377 calculate the CFA. */
2378 rtx x = XEXP (dest, 0);
2382 gcc_assert (REG_P (x));
2384 cfa.reg = REGNO (x);
2385 cfa.base_offset = offset;
2387 def_cfa_1 (label, &cfa);
2392 def_cfa_1 (label, &cfa);
2394 span = targetm.dwarf_register_span (src);
2397 queue_reg_save (label, src, NULL_RTX, offset);
2400 /* We have a PARALLEL describing where the contents of SRC
2401 live. Queue register saves for each piece of the
2405 HOST_WIDE_INT span_offset = offset;
2407 gcc_assert (GET_CODE (span) == PARALLEL);
2409 limit = XVECLEN (span, 0);
2410 for (par_index = 0; par_index < limit; par_index++)
2412 rtx elem = XVECEXP (span, 0, par_index);
2414 queue_reg_save (label, elem, NULL_RTX, span_offset);
2415 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2426 /* Record call frame debugging information for INSN, which either
2427 sets SP or FP (adjusting how we calculate the frame address) or saves a
2428 register to the stack. If INSN is NULL_RTX, initialize our state.
2430 If AFTER_P is false, we're being called before the insn is emitted,
2431 otherwise after. Call instructions get invoked twice. */
2434 dwarf2out_frame_debug (rtx insn, bool after_p)
2439 if (insn == NULL_RTX)
2443 /* Flush any queued register saves. */
2444 flush_queued_reg_saves ();
2446 /* Set up state for generating call frame debug info. */
2449 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2451 cfa.reg = STACK_POINTER_REGNUM;
2454 cfa_temp.offset = 0;
2456 for (i = 0; i < num_regs_saved_in_regs; i++)
2458 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2459 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2461 num_regs_saved_in_regs = 0;
2463 if (barrier_args_size)
2465 XDELETEVEC (barrier_args_size);
2466 barrier_args_size = NULL;
2471 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2472 flush_queued_reg_saves ();
2474 if (! RTX_FRAME_RELATED_P (insn))
2476 if (!ACCUMULATE_OUTGOING_ARGS)
2477 dwarf2out_stack_adjust (insn, after_p);
2481 label = dwarf2out_cfi_label (false);
2482 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
2484 insn = XEXP (src, 0);
2486 insn = PATTERN (insn);
2488 dwarf2out_frame_debug_expr (insn, label);
2493 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2494 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2495 (enum dwarf_call_frame_info cfi);
2497 static enum dw_cfi_oprnd_type
2498 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2503 case DW_CFA_GNU_window_save:
2504 return dw_cfi_oprnd_unused;
2506 case DW_CFA_set_loc:
2507 case DW_CFA_advance_loc1:
2508 case DW_CFA_advance_loc2:
2509 case DW_CFA_advance_loc4:
2510 case DW_CFA_MIPS_advance_loc8:
2511 return dw_cfi_oprnd_addr;
2514 case DW_CFA_offset_extended:
2515 case DW_CFA_def_cfa:
2516 case DW_CFA_offset_extended_sf:
2517 case DW_CFA_def_cfa_sf:
2518 case DW_CFA_restore_extended:
2519 case DW_CFA_undefined:
2520 case DW_CFA_same_value:
2521 case DW_CFA_def_cfa_register:
2522 case DW_CFA_register:
2523 return dw_cfi_oprnd_reg_num;
2525 case DW_CFA_def_cfa_offset:
2526 case DW_CFA_GNU_args_size:
2527 case DW_CFA_def_cfa_offset_sf:
2528 return dw_cfi_oprnd_offset;
2530 case DW_CFA_def_cfa_expression:
2531 case DW_CFA_expression:
2532 return dw_cfi_oprnd_loc;
2539 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2540 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2541 (enum dwarf_call_frame_info cfi);
2543 static enum dw_cfi_oprnd_type
2544 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2548 case DW_CFA_def_cfa:
2549 case DW_CFA_def_cfa_sf:
2551 case DW_CFA_offset_extended_sf:
2552 case DW_CFA_offset_extended:
2553 return dw_cfi_oprnd_offset;
2555 case DW_CFA_register:
2556 return dw_cfi_oprnd_reg_num;
2559 return dw_cfi_oprnd_unused;
2563 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2565 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2566 switch to the data section instead, and write out a synthetic label
2570 switch_to_eh_frame_section (void)
2574 #ifdef EH_FRAME_SECTION_NAME
2575 if (eh_frame_section == 0)
2579 if (EH_TABLES_CAN_BE_READ_ONLY)
2585 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2587 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2589 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2591 flags = ((! flag_pic
2592 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2593 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2594 && (per_encoding & 0x70) != DW_EH_PE_absptr
2595 && (per_encoding & 0x70) != DW_EH_PE_aligned
2596 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2597 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2598 ? 0 : SECTION_WRITE);
2601 flags = SECTION_WRITE;
2602 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2606 if (eh_frame_section)
2607 switch_to_section (eh_frame_section);
2610 /* We have no special eh_frame section. Put the information in
2611 the data section and emit special labels to guide collect2. */
2612 switch_to_section (data_section);
2613 label = get_file_function_name ("F");
2614 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2615 targetm.asm_out.globalize_label (asm_out_file,
2616 IDENTIFIER_POINTER (label));
2617 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2621 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
2623 static HOST_WIDE_INT
2624 div_data_align (HOST_WIDE_INT off)
2626 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
2627 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
2631 /* Output a Call Frame Information opcode and its operand(s). */
2634 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2639 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2640 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2641 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2642 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2643 ((unsigned HOST_WIDE_INT)
2644 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2645 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2647 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2648 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2649 "DW_CFA_offset, column 0x%lx", r);
2650 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2651 dw2_asm_output_data_uleb128 (off, NULL);
2653 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2655 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2656 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2657 "DW_CFA_restore, column 0x%lx", r);
2661 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2662 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2664 switch (cfi->dw_cfi_opc)
2666 case DW_CFA_set_loc:
2668 dw2_asm_output_encoded_addr_rtx (
2669 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2670 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2673 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2674 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2675 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2678 case DW_CFA_advance_loc1:
2679 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2680 fde->dw_fde_current_label, NULL);
2681 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2684 case DW_CFA_advance_loc2:
2685 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2686 fde->dw_fde_current_label, NULL);
2687 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2690 case DW_CFA_advance_loc4:
2691 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2692 fde->dw_fde_current_label, NULL);
2693 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2696 case DW_CFA_MIPS_advance_loc8:
2697 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2698 fde->dw_fde_current_label, NULL);
2699 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2702 case DW_CFA_offset_extended:
2703 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2704 dw2_asm_output_data_uleb128 (r, NULL);
2705 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2706 dw2_asm_output_data_uleb128 (off, NULL);
2709 case DW_CFA_def_cfa:
2710 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2711 dw2_asm_output_data_uleb128 (r, NULL);
2712 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2715 case DW_CFA_offset_extended_sf:
2716 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2717 dw2_asm_output_data_uleb128 (r, NULL);
2718 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2719 dw2_asm_output_data_sleb128 (off, NULL);
2722 case DW_CFA_def_cfa_sf:
2723 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2724 dw2_asm_output_data_uleb128 (r, NULL);
2725 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2726 dw2_asm_output_data_sleb128 (off, NULL);
2729 case DW_CFA_restore_extended:
2730 case DW_CFA_undefined:
2731 case DW_CFA_same_value:
2732 case DW_CFA_def_cfa_register:
2733 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2734 dw2_asm_output_data_uleb128 (r, NULL);
2737 case DW_CFA_register:
2738 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2739 dw2_asm_output_data_uleb128 (r, NULL);
2740 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2741 dw2_asm_output_data_uleb128 (r, NULL);
2744 case DW_CFA_def_cfa_offset:
2745 case DW_CFA_GNU_args_size:
2746 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2749 case DW_CFA_def_cfa_offset_sf:
2750 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2751 dw2_asm_output_data_sleb128 (off, NULL);
2754 case DW_CFA_GNU_window_save:
2757 case DW_CFA_def_cfa_expression:
2758 case DW_CFA_expression:
2759 output_cfa_loc (cfi);
2762 case DW_CFA_GNU_negative_offset_extended:
2763 /* Obsoleted by DW_CFA_offset_extended_sf. */
2772 /* Similar, but do it via assembler directives instead. */
2775 output_cfi_directive (dw_cfi_ref cfi)
2777 unsigned long r, r2;
2779 switch (cfi->dw_cfi_opc)
2781 case DW_CFA_advance_loc:
2782 case DW_CFA_advance_loc1:
2783 case DW_CFA_advance_loc2:
2784 case DW_CFA_advance_loc4:
2785 case DW_CFA_MIPS_advance_loc8:
2786 case DW_CFA_set_loc:
2787 /* Should only be created by add_fde_cfi in a code path not
2788 followed when emitting via directives. The assembler is
2789 going to take care of this for us. */
2793 case DW_CFA_offset_extended:
2794 case DW_CFA_offset_extended_sf:
2795 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2796 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2797 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2800 case DW_CFA_restore:
2801 case DW_CFA_restore_extended:
2802 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2803 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
2806 case DW_CFA_undefined:
2807 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2808 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
2811 case DW_CFA_same_value:
2812 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2813 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
2816 case DW_CFA_def_cfa:
2817 case DW_CFA_def_cfa_sf:
2818 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2819 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
2820 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
2823 case DW_CFA_def_cfa_register:
2824 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2825 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
2828 case DW_CFA_register:
2829 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
2830 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
2831 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
2834 case DW_CFA_def_cfa_offset:
2835 case DW_CFA_def_cfa_offset_sf:
2836 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
2837 HOST_WIDE_INT_PRINT_DEC"\n",
2838 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2841 case DW_CFA_GNU_args_size:
2842 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
2843 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2845 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
2846 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
2847 fputc ('\n', asm_out_file);
2850 case DW_CFA_GNU_window_save:
2851 fprintf (asm_out_file, "\t.cfi_window_save\n");
2854 case DW_CFA_def_cfa_expression:
2855 case DW_CFA_expression:
2856 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
2857 output_cfa_loc_raw (cfi);
2858 fputc ('\n', asm_out_file);
2866 /* Output the call frame information used to record information
2867 that relates to calculating the frame pointer, and records the
2868 location of saved registers. */
2871 output_call_frame_info (int for_eh)
2876 char l1[20], l2[20], section_start_label[20];
2877 bool any_lsda_needed = false;
2878 char augmentation[6];
2879 int augmentation_size;
2880 int fde_encoding = DW_EH_PE_absptr;
2881 int per_encoding = DW_EH_PE_absptr;
2882 int lsda_encoding = DW_EH_PE_absptr;
2885 /* Don't emit a CIE if there won't be any FDEs. */
2886 if (fde_table_in_use == 0)
2889 /* Nothing to do if the assembler's doing it all. */
2890 if (dwarf2out_do_cfi_asm ())
2893 /* If we make FDEs linkonce, we may have to emit an empty label for
2894 an FDE that wouldn't otherwise be emitted. We want to avoid
2895 having an FDE kept around when the function it refers to is
2896 discarded. Example where this matters: a primary function
2897 template in C++ requires EH information, but an explicit
2898 specialization doesn't. */
2899 if (TARGET_USES_WEAK_UNWIND_INFO
2900 && ! flag_asynchronous_unwind_tables
2903 for (i = 0; i < fde_table_in_use; i++)
2904 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2905 && !fde_table[i].uses_eh_lsda
2906 && ! DECL_WEAK (fde_table[i].decl))
2907 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2908 for_eh, /* empty */ 1);
2910 /* If we don't have any functions we'll want to unwind out of, don't
2911 emit any EH unwind information. Note that if exceptions aren't
2912 enabled, we won't have collected nothrow information, and if we
2913 asked for asynchronous tables, we always want this info. */
2916 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2918 for (i = 0; i < fde_table_in_use; i++)
2919 if (fde_table[i].uses_eh_lsda)
2920 any_eh_needed = any_lsda_needed = true;
2921 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2922 any_eh_needed = true;
2923 else if (! fde_table[i].nothrow
2924 && ! fde_table[i].all_throwers_are_sibcalls)
2925 any_eh_needed = true;
2927 if (! any_eh_needed)
2931 /* We're going to be generating comments, so turn on app. */
2936 switch_to_eh_frame_section ();
2939 if (!debug_frame_section)
2940 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2941 SECTION_DEBUG, NULL);
2942 switch_to_section (debug_frame_section);
2945 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2946 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2948 /* Output the CIE. */
2949 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2950 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2951 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2952 dw2_asm_output_data (4, 0xffffffff,
2953 "Initial length escape value indicating 64-bit DWARF extension");
2954 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2955 "Length of Common Information Entry");
2956 ASM_OUTPUT_LABEL (asm_out_file, l1);
2958 /* Now that the CIE pointer is PC-relative for EH,
2959 use 0 to identify the CIE. */
2960 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2961 (for_eh ? 0 : DWARF_CIE_ID),
2962 "CIE Identifier Tag");
2964 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2966 augmentation[0] = 0;
2967 augmentation_size = 0;
2973 z Indicates that a uleb128 is present to size the
2974 augmentation section.
2975 L Indicates the encoding (and thus presence) of
2976 an LSDA pointer in the FDE augmentation.
2977 R Indicates a non-default pointer encoding for
2979 P Indicates the presence of an encoding + language
2980 personality routine in the CIE augmentation. */
2982 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2983 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2984 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2986 p = augmentation + 1;
2987 if (eh_personality_libfunc)
2990 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2991 assemble_external_libcall (eh_personality_libfunc);
2993 if (any_lsda_needed)
2996 augmentation_size += 1;
2998 if (fde_encoding != DW_EH_PE_absptr)
3001 augmentation_size += 1;
3003 if (p > augmentation + 1)
3005 augmentation[0] = 'z';
3009 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3010 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
3012 int offset = ( 4 /* Length */
3014 + 1 /* CIE version */
3015 + strlen (augmentation) + 1 /* Augmentation */
3016 + size_of_uleb128 (1) /* Code alignment */
3017 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3019 + 1 /* Augmentation size */
3020 + 1 /* Personality encoding */ );
3021 int pad = -offset & (PTR_SIZE - 1);
3023 augmentation_size += pad;
3025 /* Augmentations should be small, so there's scarce need to
3026 iterate for a solution. Die if we exceed one uleb128 byte. */
3027 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3031 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3032 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3033 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3034 "CIE Data Alignment Factor");
3036 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3037 if (DW_CIE_VERSION == 1)
3038 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3040 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3042 if (augmentation[0])
3044 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3045 if (eh_personality_libfunc)
3047 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3048 eh_data_format_name (per_encoding));
3049 dw2_asm_output_encoded_addr_rtx (per_encoding,
3050 eh_personality_libfunc,
3054 if (any_lsda_needed)
3055 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3056 eh_data_format_name (lsda_encoding));
3058 if (fde_encoding != DW_EH_PE_absptr)
3059 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3060 eh_data_format_name (fde_encoding));
3063 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3064 output_cfi (cfi, NULL, for_eh);
3066 /* Pad the CIE out to an address sized boundary. */
3067 ASM_OUTPUT_ALIGN (asm_out_file,
3068 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3069 ASM_OUTPUT_LABEL (asm_out_file, l2);
3071 /* Loop through all of the FDE's. */
3072 for (i = 0; i < fde_table_in_use; i++)
3074 fde = &fde_table[i];
3076 /* Don't emit EH unwind info for leaf functions that don't need it. */
3077 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3078 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3079 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3080 && !fde->uses_eh_lsda)
3083 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
3084 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
3085 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
3086 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
3087 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3088 dw2_asm_output_data (4, 0xffffffff,
3089 "Initial length escape value indicating 64-bit DWARF extension");
3090 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3092 ASM_OUTPUT_LABEL (asm_out_file, l1);
3095 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3097 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3098 debug_frame_section, "FDE CIE offset");
3102 if (fde->dw_fde_switched_sections)
3104 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
3105 fde->dw_fde_unlikely_section_label);
3106 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
3107 fde->dw_fde_hot_section_label);
3108 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
3109 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
3110 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
3111 "FDE initial location");
3112 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3113 fde->dw_fde_hot_section_end_label,
3114 fde->dw_fde_hot_section_label,
3115 "FDE address range");
3116 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
3117 "FDE initial location");
3118 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3119 fde->dw_fde_unlikely_section_end_label,
3120 fde->dw_fde_unlikely_section_label,
3121 "FDE address range");
3125 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3126 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3127 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3130 "FDE initial location");
3131 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3132 fde->dw_fde_end, fde->dw_fde_begin,
3133 "FDE address range");
3138 if (fde->dw_fde_switched_sections)
3140 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3141 fde->dw_fde_hot_section_label,
3142 "FDE initial location");
3143 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3144 fde->dw_fde_hot_section_end_label,
3145 fde->dw_fde_hot_section_label,
3146 "FDE address range");
3147 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3148 fde->dw_fde_unlikely_section_label,
3149 "FDE initial location");
3150 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3151 fde->dw_fde_unlikely_section_end_label,
3152 fde->dw_fde_unlikely_section_label,
3153 "FDE address range");
3157 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3158 "FDE initial location");
3159 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3160 fde->dw_fde_end, fde->dw_fde_begin,
3161 "FDE address range");
3165 if (augmentation[0])
3167 if (any_lsda_needed)
3169 int size = size_of_encoded_value (lsda_encoding);
3171 if (lsda_encoding == DW_EH_PE_aligned)
3173 int offset = ( 4 /* Length */
3174 + 4 /* CIE offset */
3175 + 2 * size_of_encoded_value (fde_encoding)
3176 + 1 /* Augmentation size */ );
3177 int pad = -offset & (PTR_SIZE - 1);
3180 gcc_assert (size_of_uleb128 (size) == 1);
3183 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3185 if (fde->uses_eh_lsda)
3187 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3188 fde->funcdef_number);
3189 dw2_asm_output_encoded_addr_rtx (
3190 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3191 false, "Language Specific Data Area");
3195 if (lsda_encoding == DW_EH_PE_aligned)
3196 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3198 (size_of_encoded_value (lsda_encoding), 0,
3199 "Language Specific Data Area (none)");
3203 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3206 /* Loop through the Call Frame Instructions associated with
3208 fde->dw_fde_current_label = fde->dw_fde_begin;
3209 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3210 output_cfi (cfi, fde, for_eh);
3212 /* Pad the FDE out to an address sized boundary. */
3213 ASM_OUTPUT_ALIGN (asm_out_file,
3214 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3215 ASM_OUTPUT_LABEL (asm_out_file, l2);
3218 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3219 dw2_asm_output_data (4, 0, "End of Table");
3220 #ifdef MIPS_DEBUGGING_INFO
3221 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3222 get a value of 0. Putting .align 0 after the label fixes it. */
3223 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3226 /* Turn off app to make assembly quicker. */
3231 /* Output a marker (i.e. a label) for the beginning of a function, before
3235 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3236 const char *file ATTRIBUTE_UNUSED)
3238 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3242 current_function_func_begin_label = NULL;
3244 #ifdef TARGET_UNWIND_INFO
3245 /* ??? current_function_func_begin_label is also used by except.c
3246 for call-site information. We must emit this label if it might
3248 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3249 && ! dwarf2out_do_frame ())
3252 if (! dwarf2out_do_frame ())
3256 switch_to_section (function_section (current_function_decl));
3257 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3258 current_function_funcdef_no);
3259 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3260 current_function_funcdef_no);
3261 dup_label = xstrdup (label);
3262 current_function_func_begin_label = dup_label;
3264 #ifdef TARGET_UNWIND_INFO
3265 /* We can elide the fde allocation if we're not emitting debug info. */
3266 if (! dwarf2out_do_frame ())
3270 /* Expand the fde table if necessary. */
3271 if (fde_table_in_use == fde_table_allocated)
3273 fde_table_allocated += FDE_TABLE_INCREMENT;
3274 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3275 memset (fde_table + fde_table_in_use, 0,
3276 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3279 /* Record the FDE associated with this function. */
3280 current_funcdef_fde = fde_table_in_use;
3282 /* Add the new FDE at the end of the fde_table. */
3283 fde = &fde_table[fde_table_in_use++];
3284 fde->decl = current_function_decl;
3285 fde->dw_fde_begin = dup_label;
3286 fde->dw_fde_current_label = dup_label;
3287 fde->dw_fde_hot_section_label = NULL;
3288 fde->dw_fde_hot_section_end_label = NULL;
3289 fde->dw_fde_unlikely_section_label = NULL;
3290 fde->dw_fde_unlikely_section_end_label = NULL;
3291 fde->dw_fde_switched_sections = false;
3292 fde->dw_fde_end = NULL;
3293 fde->dw_fde_cfi = NULL;
3294 fde->funcdef_number = current_function_funcdef_no;
3295 fde->nothrow = TREE_NOTHROW (current_function_decl);
3296 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3297 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3298 fde->drap_reg = INVALID_REGNUM;
3299 fde->vdrap_reg = INVALID_REGNUM;
3301 args_size = old_args_size = 0;
3303 /* We only want to output line number information for the genuine dwarf2
3304 prologue case, not the eh frame case. */
3305 #ifdef DWARF2_DEBUGGING_INFO
3307 dwarf2out_source_line (line, file);
3310 if (dwarf2out_do_cfi_asm ())
3315 fprintf (asm_out_file, "\t.cfi_startproc\n");
3317 if (eh_personality_libfunc)
3319 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3320 ref = eh_personality_libfunc;
3322 /* ??? The GAS support isn't entirely consistent. We have to
3323 handle indirect support ourselves, but PC-relative is done
3324 in the assembler. Further, the assembler can't handle any
3325 of the weirder relocation types. */
3326 if (enc & DW_EH_PE_indirect)
3327 ref = dw2_force_const_mem (ref, true);
3329 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3330 output_addr_const (asm_out_file, ref);
3331 fputc ('\n', asm_out_file);
3334 if (crtl->uses_eh_lsda)
3338 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3339 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3340 current_function_funcdef_no);
3341 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3342 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3344 if (enc & DW_EH_PE_indirect)
3345 ref = dw2_force_const_mem (ref, true);
3347 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3348 output_addr_const (asm_out_file, ref);
3349 fputc ('\n', asm_out_file);
3354 /* Output a marker (i.e. a label) for the absolute end of the generated code
3355 for a function definition. This gets called *after* the epilogue code has
3359 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3360 const char *file ATTRIBUTE_UNUSED)
3363 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3365 if (dwarf2out_do_cfi_asm ())
3366 fprintf (asm_out_file, "\t.cfi_endproc\n");
3368 /* Output a label to mark the endpoint of the code generated for this
3370 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3371 current_function_funcdef_no);
3372 ASM_OUTPUT_LABEL (asm_out_file, label);
3373 fde = current_fde ();
3374 gcc_assert (fde != NULL);
3375 fde->dw_fde_end = xstrdup (label);
3379 dwarf2out_frame_init (void)
3381 /* Allocate the initial hunk of the fde_table. */
3382 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3383 fde_table_allocated = FDE_TABLE_INCREMENT;
3384 fde_table_in_use = 0;
3386 /* Generate the CFA instructions common to all FDE's. Do it now for the
3387 sake of lookup_cfa. */
3389 /* On entry, the Canonical Frame Address is at SP. */
3390 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3392 #ifdef DWARF2_UNWIND_INFO
3393 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3394 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3399 dwarf2out_frame_finish (void)
3401 /* Output call frame information. */
3402 if (DWARF2_FRAME_INFO)
3403 output_call_frame_info (0);
3405 #ifndef TARGET_UNWIND_INFO
3406 /* Output another copy for the unwinder. */
3407 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3408 output_call_frame_info (1);
3412 /* Note that the current function section is being used for code. */
3415 dwarf2out_note_section_used (void)
3417 section *sec = current_function_section ();
3418 if (sec == text_section)
3419 text_section_used = true;
3420 else if (sec == cold_text_section)
3421 cold_text_section_used = true;
3425 dwarf2out_switch_text_section (void)
3427 dw_fde_ref fde = current_fde ();
3429 gcc_assert (cfun && fde);
3431 fde->dw_fde_switched_sections = true;
3432 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3433 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3434 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3435 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3436 have_multiple_function_sections = true;
3438 /* Reset the current label on switching text sections, so that we
3439 don't attempt to advance_loc4 between labels in different sections. */
3440 fde->dw_fde_current_label = NULL;
3442 /* There is no need to mark used sections when not debugging. */
3443 if (cold_text_section != NULL)
3444 dwarf2out_note_section_used ();
3448 /* And now, the subset of the debugging information support code necessary
3449 for emitting location expressions. */
3451 /* Data about a single source file. */
3452 struct dwarf_file_data GTY(())
3454 const char * filename;
3458 /* We need some way to distinguish DW_OP_addr with a direct symbol
3459 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3460 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3463 typedef struct dw_val_struct *dw_val_ref;
3464 typedef struct die_struct *dw_die_ref;
3465 typedef const struct die_struct *const_dw_die_ref;
3466 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3467 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3469 typedef struct deferred_locations_struct GTY(())
3473 } deferred_locations;
3475 DEF_VEC_O(deferred_locations);
3476 DEF_VEC_ALLOC_O(deferred_locations,gc);
3478 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
3480 /* Each DIE may have a series of attribute/value pairs. Values
3481 can take on several forms. The forms that are used in this
3482 implementation are listed below. */
3487 dw_val_class_offset,
3489 dw_val_class_loc_list,
3490 dw_val_class_range_list,
3492 dw_val_class_unsigned_const,
3493 dw_val_class_long_long,
3496 dw_val_class_die_ref,
3497 dw_val_class_fde_ref,
3498 dw_val_class_lbl_id,
3499 dw_val_class_lineptr,
3501 dw_val_class_macptr,
3505 /* Describe a double word constant value. */
3506 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3508 typedef struct dw_long_long_struct GTY(())
3515 /* Describe a floating point constant value, or a vector constant value. */
3517 typedef struct dw_vec_struct GTY(())
3519 unsigned char * GTY((length ("%h.length"))) array;
3525 /* The dw_val_node describes an attribute's value, as it is
3526 represented internally. */
3528 typedef struct dw_val_struct GTY(())
3530 enum dw_val_class val_class;
3531 union dw_val_struct_union
3533 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3534 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3535 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3536 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3537 HOST_WIDE_INT GTY ((default)) val_int;
3538 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3539 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3540 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3541 struct dw_val_die_union
3545 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3546 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3547 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3548 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3549 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3550 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3552 GTY ((desc ("%1.val_class"))) v;
3556 /* Locations in memory are described using a sequence of stack machine
3559 typedef struct dw_loc_descr_struct GTY(())
3561 dw_loc_descr_ref dw_loc_next;
3562 enum dwarf_location_atom dw_loc_opc;
3564 dw_val_node dw_loc_oprnd1;
3565 dw_val_node dw_loc_oprnd2;
3569 /* Location lists are ranges + location descriptions for that range,
3570 so you can track variables that are in different places over
3571 their entire life. */
3572 typedef struct dw_loc_list_struct GTY(())
3574 dw_loc_list_ref dw_loc_next;
3575 const char *begin; /* Label for begin address of range */
3576 const char *end; /* Label for end address of range */
3577 char *ll_symbol; /* Label for beginning of location list.
3578 Only on head of list */
3579 const char *section; /* Section this loclist is relative to */
3580 dw_loc_descr_ref expr;
3583 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3585 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3587 /* Convert a DWARF stack opcode into its string name. */
3590 dwarf_stack_op_name (unsigned int op)
3595 case INTERNAL_DW_OP_tls_addr:
3596 return "DW_OP_addr";
3598 return "DW_OP_deref";
3600 return "DW_OP_const1u";
3602 return "DW_OP_const1s";
3604 return "DW_OP_const2u";
3606 return "DW_OP_const2s";
3608 return "DW_OP_const4u";
3610 return "DW_OP_const4s";
3612 return "DW_OP_const8u";
3614 return "DW_OP_const8s";
3616 return "DW_OP_constu";
3618 return "DW_OP_consts";
3622 return "DW_OP_drop";
3624 return "DW_OP_over";
3626 return "DW_OP_pick";
3628 return "DW_OP_swap";
3632 return "DW_OP_xderef";
3640 return "DW_OP_minus";
3652 return "DW_OP_plus";
3653 case DW_OP_plus_uconst:
3654 return "DW_OP_plus_uconst";
3660 return "DW_OP_shra";
3678 return "DW_OP_skip";
3680 return "DW_OP_lit0";
3682 return "DW_OP_lit1";
3684 return "DW_OP_lit2";
3686 return "DW_OP_lit3";
3688 return "DW_OP_lit4";
3690 return "DW_OP_lit5";
3692 return "DW_OP_lit6";
3694 return "DW_OP_lit7";
3696 return "DW_OP_lit8";
3698 return "DW_OP_lit9";
3700 return "DW_OP_lit10";
3702 return "DW_OP_lit11";
3704 return "DW_OP_lit12";
3706 return "DW_OP_lit13";
3708 return "DW_OP_lit14";
3710 return "DW_OP_lit15";
3712 return "DW_OP_lit16";
3714 return "DW_OP_lit17";
3716 return "DW_OP_lit18";
3718 return "DW_OP_lit19";
3720 return "DW_OP_lit20";
3722 return "DW_OP_lit21";
3724 return "DW_OP_lit22";
3726 return "DW_OP_lit23";
3728 return "DW_OP_lit24";
3730 return "DW_OP_lit25";
3732 return "DW_OP_lit26";
3734 return "DW_OP_lit27";
3736 return "DW_OP_lit28";
3738 return "DW_OP_lit29";
3740 return "DW_OP_lit30";
3742 return "DW_OP_lit31";
3744 return "DW_OP_reg0";
3746 return "DW_OP_reg1";
3748 return "DW_OP_reg2";
3750 return "DW_OP_reg3";
3752 return "DW_OP_reg4";
3754 return "DW_OP_reg5";
3756 return "DW_OP_reg6";
3758 return "DW_OP_reg7";
3760 return "DW_OP_reg8";
3762 return "DW_OP_reg9";
3764 return "DW_OP_reg10";
3766 return "DW_OP_reg11";
3768 return "DW_OP_reg12";
3770 return "DW_OP_reg13";
3772 return "DW_OP_reg14";
3774 return "DW_OP_reg15";
3776 return "DW_OP_reg16";
3778 return "DW_OP_reg17";
3780 return "DW_OP_reg18";
3782 return "DW_OP_reg19";
3784 return "DW_OP_reg20";
3786 return "DW_OP_reg21";
3788 return "DW_OP_reg22";
3790 return "DW_OP_reg23";
3792 return "DW_OP_reg24";
3794 return "DW_OP_reg25";
3796 return "DW_OP_reg26";
3798 return "DW_OP_reg27";
3800 return "DW_OP_reg28";
3802 return "DW_OP_reg29";
3804 return "DW_OP_reg30";
3806 return "DW_OP_reg31";
3808 return "DW_OP_breg0";
3810 return "DW_OP_breg1";
3812 return "DW_OP_breg2";
3814 return "DW_OP_breg3";
3816 return "DW_OP_breg4";
3818 return "DW_OP_breg5";
3820 return "DW_OP_breg6";
3822 return "DW_OP_breg7";
3824 return "DW_OP_breg8";
3826 return "DW_OP_breg9";
3828 return "DW_OP_breg10";
3830 return "DW_OP_breg11";
3832 return "DW_OP_breg12";
3834 return "DW_OP_breg13";
3836 return "DW_OP_breg14";
3838 return "DW_OP_breg15";
3840 return "DW_OP_breg16";
3842 return "DW_OP_breg17";
3844 return "DW_OP_breg18";
3846 return "DW_OP_breg19";
3848 return "DW_OP_breg20";
3850 return "DW_OP_breg21";
3852 return "DW_OP_breg22";
3854 return "DW_OP_breg23";
3856 return "DW_OP_breg24";
3858 return "DW_OP_breg25";
3860 return "DW_OP_breg26";
3862 return "DW_OP_breg27";
3864 return "DW_OP_breg28";
3866 return "DW_OP_breg29";
3868 return "DW_OP_breg30";
3870 return "DW_OP_breg31";
3872 return "DW_OP_regx";
3874 return "DW_OP_fbreg";
3876 return "DW_OP_bregx";
3878 return "DW_OP_piece";
3879 case DW_OP_deref_size:
3880 return "DW_OP_deref_size";
3881 case DW_OP_xderef_size:
3882 return "DW_OP_xderef_size";
3885 case DW_OP_push_object_address:
3886 return "DW_OP_push_object_address";
3888 return "DW_OP_call2";
3890 return "DW_OP_call4";
3891 case DW_OP_call_ref:
3892 return "DW_OP_call_ref";
3893 case DW_OP_GNU_push_tls_address:
3894 return "DW_OP_GNU_push_tls_address";
3895 case DW_OP_GNU_uninit:
3896 return "DW_OP_GNU_uninit";
3898 return "OP_<unknown>";
3902 /* Return a pointer to a newly allocated location description. Location
3903 descriptions are simple expression terms that can be strung
3904 together to form more complicated location (address) descriptions. */
3906 static inline dw_loc_descr_ref
3907 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3908 unsigned HOST_WIDE_INT oprnd2)
3910 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3912 descr->dw_loc_opc = op;
3913 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3914 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3915 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3916 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3921 /* Return a pointer to a newly allocated location description for
3924 static inline dw_loc_descr_ref
3925 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
3930 return new_loc_descr (DW_OP_breg0 + reg, offset, 0);
3932 return new_loc_descr (DW_OP_bregx, reg, offset);
3935 return new_loc_descr (DW_OP_reg0 + reg, 0, 0);
3937 return new_loc_descr (DW_OP_regx, reg, 0);
3940 /* Add a location description term to a location description expression. */
3943 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3945 dw_loc_descr_ref *d;
3947 /* Find the end of the chain. */
3948 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3954 /* Return the size of a location descriptor. */
3956 static unsigned long
3957 size_of_loc_descr (dw_loc_descr_ref loc)
3959 unsigned long size = 1;
3961 switch (loc->dw_loc_opc)
3964 case INTERNAL_DW_OP_tls_addr:
3965 size += DWARF2_ADDR_SIZE;
3984 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3987 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3992 case DW_OP_plus_uconst:
3993 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4031 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4034 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4037 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4040 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4041 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4044 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4046 case DW_OP_deref_size:
4047 case DW_OP_xderef_size:
4056 case DW_OP_call_ref:
4057 size += DWARF2_ADDR_SIZE;
4066 /* Return the size of a series of location descriptors. */
4068 static unsigned long
4069 size_of_locs (dw_loc_descr_ref loc)
4074 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4075 field, to avoid writing to a PCH file. */
4076 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4078 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4080 size += size_of_loc_descr (l);
4085 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4087 l->dw_loc_addr = size;
4088 size += size_of_loc_descr (l);
4094 /* Output location description stack opcode's operands (if any). */
4097 output_loc_operands (dw_loc_descr_ref loc)
4099 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4100 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4102 switch (loc->dw_loc_opc)
4104 #ifdef DWARF2_DEBUGGING_INFO
4106 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4110 dw2_asm_output_data (2, val1->v.val_int, NULL);
4114 dw2_asm_output_data (4, val1->v.val_int, NULL);
4118 gcc_assert (HOST_BITS_PER_LONG >= 64);
4119 dw2_asm_output_data (8, val1->v.val_int, NULL);
4126 gcc_assert (val1->val_class == dw_val_class_loc);
4127 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4129 dw2_asm_output_data (2, offset, NULL);
4142 /* We currently don't make any attempt to make sure these are
4143 aligned properly like we do for the main unwind info, so
4144 don't support emitting things larger than a byte if we're
4145 only doing unwinding. */
4150 dw2_asm_output_data (1, val1->v.val_int, NULL);
4153 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4156 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4159 dw2_asm_output_data (1, val1->v.val_int, NULL);
4161 case DW_OP_plus_uconst:
4162 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4196 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4199 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4202 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4205 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4206 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4209 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4211 case DW_OP_deref_size:
4212 case DW_OP_xderef_size:
4213 dw2_asm_output_data (1, val1->v.val_int, NULL);
4216 case INTERNAL_DW_OP_tls_addr:
4217 if (targetm.asm_out.output_dwarf_dtprel)
4219 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4222 fputc ('\n', asm_out_file);
4229 /* Other codes have no operands. */
4234 /* Output a sequence of location operations. */
4237 output_loc_sequence (dw_loc_descr_ref loc)
4239 for (; loc != NULL; loc = loc->dw_loc_next)
4241 /* Output the opcode. */
4242 dw2_asm_output_data (1, loc->dw_loc_opc,
4243 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4245 /* Output the operand(s) (if any). */
4246 output_loc_operands (loc);
4250 /* Output location description stack opcode's operands (if any).
4251 The output is single bytes on a line, suitable for .cfi_escape. */
4254 output_loc_operands_raw (dw_loc_descr_ref loc)
4256 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4257 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4259 switch (loc->dw_loc_opc)
4262 /* We cannot output addresses in .cfi_escape, only bytes. */
4268 case DW_OP_deref_size:
4269 case DW_OP_xderef_size:
4270 fputc (',', asm_out_file);
4271 dw2_asm_output_data_raw (1, val1->v.val_int);
4276 fputc (',', asm_out_file);
4277 dw2_asm_output_data_raw (2, val1->v.val_int);
4282 fputc (',', asm_out_file);
4283 dw2_asm_output_data_raw (4, val1->v.val_int);
4288 gcc_assert (HOST_BITS_PER_LONG >= 64);
4289 fputc (',', asm_out_file);
4290 dw2_asm_output_data_raw (8, val1->v.val_int);
4298 gcc_assert (val1->val_class == dw_val_class_loc);
4299 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4301 fputc (',', asm_out_file);
4302 dw2_asm_output_data_raw (2, offset);
4307 case DW_OP_plus_uconst:
4310 fputc (',', asm_out_file);
4311 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4348 fputc (',', asm_out_file);
4349 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4353 fputc (',', asm_out_file);
4354 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4355 fputc (',', asm_out_file);
4356 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4359 case INTERNAL_DW_OP_tls_addr:
4363 /* Other codes have no operands. */
4369 output_loc_sequence_raw (dw_loc_descr_ref loc)
4373 /* Output the opcode. */
4374 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4375 output_loc_operands_raw (loc);
4377 if (!loc->dw_loc_next)
4379 loc = loc->dw_loc_next;
4381 fputc (',', asm_out_file);
4385 /* This routine will generate the correct assembly data for a location
4386 description based on a cfi entry with a complex address. */
4389 output_cfa_loc (dw_cfi_ref cfi)
4391 dw_loc_descr_ref loc;
4394 if (cfi->dw_cfi_opc == DW_CFA_expression)
4395 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4397 /* Output the size of the block. */
4398 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4399 size = size_of_locs (loc);
4400 dw2_asm_output_data_uleb128 (size, NULL);
4402 /* Now output the operations themselves. */
4403 output_loc_sequence (loc);
4406 /* Similar, but used for .cfi_escape. */
4409 output_cfa_loc_raw (dw_cfi_ref cfi)
4411 dw_loc_descr_ref loc;
4414 if (cfi->dw_cfi_opc == DW_CFA_expression)
4415 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4417 /* Output the size of the block. */
4418 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4419 size = size_of_locs (loc);
4420 dw2_asm_output_data_uleb128_raw (size);
4421 fputc (',', asm_out_file);
4423 /* Now output the operations themselves. */
4424 output_loc_sequence_raw (loc);
4427 /* This function builds a dwarf location descriptor sequence from a
4428 dw_cfa_location, adding the given OFFSET to the result of the
4431 static struct dw_loc_descr_struct *
4432 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4434 struct dw_loc_descr_struct *head, *tmp;
4436 offset += cfa->offset;
4440 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
4441 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4442 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4443 add_loc_descr (&head, tmp);
4446 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4447 add_loc_descr (&head, tmp);
4451 head = new_reg_loc_descr (cfa->reg, offset);
4456 /* This function builds a dwarf location descriptor sequence for
4457 the address at OFFSET from the CFA when stack is aligned to
4460 static struct dw_loc_descr_struct *
4461 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4463 struct dw_loc_descr_struct *head;
4464 unsigned int dwarf_fp
4465 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4467 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4468 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4470 head = new_reg_loc_descr (dwarf_fp, 0);
4471 add_loc_descr (&head, int_loc_descriptor (alignment));
4472 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4474 add_loc_descr (&head, int_loc_descriptor (offset));
4475 add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
4478 head = new_reg_loc_descr (dwarf_fp, offset);
4482 /* This function fills in aa dw_cfa_location structure from a dwarf location
4483 descriptor sequence. */
4486 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4488 struct dw_loc_descr_struct *ptr;
4490 cfa->base_offset = 0;
4494 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4496 enum dwarf_location_atom op = ptr->dw_loc_opc;
4532 cfa->reg = op - DW_OP_reg0;
4535 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4569 cfa->reg = op - DW_OP_breg0;
4570 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4573 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4574 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4579 case DW_OP_plus_uconst:
4580 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4583 internal_error ("DW_LOC_OP %s not implemented",
4584 dwarf_stack_op_name (ptr->dw_loc_opc));
4588 #endif /* .debug_frame support */
4590 /* And now, the support for symbolic debugging information. */
4591 #ifdef DWARF2_DEBUGGING_INFO
4593 /* .debug_str support. */
4594 static int output_indirect_string (void **, void *);
4596 static void dwarf2out_init (const char *);
4597 static void dwarf2out_finish (const char *);
4598 static void dwarf2out_assembly_start (void);
4599 static void dwarf2out_define (unsigned int, const char *);
4600 static void dwarf2out_undef (unsigned int, const char *);
4601 static void dwarf2out_start_source_file (unsigned, const char *);
4602 static void dwarf2out_end_source_file (unsigned);
4603 static void dwarf2out_begin_block (unsigned, unsigned);
4604 static void dwarf2out_end_block (unsigned, unsigned);
4605 static bool dwarf2out_ignore_block (const_tree);
4606 static void dwarf2out_global_decl (tree);
4607 static void dwarf2out_type_decl (tree, int);
4608 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
4609 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
4611 static void dwarf2out_abstract_function (tree);
4612 static void dwarf2out_var_location (rtx);
4613 static void dwarf2out_begin_function (tree);
4615 /* The debug hooks structure. */
4617 const struct gcc_debug_hooks dwarf2_debug_hooks =
4621 dwarf2out_assembly_start,
4624 dwarf2out_start_source_file,
4625 dwarf2out_end_source_file,
4626 dwarf2out_begin_block,
4627 dwarf2out_end_block,
4628 dwarf2out_ignore_block,
4629 dwarf2out_source_line,
4630 dwarf2out_begin_prologue,
4631 debug_nothing_int_charstar, /* end_prologue */
4632 dwarf2out_end_epilogue,
4633 dwarf2out_begin_function,
4634 debug_nothing_int, /* end_function */
4635 dwarf2out_decl, /* function_decl */
4636 dwarf2out_global_decl,
4637 dwarf2out_type_decl, /* type_decl */
4638 dwarf2out_imported_module_or_decl,
4639 debug_nothing_tree, /* deferred_inline_function */
4640 /* The DWARF 2 backend tries to reduce debugging bloat by not
4641 emitting the abstract description of inline functions until
4642 something tries to reference them. */
4643 dwarf2out_abstract_function, /* outlining_inline_function */
4644 debug_nothing_rtx, /* label */
4645 debug_nothing_int, /* handle_pch */
4646 dwarf2out_var_location,
4647 dwarf2out_switch_text_section,
4648 1 /* start_end_main_source_file */
4652 /* NOTE: In the comments in this file, many references are made to
4653 "Debugging Information Entries". This term is abbreviated as `DIE'
4654 throughout the remainder of this file. */
4656 /* An internal representation of the DWARF output is built, and then
4657 walked to generate the DWARF debugging info. The walk of the internal
4658 representation is done after the entire program has been compiled.
4659 The types below are used to describe the internal representation. */
4661 /* Various DIE's use offsets relative to the beginning of the
4662 .debug_info section to refer to each other. */
4664 typedef long int dw_offset;
4666 /* Define typedefs here to avoid circular dependencies. */
4668 typedef struct dw_attr_struct *dw_attr_ref;
4669 typedef struct dw_line_info_struct *dw_line_info_ref;
4670 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
4671 typedef struct pubname_struct *pubname_ref;
4672 typedef struct dw_ranges_struct *dw_ranges_ref;
4673 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
4675 /* Each entry in the line_info_table maintains the file and
4676 line number associated with the label generated for that
4677 entry. The label gives the PC value associated with
4678 the line number entry. */
4680 typedef struct dw_line_info_struct GTY(())
4682 unsigned long dw_file_num;
4683 unsigned long dw_line_num;
4687 /* Line information for functions in separate sections; each one gets its
4689 typedef struct dw_separate_line_info_struct GTY(())
4691 unsigned long dw_file_num;
4692 unsigned long dw_line_num;
4693 unsigned long function;
4695 dw_separate_line_info_entry;
4697 /* Each DIE attribute has a field specifying the attribute kind,
4698 a link to the next attribute in the chain, and an attribute value.
4699 Attributes are typically linked below the DIE they modify. */
4701 typedef struct dw_attr_struct GTY(())
4703 enum dwarf_attribute dw_attr;
4704 dw_val_node dw_attr_val;
4708 DEF_VEC_O(dw_attr_node);
4709 DEF_VEC_ALLOC_O(dw_attr_node,gc);
4711 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4712 The children of each node form a circular list linked by
4713 die_sib. die_child points to the node *before* the "first" child node. */
4715 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
4717 enum dwarf_tag die_tag;
4719 VEC(dw_attr_node,gc) * die_attr;
4720 dw_die_ref die_parent;
4721 dw_die_ref die_child;
4723 dw_die_ref die_definition; /* ref from a specification to its definition */
4724 dw_offset die_offset;
4725 unsigned long die_abbrev;
4727 /* Die is used and must not be pruned as unused. */
4728 int die_perennial_p;
4729 unsigned int decl_id;
4733 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4734 #define FOR_EACH_CHILD(die, c, expr) do { \
4735 c = die->die_child; \
4739 } while (c != die->die_child); \
4742 /* The pubname structure */
4744 typedef struct pubname_struct GTY(())
4751 DEF_VEC_O(pubname_entry);
4752 DEF_VEC_ALLOC_O(pubname_entry, gc);
4754 struct dw_ranges_struct GTY(())
4756 /* If this is positive, it's a block number, otherwise it's a
4757 bitwise-negated index into dw_ranges_by_label. */
4761 struct dw_ranges_by_label_struct GTY(())
4767 /* The limbo die list structure. */
4768 typedef struct limbo_die_struct GTY(())
4772 struct limbo_die_struct *next;
4776 /* How to start an assembler comment. */
4777 #ifndef ASM_COMMENT_START
4778 #define ASM_COMMENT_START ";#"
4781 /* Define a macro which returns nonzero for a TYPE_DECL which was
4782 implicitly generated for a tagged type.
4784 Note that unlike the gcc front end (which generates a NULL named
4785 TYPE_DECL node for each complete tagged type, each array type, and
4786 each function type node created) the g++ front end generates a
4787 _named_ TYPE_DECL node for each tagged type node created.
4788 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4789 generate a DW_TAG_typedef DIE for them. */
4791 #define TYPE_DECL_IS_STUB(decl) \
4792 (DECL_NAME (decl) == NULL_TREE \
4793 || (DECL_ARTIFICIAL (decl) \
4794 && is_tagged_type (TREE_TYPE (decl)) \
4795 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4796 /* This is necessary for stub decls that \
4797 appear in nested inline functions. */ \
4798 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4799 && (decl_ultimate_origin (decl) \
4800 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4802 /* Information concerning the compilation unit's programming
4803 language, and compiler version. */
4805 /* Fixed size portion of the DWARF compilation unit header. */
4806 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4807 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4809 /* Fixed size portion of public names info. */
4810 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4812 /* Fixed size portion of the address range info. */
4813 #define DWARF_ARANGES_HEADER_SIZE \
4814 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4815 DWARF2_ADDR_SIZE * 2) \
4816 - DWARF_INITIAL_LENGTH_SIZE)
4818 /* Size of padding portion in the address range info. It must be
4819 aligned to twice the pointer size. */
4820 #define DWARF_ARANGES_PAD_SIZE \
4821 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4822 DWARF2_ADDR_SIZE * 2) \
4823 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4825 /* Use assembler line directives if available. */
4826 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4827 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4828 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4830 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4834 /* Minimum line offset in a special line info. opcode.
4835 This value was chosen to give a reasonable range of values. */
4836 #define DWARF_LINE_BASE -10
4838 /* First special line opcode - leave room for the standard opcodes. */
4839 #define DWARF_LINE_OPCODE_BASE 10
4841 /* Range of line offsets in a special line info. opcode. */
4842 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4844 /* Flag that indicates the initial value of the is_stmt_start flag.
4845 In the present implementation, we do not mark any lines as
4846 the beginning of a source statement, because that information
4847 is not made available by the GCC front-end. */
4848 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4850 #ifdef DWARF2_DEBUGGING_INFO
4851 /* This location is used by calc_die_sizes() to keep track
4852 the offset of each DIE within the .debug_info section. */
4853 static unsigned long next_die_offset;
4856 /* Record the root of the DIE's built for the current compilation unit. */
4857 static GTY(()) dw_die_ref comp_unit_die;
4859 /* A list of DIEs with a NULL parent waiting to be relocated. */
4860 static GTY(()) limbo_die_node *limbo_die_list;
4862 /* Filenames referenced by this compilation unit. */
4863 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
4865 /* A hash table of references to DIE's that describe declarations.
4866 The key is a DECL_UID() which is a unique number identifying each decl. */
4867 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4869 /* A hash table of references to DIE's that describe COMMON blocks.
4870 The key is DECL_UID() ^ die_parent. */
4871 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
4873 /* Node of the variable location list. */
4874 struct var_loc_node GTY ((chain_next ("%h.next")))
4876 rtx GTY (()) var_loc_note;
4877 const char * GTY (()) label;
4878 const char * GTY (()) section_label;
4879 struct var_loc_node * GTY (()) next;
4882 /* Variable location list. */
4883 struct var_loc_list_def GTY (())
4885 struct var_loc_node * GTY (()) first;
4887 /* Do not mark the last element of the chained list because
4888 it is marked through the chain. */
4889 struct var_loc_node * GTY ((skip ("%h"))) last;
4891 /* DECL_UID of the variable decl. */
4892 unsigned int decl_id;
4894 typedef struct var_loc_list_def var_loc_list;
4897 /* Table of decl location linked lists. */
4898 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4900 /* A pointer to the base of a list of references to DIE's that
4901 are uniquely identified by their tag, presence/absence of
4902 children DIE's, and list of attribute/value pairs. */
4903 static GTY((length ("abbrev_die_table_allocated")))
4904 dw_die_ref *abbrev_die_table;
4906 /* Number of elements currently allocated for abbrev_die_table. */
4907 static GTY(()) unsigned abbrev_die_table_allocated;
4909 /* Number of elements in type_die_table currently in use. */
4910 static GTY(()) unsigned abbrev_die_table_in_use;
4912 /* Size (in elements) of increments by which we may expand the
4913 abbrev_die_table. */
4914 #define ABBREV_DIE_TABLE_INCREMENT 256
4916 /* A pointer to the base of a table that contains line information
4917 for each source code line in .text in the compilation unit. */
4918 static GTY((length ("line_info_table_allocated")))
4919 dw_line_info_ref line_info_table;
4921 /* Number of elements currently allocated for line_info_table. */
4922 static GTY(()) unsigned line_info_table_allocated;
4924 /* Number of elements in line_info_table currently in use. */
4925 static GTY(()) unsigned line_info_table_in_use;
4927 /* A pointer to the base of a table that contains line information
4928 for each source code line outside of .text in the compilation unit. */
4929 static GTY ((length ("separate_line_info_table_allocated")))
4930 dw_separate_line_info_ref separate_line_info_table;
4932 /* Number of elements currently allocated for separate_line_info_table. */
4933 static GTY(()) unsigned separate_line_info_table_allocated;
4935 /* Number of elements in separate_line_info_table currently in use. */
4936 static GTY(()) unsigned separate_line_info_table_in_use;
4938 /* Size (in elements) of increments by which we may expand the
4940 #define LINE_INFO_TABLE_INCREMENT 1024
4942 /* A pointer to the base of a table that contains a list of publicly
4943 accessible names. */
4944 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4946 /* A pointer to the base of a table that contains a list of publicly
4947 accessible types. */
4948 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4950 /* Array of dies for which we should generate .debug_arange info. */
4951 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4953 /* Number of elements currently allocated for arange_table. */
4954 static GTY(()) unsigned arange_table_allocated;
4956 /* Number of elements in arange_table currently in use. */
4957 static GTY(()) unsigned arange_table_in_use;
4959 /* Size (in elements) of increments by which we may expand the
4961 #define ARANGE_TABLE_INCREMENT 64
4963 /* Array of dies for which we should generate .debug_ranges info. */
4964 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4966 /* Number of elements currently allocated for ranges_table. */
4967 static GTY(()) unsigned ranges_table_allocated;
4969 /* Number of elements in ranges_table currently in use. */
4970 static GTY(()) unsigned ranges_table_in_use;
4972 /* Array of pairs of labels referenced in ranges_table. */
4973 static GTY ((length ("ranges_by_label_allocated")))
4974 dw_ranges_by_label_ref ranges_by_label;
4976 /* Number of elements currently allocated for ranges_by_label. */
4977 static GTY(()) unsigned ranges_by_label_allocated;
4979 /* Number of elements in ranges_by_label currently in use. */
4980 static GTY(()) unsigned ranges_by_label_in_use;
4982 /* Size (in elements) of increments by which we may expand the
4984 #define RANGES_TABLE_INCREMENT 64
4986 /* Whether we have location lists that need outputting */
4987 static GTY(()) bool have_location_lists;
4989 /* Unique label counter. */
4990 static GTY(()) unsigned int loclabel_num;
4992 #ifdef DWARF2_DEBUGGING_INFO
4993 /* Record whether the function being analyzed contains inlined functions. */
4994 static int current_function_has_inlines;
4996 #if 0 && defined (MIPS_DEBUGGING_INFO)
4997 static int comp_unit_has_inlines;
5000 /* The last file entry emitted by maybe_emit_file(). */
5001 static GTY(()) struct dwarf_file_data * last_emitted_file;
5003 /* Number of internal labels generated by gen_internal_sym(). */
5004 static GTY(()) int label_num;
5006 /* Cached result of previous call to lookup_filename. */
5007 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5009 #ifdef DWARF2_DEBUGGING_INFO
5011 /* Offset from the "steady-state frame pointer" to the frame base,
5012 within the current function. */
5013 static HOST_WIDE_INT frame_pointer_fb_offset;
5015 /* Forward declarations for functions defined in this file. */
5017 static int is_pseudo_reg (const_rtx);
5018 static tree type_main_variant (tree);
5019 static int is_tagged_type (const_tree);
5020 static const char *dwarf_tag_name (unsigned);
5021 static const char *dwarf_attr_name (unsigned);
5022 static const char *dwarf_form_name (unsigned);
5023 static tree decl_ultimate_origin (const_tree);
5024 static tree decl_class_context (tree);
5025 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5026 static inline enum dw_val_class AT_class (dw_attr_ref);
5027 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5028 static inline unsigned AT_flag (dw_attr_ref);
5029 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5030 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5031 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5032 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5033 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
5035 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5036 unsigned int, unsigned char *);
5037 static hashval_t debug_str_do_hash (const void *);
5038 static int debug_str_eq (const void *, const void *);
5039 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5040 static inline const char *AT_string (dw_attr_ref);
5041 static int AT_string_form (dw_attr_ref);
5042 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5043 static void add_AT_specification (dw_die_ref, dw_die_ref);
5044 static inline dw_die_ref AT_ref (dw_attr_ref);
5045 static inline int AT_ref_external (dw_attr_ref);
5046 static inline void set_AT_ref_external (dw_attr_ref, int);
5047 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5048 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5049 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5050 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5052 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5053 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5054 static inline rtx AT_addr (dw_attr_ref);
5055 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5056 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5057 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5058 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5059 unsigned HOST_WIDE_INT);
5060 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5062 static inline const char *AT_lbl (dw_attr_ref);
5063 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5064 static const char *get_AT_low_pc (dw_die_ref);
5065 static const char *get_AT_hi_pc (dw_die_ref);
5066 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5067 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5068 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5069 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5070 static bool is_c_family (void);
5071 static bool is_cxx (void);
5072 static bool is_java (void);
5073 static bool is_fortran (void);
5074 static bool is_ada (void);
5075 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5076 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5077 static void add_child_die (dw_die_ref, dw_die_ref);
5078 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5079 static dw_die_ref lookup_type_die (tree);
5080 static void equate_type_number_to_die (tree, dw_die_ref);
5081 static hashval_t decl_die_table_hash (const void *);
5082 static int decl_die_table_eq (const void *, const void *);
5083 static dw_die_ref lookup_decl_die (tree);
5084 static hashval_t common_block_die_table_hash (const void *);
5085 static int common_block_die_table_eq (const void *, const void *);
5086 static hashval_t decl_loc_table_hash (const void *);
5087 static int decl_loc_table_eq (const void *, const void *);
5088 static var_loc_list *lookup_decl_loc (const_tree);
5089 static void equate_decl_number_to_die (tree, dw_die_ref);
5090 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5091 static void print_spaces (FILE *);
5092 static void print_die (dw_die_ref, FILE *);
5093 static void print_dwarf_line_table (FILE *);
5094 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5095 static dw_die_ref pop_compile_unit (dw_die_ref);
5096 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5097 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5098 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5099 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5100 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5101 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5102 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5103 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5104 static void compute_section_prefix (dw_die_ref);
5105 static int is_type_die (dw_die_ref);
5106 static int is_comdat_die (dw_die_ref);
5107 static int is_symbol_die (dw_die_ref);
5108 static void assign_symbol_names (dw_die_ref);
5109 static void break_out_includes (dw_die_ref);
5110 static hashval_t htab_cu_hash (const void *);
5111 static int htab_cu_eq (const void *, const void *);
5112 static void htab_cu_del (void *);
5113 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5114 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5115 static void add_sibling_attributes (dw_die_ref);
5116 static void build_abbrev_table (dw_die_ref);
5117 static void output_location_lists (dw_die_ref);
5118 static int constant_size (unsigned HOST_WIDE_INT);
5119 static unsigned long size_of_die (dw_die_ref);
5120 static void calc_die_sizes (dw_die_ref);
5121 static void mark_dies (dw_die_ref);
5122 static void unmark_dies (dw_die_ref);
5123 static void unmark_all_dies (dw_die_ref);
5124 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5125 static unsigned long size_of_aranges (void);
5126 static enum dwarf_form value_format (dw_attr_ref);
5127 static void output_value_format (dw_attr_ref);
5128 static void output_abbrev_section (void);
5129 static void output_die_symbol (dw_die_ref);
5130 static void output_die (dw_die_ref);
5131 static void output_compilation_unit_header (void);
5132 static void output_comp_unit (dw_die_ref, int);
5133 static const char *dwarf2_name (tree, int);
5134 static void add_pubname (tree, dw_die_ref);
5135 static void add_pubname_string (const char *, dw_die_ref);
5136 static void add_pubtype (tree, dw_die_ref);
5137 static void output_pubnames (VEC (pubname_entry,gc) *);
5138 static void add_arange (tree, dw_die_ref);
5139 static void output_aranges (void);
5140 static unsigned int add_ranges_num (int);
5141 static unsigned int add_ranges (const_tree);
5142 static unsigned int add_ranges_by_labels (const char *, const char *);
5143 static void output_ranges (void);
5144 static void output_line_info (void);
5145 static void output_file_names (void);
5146 static dw_die_ref base_type_die (tree);
5147 static int is_base_type (tree);
5148 static bool is_subrange_type (const_tree);
5149 static dw_die_ref subrange_type_die (tree, dw_die_ref);
5150 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5151 static int type_is_enum (const_tree);
5152 static unsigned int dbx_reg_number (const_rtx);
5153 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5154 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5155 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5156 enum var_init_status);
5157 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5158 enum var_init_status);
5159 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5160 enum var_init_status);
5161 static int is_based_loc (const_rtx);
5162 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5163 enum var_init_status);
5164 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5165 enum var_init_status);
5166 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5167 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5168 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5169 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5170 static tree field_type (const_tree);
5171 static unsigned int simple_type_align_in_bits (const_tree);
5172 static unsigned int simple_decl_align_in_bits (const_tree);
5173 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5174 static HOST_WIDE_INT field_byte_offset (const_tree);
5175 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5177 static void add_data_member_location_attribute (dw_die_ref, tree);
5178 static void add_const_value_attribute (dw_die_ref, rtx);
5179 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5180 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5181 static void insert_float (const_rtx, unsigned char *);
5182 static rtx rtl_for_decl_location (tree);
5183 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5184 enum dwarf_attribute);
5185 static void tree_add_const_value_attribute (dw_die_ref, tree);
5186 static void add_name_attribute (dw_die_ref, const char *);
5187 static void add_comp_dir_attribute (dw_die_ref);
5188 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5189 static void add_subscript_info (dw_die_ref, tree, bool);
5190 static void add_byte_size_attribute (dw_die_ref, tree);
5191 static void add_bit_offset_attribute (dw_die_ref, tree);
5192 static void add_bit_size_attribute (dw_die_ref, tree);
5193 static void add_prototyped_attribute (dw_die_ref, tree);
5194 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5195 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5196 static void add_src_coords_attributes (dw_die_ref, tree);
5197 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5198 static void push_decl_scope (tree);
5199 static void pop_decl_scope (void);
5200 static dw_die_ref scope_die_for (tree, dw_die_ref);
5201 static inline int local_scope_p (dw_die_ref);
5202 static inline int class_or_namespace_scope_p (dw_die_ref);
5203 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5204 static void add_calling_convention_attribute (dw_die_ref, tree);
5205 static const char *type_tag (const_tree);
5206 static tree member_declared_type (const_tree);
5208 static const char *decl_start_label (tree);
5210 static void gen_array_type_die (tree, dw_die_ref);
5211 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5213 static void gen_entry_point_die (tree, dw_die_ref);
5215 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5216 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5217 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5218 static void gen_formal_types_die (tree, dw_die_ref);
5219 static void gen_subprogram_die (tree, dw_die_ref);
5220 static void gen_variable_die (tree, tree, dw_die_ref);
5221 static void gen_const_die (tree, dw_die_ref);
5222 static void gen_label_die (tree, dw_die_ref);
5223 static void gen_lexical_block_die (tree, dw_die_ref, int);
5224 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5225 static void gen_field_die (tree, dw_die_ref);
5226 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5227 static dw_die_ref gen_compile_unit_die (const char *);
5228 static void gen_inheritance_die (tree, tree, dw_die_ref);
5229 static void gen_member_die (tree, dw_die_ref);
5230 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5231 enum debug_info_usage);
5232 static void gen_subroutine_type_die (tree, dw_die_ref);
5233 static void gen_typedef_die (tree, dw_die_ref);
5234 static void gen_type_die (tree, dw_die_ref);
5235 static void gen_block_die (tree, dw_die_ref, int);
5236 static void decls_for_scope (tree, dw_die_ref, int);
5237 static int is_redundant_typedef (const_tree);
5238 static void gen_namespace_die (tree, dw_die_ref);
5239 static void gen_decl_die (tree, tree, dw_die_ref);
5240 static dw_die_ref force_decl_die (tree);
5241 static dw_die_ref force_type_die (tree);
5242 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5243 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5244 static struct dwarf_file_data * lookup_filename (const char *);
5245 static void retry_incomplete_types (void);
5246 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5247 static void splice_child_die (dw_die_ref, dw_die_ref);
5248 static int file_info_cmp (const void *, const void *);
5249 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5250 const char *, const char *, unsigned);
5251 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5252 const char *, const char *,
5254 static void output_loc_list (dw_loc_list_ref);
5255 static char *gen_internal_sym (const char *);
5257 static void prune_unmark_dies (dw_die_ref);
5258 static void prune_unused_types_mark (dw_die_ref, int);
5259 static void prune_unused_types_walk (dw_die_ref);
5260 static void prune_unused_types_walk_attribs (dw_die_ref);
5261 static void prune_unused_types_prune (dw_die_ref);
5262 static void prune_unused_types (void);
5263 static int maybe_emit_file (struct dwarf_file_data *fd);
5265 /* Section names used to hold DWARF debugging information. */
5266 #ifndef DEBUG_INFO_SECTION
5267 #define DEBUG_INFO_SECTION ".debug_info"
5269 #ifndef DEBUG_ABBREV_SECTION
5270 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5272 #ifndef DEBUG_ARANGES_SECTION
5273 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5275 #ifndef DEBUG_MACINFO_SECTION
5276 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5278 #ifndef DEBUG_LINE_SECTION
5279 #define DEBUG_LINE_SECTION ".debug_line"
5281 #ifndef DEBUG_LOC_SECTION
5282 #define DEBUG_LOC_SECTION ".debug_loc"
5284 #ifndef DEBUG_PUBNAMES_SECTION
5285 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5287 #ifndef DEBUG_STR_SECTION
5288 #define DEBUG_STR_SECTION ".debug_str"
5290 #ifndef DEBUG_RANGES_SECTION
5291 #define DEBUG_RANGES_SECTION ".debug_ranges"
5294 /* Standard ELF section names for compiled code and data. */
5295 #ifndef TEXT_SECTION_NAME
5296 #define TEXT_SECTION_NAME ".text"
5299 /* Section flags for .debug_str section. */
5300 #define DEBUG_STR_SECTION_FLAGS \
5301 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5302 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5305 /* Labels we insert at beginning sections we can reference instead of
5306 the section names themselves. */
5308 #ifndef TEXT_SECTION_LABEL
5309 #define TEXT_SECTION_LABEL "Ltext"
5311 #ifndef COLD_TEXT_SECTION_LABEL
5312 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5314 #ifndef DEBUG_LINE_SECTION_LABEL
5315 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5317 #ifndef DEBUG_INFO_SECTION_LABEL
5318 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5320 #ifndef DEBUG_ABBREV_SECTION_LABEL
5321 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5323 #ifndef DEBUG_LOC_SECTION_LABEL
5324 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5326 #ifndef DEBUG_RANGES_SECTION_LABEL
5327 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5329 #ifndef DEBUG_MACINFO_SECTION_LABEL
5330 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5333 /* Definitions of defaults for formats and names of various special
5334 (artificial) labels which may be generated within this file (when the -g
5335 options is used and DWARF2_DEBUGGING_INFO is in effect.
5336 If necessary, these may be overridden from within the tm.h file, but
5337 typically, overriding these defaults is unnecessary. */
5339 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5340 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5341 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5342 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5343 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5344 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5345 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5346 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5347 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5348 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5350 #ifndef TEXT_END_LABEL
5351 #define TEXT_END_LABEL "Letext"
5353 #ifndef COLD_END_LABEL
5354 #define COLD_END_LABEL "Letext_cold"
5356 #ifndef BLOCK_BEGIN_LABEL
5357 #define BLOCK_BEGIN_LABEL "LBB"
5359 #ifndef BLOCK_END_LABEL
5360 #define BLOCK_END_LABEL "LBE"
5362 #ifndef LINE_CODE_LABEL
5363 #define LINE_CODE_LABEL "LM"
5365 #ifndef SEPARATE_LINE_CODE_LABEL
5366 #define SEPARATE_LINE_CODE_LABEL "LSM"
5370 /* We allow a language front-end to designate a function that is to be
5371 called to "demangle" any name before it is put into a DIE. */
5373 static const char *(*demangle_name_func) (const char *);
5376 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5378 demangle_name_func = func;
5381 /* Test if rtl node points to a pseudo register. */
5384 is_pseudo_reg (const_rtx rtl)
5386 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5387 || (GET_CODE (rtl) == SUBREG
5388 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5391 /* Return a reference to a type, with its const and volatile qualifiers
5395 type_main_variant (tree type)
5397 type = TYPE_MAIN_VARIANT (type);
5399 /* ??? There really should be only one main variant among any group of
5400 variants of a given type (and all of the MAIN_VARIANT values for all
5401 members of the group should point to that one type) but sometimes the C
5402 front-end messes this up for array types, so we work around that bug
5404 if (TREE_CODE (type) == ARRAY_TYPE)
5405 while (type != TYPE_MAIN_VARIANT (type))
5406 type = TYPE_MAIN_VARIANT (type);
5411 /* Return nonzero if the given type node represents a tagged type. */
5414 is_tagged_type (const_tree type)
5416 enum tree_code code = TREE_CODE (type);
5418 return (code == RECORD_TYPE || code == UNION_TYPE
5419 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5422 /* Convert a DIE tag into its string name. */
5425 dwarf_tag_name (unsigned int tag)
5429 case DW_TAG_padding:
5430 return "DW_TAG_padding";
5431 case DW_TAG_array_type:
5432 return "DW_TAG_array_type";
5433 case DW_TAG_class_type:
5434 return "DW_TAG_class_type";
5435 case DW_TAG_entry_point:
5436 return "DW_TAG_entry_point";
5437 case DW_TAG_enumeration_type:
5438 return "DW_TAG_enumeration_type";
5439 case DW_TAG_formal_parameter:
5440 return "DW_TAG_formal_parameter";
5441 case DW_TAG_imported_declaration:
5442 return "DW_TAG_imported_declaration";
5444 return "DW_TAG_label";
5445 case DW_TAG_lexical_block:
5446 return "DW_TAG_lexical_block";
5448 return "DW_TAG_member";
5449 case DW_TAG_pointer_type:
5450 return "DW_TAG_pointer_type";
5451 case DW_TAG_reference_type:
5452 return "DW_TAG_reference_type";
5453 case DW_TAG_compile_unit:
5454 return "DW_TAG_compile_unit";
5455 case DW_TAG_string_type:
5456 return "DW_TAG_string_type";
5457 case DW_TAG_structure_type:
5458 return "DW_TAG_structure_type";
5459 case DW_TAG_subroutine_type:
5460 return "DW_TAG_subroutine_type";
5461 case DW_TAG_typedef:
5462 return "DW_TAG_typedef";
5463 case DW_TAG_union_type:
5464 return "DW_TAG_union_type";
5465 case DW_TAG_unspecified_parameters:
5466 return "DW_TAG_unspecified_parameters";
5467 case DW_TAG_variant:
5468 return "DW_TAG_variant";
5469 case DW_TAG_common_block:
5470 return "DW_TAG_common_block";
5471 case DW_TAG_common_inclusion:
5472 return "DW_TAG_common_inclusion";
5473 case DW_TAG_inheritance:
5474 return "DW_TAG_inheritance";
5475 case DW_TAG_inlined_subroutine:
5476 return "DW_TAG_inlined_subroutine";
5478 return "DW_TAG_module";
5479 case DW_TAG_ptr_to_member_type:
5480 return "DW_TAG_ptr_to_member_type";
5481 case DW_TAG_set_type:
5482 return "DW_TAG_set_type";
5483 case DW_TAG_subrange_type:
5484 return "DW_TAG_subrange_type";
5485 case DW_TAG_with_stmt:
5486 return "DW_TAG_with_stmt";
5487 case DW_TAG_access_declaration:
5488 return "DW_TAG_access_declaration";
5489 case DW_TAG_base_type:
5490 return "DW_TAG_base_type";
5491 case DW_TAG_catch_block:
5492 return "DW_TAG_catch_block";
5493 case DW_TAG_const_type:
5494 return "DW_TAG_const_type";
5495 case DW_TAG_constant:
5496 return "DW_TAG_constant";
5497 case DW_TAG_enumerator:
5498 return "DW_TAG_enumerator";
5499 case DW_TAG_file_type:
5500 return "DW_TAG_file_type";
5502 return "DW_TAG_friend";
5503 case DW_TAG_namelist:
5504 return "DW_TAG_namelist";
5505 case DW_TAG_namelist_item:
5506 return "DW_TAG_namelist_item";
5507 case DW_TAG_packed_type:
5508 return "DW_TAG_packed_type";
5509 case DW_TAG_subprogram:
5510 return "DW_TAG_subprogram";
5511 case DW_TAG_template_type_param:
5512 return "DW_TAG_template_type_param";
5513 case DW_TAG_template_value_param:
5514 return "DW_TAG_template_value_param";
5515 case DW_TAG_thrown_type:
5516 return "DW_TAG_thrown_type";
5517 case DW_TAG_try_block:
5518 return "DW_TAG_try_block";
5519 case DW_TAG_variant_part:
5520 return "DW_TAG_variant_part";
5521 case DW_TAG_variable:
5522 return "DW_TAG_variable";
5523 case DW_TAG_volatile_type:
5524 return "DW_TAG_volatile_type";
5525 case DW_TAG_dwarf_procedure:
5526 return "DW_TAG_dwarf_procedure";
5527 case DW_TAG_restrict_type:
5528 return "DW_TAG_restrict_type";
5529 case DW_TAG_interface_type:
5530 return "DW_TAG_interface_type";
5531 case DW_TAG_namespace:
5532 return "DW_TAG_namespace";
5533 case DW_TAG_imported_module:
5534 return "DW_TAG_imported_module";
5535 case DW_TAG_unspecified_type:
5536 return "DW_TAG_unspecified_type";
5537 case DW_TAG_partial_unit:
5538 return "DW_TAG_partial_unit";
5539 case DW_TAG_imported_unit:
5540 return "DW_TAG_imported_unit";
5541 case DW_TAG_condition:
5542 return "DW_TAG_condition";
5543 case DW_TAG_shared_type:
5544 return "DW_TAG_shared_type";
5545 case DW_TAG_MIPS_loop:
5546 return "DW_TAG_MIPS_loop";
5547 case DW_TAG_format_label:
5548 return "DW_TAG_format_label";
5549 case DW_TAG_function_template:
5550 return "DW_TAG_function_template";
5551 case DW_TAG_class_template:
5552 return "DW_TAG_class_template";
5553 case DW_TAG_GNU_BINCL:
5554 return "DW_TAG_GNU_BINCL";
5555 case DW_TAG_GNU_EINCL:
5556 return "DW_TAG_GNU_EINCL";
5558 return "DW_TAG_<unknown>";
5562 /* Convert a DWARF attribute code into its string name. */
5565 dwarf_attr_name (unsigned int attr)
5570 return "DW_AT_sibling";
5571 case DW_AT_location:
5572 return "DW_AT_location";
5574 return "DW_AT_name";
5575 case DW_AT_ordering:
5576 return "DW_AT_ordering";
5577 case DW_AT_subscr_data:
5578 return "DW_AT_subscr_data";
5579 case DW_AT_byte_size:
5580 return "DW_AT_byte_size";
5581 case DW_AT_bit_offset:
5582 return "DW_AT_bit_offset";
5583 case DW_AT_bit_size:
5584 return "DW_AT_bit_size";
5585 case DW_AT_element_list:
5586 return "DW_AT_element_list";
5587 case DW_AT_stmt_list:
5588 return "DW_AT_stmt_list";
5590 return "DW_AT_low_pc";
5592 return "DW_AT_high_pc";
5593 case DW_AT_language:
5594 return "DW_AT_language";
5596 return "DW_AT_member";
5598 return "DW_AT_discr";
5599 case DW_AT_discr_value:
5600 return "DW_AT_discr_value";
5601 case DW_AT_visibility:
5602 return "DW_AT_visibility";
5604 return "DW_AT_import";
5605 case DW_AT_string_length:
5606 return "DW_AT_string_length";
5607 case DW_AT_common_reference:
5608 return "DW_AT_common_reference";
5609 case DW_AT_comp_dir:
5610 return "DW_AT_comp_dir";
5611 case DW_AT_const_value:
5612 return "DW_AT_const_value";
5613 case DW_AT_containing_type:
5614 return "DW_AT_containing_type";
5615 case DW_AT_default_value:
5616 return "DW_AT_default_value";
5618 return "DW_AT_inline";
5619 case DW_AT_is_optional:
5620 return "DW_AT_is_optional";
5621 case DW_AT_lower_bound:
5622 return "DW_AT_lower_bound";
5623 case DW_AT_producer:
5624 return "DW_AT_producer";
5625 case DW_AT_prototyped:
5626 return "DW_AT_prototyped";
5627 case DW_AT_return_addr:
5628 return "DW_AT_return_addr";
5629 case DW_AT_start_scope:
5630 return "DW_AT_start_scope";
5631 case DW_AT_bit_stride:
5632 return "DW_AT_bit_stride";
5633 case DW_AT_upper_bound:
5634 return "DW_AT_upper_bound";
5635 case DW_AT_abstract_origin:
5636 return "DW_AT_abstract_origin";
5637 case DW_AT_accessibility:
5638 return "DW_AT_accessibility";
5639 case DW_AT_address_class:
5640 return "DW_AT_address_class";
5641 case DW_AT_artificial:
5642 return "DW_AT_artificial";
5643 case DW_AT_base_types:
5644 return "DW_AT_base_types";
5645 case DW_AT_calling_convention:
5646 return "DW_AT_calling_convention";
5648 return "DW_AT_count";
5649 case DW_AT_data_member_location:
5650 return "DW_AT_data_member_location";
5651 case DW_AT_decl_column:
5652 return "DW_AT_decl_column";
5653 case DW_AT_decl_file:
5654 return "DW_AT_decl_file";
5655 case DW_AT_decl_line:
5656 return "DW_AT_decl_line";
5657 case DW_AT_declaration:
5658 return "DW_AT_declaration";
5659 case DW_AT_discr_list:
5660 return "DW_AT_discr_list";
5661 case DW_AT_encoding:
5662 return "DW_AT_encoding";
5663 case DW_AT_external:
5664 return "DW_AT_external";
5665 case DW_AT_frame_base:
5666 return "DW_AT_frame_base";
5668 return "DW_AT_friend";
5669 case DW_AT_identifier_case:
5670 return "DW_AT_identifier_case";
5671 case DW_AT_macro_info:
5672 return "DW_AT_macro_info";
5673 case DW_AT_namelist_items:
5674 return "DW_AT_namelist_items";
5675 case DW_AT_priority:
5676 return "DW_AT_priority";
5678 return "DW_AT_segment";
5679 case DW_AT_specification:
5680 return "DW_AT_specification";
5681 case DW_AT_static_link:
5682 return "DW_AT_static_link";
5684 return "DW_AT_type";
5685 case DW_AT_use_location:
5686 return "DW_AT_use_location";
5687 case DW_AT_variable_parameter:
5688 return "DW_AT_variable_parameter";
5689 case DW_AT_virtuality:
5690 return "DW_AT_virtuality";
5691 case DW_AT_vtable_elem_location:
5692 return "DW_AT_vtable_elem_location";
5694 case DW_AT_allocated:
5695 return "DW_AT_allocated";
5696 case DW_AT_associated:
5697 return "DW_AT_associated";
5698 case DW_AT_data_location:
5699 return "DW_AT_data_location";
5700 case DW_AT_byte_stride:
5701 return "DW_AT_byte_stride";
5702 case DW_AT_entry_pc:
5703 return "DW_AT_entry_pc";
5704 case DW_AT_use_UTF8:
5705 return "DW_AT_use_UTF8";
5706 case DW_AT_extension:
5707 return "DW_AT_extension";
5709 return "DW_AT_ranges";
5710 case DW_AT_trampoline:
5711 return "DW_AT_trampoline";
5712 case DW_AT_call_column:
5713 return "DW_AT_call_column";
5714 case DW_AT_call_file:
5715 return "DW_AT_call_file";
5716 case DW_AT_call_line:
5717 return "DW_AT_call_line";
5719 case DW_AT_MIPS_fde:
5720 return "DW_AT_MIPS_fde";
5721 case DW_AT_MIPS_loop_begin:
5722 return "DW_AT_MIPS_loop_begin";
5723 case DW_AT_MIPS_tail_loop_begin:
5724 return "DW_AT_MIPS_tail_loop_begin";
5725 case DW_AT_MIPS_epilog_begin:
5726 return "DW_AT_MIPS_epilog_begin";
5727 case DW_AT_MIPS_loop_unroll_factor:
5728 return "DW_AT_MIPS_loop_unroll_factor";
5729 case DW_AT_MIPS_software_pipeline_depth:
5730 return "DW_AT_MIPS_software_pipeline_depth";
5731 case DW_AT_MIPS_linkage_name:
5732 return "DW_AT_MIPS_linkage_name";
5733 case DW_AT_MIPS_stride:
5734 return "DW_AT_MIPS_stride";
5735 case DW_AT_MIPS_abstract_name:
5736 return "DW_AT_MIPS_abstract_name";
5737 case DW_AT_MIPS_clone_origin:
5738 return "DW_AT_MIPS_clone_origin";
5739 case DW_AT_MIPS_has_inlines:
5740 return "DW_AT_MIPS_has_inlines";
5742 case DW_AT_sf_names:
5743 return "DW_AT_sf_names";
5744 case DW_AT_src_info:
5745 return "DW_AT_src_info";
5746 case DW_AT_mac_info:
5747 return "DW_AT_mac_info";
5748 case DW_AT_src_coords:
5749 return "DW_AT_src_coords";
5750 case DW_AT_body_begin:
5751 return "DW_AT_body_begin";
5752 case DW_AT_body_end:
5753 return "DW_AT_body_end";
5754 case DW_AT_GNU_vector:
5755 return "DW_AT_GNU_vector";
5757 case DW_AT_VMS_rtnbeg_pd_address:
5758 return "DW_AT_VMS_rtnbeg_pd_address";
5761 return "DW_AT_<unknown>";
5765 /* Convert a DWARF value form code into its string name. */
5768 dwarf_form_name (unsigned int form)
5773 return "DW_FORM_addr";
5774 case DW_FORM_block2:
5775 return "DW_FORM_block2";
5776 case DW_FORM_block4:
5777 return "DW_FORM_block4";
5779 return "DW_FORM_data2";
5781 return "DW_FORM_data4";
5783 return "DW_FORM_data8";
5784 case DW_FORM_string:
5785 return "DW_FORM_string";
5787 return "DW_FORM_block";
5788 case DW_FORM_block1:
5789 return "DW_FORM_block1";
5791 return "DW_FORM_data1";
5793 return "DW_FORM_flag";
5795 return "DW_FORM_sdata";
5797 return "DW_FORM_strp";
5799 return "DW_FORM_udata";
5800 case DW_FORM_ref_addr:
5801 return "DW_FORM_ref_addr";
5803 return "DW_FORM_ref1";
5805 return "DW_FORM_ref2";
5807 return "DW_FORM_ref4";
5809 return "DW_FORM_ref8";
5810 case DW_FORM_ref_udata:
5811 return "DW_FORM_ref_udata";
5812 case DW_FORM_indirect:
5813 return "DW_FORM_indirect";
5815 return "DW_FORM_<unknown>";
5819 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5820 instance of an inlined instance of a decl which is local to an inline
5821 function, so we have to trace all of the way back through the origin chain
5822 to find out what sort of node actually served as the original seed for the
5826 decl_ultimate_origin (const_tree decl)
5828 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
5831 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5832 nodes in the function to point to themselves; ignore that if
5833 we're trying to output the abstract instance of this function. */
5834 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
5837 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5838 most distant ancestor, this should never happen. */
5839 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
5841 return DECL_ABSTRACT_ORIGIN (decl);
5844 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5845 of a virtual function may refer to a base class, so we check the 'this'
5849 decl_class_context (tree decl)
5851 tree context = NULL_TREE;
5853 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5854 context = DECL_CONTEXT (decl);
5856 context = TYPE_MAIN_VARIANT
5857 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5859 if (context && !TYPE_P (context))
5860 context = NULL_TREE;
5865 /* Add an attribute/value pair to a DIE. */
5868 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5870 /* Maybe this should be an assert? */
5874 if (die->die_attr == NULL)
5875 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5876 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5879 static inline enum dw_val_class
5880 AT_class (dw_attr_ref a)
5882 return a->dw_attr_val.val_class;
5885 /* Add a flag value attribute to a DIE. */
5888 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5892 attr.dw_attr = attr_kind;
5893 attr.dw_attr_val.val_class = dw_val_class_flag;
5894 attr.dw_attr_val.v.val_flag = flag;
5895 add_dwarf_attr (die, &attr);
5898 static inline unsigned
5899 AT_flag (dw_attr_ref a)
5901 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5902 return a->dw_attr_val.v.val_flag;
5905 /* Add a signed integer attribute value to a DIE. */
5908 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5912 attr.dw_attr = attr_kind;
5913 attr.dw_attr_val.val_class = dw_val_class_const;
5914 attr.dw_attr_val.v.val_int = int_val;
5915 add_dwarf_attr (die, &attr);
5918 static inline HOST_WIDE_INT
5919 AT_int (dw_attr_ref a)
5921 gcc_assert (a && AT_class (a) == dw_val_class_const);
5922 return a->dw_attr_val.v.val_int;
5925 /* Add an unsigned integer attribute value to a DIE. */
5928 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5929 unsigned HOST_WIDE_INT unsigned_val)
5933 attr.dw_attr = attr_kind;
5934 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5935 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5936 add_dwarf_attr (die, &attr);
5939 static inline unsigned HOST_WIDE_INT
5940 AT_unsigned (dw_attr_ref a)
5942 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5943 return a->dw_attr_val.v.val_unsigned;
5946 /* Add an unsigned double integer attribute value to a DIE. */
5949 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5950 long unsigned int val_hi, long unsigned int val_low)
5954 attr.dw_attr = attr_kind;
5955 attr.dw_attr_val.val_class = dw_val_class_long_long;
5956 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5957 attr.dw_attr_val.v.val_long_long.low = val_low;
5958 add_dwarf_attr (die, &attr);
5961 /* Add a floating point attribute value to a DIE and return it. */
5964 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5965 unsigned int length, unsigned int elt_size, unsigned char *array)
5969 attr.dw_attr = attr_kind;
5970 attr.dw_attr_val.val_class = dw_val_class_vec;
5971 attr.dw_attr_val.v.val_vec.length = length;
5972 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5973 attr.dw_attr_val.v.val_vec.array = array;
5974 add_dwarf_attr (die, &attr);
5977 /* Hash and equality functions for debug_str_hash. */
5980 debug_str_do_hash (const void *x)
5982 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5986 debug_str_eq (const void *x1, const void *x2)
5988 return strcmp ((((const struct indirect_string_node *)x1)->str),
5989 (const char *)x2) == 0;
5992 /* Add a string attribute value to a DIE. */
5995 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5998 struct indirect_string_node *node;
6001 if (! debug_str_hash)
6002 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6003 debug_str_eq, NULL);
6005 slot = htab_find_slot_with_hash (debug_str_hash, str,
6006 htab_hash_string (str), INSERT);
6009 node = (struct indirect_string_node *)
6010 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6011 node->str = ggc_strdup (str);
6015 node = (struct indirect_string_node *) *slot;
6019 attr.dw_attr = attr_kind;
6020 attr.dw_attr_val.val_class = dw_val_class_str;
6021 attr.dw_attr_val.v.val_str = node;
6022 add_dwarf_attr (die, &attr);
6025 static inline const char *
6026 AT_string (dw_attr_ref a)
6028 gcc_assert (a && AT_class (a) == dw_val_class_str);
6029 return a->dw_attr_val.v.val_str->str;
6032 /* Find out whether a string should be output inline in DIE
6033 or out-of-line in .debug_str section. */
6036 AT_string_form (dw_attr_ref a)
6038 struct indirect_string_node *node;
6042 gcc_assert (a && AT_class (a) == dw_val_class_str);
6044 node = a->dw_attr_val.v.val_str;
6048 len = strlen (node->str) + 1;
6050 /* If the string is shorter or equal to the size of the reference, it is
6051 always better to put it inline. */
6052 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6053 return node->form = DW_FORM_string;
6055 /* If we cannot expect the linker to merge strings in .debug_str
6056 section, only put it into .debug_str if it is worth even in this
6058 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
6059 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
6060 return node->form = DW_FORM_string;
6062 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6063 ++dw2_string_counter;
6064 node->label = xstrdup (label);
6066 return node->form = DW_FORM_strp;
6069 /* Add a DIE reference attribute value to a DIE. */
6072 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6076 attr.dw_attr = attr_kind;
6077 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6078 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6079 attr.dw_attr_val.v.val_die_ref.external = 0;
6080 add_dwarf_attr (die, &attr);
6083 /* Add an AT_specification attribute to a DIE, and also make the back
6084 pointer from the specification to the definition. */
6087 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6089 add_AT_die_ref (die, DW_AT_specification, targ_die);
6090 gcc_assert (!targ_die->die_definition);
6091 targ_die->die_definition = die;
6094 static inline dw_die_ref
6095 AT_ref (dw_attr_ref a)
6097 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6098 return a->dw_attr_val.v.val_die_ref.die;
6102 AT_ref_external (dw_attr_ref a)
6104 if (a && AT_class (a) == dw_val_class_die_ref)
6105 return a->dw_attr_val.v.val_die_ref.external;
6111 set_AT_ref_external (dw_attr_ref a, int i)
6113 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6114 a->dw_attr_val.v.val_die_ref.external = i;
6117 /* Add an FDE reference attribute value to a DIE. */
6120 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6124 attr.dw_attr = attr_kind;
6125 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6126 attr.dw_attr_val.v.val_fde_index = targ_fde;
6127 add_dwarf_attr (die, &attr);
6130 /* Add a location description attribute value to a DIE. */
6133 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6137 attr.dw_attr = attr_kind;
6138 attr.dw_attr_val.val_class = dw_val_class_loc;
6139 attr.dw_attr_val.v.val_loc = loc;
6140 add_dwarf_attr (die, &attr);
6143 static inline dw_loc_descr_ref
6144 AT_loc (dw_attr_ref a)
6146 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6147 return a->dw_attr_val.v.val_loc;
6151 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6155 attr.dw_attr = attr_kind;
6156 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6157 attr.dw_attr_val.v.val_loc_list = loc_list;
6158 add_dwarf_attr (die, &attr);
6159 have_location_lists = true;
6162 static inline dw_loc_list_ref
6163 AT_loc_list (dw_attr_ref a)
6165 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6166 return a->dw_attr_val.v.val_loc_list;
6169 /* Add an address constant attribute value to a DIE. */
6172 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6176 attr.dw_attr = attr_kind;
6177 attr.dw_attr_val.val_class = dw_val_class_addr;
6178 attr.dw_attr_val.v.val_addr = addr;
6179 add_dwarf_attr (die, &attr);
6182 /* Get the RTX from to an address DIE attribute. */
6185 AT_addr (dw_attr_ref a)
6187 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6188 return a->dw_attr_val.v.val_addr;
6191 /* Add a file attribute value to a DIE. */
6194 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6195 struct dwarf_file_data *fd)
6199 attr.dw_attr = attr_kind;
6200 attr.dw_attr_val.val_class = dw_val_class_file;
6201 attr.dw_attr_val.v.val_file = fd;
6202 add_dwarf_attr (die, &attr);
6205 /* Get the dwarf_file_data from a file DIE attribute. */
6207 static inline struct dwarf_file_data *
6208 AT_file (dw_attr_ref a)
6210 gcc_assert (a && AT_class (a) == dw_val_class_file);
6211 return a->dw_attr_val.v.val_file;
6214 /* Add a label identifier attribute value to a DIE. */
6217 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6221 attr.dw_attr = attr_kind;
6222 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6223 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6224 add_dwarf_attr (die, &attr);
6227 /* Add a section offset attribute value to a DIE, an offset into the
6228 debug_line section. */
6231 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6236 attr.dw_attr = attr_kind;
6237 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6238 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6239 add_dwarf_attr (die, &attr);
6242 /* Add a section offset attribute value to a DIE, an offset into the
6243 debug_macinfo section. */
6246 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6251 attr.dw_attr = attr_kind;
6252 attr.dw_attr_val.val_class = dw_val_class_macptr;
6253 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6254 add_dwarf_attr (die, &attr);
6257 /* Add an offset attribute value to a DIE. */
6260 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6261 unsigned HOST_WIDE_INT offset)
6265 attr.dw_attr = attr_kind;
6266 attr.dw_attr_val.val_class = dw_val_class_offset;
6267 attr.dw_attr_val.v.val_offset = offset;
6268 add_dwarf_attr (die, &attr);
6271 /* Add an range_list attribute value to a DIE. */
6274 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6275 long unsigned int offset)
6279 attr.dw_attr = attr_kind;
6280 attr.dw_attr_val.val_class = dw_val_class_range_list;
6281 attr.dw_attr_val.v.val_offset = offset;
6282 add_dwarf_attr (die, &attr);
6285 static inline const char *
6286 AT_lbl (dw_attr_ref a)
6288 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6289 || AT_class (a) == dw_val_class_lineptr
6290 || AT_class (a) == dw_val_class_macptr));
6291 return a->dw_attr_val.v.val_lbl_id;
6294 /* Get the attribute of type attr_kind. */
6297 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6301 dw_die_ref spec = NULL;
6306 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6307 if (a->dw_attr == attr_kind)
6309 else if (a->dw_attr == DW_AT_specification
6310 || a->dw_attr == DW_AT_abstract_origin)
6314 return get_AT (spec, attr_kind);
6319 /* Return the "low pc" attribute value, typically associated with a subprogram
6320 DIE. Return null if the "low pc" attribute is either not present, or if it
6321 cannot be represented as an assembler label identifier. */
6323 static inline const char *
6324 get_AT_low_pc (dw_die_ref die)
6326 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6328 return a ? AT_lbl (a) : NULL;
6331 /* Return the "high pc" attribute value, typically associated with a subprogram
6332 DIE. Return null if the "high pc" attribute is either not present, or if it
6333 cannot be represented as an assembler label identifier. */
6335 static inline const char *
6336 get_AT_hi_pc (dw_die_ref die)
6338 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6340 return a ? AT_lbl (a) : NULL;
6343 /* Return the value of the string attribute designated by ATTR_KIND, or
6344 NULL if it is not present. */
6346 static inline const char *
6347 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6349 dw_attr_ref a = get_AT (die, attr_kind);
6351 return a ? AT_string (a) : NULL;
6354 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6355 if it is not present. */
6358 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6360 dw_attr_ref a = get_AT (die, attr_kind);
6362 return a ? AT_flag (a) : 0;
6365 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6366 if it is not present. */
6368 static inline unsigned
6369 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6371 dw_attr_ref a = get_AT (die, attr_kind);
6373 return a ? AT_unsigned (a) : 0;
6376 static inline dw_die_ref
6377 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6379 dw_attr_ref a = get_AT (die, attr_kind);
6381 return a ? AT_ref (a) : NULL;
6384 static inline struct dwarf_file_data *
6385 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6387 dw_attr_ref a = get_AT (die, attr_kind);
6389 return a ? AT_file (a) : NULL;
6392 /* Return TRUE if the language is C or C++. */
6397 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6399 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6400 || lang == DW_LANG_C99
6401 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6404 /* Return TRUE if the language is C++. */
6409 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6411 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6414 /* Return TRUE if the language is Fortran. */
6419 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6421 return (lang == DW_LANG_Fortran77
6422 || lang == DW_LANG_Fortran90
6423 || lang == DW_LANG_Fortran95);
6426 /* Return TRUE if the language is Java. */
6431 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6433 return lang == DW_LANG_Java;
6436 /* Return TRUE if the language is Ada. */
6441 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6443 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6446 /* Remove the specified attribute if present. */
6449 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6457 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6458 if (a->dw_attr == attr_kind)
6460 if (AT_class (a) == dw_val_class_str)
6461 if (a->dw_attr_val.v.val_str->refcount)
6462 a->dw_attr_val.v.val_str->refcount--;
6464 /* VEC_ordered_remove should help reduce the number of abbrevs
6466 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6471 /* Remove CHILD from its parent. PREV must have the property that
6472 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6475 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6477 gcc_assert (child->die_parent == prev->die_parent);
6478 gcc_assert (prev->die_sib == child);
6481 gcc_assert (child->die_parent->die_child == child);
6485 prev->die_sib = child->die_sib;
6486 if (child->die_parent->die_child == child)
6487 child->die_parent->die_child = prev;
6490 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6494 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6500 dw_die_ref prev = c;
6502 while (c->die_tag == tag)
6504 remove_child_with_prev (c, prev);
6505 /* Might have removed every child. */
6506 if (c == c->die_sib)
6510 } while (c != die->die_child);
6513 /* Add a CHILD_DIE as the last child of DIE. */
6516 add_child_die (dw_die_ref die, dw_die_ref child_die)
6518 /* FIXME this should probably be an assert. */
6519 if (! die || ! child_die)
6521 gcc_assert (die != child_die);
6523 child_die->die_parent = die;
6526 child_die->die_sib = die->die_child->die_sib;
6527 die->die_child->die_sib = child_die;
6530 child_die->die_sib = child_die;
6531 die->die_child = child_die;
6534 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6535 is the specification, to the end of PARENT's list of children.
6536 This is done by removing and re-adding it. */
6539 splice_child_die (dw_die_ref parent, dw_die_ref child)
6543 /* We want the declaration DIE from inside the class, not the
6544 specification DIE at toplevel. */
6545 if (child->die_parent != parent)
6547 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6553 gcc_assert (child->die_parent == parent
6554 || (child->die_parent
6555 == get_AT_ref (parent, DW_AT_specification)));
6557 for (p = child->die_parent->die_child; ; p = p->die_sib)
6558 if (p->die_sib == child)
6560 remove_child_with_prev (child, p);
6564 add_child_die (parent, child);
6567 /* Return a pointer to a newly created DIE node. */
6569 static inline dw_die_ref
6570 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6572 dw_die_ref die = GGC_CNEW (die_node);
6574 die->die_tag = tag_value;
6576 if (parent_die != NULL)
6577 add_child_die (parent_die, die);
6580 limbo_die_node *limbo_node;
6582 limbo_node = GGC_CNEW (limbo_die_node);
6583 limbo_node->die = die;
6584 limbo_node->created_for = t;
6585 limbo_node->next = limbo_die_list;
6586 limbo_die_list = limbo_node;
6592 /* Return the DIE associated with the given type specifier. */
6594 static inline dw_die_ref
6595 lookup_type_die (tree type)
6597 return TYPE_SYMTAB_DIE (type);
6600 /* Equate a DIE to a given type specifier. */
6603 equate_type_number_to_die (tree type, dw_die_ref type_die)
6605 TYPE_SYMTAB_DIE (type) = type_die;
6608 /* Returns a hash value for X (which really is a die_struct). */
6611 decl_die_table_hash (const void *x)
6613 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
6616 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6619 decl_die_table_eq (const void *x, const void *y)
6621 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
6624 /* Return the DIE associated with a given declaration. */
6626 static inline dw_die_ref
6627 lookup_decl_die (tree decl)
6629 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
6632 /* Returns a hash value for X (which really is a var_loc_list). */
6635 decl_loc_table_hash (const void *x)
6637 return (hashval_t) ((const var_loc_list *) x)->decl_id;
6640 /* Return nonzero if decl_id of var_loc_list X is the same as
6644 decl_loc_table_eq (const void *x, const void *y)
6646 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
6649 /* Return the var_loc list associated with a given declaration. */
6651 static inline var_loc_list *
6652 lookup_decl_loc (const_tree decl)
6654 return (var_loc_list *)
6655 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
6658 /* Equate a DIE to a particular declaration. */
6661 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6663 unsigned int decl_id = DECL_UID (decl);
6666 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
6668 decl_die->decl_id = decl_id;
6671 /* Add a variable location node to the linked list for DECL. */
6674 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
6676 unsigned int decl_id = DECL_UID (decl);
6680 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
6683 temp = GGC_CNEW (var_loc_list);
6684 temp->decl_id = decl_id;
6688 temp = (var_loc_list *) *slot;
6692 /* If the current location is the same as the end of the list,
6693 and either both or neither of the locations is uninitialized,
6694 we have nothing to do. */
6695 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
6696 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
6697 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6698 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
6699 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6700 == VAR_INIT_STATUS_UNINITIALIZED)
6701 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
6702 == VAR_INIT_STATUS_UNINITIALIZED))))
6704 /* Add LOC to the end of list and update LAST. */
6705 temp->last->next = loc;
6709 /* Do not add empty location to the beginning of the list. */
6710 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
6717 /* Keep track of the number of spaces used to indent the
6718 output of the debugging routines that print the structure of
6719 the DIE internal representation. */
6720 static int print_indent;
6722 /* Indent the line the number of spaces given by print_indent. */
6725 print_spaces (FILE *outfile)
6727 fprintf (outfile, "%*s", print_indent, "");
6730 /* Print the information associated with a given DIE, and its children.
6731 This routine is a debugging aid only. */
6734 print_die (dw_die_ref die, FILE *outfile)
6740 print_spaces (outfile);
6741 fprintf (outfile, "DIE %4ld: %s\n",
6742 die->die_offset, dwarf_tag_name (die->die_tag));
6743 print_spaces (outfile);
6744 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6745 fprintf (outfile, " offset: %ld\n", die->die_offset);
6747 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6749 print_spaces (outfile);
6750 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6752 switch (AT_class (a))
6754 case dw_val_class_addr:
6755 fprintf (outfile, "address");
6757 case dw_val_class_offset:
6758 fprintf (outfile, "offset");
6760 case dw_val_class_loc:
6761 fprintf (outfile, "location descriptor");
6763 case dw_val_class_loc_list:
6764 fprintf (outfile, "location list -> label:%s",
6765 AT_loc_list (a)->ll_symbol);
6767 case dw_val_class_range_list:
6768 fprintf (outfile, "range list");
6770 case dw_val_class_const:
6771 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6773 case dw_val_class_unsigned_const:
6774 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6776 case dw_val_class_long_long:
6777 fprintf (outfile, "constant (%lu,%lu)",
6778 a->dw_attr_val.v.val_long_long.hi,
6779 a->dw_attr_val.v.val_long_long.low);
6781 case dw_val_class_vec:
6782 fprintf (outfile, "floating-point or vector constant");
6784 case dw_val_class_flag:
6785 fprintf (outfile, "%u", AT_flag (a));
6787 case dw_val_class_die_ref:
6788 if (AT_ref (a) != NULL)
6790 if (AT_ref (a)->die_symbol)
6791 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
6793 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6796 fprintf (outfile, "die -> <null>");
6798 case dw_val_class_lbl_id:
6799 case dw_val_class_lineptr:
6800 case dw_val_class_macptr:
6801 fprintf (outfile, "label: %s", AT_lbl (a));
6803 case dw_val_class_str:
6804 if (AT_string (a) != NULL)
6805 fprintf (outfile, "\"%s\"", AT_string (a));
6807 fprintf (outfile, "<null>");
6809 case dw_val_class_file:
6810 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6811 AT_file (a)->emitted_number);
6817 fprintf (outfile, "\n");
6820 if (die->die_child != NULL)
6823 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6826 if (print_indent == 0)
6827 fprintf (outfile, "\n");
6830 /* Print the contents of the source code line number correspondence table.
6831 This routine is a debugging aid only. */
6834 print_dwarf_line_table (FILE *outfile)
6837 dw_line_info_ref line_info;
6839 fprintf (outfile, "\n\nDWARF source line information\n");
6840 for (i = 1; i < line_info_table_in_use; i++)
6842 line_info = &line_info_table[i];
6843 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6844 line_info->dw_file_num,
6845 line_info->dw_line_num);
6848 fprintf (outfile, "\n\n");
6851 /* Print the information collected for a given DIE. */
6854 debug_dwarf_die (dw_die_ref die)
6856 print_die (die, stderr);
6859 /* Print all DWARF information collected for the compilation unit.
6860 This routine is a debugging aid only. */
6866 print_die (comp_unit_die, stderr);
6867 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6868 print_dwarf_line_table (stderr);
6871 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6872 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6873 DIE that marks the start of the DIEs for this include file. */
6876 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6878 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6879 dw_die_ref new_unit = gen_compile_unit_die (filename);
6881 new_unit->die_sib = old_unit;
6885 /* Close an include-file CU and reopen the enclosing one. */
6888 pop_compile_unit (dw_die_ref old_unit)
6890 dw_die_ref new_unit = old_unit->die_sib;
6892 old_unit->die_sib = NULL;
6896 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6897 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6899 /* Calculate the checksum of a location expression. */
6902 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6904 CHECKSUM (loc->dw_loc_opc);
6905 CHECKSUM (loc->dw_loc_oprnd1);
6906 CHECKSUM (loc->dw_loc_oprnd2);
6909 /* Calculate the checksum of an attribute. */
6912 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6914 dw_loc_descr_ref loc;
6917 CHECKSUM (at->dw_attr);
6919 /* We don't care that this was compiled with a different compiler
6920 snapshot; if the output is the same, that's what matters. */
6921 if (at->dw_attr == DW_AT_producer)
6924 switch (AT_class (at))
6926 case dw_val_class_const:
6927 CHECKSUM (at->dw_attr_val.v.val_int);
6929 case dw_val_class_unsigned_const:
6930 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6932 case dw_val_class_long_long:
6933 CHECKSUM (at->dw_attr_val.v.val_long_long);
6935 case dw_val_class_vec:
6936 CHECKSUM (at->dw_attr_val.v.val_vec);
6938 case dw_val_class_flag:
6939 CHECKSUM (at->dw_attr_val.v.val_flag);
6941 case dw_val_class_str:
6942 CHECKSUM_STRING (AT_string (at));
6945 case dw_val_class_addr:
6947 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6948 CHECKSUM_STRING (XSTR (r, 0));
6951 case dw_val_class_offset:
6952 CHECKSUM (at->dw_attr_val.v.val_offset);
6955 case dw_val_class_loc:
6956 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6957 loc_checksum (loc, ctx);
6960 case dw_val_class_die_ref:
6961 die_checksum (AT_ref (at), ctx, mark);
6964 case dw_val_class_fde_ref:
6965 case dw_val_class_lbl_id:
6966 case dw_val_class_lineptr:
6967 case dw_val_class_macptr:
6970 case dw_val_class_file:
6971 CHECKSUM_STRING (AT_file (at)->filename);
6979 /* Calculate the checksum of a DIE. */
6982 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6988 /* To avoid infinite recursion. */
6991 CHECKSUM (die->die_mark);
6994 die->die_mark = ++(*mark);
6996 CHECKSUM (die->die_tag);
6998 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6999 attr_checksum (a, ctx, mark);
7001 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7005 #undef CHECKSUM_STRING
7007 /* Do the location expressions look same? */
7009 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7011 return loc1->dw_loc_opc == loc2->dw_loc_opc
7012 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7013 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7016 /* Do the values look the same? */
7018 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7020 dw_loc_descr_ref loc1, loc2;
7023 if (v1->val_class != v2->val_class)
7026 switch (v1->val_class)
7028 case dw_val_class_const:
7029 return v1->v.val_int == v2->v.val_int;
7030 case dw_val_class_unsigned_const:
7031 return v1->v.val_unsigned == v2->v.val_unsigned;
7032 case dw_val_class_long_long:
7033 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
7034 && v1->v.val_long_long.low == v2->v.val_long_long.low;
7035 case dw_val_class_vec:
7036 if (v1->v.val_vec.length != v2->v.val_vec.length
7037 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7039 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7040 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7043 case dw_val_class_flag:
7044 return v1->v.val_flag == v2->v.val_flag;
7045 case dw_val_class_str:
7046 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7048 case dw_val_class_addr:
7049 r1 = v1->v.val_addr;
7050 r2 = v2->v.val_addr;
7051 if (GET_CODE (r1) != GET_CODE (r2))
7053 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7054 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7056 case dw_val_class_offset:
7057 return v1->v.val_offset == v2->v.val_offset;
7059 case dw_val_class_loc:
7060 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7062 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7063 if (!same_loc_p (loc1, loc2, mark))
7065 return !loc1 && !loc2;
7067 case dw_val_class_die_ref:
7068 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7070 case dw_val_class_fde_ref:
7071 case dw_val_class_lbl_id:
7072 case dw_val_class_lineptr:
7073 case dw_val_class_macptr:
7076 case dw_val_class_file:
7077 return v1->v.val_file == v2->v.val_file;
7084 /* Do the attributes look the same? */
7087 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7089 if (at1->dw_attr != at2->dw_attr)
7092 /* We don't care that this was compiled with a different compiler
7093 snapshot; if the output is the same, that's what matters. */
7094 if (at1->dw_attr == DW_AT_producer)
7097 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7100 /* Do the dies look the same? */
7103 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7109 /* To avoid infinite recursion. */
7111 return die1->die_mark == die2->die_mark;
7112 die1->die_mark = die2->die_mark = ++(*mark);
7114 if (die1->die_tag != die2->die_tag)
7117 if (VEC_length (dw_attr_node, die1->die_attr)
7118 != VEC_length (dw_attr_node, die2->die_attr))
7121 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7122 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7125 c1 = die1->die_child;
7126 c2 = die2->die_child;
7135 if (!same_die_p (c1, c2, mark))
7139 if (c1 == die1->die_child)
7141 if (c2 == die2->die_child)
7151 /* Do the dies look the same? Wrapper around same_die_p. */
7154 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7157 int ret = same_die_p (die1, die2, &mark);
7159 unmark_all_dies (die1);
7160 unmark_all_dies (die2);
7165 /* The prefix to attach to symbols on DIEs in the current comdat debug
7167 static char *comdat_symbol_id;
7169 /* The index of the current symbol within the current comdat CU. */
7170 static unsigned int comdat_symbol_number;
7172 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7173 children, and set comdat_symbol_id accordingly. */
7176 compute_section_prefix (dw_die_ref unit_die)
7178 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7179 const char *base = die_name ? lbasename (die_name) : "anonymous";
7180 char *name = XALLOCAVEC (char, strlen (base) + 64);
7183 unsigned char checksum[16];
7186 /* Compute the checksum of the DIE, then append part of it as hex digits to
7187 the name filename of the unit. */
7189 md5_init_ctx (&ctx);
7191 die_checksum (unit_die, &ctx, &mark);
7192 unmark_all_dies (unit_die);
7193 md5_finish_ctx (&ctx, checksum);
7195 sprintf (name, "%s.", base);
7196 clean_symbol_name (name);
7198 p = name + strlen (name);
7199 for (i = 0; i < 4; i++)
7201 sprintf (p, "%.2x", checksum[i]);
7205 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7206 comdat_symbol_number = 0;
7209 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7212 is_type_die (dw_die_ref die)
7214 switch (die->die_tag)
7216 case DW_TAG_array_type:
7217 case DW_TAG_class_type:
7218 case DW_TAG_interface_type:
7219 case DW_TAG_enumeration_type:
7220 case DW_TAG_pointer_type:
7221 case DW_TAG_reference_type:
7222 case DW_TAG_string_type:
7223 case DW_TAG_structure_type:
7224 case DW_TAG_subroutine_type:
7225 case DW_TAG_union_type:
7226 case DW_TAG_ptr_to_member_type:
7227 case DW_TAG_set_type:
7228 case DW_TAG_subrange_type:
7229 case DW_TAG_base_type:
7230 case DW_TAG_const_type:
7231 case DW_TAG_file_type:
7232 case DW_TAG_packed_type:
7233 case DW_TAG_volatile_type:
7234 case DW_TAG_typedef:
7241 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7242 Basically, we want to choose the bits that are likely to be shared between
7243 compilations (types) and leave out the bits that are specific to individual
7244 compilations (functions). */
7247 is_comdat_die (dw_die_ref c)
7249 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7250 we do for stabs. The advantage is a greater likelihood of sharing between
7251 objects that don't include headers in the same order (and therefore would
7252 put the base types in a different comdat). jason 8/28/00 */
7254 if (c->die_tag == DW_TAG_base_type)
7257 if (c->die_tag == DW_TAG_pointer_type
7258 || c->die_tag == DW_TAG_reference_type
7259 || c->die_tag == DW_TAG_const_type
7260 || c->die_tag == DW_TAG_volatile_type)
7262 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7264 return t ? is_comdat_die (t) : 0;
7267 return is_type_die (c);
7270 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7271 compilation unit. */
7274 is_symbol_die (dw_die_ref c)
7276 return (is_type_die (c)
7277 || (get_AT (c, DW_AT_declaration)
7278 && !get_AT (c, DW_AT_specification))
7279 || c->die_tag == DW_TAG_namespace
7280 || c->die_tag == DW_TAG_module);
7284 gen_internal_sym (const char *prefix)
7288 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7289 return xstrdup (buf);
7292 /* Assign symbols to all worthy DIEs under DIE. */
7295 assign_symbol_names (dw_die_ref die)
7299 if (is_symbol_die (die))
7301 if (comdat_symbol_id)
7303 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7305 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7306 comdat_symbol_id, comdat_symbol_number++);
7307 die->die_symbol = xstrdup (p);
7310 die->die_symbol = gen_internal_sym ("LDIE");
7313 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7316 struct cu_hash_table_entry
7319 unsigned min_comdat_num, max_comdat_num;
7320 struct cu_hash_table_entry *next;
7323 /* Routines to manipulate hash table of CUs. */
7325 htab_cu_hash (const void *of)
7327 const struct cu_hash_table_entry *const entry =
7328 (const struct cu_hash_table_entry *) of;
7330 return htab_hash_string (entry->cu->die_symbol);
7334 htab_cu_eq (const void *of1, const void *of2)
7336 const struct cu_hash_table_entry *const entry1 =
7337 (const struct cu_hash_table_entry *) of1;
7338 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7340 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7344 htab_cu_del (void *what)
7346 struct cu_hash_table_entry *next,
7347 *entry = (struct cu_hash_table_entry *) what;
7357 /* Check whether we have already seen this CU and set up SYM_NUM
7360 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7362 struct cu_hash_table_entry dummy;
7363 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7365 dummy.max_comdat_num = 0;
7367 slot = (struct cu_hash_table_entry **)
7368 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7372 for (; entry; last = entry, entry = entry->next)
7374 if (same_die_p_wrap (cu, entry->cu))
7380 *sym_num = entry->min_comdat_num;
7384 entry = XCNEW (struct cu_hash_table_entry);
7386 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7387 entry->next = *slot;
7393 /* Record SYM_NUM to record of CU in HTABLE. */
7395 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7397 struct cu_hash_table_entry **slot, *entry;
7399 slot = (struct cu_hash_table_entry **)
7400 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7404 entry->max_comdat_num = sym_num;
7407 /* Traverse the DIE (which is always comp_unit_die), and set up
7408 additional compilation units for each of the include files we see
7409 bracketed by BINCL/EINCL. */
7412 break_out_includes (dw_die_ref die)
7415 dw_die_ref unit = NULL;
7416 limbo_die_node *node, **pnode;
7417 htab_t cu_hash_table;
7421 dw_die_ref prev = c;
7423 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7424 || (unit && is_comdat_die (c)))
7426 dw_die_ref next = c->die_sib;
7428 /* This DIE is for a secondary CU; remove it from the main one. */
7429 remove_child_with_prev (c, prev);
7431 if (c->die_tag == DW_TAG_GNU_BINCL)
7432 unit = push_new_compile_unit (unit, c);
7433 else if (c->die_tag == DW_TAG_GNU_EINCL)
7434 unit = pop_compile_unit (unit);
7436 add_child_die (unit, c);
7438 if (c == die->die_child)
7441 } while (c != die->die_child);
7444 /* We can only use this in debugging, since the frontend doesn't check
7445 to make sure that we leave every include file we enter. */
7449 assign_symbol_names (die);
7450 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7451 for (node = limbo_die_list, pnode = &limbo_die_list;
7457 compute_section_prefix (node->die);
7458 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7459 &comdat_symbol_number);
7460 assign_symbol_names (node->die);
7462 *pnode = node->next;
7465 pnode = &node->next;
7466 record_comdat_symbol_number (node->die, cu_hash_table,
7467 comdat_symbol_number);
7470 htab_delete (cu_hash_table);
7473 /* Traverse the DIE and add a sibling attribute if it may have the
7474 effect of speeding up access to siblings. To save some space,
7475 avoid generating sibling attributes for DIE's without children. */
7478 add_sibling_attributes (dw_die_ref die)
7482 if (! die->die_child)
7485 if (die->die_parent && die != die->die_parent->die_child)
7486 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7488 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7491 /* Output all location lists for the DIE and its children. */
7494 output_location_lists (dw_die_ref die)
7500 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7501 if (AT_class (a) == dw_val_class_loc_list)
7502 output_loc_list (AT_loc_list (a));
7504 FOR_EACH_CHILD (die, c, output_location_lists (c));
7507 /* The format of each DIE (and its attribute value pairs) is encoded in an
7508 abbreviation table. This routine builds the abbreviation table and assigns
7509 a unique abbreviation id for each abbreviation entry. The children of each
7510 die are visited recursively. */
7513 build_abbrev_table (dw_die_ref die)
7515 unsigned long abbrev_id;
7516 unsigned int n_alloc;
7521 /* Scan the DIE references, and mark as external any that refer to
7522 DIEs from other CUs (i.e. those which are not marked). */
7523 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7524 if (AT_class (a) == dw_val_class_die_ref
7525 && AT_ref (a)->die_mark == 0)
7527 gcc_assert (AT_ref (a)->die_symbol);
7529 set_AT_ref_external (a, 1);
7532 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7534 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7535 dw_attr_ref die_a, abbrev_a;
7539 if (abbrev->die_tag != die->die_tag)
7541 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7544 if (VEC_length (dw_attr_node, abbrev->die_attr)
7545 != VEC_length (dw_attr_node, die->die_attr))
7548 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7550 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7551 if ((abbrev_a->dw_attr != die_a->dw_attr)
7552 || (value_format (abbrev_a) != value_format (die_a)))
7562 if (abbrev_id >= abbrev_die_table_in_use)
7564 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7566 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7567 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7570 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7571 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7572 abbrev_die_table_allocated = n_alloc;
7575 ++abbrev_die_table_in_use;
7576 abbrev_die_table[abbrev_id] = die;
7579 die->die_abbrev = abbrev_id;
7580 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7583 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7586 constant_size (unsigned HOST_WIDE_INT value)
7593 log = floor_log2 (value);
7596 log = 1 << (floor_log2 (log) + 1);
7601 /* Return the size of a DIE as it is represented in the
7602 .debug_info section. */
7604 static unsigned long
7605 size_of_die (dw_die_ref die)
7607 unsigned long size = 0;
7611 size += size_of_uleb128 (die->die_abbrev);
7612 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7614 switch (AT_class (a))
7616 case dw_val_class_addr:
7617 size += DWARF2_ADDR_SIZE;
7619 case dw_val_class_offset:
7620 size += DWARF_OFFSET_SIZE;
7622 case dw_val_class_loc:
7624 unsigned long lsize = size_of_locs (AT_loc (a));
7627 size += constant_size (lsize);
7631 case dw_val_class_loc_list:
7632 size += DWARF_OFFSET_SIZE;
7634 case dw_val_class_range_list:
7635 size += DWARF_OFFSET_SIZE;
7637 case dw_val_class_const:
7638 size += size_of_sleb128 (AT_int (a));
7640 case dw_val_class_unsigned_const:
7641 size += constant_size (AT_unsigned (a));
7643 case dw_val_class_long_long:
7644 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7646 case dw_val_class_vec:
7647 size += constant_size (a->dw_attr_val.v.val_vec.length
7648 * a->dw_attr_val.v.val_vec.elt_size)
7649 + a->dw_attr_val.v.val_vec.length
7650 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7652 case dw_val_class_flag:
7655 case dw_val_class_die_ref:
7656 if (AT_ref_external (a))
7657 size += DWARF2_ADDR_SIZE;
7659 size += DWARF_OFFSET_SIZE;
7661 case dw_val_class_fde_ref:
7662 size += DWARF_OFFSET_SIZE;
7664 case dw_val_class_lbl_id:
7665 size += DWARF2_ADDR_SIZE;
7667 case dw_val_class_lineptr:
7668 case dw_val_class_macptr:
7669 size += DWARF_OFFSET_SIZE;
7671 case dw_val_class_str:
7672 if (AT_string_form (a) == DW_FORM_strp)
7673 size += DWARF_OFFSET_SIZE;
7675 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7677 case dw_val_class_file:
7678 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7688 /* Size the debugging information associated with a given DIE. Visits the
7689 DIE's children recursively. Updates the global variable next_die_offset, on
7690 each time through. Uses the current value of next_die_offset to update the
7691 die_offset field in each DIE. */
7694 calc_die_sizes (dw_die_ref die)
7698 die->die_offset = next_die_offset;
7699 next_die_offset += size_of_die (die);
7701 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7703 if (die->die_child != NULL)
7704 /* Count the null byte used to terminate sibling lists. */
7705 next_die_offset += 1;
7708 /* Set the marks for a die and its children. We do this so
7709 that we know whether or not a reference needs to use FORM_ref_addr; only
7710 DIEs in the same CU will be marked. We used to clear out the offset
7711 and use that as the flag, but ran into ordering problems. */
7714 mark_dies (dw_die_ref die)
7718 gcc_assert (!die->die_mark);
7721 FOR_EACH_CHILD (die, c, mark_dies (c));
7724 /* Clear the marks for a die and its children. */
7727 unmark_dies (dw_die_ref die)
7731 gcc_assert (die->die_mark);
7734 FOR_EACH_CHILD (die, c, unmark_dies (c));
7737 /* Clear the marks for a die, its children and referred dies. */
7740 unmark_all_dies (dw_die_ref die)
7750 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7752 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7753 if (AT_class (a) == dw_val_class_die_ref)
7754 unmark_all_dies (AT_ref (a));
7757 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7758 generated for the compilation unit. */
7760 static unsigned long
7761 size_of_pubnames (VEC (pubname_entry, gc) * names)
7767 size = DWARF_PUBNAMES_HEADER_SIZE;
7768 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
7769 if (names != pubtype_table
7770 || p->die->die_offset != 0
7771 || !flag_eliminate_unused_debug_types)
7772 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7774 size += DWARF_OFFSET_SIZE;
7778 /* Return the size of the information in the .debug_aranges section. */
7780 static unsigned long
7781 size_of_aranges (void)
7785 size = DWARF_ARANGES_HEADER_SIZE;
7787 /* Count the address/length pair for this compilation unit. */
7788 if (text_section_used)
7789 size += 2 * DWARF2_ADDR_SIZE;
7790 if (cold_text_section_used)
7791 size += 2 * DWARF2_ADDR_SIZE;
7792 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
7794 /* Count the two zero words used to terminated the address range table. */
7795 size += 2 * DWARF2_ADDR_SIZE;
7799 /* Select the encoding of an attribute value. */
7801 static enum dwarf_form
7802 value_format (dw_attr_ref a)
7804 switch (a->dw_attr_val.val_class)
7806 case dw_val_class_addr:
7807 return DW_FORM_addr;
7808 case dw_val_class_range_list:
7809 case dw_val_class_offset:
7810 case dw_val_class_loc_list:
7811 switch (DWARF_OFFSET_SIZE)
7814 return DW_FORM_data4;
7816 return DW_FORM_data8;
7820 case dw_val_class_loc:
7821 switch (constant_size (size_of_locs (AT_loc (a))))
7824 return DW_FORM_block1;
7826 return DW_FORM_block2;
7830 case dw_val_class_const:
7831 return DW_FORM_sdata;
7832 case dw_val_class_unsigned_const:
7833 switch (constant_size (AT_unsigned (a)))
7836 return DW_FORM_data1;
7838 return DW_FORM_data2;
7840 return DW_FORM_data4;
7842 return DW_FORM_data8;
7846 case dw_val_class_long_long:
7847 return DW_FORM_block1;
7848 case dw_val_class_vec:
7849 switch (constant_size (a->dw_attr_val.v.val_vec.length
7850 * a->dw_attr_val.v.val_vec.elt_size))
7853 return DW_FORM_block1;
7855 return DW_FORM_block2;
7857 return DW_FORM_block4;
7861 case dw_val_class_flag:
7862 return DW_FORM_flag;
7863 case dw_val_class_die_ref:
7864 if (AT_ref_external (a))
7865 return DW_FORM_ref_addr;
7868 case dw_val_class_fde_ref:
7869 return DW_FORM_data;
7870 case dw_val_class_lbl_id:
7871 return DW_FORM_addr;
7872 case dw_val_class_lineptr:
7873 case dw_val_class_macptr:
7874 return DW_FORM_data;
7875 case dw_val_class_str:
7876 return AT_string_form (a);
7877 case dw_val_class_file:
7878 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7881 return DW_FORM_data1;
7883 return DW_FORM_data2;
7885 return DW_FORM_data4;
7895 /* Output the encoding of an attribute value. */
7898 output_value_format (dw_attr_ref a)
7900 enum dwarf_form form = value_format (a);
7902 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7905 /* Output the .debug_abbrev section which defines the DIE abbreviation
7909 output_abbrev_section (void)
7911 unsigned long abbrev_id;
7913 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7915 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7919 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7920 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7921 dwarf_tag_name (abbrev->die_tag));
7923 if (abbrev->die_child != NULL)
7924 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7926 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7928 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7931 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7932 dwarf_attr_name (a_attr->dw_attr));
7933 output_value_format (a_attr);
7936 dw2_asm_output_data (1, 0, NULL);
7937 dw2_asm_output_data (1, 0, NULL);
7940 /* Terminate the table. */
7941 dw2_asm_output_data (1, 0, NULL);
7944 /* Output a symbol we can use to refer to this DIE from another CU. */
7947 output_die_symbol (dw_die_ref die)
7949 char *sym = die->die_symbol;
7954 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7955 /* We make these global, not weak; if the target doesn't support
7956 .linkonce, it doesn't support combining the sections, so debugging
7958 targetm.asm_out.globalize_label (asm_out_file, sym);
7960 ASM_OUTPUT_LABEL (asm_out_file, sym);
7963 /* Return a new location list, given the begin and end range, and the
7964 expression. gensym tells us whether to generate a new internal symbol for
7965 this location list node, which is done for the head of the list only. */
7967 static inline dw_loc_list_ref
7968 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7969 const char *section, unsigned int gensym)
7971 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7973 retlist->begin = begin;
7975 retlist->expr = expr;
7976 retlist->section = section;
7978 retlist->ll_symbol = gen_internal_sym ("LLST");
7983 /* Add a location description expression to a location list. */
7986 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7987 const char *begin, const char *end,
7988 const char *section)
7992 /* Find the end of the chain. */
7993 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7996 /* Add a new location list node to the list. */
7997 *d = new_loc_list (descr, begin, end, section, 0);
8000 /* Output the location list given to us. */
8003 output_loc_list (dw_loc_list_ref list_head)
8005 dw_loc_list_ref curr = list_head;
8007 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8009 /* Walk the location list, and output each range + expression. */
8010 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8013 /* Don't output an entry that starts and ends at the same address. */
8014 if (strcmp (curr->begin, curr->end) == 0)
8016 if (!have_multiple_function_sections)
8018 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8019 "Location list begin address (%s)",
8020 list_head->ll_symbol);
8021 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8022 "Location list end address (%s)",
8023 list_head->ll_symbol);
8027 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8028 "Location list begin address (%s)",
8029 list_head->ll_symbol);
8030 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8031 "Location list end address (%s)",
8032 list_head->ll_symbol);
8034 size = size_of_locs (curr->expr);
8036 /* Output the block length for this list of location operations. */
8037 gcc_assert (size <= 0xffff);
8038 dw2_asm_output_data (2, size, "%s", "Location expression size");
8040 output_loc_sequence (curr->expr);
8043 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8044 "Location list terminator begin (%s)",
8045 list_head->ll_symbol);
8046 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8047 "Location list terminator end (%s)",
8048 list_head->ll_symbol);
8051 /* Output the DIE and its attributes. Called recursively to generate
8052 the definitions of each child DIE. */
8055 output_die (dw_die_ref die)
8062 /* If someone in another CU might refer to us, set up a symbol for
8063 them to point to. */
8064 if (die->die_symbol)
8065 output_die_symbol (die);
8067 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8068 (unsigned long)die->die_offset,
8069 dwarf_tag_name (die->die_tag));
8071 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8073 const char *name = dwarf_attr_name (a->dw_attr);
8075 switch (AT_class (a))
8077 case dw_val_class_addr:
8078 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8081 case dw_val_class_offset:
8082 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8086 case dw_val_class_range_list:
8088 char *p = strchr (ranges_section_label, '\0');
8090 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8091 a->dw_attr_val.v.val_offset);
8092 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8093 debug_ranges_section, "%s", name);
8098 case dw_val_class_loc:
8099 size = size_of_locs (AT_loc (a));
8101 /* Output the block length for this list of location operations. */
8102 dw2_asm_output_data (constant_size (size), size, "%s", name);
8104 output_loc_sequence (AT_loc (a));
8107 case dw_val_class_const:
8108 /* ??? It would be slightly more efficient to use a scheme like is
8109 used for unsigned constants below, but gdb 4.x does not sign
8110 extend. Gdb 5.x does sign extend. */
8111 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8114 case dw_val_class_unsigned_const:
8115 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8116 AT_unsigned (a), "%s", name);
8119 case dw_val_class_long_long:
8121 unsigned HOST_WIDE_INT first, second;
8123 dw2_asm_output_data (1,
8124 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8127 if (WORDS_BIG_ENDIAN)
8129 first = a->dw_attr_val.v.val_long_long.hi;
8130 second = a->dw_attr_val.v.val_long_long.low;
8134 first = a->dw_attr_val.v.val_long_long.low;
8135 second = a->dw_attr_val.v.val_long_long.hi;
8138 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8139 first, "long long constant");
8140 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8145 case dw_val_class_vec:
8147 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8148 unsigned int len = a->dw_attr_val.v.val_vec.length;
8152 dw2_asm_output_data (constant_size (len * elt_size),
8153 len * elt_size, "%s", name);
8154 if (elt_size > sizeof (HOST_WIDE_INT))
8159 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8162 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8163 "fp or vector constant word %u", i);
8167 case dw_val_class_flag:
8168 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8171 case dw_val_class_loc_list:
8173 char *sym = AT_loc_list (a)->ll_symbol;
8176 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8181 case dw_val_class_die_ref:
8182 if (AT_ref_external (a))
8184 char *sym = AT_ref (a)->die_symbol;
8187 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
8192 gcc_assert (AT_ref (a)->die_offset);
8193 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8198 case dw_val_class_fde_ref:
8202 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8203 a->dw_attr_val.v.val_fde_index * 2);
8204 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8209 case dw_val_class_lbl_id:
8210 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8213 case dw_val_class_lineptr:
8214 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8215 debug_line_section, "%s", name);
8218 case dw_val_class_macptr:
8219 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8220 debug_macinfo_section, "%s", name);
8223 case dw_val_class_str:
8224 if (AT_string_form (a) == DW_FORM_strp)
8225 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8226 a->dw_attr_val.v.val_str->label,
8228 "%s: \"%s\"", name, AT_string (a));
8230 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8233 case dw_val_class_file:
8235 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8237 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8238 a->dw_attr_val.v.val_file->filename);
8247 FOR_EACH_CHILD (die, c, output_die (c));
8249 /* Add null byte to terminate sibling list. */
8250 if (die->die_child != NULL)
8251 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8252 (unsigned long) die->die_offset);
8255 /* Output the compilation unit that appears at the beginning of the
8256 .debug_info section, and precedes the DIE descriptions. */
8259 output_compilation_unit_header (void)
8261 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8262 dw2_asm_output_data (4, 0xffffffff,
8263 "Initial length escape value indicating 64-bit DWARF extension");
8264 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8265 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8266 "Length of Compilation Unit Info");
8267 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
8268 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8269 debug_abbrev_section,
8270 "Offset Into Abbrev. Section");
8271 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8274 /* Output the compilation unit DIE and its children. */
8277 output_comp_unit (dw_die_ref die, int output_if_empty)
8279 const char *secname;
8282 /* Unless we are outputting main CU, we may throw away empty ones. */
8283 if (!output_if_empty && die->die_child == NULL)
8286 /* Even if there are no children of this DIE, we must output the information
8287 about the compilation unit. Otherwise, on an empty translation unit, we
8288 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8289 will then complain when examining the file. First mark all the DIEs in
8290 this CU so we know which get local refs. */
8293 build_abbrev_table (die);
8295 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8296 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8297 calc_die_sizes (die);
8299 oldsym = die->die_symbol;
8302 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8304 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8306 die->die_symbol = NULL;
8307 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8310 switch_to_section (debug_info_section);
8312 /* Output debugging information. */
8313 output_compilation_unit_header ();
8316 /* Leave the marks on the main CU, so we can check them in
8321 die->die_symbol = oldsym;
8325 /* Return the DWARF2/3 pubname associated with a decl. */
8328 dwarf2_name (tree decl, int scope)
8330 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8333 /* Add a new entry to .debug_pubnames if appropriate. */
8336 add_pubname_string (const char *str, dw_die_ref die)
8341 e.name = xstrdup (str);
8342 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8346 add_pubname (tree decl, dw_die_ref die)
8349 if (TREE_PUBLIC (decl))
8350 add_pubname_string (dwarf2_name (decl, 1), die);
8353 /* Add a new entry to .debug_pubtypes if appropriate. */
8356 add_pubtype (tree decl, dw_die_ref die)
8361 if ((TREE_PUBLIC (decl)
8362 || die->die_parent == comp_unit_die)
8363 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8368 if (TYPE_NAME (decl))
8370 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8371 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8372 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8373 && DECL_NAME (TYPE_NAME (decl)))
8374 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8376 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8380 e.name = xstrdup (dwarf2_name (decl, 1));
8382 /* If we don't have a name for the type, there's no point in adding
8384 if (e.name && e.name[0] != '\0')
8385 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8389 /* Output the public names table used to speed up access to externally
8390 visible names; or the public types table used to find type definitions. */
8393 output_pubnames (VEC (pubname_entry, gc) * names)
8396 unsigned long pubnames_length = size_of_pubnames (names);
8399 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8400 dw2_asm_output_data (4, 0xffffffff,
8401 "Initial length escape value indicating 64-bit DWARF extension");
8402 if (names == pubname_table)
8403 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8404 "Length of Public Names Info");
8406 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8407 "Length of Public Type Names Info");
8408 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8409 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8411 "Offset of Compilation Unit Info");
8412 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8413 "Compilation Unit Length");
8415 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8417 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8418 if (names == pubname_table)
8419 gcc_assert (pub->die->die_mark);
8421 if (names != pubtype_table
8422 || pub->die->die_offset != 0
8423 || !flag_eliminate_unused_debug_types)
8425 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8428 dw2_asm_output_nstring (pub->name, -1, "external name");
8432 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8435 /* Add a new entry to .debug_aranges if appropriate. */
8438 add_arange (tree decl, dw_die_ref die)
8440 if (! DECL_SECTION_NAME (decl))
8443 if (arange_table_in_use == arange_table_allocated)
8445 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8446 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8447 arange_table_allocated);
8448 memset (arange_table + arange_table_in_use, 0,
8449 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8452 arange_table[arange_table_in_use++] = die;
8455 /* Output the information that goes into the .debug_aranges table.
8456 Namely, define the beginning and ending address range of the
8457 text section generated for this compilation unit. */
8460 output_aranges (void)
8463 unsigned long aranges_length = size_of_aranges ();
8465 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8466 dw2_asm_output_data (4, 0xffffffff,
8467 "Initial length escape value indicating 64-bit DWARF extension");
8468 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8469 "Length of Address Ranges Info");
8470 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8471 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8473 "Offset of Compilation Unit Info");
8474 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8475 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8477 /* We need to align to twice the pointer size here. */
8478 if (DWARF_ARANGES_PAD_SIZE)
8480 /* Pad using a 2 byte words so that padding is correct for any
8482 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8483 2 * DWARF2_ADDR_SIZE);
8484 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8485 dw2_asm_output_data (2, 0, NULL);
8488 /* It is necessary not to output these entries if the sections were
8489 not used; if the sections were not used, the length will be 0 and
8490 the address may end up as 0 if the section is discarded by ld
8491 --gc-sections, leaving an invalid (0, 0) entry that can be
8492 confused with the terminator. */
8493 if (text_section_used)
8495 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8496 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8497 text_section_label, "Length");
8499 if (cold_text_section_used)
8501 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8503 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8504 cold_text_section_label, "Length");
8507 for (i = 0; i < arange_table_in_use; i++)
8509 dw_die_ref die = arange_table[i];
8511 /* We shouldn't see aranges for DIEs outside of the main CU. */
8512 gcc_assert (die->die_mark);
8514 if (die->die_tag == DW_TAG_subprogram)
8516 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8518 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8519 get_AT_low_pc (die), "Length");
8523 /* A static variable; extract the symbol from DW_AT_location.
8524 Note that this code isn't currently hit, as we only emit
8525 aranges for functions (jason 9/23/99). */
8526 dw_attr_ref a = get_AT (die, DW_AT_location);
8527 dw_loc_descr_ref loc;
8529 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8532 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8534 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8535 loc->dw_loc_oprnd1.v.val_addr, "Address");
8536 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8537 get_AT_unsigned (die, DW_AT_byte_size),
8542 /* Output the terminator words. */
8543 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8544 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8547 /* Add a new entry to .debug_ranges. Return the offset at which it
8551 add_ranges_num (int num)
8553 unsigned int in_use = ranges_table_in_use;
8555 if (in_use == ranges_table_allocated)
8557 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8558 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8559 ranges_table_allocated);
8560 memset (ranges_table + ranges_table_in_use, 0,
8561 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8564 ranges_table[in_use].num = num;
8565 ranges_table_in_use = in_use + 1;
8567 return in_use * 2 * DWARF2_ADDR_SIZE;
8570 /* Add a new entry to .debug_ranges corresponding to a block, or a
8571 range terminator if BLOCK is NULL. */
8574 add_ranges (const_tree block)
8576 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8579 /* Add a new entry to .debug_ranges corresponding to a pair of
8583 add_ranges_by_labels (const char *begin, const char *end)
8585 unsigned int in_use = ranges_by_label_in_use;
8587 if (in_use == ranges_by_label_allocated)
8589 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8590 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8592 ranges_by_label_allocated);
8593 memset (ranges_by_label + ranges_by_label_in_use, 0,
8594 RANGES_TABLE_INCREMENT
8595 * sizeof (struct dw_ranges_by_label_struct));
8598 ranges_by_label[in_use].begin = begin;
8599 ranges_by_label[in_use].end = end;
8600 ranges_by_label_in_use = in_use + 1;
8602 return add_ranges_num (-(int)in_use - 1);
8606 output_ranges (void)
8609 static const char *const start_fmt = "Offset 0x%x";
8610 const char *fmt = start_fmt;
8612 for (i = 0; i < ranges_table_in_use; i++)
8614 int block_num = ranges_table[i].num;
8618 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8619 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8621 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8622 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8624 /* If all code is in the text section, then the compilation
8625 unit base address defaults to DW_AT_low_pc, which is the
8626 base of the text section. */
8627 if (!have_multiple_function_sections)
8629 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8631 fmt, i * 2 * DWARF2_ADDR_SIZE);
8632 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8633 text_section_label, NULL);
8636 /* Otherwise, the compilation unit base address is zero,
8637 which allows us to use absolute addresses, and not worry
8638 about whether the target supports cross-section
8642 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8643 fmt, i * 2 * DWARF2_ADDR_SIZE);
8644 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8650 /* Negative block_num stands for an index into ranges_by_label. */
8651 else if (block_num < 0)
8653 int lab_idx = - block_num - 1;
8655 if (!have_multiple_function_sections)
8659 /* If we ever use add_ranges_by_labels () for a single
8660 function section, all we have to do is to take out
8662 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8663 ranges_by_label[lab_idx].begin,
8665 fmt, i * 2 * DWARF2_ADDR_SIZE);
8666 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8667 ranges_by_label[lab_idx].end,
8668 text_section_label, NULL);
8673 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8674 ranges_by_label[lab_idx].begin,
8675 fmt, i * 2 * DWARF2_ADDR_SIZE);
8676 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8677 ranges_by_label[lab_idx].end,
8683 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8684 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8690 /* Data structure containing information about input files. */
8693 const char *path; /* Complete file name. */
8694 const char *fname; /* File name part. */
8695 int length; /* Length of entire string. */
8696 struct dwarf_file_data * file_idx; /* Index in input file table. */
8697 int dir_idx; /* Index in directory table. */
8700 /* Data structure containing information about directories with source
8704 const char *path; /* Path including directory name. */
8705 int length; /* Path length. */
8706 int prefix; /* Index of directory entry which is a prefix. */
8707 int count; /* Number of files in this directory. */
8708 int dir_idx; /* Index of directory used as base. */
8711 /* Callback function for file_info comparison. We sort by looking at
8712 the directories in the path. */
8715 file_info_cmp (const void *p1, const void *p2)
8717 const struct file_info *const s1 = (const struct file_info *) p1;
8718 const struct file_info *const s2 = (const struct file_info *) p2;
8719 const unsigned char *cp1;
8720 const unsigned char *cp2;
8722 /* Take care of file names without directories. We need to make sure that
8723 we return consistent values to qsort since some will get confused if
8724 we return the same value when identical operands are passed in opposite
8725 orders. So if neither has a directory, return 0 and otherwise return
8726 1 or -1 depending on which one has the directory. */
8727 if ((s1->path == s1->fname || s2->path == s2->fname))
8728 return (s2->path == s2->fname) - (s1->path == s1->fname);
8730 cp1 = (const unsigned char *) s1->path;
8731 cp2 = (const unsigned char *) s2->path;
8737 /* Reached the end of the first path? If so, handle like above. */
8738 if ((cp1 == (const unsigned char *) s1->fname)
8739 || (cp2 == (const unsigned char *) s2->fname))
8740 return ((cp2 == (const unsigned char *) s2->fname)
8741 - (cp1 == (const unsigned char *) s1->fname));
8743 /* Character of current path component the same? */
8744 else if (*cp1 != *cp2)
8749 struct file_name_acquire_data
8751 struct file_info *files;
8756 /* Traversal function for the hash table. */
8759 file_name_acquire (void ** slot, void *data)
8761 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8762 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8763 struct file_info *fi;
8766 gcc_assert (fnad->max_files >= d->emitted_number);
8768 if (! d->emitted_number)
8771 gcc_assert (fnad->max_files != fnad->used_files);
8773 fi = fnad->files + fnad->used_files++;
8775 /* Skip all leading "./". */
8777 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8780 /* Create a new array entry. */
8782 fi->length = strlen (f);
8785 /* Search for the file name part. */
8786 f = strrchr (f, DIR_SEPARATOR);
8787 #if defined (DIR_SEPARATOR_2)
8789 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8793 if (f == NULL || f < g)
8799 fi->fname = f == NULL ? fi->path : f + 1;
8803 /* Output the directory table and the file name table. We try to minimize
8804 the total amount of memory needed. A heuristic is used to avoid large
8805 slowdowns with many input files. */
8808 output_file_names (void)
8810 struct file_name_acquire_data fnad;
8812 struct file_info *files;
8813 struct dir_info *dirs;
8822 if (!last_emitted_file)
8824 dw2_asm_output_data (1, 0, "End directory table");
8825 dw2_asm_output_data (1, 0, "End file name table");
8829 numfiles = last_emitted_file->emitted_number;
8831 /* Allocate the various arrays we need. */
8832 files = XALLOCAVEC (struct file_info, numfiles);
8833 dirs = XALLOCAVEC (struct dir_info, numfiles);
8836 fnad.used_files = 0;
8837 fnad.max_files = numfiles;
8838 htab_traverse (file_table, file_name_acquire, &fnad);
8839 gcc_assert (fnad.used_files == fnad.max_files);
8841 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8843 /* Find all the different directories used. */
8844 dirs[0].path = files[0].path;
8845 dirs[0].length = files[0].fname - files[0].path;
8846 dirs[0].prefix = -1;
8848 dirs[0].dir_idx = 0;
8849 files[0].dir_idx = 0;
8852 for (i = 1; i < numfiles; i++)
8853 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8854 && memcmp (dirs[ndirs - 1].path, files[i].path,
8855 dirs[ndirs - 1].length) == 0)
8857 /* Same directory as last entry. */
8858 files[i].dir_idx = ndirs - 1;
8859 ++dirs[ndirs - 1].count;
8865 /* This is a new directory. */
8866 dirs[ndirs].path = files[i].path;
8867 dirs[ndirs].length = files[i].fname - files[i].path;
8868 dirs[ndirs].count = 1;
8869 dirs[ndirs].dir_idx = ndirs;
8870 files[i].dir_idx = ndirs;
8872 /* Search for a prefix. */
8873 dirs[ndirs].prefix = -1;
8874 for (j = 0; j < ndirs; j++)
8875 if (dirs[j].length < dirs[ndirs].length
8876 && dirs[j].length > 1
8877 && (dirs[ndirs].prefix == -1
8878 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8879 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8880 dirs[ndirs].prefix = j;
8885 /* Now to the actual work. We have to find a subset of the directories which
8886 allow expressing the file name using references to the directory table
8887 with the least amount of characters. We do not do an exhaustive search
8888 where we would have to check out every combination of every single
8889 possible prefix. Instead we use a heuristic which provides nearly optimal
8890 results in most cases and never is much off. */
8891 saved = XALLOCAVEC (int, ndirs);
8892 savehere = XALLOCAVEC (int, ndirs);
8894 memset (saved, '\0', ndirs * sizeof (saved[0]));
8895 for (i = 0; i < ndirs; i++)
8900 /* We can always save some space for the current directory. But this
8901 does not mean it will be enough to justify adding the directory. */
8902 savehere[i] = dirs[i].length;
8903 total = (savehere[i] - saved[i]) * dirs[i].count;
8905 for (j = i + 1; j < ndirs; j++)
8908 if (saved[j] < dirs[i].length)
8910 /* Determine whether the dirs[i] path is a prefix of the
8915 while (k != -1 && k != (int) i)
8920 /* Yes it is. We can possibly save some memory by
8921 writing the filenames in dirs[j] relative to
8923 savehere[j] = dirs[i].length;
8924 total += (savehere[j] - saved[j]) * dirs[j].count;
8929 /* Check whether we can save enough to justify adding the dirs[i]
8931 if (total > dirs[i].length + 1)
8933 /* It's worthwhile adding. */
8934 for (j = i; j < ndirs; j++)
8935 if (savehere[j] > 0)
8937 /* Remember how much we saved for this directory so far. */
8938 saved[j] = savehere[j];
8940 /* Remember the prefix directory. */
8941 dirs[j].dir_idx = i;
8946 /* Emit the directory name table. */
8948 idx_offset = dirs[0].length > 0 ? 1 : 0;
8949 for (i = 1 - idx_offset; i < ndirs; i++)
8950 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8951 "Directory Entry: 0x%x", i + idx_offset);
8953 dw2_asm_output_data (1, 0, "End directory table");
8955 /* We have to emit them in the order of emitted_number since that's
8956 used in the debug info generation. To do this efficiently we
8957 generate a back-mapping of the indices first. */
8958 backmap = XALLOCAVEC (int, numfiles);
8959 for (i = 0; i < numfiles; i++)
8960 backmap[files[i].file_idx->emitted_number - 1] = i;
8962 /* Now write all the file names. */
8963 for (i = 0; i < numfiles; i++)
8965 int file_idx = backmap[i];
8966 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8968 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8969 "File Entry: 0x%x", (unsigned) i + 1);
8971 /* Include directory index. */
8972 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8974 /* Modification time. */
8975 dw2_asm_output_data_uleb128 (0, NULL);
8977 /* File length in bytes. */
8978 dw2_asm_output_data_uleb128 (0, NULL);
8981 dw2_asm_output_data (1, 0, "End file name table");
8985 /* Output the source line number correspondence information. This
8986 information goes into the .debug_line section. */
8989 output_line_info (void)
8991 char l1[20], l2[20], p1[20], p2[20];
8992 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8993 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8996 unsigned long lt_index;
8997 unsigned long current_line;
9000 unsigned long current_file;
9001 unsigned long function;
9003 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9004 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9005 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9006 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9008 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9009 dw2_asm_output_data (4, 0xffffffff,
9010 "Initial length escape value indicating 64-bit DWARF extension");
9011 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9012 "Length of Source Line Info");
9013 ASM_OUTPUT_LABEL (asm_out_file, l1);
9015 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
9016 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9017 ASM_OUTPUT_LABEL (asm_out_file, p1);
9019 /* Define the architecture-dependent minimum instruction length (in
9020 bytes). In this implementation of DWARF, this field is used for
9021 information purposes only. Since GCC generates assembly language,
9022 we have no a priori knowledge of how many instruction bytes are
9023 generated for each source line, and therefore can use only the
9024 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9025 commands. Accordingly, we fix this as `1', which is "correct
9026 enough" for all architectures, and don't let the target override. */
9027 dw2_asm_output_data (1, 1,
9028 "Minimum Instruction Length");
9030 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9031 "Default is_stmt_start flag");
9032 dw2_asm_output_data (1, DWARF_LINE_BASE,
9033 "Line Base Value (Special Opcodes)");
9034 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9035 "Line Range Value (Special Opcodes)");
9036 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9037 "Special Opcode Base");
9039 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9043 case DW_LNS_advance_pc:
9044 case DW_LNS_advance_line:
9045 case DW_LNS_set_file:
9046 case DW_LNS_set_column:
9047 case DW_LNS_fixed_advance_pc:
9055 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9059 /* Write out the information about the files we use. */
9060 output_file_names ();
9061 ASM_OUTPUT_LABEL (asm_out_file, p2);
9063 /* We used to set the address register to the first location in the text
9064 section here, but that didn't accomplish anything since we already
9065 have a line note for the opening brace of the first function. */
9067 /* Generate the line number to PC correspondence table, encoded as
9068 a series of state machine operations. */
9072 if (cfun && in_cold_section_p)
9073 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9075 strcpy (prev_line_label, text_section_label);
9076 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9078 dw_line_info_ref line_info = &line_info_table[lt_index];
9081 /* Disable this optimization for now; GDB wants to see two line notes
9082 at the beginning of a function so it can find the end of the
9085 /* Don't emit anything for redundant notes. Just updating the
9086 address doesn't accomplish anything, because we already assume
9087 that anything after the last address is this line. */
9088 if (line_info->dw_line_num == current_line
9089 && line_info->dw_file_num == current_file)
9093 /* Emit debug info for the address of the current line.
9095 Unfortunately, we have little choice here currently, and must always
9096 use the most general form. GCC does not know the address delta
9097 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9098 attributes which will give an upper bound on the address range. We
9099 could perhaps use length attributes to determine when it is safe to
9100 use DW_LNS_fixed_advance_pc. */
9102 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9105 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9106 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9107 "DW_LNS_fixed_advance_pc");
9108 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9112 /* This can handle any delta. This takes
9113 4+DWARF2_ADDR_SIZE bytes. */
9114 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9115 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9116 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9117 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9120 strcpy (prev_line_label, line_label);
9122 /* Emit debug info for the source file of the current line, if
9123 different from the previous line. */
9124 if (line_info->dw_file_num != current_file)
9126 current_file = line_info->dw_file_num;
9127 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9128 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9131 /* Emit debug info for the current line number, choosing the encoding
9132 that uses the least amount of space. */
9133 if (line_info->dw_line_num != current_line)
9135 line_offset = line_info->dw_line_num - current_line;
9136 line_delta = line_offset - DWARF_LINE_BASE;
9137 current_line = line_info->dw_line_num;
9138 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9139 /* This can handle deltas from -10 to 234, using the current
9140 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9142 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9143 "line %lu", current_line);
9146 /* This can handle any delta. This takes at least 4 bytes,
9147 depending on the value being encoded. */
9148 dw2_asm_output_data (1, DW_LNS_advance_line,
9149 "advance to line %lu", current_line);
9150 dw2_asm_output_data_sleb128 (line_offset, NULL);
9151 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9155 /* We still need to start a new row, so output a copy insn. */
9156 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9159 /* Emit debug info for the address of the end of the function. */
9162 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9163 "DW_LNS_fixed_advance_pc");
9164 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9168 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9169 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9170 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9171 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9174 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9175 dw2_asm_output_data_uleb128 (1, NULL);
9176 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9181 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9183 dw_separate_line_info_ref line_info
9184 = &separate_line_info_table[lt_index];
9187 /* Don't emit anything for redundant notes. */
9188 if (line_info->dw_line_num == current_line
9189 && line_info->dw_file_num == current_file
9190 && line_info->function == function)
9194 /* Emit debug info for the address of the current line. If this is
9195 a new function, or the first line of a function, then we need
9196 to handle it differently. */
9197 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9199 if (function != line_info->function)
9201 function = line_info->function;
9203 /* Set the address register to the first line in the function. */
9204 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9205 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9206 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9207 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9211 /* ??? See the DW_LNS_advance_pc comment above. */
9214 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9215 "DW_LNS_fixed_advance_pc");
9216 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9220 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9221 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9222 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9223 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9227 strcpy (prev_line_label, line_label);
9229 /* Emit debug info for the source file of the current line, if
9230 different from the previous line. */
9231 if (line_info->dw_file_num != current_file)
9233 current_file = line_info->dw_file_num;
9234 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9235 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9238 /* Emit debug info for the current line number, choosing the encoding
9239 that uses the least amount of space. */
9240 if (line_info->dw_line_num != current_line)
9242 line_offset = line_info->dw_line_num - current_line;
9243 line_delta = line_offset - DWARF_LINE_BASE;
9244 current_line = line_info->dw_line_num;
9245 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9246 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9247 "line %lu", current_line);
9250 dw2_asm_output_data (1, DW_LNS_advance_line,
9251 "advance to line %lu", current_line);
9252 dw2_asm_output_data_sleb128 (line_offset, NULL);
9253 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9257 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9265 /* If we're done with a function, end its sequence. */
9266 if (lt_index == separate_line_info_table_in_use
9267 || separate_line_info_table[lt_index].function != function)
9272 /* Emit debug info for the address of the end of the function. */
9273 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9276 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9277 "DW_LNS_fixed_advance_pc");
9278 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9282 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9283 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9284 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9285 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9288 /* Output the marker for the end of this sequence. */
9289 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9290 dw2_asm_output_data_uleb128 (1, NULL);
9291 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9295 /* Output the marker for the end of the line number info. */
9296 ASM_OUTPUT_LABEL (asm_out_file, l2);
9299 /* Given a pointer to a tree node for some base type, return a pointer to
9300 a DIE that describes the given type.
9302 This routine must only be called for GCC type nodes that correspond to
9303 Dwarf base (fundamental) types. */
9306 base_type_die (tree type)
9308 dw_die_ref base_type_result;
9309 enum dwarf_type encoding;
9311 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9314 switch (TREE_CODE (type))
9317 if (TYPE_STRING_FLAG (type))
9319 if (TYPE_UNSIGNED (type))
9320 encoding = DW_ATE_unsigned_char;
9322 encoding = DW_ATE_signed_char;
9324 else if (TYPE_UNSIGNED (type))
9325 encoding = DW_ATE_unsigned;
9327 encoding = DW_ATE_signed;
9331 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9332 encoding = DW_ATE_decimal_float;
9334 encoding = DW_ATE_float;
9337 case FIXED_POINT_TYPE:
9338 if (TYPE_UNSIGNED (type))
9339 encoding = DW_ATE_unsigned_fixed;
9341 encoding = DW_ATE_signed_fixed;
9344 /* Dwarf2 doesn't know anything about complex ints, so use
9345 a user defined type for it. */
9347 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9348 encoding = DW_ATE_complex_float;
9350 encoding = DW_ATE_lo_user;
9354 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9355 encoding = DW_ATE_boolean;
9359 /* No other TREE_CODEs are Dwarf fundamental types. */
9363 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9365 /* This probably indicates a bug. */
9366 if (! TYPE_NAME (type))
9367 add_name_attribute (base_type_result, "__unknown__");
9369 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9370 int_size_in_bytes (type));
9371 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9373 return base_type_result;
9376 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9377 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9380 is_base_type (tree type)
9382 switch (TREE_CODE (type))
9388 case FIXED_POINT_TYPE:
9396 case QUAL_UNION_TYPE:
9401 case REFERENCE_TYPE:
9414 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9415 node, return the size in bits for the type if it is a constant, or else
9416 return the alignment for the type if the type's size is not constant, or
9417 else return BITS_PER_WORD if the type actually turns out to be an
9420 static inline unsigned HOST_WIDE_INT
9421 simple_type_size_in_bits (const_tree type)
9423 if (TREE_CODE (type) == ERROR_MARK)
9424 return BITS_PER_WORD;
9425 else if (TYPE_SIZE (type) == NULL_TREE)
9427 else if (host_integerp (TYPE_SIZE (type), 1))
9428 return tree_low_cst (TYPE_SIZE (type), 1);
9430 return TYPE_ALIGN (type);
9433 /* Return true if the debug information for the given type should be
9434 emitted as a subrange type. */
9437 is_subrange_type (const_tree type)
9439 tree subtype = TREE_TYPE (type);
9441 /* Subrange types are identified by the fact that they are integer
9442 types, and that they have a subtype which is either an integer type
9443 or an enumeral type. */
9445 if (TREE_CODE (type) != INTEGER_TYPE
9446 || subtype == NULL_TREE)
9449 if (TREE_CODE (subtype) != INTEGER_TYPE
9450 && TREE_CODE (subtype) != ENUMERAL_TYPE
9451 && TREE_CODE (subtype) != BOOLEAN_TYPE)
9454 if (TREE_CODE (type) == TREE_CODE (subtype)
9455 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
9456 && TYPE_MIN_VALUE (type) != NULL
9457 && TYPE_MIN_VALUE (subtype) != NULL
9458 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
9459 && TYPE_MAX_VALUE (type) != NULL
9460 && TYPE_MAX_VALUE (subtype) != NULL
9461 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
9463 /* The type and its subtype have the same representation. If in
9464 addition the two types also have the same name, then the given
9465 type is not a subrange type, but rather a plain base type. */
9466 /* FIXME: brobecker/2004-03-22:
9467 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9468 therefore be sufficient to check the TYPE_SIZE node pointers
9469 rather than checking the actual size. Unfortunately, we have
9470 found some cases, such as in the Ada "integer" type, where
9471 this is not the case. Until this problem is solved, we need to
9472 keep checking the actual size. */
9473 tree type_name = TYPE_NAME (type);
9474 tree subtype_name = TYPE_NAME (subtype);
9476 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
9477 type_name = DECL_NAME (type_name);
9479 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
9480 subtype_name = DECL_NAME (subtype_name);
9482 if (type_name == subtype_name)
9489 /* Given a pointer to a tree node for a subrange type, return a pointer
9490 to a DIE that describes the given type. */
9493 subrange_type_die (tree type, dw_die_ref context_die)
9495 dw_die_ref subrange_die;
9496 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9498 if (context_die == NULL)
9499 context_die = comp_unit_die;
9501 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9503 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9505 /* The size of the subrange type and its base type do not match,
9506 so we need to generate a size attribute for the subrange type. */
9507 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9510 if (TYPE_MIN_VALUE (type) != NULL)
9511 add_bound_info (subrange_die, DW_AT_lower_bound,
9512 TYPE_MIN_VALUE (type));
9513 if (TYPE_MAX_VALUE (type) != NULL)
9514 add_bound_info (subrange_die, DW_AT_upper_bound,
9515 TYPE_MAX_VALUE (type));
9517 return subrange_die;
9520 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9521 entry that chains various modifiers in front of the given type. */
9524 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9525 dw_die_ref context_die)
9527 enum tree_code code = TREE_CODE (type);
9528 dw_die_ref mod_type_die;
9529 dw_die_ref sub_die = NULL;
9530 tree item_type = NULL;
9531 tree qualified_type;
9534 if (code == ERROR_MARK)
9537 /* See if we already have the appropriately qualified variant of
9540 = get_qualified_type (type,
9541 ((is_const_type ? TYPE_QUAL_CONST : 0)
9542 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9544 /* If we do, then we can just use its DIE, if it exists. */
9547 mod_type_die = lookup_type_die (qualified_type);
9549 return mod_type_die;
9552 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9554 /* Handle C typedef types. */
9555 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9557 tree dtype = TREE_TYPE (name);
9559 if (qualified_type == dtype)
9561 /* For a named type, use the typedef. */
9562 gen_type_die (qualified_type, context_die);
9563 return lookup_type_die (qualified_type);
9565 else if (is_const_type < TYPE_READONLY (dtype)
9566 || is_volatile_type < TYPE_VOLATILE (dtype)
9567 || (is_const_type <= TYPE_READONLY (dtype)
9568 && is_volatile_type <= TYPE_VOLATILE (dtype)
9569 && DECL_ORIGINAL_TYPE (name) != type))
9570 /* cv-unqualified version of named type. Just use the unnamed
9571 type to which it refers. */
9572 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9573 is_const_type, is_volatile_type,
9575 /* Else cv-qualified version of named type; fall through. */
9580 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9581 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9583 else if (is_volatile_type)
9585 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9586 sub_die = modified_type_die (type, 0, 0, context_die);
9588 else if (code == POINTER_TYPE)
9590 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9591 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9592 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9593 item_type = TREE_TYPE (type);
9595 else if (code == REFERENCE_TYPE)
9597 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9598 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9599 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9600 item_type = TREE_TYPE (type);
9602 else if (is_subrange_type (type))
9604 mod_type_die = subrange_type_die (type, context_die);
9605 item_type = TREE_TYPE (type);
9607 else if (is_base_type (type))
9608 mod_type_die = base_type_die (type);
9611 gen_type_die (type, context_die);
9613 /* We have to get the type_main_variant here (and pass that to the
9614 `lookup_type_die' routine) because the ..._TYPE node we have
9615 might simply be a *copy* of some original type node (where the
9616 copy was created to help us keep track of typedef names) and
9617 that copy might have a different TYPE_UID from the original
9619 if (TREE_CODE (type) != VECTOR_TYPE)
9620 return lookup_type_die (type_main_variant (type));
9622 /* Vectors have the debugging information in the type,
9623 not the main variant. */
9624 return lookup_type_die (type);
9627 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9628 don't output a DW_TAG_typedef, since there isn't one in the
9629 user's program; just attach a DW_AT_name to the type. */
9631 && (TREE_CODE (name) != TYPE_DECL
9632 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9634 if (TREE_CODE (name) == TYPE_DECL)
9635 /* Could just call add_name_and_src_coords_attributes here,
9636 but since this is a builtin type it doesn't have any
9637 useful source coordinates anyway. */
9638 name = DECL_NAME (name);
9639 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9643 equate_type_number_to_die (qualified_type, mod_type_die);
9646 /* We must do this after the equate_type_number_to_die call, in case
9647 this is a recursive type. This ensures that the modified_type_die
9648 recursion will terminate even if the type is recursive. Recursive
9649 types are possible in Ada. */
9650 sub_die = modified_type_die (item_type,
9651 TYPE_READONLY (item_type),
9652 TYPE_VOLATILE (item_type),
9655 if (sub_die != NULL)
9656 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9658 return mod_type_die;
9661 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9662 an enumerated type. */
9665 type_is_enum (const_tree type)
9667 return TREE_CODE (type) == ENUMERAL_TYPE;
9670 /* Return the DBX register number described by a given RTL node. */
9673 dbx_reg_number (const_rtx rtl)
9675 unsigned regno = REGNO (rtl);
9677 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9679 #ifdef LEAF_REG_REMAP
9680 if (current_function_uses_only_leaf_regs)
9682 int leaf_reg = LEAF_REG_REMAP (regno);
9684 regno = (unsigned) leaf_reg;
9688 return DBX_REGISTER_NUMBER (regno);
9691 /* Optionally add a DW_OP_piece term to a location description expression.
9692 DW_OP_piece is only added if the location description expression already
9693 doesn't end with DW_OP_piece. */
9696 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9698 dw_loc_descr_ref loc;
9700 if (*list_head != NULL)
9702 /* Find the end of the chain. */
9703 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9706 if (loc->dw_loc_opc != DW_OP_piece)
9707 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9711 /* Return a location descriptor that designates a machine register or
9712 zero if there is none. */
9714 static dw_loc_descr_ref
9715 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9719 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9722 regs = targetm.dwarf_register_span (rtl);
9724 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9725 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9727 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9730 /* Return a location descriptor that designates a machine register for
9731 a given hard register number. */
9733 static dw_loc_descr_ref
9734 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9736 dw_loc_descr_ref reg_loc_descr = new_reg_loc_descr (regno, 0);
9738 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9739 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9741 return reg_loc_descr;
9744 /* Given an RTL of a register, return a location descriptor that
9745 designates a value that spans more than one register. */
9747 static dw_loc_descr_ref
9748 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9749 enum var_init_status initialized)
9753 dw_loc_descr_ref loc_result = NULL;
9756 #ifdef LEAF_REG_REMAP
9757 if (current_function_uses_only_leaf_regs)
9759 int leaf_reg = LEAF_REG_REMAP (reg);
9761 reg = (unsigned) leaf_reg;
9764 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
9765 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
9767 /* Simple, contiguous registers. */
9768 if (regs == NULL_RTX)
9770 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
9777 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
9778 VAR_INIT_STATUS_INITIALIZED);
9779 add_loc_descr (&loc_result, t);
9780 add_loc_descr_op_piece (&loc_result, size);
9786 /* Now onto stupid register sets in non contiguous locations. */
9788 gcc_assert (GET_CODE (regs) == PARALLEL);
9790 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9793 for (i = 0; i < XVECLEN (regs, 0); ++i)
9797 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
9798 VAR_INIT_STATUS_INITIALIZED);
9799 add_loc_descr (&loc_result, t);
9800 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9801 add_loc_descr_op_piece (&loc_result, size);
9804 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9805 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9809 #endif /* DWARF2_DEBUGGING_INFO */
9811 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9813 /* Return a location descriptor that designates a constant. */
9815 static dw_loc_descr_ref
9816 int_loc_descriptor (HOST_WIDE_INT i)
9818 enum dwarf_location_atom op;
9820 /* Pick the smallest representation of a constant, rather than just
9821 defaulting to the LEB encoding. */
9825 op = DW_OP_lit0 + i;
9828 else if (i <= 0xffff)
9830 else if (HOST_BITS_PER_WIDE_INT == 32
9840 else if (i >= -0x8000)
9842 else if (HOST_BITS_PER_WIDE_INT == 32
9843 || i >= -0x80000000)
9849 return new_loc_descr (op, i, 0);
9853 #ifdef DWARF2_DEBUGGING_INFO
9855 /* Return a location descriptor that designates a base+offset location. */
9857 static dw_loc_descr_ref
9858 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9859 enum var_init_status initialized)
9862 dw_loc_descr_ref result;
9863 dw_fde_ref fde = current_fde ();
9865 /* We only use "frame base" when we're sure we're talking about the
9866 post-prologue local stack frame. We do this by *not* running
9867 register elimination until this point, and recognizing the special
9868 argument pointer and soft frame pointer rtx's. */
9869 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9871 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9875 if (GET_CODE (elim) == PLUS)
9877 offset += INTVAL (XEXP (elim, 1));
9878 elim = XEXP (elim, 0);
9880 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9881 && (elim == hard_frame_pointer_rtx
9882 || elim == stack_pointer_rtx))
9883 || elim == (frame_pointer_needed
9884 ? hard_frame_pointer_rtx
9885 : stack_pointer_rtx));
9887 /* If drap register is used to align stack, use frame
9888 pointer + offset to access stack variables. If stack
9889 is aligned without drap, use stack pointer + offset to
9890 access stack variables. */
9891 if (crtl->stack_realign_tried
9892 && cfa.reg == HARD_FRAME_POINTER_REGNUM
9893 && reg == frame_pointer_rtx)
9896 = DWARF_FRAME_REGNUM (cfa.indirect
9897 ? HARD_FRAME_POINTER_REGNUM
9899 return new_reg_loc_descr (base_reg, offset);
9902 offset += frame_pointer_fb_offset;
9903 return new_loc_descr (DW_OP_fbreg, offset, 0);
9907 && fde->drap_reg != INVALID_REGNUM
9908 && (fde->drap_reg == REGNO (reg)
9909 || fde->vdrap_reg == REGNO (reg)))
9911 /* Use cfa+offset to represent the location of arguments passed
9912 on stack when drap is used to align stack. */
9913 return new_loc_descr (DW_OP_fbreg, offset, 0);
9916 regno = dbx_reg_number (reg);
9918 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9920 result = new_loc_descr (DW_OP_bregx, regno, offset);
9922 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9923 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9928 /* Return true if this RTL expression describes a base+offset calculation. */
9931 is_based_loc (const_rtx rtl)
9933 return (GET_CODE (rtl) == PLUS
9934 && ((REG_P (XEXP (rtl, 0))
9935 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9936 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9939 /* Return a descriptor that describes the concatenation of N locations
9940 used to form the address of a memory location. */
9942 static dw_loc_descr_ref
9943 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9944 enum var_init_status initialized)
9947 dw_loc_descr_ref cc_loc_result = NULL;
9948 unsigned int n = XVECLEN (concatn, 0);
9950 for (i = 0; i < n; ++i)
9952 dw_loc_descr_ref ref;
9953 rtx x = XVECEXP (concatn, 0, i);
9955 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9959 add_loc_descr (&cc_loc_result, ref);
9960 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9963 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9964 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9966 return cc_loc_result;
9969 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
9972 static dw_loc_descr_ref
9973 tls_mem_loc_descriptor (rtx mem)
9976 dw_loc_descr_ref loc_result, loc_result2;
9978 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
9981 base = get_base_address (MEM_EXPR (mem));
9983 || TREE_CODE (base) != VAR_DECL
9984 || !DECL_THREAD_LOCAL_P (base))
9987 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
9988 if (loc_result == NULL)
9991 if (INTVAL (MEM_OFFSET (mem)))
9993 if (INTVAL (MEM_OFFSET (mem)) >= 0)
9994 add_loc_descr (&loc_result,
9995 new_loc_descr (DW_OP_plus_uconst,
9996 INTVAL (MEM_OFFSET (mem)), 0));
9999 loc_result2 = mem_loc_descriptor (MEM_OFFSET (mem), GET_MODE (mem),
10000 VAR_INIT_STATUS_INITIALIZED);
10001 if (loc_result2 == 0)
10003 add_loc_descr (&loc_result, loc_result2);
10004 add_loc_descr (&loc_result, new_loc_descr (DW_OP_plus, 0, 0));
10011 /* The following routine converts the RTL for a variable or parameter
10012 (resident in memory) into an equivalent Dwarf representation of a
10013 mechanism for getting the address of that same variable onto the top of a
10014 hypothetical "address evaluation" stack.
10016 When creating memory location descriptors, we are effectively transforming
10017 the RTL for a memory-resident object into its Dwarf postfix expression
10018 equivalent. This routine recursively descends an RTL tree, turning
10019 it into Dwarf postfix code as it goes.
10021 MODE is the mode of the memory reference, needed to handle some
10022 autoincrement addressing modes.
10024 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
10025 location list for RTL.
10027 Return 0 if we can't represent the location. */
10029 static dw_loc_descr_ref
10030 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
10031 enum var_init_status initialized)
10033 dw_loc_descr_ref mem_loc_result = NULL;
10034 enum dwarf_location_atom op;
10036 /* Note that for a dynamically sized array, the location we will generate a
10037 description of here will be the lowest numbered location which is
10038 actually within the array. That's *not* necessarily the same as the
10039 zeroth element of the array. */
10041 rtl = targetm.delegitimize_address (rtl);
10043 switch (GET_CODE (rtl))
10048 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
10049 just fall into the SUBREG code. */
10051 /* ... fall through ... */
10054 /* The case of a subreg may arise when we have a local (register)
10055 variable or a formal (register) parameter which doesn't quite fill
10056 up an entire register. For now, just assume that it is
10057 legitimate to make the Dwarf info refer to the whole register which
10058 contains the given subreg. */
10059 rtl = XEXP (rtl, 0);
10061 /* ... fall through ... */
10064 /* Whenever a register number forms a part of the description of the
10065 method for calculating the (dynamic) address of a memory resident
10066 object, DWARF rules require the register number be referred to as
10067 a "base register". This distinction is not based in any way upon
10068 what category of register the hardware believes the given register
10069 belongs to. This is strictly DWARF terminology we're dealing with
10070 here. Note that in cases where the location of a memory-resident
10071 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10072 OP_CONST (0)) the actual DWARF location descriptor that we generate
10073 may just be OP_BASEREG (basereg). This may look deceptively like
10074 the object in question was allocated to a register (rather than in
10075 memory) so DWARF consumers need to be aware of the subtle
10076 distinction between OP_REG and OP_BASEREG. */
10077 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
10078 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
10079 else if (stack_realign_drap
10081 && crtl->args.internal_arg_pointer == rtl
10082 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
10084 /* If RTL is internal_arg_pointer, which has been optimized
10085 out, use DRAP instead. */
10086 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
10087 VAR_INIT_STATUS_INITIALIZED);
10092 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10093 VAR_INIT_STATUS_INITIALIZED);
10094 if (mem_loc_result == NULL)
10095 mem_loc_result = tls_mem_loc_descriptor (rtl);
10096 if (mem_loc_result != 0)
10097 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
10101 rtl = XEXP (rtl, 1);
10103 /* ... fall through ... */
10106 /* Some ports can transform a symbol ref into a label ref, because
10107 the symbol ref is too far away and has to be dumped into a constant
10111 /* Alternatively, the symbol in the constant pool might be referenced
10112 by a different symbol. */
10113 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
10116 rtx tmp = get_pool_constant_mark (rtl, &marked);
10118 if (GET_CODE (tmp) == SYMBOL_REF)
10121 if (CONSTANT_POOL_ADDRESS_P (tmp))
10122 get_pool_constant_mark (tmp, &marked);
10127 /* If all references to this pool constant were optimized away,
10128 it was not output and thus we can't represent it.
10129 FIXME: might try to use DW_OP_const_value here, though
10130 DW_OP_piece complicates it. */
10135 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
10136 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
10137 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10138 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10142 /* Extract the PLUS expression nested inside and fall into
10143 PLUS code below. */
10144 rtl = XEXP (rtl, 1);
10149 /* Turn these into a PLUS expression and fall into the PLUS code
10151 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10152 GEN_INT (GET_CODE (rtl) == PRE_INC
10153 ? GET_MODE_UNIT_SIZE (mode)
10154 : -GET_MODE_UNIT_SIZE (mode)));
10156 /* ... fall through ... */
10160 if (is_based_loc (rtl))
10161 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10162 INTVAL (XEXP (rtl, 1)),
10163 VAR_INIT_STATUS_INITIALIZED);
10166 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10167 VAR_INIT_STATUS_INITIALIZED);
10168 if (mem_loc_result == 0)
10171 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
10172 && INTVAL (XEXP (rtl, 1)) >= 0)
10173 add_loc_descr (&mem_loc_result,
10174 new_loc_descr (DW_OP_plus_uconst,
10175 INTVAL (XEXP (rtl, 1)), 0));
10178 dw_loc_descr_ref mem_loc_result2
10179 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10180 VAR_INIT_STATUS_INITIALIZED);
10181 if (mem_loc_result2 == 0)
10183 add_loc_descr (&mem_loc_result, mem_loc_result2);
10184 add_loc_descr (&mem_loc_result,
10185 new_loc_descr (DW_OP_plus, 0, 0));
10190 /* If a pseudo-reg is optimized away, it is possible for it to
10191 be replaced with a MEM containing a multiply or shift. */
10210 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10211 VAR_INIT_STATUS_INITIALIZED);
10212 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10213 VAR_INIT_STATUS_INITIALIZED);
10215 if (op0 == 0 || op1 == 0)
10218 mem_loc_result = op0;
10219 add_loc_descr (&mem_loc_result, op1);
10220 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10225 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10229 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10230 VAR_INIT_STATUS_INITIALIZED);
10234 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10235 can't express it in the debug info. This can happen e.g. with some
10240 gcc_unreachable ();
10243 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10244 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10246 return mem_loc_result;
10249 /* Return a descriptor that describes the concatenation of two locations.
10250 This is typically a complex variable. */
10252 static dw_loc_descr_ref
10253 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10255 dw_loc_descr_ref cc_loc_result = NULL;
10256 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10257 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10259 if (x0_ref == 0 || x1_ref == 0)
10262 cc_loc_result = x0_ref;
10263 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10265 add_loc_descr (&cc_loc_result, x1_ref);
10266 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10268 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10269 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10271 return cc_loc_result;
10274 /* Return a descriptor that describes the concatenation of N
10277 static dw_loc_descr_ref
10278 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10281 dw_loc_descr_ref cc_loc_result = NULL;
10282 unsigned int n = XVECLEN (concatn, 0);
10284 for (i = 0; i < n; ++i)
10286 dw_loc_descr_ref ref;
10287 rtx x = XVECEXP (concatn, 0, i);
10289 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10293 add_loc_descr (&cc_loc_result, ref);
10294 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10297 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10298 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10300 return cc_loc_result;
10303 /* Output a proper Dwarf location descriptor for a variable or parameter
10304 which is either allocated in a register or in a memory location. For a
10305 register, we just generate an OP_REG and the register number. For a
10306 memory location we provide a Dwarf postfix expression describing how to
10307 generate the (dynamic) address of the object onto the address stack.
10309 If we don't know how to describe it, return 0. */
10311 static dw_loc_descr_ref
10312 loc_descriptor (rtx rtl, enum var_init_status initialized)
10314 dw_loc_descr_ref loc_result = NULL;
10316 switch (GET_CODE (rtl))
10319 /* The case of a subreg may arise when we have a local (register)
10320 variable or a formal (register) parameter which doesn't quite fill
10321 up an entire register. For now, just assume that it is
10322 legitimate to make the Dwarf info refer to the whole register which
10323 contains the given subreg. */
10324 rtl = SUBREG_REG (rtl);
10326 /* ... fall through ... */
10329 loc_result = reg_loc_descriptor (rtl, initialized);
10333 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10335 if (loc_result == NULL)
10336 loc_result = tls_mem_loc_descriptor (rtl);
10340 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10345 loc_result = concatn_loc_descriptor (rtl, initialized);
10350 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10352 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10356 rtl = XEXP (rtl, 1);
10361 rtvec par_elems = XVEC (rtl, 0);
10362 int num_elem = GET_NUM_ELEM (par_elems);
10363 enum machine_mode mode;
10366 /* Create the first one, so we have something to add to. */
10367 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10369 if (loc_result == NULL)
10371 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10372 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10373 for (i = 1; i < num_elem; i++)
10375 dw_loc_descr_ref temp;
10377 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10381 add_loc_descr (&loc_result, temp);
10382 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10383 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10389 gcc_unreachable ();
10395 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10396 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10397 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10398 top-level invocation, and we require the address of LOC; is 0 if we require
10399 the value of LOC. */
10401 static dw_loc_descr_ref
10402 loc_descriptor_from_tree_1 (tree loc, int want_address)
10404 dw_loc_descr_ref ret, ret1;
10405 int have_address = 0;
10406 enum dwarf_location_atom op;
10408 /* ??? Most of the time we do not take proper care for sign/zero
10409 extending the values properly. Hopefully this won't be a real
10412 switch (TREE_CODE (loc))
10417 case PLACEHOLDER_EXPR:
10418 /* This case involves extracting fields from an object to determine the
10419 position of other fields. We don't try to encode this here. The
10420 only user of this is Ada, which encodes the needed information using
10421 the names of types. */
10427 case PREINCREMENT_EXPR:
10428 case PREDECREMENT_EXPR:
10429 case POSTINCREMENT_EXPR:
10430 case POSTDECREMENT_EXPR:
10431 /* There are no opcodes for these operations. */
10435 /* If we already want an address, there's nothing we can do. */
10439 /* Otherwise, process the argument and look for the address. */
10440 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10443 if (DECL_THREAD_LOCAL_P (loc))
10447 unsigned second_op;
10449 if (targetm.have_tls)
10451 /* If this is not defined, we have no way to emit the
10453 if (!targetm.asm_out.output_dwarf_dtprel)
10456 /* The way DW_OP_GNU_push_tls_address is specified, we
10457 can only look up addresses of objects in the current
10459 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
10461 first_op = INTERNAL_DW_OP_tls_addr;
10462 second_op = DW_OP_GNU_push_tls_address;
10466 if (!targetm.emutls.debug_form_tls_address)
10468 loc = emutls_decl (loc);
10469 first_op = DW_OP_addr;
10470 second_op = DW_OP_form_tls_address;
10473 rtl = rtl_for_decl_location (loc);
10474 if (rtl == NULL_RTX)
10479 rtl = XEXP (rtl, 0);
10480 if (! CONSTANT_P (rtl))
10483 ret = new_loc_descr (first_op, 0, 0);
10484 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10485 ret->dw_loc_oprnd1.v.val_addr = rtl;
10487 ret1 = new_loc_descr (second_op, 0, 0);
10488 add_loc_descr (&ret, ret1);
10496 if (DECL_HAS_VALUE_EXPR_P (loc))
10497 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10502 case FUNCTION_DECL:
10504 rtx rtl = rtl_for_decl_location (loc);
10506 if (rtl == NULL_RTX)
10508 else if (GET_CODE (rtl) == CONST_INT)
10510 HOST_WIDE_INT val = INTVAL (rtl);
10511 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10512 val &= GET_MODE_MASK (DECL_MODE (loc));
10513 ret = int_loc_descriptor (val);
10515 else if (GET_CODE (rtl) == CONST_STRING)
10517 else if (CONSTANT_P (rtl))
10519 ret = new_loc_descr (DW_OP_addr, 0, 0);
10520 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10521 ret->dw_loc_oprnd1.v.val_addr = rtl;
10525 enum machine_mode mode;
10527 /* Certain constructs can only be represented at top-level. */
10528 if (want_address == 2)
10529 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10531 mode = GET_MODE (rtl);
10534 rtl = XEXP (rtl, 0);
10537 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10543 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10547 case COMPOUND_EXPR:
10548 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10551 case VIEW_CONVERT_EXPR:
10554 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10556 case COMPONENT_REF:
10557 case BIT_FIELD_REF:
10559 case ARRAY_RANGE_REF:
10562 HOST_WIDE_INT bitsize, bitpos, bytepos;
10563 enum machine_mode mode;
10565 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10567 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10568 &unsignedp, &volatilep, false);
10573 ret = loc_descriptor_from_tree_1 (obj, 1);
10575 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10578 if (offset != NULL_TREE)
10580 /* Variable offset. */
10581 ret1 = loc_descriptor_from_tree_1 (offset, 0);
10584 add_loc_descr (&ret, ret1);
10585 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10588 bytepos = bitpos / BITS_PER_UNIT;
10590 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
10591 else if (bytepos < 0)
10593 add_loc_descr (&ret, int_loc_descriptor (bytepos));
10594 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10602 if (host_integerp (loc, 0))
10603 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10610 /* Get an RTL for this, if something has been emitted. */
10611 rtx rtl = lookup_constant_def (loc);
10612 enum machine_mode mode;
10614 if (!rtl || !MEM_P (rtl))
10616 mode = GET_MODE (rtl);
10617 rtl = XEXP (rtl, 0);
10618 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10623 case TRUTH_AND_EXPR:
10624 case TRUTH_ANDIF_EXPR:
10629 case TRUTH_XOR_EXPR:
10634 case TRUTH_OR_EXPR:
10635 case TRUTH_ORIF_EXPR:
10640 case FLOOR_DIV_EXPR:
10641 case CEIL_DIV_EXPR:
10642 case ROUND_DIV_EXPR:
10643 case TRUNC_DIV_EXPR:
10644 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10653 case FLOOR_MOD_EXPR:
10654 case CEIL_MOD_EXPR:
10655 case ROUND_MOD_EXPR:
10656 case TRUNC_MOD_EXPR:
10657 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10662 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10663 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10664 if (ret == 0 || ret1 == 0)
10667 add_loc_descr (&ret, ret1);
10668 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
10669 add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
10670 add_loc_descr (&ret, new_loc_descr (DW_OP_div, 0, 0));
10671 add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
10672 add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
10684 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10687 case POINTER_PLUS_EXPR:
10689 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10690 && host_integerp (TREE_OPERAND (loc, 1), 0))
10692 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10696 add_loc_descr (&ret,
10697 new_loc_descr (DW_OP_plus_uconst,
10698 tree_low_cst (TREE_OPERAND (loc, 1),
10708 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10715 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10722 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10729 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10744 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10745 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10746 if (ret == 0 || ret1 == 0)
10749 add_loc_descr (&ret, ret1);
10750 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10753 case TRUTH_NOT_EXPR:
10767 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10771 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10777 const enum tree_code code =
10778 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10780 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10781 build2 (code, integer_type_node,
10782 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10783 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10786 /* ... fall through ... */
10790 dw_loc_descr_ref lhs
10791 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10792 dw_loc_descr_ref rhs
10793 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10794 dw_loc_descr_ref bra_node, jump_node, tmp;
10796 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10797 if (ret == 0 || lhs == 0 || rhs == 0)
10800 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10801 add_loc_descr (&ret, bra_node);
10803 add_loc_descr (&ret, rhs);
10804 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
10805 add_loc_descr (&ret, jump_node);
10807 add_loc_descr (&ret, lhs);
10808 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10809 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
10811 /* ??? Need a node to point the skip at. Use a nop. */
10812 tmp = new_loc_descr (DW_OP_nop, 0, 0);
10813 add_loc_descr (&ret, tmp);
10814 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10815 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
10819 case FIX_TRUNC_EXPR:
10823 /* Leave front-end specific codes as simply unknown. This comes
10824 up, for instance, with the C STMT_EXPR. */
10825 if ((unsigned int) TREE_CODE (loc)
10826 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
10829 #ifdef ENABLE_CHECKING
10830 /* Otherwise this is a generic code; we should just lists all of
10831 these explicitly. We forgot one. */
10832 gcc_unreachable ();
10834 /* In a release build, we want to degrade gracefully: better to
10835 generate incomplete debugging information than to crash. */
10840 /* Show if we can't fill the request for an address. */
10841 if (want_address && !have_address)
10844 /* If we've got an address and don't want one, dereference. */
10845 if (!want_address && have_address && ret)
10847 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
10849 if (size > DWARF2_ADDR_SIZE || size == -1)
10851 else if (size == DWARF2_ADDR_SIZE)
10854 op = DW_OP_deref_size;
10856 add_loc_descr (&ret, new_loc_descr (op, size, 0));
10862 static inline dw_loc_descr_ref
10863 loc_descriptor_from_tree (tree loc)
10865 return loc_descriptor_from_tree_1 (loc, 2);
10868 /* Given a value, round it up to the lowest multiple of `boundary'
10869 which is not less than the value itself. */
10871 static inline HOST_WIDE_INT
10872 ceiling (HOST_WIDE_INT value, unsigned int boundary)
10874 return (((value + boundary - 1) / boundary) * boundary);
10877 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10878 pointer to the declared type for the relevant field variable, or return
10879 `integer_type_node' if the given node turns out to be an
10880 ERROR_MARK node. */
10883 field_type (const_tree decl)
10887 if (TREE_CODE (decl) == ERROR_MARK)
10888 return integer_type_node;
10890 type = DECL_BIT_FIELD_TYPE (decl);
10891 if (type == NULL_TREE)
10892 type = TREE_TYPE (decl);
10897 /* Given a pointer to a tree node, return the alignment in bits for
10898 it, or else return BITS_PER_WORD if the node actually turns out to
10899 be an ERROR_MARK node. */
10901 static inline unsigned
10902 simple_type_align_in_bits (const_tree type)
10904 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
10907 static inline unsigned
10908 simple_decl_align_in_bits (const_tree decl)
10910 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
10913 /* Return the result of rounding T up to ALIGN. */
10915 static inline HOST_WIDE_INT
10916 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
10918 /* We must be careful if T is negative because HOST_WIDE_INT can be
10919 either "above" or "below" unsigned int as per the C promotion
10920 rules, depending on the host, thus making the signedness of the
10921 direct multiplication and division unpredictable. */
10922 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
10928 return (HOST_WIDE_INT) u;
10931 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10932 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10933 or return 0 if we are unable to determine what that offset is, either
10934 because the argument turns out to be a pointer to an ERROR_MARK node, or
10935 because the offset is actually variable. (We can't handle the latter case
10938 static HOST_WIDE_INT
10939 field_byte_offset (const_tree decl)
10941 HOST_WIDE_INT object_offset_in_bits;
10942 HOST_WIDE_INT bitpos_int;
10944 if (TREE_CODE (decl) == ERROR_MARK)
10947 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10949 /* We cannot yet cope with fields whose positions are variable, so
10950 for now, when we see such things, we simply return 0. Someday, we may
10951 be able to handle such cases, but it will be damn difficult. */
10952 if (! host_integerp (bit_position (decl), 0))
10955 bitpos_int = int_bit_position (decl);
10957 #ifdef PCC_BITFIELD_TYPE_MATTERS
10958 if (PCC_BITFIELD_TYPE_MATTERS)
10961 tree field_size_tree;
10962 HOST_WIDE_INT deepest_bitpos;
10963 unsigned HOST_WIDE_INT field_size_in_bits;
10964 unsigned int type_align_in_bits;
10965 unsigned int decl_align_in_bits;
10966 unsigned HOST_WIDE_INT type_size_in_bits;
10968 type = field_type (decl);
10969 field_size_tree = DECL_SIZE (decl);
10971 /* The size could be unspecified if there was an error, or for
10972 a flexible array member. */
10973 if (! field_size_tree)
10974 field_size_tree = bitsize_zero_node;
10976 /* If we don't know the size of the field, pretend it's a full word. */
10977 if (host_integerp (field_size_tree, 1))
10978 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10980 field_size_in_bits = BITS_PER_WORD;
10982 type_size_in_bits = simple_type_size_in_bits (type);
10983 type_align_in_bits = simple_type_align_in_bits (type);
10984 decl_align_in_bits = simple_decl_align_in_bits (decl);
10986 /* The GCC front-end doesn't make any attempt to keep track of the
10987 starting bit offset (relative to the start of the containing
10988 structure type) of the hypothetical "containing object" for a
10989 bit-field. Thus, when computing the byte offset value for the
10990 start of the "containing object" of a bit-field, we must deduce
10991 this information on our own. This can be rather tricky to do in
10992 some cases. For example, handling the following structure type
10993 definition when compiling for an i386/i486 target (which only
10994 aligns long long's to 32-bit boundaries) can be very tricky:
10996 struct S { int field1; long long field2:31; };
10998 Fortunately, there is a simple rule-of-thumb which can be used
10999 in such cases. When compiling for an i386/i486, GCC will
11000 allocate 8 bytes for the structure shown above. It decides to
11001 do this based upon one simple rule for bit-field allocation.
11002 GCC allocates each "containing object" for each bit-field at
11003 the first (i.e. lowest addressed) legitimate alignment boundary
11004 (based upon the required minimum alignment for the declared
11005 type of the field) which it can possibly use, subject to the
11006 condition that there is still enough available space remaining
11007 in the containing object (when allocated at the selected point)
11008 to fully accommodate all of the bits of the bit-field itself.
11010 This simple rule makes it obvious why GCC allocates 8 bytes for
11011 each object of the structure type shown above. When looking
11012 for a place to allocate the "containing object" for `field2',
11013 the compiler simply tries to allocate a 64-bit "containing
11014 object" at each successive 32-bit boundary (starting at zero)
11015 until it finds a place to allocate that 64- bit field such that
11016 at least 31 contiguous (and previously unallocated) bits remain
11017 within that selected 64 bit field. (As it turns out, for the
11018 example above, the compiler finds it is OK to allocate the
11019 "containing object" 64-bit field at bit-offset zero within the
11022 Here we attempt to work backwards from the limited set of facts
11023 we're given, and we try to deduce from those facts, where GCC
11024 must have believed that the containing object started (within
11025 the structure type). The value we deduce is then used (by the
11026 callers of this routine) to generate DW_AT_location and
11027 DW_AT_bit_offset attributes for fields (both bit-fields and, in
11028 the case of DW_AT_location, regular fields as well). */
11030 /* Figure out the bit-distance from the start of the structure to
11031 the "deepest" bit of the bit-field. */
11032 deepest_bitpos = bitpos_int + field_size_in_bits;
11034 /* This is the tricky part. Use some fancy footwork to deduce
11035 where the lowest addressed bit of the containing object must
11037 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11039 /* Round up to type_align by default. This works best for
11041 object_offset_in_bits
11042 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
11044 if (object_offset_in_bits > bitpos_int)
11046 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11048 /* Round up to decl_align instead. */
11049 object_offset_in_bits
11050 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
11055 object_offset_in_bits = bitpos_int;
11057 return object_offset_in_bits / BITS_PER_UNIT;
11060 /* The following routines define various Dwarf attributes and any data
11061 associated with them. */
11063 /* Add a location description attribute value to a DIE.
11065 This emits location attributes suitable for whole variables and
11066 whole parameters. Note that the location attributes for struct fields are
11067 generated by the routine `data_member_location_attribute' below. */
11070 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
11071 dw_loc_descr_ref descr)
11074 add_AT_loc (die, attr_kind, descr);
11077 /* Attach the specialized form of location attribute used for data members of
11078 struct and union types. In the special case of a FIELD_DECL node which
11079 represents a bit-field, the "offset" part of this special location
11080 descriptor must indicate the distance in bytes from the lowest-addressed
11081 byte of the containing struct or union type to the lowest-addressed byte of
11082 the "containing object" for the bit-field. (See the `field_byte_offset'
11085 For any given bit-field, the "containing object" is a hypothetical object
11086 (of some integral or enum type) within which the given bit-field lives. The
11087 type of this hypothetical "containing object" is always the same as the
11088 declared type of the individual bit-field itself (for GCC anyway... the
11089 DWARF spec doesn't actually mandate this). Note that it is the size (in
11090 bytes) of the hypothetical "containing object" which will be given in the
11091 DW_AT_byte_size attribute for this bit-field. (See the
11092 `byte_size_attribute' function below.) It is also used when calculating the
11093 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11094 function below.) */
11097 add_data_member_location_attribute (dw_die_ref die, tree decl)
11099 HOST_WIDE_INT offset;
11100 dw_loc_descr_ref loc_descr = 0;
11102 if (TREE_CODE (decl) == TREE_BINFO)
11104 /* We're working on the TAG_inheritance for a base class. */
11105 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
11107 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11108 aren't at a fixed offset from all (sub)objects of the same
11109 type. We need to extract the appropriate offset from our
11110 vtable. The following dwarf expression means
11112 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11114 This is specific to the V3 ABI, of course. */
11116 dw_loc_descr_ref tmp;
11118 /* Make a copy of the object address. */
11119 tmp = new_loc_descr (DW_OP_dup, 0, 0);
11120 add_loc_descr (&loc_descr, tmp);
11122 /* Extract the vtable address. */
11123 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11124 add_loc_descr (&loc_descr, tmp);
11126 /* Calculate the address of the offset. */
11127 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
11128 gcc_assert (offset < 0);
11130 tmp = int_loc_descriptor (-offset);
11131 add_loc_descr (&loc_descr, tmp);
11132 tmp = new_loc_descr (DW_OP_minus, 0, 0);
11133 add_loc_descr (&loc_descr, tmp);
11135 /* Extract the offset. */
11136 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11137 add_loc_descr (&loc_descr, tmp);
11139 /* Add it to the object address. */
11140 tmp = new_loc_descr (DW_OP_plus, 0, 0);
11141 add_loc_descr (&loc_descr, tmp);
11144 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
11147 offset = field_byte_offset (decl);
11151 enum dwarf_location_atom op;
11153 /* The DWARF2 standard says that we should assume that the structure
11154 address is already on the stack, so we can specify a structure field
11155 address by using DW_OP_plus_uconst. */
11157 #ifdef MIPS_DEBUGGING_INFO
11158 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11159 operator correctly. It works only if we leave the offset on the
11163 op = DW_OP_plus_uconst;
11166 loc_descr = new_loc_descr (op, offset, 0);
11169 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
11172 /* Writes integer values to dw_vec_const array. */
11175 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11179 *dest++ = val & 0xff;
11185 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11187 static HOST_WIDE_INT
11188 extract_int (const unsigned char *src, unsigned int size)
11190 HOST_WIDE_INT val = 0;
11196 val |= *--src & 0xff;
11202 /* Writes floating point values to dw_vec_const array. */
11205 insert_float (const_rtx rtl, unsigned char *array)
11207 REAL_VALUE_TYPE rv;
11211 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11212 real_to_target (val, &rv, GET_MODE (rtl));
11214 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11215 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11217 insert_int (val[i], 4, array);
11222 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11223 does not have a "location" either in memory or in a register. These
11224 things can arise in GNU C when a constant is passed as an actual parameter
11225 to an inlined function. They can also arise in C++ where declared
11226 constants do not necessarily get memory "homes". */
11229 add_const_value_attribute (dw_die_ref die, rtx rtl)
11231 switch (GET_CODE (rtl))
11235 HOST_WIDE_INT val = INTVAL (rtl);
11238 add_AT_int (die, DW_AT_const_value, val);
11240 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11245 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11246 floating-point constant. A CONST_DOUBLE is used whenever the
11247 constant requires more than one word in order to be adequately
11248 represented. We output CONST_DOUBLEs as blocks. */
11250 enum machine_mode mode = GET_MODE (rtl);
11252 if (SCALAR_FLOAT_MODE_P (mode))
11254 unsigned int length = GET_MODE_SIZE (mode);
11255 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11257 insert_float (rtl, array);
11258 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11262 /* ??? We really should be using HOST_WIDE_INT throughout. */
11263 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11265 add_AT_long_long (die, DW_AT_const_value,
11266 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11273 enum machine_mode mode = GET_MODE (rtl);
11274 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11275 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11276 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11280 switch (GET_MODE_CLASS (mode))
11282 case MODE_VECTOR_INT:
11283 for (i = 0, p = array; i < length; i++, p += elt_size)
11285 rtx elt = CONST_VECTOR_ELT (rtl, i);
11286 HOST_WIDE_INT lo, hi;
11288 switch (GET_CODE (elt))
11296 lo = CONST_DOUBLE_LOW (elt);
11297 hi = CONST_DOUBLE_HIGH (elt);
11301 gcc_unreachable ();
11304 if (elt_size <= sizeof (HOST_WIDE_INT))
11305 insert_int (lo, elt_size, p);
11308 unsigned char *p0 = p;
11309 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11311 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11312 if (WORDS_BIG_ENDIAN)
11317 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11318 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11323 case MODE_VECTOR_FLOAT:
11324 for (i = 0, p = array; i < length; i++, p += elt_size)
11326 rtx elt = CONST_VECTOR_ELT (rtl, i);
11327 insert_float (elt, p);
11332 gcc_unreachable ();
11335 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11340 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11346 add_AT_addr (die, DW_AT_const_value, rtl);
11347 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11351 /* In cases where an inlined instance of an inline function is passed
11352 the address of an `auto' variable (which is local to the caller) we
11353 can get a situation where the DECL_RTL of the artificial local
11354 variable (for the inlining) which acts as a stand-in for the
11355 corresponding formal parameter (of the inline function) will look
11356 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11357 exactly a compile-time constant expression, but it isn't the address
11358 of the (artificial) local variable either. Rather, it represents the
11359 *value* which the artificial local variable always has during its
11360 lifetime. We currently have no way to represent such quasi-constant
11361 values in Dwarf, so for now we just punt and generate nothing. */
11365 /* No other kinds of rtx should be possible here. */
11366 gcc_unreachable ();
11371 /* Determine whether the evaluation of EXPR references any variables
11372 or functions which aren't otherwise used (and therefore may not be
11375 reference_to_unused (tree * tp, int * walk_subtrees,
11376 void * data ATTRIBUTE_UNUSED)
11378 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11379 *walk_subtrees = 0;
11381 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11382 && ! TREE_ASM_WRITTEN (*tp))
11384 /* ??? The C++ FE emits debug information for using decls, so
11385 putting gcc_unreachable here falls over. See PR31899. For now
11386 be conservative. */
11387 else if (!cgraph_global_info_ready
11388 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11390 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11392 struct varpool_node *node = varpool_node (*tp);
11396 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11397 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11399 struct cgraph_node *node = cgraph_node (*tp);
11403 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11409 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11410 for use in a later add_const_value_attribute call. */
11413 rtl_for_decl_init (tree init, tree type)
11415 rtx rtl = NULL_RTX;
11417 /* If a variable is initialized with a string constant without embedded
11418 zeros, build CONST_STRING. */
11419 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11421 tree enttype = TREE_TYPE (type);
11422 tree domain = TYPE_DOMAIN (type);
11423 enum machine_mode mode = TYPE_MODE (enttype);
11425 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11427 && integer_zerop (TYPE_MIN_VALUE (domain))
11428 && compare_tree_int (TYPE_MAX_VALUE (domain),
11429 TREE_STRING_LENGTH (init) - 1) == 0
11430 && ((size_t) TREE_STRING_LENGTH (init)
11431 == strlen (TREE_STRING_POINTER (init)) + 1))
11432 rtl = gen_rtx_CONST_STRING (VOIDmode,
11433 ggc_strdup (TREE_STRING_POINTER (init)));
11435 /* Other aggregates, and complex values, could be represented using
11437 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11439 /* Vectors only work if their mode is supported by the target.
11440 FIXME: generic vectors ought to work too. */
11441 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11443 /* If the initializer is something that we know will expand into an
11444 immediate RTL constant, expand it now. We must be careful not to
11445 reference variables which won't be output. */
11446 else if (initializer_constant_valid_p (init, type)
11447 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11449 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11451 if (TREE_CODE (type) == VECTOR_TYPE)
11452 switch (TREE_CODE (init))
11457 if (TREE_CONSTANT (init))
11459 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11460 bool constant_p = true;
11462 unsigned HOST_WIDE_INT ix;
11464 /* Even when ctor is constant, it might contain non-*_CST
11465 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11466 belong into VECTOR_CST nodes. */
11467 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11468 if (!CONSTANT_CLASS_P (value))
11470 constant_p = false;
11476 init = build_vector_from_ctor (type, elts);
11486 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11488 /* If expand_expr returns a MEM, it wasn't immediate. */
11489 gcc_assert (!rtl || !MEM_P (rtl));
11495 /* Generate RTL for the variable DECL to represent its location. */
11498 rtl_for_decl_location (tree decl)
11502 /* Here we have to decide where we are going to say the parameter "lives"
11503 (as far as the debugger is concerned). We only have a couple of
11504 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11506 DECL_RTL normally indicates where the parameter lives during most of the
11507 activation of the function. If optimization is enabled however, this
11508 could be either NULL or else a pseudo-reg. Both of those cases indicate
11509 that the parameter doesn't really live anywhere (as far as the code
11510 generation parts of GCC are concerned) during most of the function's
11511 activation. That will happen (for example) if the parameter is never
11512 referenced within the function.
11514 We could just generate a location descriptor here for all non-NULL
11515 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11516 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11517 where DECL_RTL is NULL or is a pseudo-reg.
11519 Note however that we can only get away with using DECL_INCOMING_RTL as
11520 a backup substitute for DECL_RTL in certain limited cases. In cases
11521 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11522 we can be sure that the parameter was passed using the same type as it is
11523 declared to have within the function, and that its DECL_INCOMING_RTL
11524 points us to a place where a value of that type is passed.
11526 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11527 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11528 because in these cases DECL_INCOMING_RTL points us to a value of some
11529 type which is *different* from the type of the parameter itself. Thus,
11530 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11531 such cases, the debugger would end up (for example) trying to fetch a
11532 `float' from a place which actually contains the first part of a
11533 `double'. That would lead to really incorrect and confusing
11534 output at debug-time.
11536 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11537 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11538 are a couple of exceptions however. On little-endian machines we can
11539 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11540 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11541 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11542 when (on a little-endian machine) a non-prototyped function has a
11543 parameter declared to be of type `short' or `char'. In such cases,
11544 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11545 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11546 passed `int' value. If the debugger then uses that address to fetch
11547 a `short' or a `char' (on a little-endian machine) the result will be
11548 the correct data, so we allow for such exceptional cases below.
11550 Note that our goal here is to describe the place where the given formal
11551 parameter lives during most of the function's activation (i.e. between the
11552 end of the prologue and the start of the epilogue). We'll do that as best
11553 as we can. Note however that if the given formal parameter is modified
11554 sometime during the execution of the function, then a stack backtrace (at
11555 debug-time) will show the function as having been called with the *new*
11556 value rather than the value which was originally passed in. This happens
11557 rarely enough that it is not a major problem, but it *is* a problem, and
11558 I'd like to fix it.
11560 A future version of dwarf2out.c may generate two additional attributes for
11561 any given DW_TAG_formal_parameter DIE which will describe the "passed
11562 type" and the "passed location" for the given formal parameter in addition
11563 to the attributes we now generate to indicate the "declared type" and the
11564 "active location" for each parameter. This additional set of attributes
11565 could be used by debuggers for stack backtraces. Separately, note that
11566 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11567 This happens (for example) for inlined-instances of inline function formal
11568 parameters which are never referenced. This really shouldn't be
11569 happening. All PARM_DECL nodes should get valid non-NULL
11570 DECL_INCOMING_RTL values. FIXME. */
11572 /* Use DECL_RTL as the "location" unless we find something better. */
11573 rtl = DECL_RTL_IF_SET (decl);
11575 /* When generating abstract instances, ignore everything except
11576 constants, symbols living in memory, and symbols living in
11577 fixed registers. */
11578 if (! reload_completed)
11581 && (CONSTANT_P (rtl)
11583 && CONSTANT_P (XEXP (rtl, 0)))
11585 && TREE_CODE (decl) == VAR_DECL
11586 && TREE_STATIC (decl))))
11588 rtl = targetm.delegitimize_address (rtl);
11593 else if (TREE_CODE (decl) == PARM_DECL)
11595 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11597 tree declared_type = TREE_TYPE (decl);
11598 tree passed_type = DECL_ARG_TYPE (decl);
11599 enum machine_mode dmode = TYPE_MODE (declared_type);
11600 enum machine_mode pmode = TYPE_MODE (passed_type);
11602 /* This decl represents a formal parameter which was optimized out.
11603 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11604 all cases where (rtl == NULL_RTX) just below. */
11605 if (dmode == pmode)
11606 rtl = DECL_INCOMING_RTL (decl);
11607 else if (SCALAR_INT_MODE_P (dmode)
11608 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11609 && DECL_INCOMING_RTL (decl))
11611 rtx inc = DECL_INCOMING_RTL (decl);
11614 else if (MEM_P (inc))
11616 if (BYTES_BIG_ENDIAN)
11617 rtl = adjust_address_nv (inc, dmode,
11618 GET_MODE_SIZE (pmode)
11619 - GET_MODE_SIZE (dmode));
11626 /* If the parm was passed in registers, but lives on the stack, then
11627 make a big endian correction if the mode of the type of the
11628 parameter is not the same as the mode of the rtl. */
11629 /* ??? This is the same series of checks that are made in dbxout.c before
11630 we reach the big endian correction code there. It isn't clear if all
11631 of these checks are necessary here, but keeping them all is the safe
11633 else if (MEM_P (rtl)
11634 && XEXP (rtl, 0) != const0_rtx
11635 && ! CONSTANT_P (XEXP (rtl, 0))
11636 /* Not passed in memory. */
11637 && !MEM_P (DECL_INCOMING_RTL (decl))
11638 /* Not passed by invisible reference. */
11639 && (!REG_P (XEXP (rtl, 0))
11640 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11641 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11642 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11643 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11646 /* Big endian correction check. */
11647 && BYTES_BIG_ENDIAN
11648 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11649 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11652 int offset = (UNITS_PER_WORD
11653 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11655 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11656 plus_constant (XEXP (rtl, 0), offset));
11659 else if (TREE_CODE (decl) == VAR_DECL
11662 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11663 && BYTES_BIG_ENDIAN)
11665 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11666 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11668 /* If a variable is declared "register" yet is smaller than
11669 a register, then if we store the variable to memory, it
11670 looks like we're storing a register-sized value, when in
11671 fact we are not. We need to adjust the offset of the
11672 storage location to reflect the actual value's bytes,
11673 else gdb will not be able to display it. */
11675 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11676 plus_constant (XEXP (rtl, 0), rsize-dsize));
11679 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11680 and will have been substituted directly into all expressions that use it.
11681 C does not have such a concept, but C++ and other languages do. */
11682 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11683 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11686 rtl = targetm.delegitimize_address (rtl);
11688 /* If we don't look past the constant pool, we risk emitting a
11689 reference to a constant pool entry that isn't referenced from
11690 code, and thus is not emitted. */
11692 rtl = avoid_constant_pool_reference (rtl);
11697 /* We need to figure out what section we should use as the base for the
11698 address ranges where a given location is valid.
11699 1. If this particular DECL has a section associated with it, use that.
11700 2. If this function has a section associated with it, use that.
11701 3. Otherwise, use the text section.
11702 XXX: If you split a variable across multiple sections, we won't notice. */
11704 static const char *
11705 secname_for_decl (const_tree decl)
11707 const char *secname;
11709 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11711 tree sectree = DECL_SECTION_NAME (decl);
11712 secname = TREE_STRING_POINTER (sectree);
11714 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11716 tree sectree = DECL_SECTION_NAME (current_function_decl);
11717 secname = TREE_STRING_POINTER (sectree);
11719 else if (cfun && in_cold_section_p)
11720 secname = crtl->subsections.cold_section_label;
11722 secname = text_section_label;
11727 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
11728 returned. If so, the decl for the COMMON block is returned, and the
11729 value is the offset into the common block for the symbol. */
11732 fortran_common (tree decl, HOST_WIDE_INT *value)
11734 tree val_expr, cvar;
11735 enum machine_mode mode;
11736 HOST_WIDE_INT bitsize, bitpos;
11738 int volatilep = 0, unsignedp = 0;
11740 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11741 it does not have a value (the offset into the common area), or if it
11742 is thread local (as opposed to global) then it isn't common, and shouldn't
11743 be handled as such. */
11744 if (TREE_CODE (decl) != VAR_DECL
11745 || !TREE_PUBLIC (decl)
11746 || !TREE_STATIC (decl)
11747 || !DECL_HAS_VALUE_EXPR_P (decl)
11751 val_expr = DECL_VALUE_EXPR (decl);
11752 if (TREE_CODE (val_expr) != COMPONENT_REF)
11755 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11756 &mode, &unsignedp, &volatilep, true);
11758 if (cvar == NULL_TREE
11759 || TREE_CODE (cvar) != VAR_DECL
11760 || DECL_ARTIFICIAL (cvar)
11761 || !TREE_PUBLIC (cvar))
11765 if (offset != NULL)
11767 if (!host_integerp (offset, 0))
11769 *value = tree_low_cst (offset, 0);
11772 *value += bitpos / BITS_PER_UNIT;
11777 /* Dereference a location expression LOC if DECL is passed by invisible
11780 static dw_loc_descr_ref
11781 loc_by_reference (dw_loc_descr_ref loc, tree decl)
11783 HOST_WIDE_INT size;
11784 enum dwarf_location_atom op;
11789 if ((TREE_CODE (decl) != PARM_DECL && TREE_CODE (decl) != RESULT_DECL)
11790 || !DECL_BY_REFERENCE (decl))
11793 size = int_size_in_bytes (TREE_TYPE (decl));
11794 if (size > DWARF2_ADDR_SIZE || size == -1)
11796 else if (size == DWARF2_ADDR_SIZE)
11799 op = DW_OP_deref_size;
11800 add_loc_descr (&loc, new_loc_descr (op, size, 0));
11804 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11805 data attribute for a variable or a parameter. We generate the
11806 DW_AT_const_value attribute only in those cases where the given variable
11807 or parameter does not have a true "location" either in memory or in a
11808 register. This can happen (for example) when a constant is passed as an
11809 actual argument in a call to an inline function. (It's possible that
11810 these things can crop up in other ways also.) Note that one type of
11811 constant value which can be passed into an inlined function is a constant
11812 pointer. This can happen for example if an actual argument in an inlined
11813 function call evaluates to a compile-time constant address. */
11816 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
11817 enum dwarf_attribute attr)
11820 dw_loc_descr_ref descr;
11821 var_loc_list *loc_list;
11822 struct var_loc_node *node;
11823 if (TREE_CODE (decl) == ERROR_MARK)
11826 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
11827 || TREE_CODE (decl) == RESULT_DECL);
11829 /* See if we possibly have multiple locations for this variable. */
11830 loc_list = lookup_decl_loc (decl);
11832 /* If it truly has multiple locations, the first and last node will
11834 if (loc_list && loc_list->first != loc_list->last)
11836 const char *endname, *secname;
11837 dw_loc_list_ref list;
11839 enum var_init_status initialized;
11841 /* Now that we know what section we are using for a base,
11842 actually construct the list of locations.
11843 The first location information is what is passed to the
11844 function that creates the location list, and the remaining
11845 locations just get added on to that list.
11846 Note that we only know the start address for a location
11847 (IE location changes), so to build the range, we use
11848 the range [current location start, next location start].
11849 This means we have to special case the last node, and generate
11850 a range of [last location start, end of function label]. */
11852 node = loc_list->first;
11853 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11854 secname = secname_for_decl (decl);
11856 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
11857 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11859 initialized = VAR_INIT_STATUS_INITIALIZED;
11861 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
11862 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
11865 for (; node->next; node = node->next)
11866 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11868 /* The variable has a location between NODE->LABEL and
11869 NODE->NEXT->LABEL. */
11870 enum var_init_status initialized =
11871 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11872 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11873 descr = loc_by_reference (loc_descriptor (varloc, initialized),
11875 add_loc_descr_to_loc_list (&list, descr,
11876 node->label, node->next->label, secname);
11879 /* If the variable has a location at the last label
11880 it keeps its location until the end of function. */
11881 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11883 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11884 enum var_init_status initialized =
11885 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11887 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11888 if (!current_function_decl)
11889 endname = text_end_label;
11892 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11893 current_function_funcdef_no);
11894 endname = ggc_strdup (label_id);
11896 descr = loc_by_reference (loc_descriptor (varloc, initialized),
11898 add_loc_descr_to_loc_list (&list, descr,
11899 node->label, endname, secname);
11902 /* Finally, add the location list to the DIE, and we are done. */
11903 add_AT_loc_list (die, attr, list);
11907 /* Try to get some constant RTL for this decl, and use that as the value of
11910 rtl = rtl_for_decl_location (decl);
11911 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
11913 add_const_value_attribute (die, rtl);
11917 /* If we have tried to generate the location otherwise, and it
11918 didn't work out (we wouldn't be here if we did), and we have a one entry
11919 location list, try generating a location from that. */
11920 if (loc_list && loc_list->first)
11922 enum var_init_status status;
11923 node = loc_list->first;
11924 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11925 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
11928 descr = loc_by_reference (descr, decl);
11929 add_AT_location_description (die, attr, descr);
11934 /* We couldn't get any rtl, so try directly generating the location
11935 description from the tree. */
11936 descr = loc_descriptor_from_tree (decl);
11939 descr = loc_by_reference (descr, decl);
11940 add_AT_location_description (die, attr, descr);
11943 /* None of that worked, so it must not really have a location;
11944 try adding a constant value attribute from the DECL_INITIAL. */
11945 tree_add_const_value_attribute (die, decl);
11948 /* Add VARIABLE and DIE into deferred locations list. */
11951 defer_location (tree variable, dw_die_ref die)
11953 deferred_locations entry;
11954 entry.variable = variable;
11956 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
11959 /* Helper function for tree_add_const_value_attribute. Natively encode
11960 initializer INIT into an array. Return true if successful. */
11963 native_encode_initializer (tree init, unsigned char *array, int size)
11967 if (init == NULL_TREE)
11971 switch (TREE_CODE (init))
11974 type = TREE_TYPE (init);
11975 if (TREE_CODE (type) == ARRAY_TYPE)
11977 tree enttype = TREE_TYPE (type);
11978 enum machine_mode mode = TYPE_MODE (enttype);
11980 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
11982 if (int_size_in_bytes (type) != size)
11984 if (size > TREE_STRING_LENGTH (init))
11986 memcpy (array, TREE_STRING_POINTER (init),
11987 TREE_STRING_LENGTH (init));
11988 memset (array + TREE_STRING_LENGTH (init),
11989 '\0', size - TREE_STRING_LENGTH (init));
11992 memcpy (array, TREE_STRING_POINTER (init), size);
11997 type = TREE_TYPE (init);
11998 if (int_size_in_bytes (type) != size)
12000 if (TREE_CODE (type) == ARRAY_TYPE)
12002 HOST_WIDE_INT min_index;
12003 unsigned HOST_WIDE_INT cnt;
12004 int curpos = 0, fieldsize;
12005 constructor_elt *ce;
12007 if (TYPE_DOMAIN (type) == NULL_TREE
12008 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
12011 fieldsize = int_size_in_bytes (TREE_TYPE (type));
12012 if (fieldsize <= 0)
12015 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
12016 memset (array, '\0', size);
12018 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12021 tree val = ce->value;
12022 tree index = ce->index;
12024 if (index && TREE_CODE (index) == RANGE_EXPR)
12025 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
12028 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
12033 if (!native_encode_initializer (val, array + pos, fieldsize))
12036 curpos = pos + fieldsize;
12037 if (index && TREE_CODE (index) == RANGE_EXPR)
12039 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
12040 - tree_low_cst (TREE_OPERAND (index, 0), 0);
12044 memcpy (array + curpos, array + pos, fieldsize);
12045 curpos += fieldsize;
12048 gcc_assert (curpos <= size);
12052 else if (TREE_CODE (type) == RECORD_TYPE
12053 || TREE_CODE (type) == UNION_TYPE)
12055 tree field = NULL_TREE;
12056 unsigned HOST_WIDE_INT cnt;
12057 constructor_elt *ce;
12059 if (int_size_in_bytes (type) != size)
12062 if (TREE_CODE (type) == RECORD_TYPE)
12063 field = TYPE_FIELDS (type);
12066 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12067 cnt++, field = field ? TREE_CHAIN (field) : 0)
12069 tree val = ce->value;
12070 int pos, fieldsize;
12072 if (ce->index != 0)
12078 if (field == NULL_TREE || DECL_BIT_FIELD (field))
12081 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
12082 && TYPE_DOMAIN (TREE_TYPE (field))
12083 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
12085 else if (DECL_SIZE_UNIT (field) == NULL_TREE
12086 || !host_integerp (DECL_SIZE_UNIT (field), 0))
12088 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
12089 pos = int_byte_position (field);
12090 gcc_assert (pos + fieldsize <= size);
12092 && !native_encode_initializer (val, array + pos, fieldsize))
12098 case VIEW_CONVERT_EXPR:
12099 case NON_LVALUE_EXPR:
12100 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
12102 return native_encode_expr (init, array, size) == size;
12106 /* If we don't have a copy of this variable in memory for some reason (such
12107 as a C++ member constant that doesn't have an out-of-line definition),
12108 we should tell the debugger about the constant value. */
12111 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
12114 tree type = TREE_TYPE (decl);
12117 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
12120 init = DECL_INITIAL (decl);
12121 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
12126 rtl = rtl_for_decl_init (init, type);
12128 add_const_value_attribute (var_die, rtl);
12129 /* If the host and target are sane, try harder. */
12130 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
12131 && initializer_constant_valid_p (init, type))
12133 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
12134 if (size > 0 && (int) size == size)
12136 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
12138 if (native_encode_initializer (init, array, size))
12139 add_AT_vec (var_die, DW_AT_const_value, size, 1, array);
12144 /* Convert the CFI instructions for the current function into a
12145 location list. This is used for DW_AT_frame_base when we targeting
12146 a dwarf2 consumer that does not support the dwarf3
12147 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12150 static dw_loc_list_ref
12151 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
12154 dw_loc_list_ref list, *list_tail;
12156 dw_cfa_location last_cfa, next_cfa;
12157 const char *start_label, *last_label, *section;
12159 fde = current_fde ();
12160 gcc_assert (fde != NULL);
12162 section = secname_for_decl (current_function_decl);
12166 next_cfa.reg = INVALID_REGNUM;
12167 next_cfa.offset = 0;
12168 next_cfa.indirect = 0;
12169 next_cfa.base_offset = 0;
12171 start_label = fde->dw_fde_begin;
12173 /* ??? Bald assumption that the CIE opcode list does not contain
12174 advance opcodes. */
12175 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
12176 lookup_cfa_1 (cfi, &next_cfa);
12178 last_cfa = next_cfa;
12179 last_label = start_label;
12181 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
12182 switch (cfi->dw_cfi_opc)
12184 case DW_CFA_set_loc:
12185 case DW_CFA_advance_loc1:
12186 case DW_CFA_advance_loc2:
12187 case DW_CFA_advance_loc4:
12188 if (!cfa_equal_p (&last_cfa, &next_cfa))
12190 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12191 start_label, last_label, section,
12194 list_tail = &(*list_tail)->dw_loc_next;
12195 last_cfa = next_cfa;
12196 start_label = last_label;
12198 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
12201 case DW_CFA_advance_loc:
12202 /* The encoding is complex enough that we should never emit this. */
12203 case DW_CFA_remember_state:
12204 case DW_CFA_restore_state:
12205 /* We don't handle these two in this function. It would be possible
12206 if it were to be required. */
12207 gcc_unreachable ();
12210 lookup_cfa_1 (cfi, &next_cfa);
12214 if (!cfa_equal_p (&last_cfa, &next_cfa))
12216 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12217 start_label, last_label, section,
12219 list_tail = &(*list_tail)->dw_loc_next;
12220 start_label = last_label;
12222 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
12223 start_label, fde->dw_fde_end, section,
12229 /* Compute a displacement from the "steady-state frame pointer" to the
12230 frame base (often the same as the CFA), and store it in
12231 frame_pointer_fb_offset. OFFSET is added to the displacement
12232 before the latter is negated. */
12235 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
12239 #ifdef FRAME_POINTER_CFA_OFFSET
12240 reg = frame_pointer_rtx;
12241 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
12243 reg = arg_pointer_rtx;
12244 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
12247 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
12248 if (GET_CODE (elim) == PLUS)
12250 offset += INTVAL (XEXP (elim, 1));
12251 elim = XEXP (elim, 0);
12254 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12255 && (elim == hard_frame_pointer_rtx
12256 || elim == stack_pointer_rtx))
12257 || elim == (frame_pointer_needed
12258 ? hard_frame_pointer_rtx
12259 : stack_pointer_rtx));
12261 frame_pointer_fb_offset = -offset;
12264 /* Generate a DW_AT_name attribute given some string value to be included as
12265 the value of the attribute. */
12268 add_name_attribute (dw_die_ref die, const char *name_string)
12270 if (name_string != NULL && *name_string != 0)
12272 if (demangle_name_func)
12273 name_string = (*demangle_name_func) (name_string);
12275 add_AT_string (die, DW_AT_name, name_string);
12279 /* Generate a DW_AT_comp_dir attribute for DIE. */
12282 add_comp_dir_attribute (dw_die_ref die)
12284 const char *wd = get_src_pwd ();
12286 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
12289 /* Given a tree node describing an array bound (either lower or upper) output
12290 a representation for that bound. */
12293 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
12295 switch (TREE_CODE (bound))
12300 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12302 if (! host_integerp (bound, 0)
12303 || (bound_attr == DW_AT_lower_bound
12304 && (((is_c_family () || is_java ()) && integer_zerop (bound))
12305 || (is_fortran () && integer_onep (bound)))))
12306 /* Use the default. */
12309 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
12313 case VIEW_CONVERT_EXPR:
12314 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
12324 dw_die_ref decl_die = lookup_decl_die (bound);
12325 dw_loc_descr_ref loc;
12327 /* ??? Can this happen, or should the variable have been bound
12328 first? Probably it can, since I imagine that we try to create
12329 the types of parameters in the order in which they exist in
12330 the list, and won't have created a forward reference to a
12331 later parameter. */
12332 if (decl_die != NULL)
12333 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12336 loc = loc_descriptor_from_tree_1 (bound, 0);
12337 add_AT_location_description (subrange_die, bound_attr, loc);
12344 /* Otherwise try to create a stack operation procedure to
12345 evaluate the value of the array bound. */
12347 dw_die_ref ctx, decl_die;
12348 dw_loc_descr_ref loc;
12350 loc = loc_descriptor_from_tree (bound);
12354 if (current_function_decl == 0)
12355 ctx = comp_unit_die;
12357 ctx = lookup_decl_die (current_function_decl);
12359 decl_die = new_die (DW_TAG_variable, ctx, bound);
12360 add_AT_flag (decl_die, DW_AT_artificial, 1);
12361 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
12362 add_AT_loc (decl_die, DW_AT_location, loc);
12364 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12370 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12371 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12372 Note that the block of subscript information for an array type also
12373 includes information about the element type of the given array type. */
12376 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
12378 unsigned dimension_number;
12380 dw_die_ref subrange_die;
12382 for (dimension_number = 0;
12383 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12384 type = TREE_TYPE (type), dimension_number++)
12386 tree domain = TYPE_DOMAIN (type);
12388 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
12391 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12392 and (in GNU C only) variable bounds. Handle all three forms
12394 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12397 /* We have an array type with specified bounds. */
12398 lower = TYPE_MIN_VALUE (domain);
12399 upper = TYPE_MAX_VALUE (domain);
12401 /* Define the index type. */
12402 if (TREE_TYPE (domain))
12404 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12405 TREE_TYPE field. We can't emit debug info for this
12406 because it is an unnamed integral type. */
12407 if (TREE_CODE (domain) == INTEGER_TYPE
12408 && TYPE_NAME (domain) == NULL_TREE
12409 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12410 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12413 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12417 /* ??? If upper is NULL, the array has unspecified length,
12418 but it does have a lower bound. This happens with Fortran
12420 Since the debugger is definitely going to need to know N
12421 to produce useful results, go ahead and output the lower
12422 bound solo, and hope the debugger can cope. */
12424 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12426 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12429 /* Otherwise we have an array type with an unspecified length. The
12430 DWARF-2 spec does not say how to handle this; let's just leave out the
12436 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12440 switch (TREE_CODE (tree_node))
12445 case ENUMERAL_TYPE:
12448 case QUAL_UNION_TYPE:
12449 size = int_size_in_bytes (tree_node);
12452 /* For a data member of a struct or union, the DW_AT_byte_size is
12453 generally given as the number of bytes normally allocated for an
12454 object of the *declared* type of the member itself. This is true
12455 even for bit-fields. */
12456 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12459 gcc_unreachable ();
12462 /* Note that `size' might be -1 when we get to this point. If it is, that
12463 indicates that the byte size of the entity in question is variable. We
12464 have no good way of expressing this fact in Dwarf at the present time,
12465 so just let the -1 pass on through. */
12466 add_AT_unsigned (die, DW_AT_byte_size, size);
12469 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12470 which specifies the distance in bits from the highest order bit of the
12471 "containing object" for the bit-field to the highest order bit of the
12474 For any given bit-field, the "containing object" is a hypothetical object
12475 (of some integral or enum type) within which the given bit-field lives. The
12476 type of this hypothetical "containing object" is always the same as the
12477 declared type of the individual bit-field itself. The determination of the
12478 exact location of the "containing object" for a bit-field is rather
12479 complicated. It's handled by the `field_byte_offset' function (above).
12481 Note that it is the size (in bytes) of the hypothetical "containing object"
12482 which will be given in the DW_AT_byte_size attribute for this bit-field.
12483 (See `byte_size_attribute' above). */
12486 add_bit_offset_attribute (dw_die_ref die, tree decl)
12488 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12489 tree type = DECL_BIT_FIELD_TYPE (decl);
12490 HOST_WIDE_INT bitpos_int;
12491 HOST_WIDE_INT highest_order_object_bit_offset;
12492 HOST_WIDE_INT highest_order_field_bit_offset;
12493 HOST_WIDE_INT unsigned bit_offset;
12495 /* Must be a field and a bit field. */
12496 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12498 /* We can't yet handle bit-fields whose offsets are variable, so if we
12499 encounter such things, just return without generating any attribute
12500 whatsoever. Likewise for variable or too large size. */
12501 if (! host_integerp (bit_position (decl), 0)
12502 || ! host_integerp (DECL_SIZE (decl), 1))
12505 bitpos_int = int_bit_position (decl);
12507 /* Note that the bit offset is always the distance (in bits) from the
12508 highest-order bit of the "containing object" to the highest-order bit of
12509 the bit-field itself. Since the "high-order end" of any object or field
12510 is different on big-endian and little-endian machines, the computation
12511 below must take account of these differences. */
12512 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12513 highest_order_field_bit_offset = bitpos_int;
12515 if (! BYTES_BIG_ENDIAN)
12517 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12518 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12522 = (! BYTES_BIG_ENDIAN
12523 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12524 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12526 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12529 /* For a FIELD_DECL node which represents a bit field, output an attribute
12530 which specifies the length in bits of the given field. */
12533 add_bit_size_attribute (dw_die_ref die, tree decl)
12535 /* Must be a field and a bit field. */
12536 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12537 && DECL_BIT_FIELD_TYPE (decl));
12539 if (host_integerp (DECL_SIZE (decl), 1))
12540 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12543 /* If the compiled language is ANSI C, then add a 'prototyped'
12544 attribute, if arg types are given for the parameters of a function. */
12547 add_prototyped_attribute (dw_die_ref die, tree func_type)
12549 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12550 && TYPE_ARG_TYPES (func_type) != NULL)
12551 add_AT_flag (die, DW_AT_prototyped, 1);
12554 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12555 by looking in either the type declaration or object declaration
12558 static inline dw_die_ref
12559 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12561 dw_die_ref origin_die = NULL;
12563 if (TREE_CODE (origin) != FUNCTION_DECL)
12565 /* We may have gotten separated from the block for the inlined
12566 function, if we're in an exception handler or some such; make
12567 sure that the abstract function has been written out.
12569 Doing this for nested functions is wrong, however; functions are
12570 distinct units, and our context might not even be inline. */
12574 fn = TYPE_STUB_DECL (fn);
12576 fn = decl_function_context (fn);
12578 dwarf2out_abstract_function (fn);
12581 if (DECL_P (origin))
12582 origin_die = lookup_decl_die (origin);
12583 else if (TYPE_P (origin))
12584 origin_die = lookup_type_die (origin);
12586 /* XXX: Functions that are never lowered don't always have correct block
12587 trees (in the case of java, they simply have no block tree, in some other
12588 languages). For these functions, there is nothing we can really do to
12589 output correct debug info for inlined functions in all cases. Rather
12590 than die, we'll just produce deficient debug info now, in that we will
12591 have variables without a proper abstract origin. In the future, when all
12592 functions are lowered, we should re-add a gcc_assert (origin_die)
12596 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12600 /* We do not currently support the pure_virtual attribute. */
12603 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12605 if (DECL_VINDEX (func_decl))
12607 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12609 if (host_integerp (DECL_VINDEX (func_decl), 0))
12610 add_AT_loc (die, DW_AT_vtable_elem_location,
12611 new_loc_descr (DW_OP_constu,
12612 tree_low_cst (DECL_VINDEX (func_decl), 0),
12615 /* GNU extension: Record what type this method came from originally. */
12616 if (debug_info_level > DINFO_LEVEL_TERSE)
12617 add_AT_die_ref (die, DW_AT_containing_type,
12618 lookup_type_die (DECL_CONTEXT (func_decl)));
12622 /* Add source coordinate attributes for the given decl. */
12625 add_src_coords_attributes (dw_die_ref die, tree decl)
12627 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12629 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12630 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12633 /* Add a DW_AT_name attribute and source coordinate attribute for the
12634 given decl, but only if it actually has a name. */
12637 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12641 decl_name = DECL_NAME (decl);
12642 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12644 add_name_attribute (die, dwarf2_name (decl, 0));
12645 if (! DECL_ARTIFICIAL (decl))
12646 add_src_coords_attributes (die, decl);
12648 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12649 && TREE_PUBLIC (decl)
12650 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
12651 && !DECL_ABSTRACT (decl)
12652 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12654 add_AT_string (die, DW_AT_MIPS_linkage_name,
12655 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
12658 #ifdef VMS_DEBUGGING_INFO
12659 /* Get the function's name, as described by its RTL. This may be different
12660 from the DECL_NAME name used in the source file. */
12661 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
12663 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
12664 XEXP (DECL_RTL (decl), 0));
12665 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
12670 /* Push a new declaration scope. */
12673 push_decl_scope (tree scope)
12675 VEC_safe_push (tree, gc, decl_scope_table, scope);
12678 /* Pop a declaration scope. */
12681 pop_decl_scope (void)
12683 VEC_pop (tree, decl_scope_table);
12686 /* Return the DIE for the scope that immediately contains this type.
12687 Non-named types get global scope. Named types nested in other
12688 types get their containing scope if it's open, or global scope
12689 otherwise. All other types (i.e. function-local named types) get
12690 the current active scope. */
12693 scope_die_for (tree t, dw_die_ref context_die)
12695 dw_die_ref scope_die = NULL;
12696 tree containing_scope;
12699 /* Non-types always go in the current scope. */
12700 gcc_assert (TYPE_P (t));
12702 containing_scope = TYPE_CONTEXT (t);
12704 /* Use the containing namespace if it was passed in (for a declaration). */
12705 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
12707 if (context_die == lookup_decl_die (containing_scope))
12710 containing_scope = NULL_TREE;
12713 /* Ignore function type "scopes" from the C frontend. They mean that
12714 a tagged type is local to a parmlist of a function declarator, but
12715 that isn't useful to DWARF. */
12716 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
12717 containing_scope = NULL_TREE;
12719 if (containing_scope == NULL_TREE)
12720 scope_die = comp_unit_die;
12721 else if (TYPE_P (containing_scope))
12723 /* For types, we can just look up the appropriate DIE. But
12724 first we check to see if we're in the middle of emitting it
12725 so we know where the new DIE should go. */
12726 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12727 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12732 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12733 || TREE_ASM_WRITTEN (containing_scope));
12735 /* If none of the current dies are suitable, we get file scope. */
12736 scope_die = comp_unit_die;
12739 scope_die = lookup_type_die (containing_scope);
12742 scope_die = context_die;
12747 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12750 local_scope_p (dw_die_ref context_die)
12752 for (; context_die; context_die = context_die->die_parent)
12753 if (context_die->die_tag == DW_TAG_inlined_subroutine
12754 || context_die->die_tag == DW_TAG_subprogram)
12760 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12761 whether or not to treat a DIE in this context as a declaration. */
12764 class_or_namespace_scope_p (dw_die_ref context_die)
12766 return (context_die
12767 && (context_die->die_tag == DW_TAG_structure_type
12768 || context_die->die_tag == DW_TAG_class_type
12769 || context_die->die_tag == DW_TAG_interface_type
12770 || context_die->die_tag == DW_TAG_union_type
12771 || context_die->die_tag == DW_TAG_namespace));
12774 /* Many forms of DIEs require a "type description" attribute. This
12775 routine locates the proper "type descriptor" die for the type given
12776 by 'type', and adds a DW_AT_type attribute below the given die. */
12779 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
12780 int decl_volatile, dw_die_ref context_die)
12782 enum tree_code code = TREE_CODE (type);
12783 dw_die_ref type_die = NULL;
12785 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12786 or fixed-point type, use the inner type. This is because we have no
12787 support for unnamed types in base_type_die. This can happen if this is
12788 an Ada subrange type. Correct solution is emit a subrange type die. */
12789 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
12790 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
12791 type = TREE_TYPE (type), code = TREE_CODE (type);
12793 if (code == ERROR_MARK
12794 /* Handle a special case. For functions whose return type is void, we
12795 generate *no* type attribute. (Note that no object may have type
12796 `void', so this only applies to function return types). */
12797 || code == VOID_TYPE)
12800 type_die = modified_type_die (type,
12801 decl_const || TYPE_READONLY (type),
12802 decl_volatile || TYPE_VOLATILE (type),
12805 if (type_die != NULL)
12806 add_AT_die_ref (object_die, DW_AT_type, type_die);
12809 /* Given an object die, add the calling convention attribute for the
12810 function call type. */
12812 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
12814 enum dwarf_calling_convention value = DW_CC_normal;
12816 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
12818 /* DWARF doesn't provide a way to identify a program's source-level
12819 entry point. DW_AT_calling_convention attributes are only meant
12820 to describe functions' calling conventions. However, lacking a
12821 better way to signal the Fortran main program, we use this for the
12822 time being, following existing custom. */
12824 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
12825 value = DW_CC_program;
12827 /* Only add the attribute if the backend requests it, and
12828 is not DW_CC_normal. */
12829 if (value && (value != DW_CC_normal))
12830 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
12833 /* Given a tree pointer to a struct, class, union, or enum type node, return
12834 a pointer to the (string) tag name for the given type, or zero if the type
12835 was declared without a tag. */
12837 static const char *
12838 type_tag (const_tree type)
12840 const char *name = 0;
12842 if (TYPE_NAME (type) != 0)
12846 /* Find the IDENTIFIER_NODE for the type name. */
12847 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
12848 t = TYPE_NAME (type);
12850 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12851 a TYPE_DECL node, regardless of whether or not a `typedef' was
12853 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12854 && ! DECL_IGNORED_P (TYPE_NAME (type)))
12856 /* We want to be extra verbose. Don't call dwarf_name if
12857 DECL_NAME isn't set. The default hook for decl_printable_name
12858 doesn't like that, and in this context it's correct to return
12859 0, instead of "<anonymous>" or the like. */
12860 if (DECL_NAME (TYPE_NAME (type)))
12861 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
12864 /* Now get the name as a string, or invent one. */
12865 if (!name && t != 0)
12866 name = IDENTIFIER_POINTER (t);
12869 return (name == 0 || *name == '\0') ? 0 : name;
12872 /* Return the type associated with a data member, make a special check
12873 for bit field types. */
12876 member_declared_type (const_tree member)
12878 return (DECL_BIT_FIELD_TYPE (member)
12879 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
12882 /* Get the decl's label, as described by its RTL. This may be different
12883 from the DECL_NAME name used in the source file. */
12886 static const char *
12887 decl_start_label (tree decl)
12890 const char *fnname;
12892 x = DECL_RTL (decl);
12893 gcc_assert (MEM_P (x));
12896 gcc_assert (GET_CODE (x) == SYMBOL_REF);
12898 fnname = XSTR (x, 0);
12903 /* These routines generate the internal representation of the DIE's for
12904 the compilation unit. Debugging information is collected by walking
12905 the declaration trees passed in from dwarf2out_decl(). */
12908 gen_array_type_die (tree type, dw_die_ref context_die)
12910 dw_die_ref scope_die = scope_die_for (type, context_die);
12911 dw_die_ref array_die;
12913 /* GNU compilers represent multidimensional array types as sequences of one
12914 dimensional array types whose element types are themselves array types.
12915 We sometimes squish that down to a single array_type DIE with multiple
12916 subscripts in the Dwarf debugging info. The draft Dwarf specification
12917 say that we are allowed to do this kind of compression in C, because
12918 there is no difference between an array of arrays and a multidimensional
12919 array. We don't do this for Ada to remain as close as possible to the
12920 actual representation, which is especially important against the language
12921 flexibilty wrt arrays of variable size. */
12923 bool collapse_nested_arrays = !is_ada ();
12926 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
12927 DW_TAG_string_type doesn't have DW_AT_type attribute). */
12928 if (TYPE_STRING_FLAG (type)
12929 && TREE_CODE (type) == ARRAY_TYPE
12931 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
12933 HOST_WIDE_INT size;
12935 array_die = new_die (DW_TAG_string_type, scope_die, type);
12936 add_name_attribute (array_die, type_tag (type));
12937 equate_type_number_to_die (type, array_die);
12938 size = int_size_in_bytes (type);
12940 add_AT_unsigned (array_die, DW_AT_byte_size, size);
12941 else if (TYPE_DOMAIN (type) != NULL_TREE
12942 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
12943 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
12945 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
12946 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
12948 size = int_size_in_bytes (TREE_TYPE (szdecl));
12949 if (loc && size > 0)
12951 add_AT_loc (array_die, DW_AT_string_length, loc);
12952 if (size != DWARF2_ADDR_SIZE)
12953 add_AT_unsigned (array_die, DW_AT_byte_size, size);
12959 /* ??? The SGI dwarf reader fails for array of array of enum types
12960 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12961 array type comes before the outer array type. We thus call gen_type_die
12962 before we new_die and must prevent nested array types collapsing for this
12965 #ifdef MIPS_DEBUGGING_INFO
12966 gen_type_die (TREE_TYPE (type), context_die);
12967 collapse_nested_arrays = false;
12970 array_die = new_die (DW_TAG_array_type, scope_die, type);
12971 add_name_attribute (array_die, type_tag (type));
12972 equate_type_number_to_die (type, array_die);
12974 if (TREE_CODE (type) == VECTOR_TYPE)
12976 /* The frontend feeds us a representation for the vector as a struct
12977 containing an array. Pull out the array type. */
12978 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
12979 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
12982 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12984 && TREE_CODE (type) == ARRAY_TYPE
12985 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
12986 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
12987 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12990 /* We default the array ordering. SDB will probably do
12991 the right things even if DW_AT_ordering is not present. It's not even
12992 an issue until we start to get into multidimensional arrays anyway. If
12993 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12994 then we'll have to put the DW_AT_ordering attribute back in. (But if
12995 and when we find out that we need to put these in, we will only do so
12996 for multidimensional arrays. */
12997 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
13000 #ifdef MIPS_DEBUGGING_INFO
13001 /* The SGI compilers handle arrays of unknown bound by setting
13002 AT_declaration and not emitting any subrange DIEs. */
13003 if (! TYPE_DOMAIN (type))
13004 add_AT_flag (array_die, DW_AT_declaration, 1);
13007 add_subscript_info (array_die, type, collapse_nested_arrays);
13009 /* Add representation of the type of the elements of this array type and
13010 emit the corresponding DIE if we haven't done it already. */
13011 element_type = TREE_TYPE (type);
13012 if (collapse_nested_arrays)
13013 while (TREE_CODE (element_type) == ARRAY_TYPE)
13015 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
13017 element_type = TREE_TYPE (element_type);
13020 #ifndef MIPS_DEBUGGING_INFO
13021 gen_type_die (element_type, context_die);
13024 add_type_attribute (array_die, element_type, 0, 0, context_die);
13026 if (get_AT (array_die, DW_AT_name))
13027 add_pubtype (type, array_die);
13030 static dw_loc_descr_ref
13031 descr_info_loc (tree val, tree base_decl)
13033 HOST_WIDE_INT size;
13034 dw_loc_descr_ref loc, loc2;
13035 enum dwarf_location_atom op;
13037 if (val == base_decl)
13038 return new_loc_descr (DW_OP_push_object_address, 0, 0);
13040 switch (TREE_CODE (val))
13043 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13045 return loc_descriptor_from_tree_1 (val, 0);
13047 if (host_integerp (val, 0))
13048 return int_loc_descriptor (tree_low_cst (val, 0));
13051 size = int_size_in_bytes (TREE_TYPE (val));
13054 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13057 if (size == DWARF2_ADDR_SIZE)
13058 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
13060 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
13062 case POINTER_PLUS_EXPR:
13064 if (host_integerp (TREE_OPERAND (val, 1), 1)
13065 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
13068 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13071 add_loc_descr (&loc,
13072 new_loc_descr (DW_OP_plus_uconst,
13073 tree_low_cst (TREE_OPERAND (val, 1),
13080 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13083 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
13086 add_loc_descr (&loc, loc2);
13087 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
13109 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
13110 tree val, tree base_decl)
13112 dw_loc_descr_ref loc;
13114 if (host_integerp (val, 0))
13116 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
13120 loc = descr_info_loc (val, base_decl);
13124 add_AT_loc (die, attr, loc);
13127 /* This routine generates DIE for array with hidden descriptor, details
13128 are filled into *info by a langhook. */
13131 gen_descr_array_type_die (tree type, struct array_descr_info *info,
13132 dw_die_ref context_die)
13134 dw_die_ref scope_die = scope_die_for (type, context_die);
13135 dw_die_ref array_die;
13138 array_die = new_die (DW_TAG_array_type, scope_die, type);
13139 add_name_attribute (array_die, type_tag (type));
13140 equate_type_number_to_die (type, array_die);
13142 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13144 && info->ndimensions >= 2)
13145 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13147 if (info->data_location)
13148 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
13150 if (info->associated)
13151 add_descr_info_field (array_die, DW_AT_associated, info->associated,
13153 if (info->allocated)
13154 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
13157 for (dim = 0; dim < info->ndimensions; dim++)
13159 dw_die_ref subrange_die
13160 = new_die (DW_TAG_subrange_type, array_die, NULL);
13162 if (info->dimen[dim].lower_bound)
13164 /* If it is the default value, omit it. */
13165 if ((is_c_family () || is_java ())
13166 && integer_zerop (info->dimen[dim].lower_bound))
13168 else if (is_fortran ()
13169 && integer_onep (info->dimen[dim].lower_bound))
13172 add_descr_info_field (subrange_die, DW_AT_lower_bound,
13173 info->dimen[dim].lower_bound,
13176 if (info->dimen[dim].upper_bound)
13177 add_descr_info_field (subrange_die, DW_AT_upper_bound,
13178 info->dimen[dim].upper_bound,
13180 if (info->dimen[dim].stride)
13181 add_descr_info_field (subrange_die, DW_AT_byte_stride,
13182 info->dimen[dim].stride,
13186 gen_type_die (info->element_type, context_die);
13187 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
13189 if (get_AT (array_die, DW_AT_name))
13190 add_pubtype (type, array_die);
13195 gen_entry_point_die (tree decl, dw_die_ref context_die)
13197 tree origin = decl_ultimate_origin (decl);
13198 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
13200 if (origin != NULL)
13201 add_abstract_origin_attribute (decl_die, origin);
13204 add_name_and_src_coords_attributes (decl_die, decl);
13205 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
13206 0, 0, context_die);
13209 if (DECL_ABSTRACT (decl))
13210 equate_decl_number_to_die (decl, decl_die);
13212 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
13216 /* Walk through the list of incomplete types again, trying once more to
13217 emit full debugging info for them. */
13220 retry_incomplete_types (void)
13224 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
13225 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
13226 DINFO_USAGE_DIR_USE))
13227 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
13230 /* Determine what tag to use for a record type. */
13232 static enum dwarf_tag
13233 record_type_tag (tree type)
13235 if (! lang_hooks.types.classify_record)
13236 return DW_TAG_structure_type;
13238 switch (lang_hooks.types.classify_record (type))
13240 case RECORD_IS_STRUCT:
13241 return DW_TAG_structure_type;
13243 case RECORD_IS_CLASS:
13244 return DW_TAG_class_type;
13246 case RECORD_IS_INTERFACE:
13247 return DW_TAG_interface_type;
13250 gcc_unreachable ();
13254 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13255 include all of the information about the enumeration values also. Each
13256 enumerated type name/value is listed as a child of the enumerated type
13260 gen_enumeration_type_die (tree type, dw_die_ref context_die)
13262 dw_die_ref type_die = lookup_type_die (type);
13264 if (type_die == NULL)
13266 type_die = new_die (DW_TAG_enumeration_type,
13267 scope_die_for (type, context_die), type);
13268 equate_type_number_to_die (type, type_die);
13269 add_name_attribute (type_die, type_tag (type));
13271 else if (! TYPE_SIZE (type))
13274 remove_AT (type_die, DW_AT_declaration);
13276 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13277 given enum type is incomplete, do not generate the DW_AT_byte_size
13278 attribute or the DW_AT_element_list attribute. */
13279 if (TYPE_SIZE (type))
13283 TREE_ASM_WRITTEN (type) = 1;
13284 add_byte_size_attribute (type_die, type);
13285 if (TYPE_STUB_DECL (type) != NULL_TREE)
13286 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13288 /* If the first reference to this type was as the return type of an
13289 inline function, then it may not have a parent. Fix this now. */
13290 if (type_die->die_parent == NULL)
13291 add_child_die (scope_die_for (type, context_die), type_die);
13293 for (link = TYPE_VALUES (type);
13294 link != NULL; link = TREE_CHAIN (link))
13296 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
13297 tree value = TREE_VALUE (link);
13299 add_name_attribute (enum_die,
13300 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
13302 if (TREE_CODE (value) == CONST_DECL)
13303 value = DECL_INITIAL (value);
13305 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
13306 /* DWARF2 does not provide a way of indicating whether or
13307 not enumeration constants are signed or unsigned. GDB
13308 always assumes the values are signed, so we output all
13309 values as if they were signed. That means that
13310 enumeration constants with very large unsigned values
13311 will appear to have negative values in the debugger. */
13312 add_AT_int (enum_die, DW_AT_const_value,
13313 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
13317 add_AT_flag (type_die, DW_AT_declaration, 1);
13319 if (get_AT (type_die, DW_AT_name))
13320 add_pubtype (type, type_die);
13325 /* Generate a DIE to represent either a real live formal parameter decl or to
13326 represent just the type of some formal parameter position in some function
13329 Note that this routine is a bit unusual because its argument may be a
13330 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13331 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13332 node. If it's the former then this function is being called to output a
13333 DIE to represent a formal parameter object (or some inlining thereof). If
13334 it's the latter, then this function is only being called to output a
13335 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13336 argument type of some subprogram type. */
13339 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
13341 tree node_or_origin = node ? node : origin;
13342 dw_die_ref parm_die
13343 = new_die (DW_TAG_formal_parameter, context_die, node);
13345 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
13347 case tcc_declaration:
13349 origin = decl_ultimate_origin (node);
13350 if (origin != NULL)
13351 add_abstract_origin_attribute (parm_die, origin);
13354 tree type = TREE_TYPE (node);
13355 add_name_and_src_coords_attributes (parm_die, node);
13356 if (DECL_BY_REFERENCE (node))
13357 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
13360 add_type_attribute (parm_die, type,
13361 TREE_READONLY (node),
13362 TREE_THIS_VOLATILE (node),
13364 if (DECL_ARTIFICIAL (node))
13365 add_AT_flag (parm_die, DW_AT_artificial, 1);
13369 equate_decl_number_to_die (node, parm_die);
13370 if (! DECL_ABSTRACT (node_or_origin))
13371 add_location_or_const_value_attribute (parm_die, node_or_origin,
13377 /* We were called with some kind of a ..._TYPE node. */
13378 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
13382 gcc_unreachable ();
13388 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13389 at the end of an (ANSI prototyped) formal parameters list. */
13392 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
13394 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
13397 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13398 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13399 parameters as specified in some function type specification (except for
13400 those which appear as part of a function *definition*). */
13403 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13406 tree formal_type = NULL;
13407 tree first_parm_type;
13410 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13412 arg = DECL_ARGUMENTS (function_or_method_type);
13413 function_or_method_type = TREE_TYPE (function_or_method_type);
13418 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13420 /* Make our first pass over the list of formal parameter types and output a
13421 DW_TAG_formal_parameter DIE for each one. */
13422 for (link = first_parm_type; link; )
13424 dw_die_ref parm_die;
13426 formal_type = TREE_VALUE (link);
13427 if (formal_type == void_type_node)
13430 /* Output a (nameless) DIE to represent the formal parameter itself. */
13431 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
13432 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13433 && link == first_parm_type)
13434 || (arg && DECL_ARTIFICIAL (arg)))
13435 add_AT_flag (parm_die, DW_AT_artificial, 1);
13437 link = TREE_CHAIN (link);
13439 arg = TREE_CHAIN (arg);
13442 /* If this function type has an ellipsis, add a
13443 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13444 if (formal_type != void_type_node)
13445 gen_unspecified_parameters_die (function_or_method_type, context_die);
13447 /* Make our second (and final) pass over the list of formal parameter types
13448 and output DIEs to represent those types (as necessary). */
13449 for (link = TYPE_ARG_TYPES (function_or_method_type);
13450 link && TREE_VALUE (link);
13451 link = TREE_CHAIN (link))
13452 gen_type_die (TREE_VALUE (link), context_die);
13455 /* We want to generate the DIE for TYPE so that we can generate the
13456 die for MEMBER, which has been defined; we will need to refer back
13457 to the member declaration nested within TYPE. If we're trying to
13458 generate minimal debug info for TYPE, processing TYPE won't do the
13459 trick; we need to attach the member declaration by hand. */
13462 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13464 gen_type_die (type, context_die);
13466 /* If we're trying to avoid duplicate debug info, we may not have
13467 emitted the member decl for this function. Emit it now. */
13468 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13469 && ! lookup_decl_die (member))
13471 dw_die_ref type_die;
13472 gcc_assert (!decl_ultimate_origin (member));
13474 push_decl_scope (type);
13475 type_die = lookup_type_die (type);
13476 if (TREE_CODE (member) == FUNCTION_DECL)
13477 gen_subprogram_die (member, type_die);
13478 else if (TREE_CODE (member) == FIELD_DECL)
13480 /* Ignore the nameless fields that are used to skip bits but handle
13481 C++ anonymous unions and structs. */
13482 if (DECL_NAME (member) != NULL_TREE
13483 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13484 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13486 gen_type_die (member_declared_type (member), type_die);
13487 gen_field_die (member, type_die);
13491 gen_variable_die (member, NULL_TREE, type_die);
13497 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13498 may later generate inlined and/or out-of-line instances of. */
13501 dwarf2out_abstract_function (tree decl)
13503 dw_die_ref old_die;
13506 int was_abstract = DECL_ABSTRACT (decl);
13508 /* Make sure we have the actual abstract inline, not a clone. */
13509 decl = DECL_ORIGIN (decl);
13511 old_die = lookup_decl_die (decl);
13512 if (old_die && get_AT (old_die, DW_AT_inline))
13513 /* We've already generated the abstract instance. */
13516 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13517 we don't get confused by DECL_ABSTRACT. */
13518 if (debug_info_level > DINFO_LEVEL_TERSE)
13520 context = decl_class_context (decl);
13522 gen_type_die_for_member
13523 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13526 /* Pretend we've just finished compiling this function. */
13527 save_fn = current_function_decl;
13528 current_function_decl = decl;
13529 push_cfun (DECL_STRUCT_FUNCTION (decl));
13531 set_decl_abstract_flags (decl, 1);
13532 dwarf2out_decl (decl);
13533 if (! was_abstract)
13534 set_decl_abstract_flags (decl, 0);
13536 current_function_decl = save_fn;
13540 /* Helper function of premark_used_types() which gets called through
13543 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13544 marked as unused by prune_unused_types. */
13547 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13552 type = (tree) *slot;
13553 die = lookup_type_die (type);
13555 die->die_perennial_p = 1;
13559 /* Helper function of premark_types_used_by_global_vars which gets called
13560 through htab_traverse.
13562 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13563 marked as unused by prune_unused_types. The DIE of the type is marked
13564 only if the global variable using the type will actually be emitted. */
13567 premark_types_used_by_global_vars_helper (void **slot,
13568 void *data ATTRIBUTE_UNUSED)
13570 struct types_used_by_vars_entry *entry;
13573 entry = (struct types_used_by_vars_entry *) *slot;
13574 gcc_assert (entry->type != NULL
13575 && entry->var_decl != NULL);
13576 die = lookup_type_die (entry->type);
13579 /* Ask cgraph if the global variable really is to be emitted.
13580 If yes, then we'll keep the DIE of ENTRY->TYPE. */
13581 struct varpool_node *node = varpool_node (entry->var_decl);
13584 die->die_perennial_p = 1;
13585 /* Keep the parent DIEs as well. */
13586 while ((die = die->die_parent) && die->die_perennial_p == 0)
13587 die->die_perennial_p = 1;
13593 /* Mark all members of used_types_hash as perennial. */
13596 premark_used_types (void)
13598 if (cfun && cfun->used_types_hash)
13599 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13602 /* Mark all members of types_used_by_vars_entry as perennial. */
13605 premark_types_used_by_global_vars (void)
13607 if (types_used_by_vars_hash)
13608 htab_traverse (types_used_by_vars_hash,
13609 premark_types_used_by_global_vars_helper, NULL);
13612 /* Generate a DIE to represent a declared function (either file-scope or
13616 gen_subprogram_die (tree decl, dw_die_ref context_die)
13618 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13619 tree origin = decl_ultimate_origin (decl);
13620 dw_die_ref subr_die;
13623 dw_die_ref old_die = lookup_decl_die (decl);
13624 int declaration = (current_function_decl != decl
13625 || class_or_namespace_scope_p (context_die));
13627 premark_used_types ();
13629 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13630 started to generate the abstract instance of an inline, decided to output
13631 its containing class, and proceeded to emit the declaration of the inline
13632 from the member list for the class. If so, DECLARATION takes priority;
13633 we'll get back to the abstract instance when done with the class. */
13635 /* The class-scope declaration DIE must be the primary DIE. */
13636 if (origin && declaration && class_or_namespace_scope_p (context_die))
13639 gcc_assert (!old_die);
13642 /* Now that the C++ front end lazily declares artificial member fns, we
13643 might need to retrofit the declaration into its class. */
13644 if (!declaration && !origin && !old_die
13645 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13646 && !class_or_namespace_scope_p (context_die)
13647 && debug_info_level > DINFO_LEVEL_TERSE)
13648 old_die = force_decl_die (decl);
13650 if (origin != NULL)
13652 gcc_assert (!declaration || local_scope_p (context_die));
13654 /* Fixup die_parent for the abstract instance of a nested
13655 inline function. */
13656 if (old_die && old_die->die_parent == NULL)
13657 add_child_die (context_die, old_die);
13659 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13660 add_abstract_origin_attribute (subr_die, origin);
13664 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13665 struct dwarf_file_data * file_index = lookup_filename (s.file);
13667 if (!get_AT_flag (old_die, DW_AT_declaration)
13668 /* We can have a normal definition following an inline one in the
13669 case of redefinition of GNU C extern inlines.
13670 It seems reasonable to use AT_specification in this case. */
13671 && !get_AT (old_die, DW_AT_inline))
13673 /* Detect and ignore this case, where we are trying to output
13674 something we have already output. */
13678 /* If the definition comes from the same place as the declaration,
13679 maybe use the old DIE. We always want the DIE for this function
13680 that has the *_pc attributes to be under comp_unit_die so the
13681 debugger can find it. We also need to do this for abstract
13682 instances of inlines, since the spec requires the out-of-line copy
13683 to have the same parent. For local class methods, this doesn't
13684 apply; we just use the old DIE. */
13685 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13686 && (DECL_ARTIFICIAL (decl)
13687 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13688 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13689 == (unsigned) s.line))))
13691 subr_die = old_die;
13693 /* Clear out the declaration attribute and the formal parameters.
13694 Do not remove all children, because it is possible that this
13695 declaration die was forced using force_decl_die(). In such
13696 cases die that forced declaration die (e.g. TAG_imported_module)
13697 is one of the children that we do not want to remove. */
13698 remove_AT (subr_die, DW_AT_declaration);
13699 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
13703 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13704 add_AT_specification (subr_die, old_die);
13705 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13706 add_AT_file (subr_die, DW_AT_decl_file, file_index);
13707 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13708 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
13713 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13715 if (TREE_PUBLIC (decl))
13716 add_AT_flag (subr_die, DW_AT_external, 1);
13718 add_name_and_src_coords_attributes (subr_die, decl);
13719 if (debug_info_level > DINFO_LEVEL_TERSE)
13721 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
13722 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
13723 0, 0, context_die);
13726 add_pure_or_virtual_attribute (subr_die, decl);
13727 if (DECL_ARTIFICIAL (decl))
13728 add_AT_flag (subr_die, DW_AT_artificial, 1);
13730 if (TREE_PROTECTED (decl))
13731 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
13732 else if (TREE_PRIVATE (decl))
13733 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
13738 if (!old_die || !get_AT (old_die, DW_AT_inline))
13740 add_AT_flag (subr_die, DW_AT_declaration, 1);
13742 /* The first time we see a member function, it is in the context of
13743 the class to which it belongs. We make sure of this by emitting
13744 the class first. The next time is the definition, which is
13745 handled above. The two may come from the same source text.
13747 Note that force_decl_die() forces function declaration die. It is
13748 later reused to represent definition. */
13749 equate_decl_number_to_die (decl, subr_die);
13752 else if (DECL_ABSTRACT (decl))
13754 if (DECL_DECLARED_INLINE_P (decl))
13756 if (cgraph_function_possibly_inlined_p (decl))
13757 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
13759 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
13763 if (cgraph_function_possibly_inlined_p (decl))
13764 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
13766 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
13769 if (DECL_DECLARED_INLINE_P (decl)
13770 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
13771 add_AT_flag (subr_die, DW_AT_artificial, 1);
13773 equate_decl_number_to_die (decl, subr_die);
13775 else if (!DECL_EXTERNAL (decl))
13777 HOST_WIDE_INT cfa_fb_offset;
13779 if (!old_die || !get_AT (old_die, DW_AT_inline))
13780 equate_decl_number_to_die (decl, subr_die);
13782 if (!flag_reorder_blocks_and_partition)
13784 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13785 current_function_funcdef_no);
13786 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13787 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13788 current_function_funcdef_no);
13789 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13791 add_pubname (decl, subr_die);
13792 add_arange (decl, subr_die);
13795 { /* Do nothing for now; maybe need to duplicate die, one for
13796 hot section and one for cold section, then use the hot/cold
13797 section begin/end labels to generate the aranges... */
13799 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13800 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13801 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13802 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13804 add_pubname (decl, subr_die);
13805 add_arange (decl, subr_die);
13806 add_arange (decl, subr_die);
13810 #ifdef MIPS_DEBUGGING_INFO
13811 /* Add a reference to the FDE for this routine. */
13812 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13815 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13817 /* We define the "frame base" as the function's CFA. This is more
13818 convenient for several reasons: (1) It's stable across the prologue
13819 and epilogue, which makes it better than just a frame pointer,
13820 (2) With dwarf3, there exists a one-byte encoding that allows us
13821 to reference the .debug_frame data by proxy, but failing that,
13822 (3) We can at least reuse the code inspection and interpretation
13823 code that determines the CFA position at various points in the
13825 /* ??? Use some command-line or configury switch to enable the use
13826 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13827 consumers that understand it; fall back to "pure" dwarf2 and
13828 convert the CFA data into a location list. */
13830 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
13831 if (list->dw_loc_next)
13832 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
13834 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
13837 /* Compute a displacement from the "steady-state frame pointer" to
13838 the CFA. The former is what all stack slots and argument slots
13839 will reference in the rtl; the later is what we've told the
13840 debugger about. We'll need to adjust all frame_base references
13841 by this displacement. */
13842 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
13844 if (cfun->static_chain_decl)
13845 add_AT_location_description (subr_die, DW_AT_static_link,
13846 loc_descriptor_from_tree (cfun->static_chain_decl));
13849 /* Now output descriptions of the arguments for this function. This gets
13850 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13851 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13852 `...' at the end of the formal parameter list. In order to find out if
13853 there was a trailing ellipsis or not, we must instead look at the type
13854 associated with the FUNCTION_DECL. This will be a node of type
13855 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13856 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13857 an ellipsis at the end. */
13859 /* In the case where we are describing a mere function declaration, all we
13860 need to do here (and all we *can* do here) is to describe the *types* of
13861 its formal parameters. */
13862 if (debug_info_level <= DINFO_LEVEL_TERSE)
13864 else if (declaration)
13865 gen_formal_types_die (decl, subr_die);
13868 /* Generate DIEs to represent all known formal parameters. */
13869 tree arg_decls = DECL_ARGUMENTS (decl);
13872 /* When generating DIEs, generate the unspecified_parameters DIE
13873 instead if we come across the arg "__builtin_va_alist" */
13874 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
13875 if (TREE_CODE (parm) == PARM_DECL)
13877 if (DECL_NAME (parm)
13878 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
13879 "__builtin_va_alist"))
13880 gen_unspecified_parameters_die (parm, subr_die);
13882 gen_decl_die (parm, NULL, subr_die);
13885 /* Decide whether we need an unspecified_parameters DIE at the end.
13886 There are 2 more cases to do this for: 1) the ansi ... declaration -
13887 this is detectable when the end of the arg list is not a
13888 void_type_node 2) an unprototyped function declaration (not a
13889 definition). This just means that we have no info about the
13890 parameters at all. */
13891 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
13892 if (fn_arg_types != NULL)
13894 /* This is the prototyped case, check for.... */
13895 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
13896 gen_unspecified_parameters_die (decl, subr_die);
13898 else if (DECL_INITIAL (decl) == NULL_TREE)
13899 gen_unspecified_parameters_die (decl, subr_die);
13902 /* Output Dwarf info for all of the stuff within the body of the function
13903 (if it has one - it may be just a declaration). */
13904 outer_scope = DECL_INITIAL (decl);
13906 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13907 a function. This BLOCK actually represents the outermost binding contour
13908 for the function, i.e. the contour in which the function's formal
13909 parameters and labels get declared. Curiously, it appears that the front
13910 end doesn't actually put the PARM_DECL nodes for the current function onto
13911 the BLOCK_VARS list for this outer scope, but are strung off of the
13912 DECL_ARGUMENTS list for the function instead.
13914 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13915 the LABEL_DECL nodes for the function however, and we output DWARF info
13916 for those in decls_for_scope. Just within the `outer_scope' there will be
13917 a BLOCK node representing the function's outermost pair of curly braces,
13918 and any blocks used for the base and member initializers of a C++
13919 constructor function. */
13920 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
13922 /* Emit a DW_TAG_variable DIE for a named return value. */
13923 if (DECL_NAME (DECL_RESULT (decl)))
13924 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
13926 current_function_has_inlines = 0;
13927 decls_for_scope (outer_scope, subr_die, 0);
13929 #if 0 && defined (MIPS_DEBUGGING_INFO)
13930 if (current_function_has_inlines)
13932 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
13933 if (! comp_unit_has_inlines)
13935 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
13936 comp_unit_has_inlines = 1;
13941 /* Add the calling convention attribute if requested. */
13942 add_calling_convention_attribute (subr_die, decl);
13946 /* Returns a hash value for X (which really is a die_struct). */
13949 common_block_die_table_hash (const void *x)
13951 const_dw_die_ref d = (const_dw_die_ref) x;
13952 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
13955 /* Return nonzero if decl_id and die_parent of die_struct X is the same
13956 as decl_id and die_parent of die_struct Y. */
13959 common_block_die_table_eq (const void *x, const void *y)
13961 const_dw_die_ref d = (const_dw_die_ref) x;
13962 const_dw_die_ref e = (const_dw_die_ref) y;
13963 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
13966 /* Generate a DIE to represent a declared data object.
13967 Either DECL or ORIGIN must be non-null. */
13970 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
13974 tree decl_or_origin = decl ? decl : origin;
13975 dw_die_ref var_die;
13976 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
13977 dw_die_ref origin_die;
13978 int declaration = (DECL_EXTERNAL (decl_or_origin)
13979 /* If DECL is COMDAT and has not actually been
13980 emitted, we cannot take its address; there
13981 might end up being no definition anywhere in
13982 the program. For example, consider the C++
13986 struct S { static const int i = 7; };
13991 int f() { return S<int>::i; }
13993 Here, S<int>::i is not DECL_EXTERNAL, but no
13994 definition is required, so the compiler will
13995 not emit a definition. */
13996 || (TREE_CODE (decl_or_origin) == VAR_DECL
13997 && DECL_COMDAT (decl_or_origin)
13998 && !TREE_ASM_WRITTEN (decl_or_origin))
13999 || class_or_namespace_scope_p (context_die));
14002 origin = decl_ultimate_origin (decl);
14004 com_decl = fortran_common (decl_or_origin, &off);
14006 /* Symbol in common gets emitted as a child of the common block, in the form
14007 of a data member. */
14011 dw_die_ref com_die;
14012 dw_loc_descr_ref loc;
14013 die_node com_die_arg;
14015 var_die = lookup_decl_die (decl_or_origin);
14018 if (get_AT (var_die, DW_AT_location) == NULL)
14020 loc = loc_descriptor_from_tree (com_decl);
14025 /* Optimize the common case. */
14026 if (loc->dw_loc_opc == DW_OP_addr
14027 && loc->dw_loc_next == NULL
14028 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
14030 loc->dw_loc_oprnd1.v.val_addr
14031 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14033 add_loc_descr (&loc,
14034 new_loc_descr (DW_OP_plus_uconst,
14037 add_AT_loc (var_die, DW_AT_location, loc);
14038 remove_AT (var_die, DW_AT_declaration);
14044 if (common_block_die_table == NULL)
14045 common_block_die_table
14046 = htab_create_ggc (10, common_block_die_table_hash,
14047 common_block_die_table_eq, NULL);
14049 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
14050 com_die_arg.decl_id = DECL_UID (com_decl);
14051 com_die_arg.die_parent = context_die;
14052 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
14053 loc = loc_descriptor_from_tree (com_decl);
14054 if (com_die == NULL)
14057 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
14060 com_die = new_die (DW_TAG_common_block, context_die, decl);
14061 add_name_and_src_coords_attributes (com_die, com_decl);
14064 add_AT_loc (com_die, DW_AT_location, loc);
14065 /* Avoid sharing the same loc descriptor between
14066 DW_TAG_common_block and DW_TAG_variable. */
14067 loc = loc_descriptor_from_tree (com_decl);
14069 else if (DECL_EXTERNAL (decl))
14070 add_AT_flag (com_die, DW_AT_declaration, 1);
14071 add_pubname_string (cnam, com_die); /* ??? needed? */
14072 com_die->decl_id = DECL_UID (com_decl);
14073 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
14074 *slot = (void *) com_die;
14076 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
14078 add_AT_loc (com_die, DW_AT_location, loc);
14079 loc = loc_descriptor_from_tree (com_decl);
14080 remove_AT (com_die, DW_AT_declaration);
14082 var_die = new_die (DW_TAG_variable, com_die, decl);
14083 add_name_and_src_coords_attributes (var_die, decl);
14084 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
14085 TREE_THIS_VOLATILE (decl), context_die);
14086 add_AT_flag (var_die, DW_AT_external, 1);
14091 /* Optimize the common case. */
14092 if (loc->dw_loc_opc == DW_OP_addr
14093 && loc->dw_loc_next == NULL
14094 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
14095 loc->dw_loc_oprnd1.v.val_addr
14096 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14098 add_loc_descr (&loc, new_loc_descr (DW_OP_plus_uconst,
14101 add_AT_loc (var_die, DW_AT_location, loc);
14103 else if (DECL_EXTERNAL (decl))
14104 add_AT_flag (var_die, DW_AT_declaration, 1);
14105 equate_decl_number_to_die (decl, var_die);
14109 /* If the compiler emitted a definition for the DECL declaration
14110 and if we already emitted a DIE for it, don't emit a second
14111 DIE for it again. */
14114 && old_die->die_parent == context_die)
14117 var_die = new_die (DW_TAG_variable, context_die, decl);
14120 if (origin != NULL)
14121 origin_die = add_abstract_origin_attribute (var_die, origin);
14123 /* Loop unrolling can create multiple blocks that refer to the same
14124 static variable, so we must test for the DW_AT_declaration flag.
14126 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14127 copy decls and set the DECL_ABSTRACT flag on them instead of
14130 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14132 ??? The declare_in_namespace support causes us to get two DIEs for one
14133 variable, both of which are declarations. We want to avoid considering
14134 one to be a specification, so we must test that this DIE is not a
14136 else if (old_die && TREE_STATIC (decl) && ! declaration
14137 && get_AT_flag (old_die, DW_AT_declaration) == 1)
14139 /* This is a definition of a C++ class level static. */
14140 add_AT_specification (var_die, old_die);
14141 if (DECL_NAME (decl))
14143 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14144 struct dwarf_file_data * file_index = lookup_filename (s.file);
14146 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14147 add_AT_file (var_die, DW_AT_decl_file, file_index);
14149 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14150 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
14155 tree type = TREE_TYPE (decl);
14157 add_name_and_src_coords_attributes (var_die, decl);
14158 if ((TREE_CODE (decl) == PARM_DECL
14159 || TREE_CODE (decl) == RESULT_DECL)
14160 && DECL_BY_REFERENCE (decl))
14161 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
14163 add_type_attribute (var_die, type, TREE_READONLY (decl),
14164 TREE_THIS_VOLATILE (decl), context_die);
14166 if (TREE_PUBLIC (decl))
14167 add_AT_flag (var_die, DW_AT_external, 1);
14169 if (DECL_ARTIFICIAL (decl))
14170 add_AT_flag (var_die, DW_AT_artificial, 1);
14172 if (TREE_PROTECTED (decl))
14173 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
14174 else if (TREE_PRIVATE (decl))
14175 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
14179 add_AT_flag (var_die, DW_AT_declaration, 1);
14181 if (decl && (DECL_ABSTRACT (decl) || declaration))
14182 equate_decl_number_to_die (decl, var_die);
14185 && (! DECL_ABSTRACT (decl_or_origin)
14186 /* Local static vars are shared between all clones/inlines,
14187 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14189 || (TREE_CODE (decl_or_origin) == VAR_DECL
14190 && TREE_STATIC (decl_or_origin)
14191 && DECL_RTL_SET_P (decl_or_origin)))
14192 /* When abstract origin already has DW_AT_location attribute, no need
14193 to add it again. */
14194 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
14196 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
14197 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
14198 defer_location (decl_or_origin, var_die);
14200 add_location_or_const_value_attribute (var_die,
14203 add_pubname (decl_or_origin, var_die);
14206 tree_add_const_value_attribute (var_die, decl_or_origin);
14209 /* Generate a DIE to represent a named constant. */
14212 gen_const_die (tree decl, dw_die_ref context_die)
14214 dw_die_ref const_die;
14215 tree type = TREE_TYPE (decl);
14217 const_die = new_die (DW_TAG_constant, context_die, decl);
14218 add_name_and_src_coords_attributes (const_die, decl);
14219 add_type_attribute (const_die, type, 1, 0, context_die);
14220 if (TREE_PUBLIC (decl))
14221 add_AT_flag (const_die, DW_AT_external, 1);
14222 if (DECL_ARTIFICIAL (decl))
14223 add_AT_flag (const_die, DW_AT_artificial, 1);
14224 tree_add_const_value_attribute (const_die, decl);
14227 /* Generate a DIE to represent a label identifier. */
14230 gen_label_die (tree decl, dw_die_ref context_die)
14232 tree origin = decl_ultimate_origin (decl);
14233 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
14235 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14237 if (origin != NULL)
14238 add_abstract_origin_attribute (lbl_die, origin);
14240 add_name_and_src_coords_attributes (lbl_die, decl);
14242 if (DECL_ABSTRACT (decl))
14243 equate_decl_number_to_die (decl, lbl_die);
14246 insn = DECL_RTL_IF_SET (decl);
14248 /* Deleted labels are programmer specified labels which have been
14249 eliminated because of various optimizations. We still emit them
14250 here so that it is possible to put breakpoints on them. */
14254 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
14256 /* When optimization is enabled (via -O) some parts of the compiler
14257 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14258 represent source-level labels which were explicitly declared by
14259 the user. This really shouldn't be happening though, so catch
14260 it if it ever does happen. */
14261 gcc_assert (!INSN_DELETED_P (insn));
14263 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
14264 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
14269 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14270 attributes to the DIE for a block STMT, to describe where the inlined
14271 function was called from. This is similar to add_src_coords_attributes. */
14274 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
14276 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
14278 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
14279 add_AT_unsigned (die, DW_AT_call_line, s.line);
14283 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14284 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14287 add_high_low_attributes (tree stmt, dw_die_ref die)
14289 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14291 if (BLOCK_FRAGMENT_CHAIN (stmt))
14295 if (inlined_function_outer_scope_p (stmt))
14297 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14298 BLOCK_NUMBER (stmt));
14299 add_AT_lbl_id (die, DW_AT_entry_pc, label);
14302 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
14304 chain = BLOCK_FRAGMENT_CHAIN (stmt);
14307 add_ranges (chain);
14308 chain = BLOCK_FRAGMENT_CHAIN (chain);
14315 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14316 BLOCK_NUMBER (stmt));
14317 add_AT_lbl_id (die, DW_AT_low_pc, label);
14318 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
14319 BLOCK_NUMBER (stmt));
14320 add_AT_lbl_id (die, DW_AT_high_pc, label);
14324 /* Generate a DIE for a lexical block. */
14327 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
14329 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
14331 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
14332 add_high_low_attributes (stmt, stmt_die);
14334 decls_for_scope (stmt, stmt_die, depth);
14337 /* Generate a DIE for an inlined subprogram. */
14340 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
14344 /* The instance of function that is effectively being inlined shall not
14346 gcc_assert (! BLOCK_ABSTRACT (stmt));
14348 decl = block_ultimate_origin (stmt);
14350 /* Emit info for the abstract instance first, if we haven't yet. We
14351 must emit this even if the block is abstract, otherwise when we
14352 emit the block below (or elsewhere), we may end up trying to emit
14353 a die whose origin die hasn't been emitted, and crashing. */
14354 dwarf2out_abstract_function (decl);
14356 if (! BLOCK_ABSTRACT (stmt))
14358 dw_die_ref subr_die
14359 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
14361 add_abstract_origin_attribute (subr_die, decl);
14362 if (TREE_ASM_WRITTEN (stmt))
14363 add_high_low_attributes (stmt, subr_die);
14364 add_call_src_coords_attributes (stmt, subr_die);
14366 decls_for_scope (stmt, subr_die, depth);
14367 current_function_has_inlines = 1;
14371 /* Generate a DIE for a field in a record, or structure. */
14374 gen_field_die (tree decl, dw_die_ref context_die)
14376 dw_die_ref decl_die;
14378 if (TREE_TYPE (decl) == error_mark_node)
14381 decl_die = new_die (DW_TAG_member, context_die, decl);
14382 add_name_and_src_coords_attributes (decl_die, decl);
14383 add_type_attribute (decl_die, member_declared_type (decl),
14384 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
14387 if (DECL_BIT_FIELD_TYPE (decl))
14389 add_byte_size_attribute (decl_die, decl);
14390 add_bit_size_attribute (decl_die, decl);
14391 add_bit_offset_attribute (decl_die, decl);
14394 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
14395 add_data_member_location_attribute (decl_die, decl);
14397 if (DECL_ARTIFICIAL (decl))
14398 add_AT_flag (decl_die, DW_AT_artificial, 1);
14400 if (TREE_PROTECTED (decl))
14401 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
14402 else if (TREE_PRIVATE (decl))
14403 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
14405 /* Equate decl number to die, so that we can look up this decl later on. */
14406 equate_decl_number_to_die (decl, decl_die);
14410 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14411 Use modified_type_die instead.
14412 We keep this code here just in case these types of DIEs may be needed to
14413 represent certain things in other languages (e.g. Pascal) someday. */
14416 gen_pointer_type_die (tree type, dw_die_ref context_die)
14419 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
14421 equate_type_number_to_die (type, ptr_die);
14422 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14423 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14426 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14427 Use modified_type_die instead.
14428 We keep this code here just in case these types of DIEs may be needed to
14429 represent certain things in other languages (e.g. Pascal) someday. */
14432 gen_reference_type_die (tree type, dw_die_ref context_die)
14435 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
14437 equate_type_number_to_die (type, ref_die);
14438 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
14439 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14443 /* Generate a DIE for a pointer to a member type. */
14446 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
14449 = new_die (DW_TAG_ptr_to_member_type,
14450 scope_die_for (type, context_die), type);
14452 equate_type_number_to_die (type, ptr_die);
14453 add_AT_die_ref (ptr_die, DW_AT_containing_type,
14454 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
14455 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14458 /* Generate the DIE for the compilation unit. */
14461 gen_compile_unit_die (const char *filename)
14464 char producer[250];
14465 const char *language_string = lang_hooks.name;
14468 die = new_die (DW_TAG_compile_unit, NULL, NULL);
14472 add_name_attribute (die, filename);
14473 /* Don't add cwd for <built-in>. */
14474 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
14475 add_comp_dir_attribute (die);
14478 sprintf (producer, "%s %s", language_string, version_string);
14480 #ifdef MIPS_DEBUGGING_INFO
14481 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14482 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14483 not appear in the producer string, the debugger reaches the conclusion
14484 that the object file is stripped and has no debugging information.
14485 To get the MIPS/SGI debugger to believe that there is debugging
14486 information in the object file, we add a -g to the producer string. */
14487 if (debug_info_level > DINFO_LEVEL_TERSE)
14488 strcat (producer, " -g");
14491 add_AT_string (die, DW_AT_producer, producer);
14493 if (strcmp (language_string, "GNU C++") == 0)
14494 language = DW_LANG_C_plus_plus;
14495 else if (strcmp (language_string, "GNU Ada") == 0)
14496 language = DW_LANG_Ada95;
14497 else if (strcmp (language_string, "GNU F77") == 0)
14498 language = DW_LANG_Fortran77;
14499 else if (strcmp (language_string, "GNU Fortran") == 0)
14500 language = DW_LANG_Fortran95;
14501 else if (strcmp (language_string, "GNU Pascal") == 0)
14502 language = DW_LANG_Pascal83;
14503 else if (strcmp (language_string, "GNU Java") == 0)
14504 language = DW_LANG_Java;
14505 else if (strcmp (language_string, "GNU Objective-C") == 0)
14506 language = DW_LANG_ObjC;
14507 else if (strcmp (language_string, "GNU Objective-C++") == 0)
14508 language = DW_LANG_ObjC_plus_plus;
14510 language = DW_LANG_C89;
14512 add_AT_unsigned (die, DW_AT_language, language);
14516 /* Generate the DIE for a base class. */
14519 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
14521 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
14523 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
14524 add_data_member_location_attribute (die, binfo);
14526 if (BINFO_VIRTUAL_P (binfo))
14527 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14529 if (access == access_public_node)
14530 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14531 else if (access == access_protected_node)
14532 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14535 /* Generate a DIE for a class member. */
14538 gen_member_die (tree type, dw_die_ref context_die)
14541 tree binfo = TYPE_BINFO (type);
14544 /* If this is not an incomplete type, output descriptions of each of its
14545 members. Note that as we output the DIEs necessary to represent the
14546 members of this record or union type, we will also be trying to output
14547 DIEs to represent the *types* of those members. However the `type'
14548 function (above) will specifically avoid generating type DIEs for member
14549 types *within* the list of member DIEs for this (containing) type except
14550 for those types (of members) which are explicitly marked as also being
14551 members of this (containing) type themselves. The g++ front- end can
14552 force any given type to be treated as a member of some other (containing)
14553 type by setting the TYPE_CONTEXT of the given (member) type to point to
14554 the TREE node representing the appropriate (containing) type. */
14556 /* First output info about the base classes. */
14559 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14563 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14564 gen_inheritance_die (base,
14565 (accesses ? VEC_index (tree, accesses, i)
14566 : access_public_node), context_die);
14569 /* Now output info about the data members and type members. */
14570 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14572 /* If we thought we were generating minimal debug info for TYPE
14573 and then changed our minds, some of the member declarations
14574 may have already been defined. Don't define them again, but
14575 do put them in the right order. */
14577 child = lookup_decl_die (member);
14579 splice_child_die (context_die, child);
14581 gen_decl_die (member, NULL, context_die);
14584 /* Now output info about the function members (if any). */
14585 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14587 /* Don't include clones in the member list. */
14588 if (DECL_ABSTRACT_ORIGIN (member))
14591 child = lookup_decl_die (member);
14593 splice_child_die (context_die, child);
14595 gen_decl_die (member, NULL, context_die);
14599 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14600 is set, we pretend that the type was never defined, so we only get the
14601 member DIEs needed by later specification DIEs. */
14604 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14605 enum debug_info_usage usage)
14607 dw_die_ref type_die = lookup_type_die (type);
14608 dw_die_ref scope_die = 0;
14610 int complete = (TYPE_SIZE (type)
14611 && (! TYPE_STUB_DECL (type)
14612 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14613 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14614 complete = complete && should_emit_struct_debug (type, usage);
14616 if (type_die && ! complete)
14619 if (TYPE_CONTEXT (type) != NULL_TREE
14620 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14621 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14624 scope_die = scope_die_for (type, context_die);
14626 if (! type_die || (nested && scope_die == comp_unit_die))
14627 /* First occurrence of type or toplevel definition of nested class. */
14629 dw_die_ref old_die = type_die;
14631 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14632 ? record_type_tag (type) : DW_TAG_union_type,
14634 equate_type_number_to_die (type, type_die);
14636 add_AT_specification (type_die, old_die);
14638 add_name_attribute (type_die, type_tag (type));
14641 remove_AT (type_die, DW_AT_declaration);
14643 /* If this type has been completed, then give it a byte_size attribute and
14644 then give a list of members. */
14645 if (complete && !ns_decl)
14647 /* Prevent infinite recursion in cases where the type of some member of
14648 this type is expressed in terms of this type itself. */
14649 TREE_ASM_WRITTEN (type) = 1;
14650 add_byte_size_attribute (type_die, type);
14651 if (TYPE_STUB_DECL (type) != NULL_TREE)
14652 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14654 /* If the first reference to this type was as the return type of an
14655 inline function, then it may not have a parent. Fix this now. */
14656 if (type_die->die_parent == NULL)
14657 add_child_die (scope_die, type_die);
14659 push_decl_scope (type);
14660 gen_member_die (type, type_die);
14663 /* GNU extension: Record what type our vtable lives in. */
14664 if (TYPE_VFIELD (type))
14666 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14668 gen_type_die (vtype, context_die);
14669 add_AT_die_ref (type_die, DW_AT_containing_type,
14670 lookup_type_die (vtype));
14675 add_AT_flag (type_die, DW_AT_declaration, 1);
14677 /* We don't need to do this for function-local types. */
14678 if (TYPE_STUB_DECL (type)
14679 && ! decl_function_context (TYPE_STUB_DECL (type)))
14680 VEC_safe_push (tree, gc, incomplete_types, type);
14683 if (get_AT (type_die, DW_AT_name))
14684 add_pubtype (type, type_die);
14687 /* Generate a DIE for a subroutine _type_. */
14690 gen_subroutine_type_die (tree type, dw_die_ref context_die)
14692 tree return_type = TREE_TYPE (type);
14693 dw_die_ref subr_die
14694 = new_die (DW_TAG_subroutine_type,
14695 scope_die_for (type, context_die), type);
14697 equate_type_number_to_die (type, subr_die);
14698 add_prototyped_attribute (subr_die, type);
14699 add_type_attribute (subr_die, return_type, 0, 0, context_die);
14700 gen_formal_types_die (type, subr_die);
14702 if (get_AT (subr_die, DW_AT_name))
14703 add_pubtype (type, subr_die);
14706 /* Generate a DIE for a type definition. */
14709 gen_typedef_die (tree decl, dw_die_ref context_die)
14711 dw_die_ref type_die;
14714 if (TREE_ASM_WRITTEN (decl))
14717 TREE_ASM_WRITTEN (decl) = 1;
14718 type_die = new_die (DW_TAG_typedef, context_die, decl);
14719 origin = decl_ultimate_origin (decl);
14720 if (origin != NULL)
14721 add_abstract_origin_attribute (type_die, origin);
14726 add_name_and_src_coords_attributes (type_die, decl);
14727 if (DECL_ORIGINAL_TYPE (decl))
14729 type = DECL_ORIGINAL_TYPE (decl);
14731 gcc_assert (type != TREE_TYPE (decl));
14732 equate_type_number_to_die (TREE_TYPE (decl), type_die);
14735 type = TREE_TYPE (decl);
14737 add_type_attribute (type_die, type, TREE_READONLY (decl),
14738 TREE_THIS_VOLATILE (decl), context_die);
14741 if (DECL_ABSTRACT (decl))
14742 equate_decl_number_to_die (decl, type_die);
14744 if (get_AT (type_die, DW_AT_name))
14745 add_pubtype (decl, type_die);
14748 /* Generate a type description DIE. */
14751 gen_type_die_with_usage (tree type, dw_die_ref context_die,
14752 enum debug_info_usage usage)
14755 struct array_descr_info info;
14757 if (type == NULL_TREE || type == error_mark_node)
14760 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14761 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
14763 if (TREE_ASM_WRITTEN (type))
14766 /* Prevent broken recursion; we can't hand off to the same type. */
14767 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
14769 /* Use the DIE of the containing namespace as the parent DIE of
14770 the type description DIE we want to generate. */
14771 if (DECL_CONTEXT (TYPE_NAME (type))
14772 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
14773 context_die = lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type)));
14775 TREE_ASM_WRITTEN (type) = 1;
14776 gen_decl_die (TYPE_NAME (type), NULL, context_die);
14780 /* If this is an array type with hidden descriptor, handle it first. */
14781 if (!TREE_ASM_WRITTEN (type)
14782 && lang_hooks.types.get_array_descr_info
14783 && lang_hooks.types.get_array_descr_info (type, &info))
14785 gen_descr_array_type_die (type, &info, context_die);
14786 TREE_ASM_WRITTEN (type) = 1;
14790 /* We are going to output a DIE to represent the unqualified version
14791 of this type (i.e. without any const or volatile qualifiers) so
14792 get the main variant (i.e. the unqualified version) of this type
14793 now. (Vectors are special because the debugging info is in the
14794 cloned type itself). */
14795 if (TREE_CODE (type) != VECTOR_TYPE)
14796 type = type_main_variant (type);
14798 if (TREE_ASM_WRITTEN (type))
14801 switch (TREE_CODE (type))
14807 case REFERENCE_TYPE:
14808 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
14809 ensures that the gen_type_die recursion will terminate even if the
14810 type is recursive. Recursive types are possible in Ada. */
14811 /* ??? We could perhaps do this for all types before the switch
14813 TREE_ASM_WRITTEN (type) = 1;
14815 /* For these types, all that is required is that we output a DIE (or a
14816 set of DIEs) to represent the "basis" type. */
14817 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14818 DINFO_USAGE_IND_USE);
14822 /* This code is used for C++ pointer-to-data-member types.
14823 Output a description of the relevant class type. */
14824 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
14825 DINFO_USAGE_IND_USE);
14827 /* Output a description of the type of the object pointed to. */
14828 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14829 DINFO_USAGE_IND_USE);
14831 /* Now output a DIE to represent this pointer-to-data-member type
14833 gen_ptr_to_mbr_type_die (type, context_die);
14836 case FUNCTION_TYPE:
14837 /* Force out return type (in case it wasn't forced out already). */
14838 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14839 DINFO_USAGE_DIR_USE);
14840 gen_subroutine_type_die (type, context_die);
14844 /* Force out return type (in case it wasn't forced out already). */
14845 gen_type_die_with_usage (TREE_TYPE (type), context_die,
14846 DINFO_USAGE_DIR_USE);
14847 gen_subroutine_type_die (type, context_die);
14851 gen_array_type_die (type, context_die);
14855 gen_array_type_die (type, context_die);
14858 case ENUMERAL_TYPE:
14861 case QUAL_UNION_TYPE:
14862 /* If this is a nested type whose containing class hasn't been written
14863 out yet, writing it out will cover this one, too. This does not apply
14864 to instantiations of member class templates; they need to be added to
14865 the containing class as they are generated. FIXME: This hurts the
14866 idea of combining type decls from multiple TUs, since we can't predict
14867 what set of template instantiations we'll get. */
14868 if (TYPE_CONTEXT (type)
14869 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14870 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
14872 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
14874 if (TREE_ASM_WRITTEN (type))
14877 /* If that failed, attach ourselves to the stub. */
14878 push_decl_scope (TYPE_CONTEXT (type));
14879 context_die = lookup_type_die (TYPE_CONTEXT (type));
14884 context_die = declare_in_namespace (type, context_die);
14888 if (TREE_CODE (type) == ENUMERAL_TYPE)
14890 /* This might have been written out by the call to
14891 declare_in_namespace. */
14892 if (!TREE_ASM_WRITTEN (type))
14893 gen_enumeration_type_die (type, context_die);
14896 gen_struct_or_union_type_die (type, context_die, usage);
14901 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14902 it up if it is ever completed. gen_*_type_die will set it for us
14903 when appropriate. */
14909 case FIXED_POINT_TYPE:
14912 /* No DIEs needed for fundamental types. */
14916 /* No Dwarf representation currently defined. */
14920 gcc_unreachable ();
14923 TREE_ASM_WRITTEN (type) = 1;
14927 gen_type_die (tree type, dw_die_ref context_die)
14929 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
14932 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14933 things which are local to the given block. */
14936 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
14938 int must_output_die = 0;
14941 /* Ignore blocks that are NULL. */
14942 if (stmt == NULL_TREE)
14945 inlined_func = inlined_function_outer_scope_p (stmt);
14947 /* If the block is one fragment of a non-contiguous block, do not
14948 process the variables, since they will have been done by the
14949 origin block. Do process subblocks. */
14950 if (BLOCK_FRAGMENT_ORIGIN (stmt))
14954 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
14955 gen_block_die (sub, context_die, depth + 1);
14960 /* Determine if we need to output any Dwarf DIEs at all to represent this
14963 /* The outer scopes for inlinings *must* always be represented. We
14964 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14965 must_output_die = 1;
14968 /* Determine if this block directly contains any "significant"
14969 local declarations which we will need to output DIEs for. */
14970 if (debug_info_level > DINFO_LEVEL_TERSE)
14971 /* We are not in terse mode so *any* local declaration counts
14972 as being a "significant" one. */
14973 must_output_die = ((BLOCK_VARS (stmt) != NULL
14974 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
14975 && (TREE_USED (stmt)
14976 || TREE_ASM_WRITTEN (stmt)
14977 || BLOCK_ABSTRACT (stmt)));
14978 else if ((TREE_USED (stmt)
14979 || TREE_ASM_WRITTEN (stmt)
14980 || BLOCK_ABSTRACT (stmt))
14981 && !dwarf2out_ignore_block (stmt))
14982 must_output_die = 1;
14985 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14986 DIE for any block which contains no significant local declarations at
14987 all. Rather, in such cases we just call `decls_for_scope' so that any
14988 needed Dwarf info for any sub-blocks will get properly generated. Note
14989 that in terse mode, our definition of what constitutes a "significant"
14990 local declaration gets restricted to include only inlined function
14991 instances and local (nested) function definitions. */
14992 if (must_output_die)
14996 /* If STMT block is abstract, that means we have been called
14997 indirectly from dwarf2out_abstract_function.
14998 That function rightfully marks the descendent blocks (of
14999 the abstract function it is dealing with) as being abstract,
15000 precisely to prevent us from emitting any
15001 DW_TAG_inlined_subroutine DIE as a descendent
15002 of an abstract function instance. So in that case, we should
15003 not call gen_inlined_subroutine_die.
15005 Later though, when cgraph asks dwarf2out to emit info
15006 for the concrete instance of the function decl into which
15007 the concrete instance of STMT got inlined, the later will lead
15008 to the generation of a DW_TAG_inlined_subroutine DIE. */
15009 if (! BLOCK_ABSTRACT (stmt))
15010 gen_inlined_subroutine_die (stmt, context_die, depth);
15013 gen_lexical_block_die (stmt, context_die, depth);
15016 decls_for_scope (stmt, context_die, depth);
15019 /* Process variable DECL (or variable with origin ORIGIN) within
15020 block STMT and add it to CONTEXT_DIE. */
15022 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
15025 tree decl_or_origin = decl ? decl : origin;
15026 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
15028 if (ultimate_origin)
15029 origin = ultimate_origin;
15031 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
15032 die = lookup_decl_die (decl_or_origin);
15033 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
15034 && TYPE_DECL_IS_STUB (decl_or_origin))
15035 die = lookup_type_die (TREE_TYPE (decl_or_origin));
15039 if (die != NULL && die->die_parent == NULL)
15040 add_child_die (context_die, die);
15041 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
15042 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
15043 stmt, context_die);
15045 gen_decl_die (decl, origin, context_die);
15048 /* Generate all of the decls declared within a given scope and (recursively)
15049 all of its sub-blocks. */
15052 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
15058 /* Ignore NULL blocks. */
15059 if (stmt == NULL_TREE)
15062 /* Output the DIEs to represent all of the data objects and typedefs
15063 declared directly within this block but not within any nested
15064 sub-blocks. Also, nested function and tag DIEs have been
15065 generated with a parent of NULL; fix that up now. */
15066 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
15067 process_scope_var (stmt, decl, NULL_TREE, context_die);
15068 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
15069 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
15072 /* If we're at -g1, we're not interested in subblocks. */
15073 if (debug_info_level <= DINFO_LEVEL_TERSE)
15076 /* Output the DIEs to represent all sub-blocks (and the items declared
15077 therein) of this block. */
15078 for (subblocks = BLOCK_SUBBLOCKS (stmt);
15080 subblocks = BLOCK_CHAIN (subblocks))
15081 gen_block_die (subblocks, context_die, depth + 1);
15084 /* Is this a typedef we can avoid emitting? */
15087 is_redundant_typedef (const_tree decl)
15089 if (TYPE_DECL_IS_STUB (decl))
15092 if (DECL_ARTIFICIAL (decl)
15093 && DECL_CONTEXT (decl)
15094 && is_tagged_type (DECL_CONTEXT (decl))
15095 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
15096 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
15097 /* Also ignore the artificial member typedef for the class name. */
15103 /* Returns the DIE for a context. */
15105 static inline dw_die_ref
15106 get_context_die (tree context)
15110 /* Find die that represents this context. */
15111 if (TYPE_P (context))
15112 return force_type_die (context);
15114 return force_decl_die (context);
15116 return comp_unit_die;
15119 /* Returns the DIE for decl. A DIE will always be returned. */
15122 force_decl_die (tree decl)
15124 dw_die_ref decl_die;
15125 unsigned saved_external_flag;
15126 tree save_fn = NULL_TREE;
15127 decl_die = lookup_decl_die (decl);
15130 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
15132 decl_die = lookup_decl_die (decl);
15136 switch (TREE_CODE (decl))
15138 case FUNCTION_DECL:
15139 /* Clear current_function_decl, so that gen_subprogram_die thinks
15140 that this is a declaration. At this point, we just want to force
15141 declaration die. */
15142 save_fn = current_function_decl;
15143 current_function_decl = NULL_TREE;
15144 gen_subprogram_die (decl, context_die);
15145 current_function_decl = save_fn;
15149 /* Set external flag to force declaration die. Restore it after
15150 gen_decl_die() call. */
15151 saved_external_flag = DECL_EXTERNAL (decl);
15152 DECL_EXTERNAL (decl) = 1;
15153 gen_decl_die (decl, NULL, context_die);
15154 DECL_EXTERNAL (decl) = saved_external_flag;
15157 case NAMESPACE_DECL:
15158 dwarf2out_decl (decl);
15162 gcc_unreachable ();
15165 /* We should be able to find the DIE now. */
15167 decl_die = lookup_decl_die (decl);
15168 gcc_assert (decl_die);
15174 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15175 always returned. */
15178 force_type_die (tree type)
15180 dw_die_ref type_die;
15182 type_die = lookup_type_die (type);
15185 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
15187 type_die = modified_type_die (type, TYPE_READONLY (type),
15188 TYPE_VOLATILE (type), context_die);
15189 gcc_assert (type_die);
15194 /* Force out any required namespaces to be able to output DECL,
15195 and return the new context_die for it, if it's changed. */
15198 setup_namespace_context (tree thing, dw_die_ref context_die)
15200 tree context = (DECL_P (thing)
15201 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
15202 if (context && TREE_CODE (context) == NAMESPACE_DECL)
15203 /* Force out the namespace. */
15204 context_die = force_decl_die (context);
15206 return context_die;
15209 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15210 type) within its namespace, if appropriate.
15212 For compatibility with older debuggers, namespace DIEs only contain
15213 declarations; all definitions are emitted at CU scope. */
15216 declare_in_namespace (tree thing, dw_die_ref context_die)
15218 dw_die_ref ns_context;
15220 if (debug_info_level <= DINFO_LEVEL_TERSE)
15221 return context_die;
15223 /* If this decl is from an inlined function, then don't try to emit it in its
15224 namespace, as we will get confused. It would have already been emitted
15225 when the abstract instance of the inline function was emitted anyways. */
15226 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
15227 return context_die;
15229 ns_context = setup_namespace_context (thing, context_die);
15231 if (ns_context != context_die)
15235 if (DECL_P (thing))
15236 gen_decl_die (thing, NULL, ns_context);
15238 gen_type_die (thing, ns_context);
15240 return context_die;
15243 /* Generate a DIE for a namespace or namespace alias. */
15246 gen_namespace_die (tree decl, dw_die_ref context_die)
15248 dw_die_ref namespace_die;
15250 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15251 they are an alias of. */
15252 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
15254 /* Output a real namespace or module. */
15255 context_die = setup_namespace_context (decl, comp_unit_die);
15256 namespace_die = new_die (is_fortran ()
15257 ? DW_TAG_module : DW_TAG_namespace,
15258 context_die, decl);
15259 /* For Fortran modules defined in different CU don't add src coords. */
15260 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
15261 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
15263 add_name_and_src_coords_attributes (namespace_die, decl);
15264 if (DECL_EXTERNAL (decl))
15265 add_AT_flag (namespace_die, DW_AT_declaration, 1);
15266 equate_decl_number_to_die (decl, namespace_die);
15270 /* Output a namespace alias. */
15272 /* Force out the namespace we are an alias of, if necessary. */
15273 dw_die_ref origin_die
15274 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
15276 if (DECL_CONTEXT (decl) == NULL_TREE
15277 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
15278 context_die = setup_namespace_context (decl, comp_unit_die);
15279 /* Now create the namespace alias DIE. */
15280 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
15281 add_name_and_src_coords_attributes (namespace_die, decl);
15282 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
15283 equate_decl_number_to_die (decl, namespace_die);
15287 /* Generate Dwarf debug information for a decl described by DECL. */
15290 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
15292 tree decl_or_origin = decl ? decl : origin;
15293 tree class_origin = NULL;
15295 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
15298 switch (TREE_CODE (decl_or_origin))
15304 if (!is_fortran ())
15306 /* The individual enumerators of an enum type get output when we output
15307 the Dwarf representation of the relevant enum type itself. */
15311 /* Emit its type. */
15312 gen_type_die (TREE_TYPE (decl), context_die);
15314 /* And its containing namespace. */
15315 context_die = declare_in_namespace (decl, context_die);
15317 gen_const_die (decl, context_die);
15320 case FUNCTION_DECL:
15321 /* Don't output any DIEs to represent mere function declarations,
15322 unless they are class members or explicit block externs. */
15323 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
15324 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
15325 && (current_function_decl == NULL_TREE
15326 || DECL_ARTIFICIAL (decl_or_origin)))
15331 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15332 on local redeclarations of global functions. That seems broken. */
15333 if (current_function_decl != decl)
15334 /* This is only a declaration. */;
15337 /* If we're emitting a clone, emit info for the abstract instance. */
15338 if (origin || DECL_ORIGIN (decl) != decl)
15339 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
15341 /* If we're emitting an out-of-line copy of an inline function,
15342 emit info for the abstract instance and set up to refer to it. */
15343 else if (cgraph_function_possibly_inlined_p (decl)
15344 && ! DECL_ABSTRACT (decl)
15345 && ! class_or_namespace_scope_p (context_die)
15346 /* dwarf2out_abstract_function won't emit a die if this is just
15347 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15348 that case, because that works only if we have a die. */
15349 && DECL_INITIAL (decl) != NULL_TREE)
15351 dwarf2out_abstract_function (decl);
15352 set_decl_origin_self (decl);
15355 /* Otherwise we're emitting the primary DIE for this decl. */
15356 else if (debug_info_level > DINFO_LEVEL_TERSE)
15358 /* Before we describe the FUNCTION_DECL itself, make sure that we
15359 have described its return type. */
15360 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
15362 /* And its virtual context. */
15363 if (DECL_VINDEX (decl) != NULL_TREE)
15364 gen_type_die (DECL_CONTEXT (decl), context_die);
15366 /* And its containing type. */
15368 origin = decl_class_context (decl);
15369 if (origin != NULL_TREE)
15370 gen_type_die_for_member (origin, decl, context_die);
15372 /* And its containing namespace. */
15373 context_die = declare_in_namespace (decl, context_die);
15376 /* Now output a DIE to represent the function itself. */
15378 gen_subprogram_die (decl, context_die);
15382 /* If we are in terse mode, don't generate any DIEs to represent any
15383 actual typedefs. */
15384 if (debug_info_level <= DINFO_LEVEL_TERSE)
15387 /* In the special case of a TYPE_DECL node representing the declaration
15388 of some type tag, if the given TYPE_DECL is marked as having been
15389 instantiated from some other (original) TYPE_DECL node (e.g. one which
15390 was generated within the original definition of an inline function) we
15391 used to generate a special (abbreviated) DW_TAG_structure_type,
15392 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15393 should be actually referencing those DIEs, as variable DIEs with that
15394 type would be emitted already in the abstract origin, so it was always
15395 removed during unused type prunning. Don't add anything in this
15397 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
15400 if (is_redundant_typedef (decl))
15401 gen_type_die (TREE_TYPE (decl), context_die);
15403 /* Output a DIE to represent the typedef itself. */
15404 gen_typedef_die (decl, context_die);
15408 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15409 gen_label_die (decl, context_die);
15414 /* If we are in terse mode, don't generate any DIEs to represent any
15415 variable declarations or definitions. */
15416 if (debug_info_level <= DINFO_LEVEL_TERSE)
15419 /* Output any DIEs that are needed to specify the type of this data
15421 if (TREE_CODE (decl_or_origin) == RESULT_DECL
15422 && DECL_BY_REFERENCE (decl_or_origin))
15423 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15425 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15427 /* And its containing type. */
15428 class_origin = decl_class_context (decl_or_origin);
15429 if (class_origin != NULL_TREE)
15430 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
15432 /* And its containing namespace. */
15433 context_die = declare_in_namespace (decl_or_origin, context_die);
15435 /* Now output the DIE to represent the data object itself. This gets
15436 complicated because of the possibility that the VAR_DECL really
15437 represents an inlined instance of a formal parameter for an inline
15440 origin = decl_ultimate_origin (decl);
15441 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
15442 gen_formal_parameter_die (decl, origin, context_die);
15444 gen_variable_die (decl, origin, context_die);
15448 /* Ignore the nameless fields that are used to skip bits but handle C++
15449 anonymous unions and structs. */
15450 if (DECL_NAME (decl) != NULL_TREE
15451 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
15452 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
15454 gen_type_die (member_declared_type (decl), context_die);
15455 gen_field_die (decl, context_die);
15460 if (DECL_BY_REFERENCE (decl_or_origin))
15461 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15463 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15464 gen_formal_parameter_die (decl, origin, context_die);
15467 case NAMESPACE_DECL:
15468 case IMPORTED_DECL:
15469 gen_namespace_die (decl, context_die);
15473 /* Probably some frontend-internal decl. Assume we don't care. */
15474 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
15479 /* Output debug information for global decl DECL. Called from toplev.c after
15480 compilation proper has finished. */
15483 dwarf2out_global_decl (tree decl)
15485 /* Output DWARF2 information for file-scope tentative data object
15486 declarations, file-scope (extern) function declarations (which
15487 had no corresponding body) and file-scope tagged type declarations
15488 and definitions which have not yet been forced out. */
15489 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
15490 dwarf2out_decl (decl);
15493 /* Output debug information for type decl DECL. Called from toplev.c
15494 and from language front ends (to record built-in types). */
15496 dwarf2out_type_decl (tree decl, int local)
15499 dwarf2out_decl (decl);
15502 /* Output debug information for imported module or decl DECL.
15503 NAME is non-NULL name in the lexical block if the decl has been renamed.
15504 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15505 that DECL belongs to.
15506 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15508 dwarf2out_imported_module_or_decl_1 (tree decl,
15510 tree lexical_block,
15511 dw_die_ref lexical_block_die)
15513 expanded_location xloc;
15514 dw_die_ref imported_die = NULL;
15515 dw_die_ref at_import_die;
15517 if (TREE_CODE (decl) == IMPORTED_DECL)
15519 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
15520 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
15524 xloc = expand_location (input_location);
15526 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
15528 if (is_base_type (TREE_TYPE (decl)))
15529 at_import_die = base_type_die (TREE_TYPE (decl));
15531 at_import_die = force_type_die (TREE_TYPE (decl));
15532 /* For namespace N { typedef void T; } using N::T; base_type_die
15533 returns NULL, but DW_TAG_imported_declaration requires
15534 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15535 if (!at_import_die)
15537 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15538 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15539 at_import_die = lookup_type_die (TREE_TYPE (decl));
15540 gcc_assert (at_import_die);
15545 at_import_die = lookup_decl_die (decl);
15546 if (!at_import_die)
15548 /* If we're trying to avoid duplicate debug info, we may not have
15549 emitted the member decl for this field. Emit it now. */
15550 if (TREE_CODE (decl) == FIELD_DECL)
15552 tree type = DECL_CONTEXT (decl);
15554 if (TYPE_CONTEXT (type)
15555 && TYPE_P (TYPE_CONTEXT (type))
15556 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15557 DINFO_USAGE_DIR_USE))
15559 gen_type_die_for_member (type, decl,
15560 get_context_die (TYPE_CONTEXT (type)));
15562 at_import_die = force_decl_die (decl);
15566 if (TREE_CODE (decl) == NAMESPACE_DECL)
15567 imported_die = new_die (DW_TAG_imported_module,
15571 imported_die = new_die (DW_TAG_imported_declaration,
15575 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15576 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15578 add_AT_string (imported_die, DW_AT_name,
15579 IDENTIFIER_POINTER (name));
15580 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15583 /* Output debug information for imported module or decl DECL.
15584 NAME is non-NULL name in context if the decl has been renamed.
15585 CHILD is true if decl is one of the renamed decls as part of
15586 importing whole module. */
15589 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
15592 /* dw_die_ref at_import_die; */
15593 dw_die_ref scope_die;
15595 if (debug_info_level <= DINFO_LEVEL_TERSE)
15600 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15601 We need decl DIE for reference and scope die. First, get DIE for the decl
15604 /* Get the scope die for decl context. Use comp_unit_die for global module
15605 or decl. If die is not found for non globals, force new die. */
15607 && TYPE_P (context)
15608 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
15610 scope_die = get_context_die (context);
15614 gcc_assert (scope_die->die_child);
15615 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
15616 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
15617 scope_die = scope_die->die_child;
15620 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15621 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
15625 /* Write the debugging output for DECL. */
15628 dwarf2out_decl (tree decl)
15630 dw_die_ref context_die = comp_unit_die;
15632 switch (TREE_CODE (decl))
15637 case FUNCTION_DECL:
15638 /* What we would really like to do here is to filter out all mere
15639 file-scope declarations of file-scope functions which are never
15640 referenced later within this translation unit (and keep all of ones
15641 that *are* referenced later on) but we aren't clairvoyant, so we have
15642 no idea which functions will be referenced in the future (i.e. later
15643 on within the current translation unit). So here we just ignore all
15644 file-scope function declarations which are not also definitions. If
15645 and when the debugger needs to know something about these functions,
15646 it will have to hunt around and find the DWARF information associated
15647 with the definition of the function.
15649 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15650 nodes represent definitions and which ones represent mere
15651 declarations. We have to check DECL_INITIAL instead. That's because
15652 the C front-end supports some weird semantics for "extern inline"
15653 function definitions. These can get inlined within the current
15654 translation unit (and thus, we need to generate Dwarf info for their
15655 abstract instances so that the Dwarf info for the concrete inlined
15656 instances can have something to refer to) but the compiler never
15657 generates any out-of-lines instances of such things (despite the fact
15658 that they *are* definitions).
15660 The important point is that the C front-end marks these "extern
15661 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15662 them anyway. Note that the C++ front-end also plays some similar games
15663 for inline function definitions appearing within include files which
15664 also contain `#pragma interface' pragmas. */
15665 if (DECL_INITIAL (decl) == NULL_TREE)
15668 /* If we're a nested function, initially use a parent of NULL; if we're
15669 a plain function, this will be fixed up in decls_for_scope. If
15670 we're a method, it will be ignored, since we already have a DIE. */
15671 if (decl_function_context (decl)
15672 /* But if we're in terse mode, we don't care about scope. */
15673 && debug_info_level > DINFO_LEVEL_TERSE)
15674 context_die = NULL;
15678 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15679 declaration and if the declaration was never even referenced from
15680 within this entire compilation unit. We suppress these DIEs in
15681 order to save space in the .debug section (by eliminating entries
15682 which are probably useless). Note that we must not suppress
15683 block-local extern declarations (whether used or not) because that
15684 would screw-up the debugger's name lookup mechanism and cause it to
15685 miss things which really ought to be in scope at a given point. */
15686 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
15689 /* For local statics lookup proper context die. */
15690 if (TREE_STATIC (decl) && decl_function_context (decl))
15691 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15693 /* If we are in terse mode, don't generate any DIEs to represent any
15694 variable declarations or definitions. */
15695 if (debug_info_level <= DINFO_LEVEL_TERSE)
15700 if (debug_info_level <= DINFO_LEVEL_TERSE)
15702 if (!is_fortran ())
15704 if (TREE_STATIC (decl) && decl_function_context (decl))
15705 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15708 case NAMESPACE_DECL:
15709 case IMPORTED_DECL:
15710 if (debug_info_level <= DINFO_LEVEL_TERSE)
15712 if (lookup_decl_die (decl) != NULL)
15717 /* Don't emit stubs for types unless they are needed by other DIEs. */
15718 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
15721 /* Don't bother trying to generate any DIEs to represent any of the
15722 normal built-in types for the language we are compiling. */
15723 if (DECL_IS_BUILTIN (decl))
15725 /* OK, we need to generate one for `bool' so GDB knows what type
15726 comparisons have. */
15728 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
15729 && ! DECL_IGNORED_P (decl))
15730 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
15735 /* If we are in terse mode, don't generate any DIEs for types. */
15736 if (debug_info_level <= DINFO_LEVEL_TERSE)
15739 /* If we're a function-scope tag, initially use a parent of NULL;
15740 this will be fixed up in decls_for_scope. */
15741 if (decl_function_context (decl))
15742 context_die = NULL;
15750 gen_decl_die (decl, NULL, context_die);
15753 /* Output a marker (i.e. a label) for the beginning of the generated code for
15754 a lexical block. */
15757 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
15758 unsigned int blocknum)
15760 switch_to_section (current_function_section ());
15761 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
15764 /* Output a marker (i.e. a label) for the end of the generated code for a
15768 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
15770 switch_to_section (current_function_section ());
15771 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
15774 /* Returns nonzero if it is appropriate not to emit any debugging
15775 information for BLOCK, because it doesn't contain any instructions.
15777 Don't allow this for blocks with nested functions or local classes
15778 as we would end up with orphans, and in the presence of scheduling
15779 we may end up calling them anyway. */
15782 dwarf2out_ignore_block (const_tree block)
15787 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
15788 if (TREE_CODE (decl) == FUNCTION_DECL
15789 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15791 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
15793 decl = BLOCK_NONLOCALIZED_VAR (block, i);
15794 if (TREE_CODE (decl) == FUNCTION_DECL
15795 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15802 /* Hash table routines for file_hash. */
15805 file_table_eq (const void *p1_p, const void *p2_p)
15807 const struct dwarf_file_data *const p1 =
15808 (const struct dwarf_file_data *) p1_p;
15809 const char *const p2 = (const char *) p2_p;
15810 return strcmp (p1->filename, p2) == 0;
15814 file_table_hash (const void *p_p)
15816 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
15817 return htab_hash_string (p->filename);
15820 /* Lookup FILE_NAME (in the list of filenames that we know about here in
15821 dwarf2out.c) and return its "index". The index of each (known) filename is
15822 just a unique number which is associated with only that one filename. We
15823 need such numbers for the sake of generating labels (in the .debug_sfnames
15824 section) and references to those files numbers (in the .debug_srcinfo
15825 and.debug_macinfo sections). If the filename given as an argument is not
15826 found in our current list, add it to the list and assign it the next
15827 available unique index number. In order to speed up searches, we remember
15828 the index of the filename was looked up last. This handles the majority of
15831 static struct dwarf_file_data *
15832 lookup_filename (const char *file_name)
15835 struct dwarf_file_data * created;
15837 /* Check to see if the file name that was searched on the previous
15838 call matches this file name. If so, return the index. */
15839 if (file_table_last_lookup
15840 && (file_name == file_table_last_lookup->filename
15841 || strcmp (file_table_last_lookup->filename, file_name) == 0))
15842 return file_table_last_lookup;
15844 /* Didn't match the previous lookup, search the table. */
15845 slot = htab_find_slot_with_hash (file_table, file_name,
15846 htab_hash_string (file_name), INSERT);
15848 return (struct dwarf_file_data *) *slot;
15850 created = GGC_NEW (struct dwarf_file_data);
15851 created->filename = file_name;
15852 created->emitted_number = 0;
15857 /* If the assembler will construct the file table, then translate the compiler
15858 internal file table number into the assembler file table number, and emit
15859 a .file directive if we haven't already emitted one yet. The file table
15860 numbers are different because we prune debug info for unused variables and
15861 types, which may include filenames. */
15864 maybe_emit_file (struct dwarf_file_data * fd)
15866 if (! fd->emitted_number)
15868 if (last_emitted_file)
15869 fd->emitted_number = last_emitted_file->emitted_number + 1;
15871 fd->emitted_number = 1;
15872 last_emitted_file = fd;
15874 if (DWARF2_ASM_LINE_DEBUG_INFO)
15876 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
15877 output_quoted_string (asm_out_file,
15878 remap_debug_filename (fd->filename));
15879 fputc ('\n', asm_out_file);
15883 return fd->emitted_number;
15886 /* Called by the final INSN scan whenever we see a var location. We
15887 use it to drop labels in the right places, and throw the location in
15888 our lookup table. */
15891 dwarf2out_var_location (rtx loc_note)
15893 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
15894 struct var_loc_node *newloc;
15896 static rtx last_insn;
15897 static const char *last_label;
15900 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
15902 prev_insn = PREV_INSN (loc_note);
15904 newloc = GGC_CNEW (struct var_loc_node);
15905 /* If the insn we processed last time is the previous insn
15906 and it is also a var location note, use the label we emitted
15908 if (last_insn != NULL_RTX
15909 && last_insn == prev_insn
15910 && NOTE_P (prev_insn)
15911 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
15913 newloc->label = last_label;
15917 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
15918 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
15920 newloc->label = ggc_strdup (loclabel);
15922 newloc->var_loc_note = loc_note;
15923 newloc->next = NULL;
15925 if (cfun && in_cold_section_p)
15926 newloc->section_label = crtl->subsections.cold_section_label;
15928 newloc->section_label = text_section_label;
15930 last_insn = loc_note;
15931 last_label = newloc->label;
15932 decl = NOTE_VAR_LOCATION_DECL (loc_note);
15933 add_var_loc_to_decl (decl, newloc);
15936 /* We need to reset the locations at the beginning of each
15937 function. We can't do this in the end_function hook, because the
15938 declarations that use the locations won't have been output when
15939 that hook is called. Also compute have_multiple_function_sections here. */
15942 dwarf2out_begin_function (tree fun)
15944 htab_empty (decl_loc_table);
15946 if (function_section (fun) != text_section)
15947 have_multiple_function_sections = true;
15949 dwarf2out_note_section_used ();
15952 /* Output a label to mark the beginning of a source code line entry
15953 and record information relating to this source line, in
15954 'line_info_table' for later output of the .debug_line section. */
15957 dwarf2out_source_line (unsigned int line, const char *filename)
15959 if (debug_info_level >= DINFO_LEVEL_NORMAL
15962 int file_num = maybe_emit_file (lookup_filename (filename));
15964 switch_to_section (current_function_section ());
15966 /* If requested, emit something human-readable. */
15967 if (flag_debug_asm)
15968 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
15971 if (DWARF2_ASM_LINE_DEBUG_INFO)
15973 /* Emit the .loc directive understood by GNU as. */
15974 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
15976 /* Indicate that line number info exists. */
15977 line_info_table_in_use++;
15979 else if (function_section (current_function_decl) != text_section)
15981 dw_separate_line_info_ref line_info;
15982 targetm.asm_out.internal_label (asm_out_file,
15983 SEPARATE_LINE_CODE_LABEL,
15984 separate_line_info_table_in_use);
15986 /* Expand the line info table if necessary. */
15987 if (separate_line_info_table_in_use
15988 == separate_line_info_table_allocated)
15990 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15991 separate_line_info_table
15992 = GGC_RESIZEVEC (dw_separate_line_info_entry,
15993 separate_line_info_table,
15994 separate_line_info_table_allocated);
15995 memset (separate_line_info_table
15996 + separate_line_info_table_in_use,
15998 (LINE_INFO_TABLE_INCREMENT
15999 * sizeof (dw_separate_line_info_entry)));
16002 /* Add the new entry at the end of the line_info_table. */
16004 = &separate_line_info_table[separate_line_info_table_in_use++];
16005 line_info->dw_file_num = file_num;
16006 line_info->dw_line_num = line;
16007 line_info->function = current_function_funcdef_no;
16011 dw_line_info_ref line_info;
16013 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
16014 line_info_table_in_use);
16016 /* Expand the line info table if necessary. */
16017 if (line_info_table_in_use == line_info_table_allocated)
16019 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16021 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
16022 line_info_table_allocated);
16023 memset (line_info_table + line_info_table_in_use, 0,
16024 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
16027 /* Add the new entry at the end of the line_info_table. */
16028 line_info = &line_info_table[line_info_table_in_use++];
16029 line_info->dw_file_num = file_num;
16030 line_info->dw_line_num = line;
16035 /* Record the beginning of a new source file. */
16038 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
16040 if (flag_eliminate_dwarf2_dups)
16042 /* Record the beginning of the file for break_out_includes. */
16043 dw_die_ref bincl_die;
16045 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
16046 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
16049 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16051 int file_num = maybe_emit_file (lookup_filename (filename));
16053 switch_to_section (debug_macinfo_section);
16054 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
16055 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
16058 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
16062 /* Record the end of a source file. */
16065 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
16067 if (flag_eliminate_dwarf2_dups)
16068 /* Record the end of the file for break_out_includes. */
16069 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
16071 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16073 switch_to_section (debug_macinfo_section);
16074 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
16078 /* Called from debug_define in toplev.c. The `buffer' parameter contains
16079 the tail part of the directive line, i.e. the part which is past the
16080 initial whitespace, #, whitespace, directive-name, whitespace part. */
16083 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
16084 const char *buffer ATTRIBUTE_UNUSED)
16086 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16088 switch_to_section (debug_macinfo_section);
16089 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
16090 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16091 dw2_asm_output_nstring (buffer, -1, "The macro");
16095 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
16096 the tail part of the directive line, i.e. the part which is past the
16097 initial whitespace, #, whitespace, directive-name, whitespace part. */
16100 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
16101 const char *buffer ATTRIBUTE_UNUSED)
16103 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16105 switch_to_section (debug_macinfo_section);
16106 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
16107 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16108 dw2_asm_output_nstring (buffer, -1, "The macro");
16112 /* Set up for Dwarf output at the start of compilation. */
16115 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
16117 /* Allocate the file_table. */
16118 file_table = htab_create_ggc (50, file_table_hash,
16119 file_table_eq, NULL);
16121 /* Allocate the decl_die_table. */
16122 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
16123 decl_die_table_eq, NULL);
16125 /* Allocate the decl_loc_table. */
16126 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
16127 decl_loc_table_eq, NULL);
16129 /* Allocate the initial hunk of the decl_scope_table. */
16130 decl_scope_table = VEC_alloc (tree, gc, 256);
16132 /* Allocate the initial hunk of the abbrev_die_table. */
16133 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
16134 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
16135 /* Zero-th entry is allocated, but unused. */
16136 abbrev_die_table_in_use = 1;
16138 /* Allocate the initial hunk of the line_info_table. */
16139 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
16140 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
16142 /* Zero-th entry is allocated, but unused. */
16143 line_info_table_in_use = 1;
16145 /* Allocate the pubtypes and pubnames vectors. */
16146 pubname_table = VEC_alloc (pubname_entry, gc, 32);
16147 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
16149 /* Generate the initial DIE for the .debug section. Note that the (string)
16150 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16151 will (typically) be a relative pathname and that this pathname should be
16152 taken as being relative to the directory from which the compiler was
16153 invoked when the given (base) source file was compiled. We will fill
16154 in this value in dwarf2out_finish. */
16155 comp_unit_die = gen_compile_unit_die (NULL);
16157 incomplete_types = VEC_alloc (tree, gc, 64);
16159 used_rtx_array = VEC_alloc (rtx, gc, 32);
16161 debug_info_section = get_section (DEBUG_INFO_SECTION,
16162 SECTION_DEBUG, NULL);
16163 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
16164 SECTION_DEBUG, NULL);
16165 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
16166 SECTION_DEBUG, NULL);
16167 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
16168 SECTION_DEBUG, NULL);
16169 debug_line_section = get_section (DEBUG_LINE_SECTION,
16170 SECTION_DEBUG, NULL);
16171 debug_loc_section = get_section (DEBUG_LOC_SECTION,
16172 SECTION_DEBUG, NULL);
16173 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
16174 SECTION_DEBUG, NULL);
16175 #ifdef DEBUG_PUBTYPES_SECTION
16176 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
16177 SECTION_DEBUG, NULL);
16179 debug_str_section = get_section (DEBUG_STR_SECTION,
16180 DEBUG_STR_SECTION_FLAGS, NULL);
16181 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
16182 SECTION_DEBUG, NULL);
16183 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
16184 SECTION_DEBUG, NULL);
16186 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
16187 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
16188 DEBUG_ABBREV_SECTION_LABEL, 0);
16189 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
16190 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
16191 COLD_TEXT_SECTION_LABEL, 0);
16192 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
16194 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
16195 DEBUG_INFO_SECTION_LABEL, 0);
16196 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
16197 DEBUG_LINE_SECTION_LABEL, 0);
16198 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
16199 DEBUG_RANGES_SECTION_LABEL, 0);
16200 switch_to_section (debug_abbrev_section);
16201 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
16202 switch_to_section (debug_info_section);
16203 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
16204 switch_to_section (debug_line_section);
16205 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
16207 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16209 switch_to_section (debug_macinfo_section);
16210 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
16211 DEBUG_MACINFO_SECTION_LABEL, 0);
16212 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
16215 switch_to_section (text_section);
16216 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
16217 if (flag_reorder_blocks_and_partition)
16219 cold_text_section = unlikely_text_section ();
16220 switch_to_section (cold_text_section);
16221 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
16226 /* Called before cgraph_optimize starts outputtting functions, variables
16227 and toplevel asms into assembly. */
16230 dwarf2out_assembly_start (void)
16232 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE && dwarf2out_do_cfi_asm ())
16234 #ifndef TARGET_UNWIND_INFO
16235 if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
16237 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
16241 /* A helper function for dwarf2out_finish called through
16242 ht_forall. Emit one queued .debug_str string. */
16245 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
16247 struct indirect_string_node *node = (struct indirect_string_node *) *h;
16249 if (node->form == DW_FORM_strp)
16251 switch_to_section (debug_str_section);
16252 ASM_OUTPUT_LABEL (asm_out_file, node->label);
16253 assemble_string (node->str, strlen (node->str) + 1);
16259 #if ENABLE_ASSERT_CHECKING
16260 /* Verify that all marks are clear. */
16263 verify_marks_clear (dw_die_ref die)
16267 gcc_assert (! die->die_mark);
16268 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
16270 #endif /* ENABLE_ASSERT_CHECKING */
16272 /* Clear the marks for a die and its children.
16273 Be cool if the mark isn't set. */
16276 prune_unmark_dies (dw_die_ref die)
16282 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
16285 /* Given DIE that we're marking as used, find any other dies
16286 it references as attributes and mark them as used. */
16289 prune_unused_types_walk_attribs (dw_die_ref die)
16294 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16296 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
16298 /* A reference to another DIE.
16299 Make sure that it will get emitted. */
16300 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
16302 /* Set the string's refcount to 0 so that prune_unused_types_mark
16303 accounts properly for it. */
16304 if (AT_class (a) == dw_val_class_str)
16305 a->dw_attr_val.v.val_str->refcount = 0;
16310 /* Mark DIE as being used. If DOKIDS is true, then walk down
16311 to DIE's children. */
16314 prune_unused_types_mark (dw_die_ref die, int dokids)
16318 if (die->die_mark == 0)
16320 /* We haven't done this node yet. Mark it as used. */
16323 /* We also have to mark its parents as used.
16324 (But we don't want to mark our parents' kids due to this.) */
16325 if (die->die_parent)
16326 prune_unused_types_mark (die->die_parent, 0);
16328 /* Mark any referenced nodes. */
16329 prune_unused_types_walk_attribs (die);
16331 /* If this node is a specification,
16332 also mark the definition, if it exists. */
16333 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
16334 prune_unused_types_mark (die->die_definition, 1);
16337 if (dokids && die->die_mark != 2)
16339 /* We need to walk the children, but haven't done so yet.
16340 Remember that we've walked the kids. */
16343 /* If this is an array type, we need to make sure our
16344 kids get marked, even if they're types. */
16345 if (die->die_tag == DW_TAG_array_type)
16346 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
16348 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16352 /* For local classes, look if any static member functions were emitted
16353 and if so, mark them. */
16356 prune_unused_types_walk_local_classes (dw_die_ref die)
16360 if (die->die_mark == 2)
16363 switch (die->die_tag)
16365 case DW_TAG_structure_type:
16366 case DW_TAG_union_type:
16367 case DW_TAG_class_type:
16370 case DW_TAG_subprogram:
16371 if (!get_AT_flag (die, DW_AT_declaration)
16372 || die->die_definition != NULL)
16373 prune_unused_types_mark (die, 1);
16380 /* Mark children. */
16381 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
16384 /* Walk the tree DIE and mark types that we actually use. */
16387 prune_unused_types_walk (dw_die_ref die)
16391 /* Don't do anything if this node is already marked and
16392 children have been marked as well. */
16393 if (die->die_mark == 2)
16396 switch (die->die_tag)
16398 case DW_TAG_structure_type:
16399 case DW_TAG_union_type:
16400 case DW_TAG_class_type:
16401 if (die->die_perennial_p)
16404 for (c = die->die_parent; c; c = c->die_parent)
16405 if (c->die_tag == DW_TAG_subprogram)
16408 /* Finding used static member functions inside of classes
16409 is needed just for local classes, because for other classes
16410 static member function DIEs with DW_AT_specification
16411 are emitted outside of the DW_TAG_*_type. If we ever change
16412 it, we'd need to call this even for non-local classes. */
16414 prune_unused_types_walk_local_classes (die);
16416 /* It's a type node --- don't mark it. */
16419 case DW_TAG_const_type:
16420 case DW_TAG_packed_type:
16421 case DW_TAG_pointer_type:
16422 case DW_TAG_reference_type:
16423 case DW_TAG_volatile_type:
16424 case DW_TAG_typedef:
16425 case DW_TAG_array_type:
16426 case DW_TAG_interface_type:
16427 case DW_TAG_friend:
16428 case DW_TAG_variant_part:
16429 case DW_TAG_enumeration_type:
16430 case DW_TAG_subroutine_type:
16431 case DW_TAG_string_type:
16432 case DW_TAG_set_type:
16433 case DW_TAG_subrange_type:
16434 case DW_TAG_ptr_to_member_type:
16435 case DW_TAG_file_type:
16436 if (die->die_perennial_p)
16439 /* It's a type node --- don't mark it. */
16443 /* Mark everything else. */
16447 if (die->die_mark == 0)
16451 /* Now, mark any dies referenced from here. */
16452 prune_unused_types_walk_attribs (die);
16457 /* Mark children. */
16458 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16461 /* Increment the string counts on strings referred to from DIE's
16465 prune_unused_types_update_strings (dw_die_ref die)
16470 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16471 if (AT_class (a) == dw_val_class_str)
16473 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
16475 /* Avoid unnecessarily putting strings that are used less than
16476 twice in the hash table. */
16478 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
16481 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
16482 htab_hash_string (s->str),
16484 gcc_assert (*slot == NULL);
16490 /* Remove from the tree DIE any dies that aren't marked. */
16493 prune_unused_types_prune (dw_die_ref die)
16497 gcc_assert (die->die_mark);
16498 prune_unused_types_update_strings (die);
16500 if (! die->die_child)
16503 c = die->die_child;
16505 dw_die_ref prev = c;
16506 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
16507 if (c == die->die_child)
16509 /* No marked children between 'prev' and the end of the list. */
16511 /* No marked children at all. */
16512 die->die_child = NULL;
16515 prev->die_sib = c->die_sib;
16516 die->die_child = prev;
16521 if (c != prev->die_sib)
16523 prune_unused_types_prune (c);
16524 } while (c != die->die_child);
16528 /* Remove dies representing declarations that we never use. */
16531 prune_unused_types (void)
16534 limbo_die_node *node;
16537 #if ENABLE_ASSERT_CHECKING
16538 /* All the marks should already be clear. */
16539 verify_marks_clear (comp_unit_die);
16540 for (node = limbo_die_list; node; node = node->next)
16541 verify_marks_clear (node->die);
16542 #endif /* ENABLE_ASSERT_CHECKING */
16544 /* Mark types that are used in global variables. */
16545 premark_types_used_by_global_vars ();
16547 /* Set the mark on nodes that are actually used. */
16548 prune_unused_types_walk (comp_unit_die);
16549 for (node = limbo_die_list; node; node = node->next)
16550 prune_unused_types_walk (node->die);
16552 /* Also set the mark on nodes referenced from the
16553 pubname_table or arange_table. */
16554 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
16555 prune_unused_types_mark (pub->die, 1);
16556 for (i = 0; i < arange_table_in_use; i++)
16557 prune_unused_types_mark (arange_table[i], 1);
16559 /* Get rid of nodes that aren't marked; and update the string counts. */
16560 if (debug_str_hash)
16561 htab_empty (debug_str_hash);
16562 prune_unused_types_prune (comp_unit_die);
16563 for (node = limbo_die_list; node; node = node->next)
16564 prune_unused_types_prune (node->die);
16566 /* Leave the marks clear. */
16567 prune_unmark_dies (comp_unit_die);
16568 for (node = limbo_die_list; node; node = node->next)
16569 prune_unmark_dies (node->die);
16572 /* Set the parameter to true if there are any relative pathnames in
16575 file_table_relative_p (void ** slot, void *param)
16577 bool *p = (bool *) param;
16578 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
16579 if (!IS_ABSOLUTE_PATH (d->filename))
16587 /* Output stuff that dwarf requires at the end of every file,
16588 and generate the DWARF-2 debugging info. */
16591 dwarf2out_finish (const char *filename)
16593 limbo_die_node *node, *next_node;
16594 dw_die_ref die = 0;
16597 /* Add the name for the main input file now. We delayed this from
16598 dwarf2out_init to avoid complications with PCH. */
16599 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
16600 if (!IS_ABSOLUTE_PATH (filename))
16601 add_comp_dir_attribute (comp_unit_die);
16602 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
16605 htab_traverse (file_table, file_table_relative_p, &p);
16607 add_comp_dir_attribute (comp_unit_die);
16610 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
16612 add_location_or_const_value_attribute (
16613 VEC_index (deferred_locations, deferred_locations_list, i)->die,
16614 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
16618 /* Traverse the limbo die list, and add parent/child links. The only
16619 dies without parents that should be here are concrete instances of
16620 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16621 For concrete instances, we can get the parent die from the abstract
16623 for (node = limbo_die_list; node; node = next_node)
16625 next_node = node->next;
16628 if (die->die_parent == NULL)
16630 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
16633 add_child_die (origin->die_parent, die);
16634 else if (die == comp_unit_die)
16636 else if (errorcount > 0 || sorrycount > 0)
16637 /* It's OK to be confused by errors in the input. */
16638 add_child_die (comp_unit_die, die);
16641 /* In certain situations, the lexical block containing a
16642 nested function can be optimized away, which results
16643 in the nested function die being orphaned. Likewise
16644 with the return type of that nested function. Force
16645 this to be a child of the containing function.
16647 It may happen that even the containing function got fully
16648 inlined and optimized out. In that case we are lost and
16649 assign the empty child. This should not be big issue as
16650 the function is likely unreachable too. */
16651 tree context = NULL_TREE;
16653 gcc_assert (node->created_for);
16655 if (DECL_P (node->created_for))
16656 context = DECL_CONTEXT (node->created_for);
16657 else if (TYPE_P (node->created_for))
16658 context = TYPE_CONTEXT (node->created_for);
16660 gcc_assert (context
16661 && (TREE_CODE (context) == FUNCTION_DECL
16662 || TREE_CODE (context) == NAMESPACE_DECL));
16664 origin = lookup_decl_die (context);
16666 add_child_die (origin, die);
16668 add_child_die (comp_unit_die, die);
16673 limbo_die_list = NULL;
16675 /* Walk through the list of incomplete types again, trying once more to
16676 emit full debugging info for them. */
16677 retry_incomplete_types ();
16679 if (flag_eliminate_unused_debug_types)
16680 prune_unused_types ();
16682 /* Generate separate CUs for each of the include files we've seen.
16683 They will go into limbo_die_list. */
16684 if (flag_eliminate_dwarf2_dups)
16685 break_out_includes (comp_unit_die);
16687 /* Traverse the DIE's and add add sibling attributes to those DIE's
16688 that have children. */
16689 add_sibling_attributes (comp_unit_die);
16690 for (node = limbo_die_list; node; node = node->next)
16691 add_sibling_attributes (node->die);
16693 /* Output a terminator label for the .text section. */
16694 switch_to_section (text_section);
16695 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
16696 if (flag_reorder_blocks_and_partition)
16698 switch_to_section (unlikely_text_section ());
16699 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
16702 /* We can only use the low/high_pc attributes if all of the code was
16704 if (!have_multiple_function_sections)
16706 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
16707 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
16712 unsigned fde_idx = 0;
16714 /* We need to give .debug_loc and .debug_ranges an appropriate
16715 "base address". Use zero so that these addresses become
16716 absolute. Historically, we've emitted the unexpected
16717 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16718 Emit both to give time for other tools to adapt. */
16719 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
16720 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
16722 add_AT_range_list (comp_unit_die, DW_AT_ranges,
16723 add_ranges_by_labels (text_section_label,
16725 if (flag_reorder_blocks_and_partition)
16726 add_ranges_by_labels (cold_text_section_label,
16729 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
16731 dw_fde_ref fde = &fde_table[fde_idx];
16733 if (fde->dw_fde_switched_sections)
16735 add_ranges_by_labels (fde->dw_fde_hot_section_label,
16736 fde->dw_fde_hot_section_end_label);
16737 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
16738 fde->dw_fde_unlikely_section_end_label);
16741 add_ranges_by_labels (fde->dw_fde_begin,
16748 /* Output location list section if necessary. */
16749 if (have_location_lists)
16751 /* Output the location lists info. */
16752 switch_to_section (debug_loc_section);
16753 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
16754 DEBUG_LOC_SECTION_LABEL, 0);
16755 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
16756 output_location_lists (die);
16759 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16760 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
16761 debug_line_section_label);
16763 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16764 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
16766 /* Output all of the compilation units. We put the main one last so that
16767 the offsets are available to output_pubnames. */
16768 for (node = limbo_die_list; node; node = node->next)
16769 output_comp_unit (node->die, 0);
16771 /* Output the main compilation unit if non-empty or if .debug_macinfo
16772 has been emitted. */
16773 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
16775 /* Output the abbreviation table. */
16776 switch_to_section (debug_abbrev_section);
16777 output_abbrev_section ();
16779 /* Output public names table if necessary. */
16780 if (!VEC_empty (pubname_entry, pubname_table))
16782 switch_to_section (debug_pubnames_section);
16783 output_pubnames (pubname_table);
16786 #ifdef DEBUG_PUBTYPES_SECTION
16787 /* Output public types table if necessary. */
16788 if (!VEC_empty (pubname_entry, pubtype_table))
16790 switch_to_section (debug_pubtypes_section);
16791 output_pubnames (pubtype_table);
16795 /* Output the address range information. We only put functions in the arange
16796 table, so don't write it out if we don't have any. */
16797 if (fde_table_in_use)
16799 switch_to_section (debug_aranges_section);
16803 /* Output ranges section if necessary. */
16804 if (ranges_table_in_use)
16806 switch_to_section (debug_ranges_section);
16807 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
16811 /* Output the source line correspondence table. We must do this
16812 even if there is no line information. Otherwise, on an empty
16813 translation unit, we will generate a present, but empty,
16814 .debug_info section. IRIX 6.5 `nm' will then complain when
16815 examining the file. This is done late so that any filenames
16816 used by the debug_info section are marked as 'used'. */
16817 if (! DWARF2_ASM_LINE_DEBUG_INFO)
16819 switch_to_section (debug_line_section);
16820 output_line_info ();
16823 /* Have to end the macro section. */
16824 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16826 switch_to_section (debug_macinfo_section);
16827 dw2_asm_output_data (1, 0, "End compilation unit");
16830 /* If we emitted any DW_FORM_strp form attribute, output the string
16832 if (debug_str_hash)
16833 htab_traverse (debug_str_hash, output_indirect_string, NULL);
16837 /* This should never be used, but its address is needed for comparisons. */
16838 const struct gcc_debug_hooks dwarf2_debug_hooks;
16840 #endif /* DWARF2_DEBUGGING_INFO */
16842 #include "gt-dwarf2out.h"