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 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 2, 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 COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 #include "coretypes.h"
46 #include "hard-reg-set.h"
48 #include "insn-config.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
63 #include "diagnostic.h"
66 #include "langhooks.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 #ifndef DWARF2_FRAME_INFO
94 # ifdef DWARF2_DEBUGGING_INFO
95 # define DWARF2_FRAME_INFO \
96 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
98 # define DWARF2_FRAME_INFO 0
102 /* Map register numbers held in the call frame info that gcc has
103 collected using DWARF_FRAME_REGNUM to those that should be output in
104 .debug_frame and .eh_frame. */
105 #ifndef DWARF2_FRAME_REG_OUT
106 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
109 /* Decide whether we want to emit frame unwind information for the current
113 dwarf2out_do_frame (void)
115 /* We want to emit correct CFA location expressions or lists, so we
116 have to return true if we're going to output debug info, even if
117 we're not going to output frame or unwind info. */
118 return (write_symbols == DWARF2_DEBUG
119 || write_symbols == VMS_AND_DWARF2_DEBUG
121 #ifdef DWARF2_UNWIND_INFO
122 || (DWARF2_UNWIND_INFO
123 && (flag_unwind_tables
124 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
129 /* The size of the target's pointer type. */
131 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
134 /* Array of RTXes referenced by the debugging information, which therefore
135 must be kept around forever. */
136 static GTY(()) VEC(rtx,gc) *used_rtx_array;
138 /* A pointer to the base of a list of incomplete types which might be
139 completed at some later time. incomplete_types_list needs to be a
140 VEC(tree,gc) because we want to tell the garbage collector about
142 static GTY(()) VEC(tree,gc) *incomplete_types;
144 /* A pointer to the base of a table of references to declaration
145 scopes. This table is a display which tracks the nesting
146 of declaration scopes at the current scope and containing
147 scopes. This table is used to find the proper place to
148 define type declaration DIE's. */
149 static GTY(()) VEC(tree,gc) *decl_scope_table;
151 /* Pointers to various DWARF2 sections. */
152 static GTY(()) section *debug_info_section;
153 static GTY(()) section *debug_abbrev_section;
154 static GTY(()) section *debug_aranges_section;
155 static GTY(()) section *debug_macinfo_section;
156 static GTY(()) section *debug_line_section;
157 static GTY(()) section *debug_loc_section;
158 static GTY(()) section *debug_pubnames_section;
159 static GTY(()) section *debug_str_section;
160 static GTY(()) section *debug_ranges_section;
161 static GTY(()) section *debug_frame_section;
163 /* How to start an assembler comment. */
164 #ifndef ASM_COMMENT_START
165 #define ASM_COMMENT_START ";#"
168 typedef struct dw_cfi_struct *dw_cfi_ref;
169 typedef struct dw_fde_struct *dw_fde_ref;
170 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
172 /* Call frames are described using a sequence of Call Frame
173 Information instructions. The register number, offset
174 and address fields are provided as possible operands;
175 their use is selected by the opcode field. */
177 enum dw_cfi_oprnd_type {
179 dw_cfi_oprnd_reg_num,
185 typedef union dw_cfi_oprnd_struct GTY(())
187 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
188 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
189 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
190 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
194 typedef struct dw_cfi_struct GTY(())
196 dw_cfi_ref dw_cfi_next;
197 enum dwarf_call_frame_info dw_cfi_opc;
198 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
200 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
205 /* This is how we define the location of the CFA. We use to handle it
206 as REG + OFFSET all the time, but now it can be more complex.
207 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
208 Instead of passing around REG and OFFSET, we pass a copy
209 of this structure. */
210 typedef struct cfa_loc GTY(())
212 HOST_WIDE_INT offset;
213 HOST_WIDE_INT base_offset;
215 int indirect; /* 1 if CFA is accessed via a dereference. */
218 /* All call frame descriptions (FDE's) in the GCC generated DWARF
219 refer to a single Common Information Entry (CIE), defined at
220 the beginning of the .debug_frame section. This use of a single
221 CIE obviates the need to keep track of multiple CIE's
222 in the DWARF generation routines below. */
224 typedef struct dw_fde_struct GTY(())
227 const char *dw_fde_begin;
228 const char *dw_fde_current_label;
229 const char *dw_fde_end;
230 const char *dw_fde_hot_section_label;
231 const char *dw_fde_hot_section_end_label;
232 const char *dw_fde_unlikely_section_label;
233 const char *dw_fde_unlikely_section_end_label;
234 bool dw_fde_switched_sections;
235 dw_cfi_ref dw_fde_cfi;
236 unsigned funcdef_number;
237 unsigned all_throwers_are_sibcalls : 1;
238 unsigned nothrow : 1;
239 unsigned uses_eh_lsda : 1;
243 /* Maximum size (in bytes) of an artificially generated label. */
244 #define MAX_ARTIFICIAL_LABEL_BYTES 30
246 /* The size of addresses as they appear in the Dwarf 2 data.
247 Some architectures use word addresses to refer to code locations,
248 but Dwarf 2 info always uses byte addresses. On such machines,
249 Dwarf 2 addresses need to be larger than the architecture's
251 #ifndef DWARF2_ADDR_SIZE
252 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
255 /* The size in bytes of a DWARF field indicating an offset or length
256 relative to a debug info section, specified to be 4 bytes in the
257 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
260 #ifndef DWARF_OFFSET_SIZE
261 #define DWARF_OFFSET_SIZE 4
264 /* According to the (draft) DWARF 3 specification, the initial length
265 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
266 bytes are 0xffffffff, followed by the length stored in the next 8
269 However, the SGI/MIPS ABI uses an initial length which is equal to
270 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
272 #ifndef DWARF_INITIAL_LENGTH_SIZE
273 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
276 #define DWARF_VERSION 2
278 /* Round SIZE up to the nearest BOUNDARY. */
279 #define DWARF_ROUND(SIZE,BOUNDARY) \
280 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
282 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
283 #ifndef DWARF_CIE_DATA_ALIGNMENT
284 #ifdef STACK_GROWS_DOWNWARD
285 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
287 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
291 /* CIE identifier. */
292 #if HOST_BITS_PER_WIDE_INT >= 64
293 #define DWARF_CIE_ID \
294 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
296 #define DWARF_CIE_ID DW_CIE_ID
299 /* A pointer to the base of a table that contains frame description
300 information for each routine. */
301 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
303 /* Number of elements currently allocated for fde_table. */
304 static GTY(()) unsigned fde_table_allocated;
306 /* Number of elements in fde_table currently in use. */
307 static GTY(()) unsigned fde_table_in_use;
309 /* Size (in elements) of increments by which we may expand the
311 #define FDE_TABLE_INCREMENT 256
313 /* A list of call frame insns for the CIE. */
314 static GTY(()) dw_cfi_ref cie_cfi_head;
316 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
317 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
318 attribute that accelerates the lookup of the FDE associated
319 with the subprogram. This variable holds the table index of the FDE
320 associated with the current function (body) definition. */
321 static unsigned current_funcdef_fde;
324 struct indirect_string_node GTY(())
327 unsigned int refcount;
332 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
334 static GTY(()) int dw2_string_counter;
335 static GTY(()) unsigned long dwarf2out_cfi_label_num;
337 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Forward declarations for functions defined in this file. */
341 static char *stripattributes (const char *);
342 static const char *dwarf_cfi_name (unsigned);
343 static dw_cfi_ref new_cfi (void);
344 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
345 static void add_fde_cfi (const char *, dw_cfi_ref);
346 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
347 static void lookup_cfa (dw_cfa_location *);
348 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
349 static void initial_return_save (rtx);
350 static HOST_WIDE_INT stack_adjust_offset (rtx);
351 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
352 static void output_call_frame_info (int);
353 static void dwarf2out_stack_adjust (rtx, bool);
354 static void flush_queued_reg_saves (void);
355 static bool clobbers_queued_reg_save (rtx);
356 static void dwarf2out_frame_debug_expr (rtx, const char *);
357 static void premark_used_types (void);
359 /* Support for complex CFA locations. */
360 static void output_cfa_loc (dw_cfi_ref);
361 static void get_cfa_from_loc_descr (dw_cfa_location *,
362 struct dw_loc_descr_struct *);
363 static struct dw_loc_descr_struct *build_cfa_loc
364 (dw_cfa_location *, HOST_WIDE_INT);
365 static void def_cfa_1 (const char *, dw_cfa_location *);
367 /* How to start an assembler comment. */
368 #ifndef ASM_COMMENT_START
369 #define ASM_COMMENT_START ";#"
372 /* Data and reference forms for relocatable data. */
373 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
374 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
376 #ifndef DEBUG_FRAME_SECTION
377 #define DEBUG_FRAME_SECTION ".debug_frame"
380 #ifndef FUNC_BEGIN_LABEL
381 #define FUNC_BEGIN_LABEL "LFB"
384 #ifndef FUNC_END_LABEL
385 #define FUNC_END_LABEL "LFE"
388 #ifndef FRAME_BEGIN_LABEL
389 #define FRAME_BEGIN_LABEL "Lframe"
391 #define CIE_AFTER_SIZE_LABEL "LSCIE"
392 #define CIE_END_LABEL "LECIE"
393 #define FDE_LABEL "LSFDE"
394 #define FDE_AFTER_SIZE_LABEL "LASFDE"
395 #define FDE_END_LABEL "LEFDE"
396 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
397 #define LINE_NUMBER_END_LABEL "LELT"
398 #define LN_PROLOG_AS_LABEL "LASLTP"
399 #define LN_PROLOG_END_LABEL "LELTP"
400 #define DIE_LABEL_PREFIX "DW"
402 /* The DWARF 2 CFA column which tracks the return address. Normally this
403 is the column for PC, or the first column after all of the hard
405 #ifndef DWARF_FRAME_RETURN_COLUMN
407 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
409 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
413 /* The mapping from gcc register number to DWARF 2 CFA column number. By
414 default, we just provide columns for all registers. */
415 #ifndef DWARF_FRAME_REGNUM
416 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
419 /* Hook used by __throw. */
422 expand_builtin_dwarf_sp_column (void)
424 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
425 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
428 /* Return a pointer to a copy of the section string name S with all
429 attributes stripped off, and an asterisk prepended (for assemble_name). */
432 stripattributes (const char *s)
434 char *stripped = XNEWVEC (char, strlen (s) + 2);
439 while (*s && *s != ',')
446 /* Generate code to initialize the register size table. */
449 expand_builtin_init_dwarf_reg_sizes (tree address)
452 enum machine_mode mode = TYPE_MODE (char_type_node);
453 rtx addr = expand_normal (address);
454 rtx mem = gen_rtx_MEM (BLKmode, addr);
455 bool wrote_return_column = false;
457 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
459 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
461 if (rnum < DWARF_FRAME_REGISTERS)
463 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
464 enum machine_mode save_mode = reg_raw_mode[i];
467 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
468 save_mode = choose_hard_reg_mode (i, 1, true);
469 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
471 if (save_mode == VOIDmode)
473 wrote_return_column = true;
475 size = GET_MODE_SIZE (save_mode);
479 emit_move_insn (adjust_address (mem, mode, offset),
480 gen_int_mode (size, mode));
484 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
485 gcc_assert (wrote_return_column);
486 i = DWARF_ALT_FRAME_RETURN_COLUMN;
487 wrote_return_column = false;
489 i = DWARF_FRAME_RETURN_COLUMN;
492 if (! wrote_return_column)
494 enum machine_mode save_mode = Pmode;
495 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
496 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
497 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
501 /* Convert a DWARF call frame info. operation to its string name */
504 dwarf_cfi_name (unsigned int cfi_opc)
508 case DW_CFA_advance_loc:
509 return "DW_CFA_advance_loc";
511 return "DW_CFA_offset";
513 return "DW_CFA_restore";
517 return "DW_CFA_set_loc";
518 case DW_CFA_advance_loc1:
519 return "DW_CFA_advance_loc1";
520 case DW_CFA_advance_loc2:
521 return "DW_CFA_advance_loc2";
522 case DW_CFA_advance_loc4:
523 return "DW_CFA_advance_loc4";
524 case DW_CFA_offset_extended:
525 return "DW_CFA_offset_extended";
526 case DW_CFA_restore_extended:
527 return "DW_CFA_restore_extended";
528 case DW_CFA_undefined:
529 return "DW_CFA_undefined";
530 case DW_CFA_same_value:
531 return "DW_CFA_same_value";
532 case DW_CFA_register:
533 return "DW_CFA_register";
534 case DW_CFA_remember_state:
535 return "DW_CFA_remember_state";
536 case DW_CFA_restore_state:
537 return "DW_CFA_restore_state";
539 return "DW_CFA_def_cfa";
540 case DW_CFA_def_cfa_register:
541 return "DW_CFA_def_cfa_register";
542 case DW_CFA_def_cfa_offset:
543 return "DW_CFA_def_cfa_offset";
546 case DW_CFA_def_cfa_expression:
547 return "DW_CFA_def_cfa_expression";
548 case DW_CFA_expression:
549 return "DW_CFA_expression";
550 case DW_CFA_offset_extended_sf:
551 return "DW_CFA_offset_extended_sf";
552 case DW_CFA_def_cfa_sf:
553 return "DW_CFA_def_cfa_sf";
554 case DW_CFA_def_cfa_offset_sf:
555 return "DW_CFA_def_cfa_offset_sf";
557 /* SGI/MIPS specific */
558 case DW_CFA_MIPS_advance_loc8:
559 return "DW_CFA_MIPS_advance_loc8";
562 case DW_CFA_GNU_window_save:
563 return "DW_CFA_GNU_window_save";
564 case DW_CFA_GNU_args_size:
565 return "DW_CFA_GNU_args_size";
566 case DW_CFA_GNU_negative_offset_extended:
567 return "DW_CFA_GNU_negative_offset_extended";
570 return "DW_CFA_<unknown>";
574 /* Return a pointer to a newly allocated Call Frame Instruction. */
576 static inline dw_cfi_ref
579 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
581 cfi->dw_cfi_next = NULL;
582 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
583 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
588 /* Add a Call Frame Instruction to list of instructions. */
591 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
595 /* Find the end of the chain. */
596 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
602 /* Generate a new label for the CFI info to refer to. */
605 dwarf2out_cfi_label (void)
607 static char label[20];
609 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
610 ASM_OUTPUT_LABEL (asm_out_file, label);
614 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
615 or to the CIE if LABEL is NULL. */
618 add_fde_cfi (const char *label, dw_cfi_ref cfi)
622 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
625 label = dwarf2out_cfi_label ();
627 if (fde->dw_fde_current_label == NULL
628 || strcmp (label, fde->dw_fde_current_label) != 0)
632 fde->dw_fde_current_label = label = xstrdup (label);
634 /* Set the location counter to the new label. */
636 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
637 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
638 add_cfi (&fde->dw_fde_cfi, xcfi);
641 add_cfi (&fde->dw_fde_cfi, cfi);
645 add_cfi (&cie_cfi_head, cfi);
648 /* Subroutine of lookup_cfa. */
651 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
653 switch (cfi->dw_cfi_opc)
655 case DW_CFA_def_cfa_offset:
656 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
658 case DW_CFA_def_cfa_offset_sf:
660 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
662 case DW_CFA_def_cfa_register:
663 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
666 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
667 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
669 case DW_CFA_def_cfa_sf:
670 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
672 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
674 case DW_CFA_def_cfa_expression:
675 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
682 /* Find the previous value for the CFA. */
685 lookup_cfa (dw_cfa_location *loc)
689 loc->reg = INVALID_REGNUM;
692 loc->base_offset = 0;
694 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
695 lookup_cfa_1 (cfi, loc);
697 if (fde_table_in_use)
699 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
700 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
701 lookup_cfa_1 (cfi, loc);
705 /* The current rule for calculating the DWARF2 canonical frame address. */
706 static dw_cfa_location cfa;
708 /* The register used for saving registers to the stack, and its offset
710 static dw_cfa_location cfa_store;
712 /* The running total of the size of arguments pushed onto the stack. */
713 static HOST_WIDE_INT args_size;
715 /* The last args_size we actually output. */
716 static HOST_WIDE_INT old_args_size;
718 /* Entry point to update the canonical frame address (CFA).
719 LABEL is passed to add_fde_cfi. The value of CFA is now to be
720 calculated from REG+OFFSET. */
723 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
730 def_cfa_1 (label, &loc);
733 /* Determine if two dw_cfa_location structures define the same data. */
736 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
738 return (loc1->reg == loc2->reg
739 && loc1->offset == loc2->offset
740 && loc1->indirect == loc2->indirect
741 && (loc1->indirect == 0
742 || loc1->base_offset == loc2->base_offset));
745 /* This routine does the actual work. The CFA is now calculated from
746 the dw_cfa_location structure. */
749 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
752 dw_cfa_location old_cfa, loc;
757 if (cfa_store.reg == loc.reg && loc.indirect == 0)
758 cfa_store.offset = loc.offset;
760 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
761 lookup_cfa (&old_cfa);
763 /* If nothing changed, no need to issue any call frame instructions. */
764 if (cfa_equal_p (&loc, &old_cfa))
769 if (loc.reg == old_cfa.reg && !loc.indirect)
771 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
772 the CFA register did not change but the offset did. */
775 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
776 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
778 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
779 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
783 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
784 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
788 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
789 else if (loc.offset == old_cfa.offset
790 && old_cfa.reg != INVALID_REGNUM
793 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
794 indicating the CFA register has changed to <register> but the
795 offset has not changed. */
796 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
797 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
801 else if (loc.indirect == 0)
803 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
804 indicating the CFA register has changed to <register> with
805 the specified offset. */
808 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
809 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
811 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
812 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
813 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
817 cfi->dw_cfi_opc = DW_CFA_def_cfa;
818 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
819 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
824 /* Construct a DW_CFA_def_cfa_expression instruction to
825 calculate the CFA using a full location expression since no
826 register-offset pair is available. */
827 struct dw_loc_descr_struct *loc_list;
829 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
830 loc_list = build_cfa_loc (&loc, 0);
831 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
834 add_fde_cfi (label, cfi);
837 /* Add the CFI for saving a register. REG is the CFA column number.
838 LABEL is passed to add_fde_cfi.
839 If SREG is -1, the register is saved at OFFSET from the CFA;
840 otherwise it is saved in SREG. */
843 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
845 dw_cfi_ref cfi = new_cfi ();
847 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
849 if (sreg == INVALID_REGNUM)
852 /* The register number won't fit in 6 bits, so we have to use
854 cfi->dw_cfi_opc = DW_CFA_offset_extended;
856 cfi->dw_cfi_opc = DW_CFA_offset;
858 #ifdef ENABLE_CHECKING
860 /* If we get an offset that is not a multiple of
861 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
862 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
864 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
866 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
869 offset /= DWARF_CIE_DATA_ALIGNMENT;
871 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
873 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
875 else if (sreg == reg)
876 cfi->dw_cfi_opc = DW_CFA_same_value;
879 cfi->dw_cfi_opc = DW_CFA_register;
880 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
883 add_fde_cfi (label, cfi);
886 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
887 This CFI tells the unwinder that it needs to restore the window registers
888 from the previous frame's window save area.
890 ??? Perhaps we should note in the CIE where windows are saved (instead of
891 assuming 0(cfa)) and what registers are in the window. */
894 dwarf2out_window_save (const char *label)
896 dw_cfi_ref cfi = new_cfi ();
898 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
899 add_fde_cfi (label, cfi);
902 /* Add a CFI to update the running total of the size of arguments
903 pushed onto the stack. */
906 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
910 if (size == old_args_size)
913 old_args_size = size;
916 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
917 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
918 add_fde_cfi (label, cfi);
921 /* Entry point for saving a register to the stack. REG is the GCC register
922 number. LABEL and OFFSET are passed to reg_save. */
925 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
927 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
930 /* Entry point for saving the return address in the stack.
931 LABEL and OFFSET are passed to reg_save. */
934 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
936 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
939 /* Entry point for saving the return address in a register.
940 LABEL and SREG are passed to reg_save. */
943 dwarf2out_return_reg (const char *label, unsigned int sreg)
945 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
948 /* Record the initial position of the return address. RTL is
949 INCOMING_RETURN_ADDR_RTX. */
952 initial_return_save (rtx rtl)
954 unsigned int reg = INVALID_REGNUM;
955 HOST_WIDE_INT offset = 0;
957 switch (GET_CODE (rtl))
960 /* RA is in a register. */
961 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
965 /* RA is on the stack. */
967 switch (GET_CODE (rtl))
970 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
975 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
976 offset = INTVAL (XEXP (rtl, 1));
980 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
981 offset = -INTVAL (XEXP (rtl, 1));
991 /* The return address is at some offset from any value we can
992 actually load. For instance, on the SPARC it is in %i7+8. Just
993 ignore the offset for now; it doesn't matter for unwinding frames. */
994 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
995 initial_return_save (XEXP (rtl, 0));
1002 if (reg != DWARF_FRAME_RETURN_COLUMN)
1003 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1006 /* Given a SET, calculate the amount of stack adjustment it
1009 static HOST_WIDE_INT
1010 stack_adjust_offset (rtx pattern)
1012 rtx src = SET_SRC (pattern);
1013 rtx dest = SET_DEST (pattern);
1014 HOST_WIDE_INT offset = 0;
1017 if (dest == stack_pointer_rtx)
1019 /* (set (reg sp) (plus (reg sp) (const_int))) */
1020 code = GET_CODE (src);
1021 if (! (code == PLUS || code == MINUS)
1022 || XEXP (src, 0) != stack_pointer_rtx
1023 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1026 offset = INTVAL (XEXP (src, 1));
1030 else if (MEM_P (dest))
1032 /* (set (mem (pre_dec (reg sp))) (foo)) */
1033 src = XEXP (dest, 0);
1034 code = GET_CODE (src);
1040 if (XEXP (src, 0) == stack_pointer_rtx)
1042 rtx val = XEXP (XEXP (src, 1), 1);
1043 /* We handle only adjustments by constant amount. */
1044 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1045 && GET_CODE (val) == CONST_INT);
1046 offset = -INTVAL (val);
1053 if (XEXP (src, 0) == stack_pointer_rtx)
1055 offset = GET_MODE_SIZE (GET_MODE (dest));
1062 if (XEXP (src, 0) == stack_pointer_rtx)
1064 offset = -GET_MODE_SIZE (GET_MODE (dest));
1079 /* Check INSN to see if it looks like a push or a stack adjustment, and
1080 make a note of it if it does. EH uses this information to find out how
1081 much extra space it needs to pop off the stack. */
1084 dwarf2out_stack_adjust (rtx insn, bool after_p ATTRIBUTE_UNUSED)
1086 HOST_WIDE_INT offset;
1090 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1091 with this function. Proper support would require all frame-related
1092 insns to be marked, and to be able to handle saving state around
1093 epilogues textually in the middle of the function. */
1094 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1097 if (BARRIER_P (insn))
1099 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1100 the compiler will have already emitted a stack adjustment, but
1101 doesn't bother for calls to noreturn functions. */
1102 #ifdef STACK_GROWS_DOWNWARD
1103 offset = -args_size;
1108 else if (GET_CODE (PATTERN (insn)) == SET)
1109 offset = stack_adjust_offset (PATTERN (insn));
1110 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1111 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1113 /* There may be stack adjustments inside compound insns. Search
1115 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1116 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1117 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1119 else if (GET_CODE (insn) == CALL_INSN)
1124 /* We handle this separately because we want stack adjustments in a
1125 CALL_INSN to be handled. */;
1126 if (GET_CODE (insn) == CALL_INSN)
1128 /* If only calls can throw, adjust args_size only at call sites. */
1129 if (!flag_asynchronous_unwind_tables)
1130 dwarf2out_args_size ("", args_size);
1136 if (cfa.reg == STACK_POINTER_REGNUM)
1137 cfa.offset += offset;
1139 #ifndef STACK_GROWS_DOWNWARD
1143 args_size += offset;
1147 /* If only calls can throw and we have a frame pointer, we'll save
1148 up adjustments until we see the CALL_INSN. We used to return
1149 early and derive args_size from NARGS in the CALL_INSN itself,
1150 but that doesn't compute the right value if we have nested call
1151 expansions, e.g., stack adjustments for a call have already been
1152 emitted, and then we issue another call to compute an argument
1153 for the enclosing call (i.e., bar (foo ())). */
1154 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1157 label = dwarf2out_cfi_label ();
1158 def_cfa_1 (label, &cfa);
1159 if (flag_asynchronous_unwind_tables)
1160 dwarf2out_args_size (label, args_size);
1165 /* We delay emitting a register save until either (a) we reach the end
1166 of the prologue or (b) the register is clobbered. This clusters
1167 register saves so that there are fewer pc advances. */
1169 struct queued_reg_save GTY(())
1171 struct queued_reg_save *next;
1173 HOST_WIDE_INT cfa_offset;
1177 static GTY(()) struct queued_reg_save *queued_reg_saves;
1179 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1180 struct reg_saved_in_data GTY(()) {
1185 /* A list of registers saved in other registers.
1186 The list intentionally has a small maximum capacity of 4; if your
1187 port needs more than that, you might consider implementing a
1188 more efficient data structure. */
1189 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1190 static GTY(()) size_t num_regs_saved_in_regs;
1192 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1193 static const char *last_reg_save_label;
1195 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1196 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1199 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1201 struct queued_reg_save *q;
1203 /* Duplicates waste space, but it's also necessary to remove them
1204 for correctness, since the queue gets output in reverse
1206 for (q = queued_reg_saves; q != NULL; q = q->next)
1207 if (REGNO (q->reg) == REGNO (reg))
1212 q = ggc_alloc (sizeof (*q));
1213 q->next = queued_reg_saves;
1214 queued_reg_saves = q;
1218 q->cfa_offset = offset;
1219 q->saved_reg = sreg;
1221 last_reg_save_label = label;
1224 /* Output all the entries in QUEUED_REG_SAVES. */
1227 flush_queued_reg_saves (void)
1229 struct queued_reg_save *q;
1231 for (q = queued_reg_saves; q; q = q->next)
1234 unsigned int reg, sreg;
1236 for (i = 0; i < num_regs_saved_in_regs; i++)
1237 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1239 if (q->saved_reg && i == num_regs_saved_in_regs)
1241 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1242 num_regs_saved_in_regs++;
1244 if (i != num_regs_saved_in_regs)
1246 regs_saved_in_regs[i].orig_reg = q->reg;
1247 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1250 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1252 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1254 sreg = INVALID_REGNUM;
1255 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1258 queued_reg_saves = NULL;
1259 last_reg_save_label = NULL;
1262 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1263 location for? Or, does it clobber a register which we've previously
1264 said that some other register is saved in, and for which we now
1265 have a new location for? */
1268 clobbers_queued_reg_save (rtx insn)
1270 struct queued_reg_save *q;
1272 for (q = queued_reg_saves; q; q = q->next)
1275 if (modified_in_p (q->reg, insn))
1277 for (i = 0; i < num_regs_saved_in_regs; i++)
1278 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1279 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1286 /* Entry point for saving the first register into the second. */
1289 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1292 unsigned int regno, sregno;
1294 for (i = 0; i < num_regs_saved_in_regs; i++)
1295 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1297 if (i == num_regs_saved_in_regs)
1299 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1300 num_regs_saved_in_regs++;
1302 regs_saved_in_regs[i].orig_reg = reg;
1303 regs_saved_in_regs[i].saved_in_reg = sreg;
1305 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1306 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1307 reg_save (label, regno, sregno, 0);
1310 /* What register, if any, is currently saved in REG? */
1313 reg_saved_in (rtx reg)
1315 unsigned int regn = REGNO (reg);
1317 struct queued_reg_save *q;
1319 for (q = queued_reg_saves; q; q = q->next)
1320 if (q->saved_reg && regn == REGNO (q->saved_reg))
1323 for (i = 0; i < num_regs_saved_in_regs; i++)
1324 if (regs_saved_in_regs[i].saved_in_reg
1325 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1326 return regs_saved_in_regs[i].orig_reg;
1332 /* A temporary register holding an integral value used in adjusting SP
1333 or setting up the store_reg. The "offset" field holds the integer
1334 value, not an offset. */
1335 static dw_cfa_location cfa_temp;
1337 /* Record call frame debugging information for an expression EXPR,
1338 which either sets SP or FP (adjusting how we calculate the frame
1339 address) or saves a register to the stack or another register.
1340 LABEL indicates the address of EXPR.
1342 This function encodes a state machine mapping rtxes to actions on
1343 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1344 users need not read the source code.
1346 The High-Level Picture
1348 Changes in the register we use to calculate the CFA: Currently we
1349 assume that if you copy the CFA register into another register, we
1350 should take the other one as the new CFA register; this seems to
1351 work pretty well. If it's wrong for some target, it's simple
1352 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1354 Changes in the register we use for saving registers to the stack:
1355 This is usually SP, but not always. Again, we deduce that if you
1356 copy SP into another register (and SP is not the CFA register),
1357 then the new register is the one we will be using for register
1358 saves. This also seems to work.
1360 Register saves: There's not much guesswork about this one; if
1361 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1362 register save, and the register used to calculate the destination
1363 had better be the one we think we're using for this purpose.
1364 It's also assumed that a copy from a call-saved register to another
1365 register is saving that register if RTX_FRAME_RELATED_P is set on
1366 that instruction. If the copy is from a call-saved register to
1367 the *same* register, that means that the register is now the same
1368 value as in the caller.
1370 Except: If the register being saved is the CFA register, and the
1371 offset is nonzero, we are saving the CFA, so we assume we have to
1372 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1373 the intent is to save the value of SP from the previous frame.
1375 In addition, if a register has previously been saved to a different
1378 Invariants / Summaries of Rules
1380 cfa current rule for calculating the CFA. It usually
1381 consists of a register and an offset.
1382 cfa_store register used by prologue code to save things to the stack
1383 cfa_store.offset is the offset from the value of
1384 cfa_store.reg to the actual CFA
1385 cfa_temp register holding an integral value. cfa_temp.offset
1386 stores the value, which will be used to adjust the
1387 stack pointer. cfa_temp is also used like cfa_store,
1388 to track stores to the stack via fp or a temp reg.
1390 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1391 with cfa.reg as the first operand changes the cfa.reg and its
1392 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1395 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1396 expression yielding a constant. This sets cfa_temp.reg
1397 and cfa_temp.offset.
1399 Rule 5: Create a new register cfa_store used to save items to the
1402 Rules 10-14: Save a register to the stack. Define offset as the
1403 difference of the original location and cfa_store's
1404 location (or cfa_temp's location if cfa_temp is used).
1408 "{a,b}" indicates a choice of a xor b.
1409 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1412 (set <reg1> <reg2>:cfa.reg)
1413 effects: cfa.reg = <reg1>
1414 cfa.offset unchanged
1415 cfa_temp.reg = <reg1>
1416 cfa_temp.offset = cfa.offset
1419 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1420 {<const_int>,<reg>:cfa_temp.reg}))
1421 effects: cfa.reg = sp if fp used
1422 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1423 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1424 if cfa_store.reg==sp
1427 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1428 effects: cfa.reg = fp
1429 cfa_offset += +/- <const_int>
1432 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1433 constraints: <reg1> != fp
1435 effects: cfa.reg = <reg1>
1436 cfa_temp.reg = <reg1>
1437 cfa_temp.offset = cfa.offset
1440 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1441 constraints: <reg1> != fp
1443 effects: cfa_store.reg = <reg1>
1444 cfa_store.offset = cfa.offset - cfa_temp.offset
1447 (set <reg> <const_int>)
1448 effects: cfa_temp.reg = <reg>
1449 cfa_temp.offset = <const_int>
1452 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1453 effects: cfa_temp.reg = <reg1>
1454 cfa_temp.offset |= <const_int>
1457 (set <reg> (high <exp>))
1461 (set <reg> (lo_sum <exp> <const_int>))
1462 effects: cfa_temp.reg = <reg>
1463 cfa_temp.offset = <const_int>
1466 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1467 effects: cfa_store.offset -= <const_int>
1468 cfa.offset = cfa_store.offset if cfa.reg == sp
1470 cfa.base_offset = -cfa_store.offset
1473 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1474 effects: cfa_store.offset += -/+ mode_size(mem)
1475 cfa.offset = cfa_store.offset if cfa.reg == sp
1477 cfa.base_offset = -cfa_store.offset
1480 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1483 effects: cfa.reg = <reg1>
1484 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1487 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1488 effects: cfa.reg = <reg1>
1489 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1492 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1493 effects: cfa.reg = <reg1>
1494 cfa.base_offset = -cfa_temp.offset
1495 cfa_temp.offset -= mode_size(mem)
1498 Â (set <reg> {unspec, unspec_volatile})
1499 Â effects: target-dependent */
1502 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1505 HOST_WIDE_INT offset;
1507 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1508 the PARALLEL independently. The first element is always processed if
1509 it is a SET. This is for backward compatibility. Other elements
1510 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1511 flag is set in them. */
1512 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1515 int limit = XVECLEN (expr, 0);
1517 for (par_index = 0; par_index < limit; par_index++)
1518 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1519 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1521 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1526 gcc_assert (GET_CODE (expr) == SET);
1528 src = SET_SRC (expr);
1529 dest = SET_DEST (expr);
1533 rtx rsi = reg_saved_in (src);
1538 switch (GET_CODE (dest))
1541 switch (GET_CODE (src))
1543 /* Setting FP from SP. */
1545 if (cfa.reg == (unsigned) REGNO (src))
1548 /* Update the CFA rule wrt SP or FP. Make sure src is
1549 relative to the current CFA register.
1551 We used to require that dest be either SP or FP, but the
1552 ARM copies SP to a temporary register, and from there to
1553 FP. So we just rely on the backends to only set
1554 RTX_FRAME_RELATED_P on appropriate insns. */
1555 cfa.reg = REGNO (dest);
1556 cfa_temp.reg = cfa.reg;
1557 cfa_temp.offset = cfa.offset;
1561 /* Saving a register in a register. */
1562 gcc_assert (!fixed_regs [REGNO (dest)]
1563 /* For the SPARC and its register window. */
1564 || (DWARF_FRAME_REGNUM (REGNO (src))
1565 == DWARF_FRAME_RETURN_COLUMN));
1566 queue_reg_save (label, src, dest, 0);
1573 if (dest == stack_pointer_rtx)
1577 switch (GET_CODE (XEXP (src, 1)))
1580 offset = INTVAL (XEXP (src, 1));
1583 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1585 offset = cfa_temp.offset;
1591 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1593 /* Restoring SP from FP in the epilogue. */
1594 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1595 cfa.reg = STACK_POINTER_REGNUM;
1597 else if (GET_CODE (src) == LO_SUM)
1598 /* Assume we've set the source reg of the LO_SUM from sp. */
1601 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1603 if (GET_CODE (src) != MINUS)
1605 if (cfa.reg == STACK_POINTER_REGNUM)
1606 cfa.offset += offset;
1607 if (cfa_store.reg == STACK_POINTER_REGNUM)
1608 cfa_store.offset += offset;
1610 else if (dest == hard_frame_pointer_rtx)
1613 /* Either setting the FP from an offset of the SP,
1614 or adjusting the FP */
1615 gcc_assert (frame_pointer_needed);
1617 gcc_assert (REG_P (XEXP (src, 0))
1618 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1619 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1620 offset = INTVAL (XEXP (src, 1));
1621 if (GET_CODE (src) != MINUS)
1623 cfa.offset += offset;
1624 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1628 gcc_assert (GET_CODE (src) != MINUS);
1631 if (REG_P (XEXP (src, 0))
1632 && REGNO (XEXP (src, 0)) == cfa.reg
1633 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1635 /* Setting a temporary CFA register that will be copied
1636 into the FP later on. */
1637 offset = - INTVAL (XEXP (src, 1));
1638 cfa.offset += offset;
1639 cfa.reg = REGNO (dest);
1640 /* Or used to save regs to the stack. */
1641 cfa_temp.reg = cfa.reg;
1642 cfa_temp.offset = cfa.offset;
1646 else if (REG_P (XEXP (src, 0))
1647 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1648 && XEXP (src, 1) == stack_pointer_rtx)
1650 /* Setting a scratch register that we will use instead
1651 of SP for saving registers to the stack. */
1652 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1653 cfa_store.reg = REGNO (dest);
1654 cfa_store.offset = cfa.offset - cfa_temp.offset;
1658 else if (GET_CODE (src) == LO_SUM
1659 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1661 cfa_temp.reg = REGNO (dest);
1662 cfa_temp.offset = INTVAL (XEXP (src, 1));
1671 cfa_temp.reg = REGNO (dest);
1672 cfa_temp.offset = INTVAL (src);
1677 gcc_assert (REG_P (XEXP (src, 0))
1678 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1679 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1681 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1682 cfa_temp.reg = REGNO (dest);
1683 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1686 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1687 which will fill in all of the bits. */
1694 case UNSPEC_VOLATILE:
1695 gcc_assert (targetm.dwarf_handle_frame_unspec);
1696 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1703 def_cfa_1 (label, &cfa);
1707 gcc_assert (REG_P (src));
1709 /* Saving a register to the stack. Make sure dest is relative to the
1711 switch (GET_CODE (XEXP (dest, 0)))
1716 /* We can't handle variable size modifications. */
1717 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1719 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1721 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1722 && cfa_store.reg == STACK_POINTER_REGNUM);
1724 cfa_store.offset += offset;
1725 if (cfa.reg == STACK_POINTER_REGNUM)
1726 cfa.offset = cfa_store.offset;
1728 offset = -cfa_store.offset;
1734 offset = GET_MODE_SIZE (GET_MODE (dest));
1735 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1738 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1739 && cfa_store.reg == STACK_POINTER_REGNUM);
1741 cfa_store.offset += offset;
1742 if (cfa.reg == STACK_POINTER_REGNUM)
1743 cfa.offset = cfa_store.offset;
1745 offset = -cfa_store.offset;
1749 /* With an offset. */
1756 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1757 && REG_P (XEXP (XEXP (dest, 0), 0)));
1758 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1759 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1762 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1764 if (cfa_store.reg == (unsigned) regno)
1765 offset -= cfa_store.offset;
1768 gcc_assert (cfa_temp.reg == (unsigned) regno);
1769 offset -= cfa_temp.offset;
1775 /* Without an offset. */
1778 int regno = REGNO (XEXP (dest, 0));
1780 if (cfa_store.reg == (unsigned) regno)
1781 offset = -cfa_store.offset;
1784 gcc_assert (cfa_temp.reg == (unsigned) regno);
1785 offset = -cfa_temp.offset;
1792 gcc_assert (cfa_temp.reg
1793 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1794 offset = -cfa_temp.offset;
1795 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1802 if (REGNO (src) != STACK_POINTER_REGNUM
1803 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1804 && (unsigned) REGNO (src) == cfa.reg)
1806 /* We're storing the current CFA reg into the stack. */
1808 if (cfa.offset == 0)
1810 /* If the source register is exactly the CFA, assume
1811 we're saving SP like any other register; this happens
1813 def_cfa_1 (label, &cfa);
1814 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1819 /* Otherwise, we'll need to look in the stack to
1820 calculate the CFA. */
1821 rtx x = XEXP (dest, 0);
1825 gcc_assert (REG_P (x));
1827 cfa.reg = REGNO (x);
1828 cfa.base_offset = offset;
1830 def_cfa_1 (label, &cfa);
1835 def_cfa_1 (label, &cfa);
1836 queue_reg_save (label, src, NULL_RTX, offset);
1844 /* Record call frame debugging information for INSN, which either
1845 sets SP or FP (adjusting how we calculate the frame address) or saves a
1846 register to the stack. If INSN is NULL_RTX, initialize our state.
1848 If AFTER_P is false, we're being called before the insn is emitted,
1849 otherwise after. Call instructions get invoked twice. */
1852 dwarf2out_frame_debug (rtx insn, bool after_p)
1857 if (insn == NULL_RTX)
1861 /* Flush any queued register saves. */
1862 flush_queued_reg_saves ();
1864 /* Set up state for generating call frame debug info. */
1867 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1869 cfa.reg = STACK_POINTER_REGNUM;
1872 cfa_temp.offset = 0;
1874 for (i = 0; i < num_regs_saved_in_regs; i++)
1876 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1877 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1879 num_regs_saved_in_regs = 0;
1883 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1884 flush_queued_reg_saves ();
1886 if (! RTX_FRAME_RELATED_P (insn))
1888 if (!ACCUMULATE_OUTGOING_ARGS)
1889 dwarf2out_stack_adjust (insn, after_p);
1893 label = dwarf2out_cfi_label ();
1894 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1896 insn = XEXP (src, 0);
1898 insn = PATTERN (insn);
1900 dwarf2out_frame_debug_expr (insn, label);
1905 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1906 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1907 (enum dwarf_call_frame_info cfi);
1909 static enum dw_cfi_oprnd_type
1910 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1915 case DW_CFA_GNU_window_save:
1916 return dw_cfi_oprnd_unused;
1918 case DW_CFA_set_loc:
1919 case DW_CFA_advance_loc1:
1920 case DW_CFA_advance_loc2:
1921 case DW_CFA_advance_loc4:
1922 case DW_CFA_MIPS_advance_loc8:
1923 return dw_cfi_oprnd_addr;
1926 case DW_CFA_offset_extended:
1927 case DW_CFA_def_cfa:
1928 case DW_CFA_offset_extended_sf:
1929 case DW_CFA_def_cfa_sf:
1930 case DW_CFA_restore_extended:
1931 case DW_CFA_undefined:
1932 case DW_CFA_same_value:
1933 case DW_CFA_def_cfa_register:
1934 case DW_CFA_register:
1935 return dw_cfi_oprnd_reg_num;
1937 case DW_CFA_def_cfa_offset:
1938 case DW_CFA_GNU_args_size:
1939 case DW_CFA_def_cfa_offset_sf:
1940 return dw_cfi_oprnd_offset;
1942 case DW_CFA_def_cfa_expression:
1943 case DW_CFA_expression:
1944 return dw_cfi_oprnd_loc;
1951 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1952 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1953 (enum dwarf_call_frame_info cfi);
1955 static enum dw_cfi_oprnd_type
1956 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1960 case DW_CFA_def_cfa:
1961 case DW_CFA_def_cfa_sf:
1963 case DW_CFA_offset_extended_sf:
1964 case DW_CFA_offset_extended:
1965 return dw_cfi_oprnd_offset;
1967 case DW_CFA_register:
1968 return dw_cfi_oprnd_reg_num;
1971 return dw_cfi_oprnd_unused;
1975 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1977 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
1978 switch to the data section instead, and write out a synthetic label
1982 switch_to_eh_frame_section (void)
1986 #ifdef EH_FRAME_SECTION_NAME
1987 if (eh_frame_section == 0)
1991 if (EH_TABLES_CAN_BE_READ_ONLY)
1997 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
1999 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2001 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2003 flags = ((! flag_pic
2004 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2005 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2006 && (per_encoding & 0x70) != DW_EH_PE_absptr
2007 && (per_encoding & 0x70) != DW_EH_PE_aligned
2008 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2009 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2010 ? 0 : SECTION_WRITE);
2013 flags = SECTION_WRITE;
2014 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2018 if (eh_frame_section)
2019 switch_to_section (eh_frame_section);
2022 /* We have no special eh_frame section. Put the information in
2023 the data section and emit special labels to guide collect2. */
2024 switch_to_section (data_section);
2025 label = get_file_function_name ('F');
2026 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2027 targetm.asm_out.globalize_label (asm_out_file,
2028 IDENTIFIER_POINTER (label));
2029 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2033 /* Output a Call Frame Information opcode and its operand(s). */
2036 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2039 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2040 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2041 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2042 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2043 cfi->dw_cfi_oprnd1.dw_cfi_offset);
2044 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2046 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2047 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2048 "DW_CFA_offset, column 0x%lx", r);
2049 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2051 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2053 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2054 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2055 "DW_CFA_restore, column 0x%lx", r);
2059 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2060 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2062 switch (cfi->dw_cfi_opc)
2064 case DW_CFA_set_loc:
2066 dw2_asm_output_encoded_addr_rtx (
2067 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2068 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2071 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2072 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2075 case DW_CFA_advance_loc1:
2076 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2077 fde->dw_fde_current_label, NULL);
2078 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2081 case DW_CFA_advance_loc2:
2082 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2083 fde->dw_fde_current_label, NULL);
2084 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2087 case DW_CFA_advance_loc4:
2088 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2089 fde->dw_fde_current_label, NULL);
2090 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2093 case DW_CFA_MIPS_advance_loc8:
2094 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2095 fde->dw_fde_current_label, NULL);
2096 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2099 case DW_CFA_offset_extended:
2100 case DW_CFA_def_cfa:
2101 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2102 dw2_asm_output_data_uleb128 (r, NULL);
2103 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2106 case DW_CFA_offset_extended_sf:
2107 case DW_CFA_def_cfa_sf:
2108 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2109 dw2_asm_output_data_uleb128 (r, NULL);
2110 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2113 case DW_CFA_restore_extended:
2114 case DW_CFA_undefined:
2115 case DW_CFA_same_value:
2116 case DW_CFA_def_cfa_register:
2117 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2118 dw2_asm_output_data_uleb128 (r, NULL);
2121 case DW_CFA_register:
2122 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2123 dw2_asm_output_data_uleb128 (r, NULL);
2124 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2125 dw2_asm_output_data_uleb128 (r, NULL);
2128 case DW_CFA_def_cfa_offset:
2129 case DW_CFA_GNU_args_size:
2130 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2133 case DW_CFA_def_cfa_offset_sf:
2134 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2137 case DW_CFA_GNU_window_save:
2140 case DW_CFA_def_cfa_expression:
2141 case DW_CFA_expression:
2142 output_cfa_loc (cfi);
2145 case DW_CFA_GNU_negative_offset_extended:
2146 /* Obsoleted by DW_CFA_offset_extended_sf. */
2155 /* Output the call frame information used to record information
2156 that relates to calculating the frame pointer, and records the
2157 location of saved registers. */
2160 output_call_frame_info (int for_eh)
2165 char l1[20], l2[20], section_start_label[20];
2166 bool any_lsda_needed = false;
2167 char augmentation[6];
2168 int augmentation_size;
2169 int fde_encoding = DW_EH_PE_absptr;
2170 int per_encoding = DW_EH_PE_absptr;
2171 int lsda_encoding = DW_EH_PE_absptr;
2174 /* Don't emit a CIE if there won't be any FDEs. */
2175 if (fde_table_in_use == 0)
2178 /* If we make FDEs linkonce, we may have to emit an empty label for
2179 an FDE that wouldn't otherwise be emitted. We want to avoid
2180 having an FDE kept around when the function it refers to is
2181 discarded. Example where this matters: a primary function
2182 template in C++ requires EH information, but an explicit
2183 specialization doesn't. */
2184 if (TARGET_USES_WEAK_UNWIND_INFO
2185 && ! flag_asynchronous_unwind_tables
2187 for (i = 0; i < fde_table_in_use; i++)
2188 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2189 && !fde_table[i].uses_eh_lsda
2190 && ! DECL_WEAK (fde_table[i].decl))
2191 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2192 for_eh, /* empty */ 1);
2194 /* If we don't have any functions we'll want to unwind out of, don't
2195 emit any EH unwind information. Note that if exceptions aren't
2196 enabled, we won't have collected nothrow information, and if we
2197 asked for asynchronous tables, we always want this info. */
2200 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2202 for (i = 0; i < fde_table_in_use; i++)
2203 if (fde_table[i].uses_eh_lsda)
2204 any_eh_needed = any_lsda_needed = true;
2205 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2206 any_eh_needed = true;
2207 else if (! fde_table[i].nothrow
2208 && ! fde_table[i].all_throwers_are_sibcalls)
2209 any_eh_needed = true;
2211 if (! any_eh_needed)
2215 /* We're going to be generating comments, so turn on app. */
2220 switch_to_eh_frame_section ();
2222 switch_to_section (debug_frame_section);
2224 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2225 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2227 /* Output the CIE. */
2228 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2229 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2230 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2231 dw2_asm_output_data (4, 0xffffffff,
2232 "Initial length escape value indicating 64-bit DWARF extension");
2233 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2234 "Length of Common Information Entry");
2235 ASM_OUTPUT_LABEL (asm_out_file, l1);
2237 /* Now that the CIE pointer is PC-relative for EH,
2238 use 0 to identify the CIE. */
2239 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2240 (for_eh ? 0 : DWARF_CIE_ID),
2241 "CIE Identifier Tag");
2243 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2245 augmentation[0] = 0;
2246 augmentation_size = 0;
2252 z Indicates that a uleb128 is present to size the
2253 augmentation section.
2254 L Indicates the encoding (and thus presence) of
2255 an LSDA pointer in the FDE augmentation.
2256 R Indicates a non-default pointer encoding for
2258 P Indicates the presence of an encoding + language
2259 personality routine in the CIE augmentation. */
2261 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2262 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2263 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2265 p = augmentation + 1;
2266 if (eh_personality_libfunc)
2269 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2271 if (any_lsda_needed)
2274 augmentation_size += 1;
2276 if (fde_encoding != DW_EH_PE_absptr)
2279 augmentation_size += 1;
2281 if (p > augmentation + 1)
2283 augmentation[0] = 'z';
2287 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2288 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2290 int offset = ( 4 /* Length */
2292 + 1 /* CIE version */
2293 + strlen (augmentation) + 1 /* Augmentation */
2294 + size_of_uleb128 (1) /* Code alignment */
2295 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2297 + 1 /* Augmentation size */
2298 + 1 /* Personality encoding */ );
2299 int pad = -offset & (PTR_SIZE - 1);
2301 augmentation_size += pad;
2303 /* Augmentations should be small, so there's scarce need to
2304 iterate for a solution. Die if we exceed one uleb128 byte. */
2305 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2309 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2310 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2311 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2312 "CIE Data Alignment Factor");
2314 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2315 if (DW_CIE_VERSION == 1)
2316 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2318 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2320 if (augmentation[0])
2322 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2323 if (eh_personality_libfunc)
2325 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2326 eh_data_format_name (per_encoding));
2327 dw2_asm_output_encoded_addr_rtx (per_encoding,
2328 eh_personality_libfunc,
2332 if (any_lsda_needed)
2333 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2334 eh_data_format_name (lsda_encoding));
2336 if (fde_encoding != DW_EH_PE_absptr)
2337 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2338 eh_data_format_name (fde_encoding));
2341 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2342 output_cfi (cfi, NULL, for_eh);
2344 /* Pad the CIE out to an address sized boundary. */
2345 ASM_OUTPUT_ALIGN (asm_out_file,
2346 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2347 ASM_OUTPUT_LABEL (asm_out_file, l2);
2349 /* Loop through all of the FDE's. */
2350 for (i = 0; i < fde_table_in_use; i++)
2352 fde = &fde_table[i];
2354 /* Don't emit EH unwind info for leaf functions that don't need it. */
2355 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2356 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2357 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2358 && !fde->uses_eh_lsda)
2361 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2362 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2363 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2364 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2365 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2366 dw2_asm_output_data (4, 0xffffffff,
2367 "Initial length escape value indicating 64-bit DWARF extension");
2368 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2370 ASM_OUTPUT_LABEL (asm_out_file, l1);
2373 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2375 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2376 debug_frame_section, "FDE CIE offset");
2380 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2381 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2382 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2385 "FDE initial location");
2386 if (fde->dw_fde_switched_sections)
2388 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2389 fde->dw_fde_unlikely_section_label);
2390 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2391 fde->dw_fde_hot_section_label);
2392 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2393 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2394 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2395 "FDE initial location");
2396 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2397 fde->dw_fde_hot_section_end_label,
2398 fde->dw_fde_hot_section_label,
2399 "FDE address range");
2400 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2401 "FDE initial location");
2402 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2403 fde->dw_fde_unlikely_section_end_label,
2404 fde->dw_fde_unlikely_section_label,
2405 "FDE address range");
2408 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2409 fde->dw_fde_end, fde->dw_fde_begin,
2410 "FDE address range");
2414 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2415 "FDE initial location");
2416 if (fde->dw_fde_switched_sections)
2418 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2419 fde->dw_fde_hot_section_label,
2420 "FDE initial location");
2421 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2422 fde->dw_fde_hot_section_end_label,
2423 fde->dw_fde_hot_section_label,
2424 "FDE address range");
2425 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2426 fde->dw_fde_unlikely_section_label,
2427 "FDE initial location");
2428 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2429 fde->dw_fde_unlikely_section_end_label,
2430 fde->dw_fde_unlikely_section_label,
2431 "FDE address range");
2434 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2435 fde->dw_fde_end, fde->dw_fde_begin,
2436 "FDE address range");
2439 if (augmentation[0])
2441 if (any_lsda_needed)
2443 int size = size_of_encoded_value (lsda_encoding);
2445 if (lsda_encoding == DW_EH_PE_aligned)
2447 int offset = ( 4 /* Length */
2448 + 4 /* CIE offset */
2449 + 2 * size_of_encoded_value (fde_encoding)
2450 + 1 /* Augmentation size */ );
2451 int pad = -offset & (PTR_SIZE - 1);
2454 gcc_assert (size_of_uleb128 (size) == 1);
2457 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2459 if (fde->uses_eh_lsda)
2461 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2462 fde->funcdef_number);
2463 dw2_asm_output_encoded_addr_rtx (
2464 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2465 false, "Language Specific Data Area");
2469 if (lsda_encoding == DW_EH_PE_aligned)
2470 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2472 (size_of_encoded_value (lsda_encoding), 0,
2473 "Language Specific Data Area (none)");
2477 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2480 /* Loop through the Call Frame Instructions associated with
2482 fde->dw_fde_current_label = fde->dw_fde_begin;
2483 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2484 output_cfi (cfi, fde, for_eh);
2486 /* Pad the FDE out to an address sized boundary. */
2487 ASM_OUTPUT_ALIGN (asm_out_file,
2488 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2489 ASM_OUTPUT_LABEL (asm_out_file, l2);
2492 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2493 dw2_asm_output_data (4, 0, "End of Table");
2494 #ifdef MIPS_DEBUGGING_INFO
2495 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2496 get a value of 0. Putting .align 0 after the label fixes it. */
2497 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2500 /* Turn off app to make assembly quicker. */
2505 /* Output a marker (i.e. a label) for the beginning of a function, before
2509 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2510 const char *file ATTRIBUTE_UNUSED)
2512 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2516 current_function_func_begin_label = NULL;
2518 #ifdef TARGET_UNWIND_INFO
2519 /* ??? current_function_func_begin_label is also used by except.c
2520 for call-site information. We must emit this label if it might
2522 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2523 && ! dwarf2out_do_frame ())
2526 if (! dwarf2out_do_frame ())
2530 switch_to_section (function_section (current_function_decl));
2531 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2532 current_function_funcdef_no);
2533 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2534 current_function_funcdef_no);
2535 dup_label = xstrdup (label);
2536 current_function_func_begin_label = dup_label;
2538 #ifdef TARGET_UNWIND_INFO
2539 /* We can elide the fde allocation if we're not emitting debug info. */
2540 if (! dwarf2out_do_frame ())
2544 /* Expand the fde table if necessary. */
2545 if (fde_table_in_use == fde_table_allocated)
2547 fde_table_allocated += FDE_TABLE_INCREMENT;
2548 fde_table = ggc_realloc (fde_table,
2549 fde_table_allocated * sizeof (dw_fde_node));
2550 memset (fde_table + fde_table_in_use, 0,
2551 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2554 /* Record the FDE associated with this function. */
2555 current_funcdef_fde = fde_table_in_use;
2557 /* Add the new FDE at the end of the fde_table. */
2558 fde = &fde_table[fde_table_in_use++];
2559 fde->decl = current_function_decl;
2560 fde->dw_fde_begin = dup_label;
2561 fde->dw_fde_current_label = NULL;
2562 fde->dw_fde_hot_section_label = NULL;
2563 fde->dw_fde_hot_section_end_label = NULL;
2564 fde->dw_fde_unlikely_section_label = NULL;
2565 fde->dw_fde_unlikely_section_end_label = NULL;
2566 fde->dw_fde_switched_sections = false;
2567 fde->dw_fde_end = NULL;
2568 fde->dw_fde_cfi = NULL;
2569 fde->funcdef_number = current_function_funcdef_no;
2570 fde->nothrow = TREE_NOTHROW (current_function_decl);
2571 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2572 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2574 args_size = old_args_size = 0;
2576 /* We only want to output line number information for the genuine dwarf2
2577 prologue case, not the eh frame case. */
2578 #ifdef DWARF2_DEBUGGING_INFO
2580 dwarf2out_source_line (line, file);
2584 /* Output a marker (i.e. a label) for the absolute end of the generated code
2585 for a function definition. This gets called *after* the epilogue code has
2589 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2590 const char *file ATTRIBUTE_UNUSED)
2593 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2595 /* Output a label to mark the endpoint of the code generated for this
2597 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2598 current_function_funcdef_no);
2599 ASM_OUTPUT_LABEL (asm_out_file, label);
2600 fde = &fde_table[fde_table_in_use - 1];
2601 fde->dw_fde_end = xstrdup (label);
2605 dwarf2out_frame_init (void)
2607 /* Allocate the initial hunk of the fde_table. */
2608 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2609 fde_table_allocated = FDE_TABLE_INCREMENT;
2610 fde_table_in_use = 0;
2612 /* Generate the CFA instructions common to all FDE's. Do it now for the
2613 sake of lookup_cfa. */
2615 /* On entry, the Canonical Frame Address is at SP. */
2616 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2618 #ifdef DWARF2_UNWIND_INFO
2619 if (DWARF2_UNWIND_INFO)
2620 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2625 dwarf2out_frame_finish (void)
2627 /* Output call frame information. */
2628 if (DWARF2_FRAME_INFO)
2629 output_call_frame_info (0);
2631 #ifndef TARGET_UNWIND_INFO
2632 /* Output another copy for the unwinder. */
2633 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2634 output_call_frame_info (1);
2639 /* And now, the subset of the debugging information support code necessary
2640 for emitting location expressions. */
2642 /* We need some way to distinguish DW_OP_addr with a direct symbol
2643 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2644 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2647 typedef struct dw_val_struct *dw_val_ref;
2648 typedef struct die_struct *dw_die_ref;
2649 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2650 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2652 /* Each DIE may have a series of attribute/value pairs. Values
2653 can take on several forms. The forms that are used in this
2654 implementation are listed below. */
2659 dw_val_class_offset,
2661 dw_val_class_loc_list,
2662 dw_val_class_range_list,
2664 dw_val_class_unsigned_const,
2665 dw_val_class_long_long,
2668 dw_val_class_die_ref,
2669 dw_val_class_fde_ref,
2670 dw_val_class_lbl_id,
2671 dw_val_class_lineptr,
2676 /* Describe a double word constant value. */
2677 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2679 typedef struct dw_long_long_struct GTY(())
2686 /* Describe a floating point constant value, or a vector constant value. */
2688 typedef struct dw_vec_struct GTY(())
2690 unsigned char * GTY((length ("%h.length"))) array;
2696 /* The dw_val_node describes an attribute's value, as it is
2697 represented internally. */
2699 typedef struct dw_val_struct GTY(())
2701 enum dw_val_class val_class;
2702 union dw_val_struct_union
2704 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2705 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2706 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2707 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2708 HOST_WIDE_INT GTY ((default)) val_int;
2709 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2710 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2711 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2712 struct dw_val_die_union
2716 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2717 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2718 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2719 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2720 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2722 GTY ((desc ("%1.val_class"))) v;
2726 /* Locations in memory are described using a sequence of stack machine
2729 typedef struct dw_loc_descr_struct GTY(())
2731 dw_loc_descr_ref dw_loc_next;
2732 enum dwarf_location_atom dw_loc_opc;
2733 dw_val_node dw_loc_oprnd1;
2734 dw_val_node dw_loc_oprnd2;
2739 /* Location lists are ranges + location descriptions for that range,
2740 so you can track variables that are in different places over
2741 their entire life. */
2742 typedef struct dw_loc_list_struct GTY(())
2744 dw_loc_list_ref dw_loc_next;
2745 const char *begin; /* Label for begin address of range */
2746 const char *end; /* Label for end address of range */
2747 char *ll_symbol; /* Label for beginning of location list.
2748 Only on head of list */
2749 const char *section; /* Section this loclist is relative to */
2750 dw_loc_descr_ref expr;
2753 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2755 static const char *dwarf_stack_op_name (unsigned);
2756 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2757 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2758 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2759 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2760 static unsigned long size_of_locs (dw_loc_descr_ref);
2761 static void output_loc_operands (dw_loc_descr_ref);
2762 static void output_loc_sequence (dw_loc_descr_ref);
2764 /* Convert a DWARF stack opcode into its string name. */
2767 dwarf_stack_op_name (unsigned int op)
2772 case INTERNAL_DW_OP_tls_addr:
2773 return "DW_OP_addr";
2775 return "DW_OP_deref";
2777 return "DW_OP_const1u";
2779 return "DW_OP_const1s";
2781 return "DW_OP_const2u";
2783 return "DW_OP_const2s";
2785 return "DW_OP_const4u";
2787 return "DW_OP_const4s";
2789 return "DW_OP_const8u";
2791 return "DW_OP_const8s";
2793 return "DW_OP_constu";
2795 return "DW_OP_consts";
2799 return "DW_OP_drop";
2801 return "DW_OP_over";
2803 return "DW_OP_pick";
2805 return "DW_OP_swap";
2809 return "DW_OP_xderef";
2817 return "DW_OP_minus";
2829 return "DW_OP_plus";
2830 case DW_OP_plus_uconst:
2831 return "DW_OP_plus_uconst";
2837 return "DW_OP_shra";
2855 return "DW_OP_skip";
2857 return "DW_OP_lit0";
2859 return "DW_OP_lit1";
2861 return "DW_OP_lit2";
2863 return "DW_OP_lit3";
2865 return "DW_OP_lit4";
2867 return "DW_OP_lit5";
2869 return "DW_OP_lit6";
2871 return "DW_OP_lit7";
2873 return "DW_OP_lit8";
2875 return "DW_OP_lit9";
2877 return "DW_OP_lit10";
2879 return "DW_OP_lit11";
2881 return "DW_OP_lit12";
2883 return "DW_OP_lit13";
2885 return "DW_OP_lit14";
2887 return "DW_OP_lit15";
2889 return "DW_OP_lit16";
2891 return "DW_OP_lit17";
2893 return "DW_OP_lit18";
2895 return "DW_OP_lit19";
2897 return "DW_OP_lit20";
2899 return "DW_OP_lit21";
2901 return "DW_OP_lit22";
2903 return "DW_OP_lit23";
2905 return "DW_OP_lit24";
2907 return "DW_OP_lit25";
2909 return "DW_OP_lit26";
2911 return "DW_OP_lit27";
2913 return "DW_OP_lit28";
2915 return "DW_OP_lit29";
2917 return "DW_OP_lit30";
2919 return "DW_OP_lit31";
2921 return "DW_OP_reg0";
2923 return "DW_OP_reg1";
2925 return "DW_OP_reg2";
2927 return "DW_OP_reg3";
2929 return "DW_OP_reg4";
2931 return "DW_OP_reg5";
2933 return "DW_OP_reg6";
2935 return "DW_OP_reg7";
2937 return "DW_OP_reg8";
2939 return "DW_OP_reg9";
2941 return "DW_OP_reg10";
2943 return "DW_OP_reg11";
2945 return "DW_OP_reg12";
2947 return "DW_OP_reg13";
2949 return "DW_OP_reg14";
2951 return "DW_OP_reg15";
2953 return "DW_OP_reg16";
2955 return "DW_OP_reg17";
2957 return "DW_OP_reg18";
2959 return "DW_OP_reg19";
2961 return "DW_OP_reg20";
2963 return "DW_OP_reg21";
2965 return "DW_OP_reg22";
2967 return "DW_OP_reg23";
2969 return "DW_OP_reg24";
2971 return "DW_OP_reg25";
2973 return "DW_OP_reg26";
2975 return "DW_OP_reg27";
2977 return "DW_OP_reg28";
2979 return "DW_OP_reg29";
2981 return "DW_OP_reg30";
2983 return "DW_OP_reg31";
2985 return "DW_OP_breg0";
2987 return "DW_OP_breg1";
2989 return "DW_OP_breg2";
2991 return "DW_OP_breg3";
2993 return "DW_OP_breg4";
2995 return "DW_OP_breg5";
2997 return "DW_OP_breg6";
2999 return "DW_OP_breg7";
3001 return "DW_OP_breg8";
3003 return "DW_OP_breg9";
3005 return "DW_OP_breg10";
3007 return "DW_OP_breg11";
3009 return "DW_OP_breg12";
3011 return "DW_OP_breg13";
3013 return "DW_OP_breg14";
3015 return "DW_OP_breg15";
3017 return "DW_OP_breg16";
3019 return "DW_OP_breg17";
3021 return "DW_OP_breg18";
3023 return "DW_OP_breg19";
3025 return "DW_OP_breg20";
3027 return "DW_OP_breg21";
3029 return "DW_OP_breg22";
3031 return "DW_OP_breg23";
3033 return "DW_OP_breg24";
3035 return "DW_OP_breg25";
3037 return "DW_OP_breg26";
3039 return "DW_OP_breg27";
3041 return "DW_OP_breg28";
3043 return "DW_OP_breg29";
3045 return "DW_OP_breg30";
3047 return "DW_OP_breg31";
3049 return "DW_OP_regx";
3051 return "DW_OP_fbreg";
3053 return "DW_OP_bregx";
3055 return "DW_OP_piece";
3056 case DW_OP_deref_size:
3057 return "DW_OP_deref_size";
3058 case DW_OP_xderef_size:
3059 return "DW_OP_xderef_size";
3062 case DW_OP_push_object_address:
3063 return "DW_OP_push_object_address";
3065 return "DW_OP_call2";
3067 return "DW_OP_call4";
3068 case DW_OP_call_ref:
3069 return "DW_OP_call_ref";
3070 case DW_OP_GNU_push_tls_address:
3071 return "DW_OP_GNU_push_tls_address";
3073 return "OP_<unknown>";
3077 /* Return a pointer to a newly allocated location description. Location
3078 descriptions are simple expression terms that can be strung
3079 together to form more complicated location (address) descriptions. */
3081 static inline dw_loc_descr_ref
3082 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3083 unsigned HOST_WIDE_INT oprnd2)
3085 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
3087 descr->dw_loc_opc = op;
3088 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3089 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3090 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3091 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3096 /* Add a location description term to a location description expression. */
3099 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3101 dw_loc_descr_ref *d;
3103 /* Find the end of the chain. */
3104 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3110 /* Return the size of a location descriptor. */
3112 static unsigned long
3113 size_of_loc_descr (dw_loc_descr_ref loc)
3115 unsigned long size = 1;
3117 switch (loc->dw_loc_opc)
3120 case INTERNAL_DW_OP_tls_addr:
3121 size += DWARF2_ADDR_SIZE;
3140 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3143 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3148 case DW_OP_plus_uconst:
3149 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3187 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3190 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3193 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3196 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3197 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3200 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3202 case DW_OP_deref_size:
3203 case DW_OP_xderef_size:
3212 case DW_OP_call_ref:
3213 size += DWARF2_ADDR_SIZE;
3222 /* Return the size of a series of location descriptors. */
3224 static unsigned long
3225 size_of_locs (dw_loc_descr_ref loc)
3229 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3231 loc->dw_loc_addr = size;
3232 size += size_of_loc_descr (loc);
3238 /* Output location description stack opcode's operands (if any). */
3241 output_loc_operands (dw_loc_descr_ref loc)
3243 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3244 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3246 switch (loc->dw_loc_opc)
3248 #ifdef DWARF2_DEBUGGING_INFO
3250 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3254 dw2_asm_output_data (2, val1->v.val_int, NULL);
3258 dw2_asm_output_data (4, val1->v.val_int, NULL);
3262 gcc_assert (HOST_BITS_PER_LONG >= 64);
3263 dw2_asm_output_data (8, val1->v.val_int, NULL);
3270 gcc_assert (val1->val_class == dw_val_class_loc);
3271 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3273 dw2_asm_output_data (2, offset, NULL);
3286 /* We currently don't make any attempt to make sure these are
3287 aligned properly like we do for the main unwind info, so
3288 don't support emitting things larger than a byte if we're
3289 only doing unwinding. */
3294 dw2_asm_output_data (1, val1->v.val_int, NULL);
3297 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3300 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3303 dw2_asm_output_data (1, val1->v.val_int, NULL);
3305 case DW_OP_plus_uconst:
3306 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3340 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3343 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3346 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3349 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3350 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3353 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3355 case DW_OP_deref_size:
3356 case DW_OP_xderef_size:
3357 dw2_asm_output_data (1, val1->v.val_int, NULL);
3360 case INTERNAL_DW_OP_tls_addr:
3361 if (targetm.asm_out.output_dwarf_dtprel)
3363 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3366 fputc ('\n', asm_out_file);
3373 /* Other codes have no operands. */
3378 /* Output a sequence of location operations. */
3381 output_loc_sequence (dw_loc_descr_ref loc)
3383 for (; loc != NULL; loc = loc->dw_loc_next)
3385 /* Output the opcode. */
3386 dw2_asm_output_data (1, loc->dw_loc_opc,
3387 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3389 /* Output the operand(s) (if any). */
3390 output_loc_operands (loc);
3394 /* This routine will generate the correct assembly data for a location
3395 description based on a cfi entry with a complex address. */
3398 output_cfa_loc (dw_cfi_ref cfi)
3400 dw_loc_descr_ref loc;
3403 /* Output the size of the block. */
3404 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3405 size = size_of_locs (loc);
3406 dw2_asm_output_data_uleb128 (size, NULL);
3408 /* Now output the operations themselves. */
3409 output_loc_sequence (loc);
3412 /* This function builds a dwarf location descriptor sequence from a
3413 dw_cfa_location, adding the given OFFSET to the result of the
3416 static struct dw_loc_descr_struct *
3417 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3419 struct dw_loc_descr_struct *head, *tmp;
3421 offset += cfa->offset;
3425 if (cfa->base_offset)
3428 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3430 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3432 else if (cfa->reg <= 31)
3433 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3435 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3437 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3438 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3439 add_loc_descr (&head, tmp);
3442 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3443 add_loc_descr (&head, tmp);
3450 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3452 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3453 else if (cfa->reg <= 31)
3454 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3456 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3462 /* This function fills in aa dw_cfa_location structure from a dwarf location
3463 descriptor sequence. */
3466 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3468 struct dw_loc_descr_struct *ptr;
3470 cfa->base_offset = 0;
3474 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3476 enum dwarf_location_atom op = ptr->dw_loc_opc;
3512 cfa->reg = op - DW_OP_reg0;
3515 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3549 cfa->reg = op - DW_OP_breg0;
3550 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3553 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3554 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3559 case DW_OP_plus_uconst:
3560 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3563 internal_error ("DW_LOC_OP %s not implemented",
3564 dwarf_stack_op_name (ptr->dw_loc_opc));
3568 #endif /* .debug_frame support */
3570 /* And now, the support for symbolic debugging information. */
3571 #ifdef DWARF2_DEBUGGING_INFO
3573 /* .debug_str support. */
3574 static int output_indirect_string (void **, void *);
3576 static void dwarf2out_init (const char *);
3577 static void dwarf2out_finish (const char *);
3578 static void dwarf2out_define (unsigned int, const char *);
3579 static void dwarf2out_undef (unsigned int, const char *);
3580 static void dwarf2out_start_source_file (unsigned, const char *);
3581 static void dwarf2out_end_source_file (unsigned);
3582 static void dwarf2out_begin_block (unsigned, unsigned);
3583 static void dwarf2out_end_block (unsigned, unsigned);
3584 static bool dwarf2out_ignore_block (tree);
3585 static void dwarf2out_global_decl (tree);
3586 static void dwarf2out_type_decl (tree, int);
3587 static void dwarf2out_imported_module_or_decl (tree, tree);
3588 static void dwarf2out_abstract_function (tree);
3589 static void dwarf2out_var_location (rtx);
3590 static void dwarf2out_begin_function (tree);
3591 static void dwarf2out_switch_text_section (void);
3593 /* The debug hooks structure. */
3595 const struct gcc_debug_hooks dwarf2_debug_hooks =
3601 dwarf2out_start_source_file,
3602 dwarf2out_end_source_file,
3603 dwarf2out_begin_block,
3604 dwarf2out_end_block,
3605 dwarf2out_ignore_block,
3606 dwarf2out_source_line,
3607 dwarf2out_begin_prologue,
3608 debug_nothing_int_charstar, /* end_prologue */
3609 dwarf2out_end_epilogue,
3610 dwarf2out_begin_function,
3611 debug_nothing_int, /* end_function */
3612 dwarf2out_decl, /* function_decl */
3613 dwarf2out_global_decl,
3614 dwarf2out_type_decl, /* type_decl */
3615 dwarf2out_imported_module_or_decl,
3616 debug_nothing_tree, /* deferred_inline_function */
3617 /* The DWARF 2 backend tries to reduce debugging bloat by not
3618 emitting the abstract description of inline functions until
3619 something tries to reference them. */
3620 dwarf2out_abstract_function, /* outlining_inline_function */
3621 debug_nothing_rtx, /* label */
3622 debug_nothing_int, /* handle_pch */
3623 dwarf2out_var_location,
3624 dwarf2out_switch_text_section,
3625 1 /* start_end_main_source_file */
3629 /* NOTE: In the comments in this file, many references are made to
3630 "Debugging Information Entries". This term is abbreviated as `DIE'
3631 throughout the remainder of this file. */
3633 /* An internal representation of the DWARF output is built, and then
3634 walked to generate the DWARF debugging info. The walk of the internal
3635 representation is done after the entire program has been compiled.
3636 The types below are used to describe the internal representation. */
3638 /* Various DIE's use offsets relative to the beginning of the
3639 .debug_info section to refer to each other. */
3641 typedef long int dw_offset;
3643 /* Define typedefs here to avoid circular dependencies. */
3645 typedef struct dw_attr_struct *dw_attr_ref;
3646 typedef struct dw_line_info_struct *dw_line_info_ref;
3647 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3648 typedef struct pubname_struct *pubname_ref;
3649 typedef struct dw_ranges_struct *dw_ranges_ref;
3651 /* Each entry in the line_info_table maintains the file and
3652 line number associated with the label generated for that
3653 entry. The label gives the PC value associated with
3654 the line number entry. */
3656 typedef struct dw_line_info_struct GTY(())
3658 unsigned long dw_file_num;
3659 unsigned long dw_line_num;
3663 /* Line information for functions in separate sections; each one gets its
3665 typedef struct dw_separate_line_info_struct GTY(())
3667 unsigned long dw_file_num;
3668 unsigned long dw_line_num;
3669 unsigned long function;
3671 dw_separate_line_info_entry;
3673 /* Each DIE attribute has a field specifying the attribute kind,
3674 a link to the next attribute in the chain, and an attribute value.
3675 Attributes are typically linked below the DIE they modify. */
3677 typedef struct dw_attr_struct GTY(())
3679 enum dwarf_attribute dw_attr;
3680 dw_val_node dw_attr_val;
3684 DEF_VEC_O(dw_attr_node);
3685 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3687 /* The Debugging Information Entry (DIE) structure */
3689 typedef struct die_struct GTY(())
3691 enum dwarf_tag die_tag;
3693 VEC(dw_attr_node,gc) * die_attr;
3694 dw_die_ref die_parent;
3695 dw_die_ref die_child;
3697 dw_die_ref die_definition; /* ref from a specification to its definition */
3698 dw_offset die_offset;
3699 unsigned long die_abbrev;
3701 /* Die is used and must not be pruned as unused. */
3702 int die_perennial_p;
3703 unsigned int decl_id;
3707 /* The pubname structure */
3709 typedef struct pubname_struct GTY(())
3716 struct dw_ranges_struct GTY(())
3721 /* The limbo die list structure. */
3722 typedef struct limbo_die_struct GTY(())
3726 struct limbo_die_struct *next;
3730 /* How to start an assembler comment. */
3731 #ifndef ASM_COMMENT_START
3732 #define ASM_COMMENT_START ";#"
3735 /* Define a macro which returns nonzero for a TYPE_DECL which was
3736 implicitly generated for a tagged type.
3738 Note that unlike the gcc front end (which generates a NULL named
3739 TYPE_DECL node for each complete tagged type, each array type, and
3740 each function type node created) the g++ front end generates a
3741 _named_ TYPE_DECL node for each tagged type node created.
3742 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3743 generate a DW_TAG_typedef DIE for them. */
3745 #define TYPE_DECL_IS_STUB(decl) \
3746 (DECL_NAME (decl) == NULL_TREE \
3747 || (DECL_ARTIFICIAL (decl) \
3748 && is_tagged_type (TREE_TYPE (decl)) \
3749 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3750 /* This is necessary for stub decls that \
3751 appear in nested inline functions. */ \
3752 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3753 && (decl_ultimate_origin (decl) \
3754 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3756 /* Information concerning the compilation unit's programming
3757 language, and compiler version. */
3759 /* Fixed size portion of the DWARF compilation unit header. */
3760 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3761 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3763 /* Fixed size portion of public names info. */
3764 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3766 /* Fixed size portion of the address range info. */
3767 #define DWARF_ARANGES_HEADER_SIZE \
3768 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3769 DWARF2_ADDR_SIZE * 2) \
3770 - DWARF_INITIAL_LENGTH_SIZE)
3772 /* Size of padding portion in the address range info. It must be
3773 aligned to twice the pointer size. */
3774 #define DWARF_ARANGES_PAD_SIZE \
3775 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3776 DWARF2_ADDR_SIZE * 2) \
3777 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3779 /* Use assembler line directives if available. */
3780 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3781 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3782 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3784 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3788 /* Minimum line offset in a special line info. opcode.
3789 This value was chosen to give a reasonable range of values. */
3790 #define DWARF_LINE_BASE -10
3792 /* First special line opcode - leave room for the standard opcodes. */
3793 #define DWARF_LINE_OPCODE_BASE 10
3795 /* Range of line offsets in a special line info. opcode. */
3796 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3798 /* Flag that indicates the initial value of the is_stmt_start flag.
3799 In the present implementation, we do not mark any lines as
3800 the beginning of a source statement, because that information
3801 is not made available by the GCC front-end. */
3802 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3804 #ifdef DWARF2_DEBUGGING_INFO
3805 /* This location is used by calc_die_sizes() to keep track
3806 the offset of each DIE within the .debug_info section. */
3807 static unsigned long next_die_offset;
3810 /* Record the root of the DIE's built for the current compilation unit. */
3811 static GTY(()) dw_die_ref comp_unit_die;
3813 /* A list of DIEs with a NULL parent waiting to be relocated. */
3814 static GTY(()) limbo_die_node *limbo_die_list;
3816 /* Filenames referenced by this compilation unit. */
3817 static GTY(()) varray_type file_table;
3818 static GTY(()) varray_type file_table_emitted;
3819 static GTY(()) size_t file_table_last_lookup_index;
3821 /* A hash table of references to DIE's that describe declarations.
3822 The key is a DECL_UID() which is a unique number identifying each decl. */
3823 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3825 /* Node of the variable location list. */
3826 struct var_loc_node GTY ((chain_next ("%h.next")))
3828 rtx GTY (()) var_loc_note;
3829 const char * GTY (()) label;
3830 const char * GTY (()) section_label;
3831 struct var_loc_node * GTY (()) next;
3834 /* Variable location list. */
3835 struct var_loc_list_def GTY (())
3837 struct var_loc_node * GTY (()) first;
3839 /* Do not mark the last element of the chained list because
3840 it is marked through the chain. */
3841 struct var_loc_node * GTY ((skip ("%h"))) last;
3843 /* DECL_UID of the variable decl. */
3844 unsigned int decl_id;
3846 typedef struct var_loc_list_def var_loc_list;
3849 /* Table of decl location linked lists. */
3850 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3852 /* A pointer to the base of a list of references to DIE's that
3853 are uniquely identified by their tag, presence/absence of
3854 children DIE's, and list of attribute/value pairs. */
3855 static GTY((length ("abbrev_die_table_allocated")))
3856 dw_die_ref *abbrev_die_table;
3858 /* Number of elements currently allocated for abbrev_die_table. */
3859 static GTY(()) unsigned abbrev_die_table_allocated;
3861 /* Number of elements in type_die_table currently in use. */
3862 static GTY(()) unsigned abbrev_die_table_in_use;
3864 /* Size (in elements) of increments by which we may expand the
3865 abbrev_die_table. */
3866 #define ABBREV_DIE_TABLE_INCREMENT 256
3868 /* A pointer to the base of a table that contains line information
3869 for each source code line in .text in the compilation unit. */
3870 static GTY((length ("line_info_table_allocated")))
3871 dw_line_info_ref line_info_table;
3873 /* Number of elements currently allocated for line_info_table. */
3874 static GTY(()) unsigned line_info_table_allocated;
3876 /* Number of elements in line_info_table currently in use. */
3877 static GTY(()) unsigned line_info_table_in_use;
3879 /* True if the compilation unit places functions in more than one section. */
3880 static GTY(()) bool have_multiple_function_sections = false;
3882 /* A pointer to the base of a table that contains line information
3883 for each source code line outside of .text in the compilation unit. */
3884 static GTY ((length ("separate_line_info_table_allocated")))
3885 dw_separate_line_info_ref separate_line_info_table;
3887 /* Number of elements currently allocated for separate_line_info_table. */
3888 static GTY(()) unsigned separate_line_info_table_allocated;
3890 /* Number of elements in separate_line_info_table currently in use. */
3891 static GTY(()) unsigned separate_line_info_table_in_use;
3893 /* Size (in elements) of increments by which we may expand the
3895 #define LINE_INFO_TABLE_INCREMENT 1024
3897 /* A pointer to the base of a table that contains a list of publicly
3898 accessible names. */
3899 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3901 /* Number of elements currently allocated for pubname_table. */
3902 static GTY(()) unsigned pubname_table_allocated;
3904 /* Number of elements in pubname_table currently in use. */
3905 static GTY(()) unsigned pubname_table_in_use;
3907 /* Size (in elements) of increments by which we may expand the
3909 #define PUBNAME_TABLE_INCREMENT 64
3911 /* Array of dies for which we should generate .debug_arange info. */
3912 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3914 /* Number of elements currently allocated for arange_table. */
3915 static GTY(()) unsigned arange_table_allocated;
3917 /* Number of elements in arange_table currently in use. */
3918 static GTY(()) unsigned arange_table_in_use;
3920 /* Size (in elements) of increments by which we may expand the
3922 #define ARANGE_TABLE_INCREMENT 64
3924 /* Array of dies for which we should generate .debug_ranges info. */
3925 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3927 /* Number of elements currently allocated for ranges_table. */
3928 static GTY(()) unsigned ranges_table_allocated;
3930 /* Number of elements in ranges_table currently in use. */
3931 static GTY(()) unsigned ranges_table_in_use;
3933 /* Size (in elements) of increments by which we may expand the
3935 #define RANGES_TABLE_INCREMENT 64
3937 /* Whether we have location lists that need outputting */
3938 static GTY(()) bool have_location_lists;
3940 /* Unique label counter. */
3941 static GTY(()) unsigned int loclabel_num;
3943 #ifdef DWARF2_DEBUGGING_INFO
3944 /* Record whether the function being analyzed contains inlined functions. */
3945 static int current_function_has_inlines;
3947 #if 0 && defined (MIPS_DEBUGGING_INFO)
3948 static int comp_unit_has_inlines;
3951 /* Number of file tables emitted in maybe_emit_file(). */
3952 static GTY(()) int emitcount = 0;
3954 /* Number of internal labels generated by gen_internal_sym(). */
3955 static GTY(()) int label_num;
3957 #ifdef DWARF2_DEBUGGING_INFO
3959 /* Offset from the "steady-state frame pointer" to the frame base,
3960 within the current function. */
3961 static HOST_WIDE_INT frame_pointer_fb_offset;
3963 /* Forward declarations for functions defined in this file. */
3965 static int is_pseudo_reg (rtx);
3966 static tree type_main_variant (tree);
3967 static int is_tagged_type (tree);
3968 static const char *dwarf_tag_name (unsigned);
3969 static const char *dwarf_attr_name (unsigned);
3970 static const char *dwarf_form_name (unsigned);
3971 static tree decl_ultimate_origin (tree);
3972 static tree block_ultimate_origin (tree);
3973 static tree decl_class_context (tree);
3974 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3975 static inline enum dw_val_class AT_class (dw_attr_ref);
3976 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3977 static inline unsigned AT_flag (dw_attr_ref);
3978 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3979 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3980 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3981 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3982 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3984 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3985 unsigned int, unsigned char *);
3986 static hashval_t debug_str_do_hash (const void *);
3987 static int debug_str_eq (const void *, const void *);
3988 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3989 static inline const char *AT_string (dw_attr_ref);
3990 static int AT_string_form (dw_attr_ref);
3991 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3992 static void add_AT_specification (dw_die_ref, dw_die_ref);
3993 static inline dw_die_ref AT_ref (dw_attr_ref);
3994 static inline int AT_ref_external (dw_attr_ref);
3995 static inline void set_AT_ref_external (dw_attr_ref, int);
3996 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3997 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3998 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3999 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4001 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4002 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4003 static inline rtx AT_addr (dw_attr_ref);
4004 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4005 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4006 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4007 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4008 unsigned HOST_WIDE_INT);
4009 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4011 static inline const char *AT_lbl (dw_attr_ref);
4012 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4013 static const char *get_AT_low_pc (dw_die_ref);
4014 static const char *get_AT_hi_pc (dw_die_ref);
4015 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4016 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4017 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4018 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4019 static bool is_c_family (void);
4020 static bool is_cxx (void);
4021 static bool is_java (void);
4022 static bool is_fortran (void);
4023 static bool is_ada (void);
4024 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4025 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4026 static inline void free_die (dw_die_ref);
4027 static void add_child_die (dw_die_ref, dw_die_ref);
4028 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4029 static dw_die_ref lookup_type_die (tree);
4030 static void equate_type_number_to_die (tree, dw_die_ref);
4031 static hashval_t decl_die_table_hash (const void *);
4032 static int decl_die_table_eq (const void *, const void *);
4033 static dw_die_ref lookup_decl_die (tree);
4034 static hashval_t decl_loc_table_hash (const void *);
4035 static int decl_loc_table_eq (const void *, const void *);
4036 static var_loc_list *lookup_decl_loc (tree);
4037 static void equate_decl_number_to_die (tree, dw_die_ref);
4038 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4039 static void print_spaces (FILE *);
4040 static void print_die (dw_die_ref, FILE *);
4041 static void print_dwarf_line_table (FILE *);
4042 static void reverse_die_lists (dw_die_ref);
4043 static void reverse_all_dies (dw_die_ref);
4044 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4045 static dw_die_ref pop_compile_unit (dw_die_ref);
4046 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4047 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4048 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4049 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4050 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
4051 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4052 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4053 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4054 static void compute_section_prefix (dw_die_ref);
4055 static int is_type_die (dw_die_ref);
4056 static int is_comdat_die (dw_die_ref);
4057 static int is_symbol_die (dw_die_ref);
4058 static void assign_symbol_names (dw_die_ref);
4059 static void break_out_includes (dw_die_ref);
4060 static hashval_t htab_cu_hash (const void *);
4061 static int htab_cu_eq (const void *, const void *);
4062 static void htab_cu_del (void *);
4063 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4064 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4065 static void add_sibling_attributes (dw_die_ref);
4066 static void build_abbrev_table (dw_die_ref);
4067 static void output_location_lists (dw_die_ref);
4068 static int constant_size (long unsigned);
4069 static unsigned long size_of_die (dw_die_ref);
4070 static void calc_die_sizes (dw_die_ref);
4071 static void mark_dies (dw_die_ref);
4072 static void unmark_dies (dw_die_ref);
4073 static void unmark_all_dies (dw_die_ref);
4074 static unsigned long size_of_pubnames (void);
4075 static unsigned long size_of_aranges (void);
4076 static enum dwarf_form value_format (dw_attr_ref);
4077 static void output_value_format (dw_attr_ref);
4078 static void output_abbrev_section (void);
4079 static void output_die_symbol (dw_die_ref);
4080 static void output_die (dw_die_ref);
4081 static void output_compilation_unit_header (void);
4082 static void output_comp_unit (dw_die_ref, int);
4083 static const char *dwarf2_name (tree, int);
4084 static void add_pubname (tree, dw_die_ref);
4085 static void output_pubnames (void);
4086 static void add_arange (tree, dw_die_ref);
4087 static void output_aranges (void);
4088 static unsigned int add_ranges (tree);
4089 static void output_ranges (void);
4090 static void output_line_info (void);
4091 static void output_file_names (void);
4092 static dw_die_ref base_type_die (tree);
4093 static tree root_type (tree);
4094 static int is_base_type (tree);
4095 static bool is_subrange_type (tree);
4096 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4097 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4098 static int type_is_enum (tree);
4099 static unsigned int dbx_reg_number (rtx);
4100 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4101 static dw_loc_descr_ref reg_loc_descriptor (rtx);
4102 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
4103 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
4104 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4105 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT);
4106 static int is_based_loc (rtx);
4107 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
4108 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
4109 static dw_loc_descr_ref loc_descriptor (rtx);
4110 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4111 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4112 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4113 static tree field_type (tree);
4114 static unsigned int simple_type_align_in_bits (tree);
4115 static unsigned int simple_decl_align_in_bits (tree);
4116 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
4117 static HOST_WIDE_INT field_byte_offset (tree);
4118 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4120 static void add_data_member_location_attribute (dw_die_ref, tree);
4121 static void add_const_value_attribute (dw_die_ref, rtx);
4122 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4123 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4124 static void insert_float (rtx, unsigned char *);
4125 static rtx rtl_for_decl_location (tree);
4126 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4127 enum dwarf_attribute);
4128 static void tree_add_const_value_attribute (dw_die_ref, tree);
4129 static void add_name_attribute (dw_die_ref, const char *);
4130 static void add_comp_dir_attribute (dw_die_ref);
4131 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4132 static void add_subscript_info (dw_die_ref, tree);
4133 static void add_byte_size_attribute (dw_die_ref, tree);
4134 static void add_bit_offset_attribute (dw_die_ref, tree);
4135 static void add_bit_size_attribute (dw_die_ref, tree);
4136 static void add_prototyped_attribute (dw_die_ref, tree);
4137 static void add_abstract_origin_attribute (dw_die_ref, tree);
4138 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4139 static void add_src_coords_attributes (dw_die_ref, tree);
4140 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4141 static void push_decl_scope (tree);
4142 static void pop_decl_scope (void);
4143 static dw_die_ref scope_die_for (tree, dw_die_ref);
4144 static inline int local_scope_p (dw_die_ref);
4145 static inline int class_or_namespace_scope_p (dw_die_ref);
4146 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4147 static void add_calling_convention_attribute (dw_die_ref, tree);
4148 static const char *type_tag (tree);
4149 static tree member_declared_type (tree);
4151 static const char *decl_start_label (tree);
4153 static void gen_array_type_die (tree, dw_die_ref);
4155 static void gen_entry_point_die (tree, dw_die_ref);
4157 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4158 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4159 static void gen_inlined_union_type_die (tree, dw_die_ref);
4160 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4161 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4162 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4163 static void gen_formal_types_die (tree, dw_die_ref);
4164 static void gen_subprogram_die (tree, dw_die_ref);
4165 static void gen_variable_die (tree, dw_die_ref);
4166 static void gen_label_die (tree, dw_die_ref);
4167 static void gen_lexical_block_die (tree, dw_die_ref, int);
4168 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4169 static void gen_field_die (tree, dw_die_ref);
4170 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4171 static dw_die_ref gen_compile_unit_die (const char *);
4172 static void gen_inheritance_die (tree, tree, dw_die_ref);
4173 static void gen_member_die (tree, dw_die_ref);
4174 static void gen_struct_or_union_type_die (tree, dw_die_ref);
4175 static void gen_subroutine_type_die (tree, dw_die_ref);
4176 static void gen_typedef_die (tree, dw_die_ref);
4177 static void gen_type_die (tree, dw_die_ref);
4178 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4179 static void gen_block_die (tree, dw_die_ref, int);
4180 static void decls_for_scope (tree, dw_die_ref, int);
4181 static int is_redundant_typedef (tree);
4182 static void gen_namespace_die (tree);
4183 static void gen_decl_die (tree, dw_die_ref);
4184 static dw_die_ref force_decl_die (tree);
4185 static dw_die_ref force_type_die (tree);
4186 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4187 static void declare_in_namespace (tree, dw_die_ref);
4188 static unsigned lookup_filename (const char *);
4189 static void init_file_table (void);
4190 static void retry_incomplete_types (void);
4191 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4192 static void splice_child_die (dw_die_ref, dw_die_ref);
4193 static int file_info_cmp (const void *, const void *);
4194 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4195 const char *, const char *, unsigned);
4196 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4197 const char *, const char *,
4199 static void output_loc_list (dw_loc_list_ref);
4200 static char *gen_internal_sym (const char *);
4202 static void prune_unmark_dies (dw_die_ref);
4203 static void prune_unused_types_mark (dw_die_ref, int);
4204 static void prune_unused_types_walk (dw_die_ref);
4205 static void prune_unused_types_walk_attribs (dw_die_ref);
4206 static void prune_unused_types_prune (dw_die_ref);
4207 static void prune_unused_types (void);
4208 static int maybe_emit_file (int);
4210 /* Section names used to hold DWARF debugging information. */
4211 #ifndef DEBUG_INFO_SECTION
4212 #define DEBUG_INFO_SECTION ".debug_info"
4214 #ifndef DEBUG_ABBREV_SECTION
4215 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4217 #ifndef DEBUG_ARANGES_SECTION
4218 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4220 #ifndef DEBUG_MACINFO_SECTION
4221 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4223 #ifndef DEBUG_LINE_SECTION
4224 #define DEBUG_LINE_SECTION ".debug_line"
4226 #ifndef DEBUG_LOC_SECTION
4227 #define DEBUG_LOC_SECTION ".debug_loc"
4229 #ifndef DEBUG_PUBNAMES_SECTION
4230 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4232 #ifndef DEBUG_STR_SECTION
4233 #define DEBUG_STR_SECTION ".debug_str"
4235 #ifndef DEBUG_RANGES_SECTION
4236 #define DEBUG_RANGES_SECTION ".debug_ranges"
4239 /* Standard ELF section names for compiled code and data. */
4240 #ifndef TEXT_SECTION_NAME
4241 #define TEXT_SECTION_NAME ".text"
4244 /* Section flags for .debug_str section. */
4245 #define DEBUG_STR_SECTION_FLAGS \
4246 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4247 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4250 /* Labels we insert at beginning sections we can reference instead of
4251 the section names themselves. */
4253 #ifndef TEXT_SECTION_LABEL
4254 #define TEXT_SECTION_LABEL "Ltext"
4256 #ifndef COLD_TEXT_SECTION_LABEL
4257 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4259 #ifndef DEBUG_LINE_SECTION_LABEL
4260 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4262 #ifndef DEBUG_INFO_SECTION_LABEL
4263 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4265 #ifndef DEBUG_ABBREV_SECTION_LABEL
4266 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4268 #ifndef DEBUG_LOC_SECTION_LABEL
4269 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4271 #ifndef DEBUG_RANGES_SECTION_LABEL
4272 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4274 #ifndef DEBUG_MACINFO_SECTION_LABEL
4275 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4278 /* Definitions of defaults for formats and names of various special
4279 (artificial) labels which may be generated within this file (when the -g
4280 options is used and DWARF2_DEBUGGING_INFO is in effect.
4281 If necessary, these may be overridden from within the tm.h file, but
4282 typically, overriding these defaults is unnecessary. */
4284 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4285 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4286 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4287 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4288 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4289 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4290 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4291 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4292 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4293 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4295 #ifndef TEXT_END_LABEL
4296 #define TEXT_END_LABEL "Letext"
4298 #ifndef COLD_END_LABEL
4299 #define COLD_END_LABEL "Letext_cold"
4301 #ifndef BLOCK_BEGIN_LABEL
4302 #define BLOCK_BEGIN_LABEL "LBB"
4304 #ifndef BLOCK_END_LABEL
4305 #define BLOCK_END_LABEL "LBE"
4307 #ifndef LINE_CODE_LABEL
4308 #define LINE_CODE_LABEL "LM"
4310 #ifndef SEPARATE_LINE_CODE_LABEL
4311 #define SEPARATE_LINE_CODE_LABEL "LSM"
4314 /* We allow a language front-end to designate a function that is to be
4315 called to "demangle" any name before it is put into a DIE. */
4317 static const char *(*demangle_name_func) (const char *);
4320 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4322 demangle_name_func = func;
4325 /* Test if rtl node points to a pseudo register. */
4328 is_pseudo_reg (rtx rtl)
4330 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4331 || (GET_CODE (rtl) == SUBREG
4332 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4335 /* Return a reference to a type, with its const and volatile qualifiers
4339 type_main_variant (tree type)
4341 type = TYPE_MAIN_VARIANT (type);
4343 /* ??? There really should be only one main variant among any group of
4344 variants of a given type (and all of the MAIN_VARIANT values for all
4345 members of the group should point to that one type) but sometimes the C
4346 front-end messes this up for array types, so we work around that bug
4348 if (TREE_CODE (type) == ARRAY_TYPE)
4349 while (type != TYPE_MAIN_VARIANT (type))
4350 type = TYPE_MAIN_VARIANT (type);
4355 /* Return nonzero if the given type node represents a tagged type. */
4358 is_tagged_type (tree type)
4360 enum tree_code code = TREE_CODE (type);
4362 return (code == RECORD_TYPE || code == UNION_TYPE
4363 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4366 /* Convert a DIE tag into its string name. */
4369 dwarf_tag_name (unsigned int tag)
4373 case DW_TAG_padding:
4374 return "DW_TAG_padding";
4375 case DW_TAG_array_type:
4376 return "DW_TAG_array_type";
4377 case DW_TAG_class_type:
4378 return "DW_TAG_class_type";
4379 case DW_TAG_entry_point:
4380 return "DW_TAG_entry_point";
4381 case DW_TAG_enumeration_type:
4382 return "DW_TAG_enumeration_type";
4383 case DW_TAG_formal_parameter:
4384 return "DW_TAG_formal_parameter";
4385 case DW_TAG_imported_declaration:
4386 return "DW_TAG_imported_declaration";
4388 return "DW_TAG_label";
4389 case DW_TAG_lexical_block:
4390 return "DW_TAG_lexical_block";
4392 return "DW_TAG_member";
4393 case DW_TAG_pointer_type:
4394 return "DW_TAG_pointer_type";
4395 case DW_TAG_reference_type:
4396 return "DW_TAG_reference_type";
4397 case DW_TAG_compile_unit:
4398 return "DW_TAG_compile_unit";
4399 case DW_TAG_string_type:
4400 return "DW_TAG_string_type";
4401 case DW_TAG_structure_type:
4402 return "DW_TAG_structure_type";
4403 case DW_TAG_subroutine_type:
4404 return "DW_TAG_subroutine_type";
4405 case DW_TAG_typedef:
4406 return "DW_TAG_typedef";
4407 case DW_TAG_union_type:
4408 return "DW_TAG_union_type";
4409 case DW_TAG_unspecified_parameters:
4410 return "DW_TAG_unspecified_parameters";
4411 case DW_TAG_variant:
4412 return "DW_TAG_variant";
4413 case DW_TAG_common_block:
4414 return "DW_TAG_common_block";
4415 case DW_TAG_common_inclusion:
4416 return "DW_TAG_common_inclusion";
4417 case DW_TAG_inheritance:
4418 return "DW_TAG_inheritance";
4419 case DW_TAG_inlined_subroutine:
4420 return "DW_TAG_inlined_subroutine";
4422 return "DW_TAG_module";
4423 case DW_TAG_ptr_to_member_type:
4424 return "DW_TAG_ptr_to_member_type";
4425 case DW_TAG_set_type:
4426 return "DW_TAG_set_type";
4427 case DW_TAG_subrange_type:
4428 return "DW_TAG_subrange_type";
4429 case DW_TAG_with_stmt:
4430 return "DW_TAG_with_stmt";
4431 case DW_TAG_access_declaration:
4432 return "DW_TAG_access_declaration";
4433 case DW_TAG_base_type:
4434 return "DW_TAG_base_type";
4435 case DW_TAG_catch_block:
4436 return "DW_TAG_catch_block";
4437 case DW_TAG_const_type:
4438 return "DW_TAG_const_type";
4439 case DW_TAG_constant:
4440 return "DW_TAG_constant";
4441 case DW_TAG_enumerator:
4442 return "DW_TAG_enumerator";
4443 case DW_TAG_file_type:
4444 return "DW_TAG_file_type";
4446 return "DW_TAG_friend";
4447 case DW_TAG_namelist:
4448 return "DW_TAG_namelist";
4449 case DW_TAG_namelist_item:
4450 return "DW_TAG_namelist_item";
4451 case DW_TAG_namespace:
4452 return "DW_TAG_namespace";
4453 case DW_TAG_packed_type:
4454 return "DW_TAG_packed_type";
4455 case DW_TAG_subprogram:
4456 return "DW_TAG_subprogram";
4457 case DW_TAG_template_type_param:
4458 return "DW_TAG_template_type_param";
4459 case DW_TAG_template_value_param:
4460 return "DW_TAG_template_value_param";
4461 case DW_TAG_thrown_type:
4462 return "DW_TAG_thrown_type";
4463 case DW_TAG_try_block:
4464 return "DW_TAG_try_block";
4465 case DW_TAG_variant_part:
4466 return "DW_TAG_variant_part";
4467 case DW_TAG_variable:
4468 return "DW_TAG_variable";
4469 case DW_TAG_volatile_type:
4470 return "DW_TAG_volatile_type";
4471 case DW_TAG_imported_module:
4472 return "DW_TAG_imported_module";
4473 case DW_TAG_MIPS_loop:
4474 return "DW_TAG_MIPS_loop";
4475 case DW_TAG_format_label:
4476 return "DW_TAG_format_label";
4477 case DW_TAG_function_template:
4478 return "DW_TAG_function_template";
4479 case DW_TAG_class_template:
4480 return "DW_TAG_class_template";
4481 case DW_TAG_GNU_BINCL:
4482 return "DW_TAG_GNU_BINCL";
4483 case DW_TAG_GNU_EINCL:
4484 return "DW_TAG_GNU_EINCL";
4486 return "DW_TAG_<unknown>";
4490 /* Convert a DWARF attribute code into its string name. */
4493 dwarf_attr_name (unsigned int attr)
4498 return "DW_AT_sibling";
4499 case DW_AT_location:
4500 return "DW_AT_location";
4502 return "DW_AT_name";
4503 case DW_AT_ordering:
4504 return "DW_AT_ordering";
4505 case DW_AT_subscr_data:
4506 return "DW_AT_subscr_data";
4507 case DW_AT_byte_size:
4508 return "DW_AT_byte_size";
4509 case DW_AT_bit_offset:
4510 return "DW_AT_bit_offset";
4511 case DW_AT_bit_size:
4512 return "DW_AT_bit_size";
4513 case DW_AT_element_list:
4514 return "DW_AT_element_list";
4515 case DW_AT_stmt_list:
4516 return "DW_AT_stmt_list";
4518 return "DW_AT_low_pc";
4520 return "DW_AT_high_pc";
4521 case DW_AT_language:
4522 return "DW_AT_language";
4524 return "DW_AT_member";
4526 return "DW_AT_discr";
4527 case DW_AT_discr_value:
4528 return "DW_AT_discr_value";
4529 case DW_AT_visibility:
4530 return "DW_AT_visibility";
4532 return "DW_AT_import";
4533 case DW_AT_string_length:
4534 return "DW_AT_string_length";
4535 case DW_AT_common_reference:
4536 return "DW_AT_common_reference";
4537 case DW_AT_comp_dir:
4538 return "DW_AT_comp_dir";
4539 case DW_AT_const_value:
4540 return "DW_AT_const_value";
4541 case DW_AT_containing_type:
4542 return "DW_AT_containing_type";
4543 case DW_AT_default_value:
4544 return "DW_AT_default_value";
4546 return "DW_AT_inline";
4547 case DW_AT_is_optional:
4548 return "DW_AT_is_optional";
4549 case DW_AT_lower_bound:
4550 return "DW_AT_lower_bound";
4551 case DW_AT_producer:
4552 return "DW_AT_producer";
4553 case DW_AT_prototyped:
4554 return "DW_AT_prototyped";
4555 case DW_AT_return_addr:
4556 return "DW_AT_return_addr";
4557 case DW_AT_start_scope:
4558 return "DW_AT_start_scope";
4559 case DW_AT_stride_size:
4560 return "DW_AT_stride_size";
4561 case DW_AT_upper_bound:
4562 return "DW_AT_upper_bound";
4563 case DW_AT_abstract_origin:
4564 return "DW_AT_abstract_origin";
4565 case DW_AT_accessibility:
4566 return "DW_AT_accessibility";
4567 case DW_AT_address_class:
4568 return "DW_AT_address_class";
4569 case DW_AT_artificial:
4570 return "DW_AT_artificial";
4571 case DW_AT_base_types:
4572 return "DW_AT_base_types";
4573 case DW_AT_calling_convention:
4574 return "DW_AT_calling_convention";
4576 return "DW_AT_count";
4577 case DW_AT_data_member_location:
4578 return "DW_AT_data_member_location";
4579 case DW_AT_decl_column:
4580 return "DW_AT_decl_column";
4581 case DW_AT_decl_file:
4582 return "DW_AT_decl_file";
4583 case DW_AT_decl_line:
4584 return "DW_AT_decl_line";
4585 case DW_AT_declaration:
4586 return "DW_AT_declaration";
4587 case DW_AT_discr_list:
4588 return "DW_AT_discr_list";
4589 case DW_AT_encoding:
4590 return "DW_AT_encoding";
4591 case DW_AT_external:
4592 return "DW_AT_external";
4593 case DW_AT_frame_base:
4594 return "DW_AT_frame_base";
4596 return "DW_AT_friend";
4597 case DW_AT_identifier_case:
4598 return "DW_AT_identifier_case";
4599 case DW_AT_macro_info:
4600 return "DW_AT_macro_info";
4601 case DW_AT_namelist_items:
4602 return "DW_AT_namelist_items";
4603 case DW_AT_priority:
4604 return "DW_AT_priority";
4606 return "DW_AT_segment";
4607 case DW_AT_specification:
4608 return "DW_AT_specification";
4609 case DW_AT_static_link:
4610 return "DW_AT_static_link";
4612 return "DW_AT_type";
4613 case DW_AT_use_location:
4614 return "DW_AT_use_location";
4615 case DW_AT_variable_parameter:
4616 return "DW_AT_variable_parameter";
4617 case DW_AT_virtuality:
4618 return "DW_AT_virtuality";
4619 case DW_AT_vtable_elem_location:
4620 return "DW_AT_vtable_elem_location";
4622 case DW_AT_allocated:
4623 return "DW_AT_allocated";
4624 case DW_AT_associated:
4625 return "DW_AT_associated";
4626 case DW_AT_data_location:
4627 return "DW_AT_data_location";
4629 return "DW_AT_stride";
4630 case DW_AT_entry_pc:
4631 return "DW_AT_entry_pc";
4632 case DW_AT_use_UTF8:
4633 return "DW_AT_use_UTF8";
4634 case DW_AT_extension:
4635 return "DW_AT_extension";
4637 return "DW_AT_ranges";
4638 case DW_AT_trampoline:
4639 return "DW_AT_trampoline";
4640 case DW_AT_call_column:
4641 return "DW_AT_call_column";
4642 case DW_AT_call_file:
4643 return "DW_AT_call_file";
4644 case DW_AT_call_line:
4645 return "DW_AT_call_line";
4647 case DW_AT_MIPS_fde:
4648 return "DW_AT_MIPS_fde";
4649 case DW_AT_MIPS_loop_begin:
4650 return "DW_AT_MIPS_loop_begin";
4651 case DW_AT_MIPS_tail_loop_begin:
4652 return "DW_AT_MIPS_tail_loop_begin";
4653 case DW_AT_MIPS_epilog_begin:
4654 return "DW_AT_MIPS_epilog_begin";
4655 case DW_AT_MIPS_loop_unroll_factor:
4656 return "DW_AT_MIPS_loop_unroll_factor";
4657 case DW_AT_MIPS_software_pipeline_depth:
4658 return "DW_AT_MIPS_software_pipeline_depth";
4659 case DW_AT_MIPS_linkage_name:
4660 return "DW_AT_MIPS_linkage_name";
4661 case DW_AT_MIPS_stride:
4662 return "DW_AT_MIPS_stride";
4663 case DW_AT_MIPS_abstract_name:
4664 return "DW_AT_MIPS_abstract_name";
4665 case DW_AT_MIPS_clone_origin:
4666 return "DW_AT_MIPS_clone_origin";
4667 case DW_AT_MIPS_has_inlines:
4668 return "DW_AT_MIPS_has_inlines";
4670 case DW_AT_sf_names:
4671 return "DW_AT_sf_names";
4672 case DW_AT_src_info:
4673 return "DW_AT_src_info";
4674 case DW_AT_mac_info:
4675 return "DW_AT_mac_info";
4676 case DW_AT_src_coords:
4677 return "DW_AT_src_coords";
4678 case DW_AT_body_begin:
4679 return "DW_AT_body_begin";
4680 case DW_AT_body_end:
4681 return "DW_AT_body_end";
4682 case DW_AT_GNU_vector:
4683 return "DW_AT_GNU_vector";
4685 case DW_AT_VMS_rtnbeg_pd_address:
4686 return "DW_AT_VMS_rtnbeg_pd_address";
4689 return "DW_AT_<unknown>";
4693 /* Convert a DWARF value form code into its string name. */
4696 dwarf_form_name (unsigned int form)
4701 return "DW_FORM_addr";
4702 case DW_FORM_block2:
4703 return "DW_FORM_block2";
4704 case DW_FORM_block4:
4705 return "DW_FORM_block4";
4707 return "DW_FORM_data2";
4709 return "DW_FORM_data4";
4711 return "DW_FORM_data8";
4712 case DW_FORM_string:
4713 return "DW_FORM_string";
4715 return "DW_FORM_block";
4716 case DW_FORM_block1:
4717 return "DW_FORM_block1";
4719 return "DW_FORM_data1";
4721 return "DW_FORM_flag";
4723 return "DW_FORM_sdata";
4725 return "DW_FORM_strp";
4727 return "DW_FORM_udata";
4728 case DW_FORM_ref_addr:
4729 return "DW_FORM_ref_addr";
4731 return "DW_FORM_ref1";
4733 return "DW_FORM_ref2";
4735 return "DW_FORM_ref4";
4737 return "DW_FORM_ref8";
4738 case DW_FORM_ref_udata:
4739 return "DW_FORM_ref_udata";
4740 case DW_FORM_indirect:
4741 return "DW_FORM_indirect";
4743 return "DW_FORM_<unknown>";
4747 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4748 instance of an inlined instance of a decl which is local to an inline
4749 function, so we have to trace all of the way back through the origin chain
4750 to find out what sort of node actually served as the original seed for the
4754 decl_ultimate_origin (tree decl)
4756 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4759 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4760 nodes in the function to point to themselves; ignore that if
4761 we're trying to output the abstract instance of this function. */
4762 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4765 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4766 most distant ancestor, this should never happen. */
4767 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4769 return DECL_ABSTRACT_ORIGIN (decl);
4772 /* Determine the "ultimate origin" of a block. The block may be an inlined
4773 instance of an inlined instance of a block which is local to an inline
4774 function, so we have to trace all of the way back through the origin chain
4775 to find out what sort of node actually served as the original seed for the
4779 block_ultimate_origin (tree block)
4781 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4783 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4784 nodes in the function to point to themselves; ignore that if
4785 we're trying to output the abstract instance of this function. */
4786 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4789 if (immediate_origin == NULL_TREE)
4794 tree lookahead = immediate_origin;
4798 ret_val = lookahead;
4799 lookahead = (TREE_CODE (ret_val) == BLOCK
4800 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4802 while (lookahead != NULL && lookahead != ret_val);
4804 /* The block's abstract origin chain may not be the *ultimate* origin of
4805 the block. It could lead to a DECL that has an abstract origin set.
4806 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4807 will give us if it has one). Note that DECL's abstract origins are
4808 supposed to be the most distant ancestor (or so decl_ultimate_origin
4809 claims), so we don't need to loop following the DECL origins. */
4810 if (DECL_P (ret_val))
4811 return DECL_ORIGIN (ret_val);
4817 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4818 of a virtual function may refer to a base class, so we check the 'this'
4822 decl_class_context (tree decl)
4824 tree context = NULL_TREE;
4826 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4827 context = DECL_CONTEXT (decl);
4829 context = TYPE_MAIN_VARIANT
4830 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4832 if (context && !TYPE_P (context))
4833 context = NULL_TREE;
4838 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4839 addition order, and correct that in reverse_all_dies. */
4842 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4844 /* Maybe this should be an assert? */
4848 if (die->die_attr == NULL)
4849 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
4850 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
4853 static inline enum dw_val_class
4854 AT_class (dw_attr_ref a)
4856 return a->dw_attr_val.val_class;
4859 /* Add a flag value attribute to a DIE. */
4862 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4866 attr.dw_attr = attr_kind;
4867 attr.dw_attr_val.val_class = dw_val_class_flag;
4868 attr.dw_attr_val.v.val_flag = flag;
4869 add_dwarf_attr (die, &attr);
4872 static inline unsigned
4873 AT_flag (dw_attr_ref a)
4875 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4876 return a->dw_attr_val.v.val_flag;
4879 /* Add a signed integer attribute value to a DIE. */
4882 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4886 attr.dw_attr = attr_kind;
4887 attr.dw_attr_val.val_class = dw_val_class_const;
4888 attr.dw_attr_val.v.val_int = int_val;
4889 add_dwarf_attr (die, &attr);
4892 static inline HOST_WIDE_INT
4893 AT_int (dw_attr_ref a)
4895 gcc_assert (a && AT_class (a) == dw_val_class_const);
4896 return a->dw_attr_val.v.val_int;
4899 /* Add an unsigned integer attribute value to a DIE. */
4902 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4903 unsigned HOST_WIDE_INT unsigned_val)
4907 attr.dw_attr = attr_kind;
4908 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4909 attr.dw_attr_val.v.val_unsigned = unsigned_val;
4910 add_dwarf_attr (die, &attr);
4913 static inline unsigned HOST_WIDE_INT
4914 AT_unsigned (dw_attr_ref a)
4916 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4917 return a->dw_attr_val.v.val_unsigned;
4920 /* Add an unsigned double integer attribute value to a DIE. */
4923 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4924 long unsigned int val_hi, long unsigned int val_low)
4928 attr.dw_attr = attr_kind;
4929 attr.dw_attr_val.val_class = dw_val_class_long_long;
4930 attr.dw_attr_val.v.val_long_long.hi = val_hi;
4931 attr.dw_attr_val.v.val_long_long.low = val_low;
4932 add_dwarf_attr (die, &attr);
4935 /* Add a floating point attribute value to a DIE and return it. */
4938 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4939 unsigned int length, unsigned int elt_size, unsigned char *array)
4943 attr.dw_attr = attr_kind;
4944 attr.dw_attr_val.val_class = dw_val_class_vec;
4945 attr.dw_attr_val.v.val_vec.length = length;
4946 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4947 attr.dw_attr_val.v.val_vec.array = array;
4948 add_dwarf_attr (die, &attr);
4951 /* Hash and equality functions for debug_str_hash. */
4954 debug_str_do_hash (const void *x)
4956 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4960 debug_str_eq (const void *x1, const void *x2)
4962 return strcmp ((((const struct indirect_string_node *)x1)->str),
4963 (const char *)x2) == 0;
4966 /* Add a string attribute value to a DIE. */
4969 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4972 struct indirect_string_node *node;
4975 if (! debug_str_hash)
4976 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4977 debug_str_eq, NULL);
4979 slot = htab_find_slot_with_hash (debug_str_hash, str,
4980 htab_hash_string (str), INSERT);
4982 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4983 node = (struct indirect_string_node *) *slot;
4984 node->str = ggc_strdup (str);
4987 attr.dw_attr = attr_kind;
4988 attr.dw_attr_val.val_class = dw_val_class_str;
4989 attr.dw_attr_val.v.val_str = node;
4990 add_dwarf_attr (die, &attr);
4993 static inline const char *
4994 AT_string (dw_attr_ref a)
4996 gcc_assert (a && AT_class (a) == dw_val_class_str);
4997 return a->dw_attr_val.v.val_str->str;
5000 /* Find out whether a string should be output inline in DIE
5001 or out-of-line in .debug_str section. */
5004 AT_string_form (dw_attr_ref a)
5006 struct indirect_string_node *node;
5010 gcc_assert (a && AT_class (a) == dw_val_class_str);
5012 node = a->dw_attr_val.v.val_str;
5016 len = strlen (node->str) + 1;
5018 /* If the string is shorter or equal to the size of the reference, it is
5019 always better to put it inline. */
5020 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5021 return node->form = DW_FORM_string;
5023 /* If we cannot expect the linker to merge strings in .debug_str
5024 section, only put it into .debug_str if it is worth even in this
5026 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5027 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5028 return node->form = DW_FORM_string;
5030 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5031 ++dw2_string_counter;
5032 node->label = xstrdup (label);
5034 return node->form = DW_FORM_strp;
5037 /* Add a DIE reference attribute value to a DIE. */
5040 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5044 attr.dw_attr = attr_kind;
5045 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5046 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5047 attr.dw_attr_val.v.val_die_ref.external = 0;
5048 add_dwarf_attr (die, &attr);
5051 /* Add an AT_specification attribute to a DIE, and also make the back
5052 pointer from the specification to the definition. */
5055 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5057 add_AT_die_ref (die, DW_AT_specification, targ_die);
5058 gcc_assert (!targ_die->die_definition);
5059 targ_die->die_definition = die;
5062 static inline dw_die_ref
5063 AT_ref (dw_attr_ref a)
5065 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5066 return a->dw_attr_val.v.val_die_ref.die;
5070 AT_ref_external (dw_attr_ref a)
5072 if (a && AT_class (a) == dw_val_class_die_ref)
5073 return a->dw_attr_val.v.val_die_ref.external;
5079 set_AT_ref_external (dw_attr_ref a, int i)
5081 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5082 a->dw_attr_val.v.val_die_ref.external = i;
5085 /* Add an FDE reference attribute value to a DIE. */
5088 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5092 attr.dw_attr = attr_kind;
5093 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5094 attr.dw_attr_val.v.val_fde_index = targ_fde;
5095 add_dwarf_attr (die, &attr);
5098 /* Add a location description attribute value to a DIE. */
5101 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5105 attr.dw_attr = attr_kind;
5106 attr.dw_attr_val.val_class = dw_val_class_loc;
5107 attr.dw_attr_val.v.val_loc = loc;
5108 add_dwarf_attr (die, &attr);
5111 static inline dw_loc_descr_ref
5112 AT_loc (dw_attr_ref a)
5114 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5115 return a->dw_attr_val.v.val_loc;
5119 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5123 attr.dw_attr = attr_kind;
5124 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5125 attr.dw_attr_val.v.val_loc_list = loc_list;
5126 add_dwarf_attr (die, &attr);
5127 have_location_lists = true;
5130 static inline dw_loc_list_ref
5131 AT_loc_list (dw_attr_ref a)
5133 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5134 return a->dw_attr_val.v.val_loc_list;
5137 /* Add an address constant attribute value to a DIE. */
5140 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5144 attr.dw_attr = attr_kind;
5145 attr.dw_attr_val.val_class = dw_val_class_addr;
5146 attr.dw_attr_val.v.val_addr = addr;
5147 add_dwarf_attr (die, &attr);
5151 AT_addr (dw_attr_ref a)
5153 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5154 return a->dw_attr_val.v.val_addr;
5157 /* Add a label identifier attribute value to a DIE. */
5160 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5164 attr.dw_attr = attr_kind;
5165 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5166 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5167 add_dwarf_attr (die, &attr);
5170 /* Add a section offset attribute value to a DIE, an offset into the
5171 debug_line section. */
5174 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5179 attr.dw_attr = attr_kind;
5180 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5181 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5182 add_dwarf_attr (die, &attr);
5185 /* Add a section offset attribute value to a DIE, an offset into the
5186 debug_macinfo section. */
5189 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5194 attr.dw_attr = attr_kind;
5195 attr.dw_attr_val.val_class = dw_val_class_macptr;
5196 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5197 add_dwarf_attr (die, &attr);
5200 /* Add an offset attribute value to a DIE. */
5203 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5204 unsigned HOST_WIDE_INT offset)
5208 attr.dw_attr = attr_kind;
5209 attr.dw_attr_val.val_class = dw_val_class_offset;
5210 attr.dw_attr_val.v.val_offset = offset;
5211 add_dwarf_attr (die, &attr);
5214 /* Add an range_list attribute value to a DIE. */
5217 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5218 long unsigned int offset)
5222 attr.dw_attr = attr_kind;
5223 attr.dw_attr_val.val_class = dw_val_class_range_list;
5224 attr.dw_attr_val.v.val_offset = offset;
5225 add_dwarf_attr (die, &attr);
5228 static inline const char *
5229 AT_lbl (dw_attr_ref a)
5231 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5232 || AT_class (a) == dw_val_class_lineptr
5233 || AT_class (a) == dw_val_class_macptr));
5234 return a->dw_attr_val.v.val_lbl_id;
5237 /* Get the attribute of type attr_kind. */
5240 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5244 dw_die_ref spec = NULL;
5249 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5250 if (a->dw_attr == attr_kind)
5252 else if (a->dw_attr == DW_AT_specification
5253 || a->dw_attr == DW_AT_abstract_origin)
5257 return get_AT (spec, attr_kind);
5262 /* Return the "low pc" attribute value, typically associated with a subprogram
5263 DIE. Return null if the "low pc" attribute is either not present, or if it
5264 cannot be represented as an assembler label identifier. */
5266 static inline const char *
5267 get_AT_low_pc (dw_die_ref die)
5269 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5271 return a ? AT_lbl (a) : NULL;
5274 /* Return the "high pc" attribute value, typically associated with a subprogram
5275 DIE. Return null if the "high pc" attribute is either not present, or if it
5276 cannot be represented as an assembler label identifier. */
5278 static inline const char *
5279 get_AT_hi_pc (dw_die_ref die)
5281 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5283 return a ? AT_lbl (a) : NULL;
5286 /* Return the value of the string attribute designated by ATTR_KIND, or
5287 NULL if it is not present. */
5289 static inline const char *
5290 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5292 dw_attr_ref a = get_AT (die, attr_kind);
5294 return a ? AT_string (a) : NULL;
5297 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5298 if it is not present. */
5301 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5303 dw_attr_ref a = get_AT (die, attr_kind);
5305 return a ? AT_flag (a) : 0;
5308 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5309 if it is not present. */
5311 static inline unsigned
5312 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5314 dw_attr_ref a = get_AT (die, attr_kind);
5316 return a ? AT_unsigned (a) : 0;
5319 static inline dw_die_ref
5320 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5322 dw_attr_ref a = get_AT (die, attr_kind);
5324 return a ? AT_ref (a) : NULL;
5327 /* Return TRUE if the language is C or C++. */
5332 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5334 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5335 || lang == DW_LANG_C99
5336 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5339 /* Return TRUE if the language is C++. */
5344 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5346 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5349 /* Return TRUE if the language is Fortran. */
5354 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5356 return (lang == DW_LANG_Fortran77
5357 || lang == DW_LANG_Fortran90
5358 || lang == DW_LANG_Fortran95);
5361 /* Return TRUE if the language is Java. */
5366 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5368 return lang == DW_LANG_Java;
5371 /* Return TRUE if the language is Ada. */
5376 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5378 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5381 /* Free up the memory used by A. */
5383 static inline void free_AT (dw_attr_ref);
5385 free_AT (dw_attr_ref a)
5387 if (AT_class (a) == dw_val_class_str)
5388 if (a->dw_attr_val.v.val_str->refcount)
5389 a->dw_attr_val.v.val_str->refcount--;
5392 /* Remove the specified attribute if present. */
5395 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5403 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5404 if (a->dw_attr == attr_kind)
5407 /* VEC_ordered_remove should help reduce the number of abbrevs
5409 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5414 /* Remove child die whose die_tag is specified tag. */
5417 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5419 dw_die_ref current, prev, next;
5420 current = die->die_child;
5422 while (current != NULL)
5424 if (current->die_tag == tag)
5426 next = current->die_sib;
5428 die->die_child = next;
5430 prev->die_sib = next;
5437 current = current->die_sib;
5442 /* Free up the memory used by DIE, by removing its children and
5443 anything associated with its attributes. DIEs are garbage
5444 collected, so there is no actual freeing to do; the only real work is
5445 to decrease string reference counts. */
5448 free_die (dw_die_ref die)
5450 dw_die_ref child_die = die->die_child;
5452 die->die_child = NULL;
5454 while (child_die != NULL)
5456 dw_die_ref tmp_die = child_die;
5460 child_die = child_die->die_sib;
5462 for (ix = 0; VEC_iterate (dw_attr_node, tmp_die->die_attr, ix, a); ix++)
5469 /* Add a child DIE below its parent. We build the lists up in reverse
5470 addition order, and correct that in reverse_all_dies. */
5473 add_child_die (dw_die_ref die, dw_die_ref child_die)
5475 if (die != NULL && child_die != NULL)
5477 gcc_assert (die != child_die);
5479 child_die->die_parent = die;
5480 child_die->die_sib = die->die_child;
5481 die->die_child = child_die;
5485 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5486 is the specification, to the front of PARENT's list of children. */
5489 splice_child_die (dw_die_ref parent, dw_die_ref child)
5493 /* We want the declaration DIE from inside the class, not the
5494 specification DIE at toplevel. */
5495 if (child->die_parent != parent)
5497 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5503 gcc_assert (child->die_parent == parent
5504 || (child->die_parent
5505 == get_AT_ref (parent, DW_AT_specification)));
5507 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5510 *p = child->die_sib;
5514 child->die_parent = parent;
5515 child->die_sib = parent->die_child;
5516 parent->die_child = child;
5519 /* Return a pointer to a newly created DIE node. */
5521 static inline dw_die_ref
5522 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5524 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5526 die->die_tag = tag_value;
5528 if (parent_die != NULL)
5529 add_child_die (parent_die, die);
5532 limbo_die_node *limbo_node;
5534 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5535 limbo_node->die = die;
5536 limbo_node->created_for = t;
5537 limbo_node->next = limbo_die_list;
5538 limbo_die_list = limbo_node;
5544 /* Return the DIE associated with the given type specifier. */
5546 static inline dw_die_ref
5547 lookup_type_die (tree type)
5549 return TYPE_SYMTAB_DIE (type);
5552 /* Equate a DIE to a given type specifier. */
5555 equate_type_number_to_die (tree type, dw_die_ref type_die)
5557 TYPE_SYMTAB_DIE (type) = type_die;
5560 /* Returns a hash value for X (which really is a die_struct). */
5563 decl_die_table_hash (const void *x)
5565 return (hashval_t) ((const dw_die_ref) x)->decl_id;
5568 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5571 decl_die_table_eq (const void *x, const void *y)
5573 return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
5576 /* Return the DIE associated with a given declaration. */
5578 static inline dw_die_ref
5579 lookup_decl_die (tree decl)
5581 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5584 /* Returns a hash value for X (which really is a var_loc_list). */
5587 decl_loc_table_hash (const void *x)
5589 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5592 /* Return nonzero if decl_id of var_loc_list X is the same as
5596 decl_loc_table_eq (const void *x, const void *y)
5598 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y));
5601 /* Return the var_loc list associated with a given declaration. */
5603 static inline var_loc_list *
5604 lookup_decl_loc (tree decl)
5606 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5609 /* Equate a DIE to a particular declaration. */
5612 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5614 unsigned int decl_id = DECL_UID (decl);
5617 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5619 decl_die->decl_id = decl_id;
5622 /* Add a variable location node to the linked list for DECL. */
5625 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5627 unsigned int decl_id = DECL_UID (decl);
5631 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5634 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5635 temp->decl_id = decl_id;
5643 /* If the current location is the same as the end of the list,
5644 we have nothing to do. */
5645 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5646 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5648 /* Add LOC to the end of list and update LAST. */
5649 temp->last->next = loc;
5653 /* Do not add empty location to the beginning of the list. */
5654 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5661 /* Keep track of the number of spaces used to indent the
5662 output of the debugging routines that print the structure of
5663 the DIE internal representation. */
5664 static int print_indent;
5666 /* Indent the line the number of spaces given by print_indent. */
5669 print_spaces (FILE *outfile)
5671 fprintf (outfile, "%*s", print_indent, "");
5674 /* Print the information associated with a given DIE, and its children.
5675 This routine is a debugging aid only. */
5678 print_die (dw_die_ref die, FILE *outfile)
5684 print_spaces (outfile);
5685 fprintf (outfile, "DIE %4lu: %s\n",
5686 die->die_offset, dwarf_tag_name (die->die_tag));
5687 print_spaces (outfile);
5688 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5689 fprintf (outfile, " offset: %lu\n", die->die_offset);
5691 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5693 print_spaces (outfile);
5694 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5696 switch (AT_class (a))
5698 case dw_val_class_addr:
5699 fprintf (outfile, "address");
5701 case dw_val_class_offset:
5702 fprintf (outfile, "offset");
5704 case dw_val_class_loc:
5705 fprintf (outfile, "location descriptor");
5707 case dw_val_class_loc_list:
5708 fprintf (outfile, "location list -> label:%s",
5709 AT_loc_list (a)->ll_symbol);
5711 case dw_val_class_range_list:
5712 fprintf (outfile, "range list");
5714 case dw_val_class_const:
5715 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5717 case dw_val_class_unsigned_const:
5718 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5720 case dw_val_class_long_long:
5721 fprintf (outfile, "constant (%lu,%lu)",
5722 a->dw_attr_val.v.val_long_long.hi,
5723 a->dw_attr_val.v.val_long_long.low);
5725 case dw_val_class_vec:
5726 fprintf (outfile, "floating-point or vector constant");
5728 case dw_val_class_flag:
5729 fprintf (outfile, "%u", AT_flag (a));
5731 case dw_val_class_die_ref:
5732 if (AT_ref (a) != NULL)
5734 if (AT_ref (a)->die_symbol)
5735 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5737 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5740 fprintf (outfile, "die -> <null>");
5742 case dw_val_class_lbl_id:
5743 case dw_val_class_lineptr:
5744 case dw_val_class_macptr:
5745 fprintf (outfile, "label: %s", AT_lbl (a));
5747 case dw_val_class_str:
5748 if (AT_string (a) != NULL)
5749 fprintf (outfile, "\"%s\"", AT_string (a));
5751 fprintf (outfile, "<null>");
5757 fprintf (outfile, "\n");
5760 if (die->die_child != NULL)
5763 for (c = die->die_child; c != NULL; c = c->die_sib)
5764 print_die (c, outfile);
5768 if (print_indent == 0)
5769 fprintf (outfile, "\n");
5772 /* Print the contents of the source code line number correspondence table.
5773 This routine is a debugging aid only. */
5776 print_dwarf_line_table (FILE *outfile)
5779 dw_line_info_ref line_info;
5781 fprintf (outfile, "\n\nDWARF source line information\n");
5782 for (i = 1; i < line_info_table_in_use; i++)
5784 line_info = &line_info_table[i];
5785 fprintf (outfile, "%5d: ", i);
5786 fprintf (outfile, "%-20s",
5787 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5788 fprintf (outfile, "%6ld", line_info->dw_line_num);
5789 fprintf (outfile, "\n");
5792 fprintf (outfile, "\n\n");
5795 /* Print the information collected for a given DIE. */
5798 debug_dwarf_die (dw_die_ref die)
5800 print_die (die, stderr);
5803 /* Print all DWARF information collected for the compilation unit.
5804 This routine is a debugging aid only. */
5810 print_die (comp_unit_die, stderr);
5811 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5812 print_dwarf_line_table (stderr);
5815 /* We build up the lists of children and attributes by pushing new ones
5816 onto the beginning of the list. Reverse the lists for DIE so that
5817 they are in order of addition. */
5820 reverse_die_lists (dw_die_ref die)
5822 dw_die_ref c, cp, cn;
5824 for (c = die->die_child, cp = 0; c; c = cn)
5831 die->die_child = cp;
5834 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5835 reverse all dies in add_sibling_attributes, which runs through all the dies,
5836 it would reverse all the dies. Now, however, since we don't call
5837 reverse_die_lists in add_sibling_attributes, we need a routine to
5838 recursively reverse all the dies. This is that routine. */
5841 reverse_all_dies (dw_die_ref die)
5845 reverse_die_lists (die);
5847 for (c = die->die_child; c; c = c->die_sib)
5848 reverse_all_dies (c);
5851 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5852 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5853 DIE that marks the start of the DIEs for this include file. */
5856 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5858 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5859 dw_die_ref new_unit = gen_compile_unit_die (filename);
5861 new_unit->die_sib = old_unit;
5865 /* Close an include-file CU and reopen the enclosing one. */
5868 pop_compile_unit (dw_die_ref old_unit)
5870 dw_die_ref new_unit = old_unit->die_sib;
5872 old_unit->die_sib = NULL;
5876 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5877 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5879 /* Calculate the checksum of a location expression. */
5882 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5884 CHECKSUM (loc->dw_loc_opc);
5885 CHECKSUM (loc->dw_loc_oprnd1);
5886 CHECKSUM (loc->dw_loc_oprnd2);
5889 /* Calculate the checksum of an attribute. */
5892 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5894 dw_loc_descr_ref loc;
5897 CHECKSUM (at->dw_attr);
5899 /* We don't care about differences in file numbering. */
5900 if (at->dw_attr == DW_AT_decl_file
5901 /* Or that this was compiled with a different compiler snapshot; if
5902 the output is the same, that's what matters. */
5903 || at->dw_attr == DW_AT_producer)
5906 switch (AT_class (at))
5908 case dw_val_class_const:
5909 CHECKSUM (at->dw_attr_val.v.val_int);
5911 case dw_val_class_unsigned_const:
5912 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5914 case dw_val_class_long_long:
5915 CHECKSUM (at->dw_attr_val.v.val_long_long);
5917 case dw_val_class_vec:
5918 CHECKSUM (at->dw_attr_val.v.val_vec);
5920 case dw_val_class_flag:
5921 CHECKSUM (at->dw_attr_val.v.val_flag);
5923 case dw_val_class_str:
5924 CHECKSUM_STRING (AT_string (at));
5927 case dw_val_class_addr:
5929 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5930 CHECKSUM_STRING (XSTR (r, 0));
5933 case dw_val_class_offset:
5934 CHECKSUM (at->dw_attr_val.v.val_offset);
5937 case dw_val_class_loc:
5938 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5939 loc_checksum (loc, ctx);
5942 case dw_val_class_die_ref:
5943 die_checksum (AT_ref (at), ctx, mark);
5946 case dw_val_class_fde_ref:
5947 case dw_val_class_lbl_id:
5948 case dw_val_class_lineptr:
5949 case dw_val_class_macptr:
5957 /* Calculate the checksum of a DIE. */
5960 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5966 /* To avoid infinite recursion. */
5969 CHECKSUM (die->die_mark);
5972 die->die_mark = ++(*mark);
5974 CHECKSUM (die->die_tag);
5976 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5977 attr_checksum (a, ctx, mark);
5979 for (c = die->die_child; c; c = c->die_sib)
5980 die_checksum (c, ctx, mark);
5984 #undef CHECKSUM_STRING
5986 /* Do the location expressions look same? */
5988 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5990 return loc1->dw_loc_opc == loc2->dw_loc_opc
5991 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5992 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5995 /* Do the values look the same? */
5997 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5999 dw_loc_descr_ref loc1, loc2;
6002 if (v1->val_class != v2->val_class)
6005 switch (v1->val_class)
6007 case dw_val_class_const:
6008 return v1->v.val_int == v2->v.val_int;
6009 case dw_val_class_unsigned_const:
6010 return v1->v.val_unsigned == v2->v.val_unsigned;
6011 case dw_val_class_long_long:
6012 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6013 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6014 case dw_val_class_vec:
6015 if (v1->v.val_vec.length != v2->v.val_vec.length
6016 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6018 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6019 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6022 case dw_val_class_flag:
6023 return v1->v.val_flag == v2->v.val_flag;
6024 case dw_val_class_str:
6025 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6027 case dw_val_class_addr:
6028 r1 = v1->v.val_addr;
6029 r2 = v2->v.val_addr;
6030 if (GET_CODE (r1) != GET_CODE (r2))
6032 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6033 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6035 case dw_val_class_offset:
6036 return v1->v.val_offset == v2->v.val_offset;
6038 case dw_val_class_loc:
6039 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6041 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6042 if (!same_loc_p (loc1, loc2, mark))
6044 return !loc1 && !loc2;
6046 case dw_val_class_die_ref:
6047 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6049 case dw_val_class_fde_ref:
6050 case dw_val_class_lbl_id:
6051 case dw_val_class_lineptr:
6052 case dw_val_class_macptr:
6060 /* Do the attributes look the same? */
6063 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6065 if (at1->dw_attr != at2->dw_attr)
6068 /* We don't care about differences in file numbering. */
6069 if (at1->dw_attr == DW_AT_decl_file
6070 /* Or that this was compiled with a different compiler snapshot; if
6071 the output is the same, that's what matters. */
6072 || at1->dw_attr == DW_AT_producer)
6075 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6078 /* Do the dies look the same? */
6081 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6087 /* To avoid infinite recursion. */
6089 return die1->die_mark == die2->die_mark;
6090 die1->die_mark = die2->die_mark = ++(*mark);
6092 if (die1->die_tag != die2->die_tag)
6095 if (VEC_length (dw_attr_node, die1->die_attr)
6096 != VEC_length (dw_attr_node, die2->die_attr))
6099 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6100 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6103 for (c1 = die1->die_child, c2 = die2->die_child;
6105 c1 = c1->die_sib, c2 = c2->die_sib)
6106 if (!same_die_p (c1, c2, mark))
6114 /* Do the dies look the same? Wrapper around same_die_p. */
6117 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6120 int ret = same_die_p (die1, die2, &mark);
6122 unmark_all_dies (die1);
6123 unmark_all_dies (die2);
6128 /* The prefix to attach to symbols on DIEs in the current comdat debug
6130 static char *comdat_symbol_id;
6132 /* The index of the current symbol within the current comdat CU. */
6133 static unsigned int comdat_symbol_number;
6135 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6136 children, and set comdat_symbol_id accordingly. */
6139 compute_section_prefix (dw_die_ref unit_die)
6141 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6142 const char *base = die_name ? lbasename (die_name) : "anonymous";
6143 char *name = alloca (strlen (base) + 64);
6146 unsigned char checksum[16];
6149 /* Compute the checksum of the DIE, then append part of it as hex digits to
6150 the name filename of the unit. */
6152 md5_init_ctx (&ctx);
6154 die_checksum (unit_die, &ctx, &mark);
6155 unmark_all_dies (unit_die);
6156 md5_finish_ctx (&ctx, checksum);
6158 sprintf (name, "%s.", base);
6159 clean_symbol_name (name);
6161 p = name + strlen (name);
6162 for (i = 0; i < 4; i++)
6164 sprintf (p, "%.2x", checksum[i]);
6168 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6169 comdat_symbol_number = 0;
6172 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6175 is_type_die (dw_die_ref die)
6177 switch (die->die_tag)
6179 case DW_TAG_array_type:
6180 case DW_TAG_class_type:
6181 case DW_TAG_enumeration_type:
6182 case DW_TAG_pointer_type:
6183 case DW_TAG_reference_type:
6184 case DW_TAG_string_type:
6185 case DW_TAG_structure_type:
6186 case DW_TAG_subroutine_type:
6187 case DW_TAG_union_type:
6188 case DW_TAG_ptr_to_member_type:
6189 case DW_TAG_set_type:
6190 case DW_TAG_subrange_type:
6191 case DW_TAG_base_type:
6192 case DW_TAG_const_type:
6193 case DW_TAG_file_type:
6194 case DW_TAG_packed_type:
6195 case DW_TAG_volatile_type:
6196 case DW_TAG_typedef:
6203 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6204 Basically, we want to choose the bits that are likely to be shared between
6205 compilations (types) and leave out the bits that are specific to individual
6206 compilations (functions). */
6209 is_comdat_die (dw_die_ref c)
6211 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6212 we do for stabs. The advantage is a greater likelihood of sharing between
6213 objects that don't include headers in the same order (and therefore would
6214 put the base types in a different comdat). jason 8/28/00 */
6216 if (c->die_tag == DW_TAG_base_type)
6219 if (c->die_tag == DW_TAG_pointer_type
6220 || c->die_tag == DW_TAG_reference_type
6221 || c->die_tag == DW_TAG_const_type
6222 || c->die_tag == DW_TAG_volatile_type)
6224 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6226 return t ? is_comdat_die (t) : 0;
6229 return is_type_die (c);
6232 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6233 compilation unit. */
6236 is_symbol_die (dw_die_ref c)
6238 return (is_type_die (c)
6239 || (get_AT (c, DW_AT_declaration)
6240 && !get_AT (c, DW_AT_specification))
6241 || c->die_tag == DW_TAG_namespace);
6245 gen_internal_sym (const char *prefix)
6249 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6250 return xstrdup (buf);
6253 /* Assign symbols to all worthy DIEs under DIE. */
6256 assign_symbol_names (dw_die_ref die)
6260 if (is_symbol_die (die))
6262 if (comdat_symbol_id)
6264 char *p = alloca (strlen (comdat_symbol_id) + 64);
6266 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6267 comdat_symbol_id, comdat_symbol_number++);
6268 die->die_symbol = xstrdup (p);
6271 die->die_symbol = gen_internal_sym ("LDIE");
6274 for (c = die->die_child; c != NULL; c = c->die_sib)
6275 assign_symbol_names (c);
6278 struct cu_hash_table_entry
6281 unsigned min_comdat_num, max_comdat_num;
6282 struct cu_hash_table_entry *next;
6285 /* Routines to manipulate hash table of CUs. */
6287 htab_cu_hash (const void *of)
6289 const struct cu_hash_table_entry *entry = of;
6291 return htab_hash_string (entry->cu->die_symbol);
6295 htab_cu_eq (const void *of1, const void *of2)
6297 const struct cu_hash_table_entry *entry1 = of1;
6298 const struct die_struct *entry2 = of2;
6300 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6304 htab_cu_del (void *what)
6306 struct cu_hash_table_entry *next, *entry = what;
6316 /* Check whether we have already seen this CU and set up SYM_NUM
6319 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6321 struct cu_hash_table_entry dummy;
6322 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6324 dummy.max_comdat_num = 0;
6326 slot = (struct cu_hash_table_entry **)
6327 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6331 for (; entry; last = entry, entry = entry->next)
6333 if (same_die_p_wrap (cu, entry->cu))
6339 *sym_num = entry->min_comdat_num;
6343 entry = XCNEW (struct cu_hash_table_entry);
6345 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6346 entry->next = *slot;
6352 /* Record SYM_NUM to record of CU in HTABLE. */
6354 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6356 struct cu_hash_table_entry **slot, *entry;
6358 slot = (struct cu_hash_table_entry **)
6359 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6363 entry->max_comdat_num = sym_num;
6366 /* Traverse the DIE (which is always comp_unit_die), and set up
6367 additional compilation units for each of the include files we see
6368 bracketed by BINCL/EINCL. */
6371 break_out_includes (dw_die_ref die)
6374 dw_die_ref unit = NULL;
6375 limbo_die_node *node, **pnode;
6376 htab_t cu_hash_table;
6378 for (ptr = &(die->die_child); *ptr;)
6380 dw_die_ref c = *ptr;
6382 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6383 || (unit && is_comdat_die (c)))
6385 /* This DIE is for a secondary CU; remove it from the main one. */
6388 if (c->die_tag == DW_TAG_GNU_BINCL)
6390 unit = push_new_compile_unit (unit, c);
6393 else if (c->die_tag == DW_TAG_GNU_EINCL)
6395 unit = pop_compile_unit (unit);
6399 add_child_die (unit, c);
6403 /* Leave this DIE in the main CU. */
6404 ptr = &(c->die_sib);
6410 /* We can only use this in debugging, since the frontend doesn't check
6411 to make sure that we leave every include file we enter. */
6415 assign_symbol_names (die);
6416 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6417 for (node = limbo_die_list, pnode = &limbo_die_list;
6423 compute_section_prefix (node->die);
6424 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6425 &comdat_symbol_number);
6426 assign_symbol_names (node->die);
6428 *pnode = node->next;
6431 pnode = &node->next;
6432 record_comdat_symbol_number (node->die, cu_hash_table,
6433 comdat_symbol_number);
6436 htab_delete (cu_hash_table);
6439 /* Traverse the DIE and add a sibling attribute if it may have the
6440 effect of speeding up access to siblings. To save some space,
6441 avoid generating sibling attributes for DIE's without children. */
6444 add_sibling_attributes (dw_die_ref die)
6448 if (die->die_tag != DW_TAG_compile_unit
6449 && die->die_sib && die->die_child != NULL)
6450 /* Add the sibling link to the front of the attribute list. */
6451 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6453 for (c = die->die_child; c != NULL; c = c->die_sib)
6454 add_sibling_attributes (c);
6457 /* Output all location lists for the DIE and its children. */
6460 output_location_lists (dw_die_ref die)
6466 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6467 if (AT_class (a) == dw_val_class_loc_list)
6468 output_loc_list (AT_loc_list (a));
6470 for (c = die->die_child; c != NULL; c = c->die_sib)
6471 output_location_lists (c);
6475 /* The format of each DIE (and its attribute value pairs) is encoded in an
6476 abbreviation table. This routine builds the abbreviation table and assigns
6477 a unique abbreviation id for each abbreviation entry. The children of each
6478 die are visited recursively. */
6481 build_abbrev_table (dw_die_ref die)
6483 unsigned long abbrev_id;
6484 unsigned int n_alloc;
6489 /* Scan the DIE references, and mark as external any that refer to
6490 DIEs from other CUs (i.e. those which are not marked). */
6491 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6492 if (AT_class (a) == dw_val_class_die_ref
6493 && AT_ref (a)->die_mark == 0)
6495 gcc_assert (AT_ref (a)->die_symbol);
6497 set_AT_ref_external (a, 1);
6500 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6502 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6503 dw_attr_ref die_a, abbrev_a;
6507 if (abbrev->die_tag != die->die_tag)
6509 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6512 if (VEC_length (dw_attr_node, abbrev->die_attr)
6513 != VEC_length (dw_attr_node, die->die_attr))
6516 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6518 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6519 if ((abbrev_a->dw_attr != die_a->dw_attr)
6520 || (value_format (abbrev_a) != value_format (die_a)))
6530 if (abbrev_id >= abbrev_die_table_in_use)
6532 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6534 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6535 abbrev_die_table = ggc_realloc (abbrev_die_table,
6536 sizeof (dw_die_ref) * n_alloc);
6538 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6539 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6540 abbrev_die_table_allocated = n_alloc;
6543 ++abbrev_die_table_in_use;
6544 abbrev_die_table[abbrev_id] = die;
6547 die->die_abbrev = abbrev_id;
6548 for (c = die->die_child; c != NULL; c = c->die_sib)
6549 build_abbrev_table (c);
6552 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6555 constant_size (long unsigned int value)
6562 log = floor_log2 (value);
6565 log = 1 << (floor_log2 (log) + 1);
6570 /* Return the size of a DIE as it is represented in the
6571 .debug_info section. */
6573 static unsigned long
6574 size_of_die (dw_die_ref die)
6576 unsigned long size = 0;
6580 size += size_of_uleb128 (die->die_abbrev);
6581 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6583 switch (AT_class (a))
6585 case dw_val_class_addr:
6586 size += DWARF2_ADDR_SIZE;
6588 case dw_val_class_offset:
6589 size += DWARF_OFFSET_SIZE;
6591 case dw_val_class_loc:
6593 unsigned long lsize = size_of_locs (AT_loc (a));
6596 size += constant_size (lsize);
6600 case dw_val_class_loc_list:
6601 size += DWARF_OFFSET_SIZE;
6603 case dw_val_class_range_list:
6604 size += DWARF_OFFSET_SIZE;
6606 case dw_val_class_const:
6607 size += size_of_sleb128 (AT_int (a));
6609 case dw_val_class_unsigned_const:
6610 size += constant_size (AT_unsigned (a));
6612 case dw_val_class_long_long:
6613 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6615 case dw_val_class_vec:
6616 size += 1 + (a->dw_attr_val.v.val_vec.length
6617 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6619 case dw_val_class_flag:
6622 case dw_val_class_die_ref:
6623 if (AT_ref_external (a))
6624 size += DWARF2_ADDR_SIZE;
6626 size += DWARF_OFFSET_SIZE;
6628 case dw_val_class_fde_ref:
6629 size += DWARF_OFFSET_SIZE;
6631 case dw_val_class_lbl_id:
6632 size += DWARF2_ADDR_SIZE;
6634 case dw_val_class_lineptr:
6635 case dw_val_class_macptr:
6636 size += DWARF_OFFSET_SIZE;
6638 case dw_val_class_str:
6639 if (AT_string_form (a) == DW_FORM_strp)
6640 size += DWARF_OFFSET_SIZE;
6642 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6652 /* Size the debugging information associated with a given DIE. Visits the
6653 DIE's children recursively. Updates the global variable next_die_offset, on
6654 each time through. Uses the current value of next_die_offset to update the
6655 die_offset field in each DIE. */
6658 calc_die_sizes (dw_die_ref die)
6662 die->die_offset = next_die_offset;
6663 next_die_offset += size_of_die (die);
6665 for (c = die->die_child; c != NULL; c = c->die_sib)
6668 if (die->die_child != NULL)
6669 /* Count the null byte used to terminate sibling lists. */
6670 next_die_offset += 1;
6673 /* Set the marks for a die and its children. We do this so
6674 that we know whether or not a reference needs to use FORM_ref_addr; only
6675 DIEs in the same CU will be marked. We used to clear out the offset
6676 and use that as the flag, but ran into ordering problems. */
6679 mark_dies (dw_die_ref die)
6683 gcc_assert (!die->die_mark);
6686 for (c = die->die_child; c; c = c->die_sib)
6690 /* Clear the marks for a die and its children. */
6693 unmark_dies (dw_die_ref die)
6697 gcc_assert (die->die_mark);
6700 for (c = die->die_child; c; c = c->die_sib)
6704 /* Clear the marks for a die, its children and referred dies. */
6707 unmark_all_dies (dw_die_ref die)
6717 for (c = die->die_child; c; c = c->die_sib)
6718 unmark_all_dies (c);
6720 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6721 if (AT_class (a) == dw_val_class_die_ref)
6722 unmark_all_dies (AT_ref (a));
6725 /* Return the size of the .debug_pubnames table generated for the
6726 compilation unit. */
6728 static unsigned long
6729 size_of_pubnames (void)
6734 size = DWARF_PUBNAMES_HEADER_SIZE;
6735 for (i = 0; i < pubname_table_in_use; i++)
6737 pubname_ref p = &pubname_table[i];
6738 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6741 size += DWARF_OFFSET_SIZE;
6745 /* Return the size of the information in the .debug_aranges section. */
6747 static unsigned long
6748 size_of_aranges (void)
6752 size = DWARF_ARANGES_HEADER_SIZE;
6754 /* Count the address/length pair for this compilation unit. */
6755 size += 2 * DWARF2_ADDR_SIZE;
6756 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6758 /* Count the two zero words used to terminated the address range table. */
6759 size += 2 * DWARF2_ADDR_SIZE;
6763 /* Select the encoding of an attribute value. */
6765 static enum dwarf_form
6766 value_format (dw_attr_ref a)
6768 switch (a->dw_attr_val.val_class)
6770 case dw_val_class_addr:
6771 return DW_FORM_addr;
6772 case dw_val_class_range_list:
6773 case dw_val_class_offset:
6774 case dw_val_class_loc_list:
6775 switch (DWARF_OFFSET_SIZE)
6778 return DW_FORM_data4;
6780 return DW_FORM_data8;
6784 case dw_val_class_loc:
6785 switch (constant_size (size_of_locs (AT_loc (a))))
6788 return DW_FORM_block1;
6790 return DW_FORM_block2;
6794 case dw_val_class_const:
6795 return DW_FORM_sdata;
6796 case dw_val_class_unsigned_const:
6797 switch (constant_size (AT_unsigned (a)))
6800 return DW_FORM_data1;
6802 return DW_FORM_data2;
6804 return DW_FORM_data4;
6806 return DW_FORM_data8;
6810 case dw_val_class_long_long:
6811 return DW_FORM_block1;
6812 case dw_val_class_vec:
6813 return DW_FORM_block1;
6814 case dw_val_class_flag:
6815 return DW_FORM_flag;
6816 case dw_val_class_die_ref:
6817 if (AT_ref_external (a))
6818 return DW_FORM_ref_addr;
6821 case dw_val_class_fde_ref:
6822 return DW_FORM_data;
6823 case dw_val_class_lbl_id:
6824 return DW_FORM_addr;
6825 case dw_val_class_lineptr:
6826 case dw_val_class_macptr:
6827 return DW_FORM_data;
6828 case dw_val_class_str:
6829 return AT_string_form (a);
6836 /* Output the encoding of an attribute value. */
6839 output_value_format (dw_attr_ref a)
6841 enum dwarf_form form = value_format (a);
6843 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6846 /* Output the .debug_abbrev section which defines the DIE abbreviation
6850 output_abbrev_section (void)
6852 unsigned long abbrev_id;
6854 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6856 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6860 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6861 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6862 dwarf_tag_name (abbrev->die_tag));
6864 if (abbrev->die_child != NULL)
6865 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6867 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6869 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
6872 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6873 dwarf_attr_name (a_attr->dw_attr));
6874 output_value_format (a_attr);
6877 dw2_asm_output_data (1, 0, NULL);
6878 dw2_asm_output_data (1, 0, NULL);
6881 /* Terminate the table. */
6882 dw2_asm_output_data (1, 0, NULL);
6885 /* Output a symbol we can use to refer to this DIE from another CU. */
6888 output_die_symbol (dw_die_ref die)
6890 char *sym = die->die_symbol;
6895 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6896 /* We make these global, not weak; if the target doesn't support
6897 .linkonce, it doesn't support combining the sections, so debugging
6899 targetm.asm_out.globalize_label (asm_out_file, sym);
6901 ASM_OUTPUT_LABEL (asm_out_file, sym);
6904 /* Return a new location list, given the begin and end range, and the
6905 expression. gensym tells us whether to generate a new internal symbol for
6906 this location list node, which is done for the head of the list only. */
6908 static inline dw_loc_list_ref
6909 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6910 const char *section, unsigned int gensym)
6912 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6914 retlist->begin = begin;
6916 retlist->expr = expr;
6917 retlist->section = section;
6919 retlist->ll_symbol = gen_internal_sym ("LLST");
6924 /* Add a location description expression to a location list. */
6927 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6928 const char *begin, const char *end,
6929 const char *section)
6933 /* Find the end of the chain. */
6934 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6937 /* Add a new location list node to the list. */
6938 *d = new_loc_list (descr, begin, end, section, 0);
6942 dwarf2out_switch_text_section (void)
6948 fde = &fde_table[fde_table_in_use - 1];
6949 fde->dw_fde_switched_sections = true;
6950 fde->dw_fde_hot_section_label = cfun->hot_section_label;
6951 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
6952 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
6953 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
6954 have_multiple_function_sections = true;
6957 /* Output the location list given to us. */
6960 output_loc_list (dw_loc_list_ref list_head)
6962 dw_loc_list_ref curr = list_head;
6964 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6966 /* Walk the location list, and output each range + expression. */
6967 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6970 if (!have_multiple_function_sections)
6972 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6973 "Location list begin address (%s)",
6974 list_head->ll_symbol);
6975 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6976 "Location list end address (%s)",
6977 list_head->ll_symbol);
6981 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
6982 "Location list begin address (%s)",
6983 list_head->ll_symbol);
6984 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
6985 "Location list end address (%s)",
6986 list_head->ll_symbol);
6988 size = size_of_locs (curr->expr);
6990 /* Output the block length for this list of location operations. */
6991 gcc_assert (size <= 0xffff);
6992 dw2_asm_output_data (2, size, "%s", "Location expression size");
6994 output_loc_sequence (curr->expr);
6997 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6998 "Location list terminator begin (%s)",
6999 list_head->ll_symbol);
7000 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7001 "Location list terminator end (%s)",
7002 list_head->ll_symbol);
7005 /* Output the DIE and its attributes. Called recursively to generate
7006 the definitions of each child DIE. */
7009 output_die (dw_die_ref die)
7016 /* If someone in another CU might refer to us, set up a symbol for
7017 them to point to. */
7018 if (die->die_symbol)
7019 output_die_symbol (die);
7021 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7022 die->die_offset, dwarf_tag_name (die->die_tag));
7024 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7026 const char *name = dwarf_attr_name (a->dw_attr);
7028 switch (AT_class (a))
7030 case dw_val_class_addr:
7031 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7034 case dw_val_class_offset:
7035 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7039 case dw_val_class_range_list:
7041 char *p = strchr (ranges_section_label, '\0');
7043 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7044 a->dw_attr_val.v.val_offset);
7045 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7046 debug_ranges_section, "%s", name);
7051 case dw_val_class_loc:
7052 size = size_of_locs (AT_loc (a));
7054 /* Output the block length for this list of location operations. */
7055 dw2_asm_output_data (constant_size (size), size, "%s", name);
7057 output_loc_sequence (AT_loc (a));
7060 case dw_val_class_const:
7061 /* ??? It would be slightly more efficient to use a scheme like is
7062 used for unsigned constants below, but gdb 4.x does not sign
7063 extend. Gdb 5.x does sign extend. */
7064 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7067 case dw_val_class_unsigned_const:
7068 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7069 AT_unsigned (a), "%s", name);
7072 case dw_val_class_long_long:
7074 unsigned HOST_WIDE_INT first, second;
7076 dw2_asm_output_data (1,
7077 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7080 if (WORDS_BIG_ENDIAN)
7082 first = a->dw_attr_val.v.val_long_long.hi;
7083 second = a->dw_attr_val.v.val_long_long.low;
7087 first = a->dw_attr_val.v.val_long_long.low;
7088 second = a->dw_attr_val.v.val_long_long.hi;
7091 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7092 first, "long long constant");
7093 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7098 case dw_val_class_vec:
7100 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7101 unsigned int len = a->dw_attr_val.v.val_vec.length;
7105 dw2_asm_output_data (1, len * elt_size, "%s", name);
7106 if (elt_size > sizeof (HOST_WIDE_INT))
7111 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7114 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7115 "fp or vector constant word %u", i);
7119 case dw_val_class_flag:
7120 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7123 case dw_val_class_loc_list:
7125 char *sym = AT_loc_list (a)->ll_symbol;
7128 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7133 case dw_val_class_die_ref:
7134 if (AT_ref_external (a))
7136 char *sym = AT_ref (a)->die_symbol;
7139 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7144 gcc_assert (AT_ref (a)->die_offset);
7145 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7150 case dw_val_class_fde_ref:
7154 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7155 a->dw_attr_val.v.val_fde_index * 2);
7156 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7161 case dw_val_class_lbl_id:
7162 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7165 case dw_val_class_lineptr:
7166 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7167 debug_line_section, "%s", name);
7170 case dw_val_class_macptr:
7171 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7172 debug_macinfo_section, "%s", name);
7175 case dw_val_class_str:
7176 if (AT_string_form (a) == DW_FORM_strp)
7177 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7178 a->dw_attr_val.v.val_str->label,
7180 "%s: \"%s\"", name, AT_string (a));
7182 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7190 for (c = die->die_child; c != NULL; c = c->die_sib)
7193 /* Add null byte to terminate sibling list. */
7194 if (die->die_child != NULL)
7195 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7199 /* Output the compilation unit that appears at the beginning of the
7200 .debug_info section, and precedes the DIE descriptions. */
7203 output_compilation_unit_header (void)
7205 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7206 dw2_asm_output_data (4, 0xffffffff,
7207 "Initial length escape value indicating 64-bit DWARF extension");
7208 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7209 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7210 "Length of Compilation Unit Info");
7211 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7212 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7213 debug_abbrev_section,
7214 "Offset Into Abbrev. Section");
7215 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7218 /* Output the compilation unit DIE and its children. */
7221 output_comp_unit (dw_die_ref die, int output_if_empty)
7223 const char *secname;
7226 /* Unless we are outputting main CU, we may throw away empty ones. */
7227 if (!output_if_empty && die->die_child == NULL)
7230 /* Even if there are no children of this DIE, we must output the information
7231 about the compilation unit. Otherwise, on an empty translation unit, we
7232 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7233 will then complain when examining the file. First mark all the DIEs in
7234 this CU so we know which get local refs. */
7237 build_abbrev_table (die);
7239 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7240 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7241 calc_die_sizes (die);
7243 oldsym = die->die_symbol;
7246 tmp = alloca (strlen (oldsym) + 24);
7248 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7250 die->die_symbol = NULL;
7251 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7254 switch_to_section (debug_info_section);
7256 /* Output debugging information. */
7257 output_compilation_unit_header ();
7260 /* Leave the marks on the main CU, so we can check them in
7265 die->die_symbol = oldsym;
7269 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7270 output of lang_hooks.decl_printable_name for C++ looks like
7271 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7274 dwarf2_name (tree decl, int scope)
7276 return lang_hooks.decl_printable_name (decl, scope ? 1 : 0);
7279 /* Add a new entry to .debug_pubnames if appropriate. */
7282 add_pubname (tree decl, dw_die_ref die)
7286 if (! TREE_PUBLIC (decl))
7289 if (pubname_table_in_use == pubname_table_allocated)
7291 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
7293 = ggc_realloc (pubname_table,
7294 (pubname_table_allocated * sizeof (pubname_entry)));
7295 memset (pubname_table + pubname_table_in_use, 0,
7296 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
7299 p = &pubname_table[pubname_table_in_use++];
7301 p->name = xstrdup (dwarf2_name (decl, 1));
7304 /* Output the public names table used to speed up access to externally
7305 visible names. For now, only generate entries for externally
7306 visible procedures. */
7309 output_pubnames (void)
7312 unsigned long pubnames_length = size_of_pubnames ();
7314 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7315 dw2_asm_output_data (4, 0xffffffff,
7316 "Initial length escape value indicating 64-bit DWARF extension");
7317 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7318 "Length of Public Names Info");
7319 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7320 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7322 "Offset of Compilation Unit Info");
7323 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7324 "Compilation Unit Length");
7326 for (i = 0; i < pubname_table_in_use; i++)
7328 pubname_ref pub = &pubname_table[i];
7330 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7331 gcc_assert (pub->die->die_mark);
7333 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7336 dw2_asm_output_nstring (pub->name, -1, "external name");
7339 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7342 /* Add a new entry to .debug_aranges if appropriate. */
7345 add_arange (tree decl, dw_die_ref die)
7347 if (! DECL_SECTION_NAME (decl))
7350 if (arange_table_in_use == arange_table_allocated)
7352 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7353 arange_table = ggc_realloc (arange_table,
7354 (arange_table_allocated
7355 * sizeof (dw_die_ref)));
7356 memset (arange_table + arange_table_in_use, 0,
7357 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7360 arange_table[arange_table_in_use++] = die;
7363 /* Output the information that goes into the .debug_aranges table.
7364 Namely, define the beginning and ending address range of the
7365 text section generated for this compilation unit. */
7368 output_aranges (void)
7371 unsigned long aranges_length = size_of_aranges ();
7373 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7374 dw2_asm_output_data (4, 0xffffffff,
7375 "Initial length escape value indicating 64-bit DWARF extension");
7376 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7377 "Length of Address Ranges Info");
7378 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7379 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7381 "Offset of Compilation Unit Info");
7382 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7383 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7385 /* We need to align to twice the pointer size here. */
7386 if (DWARF_ARANGES_PAD_SIZE)
7388 /* Pad using a 2 byte words so that padding is correct for any
7390 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7391 2 * DWARF2_ADDR_SIZE);
7392 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7393 dw2_asm_output_data (2, 0, NULL);
7396 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7397 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7398 text_section_label, "Length");
7399 if (flag_reorder_blocks_and_partition)
7401 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7403 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7404 cold_text_section_label, "Length");
7407 for (i = 0; i < arange_table_in_use; i++)
7409 dw_die_ref die = arange_table[i];
7411 /* We shouldn't see aranges for DIEs outside of the main CU. */
7412 gcc_assert (die->die_mark);
7414 if (die->die_tag == DW_TAG_subprogram)
7416 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7418 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7419 get_AT_low_pc (die), "Length");
7423 /* A static variable; extract the symbol from DW_AT_location.
7424 Note that this code isn't currently hit, as we only emit
7425 aranges for functions (jason 9/23/99). */
7426 dw_attr_ref a = get_AT (die, DW_AT_location);
7427 dw_loc_descr_ref loc;
7429 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7432 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7434 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7435 loc->dw_loc_oprnd1.v.val_addr, "Address");
7436 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7437 get_AT_unsigned (die, DW_AT_byte_size),
7442 /* Output the terminator words. */
7443 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7444 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7447 /* Add a new entry to .debug_ranges. Return the offset at which it
7451 add_ranges (tree block)
7453 unsigned int in_use = ranges_table_in_use;
7455 if (in_use == ranges_table_allocated)
7457 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7459 = ggc_realloc (ranges_table, (ranges_table_allocated
7460 * sizeof (struct dw_ranges_struct)));
7461 memset (ranges_table + ranges_table_in_use, 0,
7462 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7465 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
7466 ranges_table_in_use = in_use + 1;
7468 return in_use * 2 * DWARF2_ADDR_SIZE;
7472 output_ranges (void)
7475 static const char *const start_fmt = "Offset 0x%x";
7476 const char *fmt = start_fmt;
7478 for (i = 0; i < ranges_table_in_use; i++)
7480 int block_num = ranges_table[i].block_num;
7484 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7485 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7487 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7488 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7490 /* If all code is in the text section, then the compilation
7491 unit base address defaults to DW_AT_low_pc, which is the
7492 base of the text section. */
7493 if (!have_multiple_function_sections)
7495 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7497 fmt, i * 2 * DWARF2_ADDR_SIZE);
7498 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7499 text_section_label, NULL);
7502 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7503 compilation unit base address to zero, which allows us to
7504 use absolute addresses, and not worry about whether the
7505 target supports cross-section arithmetic. */
7508 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7509 fmt, i * 2 * DWARF2_ADDR_SIZE);
7510 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7517 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7518 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7524 /* Data structure containing information about input files. */
7527 char *path; /* Complete file name. */
7528 char *fname; /* File name part. */
7529 int length; /* Length of entire string. */
7530 int file_idx; /* Index in input file table. */
7531 int dir_idx; /* Index in directory table. */
7534 /* Data structure containing information about directories with source
7538 char *path; /* Path including directory name. */
7539 int length; /* Path length. */
7540 int prefix; /* Index of directory entry which is a prefix. */
7541 int count; /* Number of files in this directory. */
7542 int dir_idx; /* Index of directory used as base. */
7543 int used; /* Used in the end? */
7546 /* Callback function for file_info comparison. We sort by looking at
7547 the directories in the path. */
7550 file_info_cmp (const void *p1, const void *p2)
7552 const struct file_info *s1 = p1;
7553 const struct file_info *s2 = p2;
7557 /* Take care of file names without directories. We need to make sure that
7558 we return consistent values to qsort since some will get confused if
7559 we return the same value when identical operands are passed in opposite
7560 orders. So if neither has a directory, return 0 and otherwise return
7561 1 or -1 depending on which one has the directory. */
7562 if ((s1->path == s1->fname || s2->path == s2->fname))
7563 return (s2->path == s2->fname) - (s1->path == s1->fname);
7565 cp1 = (unsigned char *) s1->path;
7566 cp2 = (unsigned char *) s2->path;
7572 /* Reached the end of the first path? If so, handle like above. */
7573 if ((cp1 == (unsigned char *) s1->fname)
7574 || (cp2 == (unsigned char *) s2->fname))
7575 return ((cp2 == (unsigned char *) s2->fname)
7576 - (cp1 == (unsigned char *) s1->fname));
7578 /* Character of current path component the same? */
7579 else if (*cp1 != *cp2)
7584 /* Output the directory table and the file name table. We try to minimize
7585 the total amount of memory needed. A heuristic is used to avoid large
7586 slowdowns with many input files. */
7589 output_file_names (void)
7591 struct file_info *files;
7592 struct dir_info *dirs;
7601 /* Handle the case where file_table is empty. */
7602 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7604 dw2_asm_output_data (1, 0, "End directory table");
7605 dw2_asm_output_data (1, 0, "End file name table");
7609 /* Allocate the various arrays we need. */
7610 files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info));
7611 dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info));
7613 /* Sort the file names. */
7614 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7618 /* Skip all leading "./". */
7619 f = VARRAY_CHAR_PTR (file_table, i);
7620 while (f[0] == '.' && f[1] == '/')
7623 /* Create a new array entry. */
7625 files[i].length = strlen (f);
7626 files[i].file_idx = i;
7628 /* Search for the file name part. */
7629 f = strrchr (f, '/');
7630 files[i].fname = f == NULL ? files[i].path : f + 1;
7633 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7634 sizeof (files[0]), file_info_cmp);
7636 /* Find all the different directories used. */
7637 dirs[0].path = files[1].path;
7638 dirs[0].length = files[1].fname - files[1].path;
7639 dirs[0].prefix = -1;
7641 dirs[0].dir_idx = 0;
7643 files[1].dir_idx = 0;
7646 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7647 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7648 && memcmp (dirs[ndirs - 1].path, files[i].path,
7649 dirs[ndirs - 1].length) == 0)
7651 /* Same directory as last entry. */
7652 files[i].dir_idx = ndirs - 1;
7653 ++dirs[ndirs - 1].count;
7659 /* This is a new directory. */
7660 dirs[ndirs].path = files[i].path;
7661 dirs[ndirs].length = files[i].fname - files[i].path;
7662 dirs[ndirs].count = 1;
7663 dirs[ndirs].dir_idx = ndirs;
7664 dirs[ndirs].used = 0;
7665 files[i].dir_idx = ndirs;
7667 /* Search for a prefix. */
7668 dirs[ndirs].prefix = -1;
7669 for (j = 0; j < ndirs; j++)
7670 if (dirs[j].length < dirs[ndirs].length
7671 && dirs[j].length > 1
7672 && (dirs[ndirs].prefix == -1
7673 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7674 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7675 dirs[ndirs].prefix = j;
7680 /* Now to the actual work. We have to find a subset of the directories which
7681 allow expressing the file name using references to the directory table
7682 with the least amount of characters. We do not do an exhaustive search
7683 where we would have to check out every combination of every single
7684 possible prefix. Instead we use a heuristic which provides nearly optimal
7685 results in most cases and never is much off. */
7686 saved = alloca (ndirs * sizeof (int));
7687 savehere = alloca (ndirs * sizeof (int));
7689 memset (saved, '\0', ndirs * sizeof (saved[0]));
7690 for (i = 0; i < ndirs; i++)
7695 /* We can always save some space for the current directory. But this
7696 does not mean it will be enough to justify adding the directory. */
7697 savehere[i] = dirs[i].length;
7698 total = (savehere[i] - saved[i]) * dirs[i].count;
7700 for (j = i + 1; j < ndirs; j++)
7703 if (saved[j] < dirs[i].length)
7705 /* Determine whether the dirs[i] path is a prefix of the
7710 while (k != -1 && k != (int) i)
7715 /* Yes it is. We can possibly safe some memory but
7716 writing the filenames in dirs[j] relative to
7718 savehere[j] = dirs[i].length;
7719 total += (savehere[j] - saved[j]) * dirs[j].count;
7724 /* Check whether we can safe enough to justify adding the dirs[i]
7726 if (total > dirs[i].length + 1)
7728 /* It's worthwhile adding. */
7729 for (j = i; j < ndirs; j++)
7730 if (savehere[j] > 0)
7732 /* Remember how much we saved for this directory so far. */
7733 saved[j] = savehere[j];
7735 /* Remember the prefix directory. */
7736 dirs[j].dir_idx = i;
7741 /* We have to emit them in the order they appear in the file_table array
7742 since the index is used in the debug info generation. To do this
7743 efficiently we generate a back-mapping of the indices first. */
7744 backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7745 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7747 backmap[files[i].file_idx] = i;
7749 /* Mark this directory as used. */
7750 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7753 /* That was it. We are ready to emit the information. First emit the
7754 directory name table. We have to make sure the first actually emitted
7755 directory name has index one; zero is reserved for the current working
7756 directory. Make sure we do not confuse these indices with the one for the
7757 constructed table (even though most of the time they are identical). */
7759 idx_offset = dirs[0].length > 0 ? 1 : 0;
7760 for (i = 1 - idx_offset; i < ndirs; i++)
7761 if (dirs[i].used != 0)
7763 dirs[i].used = idx++;
7764 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7765 "Directory Entry: 0x%x", dirs[i].used);
7768 dw2_asm_output_data (1, 0, "End directory table");
7770 /* Correct the index for the current working directory entry if it
7772 if (idx_offset == 0)
7775 /* Now write all the file names. */
7776 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7778 int file_idx = backmap[i];
7779 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7781 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7782 "File Entry: 0x%lx", (unsigned long) i);
7784 /* Include directory index. */
7785 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7787 /* Modification time. */
7788 dw2_asm_output_data_uleb128 (0, NULL);
7790 /* File length in bytes. */
7791 dw2_asm_output_data_uleb128 (0, NULL);
7794 dw2_asm_output_data (1, 0, "End file name table");
7798 /* Output the source line number correspondence information. This
7799 information goes into the .debug_line section. */
7802 output_line_info (void)
7804 char l1[20], l2[20], p1[20], p2[20];
7805 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7806 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7809 unsigned long lt_index;
7810 unsigned long current_line;
7813 unsigned long current_file;
7814 unsigned long function;
7816 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7817 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7818 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7819 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7821 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7822 dw2_asm_output_data (4, 0xffffffff,
7823 "Initial length escape value indicating 64-bit DWARF extension");
7824 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7825 "Length of Source Line Info");
7826 ASM_OUTPUT_LABEL (asm_out_file, l1);
7828 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7829 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7830 ASM_OUTPUT_LABEL (asm_out_file, p1);
7832 /* Define the architecture-dependent minimum instruction length (in
7833 bytes). In this implementation of DWARF, this field is used for
7834 information purposes only. Since GCC generates assembly language,
7835 we have no a priori knowledge of how many instruction bytes are
7836 generated for each source line, and therefore can use only the
7837 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7838 commands. Accordingly, we fix this as `1', which is "correct
7839 enough" for all architectures, and don't let the target override. */
7840 dw2_asm_output_data (1, 1,
7841 "Minimum Instruction Length");
7843 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7844 "Default is_stmt_start flag");
7845 dw2_asm_output_data (1, DWARF_LINE_BASE,
7846 "Line Base Value (Special Opcodes)");
7847 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7848 "Line Range Value (Special Opcodes)");
7849 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7850 "Special Opcode Base");
7852 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7856 case DW_LNS_advance_pc:
7857 case DW_LNS_advance_line:
7858 case DW_LNS_set_file:
7859 case DW_LNS_set_column:
7860 case DW_LNS_fixed_advance_pc:
7868 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7872 /* Write out the information about the files we use. */
7873 output_file_names ();
7874 ASM_OUTPUT_LABEL (asm_out_file, p2);
7876 /* We used to set the address register to the first location in the text
7877 section here, but that didn't accomplish anything since we already
7878 have a line note for the opening brace of the first function. */
7880 /* Generate the line number to PC correspondence table, encoded as
7881 a series of state machine operations. */
7885 if (cfun && in_cold_section_p)
7886 strcpy (prev_line_label, cfun->cold_section_label);
7888 strcpy (prev_line_label, text_section_label);
7889 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7891 dw_line_info_ref line_info = &line_info_table[lt_index];
7894 /* Disable this optimization for now; GDB wants to see two line notes
7895 at the beginning of a function so it can find the end of the
7898 /* Don't emit anything for redundant notes. Just updating the
7899 address doesn't accomplish anything, because we already assume
7900 that anything after the last address is this line. */
7901 if (line_info->dw_line_num == current_line
7902 && line_info->dw_file_num == current_file)
7906 /* Emit debug info for the address of the current line.
7908 Unfortunately, we have little choice here currently, and must always
7909 use the most general form. GCC does not know the address delta
7910 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7911 attributes which will give an upper bound on the address range. We
7912 could perhaps use length attributes to determine when it is safe to
7913 use DW_LNS_fixed_advance_pc. */
7915 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7918 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7919 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7920 "DW_LNS_fixed_advance_pc");
7921 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7925 /* This can handle any delta. This takes
7926 4+DWARF2_ADDR_SIZE bytes. */
7927 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7928 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7929 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7930 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7933 strcpy (prev_line_label, line_label);
7935 /* Emit debug info for the source file of the current line, if
7936 different from the previous line. */
7937 if (line_info->dw_file_num != current_file)
7939 current_file = line_info->dw_file_num;
7940 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7941 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7942 VARRAY_CHAR_PTR (file_table,
7946 /* Emit debug info for the current line number, choosing the encoding
7947 that uses the least amount of space. */
7948 if (line_info->dw_line_num != current_line)
7950 line_offset = line_info->dw_line_num - current_line;
7951 line_delta = line_offset - DWARF_LINE_BASE;
7952 current_line = line_info->dw_line_num;
7953 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7954 /* This can handle deltas from -10 to 234, using the current
7955 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7957 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7958 "line %lu", current_line);
7961 /* This can handle any delta. This takes at least 4 bytes,
7962 depending on the value being encoded. */
7963 dw2_asm_output_data (1, DW_LNS_advance_line,
7964 "advance to line %lu", current_line);
7965 dw2_asm_output_data_sleb128 (line_offset, NULL);
7966 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7970 /* We still need to start a new row, so output a copy insn. */
7971 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7974 /* Emit debug info for the address of the end of the function. */
7977 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7978 "DW_LNS_fixed_advance_pc");
7979 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7983 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7984 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7985 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7986 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7989 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7990 dw2_asm_output_data_uleb128 (1, NULL);
7991 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7996 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7998 dw_separate_line_info_ref line_info
7999 = &separate_line_info_table[lt_index];
8002 /* Don't emit anything for redundant notes. */
8003 if (line_info->dw_line_num == current_line
8004 && line_info->dw_file_num == current_file
8005 && line_info->function == function)
8009 /* Emit debug info for the address of the current line. If this is
8010 a new function, or the first line of a function, then we need
8011 to handle it differently. */
8012 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8014 if (function != line_info->function)
8016 function = line_info->function;
8018 /* Set the address register to the first line in the function. */
8019 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8020 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8021 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8022 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8026 /* ??? See the DW_LNS_advance_pc comment above. */
8029 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8030 "DW_LNS_fixed_advance_pc");
8031 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8035 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8036 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8037 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8038 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8042 strcpy (prev_line_label, line_label);
8044 /* Emit debug info for the source file of the current line, if
8045 different from the previous line. */
8046 if (line_info->dw_file_num != current_file)
8048 current_file = line_info->dw_file_num;
8049 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8050 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
8051 VARRAY_CHAR_PTR (file_table,
8055 /* Emit debug info for the current line number, choosing the encoding
8056 that uses the least amount of space. */
8057 if (line_info->dw_line_num != current_line)
8059 line_offset = line_info->dw_line_num - current_line;
8060 line_delta = line_offset - DWARF_LINE_BASE;
8061 current_line = line_info->dw_line_num;
8062 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8063 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8064 "line %lu", current_line);
8067 dw2_asm_output_data (1, DW_LNS_advance_line,
8068 "advance to line %lu", current_line);
8069 dw2_asm_output_data_sleb128 (line_offset, NULL);
8070 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8074 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8082 /* If we're done with a function, end its sequence. */
8083 if (lt_index == separate_line_info_table_in_use
8084 || separate_line_info_table[lt_index].function != function)
8089 /* Emit debug info for the address of the end of the function. */
8090 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8093 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8094 "DW_LNS_fixed_advance_pc");
8095 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8099 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8100 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8101 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8102 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8105 /* Output the marker for the end of this sequence. */
8106 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8107 dw2_asm_output_data_uleb128 (1, NULL);
8108 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8112 /* Output the marker for the end of the line number info. */
8113 ASM_OUTPUT_LABEL (asm_out_file, l2);
8116 /* Given a pointer to a tree node for some base type, return a pointer to
8117 a DIE that describes the given type.
8119 This routine must only be called for GCC type nodes that correspond to
8120 Dwarf base (fundamental) types. */
8123 base_type_die (tree type)
8125 dw_die_ref base_type_result;
8126 enum dwarf_type encoding;
8128 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8131 switch (TREE_CODE (type))
8134 if (TYPE_STRING_FLAG (type))
8136 if (TYPE_UNSIGNED (type))
8137 encoding = DW_ATE_unsigned_char;
8139 encoding = DW_ATE_signed_char;
8141 else if (TYPE_UNSIGNED (type))
8142 encoding = DW_ATE_unsigned;
8144 encoding = DW_ATE_signed;
8148 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8149 encoding = DW_ATE_decimal_float;
8151 encoding = DW_ATE_float;
8154 /* Dwarf2 doesn't know anything about complex ints, so use
8155 a user defined type for it. */
8157 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8158 encoding = DW_ATE_complex_float;
8160 encoding = DW_ATE_lo_user;
8164 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8165 encoding = DW_ATE_boolean;
8169 /* No other TREE_CODEs are Dwarf fundamental types. */
8173 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8175 /* This probably indicates a bug. */
8176 if (! TYPE_NAME (type))
8177 add_name_attribute (base_type_result, "__unknown__");
8179 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8180 int_size_in_bytes (type));
8181 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8183 return base_type_result;
8186 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8187 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8188 a given type is generally the same as the given type, except that if the
8189 given type is a pointer or reference type, then the root type of the given
8190 type is the root type of the "basis" type for the pointer or reference
8191 type. (This definition of the "root" type is recursive.) Also, the root
8192 type of a `const' qualified type or a `volatile' qualified type is the
8193 root type of the given type without the qualifiers. */
8196 root_type (tree type)
8198 if (TREE_CODE (type) == ERROR_MARK)
8199 return error_mark_node;
8201 switch (TREE_CODE (type))
8204 return error_mark_node;
8207 case REFERENCE_TYPE:
8208 return type_main_variant (root_type (TREE_TYPE (type)));
8211 return type_main_variant (type);
8215 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8216 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8219 is_base_type (tree type)
8221 switch (TREE_CODE (type))
8234 case QUAL_UNION_TYPE:
8239 case REFERENCE_TYPE:
8252 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8253 node, return the size in bits for the type if it is a constant, or else
8254 return the alignment for the type if the type's size is not constant, or
8255 else return BITS_PER_WORD if the type actually turns out to be an
8258 static inline unsigned HOST_WIDE_INT
8259 simple_type_size_in_bits (tree type)
8261 if (TREE_CODE (type) == ERROR_MARK)
8262 return BITS_PER_WORD;
8263 else if (TYPE_SIZE (type) == NULL_TREE)
8265 else if (host_integerp (TYPE_SIZE (type), 1))
8266 return tree_low_cst (TYPE_SIZE (type), 1);
8268 return TYPE_ALIGN (type);
8271 /* Return true if the debug information for the given type should be
8272 emitted as a subrange type. */
8275 is_subrange_type (tree type)
8277 tree subtype = TREE_TYPE (type);
8279 /* Subrange types are identified by the fact that they are integer
8280 types, and that they have a subtype which is either an integer type
8281 or an enumeral type. */
8283 if (TREE_CODE (type) != INTEGER_TYPE
8284 || subtype == NULL_TREE)
8287 if (TREE_CODE (subtype) != INTEGER_TYPE
8288 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8291 if (TREE_CODE (type) == TREE_CODE (subtype)
8292 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8293 && TYPE_MIN_VALUE (type) != NULL
8294 && TYPE_MIN_VALUE (subtype) != NULL
8295 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8296 && TYPE_MAX_VALUE (type) != NULL
8297 && TYPE_MAX_VALUE (subtype) != NULL
8298 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8300 /* The type and its subtype have the same representation. If in
8301 addition the two types also have the same name, then the given
8302 type is not a subrange type, but rather a plain base type. */
8303 /* FIXME: brobecker/2004-03-22:
8304 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8305 therefore be sufficient to check the TYPE_SIZE node pointers
8306 rather than checking the actual size. Unfortunately, we have
8307 found some cases, such as in the Ada "integer" type, where
8308 this is not the case. Until this problem is solved, we need to
8309 keep checking the actual size. */
8310 tree type_name = TYPE_NAME (type);
8311 tree subtype_name = TYPE_NAME (subtype);
8313 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8314 type_name = DECL_NAME (type_name);
8316 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8317 subtype_name = DECL_NAME (subtype_name);
8319 if (type_name == subtype_name)
8326 /* Given a pointer to a tree node for a subrange type, return a pointer
8327 to a DIE that describes the given type. */
8330 subrange_type_die (tree type, dw_die_ref context_die)
8332 dw_die_ref subrange_die;
8333 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8335 if (context_die == NULL)
8336 context_die = comp_unit_die;
8338 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8340 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8342 /* The size of the subrange type and its base type do not match,
8343 so we need to generate a size attribute for the subrange type. */
8344 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8347 if (TYPE_MIN_VALUE (type) != NULL)
8348 add_bound_info (subrange_die, DW_AT_lower_bound,
8349 TYPE_MIN_VALUE (type));
8350 if (TYPE_MAX_VALUE (type) != NULL)
8351 add_bound_info (subrange_die, DW_AT_upper_bound,
8352 TYPE_MAX_VALUE (type));
8354 return subrange_die;
8357 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8358 entry that chains various modifiers in front of the given type. */
8361 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8362 dw_die_ref context_die)
8364 enum tree_code code = TREE_CODE (type);
8365 dw_die_ref mod_type_die;
8366 dw_die_ref sub_die = NULL;
8367 tree item_type = NULL;
8368 tree qualified_type;
8371 if (code == ERROR_MARK)
8374 /* See if we already have the appropriately qualified variant of
8377 = get_qualified_type (type,
8378 ((is_const_type ? TYPE_QUAL_CONST : 0)
8379 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8381 /* If we do, then we can just use its DIE, if it exists. */
8384 mod_type_die = lookup_type_die (qualified_type);
8386 return mod_type_die;
8389 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8391 /* Handle C typedef types. */
8392 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8394 tree dtype = TREE_TYPE (name);
8396 if (qualified_type == dtype)
8398 /* For a named type, use the typedef. */
8399 gen_type_die (qualified_type, context_die);
8400 return lookup_type_die (qualified_type);
8402 else if (DECL_ORIGINAL_TYPE (name)
8403 && (is_const_type < TYPE_READONLY (dtype)
8404 || is_volatile_type < TYPE_VOLATILE (dtype)))
8405 /* cv-unqualified version of named type. Just use the unnamed
8406 type to which it refers. */
8407 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8408 is_const_type, is_volatile_type,
8410 /* Else cv-qualified version of named type; fall through. */
8415 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8416 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8418 else if (is_volatile_type)
8420 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8421 sub_die = modified_type_die (type, 0, 0, context_die);
8423 else if (code == POINTER_TYPE)
8425 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8426 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8427 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8428 item_type = TREE_TYPE (type);
8430 else if (code == REFERENCE_TYPE)
8432 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8433 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8434 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8435 item_type = TREE_TYPE (type);
8437 else if (is_subrange_type (type))
8439 mod_type_die = subrange_type_die (type, context_die);
8440 item_type = TREE_TYPE (type);
8442 else if (is_base_type (type))
8443 mod_type_die = base_type_die (type);
8446 gen_type_die (type, context_die);
8448 /* We have to get the type_main_variant here (and pass that to the
8449 `lookup_type_die' routine) because the ..._TYPE node we have
8450 might simply be a *copy* of some original type node (where the
8451 copy was created to help us keep track of typedef names) and
8452 that copy might have a different TYPE_UID from the original
8454 if (TREE_CODE (type) != VECTOR_TYPE)
8455 return lookup_type_die (type_main_variant (type));
8457 /* Vectors have the debugging information in the type,
8458 not the main variant. */
8459 return lookup_type_die (type);
8462 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8463 don't output a DW_TAG_typedef, since there isn't one in the
8464 user's program; just attach a DW_AT_name to the type. */
8466 && (TREE_CODE (name) != TYPE_DECL || TREE_TYPE (name) == qualified_type))
8468 if (TREE_CODE (name) == TYPE_DECL)
8469 /* Could just call add_name_and_src_coords_attributes here,
8470 but since this is a builtin type it doesn't have any
8471 useful source coordinates anyway. */
8472 name = DECL_NAME (name);
8473 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8477 equate_type_number_to_die (qualified_type, mod_type_die);
8480 /* We must do this after the equate_type_number_to_die call, in case
8481 this is a recursive type. This ensures that the modified_type_die
8482 recursion will terminate even if the type is recursive. Recursive
8483 types are possible in Ada. */
8484 sub_die = modified_type_die (item_type,
8485 TYPE_READONLY (item_type),
8486 TYPE_VOLATILE (item_type),
8489 if (sub_die != NULL)
8490 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8492 return mod_type_die;
8495 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8496 an enumerated type. */
8499 type_is_enum (tree type)
8501 return TREE_CODE (type) == ENUMERAL_TYPE;
8504 /* Return the DBX register number described by a given RTL node. */
8507 dbx_reg_number (rtx rtl)
8509 unsigned regno = REGNO (rtl);
8511 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8513 #ifdef LEAF_REG_REMAP
8514 regno = LEAF_REG_REMAP (regno);
8517 return DBX_REGISTER_NUMBER (regno);
8520 /* Optionally add a DW_OP_piece term to a location description expression.
8521 DW_OP_piece is only added if the location description expression already
8522 doesn't end with DW_OP_piece. */
8525 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8527 dw_loc_descr_ref loc;
8529 if (*list_head != NULL)
8531 /* Find the end of the chain. */
8532 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8535 if (loc->dw_loc_opc != DW_OP_piece)
8536 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8540 /* Return a location descriptor that designates a machine register or
8541 zero if there is none. */
8543 static dw_loc_descr_ref
8544 reg_loc_descriptor (rtx rtl)
8548 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8551 regs = targetm.dwarf_register_span (rtl);
8553 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8554 return multiple_reg_loc_descriptor (rtl, regs);
8556 return one_reg_loc_descriptor (dbx_reg_number (rtl));
8559 /* Return a location descriptor that designates a machine register for
8560 a given hard register number. */
8562 static dw_loc_descr_ref
8563 one_reg_loc_descriptor (unsigned int regno)
8566 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8568 return new_loc_descr (DW_OP_regx, regno, 0);
8571 /* Given an RTL of a register, return a location descriptor that
8572 designates a value that spans more than one register. */
8574 static dw_loc_descr_ref
8575 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8579 dw_loc_descr_ref loc_result = NULL;
8582 #ifdef LEAF_REG_REMAP
8583 reg = LEAF_REG_REMAP (reg);
8585 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8586 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8588 /* Simple, contiguous registers. */
8589 if (regs == NULL_RTX)
8591 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8598 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg));
8599 add_loc_descr (&loc_result, t);
8600 add_loc_descr_op_piece (&loc_result, size);
8606 /* Now onto stupid register sets in non contiguous locations. */
8608 gcc_assert (GET_CODE (regs) == PARALLEL);
8610 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8613 for (i = 0; i < XVECLEN (regs, 0); ++i)
8617 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8618 add_loc_descr (&loc_result, t);
8619 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8620 add_loc_descr_op_piece (&loc_result, size);
8625 /* Return a location descriptor that designates a constant. */
8627 static dw_loc_descr_ref
8628 int_loc_descriptor (HOST_WIDE_INT i)
8630 enum dwarf_location_atom op;
8632 /* Pick the smallest representation of a constant, rather than just
8633 defaulting to the LEB encoding. */
8637 op = DW_OP_lit0 + i;
8640 else if (i <= 0xffff)
8642 else if (HOST_BITS_PER_WIDE_INT == 32
8652 else if (i >= -0x8000)
8654 else if (HOST_BITS_PER_WIDE_INT == 32
8655 || i >= -0x80000000)
8661 return new_loc_descr (op, i, 0);
8664 /* Return a location descriptor that designates a base+offset location. */
8666 static dw_loc_descr_ref
8667 based_loc_descr (rtx reg, HOST_WIDE_INT offset)
8671 /* We only use "frame base" when we're sure we're talking about the
8672 post-prologue local stack frame. We do this by *not* running
8673 register elimination until this point, and recognizing the special
8674 argument pointer and soft frame pointer rtx's. */
8675 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
8677 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
8681 if (GET_CODE (elim) == PLUS)
8683 offset += INTVAL (XEXP (elim, 1));
8684 elim = XEXP (elim, 0);
8686 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
8687 : stack_pointer_rtx));
8688 offset += frame_pointer_fb_offset;
8690 return new_loc_descr (DW_OP_fbreg, offset, 0);
8694 regno = dbx_reg_number (reg);
8696 return new_loc_descr (DW_OP_breg0 + regno, offset, 0);
8698 return new_loc_descr (DW_OP_bregx, regno, offset);
8701 /* Return true if this RTL expression describes a base+offset calculation. */
8704 is_based_loc (rtx rtl)
8706 return (GET_CODE (rtl) == PLUS
8707 && ((REG_P (XEXP (rtl, 0))
8708 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8709 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8712 /* The following routine converts the RTL for a variable or parameter
8713 (resident in memory) into an equivalent Dwarf representation of a
8714 mechanism for getting the address of that same variable onto the top of a
8715 hypothetical "address evaluation" stack.
8717 When creating memory location descriptors, we are effectively transforming
8718 the RTL for a memory-resident object into its Dwarf postfix expression
8719 equivalent. This routine recursively descends an RTL tree, turning
8720 it into Dwarf postfix code as it goes.
8722 MODE is the mode of the memory reference, needed to handle some
8723 autoincrement addressing modes.
8725 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
8726 location list for RTL.
8728 Return 0 if we can't represent the location. */
8730 static dw_loc_descr_ref
8731 mem_loc_descriptor (rtx rtl, enum machine_mode mode)
8733 dw_loc_descr_ref mem_loc_result = NULL;
8734 enum dwarf_location_atom op;
8736 /* Note that for a dynamically sized array, the location we will generate a
8737 description of here will be the lowest numbered location which is
8738 actually within the array. That's *not* necessarily the same as the
8739 zeroth element of the array. */
8741 rtl = targetm.delegitimize_address (rtl);
8743 switch (GET_CODE (rtl))
8748 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8749 just fall into the SUBREG code. */
8751 /* ... fall through ... */
8754 /* The case of a subreg may arise when we have a local (register)
8755 variable or a formal (register) parameter which doesn't quite fill
8756 up an entire register. For now, just assume that it is
8757 legitimate to make the Dwarf info refer to the whole register which
8758 contains the given subreg. */
8759 rtl = XEXP (rtl, 0);
8761 /* ... fall through ... */
8764 /* Whenever a register number forms a part of the description of the
8765 method for calculating the (dynamic) address of a memory resident
8766 object, DWARF rules require the register number be referred to as
8767 a "base register". This distinction is not based in any way upon
8768 what category of register the hardware believes the given register
8769 belongs to. This is strictly DWARF terminology we're dealing with
8770 here. Note that in cases where the location of a memory-resident
8771 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8772 OP_CONST (0)) the actual DWARF location descriptor that we generate
8773 may just be OP_BASEREG (basereg). This may look deceptively like
8774 the object in question was allocated to a register (rather than in
8775 memory) so DWARF consumers need to be aware of the subtle
8776 distinction between OP_REG and OP_BASEREG. */
8777 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8778 mem_loc_result = based_loc_descr (rtl, 0);
8782 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8783 if (mem_loc_result != 0)
8784 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8788 rtl = XEXP (rtl, 1);
8790 /* ... fall through ... */
8793 /* Some ports can transform a symbol ref into a label ref, because
8794 the symbol ref is too far away and has to be dumped into a constant
8798 /* Alternatively, the symbol in the constant pool might be referenced
8799 by a different symbol. */
8800 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8803 rtx tmp = get_pool_constant_mark (rtl, &marked);
8805 if (GET_CODE (tmp) == SYMBOL_REF)
8808 if (CONSTANT_POOL_ADDRESS_P (tmp))
8809 get_pool_constant_mark (tmp, &marked);
8814 /* If all references to this pool constant were optimized away,
8815 it was not output and thus we can't represent it.
8816 FIXME: might try to use DW_OP_const_value here, though
8817 DW_OP_piece complicates it. */
8822 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8823 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8824 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8825 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
8829 /* Extract the PLUS expression nested inside and fall into
8831 rtl = XEXP (rtl, 1);
8836 /* Turn these into a PLUS expression and fall into the PLUS code
8838 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8839 GEN_INT (GET_CODE (rtl) == PRE_INC
8840 ? GET_MODE_UNIT_SIZE (mode)
8841 : -GET_MODE_UNIT_SIZE (mode)));
8843 /* ... fall through ... */
8847 if (is_based_loc (rtl))
8848 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
8849 INTVAL (XEXP (rtl, 1)));
8852 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
8853 if (mem_loc_result == 0)
8856 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8857 && INTVAL (XEXP (rtl, 1)) >= 0)
8858 add_loc_descr (&mem_loc_result,
8859 new_loc_descr (DW_OP_plus_uconst,
8860 INTVAL (XEXP (rtl, 1)), 0));
8863 add_loc_descr (&mem_loc_result,
8864 mem_loc_descriptor (XEXP (rtl, 1), mode));
8865 add_loc_descr (&mem_loc_result,
8866 new_loc_descr (DW_OP_plus, 0, 0));
8871 /* If a pseudo-reg is optimized away, it is possible for it to
8872 be replaced with a MEM containing a multiply or shift. */
8891 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
8892 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
8894 if (op0 == 0 || op1 == 0)
8897 mem_loc_result = op0;
8898 add_loc_descr (&mem_loc_result, op1);
8899 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
8904 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8911 return mem_loc_result;
8914 /* Return a descriptor that describes the concatenation of two locations.
8915 This is typically a complex variable. */
8917 static dw_loc_descr_ref
8918 concat_loc_descriptor (rtx x0, rtx x1)
8920 dw_loc_descr_ref cc_loc_result = NULL;
8921 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
8922 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
8924 if (x0_ref == 0 || x1_ref == 0)
8927 cc_loc_result = x0_ref;
8928 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
8930 add_loc_descr (&cc_loc_result, x1_ref);
8931 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
8933 return cc_loc_result;
8936 /* Output a proper Dwarf location descriptor for a variable or parameter
8937 which is either allocated in a register or in a memory location. For a
8938 register, we just generate an OP_REG and the register number. For a
8939 memory location we provide a Dwarf postfix expression describing how to
8940 generate the (dynamic) address of the object onto the address stack.
8942 If we don't know how to describe it, return 0. */
8944 static dw_loc_descr_ref
8945 loc_descriptor (rtx rtl)
8947 dw_loc_descr_ref loc_result = NULL;
8949 switch (GET_CODE (rtl))
8952 /* The case of a subreg may arise when we have a local (register)
8953 variable or a formal (register) parameter which doesn't quite fill
8954 up an entire register. For now, just assume that it is
8955 legitimate to make the Dwarf info refer to the whole register which
8956 contains the given subreg. */
8957 rtl = SUBREG_REG (rtl);
8959 /* ... fall through ... */
8962 loc_result = reg_loc_descriptor (rtl);
8966 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8970 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8975 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
8977 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0));
8981 rtl = XEXP (rtl, 1);
8986 rtvec par_elems = XVEC (rtl, 0);
8987 int num_elem = GET_NUM_ELEM (par_elems);
8988 enum machine_mode mode;
8991 /* Create the first one, so we have something to add to. */
8992 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0));
8993 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
8994 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
8995 for (i = 1; i < num_elem; i++)
8997 dw_loc_descr_ref temp;
8999 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0));
9000 add_loc_descr (&loc_result, temp);
9001 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9002 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9014 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9015 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9016 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9017 top-level invocation, and we require the address of LOC; is 0 if we require
9018 the value of LOC. */
9020 static dw_loc_descr_ref
9021 loc_descriptor_from_tree_1 (tree loc, int want_address)
9023 dw_loc_descr_ref ret, ret1;
9024 int have_address = 0;
9025 enum dwarf_location_atom op;
9027 /* ??? Most of the time we do not take proper care for sign/zero
9028 extending the values properly. Hopefully this won't be a real
9031 switch (TREE_CODE (loc))
9036 case PLACEHOLDER_EXPR:
9037 /* This case involves extracting fields from an object to determine the
9038 position of other fields. We don't try to encode this here. The
9039 only user of this is Ada, which encodes the needed information using
9040 the names of types. */
9046 case PREINCREMENT_EXPR:
9047 case PREDECREMENT_EXPR:
9048 case POSTINCREMENT_EXPR:
9049 case POSTDECREMENT_EXPR:
9050 /* There are no opcodes for these operations. */
9054 /* If we already want an address, there's nothing we can do. */
9058 /* Otherwise, process the argument and look for the address. */
9059 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9062 if (DECL_THREAD_LOCAL_P (loc))
9066 /* If this is not defined, we have no way to emit the data. */
9067 if (!targetm.asm_out.output_dwarf_dtprel)
9070 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9071 look up addresses of objects in the current module. */
9072 if (DECL_EXTERNAL (loc))
9075 rtl = rtl_for_decl_location (loc);
9076 if (rtl == NULL_RTX)
9081 rtl = XEXP (rtl, 0);
9082 if (! CONSTANT_P (rtl))
9085 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9086 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9087 ret->dw_loc_oprnd1.v.val_addr = rtl;
9089 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9090 add_loc_descr (&ret, ret1);
9098 if (DECL_HAS_VALUE_EXPR_P (loc))
9099 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9105 rtx rtl = rtl_for_decl_location (loc);
9107 if (rtl == NULL_RTX)
9109 else if (GET_CODE (rtl) == CONST_INT)
9111 HOST_WIDE_INT val = INTVAL (rtl);
9112 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9113 val &= GET_MODE_MASK (DECL_MODE (loc));
9114 ret = int_loc_descriptor (val);
9116 else if (GET_CODE (rtl) == CONST_STRING)
9118 else if (CONSTANT_P (rtl))
9120 ret = new_loc_descr (DW_OP_addr, 0, 0);
9121 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9122 ret->dw_loc_oprnd1.v.val_addr = rtl;
9126 enum machine_mode mode;
9128 /* Certain constructs can only be represented at top-level. */
9129 if (want_address == 2)
9130 return loc_descriptor (rtl);
9132 mode = GET_MODE (rtl);
9135 rtl = XEXP (rtl, 0);
9138 ret = mem_loc_descriptor (rtl, mode);
9144 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9149 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9153 case NON_LVALUE_EXPR:
9154 case VIEW_CONVERT_EXPR:
9157 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
9162 case ARRAY_RANGE_REF:
9165 HOST_WIDE_INT bitsize, bitpos, bytepos;
9166 enum machine_mode mode;
9168 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9170 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9171 &unsignedp, &volatilep, false);
9176 ret = loc_descriptor_from_tree_1 (obj, 1);
9178 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9181 if (offset != NULL_TREE)
9183 /* Variable offset. */
9184 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9185 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9188 bytepos = bitpos / BITS_PER_UNIT;
9190 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9191 else if (bytepos < 0)
9193 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9194 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9202 if (host_integerp (loc, 0))
9203 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9210 /* Get an RTL for this, if something has been emitted. */
9211 rtx rtl = lookup_constant_def (loc);
9212 enum machine_mode mode;
9214 if (!rtl || !MEM_P (rtl))
9216 mode = GET_MODE (rtl);
9217 rtl = XEXP (rtl, 0);
9218 ret = mem_loc_descriptor (rtl, mode);
9223 case TRUTH_AND_EXPR:
9224 case TRUTH_ANDIF_EXPR:
9229 case TRUTH_XOR_EXPR:
9235 case TRUTH_ORIF_EXPR:
9240 case FLOOR_DIV_EXPR:
9242 case ROUND_DIV_EXPR:
9243 case TRUNC_DIV_EXPR:
9251 case FLOOR_MOD_EXPR:
9253 case ROUND_MOD_EXPR:
9254 case TRUNC_MOD_EXPR:
9267 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9271 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9272 && host_integerp (TREE_OPERAND (loc, 1), 0))
9274 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9278 add_loc_descr (&ret,
9279 new_loc_descr (DW_OP_plus_uconst,
9280 tree_low_cst (TREE_OPERAND (loc, 1),
9290 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9297 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9304 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9311 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9326 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9327 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9328 if (ret == 0 || ret1 == 0)
9331 add_loc_descr (&ret, ret1);
9332 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9335 case TRUTH_NOT_EXPR:
9349 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9353 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9359 const enum tree_code code =
9360 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9362 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9363 build2 (code, integer_type_node,
9364 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9365 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9368 /* ... fall through ... */
9372 dw_loc_descr_ref lhs
9373 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9374 dw_loc_descr_ref rhs
9375 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9376 dw_loc_descr_ref bra_node, jump_node, tmp;
9378 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9379 if (ret == 0 || lhs == 0 || rhs == 0)
9382 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9383 add_loc_descr (&ret, bra_node);
9385 add_loc_descr (&ret, rhs);
9386 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9387 add_loc_descr (&ret, jump_node);
9389 add_loc_descr (&ret, lhs);
9390 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9391 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9393 /* ??? Need a node to point the skip at. Use a nop. */
9394 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9395 add_loc_descr (&ret, tmp);
9396 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9397 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9401 case FIX_TRUNC_EXPR:
9403 case FIX_FLOOR_EXPR:
9404 case FIX_ROUND_EXPR:
9408 /* Leave front-end specific codes as simply unknown. This comes
9409 up, for instance, with the C STMT_EXPR. */
9410 if ((unsigned int) TREE_CODE (loc)
9411 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9414 #ifdef ENABLE_CHECKING
9415 /* Otherwise this is a generic code; we should just lists all of
9416 these explicitly. We forgot one. */
9419 /* In a release build, we want to degrade gracefully: better to
9420 generate incomplete debugging information than to crash. */
9425 /* Show if we can't fill the request for an address. */
9426 if (want_address && !have_address)
9429 /* If we've got an address and don't want one, dereference. */
9430 if (!want_address && have_address && ret)
9432 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9434 if (size > DWARF2_ADDR_SIZE || size == -1)
9436 else if (size == DWARF2_ADDR_SIZE)
9439 op = DW_OP_deref_size;
9441 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9447 static inline dw_loc_descr_ref
9448 loc_descriptor_from_tree (tree loc)
9450 return loc_descriptor_from_tree_1 (loc, 2);
9453 /* Given a value, round it up to the lowest multiple of `boundary'
9454 which is not less than the value itself. */
9456 static inline HOST_WIDE_INT
9457 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9459 return (((value + boundary - 1) / boundary) * boundary);
9462 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9463 pointer to the declared type for the relevant field variable, or return
9464 `integer_type_node' if the given node turns out to be an
9468 field_type (tree decl)
9472 if (TREE_CODE (decl) == ERROR_MARK)
9473 return integer_type_node;
9475 type = DECL_BIT_FIELD_TYPE (decl);
9476 if (type == NULL_TREE)
9477 type = TREE_TYPE (decl);
9482 /* Given a pointer to a tree node, return the alignment in bits for
9483 it, or else return BITS_PER_WORD if the node actually turns out to
9484 be an ERROR_MARK node. */
9486 static inline unsigned
9487 simple_type_align_in_bits (tree type)
9489 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9492 static inline unsigned
9493 simple_decl_align_in_bits (tree decl)
9495 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9498 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9499 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9500 or return 0 if we are unable to determine what that offset is, either
9501 because the argument turns out to be a pointer to an ERROR_MARK node, or
9502 because the offset is actually variable. (We can't handle the latter case
9505 static HOST_WIDE_INT
9506 field_byte_offset (tree decl)
9508 unsigned int type_align_in_bits;
9509 unsigned int decl_align_in_bits;
9510 unsigned HOST_WIDE_INT type_size_in_bits;
9511 HOST_WIDE_INT object_offset_in_bits;
9513 tree field_size_tree;
9514 HOST_WIDE_INT bitpos_int;
9515 HOST_WIDE_INT deepest_bitpos;
9516 unsigned HOST_WIDE_INT field_size_in_bits;
9518 if (TREE_CODE (decl) == ERROR_MARK)
9521 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9523 type = field_type (decl);
9524 field_size_tree = DECL_SIZE (decl);
9526 /* The size could be unspecified if there was an error, or for
9527 a flexible array member. */
9528 if (! field_size_tree)
9529 field_size_tree = bitsize_zero_node;
9531 /* We cannot yet cope with fields whose positions are variable, so
9532 for now, when we see such things, we simply return 0. Someday, we may
9533 be able to handle such cases, but it will be damn difficult. */
9534 if (! host_integerp (bit_position (decl), 0))
9537 bitpos_int = int_bit_position (decl);
9539 /* If we don't know the size of the field, pretend it's a full word. */
9540 if (host_integerp (field_size_tree, 1))
9541 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9543 field_size_in_bits = BITS_PER_WORD;
9545 type_size_in_bits = simple_type_size_in_bits (type);
9546 type_align_in_bits = simple_type_align_in_bits (type);
9547 decl_align_in_bits = simple_decl_align_in_bits (decl);
9549 /* The GCC front-end doesn't make any attempt to keep track of the starting
9550 bit offset (relative to the start of the containing structure type) of the
9551 hypothetical "containing object" for a bit-field. Thus, when computing
9552 the byte offset value for the start of the "containing object" of a
9553 bit-field, we must deduce this information on our own. This can be rather
9554 tricky to do in some cases. For example, handling the following structure
9555 type definition when compiling for an i386/i486 target (which only aligns
9556 long long's to 32-bit boundaries) can be very tricky:
9558 struct S { int field1; long long field2:31; };
9560 Fortunately, there is a simple rule-of-thumb which can be used in such
9561 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9562 structure shown above. It decides to do this based upon one simple rule
9563 for bit-field allocation. GCC allocates each "containing object" for each
9564 bit-field at the first (i.e. lowest addressed) legitimate alignment
9565 boundary (based upon the required minimum alignment for the declared type
9566 of the field) which it can possibly use, subject to the condition that
9567 there is still enough available space remaining in the containing object
9568 (when allocated at the selected point) to fully accommodate all of the
9569 bits of the bit-field itself.
9571 This simple rule makes it obvious why GCC allocates 8 bytes for each
9572 object of the structure type shown above. When looking for a place to
9573 allocate the "containing object" for `field2', the compiler simply tries
9574 to allocate a 64-bit "containing object" at each successive 32-bit
9575 boundary (starting at zero) until it finds a place to allocate that 64-
9576 bit field such that at least 31 contiguous (and previously unallocated)
9577 bits remain within that selected 64 bit field. (As it turns out, for the
9578 example above, the compiler finds it is OK to allocate the "containing
9579 object" 64-bit field at bit-offset zero within the structure type.)
9581 Here we attempt to work backwards from the limited set of facts we're
9582 given, and we try to deduce from those facts, where GCC must have believed
9583 that the containing object started (within the structure type). The value
9584 we deduce is then used (by the callers of this routine) to generate
9585 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9586 and, in the case of DW_AT_location, regular fields as well). */
9588 /* Figure out the bit-distance from the start of the structure to the
9589 "deepest" bit of the bit-field. */
9590 deepest_bitpos = bitpos_int + field_size_in_bits;
9592 /* This is the tricky part. Use some fancy footwork to deduce where the
9593 lowest addressed bit of the containing object must be. */
9594 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9596 /* Round up to type_align by default. This works best for bitfields. */
9597 object_offset_in_bits += type_align_in_bits - 1;
9598 object_offset_in_bits /= type_align_in_bits;
9599 object_offset_in_bits *= type_align_in_bits;
9601 if (object_offset_in_bits > bitpos_int)
9603 /* Sigh, the decl must be packed. */
9604 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9606 /* Round up to decl_align instead. */
9607 object_offset_in_bits += decl_align_in_bits - 1;
9608 object_offset_in_bits /= decl_align_in_bits;
9609 object_offset_in_bits *= decl_align_in_bits;
9612 return object_offset_in_bits / BITS_PER_UNIT;
9615 /* The following routines define various Dwarf attributes and any data
9616 associated with them. */
9618 /* Add a location description attribute value to a DIE.
9620 This emits location attributes suitable for whole variables and
9621 whole parameters. Note that the location attributes for struct fields are
9622 generated by the routine `data_member_location_attribute' below. */
9625 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9626 dw_loc_descr_ref descr)
9629 add_AT_loc (die, attr_kind, descr);
9632 /* Attach the specialized form of location attribute used for data members of
9633 struct and union types. In the special case of a FIELD_DECL node which
9634 represents a bit-field, the "offset" part of this special location
9635 descriptor must indicate the distance in bytes from the lowest-addressed
9636 byte of the containing struct or union type to the lowest-addressed byte of
9637 the "containing object" for the bit-field. (See the `field_byte_offset'
9640 For any given bit-field, the "containing object" is a hypothetical object
9641 (of some integral or enum type) within which the given bit-field lives. The
9642 type of this hypothetical "containing object" is always the same as the
9643 declared type of the individual bit-field itself (for GCC anyway... the
9644 DWARF spec doesn't actually mandate this). Note that it is the size (in
9645 bytes) of the hypothetical "containing object" which will be given in the
9646 DW_AT_byte_size attribute for this bit-field. (See the
9647 `byte_size_attribute' function below.) It is also used when calculating the
9648 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9652 add_data_member_location_attribute (dw_die_ref die, tree decl)
9654 HOST_WIDE_INT offset;
9655 dw_loc_descr_ref loc_descr = 0;
9657 if (TREE_CODE (decl) == TREE_BINFO)
9659 /* We're working on the TAG_inheritance for a base class. */
9660 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
9662 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9663 aren't at a fixed offset from all (sub)objects of the same
9664 type. We need to extract the appropriate offset from our
9665 vtable. The following dwarf expression means
9667 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9669 This is specific to the V3 ABI, of course. */
9671 dw_loc_descr_ref tmp;
9673 /* Make a copy of the object address. */
9674 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9675 add_loc_descr (&loc_descr, tmp);
9677 /* Extract the vtable address. */
9678 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9679 add_loc_descr (&loc_descr, tmp);
9681 /* Calculate the address of the offset. */
9682 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9683 gcc_assert (offset < 0);
9685 tmp = int_loc_descriptor (-offset);
9686 add_loc_descr (&loc_descr, tmp);
9687 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9688 add_loc_descr (&loc_descr, tmp);
9690 /* Extract the offset. */
9691 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9692 add_loc_descr (&loc_descr, tmp);
9694 /* Add it to the object address. */
9695 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9696 add_loc_descr (&loc_descr, tmp);
9699 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9702 offset = field_byte_offset (decl);
9706 enum dwarf_location_atom op;
9708 /* The DWARF2 standard says that we should assume that the structure
9709 address is already on the stack, so we can specify a structure field
9710 address by using DW_OP_plus_uconst. */
9712 #ifdef MIPS_DEBUGGING_INFO
9713 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9714 operator correctly. It works only if we leave the offset on the
9718 op = DW_OP_plus_uconst;
9721 loc_descr = new_loc_descr (op, offset, 0);
9724 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9727 /* Writes integer values to dw_vec_const array. */
9730 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
9734 *dest++ = val & 0xff;
9740 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9742 static HOST_WIDE_INT
9743 extract_int (const unsigned char *src, unsigned int size)
9745 HOST_WIDE_INT val = 0;
9751 val |= *--src & 0xff;
9757 /* Writes floating point values to dw_vec_const array. */
9760 insert_float (rtx rtl, unsigned char *array)
9766 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9767 real_to_target (val, &rv, GET_MODE (rtl));
9769 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9770 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
9772 insert_int (val[i], 4, array);
9777 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9778 does not have a "location" either in memory or in a register. These
9779 things can arise in GNU C when a constant is passed as an actual parameter
9780 to an inlined function. They can also arise in C++ where declared
9781 constants do not necessarily get memory "homes". */
9784 add_const_value_attribute (dw_die_ref die, rtx rtl)
9786 switch (GET_CODE (rtl))
9790 HOST_WIDE_INT val = INTVAL (rtl);
9793 add_AT_int (die, DW_AT_const_value, val);
9795 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
9800 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9801 floating-point constant. A CONST_DOUBLE is used whenever the
9802 constant requires more than one word in order to be adequately
9803 represented. We output CONST_DOUBLEs as blocks. */
9805 enum machine_mode mode = GET_MODE (rtl);
9807 if (SCALAR_FLOAT_MODE_P (mode))
9809 unsigned int length = GET_MODE_SIZE (mode);
9810 unsigned char *array = ggc_alloc (length);
9812 insert_float (rtl, array);
9813 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
9817 /* ??? We really should be using HOST_WIDE_INT throughout. */
9818 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
9820 add_AT_long_long (die, DW_AT_const_value,
9821 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9828 enum machine_mode mode = GET_MODE (rtl);
9829 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
9830 unsigned int length = CONST_VECTOR_NUNITS (rtl);
9831 unsigned char *array = ggc_alloc (length * elt_size);
9835 switch (GET_MODE_CLASS (mode))
9837 case MODE_VECTOR_INT:
9838 for (i = 0, p = array; i < length; i++, p += elt_size)
9840 rtx elt = CONST_VECTOR_ELT (rtl, i);
9841 HOST_WIDE_INT lo, hi;
9843 switch (GET_CODE (elt))
9851 lo = CONST_DOUBLE_LOW (elt);
9852 hi = CONST_DOUBLE_HIGH (elt);
9859 if (elt_size <= sizeof (HOST_WIDE_INT))
9860 insert_int (lo, elt_size, p);
9863 unsigned char *p0 = p;
9864 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
9866 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
9867 if (WORDS_BIG_ENDIAN)
9872 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
9873 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
9878 case MODE_VECTOR_FLOAT:
9879 for (i = 0, p = array; i < length; i++, p += elt_size)
9881 rtx elt = CONST_VECTOR_ELT (rtl, i);
9882 insert_float (elt, p);
9890 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
9895 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9901 add_AT_addr (die, DW_AT_const_value, rtl);
9902 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9906 /* In cases where an inlined instance of an inline function is passed
9907 the address of an `auto' variable (which is local to the caller) we
9908 can get a situation where the DECL_RTL of the artificial local
9909 variable (for the inlining) which acts as a stand-in for the
9910 corresponding formal parameter (of the inline function) will look
9911 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9912 exactly a compile-time constant expression, but it isn't the address
9913 of the (artificial) local variable either. Rather, it represents the
9914 *value* which the artificial local variable always has during its
9915 lifetime. We currently have no way to represent such quasi-constant
9916 values in Dwarf, so for now we just punt and generate nothing. */
9920 /* No other kinds of rtx should be possible here. */
9926 /* Determine whether the evaluation of EXPR references any variables
9927 or functions which aren't otherwise used (and therefore may not be
9930 reference_to_unused (tree * tp, int * walk_subtrees,
9931 void * data ATTRIBUTE_UNUSED)
9933 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
9936 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
9937 && ! TREE_ASM_WRITTEN (*tp))
9943 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
9944 for use in a later add_const_value_attribute call. */
9947 rtl_for_decl_init (tree init, tree type)
9951 /* If a variable is initialized with a string constant without embedded
9952 zeros, build CONST_STRING. */
9953 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
9955 tree enttype = TREE_TYPE (type);
9956 tree domain = TYPE_DOMAIN (type);
9957 enum machine_mode mode = TYPE_MODE (enttype);
9959 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9961 && integer_zerop (TYPE_MIN_VALUE (domain))
9962 && compare_tree_int (TYPE_MAX_VALUE (domain),
9963 TREE_STRING_LENGTH (init) - 1) == 0
9964 && ((size_t) TREE_STRING_LENGTH (init)
9965 == strlen (TREE_STRING_POINTER (init)) + 1))
9966 rtl = gen_rtx_CONST_STRING (VOIDmode,
9967 ggc_strdup (TREE_STRING_POINTER (init)));
9969 /* Although DWARF could easily handle other kinds of aggregates, we
9970 have no way to represent such values as RTL constants, so skip
9972 else if (AGGREGATE_TYPE_P (type))
9974 /* If the initializer is something that we know will expand into an
9975 immediate RTL constant, expand it now. We must be careful not to
9976 reference variables which won't be output. */
9977 else if (initializer_constant_valid_p (init, type)
9978 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
9980 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
9982 /* If expand_expr returns a MEM, it wasn't immediate. */
9983 gcc_assert (!rtl || !MEM_P (rtl));
9989 /* Generate RTL for the variable DECL to represent its location. */
9992 rtl_for_decl_location (tree decl)
9996 /* Here we have to decide where we are going to say the parameter "lives"
9997 (as far as the debugger is concerned). We only have a couple of
9998 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10000 DECL_RTL normally indicates where the parameter lives during most of the
10001 activation of the function. If optimization is enabled however, this
10002 could be either NULL or else a pseudo-reg. Both of those cases indicate
10003 that the parameter doesn't really live anywhere (as far as the code
10004 generation parts of GCC are concerned) during most of the function's
10005 activation. That will happen (for example) if the parameter is never
10006 referenced within the function.
10008 We could just generate a location descriptor here for all non-NULL
10009 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10010 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10011 where DECL_RTL is NULL or is a pseudo-reg.
10013 Note however that we can only get away with using DECL_INCOMING_RTL as
10014 a backup substitute for DECL_RTL in certain limited cases. In cases
10015 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10016 we can be sure that the parameter was passed using the same type as it is
10017 declared to have within the function, and that its DECL_INCOMING_RTL
10018 points us to a place where a value of that type is passed.
10020 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10021 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10022 because in these cases DECL_INCOMING_RTL points us to a value of some
10023 type which is *different* from the type of the parameter itself. Thus,
10024 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10025 such cases, the debugger would end up (for example) trying to fetch a
10026 `float' from a place which actually contains the first part of a
10027 `double'. That would lead to really incorrect and confusing
10028 output at debug-time.
10030 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10031 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10032 are a couple of exceptions however. On little-endian machines we can
10033 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10034 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10035 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10036 when (on a little-endian machine) a non-prototyped function has a
10037 parameter declared to be of type `short' or `char'. In such cases,
10038 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10039 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10040 passed `int' value. If the debugger then uses that address to fetch
10041 a `short' or a `char' (on a little-endian machine) the result will be
10042 the correct data, so we allow for such exceptional cases below.
10044 Note that our goal here is to describe the place where the given formal
10045 parameter lives during most of the function's activation (i.e. between the
10046 end of the prologue and the start of the epilogue). We'll do that as best
10047 as we can. Note however that if the given formal parameter is modified
10048 sometime during the execution of the function, then a stack backtrace (at
10049 debug-time) will show the function as having been called with the *new*
10050 value rather than the value which was originally passed in. This happens
10051 rarely enough that it is not a major problem, but it *is* a problem, and
10052 I'd like to fix it.
10054 A future version of dwarf2out.c may generate two additional attributes for
10055 any given DW_TAG_formal_parameter DIE which will describe the "passed
10056 type" and the "passed location" for the given formal parameter in addition
10057 to the attributes we now generate to indicate the "declared type" and the
10058 "active location" for each parameter. This additional set of attributes
10059 could be used by debuggers for stack backtraces. Separately, note that
10060 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10061 This happens (for example) for inlined-instances of inline function formal
10062 parameters which are never referenced. This really shouldn't be
10063 happening. All PARM_DECL nodes should get valid non-NULL
10064 DECL_INCOMING_RTL values. FIXME. */
10066 /* Use DECL_RTL as the "location" unless we find something better. */
10067 rtl = DECL_RTL_IF_SET (decl);
10069 /* When generating abstract instances, ignore everything except
10070 constants, symbols living in memory, and symbols living in
10071 fixed registers. */
10072 if (! reload_completed)
10075 && (CONSTANT_P (rtl)
10077 && CONSTANT_P (XEXP (rtl, 0)))
10079 && TREE_CODE (decl) == VAR_DECL
10080 && TREE_STATIC (decl))))
10082 rtl = targetm.delegitimize_address (rtl);
10087 else if (TREE_CODE (decl) == PARM_DECL)
10089 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10091 tree declared_type = TREE_TYPE (decl);
10092 tree passed_type = DECL_ARG_TYPE (decl);
10093 enum machine_mode dmode = TYPE_MODE (declared_type);
10094 enum machine_mode pmode = TYPE_MODE (passed_type);
10096 /* This decl represents a formal parameter which was optimized out.
10097 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10098 all cases where (rtl == NULL_RTX) just below. */
10099 if (dmode == pmode)
10100 rtl = DECL_INCOMING_RTL (decl);
10101 else if (SCALAR_INT_MODE_P (dmode)
10102 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10103 && DECL_INCOMING_RTL (decl))
10105 rtx inc = DECL_INCOMING_RTL (decl);
10108 else if (MEM_P (inc))
10110 if (BYTES_BIG_ENDIAN)
10111 rtl = adjust_address_nv (inc, dmode,
10112 GET_MODE_SIZE (pmode)
10113 - GET_MODE_SIZE (dmode));
10120 /* If the parm was passed in registers, but lives on the stack, then
10121 make a big endian correction if the mode of the type of the
10122 parameter is not the same as the mode of the rtl. */
10123 /* ??? This is the same series of checks that are made in dbxout.c before
10124 we reach the big endian correction code there. It isn't clear if all
10125 of these checks are necessary here, but keeping them all is the safe
10127 else if (MEM_P (rtl)
10128 && XEXP (rtl, 0) != const0_rtx
10129 && ! CONSTANT_P (XEXP (rtl, 0))
10130 /* Not passed in memory. */
10131 && !MEM_P (DECL_INCOMING_RTL (decl))
10132 /* Not passed by invisible reference. */
10133 && (!REG_P (XEXP (rtl, 0))
10134 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10135 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10136 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10137 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10140 /* Big endian correction check. */
10141 && BYTES_BIG_ENDIAN
10142 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10143 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10146 int offset = (UNITS_PER_WORD
10147 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10149 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10150 plus_constant (XEXP (rtl, 0), offset));
10153 else if (TREE_CODE (decl) == VAR_DECL
10156 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10157 && BYTES_BIG_ENDIAN)
10159 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10160 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10162 /* If a variable is declared "register" yet is smaller than
10163 a register, then if we store the variable to memory, it
10164 looks like we're storing a register-sized value, when in
10165 fact we are not. We need to adjust the offset of the
10166 storage location to reflect the actual value's bytes,
10167 else gdb will not be able to display it. */
10169 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10170 plus_constant (XEXP (rtl, 0), rsize-dsize));
10173 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10174 and will have been substituted directly into all expressions that use it.
10175 C does not have such a concept, but C++ and other languages do. */
10176 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10177 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10180 rtl = targetm.delegitimize_address (rtl);
10182 /* If we don't look past the constant pool, we risk emitting a
10183 reference to a constant pool entry that isn't referenced from
10184 code, and thus is not emitted. */
10186 rtl = avoid_constant_pool_reference (rtl);
10191 /* We need to figure out what section we should use as the base for the
10192 address ranges where a given location is valid.
10193 1. If this particular DECL has a section associated with it, use that.
10194 2. If this function has a section associated with it, use that.
10195 3. Otherwise, use the text section.
10196 XXX: If you split a variable across multiple sections, we won't notice. */
10198 static const char *
10199 secname_for_decl (tree decl)
10201 const char *secname;
10203 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10205 tree sectree = DECL_SECTION_NAME (decl);
10206 secname = TREE_STRING_POINTER (sectree);
10208 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10210 tree sectree = DECL_SECTION_NAME (current_function_decl);
10211 secname = TREE_STRING_POINTER (sectree);
10213 else if (cfun && in_cold_section_p)
10214 secname = cfun->cold_section_label;
10216 secname = text_section_label;
10221 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10222 data attribute for a variable or a parameter. We generate the
10223 DW_AT_const_value attribute only in those cases where the given variable
10224 or parameter does not have a true "location" either in memory or in a
10225 register. This can happen (for example) when a constant is passed as an
10226 actual argument in a call to an inline function. (It's possible that
10227 these things can crop up in other ways also.) Note that one type of
10228 constant value which can be passed into an inlined function is a constant
10229 pointer. This can happen for example if an actual argument in an inlined
10230 function call evaluates to a compile-time constant address. */
10233 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10234 enum dwarf_attribute attr)
10237 dw_loc_descr_ref descr;
10238 var_loc_list *loc_list;
10239 struct var_loc_node *node;
10240 if (TREE_CODE (decl) == ERROR_MARK)
10243 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10244 || TREE_CODE (decl) == RESULT_DECL);
10246 /* See if we possibly have multiple locations for this variable. */
10247 loc_list = lookup_decl_loc (decl);
10249 /* If it truly has multiple locations, the first and last node will
10251 if (loc_list && loc_list->first != loc_list->last)
10253 const char *endname, *secname;
10254 dw_loc_list_ref list;
10257 /* Now that we know what section we are using for a base,
10258 actually construct the list of locations.
10259 The first location information is what is passed to the
10260 function that creates the location list, and the remaining
10261 locations just get added on to that list.
10262 Note that we only know the start address for a location
10263 (IE location changes), so to build the range, we use
10264 the range [current location start, next location start].
10265 This means we have to special case the last node, and generate
10266 a range of [last location start, end of function label]. */
10268 node = loc_list->first;
10269 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10270 secname = secname_for_decl (decl);
10272 list = new_loc_list (loc_descriptor (varloc),
10273 node->label, node->next->label, secname, 1);
10276 for (; node->next; node = node->next)
10277 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10279 /* The variable has a location between NODE->LABEL and
10280 NODE->NEXT->LABEL. */
10281 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10282 add_loc_descr_to_loc_list (&list, loc_descriptor (varloc),
10283 node->label, node->next->label, secname);
10286 /* If the variable has a location at the last label
10287 it keeps its location until the end of function. */
10288 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10290 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10292 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10293 if (!current_function_decl)
10294 endname = text_end_label;
10297 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10298 current_function_funcdef_no);
10299 endname = ggc_strdup (label_id);
10301 add_loc_descr_to_loc_list (&list, loc_descriptor (varloc),
10302 node->label, endname, secname);
10305 /* Finally, add the location list to the DIE, and we are done. */
10306 add_AT_loc_list (die, attr, list);
10310 /* Try to get some constant RTL for this decl, and use that as the value of
10313 rtl = rtl_for_decl_location (decl);
10314 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10316 add_const_value_attribute (die, rtl);
10320 /* If we have tried to generate the location otherwise, and it
10321 didn't work out (we wouldn't be here if we did), and we have a one entry
10322 location list, try generating a location from that. */
10323 if (loc_list && loc_list->first)
10325 node = loc_list->first;
10326 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note));
10329 add_AT_location_description (die, attr, descr);
10334 /* We couldn't get any rtl, so try directly generating the location
10335 description from the tree. */
10336 descr = loc_descriptor_from_tree (decl);
10339 add_AT_location_description (die, attr, descr);
10342 /* None of that worked, so it must not really have a location;
10343 try adding a constant value attribute from the DECL_INITIAL. */
10344 tree_add_const_value_attribute (die, decl);
10347 /* If we don't have a copy of this variable in memory for some reason (such
10348 as a C++ member constant that doesn't have an out-of-line definition),
10349 we should tell the debugger about the constant value. */
10352 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10354 tree init = DECL_INITIAL (decl);
10355 tree type = TREE_TYPE (decl);
10358 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10363 rtl = rtl_for_decl_init (init, type);
10365 add_const_value_attribute (var_die, rtl);
10368 /* Convert the CFI instructions for the current function into a
10369 location list. This is used for DW_AT_frame_base when we targeting
10370 a dwarf2 consumer that does not support the dwarf3
10371 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10374 static dw_loc_list_ref
10375 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
10378 dw_loc_list_ref list, *list_tail;
10380 dw_cfa_location last_cfa, next_cfa;
10381 const char *start_label, *last_label, *section;
10383 fde = &fde_table[fde_table_in_use - 1];
10385 section = secname_for_decl (current_function_decl);
10389 next_cfa.reg = INVALID_REGNUM;
10390 next_cfa.offset = 0;
10391 next_cfa.indirect = 0;
10392 next_cfa.base_offset = 0;
10394 start_label = fde->dw_fde_begin;
10396 /* ??? Bald assumption that the CIE opcode list does not contain
10397 advance opcodes. */
10398 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
10399 lookup_cfa_1 (cfi, &next_cfa);
10401 last_cfa = next_cfa;
10402 last_label = start_label;
10404 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
10405 switch (cfi->dw_cfi_opc)
10407 case DW_CFA_advance_loc1:
10408 case DW_CFA_advance_loc2:
10409 case DW_CFA_advance_loc4:
10410 if (!cfa_equal_p (&last_cfa, &next_cfa))
10412 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10413 start_label, last_label, section,
10416 list_tail = &(*list_tail)->dw_loc_next;
10417 last_cfa = next_cfa;
10418 start_label = last_label;
10420 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
10423 case DW_CFA_advance_loc:
10424 /* The encoding is complex enough that we should never emit this. */
10425 case DW_CFA_remember_state:
10426 case DW_CFA_restore_state:
10427 /* We don't handle these two in this function. It would be possible
10428 if it were to be required. */
10429 gcc_unreachable ();
10432 lookup_cfa_1 (cfi, &next_cfa);
10436 if (!cfa_equal_p (&last_cfa, &next_cfa))
10438 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
10439 start_label, last_label, section,
10441 list_tail = &(*list_tail)->dw_loc_next;
10442 start_label = last_label;
10444 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
10445 start_label, fde->dw_fde_end, section,
10451 /* Compute a displacement from the "steady-state frame pointer" to the
10452 frame base (often the same as the CFA), and store it in
10453 frame_pointer_fb_offset. OFFSET is added to the displacement
10454 before the latter is negated. */
10457 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
10461 #ifdef FRAME_POINTER_CFA_OFFSET
10462 reg = frame_pointer_rtx;
10463 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
10465 reg = arg_pointer_rtx;
10466 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
10469 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
10470 if (GET_CODE (elim) == PLUS)
10472 offset += INTVAL (XEXP (elim, 1));
10473 elim = XEXP (elim, 0);
10475 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
10476 : stack_pointer_rtx));
10478 frame_pointer_fb_offset = -offset;
10481 /* Generate a DW_AT_name attribute given some string value to be included as
10482 the value of the attribute. */
10485 add_name_attribute (dw_die_ref die, const char *name_string)
10487 if (name_string != NULL && *name_string != 0)
10489 if (demangle_name_func)
10490 name_string = (*demangle_name_func) (name_string);
10492 add_AT_string (die, DW_AT_name, name_string);
10496 /* Generate a DW_AT_comp_dir attribute for DIE. */
10499 add_comp_dir_attribute (dw_die_ref die)
10501 const char *wd = get_src_pwd ();
10503 add_AT_string (die, DW_AT_comp_dir, wd);
10506 /* Given a tree node describing an array bound (either lower or upper) output
10507 a representation for that bound. */
10510 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10512 switch (TREE_CODE (bound))
10517 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10519 if (! host_integerp (bound, 0)
10520 || (bound_attr == DW_AT_lower_bound
10521 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10522 || (is_fortran () && integer_onep (bound)))))
10523 /* Use the default. */
10526 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10531 case NON_LVALUE_EXPR:
10532 case VIEW_CONVERT_EXPR:
10533 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10543 dw_die_ref decl_die = lookup_decl_die (bound);
10545 /* ??? Can this happen, or should the variable have been bound
10546 first? Probably it can, since I imagine that we try to create
10547 the types of parameters in the order in which they exist in
10548 the list, and won't have created a forward reference to a
10549 later parameter. */
10550 if (decl_die != NULL)
10551 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10557 /* Otherwise try to create a stack operation procedure to
10558 evaluate the value of the array bound. */
10560 dw_die_ref ctx, decl_die;
10561 dw_loc_descr_ref loc;
10563 loc = loc_descriptor_from_tree (bound);
10567 if (current_function_decl == 0)
10568 ctx = comp_unit_die;
10570 ctx = lookup_decl_die (current_function_decl);
10572 decl_die = new_die (DW_TAG_variable, ctx, bound);
10573 add_AT_flag (decl_die, DW_AT_artificial, 1);
10574 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10575 add_AT_loc (decl_die, DW_AT_location, loc);
10577 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10583 /* Note that the block of subscript information for an array type also
10584 includes information about the element type of type given array type. */
10587 add_subscript_info (dw_die_ref type_die, tree type)
10589 #ifndef MIPS_DEBUGGING_INFO
10590 unsigned dimension_number;
10593 dw_die_ref subrange_die;
10595 /* The GNU compilers represent multidimensional array types as sequences of
10596 one dimensional array types whose element types are themselves array
10597 types. Here we squish that down, so that each multidimensional array
10598 type gets only one array_type DIE in the Dwarf debugging info. The draft
10599 Dwarf specification say that we are allowed to do this kind of
10600 compression in C (because there is no difference between an array or
10601 arrays and a multidimensional array in C) but for other source languages
10602 (e.g. Ada) we probably shouldn't do this. */
10604 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10605 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10606 We work around this by disabling this feature. See also
10607 gen_array_type_die. */
10608 #ifndef MIPS_DEBUGGING_INFO
10609 for (dimension_number = 0;
10610 TREE_CODE (type) == ARRAY_TYPE;
10611 type = TREE_TYPE (type), dimension_number++)
10614 tree domain = TYPE_DOMAIN (type);
10616 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10617 and (in GNU C only) variable bounds. Handle all three forms
10619 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
10622 /* We have an array type with specified bounds. */
10623 lower = TYPE_MIN_VALUE (domain);
10624 upper = TYPE_MAX_VALUE (domain);
10626 /* Define the index type. */
10627 if (TREE_TYPE (domain))
10629 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10630 TREE_TYPE field. We can't emit debug info for this
10631 because it is an unnamed integral type. */
10632 if (TREE_CODE (domain) == INTEGER_TYPE
10633 && TYPE_NAME (domain) == NULL_TREE
10634 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
10635 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
10638 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
10642 /* ??? If upper is NULL, the array has unspecified length,
10643 but it does have a lower bound. This happens with Fortran
10645 Since the debugger is definitely going to need to know N
10646 to produce useful results, go ahead and output the lower
10647 bound solo, and hope the debugger can cope. */
10649 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
10651 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
10654 /* Otherwise we have an array type with an unspecified length. The
10655 DWARF-2 spec does not say how to handle this; let's just leave out the
10661 add_byte_size_attribute (dw_die_ref die, tree tree_node)
10665 switch (TREE_CODE (tree_node))
10670 case ENUMERAL_TYPE:
10673 case QUAL_UNION_TYPE:
10674 size = int_size_in_bytes (tree_node);
10677 /* For a data member of a struct or union, the DW_AT_byte_size is
10678 generally given as the number of bytes normally allocated for an
10679 object of the *declared* type of the member itself. This is true
10680 even for bit-fields. */
10681 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
10684 gcc_unreachable ();
10687 /* Note that `size' might be -1 when we get to this point. If it is, that
10688 indicates that the byte size of the entity in question is variable. We
10689 have no good way of expressing this fact in Dwarf at the present time,
10690 so just let the -1 pass on through. */
10691 add_AT_unsigned (die, DW_AT_byte_size, size);
10694 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10695 which specifies the distance in bits from the highest order bit of the
10696 "containing object" for the bit-field to the highest order bit of the
10699 For any given bit-field, the "containing object" is a hypothetical object
10700 (of some integral or enum type) within which the given bit-field lives. The
10701 type of this hypothetical "containing object" is always the same as the
10702 declared type of the individual bit-field itself. The determination of the
10703 exact location of the "containing object" for a bit-field is rather
10704 complicated. It's handled by the `field_byte_offset' function (above).
10706 Note that it is the size (in bytes) of the hypothetical "containing object"
10707 which will be given in the DW_AT_byte_size attribute for this bit-field.
10708 (See `byte_size_attribute' above). */
10711 add_bit_offset_attribute (dw_die_ref die, tree decl)
10713 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
10714 tree type = DECL_BIT_FIELD_TYPE (decl);
10715 HOST_WIDE_INT bitpos_int;
10716 HOST_WIDE_INT highest_order_object_bit_offset;
10717 HOST_WIDE_INT highest_order_field_bit_offset;
10718 HOST_WIDE_INT unsigned bit_offset;
10720 /* Must be a field and a bit field. */
10721 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
10723 /* We can't yet handle bit-fields whose offsets are variable, so if we
10724 encounter such things, just return without generating any attribute
10725 whatsoever. Likewise for variable or too large size. */
10726 if (! host_integerp (bit_position (decl), 0)
10727 || ! host_integerp (DECL_SIZE (decl), 1))
10730 bitpos_int = int_bit_position (decl);
10732 /* Note that the bit offset is always the distance (in bits) from the
10733 highest-order bit of the "containing object" to the highest-order bit of
10734 the bit-field itself. Since the "high-order end" of any object or field
10735 is different on big-endian and little-endian machines, the computation
10736 below must take account of these differences. */
10737 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
10738 highest_order_field_bit_offset = bitpos_int;
10740 if (! BYTES_BIG_ENDIAN)
10742 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
10743 highest_order_object_bit_offset += simple_type_size_in_bits (type);
10747 = (! BYTES_BIG_ENDIAN
10748 ? highest_order_object_bit_offset - highest_order_field_bit_offset
10749 : highest_order_field_bit_offset - highest_order_object_bit_offset);
10751 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
10754 /* For a FIELD_DECL node which represents a bit field, output an attribute
10755 which specifies the length in bits of the given field. */
10758 add_bit_size_attribute (dw_die_ref die, tree decl)
10760 /* Must be a field and a bit field. */
10761 gcc_assert (TREE_CODE (decl) == FIELD_DECL
10762 && DECL_BIT_FIELD_TYPE (decl));
10764 if (host_integerp (DECL_SIZE (decl), 1))
10765 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
10768 /* If the compiled language is ANSI C, then add a 'prototyped'
10769 attribute, if arg types are given for the parameters of a function. */
10772 add_prototyped_attribute (dw_die_ref die, tree func_type)
10774 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
10775 && TYPE_ARG_TYPES (func_type) != NULL)
10776 add_AT_flag (die, DW_AT_prototyped, 1);
10779 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10780 by looking in either the type declaration or object declaration
10784 add_abstract_origin_attribute (dw_die_ref die, tree origin)
10786 dw_die_ref origin_die = NULL;
10788 if (TREE_CODE (origin) != FUNCTION_DECL)
10790 /* We may have gotten separated from the block for the inlined
10791 function, if we're in an exception handler or some such; make
10792 sure that the abstract function has been written out.
10794 Doing this for nested functions is wrong, however; functions are
10795 distinct units, and our context might not even be inline. */
10799 fn = TYPE_STUB_DECL (fn);
10801 fn = decl_function_context (fn);
10803 dwarf2out_abstract_function (fn);
10806 if (DECL_P (origin))
10807 origin_die = lookup_decl_die (origin);
10808 else if (TYPE_P (origin))
10809 origin_die = lookup_type_die (origin);
10811 /* XXX: Functions that are never lowered don't always have correct block
10812 trees (in the case of java, they simply have no block tree, in some other
10813 languages). For these functions, there is nothing we can really do to
10814 output correct debug info for inlined functions in all cases. Rather
10815 than die, we'll just produce deficient debug info now, in that we will
10816 have variables without a proper abstract origin. In the future, when all
10817 functions are lowered, we should re-add a gcc_assert (origin_die)
10821 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
10824 /* We do not currently support the pure_virtual attribute. */
10827 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
10829 if (DECL_VINDEX (func_decl))
10831 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10833 if (host_integerp (DECL_VINDEX (func_decl), 0))
10834 add_AT_loc (die, DW_AT_vtable_elem_location,
10835 new_loc_descr (DW_OP_constu,
10836 tree_low_cst (DECL_VINDEX (func_decl), 0),
10839 /* GNU extension: Record what type this method came from originally. */
10840 if (debug_info_level > DINFO_LEVEL_TERSE)
10841 add_AT_die_ref (die, DW_AT_containing_type,
10842 lookup_type_die (DECL_CONTEXT (func_decl)));
10846 /* Add source coordinate attributes for the given decl. */
10849 add_src_coords_attributes (dw_die_ref die, tree decl)
10851 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
10852 unsigned file_index = lookup_filename (s.file);
10854 add_AT_unsigned (die, DW_AT_decl_file, file_index);
10855 add_AT_unsigned (die, DW_AT_decl_line, s.line);
10858 /* Add a DW_AT_name attribute and source coordinate attribute for the
10859 given decl, but only if it actually has a name. */
10862 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
10866 decl_name = DECL_NAME (decl);
10867 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
10869 add_name_attribute (die, dwarf2_name (decl, 0));
10870 if (! DECL_ARTIFICIAL (decl))
10871 add_src_coords_attributes (die, decl);
10873 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
10874 && TREE_PUBLIC (decl)
10875 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
10876 && !DECL_ABSTRACT (decl)
10877 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)))
10878 add_AT_string (die, DW_AT_MIPS_linkage_name,
10879 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
10882 #ifdef VMS_DEBUGGING_INFO
10883 /* Get the function's name, as described by its RTL. This may be different
10884 from the DECL_NAME name used in the source file. */
10885 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
10887 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
10888 XEXP (DECL_RTL (decl), 0));
10889 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
10894 /* Push a new declaration scope. */
10897 push_decl_scope (tree scope)
10899 VEC_safe_push (tree, gc, decl_scope_table, scope);
10902 /* Pop a declaration scope. */
10905 pop_decl_scope (void)
10907 VEC_pop (tree, decl_scope_table);
10910 /* Return the DIE for the scope that immediately contains this type.
10911 Non-named types get global scope. Named types nested in other
10912 types get their containing scope if it's open, or global scope
10913 otherwise. All other types (i.e. function-local named types) get
10914 the current active scope. */
10917 scope_die_for (tree t, dw_die_ref context_die)
10919 dw_die_ref scope_die = NULL;
10920 tree containing_scope;
10923 /* Non-types always go in the current scope. */
10924 gcc_assert (TYPE_P (t));
10926 containing_scope = TYPE_CONTEXT (t);
10928 /* Use the containing namespace if it was passed in (for a declaration). */
10929 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
10931 if (context_die == lookup_decl_die (containing_scope))
10934 containing_scope = NULL_TREE;
10937 /* Ignore function type "scopes" from the C frontend. They mean that
10938 a tagged type is local to a parmlist of a function declarator, but
10939 that isn't useful to DWARF. */
10940 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
10941 containing_scope = NULL_TREE;
10943 if (containing_scope == NULL_TREE)
10944 scope_die = comp_unit_die;
10945 else if (TYPE_P (containing_scope))
10947 /* For types, we can just look up the appropriate DIE. But
10948 first we check to see if we're in the middle of emitting it
10949 so we know where the new DIE should go. */
10950 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
10951 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
10956 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
10957 || TREE_ASM_WRITTEN (containing_scope));
10959 /* If none of the current dies are suitable, we get file scope. */
10960 scope_die = comp_unit_die;
10963 scope_die = lookup_type_die (containing_scope);
10966 scope_die = context_die;
10971 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10974 local_scope_p (dw_die_ref context_die)
10976 for (; context_die; context_die = context_die->die_parent)
10977 if (context_die->die_tag == DW_TAG_inlined_subroutine
10978 || context_die->die_tag == DW_TAG_subprogram)
10984 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10985 whether or not to treat a DIE in this context as a declaration. */
10988 class_or_namespace_scope_p (dw_die_ref context_die)
10990 return (context_die
10991 && (context_die->die_tag == DW_TAG_structure_type
10992 || context_die->die_tag == DW_TAG_union_type
10993 || context_die->die_tag == DW_TAG_namespace));
10996 /* Many forms of DIEs require a "type description" attribute. This
10997 routine locates the proper "type descriptor" die for the type given
10998 by 'type', and adds a DW_AT_type attribute below the given die. */
11001 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11002 int decl_volatile, dw_die_ref context_die)
11004 enum tree_code code = TREE_CODE (type);
11005 dw_die_ref type_die = NULL;
11007 /* ??? If this type is an unnamed subrange type of an integral or
11008 floating-point type, use the inner type. This is because we have no
11009 support for unnamed types in base_type_die. This can happen if this is
11010 an Ada subrange type. Correct solution is emit a subrange type die. */
11011 if ((code == INTEGER_TYPE || code == REAL_TYPE)
11012 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11013 type = TREE_TYPE (type), code = TREE_CODE (type);
11015 if (code == ERROR_MARK
11016 /* Handle a special case. For functions whose return type is void, we
11017 generate *no* type attribute. (Note that no object may have type
11018 `void', so this only applies to function return types). */
11019 || code == VOID_TYPE)
11022 type_die = modified_type_die (type,
11023 decl_const || TYPE_READONLY (type),
11024 decl_volatile || TYPE_VOLATILE (type),
11027 if (type_die != NULL)
11028 add_AT_die_ref (object_die, DW_AT_type, type_die);
11031 /* Given an object die, add the calling convention attribute for the
11032 function call type. */
11034 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
11036 enum dwarf_calling_convention value = DW_CC_normal;
11038 value = targetm.dwarf_calling_convention (type);
11040 /* Only add the attribute if the backend requests it, and
11041 is not DW_CC_normal. */
11042 if (value && (value != DW_CC_normal))
11043 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11046 /* Given a tree pointer to a struct, class, union, or enum type node, return
11047 a pointer to the (string) tag name for the given type, or zero if the type
11048 was declared without a tag. */
11050 static const char *
11051 type_tag (tree type)
11053 const char *name = 0;
11055 if (TYPE_NAME (type) != 0)
11059 /* Find the IDENTIFIER_NODE for the type name. */
11060 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11061 t = TYPE_NAME (type);
11063 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11064 a TYPE_DECL node, regardless of whether or not a `typedef' was
11066 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11067 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11068 t = DECL_NAME (TYPE_NAME (type));
11070 /* Now get the name as a string, or invent one. */
11072 name = IDENTIFIER_POINTER (t);
11075 return (name == 0 || *name == '\0') ? 0 : name;
11078 /* Return the type associated with a data member, make a special check
11079 for bit field types. */
11082 member_declared_type (tree member)
11084 return (DECL_BIT_FIELD_TYPE (member)
11085 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11088 /* Get the decl's label, as described by its RTL. This may be different
11089 from the DECL_NAME name used in the source file. */
11092 static const char *
11093 decl_start_label (tree decl)
11096 const char *fnname;
11098 x = DECL_RTL (decl);
11099 gcc_assert (MEM_P (x));
11102 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11104 fnname = XSTR (x, 0);
11109 /* These routines generate the internal representation of the DIE's for
11110 the compilation unit. Debugging information is collected by walking
11111 the declaration trees passed in from dwarf2out_decl(). */
11114 gen_array_type_die (tree type, dw_die_ref context_die)
11116 dw_die_ref scope_die = scope_die_for (type, context_die);
11117 dw_die_ref array_die;
11120 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11121 the inner array type comes before the outer array type. Thus we must
11122 call gen_type_die before we call new_die. See below also. */
11123 #ifdef MIPS_DEBUGGING_INFO
11124 gen_type_die (TREE_TYPE (type), context_die);
11127 array_die = new_die (DW_TAG_array_type, scope_die, type);
11128 add_name_attribute (array_die, type_tag (type));
11129 equate_type_number_to_die (type, array_die);
11131 if (TREE_CODE (type) == VECTOR_TYPE)
11133 /* The frontend feeds us a representation for the vector as a struct
11134 containing an array. Pull out the array type. */
11135 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11136 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11140 /* We default the array ordering. SDB will probably do
11141 the right things even if DW_AT_ordering is not present. It's not even
11142 an issue until we start to get into multidimensional arrays anyway. If
11143 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11144 then we'll have to put the DW_AT_ordering attribute back in. (But if
11145 and when we find out that we need to put these in, we will only do so
11146 for multidimensional arrays. */
11147 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11150 #ifdef MIPS_DEBUGGING_INFO
11151 /* The SGI compilers handle arrays of unknown bound by setting
11152 AT_declaration and not emitting any subrange DIEs. */
11153 if (! TYPE_DOMAIN (type))
11154 add_AT_flag (array_die, DW_AT_declaration, 1);
11157 add_subscript_info (array_die, type);
11159 /* Add representation of the type of the elements of this array type. */
11160 element_type = TREE_TYPE (type);
11162 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11163 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11164 We work around this by disabling this feature. See also
11165 add_subscript_info. */
11166 #ifndef MIPS_DEBUGGING_INFO
11167 while (TREE_CODE (element_type) == ARRAY_TYPE)
11168 element_type = TREE_TYPE (element_type);
11170 gen_type_die (element_type, context_die);
11173 add_type_attribute (array_die, element_type, 0, 0, context_die);
11178 gen_entry_point_die (tree decl, dw_die_ref context_die)
11180 tree origin = decl_ultimate_origin (decl);
11181 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11183 if (origin != NULL)
11184 add_abstract_origin_attribute (decl_die, origin);
11187 add_name_and_src_coords_attributes (decl_die, decl);
11188 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11189 0, 0, context_die);
11192 if (DECL_ABSTRACT (decl))
11193 equate_decl_number_to_die (decl, decl_die);
11195 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
11199 /* Walk through the list of incomplete types again, trying once more to
11200 emit full debugging info for them. */
11203 retry_incomplete_types (void)
11207 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11208 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11211 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11214 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11216 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11218 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11219 be incomplete and such types are not marked. */
11220 add_abstract_origin_attribute (type_die, type);
11223 /* Generate a DIE to represent an inlined instance of a structure type. */
11226 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11228 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
11230 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11231 be incomplete and such types are not marked. */
11232 add_abstract_origin_attribute (type_die, type);
11235 /* Generate a DIE to represent an inlined instance of a union type. */
11238 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11240 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11242 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11243 be incomplete and such types are not marked. */
11244 add_abstract_origin_attribute (type_die, type);
11247 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11248 include all of the information about the enumeration values also. Each
11249 enumerated type name/value is listed as a child of the enumerated type
11253 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11255 dw_die_ref type_die = lookup_type_die (type);
11257 if (type_die == NULL)
11259 type_die = new_die (DW_TAG_enumeration_type,
11260 scope_die_for (type, context_die), type);
11261 equate_type_number_to_die (type, type_die);
11262 add_name_attribute (type_die, type_tag (type));
11264 else if (! TYPE_SIZE (type))
11267 remove_AT (type_die, DW_AT_declaration);
11269 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11270 given enum type is incomplete, do not generate the DW_AT_byte_size
11271 attribute or the DW_AT_element_list attribute. */
11272 if (TYPE_SIZE (type))
11276 TREE_ASM_WRITTEN (type) = 1;
11277 add_byte_size_attribute (type_die, type);
11278 if (TYPE_STUB_DECL (type) != NULL_TREE)
11279 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11281 /* If the first reference to this type was as the return type of an
11282 inline function, then it may not have a parent. Fix this now. */
11283 if (type_die->die_parent == NULL)
11284 add_child_die (scope_die_for (type, context_die), type_die);
11286 for (link = TYPE_VALUES (type);
11287 link != NULL; link = TREE_CHAIN (link))
11289 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
11290 tree value = TREE_VALUE (link);
11292 add_name_attribute (enum_die,
11293 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
11295 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
11296 /* DWARF2 does not provide a way of indicating whether or
11297 not enumeration constants are signed or unsigned. GDB
11298 always assumes the values are signed, so we output all
11299 values as if they were signed. That means that
11300 enumeration constants with very large unsigned values
11301 will appear to have negative values in the debugger. */
11302 add_AT_int (enum_die, DW_AT_const_value,
11303 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
11307 add_AT_flag (type_die, DW_AT_declaration, 1);
11312 /* Generate a DIE to represent either a real live formal parameter decl or to
11313 represent just the type of some formal parameter position in some function
11316 Note that this routine is a bit unusual because its argument may be a
11317 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11318 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11319 node. If it's the former then this function is being called to output a
11320 DIE to represent a formal parameter object (or some inlining thereof). If
11321 it's the latter, then this function is only being called to output a
11322 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11323 argument type of some subprogram type. */
11326 gen_formal_parameter_die (tree node, dw_die_ref context_die)
11328 dw_die_ref parm_die
11329 = new_die (DW_TAG_formal_parameter, context_die, node);
11332 switch (TREE_CODE_CLASS (TREE_CODE (node)))
11334 case tcc_declaration:
11335 origin = decl_ultimate_origin (node);
11336 if (origin != NULL)
11337 add_abstract_origin_attribute (parm_die, origin);
11340 add_name_and_src_coords_attributes (parm_die, node);
11341 add_type_attribute (parm_die, TREE_TYPE (node),
11342 TREE_READONLY (node),
11343 TREE_THIS_VOLATILE (node),
11345 if (DECL_ARTIFICIAL (node))
11346 add_AT_flag (parm_die, DW_AT_artificial, 1);
11349 equate_decl_number_to_die (node, parm_die);
11350 if (! DECL_ABSTRACT (node))
11351 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
11356 /* We were called with some kind of a ..._TYPE node. */
11357 add_type_attribute (parm_die, node, 0, 0, context_die);
11361 gcc_unreachable ();
11367 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11368 at the end of an (ANSI prototyped) formal parameters list. */
11371 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11373 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11376 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11377 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11378 parameters as specified in some function type specification (except for
11379 those which appear as part of a function *definition*). */
11382 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11385 tree formal_type = NULL;
11386 tree first_parm_type;
11389 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11391 arg = DECL_ARGUMENTS (function_or_method_type);
11392 function_or_method_type = TREE_TYPE (function_or_method_type);
11397 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11399 /* Make our first pass over the list of formal parameter types and output a
11400 DW_TAG_formal_parameter DIE for each one. */
11401 for (link = first_parm_type; link; )
11403 dw_die_ref parm_die;
11405 formal_type = TREE_VALUE (link);
11406 if (formal_type == void_type_node)
11409 /* Output a (nameless) DIE to represent the formal parameter itself. */
11410 parm_die = gen_formal_parameter_die (formal_type, context_die);
11411 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11412 && link == first_parm_type)
11413 || (arg && DECL_ARTIFICIAL (arg)))
11414 add_AT_flag (parm_die, DW_AT_artificial, 1);
11416 link = TREE_CHAIN (link);
11418 arg = TREE_CHAIN (arg);
11421 /* If this function type has an ellipsis, add a
11422 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11423 if (formal_type != void_type_node)
11424 gen_unspecified_parameters_die (function_or_method_type, context_die);
11426 /* Make our second (and final) pass over the list of formal parameter types
11427 and output DIEs to represent those types (as necessary). */
11428 for (link = TYPE_ARG_TYPES (function_or_method_type);
11429 link && TREE_VALUE (link);
11430 link = TREE_CHAIN (link))
11431 gen_type_die (TREE_VALUE (link), context_die);
11434 /* We want to generate the DIE for TYPE so that we can generate the
11435 die for MEMBER, which has been defined; we will need to refer back
11436 to the member declaration nested within TYPE. If we're trying to
11437 generate minimal debug info for TYPE, processing TYPE won't do the
11438 trick; we need to attach the member declaration by hand. */
11441 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11443 gen_type_die (type, context_die);
11445 /* If we're trying to avoid duplicate debug info, we may not have
11446 emitted the member decl for this function. Emit it now. */
11447 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11448 && ! lookup_decl_die (member))
11450 dw_die_ref type_die;
11451 gcc_assert (!decl_ultimate_origin (member));
11453 push_decl_scope (type);
11454 type_die = lookup_type_die (type);
11455 if (TREE_CODE (member) == FUNCTION_DECL)
11456 gen_subprogram_die (member, type_die);
11457 else if (TREE_CODE (member) == FIELD_DECL)
11459 /* Ignore the nameless fields that are used to skip bits but handle
11460 C++ anonymous unions and structs. */
11461 if (DECL_NAME (member) != NULL_TREE
11462 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
11463 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
11465 gen_type_die (member_declared_type (member), type_die);
11466 gen_field_die (member, type_die);
11470 gen_variable_die (member, type_die);
11476 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11477 may later generate inlined and/or out-of-line instances of. */
11480 dwarf2out_abstract_function (tree decl)
11482 dw_die_ref old_die;
11485 int was_abstract = DECL_ABSTRACT (decl);
11487 /* Make sure we have the actual abstract inline, not a clone. */
11488 decl = DECL_ORIGIN (decl);
11490 old_die = lookup_decl_die (decl);
11491 if (old_die && get_AT (old_die, DW_AT_inline))
11492 /* We've already generated the abstract instance. */
11495 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11496 we don't get confused by DECL_ABSTRACT. */
11497 if (debug_info_level > DINFO_LEVEL_TERSE)
11499 context = decl_class_context (decl);
11501 gen_type_die_for_member
11502 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11505 /* Pretend we've just finished compiling this function. */
11506 save_fn = current_function_decl;
11507 current_function_decl = decl;
11509 set_decl_abstract_flags (decl, 1);
11510 dwarf2out_decl (decl);
11511 if (! was_abstract)
11512 set_decl_abstract_flags (decl, 0);
11514 current_function_decl = save_fn;
11517 /* Helper function of premark_used_types() which gets called through
11518 htab_traverse_resize().
11520 Marks the DIE of a given type in *SLOT as perennial, so it never gets
11521 marked as unused by prune_unused_types. */
11523 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
11529 die = lookup_type_die (type);
11531 die->die_perennial_p = 1;
11535 /* Mark all members of used_types_hash as perennial. */
11537 premark_used_types (void)
11539 if (cfun && cfun->used_types_hash)
11540 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
11543 /* Generate a DIE to represent a declared function (either file-scope or
11547 gen_subprogram_die (tree decl, dw_die_ref context_die)
11549 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11550 tree origin = decl_ultimate_origin (decl);
11551 dw_die_ref subr_die;
11554 dw_die_ref old_die = lookup_decl_die (decl);
11555 int declaration = (current_function_decl != decl
11556 || class_or_namespace_scope_p (context_die));
11558 premark_used_types();
11560 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11561 started to generate the abstract instance of an inline, decided to output
11562 its containing class, and proceeded to emit the declaration of the inline
11563 from the member list for the class. If so, DECLARATION takes priority;
11564 we'll get back to the abstract instance when done with the class. */
11566 /* The class-scope declaration DIE must be the primary DIE. */
11567 if (origin && declaration && class_or_namespace_scope_p (context_die))
11570 gcc_assert (!old_die);
11573 /* Now that the C++ front end lazily declares artificial member fns, we
11574 might need to retrofit the declaration into its class. */
11575 if (!declaration && !origin && !old_die
11576 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
11577 && !class_or_namespace_scope_p (context_die)
11578 && debug_info_level > DINFO_LEVEL_TERSE)
11579 old_die = force_decl_die (decl);
11581 if (origin != NULL)
11583 gcc_assert (!declaration || local_scope_p (context_die));
11585 /* Fixup die_parent for the abstract instance of a nested
11586 inline function. */
11587 if (old_die && old_die->die_parent == NULL)
11588 add_child_die (context_die, old_die);
11590 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11591 add_abstract_origin_attribute (subr_die, origin);
11595 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11596 unsigned file_index = lookup_filename (s.file);
11598 if (!get_AT_flag (old_die, DW_AT_declaration)
11599 /* We can have a normal definition following an inline one in the
11600 case of redefinition of GNU C extern inlines.
11601 It seems reasonable to use AT_specification in this case. */
11602 && !get_AT (old_die, DW_AT_inline))
11604 /* Detect and ignore this case, where we are trying to output
11605 something we have already output. */
11609 /* If the definition comes from the same place as the declaration,
11610 maybe use the old DIE. We always want the DIE for this function
11611 that has the *_pc attributes to be under comp_unit_die so the
11612 debugger can find it. We also need to do this for abstract
11613 instances of inlines, since the spec requires the out-of-line copy
11614 to have the same parent. For local class methods, this doesn't
11615 apply; we just use the old DIE. */
11616 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
11617 && (DECL_ARTIFICIAL (decl)
11618 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
11619 && (get_AT_unsigned (old_die, DW_AT_decl_line)
11620 == (unsigned) s.line))))
11622 subr_die = old_die;
11624 /* Clear out the declaration attribute and the formal parameters.
11625 Do not remove all children, because it is possible that this
11626 declaration die was forced using force_decl_die(). In such
11627 cases die that forced declaration die (e.g. TAG_imported_module)
11628 is one of the children that we do not want to remove. */
11629 remove_AT (subr_die, DW_AT_declaration);
11630 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
11634 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11635 add_AT_specification (subr_die, old_die);
11636 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11637 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
11638 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11639 != (unsigned) s.line)
11641 (subr_die, DW_AT_decl_line, s.line);
11646 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11648 if (TREE_PUBLIC (decl))
11649 add_AT_flag (subr_die, DW_AT_external, 1);
11651 add_name_and_src_coords_attributes (subr_die, decl);
11652 if (debug_info_level > DINFO_LEVEL_TERSE)
11654 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
11655 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
11656 0, 0, context_die);
11659 add_pure_or_virtual_attribute (subr_die, decl);
11660 if (DECL_ARTIFICIAL (decl))
11661 add_AT_flag (subr_die, DW_AT_artificial, 1);
11663 if (TREE_PROTECTED (decl))
11664 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
11665 else if (TREE_PRIVATE (decl))
11666 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
11671 if (!old_die || !get_AT (old_die, DW_AT_inline))
11673 add_AT_flag (subr_die, DW_AT_declaration, 1);
11675 /* The first time we see a member function, it is in the context of
11676 the class to which it belongs. We make sure of this by emitting
11677 the class first. The next time is the definition, which is
11678 handled above. The two may come from the same source text.
11680 Note that force_decl_die() forces function declaration die. It is
11681 later reused to represent definition. */
11682 equate_decl_number_to_die (decl, subr_die);
11685 else if (DECL_ABSTRACT (decl))
11687 if (DECL_DECLARED_INLINE_P (decl))
11689 if (cgraph_function_possibly_inlined_p (decl))
11690 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
11692 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
11696 if (cgraph_function_possibly_inlined_p (decl))
11697 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
11699 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
11702 equate_decl_number_to_die (decl, subr_die);
11704 else if (!DECL_EXTERNAL (decl))
11706 HOST_WIDE_INT cfa_fb_offset;
11708 if (!old_die || !get_AT (old_die, DW_AT_inline))
11709 equate_decl_number_to_die (decl, subr_die);
11711 if (!flag_reorder_blocks_and_partition)
11713 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
11714 current_function_funcdef_no);
11715 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
11716 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11717 current_function_funcdef_no);
11718 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
11720 add_pubname (decl, subr_die);
11721 add_arange (decl, subr_die);
11724 { /* Do nothing for now; maybe need to duplicate die, one for
11725 hot section and ond for cold section, then use the hot/cold
11726 section begin/end labels to generate the aranges... */
11728 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11729 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11730 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11731 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11733 add_pubname (decl, subr_die);
11734 add_arange (decl, subr_die);
11735 add_arange (decl, subr_die);
11739 #ifdef MIPS_DEBUGGING_INFO
11740 /* Add a reference to the FDE for this routine. */
11741 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
11744 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
11746 /* We define the "frame base" as the function's CFA. This is more
11747 convenient for several reasons: (1) It's stable across the prologue
11748 and epilogue, which makes it better than just a frame pointer,
11749 (2) With dwarf3, there exists a one-byte encoding that allows us
11750 to reference the .debug_frame data by proxy, but failing that,
11751 (3) We can at least reuse the code inspection and interpretation
11752 code that determines the CFA position at various points in the
11754 /* ??? Use some command-line or configury switch to enable the use
11755 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
11756 consumers that understand it; fall back to "pure" dwarf2 and
11757 convert the CFA data into a location list. */
11759 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
11760 if (list->dw_loc_next)
11761 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
11763 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
11766 /* Compute a displacement from the "steady-state frame pointer" to
11767 the CFA. The former is what all stack slots and argument slots
11768 will reference in the rtl; the later is what we've told the
11769 debugger about. We'll need to adjust all frame_base references
11770 by this displacement. */
11771 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
11773 if (cfun->static_chain_decl)
11774 add_AT_location_description (subr_die, DW_AT_static_link,
11775 loc_descriptor_from_tree (cfun->static_chain_decl));
11778 /* Now output descriptions of the arguments for this function. This gets
11779 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11780 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11781 `...' at the end of the formal parameter list. In order to find out if
11782 there was a trailing ellipsis or not, we must instead look at the type
11783 associated with the FUNCTION_DECL. This will be a node of type
11784 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11785 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11786 an ellipsis at the end. */
11788 /* In the case where we are describing a mere function declaration, all we
11789 need to do here (and all we *can* do here) is to describe the *types* of
11790 its formal parameters. */
11791 if (debug_info_level <= DINFO_LEVEL_TERSE)
11793 else if (declaration)
11794 gen_formal_types_die (decl, subr_die);
11797 /* Generate DIEs to represent all known formal parameters. */
11798 tree arg_decls = DECL_ARGUMENTS (decl);
11801 /* When generating DIEs, generate the unspecified_parameters DIE
11802 instead if we come across the arg "__builtin_va_alist" */
11803 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
11804 if (TREE_CODE (parm) == PARM_DECL)
11806 if (DECL_NAME (parm)
11807 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
11808 "__builtin_va_alist"))
11809 gen_unspecified_parameters_die (parm, subr_die);
11811 gen_decl_die (parm, subr_die);
11814 /* Decide whether we need an unspecified_parameters DIE at the end.
11815 There are 2 more cases to do this for: 1) the ansi ... declaration -
11816 this is detectable when the end of the arg list is not a
11817 void_type_node 2) an unprototyped function declaration (not a
11818 definition). This just means that we have no info about the
11819 parameters at all. */
11820 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
11821 if (fn_arg_types != NULL)
11823 /* This is the prototyped case, check for.... */
11824 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
11825 gen_unspecified_parameters_die (decl, subr_die);
11827 else if (DECL_INITIAL (decl) == NULL_TREE)
11828 gen_unspecified_parameters_die (decl, subr_die);
11831 /* Output Dwarf info for all of the stuff within the body of the function
11832 (if it has one - it may be just a declaration). */
11833 outer_scope = DECL_INITIAL (decl);
11835 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11836 a function. This BLOCK actually represents the outermost binding contour
11837 for the function, i.e. the contour in which the function's formal
11838 parameters and labels get declared. Curiously, it appears that the front
11839 end doesn't actually put the PARM_DECL nodes for the current function onto
11840 the BLOCK_VARS list for this outer scope, but are strung off of the
11841 DECL_ARGUMENTS list for the function instead.
11843 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11844 the LABEL_DECL nodes for the function however, and we output DWARF info
11845 for those in decls_for_scope. Just within the `outer_scope' there will be
11846 a BLOCK node representing the function's outermost pair of curly braces,
11847 and any blocks used for the base and member initializers of a C++
11848 constructor function. */
11849 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
11851 /* Emit a DW_TAG_variable DIE for a named return value. */
11852 if (DECL_NAME (DECL_RESULT (decl)))
11853 gen_decl_die (DECL_RESULT (decl), subr_die);
11855 current_function_has_inlines = 0;
11856 decls_for_scope (outer_scope, subr_die, 0);
11858 #if 0 && defined (MIPS_DEBUGGING_INFO)
11859 if (current_function_has_inlines)
11861 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
11862 if (! comp_unit_has_inlines)
11864 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
11865 comp_unit_has_inlines = 1;
11870 /* Add the calling convention attribute if requested. */
11871 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
11875 /* Generate a DIE to represent a declared data object. */
11878 gen_variable_die (tree decl, dw_die_ref context_die)
11880 tree origin = decl_ultimate_origin (decl);
11881 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
11883 dw_die_ref old_die = lookup_decl_die (decl);
11884 int declaration = (DECL_EXTERNAL (decl)
11885 /* If DECL is COMDAT and has not actually been
11886 emitted, we cannot take its address; there
11887 might end up being no definition anywhere in
11888 the program. For example, consider the C++
11892 struct S { static const int i = 7; };
11897 int f() { return S<int>::i; }
11899 Here, S<int>::i is not DECL_EXTERNAL, but no
11900 definition is required, so the compiler will
11901 not emit a definition. */
11902 || (TREE_CODE (decl) == VAR_DECL
11903 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
11904 || class_or_namespace_scope_p (context_die));
11906 if (origin != NULL)
11907 add_abstract_origin_attribute (var_die, origin);
11909 /* Loop unrolling can create multiple blocks that refer to the same
11910 static variable, so we must test for the DW_AT_declaration flag.
11912 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11913 copy decls and set the DECL_ABSTRACT flag on them instead of
11916 ??? Duplicated blocks have been rewritten to use .debug_ranges.
11918 ??? The declare_in_namespace support causes us to get two DIEs for one
11919 variable, both of which are declarations. We want to avoid considering
11920 one to be a specification, so we must test that this DIE is not a
11922 else if (old_die && TREE_STATIC (decl) && ! declaration
11923 && get_AT_flag (old_die, DW_AT_declaration) == 1)
11925 /* This is a definition of a C++ class level static. */
11926 add_AT_specification (var_die, old_die);
11927 if (DECL_NAME (decl))
11929 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11930 unsigned file_index = lookup_filename (s.file);
11932 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11933 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
11935 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11936 != (unsigned) s.line)
11938 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
11943 add_name_and_src_coords_attributes (var_die, decl);
11944 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
11945 TREE_THIS_VOLATILE (decl), context_die);
11947 if (TREE_PUBLIC (decl))
11948 add_AT_flag (var_die, DW_AT_external, 1);
11950 if (DECL_ARTIFICIAL (decl))
11951 add_AT_flag (var_die, DW_AT_artificial, 1);
11953 if (TREE_PROTECTED (decl))
11954 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
11955 else if (TREE_PRIVATE (decl))
11956 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
11960 add_AT_flag (var_die, DW_AT_declaration, 1);
11962 if (DECL_ABSTRACT (decl) || declaration)
11963 equate_decl_number_to_die (decl, var_die);
11965 if (! declaration && ! DECL_ABSTRACT (decl))
11967 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
11968 add_pubname (decl, var_die);
11971 tree_add_const_value_attribute (var_die, decl);
11974 /* Generate a DIE to represent a label identifier. */
11977 gen_label_die (tree decl, dw_die_ref context_die)
11979 tree origin = decl_ultimate_origin (decl);
11980 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
11982 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11984 if (origin != NULL)
11985 add_abstract_origin_attribute (lbl_die, origin);
11987 add_name_and_src_coords_attributes (lbl_die, decl);
11989 if (DECL_ABSTRACT (decl))
11990 equate_decl_number_to_die (decl, lbl_die);
11993 insn = DECL_RTL_IF_SET (decl);
11995 /* Deleted labels are programmer specified labels which have been
11996 eliminated because of various optimizations. We still emit them
11997 here so that it is possible to put breakpoints on them. */
12001 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))))
12003 /* When optimization is enabled (via -O) some parts of the compiler
12004 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12005 represent source-level labels which were explicitly declared by
12006 the user. This really shouldn't be happening though, so catch
12007 it if it ever does happen. */
12008 gcc_assert (!INSN_DELETED_P (insn));
12010 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12011 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12016 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12017 attributes to the DIE for a block STMT, to describe where the inlined
12018 function was called from. This is similar to add_src_coords_attributes. */
12021 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12023 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12024 unsigned file_index = lookup_filename (s.file);
12026 add_AT_unsigned (die, DW_AT_call_file, file_index);
12027 add_AT_unsigned (die, DW_AT_call_line, s.line);
12030 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12031 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12034 add_high_low_attributes (tree stmt, dw_die_ref die)
12036 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12038 if (BLOCK_FRAGMENT_CHAIN (stmt))
12042 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12044 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12047 add_ranges (chain);
12048 chain = BLOCK_FRAGMENT_CHAIN (chain);
12055 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12056 BLOCK_NUMBER (stmt));
12057 add_AT_lbl_id (die, DW_AT_low_pc, label);
12058 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12059 BLOCK_NUMBER (stmt));
12060 add_AT_lbl_id (die, DW_AT_high_pc, label);
12064 /* Generate a DIE for a lexical block. */
12067 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12069 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12071 if (! BLOCK_ABSTRACT (stmt))
12072 add_high_low_attributes (stmt, stmt_die);
12074 decls_for_scope (stmt, stmt_die, depth);
12077 /* Generate a DIE for an inlined subprogram. */
12080 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12082 tree decl = block_ultimate_origin (stmt);
12084 /* Emit info for the abstract instance first, if we haven't yet. We
12085 must emit this even if the block is abstract, otherwise when we
12086 emit the block below (or elsewhere), we may end up trying to emit
12087 a die whose origin die hasn't been emitted, and crashing. */
12088 dwarf2out_abstract_function (decl);
12090 if (! BLOCK_ABSTRACT (stmt))
12092 dw_die_ref subr_die
12093 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
12095 add_abstract_origin_attribute (subr_die, decl);
12096 add_high_low_attributes (stmt, subr_die);
12097 add_call_src_coords_attributes (stmt, subr_die);
12099 decls_for_scope (stmt, subr_die, depth);
12100 current_function_has_inlines = 1;
12103 /* We may get here if we're the outer block of function A that was
12104 inlined into function B that was inlined into function C. When
12105 generating debugging info for C, dwarf2out_abstract_function(B)
12106 would mark all inlined blocks as abstract, including this one.
12107 So, we wouldn't (and shouldn't) expect labels to be generated
12108 for this one. Instead, just emit debugging info for
12109 declarations within the block. This is particularly important
12110 in the case of initializers of arguments passed from B to us:
12111 if they're statement expressions containing declarations, we
12112 wouldn't generate dies for their abstract variables, and then,
12113 when generating dies for the real variables, we'd die (pun
12115 gen_lexical_block_die (stmt, context_die, depth);
12118 /* Generate a DIE for a field in a record, or structure. */
12121 gen_field_die (tree decl, dw_die_ref context_die)
12123 dw_die_ref decl_die;
12125 if (TREE_TYPE (decl) == error_mark_node)
12128 decl_die = new_die (DW_TAG_member, context_die, decl);
12129 add_name_and_src_coords_attributes (decl_die, decl);
12130 add_type_attribute (decl_die, member_declared_type (decl),
12131 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
12134 if (DECL_BIT_FIELD_TYPE (decl))
12136 add_byte_size_attribute (decl_die, decl);
12137 add_bit_size_attribute (decl_die, decl);
12138 add_bit_offset_attribute (decl_die, decl);
12141 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
12142 add_data_member_location_attribute (decl_die, decl);
12144 if (DECL_ARTIFICIAL (decl))
12145 add_AT_flag (decl_die, DW_AT_artificial, 1);
12147 if (TREE_PROTECTED (decl))
12148 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
12149 else if (TREE_PRIVATE (decl))
12150 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
12152 /* Equate decl number to die, so that we can look up this decl later on. */
12153 equate_decl_number_to_die (decl, decl_die);
12157 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12158 Use modified_type_die instead.
12159 We keep this code here just in case these types of DIEs may be needed to
12160 represent certain things in other languages (e.g. Pascal) someday. */
12163 gen_pointer_type_die (tree type, dw_die_ref context_die)
12166 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
12168 equate_type_number_to_die (type, ptr_die);
12169 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12170 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12173 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12174 Use modified_type_die instead.
12175 We keep this code here just in case these types of DIEs may be needed to
12176 represent certain things in other languages (e.g. Pascal) someday. */
12179 gen_reference_type_die (tree type, dw_die_ref context_die)
12182 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
12184 equate_type_number_to_die (type, ref_die);
12185 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
12186 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
12190 /* Generate a DIE for a pointer to a member type. */
12193 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
12196 = new_die (DW_TAG_ptr_to_member_type,
12197 scope_die_for (type, context_die), type);
12199 equate_type_number_to_die (type, ptr_die);
12200 add_AT_die_ref (ptr_die, DW_AT_containing_type,
12201 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
12202 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
12205 /* Generate the DIE for the compilation unit. */
12208 gen_compile_unit_die (const char *filename)
12211 char producer[250];
12212 const char *language_string = lang_hooks.name;
12215 die = new_die (DW_TAG_compile_unit, NULL, NULL);
12219 add_name_attribute (die, filename);
12220 /* Don't add cwd for <built-in>. */
12221 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
12222 add_comp_dir_attribute (die);
12225 sprintf (producer, "%s %s", language_string, version_string);
12227 #ifdef MIPS_DEBUGGING_INFO
12228 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
12229 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
12230 not appear in the producer string, the debugger reaches the conclusion
12231 that the object file is stripped and has no debugging information.
12232 To get the MIPS/SGI debugger to believe that there is debugging
12233 information in the object file, we add a -g to the producer string. */
12234 if (debug_info_level > DINFO_LEVEL_TERSE)
12235 strcat (producer, " -g");
12238 add_AT_string (die, DW_AT_producer, producer);
12240 if (strcmp (language_string, "GNU C++") == 0)
12241 language = DW_LANG_C_plus_plus;
12242 else if (strcmp (language_string, "GNU Ada") == 0)
12243 language = DW_LANG_Ada95;
12244 else if (strcmp (language_string, "GNU F77") == 0)
12245 language = DW_LANG_Fortran77;
12246 else if (strcmp (language_string, "GNU F95") == 0)
12247 language = DW_LANG_Fortran95;
12248 else if (strcmp (language_string, "GNU Pascal") == 0)
12249 language = DW_LANG_Pascal83;
12250 else if (strcmp (language_string, "GNU Java") == 0)
12251 language = DW_LANG_Java;
12252 else if (strcmp (language_string, "GNU Objective-C") == 0)
12253 language = DW_LANG_ObjC;
12254 else if (strcmp (language_string, "GNU Objective-C++") == 0)
12255 language = DW_LANG_ObjC_plus_plus;
12257 language = DW_LANG_C89;
12259 add_AT_unsigned (die, DW_AT_language, language);
12263 /* Generate the DIE for a base class. */
12266 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
12268 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
12270 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
12271 add_data_member_location_attribute (die, binfo);
12273 if (BINFO_VIRTUAL_P (binfo))
12274 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12276 if (access == access_public_node)
12277 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
12278 else if (access == access_protected_node)
12279 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
12282 /* Generate a DIE for a class member. */
12285 gen_member_die (tree type, dw_die_ref context_die)
12288 tree binfo = TYPE_BINFO (type);
12291 /* If this is not an incomplete type, output descriptions of each of its
12292 members. Note that as we output the DIEs necessary to represent the
12293 members of this record or union type, we will also be trying to output
12294 DIEs to represent the *types* of those members. However the `type'
12295 function (above) will specifically avoid generating type DIEs for member
12296 types *within* the list of member DIEs for this (containing) type except
12297 for those types (of members) which are explicitly marked as also being
12298 members of this (containing) type themselves. The g++ front- end can
12299 force any given type to be treated as a member of some other (containing)
12300 type by setting the TYPE_CONTEXT of the given (member) type to point to
12301 the TREE node representing the appropriate (containing) type. */
12303 /* First output info about the base classes. */
12306 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
12310 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
12311 gen_inheritance_die (base,
12312 (accesses ? VEC_index (tree, accesses, i)
12313 : access_public_node), context_die);
12316 /* Now output info about the data members and type members. */
12317 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
12319 /* If we thought we were generating minimal debug info for TYPE
12320 and then changed our minds, some of the member declarations
12321 may have already been defined. Don't define them again, but
12322 do put them in the right order. */
12324 child = lookup_decl_die (member);
12326 splice_child_die (context_die, child);
12328 gen_decl_die (member, context_die);
12331 /* Now output info about the function members (if any). */
12332 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
12334 /* Don't include clones in the member list. */
12335 if (DECL_ABSTRACT_ORIGIN (member))
12338 child = lookup_decl_die (member);
12340 splice_child_die (context_die, child);
12342 gen_decl_die (member, context_die);
12346 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12347 is set, we pretend that the type was never defined, so we only get the
12348 member DIEs needed by later specification DIEs. */
12351 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
12353 dw_die_ref type_die = lookup_type_die (type);
12354 dw_die_ref scope_die = 0;
12356 int complete = (TYPE_SIZE (type)
12357 && (! TYPE_STUB_DECL (type)
12358 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
12359 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
12361 if (type_die && ! complete)
12364 if (TYPE_CONTEXT (type) != NULL_TREE
12365 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12366 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
12369 scope_die = scope_die_for (type, context_die);
12371 if (! type_die || (nested && scope_die == comp_unit_die))
12372 /* First occurrence of type or toplevel definition of nested class. */
12374 dw_die_ref old_die = type_die;
12376 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
12377 ? DW_TAG_structure_type : DW_TAG_union_type,
12379 equate_type_number_to_die (type, type_die);
12381 add_AT_specification (type_die, old_die);
12383 add_name_attribute (type_die, type_tag (type));
12386 remove_AT (type_die, DW_AT_declaration);
12388 /* If this type has been completed, then give it a byte_size attribute and
12389 then give a list of members. */
12390 if (complete && !ns_decl)
12392 /* Prevent infinite recursion in cases where the type of some member of
12393 this type is expressed in terms of this type itself. */
12394 TREE_ASM_WRITTEN (type) = 1;
12395 add_byte_size_attribute (type_die, type);
12396 if (TYPE_STUB_DECL (type) != NULL_TREE)
12397 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12399 /* If the first reference to this type was as the return type of an
12400 inline function, then it may not have a parent. Fix this now. */
12401 if (type_die->die_parent == NULL)
12402 add_child_die (scope_die, type_die);
12404 push_decl_scope (type);
12405 gen_member_die (type, type_die);
12408 /* GNU extension: Record what type our vtable lives in. */
12409 if (TYPE_VFIELD (type))
12411 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
12413 gen_type_die (vtype, context_die);
12414 add_AT_die_ref (type_die, DW_AT_containing_type,
12415 lookup_type_die (vtype));
12420 add_AT_flag (type_die, DW_AT_declaration, 1);
12422 /* We don't need to do this for function-local types. */
12423 if (TYPE_STUB_DECL (type)
12424 && ! decl_function_context (TYPE_STUB_DECL (type)))
12425 VEC_safe_push (tree, gc, incomplete_types, type);
12429 /* Generate a DIE for a subroutine _type_. */
12432 gen_subroutine_type_die (tree type, dw_die_ref context_die)
12434 tree return_type = TREE_TYPE (type);
12435 dw_die_ref subr_die
12436 = new_die (DW_TAG_subroutine_type,
12437 scope_die_for (type, context_die), type);
12439 equate_type_number_to_die (type, subr_die);
12440 add_prototyped_attribute (subr_die, type);
12441 add_type_attribute (subr_die, return_type, 0, 0, context_die);
12442 gen_formal_types_die (type, subr_die);
12445 /* Generate a DIE for a type definition. */
12448 gen_typedef_die (tree decl, dw_die_ref context_die)
12450 dw_die_ref type_die;
12453 if (TREE_ASM_WRITTEN (decl))
12456 TREE_ASM_WRITTEN (decl) = 1;
12457 type_die = new_die (DW_TAG_typedef, context_die, decl);
12458 origin = decl_ultimate_origin (decl);
12459 if (origin != NULL)
12460 add_abstract_origin_attribute (type_die, origin);
12465 add_name_and_src_coords_attributes (type_die, decl);
12466 if (DECL_ORIGINAL_TYPE (decl))
12468 type = DECL_ORIGINAL_TYPE (decl);
12470 gcc_assert (type != TREE_TYPE (decl));
12471 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12474 type = TREE_TYPE (decl);
12476 add_type_attribute (type_die, type, TREE_READONLY (decl),
12477 TREE_THIS_VOLATILE (decl), context_die);
12480 if (DECL_ABSTRACT (decl))
12481 equate_decl_number_to_die (decl, type_die);
12484 /* Generate a type description DIE. */
12487 gen_type_die (tree type, dw_die_ref context_die)
12491 if (type == NULL_TREE || type == error_mark_node)
12494 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12495 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12497 if (TREE_ASM_WRITTEN (type))
12500 /* Prevent broken recursion; we can't hand off to the same type. */
12501 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12503 TREE_ASM_WRITTEN (type) = 1;
12504 gen_decl_die (TYPE_NAME (type), context_die);
12508 /* We are going to output a DIE to represent the unqualified version
12509 of this type (i.e. without any const or volatile qualifiers) so
12510 get the main variant (i.e. the unqualified version) of this type
12511 now. (Vectors are special because the debugging info is in the
12512 cloned type itself). */
12513 if (TREE_CODE (type) != VECTOR_TYPE)
12514 type = type_main_variant (type);
12516 if (TREE_ASM_WRITTEN (type))
12519 switch (TREE_CODE (type))
12525 case REFERENCE_TYPE:
12526 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12527 ensures that the gen_type_die recursion will terminate even if the
12528 type is recursive. Recursive types are possible in Ada. */
12529 /* ??? We could perhaps do this for all types before the switch
12531 TREE_ASM_WRITTEN (type) = 1;
12533 /* For these types, all that is required is that we output a DIE (or a
12534 set of DIEs) to represent the "basis" type. */
12535 gen_type_die (TREE_TYPE (type), context_die);
12539 /* This code is used for C++ pointer-to-data-member types.
12540 Output a description of the relevant class type. */
12541 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
12543 /* Output a description of the type of the object pointed to. */
12544 gen_type_die (TREE_TYPE (type), context_die);
12546 /* Now output a DIE to represent this pointer-to-data-member type
12548 gen_ptr_to_mbr_type_die (type, context_die);
12551 case FUNCTION_TYPE:
12552 /* Force out return type (in case it wasn't forced out already). */
12553 gen_type_die (TREE_TYPE (type), context_die);
12554 gen_subroutine_type_die (type, context_die);
12558 /* Force out return type (in case it wasn't forced out already). */
12559 gen_type_die (TREE_TYPE (type), context_die);
12560 gen_subroutine_type_die (type, context_die);
12564 gen_array_type_die (type, context_die);
12568 gen_array_type_die (type, context_die);
12571 case ENUMERAL_TYPE:
12574 case QUAL_UNION_TYPE:
12575 /* If this is a nested type whose containing class hasn't been written
12576 out yet, writing it out will cover this one, too. This does not apply
12577 to instantiations of member class templates; they need to be added to
12578 the containing class as they are generated. FIXME: This hurts the
12579 idea of combining type decls from multiple TUs, since we can't predict
12580 what set of template instantiations we'll get. */
12581 if (TYPE_CONTEXT (type)
12582 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12583 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
12585 gen_type_die (TYPE_CONTEXT (type), context_die);
12587 if (TREE_ASM_WRITTEN (type))
12590 /* If that failed, attach ourselves to the stub. */
12591 push_decl_scope (TYPE_CONTEXT (type));
12592 context_die = lookup_type_die (TYPE_CONTEXT (type));
12597 declare_in_namespace (type, context_die);
12601 if (TREE_CODE (type) == ENUMERAL_TYPE)
12602 gen_enumeration_type_die (type, context_die);
12604 gen_struct_or_union_type_die (type, context_die);
12609 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12610 it up if it is ever completed. gen_*_type_die will set it for us
12611 when appropriate. */
12619 /* No DIEs needed for fundamental types. */
12623 /* No Dwarf representation currently defined. */
12627 gcc_unreachable ();
12630 TREE_ASM_WRITTEN (type) = 1;
12633 /* Generate a DIE for a tagged type instantiation. */
12636 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
12638 if (type == NULL_TREE || type == error_mark_node)
12641 /* We are going to output a DIE to represent the unqualified version of
12642 this type (i.e. without any const or volatile qualifiers) so make sure
12643 that we have the main variant (i.e. the unqualified version) of this
12645 gcc_assert (type == type_main_variant (type));
12647 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12648 an instance of an unresolved type. */
12650 switch (TREE_CODE (type))
12655 case ENUMERAL_TYPE:
12656 gen_inlined_enumeration_type_die (type, context_die);
12660 gen_inlined_structure_type_die (type, context_die);
12664 case QUAL_UNION_TYPE:
12665 gen_inlined_union_type_die (type, context_die);
12669 gcc_unreachable ();
12673 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12674 things which are local to the given block. */
12677 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
12679 int must_output_die = 0;
12682 enum tree_code origin_code;
12684 /* Ignore blocks that are NULL. */
12685 if (stmt == NULL_TREE)
12688 /* If the block is one fragment of a non-contiguous block, do not
12689 process the variables, since they will have been done by the
12690 origin block. Do process subblocks. */
12691 if (BLOCK_FRAGMENT_ORIGIN (stmt))
12695 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
12696 gen_block_die (sub, context_die, depth + 1);
12701 /* Determine the "ultimate origin" of this block. This block may be an
12702 inlined instance of an inlined instance of inline function, so we have
12703 to trace all of the way back through the origin chain to find out what
12704 sort of node actually served as the original seed for the creation of
12705 the current block. */
12706 origin = block_ultimate_origin (stmt);
12707 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
12709 /* Determine if we need to output any Dwarf DIEs at all to represent this
12711 if (origin_code == FUNCTION_DECL)
12712 /* The outer scopes for inlinings *must* always be represented. We
12713 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12714 must_output_die = 1;
12717 /* In the case where the current block represents an inlining of the
12718 "body block" of an inline function, we must *NOT* output any DIE for
12719 this block because we have already output a DIE to represent the whole
12720 inlined function scope and the "body block" of any function doesn't
12721 really represent a different scope according to ANSI C rules. So we
12722 check here to make sure that this block does not represent a "body
12723 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12724 if (! is_body_block (origin ? origin : stmt))
12726 /* Determine if this block directly contains any "significant"
12727 local declarations which we will need to output DIEs for. */
12728 if (debug_info_level > DINFO_LEVEL_TERSE)
12729 /* We are not in terse mode so *any* local declaration counts
12730 as being a "significant" one. */
12731 must_output_die = (BLOCK_VARS (stmt) != NULL
12732 && (TREE_USED (stmt)
12733 || TREE_ASM_WRITTEN (stmt)
12734 || BLOCK_ABSTRACT (stmt)));
12736 /* We are in terse mode, so only local (nested) function
12737 definitions count as "significant" local declarations. */
12738 for (decl = BLOCK_VARS (stmt);
12739 decl != NULL; decl = TREE_CHAIN (decl))
12740 if (TREE_CODE (decl) == FUNCTION_DECL
12741 && DECL_INITIAL (decl))
12743 must_output_die = 1;
12749 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12750 DIE for any block which contains no significant local declarations at
12751 all. Rather, in such cases we just call `decls_for_scope' so that any
12752 needed Dwarf info for any sub-blocks will get properly generated. Note
12753 that in terse mode, our definition of what constitutes a "significant"
12754 local declaration gets restricted to include only inlined function
12755 instances and local (nested) function definitions. */
12756 if (must_output_die)
12758 if (origin_code == FUNCTION_DECL)
12759 gen_inlined_subroutine_die (stmt, context_die, depth);
12761 gen_lexical_block_die (stmt, context_die, depth);
12764 decls_for_scope (stmt, context_die, depth);
12767 /* Generate all of the decls declared within a given scope and (recursively)
12768 all of its sub-blocks. */
12771 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
12776 /* Ignore NULL blocks. */
12777 if (stmt == NULL_TREE)
12780 if (TREE_USED (stmt))
12782 /* Output the DIEs to represent all of the data objects and typedefs
12783 declared directly within this block but not within any nested
12784 sub-blocks. Also, nested function and tag DIEs have been
12785 generated with a parent of NULL; fix that up now. */
12786 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
12790 if (TREE_CODE (decl) == FUNCTION_DECL)
12791 die = lookup_decl_die (decl);
12792 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
12793 die = lookup_type_die (TREE_TYPE (decl));
12797 if (die != NULL && die->die_parent == NULL)
12798 add_child_die (context_die, die);
12799 /* Do not produce debug information for static variables since
12800 these might be optimized out. We are called for these later
12801 in cgraph_varpool_analyze_pending_decls. */
12802 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
12805 gen_decl_die (decl, context_die);
12809 /* If we're at -g1, we're not interested in subblocks. */
12810 if (debug_info_level <= DINFO_LEVEL_TERSE)
12813 /* Output the DIEs to represent all sub-blocks (and the items declared
12814 therein) of this block. */
12815 for (subblocks = BLOCK_SUBBLOCKS (stmt);
12817 subblocks = BLOCK_CHAIN (subblocks))
12818 gen_block_die (subblocks, context_die, depth + 1);
12821 /* Is this a typedef we can avoid emitting? */
12824 is_redundant_typedef (tree decl)
12826 if (TYPE_DECL_IS_STUB (decl))
12829 if (DECL_ARTIFICIAL (decl)
12830 && DECL_CONTEXT (decl)
12831 && is_tagged_type (DECL_CONTEXT (decl))
12832 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
12833 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
12834 /* Also ignore the artificial member typedef for the class name. */
12840 /* Returns the DIE for decl. A DIE will always be returned. */
12843 force_decl_die (tree decl)
12845 dw_die_ref decl_die;
12846 unsigned saved_external_flag;
12847 tree save_fn = NULL_TREE;
12848 decl_die = lookup_decl_die (decl);
12851 dw_die_ref context_die;
12852 tree decl_context = DECL_CONTEXT (decl);
12855 /* Find die that represents this context. */
12856 if (TYPE_P (decl_context))
12857 context_die = force_type_die (decl_context);
12859 context_die = force_decl_die (decl_context);
12862 context_die = comp_unit_die;
12864 decl_die = lookup_decl_die (decl);
12868 switch (TREE_CODE (decl))
12870 case FUNCTION_DECL:
12871 /* Clear current_function_decl, so that gen_subprogram_die thinks
12872 that this is a declaration. At this point, we just want to force
12873 declaration die. */
12874 save_fn = current_function_decl;
12875 current_function_decl = NULL_TREE;
12876 gen_subprogram_die (decl, context_die);
12877 current_function_decl = save_fn;
12881 /* Set external flag to force declaration die. Restore it after
12882 gen_decl_die() call. */
12883 saved_external_flag = DECL_EXTERNAL (decl);
12884 DECL_EXTERNAL (decl) = 1;
12885 gen_decl_die (decl, context_die);
12886 DECL_EXTERNAL (decl) = saved_external_flag;
12889 case NAMESPACE_DECL:
12890 dwarf2out_decl (decl);
12894 gcc_unreachable ();
12897 /* We should be able to find the DIE now. */
12899 decl_die = lookup_decl_die (decl);
12900 gcc_assert (decl_die);
12906 /* Returns the DIE for TYPE. A DIE is always returned. */
12909 force_type_die (tree type)
12911 dw_die_ref type_die;
12913 type_die = lookup_type_die (type);
12916 dw_die_ref context_die;
12917 if (TYPE_CONTEXT (type))
12919 if (TYPE_P (TYPE_CONTEXT (type)))
12920 context_die = force_type_die (TYPE_CONTEXT (type));
12922 context_die = force_decl_die (TYPE_CONTEXT (type));
12925 context_die = comp_unit_die;
12927 type_die = lookup_type_die (type);
12930 gen_type_die (type, context_die);
12931 type_die = lookup_type_die (type);
12932 gcc_assert (type_die);
12937 /* Force out any required namespaces to be able to output DECL,
12938 and return the new context_die for it, if it's changed. */
12941 setup_namespace_context (tree thing, dw_die_ref context_die)
12943 tree context = (DECL_P (thing)
12944 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
12945 if (context && TREE_CODE (context) == NAMESPACE_DECL)
12946 /* Force out the namespace. */
12947 context_die = force_decl_die (context);
12949 return context_die;
12952 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12953 type) within its namespace, if appropriate.
12955 For compatibility with older debuggers, namespace DIEs only contain
12956 declarations; all definitions are emitted at CU scope. */
12959 declare_in_namespace (tree thing, dw_die_ref context_die)
12961 dw_die_ref ns_context;
12963 if (debug_info_level <= DINFO_LEVEL_TERSE)
12966 /* If this decl is from an inlined function, then don't try to emit it in its
12967 namespace, as we will get confused. It would have already been emitted
12968 when the abstract instance of the inline function was emitted anyways. */
12969 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
12972 ns_context = setup_namespace_context (thing, context_die);
12974 if (ns_context != context_die)
12976 if (DECL_P (thing))
12977 gen_decl_die (thing, ns_context);
12979 gen_type_die (thing, ns_context);
12983 /* Generate a DIE for a namespace or namespace alias. */
12986 gen_namespace_die (tree decl)
12988 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
12990 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12991 they are an alias of. */
12992 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
12994 /* Output a real namespace. */
12995 dw_die_ref namespace_die
12996 = new_die (DW_TAG_namespace, context_die, decl);
12997 add_name_and_src_coords_attributes (namespace_die, decl);
12998 equate_decl_number_to_die (decl, namespace_die);
13002 /* Output a namespace alias. */
13004 /* Force out the namespace we are an alias of, if necessary. */
13005 dw_die_ref origin_die
13006 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13008 /* Now create the namespace alias DIE. */
13009 dw_die_ref namespace_die
13010 = new_die (DW_TAG_imported_declaration, context_die, decl);
13011 add_name_and_src_coords_attributes (namespace_die, decl);
13012 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13013 equate_decl_number_to_die (decl, namespace_die);
13017 /* Generate Dwarf debug information for a decl described by DECL. */
13020 gen_decl_die (tree decl, dw_die_ref context_die)
13024 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13027 switch (TREE_CODE (decl))
13033 /* The individual enumerators of an enum type get output when we output
13034 the Dwarf representation of the relevant enum type itself. */
13037 case FUNCTION_DECL:
13038 /* Don't output any DIEs to represent mere function declarations,
13039 unless they are class members or explicit block externs. */
13040 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13041 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13046 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13047 on local redeclarations of global functions. That seems broken. */
13048 if (current_function_decl != decl)
13049 /* This is only a declaration. */;
13052 /* If we're emitting a clone, emit info for the abstract instance. */
13053 if (DECL_ORIGIN (decl) != decl)
13054 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
13056 /* If we're emitting an out-of-line copy of an inline function,
13057 emit info for the abstract instance and set up to refer to it. */
13058 else if (cgraph_function_possibly_inlined_p (decl)
13059 && ! DECL_ABSTRACT (decl)
13060 && ! class_or_namespace_scope_p (context_die)
13061 /* dwarf2out_abstract_function won't emit a die if this is just
13062 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13063 that case, because that works only if we have a die. */
13064 && DECL_INITIAL (decl) != NULL_TREE)
13066 dwarf2out_abstract_function (decl);
13067 set_decl_origin_self (decl);
13070 /* Otherwise we're emitting the primary DIE for this decl. */
13071 else if (debug_info_level > DINFO_LEVEL_TERSE)
13073 /* Before we describe the FUNCTION_DECL itself, make sure that we
13074 have described its return type. */
13075 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
13077 /* And its virtual context. */
13078 if (DECL_VINDEX (decl) != NULL_TREE)
13079 gen_type_die (DECL_CONTEXT (decl), context_die);
13081 /* And its containing type. */
13082 origin = decl_class_context (decl);
13083 if (origin != NULL_TREE)
13084 gen_type_die_for_member (origin, decl, context_die);
13086 /* And its containing namespace. */
13087 declare_in_namespace (decl, context_die);
13090 /* Now output a DIE to represent the function itself. */
13091 gen_subprogram_die (decl, context_die);
13095 /* If we are in terse mode, don't generate any DIEs to represent any
13096 actual typedefs. */
13097 if (debug_info_level <= DINFO_LEVEL_TERSE)
13100 /* In the special case of a TYPE_DECL node representing the declaration
13101 of some type tag, if the given TYPE_DECL is marked as having been
13102 instantiated from some other (original) TYPE_DECL node (e.g. one which
13103 was generated within the original definition of an inline function) we
13104 have to generate a special (abbreviated) DW_TAG_structure_type,
13105 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13106 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
13108 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
13112 if (is_redundant_typedef (decl))
13113 gen_type_die (TREE_TYPE (decl), context_die);
13115 /* Output a DIE to represent the typedef itself. */
13116 gen_typedef_die (decl, context_die);
13120 if (debug_info_level >= DINFO_LEVEL_NORMAL)
13121 gen_label_die (decl, context_die);
13126 /* If we are in terse mode, don't generate any DIEs to represent any
13127 variable declarations or definitions. */
13128 if (debug_info_level <= DINFO_LEVEL_TERSE)
13131 /* Output any DIEs that are needed to specify the type of this data
13133 gen_type_die (TREE_TYPE (decl), context_die);
13135 /* And its containing type. */
13136 origin = decl_class_context (decl);
13137 if (origin != NULL_TREE)
13138 gen_type_die_for_member (origin, decl, context_die);
13140 /* And its containing namespace. */
13141 declare_in_namespace (decl, context_die);
13143 /* Now output the DIE to represent the data object itself. This gets
13144 complicated because of the possibility that the VAR_DECL really
13145 represents an inlined instance of a formal parameter for an inline
13147 origin = decl_ultimate_origin (decl);
13148 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
13149 gen_formal_parameter_die (decl, context_die);
13151 gen_variable_die (decl, context_die);
13155 /* Ignore the nameless fields that are used to skip bits but handle C++
13156 anonymous unions and structs. */
13157 if (DECL_NAME (decl) != NULL_TREE
13158 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
13159 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
13161 gen_type_die (member_declared_type (decl), context_die);
13162 gen_field_die (decl, context_die);
13167 gen_type_die (TREE_TYPE (decl), context_die);
13168 gen_formal_parameter_die (decl, context_die);
13171 case NAMESPACE_DECL:
13172 gen_namespace_die (decl);
13176 /* Probably some frontend-internal decl. Assume we don't care. */
13177 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
13182 /* Output debug information for global decl DECL. Called from toplev.c after
13183 compilation proper has finished. */
13186 dwarf2out_global_decl (tree decl)
13188 /* Output DWARF2 information for file-scope tentative data object
13189 declarations, file-scope (extern) function declarations (which had no
13190 corresponding body) and file-scope tagged type declarations and
13191 definitions which have not yet been forced out. */
13192 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
13193 dwarf2out_decl (decl);
13196 /* Output debug information for type decl DECL. Called from toplev.c
13197 and from language front ends (to record built-in types). */
13199 dwarf2out_type_decl (tree decl, int local)
13202 dwarf2out_decl (decl);
13205 /* Output debug information for imported module or decl. */
13208 dwarf2out_imported_module_or_decl (tree decl, tree context)
13210 dw_die_ref imported_die, at_import_die;
13211 dw_die_ref scope_die;
13212 unsigned file_index;
13213 expanded_location xloc;
13215 if (debug_info_level <= DINFO_LEVEL_TERSE)
13220 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13221 We need decl DIE for reference and scope die. First, get DIE for the decl
13224 /* Get the scope die for decl context. Use comp_unit_die for global module
13225 or decl. If die is not found for non globals, force new die. */
13227 scope_die = comp_unit_die;
13228 else if (TYPE_P (context))
13229 scope_die = force_type_die (context);
13231 scope_die = force_decl_die (context);
13233 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13234 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
13235 at_import_die = force_type_die (TREE_TYPE (decl));
13238 at_import_die = lookup_decl_die (decl);
13239 if (!at_import_die)
13241 /* If we're trying to avoid duplicate debug info, we may not have
13242 emitted the member decl for this field. Emit it now. */
13243 if (TREE_CODE (decl) == FIELD_DECL)
13245 tree type = DECL_CONTEXT (decl);
13246 dw_die_ref type_context_die;
13248 if (TYPE_CONTEXT (type))
13249 if (TYPE_P (TYPE_CONTEXT (type)))
13250 type_context_die = force_type_die (TYPE_CONTEXT (type));
13252 type_context_die = force_decl_die (TYPE_CONTEXT (type));
13254 type_context_die = comp_unit_die;
13255 gen_type_die_for_member (type, decl, type_context_die);
13257 at_import_die = force_decl_die (decl);
13261 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13262 if (TREE_CODE (decl) == NAMESPACE_DECL)
13263 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
13265 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
13267 xloc = expand_location (input_location);
13268 file_index = lookup_filename (xloc.file);
13269 add_AT_unsigned (imported_die, DW_AT_decl_file, file_index);
13270 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
13271 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
13274 /* Write the debugging output for DECL. */
13277 dwarf2out_decl (tree decl)
13279 dw_die_ref context_die = comp_unit_die;
13281 switch (TREE_CODE (decl))
13286 case FUNCTION_DECL:
13287 /* What we would really like to do here is to filter out all mere
13288 file-scope declarations of file-scope functions which are never
13289 referenced later within this translation unit (and keep all of ones
13290 that *are* referenced later on) but we aren't clairvoyant, so we have
13291 no idea which functions will be referenced in the future (i.e. later
13292 on within the current translation unit). So here we just ignore all
13293 file-scope function declarations which are not also definitions. If
13294 and when the debugger needs to know something about these functions,
13295 it will have to hunt around and find the DWARF information associated
13296 with the definition of the function.
13298 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13299 nodes represent definitions and which ones represent mere
13300 declarations. We have to check DECL_INITIAL instead. That's because
13301 the C front-end supports some weird semantics for "extern inline"
13302 function definitions. These can get inlined within the current
13303 translation unit (and thus, we need to generate Dwarf info for their
13304 abstract instances so that the Dwarf info for the concrete inlined
13305 instances can have something to refer to) but the compiler never
13306 generates any out-of-lines instances of such things (despite the fact
13307 that they *are* definitions).
13309 The important point is that the C front-end marks these "extern
13310 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13311 them anyway. Note that the C++ front-end also plays some similar games
13312 for inline function definitions appearing within include files which
13313 also contain `#pragma interface' pragmas. */
13314 if (DECL_INITIAL (decl) == NULL_TREE)
13317 /* If we're a nested function, initially use a parent of NULL; if we're
13318 a plain function, this will be fixed up in decls_for_scope. If
13319 we're a method, it will be ignored, since we already have a DIE. */
13320 if (decl_function_context (decl)
13321 /* But if we're in terse mode, we don't care about scope. */
13322 && debug_info_level > DINFO_LEVEL_TERSE)
13323 context_die = NULL;
13327 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13328 declaration and if the declaration was never even referenced from
13329 within this entire compilation unit. We suppress these DIEs in
13330 order to save space in the .debug section (by eliminating entries
13331 which are probably useless). Note that we must not suppress
13332 block-local extern declarations (whether used or not) because that
13333 would screw-up the debugger's name lookup mechanism and cause it to
13334 miss things which really ought to be in scope at a given point. */
13335 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
13338 /* For local statics lookup proper context die. */
13339 if (TREE_STATIC (decl) && decl_function_context (decl))
13340 context_die = lookup_decl_die (DECL_CONTEXT (decl));
13342 /* If we are in terse mode, don't generate any DIEs to represent any
13343 variable declarations or definitions. */
13344 if (debug_info_level <= DINFO_LEVEL_TERSE)
13348 case NAMESPACE_DECL:
13349 if (debug_info_level <= DINFO_LEVEL_TERSE)
13351 if (lookup_decl_die (decl) != NULL)
13356 /* Don't emit stubs for types unless they are needed by other DIEs. */
13357 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
13360 /* Don't bother trying to generate any DIEs to represent any of the
13361 normal built-in types for the language we are compiling. */
13362 if (DECL_IS_BUILTIN (decl))
13364 /* OK, we need to generate one for `bool' so GDB knows what type
13365 comparisons have. */
13367 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
13368 && ! DECL_IGNORED_P (decl))
13369 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
13374 /* If we are in terse mode, don't generate any DIEs for types. */
13375 if (debug_info_level <= DINFO_LEVEL_TERSE)
13378 /* If we're a function-scope tag, initially use a parent of NULL;
13379 this will be fixed up in decls_for_scope. */
13380 if (decl_function_context (decl))
13381 context_die = NULL;
13389 gen_decl_die (decl, context_die);
13392 /* Output a marker (i.e. a label) for the beginning of the generated code for
13393 a lexical block. */
13396 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
13397 unsigned int blocknum)
13399 switch_to_section (current_function_section ());
13400 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
13403 /* Output a marker (i.e. a label) for the end of the generated code for a
13407 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
13409 switch_to_section (current_function_section ());
13410 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
13413 /* Returns nonzero if it is appropriate not to emit any debugging
13414 information for BLOCK, because it doesn't contain any instructions.
13416 Don't allow this for blocks with nested functions or local classes
13417 as we would end up with orphans, and in the presence of scheduling
13418 we may end up calling them anyway. */
13421 dwarf2out_ignore_block (tree block)
13425 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
13426 if (TREE_CODE (decl) == FUNCTION_DECL
13427 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
13433 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13434 dwarf2out.c) and return its "index". The index of each (known) filename is
13435 just a unique number which is associated with only that one filename. We
13436 need such numbers for the sake of generating labels (in the .debug_sfnames
13437 section) and references to those files numbers (in the .debug_srcinfo
13438 and.debug_macinfo sections). If the filename given as an argument is not
13439 found in our current list, add it to the list and assign it the next
13440 available unique index number. In order to speed up searches, we remember
13441 the index of the filename was looked up last. This handles the majority of
13445 lookup_filename (const char *file_name)
13448 char *save_file_name;
13450 /* Check to see if the file name that was searched on the previous
13451 call matches this file name. If so, return the index. */
13452 if (file_table_last_lookup_index != 0)
13455 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
13456 if (strcmp (file_name, last) == 0)
13457 return file_table_last_lookup_index;
13460 /* Didn't match the previous lookup, search the table. */
13461 n = VARRAY_ACTIVE_SIZE (file_table);
13462 for (i = 1; i < n; i++)
13463 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
13465 file_table_last_lookup_index = i;
13469 /* Add the new entry to the end of the filename table. */
13470 file_table_last_lookup_index = n;
13471 save_file_name = (char *) ggc_strdup (file_name);
13472 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
13473 VARRAY_PUSH_UINT (file_table_emitted, 0);
13475 /* If the assembler is emitting the file table, and we aren't eliminating
13476 unused debug types, then we must emit .file here. If we are eliminating
13477 unused debug types, then this will be done by the maybe_emit_file call in
13478 prune_unused_types_walk_attribs. */
13480 if (DWARF2_ASM_LINE_DEBUG_INFO && ! flag_eliminate_unused_debug_types)
13481 return maybe_emit_file (i);
13486 /* If the assembler will construct the file table, then translate the compiler
13487 internal file table number into the assembler file table number, and emit
13488 a .file directive if we haven't already emitted one yet. The file table
13489 numbers are different because we prune debug info for unused variables and
13490 types, which may include filenames. */
13493 maybe_emit_file (int fileno)
13495 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
13497 if (!VARRAY_UINT (file_table_emitted, fileno))
13499 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
13500 fprintf (asm_out_file, "\t.file %u ",
13501 VARRAY_UINT (file_table_emitted, fileno));
13502 output_quoted_string (asm_out_file,
13503 VARRAY_CHAR_PTR (file_table, fileno));
13504 fputc ('\n', asm_out_file);
13506 return VARRAY_UINT (file_table_emitted, fileno);
13512 /* Initialize the compiler internal file table. */
13515 init_file_table (void)
13517 /* Allocate the initial hunk of the file_table. */
13518 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
13519 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
13521 /* Skip the first entry - file numbers begin at 1. */
13522 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
13523 VARRAY_PUSH_UINT (file_table_emitted, 0);
13524 file_table_last_lookup_index = 0;
13527 /* Called by the final INSN scan whenever we see a var location. We
13528 use it to drop labels in the right places, and throw the location in
13529 our lookup table. */
13532 dwarf2out_var_location (rtx loc_note)
13534 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
13535 struct var_loc_node *newloc;
13537 static rtx last_insn;
13538 static const char *last_label;
13541 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
13543 prev_insn = PREV_INSN (loc_note);
13545 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
13546 /* If the insn we processed last time is the previous insn
13547 and it is also a var location note, use the label we emitted
13549 if (last_insn != NULL_RTX
13550 && last_insn == prev_insn
13551 && NOTE_P (prev_insn)
13552 && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION)
13554 newloc->label = last_label;
13558 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
13559 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
13561 newloc->label = ggc_strdup (loclabel);
13563 newloc->var_loc_note = loc_note;
13564 newloc->next = NULL;
13566 if (cfun && in_cold_section_p)
13567 newloc->section_label = cfun->cold_section_label;
13569 newloc->section_label = text_section_label;
13571 last_insn = loc_note;
13572 last_label = newloc->label;
13573 decl = NOTE_VAR_LOCATION_DECL (loc_note);
13574 if (DECL_DEBUG_EXPR_IS_FROM (decl) && DECL_DEBUG_EXPR (decl)
13575 && DECL_P (DECL_DEBUG_EXPR (decl)))
13576 decl = DECL_DEBUG_EXPR (decl);
13577 add_var_loc_to_decl (decl, newloc);
13580 /* We need to reset the locations at the beginning of each
13581 function. We can't do this in the end_function hook, because the
13582 declarations that use the locations won't have been output when
13583 that hook is called. Also compute have_multiple_function_sections here. */
13586 dwarf2out_begin_function (tree fun)
13588 htab_empty (decl_loc_table);
13590 if (function_section (fun) != text_section)
13591 have_multiple_function_sections = true;
13594 /* Output a label to mark the beginning of a source code line entry
13595 and record information relating to this source line, in
13596 'line_info_table' for later output of the .debug_line section. */
13599 dwarf2out_source_line (unsigned int line, const char *filename)
13601 if (debug_info_level >= DINFO_LEVEL_NORMAL
13604 switch_to_section (current_function_section ());
13606 /* If requested, emit something human-readable. */
13607 if (flag_debug_asm)
13608 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
13611 if (DWARF2_ASM_LINE_DEBUG_INFO)
13613 unsigned file_num = lookup_filename (filename);
13615 file_num = maybe_emit_file (file_num);
13617 /* Emit the .loc directive understood by GNU as. */
13618 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
13620 /* Indicate that line number info exists. */
13621 line_info_table_in_use++;
13623 else if (function_section (current_function_decl) != text_section)
13625 dw_separate_line_info_ref line_info;
13626 targetm.asm_out.internal_label (asm_out_file, SEPARATE_LINE_CODE_LABEL,
13627 separate_line_info_table_in_use);
13629 /* Expand the line info table if necessary. */
13630 if (separate_line_info_table_in_use
13631 == separate_line_info_table_allocated)
13633 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13634 separate_line_info_table
13635 = ggc_realloc (separate_line_info_table,
13636 separate_line_info_table_allocated
13637 * sizeof (dw_separate_line_info_entry));
13638 memset (separate_line_info_table
13639 + separate_line_info_table_in_use,
13641 (LINE_INFO_TABLE_INCREMENT
13642 * sizeof (dw_separate_line_info_entry)));
13645 /* Add the new entry at the end of the line_info_table. */
13647 = &separate_line_info_table[separate_line_info_table_in_use++];
13648 line_info->dw_file_num = lookup_filename (filename);
13649 line_info->dw_line_num = line;
13650 line_info->function = current_function_funcdef_no;
13654 dw_line_info_ref line_info;
13656 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
13657 line_info_table_in_use);
13659 /* Expand the line info table if necessary. */
13660 if (line_info_table_in_use == line_info_table_allocated)
13662 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13664 = ggc_realloc (line_info_table,
13665 (line_info_table_allocated
13666 * sizeof (dw_line_info_entry)));
13667 memset (line_info_table + line_info_table_in_use, 0,
13668 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
13671 /* Add the new entry at the end of the line_info_table. */
13672 line_info = &line_info_table[line_info_table_in_use++];
13673 line_info->dw_file_num = lookup_filename (filename);
13674 line_info->dw_line_num = line;
13679 /* Record the beginning of a new source file. */
13682 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
13684 if (flag_eliminate_dwarf2_dups)
13686 /* Record the beginning of the file for break_out_includes. */
13687 dw_die_ref bincl_die;
13689 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
13690 add_AT_string (bincl_die, DW_AT_name, filename);
13693 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13697 switch_to_section (debug_macinfo_section);
13698 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
13699 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
13702 fileno = maybe_emit_file (lookup_filename (filename));
13703 dw2_asm_output_data_uleb128 (fileno, "Filename we just started");
13707 /* Record the end of a source file. */
13710 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
13712 if (flag_eliminate_dwarf2_dups)
13713 /* Record the end of the file for break_out_includes. */
13714 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
13716 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13718 switch_to_section (debug_macinfo_section);
13719 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13723 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13724 the tail part of the directive line, i.e. the part which is past the
13725 initial whitespace, #, whitespace, directive-name, whitespace part. */
13728 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
13729 const char *buffer ATTRIBUTE_UNUSED)
13731 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13733 switch_to_section (debug_macinfo_section);
13734 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
13735 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13736 dw2_asm_output_nstring (buffer, -1, "The macro");
13740 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13741 the tail part of the directive line, i.e. the part which is past the
13742 initial whitespace, #, whitespace, directive-name, whitespace part. */
13745 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
13746 const char *buffer ATTRIBUTE_UNUSED)
13748 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13750 switch_to_section (debug_macinfo_section);
13751 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
13752 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13753 dw2_asm_output_nstring (buffer, -1, "The macro");
13757 /* Set up for Dwarf output at the start of compilation. */
13760 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
13762 init_file_table ();
13764 /* Allocate the decl_die_table. */
13765 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
13766 decl_die_table_eq, NULL);
13768 /* Allocate the decl_loc_table. */
13769 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
13770 decl_loc_table_eq, NULL);
13772 /* Allocate the initial hunk of the decl_scope_table. */
13773 decl_scope_table = VEC_alloc (tree, gc, 256);
13775 /* Allocate the initial hunk of the abbrev_die_table. */
13776 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13777 * sizeof (dw_die_ref));
13778 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
13779 /* Zero-th entry is allocated, but unused. */
13780 abbrev_die_table_in_use = 1;
13782 /* Allocate the initial hunk of the line_info_table. */
13783 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13784 * sizeof (dw_line_info_entry));
13785 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
13787 /* Zero-th entry is allocated, but unused. */
13788 line_info_table_in_use = 1;
13790 /* Generate the initial DIE for the .debug section. Note that the (string)
13791 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13792 will (typically) be a relative pathname and that this pathname should be
13793 taken as being relative to the directory from which the compiler was
13794 invoked when the given (base) source file was compiled. We will fill
13795 in this value in dwarf2out_finish. */
13796 comp_unit_die = gen_compile_unit_die (NULL);
13798 incomplete_types = VEC_alloc (tree, gc, 64);
13800 used_rtx_array = VEC_alloc (rtx, gc, 32);
13802 debug_info_section = get_section (DEBUG_INFO_SECTION,
13803 SECTION_DEBUG, NULL);
13804 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
13805 SECTION_DEBUG, NULL);
13806 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
13807 SECTION_DEBUG, NULL);
13808 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
13809 SECTION_DEBUG, NULL);
13810 debug_line_section = get_section (DEBUG_LINE_SECTION,
13811 SECTION_DEBUG, NULL);
13812 debug_loc_section = get_section (DEBUG_LOC_SECTION,
13813 SECTION_DEBUG, NULL);
13814 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
13815 SECTION_DEBUG, NULL);
13816 debug_str_section = get_section (DEBUG_STR_SECTION,
13817 DEBUG_STR_SECTION_FLAGS, NULL);
13818 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
13819 SECTION_DEBUG, NULL);
13820 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
13821 SECTION_DEBUG, NULL);
13823 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
13824 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
13825 DEBUG_ABBREV_SECTION_LABEL, 0);
13826 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
13827 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
13828 COLD_TEXT_SECTION_LABEL, 0);
13829 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
13831 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
13832 DEBUG_INFO_SECTION_LABEL, 0);
13833 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
13834 DEBUG_LINE_SECTION_LABEL, 0);
13835 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
13836 DEBUG_RANGES_SECTION_LABEL, 0);
13837 switch_to_section (debug_abbrev_section);
13838 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
13839 switch_to_section (debug_info_section);
13840 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
13841 switch_to_section (debug_line_section);
13842 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
13844 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13846 switch_to_section (debug_macinfo_section);
13847 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
13848 DEBUG_MACINFO_SECTION_LABEL, 0);
13849 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
13852 switch_to_section (text_section);
13853 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
13854 if (flag_reorder_blocks_and_partition)
13856 switch_to_section (unlikely_text_section ());
13857 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
13861 /* A helper function for dwarf2out_finish called through
13862 ht_forall. Emit one queued .debug_str string. */
13865 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
13867 struct indirect_string_node *node = (struct indirect_string_node *) *h;
13869 if (node->form == DW_FORM_strp)
13871 switch_to_section (debug_str_section);
13872 ASM_OUTPUT_LABEL (asm_out_file, node->label);
13873 assemble_string (node->str, strlen (node->str) + 1);
13881 /* Clear the marks for a die and its children.
13882 Be cool if the mark isn't set. */
13885 prune_unmark_dies (dw_die_ref die)
13889 for (c = die->die_child; c; c = c->die_sib)
13890 prune_unmark_dies (c);
13894 /* Given DIE that we're marking as used, find any other dies
13895 it references as attributes and mark them as used. */
13898 prune_unused_types_walk_attribs (dw_die_ref die)
13903 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
13905 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
13907 /* A reference to another DIE.
13908 Make sure that it will get emitted. */
13909 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
13911 else if (a->dw_attr == DW_AT_decl_file || a->dw_attr == DW_AT_call_file)
13913 /* A reference to a file. Make sure the file name is emitted. */
13914 a->dw_attr_val.v.val_unsigned =
13915 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
13921 /* Mark DIE as being used. If DOKIDS is true, then walk down
13922 to DIE's children. */
13925 prune_unused_types_mark (dw_die_ref die, int dokids)
13929 if (die->die_mark == 0)
13931 /* We haven't done this node yet. Mark it as used. */
13934 /* We also have to mark its parents as used.
13935 (But we don't want to mark our parents' kids due to this.) */
13936 if (die->die_parent)
13937 prune_unused_types_mark (die->die_parent, 0);
13939 /* Mark any referenced nodes. */
13940 prune_unused_types_walk_attribs (die);
13942 /* If this node is a specification,
13943 also mark the definition, if it exists. */
13944 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
13945 prune_unused_types_mark (die->die_definition, 1);
13948 if (dokids && die->die_mark != 2)
13950 /* We need to walk the children, but haven't done so yet.
13951 Remember that we've walked the kids. */
13955 for (c = die->die_child; c; c = c->die_sib)
13957 /* If this is an array type, we need to make sure our
13958 kids get marked, even if they're types. */
13959 if (die->die_tag == DW_TAG_array_type)
13960 prune_unused_types_mark (c, 1);
13962 prune_unused_types_walk (c);
13968 /* Walk the tree DIE and mark types that we actually use. */
13971 prune_unused_types_walk (dw_die_ref die)
13975 /* Don't do anything if this node is already marked. */
13979 switch (die->die_tag) {
13980 case DW_TAG_const_type:
13981 case DW_TAG_packed_type:
13982 case DW_TAG_pointer_type:
13983 case DW_TAG_reference_type:
13984 case DW_TAG_volatile_type:
13985 case DW_TAG_typedef:
13986 case DW_TAG_array_type:
13987 case DW_TAG_structure_type:
13988 case DW_TAG_union_type:
13989 case DW_TAG_class_type:
13990 case DW_TAG_friend:
13991 case DW_TAG_variant_part:
13992 case DW_TAG_enumeration_type:
13993 case DW_TAG_subroutine_type:
13994 case DW_TAG_string_type:
13995 case DW_TAG_set_type:
13996 case DW_TAG_subrange_type:
13997 case DW_TAG_ptr_to_member_type:
13998 case DW_TAG_file_type:
13999 if (die->die_perennial_p)
14002 /* It's a type node --- don't mark it. */
14006 /* Mark everything else. */
14012 /* Now, mark any dies referenced from here. */
14013 prune_unused_types_walk_attribs (die);
14015 /* Mark children. */
14016 for (c = die->die_child; c; c = c->die_sib)
14017 prune_unused_types_walk (c);
14021 /* Remove from the tree DIE any dies that aren't marked. */
14024 prune_unused_types_prune (dw_die_ref die)
14026 dw_die_ref c, p, n;
14028 gcc_assert (die->die_mark);
14031 for (c = die->die_child; c; c = n)
14036 prune_unused_types_prune (c);
14044 die->die_child = n;
14051 /* Remove dies representing declarations that we never use. */
14054 prune_unused_types (void)
14057 limbo_die_node *node;
14059 /* Clear all the marks. */
14060 prune_unmark_dies (comp_unit_die);
14061 for (node = limbo_die_list; node; node = node->next)
14062 prune_unmark_dies (node->die);
14064 /* Set the mark on nodes that are actually used. */
14065 prune_unused_types_walk (comp_unit_die);
14066 for (node = limbo_die_list; node; node = node->next)
14067 prune_unused_types_walk (node->die);
14069 /* Also set the mark on nodes referenced from the
14070 pubname_table or arange_table. */
14071 for (i = 0; i < pubname_table_in_use; i++)
14072 prune_unused_types_mark (pubname_table[i].die, 1);
14073 for (i = 0; i < arange_table_in_use; i++)
14074 prune_unused_types_mark (arange_table[i], 1);
14076 /* Get rid of nodes that aren't marked. */
14077 prune_unused_types_prune (comp_unit_die);
14078 for (node = limbo_die_list; node; node = node->next)
14079 prune_unused_types_prune (node->die);
14081 /* Leave the marks clear. */
14082 prune_unmark_dies (comp_unit_die);
14083 for (node = limbo_die_list; node; node = node->next)
14084 prune_unmark_dies (node->die);
14087 /* Output stuff that dwarf requires at the end of every file,
14088 and generate the DWARF-2 debugging info. */
14091 dwarf2out_finish (const char *filename)
14093 limbo_die_node *node, *next_node;
14094 dw_die_ref die = 0;
14096 /* Add the name for the main input file now. We delayed this from
14097 dwarf2out_init to avoid complications with PCH. */
14098 add_name_attribute (comp_unit_die, filename);
14099 if (filename[0] != DIR_SEPARATOR)
14100 add_comp_dir_attribute (comp_unit_die);
14101 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
14104 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
14105 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
14106 /* Don't add cwd for <built-in>. */
14107 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
14109 add_comp_dir_attribute (comp_unit_die);
14114 /* Traverse the limbo die list, and add parent/child links. The only
14115 dies without parents that should be here are concrete instances of
14116 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14117 For concrete instances, we can get the parent die from the abstract
14119 for (node = limbo_die_list; node; node = next_node)
14121 next_node = node->next;
14124 if (die->die_parent == NULL)
14126 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
14129 add_child_die (origin->die_parent, die);
14130 else if (die == comp_unit_die)
14132 else if (errorcount > 0 || sorrycount > 0)
14133 /* It's OK to be confused by errors in the input. */
14134 add_child_die (comp_unit_die, die);
14137 /* In certain situations, the lexical block containing a
14138 nested function can be optimized away, which results
14139 in the nested function die being orphaned. Likewise
14140 with the return type of that nested function. Force
14141 this to be a child of the containing function.
14143 It may happen that even the containing function got fully
14144 inlined and optimized out. In that case we are lost and
14145 assign the empty child. This should not be big issue as
14146 the function is likely unreachable too. */
14147 tree context = NULL_TREE;
14149 gcc_assert (node->created_for);
14151 if (DECL_P (node->created_for))
14152 context = DECL_CONTEXT (node->created_for);
14153 else if (TYPE_P (node->created_for))
14154 context = TYPE_CONTEXT (node->created_for);
14156 gcc_assert (context && TREE_CODE (context) == FUNCTION_DECL);
14158 origin = lookup_decl_die (context);
14160 add_child_die (origin, die);
14162 add_child_die (comp_unit_die, die);
14167 limbo_die_list = NULL;
14169 /* Walk through the list of incomplete types again, trying once more to
14170 emit full debugging info for them. */
14171 retry_incomplete_types ();
14173 /* We need to reverse all the dies before break_out_includes, or
14174 we'll see the end of an include file before the beginning. */
14175 reverse_all_dies (comp_unit_die);
14177 if (flag_eliminate_unused_debug_types)
14178 prune_unused_types ();
14180 /* Generate separate CUs for each of the include files we've seen.
14181 They will go into limbo_die_list. */
14182 if (flag_eliminate_dwarf2_dups)
14183 break_out_includes (comp_unit_die);
14185 /* Traverse the DIE's and add add sibling attributes to those DIE's
14186 that have children. */
14187 add_sibling_attributes (comp_unit_die);
14188 for (node = limbo_die_list; node; node = node->next)
14189 add_sibling_attributes (node->die);
14191 /* Output a terminator label for the .text section. */
14192 switch_to_section (text_section);
14193 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
14194 if (flag_reorder_blocks_and_partition)
14196 switch_to_section (unlikely_text_section ());
14197 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
14200 /* Output the source line correspondence table. We must do this
14201 even if there is no line information. Otherwise, on an empty
14202 translation unit, we will generate a present, but empty,
14203 .debug_info section. IRIX 6.5 `nm' will then complain when
14204 examining the file. */
14205 if (! DWARF2_ASM_LINE_DEBUG_INFO)
14207 switch_to_section (debug_line_section);
14208 output_line_info ();
14211 /* We can only use the low/high_pc attributes if all of the code was
14213 if (!have_multiple_function_sections)
14215 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
14216 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
14219 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
14220 "base address". Use zero so that these addresses become absolute. */
14221 else if (have_location_lists || ranges_table_in_use)
14222 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
14224 /* Output location list section if necessary. */
14225 if (have_location_lists)
14227 /* Output the location lists info. */
14228 switch_to_section (debug_loc_section);
14229 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
14230 DEBUG_LOC_SECTION_LABEL, 0);
14231 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
14232 output_location_lists (die);
14235 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14236 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
14237 debug_line_section_label);
14239 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14240 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
14242 /* Output all of the compilation units. We put the main one last so that
14243 the offsets are available to output_pubnames. */
14244 for (node = limbo_die_list; node; node = node->next)
14245 output_comp_unit (node->die, 0);
14247 output_comp_unit (comp_unit_die, 0);
14249 /* Output the abbreviation table. */
14250 switch_to_section (debug_abbrev_section);
14251 output_abbrev_section ();
14253 /* Output public names table if necessary. */
14254 if (pubname_table_in_use)
14256 switch_to_section (debug_pubnames_section);
14257 output_pubnames ();
14260 /* Output the address range information. We only put functions in the arange
14261 table, so don't write it out if we don't have any. */
14262 if (fde_table_in_use)
14264 switch_to_section (debug_aranges_section);
14268 /* Output ranges section if necessary. */
14269 if (ranges_table_in_use)
14271 switch_to_section (debug_ranges_section);
14272 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
14276 /* Have to end the macro section. */
14277 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14279 switch_to_section (debug_macinfo_section);
14280 dw2_asm_output_data (1, 0, "End compilation unit");
14283 /* If we emitted any DW_FORM_strp form attribute, output the string
14285 if (debug_str_hash)
14286 htab_traverse (debug_str_hash, output_indirect_string, NULL);
14290 /* This should never be used, but its address is needed for comparisons. */
14291 const struct gcc_debug_hooks dwarf2_debug_hooks;
14293 #endif /* DWARF2_DEBUGGING_INFO */
14295 #include "gt-dwarf2out.h"