1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Save the result of dwarf2out_do_frame across PCH. */
114 static GTY(()) bool saved_do_cfi_asm = 0;
116 /* Decide whether we want to emit frame unwind information for the current
120 dwarf2out_do_frame (void)
122 /* We want to emit correct CFA location expressions or lists, so we
123 have to return true if we're going to output debug info, even if
124 we're not going to output frame or unwind info. */
125 return (write_symbols == DWARF2_DEBUG
126 || write_symbols == VMS_AND_DWARF2_DEBUG
127 || DWARF2_FRAME_INFO || saved_do_cfi_asm
128 #ifdef DWARF2_UNWIND_INFO
129 || (DWARF2_UNWIND_INFO
130 && (flag_unwind_tables
131 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
136 /* Decide whether to emit frame unwind via assembler directives. */
139 dwarf2out_do_cfi_asm (void)
143 #ifdef MIPS_DEBUGGING_INFO
146 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
148 if (saved_do_cfi_asm || !eh_personality_libfunc)
150 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
153 /* Make sure the personality encoding is one the assembler can support.
154 In particular, aligned addresses can't be handled. */
155 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
156 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
158 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
159 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
162 saved_do_cfi_asm = true;
166 /* The size of the target's pointer type. */
168 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
171 /* Array of RTXes referenced by the debugging information, which therefore
172 must be kept around forever. */
173 static GTY(()) VEC(rtx,gc) *used_rtx_array;
175 /* A pointer to the base of a list of incomplete types which might be
176 completed at some later time. incomplete_types_list needs to be a
177 VEC(tree,gc) because we want to tell the garbage collector about
179 static GTY(()) VEC(tree,gc) *incomplete_types;
181 /* A pointer to the base of a table of references to declaration
182 scopes. This table is a display which tracks the nesting
183 of declaration scopes at the current scope and containing
184 scopes. This table is used to find the proper place to
185 define type declaration DIE's. */
186 static GTY(()) VEC(tree,gc) *decl_scope_table;
188 /* Pointers to various DWARF2 sections. */
189 static GTY(()) section *debug_info_section;
190 static GTY(()) section *debug_abbrev_section;
191 static GTY(()) section *debug_aranges_section;
192 static GTY(()) section *debug_macinfo_section;
193 static GTY(()) section *debug_line_section;
194 static GTY(()) section *debug_loc_section;
195 static GTY(()) section *debug_pubnames_section;
196 static GTY(()) section *debug_pubtypes_section;
197 static GTY(()) section *debug_str_section;
198 static GTY(()) section *debug_ranges_section;
199 static GTY(()) section *debug_frame_section;
201 /* How to start an assembler comment. */
202 #ifndef ASM_COMMENT_START
203 #define ASM_COMMENT_START ";#"
206 typedef struct dw_cfi_struct *dw_cfi_ref;
207 typedef struct dw_fde_struct *dw_fde_ref;
208 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
210 /* Call frames are described using a sequence of Call Frame
211 Information instructions. The register number, offset
212 and address fields are provided as possible operands;
213 their use is selected by the opcode field. */
215 enum dw_cfi_oprnd_type {
217 dw_cfi_oprnd_reg_num,
223 typedef union GTY(()) dw_cfi_oprnd_struct {
224 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
225 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
226 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
227 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
231 typedef struct GTY(()) dw_cfi_struct {
232 dw_cfi_ref dw_cfi_next;
233 enum dwarf_call_frame_info dw_cfi_opc;
234 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
236 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
241 /* This is how we define the location of the CFA. We use to handle it
242 as REG + OFFSET all the time, but now it can be more complex.
243 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
244 Instead of passing around REG and OFFSET, we pass a copy
245 of this structure. */
246 typedef struct GTY(()) cfa_loc {
247 HOST_WIDE_INT offset;
248 HOST_WIDE_INT base_offset;
250 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
251 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
254 /* All call frame descriptions (FDE's) in the GCC generated DWARF
255 refer to a single Common Information Entry (CIE), defined at
256 the beginning of the .debug_frame section. This use of a single
257 CIE obviates the need to keep track of multiple CIE's
258 in the DWARF generation routines below. */
260 typedef struct GTY(()) dw_fde_struct {
262 const char *dw_fde_begin;
263 const char *dw_fde_current_label;
264 const char *dw_fde_end;
265 const char *dw_fde_hot_section_label;
266 const char *dw_fde_hot_section_end_label;
267 const char *dw_fde_unlikely_section_label;
268 const char *dw_fde_unlikely_section_end_label;
269 bool dw_fde_switched_sections;
270 dw_cfi_ref dw_fde_cfi;
271 unsigned funcdef_number;
272 HOST_WIDE_INT stack_realignment;
273 /* Dynamic realign argument pointer register. */
274 unsigned int drap_reg;
275 /* Virtual dynamic realign argument pointer register. */
276 unsigned int vdrap_reg;
277 unsigned all_throwers_are_sibcalls : 1;
278 unsigned nothrow : 1;
279 unsigned uses_eh_lsda : 1;
280 /* Whether we did stack realign in this call frame. */
281 unsigned stack_realign : 1;
282 /* Whether dynamic realign argument pointer register has been saved. */
283 unsigned drap_reg_saved: 1;
287 /* Maximum size (in bytes) of an artificially generated label. */
288 #define MAX_ARTIFICIAL_LABEL_BYTES 30
290 /* The size of addresses as they appear in the Dwarf 2 data.
291 Some architectures use word addresses to refer to code locations,
292 but Dwarf 2 info always uses byte addresses. On such machines,
293 Dwarf 2 addresses need to be larger than the architecture's
295 #ifndef DWARF2_ADDR_SIZE
296 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
299 /* The size in bytes of a DWARF field indicating an offset or length
300 relative to a debug info section, specified to be 4 bytes in the
301 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
304 #ifndef DWARF_OFFSET_SIZE
305 #define DWARF_OFFSET_SIZE 4
308 /* According to the (draft) DWARF 3 specification, the initial length
309 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
310 bytes are 0xffffffff, followed by the length stored in the next 8
313 However, the SGI/MIPS ABI uses an initial length which is equal to
314 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
316 #ifndef DWARF_INITIAL_LENGTH_SIZE
317 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
320 #define DWARF_VERSION 2
322 /* Round SIZE up to the nearest BOUNDARY. */
323 #define DWARF_ROUND(SIZE,BOUNDARY) \
324 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
326 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
327 #ifndef DWARF_CIE_DATA_ALIGNMENT
328 #ifdef STACK_GROWS_DOWNWARD
329 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
331 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
335 /* CIE identifier. */
336 #if HOST_BITS_PER_WIDE_INT >= 64
337 #define DWARF_CIE_ID \
338 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
340 #define DWARF_CIE_ID DW_CIE_ID
343 /* A pointer to the base of a table that contains frame description
344 information for each routine. */
345 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
347 /* Number of elements currently allocated for fde_table. */
348 static GTY(()) unsigned fde_table_allocated;
350 /* Number of elements in fde_table currently in use. */
351 static GTY(()) unsigned fde_table_in_use;
353 /* Size (in elements) of increments by which we may expand the
355 #define FDE_TABLE_INCREMENT 256
357 /* Get the current fde_table entry we should use. */
359 static inline dw_fde_ref
362 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
365 /* A list of call frame insns for the CIE. */
366 static GTY(()) dw_cfi_ref cie_cfi_head;
368 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
369 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
370 attribute that accelerates the lookup of the FDE associated
371 with the subprogram. This variable holds the table index of the FDE
372 associated with the current function (body) definition. */
373 static unsigned current_funcdef_fde;
376 struct GTY(()) indirect_string_node {
378 unsigned int refcount;
379 enum dwarf_form form;
383 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
385 static GTY(()) int dw2_string_counter;
386 static GTY(()) unsigned long dwarf2out_cfi_label_num;
388 /* True if the compilation unit places functions in more than one section. */
389 static GTY(()) bool have_multiple_function_sections = false;
391 /* Whether the default text and cold text sections have been used at all. */
393 static GTY(()) bool text_section_used = false;
394 static GTY(()) bool cold_text_section_used = false;
396 /* The default cold text section. */
397 static GTY(()) section *cold_text_section;
399 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
401 /* Forward declarations for functions defined in this file. */
403 static char *stripattributes (const char *);
404 static const char *dwarf_cfi_name (unsigned);
405 static dw_cfi_ref new_cfi (void);
406 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
407 static void add_fde_cfi (const char *, dw_cfi_ref);
408 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
409 static void lookup_cfa (dw_cfa_location *);
410 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
411 #ifdef DWARF2_UNWIND_INFO
412 static void initial_return_save (rtx);
414 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
416 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
417 static void output_cfi_directive (dw_cfi_ref);
418 static void output_call_frame_info (int);
419 static void dwarf2out_note_section_used (void);
420 static void dwarf2out_stack_adjust (rtx, bool);
421 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
422 static void flush_queued_reg_saves (void);
423 static bool clobbers_queued_reg_save (const_rtx);
424 static void dwarf2out_frame_debug_expr (rtx, const char *);
426 /* Support for complex CFA locations. */
427 static void output_cfa_loc (dw_cfi_ref);
428 static void output_cfa_loc_raw (dw_cfi_ref);
429 static void get_cfa_from_loc_descr (dw_cfa_location *,
430 struct dw_loc_descr_struct *);
431 static struct dw_loc_descr_struct *build_cfa_loc
432 (dw_cfa_location *, HOST_WIDE_INT);
433 static struct dw_loc_descr_struct *build_cfa_aligned_loc
434 (HOST_WIDE_INT, HOST_WIDE_INT);
435 static void def_cfa_1 (const char *, dw_cfa_location *);
437 /* How to start an assembler comment. */
438 #ifndef ASM_COMMENT_START
439 #define ASM_COMMENT_START ";#"
442 /* Data and reference forms for relocatable data. */
443 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
444 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
446 #ifndef DEBUG_FRAME_SECTION
447 #define DEBUG_FRAME_SECTION ".debug_frame"
450 #ifndef FUNC_BEGIN_LABEL
451 #define FUNC_BEGIN_LABEL "LFB"
454 #ifndef FUNC_END_LABEL
455 #define FUNC_END_LABEL "LFE"
458 #ifndef FRAME_BEGIN_LABEL
459 #define FRAME_BEGIN_LABEL "Lframe"
461 #define CIE_AFTER_SIZE_LABEL "LSCIE"
462 #define CIE_END_LABEL "LECIE"
463 #define FDE_LABEL "LSFDE"
464 #define FDE_AFTER_SIZE_LABEL "LASFDE"
465 #define FDE_END_LABEL "LEFDE"
466 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
467 #define LINE_NUMBER_END_LABEL "LELT"
468 #define LN_PROLOG_AS_LABEL "LASLTP"
469 #define LN_PROLOG_END_LABEL "LELTP"
470 #define DIE_LABEL_PREFIX "DW"
472 /* The DWARF 2 CFA column which tracks the return address. Normally this
473 is the column for PC, or the first column after all of the hard
475 #ifndef DWARF_FRAME_RETURN_COLUMN
477 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
479 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
483 /* The mapping from gcc register number to DWARF 2 CFA column number. By
484 default, we just provide columns for all registers. */
485 #ifndef DWARF_FRAME_REGNUM
486 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
489 /* Hook used by __throw. */
492 expand_builtin_dwarf_sp_column (void)
494 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
495 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
498 /* Return a pointer to a copy of the section string name S with all
499 attributes stripped off, and an asterisk prepended (for assemble_name). */
502 stripattributes (const char *s)
504 char *stripped = XNEWVEC (char, strlen (s) + 2);
509 while (*s && *s != ',')
516 /* MEM is a memory reference for the register size table, each element of
517 which has mode MODE. Initialize column C as a return address column. */
520 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
522 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
523 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
524 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
527 /* Generate code to initialize the register size table. */
530 expand_builtin_init_dwarf_reg_sizes (tree address)
533 enum machine_mode mode = TYPE_MODE (char_type_node);
534 rtx addr = expand_normal (address);
535 rtx mem = gen_rtx_MEM (BLKmode, addr);
536 bool wrote_return_column = false;
538 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
540 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
542 if (rnum < DWARF_FRAME_REGISTERS)
544 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
545 enum machine_mode save_mode = reg_raw_mode[i];
548 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
549 save_mode = choose_hard_reg_mode (i, 1, true);
550 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
552 if (save_mode == VOIDmode)
554 wrote_return_column = true;
556 size = GET_MODE_SIZE (save_mode);
560 emit_move_insn (adjust_address (mem, mode, offset),
561 gen_int_mode (size, mode));
565 if (!wrote_return_column)
566 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
568 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
569 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
572 targetm.init_dwarf_reg_sizes_extra (address);
575 /* Convert a DWARF call frame info. operation to its string name */
578 dwarf_cfi_name (unsigned int cfi_opc)
582 case DW_CFA_advance_loc:
583 return "DW_CFA_advance_loc";
585 return "DW_CFA_offset";
587 return "DW_CFA_restore";
591 return "DW_CFA_set_loc";
592 case DW_CFA_advance_loc1:
593 return "DW_CFA_advance_loc1";
594 case DW_CFA_advance_loc2:
595 return "DW_CFA_advance_loc2";
596 case DW_CFA_advance_loc4:
597 return "DW_CFA_advance_loc4";
598 case DW_CFA_offset_extended:
599 return "DW_CFA_offset_extended";
600 case DW_CFA_restore_extended:
601 return "DW_CFA_restore_extended";
602 case DW_CFA_undefined:
603 return "DW_CFA_undefined";
604 case DW_CFA_same_value:
605 return "DW_CFA_same_value";
606 case DW_CFA_register:
607 return "DW_CFA_register";
608 case DW_CFA_remember_state:
609 return "DW_CFA_remember_state";
610 case DW_CFA_restore_state:
611 return "DW_CFA_restore_state";
613 return "DW_CFA_def_cfa";
614 case DW_CFA_def_cfa_register:
615 return "DW_CFA_def_cfa_register";
616 case DW_CFA_def_cfa_offset:
617 return "DW_CFA_def_cfa_offset";
620 case DW_CFA_def_cfa_expression:
621 return "DW_CFA_def_cfa_expression";
622 case DW_CFA_expression:
623 return "DW_CFA_expression";
624 case DW_CFA_offset_extended_sf:
625 return "DW_CFA_offset_extended_sf";
626 case DW_CFA_def_cfa_sf:
627 return "DW_CFA_def_cfa_sf";
628 case DW_CFA_def_cfa_offset_sf:
629 return "DW_CFA_def_cfa_offset_sf";
631 /* SGI/MIPS specific */
632 case DW_CFA_MIPS_advance_loc8:
633 return "DW_CFA_MIPS_advance_loc8";
636 case DW_CFA_GNU_window_save:
637 return "DW_CFA_GNU_window_save";
638 case DW_CFA_GNU_args_size:
639 return "DW_CFA_GNU_args_size";
640 case DW_CFA_GNU_negative_offset_extended:
641 return "DW_CFA_GNU_negative_offset_extended";
644 return "DW_CFA_<unknown>";
648 /* Return a pointer to a newly allocated Call Frame Instruction. */
650 static inline dw_cfi_ref
653 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
655 cfi->dw_cfi_next = NULL;
656 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
657 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
662 /* Add a Call Frame Instruction to list of instructions. */
665 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
668 dw_fde_ref fde = current_fde ();
670 /* When DRAP is used, CFA is defined with an expression. Redefine
671 CFA may lead to a different CFA value. */
672 /* ??? Of course, this heuristic fails when we're annotating epilogues,
673 because of course we'll always want to redefine the CFA back to the
674 stack pointer on the way out. Where should we move this check? */
675 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
676 switch (cfi->dw_cfi_opc)
678 case DW_CFA_def_cfa_register:
679 case DW_CFA_def_cfa_offset:
680 case DW_CFA_def_cfa_offset_sf:
682 case DW_CFA_def_cfa_sf:
689 /* Find the end of the chain. */
690 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
696 /* Generate a new label for the CFI info to refer to. */
699 dwarf2out_cfi_label (void)
701 static char label[20];
703 if (dwarf2out_do_cfi_asm ())
705 /* In this case, we will be emitting the asm directive instead of
706 the label, so just return a placeholder to keep the rest of the
708 strcpy (label, "<do not output>");
712 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
713 ASM_OUTPUT_LABEL (asm_out_file, label);
719 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
720 or to the CIE if LABEL is NULL. */
723 add_fde_cfi (const char *label, dw_cfi_ref cfi)
725 dw_cfi_ref *list_head = &cie_cfi_head;
727 if (dwarf2out_do_cfi_asm ())
731 output_cfi_directive (cfi);
733 /* We still have to add the cfi to the list so that
734 lookup_cfa works later on. */
735 list_head = ¤t_fde ()->dw_fde_cfi;
737 /* ??? If this is a CFI for the CIE, we don't emit. This
738 assumes that the standard CIE contents that the assembler
739 uses matches the standard CIE contents that the compiler
740 uses. This is probably a bad assumption. I'm not quite
741 sure how to address this for now. */
745 dw_fde_ref fde = current_fde ();
747 gcc_assert (fde != NULL);
750 label = dwarf2out_cfi_label ();
752 if (fde->dw_fde_current_label == NULL
753 || strcmp (label, fde->dw_fde_current_label) != 0)
757 label = xstrdup (label);
759 /* Set the location counter to the new label. */
761 /* If we have a current label, advance from there, otherwise
762 set the location directly using set_loc. */
763 xcfi->dw_cfi_opc = fde->dw_fde_current_label
764 ? DW_CFA_advance_loc4
766 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
767 add_cfi (&fde->dw_fde_cfi, xcfi);
769 fde->dw_fde_current_label = label;
772 list_head = &fde->dw_fde_cfi;
775 add_cfi (list_head, cfi);
778 /* Subroutine of lookup_cfa. */
781 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
783 switch (cfi->dw_cfi_opc)
785 case DW_CFA_def_cfa_offset:
786 case DW_CFA_def_cfa_offset_sf:
787 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
789 case DW_CFA_def_cfa_register:
790 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
793 case DW_CFA_def_cfa_sf:
794 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
795 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
797 case DW_CFA_def_cfa_expression:
798 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
801 case DW_CFA_remember_state:
802 gcc_assert (!remember->in_use);
804 remember->in_use = 1;
806 case DW_CFA_restore_state:
807 gcc_assert (remember->in_use);
809 remember->in_use = 0;
817 /* Find the previous value for the CFA. */
820 lookup_cfa (dw_cfa_location *loc)
824 dw_cfa_location remember;
826 memset (loc, 0, sizeof (*loc));
827 loc->reg = INVALID_REGNUM;
830 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
831 lookup_cfa_1 (cfi, loc, &remember);
833 fde = current_fde ();
835 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
836 lookup_cfa_1 (cfi, loc, &remember);
839 /* The current rule for calculating the DWARF2 canonical frame address. */
840 static dw_cfa_location cfa;
842 /* The register used for saving registers to the stack, and its offset
844 static dw_cfa_location cfa_store;
846 /* The current save location around an epilogue. */
847 static dw_cfa_location cfa_remember;
849 /* The running total of the size of arguments pushed onto the stack. */
850 static HOST_WIDE_INT args_size;
852 /* The last args_size we actually output. */
853 static HOST_WIDE_INT old_args_size;
855 /* Entry point to update the canonical frame address (CFA).
856 LABEL is passed to add_fde_cfi. The value of CFA is now to be
857 calculated from REG+OFFSET. */
860 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
867 def_cfa_1 (label, &loc);
870 /* Determine if two dw_cfa_location structures define the same data. */
873 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
875 return (loc1->reg == loc2->reg
876 && loc1->offset == loc2->offset
877 && loc1->indirect == loc2->indirect
878 && (loc1->indirect == 0
879 || loc1->base_offset == loc2->base_offset));
882 /* This routine does the actual work. The CFA is now calculated from
883 the dw_cfa_location structure. */
886 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
889 dw_cfa_location old_cfa, loc;
894 if (cfa_store.reg == loc.reg && loc.indirect == 0)
895 cfa_store.offset = loc.offset;
897 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
898 lookup_cfa (&old_cfa);
900 /* If nothing changed, no need to issue any call frame instructions. */
901 if (cfa_equal_p (&loc, &old_cfa))
906 if (loc.reg == old_cfa.reg && !loc.indirect)
908 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
909 the CFA register did not change but the offset did. The data
910 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
911 in the assembler via the .cfi_def_cfa_offset directive. */
913 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
915 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
916 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
919 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
920 else if (loc.offset == old_cfa.offset
921 && old_cfa.reg != INVALID_REGNUM
924 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
925 indicating the CFA register has changed to <register> but the
926 offset has not changed. */
927 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
928 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
932 else if (loc.indirect == 0)
934 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
935 indicating the CFA register has changed to <register> with
936 the specified offset. The data factoring for DW_CFA_def_cfa_sf
937 happens in output_cfi, or in the assembler via the .cfi_def_cfa
940 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
942 cfi->dw_cfi_opc = DW_CFA_def_cfa;
943 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
944 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
948 /* Construct a DW_CFA_def_cfa_expression instruction to
949 calculate the CFA using a full location expression since no
950 register-offset pair is available. */
951 struct dw_loc_descr_struct *loc_list;
953 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
954 loc_list = build_cfa_loc (&loc, 0);
955 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
958 add_fde_cfi (label, cfi);
961 /* Add the CFI for saving a register. REG is the CFA column number.
962 LABEL is passed to add_fde_cfi.
963 If SREG is -1, the register is saved at OFFSET from the CFA;
964 otherwise it is saved in SREG. */
967 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
969 dw_cfi_ref cfi = new_cfi ();
970 dw_fde_ref fde = current_fde ();
972 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
974 /* When stack is aligned, store REG using DW_CFA_expression with
977 && fde->stack_realign
978 && sreg == INVALID_REGNUM)
980 cfi->dw_cfi_opc = DW_CFA_expression;
981 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
982 cfi->dw_cfi_oprnd1.dw_cfi_loc
983 = build_cfa_aligned_loc (offset, fde->stack_realignment);
985 else if (sreg == INVALID_REGNUM)
988 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
989 else if (reg & ~0x3f)
990 cfi->dw_cfi_opc = DW_CFA_offset_extended;
992 cfi->dw_cfi_opc = DW_CFA_offset;
993 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
995 else if (sreg == reg)
996 cfi->dw_cfi_opc = DW_CFA_same_value;
999 cfi->dw_cfi_opc = DW_CFA_register;
1000 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1003 add_fde_cfi (label, cfi);
1006 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1007 This CFI tells the unwinder that it needs to restore the window registers
1008 from the previous frame's window save area.
1010 ??? Perhaps we should note in the CIE where windows are saved (instead of
1011 assuming 0(cfa)) and what registers are in the window. */
1014 dwarf2out_window_save (const char *label)
1016 dw_cfi_ref cfi = new_cfi ();
1018 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1019 add_fde_cfi (label, cfi);
1022 /* Add a CFI to update the running total of the size of arguments
1023 pushed onto the stack. */
1026 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1030 if (size == old_args_size)
1033 old_args_size = size;
1036 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1037 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1038 add_fde_cfi (label, cfi);
1041 /* Entry point for saving a register to the stack. REG is the GCC register
1042 number. LABEL and OFFSET are passed to reg_save. */
1045 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1047 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1050 /* Entry point for saving the return address in the stack.
1051 LABEL and OFFSET are passed to reg_save. */
1054 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1056 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1059 /* Entry point for saving the return address in a register.
1060 LABEL and SREG are passed to reg_save. */
1063 dwarf2out_return_reg (const char *label, unsigned int sreg)
1065 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1068 #ifdef DWARF2_UNWIND_INFO
1069 /* Record the initial position of the return address. RTL is
1070 INCOMING_RETURN_ADDR_RTX. */
1073 initial_return_save (rtx rtl)
1075 unsigned int reg = INVALID_REGNUM;
1076 HOST_WIDE_INT offset = 0;
1078 switch (GET_CODE (rtl))
1081 /* RA is in a register. */
1082 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1086 /* RA is on the stack. */
1087 rtl = XEXP (rtl, 0);
1088 switch (GET_CODE (rtl))
1091 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1096 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1097 offset = INTVAL (XEXP (rtl, 1));
1101 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1102 offset = -INTVAL (XEXP (rtl, 1));
1112 /* The return address is at some offset from any value we can
1113 actually load. For instance, on the SPARC it is in %i7+8. Just
1114 ignore the offset for now; it doesn't matter for unwinding frames. */
1115 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1116 initial_return_save (XEXP (rtl, 0));
1123 if (reg != DWARF_FRAME_RETURN_COLUMN)
1124 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1128 /* Given a SET, calculate the amount of stack adjustment it
1131 static HOST_WIDE_INT
1132 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1133 HOST_WIDE_INT cur_offset)
1135 const_rtx src = SET_SRC (pattern);
1136 const_rtx dest = SET_DEST (pattern);
1137 HOST_WIDE_INT offset = 0;
1140 if (dest == stack_pointer_rtx)
1142 code = GET_CODE (src);
1144 /* Assume (set (reg sp) (reg whatever)) sets args_size
1146 if (code == REG && src != stack_pointer_rtx)
1148 offset = -cur_args_size;
1149 #ifndef STACK_GROWS_DOWNWARD
1152 return offset - cur_offset;
1155 if (! (code == PLUS || code == MINUS)
1156 || XEXP (src, 0) != stack_pointer_rtx
1157 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1160 /* (set (reg sp) (plus (reg sp) (const_int))) */
1161 offset = INTVAL (XEXP (src, 1));
1167 if (MEM_P (src) && !MEM_P (dest))
1171 /* (set (mem (pre_dec (reg sp))) (foo)) */
1172 src = XEXP (dest, 0);
1173 code = GET_CODE (src);
1179 if (XEXP (src, 0) == stack_pointer_rtx)
1181 rtx val = XEXP (XEXP (src, 1), 1);
1182 /* We handle only adjustments by constant amount. */
1183 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1184 && GET_CODE (val) == CONST_INT);
1185 offset = -INTVAL (val);
1192 if (XEXP (src, 0) == stack_pointer_rtx)
1194 offset = GET_MODE_SIZE (GET_MODE (dest));
1201 if (XEXP (src, 0) == stack_pointer_rtx)
1203 offset = -GET_MODE_SIZE (GET_MODE (dest));
1218 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1219 indexed by INSN_UID. */
1221 static HOST_WIDE_INT *barrier_args_size;
1223 /* Helper function for compute_barrier_args_size. Handle one insn. */
1225 static HOST_WIDE_INT
1226 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1227 VEC (rtx, heap) **next)
1229 HOST_WIDE_INT offset = 0;
1232 if (! RTX_FRAME_RELATED_P (insn))
1234 if (prologue_epilogue_contains (insn))
1236 else if (GET_CODE (PATTERN (insn)) == SET)
1237 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1238 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1239 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1241 /* There may be stack adjustments inside compound insns. Search
1243 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1244 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1245 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1246 cur_args_size, offset);
1251 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1255 expr = XEXP (expr, 0);
1256 if (GET_CODE (expr) == PARALLEL
1257 || GET_CODE (expr) == SEQUENCE)
1258 for (i = 1; i < XVECLEN (expr, 0); i++)
1260 rtx elem = XVECEXP (expr, 0, i);
1262 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1263 offset += stack_adjust_offset (elem, cur_args_size, offset);
1268 #ifndef STACK_GROWS_DOWNWARD
1272 cur_args_size += offset;
1273 if (cur_args_size < 0)
1278 rtx dest = JUMP_LABEL (insn);
1282 if (barrier_args_size [INSN_UID (dest)] < 0)
1284 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1285 VEC_safe_push (rtx, heap, *next, dest);
1290 return cur_args_size;
1293 /* Walk the whole function and compute args_size on BARRIERs. */
1296 compute_barrier_args_size (void)
1298 int max_uid = get_max_uid (), i;
1300 VEC (rtx, heap) *worklist, *next, *tmp;
1302 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1303 for (i = 0; i < max_uid; i++)
1304 barrier_args_size[i] = -1;
1306 worklist = VEC_alloc (rtx, heap, 20);
1307 next = VEC_alloc (rtx, heap, 20);
1308 insn = get_insns ();
1309 barrier_args_size[INSN_UID (insn)] = 0;
1310 VEC_quick_push (rtx, worklist, insn);
1313 while (!VEC_empty (rtx, worklist))
1315 rtx prev, body, first_insn;
1316 HOST_WIDE_INT cur_args_size;
1318 first_insn = insn = VEC_pop (rtx, worklist);
1319 cur_args_size = barrier_args_size[INSN_UID (insn)];
1320 prev = prev_nonnote_insn (insn);
1321 if (prev && BARRIER_P (prev))
1322 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1324 for (; insn; insn = NEXT_INSN (insn))
1326 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1328 if (BARRIER_P (insn))
1333 if (insn == first_insn)
1335 else if (barrier_args_size[INSN_UID (insn)] < 0)
1337 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1342 /* The insns starting with this label have been
1343 already scanned or are in the worklist. */
1348 body = PATTERN (insn);
1349 if (GET_CODE (body) == SEQUENCE)
1351 HOST_WIDE_INT dest_args_size = cur_args_size;
1352 for (i = 1; i < XVECLEN (body, 0); i++)
1353 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1354 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1356 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1357 dest_args_size, &next);
1360 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1361 cur_args_size, &next);
1363 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1364 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1365 dest_args_size, &next);
1368 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1369 cur_args_size, &next);
1373 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1377 if (VEC_empty (rtx, next))
1380 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1384 VEC_truncate (rtx, next, 0);
1387 VEC_free (rtx, heap, worklist);
1388 VEC_free (rtx, heap, next);
1392 /* Check INSN to see if it looks like a push or a stack adjustment, and
1393 make a note of it if it does. EH uses this information to find out how
1394 much extra space it needs to pop off the stack. */
1397 dwarf2out_stack_adjust (rtx insn, bool after_p)
1399 HOST_WIDE_INT offset;
1403 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1404 with this function. Proper support would require all frame-related
1405 insns to be marked, and to be able to handle saving state around
1406 epilogues textually in the middle of the function. */
1407 if (prologue_epilogue_contains (insn))
1410 /* If INSN is an instruction from target of an annulled branch, the
1411 effects are for the target only and so current argument size
1412 shouldn't change at all. */
1414 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1415 && INSN_FROM_TARGET_P (insn))
1418 /* If only calls can throw, and we have a frame pointer,
1419 save up adjustments until we see the CALL_INSN. */
1420 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1422 if (CALL_P (insn) && !after_p)
1424 /* Extract the size of the args from the CALL rtx itself. */
1425 insn = PATTERN (insn);
1426 if (GET_CODE (insn) == PARALLEL)
1427 insn = XVECEXP (insn, 0, 0);
1428 if (GET_CODE (insn) == SET)
1429 insn = SET_SRC (insn);
1430 gcc_assert (GET_CODE (insn) == CALL);
1431 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1436 if (CALL_P (insn) && !after_p)
1438 if (!flag_asynchronous_unwind_tables)
1439 dwarf2out_args_size ("", args_size);
1442 else if (BARRIER_P (insn))
1444 /* Don't call compute_barrier_args_size () if the only
1445 BARRIER is at the end of function. */
1446 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1447 compute_barrier_args_size ();
1448 if (barrier_args_size == NULL)
1452 offset = barrier_args_size[INSN_UID (insn)];
1457 offset -= args_size;
1458 #ifndef STACK_GROWS_DOWNWARD
1462 else if (GET_CODE (PATTERN (insn)) == SET)
1463 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1464 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1465 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1467 /* There may be stack adjustments inside compound insns. Search
1469 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1470 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1471 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1480 label = dwarf2out_cfi_label ();
1481 dwarf2out_args_size_adjust (offset, label);
1484 /* Adjust args_size based on stack adjustment OFFSET. */
1487 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1489 if (cfa.reg == STACK_POINTER_REGNUM)
1490 cfa.offset += offset;
1492 if (cfa_store.reg == STACK_POINTER_REGNUM)
1493 cfa_store.offset += offset;
1495 #ifndef STACK_GROWS_DOWNWARD
1499 args_size += offset;
1503 def_cfa_1 (label, &cfa);
1504 if (flag_asynchronous_unwind_tables)
1505 dwarf2out_args_size (label, args_size);
1510 /* We delay emitting a register save until either (a) we reach the end
1511 of the prologue or (b) the register is clobbered. This clusters
1512 register saves so that there are fewer pc advances. */
1514 struct GTY(()) queued_reg_save {
1515 struct queued_reg_save *next;
1517 HOST_WIDE_INT cfa_offset;
1521 static GTY(()) struct queued_reg_save *queued_reg_saves;
1523 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1524 struct GTY(()) reg_saved_in_data {
1529 /* A list of registers saved in other registers.
1530 The list intentionally has a small maximum capacity of 4; if your
1531 port needs more than that, you might consider implementing a
1532 more efficient data structure. */
1533 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1534 static GTY(()) size_t num_regs_saved_in_regs;
1536 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1537 static const char *last_reg_save_label;
1539 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1540 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1543 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1545 struct queued_reg_save *q;
1547 /* Duplicates waste space, but it's also necessary to remove them
1548 for correctness, since the queue gets output in reverse
1550 for (q = queued_reg_saves; q != NULL; q = q->next)
1551 if (REGNO (q->reg) == REGNO (reg))
1556 q = GGC_NEW (struct queued_reg_save);
1557 q->next = queued_reg_saves;
1558 queued_reg_saves = q;
1562 q->cfa_offset = offset;
1563 q->saved_reg = sreg;
1565 last_reg_save_label = label;
1568 /* Output all the entries in QUEUED_REG_SAVES. */
1571 flush_queued_reg_saves (void)
1573 struct queued_reg_save *q;
1575 for (q = queued_reg_saves; q; q = q->next)
1578 unsigned int reg, sreg;
1580 for (i = 0; i < num_regs_saved_in_regs; i++)
1581 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1583 if (q->saved_reg && i == num_regs_saved_in_regs)
1585 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1586 num_regs_saved_in_regs++;
1588 if (i != num_regs_saved_in_regs)
1590 regs_saved_in_regs[i].orig_reg = q->reg;
1591 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1594 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1596 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1598 sreg = INVALID_REGNUM;
1599 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1602 queued_reg_saves = NULL;
1603 last_reg_save_label = NULL;
1606 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1607 location for? Or, does it clobber a register which we've previously
1608 said that some other register is saved in, and for which we now
1609 have a new location for? */
1612 clobbers_queued_reg_save (const_rtx insn)
1614 struct queued_reg_save *q;
1616 for (q = queued_reg_saves; q; q = q->next)
1619 if (modified_in_p (q->reg, insn))
1621 for (i = 0; i < num_regs_saved_in_regs; i++)
1622 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1623 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1630 /* Entry point for saving the first register into the second. */
1633 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1636 unsigned int regno, sregno;
1638 for (i = 0; i < num_regs_saved_in_regs; i++)
1639 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1641 if (i == num_regs_saved_in_regs)
1643 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1644 num_regs_saved_in_regs++;
1646 regs_saved_in_regs[i].orig_reg = reg;
1647 regs_saved_in_regs[i].saved_in_reg = sreg;
1649 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1650 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1651 reg_save (label, regno, sregno, 0);
1654 /* What register, if any, is currently saved in REG? */
1657 reg_saved_in (rtx reg)
1659 unsigned int regn = REGNO (reg);
1661 struct queued_reg_save *q;
1663 for (q = queued_reg_saves; q; q = q->next)
1664 if (q->saved_reg && regn == REGNO (q->saved_reg))
1667 for (i = 0; i < num_regs_saved_in_regs; i++)
1668 if (regs_saved_in_regs[i].saved_in_reg
1669 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1670 return regs_saved_in_regs[i].orig_reg;
1676 /* A temporary register holding an integral value used in adjusting SP
1677 or setting up the store_reg. The "offset" field holds the integer
1678 value, not an offset. */
1679 static dw_cfa_location cfa_temp;
1681 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1684 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1686 memset (&cfa, 0, sizeof (cfa));
1688 switch (GET_CODE (pat))
1691 cfa.reg = REGNO (XEXP (pat, 0));
1692 cfa.offset = INTVAL (XEXP (pat, 1));
1696 cfa.reg = REGNO (pat);
1700 /* Recurse and define an expression. */
1704 def_cfa_1 (label, &cfa);
1707 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1710 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1714 gcc_assert (GET_CODE (pat) == SET);
1715 dest = XEXP (pat, 0);
1716 src = XEXP (pat, 1);
1718 switch (GET_CODE (src))
1721 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1722 cfa.offset -= INTVAL (XEXP (src, 1));
1732 cfa.reg = REGNO (dest);
1733 gcc_assert (cfa.indirect == 0);
1735 def_cfa_1 (label, &cfa);
1738 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1741 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1743 HOST_WIDE_INT offset;
1744 rtx src, addr, span;
1746 src = XEXP (set, 1);
1747 addr = XEXP (set, 0);
1748 gcc_assert (MEM_P (addr));
1749 addr = XEXP (addr, 0);
1751 /* As documented, only consider extremely simple addresses. */
1752 switch (GET_CODE (addr))
1755 gcc_assert (REGNO (addr) == cfa.reg);
1756 offset = -cfa.offset;
1759 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1760 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1766 span = targetm.dwarf_register_span (src);
1768 /* ??? We'd like to use queue_reg_save, but we need to come up with
1769 a different flushing heuristic for epilogues. */
1771 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
1774 /* We have a PARALLEL describing where the contents of SRC live.
1775 Queue register saves for each piece of the PARALLEL. */
1778 HOST_WIDE_INT span_offset = offset;
1780 gcc_assert (GET_CODE (span) == PARALLEL);
1782 limit = XVECLEN (span, 0);
1783 for (par_index = 0; par_index < limit; par_index++)
1785 rtx elem = XVECEXP (span, 0, par_index);
1787 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
1788 INVALID_REGNUM, span_offset);
1789 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1794 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1797 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
1800 unsigned sregno, dregno;
1802 src = XEXP (set, 1);
1803 dest = XEXP (set, 0);
1806 sregno = DWARF_FRAME_RETURN_COLUMN;
1808 sregno = DWARF_FRAME_REGNUM (REGNO (src));
1810 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
1812 /* ??? We'd like to use queue_reg_save, but we need to come up with
1813 a different flushing heuristic for epilogues. */
1814 reg_save (label, sregno, dregno, 0);
1817 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1820 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
1822 dw_cfi_ref cfi = new_cfi ();
1823 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
1825 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
1826 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1828 add_fde_cfi (label, cfi);
1831 /* Record call frame debugging information for an expression EXPR,
1832 which either sets SP or FP (adjusting how we calculate the frame
1833 address) or saves a register to the stack or another register.
1834 LABEL indicates the address of EXPR.
1836 This function encodes a state machine mapping rtxes to actions on
1837 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1838 users need not read the source code.
1840 The High-Level Picture
1842 Changes in the register we use to calculate the CFA: Currently we
1843 assume that if you copy the CFA register into another register, we
1844 should take the other one as the new CFA register; this seems to
1845 work pretty well. If it's wrong for some target, it's simple
1846 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1848 Changes in the register we use for saving registers to the stack:
1849 This is usually SP, but not always. Again, we deduce that if you
1850 copy SP into another register (and SP is not the CFA register),
1851 then the new register is the one we will be using for register
1852 saves. This also seems to work.
1854 Register saves: There's not much guesswork about this one; if
1855 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1856 register save, and the register used to calculate the destination
1857 had better be the one we think we're using for this purpose.
1858 It's also assumed that a copy from a call-saved register to another
1859 register is saving that register if RTX_FRAME_RELATED_P is set on
1860 that instruction. If the copy is from a call-saved register to
1861 the *same* register, that means that the register is now the same
1862 value as in the caller.
1864 Except: If the register being saved is the CFA register, and the
1865 offset is nonzero, we are saving the CFA, so we assume we have to
1866 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1867 the intent is to save the value of SP from the previous frame.
1869 In addition, if a register has previously been saved to a different
1872 Invariants / Summaries of Rules
1874 cfa current rule for calculating the CFA. It usually
1875 consists of a register and an offset.
1876 cfa_store register used by prologue code to save things to the stack
1877 cfa_store.offset is the offset from the value of
1878 cfa_store.reg to the actual CFA
1879 cfa_temp register holding an integral value. cfa_temp.offset
1880 stores the value, which will be used to adjust the
1881 stack pointer. cfa_temp is also used like cfa_store,
1882 to track stores to the stack via fp or a temp reg.
1884 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1885 with cfa.reg as the first operand changes the cfa.reg and its
1886 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1889 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1890 expression yielding a constant. This sets cfa_temp.reg
1891 and cfa_temp.offset.
1893 Rule 5: Create a new register cfa_store used to save items to the
1896 Rules 10-14: Save a register to the stack. Define offset as the
1897 difference of the original location and cfa_store's
1898 location (or cfa_temp's location if cfa_temp is used).
1900 Rules 16-20: If AND operation happens on sp in prologue, we assume
1901 stack is realigned. We will use a group of DW_OP_XXX
1902 expressions to represent the location of the stored
1903 register instead of CFA+offset.
1907 "{a,b}" indicates a choice of a xor b.
1908 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1911 (set <reg1> <reg2>:cfa.reg)
1912 effects: cfa.reg = <reg1>
1913 cfa.offset unchanged
1914 cfa_temp.reg = <reg1>
1915 cfa_temp.offset = cfa.offset
1918 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1919 {<const_int>,<reg>:cfa_temp.reg}))
1920 effects: cfa.reg = sp if fp used
1921 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1922 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1923 if cfa_store.reg==sp
1926 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1927 effects: cfa.reg = fp
1928 cfa_offset += +/- <const_int>
1931 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1932 constraints: <reg1> != fp
1934 effects: cfa.reg = <reg1>
1935 cfa_temp.reg = <reg1>
1936 cfa_temp.offset = cfa.offset
1939 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1940 constraints: <reg1> != fp
1942 effects: cfa_store.reg = <reg1>
1943 cfa_store.offset = cfa.offset - cfa_temp.offset
1946 (set <reg> <const_int>)
1947 effects: cfa_temp.reg = <reg>
1948 cfa_temp.offset = <const_int>
1951 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1952 effects: cfa_temp.reg = <reg1>
1953 cfa_temp.offset |= <const_int>
1956 (set <reg> (high <exp>))
1960 (set <reg> (lo_sum <exp> <const_int>))
1961 effects: cfa_temp.reg = <reg>
1962 cfa_temp.offset = <const_int>
1965 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1966 effects: cfa_store.offset -= <const_int>
1967 cfa.offset = cfa_store.offset if cfa.reg == sp
1969 cfa.base_offset = -cfa_store.offset
1972 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1973 effects: cfa_store.offset += -/+ mode_size(mem)
1974 cfa.offset = cfa_store.offset if cfa.reg == sp
1976 cfa.base_offset = -cfa_store.offset
1979 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1982 effects: cfa.reg = <reg1>
1983 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1986 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1987 effects: cfa.reg = <reg1>
1988 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1991 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1992 effects: cfa.reg = <reg1>
1993 cfa.base_offset = -cfa_temp.offset
1994 cfa_temp.offset -= mode_size(mem)
1997 (set <reg> {unspec, unspec_volatile})
1998 effects: target-dependent
2001 (set sp (and: sp <const_int>))
2002 constraints: cfa_store.reg == sp
2003 effects: current_fde.stack_realign = 1
2004 cfa_store.offset = 0
2005 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2008 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2009 effects: cfa_store.offset += -/+ mode_size(mem)
2012 (set (mem ({pre_inc, pre_dec} sp)) fp)
2013 constraints: fde->stack_realign == 1
2014 effects: cfa_store.offset = 0
2015 cfa.reg != HARD_FRAME_POINTER_REGNUM
2018 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2019 constraints: fde->stack_realign == 1
2021 && cfa.indirect == 0
2022 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2023 effects: Use DW_CFA_def_cfa_expression to define cfa
2024 cfa.reg == fde->drap_reg
2027 (set reg fde->drap_reg)
2028 constraints: fde->vdrap_reg == INVALID_REGNUM
2029 effects: fde->vdrap_reg = reg.
2030 (set mem fde->drap_reg)
2031 constraints: fde->drap_reg_saved == 1
2035 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2037 rtx src, dest, span;
2038 HOST_WIDE_INT offset;
2041 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2042 the PARALLEL independently. The first element is always processed if
2043 it is a SET. This is for backward compatibility. Other elements
2044 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2045 flag is set in them. */
2046 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2049 int limit = XVECLEN (expr, 0);
2052 /* PARALLELs have strict read-modify-write semantics, so we
2053 ought to evaluate every rvalue before changing any lvalue.
2054 It's cumbersome to do that in general, but there's an
2055 easy approximation that is enough for all current users:
2056 handle register saves before register assignments. */
2057 if (GET_CODE (expr) == PARALLEL)
2058 for (par_index = 0; par_index < limit; par_index++)
2060 elem = XVECEXP (expr, 0, par_index);
2061 if (GET_CODE (elem) == SET
2062 && MEM_P (SET_DEST (elem))
2063 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2064 dwarf2out_frame_debug_expr (elem, label);
2067 for (par_index = 0; par_index < limit; par_index++)
2069 elem = XVECEXP (expr, 0, par_index);
2070 if (GET_CODE (elem) == SET
2071 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2072 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2073 dwarf2out_frame_debug_expr (elem, label);
2074 else if (GET_CODE (elem) == SET
2076 && !RTX_FRAME_RELATED_P (elem))
2078 /* Stack adjustment combining might combine some post-prologue
2079 stack adjustment into a prologue stack adjustment. */
2080 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2083 dwarf2out_args_size_adjust (offset, label);
2089 gcc_assert (GET_CODE (expr) == SET);
2091 src = SET_SRC (expr);
2092 dest = SET_DEST (expr);
2096 rtx rsi = reg_saved_in (src);
2101 fde = current_fde ();
2103 if (GET_CODE (src) == REG
2105 && fde->drap_reg == REGNO (src)
2106 && (fde->drap_reg_saved
2107 || GET_CODE (dest) == REG))
2110 /* If we are saving dynamic realign argument pointer to a
2111 register, the destination is virtual dynamic realign
2112 argument pointer. It may be used to access argument. */
2113 if (GET_CODE (dest) == REG)
2115 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2116 fde->vdrap_reg = REGNO (dest);
2121 switch (GET_CODE (dest))
2124 switch (GET_CODE (src))
2126 /* Setting FP from SP. */
2128 if (cfa.reg == (unsigned) REGNO (src))
2131 /* Update the CFA rule wrt SP or FP. Make sure src is
2132 relative to the current CFA register.
2134 We used to require that dest be either SP or FP, but the
2135 ARM copies SP to a temporary register, and from there to
2136 FP. So we just rely on the backends to only set
2137 RTX_FRAME_RELATED_P on appropriate insns. */
2138 cfa.reg = REGNO (dest);
2139 cfa_temp.reg = cfa.reg;
2140 cfa_temp.offset = cfa.offset;
2144 /* Saving a register in a register. */
2145 gcc_assert (!fixed_regs [REGNO (dest)]
2146 /* For the SPARC and its register window. */
2147 || (DWARF_FRAME_REGNUM (REGNO (src))
2148 == DWARF_FRAME_RETURN_COLUMN));
2150 /* After stack is aligned, we can only save SP in FP
2151 if drap register is used. In this case, we have
2152 to restore stack pointer with the CFA value and we
2153 don't generate this DWARF information. */
2155 && fde->stack_realign
2156 && REGNO (src) == STACK_POINTER_REGNUM)
2157 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2158 && fde->drap_reg != INVALID_REGNUM
2159 && cfa.reg != REGNO (src));
2161 queue_reg_save (label, src, dest, 0);
2168 if (dest == stack_pointer_rtx)
2172 switch (GET_CODE (XEXP (src, 1)))
2175 offset = INTVAL (XEXP (src, 1));
2178 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2180 offset = cfa_temp.offset;
2186 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2188 /* Restoring SP from FP in the epilogue. */
2189 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2190 cfa.reg = STACK_POINTER_REGNUM;
2192 else if (GET_CODE (src) == LO_SUM)
2193 /* Assume we've set the source reg of the LO_SUM from sp. */
2196 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2198 if (GET_CODE (src) != MINUS)
2200 if (cfa.reg == STACK_POINTER_REGNUM)
2201 cfa.offset += offset;
2202 if (cfa_store.reg == STACK_POINTER_REGNUM)
2203 cfa_store.offset += offset;
2205 else if (dest == hard_frame_pointer_rtx)
2208 /* Either setting the FP from an offset of the SP,
2209 or adjusting the FP */
2210 gcc_assert (frame_pointer_needed);
2212 gcc_assert (REG_P (XEXP (src, 0))
2213 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2214 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2215 offset = INTVAL (XEXP (src, 1));
2216 if (GET_CODE (src) != MINUS)
2218 cfa.offset += offset;
2219 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2223 gcc_assert (GET_CODE (src) != MINUS);
2226 if (REG_P (XEXP (src, 0))
2227 && REGNO (XEXP (src, 0)) == cfa.reg
2228 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2230 /* Setting a temporary CFA register that will be copied
2231 into the FP later on. */
2232 offset = - INTVAL (XEXP (src, 1));
2233 cfa.offset += offset;
2234 cfa.reg = REGNO (dest);
2235 /* Or used to save regs to the stack. */
2236 cfa_temp.reg = cfa.reg;
2237 cfa_temp.offset = cfa.offset;
2241 else if (REG_P (XEXP (src, 0))
2242 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2243 && XEXP (src, 1) == stack_pointer_rtx)
2245 /* Setting a scratch register that we will use instead
2246 of SP for saving registers to the stack. */
2247 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2248 cfa_store.reg = REGNO (dest);
2249 cfa_store.offset = cfa.offset - cfa_temp.offset;
2253 else if (GET_CODE (src) == LO_SUM
2254 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2256 cfa_temp.reg = REGNO (dest);
2257 cfa_temp.offset = INTVAL (XEXP (src, 1));
2266 cfa_temp.reg = REGNO (dest);
2267 cfa_temp.offset = INTVAL (src);
2272 gcc_assert (REG_P (XEXP (src, 0))
2273 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2274 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2276 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2277 cfa_temp.reg = REGNO (dest);
2278 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2281 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2282 which will fill in all of the bits. */
2289 case UNSPEC_VOLATILE:
2290 gcc_assert (targetm.dwarf_handle_frame_unspec);
2291 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2296 /* If this AND operation happens on stack pointer in prologue,
2297 we assume the stack is realigned and we extract the
2299 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2301 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2302 fde->stack_realign = 1;
2303 fde->stack_realignment = INTVAL (XEXP (src, 1));
2304 cfa_store.offset = 0;
2306 if (cfa.reg != STACK_POINTER_REGNUM
2307 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2308 fde->drap_reg = cfa.reg;
2316 def_cfa_1 (label, &cfa);
2321 /* Saving a register to the stack. Make sure dest is relative to the
2323 switch (GET_CODE (XEXP (dest, 0)))
2328 /* We can't handle variable size modifications. */
2329 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2331 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2333 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2334 && cfa_store.reg == STACK_POINTER_REGNUM);
2336 cfa_store.offset += offset;
2337 if (cfa.reg == STACK_POINTER_REGNUM)
2338 cfa.offset = cfa_store.offset;
2340 offset = -cfa_store.offset;
2346 offset = GET_MODE_SIZE (GET_MODE (dest));
2347 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2350 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2351 == STACK_POINTER_REGNUM)
2352 && cfa_store.reg == STACK_POINTER_REGNUM);
2354 cfa_store.offset += offset;
2356 /* Rule 18: If stack is aligned, we will use FP as a
2357 reference to represent the address of the stored
2360 && fde->stack_realign
2361 && src == hard_frame_pointer_rtx)
2363 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2364 cfa_store.offset = 0;
2367 if (cfa.reg == STACK_POINTER_REGNUM)
2368 cfa.offset = cfa_store.offset;
2370 offset = -cfa_store.offset;
2374 /* With an offset. */
2381 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
2382 && REG_P (XEXP (XEXP (dest, 0), 0)));
2383 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2384 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2387 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2389 if (cfa_store.reg == (unsigned) regno)
2390 offset -= cfa_store.offset;
2393 gcc_assert (cfa_temp.reg == (unsigned) regno);
2394 offset -= cfa_temp.offset;
2400 /* Without an offset. */
2403 int regno = REGNO (XEXP (dest, 0));
2405 if (cfa_store.reg == (unsigned) regno)
2406 offset = -cfa_store.offset;
2409 gcc_assert (cfa_temp.reg == (unsigned) regno);
2410 offset = -cfa_temp.offset;
2417 gcc_assert (cfa_temp.reg
2418 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2419 offset = -cfa_temp.offset;
2420 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2428 /* If the source operand of this MEM operation is not a
2429 register, basically the source is return address. Here
2430 we only care how much stack grew and we don't save it. */
2434 if (REGNO (src) != STACK_POINTER_REGNUM
2435 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2436 && (unsigned) REGNO (src) == cfa.reg)
2438 /* We're storing the current CFA reg into the stack. */
2440 if (cfa.offset == 0)
2443 /* If stack is aligned, putting CFA reg into stack means
2444 we can no longer use reg + offset to represent CFA.
2445 Here we use DW_CFA_def_cfa_expression instead. The
2446 result of this expression equals to the original CFA
2449 && fde->stack_realign
2450 && cfa.indirect == 0
2451 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2453 dw_cfa_location cfa_exp;
2455 gcc_assert (fde->drap_reg == cfa.reg);
2457 cfa_exp.indirect = 1;
2458 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2459 cfa_exp.base_offset = offset;
2462 fde->drap_reg_saved = 1;
2464 def_cfa_1 (label, &cfa_exp);
2468 /* If the source register is exactly the CFA, assume
2469 we're saving SP like any other register; this happens
2471 def_cfa_1 (label, &cfa);
2472 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2477 /* Otherwise, we'll need to look in the stack to
2478 calculate the CFA. */
2479 rtx x = XEXP (dest, 0);
2483 gcc_assert (REG_P (x));
2485 cfa.reg = REGNO (x);
2486 cfa.base_offset = offset;
2488 def_cfa_1 (label, &cfa);
2493 def_cfa_1 (label, &cfa);
2495 span = targetm.dwarf_register_span (src);
2498 queue_reg_save (label, src, NULL_RTX, offset);
2501 /* We have a PARALLEL describing where the contents of SRC
2502 live. Queue register saves for each piece of the
2506 HOST_WIDE_INT span_offset = offset;
2508 gcc_assert (GET_CODE (span) == PARALLEL);
2510 limit = XVECLEN (span, 0);
2511 for (par_index = 0; par_index < limit; par_index++)
2513 rtx elem = XVECEXP (span, 0, par_index);
2515 queue_reg_save (label, elem, NULL_RTX, span_offset);
2516 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2527 /* Record call frame debugging information for INSN, which either
2528 sets SP or FP (adjusting how we calculate the frame address) or saves a
2529 register to the stack. If INSN is NULL_RTX, initialize our state.
2531 If AFTER_P is false, we're being called before the insn is emitted,
2532 otherwise after. Call instructions get invoked twice. */
2535 dwarf2out_frame_debug (rtx insn, bool after_p)
2539 bool handled_one = false;
2541 if (insn == NULL_RTX)
2545 /* Flush any queued register saves. */
2546 flush_queued_reg_saves ();
2548 /* Set up state for generating call frame debug info. */
2551 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2553 cfa.reg = STACK_POINTER_REGNUM;
2556 cfa_temp.offset = 0;
2558 for (i = 0; i < num_regs_saved_in_regs; i++)
2560 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2561 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2563 num_regs_saved_in_regs = 0;
2565 if (barrier_args_size)
2567 XDELETEVEC (barrier_args_size);
2568 barrier_args_size = NULL;
2573 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2574 flush_queued_reg_saves ();
2576 if (! RTX_FRAME_RELATED_P (insn))
2578 if (!ACCUMULATE_OUTGOING_ARGS)
2579 dwarf2out_stack_adjust (insn, after_p);
2583 label = dwarf2out_cfi_label ();
2585 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2586 switch (REG_NOTE_KIND (note))
2588 case REG_FRAME_RELATED_EXPR:
2589 insn = XEXP (note, 0);
2592 case REG_CFA_DEF_CFA:
2593 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2597 case REG_CFA_ADJUST_CFA:
2602 if (GET_CODE (n) == PARALLEL)
2603 n = XVECEXP (n, 0, 0);
2605 dwarf2out_frame_debug_adjust_cfa (n, label);
2609 case REG_CFA_OFFSET:
2612 n = single_set (insn);
2613 dwarf2out_frame_debug_cfa_offset (n, label);
2617 case REG_CFA_REGISTER:
2622 if (GET_CODE (n) == PARALLEL)
2623 n = XVECEXP (n, 0, 0);
2625 dwarf2out_frame_debug_cfa_register (n, label);
2629 case REG_CFA_RESTORE:
2634 if (GET_CODE (n) == PARALLEL)
2635 n = XVECEXP (n, 0, 0);
2638 dwarf2out_frame_debug_cfa_restore (n, label);
2648 insn = PATTERN (insn);
2650 dwarf2out_frame_debug_expr (insn, label);
2653 /* Determine if we need to save and restore CFI information around this
2654 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2655 we do need to save/restore, then emit the save now, and insert a
2656 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2659 dwarf2out_begin_epilogue (rtx insn)
2661 bool saw_frp = false;
2665 /* Scan forward to the return insn, noticing if there are possible
2666 frame related insns. */
2667 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2672 /* Look for both regular and sibcalls to end the block. */
2673 if (returnjump_p (i))
2675 if (CALL_P (i) && SIBLING_CALL_P (i))
2678 if (RTX_FRAME_RELATED_P (i))
2682 /* If the port doesn't emit epilogue unwind info, we don't need a
2683 save/restore pair. */
2687 /* Otherwise, search forward to see if the return insn was the last
2688 basic block of the function. If so, we don't need save/restore. */
2689 gcc_assert (i != NULL);
2690 i = next_real_insn (i);
2694 /* Insert the restore before that next real insn in the stream, and before
2695 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
2696 properly nested. This should be after any label or alignment. This
2697 will be pushed into the CFI stream by the function below. */
2700 rtx p = PREV_INSN (i);
2703 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
2707 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
2709 /* Emit the state save. */
2711 cfi->dw_cfi_opc = DW_CFA_remember_state;
2712 add_fde_cfi (dwarf2out_cfi_label (), cfi);
2714 /* And emulate the state save. */
2715 gcc_assert (!cfa_remember.in_use);
2717 cfa_remember.in_use = 1;
2720 /* A "subroutine" of dwarf2out_begin_epilogue. Emit the restore required. */
2723 dwarf2out_frame_debug_restore_state (void)
2725 dw_cfi_ref cfi = new_cfi ();
2726 const char *label = dwarf2out_cfi_label ();
2728 cfi->dw_cfi_opc = DW_CFA_restore_state;
2729 add_fde_cfi (label, cfi);
2731 gcc_assert (cfa_remember.in_use);
2733 cfa_remember.in_use = 0;
2738 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2739 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2740 (enum dwarf_call_frame_info cfi);
2742 static enum dw_cfi_oprnd_type
2743 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2748 case DW_CFA_GNU_window_save:
2749 case DW_CFA_remember_state:
2750 case DW_CFA_restore_state:
2751 return dw_cfi_oprnd_unused;
2753 case DW_CFA_set_loc:
2754 case DW_CFA_advance_loc1:
2755 case DW_CFA_advance_loc2:
2756 case DW_CFA_advance_loc4:
2757 case DW_CFA_MIPS_advance_loc8:
2758 return dw_cfi_oprnd_addr;
2761 case DW_CFA_offset_extended:
2762 case DW_CFA_def_cfa:
2763 case DW_CFA_offset_extended_sf:
2764 case DW_CFA_def_cfa_sf:
2765 case DW_CFA_restore:
2766 case DW_CFA_restore_extended:
2767 case DW_CFA_undefined:
2768 case DW_CFA_same_value:
2769 case DW_CFA_def_cfa_register:
2770 case DW_CFA_register:
2771 return dw_cfi_oprnd_reg_num;
2773 case DW_CFA_def_cfa_offset:
2774 case DW_CFA_GNU_args_size:
2775 case DW_CFA_def_cfa_offset_sf:
2776 return dw_cfi_oprnd_offset;
2778 case DW_CFA_def_cfa_expression:
2779 case DW_CFA_expression:
2780 return dw_cfi_oprnd_loc;
2787 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2788 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2789 (enum dwarf_call_frame_info cfi);
2791 static enum dw_cfi_oprnd_type
2792 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2796 case DW_CFA_def_cfa:
2797 case DW_CFA_def_cfa_sf:
2799 case DW_CFA_offset_extended_sf:
2800 case DW_CFA_offset_extended:
2801 return dw_cfi_oprnd_offset;
2803 case DW_CFA_register:
2804 return dw_cfi_oprnd_reg_num;
2807 return dw_cfi_oprnd_unused;
2811 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2813 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2814 switch to the data section instead, and write out a synthetic label
2818 switch_to_eh_frame_section (void)
2822 #ifdef EH_FRAME_SECTION_NAME
2823 if (eh_frame_section == 0)
2827 if (EH_TABLES_CAN_BE_READ_ONLY)
2833 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2835 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2837 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2839 flags = ((! flag_pic
2840 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2841 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2842 && (per_encoding & 0x70) != DW_EH_PE_absptr
2843 && (per_encoding & 0x70) != DW_EH_PE_aligned
2844 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2845 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2846 ? 0 : SECTION_WRITE);
2849 flags = SECTION_WRITE;
2850 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2854 if (eh_frame_section)
2855 switch_to_section (eh_frame_section);
2858 /* We have no special eh_frame section. Put the information in
2859 the data section and emit special labels to guide collect2. */
2860 switch_to_section (data_section);
2861 label = get_file_function_name ("F");
2862 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2863 targetm.asm_out.globalize_label (asm_out_file,
2864 IDENTIFIER_POINTER (label));
2865 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2869 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
2871 static HOST_WIDE_INT
2872 div_data_align (HOST_WIDE_INT off)
2874 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
2875 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
2879 /* Output a Call Frame Information opcode and its operand(s). */
2882 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2887 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2888 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2889 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2890 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2891 ((unsigned HOST_WIDE_INT)
2892 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2893 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2895 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2896 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2897 "DW_CFA_offset, column 0x%lx", r);
2898 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2899 dw2_asm_output_data_uleb128 (off, NULL);
2901 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2903 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2904 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2905 "DW_CFA_restore, column 0x%lx", r);
2909 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2910 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2912 switch (cfi->dw_cfi_opc)
2914 case DW_CFA_set_loc:
2916 dw2_asm_output_encoded_addr_rtx (
2917 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2918 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2921 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2922 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2923 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2926 case DW_CFA_advance_loc1:
2927 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2928 fde->dw_fde_current_label, NULL);
2929 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2932 case DW_CFA_advance_loc2:
2933 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2934 fde->dw_fde_current_label, NULL);
2935 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2938 case DW_CFA_advance_loc4:
2939 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2940 fde->dw_fde_current_label, NULL);
2941 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2944 case DW_CFA_MIPS_advance_loc8:
2945 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2946 fde->dw_fde_current_label, NULL);
2947 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2950 case DW_CFA_offset_extended:
2951 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2952 dw2_asm_output_data_uleb128 (r, NULL);
2953 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2954 dw2_asm_output_data_uleb128 (off, NULL);
2957 case DW_CFA_def_cfa:
2958 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2959 dw2_asm_output_data_uleb128 (r, NULL);
2960 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2963 case DW_CFA_offset_extended_sf:
2964 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2965 dw2_asm_output_data_uleb128 (r, NULL);
2966 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2967 dw2_asm_output_data_sleb128 (off, NULL);
2970 case DW_CFA_def_cfa_sf:
2971 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2972 dw2_asm_output_data_uleb128 (r, NULL);
2973 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
2974 dw2_asm_output_data_sleb128 (off, NULL);
2977 case DW_CFA_restore_extended:
2978 case DW_CFA_undefined:
2979 case DW_CFA_same_value:
2980 case DW_CFA_def_cfa_register:
2981 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2982 dw2_asm_output_data_uleb128 (r, NULL);
2985 case DW_CFA_register:
2986 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2987 dw2_asm_output_data_uleb128 (r, NULL);
2988 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2989 dw2_asm_output_data_uleb128 (r, NULL);
2992 case DW_CFA_def_cfa_offset:
2993 case DW_CFA_GNU_args_size:
2994 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2997 case DW_CFA_def_cfa_offset_sf:
2998 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
2999 dw2_asm_output_data_sleb128 (off, NULL);
3002 case DW_CFA_GNU_window_save:
3005 case DW_CFA_def_cfa_expression:
3006 case DW_CFA_expression:
3007 output_cfa_loc (cfi);
3010 case DW_CFA_GNU_negative_offset_extended:
3011 /* Obsoleted by DW_CFA_offset_extended_sf. */
3020 /* Similar, but do it via assembler directives instead. */
3023 output_cfi_directive (dw_cfi_ref cfi)
3025 unsigned long r, r2;
3027 switch (cfi->dw_cfi_opc)
3029 case DW_CFA_advance_loc:
3030 case DW_CFA_advance_loc1:
3031 case DW_CFA_advance_loc2:
3032 case DW_CFA_advance_loc4:
3033 case DW_CFA_MIPS_advance_loc8:
3034 case DW_CFA_set_loc:
3035 /* Should only be created by add_fde_cfi in a code path not
3036 followed when emitting via directives. The assembler is
3037 going to take care of this for us. */
3041 case DW_CFA_offset_extended:
3042 case DW_CFA_offset_extended_sf:
3043 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3044 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3045 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3048 case DW_CFA_restore:
3049 case DW_CFA_restore_extended:
3050 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3051 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3054 case DW_CFA_undefined:
3055 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3056 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3059 case DW_CFA_same_value:
3060 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3061 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3064 case DW_CFA_def_cfa:
3065 case DW_CFA_def_cfa_sf:
3066 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3067 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3068 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3071 case DW_CFA_def_cfa_register:
3072 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3073 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3076 case DW_CFA_register:
3077 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 0);
3078 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 0);
3079 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3082 case DW_CFA_def_cfa_offset:
3083 case DW_CFA_def_cfa_offset_sf:
3084 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3085 HOST_WIDE_INT_PRINT_DEC"\n",
3086 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3089 case DW_CFA_remember_state:
3090 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3092 case DW_CFA_restore_state:
3093 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3096 case DW_CFA_GNU_args_size:
3097 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", DW_CFA_GNU_args_size);
3098 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3100 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3101 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3102 fputc ('\n', asm_out_file);
3105 case DW_CFA_GNU_window_save:
3106 fprintf (asm_out_file, "\t.cfi_window_save\n");
3109 case DW_CFA_def_cfa_expression:
3110 case DW_CFA_expression:
3111 fprintf (asm_out_file, "\t.cfi_escape 0x%x,", cfi->dw_cfi_opc);
3112 output_cfa_loc_raw (cfi);
3113 fputc ('\n', asm_out_file);
3121 /* Output the call frame information used to record information
3122 that relates to calculating the frame pointer, and records the
3123 location of saved registers. */
3126 output_call_frame_info (int for_eh)
3131 char l1[20], l2[20], section_start_label[20];
3132 bool any_lsda_needed = false;
3133 char augmentation[6];
3134 int augmentation_size;
3135 int fde_encoding = DW_EH_PE_absptr;
3136 int per_encoding = DW_EH_PE_absptr;
3137 int lsda_encoding = DW_EH_PE_absptr;
3140 /* Don't emit a CIE if there won't be any FDEs. */
3141 if (fde_table_in_use == 0)
3144 /* Nothing to do if the assembler's doing it all. */
3145 if (dwarf2out_do_cfi_asm ())
3148 /* If we make FDEs linkonce, we may have to emit an empty label for
3149 an FDE that wouldn't otherwise be emitted. We want to avoid
3150 having an FDE kept around when the function it refers to is
3151 discarded. Example where this matters: a primary function
3152 template in C++ requires EH information, but an explicit
3153 specialization doesn't. */
3154 if (TARGET_USES_WEAK_UNWIND_INFO
3155 && ! flag_asynchronous_unwind_tables
3158 for (i = 0; i < fde_table_in_use; i++)
3159 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
3160 && !fde_table[i].uses_eh_lsda
3161 && ! DECL_WEAK (fde_table[i].decl))
3162 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
3163 for_eh, /* empty */ 1);
3165 /* If we don't have any functions we'll want to unwind out of, don't
3166 emit any EH unwind information. Note that if exceptions aren't
3167 enabled, we won't have collected nothrow information, and if we
3168 asked for asynchronous tables, we always want this info. */
3171 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
3173 for (i = 0; i < fde_table_in_use; i++)
3174 if (fde_table[i].uses_eh_lsda)
3175 any_eh_needed = any_lsda_needed = true;
3176 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3177 any_eh_needed = true;
3178 else if (! fde_table[i].nothrow
3179 && ! fde_table[i].all_throwers_are_sibcalls)
3180 any_eh_needed = true;
3182 if (! any_eh_needed)
3186 /* We're going to be generating comments, so turn on app. */
3191 switch_to_eh_frame_section ();
3194 if (!debug_frame_section)
3195 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3196 SECTION_DEBUG, NULL);
3197 switch_to_section (debug_frame_section);
3200 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3201 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3203 /* Output the CIE. */
3204 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3205 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3206 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3207 dw2_asm_output_data (4, 0xffffffff,
3208 "Initial length escape value indicating 64-bit DWARF extension");
3209 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3210 "Length of Common Information Entry");
3211 ASM_OUTPUT_LABEL (asm_out_file, l1);
3213 /* Now that the CIE pointer is PC-relative for EH,
3214 use 0 to identify the CIE. */
3215 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3216 (for_eh ? 0 : DWARF_CIE_ID),
3217 "CIE Identifier Tag");
3219 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
3221 augmentation[0] = 0;
3222 augmentation_size = 0;
3228 z Indicates that a uleb128 is present to size the
3229 augmentation section.
3230 L Indicates the encoding (and thus presence) of
3231 an LSDA pointer in the FDE augmentation.
3232 R Indicates a non-default pointer encoding for
3234 P Indicates the presence of an encoding + language
3235 personality routine in the CIE augmentation. */
3237 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3238 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3239 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3241 p = augmentation + 1;
3242 if (eh_personality_libfunc)
3245 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3246 assemble_external_libcall (eh_personality_libfunc);
3248 if (any_lsda_needed)
3251 augmentation_size += 1;
3253 if (fde_encoding != DW_EH_PE_absptr)
3256 augmentation_size += 1;
3258 if (p > augmentation + 1)
3260 augmentation[0] = 'z';
3264 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3265 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
3267 int offset = ( 4 /* Length */
3269 + 1 /* CIE version */
3270 + strlen (augmentation) + 1 /* Augmentation */
3271 + size_of_uleb128 (1) /* Code alignment */
3272 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3274 + 1 /* Augmentation size */
3275 + 1 /* Personality encoding */ );
3276 int pad = -offset & (PTR_SIZE - 1);
3278 augmentation_size += pad;
3280 /* Augmentations should be small, so there's scarce need to
3281 iterate for a solution. Die if we exceed one uleb128 byte. */
3282 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3286 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3287 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3288 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3289 "CIE Data Alignment Factor");
3291 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3292 if (DW_CIE_VERSION == 1)
3293 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3295 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3297 if (augmentation[0])
3299 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3300 if (eh_personality_libfunc)
3302 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3303 eh_data_format_name (per_encoding));
3304 dw2_asm_output_encoded_addr_rtx (per_encoding,
3305 eh_personality_libfunc,
3309 if (any_lsda_needed)
3310 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3311 eh_data_format_name (lsda_encoding));
3313 if (fde_encoding != DW_EH_PE_absptr)
3314 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3315 eh_data_format_name (fde_encoding));
3318 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3319 output_cfi (cfi, NULL, for_eh);
3321 /* Pad the CIE out to an address sized boundary. */
3322 ASM_OUTPUT_ALIGN (asm_out_file,
3323 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3324 ASM_OUTPUT_LABEL (asm_out_file, l2);
3326 /* Loop through all of the FDE's. */
3327 for (i = 0; i < fde_table_in_use; i++)
3329 fde = &fde_table[i];
3331 /* Don't emit EH unwind info for leaf functions that don't need it. */
3332 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
3333 && (fde->nothrow || fde->all_throwers_are_sibcalls)
3334 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
3335 && !fde->uses_eh_lsda)
3338 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
3339 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
3340 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
3341 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
3342 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3343 dw2_asm_output_data (4, 0xffffffff,
3344 "Initial length escape value indicating 64-bit DWARF extension");
3345 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3347 ASM_OUTPUT_LABEL (asm_out_file, l1);
3350 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3352 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3353 debug_frame_section, "FDE CIE offset");
3357 if (fde->dw_fde_switched_sections)
3359 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
3360 fde->dw_fde_unlikely_section_label);
3361 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
3362 fde->dw_fde_hot_section_label);
3363 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
3364 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
3365 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
3366 "FDE initial location");
3367 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3368 fde->dw_fde_hot_section_end_label,
3369 fde->dw_fde_hot_section_label,
3370 "FDE address range");
3371 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
3372 "FDE initial location");
3373 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3374 fde->dw_fde_unlikely_section_end_label,
3375 fde->dw_fde_unlikely_section_label,
3376 "FDE address range");
3380 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
3381 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3382 dw2_asm_output_encoded_addr_rtx (fde_encoding,
3385 "FDE initial location");
3386 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3387 fde->dw_fde_end, fde->dw_fde_begin,
3388 "FDE address range");
3393 if (fde->dw_fde_switched_sections)
3395 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3396 fde->dw_fde_hot_section_label,
3397 "FDE initial location");
3398 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3399 fde->dw_fde_hot_section_end_label,
3400 fde->dw_fde_hot_section_label,
3401 "FDE address range");
3402 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3403 fde->dw_fde_unlikely_section_label,
3404 "FDE initial location");
3405 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3406 fde->dw_fde_unlikely_section_end_label,
3407 fde->dw_fde_unlikely_section_label,
3408 "FDE address range");
3412 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
3413 "FDE initial location");
3414 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
3415 fde->dw_fde_end, fde->dw_fde_begin,
3416 "FDE address range");
3420 if (augmentation[0])
3422 if (any_lsda_needed)
3424 int size = size_of_encoded_value (lsda_encoding);
3426 if (lsda_encoding == DW_EH_PE_aligned)
3428 int offset = ( 4 /* Length */
3429 + 4 /* CIE offset */
3430 + 2 * size_of_encoded_value (fde_encoding)
3431 + 1 /* Augmentation size */ );
3432 int pad = -offset & (PTR_SIZE - 1);
3435 gcc_assert (size_of_uleb128 (size) == 1);
3438 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3440 if (fde->uses_eh_lsda)
3442 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
3443 fde->funcdef_number);
3444 dw2_asm_output_encoded_addr_rtx (
3445 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
3446 false, "Language Specific Data Area");
3450 if (lsda_encoding == DW_EH_PE_aligned)
3451 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3453 (size_of_encoded_value (lsda_encoding), 0,
3454 "Language Specific Data Area (none)");
3458 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3461 /* Loop through the Call Frame Instructions associated with
3463 fde->dw_fde_current_label = fde->dw_fde_begin;
3464 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3465 output_cfi (cfi, fde, for_eh);
3467 /* Pad the FDE out to an address sized boundary. */
3468 ASM_OUTPUT_ALIGN (asm_out_file,
3469 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3470 ASM_OUTPUT_LABEL (asm_out_file, l2);
3473 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3474 dw2_asm_output_data (4, 0, "End of Table");
3475 #ifdef MIPS_DEBUGGING_INFO
3476 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3477 get a value of 0. Putting .align 0 after the label fixes it. */
3478 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3481 /* Turn off app to make assembly quicker. */
3486 /* Output a marker (i.e. a label) for the beginning of a function, before
3490 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
3491 const char *file ATTRIBUTE_UNUSED)
3493 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3497 current_function_func_begin_label = NULL;
3499 #ifdef TARGET_UNWIND_INFO
3500 /* ??? current_function_func_begin_label is also used by except.c
3501 for call-site information. We must emit this label if it might
3503 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3504 && ! dwarf2out_do_frame ())
3507 if (! dwarf2out_do_frame ())
3511 switch_to_section (function_section (current_function_decl));
3512 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3513 current_function_funcdef_no);
3514 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3515 current_function_funcdef_no);
3516 dup_label = xstrdup (label);
3517 current_function_func_begin_label = dup_label;
3519 #ifdef TARGET_UNWIND_INFO
3520 /* We can elide the fde allocation if we're not emitting debug info. */
3521 if (! dwarf2out_do_frame ())
3525 /* Expand the fde table if necessary. */
3526 if (fde_table_in_use == fde_table_allocated)
3528 fde_table_allocated += FDE_TABLE_INCREMENT;
3529 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3530 memset (fde_table + fde_table_in_use, 0,
3531 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3534 /* Record the FDE associated with this function. */
3535 current_funcdef_fde = fde_table_in_use;
3537 /* Add the new FDE at the end of the fde_table. */
3538 fde = &fde_table[fde_table_in_use++];
3539 fde->decl = current_function_decl;
3540 fde->dw_fde_begin = dup_label;
3541 fde->dw_fde_current_label = dup_label;
3542 fde->dw_fde_hot_section_label = NULL;
3543 fde->dw_fde_hot_section_end_label = NULL;
3544 fde->dw_fde_unlikely_section_label = NULL;
3545 fde->dw_fde_unlikely_section_end_label = NULL;
3546 fde->dw_fde_switched_sections = false;
3547 fde->dw_fde_end = NULL;
3548 fde->dw_fde_cfi = NULL;
3549 fde->funcdef_number = current_function_funcdef_no;
3550 fde->nothrow = crtl->nothrow;
3551 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3552 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3553 fde->drap_reg = INVALID_REGNUM;
3554 fde->vdrap_reg = INVALID_REGNUM;
3556 args_size = old_args_size = 0;
3558 /* We only want to output line number information for the genuine dwarf2
3559 prologue case, not the eh frame case. */
3560 #ifdef DWARF2_DEBUGGING_INFO
3562 dwarf2out_source_line (line, file);
3565 if (dwarf2out_do_cfi_asm ())
3570 fprintf (asm_out_file, "\t.cfi_startproc\n");
3572 if (eh_personality_libfunc)
3574 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3575 ref = eh_personality_libfunc;
3577 /* ??? The GAS support isn't entirely consistent. We have to
3578 handle indirect support ourselves, but PC-relative is done
3579 in the assembler. Further, the assembler can't handle any
3580 of the weirder relocation types. */
3581 if (enc & DW_EH_PE_indirect)
3582 ref = dw2_force_const_mem (ref, true);
3584 fprintf (asm_out_file, "\t.cfi_personality 0x%x,", enc);
3585 output_addr_const (asm_out_file, ref);
3586 fputc ('\n', asm_out_file);
3589 if (crtl->uses_eh_lsda)
3593 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3594 ASM_GENERATE_INTERNAL_LABEL (lab, "LLSDA",
3595 current_function_funcdef_no);
3596 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
3597 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
3599 if (enc & DW_EH_PE_indirect)
3600 ref = dw2_force_const_mem (ref, true);
3602 fprintf (asm_out_file, "\t.cfi_lsda 0x%x,", enc);
3603 output_addr_const (asm_out_file, ref);
3604 fputc ('\n', asm_out_file);
3609 /* Output a marker (i.e. a label) for the absolute end of the generated code
3610 for a function definition. This gets called *after* the epilogue code has
3614 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3615 const char *file ATTRIBUTE_UNUSED)
3618 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3620 if (dwarf2out_do_cfi_asm ())
3621 fprintf (asm_out_file, "\t.cfi_endproc\n");
3623 /* Output a label to mark the endpoint of the code generated for this
3625 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3626 current_function_funcdef_no);
3627 ASM_OUTPUT_LABEL (asm_out_file, label);
3628 fde = current_fde ();
3629 gcc_assert (fde != NULL);
3630 fde->dw_fde_end = xstrdup (label);
3634 dwarf2out_frame_init (void)
3636 /* Allocate the initial hunk of the fde_table. */
3637 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3638 fde_table_allocated = FDE_TABLE_INCREMENT;
3639 fde_table_in_use = 0;
3641 /* Generate the CFA instructions common to all FDE's. Do it now for the
3642 sake of lookup_cfa. */
3644 /* On entry, the Canonical Frame Address is at SP. */
3645 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3647 #ifdef DWARF2_UNWIND_INFO
3648 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3649 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3654 dwarf2out_frame_finish (void)
3656 /* Output call frame information. */
3657 if (DWARF2_FRAME_INFO)
3658 output_call_frame_info (0);
3660 #ifndef TARGET_UNWIND_INFO
3661 /* Output another copy for the unwinder. */
3662 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3663 output_call_frame_info (1);
3667 /* Note that the current function section is being used for code. */
3670 dwarf2out_note_section_used (void)
3672 section *sec = current_function_section ();
3673 if (sec == text_section)
3674 text_section_used = true;
3675 else if (sec == cold_text_section)
3676 cold_text_section_used = true;
3680 dwarf2out_switch_text_section (void)
3682 dw_fde_ref fde = current_fde ();
3684 gcc_assert (cfun && fde);
3686 fde->dw_fde_switched_sections = true;
3687 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3688 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3689 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3690 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3691 have_multiple_function_sections = true;
3693 /* Reset the current label on switching text sections, so that we
3694 don't attempt to advance_loc4 between labels in different sections. */
3695 fde->dw_fde_current_label = NULL;
3697 /* There is no need to mark used sections when not debugging. */
3698 if (cold_text_section != NULL)
3699 dwarf2out_note_section_used ();
3703 /* And now, the subset of the debugging information support code necessary
3704 for emitting location expressions. */
3706 /* Data about a single source file. */
3707 struct GTY(()) dwarf_file_data {
3708 const char * filename;
3712 /* We need some way to distinguish DW_OP_addr with a direct symbol
3713 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3714 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3717 typedef struct dw_val_struct *dw_val_ref;
3718 typedef struct die_struct *dw_die_ref;
3719 typedef const struct die_struct *const_dw_die_ref;
3720 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3721 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3723 typedef struct GTY(()) deferred_locations_struct
3727 } deferred_locations;
3729 DEF_VEC_O(deferred_locations);
3730 DEF_VEC_ALLOC_O(deferred_locations,gc);
3732 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
3734 /* Each DIE may have a series of attribute/value pairs. Values
3735 can take on several forms. The forms that are used in this
3736 implementation are listed below. */
3741 dw_val_class_offset,
3743 dw_val_class_loc_list,
3744 dw_val_class_range_list,
3746 dw_val_class_unsigned_const,
3747 dw_val_class_long_long,
3750 dw_val_class_die_ref,
3751 dw_val_class_fde_ref,
3752 dw_val_class_lbl_id,
3753 dw_val_class_lineptr,
3755 dw_val_class_macptr,
3759 /* Describe a double word constant value. */
3760 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3762 typedef struct GTY(()) dw_long_long_struct {
3768 /* Describe a floating point constant value, or a vector constant value. */
3770 typedef struct GTY(()) dw_vec_struct {
3771 unsigned char * GTY((length ("%h.length"))) array;
3777 /* The dw_val_node describes an attribute's value, as it is
3778 represented internally. */
3780 typedef struct GTY(()) dw_val_struct {
3781 enum dw_val_class val_class;
3782 union dw_val_struct_union
3784 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3785 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3786 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3787 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3788 HOST_WIDE_INT GTY ((default)) val_int;
3789 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3790 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3791 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3792 struct dw_val_die_union
3796 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3797 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3798 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3799 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3800 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3801 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3803 GTY ((desc ("%1.val_class"))) v;
3807 /* Locations in memory are described using a sequence of stack machine
3810 typedef struct GTY(()) dw_loc_descr_struct {
3811 dw_loc_descr_ref dw_loc_next;
3812 enum dwarf_location_atom dw_loc_opc;
3814 dw_val_node dw_loc_oprnd1;
3815 dw_val_node dw_loc_oprnd2;
3819 /* Location lists are ranges + location descriptions for that range,
3820 so you can track variables that are in different places over
3821 their entire life. */
3822 typedef struct GTY(()) dw_loc_list_struct {
3823 dw_loc_list_ref dw_loc_next;
3824 const char *begin; /* Label for begin address of range */
3825 const char *end; /* Label for end address of range */
3826 char *ll_symbol; /* Label for beginning of location list.
3827 Only on head of list */
3828 const char *section; /* Section this loclist is relative to */
3829 dw_loc_descr_ref expr;
3832 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3834 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3836 /* Convert a DWARF stack opcode into its string name. */
3839 dwarf_stack_op_name (unsigned int op)
3844 case INTERNAL_DW_OP_tls_addr:
3845 return "DW_OP_addr";
3847 return "DW_OP_deref";
3849 return "DW_OP_const1u";
3851 return "DW_OP_const1s";
3853 return "DW_OP_const2u";
3855 return "DW_OP_const2s";
3857 return "DW_OP_const4u";
3859 return "DW_OP_const4s";
3861 return "DW_OP_const8u";
3863 return "DW_OP_const8s";
3865 return "DW_OP_constu";
3867 return "DW_OP_consts";
3871 return "DW_OP_drop";
3873 return "DW_OP_over";
3875 return "DW_OP_pick";
3877 return "DW_OP_swap";
3881 return "DW_OP_xderef";
3889 return "DW_OP_minus";
3901 return "DW_OP_plus";
3902 case DW_OP_plus_uconst:
3903 return "DW_OP_plus_uconst";
3909 return "DW_OP_shra";
3927 return "DW_OP_skip";
3929 return "DW_OP_lit0";
3931 return "DW_OP_lit1";
3933 return "DW_OP_lit2";
3935 return "DW_OP_lit3";
3937 return "DW_OP_lit4";
3939 return "DW_OP_lit5";
3941 return "DW_OP_lit6";
3943 return "DW_OP_lit7";
3945 return "DW_OP_lit8";
3947 return "DW_OP_lit9";
3949 return "DW_OP_lit10";
3951 return "DW_OP_lit11";
3953 return "DW_OP_lit12";
3955 return "DW_OP_lit13";
3957 return "DW_OP_lit14";
3959 return "DW_OP_lit15";
3961 return "DW_OP_lit16";
3963 return "DW_OP_lit17";
3965 return "DW_OP_lit18";
3967 return "DW_OP_lit19";
3969 return "DW_OP_lit20";
3971 return "DW_OP_lit21";
3973 return "DW_OP_lit22";
3975 return "DW_OP_lit23";
3977 return "DW_OP_lit24";
3979 return "DW_OP_lit25";
3981 return "DW_OP_lit26";
3983 return "DW_OP_lit27";
3985 return "DW_OP_lit28";
3987 return "DW_OP_lit29";
3989 return "DW_OP_lit30";
3991 return "DW_OP_lit31";
3993 return "DW_OP_reg0";
3995 return "DW_OP_reg1";
3997 return "DW_OP_reg2";
3999 return "DW_OP_reg3";
4001 return "DW_OP_reg4";
4003 return "DW_OP_reg5";
4005 return "DW_OP_reg6";
4007 return "DW_OP_reg7";
4009 return "DW_OP_reg8";
4011 return "DW_OP_reg9";
4013 return "DW_OP_reg10";
4015 return "DW_OP_reg11";
4017 return "DW_OP_reg12";
4019 return "DW_OP_reg13";
4021 return "DW_OP_reg14";
4023 return "DW_OP_reg15";
4025 return "DW_OP_reg16";
4027 return "DW_OP_reg17";
4029 return "DW_OP_reg18";
4031 return "DW_OP_reg19";
4033 return "DW_OP_reg20";
4035 return "DW_OP_reg21";
4037 return "DW_OP_reg22";
4039 return "DW_OP_reg23";
4041 return "DW_OP_reg24";
4043 return "DW_OP_reg25";
4045 return "DW_OP_reg26";
4047 return "DW_OP_reg27";
4049 return "DW_OP_reg28";
4051 return "DW_OP_reg29";
4053 return "DW_OP_reg30";
4055 return "DW_OP_reg31";
4057 return "DW_OP_breg0";
4059 return "DW_OP_breg1";
4061 return "DW_OP_breg2";
4063 return "DW_OP_breg3";
4065 return "DW_OP_breg4";
4067 return "DW_OP_breg5";
4069 return "DW_OP_breg6";
4071 return "DW_OP_breg7";
4073 return "DW_OP_breg8";
4075 return "DW_OP_breg9";
4077 return "DW_OP_breg10";
4079 return "DW_OP_breg11";
4081 return "DW_OP_breg12";
4083 return "DW_OP_breg13";
4085 return "DW_OP_breg14";
4087 return "DW_OP_breg15";
4089 return "DW_OP_breg16";
4091 return "DW_OP_breg17";
4093 return "DW_OP_breg18";
4095 return "DW_OP_breg19";
4097 return "DW_OP_breg20";
4099 return "DW_OP_breg21";
4101 return "DW_OP_breg22";
4103 return "DW_OP_breg23";
4105 return "DW_OP_breg24";
4107 return "DW_OP_breg25";
4109 return "DW_OP_breg26";
4111 return "DW_OP_breg27";
4113 return "DW_OP_breg28";
4115 return "DW_OP_breg29";
4117 return "DW_OP_breg30";
4119 return "DW_OP_breg31";
4121 return "DW_OP_regx";
4123 return "DW_OP_fbreg";
4125 return "DW_OP_bregx";
4127 return "DW_OP_piece";
4128 case DW_OP_deref_size:
4129 return "DW_OP_deref_size";
4130 case DW_OP_xderef_size:
4131 return "DW_OP_xderef_size";
4134 case DW_OP_push_object_address:
4135 return "DW_OP_push_object_address";
4137 return "DW_OP_call2";
4139 return "DW_OP_call4";
4140 case DW_OP_call_ref:
4141 return "DW_OP_call_ref";
4142 case DW_OP_GNU_push_tls_address:
4143 return "DW_OP_GNU_push_tls_address";
4144 case DW_OP_GNU_uninit:
4145 return "DW_OP_GNU_uninit";
4147 return "OP_<unknown>";
4151 /* Return a pointer to a newly allocated location description. Location
4152 descriptions are simple expression terms that can be strung
4153 together to form more complicated location (address) descriptions. */
4155 static inline dw_loc_descr_ref
4156 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4157 unsigned HOST_WIDE_INT oprnd2)
4159 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
4161 descr->dw_loc_opc = op;
4162 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4163 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4164 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4165 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4170 /* Return a pointer to a newly allocated location description for
4173 static inline dw_loc_descr_ref
4174 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4177 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4180 return new_loc_descr (DW_OP_bregx, reg, offset);
4183 /* Add a location description term to a location description expression. */
4186 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4188 dw_loc_descr_ref *d;
4190 /* Find the end of the chain. */
4191 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4197 /* Add a constant OFFSET to a location expression. */
4200 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4202 dw_loc_descr_ref loc;
4205 gcc_assert (*list_head != NULL);
4210 /* Find the end of the chain. */
4211 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4215 if (loc->dw_loc_opc == DW_OP_fbreg
4216 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4217 p = &loc->dw_loc_oprnd1.v.val_int;
4218 else if (loc->dw_loc_opc == DW_OP_bregx)
4219 p = &loc->dw_loc_oprnd2.v.val_int;
4221 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4222 offset. Don't optimize if an signed integer overflow would happen. */
4224 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4225 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4228 else if (offset > 0)
4229 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4233 loc->dw_loc_next = int_loc_descriptor (offset);
4234 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
4238 /* Return the size of a location descriptor. */
4240 static unsigned long
4241 size_of_loc_descr (dw_loc_descr_ref loc)
4243 unsigned long size = 1;
4245 switch (loc->dw_loc_opc)
4248 case INTERNAL_DW_OP_tls_addr:
4249 size += DWARF2_ADDR_SIZE;
4268 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4271 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4276 case DW_OP_plus_uconst:
4277 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4315 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4318 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4321 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4324 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4325 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4328 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4330 case DW_OP_deref_size:
4331 case DW_OP_xderef_size:
4340 case DW_OP_call_ref:
4341 size += DWARF2_ADDR_SIZE;
4350 /* Return the size of a series of location descriptors. */
4352 static unsigned long
4353 size_of_locs (dw_loc_descr_ref loc)
4358 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
4359 field, to avoid writing to a PCH file. */
4360 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4362 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
4364 size += size_of_loc_descr (l);
4369 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
4371 l->dw_loc_addr = size;
4372 size += size_of_loc_descr (l);
4378 /* Output location description stack opcode's operands (if any). */
4381 output_loc_operands (dw_loc_descr_ref loc)
4383 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4384 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4386 switch (loc->dw_loc_opc)
4388 #ifdef DWARF2_DEBUGGING_INFO
4390 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
4394 dw2_asm_output_data (2, val1->v.val_int, NULL);
4398 dw2_asm_output_data (4, val1->v.val_int, NULL);
4402 gcc_assert (HOST_BITS_PER_LONG >= 64);
4403 dw2_asm_output_data (8, val1->v.val_int, NULL);
4410 gcc_assert (val1->val_class == dw_val_class_loc);
4411 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4413 dw2_asm_output_data (2, offset, NULL);
4426 /* We currently don't make any attempt to make sure these are
4427 aligned properly like we do for the main unwind info, so
4428 don't support emitting things larger than a byte if we're
4429 only doing unwinding. */
4434 dw2_asm_output_data (1, val1->v.val_int, NULL);
4437 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4440 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4443 dw2_asm_output_data (1, val1->v.val_int, NULL);
4445 case DW_OP_plus_uconst:
4446 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4480 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4483 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4486 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
4489 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4490 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
4493 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
4495 case DW_OP_deref_size:
4496 case DW_OP_xderef_size:
4497 dw2_asm_output_data (1, val1->v.val_int, NULL);
4500 case INTERNAL_DW_OP_tls_addr:
4501 if (targetm.asm_out.output_dwarf_dtprel)
4503 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
4506 fputc ('\n', asm_out_file);
4513 /* Other codes have no operands. */
4518 /* Output a sequence of location operations. */
4521 output_loc_sequence (dw_loc_descr_ref loc)
4523 for (; loc != NULL; loc = loc->dw_loc_next)
4525 /* Output the opcode. */
4526 dw2_asm_output_data (1, loc->dw_loc_opc,
4527 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
4529 /* Output the operand(s) (if any). */
4530 output_loc_operands (loc);
4534 /* Output location description stack opcode's operands (if any).
4535 The output is single bytes on a line, suitable for .cfi_escape. */
4538 output_loc_operands_raw (dw_loc_descr_ref loc)
4540 dw_val_ref val1 = &loc->dw_loc_oprnd1;
4541 dw_val_ref val2 = &loc->dw_loc_oprnd2;
4543 switch (loc->dw_loc_opc)
4546 /* We cannot output addresses in .cfi_escape, only bytes. */
4552 case DW_OP_deref_size:
4553 case DW_OP_xderef_size:
4554 fputc (',', asm_out_file);
4555 dw2_asm_output_data_raw (1, val1->v.val_int);
4560 fputc (',', asm_out_file);
4561 dw2_asm_output_data_raw (2, val1->v.val_int);
4566 fputc (',', asm_out_file);
4567 dw2_asm_output_data_raw (4, val1->v.val_int);
4572 gcc_assert (HOST_BITS_PER_LONG >= 64);
4573 fputc (',', asm_out_file);
4574 dw2_asm_output_data_raw (8, val1->v.val_int);
4582 gcc_assert (val1->val_class == dw_val_class_loc);
4583 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
4585 fputc (',', asm_out_file);
4586 dw2_asm_output_data_raw (2, offset);
4591 case DW_OP_plus_uconst:
4594 fputc (',', asm_out_file);
4595 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4632 fputc (',', asm_out_file);
4633 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
4637 fputc (',', asm_out_file);
4638 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
4639 fputc (',', asm_out_file);
4640 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
4643 case INTERNAL_DW_OP_tls_addr:
4647 /* Other codes have no operands. */
4653 output_loc_sequence_raw (dw_loc_descr_ref loc)
4657 /* Output the opcode. */
4658 fprintf (asm_out_file, "0x%x", loc->dw_loc_opc);
4659 output_loc_operands_raw (loc);
4661 if (!loc->dw_loc_next)
4663 loc = loc->dw_loc_next;
4665 fputc (',', asm_out_file);
4669 /* This routine will generate the correct assembly data for a location
4670 description based on a cfi entry with a complex address. */
4673 output_cfa_loc (dw_cfi_ref cfi)
4675 dw_loc_descr_ref loc;
4678 if (cfi->dw_cfi_opc == DW_CFA_expression)
4679 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
4681 /* Output the size of the block. */
4682 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4683 size = size_of_locs (loc);
4684 dw2_asm_output_data_uleb128 (size, NULL);
4686 /* Now output the operations themselves. */
4687 output_loc_sequence (loc);
4690 /* Similar, but used for .cfi_escape. */
4693 output_cfa_loc_raw (dw_cfi_ref cfi)
4695 dw_loc_descr_ref loc;
4698 if (cfi->dw_cfi_opc == DW_CFA_expression)
4699 fprintf (asm_out_file, "0x%x,", cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4701 /* Output the size of the block. */
4702 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
4703 size = size_of_locs (loc);
4704 dw2_asm_output_data_uleb128_raw (size);
4705 fputc (',', asm_out_file);
4707 /* Now output the operations themselves. */
4708 output_loc_sequence_raw (loc);
4711 /* This function builds a dwarf location descriptor sequence from a
4712 dw_cfa_location, adding the given OFFSET to the result of the
4715 static struct dw_loc_descr_struct *
4716 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
4718 struct dw_loc_descr_struct *head, *tmp;
4720 offset += cfa->offset;
4724 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
4725 head->dw_loc_oprnd1.val_class = dw_val_class_const;
4726 tmp = new_loc_descr (DW_OP_deref, 0, 0);
4727 add_loc_descr (&head, tmp);
4730 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4731 add_loc_descr (&head, tmp);
4735 head = new_reg_loc_descr (cfa->reg, offset);
4740 /* This function builds a dwarf location descriptor sequence for
4741 the address at OFFSET from the CFA when stack is aligned to
4744 static struct dw_loc_descr_struct *
4745 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4747 struct dw_loc_descr_struct *head;
4748 unsigned int dwarf_fp
4749 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4751 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4752 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4754 head = new_reg_loc_descr (dwarf_fp, 0);
4755 add_loc_descr (&head, int_loc_descriptor (alignment));
4756 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4757 loc_descr_plus_const (&head, offset);
4760 head = new_reg_loc_descr (dwarf_fp, offset);
4764 /* This function fills in aa dw_cfa_location structure from a dwarf location
4765 descriptor sequence. */
4768 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4770 struct dw_loc_descr_struct *ptr;
4772 cfa->base_offset = 0;
4776 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4778 enum dwarf_location_atom op = ptr->dw_loc_opc;
4814 cfa->reg = op - DW_OP_reg0;
4817 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4851 cfa->reg = op - DW_OP_breg0;
4852 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4855 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4856 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4861 case DW_OP_plus_uconst:
4862 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4865 internal_error ("DW_LOC_OP %s not implemented",
4866 dwarf_stack_op_name (ptr->dw_loc_opc));
4870 #endif /* .debug_frame support */
4872 /* And now, the support for symbolic debugging information. */
4873 #ifdef DWARF2_DEBUGGING_INFO
4875 /* .debug_str support. */
4876 static int output_indirect_string (void **, void *);
4878 static void dwarf2out_init (const char *);
4879 static void dwarf2out_finish (const char *);
4880 static void dwarf2out_define (unsigned int, const char *);
4881 static void dwarf2out_undef (unsigned int, const char *);
4882 static void dwarf2out_start_source_file (unsigned, const char *);
4883 static void dwarf2out_end_source_file (unsigned);
4884 static void dwarf2out_begin_block (unsigned, unsigned);
4885 static void dwarf2out_end_block (unsigned, unsigned);
4886 static bool dwarf2out_ignore_block (const_tree);
4887 static void dwarf2out_global_decl (tree);
4888 static void dwarf2out_type_decl (tree, int);
4889 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
4890 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
4892 static void dwarf2out_abstract_function (tree);
4893 static void dwarf2out_var_location (rtx);
4894 static void dwarf2out_begin_function (tree);
4895 static void dwarf2out_set_name (tree, tree);
4897 /* The debug hooks structure. */
4899 const struct gcc_debug_hooks dwarf2_debug_hooks =
4905 dwarf2out_start_source_file,
4906 dwarf2out_end_source_file,
4907 dwarf2out_begin_block,
4908 dwarf2out_end_block,
4909 dwarf2out_ignore_block,
4910 dwarf2out_source_line,
4911 dwarf2out_begin_prologue,
4912 debug_nothing_int_charstar, /* end_prologue */
4913 dwarf2out_end_epilogue,
4914 dwarf2out_begin_function,
4915 debug_nothing_int, /* end_function */
4916 dwarf2out_decl, /* function_decl */
4917 dwarf2out_global_decl,
4918 dwarf2out_type_decl, /* type_decl */
4919 dwarf2out_imported_module_or_decl,
4920 debug_nothing_tree, /* deferred_inline_function */
4921 /* The DWARF 2 backend tries to reduce debugging bloat by not
4922 emitting the abstract description of inline functions until
4923 something tries to reference them. */
4924 dwarf2out_abstract_function, /* outlining_inline_function */
4925 debug_nothing_rtx, /* label */
4926 debug_nothing_int, /* handle_pch */
4927 dwarf2out_var_location,
4928 dwarf2out_switch_text_section,
4930 1 /* start_end_main_source_file */
4934 /* NOTE: In the comments in this file, many references are made to
4935 "Debugging Information Entries". This term is abbreviated as `DIE'
4936 throughout the remainder of this file. */
4938 /* An internal representation of the DWARF output is built, and then
4939 walked to generate the DWARF debugging info. The walk of the internal
4940 representation is done after the entire program has been compiled.
4941 The types below are used to describe the internal representation. */
4943 /* Various DIE's use offsets relative to the beginning of the
4944 .debug_info section to refer to each other. */
4946 typedef long int dw_offset;
4948 /* Define typedefs here to avoid circular dependencies. */
4950 typedef struct dw_attr_struct *dw_attr_ref;
4951 typedef struct dw_line_info_struct *dw_line_info_ref;
4952 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
4953 typedef struct pubname_struct *pubname_ref;
4954 typedef struct dw_ranges_struct *dw_ranges_ref;
4955 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
4957 /* Each entry in the line_info_table maintains the file and
4958 line number associated with the label generated for that
4959 entry. The label gives the PC value associated with
4960 the line number entry. */
4962 typedef struct GTY(()) dw_line_info_struct {
4963 unsigned long dw_file_num;
4964 unsigned long dw_line_num;
4968 /* Line information for functions in separate sections; each one gets its
4970 typedef struct GTY(()) dw_separate_line_info_struct {
4971 unsigned long dw_file_num;
4972 unsigned long dw_line_num;
4973 unsigned long function;
4975 dw_separate_line_info_entry;
4977 /* Each DIE attribute has a field specifying the attribute kind,
4978 a link to the next attribute in the chain, and an attribute value.
4979 Attributes are typically linked below the DIE they modify. */
4981 typedef struct GTY(()) dw_attr_struct {
4982 enum dwarf_attribute dw_attr;
4983 dw_val_node dw_attr_val;
4987 DEF_VEC_O(dw_attr_node);
4988 DEF_VEC_ALLOC_O(dw_attr_node,gc);
4990 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4991 The children of each node form a circular list linked by
4992 die_sib. die_child points to the node *before* the "first" child node. */
4994 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
4995 enum dwarf_tag die_tag;
4997 VEC(dw_attr_node,gc) * die_attr;
4998 dw_die_ref die_parent;
4999 dw_die_ref die_child;
5001 dw_die_ref die_definition; /* ref from a specification to its definition */
5002 dw_offset die_offset;
5003 unsigned long die_abbrev;
5005 /* Die is used and must not be pruned as unused. */
5006 int die_perennial_p;
5007 unsigned int decl_id;
5011 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5012 #define FOR_EACH_CHILD(die, c, expr) do { \
5013 c = die->die_child; \
5017 } while (c != die->die_child); \
5020 /* The pubname structure */
5022 typedef struct GTY(()) pubname_struct {
5028 DEF_VEC_O(pubname_entry);
5029 DEF_VEC_ALLOC_O(pubname_entry, gc);
5031 struct GTY(()) dw_ranges_struct {
5032 /* If this is positive, it's a block number, otherwise it's a
5033 bitwise-negated index into dw_ranges_by_label. */
5037 struct GTY(()) dw_ranges_by_label_struct {
5042 /* The limbo die list structure. */
5043 typedef struct GTY(()) limbo_die_struct {
5046 struct limbo_die_struct *next;
5050 /* How to start an assembler comment. */
5051 #ifndef ASM_COMMENT_START
5052 #define ASM_COMMENT_START ";#"
5055 /* Define a macro which returns nonzero for a TYPE_DECL which was
5056 implicitly generated for a tagged type.
5058 Note that unlike the gcc front end (which generates a NULL named
5059 TYPE_DECL node for each complete tagged type, each array type, and
5060 each function type node created) the g++ front end generates a
5061 _named_ TYPE_DECL node for each tagged type node created.
5062 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
5063 generate a DW_TAG_typedef DIE for them. */
5065 #define TYPE_DECL_IS_STUB(decl) \
5066 (DECL_NAME (decl) == NULL_TREE \
5067 || (DECL_ARTIFICIAL (decl) \
5068 && is_tagged_type (TREE_TYPE (decl)) \
5069 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
5070 /* This is necessary for stub decls that \
5071 appear in nested inline functions. */ \
5072 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
5073 && (decl_ultimate_origin (decl) \
5074 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
5076 /* Information concerning the compilation unit's programming
5077 language, and compiler version. */
5079 /* Fixed size portion of the DWARF compilation unit header. */
5080 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
5081 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
5083 /* Fixed size portion of public names info. */
5084 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
5086 /* Fixed size portion of the address range info. */
5087 #define DWARF_ARANGES_HEADER_SIZE \
5088 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5089 DWARF2_ADDR_SIZE * 2) \
5090 - DWARF_INITIAL_LENGTH_SIZE)
5092 /* Size of padding portion in the address range info. It must be
5093 aligned to twice the pointer size. */
5094 #define DWARF_ARANGES_PAD_SIZE \
5095 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
5096 DWARF2_ADDR_SIZE * 2) \
5097 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
5099 /* Use assembler line directives if available. */
5100 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
5101 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
5102 #define DWARF2_ASM_LINE_DEBUG_INFO 1
5104 #define DWARF2_ASM_LINE_DEBUG_INFO 0
5108 /* Minimum line offset in a special line info. opcode.
5109 This value was chosen to give a reasonable range of values. */
5110 #define DWARF_LINE_BASE -10
5112 /* First special line opcode - leave room for the standard opcodes. */
5113 #define DWARF_LINE_OPCODE_BASE 10
5115 /* Range of line offsets in a special line info. opcode. */
5116 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
5118 /* Flag that indicates the initial value of the is_stmt_start flag.
5119 In the present implementation, we do not mark any lines as
5120 the beginning of a source statement, because that information
5121 is not made available by the GCC front-end. */
5122 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
5124 #ifdef DWARF2_DEBUGGING_INFO
5125 /* This location is used by calc_die_sizes() to keep track
5126 the offset of each DIE within the .debug_info section. */
5127 static unsigned long next_die_offset;
5130 /* Record the root of the DIE's built for the current compilation unit. */
5131 static GTY(()) dw_die_ref comp_unit_die;
5133 /* A list of DIEs with a NULL parent waiting to be relocated. */
5134 static GTY(()) limbo_die_node *limbo_die_list;
5136 /* Filenames referenced by this compilation unit. */
5137 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
5139 /* A hash table of references to DIE's that describe declarations.
5140 The key is a DECL_UID() which is a unique number identifying each decl. */
5141 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
5143 /* A hash table of references to DIE's that describe COMMON blocks.
5144 The key is DECL_UID() ^ die_parent. */
5145 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
5147 /* Node of the variable location list. */
5148 struct GTY ((chain_next ("%h.next"))) var_loc_node {
5149 rtx GTY (()) var_loc_note;
5150 const char * GTY (()) label;
5151 const char * GTY (()) section_label;
5152 struct var_loc_node * GTY (()) next;
5155 /* Variable location list. */
5156 struct GTY (()) var_loc_list_def {
5157 struct var_loc_node * GTY (()) first;
5159 /* Do not mark the last element of the chained list because
5160 it is marked through the chain. */
5161 struct var_loc_node * GTY ((skip ("%h"))) last;
5163 /* DECL_UID of the variable decl. */
5164 unsigned int decl_id;
5166 typedef struct var_loc_list_def var_loc_list;
5169 /* Table of decl location linked lists. */
5170 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
5172 /* A pointer to the base of a list of references to DIE's that
5173 are uniquely identified by their tag, presence/absence of
5174 children DIE's, and list of attribute/value pairs. */
5175 static GTY((length ("abbrev_die_table_allocated")))
5176 dw_die_ref *abbrev_die_table;
5178 /* Number of elements currently allocated for abbrev_die_table. */
5179 static GTY(()) unsigned abbrev_die_table_allocated;
5181 /* Number of elements in type_die_table currently in use. */
5182 static GTY(()) unsigned abbrev_die_table_in_use;
5184 /* Size (in elements) of increments by which we may expand the
5185 abbrev_die_table. */
5186 #define ABBREV_DIE_TABLE_INCREMENT 256
5188 /* A pointer to the base of a table that contains line information
5189 for each source code line in .text in the compilation unit. */
5190 static GTY((length ("line_info_table_allocated")))
5191 dw_line_info_ref line_info_table;
5193 /* Number of elements currently allocated for line_info_table. */
5194 static GTY(()) unsigned line_info_table_allocated;
5196 /* Number of elements in line_info_table currently in use. */
5197 static GTY(()) unsigned line_info_table_in_use;
5199 /* A pointer to the base of a table that contains line information
5200 for each source code line outside of .text in the compilation unit. */
5201 static GTY ((length ("separate_line_info_table_allocated")))
5202 dw_separate_line_info_ref separate_line_info_table;
5204 /* Number of elements currently allocated for separate_line_info_table. */
5205 static GTY(()) unsigned separate_line_info_table_allocated;
5207 /* Number of elements in separate_line_info_table currently in use. */
5208 static GTY(()) unsigned separate_line_info_table_in_use;
5210 /* Size (in elements) of increments by which we may expand the
5212 #define LINE_INFO_TABLE_INCREMENT 1024
5214 /* A pointer to the base of a table that contains a list of publicly
5215 accessible names. */
5216 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
5218 /* A pointer to the base of a table that contains a list of publicly
5219 accessible types. */
5220 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
5222 /* Array of dies for which we should generate .debug_arange info. */
5223 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
5225 /* Number of elements currently allocated for arange_table. */
5226 static GTY(()) unsigned arange_table_allocated;
5228 /* Number of elements in arange_table currently in use. */
5229 static GTY(()) unsigned arange_table_in_use;
5231 /* Size (in elements) of increments by which we may expand the
5233 #define ARANGE_TABLE_INCREMENT 64
5235 /* Array of dies for which we should generate .debug_ranges info. */
5236 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
5238 /* Number of elements currently allocated for ranges_table. */
5239 static GTY(()) unsigned ranges_table_allocated;
5241 /* Number of elements in ranges_table currently in use. */
5242 static GTY(()) unsigned ranges_table_in_use;
5244 /* Array of pairs of labels referenced in ranges_table. */
5245 static GTY ((length ("ranges_by_label_allocated")))
5246 dw_ranges_by_label_ref ranges_by_label;
5248 /* Number of elements currently allocated for ranges_by_label. */
5249 static GTY(()) unsigned ranges_by_label_allocated;
5251 /* Number of elements in ranges_by_label currently in use. */
5252 static GTY(()) unsigned ranges_by_label_in_use;
5254 /* Size (in elements) of increments by which we may expand the
5256 #define RANGES_TABLE_INCREMENT 64
5258 /* Whether we have location lists that need outputting */
5259 static GTY(()) bool have_location_lists;
5261 /* Unique label counter. */
5262 static GTY(()) unsigned int loclabel_num;
5264 #ifdef DWARF2_DEBUGGING_INFO
5265 /* Record whether the function being analyzed contains inlined functions. */
5266 static int current_function_has_inlines;
5268 #if 0 && defined (MIPS_DEBUGGING_INFO)
5269 static int comp_unit_has_inlines;
5272 /* The last file entry emitted by maybe_emit_file(). */
5273 static GTY(()) struct dwarf_file_data * last_emitted_file;
5275 /* Number of internal labels generated by gen_internal_sym(). */
5276 static GTY(()) int label_num;
5278 /* Cached result of previous call to lookup_filename. */
5279 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
5281 #ifdef DWARF2_DEBUGGING_INFO
5283 /* Offset from the "steady-state frame pointer" to the frame base,
5284 within the current function. */
5285 static HOST_WIDE_INT frame_pointer_fb_offset;
5287 /* Forward declarations for functions defined in this file. */
5289 static int is_pseudo_reg (const_rtx);
5290 static tree type_main_variant (tree);
5291 static int is_tagged_type (const_tree);
5292 static const char *dwarf_tag_name (unsigned);
5293 static const char *dwarf_attr_name (unsigned);
5294 static const char *dwarf_form_name (unsigned);
5295 static tree decl_ultimate_origin (const_tree);
5296 static tree decl_class_context (tree);
5297 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
5298 static inline enum dw_val_class AT_class (dw_attr_ref);
5299 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
5300 static inline unsigned AT_flag (dw_attr_ref);
5301 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
5302 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
5303 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
5304 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
5305 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
5307 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
5308 unsigned int, unsigned char *);
5309 static hashval_t debug_str_do_hash (const void *);
5310 static int debug_str_eq (const void *, const void *);
5311 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
5312 static inline const char *AT_string (dw_attr_ref);
5313 static enum dwarf_form AT_string_form (dw_attr_ref);
5314 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
5315 static void add_AT_specification (dw_die_ref, dw_die_ref);
5316 static inline dw_die_ref AT_ref (dw_attr_ref);
5317 static inline int AT_ref_external (dw_attr_ref);
5318 static inline void set_AT_ref_external (dw_attr_ref, int);
5319 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
5320 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
5321 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
5322 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
5324 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
5325 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
5326 static inline rtx AT_addr (dw_attr_ref);
5327 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
5328 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
5329 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
5330 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
5331 unsigned HOST_WIDE_INT);
5332 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
5334 static inline const char *AT_lbl (dw_attr_ref);
5335 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
5336 static const char *get_AT_low_pc (dw_die_ref);
5337 static const char *get_AT_hi_pc (dw_die_ref);
5338 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
5339 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
5340 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
5341 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
5342 static bool is_c_family (void);
5343 static bool is_cxx (void);
5344 static bool is_java (void);
5345 static bool is_fortran (void);
5346 static bool is_ada (void);
5347 static void remove_AT (dw_die_ref, enum dwarf_attribute);
5348 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
5349 static void add_child_die (dw_die_ref, dw_die_ref);
5350 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
5351 static dw_die_ref lookup_type_die (tree);
5352 static void equate_type_number_to_die (tree, dw_die_ref);
5353 static hashval_t decl_die_table_hash (const void *);
5354 static int decl_die_table_eq (const void *, const void *);
5355 static dw_die_ref lookup_decl_die (tree);
5356 static hashval_t common_block_die_table_hash (const void *);
5357 static int common_block_die_table_eq (const void *, const void *);
5358 static hashval_t decl_loc_table_hash (const void *);
5359 static int decl_loc_table_eq (const void *, const void *);
5360 static var_loc_list *lookup_decl_loc (const_tree);
5361 static void equate_decl_number_to_die (tree, dw_die_ref);
5362 static void add_var_loc_to_decl (tree, struct var_loc_node *);
5363 static void print_spaces (FILE *);
5364 static void print_die (dw_die_ref, FILE *);
5365 static void print_dwarf_line_table (FILE *);
5366 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
5367 static dw_die_ref pop_compile_unit (dw_die_ref);
5368 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
5369 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
5370 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
5371 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
5372 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
5373 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
5374 static int same_die_p (dw_die_ref, dw_die_ref, int *);
5375 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
5376 static void compute_section_prefix (dw_die_ref);
5377 static int is_type_die (dw_die_ref);
5378 static int is_comdat_die (dw_die_ref);
5379 static int is_symbol_die (dw_die_ref);
5380 static void assign_symbol_names (dw_die_ref);
5381 static void break_out_includes (dw_die_ref);
5382 static hashval_t htab_cu_hash (const void *);
5383 static int htab_cu_eq (const void *, const void *);
5384 static void htab_cu_del (void *);
5385 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
5386 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
5387 static void add_sibling_attributes (dw_die_ref);
5388 static void build_abbrev_table (dw_die_ref);
5389 static void output_location_lists (dw_die_ref);
5390 static int constant_size (unsigned HOST_WIDE_INT);
5391 static unsigned long size_of_die (dw_die_ref);
5392 static void calc_die_sizes (dw_die_ref);
5393 static void mark_dies (dw_die_ref);
5394 static void unmark_dies (dw_die_ref);
5395 static void unmark_all_dies (dw_die_ref);
5396 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
5397 static unsigned long size_of_aranges (void);
5398 static enum dwarf_form value_format (dw_attr_ref);
5399 static void output_value_format (dw_attr_ref);
5400 static void output_abbrev_section (void);
5401 static void output_die_symbol (dw_die_ref);
5402 static void output_die (dw_die_ref);
5403 static void output_compilation_unit_header (void);
5404 static void output_comp_unit (dw_die_ref, int);
5405 static const char *dwarf2_name (tree, int);
5406 static void add_pubname (tree, dw_die_ref);
5407 static void add_pubname_string (const char *, dw_die_ref);
5408 static void add_pubtype (tree, dw_die_ref);
5409 static void output_pubnames (VEC (pubname_entry,gc) *);
5410 static void add_arange (tree, dw_die_ref);
5411 static void output_aranges (void);
5412 static unsigned int add_ranges_num (int);
5413 static unsigned int add_ranges (const_tree);
5414 static unsigned int add_ranges_by_labels (const char *, const char *);
5415 static void output_ranges (void);
5416 static void output_line_info (void);
5417 static void output_file_names (void);
5418 static dw_die_ref base_type_die (tree);
5419 static int is_base_type (tree);
5420 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
5421 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
5422 static int type_is_enum (const_tree);
5423 static unsigned int dbx_reg_number (const_rtx);
5424 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
5425 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
5426 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
5427 enum var_init_status);
5428 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
5429 enum var_init_status);
5430 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
5431 enum var_init_status);
5432 static int is_based_loc (const_rtx);
5433 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
5434 enum var_init_status);
5435 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
5436 enum var_init_status);
5437 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
5438 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
5439 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
5440 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
5441 static tree field_type (const_tree);
5442 static unsigned int simple_type_align_in_bits (const_tree);
5443 static unsigned int simple_decl_align_in_bits (const_tree);
5444 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
5445 static HOST_WIDE_INT field_byte_offset (const_tree);
5446 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
5448 static void add_data_member_location_attribute (dw_die_ref, tree);
5449 static void add_const_value_attribute (dw_die_ref, rtx);
5450 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
5451 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5452 static void insert_float (const_rtx, unsigned char *);
5453 static rtx rtl_for_decl_location (tree);
5454 static void add_location_or_const_value_attribute (dw_die_ref, tree,
5455 enum dwarf_attribute);
5456 static void tree_add_const_value_attribute (dw_die_ref, tree);
5457 static void add_name_attribute (dw_die_ref, const char *);
5458 static void add_comp_dir_attribute (dw_die_ref);
5459 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
5460 static void add_subscript_info (dw_die_ref, tree, bool);
5461 static void add_byte_size_attribute (dw_die_ref, tree);
5462 static void add_bit_offset_attribute (dw_die_ref, tree);
5463 static void add_bit_size_attribute (dw_die_ref, tree);
5464 static void add_prototyped_attribute (dw_die_ref, tree);
5465 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
5466 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
5467 static void add_src_coords_attributes (dw_die_ref, tree);
5468 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
5469 static void push_decl_scope (tree);
5470 static void pop_decl_scope (void);
5471 static dw_die_ref scope_die_for (tree, dw_die_ref);
5472 static inline int local_scope_p (dw_die_ref);
5473 static inline int class_scope_p (dw_die_ref);
5474 static inline int class_or_namespace_scope_p (dw_die_ref);
5475 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
5476 static void add_calling_convention_attribute (dw_die_ref, tree);
5477 static const char *type_tag (const_tree);
5478 static tree member_declared_type (const_tree);
5480 static const char *decl_start_label (tree);
5482 static void gen_array_type_die (tree, dw_die_ref);
5483 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
5485 static void gen_entry_point_die (tree, dw_die_ref);
5487 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
5488 static dw_die_ref gen_formal_parameter_die (tree, tree, dw_die_ref);
5489 static void gen_unspecified_parameters_die (tree, dw_die_ref);
5490 static void gen_formal_types_die (tree, dw_die_ref);
5491 static void gen_subprogram_die (tree, dw_die_ref);
5492 static void gen_variable_die (tree, tree, dw_die_ref);
5493 static void gen_const_die (tree, dw_die_ref);
5494 static void gen_label_die (tree, dw_die_ref);
5495 static void gen_lexical_block_die (tree, dw_die_ref, int);
5496 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
5497 static void gen_field_die (tree, dw_die_ref);
5498 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
5499 static dw_die_ref gen_compile_unit_die (const char *);
5500 static void gen_inheritance_die (tree, tree, dw_die_ref);
5501 static void gen_member_die (tree, dw_die_ref);
5502 static void gen_struct_or_union_type_die (tree, dw_die_ref,
5503 enum debug_info_usage);
5504 static void gen_subroutine_type_die (tree, dw_die_ref);
5505 static void gen_typedef_die (tree, dw_die_ref);
5506 static void gen_type_die (tree, dw_die_ref);
5507 static void gen_block_die (tree, dw_die_ref, int);
5508 static void decls_for_scope (tree, dw_die_ref, int);
5509 static int is_redundant_typedef (const_tree);
5510 static void gen_namespace_die (tree, dw_die_ref);
5511 static void gen_decl_die (tree, tree, dw_die_ref);
5512 static dw_die_ref force_decl_die (tree);
5513 static dw_die_ref force_type_die (tree);
5514 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
5515 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
5516 static struct dwarf_file_data * lookup_filename (const char *);
5517 static void retry_incomplete_types (void);
5518 static void gen_type_die_for_member (tree, tree, dw_die_ref);
5519 static void splice_child_die (dw_die_ref, dw_die_ref);
5520 static int file_info_cmp (const void *, const void *);
5521 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
5522 const char *, const char *, unsigned);
5523 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
5524 const char *, const char *,
5526 static void output_loc_list (dw_loc_list_ref);
5527 static char *gen_internal_sym (const char *);
5529 static void prune_unmark_dies (dw_die_ref);
5530 static void prune_unused_types_mark (dw_die_ref, int);
5531 static void prune_unused_types_walk (dw_die_ref);
5532 static void prune_unused_types_walk_attribs (dw_die_ref);
5533 static void prune_unused_types_prune (dw_die_ref);
5534 static void prune_unused_types (void);
5535 static int maybe_emit_file (struct dwarf_file_data *fd);
5537 /* Section names used to hold DWARF debugging information. */
5538 #ifndef DEBUG_INFO_SECTION
5539 #define DEBUG_INFO_SECTION ".debug_info"
5541 #ifndef DEBUG_ABBREV_SECTION
5542 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
5544 #ifndef DEBUG_ARANGES_SECTION
5545 #define DEBUG_ARANGES_SECTION ".debug_aranges"
5547 #ifndef DEBUG_MACINFO_SECTION
5548 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
5550 #ifndef DEBUG_LINE_SECTION
5551 #define DEBUG_LINE_SECTION ".debug_line"
5553 #ifndef DEBUG_LOC_SECTION
5554 #define DEBUG_LOC_SECTION ".debug_loc"
5556 #ifndef DEBUG_PUBNAMES_SECTION
5557 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
5559 #ifndef DEBUG_STR_SECTION
5560 #define DEBUG_STR_SECTION ".debug_str"
5562 #ifndef DEBUG_RANGES_SECTION
5563 #define DEBUG_RANGES_SECTION ".debug_ranges"
5566 /* Standard ELF section names for compiled code and data. */
5567 #ifndef TEXT_SECTION_NAME
5568 #define TEXT_SECTION_NAME ".text"
5571 /* Section flags for .debug_str section. */
5572 #define DEBUG_STR_SECTION_FLAGS \
5573 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
5574 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
5577 /* Labels we insert at beginning sections we can reference instead of
5578 the section names themselves. */
5580 #ifndef TEXT_SECTION_LABEL
5581 #define TEXT_SECTION_LABEL "Ltext"
5583 #ifndef COLD_TEXT_SECTION_LABEL
5584 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
5586 #ifndef DEBUG_LINE_SECTION_LABEL
5587 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
5589 #ifndef DEBUG_INFO_SECTION_LABEL
5590 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
5592 #ifndef DEBUG_ABBREV_SECTION_LABEL
5593 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
5595 #ifndef DEBUG_LOC_SECTION_LABEL
5596 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
5598 #ifndef DEBUG_RANGES_SECTION_LABEL
5599 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
5601 #ifndef DEBUG_MACINFO_SECTION_LABEL
5602 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
5605 /* Definitions of defaults for formats and names of various special
5606 (artificial) labels which may be generated within this file (when the -g
5607 options is used and DWARF2_DEBUGGING_INFO is in effect.
5608 If necessary, these may be overridden from within the tm.h file, but
5609 typically, overriding these defaults is unnecessary. */
5611 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5612 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5613 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5614 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
5615 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5616 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5617 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5618 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5619 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
5620 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
5622 #ifndef TEXT_END_LABEL
5623 #define TEXT_END_LABEL "Letext"
5625 #ifndef COLD_END_LABEL
5626 #define COLD_END_LABEL "Letext_cold"
5628 #ifndef BLOCK_BEGIN_LABEL
5629 #define BLOCK_BEGIN_LABEL "LBB"
5631 #ifndef BLOCK_END_LABEL
5632 #define BLOCK_END_LABEL "LBE"
5634 #ifndef LINE_CODE_LABEL
5635 #define LINE_CODE_LABEL "LM"
5637 #ifndef SEPARATE_LINE_CODE_LABEL
5638 #define SEPARATE_LINE_CODE_LABEL "LSM"
5642 /* We allow a language front-end to designate a function that is to be
5643 called to "demangle" any name before it is put into a DIE. */
5645 static const char *(*demangle_name_func) (const char *);
5648 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
5650 demangle_name_func = func;
5653 /* Test if rtl node points to a pseudo register. */
5656 is_pseudo_reg (const_rtx rtl)
5658 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
5659 || (GET_CODE (rtl) == SUBREG
5660 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
5663 /* Return a reference to a type, with its const and volatile qualifiers
5667 type_main_variant (tree type)
5669 type = TYPE_MAIN_VARIANT (type);
5671 /* ??? There really should be only one main variant among any group of
5672 variants of a given type (and all of the MAIN_VARIANT values for all
5673 members of the group should point to that one type) but sometimes the C
5674 front-end messes this up for array types, so we work around that bug
5676 if (TREE_CODE (type) == ARRAY_TYPE)
5677 while (type != TYPE_MAIN_VARIANT (type))
5678 type = TYPE_MAIN_VARIANT (type);
5683 /* Return nonzero if the given type node represents a tagged type. */
5686 is_tagged_type (const_tree type)
5688 enum tree_code code = TREE_CODE (type);
5690 return (code == RECORD_TYPE || code == UNION_TYPE
5691 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
5694 /* Convert a DIE tag into its string name. */
5697 dwarf_tag_name (unsigned int tag)
5701 case DW_TAG_padding:
5702 return "DW_TAG_padding";
5703 case DW_TAG_array_type:
5704 return "DW_TAG_array_type";
5705 case DW_TAG_class_type:
5706 return "DW_TAG_class_type";
5707 case DW_TAG_entry_point:
5708 return "DW_TAG_entry_point";
5709 case DW_TAG_enumeration_type:
5710 return "DW_TAG_enumeration_type";
5711 case DW_TAG_formal_parameter:
5712 return "DW_TAG_formal_parameter";
5713 case DW_TAG_imported_declaration:
5714 return "DW_TAG_imported_declaration";
5716 return "DW_TAG_label";
5717 case DW_TAG_lexical_block:
5718 return "DW_TAG_lexical_block";
5720 return "DW_TAG_member";
5721 case DW_TAG_pointer_type:
5722 return "DW_TAG_pointer_type";
5723 case DW_TAG_reference_type:
5724 return "DW_TAG_reference_type";
5725 case DW_TAG_compile_unit:
5726 return "DW_TAG_compile_unit";
5727 case DW_TAG_string_type:
5728 return "DW_TAG_string_type";
5729 case DW_TAG_structure_type:
5730 return "DW_TAG_structure_type";
5731 case DW_TAG_subroutine_type:
5732 return "DW_TAG_subroutine_type";
5733 case DW_TAG_typedef:
5734 return "DW_TAG_typedef";
5735 case DW_TAG_union_type:
5736 return "DW_TAG_union_type";
5737 case DW_TAG_unspecified_parameters:
5738 return "DW_TAG_unspecified_parameters";
5739 case DW_TAG_variant:
5740 return "DW_TAG_variant";
5741 case DW_TAG_common_block:
5742 return "DW_TAG_common_block";
5743 case DW_TAG_common_inclusion:
5744 return "DW_TAG_common_inclusion";
5745 case DW_TAG_inheritance:
5746 return "DW_TAG_inheritance";
5747 case DW_TAG_inlined_subroutine:
5748 return "DW_TAG_inlined_subroutine";
5750 return "DW_TAG_module";
5751 case DW_TAG_ptr_to_member_type:
5752 return "DW_TAG_ptr_to_member_type";
5753 case DW_TAG_set_type:
5754 return "DW_TAG_set_type";
5755 case DW_TAG_subrange_type:
5756 return "DW_TAG_subrange_type";
5757 case DW_TAG_with_stmt:
5758 return "DW_TAG_with_stmt";
5759 case DW_TAG_access_declaration:
5760 return "DW_TAG_access_declaration";
5761 case DW_TAG_base_type:
5762 return "DW_TAG_base_type";
5763 case DW_TAG_catch_block:
5764 return "DW_TAG_catch_block";
5765 case DW_TAG_const_type:
5766 return "DW_TAG_const_type";
5767 case DW_TAG_constant:
5768 return "DW_TAG_constant";
5769 case DW_TAG_enumerator:
5770 return "DW_TAG_enumerator";
5771 case DW_TAG_file_type:
5772 return "DW_TAG_file_type";
5774 return "DW_TAG_friend";
5775 case DW_TAG_namelist:
5776 return "DW_TAG_namelist";
5777 case DW_TAG_namelist_item:
5778 return "DW_TAG_namelist_item";
5779 case DW_TAG_packed_type:
5780 return "DW_TAG_packed_type";
5781 case DW_TAG_subprogram:
5782 return "DW_TAG_subprogram";
5783 case DW_TAG_template_type_param:
5784 return "DW_TAG_template_type_param";
5785 case DW_TAG_template_value_param:
5786 return "DW_TAG_template_value_param";
5787 case DW_TAG_thrown_type:
5788 return "DW_TAG_thrown_type";
5789 case DW_TAG_try_block:
5790 return "DW_TAG_try_block";
5791 case DW_TAG_variant_part:
5792 return "DW_TAG_variant_part";
5793 case DW_TAG_variable:
5794 return "DW_TAG_variable";
5795 case DW_TAG_volatile_type:
5796 return "DW_TAG_volatile_type";
5797 case DW_TAG_dwarf_procedure:
5798 return "DW_TAG_dwarf_procedure";
5799 case DW_TAG_restrict_type:
5800 return "DW_TAG_restrict_type";
5801 case DW_TAG_interface_type:
5802 return "DW_TAG_interface_type";
5803 case DW_TAG_namespace:
5804 return "DW_TAG_namespace";
5805 case DW_TAG_imported_module:
5806 return "DW_TAG_imported_module";
5807 case DW_TAG_unspecified_type:
5808 return "DW_TAG_unspecified_type";
5809 case DW_TAG_partial_unit:
5810 return "DW_TAG_partial_unit";
5811 case DW_TAG_imported_unit:
5812 return "DW_TAG_imported_unit";
5813 case DW_TAG_condition:
5814 return "DW_TAG_condition";
5815 case DW_TAG_shared_type:
5816 return "DW_TAG_shared_type";
5817 case DW_TAG_MIPS_loop:
5818 return "DW_TAG_MIPS_loop";
5819 case DW_TAG_format_label:
5820 return "DW_TAG_format_label";
5821 case DW_TAG_function_template:
5822 return "DW_TAG_function_template";
5823 case DW_TAG_class_template:
5824 return "DW_TAG_class_template";
5825 case DW_TAG_GNU_BINCL:
5826 return "DW_TAG_GNU_BINCL";
5827 case DW_TAG_GNU_EINCL:
5828 return "DW_TAG_GNU_EINCL";
5830 return "DW_TAG_<unknown>";
5834 /* Convert a DWARF attribute code into its string name. */
5837 dwarf_attr_name (unsigned int attr)
5842 return "DW_AT_sibling";
5843 case DW_AT_location:
5844 return "DW_AT_location";
5846 return "DW_AT_name";
5847 case DW_AT_ordering:
5848 return "DW_AT_ordering";
5849 case DW_AT_subscr_data:
5850 return "DW_AT_subscr_data";
5851 case DW_AT_byte_size:
5852 return "DW_AT_byte_size";
5853 case DW_AT_bit_offset:
5854 return "DW_AT_bit_offset";
5855 case DW_AT_bit_size:
5856 return "DW_AT_bit_size";
5857 case DW_AT_element_list:
5858 return "DW_AT_element_list";
5859 case DW_AT_stmt_list:
5860 return "DW_AT_stmt_list";
5862 return "DW_AT_low_pc";
5864 return "DW_AT_high_pc";
5865 case DW_AT_language:
5866 return "DW_AT_language";
5868 return "DW_AT_member";
5870 return "DW_AT_discr";
5871 case DW_AT_discr_value:
5872 return "DW_AT_discr_value";
5873 case DW_AT_visibility:
5874 return "DW_AT_visibility";
5876 return "DW_AT_import";
5877 case DW_AT_string_length:
5878 return "DW_AT_string_length";
5879 case DW_AT_common_reference:
5880 return "DW_AT_common_reference";
5881 case DW_AT_comp_dir:
5882 return "DW_AT_comp_dir";
5883 case DW_AT_const_value:
5884 return "DW_AT_const_value";
5885 case DW_AT_containing_type:
5886 return "DW_AT_containing_type";
5887 case DW_AT_default_value:
5888 return "DW_AT_default_value";
5890 return "DW_AT_inline";
5891 case DW_AT_is_optional:
5892 return "DW_AT_is_optional";
5893 case DW_AT_lower_bound:
5894 return "DW_AT_lower_bound";
5895 case DW_AT_producer:
5896 return "DW_AT_producer";
5897 case DW_AT_prototyped:
5898 return "DW_AT_prototyped";
5899 case DW_AT_return_addr:
5900 return "DW_AT_return_addr";
5901 case DW_AT_start_scope:
5902 return "DW_AT_start_scope";
5903 case DW_AT_bit_stride:
5904 return "DW_AT_bit_stride";
5905 case DW_AT_upper_bound:
5906 return "DW_AT_upper_bound";
5907 case DW_AT_abstract_origin:
5908 return "DW_AT_abstract_origin";
5909 case DW_AT_accessibility:
5910 return "DW_AT_accessibility";
5911 case DW_AT_address_class:
5912 return "DW_AT_address_class";
5913 case DW_AT_artificial:
5914 return "DW_AT_artificial";
5915 case DW_AT_base_types:
5916 return "DW_AT_base_types";
5917 case DW_AT_calling_convention:
5918 return "DW_AT_calling_convention";
5920 return "DW_AT_count";
5921 case DW_AT_data_member_location:
5922 return "DW_AT_data_member_location";
5923 case DW_AT_decl_column:
5924 return "DW_AT_decl_column";
5925 case DW_AT_decl_file:
5926 return "DW_AT_decl_file";
5927 case DW_AT_decl_line:
5928 return "DW_AT_decl_line";
5929 case DW_AT_declaration:
5930 return "DW_AT_declaration";
5931 case DW_AT_discr_list:
5932 return "DW_AT_discr_list";
5933 case DW_AT_encoding:
5934 return "DW_AT_encoding";
5935 case DW_AT_external:
5936 return "DW_AT_external";
5937 case DW_AT_explicit:
5938 return "DW_AT_explicit";
5939 case DW_AT_frame_base:
5940 return "DW_AT_frame_base";
5942 return "DW_AT_friend";
5943 case DW_AT_identifier_case:
5944 return "DW_AT_identifier_case";
5945 case DW_AT_macro_info:
5946 return "DW_AT_macro_info";
5947 case DW_AT_namelist_items:
5948 return "DW_AT_namelist_items";
5949 case DW_AT_priority:
5950 return "DW_AT_priority";
5952 return "DW_AT_segment";
5953 case DW_AT_specification:
5954 return "DW_AT_specification";
5955 case DW_AT_static_link:
5956 return "DW_AT_static_link";
5958 return "DW_AT_type";
5959 case DW_AT_use_location:
5960 return "DW_AT_use_location";
5961 case DW_AT_variable_parameter:
5962 return "DW_AT_variable_parameter";
5963 case DW_AT_virtuality:
5964 return "DW_AT_virtuality";
5965 case DW_AT_vtable_elem_location:
5966 return "DW_AT_vtable_elem_location";
5968 case DW_AT_allocated:
5969 return "DW_AT_allocated";
5970 case DW_AT_associated:
5971 return "DW_AT_associated";
5972 case DW_AT_data_location:
5973 return "DW_AT_data_location";
5974 case DW_AT_byte_stride:
5975 return "DW_AT_byte_stride";
5976 case DW_AT_entry_pc:
5977 return "DW_AT_entry_pc";
5978 case DW_AT_use_UTF8:
5979 return "DW_AT_use_UTF8";
5980 case DW_AT_extension:
5981 return "DW_AT_extension";
5983 return "DW_AT_ranges";
5984 case DW_AT_trampoline:
5985 return "DW_AT_trampoline";
5986 case DW_AT_call_column:
5987 return "DW_AT_call_column";
5988 case DW_AT_call_file:
5989 return "DW_AT_call_file";
5990 case DW_AT_call_line:
5991 return "DW_AT_call_line";
5993 case DW_AT_MIPS_fde:
5994 return "DW_AT_MIPS_fde";
5995 case DW_AT_MIPS_loop_begin:
5996 return "DW_AT_MIPS_loop_begin";
5997 case DW_AT_MIPS_tail_loop_begin:
5998 return "DW_AT_MIPS_tail_loop_begin";
5999 case DW_AT_MIPS_epilog_begin:
6000 return "DW_AT_MIPS_epilog_begin";
6001 case DW_AT_MIPS_loop_unroll_factor:
6002 return "DW_AT_MIPS_loop_unroll_factor";
6003 case DW_AT_MIPS_software_pipeline_depth:
6004 return "DW_AT_MIPS_software_pipeline_depth";
6005 case DW_AT_MIPS_linkage_name:
6006 return "DW_AT_MIPS_linkage_name";
6007 case DW_AT_MIPS_stride:
6008 return "DW_AT_MIPS_stride";
6009 case DW_AT_MIPS_abstract_name:
6010 return "DW_AT_MIPS_abstract_name";
6011 case DW_AT_MIPS_clone_origin:
6012 return "DW_AT_MIPS_clone_origin";
6013 case DW_AT_MIPS_has_inlines:
6014 return "DW_AT_MIPS_has_inlines";
6016 case DW_AT_sf_names:
6017 return "DW_AT_sf_names";
6018 case DW_AT_src_info:
6019 return "DW_AT_src_info";
6020 case DW_AT_mac_info:
6021 return "DW_AT_mac_info";
6022 case DW_AT_src_coords:
6023 return "DW_AT_src_coords";
6024 case DW_AT_body_begin:
6025 return "DW_AT_body_begin";
6026 case DW_AT_body_end:
6027 return "DW_AT_body_end";
6028 case DW_AT_GNU_vector:
6029 return "DW_AT_GNU_vector";
6031 case DW_AT_VMS_rtnbeg_pd_address:
6032 return "DW_AT_VMS_rtnbeg_pd_address";
6035 return "DW_AT_<unknown>";
6039 /* Convert a DWARF value form code into its string name. */
6042 dwarf_form_name (unsigned int form)
6047 return "DW_FORM_addr";
6048 case DW_FORM_block2:
6049 return "DW_FORM_block2";
6050 case DW_FORM_block4:
6051 return "DW_FORM_block4";
6053 return "DW_FORM_data2";
6055 return "DW_FORM_data4";
6057 return "DW_FORM_data8";
6058 case DW_FORM_string:
6059 return "DW_FORM_string";
6061 return "DW_FORM_block";
6062 case DW_FORM_block1:
6063 return "DW_FORM_block1";
6065 return "DW_FORM_data1";
6067 return "DW_FORM_flag";
6069 return "DW_FORM_sdata";
6071 return "DW_FORM_strp";
6073 return "DW_FORM_udata";
6074 case DW_FORM_ref_addr:
6075 return "DW_FORM_ref_addr";
6077 return "DW_FORM_ref1";
6079 return "DW_FORM_ref2";
6081 return "DW_FORM_ref4";
6083 return "DW_FORM_ref8";
6084 case DW_FORM_ref_udata:
6085 return "DW_FORM_ref_udata";
6086 case DW_FORM_indirect:
6087 return "DW_FORM_indirect";
6089 return "DW_FORM_<unknown>";
6093 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
6094 instance of an inlined instance of a decl which is local to an inline
6095 function, so we have to trace all of the way back through the origin chain
6096 to find out what sort of node actually served as the original seed for the
6100 decl_ultimate_origin (const_tree decl)
6102 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
6105 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
6106 nodes in the function to point to themselves; ignore that if
6107 we're trying to output the abstract instance of this function. */
6108 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
6111 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
6112 most distant ancestor, this should never happen. */
6113 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
6115 return DECL_ABSTRACT_ORIGIN (decl);
6118 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
6119 of a virtual function may refer to a base class, so we check the 'this'
6123 decl_class_context (tree decl)
6125 tree context = NULL_TREE;
6127 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
6128 context = DECL_CONTEXT (decl);
6130 context = TYPE_MAIN_VARIANT
6131 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6133 if (context && !TYPE_P (context))
6134 context = NULL_TREE;
6139 /* Add an attribute/value pair to a DIE. */
6142 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
6144 /* Maybe this should be an assert? */
6148 if (die->die_attr == NULL)
6149 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
6150 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
6153 static inline enum dw_val_class
6154 AT_class (dw_attr_ref a)
6156 return a->dw_attr_val.val_class;
6159 /* Add a flag value attribute to a DIE. */
6162 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
6166 attr.dw_attr = attr_kind;
6167 attr.dw_attr_val.val_class = dw_val_class_flag;
6168 attr.dw_attr_val.v.val_flag = flag;
6169 add_dwarf_attr (die, &attr);
6172 static inline unsigned
6173 AT_flag (dw_attr_ref a)
6175 gcc_assert (a && AT_class (a) == dw_val_class_flag);
6176 return a->dw_attr_val.v.val_flag;
6179 /* Add a signed integer attribute value to a DIE. */
6182 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
6186 attr.dw_attr = attr_kind;
6187 attr.dw_attr_val.val_class = dw_val_class_const;
6188 attr.dw_attr_val.v.val_int = int_val;
6189 add_dwarf_attr (die, &attr);
6192 static inline HOST_WIDE_INT
6193 AT_int (dw_attr_ref a)
6195 gcc_assert (a && AT_class (a) == dw_val_class_const);
6196 return a->dw_attr_val.v.val_int;
6199 /* Add an unsigned integer attribute value to a DIE. */
6202 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
6203 unsigned HOST_WIDE_INT unsigned_val)
6207 attr.dw_attr = attr_kind;
6208 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
6209 attr.dw_attr_val.v.val_unsigned = unsigned_val;
6210 add_dwarf_attr (die, &attr);
6213 static inline unsigned HOST_WIDE_INT
6214 AT_unsigned (dw_attr_ref a)
6216 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
6217 return a->dw_attr_val.v.val_unsigned;
6220 /* Add an unsigned double integer attribute value to a DIE. */
6223 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
6224 long unsigned int val_hi, long unsigned int val_low)
6228 attr.dw_attr = attr_kind;
6229 attr.dw_attr_val.val_class = dw_val_class_long_long;
6230 attr.dw_attr_val.v.val_long_long.hi = val_hi;
6231 attr.dw_attr_val.v.val_long_long.low = val_low;
6232 add_dwarf_attr (die, &attr);
6235 /* Add a floating point attribute value to a DIE and return it. */
6238 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
6239 unsigned int length, unsigned int elt_size, unsigned char *array)
6243 attr.dw_attr = attr_kind;
6244 attr.dw_attr_val.val_class = dw_val_class_vec;
6245 attr.dw_attr_val.v.val_vec.length = length;
6246 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
6247 attr.dw_attr_val.v.val_vec.array = array;
6248 add_dwarf_attr (die, &attr);
6251 /* Hash and equality functions for debug_str_hash. */
6254 debug_str_do_hash (const void *x)
6256 return htab_hash_string (((const struct indirect_string_node *)x)->str);
6260 debug_str_eq (const void *x1, const void *x2)
6262 return strcmp ((((const struct indirect_string_node *)x1)->str),
6263 (const char *)x2) == 0;
6266 static struct indirect_string_node *
6267 find_AT_string (const char *str)
6269 struct indirect_string_node *node;
6272 if (! debug_str_hash)
6273 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
6274 debug_str_eq, NULL);
6276 slot = htab_find_slot_with_hash (debug_str_hash, str,
6277 htab_hash_string (str), INSERT);
6280 node = (struct indirect_string_node *)
6281 ggc_alloc_cleared (sizeof (struct indirect_string_node));
6282 node->str = ggc_strdup (str);
6286 node = (struct indirect_string_node *) *slot;
6292 /* Add a string attribute value to a DIE. */
6295 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
6298 struct indirect_string_node *node;
6300 node = find_AT_string (str);
6302 attr.dw_attr = attr_kind;
6303 attr.dw_attr_val.val_class = dw_val_class_str;
6304 attr.dw_attr_val.v.val_str = node;
6305 add_dwarf_attr (die, &attr);
6308 static inline const char *
6309 AT_string (dw_attr_ref a)
6311 gcc_assert (a && AT_class (a) == dw_val_class_str);
6312 return a->dw_attr_val.v.val_str->str;
6315 /* Find out whether a string should be output inline in DIE
6316 or out-of-line in .debug_str section. */
6318 static enum dwarf_form
6319 AT_string_form (dw_attr_ref a)
6321 struct indirect_string_node *node;
6325 gcc_assert (a && AT_class (a) == dw_val_class_str);
6327 node = a->dw_attr_val.v.val_str;
6331 len = strlen (node->str) + 1;
6333 /* If the string is shorter or equal to the size of the reference, it is
6334 always better to put it inline. */
6335 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
6336 return node->form = DW_FORM_string;
6338 /* If we cannot expect the linker to merge strings in .debug_str
6339 section, only put it into .debug_str if it is worth even in this
6341 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
6342 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
6343 return node->form = DW_FORM_string;
6345 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
6346 ++dw2_string_counter;
6347 node->label = xstrdup (label);
6349 return node->form = DW_FORM_strp;
6352 /* Add a DIE reference attribute value to a DIE. */
6355 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
6359 attr.dw_attr = attr_kind;
6360 attr.dw_attr_val.val_class = dw_val_class_die_ref;
6361 attr.dw_attr_val.v.val_die_ref.die = targ_die;
6362 attr.dw_attr_val.v.val_die_ref.external = 0;
6363 add_dwarf_attr (die, &attr);
6366 /* Add an AT_specification attribute to a DIE, and also make the back
6367 pointer from the specification to the definition. */
6370 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
6372 add_AT_die_ref (die, DW_AT_specification, targ_die);
6373 gcc_assert (!targ_die->die_definition);
6374 targ_die->die_definition = die;
6377 static inline dw_die_ref
6378 AT_ref (dw_attr_ref a)
6380 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6381 return a->dw_attr_val.v.val_die_ref.die;
6385 AT_ref_external (dw_attr_ref a)
6387 if (a && AT_class (a) == dw_val_class_die_ref)
6388 return a->dw_attr_val.v.val_die_ref.external;
6394 set_AT_ref_external (dw_attr_ref a, int i)
6396 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
6397 a->dw_attr_val.v.val_die_ref.external = i;
6400 /* Add an FDE reference attribute value to a DIE. */
6403 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
6407 attr.dw_attr = attr_kind;
6408 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
6409 attr.dw_attr_val.v.val_fde_index = targ_fde;
6410 add_dwarf_attr (die, &attr);
6413 /* Add a location description attribute value to a DIE. */
6416 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
6420 attr.dw_attr = attr_kind;
6421 attr.dw_attr_val.val_class = dw_val_class_loc;
6422 attr.dw_attr_val.v.val_loc = loc;
6423 add_dwarf_attr (die, &attr);
6426 static inline dw_loc_descr_ref
6427 AT_loc (dw_attr_ref a)
6429 gcc_assert (a && AT_class (a) == dw_val_class_loc);
6430 return a->dw_attr_val.v.val_loc;
6434 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
6438 attr.dw_attr = attr_kind;
6439 attr.dw_attr_val.val_class = dw_val_class_loc_list;
6440 attr.dw_attr_val.v.val_loc_list = loc_list;
6441 add_dwarf_attr (die, &attr);
6442 have_location_lists = true;
6445 static inline dw_loc_list_ref
6446 AT_loc_list (dw_attr_ref a)
6448 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
6449 return a->dw_attr_val.v.val_loc_list;
6452 /* Add an address constant attribute value to a DIE. */
6455 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
6459 attr.dw_attr = attr_kind;
6460 attr.dw_attr_val.val_class = dw_val_class_addr;
6461 attr.dw_attr_val.v.val_addr = addr;
6462 add_dwarf_attr (die, &attr);
6465 /* Get the RTX from to an address DIE attribute. */
6468 AT_addr (dw_attr_ref a)
6470 gcc_assert (a && AT_class (a) == dw_val_class_addr);
6471 return a->dw_attr_val.v.val_addr;
6474 /* Add a file attribute value to a DIE. */
6477 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
6478 struct dwarf_file_data *fd)
6482 attr.dw_attr = attr_kind;
6483 attr.dw_attr_val.val_class = dw_val_class_file;
6484 attr.dw_attr_val.v.val_file = fd;
6485 add_dwarf_attr (die, &attr);
6488 /* Get the dwarf_file_data from a file DIE attribute. */
6490 static inline struct dwarf_file_data *
6491 AT_file (dw_attr_ref a)
6493 gcc_assert (a && AT_class (a) == dw_val_class_file);
6494 return a->dw_attr_val.v.val_file;
6497 /* Add a label identifier attribute value to a DIE. */
6500 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
6504 attr.dw_attr = attr_kind;
6505 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
6506 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
6507 add_dwarf_attr (die, &attr);
6510 /* Add a section offset attribute value to a DIE, an offset into the
6511 debug_line section. */
6514 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6519 attr.dw_attr = attr_kind;
6520 attr.dw_attr_val.val_class = dw_val_class_lineptr;
6521 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6522 add_dwarf_attr (die, &attr);
6525 /* Add a section offset attribute value to a DIE, an offset into the
6526 debug_macinfo section. */
6529 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
6534 attr.dw_attr = attr_kind;
6535 attr.dw_attr_val.val_class = dw_val_class_macptr;
6536 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
6537 add_dwarf_attr (die, &attr);
6540 /* Add an offset attribute value to a DIE. */
6543 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
6544 unsigned HOST_WIDE_INT offset)
6548 attr.dw_attr = attr_kind;
6549 attr.dw_attr_val.val_class = dw_val_class_offset;
6550 attr.dw_attr_val.v.val_offset = offset;
6551 add_dwarf_attr (die, &attr);
6554 /* Add an range_list attribute value to a DIE. */
6557 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
6558 long unsigned int offset)
6562 attr.dw_attr = attr_kind;
6563 attr.dw_attr_val.val_class = dw_val_class_range_list;
6564 attr.dw_attr_val.v.val_offset = offset;
6565 add_dwarf_attr (die, &attr);
6568 static inline const char *
6569 AT_lbl (dw_attr_ref a)
6571 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
6572 || AT_class (a) == dw_val_class_lineptr
6573 || AT_class (a) == dw_val_class_macptr));
6574 return a->dw_attr_val.v.val_lbl_id;
6577 /* Get the attribute of type attr_kind. */
6580 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6584 dw_die_ref spec = NULL;
6589 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6590 if (a->dw_attr == attr_kind)
6592 else if (a->dw_attr == DW_AT_specification
6593 || a->dw_attr == DW_AT_abstract_origin)
6597 return get_AT (spec, attr_kind);
6602 /* Return the "low pc" attribute value, typically associated with a subprogram
6603 DIE. Return null if the "low pc" attribute is either not present, or if it
6604 cannot be represented as an assembler label identifier. */
6606 static inline const char *
6607 get_AT_low_pc (dw_die_ref die)
6609 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
6611 return a ? AT_lbl (a) : NULL;
6614 /* Return the "high pc" attribute value, typically associated with a subprogram
6615 DIE. Return null if the "high pc" attribute is either not present, or if it
6616 cannot be represented as an assembler label identifier. */
6618 static inline const char *
6619 get_AT_hi_pc (dw_die_ref die)
6621 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
6623 return a ? AT_lbl (a) : NULL;
6626 /* Return the value of the string attribute designated by ATTR_KIND, or
6627 NULL if it is not present. */
6629 static inline const char *
6630 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
6632 dw_attr_ref a = get_AT (die, attr_kind);
6634 return a ? AT_string (a) : NULL;
6637 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
6638 if it is not present. */
6641 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
6643 dw_attr_ref a = get_AT (die, attr_kind);
6645 return a ? AT_flag (a) : 0;
6648 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
6649 if it is not present. */
6651 static inline unsigned
6652 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
6654 dw_attr_ref a = get_AT (die, attr_kind);
6656 return a ? AT_unsigned (a) : 0;
6659 static inline dw_die_ref
6660 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
6662 dw_attr_ref a = get_AT (die, attr_kind);
6664 return a ? AT_ref (a) : NULL;
6667 static inline struct dwarf_file_data *
6668 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
6670 dw_attr_ref a = get_AT (die, attr_kind);
6672 return a ? AT_file (a) : NULL;
6675 /* Return TRUE if the language is C or C++. */
6680 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6682 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
6683 || lang == DW_LANG_C99
6684 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
6687 /* Return TRUE if the language is C++. */
6692 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6694 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6697 /* Return TRUE if the language is Fortran. */
6702 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6704 return (lang == DW_LANG_Fortran77
6705 || lang == DW_LANG_Fortran90
6706 || lang == DW_LANG_Fortran95);
6709 /* Return TRUE if the language is Java. */
6714 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6716 return lang == DW_LANG_Java;
6719 /* Return TRUE if the language is Ada. */
6724 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6726 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6729 /* Remove the specified attribute if present. */
6732 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6740 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6741 if (a->dw_attr == attr_kind)
6743 if (AT_class (a) == dw_val_class_str)
6744 if (a->dw_attr_val.v.val_str->refcount)
6745 a->dw_attr_val.v.val_str->refcount--;
6747 /* VEC_ordered_remove should help reduce the number of abbrevs
6749 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6754 /* Remove CHILD from its parent. PREV must have the property that
6755 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6758 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6760 gcc_assert (child->die_parent == prev->die_parent);
6761 gcc_assert (prev->die_sib == child);
6764 gcc_assert (child->die_parent->die_child == child);
6768 prev->die_sib = child->die_sib;
6769 if (child->die_parent->die_child == child)
6770 child->die_parent->die_child = prev;
6773 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6777 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6783 dw_die_ref prev = c;
6785 while (c->die_tag == tag)
6787 remove_child_with_prev (c, prev);
6788 /* Might have removed every child. */
6789 if (c == c->die_sib)
6793 } while (c != die->die_child);
6796 /* Add a CHILD_DIE as the last child of DIE. */
6799 add_child_die (dw_die_ref die, dw_die_ref child_die)
6801 /* FIXME this should probably be an assert. */
6802 if (! die || ! child_die)
6804 gcc_assert (die != child_die);
6806 child_die->die_parent = die;
6809 child_die->die_sib = die->die_child->die_sib;
6810 die->die_child->die_sib = child_die;
6813 child_die->die_sib = child_die;
6814 die->die_child = child_die;
6817 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6818 is the specification, to the end of PARENT's list of children.
6819 This is done by removing and re-adding it. */
6822 splice_child_die (dw_die_ref parent, dw_die_ref child)
6826 /* We want the declaration DIE from inside the class, not the
6827 specification DIE at toplevel. */
6828 if (child->die_parent != parent)
6830 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6836 gcc_assert (child->die_parent == parent
6837 || (child->die_parent
6838 == get_AT_ref (parent, DW_AT_specification)));
6840 for (p = child->die_parent->die_child; ; p = p->die_sib)
6841 if (p->die_sib == child)
6843 remove_child_with_prev (child, p);
6847 add_child_die (parent, child);
6850 /* Return a pointer to a newly created DIE node. */
6852 static inline dw_die_ref
6853 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6855 dw_die_ref die = GGC_CNEW (die_node);
6857 die->die_tag = tag_value;
6859 if (parent_die != NULL)
6860 add_child_die (parent_die, die);
6863 limbo_die_node *limbo_node;
6865 limbo_node = GGC_CNEW (limbo_die_node);
6866 limbo_node->die = die;
6867 limbo_node->created_for = t;
6868 limbo_node->next = limbo_die_list;
6869 limbo_die_list = limbo_node;
6875 /* Return the DIE associated with the given type specifier. */
6877 static inline dw_die_ref
6878 lookup_type_die (tree type)
6880 return TYPE_SYMTAB_DIE (type);
6883 /* Equate a DIE to a given type specifier. */
6886 equate_type_number_to_die (tree type, dw_die_ref type_die)
6888 TYPE_SYMTAB_DIE (type) = type_die;
6891 /* Returns a hash value for X (which really is a die_struct). */
6894 decl_die_table_hash (const void *x)
6896 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
6899 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6902 decl_die_table_eq (const void *x, const void *y)
6904 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
6907 /* Return the DIE associated with a given declaration. */
6909 static inline dw_die_ref
6910 lookup_decl_die (tree decl)
6912 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
6915 /* Returns a hash value for X (which really is a var_loc_list). */
6918 decl_loc_table_hash (const void *x)
6920 return (hashval_t) ((const var_loc_list *) x)->decl_id;
6923 /* Return nonzero if decl_id of var_loc_list X is the same as
6927 decl_loc_table_eq (const void *x, const void *y)
6929 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
6932 /* Return the var_loc list associated with a given declaration. */
6934 static inline var_loc_list *
6935 lookup_decl_loc (const_tree decl)
6937 return (var_loc_list *)
6938 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
6941 /* Equate a DIE to a particular declaration. */
6944 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6946 unsigned int decl_id = DECL_UID (decl);
6949 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
6951 decl_die->decl_id = decl_id;
6954 /* Add a variable location node to the linked list for DECL. */
6957 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
6959 unsigned int decl_id = DECL_UID (decl);
6963 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
6966 temp = GGC_CNEW (var_loc_list);
6967 temp->decl_id = decl_id;
6971 temp = (var_loc_list *) *slot;
6975 /* If the current location is the same as the end of the list,
6976 and either both or neither of the locations is uninitialized,
6977 we have nothing to do. */
6978 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
6979 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
6980 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6981 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
6982 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6983 == VAR_INIT_STATUS_UNINITIALIZED)
6984 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
6985 == VAR_INIT_STATUS_UNINITIALIZED))))
6987 /* Add LOC to the end of list and update LAST. */
6988 temp->last->next = loc;
6992 /* Do not add empty location to the beginning of the list. */
6993 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
7000 /* Keep track of the number of spaces used to indent the
7001 output of the debugging routines that print the structure of
7002 the DIE internal representation. */
7003 static int print_indent;
7005 /* Indent the line the number of spaces given by print_indent. */
7008 print_spaces (FILE *outfile)
7010 fprintf (outfile, "%*s", print_indent, "");
7013 /* Print the information associated with a given DIE, and its children.
7014 This routine is a debugging aid only. */
7017 print_die (dw_die_ref die, FILE *outfile)
7023 print_spaces (outfile);
7024 fprintf (outfile, "DIE %4ld: %s\n",
7025 die->die_offset, dwarf_tag_name (die->die_tag));
7026 print_spaces (outfile);
7027 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
7028 fprintf (outfile, " offset: %ld\n", die->die_offset);
7030 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7032 print_spaces (outfile);
7033 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
7035 switch (AT_class (a))
7037 case dw_val_class_addr:
7038 fprintf (outfile, "address");
7040 case dw_val_class_offset:
7041 fprintf (outfile, "offset");
7043 case dw_val_class_loc:
7044 fprintf (outfile, "location descriptor");
7046 case dw_val_class_loc_list:
7047 fprintf (outfile, "location list -> label:%s",
7048 AT_loc_list (a)->ll_symbol);
7050 case dw_val_class_range_list:
7051 fprintf (outfile, "range list");
7053 case dw_val_class_const:
7054 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
7056 case dw_val_class_unsigned_const:
7057 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
7059 case dw_val_class_long_long:
7060 fprintf (outfile, "constant (%lu,%lu)",
7061 a->dw_attr_val.v.val_long_long.hi,
7062 a->dw_attr_val.v.val_long_long.low);
7064 case dw_val_class_vec:
7065 fprintf (outfile, "floating-point or vector constant");
7067 case dw_val_class_flag:
7068 fprintf (outfile, "%u", AT_flag (a));
7070 case dw_val_class_die_ref:
7071 if (AT_ref (a) != NULL)
7073 if (AT_ref (a)->die_symbol)
7074 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
7076 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
7079 fprintf (outfile, "die -> <null>");
7081 case dw_val_class_lbl_id:
7082 case dw_val_class_lineptr:
7083 case dw_val_class_macptr:
7084 fprintf (outfile, "label: %s", AT_lbl (a));
7086 case dw_val_class_str:
7087 if (AT_string (a) != NULL)
7088 fprintf (outfile, "\"%s\"", AT_string (a));
7090 fprintf (outfile, "<null>");
7092 case dw_val_class_file:
7093 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
7094 AT_file (a)->emitted_number);
7100 fprintf (outfile, "\n");
7103 if (die->die_child != NULL)
7106 FOR_EACH_CHILD (die, c, print_die (c, outfile));
7109 if (print_indent == 0)
7110 fprintf (outfile, "\n");
7113 /* Print the contents of the source code line number correspondence table.
7114 This routine is a debugging aid only. */
7117 print_dwarf_line_table (FILE *outfile)
7120 dw_line_info_ref line_info;
7122 fprintf (outfile, "\n\nDWARF source line information\n");
7123 for (i = 1; i < line_info_table_in_use; i++)
7125 line_info = &line_info_table[i];
7126 fprintf (outfile, "%5d: %4ld %6ld\n", i,
7127 line_info->dw_file_num,
7128 line_info->dw_line_num);
7131 fprintf (outfile, "\n\n");
7134 /* Print the information collected for a given DIE. */
7137 debug_dwarf_die (dw_die_ref die)
7139 print_die (die, stderr);
7142 /* Print all DWARF information collected for the compilation unit.
7143 This routine is a debugging aid only. */
7149 print_die (comp_unit_die, stderr);
7150 if (! DWARF2_ASM_LINE_DEBUG_INFO)
7151 print_dwarf_line_table (stderr);
7154 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
7155 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
7156 DIE that marks the start of the DIEs for this include file. */
7159 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
7161 const char *filename = get_AT_string (bincl_die, DW_AT_name);
7162 dw_die_ref new_unit = gen_compile_unit_die (filename);
7164 new_unit->die_sib = old_unit;
7168 /* Close an include-file CU and reopen the enclosing one. */
7171 pop_compile_unit (dw_die_ref old_unit)
7173 dw_die_ref new_unit = old_unit->die_sib;
7175 old_unit->die_sib = NULL;
7179 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7180 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7182 /* Calculate the checksum of a location expression. */
7185 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7187 CHECKSUM (loc->dw_loc_opc);
7188 CHECKSUM (loc->dw_loc_oprnd1);
7189 CHECKSUM (loc->dw_loc_oprnd2);
7192 /* Calculate the checksum of an attribute. */
7195 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
7197 dw_loc_descr_ref loc;
7200 CHECKSUM (at->dw_attr);
7202 /* We don't care that this was compiled with a different compiler
7203 snapshot; if the output is the same, that's what matters. */
7204 if (at->dw_attr == DW_AT_producer)
7207 switch (AT_class (at))
7209 case dw_val_class_const:
7210 CHECKSUM (at->dw_attr_val.v.val_int);
7212 case dw_val_class_unsigned_const:
7213 CHECKSUM (at->dw_attr_val.v.val_unsigned);
7215 case dw_val_class_long_long:
7216 CHECKSUM (at->dw_attr_val.v.val_long_long);
7218 case dw_val_class_vec:
7219 CHECKSUM (at->dw_attr_val.v.val_vec);
7221 case dw_val_class_flag:
7222 CHECKSUM (at->dw_attr_val.v.val_flag);
7224 case dw_val_class_str:
7225 CHECKSUM_STRING (AT_string (at));
7228 case dw_val_class_addr:
7230 gcc_assert (GET_CODE (r) == SYMBOL_REF);
7231 CHECKSUM_STRING (XSTR (r, 0));
7234 case dw_val_class_offset:
7235 CHECKSUM (at->dw_attr_val.v.val_offset);
7238 case dw_val_class_loc:
7239 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7240 loc_checksum (loc, ctx);
7243 case dw_val_class_die_ref:
7244 die_checksum (AT_ref (at), ctx, mark);
7247 case dw_val_class_fde_ref:
7248 case dw_val_class_lbl_id:
7249 case dw_val_class_lineptr:
7250 case dw_val_class_macptr:
7253 case dw_val_class_file:
7254 CHECKSUM_STRING (AT_file (at)->filename);
7262 /* Calculate the checksum of a DIE. */
7265 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7271 /* To avoid infinite recursion. */
7274 CHECKSUM (die->die_mark);
7277 die->die_mark = ++(*mark);
7279 CHECKSUM (die->die_tag);
7281 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7282 attr_checksum (a, ctx, mark);
7284 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7288 #undef CHECKSUM_STRING
7290 /* Do the location expressions look same? */
7292 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7294 return loc1->dw_loc_opc == loc2->dw_loc_opc
7295 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7296 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7299 /* Do the values look the same? */
7301 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7303 dw_loc_descr_ref loc1, loc2;
7306 if (v1->val_class != v2->val_class)
7309 switch (v1->val_class)
7311 case dw_val_class_const:
7312 return v1->v.val_int == v2->v.val_int;
7313 case dw_val_class_unsigned_const:
7314 return v1->v.val_unsigned == v2->v.val_unsigned;
7315 case dw_val_class_long_long:
7316 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
7317 && v1->v.val_long_long.low == v2->v.val_long_long.low;
7318 case dw_val_class_vec:
7319 if (v1->v.val_vec.length != v2->v.val_vec.length
7320 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7322 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7323 v1->v.val_vec.length * v1->v.val_vec.elt_size))
7326 case dw_val_class_flag:
7327 return v1->v.val_flag == v2->v.val_flag;
7328 case dw_val_class_str:
7329 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
7331 case dw_val_class_addr:
7332 r1 = v1->v.val_addr;
7333 r2 = v2->v.val_addr;
7334 if (GET_CODE (r1) != GET_CODE (r2))
7336 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
7337 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
7339 case dw_val_class_offset:
7340 return v1->v.val_offset == v2->v.val_offset;
7342 case dw_val_class_loc:
7343 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7345 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7346 if (!same_loc_p (loc1, loc2, mark))
7348 return !loc1 && !loc2;
7350 case dw_val_class_die_ref:
7351 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7353 case dw_val_class_fde_ref:
7354 case dw_val_class_lbl_id:
7355 case dw_val_class_lineptr:
7356 case dw_val_class_macptr:
7359 case dw_val_class_file:
7360 return v1->v.val_file == v2->v.val_file;
7367 /* Do the attributes look the same? */
7370 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
7372 if (at1->dw_attr != at2->dw_attr)
7375 /* We don't care that this was compiled with a different compiler
7376 snapshot; if the output is the same, that's what matters. */
7377 if (at1->dw_attr == DW_AT_producer)
7380 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7383 /* Do the dies look the same? */
7386 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7392 /* To avoid infinite recursion. */
7394 return die1->die_mark == die2->die_mark;
7395 die1->die_mark = die2->die_mark = ++(*mark);
7397 if (die1->die_tag != die2->die_tag)
7400 if (VEC_length (dw_attr_node, die1->die_attr)
7401 != VEC_length (dw_attr_node, die2->die_attr))
7404 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
7405 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
7408 c1 = die1->die_child;
7409 c2 = die2->die_child;
7418 if (!same_die_p (c1, c2, mark))
7422 if (c1 == die1->die_child)
7424 if (c2 == die2->die_child)
7434 /* Do the dies look the same? Wrapper around same_die_p. */
7437 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
7440 int ret = same_die_p (die1, die2, &mark);
7442 unmark_all_dies (die1);
7443 unmark_all_dies (die2);
7448 /* The prefix to attach to symbols on DIEs in the current comdat debug
7450 static char *comdat_symbol_id;
7452 /* The index of the current symbol within the current comdat CU. */
7453 static unsigned int comdat_symbol_number;
7455 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
7456 children, and set comdat_symbol_id accordingly. */
7459 compute_section_prefix (dw_die_ref unit_die)
7461 const char *die_name = get_AT_string (unit_die, DW_AT_name);
7462 const char *base = die_name ? lbasename (die_name) : "anonymous";
7463 char *name = XALLOCAVEC (char, strlen (base) + 64);
7466 unsigned char checksum[16];
7469 /* Compute the checksum of the DIE, then append part of it as hex digits to
7470 the name filename of the unit. */
7472 md5_init_ctx (&ctx);
7474 die_checksum (unit_die, &ctx, &mark);
7475 unmark_all_dies (unit_die);
7476 md5_finish_ctx (&ctx, checksum);
7478 sprintf (name, "%s.", base);
7479 clean_symbol_name (name);
7481 p = name + strlen (name);
7482 for (i = 0; i < 4; i++)
7484 sprintf (p, "%.2x", checksum[i]);
7488 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
7489 comdat_symbol_number = 0;
7492 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
7495 is_type_die (dw_die_ref die)
7497 switch (die->die_tag)
7499 case DW_TAG_array_type:
7500 case DW_TAG_class_type:
7501 case DW_TAG_interface_type:
7502 case DW_TAG_enumeration_type:
7503 case DW_TAG_pointer_type:
7504 case DW_TAG_reference_type:
7505 case DW_TAG_string_type:
7506 case DW_TAG_structure_type:
7507 case DW_TAG_subroutine_type:
7508 case DW_TAG_union_type:
7509 case DW_TAG_ptr_to_member_type:
7510 case DW_TAG_set_type:
7511 case DW_TAG_subrange_type:
7512 case DW_TAG_base_type:
7513 case DW_TAG_const_type:
7514 case DW_TAG_file_type:
7515 case DW_TAG_packed_type:
7516 case DW_TAG_volatile_type:
7517 case DW_TAG_typedef:
7524 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
7525 Basically, we want to choose the bits that are likely to be shared between
7526 compilations (types) and leave out the bits that are specific to individual
7527 compilations (functions). */
7530 is_comdat_die (dw_die_ref c)
7532 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
7533 we do for stabs. The advantage is a greater likelihood of sharing between
7534 objects that don't include headers in the same order (and therefore would
7535 put the base types in a different comdat). jason 8/28/00 */
7537 if (c->die_tag == DW_TAG_base_type)
7540 if (c->die_tag == DW_TAG_pointer_type
7541 || c->die_tag == DW_TAG_reference_type
7542 || c->die_tag == DW_TAG_const_type
7543 || c->die_tag == DW_TAG_volatile_type)
7545 dw_die_ref t = get_AT_ref (c, DW_AT_type);
7547 return t ? is_comdat_die (t) : 0;
7550 return is_type_die (c);
7553 /* Returns 1 iff C is the sort of DIE that might be referred to from another
7554 compilation unit. */
7557 is_symbol_die (dw_die_ref c)
7559 return (is_type_die (c)
7560 || (get_AT (c, DW_AT_declaration)
7561 && !get_AT (c, DW_AT_specification))
7562 || c->die_tag == DW_TAG_namespace
7563 || c->die_tag == DW_TAG_module);
7567 gen_internal_sym (const char *prefix)
7571 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
7572 return xstrdup (buf);
7575 /* Assign symbols to all worthy DIEs under DIE. */
7578 assign_symbol_names (dw_die_ref die)
7582 if (is_symbol_die (die))
7584 if (comdat_symbol_id)
7586 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
7588 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
7589 comdat_symbol_id, comdat_symbol_number++);
7590 die->die_symbol = xstrdup (p);
7593 die->die_symbol = gen_internal_sym ("LDIE");
7596 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
7599 struct cu_hash_table_entry
7602 unsigned min_comdat_num, max_comdat_num;
7603 struct cu_hash_table_entry *next;
7606 /* Routines to manipulate hash table of CUs. */
7608 htab_cu_hash (const void *of)
7610 const struct cu_hash_table_entry *const entry =
7611 (const struct cu_hash_table_entry *) of;
7613 return htab_hash_string (entry->cu->die_symbol);
7617 htab_cu_eq (const void *of1, const void *of2)
7619 const struct cu_hash_table_entry *const entry1 =
7620 (const struct cu_hash_table_entry *) of1;
7621 const struct die_struct *const entry2 = (const struct die_struct *) of2;
7623 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
7627 htab_cu_del (void *what)
7629 struct cu_hash_table_entry *next,
7630 *entry = (struct cu_hash_table_entry *) what;
7640 /* Check whether we have already seen this CU and set up SYM_NUM
7643 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
7645 struct cu_hash_table_entry dummy;
7646 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
7648 dummy.max_comdat_num = 0;
7650 slot = (struct cu_hash_table_entry **)
7651 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7655 for (; entry; last = entry, entry = entry->next)
7657 if (same_die_p_wrap (cu, entry->cu))
7663 *sym_num = entry->min_comdat_num;
7667 entry = XCNEW (struct cu_hash_table_entry);
7669 entry->min_comdat_num = *sym_num = last->max_comdat_num;
7670 entry->next = *slot;
7676 /* Record SYM_NUM to record of CU in HTABLE. */
7678 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
7680 struct cu_hash_table_entry **slot, *entry;
7682 slot = (struct cu_hash_table_entry **)
7683 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
7687 entry->max_comdat_num = sym_num;
7690 /* Traverse the DIE (which is always comp_unit_die), and set up
7691 additional compilation units for each of the include files we see
7692 bracketed by BINCL/EINCL. */
7695 break_out_includes (dw_die_ref die)
7698 dw_die_ref unit = NULL;
7699 limbo_die_node *node, **pnode;
7700 htab_t cu_hash_table;
7704 dw_die_ref prev = c;
7706 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7707 || (unit && is_comdat_die (c)))
7709 dw_die_ref next = c->die_sib;
7711 /* This DIE is for a secondary CU; remove it from the main one. */
7712 remove_child_with_prev (c, prev);
7714 if (c->die_tag == DW_TAG_GNU_BINCL)
7715 unit = push_new_compile_unit (unit, c);
7716 else if (c->die_tag == DW_TAG_GNU_EINCL)
7717 unit = pop_compile_unit (unit);
7719 add_child_die (unit, c);
7721 if (c == die->die_child)
7724 } while (c != die->die_child);
7727 /* We can only use this in debugging, since the frontend doesn't check
7728 to make sure that we leave every include file we enter. */
7732 assign_symbol_names (die);
7733 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7734 for (node = limbo_die_list, pnode = &limbo_die_list;
7740 compute_section_prefix (node->die);
7741 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7742 &comdat_symbol_number);
7743 assign_symbol_names (node->die);
7745 *pnode = node->next;
7748 pnode = &node->next;
7749 record_comdat_symbol_number (node->die, cu_hash_table,
7750 comdat_symbol_number);
7753 htab_delete (cu_hash_table);
7756 /* Traverse the DIE and add a sibling attribute if it may have the
7757 effect of speeding up access to siblings. To save some space,
7758 avoid generating sibling attributes for DIE's without children. */
7761 add_sibling_attributes (dw_die_ref die)
7765 if (! die->die_child)
7768 if (die->die_parent && die != die->die_parent->die_child)
7769 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7771 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7774 /* Output all location lists for the DIE and its children. */
7777 output_location_lists (dw_die_ref die)
7783 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7784 if (AT_class (a) == dw_val_class_loc_list)
7785 output_loc_list (AT_loc_list (a));
7787 FOR_EACH_CHILD (die, c, output_location_lists (c));
7790 /* The format of each DIE (and its attribute value pairs) is encoded in an
7791 abbreviation table. This routine builds the abbreviation table and assigns
7792 a unique abbreviation id for each abbreviation entry. The children of each
7793 die are visited recursively. */
7796 build_abbrev_table (dw_die_ref die)
7798 unsigned long abbrev_id;
7799 unsigned int n_alloc;
7804 /* Scan the DIE references, and mark as external any that refer to
7805 DIEs from other CUs (i.e. those which are not marked). */
7806 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7807 if (AT_class (a) == dw_val_class_die_ref
7808 && AT_ref (a)->die_mark == 0)
7810 gcc_assert (AT_ref (a)->die_symbol);
7812 set_AT_ref_external (a, 1);
7815 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7817 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7818 dw_attr_ref die_a, abbrev_a;
7822 if (abbrev->die_tag != die->die_tag)
7824 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7827 if (VEC_length (dw_attr_node, abbrev->die_attr)
7828 != VEC_length (dw_attr_node, die->die_attr))
7831 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7833 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7834 if ((abbrev_a->dw_attr != die_a->dw_attr)
7835 || (value_format (abbrev_a) != value_format (die_a)))
7845 if (abbrev_id >= abbrev_die_table_in_use)
7847 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7849 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7850 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7853 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7854 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7855 abbrev_die_table_allocated = n_alloc;
7858 ++abbrev_die_table_in_use;
7859 abbrev_die_table[abbrev_id] = die;
7862 die->die_abbrev = abbrev_id;
7863 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7866 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7869 constant_size (unsigned HOST_WIDE_INT value)
7876 log = floor_log2 (value);
7879 log = 1 << (floor_log2 (log) + 1);
7884 /* Return the size of a DIE as it is represented in the
7885 .debug_info section. */
7887 static unsigned long
7888 size_of_die (dw_die_ref die)
7890 unsigned long size = 0;
7894 size += size_of_uleb128 (die->die_abbrev);
7895 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7897 switch (AT_class (a))
7899 case dw_val_class_addr:
7900 size += DWARF2_ADDR_SIZE;
7902 case dw_val_class_offset:
7903 size += DWARF_OFFSET_SIZE;
7905 case dw_val_class_loc:
7907 unsigned long lsize = size_of_locs (AT_loc (a));
7910 size += constant_size (lsize);
7914 case dw_val_class_loc_list:
7915 size += DWARF_OFFSET_SIZE;
7917 case dw_val_class_range_list:
7918 size += DWARF_OFFSET_SIZE;
7920 case dw_val_class_const:
7921 size += size_of_sleb128 (AT_int (a));
7923 case dw_val_class_unsigned_const:
7924 size += constant_size (AT_unsigned (a));
7926 case dw_val_class_long_long:
7927 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7929 case dw_val_class_vec:
7930 size += constant_size (a->dw_attr_val.v.val_vec.length
7931 * a->dw_attr_val.v.val_vec.elt_size)
7932 + a->dw_attr_val.v.val_vec.length
7933 * a->dw_attr_val.v.val_vec.elt_size; /* block */
7935 case dw_val_class_flag:
7938 case dw_val_class_die_ref:
7939 if (AT_ref_external (a))
7940 size += DWARF2_ADDR_SIZE;
7942 size += DWARF_OFFSET_SIZE;
7944 case dw_val_class_fde_ref:
7945 size += DWARF_OFFSET_SIZE;
7947 case dw_val_class_lbl_id:
7948 size += DWARF2_ADDR_SIZE;
7950 case dw_val_class_lineptr:
7951 case dw_val_class_macptr:
7952 size += DWARF_OFFSET_SIZE;
7954 case dw_val_class_str:
7955 if (AT_string_form (a) == DW_FORM_strp)
7956 size += DWARF_OFFSET_SIZE;
7958 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7960 case dw_val_class_file:
7961 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7971 /* Size the debugging information associated with a given DIE. Visits the
7972 DIE's children recursively. Updates the global variable next_die_offset, on
7973 each time through. Uses the current value of next_die_offset to update the
7974 die_offset field in each DIE. */
7977 calc_die_sizes (dw_die_ref die)
7981 die->die_offset = next_die_offset;
7982 next_die_offset += size_of_die (die);
7984 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7986 if (die->die_child != NULL)
7987 /* Count the null byte used to terminate sibling lists. */
7988 next_die_offset += 1;
7991 /* Set the marks for a die and its children. We do this so
7992 that we know whether or not a reference needs to use FORM_ref_addr; only
7993 DIEs in the same CU will be marked. We used to clear out the offset
7994 and use that as the flag, but ran into ordering problems. */
7997 mark_dies (dw_die_ref die)
8001 gcc_assert (!die->die_mark);
8004 FOR_EACH_CHILD (die, c, mark_dies (c));
8007 /* Clear the marks for a die and its children. */
8010 unmark_dies (dw_die_ref die)
8014 gcc_assert (die->die_mark);
8017 FOR_EACH_CHILD (die, c, unmark_dies (c));
8020 /* Clear the marks for a die, its children and referred dies. */
8023 unmark_all_dies (dw_die_ref die)
8033 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
8035 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8036 if (AT_class (a) == dw_val_class_die_ref)
8037 unmark_all_dies (AT_ref (a));
8040 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8041 generated for the compilation unit. */
8043 static unsigned long
8044 size_of_pubnames (VEC (pubname_entry, gc) * names)
8050 size = DWARF_PUBNAMES_HEADER_SIZE;
8051 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
8052 if (names != pubtype_table
8053 || p->die->die_offset != 0
8054 || !flag_eliminate_unused_debug_types)
8055 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
8057 size += DWARF_OFFSET_SIZE;
8061 /* Return the size of the information in the .debug_aranges section. */
8063 static unsigned long
8064 size_of_aranges (void)
8068 size = DWARF_ARANGES_HEADER_SIZE;
8070 /* Count the address/length pair for this compilation unit. */
8071 if (text_section_used)
8072 size += 2 * DWARF2_ADDR_SIZE;
8073 if (cold_text_section_used)
8074 size += 2 * DWARF2_ADDR_SIZE;
8075 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
8077 /* Count the two zero words used to terminated the address range table. */
8078 size += 2 * DWARF2_ADDR_SIZE;
8082 /* Select the encoding of an attribute value. */
8084 static enum dwarf_form
8085 value_format (dw_attr_ref a)
8087 switch (a->dw_attr_val.val_class)
8089 case dw_val_class_addr:
8090 return DW_FORM_addr;
8091 case dw_val_class_range_list:
8092 case dw_val_class_offset:
8093 case dw_val_class_loc_list:
8094 switch (DWARF_OFFSET_SIZE)
8097 return DW_FORM_data4;
8099 return DW_FORM_data8;
8103 case dw_val_class_loc:
8104 switch (constant_size (size_of_locs (AT_loc (a))))
8107 return DW_FORM_block1;
8109 return DW_FORM_block2;
8113 case dw_val_class_const:
8114 return DW_FORM_sdata;
8115 case dw_val_class_unsigned_const:
8116 switch (constant_size (AT_unsigned (a)))
8119 return DW_FORM_data1;
8121 return DW_FORM_data2;
8123 return DW_FORM_data4;
8125 return DW_FORM_data8;
8129 case dw_val_class_long_long:
8130 return DW_FORM_block1;
8131 case dw_val_class_vec:
8132 switch (constant_size (a->dw_attr_val.v.val_vec.length
8133 * a->dw_attr_val.v.val_vec.elt_size))
8136 return DW_FORM_block1;
8138 return DW_FORM_block2;
8140 return DW_FORM_block4;
8144 case dw_val_class_flag:
8145 return DW_FORM_flag;
8146 case dw_val_class_die_ref:
8147 if (AT_ref_external (a))
8148 return DW_FORM_ref_addr;
8151 case dw_val_class_fde_ref:
8152 return DW_FORM_data;
8153 case dw_val_class_lbl_id:
8154 return DW_FORM_addr;
8155 case dw_val_class_lineptr:
8156 case dw_val_class_macptr:
8157 return DW_FORM_data;
8158 case dw_val_class_str:
8159 return AT_string_form (a);
8160 case dw_val_class_file:
8161 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
8164 return DW_FORM_data1;
8166 return DW_FORM_data2;
8168 return DW_FORM_data4;
8178 /* Output the encoding of an attribute value. */
8181 output_value_format (dw_attr_ref a)
8183 enum dwarf_form form = value_format (a);
8185 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
8188 /* Output the .debug_abbrev section which defines the DIE abbreviation
8192 output_abbrev_section (void)
8194 unsigned long abbrev_id;
8196 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
8198 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
8202 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
8203 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
8204 dwarf_tag_name (abbrev->die_tag));
8206 if (abbrev->die_child != NULL)
8207 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
8209 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
8211 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
8214 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
8215 dwarf_attr_name (a_attr->dw_attr));
8216 output_value_format (a_attr);
8219 dw2_asm_output_data (1, 0, NULL);
8220 dw2_asm_output_data (1, 0, NULL);
8223 /* Terminate the table. */
8224 dw2_asm_output_data (1, 0, NULL);
8227 /* Output a symbol we can use to refer to this DIE from another CU. */
8230 output_die_symbol (dw_die_ref die)
8232 char *sym = die->die_symbol;
8237 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
8238 /* We make these global, not weak; if the target doesn't support
8239 .linkonce, it doesn't support combining the sections, so debugging
8241 targetm.asm_out.globalize_label (asm_out_file, sym);
8243 ASM_OUTPUT_LABEL (asm_out_file, sym);
8246 /* Return a new location list, given the begin and end range, and the
8247 expression. gensym tells us whether to generate a new internal symbol for
8248 this location list node, which is done for the head of the list only. */
8250 static inline dw_loc_list_ref
8251 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
8252 const char *section, unsigned int gensym)
8254 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
8256 retlist->begin = begin;
8258 retlist->expr = expr;
8259 retlist->section = section;
8261 retlist->ll_symbol = gen_internal_sym ("LLST");
8266 /* Add a location description expression to a location list. */
8269 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
8270 const char *begin, const char *end,
8271 const char *section)
8275 /* Find the end of the chain. */
8276 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
8279 /* Add a new location list node to the list. */
8280 *d = new_loc_list (descr, begin, end, section, 0);
8283 /* Output the location list given to us. */
8286 output_loc_list (dw_loc_list_ref list_head)
8288 dw_loc_list_ref curr = list_head;
8290 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
8292 /* Walk the location list, and output each range + expression. */
8293 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
8296 /* Don't output an entry that starts and ends at the same address. */
8297 if (strcmp (curr->begin, curr->end) == 0)
8299 if (!have_multiple_function_sections)
8301 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
8302 "Location list begin address (%s)",
8303 list_head->ll_symbol);
8304 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
8305 "Location list end address (%s)",
8306 list_head->ll_symbol);
8310 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
8311 "Location list begin address (%s)",
8312 list_head->ll_symbol);
8313 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
8314 "Location list end address (%s)",
8315 list_head->ll_symbol);
8317 size = size_of_locs (curr->expr);
8319 /* Output the block length for this list of location operations. */
8320 gcc_assert (size <= 0xffff);
8321 dw2_asm_output_data (2, size, "%s", "Location expression size");
8323 output_loc_sequence (curr->expr);
8326 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8327 "Location list terminator begin (%s)",
8328 list_head->ll_symbol);
8329 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
8330 "Location list terminator end (%s)",
8331 list_head->ll_symbol);
8334 /* Output the DIE and its attributes. Called recursively to generate
8335 the definitions of each child DIE. */
8338 output_die (dw_die_ref die)
8345 /* If someone in another CU might refer to us, set up a symbol for
8346 them to point to. */
8347 if (die->die_symbol)
8348 output_die_symbol (die);
8350 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
8351 (unsigned long)die->die_offset,
8352 dwarf_tag_name (die->die_tag));
8354 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
8356 const char *name = dwarf_attr_name (a->dw_attr);
8358 switch (AT_class (a))
8360 case dw_val_class_addr:
8361 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
8364 case dw_val_class_offset:
8365 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
8369 case dw_val_class_range_list:
8371 char *p = strchr (ranges_section_label, '\0');
8373 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
8374 a->dw_attr_val.v.val_offset);
8375 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
8376 debug_ranges_section, "%s", name);
8381 case dw_val_class_loc:
8382 size = size_of_locs (AT_loc (a));
8384 /* Output the block length for this list of location operations. */
8385 dw2_asm_output_data (constant_size (size), size, "%s", name);
8387 output_loc_sequence (AT_loc (a));
8390 case dw_val_class_const:
8391 /* ??? It would be slightly more efficient to use a scheme like is
8392 used for unsigned constants below, but gdb 4.x does not sign
8393 extend. Gdb 5.x does sign extend. */
8394 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
8397 case dw_val_class_unsigned_const:
8398 dw2_asm_output_data (constant_size (AT_unsigned (a)),
8399 AT_unsigned (a), "%s", name);
8402 case dw_val_class_long_long:
8404 unsigned HOST_WIDE_INT first, second;
8406 dw2_asm_output_data (1,
8407 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8410 if (WORDS_BIG_ENDIAN)
8412 first = a->dw_attr_val.v.val_long_long.hi;
8413 second = a->dw_attr_val.v.val_long_long.low;
8417 first = a->dw_attr_val.v.val_long_long.low;
8418 second = a->dw_attr_val.v.val_long_long.hi;
8421 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8422 first, "long long constant");
8423 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
8428 case dw_val_class_vec:
8430 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
8431 unsigned int len = a->dw_attr_val.v.val_vec.length;
8435 dw2_asm_output_data (constant_size (len * elt_size),
8436 len * elt_size, "%s", name);
8437 if (elt_size > sizeof (HOST_WIDE_INT))
8442 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
8445 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
8446 "fp or vector constant word %u", i);
8450 case dw_val_class_flag:
8451 dw2_asm_output_data (1, AT_flag (a), "%s", name);
8454 case dw_val_class_loc_list:
8456 char *sym = AT_loc_list (a)->ll_symbol;
8459 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
8464 case dw_val_class_die_ref:
8465 if (AT_ref_external (a))
8467 char *sym = AT_ref (a)->die_symbol;
8470 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
8475 gcc_assert (AT_ref (a)->die_offset);
8476 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
8481 case dw_val_class_fde_ref:
8485 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
8486 a->dw_attr_val.v.val_fde_index * 2);
8487 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
8492 case dw_val_class_lbl_id:
8493 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
8496 case dw_val_class_lineptr:
8497 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8498 debug_line_section, "%s", name);
8501 case dw_val_class_macptr:
8502 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
8503 debug_macinfo_section, "%s", name);
8506 case dw_val_class_str:
8507 if (AT_string_form (a) == DW_FORM_strp)
8508 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
8509 a->dw_attr_val.v.val_str->label,
8511 "%s: \"%s\"", name, AT_string (a));
8513 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
8516 case dw_val_class_file:
8518 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
8520 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
8521 a->dw_attr_val.v.val_file->filename);
8530 FOR_EACH_CHILD (die, c, output_die (c));
8532 /* Add null byte to terminate sibling list. */
8533 if (die->die_child != NULL)
8534 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
8535 (unsigned long) die->die_offset);
8538 /* Output the compilation unit that appears at the beginning of the
8539 .debug_info section, and precedes the DIE descriptions. */
8542 output_compilation_unit_header (void)
8544 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8545 dw2_asm_output_data (4, 0xffffffff,
8546 "Initial length escape value indicating 64-bit DWARF extension");
8547 dw2_asm_output_data (DWARF_OFFSET_SIZE,
8548 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
8549 "Length of Compilation Unit Info");
8550 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
8551 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
8552 debug_abbrev_section,
8553 "Offset Into Abbrev. Section");
8554 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
8557 /* Output the compilation unit DIE and its children. */
8560 output_comp_unit (dw_die_ref die, int output_if_empty)
8562 const char *secname;
8565 /* Unless we are outputting main CU, we may throw away empty ones. */
8566 if (!output_if_empty && die->die_child == NULL)
8569 /* Even if there are no children of this DIE, we must output the information
8570 about the compilation unit. Otherwise, on an empty translation unit, we
8571 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8572 will then complain when examining the file. First mark all the DIEs in
8573 this CU so we know which get local refs. */
8576 build_abbrev_table (die);
8578 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8579 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8580 calc_die_sizes (die);
8582 oldsym = die->die_symbol;
8585 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
8587 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
8589 die->die_symbol = NULL;
8590 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
8593 switch_to_section (debug_info_section);
8595 /* Output debugging information. */
8596 output_compilation_unit_header ();
8599 /* Leave the marks on the main CU, so we can check them in
8604 die->die_symbol = oldsym;
8608 /* Return the DWARF2/3 pubname associated with a decl. */
8611 dwarf2_name (tree decl, int scope)
8613 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
8616 /* Add a new entry to .debug_pubnames if appropriate. */
8619 add_pubname_string (const char *str, dw_die_ref die)
8624 e.name = xstrdup (str);
8625 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
8629 add_pubname (tree decl, dw_die_ref die)
8632 if (TREE_PUBLIC (decl))
8633 add_pubname_string (dwarf2_name (decl, 1), die);
8636 /* Add a new entry to .debug_pubtypes if appropriate. */
8639 add_pubtype (tree decl, dw_die_ref die)
8644 if ((TREE_PUBLIC (decl)
8645 || die->die_parent == comp_unit_die)
8646 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
8651 if (TYPE_NAME (decl))
8653 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
8654 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
8655 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
8656 && DECL_NAME (TYPE_NAME (decl)))
8657 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
8659 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
8663 e.name = xstrdup (dwarf2_name (decl, 1));
8665 /* If we don't have a name for the type, there's no point in adding
8667 if (e.name && e.name[0] != '\0')
8668 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
8672 /* Output the public names table used to speed up access to externally
8673 visible names; or the public types table used to find type definitions. */
8676 output_pubnames (VEC (pubname_entry, gc) * names)
8679 unsigned long pubnames_length = size_of_pubnames (names);
8682 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8683 dw2_asm_output_data (4, 0xffffffff,
8684 "Initial length escape value indicating 64-bit DWARF extension");
8685 if (names == pubname_table)
8686 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8687 "Length of Public Names Info");
8689 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
8690 "Length of Public Type Names Info");
8691 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8692 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8694 "Offset of Compilation Unit Info");
8695 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
8696 "Compilation Unit Length");
8698 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
8700 /* We shouldn't see pubnames for DIEs outside of the main CU. */
8701 if (names == pubname_table)
8702 gcc_assert (pub->die->die_mark);
8704 if (names != pubtype_table
8705 || pub->die->die_offset != 0
8706 || !flag_eliminate_unused_debug_types)
8708 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8711 dw2_asm_output_nstring (pub->name, -1, "external name");
8715 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8718 /* Add a new entry to .debug_aranges if appropriate. */
8721 add_arange (tree decl, dw_die_ref die)
8723 if (! DECL_SECTION_NAME (decl))
8726 if (arange_table_in_use == arange_table_allocated)
8728 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8729 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8730 arange_table_allocated);
8731 memset (arange_table + arange_table_in_use, 0,
8732 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8735 arange_table[arange_table_in_use++] = die;
8738 /* Output the information that goes into the .debug_aranges table.
8739 Namely, define the beginning and ending address range of the
8740 text section generated for this compilation unit. */
8743 output_aranges (void)
8746 unsigned long aranges_length = size_of_aranges ();
8748 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8749 dw2_asm_output_data (4, 0xffffffff,
8750 "Initial length escape value indicating 64-bit DWARF extension");
8751 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8752 "Length of Address Ranges Info");
8753 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8754 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8756 "Offset of Compilation Unit Info");
8757 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8758 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8760 /* We need to align to twice the pointer size here. */
8761 if (DWARF_ARANGES_PAD_SIZE)
8763 /* Pad using a 2 byte words so that padding is correct for any
8765 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8766 2 * DWARF2_ADDR_SIZE);
8767 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8768 dw2_asm_output_data (2, 0, NULL);
8771 /* It is necessary not to output these entries if the sections were
8772 not used; if the sections were not used, the length will be 0 and
8773 the address may end up as 0 if the section is discarded by ld
8774 --gc-sections, leaving an invalid (0, 0) entry that can be
8775 confused with the terminator. */
8776 if (text_section_used)
8778 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8779 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8780 text_section_label, "Length");
8782 if (cold_text_section_used)
8784 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8786 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8787 cold_text_section_label, "Length");
8790 for (i = 0; i < arange_table_in_use; i++)
8792 dw_die_ref die = arange_table[i];
8794 /* We shouldn't see aranges for DIEs outside of the main CU. */
8795 gcc_assert (die->die_mark);
8797 if (die->die_tag == DW_TAG_subprogram)
8799 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8801 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8802 get_AT_low_pc (die), "Length");
8806 /* A static variable; extract the symbol from DW_AT_location.
8807 Note that this code isn't currently hit, as we only emit
8808 aranges for functions (jason 9/23/99). */
8809 dw_attr_ref a = get_AT (die, DW_AT_location);
8810 dw_loc_descr_ref loc;
8812 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8815 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8817 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8818 loc->dw_loc_oprnd1.v.val_addr, "Address");
8819 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8820 get_AT_unsigned (die, DW_AT_byte_size),
8825 /* Output the terminator words. */
8826 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8827 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8830 /* Add a new entry to .debug_ranges. Return the offset at which it
8834 add_ranges_num (int num)
8836 unsigned int in_use = ranges_table_in_use;
8838 if (in_use == ranges_table_allocated)
8840 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8841 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8842 ranges_table_allocated);
8843 memset (ranges_table + ranges_table_in_use, 0,
8844 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8847 ranges_table[in_use].num = num;
8848 ranges_table_in_use = in_use + 1;
8850 return in_use * 2 * DWARF2_ADDR_SIZE;
8853 /* Add a new entry to .debug_ranges corresponding to a block, or a
8854 range terminator if BLOCK is NULL. */
8857 add_ranges (const_tree block)
8859 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8862 /* Add a new entry to .debug_ranges corresponding to a pair of
8866 add_ranges_by_labels (const char *begin, const char *end)
8868 unsigned int in_use = ranges_by_label_in_use;
8870 if (in_use == ranges_by_label_allocated)
8872 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8873 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8875 ranges_by_label_allocated);
8876 memset (ranges_by_label + ranges_by_label_in_use, 0,
8877 RANGES_TABLE_INCREMENT
8878 * sizeof (struct dw_ranges_by_label_struct));
8881 ranges_by_label[in_use].begin = begin;
8882 ranges_by_label[in_use].end = end;
8883 ranges_by_label_in_use = in_use + 1;
8885 return add_ranges_num (-(int)in_use - 1);
8889 output_ranges (void)
8892 static const char *const start_fmt = "Offset 0x%x";
8893 const char *fmt = start_fmt;
8895 for (i = 0; i < ranges_table_in_use; i++)
8897 int block_num = ranges_table[i].num;
8901 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8902 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8904 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8905 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8907 /* If all code is in the text section, then the compilation
8908 unit base address defaults to DW_AT_low_pc, which is the
8909 base of the text section. */
8910 if (!have_multiple_function_sections)
8912 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8914 fmt, i * 2 * DWARF2_ADDR_SIZE);
8915 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8916 text_section_label, NULL);
8919 /* Otherwise, the compilation unit base address is zero,
8920 which allows us to use absolute addresses, and not worry
8921 about whether the target supports cross-section
8925 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8926 fmt, i * 2 * DWARF2_ADDR_SIZE);
8927 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8933 /* Negative block_num stands for an index into ranges_by_label. */
8934 else if (block_num < 0)
8936 int lab_idx = - block_num - 1;
8938 if (!have_multiple_function_sections)
8942 /* If we ever use add_ranges_by_labels () for a single
8943 function section, all we have to do is to take out
8945 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8946 ranges_by_label[lab_idx].begin,
8948 fmt, i * 2 * DWARF2_ADDR_SIZE);
8949 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8950 ranges_by_label[lab_idx].end,
8951 text_section_label, NULL);
8956 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8957 ranges_by_label[lab_idx].begin,
8958 fmt, i * 2 * DWARF2_ADDR_SIZE);
8959 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8960 ranges_by_label[lab_idx].end,
8966 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8967 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8973 /* Data structure containing information about input files. */
8976 const char *path; /* Complete file name. */
8977 const char *fname; /* File name part. */
8978 int length; /* Length of entire string. */
8979 struct dwarf_file_data * file_idx; /* Index in input file table. */
8980 int dir_idx; /* Index in directory table. */
8983 /* Data structure containing information about directories with source
8987 const char *path; /* Path including directory name. */
8988 int length; /* Path length. */
8989 int prefix; /* Index of directory entry which is a prefix. */
8990 int count; /* Number of files in this directory. */
8991 int dir_idx; /* Index of directory used as base. */
8994 /* Callback function for file_info comparison. We sort by looking at
8995 the directories in the path. */
8998 file_info_cmp (const void *p1, const void *p2)
9000 const struct file_info *const s1 = (const struct file_info *) p1;
9001 const struct file_info *const s2 = (const struct file_info *) p2;
9002 const unsigned char *cp1;
9003 const unsigned char *cp2;
9005 /* Take care of file names without directories. We need to make sure that
9006 we return consistent values to qsort since some will get confused if
9007 we return the same value when identical operands are passed in opposite
9008 orders. So if neither has a directory, return 0 and otherwise return
9009 1 or -1 depending on which one has the directory. */
9010 if ((s1->path == s1->fname || s2->path == s2->fname))
9011 return (s2->path == s2->fname) - (s1->path == s1->fname);
9013 cp1 = (const unsigned char *) s1->path;
9014 cp2 = (const unsigned char *) s2->path;
9020 /* Reached the end of the first path? If so, handle like above. */
9021 if ((cp1 == (const unsigned char *) s1->fname)
9022 || (cp2 == (const unsigned char *) s2->fname))
9023 return ((cp2 == (const unsigned char *) s2->fname)
9024 - (cp1 == (const unsigned char *) s1->fname));
9026 /* Character of current path component the same? */
9027 else if (*cp1 != *cp2)
9032 struct file_name_acquire_data
9034 struct file_info *files;
9039 /* Traversal function for the hash table. */
9042 file_name_acquire (void ** slot, void *data)
9044 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
9045 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
9046 struct file_info *fi;
9049 gcc_assert (fnad->max_files >= d->emitted_number);
9051 if (! d->emitted_number)
9054 gcc_assert (fnad->max_files != fnad->used_files);
9056 fi = fnad->files + fnad->used_files++;
9058 /* Skip all leading "./". */
9060 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
9063 /* Create a new array entry. */
9065 fi->length = strlen (f);
9068 /* Search for the file name part. */
9069 f = strrchr (f, DIR_SEPARATOR);
9070 #if defined (DIR_SEPARATOR_2)
9072 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
9076 if (f == NULL || f < g)
9082 fi->fname = f == NULL ? fi->path : f + 1;
9086 /* Output the directory table and the file name table. We try to minimize
9087 the total amount of memory needed. A heuristic is used to avoid large
9088 slowdowns with many input files. */
9091 output_file_names (void)
9093 struct file_name_acquire_data fnad;
9095 struct file_info *files;
9096 struct dir_info *dirs;
9105 if (!last_emitted_file)
9107 dw2_asm_output_data (1, 0, "End directory table");
9108 dw2_asm_output_data (1, 0, "End file name table");
9112 numfiles = last_emitted_file->emitted_number;
9114 /* Allocate the various arrays we need. */
9115 files = XALLOCAVEC (struct file_info, numfiles);
9116 dirs = XALLOCAVEC (struct dir_info, numfiles);
9119 fnad.used_files = 0;
9120 fnad.max_files = numfiles;
9121 htab_traverse (file_table, file_name_acquire, &fnad);
9122 gcc_assert (fnad.used_files == fnad.max_files);
9124 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
9126 /* Find all the different directories used. */
9127 dirs[0].path = files[0].path;
9128 dirs[0].length = files[0].fname - files[0].path;
9129 dirs[0].prefix = -1;
9131 dirs[0].dir_idx = 0;
9132 files[0].dir_idx = 0;
9135 for (i = 1; i < numfiles; i++)
9136 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
9137 && memcmp (dirs[ndirs - 1].path, files[i].path,
9138 dirs[ndirs - 1].length) == 0)
9140 /* Same directory as last entry. */
9141 files[i].dir_idx = ndirs - 1;
9142 ++dirs[ndirs - 1].count;
9148 /* This is a new directory. */
9149 dirs[ndirs].path = files[i].path;
9150 dirs[ndirs].length = files[i].fname - files[i].path;
9151 dirs[ndirs].count = 1;
9152 dirs[ndirs].dir_idx = ndirs;
9153 files[i].dir_idx = ndirs;
9155 /* Search for a prefix. */
9156 dirs[ndirs].prefix = -1;
9157 for (j = 0; j < ndirs; j++)
9158 if (dirs[j].length < dirs[ndirs].length
9159 && dirs[j].length > 1
9160 && (dirs[ndirs].prefix == -1
9161 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
9162 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
9163 dirs[ndirs].prefix = j;
9168 /* Now to the actual work. We have to find a subset of the directories which
9169 allow expressing the file name using references to the directory table
9170 with the least amount of characters. We do not do an exhaustive search
9171 where we would have to check out every combination of every single
9172 possible prefix. Instead we use a heuristic which provides nearly optimal
9173 results in most cases and never is much off. */
9174 saved = XALLOCAVEC (int, ndirs);
9175 savehere = XALLOCAVEC (int, ndirs);
9177 memset (saved, '\0', ndirs * sizeof (saved[0]));
9178 for (i = 0; i < ndirs; i++)
9183 /* We can always save some space for the current directory. But this
9184 does not mean it will be enough to justify adding the directory. */
9185 savehere[i] = dirs[i].length;
9186 total = (savehere[i] - saved[i]) * dirs[i].count;
9188 for (j = i + 1; j < ndirs; j++)
9191 if (saved[j] < dirs[i].length)
9193 /* Determine whether the dirs[i] path is a prefix of the
9198 while (k != -1 && k != (int) i)
9203 /* Yes it is. We can possibly save some memory by
9204 writing the filenames in dirs[j] relative to
9206 savehere[j] = dirs[i].length;
9207 total += (savehere[j] - saved[j]) * dirs[j].count;
9212 /* Check whether we can save enough to justify adding the dirs[i]
9214 if (total > dirs[i].length + 1)
9216 /* It's worthwhile adding. */
9217 for (j = i; j < ndirs; j++)
9218 if (savehere[j] > 0)
9220 /* Remember how much we saved for this directory so far. */
9221 saved[j] = savehere[j];
9223 /* Remember the prefix directory. */
9224 dirs[j].dir_idx = i;
9229 /* Emit the directory name table. */
9231 idx_offset = dirs[0].length > 0 ? 1 : 0;
9232 for (i = 1 - idx_offset; i < ndirs; i++)
9233 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
9234 "Directory Entry: 0x%x", i + idx_offset);
9236 dw2_asm_output_data (1, 0, "End directory table");
9238 /* We have to emit them in the order of emitted_number since that's
9239 used in the debug info generation. To do this efficiently we
9240 generate a back-mapping of the indices first. */
9241 backmap = XALLOCAVEC (int, numfiles);
9242 for (i = 0; i < numfiles; i++)
9243 backmap[files[i].file_idx->emitted_number - 1] = i;
9245 /* Now write all the file names. */
9246 for (i = 0; i < numfiles; i++)
9248 int file_idx = backmap[i];
9249 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
9251 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
9252 "File Entry: 0x%x", (unsigned) i + 1);
9254 /* Include directory index. */
9255 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
9257 /* Modification time. */
9258 dw2_asm_output_data_uleb128 (0, NULL);
9260 /* File length in bytes. */
9261 dw2_asm_output_data_uleb128 (0, NULL);
9264 dw2_asm_output_data (1, 0, "End file name table");
9268 /* Output the source line number correspondence information. This
9269 information goes into the .debug_line section. */
9272 output_line_info (void)
9274 char l1[20], l2[20], p1[20], p2[20];
9275 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9276 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
9279 unsigned long lt_index;
9280 unsigned long current_line;
9283 unsigned long current_file;
9284 unsigned long function;
9286 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
9287 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
9288 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
9289 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
9291 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
9292 dw2_asm_output_data (4, 0xffffffff,
9293 "Initial length escape value indicating 64-bit DWARF extension");
9294 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
9295 "Length of Source Line Info");
9296 ASM_OUTPUT_LABEL (asm_out_file, l1);
9298 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
9299 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
9300 ASM_OUTPUT_LABEL (asm_out_file, p1);
9302 /* Define the architecture-dependent minimum instruction length (in
9303 bytes). In this implementation of DWARF, this field is used for
9304 information purposes only. Since GCC generates assembly language,
9305 we have no a priori knowledge of how many instruction bytes are
9306 generated for each source line, and therefore can use only the
9307 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
9308 commands. Accordingly, we fix this as `1', which is "correct
9309 enough" for all architectures, and don't let the target override. */
9310 dw2_asm_output_data (1, 1,
9311 "Minimum Instruction Length");
9313 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
9314 "Default is_stmt_start flag");
9315 dw2_asm_output_data (1, DWARF_LINE_BASE,
9316 "Line Base Value (Special Opcodes)");
9317 dw2_asm_output_data (1, DWARF_LINE_RANGE,
9318 "Line Range Value (Special Opcodes)");
9319 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
9320 "Special Opcode Base");
9322 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
9326 case DW_LNS_advance_pc:
9327 case DW_LNS_advance_line:
9328 case DW_LNS_set_file:
9329 case DW_LNS_set_column:
9330 case DW_LNS_fixed_advance_pc:
9338 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
9342 /* Write out the information about the files we use. */
9343 output_file_names ();
9344 ASM_OUTPUT_LABEL (asm_out_file, p2);
9346 /* We used to set the address register to the first location in the text
9347 section here, but that didn't accomplish anything since we already
9348 have a line note for the opening brace of the first function. */
9350 /* Generate the line number to PC correspondence table, encoded as
9351 a series of state machine operations. */
9355 if (cfun && in_cold_section_p)
9356 strcpy (prev_line_label, crtl->subsections.cold_section_label);
9358 strcpy (prev_line_label, text_section_label);
9359 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
9361 dw_line_info_ref line_info = &line_info_table[lt_index];
9364 /* Disable this optimization for now; GDB wants to see two line notes
9365 at the beginning of a function so it can find the end of the
9368 /* Don't emit anything for redundant notes. Just updating the
9369 address doesn't accomplish anything, because we already assume
9370 that anything after the last address is this line. */
9371 if (line_info->dw_line_num == current_line
9372 && line_info->dw_file_num == current_file)
9376 /* Emit debug info for the address of the current line.
9378 Unfortunately, we have little choice here currently, and must always
9379 use the most general form. GCC does not know the address delta
9380 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
9381 attributes which will give an upper bound on the address range. We
9382 could perhaps use length attributes to determine when it is safe to
9383 use DW_LNS_fixed_advance_pc. */
9385 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
9388 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
9389 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9390 "DW_LNS_fixed_advance_pc");
9391 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9395 /* This can handle any delta. This takes
9396 4+DWARF2_ADDR_SIZE bytes. */
9397 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9398 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9399 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9400 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9403 strcpy (prev_line_label, line_label);
9405 /* Emit debug info for the source file of the current line, if
9406 different from the previous line. */
9407 if (line_info->dw_file_num != current_file)
9409 current_file = line_info->dw_file_num;
9410 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9411 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9414 /* Emit debug info for the current line number, choosing the encoding
9415 that uses the least amount of space. */
9416 if (line_info->dw_line_num != current_line)
9418 line_offset = line_info->dw_line_num - current_line;
9419 line_delta = line_offset - DWARF_LINE_BASE;
9420 current_line = line_info->dw_line_num;
9421 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9422 /* This can handle deltas from -10 to 234, using the current
9423 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
9425 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9426 "line %lu", current_line);
9429 /* This can handle any delta. This takes at least 4 bytes,
9430 depending on the value being encoded. */
9431 dw2_asm_output_data (1, DW_LNS_advance_line,
9432 "advance to line %lu", current_line);
9433 dw2_asm_output_data_sleb128 (line_offset, NULL);
9434 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9438 /* We still need to start a new row, so output a copy insn. */
9439 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9442 /* Emit debug info for the address of the end of the function. */
9445 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9446 "DW_LNS_fixed_advance_pc");
9447 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
9451 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9452 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9453 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9454 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
9457 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9458 dw2_asm_output_data_uleb128 (1, NULL);
9459 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9464 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
9466 dw_separate_line_info_ref line_info
9467 = &separate_line_info_table[lt_index];
9470 /* Don't emit anything for redundant notes. */
9471 if (line_info->dw_line_num == current_line
9472 && line_info->dw_file_num == current_file
9473 && line_info->function == function)
9477 /* Emit debug info for the address of the current line. If this is
9478 a new function, or the first line of a function, then we need
9479 to handle it differently. */
9480 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
9482 if (function != line_info->function)
9484 function = line_info->function;
9486 /* Set the address register to the first line in the function. */
9487 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9488 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9489 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9490 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9494 /* ??? See the DW_LNS_advance_pc comment above. */
9497 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9498 "DW_LNS_fixed_advance_pc");
9499 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9503 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9504 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9505 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9506 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9510 strcpy (prev_line_label, line_label);
9512 /* Emit debug info for the source file of the current line, if
9513 different from the previous line. */
9514 if (line_info->dw_file_num != current_file)
9516 current_file = line_info->dw_file_num;
9517 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
9518 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
9521 /* Emit debug info for the current line number, choosing the encoding
9522 that uses the least amount of space. */
9523 if (line_info->dw_line_num != current_line)
9525 line_offset = line_info->dw_line_num - current_line;
9526 line_delta = line_offset - DWARF_LINE_BASE;
9527 current_line = line_info->dw_line_num;
9528 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
9529 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
9530 "line %lu", current_line);
9533 dw2_asm_output_data (1, DW_LNS_advance_line,
9534 "advance to line %lu", current_line);
9535 dw2_asm_output_data_sleb128 (line_offset, NULL);
9536 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9540 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
9548 /* If we're done with a function, end its sequence. */
9549 if (lt_index == separate_line_info_table_in_use
9550 || separate_line_info_table[lt_index].function != function)
9555 /* Emit debug info for the address of the end of the function. */
9556 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
9559 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
9560 "DW_LNS_fixed_advance_pc");
9561 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
9565 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
9566 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
9567 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
9568 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
9571 /* Output the marker for the end of this sequence. */
9572 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
9573 dw2_asm_output_data_uleb128 (1, NULL);
9574 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
9578 /* Output the marker for the end of the line number info. */
9579 ASM_OUTPUT_LABEL (asm_out_file, l2);
9582 /* Given a pointer to a tree node for some base type, return a pointer to
9583 a DIE that describes the given type.
9585 This routine must only be called for GCC type nodes that correspond to
9586 Dwarf base (fundamental) types. */
9589 base_type_die (tree type)
9591 dw_die_ref base_type_result;
9592 enum dwarf_type encoding;
9594 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
9597 /* If this is a subtype that should not be emitted as a subrange type,
9598 use the base type. See subrange_type_for_debug_p. */
9599 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
9600 type = TREE_TYPE (type);
9602 switch (TREE_CODE (type))
9605 if (TYPE_STRING_FLAG (type))
9607 if (TYPE_UNSIGNED (type))
9608 encoding = DW_ATE_unsigned_char;
9610 encoding = DW_ATE_signed_char;
9612 else if (TYPE_UNSIGNED (type))
9613 encoding = DW_ATE_unsigned;
9615 encoding = DW_ATE_signed;
9619 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
9620 encoding = DW_ATE_decimal_float;
9622 encoding = DW_ATE_float;
9625 case FIXED_POINT_TYPE:
9626 if (TYPE_UNSIGNED (type))
9627 encoding = DW_ATE_unsigned_fixed;
9629 encoding = DW_ATE_signed_fixed;
9632 /* Dwarf2 doesn't know anything about complex ints, so use
9633 a user defined type for it. */
9635 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
9636 encoding = DW_ATE_complex_float;
9638 encoding = DW_ATE_lo_user;
9642 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9643 encoding = DW_ATE_boolean;
9647 /* No other TREE_CODEs are Dwarf fundamental types. */
9651 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
9653 /* This probably indicates a bug. */
9654 if (! TYPE_NAME (type))
9655 add_name_attribute (base_type_result, "__unknown__");
9657 add_AT_unsigned (base_type_result, DW_AT_byte_size,
9658 int_size_in_bytes (type));
9659 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
9661 return base_type_result;
9664 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9665 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9668 is_base_type (tree type)
9670 switch (TREE_CODE (type))
9676 case FIXED_POINT_TYPE:
9684 case QUAL_UNION_TYPE:
9689 case REFERENCE_TYPE:
9702 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9703 node, return the size in bits for the type if it is a constant, or else
9704 return the alignment for the type if the type's size is not constant, or
9705 else return BITS_PER_WORD if the type actually turns out to be an
9708 static inline unsigned HOST_WIDE_INT
9709 simple_type_size_in_bits (const_tree type)
9711 if (TREE_CODE (type) == ERROR_MARK)
9712 return BITS_PER_WORD;
9713 else if (TYPE_SIZE (type) == NULL_TREE)
9715 else if (host_integerp (TYPE_SIZE (type), 1))
9716 return tree_low_cst (TYPE_SIZE (type), 1);
9718 return TYPE_ALIGN (type);
9721 /* Given a pointer to a tree node for a subrange type, return a pointer
9722 to a DIE that describes the given type. */
9725 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
9727 dw_die_ref subrange_die;
9728 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9730 if (context_die == NULL)
9731 context_die = comp_unit_die;
9733 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9735 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9737 /* The size of the subrange type and its base type do not match,
9738 so we need to generate a size attribute for the subrange type. */
9739 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9743 add_bound_info (subrange_die, DW_AT_lower_bound, low);
9745 add_bound_info (subrange_die, DW_AT_upper_bound, high);
9747 return subrange_die;
9750 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9751 entry that chains various modifiers in front of the given type. */
9754 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9755 dw_die_ref context_die)
9757 enum tree_code code = TREE_CODE (type);
9758 dw_die_ref mod_type_die;
9759 dw_die_ref sub_die = NULL;
9760 tree item_type = NULL;
9761 tree qualified_type;
9762 tree name, low, high;
9764 if (code == ERROR_MARK)
9767 /* See if we already have the appropriately qualified variant of
9770 = get_qualified_type (type,
9771 ((is_const_type ? TYPE_QUAL_CONST : 0)
9772 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9774 /* If we do, then we can just use its DIE, if it exists. */
9777 mod_type_die = lookup_type_die (qualified_type);
9779 return mod_type_die;
9782 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9784 /* Handle C typedef types. */
9785 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9787 tree dtype = TREE_TYPE (name);
9789 if (qualified_type == dtype)
9791 /* For a named type, use the typedef. */
9792 gen_type_die (qualified_type, context_die);
9793 return lookup_type_die (qualified_type);
9795 else if (is_const_type < TYPE_READONLY (dtype)
9796 || is_volatile_type < TYPE_VOLATILE (dtype)
9797 || (is_const_type <= TYPE_READONLY (dtype)
9798 && is_volatile_type <= TYPE_VOLATILE (dtype)
9799 && DECL_ORIGINAL_TYPE (name) != type))
9800 /* cv-unqualified version of named type. Just use the unnamed
9801 type to which it refers. */
9802 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9803 is_const_type, is_volatile_type,
9805 /* Else cv-qualified version of named type; fall through. */
9810 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9811 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9813 else if (is_volatile_type)
9815 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9816 sub_die = modified_type_die (type, 0, 0, context_die);
9818 else if (code == POINTER_TYPE)
9820 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9821 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9822 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9823 item_type = TREE_TYPE (type);
9825 else if (code == REFERENCE_TYPE)
9827 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9828 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9829 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9830 item_type = TREE_TYPE (type);
9832 else if (code == INTEGER_TYPE
9833 && TREE_TYPE (type) != NULL_TREE
9834 && subrange_type_for_debug_p (type, &low, &high))
9836 mod_type_die = subrange_type_die (type, low, high, context_die);
9837 item_type = TREE_TYPE (type);
9839 else if (is_base_type (type))
9840 mod_type_die = base_type_die (type);
9843 gen_type_die (type, context_die);
9845 /* We have to get the type_main_variant here (and pass that to the
9846 `lookup_type_die' routine) because the ..._TYPE node we have
9847 might simply be a *copy* of some original type node (where the
9848 copy was created to help us keep track of typedef names) and
9849 that copy might have a different TYPE_UID from the original
9851 if (TREE_CODE (type) != VECTOR_TYPE)
9852 return lookup_type_die (type_main_variant (type));
9854 /* Vectors have the debugging information in the type,
9855 not the main variant. */
9856 return lookup_type_die (type);
9859 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9860 don't output a DW_TAG_typedef, since there isn't one in the
9861 user's program; just attach a DW_AT_name to the type. */
9863 && (TREE_CODE (name) != TYPE_DECL
9864 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9866 if (TREE_CODE (name) == TYPE_DECL)
9867 /* Could just call add_name_and_src_coords_attributes here,
9868 but since this is a builtin type it doesn't have any
9869 useful source coordinates anyway. */
9870 name = DECL_NAME (name);
9871 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9875 equate_type_number_to_die (qualified_type, mod_type_die);
9878 /* We must do this after the equate_type_number_to_die call, in case
9879 this is a recursive type. This ensures that the modified_type_die
9880 recursion will terminate even if the type is recursive. Recursive
9881 types are possible in Ada. */
9882 sub_die = modified_type_die (item_type,
9883 TYPE_READONLY (item_type),
9884 TYPE_VOLATILE (item_type),
9887 if (sub_die != NULL)
9888 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9890 return mod_type_die;
9893 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9894 an enumerated type. */
9897 type_is_enum (const_tree type)
9899 return TREE_CODE (type) == ENUMERAL_TYPE;
9902 /* Return the DBX register number described by a given RTL node. */
9905 dbx_reg_number (const_rtx rtl)
9907 unsigned regno = REGNO (rtl);
9909 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9911 #ifdef LEAF_REG_REMAP
9912 if (current_function_uses_only_leaf_regs)
9914 int leaf_reg = LEAF_REG_REMAP (regno);
9916 regno = (unsigned) leaf_reg;
9920 return DBX_REGISTER_NUMBER (regno);
9923 /* Optionally add a DW_OP_piece term to a location description expression.
9924 DW_OP_piece is only added if the location description expression already
9925 doesn't end with DW_OP_piece. */
9928 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9930 dw_loc_descr_ref loc;
9932 if (*list_head != NULL)
9934 /* Find the end of the chain. */
9935 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9938 if (loc->dw_loc_opc != DW_OP_piece)
9939 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9943 /* Return a location descriptor that designates a machine register or
9944 zero if there is none. */
9946 static dw_loc_descr_ref
9947 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9951 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9954 regs = targetm.dwarf_register_span (rtl);
9956 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9957 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9959 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9962 /* Return a location descriptor that designates a machine register for
9963 a given hard register number. */
9965 static dw_loc_descr_ref
9966 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9968 dw_loc_descr_ref reg_loc_descr;
9972 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
9974 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
9976 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9977 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9979 return reg_loc_descr;
9982 /* Given an RTL of a register, return a location descriptor that
9983 designates a value that spans more than one register. */
9985 static dw_loc_descr_ref
9986 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9987 enum var_init_status initialized)
9991 dw_loc_descr_ref loc_result = NULL;
9994 #ifdef LEAF_REG_REMAP
9995 if (current_function_uses_only_leaf_regs)
9997 int leaf_reg = LEAF_REG_REMAP (reg);
9999 reg = (unsigned) leaf_reg;
10002 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
10003 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
10005 /* Simple, contiguous registers. */
10006 if (regs == NULL_RTX)
10008 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
10013 dw_loc_descr_ref t;
10015 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
10016 VAR_INIT_STATUS_INITIALIZED);
10017 add_loc_descr (&loc_result, t);
10018 add_loc_descr_op_piece (&loc_result, size);
10024 /* Now onto stupid register sets in non contiguous locations. */
10026 gcc_assert (GET_CODE (regs) == PARALLEL);
10028 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10031 for (i = 0; i < XVECLEN (regs, 0); ++i)
10033 dw_loc_descr_ref t;
10035 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
10036 VAR_INIT_STATUS_INITIALIZED);
10037 add_loc_descr (&loc_result, t);
10038 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
10039 add_loc_descr_op_piece (&loc_result, size);
10042 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10043 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10047 #endif /* DWARF2_DEBUGGING_INFO */
10049 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
10051 /* Return a location descriptor that designates a constant. */
10053 static dw_loc_descr_ref
10054 int_loc_descriptor (HOST_WIDE_INT i)
10056 enum dwarf_location_atom op;
10058 /* Pick the smallest representation of a constant, rather than just
10059 defaulting to the LEB encoding. */
10063 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
10064 else if (i <= 0xff)
10065 op = DW_OP_const1u;
10066 else if (i <= 0xffff)
10067 op = DW_OP_const2u;
10068 else if (HOST_BITS_PER_WIDE_INT == 32
10069 || i <= 0xffffffff)
10070 op = DW_OP_const4u;
10077 op = DW_OP_const1s;
10078 else if (i >= -0x8000)
10079 op = DW_OP_const2s;
10080 else if (HOST_BITS_PER_WIDE_INT == 32
10081 || i >= -0x80000000)
10082 op = DW_OP_const4s;
10087 return new_loc_descr (op, i, 0);
10091 #ifdef DWARF2_DEBUGGING_INFO
10093 /* Return a location descriptor that designates a base+offset location. */
10095 static dw_loc_descr_ref
10096 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
10097 enum var_init_status initialized)
10099 unsigned int regno;
10100 dw_loc_descr_ref result;
10101 dw_fde_ref fde = current_fde ();
10103 /* We only use "frame base" when we're sure we're talking about the
10104 post-prologue local stack frame. We do this by *not* running
10105 register elimination until this point, and recognizing the special
10106 argument pointer and soft frame pointer rtx's. */
10107 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
10109 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10113 if (GET_CODE (elim) == PLUS)
10115 offset += INTVAL (XEXP (elim, 1));
10116 elim = XEXP (elim, 0);
10118 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10119 && (elim == hard_frame_pointer_rtx
10120 || elim == stack_pointer_rtx))
10121 || elim == (frame_pointer_needed
10122 ? hard_frame_pointer_rtx
10123 : stack_pointer_rtx));
10125 /* If drap register is used to align stack, use frame
10126 pointer + offset to access stack variables. If stack
10127 is aligned without drap, use stack pointer + offset to
10128 access stack variables. */
10129 if (crtl->stack_realign_tried
10130 && cfa.reg == HARD_FRAME_POINTER_REGNUM
10131 && reg == frame_pointer_rtx)
10134 = DWARF_FRAME_REGNUM (cfa.indirect
10135 ? HARD_FRAME_POINTER_REGNUM
10136 : STACK_POINTER_REGNUM);
10137 return new_reg_loc_descr (base_reg, offset);
10140 offset += frame_pointer_fb_offset;
10141 return new_loc_descr (DW_OP_fbreg, offset, 0);
10145 && fde->drap_reg != INVALID_REGNUM
10146 && (fde->drap_reg == REGNO (reg)
10147 || fde->vdrap_reg == REGNO (reg)))
10149 /* Use cfa+offset to represent the location of arguments passed
10150 on stack when drap is used to align stack. */
10151 return new_loc_descr (DW_OP_fbreg, offset, 0);
10154 regno = dbx_reg_number (reg);
10156 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
10159 result = new_loc_descr (DW_OP_bregx, regno, offset);
10161 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10162 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10167 /* Return true if this RTL expression describes a base+offset calculation. */
10170 is_based_loc (const_rtx rtl)
10172 return (GET_CODE (rtl) == PLUS
10173 && ((REG_P (XEXP (rtl, 0))
10174 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
10175 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
10178 /* Return a descriptor that describes the concatenation of N locations
10179 used to form the address of a memory location. */
10181 static dw_loc_descr_ref
10182 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
10183 enum var_init_status initialized)
10186 dw_loc_descr_ref cc_loc_result = NULL;
10187 unsigned int n = XVECLEN (concatn, 0);
10189 for (i = 0; i < n; ++i)
10191 dw_loc_descr_ref ref;
10192 rtx x = XVECEXP (concatn, 0, i);
10194 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
10198 add_loc_descr (&cc_loc_result, ref);
10199 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10202 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10203 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10205 return cc_loc_result;
10208 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10211 static dw_loc_descr_ref
10212 tls_mem_loc_descriptor (rtx mem)
10215 dw_loc_descr_ref loc_result;
10217 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
10220 base = get_base_address (MEM_EXPR (mem));
10222 || TREE_CODE (base) != VAR_DECL
10223 || !DECL_THREAD_LOCAL_P (base))
10226 loc_result = loc_descriptor_from_tree_1 (MEM_EXPR (mem), 2);
10227 if (loc_result == NULL)
10230 if (INTVAL (MEM_OFFSET (mem)))
10231 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
10236 /* The following routine converts the RTL for a variable or parameter
10237 (resident in memory) into an equivalent Dwarf representation of a
10238 mechanism for getting the address of that same variable onto the top of a
10239 hypothetical "address evaluation" stack.
10241 When creating memory location descriptors, we are effectively transforming
10242 the RTL for a memory-resident object into its Dwarf postfix expression
10243 equivalent. This routine recursively descends an RTL tree, turning
10244 it into Dwarf postfix code as it goes.
10246 MODE is the mode of the memory reference, needed to handle some
10247 autoincrement addressing modes.
10249 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
10250 location list for RTL.
10252 Return 0 if we can't represent the location. */
10254 static dw_loc_descr_ref
10255 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
10256 enum var_init_status initialized)
10258 dw_loc_descr_ref mem_loc_result = NULL;
10259 enum dwarf_location_atom op;
10261 /* Note that for a dynamically sized array, the location we will generate a
10262 description of here will be the lowest numbered location which is
10263 actually within the array. That's *not* necessarily the same as the
10264 zeroth element of the array. */
10266 rtl = targetm.delegitimize_address (rtl);
10268 switch (GET_CODE (rtl))
10273 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
10274 just fall into the SUBREG code. */
10276 /* ... fall through ... */
10279 /* The case of a subreg may arise when we have a local (register)
10280 variable or a formal (register) parameter which doesn't quite fill
10281 up an entire register. For now, just assume that it is
10282 legitimate to make the Dwarf info refer to the whole register which
10283 contains the given subreg. */
10284 rtl = XEXP (rtl, 0);
10286 /* ... fall through ... */
10289 /* Whenever a register number forms a part of the description of the
10290 method for calculating the (dynamic) address of a memory resident
10291 object, DWARF rules require the register number be referred to as
10292 a "base register". This distinction is not based in any way upon
10293 what category of register the hardware believes the given register
10294 belongs to. This is strictly DWARF terminology we're dealing with
10295 here. Note that in cases where the location of a memory-resident
10296 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
10297 OP_CONST (0)) the actual DWARF location descriptor that we generate
10298 may just be OP_BASEREG (basereg). This may look deceptively like
10299 the object in question was allocated to a register (rather than in
10300 memory) so DWARF consumers need to be aware of the subtle
10301 distinction between OP_REG and OP_BASEREG. */
10302 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
10303 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
10304 else if (stack_realign_drap
10306 && crtl->args.internal_arg_pointer == rtl
10307 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
10309 /* If RTL is internal_arg_pointer, which has been optimized
10310 out, use DRAP instead. */
10311 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
10312 VAR_INIT_STATUS_INITIALIZED);
10317 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10318 VAR_INIT_STATUS_INITIALIZED);
10319 if (mem_loc_result == NULL)
10320 mem_loc_result = tls_mem_loc_descriptor (rtl);
10321 if (mem_loc_result != 0)
10322 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
10326 rtl = XEXP (rtl, 1);
10328 /* ... fall through ... */
10331 /* Some ports can transform a symbol ref into a label ref, because
10332 the symbol ref is too far away and has to be dumped into a constant
10336 /* Alternatively, the symbol in the constant pool might be referenced
10337 by a different symbol. */
10338 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
10341 rtx tmp = get_pool_constant_mark (rtl, &marked);
10343 if (GET_CODE (tmp) == SYMBOL_REF)
10346 if (CONSTANT_POOL_ADDRESS_P (tmp))
10347 get_pool_constant_mark (tmp, &marked);
10352 /* If all references to this pool constant were optimized away,
10353 it was not output and thus we can't represent it.
10354 FIXME: might try to use DW_OP_const_value here, though
10355 DW_OP_piece complicates it. */
10360 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
10361 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
10362 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
10363 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10367 /* Extract the PLUS expression nested inside and fall into
10368 PLUS code below. */
10369 rtl = XEXP (rtl, 1);
10374 /* Turn these into a PLUS expression and fall into the PLUS code
10376 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
10377 GEN_INT (GET_CODE (rtl) == PRE_INC
10378 ? GET_MODE_UNIT_SIZE (mode)
10379 : -GET_MODE_UNIT_SIZE (mode)));
10381 /* ... fall through ... */
10385 if (is_based_loc (rtl))
10386 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
10387 INTVAL (XEXP (rtl, 1)),
10388 VAR_INIT_STATUS_INITIALIZED);
10391 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
10392 VAR_INIT_STATUS_INITIALIZED);
10393 if (mem_loc_result == 0)
10396 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT)
10397 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
10400 dw_loc_descr_ref mem_loc_result2
10401 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10402 VAR_INIT_STATUS_INITIALIZED);
10403 if (mem_loc_result2 == 0)
10405 add_loc_descr (&mem_loc_result, mem_loc_result2);
10406 add_loc_descr (&mem_loc_result,
10407 new_loc_descr (DW_OP_plus, 0, 0));
10412 /* If a pseudo-reg is optimized away, it is possible for it to
10413 be replaced with a MEM containing a multiply or shift. */
10432 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
10433 VAR_INIT_STATUS_INITIALIZED);
10434 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
10435 VAR_INIT_STATUS_INITIALIZED);
10437 if (op0 == 0 || op1 == 0)
10440 mem_loc_result = op0;
10441 add_loc_descr (&mem_loc_result, op1);
10442 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
10447 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
10451 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
10452 VAR_INIT_STATUS_INITIALIZED);
10456 /* If delegitimize_address couldn't do anything with the UNSPEC, we
10457 can't express it in the debug info. This can happen e.g. with some
10462 gcc_unreachable ();
10465 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10466 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10468 return mem_loc_result;
10471 /* Return a descriptor that describes the concatenation of two locations.
10472 This is typically a complex variable. */
10474 static dw_loc_descr_ref
10475 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
10477 dw_loc_descr_ref cc_loc_result = NULL;
10478 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
10479 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
10481 if (x0_ref == 0 || x1_ref == 0)
10484 cc_loc_result = x0_ref;
10485 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
10487 add_loc_descr (&cc_loc_result, x1_ref);
10488 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
10490 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
10491 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10493 return cc_loc_result;
10496 /* Return a descriptor that describes the concatenation of N
10499 static dw_loc_descr_ref
10500 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
10503 dw_loc_descr_ref cc_loc_result = NULL;
10504 unsigned int n = XVECLEN (concatn, 0);
10506 for (i = 0; i < n; ++i)
10508 dw_loc_descr_ref ref;
10509 rtx x = XVECEXP (concatn, 0, i);
10511 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
10515 add_loc_descr (&cc_loc_result, ref);
10516 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
10519 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
10520 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
10522 return cc_loc_result;
10525 /* Output a proper Dwarf location descriptor for a variable or parameter
10526 which is either allocated in a register or in a memory location. For a
10527 register, we just generate an OP_REG and the register number. For a
10528 memory location we provide a Dwarf postfix expression describing how to
10529 generate the (dynamic) address of the object onto the address stack.
10531 If we don't know how to describe it, return 0. */
10533 static dw_loc_descr_ref
10534 loc_descriptor (rtx rtl, enum var_init_status initialized)
10536 dw_loc_descr_ref loc_result = NULL;
10538 switch (GET_CODE (rtl))
10541 /* The case of a subreg may arise when we have a local (register)
10542 variable or a formal (register) parameter which doesn't quite fill
10543 up an entire register. For now, just assume that it is
10544 legitimate to make the Dwarf info refer to the whole register which
10545 contains the given subreg. */
10546 rtl = SUBREG_REG (rtl);
10548 /* ... fall through ... */
10551 loc_result = reg_loc_descriptor (rtl, initialized);
10555 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
10557 if (loc_result == NULL)
10558 loc_result = tls_mem_loc_descriptor (rtl);
10562 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
10567 loc_result = concatn_loc_descriptor (rtl, initialized);
10572 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
10574 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
10578 rtl = XEXP (rtl, 1);
10583 rtvec par_elems = XVEC (rtl, 0);
10584 int num_elem = GET_NUM_ELEM (par_elems);
10585 enum machine_mode mode;
10588 /* Create the first one, so we have something to add to. */
10589 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
10591 if (loc_result == NULL)
10593 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
10594 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10595 for (i = 1; i < num_elem; i++)
10597 dw_loc_descr_ref temp;
10599 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
10603 add_loc_descr (&loc_result, temp);
10604 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
10605 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
10611 gcc_unreachable ();
10617 /* Similar, but generate the descriptor from trees instead of rtl. This comes
10618 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
10619 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
10620 top-level invocation, and we require the address of LOC; is 0 if we require
10621 the value of LOC. */
10623 static dw_loc_descr_ref
10624 loc_descriptor_from_tree_1 (tree loc, int want_address)
10626 dw_loc_descr_ref ret, ret1;
10627 int have_address = 0;
10628 enum dwarf_location_atom op;
10630 /* ??? Most of the time we do not take proper care for sign/zero
10631 extending the values properly. Hopefully this won't be a real
10634 switch (TREE_CODE (loc))
10639 case PLACEHOLDER_EXPR:
10640 /* This case involves extracting fields from an object to determine the
10641 position of other fields. We don't try to encode this here. The
10642 only user of this is Ada, which encodes the needed information using
10643 the names of types. */
10649 case PREINCREMENT_EXPR:
10650 case PREDECREMENT_EXPR:
10651 case POSTINCREMENT_EXPR:
10652 case POSTDECREMENT_EXPR:
10653 /* There are no opcodes for these operations. */
10657 /* If we already want an address, there's nothing we can do. */
10661 /* Otherwise, process the argument and look for the address. */
10662 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
10665 if (DECL_THREAD_LOCAL_P (loc))
10668 enum dwarf_location_atom first_op;
10669 enum dwarf_location_atom second_op;
10671 if (targetm.have_tls)
10673 /* If this is not defined, we have no way to emit the
10675 if (!targetm.asm_out.output_dwarf_dtprel)
10678 /* The way DW_OP_GNU_push_tls_address is specified, we
10679 can only look up addresses of objects in the current
10681 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
10683 first_op = (enum dwarf_location_atom) INTERNAL_DW_OP_tls_addr;
10684 second_op = DW_OP_GNU_push_tls_address;
10688 if (!targetm.emutls.debug_form_tls_address)
10690 loc = emutls_decl (loc);
10691 first_op = DW_OP_addr;
10692 second_op = DW_OP_form_tls_address;
10695 rtl = rtl_for_decl_location (loc);
10696 if (rtl == NULL_RTX)
10701 rtl = XEXP (rtl, 0);
10702 if (! CONSTANT_P (rtl))
10705 ret = new_loc_descr (first_op, 0, 0);
10706 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10707 ret->dw_loc_oprnd1.v.val_addr = rtl;
10709 ret1 = new_loc_descr (second_op, 0, 0);
10710 add_loc_descr (&ret, ret1);
10718 if (DECL_HAS_VALUE_EXPR_P (loc))
10719 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10724 case FUNCTION_DECL:
10726 rtx rtl = rtl_for_decl_location (loc);
10728 if (rtl == NULL_RTX)
10730 else if (GET_CODE (rtl) == CONST_INT)
10732 HOST_WIDE_INT val = INTVAL (rtl);
10733 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10734 val &= GET_MODE_MASK (DECL_MODE (loc));
10735 ret = int_loc_descriptor (val);
10737 else if (GET_CODE (rtl) == CONST_STRING)
10739 else if (CONSTANT_P (rtl))
10741 ret = new_loc_descr (DW_OP_addr, 0, 0);
10742 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10743 ret->dw_loc_oprnd1.v.val_addr = rtl;
10747 enum machine_mode mode;
10749 /* Certain constructs can only be represented at top-level. */
10750 if (want_address == 2)
10751 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10753 mode = GET_MODE (rtl);
10756 rtl = XEXP (rtl, 0);
10759 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10765 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10769 case COMPOUND_EXPR:
10770 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10773 case VIEW_CONVERT_EXPR:
10776 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10778 case COMPONENT_REF:
10779 case BIT_FIELD_REF:
10781 case ARRAY_RANGE_REF:
10784 HOST_WIDE_INT bitsize, bitpos, bytepos;
10785 enum machine_mode mode;
10787 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10789 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10790 &unsignedp, &volatilep, false);
10795 ret = loc_descriptor_from_tree_1 (obj, 1);
10797 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10800 if (offset != NULL_TREE)
10802 /* Variable offset. */
10803 ret1 = loc_descriptor_from_tree_1 (offset, 0);
10806 add_loc_descr (&ret, ret1);
10807 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10810 bytepos = bitpos / BITS_PER_UNIT;
10811 loc_descr_plus_const (&ret, bytepos);
10818 if (host_integerp (loc, 0))
10819 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10826 /* Get an RTL for this, if something has been emitted. */
10827 rtx rtl = lookup_constant_def (loc);
10828 enum machine_mode mode;
10830 if (!rtl || !MEM_P (rtl))
10832 mode = GET_MODE (rtl);
10833 rtl = XEXP (rtl, 0);
10834 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10839 case TRUTH_AND_EXPR:
10840 case TRUTH_ANDIF_EXPR:
10845 case TRUTH_XOR_EXPR:
10850 case TRUTH_OR_EXPR:
10851 case TRUTH_ORIF_EXPR:
10856 case FLOOR_DIV_EXPR:
10857 case CEIL_DIV_EXPR:
10858 case ROUND_DIV_EXPR:
10859 case TRUNC_DIV_EXPR:
10867 case FLOOR_MOD_EXPR:
10868 case CEIL_MOD_EXPR:
10869 case ROUND_MOD_EXPR:
10870 case TRUNC_MOD_EXPR:
10883 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10886 case POINTER_PLUS_EXPR:
10888 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10889 && host_integerp (TREE_OPERAND (loc, 1), 0))
10891 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10895 loc_descr_plus_const (&ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
10903 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10910 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10917 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10924 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10939 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10940 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10941 if (ret == 0 || ret1 == 0)
10944 add_loc_descr (&ret, ret1);
10945 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10948 case TRUTH_NOT_EXPR:
10962 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10966 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10972 const enum tree_code code =
10973 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10975 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10976 build2 (code, integer_type_node,
10977 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10978 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10981 /* ... fall through ... */
10985 dw_loc_descr_ref lhs
10986 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10987 dw_loc_descr_ref rhs
10988 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10989 dw_loc_descr_ref bra_node, jump_node, tmp;
10991 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10992 if (ret == 0 || lhs == 0 || rhs == 0)
10995 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10996 add_loc_descr (&ret, bra_node);
10998 add_loc_descr (&ret, rhs);
10999 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
11000 add_loc_descr (&ret, jump_node);
11002 add_loc_descr (&ret, lhs);
11003 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11004 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
11006 /* ??? Need a node to point the skip at. Use a nop. */
11007 tmp = new_loc_descr (DW_OP_nop, 0, 0);
11008 add_loc_descr (&ret, tmp);
11009 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
11010 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
11014 case FIX_TRUNC_EXPR:
11018 /* Leave front-end specific codes as simply unknown. This comes
11019 up, for instance, with the C STMT_EXPR. */
11020 if ((unsigned int) TREE_CODE (loc)
11021 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
11024 #ifdef ENABLE_CHECKING
11025 /* Otherwise this is a generic code; we should just lists all of
11026 these explicitly. We forgot one. */
11027 gcc_unreachable ();
11029 /* In a release build, we want to degrade gracefully: better to
11030 generate incomplete debugging information than to crash. */
11035 /* Show if we can't fill the request for an address. */
11036 if (want_address && !have_address)
11039 /* If we've got an address and don't want one, dereference. */
11040 if (!want_address && have_address && ret)
11042 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
11044 if (size > DWARF2_ADDR_SIZE || size == -1)
11046 else if (size == DWARF2_ADDR_SIZE)
11049 op = DW_OP_deref_size;
11051 add_loc_descr (&ret, new_loc_descr (op, size, 0));
11057 static inline dw_loc_descr_ref
11058 loc_descriptor_from_tree (tree loc)
11060 return loc_descriptor_from_tree_1 (loc, 2);
11063 /* Given a value, round it up to the lowest multiple of `boundary'
11064 which is not less than the value itself. */
11066 static inline HOST_WIDE_INT
11067 ceiling (HOST_WIDE_INT value, unsigned int boundary)
11069 return (((value + boundary - 1) / boundary) * boundary);
11072 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
11073 pointer to the declared type for the relevant field variable, or return
11074 `integer_type_node' if the given node turns out to be an
11075 ERROR_MARK node. */
11078 field_type (const_tree decl)
11082 if (TREE_CODE (decl) == ERROR_MARK)
11083 return integer_type_node;
11085 type = DECL_BIT_FIELD_TYPE (decl);
11086 if (type == NULL_TREE)
11087 type = TREE_TYPE (decl);
11092 /* Given a pointer to a tree node, return the alignment in bits for
11093 it, or else return BITS_PER_WORD if the node actually turns out to
11094 be an ERROR_MARK node. */
11096 static inline unsigned
11097 simple_type_align_in_bits (const_tree type)
11099 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
11102 static inline unsigned
11103 simple_decl_align_in_bits (const_tree decl)
11105 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
11108 /* Return the result of rounding T up to ALIGN. */
11110 static inline HOST_WIDE_INT
11111 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
11113 /* We must be careful if T is negative because HOST_WIDE_INT can be
11114 either "above" or "below" unsigned int as per the C promotion
11115 rules, depending on the host, thus making the signedness of the
11116 direct multiplication and division unpredictable. */
11117 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
11123 return (HOST_WIDE_INT) u;
11126 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
11127 lowest addressed byte of the "containing object" for the given FIELD_DECL,
11128 or return 0 if we are unable to determine what that offset is, either
11129 because the argument turns out to be a pointer to an ERROR_MARK node, or
11130 because the offset is actually variable. (We can't handle the latter case
11133 static HOST_WIDE_INT
11134 field_byte_offset (const_tree decl)
11136 HOST_WIDE_INT object_offset_in_bits;
11137 HOST_WIDE_INT bitpos_int;
11139 if (TREE_CODE (decl) == ERROR_MARK)
11142 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
11144 /* We cannot yet cope with fields whose positions are variable, so
11145 for now, when we see such things, we simply return 0. Someday, we may
11146 be able to handle such cases, but it will be damn difficult. */
11147 if (! host_integerp (bit_position (decl), 0))
11150 bitpos_int = int_bit_position (decl);
11152 #ifdef PCC_BITFIELD_TYPE_MATTERS
11153 if (PCC_BITFIELD_TYPE_MATTERS)
11156 tree field_size_tree;
11157 HOST_WIDE_INT deepest_bitpos;
11158 unsigned HOST_WIDE_INT field_size_in_bits;
11159 unsigned int type_align_in_bits;
11160 unsigned int decl_align_in_bits;
11161 unsigned HOST_WIDE_INT type_size_in_bits;
11163 type = field_type (decl);
11164 type_size_in_bits = simple_type_size_in_bits (type);
11165 type_align_in_bits = simple_type_align_in_bits (type);
11167 field_size_tree = DECL_SIZE (decl);
11169 /* The size could be unspecified if there was an error, or for
11170 a flexible array member. */
11171 if (!field_size_tree)
11172 field_size_tree = bitsize_zero_node;
11174 /* If the size of the field is not constant, use the type size. */
11175 if (host_integerp (field_size_tree, 1))
11176 field_size_in_bits = tree_low_cst (field_size_tree, 1);
11178 field_size_in_bits = type_size_in_bits;
11180 decl_align_in_bits = simple_decl_align_in_bits (decl);
11182 /* The GCC front-end doesn't make any attempt to keep track of the
11183 starting bit offset (relative to the start of the containing
11184 structure type) of the hypothetical "containing object" for a
11185 bit-field. Thus, when computing the byte offset value for the
11186 start of the "containing object" of a bit-field, we must deduce
11187 this information on our own. This can be rather tricky to do in
11188 some cases. For example, handling the following structure type
11189 definition when compiling for an i386/i486 target (which only
11190 aligns long long's to 32-bit boundaries) can be very tricky:
11192 struct S { int field1; long long field2:31; };
11194 Fortunately, there is a simple rule-of-thumb which can be used
11195 in such cases. When compiling for an i386/i486, GCC will
11196 allocate 8 bytes for the structure shown above. It decides to
11197 do this based upon one simple rule for bit-field allocation.
11198 GCC allocates each "containing object" for each bit-field at
11199 the first (i.e. lowest addressed) legitimate alignment boundary
11200 (based upon the required minimum alignment for the declared
11201 type of the field) which it can possibly use, subject to the
11202 condition that there is still enough available space remaining
11203 in the containing object (when allocated at the selected point)
11204 to fully accommodate all of the bits of the bit-field itself.
11206 This simple rule makes it obvious why GCC allocates 8 bytes for
11207 each object of the structure type shown above. When looking
11208 for a place to allocate the "containing object" for `field2',
11209 the compiler simply tries to allocate a 64-bit "containing
11210 object" at each successive 32-bit boundary (starting at zero)
11211 until it finds a place to allocate that 64- bit field such that
11212 at least 31 contiguous (and previously unallocated) bits remain
11213 within that selected 64 bit field. (As it turns out, for the
11214 example above, the compiler finds it is OK to allocate the
11215 "containing object" 64-bit field at bit-offset zero within the
11218 Here we attempt to work backwards from the limited set of facts
11219 we're given, and we try to deduce from those facts, where GCC
11220 must have believed that the containing object started (within
11221 the structure type). The value we deduce is then used (by the
11222 callers of this routine) to generate DW_AT_location and
11223 DW_AT_bit_offset attributes for fields (both bit-fields and, in
11224 the case of DW_AT_location, regular fields as well). */
11226 /* Figure out the bit-distance from the start of the structure to
11227 the "deepest" bit of the bit-field. */
11228 deepest_bitpos = bitpos_int + field_size_in_bits;
11230 /* This is the tricky part. Use some fancy footwork to deduce
11231 where the lowest addressed bit of the containing object must
11233 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11235 /* Round up to type_align by default. This works best for
11237 object_offset_in_bits
11238 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
11240 if (object_offset_in_bits > bitpos_int)
11242 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
11244 /* Round up to decl_align instead. */
11245 object_offset_in_bits
11246 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
11251 object_offset_in_bits = bitpos_int;
11253 return object_offset_in_bits / BITS_PER_UNIT;
11256 /* The following routines define various Dwarf attributes and any data
11257 associated with them. */
11259 /* Add a location description attribute value to a DIE.
11261 This emits location attributes suitable for whole variables and
11262 whole parameters. Note that the location attributes for struct fields are
11263 generated by the routine `data_member_location_attribute' below. */
11266 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
11267 dw_loc_descr_ref descr)
11270 add_AT_loc (die, attr_kind, descr);
11273 /* Attach the specialized form of location attribute used for data members of
11274 struct and union types. In the special case of a FIELD_DECL node which
11275 represents a bit-field, the "offset" part of this special location
11276 descriptor must indicate the distance in bytes from the lowest-addressed
11277 byte of the containing struct or union type to the lowest-addressed byte of
11278 the "containing object" for the bit-field. (See the `field_byte_offset'
11281 For any given bit-field, the "containing object" is a hypothetical object
11282 (of some integral or enum type) within which the given bit-field lives. The
11283 type of this hypothetical "containing object" is always the same as the
11284 declared type of the individual bit-field itself (for GCC anyway... the
11285 DWARF spec doesn't actually mandate this). Note that it is the size (in
11286 bytes) of the hypothetical "containing object" which will be given in the
11287 DW_AT_byte_size attribute for this bit-field. (See the
11288 `byte_size_attribute' function below.) It is also used when calculating the
11289 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
11290 function below.) */
11293 add_data_member_location_attribute (dw_die_ref die, tree decl)
11295 HOST_WIDE_INT offset;
11296 dw_loc_descr_ref loc_descr = 0;
11298 if (TREE_CODE (decl) == TREE_BINFO)
11300 /* We're working on the TAG_inheritance for a base class. */
11301 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
11303 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
11304 aren't at a fixed offset from all (sub)objects of the same
11305 type. We need to extract the appropriate offset from our
11306 vtable. The following dwarf expression means
11308 BaseAddr = ObAddr + *((*ObAddr) - Offset)
11310 This is specific to the V3 ABI, of course. */
11312 dw_loc_descr_ref tmp;
11314 /* Make a copy of the object address. */
11315 tmp = new_loc_descr (DW_OP_dup, 0, 0);
11316 add_loc_descr (&loc_descr, tmp);
11318 /* Extract the vtable address. */
11319 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11320 add_loc_descr (&loc_descr, tmp);
11322 /* Calculate the address of the offset. */
11323 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
11324 gcc_assert (offset < 0);
11326 tmp = int_loc_descriptor (-offset);
11327 add_loc_descr (&loc_descr, tmp);
11328 tmp = new_loc_descr (DW_OP_minus, 0, 0);
11329 add_loc_descr (&loc_descr, tmp);
11331 /* Extract the offset. */
11332 tmp = new_loc_descr (DW_OP_deref, 0, 0);
11333 add_loc_descr (&loc_descr, tmp);
11335 /* Add it to the object address. */
11336 tmp = new_loc_descr (DW_OP_plus, 0, 0);
11337 add_loc_descr (&loc_descr, tmp);
11340 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
11343 offset = field_byte_offset (decl);
11347 enum dwarf_location_atom op;
11349 /* The DWARF2 standard says that we should assume that the structure
11350 address is already on the stack, so we can specify a structure field
11351 address by using DW_OP_plus_uconst. */
11353 #ifdef MIPS_DEBUGGING_INFO
11354 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
11355 operator correctly. It works only if we leave the offset on the
11359 op = DW_OP_plus_uconst;
11362 loc_descr = new_loc_descr (op, offset, 0);
11365 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
11368 /* Writes integer values to dw_vec_const array. */
11371 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
11375 *dest++ = val & 0xff;
11381 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
11383 static HOST_WIDE_INT
11384 extract_int (const unsigned char *src, unsigned int size)
11386 HOST_WIDE_INT val = 0;
11392 val |= *--src & 0xff;
11398 /* Writes floating point values to dw_vec_const array. */
11401 insert_float (const_rtx rtl, unsigned char *array)
11403 REAL_VALUE_TYPE rv;
11407 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
11408 real_to_target (val, &rv, GET_MODE (rtl));
11410 /* real_to_target puts 32-bit pieces in each long. Pack them. */
11411 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
11413 insert_int (val[i], 4, array);
11418 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
11419 does not have a "location" either in memory or in a register. These
11420 things can arise in GNU C when a constant is passed as an actual parameter
11421 to an inlined function. They can also arise in C++ where declared
11422 constants do not necessarily get memory "homes". */
11425 add_const_value_attribute (dw_die_ref die, rtx rtl)
11427 switch (GET_CODE (rtl))
11431 HOST_WIDE_INT val = INTVAL (rtl);
11434 add_AT_int (die, DW_AT_const_value, val);
11436 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
11441 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
11442 floating-point constant. A CONST_DOUBLE is used whenever the
11443 constant requires more than one word in order to be adequately
11444 represented. We output CONST_DOUBLEs as blocks. */
11446 enum machine_mode mode = GET_MODE (rtl);
11448 if (SCALAR_FLOAT_MODE_P (mode))
11450 unsigned int length = GET_MODE_SIZE (mode);
11451 unsigned char *array = GGC_NEWVEC (unsigned char, length);
11453 insert_float (rtl, array);
11454 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
11458 /* ??? We really should be using HOST_WIDE_INT throughout. */
11459 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
11461 add_AT_long_long (die, DW_AT_const_value,
11462 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
11469 enum machine_mode mode = GET_MODE (rtl);
11470 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
11471 unsigned int length = CONST_VECTOR_NUNITS (rtl);
11472 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
11476 switch (GET_MODE_CLASS (mode))
11478 case MODE_VECTOR_INT:
11479 for (i = 0, p = array; i < length; i++, p += elt_size)
11481 rtx elt = CONST_VECTOR_ELT (rtl, i);
11482 HOST_WIDE_INT lo, hi;
11484 switch (GET_CODE (elt))
11492 lo = CONST_DOUBLE_LOW (elt);
11493 hi = CONST_DOUBLE_HIGH (elt);
11497 gcc_unreachable ();
11500 if (elt_size <= sizeof (HOST_WIDE_INT))
11501 insert_int (lo, elt_size, p);
11504 unsigned char *p0 = p;
11505 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
11507 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
11508 if (WORDS_BIG_ENDIAN)
11513 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
11514 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
11519 case MODE_VECTOR_FLOAT:
11520 for (i = 0, p = array; i < length; i++, p += elt_size)
11522 rtx elt = CONST_VECTOR_ELT (rtl, i);
11523 insert_float (elt, p);
11528 gcc_unreachable ();
11531 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
11536 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
11542 add_AT_addr (die, DW_AT_const_value, rtl);
11543 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
11547 /* In cases where an inlined instance of an inline function is passed
11548 the address of an `auto' variable (which is local to the caller) we
11549 can get a situation where the DECL_RTL of the artificial local
11550 variable (for the inlining) which acts as a stand-in for the
11551 corresponding formal parameter (of the inline function) will look
11552 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
11553 exactly a compile-time constant expression, but it isn't the address
11554 of the (artificial) local variable either. Rather, it represents the
11555 *value* which the artificial local variable always has during its
11556 lifetime. We currently have no way to represent such quasi-constant
11557 values in Dwarf, so for now we just punt and generate nothing. */
11561 /* No other kinds of rtx should be possible here. */
11562 gcc_unreachable ();
11567 /* Determine whether the evaluation of EXPR references any variables
11568 or functions which aren't otherwise used (and therefore may not be
11571 reference_to_unused (tree * tp, int * walk_subtrees,
11572 void * data ATTRIBUTE_UNUSED)
11574 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
11575 *walk_subtrees = 0;
11577 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
11578 && ! TREE_ASM_WRITTEN (*tp))
11580 /* ??? The C++ FE emits debug information for using decls, so
11581 putting gcc_unreachable here falls over. See PR31899. For now
11582 be conservative. */
11583 else if (!cgraph_global_info_ready
11584 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
11586 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
11588 struct varpool_node *node = varpool_node (*tp);
11592 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
11593 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
11595 struct cgraph_node *node = cgraph_node (*tp);
11596 if (node->process || TREE_ASM_WRITTEN (*tp))
11599 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
11605 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
11606 for use in a later add_const_value_attribute call. */
11609 rtl_for_decl_init (tree init, tree type)
11611 rtx rtl = NULL_RTX;
11613 /* If a variable is initialized with a string constant without embedded
11614 zeros, build CONST_STRING. */
11615 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
11617 tree enttype = TREE_TYPE (type);
11618 tree domain = TYPE_DOMAIN (type);
11619 enum machine_mode mode = TYPE_MODE (enttype);
11621 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
11623 && integer_zerop (TYPE_MIN_VALUE (domain))
11624 && compare_tree_int (TYPE_MAX_VALUE (domain),
11625 TREE_STRING_LENGTH (init) - 1) == 0
11626 && ((size_t) TREE_STRING_LENGTH (init)
11627 == strlen (TREE_STRING_POINTER (init)) + 1))
11628 rtl = gen_rtx_CONST_STRING (VOIDmode,
11629 ggc_strdup (TREE_STRING_POINTER (init)));
11631 /* Other aggregates, and complex values, could be represented using
11633 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
11635 /* Vectors only work if their mode is supported by the target.
11636 FIXME: generic vectors ought to work too. */
11637 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
11639 /* If the initializer is something that we know will expand into an
11640 immediate RTL constant, expand it now. We must be careful not to
11641 reference variables which won't be output. */
11642 else if (initializer_constant_valid_p (init, type)
11643 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
11645 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
11647 if (TREE_CODE (type) == VECTOR_TYPE)
11648 switch (TREE_CODE (init))
11653 if (TREE_CONSTANT (init))
11655 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
11656 bool constant_p = true;
11658 unsigned HOST_WIDE_INT ix;
11660 /* Even when ctor is constant, it might contain non-*_CST
11661 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
11662 belong into VECTOR_CST nodes. */
11663 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
11664 if (!CONSTANT_CLASS_P (value))
11666 constant_p = false;
11672 init = build_vector_from_ctor (type, elts);
11682 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
11684 /* If expand_expr returns a MEM, it wasn't immediate. */
11685 gcc_assert (!rtl || !MEM_P (rtl));
11691 /* Generate RTL for the variable DECL to represent its location. */
11694 rtl_for_decl_location (tree decl)
11698 /* Here we have to decide where we are going to say the parameter "lives"
11699 (as far as the debugger is concerned). We only have a couple of
11700 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11702 DECL_RTL normally indicates where the parameter lives during most of the
11703 activation of the function. If optimization is enabled however, this
11704 could be either NULL or else a pseudo-reg. Both of those cases indicate
11705 that the parameter doesn't really live anywhere (as far as the code
11706 generation parts of GCC are concerned) during most of the function's
11707 activation. That will happen (for example) if the parameter is never
11708 referenced within the function.
11710 We could just generate a location descriptor here for all non-NULL
11711 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11712 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11713 where DECL_RTL is NULL or is a pseudo-reg.
11715 Note however that we can only get away with using DECL_INCOMING_RTL as
11716 a backup substitute for DECL_RTL in certain limited cases. In cases
11717 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11718 we can be sure that the parameter was passed using the same type as it is
11719 declared to have within the function, and that its DECL_INCOMING_RTL
11720 points us to a place where a value of that type is passed.
11722 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11723 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11724 because in these cases DECL_INCOMING_RTL points us to a value of some
11725 type which is *different* from the type of the parameter itself. Thus,
11726 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11727 such cases, the debugger would end up (for example) trying to fetch a
11728 `float' from a place which actually contains the first part of a
11729 `double'. That would lead to really incorrect and confusing
11730 output at debug-time.
11732 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11733 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11734 are a couple of exceptions however. On little-endian machines we can
11735 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11736 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11737 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11738 when (on a little-endian machine) a non-prototyped function has a
11739 parameter declared to be of type `short' or `char'. In such cases,
11740 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11741 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11742 passed `int' value. If the debugger then uses that address to fetch
11743 a `short' or a `char' (on a little-endian machine) the result will be
11744 the correct data, so we allow for such exceptional cases below.
11746 Note that our goal here is to describe the place where the given formal
11747 parameter lives during most of the function's activation (i.e. between the
11748 end of the prologue and the start of the epilogue). We'll do that as best
11749 as we can. Note however that if the given formal parameter is modified
11750 sometime during the execution of the function, then a stack backtrace (at
11751 debug-time) will show the function as having been called with the *new*
11752 value rather than the value which was originally passed in. This happens
11753 rarely enough that it is not a major problem, but it *is* a problem, and
11754 I'd like to fix it.
11756 A future version of dwarf2out.c may generate two additional attributes for
11757 any given DW_TAG_formal_parameter DIE which will describe the "passed
11758 type" and the "passed location" for the given formal parameter in addition
11759 to the attributes we now generate to indicate the "declared type" and the
11760 "active location" for each parameter. This additional set of attributes
11761 could be used by debuggers for stack backtraces. Separately, note that
11762 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11763 This happens (for example) for inlined-instances of inline function formal
11764 parameters which are never referenced. This really shouldn't be
11765 happening. All PARM_DECL nodes should get valid non-NULL
11766 DECL_INCOMING_RTL values. FIXME. */
11768 /* Use DECL_RTL as the "location" unless we find something better. */
11769 rtl = DECL_RTL_IF_SET (decl);
11771 /* When generating abstract instances, ignore everything except
11772 constants, symbols living in memory, and symbols living in
11773 fixed registers. */
11774 if (! reload_completed)
11777 && (CONSTANT_P (rtl)
11779 && CONSTANT_P (XEXP (rtl, 0)))
11781 && TREE_CODE (decl) == VAR_DECL
11782 && TREE_STATIC (decl))))
11784 rtl = targetm.delegitimize_address (rtl);
11789 else if (TREE_CODE (decl) == PARM_DECL)
11791 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11793 tree declared_type = TREE_TYPE (decl);
11794 tree passed_type = DECL_ARG_TYPE (decl);
11795 enum machine_mode dmode = TYPE_MODE (declared_type);
11796 enum machine_mode pmode = TYPE_MODE (passed_type);
11798 /* This decl represents a formal parameter which was optimized out.
11799 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11800 all cases where (rtl == NULL_RTX) just below. */
11801 if (dmode == pmode)
11802 rtl = DECL_INCOMING_RTL (decl);
11803 else if (SCALAR_INT_MODE_P (dmode)
11804 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11805 && DECL_INCOMING_RTL (decl))
11807 rtx inc = DECL_INCOMING_RTL (decl);
11810 else if (MEM_P (inc))
11812 if (BYTES_BIG_ENDIAN)
11813 rtl = adjust_address_nv (inc, dmode,
11814 GET_MODE_SIZE (pmode)
11815 - GET_MODE_SIZE (dmode));
11822 /* If the parm was passed in registers, but lives on the stack, then
11823 make a big endian correction if the mode of the type of the
11824 parameter is not the same as the mode of the rtl. */
11825 /* ??? This is the same series of checks that are made in dbxout.c before
11826 we reach the big endian correction code there. It isn't clear if all
11827 of these checks are necessary here, but keeping them all is the safe
11829 else if (MEM_P (rtl)
11830 && XEXP (rtl, 0) != const0_rtx
11831 && ! CONSTANT_P (XEXP (rtl, 0))
11832 /* Not passed in memory. */
11833 && !MEM_P (DECL_INCOMING_RTL (decl))
11834 /* Not passed by invisible reference. */
11835 && (!REG_P (XEXP (rtl, 0))
11836 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11837 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11838 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11839 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11842 /* Big endian correction check. */
11843 && BYTES_BIG_ENDIAN
11844 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11845 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11848 int offset = (UNITS_PER_WORD
11849 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11851 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11852 plus_constant (XEXP (rtl, 0), offset));
11855 else if (TREE_CODE (decl) == VAR_DECL
11858 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11859 && BYTES_BIG_ENDIAN)
11861 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11862 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11864 /* If a variable is declared "register" yet is smaller than
11865 a register, then if we store the variable to memory, it
11866 looks like we're storing a register-sized value, when in
11867 fact we are not. We need to adjust the offset of the
11868 storage location to reflect the actual value's bytes,
11869 else gdb will not be able to display it. */
11871 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11872 plus_constant (XEXP (rtl, 0), rsize-dsize));
11875 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11876 and will have been substituted directly into all expressions that use it.
11877 C does not have such a concept, but C++ and other languages do. */
11878 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11879 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11882 rtl = targetm.delegitimize_address (rtl);
11884 /* If we don't look past the constant pool, we risk emitting a
11885 reference to a constant pool entry that isn't referenced from
11886 code, and thus is not emitted. */
11888 rtl = avoid_constant_pool_reference (rtl);
11893 /* We need to figure out what section we should use as the base for the
11894 address ranges where a given location is valid.
11895 1. If this particular DECL has a section associated with it, use that.
11896 2. If this function has a section associated with it, use that.
11897 3. Otherwise, use the text section.
11898 XXX: If you split a variable across multiple sections, we won't notice. */
11900 static const char *
11901 secname_for_decl (const_tree decl)
11903 const char *secname;
11905 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11907 tree sectree = DECL_SECTION_NAME (decl);
11908 secname = TREE_STRING_POINTER (sectree);
11910 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11912 tree sectree = DECL_SECTION_NAME (current_function_decl);
11913 secname = TREE_STRING_POINTER (sectree);
11915 else if (cfun && in_cold_section_p)
11916 secname = crtl->subsections.cold_section_label;
11918 secname = text_section_label;
11923 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
11924 returned. If so, the decl for the COMMON block is returned, and the
11925 value is the offset into the common block for the symbol. */
11928 fortran_common (tree decl, HOST_WIDE_INT *value)
11930 tree val_expr, cvar;
11931 enum machine_mode mode;
11932 HOST_WIDE_INT bitsize, bitpos;
11934 int volatilep = 0, unsignedp = 0;
11936 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11937 it does not have a value (the offset into the common area), or if it
11938 is thread local (as opposed to global) then it isn't common, and shouldn't
11939 be handled as such. */
11940 if (TREE_CODE (decl) != VAR_DECL
11941 || !TREE_PUBLIC (decl)
11942 || !TREE_STATIC (decl)
11943 || !DECL_HAS_VALUE_EXPR_P (decl)
11947 val_expr = DECL_VALUE_EXPR (decl);
11948 if (TREE_CODE (val_expr) != COMPONENT_REF)
11951 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11952 &mode, &unsignedp, &volatilep, true);
11954 if (cvar == NULL_TREE
11955 || TREE_CODE (cvar) != VAR_DECL
11956 || DECL_ARTIFICIAL (cvar)
11957 || !TREE_PUBLIC (cvar))
11961 if (offset != NULL)
11963 if (!host_integerp (offset, 0))
11965 *value = tree_low_cst (offset, 0);
11968 *value += bitpos / BITS_PER_UNIT;
11973 /* Dereference a location expression LOC if DECL is passed by invisible
11976 static dw_loc_descr_ref
11977 loc_by_reference (dw_loc_descr_ref loc, tree decl)
11979 HOST_WIDE_INT size;
11980 enum dwarf_location_atom op;
11985 if ((TREE_CODE (decl) != PARM_DECL
11986 && TREE_CODE (decl) != RESULT_DECL
11987 && TREE_CODE (decl) != VAR_DECL)
11988 || !DECL_BY_REFERENCE (decl))
11991 /* If loc is DW_OP_reg{0...31,x}, don't add DW_OP_deref, instead
11992 change it into corresponding DW_OP_breg{0...31,x} 0. Then the
11993 location expression is considered to be address of a memory location,
11994 rather than the register itself. */
11995 if (((loc->dw_loc_opc >= DW_OP_reg0 && loc->dw_loc_opc <= DW_OP_reg31)
11996 || loc->dw_loc_opc == DW_OP_regx)
11997 && (loc->dw_loc_next == NULL
11998 || (loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_uninit
11999 && loc->dw_loc_next->dw_loc_next == NULL)))
12001 if (loc->dw_loc_opc == DW_OP_regx)
12003 loc->dw_loc_opc = DW_OP_bregx;
12004 loc->dw_loc_oprnd2.v.val_int = 0;
12009 = (enum dwarf_location_atom)
12010 (loc->dw_loc_opc + (DW_OP_breg0 - DW_OP_reg0));
12011 loc->dw_loc_oprnd1.v.val_int = 0;
12016 size = int_size_in_bytes (TREE_TYPE (decl));
12017 if (size > DWARF2_ADDR_SIZE || size == -1)
12019 else if (size == DWARF2_ADDR_SIZE)
12022 op = DW_OP_deref_size;
12023 add_loc_descr (&loc, new_loc_descr (op, size, 0));
12027 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
12028 data attribute for a variable or a parameter. We generate the
12029 DW_AT_const_value attribute only in those cases where the given variable
12030 or parameter does not have a true "location" either in memory or in a
12031 register. This can happen (for example) when a constant is passed as an
12032 actual argument in a call to an inline function. (It's possible that
12033 these things can crop up in other ways also.) Note that one type of
12034 constant value which can be passed into an inlined function is a constant
12035 pointer. This can happen for example if an actual argument in an inlined
12036 function call evaluates to a compile-time constant address. */
12039 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
12040 enum dwarf_attribute attr)
12043 dw_loc_descr_ref descr;
12044 var_loc_list *loc_list;
12045 struct var_loc_node *node;
12046 if (TREE_CODE (decl) == ERROR_MARK)
12049 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
12050 || TREE_CODE (decl) == RESULT_DECL);
12052 /* See if we possibly have multiple locations for this variable. */
12053 loc_list = lookup_decl_loc (decl);
12055 /* If it truly has multiple locations, the first and last node will
12057 if (loc_list && loc_list->first != loc_list->last)
12059 const char *endname, *secname;
12060 dw_loc_list_ref list;
12062 enum var_init_status initialized;
12064 /* Now that we know what section we are using for a base,
12065 actually construct the list of locations.
12066 The first location information is what is passed to the
12067 function that creates the location list, and the remaining
12068 locations just get added on to that list.
12069 Note that we only know the start address for a location
12070 (IE location changes), so to build the range, we use
12071 the range [current location start, next location start].
12072 This means we have to special case the last node, and generate
12073 a range of [last location start, end of function label]. */
12075 node = loc_list->first;
12076 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12077 secname = secname_for_decl (decl);
12079 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
12080 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12082 initialized = VAR_INIT_STATUS_INITIALIZED;
12084 descr = loc_by_reference (loc_descriptor (varloc, initialized), decl);
12085 list = new_loc_list (descr, node->label, node->next->label, secname, 1);
12088 for (; node->next; node = node->next)
12089 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12091 /* The variable has a location between NODE->LABEL and
12092 NODE->NEXT->LABEL. */
12093 enum var_init_status initialized =
12094 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12095 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12096 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12098 add_loc_descr_to_loc_list (&list, descr,
12099 node->label, node->next->label, secname);
12102 /* If the variable has a location at the last label
12103 it keeps its location until the end of function. */
12104 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
12106 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12107 enum var_init_status initialized =
12108 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12110 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
12111 if (!current_function_decl)
12112 endname = text_end_label;
12115 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12116 current_function_funcdef_no);
12117 endname = ggc_strdup (label_id);
12119 descr = loc_by_reference (loc_descriptor (varloc, initialized),
12121 add_loc_descr_to_loc_list (&list, descr,
12122 node->label, endname, secname);
12125 /* Finally, add the location list to the DIE, and we are done. */
12126 add_AT_loc_list (die, attr, list);
12130 /* Try to get some constant RTL for this decl, and use that as the value of
12133 rtl = rtl_for_decl_location (decl);
12134 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
12136 add_const_value_attribute (die, rtl);
12140 /* If we have tried to generate the location otherwise, and it
12141 didn't work out (we wouldn't be here if we did), and we have a one entry
12142 location list, try generating a location from that. */
12143 if (loc_list && loc_list->first)
12145 enum var_init_status status;
12146 node = loc_list->first;
12147 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
12148 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
12151 descr = loc_by_reference (descr, decl);
12152 add_AT_location_description (die, attr, descr);
12157 /* We couldn't get any rtl, so try directly generating the location
12158 description from the tree. */
12159 descr = loc_descriptor_from_tree (decl);
12162 descr = loc_by_reference (descr, decl);
12163 add_AT_location_description (die, attr, descr);
12166 /* None of that worked, so it must not really have a location;
12167 try adding a constant value attribute from the DECL_INITIAL. */
12168 tree_add_const_value_attribute (die, decl);
12171 /* Add VARIABLE and DIE into deferred locations list. */
12174 defer_location (tree variable, dw_die_ref die)
12176 deferred_locations entry;
12177 entry.variable = variable;
12179 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
12182 /* Helper function for tree_add_const_value_attribute. Natively encode
12183 initializer INIT into an array. Return true if successful. */
12186 native_encode_initializer (tree init, unsigned char *array, int size)
12190 if (init == NULL_TREE)
12194 switch (TREE_CODE (init))
12197 type = TREE_TYPE (init);
12198 if (TREE_CODE (type) == ARRAY_TYPE)
12200 tree enttype = TREE_TYPE (type);
12201 enum machine_mode mode = TYPE_MODE (enttype);
12203 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
12205 if (int_size_in_bytes (type) != size)
12207 if (size > TREE_STRING_LENGTH (init))
12209 memcpy (array, TREE_STRING_POINTER (init),
12210 TREE_STRING_LENGTH (init));
12211 memset (array + TREE_STRING_LENGTH (init),
12212 '\0', size - TREE_STRING_LENGTH (init));
12215 memcpy (array, TREE_STRING_POINTER (init), size);
12220 type = TREE_TYPE (init);
12221 if (int_size_in_bytes (type) != size)
12223 if (TREE_CODE (type) == ARRAY_TYPE)
12225 HOST_WIDE_INT min_index;
12226 unsigned HOST_WIDE_INT cnt;
12227 int curpos = 0, fieldsize;
12228 constructor_elt *ce;
12230 if (TYPE_DOMAIN (type) == NULL_TREE
12231 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
12234 fieldsize = int_size_in_bytes (TREE_TYPE (type));
12235 if (fieldsize <= 0)
12238 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
12239 memset (array, '\0', size);
12241 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12244 tree val = ce->value;
12245 tree index = ce->index;
12247 if (index && TREE_CODE (index) == RANGE_EXPR)
12248 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
12251 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
12256 if (!native_encode_initializer (val, array + pos, fieldsize))
12259 curpos = pos + fieldsize;
12260 if (index && TREE_CODE (index) == RANGE_EXPR)
12262 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
12263 - tree_low_cst (TREE_OPERAND (index, 0), 0);
12267 memcpy (array + curpos, array + pos, fieldsize);
12268 curpos += fieldsize;
12271 gcc_assert (curpos <= size);
12275 else if (TREE_CODE (type) == RECORD_TYPE
12276 || TREE_CODE (type) == UNION_TYPE)
12278 tree field = NULL_TREE;
12279 unsigned HOST_WIDE_INT cnt;
12280 constructor_elt *ce;
12282 if (int_size_in_bytes (type) != size)
12285 if (TREE_CODE (type) == RECORD_TYPE)
12286 field = TYPE_FIELDS (type);
12289 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce);
12290 cnt++, field = field ? TREE_CHAIN (field) : 0)
12292 tree val = ce->value;
12293 int pos, fieldsize;
12295 if (ce->index != 0)
12301 if (field == NULL_TREE || DECL_BIT_FIELD (field))
12304 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
12305 && TYPE_DOMAIN (TREE_TYPE (field))
12306 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
12308 else if (DECL_SIZE_UNIT (field) == NULL_TREE
12309 || !host_integerp (DECL_SIZE_UNIT (field), 0))
12311 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
12312 pos = int_byte_position (field);
12313 gcc_assert (pos + fieldsize <= size);
12315 && !native_encode_initializer (val, array + pos, fieldsize))
12321 case VIEW_CONVERT_EXPR:
12322 case NON_LVALUE_EXPR:
12323 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
12325 return native_encode_expr (init, array, size) == size;
12329 /* If we don't have a copy of this variable in memory for some reason (such
12330 as a C++ member constant that doesn't have an out-of-line definition),
12331 we should tell the debugger about the constant value. */
12334 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
12337 tree type = TREE_TYPE (decl);
12340 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
12343 init = DECL_INITIAL (decl);
12344 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
12349 rtl = rtl_for_decl_init (init, type);
12351 add_const_value_attribute (var_die, rtl);
12352 /* If the host and target are sane, try harder. */
12353 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
12354 && initializer_constant_valid_p (init, type))
12356 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
12357 if (size > 0 && (int) size == size)
12359 unsigned char *array = GGC_CNEWVEC (unsigned char, size);
12361 if (native_encode_initializer (init, array, size))
12362 add_AT_vec (var_die, DW_AT_const_value, size, 1, array);
12367 /* Convert the CFI instructions for the current function into a
12368 location list. This is used for DW_AT_frame_base when we targeting
12369 a dwarf2 consumer that does not support the dwarf3
12370 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
12373 static dw_loc_list_ref
12374 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
12377 dw_loc_list_ref list, *list_tail;
12379 dw_cfa_location last_cfa, next_cfa;
12380 const char *start_label, *last_label, *section;
12381 dw_cfa_location remember;
12383 fde = current_fde ();
12384 gcc_assert (fde != NULL);
12386 section = secname_for_decl (current_function_decl);
12390 memset (&next_cfa, 0, sizeof (next_cfa));
12391 next_cfa.reg = INVALID_REGNUM;
12392 remember = next_cfa;
12394 start_label = fde->dw_fde_begin;
12396 /* ??? Bald assumption that the CIE opcode list does not contain
12397 advance opcodes. */
12398 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
12399 lookup_cfa_1 (cfi, &next_cfa, &remember);
12401 last_cfa = next_cfa;
12402 last_label = start_label;
12404 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
12405 switch (cfi->dw_cfi_opc)
12407 case DW_CFA_set_loc:
12408 case DW_CFA_advance_loc1:
12409 case DW_CFA_advance_loc2:
12410 case DW_CFA_advance_loc4:
12411 if (!cfa_equal_p (&last_cfa, &next_cfa))
12413 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12414 start_label, last_label, section,
12417 list_tail = &(*list_tail)->dw_loc_next;
12418 last_cfa = next_cfa;
12419 start_label = last_label;
12421 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
12424 case DW_CFA_advance_loc:
12425 /* The encoding is complex enough that we should never emit this. */
12426 gcc_unreachable ();
12429 lookup_cfa_1 (cfi, &next_cfa, &remember);
12433 if (!cfa_equal_p (&last_cfa, &next_cfa))
12435 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
12436 start_label, last_label, section,
12438 list_tail = &(*list_tail)->dw_loc_next;
12439 start_label = last_label;
12441 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
12442 start_label, fde->dw_fde_end, section,
12448 /* Compute a displacement from the "steady-state frame pointer" to the
12449 frame base (often the same as the CFA), and store it in
12450 frame_pointer_fb_offset. OFFSET is added to the displacement
12451 before the latter is negated. */
12454 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
12458 #ifdef FRAME_POINTER_CFA_OFFSET
12459 reg = frame_pointer_rtx;
12460 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
12462 reg = arg_pointer_rtx;
12463 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
12466 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
12467 if (GET_CODE (elim) == PLUS)
12469 offset += INTVAL (XEXP (elim, 1));
12470 elim = XEXP (elim, 0);
12473 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12474 && (elim == hard_frame_pointer_rtx
12475 || elim == stack_pointer_rtx))
12476 || elim == (frame_pointer_needed
12477 ? hard_frame_pointer_rtx
12478 : stack_pointer_rtx));
12480 frame_pointer_fb_offset = -offset;
12483 /* Generate a DW_AT_name attribute given some string value to be included as
12484 the value of the attribute. */
12487 add_name_attribute (dw_die_ref die, const char *name_string)
12489 if (name_string != NULL && *name_string != 0)
12491 if (demangle_name_func)
12492 name_string = (*demangle_name_func) (name_string);
12494 add_AT_string (die, DW_AT_name, name_string);
12498 /* Generate a DW_AT_comp_dir attribute for DIE. */
12501 add_comp_dir_attribute (dw_die_ref die)
12503 const char *wd = get_src_pwd ();
12505 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
12508 /* Given a tree node describing an array bound (either lower or upper) output
12509 a representation for that bound. */
12512 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
12514 switch (TREE_CODE (bound))
12519 /* All fixed-bounds are represented by INTEGER_CST nodes. */
12521 if (! host_integerp (bound, 0)
12522 || (bound_attr == DW_AT_lower_bound
12523 && (((is_c_family () || is_java ()) && integer_zerop (bound))
12524 || (is_fortran () && integer_onep (bound)))))
12525 /* Use the default. */
12528 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
12532 case VIEW_CONVERT_EXPR:
12533 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
12543 dw_die_ref decl_die = lookup_decl_die (bound);
12544 dw_loc_descr_ref loc;
12546 /* ??? Can this happen, or should the variable have been bound
12547 first? Probably it can, since I imagine that we try to create
12548 the types of parameters in the order in which they exist in
12549 the list, and won't have created a forward reference to a
12550 later parameter. */
12551 if (decl_die != NULL)
12552 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12555 loc = loc_descriptor_from_tree_1 (bound, 0);
12556 add_AT_location_description (subrange_die, bound_attr, loc);
12563 /* Otherwise try to create a stack operation procedure to
12564 evaluate the value of the array bound. */
12566 dw_die_ref ctx, decl_die;
12567 dw_loc_descr_ref loc;
12569 loc = loc_descriptor_from_tree (bound);
12573 if (current_function_decl == 0)
12574 ctx = comp_unit_die;
12576 ctx = lookup_decl_die (current_function_decl);
12578 decl_die = new_die (DW_TAG_variable, ctx, bound);
12579 add_AT_flag (decl_die, DW_AT_artificial, 1);
12580 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
12581 add_AT_loc (decl_die, DW_AT_location, loc);
12583 add_AT_die_ref (subrange_die, bound_attr, decl_die);
12589 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
12590 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
12591 Note that the block of subscript information for an array type also
12592 includes information about the element type of the given array type. */
12595 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
12597 unsigned dimension_number;
12599 dw_die_ref subrange_die;
12601 for (dimension_number = 0;
12602 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
12603 type = TREE_TYPE (type), dimension_number++)
12605 tree domain = TYPE_DOMAIN (type);
12607 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
12610 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
12611 and (in GNU C only) variable bounds. Handle all three forms
12613 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
12616 /* We have an array type with specified bounds. */
12617 lower = TYPE_MIN_VALUE (domain);
12618 upper = TYPE_MAX_VALUE (domain);
12620 /* Define the index type. */
12621 if (TREE_TYPE (domain))
12623 /* ??? This is probably an Ada unnamed subrange type. Ignore the
12624 TREE_TYPE field. We can't emit debug info for this
12625 because it is an unnamed integral type. */
12626 if (TREE_CODE (domain) == INTEGER_TYPE
12627 && TYPE_NAME (domain) == NULL_TREE
12628 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
12629 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
12632 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
12636 /* ??? If upper is NULL, the array has unspecified length,
12637 but it does have a lower bound. This happens with Fortran
12639 Since the debugger is definitely going to need to know N
12640 to produce useful results, go ahead and output the lower
12641 bound solo, and hope the debugger can cope. */
12643 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
12645 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
12648 /* Otherwise we have an array type with an unspecified length. The
12649 DWARF-2 spec does not say how to handle this; let's just leave out the
12655 add_byte_size_attribute (dw_die_ref die, tree tree_node)
12659 switch (TREE_CODE (tree_node))
12664 case ENUMERAL_TYPE:
12667 case QUAL_UNION_TYPE:
12668 size = int_size_in_bytes (tree_node);
12671 /* For a data member of a struct or union, the DW_AT_byte_size is
12672 generally given as the number of bytes normally allocated for an
12673 object of the *declared* type of the member itself. This is true
12674 even for bit-fields. */
12675 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
12678 gcc_unreachable ();
12681 /* Note that `size' might be -1 when we get to this point. If it is, that
12682 indicates that the byte size of the entity in question is variable. We
12683 have no good way of expressing this fact in Dwarf at the present time,
12684 so just let the -1 pass on through. */
12685 add_AT_unsigned (die, DW_AT_byte_size, size);
12688 /* For a FIELD_DECL node which represents a bit-field, output an attribute
12689 which specifies the distance in bits from the highest order bit of the
12690 "containing object" for the bit-field to the highest order bit of the
12693 For any given bit-field, the "containing object" is a hypothetical object
12694 (of some integral or enum type) within which the given bit-field lives. The
12695 type of this hypothetical "containing object" is always the same as the
12696 declared type of the individual bit-field itself. The determination of the
12697 exact location of the "containing object" for a bit-field is rather
12698 complicated. It's handled by the `field_byte_offset' function (above).
12700 Note that it is the size (in bytes) of the hypothetical "containing object"
12701 which will be given in the DW_AT_byte_size attribute for this bit-field.
12702 (See `byte_size_attribute' above). */
12705 add_bit_offset_attribute (dw_die_ref die, tree decl)
12707 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
12708 tree type = DECL_BIT_FIELD_TYPE (decl);
12709 HOST_WIDE_INT bitpos_int;
12710 HOST_WIDE_INT highest_order_object_bit_offset;
12711 HOST_WIDE_INT highest_order_field_bit_offset;
12712 HOST_WIDE_INT unsigned bit_offset;
12714 /* Must be a field and a bit field. */
12715 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
12717 /* We can't yet handle bit-fields whose offsets are variable, so if we
12718 encounter such things, just return without generating any attribute
12719 whatsoever. Likewise for variable or too large size. */
12720 if (! host_integerp (bit_position (decl), 0)
12721 || ! host_integerp (DECL_SIZE (decl), 1))
12724 bitpos_int = int_bit_position (decl);
12726 /* Note that the bit offset is always the distance (in bits) from the
12727 highest-order bit of the "containing object" to the highest-order bit of
12728 the bit-field itself. Since the "high-order end" of any object or field
12729 is different on big-endian and little-endian machines, the computation
12730 below must take account of these differences. */
12731 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
12732 highest_order_field_bit_offset = bitpos_int;
12734 if (! BYTES_BIG_ENDIAN)
12736 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
12737 highest_order_object_bit_offset += simple_type_size_in_bits (type);
12741 = (! BYTES_BIG_ENDIAN
12742 ? highest_order_object_bit_offset - highest_order_field_bit_offset
12743 : highest_order_field_bit_offset - highest_order_object_bit_offset);
12745 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
12748 /* For a FIELD_DECL node which represents a bit field, output an attribute
12749 which specifies the length in bits of the given field. */
12752 add_bit_size_attribute (dw_die_ref die, tree decl)
12754 /* Must be a field and a bit field. */
12755 gcc_assert (TREE_CODE (decl) == FIELD_DECL
12756 && DECL_BIT_FIELD_TYPE (decl));
12758 if (host_integerp (DECL_SIZE (decl), 1))
12759 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
12762 /* If the compiled language is ANSI C, then add a 'prototyped'
12763 attribute, if arg types are given for the parameters of a function. */
12766 add_prototyped_attribute (dw_die_ref die, tree func_type)
12768 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
12769 && TYPE_ARG_TYPES (func_type) != NULL)
12770 add_AT_flag (die, DW_AT_prototyped, 1);
12773 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
12774 by looking in either the type declaration or object declaration
12777 static inline dw_die_ref
12778 add_abstract_origin_attribute (dw_die_ref die, tree origin)
12780 dw_die_ref origin_die = NULL;
12782 if (TREE_CODE (origin) != FUNCTION_DECL)
12784 /* We may have gotten separated from the block for the inlined
12785 function, if we're in an exception handler or some such; make
12786 sure that the abstract function has been written out.
12788 Doing this for nested functions is wrong, however; functions are
12789 distinct units, and our context might not even be inline. */
12793 fn = TYPE_STUB_DECL (fn);
12795 fn = decl_function_context (fn);
12797 dwarf2out_abstract_function (fn);
12800 if (DECL_P (origin))
12801 origin_die = lookup_decl_die (origin);
12802 else if (TYPE_P (origin))
12803 origin_die = lookup_type_die (origin);
12805 /* XXX: Functions that are never lowered don't always have correct block
12806 trees (in the case of java, they simply have no block tree, in some other
12807 languages). For these functions, there is nothing we can really do to
12808 output correct debug info for inlined functions in all cases. Rather
12809 than die, we'll just produce deficient debug info now, in that we will
12810 have variables without a proper abstract origin. In the future, when all
12811 functions are lowered, we should re-add a gcc_assert (origin_die)
12815 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
12819 /* We do not currently support the pure_virtual attribute. */
12822 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
12824 if (DECL_VINDEX (func_decl))
12826 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12828 if (host_integerp (DECL_VINDEX (func_decl), 0))
12829 add_AT_loc (die, DW_AT_vtable_elem_location,
12830 new_loc_descr (DW_OP_constu,
12831 tree_low_cst (DECL_VINDEX (func_decl), 0),
12834 /* GNU extension: Record what type this method came from originally. */
12835 if (debug_info_level > DINFO_LEVEL_TERSE)
12836 add_AT_die_ref (die, DW_AT_containing_type,
12837 lookup_type_die (DECL_CONTEXT (func_decl)));
12841 /* Add source coordinate attributes for the given decl. */
12844 add_src_coords_attributes (dw_die_ref die, tree decl)
12846 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12848 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
12849 add_AT_unsigned (die, DW_AT_decl_line, s.line);
12852 /* Add a DW_AT_name attribute and source coordinate attribute for the
12853 given decl, but only if it actually has a name. */
12856 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
12860 decl_name = DECL_NAME (decl);
12861 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
12863 add_name_attribute (die, dwarf2_name (decl, 0));
12864 if (! DECL_ARTIFICIAL (decl))
12865 add_src_coords_attributes (die, decl);
12867 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
12868 && TREE_PUBLIC (decl)
12869 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
12870 && !DECL_ABSTRACT (decl)
12871 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
12873 add_AT_string (die, DW_AT_MIPS_linkage_name,
12874 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
12877 #ifdef VMS_DEBUGGING_INFO
12878 /* Get the function's name, as described by its RTL. This may be different
12879 from the DECL_NAME name used in the source file. */
12880 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
12882 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
12883 XEXP (DECL_RTL (decl), 0));
12884 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
12889 /* Push a new declaration scope. */
12892 push_decl_scope (tree scope)
12894 VEC_safe_push (tree, gc, decl_scope_table, scope);
12897 /* Pop a declaration scope. */
12900 pop_decl_scope (void)
12902 VEC_pop (tree, decl_scope_table);
12905 /* Return the DIE for the scope that immediately contains this type.
12906 Non-named types get global scope. Named types nested in other
12907 types get their containing scope if it's open, or global scope
12908 otherwise. All other types (i.e. function-local named types) get
12909 the current active scope. */
12912 scope_die_for (tree t, dw_die_ref context_die)
12914 dw_die_ref scope_die = NULL;
12915 tree containing_scope;
12918 /* Non-types always go in the current scope. */
12919 gcc_assert (TYPE_P (t));
12921 containing_scope = TYPE_CONTEXT (t);
12923 /* Use the containing namespace if it was passed in (for a declaration). */
12924 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
12926 if (context_die == lookup_decl_die (containing_scope))
12929 containing_scope = NULL_TREE;
12932 /* Ignore function type "scopes" from the C frontend. They mean that
12933 a tagged type is local to a parmlist of a function declarator, but
12934 that isn't useful to DWARF. */
12935 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
12936 containing_scope = NULL_TREE;
12938 if (containing_scope == NULL_TREE)
12939 scope_die = comp_unit_die;
12940 else if (TYPE_P (containing_scope))
12942 /* For types, we can just look up the appropriate DIE. But
12943 first we check to see if we're in the middle of emitting it
12944 so we know where the new DIE should go. */
12945 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12946 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12951 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12952 || TREE_ASM_WRITTEN (containing_scope));
12954 /* If none of the current dies are suitable, we get file scope. */
12955 scope_die = comp_unit_die;
12958 scope_die = lookup_type_die (containing_scope);
12961 scope_die = context_die;
12966 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12969 local_scope_p (dw_die_ref context_die)
12971 for (; context_die; context_die = context_die->die_parent)
12972 if (context_die->die_tag == DW_TAG_inlined_subroutine
12973 || context_die->die_tag == DW_TAG_subprogram)
12979 /* Returns nonzero if CONTEXT_DIE is a class. */
12982 class_scope_p (dw_die_ref context_die)
12984 return (context_die
12985 && (context_die->die_tag == DW_TAG_structure_type
12986 || context_die->die_tag == DW_TAG_class_type
12987 || context_die->die_tag == DW_TAG_interface_type
12988 || context_die->die_tag == DW_TAG_union_type));
12991 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12992 whether or not to treat a DIE in this context as a declaration. */
12995 class_or_namespace_scope_p (dw_die_ref context_die)
12997 return (class_scope_p (context_die)
12998 || (context_die && context_die->die_tag == DW_TAG_namespace));
13001 /* Many forms of DIEs require a "type description" attribute. This
13002 routine locates the proper "type descriptor" die for the type given
13003 by 'type', and adds a DW_AT_type attribute below the given die. */
13006 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
13007 int decl_volatile, dw_die_ref context_die)
13009 enum tree_code code = TREE_CODE (type);
13010 dw_die_ref type_die = NULL;
13012 /* ??? If this type is an unnamed subrange type of an integral, floating-point
13013 or fixed-point type, use the inner type. This is because we have no
13014 support for unnamed types in base_type_die. This can happen if this is
13015 an Ada subrange type. Correct solution is emit a subrange type die. */
13016 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
13017 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
13018 type = TREE_TYPE (type), code = TREE_CODE (type);
13020 if (code == ERROR_MARK
13021 /* Handle a special case. For functions whose return type is void, we
13022 generate *no* type attribute. (Note that no object may have type
13023 `void', so this only applies to function return types). */
13024 || code == VOID_TYPE)
13027 type_die = modified_type_die (type,
13028 decl_const || TYPE_READONLY (type),
13029 decl_volatile || TYPE_VOLATILE (type),
13032 if (type_die != NULL)
13033 add_AT_die_ref (object_die, DW_AT_type, type_die);
13036 /* Given an object die, add the calling convention attribute for the
13037 function call type. */
13039 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
13041 enum dwarf_calling_convention value = DW_CC_normal;
13043 value = ((enum dwarf_calling_convention)
13044 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
13046 /* DWARF doesn't provide a way to identify a program's source-level
13047 entry point. DW_AT_calling_convention attributes are only meant
13048 to describe functions' calling conventions. However, lacking a
13049 better way to signal the Fortran main program, we use this for the
13050 time being, following existing custom. */
13052 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
13053 value = DW_CC_program;
13055 /* Only add the attribute if the backend requests it, and
13056 is not DW_CC_normal. */
13057 if (value && (value != DW_CC_normal))
13058 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
13061 /* Given a tree pointer to a struct, class, union, or enum type node, return
13062 a pointer to the (string) tag name for the given type, or zero if the type
13063 was declared without a tag. */
13065 static const char *
13066 type_tag (const_tree type)
13068 const char *name = 0;
13070 if (TYPE_NAME (type) != 0)
13074 /* Find the IDENTIFIER_NODE for the type name. */
13075 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
13076 t = TYPE_NAME (type);
13078 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
13079 a TYPE_DECL node, regardless of whether or not a `typedef' was
13081 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13082 && ! DECL_IGNORED_P (TYPE_NAME (type)))
13084 /* We want to be extra verbose. Don't call dwarf_name if
13085 DECL_NAME isn't set. The default hook for decl_printable_name
13086 doesn't like that, and in this context it's correct to return
13087 0, instead of "<anonymous>" or the like. */
13088 if (DECL_NAME (TYPE_NAME (type)))
13089 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
13092 /* Now get the name as a string, or invent one. */
13093 if (!name && t != 0)
13094 name = IDENTIFIER_POINTER (t);
13097 return (name == 0 || *name == '\0') ? 0 : name;
13100 /* Return the type associated with a data member, make a special check
13101 for bit field types. */
13104 member_declared_type (const_tree member)
13106 return (DECL_BIT_FIELD_TYPE (member)
13107 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
13110 /* Get the decl's label, as described by its RTL. This may be different
13111 from the DECL_NAME name used in the source file. */
13114 static const char *
13115 decl_start_label (tree decl)
13118 const char *fnname;
13120 x = DECL_RTL (decl);
13121 gcc_assert (MEM_P (x));
13124 gcc_assert (GET_CODE (x) == SYMBOL_REF);
13126 fnname = XSTR (x, 0);
13131 /* These routines generate the internal representation of the DIE's for
13132 the compilation unit. Debugging information is collected by walking
13133 the declaration trees passed in from dwarf2out_decl(). */
13136 gen_array_type_die (tree type, dw_die_ref context_die)
13138 dw_die_ref scope_die = scope_die_for (type, context_die);
13139 dw_die_ref array_die;
13141 /* GNU compilers represent multidimensional array types as sequences of one
13142 dimensional array types whose element types are themselves array types.
13143 We sometimes squish that down to a single array_type DIE with multiple
13144 subscripts in the Dwarf debugging info. The draft Dwarf specification
13145 say that we are allowed to do this kind of compression in C, because
13146 there is no difference between an array of arrays and a multidimensional
13147 array. We don't do this for Ada to remain as close as possible to the
13148 actual representation, which is especially important against the language
13149 flexibilty wrt arrays of variable size. */
13151 bool collapse_nested_arrays = !is_ada ();
13154 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
13155 DW_TAG_string_type doesn't have DW_AT_type attribute). */
13156 if (TYPE_STRING_FLAG (type)
13157 && TREE_CODE (type) == ARRAY_TYPE
13159 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
13161 HOST_WIDE_INT size;
13163 array_die = new_die (DW_TAG_string_type, scope_die, type);
13164 add_name_attribute (array_die, type_tag (type));
13165 equate_type_number_to_die (type, array_die);
13166 size = int_size_in_bytes (type);
13168 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13169 else if (TYPE_DOMAIN (type) != NULL_TREE
13170 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
13171 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
13173 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
13174 dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
13176 size = int_size_in_bytes (TREE_TYPE (szdecl));
13177 if (loc && size > 0)
13179 add_AT_loc (array_die, DW_AT_string_length, loc);
13180 if (size != DWARF2_ADDR_SIZE)
13181 add_AT_unsigned (array_die, DW_AT_byte_size, size);
13187 /* ??? The SGI dwarf reader fails for array of array of enum types
13188 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
13189 array type comes before the outer array type. We thus call gen_type_die
13190 before we new_die and must prevent nested array types collapsing for this
13193 #ifdef MIPS_DEBUGGING_INFO
13194 gen_type_die (TREE_TYPE (type), context_die);
13195 collapse_nested_arrays = false;
13198 array_die = new_die (DW_TAG_array_type, scope_die, type);
13199 add_name_attribute (array_die, type_tag (type));
13200 equate_type_number_to_die (type, array_die);
13202 if (TREE_CODE (type) == VECTOR_TYPE)
13204 /* The frontend feeds us a representation for the vector as a struct
13205 containing an array. Pull out the array type. */
13206 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
13207 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
13210 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13212 && TREE_CODE (type) == ARRAY_TYPE
13213 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
13214 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
13215 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13218 /* We default the array ordering. SDB will probably do
13219 the right things even if DW_AT_ordering is not present. It's not even
13220 an issue until we start to get into multidimensional arrays anyway. If
13221 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
13222 then we'll have to put the DW_AT_ordering attribute back in. (But if
13223 and when we find out that we need to put these in, we will only do so
13224 for multidimensional arrays. */
13225 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
13228 #ifdef MIPS_DEBUGGING_INFO
13229 /* The SGI compilers handle arrays of unknown bound by setting
13230 AT_declaration and not emitting any subrange DIEs. */
13231 if (! TYPE_DOMAIN (type))
13232 add_AT_flag (array_die, DW_AT_declaration, 1);
13235 add_subscript_info (array_die, type, collapse_nested_arrays);
13237 /* Add representation of the type of the elements of this array type and
13238 emit the corresponding DIE if we haven't done it already. */
13239 element_type = TREE_TYPE (type);
13240 if (collapse_nested_arrays)
13241 while (TREE_CODE (element_type) == ARRAY_TYPE)
13243 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
13245 element_type = TREE_TYPE (element_type);
13248 #ifndef MIPS_DEBUGGING_INFO
13249 gen_type_die (element_type, context_die);
13252 add_type_attribute (array_die, element_type, 0, 0, context_die);
13254 if (get_AT (array_die, DW_AT_name))
13255 add_pubtype (type, array_die);
13258 static dw_loc_descr_ref
13259 descr_info_loc (tree val, tree base_decl)
13261 HOST_WIDE_INT size;
13262 dw_loc_descr_ref loc, loc2;
13263 enum dwarf_location_atom op;
13265 if (val == base_decl)
13266 return new_loc_descr (DW_OP_push_object_address, 0, 0);
13268 switch (TREE_CODE (val))
13271 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13273 return loc_descriptor_from_tree_1 (val, 0);
13275 if (host_integerp (val, 0))
13276 return int_loc_descriptor (tree_low_cst (val, 0));
13279 size = int_size_in_bytes (TREE_TYPE (val));
13282 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13285 if (size == DWARF2_ADDR_SIZE)
13286 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
13288 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
13290 case POINTER_PLUS_EXPR:
13292 if (host_integerp (TREE_OPERAND (val, 1), 1)
13293 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
13296 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13299 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
13305 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
13308 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
13311 add_loc_descr (&loc, loc2);
13312 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
13334 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
13335 tree val, tree base_decl)
13337 dw_loc_descr_ref loc;
13339 if (host_integerp (val, 0))
13341 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
13345 loc = descr_info_loc (val, base_decl);
13349 add_AT_loc (die, attr, loc);
13352 /* This routine generates DIE for array with hidden descriptor, details
13353 are filled into *info by a langhook. */
13356 gen_descr_array_type_die (tree type, struct array_descr_info *info,
13357 dw_die_ref context_die)
13359 dw_die_ref scope_die = scope_die_for (type, context_die);
13360 dw_die_ref array_die;
13363 array_die = new_die (DW_TAG_array_type, scope_die, type);
13364 add_name_attribute (array_die, type_tag (type));
13365 equate_type_number_to_die (type, array_die);
13367 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
13369 && info->ndimensions >= 2)
13370 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
13372 if (info->data_location)
13373 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
13375 if (info->associated)
13376 add_descr_info_field (array_die, DW_AT_associated, info->associated,
13378 if (info->allocated)
13379 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
13382 for (dim = 0; dim < info->ndimensions; dim++)
13384 dw_die_ref subrange_die
13385 = new_die (DW_TAG_subrange_type, array_die, NULL);
13387 if (info->dimen[dim].lower_bound)
13389 /* If it is the default value, omit it. */
13390 if ((is_c_family () || is_java ())
13391 && integer_zerop (info->dimen[dim].lower_bound))
13393 else if (is_fortran ()
13394 && integer_onep (info->dimen[dim].lower_bound))
13397 add_descr_info_field (subrange_die, DW_AT_lower_bound,
13398 info->dimen[dim].lower_bound,
13401 if (info->dimen[dim].upper_bound)
13402 add_descr_info_field (subrange_die, DW_AT_upper_bound,
13403 info->dimen[dim].upper_bound,
13405 if (info->dimen[dim].stride)
13406 add_descr_info_field (subrange_die, DW_AT_byte_stride,
13407 info->dimen[dim].stride,
13411 gen_type_die (info->element_type, context_die);
13412 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
13414 if (get_AT (array_die, DW_AT_name))
13415 add_pubtype (type, array_die);
13420 gen_entry_point_die (tree decl, dw_die_ref context_die)
13422 tree origin = decl_ultimate_origin (decl);
13423 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
13425 if (origin != NULL)
13426 add_abstract_origin_attribute (decl_die, origin);
13429 add_name_and_src_coords_attributes (decl_die, decl);
13430 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
13431 0, 0, context_die);
13434 if (DECL_ABSTRACT (decl))
13435 equate_decl_number_to_die (decl, decl_die);
13437 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
13441 /* Walk through the list of incomplete types again, trying once more to
13442 emit full debugging info for them. */
13445 retry_incomplete_types (void)
13449 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
13450 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
13453 /* Determine what tag to use for a record type. */
13455 static enum dwarf_tag
13456 record_type_tag (tree type)
13458 if (! lang_hooks.types.classify_record)
13459 return DW_TAG_structure_type;
13461 switch (lang_hooks.types.classify_record (type))
13463 case RECORD_IS_STRUCT:
13464 return DW_TAG_structure_type;
13466 case RECORD_IS_CLASS:
13467 return DW_TAG_class_type;
13469 case RECORD_IS_INTERFACE:
13470 return DW_TAG_interface_type;
13473 gcc_unreachable ();
13477 /* Generate a DIE to represent an enumeration type. Note that these DIEs
13478 include all of the information about the enumeration values also. Each
13479 enumerated type name/value is listed as a child of the enumerated type
13483 gen_enumeration_type_die (tree type, dw_die_ref context_die)
13485 dw_die_ref type_die = lookup_type_die (type);
13487 if (type_die == NULL)
13489 type_die = new_die (DW_TAG_enumeration_type,
13490 scope_die_for (type, context_die), type);
13491 equate_type_number_to_die (type, type_die);
13492 add_name_attribute (type_die, type_tag (type));
13494 else if (! TYPE_SIZE (type))
13497 remove_AT (type_die, DW_AT_declaration);
13499 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
13500 given enum type is incomplete, do not generate the DW_AT_byte_size
13501 attribute or the DW_AT_element_list attribute. */
13502 if (TYPE_SIZE (type))
13506 TREE_ASM_WRITTEN (type) = 1;
13507 add_byte_size_attribute (type_die, type);
13508 if (TYPE_STUB_DECL (type) != NULL_TREE)
13509 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13511 /* If the first reference to this type was as the return type of an
13512 inline function, then it may not have a parent. Fix this now. */
13513 if (type_die->die_parent == NULL)
13514 add_child_die (scope_die_for (type, context_die), type_die);
13516 for (link = TYPE_VALUES (type);
13517 link != NULL; link = TREE_CHAIN (link))
13519 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
13520 tree value = TREE_VALUE (link);
13522 add_name_attribute (enum_die,
13523 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
13525 if (TREE_CODE (value) == CONST_DECL)
13526 value = DECL_INITIAL (value);
13528 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
13529 /* DWARF2 does not provide a way of indicating whether or
13530 not enumeration constants are signed or unsigned. GDB
13531 always assumes the values are signed, so we output all
13532 values as if they were signed. That means that
13533 enumeration constants with very large unsigned values
13534 will appear to have negative values in the debugger. */
13535 add_AT_int (enum_die, DW_AT_const_value,
13536 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
13540 add_AT_flag (type_die, DW_AT_declaration, 1);
13542 if (get_AT (type_die, DW_AT_name))
13543 add_pubtype (type, type_die);
13548 /* Generate a DIE to represent either a real live formal parameter decl or to
13549 represent just the type of some formal parameter position in some function
13552 Note that this routine is a bit unusual because its argument may be a
13553 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
13554 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
13555 node. If it's the former then this function is being called to output a
13556 DIE to represent a formal parameter object (or some inlining thereof). If
13557 it's the latter, then this function is only being called to output a
13558 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
13559 argument type of some subprogram type. */
13562 gen_formal_parameter_die (tree node, tree origin, dw_die_ref context_die)
13564 tree node_or_origin = node ? node : origin;
13565 dw_die_ref parm_die
13566 = new_die (DW_TAG_formal_parameter, context_die, node);
13568 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
13570 case tcc_declaration:
13572 origin = decl_ultimate_origin (node);
13573 if (origin != NULL)
13574 add_abstract_origin_attribute (parm_die, origin);
13577 tree type = TREE_TYPE (node);
13578 add_name_and_src_coords_attributes (parm_die, node);
13579 if (DECL_BY_REFERENCE (node))
13580 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
13583 add_type_attribute (parm_die, type,
13584 TREE_READONLY (node),
13585 TREE_THIS_VOLATILE (node),
13587 if (DECL_ARTIFICIAL (node))
13588 add_AT_flag (parm_die, DW_AT_artificial, 1);
13592 equate_decl_number_to_die (node, parm_die);
13593 if (! DECL_ABSTRACT (node_or_origin))
13594 add_location_or_const_value_attribute (parm_die, node_or_origin,
13600 /* We were called with some kind of a ..._TYPE node. */
13601 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
13605 gcc_unreachable ();
13611 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
13612 at the end of an (ANSI prototyped) formal parameters list. */
13615 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
13617 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
13620 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
13621 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
13622 parameters as specified in some function type specification (except for
13623 those which appear as part of a function *definition*). */
13626 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
13629 tree formal_type = NULL;
13630 tree first_parm_type;
13633 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
13635 arg = DECL_ARGUMENTS (function_or_method_type);
13636 function_or_method_type = TREE_TYPE (function_or_method_type);
13641 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
13643 /* Make our first pass over the list of formal parameter types and output a
13644 DW_TAG_formal_parameter DIE for each one. */
13645 for (link = first_parm_type; link; )
13647 dw_die_ref parm_die;
13649 formal_type = TREE_VALUE (link);
13650 if (formal_type == void_type_node)
13653 /* Output a (nameless) DIE to represent the formal parameter itself. */
13654 parm_die = gen_formal_parameter_die (formal_type, NULL, context_die);
13655 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
13656 && link == first_parm_type)
13657 || (arg && DECL_ARTIFICIAL (arg)))
13658 add_AT_flag (parm_die, DW_AT_artificial, 1);
13660 link = TREE_CHAIN (link);
13662 arg = TREE_CHAIN (arg);
13665 /* If this function type has an ellipsis, add a
13666 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
13667 if (formal_type != void_type_node)
13668 gen_unspecified_parameters_die (function_or_method_type, context_die);
13670 /* Make our second (and final) pass over the list of formal parameter types
13671 and output DIEs to represent those types (as necessary). */
13672 for (link = TYPE_ARG_TYPES (function_or_method_type);
13673 link && TREE_VALUE (link);
13674 link = TREE_CHAIN (link))
13675 gen_type_die (TREE_VALUE (link), context_die);
13678 /* We want to generate the DIE for TYPE so that we can generate the
13679 die for MEMBER, which has been defined; we will need to refer back
13680 to the member declaration nested within TYPE. If we're trying to
13681 generate minimal debug info for TYPE, processing TYPE won't do the
13682 trick; we need to attach the member declaration by hand. */
13685 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
13687 gen_type_die (type, context_die);
13689 /* If we're trying to avoid duplicate debug info, we may not have
13690 emitted the member decl for this function. Emit it now. */
13691 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
13692 && ! lookup_decl_die (member))
13694 dw_die_ref type_die;
13695 gcc_assert (!decl_ultimate_origin (member));
13697 push_decl_scope (type);
13698 type_die = lookup_type_die (type);
13699 if (TREE_CODE (member) == FUNCTION_DECL)
13700 gen_subprogram_die (member, type_die);
13701 else if (TREE_CODE (member) == FIELD_DECL)
13703 /* Ignore the nameless fields that are used to skip bits but handle
13704 C++ anonymous unions and structs. */
13705 if (DECL_NAME (member) != NULL_TREE
13706 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
13707 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
13709 gen_type_die (member_declared_type (member), type_die);
13710 gen_field_die (member, type_die);
13714 gen_variable_die (member, NULL_TREE, type_die);
13720 /* Generate the DWARF2 info for the "abstract" instance of a function which we
13721 may later generate inlined and/or out-of-line instances of. */
13724 dwarf2out_abstract_function (tree decl)
13726 dw_die_ref old_die;
13729 int was_abstract = DECL_ABSTRACT (decl);
13731 /* Make sure we have the actual abstract inline, not a clone. */
13732 decl = DECL_ORIGIN (decl);
13734 old_die = lookup_decl_die (decl);
13735 if (old_die && get_AT (old_die, DW_AT_inline))
13736 /* We've already generated the abstract instance. */
13739 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
13740 we don't get confused by DECL_ABSTRACT. */
13741 if (debug_info_level > DINFO_LEVEL_TERSE)
13743 context = decl_class_context (decl);
13745 gen_type_die_for_member
13746 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
13749 /* Pretend we've just finished compiling this function. */
13750 save_fn = current_function_decl;
13751 current_function_decl = decl;
13752 push_cfun (DECL_STRUCT_FUNCTION (decl));
13754 set_decl_abstract_flags (decl, 1);
13755 dwarf2out_decl (decl);
13756 if (! was_abstract)
13757 set_decl_abstract_flags (decl, 0);
13759 current_function_decl = save_fn;
13763 /* Helper function of premark_used_types() which gets called through
13764 htab_traverse_resize().
13766 Marks the DIE of a given type in *SLOT as perennial, so it never gets
13767 marked as unused by prune_unused_types. */
13769 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
13774 type = (tree) *slot;
13775 die = lookup_type_die (type);
13777 die->die_perennial_p = 1;
13781 /* Mark all members of used_types_hash as perennial. */
13783 premark_used_types (void)
13785 if (cfun && cfun->used_types_hash)
13786 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
13789 /* Generate a DIE to represent a declared function (either file-scope or
13793 gen_subprogram_die (tree decl, dw_die_ref context_die)
13795 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
13796 tree origin = decl_ultimate_origin (decl);
13797 dw_die_ref subr_die;
13800 dw_die_ref old_die = lookup_decl_die (decl);
13801 int declaration = (current_function_decl != decl
13802 || class_or_namespace_scope_p (context_die));
13804 premark_used_types ();
13806 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
13807 started to generate the abstract instance of an inline, decided to output
13808 its containing class, and proceeded to emit the declaration of the inline
13809 from the member list for the class. If so, DECLARATION takes priority;
13810 we'll get back to the abstract instance when done with the class. */
13812 /* The class-scope declaration DIE must be the primary DIE. */
13813 if (origin && declaration && class_or_namespace_scope_p (context_die))
13816 gcc_assert (!old_die);
13819 /* Now that the C++ front end lazily declares artificial member fns, we
13820 might need to retrofit the declaration into its class. */
13821 if (!declaration && !origin && !old_die
13822 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
13823 && !class_or_namespace_scope_p (context_die)
13824 && debug_info_level > DINFO_LEVEL_TERSE)
13825 old_die = force_decl_die (decl);
13827 if (origin != NULL)
13829 gcc_assert (!declaration || local_scope_p (context_die));
13831 /* Fixup die_parent for the abstract instance of a nested
13832 inline function. */
13833 if (old_die && old_die->die_parent == NULL)
13834 add_child_die (context_die, old_die);
13836 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13837 add_abstract_origin_attribute (subr_die, origin);
13841 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13842 struct dwarf_file_data * file_index = lookup_filename (s.file);
13844 if (!get_AT_flag (old_die, DW_AT_declaration)
13845 /* We can have a normal definition following an inline one in the
13846 case of redefinition of GNU C extern inlines.
13847 It seems reasonable to use AT_specification in this case. */
13848 && !get_AT (old_die, DW_AT_inline))
13850 /* Detect and ignore this case, where we are trying to output
13851 something we have already output. */
13855 /* If the definition comes from the same place as the declaration,
13856 maybe use the old DIE. We always want the DIE for this function
13857 that has the *_pc attributes to be under comp_unit_die so the
13858 debugger can find it. We also need to do this for abstract
13859 instances of inlines, since the spec requires the out-of-line copy
13860 to have the same parent. For local class methods, this doesn't
13861 apply; we just use the old DIE. */
13862 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
13863 && (DECL_ARTIFICIAL (decl)
13864 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
13865 && (get_AT_unsigned (old_die, DW_AT_decl_line)
13866 == (unsigned) s.line))))
13868 subr_die = old_die;
13870 /* Clear out the declaration attribute and the formal parameters.
13871 Do not remove all children, because it is possible that this
13872 declaration die was forced using force_decl_die(). In such
13873 cases die that forced declaration die (e.g. TAG_imported_module)
13874 is one of the children that we do not want to remove. */
13875 remove_AT (subr_die, DW_AT_declaration);
13876 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
13880 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13881 add_AT_specification (subr_die, old_die);
13882 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13883 add_AT_file (subr_die, DW_AT_decl_file, file_index);
13884 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13885 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
13890 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
13892 if (TREE_PUBLIC (decl))
13893 add_AT_flag (subr_die, DW_AT_external, 1);
13895 add_name_and_src_coords_attributes (subr_die, decl);
13896 if (debug_info_level > DINFO_LEVEL_TERSE)
13898 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
13899 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
13900 0, 0, context_die);
13903 add_pure_or_virtual_attribute (subr_die, decl);
13904 if (DECL_ARTIFICIAL (decl))
13905 add_AT_flag (subr_die, DW_AT_artificial, 1);
13907 if (TREE_PROTECTED (decl))
13908 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
13909 else if (TREE_PRIVATE (decl))
13910 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
13915 if (!old_die || !get_AT (old_die, DW_AT_inline))
13917 add_AT_flag (subr_die, DW_AT_declaration, 1);
13919 /* If this is an explicit function declaration then generate
13920 a DW_AT_explicit attribute. */
13921 if (lang_hooks.decls.function_decl_explicit_p (decl))
13922 add_AT_flag (subr_die, DW_AT_explicit, 1);
13924 /* The first time we see a member function, it is in the context of
13925 the class to which it belongs. We make sure of this by emitting
13926 the class first. The next time is the definition, which is
13927 handled above. The two may come from the same source text.
13929 Note that force_decl_die() forces function declaration die. It is
13930 later reused to represent definition. */
13931 equate_decl_number_to_die (decl, subr_die);
13934 else if (DECL_ABSTRACT (decl))
13936 if (DECL_DECLARED_INLINE_P (decl))
13938 if (cgraph_function_possibly_inlined_p (decl))
13939 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
13941 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
13945 if (cgraph_function_possibly_inlined_p (decl))
13946 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
13948 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
13951 if (DECL_DECLARED_INLINE_P (decl)
13952 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
13953 add_AT_flag (subr_die, DW_AT_artificial, 1);
13955 equate_decl_number_to_die (decl, subr_die);
13957 else if (!DECL_EXTERNAL (decl))
13959 HOST_WIDE_INT cfa_fb_offset;
13961 if (!old_die || !get_AT (old_die, DW_AT_inline))
13962 equate_decl_number_to_die (decl, subr_die);
13964 if (!flag_reorder_blocks_and_partition)
13966 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13967 current_function_funcdef_no);
13968 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13969 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13970 current_function_funcdef_no);
13971 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13973 add_pubname (decl, subr_die);
13974 add_arange (decl, subr_die);
13977 { /* Do nothing for now; maybe need to duplicate die, one for
13978 hot section and one for cold section, then use the hot/cold
13979 section begin/end labels to generate the aranges... */
13981 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13982 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13983 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13984 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13986 add_pubname (decl, subr_die);
13987 add_arange (decl, subr_die);
13988 add_arange (decl, subr_die);
13992 #ifdef MIPS_DEBUGGING_INFO
13993 /* Add a reference to the FDE for this routine. */
13994 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13997 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13999 /* We define the "frame base" as the function's CFA. This is more
14000 convenient for several reasons: (1) It's stable across the prologue
14001 and epilogue, which makes it better than just a frame pointer,
14002 (2) With dwarf3, there exists a one-byte encoding that allows us
14003 to reference the .debug_frame data by proxy, but failing that,
14004 (3) We can at least reuse the code inspection and interpretation
14005 code that determines the CFA position at various points in the
14007 /* ??? Use some command-line or configury switch to enable the use
14008 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
14009 consumers that understand it; fall back to "pure" dwarf2 and
14010 convert the CFA data into a location list. */
14012 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
14013 if (list->dw_loc_next)
14014 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
14016 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
14019 /* Compute a displacement from the "steady-state frame pointer" to
14020 the CFA. The former is what all stack slots and argument slots
14021 will reference in the rtl; the later is what we've told the
14022 debugger about. We'll need to adjust all frame_base references
14023 by this displacement. */
14024 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
14026 if (cfun->static_chain_decl)
14027 add_AT_location_description (subr_die, DW_AT_static_link,
14028 loc_descriptor_from_tree (cfun->static_chain_decl));
14031 /* Now output descriptions of the arguments for this function. This gets
14032 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
14033 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
14034 `...' at the end of the formal parameter list. In order to find out if
14035 there was a trailing ellipsis or not, we must instead look at the type
14036 associated with the FUNCTION_DECL. This will be a node of type
14037 FUNCTION_TYPE. If the chain of type nodes hanging off of this
14038 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
14039 an ellipsis at the end. */
14041 /* In the case where we are describing a mere function declaration, all we
14042 need to do here (and all we *can* do here) is to describe the *types* of
14043 its formal parameters. */
14044 if (debug_info_level <= DINFO_LEVEL_TERSE)
14046 else if (declaration)
14047 gen_formal_types_die (decl, subr_die);
14050 /* Generate DIEs to represent all known formal parameters. */
14051 tree arg_decls = DECL_ARGUMENTS (decl);
14054 /* When generating DIEs, generate the unspecified_parameters DIE
14055 instead if we come across the arg "__builtin_va_alist" */
14056 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
14057 if (TREE_CODE (parm) == PARM_DECL)
14059 if (DECL_NAME (parm)
14060 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
14061 "__builtin_va_alist"))
14062 gen_unspecified_parameters_die (parm, subr_die);
14064 gen_decl_die (parm, NULL, subr_die);
14067 /* Decide whether we need an unspecified_parameters DIE at the end.
14068 There are 2 more cases to do this for: 1) the ansi ... declaration -
14069 this is detectable when the end of the arg list is not a
14070 void_type_node 2) an unprototyped function declaration (not a
14071 definition). This just means that we have no info about the
14072 parameters at all. */
14073 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
14074 if (fn_arg_types != NULL)
14076 /* This is the prototyped case, check for.... */
14077 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
14078 gen_unspecified_parameters_die (decl, subr_die);
14080 else if (DECL_INITIAL (decl) == NULL_TREE)
14081 gen_unspecified_parameters_die (decl, subr_die);
14084 /* Output Dwarf info for all of the stuff within the body of the function
14085 (if it has one - it may be just a declaration). */
14086 outer_scope = DECL_INITIAL (decl);
14088 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
14089 a function. This BLOCK actually represents the outermost binding contour
14090 for the function, i.e. the contour in which the function's formal
14091 parameters and labels get declared. Curiously, it appears that the front
14092 end doesn't actually put the PARM_DECL nodes for the current function onto
14093 the BLOCK_VARS list for this outer scope, but are strung off of the
14094 DECL_ARGUMENTS list for the function instead.
14096 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
14097 the LABEL_DECL nodes for the function however, and we output DWARF info
14098 for those in decls_for_scope. Just within the `outer_scope' there will be
14099 a BLOCK node representing the function's outermost pair of curly braces,
14100 and any blocks used for the base and member initializers of a C++
14101 constructor function. */
14102 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
14104 /* Emit a DW_TAG_variable DIE for a named return value. */
14105 if (DECL_NAME (DECL_RESULT (decl)))
14106 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
14108 current_function_has_inlines = 0;
14109 decls_for_scope (outer_scope, subr_die, 0);
14111 #if 0 && defined (MIPS_DEBUGGING_INFO)
14112 if (current_function_has_inlines)
14114 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
14115 if (! comp_unit_has_inlines)
14117 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
14118 comp_unit_has_inlines = 1;
14123 /* Add the calling convention attribute if requested. */
14124 add_calling_convention_attribute (subr_die, decl);
14128 /* Returns a hash value for X (which really is a die_struct). */
14131 common_block_die_table_hash (const void *x)
14133 const_dw_die_ref d = (const_dw_die_ref) x;
14134 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
14137 /* Return nonzero if decl_id and die_parent of die_struct X is the same
14138 as decl_id and die_parent of die_struct Y. */
14141 common_block_die_table_eq (const void *x, const void *y)
14143 const_dw_die_ref d = (const_dw_die_ref) x;
14144 const_dw_die_ref e = (const_dw_die_ref) y;
14145 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
14148 /* Generate a DIE to represent a declared data object.
14149 Either DECL or ORIGIN must be non-null. */
14152 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
14156 tree decl_or_origin = decl ? decl : origin;
14157 dw_die_ref var_die;
14158 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
14159 dw_die_ref origin_die;
14160 int declaration = (DECL_EXTERNAL (decl_or_origin)
14161 /* If DECL is COMDAT and has not actually been
14162 emitted, we cannot take its address; there
14163 might end up being no definition anywhere in
14164 the program. For example, consider the C++
14168 struct S { static const int i = 7; };
14173 int f() { return S<int>::i; }
14175 Here, S<int>::i is not DECL_EXTERNAL, but no
14176 definition is required, so the compiler will
14177 not emit a definition. */
14178 || (TREE_CODE (decl_or_origin) == VAR_DECL
14179 && DECL_COMDAT (decl_or_origin)
14180 && !TREE_ASM_WRITTEN (decl_or_origin))
14181 || class_or_namespace_scope_p (context_die));
14184 origin = decl_ultimate_origin (decl);
14186 com_decl = fortran_common (decl_or_origin, &off);
14188 /* Symbol in common gets emitted as a child of the common block, in the form
14189 of a data member. */
14193 dw_die_ref com_die;
14194 dw_loc_descr_ref loc;
14195 die_node com_die_arg;
14197 var_die = lookup_decl_die (decl_or_origin);
14200 if (get_AT (var_die, DW_AT_location) == NULL)
14202 loc = loc_descriptor_from_tree (com_decl);
14207 /* Optimize the common case. */
14208 if (loc->dw_loc_opc == DW_OP_addr
14209 && loc->dw_loc_next == NULL
14210 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr)
14212 loc->dw_loc_oprnd1.v.val_addr
14213 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14215 loc_descr_plus_const (&loc, off);
14217 add_AT_loc (var_die, DW_AT_location, loc);
14218 remove_AT (var_die, DW_AT_declaration);
14224 if (common_block_die_table == NULL)
14225 common_block_die_table
14226 = htab_create_ggc (10, common_block_die_table_hash,
14227 common_block_die_table_eq, NULL);
14229 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
14230 com_die_arg.decl_id = DECL_UID (com_decl);
14231 com_die_arg.die_parent = context_die;
14232 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
14233 loc = loc_descriptor_from_tree (com_decl);
14234 if (com_die == NULL)
14237 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
14240 com_die = new_die (DW_TAG_common_block, context_die, decl);
14241 add_name_and_src_coords_attributes (com_die, com_decl);
14244 add_AT_loc (com_die, DW_AT_location, loc);
14245 /* Avoid sharing the same loc descriptor between
14246 DW_TAG_common_block and DW_TAG_variable. */
14247 loc = loc_descriptor_from_tree (com_decl);
14249 else if (DECL_EXTERNAL (decl))
14250 add_AT_flag (com_die, DW_AT_declaration, 1);
14251 add_pubname_string (cnam, com_die); /* ??? needed? */
14252 com_die->decl_id = DECL_UID (com_decl);
14253 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
14254 *slot = (void *) com_die;
14256 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
14258 add_AT_loc (com_die, DW_AT_location, loc);
14259 loc = loc_descriptor_from_tree (com_decl);
14260 remove_AT (com_die, DW_AT_declaration);
14262 var_die = new_die (DW_TAG_variable, com_die, decl);
14263 add_name_and_src_coords_attributes (var_die, decl);
14264 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
14265 TREE_THIS_VOLATILE (decl), context_die);
14266 add_AT_flag (var_die, DW_AT_external, 1);
14271 /* Optimize the common case. */
14272 if (loc->dw_loc_opc == DW_OP_addr
14273 && loc->dw_loc_next == NULL
14274 && GET_CODE (loc->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
14275 loc->dw_loc_oprnd1.v.val_addr
14276 = plus_constant (loc->dw_loc_oprnd1.v.val_addr, off);
14278 loc_descr_plus_const (&loc, off);
14280 add_AT_loc (var_die, DW_AT_location, loc);
14282 else if (DECL_EXTERNAL (decl))
14283 add_AT_flag (var_die, DW_AT_declaration, 1);
14284 equate_decl_number_to_die (decl, var_die);
14288 /* If the compiler emitted a definition for the DECL declaration
14289 and if we already emitted a DIE for it, don't emit a second
14290 DIE for it again. */
14293 && old_die->die_parent == context_die)
14296 /* For static data members, the declaration in the class is supposed
14297 to have DW_TAG_member tag; the specification should still be
14298 DW_TAG_variable referencing the DW_TAG_member DIE. */
14299 if (declaration && class_scope_p (context_die))
14300 var_die = new_die (DW_TAG_member, context_die, decl);
14302 var_die = new_die (DW_TAG_variable, context_die, decl);
14305 if (origin != NULL)
14306 origin_die = add_abstract_origin_attribute (var_die, origin);
14308 /* Loop unrolling can create multiple blocks that refer to the same
14309 static variable, so we must test for the DW_AT_declaration flag.
14311 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
14312 copy decls and set the DECL_ABSTRACT flag on them instead of
14315 ??? Duplicated blocks have been rewritten to use .debug_ranges.
14317 ??? The declare_in_namespace support causes us to get two DIEs for one
14318 variable, both of which are declarations. We want to avoid considering
14319 one to be a specification, so we must test that this DIE is not a
14321 else if (old_die && TREE_STATIC (decl) && ! declaration
14322 && get_AT_flag (old_die, DW_AT_declaration) == 1)
14324 /* This is a definition of a C++ class level static. */
14325 add_AT_specification (var_die, old_die);
14326 if (DECL_NAME (decl))
14328 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
14329 struct dwarf_file_data * file_index = lookup_filename (s.file);
14331 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
14332 add_AT_file (var_die, DW_AT_decl_file, file_index);
14334 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
14335 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
14340 tree type = TREE_TYPE (decl);
14342 add_name_and_src_coords_attributes (var_die, decl);
14343 if ((TREE_CODE (decl) == PARM_DECL
14344 || TREE_CODE (decl) == RESULT_DECL
14345 || TREE_CODE (decl) == VAR_DECL)
14346 && DECL_BY_REFERENCE (decl))
14347 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
14349 add_type_attribute (var_die, type, TREE_READONLY (decl),
14350 TREE_THIS_VOLATILE (decl), context_die);
14352 if (TREE_PUBLIC (decl))
14353 add_AT_flag (var_die, DW_AT_external, 1);
14355 if (DECL_ARTIFICIAL (decl))
14356 add_AT_flag (var_die, DW_AT_artificial, 1);
14358 if (TREE_PROTECTED (decl))
14359 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
14360 else if (TREE_PRIVATE (decl))
14361 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
14365 add_AT_flag (var_die, DW_AT_declaration, 1);
14367 if (decl && (DECL_ABSTRACT (decl) || declaration))
14368 equate_decl_number_to_die (decl, var_die);
14371 && (! DECL_ABSTRACT (decl_or_origin)
14372 /* Local static vars are shared between all clones/inlines,
14373 so emit DW_AT_location on the abstract DIE if DECL_RTL is
14375 || (TREE_CODE (decl_or_origin) == VAR_DECL
14376 && TREE_STATIC (decl_or_origin)
14377 && DECL_RTL_SET_P (decl_or_origin)))
14378 /* When abstract origin already has DW_AT_location attribute, no need
14379 to add it again. */
14380 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
14382 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
14383 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
14384 defer_location (decl_or_origin, var_die);
14386 add_location_or_const_value_attribute (var_die,
14389 add_pubname (decl_or_origin, var_die);
14392 tree_add_const_value_attribute (var_die, decl_or_origin);
14395 /* Generate a DIE to represent a named constant. */
14398 gen_const_die (tree decl, dw_die_ref context_die)
14400 dw_die_ref const_die;
14401 tree type = TREE_TYPE (decl);
14403 const_die = new_die (DW_TAG_constant, context_die, decl);
14404 add_name_and_src_coords_attributes (const_die, decl);
14405 add_type_attribute (const_die, type, 1, 0, context_die);
14406 if (TREE_PUBLIC (decl))
14407 add_AT_flag (const_die, DW_AT_external, 1);
14408 if (DECL_ARTIFICIAL (decl))
14409 add_AT_flag (const_die, DW_AT_artificial, 1);
14410 tree_add_const_value_attribute (const_die, decl);
14413 /* Generate a DIE to represent a label identifier. */
14416 gen_label_die (tree decl, dw_die_ref context_die)
14418 tree origin = decl_ultimate_origin (decl);
14419 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
14421 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14423 if (origin != NULL)
14424 add_abstract_origin_attribute (lbl_die, origin);
14426 add_name_and_src_coords_attributes (lbl_die, decl);
14428 if (DECL_ABSTRACT (decl))
14429 equate_decl_number_to_die (decl, lbl_die);
14432 insn = DECL_RTL_IF_SET (decl);
14434 /* Deleted labels are programmer specified labels which have been
14435 eliminated because of various optimizations. We still emit them
14436 here so that it is possible to put breakpoints on them. */
14440 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
14442 /* When optimization is enabled (via -O) some parts of the compiler
14443 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
14444 represent source-level labels which were explicitly declared by
14445 the user. This really shouldn't be happening though, so catch
14446 it if it ever does happen. */
14447 gcc_assert (!INSN_DELETED_P (insn));
14449 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
14450 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
14455 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
14456 attributes to the DIE for a block STMT, to describe where the inlined
14457 function was called from. This is similar to add_src_coords_attributes. */
14460 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
14462 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
14464 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
14465 add_AT_unsigned (die, DW_AT_call_line, s.line);
14469 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
14470 Add low_pc and high_pc attributes to the DIE for a block STMT. */
14473 add_high_low_attributes (tree stmt, dw_die_ref die)
14475 char label[MAX_ARTIFICIAL_LABEL_BYTES];
14477 if (BLOCK_FRAGMENT_CHAIN (stmt))
14481 if (inlined_function_outer_scope_p (stmt))
14483 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14484 BLOCK_NUMBER (stmt));
14485 add_AT_lbl_id (die, DW_AT_entry_pc, label);
14488 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
14490 chain = BLOCK_FRAGMENT_CHAIN (stmt);
14493 add_ranges (chain);
14494 chain = BLOCK_FRAGMENT_CHAIN (chain);
14501 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
14502 BLOCK_NUMBER (stmt));
14503 add_AT_lbl_id (die, DW_AT_low_pc, label);
14504 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
14505 BLOCK_NUMBER (stmt));
14506 add_AT_lbl_id (die, DW_AT_high_pc, label);
14510 /* Generate a DIE for a lexical block. */
14513 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
14515 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
14517 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
14518 add_high_low_attributes (stmt, stmt_die);
14520 decls_for_scope (stmt, stmt_die, depth);
14523 /* Generate a DIE for an inlined subprogram. */
14526 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
14528 tree decl = block_ultimate_origin (stmt);
14530 /* Emit info for the abstract instance first, if we haven't yet. We
14531 must emit this even if the block is abstract, otherwise when we
14532 emit the block below (or elsewhere), we may end up trying to emit
14533 a die whose origin die hasn't been emitted, and crashing. */
14534 dwarf2out_abstract_function (decl);
14536 if (! BLOCK_ABSTRACT (stmt))
14538 dw_die_ref subr_die
14539 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
14541 add_abstract_origin_attribute (subr_die, decl);
14542 if (TREE_ASM_WRITTEN (stmt))
14543 add_high_low_attributes (stmt, subr_die);
14544 add_call_src_coords_attributes (stmt, subr_die);
14546 decls_for_scope (stmt, subr_die, depth);
14547 current_function_has_inlines = 1;
14550 /* We may get here if we're the outer block of function A that was
14551 inlined into function B that was inlined into function C. When
14552 generating debugging info for C, dwarf2out_abstract_function(B)
14553 would mark all inlined blocks as abstract, including this one.
14554 So, we wouldn't (and shouldn't) expect labels to be generated
14555 for this one. Instead, just emit debugging info for
14556 declarations within the block. This is particularly important
14557 in the case of initializers of arguments passed from B to us:
14558 if they're statement expressions containing declarations, we
14559 wouldn't generate dies for their abstract variables, and then,
14560 when generating dies for the real variables, we'd die (pun
14562 gen_lexical_block_die (stmt, context_die, depth);
14565 /* Generate a DIE for a field in a record, or structure. */
14568 gen_field_die (tree decl, dw_die_ref context_die)
14570 dw_die_ref decl_die;
14572 if (TREE_TYPE (decl) == error_mark_node)
14575 decl_die = new_die (DW_TAG_member, context_die, decl);
14576 add_name_and_src_coords_attributes (decl_die, decl);
14577 add_type_attribute (decl_die, member_declared_type (decl),
14578 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
14581 if (DECL_BIT_FIELD_TYPE (decl))
14583 add_byte_size_attribute (decl_die, decl);
14584 add_bit_size_attribute (decl_die, decl);
14585 add_bit_offset_attribute (decl_die, decl);
14588 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
14589 add_data_member_location_attribute (decl_die, decl);
14591 if (DECL_ARTIFICIAL (decl))
14592 add_AT_flag (decl_die, DW_AT_artificial, 1);
14594 if (TREE_PROTECTED (decl))
14595 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
14596 else if (TREE_PRIVATE (decl))
14597 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
14599 /* Equate decl number to die, so that we can look up this decl later on. */
14600 equate_decl_number_to_die (decl, decl_die);
14604 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14605 Use modified_type_die instead.
14606 We keep this code here just in case these types of DIEs may be needed to
14607 represent certain things in other languages (e.g. Pascal) someday. */
14610 gen_pointer_type_die (tree type, dw_die_ref context_die)
14613 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
14615 equate_type_number_to_die (type, ptr_die);
14616 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14617 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14620 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
14621 Use modified_type_die instead.
14622 We keep this code here just in case these types of DIEs may be needed to
14623 represent certain things in other languages (e.g. Pascal) someday. */
14626 gen_reference_type_die (tree type, dw_die_ref context_die)
14629 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
14631 equate_type_number_to_die (type, ref_die);
14632 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
14633 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
14637 /* Generate a DIE for a pointer to a member type. */
14640 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
14643 = new_die (DW_TAG_ptr_to_member_type,
14644 scope_die_for (type, context_die), type);
14646 equate_type_number_to_die (type, ptr_die);
14647 add_AT_die_ref (ptr_die, DW_AT_containing_type,
14648 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
14649 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
14652 /* Generate the DIE for the compilation unit. */
14655 gen_compile_unit_die (const char *filename)
14658 char producer[250];
14659 const char *language_string = lang_hooks.name;
14662 die = new_die (DW_TAG_compile_unit, NULL, NULL);
14666 add_name_attribute (die, filename);
14667 /* Don't add cwd for <built-in>. */
14668 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
14669 add_comp_dir_attribute (die);
14672 sprintf (producer, "%s %s", language_string, version_string);
14674 #ifdef MIPS_DEBUGGING_INFO
14675 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
14676 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
14677 not appear in the producer string, the debugger reaches the conclusion
14678 that the object file is stripped and has no debugging information.
14679 To get the MIPS/SGI debugger to believe that there is debugging
14680 information in the object file, we add a -g to the producer string. */
14681 if (debug_info_level > DINFO_LEVEL_TERSE)
14682 strcat (producer, " -g");
14685 add_AT_string (die, DW_AT_producer, producer);
14687 if (strcmp (language_string, "GNU C++") == 0)
14688 language = DW_LANG_C_plus_plus;
14689 else if (strcmp (language_string, "GNU Ada") == 0)
14690 language = DW_LANG_Ada95;
14691 else if (strcmp (language_string, "GNU F77") == 0)
14692 language = DW_LANG_Fortran77;
14693 else if (strcmp (language_string, "GNU Fortran") == 0)
14694 language = DW_LANG_Fortran95;
14695 else if (strcmp (language_string, "GNU Pascal") == 0)
14696 language = DW_LANG_Pascal83;
14697 else if (strcmp (language_string, "GNU Java") == 0)
14698 language = DW_LANG_Java;
14699 else if (strcmp (language_string, "GNU Objective-C") == 0)
14700 language = DW_LANG_ObjC;
14701 else if (strcmp (language_string, "GNU Objective-C++") == 0)
14702 language = DW_LANG_ObjC_plus_plus;
14704 language = DW_LANG_C89;
14706 add_AT_unsigned (die, DW_AT_language, language);
14710 /* Generate the DIE for a base class. */
14713 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
14715 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
14717 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
14718 add_data_member_location_attribute (die, binfo);
14720 if (BINFO_VIRTUAL_P (binfo))
14721 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
14723 if (access == access_public_node)
14724 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
14725 else if (access == access_protected_node)
14726 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
14729 /* Generate a DIE for a class member. */
14732 gen_member_die (tree type, dw_die_ref context_die)
14735 tree binfo = TYPE_BINFO (type);
14738 /* If this is not an incomplete type, output descriptions of each of its
14739 members. Note that as we output the DIEs necessary to represent the
14740 members of this record or union type, we will also be trying to output
14741 DIEs to represent the *types* of those members. However the `type'
14742 function (above) will specifically avoid generating type DIEs for member
14743 types *within* the list of member DIEs for this (containing) type except
14744 for those types (of members) which are explicitly marked as also being
14745 members of this (containing) type themselves. The g++ front- end can
14746 force any given type to be treated as a member of some other (containing)
14747 type by setting the TYPE_CONTEXT of the given (member) type to point to
14748 the TREE node representing the appropriate (containing) type. */
14750 /* First output info about the base classes. */
14753 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
14757 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
14758 gen_inheritance_die (base,
14759 (accesses ? VEC_index (tree, accesses, i)
14760 : access_public_node), context_die);
14763 /* Now output info about the data members and type members. */
14764 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
14766 /* If we thought we were generating minimal debug info for TYPE
14767 and then changed our minds, some of the member declarations
14768 may have already been defined. Don't define them again, but
14769 do put them in the right order. */
14771 child = lookup_decl_die (member);
14773 splice_child_die (context_die, child);
14775 gen_decl_die (member, NULL, context_die);
14778 /* Now output info about the function members (if any). */
14779 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
14781 /* Don't include clones in the member list. */
14782 if (DECL_ABSTRACT_ORIGIN (member))
14785 child = lookup_decl_die (member);
14787 splice_child_die (context_die, child);
14789 gen_decl_die (member, NULL, context_die);
14793 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
14794 is set, we pretend that the type was never defined, so we only get the
14795 member DIEs needed by later specification DIEs. */
14798 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
14799 enum debug_info_usage usage)
14801 dw_die_ref type_die = lookup_type_die (type);
14802 dw_die_ref scope_die = 0;
14804 int complete = (TYPE_SIZE (type)
14805 && (! TYPE_STUB_DECL (type)
14806 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
14807 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
14808 complete = complete && should_emit_struct_debug (type, usage);
14810 if (type_die && ! complete)
14813 if (TYPE_CONTEXT (type) != NULL_TREE
14814 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
14815 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
14818 scope_die = scope_die_for (type, context_die);
14820 if (! type_die || (nested && scope_die == comp_unit_die))
14821 /* First occurrence of type or toplevel definition of nested class. */
14823 dw_die_ref old_die = type_die;
14825 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
14826 ? record_type_tag (type) : DW_TAG_union_type,
14828 equate_type_number_to_die (type, type_die);
14830 add_AT_specification (type_die, old_die);
14832 add_name_attribute (type_die, type_tag (type));
14835 remove_AT (type_die, DW_AT_declaration);
14837 /* If this type has been completed, then give it a byte_size attribute and
14838 then give a list of members. */
14839 if (complete && !ns_decl)
14841 /* Prevent infinite recursion in cases where the type of some member of
14842 this type is expressed in terms of this type itself. */
14843 TREE_ASM_WRITTEN (type) = 1;
14844 add_byte_size_attribute (type_die, type);
14845 if (TYPE_STUB_DECL (type) != NULL_TREE)
14846 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
14848 /* If the first reference to this type was as the return type of an
14849 inline function, then it may not have a parent. Fix this now. */
14850 if (type_die->die_parent == NULL)
14851 add_child_die (scope_die, type_die);
14853 push_decl_scope (type);
14854 gen_member_die (type, type_die);
14857 /* GNU extension: Record what type our vtable lives in. */
14858 if (TYPE_VFIELD (type))
14860 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
14862 gen_type_die (vtype, context_die);
14863 add_AT_die_ref (type_die, DW_AT_containing_type,
14864 lookup_type_die (vtype));
14869 add_AT_flag (type_die, DW_AT_declaration, 1);
14871 /* We don't need to do this for function-local types. */
14872 if (TYPE_STUB_DECL (type)
14873 && ! decl_function_context (TYPE_STUB_DECL (type)))
14874 VEC_safe_push (tree, gc, incomplete_types, type);
14877 if (get_AT (type_die, DW_AT_name))
14878 add_pubtype (type, type_die);
14881 /* Generate a DIE for a subroutine _type_. */
14884 gen_subroutine_type_die (tree type, dw_die_ref context_die)
14886 tree return_type = TREE_TYPE (type);
14887 dw_die_ref subr_die
14888 = new_die (DW_TAG_subroutine_type,
14889 scope_die_for (type, context_die), type);
14891 equate_type_number_to_die (type, subr_die);
14892 add_prototyped_attribute (subr_die, type);
14893 add_type_attribute (subr_die, return_type, 0, 0, context_die);
14894 gen_formal_types_die (type, subr_die);
14896 if (get_AT (subr_die, DW_AT_name))
14897 add_pubtype (type, subr_die);
14900 /* Generate a DIE for a type definition. */
14903 gen_typedef_die (tree decl, dw_die_ref context_die)
14905 dw_die_ref type_die;
14908 if (TREE_ASM_WRITTEN (decl))
14911 TREE_ASM_WRITTEN (decl) = 1;
14912 type_die = new_die (DW_TAG_typedef, context_die, decl);
14913 origin = decl_ultimate_origin (decl);
14914 if (origin != NULL)
14915 add_abstract_origin_attribute (type_die, origin);
14920 add_name_and_src_coords_attributes (type_die, decl);
14921 if (DECL_ORIGINAL_TYPE (decl))
14923 type = DECL_ORIGINAL_TYPE (decl);
14925 gcc_assert (type != TREE_TYPE (decl));
14926 equate_type_number_to_die (TREE_TYPE (decl), type_die);
14929 type = TREE_TYPE (decl);
14931 add_type_attribute (type_die, type, TREE_READONLY (decl),
14932 TREE_THIS_VOLATILE (decl), context_die);
14935 if (DECL_ABSTRACT (decl))
14936 equate_decl_number_to_die (decl, type_die);
14938 if (get_AT (type_die, DW_AT_name))
14939 add_pubtype (decl, type_die);
14942 /* Generate a type description DIE. */
14945 gen_type_die_with_usage (tree type, dw_die_ref context_die,
14946 enum debug_info_usage usage)
14949 struct array_descr_info info;
14951 if (type == NULL_TREE || type == error_mark_node)
14954 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
14955 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
14957 if (TREE_ASM_WRITTEN (type))
14960 /* Prevent broken recursion; we can't hand off to the same type. */
14961 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
14963 /* Use the DIE of the containing namespace as the parent DIE of
14964 the type description DIE we want to generate. */
14965 if (DECL_CONTEXT (TYPE_NAME (type))
14966 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
14967 context_die = lookup_decl_die (DECL_CONTEXT (TYPE_NAME (type)));
14969 TREE_ASM_WRITTEN (type) = 1;
14970 gen_decl_die (TYPE_NAME (type), NULL, context_die);
14974 /* If this is an array type with hidden descriptor, handle it first. */
14975 if (!TREE_ASM_WRITTEN (type)
14976 && lang_hooks.types.get_array_descr_info
14977 && lang_hooks.types.get_array_descr_info (type, &info))
14979 gen_descr_array_type_die (type, &info, context_die);
14980 TREE_ASM_WRITTEN (type) = 1;
14984 /* We are going to output a DIE to represent the unqualified version
14985 of this type (i.e. without any const or volatile qualifiers) so
14986 get the main variant (i.e. the unqualified version) of this type
14987 now. (Vectors are special because the debugging info is in the
14988 cloned type itself). */
14989 if (TREE_CODE (type) != VECTOR_TYPE)
14990 type = type_main_variant (type);
14992 if (TREE_ASM_WRITTEN (type))
14995 switch (TREE_CODE (type))
15001 case REFERENCE_TYPE:
15002 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
15003 ensures that the gen_type_die recursion will terminate even if the
15004 type is recursive. Recursive types are possible in Ada. */
15005 /* ??? We could perhaps do this for all types before the switch
15007 TREE_ASM_WRITTEN (type) = 1;
15009 /* For these types, all that is required is that we output a DIE (or a
15010 set of DIEs) to represent the "basis" type. */
15011 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15012 DINFO_USAGE_IND_USE);
15016 /* This code is used for C++ pointer-to-data-member types.
15017 Output a description of the relevant class type. */
15018 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
15019 DINFO_USAGE_IND_USE);
15021 /* Output a description of the type of the object pointed to. */
15022 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15023 DINFO_USAGE_IND_USE);
15025 /* Now output a DIE to represent this pointer-to-data-member type
15027 gen_ptr_to_mbr_type_die (type, context_die);
15030 case FUNCTION_TYPE:
15031 /* Force out return type (in case it wasn't forced out already). */
15032 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15033 DINFO_USAGE_DIR_USE);
15034 gen_subroutine_type_die (type, context_die);
15038 /* Force out return type (in case it wasn't forced out already). */
15039 gen_type_die_with_usage (TREE_TYPE (type), context_die,
15040 DINFO_USAGE_DIR_USE);
15041 gen_subroutine_type_die (type, context_die);
15045 gen_array_type_die (type, context_die);
15049 gen_array_type_die (type, context_die);
15052 case ENUMERAL_TYPE:
15055 case QUAL_UNION_TYPE:
15056 /* If this is a nested type whose containing class hasn't been written
15057 out yet, writing it out will cover this one, too. This does not apply
15058 to instantiations of member class templates; they need to be added to
15059 the containing class as they are generated. FIXME: This hurts the
15060 idea of combining type decls from multiple TUs, since we can't predict
15061 what set of template instantiations we'll get. */
15062 if (TYPE_CONTEXT (type)
15063 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
15064 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
15066 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
15068 if (TREE_ASM_WRITTEN (type))
15071 /* If that failed, attach ourselves to the stub. */
15072 push_decl_scope (TYPE_CONTEXT (type));
15073 context_die = lookup_type_die (TYPE_CONTEXT (type));
15078 context_die = declare_in_namespace (type, context_die);
15082 if (TREE_CODE (type) == ENUMERAL_TYPE)
15084 /* This might have been written out by the call to
15085 declare_in_namespace. */
15086 if (!TREE_ASM_WRITTEN (type))
15087 gen_enumeration_type_die (type, context_die);
15090 gen_struct_or_union_type_die (type, context_die, usage);
15095 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
15096 it up if it is ever completed. gen_*_type_die will set it for us
15097 when appropriate. */
15103 case FIXED_POINT_TYPE:
15106 /* No DIEs needed for fundamental types. */
15110 /* No Dwarf representation currently defined. */
15114 gcc_unreachable ();
15117 TREE_ASM_WRITTEN (type) = 1;
15121 gen_type_die (tree type, dw_die_ref context_die)
15123 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
15126 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
15127 things which are local to the given block. */
15130 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
15132 int must_output_die = 0;
15135 /* Ignore blocks that are NULL. */
15136 if (stmt == NULL_TREE)
15139 inlined_func = inlined_function_outer_scope_p (stmt);
15141 /* If the block is one fragment of a non-contiguous block, do not
15142 process the variables, since they will have been done by the
15143 origin block. Do process subblocks. */
15144 if (BLOCK_FRAGMENT_ORIGIN (stmt))
15148 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
15149 gen_block_die (sub, context_die, depth + 1);
15154 /* Determine if we need to output any Dwarf DIEs at all to represent this
15157 /* The outer scopes for inlinings *must* always be represented. We
15158 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
15159 must_output_die = 1;
15162 /* Determine if this block directly contains any "significant"
15163 local declarations which we will need to output DIEs for. */
15164 if (debug_info_level > DINFO_LEVEL_TERSE)
15165 /* We are not in terse mode so *any* local declaration counts
15166 as being a "significant" one. */
15167 must_output_die = ((BLOCK_VARS (stmt) != NULL
15168 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
15169 && (TREE_USED (stmt)
15170 || TREE_ASM_WRITTEN (stmt)
15171 || BLOCK_ABSTRACT (stmt)));
15172 else if ((TREE_USED (stmt)
15173 || TREE_ASM_WRITTEN (stmt)
15174 || BLOCK_ABSTRACT (stmt))
15175 && !dwarf2out_ignore_block (stmt))
15176 must_output_die = 1;
15179 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
15180 DIE for any block which contains no significant local declarations at
15181 all. Rather, in such cases we just call `decls_for_scope' so that any
15182 needed Dwarf info for any sub-blocks will get properly generated. Note
15183 that in terse mode, our definition of what constitutes a "significant"
15184 local declaration gets restricted to include only inlined function
15185 instances and local (nested) function definitions. */
15186 if (must_output_die)
15189 gen_inlined_subroutine_die (stmt, context_die, depth);
15191 gen_lexical_block_die (stmt, context_die, depth);
15194 decls_for_scope (stmt, context_die, depth);
15197 /* Process variable DECL (or variable with origin ORIGIN) within
15198 block STMT and add it to CONTEXT_DIE. */
15200 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
15203 tree decl_or_origin = decl ? decl : origin;
15204 tree ultimate_origin = origin ? decl_ultimate_origin (origin) : NULL;
15206 if (ultimate_origin)
15207 origin = ultimate_origin;
15209 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
15210 die = lookup_decl_die (decl_or_origin);
15211 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
15212 && TYPE_DECL_IS_STUB (decl_or_origin))
15213 die = lookup_type_die (TREE_TYPE (decl_or_origin));
15217 if (die != NULL && die->die_parent == NULL)
15218 add_child_die (context_die, die);
15219 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
15220 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
15221 stmt, context_die);
15223 gen_decl_die (decl, origin, context_die);
15226 /* Generate all of the decls declared within a given scope and (recursively)
15227 all of its sub-blocks. */
15230 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
15236 /* Ignore NULL blocks. */
15237 if (stmt == NULL_TREE)
15240 /* Output the DIEs to represent all of the data objects and typedefs
15241 declared directly within this block but not within any nested
15242 sub-blocks. Also, nested function and tag DIEs have been
15243 generated with a parent of NULL; fix that up now. */
15244 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
15245 process_scope_var (stmt, decl, NULL_TREE, context_die);
15246 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
15247 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
15250 /* If we're at -g1, we're not interested in subblocks. */
15251 if (debug_info_level <= DINFO_LEVEL_TERSE)
15254 /* Output the DIEs to represent all sub-blocks (and the items declared
15255 therein) of this block. */
15256 for (subblocks = BLOCK_SUBBLOCKS (stmt);
15258 subblocks = BLOCK_CHAIN (subblocks))
15259 gen_block_die (subblocks, context_die, depth + 1);
15262 /* Is this a typedef we can avoid emitting? */
15265 is_redundant_typedef (const_tree decl)
15267 if (TYPE_DECL_IS_STUB (decl))
15270 if (DECL_ARTIFICIAL (decl)
15271 && DECL_CONTEXT (decl)
15272 && is_tagged_type (DECL_CONTEXT (decl))
15273 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
15274 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
15275 /* Also ignore the artificial member typedef for the class name. */
15281 /* Returns the DIE for a context. */
15283 static inline dw_die_ref
15284 get_context_die (tree context)
15288 /* Find die that represents this context. */
15289 if (TYPE_P (context))
15290 return force_type_die (context);
15292 return force_decl_die (context);
15294 return comp_unit_die;
15297 /* Returns the DIE for decl. A DIE will always be returned. */
15300 force_decl_die (tree decl)
15302 dw_die_ref decl_die;
15303 unsigned saved_external_flag;
15304 tree save_fn = NULL_TREE;
15305 decl_die = lookup_decl_die (decl);
15308 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
15310 decl_die = lookup_decl_die (decl);
15314 switch (TREE_CODE (decl))
15316 case FUNCTION_DECL:
15317 /* Clear current_function_decl, so that gen_subprogram_die thinks
15318 that this is a declaration. At this point, we just want to force
15319 declaration die. */
15320 save_fn = current_function_decl;
15321 current_function_decl = NULL_TREE;
15322 gen_subprogram_die (decl, context_die);
15323 current_function_decl = save_fn;
15327 /* Set external flag to force declaration die. Restore it after
15328 gen_decl_die() call. */
15329 saved_external_flag = DECL_EXTERNAL (decl);
15330 DECL_EXTERNAL (decl) = 1;
15331 gen_decl_die (decl, NULL, context_die);
15332 DECL_EXTERNAL (decl) = saved_external_flag;
15335 case NAMESPACE_DECL:
15336 dwarf2out_decl (decl);
15340 gcc_unreachable ();
15343 /* We should be able to find the DIE now. */
15345 decl_die = lookup_decl_die (decl);
15346 gcc_assert (decl_die);
15352 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
15353 always returned. */
15356 force_type_die (tree type)
15358 dw_die_ref type_die;
15360 type_die = lookup_type_die (type);
15363 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
15365 type_die = modified_type_die (type, TYPE_READONLY (type),
15366 TYPE_VOLATILE (type), context_die);
15367 gcc_assert (type_die);
15372 /* Force out any required namespaces to be able to output DECL,
15373 and return the new context_die for it, if it's changed. */
15376 setup_namespace_context (tree thing, dw_die_ref context_die)
15378 tree context = (DECL_P (thing)
15379 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
15380 if (context && TREE_CODE (context) == NAMESPACE_DECL)
15381 /* Force out the namespace. */
15382 context_die = force_decl_die (context);
15384 return context_die;
15387 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
15388 type) within its namespace, if appropriate.
15390 For compatibility with older debuggers, namespace DIEs only contain
15391 declarations; all definitions are emitted at CU scope. */
15394 declare_in_namespace (tree thing, dw_die_ref context_die)
15396 dw_die_ref ns_context;
15398 if (debug_info_level <= DINFO_LEVEL_TERSE)
15399 return context_die;
15401 /* If this decl is from an inlined function, then don't try to emit it in its
15402 namespace, as we will get confused. It would have already been emitted
15403 when the abstract instance of the inline function was emitted anyways. */
15404 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
15405 return context_die;
15407 ns_context = setup_namespace_context (thing, context_die);
15409 if (ns_context != context_die)
15413 if (DECL_P (thing))
15414 gen_decl_die (thing, NULL, ns_context);
15416 gen_type_die (thing, ns_context);
15418 return context_die;
15421 /* Generate a DIE for a namespace or namespace alias. */
15424 gen_namespace_die (tree decl, dw_die_ref context_die)
15426 dw_die_ref namespace_die;
15428 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
15429 they are an alias of. */
15430 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
15432 /* Output a real namespace or module. */
15433 context_die = setup_namespace_context (decl, comp_unit_die);
15434 namespace_die = new_die (is_fortran ()
15435 ? DW_TAG_module : DW_TAG_namespace,
15436 context_die, decl);
15437 /* For Fortran modules defined in different CU don't add src coords. */
15438 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
15439 add_name_attribute (namespace_die, dwarf2_name (decl, 0));
15441 add_name_and_src_coords_attributes (namespace_die, decl);
15442 if (DECL_EXTERNAL (decl))
15443 add_AT_flag (namespace_die, DW_AT_declaration, 1);
15444 equate_decl_number_to_die (decl, namespace_die);
15448 /* Output a namespace alias. */
15450 /* Force out the namespace we are an alias of, if necessary. */
15451 dw_die_ref origin_die
15452 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
15454 if (DECL_CONTEXT (decl) == NULL_TREE
15455 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
15456 context_die = setup_namespace_context (decl, comp_unit_die);
15457 /* Now create the namespace alias DIE. */
15458 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
15459 add_name_and_src_coords_attributes (namespace_die, decl);
15460 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
15461 equate_decl_number_to_die (decl, namespace_die);
15465 /* Generate Dwarf debug information for a decl described by DECL. */
15468 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
15470 tree decl_or_origin = decl ? decl : origin;
15471 tree class_origin = NULL;
15473 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
15476 switch (TREE_CODE (decl_or_origin))
15482 if (!is_fortran ())
15484 /* The individual enumerators of an enum type get output when we output
15485 the Dwarf representation of the relevant enum type itself. */
15489 /* Emit its type. */
15490 gen_type_die (TREE_TYPE (decl), context_die);
15492 /* And its containing namespace. */
15493 context_die = declare_in_namespace (decl, context_die);
15495 gen_const_die (decl, context_die);
15498 case FUNCTION_DECL:
15499 /* Don't output any DIEs to represent mere function declarations,
15500 unless they are class members or explicit block externs. */
15501 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
15502 && DECL_CONTEXT (decl_or_origin) == NULL_TREE
15503 && (current_function_decl == NULL_TREE
15504 || DECL_ARTIFICIAL (decl_or_origin)))
15509 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
15510 on local redeclarations of global functions. That seems broken. */
15511 if (current_function_decl != decl)
15512 /* This is only a declaration. */;
15515 /* If we're emitting a clone, emit info for the abstract instance. */
15516 if (origin || DECL_ORIGIN (decl) != decl)
15517 dwarf2out_abstract_function (origin ? origin : DECL_ABSTRACT_ORIGIN (decl));
15519 /* If we're emitting an out-of-line copy of an inline function,
15520 emit info for the abstract instance and set up to refer to it. */
15521 else if (cgraph_function_possibly_inlined_p (decl)
15522 && ! DECL_ABSTRACT (decl)
15523 && ! class_or_namespace_scope_p (context_die)
15524 /* dwarf2out_abstract_function won't emit a die if this is just
15525 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
15526 that case, because that works only if we have a die. */
15527 && DECL_INITIAL (decl) != NULL_TREE)
15529 dwarf2out_abstract_function (decl);
15530 set_decl_origin_self (decl);
15533 /* Otherwise we're emitting the primary DIE for this decl. */
15534 else if (debug_info_level > DINFO_LEVEL_TERSE)
15536 /* Before we describe the FUNCTION_DECL itself, make sure that we
15537 have described its return type. */
15538 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
15540 /* And its virtual context. */
15541 if (DECL_VINDEX (decl) != NULL_TREE)
15542 gen_type_die (DECL_CONTEXT (decl), context_die);
15544 /* And its containing type. */
15546 origin = decl_class_context (decl);
15547 if (origin != NULL_TREE)
15548 gen_type_die_for_member (origin, decl, context_die);
15550 /* And its containing namespace. */
15551 context_die = declare_in_namespace (decl, context_die);
15554 /* Now output a DIE to represent the function itself. */
15556 gen_subprogram_die (decl, context_die);
15560 /* If we are in terse mode, don't generate any DIEs to represent any
15561 actual typedefs. */
15562 if (debug_info_level <= DINFO_LEVEL_TERSE)
15565 /* In the special case of a TYPE_DECL node representing the declaration
15566 of some type tag, if the given TYPE_DECL is marked as having been
15567 instantiated from some other (original) TYPE_DECL node (e.g. one which
15568 was generated within the original definition of an inline function) we
15569 used to generate a special (abbreviated) DW_TAG_structure_type,
15570 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
15571 should be actually referencing those DIEs, as variable DIEs with that
15572 type would be emitted already in the abstract origin, so it was always
15573 removed during unused type prunning. Don't add anything in this
15575 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
15578 if (is_redundant_typedef (decl))
15579 gen_type_die (TREE_TYPE (decl), context_die);
15581 /* Output a DIE to represent the typedef itself. */
15582 gen_typedef_die (decl, context_die);
15586 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15587 gen_label_die (decl, context_die);
15592 /* If we are in terse mode, don't generate any DIEs to represent any
15593 variable declarations or definitions. */
15594 if (debug_info_level <= DINFO_LEVEL_TERSE)
15597 /* Output any DIEs that are needed to specify the type of this data
15599 if ((TREE_CODE (decl_or_origin) == RESULT_DECL
15600 || TREE_CODE (decl_or_origin) == VAR_DECL)
15601 && DECL_BY_REFERENCE (decl_or_origin))
15602 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15604 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15606 /* And its containing type. */
15607 class_origin = decl_class_context (decl_or_origin);
15608 if (class_origin != NULL_TREE)
15609 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
15611 /* And its containing namespace. */
15612 context_die = declare_in_namespace (decl_or_origin, context_die);
15614 /* Now output the DIE to represent the data object itself. This gets
15615 complicated because of the possibility that the VAR_DECL really
15616 represents an inlined instance of a formal parameter for an inline
15619 origin = decl_ultimate_origin (decl);
15620 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
15621 gen_formal_parameter_die (decl, origin, context_die);
15623 gen_variable_die (decl, origin, context_die);
15627 /* Ignore the nameless fields that are used to skip bits but handle C++
15628 anonymous unions and structs. */
15629 if (DECL_NAME (decl) != NULL_TREE
15630 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
15631 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
15633 gen_type_die (member_declared_type (decl), context_die);
15634 gen_field_die (decl, context_die);
15639 if (DECL_BY_REFERENCE (decl_or_origin))
15640 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
15642 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
15643 gen_formal_parameter_die (decl, origin, context_die);
15646 case NAMESPACE_DECL:
15647 case IMPORTED_DECL:
15648 gen_namespace_die (decl, context_die);
15652 /* Probably some frontend-internal decl. Assume we don't care. */
15653 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
15658 /* Output debug information for global decl DECL. Called from toplev.c after
15659 compilation proper has finished. */
15662 dwarf2out_global_decl (tree decl)
15664 /* Output DWARF2 information for file-scope tentative data object
15665 declarations, file-scope (extern) function declarations (which
15666 had no corresponding body) and file-scope tagged type declarations
15667 and definitions which have not yet been forced out. */
15668 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
15669 dwarf2out_decl (decl);
15672 /* Output debug information for type decl DECL. Called from toplev.c
15673 and from language front ends (to record built-in types). */
15675 dwarf2out_type_decl (tree decl, int local)
15678 dwarf2out_decl (decl);
15681 /* Output debug information for imported module or decl DECL.
15682 NAME is non-NULL name in the lexical block if the decl has been renamed.
15683 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
15684 that DECL belongs to.
15685 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
15687 dwarf2out_imported_module_or_decl_1 (tree decl,
15689 tree lexical_block,
15690 dw_die_ref lexical_block_die)
15692 expanded_location xloc;
15693 dw_die_ref imported_die = NULL;
15694 dw_die_ref at_import_die;
15696 if (TREE_CODE (decl) == IMPORTED_DECL)
15698 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
15699 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
15703 xloc = expand_location (input_location);
15705 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
15707 if (is_base_type (TREE_TYPE (decl)))
15708 at_import_die = base_type_die (TREE_TYPE (decl));
15710 at_import_die = force_type_die (TREE_TYPE (decl));
15711 /* For namespace N { typedef void T; } using N::T; base_type_die
15712 returns NULL, but DW_TAG_imported_declaration requires
15713 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
15714 if (!at_import_die)
15716 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
15717 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
15718 at_import_die = lookup_type_die (TREE_TYPE (decl));
15719 gcc_assert (at_import_die);
15724 at_import_die = lookup_decl_die (decl);
15725 if (!at_import_die)
15727 /* If we're trying to avoid duplicate debug info, we may not have
15728 emitted the member decl for this field. Emit it now. */
15729 if (TREE_CODE (decl) == FIELD_DECL)
15731 tree type = DECL_CONTEXT (decl);
15733 if (TYPE_CONTEXT (type)
15734 && TYPE_P (TYPE_CONTEXT (type))
15735 && !should_emit_struct_debug (TYPE_CONTEXT (type),
15736 DINFO_USAGE_DIR_USE))
15738 gen_type_die_for_member (type, decl,
15739 get_context_die (TYPE_CONTEXT (type)));
15741 at_import_die = force_decl_die (decl);
15745 if (TREE_CODE (decl) == NAMESPACE_DECL)
15746 imported_die = new_die (DW_TAG_imported_module,
15750 imported_die = new_die (DW_TAG_imported_declaration,
15754 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
15755 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
15757 add_AT_string (imported_die, DW_AT_name,
15758 IDENTIFIER_POINTER (name));
15759 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
15762 /* Output debug information for imported module or decl DECL.
15763 NAME is non-NULL name in context if the decl has been renamed.
15764 CHILD is true if decl is one of the renamed decls as part of
15765 importing whole module. */
15768 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
15771 /* dw_die_ref at_import_die; */
15772 dw_die_ref scope_die;
15774 if (debug_info_level <= DINFO_LEVEL_TERSE)
15779 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
15780 We need decl DIE for reference and scope die. First, get DIE for the decl
15783 /* Get the scope die for decl context. Use comp_unit_die for global module
15784 or decl. If die is not found for non globals, force new die. */
15786 && TYPE_P (context)
15787 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
15789 scope_die = get_context_die (context);
15793 gcc_assert (scope_die->die_child);
15794 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
15795 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
15796 scope_die = scope_die->die_child;
15799 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
15800 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
15804 /* Write the debugging output for DECL. */
15807 dwarf2out_decl (tree decl)
15809 dw_die_ref context_die = comp_unit_die;
15811 switch (TREE_CODE (decl))
15816 case FUNCTION_DECL:
15817 /* What we would really like to do here is to filter out all mere
15818 file-scope declarations of file-scope functions which are never
15819 referenced later within this translation unit (and keep all of ones
15820 that *are* referenced later on) but we aren't clairvoyant, so we have
15821 no idea which functions will be referenced in the future (i.e. later
15822 on within the current translation unit). So here we just ignore all
15823 file-scope function declarations which are not also definitions. If
15824 and when the debugger needs to know something about these functions,
15825 it will have to hunt around and find the DWARF information associated
15826 with the definition of the function.
15828 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
15829 nodes represent definitions and which ones represent mere
15830 declarations. We have to check DECL_INITIAL instead. That's because
15831 the C front-end supports some weird semantics for "extern inline"
15832 function definitions. These can get inlined within the current
15833 translation unit (and thus, we need to generate Dwarf info for their
15834 abstract instances so that the Dwarf info for the concrete inlined
15835 instances can have something to refer to) but the compiler never
15836 generates any out-of-lines instances of such things (despite the fact
15837 that they *are* definitions).
15839 The important point is that the C front-end marks these "extern
15840 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
15841 them anyway. Note that the C++ front-end also plays some similar games
15842 for inline function definitions appearing within include files which
15843 also contain `#pragma interface' pragmas. */
15844 if (DECL_INITIAL (decl) == NULL_TREE)
15847 /* If we're a nested function, initially use a parent of NULL; if we're
15848 a plain function, this will be fixed up in decls_for_scope. If
15849 we're a method, it will be ignored, since we already have a DIE. */
15850 if (decl_function_context (decl)
15851 /* But if we're in terse mode, we don't care about scope. */
15852 && debug_info_level > DINFO_LEVEL_TERSE)
15853 context_die = NULL;
15857 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
15858 declaration and if the declaration was never even referenced from
15859 within this entire compilation unit. We suppress these DIEs in
15860 order to save space in the .debug section (by eliminating entries
15861 which are probably useless). Note that we must not suppress
15862 block-local extern declarations (whether used or not) because that
15863 would screw-up the debugger's name lookup mechanism and cause it to
15864 miss things which really ought to be in scope at a given point. */
15865 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
15868 /* For local statics lookup proper context die. */
15869 if (TREE_STATIC (decl) && decl_function_context (decl))
15870 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15872 /* If we are in terse mode, don't generate any DIEs to represent any
15873 variable declarations or definitions. */
15874 if (debug_info_level <= DINFO_LEVEL_TERSE)
15879 if (debug_info_level <= DINFO_LEVEL_TERSE)
15881 if (!is_fortran ())
15883 if (TREE_STATIC (decl) && decl_function_context (decl))
15884 context_die = lookup_decl_die (DECL_CONTEXT (decl));
15887 case NAMESPACE_DECL:
15888 case IMPORTED_DECL:
15889 if (debug_info_level <= DINFO_LEVEL_TERSE)
15891 if (lookup_decl_die (decl) != NULL)
15896 /* Don't emit stubs for types unless they are needed by other DIEs. */
15897 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
15900 /* Don't bother trying to generate any DIEs to represent any of the
15901 normal built-in types for the language we are compiling. */
15902 if (DECL_IS_BUILTIN (decl))
15904 /* OK, we need to generate one for `bool' so GDB knows what type
15905 comparisons have. */
15907 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
15908 && ! DECL_IGNORED_P (decl))
15909 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
15914 /* If we are in terse mode, don't generate any DIEs for types. */
15915 if (debug_info_level <= DINFO_LEVEL_TERSE)
15918 /* If we're a function-scope tag, initially use a parent of NULL;
15919 this will be fixed up in decls_for_scope. */
15920 if (decl_function_context (decl))
15921 context_die = NULL;
15929 gen_decl_die (decl, NULL, context_die);
15932 /* Output a marker (i.e. a label) for the beginning of the generated code for
15933 a lexical block. */
15936 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
15937 unsigned int blocknum)
15939 switch_to_section (current_function_section ());
15940 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
15943 /* Output a marker (i.e. a label) for the end of the generated code for a
15947 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
15949 switch_to_section (current_function_section ());
15950 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
15953 /* Returns nonzero if it is appropriate not to emit any debugging
15954 information for BLOCK, because it doesn't contain any instructions.
15956 Don't allow this for blocks with nested functions or local classes
15957 as we would end up with orphans, and in the presence of scheduling
15958 we may end up calling them anyway. */
15961 dwarf2out_ignore_block (const_tree block)
15966 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
15967 if (TREE_CODE (decl) == FUNCTION_DECL
15968 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15970 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
15972 decl = BLOCK_NONLOCALIZED_VAR (block, i);
15973 if (TREE_CODE (decl) == FUNCTION_DECL
15974 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
15981 /* Hash table routines for file_hash. */
15984 file_table_eq (const void *p1_p, const void *p2_p)
15986 const struct dwarf_file_data *const p1 =
15987 (const struct dwarf_file_data *) p1_p;
15988 const char *const p2 = (const char *) p2_p;
15989 return strcmp (p1->filename, p2) == 0;
15993 file_table_hash (const void *p_p)
15995 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
15996 return htab_hash_string (p->filename);
15999 /* Lookup FILE_NAME (in the list of filenames that we know about here in
16000 dwarf2out.c) and return its "index". The index of each (known) filename is
16001 just a unique number which is associated with only that one filename. We
16002 need such numbers for the sake of generating labels (in the .debug_sfnames
16003 section) and references to those files numbers (in the .debug_srcinfo
16004 and.debug_macinfo sections). If the filename given as an argument is not
16005 found in our current list, add it to the list and assign it the next
16006 available unique index number. In order to speed up searches, we remember
16007 the index of the filename was looked up last. This handles the majority of
16010 static struct dwarf_file_data *
16011 lookup_filename (const char *file_name)
16014 struct dwarf_file_data * created;
16016 /* Check to see if the file name that was searched on the previous
16017 call matches this file name. If so, return the index. */
16018 if (file_table_last_lookup
16019 && (file_name == file_table_last_lookup->filename
16020 || strcmp (file_table_last_lookup->filename, file_name) == 0))
16021 return file_table_last_lookup;
16023 /* Didn't match the previous lookup, search the table. */
16024 slot = htab_find_slot_with_hash (file_table, file_name,
16025 htab_hash_string (file_name), INSERT);
16027 return (struct dwarf_file_data *) *slot;
16029 created = GGC_NEW (struct dwarf_file_data);
16030 created->filename = file_name;
16031 created->emitted_number = 0;
16036 /* If the assembler will construct the file table, then translate the compiler
16037 internal file table number into the assembler file table number, and emit
16038 a .file directive if we haven't already emitted one yet. The file table
16039 numbers are different because we prune debug info for unused variables and
16040 types, which may include filenames. */
16043 maybe_emit_file (struct dwarf_file_data * fd)
16045 if (! fd->emitted_number)
16047 if (last_emitted_file)
16048 fd->emitted_number = last_emitted_file->emitted_number + 1;
16050 fd->emitted_number = 1;
16051 last_emitted_file = fd;
16053 if (DWARF2_ASM_LINE_DEBUG_INFO)
16055 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
16056 output_quoted_string (asm_out_file,
16057 remap_debug_filename (fd->filename));
16058 fputc ('\n', asm_out_file);
16062 return fd->emitted_number;
16065 /* Replace DW_AT_name for the decl with name. */
16068 dwarf2out_set_name (tree decl, tree name)
16073 die = TYPE_SYMTAB_DIE (decl);
16077 attr = get_AT (die, DW_AT_name);
16080 struct indirect_string_node *node;
16082 node = find_AT_string (dwarf2_name (name, 0));
16083 /* replace the string. */
16084 attr->dw_attr_val.v.val_str = node;
16088 add_name_attribute (die, dwarf2_name (name, 0));
16090 /* Called by the final INSN scan whenever we see a var location. We
16091 use it to drop labels in the right places, and throw the location in
16092 our lookup table. */
16095 dwarf2out_var_location (rtx loc_note)
16097 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
16098 struct var_loc_node *newloc;
16100 static rtx last_insn;
16101 static const char *last_label;
16104 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
16106 prev_insn = PREV_INSN (loc_note);
16108 newloc = GGC_CNEW (struct var_loc_node);
16109 /* If the insn we processed last time is the previous insn
16110 and it is also a var location note, use the label we emitted
16112 if (last_insn != NULL_RTX
16113 && last_insn == prev_insn
16114 && NOTE_P (prev_insn)
16115 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
16117 newloc->label = last_label;
16121 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
16122 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
16124 newloc->label = ggc_strdup (loclabel);
16126 newloc->var_loc_note = loc_note;
16127 newloc->next = NULL;
16129 if (cfun && in_cold_section_p)
16130 newloc->section_label = crtl->subsections.cold_section_label;
16132 newloc->section_label = text_section_label;
16134 last_insn = loc_note;
16135 last_label = newloc->label;
16136 decl = NOTE_VAR_LOCATION_DECL (loc_note);
16137 add_var_loc_to_decl (decl, newloc);
16140 /* We need to reset the locations at the beginning of each
16141 function. We can't do this in the end_function hook, because the
16142 declarations that use the locations won't have been output when
16143 that hook is called. Also compute have_multiple_function_sections here. */
16146 dwarf2out_begin_function (tree fun)
16148 htab_empty (decl_loc_table);
16150 if (function_section (fun) != text_section)
16151 have_multiple_function_sections = true;
16153 dwarf2out_note_section_used ();
16156 /* Output a label to mark the beginning of a source code line entry
16157 and record information relating to this source line, in
16158 'line_info_table' for later output of the .debug_line section. */
16161 dwarf2out_source_line (unsigned int line, const char *filename)
16163 if (debug_info_level >= DINFO_LEVEL_NORMAL
16166 int file_num = maybe_emit_file (lookup_filename (filename));
16168 switch_to_section (current_function_section ());
16170 /* If requested, emit something human-readable. */
16171 if (flag_debug_asm)
16172 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
16175 if (DWARF2_ASM_LINE_DEBUG_INFO)
16177 /* Emit the .loc directive understood by GNU as. */
16178 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
16180 /* Indicate that line number info exists. */
16181 line_info_table_in_use++;
16183 else if (function_section (current_function_decl) != text_section)
16185 dw_separate_line_info_ref line_info;
16186 targetm.asm_out.internal_label (asm_out_file,
16187 SEPARATE_LINE_CODE_LABEL,
16188 separate_line_info_table_in_use);
16190 /* Expand the line info table if necessary. */
16191 if (separate_line_info_table_in_use
16192 == separate_line_info_table_allocated)
16194 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16195 separate_line_info_table
16196 = GGC_RESIZEVEC (dw_separate_line_info_entry,
16197 separate_line_info_table,
16198 separate_line_info_table_allocated);
16199 memset (separate_line_info_table
16200 + separate_line_info_table_in_use,
16202 (LINE_INFO_TABLE_INCREMENT
16203 * sizeof (dw_separate_line_info_entry)));
16206 /* Add the new entry at the end of the line_info_table. */
16208 = &separate_line_info_table[separate_line_info_table_in_use++];
16209 line_info->dw_file_num = file_num;
16210 line_info->dw_line_num = line;
16211 line_info->function = current_function_funcdef_no;
16215 dw_line_info_ref line_info;
16217 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
16218 line_info_table_in_use);
16220 /* Expand the line info table if necessary. */
16221 if (line_info_table_in_use == line_info_table_allocated)
16223 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
16225 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
16226 line_info_table_allocated);
16227 memset (line_info_table + line_info_table_in_use, 0,
16228 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
16231 /* Add the new entry at the end of the line_info_table. */
16232 line_info = &line_info_table[line_info_table_in_use++];
16233 line_info->dw_file_num = file_num;
16234 line_info->dw_line_num = line;
16239 /* Record the beginning of a new source file. */
16242 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
16244 if (flag_eliminate_dwarf2_dups)
16246 /* Record the beginning of the file for break_out_includes. */
16247 dw_die_ref bincl_die;
16249 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
16250 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
16253 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16255 int file_num = maybe_emit_file (lookup_filename (filename));
16257 switch_to_section (debug_macinfo_section);
16258 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
16259 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
16262 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
16266 /* Record the end of a source file. */
16269 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
16271 if (flag_eliminate_dwarf2_dups)
16272 /* Record the end of the file for break_out_includes. */
16273 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
16275 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16277 switch_to_section (debug_macinfo_section);
16278 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
16282 /* Called from debug_define in toplev.c. The `buffer' parameter contains
16283 the tail part of the directive line, i.e. the part which is past the
16284 initial whitespace, #, whitespace, directive-name, whitespace part. */
16287 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
16288 const char *buffer ATTRIBUTE_UNUSED)
16290 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16292 switch_to_section (debug_macinfo_section);
16293 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
16294 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16295 dw2_asm_output_nstring (buffer, -1, "The macro");
16299 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
16300 the tail part of the directive line, i.e. the part which is past the
16301 initial whitespace, #, whitespace, directive-name, whitespace part. */
16304 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
16305 const char *buffer ATTRIBUTE_UNUSED)
16307 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16309 switch_to_section (debug_macinfo_section);
16310 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
16311 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
16312 dw2_asm_output_nstring (buffer, -1, "The macro");
16316 /* Set up for Dwarf output at the start of compilation. */
16319 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
16321 /* Allocate the file_table. */
16322 file_table = htab_create_ggc (50, file_table_hash,
16323 file_table_eq, NULL);
16325 /* Allocate the decl_die_table. */
16326 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
16327 decl_die_table_eq, NULL);
16329 /* Allocate the decl_loc_table. */
16330 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
16331 decl_loc_table_eq, NULL);
16333 /* Allocate the initial hunk of the decl_scope_table. */
16334 decl_scope_table = VEC_alloc (tree, gc, 256);
16336 /* Allocate the initial hunk of the abbrev_die_table. */
16337 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
16338 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
16339 /* Zero-th entry is allocated, but unused. */
16340 abbrev_die_table_in_use = 1;
16342 /* Allocate the initial hunk of the line_info_table. */
16343 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
16344 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
16346 /* Zero-th entry is allocated, but unused. */
16347 line_info_table_in_use = 1;
16349 /* Allocate the pubtypes and pubnames vectors. */
16350 pubname_table = VEC_alloc (pubname_entry, gc, 32);
16351 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
16353 /* Generate the initial DIE for the .debug section. Note that the (string)
16354 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
16355 will (typically) be a relative pathname and that this pathname should be
16356 taken as being relative to the directory from which the compiler was
16357 invoked when the given (base) source file was compiled. We will fill
16358 in this value in dwarf2out_finish. */
16359 comp_unit_die = gen_compile_unit_die (NULL);
16361 incomplete_types = VEC_alloc (tree, gc, 64);
16363 used_rtx_array = VEC_alloc (rtx, gc, 32);
16365 debug_info_section = get_section (DEBUG_INFO_SECTION,
16366 SECTION_DEBUG, NULL);
16367 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
16368 SECTION_DEBUG, NULL);
16369 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
16370 SECTION_DEBUG, NULL);
16371 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
16372 SECTION_DEBUG, NULL);
16373 debug_line_section = get_section (DEBUG_LINE_SECTION,
16374 SECTION_DEBUG, NULL);
16375 debug_loc_section = get_section (DEBUG_LOC_SECTION,
16376 SECTION_DEBUG, NULL);
16377 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
16378 SECTION_DEBUG, NULL);
16379 #ifdef DEBUG_PUBTYPES_SECTION
16380 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
16381 SECTION_DEBUG, NULL);
16383 debug_str_section = get_section (DEBUG_STR_SECTION,
16384 DEBUG_STR_SECTION_FLAGS, NULL);
16385 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
16386 SECTION_DEBUG, NULL);
16387 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
16388 SECTION_DEBUG, NULL);
16390 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
16391 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
16392 DEBUG_ABBREV_SECTION_LABEL, 0);
16393 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
16394 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
16395 COLD_TEXT_SECTION_LABEL, 0);
16396 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
16398 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
16399 DEBUG_INFO_SECTION_LABEL, 0);
16400 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
16401 DEBUG_LINE_SECTION_LABEL, 0);
16402 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
16403 DEBUG_RANGES_SECTION_LABEL, 0);
16404 switch_to_section (debug_abbrev_section);
16405 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
16406 switch_to_section (debug_info_section);
16407 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
16408 switch_to_section (debug_line_section);
16409 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
16411 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16413 switch_to_section (debug_macinfo_section);
16414 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
16415 DEBUG_MACINFO_SECTION_LABEL, 0);
16416 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
16419 switch_to_section (text_section);
16420 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
16421 if (flag_reorder_blocks_and_partition)
16423 cold_text_section = unlikely_text_section ();
16424 switch_to_section (cold_text_section);
16425 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
16429 /* A helper function for dwarf2out_finish called through
16430 ht_forall. Emit one queued .debug_str string. */
16433 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
16435 struct indirect_string_node *node = (struct indirect_string_node *) *h;
16437 if (node->form == DW_FORM_strp)
16439 switch_to_section (debug_str_section);
16440 ASM_OUTPUT_LABEL (asm_out_file, node->label);
16441 assemble_string (node->str, strlen (node->str) + 1);
16447 #if ENABLE_ASSERT_CHECKING
16448 /* Verify that all marks are clear. */
16451 verify_marks_clear (dw_die_ref die)
16455 gcc_assert (! die->die_mark);
16456 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
16458 #endif /* ENABLE_ASSERT_CHECKING */
16460 /* Clear the marks for a die and its children.
16461 Be cool if the mark isn't set. */
16464 prune_unmark_dies (dw_die_ref die)
16470 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
16473 /* Given DIE that we're marking as used, find any other dies
16474 it references as attributes and mark them as used. */
16477 prune_unused_types_walk_attribs (dw_die_ref die)
16482 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16484 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
16486 /* A reference to another DIE.
16487 Make sure that it will get emitted. */
16488 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
16490 /* Set the string's refcount to 0 so that prune_unused_types_mark
16491 accounts properly for it. */
16492 if (AT_class (a) == dw_val_class_str)
16493 a->dw_attr_val.v.val_str->refcount = 0;
16498 /* Mark DIE as being used. If DOKIDS is true, then walk down
16499 to DIE's children. */
16502 prune_unused_types_mark (dw_die_ref die, int dokids)
16506 if (die->die_mark == 0)
16508 /* We haven't done this node yet. Mark it as used. */
16511 /* We also have to mark its parents as used.
16512 (But we don't want to mark our parents' kids due to this.) */
16513 if (die->die_parent)
16514 prune_unused_types_mark (die->die_parent, 0);
16516 /* Mark any referenced nodes. */
16517 prune_unused_types_walk_attribs (die);
16519 /* If this node is a specification,
16520 also mark the definition, if it exists. */
16521 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
16522 prune_unused_types_mark (die->die_definition, 1);
16525 if (dokids && die->die_mark != 2)
16527 /* We need to walk the children, but haven't done so yet.
16528 Remember that we've walked the kids. */
16531 /* If this is an array type, we need to make sure our
16532 kids get marked, even if they're types. */
16533 if (die->die_tag == DW_TAG_array_type)
16534 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
16536 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16540 /* For local classes, look if any static member functions were emitted
16541 and if so, mark them. */
16544 prune_unused_types_walk_local_classes (dw_die_ref die)
16548 if (die->die_mark == 2)
16551 switch (die->die_tag)
16553 case DW_TAG_structure_type:
16554 case DW_TAG_union_type:
16555 case DW_TAG_class_type:
16558 case DW_TAG_subprogram:
16559 if (!get_AT_flag (die, DW_AT_declaration)
16560 || die->die_definition != NULL)
16561 prune_unused_types_mark (die, 1);
16568 /* Mark children. */
16569 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
16572 /* Walk the tree DIE and mark types that we actually use. */
16575 prune_unused_types_walk (dw_die_ref die)
16579 /* Don't do anything if this node is already marked and
16580 children have been marked as well. */
16581 if (die->die_mark == 2)
16584 switch (die->die_tag)
16586 case DW_TAG_structure_type:
16587 case DW_TAG_union_type:
16588 case DW_TAG_class_type:
16589 if (die->die_perennial_p)
16592 for (c = die->die_parent; c; c = c->die_parent)
16593 if (c->die_tag == DW_TAG_subprogram)
16596 /* Finding used static member functions inside of classes
16597 is needed just for local classes, because for other classes
16598 static member function DIEs with DW_AT_specification
16599 are emitted outside of the DW_TAG_*_type. If we ever change
16600 it, we'd need to call this even for non-local classes. */
16602 prune_unused_types_walk_local_classes (die);
16604 /* It's a type node --- don't mark it. */
16607 case DW_TAG_const_type:
16608 case DW_TAG_packed_type:
16609 case DW_TAG_pointer_type:
16610 case DW_TAG_reference_type:
16611 case DW_TAG_volatile_type:
16612 case DW_TAG_typedef:
16613 case DW_TAG_array_type:
16614 case DW_TAG_interface_type:
16615 case DW_TAG_friend:
16616 case DW_TAG_variant_part:
16617 case DW_TAG_enumeration_type:
16618 case DW_TAG_subroutine_type:
16619 case DW_TAG_string_type:
16620 case DW_TAG_set_type:
16621 case DW_TAG_subrange_type:
16622 case DW_TAG_ptr_to_member_type:
16623 case DW_TAG_file_type:
16624 if (die->die_perennial_p)
16627 /* It's a type node --- don't mark it. */
16631 /* Mark everything else. */
16635 if (die->die_mark == 0)
16639 /* Now, mark any dies referenced from here. */
16640 prune_unused_types_walk_attribs (die);
16645 /* Mark children. */
16646 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
16649 /* Increment the string counts on strings referred to from DIE's
16653 prune_unused_types_update_strings (dw_die_ref die)
16658 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
16659 if (AT_class (a) == dw_val_class_str)
16661 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
16663 /* Avoid unnecessarily putting strings that are used less than
16664 twice in the hash table. */
16666 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
16669 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
16670 htab_hash_string (s->str),
16672 gcc_assert (*slot == NULL);
16678 /* Remove from the tree DIE any dies that aren't marked. */
16681 prune_unused_types_prune (dw_die_ref die)
16685 gcc_assert (die->die_mark);
16686 prune_unused_types_update_strings (die);
16688 if (! die->die_child)
16691 c = die->die_child;
16693 dw_die_ref prev = c;
16694 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
16695 if (c == die->die_child)
16697 /* No marked children between 'prev' and the end of the list. */
16699 /* No marked children at all. */
16700 die->die_child = NULL;
16703 prev->die_sib = c->die_sib;
16704 die->die_child = prev;
16709 if (c != prev->die_sib)
16711 prune_unused_types_prune (c);
16712 } while (c != die->die_child);
16716 /* Remove dies representing declarations that we never use. */
16719 prune_unused_types (void)
16722 limbo_die_node *node;
16725 #if ENABLE_ASSERT_CHECKING
16726 /* All the marks should already be clear. */
16727 verify_marks_clear (comp_unit_die);
16728 for (node = limbo_die_list; node; node = node->next)
16729 verify_marks_clear (node->die);
16730 #endif /* ENABLE_ASSERT_CHECKING */
16732 /* Set the mark on nodes that are actually used. */
16733 prune_unused_types_walk (comp_unit_die);
16734 for (node = limbo_die_list; node; node = node->next)
16735 prune_unused_types_walk (node->die);
16737 /* Also set the mark on nodes referenced from the
16738 pubname_table or arange_table. */
16739 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
16740 prune_unused_types_mark (pub->die, 1);
16741 for (i = 0; i < arange_table_in_use; i++)
16742 prune_unused_types_mark (arange_table[i], 1);
16744 /* Get rid of nodes that aren't marked; and update the string counts. */
16745 if (debug_str_hash)
16746 htab_empty (debug_str_hash);
16747 prune_unused_types_prune (comp_unit_die);
16748 for (node = limbo_die_list; node; node = node->next)
16749 prune_unused_types_prune (node->die);
16751 /* Leave the marks clear. */
16752 prune_unmark_dies (comp_unit_die);
16753 for (node = limbo_die_list; node; node = node->next)
16754 prune_unmark_dies (node->die);
16757 /* Set the parameter to true if there are any relative pathnames in
16760 file_table_relative_p (void ** slot, void *param)
16762 bool *p = (bool *) param;
16763 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
16764 if (!IS_ABSOLUTE_PATH (d->filename))
16772 /* Output stuff that dwarf requires at the end of every file,
16773 and generate the DWARF-2 debugging info. */
16776 dwarf2out_finish (const char *filename)
16778 limbo_die_node *node, *next_node;
16779 dw_die_ref die = 0;
16782 /* Add the name for the main input file now. We delayed this from
16783 dwarf2out_init to avoid complications with PCH. */
16784 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
16785 if (!IS_ABSOLUTE_PATH (filename))
16786 add_comp_dir_attribute (comp_unit_die);
16787 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
16790 htab_traverse (file_table, file_table_relative_p, &p);
16792 add_comp_dir_attribute (comp_unit_die);
16795 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
16797 add_location_or_const_value_attribute (
16798 VEC_index (deferred_locations, deferred_locations_list, i)->die,
16799 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
16803 /* Traverse the limbo die list, and add parent/child links. The only
16804 dies without parents that should be here are concrete instances of
16805 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
16806 For concrete instances, we can get the parent die from the abstract
16808 for (node = limbo_die_list; node; node = next_node)
16810 next_node = node->next;
16813 if (die->die_parent == NULL)
16815 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
16818 add_child_die (origin->die_parent, die);
16819 else if (die == comp_unit_die)
16821 else if (errorcount > 0 || sorrycount > 0)
16822 /* It's OK to be confused by errors in the input. */
16823 add_child_die (comp_unit_die, die);
16826 /* In certain situations, the lexical block containing a
16827 nested function can be optimized away, which results
16828 in the nested function die being orphaned. Likewise
16829 with the return type of that nested function. Force
16830 this to be a child of the containing function.
16832 It may happen that even the containing function got fully
16833 inlined and optimized out. In that case we are lost and
16834 assign the empty child. This should not be big issue as
16835 the function is likely unreachable too. */
16836 tree context = NULL_TREE;
16838 gcc_assert (node->created_for);
16840 if (DECL_P (node->created_for))
16841 context = DECL_CONTEXT (node->created_for);
16842 else if (TYPE_P (node->created_for))
16843 context = TYPE_CONTEXT (node->created_for);
16845 gcc_assert (context
16846 && (TREE_CODE (context) == FUNCTION_DECL
16847 || TREE_CODE (context) == NAMESPACE_DECL));
16849 origin = lookup_decl_die (context);
16851 add_child_die (origin, die);
16853 add_child_die (comp_unit_die, die);
16858 limbo_die_list = NULL;
16860 /* Walk through the list of incomplete types again, trying once more to
16861 emit full debugging info for them. */
16862 retry_incomplete_types ();
16864 if (flag_eliminate_unused_debug_types)
16865 prune_unused_types ();
16867 /* Generate separate CUs for each of the include files we've seen.
16868 They will go into limbo_die_list. */
16869 if (flag_eliminate_dwarf2_dups)
16870 break_out_includes (comp_unit_die);
16872 /* Traverse the DIE's and add add sibling attributes to those DIE's
16873 that have children. */
16874 add_sibling_attributes (comp_unit_die);
16875 for (node = limbo_die_list; node; node = node->next)
16876 add_sibling_attributes (node->die);
16878 /* Output a terminator label for the .text section. */
16879 switch_to_section (text_section);
16880 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
16881 if (flag_reorder_blocks_and_partition)
16883 switch_to_section (unlikely_text_section ());
16884 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
16887 /* We can only use the low/high_pc attributes if all of the code was
16889 if (!have_multiple_function_sections)
16891 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
16892 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
16897 unsigned fde_idx = 0;
16899 /* We need to give .debug_loc and .debug_ranges an appropriate
16900 "base address". Use zero so that these addresses become
16901 absolute. Historically, we've emitted the unexpected
16902 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
16903 Emit both to give time for other tools to adapt. */
16904 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
16905 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
16907 add_AT_range_list (comp_unit_die, DW_AT_ranges,
16908 add_ranges_by_labels (text_section_label,
16910 if (flag_reorder_blocks_and_partition)
16911 add_ranges_by_labels (cold_text_section_label,
16914 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
16916 dw_fde_ref fde = &fde_table[fde_idx];
16918 if (fde->dw_fde_switched_sections)
16920 add_ranges_by_labels (fde->dw_fde_hot_section_label,
16921 fde->dw_fde_hot_section_end_label);
16922 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
16923 fde->dw_fde_unlikely_section_end_label);
16926 add_ranges_by_labels (fde->dw_fde_begin,
16933 /* Output location list section if necessary. */
16934 if (have_location_lists)
16936 /* Output the location lists info. */
16937 switch_to_section (debug_loc_section);
16938 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
16939 DEBUG_LOC_SECTION_LABEL, 0);
16940 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
16941 output_location_lists (die);
16944 if (debug_info_level >= DINFO_LEVEL_NORMAL)
16945 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
16946 debug_line_section_label);
16948 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
16949 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
16951 /* Output all of the compilation units. We put the main one last so that
16952 the offsets are available to output_pubnames. */
16953 for (node = limbo_die_list; node; node = node->next)
16954 output_comp_unit (node->die, 0);
16956 /* Output the main compilation unit if non-empty or if .debug_macinfo
16957 has been emitted. */
16958 output_comp_unit (comp_unit_die, debug_info_level >= DINFO_LEVEL_VERBOSE);
16960 /* Output the abbreviation table. */
16961 switch_to_section (debug_abbrev_section);
16962 output_abbrev_section ();
16964 /* Output public names table if necessary. */
16965 if (!VEC_empty (pubname_entry, pubname_table))
16967 switch_to_section (debug_pubnames_section);
16968 output_pubnames (pubname_table);
16971 #ifdef DEBUG_PUBTYPES_SECTION
16972 /* Output public types table if necessary. */
16973 if (!VEC_empty (pubname_entry, pubtype_table))
16975 switch_to_section (debug_pubtypes_section);
16976 output_pubnames (pubtype_table);
16980 /* Output the address range information. We only put functions in the arange
16981 table, so don't write it out if we don't have any. */
16982 if (fde_table_in_use)
16984 switch_to_section (debug_aranges_section);
16988 /* Output ranges section if necessary. */
16989 if (ranges_table_in_use)
16991 switch_to_section (debug_ranges_section);
16992 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
16996 /* Output the source line correspondence table. We must do this
16997 even if there is no line information. Otherwise, on an empty
16998 translation unit, we will generate a present, but empty,
16999 .debug_info section. IRIX 6.5 `nm' will then complain when
17000 examining the file. This is done late so that any filenames
17001 used by the debug_info section are marked as 'used'. */
17002 if (! DWARF2_ASM_LINE_DEBUG_INFO)
17004 switch_to_section (debug_line_section);
17005 output_line_info ();
17008 /* Have to end the macro section. */
17009 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
17011 switch_to_section (debug_macinfo_section);
17012 dw2_asm_output_data (1, 0, "End compilation unit");
17015 /* If we emitted any DW_FORM_strp form attribute, output the string
17017 if (debug_str_hash)
17018 htab_traverse (debug_str_hash, output_indirect_string, NULL);
17022 /* This should never be used, but its address is needed for comparisons. */
17023 const struct gcc_debug_hooks dwarf2_debug_hooks;
17025 #endif /* DWARF2_DEBUGGING_INFO */
17027 #include "gt-dwarf2out.h"