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 unsigned all_throwers_are_sibcalls : 1;
243 unsigned nothrow : 1;
244 unsigned uses_eh_lsda : 1;
248 /* Maximum size (in bytes) of an artificially generated label. */
249 #define MAX_ARTIFICIAL_LABEL_BYTES 30
251 /* The size of addresses as they appear in the Dwarf 2 data.
252 Some architectures use word addresses to refer to code locations,
253 but Dwarf 2 info always uses byte addresses. On such machines,
254 Dwarf 2 addresses need to be larger than the architecture's
256 #ifndef DWARF2_ADDR_SIZE
257 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
260 /* The size in bytes of a DWARF field indicating an offset or length
261 relative to a debug info section, specified to be 4 bytes in the
262 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
265 #ifndef DWARF_OFFSET_SIZE
266 #define DWARF_OFFSET_SIZE 4
269 /* According to the (draft) DWARF 3 specification, the initial length
270 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
271 bytes are 0xffffffff, followed by the length stored in the next 8
274 However, the SGI/MIPS ABI uses an initial length which is equal to
275 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
277 #ifndef DWARF_INITIAL_LENGTH_SIZE
278 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
281 #define DWARF_VERSION 2
283 /* Round SIZE up to the nearest BOUNDARY. */
284 #define DWARF_ROUND(SIZE,BOUNDARY) \
285 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
287 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
288 #ifndef DWARF_CIE_DATA_ALIGNMENT
289 #ifdef STACK_GROWS_DOWNWARD
290 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
292 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
296 /* CIE identifier. */
297 #if HOST_BITS_PER_WIDE_INT >= 64
298 #define DWARF_CIE_ID \
299 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
301 #define DWARF_CIE_ID DW_CIE_ID
304 /* A pointer to the base of a table that contains frame description
305 information for each routine. */
306 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
308 /* Number of elements currently allocated for fde_table. */
309 static GTY(()) unsigned fde_table_allocated;
311 /* Number of elements in fde_table currently in use. */
312 static GTY(()) unsigned fde_table_in_use;
314 /* Size (in elements) of increments by which we may expand the
316 #define FDE_TABLE_INCREMENT 256
318 /* Get the current fde_table entry we should use. */
320 static inline dw_fde_ref
323 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
326 /* A list of call frame insns for the CIE. */
327 static GTY(()) dw_cfi_ref cie_cfi_head;
329 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
330 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
331 attribute that accelerates the lookup of the FDE associated
332 with the subprogram. This variable holds the table index of the FDE
333 associated with the current function (body) definition. */
334 static unsigned current_funcdef_fde;
337 struct indirect_string_node GTY(())
340 unsigned int refcount;
345 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
347 static GTY(()) int dw2_string_counter;
348 static GTY(()) unsigned long dwarf2out_cfi_label_num;
350 /* True if the compilation unit places functions in more than one section. */
351 static GTY(()) bool have_multiple_function_sections = false;
353 /* Whether the default text and cold text sections have been used at all. */
355 static GTY(()) bool text_section_used = false;
356 static GTY(()) bool cold_text_section_used = false;
358 /* The default cold text section. */
359 static GTY(()) section *cold_text_section;
361 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
363 /* Forward declarations for functions defined in this file. */
365 static char *stripattributes (const char *);
366 static const char *dwarf_cfi_name (unsigned);
367 static dw_cfi_ref new_cfi (void);
368 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
369 static void add_fde_cfi (const char *, dw_cfi_ref);
370 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
371 static void lookup_cfa (dw_cfa_location *);
372 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
373 #ifdef DWARF2_UNWIND_INFO
374 static void initial_return_save (rtx);
376 static HOST_WIDE_INT stack_adjust_offset (const_rtx);
377 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
378 static void output_call_frame_info (int);
379 static void dwarf2out_note_section_used (void);
380 static void dwarf2out_stack_adjust (rtx, bool);
381 static void flush_queued_reg_saves (void);
382 static bool clobbers_queued_reg_save (const_rtx);
383 static void dwarf2out_frame_debug_expr (rtx, const char *);
385 /* Support for complex CFA locations. */
386 static void output_cfa_loc (dw_cfi_ref);
387 static void get_cfa_from_loc_descr (dw_cfa_location *,
388 struct dw_loc_descr_struct *);
389 static struct dw_loc_descr_struct *build_cfa_loc
390 (dw_cfa_location *, HOST_WIDE_INT);
391 static void def_cfa_1 (const char *, dw_cfa_location *);
393 /* How to start an assembler comment. */
394 #ifndef ASM_COMMENT_START
395 #define ASM_COMMENT_START ";#"
398 /* Data and reference forms for relocatable data. */
399 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
400 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
402 #ifndef DEBUG_FRAME_SECTION
403 #define DEBUG_FRAME_SECTION ".debug_frame"
406 #ifndef FUNC_BEGIN_LABEL
407 #define FUNC_BEGIN_LABEL "LFB"
410 #ifndef FUNC_END_LABEL
411 #define FUNC_END_LABEL "LFE"
414 #ifndef FRAME_BEGIN_LABEL
415 #define FRAME_BEGIN_LABEL "Lframe"
417 #define CIE_AFTER_SIZE_LABEL "LSCIE"
418 #define CIE_END_LABEL "LECIE"
419 #define FDE_LABEL "LSFDE"
420 #define FDE_AFTER_SIZE_LABEL "LASFDE"
421 #define FDE_END_LABEL "LEFDE"
422 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
423 #define LINE_NUMBER_END_LABEL "LELT"
424 #define LN_PROLOG_AS_LABEL "LASLTP"
425 #define LN_PROLOG_END_LABEL "LELTP"
426 #define DIE_LABEL_PREFIX "DW"
428 /* The DWARF 2 CFA column which tracks the return address. Normally this
429 is the column for PC, or the first column after all of the hard
431 #ifndef DWARF_FRAME_RETURN_COLUMN
433 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
435 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
439 /* The mapping from gcc register number to DWARF 2 CFA column number. By
440 default, we just provide columns for all registers. */
441 #ifndef DWARF_FRAME_REGNUM
442 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
445 /* Hook used by __throw. */
448 expand_builtin_dwarf_sp_column (void)
450 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
451 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
454 /* Return a pointer to a copy of the section string name S with all
455 attributes stripped off, and an asterisk prepended (for assemble_name). */
458 stripattributes (const char *s)
460 char *stripped = XNEWVEC (char, strlen (s) + 2);
465 while (*s && *s != ',')
472 /* MEM is a memory reference for the register size table, each element of
473 which has mode MODE. Initialize column C as a return address column. */
476 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
478 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
479 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
480 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
483 /* Generate code to initialize the register size table. */
486 expand_builtin_init_dwarf_reg_sizes (tree address)
489 enum machine_mode mode = TYPE_MODE (char_type_node);
490 rtx addr = expand_normal (address);
491 rtx mem = gen_rtx_MEM (BLKmode, addr);
492 bool wrote_return_column = false;
494 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
496 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
498 if (rnum < DWARF_FRAME_REGISTERS)
500 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
501 enum machine_mode save_mode = reg_raw_mode[i];
504 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
505 save_mode = choose_hard_reg_mode (i, 1, true);
506 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
508 if (save_mode == VOIDmode)
510 wrote_return_column = true;
512 size = GET_MODE_SIZE (save_mode);
516 emit_move_insn (adjust_address (mem, mode, offset),
517 gen_int_mode (size, mode));
521 if (!wrote_return_column)
522 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
524 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
525 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
528 targetm.init_dwarf_reg_sizes_extra (address);
531 /* Convert a DWARF call frame info. operation to its string name */
534 dwarf_cfi_name (unsigned int cfi_opc)
538 case DW_CFA_advance_loc:
539 return "DW_CFA_advance_loc";
541 return "DW_CFA_offset";
543 return "DW_CFA_restore";
547 return "DW_CFA_set_loc";
548 case DW_CFA_advance_loc1:
549 return "DW_CFA_advance_loc1";
550 case DW_CFA_advance_loc2:
551 return "DW_CFA_advance_loc2";
552 case DW_CFA_advance_loc4:
553 return "DW_CFA_advance_loc4";
554 case DW_CFA_offset_extended:
555 return "DW_CFA_offset_extended";
556 case DW_CFA_restore_extended:
557 return "DW_CFA_restore_extended";
558 case DW_CFA_undefined:
559 return "DW_CFA_undefined";
560 case DW_CFA_same_value:
561 return "DW_CFA_same_value";
562 case DW_CFA_register:
563 return "DW_CFA_register";
564 case DW_CFA_remember_state:
565 return "DW_CFA_remember_state";
566 case DW_CFA_restore_state:
567 return "DW_CFA_restore_state";
569 return "DW_CFA_def_cfa";
570 case DW_CFA_def_cfa_register:
571 return "DW_CFA_def_cfa_register";
572 case DW_CFA_def_cfa_offset:
573 return "DW_CFA_def_cfa_offset";
576 case DW_CFA_def_cfa_expression:
577 return "DW_CFA_def_cfa_expression";
578 case DW_CFA_expression:
579 return "DW_CFA_expression";
580 case DW_CFA_offset_extended_sf:
581 return "DW_CFA_offset_extended_sf";
582 case DW_CFA_def_cfa_sf:
583 return "DW_CFA_def_cfa_sf";
584 case DW_CFA_def_cfa_offset_sf:
585 return "DW_CFA_def_cfa_offset_sf";
587 /* SGI/MIPS specific */
588 case DW_CFA_MIPS_advance_loc8:
589 return "DW_CFA_MIPS_advance_loc8";
592 case DW_CFA_GNU_window_save:
593 return "DW_CFA_GNU_window_save";
594 case DW_CFA_GNU_args_size:
595 return "DW_CFA_GNU_args_size";
596 case DW_CFA_GNU_negative_offset_extended:
597 return "DW_CFA_GNU_negative_offset_extended";
600 return "DW_CFA_<unknown>";
604 /* Return a pointer to a newly allocated Call Frame Instruction. */
606 static inline dw_cfi_ref
609 dw_cfi_ref cfi = GGC_NEW (dw_cfi_node);
611 cfi->dw_cfi_next = NULL;
612 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
613 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
618 /* Add a Call Frame Instruction to list of instructions. */
621 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
625 /* Find the end of the chain. */
626 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
632 /* Generate a new label for the CFI info to refer to. */
635 dwarf2out_cfi_label (void)
637 static char label[20];
639 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
640 ASM_OUTPUT_LABEL (asm_out_file, label);
644 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
645 or to the CIE if LABEL is NULL. */
648 add_fde_cfi (const char *label, dw_cfi_ref cfi)
652 dw_fde_ref fde = current_fde ();
654 gcc_assert (fde != NULL);
657 label = dwarf2out_cfi_label ();
659 if (fde->dw_fde_current_label == NULL
660 || strcmp (label, fde->dw_fde_current_label) != 0)
664 label = xstrdup (label);
666 /* Set the location counter to the new label. */
668 /* If we have a current label, advance from there, otherwise
669 set the location directly using set_loc. */
670 xcfi->dw_cfi_opc = fde->dw_fde_current_label
671 ? DW_CFA_advance_loc4
673 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
674 add_cfi (&fde->dw_fde_cfi, xcfi);
676 fde->dw_fde_current_label = label;
679 add_cfi (&fde->dw_fde_cfi, cfi);
683 add_cfi (&cie_cfi_head, cfi);
686 /* Subroutine of lookup_cfa. */
689 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
691 switch (cfi->dw_cfi_opc)
693 case DW_CFA_def_cfa_offset:
694 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
696 case DW_CFA_def_cfa_offset_sf:
698 = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
700 case DW_CFA_def_cfa_register:
701 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
704 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
705 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
707 case DW_CFA_def_cfa_sf:
708 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
710 = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT;
712 case DW_CFA_def_cfa_expression:
713 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
720 /* Find the previous value for the CFA. */
723 lookup_cfa (dw_cfa_location *loc)
728 loc->reg = INVALID_REGNUM;
731 loc->base_offset = 0;
733 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
734 lookup_cfa_1 (cfi, loc);
736 fde = current_fde ();
738 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
739 lookup_cfa_1 (cfi, loc);
742 /* The current rule for calculating the DWARF2 canonical frame address. */
743 static dw_cfa_location cfa;
745 /* The register used for saving registers to the stack, and its offset
747 static dw_cfa_location cfa_store;
749 /* The running total of the size of arguments pushed onto the stack. */
750 static HOST_WIDE_INT args_size;
752 /* The last args_size we actually output. */
753 static HOST_WIDE_INT old_args_size;
755 /* Entry point to update the canonical frame address (CFA).
756 LABEL is passed to add_fde_cfi. The value of CFA is now to be
757 calculated from REG+OFFSET. */
760 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
767 def_cfa_1 (label, &loc);
770 /* Determine if two dw_cfa_location structures define the same data. */
773 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
775 return (loc1->reg == loc2->reg
776 && loc1->offset == loc2->offset
777 && loc1->indirect == loc2->indirect
778 && (loc1->indirect == 0
779 || loc1->base_offset == loc2->base_offset));
782 /* This routine does the actual work. The CFA is now calculated from
783 the dw_cfa_location structure. */
786 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
789 dw_cfa_location old_cfa, loc;
794 if (cfa_store.reg == loc.reg && loc.indirect == 0)
795 cfa_store.offset = loc.offset;
797 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
798 lookup_cfa (&old_cfa);
800 /* If nothing changed, no need to issue any call frame instructions. */
801 if (cfa_equal_p (&loc, &old_cfa))
806 if (loc.reg == old_cfa.reg && !loc.indirect)
808 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
809 the CFA register did not change but the offset did. */
812 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
813 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
815 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
816 cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset;
820 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
821 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
825 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
826 else if (loc.offset == old_cfa.offset
827 && old_cfa.reg != INVALID_REGNUM
830 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
831 indicating the CFA register has changed to <register> but the
832 offset has not changed. */
833 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
834 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
838 else if (loc.indirect == 0)
840 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
841 indicating the CFA register has changed to <register> with
842 the specified offset. */
845 HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT;
846 gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset);
848 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
849 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
850 cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset;
854 cfi->dw_cfi_opc = DW_CFA_def_cfa;
855 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
856 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
861 /* Construct a DW_CFA_def_cfa_expression instruction to
862 calculate the CFA using a full location expression since no
863 register-offset pair is available. */
864 struct dw_loc_descr_struct *loc_list;
866 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
867 loc_list = build_cfa_loc (&loc, 0);
868 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
871 add_fde_cfi (label, cfi);
874 /* Add the CFI for saving a register. REG is the CFA column number.
875 LABEL is passed to add_fde_cfi.
876 If SREG is -1, the register is saved at OFFSET from the CFA;
877 otherwise it is saved in SREG. */
880 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
882 dw_cfi_ref cfi = new_cfi ();
884 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
886 if (sreg == INVALID_REGNUM)
889 /* The register number won't fit in 6 bits, so we have to use
891 cfi->dw_cfi_opc = DW_CFA_offset_extended;
893 cfi->dw_cfi_opc = DW_CFA_offset;
895 #ifdef ENABLE_CHECKING
897 /* If we get an offset that is not a multiple of
898 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
899 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
901 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
903 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
906 offset /= DWARF_CIE_DATA_ALIGNMENT;
908 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
910 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
912 else if (sreg == reg)
913 cfi->dw_cfi_opc = DW_CFA_same_value;
916 cfi->dw_cfi_opc = DW_CFA_register;
917 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
920 add_fde_cfi (label, cfi);
923 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
924 This CFI tells the unwinder that it needs to restore the window registers
925 from the previous frame's window save area.
927 ??? Perhaps we should note in the CIE where windows are saved (instead of
928 assuming 0(cfa)) and what registers are in the window. */
931 dwarf2out_window_save (const char *label)
933 dw_cfi_ref cfi = new_cfi ();
935 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
936 add_fde_cfi (label, cfi);
939 /* Add a CFI to update the running total of the size of arguments
940 pushed onto the stack. */
943 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
947 if (size == old_args_size)
950 old_args_size = size;
953 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
954 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
955 add_fde_cfi (label, cfi);
958 /* Entry point for saving a register to the stack. REG is the GCC register
959 number. LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
964 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
967 /* Entry point for saving the return address in the stack.
968 LABEL and OFFSET are passed to reg_save. */
971 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
973 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
976 /* Entry point for saving the return address in a register.
977 LABEL and SREG are passed to reg_save. */
980 dwarf2out_return_reg (const char *label, unsigned int sreg)
982 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
985 #ifdef DWARF2_UNWIND_INFO
986 /* Record the initial position of the return address. RTL is
987 INCOMING_RETURN_ADDR_RTX. */
990 initial_return_save (rtx rtl)
992 unsigned int reg = INVALID_REGNUM;
993 HOST_WIDE_INT offset = 0;
995 switch (GET_CODE (rtl))
998 /* RA is in a register. */
999 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1003 /* RA is on the stack. */
1004 rtl = XEXP (rtl, 0);
1005 switch (GET_CODE (rtl))
1008 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1013 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1014 offset = INTVAL (XEXP (rtl, 1));
1018 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1019 offset = -INTVAL (XEXP (rtl, 1));
1029 /* The return address is at some offset from any value we can
1030 actually load. For instance, on the SPARC it is in %i7+8. Just
1031 ignore the offset for now; it doesn't matter for unwinding frames. */
1032 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
1033 initial_return_save (XEXP (rtl, 0));
1040 if (reg != DWARF_FRAME_RETURN_COLUMN)
1041 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1045 /* Given a SET, calculate the amount of stack adjustment it
1048 static HOST_WIDE_INT
1049 stack_adjust_offset (const_rtx pattern)
1051 const_rtx src = SET_SRC (pattern);
1052 const_rtx dest = SET_DEST (pattern);
1053 HOST_WIDE_INT offset = 0;
1056 if (dest == stack_pointer_rtx)
1058 /* (set (reg sp) (plus (reg sp) (const_int))) */
1059 code = GET_CODE (src);
1060 if (! (code == PLUS || code == MINUS)
1061 || XEXP (src, 0) != stack_pointer_rtx
1062 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1065 offset = INTVAL (XEXP (src, 1));
1069 else if (MEM_P (dest))
1071 /* (set (mem (pre_dec (reg sp))) (foo)) */
1072 src = XEXP (dest, 0);
1073 code = GET_CODE (src);
1079 if (XEXP (src, 0) == stack_pointer_rtx)
1081 rtx val = XEXP (XEXP (src, 1), 1);
1082 /* We handle only adjustments by constant amount. */
1083 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1084 && GET_CODE (val) == CONST_INT);
1085 offset = -INTVAL (val);
1092 if (XEXP (src, 0) == stack_pointer_rtx)
1094 offset = GET_MODE_SIZE (GET_MODE (dest));
1101 if (XEXP (src, 0) == stack_pointer_rtx)
1103 offset = -GET_MODE_SIZE (GET_MODE (dest));
1118 /* Check INSN to see if it looks like a push or a stack adjustment, and
1119 make a note of it if it does. EH uses this information to find out how
1120 much extra space it needs to pop off the stack. */
1123 dwarf2out_stack_adjust (rtx insn, bool after_p)
1125 HOST_WIDE_INT offset;
1129 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1130 with this function. Proper support would require all frame-related
1131 insns to be marked, and to be able to handle saving state around
1132 epilogues textually in the middle of the function. */
1133 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1136 /* If only calls can throw, and we have a frame pointer,
1137 save up adjustments until we see the CALL_INSN. */
1138 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1140 if (CALL_P (insn) && !after_p)
1142 /* Extract the size of the args from the CALL rtx itself. */
1143 insn = PATTERN (insn);
1144 if (GET_CODE (insn) == PARALLEL)
1145 insn = XVECEXP (insn, 0, 0);
1146 if (GET_CODE (insn) == SET)
1147 insn = SET_SRC (insn);
1148 gcc_assert (GET_CODE (insn) == CALL);
1149 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1154 if (CALL_P (insn) && !after_p)
1156 if (!flag_asynchronous_unwind_tables)
1157 dwarf2out_args_size ("", args_size);
1160 else if (BARRIER_P (insn))
1162 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1163 the compiler will have already emitted a stack adjustment, but
1164 doesn't bother for calls to noreturn functions. */
1165 #ifdef STACK_GROWS_DOWNWARD
1166 offset = -args_size;
1171 else if (GET_CODE (PATTERN (insn)) == SET)
1172 offset = stack_adjust_offset (PATTERN (insn));
1173 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1174 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1176 /* There may be stack adjustments inside compound insns. Search
1178 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1179 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1180 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1188 if (cfa.reg == STACK_POINTER_REGNUM)
1189 cfa.offset += offset;
1191 #ifndef STACK_GROWS_DOWNWARD
1195 args_size += offset;
1199 label = dwarf2out_cfi_label ();
1200 def_cfa_1 (label, &cfa);
1201 if (flag_asynchronous_unwind_tables)
1202 dwarf2out_args_size (label, args_size);
1207 /* We delay emitting a register save until either (a) we reach the end
1208 of the prologue or (b) the register is clobbered. This clusters
1209 register saves so that there are fewer pc advances. */
1211 struct queued_reg_save GTY(())
1213 struct queued_reg_save *next;
1215 HOST_WIDE_INT cfa_offset;
1219 static GTY(()) struct queued_reg_save *queued_reg_saves;
1221 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1222 struct reg_saved_in_data GTY(()) {
1227 /* A list of registers saved in other registers.
1228 The list intentionally has a small maximum capacity of 4; if your
1229 port needs more than that, you might consider implementing a
1230 more efficient data structure. */
1231 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1232 static GTY(()) size_t num_regs_saved_in_regs;
1234 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1235 static const char *last_reg_save_label;
1237 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1238 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1241 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1243 struct queued_reg_save *q;
1245 /* Duplicates waste space, but it's also necessary to remove them
1246 for correctness, since the queue gets output in reverse
1248 for (q = queued_reg_saves; q != NULL; q = q->next)
1249 if (REGNO (q->reg) == REGNO (reg))
1254 q = GGC_NEW (struct queued_reg_save);
1255 q->next = queued_reg_saves;
1256 queued_reg_saves = q;
1260 q->cfa_offset = offset;
1261 q->saved_reg = sreg;
1263 last_reg_save_label = label;
1266 /* Output all the entries in QUEUED_REG_SAVES. */
1269 flush_queued_reg_saves (void)
1271 struct queued_reg_save *q;
1273 for (q = queued_reg_saves; q; q = q->next)
1276 unsigned int reg, sreg;
1278 for (i = 0; i < num_regs_saved_in_regs; i++)
1279 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1281 if (q->saved_reg && i == num_regs_saved_in_regs)
1283 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1284 num_regs_saved_in_regs++;
1286 if (i != num_regs_saved_in_regs)
1288 regs_saved_in_regs[i].orig_reg = q->reg;
1289 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1292 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1294 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1296 sreg = INVALID_REGNUM;
1297 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1300 queued_reg_saves = NULL;
1301 last_reg_save_label = NULL;
1304 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1305 location for? Or, does it clobber a register which we've previously
1306 said that some other register is saved in, and for which we now
1307 have a new location for? */
1310 clobbers_queued_reg_save (const_rtx insn)
1312 struct queued_reg_save *q;
1314 for (q = queued_reg_saves; q; q = q->next)
1317 if (modified_in_p (q->reg, insn))
1319 for (i = 0; i < num_regs_saved_in_regs; i++)
1320 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1321 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1328 /* Entry point for saving the first register into the second. */
1331 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1334 unsigned int regno, sregno;
1336 for (i = 0; i < num_regs_saved_in_regs; i++)
1337 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1339 if (i == num_regs_saved_in_regs)
1341 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1342 num_regs_saved_in_regs++;
1344 regs_saved_in_regs[i].orig_reg = reg;
1345 regs_saved_in_regs[i].saved_in_reg = sreg;
1347 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1348 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1349 reg_save (label, regno, sregno, 0);
1352 /* What register, if any, is currently saved in REG? */
1355 reg_saved_in (rtx reg)
1357 unsigned int regn = REGNO (reg);
1359 struct queued_reg_save *q;
1361 for (q = queued_reg_saves; q; q = q->next)
1362 if (q->saved_reg && regn == REGNO (q->saved_reg))
1365 for (i = 0; i < num_regs_saved_in_regs; i++)
1366 if (regs_saved_in_regs[i].saved_in_reg
1367 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1368 return regs_saved_in_regs[i].orig_reg;
1374 /* A temporary register holding an integral value used in adjusting SP
1375 or setting up the store_reg. The "offset" field holds the integer
1376 value, not an offset. */
1377 static dw_cfa_location cfa_temp;
1379 /* Record call frame debugging information for an expression EXPR,
1380 which either sets SP or FP (adjusting how we calculate the frame
1381 address) or saves a register to the stack or another register.
1382 LABEL indicates the address of EXPR.
1384 This function encodes a state machine mapping rtxes to actions on
1385 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1386 users need not read the source code.
1388 The High-Level Picture
1390 Changes in the register we use to calculate the CFA: Currently we
1391 assume that if you copy the CFA register into another register, we
1392 should take the other one as the new CFA register; this seems to
1393 work pretty well. If it's wrong for some target, it's simple
1394 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1396 Changes in the register we use for saving registers to the stack:
1397 This is usually SP, but not always. Again, we deduce that if you
1398 copy SP into another register (and SP is not the CFA register),
1399 then the new register is the one we will be using for register
1400 saves. This also seems to work.
1402 Register saves: There's not much guesswork about this one; if
1403 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1404 register save, and the register used to calculate the destination
1405 had better be the one we think we're using for this purpose.
1406 It's also assumed that a copy from a call-saved register to another
1407 register is saving that register if RTX_FRAME_RELATED_P is set on
1408 that instruction. If the copy is from a call-saved register to
1409 the *same* register, that means that the register is now the same
1410 value as in the caller.
1412 Except: If the register being saved is the CFA register, and the
1413 offset is nonzero, we are saving the CFA, so we assume we have to
1414 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1415 the intent is to save the value of SP from the previous frame.
1417 In addition, if a register has previously been saved to a different
1420 Invariants / Summaries of Rules
1422 cfa current rule for calculating the CFA. It usually
1423 consists of a register and an offset.
1424 cfa_store register used by prologue code to save things to the stack
1425 cfa_store.offset is the offset from the value of
1426 cfa_store.reg to the actual CFA
1427 cfa_temp register holding an integral value. cfa_temp.offset
1428 stores the value, which will be used to adjust the
1429 stack pointer. cfa_temp is also used like cfa_store,
1430 to track stores to the stack via fp or a temp reg.
1432 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1433 with cfa.reg as the first operand changes the cfa.reg and its
1434 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1437 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1438 expression yielding a constant. This sets cfa_temp.reg
1439 and cfa_temp.offset.
1441 Rule 5: Create a new register cfa_store used to save items to the
1444 Rules 10-14: Save a register to the stack. Define offset as the
1445 difference of the original location and cfa_store's
1446 location (or cfa_temp's location if cfa_temp is used).
1450 "{a,b}" indicates a choice of a xor b.
1451 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1454 (set <reg1> <reg2>:cfa.reg)
1455 effects: cfa.reg = <reg1>
1456 cfa.offset unchanged
1457 cfa_temp.reg = <reg1>
1458 cfa_temp.offset = cfa.offset
1461 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1462 {<const_int>,<reg>:cfa_temp.reg}))
1463 effects: cfa.reg = sp if fp used
1464 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1465 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1466 if cfa_store.reg==sp
1469 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1470 effects: cfa.reg = fp
1471 cfa_offset += +/- <const_int>
1474 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1475 constraints: <reg1> != fp
1477 effects: cfa.reg = <reg1>
1478 cfa_temp.reg = <reg1>
1479 cfa_temp.offset = cfa.offset
1482 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1483 constraints: <reg1> != fp
1485 effects: cfa_store.reg = <reg1>
1486 cfa_store.offset = cfa.offset - cfa_temp.offset
1489 (set <reg> <const_int>)
1490 effects: cfa_temp.reg = <reg>
1491 cfa_temp.offset = <const_int>
1494 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1495 effects: cfa_temp.reg = <reg1>
1496 cfa_temp.offset |= <const_int>
1499 (set <reg> (high <exp>))
1503 (set <reg> (lo_sum <exp> <const_int>))
1504 effects: cfa_temp.reg = <reg>
1505 cfa_temp.offset = <const_int>
1508 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1509 effects: cfa_store.offset -= <const_int>
1510 cfa.offset = cfa_store.offset if cfa.reg == sp
1512 cfa.base_offset = -cfa_store.offset
1515 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1516 effects: cfa_store.offset += -/+ mode_size(mem)
1517 cfa.offset = cfa_store.offset if cfa.reg == sp
1519 cfa.base_offset = -cfa_store.offset
1522 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1525 effects: cfa.reg = <reg1>
1526 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1529 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1530 effects: cfa.reg = <reg1>
1531 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1534 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1535 effects: cfa.reg = <reg1>
1536 cfa.base_offset = -cfa_temp.offset
1537 cfa_temp.offset -= mode_size(mem)
1540 (set <reg> {unspec, unspec_volatile})
1541 effects: target-dependent */
1544 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1546 rtx src, dest, span;
1547 HOST_WIDE_INT offset;
1549 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1550 the PARALLEL independently. The first element is always processed if
1551 it is a SET. This is for backward compatibility. Other elements
1552 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1553 flag is set in them. */
1554 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1557 int limit = XVECLEN (expr, 0);
1560 /* PARALLELs have strict read-modify-write semantics, so we
1561 ought to evaluate every rvalue before changing any lvalue.
1562 It's cumbersome to do that in general, but there's an
1563 easy approximation that is enough for all current users:
1564 handle register saves before register assignments. */
1565 if (GET_CODE (expr) == PARALLEL)
1566 for (par_index = 0; par_index < limit; par_index++)
1568 elem = XVECEXP (expr, 0, par_index);
1569 if (GET_CODE (elem) == SET
1570 && MEM_P (SET_DEST (elem))
1571 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1572 dwarf2out_frame_debug_expr (elem, label);
1575 for (par_index = 0; par_index < limit; par_index++)
1577 elem = XVECEXP (expr, 0, par_index);
1578 if (GET_CODE (elem) == SET
1579 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
1580 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
1581 dwarf2out_frame_debug_expr (elem, label);
1586 gcc_assert (GET_CODE (expr) == SET);
1588 src = SET_SRC (expr);
1589 dest = SET_DEST (expr);
1593 rtx rsi = reg_saved_in (src);
1598 switch (GET_CODE (dest))
1601 switch (GET_CODE (src))
1603 /* Setting FP from SP. */
1605 if (cfa.reg == (unsigned) REGNO (src))
1608 /* Update the CFA rule wrt SP or FP. Make sure src is
1609 relative to the current CFA register.
1611 We used to require that dest be either SP or FP, but the
1612 ARM copies SP to a temporary register, and from there to
1613 FP. So we just rely on the backends to only set
1614 RTX_FRAME_RELATED_P on appropriate insns. */
1615 cfa.reg = REGNO (dest);
1616 cfa_temp.reg = cfa.reg;
1617 cfa_temp.offset = cfa.offset;
1621 /* Saving a register in a register. */
1622 gcc_assert (!fixed_regs [REGNO (dest)]
1623 /* For the SPARC and its register window. */
1624 || (DWARF_FRAME_REGNUM (REGNO (src))
1625 == DWARF_FRAME_RETURN_COLUMN));
1626 queue_reg_save (label, src, dest, 0);
1633 if (dest == stack_pointer_rtx)
1637 switch (GET_CODE (XEXP (src, 1)))
1640 offset = INTVAL (XEXP (src, 1));
1643 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1645 offset = cfa_temp.offset;
1651 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1653 /* Restoring SP from FP in the epilogue. */
1654 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1655 cfa.reg = STACK_POINTER_REGNUM;
1657 else if (GET_CODE (src) == LO_SUM)
1658 /* Assume we've set the source reg of the LO_SUM from sp. */
1661 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1663 if (GET_CODE (src) != MINUS)
1665 if (cfa.reg == STACK_POINTER_REGNUM)
1666 cfa.offset += offset;
1667 if (cfa_store.reg == STACK_POINTER_REGNUM)
1668 cfa_store.offset += offset;
1670 else if (dest == hard_frame_pointer_rtx)
1673 /* Either setting the FP from an offset of the SP,
1674 or adjusting the FP */
1675 gcc_assert (frame_pointer_needed);
1677 gcc_assert (REG_P (XEXP (src, 0))
1678 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1679 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1680 offset = INTVAL (XEXP (src, 1));
1681 if (GET_CODE (src) != MINUS)
1683 cfa.offset += offset;
1684 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1688 gcc_assert (GET_CODE (src) != MINUS);
1691 if (REG_P (XEXP (src, 0))
1692 && REGNO (XEXP (src, 0)) == cfa.reg
1693 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1695 /* Setting a temporary CFA register that will be copied
1696 into the FP later on. */
1697 offset = - INTVAL (XEXP (src, 1));
1698 cfa.offset += offset;
1699 cfa.reg = REGNO (dest);
1700 /* Or used to save regs to the stack. */
1701 cfa_temp.reg = cfa.reg;
1702 cfa_temp.offset = cfa.offset;
1706 else if (REG_P (XEXP (src, 0))
1707 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1708 && XEXP (src, 1) == stack_pointer_rtx)
1710 /* Setting a scratch register that we will use instead
1711 of SP for saving registers to the stack. */
1712 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1713 cfa_store.reg = REGNO (dest);
1714 cfa_store.offset = cfa.offset - cfa_temp.offset;
1718 else if (GET_CODE (src) == LO_SUM
1719 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1721 cfa_temp.reg = REGNO (dest);
1722 cfa_temp.offset = INTVAL (XEXP (src, 1));
1731 cfa_temp.reg = REGNO (dest);
1732 cfa_temp.offset = INTVAL (src);
1737 gcc_assert (REG_P (XEXP (src, 0))
1738 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1739 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1741 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1742 cfa_temp.reg = REGNO (dest);
1743 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1746 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1747 which will fill in all of the bits. */
1754 case UNSPEC_VOLATILE:
1755 gcc_assert (targetm.dwarf_handle_frame_unspec);
1756 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1763 def_cfa_1 (label, &cfa);
1767 gcc_assert (REG_P (src));
1769 /* Saving a register to the stack. Make sure dest is relative to the
1771 switch (GET_CODE (XEXP (dest, 0)))
1776 /* We can't handle variable size modifications. */
1777 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1779 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1781 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1782 && cfa_store.reg == STACK_POINTER_REGNUM);
1784 cfa_store.offset += offset;
1785 if (cfa.reg == STACK_POINTER_REGNUM)
1786 cfa.offset = cfa_store.offset;
1788 offset = -cfa_store.offset;
1794 offset = GET_MODE_SIZE (GET_MODE (dest));
1795 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1798 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1799 && cfa_store.reg == STACK_POINTER_REGNUM);
1801 cfa_store.offset += offset;
1802 if (cfa.reg == STACK_POINTER_REGNUM)
1803 cfa.offset = cfa_store.offset;
1805 offset = -cfa_store.offset;
1809 /* With an offset. */
1816 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT
1817 && REG_P (XEXP (XEXP (dest, 0), 0)));
1818 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1819 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1822 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1824 if (cfa_store.reg == (unsigned) regno)
1825 offset -= cfa_store.offset;
1828 gcc_assert (cfa_temp.reg == (unsigned) regno);
1829 offset -= cfa_temp.offset;
1835 /* Without an offset. */
1838 int regno = REGNO (XEXP (dest, 0));
1840 if (cfa_store.reg == (unsigned) regno)
1841 offset = -cfa_store.offset;
1844 gcc_assert (cfa_temp.reg == (unsigned) regno);
1845 offset = -cfa_temp.offset;
1852 gcc_assert (cfa_temp.reg
1853 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1854 offset = -cfa_temp.offset;
1855 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1862 if (REGNO (src) != STACK_POINTER_REGNUM
1863 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1864 && (unsigned) REGNO (src) == cfa.reg)
1866 /* We're storing the current CFA reg into the stack. */
1868 if (cfa.offset == 0)
1870 /* If the source register is exactly the CFA, assume
1871 we're saving SP like any other register; this happens
1873 def_cfa_1 (label, &cfa);
1874 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1879 /* Otherwise, we'll need to look in the stack to
1880 calculate the CFA. */
1881 rtx x = XEXP (dest, 0);
1885 gcc_assert (REG_P (x));
1887 cfa.reg = REGNO (x);
1888 cfa.base_offset = offset;
1890 def_cfa_1 (label, &cfa);
1895 def_cfa_1 (label, &cfa);
1897 span = targetm.dwarf_register_span (src);
1900 queue_reg_save (label, src, NULL_RTX, offset);
1903 /* We have a PARALLEL describing where the contents of SRC
1904 live. Queue register saves for each piece of the
1908 HOST_WIDE_INT span_offset = offset;
1910 gcc_assert (GET_CODE (span) == PARALLEL);
1912 limit = XVECLEN (span, 0);
1913 for (par_index = 0; par_index < limit; par_index++)
1915 rtx elem = XVECEXP (span, 0, par_index);
1917 queue_reg_save (label, elem, NULL_RTX, span_offset);
1918 span_offset += GET_MODE_SIZE (GET_MODE (elem));
1929 /* Record call frame debugging information for INSN, which either
1930 sets SP or FP (adjusting how we calculate the frame address) or saves a
1931 register to the stack. If INSN is NULL_RTX, initialize our state.
1933 If AFTER_P is false, we're being called before the insn is emitted,
1934 otherwise after. Call instructions get invoked twice. */
1937 dwarf2out_frame_debug (rtx insn, bool after_p)
1942 if (insn == NULL_RTX)
1946 /* Flush any queued register saves. */
1947 flush_queued_reg_saves ();
1949 /* Set up state for generating call frame debug info. */
1952 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1954 cfa.reg = STACK_POINTER_REGNUM;
1957 cfa_temp.offset = 0;
1959 for (i = 0; i < num_regs_saved_in_regs; i++)
1961 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1962 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1964 num_regs_saved_in_regs = 0;
1968 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1969 flush_queued_reg_saves ();
1971 if (! RTX_FRAME_RELATED_P (insn))
1973 if (!ACCUMULATE_OUTGOING_ARGS)
1974 dwarf2out_stack_adjust (insn, after_p);
1978 label = dwarf2out_cfi_label ();
1979 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1981 insn = XEXP (src, 0);
1983 insn = PATTERN (insn);
1985 dwarf2out_frame_debug_expr (insn, label);
1990 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1991 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1992 (enum dwarf_call_frame_info cfi);
1994 static enum dw_cfi_oprnd_type
1995 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
2000 case DW_CFA_GNU_window_save:
2001 return dw_cfi_oprnd_unused;
2003 case DW_CFA_set_loc:
2004 case DW_CFA_advance_loc1:
2005 case DW_CFA_advance_loc2:
2006 case DW_CFA_advance_loc4:
2007 case DW_CFA_MIPS_advance_loc8:
2008 return dw_cfi_oprnd_addr;
2011 case DW_CFA_offset_extended:
2012 case DW_CFA_def_cfa:
2013 case DW_CFA_offset_extended_sf:
2014 case DW_CFA_def_cfa_sf:
2015 case DW_CFA_restore_extended:
2016 case DW_CFA_undefined:
2017 case DW_CFA_same_value:
2018 case DW_CFA_def_cfa_register:
2019 case DW_CFA_register:
2020 return dw_cfi_oprnd_reg_num;
2022 case DW_CFA_def_cfa_offset:
2023 case DW_CFA_GNU_args_size:
2024 case DW_CFA_def_cfa_offset_sf:
2025 return dw_cfi_oprnd_offset;
2027 case DW_CFA_def_cfa_expression:
2028 case DW_CFA_expression:
2029 return dw_cfi_oprnd_loc;
2036 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2037 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2038 (enum dwarf_call_frame_info cfi);
2040 static enum dw_cfi_oprnd_type
2041 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
2045 case DW_CFA_def_cfa:
2046 case DW_CFA_def_cfa_sf:
2048 case DW_CFA_offset_extended_sf:
2049 case DW_CFA_offset_extended:
2050 return dw_cfi_oprnd_offset;
2052 case DW_CFA_register:
2053 return dw_cfi_oprnd_reg_num;
2056 return dw_cfi_oprnd_unused;
2060 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2062 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2063 switch to the data section instead, and write out a synthetic label
2067 switch_to_eh_frame_section (void)
2071 #ifdef EH_FRAME_SECTION_NAME
2072 if (eh_frame_section == 0)
2076 if (EH_TABLES_CAN_BE_READ_ONLY)
2082 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2084 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2086 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2088 flags = ((! flag_pic
2089 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
2090 && (fde_encoding & 0x70) != DW_EH_PE_aligned
2091 && (per_encoding & 0x70) != DW_EH_PE_absptr
2092 && (per_encoding & 0x70) != DW_EH_PE_aligned
2093 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
2094 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
2095 ? 0 : SECTION_WRITE);
2098 flags = SECTION_WRITE;
2099 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
2103 if (eh_frame_section)
2104 switch_to_section (eh_frame_section);
2107 /* We have no special eh_frame section. Put the information in
2108 the data section and emit special labels to guide collect2. */
2109 switch_to_section (data_section);
2110 label = get_file_function_name ("F");
2111 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2112 targetm.asm_out.globalize_label (asm_out_file,
2113 IDENTIFIER_POINTER (label));
2114 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2118 /* Output a Call Frame Information opcode and its operand(s). */
2121 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
2124 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
2125 dw2_asm_output_data (1, (cfi->dw_cfi_opc
2126 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
2127 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
2128 ((unsigned HOST_WIDE_INT)
2129 cfi->dw_cfi_oprnd1.dw_cfi_offset));
2130 else if (cfi->dw_cfi_opc == DW_CFA_offset)
2132 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2133 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2134 "DW_CFA_offset, column 0x%lx", r);
2135 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2137 else if (cfi->dw_cfi_opc == DW_CFA_restore)
2139 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2140 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
2141 "DW_CFA_restore, column 0x%lx", r);
2145 dw2_asm_output_data (1, cfi->dw_cfi_opc,
2146 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
2148 switch (cfi->dw_cfi_opc)
2150 case DW_CFA_set_loc:
2152 dw2_asm_output_encoded_addr_rtx (
2153 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2154 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
2157 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2158 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
2159 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2162 case DW_CFA_advance_loc1:
2163 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2164 fde->dw_fde_current_label, NULL);
2165 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2168 case DW_CFA_advance_loc2:
2169 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2170 fde->dw_fde_current_label, NULL);
2171 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2174 case DW_CFA_advance_loc4:
2175 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2176 fde->dw_fde_current_label, NULL);
2177 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2180 case DW_CFA_MIPS_advance_loc8:
2181 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2182 fde->dw_fde_current_label, NULL);
2183 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2186 case DW_CFA_offset_extended:
2187 case DW_CFA_def_cfa:
2188 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2189 dw2_asm_output_data_uleb128 (r, NULL);
2190 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2193 case DW_CFA_offset_extended_sf:
2194 case DW_CFA_def_cfa_sf:
2195 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2196 dw2_asm_output_data_uleb128 (r, NULL);
2197 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2200 case DW_CFA_restore_extended:
2201 case DW_CFA_undefined:
2202 case DW_CFA_same_value:
2203 case DW_CFA_def_cfa_register:
2204 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2205 dw2_asm_output_data_uleb128 (r, NULL);
2208 case DW_CFA_register:
2209 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2210 dw2_asm_output_data_uleb128 (r, NULL);
2211 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2212 dw2_asm_output_data_uleb128 (r, NULL);
2215 case DW_CFA_def_cfa_offset:
2216 case DW_CFA_GNU_args_size:
2217 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2220 case DW_CFA_def_cfa_offset_sf:
2221 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2224 case DW_CFA_GNU_window_save:
2227 case DW_CFA_def_cfa_expression:
2228 case DW_CFA_expression:
2229 output_cfa_loc (cfi);
2232 case DW_CFA_GNU_negative_offset_extended:
2233 /* Obsoleted by DW_CFA_offset_extended_sf. */
2242 /* Output the call frame information used to record information
2243 that relates to calculating the frame pointer, and records the
2244 location of saved registers. */
2247 output_call_frame_info (int for_eh)
2252 char l1[20], l2[20], section_start_label[20];
2253 bool any_lsda_needed = false;
2254 char augmentation[6];
2255 int augmentation_size;
2256 int fde_encoding = DW_EH_PE_absptr;
2257 int per_encoding = DW_EH_PE_absptr;
2258 int lsda_encoding = DW_EH_PE_absptr;
2261 /* Don't emit a CIE if there won't be any FDEs. */
2262 if (fde_table_in_use == 0)
2265 /* If we make FDEs linkonce, we may have to emit an empty label for
2266 an FDE that wouldn't otherwise be emitted. We want to avoid
2267 having an FDE kept around when the function it refers to is
2268 discarded. Example where this matters: a primary function
2269 template in C++ requires EH information, but an explicit
2270 specialization doesn't. */
2271 if (TARGET_USES_WEAK_UNWIND_INFO
2272 && ! flag_asynchronous_unwind_tables
2275 for (i = 0; i < fde_table_in_use; i++)
2276 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2277 && !fde_table[i].uses_eh_lsda
2278 && ! DECL_WEAK (fde_table[i].decl))
2279 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2280 for_eh, /* empty */ 1);
2282 /* If we don't have any functions we'll want to unwind out of, don't
2283 emit any EH unwind information. Note that if exceptions aren't
2284 enabled, we won't have collected nothrow information, and if we
2285 asked for asynchronous tables, we always want this info. */
2288 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2290 for (i = 0; i < fde_table_in_use; i++)
2291 if (fde_table[i].uses_eh_lsda)
2292 any_eh_needed = any_lsda_needed = true;
2293 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2294 any_eh_needed = true;
2295 else if (! fde_table[i].nothrow
2296 && ! fde_table[i].all_throwers_are_sibcalls)
2297 any_eh_needed = true;
2299 if (! any_eh_needed)
2303 /* We're going to be generating comments, so turn on app. */
2308 switch_to_eh_frame_section ();
2311 if (!debug_frame_section)
2312 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
2313 SECTION_DEBUG, NULL);
2314 switch_to_section (debug_frame_section);
2317 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2318 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2320 /* Output the CIE. */
2321 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2322 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2323 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2324 dw2_asm_output_data (4, 0xffffffff,
2325 "Initial length escape value indicating 64-bit DWARF extension");
2326 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2327 "Length of Common Information Entry");
2328 ASM_OUTPUT_LABEL (asm_out_file, l1);
2330 /* Now that the CIE pointer is PC-relative for EH,
2331 use 0 to identify the CIE. */
2332 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2333 (for_eh ? 0 : DWARF_CIE_ID),
2334 "CIE Identifier Tag");
2336 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2338 augmentation[0] = 0;
2339 augmentation_size = 0;
2345 z Indicates that a uleb128 is present to size the
2346 augmentation section.
2347 L Indicates the encoding (and thus presence) of
2348 an LSDA pointer in the FDE augmentation.
2349 R Indicates a non-default pointer encoding for
2351 P Indicates the presence of an encoding + language
2352 personality routine in the CIE augmentation. */
2354 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2355 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2356 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2358 p = augmentation + 1;
2359 if (eh_personality_libfunc)
2362 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2363 assemble_external_libcall (eh_personality_libfunc);
2365 if (any_lsda_needed)
2368 augmentation_size += 1;
2370 if (fde_encoding != DW_EH_PE_absptr)
2373 augmentation_size += 1;
2375 if (p > augmentation + 1)
2377 augmentation[0] = 'z';
2381 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2382 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2384 int offset = ( 4 /* Length */
2386 + 1 /* CIE version */
2387 + strlen (augmentation) + 1 /* Augmentation */
2388 + size_of_uleb128 (1) /* Code alignment */
2389 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2391 + 1 /* Augmentation size */
2392 + 1 /* Personality encoding */ );
2393 int pad = -offset & (PTR_SIZE - 1);
2395 augmentation_size += pad;
2397 /* Augmentations should be small, so there's scarce need to
2398 iterate for a solution. Die if we exceed one uleb128 byte. */
2399 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2403 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2404 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2405 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2406 "CIE Data Alignment Factor");
2408 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2409 if (DW_CIE_VERSION == 1)
2410 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2412 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2414 if (augmentation[0])
2416 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2417 if (eh_personality_libfunc)
2419 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2420 eh_data_format_name (per_encoding));
2421 dw2_asm_output_encoded_addr_rtx (per_encoding,
2422 eh_personality_libfunc,
2426 if (any_lsda_needed)
2427 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2428 eh_data_format_name (lsda_encoding));
2430 if (fde_encoding != DW_EH_PE_absptr)
2431 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2432 eh_data_format_name (fde_encoding));
2435 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2436 output_cfi (cfi, NULL, for_eh);
2438 /* Pad the CIE out to an address sized boundary. */
2439 ASM_OUTPUT_ALIGN (asm_out_file,
2440 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2441 ASM_OUTPUT_LABEL (asm_out_file, l2);
2443 /* Loop through all of the FDE's. */
2444 for (i = 0; i < fde_table_in_use; i++)
2446 fde = &fde_table[i];
2448 /* Don't emit EH unwind info for leaf functions that don't need it. */
2449 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2450 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2451 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2452 && !fde->uses_eh_lsda)
2455 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2456 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2457 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2458 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2459 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
2460 dw2_asm_output_data (4, 0xffffffff,
2461 "Initial length escape value indicating 64-bit DWARF extension");
2462 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2464 ASM_OUTPUT_LABEL (asm_out_file, l1);
2467 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2469 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2470 debug_frame_section, "FDE CIE offset");
2474 if (fde->dw_fde_switched_sections)
2476 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2477 fde->dw_fde_unlikely_section_label);
2478 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2479 fde->dw_fde_hot_section_label);
2480 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2481 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2482 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false,
2483 "FDE initial location");
2484 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2485 fde->dw_fde_hot_section_end_label,
2486 fde->dw_fde_hot_section_label,
2487 "FDE address range");
2488 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false,
2489 "FDE initial location");
2490 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2491 fde->dw_fde_unlikely_section_end_label,
2492 fde->dw_fde_unlikely_section_label,
2493 "FDE address range");
2497 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2498 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2499 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2502 "FDE initial location");
2503 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2504 fde->dw_fde_end, fde->dw_fde_begin,
2505 "FDE address range");
2510 if (fde->dw_fde_switched_sections)
2512 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2513 fde->dw_fde_hot_section_label,
2514 "FDE initial location");
2515 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2516 fde->dw_fde_hot_section_end_label,
2517 fde->dw_fde_hot_section_label,
2518 "FDE address range");
2519 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2520 fde->dw_fde_unlikely_section_label,
2521 "FDE initial location");
2522 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2523 fde->dw_fde_unlikely_section_end_label,
2524 fde->dw_fde_unlikely_section_label,
2525 "FDE address range");
2529 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2530 "FDE initial location");
2531 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2532 fde->dw_fde_end, fde->dw_fde_begin,
2533 "FDE address range");
2537 if (augmentation[0])
2539 if (any_lsda_needed)
2541 int size = size_of_encoded_value (lsda_encoding);
2543 if (lsda_encoding == DW_EH_PE_aligned)
2545 int offset = ( 4 /* Length */
2546 + 4 /* CIE offset */
2547 + 2 * size_of_encoded_value (fde_encoding)
2548 + 1 /* Augmentation size */ );
2549 int pad = -offset & (PTR_SIZE - 1);
2552 gcc_assert (size_of_uleb128 (size) == 1);
2555 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2557 if (fde->uses_eh_lsda)
2559 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2560 fde->funcdef_number);
2561 dw2_asm_output_encoded_addr_rtx (
2562 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2563 false, "Language Specific Data Area");
2567 if (lsda_encoding == DW_EH_PE_aligned)
2568 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2570 (size_of_encoded_value (lsda_encoding), 0,
2571 "Language Specific Data Area (none)");
2575 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2578 /* Loop through the Call Frame Instructions associated with
2580 fde->dw_fde_current_label = fde->dw_fde_begin;
2581 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2582 output_cfi (cfi, fde, for_eh);
2584 /* Pad the FDE out to an address sized boundary. */
2585 ASM_OUTPUT_ALIGN (asm_out_file,
2586 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2587 ASM_OUTPUT_LABEL (asm_out_file, l2);
2590 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2591 dw2_asm_output_data (4, 0, "End of Table");
2592 #ifdef MIPS_DEBUGGING_INFO
2593 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2594 get a value of 0. Putting .align 0 after the label fixes it. */
2595 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2598 /* Turn off app to make assembly quicker. */
2603 /* Output a marker (i.e. a label) for the beginning of a function, before
2607 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2608 const char *file ATTRIBUTE_UNUSED)
2610 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2614 current_function_func_begin_label = NULL;
2616 #ifdef TARGET_UNWIND_INFO
2617 /* ??? current_function_func_begin_label is also used by except.c
2618 for call-site information. We must emit this label if it might
2620 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2621 && ! dwarf2out_do_frame ())
2624 if (! dwarf2out_do_frame ())
2628 switch_to_section (function_section (current_function_decl));
2629 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2630 current_function_funcdef_no);
2631 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2632 current_function_funcdef_no);
2633 dup_label = xstrdup (label);
2634 current_function_func_begin_label = dup_label;
2636 #ifdef TARGET_UNWIND_INFO
2637 /* We can elide the fde allocation if we're not emitting debug info. */
2638 if (! dwarf2out_do_frame ())
2642 /* Expand the fde table if necessary. */
2643 if (fde_table_in_use == fde_table_allocated)
2645 fde_table_allocated += FDE_TABLE_INCREMENT;
2646 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
2647 memset (fde_table + fde_table_in_use, 0,
2648 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2651 /* Record the FDE associated with this function. */
2652 current_funcdef_fde = fde_table_in_use;
2654 /* Add the new FDE at the end of the fde_table. */
2655 fde = &fde_table[fde_table_in_use++];
2656 fde->decl = current_function_decl;
2657 fde->dw_fde_begin = dup_label;
2658 fde->dw_fde_current_label = dup_label;
2659 fde->dw_fde_hot_section_label = NULL;
2660 fde->dw_fde_hot_section_end_label = NULL;
2661 fde->dw_fde_unlikely_section_label = NULL;
2662 fde->dw_fde_unlikely_section_end_label = NULL;
2663 fde->dw_fde_switched_sections = false;
2664 fde->dw_fde_end = NULL;
2665 fde->dw_fde_cfi = NULL;
2666 fde->funcdef_number = current_function_funcdef_no;
2667 fde->nothrow = TREE_NOTHROW (current_function_decl);
2668 fde->uses_eh_lsda = crtl->uses_eh_lsda;
2669 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
2671 args_size = old_args_size = 0;
2673 /* We only want to output line number information for the genuine dwarf2
2674 prologue case, not the eh frame case. */
2675 #ifdef DWARF2_DEBUGGING_INFO
2677 dwarf2out_source_line (line, file);
2681 /* Output a marker (i.e. a label) for the absolute end of the generated code
2682 for a function definition. This gets called *after* the epilogue code has
2686 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2687 const char *file ATTRIBUTE_UNUSED)
2690 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2692 /* Output a label to mark the endpoint of the code generated for this
2694 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2695 current_function_funcdef_no);
2696 ASM_OUTPUT_LABEL (asm_out_file, label);
2697 fde = current_fde ();
2698 gcc_assert (fde != NULL);
2699 fde->dw_fde_end = xstrdup (label);
2703 dwarf2out_frame_init (void)
2705 /* Allocate the initial hunk of the fde_table. */
2706 fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT);
2707 fde_table_allocated = FDE_TABLE_INCREMENT;
2708 fde_table_in_use = 0;
2710 /* Generate the CFA instructions common to all FDE's. Do it now for the
2711 sake of lookup_cfa. */
2713 /* On entry, the Canonical Frame Address is at SP. */
2714 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2716 #ifdef DWARF2_UNWIND_INFO
2717 if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO)
2718 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2723 dwarf2out_frame_finish (void)
2725 /* Output call frame information. */
2726 if (DWARF2_FRAME_INFO)
2727 output_call_frame_info (0);
2729 #ifndef TARGET_UNWIND_INFO
2730 /* Output another copy for the unwinder. */
2731 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2732 output_call_frame_info (1);
2736 /* Note that the current function section is being used for code. */
2739 dwarf2out_note_section_used (void)
2741 section *sec = current_function_section ();
2742 if (sec == text_section)
2743 text_section_used = true;
2744 else if (sec == cold_text_section)
2745 cold_text_section_used = true;
2749 dwarf2out_switch_text_section (void)
2751 dw_fde_ref fde = current_fde ();
2753 gcc_assert (cfun && fde);
2755 fde->dw_fde_switched_sections = true;
2756 fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label;
2757 fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label;
2758 fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label;
2759 fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label;
2760 have_multiple_function_sections = true;
2762 /* Reset the current label on switching text sections, so that we
2763 don't attempt to advance_loc4 between labels in different sections. */
2764 fde->dw_fde_current_label = NULL;
2766 /* There is no need to mark used sections when not debugging. */
2767 if (cold_text_section != NULL)
2768 dwarf2out_note_section_used ();
2772 /* And now, the subset of the debugging information support code necessary
2773 for emitting location expressions. */
2775 /* Data about a single source file. */
2776 struct dwarf_file_data GTY(())
2778 const char * filename;
2782 /* We need some way to distinguish DW_OP_addr with a direct symbol
2783 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2784 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2787 typedef struct dw_val_struct *dw_val_ref;
2788 typedef struct die_struct *dw_die_ref;
2789 typedef const struct die_struct *const_dw_die_ref;
2790 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2791 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2793 /* Each DIE may have a series of attribute/value pairs. Values
2794 can take on several forms. The forms that are used in this
2795 implementation are listed below. */
2800 dw_val_class_offset,
2802 dw_val_class_loc_list,
2803 dw_val_class_range_list,
2805 dw_val_class_unsigned_const,
2806 dw_val_class_long_long,
2809 dw_val_class_die_ref,
2810 dw_val_class_fde_ref,
2811 dw_val_class_lbl_id,
2812 dw_val_class_lineptr,
2814 dw_val_class_macptr,
2818 /* Describe a double word constant value. */
2819 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2821 typedef struct dw_long_long_struct GTY(())
2828 /* Describe a floating point constant value, or a vector constant value. */
2830 typedef struct dw_vec_struct GTY(())
2832 unsigned char * GTY((length ("%h.length"))) array;
2838 /* The dw_val_node describes an attribute's value, as it is
2839 represented internally. */
2841 typedef struct dw_val_struct GTY(())
2843 enum dw_val_class val_class;
2844 union dw_val_struct_union
2846 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2847 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2848 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2849 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2850 HOST_WIDE_INT GTY ((default)) val_int;
2851 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2852 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2853 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2854 struct dw_val_die_union
2858 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2859 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2860 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2861 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2862 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2863 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
2865 GTY ((desc ("%1.val_class"))) v;
2869 /* Locations in memory are described using a sequence of stack machine
2872 typedef struct dw_loc_descr_struct GTY(())
2874 dw_loc_descr_ref dw_loc_next;
2875 enum dwarf_location_atom dw_loc_opc;
2876 dw_val_node dw_loc_oprnd1;
2877 dw_val_node dw_loc_oprnd2;
2882 /* Location lists are ranges + location descriptions for that range,
2883 so you can track variables that are in different places over
2884 their entire life. */
2885 typedef struct dw_loc_list_struct GTY(())
2887 dw_loc_list_ref dw_loc_next;
2888 const char *begin; /* Label for begin address of range */
2889 const char *end; /* Label for end address of range */
2890 char *ll_symbol; /* Label for beginning of location list.
2891 Only on head of list */
2892 const char *section; /* Section this loclist is relative to */
2893 dw_loc_descr_ref expr;
2896 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2898 static const char *dwarf_stack_op_name (unsigned);
2899 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2900 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2901 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2902 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2903 static unsigned long size_of_locs (dw_loc_descr_ref);
2904 static void output_loc_operands (dw_loc_descr_ref);
2905 static void output_loc_sequence (dw_loc_descr_ref);
2907 /* Convert a DWARF stack opcode into its string name. */
2910 dwarf_stack_op_name (unsigned int op)
2915 case INTERNAL_DW_OP_tls_addr:
2916 return "DW_OP_addr";
2918 return "DW_OP_deref";
2920 return "DW_OP_const1u";
2922 return "DW_OP_const1s";
2924 return "DW_OP_const2u";
2926 return "DW_OP_const2s";
2928 return "DW_OP_const4u";
2930 return "DW_OP_const4s";
2932 return "DW_OP_const8u";
2934 return "DW_OP_const8s";
2936 return "DW_OP_constu";
2938 return "DW_OP_consts";
2942 return "DW_OP_drop";
2944 return "DW_OP_over";
2946 return "DW_OP_pick";
2948 return "DW_OP_swap";
2952 return "DW_OP_xderef";
2960 return "DW_OP_minus";
2972 return "DW_OP_plus";
2973 case DW_OP_plus_uconst:
2974 return "DW_OP_plus_uconst";
2980 return "DW_OP_shra";
2998 return "DW_OP_skip";
3000 return "DW_OP_lit0";
3002 return "DW_OP_lit1";
3004 return "DW_OP_lit2";
3006 return "DW_OP_lit3";
3008 return "DW_OP_lit4";
3010 return "DW_OP_lit5";
3012 return "DW_OP_lit6";
3014 return "DW_OP_lit7";
3016 return "DW_OP_lit8";
3018 return "DW_OP_lit9";
3020 return "DW_OP_lit10";
3022 return "DW_OP_lit11";
3024 return "DW_OP_lit12";
3026 return "DW_OP_lit13";
3028 return "DW_OP_lit14";
3030 return "DW_OP_lit15";
3032 return "DW_OP_lit16";
3034 return "DW_OP_lit17";
3036 return "DW_OP_lit18";
3038 return "DW_OP_lit19";
3040 return "DW_OP_lit20";
3042 return "DW_OP_lit21";
3044 return "DW_OP_lit22";
3046 return "DW_OP_lit23";
3048 return "DW_OP_lit24";
3050 return "DW_OP_lit25";
3052 return "DW_OP_lit26";
3054 return "DW_OP_lit27";
3056 return "DW_OP_lit28";
3058 return "DW_OP_lit29";
3060 return "DW_OP_lit30";
3062 return "DW_OP_lit31";
3064 return "DW_OP_reg0";
3066 return "DW_OP_reg1";
3068 return "DW_OP_reg2";
3070 return "DW_OP_reg3";
3072 return "DW_OP_reg4";
3074 return "DW_OP_reg5";
3076 return "DW_OP_reg6";
3078 return "DW_OP_reg7";
3080 return "DW_OP_reg8";
3082 return "DW_OP_reg9";
3084 return "DW_OP_reg10";
3086 return "DW_OP_reg11";
3088 return "DW_OP_reg12";
3090 return "DW_OP_reg13";
3092 return "DW_OP_reg14";
3094 return "DW_OP_reg15";
3096 return "DW_OP_reg16";
3098 return "DW_OP_reg17";
3100 return "DW_OP_reg18";
3102 return "DW_OP_reg19";
3104 return "DW_OP_reg20";
3106 return "DW_OP_reg21";
3108 return "DW_OP_reg22";
3110 return "DW_OP_reg23";
3112 return "DW_OP_reg24";
3114 return "DW_OP_reg25";
3116 return "DW_OP_reg26";
3118 return "DW_OP_reg27";
3120 return "DW_OP_reg28";
3122 return "DW_OP_reg29";
3124 return "DW_OP_reg30";
3126 return "DW_OP_reg31";
3128 return "DW_OP_breg0";
3130 return "DW_OP_breg1";
3132 return "DW_OP_breg2";
3134 return "DW_OP_breg3";
3136 return "DW_OP_breg4";
3138 return "DW_OP_breg5";
3140 return "DW_OP_breg6";
3142 return "DW_OP_breg7";
3144 return "DW_OP_breg8";
3146 return "DW_OP_breg9";
3148 return "DW_OP_breg10";
3150 return "DW_OP_breg11";
3152 return "DW_OP_breg12";
3154 return "DW_OP_breg13";
3156 return "DW_OP_breg14";
3158 return "DW_OP_breg15";
3160 return "DW_OP_breg16";
3162 return "DW_OP_breg17";
3164 return "DW_OP_breg18";
3166 return "DW_OP_breg19";
3168 return "DW_OP_breg20";
3170 return "DW_OP_breg21";
3172 return "DW_OP_breg22";
3174 return "DW_OP_breg23";
3176 return "DW_OP_breg24";
3178 return "DW_OP_breg25";
3180 return "DW_OP_breg26";
3182 return "DW_OP_breg27";
3184 return "DW_OP_breg28";
3186 return "DW_OP_breg29";
3188 return "DW_OP_breg30";
3190 return "DW_OP_breg31";
3192 return "DW_OP_regx";
3194 return "DW_OP_fbreg";
3196 return "DW_OP_bregx";
3198 return "DW_OP_piece";
3199 case DW_OP_deref_size:
3200 return "DW_OP_deref_size";
3201 case DW_OP_xderef_size:
3202 return "DW_OP_xderef_size";
3205 case DW_OP_push_object_address:
3206 return "DW_OP_push_object_address";
3208 return "DW_OP_call2";
3210 return "DW_OP_call4";
3211 case DW_OP_call_ref:
3212 return "DW_OP_call_ref";
3213 case DW_OP_GNU_push_tls_address:
3214 return "DW_OP_GNU_push_tls_address";
3215 case DW_OP_GNU_uninit:
3216 return "DW_OP_GNU_uninit";
3218 return "OP_<unknown>";
3222 /* Return a pointer to a newly allocated location description. Location
3223 descriptions are simple expression terms that can be strung
3224 together to form more complicated location (address) descriptions. */
3226 static inline dw_loc_descr_ref
3227 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
3228 unsigned HOST_WIDE_INT oprnd2)
3230 dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node);
3232 descr->dw_loc_opc = op;
3233 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
3234 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
3235 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
3236 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
3241 /* Add a location description term to a location description expression. */
3244 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3246 dw_loc_descr_ref *d;
3248 /* Find the end of the chain. */
3249 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3255 /* Return the size of a location descriptor. */
3257 static unsigned long
3258 size_of_loc_descr (dw_loc_descr_ref loc)
3260 unsigned long size = 1;
3262 switch (loc->dw_loc_opc)
3265 case INTERNAL_DW_OP_tls_addr:
3266 size += DWARF2_ADDR_SIZE;
3285 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3288 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3293 case DW_OP_plus_uconst:
3294 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3332 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3335 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3338 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3341 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3342 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3345 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3347 case DW_OP_deref_size:
3348 case DW_OP_xderef_size:
3357 case DW_OP_call_ref:
3358 size += DWARF2_ADDR_SIZE;
3367 /* Return the size of a series of location descriptors. */
3369 static unsigned long
3370 size_of_locs (dw_loc_descr_ref loc)
3375 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3376 field, to avoid writing to a PCH file. */
3377 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3379 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
3381 size += size_of_loc_descr (l);
3386 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
3388 l->dw_loc_addr = size;
3389 size += size_of_loc_descr (l);
3395 /* Output location description stack opcode's operands (if any). */
3398 output_loc_operands (dw_loc_descr_ref loc)
3400 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3401 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3403 switch (loc->dw_loc_opc)
3405 #ifdef DWARF2_DEBUGGING_INFO
3407 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3411 dw2_asm_output_data (2, val1->v.val_int, NULL);
3415 dw2_asm_output_data (4, val1->v.val_int, NULL);
3419 gcc_assert (HOST_BITS_PER_LONG >= 64);
3420 dw2_asm_output_data (8, val1->v.val_int, NULL);
3427 gcc_assert (val1->val_class == dw_val_class_loc);
3428 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3430 dw2_asm_output_data (2, offset, NULL);
3443 /* We currently don't make any attempt to make sure these are
3444 aligned properly like we do for the main unwind info, so
3445 don't support emitting things larger than a byte if we're
3446 only doing unwinding. */
3451 dw2_asm_output_data (1, val1->v.val_int, NULL);
3454 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3457 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3460 dw2_asm_output_data (1, val1->v.val_int, NULL);
3462 case DW_OP_plus_uconst:
3463 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3497 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3500 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3503 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3506 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3507 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3510 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3512 case DW_OP_deref_size:
3513 case DW_OP_xderef_size:
3514 dw2_asm_output_data (1, val1->v.val_int, NULL);
3517 case INTERNAL_DW_OP_tls_addr:
3518 if (targetm.asm_out.output_dwarf_dtprel)
3520 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3523 fputc ('\n', asm_out_file);
3530 /* Other codes have no operands. */
3535 /* Output a sequence of location operations. */
3538 output_loc_sequence (dw_loc_descr_ref loc)
3540 for (; loc != NULL; loc = loc->dw_loc_next)
3542 /* Output the opcode. */
3543 dw2_asm_output_data (1, loc->dw_loc_opc,
3544 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3546 /* Output the operand(s) (if any). */
3547 output_loc_operands (loc);
3551 /* This routine will generate the correct assembly data for a location
3552 description based on a cfi entry with a complex address. */
3555 output_cfa_loc (dw_cfi_ref cfi)
3557 dw_loc_descr_ref loc;
3560 /* Output the size of the block. */
3561 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3562 size = size_of_locs (loc);
3563 dw2_asm_output_data_uleb128 (size, NULL);
3565 /* Now output the operations themselves. */
3566 output_loc_sequence (loc);
3569 /* This function builds a dwarf location descriptor sequence from a
3570 dw_cfa_location, adding the given OFFSET to the result of the
3573 static struct dw_loc_descr_struct *
3574 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
3576 struct dw_loc_descr_struct *head, *tmp;
3578 offset += cfa->offset;
3582 if (cfa->base_offset)
3585 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3587 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3589 else if (cfa->reg <= 31)
3590 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3592 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3594 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3595 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3596 add_loc_descr (&head, tmp);
3599 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
3600 add_loc_descr (&head, tmp);
3607 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3609 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3610 else if (cfa->reg <= 31)
3611 head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0);
3613 head = new_loc_descr (DW_OP_bregx, cfa->reg, offset);
3619 /* This function fills in aa dw_cfa_location structure from a dwarf location
3620 descriptor sequence. */
3623 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3625 struct dw_loc_descr_struct *ptr;
3627 cfa->base_offset = 0;
3631 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3633 enum dwarf_location_atom op = ptr->dw_loc_opc;
3669 cfa->reg = op - DW_OP_reg0;
3672 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3706 cfa->reg = op - DW_OP_breg0;
3707 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3710 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3711 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3716 case DW_OP_plus_uconst:
3717 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3720 internal_error ("DW_LOC_OP %s not implemented",
3721 dwarf_stack_op_name (ptr->dw_loc_opc));
3725 #endif /* .debug_frame support */
3727 /* And now, the support for symbolic debugging information. */
3728 #ifdef DWARF2_DEBUGGING_INFO
3730 /* .debug_str support. */
3731 static int output_indirect_string (void **, void *);
3733 static void dwarf2out_init (const char *);
3734 static void dwarf2out_finish (const char *);
3735 static void dwarf2out_define (unsigned int, const char *);
3736 static void dwarf2out_undef (unsigned int, const char *);
3737 static void dwarf2out_start_source_file (unsigned, const char *);
3738 static void dwarf2out_end_source_file (unsigned);
3739 static void dwarf2out_begin_block (unsigned, unsigned);
3740 static void dwarf2out_end_block (unsigned, unsigned);
3741 static bool dwarf2out_ignore_block (const_tree);
3742 static void dwarf2out_global_decl (tree);
3743 static void dwarf2out_type_decl (tree, int);
3744 static void dwarf2out_imported_module_or_decl (tree, tree);
3745 static void dwarf2out_abstract_function (tree);
3746 static void dwarf2out_var_location (rtx);
3747 static void dwarf2out_begin_function (tree);
3749 /* The debug hooks structure. */
3751 const struct gcc_debug_hooks dwarf2_debug_hooks =
3757 dwarf2out_start_source_file,
3758 dwarf2out_end_source_file,
3759 dwarf2out_begin_block,
3760 dwarf2out_end_block,
3761 dwarf2out_ignore_block,
3762 dwarf2out_source_line,
3763 dwarf2out_begin_prologue,
3764 debug_nothing_int_charstar, /* end_prologue */
3765 dwarf2out_end_epilogue,
3766 dwarf2out_begin_function,
3767 debug_nothing_int, /* end_function */
3768 dwarf2out_decl, /* function_decl */
3769 dwarf2out_global_decl,
3770 dwarf2out_type_decl, /* type_decl */
3771 dwarf2out_imported_module_or_decl,
3772 debug_nothing_tree, /* deferred_inline_function */
3773 /* The DWARF 2 backend tries to reduce debugging bloat by not
3774 emitting the abstract description of inline functions until
3775 something tries to reference them. */
3776 dwarf2out_abstract_function, /* outlining_inline_function */
3777 debug_nothing_rtx, /* label */
3778 debug_nothing_int, /* handle_pch */
3779 dwarf2out_var_location,
3780 dwarf2out_switch_text_section,
3781 1 /* start_end_main_source_file */
3785 /* NOTE: In the comments in this file, many references are made to
3786 "Debugging Information Entries". This term is abbreviated as `DIE'
3787 throughout the remainder of this file. */
3789 /* An internal representation of the DWARF output is built, and then
3790 walked to generate the DWARF debugging info. The walk of the internal
3791 representation is done after the entire program has been compiled.
3792 The types below are used to describe the internal representation. */
3794 /* Various DIE's use offsets relative to the beginning of the
3795 .debug_info section to refer to each other. */
3797 typedef long int dw_offset;
3799 /* Define typedefs here to avoid circular dependencies. */
3801 typedef struct dw_attr_struct *dw_attr_ref;
3802 typedef struct dw_line_info_struct *dw_line_info_ref;
3803 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3804 typedef struct pubname_struct *pubname_ref;
3805 typedef struct dw_ranges_struct *dw_ranges_ref;
3806 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
3808 /* Each entry in the line_info_table maintains the file and
3809 line number associated with the label generated for that
3810 entry. The label gives the PC value associated with
3811 the line number entry. */
3813 typedef struct dw_line_info_struct GTY(())
3815 unsigned long dw_file_num;
3816 unsigned long dw_line_num;
3820 /* Line information for functions in separate sections; each one gets its
3822 typedef struct dw_separate_line_info_struct GTY(())
3824 unsigned long dw_file_num;
3825 unsigned long dw_line_num;
3826 unsigned long function;
3828 dw_separate_line_info_entry;
3830 /* Each DIE attribute has a field specifying the attribute kind,
3831 a link to the next attribute in the chain, and an attribute value.
3832 Attributes are typically linked below the DIE they modify. */
3834 typedef struct dw_attr_struct GTY(())
3836 enum dwarf_attribute dw_attr;
3837 dw_val_node dw_attr_val;
3841 DEF_VEC_O(dw_attr_node);
3842 DEF_VEC_ALLOC_O(dw_attr_node,gc);
3844 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3845 The children of each node form a circular list linked by
3846 die_sib. die_child points to the node *before* the "first" child node. */
3848 typedef struct die_struct GTY((chain_circular ("%h.die_sib")))
3850 enum dwarf_tag die_tag;
3852 VEC(dw_attr_node,gc) * die_attr;
3853 dw_die_ref die_parent;
3854 dw_die_ref die_child;
3856 dw_die_ref die_definition; /* ref from a specification to its definition */
3857 dw_offset die_offset;
3858 unsigned long die_abbrev;
3860 /* Die is used and must not be pruned as unused. */
3861 int die_perennial_p;
3862 unsigned int decl_id;
3866 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3867 #define FOR_EACH_CHILD(die, c, expr) do { \
3868 c = die->die_child; \
3872 } while (c != die->die_child); \
3875 /* The pubname structure */
3877 typedef struct pubname_struct GTY(())
3884 DEF_VEC_O(pubname_entry);
3885 DEF_VEC_ALLOC_O(pubname_entry, gc);
3887 struct dw_ranges_struct GTY(())
3889 /* If this is positive, it's a block number, otherwise it's a
3890 bitwise-negated index into dw_ranges_by_label. */
3894 struct dw_ranges_by_label_struct GTY(())
3900 /* The limbo die list structure. */
3901 typedef struct limbo_die_struct GTY(())
3905 struct limbo_die_struct *next;
3909 /* How to start an assembler comment. */
3910 #ifndef ASM_COMMENT_START
3911 #define ASM_COMMENT_START ";#"
3914 /* Define a macro which returns nonzero for a TYPE_DECL which was
3915 implicitly generated for a tagged type.
3917 Note that unlike the gcc front end (which generates a NULL named
3918 TYPE_DECL node for each complete tagged type, each array type, and
3919 each function type node created) the g++ front end generates a
3920 _named_ TYPE_DECL node for each tagged type node created.
3921 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3922 generate a DW_TAG_typedef DIE for them. */
3924 #define TYPE_DECL_IS_STUB(decl) \
3925 (DECL_NAME (decl) == NULL_TREE \
3926 || (DECL_ARTIFICIAL (decl) \
3927 && is_tagged_type (TREE_TYPE (decl)) \
3928 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3929 /* This is necessary for stub decls that \
3930 appear in nested inline functions. */ \
3931 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3932 && (decl_ultimate_origin (decl) \
3933 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3935 /* Information concerning the compilation unit's programming
3936 language, and compiler version. */
3938 /* Fixed size portion of the DWARF compilation unit header. */
3939 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3940 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3942 /* Fixed size portion of public names info. */
3943 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3945 /* Fixed size portion of the address range info. */
3946 #define DWARF_ARANGES_HEADER_SIZE \
3947 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3948 DWARF2_ADDR_SIZE * 2) \
3949 - DWARF_INITIAL_LENGTH_SIZE)
3951 /* Size of padding portion in the address range info. It must be
3952 aligned to twice the pointer size. */
3953 #define DWARF_ARANGES_PAD_SIZE \
3954 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3955 DWARF2_ADDR_SIZE * 2) \
3956 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3958 /* Use assembler line directives if available. */
3959 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3960 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3961 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3963 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3967 /* Minimum line offset in a special line info. opcode.
3968 This value was chosen to give a reasonable range of values. */
3969 #define DWARF_LINE_BASE -10
3971 /* First special line opcode - leave room for the standard opcodes. */
3972 #define DWARF_LINE_OPCODE_BASE 10
3974 /* Range of line offsets in a special line info. opcode. */
3975 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3977 /* Flag that indicates the initial value of the is_stmt_start flag.
3978 In the present implementation, we do not mark any lines as
3979 the beginning of a source statement, because that information
3980 is not made available by the GCC front-end. */
3981 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3983 #ifdef DWARF2_DEBUGGING_INFO
3984 /* This location is used by calc_die_sizes() to keep track
3985 the offset of each DIE within the .debug_info section. */
3986 static unsigned long next_die_offset;
3989 /* Record the root of the DIE's built for the current compilation unit. */
3990 static GTY(()) dw_die_ref comp_unit_die;
3992 /* A list of DIEs with a NULL parent waiting to be relocated. */
3993 static GTY(()) limbo_die_node *limbo_die_list;
3995 /* Filenames referenced by this compilation unit. */
3996 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
3998 /* A hash table of references to DIE's that describe declarations.
3999 The key is a DECL_UID() which is a unique number identifying each decl. */
4000 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
4002 /* Node of the variable location list. */
4003 struct var_loc_node GTY ((chain_next ("%h.next")))
4005 rtx GTY (()) var_loc_note;
4006 const char * GTY (()) label;
4007 const char * GTY (()) section_label;
4008 struct var_loc_node * GTY (()) next;
4011 /* Variable location list. */
4012 struct var_loc_list_def GTY (())
4014 struct var_loc_node * GTY (()) first;
4016 /* Do not mark the last element of the chained list because
4017 it is marked through the chain. */
4018 struct var_loc_node * GTY ((skip ("%h"))) last;
4020 /* DECL_UID of the variable decl. */
4021 unsigned int decl_id;
4023 typedef struct var_loc_list_def var_loc_list;
4026 /* Table of decl location linked lists. */
4027 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
4029 /* A pointer to the base of a list of references to DIE's that
4030 are uniquely identified by their tag, presence/absence of
4031 children DIE's, and list of attribute/value pairs. */
4032 static GTY((length ("abbrev_die_table_allocated")))
4033 dw_die_ref *abbrev_die_table;
4035 /* Number of elements currently allocated for abbrev_die_table. */
4036 static GTY(()) unsigned abbrev_die_table_allocated;
4038 /* Number of elements in type_die_table currently in use. */
4039 static GTY(()) unsigned abbrev_die_table_in_use;
4041 /* Size (in elements) of increments by which we may expand the
4042 abbrev_die_table. */
4043 #define ABBREV_DIE_TABLE_INCREMENT 256
4045 /* A pointer to the base of a table that contains line information
4046 for each source code line in .text in the compilation unit. */
4047 static GTY((length ("line_info_table_allocated")))
4048 dw_line_info_ref line_info_table;
4050 /* Number of elements currently allocated for line_info_table. */
4051 static GTY(()) unsigned line_info_table_allocated;
4053 /* Number of elements in line_info_table currently in use. */
4054 static GTY(()) unsigned line_info_table_in_use;
4056 /* A pointer to the base of a table that contains line information
4057 for each source code line outside of .text in the compilation unit. */
4058 static GTY ((length ("separate_line_info_table_allocated")))
4059 dw_separate_line_info_ref separate_line_info_table;
4061 /* Number of elements currently allocated for separate_line_info_table. */
4062 static GTY(()) unsigned separate_line_info_table_allocated;
4064 /* Number of elements in separate_line_info_table currently in use. */
4065 static GTY(()) unsigned separate_line_info_table_in_use;
4067 /* Size (in elements) of increments by which we may expand the
4069 #define LINE_INFO_TABLE_INCREMENT 1024
4071 /* A pointer to the base of a table that contains a list of publicly
4072 accessible names. */
4073 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
4075 /* A pointer to the base of a table that contains a list of publicly
4076 accessible types. */
4077 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
4079 /* Array of dies for which we should generate .debug_arange info. */
4080 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
4082 /* Number of elements currently allocated for arange_table. */
4083 static GTY(()) unsigned arange_table_allocated;
4085 /* Number of elements in arange_table currently in use. */
4086 static GTY(()) unsigned arange_table_in_use;
4088 /* Size (in elements) of increments by which we may expand the
4090 #define ARANGE_TABLE_INCREMENT 64
4092 /* Array of dies for which we should generate .debug_ranges info. */
4093 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
4095 /* Number of elements currently allocated for ranges_table. */
4096 static GTY(()) unsigned ranges_table_allocated;
4098 /* Number of elements in ranges_table currently in use. */
4099 static GTY(()) unsigned ranges_table_in_use;
4101 /* Array of pairs of labels referenced in ranges_table. */
4102 static GTY ((length ("ranges_by_label_allocated")))
4103 dw_ranges_by_label_ref ranges_by_label;
4105 /* Number of elements currently allocated for ranges_by_label. */
4106 static GTY(()) unsigned ranges_by_label_allocated;
4108 /* Number of elements in ranges_by_label currently in use. */
4109 static GTY(()) unsigned ranges_by_label_in_use;
4111 /* Size (in elements) of increments by which we may expand the
4113 #define RANGES_TABLE_INCREMENT 64
4115 /* Whether we have location lists that need outputting */
4116 static GTY(()) bool have_location_lists;
4118 /* Unique label counter. */
4119 static GTY(()) unsigned int loclabel_num;
4121 #ifdef DWARF2_DEBUGGING_INFO
4122 /* Record whether the function being analyzed contains inlined functions. */
4123 static int current_function_has_inlines;
4125 #if 0 && defined (MIPS_DEBUGGING_INFO)
4126 static int comp_unit_has_inlines;
4129 /* The last file entry emitted by maybe_emit_file(). */
4130 static GTY(()) struct dwarf_file_data * last_emitted_file;
4132 /* Number of internal labels generated by gen_internal_sym(). */
4133 static GTY(()) int label_num;
4135 /* Cached result of previous call to lookup_filename. */
4136 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
4138 #ifdef DWARF2_DEBUGGING_INFO
4140 /* Offset from the "steady-state frame pointer" to the frame base,
4141 within the current function. */
4142 static HOST_WIDE_INT frame_pointer_fb_offset;
4144 /* Forward declarations for functions defined in this file. */
4146 static int is_pseudo_reg (const_rtx);
4147 static tree type_main_variant (tree);
4148 static int is_tagged_type (const_tree);
4149 static const char *dwarf_tag_name (unsigned);
4150 static const char *dwarf_attr_name (unsigned);
4151 static const char *dwarf_form_name (unsigned);
4152 static tree decl_ultimate_origin (const_tree);
4153 static tree block_ultimate_origin (const_tree);
4154 static tree decl_class_context (tree);
4155 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
4156 static inline enum dw_val_class AT_class (dw_attr_ref);
4157 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
4158 static inline unsigned AT_flag (dw_attr_ref);
4159 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
4160 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
4161 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
4162 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
4163 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
4165 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
4166 unsigned int, unsigned char *);
4167 static hashval_t debug_str_do_hash (const void *);
4168 static int debug_str_eq (const void *, const void *);
4169 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
4170 static inline const char *AT_string (dw_attr_ref);
4171 static int AT_string_form (dw_attr_ref);
4172 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
4173 static void add_AT_specification (dw_die_ref, dw_die_ref);
4174 static inline dw_die_ref AT_ref (dw_attr_ref);
4175 static inline int AT_ref_external (dw_attr_ref);
4176 static inline void set_AT_ref_external (dw_attr_ref, int);
4177 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
4178 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
4179 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
4180 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
4182 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
4183 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
4184 static inline rtx AT_addr (dw_attr_ref);
4185 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
4186 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
4187 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
4188 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
4189 unsigned HOST_WIDE_INT);
4190 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
4192 static inline const char *AT_lbl (dw_attr_ref);
4193 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
4194 static const char *get_AT_low_pc (dw_die_ref);
4195 static const char *get_AT_hi_pc (dw_die_ref);
4196 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
4197 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
4198 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
4199 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
4200 static bool is_c_family (void);
4201 static bool is_cxx (void);
4202 static bool is_java (void);
4203 static bool is_fortran (void);
4204 static bool is_ada (void);
4205 static void remove_AT (dw_die_ref, enum dwarf_attribute);
4206 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
4207 static void add_child_die (dw_die_ref, dw_die_ref);
4208 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
4209 static dw_die_ref lookup_type_die (tree);
4210 static void equate_type_number_to_die (tree, dw_die_ref);
4211 static hashval_t decl_die_table_hash (const void *);
4212 static int decl_die_table_eq (const void *, const void *);
4213 static dw_die_ref lookup_decl_die (tree);
4214 static hashval_t decl_loc_table_hash (const void *);
4215 static int decl_loc_table_eq (const void *, const void *);
4216 static var_loc_list *lookup_decl_loc (const_tree);
4217 static void equate_decl_number_to_die (tree, dw_die_ref);
4218 static void add_var_loc_to_decl (tree, struct var_loc_node *);
4219 static void print_spaces (FILE *);
4220 static void print_die (dw_die_ref, FILE *);
4221 static void print_dwarf_line_table (FILE *);
4222 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
4223 static dw_die_ref pop_compile_unit (dw_die_ref);
4224 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
4225 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
4226 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
4227 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
4228 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
4229 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
4230 static int same_die_p (dw_die_ref, dw_die_ref, int *);
4231 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
4232 static void compute_section_prefix (dw_die_ref);
4233 static int is_type_die (dw_die_ref);
4234 static int is_comdat_die (dw_die_ref);
4235 static int is_symbol_die (dw_die_ref);
4236 static void assign_symbol_names (dw_die_ref);
4237 static void break_out_includes (dw_die_ref);
4238 static hashval_t htab_cu_hash (const void *);
4239 static int htab_cu_eq (const void *, const void *);
4240 static void htab_cu_del (void *);
4241 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
4242 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
4243 static void add_sibling_attributes (dw_die_ref);
4244 static void build_abbrev_table (dw_die_ref);
4245 static void output_location_lists (dw_die_ref);
4246 static int constant_size (long unsigned);
4247 static unsigned long size_of_die (dw_die_ref);
4248 static void calc_die_sizes (dw_die_ref);
4249 static void mark_dies (dw_die_ref);
4250 static void unmark_dies (dw_die_ref);
4251 static void unmark_all_dies (dw_die_ref);
4252 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
4253 static unsigned long size_of_aranges (void);
4254 static enum dwarf_form value_format (dw_attr_ref);
4255 static void output_value_format (dw_attr_ref);
4256 static void output_abbrev_section (void);
4257 static void output_die_symbol (dw_die_ref);
4258 static void output_die (dw_die_ref);
4259 static void output_compilation_unit_header (void);
4260 static void output_comp_unit (dw_die_ref, int);
4261 static const char *dwarf2_name (tree, int);
4262 static void add_pubname (tree, dw_die_ref);
4263 static void add_pubname_string (const char *, dw_die_ref);
4264 static void add_pubtype (tree, dw_die_ref);
4265 static void output_pubnames (VEC (pubname_entry,gc) *);
4266 static void add_arange (tree, dw_die_ref);
4267 static void output_aranges (void);
4268 static unsigned int add_ranges_num (int);
4269 static unsigned int add_ranges (const_tree);
4270 static unsigned int add_ranges_by_labels (const char *, const char *);
4271 static void output_ranges (void);
4272 static void output_line_info (void);
4273 static void output_file_names (void);
4274 static dw_die_ref base_type_die (tree);
4275 static int is_base_type (tree);
4276 static bool is_subrange_type (const_tree);
4277 static dw_die_ref subrange_type_die (tree, dw_die_ref);
4278 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
4279 static int type_is_enum (const_tree);
4280 static unsigned int dbx_reg_number (const_rtx);
4281 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
4282 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
4283 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
4284 enum var_init_status);
4285 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
4286 enum var_init_status);
4287 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4288 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
4289 enum var_init_status);
4290 static int is_based_loc (const_rtx);
4291 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode,
4292 enum var_init_status);
4293 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
4294 enum var_init_status);
4295 static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status);
4296 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
4297 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
4298 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
4299 static tree field_type (const_tree);
4300 static unsigned int simple_type_align_in_bits (const_tree);
4301 static unsigned int simple_decl_align_in_bits (const_tree);
4302 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
4303 static HOST_WIDE_INT field_byte_offset (const_tree);
4304 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
4306 static void add_data_member_location_attribute (dw_die_ref, tree);
4307 static void add_const_value_attribute (dw_die_ref, rtx);
4308 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4309 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4310 static void insert_float (const_rtx, unsigned char *);
4311 static rtx rtl_for_decl_location (tree);
4312 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4313 enum dwarf_attribute);
4314 static void tree_add_const_value_attribute (dw_die_ref, tree);
4315 static void add_name_attribute (dw_die_ref, const char *);
4316 static void add_comp_dir_attribute (dw_die_ref);
4317 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4318 static void add_subscript_info (dw_die_ref, tree);
4319 static void add_byte_size_attribute (dw_die_ref, tree);
4320 static void add_bit_offset_attribute (dw_die_ref, tree);
4321 static void add_bit_size_attribute (dw_die_ref, tree);
4322 static void add_prototyped_attribute (dw_die_ref, tree);
4323 static void add_abstract_origin_attribute (dw_die_ref, tree);
4324 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4325 static void add_src_coords_attributes (dw_die_ref, tree);
4326 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4327 static void push_decl_scope (tree);
4328 static void pop_decl_scope (void);
4329 static dw_die_ref scope_die_for (tree, dw_die_ref);
4330 static inline int local_scope_p (dw_die_ref);
4331 static inline int class_or_namespace_scope_p (dw_die_ref);
4332 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4333 static void add_calling_convention_attribute (dw_die_ref, tree);
4334 static const char *type_tag (const_tree);
4335 static tree member_declared_type (const_tree);
4337 static const char *decl_start_label (tree);
4339 static void gen_array_type_die (tree, dw_die_ref);
4340 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
4342 static void gen_entry_point_die (tree, dw_die_ref);
4344 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4345 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4346 static void gen_inlined_union_type_die (tree, dw_die_ref);
4347 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4348 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4349 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4350 static void gen_formal_types_die (tree, dw_die_ref);
4351 static void gen_subprogram_die (tree, dw_die_ref);
4352 static void gen_variable_die (tree, dw_die_ref);
4353 static void gen_label_die (tree, dw_die_ref);
4354 static void gen_lexical_block_die (tree, dw_die_ref, int);
4355 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4356 static void gen_field_die (tree, dw_die_ref);
4357 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4358 static dw_die_ref gen_compile_unit_die (const char *);
4359 static void gen_inheritance_die (tree, tree, dw_die_ref);
4360 static void gen_member_die (tree, dw_die_ref);
4361 static void gen_struct_or_union_type_die (tree, dw_die_ref,
4362 enum debug_info_usage);
4363 static void gen_subroutine_type_die (tree, dw_die_ref);
4364 static void gen_typedef_die (tree, dw_die_ref);
4365 static void gen_type_die (tree, dw_die_ref);
4366 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4367 static void gen_block_die (tree, dw_die_ref, int);
4368 static void decls_for_scope (tree, dw_die_ref, int);
4369 static int is_redundant_typedef (const_tree);
4370 static void gen_namespace_die (tree);
4371 static void gen_decl_die (tree, dw_die_ref);
4372 static dw_die_ref force_decl_die (tree);
4373 static dw_die_ref force_type_die (tree);
4374 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4375 static void declare_in_namespace (tree, dw_die_ref);
4376 static struct dwarf_file_data * lookup_filename (const char *);
4377 static void retry_incomplete_types (void);
4378 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4379 static void splice_child_die (dw_die_ref, dw_die_ref);
4380 static int file_info_cmp (const void *, const void *);
4381 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4382 const char *, const char *, unsigned);
4383 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4384 const char *, const char *,
4386 static void output_loc_list (dw_loc_list_ref);
4387 static char *gen_internal_sym (const char *);
4389 static void prune_unmark_dies (dw_die_ref);
4390 static void prune_unused_types_mark (dw_die_ref, int);
4391 static void prune_unused_types_walk (dw_die_ref);
4392 static void prune_unused_types_walk_attribs (dw_die_ref);
4393 static void prune_unused_types_prune (dw_die_ref);
4394 static void prune_unused_types (void);
4395 static int maybe_emit_file (struct dwarf_file_data *fd);
4397 /* Section names used to hold DWARF debugging information. */
4398 #ifndef DEBUG_INFO_SECTION
4399 #define DEBUG_INFO_SECTION ".debug_info"
4401 #ifndef DEBUG_ABBREV_SECTION
4402 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4404 #ifndef DEBUG_ARANGES_SECTION
4405 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4407 #ifndef DEBUG_MACINFO_SECTION
4408 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4410 #ifndef DEBUG_LINE_SECTION
4411 #define DEBUG_LINE_SECTION ".debug_line"
4413 #ifndef DEBUG_LOC_SECTION
4414 #define DEBUG_LOC_SECTION ".debug_loc"
4416 #ifndef DEBUG_PUBNAMES_SECTION
4417 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4419 #ifndef DEBUG_STR_SECTION
4420 #define DEBUG_STR_SECTION ".debug_str"
4422 #ifndef DEBUG_RANGES_SECTION
4423 #define DEBUG_RANGES_SECTION ".debug_ranges"
4426 /* Standard ELF section names for compiled code and data. */
4427 #ifndef TEXT_SECTION_NAME
4428 #define TEXT_SECTION_NAME ".text"
4431 /* Section flags for .debug_str section. */
4432 #define DEBUG_STR_SECTION_FLAGS \
4433 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4434 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4437 /* Labels we insert at beginning sections we can reference instead of
4438 the section names themselves. */
4440 #ifndef TEXT_SECTION_LABEL
4441 #define TEXT_SECTION_LABEL "Ltext"
4443 #ifndef COLD_TEXT_SECTION_LABEL
4444 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4446 #ifndef DEBUG_LINE_SECTION_LABEL
4447 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4449 #ifndef DEBUG_INFO_SECTION_LABEL
4450 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4452 #ifndef DEBUG_ABBREV_SECTION_LABEL
4453 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4455 #ifndef DEBUG_LOC_SECTION_LABEL
4456 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4458 #ifndef DEBUG_RANGES_SECTION_LABEL
4459 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4461 #ifndef DEBUG_MACINFO_SECTION_LABEL
4462 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4465 /* Definitions of defaults for formats and names of various special
4466 (artificial) labels which may be generated within this file (when the -g
4467 options is used and DWARF2_DEBUGGING_INFO is in effect.
4468 If necessary, these may be overridden from within the tm.h file, but
4469 typically, overriding these defaults is unnecessary. */
4471 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4472 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4473 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4474 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4475 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4476 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4477 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4478 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4479 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4480 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4482 #ifndef TEXT_END_LABEL
4483 #define TEXT_END_LABEL "Letext"
4485 #ifndef COLD_END_LABEL
4486 #define COLD_END_LABEL "Letext_cold"
4488 #ifndef BLOCK_BEGIN_LABEL
4489 #define BLOCK_BEGIN_LABEL "LBB"
4491 #ifndef BLOCK_END_LABEL
4492 #define BLOCK_END_LABEL "LBE"
4494 #ifndef LINE_CODE_LABEL
4495 #define LINE_CODE_LABEL "LM"
4497 #ifndef SEPARATE_LINE_CODE_LABEL
4498 #define SEPARATE_LINE_CODE_LABEL "LSM"
4502 /* We allow a language front-end to designate a function that is to be
4503 called to "demangle" any name before it is put into a DIE. */
4505 static const char *(*demangle_name_func) (const char *);
4508 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4510 demangle_name_func = func;
4513 /* Test if rtl node points to a pseudo register. */
4516 is_pseudo_reg (const_rtx rtl)
4518 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4519 || (GET_CODE (rtl) == SUBREG
4520 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4523 /* Return a reference to a type, with its const and volatile qualifiers
4527 type_main_variant (tree type)
4529 type = TYPE_MAIN_VARIANT (type);
4531 /* ??? There really should be only one main variant among any group of
4532 variants of a given type (and all of the MAIN_VARIANT values for all
4533 members of the group should point to that one type) but sometimes the C
4534 front-end messes this up for array types, so we work around that bug
4536 if (TREE_CODE (type) == ARRAY_TYPE)
4537 while (type != TYPE_MAIN_VARIANT (type))
4538 type = TYPE_MAIN_VARIANT (type);
4543 /* Return nonzero if the given type node represents a tagged type. */
4546 is_tagged_type (const_tree type)
4548 enum tree_code code = TREE_CODE (type);
4550 return (code == RECORD_TYPE || code == UNION_TYPE
4551 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4554 /* Convert a DIE tag into its string name. */
4557 dwarf_tag_name (unsigned int tag)
4561 case DW_TAG_padding:
4562 return "DW_TAG_padding";
4563 case DW_TAG_array_type:
4564 return "DW_TAG_array_type";
4565 case DW_TAG_class_type:
4566 return "DW_TAG_class_type";
4567 case DW_TAG_entry_point:
4568 return "DW_TAG_entry_point";
4569 case DW_TAG_enumeration_type:
4570 return "DW_TAG_enumeration_type";
4571 case DW_TAG_formal_parameter:
4572 return "DW_TAG_formal_parameter";
4573 case DW_TAG_imported_declaration:
4574 return "DW_TAG_imported_declaration";
4576 return "DW_TAG_label";
4577 case DW_TAG_lexical_block:
4578 return "DW_TAG_lexical_block";
4580 return "DW_TAG_member";
4581 case DW_TAG_pointer_type:
4582 return "DW_TAG_pointer_type";
4583 case DW_TAG_reference_type:
4584 return "DW_TAG_reference_type";
4585 case DW_TAG_compile_unit:
4586 return "DW_TAG_compile_unit";
4587 case DW_TAG_string_type:
4588 return "DW_TAG_string_type";
4589 case DW_TAG_structure_type:
4590 return "DW_TAG_structure_type";
4591 case DW_TAG_subroutine_type:
4592 return "DW_TAG_subroutine_type";
4593 case DW_TAG_typedef:
4594 return "DW_TAG_typedef";
4595 case DW_TAG_union_type:
4596 return "DW_TAG_union_type";
4597 case DW_TAG_unspecified_parameters:
4598 return "DW_TAG_unspecified_parameters";
4599 case DW_TAG_variant:
4600 return "DW_TAG_variant";
4601 case DW_TAG_common_block:
4602 return "DW_TAG_common_block";
4603 case DW_TAG_common_inclusion:
4604 return "DW_TAG_common_inclusion";
4605 case DW_TAG_inheritance:
4606 return "DW_TAG_inheritance";
4607 case DW_TAG_inlined_subroutine:
4608 return "DW_TAG_inlined_subroutine";
4610 return "DW_TAG_module";
4611 case DW_TAG_ptr_to_member_type:
4612 return "DW_TAG_ptr_to_member_type";
4613 case DW_TAG_set_type:
4614 return "DW_TAG_set_type";
4615 case DW_TAG_subrange_type:
4616 return "DW_TAG_subrange_type";
4617 case DW_TAG_with_stmt:
4618 return "DW_TAG_with_stmt";
4619 case DW_TAG_access_declaration:
4620 return "DW_TAG_access_declaration";
4621 case DW_TAG_base_type:
4622 return "DW_TAG_base_type";
4623 case DW_TAG_catch_block:
4624 return "DW_TAG_catch_block";
4625 case DW_TAG_const_type:
4626 return "DW_TAG_const_type";
4627 case DW_TAG_constant:
4628 return "DW_TAG_constant";
4629 case DW_TAG_enumerator:
4630 return "DW_TAG_enumerator";
4631 case DW_TAG_file_type:
4632 return "DW_TAG_file_type";
4634 return "DW_TAG_friend";
4635 case DW_TAG_namelist:
4636 return "DW_TAG_namelist";
4637 case DW_TAG_namelist_item:
4638 return "DW_TAG_namelist_item";
4639 case DW_TAG_packed_type:
4640 return "DW_TAG_packed_type";
4641 case DW_TAG_subprogram:
4642 return "DW_TAG_subprogram";
4643 case DW_TAG_template_type_param:
4644 return "DW_TAG_template_type_param";
4645 case DW_TAG_template_value_param:
4646 return "DW_TAG_template_value_param";
4647 case DW_TAG_thrown_type:
4648 return "DW_TAG_thrown_type";
4649 case DW_TAG_try_block:
4650 return "DW_TAG_try_block";
4651 case DW_TAG_variant_part:
4652 return "DW_TAG_variant_part";
4653 case DW_TAG_variable:
4654 return "DW_TAG_variable";
4655 case DW_TAG_volatile_type:
4656 return "DW_TAG_volatile_type";
4657 case DW_TAG_dwarf_procedure:
4658 return "DW_TAG_dwarf_procedure";
4659 case DW_TAG_restrict_type:
4660 return "DW_TAG_restrict_type";
4661 case DW_TAG_interface_type:
4662 return "DW_TAG_interface_type";
4663 case DW_TAG_namespace:
4664 return "DW_TAG_namespace";
4665 case DW_TAG_imported_module:
4666 return "DW_TAG_imported_module";
4667 case DW_TAG_unspecified_type:
4668 return "DW_TAG_unspecified_type";
4669 case DW_TAG_partial_unit:
4670 return "DW_TAG_partial_unit";
4671 case DW_TAG_imported_unit:
4672 return "DW_TAG_imported_unit";
4673 case DW_TAG_condition:
4674 return "DW_TAG_condition";
4675 case DW_TAG_shared_type:
4676 return "DW_TAG_shared_type";
4677 case DW_TAG_MIPS_loop:
4678 return "DW_TAG_MIPS_loop";
4679 case DW_TAG_format_label:
4680 return "DW_TAG_format_label";
4681 case DW_TAG_function_template:
4682 return "DW_TAG_function_template";
4683 case DW_TAG_class_template:
4684 return "DW_TAG_class_template";
4685 case DW_TAG_GNU_BINCL:
4686 return "DW_TAG_GNU_BINCL";
4687 case DW_TAG_GNU_EINCL:
4688 return "DW_TAG_GNU_EINCL";
4690 return "DW_TAG_<unknown>";
4694 /* Convert a DWARF attribute code into its string name. */
4697 dwarf_attr_name (unsigned int attr)
4702 return "DW_AT_sibling";
4703 case DW_AT_location:
4704 return "DW_AT_location";
4706 return "DW_AT_name";
4707 case DW_AT_ordering:
4708 return "DW_AT_ordering";
4709 case DW_AT_subscr_data:
4710 return "DW_AT_subscr_data";
4711 case DW_AT_byte_size:
4712 return "DW_AT_byte_size";
4713 case DW_AT_bit_offset:
4714 return "DW_AT_bit_offset";
4715 case DW_AT_bit_size:
4716 return "DW_AT_bit_size";
4717 case DW_AT_element_list:
4718 return "DW_AT_element_list";
4719 case DW_AT_stmt_list:
4720 return "DW_AT_stmt_list";
4722 return "DW_AT_low_pc";
4724 return "DW_AT_high_pc";
4725 case DW_AT_language:
4726 return "DW_AT_language";
4728 return "DW_AT_member";
4730 return "DW_AT_discr";
4731 case DW_AT_discr_value:
4732 return "DW_AT_discr_value";
4733 case DW_AT_visibility:
4734 return "DW_AT_visibility";
4736 return "DW_AT_import";
4737 case DW_AT_string_length:
4738 return "DW_AT_string_length";
4739 case DW_AT_common_reference:
4740 return "DW_AT_common_reference";
4741 case DW_AT_comp_dir:
4742 return "DW_AT_comp_dir";
4743 case DW_AT_const_value:
4744 return "DW_AT_const_value";
4745 case DW_AT_containing_type:
4746 return "DW_AT_containing_type";
4747 case DW_AT_default_value:
4748 return "DW_AT_default_value";
4750 return "DW_AT_inline";
4751 case DW_AT_is_optional:
4752 return "DW_AT_is_optional";
4753 case DW_AT_lower_bound:
4754 return "DW_AT_lower_bound";
4755 case DW_AT_producer:
4756 return "DW_AT_producer";
4757 case DW_AT_prototyped:
4758 return "DW_AT_prototyped";
4759 case DW_AT_return_addr:
4760 return "DW_AT_return_addr";
4761 case DW_AT_start_scope:
4762 return "DW_AT_start_scope";
4763 case DW_AT_bit_stride:
4764 return "DW_AT_bit_stride";
4765 case DW_AT_upper_bound:
4766 return "DW_AT_upper_bound";
4767 case DW_AT_abstract_origin:
4768 return "DW_AT_abstract_origin";
4769 case DW_AT_accessibility:
4770 return "DW_AT_accessibility";
4771 case DW_AT_address_class:
4772 return "DW_AT_address_class";
4773 case DW_AT_artificial:
4774 return "DW_AT_artificial";
4775 case DW_AT_base_types:
4776 return "DW_AT_base_types";
4777 case DW_AT_calling_convention:
4778 return "DW_AT_calling_convention";
4780 return "DW_AT_count";
4781 case DW_AT_data_member_location:
4782 return "DW_AT_data_member_location";
4783 case DW_AT_decl_column:
4784 return "DW_AT_decl_column";
4785 case DW_AT_decl_file:
4786 return "DW_AT_decl_file";
4787 case DW_AT_decl_line:
4788 return "DW_AT_decl_line";
4789 case DW_AT_declaration:
4790 return "DW_AT_declaration";
4791 case DW_AT_discr_list:
4792 return "DW_AT_discr_list";
4793 case DW_AT_encoding:
4794 return "DW_AT_encoding";
4795 case DW_AT_external:
4796 return "DW_AT_external";
4797 case DW_AT_frame_base:
4798 return "DW_AT_frame_base";
4800 return "DW_AT_friend";
4801 case DW_AT_identifier_case:
4802 return "DW_AT_identifier_case";
4803 case DW_AT_macro_info:
4804 return "DW_AT_macro_info";
4805 case DW_AT_namelist_items:
4806 return "DW_AT_namelist_items";
4807 case DW_AT_priority:
4808 return "DW_AT_priority";
4810 return "DW_AT_segment";
4811 case DW_AT_specification:
4812 return "DW_AT_specification";
4813 case DW_AT_static_link:
4814 return "DW_AT_static_link";
4816 return "DW_AT_type";
4817 case DW_AT_use_location:
4818 return "DW_AT_use_location";
4819 case DW_AT_variable_parameter:
4820 return "DW_AT_variable_parameter";
4821 case DW_AT_virtuality:
4822 return "DW_AT_virtuality";
4823 case DW_AT_vtable_elem_location:
4824 return "DW_AT_vtable_elem_location";
4826 case DW_AT_allocated:
4827 return "DW_AT_allocated";
4828 case DW_AT_associated:
4829 return "DW_AT_associated";
4830 case DW_AT_data_location:
4831 return "DW_AT_data_location";
4832 case DW_AT_byte_stride:
4833 return "DW_AT_byte_stride";
4834 case DW_AT_entry_pc:
4835 return "DW_AT_entry_pc";
4836 case DW_AT_use_UTF8:
4837 return "DW_AT_use_UTF8";
4838 case DW_AT_extension:
4839 return "DW_AT_extension";
4841 return "DW_AT_ranges";
4842 case DW_AT_trampoline:
4843 return "DW_AT_trampoline";
4844 case DW_AT_call_column:
4845 return "DW_AT_call_column";
4846 case DW_AT_call_file:
4847 return "DW_AT_call_file";
4848 case DW_AT_call_line:
4849 return "DW_AT_call_line";
4851 case DW_AT_MIPS_fde:
4852 return "DW_AT_MIPS_fde";
4853 case DW_AT_MIPS_loop_begin:
4854 return "DW_AT_MIPS_loop_begin";
4855 case DW_AT_MIPS_tail_loop_begin:
4856 return "DW_AT_MIPS_tail_loop_begin";
4857 case DW_AT_MIPS_epilog_begin:
4858 return "DW_AT_MIPS_epilog_begin";
4859 case DW_AT_MIPS_loop_unroll_factor:
4860 return "DW_AT_MIPS_loop_unroll_factor";
4861 case DW_AT_MIPS_software_pipeline_depth:
4862 return "DW_AT_MIPS_software_pipeline_depth";
4863 case DW_AT_MIPS_linkage_name:
4864 return "DW_AT_MIPS_linkage_name";
4865 case DW_AT_MIPS_stride:
4866 return "DW_AT_MIPS_stride";
4867 case DW_AT_MIPS_abstract_name:
4868 return "DW_AT_MIPS_abstract_name";
4869 case DW_AT_MIPS_clone_origin:
4870 return "DW_AT_MIPS_clone_origin";
4871 case DW_AT_MIPS_has_inlines:
4872 return "DW_AT_MIPS_has_inlines";
4874 case DW_AT_sf_names:
4875 return "DW_AT_sf_names";
4876 case DW_AT_src_info:
4877 return "DW_AT_src_info";
4878 case DW_AT_mac_info:
4879 return "DW_AT_mac_info";
4880 case DW_AT_src_coords:
4881 return "DW_AT_src_coords";
4882 case DW_AT_body_begin:
4883 return "DW_AT_body_begin";
4884 case DW_AT_body_end:
4885 return "DW_AT_body_end";
4886 case DW_AT_GNU_vector:
4887 return "DW_AT_GNU_vector";
4889 case DW_AT_VMS_rtnbeg_pd_address:
4890 return "DW_AT_VMS_rtnbeg_pd_address";
4893 return "DW_AT_<unknown>";
4897 /* Convert a DWARF value form code into its string name. */
4900 dwarf_form_name (unsigned int form)
4905 return "DW_FORM_addr";
4906 case DW_FORM_block2:
4907 return "DW_FORM_block2";
4908 case DW_FORM_block4:
4909 return "DW_FORM_block4";
4911 return "DW_FORM_data2";
4913 return "DW_FORM_data4";
4915 return "DW_FORM_data8";
4916 case DW_FORM_string:
4917 return "DW_FORM_string";
4919 return "DW_FORM_block";
4920 case DW_FORM_block1:
4921 return "DW_FORM_block1";
4923 return "DW_FORM_data1";
4925 return "DW_FORM_flag";
4927 return "DW_FORM_sdata";
4929 return "DW_FORM_strp";
4931 return "DW_FORM_udata";
4932 case DW_FORM_ref_addr:
4933 return "DW_FORM_ref_addr";
4935 return "DW_FORM_ref1";
4937 return "DW_FORM_ref2";
4939 return "DW_FORM_ref4";
4941 return "DW_FORM_ref8";
4942 case DW_FORM_ref_udata:
4943 return "DW_FORM_ref_udata";
4944 case DW_FORM_indirect:
4945 return "DW_FORM_indirect";
4947 return "DW_FORM_<unknown>";
4951 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4952 instance of an inlined instance of a decl which is local to an inline
4953 function, so we have to trace all of the way back through the origin chain
4954 to find out what sort of node actually served as the original seed for the
4958 decl_ultimate_origin (const_tree decl)
4960 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4963 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4964 nodes in the function to point to themselves; ignore that if
4965 we're trying to output the abstract instance of this function. */
4966 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4969 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4970 most distant ancestor, this should never happen. */
4971 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4973 return DECL_ABSTRACT_ORIGIN (decl);
4976 /* Determine the "ultimate origin" of a block. The block may be an inlined
4977 instance of an inlined instance of a block which is local to an inline
4978 function, so we have to trace all of the way back through the origin chain
4979 to find out what sort of node actually served as the original seed for the
4983 block_ultimate_origin (const_tree block)
4985 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4987 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4988 nodes in the function to point to themselves; ignore that if
4989 we're trying to output the abstract instance of this function. */
4990 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4993 if (immediate_origin == NULL_TREE)
4998 tree lookahead = immediate_origin;
5002 ret_val = lookahead;
5003 lookahead = (TREE_CODE (ret_val) == BLOCK
5004 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
5006 while (lookahead != NULL && lookahead != ret_val);
5008 /* The block's abstract origin chain may not be the *ultimate* origin of
5009 the block. It could lead to a DECL that has an abstract origin set.
5010 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5011 will give us if it has one). Note that DECL's abstract origins are
5012 supposed to be the most distant ancestor (or so decl_ultimate_origin
5013 claims), so we don't need to loop following the DECL origins. */
5014 if (DECL_P (ret_val))
5015 return DECL_ORIGIN (ret_val);
5021 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5022 of a virtual function may refer to a base class, so we check the 'this'
5026 decl_class_context (tree decl)
5028 tree context = NULL_TREE;
5030 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
5031 context = DECL_CONTEXT (decl);
5033 context = TYPE_MAIN_VARIANT
5034 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
5036 if (context && !TYPE_P (context))
5037 context = NULL_TREE;
5042 /* Add an attribute/value pair to a DIE. */
5045 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
5047 /* Maybe this should be an assert? */
5051 if (die->die_attr == NULL)
5052 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
5053 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
5056 static inline enum dw_val_class
5057 AT_class (dw_attr_ref a)
5059 return a->dw_attr_val.val_class;
5062 /* Add a flag value attribute to a DIE. */
5065 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
5069 attr.dw_attr = attr_kind;
5070 attr.dw_attr_val.val_class = dw_val_class_flag;
5071 attr.dw_attr_val.v.val_flag = flag;
5072 add_dwarf_attr (die, &attr);
5075 static inline unsigned
5076 AT_flag (dw_attr_ref a)
5078 gcc_assert (a && AT_class (a) == dw_val_class_flag);
5079 return a->dw_attr_val.v.val_flag;
5082 /* Add a signed integer attribute value to a DIE. */
5085 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
5089 attr.dw_attr = attr_kind;
5090 attr.dw_attr_val.val_class = dw_val_class_const;
5091 attr.dw_attr_val.v.val_int = int_val;
5092 add_dwarf_attr (die, &attr);
5095 static inline HOST_WIDE_INT
5096 AT_int (dw_attr_ref a)
5098 gcc_assert (a && AT_class (a) == dw_val_class_const);
5099 return a->dw_attr_val.v.val_int;
5102 /* Add an unsigned integer attribute value to a DIE. */
5105 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
5106 unsigned HOST_WIDE_INT unsigned_val)
5110 attr.dw_attr = attr_kind;
5111 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
5112 attr.dw_attr_val.v.val_unsigned = unsigned_val;
5113 add_dwarf_attr (die, &attr);
5116 static inline unsigned HOST_WIDE_INT
5117 AT_unsigned (dw_attr_ref a)
5119 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
5120 return a->dw_attr_val.v.val_unsigned;
5123 /* Add an unsigned double integer attribute value to a DIE. */
5126 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
5127 long unsigned int val_hi, long unsigned int val_low)
5131 attr.dw_attr = attr_kind;
5132 attr.dw_attr_val.val_class = dw_val_class_long_long;
5133 attr.dw_attr_val.v.val_long_long.hi = val_hi;
5134 attr.dw_attr_val.v.val_long_long.low = val_low;
5135 add_dwarf_attr (die, &attr);
5138 /* Add a floating point attribute value to a DIE and return it. */
5141 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
5142 unsigned int length, unsigned int elt_size, unsigned char *array)
5146 attr.dw_attr = attr_kind;
5147 attr.dw_attr_val.val_class = dw_val_class_vec;
5148 attr.dw_attr_val.v.val_vec.length = length;
5149 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
5150 attr.dw_attr_val.v.val_vec.array = array;
5151 add_dwarf_attr (die, &attr);
5154 /* Hash and equality functions for debug_str_hash. */
5157 debug_str_do_hash (const void *x)
5159 return htab_hash_string (((const struct indirect_string_node *)x)->str);
5163 debug_str_eq (const void *x1, const void *x2)
5165 return strcmp ((((const struct indirect_string_node *)x1)->str),
5166 (const char *)x2) == 0;
5169 /* Add a string attribute value to a DIE. */
5172 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
5175 struct indirect_string_node *node;
5178 if (! debug_str_hash)
5179 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
5180 debug_str_eq, NULL);
5182 slot = htab_find_slot_with_hash (debug_str_hash, str,
5183 htab_hash_string (str), INSERT);
5186 node = (struct indirect_string_node *)
5187 ggc_alloc_cleared (sizeof (struct indirect_string_node));
5188 node->str = ggc_strdup (str);
5192 node = (struct indirect_string_node *) *slot;
5196 attr.dw_attr = attr_kind;
5197 attr.dw_attr_val.val_class = dw_val_class_str;
5198 attr.dw_attr_val.v.val_str = node;
5199 add_dwarf_attr (die, &attr);
5202 static inline const char *
5203 AT_string (dw_attr_ref a)
5205 gcc_assert (a && AT_class (a) == dw_val_class_str);
5206 return a->dw_attr_val.v.val_str->str;
5209 /* Find out whether a string should be output inline in DIE
5210 or out-of-line in .debug_str section. */
5213 AT_string_form (dw_attr_ref a)
5215 struct indirect_string_node *node;
5219 gcc_assert (a && AT_class (a) == dw_val_class_str);
5221 node = a->dw_attr_val.v.val_str;
5225 len = strlen (node->str) + 1;
5227 /* If the string is shorter or equal to the size of the reference, it is
5228 always better to put it inline. */
5229 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
5230 return node->form = DW_FORM_string;
5232 /* If we cannot expect the linker to merge strings in .debug_str
5233 section, only put it into .debug_str if it is worth even in this
5235 if ((debug_str_section->common.flags & SECTION_MERGE) == 0
5236 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
5237 return node->form = DW_FORM_string;
5239 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
5240 ++dw2_string_counter;
5241 node->label = xstrdup (label);
5243 return node->form = DW_FORM_strp;
5246 /* Add a DIE reference attribute value to a DIE. */
5249 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
5253 attr.dw_attr = attr_kind;
5254 attr.dw_attr_val.val_class = dw_val_class_die_ref;
5255 attr.dw_attr_val.v.val_die_ref.die = targ_die;
5256 attr.dw_attr_val.v.val_die_ref.external = 0;
5257 add_dwarf_attr (die, &attr);
5260 /* Add an AT_specification attribute to a DIE, and also make the back
5261 pointer from the specification to the definition. */
5264 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
5266 add_AT_die_ref (die, DW_AT_specification, targ_die);
5267 gcc_assert (!targ_die->die_definition);
5268 targ_die->die_definition = die;
5271 static inline dw_die_ref
5272 AT_ref (dw_attr_ref a)
5274 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5275 return a->dw_attr_val.v.val_die_ref.die;
5279 AT_ref_external (dw_attr_ref a)
5281 if (a && AT_class (a) == dw_val_class_die_ref)
5282 return a->dw_attr_val.v.val_die_ref.external;
5288 set_AT_ref_external (dw_attr_ref a, int i)
5290 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
5291 a->dw_attr_val.v.val_die_ref.external = i;
5294 /* Add an FDE reference attribute value to a DIE. */
5297 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
5301 attr.dw_attr = attr_kind;
5302 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
5303 attr.dw_attr_val.v.val_fde_index = targ_fde;
5304 add_dwarf_attr (die, &attr);
5307 /* Add a location description attribute value to a DIE. */
5310 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
5314 attr.dw_attr = attr_kind;
5315 attr.dw_attr_val.val_class = dw_val_class_loc;
5316 attr.dw_attr_val.v.val_loc = loc;
5317 add_dwarf_attr (die, &attr);
5320 static inline dw_loc_descr_ref
5321 AT_loc (dw_attr_ref a)
5323 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5324 return a->dw_attr_val.v.val_loc;
5328 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5332 attr.dw_attr = attr_kind;
5333 attr.dw_attr_val.val_class = dw_val_class_loc_list;
5334 attr.dw_attr_val.v.val_loc_list = loc_list;
5335 add_dwarf_attr (die, &attr);
5336 have_location_lists = true;
5339 static inline dw_loc_list_ref
5340 AT_loc_list (dw_attr_ref a)
5342 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5343 return a->dw_attr_val.v.val_loc_list;
5346 /* Add an address constant attribute value to a DIE. */
5349 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5353 attr.dw_attr = attr_kind;
5354 attr.dw_attr_val.val_class = dw_val_class_addr;
5355 attr.dw_attr_val.v.val_addr = addr;
5356 add_dwarf_attr (die, &attr);
5359 /* Get the RTX from to an address DIE attribute. */
5362 AT_addr (dw_attr_ref a)
5364 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5365 return a->dw_attr_val.v.val_addr;
5368 /* Add a file attribute value to a DIE. */
5371 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5372 struct dwarf_file_data *fd)
5376 attr.dw_attr = attr_kind;
5377 attr.dw_attr_val.val_class = dw_val_class_file;
5378 attr.dw_attr_val.v.val_file = fd;
5379 add_dwarf_attr (die, &attr);
5382 /* Get the dwarf_file_data from a file DIE attribute. */
5384 static inline struct dwarf_file_data *
5385 AT_file (dw_attr_ref a)
5387 gcc_assert (a && AT_class (a) == dw_val_class_file);
5388 return a->dw_attr_val.v.val_file;
5391 /* Add a label identifier attribute value to a DIE. */
5394 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5398 attr.dw_attr = attr_kind;
5399 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5400 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5401 add_dwarf_attr (die, &attr);
5404 /* Add a section offset attribute value to a DIE, an offset into the
5405 debug_line section. */
5408 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5413 attr.dw_attr = attr_kind;
5414 attr.dw_attr_val.val_class = dw_val_class_lineptr;
5415 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5416 add_dwarf_attr (die, &attr);
5419 /* Add a section offset attribute value to a DIE, an offset into the
5420 debug_macinfo section. */
5423 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5428 attr.dw_attr = attr_kind;
5429 attr.dw_attr_val.val_class = dw_val_class_macptr;
5430 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5431 add_dwarf_attr (die, &attr);
5434 /* Add an offset attribute value to a DIE. */
5437 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5438 unsigned HOST_WIDE_INT offset)
5442 attr.dw_attr = attr_kind;
5443 attr.dw_attr_val.val_class = dw_val_class_offset;
5444 attr.dw_attr_val.v.val_offset = offset;
5445 add_dwarf_attr (die, &attr);
5448 /* Add an range_list attribute value to a DIE. */
5451 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5452 long unsigned int offset)
5456 attr.dw_attr = attr_kind;
5457 attr.dw_attr_val.val_class = dw_val_class_range_list;
5458 attr.dw_attr_val.v.val_offset = offset;
5459 add_dwarf_attr (die, &attr);
5462 static inline const char *
5463 AT_lbl (dw_attr_ref a)
5465 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5466 || AT_class (a) == dw_val_class_lineptr
5467 || AT_class (a) == dw_val_class_macptr));
5468 return a->dw_attr_val.v.val_lbl_id;
5471 /* Get the attribute of type attr_kind. */
5474 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5478 dw_die_ref spec = NULL;
5483 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5484 if (a->dw_attr == attr_kind)
5486 else if (a->dw_attr == DW_AT_specification
5487 || a->dw_attr == DW_AT_abstract_origin)
5491 return get_AT (spec, attr_kind);
5496 /* Return the "low pc" attribute value, typically associated with a subprogram
5497 DIE. Return null if the "low pc" attribute is either not present, or if it
5498 cannot be represented as an assembler label identifier. */
5500 static inline const char *
5501 get_AT_low_pc (dw_die_ref die)
5503 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5505 return a ? AT_lbl (a) : NULL;
5508 /* Return the "high pc" attribute value, typically associated with a subprogram
5509 DIE. Return null if the "high pc" attribute is either not present, or if it
5510 cannot be represented as an assembler label identifier. */
5512 static inline const char *
5513 get_AT_hi_pc (dw_die_ref die)
5515 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5517 return a ? AT_lbl (a) : NULL;
5520 /* Return the value of the string attribute designated by ATTR_KIND, or
5521 NULL if it is not present. */
5523 static inline const char *
5524 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5526 dw_attr_ref a = get_AT (die, attr_kind);
5528 return a ? AT_string (a) : NULL;
5531 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5532 if it is not present. */
5535 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5537 dw_attr_ref a = get_AT (die, attr_kind);
5539 return a ? AT_flag (a) : 0;
5542 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5543 if it is not present. */
5545 static inline unsigned
5546 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5548 dw_attr_ref a = get_AT (die, attr_kind);
5550 return a ? AT_unsigned (a) : 0;
5553 static inline dw_die_ref
5554 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5556 dw_attr_ref a = get_AT (die, attr_kind);
5558 return a ? AT_ref (a) : NULL;
5561 static inline struct dwarf_file_data *
5562 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5564 dw_attr_ref a = get_AT (die, attr_kind);
5566 return a ? AT_file (a) : NULL;
5569 /* Return TRUE if the language is C or C++. */
5574 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5576 return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC
5577 || lang == DW_LANG_C99
5578 || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus);
5581 /* Return TRUE if the language is C++. */
5586 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5588 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
5591 /* Return TRUE if the language is Fortran. */
5596 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5598 return (lang == DW_LANG_Fortran77
5599 || lang == DW_LANG_Fortran90
5600 || lang == DW_LANG_Fortran95);
5603 /* Return TRUE if the language is Java. */
5608 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5610 return lang == DW_LANG_Java;
5613 /* Return TRUE if the language is Ada. */
5618 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5620 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5623 /* Remove the specified attribute if present. */
5626 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5634 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5635 if (a->dw_attr == attr_kind)
5637 if (AT_class (a) == dw_val_class_str)
5638 if (a->dw_attr_val.v.val_str->refcount)
5639 a->dw_attr_val.v.val_str->refcount--;
5641 /* VEC_ordered_remove should help reduce the number of abbrevs
5643 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
5648 /* Remove CHILD from its parent. PREV must have the property that
5649 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5652 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5654 gcc_assert (child->die_parent == prev->die_parent);
5655 gcc_assert (prev->die_sib == child);
5658 gcc_assert (child->die_parent->die_child == child);
5662 prev->die_sib = child->die_sib;
5663 if (child->die_parent->die_child == child)
5664 child->die_parent->die_child = prev;
5667 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5671 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5677 dw_die_ref prev = c;
5679 while (c->die_tag == tag)
5681 remove_child_with_prev (c, prev);
5682 /* Might have removed every child. */
5683 if (c == c->die_sib)
5687 } while (c != die->die_child);
5690 /* Add a CHILD_DIE as the last child of DIE. */
5693 add_child_die (dw_die_ref die, dw_die_ref child_die)
5695 /* FIXME this should probably be an assert. */
5696 if (! die || ! child_die)
5698 gcc_assert (die != child_die);
5700 child_die->die_parent = die;
5703 child_die->die_sib = die->die_child->die_sib;
5704 die->die_child->die_sib = child_die;
5707 child_die->die_sib = child_die;
5708 die->die_child = child_die;
5711 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5712 is the specification, to the end of PARENT's list of children.
5713 This is done by removing and re-adding it. */
5716 splice_child_die (dw_die_ref parent, dw_die_ref child)
5720 /* We want the declaration DIE from inside the class, not the
5721 specification DIE at toplevel. */
5722 if (child->die_parent != parent)
5724 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5730 gcc_assert (child->die_parent == parent
5731 || (child->die_parent
5732 == get_AT_ref (parent, DW_AT_specification)));
5734 for (p = child->die_parent->die_child; ; p = p->die_sib)
5735 if (p->die_sib == child)
5737 remove_child_with_prev (child, p);
5741 add_child_die (parent, child);
5744 /* Return a pointer to a newly created DIE node. */
5746 static inline dw_die_ref
5747 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5749 dw_die_ref die = GGC_CNEW (die_node);
5751 die->die_tag = tag_value;
5753 if (parent_die != NULL)
5754 add_child_die (parent_die, die);
5757 limbo_die_node *limbo_node;
5759 limbo_node = GGC_CNEW (limbo_die_node);
5760 limbo_node->die = die;
5761 limbo_node->created_for = t;
5762 limbo_node->next = limbo_die_list;
5763 limbo_die_list = limbo_node;
5769 /* Return the DIE associated with the given type specifier. */
5771 static inline dw_die_ref
5772 lookup_type_die (tree type)
5774 return TYPE_SYMTAB_DIE (type);
5777 /* Equate a DIE to a given type specifier. */
5780 equate_type_number_to_die (tree type, dw_die_ref type_die)
5782 TYPE_SYMTAB_DIE (type) = type_die;
5785 /* Returns a hash value for X (which really is a die_struct). */
5788 decl_die_table_hash (const void *x)
5790 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
5793 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5796 decl_die_table_eq (const void *x, const void *y)
5798 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
5801 /* Return the DIE associated with a given declaration. */
5803 static inline dw_die_ref
5804 lookup_decl_die (tree decl)
5806 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5809 /* Returns a hash value for X (which really is a var_loc_list). */
5812 decl_loc_table_hash (const void *x)
5814 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5817 /* Return nonzero if decl_id of var_loc_list X is the same as
5821 decl_loc_table_eq (const void *x, const void *y)
5823 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
5826 /* Return the var_loc list associated with a given declaration. */
5828 static inline var_loc_list *
5829 lookup_decl_loc (const_tree decl)
5831 return (var_loc_list *)
5832 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5835 /* Equate a DIE to a particular declaration. */
5838 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5840 unsigned int decl_id = DECL_UID (decl);
5843 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5845 decl_die->decl_id = decl_id;
5848 /* Add a variable location node to the linked list for DECL. */
5851 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5853 unsigned int decl_id = DECL_UID (decl);
5857 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5860 temp = GGC_CNEW (var_loc_list);
5861 temp->decl_id = decl_id;
5865 temp = (var_loc_list *) *slot;
5869 /* If the current location is the same as the end of the list,
5870 and either both or neither of the locations is uninitialized,
5871 we have nothing to do. */
5872 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5873 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5874 || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5875 != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note))
5876 && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note)
5877 == VAR_INIT_STATUS_UNINITIALIZED)
5878 || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)
5879 == VAR_INIT_STATUS_UNINITIALIZED))))
5881 /* Add LOC to the end of list and update LAST. */
5882 temp->last->next = loc;
5886 /* Do not add empty location to the beginning of the list. */
5887 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5894 /* Keep track of the number of spaces used to indent the
5895 output of the debugging routines that print the structure of
5896 the DIE internal representation. */
5897 static int print_indent;
5899 /* Indent the line the number of spaces given by print_indent. */
5902 print_spaces (FILE *outfile)
5904 fprintf (outfile, "%*s", print_indent, "");
5907 /* Print the information associated with a given DIE, and its children.
5908 This routine is a debugging aid only. */
5911 print_die (dw_die_ref die, FILE *outfile)
5917 print_spaces (outfile);
5918 fprintf (outfile, "DIE %4ld: %s\n",
5919 die->die_offset, dwarf_tag_name (die->die_tag));
5920 print_spaces (outfile);
5921 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5922 fprintf (outfile, " offset: %ld\n", die->die_offset);
5924 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
5926 print_spaces (outfile);
5927 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5929 switch (AT_class (a))
5931 case dw_val_class_addr:
5932 fprintf (outfile, "address");
5934 case dw_val_class_offset:
5935 fprintf (outfile, "offset");
5937 case dw_val_class_loc:
5938 fprintf (outfile, "location descriptor");
5940 case dw_val_class_loc_list:
5941 fprintf (outfile, "location list -> label:%s",
5942 AT_loc_list (a)->ll_symbol);
5944 case dw_val_class_range_list:
5945 fprintf (outfile, "range list");
5947 case dw_val_class_const:
5948 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5950 case dw_val_class_unsigned_const:
5951 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5953 case dw_val_class_long_long:
5954 fprintf (outfile, "constant (%lu,%lu)",
5955 a->dw_attr_val.v.val_long_long.hi,
5956 a->dw_attr_val.v.val_long_long.low);
5958 case dw_val_class_vec:
5959 fprintf (outfile, "floating-point or vector constant");
5961 case dw_val_class_flag:
5962 fprintf (outfile, "%u", AT_flag (a));
5964 case dw_val_class_die_ref:
5965 if (AT_ref (a) != NULL)
5967 if (AT_ref (a)->die_symbol)
5968 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5970 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
5973 fprintf (outfile, "die -> <null>");
5975 case dw_val_class_lbl_id:
5976 case dw_val_class_lineptr:
5977 case dw_val_class_macptr:
5978 fprintf (outfile, "label: %s", AT_lbl (a));
5980 case dw_val_class_str:
5981 if (AT_string (a) != NULL)
5982 fprintf (outfile, "\"%s\"", AT_string (a));
5984 fprintf (outfile, "<null>");
5986 case dw_val_class_file:
5987 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
5988 AT_file (a)->emitted_number);
5994 fprintf (outfile, "\n");
5997 if (die->die_child != NULL)
6000 FOR_EACH_CHILD (die, c, print_die (c, outfile));
6003 if (print_indent == 0)
6004 fprintf (outfile, "\n");
6007 /* Print the contents of the source code line number correspondence table.
6008 This routine is a debugging aid only. */
6011 print_dwarf_line_table (FILE *outfile)
6014 dw_line_info_ref line_info;
6016 fprintf (outfile, "\n\nDWARF source line information\n");
6017 for (i = 1; i < line_info_table_in_use; i++)
6019 line_info = &line_info_table[i];
6020 fprintf (outfile, "%5d: %4ld %6ld\n", i,
6021 line_info->dw_file_num,
6022 line_info->dw_line_num);
6025 fprintf (outfile, "\n\n");
6028 /* Print the information collected for a given DIE. */
6031 debug_dwarf_die (dw_die_ref die)
6033 print_die (die, stderr);
6036 /* Print all DWARF information collected for the compilation unit.
6037 This routine is a debugging aid only. */
6043 print_die (comp_unit_die, stderr);
6044 if (! DWARF2_ASM_LINE_DEBUG_INFO)
6045 print_dwarf_line_table (stderr);
6048 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6049 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6050 DIE that marks the start of the DIEs for this include file. */
6053 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
6055 const char *filename = get_AT_string (bincl_die, DW_AT_name);
6056 dw_die_ref new_unit = gen_compile_unit_die (filename);
6058 new_unit->die_sib = old_unit;
6062 /* Close an include-file CU and reopen the enclosing one. */
6065 pop_compile_unit (dw_die_ref old_unit)
6067 dw_die_ref new_unit = old_unit->die_sib;
6069 old_unit->die_sib = NULL;
6073 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6074 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6076 /* Calculate the checksum of a location expression. */
6079 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
6081 CHECKSUM (loc->dw_loc_opc);
6082 CHECKSUM (loc->dw_loc_oprnd1);
6083 CHECKSUM (loc->dw_loc_oprnd2);
6086 /* Calculate the checksum of an attribute. */
6089 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
6091 dw_loc_descr_ref loc;
6094 CHECKSUM (at->dw_attr);
6096 /* We don't care that this was compiled with a different compiler
6097 snapshot; if the output is the same, that's what matters. */
6098 if (at->dw_attr == DW_AT_producer)
6101 switch (AT_class (at))
6103 case dw_val_class_const:
6104 CHECKSUM (at->dw_attr_val.v.val_int);
6106 case dw_val_class_unsigned_const:
6107 CHECKSUM (at->dw_attr_val.v.val_unsigned);
6109 case dw_val_class_long_long:
6110 CHECKSUM (at->dw_attr_val.v.val_long_long);
6112 case dw_val_class_vec:
6113 CHECKSUM (at->dw_attr_val.v.val_vec);
6115 case dw_val_class_flag:
6116 CHECKSUM (at->dw_attr_val.v.val_flag);
6118 case dw_val_class_str:
6119 CHECKSUM_STRING (AT_string (at));
6122 case dw_val_class_addr:
6124 gcc_assert (GET_CODE (r) == SYMBOL_REF);
6125 CHECKSUM_STRING (XSTR (r, 0));
6128 case dw_val_class_offset:
6129 CHECKSUM (at->dw_attr_val.v.val_offset);
6132 case dw_val_class_loc:
6133 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
6134 loc_checksum (loc, ctx);
6137 case dw_val_class_die_ref:
6138 die_checksum (AT_ref (at), ctx, mark);
6141 case dw_val_class_fde_ref:
6142 case dw_val_class_lbl_id:
6143 case dw_val_class_lineptr:
6144 case dw_val_class_macptr:
6147 case dw_val_class_file:
6148 CHECKSUM_STRING (AT_file (at)->filename);
6156 /* Calculate the checksum of a DIE. */
6159 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
6165 /* To avoid infinite recursion. */
6168 CHECKSUM (die->die_mark);
6171 die->die_mark = ++(*mark);
6173 CHECKSUM (die->die_tag);
6175 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6176 attr_checksum (a, ctx, mark);
6178 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
6182 #undef CHECKSUM_STRING
6184 /* Do the location expressions look same? */
6186 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
6188 return loc1->dw_loc_opc == loc2->dw_loc_opc
6189 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
6190 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
6193 /* Do the values look the same? */
6195 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
6197 dw_loc_descr_ref loc1, loc2;
6200 if (v1->val_class != v2->val_class)
6203 switch (v1->val_class)
6205 case dw_val_class_const:
6206 return v1->v.val_int == v2->v.val_int;
6207 case dw_val_class_unsigned_const:
6208 return v1->v.val_unsigned == v2->v.val_unsigned;
6209 case dw_val_class_long_long:
6210 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
6211 && v1->v.val_long_long.low == v2->v.val_long_long.low;
6212 case dw_val_class_vec:
6213 if (v1->v.val_vec.length != v2->v.val_vec.length
6214 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
6216 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
6217 v1->v.val_vec.length * v1->v.val_vec.elt_size))
6220 case dw_val_class_flag:
6221 return v1->v.val_flag == v2->v.val_flag;
6222 case dw_val_class_str:
6223 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
6225 case dw_val_class_addr:
6226 r1 = v1->v.val_addr;
6227 r2 = v2->v.val_addr;
6228 if (GET_CODE (r1) != GET_CODE (r2))
6230 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
6231 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
6233 case dw_val_class_offset:
6234 return v1->v.val_offset == v2->v.val_offset;
6236 case dw_val_class_loc:
6237 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
6239 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
6240 if (!same_loc_p (loc1, loc2, mark))
6242 return !loc1 && !loc2;
6244 case dw_val_class_die_ref:
6245 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
6247 case dw_val_class_fde_ref:
6248 case dw_val_class_lbl_id:
6249 case dw_val_class_lineptr:
6250 case dw_val_class_macptr:
6253 case dw_val_class_file:
6254 return v1->v.val_file == v2->v.val_file;
6261 /* Do the attributes look the same? */
6264 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
6266 if (at1->dw_attr != at2->dw_attr)
6269 /* We don't care that this was compiled with a different compiler
6270 snapshot; if the output is the same, that's what matters. */
6271 if (at1->dw_attr == DW_AT_producer)
6274 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
6277 /* Do the dies look the same? */
6280 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
6286 /* To avoid infinite recursion. */
6288 return die1->die_mark == die2->die_mark;
6289 die1->die_mark = die2->die_mark = ++(*mark);
6291 if (die1->die_tag != die2->die_tag)
6294 if (VEC_length (dw_attr_node, die1->die_attr)
6295 != VEC_length (dw_attr_node, die2->die_attr))
6298 for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++)
6299 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
6302 c1 = die1->die_child;
6303 c2 = die2->die_child;
6312 if (!same_die_p (c1, c2, mark))
6316 if (c1 == die1->die_child)
6318 if (c2 == die2->die_child)
6328 /* Do the dies look the same? Wrapper around same_die_p. */
6331 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6334 int ret = same_die_p (die1, die2, &mark);
6336 unmark_all_dies (die1);
6337 unmark_all_dies (die2);
6342 /* The prefix to attach to symbols on DIEs in the current comdat debug
6344 static char *comdat_symbol_id;
6346 /* The index of the current symbol within the current comdat CU. */
6347 static unsigned int comdat_symbol_number;
6349 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6350 children, and set comdat_symbol_id accordingly. */
6353 compute_section_prefix (dw_die_ref unit_die)
6355 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6356 const char *base = die_name ? lbasename (die_name) : "anonymous";
6357 char *name = XALLOCAVEC (char, strlen (base) + 64);
6360 unsigned char checksum[16];
6363 /* Compute the checksum of the DIE, then append part of it as hex digits to
6364 the name filename of the unit. */
6366 md5_init_ctx (&ctx);
6368 die_checksum (unit_die, &ctx, &mark);
6369 unmark_all_dies (unit_die);
6370 md5_finish_ctx (&ctx, checksum);
6372 sprintf (name, "%s.", base);
6373 clean_symbol_name (name);
6375 p = name + strlen (name);
6376 for (i = 0; i < 4; i++)
6378 sprintf (p, "%.2x", checksum[i]);
6382 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6383 comdat_symbol_number = 0;
6386 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6389 is_type_die (dw_die_ref die)
6391 switch (die->die_tag)
6393 case DW_TAG_array_type:
6394 case DW_TAG_class_type:
6395 case DW_TAG_interface_type:
6396 case DW_TAG_enumeration_type:
6397 case DW_TAG_pointer_type:
6398 case DW_TAG_reference_type:
6399 case DW_TAG_string_type:
6400 case DW_TAG_structure_type:
6401 case DW_TAG_subroutine_type:
6402 case DW_TAG_union_type:
6403 case DW_TAG_ptr_to_member_type:
6404 case DW_TAG_set_type:
6405 case DW_TAG_subrange_type:
6406 case DW_TAG_base_type:
6407 case DW_TAG_const_type:
6408 case DW_TAG_file_type:
6409 case DW_TAG_packed_type:
6410 case DW_TAG_volatile_type:
6411 case DW_TAG_typedef:
6418 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6419 Basically, we want to choose the bits that are likely to be shared between
6420 compilations (types) and leave out the bits that are specific to individual
6421 compilations (functions). */
6424 is_comdat_die (dw_die_ref c)
6426 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6427 we do for stabs. The advantage is a greater likelihood of sharing between
6428 objects that don't include headers in the same order (and therefore would
6429 put the base types in a different comdat). jason 8/28/00 */
6431 if (c->die_tag == DW_TAG_base_type)
6434 if (c->die_tag == DW_TAG_pointer_type
6435 || c->die_tag == DW_TAG_reference_type
6436 || c->die_tag == DW_TAG_const_type
6437 || c->die_tag == DW_TAG_volatile_type)
6439 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6441 return t ? is_comdat_die (t) : 0;
6444 return is_type_die (c);
6447 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6448 compilation unit. */
6451 is_symbol_die (dw_die_ref c)
6453 return (is_type_die (c)
6454 || (get_AT (c, DW_AT_declaration)
6455 && !get_AT (c, DW_AT_specification))
6456 || c->die_tag == DW_TAG_namespace);
6460 gen_internal_sym (const char *prefix)
6464 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6465 return xstrdup (buf);
6468 /* Assign symbols to all worthy DIEs under DIE. */
6471 assign_symbol_names (dw_die_ref die)
6475 if (is_symbol_die (die))
6477 if (comdat_symbol_id)
6479 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
6481 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6482 comdat_symbol_id, comdat_symbol_number++);
6483 die->die_symbol = xstrdup (p);
6486 die->die_symbol = gen_internal_sym ("LDIE");
6489 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
6492 struct cu_hash_table_entry
6495 unsigned min_comdat_num, max_comdat_num;
6496 struct cu_hash_table_entry *next;
6499 /* Routines to manipulate hash table of CUs. */
6501 htab_cu_hash (const void *of)
6503 const struct cu_hash_table_entry *const entry =
6504 (const struct cu_hash_table_entry *) of;
6506 return htab_hash_string (entry->cu->die_symbol);
6510 htab_cu_eq (const void *of1, const void *of2)
6512 const struct cu_hash_table_entry *const entry1 =
6513 (const struct cu_hash_table_entry *) of1;
6514 const struct die_struct *const entry2 = (const struct die_struct *) of2;
6516 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6520 htab_cu_del (void *what)
6522 struct cu_hash_table_entry *next,
6523 *entry = (struct cu_hash_table_entry *) what;
6533 /* Check whether we have already seen this CU and set up SYM_NUM
6536 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6538 struct cu_hash_table_entry dummy;
6539 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6541 dummy.max_comdat_num = 0;
6543 slot = (struct cu_hash_table_entry **)
6544 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6548 for (; entry; last = entry, entry = entry->next)
6550 if (same_die_p_wrap (cu, entry->cu))
6556 *sym_num = entry->min_comdat_num;
6560 entry = XCNEW (struct cu_hash_table_entry);
6562 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6563 entry->next = *slot;
6569 /* Record SYM_NUM to record of CU in HTABLE. */
6571 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6573 struct cu_hash_table_entry **slot, *entry;
6575 slot = (struct cu_hash_table_entry **)
6576 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6580 entry->max_comdat_num = sym_num;
6583 /* Traverse the DIE (which is always comp_unit_die), and set up
6584 additional compilation units for each of the include files we see
6585 bracketed by BINCL/EINCL. */
6588 break_out_includes (dw_die_ref die)
6591 dw_die_ref unit = NULL;
6592 limbo_die_node *node, **pnode;
6593 htab_t cu_hash_table;
6597 dw_die_ref prev = c;
6599 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6600 || (unit && is_comdat_die (c)))
6602 dw_die_ref next = c->die_sib;
6604 /* This DIE is for a secondary CU; remove it from the main one. */
6605 remove_child_with_prev (c, prev);
6607 if (c->die_tag == DW_TAG_GNU_BINCL)
6608 unit = push_new_compile_unit (unit, c);
6609 else if (c->die_tag == DW_TAG_GNU_EINCL)
6610 unit = pop_compile_unit (unit);
6612 add_child_die (unit, c);
6614 if (c == die->die_child)
6617 } while (c != die->die_child);
6620 /* We can only use this in debugging, since the frontend doesn't check
6621 to make sure that we leave every include file we enter. */
6625 assign_symbol_names (die);
6626 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6627 for (node = limbo_die_list, pnode = &limbo_die_list;
6633 compute_section_prefix (node->die);
6634 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6635 &comdat_symbol_number);
6636 assign_symbol_names (node->die);
6638 *pnode = node->next;
6641 pnode = &node->next;
6642 record_comdat_symbol_number (node->die, cu_hash_table,
6643 comdat_symbol_number);
6646 htab_delete (cu_hash_table);
6649 /* Traverse the DIE and add a sibling attribute if it may have the
6650 effect of speeding up access to siblings. To save some space,
6651 avoid generating sibling attributes for DIE's without children. */
6654 add_sibling_attributes (dw_die_ref die)
6658 if (! die->die_child)
6661 if (die->die_parent && die != die->die_parent->die_child)
6662 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6664 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
6667 /* Output all location lists for the DIE and its children. */
6670 output_location_lists (dw_die_ref die)
6676 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6677 if (AT_class (a) == dw_val_class_loc_list)
6678 output_loc_list (AT_loc_list (a));
6680 FOR_EACH_CHILD (die, c, output_location_lists (c));
6683 /* The format of each DIE (and its attribute value pairs) is encoded in an
6684 abbreviation table. This routine builds the abbreviation table and assigns
6685 a unique abbreviation id for each abbreviation entry. The children of each
6686 die are visited recursively. */
6689 build_abbrev_table (dw_die_ref die)
6691 unsigned long abbrev_id;
6692 unsigned int n_alloc;
6697 /* Scan the DIE references, and mark as external any that refer to
6698 DIEs from other CUs (i.e. those which are not marked). */
6699 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6700 if (AT_class (a) == dw_val_class_die_ref
6701 && AT_ref (a)->die_mark == 0)
6703 gcc_assert (AT_ref (a)->die_symbol);
6705 set_AT_ref_external (a, 1);
6708 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6710 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6711 dw_attr_ref die_a, abbrev_a;
6715 if (abbrev->die_tag != die->die_tag)
6717 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
6720 if (VEC_length (dw_attr_node, abbrev->die_attr)
6721 != VEC_length (dw_attr_node, die->die_attr))
6724 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++)
6726 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
6727 if ((abbrev_a->dw_attr != die_a->dw_attr)
6728 || (value_format (abbrev_a) != value_format (die_a)))
6738 if (abbrev_id >= abbrev_die_table_in_use)
6740 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6742 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6743 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
6746 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6747 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6748 abbrev_die_table_allocated = n_alloc;
6751 ++abbrev_die_table_in_use;
6752 abbrev_die_table[abbrev_id] = die;
6755 die->die_abbrev = abbrev_id;
6756 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
6759 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6762 constant_size (long unsigned int value)
6769 log = floor_log2 (value);
6772 log = 1 << (floor_log2 (log) + 1);
6777 /* Return the size of a DIE as it is represented in the
6778 .debug_info section. */
6780 static unsigned long
6781 size_of_die (dw_die_ref die)
6783 unsigned long size = 0;
6787 size += size_of_uleb128 (die->die_abbrev);
6788 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6790 switch (AT_class (a))
6792 case dw_val_class_addr:
6793 size += DWARF2_ADDR_SIZE;
6795 case dw_val_class_offset:
6796 size += DWARF_OFFSET_SIZE;
6798 case dw_val_class_loc:
6800 unsigned long lsize = size_of_locs (AT_loc (a));
6803 size += constant_size (lsize);
6807 case dw_val_class_loc_list:
6808 size += DWARF_OFFSET_SIZE;
6810 case dw_val_class_range_list:
6811 size += DWARF_OFFSET_SIZE;
6813 case dw_val_class_const:
6814 size += size_of_sleb128 (AT_int (a));
6816 case dw_val_class_unsigned_const:
6817 size += constant_size (AT_unsigned (a));
6819 case dw_val_class_long_long:
6820 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6822 case dw_val_class_vec:
6823 size += 1 + (a->dw_attr_val.v.val_vec.length
6824 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6826 case dw_val_class_flag:
6829 case dw_val_class_die_ref:
6830 if (AT_ref_external (a))
6831 size += DWARF2_ADDR_SIZE;
6833 size += DWARF_OFFSET_SIZE;
6835 case dw_val_class_fde_ref:
6836 size += DWARF_OFFSET_SIZE;
6838 case dw_val_class_lbl_id:
6839 size += DWARF2_ADDR_SIZE;
6841 case dw_val_class_lineptr:
6842 case dw_val_class_macptr:
6843 size += DWARF_OFFSET_SIZE;
6845 case dw_val_class_str:
6846 if (AT_string_form (a) == DW_FORM_strp)
6847 size += DWARF_OFFSET_SIZE;
6849 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6851 case dw_val_class_file:
6852 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
6862 /* Size the debugging information associated with a given DIE. Visits the
6863 DIE's children recursively. Updates the global variable next_die_offset, on
6864 each time through. Uses the current value of next_die_offset to update the
6865 die_offset field in each DIE. */
6868 calc_die_sizes (dw_die_ref die)
6872 die->die_offset = next_die_offset;
6873 next_die_offset += size_of_die (die);
6875 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
6877 if (die->die_child != NULL)
6878 /* Count the null byte used to terminate sibling lists. */
6879 next_die_offset += 1;
6882 /* Set the marks for a die and its children. We do this so
6883 that we know whether or not a reference needs to use FORM_ref_addr; only
6884 DIEs in the same CU will be marked. We used to clear out the offset
6885 and use that as the flag, but ran into ordering problems. */
6888 mark_dies (dw_die_ref die)
6892 gcc_assert (!die->die_mark);
6895 FOR_EACH_CHILD (die, c, mark_dies (c));
6898 /* Clear the marks for a die and its children. */
6901 unmark_dies (dw_die_ref die)
6905 gcc_assert (die->die_mark);
6908 FOR_EACH_CHILD (die, c, unmark_dies (c));
6911 /* Clear the marks for a die, its children and referred dies. */
6914 unmark_all_dies (dw_die_ref die)
6924 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
6926 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
6927 if (AT_class (a) == dw_val_class_die_ref)
6928 unmark_all_dies (AT_ref (a));
6931 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6932 generated for the compilation unit. */
6934 static unsigned long
6935 size_of_pubnames (VEC (pubname_entry, gc) * names)
6941 size = DWARF_PUBNAMES_HEADER_SIZE;
6942 for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++)
6943 if (names != pubtype_table
6944 || p->die->die_offset != 0
6945 || !flag_eliminate_unused_debug_types)
6946 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
6948 size += DWARF_OFFSET_SIZE;
6952 /* Return the size of the information in the .debug_aranges section. */
6954 static unsigned long
6955 size_of_aranges (void)
6959 size = DWARF_ARANGES_HEADER_SIZE;
6961 /* Count the address/length pair for this compilation unit. */
6962 if (text_section_used)
6963 size += 2 * DWARF2_ADDR_SIZE;
6964 if (cold_text_section_used)
6965 size += 2 * DWARF2_ADDR_SIZE;
6966 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6968 /* Count the two zero words used to terminated the address range table. */
6969 size += 2 * DWARF2_ADDR_SIZE;
6973 /* Select the encoding of an attribute value. */
6975 static enum dwarf_form
6976 value_format (dw_attr_ref a)
6978 switch (a->dw_attr_val.val_class)
6980 case dw_val_class_addr:
6981 return DW_FORM_addr;
6982 case dw_val_class_range_list:
6983 case dw_val_class_offset:
6984 case dw_val_class_loc_list:
6985 switch (DWARF_OFFSET_SIZE)
6988 return DW_FORM_data4;
6990 return DW_FORM_data8;
6994 case dw_val_class_loc:
6995 switch (constant_size (size_of_locs (AT_loc (a))))
6998 return DW_FORM_block1;
7000 return DW_FORM_block2;
7004 case dw_val_class_const:
7005 return DW_FORM_sdata;
7006 case dw_val_class_unsigned_const:
7007 switch (constant_size (AT_unsigned (a)))
7010 return DW_FORM_data1;
7012 return DW_FORM_data2;
7014 return DW_FORM_data4;
7016 return DW_FORM_data8;
7020 case dw_val_class_long_long:
7021 return DW_FORM_block1;
7022 case dw_val_class_vec:
7023 return DW_FORM_block1;
7024 case dw_val_class_flag:
7025 return DW_FORM_flag;
7026 case dw_val_class_die_ref:
7027 if (AT_ref_external (a))
7028 return DW_FORM_ref_addr;
7031 case dw_val_class_fde_ref:
7032 return DW_FORM_data;
7033 case dw_val_class_lbl_id:
7034 return DW_FORM_addr;
7035 case dw_val_class_lineptr:
7036 case dw_val_class_macptr:
7037 return DW_FORM_data;
7038 case dw_val_class_str:
7039 return AT_string_form (a);
7040 case dw_val_class_file:
7041 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
7044 return DW_FORM_data1;
7046 return DW_FORM_data2;
7048 return DW_FORM_data4;
7058 /* Output the encoding of an attribute value. */
7061 output_value_format (dw_attr_ref a)
7063 enum dwarf_form form = value_format (a);
7065 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
7068 /* Output the .debug_abbrev section which defines the DIE abbreviation
7072 output_abbrev_section (void)
7074 unsigned long abbrev_id;
7076 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
7078 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
7082 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
7083 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
7084 dwarf_tag_name (abbrev->die_tag));
7086 if (abbrev->die_child != NULL)
7087 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
7089 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
7091 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
7094 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
7095 dwarf_attr_name (a_attr->dw_attr));
7096 output_value_format (a_attr);
7099 dw2_asm_output_data (1, 0, NULL);
7100 dw2_asm_output_data (1, 0, NULL);
7103 /* Terminate the table. */
7104 dw2_asm_output_data (1, 0, NULL);
7107 /* Output a symbol we can use to refer to this DIE from another CU. */
7110 output_die_symbol (dw_die_ref die)
7112 char *sym = die->die_symbol;
7117 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
7118 /* We make these global, not weak; if the target doesn't support
7119 .linkonce, it doesn't support combining the sections, so debugging
7121 targetm.asm_out.globalize_label (asm_out_file, sym);
7123 ASM_OUTPUT_LABEL (asm_out_file, sym);
7126 /* Return a new location list, given the begin and end range, and the
7127 expression. gensym tells us whether to generate a new internal symbol for
7128 this location list node, which is done for the head of the list only. */
7130 static inline dw_loc_list_ref
7131 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
7132 const char *section, unsigned int gensym)
7134 dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node);
7136 retlist->begin = begin;
7138 retlist->expr = expr;
7139 retlist->section = section;
7141 retlist->ll_symbol = gen_internal_sym ("LLST");
7146 /* Add a location description expression to a location list. */
7149 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
7150 const char *begin, const char *end,
7151 const char *section)
7155 /* Find the end of the chain. */
7156 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
7159 /* Add a new location list node to the list. */
7160 *d = new_loc_list (descr, begin, end, section, 0);
7163 /* Output the location list given to us. */
7166 output_loc_list (dw_loc_list_ref list_head)
7168 dw_loc_list_ref curr = list_head;
7170 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
7172 /* Walk the location list, and output each range + expression. */
7173 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
7176 /* Don't output an entry that starts and ends at the same address. */
7177 if (strcmp (curr->begin, curr->end) == 0)
7179 if (!have_multiple_function_sections)
7181 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
7182 "Location list begin address (%s)",
7183 list_head->ll_symbol);
7184 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
7185 "Location list end address (%s)",
7186 list_head->ll_symbol);
7190 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
7191 "Location list begin address (%s)",
7192 list_head->ll_symbol);
7193 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
7194 "Location list end address (%s)",
7195 list_head->ll_symbol);
7197 size = size_of_locs (curr->expr);
7199 /* Output the block length for this list of location operations. */
7200 gcc_assert (size <= 0xffff);
7201 dw2_asm_output_data (2, size, "%s", "Location expression size");
7203 output_loc_sequence (curr->expr);
7206 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7207 "Location list terminator begin (%s)",
7208 list_head->ll_symbol);
7209 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
7210 "Location list terminator end (%s)",
7211 list_head->ll_symbol);
7214 /* Output the DIE and its attributes. Called recursively to generate
7215 the definitions of each child DIE. */
7218 output_die (dw_die_ref die)
7225 /* If someone in another CU might refer to us, set up a symbol for
7226 them to point to. */
7227 if (die->die_symbol)
7228 output_die_symbol (die);
7230 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
7231 (unsigned long)die->die_offset,
7232 dwarf_tag_name (die->die_tag));
7234 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
7236 const char *name = dwarf_attr_name (a->dw_attr);
7238 switch (AT_class (a))
7240 case dw_val_class_addr:
7241 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
7244 case dw_val_class_offset:
7245 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
7249 case dw_val_class_range_list:
7251 char *p = strchr (ranges_section_label, '\0');
7253 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
7254 a->dw_attr_val.v.val_offset);
7255 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
7256 debug_ranges_section, "%s", name);
7261 case dw_val_class_loc:
7262 size = size_of_locs (AT_loc (a));
7264 /* Output the block length for this list of location operations. */
7265 dw2_asm_output_data (constant_size (size), size, "%s", name);
7267 output_loc_sequence (AT_loc (a));
7270 case dw_val_class_const:
7271 /* ??? It would be slightly more efficient to use a scheme like is
7272 used for unsigned constants below, but gdb 4.x does not sign
7273 extend. Gdb 5.x does sign extend. */
7274 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
7277 case dw_val_class_unsigned_const:
7278 dw2_asm_output_data (constant_size (AT_unsigned (a)),
7279 AT_unsigned (a), "%s", name);
7282 case dw_val_class_long_long:
7284 unsigned HOST_WIDE_INT first, second;
7286 dw2_asm_output_data (1,
7287 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7290 if (WORDS_BIG_ENDIAN)
7292 first = a->dw_attr_val.v.val_long_long.hi;
7293 second = a->dw_attr_val.v.val_long_long.low;
7297 first = a->dw_attr_val.v.val_long_long.low;
7298 second = a->dw_attr_val.v.val_long_long.hi;
7301 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7302 first, "long long constant");
7303 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
7308 case dw_val_class_vec:
7310 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
7311 unsigned int len = a->dw_attr_val.v.val_vec.length;
7315 dw2_asm_output_data (1, len * elt_size, "%s", name);
7316 if (elt_size > sizeof (HOST_WIDE_INT))
7321 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
7324 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
7325 "fp or vector constant word %u", i);
7329 case dw_val_class_flag:
7330 dw2_asm_output_data (1, AT_flag (a), "%s", name);
7333 case dw_val_class_loc_list:
7335 char *sym = AT_loc_list (a)->ll_symbol;
7338 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
7343 case dw_val_class_die_ref:
7344 if (AT_ref_external (a))
7346 char *sym = AT_ref (a)->die_symbol;
7349 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section,
7354 gcc_assert (AT_ref (a)->die_offset);
7355 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7360 case dw_val_class_fde_ref:
7364 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7365 a->dw_attr_val.v.val_fde_index * 2);
7366 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
7371 case dw_val_class_lbl_id:
7372 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7375 case dw_val_class_lineptr:
7376 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7377 debug_line_section, "%s", name);
7380 case dw_val_class_macptr:
7381 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
7382 debug_macinfo_section, "%s", name);
7385 case dw_val_class_str:
7386 if (AT_string_form (a) == DW_FORM_strp)
7387 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7388 a->dw_attr_val.v.val_str->label,
7390 "%s: \"%s\"", name, AT_string (a));
7392 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7395 case dw_val_class_file:
7397 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
7399 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
7400 a->dw_attr_val.v.val_file->filename);
7409 FOR_EACH_CHILD (die, c, output_die (c));
7411 /* Add null byte to terminate sibling list. */
7412 if (die->die_child != NULL)
7413 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7414 (unsigned long) die->die_offset);
7417 /* Output the compilation unit that appears at the beginning of the
7418 .debug_info section, and precedes the DIE descriptions. */
7421 output_compilation_unit_header (void)
7423 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7424 dw2_asm_output_data (4, 0xffffffff,
7425 "Initial length escape value indicating 64-bit DWARF extension");
7426 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7427 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7428 "Length of Compilation Unit Info");
7429 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7430 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7431 debug_abbrev_section,
7432 "Offset Into Abbrev. Section");
7433 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7436 /* Output the compilation unit DIE and its children. */
7439 output_comp_unit (dw_die_ref die, int output_if_empty)
7441 const char *secname;
7444 /* Unless we are outputting main CU, we may throw away empty ones. */
7445 if (!output_if_empty && die->die_child == NULL)
7448 /* Even if there are no children of this DIE, we must output the information
7449 about the compilation unit. Otherwise, on an empty translation unit, we
7450 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7451 will then complain when examining the file. First mark all the DIEs in
7452 this CU so we know which get local refs. */
7455 build_abbrev_table (die);
7457 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7458 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7459 calc_die_sizes (die);
7461 oldsym = die->die_symbol;
7464 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
7466 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7468 die->die_symbol = NULL;
7469 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
7472 switch_to_section (debug_info_section);
7474 /* Output debugging information. */
7475 output_compilation_unit_header ();
7478 /* Leave the marks on the main CU, so we can check them in
7483 die->die_symbol = oldsym;
7487 /* Return the DWARF2/3 pubname associated with a decl. */
7490 dwarf2_name (tree decl, int scope)
7492 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
7495 /* Add a new entry to .debug_pubnames if appropriate. */
7498 add_pubname_string (const char *str, dw_die_ref die)
7503 e.name = xstrdup (str);
7504 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
7508 add_pubname (tree decl, dw_die_ref die)
7511 if (TREE_PUBLIC (decl))
7512 add_pubname_string (dwarf2_name (decl, 1), die);
7515 /* Add a new entry to .debug_pubtypes if appropriate. */
7518 add_pubtype (tree decl, dw_die_ref die)
7523 if ((TREE_PUBLIC (decl)
7524 || die->die_parent == comp_unit_die)
7525 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
7530 if (TYPE_NAME (decl))
7532 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
7533 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
7534 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
7535 && DECL_NAME (TYPE_NAME (decl)))
7536 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
7538 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
7542 e.name = xstrdup (dwarf2_name (decl, 1));
7544 /* If we don't have a name for the type, there's no point in adding
7546 if (e.name && e.name[0] != '\0')
7547 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
7551 /* Output the public names table used to speed up access to externally
7552 visible names; or the public types table used to find type definitions. */
7555 output_pubnames (VEC (pubname_entry, gc) * names)
7558 unsigned long pubnames_length = size_of_pubnames (names);
7561 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7562 dw2_asm_output_data (4, 0xffffffff,
7563 "Initial length escape value indicating 64-bit DWARF extension");
7564 if (names == pubname_table)
7565 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7566 "Length of Public Names Info");
7568 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7569 "Length of Public Type Names Info");
7570 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7571 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7573 "Offset of Compilation Unit Info");
7574 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7575 "Compilation Unit Length");
7577 for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++)
7579 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7580 if (names == pubname_table)
7581 gcc_assert (pub->die->die_mark);
7583 if (names != pubtype_table
7584 || pub->die->die_offset != 0
7585 || !flag_eliminate_unused_debug_types)
7587 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7590 dw2_asm_output_nstring (pub->name, -1, "external name");
7594 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7597 /* Add a new entry to .debug_aranges if appropriate. */
7600 add_arange (tree decl, dw_die_ref die)
7602 if (! DECL_SECTION_NAME (decl))
7605 if (arange_table_in_use == arange_table_allocated)
7607 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7608 arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table,
7609 arange_table_allocated);
7610 memset (arange_table + arange_table_in_use, 0,
7611 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7614 arange_table[arange_table_in_use++] = die;
7617 /* Output the information that goes into the .debug_aranges table.
7618 Namely, define the beginning and ending address range of the
7619 text section generated for this compilation unit. */
7622 output_aranges (void)
7625 unsigned long aranges_length = size_of_aranges ();
7627 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7628 dw2_asm_output_data (4, 0xffffffff,
7629 "Initial length escape value indicating 64-bit DWARF extension");
7630 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7631 "Length of Address Ranges Info");
7632 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7633 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7635 "Offset of Compilation Unit Info");
7636 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7637 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7639 /* We need to align to twice the pointer size here. */
7640 if (DWARF_ARANGES_PAD_SIZE)
7642 /* Pad using a 2 byte words so that padding is correct for any
7644 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7645 2 * DWARF2_ADDR_SIZE);
7646 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7647 dw2_asm_output_data (2, 0, NULL);
7650 /* It is necessary not to output these entries if the sections were
7651 not used; if the sections were not used, the length will be 0 and
7652 the address may end up as 0 if the section is discarded by ld
7653 --gc-sections, leaving an invalid (0, 0) entry that can be
7654 confused with the terminator. */
7655 if (text_section_used)
7657 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7658 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7659 text_section_label, "Length");
7661 if (cold_text_section_used)
7663 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7665 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7666 cold_text_section_label, "Length");
7669 for (i = 0; i < arange_table_in_use; i++)
7671 dw_die_ref die = arange_table[i];
7673 /* We shouldn't see aranges for DIEs outside of the main CU. */
7674 gcc_assert (die->die_mark);
7676 if (die->die_tag == DW_TAG_subprogram)
7678 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7680 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7681 get_AT_low_pc (die), "Length");
7685 /* A static variable; extract the symbol from DW_AT_location.
7686 Note that this code isn't currently hit, as we only emit
7687 aranges for functions (jason 9/23/99). */
7688 dw_attr_ref a = get_AT (die, DW_AT_location);
7689 dw_loc_descr_ref loc;
7691 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7694 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7696 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7697 loc->dw_loc_oprnd1.v.val_addr, "Address");
7698 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7699 get_AT_unsigned (die, DW_AT_byte_size),
7704 /* Output the terminator words. */
7705 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7706 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7709 /* Add a new entry to .debug_ranges. Return the offset at which it
7713 add_ranges_num (int num)
7715 unsigned int in_use = ranges_table_in_use;
7717 if (in_use == ranges_table_allocated)
7719 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7720 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
7721 ranges_table_allocated);
7722 memset (ranges_table + ranges_table_in_use, 0,
7723 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7726 ranges_table[in_use].num = num;
7727 ranges_table_in_use = in_use + 1;
7729 return in_use * 2 * DWARF2_ADDR_SIZE;
7732 /* Add a new entry to .debug_ranges corresponding to a block, or a
7733 range terminator if BLOCK is NULL. */
7736 add_ranges (const_tree block)
7738 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
7741 /* Add a new entry to .debug_ranges corresponding to a pair of
7745 add_ranges_by_labels (const char *begin, const char *end)
7747 unsigned int in_use = ranges_by_label_in_use;
7749 if (in_use == ranges_by_label_allocated)
7751 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
7752 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
7754 ranges_by_label_allocated);
7755 memset (ranges_by_label + ranges_by_label_in_use, 0,
7756 RANGES_TABLE_INCREMENT
7757 * sizeof (struct dw_ranges_by_label_struct));
7760 ranges_by_label[in_use].begin = begin;
7761 ranges_by_label[in_use].end = end;
7762 ranges_by_label_in_use = in_use + 1;
7764 return add_ranges_num (-(int)in_use - 1);
7768 output_ranges (void)
7771 static const char *const start_fmt = "Offset 0x%x";
7772 const char *fmt = start_fmt;
7774 for (i = 0; i < ranges_table_in_use; i++)
7776 int block_num = ranges_table[i].num;
7780 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7781 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7783 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7784 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7786 /* If all code is in the text section, then the compilation
7787 unit base address defaults to DW_AT_low_pc, which is the
7788 base of the text section. */
7789 if (!have_multiple_function_sections)
7791 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7793 fmt, i * 2 * DWARF2_ADDR_SIZE);
7794 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7795 text_section_label, NULL);
7798 /* Otherwise, the compilation unit base address is zero,
7799 which allows us to use absolute addresses, and not worry
7800 about whether the target supports cross-section
7804 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7805 fmt, i * 2 * DWARF2_ADDR_SIZE);
7806 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7812 /* Negative block_num stands for an index into ranges_by_label. */
7813 else if (block_num < 0)
7815 int lab_idx = - block_num - 1;
7817 if (!have_multiple_function_sections)
7821 /* If we ever use add_ranges_by_labels () for a single
7822 function section, all we have to do is to take out
7824 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7825 ranges_by_label[lab_idx].begin,
7827 fmt, i * 2 * DWARF2_ADDR_SIZE);
7828 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
7829 ranges_by_label[lab_idx].end,
7830 text_section_label, NULL);
7835 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7836 ranges_by_label[lab_idx].begin,
7837 fmt, i * 2 * DWARF2_ADDR_SIZE);
7838 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
7839 ranges_by_label[lab_idx].end,
7845 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7846 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7852 /* Data structure containing information about input files. */
7855 const char *path; /* Complete file name. */
7856 const char *fname; /* File name part. */
7857 int length; /* Length of entire string. */
7858 struct dwarf_file_data * file_idx; /* Index in input file table. */
7859 int dir_idx; /* Index in directory table. */
7862 /* Data structure containing information about directories with source
7866 const char *path; /* Path including directory name. */
7867 int length; /* Path length. */
7868 int prefix; /* Index of directory entry which is a prefix. */
7869 int count; /* Number of files in this directory. */
7870 int dir_idx; /* Index of directory used as base. */
7873 /* Callback function for file_info comparison. We sort by looking at
7874 the directories in the path. */
7877 file_info_cmp (const void *p1, const void *p2)
7879 const struct file_info *const s1 = (const struct file_info *) p1;
7880 const struct file_info *const s2 = (const struct file_info *) p2;
7881 const unsigned char *cp1;
7882 const unsigned char *cp2;
7884 /* Take care of file names without directories. We need to make sure that
7885 we return consistent values to qsort since some will get confused if
7886 we return the same value when identical operands are passed in opposite
7887 orders. So if neither has a directory, return 0 and otherwise return
7888 1 or -1 depending on which one has the directory. */
7889 if ((s1->path == s1->fname || s2->path == s2->fname))
7890 return (s2->path == s2->fname) - (s1->path == s1->fname);
7892 cp1 = (const unsigned char *) s1->path;
7893 cp2 = (const unsigned char *) s2->path;
7899 /* Reached the end of the first path? If so, handle like above. */
7900 if ((cp1 == (const unsigned char *) s1->fname)
7901 || (cp2 == (const unsigned char *) s2->fname))
7902 return ((cp2 == (const unsigned char *) s2->fname)
7903 - (cp1 == (const unsigned char *) s1->fname));
7905 /* Character of current path component the same? */
7906 else if (*cp1 != *cp2)
7911 struct file_name_acquire_data
7913 struct file_info *files;
7918 /* Traversal function for the hash table. */
7921 file_name_acquire (void ** slot, void *data)
7923 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
7924 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
7925 struct file_info *fi;
7928 gcc_assert (fnad->max_files >= d->emitted_number);
7930 if (! d->emitted_number)
7933 gcc_assert (fnad->max_files != fnad->used_files);
7935 fi = fnad->files + fnad->used_files++;
7937 /* Skip all leading "./". */
7939 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
7942 /* Create a new array entry. */
7944 fi->length = strlen (f);
7947 /* Search for the file name part. */
7948 f = strrchr (f, DIR_SEPARATOR);
7949 #if defined (DIR_SEPARATOR_2)
7951 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
7955 if (f == NULL || f < g)
7961 fi->fname = f == NULL ? fi->path : f + 1;
7965 /* Output the directory table and the file name table. We try to minimize
7966 the total amount of memory needed. A heuristic is used to avoid large
7967 slowdowns with many input files. */
7970 output_file_names (void)
7972 struct file_name_acquire_data fnad;
7974 struct file_info *files;
7975 struct dir_info *dirs;
7984 if (!last_emitted_file)
7986 dw2_asm_output_data (1, 0, "End directory table");
7987 dw2_asm_output_data (1, 0, "End file name table");
7991 numfiles = last_emitted_file->emitted_number;
7993 /* Allocate the various arrays we need. */
7994 files = XALLOCAVEC (struct file_info, numfiles);
7995 dirs = XALLOCAVEC (struct dir_info, numfiles);
7998 fnad.used_files = 0;
7999 fnad.max_files = numfiles;
8000 htab_traverse (file_table, file_name_acquire, &fnad);
8001 gcc_assert (fnad.used_files == fnad.max_files);
8003 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
8005 /* Find all the different directories used. */
8006 dirs[0].path = files[0].path;
8007 dirs[0].length = files[0].fname - files[0].path;
8008 dirs[0].prefix = -1;
8010 dirs[0].dir_idx = 0;
8011 files[0].dir_idx = 0;
8014 for (i = 1; i < numfiles; i++)
8015 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
8016 && memcmp (dirs[ndirs - 1].path, files[i].path,
8017 dirs[ndirs - 1].length) == 0)
8019 /* Same directory as last entry. */
8020 files[i].dir_idx = ndirs - 1;
8021 ++dirs[ndirs - 1].count;
8027 /* This is a new directory. */
8028 dirs[ndirs].path = files[i].path;
8029 dirs[ndirs].length = files[i].fname - files[i].path;
8030 dirs[ndirs].count = 1;
8031 dirs[ndirs].dir_idx = ndirs;
8032 files[i].dir_idx = ndirs;
8034 /* Search for a prefix. */
8035 dirs[ndirs].prefix = -1;
8036 for (j = 0; j < ndirs; j++)
8037 if (dirs[j].length < dirs[ndirs].length
8038 && dirs[j].length > 1
8039 && (dirs[ndirs].prefix == -1
8040 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
8041 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
8042 dirs[ndirs].prefix = j;
8047 /* Now to the actual work. We have to find a subset of the directories which
8048 allow expressing the file name using references to the directory table
8049 with the least amount of characters. We do not do an exhaustive search
8050 where we would have to check out every combination of every single
8051 possible prefix. Instead we use a heuristic which provides nearly optimal
8052 results in most cases and never is much off. */
8053 saved = XALLOCAVEC (int, ndirs);
8054 savehere = XALLOCAVEC (int, ndirs);
8056 memset (saved, '\0', ndirs * sizeof (saved[0]));
8057 for (i = 0; i < ndirs; i++)
8062 /* We can always save some space for the current directory. But this
8063 does not mean it will be enough to justify adding the directory. */
8064 savehere[i] = dirs[i].length;
8065 total = (savehere[i] - saved[i]) * dirs[i].count;
8067 for (j = i + 1; j < ndirs; j++)
8070 if (saved[j] < dirs[i].length)
8072 /* Determine whether the dirs[i] path is a prefix of the
8077 while (k != -1 && k != (int) i)
8082 /* Yes it is. We can possibly save some memory by
8083 writing the filenames in dirs[j] relative to
8085 savehere[j] = dirs[i].length;
8086 total += (savehere[j] - saved[j]) * dirs[j].count;
8091 /* Check whether we can save enough to justify adding the dirs[i]
8093 if (total > dirs[i].length + 1)
8095 /* It's worthwhile adding. */
8096 for (j = i; j < ndirs; j++)
8097 if (savehere[j] > 0)
8099 /* Remember how much we saved for this directory so far. */
8100 saved[j] = savehere[j];
8102 /* Remember the prefix directory. */
8103 dirs[j].dir_idx = i;
8108 /* Emit the directory name table. */
8110 idx_offset = dirs[0].length > 0 ? 1 : 0;
8111 for (i = 1 - idx_offset; i < ndirs; i++)
8112 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
8113 "Directory Entry: 0x%x", i + idx_offset);
8115 dw2_asm_output_data (1, 0, "End directory table");
8117 /* We have to emit them in the order of emitted_number since that's
8118 used in the debug info generation. To do this efficiently we
8119 generate a back-mapping of the indices first. */
8120 backmap = XALLOCAVEC (int, numfiles);
8121 for (i = 0; i < numfiles; i++)
8122 backmap[files[i].file_idx->emitted_number - 1] = i;
8124 /* Now write all the file names. */
8125 for (i = 0; i < numfiles; i++)
8127 int file_idx = backmap[i];
8128 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
8130 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
8131 "File Entry: 0x%x", (unsigned) i + 1);
8133 /* Include directory index. */
8134 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
8136 /* Modification time. */
8137 dw2_asm_output_data_uleb128 (0, NULL);
8139 /* File length in bytes. */
8140 dw2_asm_output_data_uleb128 (0, NULL);
8143 dw2_asm_output_data (1, 0, "End file name table");
8147 /* Output the source line number correspondence information. This
8148 information goes into the .debug_line section. */
8151 output_line_info (void)
8153 char l1[20], l2[20], p1[20], p2[20];
8154 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8155 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
8158 unsigned long lt_index;
8159 unsigned long current_line;
8162 unsigned long current_file;
8163 unsigned long function;
8165 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
8166 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
8167 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
8168 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
8170 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
8171 dw2_asm_output_data (4, 0xffffffff,
8172 "Initial length escape value indicating 64-bit DWARF extension");
8173 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
8174 "Length of Source Line Info");
8175 ASM_OUTPUT_LABEL (asm_out_file, l1);
8177 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
8178 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
8179 ASM_OUTPUT_LABEL (asm_out_file, p1);
8181 /* Define the architecture-dependent minimum instruction length (in
8182 bytes). In this implementation of DWARF, this field is used for
8183 information purposes only. Since GCC generates assembly language,
8184 we have no a priori knowledge of how many instruction bytes are
8185 generated for each source line, and therefore can use only the
8186 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8187 commands. Accordingly, we fix this as `1', which is "correct
8188 enough" for all architectures, and don't let the target override. */
8189 dw2_asm_output_data (1, 1,
8190 "Minimum Instruction Length");
8192 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
8193 "Default is_stmt_start flag");
8194 dw2_asm_output_data (1, DWARF_LINE_BASE,
8195 "Line Base Value (Special Opcodes)");
8196 dw2_asm_output_data (1, DWARF_LINE_RANGE,
8197 "Line Range Value (Special Opcodes)");
8198 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
8199 "Special Opcode Base");
8201 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
8205 case DW_LNS_advance_pc:
8206 case DW_LNS_advance_line:
8207 case DW_LNS_set_file:
8208 case DW_LNS_set_column:
8209 case DW_LNS_fixed_advance_pc:
8217 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
8221 /* Write out the information about the files we use. */
8222 output_file_names ();
8223 ASM_OUTPUT_LABEL (asm_out_file, p2);
8225 /* We used to set the address register to the first location in the text
8226 section here, but that didn't accomplish anything since we already
8227 have a line note for the opening brace of the first function. */
8229 /* Generate the line number to PC correspondence table, encoded as
8230 a series of state machine operations. */
8234 if (cfun && in_cold_section_p)
8235 strcpy (prev_line_label, crtl->subsections.cold_section_label);
8237 strcpy (prev_line_label, text_section_label);
8238 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
8240 dw_line_info_ref line_info = &line_info_table[lt_index];
8243 /* Disable this optimization for now; GDB wants to see two line notes
8244 at the beginning of a function so it can find the end of the
8247 /* Don't emit anything for redundant notes. Just updating the
8248 address doesn't accomplish anything, because we already assume
8249 that anything after the last address is this line. */
8250 if (line_info->dw_line_num == current_line
8251 && line_info->dw_file_num == current_file)
8255 /* Emit debug info for the address of the current line.
8257 Unfortunately, we have little choice here currently, and must always
8258 use the most general form. GCC does not know the address delta
8259 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8260 attributes which will give an upper bound on the address range. We
8261 could perhaps use length attributes to determine when it is safe to
8262 use DW_LNS_fixed_advance_pc. */
8264 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
8267 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8268 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8269 "DW_LNS_fixed_advance_pc");
8270 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8274 /* This can handle any delta. This takes
8275 4+DWARF2_ADDR_SIZE bytes. */
8276 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8277 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8278 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8279 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8282 strcpy (prev_line_label, line_label);
8284 /* Emit debug info for the source file of the current line, if
8285 different from the previous line. */
8286 if (line_info->dw_file_num != current_file)
8288 current_file = line_info->dw_file_num;
8289 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8290 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8293 /* Emit debug info for the current line number, choosing the encoding
8294 that uses the least amount of space. */
8295 if (line_info->dw_line_num != current_line)
8297 line_offset = line_info->dw_line_num - current_line;
8298 line_delta = line_offset - DWARF_LINE_BASE;
8299 current_line = line_info->dw_line_num;
8300 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8301 /* This can handle deltas from -10 to 234, using the current
8302 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8304 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8305 "line %lu", current_line);
8308 /* This can handle any delta. This takes at least 4 bytes,
8309 depending on the value being encoded. */
8310 dw2_asm_output_data (1, DW_LNS_advance_line,
8311 "advance to line %lu", current_line);
8312 dw2_asm_output_data_sleb128 (line_offset, NULL);
8313 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8317 /* We still need to start a new row, so output a copy insn. */
8318 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8321 /* Emit debug info for the address of the end of the function. */
8324 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8325 "DW_LNS_fixed_advance_pc");
8326 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
8330 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8331 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8332 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8333 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
8336 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8337 dw2_asm_output_data_uleb128 (1, NULL);
8338 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8343 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
8345 dw_separate_line_info_ref line_info
8346 = &separate_line_info_table[lt_index];
8349 /* Don't emit anything for redundant notes. */
8350 if (line_info->dw_line_num == current_line
8351 && line_info->dw_file_num == current_file
8352 && line_info->function == function)
8356 /* Emit debug info for the address of the current line. If this is
8357 a new function, or the first line of a function, then we need
8358 to handle it differently. */
8359 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
8361 if (function != line_info->function)
8363 function = line_info->function;
8365 /* Set the address register to the first line in the function. */
8366 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8367 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8368 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8369 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8373 /* ??? See the DW_LNS_advance_pc comment above. */
8376 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8377 "DW_LNS_fixed_advance_pc");
8378 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8382 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8383 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8384 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8385 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8389 strcpy (prev_line_label, line_label);
8391 /* Emit debug info for the source file of the current line, if
8392 different from the previous line. */
8393 if (line_info->dw_file_num != current_file)
8395 current_file = line_info->dw_file_num;
8396 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
8397 dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
8400 /* Emit debug info for the current line number, choosing the encoding
8401 that uses the least amount of space. */
8402 if (line_info->dw_line_num != current_line)
8404 line_offset = line_info->dw_line_num - current_line;
8405 line_delta = line_offset - DWARF_LINE_BASE;
8406 current_line = line_info->dw_line_num;
8407 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
8408 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
8409 "line %lu", current_line);
8412 dw2_asm_output_data (1, DW_LNS_advance_line,
8413 "advance to line %lu", current_line);
8414 dw2_asm_output_data_sleb128 (line_offset, NULL);
8415 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8419 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
8427 /* If we're done with a function, end its sequence. */
8428 if (lt_index == separate_line_info_table_in_use
8429 || separate_line_info_table[lt_index].function != function)
8434 /* Emit debug info for the address of the end of the function. */
8435 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
8438 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
8439 "DW_LNS_fixed_advance_pc");
8440 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
8444 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8445 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
8446 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
8447 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
8450 /* Output the marker for the end of this sequence. */
8451 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8452 dw2_asm_output_data_uleb128 (1, NULL);
8453 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
8457 /* Output the marker for the end of the line number info. */
8458 ASM_OUTPUT_LABEL (asm_out_file, l2);
8461 /* Given a pointer to a tree node for some base type, return a pointer to
8462 a DIE that describes the given type.
8464 This routine must only be called for GCC type nodes that correspond to
8465 Dwarf base (fundamental) types. */
8468 base_type_die (tree type)
8470 dw_die_ref base_type_result;
8471 enum dwarf_type encoding;
8473 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
8476 switch (TREE_CODE (type))
8479 if (TYPE_STRING_FLAG (type))
8481 if (TYPE_UNSIGNED (type))
8482 encoding = DW_ATE_unsigned_char;
8484 encoding = DW_ATE_signed_char;
8486 else if (TYPE_UNSIGNED (type))
8487 encoding = DW_ATE_unsigned;
8489 encoding = DW_ATE_signed;
8493 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
8494 encoding = DW_ATE_decimal_float;
8496 encoding = DW_ATE_float;
8499 case FIXED_POINT_TYPE:
8500 if (TYPE_UNSIGNED (type))
8501 encoding = DW_ATE_unsigned_fixed;
8503 encoding = DW_ATE_signed_fixed;
8506 /* Dwarf2 doesn't know anything about complex ints, so use
8507 a user defined type for it. */
8509 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8510 encoding = DW_ATE_complex_float;
8512 encoding = DW_ATE_lo_user;
8516 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8517 encoding = DW_ATE_boolean;
8521 /* No other TREE_CODEs are Dwarf fundamental types. */
8525 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8527 /* This probably indicates a bug. */
8528 if (! TYPE_NAME (type))
8529 add_name_attribute (base_type_result, "__unknown__");
8531 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8532 int_size_in_bytes (type));
8533 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8535 return base_type_result;
8538 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8539 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8542 is_base_type (tree type)
8544 switch (TREE_CODE (type))
8550 case FIXED_POINT_TYPE:
8558 case QUAL_UNION_TYPE:
8563 case REFERENCE_TYPE:
8576 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8577 node, return the size in bits for the type if it is a constant, or else
8578 return the alignment for the type if the type's size is not constant, or
8579 else return BITS_PER_WORD if the type actually turns out to be an
8582 static inline unsigned HOST_WIDE_INT
8583 simple_type_size_in_bits (const_tree type)
8585 if (TREE_CODE (type) == ERROR_MARK)
8586 return BITS_PER_WORD;
8587 else if (TYPE_SIZE (type) == NULL_TREE)
8589 else if (host_integerp (TYPE_SIZE (type), 1))
8590 return tree_low_cst (TYPE_SIZE (type), 1);
8592 return TYPE_ALIGN (type);
8595 /* Return true if the debug information for the given type should be
8596 emitted as a subrange type. */
8599 is_subrange_type (const_tree type)
8601 tree subtype = TREE_TYPE (type);
8603 /* Subrange types are identified by the fact that they are integer
8604 types, and that they have a subtype which is either an integer type
8605 or an enumeral type. */
8607 if (TREE_CODE (type) != INTEGER_TYPE
8608 || subtype == NULL_TREE)
8611 if (TREE_CODE (subtype) != INTEGER_TYPE
8612 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8615 if (TREE_CODE (type) == TREE_CODE (subtype)
8616 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8617 && TYPE_MIN_VALUE (type) != NULL
8618 && TYPE_MIN_VALUE (subtype) != NULL
8619 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8620 && TYPE_MAX_VALUE (type) != NULL
8621 && TYPE_MAX_VALUE (subtype) != NULL
8622 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8624 /* The type and its subtype have the same representation. If in
8625 addition the two types also have the same name, then the given
8626 type is not a subrange type, but rather a plain base type. */
8627 /* FIXME: brobecker/2004-03-22:
8628 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8629 therefore be sufficient to check the TYPE_SIZE node pointers
8630 rather than checking the actual size. Unfortunately, we have
8631 found some cases, such as in the Ada "integer" type, where
8632 this is not the case. Until this problem is solved, we need to
8633 keep checking the actual size. */
8634 tree type_name = TYPE_NAME (type);
8635 tree subtype_name = TYPE_NAME (subtype);
8637 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8638 type_name = DECL_NAME (type_name);
8640 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8641 subtype_name = DECL_NAME (subtype_name);
8643 if (type_name == subtype_name)
8650 /* Given a pointer to a tree node for a subrange type, return a pointer
8651 to a DIE that describes the given type. */
8654 subrange_type_die (tree type, dw_die_ref context_die)
8656 dw_die_ref subrange_die;
8657 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8659 if (context_die == NULL)
8660 context_die = comp_unit_die;
8662 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8664 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
8666 /* The size of the subrange type and its base type do not match,
8667 so we need to generate a size attribute for the subrange type. */
8668 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8671 if (TYPE_MIN_VALUE (type) != NULL)
8672 add_bound_info (subrange_die, DW_AT_lower_bound,
8673 TYPE_MIN_VALUE (type));
8674 if (TYPE_MAX_VALUE (type) != NULL)
8675 add_bound_info (subrange_die, DW_AT_upper_bound,
8676 TYPE_MAX_VALUE (type));
8678 return subrange_die;
8681 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8682 entry that chains various modifiers in front of the given type. */
8685 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8686 dw_die_ref context_die)
8688 enum tree_code code = TREE_CODE (type);
8689 dw_die_ref mod_type_die;
8690 dw_die_ref sub_die = NULL;
8691 tree item_type = NULL;
8692 tree qualified_type;
8695 if (code == ERROR_MARK)
8698 /* See if we already have the appropriately qualified variant of
8701 = get_qualified_type (type,
8702 ((is_const_type ? TYPE_QUAL_CONST : 0)
8703 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
8705 /* If we do, then we can just use its DIE, if it exists. */
8708 mod_type_die = lookup_type_die (qualified_type);
8710 return mod_type_die;
8713 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
8715 /* Handle C typedef types. */
8716 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name))
8718 tree dtype = TREE_TYPE (name);
8720 if (qualified_type == dtype)
8722 /* For a named type, use the typedef. */
8723 gen_type_die (qualified_type, context_die);
8724 return lookup_type_die (qualified_type);
8726 else if (is_const_type < TYPE_READONLY (dtype)
8727 || is_volatile_type < TYPE_VOLATILE (dtype)
8728 || (is_const_type <= TYPE_READONLY (dtype)
8729 && is_volatile_type <= TYPE_VOLATILE (dtype)
8730 && DECL_ORIGINAL_TYPE (name) != type))
8731 /* cv-unqualified version of named type. Just use the unnamed
8732 type to which it refers. */
8733 return modified_type_die (DECL_ORIGINAL_TYPE (name),
8734 is_const_type, is_volatile_type,
8736 /* Else cv-qualified version of named type; fall through. */
8741 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8742 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8744 else if (is_volatile_type)
8746 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8747 sub_die = modified_type_die (type, 0, 0, context_die);
8749 else if (code == POINTER_TYPE)
8751 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8752 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8753 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8754 item_type = TREE_TYPE (type);
8756 else if (code == REFERENCE_TYPE)
8758 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8759 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8760 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8761 item_type = TREE_TYPE (type);
8763 else if (is_subrange_type (type))
8765 mod_type_die = subrange_type_die (type, context_die);
8766 item_type = TREE_TYPE (type);
8768 else if (is_base_type (type))
8769 mod_type_die = base_type_die (type);
8772 gen_type_die (type, context_die);
8774 /* We have to get the type_main_variant here (and pass that to the
8775 `lookup_type_die' routine) because the ..._TYPE node we have
8776 might simply be a *copy* of some original type node (where the
8777 copy was created to help us keep track of typedef names) and
8778 that copy might have a different TYPE_UID from the original
8780 if (TREE_CODE (type) != VECTOR_TYPE)
8781 return lookup_type_die (type_main_variant (type));
8783 /* Vectors have the debugging information in the type,
8784 not the main variant. */
8785 return lookup_type_die (type);
8788 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8789 don't output a DW_TAG_typedef, since there isn't one in the
8790 user's program; just attach a DW_AT_name to the type. */
8792 && (TREE_CODE (name) != TYPE_DECL
8793 || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
8795 if (TREE_CODE (name) == TYPE_DECL)
8796 /* Could just call add_name_and_src_coords_attributes here,
8797 but since this is a builtin type it doesn't have any
8798 useful source coordinates anyway. */
8799 name = DECL_NAME (name);
8800 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
8804 equate_type_number_to_die (qualified_type, mod_type_die);
8807 /* We must do this after the equate_type_number_to_die call, in case
8808 this is a recursive type. This ensures that the modified_type_die
8809 recursion will terminate even if the type is recursive. Recursive
8810 types are possible in Ada. */
8811 sub_die = modified_type_die (item_type,
8812 TYPE_READONLY (item_type),
8813 TYPE_VOLATILE (item_type),
8816 if (sub_die != NULL)
8817 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8819 return mod_type_die;
8822 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8823 an enumerated type. */
8826 type_is_enum (const_tree type)
8828 return TREE_CODE (type) == ENUMERAL_TYPE;
8831 /* Return the DBX register number described by a given RTL node. */
8834 dbx_reg_number (const_rtx rtl)
8836 unsigned regno = REGNO (rtl);
8838 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8840 #ifdef LEAF_REG_REMAP
8841 if (current_function_uses_only_leaf_regs)
8843 int leaf_reg = LEAF_REG_REMAP (regno);
8845 regno = (unsigned) leaf_reg;
8849 return DBX_REGISTER_NUMBER (regno);
8852 /* Optionally add a DW_OP_piece term to a location description expression.
8853 DW_OP_piece is only added if the location description expression already
8854 doesn't end with DW_OP_piece. */
8857 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8859 dw_loc_descr_ref loc;
8861 if (*list_head != NULL)
8863 /* Find the end of the chain. */
8864 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8867 if (loc->dw_loc_opc != DW_OP_piece)
8868 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8872 /* Return a location descriptor that designates a machine register or
8873 zero if there is none. */
8875 static dw_loc_descr_ref
8876 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
8880 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8883 regs = targetm.dwarf_register_span (rtl);
8885 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
8886 return multiple_reg_loc_descriptor (rtl, regs, initialized);
8888 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
8891 /* Return a location descriptor that designates a machine register for
8892 a given hard register number. */
8894 static dw_loc_descr_ref
8895 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
8897 dw_loc_descr_ref reg_loc_descr;
8899 reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8901 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
8903 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
8904 add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8906 return reg_loc_descr;
8909 /* Given an RTL of a register, return a location descriptor that
8910 designates a value that spans more than one register. */
8912 static dw_loc_descr_ref
8913 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
8914 enum var_init_status initialized)
8918 dw_loc_descr_ref loc_result = NULL;
8921 #ifdef LEAF_REG_REMAP
8922 if (current_function_uses_only_leaf_regs)
8924 int leaf_reg = LEAF_REG_REMAP (reg);
8926 reg = (unsigned) leaf_reg;
8929 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
8930 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8932 /* Simple, contiguous registers. */
8933 if (regs == NULL_RTX)
8935 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8942 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
8943 VAR_INIT_STATUS_INITIALIZED);
8944 add_loc_descr (&loc_result, t);
8945 add_loc_descr_op_piece (&loc_result, size);
8951 /* Now onto stupid register sets in non contiguous locations. */
8953 gcc_assert (GET_CODE (regs) == PARALLEL);
8955 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8958 for (i = 0; i < XVECLEN (regs, 0); ++i)
8962 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
8963 VAR_INIT_STATUS_INITIALIZED);
8964 add_loc_descr (&loc_result, t);
8965 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8966 add_loc_descr_op_piece (&loc_result, size);
8969 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
8970 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
8974 /* Return a location descriptor that designates a constant. */
8976 static dw_loc_descr_ref
8977 int_loc_descriptor (HOST_WIDE_INT i)
8979 enum dwarf_location_atom op;
8981 /* Pick the smallest representation of a constant, rather than just
8982 defaulting to the LEB encoding. */
8986 op = DW_OP_lit0 + i;
8989 else if (i <= 0xffff)
8991 else if (HOST_BITS_PER_WIDE_INT == 32
9001 else if (i >= -0x8000)
9003 else if (HOST_BITS_PER_WIDE_INT == 32
9004 || i >= -0x80000000)
9010 return new_loc_descr (op, i, 0);
9013 /* Return a location descriptor that designates a base+offset location. */
9015 static dw_loc_descr_ref
9016 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
9017 enum var_init_status initialized)
9020 dw_loc_descr_ref result;
9022 /* We only use "frame base" when we're sure we're talking about the
9023 post-prologue local stack frame. We do this by *not* running
9024 register elimination until this point, and recognizing the special
9025 argument pointer and soft frame pointer rtx's. */
9026 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
9028 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9032 if (GET_CODE (elim) == PLUS)
9034 offset += INTVAL (XEXP (elim, 1));
9035 elim = XEXP (elim, 0);
9037 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
9038 : stack_pointer_rtx));
9039 offset += frame_pointer_fb_offset;
9041 return new_loc_descr (DW_OP_fbreg, offset, 0);
9045 regno = dbx_reg_number (reg);
9047 result = new_loc_descr (DW_OP_breg0 + regno, offset, 0);
9049 result = new_loc_descr (DW_OP_bregx, regno, offset);
9051 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9052 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9057 /* Return true if this RTL expression describes a base+offset calculation. */
9060 is_based_loc (const_rtx rtl)
9062 return (GET_CODE (rtl) == PLUS
9063 && ((REG_P (XEXP (rtl, 0))
9064 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
9065 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
9068 /* Return a descriptor that describes the concatenation of N locations
9069 used to form the address of a memory location. */
9071 static dw_loc_descr_ref
9072 concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode,
9073 enum var_init_status initialized)
9076 dw_loc_descr_ref cc_loc_result = NULL;
9077 unsigned int n = XVECLEN (concatn, 0);
9079 for (i = 0; i < n; ++i)
9081 dw_loc_descr_ref ref;
9082 rtx x = XVECEXP (concatn, 0, i);
9084 ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED);
9088 add_loc_descr (&cc_loc_result, ref);
9089 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9092 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9093 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9095 return cc_loc_result;
9098 /* The following routine converts the RTL for a variable or parameter
9099 (resident in memory) into an equivalent Dwarf representation of a
9100 mechanism for getting the address of that same variable onto the top of a
9101 hypothetical "address evaluation" stack.
9103 When creating memory location descriptors, we are effectively transforming
9104 the RTL for a memory-resident object into its Dwarf postfix expression
9105 equivalent. This routine recursively descends an RTL tree, turning
9106 it into Dwarf postfix code as it goes.
9108 MODE is the mode of the memory reference, needed to handle some
9109 autoincrement addressing modes.
9111 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9112 location list for RTL.
9114 Return 0 if we can't represent the location. */
9116 static dw_loc_descr_ref
9117 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
9118 enum var_init_status initialized)
9120 dw_loc_descr_ref mem_loc_result = NULL;
9121 enum dwarf_location_atom op;
9123 /* Note that for a dynamically sized array, the location we will generate a
9124 description of here will be the lowest numbered location which is
9125 actually within the array. That's *not* necessarily the same as the
9126 zeroth element of the array. */
9128 rtl = targetm.delegitimize_address (rtl);
9130 switch (GET_CODE (rtl))
9135 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9136 just fall into the SUBREG code. */
9138 /* ... fall through ... */
9141 /* The case of a subreg may arise when we have a local (register)
9142 variable or a formal (register) parameter which doesn't quite fill
9143 up an entire register. For now, just assume that it is
9144 legitimate to make the Dwarf info refer to the whole register which
9145 contains the given subreg. */
9146 rtl = XEXP (rtl, 0);
9148 /* ... fall through ... */
9151 /* Whenever a register number forms a part of the description of the
9152 method for calculating the (dynamic) address of a memory resident
9153 object, DWARF rules require the register number be referred to as
9154 a "base register". This distinction is not based in any way upon
9155 what category of register the hardware believes the given register
9156 belongs to. This is strictly DWARF terminology we're dealing with
9157 here. Note that in cases where the location of a memory-resident
9158 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9159 OP_CONST (0)) the actual DWARF location descriptor that we generate
9160 may just be OP_BASEREG (basereg). This may look deceptively like
9161 the object in question was allocated to a register (rather than in
9162 memory) so DWARF consumers need to be aware of the subtle
9163 distinction between OP_REG and OP_BASEREG. */
9164 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
9165 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
9169 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9170 VAR_INIT_STATUS_INITIALIZED);
9171 if (mem_loc_result != 0)
9172 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
9176 rtl = XEXP (rtl, 1);
9178 /* ... fall through ... */
9181 /* Some ports can transform a symbol ref into a label ref, because
9182 the symbol ref is too far away and has to be dumped into a constant
9186 /* Alternatively, the symbol in the constant pool might be referenced
9187 by a different symbol. */
9188 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
9191 rtx tmp = get_pool_constant_mark (rtl, &marked);
9193 if (GET_CODE (tmp) == SYMBOL_REF)
9196 if (CONSTANT_POOL_ADDRESS_P (tmp))
9197 get_pool_constant_mark (tmp, &marked);
9202 /* If all references to this pool constant were optimized away,
9203 it was not output and thus we can't represent it.
9204 FIXME: might try to use DW_OP_const_value here, though
9205 DW_OP_piece complicates it. */
9210 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
9211 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
9212 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
9213 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9217 /* Extract the PLUS expression nested inside and fall into
9219 rtl = XEXP (rtl, 1);
9224 /* Turn these into a PLUS expression and fall into the PLUS code
9226 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
9227 GEN_INT (GET_CODE (rtl) == PRE_INC
9228 ? GET_MODE_UNIT_SIZE (mode)
9229 : -GET_MODE_UNIT_SIZE (mode)));
9231 /* ... fall through ... */
9235 if (is_based_loc (rtl))
9236 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
9237 INTVAL (XEXP (rtl, 1)),
9238 VAR_INIT_STATUS_INITIALIZED);
9241 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
9242 VAR_INIT_STATUS_INITIALIZED);
9243 if (mem_loc_result == 0)
9246 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
9247 && INTVAL (XEXP (rtl, 1)) >= 0)
9248 add_loc_descr (&mem_loc_result,
9249 new_loc_descr (DW_OP_plus_uconst,
9250 INTVAL (XEXP (rtl, 1)), 0));
9253 add_loc_descr (&mem_loc_result,
9254 mem_loc_descriptor (XEXP (rtl, 1), mode,
9255 VAR_INIT_STATUS_INITIALIZED));
9256 add_loc_descr (&mem_loc_result,
9257 new_loc_descr (DW_OP_plus, 0, 0));
9262 /* If a pseudo-reg is optimized away, it is possible for it to
9263 be replaced with a MEM containing a multiply or shift. */
9282 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
9283 VAR_INIT_STATUS_INITIALIZED);
9284 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
9285 VAR_INIT_STATUS_INITIALIZED);
9287 if (op0 == 0 || op1 == 0)
9290 mem_loc_result = op0;
9291 add_loc_descr (&mem_loc_result, op1);
9292 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
9297 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
9301 mem_loc_result = concatn_mem_loc_descriptor (rtl, mode,
9302 VAR_INIT_STATUS_INITIALIZED);
9309 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9310 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9312 return mem_loc_result;
9315 /* Return a descriptor that describes the concatenation of two locations.
9316 This is typically a complex variable. */
9318 static dw_loc_descr_ref
9319 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
9321 dw_loc_descr_ref cc_loc_result = NULL;
9322 dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED);
9323 dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED);
9325 if (x0_ref == 0 || x1_ref == 0)
9328 cc_loc_result = x0_ref;
9329 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
9331 add_loc_descr (&cc_loc_result, x1_ref);
9332 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
9334 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
9335 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9337 return cc_loc_result;
9340 /* Return a descriptor that describes the concatenation of N
9343 static dw_loc_descr_ref
9344 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
9347 dw_loc_descr_ref cc_loc_result = NULL;
9348 unsigned int n = XVECLEN (concatn, 0);
9350 for (i = 0; i < n; ++i)
9352 dw_loc_descr_ref ref;
9353 rtx x = XVECEXP (concatn, 0, i);
9355 ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED);
9359 add_loc_descr (&cc_loc_result, ref);
9360 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
9363 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
9364 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
9366 return cc_loc_result;
9369 /* Output a proper Dwarf location descriptor for a variable or parameter
9370 which is either allocated in a register or in a memory location. For a
9371 register, we just generate an OP_REG and the register number. For a
9372 memory location we provide a Dwarf postfix expression describing how to
9373 generate the (dynamic) address of the object onto the address stack.
9375 If we don't know how to describe it, return 0. */
9377 static dw_loc_descr_ref
9378 loc_descriptor (rtx rtl, enum var_init_status initialized)
9380 dw_loc_descr_ref loc_result = NULL;
9382 switch (GET_CODE (rtl))
9385 /* The case of a subreg may arise when we have a local (register)
9386 variable or a formal (register) parameter which doesn't quite fill
9387 up an entire register. For now, just assume that it is
9388 legitimate to make the Dwarf info refer to the whole register which
9389 contains the given subreg. */
9390 rtl = SUBREG_REG (rtl);
9392 /* ... fall through ... */
9395 loc_result = reg_loc_descriptor (rtl, initialized);
9399 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
9404 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
9409 loc_result = concatn_loc_descriptor (rtl, initialized);
9414 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
9416 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized);
9420 rtl = XEXP (rtl, 1);
9425 rtvec par_elems = XVEC (rtl, 0);
9426 int num_elem = GET_NUM_ELEM (par_elems);
9427 enum machine_mode mode;
9430 /* Create the first one, so we have something to add to. */
9431 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
9433 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
9434 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9435 for (i = 1; i < num_elem; i++)
9437 dw_loc_descr_ref temp;
9439 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
9441 add_loc_descr (&loc_result, temp);
9442 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
9443 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
9455 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9456 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9457 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9458 top-level invocation, and we require the address of LOC; is 0 if we require
9459 the value of LOC. */
9461 static dw_loc_descr_ref
9462 loc_descriptor_from_tree_1 (tree loc, int want_address)
9464 dw_loc_descr_ref ret, ret1;
9465 int have_address = 0;
9466 enum dwarf_location_atom op;
9468 /* ??? Most of the time we do not take proper care for sign/zero
9469 extending the values properly. Hopefully this won't be a real
9472 switch (TREE_CODE (loc))
9477 case PLACEHOLDER_EXPR:
9478 /* This case involves extracting fields from an object to determine the
9479 position of other fields. We don't try to encode this here. The
9480 only user of this is Ada, which encodes the needed information using
9481 the names of types. */
9487 case PREINCREMENT_EXPR:
9488 case PREDECREMENT_EXPR:
9489 case POSTINCREMENT_EXPR:
9490 case POSTDECREMENT_EXPR:
9491 /* There are no opcodes for these operations. */
9495 /* If we already want an address, there's nothing we can do. */
9499 /* Otherwise, process the argument and look for the address. */
9500 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
9503 if (DECL_THREAD_LOCAL_P (loc))
9509 if (targetm.have_tls)
9511 /* If this is not defined, we have no way to emit the
9513 if (!targetm.asm_out.output_dwarf_dtprel)
9516 /* The way DW_OP_GNU_push_tls_address is specified, we
9517 can only look up addresses of objects in the current
9519 if (DECL_EXTERNAL (loc))
9521 first_op = INTERNAL_DW_OP_tls_addr;
9522 second_op = DW_OP_GNU_push_tls_address;
9526 if (!targetm.emutls.debug_form_tls_address)
9528 loc = emutls_decl (loc);
9529 first_op = DW_OP_addr;
9530 second_op = DW_OP_form_tls_address;
9533 rtl = rtl_for_decl_location (loc);
9534 if (rtl == NULL_RTX)
9539 rtl = XEXP (rtl, 0);
9540 if (! CONSTANT_P (rtl))
9543 ret = new_loc_descr (first_op, 0, 0);
9544 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9545 ret->dw_loc_oprnd1.v.val_addr = rtl;
9547 ret1 = new_loc_descr (second_op, 0, 0);
9548 add_loc_descr (&ret, ret1);
9556 if (DECL_HAS_VALUE_EXPR_P (loc))
9557 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9564 rtx rtl = rtl_for_decl_location (loc);
9566 if (rtl == NULL_RTX)
9568 else if (GET_CODE (rtl) == CONST_INT)
9570 HOST_WIDE_INT val = INTVAL (rtl);
9571 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9572 val &= GET_MODE_MASK (DECL_MODE (loc));
9573 ret = int_loc_descriptor (val);
9575 else if (GET_CODE (rtl) == CONST_STRING)
9577 else if (CONSTANT_P (rtl))
9579 ret = new_loc_descr (DW_OP_addr, 0, 0);
9580 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9581 ret->dw_loc_oprnd1.v.val_addr = rtl;
9585 enum machine_mode mode;
9587 /* Certain constructs can only be represented at top-level. */
9588 if (want_address == 2)
9589 return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED);
9591 mode = GET_MODE (rtl);
9594 rtl = XEXP (rtl, 0);
9597 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9603 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9608 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9611 case VIEW_CONVERT_EXPR:
9613 case GIMPLE_MODIFY_STMT:
9614 return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc, 0),
9620 case ARRAY_RANGE_REF:
9623 HOST_WIDE_INT bitsize, bitpos, bytepos;
9624 enum machine_mode mode;
9626 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
9628 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9629 &unsignedp, &volatilep, false);
9634 ret = loc_descriptor_from_tree_1 (obj, 1);
9636 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9639 if (offset != NULL_TREE)
9641 /* Variable offset. */
9642 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9643 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9646 bytepos = bitpos / BITS_PER_UNIT;
9648 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9649 else if (bytepos < 0)
9651 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9652 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9660 if (host_integerp (loc, 0))
9661 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9668 /* Get an RTL for this, if something has been emitted. */
9669 rtx rtl = lookup_constant_def (loc);
9670 enum machine_mode mode;
9672 if (!rtl || !MEM_P (rtl))
9674 mode = GET_MODE (rtl);
9675 rtl = XEXP (rtl, 0);
9676 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
9681 case TRUTH_AND_EXPR:
9682 case TRUTH_ANDIF_EXPR:
9687 case TRUTH_XOR_EXPR:
9693 case TRUTH_ORIF_EXPR:
9698 case FLOOR_DIV_EXPR:
9700 case ROUND_DIV_EXPR:
9701 case TRUNC_DIV_EXPR:
9709 case FLOOR_MOD_EXPR:
9711 case ROUND_MOD_EXPR:
9712 case TRUNC_MOD_EXPR:
9725 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
9728 case POINTER_PLUS_EXPR:
9730 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9731 && host_integerp (TREE_OPERAND (loc, 1), 0))
9733 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9737 add_loc_descr (&ret,
9738 new_loc_descr (DW_OP_plus_uconst,
9739 tree_low_cst (TREE_OPERAND (loc, 1),
9749 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9756 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9763 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9770 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9785 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9786 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9787 if (ret == 0 || ret1 == 0)
9790 add_loc_descr (&ret, ret1);
9791 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9794 case TRUTH_NOT_EXPR:
9808 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9812 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9818 const enum tree_code code =
9819 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9821 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9822 build2 (code, integer_type_node,
9823 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9824 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9827 /* ... fall through ... */
9831 dw_loc_descr_ref lhs
9832 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9833 dw_loc_descr_ref rhs
9834 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9835 dw_loc_descr_ref bra_node, jump_node, tmp;
9837 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9838 if (ret == 0 || lhs == 0 || rhs == 0)
9841 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9842 add_loc_descr (&ret, bra_node);
9844 add_loc_descr (&ret, rhs);
9845 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9846 add_loc_descr (&ret, jump_node);
9848 add_loc_descr (&ret, lhs);
9849 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9850 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9852 /* ??? Need a node to point the skip at. Use a nop. */
9853 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9854 add_loc_descr (&ret, tmp);
9855 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9856 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9860 case FIX_TRUNC_EXPR:
9864 /* Leave front-end specific codes as simply unknown. This comes
9865 up, for instance, with the C STMT_EXPR. */
9866 if ((unsigned int) TREE_CODE (loc)
9867 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9870 #ifdef ENABLE_CHECKING
9871 /* Otherwise this is a generic code; we should just lists all of
9872 these explicitly. We forgot one. */
9875 /* In a release build, we want to degrade gracefully: better to
9876 generate incomplete debugging information than to crash. */
9881 /* Show if we can't fill the request for an address. */
9882 if (want_address && !have_address)
9885 /* If we've got an address and don't want one, dereference. */
9886 if (!want_address && have_address && ret)
9888 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9890 if (size > DWARF2_ADDR_SIZE || size == -1)
9892 else if (size == DWARF2_ADDR_SIZE)
9895 op = DW_OP_deref_size;
9897 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9903 static inline dw_loc_descr_ref
9904 loc_descriptor_from_tree (tree loc)
9906 return loc_descriptor_from_tree_1 (loc, 2);
9909 /* Given a value, round it up to the lowest multiple of `boundary'
9910 which is not less than the value itself. */
9912 static inline HOST_WIDE_INT
9913 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9915 return (((value + boundary - 1) / boundary) * boundary);
9918 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9919 pointer to the declared type for the relevant field variable, or return
9920 `integer_type_node' if the given node turns out to be an
9924 field_type (const_tree decl)
9928 if (TREE_CODE (decl) == ERROR_MARK)
9929 return integer_type_node;
9931 type = DECL_BIT_FIELD_TYPE (decl);
9932 if (type == NULL_TREE)
9933 type = TREE_TYPE (decl);
9938 /* Given a pointer to a tree node, return the alignment in bits for
9939 it, or else return BITS_PER_WORD if the node actually turns out to
9940 be an ERROR_MARK node. */
9942 static inline unsigned
9943 simple_type_align_in_bits (const_tree type)
9945 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9948 static inline unsigned
9949 simple_decl_align_in_bits (const_tree decl)
9951 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9954 /* Return the result of rounding T up to ALIGN. */
9956 static inline HOST_WIDE_INT
9957 round_up_to_align (HOST_WIDE_INT t, unsigned int align)
9959 /* We must be careful if T is negative because HOST_WIDE_INT can be
9960 either "above" or "below" unsigned int as per the C promotion
9961 rules, depending on the host, thus making the signedness of the
9962 direct multiplication and division unpredictable. */
9963 unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
9969 return (HOST_WIDE_INT) u;
9972 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9973 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9974 or return 0 if we are unable to determine what that offset is, either
9975 because the argument turns out to be a pointer to an ERROR_MARK node, or
9976 because the offset is actually variable. (We can't handle the latter case
9979 static HOST_WIDE_INT
9980 field_byte_offset (const_tree decl)
9982 HOST_WIDE_INT object_offset_in_bits;
9983 HOST_WIDE_INT bitpos_int;
9985 if (TREE_CODE (decl) == ERROR_MARK)
9988 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9990 /* We cannot yet cope with fields whose positions are variable, so
9991 for now, when we see such things, we simply return 0. Someday, we may
9992 be able to handle such cases, but it will be damn difficult. */
9993 if (! host_integerp (bit_position (decl), 0))
9996 bitpos_int = int_bit_position (decl);
9998 #ifdef PCC_BITFIELD_TYPE_MATTERS
9999 if (PCC_BITFIELD_TYPE_MATTERS)
10002 tree field_size_tree;
10003 HOST_WIDE_INT deepest_bitpos;
10004 unsigned HOST_WIDE_INT field_size_in_bits;
10005 unsigned int type_align_in_bits;
10006 unsigned int decl_align_in_bits;
10007 unsigned HOST_WIDE_INT type_size_in_bits;
10009 type = field_type (decl);
10010 field_size_tree = DECL_SIZE (decl);
10012 /* The size could be unspecified if there was an error, or for
10013 a flexible array member. */
10014 if (! field_size_tree)
10015 field_size_tree = bitsize_zero_node;
10017 /* If we don't know the size of the field, pretend it's a full word. */
10018 if (host_integerp (field_size_tree, 1))
10019 field_size_in_bits = tree_low_cst (field_size_tree, 1);
10021 field_size_in_bits = BITS_PER_WORD;
10023 type_size_in_bits = simple_type_size_in_bits (type);
10024 type_align_in_bits = simple_type_align_in_bits (type);
10025 decl_align_in_bits = simple_decl_align_in_bits (decl);
10027 /* The GCC front-end doesn't make any attempt to keep track of the
10028 starting bit offset (relative to the start of the containing
10029 structure type) of the hypothetical "containing object" for a
10030 bit-field. Thus, when computing the byte offset value for the
10031 start of the "containing object" of a bit-field, we must deduce
10032 this information on our own. This can be rather tricky to do in
10033 some cases. For example, handling the following structure type
10034 definition when compiling for an i386/i486 target (which only
10035 aligns long long's to 32-bit boundaries) can be very tricky:
10037 struct S { int field1; long long field2:31; };
10039 Fortunately, there is a simple rule-of-thumb which can be used
10040 in such cases. When compiling for an i386/i486, GCC will
10041 allocate 8 bytes for the structure shown above. It decides to
10042 do this based upon one simple rule for bit-field allocation.
10043 GCC allocates each "containing object" for each bit-field at
10044 the first (i.e. lowest addressed) legitimate alignment boundary
10045 (based upon the required minimum alignment for the declared
10046 type of the field) which it can possibly use, subject to the
10047 condition that there is still enough available space remaining
10048 in the containing object (when allocated at the selected point)
10049 to fully accommodate all of the bits of the bit-field itself.
10051 This simple rule makes it obvious why GCC allocates 8 bytes for
10052 each object of the structure type shown above. When looking
10053 for a place to allocate the "containing object" for `field2',
10054 the compiler simply tries to allocate a 64-bit "containing
10055 object" at each successive 32-bit boundary (starting at zero)
10056 until it finds a place to allocate that 64- bit field such that
10057 at least 31 contiguous (and previously unallocated) bits remain
10058 within that selected 64 bit field. (As it turns out, for the
10059 example above, the compiler finds it is OK to allocate the
10060 "containing object" 64-bit field at bit-offset zero within the
10063 Here we attempt to work backwards from the limited set of facts
10064 we're given, and we try to deduce from those facts, where GCC
10065 must have believed that the containing object started (within
10066 the structure type). The value we deduce is then used (by the
10067 callers of this routine) to generate DW_AT_location and
10068 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10069 the case of DW_AT_location, regular fields as well). */
10071 /* Figure out the bit-distance from the start of the structure to
10072 the "deepest" bit of the bit-field. */
10073 deepest_bitpos = bitpos_int + field_size_in_bits;
10075 /* This is the tricky part. Use some fancy footwork to deduce
10076 where the lowest addressed bit of the containing object must
10078 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10080 /* Round up to type_align by default. This works best for
10082 object_offset_in_bits
10083 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
10085 if (object_offset_in_bits > bitpos_int)
10087 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
10089 /* Round up to decl_align instead. */
10090 object_offset_in_bits
10091 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
10096 object_offset_in_bits = bitpos_int;
10098 return object_offset_in_bits / BITS_PER_UNIT;
10101 /* The following routines define various Dwarf attributes and any data
10102 associated with them. */
10104 /* Add a location description attribute value to a DIE.
10106 This emits location attributes suitable for whole variables and
10107 whole parameters. Note that the location attributes for struct fields are
10108 generated by the routine `data_member_location_attribute' below. */
10111 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
10112 dw_loc_descr_ref descr)
10115 add_AT_loc (die, attr_kind, descr);
10118 /* Attach the specialized form of location attribute used for data members of
10119 struct and union types. In the special case of a FIELD_DECL node which
10120 represents a bit-field, the "offset" part of this special location
10121 descriptor must indicate the distance in bytes from the lowest-addressed
10122 byte of the containing struct or union type to the lowest-addressed byte of
10123 the "containing object" for the bit-field. (See the `field_byte_offset'
10126 For any given bit-field, the "containing object" is a hypothetical object
10127 (of some integral or enum type) within which the given bit-field lives. The
10128 type of this hypothetical "containing object" is always the same as the
10129 declared type of the individual bit-field itself (for GCC anyway... the
10130 DWARF spec doesn't actually mandate this). Note that it is the size (in
10131 bytes) of the hypothetical "containing object" which will be given in the
10132 DW_AT_byte_size attribute for this bit-field. (See the
10133 `byte_size_attribute' function below.) It is also used when calculating the
10134 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10135 function below.) */
10138 add_data_member_location_attribute (dw_die_ref die, tree decl)
10140 HOST_WIDE_INT offset;
10141 dw_loc_descr_ref loc_descr = 0;
10143 if (TREE_CODE (decl) == TREE_BINFO)
10145 /* We're working on the TAG_inheritance for a base class. */
10146 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
10148 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10149 aren't at a fixed offset from all (sub)objects of the same
10150 type. We need to extract the appropriate offset from our
10151 vtable. The following dwarf expression means
10153 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10155 This is specific to the V3 ABI, of course. */
10157 dw_loc_descr_ref tmp;
10159 /* Make a copy of the object address. */
10160 tmp = new_loc_descr (DW_OP_dup, 0, 0);
10161 add_loc_descr (&loc_descr, tmp);
10163 /* Extract the vtable address. */
10164 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10165 add_loc_descr (&loc_descr, tmp);
10167 /* Calculate the address of the offset. */
10168 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
10169 gcc_assert (offset < 0);
10171 tmp = int_loc_descriptor (-offset);
10172 add_loc_descr (&loc_descr, tmp);
10173 tmp = new_loc_descr (DW_OP_minus, 0, 0);
10174 add_loc_descr (&loc_descr, tmp);
10176 /* Extract the offset. */
10177 tmp = new_loc_descr (DW_OP_deref, 0, 0);
10178 add_loc_descr (&loc_descr, tmp);
10180 /* Add it to the object address. */
10181 tmp = new_loc_descr (DW_OP_plus, 0, 0);
10182 add_loc_descr (&loc_descr, tmp);
10185 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
10188 offset = field_byte_offset (decl);
10192 enum dwarf_location_atom op;
10194 /* The DWARF2 standard says that we should assume that the structure
10195 address is already on the stack, so we can specify a structure field
10196 address by using DW_OP_plus_uconst. */
10198 #ifdef MIPS_DEBUGGING_INFO
10199 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10200 operator correctly. It works only if we leave the offset on the
10204 op = DW_OP_plus_uconst;
10207 loc_descr = new_loc_descr (op, offset, 0);
10210 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
10213 /* Writes integer values to dw_vec_const array. */
10216 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
10220 *dest++ = val & 0xff;
10226 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10228 static HOST_WIDE_INT
10229 extract_int (const unsigned char *src, unsigned int size)
10231 HOST_WIDE_INT val = 0;
10237 val |= *--src & 0xff;
10243 /* Writes floating point values to dw_vec_const array. */
10246 insert_float (const_rtx rtl, unsigned char *array)
10248 REAL_VALUE_TYPE rv;
10252 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
10253 real_to_target (val, &rv, GET_MODE (rtl));
10255 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10256 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
10258 insert_int (val[i], 4, array);
10263 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10264 does not have a "location" either in memory or in a register. These
10265 things can arise in GNU C when a constant is passed as an actual parameter
10266 to an inlined function. They can also arise in C++ where declared
10267 constants do not necessarily get memory "homes". */
10270 add_const_value_attribute (dw_die_ref die, rtx rtl)
10272 switch (GET_CODE (rtl))
10276 HOST_WIDE_INT val = INTVAL (rtl);
10279 add_AT_int (die, DW_AT_const_value, val);
10281 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
10286 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10287 floating-point constant. A CONST_DOUBLE is used whenever the
10288 constant requires more than one word in order to be adequately
10289 represented. We output CONST_DOUBLEs as blocks. */
10291 enum machine_mode mode = GET_MODE (rtl);
10293 if (SCALAR_FLOAT_MODE_P (mode))
10295 unsigned int length = GET_MODE_SIZE (mode);
10296 unsigned char *array = GGC_NEWVEC (unsigned char, length);
10298 insert_float (rtl, array);
10299 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
10303 /* ??? We really should be using HOST_WIDE_INT throughout. */
10304 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
10306 add_AT_long_long (die, DW_AT_const_value,
10307 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
10314 enum machine_mode mode = GET_MODE (rtl);
10315 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
10316 unsigned int length = CONST_VECTOR_NUNITS (rtl);
10317 unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size);
10321 switch (GET_MODE_CLASS (mode))
10323 case MODE_VECTOR_INT:
10324 for (i = 0, p = array; i < length; i++, p += elt_size)
10326 rtx elt = CONST_VECTOR_ELT (rtl, i);
10327 HOST_WIDE_INT lo, hi;
10329 switch (GET_CODE (elt))
10337 lo = CONST_DOUBLE_LOW (elt);
10338 hi = CONST_DOUBLE_HIGH (elt);
10342 gcc_unreachable ();
10345 if (elt_size <= sizeof (HOST_WIDE_INT))
10346 insert_int (lo, elt_size, p);
10349 unsigned char *p0 = p;
10350 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
10352 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
10353 if (WORDS_BIG_ENDIAN)
10358 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
10359 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
10364 case MODE_VECTOR_FLOAT:
10365 for (i = 0, p = array; i < length; i++, p += elt_size)
10367 rtx elt = CONST_VECTOR_ELT (rtl, i);
10368 insert_float (elt, p);
10373 gcc_unreachable ();
10376 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
10381 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
10387 add_AT_addr (die, DW_AT_const_value, rtl);
10388 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
10392 /* In cases where an inlined instance of an inline function is passed
10393 the address of an `auto' variable (which is local to the caller) we
10394 can get a situation where the DECL_RTL of the artificial local
10395 variable (for the inlining) which acts as a stand-in for the
10396 corresponding formal parameter (of the inline function) will look
10397 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10398 exactly a compile-time constant expression, but it isn't the address
10399 of the (artificial) local variable either. Rather, it represents the
10400 *value* which the artificial local variable always has during its
10401 lifetime. We currently have no way to represent such quasi-constant
10402 values in Dwarf, so for now we just punt and generate nothing. */
10406 /* No other kinds of rtx should be possible here. */
10407 gcc_unreachable ();
10412 /* Determine whether the evaluation of EXPR references any variables
10413 or functions which aren't otherwise used (and therefore may not be
10416 reference_to_unused (tree * tp, int * walk_subtrees,
10417 void * data ATTRIBUTE_UNUSED)
10419 if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp))
10420 *walk_subtrees = 0;
10422 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
10423 && ! TREE_ASM_WRITTEN (*tp))
10425 else if (!flag_unit_at_a_time)
10427 /* ??? The C++ FE emits debug information for using decls, so
10428 putting gcc_unreachable here falls over. See PR31899. For now
10429 be conservative. */
10430 else if (!cgraph_global_info_ready
10431 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
10433 else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
10435 struct varpool_node *node = varpool_node (*tp);
10439 else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL
10440 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
10442 struct cgraph_node *node = cgraph_node (*tp);
10446 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
10452 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10453 for use in a later add_const_value_attribute call. */
10456 rtl_for_decl_init (tree init, tree type)
10458 rtx rtl = NULL_RTX;
10460 /* If a variable is initialized with a string constant without embedded
10461 zeros, build CONST_STRING. */
10462 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
10464 tree enttype = TREE_TYPE (type);
10465 tree domain = TYPE_DOMAIN (type);
10466 enum machine_mode mode = TYPE_MODE (enttype);
10468 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
10470 && integer_zerop (TYPE_MIN_VALUE (domain))
10471 && compare_tree_int (TYPE_MAX_VALUE (domain),
10472 TREE_STRING_LENGTH (init) - 1) == 0
10473 && ((size_t) TREE_STRING_LENGTH (init)
10474 == strlen (TREE_STRING_POINTER (init)) + 1))
10475 rtl = gen_rtx_CONST_STRING (VOIDmode,
10476 ggc_strdup (TREE_STRING_POINTER (init)));
10478 /* Other aggregates, and complex values, could be represented using
10480 else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
10482 /* Vectors only work if their mode is supported by the target.
10483 FIXME: generic vectors ought to work too. */
10484 else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode)
10486 /* If the initializer is something that we know will expand into an
10487 immediate RTL constant, expand it now. We must be careful not to
10488 reference variables which won't be output. */
10489 else if (initializer_constant_valid_p (init, type)
10490 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
10492 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10494 if (TREE_CODE (type) == VECTOR_TYPE)
10495 switch (TREE_CODE (init))
10500 if (TREE_CONSTANT (init))
10502 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
10503 bool constant_p = true;
10505 unsigned HOST_WIDE_INT ix;
10507 /* Even when ctor is constant, it might contain non-*_CST
10508 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10509 belong into VECTOR_CST nodes. */
10510 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
10511 if (!CONSTANT_CLASS_P (value))
10513 constant_p = false;
10519 init = build_vector_from_ctor (type, elts);
10529 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
10531 /* If expand_expr returns a MEM, it wasn't immediate. */
10532 gcc_assert (!rtl || !MEM_P (rtl));
10538 /* Generate RTL for the variable DECL to represent its location. */
10541 rtl_for_decl_location (tree decl)
10545 /* Here we have to decide where we are going to say the parameter "lives"
10546 (as far as the debugger is concerned). We only have a couple of
10547 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10549 DECL_RTL normally indicates where the parameter lives during most of the
10550 activation of the function. If optimization is enabled however, this
10551 could be either NULL or else a pseudo-reg. Both of those cases indicate
10552 that the parameter doesn't really live anywhere (as far as the code
10553 generation parts of GCC are concerned) during most of the function's
10554 activation. That will happen (for example) if the parameter is never
10555 referenced within the function.
10557 We could just generate a location descriptor here for all non-NULL
10558 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10559 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10560 where DECL_RTL is NULL or is a pseudo-reg.
10562 Note however that we can only get away with using DECL_INCOMING_RTL as
10563 a backup substitute for DECL_RTL in certain limited cases. In cases
10564 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10565 we can be sure that the parameter was passed using the same type as it is
10566 declared to have within the function, and that its DECL_INCOMING_RTL
10567 points us to a place where a value of that type is passed.
10569 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10570 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10571 because in these cases DECL_INCOMING_RTL points us to a value of some
10572 type which is *different* from the type of the parameter itself. Thus,
10573 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10574 such cases, the debugger would end up (for example) trying to fetch a
10575 `float' from a place which actually contains the first part of a
10576 `double'. That would lead to really incorrect and confusing
10577 output at debug-time.
10579 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10580 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10581 are a couple of exceptions however. On little-endian machines we can
10582 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10583 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10584 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10585 when (on a little-endian machine) a non-prototyped function has a
10586 parameter declared to be of type `short' or `char'. In such cases,
10587 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10588 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10589 passed `int' value. If the debugger then uses that address to fetch
10590 a `short' or a `char' (on a little-endian machine) the result will be
10591 the correct data, so we allow for such exceptional cases below.
10593 Note that our goal here is to describe the place where the given formal
10594 parameter lives during most of the function's activation (i.e. between the
10595 end of the prologue and the start of the epilogue). We'll do that as best
10596 as we can. Note however that if the given formal parameter is modified
10597 sometime during the execution of the function, then a stack backtrace (at
10598 debug-time) will show the function as having been called with the *new*
10599 value rather than the value which was originally passed in. This happens
10600 rarely enough that it is not a major problem, but it *is* a problem, and
10601 I'd like to fix it.
10603 A future version of dwarf2out.c may generate two additional attributes for
10604 any given DW_TAG_formal_parameter DIE which will describe the "passed
10605 type" and the "passed location" for the given formal parameter in addition
10606 to the attributes we now generate to indicate the "declared type" and the
10607 "active location" for each parameter. This additional set of attributes
10608 could be used by debuggers for stack backtraces. Separately, note that
10609 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10610 This happens (for example) for inlined-instances of inline function formal
10611 parameters which are never referenced. This really shouldn't be
10612 happening. All PARM_DECL nodes should get valid non-NULL
10613 DECL_INCOMING_RTL values. FIXME. */
10615 /* Use DECL_RTL as the "location" unless we find something better. */
10616 rtl = DECL_RTL_IF_SET (decl);
10618 /* When generating abstract instances, ignore everything except
10619 constants, symbols living in memory, and symbols living in
10620 fixed registers. */
10621 if (! reload_completed)
10624 && (CONSTANT_P (rtl)
10626 && CONSTANT_P (XEXP (rtl, 0)))
10628 && TREE_CODE (decl) == VAR_DECL
10629 && TREE_STATIC (decl))))
10631 rtl = targetm.delegitimize_address (rtl);
10636 else if (TREE_CODE (decl) == PARM_DECL)
10638 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
10640 tree declared_type = TREE_TYPE (decl);
10641 tree passed_type = DECL_ARG_TYPE (decl);
10642 enum machine_mode dmode = TYPE_MODE (declared_type);
10643 enum machine_mode pmode = TYPE_MODE (passed_type);
10645 /* This decl represents a formal parameter which was optimized out.
10646 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10647 all cases where (rtl == NULL_RTX) just below. */
10648 if (dmode == pmode)
10649 rtl = DECL_INCOMING_RTL (decl);
10650 else if (SCALAR_INT_MODE_P (dmode)
10651 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10652 && DECL_INCOMING_RTL (decl))
10654 rtx inc = DECL_INCOMING_RTL (decl);
10657 else if (MEM_P (inc))
10659 if (BYTES_BIG_ENDIAN)
10660 rtl = adjust_address_nv (inc, dmode,
10661 GET_MODE_SIZE (pmode)
10662 - GET_MODE_SIZE (dmode));
10669 /* If the parm was passed in registers, but lives on the stack, then
10670 make a big endian correction if the mode of the type of the
10671 parameter is not the same as the mode of the rtl. */
10672 /* ??? This is the same series of checks that are made in dbxout.c before
10673 we reach the big endian correction code there. It isn't clear if all
10674 of these checks are necessary here, but keeping them all is the safe
10676 else if (MEM_P (rtl)
10677 && XEXP (rtl, 0) != const0_rtx
10678 && ! CONSTANT_P (XEXP (rtl, 0))
10679 /* Not passed in memory. */
10680 && !MEM_P (DECL_INCOMING_RTL (decl))
10681 /* Not passed by invisible reference. */
10682 && (!REG_P (XEXP (rtl, 0))
10683 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10684 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10685 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10686 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10689 /* Big endian correction check. */
10690 && BYTES_BIG_ENDIAN
10691 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10692 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10695 int offset = (UNITS_PER_WORD
10696 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10698 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10699 plus_constant (XEXP (rtl, 0), offset));
10702 else if (TREE_CODE (decl) == VAR_DECL
10705 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10706 && BYTES_BIG_ENDIAN)
10708 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10709 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10711 /* If a variable is declared "register" yet is smaller than
10712 a register, then if we store the variable to memory, it
10713 looks like we're storing a register-sized value, when in
10714 fact we are not. We need to adjust the offset of the
10715 storage location to reflect the actual value's bytes,
10716 else gdb will not be able to display it. */
10718 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10719 plus_constant (XEXP (rtl, 0), rsize-dsize));
10722 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10723 and will have been substituted directly into all expressions that use it.
10724 C does not have such a concept, but C++ and other languages do. */
10725 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10726 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10729 rtl = targetm.delegitimize_address (rtl);
10731 /* If we don't look past the constant pool, we risk emitting a
10732 reference to a constant pool entry that isn't referenced from
10733 code, and thus is not emitted. */
10735 rtl = avoid_constant_pool_reference (rtl);
10740 /* We need to figure out what section we should use as the base for the
10741 address ranges where a given location is valid.
10742 1. If this particular DECL has a section associated with it, use that.
10743 2. If this function has a section associated with it, use that.
10744 3. Otherwise, use the text section.
10745 XXX: If you split a variable across multiple sections, we won't notice. */
10747 static const char *
10748 secname_for_decl (const_tree decl)
10750 const char *secname;
10752 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10754 tree sectree = DECL_SECTION_NAME (decl);
10755 secname = TREE_STRING_POINTER (sectree);
10757 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
10759 tree sectree = DECL_SECTION_NAME (current_function_decl);
10760 secname = TREE_STRING_POINTER (sectree);
10762 else if (cfun && in_cold_section_p)
10763 secname = crtl->subsections.cold_section_label;
10765 secname = text_section_label;
10770 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
10771 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
10772 value is the offset into the common block for the symbol. */
10775 fortran_common (tree decl, HOST_WIDE_INT *value)
10777 tree val_expr, cvar;
10778 enum machine_mode mode;
10779 HOST_WIDE_INT bitsize, bitpos;
10781 int volatilep = 0, unsignedp = 0;
10783 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
10784 it does not have a value (the offset into the common area), or if it
10785 is thread local (as opposed to global) then it isn't common, and shouldn't
10786 be handled as such. */
10787 if (TREE_CODE (decl) != VAR_DECL
10788 || !TREE_PUBLIC (decl)
10789 || !TREE_STATIC (decl)
10790 || !DECL_HAS_VALUE_EXPR_P (decl)
10794 val_expr = DECL_VALUE_EXPR (decl);
10795 if (TREE_CODE (val_expr) != COMPONENT_REF)
10798 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
10799 &mode, &unsignedp, &volatilep, true);
10801 if (cvar == NULL_TREE
10802 || TREE_CODE (cvar) != VAR_DECL
10803 || DECL_ARTIFICIAL (cvar)
10804 || !TREE_PUBLIC (cvar))
10808 if (offset != NULL)
10810 if (!host_integerp (offset, 0))
10812 *value = tree_low_cst (offset, 0);
10815 *value += bitpos / BITS_PER_UNIT;
10821 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10822 data attribute for a variable or a parameter. We generate the
10823 DW_AT_const_value attribute only in those cases where the given variable
10824 or parameter does not have a true "location" either in memory or in a
10825 register. This can happen (for example) when a constant is passed as an
10826 actual argument in a call to an inline function. (It's possible that
10827 these things can crop up in other ways also.) Note that one type of
10828 constant value which can be passed into an inlined function is a constant
10829 pointer. This can happen for example if an actual argument in an inlined
10830 function call evaluates to a compile-time constant address. */
10833 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10834 enum dwarf_attribute attr)
10837 dw_loc_descr_ref descr;
10838 var_loc_list *loc_list;
10839 struct var_loc_node *node;
10840 if (TREE_CODE (decl) == ERROR_MARK)
10843 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10844 || TREE_CODE (decl) == RESULT_DECL);
10846 /* See if we possibly have multiple locations for this variable. */
10847 loc_list = lookup_decl_loc (decl);
10849 /* If it truly has multiple locations, the first and last node will
10851 if (loc_list && loc_list->first != loc_list->last)
10853 const char *endname, *secname;
10854 dw_loc_list_ref list;
10856 enum var_init_status initialized;
10858 /* Now that we know what section we are using for a base,
10859 actually construct the list of locations.
10860 The first location information is what is passed to the
10861 function that creates the location list, and the remaining
10862 locations just get added on to that list.
10863 Note that we only know the start address for a location
10864 (IE location changes), so to build the range, we use
10865 the range [current location start, next location start].
10866 This means we have to special case the last node, and generate
10867 a range of [last location start, end of function label]. */
10869 node = loc_list->first;
10870 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10871 secname = secname_for_decl (decl);
10873 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note))
10874 initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10876 initialized = VAR_INIT_STATUS_INITIALIZED;
10878 list = new_loc_list (loc_descriptor (varloc, initialized),
10879 node->label, node->next->label, secname, 1);
10882 for (; node->next; node = node->next)
10883 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10885 /* The variable has a location between NODE->LABEL and
10886 NODE->NEXT->LABEL. */
10887 enum var_init_status initialized =
10888 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10889 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10890 add_loc_descr_to_loc_list (&list,
10891 loc_descriptor (varloc, initialized),
10892 node->label, node->next->label, secname);
10895 /* If the variable has a location at the last label
10896 it keeps its location until the end of function. */
10897 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10899 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10900 enum var_init_status initialized =
10901 NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10903 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10904 if (!current_function_decl)
10905 endname = text_end_label;
10908 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10909 current_function_funcdef_no);
10910 endname = ggc_strdup (label_id);
10912 add_loc_descr_to_loc_list (&list,
10913 loc_descriptor (varloc, initialized),
10914 node->label, endname, secname);
10917 /* Finally, add the location list to the DIE, and we are done. */
10918 add_AT_loc_list (die, attr, list);
10922 /* Try to get some constant RTL for this decl, and use that as the value of
10925 rtl = rtl_for_decl_location (decl);
10926 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10928 add_const_value_attribute (die, rtl);
10932 /* If we have tried to generate the location otherwise, and it
10933 didn't work out (we wouldn't be here if we did), and we have a one entry
10934 location list, try generating a location from that. */
10935 if (loc_list && loc_list->first)
10937 enum var_init_status status;
10938 node = loc_list->first;
10939 status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note);
10940 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status);
10943 add_AT_location_description (die, attr, descr);
10948 /* We couldn't get any rtl, so try directly generating the location
10949 description from the tree. */
10950 descr = loc_descriptor_from_tree (decl);
10953 add_AT_location_description (die, attr, descr);
10956 /* None of that worked, so it must not really have a location;
10957 try adding a constant value attribute from the DECL_INITIAL. */
10958 tree_add_const_value_attribute (die, decl);
10961 /* If we don't have a copy of this variable in memory for some reason (such
10962 as a C++ member constant that doesn't have an out-of-line definition),
10963 we should tell the debugger about the constant value. */
10966 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10968 tree init = DECL_INITIAL (decl);
10969 tree type = TREE_TYPE (decl);
10972 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10977 rtl = rtl_for_decl_init (init, type);
10979 add_const_value_attribute (var_die, rtl);
10982 /* Convert the CFI instructions for the current function into a
10983 location list. This is used for DW_AT_frame_base when we targeting
10984 a dwarf2 consumer that does not support the dwarf3
10985 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10988 static dw_loc_list_ref
10989 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
10992 dw_loc_list_ref list, *list_tail;
10994 dw_cfa_location last_cfa, next_cfa;
10995 const char *start_label, *last_label, *section;
10997 fde = current_fde ();
10998 gcc_assert (fde != NULL);
11000 section = secname_for_decl (current_function_decl);
11004 next_cfa.reg = INVALID_REGNUM;
11005 next_cfa.offset = 0;
11006 next_cfa.indirect = 0;
11007 next_cfa.base_offset = 0;
11009 start_label = fde->dw_fde_begin;
11011 /* ??? Bald assumption that the CIE opcode list does not contain
11012 advance opcodes. */
11013 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
11014 lookup_cfa_1 (cfi, &next_cfa);
11016 last_cfa = next_cfa;
11017 last_label = start_label;
11019 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
11020 switch (cfi->dw_cfi_opc)
11022 case DW_CFA_set_loc:
11023 case DW_CFA_advance_loc1:
11024 case DW_CFA_advance_loc2:
11025 case DW_CFA_advance_loc4:
11026 if (!cfa_equal_p (&last_cfa, &next_cfa))
11028 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11029 start_label, last_label, section,
11032 list_tail = &(*list_tail)->dw_loc_next;
11033 last_cfa = next_cfa;
11034 start_label = last_label;
11036 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
11039 case DW_CFA_advance_loc:
11040 /* The encoding is complex enough that we should never emit this. */
11041 case DW_CFA_remember_state:
11042 case DW_CFA_restore_state:
11043 /* We don't handle these two in this function. It would be possible
11044 if it were to be required. */
11045 gcc_unreachable ();
11048 lookup_cfa_1 (cfi, &next_cfa);
11052 if (!cfa_equal_p (&last_cfa, &next_cfa))
11054 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
11055 start_label, last_label, section,
11057 list_tail = &(*list_tail)->dw_loc_next;
11058 start_label = last_label;
11060 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
11061 start_label, fde->dw_fde_end, section,
11067 /* Compute a displacement from the "steady-state frame pointer" to the
11068 frame base (often the same as the CFA), and store it in
11069 frame_pointer_fb_offset. OFFSET is added to the displacement
11070 before the latter is negated. */
11073 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
11077 #ifdef FRAME_POINTER_CFA_OFFSET
11078 reg = frame_pointer_rtx;
11079 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
11081 reg = arg_pointer_rtx;
11082 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
11085 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
11086 if (GET_CODE (elim) == PLUS)
11088 offset += INTVAL (XEXP (elim, 1));
11089 elim = XEXP (elim, 0);
11091 gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx
11092 : stack_pointer_rtx));
11094 frame_pointer_fb_offset = -offset;
11097 /* Generate a DW_AT_name attribute given some string value to be included as
11098 the value of the attribute. */
11101 add_name_attribute (dw_die_ref die, const char *name_string)
11103 if (name_string != NULL && *name_string != 0)
11105 if (demangle_name_func)
11106 name_string = (*demangle_name_func) (name_string);
11108 add_AT_string (die, DW_AT_name, name_string);
11112 /* Generate a DW_AT_comp_dir attribute for DIE. */
11115 add_comp_dir_attribute (dw_die_ref die)
11117 const char *wd = get_src_pwd ();
11119 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
11122 /* Given a tree node describing an array bound (either lower or upper) output
11123 a representation for that bound. */
11126 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
11128 switch (TREE_CODE (bound))
11133 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11135 if (! host_integerp (bound, 0)
11136 || (bound_attr == DW_AT_lower_bound
11137 && (((is_c_family () || is_java ()) && integer_zerop (bound))
11138 || (is_fortran () && integer_onep (bound)))))
11139 /* Use the default. */
11142 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
11146 case VIEW_CONVERT_EXPR:
11147 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
11157 dw_die_ref decl_die = lookup_decl_die (bound);
11159 /* ??? Can this happen, or should the variable have been bound
11160 first? Probably it can, since I imagine that we try to create
11161 the types of parameters in the order in which they exist in
11162 the list, and won't have created a forward reference to a
11163 later parameter. */
11164 if (decl_die != NULL)
11165 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11171 /* Otherwise try to create a stack operation procedure to
11172 evaluate the value of the array bound. */
11174 dw_die_ref ctx, decl_die;
11175 dw_loc_descr_ref loc;
11177 loc = loc_descriptor_from_tree (bound);
11181 if (current_function_decl == 0)
11182 ctx = comp_unit_die;
11184 ctx = lookup_decl_die (current_function_decl);
11186 decl_die = new_die (DW_TAG_variable, ctx, bound);
11187 add_AT_flag (decl_die, DW_AT_artificial, 1);
11188 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
11189 add_AT_loc (decl_die, DW_AT_location, loc);
11191 add_AT_die_ref (subrange_die, bound_attr, decl_die);
11197 /* Note that the block of subscript information for an array type also
11198 includes information about the element type of type given array type. */
11201 add_subscript_info (dw_die_ref type_die, tree type)
11203 #ifndef MIPS_DEBUGGING_INFO
11204 unsigned dimension_number;
11207 dw_die_ref subrange_die;
11209 /* The GNU compilers represent multidimensional array types as sequences of
11210 one dimensional array types whose element types are themselves array
11211 types. Here we squish that down, so that each multidimensional array
11212 type gets only one array_type DIE in the Dwarf debugging info. The draft
11213 Dwarf specification say that we are allowed to do this kind of
11214 compression in C (because there is no difference between an array or
11215 arrays and a multidimensional array in C) but for other source languages
11216 (e.g. Ada) we probably shouldn't do this. */
11218 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11219 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11220 We work around this by disabling this feature. See also
11221 gen_array_type_die. */
11222 #ifndef MIPS_DEBUGGING_INFO
11223 for (dimension_number = 0;
11224 TREE_CODE (type) == ARRAY_TYPE;
11225 type = TREE_TYPE (type), dimension_number++)
11228 tree domain = TYPE_DOMAIN (type);
11230 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11231 and (in GNU C only) variable bounds. Handle all three forms
11233 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
11236 /* We have an array type with specified bounds. */
11237 lower = TYPE_MIN_VALUE (domain);
11238 upper = TYPE_MAX_VALUE (domain);
11240 /* Define the index type. */
11241 if (TREE_TYPE (domain))
11243 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11244 TREE_TYPE field. We can't emit debug info for this
11245 because it is an unnamed integral type. */
11246 if (TREE_CODE (domain) == INTEGER_TYPE
11247 && TYPE_NAME (domain) == NULL_TREE
11248 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
11249 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
11252 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
11256 /* ??? If upper is NULL, the array has unspecified length,
11257 but it does have a lower bound. This happens with Fortran
11259 Since the debugger is definitely going to need to know N
11260 to produce useful results, go ahead and output the lower
11261 bound solo, and hope the debugger can cope. */
11263 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
11265 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
11268 /* Otherwise we have an array type with an unspecified length. The
11269 DWARF-2 spec does not say how to handle this; let's just leave out the
11275 add_byte_size_attribute (dw_die_ref die, tree tree_node)
11279 switch (TREE_CODE (tree_node))
11284 case ENUMERAL_TYPE:
11287 case QUAL_UNION_TYPE:
11288 size = int_size_in_bytes (tree_node);
11291 /* For a data member of a struct or union, the DW_AT_byte_size is
11292 generally given as the number of bytes normally allocated for an
11293 object of the *declared* type of the member itself. This is true
11294 even for bit-fields. */
11295 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
11298 gcc_unreachable ();
11301 /* Note that `size' might be -1 when we get to this point. If it is, that
11302 indicates that the byte size of the entity in question is variable. We
11303 have no good way of expressing this fact in Dwarf at the present time,
11304 so just let the -1 pass on through. */
11305 add_AT_unsigned (die, DW_AT_byte_size, size);
11308 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11309 which specifies the distance in bits from the highest order bit of the
11310 "containing object" for the bit-field to the highest order bit of the
11313 For any given bit-field, the "containing object" is a hypothetical object
11314 (of some integral or enum type) within which the given bit-field lives. The
11315 type of this hypothetical "containing object" is always the same as the
11316 declared type of the individual bit-field itself. The determination of the
11317 exact location of the "containing object" for a bit-field is rather
11318 complicated. It's handled by the `field_byte_offset' function (above).
11320 Note that it is the size (in bytes) of the hypothetical "containing object"
11321 which will be given in the DW_AT_byte_size attribute for this bit-field.
11322 (See `byte_size_attribute' above). */
11325 add_bit_offset_attribute (dw_die_ref die, tree decl)
11327 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
11328 tree type = DECL_BIT_FIELD_TYPE (decl);
11329 HOST_WIDE_INT bitpos_int;
11330 HOST_WIDE_INT highest_order_object_bit_offset;
11331 HOST_WIDE_INT highest_order_field_bit_offset;
11332 HOST_WIDE_INT unsigned bit_offset;
11334 /* Must be a field and a bit field. */
11335 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
11337 /* We can't yet handle bit-fields whose offsets are variable, so if we
11338 encounter such things, just return without generating any attribute
11339 whatsoever. Likewise for variable or too large size. */
11340 if (! host_integerp (bit_position (decl), 0)
11341 || ! host_integerp (DECL_SIZE (decl), 1))
11344 bitpos_int = int_bit_position (decl);
11346 /* Note that the bit offset is always the distance (in bits) from the
11347 highest-order bit of the "containing object" to the highest-order bit of
11348 the bit-field itself. Since the "high-order end" of any object or field
11349 is different on big-endian and little-endian machines, the computation
11350 below must take account of these differences. */
11351 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
11352 highest_order_field_bit_offset = bitpos_int;
11354 if (! BYTES_BIG_ENDIAN)
11356 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
11357 highest_order_object_bit_offset += simple_type_size_in_bits (type);
11361 = (! BYTES_BIG_ENDIAN
11362 ? highest_order_object_bit_offset - highest_order_field_bit_offset
11363 : highest_order_field_bit_offset - highest_order_object_bit_offset);
11365 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
11368 /* For a FIELD_DECL node which represents a bit field, output an attribute
11369 which specifies the length in bits of the given field. */
11372 add_bit_size_attribute (dw_die_ref die, tree decl)
11374 /* Must be a field and a bit field. */
11375 gcc_assert (TREE_CODE (decl) == FIELD_DECL
11376 && DECL_BIT_FIELD_TYPE (decl));
11378 if (host_integerp (DECL_SIZE (decl), 1))
11379 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
11382 /* If the compiled language is ANSI C, then add a 'prototyped'
11383 attribute, if arg types are given for the parameters of a function. */
11386 add_prototyped_attribute (dw_die_ref die, tree func_type)
11388 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
11389 && TYPE_ARG_TYPES (func_type) != NULL)
11390 add_AT_flag (die, DW_AT_prototyped, 1);
11393 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11394 by looking in either the type declaration or object declaration
11398 add_abstract_origin_attribute (dw_die_ref die, tree origin)
11400 dw_die_ref origin_die = NULL;
11402 if (TREE_CODE (origin) != FUNCTION_DECL)
11404 /* We may have gotten separated from the block for the inlined
11405 function, if we're in an exception handler or some such; make
11406 sure that the abstract function has been written out.
11408 Doing this for nested functions is wrong, however; functions are
11409 distinct units, and our context might not even be inline. */
11413 fn = TYPE_STUB_DECL (fn);
11415 fn = decl_function_context (fn);
11417 dwarf2out_abstract_function (fn);
11420 if (DECL_P (origin))
11421 origin_die = lookup_decl_die (origin);
11422 else if (TYPE_P (origin))
11423 origin_die = lookup_type_die (origin);
11425 /* XXX: Functions that are never lowered don't always have correct block
11426 trees (in the case of java, they simply have no block tree, in some other
11427 languages). For these functions, there is nothing we can really do to
11428 output correct debug info for inlined functions in all cases. Rather
11429 than die, we'll just produce deficient debug info now, in that we will
11430 have variables without a proper abstract origin. In the future, when all
11431 functions are lowered, we should re-add a gcc_assert (origin_die)
11435 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
11438 /* We do not currently support the pure_virtual attribute. */
11441 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
11443 if (DECL_VINDEX (func_decl))
11445 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11447 if (host_integerp (DECL_VINDEX (func_decl), 0))
11448 add_AT_loc (die, DW_AT_vtable_elem_location,
11449 new_loc_descr (DW_OP_constu,
11450 tree_low_cst (DECL_VINDEX (func_decl), 0),
11453 /* GNU extension: Record what type this method came from originally. */
11454 if (debug_info_level > DINFO_LEVEL_TERSE)
11455 add_AT_die_ref (die, DW_AT_containing_type,
11456 lookup_type_die (DECL_CONTEXT (func_decl)));
11460 /* Add source coordinate attributes for the given decl. */
11463 add_src_coords_attributes (dw_die_ref die, tree decl)
11465 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11467 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
11468 add_AT_unsigned (die, DW_AT_decl_line, s.line);
11471 /* Add a DW_AT_name attribute and source coordinate attribute for the
11472 given decl, but only if it actually has a name. */
11475 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
11479 decl_name = DECL_NAME (decl);
11480 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
11482 add_name_attribute (die, dwarf2_name (decl, 0));
11483 if (! DECL_ARTIFICIAL (decl))
11484 add_src_coords_attributes (die, decl);
11486 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
11487 && TREE_PUBLIC (decl)
11488 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
11489 && !DECL_ABSTRACT (decl)
11490 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
11492 add_AT_string (die, DW_AT_MIPS_linkage_name,
11493 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
11496 #ifdef VMS_DEBUGGING_INFO
11497 /* Get the function's name, as described by its RTL. This may be different
11498 from the DECL_NAME name used in the source file. */
11499 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
11501 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
11502 XEXP (DECL_RTL (decl), 0));
11503 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
11508 /* Push a new declaration scope. */
11511 push_decl_scope (tree scope)
11513 VEC_safe_push (tree, gc, decl_scope_table, scope);
11516 /* Pop a declaration scope. */
11519 pop_decl_scope (void)
11521 VEC_pop (tree, decl_scope_table);
11524 /* Return the DIE for the scope that immediately contains this type.
11525 Non-named types get global scope. Named types nested in other
11526 types get their containing scope if it's open, or global scope
11527 otherwise. All other types (i.e. function-local named types) get
11528 the current active scope. */
11531 scope_die_for (tree t, dw_die_ref context_die)
11533 dw_die_ref scope_die = NULL;
11534 tree containing_scope;
11537 /* Non-types always go in the current scope. */
11538 gcc_assert (TYPE_P (t));
11540 containing_scope = TYPE_CONTEXT (t);
11542 /* Use the containing namespace if it was passed in (for a declaration). */
11543 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
11545 if (context_die == lookup_decl_die (containing_scope))
11548 containing_scope = NULL_TREE;
11551 /* Ignore function type "scopes" from the C frontend. They mean that
11552 a tagged type is local to a parmlist of a function declarator, but
11553 that isn't useful to DWARF. */
11554 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
11555 containing_scope = NULL_TREE;
11557 if (containing_scope == NULL_TREE)
11558 scope_die = comp_unit_die;
11559 else if (TYPE_P (containing_scope))
11561 /* For types, we can just look up the appropriate DIE. But
11562 first we check to see if we're in the middle of emitting it
11563 so we know where the new DIE should go. */
11564 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
11565 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
11570 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
11571 || TREE_ASM_WRITTEN (containing_scope));
11573 /* If none of the current dies are suitable, we get file scope. */
11574 scope_die = comp_unit_die;
11577 scope_die = lookup_type_die (containing_scope);
11580 scope_die = context_die;
11585 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11588 local_scope_p (dw_die_ref context_die)
11590 for (; context_die; context_die = context_die->die_parent)
11591 if (context_die->die_tag == DW_TAG_inlined_subroutine
11592 || context_die->die_tag == DW_TAG_subprogram)
11598 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11599 whether or not to treat a DIE in this context as a declaration. */
11602 class_or_namespace_scope_p (dw_die_ref context_die)
11604 return (context_die
11605 && (context_die->die_tag == DW_TAG_structure_type
11606 || context_die->die_tag == DW_TAG_class_type
11607 || context_die->die_tag == DW_TAG_interface_type
11608 || context_die->die_tag == DW_TAG_union_type
11609 || context_die->die_tag == DW_TAG_namespace));
11612 /* Many forms of DIEs require a "type description" attribute. This
11613 routine locates the proper "type descriptor" die for the type given
11614 by 'type', and adds a DW_AT_type attribute below the given die. */
11617 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
11618 int decl_volatile, dw_die_ref context_die)
11620 enum tree_code code = TREE_CODE (type);
11621 dw_die_ref type_die = NULL;
11623 /* ??? If this type is an unnamed subrange type of an integral, floating-point
11624 or fixed-point type, use the inner type. This is because we have no
11625 support for unnamed types in base_type_die. This can happen if this is
11626 an Ada subrange type. Correct solution is emit a subrange type die. */
11627 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
11628 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
11629 type = TREE_TYPE (type), code = TREE_CODE (type);
11631 if (code == ERROR_MARK
11632 /* Handle a special case. For functions whose return type is void, we
11633 generate *no* type attribute. (Note that no object may have type
11634 `void', so this only applies to function return types). */
11635 || code == VOID_TYPE)
11638 type_die = modified_type_die (type,
11639 decl_const || TYPE_READONLY (type),
11640 decl_volatile || TYPE_VOLATILE (type),
11643 if (type_die != NULL)
11644 add_AT_die_ref (object_die, DW_AT_type, type_die);
11647 /* Given an object die, add the calling convention attribute for the
11648 function call type. */
11650 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
11652 enum dwarf_calling_convention value = DW_CC_normal;
11654 value = targetm.dwarf_calling_convention (TREE_TYPE (decl));
11656 /* DWARF doesn't provide a way to identify a program's source-level
11657 entry point. DW_AT_calling_convention attributes are only meant
11658 to describe functions' calling conventions. However, lacking a
11659 better way to signal the Fortran main program, we use this for the
11660 time being, following existing custom. */
11662 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
11663 value = DW_CC_program;
11665 /* Only add the attribute if the backend requests it, and
11666 is not DW_CC_normal. */
11667 if (value && (value != DW_CC_normal))
11668 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
11671 /* Given a tree pointer to a struct, class, union, or enum type node, return
11672 a pointer to the (string) tag name for the given type, or zero if the type
11673 was declared without a tag. */
11675 static const char *
11676 type_tag (const_tree type)
11678 const char *name = 0;
11680 if (TYPE_NAME (type) != 0)
11684 /* Find the IDENTIFIER_NODE for the type name. */
11685 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
11686 t = TYPE_NAME (type);
11688 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11689 a TYPE_DECL node, regardless of whether or not a `typedef' was
11691 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11692 && ! DECL_IGNORED_P (TYPE_NAME (type)))
11694 /* We want to be extra verbose. Don't call dwarf_name if
11695 DECL_NAME isn't set. The default hook for decl_printable_name
11696 doesn't like that, and in this context it's correct to return
11697 0, instead of "<anonymous>" or the like. */
11698 if (DECL_NAME (TYPE_NAME (type)))
11699 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
11702 /* Now get the name as a string, or invent one. */
11703 if (!name && t != 0)
11704 name = IDENTIFIER_POINTER (t);
11707 return (name == 0 || *name == '\0') ? 0 : name;
11710 /* Return the type associated with a data member, make a special check
11711 for bit field types. */
11714 member_declared_type (const_tree member)
11716 return (DECL_BIT_FIELD_TYPE (member)
11717 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
11720 /* Get the decl's label, as described by its RTL. This may be different
11721 from the DECL_NAME name used in the source file. */
11724 static const char *
11725 decl_start_label (tree decl)
11728 const char *fnname;
11730 x = DECL_RTL (decl);
11731 gcc_assert (MEM_P (x));
11734 gcc_assert (GET_CODE (x) == SYMBOL_REF);
11736 fnname = XSTR (x, 0);
11741 /* These routines generate the internal representation of the DIE's for
11742 the compilation unit. Debugging information is collected by walking
11743 the declaration trees passed in from dwarf2out_decl(). */
11746 gen_array_type_die (tree type, dw_die_ref context_die)
11748 dw_die_ref scope_die = scope_die_for (type, context_die);
11749 dw_die_ref array_die;
11752 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11753 the inner array type comes before the outer array type. Thus we must
11754 call gen_type_die before we call new_die. See below also. */
11755 #ifdef MIPS_DEBUGGING_INFO
11756 gen_type_die (TREE_TYPE (type), context_die);
11759 array_die = new_die (DW_TAG_array_type, scope_die, type);
11760 add_name_attribute (array_die, type_tag (type));
11761 equate_type_number_to_die (type, array_die);
11763 if (TREE_CODE (type) == VECTOR_TYPE)
11765 /* The frontend feeds us a representation for the vector as a struct
11766 containing an array. Pull out the array type. */
11767 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
11768 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
11771 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11773 && TREE_CODE (type) == ARRAY_TYPE
11774 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
11775 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11778 /* We default the array ordering. SDB will probably do
11779 the right things even if DW_AT_ordering is not present. It's not even
11780 an issue until we start to get into multidimensional arrays anyway. If
11781 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11782 then we'll have to put the DW_AT_ordering attribute back in. (But if
11783 and when we find out that we need to put these in, we will only do so
11784 for multidimensional arrays. */
11785 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
11788 #ifdef MIPS_DEBUGGING_INFO
11789 /* The SGI compilers handle arrays of unknown bound by setting
11790 AT_declaration and not emitting any subrange DIEs. */
11791 if (! TYPE_DOMAIN (type))
11792 add_AT_flag (array_die, DW_AT_declaration, 1);
11795 add_subscript_info (array_die, type);
11797 /* Add representation of the type of the elements of this array type. */
11798 element_type = TREE_TYPE (type);
11800 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11801 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11802 We work around this by disabling this feature. See also
11803 add_subscript_info. */
11804 #ifndef MIPS_DEBUGGING_INFO
11805 while (TREE_CODE (element_type) == ARRAY_TYPE)
11806 element_type = TREE_TYPE (element_type);
11808 gen_type_die (element_type, context_die);
11811 add_type_attribute (array_die, element_type, 0, 0, context_die);
11813 if (get_AT (array_die, DW_AT_name))
11814 add_pubtype (type, array_die);
11817 static dw_loc_descr_ref
11818 descr_info_loc (tree val, tree base_decl)
11820 HOST_WIDE_INT size;
11821 dw_loc_descr_ref loc, loc2;
11822 enum dwarf_location_atom op;
11824 if (val == base_decl)
11825 return new_loc_descr (DW_OP_push_object_address, 0, 0);
11827 switch (TREE_CODE (val))
11830 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11832 if (host_integerp (val, 0))
11833 return int_loc_descriptor (tree_low_cst (val, 0));
11836 size = int_size_in_bytes (TREE_TYPE (val));
11839 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11842 if (size == DWARF2_ADDR_SIZE)
11843 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
11845 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
11847 case POINTER_PLUS_EXPR:
11849 if (host_integerp (TREE_OPERAND (val, 1), 1)
11850 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
11853 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11856 add_loc_descr (&loc,
11857 new_loc_descr (DW_OP_plus_uconst,
11858 tree_low_cst (TREE_OPERAND (val, 1),
11865 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
11868 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
11871 add_loc_descr (&loc, loc2);
11872 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
11894 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
11895 tree val, tree base_decl)
11897 dw_loc_descr_ref loc;
11899 if (host_integerp (val, 0))
11901 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
11905 loc = descr_info_loc (val, base_decl);
11909 add_AT_loc (die, attr, loc);
11912 /* This routine generates DIE for array with hidden descriptor, details
11913 are filled into *info by a langhook. */
11916 gen_descr_array_type_die (tree type, struct array_descr_info *info,
11917 dw_die_ref context_die)
11919 dw_die_ref scope_die = scope_die_for (type, context_die);
11920 dw_die_ref array_die;
11923 array_die = new_die (DW_TAG_array_type, scope_die, type);
11924 add_name_attribute (array_die, type_tag (type));
11925 equate_type_number_to_die (type, array_die);
11927 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11929 && info->ndimensions >= 2)
11930 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
11932 if (info->data_location)
11933 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
11935 if (info->associated)
11936 add_descr_info_field (array_die, DW_AT_associated, info->associated,
11938 if (info->allocated)
11939 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
11942 for (dim = 0; dim < info->ndimensions; dim++)
11944 dw_die_ref subrange_die
11945 = new_die (DW_TAG_subrange_type, array_die, NULL);
11947 if (info->dimen[dim].lower_bound)
11949 /* If it is the default value, omit it. */
11950 if ((is_c_family () || is_java ())
11951 && integer_zerop (info->dimen[dim].lower_bound))
11953 else if (is_fortran ()
11954 && integer_onep (info->dimen[dim].lower_bound))
11957 add_descr_info_field (subrange_die, DW_AT_lower_bound,
11958 info->dimen[dim].lower_bound,
11961 if (info->dimen[dim].upper_bound)
11962 add_descr_info_field (subrange_die, DW_AT_upper_bound,
11963 info->dimen[dim].upper_bound,
11965 if (info->dimen[dim].stride)
11966 add_descr_info_field (subrange_die, DW_AT_byte_stride,
11967 info->dimen[dim].stride,
11971 gen_type_die (info->element_type, context_die);
11972 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
11974 if (get_AT (array_die, DW_AT_name))
11975 add_pubtype (type, array_die);
11980 gen_entry_point_die (tree decl, dw_die_ref context_die)
11982 tree origin = decl_ultimate_origin (decl);
11983 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
11985 if (origin != NULL)
11986 add_abstract_origin_attribute (decl_die, origin);
11989 add_name_and_src_coords_attributes (decl_die, decl);
11990 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
11991 0, 0, context_die);
11994 if (DECL_ABSTRACT (decl))
11995 equate_decl_number_to_die (decl, decl_die);
11997 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
12001 /* Walk through the list of incomplete types again, trying once more to
12002 emit full debugging info for them. */
12005 retry_incomplete_types (void)
12009 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
12010 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
12013 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12016 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
12018 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
12020 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12021 be incomplete and such types are not marked. */
12022 add_abstract_origin_attribute (type_die, type);
12025 /* Determine what tag to use for a record type. */
12027 static enum dwarf_tag
12028 record_type_tag (tree type)
12030 if (! lang_hooks.types.classify_record)
12031 return DW_TAG_structure_type;
12033 switch (lang_hooks.types.classify_record (type))
12035 case RECORD_IS_STRUCT:
12036 return DW_TAG_structure_type;
12038 case RECORD_IS_CLASS:
12039 return DW_TAG_class_type;
12041 case RECORD_IS_INTERFACE:
12042 return DW_TAG_interface_type;
12045 gcc_unreachable ();
12049 /* Generate a DIE to represent an inlined instance of a structure type. */
12052 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
12054 dw_die_ref type_die = new_die (record_type_tag (type), context_die, type);
12056 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12057 be incomplete and such types are not marked. */
12058 add_abstract_origin_attribute (type_die, type);
12061 /* Generate a DIE to represent an inlined instance of a union type. */
12064 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
12066 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
12068 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12069 be incomplete and such types are not marked. */
12070 add_abstract_origin_attribute (type_die, type);
12073 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12074 include all of the information about the enumeration values also. Each
12075 enumerated type name/value is listed as a child of the enumerated type
12079 gen_enumeration_type_die (tree type, dw_die_ref context_die)
12081 dw_die_ref type_die = lookup_type_die (type);
12083 if (type_die == NULL)
12085 type_die = new_die (DW_TAG_enumeration_type,
12086 scope_die_for (type, context_die), type);
12087 equate_type_number_to_die (type, type_die);
12088 add_name_attribute (type_die, type_tag (type));
12090 else if (! TYPE_SIZE (type))
12093 remove_AT (type_die, DW_AT_declaration);
12095 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12096 given enum type is incomplete, do not generate the DW_AT_byte_size
12097 attribute or the DW_AT_element_list attribute. */
12098 if (TYPE_SIZE (type))
12102 TREE_ASM_WRITTEN (type) = 1;
12103 add_byte_size_attribute (type_die, type);
12104 if (TYPE_STUB_DECL (type) != NULL_TREE)
12105 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12107 /* If the first reference to this type was as the return type of an
12108 inline function, then it may not have a parent. Fix this now. */
12109 if (type_die->die_parent == NULL)
12110 add_child_die (scope_die_for (type, context_die), type_die);
12112 for (link = TYPE_VALUES (type);
12113 link != NULL; link = TREE_CHAIN (link))
12115 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
12116 tree value = TREE_VALUE (link);
12118 add_name_attribute (enum_die,
12119 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
12121 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
12122 /* DWARF2 does not provide a way of indicating whether or
12123 not enumeration constants are signed or unsigned. GDB
12124 always assumes the values are signed, so we output all
12125 values as if they were signed. That means that
12126 enumeration constants with very large unsigned values
12127 will appear to have negative values in the debugger. */
12128 add_AT_int (enum_die, DW_AT_const_value,
12129 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
12133 add_AT_flag (type_die, DW_AT_declaration, 1);
12135 if (get_AT (type_die, DW_AT_name))
12136 add_pubtype (type, type_die);
12141 /* Generate a DIE to represent either a real live formal parameter decl or to
12142 represent just the type of some formal parameter position in some function
12145 Note that this routine is a bit unusual because its argument may be a
12146 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12147 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12148 node. If it's the former then this function is being called to output a
12149 DIE to represent a formal parameter object (or some inlining thereof). If
12150 it's the latter, then this function is only being called to output a
12151 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12152 argument type of some subprogram type. */
12155 gen_formal_parameter_die (tree node, dw_die_ref context_die)
12157 dw_die_ref parm_die
12158 = new_die (DW_TAG_formal_parameter, context_die, node);
12161 switch (TREE_CODE_CLASS (TREE_CODE (node)))
12163 case tcc_declaration:
12164 origin = decl_ultimate_origin (node);
12165 if (origin != NULL)
12166 add_abstract_origin_attribute (parm_die, origin);
12169 tree type = TREE_TYPE (node);
12170 add_name_and_src_coords_attributes (parm_die, node);
12171 if (DECL_BY_REFERENCE (node))
12172 type = TREE_TYPE (type);
12173 add_type_attribute (parm_die, type,
12174 TREE_READONLY (node),
12175 TREE_THIS_VOLATILE (node),
12177 if (DECL_ARTIFICIAL (node))
12178 add_AT_flag (parm_die, DW_AT_artificial, 1);
12181 equate_decl_number_to_die (node, parm_die);
12182 if (! DECL_ABSTRACT (node))
12183 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
12188 /* We were called with some kind of a ..._TYPE node. */
12189 add_type_attribute (parm_die, node, 0, 0, context_die);
12193 gcc_unreachable ();
12199 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12200 at the end of an (ANSI prototyped) formal parameters list. */
12203 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
12205 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
12208 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12209 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12210 parameters as specified in some function type specification (except for
12211 those which appear as part of a function *definition*). */
12214 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
12217 tree formal_type = NULL;
12218 tree first_parm_type;
12221 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
12223 arg = DECL_ARGUMENTS (function_or_method_type);
12224 function_or_method_type = TREE_TYPE (function_or_method_type);
12229 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
12231 /* Make our first pass over the list of formal parameter types and output a
12232 DW_TAG_formal_parameter DIE for each one. */
12233 for (link = first_parm_type; link; )
12235 dw_die_ref parm_die;
12237 formal_type = TREE_VALUE (link);
12238 if (formal_type == void_type_node)
12241 /* Output a (nameless) DIE to represent the formal parameter itself. */
12242 parm_die = gen_formal_parameter_die (formal_type, context_die);
12243 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
12244 && link == first_parm_type)
12245 || (arg && DECL_ARTIFICIAL (arg)))
12246 add_AT_flag (parm_die, DW_AT_artificial, 1);
12248 link = TREE_CHAIN (link);
12250 arg = TREE_CHAIN (arg);
12253 /* If this function type has an ellipsis, add a
12254 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12255 if (formal_type != void_type_node)
12256 gen_unspecified_parameters_die (function_or_method_type, context_die);
12258 /* Make our second (and final) pass over the list of formal parameter types
12259 and output DIEs to represent those types (as necessary). */
12260 for (link = TYPE_ARG_TYPES (function_or_method_type);
12261 link && TREE_VALUE (link);
12262 link = TREE_CHAIN (link))
12263 gen_type_die (TREE_VALUE (link), context_die);
12266 /* We want to generate the DIE for TYPE so that we can generate the
12267 die for MEMBER, which has been defined; we will need to refer back
12268 to the member declaration nested within TYPE. If we're trying to
12269 generate minimal debug info for TYPE, processing TYPE won't do the
12270 trick; we need to attach the member declaration by hand. */
12273 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
12275 gen_type_die (type, context_die);
12277 /* If we're trying to avoid duplicate debug info, we may not have
12278 emitted the member decl for this function. Emit it now. */
12279 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
12280 && ! lookup_decl_die (member))
12282 dw_die_ref type_die;
12283 gcc_assert (!decl_ultimate_origin (member));
12285 push_decl_scope (type);
12286 type_die = lookup_type_die (type);
12287 if (TREE_CODE (member) == FUNCTION_DECL)
12288 gen_subprogram_die (member, type_die);
12289 else if (TREE_CODE (member) == FIELD_DECL)
12291 /* Ignore the nameless fields that are used to skip bits but handle
12292 C++ anonymous unions and structs. */
12293 if (DECL_NAME (member) != NULL_TREE
12294 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
12295 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
12297 gen_type_die (member_declared_type (member), type_die);
12298 gen_field_die (member, type_die);
12302 gen_variable_die (member, type_die);
12308 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12309 may later generate inlined and/or out-of-line instances of. */
12312 dwarf2out_abstract_function (tree decl)
12314 dw_die_ref old_die;
12317 int was_abstract = DECL_ABSTRACT (decl);
12319 /* Make sure we have the actual abstract inline, not a clone. */
12320 decl = DECL_ORIGIN (decl);
12322 old_die = lookup_decl_die (decl);
12323 if (old_die && get_AT (old_die, DW_AT_inline))
12324 /* We've already generated the abstract instance. */
12327 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12328 we don't get confused by DECL_ABSTRACT. */
12329 if (debug_info_level > DINFO_LEVEL_TERSE)
12331 context = decl_class_context (decl);
12333 gen_type_die_for_member
12334 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
12337 /* Pretend we've just finished compiling this function. */
12338 save_fn = current_function_decl;
12339 current_function_decl = decl;
12340 push_cfun (DECL_STRUCT_FUNCTION (decl));
12342 set_decl_abstract_flags (decl, 1);
12343 dwarf2out_decl (decl);
12344 if (! was_abstract)
12345 set_decl_abstract_flags (decl, 0);
12347 current_function_decl = save_fn;
12351 /* Helper function of premark_used_types() which gets called through
12352 htab_traverse_resize().
12354 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12355 marked as unused by prune_unused_types. */
12357 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
12362 type = (tree) *slot;
12363 die = lookup_type_die (type);
12365 die->die_perennial_p = 1;
12369 /* Mark all members of used_types_hash as perennial. */
12371 premark_used_types (void)
12373 if (cfun && cfun->used_types_hash)
12374 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
12377 /* Generate a DIE to represent a declared function (either file-scope or
12381 gen_subprogram_die (tree decl, dw_die_ref context_die)
12383 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
12384 tree origin = decl_ultimate_origin (decl);
12385 dw_die_ref subr_die;
12388 dw_die_ref old_die = lookup_decl_die (decl);
12389 int declaration = (current_function_decl != decl
12390 || class_or_namespace_scope_p (context_die));
12392 premark_used_types ();
12394 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12395 started to generate the abstract instance of an inline, decided to output
12396 its containing class, and proceeded to emit the declaration of the inline
12397 from the member list for the class. If so, DECLARATION takes priority;
12398 we'll get back to the abstract instance when done with the class. */
12400 /* The class-scope declaration DIE must be the primary DIE. */
12401 if (origin && declaration && class_or_namespace_scope_p (context_die))
12404 gcc_assert (!old_die);
12407 /* Now that the C++ front end lazily declares artificial member fns, we
12408 might need to retrofit the declaration into its class. */
12409 if (!declaration && !origin && !old_die
12410 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
12411 && !class_or_namespace_scope_p (context_die)
12412 && debug_info_level > DINFO_LEVEL_TERSE)
12413 old_die = force_decl_die (decl);
12415 if (origin != NULL)
12417 gcc_assert (!declaration || local_scope_p (context_die));
12419 /* Fixup die_parent for the abstract instance of a nested
12420 inline function. */
12421 if (old_die && old_die->die_parent == NULL)
12422 add_child_die (context_die, old_die);
12424 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12425 add_abstract_origin_attribute (subr_die, origin);
12429 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12430 struct dwarf_file_data * file_index = lookup_filename (s.file);
12432 if (!get_AT_flag (old_die, DW_AT_declaration)
12433 /* We can have a normal definition following an inline one in the
12434 case of redefinition of GNU C extern inlines.
12435 It seems reasonable to use AT_specification in this case. */
12436 && !get_AT (old_die, DW_AT_inline))
12438 /* Detect and ignore this case, where we are trying to output
12439 something we have already output. */
12443 /* If the definition comes from the same place as the declaration,
12444 maybe use the old DIE. We always want the DIE for this function
12445 that has the *_pc attributes to be under comp_unit_die so the
12446 debugger can find it. We also need to do this for abstract
12447 instances of inlines, since the spec requires the out-of-line copy
12448 to have the same parent. For local class methods, this doesn't
12449 apply; we just use the old DIE. */
12450 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
12451 && (DECL_ARTIFICIAL (decl)
12452 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
12453 && (get_AT_unsigned (old_die, DW_AT_decl_line)
12454 == (unsigned) s.line))))
12456 subr_die = old_die;
12458 /* Clear out the declaration attribute and the formal parameters.
12459 Do not remove all children, because it is possible that this
12460 declaration die was forced using force_decl_die(). In such
12461 cases die that forced declaration die (e.g. TAG_imported_module)
12462 is one of the children that we do not want to remove. */
12463 remove_AT (subr_die, DW_AT_declaration);
12464 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
12468 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12469 add_AT_specification (subr_die, old_die);
12470 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12471 add_AT_file (subr_die, DW_AT_decl_file, file_index);
12472 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12473 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
12478 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
12480 if (TREE_PUBLIC (decl))
12481 add_AT_flag (subr_die, DW_AT_external, 1);
12483 add_name_and_src_coords_attributes (subr_die, decl);
12484 if (debug_info_level > DINFO_LEVEL_TERSE)
12486 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
12487 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
12488 0, 0, context_die);
12491 add_pure_or_virtual_attribute (subr_die, decl);
12492 if (DECL_ARTIFICIAL (decl))
12493 add_AT_flag (subr_die, DW_AT_artificial, 1);
12495 if (TREE_PROTECTED (decl))
12496 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
12497 else if (TREE_PRIVATE (decl))
12498 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
12503 if (!old_die || !get_AT (old_die, DW_AT_inline))
12505 add_AT_flag (subr_die, DW_AT_declaration, 1);
12507 /* The first time we see a member function, it is in the context of
12508 the class to which it belongs. We make sure of this by emitting
12509 the class first. The next time is the definition, which is
12510 handled above. The two may come from the same source text.
12512 Note that force_decl_die() forces function declaration die. It is
12513 later reused to represent definition. */
12514 equate_decl_number_to_die (decl, subr_die);
12517 else if (DECL_ABSTRACT (decl))
12519 if (DECL_DECLARED_INLINE_P (decl))
12521 if (cgraph_function_possibly_inlined_p (decl))
12522 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
12524 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
12528 if (cgraph_function_possibly_inlined_p (decl))
12529 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
12531 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
12534 if (DECL_DECLARED_INLINE_P (decl)
12535 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
12536 add_AT_flag (subr_die, DW_AT_artificial, 1);
12538 equate_decl_number_to_die (decl, subr_die);
12540 else if (!DECL_EXTERNAL (decl))
12542 HOST_WIDE_INT cfa_fb_offset;
12544 if (!old_die || !get_AT (old_die, DW_AT_inline))
12545 equate_decl_number_to_die (decl, subr_die);
12547 if (!flag_reorder_blocks_and_partition)
12549 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
12550 current_function_funcdef_no);
12551 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
12552 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
12553 current_function_funcdef_no);
12554 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
12556 add_pubname (decl, subr_die);
12557 add_arange (decl, subr_die);
12560 { /* Do nothing for now; maybe need to duplicate die, one for
12561 hot section and one for cold section, then use the hot/cold
12562 section begin/end labels to generate the aranges... */
12564 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
12565 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
12566 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
12567 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
12569 add_pubname (decl, subr_die);
12570 add_arange (decl, subr_die);
12571 add_arange (decl, subr_die);
12575 #ifdef MIPS_DEBUGGING_INFO
12576 /* Add a reference to the FDE for this routine. */
12577 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
12580 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
12582 /* We define the "frame base" as the function's CFA. This is more
12583 convenient for several reasons: (1) It's stable across the prologue
12584 and epilogue, which makes it better than just a frame pointer,
12585 (2) With dwarf3, there exists a one-byte encoding that allows us
12586 to reference the .debug_frame data by proxy, but failing that,
12587 (3) We can at least reuse the code inspection and interpretation
12588 code that determines the CFA position at various points in the
12590 /* ??? Use some command-line or configury switch to enable the use
12591 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
12592 consumers that understand it; fall back to "pure" dwarf2 and
12593 convert the CFA data into a location list. */
12595 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
12596 if (list->dw_loc_next)
12597 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
12599 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
12602 /* Compute a displacement from the "steady-state frame pointer" to
12603 the CFA. The former is what all stack slots and argument slots
12604 will reference in the rtl; the later is what we've told the
12605 debugger about. We'll need to adjust all frame_base references
12606 by this displacement. */
12607 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
12609 if (cfun->static_chain_decl)
12610 add_AT_location_description (subr_die, DW_AT_static_link,
12611 loc_descriptor_from_tree (cfun->static_chain_decl));
12614 /* Now output descriptions of the arguments for this function. This gets
12615 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12616 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12617 `...' at the end of the formal parameter list. In order to find out if
12618 there was a trailing ellipsis or not, we must instead look at the type
12619 associated with the FUNCTION_DECL. This will be a node of type
12620 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12621 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12622 an ellipsis at the end. */
12624 /* In the case where we are describing a mere function declaration, all we
12625 need to do here (and all we *can* do here) is to describe the *types* of
12626 its formal parameters. */
12627 if (debug_info_level <= DINFO_LEVEL_TERSE)
12629 else if (declaration)
12630 gen_formal_types_die (decl, subr_die);
12633 /* Generate DIEs to represent all known formal parameters. */
12634 tree arg_decls = DECL_ARGUMENTS (decl);
12637 /* When generating DIEs, generate the unspecified_parameters DIE
12638 instead if we come across the arg "__builtin_va_alist" */
12639 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
12640 if (TREE_CODE (parm) == PARM_DECL)
12642 if (DECL_NAME (parm)
12643 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
12644 "__builtin_va_alist"))
12645 gen_unspecified_parameters_die (parm, subr_die);
12647 gen_decl_die (parm, subr_die);
12650 /* Decide whether we need an unspecified_parameters DIE at the end.
12651 There are 2 more cases to do this for: 1) the ansi ... declaration -
12652 this is detectable when the end of the arg list is not a
12653 void_type_node 2) an unprototyped function declaration (not a
12654 definition). This just means that we have no info about the
12655 parameters at all. */
12656 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
12657 if (fn_arg_types != NULL)
12659 /* This is the prototyped case, check for.... */
12660 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
12661 gen_unspecified_parameters_die (decl, subr_die);
12663 else if (DECL_INITIAL (decl) == NULL_TREE)
12664 gen_unspecified_parameters_die (decl, subr_die);
12667 /* Output Dwarf info for all of the stuff within the body of the function
12668 (if it has one - it may be just a declaration). */
12669 outer_scope = DECL_INITIAL (decl);
12671 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12672 a function. This BLOCK actually represents the outermost binding contour
12673 for the function, i.e. the contour in which the function's formal
12674 parameters and labels get declared. Curiously, it appears that the front
12675 end doesn't actually put the PARM_DECL nodes for the current function onto
12676 the BLOCK_VARS list for this outer scope, but are strung off of the
12677 DECL_ARGUMENTS list for the function instead.
12679 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12680 the LABEL_DECL nodes for the function however, and we output DWARF info
12681 for those in decls_for_scope. Just within the `outer_scope' there will be
12682 a BLOCK node representing the function's outermost pair of curly braces,
12683 and any blocks used for the base and member initializers of a C++
12684 constructor function. */
12685 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
12687 /* Emit a DW_TAG_variable DIE for a named return value. */
12688 if (DECL_NAME (DECL_RESULT (decl)))
12689 gen_decl_die (DECL_RESULT (decl), subr_die);
12691 current_function_has_inlines = 0;
12692 decls_for_scope (outer_scope, subr_die, 0);
12694 #if 0 && defined (MIPS_DEBUGGING_INFO)
12695 if (current_function_has_inlines)
12697 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
12698 if (! comp_unit_has_inlines)
12700 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
12701 comp_unit_has_inlines = 1;
12706 /* Add the calling convention attribute if requested. */
12707 add_calling_convention_attribute (subr_die, decl);
12711 /* Generate a DIE to represent a declared data object. */
12714 gen_variable_die (tree decl, dw_die_ref context_die)
12718 dw_die_ref var_die;
12719 tree origin = decl_ultimate_origin (decl);
12720 dw_die_ref old_die = lookup_decl_die (decl);
12721 int declaration = (DECL_EXTERNAL (decl)
12722 /* If DECL is COMDAT and has not actually been
12723 emitted, we cannot take its address; there
12724 might end up being no definition anywhere in
12725 the program. For example, consider the C++
12729 struct S { static const int i = 7; };
12734 int f() { return S<int>::i; }
12736 Here, S<int>::i is not DECL_EXTERNAL, but no
12737 definition is required, so the compiler will
12738 not emit a definition. */
12739 || (TREE_CODE (decl) == VAR_DECL
12740 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
12741 || class_or_namespace_scope_p (context_die));
12743 com_decl = fortran_common (decl, &off);
12745 /* Symbol in common gets emitted as a child of the common block, in the form
12748 ??? This creates a new common block die for every common block symbol.
12749 Better to share same common block die for all symbols in that block. */
12753 dw_die_ref com_die;
12754 const char *cnam = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
12755 dw_loc_descr_ref loc = loc_descriptor_from_tree (com_decl);
12757 field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0);
12758 var_die = new_die (DW_TAG_common_block, context_die, decl);
12759 add_name_and_src_coords_attributes (var_die, field);
12760 add_AT_flag (var_die, DW_AT_external, 1);
12761 add_AT_loc (var_die, DW_AT_location, loc);
12762 com_die = new_die (DW_TAG_member, var_die, decl);
12763 add_name_and_src_coords_attributes (com_die, decl);
12764 add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl),
12765 TREE_THIS_VOLATILE (decl), context_die);
12766 add_AT_loc (com_die, DW_AT_data_member_location,
12767 int_loc_descriptor (off));
12768 add_pubname_string (cnam, var_die); /* ??? needed? */
12772 var_die = new_die (DW_TAG_variable, context_die, decl);
12774 if (origin != NULL)
12775 add_abstract_origin_attribute (var_die, origin);
12777 /* Loop unrolling can create multiple blocks that refer to the same
12778 static variable, so we must test for the DW_AT_declaration flag.
12780 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12781 copy decls and set the DECL_ABSTRACT flag on them instead of
12784 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12786 ??? The declare_in_namespace support causes us to get two DIEs for one
12787 variable, both of which are declarations. We want to avoid considering
12788 one to be a specification, so we must test that this DIE is not a
12790 else if (old_die && TREE_STATIC (decl) && ! declaration
12791 && get_AT_flag (old_die, DW_AT_declaration) == 1)
12793 /* This is a definition of a C++ class level static. */
12794 add_AT_specification (var_die, old_die);
12795 if (DECL_NAME (decl))
12797 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
12798 struct dwarf_file_data * file_index = lookup_filename (s.file);
12800 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
12801 add_AT_file (var_die, DW_AT_decl_file, file_index);
12803 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
12804 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
12809 tree type = TREE_TYPE (decl);
12810 if ((TREE_CODE (decl) == PARM_DECL
12811 || TREE_CODE (decl) == RESULT_DECL)
12812 && DECL_BY_REFERENCE (decl))
12813 type = TREE_TYPE (type);
12815 add_name_and_src_coords_attributes (var_die, decl);
12816 add_type_attribute (var_die, type, TREE_READONLY (decl),
12817 TREE_THIS_VOLATILE (decl), context_die);
12819 if (TREE_PUBLIC (decl))
12820 add_AT_flag (var_die, DW_AT_external, 1);
12822 if (DECL_ARTIFICIAL (decl))
12823 add_AT_flag (var_die, DW_AT_artificial, 1);
12825 if (TREE_PROTECTED (decl))
12826 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
12827 else if (TREE_PRIVATE (decl))
12828 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
12832 add_AT_flag (var_die, DW_AT_declaration, 1);
12834 if (DECL_ABSTRACT (decl) || declaration)
12835 equate_decl_number_to_die (decl, var_die);
12837 if (! declaration && ! DECL_ABSTRACT (decl))
12839 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
12840 add_pubname (decl, var_die);
12843 tree_add_const_value_attribute (var_die, decl);
12846 /* Generate a DIE to represent a label identifier. */
12849 gen_label_die (tree decl, dw_die_ref context_die)
12851 tree origin = decl_ultimate_origin (decl);
12852 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
12854 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12856 if (origin != NULL)
12857 add_abstract_origin_attribute (lbl_die, origin);
12859 add_name_and_src_coords_attributes (lbl_die, decl);
12861 if (DECL_ABSTRACT (decl))
12862 equate_decl_number_to_die (decl, lbl_die);
12865 insn = DECL_RTL_IF_SET (decl);
12867 /* Deleted labels are programmer specified labels which have been
12868 eliminated because of various optimizations. We still emit them
12869 here so that it is possible to put breakpoints on them. */
12873 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
12875 /* When optimization is enabled (via -O) some parts of the compiler
12876 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12877 represent source-level labels which were explicitly declared by
12878 the user. This really shouldn't be happening though, so catch
12879 it if it ever does happen. */
12880 gcc_assert (!INSN_DELETED_P (insn));
12882 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
12883 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
12888 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12889 attributes to the DIE for a block STMT, to describe where the inlined
12890 function was called from. This is similar to add_src_coords_attributes. */
12893 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
12895 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
12897 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
12898 add_AT_unsigned (die, DW_AT_call_line, s.line);
12902 /* If STMT's abstract origin is a function declaration and STMT's
12903 first subblock's abstract origin is the function's outermost block,
12904 then we're looking at the main entry point. */
12906 is_inlined_entry_point (const_tree stmt)
12910 if (!stmt || TREE_CODE (stmt) != BLOCK)
12913 decl = block_ultimate_origin (stmt);
12915 if (!decl || TREE_CODE (decl) != FUNCTION_DECL)
12918 block = BLOCK_SUBBLOCKS (stmt);
12922 if (TREE_CODE (block) != BLOCK)
12925 block = block_ultimate_origin (block);
12928 return block == DECL_INITIAL (decl);
12931 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12932 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12935 add_high_low_attributes (tree stmt, dw_die_ref die)
12937 char label[MAX_ARTIFICIAL_LABEL_BYTES];
12939 if (BLOCK_FRAGMENT_CHAIN (stmt))
12943 if (is_inlined_entry_point (stmt))
12945 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12946 BLOCK_NUMBER (stmt));
12947 add_AT_lbl_id (die, DW_AT_entry_pc, label);
12950 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
12952 chain = BLOCK_FRAGMENT_CHAIN (stmt);
12955 add_ranges (chain);
12956 chain = BLOCK_FRAGMENT_CHAIN (chain);
12963 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
12964 BLOCK_NUMBER (stmt));
12965 add_AT_lbl_id (die, DW_AT_low_pc, label);
12966 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
12967 BLOCK_NUMBER (stmt));
12968 add_AT_lbl_id (die, DW_AT_high_pc, label);
12972 /* Generate a DIE for a lexical block. */
12975 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
12977 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
12979 if (! BLOCK_ABSTRACT (stmt))
12980 add_high_low_attributes (stmt, stmt_die);
12982 decls_for_scope (stmt, stmt_die, depth);
12985 /* Generate a DIE for an inlined subprogram. */
12988 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
12990 tree decl = block_ultimate_origin (stmt);
12992 /* Emit info for the abstract instance first, if we haven't yet. We
12993 must emit this even if the block is abstract, otherwise when we
12994 emit the block below (or elsewhere), we may end up trying to emit
12995 a die whose origin die hasn't been emitted, and crashing. */
12996 dwarf2out_abstract_function (decl);
12998 if (! BLOCK_ABSTRACT (stmt))
13000 dw_die_ref subr_die
13001 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
13003 add_abstract_origin_attribute (subr_die, decl);
13004 add_high_low_attributes (stmt, subr_die);
13005 add_call_src_coords_attributes (stmt, subr_die);
13007 decls_for_scope (stmt, subr_die, depth);
13008 current_function_has_inlines = 1;
13011 /* We may get here if we're the outer block of function A that was
13012 inlined into function B that was inlined into function C. When
13013 generating debugging info for C, dwarf2out_abstract_function(B)
13014 would mark all inlined blocks as abstract, including this one.
13015 So, we wouldn't (and shouldn't) expect labels to be generated
13016 for this one. Instead, just emit debugging info for
13017 declarations within the block. This is particularly important
13018 in the case of initializers of arguments passed from B to us:
13019 if they're statement expressions containing declarations, we
13020 wouldn't generate dies for their abstract variables, and then,
13021 when generating dies for the real variables, we'd die (pun
13023 gen_lexical_block_die (stmt, context_die, depth);
13026 /* Generate a DIE for a field in a record, or structure. */
13029 gen_field_die (tree decl, dw_die_ref context_die)
13031 dw_die_ref decl_die;
13033 if (TREE_TYPE (decl) == error_mark_node)
13036 decl_die = new_die (DW_TAG_member, context_die, decl);
13037 add_name_and_src_coords_attributes (decl_die, decl);
13038 add_type_attribute (decl_die, member_declared_type (decl),
13039 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
13042 if (DECL_BIT_FIELD_TYPE (decl))
13044 add_byte_size_attribute (decl_die, decl);
13045 add_bit_size_attribute (decl_die, decl);
13046 add_bit_offset_attribute (decl_die, decl);
13049 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
13050 add_data_member_location_attribute (decl_die, decl);
13052 if (DECL_ARTIFICIAL (decl))
13053 add_AT_flag (decl_die, DW_AT_artificial, 1);
13055 if (TREE_PROTECTED (decl))
13056 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
13057 else if (TREE_PRIVATE (decl))
13058 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
13060 /* Equate decl number to die, so that we can look up this decl later on. */
13061 equate_decl_number_to_die (decl, decl_die);
13065 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13066 Use modified_type_die instead.
13067 We keep this code here just in case these types of DIEs may be needed to
13068 represent certain things in other languages (e.g. Pascal) someday. */
13071 gen_pointer_type_die (tree type, dw_die_ref context_die)
13074 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
13076 equate_type_number_to_die (type, ptr_die);
13077 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13078 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13081 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13082 Use modified_type_die instead.
13083 We keep this code here just in case these types of DIEs may be needed to
13084 represent certain things in other languages (e.g. Pascal) someday. */
13087 gen_reference_type_die (tree type, dw_die_ref context_die)
13090 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
13092 equate_type_number_to_die (type, ref_die);
13093 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
13094 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
13098 /* Generate a DIE for a pointer to a member type. */
13101 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
13104 = new_die (DW_TAG_ptr_to_member_type,
13105 scope_die_for (type, context_die), type);
13107 equate_type_number_to_die (type, ptr_die);
13108 add_AT_die_ref (ptr_die, DW_AT_containing_type,
13109 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
13110 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
13113 /* Generate the DIE for the compilation unit. */
13116 gen_compile_unit_die (const char *filename)
13119 char producer[250];
13120 const char *language_string = lang_hooks.name;
13123 die = new_die (DW_TAG_compile_unit, NULL, NULL);
13127 add_name_attribute (die, filename);
13128 /* Don't add cwd for <built-in>. */
13129 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
13130 add_comp_dir_attribute (die);
13133 sprintf (producer, "%s %s", language_string, version_string);
13135 #ifdef MIPS_DEBUGGING_INFO
13136 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13137 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13138 not appear in the producer string, the debugger reaches the conclusion
13139 that the object file is stripped and has no debugging information.
13140 To get the MIPS/SGI debugger to believe that there is debugging
13141 information in the object file, we add a -g to the producer string. */
13142 if (debug_info_level > DINFO_LEVEL_TERSE)
13143 strcat (producer, " -g");
13146 add_AT_string (die, DW_AT_producer, producer);
13148 if (strcmp (language_string, "GNU C++") == 0)
13149 language = DW_LANG_C_plus_plus;
13150 else if (strcmp (language_string, "GNU Ada") == 0)
13151 language = DW_LANG_Ada95;
13152 else if (strcmp (language_string, "GNU F77") == 0)
13153 language = DW_LANG_Fortran77;
13154 else if (strcmp (language_string, "GNU Fortran") == 0)
13155 language = DW_LANG_Fortran95;
13156 else if (strcmp (language_string, "GNU Pascal") == 0)
13157 language = DW_LANG_Pascal83;
13158 else if (strcmp (language_string, "GNU Java") == 0)
13159 language = DW_LANG_Java;
13160 else if (strcmp (language_string, "GNU Objective-C") == 0)
13161 language = DW_LANG_ObjC;
13162 else if (strcmp (language_string, "GNU Objective-C++") == 0)
13163 language = DW_LANG_ObjC_plus_plus;
13165 language = DW_LANG_C89;
13167 add_AT_unsigned (die, DW_AT_language, language);
13171 /* Generate the DIE for a base class. */
13174 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
13176 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
13178 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
13179 add_data_member_location_attribute (die, binfo);
13181 if (BINFO_VIRTUAL_P (binfo))
13182 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
13184 if (access == access_public_node)
13185 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
13186 else if (access == access_protected_node)
13187 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
13190 /* Generate a DIE for a class member. */
13193 gen_member_die (tree type, dw_die_ref context_die)
13196 tree binfo = TYPE_BINFO (type);
13199 /* If this is not an incomplete type, output descriptions of each of its
13200 members. Note that as we output the DIEs necessary to represent the
13201 members of this record or union type, we will also be trying to output
13202 DIEs to represent the *types* of those members. However the `type'
13203 function (above) will specifically avoid generating type DIEs for member
13204 types *within* the list of member DIEs for this (containing) type except
13205 for those types (of members) which are explicitly marked as also being
13206 members of this (containing) type themselves. The g++ front- end can
13207 force any given type to be treated as a member of some other (containing)
13208 type by setting the TYPE_CONTEXT of the given (member) type to point to
13209 the TREE node representing the appropriate (containing) type. */
13211 /* First output info about the base classes. */
13214 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
13218 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
13219 gen_inheritance_die (base,
13220 (accesses ? VEC_index (tree, accesses, i)
13221 : access_public_node), context_die);
13224 /* Now output info about the data members and type members. */
13225 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
13227 /* If we thought we were generating minimal debug info for TYPE
13228 and then changed our minds, some of the member declarations
13229 may have already been defined. Don't define them again, but
13230 do put them in the right order. */
13232 child = lookup_decl_die (member);
13234 splice_child_die (context_die, child);
13236 gen_decl_die (member, context_die);
13239 /* Now output info about the function members (if any). */
13240 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
13242 /* Don't include clones in the member list. */
13243 if (DECL_ABSTRACT_ORIGIN (member))
13246 child = lookup_decl_die (member);
13248 splice_child_die (context_die, child);
13250 gen_decl_die (member, context_die);
13254 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13255 is set, we pretend that the type was never defined, so we only get the
13256 member DIEs needed by later specification DIEs. */
13259 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
13260 enum debug_info_usage usage)
13262 dw_die_ref type_die = lookup_type_die (type);
13263 dw_die_ref scope_die = 0;
13265 int complete = (TYPE_SIZE (type)
13266 && (! TYPE_STUB_DECL (type)
13267 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
13268 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
13269 complete = complete && should_emit_struct_debug (type, usage);
13271 if (type_die && ! complete)
13274 if (TYPE_CONTEXT (type) != NULL_TREE
13275 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13276 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
13279 scope_die = scope_die_for (type, context_die);
13281 if (! type_die || (nested && scope_die == comp_unit_die))
13282 /* First occurrence of type or toplevel definition of nested class. */
13284 dw_die_ref old_die = type_die;
13286 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
13287 ? record_type_tag (type) : DW_TAG_union_type,
13289 equate_type_number_to_die (type, type_die);
13291 add_AT_specification (type_die, old_die);
13293 add_name_attribute (type_die, type_tag (type));
13296 remove_AT (type_die, DW_AT_declaration);
13298 /* If this type has been completed, then give it a byte_size attribute and
13299 then give a list of members. */
13300 if (complete && !ns_decl)
13302 /* Prevent infinite recursion in cases where the type of some member of
13303 this type is expressed in terms of this type itself. */
13304 TREE_ASM_WRITTEN (type) = 1;
13305 add_byte_size_attribute (type_die, type);
13306 if (TYPE_STUB_DECL (type) != NULL_TREE)
13307 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
13309 /* If the first reference to this type was as the return type of an
13310 inline function, then it may not have a parent. Fix this now. */
13311 if (type_die->die_parent == NULL)
13312 add_child_die (scope_die, type_die);
13314 push_decl_scope (type);
13315 gen_member_die (type, type_die);
13318 /* GNU extension: Record what type our vtable lives in. */
13319 if (TYPE_VFIELD (type))
13321 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
13323 gen_type_die (vtype, context_die);
13324 add_AT_die_ref (type_die, DW_AT_containing_type,
13325 lookup_type_die (vtype));
13330 add_AT_flag (type_die, DW_AT_declaration, 1);
13332 /* We don't need to do this for function-local types. */
13333 if (TYPE_STUB_DECL (type)
13334 && ! decl_function_context (TYPE_STUB_DECL (type)))
13335 VEC_safe_push (tree, gc, incomplete_types, type);
13338 if (get_AT (type_die, DW_AT_name))
13339 add_pubtype (type, type_die);
13342 /* Generate a DIE for a subroutine _type_. */
13345 gen_subroutine_type_die (tree type, dw_die_ref context_die)
13347 tree return_type = TREE_TYPE (type);
13348 dw_die_ref subr_die
13349 = new_die (DW_TAG_subroutine_type,
13350 scope_die_for (type, context_die), type);
13352 equate_type_number_to_die (type, subr_die);
13353 add_prototyped_attribute (subr_die, type);
13354 add_type_attribute (subr_die, return_type, 0, 0, context_die);
13355 gen_formal_types_die (type, subr_die);
13357 if (get_AT (subr_die, DW_AT_name))
13358 add_pubtype (type, subr_die);
13361 /* Generate a DIE for a type definition. */
13364 gen_typedef_die (tree decl, dw_die_ref context_die)
13366 dw_die_ref type_die;
13369 if (TREE_ASM_WRITTEN (decl))
13372 TREE_ASM_WRITTEN (decl) = 1;
13373 type_die = new_die (DW_TAG_typedef, context_die, decl);
13374 origin = decl_ultimate_origin (decl);
13375 if (origin != NULL)
13376 add_abstract_origin_attribute (type_die, origin);
13381 add_name_and_src_coords_attributes (type_die, decl);
13382 if (DECL_ORIGINAL_TYPE (decl))
13384 type = DECL_ORIGINAL_TYPE (decl);
13386 gcc_assert (type != TREE_TYPE (decl));
13387 equate_type_number_to_die (TREE_TYPE (decl), type_die);
13390 type = TREE_TYPE (decl);
13392 add_type_attribute (type_die, type, TREE_READONLY (decl),
13393 TREE_THIS_VOLATILE (decl), context_die);
13396 if (DECL_ABSTRACT (decl))
13397 equate_decl_number_to_die (decl, type_die);
13399 if (get_AT (type_die, DW_AT_name))
13400 add_pubtype (decl, type_die);
13403 /* Generate a type description DIE. */
13406 gen_type_die_with_usage (tree type, dw_die_ref context_die,
13407 enum debug_info_usage usage)
13410 struct array_descr_info info;
13412 if (type == NULL_TREE || type == error_mark_node)
13415 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13416 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
13418 if (TREE_ASM_WRITTEN (type))
13421 /* Prevent broken recursion; we can't hand off to the same type. */
13422 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
13424 TREE_ASM_WRITTEN (type) = 1;
13425 gen_decl_die (TYPE_NAME (type), context_die);
13429 /* If this is an array type with hidden descriptor, handle it first. */
13430 if (!TREE_ASM_WRITTEN (type)
13431 && lang_hooks.types.get_array_descr_info
13432 && lang_hooks.types.get_array_descr_info (type, &info))
13434 gen_descr_array_type_die (type, &info, context_die);
13435 TREE_ASM_WRITTEN (type) = 1;
13439 /* We are going to output a DIE to represent the unqualified version
13440 of this type (i.e. without any const or volatile qualifiers) so
13441 get the main variant (i.e. the unqualified version) of this type
13442 now. (Vectors are special because the debugging info is in the
13443 cloned type itself). */
13444 if (TREE_CODE (type) != VECTOR_TYPE)
13445 type = type_main_variant (type);
13447 if (TREE_ASM_WRITTEN (type))
13450 switch (TREE_CODE (type))
13456 case REFERENCE_TYPE:
13457 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13458 ensures that the gen_type_die recursion will terminate even if the
13459 type is recursive. Recursive types are possible in Ada. */
13460 /* ??? We could perhaps do this for all types before the switch
13462 TREE_ASM_WRITTEN (type) = 1;
13464 /* For these types, all that is required is that we output a DIE (or a
13465 set of DIEs) to represent the "basis" type. */
13466 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13467 DINFO_USAGE_IND_USE);
13471 /* This code is used for C++ pointer-to-data-member types.
13472 Output a description of the relevant class type. */
13473 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
13474 DINFO_USAGE_IND_USE);
13476 /* Output a description of the type of the object pointed to. */
13477 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13478 DINFO_USAGE_IND_USE);
13480 /* Now output a DIE to represent this pointer-to-data-member type
13482 gen_ptr_to_mbr_type_die (type, context_die);
13485 case FUNCTION_TYPE:
13486 /* Force out return type (in case it wasn't forced out already). */
13487 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13488 DINFO_USAGE_DIR_USE);
13489 gen_subroutine_type_die (type, context_die);
13493 /* Force out return type (in case it wasn't forced out already). */
13494 gen_type_die_with_usage (TREE_TYPE (type), context_die,
13495 DINFO_USAGE_DIR_USE);
13496 gen_subroutine_type_die (type, context_die);
13500 gen_array_type_die (type, context_die);
13504 gen_array_type_die (type, context_die);
13507 case ENUMERAL_TYPE:
13510 case QUAL_UNION_TYPE:
13511 /* If this is a nested type whose containing class hasn't been written
13512 out yet, writing it out will cover this one, too. This does not apply
13513 to instantiations of member class templates; they need to be added to
13514 the containing class as they are generated. FIXME: This hurts the
13515 idea of combining type decls from multiple TUs, since we can't predict
13516 what set of template instantiations we'll get. */
13517 if (TYPE_CONTEXT (type)
13518 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
13519 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
13521 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
13523 if (TREE_ASM_WRITTEN (type))
13526 /* If that failed, attach ourselves to the stub. */
13527 push_decl_scope (TYPE_CONTEXT (type));
13528 context_die = lookup_type_die (TYPE_CONTEXT (type));
13533 declare_in_namespace (type, context_die);
13537 if (TREE_CODE (type) == ENUMERAL_TYPE)
13539 /* This might have been written out by the call to
13540 declare_in_namespace. */
13541 if (!TREE_ASM_WRITTEN (type))
13542 gen_enumeration_type_die (type, context_die);
13545 gen_struct_or_union_type_die (type, context_die, usage);
13550 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13551 it up if it is ever completed. gen_*_type_die will set it for us
13552 when appropriate. */
13558 case FIXED_POINT_TYPE:
13561 /* No DIEs needed for fundamental types. */
13565 /* No Dwarf representation currently defined. */
13569 gcc_unreachable ();
13572 TREE_ASM_WRITTEN (type) = 1;
13576 gen_type_die (tree type, dw_die_ref context_die)
13578 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
13581 /* Generate a DIE for a tagged type instantiation. */
13584 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
13586 if (type == NULL_TREE || type == error_mark_node)
13589 /* We are going to output a DIE to represent the unqualified version of
13590 this type (i.e. without any const or volatile qualifiers) so make sure
13591 that we have the main variant (i.e. the unqualified version) of this
13593 gcc_assert (type == type_main_variant (type));
13595 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
13596 an instance of an unresolved type. */
13598 switch (TREE_CODE (type))
13603 case ENUMERAL_TYPE:
13604 gen_inlined_enumeration_type_die (type, context_die);
13608 gen_inlined_structure_type_die (type, context_die);
13612 case QUAL_UNION_TYPE:
13613 gen_inlined_union_type_die (type, context_die);
13617 gcc_unreachable ();
13621 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
13622 things which are local to the given block. */
13625 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
13627 int must_output_die = 0;
13630 enum tree_code origin_code;
13632 /* Ignore blocks that are NULL. */
13633 if (stmt == NULL_TREE)
13636 /* If the block is one fragment of a non-contiguous block, do not
13637 process the variables, since they will have been done by the
13638 origin block. Do process subblocks. */
13639 if (BLOCK_FRAGMENT_ORIGIN (stmt))
13643 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
13644 gen_block_die (sub, context_die, depth + 1);
13649 /* Determine the "ultimate origin" of this block. This block may be an
13650 inlined instance of an inlined instance of inline function, so we have
13651 to trace all of the way back through the origin chain to find out what
13652 sort of node actually served as the original seed for the creation of
13653 the current block. */
13654 origin = block_ultimate_origin (stmt);
13655 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
13657 /* Determine if we need to output any Dwarf DIEs at all to represent this
13659 if (origin_code == FUNCTION_DECL)
13660 /* The outer scopes for inlinings *must* always be represented. We
13661 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13662 must_output_die = 1;
13665 /* In the case where the current block represents an inlining of the
13666 "body block" of an inline function, we must *NOT* output any DIE for
13667 this block because we have already output a DIE to represent the whole
13668 inlined function scope and the "body block" of any function doesn't
13669 really represent a different scope according to ANSI C rules. So we
13670 check here to make sure that this block does not represent a "body
13671 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13672 if (! is_body_block (origin ? origin : stmt))
13674 /* Determine if this block directly contains any "significant"
13675 local declarations which we will need to output DIEs for. */
13676 if (debug_info_level > DINFO_LEVEL_TERSE)
13677 /* We are not in terse mode so *any* local declaration counts
13678 as being a "significant" one. */
13679 must_output_die = (BLOCK_VARS (stmt) != NULL
13680 && (TREE_USED (stmt)
13681 || TREE_ASM_WRITTEN (stmt)
13682 || BLOCK_ABSTRACT (stmt)));
13684 /* We are in terse mode, so only local (nested) function
13685 definitions count as "significant" local declarations. */
13686 for (decl = BLOCK_VARS (stmt);
13687 decl != NULL; decl = TREE_CHAIN (decl))
13688 if (TREE_CODE (decl) == FUNCTION_DECL
13689 && DECL_INITIAL (decl))
13691 must_output_die = 1;
13697 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13698 DIE for any block which contains no significant local declarations at
13699 all. Rather, in such cases we just call `decls_for_scope' so that any
13700 needed Dwarf info for any sub-blocks will get properly generated. Note
13701 that in terse mode, our definition of what constitutes a "significant"
13702 local declaration gets restricted to include only inlined function
13703 instances and local (nested) function definitions. */
13704 if (must_output_die)
13706 if (origin_code == FUNCTION_DECL)
13707 gen_inlined_subroutine_die (stmt, context_die, depth);
13709 gen_lexical_block_die (stmt, context_die, depth);
13712 decls_for_scope (stmt, context_die, depth);
13715 /* Generate all of the decls declared within a given scope and (recursively)
13716 all of its sub-blocks. */
13719 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
13724 /* Ignore NULL blocks. */
13725 if (stmt == NULL_TREE)
13728 if (TREE_USED (stmt))
13730 /* Output the DIEs to represent all of the data objects and typedefs
13731 declared directly within this block but not within any nested
13732 sub-blocks. Also, nested function and tag DIEs have been
13733 generated with a parent of NULL; fix that up now. */
13734 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
13738 if (TREE_CODE (decl) == FUNCTION_DECL)
13739 die = lookup_decl_die (decl);
13740 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
13741 die = lookup_type_die (TREE_TYPE (decl));
13745 if (die != NULL && die->die_parent == NULL)
13746 add_child_die (context_die, die);
13747 /* Do not produce debug information for static variables since
13748 these might be optimized out. We are called for these later
13749 in varpool_analyze_pending_decls.
13751 But *do* produce it for Fortran COMMON variables because,
13752 even though they are static, their names can differ depending
13753 on the scope, which we need to preserve. */
13754 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
13755 && !(is_fortran () && TREE_PUBLIC (decl)))
13758 gen_decl_die (decl, context_die);
13762 /* If we're at -g1, we're not interested in subblocks. */
13763 if (debug_info_level <= DINFO_LEVEL_TERSE)
13766 /* Output the DIEs to represent all sub-blocks (and the items declared
13767 therein) of this block. */
13768 for (subblocks = BLOCK_SUBBLOCKS (stmt);
13770 subblocks = BLOCK_CHAIN (subblocks))
13771 gen_block_die (subblocks, context_die, depth + 1);
13774 /* Is this a typedef we can avoid emitting? */
13777 is_redundant_typedef (const_tree decl)
13779 if (TYPE_DECL_IS_STUB (decl))
13782 if (DECL_ARTIFICIAL (decl)
13783 && DECL_CONTEXT (decl)
13784 && is_tagged_type (DECL_CONTEXT (decl))
13785 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
13786 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
13787 /* Also ignore the artificial member typedef for the class name. */
13793 /* Returns the DIE for decl. A DIE will always be returned. */
13796 force_decl_die (tree decl)
13798 dw_die_ref decl_die;
13799 unsigned saved_external_flag;
13800 tree save_fn = NULL_TREE;
13801 decl_die = lookup_decl_die (decl);
13804 dw_die_ref context_die;
13805 tree decl_context = DECL_CONTEXT (decl);
13808 /* Find die that represents this context. */
13809 if (TYPE_P (decl_context))
13810 context_die = force_type_die (decl_context);
13812 context_die = force_decl_die (decl_context);
13815 context_die = comp_unit_die;
13817 decl_die = lookup_decl_die (decl);
13821 switch (TREE_CODE (decl))
13823 case FUNCTION_DECL:
13824 /* Clear current_function_decl, so that gen_subprogram_die thinks
13825 that this is a declaration. At this point, we just want to force
13826 declaration die. */
13827 save_fn = current_function_decl;
13828 current_function_decl = NULL_TREE;
13829 gen_subprogram_die (decl, context_die);
13830 current_function_decl = save_fn;
13834 /* Set external flag to force declaration die. Restore it after
13835 gen_decl_die() call. */
13836 saved_external_flag = DECL_EXTERNAL (decl);
13837 DECL_EXTERNAL (decl) = 1;
13838 gen_decl_die (decl, context_die);
13839 DECL_EXTERNAL (decl) = saved_external_flag;
13842 case NAMESPACE_DECL:
13843 dwarf2out_decl (decl);
13847 gcc_unreachable ();
13850 /* We should be able to find the DIE now. */
13852 decl_die = lookup_decl_die (decl);
13853 gcc_assert (decl_die);
13859 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13860 always returned. */
13863 force_type_die (tree type)
13865 dw_die_ref type_die;
13867 type_die = lookup_type_die (type);
13870 dw_die_ref context_die;
13871 if (TYPE_CONTEXT (type))
13873 if (TYPE_P (TYPE_CONTEXT (type)))
13874 context_die = force_type_die (TYPE_CONTEXT (type));
13876 context_die = force_decl_die (TYPE_CONTEXT (type));
13879 context_die = comp_unit_die;
13881 type_die = modified_type_die (type, TYPE_READONLY (type),
13882 TYPE_VOLATILE (type), context_die);
13883 gcc_assert (type_die);
13888 /* Force out any required namespaces to be able to output DECL,
13889 and return the new context_die for it, if it's changed. */
13892 setup_namespace_context (tree thing, dw_die_ref context_die)
13894 tree context = (DECL_P (thing)
13895 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
13896 if (context && TREE_CODE (context) == NAMESPACE_DECL)
13897 /* Force out the namespace. */
13898 context_die = force_decl_die (context);
13900 return context_die;
13903 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13904 type) within its namespace, if appropriate.
13906 For compatibility with older debuggers, namespace DIEs only contain
13907 declarations; all definitions are emitted at CU scope. */
13910 declare_in_namespace (tree thing, dw_die_ref context_die)
13912 dw_die_ref ns_context;
13914 if (debug_info_level <= DINFO_LEVEL_TERSE)
13917 /* If this decl is from an inlined function, then don't try to emit it in its
13918 namespace, as we will get confused. It would have already been emitted
13919 when the abstract instance of the inline function was emitted anyways. */
13920 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
13923 ns_context = setup_namespace_context (thing, context_die);
13925 if (ns_context != context_die)
13927 if (DECL_P (thing))
13928 gen_decl_die (thing, ns_context);
13930 gen_type_die (thing, ns_context);
13934 /* Generate a DIE for a namespace or namespace alias. */
13937 gen_namespace_die (tree decl)
13939 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
13941 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13942 they are an alias of. */
13943 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
13945 /* Output a real namespace. */
13946 dw_die_ref namespace_die
13947 = new_die (DW_TAG_namespace, context_die, decl);
13948 add_name_and_src_coords_attributes (namespace_die, decl);
13949 equate_decl_number_to_die (decl, namespace_die);
13953 /* Output a namespace alias. */
13955 /* Force out the namespace we are an alias of, if necessary. */
13956 dw_die_ref origin_die
13957 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
13959 /* Now create the namespace alias DIE. */
13960 dw_die_ref namespace_die
13961 = new_die (DW_TAG_imported_declaration, context_die, decl);
13962 add_name_and_src_coords_attributes (namespace_die, decl);
13963 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
13964 equate_decl_number_to_die (decl, namespace_die);
13968 /* Generate Dwarf debug information for a decl described by DECL. */
13971 gen_decl_die (tree decl, dw_die_ref context_die)
13975 if (DECL_P (decl) && DECL_IGNORED_P (decl))
13978 switch (TREE_CODE (decl))
13984 /* The individual enumerators of an enum type get output when we output
13985 the Dwarf representation of the relevant enum type itself. */
13988 case FUNCTION_DECL:
13989 /* Don't output any DIEs to represent mere function declarations,
13990 unless they are class members or explicit block externs. */
13991 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
13992 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
13997 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13998 on local redeclarations of global functions. That seems broken. */
13999 if (current_function_decl != decl)
14000 /* This is only a declaration. */;
14003 /* If we're emitting a clone, emit info for the abstract instance. */
14004 if (DECL_ORIGIN (decl) != decl)
14005 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
14007 /* If we're emitting an out-of-line copy of an inline function,
14008 emit info for the abstract instance and set up to refer to it. */
14009 else if (cgraph_function_possibly_inlined_p (decl)
14010 && ! DECL_ABSTRACT (decl)
14011 && ! class_or_namespace_scope_p (context_die)
14012 /* dwarf2out_abstract_function won't emit a die if this is just
14013 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14014 that case, because that works only if we have a die. */
14015 && DECL_INITIAL (decl) != NULL_TREE)
14017 dwarf2out_abstract_function (decl);
14018 set_decl_origin_self (decl);
14021 /* Otherwise we're emitting the primary DIE for this decl. */
14022 else if (debug_info_level > DINFO_LEVEL_TERSE)
14024 /* Before we describe the FUNCTION_DECL itself, make sure that we
14025 have described its return type. */
14026 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14028 /* And its virtual context. */
14029 if (DECL_VINDEX (decl) != NULL_TREE)
14030 gen_type_die (DECL_CONTEXT (decl), context_die);
14032 /* And its containing type. */
14033 origin = decl_class_context (decl);
14034 if (origin != NULL_TREE)
14035 gen_type_die_for_member (origin, decl, context_die);
14037 /* And its containing namespace. */
14038 declare_in_namespace (decl, context_die);
14041 /* Now output a DIE to represent the function itself. */
14042 gen_subprogram_die (decl, context_die);
14046 /* If we are in terse mode, don't generate any DIEs to represent any
14047 actual typedefs. */
14048 if (debug_info_level <= DINFO_LEVEL_TERSE)
14051 /* In the special case of a TYPE_DECL node representing the declaration
14052 of some type tag, if the given TYPE_DECL is marked as having been
14053 instantiated from some other (original) TYPE_DECL node (e.g. one which
14054 was generated within the original definition of an inline function) we
14055 have to generate a special (abbreviated) DW_TAG_structure_type,
14056 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14057 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE
14058 && is_tagged_type (TREE_TYPE (decl)))
14060 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
14064 if (is_redundant_typedef (decl))
14065 gen_type_die (TREE_TYPE (decl), context_die);
14067 /* Output a DIE to represent the typedef itself. */
14068 gen_typedef_die (decl, context_die);
14072 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14073 gen_label_die (decl, context_die);
14078 /* If we are in terse mode, don't generate any DIEs to represent any
14079 variable declarations or definitions. */
14080 if (debug_info_level <= DINFO_LEVEL_TERSE)
14083 /* If this is the global definition of the Fortran COMMON block, we don't
14084 need to do anything. Syntactically, the block itself has no identity,
14085 just its constituent identifiers. */
14086 if (TREE_CODE (decl) == VAR_DECL
14087 && TREE_PUBLIC (decl)
14088 && TREE_STATIC (decl)
14090 && !DECL_HAS_VALUE_EXPR_P (decl))
14093 /* Output any DIEs that are needed to specify the type of this data
14095 if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl))
14096 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14098 gen_type_die (TREE_TYPE (decl), context_die);
14100 /* And its containing type. */
14101 origin = decl_class_context (decl);
14102 if (origin != NULL_TREE)
14103 gen_type_die_for_member (origin, decl, context_die);
14105 /* And its containing namespace. */
14106 declare_in_namespace (decl, context_die);
14108 /* Now output the DIE to represent the data object itself. This gets
14109 complicated because of the possibility that the VAR_DECL really
14110 represents an inlined instance of a formal parameter for an inline
14112 origin = decl_ultimate_origin (decl);
14113 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
14114 gen_formal_parameter_die (decl, context_die);
14116 gen_variable_die (decl, context_die);
14120 /* Ignore the nameless fields that are used to skip bits but handle C++
14121 anonymous unions and structs. */
14122 if (DECL_NAME (decl) != NULL_TREE
14123 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
14124 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
14126 gen_type_die (member_declared_type (decl), context_die);
14127 gen_field_die (decl, context_die);
14132 if (DECL_BY_REFERENCE (decl))
14133 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
14135 gen_type_die (TREE_TYPE (decl), context_die);
14136 gen_formal_parameter_die (decl, context_die);
14139 case NAMESPACE_DECL:
14140 gen_namespace_die (decl);
14144 /* Probably some frontend-internal decl. Assume we don't care. */
14145 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
14150 /* Output debug information for global decl DECL. Called from toplev.c after
14151 compilation proper has finished. */
14154 dwarf2out_global_decl (tree decl)
14156 /* Output DWARF2 information for file-scope tentative data object
14157 declarations, file-scope (extern) function declarations (which had no
14158 corresponding body) and file-scope tagged type declarations and
14159 definitions which have not yet been forced out.
14161 Ignore the global decl of any Fortran COMMON blocks which also wind up here
14162 though they have already been described in the local scope for the
14163 procedures using them. */
14164 if (TREE_CODE (decl) == VAR_DECL
14165 && TREE_PUBLIC (decl) && TREE_STATIC (decl) && is_fortran ())
14168 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
14169 dwarf2out_decl (decl);
14172 /* Output debug information for type decl DECL. Called from toplev.c
14173 and from language front ends (to record built-in types). */
14175 dwarf2out_type_decl (tree decl, int local)
14178 dwarf2out_decl (decl);
14181 /* Output debug information for imported module or decl. */
14184 dwarf2out_imported_module_or_decl (tree decl, tree context)
14186 dw_die_ref imported_die, at_import_die;
14187 dw_die_ref scope_die;
14188 expanded_location xloc;
14190 if (debug_info_level <= DINFO_LEVEL_TERSE)
14195 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14196 We need decl DIE for reference and scope die. First, get DIE for the decl
14199 /* Get the scope die for decl context. Use comp_unit_die for global module
14200 or decl. If die is not found for non globals, force new die. */
14202 scope_die = comp_unit_die;
14203 else if (TYPE_P (context))
14205 if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
14207 scope_die = force_type_die (context);
14210 scope_die = force_decl_die (context);
14212 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14213 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
14215 if (is_base_type (TREE_TYPE (decl)))
14216 at_import_die = base_type_die (TREE_TYPE (decl));
14218 at_import_die = force_type_die (TREE_TYPE (decl));
14222 at_import_die = lookup_decl_die (decl);
14223 if (!at_import_die)
14225 /* If we're trying to avoid duplicate debug info, we may not have
14226 emitted the member decl for this field. Emit it now. */
14227 if (TREE_CODE (decl) == FIELD_DECL)
14229 tree type = DECL_CONTEXT (decl);
14230 dw_die_ref type_context_die;
14232 if (TYPE_CONTEXT (type))
14233 if (TYPE_P (TYPE_CONTEXT (type)))
14235 if (!should_emit_struct_debug (TYPE_CONTEXT (type),
14236 DINFO_USAGE_DIR_USE))
14238 type_context_die = force_type_die (TYPE_CONTEXT (type));
14241 type_context_die = force_decl_die (TYPE_CONTEXT (type));
14243 type_context_die = comp_unit_die;
14244 gen_type_die_for_member (type, decl, type_context_die);
14246 at_import_die = force_decl_die (decl);
14250 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14251 if (TREE_CODE (decl) == NAMESPACE_DECL)
14252 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
14254 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
14256 xloc = expand_location (input_location);
14257 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
14258 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
14259 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
14262 /* Write the debugging output for DECL. */
14265 dwarf2out_decl (tree decl)
14267 dw_die_ref context_die = comp_unit_die;
14269 switch (TREE_CODE (decl))
14274 case FUNCTION_DECL:
14275 /* What we would really like to do here is to filter out all mere
14276 file-scope declarations of file-scope functions which are never
14277 referenced later within this translation unit (and keep all of ones
14278 that *are* referenced later on) but we aren't clairvoyant, so we have
14279 no idea which functions will be referenced in the future (i.e. later
14280 on within the current translation unit). So here we just ignore all
14281 file-scope function declarations which are not also definitions. If
14282 and when the debugger needs to know something about these functions,
14283 it will have to hunt around and find the DWARF information associated
14284 with the definition of the function.
14286 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14287 nodes represent definitions and which ones represent mere
14288 declarations. We have to check DECL_INITIAL instead. That's because
14289 the C front-end supports some weird semantics for "extern inline"
14290 function definitions. These can get inlined within the current
14291 translation unit (and thus, we need to generate Dwarf info for their
14292 abstract instances so that the Dwarf info for the concrete inlined
14293 instances can have something to refer to) but the compiler never
14294 generates any out-of-lines instances of such things (despite the fact
14295 that they *are* definitions).
14297 The important point is that the C front-end marks these "extern
14298 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14299 them anyway. Note that the C++ front-end also plays some similar games
14300 for inline function definitions appearing within include files which
14301 also contain `#pragma interface' pragmas. */
14302 if (DECL_INITIAL (decl) == NULL_TREE)
14305 /* If we're a nested function, initially use a parent of NULL; if we're
14306 a plain function, this will be fixed up in decls_for_scope. If
14307 we're a method, it will be ignored, since we already have a DIE. */
14308 if (decl_function_context (decl)
14309 /* But if we're in terse mode, we don't care about scope. */
14310 && debug_info_level > DINFO_LEVEL_TERSE)
14311 context_die = NULL;
14315 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14316 declaration and if the declaration was never even referenced from
14317 within this entire compilation unit. We suppress these DIEs in
14318 order to save space in the .debug section (by eliminating entries
14319 which are probably useless). Note that we must not suppress
14320 block-local extern declarations (whether used or not) because that
14321 would screw-up the debugger's name lookup mechanism and cause it to
14322 miss things which really ought to be in scope at a given point. */
14323 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
14326 /* For local statics lookup proper context die. */
14327 if (TREE_STATIC (decl) && decl_function_context (decl))
14328 context_die = lookup_decl_die (DECL_CONTEXT (decl));
14330 /* If we are in terse mode, don't generate any DIEs to represent any
14331 variable declarations or definitions. */
14332 if (debug_info_level <= DINFO_LEVEL_TERSE)
14336 case NAMESPACE_DECL:
14337 if (debug_info_level <= DINFO_LEVEL_TERSE)
14339 if (lookup_decl_die (decl) != NULL)
14344 /* Don't emit stubs for types unless they are needed by other DIEs. */
14345 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
14348 /* Don't bother trying to generate any DIEs to represent any of the
14349 normal built-in types for the language we are compiling. */
14350 if (DECL_IS_BUILTIN (decl))
14352 /* OK, we need to generate one for `bool' so GDB knows what type
14353 comparisons have. */
14355 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
14356 && ! DECL_IGNORED_P (decl))
14357 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
14362 /* If we are in terse mode, don't generate any DIEs for types. */
14363 if (debug_info_level <= DINFO_LEVEL_TERSE)
14366 /* If we're a function-scope tag, initially use a parent of NULL;
14367 this will be fixed up in decls_for_scope. */
14368 if (decl_function_context (decl))
14369 context_die = NULL;
14377 gen_decl_die (decl, context_die);
14380 /* Output a marker (i.e. a label) for the beginning of the generated code for
14381 a lexical block. */
14384 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
14385 unsigned int blocknum)
14387 switch_to_section (current_function_section ());
14388 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
14391 /* Output a marker (i.e. a label) for the end of the generated code for a
14395 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
14397 switch_to_section (current_function_section ());
14398 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
14401 /* Returns nonzero if it is appropriate not to emit any debugging
14402 information for BLOCK, because it doesn't contain any instructions.
14404 Don't allow this for blocks with nested functions or local classes
14405 as we would end up with orphans, and in the presence of scheduling
14406 we may end up calling them anyway. */
14409 dwarf2out_ignore_block (const_tree block)
14413 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
14414 if (TREE_CODE (decl) == FUNCTION_DECL
14415 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
14421 /* Hash table routines for file_hash. */
14424 file_table_eq (const void *p1_p, const void *p2_p)
14426 const struct dwarf_file_data *const p1 =
14427 (const struct dwarf_file_data *) p1_p;
14428 const char *const p2 = (const char *) p2_p;
14429 return strcmp (p1->filename, p2) == 0;
14433 file_table_hash (const void *p_p)
14435 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
14436 return htab_hash_string (p->filename);
14439 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14440 dwarf2out.c) and return its "index". The index of each (known) filename is
14441 just a unique number which is associated with only that one filename. We
14442 need such numbers for the sake of generating labels (in the .debug_sfnames
14443 section) and references to those files numbers (in the .debug_srcinfo
14444 and.debug_macinfo sections). If the filename given as an argument is not
14445 found in our current list, add it to the list and assign it the next
14446 available unique index number. In order to speed up searches, we remember
14447 the index of the filename was looked up last. This handles the majority of
14450 static struct dwarf_file_data *
14451 lookup_filename (const char *file_name)
14454 struct dwarf_file_data * created;
14456 /* Check to see if the file name that was searched on the previous
14457 call matches this file name. If so, return the index. */
14458 if (file_table_last_lookup
14459 && (file_name == file_table_last_lookup->filename
14460 || strcmp (file_table_last_lookup->filename, file_name) == 0))
14461 return file_table_last_lookup;
14463 /* Didn't match the previous lookup, search the table. */
14464 slot = htab_find_slot_with_hash (file_table, file_name,
14465 htab_hash_string (file_name), INSERT);
14467 return (struct dwarf_file_data *) *slot;
14469 created = GGC_NEW (struct dwarf_file_data);
14470 created->filename = file_name;
14471 created->emitted_number = 0;
14476 /* If the assembler will construct the file table, then translate the compiler
14477 internal file table number into the assembler file table number, and emit
14478 a .file directive if we haven't already emitted one yet. The file table
14479 numbers are different because we prune debug info for unused variables and
14480 types, which may include filenames. */
14483 maybe_emit_file (struct dwarf_file_data * fd)
14485 if (! fd->emitted_number)
14487 if (last_emitted_file)
14488 fd->emitted_number = last_emitted_file->emitted_number + 1;
14490 fd->emitted_number = 1;
14491 last_emitted_file = fd;
14493 if (DWARF2_ASM_LINE_DEBUG_INFO)
14495 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
14496 output_quoted_string (asm_out_file,
14497 remap_debug_filename (fd->filename));
14498 fputc ('\n', asm_out_file);
14502 return fd->emitted_number;
14505 /* Called by the final INSN scan whenever we see a var location. We
14506 use it to drop labels in the right places, and throw the location in
14507 our lookup table. */
14510 dwarf2out_var_location (rtx loc_note)
14512 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
14513 struct var_loc_node *newloc;
14515 static rtx last_insn;
14516 static const char *last_label;
14519 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
14521 prev_insn = PREV_INSN (loc_note);
14523 newloc = GGC_CNEW (struct var_loc_node);
14524 /* If the insn we processed last time is the previous insn
14525 and it is also a var location note, use the label we emitted
14527 if (last_insn != NULL_RTX
14528 && last_insn == prev_insn
14529 && NOTE_P (prev_insn)
14530 && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION)
14532 newloc->label = last_label;
14536 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
14537 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
14539 newloc->label = ggc_strdup (loclabel);
14541 newloc->var_loc_note = loc_note;
14542 newloc->next = NULL;
14544 if (cfun && in_cold_section_p)
14545 newloc->section_label = crtl->subsections.cold_section_label;
14547 newloc->section_label = text_section_label;
14549 last_insn = loc_note;
14550 last_label = newloc->label;
14551 decl = NOTE_VAR_LOCATION_DECL (loc_note);
14552 add_var_loc_to_decl (decl, newloc);
14555 /* We need to reset the locations at the beginning of each
14556 function. We can't do this in the end_function hook, because the
14557 declarations that use the locations won't have been output when
14558 that hook is called. Also compute have_multiple_function_sections here. */
14561 dwarf2out_begin_function (tree fun)
14563 htab_empty (decl_loc_table);
14565 if (function_section (fun) != text_section)
14566 have_multiple_function_sections = true;
14568 dwarf2out_note_section_used ();
14571 /* Output a label to mark the beginning of a source code line entry
14572 and record information relating to this source line, in
14573 'line_info_table' for later output of the .debug_line section. */
14576 dwarf2out_source_line (unsigned int line, const char *filename)
14578 if (debug_info_level >= DINFO_LEVEL_NORMAL
14581 int file_num = maybe_emit_file (lookup_filename (filename));
14583 switch_to_section (current_function_section ());
14585 /* If requested, emit something human-readable. */
14586 if (flag_debug_asm)
14587 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
14590 if (DWARF2_ASM_LINE_DEBUG_INFO)
14592 /* Emit the .loc directive understood by GNU as. */
14593 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
14595 /* Indicate that line number info exists. */
14596 line_info_table_in_use++;
14598 else if (function_section (current_function_decl) != text_section)
14600 dw_separate_line_info_ref line_info;
14601 targetm.asm_out.internal_label (asm_out_file,
14602 SEPARATE_LINE_CODE_LABEL,
14603 separate_line_info_table_in_use);
14605 /* Expand the line info table if necessary. */
14606 if (separate_line_info_table_in_use
14607 == separate_line_info_table_allocated)
14609 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14610 separate_line_info_table
14611 = GGC_RESIZEVEC (dw_separate_line_info_entry,
14612 separate_line_info_table,
14613 separate_line_info_table_allocated);
14614 memset (separate_line_info_table
14615 + separate_line_info_table_in_use,
14617 (LINE_INFO_TABLE_INCREMENT
14618 * sizeof (dw_separate_line_info_entry)));
14621 /* Add the new entry at the end of the line_info_table. */
14623 = &separate_line_info_table[separate_line_info_table_in_use++];
14624 line_info->dw_file_num = file_num;
14625 line_info->dw_line_num = line;
14626 line_info->function = current_function_funcdef_no;
14630 dw_line_info_ref line_info;
14632 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
14633 line_info_table_in_use);
14635 /* Expand the line info table if necessary. */
14636 if (line_info_table_in_use == line_info_table_allocated)
14638 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
14640 = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
14641 line_info_table_allocated);
14642 memset (line_info_table + line_info_table_in_use, 0,
14643 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
14646 /* Add the new entry at the end of the line_info_table. */
14647 line_info = &line_info_table[line_info_table_in_use++];
14648 line_info->dw_file_num = file_num;
14649 line_info->dw_line_num = line;
14654 /* Record the beginning of a new source file. */
14657 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
14659 if (flag_eliminate_dwarf2_dups)
14661 /* Record the beginning of the file for break_out_includes. */
14662 dw_die_ref bincl_die;
14664 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
14665 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
14668 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14670 int file_num = maybe_emit_file (lookup_filename (filename));
14672 switch_to_section (debug_macinfo_section);
14673 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
14674 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
14677 dw2_asm_output_data_uleb128 (file_num, "file %s", filename);
14681 /* Record the end of a source file. */
14684 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
14686 if (flag_eliminate_dwarf2_dups)
14687 /* Record the end of the file for break_out_includes. */
14688 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
14690 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14692 switch_to_section (debug_macinfo_section);
14693 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
14697 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14698 the tail part of the directive line, i.e. the part which is past the
14699 initial whitespace, #, whitespace, directive-name, whitespace part. */
14702 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
14703 const char *buffer ATTRIBUTE_UNUSED)
14705 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14707 switch_to_section (debug_macinfo_section);
14708 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
14709 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14710 dw2_asm_output_nstring (buffer, -1, "The macro");
14714 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14715 the tail part of the directive line, i.e. the part which is past the
14716 initial whitespace, #, whitespace, directive-name, whitespace part. */
14719 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
14720 const char *buffer ATTRIBUTE_UNUSED)
14722 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14724 switch_to_section (debug_macinfo_section);
14725 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
14726 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
14727 dw2_asm_output_nstring (buffer, -1, "The macro");
14731 /* Set up for Dwarf output at the start of compilation. */
14734 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
14736 /* Allocate the file_table. */
14737 file_table = htab_create_ggc (50, file_table_hash,
14738 file_table_eq, NULL);
14740 /* Allocate the decl_die_table. */
14741 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
14742 decl_die_table_eq, NULL);
14744 /* Allocate the decl_loc_table. */
14745 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
14746 decl_loc_table_eq, NULL);
14748 /* Allocate the initial hunk of the decl_scope_table. */
14749 decl_scope_table = VEC_alloc (tree, gc, 256);
14751 /* Allocate the initial hunk of the abbrev_die_table. */
14752 abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT);
14753 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
14754 /* Zero-th entry is allocated, but unused. */
14755 abbrev_die_table_in_use = 1;
14757 /* Allocate the initial hunk of the line_info_table. */
14758 line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT);
14759 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
14761 /* Zero-th entry is allocated, but unused. */
14762 line_info_table_in_use = 1;
14764 /* Allocate the pubtypes and pubnames vectors. */
14765 pubname_table = VEC_alloc (pubname_entry, gc, 32);
14766 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
14768 /* Generate the initial DIE for the .debug section. Note that the (string)
14769 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14770 will (typically) be a relative pathname and that this pathname should be
14771 taken as being relative to the directory from which the compiler was
14772 invoked when the given (base) source file was compiled. We will fill
14773 in this value in dwarf2out_finish. */
14774 comp_unit_die = gen_compile_unit_die (NULL);
14776 incomplete_types = VEC_alloc (tree, gc, 64);
14778 used_rtx_array = VEC_alloc (rtx, gc, 32);
14780 debug_info_section = get_section (DEBUG_INFO_SECTION,
14781 SECTION_DEBUG, NULL);
14782 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
14783 SECTION_DEBUG, NULL);
14784 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
14785 SECTION_DEBUG, NULL);
14786 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
14787 SECTION_DEBUG, NULL);
14788 debug_line_section = get_section (DEBUG_LINE_SECTION,
14789 SECTION_DEBUG, NULL);
14790 debug_loc_section = get_section (DEBUG_LOC_SECTION,
14791 SECTION_DEBUG, NULL);
14792 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
14793 SECTION_DEBUG, NULL);
14794 #ifdef DEBUG_PUBTYPES_SECTION
14795 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
14796 SECTION_DEBUG, NULL);
14798 debug_str_section = get_section (DEBUG_STR_SECTION,
14799 DEBUG_STR_SECTION_FLAGS, NULL);
14800 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
14801 SECTION_DEBUG, NULL);
14802 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
14803 SECTION_DEBUG, NULL);
14805 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
14806 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
14807 DEBUG_ABBREV_SECTION_LABEL, 0);
14808 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
14809 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
14810 COLD_TEXT_SECTION_LABEL, 0);
14811 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
14813 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
14814 DEBUG_INFO_SECTION_LABEL, 0);
14815 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
14816 DEBUG_LINE_SECTION_LABEL, 0);
14817 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
14818 DEBUG_RANGES_SECTION_LABEL, 0);
14819 switch_to_section (debug_abbrev_section);
14820 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
14821 switch_to_section (debug_info_section);
14822 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
14823 switch_to_section (debug_line_section);
14824 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
14826 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14828 switch_to_section (debug_macinfo_section);
14829 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
14830 DEBUG_MACINFO_SECTION_LABEL, 0);
14831 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
14834 switch_to_section (text_section);
14835 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
14836 if (flag_reorder_blocks_and_partition)
14838 cold_text_section = unlikely_text_section ();
14839 switch_to_section (cold_text_section);
14840 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
14844 /* A helper function for dwarf2out_finish called through
14845 ht_forall. Emit one queued .debug_str string. */
14848 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
14850 struct indirect_string_node *node = (struct indirect_string_node *) *h;
14852 if (node->form == DW_FORM_strp)
14854 switch_to_section (debug_str_section);
14855 ASM_OUTPUT_LABEL (asm_out_file, node->label);
14856 assemble_string (node->str, strlen (node->str) + 1);
14862 #if ENABLE_ASSERT_CHECKING
14863 /* Verify that all marks are clear. */
14866 verify_marks_clear (dw_die_ref die)
14870 gcc_assert (! die->die_mark);
14871 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
14873 #endif /* ENABLE_ASSERT_CHECKING */
14875 /* Clear the marks for a die and its children.
14876 Be cool if the mark isn't set. */
14879 prune_unmark_dies (dw_die_ref die)
14885 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
14888 /* Given DIE that we're marking as used, find any other dies
14889 it references as attributes and mark them as used. */
14892 prune_unused_types_walk_attribs (dw_die_ref die)
14897 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
14899 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
14901 /* A reference to another DIE.
14902 Make sure that it will get emitted. */
14903 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
14905 /* Set the string's refcount to 0 so that prune_unused_types_mark
14906 accounts properly for it. */
14907 if (AT_class (a) == dw_val_class_str)
14908 a->dw_attr_val.v.val_str->refcount = 0;
14913 /* Mark DIE as being used. If DOKIDS is true, then walk down
14914 to DIE's children. */
14917 prune_unused_types_mark (dw_die_ref die, int dokids)
14921 if (die->die_mark == 0)
14923 /* We haven't done this node yet. Mark it as used. */
14926 /* We also have to mark its parents as used.
14927 (But we don't want to mark our parents' kids due to this.) */
14928 if (die->die_parent)
14929 prune_unused_types_mark (die->die_parent, 0);
14931 /* Mark any referenced nodes. */
14932 prune_unused_types_walk_attribs (die);
14934 /* If this node is a specification,
14935 also mark the definition, if it exists. */
14936 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
14937 prune_unused_types_mark (die->die_definition, 1);
14940 if (dokids && die->die_mark != 2)
14942 /* We need to walk the children, but haven't done so yet.
14943 Remember that we've walked the kids. */
14946 /* If this is an array type, we need to make sure our
14947 kids get marked, even if they're types. */
14948 if (die->die_tag == DW_TAG_array_type)
14949 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
14951 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
14956 /* Walk the tree DIE and mark types that we actually use. */
14959 prune_unused_types_walk (dw_die_ref die)
14963 /* Don't do anything if this node is already marked. */
14967 switch (die->die_tag)
14969 case DW_TAG_const_type:
14970 case DW_TAG_packed_type:
14971 case DW_TAG_pointer_type:
14972 case DW_TAG_reference_type:
14973 case DW_TAG_volatile_type:
14974 case DW_TAG_typedef:
14975 case DW_TAG_array_type:
14976 case DW_TAG_structure_type:
14977 case DW_TAG_union_type:
14978 case DW_TAG_class_type:
14979 case DW_TAG_interface_type:
14980 case DW_TAG_friend:
14981 case DW_TAG_variant_part:
14982 case DW_TAG_enumeration_type:
14983 case DW_TAG_subroutine_type:
14984 case DW_TAG_string_type:
14985 case DW_TAG_set_type:
14986 case DW_TAG_subrange_type:
14987 case DW_TAG_ptr_to_member_type:
14988 case DW_TAG_file_type:
14989 if (die->die_perennial_p)
14992 /* It's a type node --- don't mark it. */
14996 /* Mark everything else. */
15002 /* Now, mark any dies referenced from here. */
15003 prune_unused_types_walk_attribs (die);
15005 /* Mark children. */
15006 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
15009 /* Increment the string counts on strings referred to from DIE's
15013 prune_unused_types_update_strings (dw_die_ref die)
15018 for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
15019 if (AT_class (a) == dw_val_class_str)
15021 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
15023 /* Avoid unnecessarily putting strings that are used less than
15024 twice in the hash table. */
15026 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
15029 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
15030 htab_hash_string (s->str),
15032 gcc_assert (*slot == NULL);
15038 /* Remove from the tree DIE any dies that aren't marked. */
15041 prune_unused_types_prune (dw_die_ref die)
15045 gcc_assert (die->die_mark);
15046 prune_unused_types_update_strings (die);
15048 if (! die->die_child)
15051 c = die->die_child;
15053 dw_die_ref prev = c;
15054 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
15055 if (c == die->die_child)
15057 /* No marked children between 'prev' and the end of the list. */
15059 /* No marked children at all. */
15060 die->die_child = NULL;
15063 prev->die_sib = c->die_sib;
15064 die->die_child = prev;
15069 if (c != prev->die_sib)
15071 prune_unused_types_prune (c);
15072 } while (c != die->die_child);
15076 /* Remove dies representing declarations that we never use. */
15079 prune_unused_types (void)
15082 limbo_die_node *node;
15085 #if ENABLE_ASSERT_CHECKING
15086 /* All the marks should already be clear. */
15087 verify_marks_clear (comp_unit_die);
15088 for (node = limbo_die_list; node; node = node->next)
15089 verify_marks_clear (node->die);
15090 #endif /* ENABLE_ASSERT_CHECKING */
15092 /* Set the mark on nodes that are actually used. */
15093 prune_unused_types_walk (comp_unit_die);
15094 for (node = limbo_die_list; node; node = node->next)
15095 prune_unused_types_walk (node->die);
15097 /* Also set the mark on nodes referenced from the
15098 pubname_table or arange_table. */
15099 for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++)
15100 prune_unused_types_mark (pub->die, 1);
15101 for (i = 0; i < arange_table_in_use; i++)
15102 prune_unused_types_mark (arange_table[i], 1);
15104 /* Get rid of nodes that aren't marked; and update the string counts. */
15105 if (debug_str_hash)
15106 htab_empty (debug_str_hash);
15107 prune_unused_types_prune (comp_unit_die);
15108 for (node = limbo_die_list; node; node = node->next)
15109 prune_unused_types_prune (node->die);
15111 /* Leave the marks clear. */
15112 prune_unmark_dies (comp_unit_die);
15113 for (node = limbo_die_list; node; node = node->next)
15114 prune_unmark_dies (node->die);
15117 /* Set the parameter to true if there are any relative pathnames in
15120 file_table_relative_p (void ** slot, void *param)
15122 bool *p = (bool *) param;
15123 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
15124 if (!IS_ABSOLUTE_PATH (d->filename))
15132 /* Output stuff that dwarf requires at the end of every file,
15133 and generate the DWARF-2 debugging info. */
15136 dwarf2out_finish (const char *filename)
15138 limbo_die_node *node, *next_node;
15139 dw_die_ref die = 0;
15141 /* Add the name for the main input file now. We delayed this from
15142 dwarf2out_init to avoid complications with PCH. */
15143 add_name_attribute (comp_unit_die, remap_debug_filename (filename));
15144 if (!IS_ABSOLUTE_PATH (filename))
15145 add_comp_dir_attribute (comp_unit_die);
15146 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
15149 htab_traverse (file_table, file_table_relative_p, &p);
15151 add_comp_dir_attribute (comp_unit_die);
15154 /* Traverse the limbo die list, and add parent/child links. The only
15155 dies without parents that should be here are concrete instances of
15156 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15157 For concrete instances, we can get the parent die from the abstract
15159 for (node = limbo_die_list; node; node = next_node)
15161 next_node = node->next;
15164 if (die->die_parent == NULL)
15166 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
15169 add_child_die (origin->die_parent, die);
15170 else if (die == comp_unit_die)
15172 else if (errorcount > 0 || sorrycount > 0)
15173 /* It's OK to be confused by errors in the input. */
15174 add_child_die (comp_unit_die, die);
15177 /* In certain situations, the lexical block containing a
15178 nested function can be optimized away, which results
15179 in the nested function die being orphaned. Likewise
15180 with the return type of that nested function. Force
15181 this to be a child of the containing function.
15183 It may happen that even the containing function got fully
15184 inlined and optimized out. In that case we are lost and
15185 assign the empty child. This should not be big issue as
15186 the function is likely unreachable too. */
15187 tree context = NULL_TREE;
15189 gcc_assert (node->created_for);
15191 if (DECL_P (node->created_for))
15192 context = DECL_CONTEXT (node->created_for);
15193 else if (TYPE_P (node->created_for))
15194 context = TYPE_CONTEXT (node->created_for);
15196 gcc_assert (context
15197 && (TREE_CODE (context) == FUNCTION_DECL
15198 || TREE_CODE (context) == NAMESPACE_DECL));
15200 origin = lookup_decl_die (context);
15202 add_child_die (origin, die);
15204 add_child_die (comp_unit_die, die);
15209 limbo_die_list = NULL;
15211 /* Walk through the list of incomplete types again, trying once more to
15212 emit full debugging info for them. */
15213 retry_incomplete_types ();
15215 if (flag_eliminate_unused_debug_types)
15216 prune_unused_types ();
15218 /* Generate separate CUs for each of the include files we've seen.
15219 They will go into limbo_die_list. */
15220 if (flag_eliminate_dwarf2_dups)
15221 break_out_includes (comp_unit_die);
15223 /* Traverse the DIE's and add add sibling attributes to those DIE's
15224 that have children. */
15225 add_sibling_attributes (comp_unit_die);
15226 for (node = limbo_die_list; node; node = node->next)
15227 add_sibling_attributes (node->die);
15229 /* Output a terminator label for the .text section. */
15230 switch_to_section (text_section);
15231 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
15232 if (flag_reorder_blocks_and_partition)
15234 switch_to_section (unlikely_text_section ());
15235 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
15238 /* We can only use the low/high_pc attributes if all of the code was
15240 if (!have_multiple_function_sections)
15242 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
15243 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
15248 unsigned fde_idx = 0;
15250 /* We need to give .debug_loc and .debug_ranges an appropriate
15251 "base address". Use zero so that these addresses become
15252 absolute. Historically, we've emitted the unexpected
15253 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15254 Emit both to give time for other tools to adapt. */
15255 add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx);
15256 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
15258 add_AT_range_list (comp_unit_die, DW_AT_ranges,
15259 add_ranges_by_labels (text_section_label,
15261 if (flag_reorder_blocks_and_partition)
15262 add_ranges_by_labels (cold_text_section_label,
15265 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
15267 dw_fde_ref fde = &fde_table[fde_idx];
15269 if (fde->dw_fde_switched_sections)
15271 add_ranges_by_labels (fde->dw_fde_hot_section_label,
15272 fde->dw_fde_hot_section_end_label);
15273 add_ranges_by_labels (fde->dw_fde_unlikely_section_label,
15274 fde->dw_fde_unlikely_section_end_label);
15277 add_ranges_by_labels (fde->dw_fde_begin,
15284 /* Output location list section if necessary. */
15285 if (have_location_lists)
15287 /* Output the location lists info. */
15288 switch_to_section (debug_loc_section);
15289 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
15290 DEBUG_LOC_SECTION_LABEL, 0);
15291 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
15292 output_location_lists (die);
15295 if (debug_info_level >= DINFO_LEVEL_NORMAL)
15296 add_AT_lineptr (comp_unit_die, DW_AT_stmt_list,
15297 debug_line_section_label);
15299 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15300 add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
15302 /* Output all of the compilation units. We put the main one last so that
15303 the offsets are available to output_pubnames. */
15304 for (node = limbo_die_list; node; node = node->next)
15305 output_comp_unit (node->die, 0);
15307 output_comp_unit (comp_unit_die, 0);
15309 /* Output the abbreviation table. */
15310 switch_to_section (debug_abbrev_section);
15311 output_abbrev_section ();
15313 /* Output public names table if necessary. */
15314 if (!VEC_empty (pubname_entry, pubname_table))
15316 switch_to_section (debug_pubnames_section);
15317 output_pubnames (pubname_table);
15320 #ifdef DEBUG_PUBTYPES_SECTION
15321 /* Output public types table if necessary. */
15322 if (!VEC_empty (pubname_entry, pubtype_table))
15324 switch_to_section (debug_pubtypes_section);
15325 output_pubnames (pubtype_table);
15329 /* Output the address range information. We only put functions in the arange
15330 table, so don't write it out if we don't have any. */
15331 if (fde_table_in_use)
15333 switch_to_section (debug_aranges_section);
15337 /* Output ranges section if necessary. */
15338 if (ranges_table_in_use)
15340 switch_to_section (debug_ranges_section);
15341 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
15345 /* Output the source line correspondence table. We must do this
15346 even if there is no line information. Otherwise, on an empty
15347 translation unit, we will generate a present, but empty,
15348 .debug_info section. IRIX 6.5 `nm' will then complain when
15349 examining the file. This is done late so that any filenames
15350 used by the debug_info section are marked as 'used'. */
15351 if (! DWARF2_ASM_LINE_DEBUG_INFO)
15353 switch_to_section (debug_line_section);
15354 output_line_info ();
15357 /* Have to end the macro section. */
15358 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
15360 switch_to_section (debug_macinfo_section);
15361 dw2_asm_output_data (1, 0, "End compilation unit");
15364 /* If we emitted any DW_FORM_strp form attribute, output the string
15366 if (debug_str_hash)
15367 htab_traverse (debug_str_hash, output_indirect_string, NULL);
15371 /* This should never be used, but its address is needed for comparisons. */
15372 const struct gcc_debug_hooks dwarf2_debug_hooks;
15374 #endif /* DWARF2_DEBUGGING_INFO */
15376 #include "gt-dwarf2out.h"