1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols == DWARF2_DEBUG
123 || write_symbols == VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) VEC(rtx,gc) *used_rtx_array;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 VEC(tree,gc) because we want to tell the garbage collector about
146 static GTY(()) VEC(tree,gc) *incomplete_types;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) VEC(tree,gc) *decl_scope_table;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section *debug_info_section;
157 static GTY(()) section *debug_abbrev_section;
158 static GTY(()) section *debug_aranges_section;
159 static GTY(()) section *debug_macinfo_section;
160 static GTY(()) section *debug_line_section;
161 static GTY(()) section *debug_loc_section;
162 static GTY(()) section *debug_pubnames_section;
163 static GTY(()) section *debug_pubtypes_section;
164 static GTY(()) section *debug_str_section;
165 static GTY(()) section *debug_ranges_section;
166 static GTY(()) section *debug_frame_section;
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct *dw_cfi_ref;
174 typedef struct dw_fde_struct *dw_fde_ref;
175 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 enum dw_cfi_oprnd_type {
184 dw_cfi_oprnd_reg_num,
190 typedef union dw_cfi_oprnd_struct GTY(())
192 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
193 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
194 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
195 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
199 typedef struct dw_cfi_struct GTY(())
201 dw_cfi_ref dw_cfi_next;
202 enum dwarf_call_frame_info dw_cfi_opc;
203 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
205 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
210 /* This is how we define the location of the CFA. We use to handle it
211 as REG + OFFSET all the time, but now it can be more complex.
212 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
213 Instead of passing around REG and OFFSET, we pass a copy
214 of this structure. */
215 typedef struct cfa_loc GTY(())
217 HOST_WIDE_INT offset;
218 HOST_WIDE_INT base_offset;
220 int indirect; /* 1 if CFA is accessed via a dereference. */
223 /* All call frame descriptions (FDE's) in the GCC generated DWARF
224 refer to a single Common Information Entry (CIE), defined at
225 the beginning of the .debug_frame section. This use of a single
226 CIE obviates the need to keep track of multiple CIE's
227 in the DWARF generation routines below. */
229 typedef struct dw_fde_struct GTY(())
232 const char *dw_fde_begin;
233 const char *dw_fde_current_label;
234 const char *dw_fde_end;
235 const char *dw_fde_hot_section_label;
236 const char *dw_fde_hot_section_end_label;
237 const char *dw_fde_unlikely_section_label;
238 const char *dw_fde_unlikely_section_end_label;
239 bool dw_fde_switched_sections;
240 dw_cfi_ref dw_fde_cfi;
241 unsigned funcdef_number;
242 HOST_WIDE_INT stack_realignment;
243 /* Dynamic realign argument pointer register. */
244 unsigned int drap_reg;
245 /* Virtual dynamic realign argument pointer register. */
246 unsigned int vdrap_reg;
247 unsigned all_throwers_are_sibcalls : 1;
248 unsigned nothrow : 1;
249 unsigned uses_eh_lsda : 1;
250 /* Whether we did stack realign in this call frame. */
251 unsigned stack_realign : 1;
252 /* Whether dynamic realign argument pointer register has been saved. */
253 unsigned drap_reg_saved: 1;
257 /* Maximum size (in bytes) of an artificially generated label. */
258 #define MAX_ARTIFICIAL_LABEL_BYTES 30
260 /* The size of addresses as they appear in the Dwarf 2 data.
261 Some architectures use word addresses to refer to code locations,
262 but Dwarf 2 info always uses byte addresses. On such machines,
263 Dwarf 2 addresses need to be larger than the architecture's
265 #ifndef DWARF2_ADDR_SIZE
266 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
269 /* The size in bytes of a DWARF field indicating an offset or length
270 relative to a debug info section, specified to be 4 bytes in the
271 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
274 #ifndef DWARF_OFFSET_SIZE
275 #define DWARF_OFFSET_SIZE 4
278 /* According to the (draft) DWARF 3 specification, the initial length
279 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
280 bytes are 0xffffffff, followed by the length stored in the next 8
283 However, the SGI/MIPS ABI uses an initial length which is equal to
284 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
286 #ifndef DWARF_INITIAL_LENGTH_SIZE
287 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
290 #define DWARF_VERSION 2
292 /* Round SIZE up to the nearest BOUNDARY. */
293 #define DWARF_ROUND(SIZE,BOUNDARY) \
294 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
296 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
297 #ifndef DWARF_CIE_DATA_ALIGNMENT
298 #ifdef STACK_GROWS_DOWNWARD
299 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
301 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
305 /* CIE identifier. */
306 #if HOST_BITS_PER_WIDE_INT >= 64
307 #define DWARF_CIE_ID \
308 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
310 #define DWARF_CIE_ID DW_CIE_ID
313 /* A pointer to the base of a table that contains frame description
314 information for each routine. */
315 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
317 /* Number of elements currently allocated for fde_table. */
318 static GTY(()) unsigned fde_table_allocated;
320 /* Number of elements in fde_table currently in use. */
321 static GTY(()) unsigned fde_table_in_use;
323 /* Size (in elements) of increments by which we may expand the
325 #define FDE_TABLE_INCREMENT 256
327 /* Get the current fde_table entry we should use. */
329 static inline dw_fde_ref
332 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
335 /* A list of call frame insns for the CIE. */
336 static GTY(()) dw_cfi_ref cie_cfi_head;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
340 attribute that accelerates the lookup of the FDE associated
341 with the subprogram. This variable holds the table index of the FDE
342 associated with the current function (body) definition. */
343 static unsigned current_funcdef_fde;
346 struct indirect_string_node GTY(())
349 unsigned int refcount;
354 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
356 static GTY(()) int dw2_string_counter;
357 static GTY(()) unsigned long dwarf2out_cfi_label_num;
359 /* True if the compilation unit places functions in more than one section. */
360 static GTY(()) bool have_multiple_function_sections = false;
362 /* Whether the default text and cold text sections have been used at all. */
364 static GTY(()) bool text_section_used = false;
365 static GTY(()) bool cold_text_section_used = false;
367 /* The default cold text section. */
368 static GTY(()) section *cold_text_section;
370 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
372 /* Forward declarations for functions defined in this file. */
374 static char *stripattributes (const char *);
375 static const char *dwarf_cfi_name (unsigned);
376 static dw_cfi_ref new_cfi (void);
377 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
378 static void add_fde_cfi (const char *, dw_cfi_ref);
379 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
380 static void lookup_cfa (dw_cfa_location *);
381 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
382 #ifdef DWARF2_UNWIND_INFO
383 static void initial_return_save (rtx);
385 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
386 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
387 static void output_call_frame_info (int);
388 static void dwarf2out_note_section_used (void);
389 static void dwarf2out_stack_adjust (rtx, bool);
390 static void dwarf2out_args_size_adjust (HOST_WIDE_INT, const char *);
391 static void flush_queued_reg_saves (void);
392 static bool clobbers_queued_reg_save (const_rtx);
393 static void dwarf2out_frame_debug_expr (rtx, const char *);
395 /* Support for complex CFA locations. */
396 static void output_cfa_loc (dw_cfi_ref);
397 static void get_cfa_from_loc_descr (dw_cfa_location *,
398 struct dw_loc_descr_struct *);
399 static struct dw_loc_descr_struct *build_cfa_loc
400 (dw_cfa_location *, HOST_WIDE_INT);
401 static struct dw_loc_descr_struct *build_cfa_aligned_loc
402 (HOST_WIDE_INT, HOST_WIDE_INT);
403 static void def_cfa_1 (const char *, dw_cfa_location *);
405 /* How to start an assembler comment. */
406 #ifndef ASM_COMMENT_START
407 #define ASM_COMMENT_START ";#"
410 /* Data and reference forms for relocatable data. */
411 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
412 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
414 #ifndef DEBUG_FRAME_SECTION
415 #define DEBUG_FRAME_SECTION ".debug_frame"
418 #ifndef FUNC_BEGIN_LABEL
419 #define FUNC_BEGIN_LABEL "LFB"
422 #ifndef FUNC_END_LABEL
423 #define FUNC_END_LABEL "LFE"
426 #ifndef FRAME_BEGIN_LABEL
427 #define FRAME_BEGIN_LABEL "Lframe"
429 #define CIE_AFTER_SIZE_LABEL "LSCIE"
430 #define CIE_END_LABEL "LECIE"
431 #define FDE_LABEL "LSFDE"
432 #define FDE_AFTER_SIZE_LABEL "LASFDE"
433 #define FDE_END_LABEL "LEFDE"
434 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
435 #define LINE_NUMBER_END_LABEL "LELT"
436 #define LN_PROLOG_AS_LABEL "LASLTP"
437 #define LN_PROLOG_END_LABEL "LELTP"
438 #define DIE_LABEL_PREFIX "DW"
440 /* The DWARF 2 CFA column which tracks the return address. Normally this
441 is the column for PC, or the first column after all of the hard
443 #ifndef DWARF_FRAME_RETURN_COLUMN
445 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
447 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
451 /* The mapping from gcc register number to DWARF 2 CFA column number. By
452 default, we just provide columns for all registers. */
453 #ifndef DWARF_FRAME_REGNUM
454 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
457 /* Hook used by __throw. */
460 expand_builtin_dwarf_sp_column (void)
462 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
463 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
466 /* Return a pointer to a copy of the section string name S with all
467 attributes stripped off, and an asterisk prepended (for assemble_name). */
470 stripattributes (const char *s)
472 char *stripped = XNEWVEC (char, strlen (s) + 2);
477 while (*s && *s != ',')
484 /* MEM is a memory reference for the register size table, each element of
485 which has mode MODE. Initialize column C as a return address column. */
488 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
490 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
491 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
492 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
495 /* Generate code to initialize the register size table. */
498 expand_builtin_init_dwarf_reg_sizes (tree address)
501 enum machine_mode mode = TYPE_MODE (char_type_node);
502 rtx addr = expand_normal (address);
503 rtx mem = gen_rtx_MEM (BLKmode, addr);
504 bool wrote_return_column = false;
506 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
508 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
510 if (rnum < DWARF_FRAME_REGISTERS)
512 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
513 enum machine_mode save_mode = reg_raw_mode[i];
516 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
517 save_mode = choose_hard_reg_mode (i, 1, true);
518 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
520 if (save_mode == VOIDmode)
522 wrote_return_column = true;
524 size = GET_MODE_SIZE (save_mode);
528 emit_move_insn (adjust_address (mem, mode, offset),
529 gen_int_mode (size, mode));
533 if (!wrote_return_column)
534 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
536 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
537 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
540 targetm.init_dwarf_reg_sizes_extra (address);
543 /* Convert a DWARF call frame info. operation to its string name */
546 dwarf_cfi_name (unsigned int cfi_opc)
550 case DW_CFA_advance_loc:
551 return "DW_CFA_advance_loc";
553 return "DW_CFA_offset";
555 return "DW_CFA_restore";
559 return "DW_CFA_set_loc";
560 case DW_CFA_advance_loc1:
561 return "DW_CFA_advance_loc1";
562 case DW_CFA_advance_loc2:
563 return "DW_CFA_advance_loc2";
564 case DW_CFA_advance_loc4:
565 return "DW_CFA_advance_loc4";
566 case DW_CFA_offset_extended:
567 return "DW_CFA_offset_extended";
568 case DW_CFA_restore_extended:
569 return "DW_CFA_restore_extended";
570 case DW_CFA_undefined:
571 return "DW_CFA_undefined";
572 case DW_CFA_same_value:
573 return "DW_CFA_same_value";
574 case DW_CFA_register:
575 return "DW_CFA_register";
576 case DW_CFA_remember_state:
577 return "DW_CFA_remember_state";
578 case DW_CFA_restore_state:
579 return "DW_CFA_restore_state";
581 return "DW_CFA_def_cfa";
582 case DW_CFA_def_cfa_register:
583 return "DW_CFA_def_cfa_register";
584 case DW_CFA_def_cfa_offset:
585 return "DW_CFA_def_cfa_offset";
588 case DW_CFA_def_cfa_expression:
589 return "DW_CFA_def_cfa_expression";
590 case DW_CFA_expression:
591 return "DW_CFA_expression";
592 case DW_CFA_offset_extended_sf:
593 return "DW_CFA_offset_extended_sf";
594 case DW_CFA_def_cfa_sf:
595 return "DW_CFA_def_cfa_sf";
596 case DW_CFA_def_cfa_offset_sf:
597 return "DW_CFA_def_cfa_offset_sf";
599 /* SGI/MIPS specific */
600 case DW_CFA_MIPS_advance_loc8:
601 return "DW_CFA_MIPS_advance_loc8";
604 case DW_CFA_GNU_window_save:
605 return "DW_CFA_GNU_window_save";
606 case DW_CFA_GNU_args_size:
607 return "DW_CFA_GNU_args_size";
608 case DW_CFA_GNU_negative_offset_extended:
609 return "DW_CFA_GNU_negative_offset_extended";
612 return "DW_CFA_<unknown>";
616 /* Return a pointer to a newly allocated Call Frame Instruction. */
618 static inline dw_cfi_ref
621 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
623 cfi->dw_cfi_next = NULL;
624 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
625 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
630 /* Add a Call Frame Instruction to list of instructions. */
633 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
636 dw_fde_ref fde = current_fde ();
638 /* When DRAP is used, CFA is defined with an expression. Redefine
639 CFA may lead to a different CFA value. */
640 if (fde && fde->drap_reg != INVALID_REGNUM)
641 switch (cfi->dw_cfi_opc)
643 case DW_CFA_def_cfa_register:
644 case DW_CFA_def_cfa_offset:
645 case DW_CFA_def_cfa_offset_sf:
647 case DW_CFA_def_cfa_sf:
654 /* Find the end of the chain. */
655 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
661 /* Generate a new label for the CFI info to refer to. */
664 dwarf2out_cfi_label (void)
666 static char label[20];
668 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
669 ASM_OUTPUT_LABEL (asm_out_file, label);
673 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
674 or to the CIE if LABEL is NULL. */
677 add_fde_cfi (const char *label, dw_cfi_ref cfi)
681 dw_fde_ref fde = current_fde ();
683 gcc_assert (fde != NULL);
686 label = dwarf2out_cfi_label ();
688 if (fde->dw_fde_current_label == NULL
689 || strcmp (label, fde->dw_fde_current_label) != 0)
693 label = xstrdup (label);
695 /* Set the location counter to the new label. */
697 /* If we have a current label, advance from there, otherwise
698 set the location directly using set_loc. */
699 xcfi->dw_cfi_opc = fde->dw_fde_current_label
700 ? DW_CFA_advance_loc4
702 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
703 add_cfi (&fde->dw_fde_cfi, xcfi);
705 fde->dw_fde_current_label = label;
708 add_cfi (&fde->dw_fde_cfi, cfi);
712 add_cfi (&cie_cfi_head, cfi);
715 /* Subroutine of lookup_cfa. */
718 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
720 switch (cfi->dw_cfi_opc)
722 case DW_CFA_def_cfa_offset:
723 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
725 case DW_CFA_def_cfa_offset_sf:
727 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
729 case DW_CFA_def_cfa_register:
730 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
733 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
734 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
736 case DW_CFA_def_cfa_sf:
737 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
739 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
741 case DW_CFA_def_cfa_expression:
742 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
749 /* Find the previous value for the CFA. */
752 lookup_cfa (dw_cfa_location *loc)
757 loc->reg = INVALID_REGNUM;
760 loc->base_offset = 0;
762 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
763 lookup_cfa_1 (cfi, loc);
765 fde = current_fde ();
767 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
768 lookup_cfa_1 (cfi, loc);
771 /* The current rule for calculating the DWARF2 canonical frame address. */
772 static dw_cfa_location cfa;
774 /* The register used for saving registers to the stack, and its offset
776 static dw_cfa_location cfa_store;
778 /* The running total of the size of arguments pushed onto the stack. */
779 static HOST_WIDE_INT args_size;
781 /* The last args_size we actually output. */
782 static HOST_WIDE_INT old_args_size;
784 /* Entry point to update the canonical frame address (CFA).
785 LABEL is passed to add_fde_cfi. The value of CFA is now to be
786 calculated from REG+OFFSET. */
789 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
796 def_cfa_1 (label, &loc);
799 /* Determine if two dw_cfa_location structures define the same data. */
802 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
804 return (loc1->reg == loc2->reg
805 && loc1->offset == loc2->offset
806 && loc1->indirect == loc2->indirect
807 && (loc1->indirect == 0
808 || loc1->base_offset == loc2->base_offset));
811 /* This routine does the actual work. The CFA is now calculated from
812 the dw_cfa_location structure. */
815 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
818 dw_cfa_location old_cfa, loc;
823 if (cfa_store.reg == loc.reg && loc.indirect == 0)
824 cfa_store.offset = loc.offset;
826 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
827 lookup_cfa (&old_cfa);
829 /* If nothing changed, no need to issue any call frame instructions. */
830 if (cfa_equal_p (&loc, &old_cfa))
835 if (loc.reg == old_cfa.reg && !loc.indirect)
837 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
838 the CFA register did not change but the offset did. */
841 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
842 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
844 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
845 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
849 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
850 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
854 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
855 else if (loc.offset == old_cfa.offset
856 && old_cfa.reg != INVALID_REGNUM
859 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
860 indicating the CFA register has changed to <register> but the
861 offset has not changed. */
862 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
863 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
867 else if (loc.indirect == 0)
869 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
870 indicating the CFA register has changed to <register> with
871 the specified offset. */
874 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
875 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
877 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
878 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
879 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
883 cfi->dw_cfi_opc = DW_CFA_def_cfa;
884 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
885 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
890 /* Construct a DW_CFA_def_cfa_expression instruction to
891 calculate the CFA using a full location expression since no
892 register-offset pair is available. */
893 struct dw_loc_descr_struct *loc_list;
895 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
896 loc_list = build_cfa_loc (&loc, 0);
897 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
900 add_fde_cfi (label, cfi);
903 /* Add the CFI for saving a register. REG is the CFA column number.
904 LABEL is passed to add_fde_cfi.
905 If SREG is -1, the register is saved at OFFSET from the CFA;
906 otherwise it is saved in SREG. */
909 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
911 dw_cfi_ref cfi = new_cfi ();
912 dw_fde_ref fde = current_fde ();
914 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
916 /* When stack is aligned, store REG using DW_CFA_expression with
919 && fde->stack_realign
920 && sreg == INVALID_REGNUM)
922 cfi->dw_cfi_opc = DW_CFA_expression;
923 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = reg;
924 cfi->dw_cfi_oprnd1.dw_cfi_loc
925 = build_cfa_aligned_loc (offset, fde->stack_realignment);
927 else if (sreg == INVALID_REGNUM)
930 /* The register number won't fit in 6 bits, so we have to use
932 cfi->dw_cfi_opc = DW_CFA_offset_extended;
934 cfi->dw_cfi_opc = DW_CFA_offset;
936 #ifdef ENABLE_CHECKING
938 /* If we get an offset that is not a multiple of
939 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
940 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
942 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
944 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
947 offset /= DWARF_CIE_DATA_ALIGNMENT;
949 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
951 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
953 else if (sreg == reg)
954 cfi->dw_cfi_opc = DW_CFA_same_value;
957 cfi->dw_cfi_opc = DW_CFA_register;
958 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
961 add_fde_cfi (label, cfi);
964 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
965 This CFI tells the unwinder that it needs to restore the window registers
966 from the previous frame's window save area.
968 ??? Perhaps we should note in the CIE where windows are saved (instead of
969 assuming 0(cfa)) and what registers are in the window. */
972 dwarf2out_window_save (const char *label)
974 dw_cfi_ref cfi = new_cfi ();
976 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
977 add_fde_cfi (label, cfi);
980 /* Add a CFI to update the running total of the size of arguments
981 pushed onto the stack. */
984 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
988 if (size == old_args_size)
991 old_args_size = size;
994 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
995 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
996 add_fde_cfi (label, cfi);
999 /* Entry point for saving a register to the stack. REG is the GCC register
1000 number. LABEL and OFFSET are passed to reg_save. */
1003 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1005 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1008 /* Entry point for saving the return address in the stack.
1009 LABEL and OFFSET are passed to reg_save. */
1012 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1014 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1017 /* Entry point for saving the return address in a register.
1018 LABEL and SREG are passed to reg_save. */
1021 dwarf2out_return_reg (const char *label, unsigned int sreg)
1023 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1026 #ifdef DWARF2_UNWIND_INFO
1027 /* Record the initial position of the return address. RTL is
1028 INCOMING_RETURN_ADDR_RTX. */
1031 initial_return_save (rtx rtl)
1033 unsigned int reg = INVALID_REGNUM;
1034 HOST_WIDE_INT offset = 0;
1036 switch (GET_CODE (rtl))
1039 /* RA is in a register. */
1040 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1044 /* RA is on the stack. */
1045 rtl = XEXP (rtl, 0);
1046 switch (GET_CODE (rtl))
1049 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1054 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1055 offset = INTVAL (XEXP (rtl, 1));
1059 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1060 offset = -INTVAL (XEXP (rtl, 1));
1070 /* The return address is at some offset from any value we can
1071 actually load. For instance, on the SPARC it is in %i7+8. Just
1072 ignore the offset for now; it doesn't matter for unwinding frames. */
1073 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1074 initial_return_save (XEXP (rtl, 0));
1081 if (reg != DWARF_FRAME_RETURN_COLUMN)
1082 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1086 /* Given a SET, calculate the amount of stack adjustment it
1089 static HOST_WIDE_INT
1090 stack_adjust_offset (const_rtx pattern)
1092 const_rtx src = SET_SRC (pattern);
1093 const_rtx dest = SET_DEST (pattern);
1094 HOST_WIDE_INT offset = 0;
1097 if (dest == stack_pointer_rtx)
1099 /* (set (reg sp) (plus (reg sp) (const_int))) */
1100 code = GET_CODE (src);
1101 if (! (code == PLUS || code == MINUS)
1102 || XEXP (src, 0) != stack_pointer_rtx
1103 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1106 offset = INTVAL (XEXP (src, 1));
1110 else if (MEM_P (dest))
1112 /* (set (mem (pre_dec (reg sp))) (foo)) */
1113 src = XEXP (dest, 0);
1114 code = GET_CODE (src);
1120 if (XEXP (src, 0) == stack_pointer_rtx)
1122 rtx val = XEXP (XEXP (src, 1), 1);
1123 /* We handle only adjustments by constant amount. */
1124 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1125 && GET_CODE (val) == CONST_INT);
1126 offset = -INTVAL (val);
1133 if (XEXP (src, 0) == stack_pointer_rtx)
1135 offset = GET_MODE_SIZE (GET_MODE (dest));
1142 if (XEXP (src, 0) == stack_pointer_rtx)
1144 offset = -GET_MODE_SIZE (GET_MODE (dest));
1159 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1160 indexed by INSN_UID. */
1162 static HOST_WIDE_INT *barrier_args_size;
1164 /* Helper function for compute_barrier_args_size. Handle one insn. */
1166 static HOST_WIDE_INT
1167 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1168 VEC (rtx, heap) **next)
1170 HOST_WIDE_INT offset = 0;
1173 if (! RTX_FRAME_RELATED_P (insn))
1175 if (prologue_epilogue_contains (insn)
1176 || sibcall_epilogue_contains (insn))
1178 else if (GET_CODE (PATTERN (insn)) == SET)
1179 offset = stack_adjust_offset (PATTERN (insn));
1180 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1181 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1183 /* There may be stack adjustments inside compound insns. Search
1185 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1186 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1187 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1192 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1196 expr = XEXP (expr, 0);
1197 if (GET_CODE (expr) == PARALLEL
1198 || GET_CODE (expr) == SEQUENCE)
1199 for (i = 1; i < XVECLEN (expr, 0); i++)
1201 rtx elem = XVECEXP (expr, 0, i);
1203 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1204 offset += stack_adjust_offset (elem);
1209 #ifndef STACK_GROWS_DOWNWARD
1213 cur_args_size += offset;
1214 if (cur_args_size < 0)
1219 rtx dest = JUMP_LABEL (insn);
1223 if (barrier_args_size [INSN_UID (dest)] < 0)
1225 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1226 VEC_safe_push (rtx, heap, *next, dest);
1229 gcc_assert (barrier_args_size[INSN_UID (dest)]
1234 return cur_args_size;
1237 /* Walk the whole function and compute args_size on BARRIERs. */
1240 compute_barrier_args_size (void)
1242 int max_uid = get_max_uid (), i;
1244 VEC (rtx, heap) *worklist, *next, *tmp;
1246 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1247 for (i = 0; i < max_uid; i++)
1248 barrier_args_size[i] = -1;
1250 worklist = VEC_alloc (rtx, heap, 20);
1251 next = VEC_alloc (rtx, heap, 20);
1252 insn = get_insns ();
1253 barrier_args_size[INSN_UID (insn)] = 0;
1254 VEC_quick_push (rtx, worklist, insn);
1257 while (!VEC_empty (rtx, worklist))
1259 rtx prev, body, first_insn;
1260 HOST_WIDE_INT cur_args_size;
1262 first_insn = insn = VEC_pop (rtx, worklist);
1263 cur_args_size = barrier_args_size[INSN_UID (insn)];
1264 prev = prev_nonnote_insn (insn);
1265 if (prev && BARRIER_P (prev))
1266 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1268 for (; insn; insn = NEXT_INSN (insn))
1270 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1272 if (BARRIER_P (insn))
1277 if (insn == first_insn)
1279 else if (barrier_args_size[INSN_UID (insn)] < 0)
1281 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1286 /* The insns starting with this label have been
1287 already scanned or are in the worklist. */
1288 gcc_assert (barrier_args_size[INSN_UID (insn)]
1294 body = PATTERN (insn);
1295 if (GET_CODE (body) == SEQUENCE)
1297 for (i = 1; i < XVECLEN (body, 0); i++)
1299 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1300 cur_args_size, &next);
1302 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1303 cur_args_size, &next);
1307 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1311 if (VEC_empty (rtx, next))
1314 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1318 VEC_truncate (rtx, next, 0);
1321 VEC_free (rtx, heap, worklist);
1322 VEC_free (rtx, heap, next);
1326 /* Check INSN to see if it looks like a push or a stack adjustment, and
1327 make a note of it if it does. EH uses this information to find out how
1328 much extra space it needs to pop off the stack. */
1331 dwarf2out_stack_adjust (rtx insn, bool after_p)
1333 HOST_WIDE_INT offset;
1337 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1338 with this function. Proper support would require all frame-related
1339 insns to be marked, and to be able to handle saving state around
1340 epilogues textually in the middle of the function. */
1341 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1344 /* If only calls can throw, and we have a frame pointer,
1345 save up adjustments until we see the CALL_INSN. */
1346 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1348 if (CALL_P (insn) && !after_p)
1350 /* Extract the size of the args from the CALL rtx itself. */
1351 insn = PATTERN (insn);
1352 if (GET_CODE (insn) == PARALLEL)
1353 insn = XVECEXP (insn, 0, 0);
1354 if (GET_CODE (insn) == SET)
1355 insn = SET_SRC (insn);
1356 gcc_assert (GET_CODE (insn) == CALL);
1357 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1362 if (CALL_P (insn) && !after_p)
1364 if (!flag_asynchronous_unwind_tables)
1365 dwarf2out_args_size ("", args_size);
1368 else if (BARRIER_P (insn))
1370 /* Don't call compute_barrier_args_size () if the only
1371 BARRIER is at the end of function. */
1372 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1373 compute_barrier_args_size ();
1374 if (barrier_args_size == NULL)
1378 offset = barrier_args_size[INSN_UID (insn)];
1383 offset -= args_size;
1384 #ifndef STACK_GROWS_DOWNWARD
1388 else if (GET_CODE (PATTERN (insn)) == SET)
1389 offset = stack_adjust_offset (PATTERN (insn));
1390 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1391 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1393 /* There may be stack adjustments inside compound insns. Search
1395 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1396 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1397 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1405 label = dwarf2out_cfi_label ();
1406 dwarf2out_args_size_adjust (offset, label);
1409 /* Adjust args_size based on stack adjustment OFFSET. */
1412 dwarf2out_args_size_adjust (HOST_WIDE_INT offset, const char *label)
1414 if (cfa.reg == STACK_POINTER_REGNUM)
1415 cfa.offset += offset;
1417 if (cfa_store.reg == STACK_POINTER_REGNUM)
1418 cfa_store.offset += offset;
1420 #ifndef STACK_GROWS_DOWNWARD
1424 args_size += offset;
1428 def_cfa_1 (label, &cfa);
1429 if (flag_asynchronous_unwind_tables)
1430 dwarf2out_args_size (label, args_size);
1435 /* We delay emitting a register save until either (a) we reach the end
1436 of the prologue or (b) the register is clobbered. This clusters
1437 register saves so that there are fewer pc advances. */
1439 struct queued_reg_save GTY(())
1441 struct queued_reg_save *next;
1443 HOST_WIDE_INT cfa_offset;
1447 static GTY(()) struct queued_reg_save *queued_reg_saves;
1449 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1450 struct reg_saved_in_data GTY(()) {
1455 /* A list of registers saved in other registers.
1456 The list intentionally has a small maximum capacity of 4; if your
1457 port needs more than that, you might consider implementing a
1458 more efficient data structure. */
1459 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1460 static GTY(()) size_t num_regs_saved_in_regs;
1462 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1463 static const char *last_reg_save_label;
1465 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1466 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1469 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1471 struct queued_reg_save *q;
1473 /* Duplicates waste space, but it's also necessary to remove them
1474 for correctness, since the queue gets output in reverse
1476 for (q = queued_reg_saves; q != NULL; q = q->next)
1477 if (REGNO (q->reg) == REGNO (reg))
1482 q = GGC_NEW (struct queued_reg_save);
1483 q->next = queued_reg_saves;
1484 queued_reg_saves = q;
1488 q->cfa_offset = offset;
1489 q->saved_reg = sreg;
1491 last_reg_save_label = label;
1494 /* Output all the entries in QUEUED_REG_SAVES. */
1497 flush_queued_reg_saves (void)
1499 struct queued_reg_save *q;
1501 for (q = queued_reg_saves; q; q = q->next)
1504 unsigned int reg, sreg;
1506 for (i = 0; i < num_regs_saved_in_regs; i++)
1507 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1509 if (q->saved_reg && i == num_regs_saved_in_regs)
1511 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1512 num_regs_saved_in_regs++;
1514 if (i != num_regs_saved_in_regs)
1516 regs_saved_in_regs[i].orig_reg = q->reg;
1517 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1520 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1522 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1524 sreg = INVALID_REGNUM;
1525 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1528 queued_reg_saves = NULL;
1529 last_reg_save_label = NULL;
1532 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1533 location for? Or, does it clobber a register which we've previously
1534 said that some other register is saved in, and for which we now
1535 have a new location for? */
1538 clobbers_queued_reg_save (const_rtx insn)
1540 struct queued_reg_save *q;
1542 for (q = queued_reg_saves; q; q = q->next)
1545 if (modified_in_p (q->reg, insn))
1547 for (i = 0; i < num_regs_saved_in_regs; i++)
1548 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1549 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1556 /* Entry point for saving the first register into the second. */
1559 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1562 unsigned int regno, sregno;
1564 for (i = 0; i < num_regs_saved_in_regs; i++)
1565 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1567 if (i == num_regs_saved_in_regs)
1569 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1570 num_regs_saved_in_regs++;
1572 regs_saved_in_regs[i].orig_reg = reg;
1573 regs_saved_in_regs[i].saved_in_reg = sreg;
1575 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1576 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1577 reg_save (label, regno, sregno, 0);
1580 /* What register, if any, is currently saved in REG? */
1583 reg_saved_in (rtx reg)
1585 unsigned int regn = REGNO (reg);
1587 struct queued_reg_save *q;
1589 for (q = queued_reg_saves; q; q = q->next)
1590 if (q->saved_reg && regn == REGNO (q->saved_reg))
1593 for (i = 0; i < num_regs_saved_in_regs; i++)
1594 if (regs_saved_in_regs[i].saved_in_reg
1595 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1596 return regs_saved_in_regs[i].orig_reg;
1602 /* A temporary register holding an integral value used in adjusting SP
1603 or setting up the store_reg. The "offset" field holds the integer
1604 value, not an offset. */
1605 static dw_cfa_location cfa_temp;
1607 /* Record call frame debugging information for an expression EXPR,
1608 which either sets SP or FP (adjusting how we calculate the frame
1609 address) or saves a register to the stack or another register.
1610 LABEL indicates the address of EXPR.
1612 This function encodes a state machine mapping rtxes to actions on
1613 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1614 users need not read the source code.
1616 The High-Level Picture
1618 Changes in the register we use to calculate the CFA: Currently we
1619 assume that if you copy the CFA register into another register, we
1620 should take the other one as the new CFA register; this seems to
1621 work pretty well. If it's wrong for some target, it's simple
1622 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1624 Changes in the register we use for saving registers to the stack:
1625 This is usually SP, but not always. Again, we deduce that if you
1626 copy SP into another register (and SP is not the CFA register),
1627 then the new register is the one we will be using for register
1628 saves. This also seems to work.
1630 Register saves: There's not much guesswork about this one; if
1631 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1632 register save, and the register used to calculate the destination
1633 had better be the one we think we're using for this purpose.
1634 It's also assumed that a copy from a call-saved register to another
1635 register is saving that register if RTX_FRAME_RELATED_P is set on
1636 that instruction. If the copy is from a call-saved register to
1637 the *same* register, that means that the register is now the same
1638 value as in the caller.
1640 Except: If the register being saved is the CFA register, and the
1641 offset is nonzero, we are saving the CFA, so we assume we have to
1642 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1643 the intent is to save the value of SP from the previous frame.
1645 In addition, if a register has previously been saved to a different
1648 Invariants / Summaries of Rules
1650 cfa current rule for calculating the CFA. It usually
1651 consists of a register and an offset.
1652 cfa_store register used by prologue code to save things to the stack
1653 cfa_store.offset is the offset from the value of
1654 cfa_store.reg to the actual CFA
1655 cfa_temp register holding an integral value. cfa_temp.offset
1656 stores the value, which will be used to adjust the
1657 stack pointer. cfa_temp is also used like cfa_store,
1658 to track stores to the stack via fp or a temp reg.
1660 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1661 with cfa.reg as the first operand changes the cfa.reg and its
1662 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1665 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1666 expression yielding a constant. This sets cfa_temp.reg
1667 and cfa_temp.offset.
1669 Rule 5: Create a new register cfa_store used to save items to the
1672 Rules 10-14: Save a register to the stack. Define offset as the
1673 difference of the original location and cfa_store's
1674 location (or cfa_temp's location if cfa_temp is used).
1676 Rules 16-20: If AND operation happens on sp in prologue, we assume
1677 stack is realigned. We will use a group of DW_OP_XXX
1678 expressions to represent the location of the stored
1679 register instead of CFA+offset.
1683 "{a,b}" indicates a choice of a xor b.
1684 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1687 (set <reg1> <reg2>:cfa.reg)
1688 effects: cfa.reg = <reg1>
1689 cfa.offset unchanged
1690 cfa_temp.reg = <reg1>
1691 cfa_temp.offset = cfa.offset
1694 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1695 {<const_int>,<reg>:cfa_temp.reg}))
1696 effects: cfa.reg = sp if fp used
1697 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1698 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1699 if cfa_store.reg==sp
1702 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1703 effects: cfa.reg = fp
1704 cfa_offset += +/- <const_int>
1707 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1708 constraints: <reg1> != fp
1710 effects: cfa.reg = <reg1>
1711 cfa_temp.reg = <reg1>
1712 cfa_temp.offset = cfa.offset
1715 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1716 constraints: <reg1> != fp
1718 effects: cfa_store.reg = <reg1>
1719 cfa_store.offset = cfa.offset - cfa_temp.offset
1722 (set <reg> <const_int>)
1723 effects: cfa_temp.reg = <reg>
1724 cfa_temp.offset = <const_int>
1727 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1728 effects: cfa_temp.reg = <reg1>
1729 cfa_temp.offset |= <const_int>
1732 (set <reg> (high <exp>))
1736 (set <reg> (lo_sum <exp> <const_int>))
1737 effects: cfa_temp.reg = <reg>
1738 cfa_temp.offset = <const_int>
1741 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1742 effects: cfa_store.offset -= <const_int>
1743 cfa.offset = cfa_store.offset if cfa.reg == sp
1745 cfa.base_offset = -cfa_store.offset
1748 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1749 effects: cfa_store.offset += -/+ mode_size(mem)
1750 cfa.offset = cfa_store.offset if cfa.reg == sp
1752 cfa.base_offset = -cfa_store.offset
1755 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1758 effects: cfa.reg = <reg1>
1759 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1762 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1763 effects: cfa.reg = <reg1>
1764 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1767 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1768 effects: cfa.reg = <reg1>
1769 cfa.base_offset = -cfa_temp.offset
1770 cfa_temp.offset -= mode_size(mem)
1773 (set <reg> {unspec, unspec_volatile})
1774 effects: target-dependent
1777 (set sp (and: sp <const_int>))
1778 constraints: cfa_store.reg == sp
1779 effects: current_fde.stack_realign = 1
1780 cfa_store.offset = 0
1781 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1784 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1785 effects: cfa_store.offset += -/+ mode_size(mem)
1788 (set (mem ({pre_inc, pre_dec} sp)) fp)
1789 constraints: fde->stack_realign == 1
1790 effects: cfa_store.offset = 0
1791 cfa.reg != HARD_FRAME_POINTER_REGNUM
1794 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1795 constraints: fde->stack_realign == 1
1797 && cfa.indirect == 0
1798 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1799 effects: Use DW_CFA_def_cfa_expression to define cfa
1800 cfa.reg == fde->drap_reg
1803 (set reg fde->drap_reg)
1804 constraints: fde->vdrap_reg == INVALID_REGNUM
1805 effects: fde->vdrap_reg = reg.
1806 (set mem fde->drap_reg)
1807 constraints: fde->drap_reg_saved == 1
1811 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1813 rtx src, dest, span;
1814 HOST_WIDE_INT offset;
1817 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1818 the PARALLEL independently. The first element is always processed if
1819 it is a SET. This is for backward compatibility. Other elements
1820 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1821 flag is set in them. */
1822 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1825 int limit = XVECLEN (expr, 0);
1828 /* PARALLELs have strict read-modify-write semantics, so we
1829 ought to evaluate every rvalue before changing any lvalue.
1830 It's cumbersome to do that in general, but there's an
1831 easy approximation that is enough for all current users:
1832 handle register saves before register assignments. */
1833 if (GET_CODE (expr) == PARALLEL)
1834 for (par_index = 0; par_index < limit; par_index++)
1836 elem = XVECEXP (expr, 0, par_index);
1837 if (GET_CODE (elem) == SET
1838 && MEM_P (SET_DEST (elem))
1839 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1840 dwarf2out_frame_debug_expr (elem, label);
1843 for (par_index = 0; par_index < limit; par_index++)
1845 elem = XVECEXP (expr, 0, par_index);
1846 if (GET_CODE (elem) == SET
1847 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1848 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1849 dwarf2out_frame_debug_expr (elem, label);
1850 else if (GET_CODE (elem) == SET
1852 && !RTX_FRAME_RELATED_P (elem))
1854 /* Stack adjustment combining might combine some post-prologue
1855 stack adjustment into a prologue stack adjustment. */
1856 HOST_WIDE_INT offset = stack_adjust_offset (elem);
1859 dwarf2out_args_size_adjust (offset, label);
1865 gcc_assert (GET_CODE (expr) == SET);
1867 src = SET_SRC (expr);
1868 dest = SET_DEST (expr);
1872 rtx rsi = reg_saved_in (src);
1877 fde = current_fde ();
1879 if (GET_CODE (src) == REG
1881 && fde->drap_reg == REGNO (src)
1882 && (fde->drap_reg_saved
1883 || GET_CODE (dest) == REG))
1886 /* If we are saving dynamic realign argument pointer to a
1887 register, the destination is virtual dynamic realign
1888 argument pointer. It may be used to access argument. */
1889 if (GET_CODE (dest) == REG)
1891 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
1892 fde->vdrap_reg = REGNO (dest);
1897 switch (GET_CODE (dest))
1900 switch (GET_CODE (src))
1902 /* Setting FP from SP. */
1904 if (cfa.reg == (unsigned) REGNO (src))
1907 /* Update the CFA rule wrt SP or FP. Make sure src is
1908 relative to the current CFA register.
1910 We used to require that dest be either SP or FP, but the
1911 ARM copies SP to a temporary register, and from there to
1912 FP. So we just rely on the backends to only set
1913 RTX_FRAME_RELATED_P on appropriate insns. */
1914 cfa.reg = REGNO (dest);
1915 cfa_temp.reg = cfa.reg;
1916 cfa_temp.offset = cfa.offset;
1920 /* Saving a register in a register. */
1921 gcc_assert (!fixed_regs [REGNO (dest)]
1922 /* For the SPARC and its register window. */
1923 || (DWARF_FRAME_REGNUM (REGNO (src))
1924 == DWARF_FRAME_RETURN_COLUMN));
1926 /* After stack is aligned, we can only save SP in FP
1927 if drap register is used. In this case, we have
1928 to restore stack pointer with the CFA value and we
1929 don't generate this DWARF information. */
1931 && fde->stack_realign
1932 && REGNO (src) == STACK_POINTER_REGNUM)
1933 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
1934 && fde->drap_reg != INVALID_REGNUM
1935 && cfa.reg != REGNO (src));
1937 queue_reg_save (label, src, dest, 0);
1944 if (dest == stack_pointer_rtx)
1948 switch (GET_CODE (XEXP (src, 1)))
1951 offset = INTVAL (XEXP (src, 1));
1954 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1956 offset = cfa_temp.offset;
1962 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1964 /* Restoring SP from FP in the epilogue. */
1965 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1966 cfa.reg = STACK_POINTER_REGNUM;
1968 else if (GET_CODE (src) == LO_SUM)
1969 /* Assume we've set the source reg of the LO_SUM from sp. */
1972 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1974 if (GET_CODE (src) != MINUS)
1976 if (cfa.reg == STACK_POINTER_REGNUM)
1977 cfa.offset += offset;
1978 if (cfa_store.reg == STACK_POINTER_REGNUM)
1979 cfa_store.offset += offset;
1981 else if (dest == hard_frame_pointer_rtx)
1984 /* Either setting the FP from an offset of the SP,
1985 or adjusting the FP */
1986 gcc_assert (frame_pointer_needed);
1988 gcc_assert (REG_P (XEXP (src, 0))
1989 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1990 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1991 offset = INTVAL (XEXP (src, 1));
1992 if (GET_CODE (src) != MINUS)
1994 cfa.offset += offset;
1995 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1999 gcc_assert (GET_CODE (src) != MINUS);
2002 if (REG_P (XEXP (src, 0))
2003 && REGNO (XEXP (src, 0)) == cfa.reg
2004 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2006 /* Setting a temporary CFA register that will be copied
2007 into the FP later on. */
2008 offset = - INTVAL (XEXP (src, 1));
2009 cfa.offset += offset;
2010 cfa.reg = REGNO (dest);
2011 /* Or used to save regs to the stack. */
2012 cfa_temp.reg = cfa.reg;
2013 cfa_temp.offset = cfa.offset;
2017 else if (REG_P (XEXP (src, 0))
2018 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2019 && XEXP (src, 1) == stack_pointer_rtx)
2021 /* Setting a scratch register that we will use instead
2022 of SP for saving registers to the stack. */
2023 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2024 cfa_store.reg = REGNO (dest);
2025 cfa_store.offset = cfa.offset - cfa_temp.offset;
2029 else if (GET_CODE (src) == LO_SUM
2030 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2032 cfa_temp.reg = REGNO (dest);
2033 cfa_temp.offset = INTVAL (XEXP (src, 1));
2042 cfa_temp.reg = REGNO (dest);
2043 cfa_temp.offset = INTVAL (src);
2048 gcc_assert (REG_P (XEXP (src, 0))
2049 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2050 && GET_CODE (XEXP (src, 1)) == CONST_INT);
2052 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2053 cfa_temp.reg = REGNO (dest);
2054 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2057 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2058 which will fill in all of the bits. */
2065 case UNSPEC_VOLATILE:
2066 gcc_assert (targetm.dwarf_handle_frame_unspec);
2067 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2072 /* If this AND operation happens on stack pointer in prologue,
2073 we assume the stack is realigned and we extract the
2075 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2077 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2078 fde->stack_realign = 1;
2079 fde->stack_realignment = INTVAL (XEXP (src, 1));
2080 cfa_store.offset = 0;
2082 if (cfa.reg != STACK_POINTER_REGNUM
2083 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2084 fde->drap_reg = cfa.reg;
2092 def_cfa_1 (label, &cfa);
2097 /* Saving a register to the stack. Make sure dest is relative to the
2099 switch (GET_CODE (XEXP (dest, 0)))
2104 /* We can't handle variable size modifications. */
2105 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2107 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2109 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2110 && cfa_store.reg == STACK_POINTER_REGNUM);
2112 cfa_store.offset += offset;
2113 if (cfa.reg == STACK_POINTER_REGNUM)
2114 cfa.offset = cfa_store.offset;
2116 offset = -cfa_store.offset;
2122 offset = GET_MODE_SIZE (GET_MODE (dest));
2123 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2126 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2127 == STACK_POINTER_REGNUM)
2128 && cfa_store.reg == STACK_POINTER_REGNUM);
2130 cfa_store.offset += offset;
2132 /* Rule 18: If stack is aligned, we will use FP as a
2133 reference to represent the address of the stored
2136 && fde->stack_realign
2137 && src == hard_frame_pointer_rtx)
2139 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2140 cfa_store.offset = 0;
2143 if (cfa.reg == STACK_POINTER_REGNUM)
2144 cfa.offset = cfa_store.offset;
2146 offset = -cfa_store.offset;
2150 /* With an offset. */
2157 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
2158 && REG_P (XEXP (XEXP (dest, 0), 0)));
2159 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2160 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2163 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2165 if (cfa_store.reg == (unsigned) regno)
2166 offset -= cfa_store.offset;
2169 gcc_assert (cfa_temp.reg == (unsigned) regno);
2170 offset -= cfa_temp.offset;
2176 /* Without an offset. */
2179 int regno = REGNO (XEXP (dest, 0));
2181 if (cfa_store.reg == (unsigned) regno)
2182 offset = -cfa_store.offset;
2185 gcc_assert (cfa_temp.reg == (unsigned) regno);
2186 offset = -cfa_temp.offset;
2193 gcc_assert (cfa_temp.reg
2194 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2195 offset = -cfa_temp.offset;
2196 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2204 /* If the source operand of this MEM operation is not a
2205 register, basically the source is return address. Here
2206 we only care how much stack grew and we don't save it. */
2210 if (REGNO (src) != STACK_POINTER_REGNUM
2211 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2212 && (unsigned) REGNO (src) == cfa.reg)
2214 /* We're storing the current CFA reg into the stack. */
2216 if (cfa.offset == 0)
2219 /* If stack is aligned, putting CFA reg into stack means
2220 we can no longer use reg + offset to represent CFA.
2221 Here we use DW_CFA_def_cfa_expression instead. The
2222 result of this expression equals to the original CFA
2225 && fde->stack_realign
2226 && cfa.indirect == 0
2227 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2229 dw_cfa_location cfa_exp;
2231 gcc_assert (fde->drap_reg == cfa.reg);
2233 cfa_exp.indirect = 1;
2234 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2235 cfa_exp.base_offset = offset;
2238 fde->drap_reg_saved = 1;
2240 def_cfa_1 (label, &cfa_exp);
2244 /* If the source register is exactly the CFA, assume
2245 we're saving SP like any other register; this happens
2247 def_cfa_1 (label, &cfa);
2248 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2253 /* Otherwise, we'll need to look in the stack to
2254 calculate the CFA. */
2255 rtx x = XEXP (dest, 0);
2259 gcc_assert (REG_P (x));
2261 cfa.reg = REGNO (x);
2262 cfa.base_offset = offset;
2264 def_cfa_1 (label, &cfa);
2269 def_cfa_1 (label, &cfa);
2271 span = targetm.dwarf_register_span (src);
2274 queue_reg_save (label, src, NULL_RTX, offset);
2277 /* We have a PARALLEL describing where the contents of SRC
2278 live. Queue register saves for each piece of the
2282 HOST_WIDE_INT span_offset = offset;
2284 gcc_assert (GET_CODE (span) == PARALLEL);
2286 limit = XVECLEN (span, 0);
2287 for (par_index = 0; par_index < limit; par_index++)
2289 rtx elem = XVECEXP (span, 0, par_index);
2291 queue_reg_save (label, elem, NULL_RTX, span_offset);
2292 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2303 /* Record call frame debugging information for INSN, which either
2304 sets SP or FP (adjusting how we calculate the frame address) or saves a
2305 register to the stack. If INSN is NULL_RTX, initialize our state.
2307 If AFTER_P is false, we're being called before the insn is emitted,
2308 otherwise after. Call instructions get invoked twice. */
2311 dwarf2out_frame_debug (rtx insn, bool after_p)
2316 if (insn == NULL_RTX)
2320 /* Flush any queued register saves. */
2321 flush_queued_reg_saves ();
2323 /* Set up state for generating call frame debug info. */
2326 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2328 cfa.reg = STACK_POINTER_REGNUM;
2331 cfa_temp.offset = 0;
2333 for (i = 0; i < num_regs_saved_in_regs; i++)
2335 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2336 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2338 num_regs_saved_in_regs = 0;
2340 if (barrier_args_size)
2342 XDELETEVEC (barrier_args_size);
2343 barrier_args_size = NULL;
2348 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2349 flush_queued_reg_saves ();
2351 if (! RTX_FRAME_RELATED_P (insn))
2353 if (!ACCUMULATE_OUTGOING_ARGS)
2354 dwarf2out_stack_adjust (insn, after_p);
2358 label = dwarf2out_cfi_label ();
2359 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
2361 insn = XEXP (src, 0);
2363 insn = PATTERN (insn);
2365 dwarf2out_frame_debug_expr (insn, label);
2370 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2371 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2372 (enum dwarf_call_frame_info cfi);
2374 static enum dw_cfi_oprnd_type
2375 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2380 case DW_CFA_GNU_window_save:
2381 return dw_cfi_oprnd_unused;
2383 case DW_CFA_set_loc:
2384 case DW_CFA_advance_loc1:
2385 case DW_CFA_advance_loc2:
2386 case DW_CFA_advance_loc4:
2387 case DW_CFA_MIPS_advance_loc8:
2388 return dw_cfi_oprnd_addr;
2391 case DW_CFA_offset_extended:
2392 case DW_CFA_def_cfa:
2393 case DW_CFA_offset_extended_sf:
2394 case DW_CFA_def_cfa_sf:
2395 case DW_CFA_restore_extended:
2396 case DW_CFA_undefined:
2397 case DW_CFA_same_value:
2398 case DW_CFA_def_cfa_register:
2399 case DW_CFA_register:
2400 return dw_cfi_oprnd_reg_num;
2402 case DW_CFA_def_cfa_offset:
2403 case DW_CFA_GNU_args_size:
2404 case DW_CFA_def_cfa_offset_sf:
2405 return dw_cfi_oprnd_offset;
2407 case DW_CFA_def_cfa_expression:
2408 case DW_CFA_expression:
2409 return dw_cfi_oprnd_loc;
2416 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2417 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2418 (enum dwarf_call_frame_info cfi);
2420 static enum dw_cfi_oprnd_type
2421 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2425 case DW_CFA_def_cfa:
2426 case DW_CFA_def_cfa_sf:
2428 case DW_CFA_offset_extended_sf:
2429 case DW_CFA_offset_extended:
2430 return dw_cfi_oprnd_offset;
2432 case DW_CFA_register:
2433 return dw_cfi_oprnd_reg_num;
2436 return dw_cfi_oprnd_unused;
2440 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2442 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2443 switch to the data section instead, and write out a synthetic label
2447 switch_to_eh_frame_section (void)
2451 #ifdef EH_FRAME_SECTION_NAME
2452 if (eh_frame_section == 0)
2456 if (EH_TABLES_CAN_BE_READ_ONLY)
2462 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2464 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2466 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2468 flags = ((! flag_pic
2469 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2470 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2471 && (per_encoding & 0x70) != DW_EH_PE_absptr
2472 && (per_encoding & 0x70) != DW_EH_PE_aligned
2473 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2474 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2475 ? 0 : SECTION_WRITE);
2478 flags = SECTION_WRITE;
2479 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2483 if (eh_frame_section)
2484 switch_to_section (eh_frame_section);
2487 /* We have no special eh_frame section. Put the information in
2488 the data section and emit special labels to guide collect2. */
2489 switch_to_section (data_section);
2490 label = get_file_function_name ("F");
2491 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2492 targetm.asm_out.globalize_label (asm_out_file,
2493 IDENTIFIER_POINTER (label));
2494 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2498 /* Output a Call Frame Information opcode and its operand(s). */
2501 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2504 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2505 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2506 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2507 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2508 ((unsigned HOST_WIDE_INT)
2509 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2510 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2512 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2513 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2514 "DW_CFA_offset, column 0x%lx", r);
2515 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2517 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2519 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2520 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2521 "DW_CFA_restore, column 0x%lx", r);
2525 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2526 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2528 switch (cfi->dw_cfi_opc)
2530 case DW_CFA_set_loc:
2532 dw2_asm_output_encoded_addr_rtx (
2533 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2534 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2537 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2538 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2539 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2542 case DW_CFA_advance_loc1:
2543 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2544 fde->dw_fde_current_label, NULL);
2545 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2548 case DW_CFA_advance_loc2:
2549 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2550 fde->dw_fde_current_label, NULL);
2551 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2554 case DW_CFA_advance_loc4:
2555 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2556 fde->dw_fde_current_label, NULL);
2557 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2560 case DW_CFA_MIPS_advance_loc8:
2561 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2562 fde->dw_fde_current_label, NULL);
2563 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2566 case DW_CFA_offset_extended:
2567 case DW_CFA_def_cfa:
2568 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2569 dw2_asm_output_data_uleb128 (r, NULL);
2570 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2573 case DW_CFA_offset_extended_sf:
2574 case DW_CFA_def_cfa_sf:
2575 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2576 dw2_asm_output_data_uleb128 (r, NULL);
2577 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2580 case DW_CFA_restore_extended:
2581 case DW_CFA_undefined:
2582 case DW_CFA_same_value:
2583 case DW_CFA_def_cfa_register:
2584 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2585 dw2_asm_output_data_uleb128 (r, NULL);
2588 case DW_CFA_register:
2589 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2590 dw2_asm_output_data_uleb128 (r, NULL);
2591 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2592 dw2_asm_output_data_uleb128 (r, NULL);
2595 case DW_CFA_def_cfa_offset:
2596 case DW_CFA_GNU_args_size:
2597 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2600 case DW_CFA_def_cfa_offset_sf:
2601 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2604 case DW_CFA_GNU_window_save:
2607 case DW_CFA_def_cfa_expression:
2608 case DW_CFA_expression:
2609 output_cfa_loc (cfi);
2612 case DW_CFA_GNU_negative_offset_extended:
2613 /* Obsoleted by DW_CFA_offset_extended_sf. */
2622 /* Output the call frame information used to record information
2623 that relates to calculating the frame pointer, and records the
2624 location of saved registers. */
2627 output_call_frame_info (int for_eh)
2632 char l1[20], l2[20], section_start_label[20];
2633 bool any_lsda_needed = false;
2634 char augmentation[6];
2635 int augmentation_size;
2636 int fde_encoding = DW_EH_PE_absptr;
2637 int per_encoding = DW_EH_PE_absptr;
2638 int lsda_encoding = DW_EH_PE_absptr;
2641 /* Don't emit a CIE if there won't be any FDEs. */
2642 if (fde_table_in_use == 0)
2645 /* If we make FDEs linkonce, we may have to emit an empty label for
2646 an FDE that wouldn't otherwise be emitted. We want to avoid
2647 having an FDE kept around when the function it refers to is
2648 discarded. Example where this matters: a primary function
2649 template in C++ requires EH information, but an explicit
2650 specialization doesn't. */
2651 if (TARGET_USES_WEAK_UNWIND_INFO
2652 && ! flag_asynchronous_unwind_tables
2655 for (i = 0; i < fde_table_in_use; i++)
2656 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2657 && !fde_table[i].uses_eh_lsda
2658 && ! DECL_WEAK (fde_table[i].decl))
2659 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2660 for_eh, /* empty */ 1);
2662 /* If we don't have any functions we'll want to unwind out of, don't
2663 emit any EH unwind information. Note that if exceptions aren't
2664 enabled, we won't have collected nothrow information, and if we
2665 asked for asynchronous tables, we always want this info. */
2668 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2670 for (i = 0; i < fde_table_in_use; i++)
2671 if (fde_table[i].uses_eh_lsda)
2672 any_eh_needed = any_lsda_needed = true;
2673 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2674 any_eh_needed = true;
2675 else if (! fde_table[i].nothrow
2676 && ! fde_table[i].all_throwers_are_sibcalls)
2677 any_eh_needed = true;
2679 if (! any_eh_needed)
2683 /* We're going to be generating comments, so turn on app. */
2688 switch_to_eh_frame_section ();
2691 if (!debug_frame_section)
2692 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2693 SECTION_DEBUG, NULL);
2694 switch_to_section (debug_frame_section);
2697 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2698 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2700 /* Output the CIE. */
2701 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2702 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2703 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2704 dw2_asm_output_data (4, 0xffffffff,
2705 "Initial length escape value indicating 64-bit DWARF extension");
2706 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2707 "Length of Common Information Entry");
2708 ASM_OUTPUT_LABEL (asm_out_file, l1);
2710 /* Now that the CIE pointer is PC-relative for EH,
2711 use 0 to identify the CIE. */
2712 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2713 (for_eh ? 0 : DWARF_CIE_ID),
2714 "CIE Identifier Tag");
2716 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2718 augmentation[0] = 0;
2719 augmentation_size = 0;
2725 z Indicates that a uleb128 is present to size the
2726 augmentation section.
2727 L Indicates the encoding (and thus presence) of
2728 an LSDA pointer in the FDE augmentation.
2729 R Indicates a non-default pointer encoding for
2731 P Indicates the presence of an encoding + language
2732 personality routine in the CIE augmentation. */
2734 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2735 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2736 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2738 p = augmentation + 1;
2739 if (eh_personality_libfunc)
2742 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2743 assemble_external_libcall (eh_personality_libfunc);
2745 if (any_lsda_needed)
2748 augmentation_size += 1;
2750 if (fde_encoding != DW_EH_PE_absptr)
2753 augmentation_size += 1;
2755 if (p > augmentation + 1)
2757 augmentation[0] = 'z';
2761 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2762 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2764 int offset = ( 4 /* Length */
2766 + 1 /* CIE version */
2767 + strlen (augmentation) + 1 /* Augmentation */
2768 + size_of_uleb128 (1) /* Code alignment */
2769 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2771 + 1 /* Augmentation size */
2772 + 1 /* Personality encoding */ );
2773 int pad = -offset & (PTR_SIZE - 1);
2775 augmentation_size += pad;
2777 /* Augmentations should be small, so there's scarce need to
2778 iterate for a solution. Die if we exceed one uleb128 byte. */
2779 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2783 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2784 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2785 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2786 "CIE Data Alignment Factor");
2788 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2789 if (DW_CIE_VERSION == 1)
2790 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2792 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2794 if (augmentation[0])
2796 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2797 if (eh_personality_libfunc)
2799 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2800 eh_data_format_name (per_encoding));
2801 dw2_asm_output_encoded_addr_rtx (per_encoding,
2802 eh_personality_libfunc,
2806 if (any_lsda_needed)
2807 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2808 eh_data_format_name (lsda_encoding));
2810 if (fde_encoding != DW_EH_PE_absptr)
2811 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2812 eh_data_format_name (fde_encoding));
2815 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2816 output_cfi (cfi, NULL, for_eh);
2818 /* Pad the CIE out to an address sized boundary. */
2819 ASM_OUTPUT_ALIGN (asm_out_file,
2820 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2821 ASM_OUTPUT_LABEL (asm_out_file, l2);
2823 /* Loop through all of the FDE's. */
2824 for (i = 0; i < fde_table_in_use; i++)
2826 fde = &fde_table[i];
2828 /* Don't emit EH unwind info for leaf functions that don't need it. */
2829 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2830 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2831 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2832 && !fde->uses_eh_lsda)
2835 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2836 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2837 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2838 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2839 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2840 dw2_asm_output_data (4, 0xffffffff,
2841 "Initial length escape value indicating 64-bit DWARF extension");
2842 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2844 ASM_OUTPUT_LABEL (asm_out_file, l1);
2847 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2849 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2850 debug_frame_section, "FDE CIE offset");
2854 if (fde->dw_fde_switched_sections)
2856 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2857 fde->dw_fde_unlikely_section_label);
2858 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2859 fde->dw_fde_hot_section_label);
2860 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2861 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2862 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2863 "FDE initial location");
2864 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2865 fde->dw_fde_hot_section_end_label,
2866 fde->dw_fde_hot_section_label,
2867 "FDE address range");
2868 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2869 "FDE initial location");
2870 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2871 fde->dw_fde_unlikely_section_end_label,
2872 fde->dw_fde_unlikely_section_label,
2873 "FDE address range");
2877 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2878 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2879 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2882 "FDE initial location");
2883 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2884 fde->dw_fde_end, fde->dw_fde_begin,
2885 "FDE address range");
2890 if (fde->dw_fde_switched_sections)
2892 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2893 fde->dw_fde_hot_section_label,
2894 "FDE initial location");
2895 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2896 fde->dw_fde_hot_section_end_label,
2897 fde->dw_fde_hot_section_label,
2898 "FDE address range");
2899 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2900 fde->dw_fde_unlikely_section_label,
2901 "FDE initial location");
2902 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2903 fde->dw_fde_unlikely_section_end_label,
2904 fde->dw_fde_unlikely_section_label,
2905 "FDE address range");
2909 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2910 "FDE initial location");
2911 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2912 fde->dw_fde_end, fde->dw_fde_begin,
2913 "FDE address range");
2917 if (augmentation[0])
2919 if (any_lsda_needed)
2921 int size = size_of_encoded_value (lsda_encoding);
2923 if (lsda_encoding == DW_EH_PE_aligned)
2925 int offset = ( 4 /* Length */
2926 + 4 /* CIE offset */
2927 + 2 * size_of_encoded_value (fde_encoding)
2928 + 1 /* Augmentation size */ );
2929 int pad = -offset & (PTR_SIZE - 1);
2932 gcc_assert (size_of_uleb128 (size) == 1);
2935 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2937 if (fde->uses_eh_lsda)
2939 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2940 fde->funcdef_number);
2941 dw2_asm_output_encoded_addr_rtx (
2942 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2943 false, "Language Specific Data Area");
2947 if (lsda_encoding == DW_EH_PE_aligned)
2948 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2950 (size_of_encoded_value (lsda_encoding), 0,
2951 "Language Specific Data Area (none)");
2955 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2958 /* Loop through the Call Frame Instructions associated with
2960 fde->dw_fde_current_label = fde->dw_fde_begin;
2961 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2962 output_cfi (cfi, fde, for_eh);
2964 /* Pad the FDE out to an address sized boundary. */
2965 ASM_OUTPUT_ALIGN (asm_out_file,
2966 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2967 ASM_OUTPUT_LABEL (asm_out_file, l2);
2970 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2971 dw2_asm_output_data (4, 0, "End of Table");
2972 #ifdef MIPS_DEBUGGING_INFO
2973 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2974 get a value of 0. Putting .align 0 after the label fixes it. */
2975 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2978 /* Turn off app to make assembly quicker. */
2983 /* Output a marker (i.e. a label) for the beginning of a function, before
2987 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2988 const char *file ATTRIBUTE_UNUSED)
2990 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2994 current_function_func_begin_label = NULL;
2996 #ifdef TARGET_UNWIND_INFO
2997 /* ??? current_function_func_begin_label is also used by except.c
2998 for call-site information. We must emit this label if it might
3000 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
3001 && ! dwarf2out_do_frame ())
3004 if (! dwarf2out_do_frame ())
3008 switch_to_section (function_section (current_function_decl));
3009 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
3010 current_function_funcdef_no);
3011 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
3012 current_function_funcdef_no);
3013 dup_label = xstrdup (label);
3014 current_function_func_begin_label = dup_label;
3016 #ifdef TARGET_UNWIND_INFO
3017 /* We can elide the fde allocation if we're not emitting debug info. */
3018 if (! dwarf2out_do_frame ())
3022 /* Expand the fde table if necessary. */
3023 if (fde_table_in_use == fde_table_allocated)
3025 fde_table_allocated += FDE_TABLE_INCREMENT;
3026 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
3027 memset (fde_table + fde_table_in_use, 0,
3028 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
3031 /* Record the FDE associated with this function. */
3032 current_funcdef_fde = fde_table_in_use;
3034 /* Add the new FDE at the end of the fde_table. */
3035 fde = &fde_table[fde_table_in_use++];
3036 fde->decl = current_function_decl;
3037 fde->dw_fde_begin = dup_label;
3038 fde->dw_fde_current_label = dup_label;
3039 fde->dw_fde_hot_section_label = NULL;
3040 fde->dw_fde_hot_section_end_label = NULL;
3041 fde->dw_fde_unlikely_section_label = NULL;
3042 fde->dw_fde_unlikely_section_end_label = NULL;
3043 fde->dw_fde_switched_sections = false;
3044 fde->dw_fde_end = NULL;
3045 fde->dw_fde_cfi = NULL;
3046 fde->funcdef_number = current_function_funcdef_no;
3047 fde->nothrow = TREE_NOTHROW (current_function_decl);
3048 fde->uses_eh_lsda = crtl->uses_eh_lsda;
3049 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
3050 fde->drap_reg = INVALID_REGNUM;
3051 fde->vdrap_reg = INVALID_REGNUM;
3053 args_size = old_args_size = 0;
3055 /* We only want to output line number information for the genuine dwarf2
3056 prologue case, not the eh frame case. */
3057 #ifdef DWARF2_DEBUGGING_INFO
3059 dwarf2out_source_line (line, file);
3063 /* Output a marker (i.e. a label) for the absolute end of the generated code
3064 for a function definition. This gets called *after* the epilogue code has
3068 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
3069 const char *file ATTRIBUTE_UNUSED)
3072 char label[MAX_ARTIFICIAL_LABEL_BYTES];
3074 /* Output a label to mark the endpoint of the code generated for this
3076 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
3077 current_function_funcdef_no);
3078 ASM_OUTPUT_LABEL (asm_out_file, label);
3079 fde = current_fde ();
3080 gcc_assert (fde != NULL);
3081 fde->dw_fde_end = xstrdup (label);
3085 dwarf2out_frame_init (void)
3087 /* Allocate the initial hunk of the fde_table. */
3088 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
3089 fde_table_allocated = FDE_TABLE_INCREMENT;
3090 fde_table_in_use = 0;
3092 /* Generate the CFA instructions common to all FDE's. Do it now for the
3093 sake of lookup_cfa. */
3095 /* On entry, the Canonical Frame Address is at SP. */
3096 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
3098 #ifdef DWARF2_UNWIND_INFO
3099 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
3100 initial_return_save (INCOMING_RETURN_ADDR_RTX);
3105 dwarf2out_frame_finish (void)
3107 /* Output call frame information. */
3108 if (DWARF2_FRAME_INFO)
3109 output_call_frame_info (0);
3111 #ifndef TARGET_UNWIND_INFO
3112 /* Output another copy for the unwinder. */
3113 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
3114 output_call_frame_info (1);
3118 /* Note that the current function section is being used for code. */
3121 dwarf2out_note_section_used (void)
3123 section *sec = current_function_section ();
3124 if (sec == text_section)
3125 text_section_used = true;
3126 else if (sec == cold_text_section)
3127 cold_text_section_used = true;
3131 dwarf2out_switch_text_section (void)
3133 dw_fde_ref fde = current_fde ();
3135 gcc_assert (cfun && fde);
3137 fde->dw_fde_switched_sections = true;
3138 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
3139 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
3140 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
3141 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
3142 have_multiple_function_sections = true;
3144 /* Reset the current label on switching text sections, so that we
3145 don't attempt to advance_loc4 between labels in different sections. */
3146 fde->dw_fde_current_label = NULL;
3148 /* There is no need to mark used sections when not debugging. */
3149 if (cold_text_section != NULL)
3150 dwarf2out_note_section_used ();
3154 /* And now, the subset of the debugging information support code necessary
3155 for emitting location expressions. */
3157 /* Data about a single source file. */
3158 struct dwarf_file_data GTY(())
3160 const char * filename;
3164 /* We need some way to distinguish DW_OP_addr with a direct symbol
3165 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3166 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3169 typedef struct dw_val_struct *dw_val_ref;
3170 typedef struct die_struct *dw_die_ref;
3171 typedef const struct die_struct *const_dw_die_ref;
3172 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
3173 typedef struct dw_loc_list_struct *dw_loc_list_ref;
3175 /* Each DIE may have a series of attribute/value pairs. Values
3176 can take on several forms. The forms that are used in this
3177 implementation are listed below. */
3182 dw_val_class_offset,
3184 dw_val_class_loc_list,
3185 dw_val_class_range_list,
3187 dw_val_class_unsigned_const,
3188 dw_val_class_long_long,
3191 dw_val_class_die_ref,
3192 dw_val_class_fde_ref,
3193 dw_val_class_lbl_id,
3194 dw_val_class_lineptr,
3196 dw_val_class_macptr,
3200 /* Describe a double word constant value. */
3201 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3203 typedef struct dw_long_long_struct GTY(())
3210 /* Describe a floating point constant value, or a vector constant value. */
3212 typedef struct dw_vec_struct GTY(())
3214 unsigned char * GTY((length ("%h.length"))) array;
3220 /* The dw_val_node describes an attribute's value, as it is
3221 represented internally. */
3223 typedef struct dw_val_struct GTY(())
3225 enum dw_val_class val_class;
3226 union dw_val_struct_union
3228 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
3229 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
3230 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
3231 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
3232 HOST_WIDE_INT GTY ((default)) val_int;
3233 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
3234 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
3235 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
3236 struct dw_val_die_union
3240 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
3241 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
3242 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
3243 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
3244 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
3245 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
3247 GTY ((desc ("%1.val_class"))) v;
3251 /* Locations in memory are described using a sequence of stack machine
3254 typedef struct dw_loc_descr_struct GTY(())
3256 dw_loc_descr_ref dw_loc_next;
3257 enum dwarf_location_atom dw_loc_opc;
3258 dw_val_node dw_loc_oprnd1;
3259 dw_val_node dw_loc_oprnd2;
3264 /* Location lists are ranges + location descriptions for that range,
3265 so you can track variables that are in different places over
3266 their entire life. */
3267 typedef struct dw_loc_list_struct GTY(())
3269 dw_loc_list_ref dw_loc_next;
3270 const char *begin; /* Label for begin address of range */
3271 const char *end; /* Label for end address of range */
3272 char *ll_symbol; /* Label for beginning of location list.
3273 Only on head of list */
3274 const char *section; /* Section this loclist is relative to */
3275 dw_loc_descr_ref expr;
3278 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3280 static const char *dwarf_stack_op_name (unsigned);
3281 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
3282 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3283 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3284 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
3285 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
3286 static unsigned long size_of_locs (dw_loc_descr_ref);
3287 static void output_loc_operands (dw_loc_descr_ref);
3288 static void output_loc_sequence (dw_loc_descr_ref);
3290 /* Convert a DWARF stack opcode into its string name. */
3293 dwarf_stack_op_name (unsigned int op)
3298 case INTERNAL_DW_OP_tls_addr:
3299 return "DW_OP_addr";
3301 return "DW_OP_deref";
3303 return "DW_OP_const1u";
3305 return "DW_OP_const1s";
3307 return "DW_OP_const2u";
3309 return "DW_OP_const2s";
3311 return "DW_OP_const4u";
3313 return "DW_OP_const4s";
3315 return "DW_OP_const8u";
3317 return "DW_OP_const8s";
3319 return "DW_OP_constu";
3321 return "DW_OP_consts";
3325 return "DW_OP_drop";
3327 return "DW_OP_over";
3329 return "DW_OP_pick";
3331 return "DW_OP_swap";
3335 return "DW_OP_xderef";
3343 return "DW_OP_minus";
3355 return "DW_OP_plus";
3356 case DW_OP_plus_uconst:
3357 return "DW_OP_plus_uconst";
3363 return "DW_OP_shra";
3381 return "DW_OP_skip";
3383 return "DW_OP_lit0";
3385 return "DW_OP_lit1";
3387 return "DW_OP_lit2";
3389 return "DW_OP_lit3";
3391 return "DW_OP_lit4";
3393 return "DW_OP_lit5";
3395 return "DW_OP_lit6";
3397 return "DW_OP_lit7";
3399 return "DW_OP_lit8";
3401 return "DW_OP_lit9";
3403 return "DW_OP_lit10";
3405 return "DW_OP_lit11";
3407 return "DW_OP_lit12";
3409 return "DW_OP_lit13";
3411 return "DW_OP_lit14";
3413 return "DW_OP_lit15";
3415 return "DW_OP_lit16";
3417 return "DW_OP_lit17";
3419 return "DW_OP_lit18";
3421 return "DW_OP_lit19";
3423 return "DW_OP_lit20";
3425 return "DW_OP_lit21";
3427 return "DW_OP_lit22";
3429 return "DW_OP_lit23";
3431 return "DW_OP_lit24";
3433 return "DW_OP_lit25";
3435 return "DW_OP_lit26";
3437 return "DW_OP_lit27";
3439 return "DW_OP_lit28";
3441 return "DW_OP_lit29";
3443 return "DW_OP_lit30";
3445 return "DW_OP_lit31";
3447 return "DW_OP_reg0";
3449 return "DW_OP_reg1";
3451 return "DW_OP_reg2";
3453 return "DW_OP_reg3";
3455 return "DW_OP_reg4";
3457 return "DW_OP_reg5";
3459 return "DW_OP_reg6";
3461 return "DW_OP_reg7";
3463 return "DW_OP_reg8";
3465 return "DW_OP_reg9";
3467 return "DW_OP_reg10";
3469 return "DW_OP_reg11";
3471 return "DW_OP_reg12";
3473 return "DW_OP_reg13";
3475 return "DW_OP_reg14";
3477 return "DW_OP_reg15";
3479 return "DW_OP_reg16";
3481 return "DW_OP_reg17";
3483 return "DW_OP_reg18";
3485 return "DW_OP_reg19";
3487 return "DW_OP_reg20";
3489 return "DW_OP_reg21";
3491 return "DW_OP_reg22";
3493 return "DW_OP_reg23";
3495 return "DW_OP_reg24";
3497 return "DW_OP_reg25";
3499 return "DW_OP_reg26";
3501 return "DW_OP_reg27";
3503 return "DW_OP_reg28";
3505 return "DW_OP_reg29";
3507 return "DW_OP_reg30";
3509 return "DW_OP_reg31";
3511 return "DW_OP_breg0";
3513 return "DW_OP_breg1";
3515 return "DW_OP_breg2";
3517 return "DW_OP_breg3";
3519 return "DW_OP_breg4";
3521 return "DW_OP_breg5";
3523 return "DW_OP_breg6";
3525 return "DW_OP_breg7";
3527 return "DW_OP_breg8";
3529 return "DW_OP_breg9";
3531 return "DW_OP_breg10";
3533 return "DW_OP_breg11";
3535 return "DW_OP_breg12";
3537 return "DW_OP_breg13";
3539 return "DW_OP_breg14";
3541 return "DW_OP_breg15";
3543 return "DW_OP_breg16";
3545 return "DW_OP_breg17";
3547 return "DW_OP_breg18";
3549 return "DW_OP_breg19";
3551 return "DW_OP_breg20";
3553 return "DW_OP_breg21";
3555 return "DW_OP_breg22";
3557 return "DW_OP_breg23";
3559 return "DW_OP_breg24";
3561 return "DW_OP_breg25";
3563 return "DW_OP_breg26";
3565 return "DW_OP_breg27";
3567 return "DW_OP_breg28";
3569 return "DW_OP_breg29";
3571 return "DW_OP_breg30";
3573 return "DW_OP_breg31";
3575 return "DW_OP_regx";
3577 return "DW_OP_fbreg";
3579 return "DW_OP_bregx";
3581 return "DW_OP_piece";
3582 case DW_OP_deref_size:
3583 return "DW_OP_deref_size";
3584 case DW_OP_xderef_size:
3585 return "DW_OP_xderef_size";
3588 case DW_OP_push_object_address:
3589 return "DW_OP_push_object_address";
3591 return "DW_OP_call2";
3593 return "DW_OP_call4";
3594 case DW_OP_call_ref:
3595 return "DW_OP_call_ref";
3596 case DW_OP_GNU_push_tls_address:
3597 return "DW_OP_GNU_push_tls_address";
3598 case DW_OP_GNU_uninit:
3599 return "DW_OP_GNU_uninit";
3601 return "OP_<unknown>";
3605 /* Return a pointer to a newly allocated location description. Location
3606 descriptions are simple expression terms that can be strung
3607 together to form more complicated location (address) descriptions. */
3609 static inline dw_loc_descr_ref
3610 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3611 unsigned HOST_WIDE_INT oprnd2)
3613 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3615 descr->dw_loc_opc = op;
3616 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3617 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3618 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3619 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3624 /* Add a location description term to a location description expression. */
3627 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3629 dw_loc_descr_ref *d;
3631 /* Find the end of the chain. */
3632 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3638 /* Return the size of a location descriptor. */
3640 static unsigned long
3641 size_of_loc_descr (dw_loc_descr_ref loc)
3643 unsigned long size = 1;
3645 switch (loc->dw_loc_opc)
3648 case INTERNAL_DW_OP_tls_addr:
3649 size += DWARF2_ADDR_SIZE;
3668 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3671 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3676 case DW_OP_plus_uconst:
3677 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3715 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3718 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3721 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3724 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3725 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3728 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3730 case DW_OP_deref_size:
3731 case DW_OP_xderef_size:
3740 case DW_OP_call_ref:
3741 size += DWARF2_ADDR_SIZE;
3750 /* Return the size of a series of location descriptors. */
3752 static unsigned long
3753 size_of_locs (dw_loc_descr_ref loc)
3758 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3759 field, to avoid writing to a PCH file. */
3760 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3762 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3764 size += size_of_loc_descr (l);
3769 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3771 l->dw_loc_addr = size;
3772 size += size_of_loc_descr (l);
3778 /* Output location description stack opcode's operands (if any). */
3781 output_loc_operands (dw_loc_descr_ref loc)
3783 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3784 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3786 switch (loc->dw_loc_opc)
3788 #ifdef DWARF2_DEBUGGING_INFO
3790 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3794 dw2_asm_output_data (2, val1->v.val_int, NULL);
3798 dw2_asm_output_data (4, val1->v.val_int, NULL);
3802 gcc_assert (HOST_BITS_PER_LONG >= 64);
3803 dw2_asm_output_data (8, val1->v.val_int, NULL);
3810 gcc_assert (val1->val_class == dw_val_class_loc);
3811 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3813 dw2_asm_output_data (2, offset, NULL);
3826 /* We currently don't make any attempt to make sure these are
3827 aligned properly like we do for the main unwind info, so
3828 don't support emitting things larger than a byte if we're
3829 only doing unwinding. */
3834 dw2_asm_output_data (1, val1->v.val_int, NULL);
3837 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3840 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3843 dw2_asm_output_data (1, val1->v.val_int, NULL);
3845 case DW_OP_plus_uconst:
3846 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3880 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3883 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3886 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3889 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3890 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3893 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3895 case DW_OP_deref_size:
3896 case DW_OP_xderef_size:
3897 dw2_asm_output_data (1, val1->v.val_int, NULL);
3900 case INTERNAL_DW_OP_tls_addr:
3901 if (targetm.asm_out.output_dwarf_dtprel)
3903 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3906 fputc ('\n', asm_out_file);
3913 /* Other codes have no operands. */
3918 /* Output a sequence of location operations. */
3921 output_loc_sequence (dw_loc_descr_ref loc)
3923 for (; loc != NULL; loc = loc->dw_loc_next)
3925 /* Output the opcode. */
3926 dw2_asm_output_data (1, loc->dw_loc_opc,
3927 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3929 /* Output the operand(s) (if any). */
3930 output_loc_operands (loc);
3934 /* This routine will generate the correct assembly data for a location
3935 description based on a cfi entry with a complex address. */
3938 output_cfa_loc (dw_cfi_ref cfi)
3940 dw_loc_descr_ref loc;
3943 if (cfi->dw_cfi_opc == DW_CFA_expression)
3944 dw2_asm_output_data (1, cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
3946 /* Output the size of the block. */
3947 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3948 size = size_of_locs (loc);
3949 dw2_asm_output_data_uleb128 (size, NULL);
3951 /* Now output the operations themselves. */
3952 output_loc_sequence (loc);
3955 /* This function builds a dwarf location descriptor sequence from a
3956 dw_cfa_location, adding the given OFFSET to the result of the
3959 static struct dw_loc_descr_struct *
3960 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3962 struct dw_loc_descr_struct *head, *tmp;
3964 offset += cfa->offset;
3968 if (cfa->base_offset)
3971 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3973 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3975 else if (cfa->reg <= 31)
3976 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3978 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3980 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3981 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3982 add_loc_descr (&head, tmp);
3985 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3986 add_loc_descr (&head, tmp);
3993 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3995 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3996 else if (cfa->reg <= 31)
3997 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3999 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
4005 /* This function builds a dwarf location descriptor sequence for
4006 the address at OFFSET from the CFA when stack is aligned to
4009 static struct dw_loc_descr_struct *
4010 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
4012 struct dw_loc_descr_struct *head;
4013 unsigned int dwarf_fp
4014 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
4016 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
4017 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
4020 head = new_loc_descr (DW_OP_breg0 + dwarf_fp, 0, 0);
4022 head = new_loc_descr (DW_OP_bregx, dwarf_fp, 0);
4024 add_loc_descr (&head, int_loc_descriptor (alignment));
4025 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
4027 add_loc_descr (&head, int_loc_descriptor (offset));
4028 add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
4030 else if (dwarf_fp <= 31)
4031 head = new_loc_descr (DW_OP_breg0 + dwarf_fp, offset, 0);
4033 head = new_loc_descr (DW_OP_bregx, dwarf_fp, offset);
4037 /* This function fills in aa dw_cfa_location structure from a dwarf location
4038 descriptor sequence. */
4041 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
4043 struct dw_loc_descr_struct *ptr;
4045 cfa->base_offset = 0;
4049 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
4051 enum dwarf_location_atom op = ptr->dw_loc_opc;
4087 cfa->reg = op - DW_OP_reg0;
4090 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4124 cfa->reg = op - DW_OP_breg0;
4125 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
4128 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
4129 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
4134 case DW_OP_plus_uconst:
4135 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
4138 internal_error ("DW_LOC_OP %s not implemented",
4139 dwarf_stack_op_name (ptr->dw_loc_opc));
4143 #endif /* .debug_frame support */
4145 /* And now, the support for symbolic debugging information. */
4146 #ifdef DWARF2_DEBUGGING_INFO
4148 /* .debug_str support. */
4149 static int output_indirect_string (void **, void *);
4151 static void dwarf2out_init (const char *);
4152 static void dwarf2out_finish (const char *);
4153 static void dwarf2out_define (unsigned int, const char *);
4154 static void dwarf2out_undef (unsigned int, const char *);
4155 static void dwarf2out_start_source_file (unsigned, const char *);
4156 static void dwarf2out_end_source_file (unsigned);
4157 static void dwarf2out_begin_block (unsigned, unsigned);
4158 static void dwarf2out_end_block (unsigned, unsigned);
4159 static bool dwarf2out_ignore_block (const_tree);
4160 static void dwarf2out_global_decl (tree);
4161 static void dwarf2out_type_decl (tree, int);
4162 static void dwarf2out_imported_module_or_decl (tree, tree);
4163 static void dwarf2out_abstract_function (tree);
4164 static void dwarf2out_var_location (rtx);
4165 static void dwarf2out_begin_function (tree);
4167 /* The debug hooks structure. */
4169 const struct gcc_debug_hooks dwarf2_debug_hooks =
4175 dwarf2out_start_source_file,
4176 dwarf2out_end_source_file,
4177 dwarf2out_begin_block,
4178 dwarf2out_end_block,
4179 dwarf2out_ignore_block,
4180 dwarf2out_source_line,
4181 dwarf2out_begin_prologue,
4182 debug_nothing_int_charstar, /* end_prologue */
4183 dwarf2out_end_epilogue,
4184 dwarf2out_begin_function,
4185 debug_nothing_int, /* end_function */
4186 dwarf2out_decl, /* function_decl */
4187 dwarf2out_global_decl,
4188 dwarf2out_type_decl, /* type_decl */
4189 dwarf2out_imported_module_or_decl,
4190 debug_nothing_tree, /* deferred_inline_function */
4191 /* The DWARF 2 backend tries to reduce debugging bloat by not
4192 emitting the abstract description of inline functions until
4193 something tries to reference them. */
4194 dwarf2out_abstract_function, /* outlining_inline_function */
4195 debug_nothing_rtx, /* label */
4196 debug_nothing_int, /* handle_pch */
4197 dwarf2out_var_location,
4198 dwarf2out_switch_text_section,
4199 1 /* start_end_main_source_file */
4203 /* NOTE: In the comments in this file, many references are made to
4204 "Debugging Information Entries". This term is abbreviated as `DIE'
4205 throughout the remainder of this file. */
4207 /* An internal representation of the DWARF output is built, and then
4208 walked to generate the DWARF debugging info. The walk of the internal
4209 representation is done after the entire program has been compiled.
4210 The types below are used to describe the internal representation. */
4212 /* Various DIE's use offsets relative to the beginning of the
4213 .debug_info section to refer to each other. */
4215 typedef long int dw_offset;
4217 /* Define typedefs here to avoid circular dependencies. */
4219 typedef struct dw_attr_struct *dw_attr_ref;
4220 typedef struct dw_line_info_struct *dw_line_info_ref;
4221 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
4222 typedef struct pubname_struct *pubname_ref;
4223 typedef struct dw_ranges_struct *dw_ranges_ref;
4224 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
4226 /* Each entry in the line_info_table maintains the file and
4227 line number associated with the label generated for that
4228 entry. The label gives the PC value associated with
4229 the line number entry. */
4231 typedef struct dw_line_info_struct GTY(())
4233 unsigned long dw_file_num;
4234 unsigned long dw_line_num;
4238 /* Line information for functions in separate sections; each one gets its
4240 typedef struct dw_separate_line_info_struct GTY(())
4242 unsigned long dw_file_num;
4243 unsigned long dw_line_num;
4244 unsigned long function;
4246 dw_separate_line_info_entry;
4248 /* Each DIE attribute has a field specifying the attribute kind,
4249 a link to the next attribute in the chain, and an attribute value.
4250 Attributes are typically linked below the DIE they modify. */
4252 typedef struct dw_attr_struct GTY(())
4254 enum dwarf_attribute dw_attr;
4255 dw_val_node dw_attr_val;
4259 DEF_VEC_O(dw_attr_node);
4260 DEF_VEC_ALLOC_O(dw_attr_node,gc);
4262 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4263 The children of each node form a circular list linked by
4264 die_sib. die_child points to the node *before* the "first" child node. */
4266 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
4268 enum dwarf_tag die_tag;
4270 VEC(dw_attr_node,gc) * die_attr;
4271 dw_die_ref die_parent;
4272 dw_die_ref die_child;
4274 dw_die_ref die_definition; /* ref from a specification to its definition */
4275 dw_offset die_offset;
4276 unsigned long die_abbrev;
4278 /* Die is used and must not be pruned as unused. */
4279 int die_perennial_p;
4280 unsigned int decl_id;
4284 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4285 #define FOR_EACH_CHILD(die, c, expr) do { \
4286 c = die->die_child; \
4290 } while (c != die->die_child); \
4293 /* The pubname structure */
4295 typedef struct pubname_struct GTY(())
4302 DEF_VEC_O(pubname_entry);
4303 DEF_VEC_ALLOC_O(pubname_entry, gc);
4305 struct dw_ranges_struct GTY(())
4307 /* If this is positive, it's a block number, otherwise it's a
4308 bitwise-negated index into dw_ranges_by_label. */
4312 struct dw_ranges_by_label_struct GTY(())
4318 /* The limbo die list structure. */
4319 typedef struct limbo_die_struct GTY(())
4323 struct limbo_die_struct *next;
4327 /* How to start an assembler comment. */
4328 #ifndef ASM_COMMENT_START
4329 #define ASM_COMMENT_START ";#"
4332 /* Define a macro which returns nonzero for a TYPE_DECL which was
4333 implicitly generated for a tagged type.
4335 Note that unlike the gcc front end (which generates a NULL named
4336 TYPE_DECL node for each complete tagged type, each array type, and
4337 each function type node created) the g++ front end generates a
4338 _named_ TYPE_DECL node for each tagged type node created.
4339 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4340 generate a DW_TAG_typedef DIE for them. */
4342 #define TYPE_DECL_IS_STUB(decl) \
4343 (DECL_NAME (decl) == NULL_TREE \
4344 || (DECL_ARTIFICIAL (decl) \
4345 && is_tagged_type (TREE_TYPE (decl)) \
4346 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4347 /* This is necessary for stub decls that \
4348 appear in nested inline functions. */ \
4349 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4350 && (decl_ultimate_origin (decl) \
4351 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4353 /* Information concerning the compilation unit's programming
4354 language, and compiler version. */
4356 /* Fixed size portion of the DWARF compilation unit header. */
4357 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4358 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4360 /* Fixed size portion of public names info. */
4361 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4363 /* Fixed size portion of the address range info. */
4364 #define DWARF_ARANGES_HEADER_SIZE \
4365 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4366 DWARF2_ADDR_SIZE * 2) \
4367 - DWARF_INITIAL_LENGTH_SIZE)
4369 /* Size of padding portion in the address range info. It must be
4370 aligned to twice the pointer size. */
4371 #define DWARF_ARANGES_PAD_SIZE \
4372 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4373 DWARF2_ADDR_SIZE * 2) \
4374 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4376 /* Use assembler line directives if available. */
4377 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4378 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4379 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4381 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4385 /* Minimum line offset in a special line info. opcode.
4386 This value was chosen to give a reasonable range of values. */
4387 #define DWARF_LINE_BASE -10
4389 /* First special line opcode - leave room for the standard opcodes. */
4390 #define DWARF_LINE_OPCODE_BASE 10
4392 /* Range of line offsets in a special line info. opcode. */
4393 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4395 /* Flag that indicates the initial value of the is_stmt_start flag.
4396 In the present implementation, we do not mark any lines as
4397 the beginning of a source statement, because that information
4398 is not made available by the GCC front-end. */
4399 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4401 #ifdef DWARF2_DEBUGGING_INFO
4402 /* This location is used by calc_die_sizes() to keep track
4403 the offset of each DIE within the .debug_info section. */
4404 static unsigned long next_die_offset;
4407 /* Record the root of the DIE's built for the current compilation unit. */
4408 static GTY(()) dw_die_ref comp_unit_die;
4410 /* A list of DIEs with a NULL parent waiting to be relocated. */
4411 static GTY(()) limbo_die_node *limbo_die_list;
4413 /* Filenames referenced by this compilation unit. */
4414 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
4416 /* A hash table of references to DIE's that describe declarations.
4417 The key is a DECL_UID() which is a unique number identifying each decl. */
4418 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4420 /* Node of the variable location list. */
4421 struct var_loc_node GTY ((chain_next ("%h.next")))
4423 rtx GTY (()) var_loc_note;
4424 const char * GTY (()) label;
4425 const char * GTY (()) section_label;
4426 struct var_loc_node * GTY (()) next;
4429 /* Variable location list. */
4430 struct var_loc_list_def GTY (())
4432 struct var_loc_node * GTY (()) first;
4434 /* Do not mark the last element of the chained list because
4435 it is marked through the chain. */
4436 struct var_loc_node * GTY ((skip ("%h"))) last;
4438 /* DECL_UID of the variable decl. */
4439 unsigned int decl_id;
4441 typedef struct var_loc_list_def var_loc_list;
4444 /* Table of decl location linked lists. */
4445 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4447 /* A pointer to the base of a list of references to DIE's that
4448 are uniquely identified by their tag, presence/absence of
4449 children DIE's, and list of attribute/value pairs. */
4450 static GTY((length ("abbrev_die_table_allocated")))
4451 dw_die_ref *abbrev_die_table;
4453 /* Number of elements currently allocated for abbrev_die_table. */
4454 static GTY(()) unsigned abbrev_die_table_allocated;
4456 /* Number of elements in type_die_table currently in use. */
4457 static GTY(()) unsigned abbrev_die_table_in_use;
4459 /* Size (in elements) of increments by which we may expand the
4460 abbrev_die_table. */
4461 #define ABBREV_DIE_TABLE_INCREMENT 256
4463 /* A pointer to the base of a table that contains line information
4464 for each source code line in .text in the compilation unit. */
4465 static GTY((length ("line_info_table_allocated")))
4466 dw_line_info_ref line_info_table;
4468 /* Number of elements currently allocated for line_info_table. */
4469 static GTY(()) unsigned line_info_table_allocated;
4471 /* Number of elements in line_info_table currently in use. */
4472 static GTY(()) unsigned line_info_table_in_use;
4474 /* A pointer to the base of a table that contains line information
4475 for each source code line outside of .text in the compilation unit. */
4476 static GTY ((length ("separate_line_info_table_allocated")))
4477 dw_separate_line_info_ref separate_line_info_table;
4479 /* Number of elements currently allocated for separate_line_info_table. */
4480 static GTY(()) unsigned separate_line_info_table_allocated;
4482 /* Number of elements in separate_line_info_table currently in use. */
4483 static GTY(()) unsigned separate_line_info_table_in_use;
4485 /* Size (in elements) of increments by which we may expand the
4487 #define LINE_INFO_TABLE_INCREMENT 1024
4489 /* A pointer to the base of a table that contains a list of publicly
4490 accessible names. */
4491 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4493 /* A pointer to the base of a table that contains a list of publicly
4494 accessible types. */
4495 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4497 /* Array of dies for which we should generate .debug_arange info. */
4498 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4500 /* Number of elements currently allocated for arange_table. */
4501 static GTY(()) unsigned arange_table_allocated;
4503 /* Number of elements in arange_table currently in use. */
4504 static GTY(()) unsigned arange_table_in_use;
4506 /* Size (in elements) of increments by which we may expand the
4508 #define ARANGE_TABLE_INCREMENT 64
4510 /* Array of dies for which we should generate .debug_ranges info. */
4511 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4513 /* Number of elements currently allocated for ranges_table. */
4514 static GTY(()) unsigned ranges_table_allocated;
4516 /* Number of elements in ranges_table currently in use. */
4517 static GTY(()) unsigned ranges_table_in_use;
4519 /* Array of pairs of labels referenced in ranges_table. */
4520 static GTY ((length ("ranges_by_label_allocated")))
4521 dw_ranges_by_label_ref ranges_by_label;
4523 /* Number of elements currently allocated for ranges_by_label. */
4524 static GTY(()) unsigned ranges_by_label_allocated;
4526 /* Number of elements in ranges_by_label currently in use. */
4527 static GTY(()) unsigned ranges_by_label_in_use;
4529 /* Size (in elements) of increments by which we may expand the
4531 #define RANGES_TABLE_INCREMENT 64
4533 /* Whether we have location lists that need outputting */
4534 static GTY(()) bool have_location_lists;
4536 /* Unique label counter. */
4537 static GTY(()) unsigned int loclabel_num;
4539 #ifdef DWARF2_DEBUGGING_INFO
4540 /* Record whether the function being analyzed contains inlined functions. */
4541 static int current_function_has_inlines;
4543 #if 0 && defined (MIPS_DEBUGGING_INFO)
4544 static int comp_unit_has_inlines;
4547 /* The last file entry emitted by maybe_emit_file(). */
4548 static GTY(()) struct dwarf_file_data * last_emitted_file;
4550 /* Number of internal labels generated by gen_internal_sym(). */
4551 static GTY(()) int label_num;
4553 /* Cached result of previous call to lookup_filename. */
4554 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4556 #ifdef DWARF2_DEBUGGING_INFO
4558 /* Offset from the "steady-state frame pointer" to the frame base,
4559 within the current function. */
4560 static HOST_WIDE_INT frame_pointer_fb_offset;
4562 /* Forward declarations for functions defined in this file. */
4564 static int is_pseudo_reg (const_rtx);
4565 static tree type_main_variant (tree);
4566 static int is_tagged_type (const_tree);
4567 static const char *dwarf_tag_name (unsigned);
4568 static const char *dwarf_attr_name (unsigned);
4569 static const char *dwarf_form_name (unsigned);
4570 static tree decl_ultimate_origin (const_tree);
4571 static tree block_ultimate_origin (const_tree);
4572 static tree decl_class_context (tree);
4573 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4574 static inline enum dw_val_class AT_class (dw_attr_ref);
4575 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4576 static inline unsigned AT_flag (dw_attr_ref);
4577 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4578 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4579 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4580 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4581 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4583 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4584 unsigned int, unsigned char *);
4585 static hashval_t debug_str_do_hash (const void *);
4586 static int debug_str_eq (const void *, const void *);
4587 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4588 static inline const char *AT_string (dw_attr_ref);
4589 static int AT_string_form (dw_attr_ref);
4590 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4591 static void add_AT_specification (dw_die_ref, dw_die_ref);
4592 static inline dw_die_ref AT_ref (dw_attr_ref);
4593 static inline int AT_ref_external (dw_attr_ref);
4594 static inline void set_AT_ref_external (dw_attr_ref, int);
4595 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4596 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4597 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4598 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4600 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4601 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4602 static inline rtx AT_addr (dw_attr_ref);
4603 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4604 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4605 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4606 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4607 unsigned HOST_WIDE_INT);
4608 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4610 static inline const char *AT_lbl (dw_attr_ref);
4611 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4612 static const char *get_AT_low_pc (dw_die_ref);
4613 static const char *get_AT_hi_pc (dw_die_ref);
4614 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4615 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4616 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4617 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4618 static bool is_c_family (void);
4619 static bool is_cxx (void);
4620 static bool is_java (void);
4621 static bool is_fortran (void);
4622 static bool is_ada (void);
4623 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4624 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4625 static void add_child_die (dw_die_ref, dw_die_ref);
4626 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4627 static dw_die_ref lookup_type_die (tree);
4628 static void equate_type_number_to_die (tree, dw_die_ref);
4629 static hashval_t decl_die_table_hash (const void *);
4630 static int decl_die_table_eq (const void *, const void *);
4631 static dw_die_ref lookup_decl_die (tree);
4632 static hashval_t decl_loc_table_hash (const void *);
4633 static int decl_loc_table_eq (const void *, const void *);
4634 static var_loc_list *lookup_decl_loc (const_tree);
4635 static void equate_decl_number_to_die (tree, dw_die_ref);
4636 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4637 static void print_spaces (FILE *);
4638 static void print_die (dw_die_ref, FILE *);
4639 static void print_dwarf_line_table (FILE *);
4640 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4641 static dw_die_ref pop_compile_unit (dw_die_ref);
4642 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4643 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4644 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4645 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4646 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4647 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4648 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4649 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4650 static void compute_section_prefix (dw_die_ref);
4651 static int is_type_die (dw_die_ref);
4652 static int is_comdat_die (dw_die_ref);
4653 static int is_symbol_die (dw_die_ref);
4654 static void assign_symbol_names (dw_die_ref);
4655 static void break_out_includes (dw_die_ref);
4656 static hashval_t htab_cu_hash (const void *);
4657 static int htab_cu_eq (const void *, const void *);
4658 static void htab_cu_del (void *);
4659 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4660 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4661 static void add_sibling_attributes (dw_die_ref);
4662 static void build_abbrev_table (dw_die_ref);
4663 static void output_location_lists (dw_die_ref);
4664 static int constant_size (long unsigned);
4665 static unsigned long size_of_die (dw_die_ref);
4666 static void calc_die_sizes (dw_die_ref);
4667 static void mark_dies (dw_die_ref);
4668 static void unmark_dies (dw_die_ref);
4669 static void unmark_all_dies (dw_die_ref);
4670 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4671 static unsigned long size_of_aranges (void);
4672 static enum dwarf_form value_format (dw_attr_ref);
4673 static void output_value_format (dw_attr_ref);
4674 static void output_abbrev_section (void);
4675 static void output_die_symbol (dw_die_ref);
4676 static void output_die (dw_die_ref);
4677 static void output_compilation_unit_header (void);
4678 static void output_comp_unit (dw_die_ref, int);
4679 static const char *dwarf2_name (tree, int);
4680 static void add_pubname (tree, dw_die_ref);
4681 static void add_pubname_string (const char *, dw_die_ref);
4682 static void add_pubtype (tree, dw_die_ref);
4683 static void output_pubnames (VEC (pubname_entry,gc) *);
4684 static void add_arange (tree, dw_die_ref);
4685 static void output_aranges (void);
4686 static unsigned int add_ranges_num (int);
4687 static unsigned int add_ranges (const_tree);
4688 static unsigned int add_ranges_by_labels (const char *, const char *);
4689 static void output_ranges (void);
4690 static void output_line_info (void);
4691 static void output_file_names (void);
4692 static dw_die_ref base_type_die (tree);
4693 static int is_base_type (tree);
4694 static bool is_subrange_type (const_tree);
4695 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4696 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4697 static int type_is_enum (const_tree);
4698 static unsigned int dbx_reg_number (const_rtx);
4699 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4700 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4701 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4702 enum var_init_status);
4703 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
4704 enum var_init_status);
4705 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
4706 enum var_init_status);
4707 static int is_based_loc (const_rtx);
4708 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
4709 enum var_init_status);
4710 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
4711 enum var_init_status);
4712 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
4713 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4714 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4715 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4716 static tree field_type (const_tree);
4717 static unsigned int simple_type_align_in_bits (const_tree);
4718 static unsigned int simple_decl_align_in_bits (const_tree);
4719 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
4720 static HOST_WIDE_INT field_byte_offset (const_tree);
4721 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4723 static void add_data_member_location_attribute (dw_die_ref, tree);
4724 static void add_const_value_attribute (dw_die_ref, rtx);
4725 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4726 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4727 static void insert_float (const_rtx, unsigned char *);
4728 static rtx rtl_for_decl_location (tree);
4729 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4730 enum dwarf_attribute);
4731 static void tree_add_const_value_attribute (dw_die_ref, tree);
4732 static void add_name_attribute (dw_die_ref, const char *);
4733 static void add_comp_dir_attribute (dw_die_ref);
4734 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4735 static void add_subscript_info (dw_die_ref, tree, bool);
4736 static void add_byte_size_attribute (dw_die_ref, tree);
4737 static void add_bit_offset_attribute (dw_die_ref, tree);
4738 static void add_bit_size_attribute (dw_die_ref, tree);
4739 static void add_prototyped_attribute (dw_die_ref, tree);
4740 static void add_abstract_origin_attribute (dw_die_ref, tree);
4741 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4742 static void add_src_coords_attributes (dw_die_ref, tree);
4743 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4744 static void push_decl_scope (tree);
4745 static void pop_decl_scope (void);
4746 static dw_die_ref scope_die_for (tree, dw_die_ref);
4747 static inline int local_scope_p (dw_die_ref);
4748 static inline int class_or_namespace_scope_p (dw_die_ref);
4749 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4750 static void add_calling_convention_attribute (dw_die_ref, tree);
4751 static const char *type_tag (const_tree);
4752 static tree member_declared_type (const_tree);
4754 static const char *decl_start_label (tree);
4756 static void gen_array_type_die (tree, dw_die_ref);
4757 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4759 static void gen_entry_point_die (tree, dw_die_ref);
4761 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4762 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4763 static void gen_inlined_union_type_die (tree, dw_die_ref);
4764 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4765 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4766 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4767 static void gen_formal_types_die (tree, dw_die_ref);
4768 static void gen_subprogram_die (tree, dw_die_ref);
4769 static void gen_variable_die (tree, dw_die_ref);
4770 static void gen_label_die (tree, dw_die_ref);
4771 static void gen_lexical_block_die (tree, dw_die_ref, int);
4772 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4773 static void gen_field_die (tree, dw_die_ref);
4774 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4775 static dw_die_ref gen_compile_unit_die (const char *);
4776 static void gen_inheritance_die (tree, tree, dw_die_ref);
4777 static void gen_member_die (tree, dw_die_ref);
4778 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4779 enum debug_info_usage);
4780 static void gen_subroutine_type_die (tree, dw_die_ref);
4781 static void gen_typedef_die (tree, dw_die_ref);
4782 static void gen_type_die (tree, dw_die_ref);
4783 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4784 static void gen_block_die (tree, dw_die_ref, int);
4785 static void decls_for_scope (tree, dw_die_ref, int);
4786 static int is_redundant_typedef (const_tree);
4787 static void gen_namespace_die (tree);
4788 static void gen_decl_die (tree, dw_die_ref);
4789 static dw_die_ref force_decl_die (tree);
4790 static dw_die_ref force_type_die (tree);
4791 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4792 static void declare_in_namespace (tree, dw_die_ref);
4793 static struct dwarf_file_data * lookup_filename (const char *);
4794 static void retry_incomplete_types (void);
4795 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4796 static void splice_child_die (dw_die_ref, dw_die_ref);
4797 static int file_info_cmp (const void *, const void *);
4798 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4799 const char *, const char *, unsigned);
4800 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4801 const char *, const char *,
4803 static void output_loc_list (dw_loc_list_ref);
4804 static char *gen_internal_sym (const char *);
4806 static void prune_unmark_dies (dw_die_ref);
4807 static void prune_unused_types_mark (dw_die_ref, int);
4808 static void prune_unused_types_walk (dw_die_ref);
4809 static void prune_unused_types_walk_attribs (dw_die_ref);
4810 static void prune_unused_types_prune (dw_die_ref);
4811 static void prune_unused_types (void);
4812 static int maybe_emit_file (struct dwarf_file_data *fd);
4814 /* Section names used to hold DWARF debugging information. */
4815 #ifndef DEBUG_INFO_SECTION
4816 #define DEBUG_INFO_SECTION ".debug_info"
4818 #ifndef DEBUG_ABBREV_SECTION
4819 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4821 #ifndef DEBUG_ARANGES_SECTION
4822 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4824 #ifndef DEBUG_MACINFO_SECTION
4825 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4827 #ifndef DEBUG_LINE_SECTION
4828 #define DEBUG_LINE_SECTION ".debug_line"
4830 #ifndef DEBUG_LOC_SECTION
4831 #define DEBUG_LOC_SECTION ".debug_loc"
4833 #ifndef DEBUG_PUBNAMES_SECTION
4834 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4836 #ifndef DEBUG_STR_SECTION
4837 #define DEBUG_STR_SECTION ".debug_str"
4839 #ifndef DEBUG_RANGES_SECTION
4840 #define DEBUG_RANGES_SECTION ".debug_ranges"
4843 /* Standard ELF section names for compiled code and data. */
4844 #ifndef TEXT_SECTION_NAME
4845 #define TEXT_SECTION_NAME ".text"
4848 /* Section flags for .debug_str section. */
4849 #define DEBUG_STR_SECTION_FLAGS \
4850 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4851 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4854 /* Labels we insert at beginning sections we can reference instead of
4855 the section names themselves. */
4857 #ifndef TEXT_SECTION_LABEL
4858 #define TEXT_SECTION_LABEL "Ltext"
4860 #ifndef COLD_TEXT_SECTION_LABEL
4861 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4863 #ifndef DEBUG_LINE_SECTION_LABEL
4864 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4866 #ifndef DEBUG_INFO_SECTION_LABEL
4867 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4869 #ifndef DEBUG_ABBREV_SECTION_LABEL
4870 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4872 #ifndef DEBUG_LOC_SECTION_LABEL
4873 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4875 #ifndef DEBUG_RANGES_SECTION_LABEL
4876 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4878 #ifndef DEBUG_MACINFO_SECTION_LABEL
4879 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4882 /* Definitions of defaults for formats and names of various special
4883 (artificial) labels which may be generated within this file (when the -g
4884 options is used and DWARF2_DEBUGGING_INFO is in effect.
4885 If necessary, these may be overridden from within the tm.h file, but
4886 typically, overriding these defaults is unnecessary. */
4888 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4889 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4890 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4891 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4892 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4893 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4894 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4895 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4896 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4897 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4899 #ifndef TEXT_END_LABEL
4900 #define TEXT_END_LABEL "Letext"
4902 #ifndef COLD_END_LABEL
4903 #define COLD_END_LABEL "Letext_cold"
4905 #ifndef BLOCK_BEGIN_LABEL
4906 #define BLOCK_BEGIN_LABEL "LBB"
4908 #ifndef BLOCK_END_LABEL
4909 #define BLOCK_END_LABEL "LBE"
4911 #ifndef LINE_CODE_LABEL
4912 #define LINE_CODE_LABEL "LM"
4914 #ifndef SEPARATE_LINE_CODE_LABEL
4915 #define SEPARATE_LINE_CODE_LABEL "LSM"
4919 /* We allow a language front-end to designate a function that is to be
4920 called to "demangle" any name before it is put into a DIE. */
4922 static const char *(*demangle_name_func) (const char *);
4925 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4927 demangle_name_func = func;
4930 /* Test if rtl node points to a pseudo register. */
4933 is_pseudo_reg (const_rtx rtl)
4935 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4936 || (GET_CODE (rtl) == SUBREG
4937 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4940 /* Return a reference to a type, with its const and volatile qualifiers
4944 type_main_variant (tree type)
4946 type = TYPE_MAIN_VARIANT (type);
4948 /* ??? There really should be only one main variant among any group of
4949 variants of a given type (and all of the MAIN_VARIANT values for all
4950 members of the group should point to that one type) but sometimes the C
4951 front-end messes this up for array types, so we work around that bug
4953 if (TREE_CODE (type) == ARRAY_TYPE)
4954 while (type != TYPE_MAIN_VARIANT (type))
4955 type = TYPE_MAIN_VARIANT (type);
4960 /* Return nonzero if the given type node represents a tagged type. */
4963 is_tagged_type (const_tree type)
4965 enum tree_code code = TREE_CODE (type);
4967 return (code == RECORD_TYPE || code == UNION_TYPE
4968 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4971 /* Convert a DIE tag into its string name. */
4974 dwarf_tag_name (unsigned int tag)
4978 case DW_TAG_padding:
4979 return "DW_TAG_padding";
4980 case DW_TAG_array_type:
4981 return "DW_TAG_array_type";
4982 case DW_TAG_class_type:
4983 return "DW_TAG_class_type";
4984 case DW_TAG_entry_point:
4985 return "DW_TAG_entry_point";
4986 case DW_TAG_enumeration_type:
4987 return "DW_TAG_enumeration_type";
4988 case DW_TAG_formal_parameter:
4989 return "DW_TAG_formal_parameter";
4990 case DW_TAG_imported_declaration:
4991 return "DW_TAG_imported_declaration";
4993 return "DW_TAG_label";
4994 case DW_TAG_lexical_block:
4995 return "DW_TAG_lexical_block";
4997 return "DW_TAG_member";
4998 case DW_TAG_pointer_type:
4999 return "DW_TAG_pointer_type";
5000 case DW_TAG_reference_type:
5001 return "DW_TAG_reference_type";
5002 case DW_TAG_compile_unit:
5003 return "DW_TAG_compile_unit";
5004 case DW_TAG_string_type:
5005 return "DW_TAG_string_type";
5006 case DW_TAG_structure_type:
5007 return "DW_TAG_structure_type";
5008 case DW_TAG_subroutine_type:
5009 return "DW_TAG_subroutine_type";
5010 case DW_TAG_typedef:
5011 return "DW_TAG_typedef";
5012 case DW_TAG_union_type:
5013 return "DW_TAG_union_type";
5014 case DW_TAG_unspecified_parameters:
5015 return "DW_TAG_unspecified_parameters";
5016 case DW_TAG_variant:
5017 return "DW_TAG_variant";
5018 case DW_TAG_common_block:
5019 return "DW_TAG_common_block";
5020 case DW_TAG_common_inclusion:
5021 return "DW_TAG_common_inclusion";
5022 case DW_TAG_inheritance:
5023 return "DW_TAG_inheritance";
5024 case DW_TAG_inlined_subroutine:
5025 return "DW_TAG_inlined_subroutine";
5027 return "DW_TAG_module";
5028 case DW_TAG_ptr_to_member_type:
5029 return "DW_TAG_ptr_to_member_type";
5030 case DW_TAG_set_type:
5031 return "DW_TAG_set_type";
5032 case DW_TAG_subrange_type:
5033 return "DW_TAG_subrange_type";
5034 case DW_TAG_with_stmt:
5035 return "DW_TAG_with_stmt";
5036 case DW_TAG_access_declaration:
5037 return "DW_TAG_access_declaration";
5038 case DW_TAG_base_type:
5039 return "DW_TAG_base_type";
5040 case DW_TAG_catch_block:
5041 return "DW_TAG_catch_block";
5042 case DW_TAG_const_type:
5043 return "DW_TAG_const_type";
5044 case DW_TAG_constant:
5045 return "DW_TAG_constant";
5046 case DW_TAG_enumerator:
5047 return "DW_TAG_enumerator";
5048 case DW_TAG_file_type:
5049 return "DW_TAG_file_type";
5051 return "DW_TAG_friend";
5052 case DW_TAG_namelist:
5053 return "DW_TAG_namelist";
5054 case DW_TAG_namelist_item:
5055 return "DW_TAG_namelist_item";
5056 case DW_TAG_packed_type:
5057 return "DW_TAG_packed_type";
5058 case DW_TAG_subprogram:
5059 return "DW_TAG_subprogram";
5060 case DW_TAG_template_type_param:
5061 return "DW_TAG_template_type_param";
5062 case DW_TAG_template_value_param:
5063 return "DW_TAG_template_value_param";
5064 case DW_TAG_thrown_type:
5065 return "DW_TAG_thrown_type";
5066 case DW_TAG_try_block:
5067 return "DW_TAG_try_block";
5068 case DW_TAG_variant_part:
5069 return "DW_TAG_variant_part";
5070 case DW_TAG_variable:
5071 return "DW_TAG_variable";
5072 case DW_TAG_volatile_type:
5073 return "DW_TAG_volatile_type";
5074 case DW_TAG_dwarf_procedure:
5075 return "DW_TAG_dwarf_procedure";
5076 case DW_TAG_restrict_type:
5077 return "DW_TAG_restrict_type";
5078 case DW_TAG_interface_type:
5079 return "DW_TAG_interface_type";
5080 case DW_TAG_namespace:
5081 return "DW_TAG_namespace";
5082 case DW_TAG_imported_module:
5083 return "DW_TAG_imported_module";
5084 case DW_TAG_unspecified_type:
5085 return "DW_TAG_unspecified_type";
5086 case DW_TAG_partial_unit:
5087 return "DW_TAG_partial_unit";
5088 case DW_TAG_imported_unit:
5089 return "DW_TAG_imported_unit";
5090 case DW_TAG_condition:
5091 return "DW_TAG_condition";
5092 case DW_TAG_shared_type:
5093 return "DW_TAG_shared_type";
5094 case DW_TAG_MIPS_loop:
5095 return "DW_TAG_MIPS_loop";
5096 case DW_TAG_format_label:
5097 return "DW_TAG_format_label";
5098 case DW_TAG_function_template:
5099 return "DW_TAG_function_template";
5100 case DW_TAG_class_template:
5101 return "DW_TAG_class_template";
5102 case DW_TAG_GNU_BINCL:
5103 return "DW_TAG_GNU_BINCL";
5104 case DW_TAG_GNU_EINCL:
5105 return "DW_TAG_GNU_EINCL";
5107 return "DW_TAG_<unknown>";
5111 /* Convert a DWARF attribute code into its string name. */
5114 dwarf_attr_name (unsigned int attr)
5119 return "DW_AT_sibling";
5120 case DW_AT_location:
5121 return "DW_AT_location";
5123 return "DW_AT_name";
5124 case DW_AT_ordering:
5125 return "DW_AT_ordering";
5126 case DW_AT_subscr_data:
5127 return "DW_AT_subscr_data";
5128 case DW_AT_byte_size:
5129 return "DW_AT_byte_size";
5130 case DW_AT_bit_offset:
5131 return "DW_AT_bit_offset";
5132 case DW_AT_bit_size:
5133 return "DW_AT_bit_size";
5134 case DW_AT_element_list:
5135 return "DW_AT_element_list";
5136 case DW_AT_stmt_list:
5137 return "DW_AT_stmt_list";
5139 return "DW_AT_low_pc";
5141 return "DW_AT_high_pc";
5142 case DW_AT_language:
5143 return "DW_AT_language";
5145 return "DW_AT_member";
5147 return "DW_AT_discr";
5148 case DW_AT_discr_value:
5149 return "DW_AT_discr_value";
5150 case DW_AT_visibility:
5151 return "DW_AT_visibility";
5153 return "DW_AT_import";
5154 case DW_AT_string_length:
5155 return "DW_AT_string_length";
5156 case DW_AT_common_reference:
5157 return "DW_AT_common_reference";
5158 case DW_AT_comp_dir:
5159 return "DW_AT_comp_dir";
5160 case DW_AT_const_value:
5161 return "DW_AT_const_value";
5162 case DW_AT_containing_type:
5163 return "DW_AT_containing_type";
5164 case DW_AT_default_value:
5165 return "DW_AT_default_value";
5167 return "DW_AT_inline";
5168 case DW_AT_is_optional:
5169 return "DW_AT_is_optional";
5170 case DW_AT_lower_bound:
5171 return "DW_AT_lower_bound";
5172 case DW_AT_producer:
5173 return "DW_AT_producer";
5174 case DW_AT_prototyped:
5175 return "DW_AT_prototyped";
5176 case DW_AT_return_addr:
5177 return "DW_AT_return_addr";
5178 case DW_AT_start_scope:
5179 return "DW_AT_start_scope";
5180 case DW_AT_bit_stride:
5181 return "DW_AT_bit_stride";
5182 case DW_AT_upper_bound:
5183 return "DW_AT_upper_bound";
5184 case DW_AT_abstract_origin:
5185 return "DW_AT_abstract_origin";
5186 case DW_AT_accessibility:
5187 return "DW_AT_accessibility";
5188 case DW_AT_address_class:
5189 return "DW_AT_address_class";
5190 case DW_AT_artificial:
5191 return "DW_AT_artificial";
5192 case DW_AT_base_types:
5193 return "DW_AT_base_types";
5194 case DW_AT_calling_convention:
5195 return "DW_AT_calling_convention";
5197 return "DW_AT_count";
5198 case DW_AT_data_member_location:
5199 return "DW_AT_data_member_location";
5200 case DW_AT_decl_column:
5201 return "DW_AT_decl_column";
5202 case DW_AT_decl_file:
5203 return "DW_AT_decl_file";
5204 case DW_AT_decl_line:
5205 return "DW_AT_decl_line";
5206 case DW_AT_declaration:
5207 return "DW_AT_declaration";
5208 case DW_AT_discr_list:
5209 return "DW_AT_discr_list";
5210 case DW_AT_encoding:
5211 return "DW_AT_encoding";
5212 case DW_AT_external:
5213 return "DW_AT_external";
5214 case DW_AT_frame_base:
5215 return "DW_AT_frame_base";
5217 return "DW_AT_friend";
5218 case DW_AT_identifier_case:
5219 return "DW_AT_identifier_case";
5220 case DW_AT_macro_info:
5221 return "DW_AT_macro_info";
5222 case DW_AT_namelist_items:
5223 return "DW_AT_namelist_items";
5224 case DW_AT_priority:
5225 return "DW_AT_priority";
5227 return "DW_AT_segment";
5228 case DW_AT_specification:
5229 return "DW_AT_specification";
5230 case DW_AT_static_link:
5231 return "DW_AT_static_link";
5233 return "DW_AT_type";
5234 case DW_AT_use_location:
5235 return "DW_AT_use_location";
5236 case DW_AT_variable_parameter:
5237 return "DW_AT_variable_parameter";
5238 case DW_AT_virtuality:
5239 return "DW_AT_virtuality";
5240 case DW_AT_vtable_elem_location:
5241 return "DW_AT_vtable_elem_location";
5243 case DW_AT_allocated:
5244 return "DW_AT_allocated";
5245 case DW_AT_associated:
5246 return "DW_AT_associated";
5247 case DW_AT_data_location:
5248 return "DW_AT_data_location";
5249 case DW_AT_byte_stride:
5250 return "DW_AT_byte_stride";
5251 case DW_AT_entry_pc:
5252 return "DW_AT_entry_pc";
5253 case DW_AT_use_UTF8:
5254 return "DW_AT_use_UTF8";
5255 case DW_AT_extension:
5256 return "DW_AT_extension";
5258 return "DW_AT_ranges";
5259 case DW_AT_trampoline:
5260 return "DW_AT_trampoline";
5261 case DW_AT_call_column:
5262 return "DW_AT_call_column";
5263 case DW_AT_call_file:
5264 return "DW_AT_call_file";
5265 case DW_AT_call_line:
5266 return "DW_AT_call_line";
5268 case DW_AT_MIPS_fde:
5269 return "DW_AT_MIPS_fde";
5270 case DW_AT_MIPS_loop_begin:
5271 return "DW_AT_MIPS_loop_begin";
5272 case DW_AT_MIPS_tail_loop_begin:
5273 return "DW_AT_MIPS_tail_loop_begin";
5274 case DW_AT_MIPS_epilog_begin:
5275 return "DW_AT_MIPS_epilog_begin";
5276 case DW_AT_MIPS_loop_unroll_factor:
5277 return "DW_AT_MIPS_loop_unroll_factor";
5278 case DW_AT_MIPS_software_pipeline_depth:
5279 return "DW_AT_MIPS_software_pipeline_depth";
5280 case DW_AT_MIPS_linkage_name:
5281 return "DW_AT_MIPS_linkage_name";
5282 case DW_AT_MIPS_stride:
5283 return "DW_AT_MIPS_stride";
5284 case DW_AT_MIPS_abstract_name:
5285 return "DW_AT_MIPS_abstract_name";
5286 case DW_AT_MIPS_clone_origin:
5287 return "DW_AT_MIPS_clone_origin";
5288 case DW_AT_MIPS_has_inlines:
5289 return "DW_AT_MIPS_has_inlines";
5291 case DW_AT_sf_names:
5292 return "DW_AT_sf_names";
5293 case DW_AT_src_info:
5294 return "DW_AT_src_info";
5295 case DW_AT_mac_info:
5296 return "DW_AT_mac_info";
5297 case DW_AT_src_coords:
5298 return "DW_AT_src_coords";
5299 case DW_AT_body_begin:
5300 return "DW_AT_body_begin";
5301 case DW_AT_body_end:
5302 return "DW_AT_body_end";
5303 case DW_AT_GNU_vector:
5304 return "DW_AT_GNU_vector";
5306 case DW_AT_VMS_rtnbeg_pd_address:
5307 return "DW_AT_VMS_rtnbeg_pd_address";
5310 return "DW_AT_<unknown>";
5314 /* Convert a DWARF value form code into its string name. */
5317 dwarf_form_name (unsigned int form)
5322 return "DW_FORM_addr";
5323 case DW_FORM_block2:
5324 return "DW_FORM_block2";
5325 case DW_FORM_block4:
5326 return "DW_FORM_block4";
5328 return "DW_FORM_data2";
5330 return "DW_FORM_data4";
5332 return "DW_FORM_data8";
5333 case DW_FORM_string:
5334 return "DW_FORM_string";
5336 return "DW_FORM_block";
5337 case DW_FORM_block1:
5338 return "DW_FORM_block1";
5340 return "DW_FORM_data1";
5342 return "DW_FORM_flag";
5344 return "DW_FORM_sdata";
5346 return "DW_FORM_strp";
5348 return "DW_FORM_udata";
5349 case DW_FORM_ref_addr:
5350 return "DW_FORM_ref_addr";
5352 return "DW_FORM_ref1";
5354 return "DW_FORM_ref2";
5356 return "DW_FORM_ref4";
5358 return "DW_FORM_ref8";
5359 case DW_FORM_ref_udata:
5360 return "DW_FORM_ref_udata";
5361 case DW_FORM_indirect:
5362 return "DW_FORM_indirect";
5364 return "DW_FORM_<unknown>";
5368 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5369 instance of an inlined instance of a decl which is local to an inline
5370 function, so we have to trace all of the way back through the origin chain
5371 to find out what sort of node actually served as the original seed for the
5375 decl_ultimate_origin (const_tree decl)
5377 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
5380 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5381 nodes in the function to point to themselves; ignore that if
5382 we're trying to output the abstract instance of this function. */
5383 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
5386 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5387 most distant ancestor, this should never happen. */
5388 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
5390 return DECL_ABSTRACT_ORIGIN (decl);
5393 /* Determine the "ultimate origin" of a block. The block may be an inlined
5394 instance of an inlined instance of a block which is local to an inline
5395 function, so we have to trace all of the way back through the origin chain
5396 to find out what sort of node actually served as the original seed for the
5400 block_ultimate_origin (const_tree block)
5402 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
5404 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
5405 nodes in the function to point to themselves; ignore that if
5406 we're trying to output the abstract instance of this function. */
5407 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
5410 if (immediate_origin == NULL_TREE)
5415 tree lookahead = immediate_origin;
5419 ret_val = lookahead;
5420 lookahead = (TREE_CODE (ret_val) == BLOCK
5421 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
5423 while (lookahead != NULL && lookahead != ret_val);
5425 /* The block's abstract origin chain may not be the *ultimate* origin of
5426 the block. It could lead to a DECL that has an abstract origin set.
5427 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5428 will give us if it has one). Note that DECL's abstract origins are
5429 supposed to be the most distant ancestor (or so decl_ultimate_origin
5430 claims), so we don't need to loop following the DECL origins. */
5431 if (DECL_P (ret_val))
5432 return DECL_ORIGIN (ret_val);
5438 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5439 of a virtual function may refer to a base class, so we check the 'this'
5443 decl_class_context (tree decl)
5445 tree context = NULL_TREE;
5447 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5448 context = DECL_CONTEXT (decl);
5450 context = TYPE_MAIN_VARIANT
5451 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5453 if (context && !TYPE_P (context))
5454 context = NULL_TREE;
5459 /* Add an attribute/value pair to a DIE. */
5462 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5464 /* Maybe this should be an assert? */
5468 if (die->die_attr == NULL)
5469 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5470 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5473 static inline enum dw_val_class
5474 AT_class (dw_attr_ref a)
5476 return a->dw_attr_val.val_class;
5479 /* Add a flag value attribute to a DIE. */
5482 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5486 attr.dw_attr = attr_kind;
5487 attr.dw_attr_val.val_class = dw_val_class_flag;
5488 attr.dw_attr_val.v.val_flag = flag;
5489 add_dwarf_attr (die, &attr);
5492 static inline unsigned
5493 AT_flag (dw_attr_ref a)
5495 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5496 return a->dw_attr_val.v.val_flag;
5499 /* Add a signed integer attribute value to a DIE. */
5502 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5506 attr.dw_attr = attr_kind;
5507 attr.dw_attr_val.val_class = dw_val_class_const;
5508 attr.dw_attr_val.v.val_int = int_val;
5509 add_dwarf_attr (die, &attr);
5512 static inline HOST_WIDE_INT
5513 AT_int (dw_attr_ref a)
5515 gcc_assert (a && AT_class (a) == dw_val_class_const);
5516 return a->dw_attr_val.v.val_int;
5519 /* Add an unsigned integer attribute value to a DIE. */
5522 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5523 unsigned HOST_WIDE_INT unsigned_val)
5527 attr.dw_attr = attr_kind;
5528 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5529 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5530 add_dwarf_attr (die, &attr);
5533 static inline unsigned HOST_WIDE_INT
5534 AT_unsigned (dw_attr_ref a)
5536 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5537 return a->dw_attr_val.v.val_unsigned;
5540 /* Add an unsigned double integer attribute value to a DIE. */
5543 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5544 long unsigned int val_hi, long unsigned int val_low)
5548 attr.dw_attr = attr_kind;
5549 attr.dw_attr_val.val_class = dw_val_class_long_long;
5550 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5551 attr.dw_attr_val.v.val_long_long.low = val_low;
5552 add_dwarf_attr (die, &attr);
5555 /* Add a floating point attribute value to a DIE and return it. */
5558 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5559 unsigned int length, unsigned int elt_size, unsigned char *array)
5563 attr.dw_attr = attr_kind;
5564 attr.dw_attr_val.val_class = dw_val_class_vec;
5565 attr.dw_attr_val.v.val_vec.length = length;
5566 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5567 attr.dw_attr_val.v.val_vec.array = array;
5568 add_dwarf_attr (die, &attr);
5571 /* Hash and equality functions for debug_str_hash. */
5574 debug_str_do_hash (const void *x)
5576 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5580 debug_str_eq (const void *x1, const void *x2)
5582 return strcmp ((((const struct indirect_string_node *)x1)->str),
5583 (const char *)x2) == 0;
5586 /* Add a string attribute value to a DIE. */
5589 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5592 struct indirect_string_node *node;
5595 if (! debug_str_hash)
5596 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5597 debug_str_eq, NULL);
5599 slot = htab_find_slot_with_hash (debug_str_hash, str,
5600 htab_hash_string (str), INSERT);
5603 node = (struct indirect_string_node *)
5604 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5605 node->str = ggc_strdup (str);
5609 node = (struct indirect_string_node *) *slot;
5613 attr.dw_attr = attr_kind;
5614 attr.dw_attr_val.val_class = dw_val_class_str;
5615 attr.dw_attr_val.v.val_str = node;
5616 add_dwarf_attr (die, &attr);
5619 static inline const char *
5620 AT_string (dw_attr_ref a)
5622 gcc_assert (a && AT_class (a) == dw_val_class_str);
5623 return a->dw_attr_val.v.val_str->str;
5626 /* Find out whether a string should be output inline in DIE
5627 or out-of-line in .debug_str section. */
5630 AT_string_form (dw_attr_ref a)
5632 struct indirect_string_node *node;
5636 gcc_assert (a && AT_class (a) == dw_val_class_str);
5638 node = a->dw_attr_val.v.val_str;
5642 len = strlen (node->str) + 1;
5644 /* If the string is shorter or equal to the size of the reference, it is
5645 always better to put it inline. */
5646 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5647 return node->form = DW_FORM_string;
5649 /* If we cannot expect the linker to merge strings in .debug_str
5650 section, only put it into .debug_str if it is worth even in this
5652 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5653 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5654 return node->form = DW_FORM_string;
5656 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5657 ++dw2_string_counter;
5658 node->label = xstrdup (label);
5660 return node->form = DW_FORM_strp;
5663 /* Add a DIE reference attribute value to a DIE. */
5666 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5670 attr.dw_attr = attr_kind;
5671 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5672 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5673 attr.dw_attr_val.v.val_die_ref.external = 0;
5674 add_dwarf_attr (die, &attr);
5677 /* Add an AT_specification attribute to a DIE, and also make the back
5678 pointer from the specification to the definition. */
5681 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5683 add_AT_die_ref (die, DW_AT_specification, targ_die);
5684 gcc_assert (!targ_die->die_definition);
5685 targ_die->die_definition = die;
5688 static inline dw_die_ref
5689 AT_ref (dw_attr_ref a)
5691 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5692 return a->dw_attr_val.v.val_die_ref.die;
5696 AT_ref_external (dw_attr_ref a)
5698 if (a && AT_class (a) == dw_val_class_die_ref)
5699 return a->dw_attr_val.v.val_die_ref.external;
5705 set_AT_ref_external (dw_attr_ref a, int i)
5707 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5708 a->dw_attr_val.v.val_die_ref.external = i;
5711 /* Add an FDE reference attribute value to a DIE. */
5714 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5718 attr.dw_attr = attr_kind;
5719 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5720 attr.dw_attr_val.v.val_fde_index = targ_fde;
5721 add_dwarf_attr (die, &attr);
5724 /* Add a location description attribute value to a DIE. */
5727 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5731 attr.dw_attr = attr_kind;
5732 attr.dw_attr_val.val_class = dw_val_class_loc;
5733 attr.dw_attr_val.v.val_loc = loc;
5734 add_dwarf_attr (die, &attr);
5737 static inline dw_loc_descr_ref
5738 AT_loc (dw_attr_ref a)
5740 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5741 return a->dw_attr_val.v.val_loc;
5745 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5749 attr.dw_attr = attr_kind;
5750 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5751 attr.dw_attr_val.v.val_loc_list = loc_list;
5752 add_dwarf_attr (die, &attr);
5753 have_location_lists = true;
5756 static inline dw_loc_list_ref
5757 AT_loc_list (dw_attr_ref a)
5759 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5760 return a->dw_attr_val.v.val_loc_list;
5763 /* Add an address constant attribute value to a DIE. */
5766 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5770 attr.dw_attr = attr_kind;
5771 attr.dw_attr_val.val_class = dw_val_class_addr;
5772 attr.dw_attr_val.v.val_addr = addr;
5773 add_dwarf_attr (die, &attr);
5776 /* Get the RTX from to an address DIE attribute. */
5779 AT_addr (dw_attr_ref a)
5781 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5782 return a->dw_attr_val.v.val_addr;
5785 /* Add a file attribute value to a DIE. */
5788 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5789 struct dwarf_file_data *fd)
5793 attr.dw_attr = attr_kind;
5794 attr.dw_attr_val.val_class = dw_val_class_file;
5795 attr.dw_attr_val.v.val_file = fd;
5796 add_dwarf_attr (die, &attr);
5799 /* Get the dwarf_file_data from a file DIE attribute. */
5801 static inline struct dwarf_file_data *
5802 AT_file (dw_attr_ref a)
5804 gcc_assert (a && AT_class (a) == dw_val_class_file);
5805 return a->dw_attr_val.v.val_file;
5808 /* Add a label identifier attribute value to a DIE. */
5811 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5815 attr.dw_attr = attr_kind;
5816 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5817 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5818 add_dwarf_attr (die, &attr);
5821 /* Add a section offset attribute value to a DIE, an offset into the
5822 debug_line section. */
5825 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5830 attr.dw_attr = attr_kind;
5831 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5832 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5833 add_dwarf_attr (die, &attr);
5836 /* Add a section offset attribute value to a DIE, an offset into the
5837 debug_macinfo section. */
5840 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5845 attr.dw_attr = attr_kind;
5846 attr.dw_attr_val.val_class = dw_val_class_macptr;
5847 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5848 add_dwarf_attr (die, &attr);
5851 /* Add an offset attribute value to a DIE. */
5854 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5855 unsigned HOST_WIDE_INT offset)
5859 attr.dw_attr = attr_kind;
5860 attr.dw_attr_val.val_class = dw_val_class_offset;
5861 attr.dw_attr_val.v.val_offset = offset;
5862 add_dwarf_attr (die, &attr);
5865 /* Add an range_list attribute value to a DIE. */
5868 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5869 long unsigned int offset)
5873 attr.dw_attr = attr_kind;
5874 attr.dw_attr_val.val_class = dw_val_class_range_list;
5875 attr.dw_attr_val.v.val_offset = offset;
5876 add_dwarf_attr (die, &attr);
5879 static inline const char *
5880 AT_lbl (dw_attr_ref a)
5882 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5883 || AT_class (a) == dw_val_class_lineptr
5884 || AT_class (a) == dw_val_class_macptr));
5885 return a->dw_attr_val.v.val_lbl_id;
5888 /* Get the attribute of type attr_kind. */
5891 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5895 dw_die_ref spec = NULL;
5900 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5901 if (a->dw_attr == attr_kind)
5903 else if (a->dw_attr == DW_AT_specification
5904 || a->dw_attr == DW_AT_abstract_origin)
5908 return get_AT (spec, attr_kind);
5913 /* Return the "low pc" attribute value, typically associated with a subprogram
5914 DIE. Return null if the "low pc" attribute is either not present, or if it
5915 cannot be represented as an assembler label identifier. */
5917 static inline const char *
5918 get_AT_low_pc (dw_die_ref die)
5920 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5922 return a ? AT_lbl (a) : NULL;
5925 /* Return the "high pc" attribute value, typically associated with a subprogram
5926 DIE. Return null if the "high pc" attribute is either not present, or if it
5927 cannot be represented as an assembler label identifier. */
5929 static inline const char *
5930 get_AT_hi_pc (dw_die_ref die)
5932 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5934 return a ? AT_lbl (a) : NULL;
5937 /* Return the value of the string attribute designated by ATTR_KIND, or
5938 NULL if it is not present. */
5940 static inline const char *
5941 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5943 dw_attr_ref a = get_AT (die, attr_kind);
5945 return a ? AT_string (a) : NULL;
5948 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5949 if it is not present. */
5952 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5954 dw_attr_ref a = get_AT (die, attr_kind);
5956 return a ? AT_flag (a) : 0;
5959 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5960 if it is not present. */
5962 static inline unsigned
5963 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5965 dw_attr_ref a = get_AT (die, attr_kind);
5967 return a ? AT_unsigned (a) : 0;
5970 static inline dw_die_ref
5971 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5973 dw_attr_ref a = get_AT (die, attr_kind);
5975 return a ? AT_ref (a) : NULL;
5978 static inline struct dwarf_file_data *
5979 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5981 dw_attr_ref a = get_AT (die, attr_kind);
5983 return a ? AT_file (a) : NULL;
5986 /* Return TRUE if the language is C or C++. */
5991 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5993 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5994 || lang == DW_LANG_C99
5995 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5998 /* Return TRUE if the language is C++. */
6003 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6005 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
6008 /* Return TRUE if the language is Fortran. */
6013 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6015 return (lang == DW_LANG_Fortran77
6016 || lang == DW_LANG_Fortran90
6017 || lang == DW_LANG_Fortran95);
6020 /* Return TRUE if the language is Java. */
6025 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6027 return lang == DW_LANG_Java;
6030 /* Return TRUE if the language is Ada. */
6035 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
6037 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
6040 /* Remove the specified attribute if present. */
6043 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
6051 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6052 if (a->dw_attr == attr_kind)
6054 if (AT_class (a) == dw_val_class_str)
6055 if (a->dw_attr_val.v.val_str->refcount)
6056 a->dw_attr_val.v.val_str->refcount--;
6058 /* VEC_ordered_remove should help reduce the number of abbrevs
6060 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
6065 /* Remove CHILD from its parent. PREV must have the property that
6066 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6069 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
6071 gcc_assert (child->die_parent == prev->die_parent);
6072 gcc_assert (prev->die_sib == child);
6075 gcc_assert (child->die_parent->die_child == child);
6079 prev->die_sib = child->die_sib;
6080 if (child->die_parent->die_child == child)
6081 child->die_parent->die_child = prev;
6084 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6088 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
6094 dw_die_ref prev = c;
6096 while (c->die_tag == tag)
6098 remove_child_with_prev (c, prev);
6099 /* Might have removed every child. */
6100 if (c == c->die_sib)
6104 } while (c != die->die_child);
6107 /* Add a CHILD_DIE as the last child of DIE. */
6110 add_child_die (dw_die_ref die, dw_die_ref child_die)
6112 /* FIXME this should probably be an assert. */
6113 if (! die || ! child_die)
6115 gcc_assert (die != child_die);
6117 child_die->die_parent = die;
6120 child_die->die_sib = die->die_child->die_sib;
6121 die->die_child->die_sib = child_die;
6124 child_die->die_sib = child_die;
6125 die->die_child = child_die;
6128 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6129 is the specification, to the end of PARENT's list of children.
6130 This is done by removing and re-adding it. */
6133 splice_child_die (dw_die_ref parent, dw_die_ref child)
6137 /* We want the declaration DIE from inside the class, not the
6138 specification DIE at toplevel. */
6139 if (child->die_parent != parent)
6141 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
6147 gcc_assert (child->die_parent == parent
6148 || (child->die_parent
6149 == get_AT_ref (parent, DW_AT_specification)));
6151 for (p = child->die_parent->die_child; ; p = p->die_sib)
6152 if (p->die_sib == child)
6154 remove_child_with_prev (child, p);
6158 add_child_die (parent, child);
6161 /* Return a pointer to a newly created DIE node. */
6163 static inline dw_die_ref
6164 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
6166 dw_die_ref die = GGC_CNEW (die_node);
6168 die->die_tag = tag_value;
6170 if (parent_die != NULL)
6171 add_child_die (parent_die, die);
6174 limbo_die_node *limbo_node;
6176 limbo_node = GGC_CNEW (limbo_die_node);
6177 limbo_node->die = die;
6178 limbo_node->created_for = t;
6179 limbo_node->next = limbo_die_list;
6180 limbo_die_list = limbo_node;
6186 /* Return the DIE associated with the given type specifier. */
6188 static inline dw_die_ref
6189 lookup_type_die (tree type)
6191 return TYPE_SYMTAB_DIE (type);
6194 /* Equate a DIE to a given type specifier. */
6197 equate_type_number_to_die (tree type, dw_die_ref type_die)
6199 TYPE_SYMTAB_DIE (type) = type_die;
6202 /* Returns a hash value for X (which really is a die_struct). */
6205 decl_die_table_hash (const void *x)
6207 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
6210 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6213 decl_die_table_eq (const void *x, const void *y)
6215 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
6218 /* Return the DIE associated with a given declaration. */
6220 static inline dw_die_ref
6221 lookup_decl_die (tree decl)
6223 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
6226 /* Returns a hash value for X (which really is a var_loc_list). */
6229 decl_loc_table_hash (const void *x)
6231 return (hashval_t) ((const var_loc_list *) x)->decl_id;
6234 /* Return nonzero if decl_id of var_loc_list X is the same as
6238 decl_loc_table_eq (const void *x, const void *y)
6240 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
6243 /* Return the var_loc list associated with a given declaration. */
6245 static inline var_loc_list *
6246 lookup_decl_loc (const_tree decl)
6248 return (var_loc_list *)
6249 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
6252 /* Equate a DIE to a particular declaration. */
6255 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6257 unsigned int decl_id = DECL_UID (decl);
6260 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
6262 decl_die->decl_id = decl_id;
6265 /* Add a variable location node to the linked list for DECL. */
6268 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
6270 unsigned int decl_id = DECL_UID (decl);
6274 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
6277 temp = GGC_CNEW (var_loc_list);
6278 temp->decl_id = decl_id;
6282 temp = (var_loc_list *) *slot;
6286 /* If the current location is the same as the end of the list,
6287 and either both or neither of the locations is uninitialized,
6288 we have nothing to do. */
6289 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
6290 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
6291 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6292 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
6293 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
6294 == VAR_INIT_STATUS_UNINITIALIZED)
6295 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
6296 == VAR_INIT_STATUS_UNINITIALIZED))))
6298 /* Add LOC to the end of list and update LAST. */
6299 temp->last->next = loc;
6303 /* Do not add empty location to the beginning of the list. */
6304 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
6311 /* Keep track of the number of spaces used to indent the
6312 output of the debugging routines that print the structure of
6313 the DIE internal representation. */
6314 static int print_indent;
6316 /* Indent the line the number of spaces given by print_indent. */
6319 print_spaces (FILE *outfile)
6321 fprintf (outfile, "%*s", print_indent, "");
6324 /* Print the information associated with a given DIE, and its children.
6325 This routine is a debugging aid only. */
6328 print_die (dw_die_ref die, FILE *outfile)
6334 print_spaces (outfile);
6335 fprintf (outfile, "DIE %4ld: %s\n",
6336 die->die_offset, dwarf_tag_name (die->die_tag));
6337 print_spaces (outfile);
6338 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6339 fprintf (outfile, " offset: %ld\n", die->die_offset);
6341 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6343 print_spaces (outfile);
6344 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6346 switch (AT_class (a))
6348 case dw_val_class_addr:
6349 fprintf (outfile, "address");
6351 case dw_val_class_offset:
6352 fprintf (outfile, "offset");
6354 case dw_val_class_loc:
6355 fprintf (outfile, "location descriptor");
6357 case dw_val_class_loc_list:
6358 fprintf (outfile, "location list -> label:%s",
6359 AT_loc_list (a)->ll_symbol);
6361 case dw_val_class_range_list:
6362 fprintf (outfile, "range list");
6364 case dw_val_class_const:
6365 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
6367 case dw_val_class_unsigned_const:
6368 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
6370 case dw_val_class_long_long:
6371 fprintf (outfile, "constant (%lu,%lu)",
6372 a->dw_attr_val.v.val_long_long.hi,
6373 a->dw_attr_val.v.val_long_long.low);
6375 case dw_val_class_vec:
6376 fprintf (outfile, "floating-point or vector constant");
6378 case dw_val_class_flag:
6379 fprintf (outfile, "%u", AT_flag (a));
6381 case dw_val_class_die_ref:
6382 if (AT_ref (a) != NULL)
6384 if (AT_ref (a)->die_symbol)
6385 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
6387 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
6390 fprintf (outfile, "die -> <null>");
6392 case dw_val_class_lbl_id:
6393 case dw_val_class_lineptr:
6394 case dw_val_class_macptr:
6395 fprintf (outfile, "label: %s", AT_lbl (a));
6397 case dw_val_class_str:
6398 if (AT_string (a) != NULL)
6399 fprintf (outfile, "\"%s\"", AT_string (a));
6401 fprintf (outfile, "<null>");
6403 case dw_val_class_file:
6404 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
6405 AT_file (a)->emitted_number);
6411 fprintf (outfile, "\n");
6414 if (die->die_child != NULL)
6417 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6420 if (print_indent == 0)
6421 fprintf (outfile, "\n");
6424 /* Print the contents of the source code line number correspondence table.
6425 This routine is a debugging aid only. */
6428 print_dwarf_line_table (FILE *outfile)
6431 dw_line_info_ref line_info;
6433 fprintf (outfile, "\n\nDWARF source line information\n");
6434 for (i = 1; i < line_info_table_in_use; i++)
6436 line_info = &line_info_table[i];
6437 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6438 line_info->dw_file_num,
6439 line_info->dw_line_num);
6442 fprintf (outfile, "\n\n");
6445 /* Print the information collected for a given DIE. */
6448 debug_dwarf_die (dw_die_ref die)
6450 print_die (die, stderr);
6453 /* Print all DWARF information collected for the compilation unit.
6454 This routine is a debugging aid only. */
6460 print_die (comp_unit_die, stderr);
6461 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6462 print_dwarf_line_table (stderr);
6465 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6466 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6467 DIE that marks the start of the DIEs for this include file. */
6470 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6472 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6473 dw_die_ref new_unit = gen_compile_unit_die (filename);
6475 new_unit->die_sib = old_unit;
6479 /* Close an include-file CU and reopen the enclosing one. */
6482 pop_compile_unit (dw_die_ref old_unit)
6484 dw_die_ref new_unit = old_unit->die_sib;
6486 old_unit->die_sib = NULL;
6490 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6491 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6493 /* Calculate the checksum of a location expression. */
6496 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6498 CHECKSUM (loc->dw_loc_opc);
6499 CHECKSUM (loc->dw_loc_oprnd1);
6500 CHECKSUM (loc->dw_loc_oprnd2);
6503 /* Calculate the checksum of an attribute. */
6506 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6508 dw_loc_descr_ref loc;
6511 CHECKSUM (at->dw_attr);
6513 /* We don't care that this was compiled with a different compiler
6514 snapshot; if the output is the same, that's what matters. */
6515 if (at->dw_attr == DW_AT_producer)
6518 switch (AT_class (at))
6520 case dw_val_class_const:
6521 CHECKSUM (at->dw_attr_val.v.val_int);
6523 case dw_val_class_unsigned_const:
6524 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6526 case dw_val_class_long_long:
6527 CHECKSUM (at->dw_attr_val.v.val_long_long);
6529 case dw_val_class_vec:
6530 CHECKSUM (at->dw_attr_val.v.val_vec);
6532 case dw_val_class_flag:
6533 CHECKSUM (at->dw_attr_val.v.val_flag);
6535 case dw_val_class_str:
6536 CHECKSUM_STRING (AT_string (at));
6539 case dw_val_class_addr:
6541 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6542 CHECKSUM_STRING (XSTR (r, 0));
6545 case dw_val_class_offset:
6546 CHECKSUM (at->dw_attr_val.v.val_offset);
6549 case dw_val_class_loc:
6550 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6551 loc_checksum (loc, ctx);
6554 case dw_val_class_die_ref:
6555 die_checksum (AT_ref (at), ctx, mark);
6558 case dw_val_class_fde_ref:
6559 case dw_val_class_lbl_id:
6560 case dw_val_class_lineptr:
6561 case dw_val_class_macptr:
6564 case dw_val_class_file:
6565 CHECKSUM_STRING (AT_file (at)->filename);
6573 /* Calculate the checksum of a DIE. */
6576 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6582 /* To avoid infinite recursion. */
6585 CHECKSUM (die->die_mark);
6588 die->die_mark = ++(*mark);
6590 CHECKSUM (die->die_tag);
6592 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6593 attr_checksum (a, ctx, mark);
6595 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6599 #undef CHECKSUM_STRING
6601 /* Do the location expressions look same? */
6603 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6605 return loc1->dw_loc_opc == loc2->dw_loc_opc
6606 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6607 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6610 /* Do the values look the same? */
6612 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6614 dw_loc_descr_ref loc1, loc2;
6617 if (v1->val_class != v2->val_class)
6620 switch (v1->val_class)
6622 case dw_val_class_const:
6623 return v1->v.val_int == v2->v.val_int;
6624 case dw_val_class_unsigned_const:
6625 return v1->v.val_unsigned == v2->v.val_unsigned;
6626 case dw_val_class_long_long:
6627 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6628 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6629 case dw_val_class_vec:
6630 if (v1->v.val_vec.length != v2->v.val_vec.length
6631 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6633 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6634 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6637 case dw_val_class_flag:
6638 return v1->v.val_flag == v2->v.val_flag;
6639 case dw_val_class_str:
6640 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6642 case dw_val_class_addr:
6643 r1 = v1->v.val_addr;
6644 r2 = v2->v.val_addr;
6645 if (GET_CODE (r1) != GET_CODE (r2))
6647 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6648 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6650 case dw_val_class_offset:
6651 return v1->v.val_offset == v2->v.val_offset;
6653 case dw_val_class_loc:
6654 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6656 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6657 if (!same_loc_p (loc1, loc2, mark))
6659 return !loc1 && !loc2;
6661 case dw_val_class_die_ref:
6662 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6664 case dw_val_class_fde_ref:
6665 case dw_val_class_lbl_id:
6666 case dw_val_class_lineptr:
6667 case dw_val_class_macptr:
6670 case dw_val_class_file:
6671 return v1->v.val_file == v2->v.val_file;
6678 /* Do the attributes look the same? */
6681 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6683 if (at1->dw_attr != at2->dw_attr)
6686 /* We don't care that this was compiled with a different compiler
6687 snapshot; if the output is the same, that's what matters. */
6688 if (at1->dw_attr == DW_AT_producer)
6691 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6694 /* Do the dies look the same? */
6697 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6703 /* To avoid infinite recursion. */
6705 return die1->die_mark == die2->die_mark;
6706 die1->die_mark = die2->die_mark = ++(*mark);
6708 if (die1->die_tag != die2->die_tag)
6711 if (VEC_length (dw_attr_node, die1->die_attr)
6712 != VEC_length (dw_attr_node, die2->die_attr))
6715 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6716 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6719 c1 = die1->die_child;
6720 c2 = die2->die_child;
6729 if (!same_die_p (c1, c2, mark))
6733 if (c1 == die1->die_child)
6735 if (c2 == die2->die_child)
6745 /* Do the dies look the same? Wrapper around same_die_p. */
6748 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6751 int ret = same_die_p (die1, die2, &mark);
6753 unmark_all_dies (die1);
6754 unmark_all_dies (die2);
6759 /* The prefix to attach to symbols on DIEs in the current comdat debug
6761 static char *comdat_symbol_id;
6763 /* The index of the current symbol within the current comdat CU. */
6764 static unsigned int comdat_symbol_number;
6766 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6767 children, and set comdat_symbol_id accordingly. */
6770 compute_section_prefix (dw_die_ref unit_die)
6772 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6773 const char *base = die_name ? lbasename (die_name) : "anonymous";
6774 char *name = XALLOCAVEC (char, strlen (base) + 64);
6777 unsigned char checksum[16];
6780 /* Compute the checksum of the DIE, then append part of it as hex digits to
6781 the name filename of the unit. */
6783 md5_init_ctx (&ctx);
6785 die_checksum (unit_die, &ctx, &mark);
6786 unmark_all_dies (unit_die);
6787 md5_finish_ctx (&ctx, checksum);
6789 sprintf (name, "%s.", base);
6790 clean_symbol_name (name);
6792 p = name + strlen (name);
6793 for (i = 0; i < 4; i++)
6795 sprintf (p, "%.2x", checksum[i]);
6799 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6800 comdat_symbol_number = 0;
6803 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6806 is_type_die (dw_die_ref die)
6808 switch (die->die_tag)
6810 case DW_TAG_array_type:
6811 case DW_TAG_class_type:
6812 case DW_TAG_interface_type:
6813 case DW_TAG_enumeration_type:
6814 case DW_TAG_pointer_type:
6815 case DW_TAG_reference_type:
6816 case DW_TAG_string_type:
6817 case DW_TAG_structure_type:
6818 case DW_TAG_subroutine_type:
6819 case DW_TAG_union_type:
6820 case DW_TAG_ptr_to_member_type:
6821 case DW_TAG_set_type:
6822 case DW_TAG_subrange_type:
6823 case DW_TAG_base_type:
6824 case DW_TAG_const_type:
6825 case DW_TAG_file_type:
6826 case DW_TAG_packed_type:
6827 case DW_TAG_volatile_type:
6828 case DW_TAG_typedef:
6835 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6836 Basically, we want to choose the bits that are likely to be shared between
6837 compilations (types) and leave out the bits that are specific to individual
6838 compilations (functions). */
6841 is_comdat_die (dw_die_ref c)
6843 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6844 we do for stabs. The advantage is a greater likelihood of sharing between
6845 objects that don't include headers in the same order (and therefore would
6846 put the base types in a different comdat). jason 8/28/00 */
6848 if (c->die_tag == DW_TAG_base_type)
6851 if (c->die_tag == DW_TAG_pointer_type
6852 || c->die_tag == DW_TAG_reference_type
6853 || c->die_tag == DW_TAG_const_type
6854 || c->die_tag == DW_TAG_volatile_type)
6856 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6858 return t ? is_comdat_die (t) : 0;
6861 return is_type_die (c);
6864 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6865 compilation unit. */
6868 is_symbol_die (dw_die_ref c)
6870 return (is_type_die (c)
6871 || (get_AT (c, DW_AT_declaration)
6872 && !get_AT (c, DW_AT_specification))
6873 || c->die_tag == DW_TAG_namespace);
6877 gen_internal_sym (const char *prefix)
6881 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6882 return xstrdup (buf);
6885 /* Assign symbols to all worthy DIEs under DIE. */
6888 assign_symbol_names (dw_die_ref die)
6892 if (is_symbol_die (die))
6894 if (comdat_symbol_id)
6896 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6898 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6899 comdat_symbol_id, comdat_symbol_number++);
6900 die->die_symbol = xstrdup (p);
6903 die->die_symbol = gen_internal_sym ("LDIE");
6906 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6909 struct cu_hash_table_entry
6912 unsigned min_comdat_num, max_comdat_num;
6913 struct cu_hash_table_entry *next;
6916 /* Routines to manipulate hash table of CUs. */
6918 htab_cu_hash (const void *of)
6920 const struct cu_hash_table_entry *const entry =
6921 (const struct cu_hash_table_entry *) of;
6923 return htab_hash_string (entry->cu->die_symbol);
6927 htab_cu_eq (const void *of1, const void *of2)
6929 const struct cu_hash_table_entry *const entry1 =
6930 (const struct cu_hash_table_entry *) of1;
6931 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6933 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6937 htab_cu_del (void *what)
6939 struct cu_hash_table_entry *next,
6940 *entry = (struct cu_hash_table_entry *) what;
6950 /* Check whether we have already seen this CU and set up SYM_NUM
6953 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6955 struct cu_hash_table_entry dummy;
6956 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6958 dummy.max_comdat_num = 0;
6960 slot = (struct cu_hash_table_entry **)
6961 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6965 for (; entry; last = entry, entry = entry->next)
6967 if (same_die_p_wrap (cu, entry->cu))
6973 *sym_num = entry->min_comdat_num;
6977 entry = XCNEW (struct cu_hash_table_entry);
6979 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6980 entry->next = *slot;
6986 /* Record SYM_NUM to record of CU in HTABLE. */
6988 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6990 struct cu_hash_table_entry **slot, *entry;
6992 slot = (struct cu_hash_table_entry **)
6993 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6997 entry->max_comdat_num = sym_num;
7000 /* Traverse the DIE (which is always comp_unit_die), and set up
7001 additional compilation units for each of the include files we see
7002 bracketed by BINCL/EINCL. */
7005 break_out_includes (dw_die_ref die)
7008 dw_die_ref unit = NULL;
7009 limbo_die_node *node, **pnode;
7010 htab_t cu_hash_table;
7014 dw_die_ref prev = c;
7016 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
7017 || (unit && is_comdat_die (c)))
7019 dw_die_ref next = c->die_sib;
7021 /* This DIE is for a secondary CU; remove it from the main one. */
7022 remove_child_with_prev (c, prev);
7024 if (c->die_tag == DW_TAG_GNU_BINCL)
7025 unit = push_new_compile_unit (unit, c);
7026 else if (c->die_tag == DW_TAG_GNU_EINCL)
7027 unit = pop_compile_unit (unit);
7029 add_child_die (unit, c);
7031 if (c == die->die_child)
7034 } while (c != die->die_child);
7037 /* We can only use this in debugging, since the frontend doesn't check
7038 to make sure that we leave every include file we enter. */
7042 assign_symbol_names (die);
7043 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
7044 for (node = limbo_die_list, pnode = &limbo_die_list;
7050 compute_section_prefix (node->die);
7051 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
7052 &comdat_symbol_number);
7053 assign_symbol_names (node->die);
7055 *pnode = node->next;
7058 pnode = &node->next;
7059 record_comdat_symbol_number (node->die, cu_hash_table,
7060 comdat_symbol_number);
7063 htab_delete (cu_hash_table);
7066 /* Traverse the DIE and add a sibling attribute if it may have the
7067 effect of speeding up access to siblings. To save some space,
7068 avoid generating sibling attributes for DIE's without children. */
7071 add_sibling_attributes (dw_die_ref die)
7075 if (! die->die_child)
7078 if (die->die_parent && die != die->die_parent->die_child)
7079 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
7081 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
7084 /* Output all location lists for the DIE and its children. */
7087 output_location_lists (dw_die_ref die)
7093 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7094 if (AT_class (a) == dw_val_class_loc_list)
7095 output_loc_list (AT_loc_list (a));
7097 FOR_EACH_CHILD (die, c, output_location_lists (c));
7100 /* The format of each DIE (and its attribute value pairs) is encoded in an
7101 abbreviation table. This routine builds the abbreviation table and assigns
7102 a unique abbreviation id for each abbreviation entry. The children of each
7103 die are visited recursively. */
7106 build_abbrev_table (dw_die_ref die)
7108 unsigned long abbrev_id;
7109 unsigned int n_alloc;
7114 /* Scan the DIE references, and mark as external any that refer to
7115 DIEs from other CUs (i.e. those which are not marked). */
7116 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7117 if (AT_class (a) == dw_val_class_die_ref
7118 && AT_ref (a)->die_mark == 0)
7120 gcc_assert (AT_ref (a)->die_symbol);
7122 set_AT_ref_external (a, 1);
7125 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7127 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7128 dw_attr_ref die_a, abbrev_a;
7132 if (abbrev->die_tag != die->die_tag)
7134 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
7137 if (VEC_length (dw_attr_node, abbrev->die_attr)
7138 != VEC_length (dw_attr_node, die->die_attr))
7141 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
7143 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
7144 if ((abbrev_a->dw_attr != die_a->dw_attr)
7145 || (value_format (abbrev_a) != value_format (die_a)))
7155 if (abbrev_id >= abbrev_die_table_in_use)
7157 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
7159 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
7160 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
7163 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
7164 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
7165 abbrev_die_table_allocated = n_alloc;
7168 ++abbrev_die_table_in_use;
7169 abbrev_die_table[abbrev_id] = die;
7172 die->die_abbrev = abbrev_id;
7173 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
7176 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7179 constant_size (long unsigned int value)
7186 log = floor_log2 (value);
7189 log = 1 << (floor_log2 (log) + 1);
7194 /* Return the size of a DIE as it is represented in the
7195 .debug_info section. */
7197 static unsigned long
7198 size_of_die (dw_die_ref die)
7200 unsigned long size = 0;
7204 size += size_of_uleb128 (die->die_abbrev);
7205 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7207 switch (AT_class (a))
7209 case dw_val_class_addr:
7210 size += DWARF2_ADDR_SIZE;
7212 case dw_val_class_offset:
7213 size += DWARF_OFFSET_SIZE;
7215 case dw_val_class_loc:
7217 unsigned long lsize = size_of_locs (AT_loc (a));
7220 size += constant_size (lsize);
7224 case dw_val_class_loc_list:
7225 size += DWARF_OFFSET_SIZE;
7227 case dw_val_class_range_list:
7228 size += DWARF_OFFSET_SIZE;
7230 case dw_val_class_const:
7231 size += size_of_sleb128 (AT_int (a));
7233 case dw_val_class_unsigned_const:
7234 size += constant_size (AT_unsigned (a));
7236 case dw_val_class_long_long:
7237 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
7239 case dw_val_class_vec:
7240 size += 1 + (a->dw_attr_val.v.val_vec.length
7241 * a->dw_attr_val.v.val_vec.elt_size); /* block */
7243 case dw_val_class_flag:
7246 case dw_val_class_die_ref:
7247 if (AT_ref_external (a))
7248 size += DWARF2_ADDR_SIZE;
7250 size += DWARF_OFFSET_SIZE;
7252 case dw_val_class_fde_ref:
7253 size += DWARF_OFFSET_SIZE;
7255 case dw_val_class_lbl_id:
7256 size += DWARF2_ADDR_SIZE;
7258 case dw_val_class_lineptr:
7259 case dw_val_class_macptr:
7260 size += DWARF_OFFSET_SIZE;
7262 case dw_val_class_str:
7263 if (AT_string_form (a) == DW_FORM_strp)
7264 size += DWARF_OFFSET_SIZE;
7266 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
7268 case dw_val_class_file:
7269 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
7279 /* Size the debugging information associated with a given DIE. Visits the
7280 DIE's children recursively. Updates the global variable next_die_offset, on
7281 each time through. Uses the current value of next_die_offset to update the
7282 die_offset field in each DIE. */
7285 calc_die_sizes (dw_die_ref die)
7289 die->die_offset = next_die_offset;
7290 next_die_offset += size_of_die (die);
7292 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
7294 if (die->die_child != NULL)
7295 /* Count the null byte used to terminate sibling lists. */
7296 next_die_offset += 1;
7299 /* Set the marks for a die and its children. We do this so
7300 that we know whether or not a reference needs to use FORM_ref_addr; only
7301 DIEs in the same CU will be marked. We used to clear out the offset
7302 and use that as the flag, but ran into ordering problems. */
7305 mark_dies (dw_die_ref die)
7309 gcc_assert (!die->die_mark);
7312 FOR_EACH_CHILD (die, c, mark_dies (c));
7315 /* Clear the marks for a die and its children. */
7318 unmark_dies (dw_die_ref die)
7322 gcc_assert (die->die_mark);
7325 FOR_EACH_CHILD (die, c, unmark_dies (c));
7328 /* Clear the marks for a die, its children and referred dies. */
7331 unmark_all_dies (dw_die_ref die)
7341 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
7343 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7344 if (AT_class (a) == dw_val_class_die_ref)
7345 unmark_all_dies (AT_ref (a));
7348 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7349 generated for the compilation unit. */
7351 static unsigned long
7352 size_of_pubnames (VEC (pubname_entry, gc) * names)
7358 size = DWARF_PUBNAMES_HEADER_SIZE;
7359 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
7360 if (names != pubtype_table
7361 || p->die->die_offset != 0
7362 || !flag_eliminate_unused_debug_types)
7363 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
7365 size += DWARF_OFFSET_SIZE;
7369 /* Return the size of the information in the .debug_aranges section. */
7371 static unsigned long
7372 size_of_aranges (void)
7376 size = DWARF_ARANGES_HEADER_SIZE;
7378 /* Count the address/length pair for this compilation unit. */
7379 if (text_section_used)
7380 size += 2 * DWARF2_ADDR_SIZE;
7381 if (cold_text_section_used)
7382 size += 2 * DWARF2_ADDR_SIZE;
7383 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
7385 /* Count the two zero words used to terminated the address range table. */
7386 size += 2 * DWARF2_ADDR_SIZE;
7390 /* Select the encoding of an attribute value. */
7392 static enum dwarf_form
7393 value_format (dw_attr_ref a)
7395 switch (a->dw_attr_val.val_class)
7397 case dw_val_class_addr:
7398 return DW_FORM_addr;
7399 case dw_val_class_range_list:
7400 case dw_val_class_offset:
7401 case dw_val_class_loc_list:
7402 switch (DWARF_OFFSET_SIZE)
7405 return DW_FORM_data4;
7407 return DW_FORM_data8;
7411 case dw_val_class_loc:
7412 switch (constant_size (size_of_locs (AT_loc (a))))
7415 return DW_FORM_block1;
7417 return DW_FORM_block2;
7421 case dw_val_class_const:
7422 return DW_FORM_sdata;
7423 case dw_val_class_unsigned_const:
7424 switch (constant_size (AT_unsigned (a)))
7427 return DW_FORM_data1;
7429 return DW_FORM_data2;
7431 return DW_FORM_data4;
7433 return DW_FORM_data8;
7437 case dw_val_class_long_long:
7438 return DW_FORM_block1;
7439 case dw_val_class_vec:
7440 return DW_FORM_block1;
7441 case dw_val_class_flag:
7442 return DW_FORM_flag;
7443 case dw_val_class_die_ref:
7444 if (AT_ref_external (a))
7445 return DW_FORM_ref_addr;
7448 case dw_val_class_fde_ref:
7449 return DW_FORM_data;
7450 case dw_val_class_lbl_id:
7451 return DW_FORM_addr;
7452 case dw_val_class_lineptr:
7453 case dw_val_class_macptr:
7454 return DW_FORM_data;
7455 case dw_val_class_str:
7456 return AT_string_form (a);
7457 case dw_val_class_file:
7458 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7461 return DW_FORM_data1;
7463 return DW_FORM_data2;
7465 return DW_FORM_data4;
7475 /* Output the encoding of an attribute value. */
7478 output_value_format (dw_attr_ref a)
7480 enum dwarf_form form = value_format (a);
7482 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7485 /* Output the .debug_abbrev section which defines the DIE abbreviation
7489 output_abbrev_section (void)
7491 unsigned long abbrev_id;
7493 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7495 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7499 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7500 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7501 dwarf_tag_name (abbrev->die_tag));
7503 if (abbrev->die_child != NULL)
7504 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7506 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7508 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7511 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7512 dwarf_attr_name (a_attr->dw_attr));
7513 output_value_format (a_attr);
7516 dw2_asm_output_data (1, 0, NULL);
7517 dw2_asm_output_data (1, 0, NULL);
7520 /* Terminate the table. */
7521 dw2_asm_output_data (1, 0, NULL);
7524 /* Output a symbol we can use to refer to this DIE from another CU. */
7527 output_die_symbol (dw_die_ref die)
7529 char *sym = die->die_symbol;
7534 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7535 /* We make these global, not weak; if the target doesn't support
7536 .linkonce, it doesn't support combining the sections, so debugging
7538 targetm.asm_out.globalize_label (asm_out_file, sym);
7540 ASM_OUTPUT_LABEL (asm_out_file, sym);
7543 /* Return a new location list, given the begin and end range, and the
7544 expression. gensym tells us whether to generate a new internal symbol for
7545 this location list node, which is done for the head of the list only. */
7547 static inline dw_loc_list_ref
7548 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7549 const char *section, unsigned int gensym)
7551 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7553 retlist->begin = begin;
7555 retlist->expr = expr;
7556 retlist->section = section;
7558 retlist->ll_symbol = gen_internal_sym ("LLST");
7563 /* Add a location description expression to a location list. */
7566 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7567 const char *begin, const char *end,
7568 const char *section)
7572 /* Find the end of the chain. */
7573 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7576 /* Add a new location list node to the list. */
7577 *d = new_loc_list (descr, begin, end, section, 0);
7580 /* Output the location list given to us. */
7583 output_loc_list (dw_loc_list_ref list_head)
7585 dw_loc_list_ref curr = list_head;
7587 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7589 /* Walk the location list, and output each range + expression. */
7590 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7593 /* Don't output an entry that starts and ends at the same address. */
7594 if (strcmp (curr->begin, curr->end) == 0)
7596 if (!have_multiple_function_sections)
7598 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7599 "Location list begin address (%s)",
7600 list_head->ll_symbol);
7601 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7602 "Location list end address (%s)",
7603 list_head->ll_symbol);
7607 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7608 "Location list begin address (%s)",
7609 list_head->ll_symbol);
7610 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7611 "Location list end address (%s)",
7612 list_head->ll_symbol);
7614 size = size_of_locs (curr->expr);
7616 /* Output the block length for this list of location operations. */
7617 gcc_assert (size <= 0xffff);
7618 dw2_asm_output_data (2, size, "%s", "Location expression size");
7620 output_loc_sequence (curr->expr);
7623 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7624 "Location list terminator begin (%s)",
7625 list_head->ll_symbol);
7626 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7627 "Location list terminator end (%s)",
7628 list_head->ll_symbol);
7631 /* Output the DIE and its attributes. Called recursively to generate
7632 the definitions of each child DIE. */
7635 output_die (dw_die_ref die)
7642 /* If someone in another CU might refer to us, set up a symbol for
7643 them to point to. */
7644 if (die->die_symbol)
7645 output_die_symbol (die);
7647 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7648 (unsigned long)die->die_offset,
7649 dwarf_tag_name (die->die_tag));
7651 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7653 const char *name = dwarf_attr_name (a->dw_attr);
7655 switch (AT_class (a))
7657 case dw_val_class_addr:
7658 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7661 case dw_val_class_offset:
7662 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7666 case dw_val_class_range_list:
7668 char *p = strchr (ranges_section_label, '\0');
7670 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7671 a->dw_attr_val.v.val_offset);
7672 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7673 debug_ranges_section, "%s", name);
7678 case dw_val_class_loc:
7679 size = size_of_locs (AT_loc (a));
7681 /* Output the block length for this list of location operations. */
7682 dw2_asm_output_data (constant_size (size), size, "%s", name);
7684 output_loc_sequence (AT_loc (a));
7687 case dw_val_class_const:
7688 /* ??? It would be slightly more efficient to use a scheme like is
7689 used for unsigned constants below, but gdb 4.x does not sign
7690 extend. Gdb 5.x does sign extend. */
7691 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7694 case dw_val_class_unsigned_const:
7695 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7696 AT_unsigned (a), "%s", name);
7699 case dw_val_class_long_long:
7701 unsigned HOST_WIDE_INT first, second;
7703 dw2_asm_output_data (1,
7704 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7707 if (WORDS_BIG_ENDIAN)
7709 first = a->dw_attr_val.v.val_long_long.hi;
7710 second = a->dw_attr_val.v.val_long_long.low;
7714 first = a->dw_attr_val.v.val_long_long.low;
7715 second = a->dw_attr_val.v.val_long_long.hi;
7718 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7719 first, "long long constant");
7720 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7725 case dw_val_class_vec:
7727 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7728 unsigned int len = a->dw_attr_val.v.val_vec.length;
7732 dw2_asm_output_data (1, len * elt_size, "%s", name);
7733 if (elt_size > sizeof (HOST_WIDE_INT))
7738 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7741 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7742 "fp or vector constant word %u", i);
7746 case dw_val_class_flag:
7747 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7750 case dw_val_class_loc_list:
7752 char *sym = AT_loc_list (a)->ll_symbol;
7755 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7760 case dw_val_class_die_ref:
7761 if (AT_ref_external (a))
7763 char *sym = AT_ref (a)->die_symbol;
7766 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7771 gcc_assert (AT_ref (a)->die_offset);
7772 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7777 case dw_val_class_fde_ref:
7781 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7782 a->dw_attr_val.v.val_fde_index * 2);
7783 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7788 case dw_val_class_lbl_id:
7789 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7792 case dw_val_class_lineptr:
7793 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7794 debug_line_section, "%s", name);
7797 case dw_val_class_macptr:
7798 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7799 debug_macinfo_section, "%s", name);
7802 case dw_val_class_str:
7803 if (AT_string_form (a) == DW_FORM_strp)
7804 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7805 a->dw_attr_val.v.val_str->label,
7807 "%s: \"%s\"", name, AT_string (a));
7809 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7812 case dw_val_class_file:
7814 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7816 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7817 a->dw_attr_val.v.val_file->filename);
7826 FOR_EACH_CHILD (die, c, output_die (c));
7828 /* Add null byte to terminate sibling list. */
7829 if (die->die_child != NULL)
7830 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7831 (unsigned long) die->die_offset);
7834 /* Output the compilation unit that appears at the beginning of the
7835 .debug_info section, and precedes the DIE descriptions. */
7838 output_compilation_unit_header (void)
7840 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7841 dw2_asm_output_data (4, 0xffffffff,
7842 "Initial length escape value indicating 64-bit DWARF extension");
7843 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7844 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7845 "Length of Compilation Unit Info");
7846 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7847 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7848 debug_abbrev_section,
7849 "Offset Into Abbrev. Section");
7850 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7853 /* Output the compilation unit DIE and its children. */
7856 output_comp_unit (dw_die_ref die, int output_if_empty)
7858 const char *secname;
7861 /* Unless we are outputting main CU, we may throw away empty ones. */
7862 if (!output_if_empty && die->die_child == NULL)
7865 /* Even if there are no children of this DIE, we must output the information
7866 about the compilation unit. Otherwise, on an empty translation unit, we
7867 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7868 will then complain when examining the file. First mark all the DIEs in
7869 this CU so we know which get local refs. */
7872 build_abbrev_table (die);
7874 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7875 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7876 calc_die_sizes (die);
7878 oldsym = die->die_symbol;
7881 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
7883 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7885 die->die_symbol = NULL;
7886 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7889 switch_to_section (debug_info_section);
7891 /* Output debugging information. */
7892 output_compilation_unit_header ();
7895 /* Leave the marks on the main CU, so we can check them in
7900 die->die_symbol = oldsym;
7904 /* Return the DWARF2/3 pubname associated with a decl. */
7907 dwarf2_name (tree decl, int scope)
7909 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7912 /* Add a new entry to .debug_pubnames if appropriate. */
7915 add_pubname_string (const char *str, dw_die_ref die)
7920 e.name = xstrdup (str);
7921 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7925 add_pubname (tree decl, dw_die_ref die)
7928 if (TREE_PUBLIC (decl))
7929 add_pubname_string (dwarf2_name (decl, 1), die);
7932 /* Add a new entry to .debug_pubtypes if appropriate. */
7935 add_pubtype (tree decl, dw_die_ref die)
7940 if ((TREE_PUBLIC (decl)
7941 || die->die_parent == comp_unit_die)
7942 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7947 if (TYPE_NAME (decl))
7949 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7950 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7951 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7952 && DECL_NAME (TYPE_NAME (decl)))
7953 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7955 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7959 e.name = xstrdup (dwarf2_name (decl, 1));
7961 /* If we don't have a name for the type, there's no point in adding
7963 if (e.name && e.name[0] != '\0')
7964 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7968 /* Output the public names table used to speed up access to externally
7969 visible names; or the public types table used to find type definitions. */
7972 output_pubnames (VEC (pubname_entry, gc) * names)
7975 unsigned long pubnames_length = size_of_pubnames (names);
7978 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7979 dw2_asm_output_data (4, 0xffffffff,
7980 "Initial length escape value indicating 64-bit DWARF extension");
7981 if (names == pubname_table)
7982 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7983 "Length of Public Names Info");
7985 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7986 "Length of Public Type Names Info");
7987 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7988 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7990 "Offset of Compilation Unit Info");
7991 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7992 "Compilation Unit Length");
7994 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7996 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7997 if (names == pubname_table)
7998 gcc_assert (pub->die->die_mark);
8000 if (names != pubtype_table
8001 || pub->die->die_offset != 0
8002 || !flag_eliminate_unused_debug_types)
8004 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
8007 dw2_asm_output_nstring (pub->name, -1, "external name");
8011 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
8014 /* Add a new entry to .debug_aranges if appropriate. */
8017 add_arange (tree decl, dw_die_ref die)
8019 if (! DECL_SECTION_NAME (decl))
8022 if (arange_table_in_use == arange_table_allocated)
8024 arange_table_allocated += ARANGE_TABLE_INCREMENT;
8025 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
8026 arange_table_allocated);
8027 memset (arange_table + arange_table_in_use, 0,
8028 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
8031 arange_table[arange_table_in_use++] = die;
8034 /* Output the information that goes into the .debug_aranges table.
8035 Namely, define the beginning and ending address range of the
8036 text section generated for this compilation unit. */
8039 output_aranges (void)
8042 unsigned long aranges_length = size_of_aranges ();
8044 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8045 dw2_asm_output_data (4, 0xffffffff,
8046 "Initial length escape value indicating 64-bit DWARF extension");
8047 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
8048 "Length of Address Ranges Info");
8049 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8050 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
8052 "Offset of Compilation Unit Info");
8053 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
8054 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8056 /* We need to align to twice the pointer size here. */
8057 if (DWARF_ARANGES_PAD_SIZE)
8059 /* Pad using a 2 byte words so that padding is correct for any
8061 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8062 2 * DWARF2_ADDR_SIZE);
8063 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
8064 dw2_asm_output_data (2, 0, NULL);
8067 /* It is necessary not to output these entries if the sections were
8068 not used; if the sections were not used, the length will be 0 and
8069 the address may end up as 0 if the section is discarded by ld
8070 --gc-sections, leaving an invalid (0, 0) entry that can be
8071 confused with the terminator. */
8072 if (text_section_used)
8074 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
8075 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
8076 text_section_label, "Length");
8078 if (cold_text_section_used)
8080 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
8082 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
8083 cold_text_section_label, "Length");
8086 for (i = 0; i < arange_table_in_use; i++)
8088 dw_die_ref die = arange_table[i];
8090 /* We shouldn't see aranges for DIEs outside of the main CU. */
8091 gcc_assert (die->die_mark);
8093 if (die->die_tag == DW_TAG_subprogram)
8095 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
8097 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
8098 get_AT_low_pc (die), "Length");
8102 /* A static variable; extract the symbol from DW_AT_location.
8103 Note that this code isn't currently hit, as we only emit
8104 aranges for functions (jason 9/23/99). */
8105 dw_attr_ref a = get_AT (die, DW_AT_location);
8106 dw_loc_descr_ref loc;
8108 gcc_assert (a && AT_class (a) == dw_val_class_loc);
8111 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
8113 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
8114 loc->dw_loc_oprnd1.v.val_addr, "Address");
8115 dw2_asm_output_data (DWARF2_ADDR_SIZE,
8116 get_AT_unsigned (die, DW_AT_byte_size),
8121 /* Output the terminator words. */
8122 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8123 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8126 /* Add a new entry to .debug_ranges. Return the offset at which it
8130 add_ranges_num (int num)
8132 unsigned int in_use = ranges_table_in_use;
8134 if (in_use == ranges_table_allocated)
8136 ranges_table_allocated += RANGES_TABLE_INCREMENT;
8137 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
8138 ranges_table_allocated);
8139 memset (ranges_table + ranges_table_in_use, 0,
8140 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
8143 ranges_table[in_use].num = num;
8144 ranges_table_in_use = in_use + 1;
8146 return in_use * 2 * DWARF2_ADDR_SIZE;
8149 /* Add a new entry to .debug_ranges corresponding to a block, or a
8150 range terminator if BLOCK is NULL. */
8153 add_ranges (const_tree block)
8155 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
8158 /* Add a new entry to .debug_ranges corresponding to a pair of
8162 add_ranges_by_labels (const char *begin, const char *end)
8164 unsigned int in_use = ranges_by_label_in_use;
8166 if (in_use == ranges_by_label_allocated)
8168 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
8169 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
8171 ranges_by_label_allocated);
8172 memset (ranges_by_label + ranges_by_label_in_use, 0,
8173 RANGES_TABLE_INCREMENT
8174 * sizeof (struct dw_ranges_by_label_struct));
8177 ranges_by_label[in_use].begin = begin;
8178 ranges_by_label[in_use].end = end;
8179 ranges_by_label_in_use = in_use + 1;
8181 return add_ranges_num (-(int)in_use - 1);
8185 output_ranges (void)
8188 static const char *const start_fmt = "Offset 0x%x";
8189 const char *fmt = start_fmt;
8191 for (i = 0; i < ranges_table_in_use; i++)
8193 int block_num = ranges_table[i].num;
8197 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
8198 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
8200 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
8201 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
8203 /* If all code is in the text section, then the compilation
8204 unit base address defaults to DW_AT_low_pc, which is the
8205 base of the text section. */
8206 if (!have_multiple_function_sections)
8208 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
8210 fmt, i * 2 * DWARF2_ADDR_SIZE);
8211 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
8212 text_section_label, NULL);
8215 /* Otherwise, the compilation unit base address is zero,
8216 which allows us to use absolute addresses, and not worry
8217 about whether the target supports cross-section
8221 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
8222 fmt, i * 2 * DWARF2_ADDR_SIZE);
8223 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
8229 /* Negative block_num stands for an index into ranges_by_label. */
8230 else if (block_num < 0)
8232 int lab_idx = - block_num - 1;
8234 if (!have_multiple_function_sections)
8238 /* If we ever use add_ranges_by_labels () for a single
8239 function section, all we have to do is to take out
8241 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8242 ranges_by_label[lab_idx].begin,
8244 fmt, i * 2 * DWARF2_ADDR_SIZE);
8245 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
8246 ranges_by_label[lab_idx].end,
8247 text_section_label, NULL);
8252 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8253 ranges_by_label[lab_idx].begin,
8254 fmt, i * 2 * DWARF2_ADDR_SIZE);
8255 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
8256 ranges_by_label[lab_idx].end,
8262 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8263 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
8269 /* Data structure containing information about input files. */
8272 const char *path; /* Complete file name. */
8273 const char *fname; /* File name part. */
8274 int length; /* Length of entire string. */
8275 struct dwarf_file_data * file_idx; /* Index in input file table. */
8276 int dir_idx; /* Index in directory table. */
8279 /* Data structure containing information about directories with source
8283 const char *path; /* Path including directory name. */
8284 int length; /* Path length. */
8285 int prefix; /* Index of directory entry which is a prefix. */
8286 int count; /* Number of files in this directory. */
8287 int dir_idx; /* Index of directory used as base. */
8290 /* Callback function for file_info comparison. We sort by looking at
8291 the directories in the path. */
8294 file_info_cmp (const void *p1, const void *p2)
8296 const struct file_info *const s1 = (const struct file_info *) p1;
8297 const struct file_info *const s2 = (const struct file_info *) p2;
8298 const unsigned char *cp1;
8299 const unsigned char *cp2;
8301 /* Take care of file names without directories. We need to make sure that
8302 we return consistent values to qsort since some will get confused if
8303 we return the same value when identical operands are passed in opposite
8304 orders. So if neither has a directory, return 0 and otherwise return
8305 1 or -1 depending on which one has the directory. */
8306 if ((s1->path == s1->fname || s2->path == s2->fname))
8307 return (s2->path == s2->fname) - (s1->path == s1->fname);
8309 cp1 = (const unsigned char *) s1->path;
8310 cp2 = (const unsigned char *) s2->path;
8316 /* Reached the end of the first path? If so, handle like above. */
8317 if ((cp1 == (const unsigned char *) s1->fname)
8318 || (cp2 == (const unsigned char *) s2->fname))
8319 return ((cp2 == (const unsigned char *) s2->fname)
8320 - (cp1 == (const unsigned char *) s1->fname));
8322 /* Character of current path component the same? */
8323 else if (*cp1 != *cp2)
8328 struct file_name_acquire_data
8330 struct file_info *files;
8335 /* Traversal function for the hash table. */
8338 file_name_acquire (void ** slot, void *data)
8340 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
8341 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
8342 struct file_info *fi;
8345 gcc_assert (fnad->max_files >= d->emitted_number);
8347 if (! d->emitted_number)
8350 gcc_assert (fnad->max_files != fnad->used_files);
8352 fi = fnad->files + fnad->used_files++;
8354 /* Skip all leading "./". */
8356 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
8359 /* Create a new array entry. */
8361 fi->length = strlen (f);
8364 /* Search for the file name part. */
8365 f = strrchr (f, DIR_SEPARATOR);
8366 #if defined (DIR_SEPARATOR_2)
8368 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
8372 if (f == NULL || f < g)
8378 fi->fname = f == NULL ? fi->path : f + 1;
8382 /* Output the directory table and the file name table. We try to minimize
8383 the total amount of memory needed. A heuristic is used to avoid large
8384 slowdowns with many input files. */
8387 output_file_names (void)
8389 struct file_name_acquire_data fnad;
8391 struct file_info *files;
8392 struct dir_info *dirs;
8401 if (!last_emitted_file)
8403 dw2_asm_output_data (1, 0, "End directory table");
8404 dw2_asm_output_data (1, 0, "End file name table");
8408 numfiles = last_emitted_file->emitted_number;
8410 /* Allocate the various arrays we need. */
8411 files = XALLOCAVEC (struct file_info, numfiles);
8412 dirs = XALLOCAVEC (struct dir_info, numfiles);
8415 fnad.used_files = 0;
8416 fnad.max_files = numfiles;
8417 htab_traverse (file_table, file_name_acquire, &fnad);
8418 gcc_assert (fnad.used_files == fnad.max_files);
8420 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8422 /* Find all the different directories used. */
8423 dirs[0].path = files[0].path;
8424 dirs[0].length = files[0].fname - files[0].path;
8425 dirs[0].prefix = -1;
8427 dirs[0].dir_idx = 0;
8428 files[0].dir_idx = 0;
8431 for (i = 1; i < numfiles; i++)
8432 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8433 && memcmp (dirs[ndirs - 1].path, files[i].path,
8434 dirs[ndirs - 1].length) == 0)
8436 /* Same directory as last entry. */
8437 files[i].dir_idx = ndirs - 1;
8438 ++dirs[ndirs - 1].count;
8444 /* This is a new directory. */
8445 dirs[ndirs].path = files[i].path;
8446 dirs[ndirs].length = files[i].fname - files[i].path;
8447 dirs[ndirs].count = 1;
8448 dirs[ndirs].dir_idx = ndirs;
8449 files[i].dir_idx = ndirs;
8451 /* Search for a prefix. */
8452 dirs[ndirs].prefix = -1;
8453 for (j = 0; j < ndirs; j++)
8454 if (dirs[j].length < dirs[ndirs].length
8455 && dirs[j].length > 1
8456 && (dirs[ndirs].prefix == -1
8457 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8458 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8459 dirs[ndirs].prefix = j;
8464 /* Now to the actual work. We have to find a subset of the directories which
8465 allow expressing the file name using references to the directory table
8466 with the least amount of characters. We do not do an exhaustive search
8467 where we would have to check out every combination of every single
8468 possible prefix. Instead we use a heuristic which provides nearly optimal
8469 results in most cases and never is much off. */
8470 saved = XALLOCAVEC (int, ndirs);
8471 savehere = XALLOCAVEC (int, ndirs);
8473 memset (saved, '\0', ndirs * sizeof (saved[0]));
8474 for (i = 0; i < ndirs; i++)
8479 /* We can always save some space for the current directory. But this
8480 does not mean it will be enough to justify adding the directory. */
8481 savehere[i] = dirs[i].length;
8482 total = (savehere[i] - saved[i]) * dirs[i].count;
8484 for (j = i + 1; j < ndirs; j++)
8487 if (saved[j] < dirs[i].length)
8489 /* Determine whether the dirs[i] path is a prefix of the
8494 while (k != -1 && k != (int) i)
8499 /* Yes it is. We can possibly save some memory by
8500 writing the filenames in dirs[j] relative to
8502 savehere[j] = dirs[i].length;
8503 total += (savehere[j] - saved[j]) * dirs[j].count;
8508 /* Check whether we can save enough to justify adding the dirs[i]
8510 if (total > dirs[i].length + 1)
8512 /* It's worthwhile adding. */
8513 for (j = i; j < ndirs; j++)
8514 if (savehere[j] > 0)
8516 /* Remember how much we saved for this directory so far. */
8517 saved[j] = savehere[j];
8519 /* Remember the prefix directory. */
8520 dirs[j].dir_idx = i;
8525 /* Emit the directory name table. */
8527 idx_offset = dirs[0].length > 0 ? 1 : 0;
8528 for (i = 1 - idx_offset; i < ndirs; i++)
8529 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8530 "Directory Entry: 0x%x", i + idx_offset);
8532 dw2_asm_output_data (1, 0, "End directory table");
8534 /* We have to emit them in the order of emitted_number since that's
8535 used in the debug info generation. To do this efficiently we
8536 generate a back-mapping of the indices first. */
8537 backmap = XALLOCAVEC (int, numfiles);
8538 for (i = 0; i < numfiles; i++)
8539 backmap[files[i].file_idx->emitted_number - 1] = i;
8541 /* Now write all the file names. */
8542 for (i = 0; i < numfiles; i++)
8544 int file_idx = backmap[i];
8545 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8547 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8548 "File Entry: 0x%x", (unsigned) i + 1);
8550 /* Include directory index. */
8551 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8553 /* Modification time. */
8554 dw2_asm_output_data_uleb128 (0, NULL);
8556 /* File length in bytes. */
8557 dw2_asm_output_data_uleb128 (0, NULL);
8560 dw2_asm_output_data (1, 0, "End file name table");
8564 /* Output the source line number correspondence information. This
8565 information goes into the .debug_line section. */
8568 output_line_info (void)
8570 char l1[20], l2[20], p1[20], p2[20];
8571 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8572 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8575 unsigned long lt_index;
8576 unsigned long current_line;
8579 unsigned long current_file;
8580 unsigned long function;
8582 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8583 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8584 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8585 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8587 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8588 dw2_asm_output_data (4, 0xffffffff,
8589 "Initial length escape value indicating 64-bit DWARF extension");
8590 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8591 "Length of Source Line Info");
8592 ASM_OUTPUT_LABEL (asm_out_file, l1);
8594 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8595 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8596 ASM_OUTPUT_LABEL (asm_out_file, p1);
8598 /* Define the architecture-dependent minimum instruction length (in
8599 bytes). In this implementation of DWARF, this field is used for
8600 information purposes only. Since GCC generates assembly language,
8601 we have no a priori knowledge of how many instruction bytes are
8602 generated for each source line, and therefore can use only the
8603 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8604 commands. Accordingly, we fix this as `1', which is "correct
8605 enough" for all architectures, and don't let the target override. */
8606 dw2_asm_output_data (1, 1,
8607 "Minimum Instruction Length");
8609 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8610 "Default is_stmt_start flag");
8611 dw2_asm_output_data (1, DWARF_LINE_BASE,
8612 "Line Base Value (Special Opcodes)");
8613 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8614 "Line Range Value (Special Opcodes)");
8615 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8616 "Special Opcode Base");
8618 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8622 case DW_LNS_advance_pc:
8623 case DW_LNS_advance_line:
8624 case DW_LNS_set_file:
8625 case DW_LNS_set_column:
8626 case DW_LNS_fixed_advance_pc:
8634 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8638 /* Write out the information about the files we use. */
8639 output_file_names ();
8640 ASM_OUTPUT_LABEL (asm_out_file, p2);
8642 /* We used to set the address register to the first location in the text
8643 section here, but that didn't accomplish anything since we already
8644 have a line note for the opening brace of the first function. */
8646 /* Generate the line number to PC correspondence table, encoded as
8647 a series of state machine operations. */
8651 if (cfun && in_cold_section_p)
8652 strcpy (prev_line_label, crtl->subsections.cold_section_label);
8654 strcpy (prev_line_label, text_section_label);
8655 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8657 dw_line_info_ref line_info = &line_info_table[lt_index];
8660 /* Disable this optimization for now; GDB wants to see two line notes
8661 at the beginning of a function so it can find the end of the
8664 /* Don't emit anything for redundant notes. Just updating the
8665 address doesn't accomplish anything, because we already assume
8666 that anything after the last address is this line. */
8667 if (line_info->dw_line_num == current_line
8668 && line_info->dw_file_num == current_file)
8672 /* Emit debug info for the address of the current line.
8674 Unfortunately, we have little choice here currently, and must always
8675 use the most general form. GCC does not know the address delta
8676 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8677 attributes which will give an upper bound on the address range. We
8678 could perhaps use length attributes to determine when it is safe to
8679 use DW_LNS_fixed_advance_pc. */
8681 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8684 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8685 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8686 "DW_LNS_fixed_advance_pc");
8687 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8691 /* This can handle any delta. This takes
8692 4+DWARF2_ADDR_SIZE bytes. */
8693 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8694 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8695 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8696 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8699 strcpy (prev_line_label, line_label);
8701 /* Emit debug info for the source file of the current line, if
8702 different from the previous line. */
8703 if (line_info->dw_file_num != current_file)
8705 current_file = line_info->dw_file_num;
8706 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8707 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8710 /* Emit debug info for the current line number, choosing the encoding
8711 that uses the least amount of space. */
8712 if (line_info->dw_line_num != current_line)
8714 line_offset = line_info->dw_line_num - current_line;
8715 line_delta = line_offset - DWARF_LINE_BASE;
8716 current_line = line_info->dw_line_num;
8717 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8718 /* This can handle deltas from -10 to 234, using the current
8719 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8721 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8722 "line %lu", current_line);
8725 /* This can handle any delta. This takes at least 4 bytes,
8726 depending on the value being encoded. */
8727 dw2_asm_output_data (1, DW_LNS_advance_line,
8728 "advance to line %lu", current_line);
8729 dw2_asm_output_data_sleb128 (line_offset, NULL);
8730 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8734 /* We still need to start a new row, so output a copy insn. */
8735 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8738 /* Emit debug info for the address of the end of the function. */
8741 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8742 "DW_LNS_fixed_advance_pc");
8743 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8747 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8748 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8749 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8750 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8753 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8754 dw2_asm_output_data_uleb128 (1, NULL);
8755 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8760 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8762 dw_separate_line_info_ref line_info
8763 = &separate_line_info_table[lt_index];
8766 /* Don't emit anything for redundant notes. */
8767 if (line_info->dw_line_num == current_line
8768 && line_info->dw_file_num == current_file
8769 && line_info->function == function)
8773 /* Emit debug info for the address of the current line. If this is
8774 a new function, or the first line of a function, then we need
8775 to handle it differently. */
8776 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8778 if (function != line_info->function)
8780 function = line_info->function;
8782 /* Set the address register to the first line in the function. */
8783 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8784 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8785 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8786 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8790 /* ??? See the DW_LNS_advance_pc comment above. */
8793 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8794 "DW_LNS_fixed_advance_pc");
8795 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8799 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8800 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8801 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8802 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8806 strcpy (prev_line_label, line_label);
8808 /* Emit debug info for the source file of the current line, if
8809 different from the previous line. */
8810 if (line_info->dw_file_num != current_file)
8812 current_file = line_info->dw_file_num;
8813 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8814 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8817 /* Emit debug info for the current line number, choosing the encoding
8818 that uses the least amount of space. */
8819 if (line_info->dw_line_num != current_line)
8821 line_offset = line_info->dw_line_num - current_line;
8822 line_delta = line_offset - DWARF_LINE_BASE;
8823 current_line = line_info->dw_line_num;
8824 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8825 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8826 "line %lu", current_line);
8829 dw2_asm_output_data (1, DW_LNS_advance_line,
8830 "advance to line %lu", current_line);
8831 dw2_asm_output_data_sleb128 (line_offset, NULL);
8832 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8836 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8844 /* If we're done with a function, end its sequence. */
8845 if (lt_index == separate_line_info_table_in_use
8846 || separate_line_info_table[lt_index].function != function)
8851 /* Emit debug info for the address of the end of the function. */
8852 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8855 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8856 "DW_LNS_fixed_advance_pc");
8857 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8861 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8862 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8863 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8864 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8867 /* Output the marker for the end of this sequence. */
8868 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8869 dw2_asm_output_data_uleb128 (1, NULL);
8870 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8874 /* Output the marker for the end of the line number info. */
8875 ASM_OUTPUT_LABEL (asm_out_file, l2);
8878 /* Given a pointer to a tree node for some base type, return a pointer to
8879 a DIE that describes the given type.
8881 This routine must only be called for GCC type nodes that correspond to
8882 Dwarf base (fundamental) types. */
8885 base_type_die (tree type)
8887 dw_die_ref base_type_result;
8888 enum dwarf_type encoding;
8890 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8893 switch (TREE_CODE (type))
8896 if (TYPE_STRING_FLAG (type))
8898 if (TYPE_UNSIGNED (type))
8899 encoding = DW_ATE_unsigned_char;
8901 encoding = DW_ATE_signed_char;
8903 else if (TYPE_UNSIGNED (type))
8904 encoding = DW_ATE_unsigned;
8906 encoding = DW_ATE_signed;
8910 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8911 encoding = DW_ATE_decimal_float;
8913 encoding = DW_ATE_float;
8916 case FIXED_POINT_TYPE:
8917 if (TYPE_UNSIGNED (type))
8918 encoding = DW_ATE_unsigned_fixed;
8920 encoding = DW_ATE_signed_fixed;
8923 /* Dwarf2 doesn't know anything about complex ints, so use
8924 a user defined type for it. */
8926 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8927 encoding = DW_ATE_complex_float;
8929 encoding = DW_ATE_lo_user;
8933 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8934 encoding = DW_ATE_boolean;
8938 /* No other TREE_CODEs are Dwarf fundamental types. */
8942 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8944 /* This probably indicates a bug. */
8945 if (! TYPE_NAME (type))
8946 add_name_attribute (base_type_result, "__unknown__");
8948 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8949 int_size_in_bytes (type));
8950 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8952 return base_type_result;
8955 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8956 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8959 is_base_type (tree type)
8961 switch (TREE_CODE (type))
8967 case FIXED_POINT_TYPE:
8975 case QUAL_UNION_TYPE:
8980 case REFERENCE_TYPE:
8993 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8994 node, return the size in bits for the type if it is a constant, or else
8995 return the alignment for the type if the type's size is not constant, or
8996 else return BITS_PER_WORD if the type actually turns out to be an
8999 static inline unsigned HOST_WIDE_INT
9000 simple_type_size_in_bits (const_tree type)
9002 if (TREE_CODE (type) == ERROR_MARK)
9003 return BITS_PER_WORD;
9004 else if (TYPE_SIZE (type) == NULL_TREE)
9006 else if (host_integerp (TYPE_SIZE (type), 1))
9007 return tree_low_cst (TYPE_SIZE (type), 1);
9009 return TYPE_ALIGN (type);
9012 /* Return true if the debug information for the given type should be
9013 emitted as a subrange type. */
9016 is_subrange_type (const_tree type)
9018 tree subtype = TREE_TYPE (type);
9020 /* Subrange types are identified by the fact that they are integer
9021 types, and that they have a subtype which is either an integer type
9022 or an enumeral type. */
9024 if (TREE_CODE (type) != INTEGER_TYPE
9025 || subtype == NULL_TREE)
9028 if (TREE_CODE (subtype) != INTEGER_TYPE
9029 && TREE_CODE (subtype) != ENUMERAL_TYPE
9030 && TREE_CODE (subtype) != BOOLEAN_TYPE)
9033 if (TREE_CODE (type) == TREE_CODE (subtype)
9034 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
9035 && TYPE_MIN_VALUE (type) != NULL
9036 && TYPE_MIN_VALUE (subtype) != NULL
9037 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
9038 && TYPE_MAX_VALUE (type) != NULL
9039 && TYPE_MAX_VALUE (subtype) != NULL
9040 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
9042 /* The type and its subtype have the same representation. If in
9043 addition the two types also have the same name, then the given
9044 type is not a subrange type, but rather a plain base type. */
9045 /* FIXME: brobecker/2004-03-22:
9046 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9047 therefore be sufficient to check the TYPE_SIZE node pointers
9048 rather than checking the actual size. Unfortunately, we have
9049 found some cases, such as in the Ada "integer" type, where
9050 this is not the case. Until this problem is solved, we need to
9051 keep checking the actual size. */
9052 tree type_name = TYPE_NAME (type);
9053 tree subtype_name = TYPE_NAME (subtype);
9055 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
9056 type_name = DECL_NAME (type_name);
9058 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
9059 subtype_name = DECL_NAME (subtype_name);
9061 if (type_name == subtype_name)
9068 /* Given a pointer to a tree node for a subrange type, return a pointer
9069 to a DIE that describes the given type. */
9072 subrange_type_die (tree type, dw_die_ref context_die)
9074 dw_die_ref subrange_die;
9075 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
9077 if (context_die == NULL)
9078 context_die = comp_unit_die;
9080 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
9082 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
9084 /* The size of the subrange type and its base type do not match,
9085 so we need to generate a size attribute for the subrange type. */
9086 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
9089 if (TYPE_MIN_VALUE (type) != NULL)
9090 add_bound_info (subrange_die, DW_AT_lower_bound,
9091 TYPE_MIN_VALUE (type));
9092 if (TYPE_MAX_VALUE (type) != NULL)
9093 add_bound_info (subrange_die, DW_AT_upper_bound,
9094 TYPE_MAX_VALUE (type));
9096 return subrange_die;
9099 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9100 entry that chains various modifiers in front of the given type. */
9103 modified_type_die (tree type, int is_const_type, int is_volatile_type,
9104 dw_die_ref context_die)
9106 enum tree_code code = TREE_CODE (type);
9107 dw_die_ref mod_type_die;
9108 dw_die_ref sub_die = NULL;
9109 tree item_type = NULL;
9110 tree qualified_type;
9113 if (code == ERROR_MARK)
9116 /* See if we already have the appropriately qualified variant of
9119 = get_qualified_type (type,
9120 ((is_const_type ? TYPE_QUAL_CONST : 0)
9121 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
9123 /* If we do, then we can just use its DIE, if it exists. */
9126 mod_type_die = lookup_type_die (qualified_type);
9128 return mod_type_die;
9131 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
9133 /* Handle C typedef types. */
9134 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
9136 tree dtype = TREE_TYPE (name);
9138 if (qualified_type == dtype)
9140 /* For a named type, use the typedef. */
9141 gen_type_die (qualified_type, context_die);
9142 return lookup_type_die (qualified_type);
9144 else if (is_const_type < TYPE_READONLY (dtype)
9145 || is_volatile_type < TYPE_VOLATILE (dtype)
9146 || (is_const_type <= TYPE_READONLY (dtype)
9147 && is_volatile_type <= TYPE_VOLATILE (dtype)
9148 && DECL_ORIGINAL_TYPE (name) != type))
9149 /* cv-unqualified version of named type. Just use the unnamed
9150 type to which it refers. */
9151 return modified_type_die (DECL_ORIGINAL_TYPE (name),
9152 is_const_type, is_volatile_type,
9154 /* Else cv-qualified version of named type; fall through. */
9159 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
9160 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
9162 else if (is_volatile_type)
9164 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
9165 sub_die = modified_type_die (type, 0, 0, context_die);
9167 else if (code == POINTER_TYPE)
9169 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
9170 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9171 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9172 item_type = TREE_TYPE (type);
9174 else if (code == REFERENCE_TYPE)
9176 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
9177 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
9178 simple_type_size_in_bits (type) / BITS_PER_UNIT);
9179 item_type = TREE_TYPE (type);
9181 else if (is_subrange_type (type))
9183 mod_type_die = subrange_type_die (type, context_die);
9184 item_type = TREE_TYPE (type);
9186 else if (is_base_type (type))
9187 mod_type_die = base_type_die (type);
9190 gen_type_die (type, context_die);
9192 /* We have to get the type_main_variant here (and pass that to the
9193 `lookup_type_die' routine) because the ..._TYPE node we have
9194 might simply be a *copy* of some original type node (where the
9195 copy was created to help us keep track of typedef names) and
9196 that copy might have a different TYPE_UID from the original
9198 if (TREE_CODE (type) != VECTOR_TYPE)
9199 return lookup_type_die (type_main_variant (type));
9201 /* Vectors have the debugging information in the type,
9202 not the main variant. */
9203 return lookup_type_die (type);
9206 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9207 don't output a DW_TAG_typedef, since there isn't one in the
9208 user's program; just attach a DW_AT_name to the type. */
9210 && (TREE_CODE (name) != TYPE_DECL
9211 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
9213 if (TREE_CODE (name) == TYPE_DECL)
9214 /* Could just call add_name_and_src_coords_attributes here,
9215 but since this is a builtin type it doesn't have any
9216 useful source coordinates anyway. */
9217 name = DECL_NAME (name);
9218 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
9222 equate_type_number_to_die (qualified_type, mod_type_die);
9225 /* We must do this after the equate_type_number_to_die call, in case
9226 this is a recursive type. This ensures that the modified_type_die
9227 recursion will terminate even if the type is recursive. Recursive
9228 types are possible in Ada. */
9229 sub_die = modified_type_die (item_type,
9230 TYPE_READONLY (item_type),
9231 TYPE_VOLATILE (item_type),
9234 if (sub_die != NULL)
9235 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
9237 return mod_type_die;
9240 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9241 an enumerated type. */
9244 type_is_enum (const_tree type)
9246 return TREE_CODE (type) == ENUMERAL_TYPE;
9249 /* Return the DBX register number described by a given RTL node. */
9252 dbx_reg_number (const_rtx rtl)
9254 unsigned regno = REGNO (rtl);
9256 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
9258 #ifdef LEAF_REG_REMAP
9259 if (current_function_uses_only_leaf_regs)
9261 int leaf_reg = LEAF_REG_REMAP (regno);
9263 regno = (unsigned) leaf_reg;
9267 return DBX_REGISTER_NUMBER (regno);
9270 /* Optionally add a DW_OP_piece term to a location description expression.
9271 DW_OP_piece is only added if the location description expression already
9272 doesn't end with DW_OP_piece. */
9275 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
9277 dw_loc_descr_ref loc;
9279 if (*list_head != NULL)
9281 /* Find the end of the chain. */
9282 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
9285 if (loc->dw_loc_opc != DW_OP_piece)
9286 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
9290 /* Return a location descriptor that designates a machine register or
9291 zero if there is none. */
9293 static dw_loc_descr_ref
9294 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
9298 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
9301 regs = targetm.dwarf_register_span (rtl);
9303 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
9304 return multiple_reg_loc_descriptor (rtl, regs, initialized);
9306 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
9309 /* Return a location descriptor that designates a machine register for
9310 a given hard register number. */
9312 static dw_loc_descr_ref
9313 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
9315 dw_loc_descr_ref reg_loc_descr;
9317 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
9319 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
9321 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9322 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9324 return reg_loc_descr;
9327 /* Given an RTL of a register, return a location descriptor that
9328 designates a value that spans more than one register. */
9330 static dw_loc_descr_ref
9331 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
9332 enum var_init_status initialized)
9336 dw_loc_descr_ref loc_result = NULL;
9339 #ifdef LEAF_REG_REMAP
9340 if (current_function_uses_only_leaf_regs)
9342 int leaf_reg = LEAF_REG_REMAP (reg);
9344 reg = (unsigned) leaf_reg;
9347 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
9348 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
9350 /* Simple, contiguous registers. */
9351 if (regs == NULL_RTX)
9353 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
9360 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
9361 VAR_INIT_STATUS_INITIALIZED);
9362 add_loc_descr (&loc_result, t);
9363 add_loc_descr_op_piece (&loc_result, size);
9369 /* Now onto stupid register sets in non contiguous locations. */
9371 gcc_assert (GET_CODE (regs) == PARALLEL);
9373 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9376 for (i = 0; i < XVECLEN (regs, 0); ++i)
9380 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
9381 VAR_INIT_STATUS_INITIALIZED);
9382 add_loc_descr (&loc_result, t);
9383 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
9384 add_loc_descr_op_piece (&loc_result, size);
9387 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9388 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9392 #endif /* DWARF2_DEBUGGING_INFO */
9394 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9396 /* Return a location descriptor that designates a constant. */
9398 static dw_loc_descr_ref
9399 int_loc_descriptor (HOST_WIDE_INT i)
9401 enum dwarf_location_atom op;
9403 /* Pick the smallest representation of a constant, rather than just
9404 defaulting to the LEB encoding. */
9408 op = DW_OP_lit0 + i;
9411 else if (i <= 0xffff)
9413 else if (HOST_BITS_PER_WIDE_INT == 32
9423 else if (i >= -0x8000)
9425 else if (HOST_BITS_PER_WIDE_INT == 32
9426 || i >= -0x80000000)
9432 return new_loc_descr (op, i, 0);
9436 #ifdef DWARF2_DEBUGGING_INFO
9438 /* Return a location descriptor that designates a base+offset location. */
9440 static dw_loc_descr_ref
9441 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9442 enum var_init_status initialized)
9445 dw_loc_descr_ref result;
9446 dw_fde_ref fde = current_fde ();
9448 /* We only use "frame base" when we're sure we're talking about the
9449 post-prologue local stack frame. We do this by *not* running
9450 register elimination until this point, and recognizing the special
9451 argument pointer and soft frame pointer rtx's. */
9452 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9454 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9458 if (GET_CODE (elim) == PLUS)
9460 offset += INTVAL (XEXP (elim, 1));
9461 elim = XEXP (elim, 0);
9463 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9464 && (elim == hard_frame_pointer_rtx
9465 || elim == stack_pointer_rtx))
9466 || elim == (frame_pointer_needed
9467 ? hard_frame_pointer_rtx
9468 : stack_pointer_rtx));
9470 /* If drap register is used to align stack, use frame
9471 pointer + offset to access stack variables. If stack
9472 is aligned without drap, use stack pointer + offset to
9473 access stack variables. */
9474 if (crtl->stack_realign_tried
9475 && cfa.reg == HARD_FRAME_POINTER_REGNUM
9476 && reg == frame_pointer_rtx)
9479 = DWARF_FRAME_REGNUM (cfa.indirect
9480 ? HARD_FRAME_POINTER_REGNUM
9481 : STACK_POINTER_REGNUM);
9483 return new_loc_descr (DW_OP_breg0 + base_reg, offset, 0);
9485 return new_loc_descr (DW_OP_bregx, base_reg, offset);
9488 offset += frame_pointer_fb_offset;
9489 return new_loc_descr (DW_OP_fbreg, offset, 0);
9493 && fde->drap_reg != INVALID_REGNUM
9494 && (fde->drap_reg == REGNO (reg)
9495 || fde->vdrap_reg == REGNO (reg)))
9497 /* Use cfa+offset to represent the location of arguments passed
9498 on stack when drap is used to align stack. */
9499 return new_loc_descr (DW_OP_fbreg, offset, 0);
9502 regno = dbx_reg_number (reg);
9504 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9506 result = new_loc_descr (DW_OP_bregx, regno, offset);
9508 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9509 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9514 /* Return true if this RTL expression describes a base+offset calculation. */
9517 is_based_loc (const_rtx rtl)
9519 return (GET_CODE (rtl) == PLUS
9520 && ((REG_P (XEXP (rtl, 0))
9521 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9522 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9525 /* Return a descriptor that describes the concatenation of N locations
9526 used to form the address of a memory location. */
9528 static dw_loc_descr_ref
9529 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9530 enum var_init_status initialized)
9533 dw_loc_descr_ref cc_loc_result = NULL;
9534 unsigned int n = XVECLEN (concatn, 0);
9536 for (i = 0; i < n; ++i)
9538 dw_loc_descr_ref ref;
9539 rtx x = XVECEXP (concatn, 0, i);
9541 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9545 add_loc_descr (&cc_loc_result, ref);
9546 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9549 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9550 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9552 return cc_loc_result;
9555 /* The following routine converts the RTL for a variable or parameter
9556 (resident in memory) into an equivalent Dwarf representation of a
9557 mechanism for getting the address of that same variable onto the top of a
9558 hypothetical "address evaluation" stack.
9560 When creating memory location descriptors, we are effectively transforming
9561 the RTL for a memory-resident object into its Dwarf postfix expression
9562 equivalent. This routine recursively descends an RTL tree, turning
9563 it into Dwarf postfix code as it goes.
9565 MODE is the mode of the memory reference, needed to handle some
9566 autoincrement addressing modes.
9568 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9569 location list for RTL.
9571 Return 0 if we can't represent the location. */
9573 static dw_loc_descr_ref
9574 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9575 enum var_init_status initialized)
9577 dw_loc_descr_ref mem_loc_result = NULL;
9578 enum dwarf_location_atom op;
9580 /* Note that for a dynamically sized array, the location we will generate a
9581 description of here will be the lowest numbered location which is
9582 actually within the array. That's *not* necessarily the same as the
9583 zeroth element of the array. */
9585 rtl = targetm.delegitimize_address (rtl);
9587 switch (GET_CODE (rtl))
9592 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9593 just fall into the SUBREG code. */
9595 /* ... fall through ... */
9598 /* The case of a subreg may arise when we have a local (register)
9599 variable or a formal (register) parameter which doesn't quite fill
9600 up an entire register. For now, just assume that it is
9601 legitimate to make the Dwarf info refer to the whole register which
9602 contains the given subreg. */
9603 rtl = XEXP (rtl, 0);
9605 /* ... fall through ... */
9608 /* Whenever a register number forms a part of the description of the
9609 method for calculating the (dynamic) address of a memory resident
9610 object, DWARF rules require the register number be referred to as
9611 a "base register". This distinction is not based in any way upon
9612 what category of register the hardware believes the given register
9613 belongs to. This is strictly DWARF terminology we're dealing with
9614 here. Note that in cases where the location of a memory-resident
9615 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9616 OP_CONST (0)) the actual DWARF location descriptor that we generate
9617 may just be OP_BASEREG (basereg). This may look deceptively like
9618 the object in question was allocated to a register (rather than in
9619 memory) so DWARF consumers need to be aware of the subtle
9620 distinction between OP_REG and OP_BASEREG. */
9621 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9622 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9626 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9627 VAR_INIT_STATUS_INITIALIZED);
9628 if (mem_loc_result != 0)
9629 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9633 rtl = XEXP (rtl, 1);
9635 /* ... fall through ... */
9638 /* Some ports can transform a symbol ref into a label ref, because
9639 the symbol ref is too far away and has to be dumped into a constant
9643 /* Alternatively, the symbol in the constant pool might be referenced
9644 by a different symbol. */
9645 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9648 rtx tmp = get_pool_constant_mark (rtl, &marked);
9650 if (GET_CODE (tmp) == SYMBOL_REF)
9653 if (CONSTANT_POOL_ADDRESS_P (tmp))
9654 get_pool_constant_mark (tmp, &marked);
9659 /* If all references to this pool constant were optimized away,
9660 it was not output and thus we can't represent it.
9661 FIXME: might try to use DW_OP_const_value here, though
9662 DW_OP_piece complicates it. */
9667 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9668 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9669 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9670 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9674 /* Extract the PLUS expression nested inside and fall into
9676 rtl = XEXP (rtl, 1);
9681 /* Turn these into a PLUS expression and fall into the PLUS code
9683 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
9684 GEN_INT (GET_CODE (rtl) == PRE_INC
9685 ? GET_MODE_UNIT_SIZE (mode)
9686 : -GET_MODE_UNIT_SIZE (mode)));
9688 /* ... fall through ... */
9692 if (is_based_loc (rtl))
9693 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
9694 INTVAL (XEXP (rtl, 1)),
9695 VAR_INIT_STATUS_INITIALIZED);
9698 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
9699 VAR_INIT_STATUS_INITIALIZED);
9700 if (mem_loc_result == 0)
9703 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
9704 && INTVAL (XEXP (rtl, 1)) >= 0)
9705 add_loc_descr (&mem_loc_result,
9706 new_loc_descr (DW_OP_plus_uconst,
9707 INTVAL (XEXP (rtl, 1)), 0));
9710 add_loc_descr (&mem_loc_result,
9711 mem_loc_descriptor (XEXP (rtl, 1), mode,
9712 VAR_INIT_STATUS_INITIALIZED));
9713 add_loc_descr (&mem_loc_result,
9714 new_loc_descr (DW_OP_plus, 0, 0));
9719 /* If a pseudo-reg is optimized away, it is possible for it to
9720 be replaced with a MEM containing a multiply or shift. */
9739 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
9740 VAR_INIT_STATUS_INITIALIZED);
9741 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
9742 VAR_INIT_STATUS_INITIALIZED);
9744 if (op0 == 0 || op1 == 0)
9747 mem_loc_result = op0;
9748 add_loc_descr (&mem_loc_result, op1);
9749 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9754 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9758 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
9759 VAR_INIT_STATUS_INITIALIZED);
9766 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9767 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9769 return mem_loc_result;
9772 /* Return a descriptor that describes the concatenation of two locations.
9773 This is typically a complex variable. */
9775 static dw_loc_descr_ref
9776 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
9778 dw_loc_descr_ref cc_loc_result = NULL;
9779 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
9780 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
9782 if (x0_ref == 0 || x1_ref == 0)
9785 cc_loc_result = x0_ref;
9786 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9788 add_loc_descr (&cc_loc_result, x1_ref);
9789 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9791 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9792 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9794 return cc_loc_result;
9797 /* Return a descriptor that describes the concatenation of N
9800 static dw_loc_descr_ref
9801 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
9804 dw_loc_descr_ref cc_loc_result = NULL;
9805 unsigned int n = XVECLEN (concatn, 0);
9807 for (i = 0; i < n; ++i)
9809 dw_loc_descr_ref ref;
9810 rtx x = XVECEXP (concatn, 0, i);
9812 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
9816 add_loc_descr (&cc_loc_result, ref);
9817 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9820 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9821 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9823 return cc_loc_result;
9826 /* Output a proper Dwarf location descriptor for a variable or parameter
9827 which is either allocated in a register or in a memory location. For a
9828 register, we just generate an OP_REG and the register number. For a
9829 memory location we provide a Dwarf postfix expression describing how to
9830 generate the (dynamic) address of the object onto the address stack.
9832 If we don't know how to describe it, return 0. */
9834 static dw_loc_descr_ref
9835 loc_descriptor (rtx rtl, enum var_init_status initialized)
9837 dw_loc_descr_ref loc_result = NULL;
9839 switch (GET_CODE (rtl))
9842 /* The case of a subreg may arise when we have a local (register)
9843 variable or a formal (register) parameter which doesn't quite fill
9844 up an entire register. For now, just assume that it is
9845 legitimate to make the Dwarf info refer to the whole register which
9846 contains the given subreg. */
9847 rtl = SUBREG_REG (rtl);
9849 /* ... fall through ... */
9852 loc_result = reg_loc_descriptor (rtl, initialized);
9856 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9861 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
9866 loc_result = concatn_loc_descriptor (rtl, initialized);
9871 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9873 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
9877 rtl = XEXP (rtl, 1);
9882 rtvec par_elems = XVEC (rtl, 0);
9883 int num_elem = GET_NUM_ELEM (par_elems);
9884 enum machine_mode mode;
9887 /* Create the first one, so we have something to add to. */
9888 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
9890 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9891 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9892 for (i = 1; i < num_elem; i++)
9894 dw_loc_descr_ref temp;
9896 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
9898 add_loc_descr (&loc_result, temp);
9899 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9900 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9912 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9913 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9914 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9915 top-level invocation, and we require the address of LOC; is 0 if we require
9916 the value of LOC. */
9918 static dw_loc_descr_ref
9919 loc_descriptor_from_tree_1 (tree loc, int want_address)
9921 dw_loc_descr_ref ret, ret1;
9922 int have_address = 0;
9923 enum dwarf_location_atom op;
9925 /* ??? Most of the time we do not take proper care for sign/zero
9926 extending the values properly. Hopefully this won't be a real
9929 switch (TREE_CODE (loc))
9934 case PLACEHOLDER_EXPR:
9935 /* This case involves extracting fields from an object to determine the
9936 position of other fields. We don't try to encode this here. The
9937 only user of this is Ada, which encodes the needed information using
9938 the names of types. */
9944 case PREINCREMENT_EXPR:
9945 case PREDECREMENT_EXPR:
9946 case POSTINCREMENT_EXPR:
9947 case POSTDECREMENT_EXPR:
9948 /* There are no opcodes for these operations. */
9952 /* If we already want an address, there's nothing we can do. */
9956 /* Otherwise, process the argument and look for the address. */
9957 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9960 if (DECL_THREAD_LOCAL_P (loc))
9966 if (targetm.have_tls)
9968 /* If this is not defined, we have no way to emit the
9970 if (!targetm.asm_out.output_dwarf_dtprel)
9973 /* The way DW_OP_GNU_push_tls_address is specified, we
9974 can only look up addresses of objects in the current
9976 if (DECL_EXTERNAL (loc))
9978 first_op = INTERNAL_DW_OP_tls_addr;
9979 second_op = DW_OP_GNU_push_tls_address;
9983 if (!targetm.emutls.debug_form_tls_address)
9985 loc = emutls_decl (loc);
9986 first_op = DW_OP_addr;
9987 second_op = DW_OP_form_tls_address;
9990 rtl = rtl_for_decl_location (loc);
9991 if (rtl == NULL_RTX)
9996 rtl = XEXP (rtl, 0);
9997 if (! CONSTANT_P (rtl))
10000 ret = new_loc_descr (first_op, 0, 0);
10001 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10002 ret->dw_loc_oprnd1.v.val_addr = rtl;
10004 ret1 = new_loc_descr (second_op, 0, 0);
10005 add_loc_descr (&ret, ret1);
10013 if (DECL_HAS_VALUE_EXPR_P (loc))
10014 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
10019 case FUNCTION_DECL:
10021 rtx rtl = rtl_for_decl_location (loc);
10023 if (rtl == NULL_RTX)
10025 else if (GET_CODE (rtl) == CONST_INT)
10027 HOST_WIDE_INT val = INTVAL (rtl);
10028 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
10029 val &= GET_MODE_MASK (DECL_MODE (loc));
10030 ret = int_loc_descriptor (val);
10032 else if (GET_CODE (rtl) == CONST_STRING)
10034 else if (CONSTANT_P (rtl))
10036 ret = new_loc_descr (DW_OP_addr, 0, 0);
10037 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
10038 ret->dw_loc_oprnd1.v.val_addr = rtl;
10042 enum machine_mode mode;
10044 /* Certain constructs can only be represented at top-level. */
10045 if (want_address == 2)
10046 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
10048 mode = GET_MODE (rtl);
10051 rtl = XEXP (rtl, 0);
10054 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10060 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10064 case COMPOUND_EXPR:
10065 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
10068 case VIEW_CONVERT_EXPR:
10071 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
10073 case COMPONENT_REF:
10074 case BIT_FIELD_REF:
10076 case ARRAY_RANGE_REF:
10079 HOST_WIDE_INT bitsize, bitpos, bytepos;
10080 enum machine_mode mode;
10082 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
10084 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
10085 &unsignedp, &volatilep, false);
10090 ret = loc_descriptor_from_tree_1 (obj, 1);
10092 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
10095 if (offset != NULL_TREE)
10097 /* Variable offset. */
10098 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
10099 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10102 bytepos = bitpos / BITS_PER_UNIT;
10104 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
10105 else if (bytepos < 0)
10107 add_loc_descr (&ret, int_loc_descriptor (bytepos));
10108 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
10116 if (host_integerp (loc, 0))
10117 ret = int_loc_descriptor (tree_low_cst (loc, 0));
10124 /* Get an RTL for this, if something has been emitted. */
10125 rtx rtl = lookup_constant_def (loc);
10126 enum machine_mode mode;
10128 if (!rtl || !MEM_P (rtl))
10130 mode = GET_MODE (rtl);
10131 rtl = XEXP (rtl, 0);
10132 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
10137 case TRUTH_AND_EXPR:
10138 case TRUTH_ANDIF_EXPR:
10143 case TRUTH_XOR_EXPR:
10148 case TRUTH_OR_EXPR:
10149 case TRUTH_ORIF_EXPR:
10154 case FLOOR_DIV_EXPR:
10155 case CEIL_DIV_EXPR:
10156 case ROUND_DIV_EXPR:
10157 case TRUNC_DIV_EXPR:
10165 case FLOOR_MOD_EXPR:
10166 case CEIL_MOD_EXPR:
10167 case ROUND_MOD_EXPR:
10168 case TRUNC_MOD_EXPR:
10181 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
10184 case POINTER_PLUS_EXPR:
10186 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
10187 && host_integerp (TREE_OPERAND (loc, 1), 0))
10189 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10193 add_loc_descr (&ret,
10194 new_loc_descr (DW_OP_plus_uconst,
10195 tree_low_cst (TREE_OPERAND (loc, 1),
10205 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10212 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10219 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10226 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
10241 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10242 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10243 if (ret == 0 || ret1 == 0)
10246 add_loc_descr (&ret, ret1);
10247 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10250 case TRUTH_NOT_EXPR:
10264 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10268 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
10274 const enum tree_code code =
10275 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
10277 loc = build3 (COND_EXPR, TREE_TYPE (loc),
10278 build2 (code, integer_type_node,
10279 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
10280 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
10283 /* ... fall through ... */
10287 dw_loc_descr_ref lhs
10288 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
10289 dw_loc_descr_ref rhs
10290 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
10291 dw_loc_descr_ref bra_node, jump_node, tmp;
10293 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
10294 if (ret == 0 || lhs == 0 || rhs == 0)
10297 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
10298 add_loc_descr (&ret, bra_node);
10300 add_loc_descr (&ret, rhs);
10301 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
10302 add_loc_descr (&ret, jump_node);
10304 add_loc_descr (&ret, lhs);
10305 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10306 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
10308 /* ??? Need a node to point the skip at. Use a nop. */
10309 tmp = new_loc_descr (DW_OP_nop, 0, 0);
10310 add_loc_descr (&ret, tmp);
10311 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
10312 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
10316 case FIX_TRUNC_EXPR:
10320 /* Leave front-end specific codes as simply unknown. This comes
10321 up, for instance, with the C STMT_EXPR. */
10322 if ((unsigned int) TREE_CODE (loc)
10323 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
10326 #ifdef ENABLE_CHECKING
10327 /* Otherwise this is a generic code; we should just lists all of
10328 these explicitly. We forgot one. */
10329 gcc_unreachable ();
10331 /* In a release build, we want to degrade gracefully: better to
10332 generate incomplete debugging information than to crash. */
10337 /* Show if we can't fill the request for an address. */
10338 if (want_address && !have_address)
10341 /* If we've got an address and don't want one, dereference. */
10342 if (!want_address && have_address && ret)
10344 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
10346 if (size > DWARF2_ADDR_SIZE || size == -1)
10348 else if (size == DWARF2_ADDR_SIZE)
10351 op = DW_OP_deref_size;
10353 add_loc_descr (&ret, new_loc_descr (op, size, 0));
10359 static inline dw_loc_descr_ref
10360 loc_descriptor_from_tree (tree loc)
10362 return loc_descriptor_from_tree_1 (loc, 2);
10365 /* Given a value, round it up to the lowest multiple of `boundary'
10366 which is not less than the value itself. */
10368 static inline HOST_WIDE_INT
10369 ceiling (HOST_WIDE_INT value, unsigned int boundary)
10371 return (((value + boundary - 1) / boundary) * boundary);
10374 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10375 pointer to the declared type for the relevant field variable, or return
10376 `integer_type_node' if the given node turns out to be an
10377 ERROR_MARK node. */
10380 field_type (const_tree decl)
10384 if (TREE_CODE (decl) == ERROR_MARK)
10385 return integer_type_node;
10387 type = DECL_BIT_FIELD_TYPE (decl);
10388 if (type == NULL_TREE)
10389 type = TREE_TYPE (decl);
10394 /* Given a pointer to a tree node, return the alignment in bits for
10395 it, or else return BITS_PER_WORD if the node actually turns out to
10396 be an ERROR_MARK node. */
10398 static inline unsigned
10399 simple_type_align_in_bits (const_tree type)
10401 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
10404 static inline unsigned
10405 simple_decl_align_in_bits (const_tree decl)
10407 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
10410 /* Return the result of rounding T up to ALIGN. */
10412 static inline HOST_WIDE_INT
10413 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
10415 /* We must be careful if T is negative because HOST_WIDE_INT can be
10416 either "above" or "below" unsigned int as per the C promotion
10417 rules, depending on the host, thus making the signedness of the
10418 direct multiplication and division unpredictable. */
10419 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
10425 return (HOST_WIDE_INT) u;
10428 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10429 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10430 or return 0 if we are unable to determine what that offset is, either
10431 because the argument turns out to be a pointer to an ERROR_MARK node, or
10432 because the offset is actually variable. (We can't handle the latter case
10435 static HOST_WIDE_INT
10436 field_byte_offset (const_tree decl)
10438 HOST_WIDE_INT object_offset_in_bits;
10439 HOST_WIDE_INT bitpos_int;
10441 if (TREE_CODE (decl) == ERROR_MARK)
10444 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
10446 /* We cannot yet cope with fields whose positions are variable, so
10447 for now, when we see such things, we simply return 0. Someday, we may
10448 be able to handle such cases, but it will be damn difficult. */
10449 if (! host_integerp (bit_position (decl), 0))
10452 bitpos_int = int_bit_position (decl);
10454 #ifdef PCC_BITFIELD_TYPE_MATTERS
10455 if (PCC_BITFIELD_TYPE_MATTERS)
10458 tree field_size_tree;
10459 HOST_WIDE_INT deepest_bitpos;
10460 unsigned HOST_WIDE_INT field_size_in_bits;
10461 unsigned int type_align_in_bits;
10462 unsigned int decl_align_in_bits;
10463 unsigned HOST_WIDE_INT type_size_in_bits;
10465 type = field_type (decl);
10466 field_size_tree = DECL_SIZE (decl);
10468 /* The size could be unspecified if there was an error, or for
10469 a flexible array member. */
10470 if (! field_size_tree)
10471 field_size_tree = bitsize_zero_node;
10473 /* If we don't know the size of the field, pretend it's a full word. */
10474 if (host_integerp (field_size_tree, 1))
10475 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10477 field_size_in_bits = BITS_PER_WORD;
10479 type_size_in_bits = simple_type_size_in_bits (type);
10480 type_align_in_bits = simple_type_align_in_bits (type);
10481 decl_align_in_bits = simple_decl_align_in_bits (decl);
10483 /* The GCC front-end doesn't make any attempt to keep track of the
10484 starting bit offset (relative to the start of the containing
10485 structure type) of the hypothetical "containing object" for a
10486 bit-field. Thus, when computing the byte offset value for the
10487 start of the "containing object" of a bit-field, we must deduce
10488 this information on our own. This can be rather tricky to do in
10489 some cases. For example, handling the following structure type
10490 definition when compiling for an i386/i486 target (which only
10491 aligns long long's to 32-bit boundaries) can be very tricky:
10493 struct S { int field1; long long field2:31; };
10495 Fortunately, there is a simple rule-of-thumb which can be used
10496 in such cases. When compiling for an i386/i486, GCC will
10497 allocate 8 bytes for the structure shown above. It decides to
10498 do this based upon one simple rule for bit-field allocation.
10499 GCC allocates each "containing object" for each bit-field at
10500 the first (i.e. lowest addressed) legitimate alignment boundary
10501 (based upon the required minimum alignment for the declared
10502 type of the field) which it can possibly use, subject to the
10503 condition that there is still enough available space remaining
10504 in the containing object (when allocated at the selected point)
10505 to fully accommodate all of the bits of the bit-field itself.
10507 This simple rule makes it obvious why GCC allocates 8 bytes for
10508 each object of the structure type shown above. When looking
10509 for a place to allocate the "containing object" for `field2',
10510 the compiler simply tries to allocate a 64-bit "containing
10511 object" at each successive 32-bit boundary (starting at zero)
10512 until it finds a place to allocate that 64- bit field such that
10513 at least 31 contiguous (and previously unallocated) bits remain
10514 within that selected 64 bit field. (As it turns out, for the
10515 example above, the compiler finds it is OK to allocate the
10516 "containing object" 64-bit field at bit-offset zero within the
10519 Here we attempt to work backwards from the limited set of facts
10520 we're given, and we try to deduce from those facts, where GCC
10521 must have believed that the containing object started (within
10522 the structure type). The value we deduce is then used (by the
10523 callers of this routine) to generate DW_AT_location and
10524 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10525 the case of DW_AT_location, regular fields as well). */
10527 /* Figure out the bit-distance from the start of the structure to
10528 the "deepest" bit of the bit-field. */
10529 deepest_bitpos = bitpos_int + field_size_in_bits;
10531 /* This is the tricky part. Use some fancy footwork to deduce
10532 where the lowest addressed bit of the containing object must
10534 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10536 /* Round up to type_align by default. This works best for
10538 object_offset_in_bits
10539 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10541 if (object_offset_in_bits > bitpos_int)
10543 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10545 /* Round up to decl_align instead. */
10546 object_offset_in_bits
10547 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10552 object_offset_in_bits = bitpos_int;
10554 return object_offset_in_bits / BITS_PER_UNIT;
10557 /* The following routines define various Dwarf attributes and any data
10558 associated with them. */
10560 /* Add a location description attribute value to a DIE.
10562 This emits location attributes suitable for whole variables and
10563 whole parameters. Note that the location attributes for struct fields are
10564 generated by the routine `data_member_location_attribute' below. */
10567 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10568 dw_loc_descr_ref descr)
10571 add_AT_loc (die, attr_kind, descr);
10574 /* Attach the specialized form of location attribute used for data members of
10575 struct and union types. In the special case of a FIELD_DECL node which
10576 represents a bit-field, the "offset" part of this special location
10577 descriptor must indicate the distance in bytes from the lowest-addressed
10578 byte of the containing struct or union type to the lowest-addressed byte of
10579 the "containing object" for the bit-field. (See the `field_byte_offset'
10582 For any given bit-field, the "containing object" is a hypothetical object
10583 (of some integral or enum type) within which the given bit-field lives. The
10584 type of this hypothetical "containing object" is always the same as the
10585 declared type of the individual bit-field itself (for GCC anyway... the
10586 DWARF spec doesn't actually mandate this). Note that it is the size (in
10587 bytes) of the hypothetical "containing object" which will be given in the
10588 DW_AT_byte_size attribute for this bit-field. (See the
10589 `byte_size_attribute' function below.) It is also used when calculating the
10590 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10591 function below.) */
10594 add_data_member_location_attribute (dw_die_ref die, tree decl)
10596 HOST_WIDE_INT offset;
10597 dw_loc_descr_ref loc_descr = 0;
10599 if (TREE_CODE (decl) == TREE_BINFO)
10601 /* We're working on the TAG_inheritance for a base class. */
10602 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10604 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10605 aren't at a fixed offset from all (sub)objects of the same
10606 type. We need to extract the appropriate offset from our
10607 vtable. The following dwarf expression means
10609 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10611 This is specific to the V3 ABI, of course. */
10613 dw_loc_descr_ref tmp;
10615 /* Make a copy of the object address. */
10616 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10617 add_loc_descr (&loc_descr, tmp);
10619 /* Extract the vtable address. */
10620 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10621 add_loc_descr (&loc_descr, tmp);
10623 /* Calculate the address of the offset. */
10624 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10625 gcc_assert (offset < 0);
10627 tmp = int_loc_descriptor (-offset);
10628 add_loc_descr (&loc_descr, tmp);
10629 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10630 add_loc_descr (&loc_descr, tmp);
10632 /* Extract the offset. */
10633 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10634 add_loc_descr (&loc_descr, tmp);
10636 /* Add it to the object address. */
10637 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10638 add_loc_descr (&loc_descr, tmp);
10641 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10644 offset = field_byte_offset (decl);
10648 enum dwarf_location_atom op;
10650 /* The DWARF2 standard says that we should assume that the structure
10651 address is already on the stack, so we can specify a structure field
10652 address by using DW_OP_plus_uconst. */
10654 #ifdef MIPS_DEBUGGING_INFO
10655 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10656 operator correctly. It works only if we leave the offset on the
10660 op = DW_OP_plus_uconst;
10663 loc_descr = new_loc_descr (op, offset, 0);
10666 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10669 /* Writes integer values to dw_vec_const array. */
10672 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10676 *dest++ = val & 0xff;
10682 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10684 static HOST_WIDE_INT
10685 extract_int (const unsigned char *src, unsigned int size)
10687 HOST_WIDE_INT val = 0;
10693 val |= *--src & 0xff;
10699 /* Writes floating point values to dw_vec_const array. */
10702 insert_float (const_rtx rtl, unsigned char *array)
10704 REAL_VALUE_TYPE rv;
10708 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
10709 real_to_target (val, &rv, GET_MODE (rtl));
10711 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10712 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
10714 insert_int (val[i], 4, array);
10719 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10720 does not have a "location" either in memory or in a register. These
10721 things can arise in GNU C when a constant is passed as an actual parameter
10722 to an inlined function. They can also arise in C++ where declared
10723 constants do not necessarily get memory "homes". */
10726 add_const_value_attribute (dw_die_ref die, rtx rtl)
10728 switch (GET_CODE (rtl))
10732 HOST_WIDE_INT val = INTVAL (rtl);
10735 add_AT_int (die, DW_AT_const_value, val);
10737 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10742 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10743 floating-point constant. A CONST_DOUBLE is used whenever the
10744 constant requires more than one word in order to be adequately
10745 represented. We output CONST_DOUBLEs as blocks. */
10747 enum machine_mode mode = GET_MODE (rtl);
10749 if (SCALAR_FLOAT_MODE_P (mode))
10751 unsigned int length = GET_MODE_SIZE (mode);
10752 unsigned char *array = GGC_NEWVEC (unsigned char, length);
10754 insert_float (rtl, array);
10755 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10759 /* ??? We really should be using HOST_WIDE_INT throughout. */
10760 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10762 add_AT_long_long (die, DW_AT_const_value,
10763 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10770 enum machine_mode mode = GET_MODE (rtl);
10771 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10772 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10773 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
10777 switch (GET_MODE_CLASS (mode))
10779 case MODE_VECTOR_INT:
10780 for (i = 0, p = array; i < length; i++, p += elt_size)
10782 rtx elt = CONST_VECTOR_ELT (rtl, i);
10783 HOST_WIDE_INT lo, hi;
10785 switch (GET_CODE (elt))
10793 lo = CONST_DOUBLE_LOW (elt);
10794 hi = CONST_DOUBLE_HIGH (elt);
10798 gcc_unreachable ();
10801 if (elt_size <= sizeof (HOST_WIDE_INT))
10802 insert_int (lo, elt_size, p);
10805 unsigned char *p0 = p;
10806 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10808 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10809 if (WORDS_BIG_ENDIAN)
10814 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10815 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10820 case MODE_VECTOR_FLOAT:
10821 for (i = 0, p = array; i < length; i++, p += elt_size)
10823 rtx elt = CONST_VECTOR_ELT (rtl, i);
10824 insert_float (elt, p);
10829 gcc_unreachable ();
10832 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10837 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10843 add_AT_addr (die, DW_AT_const_value, rtl);
10844 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10848 /* In cases where an inlined instance of an inline function is passed
10849 the address of an `auto' variable (which is local to the caller) we
10850 can get a situation where the DECL_RTL of the artificial local
10851 variable (for the inlining) which acts as a stand-in for the
10852 corresponding formal parameter (of the inline function) will look
10853 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10854 exactly a compile-time constant expression, but it isn't the address
10855 of the (artificial) local variable either. Rather, it represents the
10856 *value* which the artificial local variable always has during its
10857 lifetime. We currently have no way to represent such quasi-constant
10858 values in Dwarf, so for now we just punt and generate nothing. */
10862 /* No other kinds of rtx should be possible here. */
10863 gcc_unreachable ();
10868 /* Determine whether the evaluation of EXPR references any variables
10869 or functions which aren't otherwise used (and therefore may not be
10872 reference_to_unused (tree * tp, int * walk_subtrees,
10873 void * data ATTRIBUTE_UNUSED)
10875 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10876 *walk_subtrees = 0;
10878 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10879 && ! TREE_ASM_WRITTEN (*tp))
10881 /* ??? The C++ FE emits debug information for using decls, so
10882 putting gcc_unreachable here falls over. See PR31899. For now
10883 be conservative. */
10884 else if (!cgraph_global_info_ready
10885 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10887 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10889 struct varpool_node *node = varpool_node (*tp);
10893 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10894 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10896 struct cgraph_node *node = cgraph_node (*tp);
10900 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
10906 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10907 for use in a later add_const_value_attribute call. */
10910 rtl_for_decl_init (tree init, tree type)
10912 rtx rtl = NULL_RTX;
10914 /* If a variable is initialized with a string constant without embedded
10915 zeros, build CONST_STRING. */
10916 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10918 tree enttype = TREE_TYPE (type);
10919 tree domain = TYPE_DOMAIN (type);
10920 enum machine_mode mode = TYPE_MODE (enttype);
10922 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10924 && integer_zerop (TYPE_MIN_VALUE (domain))
10925 && compare_tree_int (TYPE_MAX_VALUE (domain),
10926 TREE_STRING_LENGTH (init) - 1) == 0
10927 && ((size_t) TREE_STRING_LENGTH (init)
10928 == strlen (TREE_STRING_POINTER (init)) + 1))
10929 rtl = gen_rtx_CONST_STRING (VOIDmode,
10930 ggc_strdup (TREE_STRING_POINTER (init)));
10932 /* Other aggregates, and complex values, could be represented using
10934 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10936 /* Vectors only work if their mode is supported by the target.
10937 FIXME: generic vectors ought to work too. */
10938 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10940 /* If the initializer is something that we know will expand into an
10941 immediate RTL constant, expand it now. We must be careful not to
10942 reference variables which won't be output. */
10943 else if (initializer_constant_valid_p (init, type)
10944 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10946 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10948 if (TREE_CODE (type) == VECTOR_TYPE)
10949 switch (TREE_CODE (init))
10954 if (TREE_CONSTANT (init))
10956 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
10957 bool constant_p = true;
10959 unsigned HOST_WIDE_INT ix;
10961 /* Even when ctor is constant, it might contain non-*_CST
10962 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10963 belong into VECTOR_CST nodes. */
10964 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
10965 if (!CONSTANT_CLASS_P (value))
10967 constant_p = false;
10973 init = build_vector_from_ctor (type, elts);
10983 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10985 /* If expand_expr returns a MEM, it wasn't immediate. */
10986 gcc_assert (!rtl || !MEM_P (rtl));
10992 /* Generate RTL for the variable DECL to represent its location. */
10995 rtl_for_decl_location (tree decl)
10999 /* Here we have to decide where we are going to say the parameter "lives"
11000 (as far as the debugger is concerned). We only have a couple of
11001 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
11003 DECL_RTL normally indicates where the parameter lives during most of the
11004 activation of the function. If optimization is enabled however, this
11005 could be either NULL or else a pseudo-reg. Both of those cases indicate
11006 that the parameter doesn't really live anywhere (as far as the code
11007 generation parts of GCC are concerned) during most of the function's
11008 activation. That will happen (for example) if the parameter is never
11009 referenced within the function.
11011 We could just generate a location descriptor here for all non-NULL
11012 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
11013 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
11014 where DECL_RTL is NULL or is a pseudo-reg.
11016 Note however that we can only get away with using DECL_INCOMING_RTL as
11017 a backup substitute for DECL_RTL in certain limited cases. In cases
11018 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11019 we can be sure that the parameter was passed using the same type as it is
11020 declared to have within the function, and that its DECL_INCOMING_RTL
11021 points us to a place where a value of that type is passed.
11023 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11024 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11025 because in these cases DECL_INCOMING_RTL points us to a value of some
11026 type which is *different* from the type of the parameter itself. Thus,
11027 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11028 such cases, the debugger would end up (for example) trying to fetch a
11029 `float' from a place which actually contains the first part of a
11030 `double'. That would lead to really incorrect and confusing
11031 output at debug-time.
11033 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11034 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11035 are a couple of exceptions however. On little-endian machines we can
11036 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11037 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11038 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11039 when (on a little-endian machine) a non-prototyped function has a
11040 parameter declared to be of type `short' or `char'. In such cases,
11041 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11042 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11043 passed `int' value. If the debugger then uses that address to fetch
11044 a `short' or a `char' (on a little-endian machine) the result will be
11045 the correct data, so we allow for such exceptional cases below.
11047 Note that our goal here is to describe the place where the given formal
11048 parameter lives during most of the function's activation (i.e. between the
11049 end of the prologue and the start of the epilogue). We'll do that as best
11050 as we can. Note however that if the given formal parameter is modified
11051 sometime during the execution of the function, then a stack backtrace (at
11052 debug-time) will show the function as having been called with the *new*
11053 value rather than the value which was originally passed in. This happens
11054 rarely enough that it is not a major problem, but it *is* a problem, and
11055 I'd like to fix it.
11057 A future version of dwarf2out.c may generate two additional attributes for
11058 any given DW_TAG_formal_parameter DIE which will describe the "passed
11059 type" and the "passed location" for the given formal parameter in addition
11060 to the attributes we now generate to indicate the "declared type" and the
11061 "active location" for each parameter. This additional set of attributes
11062 could be used by debuggers for stack backtraces. Separately, note that
11063 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11064 This happens (for example) for inlined-instances of inline function formal
11065 parameters which are never referenced. This really shouldn't be
11066 happening. All PARM_DECL nodes should get valid non-NULL
11067 DECL_INCOMING_RTL values. FIXME. */
11069 /* Use DECL_RTL as the "location" unless we find something better. */
11070 rtl = DECL_RTL_IF_SET (decl);
11072 /* When generating abstract instances, ignore everything except
11073 constants, symbols living in memory, and symbols living in
11074 fixed registers. */
11075 if (! reload_completed)
11078 && (CONSTANT_P (rtl)
11080 && CONSTANT_P (XEXP (rtl, 0)))
11082 && TREE_CODE (decl) == VAR_DECL
11083 && TREE_STATIC (decl))))
11085 rtl = targetm.delegitimize_address (rtl);
11090 else if (TREE_CODE (decl) == PARM_DECL)
11092 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
11094 tree declared_type = TREE_TYPE (decl);
11095 tree passed_type = DECL_ARG_TYPE (decl);
11096 enum machine_mode dmode = TYPE_MODE (declared_type);
11097 enum machine_mode pmode = TYPE_MODE (passed_type);
11099 /* This decl represents a formal parameter which was optimized out.
11100 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11101 all cases where (rtl == NULL_RTX) just below. */
11102 if (dmode == pmode)
11103 rtl = DECL_INCOMING_RTL (decl);
11104 else if (SCALAR_INT_MODE_P (dmode)
11105 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
11106 && DECL_INCOMING_RTL (decl))
11108 rtx inc = DECL_INCOMING_RTL (decl);
11111 else if (MEM_P (inc))
11113 if (BYTES_BIG_ENDIAN)
11114 rtl = adjust_address_nv (inc, dmode,
11115 GET_MODE_SIZE (pmode)
11116 - GET_MODE_SIZE (dmode));
11123 /* If the parm was passed in registers, but lives on the stack, then
11124 make a big endian correction if the mode of the type of the
11125 parameter is not the same as the mode of the rtl. */
11126 /* ??? This is the same series of checks that are made in dbxout.c before
11127 we reach the big endian correction code there. It isn't clear if all
11128 of these checks are necessary here, but keeping them all is the safe
11130 else if (MEM_P (rtl)
11131 && XEXP (rtl, 0) != const0_rtx
11132 && ! CONSTANT_P (XEXP (rtl, 0))
11133 /* Not passed in memory. */
11134 && !MEM_P (DECL_INCOMING_RTL (decl))
11135 /* Not passed by invisible reference. */
11136 && (!REG_P (XEXP (rtl, 0))
11137 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
11138 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
11139 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11140 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
11143 /* Big endian correction check. */
11144 && BYTES_BIG_ENDIAN
11145 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
11146 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
11149 int offset = (UNITS_PER_WORD
11150 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
11152 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11153 plus_constant (XEXP (rtl, 0), offset));
11156 else if (TREE_CODE (decl) == VAR_DECL
11159 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
11160 && BYTES_BIG_ENDIAN)
11162 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
11163 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
11165 /* If a variable is declared "register" yet is smaller than
11166 a register, then if we store the variable to memory, it
11167 looks like we're storing a register-sized value, when in
11168 fact we are not. We need to adjust the offset of the
11169 storage location to reflect the actual value's bytes,
11170 else gdb will not be able to display it. */
11172 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
11173 plus_constant (XEXP (rtl, 0), rsize-dsize));
11176 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11177 and will have been substituted directly into all expressions that use it.
11178 C does not have such a concept, but C++ and other languages do. */
11179 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
11180 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
11183 rtl = targetm.delegitimize_address (rtl);
11185 /* If we don't look past the constant pool, we risk emitting a
11186 reference to a constant pool entry that isn't referenced from
11187 code, and thus is not emitted. */
11189 rtl = avoid_constant_pool_reference (rtl);
11194 /* We need to figure out what section we should use as the base for the
11195 address ranges where a given location is valid.
11196 1. If this particular DECL has a section associated with it, use that.
11197 2. If this function has a section associated with it, use that.
11198 3. Otherwise, use the text section.
11199 XXX: If you split a variable across multiple sections, we won't notice. */
11201 static const char *
11202 secname_for_decl (const_tree decl)
11204 const char *secname;
11206 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
11208 tree sectree = DECL_SECTION_NAME (decl);
11209 secname = TREE_STRING_POINTER (sectree);
11211 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
11213 tree sectree = DECL_SECTION_NAME (current_function_decl);
11214 secname = TREE_STRING_POINTER (sectree);
11216 else if (cfun && in_cold_section_p)
11217 secname = crtl->subsections.cold_section_label;
11219 secname = text_section_label;
11224 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
11225 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
11226 value is the offset into the common block for the symbol. */
11229 fortran_common (tree decl, HOST_WIDE_INT *value)
11231 tree val_expr, cvar;
11232 enum machine_mode mode;
11233 HOST_WIDE_INT bitsize, bitpos;
11235 int volatilep = 0, unsignedp = 0;
11237 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11238 it does not have a value (the offset into the common area), or if it
11239 is thread local (as opposed to global) then it isn't common, and shouldn't
11240 be handled as such. */
11241 if (TREE_CODE (decl) != VAR_DECL
11242 || !TREE_PUBLIC (decl)
11243 || !TREE_STATIC (decl)
11244 || !DECL_HAS_VALUE_EXPR_P (decl)
11248 val_expr = DECL_VALUE_EXPR (decl);
11249 if (TREE_CODE (val_expr) != COMPONENT_REF)
11252 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
11253 &mode, &unsignedp, &volatilep, true);
11255 if (cvar == NULL_TREE
11256 || TREE_CODE (cvar) != VAR_DECL
11257 || DECL_ARTIFICIAL (cvar)
11258 || !TREE_PUBLIC (cvar))
11262 if (offset != NULL)
11264 if (!host_integerp (offset, 0))
11266 *value = tree_low_cst (offset, 0);
11269 *value += bitpos / BITS_PER_UNIT;
11275 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11276 data attribute for a variable or a parameter. We generate the
11277 DW_AT_const_value attribute only in those cases where the given variable
11278 or parameter does not have a true "location" either in memory or in a
11279 register. This can happen (for example) when a constant is passed as an
11280 actual argument in a call to an inline function. (It's possible that
11281 these things can crop up in other ways also.) Note that one type of
11282 constant value which can be passed into an inlined function is a constant
11283 pointer. This can happen for example if an actual argument in an inlined
11284 function call evaluates to a compile-time constant address. */
11287 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
11288 enum dwarf_attribute attr)
11291 dw_loc_descr_ref descr;
11292 var_loc_list *loc_list;
11293 struct var_loc_node *node;
11294 if (TREE_CODE (decl) == ERROR_MARK)
11297 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
11298 || TREE_CODE (decl) == RESULT_DECL);
11300 /* See if we possibly have multiple locations for this variable. */
11301 loc_list = lookup_decl_loc (decl);
11303 /* If it truly has multiple locations, the first and last node will
11305 if (loc_list && loc_list->first != loc_list->last)
11307 const char *endname, *secname;
11308 dw_loc_list_ref list;
11310 enum var_init_status initialized;
11312 /* Now that we know what section we are using for a base,
11313 actually construct the list of locations.
11314 The first location information is what is passed to the
11315 function that creates the location list, and the remaining
11316 locations just get added on to that list.
11317 Note that we only know the start address for a location
11318 (IE location changes), so to build the range, we use
11319 the range [current location start, next location start].
11320 This means we have to special case the last node, and generate
11321 a range of [last location start, end of function label]. */
11323 node = loc_list->first;
11324 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11325 secname = secname_for_decl (decl);
11327 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
11328 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11330 initialized = VAR_INIT_STATUS_INITIALIZED;
11332 list = new_loc_list (loc_descriptor (varloc, initialized),
11333 node->label, node->next->label, secname, 1);
11336 for (; node->next; node = node->next)
11337 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11339 /* The variable has a location between NODE->LABEL and
11340 NODE->NEXT->LABEL. */
11341 enum var_init_status initialized =
11342 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11343 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11344 add_loc_descr_to_loc_list (&list,
11345 loc_descriptor (varloc, initialized),
11346 node->label, node->next->label, secname);
11349 /* If the variable has a location at the last label
11350 it keeps its location until the end of function. */
11351 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
11353 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11354 enum var_init_status initialized =
11355 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11357 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
11358 if (!current_function_decl)
11359 endname = text_end_label;
11362 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11363 current_function_funcdef_no);
11364 endname = ggc_strdup (label_id);
11366 add_loc_descr_to_loc_list (&list,
11367 loc_descriptor (varloc, initialized),
11368 node->label, endname, secname);
11371 /* Finally, add the location list to the DIE, and we are done. */
11372 add_AT_loc_list (die, attr, list);
11376 /* Try to get some constant RTL for this decl, and use that as the value of
11379 rtl = rtl_for_decl_location (decl);
11380 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
11382 add_const_value_attribute (die, rtl);
11386 /* If we have tried to generate the location otherwise, and it
11387 didn't work out (we wouldn't be here if we did), and we have a one entry
11388 location list, try generating a location from that. */
11389 if (loc_list && loc_list->first)
11391 enum var_init_status status;
11392 node = loc_list->first;
11393 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
11394 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
11397 add_AT_location_description (die, attr, descr);
11402 /* We couldn't get any rtl, so try directly generating the location
11403 description from the tree. */
11404 descr = loc_descriptor_from_tree (decl);
11407 add_AT_location_description (die, attr, descr);
11410 /* None of that worked, so it must not really have a location;
11411 try adding a constant value attribute from the DECL_INITIAL. */
11412 tree_add_const_value_attribute (die, decl);
11415 /* If we don't have a copy of this variable in memory for some reason (such
11416 as a C++ member constant that doesn't have an out-of-line definition),
11417 we should tell the debugger about the constant value. */
11420 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
11422 tree init = DECL_INITIAL (decl);
11423 tree type = TREE_TYPE (decl);
11426 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
11431 rtl = rtl_for_decl_init (init, type);
11433 add_const_value_attribute (var_die, rtl);
11436 /* Convert the CFI instructions for the current function into a
11437 location list. This is used for DW_AT_frame_base when we targeting
11438 a dwarf2 consumer that does not support the dwarf3
11439 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
11442 static dw_loc_list_ref
11443 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
11446 dw_loc_list_ref list, *list_tail;
11448 dw_cfa_location last_cfa, next_cfa;
11449 const char *start_label, *last_label, *section;
11451 fde = current_fde ();
11452 gcc_assert (fde != NULL);
11454 section = secname_for_decl (current_function_decl);
11458 next_cfa.reg = INVALID_REGNUM;
11459 next_cfa.offset = 0;
11460 next_cfa.indirect = 0;
11461 next_cfa.base_offset = 0;
11463 start_label = fde->dw_fde_begin;
11465 /* ??? Bald assumption that the CIE opcode list does not contain
11466 advance opcodes. */
11467 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
11468 lookup_cfa_1 (cfi, &next_cfa);
11470 last_cfa = next_cfa;
11471 last_label = start_label;
11473 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
11474 switch (cfi->dw_cfi_opc)
11476 case DW_CFA_set_loc:
11477 case DW_CFA_advance_loc1:
11478 case DW_CFA_advance_loc2:
11479 case DW_CFA_advance_loc4:
11480 if (!cfa_equal_p (&last_cfa, &next_cfa))
11482 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11483 start_label, last_label, section,
11486 list_tail = &(*list_tail)->dw_loc_next;
11487 last_cfa = next_cfa;
11488 start_label = last_label;
11490 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
11493 case DW_CFA_advance_loc:
11494 /* The encoding is complex enough that we should never emit this. */
11495 case DW_CFA_remember_state:
11496 case DW_CFA_restore_state:
11497 /* We don't handle these two in this function. It would be possible
11498 if it were to be required. */
11499 gcc_unreachable ();
11502 lookup_cfa_1 (cfi, &next_cfa);
11506 if (!cfa_equal_p (&last_cfa, &next_cfa))
11508 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11509 start_label, last_label, section,
11511 list_tail = &(*list_tail)->dw_loc_next;
11512 start_label = last_label;
11514 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
11515 start_label, fde->dw_fde_end, section,
11521 /* Compute a displacement from the "steady-state frame pointer" to the
11522 frame base (often the same as the CFA), and store it in
11523 frame_pointer_fb_offset. OFFSET is added to the displacement
11524 before the latter is negated. */
11527 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
11531 #ifdef FRAME_POINTER_CFA_OFFSET
11532 reg = frame_pointer_rtx;
11533 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
11535 reg = arg_pointer_rtx;
11536 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
11539 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11540 if (GET_CODE (elim) == PLUS)
11542 offset += INTVAL (XEXP (elim, 1));
11543 elim = XEXP (elim, 0);
11546 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11547 && (elim == hard_frame_pointer_rtx
11548 || elim == stack_pointer_rtx))
11549 || elim == (frame_pointer_needed
11550 ? hard_frame_pointer_rtx
11551 : stack_pointer_rtx));
11553 frame_pointer_fb_offset = -offset;
11556 /* Generate a DW_AT_name attribute given some string value to be included as
11557 the value of the attribute. */
11560 add_name_attribute (dw_die_ref die, const char *name_string)
11562 if (name_string != NULL && *name_string != 0)
11564 if (demangle_name_func)
11565 name_string = (*demangle_name_func) (name_string);
11567 add_AT_string (die, DW_AT_name, name_string);
11571 /* Generate a DW_AT_comp_dir attribute for DIE. */
11574 add_comp_dir_attribute (dw_die_ref die)
11576 const char *wd = get_src_pwd ();
11578 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11581 /* Given a tree node describing an array bound (either lower or upper) output
11582 a representation for that bound. */
11585 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11587 switch (TREE_CODE (bound))
11592 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11594 if (! host_integerp (bound, 0)
11595 || (bound_attr == DW_AT_lower_bound
11596 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11597 || (is_fortran () && integer_onep (bound)))))
11598 /* Use the default. */
11601 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11605 case VIEW_CONVERT_EXPR:
11606 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11616 dw_die_ref decl_die = lookup_decl_die (bound);
11618 /* ??? Can this happen, or should the variable have been bound
11619 first? Probably it can, since I imagine that we try to create
11620 the types of parameters in the order in which they exist in
11621 the list, and won't have created a forward reference to a
11622 later parameter. */
11623 if (decl_die != NULL)
11624 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11630 /* Otherwise try to create a stack operation procedure to
11631 evaluate the value of the array bound. */
11633 dw_die_ref ctx, decl_die;
11634 dw_loc_descr_ref loc;
11636 loc = loc_descriptor_from_tree (bound);
11640 if (current_function_decl == 0)
11641 ctx = comp_unit_die;
11643 ctx = lookup_decl_die (current_function_decl);
11645 decl_die = new_die (DW_TAG_variable, ctx, bound);
11646 add_AT_flag (decl_die, DW_AT_artificial, 1);
11647 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11648 add_AT_loc (decl_die, DW_AT_location, loc);
11650 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11656 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
11657 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
11658 Note that the block of subscript information for an array type also
11659 includes information about the element type of the given array type. */
11662 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
11664 unsigned dimension_number;
11666 dw_die_ref subrange_die;
11668 for (dimension_number = 0;
11669 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
11670 type = TREE_TYPE (type), dimension_number++)
11672 tree domain = TYPE_DOMAIN (type);
11674 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11675 and (in GNU C only) variable bounds. Handle all three forms
11677 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11680 /* We have an array type with specified bounds. */
11681 lower = TYPE_MIN_VALUE (domain);
11682 upper = TYPE_MAX_VALUE (domain);
11684 /* Define the index type. */
11685 if (TREE_TYPE (domain))
11687 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11688 TREE_TYPE field. We can't emit debug info for this
11689 because it is an unnamed integral type. */
11690 if (TREE_CODE (domain) == INTEGER_TYPE
11691 && TYPE_NAME (domain) == NULL_TREE
11692 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
11693 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
11696 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
11700 /* ??? If upper is NULL, the array has unspecified length,
11701 but it does have a lower bound. This happens with Fortran
11703 Since the debugger is definitely going to need to know N
11704 to produce useful results, go ahead and output the lower
11705 bound solo, and hope the debugger can cope. */
11707 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
11709 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
11712 /* Otherwise we have an array type with an unspecified length. The
11713 DWARF-2 spec does not say how to handle this; let's just leave out the
11719 add_byte_size_attribute (dw_die_ref die, tree tree_node)
11723 switch (TREE_CODE (tree_node))
11728 case ENUMERAL_TYPE:
11731 case QUAL_UNION_TYPE:
11732 size = int_size_in_bytes (tree_node);
11735 /* For a data member of a struct or union, the DW_AT_byte_size is
11736 generally given as the number of bytes normally allocated for an
11737 object of the *declared* type of the member itself. This is true
11738 even for bit-fields. */
11739 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
11742 gcc_unreachable ();
11745 /* Note that `size' might be -1 when we get to this point. If it is, that
11746 indicates that the byte size of the entity in question is variable. We
11747 have no good way of expressing this fact in Dwarf at the present time,
11748 so just let the -1 pass on through. */
11749 add_AT_unsigned (die, DW_AT_byte_size, size);
11752 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11753 which specifies the distance in bits from the highest order bit of the
11754 "containing object" for the bit-field to the highest order bit of the
11757 For any given bit-field, the "containing object" is a hypothetical object
11758 (of some integral or enum type) within which the given bit-field lives. The
11759 type of this hypothetical "containing object" is always the same as the
11760 declared type of the individual bit-field itself. The determination of the
11761 exact location of the "containing object" for a bit-field is rather
11762 complicated. It's handled by the `field_byte_offset' function (above).
11764 Note that it is the size (in bytes) of the hypothetical "containing object"
11765 which will be given in the DW_AT_byte_size attribute for this bit-field.
11766 (See `byte_size_attribute' above). */
11769 add_bit_offset_attribute (dw_die_ref die, tree decl)
11771 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
11772 tree type = DECL_BIT_FIELD_TYPE (decl);
11773 HOST_WIDE_INT bitpos_int;
11774 HOST_WIDE_INT highest_order_object_bit_offset;
11775 HOST_WIDE_INT highest_order_field_bit_offset;
11776 HOST_WIDE_INT unsigned bit_offset;
11778 /* Must be a field and a bit field. */
11779 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
11781 /* We can't yet handle bit-fields whose offsets are variable, so if we
11782 encounter such things, just return without generating any attribute
11783 whatsoever. Likewise for variable or too large size. */
11784 if (! host_integerp (bit_position (decl), 0)
11785 || ! host_integerp (DECL_SIZE (decl), 1))
11788 bitpos_int = int_bit_position (decl);
11790 /* Note that the bit offset is always the distance (in bits) from the
11791 highest-order bit of the "containing object" to the highest-order bit of
11792 the bit-field itself. Since the "high-order end" of any object or field
11793 is different on big-endian and little-endian machines, the computation
11794 below must take account of these differences. */
11795 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
11796 highest_order_field_bit_offset = bitpos_int;
11798 if (! BYTES_BIG_ENDIAN)
11800 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
11801 highest_order_object_bit_offset += simple_type_size_in_bits (type);
11805 = (! BYTES_BIG_ENDIAN
11806 ? highest_order_object_bit_offset - highest_order_field_bit_offset
11807 : highest_order_field_bit_offset - highest_order_object_bit_offset);
11809 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
11812 /* For a FIELD_DECL node which represents a bit field, output an attribute
11813 which specifies the length in bits of the given field. */
11816 add_bit_size_attribute (dw_die_ref die, tree decl)
11818 /* Must be a field and a bit field. */
11819 gcc_assert (TREE_CODE (decl) == FIELD_DECL
11820 && DECL_BIT_FIELD_TYPE (decl));
11822 if (host_integerp (DECL_SIZE (decl), 1))
11823 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
11826 /* If the compiled language is ANSI C, then add a 'prototyped'
11827 attribute, if arg types are given for the parameters of a function. */
11830 add_prototyped_attribute (dw_die_ref die, tree func_type)
11832 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11833 && TYPE_ARG_TYPES (func_type) != NULL)
11834 add_AT_flag (die, DW_AT_prototyped, 1);
11837 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11838 by looking in either the type declaration or object declaration
11842 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11844 dw_die_ref origin_die = NULL;
11846 if (TREE_CODE (origin) != FUNCTION_DECL)
11848 /* We may have gotten separated from the block for the inlined
11849 function, if we're in an exception handler or some such; make
11850 sure that the abstract function has been written out.
11852 Doing this for nested functions is wrong, however; functions are
11853 distinct units, and our context might not even be inline. */
11857 fn = TYPE_STUB_DECL (fn);
11859 fn = decl_function_context (fn);
11861 dwarf2out_abstract_function (fn);
11864 if (DECL_P (origin))
11865 origin_die = lookup_decl_die (origin);
11866 else if (TYPE_P (origin))
11867 origin_die = lookup_type_die (origin);
11869 /* XXX: Functions that are never lowered don't always have correct block
11870 trees (in the case of java, they simply have no block tree, in some other
11871 languages). For these functions, there is nothing we can really do to
11872 output correct debug info for inlined functions in all cases. Rather
11873 than die, we'll just produce deficient debug info now, in that we will
11874 have variables without a proper abstract origin. In the future, when all
11875 functions are lowered, we should re-add a gcc_assert (origin_die)
11879 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11882 /* We do not currently support the pure_virtual attribute. */
11885 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11887 if (DECL_VINDEX (func_decl))
11889 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11891 if (host_integerp (DECL_VINDEX (func_decl), 0))
11892 add_AT_loc (die, DW_AT_vtable_elem_location,
11893 new_loc_descr (DW_OP_constu,
11894 tree_low_cst (DECL_VINDEX (func_decl), 0),
11897 /* GNU extension: Record what type this method came from originally. */
11898 if (debug_info_level > DINFO_LEVEL_TERSE)
11899 add_AT_die_ref (die, DW_AT_containing_type,
11900 lookup_type_die (DECL_CONTEXT (func_decl)));
11904 /* Add source coordinate attributes for the given decl. */
11907 add_src_coords_attributes (dw_die_ref die, tree decl)
11909 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11911 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11912 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11915 /* Add a DW_AT_name attribute and source coordinate attribute for the
11916 given decl, but only if it actually has a name. */
11919 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11923 decl_name = DECL_NAME (decl);
11924 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11926 add_name_attribute (die, dwarf2_name (decl, 0));
11927 if (! DECL_ARTIFICIAL (decl))
11928 add_src_coords_attributes (die, decl);
11930 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11931 && TREE_PUBLIC (decl)
11932 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11933 && !DECL_ABSTRACT (decl)
11934 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
11936 add_AT_string (die, DW_AT_MIPS_linkage_name,
11937 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11940 #ifdef VMS_DEBUGGING_INFO
11941 /* Get the function's name, as described by its RTL. This may be different
11942 from the DECL_NAME name used in the source file. */
11943 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11945 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11946 XEXP (DECL_RTL (decl), 0));
11947 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11952 /* Push a new declaration scope. */
11955 push_decl_scope (tree scope)
11957 VEC_safe_push (tree, gc, decl_scope_table, scope);
11960 /* Pop a declaration scope. */
11963 pop_decl_scope (void)
11965 VEC_pop (tree, decl_scope_table);
11968 /* Return the DIE for the scope that immediately contains this type.
11969 Non-named types get global scope. Named types nested in other
11970 types get their containing scope if it's open, or global scope
11971 otherwise. All other types (i.e. function-local named types) get
11972 the current active scope. */
11975 scope_die_for (tree t, dw_die_ref context_die)
11977 dw_die_ref scope_die = NULL;
11978 tree containing_scope;
11981 /* Non-types always go in the current scope. */
11982 gcc_assert (TYPE_P (t));
11984 containing_scope = TYPE_CONTEXT (t);
11986 /* Use the containing namespace if it was passed in (for a declaration). */
11987 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11989 if (context_die == lookup_decl_die (containing_scope))
11992 containing_scope = NULL_TREE;
11995 /* Ignore function type "scopes" from the C frontend. They mean that
11996 a tagged type is local to a parmlist of a function declarator, but
11997 that isn't useful to DWARF. */
11998 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11999 containing_scope = NULL_TREE;
12001 if (containing_scope == NULL_TREE)
12002 scope_die = comp_unit_die;
12003 else if (TYPE_P (containing_scope))
12005 /* For types, we can just look up the appropriate DIE. But
12006 first we check to see if we're in the middle of emitting it
12007 so we know where the new DIE should go. */
12008 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
12009 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
12014 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
12015 || TREE_ASM_WRITTEN (containing_scope));
12017 /* If none of the current dies are suitable, we get file scope. */
12018 scope_die = comp_unit_die;
12021 scope_die = lookup_type_die (containing_scope);
12024 scope_die = context_die;
12029 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12032 local_scope_p (dw_die_ref context_die)
12034 for (; context_die; context_die = context_die->die_parent)
12035 if (context_die->die_tag == DW_TAG_inlined_subroutine
12036 || context_die->die_tag == DW_TAG_subprogram)
12042 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12043 whether or not to treat a DIE in this context as a declaration. */
12046 class_or_namespace_scope_p (dw_die_ref context_die)
12048 return (context_die
12049 && (context_die->die_tag == DW_TAG_structure_type
12050 || context_die->die_tag == DW_TAG_class_type
12051 || context_die->die_tag == DW_TAG_interface_type
12052 || context_die->die_tag == DW_TAG_union_type
12053 || context_die->die_tag == DW_TAG_namespace));
12056 /* Many forms of DIEs require a "type description" attribute. This
12057 routine locates the proper "type descriptor" die for the type given
12058 by 'type', and adds a DW_AT_type attribute below the given die. */
12061 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
12062 int decl_volatile, dw_die_ref context_die)
12064 enum tree_code code = TREE_CODE (type);
12065 dw_die_ref type_die = NULL;
12067 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12068 or fixed-point type, use the inner type. This is because we have no
12069 support for unnamed types in base_type_die. This can happen if this is
12070 an Ada subrange type. Correct solution is emit a subrange type die. */
12071 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
12072 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
12073 type = TREE_TYPE (type), code = TREE_CODE (type);
12075 if (code == ERROR_MARK
12076 /* Handle a special case. For functions whose return type is void, we
12077 generate *no* type attribute. (Note that no object may have type
12078 `void', so this only applies to function return types). */
12079 || code == VOID_TYPE)
12082 type_die = modified_type_die (type,
12083 decl_const || TYPE_READONLY (type),
12084 decl_volatile || TYPE_VOLATILE (type),
12087 if (type_die != NULL)
12088 add_AT_die_ref (object_die, DW_AT_type, type_die);
12091 /* Given an object die, add the calling convention attribute for the
12092 function call type. */
12094 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
12096 enum dwarf_calling_convention value = DW_CC_normal;
12098 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
12100 /* DWARF doesn't provide a way to identify a program's source-level
12101 entry point. DW_AT_calling_convention attributes are only meant
12102 to describe functions' calling conventions. However, lacking a
12103 better way to signal the Fortran main program, we use this for the
12104 time being, following existing custom. */
12106 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
12107 value = DW_CC_program;
12109 /* Only add the attribute if the backend requests it, and
12110 is not DW_CC_normal. */
12111 if (value && (value != DW_CC_normal))
12112 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
12115 /* Given a tree pointer to a struct, class, union, or enum type node, return
12116 a pointer to the (string) tag name for the given type, or zero if the type
12117 was declared without a tag. */
12119 static const char *
12120 type_tag (const_tree type)
12122 const char *name = 0;
12124 if (TYPE_NAME (type) != 0)
12128 /* Find the IDENTIFIER_NODE for the type name. */
12129 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
12130 t = TYPE_NAME (type);
12132 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12133 a TYPE_DECL node, regardless of whether or not a `typedef' was
12135 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12136 && ! DECL_IGNORED_P (TYPE_NAME (type)))
12138 /* We want to be extra verbose. Don't call dwarf_name if
12139 DECL_NAME isn't set. The default hook for decl_printable_name
12140 doesn't like that, and in this context it's correct to return
12141 0, instead of "<anonymous>" or the like. */
12142 if (DECL_NAME (TYPE_NAME (type)))
12143 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
12146 /* Now get the name as a string, or invent one. */
12147 if (!name && t != 0)
12148 name = IDENTIFIER_POINTER (t);
12151 return (name == 0 || *name == '\0') ? 0 : name;
12154 /* Return the type associated with a data member, make a special check
12155 for bit field types. */
12158 member_declared_type (const_tree member)
12160 return (DECL_BIT_FIELD_TYPE (member)
12161 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
12164 /* Get the decl's label, as described by its RTL. This may be different
12165 from the DECL_NAME name used in the source file. */
12168 static const char *
12169 decl_start_label (tree decl)
12172 const char *fnname;
12174 x = DECL_RTL (decl);
12175 gcc_assert (MEM_P (x));
12178 gcc_assert (GET_CODE (x) == SYMBOL_REF);
12180 fnname = XSTR (x, 0);
12185 /* These routines generate the internal representation of the DIE's for
12186 the compilation unit. Debugging information is collected by walking
12187 the declaration trees passed in from dwarf2out_decl(). */
12190 gen_array_type_die (tree type, dw_die_ref context_die)
12192 dw_die_ref scope_die = scope_die_for (type, context_die);
12193 dw_die_ref array_die;
12195 /* GNU compilers represent multidimensional array types as sequences of one
12196 dimensional array types whose element types are themselves array types.
12197 We sometimes squish that down to a single array_type DIE with multiple
12198 subscripts in the Dwarf debugging info. The draft Dwarf specification
12199 say that we are allowed to do this kind of compression in C, because
12200 there is no difference between an array of arrays and a multidimensional
12201 array. We don't do this for Ada to remain as close as possible to the
12202 actual representation, which is especially important against the language
12203 flexibilty wrt arrays of variable size. */
12205 bool collapse_nested_arrays = !is_ada ();
12208 /* ??? The SGI dwarf reader fails for array of array of enum types
12209 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12210 array type comes before the outer array type. We thus call gen_type_die
12211 before we new_die and must prevent nested array types collapsing for this
12214 #ifdef MIPS_DEBUGGING_INFO
12215 gen_type_die (TREE_TYPE (type), context_die);
12216 collapse_nested_arrays = false;
12219 array_die = new_die (DW_TAG_array_type, scope_die, type);
12220 add_name_attribute (array_die, type_tag (type));
12221 equate_type_number_to_die (type, array_die);
12223 if (TREE_CODE (type) == VECTOR_TYPE)
12225 /* The frontend feeds us a representation for the vector as a struct
12226 containing an array. Pull out the array type. */
12227 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
12228 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
12231 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12233 && TREE_CODE (type) == ARRAY_TYPE
12234 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
12235 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12238 /* We default the array ordering. SDB will probably do
12239 the right things even if DW_AT_ordering is not present. It's not even
12240 an issue until we start to get into multidimensional arrays anyway. If
12241 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12242 then we'll have to put the DW_AT_ordering attribute back in. (But if
12243 and when we find out that we need to put these in, we will only do so
12244 for multidimensional arrays. */
12245 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
12248 #ifdef MIPS_DEBUGGING_INFO
12249 /* The SGI compilers handle arrays of unknown bound by setting
12250 AT_declaration and not emitting any subrange DIEs. */
12251 if (! TYPE_DOMAIN (type))
12252 add_AT_flag (array_die, DW_AT_declaration, 1);
12255 add_subscript_info (array_die, type, collapse_nested_arrays);
12257 /* Add representation of the type of the elements of this array type and
12258 emit the corresponding DIE if we haven't done it already. */
12259 element_type = TREE_TYPE (type);
12260 if (collapse_nested_arrays)
12261 while (TREE_CODE (element_type) == ARRAY_TYPE)
12262 element_type = TREE_TYPE (element_type);
12264 #ifndef MIPS_DEBUGGING_INFO
12265 gen_type_die (element_type, context_die);
12268 add_type_attribute (array_die, element_type, 0, 0, context_die);
12270 if (get_AT (array_die, DW_AT_name))
12271 add_pubtype (type, array_die);
12274 static dw_loc_descr_ref
12275 descr_info_loc (tree val, tree base_decl)
12277 HOST_WIDE_INT size;
12278 dw_loc_descr_ref loc, loc2;
12279 enum dwarf_location_atom op;
12281 if (val == base_decl)
12282 return new_loc_descr (DW_OP_push_object_address, 0, 0);
12284 switch (TREE_CODE (val))
12287 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12289 if (host_integerp (val, 0))
12290 return int_loc_descriptor (tree_low_cst (val, 0));
12293 size = int_size_in_bytes (TREE_TYPE (val));
12296 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12299 if (size == DWARF2_ADDR_SIZE)
12300 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
12302 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
12304 case POINTER_PLUS_EXPR:
12306 if (host_integerp (TREE_OPERAND (val, 1), 1)
12307 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
12310 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12313 add_loc_descr (&loc,
12314 new_loc_descr (DW_OP_plus_uconst,
12315 tree_low_cst (TREE_OPERAND (val, 1),
12322 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
12325 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
12328 add_loc_descr (&loc, loc2);
12329 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
12351 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
12352 tree val, tree base_decl)
12354 dw_loc_descr_ref loc;
12356 if (host_integerp (val, 0))
12358 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
12362 loc = descr_info_loc (val, base_decl);
12366 add_AT_loc (die, attr, loc);
12369 /* This routine generates DIE for array with hidden descriptor, details
12370 are filled into *info by a langhook. */
12373 gen_descr_array_type_die (tree type, struct array_descr_info *info,
12374 dw_die_ref context_die)
12376 dw_die_ref scope_die = scope_die_for (type, context_die);
12377 dw_die_ref array_die;
12380 array_die = new_die (DW_TAG_array_type, scope_die, type);
12381 add_name_attribute (array_die, type_tag (type));
12382 equate_type_number_to_die (type, array_die);
12384 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12386 && info->ndimensions >= 2)
12387 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
12389 if (info->data_location)
12390 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
12392 if (info->associated)
12393 add_descr_info_field (array_die, DW_AT_associated, info->associated,
12395 if (info->allocated)
12396 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
12399 for (dim = 0; dim < info->ndimensions; dim++)
12401 dw_die_ref subrange_die
12402 = new_die (DW_TAG_subrange_type, array_die, NULL);
12404 if (info->dimen[dim].lower_bound)
12406 /* If it is the default value, omit it. */
12407 if ((is_c_family () || is_java ())
12408 && integer_zerop (info->dimen[dim].lower_bound))
12410 else if (is_fortran ()
12411 && integer_onep (info->dimen[dim].lower_bound))
12414 add_descr_info_field (subrange_die, DW_AT_lower_bound,
12415 info->dimen[dim].lower_bound,
12418 if (info->dimen[dim].upper_bound)
12419 add_descr_info_field (subrange_die, DW_AT_upper_bound,
12420 info->dimen[dim].upper_bound,
12422 if (info->dimen[dim].stride)
12423 add_descr_info_field (subrange_die, DW_AT_byte_stride,
12424 info->dimen[dim].stride,
12428 gen_type_die (info->element_type, context_die);
12429 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
12431 if (get_AT (array_die, DW_AT_name))
12432 add_pubtype (type, array_die);
12437 gen_entry_point_die (tree decl, dw_die_ref context_die)
12439 tree origin = decl_ultimate_origin (decl);
12440 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
12442 if (origin != NULL)
12443 add_abstract_origin_attribute (decl_die, origin);
12446 add_name_and_src_coords_attributes (decl_die, decl);
12447 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
12448 0, 0, context_die);
12451 if (DECL_ABSTRACT (decl))
12452 equate_decl_number_to_die (decl, decl_die);
12454 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
12458 /* Walk through the list of incomplete types again, trying once more to
12459 emit full debugging info for them. */
12462 retry_incomplete_types (void)
12466 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
12467 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
12470 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12473 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
12475 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
12477 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12478 be incomplete and such types are not marked. */
12479 add_abstract_origin_attribute (type_die, type);
12482 /* Determine what tag to use for a record type. */
12484 static enum dwarf_tag
12485 record_type_tag (tree type)
12487 if (! lang_hooks.types.classify_record)
12488 return DW_TAG_structure_type;
12490 switch (lang_hooks.types.classify_record (type))
12492 case RECORD_IS_STRUCT:
12493 return DW_TAG_structure_type;
12495 case RECORD_IS_CLASS:
12496 return DW_TAG_class_type;
12498 case RECORD_IS_INTERFACE:
12499 return DW_TAG_interface_type;
12502 gcc_unreachable ();
12506 /* Generate a DIE to represent an inlined instance of a structure type. */
12509 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
12511 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
12513 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12514 be incomplete and such types are not marked. */
12515 add_abstract_origin_attribute (type_die, type);
12518 /* Generate a DIE to represent an inlined instance of a union type. */
12521 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
12523 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
12525 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12526 be incomplete and such types are not marked. */
12527 add_abstract_origin_attribute (type_die, type);
12530 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12531 include all of the information about the enumeration values also. Each
12532 enumerated type name/value is listed as a child of the enumerated type
12536 gen_enumeration_type_die (tree type, dw_die_ref context_die)
12538 dw_die_ref type_die = lookup_type_die (type);
12540 if (type_die == NULL)
12542 type_die = new_die (DW_TAG_enumeration_type,
12543 scope_die_for (type, context_die), type);
12544 equate_type_number_to_die (type, type_die);
12545 add_name_attribute (type_die, type_tag (type));
12547 else if (! TYPE_SIZE (type))
12550 remove_AT (type_die, DW_AT_declaration);
12552 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12553 given enum type is incomplete, do not generate the DW_AT_byte_size
12554 attribute or the DW_AT_element_list attribute. */
12555 if (TYPE_SIZE (type))
12559 TREE_ASM_WRITTEN (type) = 1;
12560 add_byte_size_attribute (type_die, type);
12561 if (TYPE_STUB_DECL (type) != NULL_TREE)
12562 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12564 /* If the first reference to this type was as the return type of an
12565 inline function, then it may not have a parent. Fix this now. */
12566 if (type_die->die_parent == NULL)
12567 add_child_die (scope_die_for (type, context_die), type_die);
12569 for (link = TYPE_VALUES (type);
12570 link != NULL; link = TREE_CHAIN (link))
12572 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12573 tree value = TREE_VALUE (link);
12575 add_name_attribute (enum_die,
12576 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12578 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12579 /* DWARF2 does not provide a way of indicating whether or
12580 not enumeration constants are signed or unsigned. GDB
12581 always assumes the values are signed, so we output all
12582 values as if they were signed. That means that
12583 enumeration constants with very large unsigned values
12584 will appear to have negative values in the debugger. */
12585 add_AT_int (enum_die, DW_AT_const_value,
12586 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12590 add_AT_flag (type_die, DW_AT_declaration, 1);
12592 if (get_AT (type_die, DW_AT_name))
12593 add_pubtype (type, type_die);
12598 /* Generate a DIE to represent either a real live formal parameter decl or to
12599 represent just the type of some formal parameter position in some function
12602 Note that this routine is a bit unusual because its argument may be a
12603 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12604 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12605 node. If it's the former then this function is being called to output a
12606 DIE to represent a formal parameter object (or some inlining thereof). If
12607 it's the latter, then this function is only being called to output a
12608 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12609 argument type of some subprogram type. */
12612 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12614 dw_die_ref parm_die
12615 = new_die (DW_TAG_formal_parameter, context_die, node);
12618 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12620 case tcc_declaration:
12621 origin = decl_ultimate_origin (node);
12622 if (origin != NULL)
12623 add_abstract_origin_attribute (parm_die, origin);
12626 tree type = TREE_TYPE (node);
12627 add_name_and_src_coords_attributes (parm_die, node);
12628 if (DECL_BY_REFERENCE (node))
12629 type = TREE_TYPE (type);
12630 add_type_attribute (parm_die, type,
12631 TREE_READONLY (node),
12632 TREE_THIS_VOLATILE (node),
12634 if (DECL_ARTIFICIAL (node))
12635 add_AT_flag (parm_die, DW_AT_artificial, 1);
12638 equate_decl_number_to_die (node, parm_die);
12639 if (! DECL_ABSTRACT (node))
12640 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12645 /* We were called with some kind of a ..._TYPE node. */
12646 add_type_attribute (parm_die, node, 0, 0, context_die);
12650 gcc_unreachable ();
12656 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12657 at the end of an (ANSI prototyped) formal parameters list. */
12660 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12662 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12665 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12666 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12667 parameters as specified in some function type specification (except for
12668 those which appear as part of a function *definition*). */
12671 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
12674 tree formal_type = NULL;
12675 tree first_parm_type;
12678 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
12680 arg = DECL_ARGUMENTS (function_or_method_type);
12681 function_or_method_type = TREE_TYPE (function_or_method_type);
12686 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
12688 /* Make our first pass over the list of formal parameter types and output a
12689 DW_TAG_formal_parameter DIE for each one. */
12690 for (link = first_parm_type; link; )
12692 dw_die_ref parm_die;
12694 formal_type = TREE_VALUE (link);
12695 if (formal_type == void_type_node)
12698 /* Output a (nameless) DIE to represent the formal parameter itself. */
12699 parm_die = gen_formal_parameter_die (formal_type, context_die);
12700 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
12701 && link == first_parm_type)
12702 || (arg && DECL_ARTIFICIAL (arg)))
12703 add_AT_flag (parm_die, DW_AT_artificial, 1);
12705 link = TREE_CHAIN (link);
12707 arg = TREE_CHAIN (arg);
12710 /* If this function type has an ellipsis, add a
12711 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12712 if (formal_type != void_type_node)
12713 gen_unspecified_parameters_die (function_or_method_type, context_die);
12715 /* Make our second (and final) pass over the list of formal parameter types
12716 and output DIEs to represent those types (as necessary). */
12717 for (link = TYPE_ARG_TYPES (function_or_method_type);
12718 link && TREE_VALUE (link);
12719 link = TREE_CHAIN (link))
12720 gen_type_die (TREE_VALUE (link), context_die);
12723 /* We want to generate the DIE for TYPE so that we can generate the
12724 die for MEMBER, which has been defined; we will need to refer back
12725 to the member declaration nested within TYPE. If we're trying to
12726 generate minimal debug info for TYPE, processing TYPE won't do the
12727 trick; we need to attach the member declaration by hand. */
12730 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
12732 gen_type_die (type, context_die);
12734 /* If we're trying to avoid duplicate debug info, we may not have
12735 emitted the member decl for this function. Emit it now. */
12736 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
12737 && ! lookup_decl_die (member))
12739 dw_die_ref type_die;
12740 gcc_assert (!decl_ultimate_origin (member));
12742 push_decl_scope (type);
12743 type_die = lookup_type_die (type);
12744 if (TREE_CODE (member) == FUNCTION_DECL)
12745 gen_subprogram_die (member, type_die);
12746 else if (TREE_CODE (member) == FIELD_DECL)
12748 /* Ignore the nameless fields that are used to skip bits but handle
12749 C++ anonymous unions and structs. */
12750 if (DECL_NAME (member) != NULL_TREE
12751 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
12752 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
12754 gen_type_die (member_declared_type (member), type_die);
12755 gen_field_die (member, type_die);
12759 gen_variable_die (member, type_die);
12765 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12766 may later generate inlined and/or out-of-line instances of. */
12769 dwarf2out_abstract_function (tree decl)
12771 dw_die_ref old_die;
12774 int was_abstract = DECL_ABSTRACT (decl);
12776 /* Make sure we have the actual abstract inline, not a clone. */
12777 decl = DECL_ORIGIN (decl);
12779 old_die = lookup_decl_die (decl);
12780 if (old_die && get_AT (old_die, DW_AT_inline))
12781 /* We've already generated the abstract instance. */
12784 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12785 we don't get confused by DECL_ABSTRACT. */
12786 if (debug_info_level > DINFO_LEVEL_TERSE)
12788 context = decl_class_context (decl);
12790 gen_type_die_for_member
12791 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
12794 /* Pretend we've just finished compiling this function. */
12795 save_fn = current_function_decl;
12796 current_function_decl = decl;
12797 push_cfun (DECL_STRUCT_FUNCTION (decl));
12799 set_decl_abstract_flags (decl, 1);
12800 dwarf2out_decl (decl);
12801 if (! was_abstract)
12802 set_decl_abstract_flags (decl, 0);
12804 current_function_decl = save_fn;
12808 /* Helper function of premark_used_types() which gets called through
12809 htab_traverse_resize().
12811 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12812 marked as unused by prune_unused_types. */
12814 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
12819 type = (tree) *slot;
12820 die = lookup_type_die (type);
12822 die->die_perennial_p = 1;
12826 /* Mark all members of used_types_hash as perennial. */
12828 premark_used_types (void)
12830 if (cfun && cfun->used_types_hash)
12831 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
12834 /* Generate a DIE to represent a declared function (either file-scope or
12838 gen_subprogram_die (tree decl, dw_die_ref context_die)
12840 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12841 tree origin = decl_ultimate_origin (decl);
12842 dw_die_ref subr_die;
12845 dw_die_ref old_die = lookup_decl_die (decl);
12846 int declaration = (current_function_decl != decl
12847 || class_or_namespace_scope_p (context_die));
12849 premark_used_types ();
12851 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12852 started to generate the abstract instance of an inline, decided to output
12853 its containing class, and proceeded to emit the declaration of the inline
12854 from the member list for the class. If so, DECLARATION takes priority;
12855 we'll get back to the abstract instance when done with the class. */
12857 /* The class-scope declaration DIE must be the primary DIE. */
12858 if (origin && declaration && class_or_namespace_scope_p (context_die))
12861 gcc_assert (!old_die);
12864 /* Now that the C++ front end lazily declares artificial member fns, we
12865 might need to retrofit the declaration into its class. */
12866 if (!declaration && !origin && !old_die
12867 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
12868 && !class_or_namespace_scope_p (context_die)
12869 && debug_info_level > DINFO_LEVEL_TERSE)
12870 old_die = force_decl_die (decl);
12872 if (origin != NULL)
12874 gcc_assert (!declaration || local_scope_p (context_die));
12876 /* Fixup die_parent for the abstract instance of a nested
12877 inline function. */
12878 if (old_die && old_die->die_parent == NULL)
12879 add_child_die (context_die, old_die);
12881 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12882 add_abstract_origin_attribute (subr_die, origin);
12886 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12887 struct dwarf_file_data * file_index = lookup_filename (s.file);
12889 if (!get_AT_flag (old_die, DW_AT_declaration)
12890 /* We can have a normal definition following an inline one in the
12891 case of redefinition of GNU C extern inlines.
12892 It seems reasonable to use AT_specification in this case. */
12893 && !get_AT (old_die, DW_AT_inline))
12895 /* Detect and ignore this case, where we are trying to output
12896 something we have already output. */
12900 /* If the definition comes from the same place as the declaration,
12901 maybe use the old DIE. We always want the DIE for this function
12902 that has the *_pc attributes to be under comp_unit_die so the
12903 debugger can find it. We also need to do this for abstract
12904 instances of inlines, since the spec requires the out-of-line copy
12905 to have the same parent. For local class methods, this doesn't
12906 apply; we just use the old DIE. */
12907 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
12908 && (DECL_ARTIFICIAL (decl)
12909 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
12910 && (get_AT_unsigned (old_die, DW_AT_decl_line)
12911 == (unsigned) s.line))))
12913 subr_die = old_die;
12915 /* Clear out the declaration attribute and the formal parameters.
12916 Do not remove all children, because it is possible that this
12917 declaration die was forced using force_decl_die(). In such
12918 cases die that forced declaration die (e.g. TAG_imported_module)
12919 is one of the children that we do not want to remove. */
12920 remove_AT (subr_die, DW_AT_declaration);
12921 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
12925 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12926 add_AT_specification (subr_die, old_die);
12927 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12928 add_AT_file (subr_die, DW_AT_decl_file, file_index);
12929 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12930 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
12935 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12937 if (TREE_PUBLIC (decl))
12938 add_AT_flag (subr_die, DW_AT_external, 1);
12940 add_name_and_src_coords_attributes (subr_die, decl);
12941 if (debug_info_level > DINFO_LEVEL_TERSE)
12943 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
12944 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
12945 0, 0, context_die);
12948 add_pure_or_virtual_attribute (subr_die, decl);
12949 if (DECL_ARTIFICIAL (decl))
12950 add_AT_flag (subr_die, DW_AT_artificial, 1);
12952 if (TREE_PROTECTED (decl))
12953 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
12954 else if (TREE_PRIVATE (decl))
12955 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
12960 if (!old_die || !get_AT (old_die, DW_AT_inline))
12962 add_AT_flag (subr_die, DW_AT_declaration, 1);
12964 /* The first time we see a member function, it is in the context of
12965 the class to which it belongs. We make sure of this by emitting
12966 the class first. The next time is the definition, which is
12967 handled above. The two may come from the same source text.
12969 Note that force_decl_die() forces function declaration die. It is
12970 later reused to represent definition. */
12971 equate_decl_number_to_die (decl, subr_die);
12974 else if (DECL_ABSTRACT (decl))
12976 if (DECL_DECLARED_INLINE_P (decl))
12978 if (cgraph_function_possibly_inlined_p (decl))
12979 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
12981 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
12985 if (cgraph_function_possibly_inlined_p (decl))
12986 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
12988 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
12991 if (DECL_DECLARED_INLINE_P (decl)
12992 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
12993 add_AT_flag (subr_die, DW_AT_artificial, 1);
12995 equate_decl_number_to_die (decl, subr_die);
12997 else if (!DECL_EXTERNAL (decl))
12999 HOST_WIDE_INT cfa_fb_offset;
13001 if (!old_die || !get_AT (old_die, DW_AT_inline))
13002 equate_decl_number_to_die (decl, subr_die);
13004 if (!flag_reorder_blocks_and_partition)
13006 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
13007 current_function_funcdef_no);
13008 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
13009 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
13010 current_function_funcdef_no);
13011 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
13013 add_pubname (decl, subr_die);
13014 add_arange (decl, subr_die);
13017 { /* Do nothing for now; maybe need to duplicate die, one for
13018 hot section and one for cold section, then use the hot/cold
13019 section begin/end labels to generate the aranges... */
13021 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13022 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13023 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13024 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13026 add_pubname (decl, subr_die);
13027 add_arange (decl, subr_die);
13028 add_arange (decl, subr_die);
13032 #ifdef MIPS_DEBUGGING_INFO
13033 /* Add a reference to the FDE for this routine. */
13034 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
13037 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
13039 /* We define the "frame base" as the function's CFA. This is more
13040 convenient for several reasons: (1) It's stable across the prologue
13041 and epilogue, which makes it better than just a frame pointer,
13042 (2) With dwarf3, there exists a one-byte encoding that allows us
13043 to reference the .debug_frame data by proxy, but failing that,
13044 (3) We can at least reuse the code inspection and interpretation
13045 code that determines the CFA position at various points in the
13047 /* ??? Use some command-line or configury switch to enable the use
13048 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13049 consumers that understand it; fall back to "pure" dwarf2 and
13050 convert the CFA data into a location list. */
13052 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
13053 if (list->dw_loc_next)
13054 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
13056 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
13059 /* Compute a displacement from the "steady-state frame pointer" to
13060 the CFA. The former is what all stack slots and argument slots
13061 will reference in the rtl; the later is what we've told the
13062 debugger about. We'll need to adjust all frame_base references
13063 by this displacement. */
13064 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
13066 if (cfun->static_chain_decl)
13067 add_AT_location_description (subr_die, DW_AT_static_link,
13068 loc_descriptor_from_tree (cfun->static_chain_decl));
13071 /* Now output descriptions of the arguments for this function. This gets
13072 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13073 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13074 `...' at the end of the formal parameter list. In order to find out if
13075 there was a trailing ellipsis or not, we must instead look at the type
13076 associated with the FUNCTION_DECL. This will be a node of type
13077 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13078 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13079 an ellipsis at the end. */
13081 /* In the case where we are describing a mere function declaration, all we
13082 need to do here (and all we *can* do here) is to describe the *types* of
13083 its formal parameters. */
13084 if (debug_info_level <= DINFO_LEVEL_TERSE)
13086 else if (declaration)
13087 gen_formal_types_die (decl, subr_die);
13090 /* Generate DIEs to represent all known formal parameters. */
13091 tree arg_decls = DECL_ARGUMENTS (decl);
13094 /* When generating DIEs, generate the unspecified_parameters DIE
13095 instead if we come across the arg "__builtin_va_alist" */
13096 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
13097 if (TREE_CODE (parm) == PARM_DECL)
13099 if (DECL_NAME (parm)
13100 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
13101 "__builtin_va_alist"))
13102 gen_unspecified_parameters_die (parm, subr_die);
13104 gen_decl_die (parm, subr_die);
13107 /* Decide whether we need an unspecified_parameters DIE at the end.
13108 There are 2 more cases to do this for: 1) the ansi ... declaration -
13109 this is detectable when the end of the arg list is not a
13110 void_type_node 2) an unprototyped function declaration (not a
13111 definition). This just means that we have no info about the
13112 parameters at all. */
13113 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
13114 if (fn_arg_types != NULL)
13116 /* This is the prototyped case, check for.... */
13117 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
13118 gen_unspecified_parameters_die (decl, subr_die);
13120 else if (DECL_INITIAL (decl) == NULL_TREE)
13121 gen_unspecified_parameters_die (decl, subr_die);
13124 /* Output Dwarf info for all of the stuff within the body of the function
13125 (if it has one - it may be just a declaration). */
13126 outer_scope = DECL_INITIAL (decl);
13128 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13129 a function. This BLOCK actually represents the outermost binding contour
13130 for the function, i.e. the contour in which the function's formal
13131 parameters and labels get declared. Curiously, it appears that the front
13132 end doesn't actually put the PARM_DECL nodes for the current function onto
13133 the BLOCK_VARS list for this outer scope, but are strung off of the
13134 DECL_ARGUMENTS list for the function instead.
13136 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13137 the LABEL_DECL nodes for the function however, and we output DWARF info
13138 for those in decls_for_scope. Just within the `outer_scope' there will be
13139 a BLOCK node representing the function's outermost pair of curly braces,
13140 and any blocks used for the base and member initializers of a C++
13141 constructor function. */
13142 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
13144 /* Emit a DW_TAG_variable DIE for a named return value. */
13145 if (DECL_NAME (DECL_RESULT (decl)))
13146 gen_decl_die (DECL_RESULT (decl), subr_die);
13148 current_function_has_inlines = 0;
13149 decls_for_scope (outer_scope, subr_die, 0);
13151 #if 0 && defined (MIPS_DEBUGGING_INFO)
13152 if (current_function_has_inlines)
13154 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
13155 if (! comp_unit_has_inlines)
13157 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
13158 comp_unit_has_inlines = 1;
13163 /* Add the calling convention attribute if requested. */
13164 add_calling_convention_attribute (subr_die, decl);
13168 /* Generate a DIE to represent a declared data object. */
13171 gen_variable_die (tree decl, dw_die_ref context_die)
13175 dw_die_ref var_die;
13176 tree origin = decl_ultimate_origin (decl);
13177 dw_die_ref old_die = lookup_decl_die (decl);
13178 int declaration = (DECL_EXTERNAL (decl)
13179 /* If DECL is COMDAT and has not actually been
13180 emitted, we cannot take its address; there
13181 might end up being no definition anywhere in
13182 the program. For example, consider the C++
13186 struct S { static const int i = 7; };
13191 int f() { return S<int>::i; }
13193 Here, S<int>::i is not DECL_EXTERNAL, but no
13194 definition is required, so the compiler will
13195 not emit a definition. */
13196 || (TREE_CODE (decl) == VAR_DECL
13197 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
13198 || class_or_namespace_scope_p (context_die));
13200 com_decl = fortran_common (decl, &off);
13202 /* Symbol in common gets emitted as a child of the common block, in the form
13205 ??? This creates a new common block die for every common block symbol.
13206 Better to share same common block die for all symbols in that block. */
13210 dw_die_ref com_die;
13211 const char *cnam = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
13212 dw_loc_descr_ref loc = loc_descriptor_from_tree (com_decl);
13214 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
13215 var_die = new_die (DW_TAG_common_block, context_die, decl);
13216 add_name_and_src_coords_attributes (var_die, field);
13217 add_AT_flag (var_die, DW_AT_external, 1);
13218 add_AT_loc (var_die, DW_AT_location, loc);
13219 com_die = new_die (DW_TAG_member, var_die, decl);
13220 add_name_and_src_coords_attributes (com_die, decl);
13221 add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl),
13222 TREE_THIS_VOLATILE (decl), context_die);
13223 add_AT_loc (com_die, DW_AT_data_member_location,
13224 int_loc_descriptor (off));
13225 add_pubname_string (cnam, var_die); /* ??? needed? */
13229 var_die = new_die (DW_TAG_variable, context_die, decl);
13231 if (origin != NULL)
13232 add_abstract_origin_attribute (var_die, origin);
13234 /* Loop unrolling can create multiple blocks that refer to the same
13235 static variable, so we must test for the DW_AT_declaration flag.
13237 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13238 copy decls and set the DECL_ABSTRACT flag on them instead of
13241 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13243 ??? The declare_in_namespace support causes us to get two DIEs for one
13244 variable, both of which are declarations. We want to avoid considering
13245 one to be a specification, so we must test that this DIE is not a
13247 else if (old_die && TREE_STATIC (decl) && ! declaration
13248 && get_AT_flag (old_die, DW_AT_declaration) == 1)
13250 /* This is a definition of a C++ class level static. */
13251 add_AT_specification (var_die, old_die);
13252 if (DECL_NAME (decl))
13254 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
13255 struct dwarf_file_data * file_index = lookup_filename (s.file);
13257 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
13258 add_AT_file (var_die, DW_AT_decl_file, file_index);
13260 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
13261 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
13266 tree type = TREE_TYPE (decl);
13267 if ((TREE_CODE (decl) == PARM_DECL
13268 || TREE_CODE (decl) == RESULT_DECL)
13269 && DECL_BY_REFERENCE (decl))
13270 type = TREE_TYPE (type);
13272 add_name_and_src_coords_attributes (var_die, decl);
13273 add_type_attribute (var_die, type, TREE_READONLY (decl),
13274 TREE_THIS_VOLATILE (decl), context_die);
13276 if (TREE_PUBLIC (decl))
13277 add_AT_flag (var_die, DW_AT_external, 1);
13279 if (DECL_ARTIFICIAL (decl))
13280 add_AT_flag (var_die, DW_AT_artificial, 1);
13282 if (TREE_PROTECTED (decl))
13283 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
13284 else if (TREE_PRIVATE (decl))
13285 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
13289 add_AT_flag (var_die, DW_AT_declaration, 1);
13291 if (DECL_ABSTRACT (decl) || declaration)
13292 equate_decl_number_to_die (decl, var_die);
13294 if (! declaration && ! DECL_ABSTRACT (decl))
13296 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
13297 add_pubname (decl, var_die);
13300 tree_add_const_value_attribute (var_die, decl);
13303 /* Generate a DIE to represent a label identifier. */
13306 gen_label_die (tree decl, dw_die_ref context_die)
13308 tree origin = decl_ultimate_origin (decl);
13309 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
13311 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13313 if (origin != NULL)
13314 add_abstract_origin_attribute (lbl_die, origin);
13316 add_name_and_src_coords_attributes (lbl_die, decl);
13318 if (DECL_ABSTRACT (decl))
13319 equate_decl_number_to_die (decl, lbl_die);
13322 insn = DECL_RTL_IF_SET (decl);
13324 /* Deleted labels are programmer specified labels which have been
13325 eliminated because of various optimizations. We still emit them
13326 here so that it is possible to put breakpoints on them. */
13330 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
13332 /* When optimization is enabled (via -O) some parts of the compiler
13333 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
13334 represent source-level labels which were explicitly declared by
13335 the user. This really shouldn't be happening though, so catch
13336 it if it ever does happen. */
13337 gcc_assert (!INSN_DELETED_P (insn));
13339 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
13340 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
13345 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
13346 attributes to the DIE for a block STMT, to describe where the inlined
13347 function was called from. This is similar to add_src_coords_attributes. */
13350 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
13352 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
13354 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
13355 add_AT_unsigned (die, DW_AT_call_line, s.line);
13359 /* If STMT's abstract origin is a function declaration and STMT's
13360 first subblock's abstract origin is the function's outermost block,
13361 then we're looking at the main entry point. */
13363 is_inlined_entry_point (const_tree stmt)
13367 if (!stmt || TREE_CODE (stmt) != BLOCK)
13370 decl = block_ultimate_origin (stmt);
13372 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
13375 block = BLOCK_SUBBLOCKS (stmt);
13379 if (TREE_CODE (block) != BLOCK)
13382 block = block_ultimate_origin (block);
13385 return block == DECL_INITIAL (decl);
13388 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
13389 Add low_pc and high_pc attributes to the DIE for a block STMT. */
13392 add_high_low_attributes (tree stmt, dw_die_ref die)
13394 char label[MAX_ARTIFICIAL_LABEL_BYTES];
13396 if (BLOCK_FRAGMENT_CHAIN (stmt))
13400 if (is_inlined_entry_point (stmt))
13402 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13403 BLOCK_NUMBER (stmt));
13404 add_AT_lbl_id (die, DW_AT_entry_pc, label);
13407 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
13409 chain = BLOCK_FRAGMENT_CHAIN (stmt);
13412 add_ranges (chain);
13413 chain = BLOCK_FRAGMENT_CHAIN (chain);
13420 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
13421 BLOCK_NUMBER (stmt));
13422 add_AT_lbl_id (die, DW_AT_low_pc, label);
13423 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
13424 BLOCK_NUMBER (stmt));
13425 add_AT_lbl_id (die, DW_AT_high_pc, label);
13429 /* Generate a DIE for a lexical block. */
13432 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
13434 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
13436 if (! BLOCK_ABSTRACT (stmt))
13437 add_high_low_attributes (stmt, stmt_die);
13439 decls_for_scope (stmt, stmt_die, depth);
13442 /* Generate a DIE for an inlined subprogram. */
13445 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
13447 tree decl = block_ultimate_origin (stmt);
13449 /* Emit info for the abstract instance first, if we haven't yet. We
13450 must emit this even if the block is abstract, otherwise when we
13451 emit the block below (or elsewhere), we may end up trying to emit
13452 a die whose origin die hasn't been emitted, and crashing. */
13453 dwarf2out_abstract_function (decl);
13455 if (! BLOCK_ABSTRACT (stmt))
13457 dw_die_ref subr_die
13458 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
13460 add_abstract_origin_attribute (subr_die, decl);
13461 add_high_low_attributes (stmt, subr_die);
13462 add_call_src_coords_attributes (stmt, subr_die);
13464 decls_for_scope (stmt, subr_die, depth);
13465 current_function_has_inlines = 1;
13468 /* We may get here if we're the outer block of function A that was
13469 inlined into function B that was inlined into function C. When
13470 generating debugging info for C, dwarf2out_abstract_function(B)
13471 would mark all inlined blocks as abstract, including this one.
13472 So, we wouldn't (and shouldn't) expect labels to be generated
13473 for this one. Instead, just emit debugging info for
13474 declarations within the block. This is particularly important
13475 in the case of initializers of arguments passed from B to us:
13476 if they're statement expressions containing declarations, we
13477 wouldn't generate dies for their abstract variables, and then,
13478 when generating dies for the real variables, we'd die (pun
13480 gen_lexical_block_die (stmt, context_die, depth);
13483 /* Generate a DIE for a field in a record, or structure. */
13486 gen_field_die (tree decl, dw_die_ref context_die)
13488 dw_die_ref decl_die;
13490 if (TREE_TYPE (decl) == error_mark_node)
13493 decl_die = new_die (DW_TAG_member, context_die, decl);
13494 add_name_and_src_coords_attributes (decl_die, decl);
13495 add_type_attribute (decl_die, member_declared_type (decl),
13496 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
13499 if (DECL_BIT_FIELD_TYPE (decl))
13501 add_byte_size_attribute (decl_die, decl);
13502 add_bit_size_attribute (decl_die, decl);
13503 add_bit_offset_attribute (decl_die, decl);
13506 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
13507 add_data_member_location_attribute (decl_die, decl);
13509 if (DECL_ARTIFICIAL (decl))
13510 add_AT_flag (decl_die, DW_AT_artificial, 1);
13512 if (TREE_PROTECTED (decl))
13513 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
13514 else if (TREE_PRIVATE (decl))
13515 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
13517 /* Equate decl number to die, so that we can look up this decl later on. */
13518 equate_decl_number_to_die (decl, decl_die);
13522 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13523 Use modified_type_die instead.
13524 We keep this code here just in case these types of DIEs may be needed to
13525 represent certain things in other languages (e.g. Pascal) someday. */
13528 gen_pointer_type_die (tree type, dw_die_ref context_die)
13531 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
13533 equate_type_number_to_die (type, ptr_die);
13534 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13535 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13538 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13539 Use modified_type_die instead.
13540 We keep this code here just in case these types of DIEs may be needed to
13541 represent certain things in other languages (e.g. Pascal) someday. */
13544 gen_reference_type_die (tree type, dw_die_ref context_die)
13547 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
13549 equate_type_number_to_die (type, ref_die);
13550 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
13551 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13555 /* Generate a DIE for a pointer to a member type. */
13558 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
13561 = new_die (DW_TAG_ptr_to_member_type,
13562 scope_die_for (type, context_die), type);
13564 equate_type_number_to_die (type, ptr_die);
13565 add_AT_die_ref (ptr_die, DW_AT_containing_type,
13566 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
13567 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13570 /* Generate the DIE for the compilation unit. */
13573 gen_compile_unit_die (const char *filename)
13576 char producer[250];
13577 const char *language_string = lang_hooks.name;
13580 die = new_die (DW_TAG_compile_unit, NULL, NULL);
13584 add_name_attribute (die, filename);
13585 /* Don't add cwd for <built-in>. */
13586 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
13587 add_comp_dir_attribute (die);
13590 sprintf (producer, "%s %s", language_string, version_string);
13592 #ifdef MIPS_DEBUGGING_INFO
13593 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13594 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13595 not appear in the producer string, the debugger reaches the conclusion
13596 that the object file is stripped and has no debugging information.
13597 To get the MIPS/SGI debugger to believe that there is debugging
13598 information in the object file, we add a -g to the producer string. */
13599 if (debug_info_level > DINFO_LEVEL_TERSE)
13600 strcat (producer, " -g");
13603 add_AT_string (die, DW_AT_producer, producer);
13605 if (strcmp (language_string, "GNU C++") == 0)
13606 language = DW_LANG_C_plus_plus;
13607 else if (strcmp (language_string, "GNU Ada") == 0)
13608 language = DW_LANG_Ada95;
13609 else if (strcmp (language_string, "GNU F77") == 0)
13610 language = DW_LANG_Fortran77;
13611 else if (strcmp (language_string, "GNU Fortran") == 0)
13612 language = DW_LANG_Fortran95;
13613 else if (strcmp (language_string, "GNU Pascal") == 0)
13614 language = DW_LANG_Pascal83;
13615 else if (strcmp (language_string, "GNU Java") == 0)
13616 language = DW_LANG_Java;
13617 else if (strcmp (language_string, "GNU Objective-C") == 0)
13618 language = DW_LANG_ObjC;
13619 else if (strcmp (language_string, "GNU Objective-C++") == 0)
13620 language = DW_LANG_ObjC_plus_plus;
13622 language = DW_LANG_C89;
13624 add_AT_unsigned (die, DW_AT_language, language);
13628 /* Generate the DIE for a base class. */
13631 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
13633 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
13635 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
13636 add_data_member_location_attribute (die, binfo);
13638 if (BINFO_VIRTUAL_P (binfo))
13639 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13641 if (access == access_public_node)
13642 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13643 else if (access == access_protected_node)
13644 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13647 /* Generate a DIE for a class member. */
13650 gen_member_die (tree type, dw_die_ref context_die)
13653 tree binfo = TYPE_BINFO (type);
13656 /* If this is not an incomplete type, output descriptions of each of its
13657 members. Note that as we output the DIEs necessary to represent the
13658 members of this record or union type, we will also be trying to output
13659 DIEs to represent the *types* of those members. However the `type'
13660 function (above) will specifically avoid generating type DIEs for member
13661 types *within* the list of member DIEs for this (containing) type except
13662 for those types (of members) which are explicitly marked as also being
13663 members of this (containing) type themselves. The g++ front- end can
13664 force any given type to be treated as a member of some other (containing)
13665 type by setting the TYPE_CONTEXT of the given (member) type to point to
13666 the TREE node representing the appropriate (containing) type. */
13668 /* First output info about the base classes. */
13671 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
13675 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
13676 gen_inheritance_die (base,
13677 (accesses ? VEC_index (tree, accesses, i)
13678 : access_public_node), context_die);
13681 /* Now output info about the data members and type members. */
13682 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
13684 /* If we thought we were generating minimal debug info for TYPE
13685 and then changed our minds, some of the member declarations
13686 may have already been defined. Don't define them again, but
13687 do put them in the right order. */
13689 child = lookup_decl_die (member);
13691 splice_child_die (context_die, child);
13693 gen_decl_die (member, context_die);
13696 /* Now output info about the function members (if any). */
13697 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
13699 /* Don't include clones in the member list. */
13700 if (DECL_ABSTRACT_ORIGIN (member))
13703 child = lookup_decl_die (member);
13705 splice_child_die (context_die, child);
13707 gen_decl_die (member, context_die);
13711 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13712 is set, we pretend that the type was never defined, so we only get the
13713 member DIEs needed by later specification DIEs. */
13716 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
13717 enum debug_info_usage usage)
13719 dw_die_ref type_die = lookup_type_die (type);
13720 dw_die_ref scope_die = 0;
13722 int complete = (TYPE_SIZE (type)
13723 && (! TYPE_STUB_DECL (type)
13724 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
13725 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
13726 complete = complete && should_emit_struct_debug (type, usage);
13728 if (type_die && ! complete)
13731 if (TYPE_CONTEXT (type) != NULL_TREE
13732 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13733 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
13736 scope_die = scope_die_for (type, context_die);
13738 if (! type_die || (nested && scope_die == comp_unit_die))
13739 /* First occurrence of type or toplevel definition of nested class. */
13741 dw_die_ref old_die = type_die;
13743 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
13744 ? record_type_tag (type) : DW_TAG_union_type,
13746 equate_type_number_to_die (type, type_die);
13748 add_AT_specification (type_die, old_die);
13750 add_name_attribute (type_die, type_tag (type));
13753 remove_AT (type_die, DW_AT_declaration);
13755 /* If this type has been completed, then give it a byte_size attribute and
13756 then give a list of members. */
13757 if (complete && !ns_decl)
13759 /* Prevent infinite recursion in cases where the type of some member of
13760 this type is expressed in terms of this type itself. */
13761 TREE_ASM_WRITTEN (type) = 1;
13762 add_byte_size_attribute (type_die, type);
13763 if (TYPE_STUB_DECL (type) != NULL_TREE)
13764 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13766 /* If the first reference to this type was as the return type of an
13767 inline function, then it may not have a parent. Fix this now. */
13768 if (type_die->die_parent == NULL)
13769 add_child_die (scope_die, type_die);
13771 push_decl_scope (type);
13772 gen_member_die (type, type_die);
13775 /* GNU extension: Record what type our vtable lives in. */
13776 if (TYPE_VFIELD (type))
13778 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
13780 gen_type_die (vtype, context_die);
13781 add_AT_die_ref (type_die, DW_AT_containing_type,
13782 lookup_type_die (vtype));
13787 add_AT_flag (type_die, DW_AT_declaration, 1);
13789 /* We don't need to do this for function-local types. */
13790 if (TYPE_STUB_DECL (type)
13791 && ! decl_function_context (TYPE_STUB_DECL (type)))
13792 VEC_safe_push (tree, gc, incomplete_types, type);
13795 if (get_AT (type_die, DW_AT_name))
13796 add_pubtype (type, type_die);
13799 /* Generate a DIE for a subroutine _type_. */
13802 gen_subroutine_type_die (tree type, dw_die_ref context_die)
13804 tree return_type = TREE_TYPE (type);
13805 dw_die_ref subr_die
13806 = new_die (DW_TAG_subroutine_type,
13807 scope_die_for (type, context_die), type);
13809 equate_type_number_to_die (type, subr_die);
13810 add_prototyped_attribute (subr_die, type);
13811 add_type_attribute (subr_die, return_type, 0, 0, context_die);
13812 gen_formal_types_die (type, subr_die);
13814 if (get_AT (subr_die, DW_AT_name))
13815 add_pubtype (type, subr_die);
13818 /* Generate a DIE for a type definition. */
13821 gen_typedef_die (tree decl, dw_die_ref context_die)
13823 dw_die_ref type_die;
13826 if (TREE_ASM_WRITTEN (decl))
13829 TREE_ASM_WRITTEN (decl) = 1;
13830 type_die = new_die (DW_TAG_typedef, context_die, decl);
13831 origin = decl_ultimate_origin (decl);
13832 if (origin != NULL)
13833 add_abstract_origin_attribute (type_die, origin);
13838 add_name_and_src_coords_attributes (type_die, decl);
13839 if (DECL_ORIGINAL_TYPE (decl))
13841 type = DECL_ORIGINAL_TYPE (decl);
13843 gcc_assert (type != TREE_TYPE (decl));
13844 equate_type_number_to_die (TREE_TYPE (decl), type_die);
13847 type = TREE_TYPE (decl);
13849 add_type_attribute (type_die, type, TREE_READONLY (decl),
13850 TREE_THIS_VOLATILE (decl), context_die);
13853 if (DECL_ABSTRACT (decl))
13854 equate_decl_number_to_die (decl, type_die);
13856 if (get_AT (type_die, DW_AT_name))
13857 add_pubtype (decl, type_die);
13860 /* Generate a type description DIE. */
13863 gen_type_die_with_usage (tree type, dw_die_ref context_die,
13864 enum debug_info_usage usage)
13867 struct array_descr_info info;
13869 if (type == NULL_TREE || type == error_mark_node)
13872 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13873 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
13875 if (TREE_ASM_WRITTEN (type))
13878 /* Prevent broken recursion; we can't hand off to the same type. */
13879 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
13881 TREE_ASM_WRITTEN (type) = 1;
13882 gen_decl_die (TYPE_NAME (type), context_die);
13886 /* If this is an array type with hidden descriptor, handle it first. */
13887 if (!TREE_ASM_WRITTEN (type)
13888 && lang_hooks.types.get_array_descr_info
13889 && lang_hooks.types.get_array_descr_info (type, &info))
13891 gen_descr_array_type_die (type, &info, context_die);
13892 TREE_ASM_WRITTEN (type) = 1;
13896 /* We are going to output a DIE to represent the unqualified version
13897 of this type (i.e. without any const or volatile qualifiers) so
13898 get the main variant (i.e. the unqualified version) of this type
13899 now. (Vectors are special because the debugging info is in the
13900 cloned type itself). */
13901 if (TREE_CODE (type) != VECTOR_TYPE)
13902 type = type_main_variant (type);
13904 if (TREE_ASM_WRITTEN (type))
13907 switch (TREE_CODE (type))
13913 case REFERENCE_TYPE:
13914 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13915 ensures that the gen_type_die recursion will terminate even if the
13916 type is recursive. Recursive types are possible in Ada. */
13917 /* ??? We could perhaps do this for all types before the switch
13919 TREE_ASM_WRITTEN (type) = 1;
13921 /* For these types, all that is required is that we output a DIE (or a
13922 set of DIEs) to represent the "basis" type. */
13923 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13924 DINFO_USAGE_IND_USE);
13928 /* This code is used for C++ pointer-to-data-member types.
13929 Output a description of the relevant class type. */
13930 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
13931 DINFO_USAGE_IND_USE);
13933 /* Output a description of the type of the object pointed to. */
13934 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13935 DINFO_USAGE_IND_USE);
13937 /* Now output a DIE to represent this pointer-to-data-member type
13939 gen_ptr_to_mbr_type_die (type, context_die);
13942 case FUNCTION_TYPE:
13943 /* Force out return type (in case it wasn't forced out already). */
13944 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13945 DINFO_USAGE_DIR_USE);
13946 gen_subroutine_type_die (type, context_die);
13950 /* Force out return type (in case it wasn't forced out already). */
13951 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13952 DINFO_USAGE_DIR_USE);
13953 gen_subroutine_type_die (type, context_die);
13957 gen_array_type_die (type, context_die);
13961 gen_array_type_die (type, context_die);
13964 case ENUMERAL_TYPE:
13967 case QUAL_UNION_TYPE:
13968 /* If this is a nested type whose containing class hasn't been written
13969 out yet, writing it out will cover this one, too. This does not apply
13970 to instantiations of member class templates; they need to be added to
13971 the containing class as they are generated. FIXME: This hurts the
13972 idea of combining type decls from multiple TUs, since we can't predict
13973 what set of template instantiations we'll get. */
13974 if (TYPE_CONTEXT (type)
13975 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13976 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
13978 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
13980 if (TREE_ASM_WRITTEN (type))
13983 /* If that failed, attach ourselves to the stub. */
13984 push_decl_scope (TYPE_CONTEXT (type));
13985 context_die = lookup_type_die (TYPE_CONTEXT (type));
13990 declare_in_namespace (type, context_die);
13994 if (TREE_CODE (type) == ENUMERAL_TYPE)
13996 /* This might have been written out by the call to
13997 declare_in_namespace. */
13998 if (!TREE_ASM_WRITTEN (type))
13999 gen_enumeration_type_die (type, context_die);
14002 gen_struct_or_union_type_die (type, context_die, usage);
14007 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
14008 it up if it is ever completed. gen_*_type_die will set it for us
14009 when appropriate. */
14015 case FIXED_POINT_TYPE:
14018 /* No DIEs needed for fundamental types. */
14022 /* No Dwarf representation currently defined. */
14026 gcc_unreachable ();
14029 TREE_ASM_WRITTEN (type) = 1;
14033 gen_type_die (tree type, dw_die_ref context_die)
14035 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
14038 /* Generate a DIE for a tagged type instantiation. */
14041 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
14043 if (type == NULL_TREE || type == error_mark_node)
14046 /* We are going to output a DIE to represent the unqualified version of
14047 this type (i.e. without any const or volatile qualifiers) so make sure
14048 that we have the main variant (i.e. the unqualified version) of this
14050 gcc_assert (type == type_main_variant (type));
14052 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
14053 an instance of an unresolved type. */
14055 switch (TREE_CODE (type))
14060 case ENUMERAL_TYPE:
14061 gen_inlined_enumeration_type_die (type, context_die);
14065 gen_inlined_structure_type_die (type, context_die);
14069 case QUAL_UNION_TYPE:
14070 gen_inlined_union_type_die (type, context_die);
14074 gcc_unreachable ();
14078 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14079 things which are local to the given block. */
14082 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
14084 int must_output_die = 0;
14087 enum tree_code origin_code;
14089 /* Ignore blocks that are NULL. */
14090 if (stmt == NULL_TREE)
14093 /* If the block is one fragment of a non-contiguous block, do not
14094 process the variables, since they will have been done by the
14095 origin block. Do process subblocks. */
14096 if (BLOCK_FRAGMENT_ORIGIN (stmt))
14100 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
14101 gen_block_die (sub, context_die, depth + 1);
14106 /* Determine the "ultimate origin" of this block. This block may be an
14107 inlined instance of an inlined instance of inline function, so we have
14108 to trace all of the way back through the origin chain to find out what
14109 sort of node actually served as the original seed for the creation of
14110 the current block. */
14111 origin = block_ultimate_origin (stmt);
14112 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
14114 /* Determine if we need to output any Dwarf DIEs at all to represent this
14116 if (origin_code == FUNCTION_DECL)
14117 /* The outer scopes for inlinings *must* always be represented. We
14118 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14119 must_output_die = 1;
14122 /* In the case where the current block represents an inlining of the
14123 "body block" of an inline function, we must *NOT* output any DIE for
14124 this block because we have already output a DIE to represent the whole
14125 inlined function scope and the "body block" of any function doesn't
14126 really represent a different scope according to ANSI C rules. So we
14127 check here to make sure that this block does not represent a "body
14128 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
14129 if (! is_body_block (origin ? origin : stmt))
14131 /* Determine if this block directly contains any "significant"
14132 local declarations which we will need to output DIEs for. */
14133 if (debug_info_level > DINFO_LEVEL_TERSE)
14134 /* We are not in terse mode so *any* local declaration counts
14135 as being a "significant" one. */
14136 must_output_die = (BLOCK_VARS (stmt) != NULL
14137 && (TREE_USED (stmt)
14138 || TREE_ASM_WRITTEN (stmt)
14139 || BLOCK_ABSTRACT (stmt)));
14141 /* We are in terse mode, so only local (nested) function
14142 definitions count as "significant" local declarations. */
14143 for (decl = BLOCK_VARS (stmt);
14144 decl != NULL; decl = TREE_CHAIN (decl))
14145 if (TREE_CODE (decl) == FUNCTION_DECL
14146 && DECL_INITIAL (decl))
14148 must_output_die = 1;
14154 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14155 DIE for any block which contains no significant local declarations at
14156 all. Rather, in such cases we just call `decls_for_scope' so that any
14157 needed Dwarf info for any sub-blocks will get properly generated. Note
14158 that in terse mode, our definition of what constitutes a "significant"
14159 local declaration gets restricted to include only inlined function
14160 instances and local (nested) function definitions. */
14161 if (must_output_die)
14163 if (origin_code == FUNCTION_DECL)
14164 gen_inlined_subroutine_die (stmt, context_die, depth);
14166 gen_lexical_block_die (stmt, context_die, depth);
14169 decls_for_scope (stmt, context_die, depth);
14172 /* Generate all of the decls declared within a given scope and (recursively)
14173 all of its sub-blocks. */
14176 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
14181 /* Ignore NULL blocks. */
14182 if (stmt == NULL_TREE)
14185 if (TREE_USED (stmt))
14187 /* Output the DIEs to represent all of the data objects and typedefs
14188 declared directly within this block but not within any nested
14189 sub-blocks. Also, nested function and tag DIEs have been
14190 generated with a parent of NULL; fix that up now. */
14191 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
14195 if (TREE_CODE (decl) == FUNCTION_DECL)
14196 die = lookup_decl_die (decl);
14197 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
14198 die = lookup_type_die (TREE_TYPE (decl));
14202 if (die != NULL && die->die_parent == NULL)
14203 add_child_die (context_die, die);
14204 /* Do not produce debug information for static variables since
14205 these might be optimized out. We are called for these later
14206 in varpool_analyze_pending_decls.
14208 But *do* produce it for Fortran COMMON variables because,
14209 even though they are static, their names can differ depending
14210 on the scope, which we need to preserve. */
14211 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
14212 && !(is_fortran () && TREE_PUBLIC (decl)))
14215 gen_decl_die (decl, context_die);
14219 /* If we're at -g1, we're not interested in subblocks. */
14220 if (debug_info_level <= DINFO_LEVEL_TERSE)
14223 /* Output the DIEs to represent all sub-blocks (and the items declared
14224 therein) of this block. */
14225 for (subblocks = BLOCK_SUBBLOCKS (stmt);
14227 subblocks = BLOCK_CHAIN (subblocks))
14228 gen_block_die (subblocks, context_die, depth + 1);
14231 /* Is this a typedef we can avoid emitting? */
14234 is_redundant_typedef (const_tree decl)
14236 if (TYPE_DECL_IS_STUB (decl))
14239 if (DECL_ARTIFICIAL (decl)
14240 && DECL_CONTEXT (decl)
14241 && is_tagged_type (DECL_CONTEXT (decl))
14242 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
14243 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
14244 /* Also ignore the artificial member typedef for the class name. */
14250 /* Returns the DIE for a context. */
14252 static inline dw_die_ref
14253 get_context_die (tree context)
14257 /* Find die that represents this context. */
14258 if (TYPE_P (context))
14259 return force_type_die (context);
14261 return force_decl_die (context);
14263 return comp_unit_die;
14266 /* Returns the DIE for decl. A DIE will always be returned. */
14269 force_decl_die (tree decl)
14271 dw_die_ref decl_die;
14272 unsigned saved_external_flag;
14273 tree save_fn = NULL_TREE;
14274 decl_die = lookup_decl_die (decl);
14277 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
14279 decl_die = lookup_decl_die (decl);
14283 switch (TREE_CODE (decl))
14285 case FUNCTION_DECL:
14286 /* Clear current_function_decl, so that gen_subprogram_die thinks
14287 that this is a declaration. At this point, we just want to force
14288 declaration die. */
14289 save_fn = current_function_decl;
14290 current_function_decl = NULL_TREE;
14291 gen_subprogram_die (decl, context_die);
14292 current_function_decl = save_fn;
14296 /* Set external flag to force declaration die. Restore it after
14297 gen_decl_die() call. */
14298 saved_external_flag = DECL_EXTERNAL (decl);
14299 DECL_EXTERNAL (decl) = 1;
14300 gen_decl_die (decl, context_die);
14301 DECL_EXTERNAL (decl) = saved_external_flag;
14304 case NAMESPACE_DECL:
14305 dwarf2out_decl (decl);
14309 gcc_unreachable ();
14312 /* We should be able to find the DIE now. */
14314 decl_die = lookup_decl_die (decl);
14315 gcc_assert (decl_die);
14321 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
14322 always returned. */
14325 force_type_die (tree type)
14327 dw_die_ref type_die;
14329 type_die = lookup_type_die (type);
14332 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
14334 type_die = modified_type_die (type, TYPE_READONLY (type),
14335 TYPE_VOLATILE (type), context_die);
14336 gcc_assert (type_die);
14341 /* Force out any required namespaces to be able to output DECL,
14342 and return the new context_die for it, if it's changed. */
14345 setup_namespace_context (tree thing, dw_die_ref context_die)
14347 tree context = (DECL_P (thing)
14348 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
14349 if (context && TREE_CODE (context) == NAMESPACE_DECL)
14350 /* Force out the namespace. */
14351 context_die = force_decl_die (context);
14353 return context_die;
14356 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
14357 type) within its namespace, if appropriate.
14359 For compatibility with older debuggers, namespace DIEs only contain
14360 declarations; all definitions are emitted at CU scope. */
14363 declare_in_namespace (tree thing, dw_die_ref context_die)
14365 dw_die_ref ns_context;
14367 if (debug_info_level <= DINFO_LEVEL_TERSE)
14370 /* If this decl is from an inlined function, then don't try to emit it in its
14371 namespace, as we will get confused. It would have already been emitted
14372 when the abstract instance of the inline function was emitted anyways. */
14373 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
14376 ns_context = setup_namespace_context (thing, context_die);
14378 if (ns_context != context_die)
14380 if (DECL_P (thing))
14381 gen_decl_die (thing, ns_context);
14383 gen_type_die (thing, ns_context);
14387 /* Generate a DIE for a namespace or namespace alias. */
14390 gen_namespace_die (tree decl)
14392 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
14394 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
14395 they are an alias of. */
14396 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
14398 /* Output a real namespace. */
14399 dw_die_ref namespace_die
14400 = new_die (DW_TAG_namespace, context_die, decl);
14401 add_name_and_src_coords_attributes (namespace_die, decl);
14402 equate_decl_number_to_die (decl, namespace_die);
14406 /* Output a namespace alias. */
14408 /* Force out the namespace we are an alias of, if necessary. */
14409 dw_die_ref origin_die
14410 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
14412 /* Now create the namespace alias DIE. */
14413 dw_die_ref namespace_die
14414 = new_die (DW_TAG_imported_declaration, context_die, decl);
14415 add_name_and_src_coords_attributes (namespace_die, decl);
14416 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
14417 equate_decl_number_to_die (decl, namespace_die);
14421 /* Generate Dwarf debug information for a decl described by DECL. */
14424 gen_decl_die (tree decl, dw_die_ref context_die)
14428 if (DECL_P (decl) && DECL_IGNORED_P (decl))
14431 switch (TREE_CODE (decl))
14437 /* The individual enumerators of an enum type get output when we output
14438 the Dwarf representation of the relevant enum type itself. */
14441 case FUNCTION_DECL:
14442 /* Don't output any DIEs to represent mere function declarations,
14443 unless they are class members or explicit block externs. */
14444 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
14445 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
14450 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
14451 on local redeclarations of global functions. That seems broken. */
14452 if (current_function_decl != decl)
14453 /* This is only a declaration. */;
14456 /* If we're emitting a clone, emit info for the abstract instance. */
14457 if (DECL_ORIGIN (decl) != decl)
14458 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
14460 /* If we're emitting an out-of-line copy of an inline function,
14461 emit info for the abstract instance and set up to refer to it. */
14462 else if (cgraph_function_possibly_inlined_p (decl)
14463 && ! DECL_ABSTRACT (decl)
14464 && ! class_or_namespace_scope_p (context_die)
14465 /* dwarf2out_abstract_function won't emit a die if this is just
14466 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14467 that case, because that works only if we have a die. */
14468 && DECL_INITIAL (decl) != NULL_TREE)
14470 dwarf2out_abstract_function (decl);
14471 set_decl_origin_self (decl);
14474 /* Otherwise we're emitting the primary DIE for this decl. */
14475 else if (debug_info_level > DINFO_LEVEL_TERSE)
14477 /* Before we describe the FUNCTION_DECL itself, make sure that we
14478 have described its return type. */
14479 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14481 /* And its virtual context. */
14482 if (DECL_VINDEX (decl) != NULL_TREE)
14483 gen_type_die (DECL_CONTEXT (decl), context_die);
14485 /* And its containing type. */
14486 origin = decl_class_context (decl);
14487 if (origin != NULL_TREE)
14488 gen_type_die_for_member (origin, decl, context_die);
14490 /* And its containing namespace. */
14491 declare_in_namespace (decl, context_die);
14494 /* Now output a DIE to represent the function itself. */
14495 gen_subprogram_die (decl, context_die);
14499 /* If we are in terse mode, don't generate any DIEs to represent any
14500 actual typedefs. */
14501 if (debug_info_level <= DINFO_LEVEL_TERSE)
14504 /* In the special case of a TYPE_DECL node representing the declaration
14505 of some type tag, if the given TYPE_DECL is marked as having been
14506 instantiated from some other (original) TYPE_DECL node (e.g. one which
14507 was generated within the original definition of an inline function) we
14508 have to generate a special (abbreviated) DW_TAG_structure_type,
14509 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14510 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
14511 && is_tagged_type (TREE_TYPE (decl)))
14513 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
14517 if (is_redundant_typedef (decl))
14518 gen_type_die (TREE_TYPE (decl), context_die);
14520 /* Output a DIE to represent the typedef itself. */
14521 gen_typedef_die (decl, context_die);
14525 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14526 gen_label_die (decl, context_die);
14531 /* If we are in terse mode, don't generate any DIEs to represent any
14532 variable declarations or definitions. */
14533 if (debug_info_level <= DINFO_LEVEL_TERSE)
14536 /* If this is the global definition of the Fortran COMMON block, we don't
14537 need to do anything. Syntactically, the block itself has no identity,
14538 just its constituent identifiers. */
14539 if (TREE_CODE (decl) == VAR_DECL
14540 && TREE_PUBLIC (decl)
14541 && TREE_STATIC (decl)
14543 && !DECL_HAS_VALUE_EXPR_P (decl))
14546 /* Output any DIEs that are needed to specify the type of this data
14548 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
14549 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14551 gen_type_die (TREE_TYPE (decl), context_die);
14553 /* And its containing type. */
14554 origin = decl_class_context (decl);
14555 if (origin != NULL_TREE)
14556 gen_type_die_for_member (origin, decl, context_die);
14558 /* And its containing namespace. */
14559 declare_in_namespace (decl, context_die);
14561 /* Now output the DIE to represent the data object itself. This gets
14562 complicated because of the possibility that the VAR_DECL really
14563 represents an inlined instance of a formal parameter for an inline
14565 origin = decl_ultimate_origin (decl);
14566 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
14567 gen_formal_parameter_die (decl, context_die);
14569 gen_variable_die (decl, context_die);
14573 /* Ignore the nameless fields that are used to skip bits but handle C++
14574 anonymous unions and structs. */
14575 if (DECL_NAME (decl) != NULL_TREE
14576 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
14577 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
14579 gen_type_die (member_declared_type (decl), context_die);
14580 gen_field_die (decl, context_die);
14585 if (DECL_BY_REFERENCE (decl))
14586 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14588 gen_type_die (TREE_TYPE (decl), context_die);
14589 gen_formal_parameter_die (decl, context_die);
14592 case NAMESPACE_DECL:
14593 gen_namespace_die (decl);
14597 /* Probably some frontend-internal decl. Assume we don't care. */
14598 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
14603 /* Output debug information for global decl DECL. Called from toplev.c after
14604 compilation proper has finished. */
14607 dwarf2out_global_decl (tree decl)
14609 /* Output DWARF2 information for file-scope tentative data object
14610 declarations, file-scope (extern) function declarations (which
14611 had no corresponding body) and file-scope tagged type declarations
14612 and definitions which have not yet been forced out.
14614 Ignore the global decl of any Fortran COMMON blocks which also
14615 wind up here though they have already been described in the local
14616 scope for the procedures using them. */
14617 if (TREE_CODE (decl) == VAR_DECL
14618 && TREE_PUBLIC (decl) && TREE_STATIC (decl) && is_fortran ())
14621 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
14622 dwarf2out_decl (decl);
14625 /* Output debug information for type decl DECL. Called from toplev.c
14626 and from language front ends (to record built-in types). */
14628 dwarf2out_type_decl (tree decl, int local)
14631 dwarf2out_decl (decl);
14634 /* Output debug information for imported module or decl. */
14637 dwarf2out_imported_module_or_decl (tree decl, tree context)
14639 dw_die_ref imported_die, at_import_die;
14640 dw_die_ref scope_die;
14641 expanded_location xloc;
14643 if (debug_info_level <= DINFO_LEVEL_TERSE)
14648 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14649 We need decl DIE for reference and scope die. First, get DIE for the decl
14652 /* Get the scope die for decl context. Use comp_unit_die for global module
14653 or decl. If die is not found for non globals, force new die. */
14655 && TYPE_P (context)
14656 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14658 scope_die = get_context_die (context);
14660 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14661 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14663 if (is_base_type (TREE_TYPE (decl)))
14664 at_import_die = base_type_die (TREE_TYPE (decl));
14666 at_import_die = force_type_die (TREE_TYPE (decl));
14667 /* For namespace N { typedef void T; } using N::T; base_type_die
14668 returns NULL, but DW_TAG_imported_declaration requires
14669 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
14670 if (!at_import_die)
14672 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
14673 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
14674 at_import_die = lookup_type_die (TREE_TYPE (decl));
14675 gcc_assert (at_import_die);
14680 at_import_die = lookup_decl_die (decl);
14681 if (!at_import_die)
14683 /* If we're trying to avoid duplicate debug info, we may not have
14684 emitted the member decl for this field. Emit it now. */
14685 if (TREE_CODE (decl) == FIELD_DECL)
14687 tree type = DECL_CONTEXT (decl);
14689 if (TYPE_CONTEXT (type)
14690 && TYPE_P (TYPE_CONTEXT (type))
14691 && !should_emit_struct_debug (TYPE_CONTEXT (type),
14692 DINFO_USAGE_DIR_USE))
14694 gen_type_die_for_member (type, decl,
14695 get_context_die (TYPE_CONTEXT (type)));
14697 at_import_die = force_decl_die (decl);
14701 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14702 if (TREE_CODE (decl) == NAMESPACE_DECL)
14703 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
14705 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
14707 xloc = expand_location (input_location);
14708 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
14709 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
14710 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
14713 /* Write the debugging output for DECL. */
14716 dwarf2out_decl (tree decl)
14718 dw_die_ref context_die = comp_unit_die;
14720 switch (TREE_CODE (decl))
14725 case FUNCTION_DECL:
14726 /* What we would really like to do here is to filter out all mere
14727 file-scope declarations of file-scope functions which are never
14728 referenced later within this translation unit (and keep all of ones
14729 that *are* referenced later on) but we aren't clairvoyant, so we have
14730 no idea which functions will be referenced in the future (i.e. later
14731 on within the current translation unit). So here we just ignore all
14732 file-scope function declarations which are not also definitions. If
14733 and when the debugger needs to know something about these functions,
14734 it will have to hunt around and find the DWARF information associated
14735 with the definition of the function.
14737 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14738 nodes represent definitions and which ones represent mere
14739 declarations. We have to check DECL_INITIAL instead. That's because
14740 the C front-end supports some weird semantics for "extern inline"
14741 function definitions. These can get inlined within the current
14742 translation unit (and thus, we need to generate Dwarf info for their
14743 abstract instances so that the Dwarf info for the concrete inlined
14744 instances can have something to refer to) but the compiler never
14745 generates any out-of-lines instances of such things (despite the fact
14746 that they *are* definitions).
14748 The important point is that the C front-end marks these "extern
14749 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14750 them anyway. Note that the C++ front-end also plays some similar games
14751 for inline function definitions appearing within include files which
14752 also contain `#pragma interface' pragmas. */
14753 if (DECL_INITIAL (decl) == NULL_TREE)
14756 /* If we're a nested function, initially use a parent of NULL; if we're
14757 a plain function, this will be fixed up in decls_for_scope. If
14758 we're a method, it will be ignored, since we already have a DIE. */
14759 if (decl_function_context (decl)
14760 /* But if we're in terse mode, we don't care about scope. */
14761 && debug_info_level > DINFO_LEVEL_TERSE)
14762 context_die = NULL;
14766 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14767 declaration and if the declaration was never even referenced from
14768 within this entire compilation unit. We suppress these DIEs in
14769 order to save space in the .debug section (by eliminating entries
14770 which are probably useless). Note that we must not suppress
14771 block-local extern declarations (whether used or not) because that
14772 would screw-up the debugger's name lookup mechanism and cause it to
14773 miss things which really ought to be in scope at a given point. */
14774 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
14777 /* For local statics lookup proper context die. */
14778 if (TREE_STATIC (decl) && decl_function_context (decl))
14779 context_die = lookup_decl_die (DECL_CONTEXT (decl));
14781 /* If we are in terse mode, don't generate any DIEs to represent any
14782 variable declarations or definitions. */
14783 if (debug_info_level <= DINFO_LEVEL_TERSE)
14787 case NAMESPACE_DECL:
14788 if (debug_info_level <= DINFO_LEVEL_TERSE)
14790 if (lookup_decl_die (decl) != NULL)
14795 /* Don't emit stubs for types unless they are needed by other DIEs. */
14796 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
14799 /* Don't bother trying to generate any DIEs to represent any of the
14800 normal built-in types for the language we are compiling. */
14801 if (DECL_IS_BUILTIN (decl))
14803 /* OK, we need to generate one for `bool' so GDB knows what type
14804 comparisons have. */
14806 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
14807 && ! DECL_IGNORED_P (decl))
14808 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
14813 /* If we are in terse mode, don't generate any DIEs for types. */
14814 if (debug_info_level <= DINFO_LEVEL_TERSE)
14817 /* If we're a function-scope tag, initially use a parent of NULL;
14818 this will be fixed up in decls_for_scope. */
14819 if (decl_function_context (decl))
14820 context_die = NULL;
14828 gen_decl_die (decl, context_die);
14831 /* Output a marker (i.e. a label) for the beginning of the generated code for
14832 a lexical block. */
14835 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
14836 unsigned int blocknum)
14838 switch_to_section (current_function_section ());
14839 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
14842 /* Output a marker (i.e. a label) for the end of the generated code for a
14846 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
14848 switch_to_section (current_function_section ());
14849 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
14852 /* Returns nonzero if it is appropriate not to emit any debugging
14853 information for BLOCK, because it doesn't contain any instructions.
14855 Don't allow this for blocks with nested functions or local classes
14856 as we would end up with orphans, and in the presence of scheduling
14857 we may end up calling them anyway. */
14860 dwarf2out_ignore_block (const_tree block)
14864 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
14865 if (TREE_CODE (decl) == FUNCTION_DECL
14866 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
14872 /* Hash table routines for file_hash. */
14875 file_table_eq (const void *p1_p, const void *p2_p)
14877 const struct dwarf_file_data *const p1 =
14878 (const struct dwarf_file_data *) p1_p;
14879 const char *const p2 = (const char *) p2_p;
14880 return strcmp (p1->filename, p2) == 0;
14884 file_table_hash (const void *p_p)
14886 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
14887 return htab_hash_string (p->filename);
14890 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14891 dwarf2out.c) and return its "index". The index of each (known) filename is
14892 just a unique number which is associated with only that one filename. We
14893 need such numbers for the sake of generating labels (in the .debug_sfnames
14894 section) and references to those files numbers (in the .debug_srcinfo
14895 and.debug_macinfo sections). If the filename given as an argument is not
14896 found in our current list, add it to the list and assign it the next
14897 available unique index number. In order to speed up searches, we remember
14898 the index of the filename was looked up last. This handles the majority of
14901 static struct dwarf_file_data *
14902 lookup_filename (const char *file_name)
14905 struct dwarf_file_data * created;
14907 /* Check to see if the file name that was searched on the previous
14908 call matches this file name. If so, return the index. */
14909 if (file_table_last_lookup
14910 && (file_name == file_table_last_lookup->filename
14911 || strcmp (file_table_last_lookup->filename, file_name) == 0))
14912 return file_table_last_lookup;
14914 /* Didn't match the previous lookup, search the table. */
14915 slot = htab_find_slot_with_hash (file_table, file_name,
14916 htab_hash_string (file_name), INSERT);
14918 return (struct dwarf_file_data *) *slot;
14920 created = GGC_NEW (struct dwarf_file_data);
14921 created->filename = file_name;
14922 created->emitted_number = 0;
14927 /* If the assembler will construct the file table, then translate the compiler
14928 internal file table number into the assembler file table number, and emit
14929 a .file directive if we haven't already emitted one yet. The file table
14930 numbers are different because we prune debug info for unused variables and
14931 types, which may include filenames. */
14934 maybe_emit_file (struct dwarf_file_data * fd)
14936 if (! fd->emitted_number)
14938 if (last_emitted_file)
14939 fd->emitted_number = last_emitted_file->emitted_number + 1;
14941 fd->emitted_number = 1;
14942 last_emitted_file = fd;
14944 if (DWARF2_ASM_LINE_DEBUG_INFO)
14946 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
14947 output_quoted_string (asm_out_file,
14948 remap_debug_filename (fd->filename));
14949 fputc ('\n', asm_out_file);
14953 return fd->emitted_number;
14956 /* Called by the final INSN scan whenever we see a var location. We
14957 use it to drop labels in the right places, and throw the location in
14958 our lookup table. */
14961 dwarf2out_var_location (rtx loc_note)
14963 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
14964 struct var_loc_node *newloc;
14966 static rtx last_insn;
14967 static const char *last_label;
14970 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
14972 prev_insn = PREV_INSN (loc_note);
14974 newloc = GGC_CNEW (struct var_loc_node);
14975 /* If the insn we processed last time is the previous insn
14976 and it is also a var location note, use the label we emitted
14978 if (last_insn != NULL_RTX
14979 && last_insn == prev_insn
14980 && NOTE_P (prev_insn)
14981 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
14983 newloc->label = last_label;
14987 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
14988 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
14990 newloc->label = ggc_strdup (loclabel);
14992 newloc->var_loc_note = loc_note;
14993 newloc->next = NULL;
14995 if (cfun && in_cold_section_p)
14996 newloc->section_label = crtl->subsections.cold_section_label;
14998 newloc->section_label = text_section_label;
15000 last_insn = loc_note;
15001 last_label = newloc->label;
15002 decl = NOTE_VAR_LOCATION_DECL (loc_note);
15003 add_var_loc_to_decl (decl, newloc);
15006 /* We need to reset the locations at the beginning of each
15007 function. We can't do this in the end_function hook, because the
15008 declarations that use the locations won't have been output when
15009 that hook is called. Also compute have_multiple_function_sections here. */
15012 dwarf2out_begin_function (tree fun)
15014 htab_empty (decl_loc_table);
15016 if (function_section (fun) != text_section)
15017 have_multiple_function_sections = true;
15019 dwarf2out_note_section_used ();
15022 /* Output a label to mark the beginning of a source code line entry
15023 and record information relating to this source line, in
15024 'line_info_table' for later output of the .debug_line section. */
15027 dwarf2out_source_line (unsigned int line, const char *filename)
15029 if (debug_info_level >= DINFO_LEVEL_NORMAL
15032 int file_num = maybe_emit_file (lookup_filename (filename));
15034 switch_to_section (current_function_section ());
15036 /* If requested, emit something human-readable. */
15037 if (flag_debug_asm)
15038 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
15041 if (DWARF2_ASM_LINE_DEBUG_INFO)
15043 /* Emit the .loc directive understood by GNU as. */
15044 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
15046 /* Indicate that line number info exists. */
15047 line_info_table_in_use++;
15049 else if (function_section (current_function_decl) != text_section)
15051 dw_separate_line_info_ref line_info;
15052 targetm.asm_out.internal_label (asm_out_file,
15053 SEPARATE_LINE_CODE_LABEL,
15054 separate_line_info_table_in_use);
15056 /* Expand the line info table if necessary. */
15057 if (separate_line_info_table_in_use
15058 == separate_line_info_table_allocated)
15060 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15061 separate_line_info_table
15062 = GGC_RESIZEVEC (dw_separate_line_info_entry,
15063 separate_line_info_table,
15064 separate_line_info_table_allocated);
15065 memset (separate_line_info_table
15066 + separate_line_info_table_in_use,
15068 (LINE_INFO_TABLE_INCREMENT
15069 * sizeof (dw_separate_line_info_entry)));
15072 /* Add the new entry at the end of the line_info_table. */
15074 = &separate_line_info_table[separate_line_info_table_in_use++];
15075 line_info->dw_file_num = file_num;
15076 line_info->dw_line_num = line;
15077 line_info->function = current_function_funcdef_no;
15081 dw_line_info_ref line_info;
15083 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
15084 line_info_table_in_use);
15086 /* Expand the line info table if necessary. */
15087 if (line_info_table_in_use == line_info_table_allocated)
15089 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
15091 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
15092 line_info_table_allocated);
15093 memset (line_info_table + line_info_table_in_use, 0,
15094 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
15097 /* Add the new entry at the end of the line_info_table. */
15098 line_info = &line_info_table[line_info_table_in_use++];
15099 line_info->dw_file_num = file_num;
15100 line_info->dw_line_num = line;
15105 /* Record the beginning of a new source file. */
15108 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
15110 if (flag_eliminate_dwarf2_dups)
15112 /* Record the beginning of the file for break_out_includes. */
15113 dw_die_ref bincl_die;
15115 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
15116 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
15119 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15121 int file_num = maybe_emit_file (lookup_filename (filename));
15123 switch_to_section (debug_macinfo_section);
15124 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
15125 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
15128 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
15132 /* Record the end of a source file. */
15135 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
15137 if (flag_eliminate_dwarf2_dups)
15138 /* Record the end of the file for break_out_includes. */
15139 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
15141 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15143 switch_to_section (debug_macinfo_section);
15144 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
15148 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15149 the tail part of the directive line, i.e. the part which is past the
15150 initial whitespace, #, whitespace, directive-name, whitespace part. */
15153 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
15154 const char *buffer ATTRIBUTE_UNUSED)
15156 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15158 switch_to_section (debug_macinfo_section);
15159 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
15160 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15161 dw2_asm_output_nstring (buffer, -1, "The macro");
15165 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15166 the tail part of the directive line, i.e. the part which is past the
15167 initial whitespace, #, whitespace, directive-name, whitespace part. */
15170 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
15171 const char *buffer ATTRIBUTE_UNUSED)
15173 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15175 switch_to_section (debug_macinfo_section);
15176 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
15177 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
15178 dw2_asm_output_nstring (buffer, -1, "The macro");
15182 /* Set up for Dwarf output at the start of compilation. */
15185 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
15187 /* Allocate the file_table. */
15188 file_table = htab_create_ggc (50, file_table_hash,
15189 file_table_eq, NULL);
15191 /* Allocate the decl_die_table. */
15192 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
15193 decl_die_table_eq, NULL);
15195 /* Allocate the decl_loc_table. */
15196 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
15197 decl_loc_table_eq, NULL);
15199 /* Allocate the initial hunk of the decl_scope_table. */
15200 decl_scope_table = VEC_alloc (tree, gc, 256);
15202 /* Allocate the initial hunk of the abbrev_die_table. */
15203 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
15204 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
15205 /* Zero-th entry is allocated, but unused. */
15206 abbrev_die_table_in_use = 1;
15208 /* Allocate the initial hunk of the line_info_table. */
15209 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
15210 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
15212 /* Zero-th entry is allocated, but unused. */
15213 line_info_table_in_use = 1;
15215 /* Allocate the pubtypes and pubnames vectors. */
15216 pubname_table = VEC_alloc (pubname_entry, gc, 32);
15217 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
15219 /* Generate the initial DIE for the .debug section. Note that the (string)
15220 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
15221 will (typically) be a relative pathname and that this pathname should be
15222 taken as being relative to the directory from which the compiler was
15223 invoked when the given (base) source file was compiled. We will fill
15224 in this value in dwarf2out_finish. */
15225 comp_unit_die = gen_compile_unit_die (NULL);
15227 incomplete_types = VEC_alloc (tree, gc, 64);
15229 used_rtx_array = VEC_alloc (rtx, gc, 32);
15231 debug_info_section = get_section (DEBUG_INFO_SECTION,
15232 SECTION_DEBUG, NULL);
15233 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
15234 SECTION_DEBUG, NULL);
15235 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
15236 SECTION_DEBUG, NULL);
15237 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
15238 SECTION_DEBUG, NULL);
15239 debug_line_section = get_section (DEBUG_LINE_SECTION,
15240 SECTION_DEBUG, NULL);
15241 debug_loc_section = get_section (DEBUG_LOC_SECTION,
15242 SECTION_DEBUG, NULL);
15243 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
15244 SECTION_DEBUG, NULL);
15245 #ifdef DEBUG_PUBTYPES_SECTION
15246 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
15247 SECTION_DEBUG, NULL);
15249 debug_str_section = get_section (DEBUG_STR_SECTION,
15250 DEBUG_STR_SECTION_FLAGS, NULL);
15251 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
15252 SECTION_DEBUG, NULL);
15253 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
15254 SECTION_DEBUG, NULL);
15256 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
15257 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
15258 DEBUG_ABBREV_SECTION_LABEL, 0);
15259 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
15260 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
15261 COLD_TEXT_SECTION_LABEL, 0);
15262 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
15264 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
15265 DEBUG_INFO_SECTION_LABEL, 0);
15266 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
15267 DEBUG_LINE_SECTION_LABEL, 0);
15268 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
15269 DEBUG_RANGES_SECTION_LABEL, 0);
15270 switch_to_section (debug_abbrev_section);
15271 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
15272 switch_to_section (debug_info_section);
15273 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
15274 switch_to_section (debug_line_section);
15275 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
15277 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15279 switch_to_section (debug_macinfo_section);
15280 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
15281 DEBUG_MACINFO_SECTION_LABEL, 0);
15282 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
15285 switch_to_section (text_section);
15286 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
15287 if (flag_reorder_blocks_and_partition)
15289 cold_text_section = unlikely_text_section ();
15290 switch_to_section (cold_text_section);
15291 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
15295 /* A helper function for dwarf2out_finish called through
15296 ht_forall. Emit one queued .debug_str string. */
15299 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
15301 struct indirect_string_node *node = (struct indirect_string_node *) *h;
15303 if (node->form == DW_FORM_strp)
15305 switch_to_section (debug_str_section);
15306 ASM_OUTPUT_LABEL (asm_out_file, node->label);
15307 assemble_string (node->str, strlen (node->str) + 1);
15313 #if ENABLE_ASSERT_CHECKING
15314 /* Verify that all marks are clear. */
15317 verify_marks_clear (dw_die_ref die)
15321 gcc_assert (! die->die_mark);
15322 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
15324 #endif /* ENABLE_ASSERT_CHECKING */
15326 /* Clear the marks for a die and its children.
15327 Be cool if the mark isn't set. */
15330 prune_unmark_dies (dw_die_ref die)
15336 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
15339 /* Given DIE that we're marking as used, find any other dies
15340 it references as attributes and mark them as used. */
15343 prune_unused_types_walk_attribs (dw_die_ref die)
15348 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15350 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
15352 /* A reference to another DIE.
15353 Make sure that it will get emitted. */
15354 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
15356 /* Set the string's refcount to 0 so that prune_unused_types_mark
15357 accounts properly for it. */
15358 if (AT_class (a) == dw_val_class_str)
15359 a->dw_attr_val.v.val_str->refcount = 0;
15364 /* Mark DIE as being used. If DOKIDS is true, then walk down
15365 to DIE's children. */
15368 prune_unused_types_mark (dw_die_ref die, int dokids)
15372 if (die->die_mark == 0)
15374 /* We haven't done this node yet. Mark it as used. */
15377 /* We also have to mark its parents as used.
15378 (But we don't want to mark our parents' kids due to this.) */
15379 if (die->die_parent)
15380 prune_unused_types_mark (die->die_parent, 0);
15382 /* Mark any referenced nodes. */
15383 prune_unused_types_walk_attribs (die);
15385 /* If this node is a specification,
15386 also mark the definition, if it exists. */
15387 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
15388 prune_unused_types_mark (die->die_definition, 1);
15391 if (dokids && die->die_mark != 2)
15393 /* We need to walk the children, but haven't done so yet.
15394 Remember that we've walked the kids. */
15397 /* If this is an array type, we need to make sure our
15398 kids get marked, even if they're types. */
15399 if (die->die_tag == DW_TAG_array_type)
15400 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
15402 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15407 /* Walk the tree DIE and mark types that we actually use. */
15410 prune_unused_types_walk (dw_die_ref die)
15414 /* Don't do anything if this node is already marked. */
15418 switch (die->die_tag)
15420 case DW_TAG_const_type:
15421 case DW_TAG_packed_type:
15422 case DW_TAG_pointer_type:
15423 case DW_TAG_reference_type:
15424 case DW_TAG_volatile_type:
15425 case DW_TAG_typedef:
15426 case DW_TAG_array_type:
15427 case DW_TAG_structure_type:
15428 case DW_TAG_union_type:
15429 case DW_TAG_class_type:
15430 case DW_TAG_interface_type:
15431 case DW_TAG_friend:
15432 case DW_TAG_variant_part:
15433 case DW_TAG_enumeration_type:
15434 case DW_TAG_subroutine_type:
15435 case DW_TAG_string_type:
15436 case DW_TAG_set_type:
15437 case DW_TAG_subrange_type:
15438 case DW_TAG_ptr_to_member_type:
15439 case DW_TAG_file_type:
15440 if (die->die_perennial_p)
15443 /* It's a type node --- don't mark it. */
15447 /* Mark everything else. */
15453 /* Now, mark any dies referenced from here. */
15454 prune_unused_types_walk_attribs (die);
15456 /* Mark children. */
15457 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15460 /* Increment the string counts on strings referred to from DIE's
15464 prune_unused_types_update_strings (dw_die_ref die)
15469 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15470 if (AT_class (a) == dw_val_class_str)
15472 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
15474 /* Avoid unnecessarily putting strings that are used less than
15475 twice in the hash table. */
15477 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
15480 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
15481 htab_hash_string (s->str),
15483 gcc_assert (*slot == NULL);
15489 /* Remove from the tree DIE any dies that aren't marked. */
15492 prune_unused_types_prune (dw_die_ref die)
15496 gcc_assert (die->die_mark);
15497 prune_unused_types_update_strings (die);
15499 if (! die->die_child)
15502 c = die->die_child;
15504 dw_die_ref prev = c;
15505 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
15506 if (c == die->die_child)
15508 /* No marked children between 'prev' and the end of the list. */
15510 /* No marked children at all. */
15511 die->die_child = NULL;
15514 prev->die_sib = c->die_sib;
15515 die->die_child = prev;
15520 if (c != prev->die_sib)
15522 prune_unused_types_prune (c);
15523 } while (c != die->die_child);
15527 /* Remove dies representing declarations that we never use. */
15530 prune_unused_types (void)
15533 limbo_die_node *node;
15536 #if ENABLE_ASSERT_CHECKING
15537 /* All the marks should already be clear. */
15538 verify_marks_clear (comp_unit_die);
15539 for (node = limbo_die_list; node; node = node->next)
15540 verify_marks_clear (node->die);
15541 #endif /* ENABLE_ASSERT_CHECKING */
15543 /* Set the mark on nodes that are actually used. */
15544 prune_unused_types_walk (comp_unit_die);
15545 for (node = limbo_die_list; node; node = node->next)
15546 prune_unused_types_walk (node->die);
15548 /* Also set the mark on nodes referenced from the
15549 pubname_table or arange_table. */
15550 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
15551 prune_unused_types_mark (pub->die, 1);
15552 for (i = 0; i < arange_table_in_use; i++)
15553 prune_unused_types_mark (arange_table[i], 1);
15555 /* Get rid of nodes that aren't marked; and update the string counts. */
15556 if (debug_str_hash)
15557 htab_empty (debug_str_hash);
15558 prune_unused_types_prune (comp_unit_die);
15559 for (node = limbo_die_list; node; node = node->next)
15560 prune_unused_types_prune (node->die);
15562 /* Leave the marks clear. */
15563 prune_unmark_dies (comp_unit_die);
15564 for (node = limbo_die_list; node; node = node->next)
15565 prune_unmark_dies (node->die);
15568 /* Set the parameter to true if there are any relative pathnames in
15571 file_table_relative_p (void ** slot, void *param)
15573 bool *p = (bool *) param;
15574 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
15575 if (!IS_ABSOLUTE_PATH (d->filename))
15583 /* Output stuff that dwarf requires at the end of every file,
15584 and generate the DWARF-2 debugging info. */
15587 dwarf2out_finish (const char *filename)
15589 limbo_die_node *node, *next_node;
15590 dw_die_ref die = 0;
15592 /* Add the name for the main input file now. We delayed this from
15593 dwarf2out_init to avoid complications with PCH. */
15594 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
15595 if (!IS_ABSOLUTE_PATH (filename))
15596 add_comp_dir_attribute (comp_unit_die);
15597 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
15600 htab_traverse (file_table, file_table_relative_p, &p);
15602 add_comp_dir_attribute (comp_unit_die);
15605 /* Traverse the limbo die list, and add parent/child links. The only
15606 dies without parents that should be here are concrete instances of
15607 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15608 For concrete instances, we can get the parent die from the abstract
15610 for (node = limbo_die_list; node; node = next_node)
15612 next_node = node->next;
15615 if (die->die_parent == NULL)
15617 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
15620 add_child_die (origin->die_parent, die);
15621 else if (die == comp_unit_die)
15623 else if (errorcount > 0 || sorrycount > 0)
15624 /* It's OK to be confused by errors in the input. */
15625 add_child_die (comp_unit_die, die);
15628 /* In certain situations, the lexical block containing a
15629 nested function can be optimized away, which results
15630 in the nested function die being orphaned. Likewise
15631 with the return type of that nested function. Force
15632 this to be a child of the containing function.
15634 It may happen that even the containing function got fully
15635 inlined and optimized out. In that case we are lost and
15636 assign the empty child. This should not be big issue as
15637 the function is likely unreachable too. */
15638 tree context = NULL_TREE;
15640 gcc_assert (node->created_for);
15642 if (DECL_P (node->created_for))
15643 context = DECL_CONTEXT (node->created_for);
15644 else if (TYPE_P (node->created_for))
15645 context = TYPE_CONTEXT (node->created_for);
15647 gcc_assert (context
15648 && (TREE_CODE (context) == FUNCTION_DECL
15649 || TREE_CODE (context) == NAMESPACE_DECL));
15651 origin = lookup_decl_die (context);
15653 add_child_die (origin, die);
15655 add_child_die (comp_unit_die, die);
15660 limbo_die_list = NULL;
15662 /* Walk through the list of incomplete types again, trying once more to
15663 emit full debugging info for them. */
15664 retry_incomplete_types ();
15666 if (flag_eliminate_unused_debug_types)
15667 prune_unused_types ();
15669 /* Generate separate CUs for each of the include files we've seen.
15670 They will go into limbo_die_list. */
15671 if (flag_eliminate_dwarf2_dups)
15672 break_out_includes (comp_unit_die);
15674 /* Traverse the DIE's and add add sibling attributes to those DIE's
15675 that have children. */
15676 add_sibling_attributes (comp_unit_die);
15677 for (node = limbo_die_list; node; node = node->next)
15678 add_sibling_attributes (node->die);
15680 /* Output a terminator label for the .text section. */
15681 switch_to_section (text_section);
15682 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
15683 if (flag_reorder_blocks_and_partition)
15685 switch_to_section (unlikely_text_section ());
15686 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
15689 /* We can only use the low/high_pc attributes if all of the code was
15691 if (!have_multiple_function_sections)
15693 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
15694 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
15699 unsigned fde_idx = 0;
15701 /* We need to give .debug_loc and .debug_ranges an appropriate
15702 "base address". Use zero so that these addresses become
15703 absolute. Historically, we've emitted the unexpected
15704 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15705 Emit both to give time for other tools to adapt. */
15706 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
15707 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
15709 add_AT_range_list (comp_unit_die, DW_AT_ranges,
15710 add_ranges_by_labels (text_section_label,
15712 if (flag_reorder_blocks_and_partition)
15713 add_ranges_by_labels (cold_text_section_label,
15716 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
15718 dw_fde_ref fde = &fde_table[fde_idx];
15720 if (fde->dw_fde_switched_sections)
15722 add_ranges_by_labels (fde->dw_fde_hot_section_label,
15723 fde->dw_fde_hot_section_end_label);
15724 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
15725 fde->dw_fde_unlikely_section_end_label);
15728 add_ranges_by_labels (fde->dw_fde_begin,
15735 /* Output location list section if necessary. */
15736 if (have_location_lists)
15738 /* Output the location lists info. */
15739 switch_to_section (debug_loc_section);
15740 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
15741 DEBUG_LOC_SECTION_LABEL, 0);
15742 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
15743 output_location_lists (die);
15746 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15747 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
15748 debug_line_section_label);
15750 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15751 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
15753 /* Output all of the compilation units. We put the main one last so that
15754 the offsets are available to output_pubnames. */
15755 for (node = limbo_die_list; node; node = node->next)
15756 output_comp_unit (node->die, 0);
15758 output_comp_unit (comp_unit_die, 0);
15760 /* Output the abbreviation table. */
15761 switch_to_section (debug_abbrev_section);
15762 output_abbrev_section ();
15764 /* Output public names table if necessary. */
15765 if (!VEC_empty (pubname_entry, pubname_table))
15767 switch_to_section (debug_pubnames_section);
15768 output_pubnames (pubname_table);
15771 #ifdef DEBUG_PUBTYPES_SECTION
15772 /* Output public types table if necessary. */
15773 if (!VEC_empty (pubname_entry, pubtype_table))
15775 switch_to_section (debug_pubtypes_section);
15776 output_pubnames (pubtype_table);
15780 /* Output the address range information. We only put functions in the arange
15781 table, so don't write it out if we don't have any. */
15782 if (fde_table_in_use)
15784 switch_to_section (debug_aranges_section);
15788 /* Output ranges section if necessary. */
15789 if (ranges_table_in_use)
15791 switch_to_section (debug_ranges_section);
15792 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
15796 /* Output the source line correspondence table. We must do this
15797 even if there is no line information. Otherwise, on an empty
15798 translation unit, we will generate a present, but empty,
15799 .debug_info section. IRIX 6.5 `nm' will then complain when
15800 examining the file. This is done late so that any filenames
15801 used by the debug_info section are marked as 'used'. */
15802 if (! DWARF2_ASM_LINE_DEBUG_INFO)
15804 switch_to_section (debug_line_section);
15805 output_line_info ();
15808 /* Have to end the macro section. */
15809 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15811 switch_to_section (debug_macinfo_section);
15812 dw2_asm_output_data (1, 0, "End compilation unit");
15815 /* If we emitted any DW_FORM_strp form attribute, output the string
15817 if (debug_str_hash)
15818 htab_traverse (debug_str_hash, output_indirect_string, NULL);
15822 /* This should never be used, but its address is needed for comparisons. */
15823 const struct gcc_debug_hooks dwarf2_debug_hooks;
15825 #endif /* DWARF2_DEBUGGING_INFO */
15827 #include "gt-dwarf2out.h"