1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 #include "coretypes.h"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
62 #include "diagnostic.h"
65 #include "langhooks.h"
68 #ifdef DWARF2_DEBUGGING_INFO
69 static void dwarf2out_source_line (unsigned int, const char *);
72 /* DWARF2 Abbreviation Glossary:
73 CFA = Canonical Frame Address
74 a fixed address on the stack which identifies a call frame.
75 We define it to be the value of SP just before the call insn.
76 The CFA register and offset, which may change during the course
77 of the function, are used to calculate its value at runtime.
78 CFI = Call Frame Instruction
79 an instruction for the DWARF2 abstract machine
80 CIE = Common Information Entry
81 information describing information common to one or more FDEs
82 DIE = Debugging Information Entry
83 FDE = Frame Description Entry
84 information describing the stack call frame, in particular,
85 how to restore registers
87 DW_CFA_... = DWARF2 CFA call frame instruction
88 DW_TAG_... = DWARF2 DIE tag */
90 /* Decide whether we want to emit frame unwind information for the current
94 dwarf2out_do_frame (void)
96 return (write_symbols == DWARF2_DEBUG
97 || write_symbols == VMS_AND_DWARF2_DEBUG
98 #ifdef DWARF2_FRAME_INFO
101 #ifdef DWARF2_UNWIND_INFO
102 || flag_unwind_tables
103 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
108 /* The size of the target's pointer type. */
110 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
113 /* Various versions of targetm.eh_frame_section. Note these must appear
114 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
116 /* Version of targetm.eh_frame_section for systems with named sections. */
118 named_section_eh_frame_section (void)
120 #ifdef EH_FRAME_SECTION_NAME
121 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
122 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
123 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
124 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
128 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
129 && (fde_encoding & 0x70) != DW_EH_PE_aligned
130 && (per_encoding & 0x70) != DW_EH_PE_absptr
131 && (per_encoding & 0x70) != DW_EH_PE_aligned
132 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
133 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
135 named_section_flags (EH_FRAME_SECTION_NAME, flags);
137 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
142 /* Version of targetm.eh_frame_section for systems using collect2. */
144 collect2_eh_frame_section (void)
146 tree label = get_file_function_name ('F');
149 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
150 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label));
151 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
154 /* Default version of targetm.eh_frame_section. */
156 default_eh_frame_section (void)
158 #ifdef EH_FRAME_SECTION_NAME
159 named_section_eh_frame_section ();
161 collect2_eh_frame_section ();
165 /* Array of RTXes referenced by the debugging information, which therefore
166 must be kept around forever. */
167 static GTY(()) varray_type used_rtx_varray;
169 /* A pointer to the base of a list of incomplete types which might be
170 completed at some later time. incomplete_types_list needs to be a VARRAY
171 because we want to tell the garbage collector about it. */
172 static GTY(()) varray_type incomplete_types;
174 /* A pointer to the base of a table of references to declaration
175 scopes. This table is a display which tracks the nesting
176 of declaration scopes at the current scope and containing
177 scopes. This table is used to find the proper place to
178 define type declaration DIE's. */
179 static GTY(()) varray_type decl_scope_table;
181 /* How to start an assembler comment. */
182 #ifndef ASM_COMMENT_START
183 #define ASM_COMMENT_START ";#"
186 typedef struct dw_cfi_struct *dw_cfi_ref;
187 typedef struct dw_fde_struct *dw_fde_ref;
188 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
190 /* Call frames are described using a sequence of Call Frame
191 Information instructions. The register number, offset
192 and address fields are provided as possible operands;
193 their use is selected by the opcode field. */
195 enum dw_cfi_oprnd_type {
197 dw_cfi_oprnd_reg_num,
203 typedef union dw_cfi_oprnd_struct GTY(())
205 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
206 long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
207 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
208 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
212 typedef struct dw_cfi_struct GTY(())
214 dw_cfi_ref dw_cfi_next;
215 enum dwarf_call_frame_info dw_cfi_opc;
216 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
218 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
223 /* This is how we define the location of the CFA. We use to handle it
224 as REG + OFFSET all the time, but now it can be more complex.
225 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
226 Instead of passing around REG and OFFSET, we pass a copy
227 of this structure. */
228 typedef struct cfa_loc GTY(())
233 int indirect; /* 1 if CFA is accessed via a dereference. */
236 /* All call frame descriptions (FDE's) in the GCC generated DWARF
237 refer to a single Common Information Entry (CIE), defined at
238 the beginning of the .debug_frame section. This use of a single
239 CIE obviates the need to keep track of multiple CIE's
240 in the DWARF generation routines below. */
242 typedef struct dw_fde_struct GTY(())
244 const char *dw_fde_begin;
245 const char *dw_fde_current_label;
246 const char *dw_fde_end;
247 dw_cfi_ref dw_fde_cfi;
248 unsigned funcdef_number;
249 unsigned all_throwers_are_sibcalls : 1;
250 unsigned nothrow : 1;
251 unsigned uses_eh_lsda : 1;
255 /* Maximum size (in bytes) of an artificially generated label. */
256 #define MAX_ARTIFICIAL_LABEL_BYTES 30
258 /* The size of addresses as they appear in the Dwarf 2 data.
259 Some architectures use word addresses to refer to code locations,
260 but Dwarf 2 info always uses byte addresses. On such machines,
261 Dwarf 2 addresses need to be larger than the architecture's
263 #ifndef DWARF2_ADDR_SIZE
264 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
267 /* The size in bytes of a DWARF field indicating an offset or length
268 relative to a debug info section, specified to be 4 bytes in the
269 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
272 #ifndef DWARF_OFFSET_SIZE
273 #define DWARF_OFFSET_SIZE 4
276 /* According to the (draft) DWARF 3 specification, the initial length
277 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
278 bytes are 0xffffffff, followed by the length stored in the next 8
281 However, the SGI/MIPS ABI uses an initial length which is equal to
282 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
284 #ifndef DWARF_INITIAL_LENGTH_SIZE
285 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
288 #define DWARF_VERSION 2
290 /* Round SIZE up to the nearest BOUNDARY. */
291 #define DWARF_ROUND(SIZE,BOUNDARY) \
292 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
294 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
295 #ifndef DWARF_CIE_DATA_ALIGNMENT
296 #ifdef STACK_GROWS_DOWNWARD
297 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
299 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
303 /* A pointer to the base of a table that contains frame description
304 information for each routine. */
305 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
307 /* Number of elements currently allocated for fde_table. */
308 static GTY(()) unsigned fde_table_allocated;
310 /* Number of elements in fde_table currently in use. */
311 static GTY(()) unsigned fde_table_in_use;
313 /* Size (in elements) of increments by which we may expand the
315 #define FDE_TABLE_INCREMENT 256
317 /* A list of call frame insns for the CIE. */
318 static GTY(()) dw_cfi_ref cie_cfi_head;
320 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
321 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
322 attribute that accelerates the lookup of the FDE associated
323 with the subprogram. This variable holds the table index of the FDE
324 associated with the current function (body) definition. */
325 static unsigned current_funcdef_fde;
328 struct indirect_string_node GTY(())
331 unsigned int refcount;
336 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
338 static GTY(()) int dw2_string_counter;
339 static GTY(()) unsigned long dwarf2out_cfi_label_num;
341 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
343 /* Forward declarations for functions defined in this file. */
345 static char *stripattributes (const char *);
346 static const char *dwarf_cfi_name (unsigned);
347 static dw_cfi_ref new_cfi (void);
348 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
349 static void add_fde_cfi (const char *, dw_cfi_ref);
350 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
351 static void lookup_cfa (dw_cfa_location *);
352 static void reg_save (const char *, unsigned, unsigned, long);
353 static void initial_return_save (rtx);
354 static long stack_adjust_offset (rtx);
355 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
356 static void output_call_frame_info (int);
357 static void dwarf2out_stack_adjust (rtx);
358 static void queue_reg_save (const char *, rtx, long);
359 static void flush_queued_reg_saves (void);
360 static bool clobbers_queued_reg_save (rtx);
361 static void dwarf2out_frame_debug_expr (rtx, const char *);
363 /* Support for complex CFA locations. */
364 static void output_cfa_loc (dw_cfi_ref);
365 static void get_cfa_from_loc_descr (dw_cfa_location *,
366 struct dw_loc_descr_struct *);
367 static struct dw_loc_descr_struct *build_cfa_loc
369 static void def_cfa_1 (const char *, dw_cfa_location *);
371 /* How to start an assembler comment. */
372 #ifndef ASM_COMMENT_START
373 #define ASM_COMMENT_START ";#"
376 /* Data and reference forms for relocatable data. */
377 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
378 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
380 #ifndef DEBUG_FRAME_SECTION
381 #define DEBUG_FRAME_SECTION ".debug_frame"
384 #ifndef FUNC_BEGIN_LABEL
385 #define FUNC_BEGIN_LABEL "LFB"
388 #ifndef FUNC_END_LABEL
389 #define FUNC_END_LABEL "LFE"
392 #define FRAME_BEGIN_LABEL "Lframe"
393 #define CIE_AFTER_SIZE_LABEL "LSCIE"
394 #define CIE_END_LABEL "LECIE"
395 #define FDE_LABEL "LSFDE"
396 #define FDE_AFTER_SIZE_LABEL "LASFDE"
397 #define FDE_END_LABEL "LEFDE"
398 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
399 #define LINE_NUMBER_END_LABEL "LELT"
400 #define LN_PROLOG_AS_LABEL "LASLTP"
401 #define LN_PROLOG_END_LABEL "LELTP"
402 #define DIE_LABEL_PREFIX "DW"
404 /* The DWARF 2 CFA column which tracks the return address. Normally this
405 is the column for PC, or the first column after all of the hard
407 #ifndef DWARF_FRAME_RETURN_COLUMN
409 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
411 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
415 /* The mapping from gcc register number to DWARF 2 CFA column number. By
416 default, we just provide columns for all registers. */
417 #ifndef DWARF_FRAME_REGNUM
418 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
421 /* The offset from the incoming value of %sp to the top of the stack frame
422 for the current function. */
423 #ifndef INCOMING_FRAME_SP_OFFSET
424 #define INCOMING_FRAME_SP_OFFSET 0
427 /* Hook used by __throw. */
430 expand_builtin_dwarf_sp_column (void)
432 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
435 /* Return a pointer to a copy of the section string name S with all
436 attributes stripped off, and an asterisk prepended (for assemble_name). */
439 stripattributes (const char *s)
441 char *stripped = xmalloc (strlen (s) + 2);
446 while (*s && *s != ',')
453 /* Generate code to initialize the register size table. */
456 expand_builtin_init_dwarf_reg_sizes (tree address)
459 enum machine_mode mode = TYPE_MODE (char_type_node);
460 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
461 rtx mem = gen_rtx_MEM (BLKmode, addr);
462 bool wrote_return_column = false;
464 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
465 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
467 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
468 enum machine_mode save_mode = reg_raw_mode[i];
471 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
472 save_mode = choose_hard_reg_mode (i, 1, true);
473 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
475 if (save_mode == VOIDmode)
477 wrote_return_column = true;
479 size = GET_MODE_SIZE (save_mode);
483 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
486 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
487 if (! wrote_return_column)
489 i = DWARF_ALT_FRAME_RETURN_COLUMN;
490 wrote_return_column = false;
492 i = DWARF_FRAME_RETURN_COLUMN;
495 if (! wrote_return_column)
497 enum machine_mode save_mode = Pmode;
498 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
499 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
500 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
504 /* Convert a DWARF call frame info. operation to its string name */
507 dwarf_cfi_name (unsigned int cfi_opc)
511 case DW_CFA_advance_loc:
512 return "DW_CFA_advance_loc";
514 return "DW_CFA_offset";
516 return "DW_CFA_restore";
520 return "DW_CFA_set_loc";
521 case DW_CFA_advance_loc1:
522 return "DW_CFA_advance_loc1";
523 case DW_CFA_advance_loc2:
524 return "DW_CFA_advance_loc2";
525 case DW_CFA_advance_loc4:
526 return "DW_CFA_advance_loc4";
527 case DW_CFA_offset_extended:
528 return "DW_CFA_offset_extended";
529 case DW_CFA_restore_extended:
530 return "DW_CFA_restore_extended";
531 case DW_CFA_undefined:
532 return "DW_CFA_undefined";
533 case DW_CFA_same_value:
534 return "DW_CFA_same_value";
535 case DW_CFA_register:
536 return "DW_CFA_register";
537 case DW_CFA_remember_state:
538 return "DW_CFA_remember_state";
539 case DW_CFA_restore_state:
540 return "DW_CFA_restore_state";
542 return "DW_CFA_def_cfa";
543 case DW_CFA_def_cfa_register:
544 return "DW_CFA_def_cfa_register";
545 case DW_CFA_def_cfa_offset:
546 return "DW_CFA_def_cfa_offset";
549 case DW_CFA_def_cfa_expression:
550 return "DW_CFA_def_cfa_expression";
551 case DW_CFA_expression:
552 return "DW_CFA_expression";
553 case DW_CFA_offset_extended_sf:
554 return "DW_CFA_offset_extended_sf";
555 case DW_CFA_def_cfa_sf:
556 return "DW_CFA_def_cfa_sf";
557 case DW_CFA_def_cfa_offset_sf:
558 return "DW_CFA_def_cfa_offset_sf";
560 /* SGI/MIPS specific */
561 case DW_CFA_MIPS_advance_loc8:
562 return "DW_CFA_MIPS_advance_loc8";
565 case DW_CFA_GNU_window_save:
566 return "DW_CFA_GNU_window_save";
567 case DW_CFA_GNU_args_size:
568 return "DW_CFA_GNU_args_size";
569 case DW_CFA_GNU_negative_offset_extended:
570 return "DW_CFA_GNU_negative_offset_extended";
573 return "DW_CFA_<unknown>";
577 /* Return a pointer to a newly allocated Call Frame Instruction. */
579 static inline dw_cfi_ref
582 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
584 cfi->dw_cfi_next = NULL;
585 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
586 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
591 /* Add a Call Frame Instruction to list of instructions. */
594 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
598 /* Find the end of the chain. */
599 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
605 /* Generate a new label for the CFI info to refer to. */
608 dwarf2out_cfi_label (void)
610 static char label[20];
612 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
613 ASM_OUTPUT_LABEL (asm_out_file, label);
617 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
618 or to the CIE if LABEL is NULL. */
621 add_fde_cfi (const char *label, dw_cfi_ref cfi)
625 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
628 label = dwarf2out_cfi_label ();
630 if (fde->dw_fde_current_label == NULL
631 || strcmp (label, fde->dw_fde_current_label) != 0)
635 fde->dw_fde_current_label = label = xstrdup (label);
637 /* Set the location counter to the new label. */
639 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
640 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
641 add_cfi (&fde->dw_fde_cfi, xcfi);
644 add_cfi (&fde->dw_fde_cfi, cfi);
648 add_cfi (&cie_cfi_head, cfi);
651 /* Subroutine of lookup_cfa. */
654 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
656 switch (cfi->dw_cfi_opc)
658 case DW_CFA_def_cfa_offset:
659 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
661 case DW_CFA_def_cfa_register:
662 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
665 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
666 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
668 case DW_CFA_def_cfa_expression:
669 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
676 /* Find the previous value for the CFA. */
679 lookup_cfa (dw_cfa_location *loc)
683 loc->reg = (unsigned long) -1;
686 loc->base_offset = 0;
688 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
689 lookup_cfa_1 (cfi, loc);
691 if (fde_table_in_use)
693 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
694 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
695 lookup_cfa_1 (cfi, loc);
699 /* The current rule for calculating the DWARF2 canonical frame address. */
700 static dw_cfa_location cfa;
702 /* The register used for saving registers to the stack, and its offset
704 static dw_cfa_location cfa_store;
706 /* The running total of the size of arguments pushed onto the stack. */
707 static long args_size;
709 /* The last args_size we actually output. */
710 static long old_args_size;
712 /* Entry point to update the canonical frame address (CFA).
713 LABEL is passed to add_fde_cfi. The value of CFA is now to be
714 calculated from REG+OFFSET. */
717 dwarf2out_def_cfa (const char *label, unsigned int reg, long int offset)
724 def_cfa_1 (label, &loc);
727 /* This routine does the actual work. The CFA is now calculated from
728 the dw_cfa_location structure. */
731 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
734 dw_cfa_location old_cfa, loc;
739 if (cfa_store.reg == loc.reg && loc.indirect == 0)
740 cfa_store.offset = loc.offset;
742 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
743 lookup_cfa (&old_cfa);
745 /* If nothing changed, no need to issue any call frame instructions. */
746 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
747 && loc.indirect == old_cfa.indirect
748 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
753 if (loc.reg == old_cfa.reg && !loc.indirect)
755 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
756 indicating the CFA register did not change but the offset
758 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
759 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
762 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
763 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
766 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
767 indicating the CFA register has changed to <register> but the
768 offset has not changed. */
769 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
770 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
774 else if (loc.indirect == 0)
776 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
777 indicating the CFA register has changed to <register> with
778 the specified offset. */
779 cfi->dw_cfi_opc = DW_CFA_def_cfa;
780 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
781 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
785 /* Construct a DW_CFA_def_cfa_expression instruction to
786 calculate the CFA using a full location expression since no
787 register-offset pair is available. */
788 struct dw_loc_descr_struct *loc_list;
790 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
791 loc_list = build_cfa_loc (&loc);
792 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
795 add_fde_cfi (label, cfi);
798 /* Add the CFI for saving a register. REG is the CFA column number.
799 LABEL is passed to add_fde_cfi.
800 If SREG is -1, the register is saved at OFFSET from the CFA;
801 otherwise it is saved in SREG. */
804 reg_save (const char *label, unsigned int reg, unsigned int sreg, long int offset)
806 dw_cfi_ref cfi = new_cfi ();
808 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
810 /* The following comparison is correct. -1 is used to indicate that
811 the value isn't a register number. */
812 if (sreg == (unsigned int) -1)
815 /* The register number won't fit in 6 bits, so we have to use
817 cfi->dw_cfi_opc = DW_CFA_offset_extended;
819 cfi->dw_cfi_opc = DW_CFA_offset;
821 #ifdef ENABLE_CHECKING
823 /* If we get an offset that is not a multiple of
824 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
825 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
827 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
829 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
833 offset /= DWARF_CIE_DATA_ALIGNMENT;
835 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
837 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
839 else if (sreg == reg)
840 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
844 cfi->dw_cfi_opc = DW_CFA_register;
845 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
848 add_fde_cfi (label, cfi);
851 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
852 This CFI tells the unwinder that it needs to restore the window registers
853 from the previous frame's window save area.
855 ??? Perhaps we should note in the CIE where windows are saved (instead of
856 assuming 0(cfa)) and what registers are in the window. */
859 dwarf2out_window_save (const char *label)
861 dw_cfi_ref cfi = new_cfi ();
863 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
864 add_fde_cfi (label, cfi);
867 /* Add a CFI to update the running total of the size of arguments
868 pushed onto the stack. */
871 dwarf2out_args_size (const char *label, long int size)
875 if (size == old_args_size)
878 old_args_size = size;
881 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
882 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
883 add_fde_cfi (label, cfi);
886 /* Entry point for saving a register to the stack. REG is the GCC register
887 number. LABEL and OFFSET are passed to reg_save. */
890 dwarf2out_reg_save (const char *label, unsigned int reg, long int offset)
892 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
895 /* Entry point for saving the return address in the stack.
896 LABEL and OFFSET are passed to reg_save. */
899 dwarf2out_return_save (const char *label, long int offset)
901 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
904 /* Entry point for saving the return address in a register.
905 LABEL and SREG are passed to reg_save. */
908 dwarf2out_return_reg (const char *label, unsigned int sreg)
910 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
913 /* Record the initial position of the return address. RTL is
914 INCOMING_RETURN_ADDR_RTX. */
917 initial_return_save (rtx rtl)
919 unsigned int reg = (unsigned int) -1;
920 HOST_WIDE_INT offset = 0;
922 switch (GET_CODE (rtl))
925 /* RA is in a register. */
926 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
930 /* RA is on the stack. */
932 switch (GET_CODE (rtl))
935 if (REGNO (rtl) != STACK_POINTER_REGNUM)
941 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
943 offset = INTVAL (XEXP (rtl, 1));
947 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
949 offset = -INTVAL (XEXP (rtl, 1));
959 /* The return address is at some offset from any value we can
960 actually load. For instance, on the SPARC it is in %i7+8. Just
961 ignore the offset for now; it doesn't matter for unwinding frames. */
962 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
964 initial_return_save (XEXP (rtl, 0));
971 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
974 /* Given a SET, calculate the amount of stack adjustment it
978 stack_adjust_offset (rtx pattern)
980 rtx src = SET_SRC (pattern);
981 rtx dest = SET_DEST (pattern);
982 HOST_WIDE_INT offset = 0;
985 if (dest == stack_pointer_rtx)
987 /* (set (reg sp) (plus (reg sp) (const_int))) */
988 code = GET_CODE (src);
989 if (! (code == PLUS || code == MINUS)
990 || XEXP (src, 0) != stack_pointer_rtx
991 || GET_CODE (XEXP (src, 1)) != CONST_INT)
994 offset = INTVAL (XEXP (src, 1));
998 else if (GET_CODE (dest) == MEM)
1000 /* (set (mem (pre_dec (reg sp))) (foo)) */
1001 src = XEXP (dest, 0);
1002 code = GET_CODE (src);
1008 if (XEXP (src, 0) == stack_pointer_rtx)
1010 rtx val = XEXP (XEXP (src, 1), 1);
1011 /* We handle only adjustments by constant amount. */
1012 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1013 GET_CODE (val) != CONST_INT)
1015 offset = -INTVAL (val);
1022 if (XEXP (src, 0) == stack_pointer_rtx)
1024 offset = GET_MODE_SIZE (GET_MODE (dest));
1031 if (XEXP (src, 0) == stack_pointer_rtx)
1033 offset = -GET_MODE_SIZE (GET_MODE (dest));
1048 /* Check INSN to see if it looks like a push or a stack adjustment, and
1049 make a note of it if it does. EH uses this information to find out how
1050 much extra space it needs to pop off the stack. */
1053 dwarf2out_stack_adjust (rtx insn)
1055 HOST_WIDE_INT offset;
1059 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1061 /* Extract the size of the args from the CALL rtx itself. */
1062 insn = PATTERN (insn);
1063 if (GET_CODE (insn) == PARALLEL)
1064 insn = XVECEXP (insn, 0, 0);
1065 if (GET_CODE (insn) == SET)
1066 insn = SET_SRC (insn);
1067 if (GET_CODE (insn) != CALL)
1070 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1074 /* If only calls can throw, and we have a frame pointer,
1075 save up adjustments until we see the CALL_INSN. */
1076 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1079 if (GET_CODE (insn) == BARRIER)
1081 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1082 the compiler will have already emitted a stack adjustment, but
1083 doesn't bother for calls to noreturn functions. */
1084 #ifdef STACK_GROWS_DOWNWARD
1085 offset = -args_size;
1090 else if (GET_CODE (PATTERN (insn)) == SET)
1091 offset = stack_adjust_offset (PATTERN (insn));
1092 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1093 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1095 /* There may be stack adjustments inside compound insns. Search
1097 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1098 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1099 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1107 if (cfa.reg == STACK_POINTER_REGNUM)
1108 cfa.offset += offset;
1110 #ifndef STACK_GROWS_DOWNWARD
1114 args_size += offset;
1118 label = dwarf2out_cfi_label ();
1119 def_cfa_1 (label, &cfa);
1120 dwarf2out_args_size (label, args_size);
1125 /* We delay emitting a register save until either (a) we reach the end
1126 of the prologue or (b) the register is clobbered. This clusters
1127 register saves so that there are fewer pc advances. */
1129 struct queued_reg_save GTY(())
1131 struct queued_reg_save *next;
1136 static GTY(()) struct queued_reg_save *queued_reg_saves;
1138 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1139 static const char *last_reg_save_label;
1142 queue_reg_save (const char *label, rtx reg, long int offset)
1144 struct queued_reg_save *q = ggc_alloc (sizeof (*q));
1146 q->next = queued_reg_saves;
1148 q->cfa_offset = offset;
1149 queued_reg_saves = q;
1151 last_reg_save_label = label;
1155 flush_queued_reg_saves (void)
1157 struct queued_reg_save *q, *next;
1159 for (q = queued_reg_saves; q; q = next)
1161 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1165 queued_reg_saves = NULL;
1166 last_reg_save_label = NULL;
1170 clobbers_queued_reg_save (rtx insn)
1172 struct queued_reg_save *q;
1174 for (q = queued_reg_saves; q; q = q->next)
1175 if (modified_in_p (q->reg, insn))
1182 /* A temporary register holding an integral value used in adjusting SP
1183 or setting up the store_reg. The "offset" field holds the integer
1184 value, not an offset. */
1185 static dw_cfa_location cfa_temp;
1187 /* Record call frame debugging information for an expression EXPR,
1188 which either sets SP or FP (adjusting how we calculate the frame
1189 address) or saves a register to the stack. LABEL indicates the
1192 This function encodes a state machine mapping rtxes to actions on
1193 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1194 users need not read the source code.
1196 The High-Level Picture
1198 Changes in the register we use to calculate the CFA: Currently we
1199 assume that if you copy the CFA register into another register, we
1200 should take the other one as the new CFA register; this seems to
1201 work pretty well. If it's wrong for some target, it's simple
1202 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1204 Changes in the register we use for saving registers to the stack:
1205 This is usually SP, but not always. Again, we deduce that if you
1206 copy SP into another register (and SP is not the CFA register),
1207 then the new register is the one we will be using for register
1208 saves. This also seems to work.
1210 Register saves: There's not much guesswork about this one; if
1211 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1212 register save, and the register used to calculate the destination
1213 had better be the one we think we're using for this purpose.
1215 Except: If the register being saved is the CFA register, and the
1216 offset is nonzero, we are saving the CFA, so we assume we have to
1217 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1218 the intent is to save the value of SP from the previous frame.
1220 Invariants / Summaries of Rules
1222 cfa current rule for calculating the CFA. It usually
1223 consists of a register and an offset.
1224 cfa_store register used by prologue code to save things to the stack
1225 cfa_store.offset is the offset from the value of
1226 cfa_store.reg to the actual CFA
1227 cfa_temp register holding an integral value. cfa_temp.offset
1228 stores the value, which will be used to adjust the
1229 stack pointer. cfa_temp is also used like cfa_store,
1230 to track stores to the stack via fp or a temp reg.
1232 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1233 with cfa.reg as the first operand changes the cfa.reg and its
1234 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1237 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1238 expression yielding a constant. This sets cfa_temp.reg
1239 and cfa_temp.offset.
1241 Rule 5: Create a new register cfa_store used to save items to the
1244 Rules 10-14: Save a register to the stack. Define offset as the
1245 difference of the original location and cfa_store's
1246 location (or cfa_temp's location if cfa_temp is used).
1250 "{a,b}" indicates a choice of a xor b.
1251 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1254 (set <reg1> <reg2>:cfa.reg)
1255 effects: cfa.reg = <reg1>
1256 cfa.offset unchanged
1257 cfa_temp.reg = <reg1>
1258 cfa_temp.offset = cfa.offset
1261 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1262 {<const_int>,<reg>:cfa_temp.reg}))
1263 effects: cfa.reg = sp if fp used
1264 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1265 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1266 if cfa_store.reg==sp
1269 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1270 effects: cfa.reg = fp
1271 cfa_offset += +/- <const_int>
1274 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1275 constraints: <reg1> != fp
1277 effects: cfa.reg = <reg1>
1278 cfa_temp.reg = <reg1>
1279 cfa_temp.offset = cfa.offset
1282 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1283 constraints: <reg1> != fp
1285 effects: cfa_store.reg = <reg1>
1286 cfa_store.offset = cfa.offset - cfa_temp.offset
1289 (set <reg> <const_int>)
1290 effects: cfa_temp.reg = <reg>
1291 cfa_temp.offset = <const_int>
1294 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1295 effects: cfa_temp.reg = <reg1>
1296 cfa_temp.offset |= <const_int>
1299 (set <reg> (high <exp>))
1303 (set <reg> (lo_sum <exp> <const_int>))
1304 effects: cfa_temp.reg = <reg>
1305 cfa_temp.offset = <const_int>
1308 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1309 effects: cfa_store.offset -= <const_int>
1310 cfa.offset = cfa_store.offset if cfa.reg == sp
1312 cfa.base_offset = -cfa_store.offset
1315 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1316 effects: cfa_store.offset += -/+ mode_size(mem)
1317 cfa.offset = cfa_store.offset if cfa.reg == sp
1319 cfa.base_offset = -cfa_store.offset
1322 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1325 effects: cfa.reg = <reg1>
1326 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1329 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1330 effects: cfa.reg = <reg1>
1331 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1334 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1335 effects: cfa.reg = <reg1>
1336 cfa.base_offset = -cfa_temp.offset
1337 cfa_temp.offset -= mode_size(mem) */
1340 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1343 HOST_WIDE_INT offset;
1345 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1346 the PARALLEL independently. The first element is always processed if
1347 it is a SET. This is for backward compatibility. Other elements
1348 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1349 flag is set in them. */
1350 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1353 int limit = XVECLEN (expr, 0);
1355 for (par_index = 0; par_index < limit; par_index++)
1356 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1357 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1359 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1364 if (GET_CODE (expr) != SET)
1367 src = SET_SRC (expr);
1368 dest = SET_DEST (expr);
1370 switch (GET_CODE (dest))
1374 /* Update the CFA rule wrt SP or FP. Make sure src is
1375 relative to the current CFA register. */
1376 switch (GET_CODE (src))
1378 /* Setting FP from SP. */
1380 if (cfa.reg == (unsigned) REGNO (src))
1386 /* We used to require that dest be either SP or FP, but the
1387 ARM copies SP to a temporary register, and from there to
1388 FP. So we just rely on the backends to only set
1389 RTX_FRAME_RELATED_P on appropriate insns. */
1390 cfa.reg = REGNO (dest);
1391 cfa_temp.reg = cfa.reg;
1392 cfa_temp.offset = cfa.offset;
1398 if (dest == stack_pointer_rtx)
1402 switch (GET_CODE (XEXP (src, 1)))
1405 offset = INTVAL (XEXP (src, 1));
1408 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1410 offset = cfa_temp.offset;
1416 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1418 /* Restoring SP from FP in the epilogue. */
1419 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1421 cfa.reg = STACK_POINTER_REGNUM;
1423 else if (GET_CODE (src) == LO_SUM)
1424 /* Assume we've set the source reg of the LO_SUM from sp. */
1426 else if (XEXP (src, 0) != stack_pointer_rtx)
1429 if (GET_CODE (src) != MINUS)
1431 if (cfa.reg == STACK_POINTER_REGNUM)
1432 cfa.offset += offset;
1433 if (cfa_store.reg == STACK_POINTER_REGNUM)
1434 cfa_store.offset += offset;
1436 else if (dest == hard_frame_pointer_rtx)
1439 /* Either setting the FP from an offset of the SP,
1440 or adjusting the FP */
1441 if (! frame_pointer_needed)
1444 if (GET_CODE (XEXP (src, 0)) == REG
1445 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1446 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1448 offset = INTVAL (XEXP (src, 1));
1449 if (GET_CODE (src) != MINUS)
1451 cfa.offset += offset;
1452 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1459 if (GET_CODE (src) == MINUS)
1463 if (GET_CODE (XEXP (src, 0)) == REG
1464 && REGNO (XEXP (src, 0)) == cfa.reg
1465 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1467 /* Setting a temporary CFA register that will be copied
1468 into the FP later on. */
1469 offset = - INTVAL (XEXP (src, 1));
1470 cfa.offset += offset;
1471 cfa.reg = REGNO (dest);
1472 /* Or used to save regs to the stack. */
1473 cfa_temp.reg = cfa.reg;
1474 cfa_temp.offset = cfa.offset;
1478 else if (GET_CODE (XEXP (src, 0)) == REG
1479 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1480 && XEXP (src, 1) == stack_pointer_rtx)
1482 /* Setting a scratch register that we will use instead
1483 of SP for saving registers to the stack. */
1484 if (cfa.reg != STACK_POINTER_REGNUM)
1486 cfa_store.reg = REGNO (dest);
1487 cfa_store.offset = cfa.offset - cfa_temp.offset;
1491 else if (GET_CODE (src) == LO_SUM
1492 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1494 cfa_temp.reg = REGNO (dest);
1495 cfa_temp.offset = INTVAL (XEXP (src, 1));
1504 cfa_temp.reg = REGNO (dest);
1505 cfa_temp.offset = INTVAL (src);
1510 if (GET_CODE (XEXP (src, 0)) != REG
1511 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1512 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1515 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1516 cfa_temp.reg = REGNO (dest);
1517 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1520 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1521 which will fill in all of the bits. */
1530 def_cfa_1 (label, &cfa);
1534 if (GET_CODE (src) != REG)
1537 /* Saving a register to the stack. Make sure dest is relative to the
1539 switch (GET_CODE (XEXP (dest, 0)))
1544 /* We can't handle variable size modifications. */
1545 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1547 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1549 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1550 || cfa_store.reg != STACK_POINTER_REGNUM)
1553 cfa_store.offset += offset;
1554 if (cfa.reg == STACK_POINTER_REGNUM)
1555 cfa.offset = cfa_store.offset;
1557 offset = -cfa_store.offset;
1563 offset = GET_MODE_SIZE (GET_MODE (dest));
1564 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1567 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1568 || cfa_store.reg != STACK_POINTER_REGNUM)
1571 cfa_store.offset += offset;
1572 if (cfa.reg == STACK_POINTER_REGNUM)
1573 cfa.offset = cfa_store.offset;
1575 offset = -cfa_store.offset;
1579 /* With an offset. */
1583 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1585 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1586 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1589 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1590 offset -= cfa_store.offset;
1591 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1592 offset -= cfa_temp.offset;
1598 /* Without an offset. */
1600 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1601 offset = -cfa_store.offset;
1602 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1603 offset = -cfa_temp.offset;
1610 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1612 offset = -cfa_temp.offset;
1613 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1620 if (REGNO (src) != STACK_POINTER_REGNUM
1621 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1622 && (unsigned) REGNO (src) == cfa.reg)
1624 /* We're storing the current CFA reg into the stack. */
1626 if (cfa.offset == 0)
1628 /* If the source register is exactly the CFA, assume
1629 we're saving SP like any other register; this happens
1631 def_cfa_1 (label, &cfa);
1632 queue_reg_save (label, stack_pointer_rtx, offset);
1637 /* Otherwise, we'll need to look in the stack to
1638 calculate the CFA. */
1639 rtx x = XEXP (dest, 0);
1641 if (GET_CODE (x) != REG)
1643 if (GET_CODE (x) != REG)
1646 cfa.reg = REGNO (x);
1647 cfa.base_offset = offset;
1649 def_cfa_1 (label, &cfa);
1654 def_cfa_1 (label, &cfa);
1655 queue_reg_save (label, src, offset);
1663 /* Record call frame debugging information for INSN, which either
1664 sets SP or FP (adjusting how we calculate the frame address) or saves a
1665 register to the stack. If INSN is NULL_RTX, initialize our state. */
1668 dwarf2out_frame_debug (rtx insn)
1673 if (insn == NULL_RTX)
1675 /* Flush any queued register saves. */
1676 flush_queued_reg_saves ();
1678 /* Set up state for generating call frame debug info. */
1680 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1683 cfa.reg = STACK_POINTER_REGNUM;
1686 cfa_temp.offset = 0;
1690 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1691 flush_queued_reg_saves ();
1693 if (! RTX_FRAME_RELATED_P (insn))
1695 if (!ACCUMULATE_OUTGOING_ARGS)
1696 dwarf2out_stack_adjust (insn);
1701 label = dwarf2out_cfi_label ();
1702 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1704 insn = XEXP (src, 0);
1706 insn = PATTERN (insn);
1708 dwarf2out_frame_debug_expr (insn, label);
1713 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1714 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1715 (enum dwarf_call_frame_info cfi);
1717 static enum dw_cfi_oprnd_type
1718 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1723 case DW_CFA_GNU_window_save:
1724 return dw_cfi_oprnd_unused;
1726 case DW_CFA_set_loc:
1727 case DW_CFA_advance_loc1:
1728 case DW_CFA_advance_loc2:
1729 case DW_CFA_advance_loc4:
1730 case DW_CFA_MIPS_advance_loc8:
1731 return dw_cfi_oprnd_addr;
1734 case DW_CFA_offset_extended:
1735 case DW_CFA_def_cfa:
1736 case DW_CFA_offset_extended_sf:
1737 case DW_CFA_def_cfa_sf:
1738 case DW_CFA_restore_extended:
1739 case DW_CFA_undefined:
1740 case DW_CFA_same_value:
1741 case DW_CFA_def_cfa_register:
1742 case DW_CFA_register:
1743 return dw_cfi_oprnd_reg_num;
1745 case DW_CFA_def_cfa_offset:
1746 case DW_CFA_GNU_args_size:
1747 case DW_CFA_def_cfa_offset_sf:
1748 return dw_cfi_oprnd_offset;
1750 case DW_CFA_def_cfa_expression:
1751 case DW_CFA_expression:
1752 return dw_cfi_oprnd_loc;
1759 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1760 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1761 (enum dwarf_call_frame_info cfi);
1763 static enum dw_cfi_oprnd_type
1764 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1768 case DW_CFA_def_cfa:
1769 case DW_CFA_def_cfa_sf:
1771 case DW_CFA_offset_extended_sf:
1772 case DW_CFA_offset_extended:
1773 return dw_cfi_oprnd_offset;
1775 case DW_CFA_register:
1776 return dw_cfi_oprnd_reg_num;
1779 return dw_cfi_oprnd_unused;
1783 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1785 /* Output a Call Frame Information opcode and its operand(s). */
1788 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1790 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1791 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1792 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1793 "DW_CFA_advance_loc 0x%lx",
1794 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1795 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1797 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1798 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1799 "DW_CFA_offset, column 0x%lx",
1800 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1801 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1803 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1804 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1805 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1806 "DW_CFA_restore, column 0x%lx",
1807 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1810 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1811 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1813 switch (cfi->dw_cfi_opc)
1815 case DW_CFA_set_loc:
1817 dw2_asm_output_encoded_addr_rtx (
1818 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1819 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1822 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1823 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1826 case DW_CFA_advance_loc1:
1827 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1828 fde->dw_fde_current_label, NULL);
1829 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1832 case DW_CFA_advance_loc2:
1833 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1834 fde->dw_fde_current_label, NULL);
1835 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1838 case DW_CFA_advance_loc4:
1839 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1840 fde->dw_fde_current_label, NULL);
1841 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1844 case DW_CFA_MIPS_advance_loc8:
1845 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1846 fde->dw_fde_current_label, NULL);
1847 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1850 case DW_CFA_offset_extended:
1851 case DW_CFA_def_cfa:
1852 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1854 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1857 case DW_CFA_offset_extended_sf:
1858 case DW_CFA_def_cfa_sf:
1859 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1861 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1864 case DW_CFA_restore_extended:
1865 case DW_CFA_undefined:
1866 case DW_CFA_same_value:
1867 case DW_CFA_def_cfa_register:
1868 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1872 case DW_CFA_register:
1873 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1875 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1879 case DW_CFA_def_cfa_offset:
1880 case DW_CFA_GNU_args_size:
1881 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1884 case DW_CFA_def_cfa_offset_sf:
1885 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1888 case DW_CFA_GNU_window_save:
1891 case DW_CFA_def_cfa_expression:
1892 case DW_CFA_expression:
1893 output_cfa_loc (cfi);
1896 case DW_CFA_GNU_negative_offset_extended:
1897 /* Obsoleted by DW_CFA_offset_extended_sf. */
1906 /* Output the call frame information used to used to record information
1907 that relates to calculating the frame pointer, and records the
1908 location of saved registers. */
1911 output_call_frame_info (int for_eh)
1916 char l1[20], l2[20], section_start_label[20];
1917 bool any_lsda_needed = false;
1918 char augmentation[6];
1919 int augmentation_size;
1920 int fde_encoding = DW_EH_PE_absptr;
1921 int per_encoding = DW_EH_PE_absptr;
1922 int lsda_encoding = DW_EH_PE_absptr;
1924 /* Don't emit a CIE if there won't be any FDEs. */
1925 if (fde_table_in_use == 0)
1928 /* If we don't have any functions we'll want to unwind out of, don't
1929 emit any EH unwind information. Note that if exceptions aren't
1930 enabled, we won't have collected nothrow information, and if we
1931 asked for asynchronous tables, we always want this info. */
1934 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
1936 for (i = 0; i < fde_table_in_use; i++)
1937 if (fde_table[i].uses_eh_lsda)
1938 any_eh_needed = any_lsda_needed = true;
1939 else if (! fde_table[i].nothrow
1940 && ! fde_table[i].all_throwers_are_sibcalls)
1941 any_eh_needed = true;
1943 if (! any_eh_needed)
1947 /* We're going to be generating comments, so turn on app. */
1952 (*targetm.asm_out.eh_frame_section) ();
1954 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1956 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1957 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1959 /* Output the CIE. */
1960 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1961 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1962 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1963 "Length of Common Information Entry");
1964 ASM_OUTPUT_LABEL (asm_out_file, l1);
1966 /* Now that the CIE pointer is PC-relative for EH,
1967 use 0 to identify the CIE. */
1968 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1969 (for_eh ? 0 : DW_CIE_ID),
1970 "CIE Identifier Tag");
1972 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1974 augmentation[0] = 0;
1975 augmentation_size = 0;
1981 z Indicates that a uleb128 is present to size the
1982 augmentation section.
1983 L Indicates the encoding (and thus presence) of
1984 an LSDA pointer in the FDE augmentation.
1985 R Indicates a non-default pointer encoding for
1987 P Indicates the presence of an encoding + language
1988 personality routine in the CIE augmentation. */
1990 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1991 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1992 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1994 p = augmentation + 1;
1995 if (eh_personality_libfunc)
1998 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2000 if (any_lsda_needed)
2003 augmentation_size += 1;
2005 if (fde_encoding != DW_EH_PE_absptr)
2008 augmentation_size += 1;
2010 if (p > augmentation + 1)
2012 augmentation[0] = 'z';
2016 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2017 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2019 int offset = ( 4 /* Length */
2021 + 1 /* CIE version */
2022 + strlen (augmentation) + 1 /* Augmentation */
2023 + size_of_uleb128 (1) /* Code alignment */
2024 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2026 + 1 /* Augmentation size */
2027 + 1 /* Personality encoding */ );
2028 int pad = -offset & (PTR_SIZE - 1);
2030 augmentation_size += pad;
2032 /* Augmentations should be small, so there's scarce need to
2033 iterate for a solution. Die if we exceed one uleb128 byte. */
2034 if (size_of_uleb128 (augmentation_size) != 1)
2039 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2040 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2041 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2042 "CIE Data Alignment Factor");
2043 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
2045 if (augmentation[0])
2047 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2048 if (eh_personality_libfunc)
2050 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2051 eh_data_format_name (per_encoding));
2052 dw2_asm_output_encoded_addr_rtx (per_encoding,
2053 eh_personality_libfunc, NULL);
2056 if (any_lsda_needed)
2057 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2058 eh_data_format_name (lsda_encoding));
2060 if (fde_encoding != DW_EH_PE_absptr)
2061 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2062 eh_data_format_name (fde_encoding));
2065 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2066 output_cfi (cfi, NULL, for_eh);
2068 /* Pad the CIE out to an address sized boundary. */
2069 ASM_OUTPUT_ALIGN (asm_out_file,
2070 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2071 ASM_OUTPUT_LABEL (asm_out_file, l2);
2073 /* Loop through all of the FDE's. */
2074 for (i = 0; i < fde_table_in_use; i++)
2076 fde = &fde_table[i];
2078 /* Don't emit EH unwind info for leaf functions that don't need it. */
2079 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2080 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2081 && !fde->uses_eh_lsda)
2084 (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2);
2085 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2086 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2087 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2089 ASM_OUTPUT_LABEL (asm_out_file, l1);
2092 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2094 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2099 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2100 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
2101 "FDE initial location");
2102 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2103 fde->dw_fde_end, fde->dw_fde_begin,
2104 "FDE address range");
2108 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2109 "FDE initial location");
2110 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2111 fde->dw_fde_end, fde->dw_fde_begin,
2112 "FDE address range");
2115 if (augmentation[0])
2117 if (any_lsda_needed)
2119 int size = size_of_encoded_value (lsda_encoding);
2121 if (lsda_encoding == DW_EH_PE_aligned)
2123 int offset = ( 4 /* Length */
2124 + 4 /* CIE offset */
2125 + 2 * size_of_encoded_value (fde_encoding)
2126 + 1 /* Augmentation size */ );
2127 int pad = -offset & (PTR_SIZE - 1);
2130 if (size_of_uleb128 (size) != 1)
2134 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2136 if (fde->uses_eh_lsda)
2138 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2139 fde->funcdef_number);
2140 dw2_asm_output_encoded_addr_rtx (
2141 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2142 "Language Specific Data Area");
2146 if (lsda_encoding == DW_EH_PE_aligned)
2147 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2149 (size_of_encoded_value (lsda_encoding), 0,
2150 "Language Specific Data Area (none)");
2154 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2157 /* Loop through the Call Frame Instructions associated with
2159 fde->dw_fde_current_label = fde->dw_fde_begin;
2160 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2161 output_cfi (cfi, fde, for_eh);
2163 /* Pad the FDE out to an address sized boundary. */
2164 ASM_OUTPUT_ALIGN (asm_out_file,
2165 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2166 ASM_OUTPUT_LABEL (asm_out_file, l2);
2169 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2170 dw2_asm_output_data (4, 0, "End of Table");
2171 #ifdef MIPS_DEBUGGING_INFO
2172 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2173 get a value of 0. Putting .align 0 after the label fixes it. */
2174 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2177 /* Turn off app to make assembly quicker. */
2182 /* Output a marker (i.e. a label) for the beginning of a function, before
2186 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2187 const char *file ATTRIBUTE_UNUSED)
2189 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2192 current_function_func_begin_label = 0;
2194 #ifdef IA64_UNWIND_INFO
2195 /* ??? current_function_func_begin_label is also used by except.c
2196 for call-site information. We must emit this label if it might
2198 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2199 && ! dwarf2out_do_frame ())
2202 if (! dwarf2out_do_frame ())
2206 function_section (current_function_decl);
2207 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2208 current_function_funcdef_no);
2209 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2210 current_function_funcdef_no);
2211 current_function_func_begin_label = get_identifier (label);
2213 #ifdef IA64_UNWIND_INFO
2214 /* We can elide the fde allocation if we're not emitting debug info. */
2215 if (! dwarf2out_do_frame ())
2219 /* Expand the fde table if necessary. */
2220 if (fde_table_in_use == fde_table_allocated)
2222 fde_table_allocated += FDE_TABLE_INCREMENT;
2223 fde_table = ggc_realloc (fde_table,
2224 fde_table_allocated * sizeof (dw_fde_node));
2225 memset (fde_table + fde_table_in_use, 0,
2226 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2229 /* Record the FDE associated with this function. */
2230 current_funcdef_fde = fde_table_in_use;
2232 /* Add the new FDE at the end of the fde_table. */
2233 fde = &fde_table[fde_table_in_use++];
2234 fde->dw_fde_begin = xstrdup (label);
2235 fde->dw_fde_current_label = NULL;
2236 fde->dw_fde_end = NULL;
2237 fde->dw_fde_cfi = NULL;
2238 fde->funcdef_number = current_function_funcdef_no;
2239 fde->nothrow = current_function_nothrow;
2240 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2241 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2243 args_size = old_args_size = 0;
2245 /* We only want to output line number information for the genuine dwarf2
2246 prologue case, not the eh frame case. */
2247 #ifdef DWARF2_DEBUGGING_INFO
2249 dwarf2out_source_line (line, file);
2253 /* Output a marker (i.e. a label) for the absolute end of the generated code
2254 for a function definition. This gets called *after* the epilogue code has
2258 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2259 const char *file ATTRIBUTE_UNUSED)
2262 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2264 /* Output a label to mark the endpoint of the code generated for this
2266 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2267 current_function_funcdef_no);
2268 ASM_OUTPUT_LABEL (asm_out_file, label);
2269 fde = &fde_table[fde_table_in_use - 1];
2270 fde->dw_fde_end = xstrdup (label);
2274 dwarf2out_frame_init (void)
2276 /* Allocate the initial hunk of the fde_table. */
2277 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2278 fde_table_allocated = FDE_TABLE_INCREMENT;
2279 fde_table_in_use = 0;
2281 /* Generate the CFA instructions common to all FDE's. Do it now for the
2282 sake of lookup_cfa. */
2284 #ifdef DWARF2_UNWIND_INFO
2285 /* On entry, the Canonical Frame Address is at SP. */
2286 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2287 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2292 dwarf2out_frame_finish (void)
2294 /* Output call frame information. */
2295 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2296 output_call_frame_info (0);
2298 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2299 output_call_frame_info (1);
2303 /* And now, the subset of the debugging information support code necessary
2304 for emitting location expressions. */
2306 /* We need some way to distinguish DW_OP_addr with a direct symbol
2307 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2308 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2311 typedef struct dw_val_struct *dw_val_ref;
2312 typedef struct die_struct *dw_die_ref;
2313 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2314 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2316 /* Each DIE may have a series of attribute/value pairs. Values
2317 can take on several forms. The forms that are used in this
2318 implementation are listed below. */
2323 dw_val_class_offset,
2325 dw_val_class_loc_list,
2326 dw_val_class_range_list,
2328 dw_val_class_unsigned_const,
2329 dw_val_class_long_long,
2332 dw_val_class_die_ref,
2333 dw_val_class_fde_ref,
2334 dw_val_class_lbl_id,
2335 dw_val_class_lbl_offset,
2339 /* Describe a double word constant value. */
2340 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2342 typedef struct dw_long_long_struct GTY(())
2349 /* Describe a floating point constant value. */
2351 typedef struct dw_fp_struct GTY(())
2353 long * GTY((length ("%h.length"))) array;
2358 /* The dw_val_node describes an attribute's value, as it is
2359 represented internally. */
2361 typedef struct dw_val_struct GTY(())
2363 enum dw_val_class val_class;
2364 union dw_val_struct_union
2366 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2367 long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset;
2368 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2369 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2370 long int GTY ((default (""))) val_int;
2371 long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2372 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2373 dw_float_const GTY ((tag ("dw_val_class_float"))) val_float;
2374 struct dw_val_die_union
2378 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2379 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2380 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2381 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2382 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2384 GTY ((desc ("%1.val_class"))) v;
2388 /* Locations in memory are described using a sequence of stack machine
2391 typedef struct dw_loc_descr_struct GTY(())
2393 dw_loc_descr_ref dw_loc_next;
2394 enum dwarf_location_atom dw_loc_opc;
2395 dw_val_node dw_loc_oprnd1;
2396 dw_val_node dw_loc_oprnd2;
2401 /* Location lists are ranges + location descriptions for that range,
2402 so you can track variables that are in different places over
2403 their entire life. */
2404 typedef struct dw_loc_list_struct GTY(())
2406 dw_loc_list_ref dw_loc_next;
2407 const char *begin; /* Label for begin address of range */
2408 const char *end; /* Label for end address of range */
2409 char *ll_symbol; /* Label for beginning of location list.
2410 Only on head of list */
2411 const char *section; /* Section this loclist is relative to */
2412 dw_loc_descr_ref expr;
2415 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2417 static const char *dwarf_stack_op_name (unsigned);
2418 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2419 unsigned long, unsigned long);
2420 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2421 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2422 static unsigned long size_of_locs (dw_loc_descr_ref);
2423 static void output_loc_operands (dw_loc_descr_ref);
2424 static void output_loc_sequence (dw_loc_descr_ref);
2426 /* Convert a DWARF stack opcode into its string name. */
2429 dwarf_stack_op_name (unsigned int op)
2434 case INTERNAL_DW_OP_tls_addr:
2435 return "DW_OP_addr";
2437 return "DW_OP_deref";
2439 return "DW_OP_const1u";
2441 return "DW_OP_const1s";
2443 return "DW_OP_const2u";
2445 return "DW_OP_const2s";
2447 return "DW_OP_const4u";
2449 return "DW_OP_const4s";
2451 return "DW_OP_const8u";
2453 return "DW_OP_const8s";
2455 return "DW_OP_constu";
2457 return "DW_OP_consts";
2461 return "DW_OP_drop";
2463 return "DW_OP_over";
2465 return "DW_OP_pick";
2467 return "DW_OP_swap";
2471 return "DW_OP_xderef";
2479 return "DW_OP_minus";
2491 return "DW_OP_plus";
2492 case DW_OP_plus_uconst:
2493 return "DW_OP_plus_uconst";
2499 return "DW_OP_shra";
2517 return "DW_OP_skip";
2519 return "DW_OP_lit0";
2521 return "DW_OP_lit1";
2523 return "DW_OP_lit2";
2525 return "DW_OP_lit3";
2527 return "DW_OP_lit4";
2529 return "DW_OP_lit5";
2531 return "DW_OP_lit6";
2533 return "DW_OP_lit7";
2535 return "DW_OP_lit8";
2537 return "DW_OP_lit9";
2539 return "DW_OP_lit10";
2541 return "DW_OP_lit11";
2543 return "DW_OP_lit12";
2545 return "DW_OP_lit13";
2547 return "DW_OP_lit14";
2549 return "DW_OP_lit15";
2551 return "DW_OP_lit16";
2553 return "DW_OP_lit17";
2555 return "DW_OP_lit18";
2557 return "DW_OP_lit19";
2559 return "DW_OP_lit20";
2561 return "DW_OP_lit21";
2563 return "DW_OP_lit22";
2565 return "DW_OP_lit23";
2567 return "DW_OP_lit24";
2569 return "DW_OP_lit25";
2571 return "DW_OP_lit26";
2573 return "DW_OP_lit27";
2575 return "DW_OP_lit28";
2577 return "DW_OP_lit29";
2579 return "DW_OP_lit30";
2581 return "DW_OP_lit31";
2583 return "DW_OP_reg0";
2585 return "DW_OP_reg1";
2587 return "DW_OP_reg2";
2589 return "DW_OP_reg3";
2591 return "DW_OP_reg4";
2593 return "DW_OP_reg5";
2595 return "DW_OP_reg6";
2597 return "DW_OP_reg7";
2599 return "DW_OP_reg8";
2601 return "DW_OP_reg9";
2603 return "DW_OP_reg10";
2605 return "DW_OP_reg11";
2607 return "DW_OP_reg12";
2609 return "DW_OP_reg13";
2611 return "DW_OP_reg14";
2613 return "DW_OP_reg15";
2615 return "DW_OP_reg16";
2617 return "DW_OP_reg17";
2619 return "DW_OP_reg18";
2621 return "DW_OP_reg19";
2623 return "DW_OP_reg20";
2625 return "DW_OP_reg21";
2627 return "DW_OP_reg22";
2629 return "DW_OP_reg23";
2631 return "DW_OP_reg24";
2633 return "DW_OP_reg25";
2635 return "DW_OP_reg26";
2637 return "DW_OP_reg27";
2639 return "DW_OP_reg28";
2641 return "DW_OP_reg29";
2643 return "DW_OP_reg30";
2645 return "DW_OP_reg31";
2647 return "DW_OP_breg0";
2649 return "DW_OP_breg1";
2651 return "DW_OP_breg2";
2653 return "DW_OP_breg3";
2655 return "DW_OP_breg4";
2657 return "DW_OP_breg5";
2659 return "DW_OP_breg6";
2661 return "DW_OP_breg7";
2663 return "DW_OP_breg8";
2665 return "DW_OP_breg9";
2667 return "DW_OP_breg10";
2669 return "DW_OP_breg11";
2671 return "DW_OP_breg12";
2673 return "DW_OP_breg13";
2675 return "DW_OP_breg14";
2677 return "DW_OP_breg15";
2679 return "DW_OP_breg16";
2681 return "DW_OP_breg17";
2683 return "DW_OP_breg18";
2685 return "DW_OP_breg19";
2687 return "DW_OP_breg20";
2689 return "DW_OP_breg21";
2691 return "DW_OP_breg22";
2693 return "DW_OP_breg23";
2695 return "DW_OP_breg24";
2697 return "DW_OP_breg25";
2699 return "DW_OP_breg26";
2701 return "DW_OP_breg27";
2703 return "DW_OP_breg28";
2705 return "DW_OP_breg29";
2707 return "DW_OP_breg30";
2709 return "DW_OP_breg31";
2711 return "DW_OP_regx";
2713 return "DW_OP_fbreg";
2715 return "DW_OP_bregx";
2717 return "DW_OP_piece";
2718 case DW_OP_deref_size:
2719 return "DW_OP_deref_size";
2720 case DW_OP_xderef_size:
2721 return "DW_OP_xderef_size";
2724 case DW_OP_push_object_address:
2725 return "DW_OP_push_object_address";
2727 return "DW_OP_call2";
2729 return "DW_OP_call4";
2730 case DW_OP_call_ref:
2731 return "DW_OP_call_ref";
2732 case DW_OP_GNU_push_tls_address:
2733 return "DW_OP_GNU_push_tls_address";
2735 return "OP_<unknown>";
2739 /* Return a pointer to a newly allocated location description. Location
2740 descriptions are simple expression terms that can be strung
2741 together to form more complicated location (address) descriptions. */
2743 static inline dw_loc_descr_ref
2744 new_loc_descr (enum dwarf_location_atom op, long unsigned int oprnd1,
2745 long unsigned int oprnd2)
2747 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2749 descr->dw_loc_opc = op;
2750 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2751 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2752 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2753 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2759 /* Add a location description term to a location description expression. */
2762 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
2764 dw_loc_descr_ref *d;
2766 /* Find the end of the chain. */
2767 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2773 /* Return the size of a location descriptor. */
2775 static unsigned long
2776 size_of_loc_descr (dw_loc_descr_ref loc)
2778 unsigned long size = 1;
2780 switch (loc->dw_loc_opc)
2783 case INTERNAL_DW_OP_tls_addr:
2784 size += DWARF2_ADDR_SIZE;
2803 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2806 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2811 case DW_OP_plus_uconst:
2812 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2850 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2853 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2856 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2859 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2860 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2863 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2865 case DW_OP_deref_size:
2866 case DW_OP_xderef_size:
2875 case DW_OP_call_ref:
2876 size += DWARF2_ADDR_SIZE;
2885 /* Return the size of a series of location descriptors. */
2887 static unsigned long
2888 size_of_locs (dw_loc_descr_ref loc)
2892 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2894 loc->dw_loc_addr = size;
2895 size += size_of_loc_descr (loc);
2901 /* Output location description stack opcode's operands (if any). */
2904 output_loc_operands (dw_loc_descr_ref loc)
2906 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2907 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2909 switch (loc->dw_loc_opc)
2911 #ifdef DWARF2_DEBUGGING_INFO
2913 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2917 dw2_asm_output_data (2, val1->v.val_int, NULL);
2921 dw2_asm_output_data (4, val1->v.val_int, NULL);
2925 if (HOST_BITS_PER_LONG < 64)
2927 dw2_asm_output_data (8, val1->v.val_int, NULL);
2934 if (val1->val_class == dw_val_class_loc)
2935 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2939 dw2_asm_output_data (2, offset, NULL);
2952 /* We currently don't make any attempt to make sure these are
2953 aligned properly like we do for the main unwind info, so
2954 don't support emitting things larger than a byte if we're
2955 only doing unwinding. */
2960 dw2_asm_output_data (1, val1->v.val_int, NULL);
2963 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2966 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2969 dw2_asm_output_data (1, val1->v.val_int, NULL);
2971 case DW_OP_plus_uconst:
2972 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3006 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3009 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3012 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3015 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3016 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3019 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3021 case DW_OP_deref_size:
3022 case DW_OP_xderef_size:
3023 dw2_asm_output_data (1, val1->v.val_int, NULL);
3026 case INTERNAL_DW_OP_tls_addr:
3027 #ifdef ASM_OUTPUT_DWARF_DTPREL
3028 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
3030 fputc ('\n', asm_out_file);
3037 /* Other codes have no operands. */
3042 /* Output a sequence of location operations. */
3045 output_loc_sequence (dw_loc_descr_ref loc)
3047 for (; loc != NULL; loc = loc->dw_loc_next)
3049 /* Output the opcode. */
3050 dw2_asm_output_data (1, loc->dw_loc_opc,
3051 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3053 /* Output the operand(s) (if any). */
3054 output_loc_operands (loc);
3058 /* This routine will generate the correct assembly data for a location
3059 description based on a cfi entry with a complex address. */
3062 output_cfa_loc (dw_cfi_ref cfi)
3064 dw_loc_descr_ref loc;
3067 /* Output the size of the block. */
3068 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3069 size = size_of_locs (loc);
3070 dw2_asm_output_data_uleb128 (size, NULL);
3072 /* Now output the operations themselves. */
3073 output_loc_sequence (loc);
3076 /* This function builds a dwarf location descriptor sequence from
3077 a dw_cfa_location. */
3079 static struct dw_loc_descr_struct *
3080 build_cfa_loc (dw_cfa_location *cfa)
3082 struct dw_loc_descr_struct *head, *tmp;
3084 if (cfa->indirect == 0)
3087 if (cfa->base_offset)
3090 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3092 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3094 else if (cfa->reg <= 31)
3095 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3097 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3099 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3100 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3101 add_loc_descr (&head, tmp);
3102 if (cfa->offset != 0)
3104 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3105 add_loc_descr (&head, tmp);
3111 /* This function fills in aa dw_cfa_location structure from a dwarf location
3112 descriptor sequence. */
3115 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3117 struct dw_loc_descr_struct *ptr;
3119 cfa->base_offset = 0;
3123 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3125 enum dwarf_location_atom op = ptr->dw_loc_opc;
3161 cfa->reg = op - DW_OP_reg0;
3164 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3198 cfa->reg = op - DW_OP_breg0;
3199 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3202 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3203 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3208 case DW_OP_plus_uconst:
3209 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3212 internal_error ("DW_LOC_OP %s not implemented\n",
3213 dwarf_stack_op_name (ptr->dw_loc_opc));
3217 #endif /* .debug_frame support */
3219 /* And now, the support for symbolic debugging information. */
3220 #ifdef DWARF2_DEBUGGING_INFO
3222 /* .debug_str support. */
3223 static int output_indirect_string (void **, void *);
3225 static void dwarf2out_init (const char *);
3226 static void dwarf2out_finish (const char *);
3227 static void dwarf2out_define (unsigned int, const char *);
3228 static void dwarf2out_undef (unsigned int, const char *);
3229 static void dwarf2out_start_source_file (unsigned, const char *);
3230 static void dwarf2out_end_source_file (unsigned);
3231 static void dwarf2out_begin_block (unsigned, unsigned);
3232 static void dwarf2out_end_block (unsigned, unsigned);
3233 static bool dwarf2out_ignore_block (tree);
3234 static void dwarf2out_global_decl (tree);
3235 static void dwarf2out_abstract_function (tree);
3237 /* The debug hooks structure. */
3239 const struct gcc_debug_hooks dwarf2_debug_hooks =
3245 dwarf2out_start_source_file,
3246 dwarf2out_end_source_file,
3247 dwarf2out_begin_block,
3248 dwarf2out_end_block,
3249 dwarf2out_ignore_block,
3250 dwarf2out_source_line,
3251 dwarf2out_begin_prologue,
3252 debug_nothing_int_charstar, /* end_prologue */
3253 dwarf2out_end_epilogue,
3254 debug_nothing_tree, /* begin_function */
3255 debug_nothing_int, /* end_function */
3256 dwarf2out_decl, /* function_decl */
3257 dwarf2out_global_decl,
3258 debug_nothing_tree, /* deferred_inline_function */
3259 /* The DWARF 2 backend tries to reduce debugging bloat by not
3260 emitting the abstract description of inline functions until
3261 something tries to reference them. */
3262 dwarf2out_abstract_function, /* outlining_inline_function */
3263 debug_nothing_rtx, /* label */
3264 debug_nothing_int /* handle_pch */
3268 /* NOTE: In the comments in this file, many references are made to
3269 "Debugging Information Entries". This term is abbreviated as `DIE'
3270 throughout the remainder of this file. */
3272 /* An internal representation of the DWARF output is built, and then
3273 walked to generate the DWARF debugging info. The walk of the internal
3274 representation is done after the entire program has been compiled.
3275 The types below are used to describe the internal representation. */
3277 /* Various DIE's use offsets relative to the beginning of the
3278 .debug_info section to refer to each other. */
3280 typedef long int dw_offset;
3282 /* Define typedefs here to avoid circular dependencies. */
3284 typedef struct dw_attr_struct *dw_attr_ref;
3285 typedef struct dw_line_info_struct *dw_line_info_ref;
3286 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3287 typedef struct pubname_struct *pubname_ref;
3288 typedef struct dw_ranges_struct *dw_ranges_ref;
3290 /* Each entry in the line_info_table maintains the file and
3291 line number associated with the label generated for that
3292 entry. The label gives the PC value associated with
3293 the line number entry. */
3295 typedef struct dw_line_info_struct GTY(())
3297 unsigned long dw_file_num;
3298 unsigned long dw_line_num;
3302 /* Line information for functions in separate sections; each one gets its
3304 typedef struct dw_separate_line_info_struct GTY(())
3306 unsigned long dw_file_num;
3307 unsigned long dw_line_num;
3308 unsigned long function;
3310 dw_separate_line_info_entry;
3312 /* Each DIE attribute has a field specifying the attribute kind,
3313 a link to the next attribute in the chain, and an attribute value.
3314 Attributes are typically linked below the DIE they modify. */
3316 typedef struct dw_attr_struct GTY(())
3318 enum dwarf_attribute dw_attr;
3319 dw_attr_ref dw_attr_next;
3320 dw_val_node dw_attr_val;
3324 /* The Debugging Information Entry (DIE) structure */
3326 typedef struct die_struct GTY(())
3328 enum dwarf_tag die_tag;
3330 dw_attr_ref die_attr;
3331 dw_die_ref die_parent;
3332 dw_die_ref die_child;
3334 dw_offset die_offset;
3335 unsigned long die_abbrev;
3340 /* The pubname structure */
3342 typedef struct pubname_struct GTY(())
3349 struct dw_ranges_struct GTY(())
3354 /* The limbo die list structure. */
3355 typedef struct limbo_die_struct GTY(())
3359 struct limbo_die_struct *next;
3363 /* How to start an assembler comment. */
3364 #ifndef ASM_COMMENT_START
3365 #define ASM_COMMENT_START ";#"
3368 /* Define a macro which returns nonzero for a TYPE_DECL which was
3369 implicitly generated for a tagged type.
3371 Note that unlike the gcc front end (which generates a NULL named
3372 TYPE_DECL node for each complete tagged type, each array type, and
3373 each function type node created) the g++ front end generates a
3374 _named_ TYPE_DECL node for each tagged type node created.
3375 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3376 generate a DW_TAG_typedef DIE for them. */
3378 #define TYPE_DECL_IS_STUB(decl) \
3379 (DECL_NAME (decl) == NULL_TREE \
3380 || (DECL_ARTIFICIAL (decl) \
3381 && is_tagged_type (TREE_TYPE (decl)) \
3382 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3383 /* This is necessary for stub decls that \
3384 appear in nested inline functions. */ \
3385 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3386 && (decl_ultimate_origin (decl) \
3387 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3389 /* Information concerning the compilation unit's programming
3390 language, and compiler version. */
3392 /* Fixed size portion of the DWARF compilation unit header. */
3393 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3394 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3396 /* Fixed size portion of public names info. */
3397 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3399 /* Fixed size portion of the address range info. */
3400 #define DWARF_ARANGES_HEADER_SIZE \
3401 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3402 DWARF2_ADDR_SIZE * 2) \
3403 - DWARF_INITIAL_LENGTH_SIZE)
3405 /* Size of padding portion in the address range info. It must be
3406 aligned to twice the pointer size. */
3407 #define DWARF_ARANGES_PAD_SIZE \
3408 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3409 DWARF2_ADDR_SIZE * 2) \
3410 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3412 /* Use assembler line directives if available. */
3413 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3414 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3415 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3417 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3421 /* Minimum line offset in a special line info. opcode.
3422 This value was chosen to give a reasonable range of values. */
3423 #define DWARF_LINE_BASE -10
3425 /* First special line opcode - leave room for the standard opcodes. */
3426 #define DWARF_LINE_OPCODE_BASE 10
3428 /* Range of line offsets in a special line info. opcode. */
3429 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3431 /* Flag that indicates the initial value of the is_stmt_start flag.
3432 In the present implementation, we do not mark any lines as
3433 the beginning of a source statement, because that information
3434 is not made available by the GCC front-end. */
3435 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3437 #ifdef DWARF2_DEBUGGING_INFO
3438 /* This location is used by calc_die_sizes() to keep track
3439 the offset of each DIE within the .debug_info section. */
3440 static unsigned long next_die_offset;
3443 /* Record the root of the DIE's built for the current compilation unit. */
3444 static GTY(()) dw_die_ref comp_unit_die;
3446 /* A list of DIEs with a NULL parent waiting to be relocated. */
3447 static GTY(()) limbo_die_node *limbo_die_list;
3449 /* Filenames referenced by this compilation unit. */
3450 static GTY(()) varray_type file_table;
3451 static GTY(()) varray_type file_table_emitted;
3452 static GTY(()) size_t file_table_last_lookup_index;
3454 /* A pointer to the base of a table of references to DIE's that describe
3455 declarations. The table is indexed by DECL_UID() which is a unique
3456 number identifying each decl. */
3457 static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table;
3459 /* Number of elements currently allocated for the decl_die_table. */
3460 static GTY(()) unsigned decl_die_table_allocated;
3462 /* Number of elements in decl_die_table currently in use. */
3463 static GTY(()) unsigned decl_die_table_in_use;
3465 /* Size (in elements) of increments by which we may expand the
3467 #define DECL_DIE_TABLE_INCREMENT 256
3469 /* A pointer to the base of a list of references to DIE's that
3470 are uniquely identified by their tag, presence/absence of
3471 children DIE's, and list of attribute/value pairs. */
3472 static GTY((length ("abbrev_die_table_allocated")))
3473 dw_die_ref *abbrev_die_table;
3475 /* Number of elements currently allocated for abbrev_die_table. */
3476 static GTY(()) unsigned abbrev_die_table_allocated;
3478 /* Number of elements in type_die_table currently in use. */
3479 static GTY(()) unsigned abbrev_die_table_in_use;
3481 /* Size (in elements) of increments by which we may expand the
3482 abbrev_die_table. */
3483 #define ABBREV_DIE_TABLE_INCREMENT 256
3485 /* A pointer to the base of a table that contains line information
3486 for each source code line in .text in the compilation unit. */
3487 static GTY((length ("line_info_table_allocated")))
3488 dw_line_info_ref line_info_table;
3490 /* Number of elements currently allocated for line_info_table. */
3491 static GTY(()) unsigned line_info_table_allocated;
3493 /* Number of elements in line_info_table currently in use. */
3494 static GTY(()) unsigned line_info_table_in_use;
3496 /* A pointer to the base of a table that contains line information
3497 for each source code line outside of .text in the compilation unit. */
3498 static GTY ((length ("separate_line_info_table_allocated")))
3499 dw_separate_line_info_ref separate_line_info_table;
3501 /* Number of elements currently allocated for separate_line_info_table. */
3502 static GTY(()) unsigned separate_line_info_table_allocated;
3504 /* Number of elements in separate_line_info_table currently in use. */
3505 static GTY(()) unsigned separate_line_info_table_in_use;
3507 /* Size (in elements) of increments by which we may expand the
3509 #define LINE_INFO_TABLE_INCREMENT 1024
3511 /* A pointer to the base of a table that contains a list of publicly
3512 accessible names. */
3513 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3515 /* Number of elements currently allocated for pubname_table. */
3516 static GTY(()) unsigned pubname_table_allocated;
3518 /* Number of elements in pubname_table currently in use. */
3519 static GTY(()) unsigned pubname_table_in_use;
3521 /* Size (in elements) of increments by which we may expand the
3523 #define PUBNAME_TABLE_INCREMENT 64
3525 /* Array of dies for which we should generate .debug_arange info. */
3526 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3528 /* Number of elements currently allocated for arange_table. */
3529 static GTY(()) unsigned arange_table_allocated;
3531 /* Number of elements in arange_table currently in use. */
3532 static GTY(()) unsigned arange_table_in_use;
3534 /* Size (in elements) of increments by which we may expand the
3536 #define ARANGE_TABLE_INCREMENT 64
3538 /* Array of dies for which we should generate .debug_ranges info. */
3539 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3541 /* Number of elements currently allocated for ranges_table. */
3542 static GTY(()) unsigned ranges_table_allocated;
3544 /* Number of elements in ranges_table currently in use. */
3545 static GTY(()) unsigned ranges_table_in_use;
3547 /* Size (in elements) of increments by which we may expand the
3549 #define RANGES_TABLE_INCREMENT 64
3551 /* Whether we have location lists that need outputting */
3552 static GTY(()) unsigned have_location_lists;
3554 #ifdef DWARF2_DEBUGGING_INFO
3555 /* Record whether the function being analyzed contains inlined functions. */
3556 static int current_function_has_inlines;
3558 #if 0 && defined (MIPS_DEBUGGING_INFO)
3559 static int comp_unit_has_inlines;
3562 /* Number of file tables emitted in maybe_emit_file(). */
3563 static GTY(()) int emitcount = 0;
3565 /* Number of internal labels generated by gen_internal_sym(). */
3566 static GTY(()) int label_num;
3568 #ifdef DWARF2_DEBUGGING_INFO
3570 /* Forward declarations for functions defined in this file. */
3572 static int is_pseudo_reg (rtx);
3573 static tree type_main_variant (tree);
3574 static int is_tagged_type (tree);
3575 static const char *dwarf_tag_name (unsigned);
3576 static const char *dwarf_attr_name (unsigned);
3577 static const char *dwarf_form_name (unsigned);
3579 static const char *dwarf_type_encoding_name (unsigned);
3581 static tree decl_ultimate_origin (tree);
3582 static tree block_ultimate_origin (tree);
3583 static tree decl_class_context (tree);
3584 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3585 static inline enum dw_val_class AT_class (dw_attr_ref);
3586 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3587 static inline unsigned AT_flag (dw_attr_ref);
3588 static void add_AT_int (dw_die_ref, enum dwarf_attribute, long);
3589 static inline long int AT_int (dw_attr_ref);
3590 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned long);
3591 static inline unsigned long AT_unsigned (dw_attr_ref);
3592 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3594 static void add_AT_float (dw_die_ref, enum dwarf_attribute, unsigned, long *);
3595 static hashval_t debug_str_do_hash (const void *);
3596 static int debug_str_eq (const void *, const void *);
3597 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3598 static inline const char *AT_string (dw_attr_ref);
3599 static int AT_string_form (dw_attr_ref);
3600 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3601 static inline dw_die_ref AT_ref (dw_attr_ref);
3602 static inline int AT_ref_external (dw_attr_ref);
3603 static inline void set_AT_ref_external (dw_attr_ref, int);
3604 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3605 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3606 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3607 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3609 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3610 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3611 static inline rtx AT_addr (dw_attr_ref);
3612 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3613 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3614 static void add_AT_offset (dw_die_ref, enum dwarf_attribute, unsigned long);
3615 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3617 static inline const char *AT_lbl (dw_attr_ref);
3618 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3619 static const char *get_AT_low_pc (dw_die_ref);
3620 static const char *get_AT_hi_pc (dw_die_ref);
3621 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3622 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3623 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3624 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3625 static bool is_c_family (void);
3626 static bool is_cxx (void);
3627 static bool is_java (void);
3628 static bool is_fortran (void);
3629 static bool is_ada (void);
3630 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3631 static inline void free_die (dw_die_ref);
3632 static void remove_children (dw_die_ref);
3633 static void add_child_die (dw_die_ref, dw_die_ref);
3634 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3635 static dw_die_ref lookup_type_die (tree);
3636 static void equate_type_number_to_die (tree, dw_die_ref);
3637 static dw_die_ref lookup_decl_die (tree);
3638 static void equate_decl_number_to_die (tree, dw_die_ref);
3639 static void print_spaces (FILE *);
3640 static void print_die (dw_die_ref, FILE *);
3641 static void print_dwarf_line_table (FILE *);
3642 static void reverse_die_lists (dw_die_ref);
3643 static void reverse_all_dies (dw_die_ref);
3644 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3645 static dw_die_ref pop_compile_unit (dw_die_ref);
3646 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3647 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3648 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3649 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3650 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3651 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3652 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3653 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3654 static void compute_section_prefix (dw_die_ref);
3655 static int is_type_die (dw_die_ref);
3656 static int is_comdat_die (dw_die_ref);
3657 static int is_symbol_die (dw_die_ref);
3658 static void assign_symbol_names (dw_die_ref);
3659 static void break_out_includes (dw_die_ref);
3660 static hashval_t htab_cu_hash (const void *);
3661 static int htab_cu_eq (const void *, const void *);
3662 static void htab_cu_del (void *);
3663 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3664 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3665 static void add_sibling_attributes (dw_die_ref);
3666 static void build_abbrev_table (dw_die_ref);
3667 static void output_location_lists (dw_die_ref);
3668 static int constant_size (long unsigned);
3669 static unsigned long size_of_die (dw_die_ref);
3670 static void calc_die_sizes (dw_die_ref);
3671 static void mark_dies (dw_die_ref);
3672 static void unmark_dies (dw_die_ref);
3673 static void unmark_all_dies (dw_die_ref);
3674 static unsigned long size_of_pubnames (void);
3675 static unsigned long size_of_aranges (void);
3676 static enum dwarf_form value_format (dw_attr_ref);
3677 static void output_value_format (dw_attr_ref);
3678 static void output_abbrev_section (void);
3679 static void output_die_symbol (dw_die_ref);
3680 static void output_die (dw_die_ref);
3681 static void output_compilation_unit_header (void);
3682 static void output_comp_unit (dw_die_ref, int);
3683 static const char *dwarf2_name (tree, int);
3684 static void add_pubname (tree, dw_die_ref);
3685 static void output_pubnames (void);
3686 static void add_arange (tree, dw_die_ref);
3687 static void output_aranges (void);
3688 static unsigned int add_ranges (tree);
3689 static void output_ranges (void);
3690 static void output_line_info (void);
3691 static void output_file_names (void);
3692 static dw_die_ref base_type_die (tree);
3693 static tree root_type (tree);
3694 static int is_base_type (tree);
3695 static bool is_ada_subrange_type (tree);
3696 static dw_die_ref subrange_type_die (tree);
3697 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3698 static int type_is_enum (tree);
3699 static unsigned int reg_number (rtx);
3700 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3701 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3702 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3703 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3704 static dw_loc_descr_ref based_loc_descr (unsigned, long);
3705 static int is_based_loc (rtx);
3706 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
3707 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
3708 static dw_loc_descr_ref loc_descriptor (rtx);
3709 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
3710 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3711 static tree field_type (tree);
3712 static unsigned int simple_type_align_in_bits (tree);
3713 static unsigned int simple_decl_align_in_bits (tree);
3714 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3715 static HOST_WIDE_INT field_byte_offset (tree);
3716 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3718 static void add_data_member_location_attribute (dw_die_ref, tree);
3719 static void add_const_value_attribute (dw_die_ref, rtx);
3720 static rtx rtl_for_decl_location (tree);
3721 static void add_location_or_const_value_attribute (dw_die_ref, tree);
3722 static void tree_add_const_value_attribute (dw_die_ref, tree);
3723 static void add_name_attribute (dw_die_ref, const char *);
3724 static void add_comp_dir_attribute (dw_die_ref);
3725 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
3726 static void add_subscript_info (dw_die_ref, tree);
3727 static void add_byte_size_attribute (dw_die_ref, tree);
3728 static void add_bit_offset_attribute (dw_die_ref, tree);
3729 static void add_bit_size_attribute (dw_die_ref, tree);
3730 static void add_prototyped_attribute (dw_die_ref, tree);
3731 static void add_abstract_origin_attribute (dw_die_ref, tree);
3732 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3733 static void add_src_coords_attributes (dw_die_ref, tree);
3734 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
3735 static void push_decl_scope (tree);
3736 static void pop_decl_scope (void);
3737 static dw_die_ref scope_die_for (tree, dw_die_ref);
3738 static inline int local_scope_p (dw_die_ref);
3739 static inline int class_scope_p (dw_die_ref);
3740 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
3741 static const char *type_tag (tree);
3742 static tree member_declared_type (tree);
3744 static const char *decl_start_label (tree);
3746 static void gen_array_type_die (tree, dw_die_ref);
3747 static void gen_set_type_die (tree, dw_die_ref);
3749 static void gen_entry_point_die (tree, dw_die_ref);
3751 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
3752 static void gen_inlined_structure_type_die (tree, dw_die_ref);
3753 static void gen_inlined_union_type_die (tree, dw_die_ref);
3754 static void gen_enumeration_type_die (tree, dw_die_ref);
3755 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
3756 static void gen_unspecified_parameters_die (tree, dw_die_ref);
3757 static void gen_formal_types_die (tree, dw_die_ref);
3758 static void gen_subprogram_die (tree, dw_die_ref);
3759 static void gen_variable_die (tree, dw_die_ref);
3760 static void gen_label_die (tree, dw_die_ref);
3761 static void gen_lexical_block_die (tree, dw_die_ref, int);
3762 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
3763 static void gen_field_die (tree, dw_die_ref);
3764 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3765 static dw_die_ref gen_compile_unit_die (const char *);
3766 static void gen_string_type_die (tree, dw_die_ref);
3767 static void gen_inheritance_die (tree, tree, dw_die_ref);
3768 static void gen_member_die (tree, dw_die_ref);
3769 static void gen_struct_or_union_type_die (tree, dw_die_ref);
3770 static void gen_subroutine_type_die (tree, dw_die_ref);
3771 static void gen_typedef_die (tree, dw_die_ref);
3772 static void gen_type_die (tree, dw_die_ref);
3773 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
3774 static void gen_block_die (tree, dw_die_ref, int);
3775 static void decls_for_scope (tree, dw_die_ref, int);
3776 static int is_redundant_typedef (tree);
3777 static void gen_decl_die (tree, dw_die_ref);
3778 static unsigned lookup_filename (const char *);
3779 static void init_file_table (void);
3780 static void retry_incomplete_types (void);
3781 static void gen_type_die_for_member (tree, tree, dw_die_ref);
3782 static void splice_child_die (dw_die_ref, dw_die_ref);
3783 static int file_info_cmp (const void *, const void *);
3784 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
3785 const char *, const char *, unsigned);
3786 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
3787 const char *, const char *,
3789 static void output_loc_list (dw_loc_list_ref);
3790 static char *gen_internal_sym (const char *);
3792 static void prune_unmark_dies (dw_die_ref);
3793 static void prune_unused_types_mark (dw_die_ref, int);
3794 static void prune_unused_types_walk (dw_die_ref);
3795 static void prune_unused_types_walk_attribs (dw_die_ref);
3796 static void prune_unused_types_prune (dw_die_ref);
3797 static void prune_unused_types (void);
3798 static int maybe_emit_file (int);
3800 /* Section names used to hold DWARF debugging information. */
3801 #ifndef DEBUG_INFO_SECTION
3802 #define DEBUG_INFO_SECTION ".debug_info"
3804 #ifndef DEBUG_ABBREV_SECTION
3805 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3807 #ifndef DEBUG_ARANGES_SECTION
3808 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3810 #ifndef DEBUG_MACINFO_SECTION
3811 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3813 #ifndef DEBUG_LINE_SECTION
3814 #define DEBUG_LINE_SECTION ".debug_line"
3816 #ifndef DEBUG_LOC_SECTION
3817 #define DEBUG_LOC_SECTION ".debug_loc"
3819 #ifndef DEBUG_PUBNAMES_SECTION
3820 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3822 #ifndef DEBUG_STR_SECTION
3823 #define DEBUG_STR_SECTION ".debug_str"
3825 #ifndef DEBUG_RANGES_SECTION
3826 #define DEBUG_RANGES_SECTION ".debug_ranges"
3829 /* Standard ELF section names for compiled code and data. */
3830 #ifndef TEXT_SECTION_NAME
3831 #define TEXT_SECTION_NAME ".text"
3834 /* Section flags for .debug_str section. */
3835 #define DEBUG_STR_SECTION_FLAGS \
3836 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
3837 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3840 /* Labels we insert at beginning sections we can reference instead of
3841 the section names themselves. */
3843 #ifndef TEXT_SECTION_LABEL
3844 #define TEXT_SECTION_LABEL "Ltext"
3846 #ifndef DEBUG_LINE_SECTION_LABEL
3847 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3849 #ifndef DEBUG_INFO_SECTION_LABEL
3850 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3852 #ifndef DEBUG_ABBREV_SECTION_LABEL
3853 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3855 #ifndef DEBUG_LOC_SECTION_LABEL
3856 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3858 #ifndef DEBUG_RANGES_SECTION_LABEL
3859 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3861 #ifndef DEBUG_MACINFO_SECTION_LABEL
3862 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3865 /* Definitions of defaults for formats and names of various special
3866 (artificial) labels which may be generated within this file (when the -g
3867 options is used and DWARF_DEBUGGING_INFO is in effect.
3868 If necessary, these may be overridden from within the tm.h file, but
3869 typically, overriding these defaults is unnecessary. */
3871 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3872 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3873 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3874 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3875 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3876 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3877 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3878 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3880 #ifndef TEXT_END_LABEL
3881 #define TEXT_END_LABEL "Letext"
3883 #ifndef BLOCK_BEGIN_LABEL
3884 #define BLOCK_BEGIN_LABEL "LBB"
3886 #ifndef BLOCK_END_LABEL
3887 #define BLOCK_END_LABEL "LBE"
3889 #ifndef LINE_CODE_LABEL
3890 #define LINE_CODE_LABEL "LM"
3892 #ifndef SEPARATE_LINE_CODE_LABEL
3893 #define SEPARATE_LINE_CODE_LABEL "LSM"
3896 /* We allow a language front-end to designate a function that is to be
3897 called to "demangle" any name before it it put into a DIE. */
3899 static const char *(*demangle_name_func) (const char *);
3902 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
3904 demangle_name_func = func;
3907 /* Test if rtl node points to a pseudo register. */
3910 is_pseudo_reg (rtx rtl)
3912 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3913 || (GET_CODE (rtl) == SUBREG
3914 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3917 /* Return a reference to a type, with its const and volatile qualifiers
3921 type_main_variant (tree type)
3923 type = TYPE_MAIN_VARIANT (type);
3925 /* ??? There really should be only one main variant among any group of
3926 variants of a given type (and all of the MAIN_VARIANT values for all
3927 members of the group should point to that one type) but sometimes the C
3928 front-end messes this up for array types, so we work around that bug
3930 if (TREE_CODE (type) == ARRAY_TYPE)
3931 while (type != TYPE_MAIN_VARIANT (type))
3932 type = TYPE_MAIN_VARIANT (type);
3937 /* Return nonzero if the given type node represents a tagged type. */
3940 is_tagged_type (tree type)
3942 enum tree_code code = TREE_CODE (type);
3944 return (code == RECORD_TYPE || code == UNION_TYPE
3945 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3948 /* Convert a DIE tag into its string name. */
3951 dwarf_tag_name (unsigned int tag)
3955 case DW_TAG_padding:
3956 return "DW_TAG_padding";
3957 case DW_TAG_array_type:
3958 return "DW_TAG_array_type";
3959 case DW_TAG_class_type:
3960 return "DW_TAG_class_type";
3961 case DW_TAG_entry_point:
3962 return "DW_TAG_entry_point";
3963 case DW_TAG_enumeration_type:
3964 return "DW_TAG_enumeration_type";
3965 case DW_TAG_formal_parameter:
3966 return "DW_TAG_formal_parameter";
3967 case DW_TAG_imported_declaration:
3968 return "DW_TAG_imported_declaration";
3970 return "DW_TAG_label";
3971 case DW_TAG_lexical_block:
3972 return "DW_TAG_lexical_block";
3974 return "DW_TAG_member";
3975 case DW_TAG_pointer_type:
3976 return "DW_TAG_pointer_type";
3977 case DW_TAG_reference_type:
3978 return "DW_TAG_reference_type";
3979 case DW_TAG_compile_unit:
3980 return "DW_TAG_compile_unit";
3981 case DW_TAG_string_type:
3982 return "DW_TAG_string_type";
3983 case DW_TAG_structure_type:
3984 return "DW_TAG_structure_type";
3985 case DW_TAG_subroutine_type:
3986 return "DW_TAG_subroutine_type";
3987 case DW_TAG_typedef:
3988 return "DW_TAG_typedef";
3989 case DW_TAG_union_type:
3990 return "DW_TAG_union_type";
3991 case DW_TAG_unspecified_parameters:
3992 return "DW_TAG_unspecified_parameters";
3993 case DW_TAG_variant:
3994 return "DW_TAG_variant";
3995 case DW_TAG_common_block:
3996 return "DW_TAG_common_block";
3997 case DW_TAG_common_inclusion:
3998 return "DW_TAG_common_inclusion";
3999 case DW_TAG_inheritance:
4000 return "DW_TAG_inheritance";
4001 case DW_TAG_inlined_subroutine:
4002 return "DW_TAG_inlined_subroutine";
4004 return "DW_TAG_module";
4005 case DW_TAG_ptr_to_member_type:
4006 return "DW_TAG_ptr_to_member_type";
4007 case DW_TAG_set_type:
4008 return "DW_TAG_set_type";
4009 case DW_TAG_subrange_type:
4010 return "DW_TAG_subrange_type";
4011 case DW_TAG_with_stmt:
4012 return "DW_TAG_with_stmt";
4013 case DW_TAG_access_declaration:
4014 return "DW_TAG_access_declaration";
4015 case DW_TAG_base_type:
4016 return "DW_TAG_base_type";
4017 case DW_TAG_catch_block:
4018 return "DW_TAG_catch_block";
4019 case DW_TAG_const_type:
4020 return "DW_TAG_const_type";
4021 case DW_TAG_constant:
4022 return "DW_TAG_constant";
4023 case DW_TAG_enumerator:
4024 return "DW_TAG_enumerator";
4025 case DW_TAG_file_type:
4026 return "DW_TAG_file_type";
4028 return "DW_TAG_friend";
4029 case DW_TAG_namelist:
4030 return "DW_TAG_namelist";
4031 case DW_TAG_namelist_item:
4032 return "DW_TAG_namelist_item";
4033 case DW_TAG_packed_type:
4034 return "DW_TAG_packed_type";
4035 case DW_TAG_subprogram:
4036 return "DW_TAG_subprogram";
4037 case DW_TAG_template_type_param:
4038 return "DW_TAG_template_type_param";
4039 case DW_TAG_template_value_param:
4040 return "DW_TAG_template_value_param";
4041 case DW_TAG_thrown_type:
4042 return "DW_TAG_thrown_type";
4043 case DW_TAG_try_block:
4044 return "DW_TAG_try_block";
4045 case DW_TAG_variant_part:
4046 return "DW_TAG_variant_part";
4047 case DW_TAG_variable:
4048 return "DW_TAG_variable";
4049 case DW_TAG_volatile_type:
4050 return "DW_TAG_volatile_type";
4051 case DW_TAG_MIPS_loop:
4052 return "DW_TAG_MIPS_loop";
4053 case DW_TAG_format_label:
4054 return "DW_TAG_format_label";
4055 case DW_TAG_function_template:
4056 return "DW_TAG_function_template";
4057 case DW_TAG_class_template:
4058 return "DW_TAG_class_template";
4059 case DW_TAG_GNU_BINCL:
4060 return "DW_TAG_GNU_BINCL";
4061 case DW_TAG_GNU_EINCL:
4062 return "DW_TAG_GNU_EINCL";
4064 return "DW_TAG_<unknown>";
4068 /* Convert a DWARF attribute code into its string name. */
4071 dwarf_attr_name (unsigned int attr)
4076 return "DW_AT_sibling";
4077 case DW_AT_location:
4078 return "DW_AT_location";
4080 return "DW_AT_name";
4081 case DW_AT_ordering:
4082 return "DW_AT_ordering";
4083 case DW_AT_subscr_data:
4084 return "DW_AT_subscr_data";
4085 case DW_AT_byte_size:
4086 return "DW_AT_byte_size";
4087 case DW_AT_bit_offset:
4088 return "DW_AT_bit_offset";
4089 case DW_AT_bit_size:
4090 return "DW_AT_bit_size";
4091 case DW_AT_element_list:
4092 return "DW_AT_element_list";
4093 case DW_AT_stmt_list:
4094 return "DW_AT_stmt_list";
4096 return "DW_AT_low_pc";
4098 return "DW_AT_high_pc";
4099 case DW_AT_language:
4100 return "DW_AT_language";
4102 return "DW_AT_member";
4104 return "DW_AT_discr";
4105 case DW_AT_discr_value:
4106 return "DW_AT_discr_value";
4107 case DW_AT_visibility:
4108 return "DW_AT_visibility";
4110 return "DW_AT_import";
4111 case DW_AT_string_length:
4112 return "DW_AT_string_length";
4113 case DW_AT_common_reference:
4114 return "DW_AT_common_reference";
4115 case DW_AT_comp_dir:
4116 return "DW_AT_comp_dir";
4117 case DW_AT_const_value:
4118 return "DW_AT_const_value";
4119 case DW_AT_containing_type:
4120 return "DW_AT_containing_type";
4121 case DW_AT_default_value:
4122 return "DW_AT_default_value";
4124 return "DW_AT_inline";
4125 case DW_AT_is_optional:
4126 return "DW_AT_is_optional";
4127 case DW_AT_lower_bound:
4128 return "DW_AT_lower_bound";
4129 case DW_AT_producer:
4130 return "DW_AT_producer";
4131 case DW_AT_prototyped:
4132 return "DW_AT_prototyped";
4133 case DW_AT_return_addr:
4134 return "DW_AT_return_addr";
4135 case DW_AT_start_scope:
4136 return "DW_AT_start_scope";
4137 case DW_AT_stride_size:
4138 return "DW_AT_stride_size";
4139 case DW_AT_upper_bound:
4140 return "DW_AT_upper_bound";
4141 case DW_AT_abstract_origin:
4142 return "DW_AT_abstract_origin";
4143 case DW_AT_accessibility:
4144 return "DW_AT_accessibility";
4145 case DW_AT_address_class:
4146 return "DW_AT_address_class";
4147 case DW_AT_artificial:
4148 return "DW_AT_artificial";
4149 case DW_AT_base_types:
4150 return "DW_AT_base_types";
4151 case DW_AT_calling_convention:
4152 return "DW_AT_calling_convention";
4154 return "DW_AT_count";
4155 case DW_AT_data_member_location:
4156 return "DW_AT_data_member_location";
4157 case DW_AT_decl_column:
4158 return "DW_AT_decl_column";
4159 case DW_AT_decl_file:
4160 return "DW_AT_decl_file";
4161 case DW_AT_decl_line:
4162 return "DW_AT_decl_line";
4163 case DW_AT_declaration:
4164 return "DW_AT_declaration";
4165 case DW_AT_discr_list:
4166 return "DW_AT_discr_list";
4167 case DW_AT_encoding:
4168 return "DW_AT_encoding";
4169 case DW_AT_external:
4170 return "DW_AT_external";
4171 case DW_AT_frame_base:
4172 return "DW_AT_frame_base";
4174 return "DW_AT_friend";
4175 case DW_AT_identifier_case:
4176 return "DW_AT_identifier_case";
4177 case DW_AT_macro_info:
4178 return "DW_AT_macro_info";
4179 case DW_AT_namelist_items:
4180 return "DW_AT_namelist_items";
4181 case DW_AT_priority:
4182 return "DW_AT_priority";
4184 return "DW_AT_segment";
4185 case DW_AT_specification:
4186 return "DW_AT_specification";
4187 case DW_AT_static_link:
4188 return "DW_AT_static_link";
4190 return "DW_AT_type";
4191 case DW_AT_use_location:
4192 return "DW_AT_use_location";
4193 case DW_AT_variable_parameter:
4194 return "DW_AT_variable_parameter";
4195 case DW_AT_virtuality:
4196 return "DW_AT_virtuality";
4197 case DW_AT_vtable_elem_location:
4198 return "DW_AT_vtable_elem_location";
4200 case DW_AT_allocated:
4201 return "DW_AT_allocated";
4202 case DW_AT_associated:
4203 return "DW_AT_associated";
4204 case DW_AT_data_location:
4205 return "DW_AT_data_location";
4207 return "DW_AT_stride";
4208 case DW_AT_entry_pc:
4209 return "DW_AT_entry_pc";
4210 case DW_AT_use_UTF8:
4211 return "DW_AT_use_UTF8";
4212 case DW_AT_extension:
4213 return "DW_AT_extension";
4215 return "DW_AT_ranges";
4216 case DW_AT_trampoline:
4217 return "DW_AT_trampoline";
4218 case DW_AT_call_column:
4219 return "DW_AT_call_column";
4220 case DW_AT_call_file:
4221 return "DW_AT_call_file";
4222 case DW_AT_call_line:
4223 return "DW_AT_call_line";
4225 case DW_AT_MIPS_fde:
4226 return "DW_AT_MIPS_fde";
4227 case DW_AT_MIPS_loop_begin:
4228 return "DW_AT_MIPS_loop_begin";
4229 case DW_AT_MIPS_tail_loop_begin:
4230 return "DW_AT_MIPS_tail_loop_begin";
4231 case DW_AT_MIPS_epilog_begin:
4232 return "DW_AT_MIPS_epilog_begin";
4233 case DW_AT_MIPS_loop_unroll_factor:
4234 return "DW_AT_MIPS_loop_unroll_factor";
4235 case DW_AT_MIPS_software_pipeline_depth:
4236 return "DW_AT_MIPS_software_pipeline_depth";
4237 case DW_AT_MIPS_linkage_name:
4238 return "DW_AT_MIPS_linkage_name";
4239 case DW_AT_MIPS_stride:
4240 return "DW_AT_MIPS_stride";
4241 case DW_AT_MIPS_abstract_name:
4242 return "DW_AT_MIPS_abstract_name";
4243 case DW_AT_MIPS_clone_origin:
4244 return "DW_AT_MIPS_clone_origin";
4245 case DW_AT_MIPS_has_inlines:
4246 return "DW_AT_MIPS_has_inlines";
4248 case DW_AT_sf_names:
4249 return "DW_AT_sf_names";
4250 case DW_AT_src_info:
4251 return "DW_AT_src_info";
4252 case DW_AT_mac_info:
4253 return "DW_AT_mac_info";
4254 case DW_AT_src_coords:
4255 return "DW_AT_src_coords";
4256 case DW_AT_body_begin:
4257 return "DW_AT_body_begin";
4258 case DW_AT_body_end:
4259 return "DW_AT_body_end";
4260 case DW_AT_GNU_vector:
4261 return "DW_AT_GNU_vector";
4263 case DW_AT_VMS_rtnbeg_pd_address:
4264 return "DW_AT_VMS_rtnbeg_pd_address";
4267 return "DW_AT_<unknown>";
4271 /* Convert a DWARF value form code into its string name. */
4274 dwarf_form_name (unsigned int form)
4279 return "DW_FORM_addr";
4280 case DW_FORM_block2:
4281 return "DW_FORM_block2";
4282 case DW_FORM_block4:
4283 return "DW_FORM_block4";
4285 return "DW_FORM_data2";
4287 return "DW_FORM_data4";
4289 return "DW_FORM_data8";
4290 case DW_FORM_string:
4291 return "DW_FORM_string";
4293 return "DW_FORM_block";
4294 case DW_FORM_block1:
4295 return "DW_FORM_block1";
4297 return "DW_FORM_data1";
4299 return "DW_FORM_flag";
4301 return "DW_FORM_sdata";
4303 return "DW_FORM_strp";
4305 return "DW_FORM_udata";
4306 case DW_FORM_ref_addr:
4307 return "DW_FORM_ref_addr";
4309 return "DW_FORM_ref1";
4311 return "DW_FORM_ref2";
4313 return "DW_FORM_ref4";
4315 return "DW_FORM_ref8";
4316 case DW_FORM_ref_udata:
4317 return "DW_FORM_ref_udata";
4318 case DW_FORM_indirect:
4319 return "DW_FORM_indirect";
4321 return "DW_FORM_<unknown>";
4325 /* Convert a DWARF type code into its string name. */
4329 dwarf_type_encoding_name (unsigned enc)
4333 case DW_ATE_address:
4334 return "DW_ATE_address";
4335 case DW_ATE_boolean:
4336 return "DW_ATE_boolean";
4337 case DW_ATE_complex_float:
4338 return "DW_ATE_complex_float";
4340 return "DW_ATE_float";
4342 return "DW_ATE_signed";
4343 case DW_ATE_signed_char:
4344 return "DW_ATE_signed_char";
4345 case DW_ATE_unsigned:
4346 return "DW_ATE_unsigned";
4347 case DW_ATE_unsigned_char:
4348 return "DW_ATE_unsigned_char";
4350 return "DW_ATE_<unknown>";
4355 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4356 instance of an inlined instance of a decl which is local to an inline
4357 function, so we have to trace all of the way back through the origin chain
4358 to find out what sort of node actually served as the original seed for the
4362 decl_ultimate_origin (tree decl)
4364 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4365 nodes in the function to point to themselves; ignore that if
4366 we're trying to output the abstract instance of this function. */
4367 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4370 #ifdef ENABLE_CHECKING
4371 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4372 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4373 most distant ancestor, this should never happen. */
4377 return DECL_ABSTRACT_ORIGIN (decl);
4380 /* Determine the "ultimate origin" of a block. The block may be an inlined
4381 instance of an inlined instance of a block which is local to an inline
4382 function, so we have to trace all of the way back through the origin chain
4383 to find out what sort of node actually served as the original seed for the
4387 block_ultimate_origin (tree block)
4389 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4391 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4392 nodes in the function to point to themselves; ignore that if
4393 we're trying to output the abstract instance of this function. */
4394 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4397 if (immediate_origin == NULL_TREE)
4402 tree lookahead = immediate_origin;
4406 ret_val = lookahead;
4407 lookahead = (TREE_CODE (ret_val) == BLOCK
4408 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4410 while (lookahead != NULL && lookahead != ret_val);
4416 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4417 of a virtual function may refer to a base class, so we check the 'this'
4421 decl_class_context (tree decl)
4423 tree context = NULL_TREE;
4425 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4426 context = DECL_CONTEXT (decl);
4428 context = TYPE_MAIN_VARIANT
4429 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4431 if (context && !TYPE_P (context))
4432 context = NULL_TREE;
4437 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4438 addition order, and correct that in reverse_all_dies. */
4441 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4443 if (die != NULL && attr != NULL)
4445 attr->dw_attr_next = die->die_attr;
4446 die->die_attr = attr;
4450 static inline enum dw_val_class
4451 AT_class (dw_attr_ref a)
4453 return a->dw_attr_val.val_class;
4456 /* Add a flag value attribute to a DIE. */
4459 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4461 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4463 attr->dw_attr_next = NULL;
4464 attr->dw_attr = attr_kind;
4465 attr->dw_attr_val.val_class = dw_val_class_flag;
4466 attr->dw_attr_val.v.val_flag = flag;
4467 add_dwarf_attr (die, attr);
4470 static inline unsigned
4471 AT_flag (dw_attr_ref a)
4473 if (a && AT_class (a) == dw_val_class_flag)
4474 return a->dw_attr_val.v.val_flag;
4479 /* Add a signed integer attribute value to a DIE. */
4482 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, long int int_val)
4484 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4486 attr->dw_attr_next = NULL;
4487 attr->dw_attr = attr_kind;
4488 attr->dw_attr_val.val_class = dw_val_class_const;
4489 attr->dw_attr_val.v.val_int = int_val;
4490 add_dwarf_attr (die, attr);
4493 static inline long int
4494 AT_int (dw_attr_ref a)
4496 if (a && AT_class (a) == dw_val_class_const)
4497 return a->dw_attr_val.v.val_int;
4502 /* Add an unsigned integer attribute value to a DIE. */
4505 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4506 long unsigned int unsigned_val)
4508 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4510 attr->dw_attr_next = NULL;
4511 attr->dw_attr = attr_kind;
4512 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4513 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4514 add_dwarf_attr (die, attr);
4517 static inline unsigned long
4518 AT_unsigned (dw_attr_ref a)
4520 if (a && AT_class (a) == dw_val_class_unsigned_const)
4521 return a->dw_attr_val.v.val_unsigned;
4526 /* Add an unsigned double integer attribute value to a DIE. */
4529 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4530 long unsigned int val_hi, long unsigned int val_low)
4532 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4534 attr->dw_attr_next = NULL;
4535 attr->dw_attr = attr_kind;
4536 attr->dw_attr_val.val_class = dw_val_class_long_long;
4537 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4538 attr->dw_attr_val.v.val_long_long.low = val_low;
4539 add_dwarf_attr (die, attr);
4542 /* Add a floating point attribute value to a DIE and return it. */
4545 add_AT_float (dw_die_ref die, enum dwarf_attribute attr_kind,
4546 unsigned int length, long int *array)
4548 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4550 attr->dw_attr_next = NULL;
4551 attr->dw_attr = attr_kind;
4552 attr->dw_attr_val.val_class = dw_val_class_float;
4553 attr->dw_attr_val.v.val_float.length = length;
4554 attr->dw_attr_val.v.val_float.array = array;
4555 add_dwarf_attr (die, attr);
4558 /* Hash and equality functions for debug_str_hash. */
4561 debug_str_do_hash (const void *x)
4563 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4567 debug_str_eq (const void *x1, const void *x2)
4569 return strcmp ((((const struct indirect_string_node *)x1)->str),
4570 (const char *)x2) == 0;
4573 /* Add a string attribute value to a DIE. */
4576 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4578 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4579 struct indirect_string_node *node;
4582 if (! debug_str_hash)
4583 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4584 debug_str_eq, NULL);
4586 slot = htab_find_slot_with_hash (debug_str_hash, str,
4587 htab_hash_string (str), INSERT);
4589 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4590 node = (struct indirect_string_node *) *slot;
4591 node->str = ggc_strdup (str);
4594 attr->dw_attr_next = NULL;
4595 attr->dw_attr = attr_kind;
4596 attr->dw_attr_val.val_class = dw_val_class_str;
4597 attr->dw_attr_val.v.val_str = node;
4598 add_dwarf_attr (die, attr);
4601 static inline const char *
4602 AT_string (dw_attr_ref a)
4604 if (a && AT_class (a) == dw_val_class_str)
4605 return a->dw_attr_val.v.val_str->str;
4610 /* Find out whether a string should be output inline in DIE
4611 or out-of-line in .debug_str section. */
4614 AT_string_form (dw_attr_ref a)
4616 if (a && AT_class (a) == dw_val_class_str)
4618 struct indirect_string_node *node;
4622 node = a->dw_attr_val.v.val_str;
4626 len = strlen (node->str) + 1;
4628 /* If the string is shorter or equal to the size of the reference, it is
4629 always better to put it inline. */
4630 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4631 return node->form = DW_FORM_string;
4633 /* If we cannot expect the linker to merge strings in .debug_str
4634 section, only put it into .debug_str if it is worth even in this
4636 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4637 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4638 return node->form = DW_FORM_string;
4640 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4641 ++dw2_string_counter;
4642 node->label = xstrdup (label);
4644 return node->form = DW_FORM_strp;
4650 /* Add a DIE reference attribute value to a DIE. */
4653 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4655 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4657 attr->dw_attr_next = NULL;
4658 attr->dw_attr = attr_kind;
4659 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4660 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4661 attr->dw_attr_val.v.val_die_ref.external = 0;
4662 add_dwarf_attr (die, attr);
4665 static inline dw_die_ref
4666 AT_ref (dw_attr_ref a)
4668 if (a && AT_class (a) == dw_val_class_die_ref)
4669 return a->dw_attr_val.v.val_die_ref.die;
4675 AT_ref_external (dw_attr_ref a)
4677 if (a && AT_class (a) == dw_val_class_die_ref)
4678 return a->dw_attr_val.v.val_die_ref.external;
4684 set_AT_ref_external (dw_attr_ref a, int i)
4686 if (a && AT_class (a) == dw_val_class_die_ref)
4687 a->dw_attr_val.v.val_die_ref.external = i;
4692 /* Add an FDE reference attribute value to a DIE. */
4695 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4697 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4699 attr->dw_attr_next = NULL;
4700 attr->dw_attr = attr_kind;
4701 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4702 attr->dw_attr_val.v.val_fde_index = targ_fde;
4703 add_dwarf_attr (die, attr);
4706 /* Add a location description attribute value to a DIE. */
4709 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4711 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4713 attr->dw_attr_next = NULL;
4714 attr->dw_attr = attr_kind;
4715 attr->dw_attr_val.val_class = dw_val_class_loc;
4716 attr->dw_attr_val.v.val_loc = loc;
4717 add_dwarf_attr (die, attr);
4720 static inline dw_loc_descr_ref
4721 AT_loc (dw_attr_ref a)
4723 if (a && AT_class (a) == dw_val_class_loc)
4724 return a->dw_attr_val.v.val_loc;
4730 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4732 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4734 attr->dw_attr_next = NULL;
4735 attr->dw_attr = attr_kind;
4736 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4737 attr->dw_attr_val.v.val_loc_list = loc_list;
4738 add_dwarf_attr (die, attr);
4739 have_location_lists = 1;
4742 static inline dw_loc_list_ref
4743 AT_loc_list (dw_attr_ref a)
4745 if (a && AT_class (a) == dw_val_class_loc_list)
4746 return a->dw_attr_val.v.val_loc_list;
4751 /* Add an address constant attribute value to a DIE. */
4754 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
4756 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4758 attr->dw_attr_next = NULL;
4759 attr->dw_attr = attr_kind;
4760 attr->dw_attr_val.val_class = dw_val_class_addr;
4761 attr->dw_attr_val.v.val_addr = addr;
4762 add_dwarf_attr (die, attr);
4766 AT_addr (dw_attr_ref a)
4768 if (a && AT_class (a) == dw_val_class_addr)
4769 return a->dw_attr_val.v.val_addr;
4774 /* Add a label identifier attribute value to a DIE. */
4777 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
4779 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4781 attr->dw_attr_next = NULL;
4782 attr->dw_attr = attr_kind;
4783 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4784 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4785 add_dwarf_attr (die, attr);
4788 /* Add a section offset attribute value to a DIE. */
4791 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
4793 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4795 attr->dw_attr_next = NULL;
4796 attr->dw_attr = attr_kind;
4797 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4798 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4799 add_dwarf_attr (die, attr);
4802 /* Add an offset attribute value to a DIE. */
4805 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind, long unsigned int offset)
4807 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4809 attr->dw_attr_next = NULL;
4810 attr->dw_attr = attr_kind;
4811 attr->dw_attr_val.val_class = dw_val_class_offset;
4812 attr->dw_attr_val.v.val_offset = offset;
4813 add_dwarf_attr (die, attr);
4816 /* Add an range_list attribute value to a DIE. */
4819 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
4820 long unsigned int offset)
4822 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4824 attr->dw_attr_next = NULL;
4825 attr->dw_attr = attr_kind;
4826 attr->dw_attr_val.val_class = dw_val_class_range_list;
4827 attr->dw_attr_val.v.val_offset = offset;
4828 add_dwarf_attr (die, attr);
4831 static inline const char *
4832 AT_lbl (dw_attr_ref a)
4834 if (a && (AT_class (a) == dw_val_class_lbl_id
4835 || AT_class (a) == dw_val_class_lbl_offset))
4836 return a->dw_attr_val.v.val_lbl_id;
4841 /* Get the attribute of type attr_kind. */
4843 static inline dw_attr_ref
4844 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4847 dw_die_ref spec = NULL;
4851 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4852 if (a->dw_attr == attr_kind)
4854 else if (a->dw_attr == DW_AT_specification
4855 || a->dw_attr == DW_AT_abstract_origin)
4859 return get_AT (spec, attr_kind);
4865 /* Return the "low pc" attribute value, typically associated with a subprogram
4866 DIE. Return null if the "low pc" attribute is either not present, or if it
4867 cannot be represented as an assembler label identifier. */
4869 static inline const char *
4870 get_AT_low_pc (dw_die_ref die)
4872 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4874 return a ? AT_lbl (a) : NULL;
4877 /* Return the "high pc" attribute value, typically associated with a subprogram
4878 DIE. Return null if the "high pc" attribute is either not present, or if it
4879 cannot be represented as an assembler label identifier. */
4881 static inline const char *
4882 get_AT_hi_pc (dw_die_ref die)
4884 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4886 return a ? AT_lbl (a) : NULL;
4889 /* Return the value of the string attribute designated by ATTR_KIND, or
4890 NULL if it is not present. */
4892 static inline const char *
4893 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
4895 dw_attr_ref a = get_AT (die, attr_kind);
4897 return a ? AT_string (a) : NULL;
4900 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4901 if it is not present. */
4904 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
4906 dw_attr_ref a = get_AT (die, attr_kind);
4908 return a ? AT_flag (a) : 0;
4911 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4912 if it is not present. */
4914 static inline unsigned
4915 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
4917 dw_attr_ref a = get_AT (die, attr_kind);
4919 return a ? AT_unsigned (a) : 0;
4922 static inline dw_die_ref
4923 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
4925 dw_attr_ref a = get_AT (die, attr_kind);
4927 return a ? AT_ref (a) : NULL;
4930 /* Return TRUE if the language is C or C++. */
4935 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4937 return (lang == DW_LANG_C || lang == DW_LANG_C89
4938 || lang == DW_LANG_C_plus_plus);
4941 /* Return TRUE if the language is C++. */
4946 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4947 == DW_LANG_C_plus_plus);
4950 /* Return TRUE if the language is Fortran. */
4955 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4957 return lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90;
4960 /* Return TRUE if the language is Java. */
4965 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4967 return lang == DW_LANG_Java;
4970 /* Return TRUE if the language is Ada. */
4975 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4977 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
4980 /* Free up the memory used by A. */
4982 static inline void free_AT (dw_attr_ref);
4984 free_AT (dw_attr_ref a)
4986 if (AT_class (a) == dw_val_class_str)
4987 if (a->dw_attr_val.v.val_str->refcount)
4988 a->dw_attr_val.v.val_str->refcount--;
4991 /* Remove the specified attribute if present. */
4994 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
4997 dw_attr_ref removed = NULL;
5001 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
5002 if ((*p)->dw_attr == attr_kind)
5005 *p = (*p)->dw_attr_next;
5014 /* Free up the memory used by DIE. */
5017 free_die (dw_die_ref die)
5019 remove_children (die);
5022 /* Discard the children of this DIE. */
5025 remove_children (dw_die_ref die)
5027 dw_die_ref child_die = die->die_child;
5029 die->die_child = NULL;
5031 while (child_die != NULL)
5033 dw_die_ref tmp_die = child_die;
5036 child_die = child_die->die_sib;
5038 for (a = tmp_die->die_attr; a != NULL;)
5040 dw_attr_ref tmp_a = a;
5042 a = a->dw_attr_next;
5050 /* Add a child DIE below its parent. We build the lists up in reverse
5051 addition order, and correct that in reverse_all_dies. */
5054 add_child_die (dw_die_ref die, dw_die_ref child_die)
5056 if (die != NULL && child_die != NULL)
5058 if (die == child_die)
5061 child_die->die_parent = die;
5062 child_die->die_sib = die->die_child;
5063 die->die_child = child_die;
5067 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5068 is the specification, to the front of PARENT's list of children. */
5071 splice_child_die (dw_die_ref parent, dw_die_ref child)
5075 /* We want the declaration DIE from inside the class, not the
5076 specification DIE at toplevel. */
5077 if (child->die_parent != parent)
5079 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5085 if (child->die_parent != parent
5086 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5089 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5092 *p = child->die_sib;
5096 child->die_parent = parent;
5097 child->die_sib = parent->die_child;
5098 parent->die_child = child;
5101 /* Return a pointer to a newly created DIE node. */
5103 static inline dw_die_ref
5104 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5106 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5108 die->die_tag = tag_value;
5110 if (parent_die != NULL)
5111 add_child_die (parent_die, die);
5114 limbo_die_node *limbo_node;
5116 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5117 limbo_node->die = die;
5118 limbo_node->created_for = t;
5119 limbo_node->next = limbo_die_list;
5120 limbo_die_list = limbo_node;
5126 /* Return the DIE associated with the given type specifier. */
5128 static inline dw_die_ref
5129 lookup_type_die (tree type)
5131 return TYPE_SYMTAB_DIE (type);
5134 /* Equate a DIE to a given type specifier. */
5137 equate_type_number_to_die (tree type, dw_die_ref type_die)
5139 TYPE_SYMTAB_DIE (type) = type_die;
5142 /* Return the DIE associated with a given declaration. */
5144 static inline dw_die_ref
5145 lookup_decl_die (tree decl)
5147 unsigned decl_id = DECL_UID (decl);
5149 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5152 /* Equate a DIE to a particular declaration. */
5155 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5157 unsigned int decl_id = DECL_UID (decl);
5158 unsigned int num_allocated;
5160 if (decl_id >= decl_die_table_allocated)
5163 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5164 / DECL_DIE_TABLE_INCREMENT)
5165 * DECL_DIE_TABLE_INCREMENT;
5167 decl_die_table = ggc_realloc (decl_die_table,
5168 sizeof (dw_die_ref) * num_allocated);
5170 memset (&decl_die_table[decl_die_table_allocated], 0,
5171 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5172 decl_die_table_allocated = num_allocated;
5175 if (decl_id >= decl_die_table_in_use)
5176 decl_die_table_in_use = (decl_id + 1);
5178 decl_die_table[decl_id] = decl_die;
5181 /* Keep track of the number of spaces used to indent the
5182 output of the debugging routines that print the structure of
5183 the DIE internal representation. */
5184 static int print_indent;
5186 /* Indent the line the number of spaces given by print_indent. */
5189 print_spaces (FILE *outfile)
5191 fprintf (outfile, "%*s", print_indent, "");
5194 /* Print the information associated with a given DIE, and its children.
5195 This routine is a debugging aid only. */
5198 print_die (dw_die_ref die, FILE *outfile)
5203 print_spaces (outfile);
5204 fprintf (outfile, "DIE %4lu: %s\n",
5205 die->die_offset, dwarf_tag_name (die->die_tag));
5206 print_spaces (outfile);
5207 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5208 fprintf (outfile, " offset: %lu\n", die->die_offset);
5210 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5212 print_spaces (outfile);
5213 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5215 switch (AT_class (a))
5217 case dw_val_class_addr:
5218 fprintf (outfile, "address");
5220 case dw_val_class_offset:
5221 fprintf (outfile, "offset");
5223 case dw_val_class_loc:
5224 fprintf (outfile, "location descriptor");
5226 case dw_val_class_loc_list:
5227 fprintf (outfile, "location list -> label:%s",
5228 AT_loc_list (a)->ll_symbol);
5230 case dw_val_class_range_list:
5231 fprintf (outfile, "range list");
5233 case dw_val_class_const:
5234 fprintf (outfile, "%ld", AT_int (a));
5236 case dw_val_class_unsigned_const:
5237 fprintf (outfile, "%lu", AT_unsigned (a));
5239 case dw_val_class_long_long:
5240 fprintf (outfile, "constant (%lu,%lu)",
5241 a->dw_attr_val.v.val_long_long.hi,
5242 a->dw_attr_val.v.val_long_long.low);
5244 case dw_val_class_float:
5245 fprintf (outfile, "floating-point constant");
5247 case dw_val_class_flag:
5248 fprintf (outfile, "%u", AT_flag (a));
5250 case dw_val_class_die_ref:
5251 if (AT_ref (a) != NULL)
5253 if (AT_ref (a)->die_symbol)
5254 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5256 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5259 fprintf (outfile, "die -> <null>");
5261 case dw_val_class_lbl_id:
5262 case dw_val_class_lbl_offset:
5263 fprintf (outfile, "label: %s", AT_lbl (a));
5265 case dw_val_class_str:
5266 if (AT_string (a) != NULL)
5267 fprintf (outfile, "\"%s\"", AT_string (a));
5269 fprintf (outfile, "<null>");
5275 fprintf (outfile, "\n");
5278 if (die->die_child != NULL)
5281 for (c = die->die_child; c != NULL; c = c->die_sib)
5282 print_die (c, outfile);
5286 if (print_indent == 0)
5287 fprintf (outfile, "\n");
5290 /* Print the contents of the source code line number correspondence table.
5291 This routine is a debugging aid only. */
5294 print_dwarf_line_table (FILE *outfile)
5297 dw_line_info_ref line_info;
5299 fprintf (outfile, "\n\nDWARF source line information\n");
5300 for (i = 1; i < line_info_table_in_use; i++)
5302 line_info = &line_info_table[i];
5303 fprintf (outfile, "%5d: ", i);
5304 fprintf (outfile, "%-20s",
5305 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5306 fprintf (outfile, "%6ld", line_info->dw_line_num);
5307 fprintf (outfile, "\n");
5310 fprintf (outfile, "\n\n");
5313 /* Print the information collected for a given DIE. */
5316 debug_dwarf_die (dw_die_ref die)
5318 print_die (die, stderr);
5321 /* Print all DWARF information collected for the compilation unit.
5322 This routine is a debugging aid only. */
5328 print_die (comp_unit_die, stderr);
5329 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5330 print_dwarf_line_table (stderr);
5333 /* We build up the lists of children and attributes by pushing new ones
5334 onto the beginning of the list. Reverse the lists for DIE so that
5335 they are in order of addition. */
5338 reverse_die_lists (dw_die_ref die)
5340 dw_die_ref c, cp, cn;
5341 dw_attr_ref a, ap, an;
5343 for (a = die->die_attr, ap = 0; a; a = an)
5345 an = a->dw_attr_next;
5346 a->dw_attr_next = ap;
5352 for (c = die->die_child, cp = 0; c; c = cn)
5359 die->die_child = cp;
5362 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5363 reverse all dies in add_sibling_attributes, which runs through all the dies,
5364 it would reverse all the dies. Now, however, since we don't call
5365 reverse_die_lists in add_sibling_attributes, we need a routine to
5366 recursively reverse all the dies. This is that routine. */
5369 reverse_all_dies (dw_die_ref die)
5373 reverse_die_lists (die);
5375 for (c = die->die_child; c; c = c->die_sib)
5376 reverse_all_dies (c);
5379 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5380 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5381 DIE that marks the start of the DIEs for this include file. */
5384 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5386 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5387 dw_die_ref new_unit = gen_compile_unit_die (filename);
5389 new_unit->die_sib = old_unit;
5393 /* Close an include-file CU and reopen the enclosing one. */
5396 pop_compile_unit (dw_die_ref old_unit)
5398 dw_die_ref new_unit = old_unit->die_sib;
5400 old_unit->die_sib = NULL;
5404 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5405 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5407 /* Calculate the checksum of a location expression. */
5410 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5412 CHECKSUM (loc->dw_loc_opc);
5413 CHECKSUM (loc->dw_loc_oprnd1);
5414 CHECKSUM (loc->dw_loc_oprnd2);
5417 /* Calculate the checksum of an attribute. */
5420 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5422 dw_loc_descr_ref loc;
5425 CHECKSUM (at->dw_attr);
5427 /* We don't care about differences in file numbering. */
5428 if (at->dw_attr == DW_AT_decl_file
5429 /* Or that this was compiled with a different compiler snapshot; if
5430 the output is the same, that's what matters. */
5431 || at->dw_attr == DW_AT_producer)
5434 switch (AT_class (at))
5436 case dw_val_class_const:
5437 CHECKSUM (at->dw_attr_val.v.val_int);
5439 case dw_val_class_unsigned_const:
5440 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5442 case dw_val_class_long_long:
5443 CHECKSUM (at->dw_attr_val.v.val_long_long);
5445 case dw_val_class_float:
5446 CHECKSUM (at->dw_attr_val.v.val_float);
5448 case dw_val_class_flag:
5449 CHECKSUM (at->dw_attr_val.v.val_flag);
5451 case dw_val_class_str:
5452 CHECKSUM_STRING (AT_string (at));
5455 case dw_val_class_addr:
5457 switch (GET_CODE (r))
5460 CHECKSUM_STRING (XSTR (r, 0));
5468 case dw_val_class_offset:
5469 CHECKSUM (at->dw_attr_val.v.val_offset);
5472 case dw_val_class_loc:
5473 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5474 loc_checksum (loc, ctx);
5477 case dw_val_class_die_ref:
5478 die_checksum (AT_ref (at), ctx, mark);
5481 case dw_val_class_fde_ref:
5482 case dw_val_class_lbl_id:
5483 case dw_val_class_lbl_offset:
5491 /* Calculate the checksum of a DIE. */
5494 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5499 /* To avoid infinite recursion. */
5502 CHECKSUM (die->die_mark);
5505 die->die_mark = ++(*mark);
5507 CHECKSUM (die->die_tag);
5509 for (a = die->die_attr; a; a = a->dw_attr_next)
5510 attr_checksum (a, ctx, mark);
5512 for (c = die->die_child; c; c = c->die_sib)
5513 die_checksum (c, ctx, mark);
5517 #undef CHECKSUM_STRING
5519 /* Do the location expressions look same? */
5521 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5523 return loc1->dw_loc_opc == loc2->dw_loc_opc
5524 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5525 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5528 /* Do the values look the same? */
5530 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5532 dw_loc_descr_ref loc1, loc2;
5536 if (v1->val_class != v2->val_class)
5539 switch (v1->val_class)
5541 case dw_val_class_const:
5542 return v1->v.val_int == v2->v.val_int;
5543 case dw_val_class_unsigned_const:
5544 return v1->v.val_unsigned == v2->v.val_unsigned;
5545 case dw_val_class_long_long:
5546 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5547 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5548 case dw_val_class_float:
5549 if (v1->v.val_float.length != v2->v.val_float.length)
5551 for (i = 0; i < v1->v.val_float.length; i++)
5552 if (v1->v.val_float.array[i] != v2->v.val_float.array[i])
5555 case dw_val_class_flag:
5556 return v1->v.val_flag == v2->v.val_flag;
5557 case dw_val_class_str:
5558 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5560 case dw_val_class_addr:
5561 r1 = v1->v.val_addr;
5562 r2 = v2->v.val_addr;
5563 if (GET_CODE (r1) != GET_CODE (r2))
5565 switch (GET_CODE (r1))
5568 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
5574 case dw_val_class_offset:
5575 return v1->v.val_offset == v2->v.val_offset;
5577 case dw_val_class_loc:
5578 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
5580 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
5581 if (!same_loc_p (loc1, loc2, mark))
5583 return !loc1 && !loc2;
5585 case dw_val_class_die_ref:
5586 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
5588 case dw_val_class_fde_ref:
5589 case dw_val_class_lbl_id:
5590 case dw_val_class_lbl_offset:
5598 /* Do the attributes look the same? */
5601 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
5603 if (at1->dw_attr != at2->dw_attr)
5606 /* We don't care about differences in file numbering. */
5607 if (at1->dw_attr == DW_AT_decl_file
5608 /* Or that this was compiled with a different compiler snapshot; if
5609 the output is the same, that's what matters. */
5610 || at1->dw_attr == DW_AT_producer)
5613 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
5616 /* Do the dies look the same? */
5619 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
5624 /* To avoid infinite recursion. */
5626 return die1->die_mark == die2->die_mark;
5627 die1->die_mark = die2->die_mark = ++(*mark);
5629 if (die1->die_tag != die2->die_tag)
5632 for (a1 = die1->die_attr, a2 = die2->die_attr;
5634 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
5635 if (!same_attr_p (a1, a2, mark))
5640 for (c1 = die1->die_child, c2 = die2->die_child;
5642 c1 = c1->die_sib, c2 = c2->die_sib)
5643 if (!same_die_p (c1, c2, mark))
5651 /* Do the dies look the same? Wrapper around same_die_p. */
5654 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
5657 int ret = same_die_p (die1, die2, &mark);
5659 unmark_all_dies (die1);
5660 unmark_all_dies (die2);
5665 /* The prefix to attach to symbols on DIEs in the current comdat debug
5667 static char *comdat_symbol_id;
5669 /* The index of the current symbol within the current comdat CU. */
5670 static unsigned int comdat_symbol_number;
5672 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5673 children, and set comdat_symbol_id accordingly. */
5676 compute_section_prefix (dw_die_ref unit_die)
5678 const char *die_name = get_AT_string (unit_die, DW_AT_name);
5679 const char *base = die_name ? lbasename (die_name) : "anonymous";
5680 char *name = alloca (strlen (base) + 64);
5683 unsigned char checksum[16];
5686 /* Compute the checksum of the DIE, then append part of it as hex digits to
5687 the name filename of the unit. */
5689 md5_init_ctx (&ctx);
5691 die_checksum (unit_die, &ctx, &mark);
5692 unmark_all_dies (unit_die);
5693 md5_finish_ctx (&ctx, checksum);
5695 sprintf (name, "%s.", base);
5696 clean_symbol_name (name);
5698 p = name + strlen (name);
5699 for (i = 0; i < 4; i++)
5701 sprintf (p, "%.2x", checksum[i]);
5705 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5706 comdat_symbol_number = 0;
5709 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5712 is_type_die (dw_die_ref die)
5714 switch (die->die_tag)
5716 case DW_TAG_array_type:
5717 case DW_TAG_class_type:
5718 case DW_TAG_enumeration_type:
5719 case DW_TAG_pointer_type:
5720 case DW_TAG_reference_type:
5721 case DW_TAG_string_type:
5722 case DW_TAG_structure_type:
5723 case DW_TAG_subroutine_type:
5724 case DW_TAG_union_type:
5725 case DW_TAG_ptr_to_member_type:
5726 case DW_TAG_set_type:
5727 case DW_TAG_subrange_type:
5728 case DW_TAG_base_type:
5729 case DW_TAG_const_type:
5730 case DW_TAG_file_type:
5731 case DW_TAG_packed_type:
5732 case DW_TAG_volatile_type:
5733 case DW_TAG_typedef:
5740 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5741 Basically, we want to choose the bits that are likely to be shared between
5742 compilations (types) and leave out the bits that are specific to individual
5743 compilations (functions). */
5746 is_comdat_die (dw_die_ref c)
5748 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5749 we do for stabs. The advantage is a greater likelihood of sharing between
5750 objects that don't include headers in the same order (and therefore would
5751 put the base types in a different comdat). jason 8/28/00 */
5753 if (c->die_tag == DW_TAG_base_type)
5756 if (c->die_tag == DW_TAG_pointer_type
5757 || c->die_tag == DW_TAG_reference_type
5758 || c->die_tag == DW_TAG_const_type
5759 || c->die_tag == DW_TAG_volatile_type)
5761 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5763 return t ? is_comdat_die (t) : 0;
5766 return is_type_die (c);
5769 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5770 compilation unit. */
5773 is_symbol_die (dw_die_ref c)
5775 return (is_type_die (c)
5776 || (get_AT (c, DW_AT_declaration)
5777 && !get_AT (c, DW_AT_specification)));
5781 gen_internal_sym (const char *prefix)
5785 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5786 return xstrdup (buf);
5789 /* Assign symbols to all worthy DIEs under DIE. */
5792 assign_symbol_names (dw_die_ref die)
5796 if (is_symbol_die (die))
5798 if (comdat_symbol_id)
5800 char *p = alloca (strlen (comdat_symbol_id) + 64);
5802 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5803 comdat_symbol_id, comdat_symbol_number++);
5804 die->die_symbol = xstrdup (p);
5807 die->die_symbol = gen_internal_sym ("LDIE");
5810 for (c = die->die_child; c != NULL; c = c->die_sib)
5811 assign_symbol_names (c);
5814 struct cu_hash_table_entry
5817 unsigned min_comdat_num, max_comdat_num;
5818 struct cu_hash_table_entry *next;
5821 /* Routines to manipulate hash table of CUs. */
5823 htab_cu_hash (const void *of)
5825 const struct cu_hash_table_entry *entry = of;
5827 return htab_hash_string (entry->cu->die_symbol);
5831 htab_cu_eq (const void *of1, const void *of2)
5833 const struct cu_hash_table_entry *entry1 = of1;
5834 const struct die_struct *entry2 = of2;
5836 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
5840 htab_cu_del (void *what)
5842 struct cu_hash_table_entry *next, *entry = what;
5852 /* Check whether we have already seen this CU and set up SYM_NUM
5855 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
5857 struct cu_hash_table_entry dummy;
5858 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
5860 dummy.max_comdat_num = 0;
5862 slot = (struct cu_hash_table_entry **)
5863 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
5867 for (; entry; last = entry, entry = entry->next)
5869 if (same_die_p_wrap (cu, entry->cu))
5875 *sym_num = entry->min_comdat_num;
5879 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
5881 entry->min_comdat_num = *sym_num = last->max_comdat_num;
5882 entry->next = *slot;
5888 /* Record SYM_NUM to record of CU in HTABLE. */
5890 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
5892 struct cu_hash_table_entry **slot, *entry;
5894 slot = (struct cu_hash_table_entry **)
5895 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
5899 entry->max_comdat_num = sym_num;
5902 /* Traverse the DIE (which is always comp_unit_die), and set up
5903 additional compilation units for each of the include files we see
5904 bracketed by BINCL/EINCL. */
5907 break_out_includes (dw_die_ref die)
5910 dw_die_ref unit = NULL;
5911 limbo_die_node *node, **pnode;
5912 htab_t cu_hash_table;
5914 for (ptr = &(die->die_child); *ptr;)
5916 dw_die_ref c = *ptr;
5918 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5919 || (unit && is_comdat_die (c)))
5921 /* This DIE is for a secondary CU; remove it from the main one. */
5924 if (c->die_tag == DW_TAG_GNU_BINCL)
5926 unit = push_new_compile_unit (unit, c);
5929 else if (c->die_tag == DW_TAG_GNU_EINCL)
5931 unit = pop_compile_unit (unit);
5935 add_child_die (unit, c);
5939 /* Leave this DIE in the main CU. */
5940 ptr = &(c->die_sib);
5946 /* We can only use this in debugging, since the frontend doesn't check
5947 to make sure that we leave every include file we enter. */
5952 assign_symbol_names (die);
5953 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
5954 for (node = limbo_die_list, pnode = &limbo_die_list;
5960 compute_section_prefix (node->die);
5961 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
5962 &comdat_symbol_number);
5963 assign_symbol_names (node->die);
5965 *pnode = node->next;
5968 pnode = &node->next;
5969 record_comdat_symbol_number (node->die, cu_hash_table,
5970 comdat_symbol_number);
5973 htab_delete (cu_hash_table);
5976 /* Traverse the DIE and add a sibling attribute if it may have the
5977 effect of speeding up access to siblings. To save some space,
5978 avoid generating sibling attributes for DIE's without children. */
5981 add_sibling_attributes (dw_die_ref die)
5985 if (die->die_tag != DW_TAG_compile_unit
5986 && die->die_sib && die->die_child != NULL)
5987 /* Add the sibling link to the front of the attribute list. */
5988 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5990 for (c = die->die_child; c != NULL; c = c->die_sib)
5991 add_sibling_attributes (c);
5994 /* Output all location lists for the DIE and its children. */
5997 output_location_lists (dw_die_ref die)
6002 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6003 if (AT_class (d_attr) == dw_val_class_loc_list)
6004 output_loc_list (AT_loc_list (d_attr));
6006 for (c = die->die_child; c != NULL; c = c->die_sib)
6007 output_location_lists (c);
6011 /* The format of each DIE (and its attribute value pairs) is encoded in an
6012 abbreviation table. This routine builds the abbreviation table and assigns
6013 a unique abbreviation id for each abbreviation entry. The children of each
6014 die are visited recursively. */
6017 build_abbrev_table (dw_die_ref die)
6019 unsigned long abbrev_id;
6020 unsigned int n_alloc;
6022 dw_attr_ref d_attr, a_attr;
6024 /* Scan the DIE references, and mark as external any that refer to
6025 DIEs from other CUs (i.e. those which are not marked). */
6026 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6027 if (AT_class (d_attr) == dw_val_class_die_ref
6028 && AT_ref (d_attr)->die_mark == 0)
6030 if (AT_ref (d_attr)->die_symbol == 0)
6033 set_AT_ref_external (d_attr, 1);
6036 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6038 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6040 if (abbrev->die_tag == die->die_tag)
6042 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6044 a_attr = abbrev->die_attr;
6045 d_attr = die->die_attr;
6047 while (a_attr != NULL && d_attr != NULL)
6049 if ((a_attr->dw_attr != d_attr->dw_attr)
6050 || (value_format (a_attr) != value_format (d_attr)))
6053 a_attr = a_attr->dw_attr_next;
6054 d_attr = d_attr->dw_attr_next;
6057 if (a_attr == NULL && d_attr == NULL)
6063 if (abbrev_id >= abbrev_die_table_in_use)
6065 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6067 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6068 abbrev_die_table = ggc_realloc (abbrev_die_table,
6069 sizeof (dw_die_ref) * n_alloc);
6071 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6072 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6073 abbrev_die_table_allocated = n_alloc;
6076 ++abbrev_die_table_in_use;
6077 abbrev_die_table[abbrev_id] = die;
6080 die->die_abbrev = abbrev_id;
6081 for (c = die->die_child; c != NULL; c = c->die_sib)
6082 build_abbrev_table (c);
6085 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6088 constant_size (long unsigned int value)
6095 log = floor_log2 (value);
6098 log = 1 << (floor_log2 (log) + 1);
6103 /* Return the size of a DIE as it is represented in the
6104 .debug_info section. */
6106 static unsigned long
6107 size_of_die (dw_die_ref die)
6109 unsigned long size = 0;
6112 size += size_of_uleb128 (die->die_abbrev);
6113 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6115 switch (AT_class (a))
6117 case dw_val_class_addr:
6118 size += DWARF2_ADDR_SIZE;
6120 case dw_val_class_offset:
6121 size += DWARF_OFFSET_SIZE;
6123 case dw_val_class_loc:
6125 unsigned long lsize = size_of_locs (AT_loc (a));
6128 size += constant_size (lsize);
6132 case dw_val_class_loc_list:
6133 size += DWARF_OFFSET_SIZE;
6135 case dw_val_class_range_list:
6136 size += DWARF_OFFSET_SIZE;
6138 case dw_val_class_const:
6139 size += size_of_sleb128 (AT_int (a));
6141 case dw_val_class_unsigned_const:
6142 size += constant_size (AT_unsigned (a));
6144 case dw_val_class_long_long:
6145 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6147 case dw_val_class_float:
6148 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
6150 case dw_val_class_flag:
6153 case dw_val_class_die_ref:
6154 if (AT_ref_external (a))
6155 size += DWARF2_ADDR_SIZE;
6157 size += DWARF_OFFSET_SIZE;
6159 case dw_val_class_fde_ref:
6160 size += DWARF_OFFSET_SIZE;
6162 case dw_val_class_lbl_id:
6163 size += DWARF2_ADDR_SIZE;
6165 case dw_val_class_lbl_offset:
6166 size += DWARF_OFFSET_SIZE;
6168 case dw_val_class_str:
6169 if (AT_string_form (a) == DW_FORM_strp)
6170 size += DWARF_OFFSET_SIZE;
6172 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6182 /* Size the debugging information associated with a given DIE. Visits the
6183 DIE's children recursively. Updates the global variable next_die_offset, on
6184 each time through. Uses the current value of next_die_offset to update the
6185 die_offset field in each DIE. */
6188 calc_die_sizes (dw_die_ref die)
6192 die->die_offset = next_die_offset;
6193 next_die_offset += size_of_die (die);
6195 for (c = die->die_child; c != NULL; c = c->die_sib)
6198 if (die->die_child != NULL)
6199 /* Count the null byte used to terminate sibling lists. */
6200 next_die_offset += 1;
6203 /* Set the marks for a die and its children. We do this so
6204 that we know whether or not a reference needs to use FORM_ref_addr; only
6205 DIEs in the same CU will be marked. We used to clear out the offset
6206 and use that as the flag, but ran into ordering problems. */
6209 mark_dies (dw_die_ref die)
6217 for (c = die->die_child; c; c = c->die_sib)
6221 /* Clear the marks for a die and its children. */
6224 unmark_dies (dw_die_ref die)
6232 for (c = die->die_child; c; c = c->die_sib)
6236 /* Clear the marks for a die, its children and referred dies. */
6239 unmark_all_dies (dw_die_ref die)
6248 for (c = die->die_child; c; c = c->die_sib)
6249 unmark_all_dies (c);
6251 for (a = die->die_attr; a; a = a->dw_attr_next)
6252 if (AT_class (a) == dw_val_class_die_ref)
6253 unmark_all_dies (AT_ref (a));
6256 /* Return the size of the .debug_pubnames table generated for the
6257 compilation unit. */
6259 static unsigned long
6260 size_of_pubnames (void)
6265 size = DWARF_PUBNAMES_HEADER_SIZE;
6266 for (i = 0; i < pubname_table_in_use; i++)
6268 pubname_ref p = &pubname_table[i];
6269 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6272 size += DWARF_OFFSET_SIZE;
6276 /* Return the size of the information in the .debug_aranges section. */
6278 static unsigned long
6279 size_of_aranges (void)
6283 size = DWARF_ARANGES_HEADER_SIZE;
6285 /* Count the address/length pair for this compilation unit. */
6286 size += 2 * DWARF2_ADDR_SIZE;
6287 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6289 /* Count the two zero words used to terminated the address range table. */
6290 size += 2 * DWARF2_ADDR_SIZE;
6294 /* Select the encoding of an attribute value. */
6296 static enum dwarf_form
6297 value_format (dw_attr_ref a)
6299 switch (a->dw_attr_val.val_class)
6301 case dw_val_class_addr:
6302 return DW_FORM_addr;
6303 case dw_val_class_range_list:
6304 case dw_val_class_offset:
6305 if (DWARF_OFFSET_SIZE == 4)
6306 return DW_FORM_data4;
6307 if (DWARF_OFFSET_SIZE == 8)
6308 return DW_FORM_data8;
6310 case dw_val_class_loc_list:
6311 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6312 .debug_loc section */
6313 return DW_FORM_data4;
6314 case dw_val_class_loc:
6315 switch (constant_size (size_of_locs (AT_loc (a))))
6318 return DW_FORM_block1;
6320 return DW_FORM_block2;
6324 case dw_val_class_const:
6325 return DW_FORM_sdata;
6326 case dw_val_class_unsigned_const:
6327 switch (constant_size (AT_unsigned (a)))
6330 return DW_FORM_data1;
6332 return DW_FORM_data2;
6334 return DW_FORM_data4;
6336 return DW_FORM_data8;
6340 case dw_val_class_long_long:
6341 return DW_FORM_block1;
6342 case dw_val_class_float:
6343 return DW_FORM_block1;
6344 case dw_val_class_flag:
6345 return DW_FORM_flag;
6346 case dw_val_class_die_ref:
6347 if (AT_ref_external (a))
6348 return DW_FORM_ref_addr;
6351 case dw_val_class_fde_ref:
6352 return DW_FORM_data;
6353 case dw_val_class_lbl_id:
6354 return DW_FORM_addr;
6355 case dw_val_class_lbl_offset:
6356 return DW_FORM_data;
6357 case dw_val_class_str:
6358 return AT_string_form (a);
6365 /* Output the encoding of an attribute value. */
6368 output_value_format (dw_attr_ref a)
6370 enum dwarf_form form = value_format (a);
6372 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6375 /* Output the .debug_abbrev section which defines the DIE abbreviation
6379 output_abbrev_section (void)
6381 unsigned long abbrev_id;
6385 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6387 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6389 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6390 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6391 dwarf_tag_name (abbrev->die_tag));
6393 if (abbrev->die_child != NULL)
6394 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6396 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6398 for (a_attr = abbrev->die_attr; a_attr != NULL;
6399 a_attr = a_attr->dw_attr_next)
6401 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6402 dwarf_attr_name (a_attr->dw_attr));
6403 output_value_format (a_attr);
6406 dw2_asm_output_data (1, 0, NULL);
6407 dw2_asm_output_data (1, 0, NULL);
6410 /* Terminate the table. */
6411 dw2_asm_output_data (1, 0, NULL);
6414 /* Output a symbol we can use to refer to this DIE from another CU. */
6417 output_die_symbol (dw_die_ref die)
6419 char *sym = die->die_symbol;
6424 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6425 /* We make these global, not weak; if the target doesn't support
6426 .linkonce, it doesn't support combining the sections, so debugging
6428 (*targetm.asm_out.globalize_label) (asm_out_file, sym);
6430 ASM_OUTPUT_LABEL (asm_out_file, sym);
6433 /* Return a new location list, given the begin and end range, and the
6434 expression. gensym tells us whether to generate a new internal symbol for
6435 this location list node, which is done for the head of the list only. */
6437 static inline dw_loc_list_ref
6438 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6439 const char *section, unsigned int gensym)
6441 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6443 retlist->begin = begin;
6445 retlist->expr = expr;
6446 retlist->section = section;
6448 retlist->ll_symbol = gen_internal_sym ("LLST");
6453 /* Add a location description expression to a location list. */
6456 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6457 const char *begin, const char *end,
6458 const char *section)
6462 /* Find the end of the chain. */
6463 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6466 /* Add a new location list node to the list. */
6467 *d = new_loc_list (descr, begin, end, section, 0);
6470 /* Output the location list given to us. */
6473 output_loc_list (dw_loc_list_ref list_head)
6475 dw_loc_list_ref curr = list_head;
6477 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6479 /* ??? This shouldn't be needed now that we've forced the
6480 compilation unit base address to zero when there is code
6481 in more than one section. */
6482 if (strcmp (curr->section, ".text") == 0)
6484 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6485 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6486 "Location list base address specifier fake entry");
6487 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6488 "Location list base address specifier base");
6491 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6495 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6496 "Location list begin address (%s)",
6497 list_head->ll_symbol);
6498 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6499 "Location list end address (%s)",
6500 list_head->ll_symbol);
6501 size = size_of_locs (curr->expr);
6503 /* Output the block length for this list of location operations. */
6506 dw2_asm_output_data (2, size, "%s", "Location expression size");
6508 output_loc_sequence (curr->expr);
6511 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6512 "Location list terminator begin (%s)",
6513 list_head->ll_symbol);
6514 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6515 "Location list terminator end (%s)",
6516 list_head->ll_symbol);
6519 /* Output the DIE and its attributes. Called recursively to generate
6520 the definitions of each child DIE. */
6523 output_die (dw_die_ref die)
6529 /* If someone in another CU might refer to us, set up a symbol for
6530 them to point to. */
6531 if (die->die_symbol)
6532 output_die_symbol (die);
6534 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6535 die->die_offset, dwarf_tag_name (die->die_tag));
6537 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6539 const char *name = dwarf_attr_name (a->dw_attr);
6541 switch (AT_class (a))
6543 case dw_val_class_addr:
6544 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6547 case dw_val_class_offset:
6548 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6552 case dw_val_class_range_list:
6554 char *p = strchr (ranges_section_label, '\0');
6556 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6557 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6563 case dw_val_class_loc:
6564 size = size_of_locs (AT_loc (a));
6566 /* Output the block length for this list of location operations. */
6567 dw2_asm_output_data (constant_size (size), size, "%s", name);
6569 output_loc_sequence (AT_loc (a));
6572 case dw_val_class_const:
6573 /* ??? It would be slightly more efficient to use a scheme like is
6574 used for unsigned constants below, but gdb 4.x does not sign
6575 extend. Gdb 5.x does sign extend. */
6576 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6579 case dw_val_class_unsigned_const:
6580 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6581 AT_unsigned (a), "%s", name);
6584 case dw_val_class_long_long:
6586 unsigned HOST_WIDE_INT first, second;
6588 dw2_asm_output_data (1,
6589 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6592 if (WORDS_BIG_ENDIAN)
6594 first = a->dw_attr_val.v.val_long_long.hi;
6595 second = a->dw_attr_val.v.val_long_long.low;
6599 first = a->dw_attr_val.v.val_long_long.low;
6600 second = a->dw_attr_val.v.val_long_long.hi;
6603 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6604 first, "long long constant");
6605 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6610 case dw_val_class_float:
6614 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6617 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6618 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6619 "fp constant word %u", i);
6623 case dw_val_class_flag:
6624 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6627 case dw_val_class_loc_list:
6629 char *sym = AT_loc_list (a)->ll_symbol;
6633 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6634 loc_section_label, "%s", name);
6638 case dw_val_class_die_ref:
6639 if (AT_ref_external (a))
6641 char *sym = AT_ref (a)->die_symbol;
6645 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6647 else if (AT_ref (a)->die_offset == 0)
6650 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6654 case dw_val_class_fde_ref:
6658 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6659 a->dw_attr_val.v.val_fde_index * 2);
6660 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6664 case dw_val_class_lbl_id:
6665 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6668 case dw_val_class_lbl_offset:
6669 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6672 case dw_val_class_str:
6673 if (AT_string_form (a) == DW_FORM_strp)
6674 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6675 a->dw_attr_val.v.val_str->label,
6676 "%s: \"%s\"", name, AT_string (a));
6678 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6686 for (c = die->die_child; c != NULL; c = c->die_sib)
6689 /* Add null byte to terminate sibling list. */
6690 if (die->die_child != NULL)
6691 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6695 /* Output the compilation unit that appears at the beginning of the
6696 .debug_info section, and precedes the DIE descriptions. */
6699 output_compilation_unit_header (void)
6701 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6702 dw2_asm_output_data (4, 0xffffffff,
6703 "Initial length escape value indicating 64-bit DWARF extension");
6704 dw2_asm_output_data (DWARF_OFFSET_SIZE,
6705 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
6706 "Length of Compilation Unit Info");
6707 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6708 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6709 "Offset Into Abbrev. Section");
6710 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6713 /* Output the compilation unit DIE and its children. */
6716 output_comp_unit (dw_die_ref die, int output_if_empty)
6718 const char *secname;
6721 /* Unless we are outputting main CU, we may throw away empty ones. */
6722 if (!output_if_empty && die->die_child == NULL)
6725 /* Even if there are no children of this DIE, we must output the information
6726 about the compilation unit. Otherwise, on an empty translation unit, we
6727 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6728 will then complain when examining the file. First mark all the DIEs in
6729 this CU so we know which get local refs. */
6732 build_abbrev_table (die);
6734 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6735 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6736 calc_die_sizes (die);
6738 oldsym = die->die_symbol;
6741 tmp = alloca (strlen (oldsym) + 24);
6743 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
6745 die->die_symbol = NULL;
6748 secname = (const char *) DEBUG_INFO_SECTION;
6750 /* Output debugging information. */
6751 named_section_flags (secname, SECTION_DEBUG);
6752 output_compilation_unit_header ();
6755 /* Leave the marks on the main CU, so we can check them in
6760 die->die_symbol = oldsym;
6764 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6765 output of lang_hooks.decl_printable_name for C++ looks like
6766 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6769 dwarf2_name (tree decl, int scope)
6771 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6774 /* Add a new entry to .debug_pubnames if appropriate. */
6777 add_pubname (tree decl, dw_die_ref die)
6781 if (! TREE_PUBLIC (decl))
6784 if (pubname_table_in_use == pubname_table_allocated)
6786 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6788 = ggc_realloc (pubname_table,
6789 (pubname_table_allocated * sizeof (pubname_entry)));
6790 memset (pubname_table + pubname_table_in_use, 0,
6791 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
6794 p = &pubname_table[pubname_table_in_use++];
6796 p->name = xstrdup (dwarf2_name (decl, 1));
6799 /* Output the public names table used to speed up access to externally
6800 visible names. For now, only generate entries for externally
6801 visible procedures. */
6804 output_pubnames (void)
6807 unsigned long pubnames_length = size_of_pubnames ();
6809 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6810 dw2_asm_output_data (4, 0xffffffff,
6811 "Initial length escape value indicating 64-bit DWARF extension");
6812 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6813 "Length of Public Names Info");
6814 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6815 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6816 "Offset of Compilation Unit Info");
6817 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6818 "Compilation Unit Length");
6820 for (i = 0; i < pubname_table_in_use; i++)
6822 pubname_ref pub = &pubname_table[i];
6824 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6825 if (pub->die->die_mark == 0)
6828 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6831 dw2_asm_output_nstring (pub->name, -1, "external name");
6834 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6837 /* Add a new entry to .debug_aranges if appropriate. */
6840 add_arange (tree decl, dw_die_ref die)
6842 if (! DECL_SECTION_NAME (decl))
6845 if (arange_table_in_use == arange_table_allocated)
6847 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6848 arange_table = ggc_realloc (arange_table,
6849 (arange_table_allocated
6850 * sizeof (dw_die_ref)));
6851 memset (arange_table + arange_table_in_use, 0,
6852 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
6855 arange_table[arange_table_in_use++] = die;
6858 /* Output the information that goes into the .debug_aranges table.
6859 Namely, define the beginning and ending address range of the
6860 text section generated for this compilation unit. */
6863 output_aranges (void)
6866 unsigned long aranges_length = size_of_aranges ();
6868 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
6869 dw2_asm_output_data (4, 0xffffffff,
6870 "Initial length escape value indicating 64-bit DWARF extension");
6871 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6872 "Length of Address Ranges Info");
6873 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6874 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6875 "Offset of Compilation Unit Info");
6876 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6877 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6879 /* We need to align to twice the pointer size here. */
6880 if (DWARF_ARANGES_PAD_SIZE)
6882 /* Pad using a 2 byte words so that padding is correct for any
6884 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6885 2 * DWARF2_ADDR_SIZE);
6886 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6887 dw2_asm_output_data (2, 0, NULL);
6890 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6891 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6892 text_section_label, "Length");
6894 for (i = 0; i < arange_table_in_use; i++)
6896 dw_die_ref die = arange_table[i];
6898 /* We shouldn't see aranges for DIEs outside of the main CU. */
6899 if (die->die_mark == 0)
6902 if (die->die_tag == DW_TAG_subprogram)
6904 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6906 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6907 get_AT_low_pc (die), "Length");
6911 /* A static variable; extract the symbol from DW_AT_location.
6912 Note that this code isn't currently hit, as we only emit
6913 aranges for functions (jason 9/23/99). */
6914 dw_attr_ref a = get_AT (die, DW_AT_location);
6915 dw_loc_descr_ref loc;
6917 if (! a || AT_class (a) != dw_val_class_loc)
6921 if (loc->dw_loc_opc != DW_OP_addr)
6924 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6925 loc->dw_loc_oprnd1.v.val_addr, "Address");
6926 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6927 get_AT_unsigned (die, DW_AT_byte_size),
6932 /* Output the terminator words. */
6933 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6934 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6937 /* Add a new entry to .debug_ranges. Return the offset at which it
6941 add_ranges (tree block)
6943 unsigned int in_use = ranges_table_in_use;
6945 if (in_use == ranges_table_allocated)
6947 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6949 = ggc_realloc (ranges_table, (ranges_table_allocated
6950 * sizeof (struct dw_ranges_struct)));
6951 memset (ranges_table + ranges_table_in_use, 0,
6952 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
6955 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6956 ranges_table_in_use = in_use + 1;
6958 return in_use * 2 * DWARF2_ADDR_SIZE;
6962 output_ranges (void)
6965 static const char *const start_fmt = "Offset 0x%x";
6966 const char *fmt = start_fmt;
6968 for (i = 0; i < ranges_table_in_use; i++)
6970 int block_num = ranges_table[i].block_num;
6974 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6975 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6977 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6978 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6980 /* If all code is in the text section, then the compilation
6981 unit base address defaults to DW_AT_low_pc, which is the
6982 base of the text section. */
6983 if (separate_line_info_table_in_use == 0)
6985 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6987 fmt, i * 2 * DWARF2_ADDR_SIZE);
6988 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6989 text_section_label, NULL);
6992 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6993 compilation unit base address to zero, which allows us to
6994 use absolute addresses, and not worry about whether the
6995 target supports cross-section arithmetic. */
6998 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6999 fmt, i * 2 * DWARF2_ADDR_SIZE);
7000 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7007 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7008 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7014 /* Data structure containing information about input files. */
7017 char *path; /* Complete file name. */
7018 char *fname; /* File name part. */
7019 int length; /* Length of entire string. */
7020 int file_idx; /* Index in input file table. */
7021 int dir_idx; /* Index in directory table. */
7024 /* Data structure containing information about directories with source
7028 char *path; /* Path including directory name. */
7029 int length; /* Path length. */
7030 int prefix; /* Index of directory entry which is a prefix. */
7031 int count; /* Number of files in this directory. */
7032 int dir_idx; /* Index of directory used as base. */
7033 int used; /* Used in the end? */
7036 /* Callback function for file_info comparison. We sort by looking at
7037 the directories in the path. */
7040 file_info_cmp (const void *p1, const void *p2)
7042 const struct file_info *s1 = p1;
7043 const struct file_info *s2 = p2;
7047 /* Take care of file names without directories. We need to make sure that
7048 we return consistent values to qsort since some will get confused if
7049 we return the same value when identical operands are passed in opposite
7050 orders. So if neither has a directory, return 0 and otherwise return
7051 1 or -1 depending on which one has the directory. */
7052 if ((s1->path == s1->fname || s2->path == s2->fname))
7053 return (s2->path == s2->fname) - (s1->path == s1->fname);
7055 cp1 = (unsigned char *) s1->path;
7056 cp2 = (unsigned char *) s2->path;
7062 /* Reached the end of the first path? If so, handle like above. */
7063 if ((cp1 == (unsigned char *) s1->fname)
7064 || (cp2 == (unsigned char *) s2->fname))
7065 return ((cp2 == (unsigned char *) s2->fname)
7066 - (cp1 == (unsigned char *) s1->fname));
7068 /* Character of current path component the same? */
7069 else if (*cp1 != *cp2)
7074 /* Output the directory table and the file name table. We try to minimize
7075 the total amount of memory needed. A heuristic is used to avoid large
7076 slowdowns with many input files. */
7079 output_file_names (void)
7081 struct file_info *files;
7082 struct dir_info *dirs;
7091 /* Handle the case where file_table is empty. */
7092 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7094 dw2_asm_output_data (1, 0, "End directory table");
7095 dw2_asm_output_data (1, 0, "End file name table");
7099 /* Allocate the various arrays we need. */
7100 files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info));
7101 dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info));
7103 /* Sort the file names. */
7104 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7108 /* Skip all leading "./". */
7109 f = VARRAY_CHAR_PTR (file_table, i);
7110 while (f[0] == '.' && f[1] == '/')
7113 /* Create a new array entry. */
7115 files[i].length = strlen (f);
7116 files[i].file_idx = i;
7118 /* Search for the file name part. */
7119 f = strrchr (f, '/');
7120 files[i].fname = f == NULL ? files[i].path : f + 1;
7123 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7124 sizeof (files[0]), file_info_cmp);
7126 /* Find all the different directories used. */
7127 dirs[0].path = files[1].path;
7128 dirs[0].length = files[1].fname - files[1].path;
7129 dirs[0].prefix = -1;
7131 dirs[0].dir_idx = 0;
7133 files[1].dir_idx = 0;
7136 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7137 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7138 && memcmp (dirs[ndirs - 1].path, files[i].path,
7139 dirs[ndirs - 1].length) == 0)
7141 /* Same directory as last entry. */
7142 files[i].dir_idx = ndirs - 1;
7143 ++dirs[ndirs - 1].count;
7149 /* This is a new directory. */
7150 dirs[ndirs].path = files[i].path;
7151 dirs[ndirs].length = files[i].fname - files[i].path;
7152 dirs[ndirs].count = 1;
7153 dirs[ndirs].dir_idx = ndirs;
7154 dirs[ndirs].used = 0;
7155 files[i].dir_idx = ndirs;
7157 /* Search for a prefix. */
7158 dirs[ndirs].prefix = -1;
7159 for (j = 0; j < ndirs; j++)
7160 if (dirs[j].length < dirs[ndirs].length
7161 && dirs[j].length > 1
7162 && (dirs[ndirs].prefix == -1
7163 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7164 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7165 dirs[ndirs].prefix = j;
7170 /* Now to the actual work. We have to find a subset of the directories which
7171 allow expressing the file name using references to the directory table
7172 with the least amount of characters. We do not do an exhaustive search
7173 where we would have to check out every combination of every single
7174 possible prefix. Instead we use a heuristic which provides nearly optimal
7175 results in most cases and never is much off. */
7176 saved = alloca (ndirs * sizeof (int));
7177 savehere = alloca (ndirs * sizeof (int));
7179 memset (saved, '\0', ndirs * sizeof (saved[0]));
7180 for (i = 0; i < ndirs; i++)
7185 /* We can always save some space for the current directory. But this
7186 does not mean it will be enough to justify adding the directory. */
7187 savehere[i] = dirs[i].length;
7188 total = (savehere[i] - saved[i]) * dirs[i].count;
7190 for (j = i + 1; j < ndirs; j++)
7193 if (saved[j] < dirs[i].length)
7195 /* Determine whether the dirs[i] path is a prefix of the
7200 while (k != -1 && k != (int) i)
7205 /* Yes it is. We can possibly safe some memory but
7206 writing the filenames in dirs[j] relative to
7208 savehere[j] = dirs[i].length;
7209 total += (savehere[j] - saved[j]) * dirs[j].count;
7214 /* Check whether we can safe enough to justify adding the dirs[i]
7216 if (total > dirs[i].length + 1)
7218 /* It's worthwhile adding. */
7219 for (j = i; j < ndirs; j++)
7220 if (savehere[j] > 0)
7222 /* Remember how much we saved for this directory so far. */
7223 saved[j] = savehere[j];
7225 /* Remember the prefix directory. */
7226 dirs[j].dir_idx = i;
7231 /* We have to emit them in the order they appear in the file_table array
7232 since the index is used in the debug info generation. To do this
7233 efficiently we generate a back-mapping of the indices first. */
7234 backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7235 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7237 backmap[files[i].file_idx] = i;
7239 /* Mark this directory as used. */
7240 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7243 /* That was it. We are ready to emit the information. First emit the
7244 directory name table. We have to make sure the first actually emitted
7245 directory name has index one; zero is reserved for the current working
7246 directory. Make sure we do not confuse these indices with the one for the
7247 constructed table (even though most of the time they are identical). */
7249 idx_offset = dirs[0].length > 0 ? 1 : 0;
7250 for (i = 1 - idx_offset; i < ndirs; i++)
7251 if (dirs[i].used != 0)
7253 dirs[i].used = idx++;
7254 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7255 "Directory Entry: 0x%x", dirs[i].used);
7258 dw2_asm_output_data (1, 0, "End directory table");
7260 /* Correct the index for the current working directory entry if it
7262 if (idx_offset == 0)
7265 /* Now write all the file names. */
7266 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7268 int file_idx = backmap[i];
7269 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7271 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7272 "File Entry: 0x%lx", (unsigned long) i);
7274 /* Include directory index. */
7275 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7277 /* Modification time. */
7278 dw2_asm_output_data_uleb128 (0, NULL);
7280 /* File length in bytes. */
7281 dw2_asm_output_data_uleb128 (0, NULL);
7284 dw2_asm_output_data (1, 0, "End file name table");
7288 /* Output the source line number correspondence information. This
7289 information goes into the .debug_line section. */
7292 output_line_info (void)
7294 char l1[20], l2[20], p1[20], p2[20];
7295 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7296 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7299 unsigned long lt_index;
7300 unsigned long current_line;
7303 unsigned long current_file;
7304 unsigned long function;
7306 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7307 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7308 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7309 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7311 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7312 dw2_asm_output_data (4, 0xffffffff,
7313 "Initial length escape value indicating 64-bit DWARF extension");
7314 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7315 "Length of Source Line Info");
7316 ASM_OUTPUT_LABEL (asm_out_file, l1);
7318 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7319 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7320 ASM_OUTPUT_LABEL (asm_out_file, p1);
7322 /* Define the architecture-dependent minimum instruction length (in
7323 bytes). In this implementation of DWARF, this field is used for
7324 information purposes only. Since GCC generates assembly language,
7325 we have no a priori knowledge of how many instruction bytes are
7326 generated for each source line, and therefore can use only the
7327 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7328 commands. Accordingly, we fix this as `1', which is "correct
7329 enough" for all architectures, and don't let the target override. */
7330 dw2_asm_output_data (1, 1,
7331 "Minimum Instruction Length");
7333 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7334 "Default is_stmt_start flag");
7335 dw2_asm_output_data (1, DWARF_LINE_BASE,
7336 "Line Base Value (Special Opcodes)");
7337 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7338 "Line Range Value (Special Opcodes)");
7339 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7340 "Special Opcode Base");
7342 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7346 case DW_LNS_advance_pc:
7347 case DW_LNS_advance_line:
7348 case DW_LNS_set_file:
7349 case DW_LNS_set_column:
7350 case DW_LNS_fixed_advance_pc:
7358 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7362 /* Write out the information about the files we use. */
7363 output_file_names ();
7364 ASM_OUTPUT_LABEL (asm_out_file, p2);
7366 /* We used to set the address register to the first location in the text
7367 section here, but that didn't accomplish anything since we already
7368 have a line note for the opening brace of the first function. */
7370 /* Generate the line number to PC correspondence table, encoded as
7371 a series of state machine operations. */
7374 strcpy (prev_line_label, text_section_label);
7375 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7377 dw_line_info_ref line_info = &line_info_table[lt_index];
7380 /* Disable this optimization for now; GDB wants to see two line notes
7381 at the beginning of a function so it can find the end of the
7384 /* Don't emit anything for redundant notes. Just updating the
7385 address doesn't accomplish anything, because we already assume
7386 that anything after the last address is this line. */
7387 if (line_info->dw_line_num == current_line
7388 && line_info->dw_file_num == current_file)
7392 /* Emit debug info for the address of the current line.
7394 Unfortunately, we have little choice here currently, and must always
7395 use the most general form. GCC does not know the address delta
7396 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7397 attributes which will give an upper bound on the address range. We
7398 could perhaps use length attributes to determine when it is safe to
7399 use DW_LNS_fixed_advance_pc. */
7401 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7404 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7405 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7406 "DW_LNS_fixed_advance_pc");
7407 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7411 /* This can handle any delta. This takes
7412 4+DWARF2_ADDR_SIZE bytes. */
7413 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7414 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7415 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7416 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7419 strcpy (prev_line_label, line_label);
7421 /* Emit debug info for the source file of the current line, if
7422 different from the previous line. */
7423 if (line_info->dw_file_num != current_file)
7425 current_file = line_info->dw_file_num;
7426 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7427 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7428 VARRAY_CHAR_PTR (file_table,
7432 /* Emit debug info for the current line number, choosing the encoding
7433 that uses the least amount of space. */
7434 if (line_info->dw_line_num != current_line)
7436 line_offset = line_info->dw_line_num - current_line;
7437 line_delta = line_offset - DWARF_LINE_BASE;
7438 current_line = line_info->dw_line_num;
7439 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7440 /* This can handle deltas from -10 to 234, using the current
7441 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7443 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7444 "line %lu", current_line);
7447 /* This can handle any delta. This takes at least 4 bytes,
7448 depending on the value being encoded. */
7449 dw2_asm_output_data (1, DW_LNS_advance_line,
7450 "advance to line %lu", current_line);
7451 dw2_asm_output_data_sleb128 (line_offset, NULL);
7452 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7456 /* We still need to start a new row, so output a copy insn. */
7457 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7460 /* Emit debug info for the address of the end of the function. */
7463 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7464 "DW_LNS_fixed_advance_pc");
7465 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7469 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7470 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7471 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7472 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7475 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7476 dw2_asm_output_data_uleb128 (1, NULL);
7477 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7482 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7484 dw_separate_line_info_ref line_info
7485 = &separate_line_info_table[lt_index];
7488 /* Don't emit anything for redundant notes. */
7489 if (line_info->dw_line_num == current_line
7490 && line_info->dw_file_num == current_file
7491 && line_info->function == function)
7495 /* Emit debug info for the address of the current line. If this is
7496 a new function, or the first line of a function, then we need
7497 to handle it differently. */
7498 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7500 if (function != line_info->function)
7502 function = line_info->function;
7504 /* Set the address register to the first line in the function. */
7505 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7506 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7507 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7508 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7512 /* ??? See the DW_LNS_advance_pc comment above. */
7515 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7516 "DW_LNS_fixed_advance_pc");
7517 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7521 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7522 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7523 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7524 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7528 strcpy (prev_line_label, line_label);
7530 /* Emit debug info for the source file of the current line, if
7531 different from the previous line. */
7532 if (line_info->dw_file_num != current_file)
7534 current_file = line_info->dw_file_num;
7535 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7536 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7537 VARRAY_CHAR_PTR (file_table,
7541 /* Emit debug info for the current line number, choosing the encoding
7542 that uses the least amount of space. */
7543 if (line_info->dw_line_num != current_line)
7545 line_offset = line_info->dw_line_num - current_line;
7546 line_delta = line_offset - DWARF_LINE_BASE;
7547 current_line = line_info->dw_line_num;
7548 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7549 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7550 "line %lu", current_line);
7553 dw2_asm_output_data (1, DW_LNS_advance_line,
7554 "advance to line %lu", current_line);
7555 dw2_asm_output_data_sleb128 (line_offset, NULL);
7556 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7560 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7568 /* If we're done with a function, end its sequence. */
7569 if (lt_index == separate_line_info_table_in_use
7570 || separate_line_info_table[lt_index].function != function)
7575 /* Emit debug info for the address of the end of the function. */
7576 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7579 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7580 "DW_LNS_fixed_advance_pc");
7581 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7585 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7586 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7587 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7588 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7591 /* Output the marker for the end of this sequence. */
7592 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7593 dw2_asm_output_data_uleb128 (1, NULL);
7594 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7598 /* Output the marker for the end of the line number info. */
7599 ASM_OUTPUT_LABEL (asm_out_file, l2);
7602 /* Given a pointer to a tree node for some base type, return a pointer to
7603 a DIE that describes the given type.
7605 This routine must only be called for GCC type nodes that correspond to
7606 Dwarf base (fundamental) types. */
7609 base_type_die (tree type)
7611 dw_die_ref base_type_result;
7612 const char *type_name;
7613 enum dwarf_type encoding;
7614 tree name = TYPE_NAME (type);
7616 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7621 if (TREE_CODE (name) == TYPE_DECL)
7622 name = DECL_NAME (name);
7624 type_name = IDENTIFIER_POINTER (name);
7627 type_name = "__unknown__";
7629 switch (TREE_CODE (type))
7632 /* Carefully distinguish the C character types, without messing
7633 up if the language is not C. Note that we check only for the names
7634 that contain spaces; other names might occur by coincidence in other
7636 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7637 && (type == char_type_node
7638 || ! strcmp (type_name, "signed char")
7639 || ! strcmp (type_name, "unsigned char"))))
7641 if (TREE_UNSIGNED (type))
7642 encoding = DW_ATE_unsigned;
7644 encoding = DW_ATE_signed;
7647 /* else fall through. */
7650 /* GNU Pascal/Ada CHAR type. Not used in C. */
7651 if (TREE_UNSIGNED (type))
7652 encoding = DW_ATE_unsigned_char;
7654 encoding = DW_ATE_signed_char;
7658 encoding = DW_ATE_float;
7661 /* Dwarf2 doesn't know anything about complex ints, so use
7662 a user defined type for it. */
7664 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7665 encoding = DW_ATE_complex_float;
7667 encoding = DW_ATE_lo_user;
7671 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7672 encoding = DW_ATE_boolean;
7676 /* No other TREE_CODEs are Dwarf fundamental types. */
7680 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7681 if (demangle_name_func)
7682 type_name = (*demangle_name_func) (type_name);
7684 add_AT_string (base_type_result, DW_AT_name, type_name);
7685 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7686 int_size_in_bytes (type));
7687 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7689 return base_type_result;
7692 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7693 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7694 a given type is generally the same as the given type, except that if the
7695 given type is a pointer or reference type, then the root type of the given
7696 type is the root type of the "basis" type for the pointer or reference
7697 type. (This definition of the "root" type is recursive.) Also, the root
7698 type of a `const' qualified type or a `volatile' qualified type is the
7699 root type of the given type without the qualifiers. */
7702 root_type (tree type)
7704 if (TREE_CODE (type) == ERROR_MARK)
7705 return error_mark_node;
7707 switch (TREE_CODE (type))
7710 return error_mark_node;
7713 case REFERENCE_TYPE:
7714 return type_main_variant (root_type (TREE_TYPE (type)));
7717 return type_main_variant (type);
7721 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7722 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7725 is_base_type (tree type)
7727 switch (TREE_CODE (type))
7742 case QUAL_UNION_TYPE:
7747 case REFERENCE_TYPE:
7761 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7762 node, return the size in bits for the type if it is a constant, or else
7763 return the alignment for the type if the type's size is not constant, or
7764 else return BITS_PER_WORD if the type actually turns out to be an
7767 static inline unsigned HOST_WIDE_INT
7768 simple_type_size_in_bits (tree type)
7770 if (TREE_CODE (type) == ERROR_MARK)
7771 return BITS_PER_WORD;
7772 else if (TYPE_SIZE (type) == NULL_TREE)
7774 else if (host_integerp (TYPE_SIZE (type), 1))
7775 return tree_low_cst (TYPE_SIZE (type), 1);
7777 return TYPE_ALIGN (type);
7780 /* Return true if the debug information for the given type should be
7781 emitted as a subrange type. */
7784 is_ada_subrange_type (tree type)
7786 /* We do this for INTEGER_TYPEs that have names, parent types, and when
7787 we are compiling Ada code. */
7788 return (TREE_CODE (type) == INTEGER_TYPE
7789 && TYPE_NAME (type) != 0 && TREE_TYPE (type) != 0
7790 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE
7791 && TREE_UNSIGNED (TREE_TYPE (type)) && is_ada ());
7794 /* Given a pointer to a tree node for a subrange type, return a pointer
7795 to a DIE that describes the given type. */
7798 subrange_type_die (tree type)
7800 dw_die_ref subtype_die;
7801 dw_die_ref subrange_die;
7802 tree name = TYPE_NAME (type);
7804 subtype_die = base_type_die (TREE_TYPE (type));
7806 if (TREE_CODE (name) == TYPE_DECL)
7807 name = DECL_NAME (name);
7809 subrange_die = new_die (DW_TAG_subrange_type, comp_unit_die, type);
7810 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
7811 if (TYPE_MIN_VALUE (type) != NULL)
7812 add_bound_info (subrange_die, DW_AT_lower_bound,
7813 TYPE_MIN_VALUE (type));
7814 if (TYPE_MAX_VALUE (type) != NULL)
7815 add_bound_info (subrange_die, DW_AT_upper_bound,
7816 TYPE_MAX_VALUE (type));
7817 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
7819 return subrange_die;
7822 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7823 entry that chains various modifiers in front of the given type. */
7826 modified_type_die (tree type, int is_const_type, int is_volatile_type,
7827 dw_die_ref context_die)
7829 enum tree_code code = TREE_CODE (type);
7830 dw_die_ref mod_type_die = NULL;
7831 dw_die_ref sub_die = NULL;
7832 tree item_type = NULL;
7834 if (code != ERROR_MARK)
7836 tree qualified_type;
7838 /* See if we already have the appropriately qualified variant of
7841 = get_qualified_type (type,
7842 ((is_const_type ? TYPE_QUAL_CONST : 0)
7844 ? TYPE_QUAL_VOLATILE : 0)));
7846 /* If we do, then we can just use its DIE, if it exists. */
7849 mod_type_die = lookup_type_die (qualified_type);
7851 return mod_type_die;
7854 /* Handle C typedef types. */
7855 if (qualified_type && TYPE_NAME (qualified_type)
7856 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7857 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7859 tree type_name = TYPE_NAME (qualified_type);
7860 tree dtype = TREE_TYPE (type_name);
7862 if (qualified_type == dtype)
7864 /* For a named type, use the typedef. */
7865 gen_type_die (qualified_type, context_die);
7866 mod_type_die = lookup_type_die (qualified_type);
7868 else if (is_const_type < TYPE_READONLY (dtype)
7869 || is_volatile_type < TYPE_VOLATILE (dtype))
7870 /* cv-unqualified version of named type. Just use the unnamed
7871 type to which it refers. */
7873 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7874 is_const_type, is_volatile_type,
7877 /* Else cv-qualified version of named type; fall through. */
7883 else if (is_const_type)
7885 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7886 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7888 else if (is_volatile_type)
7890 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7891 sub_die = modified_type_die (type, 0, 0, context_die);
7893 else if (code == POINTER_TYPE)
7895 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7896 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
7897 simple_type_size_in_bits (type) / BITS_PER_UNIT);
7899 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7901 item_type = TREE_TYPE (type);
7903 else if (code == REFERENCE_TYPE)
7905 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7906 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
7907 simple_type_size_in_bits (type) / BITS_PER_UNIT);
7909 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7911 item_type = TREE_TYPE (type);
7913 else if (is_ada_subrange_type (type))
7914 mod_type_die = subrange_type_die (type);
7915 else if (is_base_type (type))
7916 mod_type_die = base_type_die (type);
7919 gen_type_die (type, context_die);
7921 /* We have to get the type_main_variant here (and pass that to the
7922 `lookup_type_die' routine) because the ..._TYPE node we have
7923 might simply be a *copy* of some original type node (where the
7924 copy was created to help us keep track of typedef names) and
7925 that copy might have a different TYPE_UID from the original
7927 if (TREE_CODE (type) != VECTOR_TYPE)
7928 mod_type_die = lookup_type_die (type_main_variant (type));
7930 /* Vectors have the debugging information in the type,
7931 not the main variant. */
7932 mod_type_die = lookup_type_die (type);
7933 if (mod_type_die == NULL)
7937 /* We want to equate the qualified type to the die below. */
7938 type = qualified_type;
7942 equate_type_number_to_die (type, mod_type_die);
7944 /* We must do this after the equate_type_number_to_die call, in case
7945 this is a recursive type. This ensures that the modified_type_die
7946 recursion will terminate even if the type is recursive. Recursive
7947 types are possible in Ada. */
7948 sub_die = modified_type_die (item_type,
7949 TYPE_READONLY (item_type),
7950 TYPE_VOLATILE (item_type),
7953 if (sub_die != NULL)
7954 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7956 return mod_type_die;
7959 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7960 an enumerated type. */
7963 type_is_enum (tree type)
7965 return TREE_CODE (type) == ENUMERAL_TYPE;
7968 /* Return the register number described by a given RTL node. */
7971 reg_number (rtx rtl)
7973 unsigned regno = REGNO (rtl);
7975 if (regno >= FIRST_PSEUDO_REGISTER)
7978 return DBX_REGISTER_NUMBER (regno);
7981 /* Return a location descriptor that designates a machine register or
7982 zero if there is none. */
7984 static dw_loc_descr_ref
7985 reg_loc_descriptor (rtx rtl)
7990 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7993 reg = reg_number (rtl);
7994 regs = (*targetm.dwarf_register_span) (rtl);
7996 if (HARD_REGNO_NREGS (reg, GET_MODE (rtl)) > 1
7998 return multiple_reg_loc_descriptor (rtl, regs);
8000 return one_reg_loc_descriptor (reg);
8003 /* Return a location descriptor that designates a machine register for
8004 a given hard register number. */
8006 static dw_loc_descr_ref
8007 one_reg_loc_descriptor (unsigned int regno)
8010 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8012 return new_loc_descr (DW_OP_regx, regno, 0);
8015 /* Given an RTL of a register, return a location descriptor that
8016 designates a value that spans more than one register. */
8018 static dw_loc_descr_ref
8019 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8023 dw_loc_descr_ref loc_result = NULL;
8025 reg = reg_number (rtl);
8026 nregs = HARD_REGNO_NREGS (reg, GET_MODE (rtl));
8028 /* Simple, contiguous registers. */
8029 if (regs == NULL_RTX)
8031 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8038 t = one_reg_loc_descriptor (reg);
8039 add_loc_descr (&loc_result, t);
8040 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8046 /* Now onto stupid register sets in non contiguous locations. */
8048 if (GET_CODE (regs) != PARALLEL)
8051 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8054 for (i = 0; i < XVECLEN (regs, 0); ++i)
8058 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8059 add_loc_descr (&loc_result, t);
8060 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8061 add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0));
8066 /* Return a location descriptor that designates a constant. */
8068 static dw_loc_descr_ref
8069 int_loc_descriptor (HOST_WIDE_INT i)
8071 enum dwarf_location_atom op;
8073 /* Pick the smallest representation of a constant, rather than just
8074 defaulting to the LEB encoding. */
8078 op = DW_OP_lit0 + i;
8081 else if (i <= 0xffff)
8083 else if (HOST_BITS_PER_WIDE_INT == 32
8093 else if (i >= -0x8000)
8095 else if (HOST_BITS_PER_WIDE_INT == 32
8096 || i >= -0x80000000)
8102 return new_loc_descr (op, i, 0);
8105 /* Return a location descriptor that designates a base+offset location. */
8107 static dw_loc_descr_ref
8108 based_loc_descr (unsigned int reg, long int offset)
8110 dw_loc_descr_ref loc_result;
8111 /* For the "frame base", we use the frame pointer or stack pointer
8112 registers, since the RTL for local variables is relative to one of
8114 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
8115 ? HARD_FRAME_POINTER_REGNUM
8116 : STACK_POINTER_REGNUM);
8119 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
8121 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
8123 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
8128 /* Return true if this RTL expression describes a base+offset calculation. */
8131 is_based_loc (rtx rtl)
8133 return (GET_CODE (rtl) == PLUS
8134 && ((GET_CODE (XEXP (rtl, 0)) == REG
8135 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8136 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8139 /* The following routine converts the RTL for a variable or parameter
8140 (resident in memory) into an equivalent Dwarf representation of a
8141 mechanism for getting the address of that same variable onto the top of a
8142 hypothetical "address evaluation" stack.
8144 When creating memory location descriptors, we are effectively transforming
8145 the RTL for a memory-resident object into its Dwarf postfix expression
8146 equivalent. This routine recursively descends an RTL tree, turning
8147 it into Dwarf postfix code as it goes.
8149 MODE is the mode of the memory reference, needed to handle some
8150 autoincrement addressing modes.
8152 Return 0 if we can't represent the location. */
8154 static dw_loc_descr_ref
8155 mem_loc_descriptor (rtx rtl, enum machine_mode mode)
8157 dw_loc_descr_ref mem_loc_result = NULL;
8159 /* Note that for a dynamically sized array, the location we will generate a
8160 description of here will be the lowest numbered location which is
8161 actually within the array. That's *not* necessarily the same as the
8162 zeroth element of the array. */
8164 rtl = (*targetm.delegitimize_address) (rtl);
8166 switch (GET_CODE (rtl))
8171 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8172 just fall into the SUBREG code. */
8174 /* ... fall through ... */
8177 /* The case of a subreg may arise when we have a local (register)
8178 variable or a formal (register) parameter which doesn't quite fill
8179 up an entire register. For now, just assume that it is
8180 legitimate to make the Dwarf info refer to the whole register which
8181 contains the given subreg. */
8182 rtl = SUBREG_REG (rtl);
8184 /* ... fall through ... */
8187 /* Whenever a register number forms a part of the description of the
8188 method for calculating the (dynamic) address of a memory resident
8189 object, DWARF rules require the register number be referred to as
8190 a "base register". This distinction is not based in any way upon
8191 what category of register the hardware believes the given register
8192 belongs to. This is strictly DWARF terminology we're dealing with
8193 here. Note that in cases where the location of a memory-resident
8194 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8195 OP_CONST (0)) the actual DWARF location descriptor that we generate
8196 may just be OP_BASEREG (basereg). This may look deceptively like
8197 the object in question was allocated to a register (rather than in
8198 memory) so DWARF consumers need to be aware of the subtle
8199 distinction between OP_REG and OP_BASEREG. */
8200 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8201 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
8205 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8206 if (mem_loc_result != 0)
8207 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8211 rtl = XEXP (rtl, 1);
8213 /* ... fall through ... */
8216 /* Some ports can transform a symbol ref into a label ref, because
8217 the symbol ref is too far away and has to be dumped into a constant
8221 /* Alternatively, the symbol in the constant pool might be referenced
8222 by a different symbol. */
8223 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8226 rtx tmp = get_pool_constant_mark (rtl, &marked);
8228 if (GET_CODE (tmp) == SYMBOL_REF)
8231 if (CONSTANT_POOL_ADDRESS_P (tmp))
8232 get_pool_constant_mark (tmp, &marked);
8237 /* If all references to this pool constant were optimized away,
8238 it was not output and thus we can't represent it.
8239 FIXME: might try to use DW_OP_const_value here, though
8240 DW_OP_piece complicates it. */
8245 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8246 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8247 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8248 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8252 /* Extract the PLUS expression nested inside and fall into
8254 rtl = XEXP (rtl, 1);
8259 /* Turn these into a PLUS expression and fall into the PLUS code
8261 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8262 GEN_INT (GET_CODE (rtl) == PRE_INC
8263 ? GET_MODE_UNIT_SIZE (mode)
8264 : -GET_MODE_UNIT_SIZE (mode)));
8266 /* ... fall through ... */
8270 if (is_based_loc (rtl))
8271 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
8272 INTVAL (XEXP (rtl, 1)));
8275 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
8276 if (mem_loc_result == 0)
8279 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8280 && INTVAL (XEXP (rtl, 1)) >= 0)
8281 add_loc_descr (&mem_loc_result,
8282 new_loc_descr (DW_OP_plus_uconst,
8283 INTVAL (XEXP (rtl, 1)), 0));
8286 add_loc_descr (&mem_loc_result,
8287 mem_loc_descriptor (XEXP (rtl, 1), mode));
8288 add_loc_descr (&mem_loc_result,
8289 new_loc_descr (DW_OP_plus, 0, 0));
8296 /* If a pseudo-reg is optimized away, it is possible for it to
8297 be replaced with a MEM containing a multiply. */
8298 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
8299 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
8301 if (op0 == 0 || op1 == 0)
8304 mem_loc_result = op0;
8305 add_loc_descr (&mem_loc_result, op1);
8306 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
8311 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8315 /* If this is a MEM, return its address. Otherwise, we can't
8317 if (GET_CODE (XEXP (rtl, 0)) == MEM)
8318 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
8326 return mem_loc_result;
8329 /* Return a descriptor that describes the concatenation of two locations.
8330 This is typically a complex variable. */
8332 static dw_loc_descr_ref
8333 concat_loc_descriptor (rtx x0, rtx x1)
8335 dw_loc_descr_ref cc_loc_result = NULL;
8336 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
8337 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
8339 if (x0_ref == 0 || x1_ref == 0)
8342 cc_loc_result = x0_ref;
8343 add_loc_descr (&cc_loc_result,
8344 new_loc_descr (DW_OP_piece,
8345 GET_MODE_SIZE (GET_MODE (x0)), 0));
8347 add_loc_descr (&cc_loc_result, x1_ref);
8348 add_loc_descr (&cc_loc_result,
8349 new_loc_descr (DW_OP_piece,
8350 GET_MODE_SIZE (GET_MODE (x1)), 0));
8352 return cc_loc_result;
8355 /* Output a proper Dwarf location descriptor for a variable or parameter
8356 which is either allocated in a register or in a memory location. For a
8357 register, we just generate an OP_REG and the register number. For a
8358 memory location we provide a Dwarf postfix expression describing how to
8359 generate the (dynamic) address of the object onto the address stack.
8361 If we don't know how to describe it, return 0. */
8363 static dw_loc_descr_ref
8364 loc_descriptor (rtx rtl)
8366 dw_loc_descr_ref loc_result = NULL;
8368 switch (GET_CODE (rtl))
8371 /* The case of a subreg may arise when we have a local (register)
8372 variable or a formal (register) parameter which doesn't quite fill
8373 up an entire register. For now, just assume that it is
8374 legitimate to make the Dwarf info refer to the whole register which
8375 contains the given subreg. */
8376 rtl = SUBREG_REG (rtl);
8378 /* ... fall through ... */
8381 loc_result = reg_loc_descriptor (rtl);
8385 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8389 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8399 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8400 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8401 looking for an address. Otherwise, we return a value. If we can't make a
8402 descriptor, return 0. */
8404 static dw_loc_descr_ref
8405 loc_descriptor_from_tree (tree loc, int addressp)
8407 dw_loc_descr_ref ret, ret1;
8409 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8410 enum dwarf_location_atom op;
8412 /* ??? Most of the time we do not take proper care for sign/zero
8413 extending the values properly. Hopefully this won't be a real
8416 switch (TREE_CODE (loc))
8421 case WITH_RECORD_EXPR:
8422 case PLACEHOLDER_EXPR:
8423 /* This case involves extracting fields from an object to determine the
8424 position of other fields. We don't try to encode this here. The
8425 only user of this is Ada, which encodes the needed information using
8426 the names of types. */
8433 /* We can support this only if we can look through conversions and
8434 find an INDIRECT_EXPR. */
8435 for (loc = TREE_OPERAND (loc, 0);
8436 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8437 || TREE_CODE (loc) == NON_LVALUE_EXPR
8438 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8439 || TREE_CODE (loc) == SAVE_EXPR;
8440 loc = TREE_OPERAND (loc, 0))
8443 return (TREE_CODE (loc) == INDIRECT_REF
8444 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8448 if (DECL_THREAD_LOCAL (loc))
8452 #ifndef ASM_OUTPUT_DWARF_DTPREL
8453 /* If this is not defined, we have no way to emit the data. */
8457 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8458 look up addresses of objects in the current module. */
8459 if (DECL_EXTERNAL (loc))
8462 rtl = rtl_for_decl_location (loc);
8463 if (rtl == NULL_RTX)
8466 if (GET_CODE (rtl) != MEM)
8468 rtl = XEXP (rtl, 0);
8469 if (! CONSTANT_P (rtl))
8472 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8473 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8474 ret->dw_loc_oprnd1.v.val_addr = rtl;
8476 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8477 add_loc_descr (&ret, ret1);
8486 rtx rtl = rtl_for_decl_location (loc);
8488 if (rtl == NULL_RTX)
8490 else if (CONSTANT_P (rtl))
8492 ret = new_loc_descr (DW_OP_addr, 0, 0);
8493 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8494 ret->dw_loc_oprnd1.v.val_addr = rtl;
8499 enum machine_mode mode = GET_MODE (rtl);
8501 if (GET_CODE (rtl) == MEM)
8504 rtl = XEXP (rtl, 0);
8507 ret = mem_loc_descriptor (rtl, mode);
8513 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8518 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8522 case NON_LVALUE_EXPR:
8523 case VIEW_CONVERT_EXPR:
8526 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8531 case ARRAY_RANGE_REF:
8534 HOST_WIDE_INT bitsize, bitpos, bytepos;
8535 enum machine_mode mode;
8538 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8539 &unsignedp, &volatilep);
8544 ret = loc_descriptor_from_tree (obj, 1);
8546 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8549 if (offset != NULL_TREE)
8551 /* Variable offset. */
8552 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8553 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8559 bytepos = bitpos / BITS_PER_UNIT;
8561 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8562 else if (bytepos < 0)
8564 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8565 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8571 if (host_integerp (loc, 0))
8572 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8579 /* Get an RTL for this, if something has been emitted. */
8580 rtx rtl = lookup_constant_def (loc);
8581 enum machine_mode mode;
8583 if (GET_CODE (rtl) != MEM)
8585 mode = GET_MODE (rtl);
8586 rtl = XEXP (rtl, 0);
8588 rtl = (*targetm.delegitimize_address) (rtl);
8591 ret = mem_loc_descriptor (rtl, mode);
8595 case TRUTH_AND_EXPR:
8596 case TRUTH_ANDIF_EXPR:
8601 case TRUTH_XOR_EXPR:
8607 case TRUTH_ORIF_EXPR:
8612 case FLOOR_DIV_EXPR:
8614 case ROUND_DIV_EXPR:
8615 case TRUNC_DIV_EXPR:
8623 case FLOOR_MOD_EXPR:
8625 case ROUND_MOD_EXPR:
8626 case TRUNC_MOD_EXPR:
8639 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8643 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8644 && host_integerp (TREE_OPERAND (loc, 1), 0))
8646 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8650 add_loc_descr (&ret,
8651 new_loc_descr (DW_OP_plus_uconst,
8652 tree_low_cst (TREE_OPERAND (loc, 1),
8662 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8669 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8676 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8683 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8698 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8699 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8700 if (ret == 0 || ret1 == 0)
8703 add_loc_descr (&ret, ret1);
8704 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8707 case TRUTH_NOT_EXPR:
8721 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8725 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8729 loc = build (COND_EXPR, TREE_TYPE (loc),
8730 build (LT_EXPR, integer_type_node,
8731 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8732 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8734 /* ... fall through ... */
8738 dw_loc_descr_ref lhs
8739 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8740 dw_loc_descr_ref rhs
8741 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8742 dw_loc_descr_ref bra_node, jump_node, tmp;
8744 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8745 if (ret == 0 || lhs == 0 || rhs == 0)
8748 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8749 add_loc_descr (&ret, bra_node);
8751 add_loc_descr (&ret, rhs);
8752 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8753 add_loc_descr (&ret, jump_node);
8755 add_loc_descr (&ret, lhs);
8756 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8757 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8759 /* ??? Need a node to point the skip at. Use a nop. */
8760 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8761 add_loc_descr (&ret, tmp);
8762 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8763 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8768 /* Leave front-end specific codes as simply unknown. This comes
8769 up, for instance, with the C STMT_EXPR. */
8770 if ((unsigned int) TREE_CODE (loc)
8771 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
8774 /* Otherwise this is a generic code; we should just lists all of
8775 these explicitly. Aborting means we forgot one. */
8779 /* Show if we can't fill the request for an address. */
8780 if (addressp && indirect_p == 0)
8783 /* If we've got an address and don't want one, dereference. */
8784 if (!addressp && indirect_p > 0)
8786 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8788 if (size > DWARF2_ADDR_SIZE || size == -1)
8790 else if (size == DWARF2_ADDR_SIZE)
8793 op = DW_OP_deref_size;
8795 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8801 /* Given a value, round it up to the lowest multiple of `boundary'
8802 which is not less than the value itself. */
8804 static inline HOST_WIDE_INT
8805 ceiling (HOST_WIDE_INT value, unsigned int boundary)
8807 return (((value + boundary - 1) / boundary) * boundary);
8810 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8811 pointer to the declared type for the relevant field variable, or return
8812 `integer_type_node' if the given node turns out to be an
8816 field_type (tree decl)
8820 if (TREE_CODE (decl) == ERROR_MARK)
8821 return integer_type_node;
8823 type = DECL_BIT_FIELD_TYPE (decl);
8824 if (type == NULL_TREE)
8825 type = TREE_TYPE (decl);
8830 /* Given a pointer to a tree node, return the alignment in bits for
8831 it, or else return BITS_PER_WORD if the node actually turns out to
8832 be an ERROR_MARK node. */
8834 static inline unsigned
8835 simple_type_align_in_bits (tree type)
8837 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8840 static inline unsigned
8841 simple_decl_align_in_bits (tree decl)
8843 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8846 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8847 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8848 or return 0 if we are unable to determine what that offset is, either
8849 because the argument turns out to be a pointer to an ERROR_MARK node, or
8850 because the offset is actually variable. (We can't handle the latter case
8853 static HOST_WIDE_INT
8854 field_byte_offset (tree decl)
8856 unsigned int type_align_in_bits;
8857 unsigned int decl_align_in_bits;
8858 unsigned HOST_WIDE_INT type_size_in_bits;
8859 HOST_WIDE_INT object_offset_in_bits;
8861 tree field_size_tree;
8862 HOST_WIDE_INT bitpos_int;
8863 HOST_WIDE_INT deepest_bitpos;
8864 unsigned HOST_WIDE_INT field_size_in_bits;
8866 if (TREE_CODE (decl) == ERROR_MARK)
8868 else if (TREE_CODE (decl) != FIELD_DECL)
8871 type = field_type (decl);
8872 field_size_tree = DECL_SIZE (decl);
8874 /* The size could be unspecified if there was an error, or for
8875 a flexible array member. */
8876 if (! field_size_tree)
8877 field_size_tree = bitsize_zero_node;
8879 /* We cannot yet cope with fields whose positions are variable, so
8880 for now, when we see such things, we simply return 0. Someday, we may
8881 be able to handle such cases, but it will be damn difficult. */
8882 if (! host_integerp (bit_position (decl), 0))
8885 bitpos_int = int_bit_position (decl);
8887 /* If we don't know the size of the field, pretend it's a full word. */
8888 if (host_integerp (field_size_tree, 1))
8889 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8891 field_size_in_bits = BITS_PER_WORD;
8893 type_size_in_bits = simple_type_size_in_bits (type);
8894 type_align_in_bits = simple_type_align_in_bits (type);
8895 decl_align_in_bits = simple_decl_align_in_bits (decl);
8897 /* The GCC front-end doesn't make any attempt to keep track of the starting
8898 bit offset (relative to the start of the containing structure type) of the
8899 hypothetical "containing object" for a bit-field. Thus, when computing
8900 the byte offset value for the start of the "containing object" of a
8901 bit-field, we must deduce this information on our own. This can be rather
8902 tricky to do in some cases. For example, handling the following structure
8903 type definition when compiling for an i386/i486 target (which only aligns
8904 long long's to 32-bit boundaries) can be very tricky:
8906 struct S { int field1; long long field2:31; };
8908 Fortunately, there is a simple rule-of-thumb which can be used in such
8909 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8910 structure shown above. It decides to do this based upon one simple rule
8911 for bit-field allocation. GCC allocates each "containing object" for each
8912 bit-field at the first (i.e. lowest addressed) legitimate alignment
8913 boundary (based upon the required minimum alignment for the declared type
8914 of the field) which it can possibly use, subject to the condition that
8915 there is still enough available space remaining in the containing object
8916 (when allocated at the selected point) to fully accommodate all of the
8917 bits of the bit-field itself.
8919 This simple rule makes it obvious why GCC allocates 8 bytes for each
8920 object of the structure type shown above. When looking for a place to
8921 allocate the "containing object" for `field2', the compiler simply tries
8922 to allocate a 64-bit "containing object" at each successive 32-bit
8923 boundary (starting at zero) until it finds a place to allocate that 64-
8924 bit field such that at least 31 contiguous (and previously unallocated)
8925 bits remain within that selected 64 bit field. (As it turns out, for the
8926 example above, the compiler finds it is OK to allocate the "containing
8927 object" 64-bit field at bit-offset zero within the structure type.)
8929 Here we attempt to work backwards from the limited set of facts we're
8930 given, and we try to deduce from those facts, where GCC must have believed
8931 that the containing object started (within the structure type). The value
8932 we deduce is then used (by the callers of this routine) to generate
8933 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8934 and, in the case of DW_AT_location, regular fields as well). */
8936 /* Figure out the bit-distance from the start of the structure to the
8937 "deepest" bit of the bit-field. */
8938 deepest_bitpos = bitpos_int + field_size_in_bits;
8940 /* This is the tricky part. Use some fancy footwork to deduce where the
8941 lowest addressed bit of the containing object must be. */
8942 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8944 /* Round up to type_align by default. This works best for bitfields. */
8945 object_offset_in_bits += type_align_in_bits - 1;
8946 object_offset_in_bits /= type_align_in_bits;
8947 object_offset_in_bits *= type_align_in_bits;
8949 if (object_offset_in_bits > bitpos_int)
8951 /* Sigh, the decl must be packed. */
8952 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8954 /* Round up to decl_align instead. */
8955 object_offset_in_bits += decl_align_in_bits - 1;
8956 object_offset_in_bits /= decl_align_in_bits;
8957 object_offset_in_bits *= decl_align_in_bits;
8960 return object_offset_in_bits / BITS_PER_UNIT;
8963 /* The following routines define various Dwarf attributes and any data
8964 associated with them. */
8966 /* Add a location description attribute value to a DIE.
8968 This emits location attributes suitable for whole variables and
8969 whole parameters. Note that the location attributes for struct fields are
8970 generated by the routine `data_member_location_attribute' below. */
8973 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
8974 dw_loc_descr_ref descr)
8977 add_AT_loc (die, attr_kind, descr);
8980 /* Attach the specialized form of location attribute used for data members of
8981 struct and union types. In the special case of a FIELD_DECL node which
8982 represents a bit-field, the "offset" part of this special location
8983 descriptor must indicate the distance in bytes from the lowest-addressed
8984 byte of the containing struct or union type to the lowest-addressed byte of
8985 the "containing object" for the bit-field. (See the `field_byte_offset'
8988 For any given bit-field, the "containing object" is a hypothetical object
8989 (of some integral or enum type) within which the given bit-field lives. The
8990 type of this hypothetical "containing object" is always the same as the
8991 declared type of the individual bit-field itself (for GCC anyway... the
8992 DWARF spec doesn't actually mandate this). Note that it is the size (in
8993 bytes) of the hypothetical "containing object" which will be given in the
8994 DW_AT_byte_size attribute for this bit-field. (See the
8995 `byte_size_attribute' function below.) It is also used when calculating the
8996 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9000 add_data_member_location_attribute (dw_die_ref die, tree decl)
9003 dw_loc_descr_ref loc_descr = 0;
9005 if (TREE_CODE (decl) == TREE_VEC)
9007 /* We're working on the TAG_inheritance for a base class. */
9008 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
9010 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9011 aren't at a fixed offset from all (sub)objects of the same
9012 type. We need to extract the appropriate offset from our
9013 vtable. The following dwarf expression means
9015 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9017 This is specific to the V3 ABI, of course. */
9019 dw_loc_descr_ref tmp;
9021 /* Make a copy of the object address. */
9022 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9023 add_loc_descr (&loc_descr, tmp);
9025 /* Extract the vtable address. */
9026 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9027 add_loc_descr (&loc_descr, tmp);
9029 /* Calculate the address of the offset. */
9030 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9034 tmp = int_loc_descriptor (-offset);
9035 add_loc_descr (&loc_descr, tmp);
9036 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9037 add_loc_descr (&loc_descr, tmp);
9039 /* Extract the offset. */
9040 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9041 add_loc_descr (&loc_descr, tmp);
9043 /* Add it to the object address. */
9044 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9045 add_loc_descr (&loc_descr, tmp);
9048 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9051 offset = field_byte_offset (decl);
9055 enum dwarf_location_atom op;
9057 /* The DWARF2 standard says that we should assume that the structure
9058 address is already on the stack, so we can specify a structure field
9059 address by using DW_OP_plus_uconst. */
9061 #ifdef MIPS_DEBUGGING_INFO
9062 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9063 operator correctly. It works only if we leave the offset on the
9067 op = DW_OP_plus_uconst;
9070 loc_descr = new_loc_descr (op, offset, 0);
9073 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9076 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9077 does not have a "location" either in memory or in a register. These
9078 things can arise in GNU C when a constant is passed as an actual parameter
9079 to an inlined function. They can also arise in C++ where declared
9080 constants do not necessarily get memory "homes". */
9083 add_const_value_attribute (dw_die_ref die, rtx rtl)
9085 switch (GET_CODE (rtl))
9088 /* Note that a CONST_INT rtx could represent either an integer
9089 or a floating-point constant. A CONST_INT is used whenever
9090 the constant will fit into a single word. In all such
9091 cases, the original mode of the constant value is wiped
9092 out, and the CONST_INT rtx is assigned VOIDmode. */
9094 HOST_WIDE_INT val = INTVAL (rtl);
9096 /* ??? We really should be using HOST_WIDE_INT throughout. */
9097 if (val < 0 && (long) val == val)
9098 add_AT_int (die, DW_AT_const_value, (long) val);
9099 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
9100 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
9103 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
9104 add_AT_long_long (die, DW_AT_const_value,
9105 val >> HOST_BITS_PER_LONG, val);
9114 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9115 floating-point constant. A CONST_DOUBLE is used whenever the
9116 constant requires more than one word in order to be adequately
9117 represented. We output CONST_DOUBLEs as blocks. */
9119 enum machine_mode mode = GET_MODE (rtl);
9121 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
9123 unsigned length = GET_MODE_SIZE (mode) / 4;
9124 long *array = ggc_alloc (sizeof (long) * length);
9127 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9128 real_to_target (array, &rv, mode);
9130 add_AT_float (die, DW_AT_const_value, length, array);
9134 /* ??? We really should be using HOST_WIDE_INT throughout. */
9135 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
9138 add_AT_long_long (die, DW_AT_const_value,
9139 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9145 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9151 add_AT_addr (die, DW_AT_const_value, rtl);
9152 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
9156 /* In cases where an inlined instance of an inline function is passed
9157 the address of an `auto' variable (which is local to the caller) we
9158 can get a situation where the DECL_RTL of the artificial local
9159 variable (for the inlining) which acts as a stand-in for the
9160 corresponding formal parameter (of the inline function) will look
9161 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9162 exactly a compile-time constant expression, but it isn't the address
9163 of the (artificial) local variable either. Rather, it represents the
9164 *value* which the artificial local variable always has during its
9165 lifetime. We currently have no way to represent such quasi-constant
9166 values in Dwarf, so for now we just punt and generate nothing. */
9170 /* No other kinds of rtx should be possible here. */
9177 rtl_for_decl_location (tree decl)
9181 /* Here we have to decide where we are going to say the parameter "lives"
9182 (as far as the debugger is concerned). We only have a couple of
9183 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9185 DECL_RTL normally indicates where the parameter lives during most of the
9186 activation of the function. If optimization is enabled however, this
9187 could be either NULL or else a pseudo-reg. Both of those cases indicate
9188 that the parameter doesn't really live anywhere (as far as the code
9189 generation parts of GCC are concerned) during most of the function's
9190 activation. That will happen (for example) if the parameter is never
9191 referenced within the function.
9193 We could just generate a location descriptor here for all non-NULL
9194 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9195 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9196 where DECL_RTL is NULL or is a pseudo-reg.
9198 Note however that we can only get away with using DECL_INCOMING_RTL as
9199 a backup substitute for DECL_RTL in certain limited cases. In cases
9200 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9201 we can be sure that the parameter was passed using the same type as it is
9202 declared to have within the function, and that its DECL_INCOMING_RTL
9203 points us to a place where a value of that type is passed.
9205 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9206 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9207 because in these cases DECL_INCOMING_RTL points us to a value of some
9208 type which is *different* from the type of the parameter itself. Thus,
9209 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9210 such cases, the debugger would end up (for example) trying to fetch a
9211 `float' from a place which actually contains the first part of a
9212 `double'. That would lead to really incorrect and confusing
9213 output at debug-time.
9215 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9216 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9217 are a couple of exceptions however. On little-endian machines we can
9218 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9219 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9220 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9221 when (on a little-endian machine) a non-prototyped function has a
9222 parameter declared to be of type `short' or `char'. In such cases,
9223 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9224 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9225 passed `int' value. If the debugger then uses that address to fetch
9226 a `short' or a `char' (on a little-endian machine) the result will be
9227 the correct data, so we allow for such exceptional cases below.
9229 Note that our goal here is to describe the place where the given formal
9230 parameter lives during most of the function's activation (i.e. between the
9231 end of the prologue and the start of the epilogue). We'll do that as best
9232 as we can. Note however that if the given formal parameter is modified
9233 sometime during the execution of the function, then a stack backtrace (at
9234 debug-time) will show the function as having been called with the *new*
9235 value rather than the value which was originally passed in. This happens
9236 rarely enough that it is not a major problem, but it *is* a problem, and
9239 A future version of dwarf2out.c may generate two additional attributes for
9240 any given DW_TAG_formal_parameter DIE which will describe the "passed
9241 type" and the "passed location" for the given formal parameter in addition
9242 to the attributes we now generate to indicate the "declared type" and the
9243 "active location" for each parameter. This additional set of attributes
9244 could be used by debuggers for stack backtraces. Separately, note that
9245 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9246 This happens (for example) for inlined-instances of inline function formal
9247 parameters which are never referenced. This really shouldn't be
9248 happening. All PARM_DECL nodes should get valid non-NULL
9249 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
9250 values for inlined instances of inline function parameters, so when we see
9251 such cases, we are just out-of-luck for the time being (until integrate.c
9254 /* Use DECL_RTL as the "location" unless we find something better. */
9255 rtl = DECL_RTL_IF_SET (decl);
9257 /* When generating abstract instances, ignore everything except
9258 constants, symbols living in memory, and symbols living in
9260 if (! reload_completed)
9263 && (CONSTANT_P (rtl)
9264 || (GET_CODE (rtl) == MEM
9265 && CONSTANT_P (XEXP (rtl, 0)))
9266 || (GET_CODE (rtl) == REG
9267 && TREE_CODE (decl) == VAR_DECL
9268 && TREE_STATIC (decl))))
9270 rtl = (*targetm.delegitimize_address) (rtl);
9275 else if (TREE_CODE (decl) == PARM_DECL)
9277 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
9279 tree declared_type = type_main_variant (TREE_TYPE (decl));
9280 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
9282 /* This decl represents a formal parameter which was optimized out.
9283 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9284 all cases where (rtl == NULL_RTX) just below. */
9285 if (declared_type == passed_type)
9286 rtl = DECL_INCOMING_RTL (decl);
9287 else if (! BYTES_BIG_ENDIAN
9288 && TREE_CODE (declared_type) == INTEGER_TYPE
9289 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
9290 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
9291 rtl = DECL_INCOMING_RTL (decl);
9294 /* If the parm was passed in registers, but lives on the stack, then
9295 make a big endian correction if the mode of the type of the
9296 parameter is not the same as the mode of the rtl. */
9297 /* ??? This is the same series of checks that are made in dbxout.c before
9298 we reach the big endian correction code there. It isn't clear if all
9299 of these checks are necessary here, but keeping them all is the safe
9301 else if (GET_CODE (rtl) == MEM
9302 && XEXP (rtl, 0) != const0_rtx
9303 && ! CONSTANT_P (XEXP (rtl, 0))
9304 /* Not passed in memory. */
9305 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
9306 /* Not passed by invisible reference. */
9307 && (GET_CODE (XEXP (rtl, 0)) != REG
9308 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
9309 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
9310 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9311 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
9314 /* Big endian correction check. */
9316 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
9317 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
9320 int offset = (UNITS_PER_WORD
9321 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
9323 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
9324 plus_constant (XEXP (rtl, 0), offset));
9328 if (rtl != NULL_RTX)
9330 rtl = eliminate_regs (rtl, 0, NULL_RTX);
9331 #ifdef LEAF_REG_REMAP
9332 if (current_function_uses_only_leaf_regs)
9333 leaf_renumber_regs_insn (rtl);
9337 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9338 and will have been substituted directly into all expressions that use it.
9339 C does not have such a concept, but C++ and other languages do. */
9340 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
9342 /* If a variable is initialized with a string constant without embedded
9343 zeros, build CONST_STRING. */
9344 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
9345 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
9347 tree arrtype = TREE_TYPE (decl);
9348 tree enttype = TREE_TYPE (arrtype);
9349 tree domain = TYPE_DOMAIN (arrtype);
9350 tree init = DECL_INITIAL (decl);
9351 enum machine_mode mode = TYPE_MODE (enttype);
9353 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9355 && integer_zerop (TYPE_MIN_VALUE (domain))
9356 && compare_tree_int (TYPE_MAX_VALUE (domain),
9357 TREE_STRING_LENGTH (init) - 1) == 0
9358 && ((size_t) TREE_STRING_LENGTH (init)
9359 == strlen (TREE_STRING_POINTER (init)) + 1))
9360 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
9362 /* If the initializer is something that we know will expand into an
9363 immediate RTL constant, expand it now. Expanding anything else
9364 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9365 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
9366 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
9368 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
9369 EXPAND_INITIALIZER);
9370 /* If expand_expr returns a MEM, it wasn't immediate. */
9371 if (rtl && GET_CODE (rtl) == MEM)
9377 rtl = (*targetm.delegitimize_address) (rtl);
9379 /* If we don't look past the constant pool, we risk emitting a
9380 reference to a constant pool entry that isn't referenced from
9381 code, and thus is not emitted. */
9383 rtl = avoid_constant_pool_reference (rtl);
9388 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9389 data attribute for a variable or a parameter. We generate the
9390 DW_AT_const_value attribute only in those cases where the given variable
9391 or parameter does not have a true "location" either in memory or in a
9392 register. This can happen (for example) when a constant is passed as an
9393 actual argument in a call to an inline function. (It's possible that
9394 these things can crop up in other ways also.) Note that one type of
9395 constant value which can be passed into an inlined function is a constant
9396 pointer. This can happen for example if an actual argument in an inlined
9397 function call evaluates to a compile-time constant address. */
9400 add_location_or_const_value_attribute (dw_die_ref die, tree decl)
9403 dw_loc_descr_ref descr;
9405 if (TREE_CODE (decl) == ERROR_MARK)
9407 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9410 rtl = rtl_for_decl_location (decl);
9411 if (rtl == NULL_RTX)
9414 switch (GET_CODE (rtl))
9417 /* The address of a variable that was optimized away;
9418 don't emit anything. */
9428 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9429 add_const_value_attribute (die, rtl);
9433 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
9435 /* Need loc_descriptor_from_tree since that's where we know
9436 how to handle TLS variables. Want the object's address
9437 since the top-level DW_AT_location assumes such. See
9438 the confusion in loc_descriptor for reference. */
9439 descr = loc_descriptor_from_tree (decl, 1);
9446 descr = loc_descriptor (rtl);
9448 add_AT_location_description (die, DW_AT_location, descr);
9456 /* If we don't have a copy of this variable in memory for some reason (such
9457 as a C++ member constant that doesn't have an out-of-line definition),
9458 we should tell the debugger about the constant value. */
9461 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
9463 tree init = DECL_INITIAL (decl);
9464 tree type = TREE_TYPE (decl);
9466 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9467 && initializer_constant_valid_p (init, type) == null_pointer_node)
9472 switch (TREE_CODE (type))
9475 if (host_integerp (init, 0))
9476 add_AT_unsigned (var_die, DW_AT_const_value,
9477 tree_low_cst (init, 0));
9479 add_AT_long_long (var_die, DW_AT_const_value,
9480 TREE_INT_CST_HIGH (init),
9481 TREE_INT_CST_LOW (init));
9488 /* Generate a DW_AT_name attribute given some string value to be included as
9489 the value of the attribute. */
9492 add_name_attribute (dw_die_ref die, const char *name_string)
9494 if (name_string != NULL && *name_string != 0)
9496 if (demangle_name_func)
9497 name_string = (*demangle_name_func) (name_string);
9499 add_AT_string (die, DW_AT_name, name_string);
9503 /* Generate a DW_AT_comp_dir attribute for DIE. */
9506 add_comp_dir_attribute (dw_die_ref die)
9508 const char *wd = get_src_pwd ();
9510 add_AT_string (die, DW_AT_comp_dir, wd);
9513 /* Given a tree node describing an array bound (either lower or upper) output
9514 a representation for that bound. */
9517 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
9519 switch (TREE_CODE (bound))
9524 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9526 if (! host_integerp (bound, 0)
9527 || (bound_attr == DW_AT_lower_bound
9528 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9529 || (is_fortran () && integer_onep (bound)))))
9530 /* use the default */
9533 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9538 case NON_LVALUE_EXPR:
9539 case VIEW_CONVERT_EXPR:
9540 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9544 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9545 access the upper bound values may be bogus. If they refer to a
9546 register, they may only describe how to get at these values at the
9547 points in the generated code right after they have just been
9548 computed. Worse yet, in the typical case, the upper bound values
9549 will not even *be* computed in the optimized code (though the
9550 number of elements will), so these SAVE_EXPRs are entirely
9551 bogus. In order to compensate for this fact, we check here to see
9552 if optimization is enabled, and if so, we don't add an attribute
9553 for the (unknown and unknowable) upper bound. This should not
9554 cause too much trouble for existing (stupid?) debuggers because
9555 they have to deal with empty upper bounds location descriptions
9556 anyway in order to be able to deal with incomplete array types.
9557 Of course an intelligent debugger (GDB?) should be able to
9558 comprehend that a missing upper bound specification in an array
9559 type used for a storage class `auto' local array variable
9560 indicates that the upper bound is both unknown (at compile- time)
9561 and unknowable (at run-time) due to optimization.
9563 We assume that a MEM rtx is safe because gcc wouldn't put the
9564 value there unless it was going to be used repeatedly in the
9565 function, i.e. for cleanups. */
9566 if (SAVE_EXPR_RTL (bound)
9567 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9569 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9570 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9571 rtx loc = SAVE_EXPR_RTL (bound);
9573 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9574 it references an outer function's frame. */
9575 if (GET_CODE (loc) == MEM)
9577 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9579 if (XEXP (loc, 0) != new_addr)
9580 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9583 add_AT_flag (decl_die, DW_AT_artificial, 1);
9584 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9585 add_AT_location_description (decl_die, DW_AT_location,
9586 loc_descriptor (loc));
9587 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9590 /* Else leave out the attribute. */
9596 dw_die_ref decl_die = lookup_decl_die (bound);
9598 /* ??? Can this happen, or should the variable have been bound
9599 first? Probably it can, since I imagine that we try to create
9600 the types of parameters in the order in which they exist in
9601 the list, and won't have created a forward reference to a
9603 if (decl_die != NULL)
9604 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9610 /* Otherwise try to create a stack operation procedure to
9611 evaluate the value of the array bound. */
9613 dw_die_ref ctx, decl_die;
9614 dw_loc_descr_ref loc;
9616 loc = loc_descriptor_from_tree (bound, 0);
9620 if (current_function_decl == 0)
9621 ctx = comp_unit_die;
9623 ctx = lookup_decl_die (current_function_decl);
9625 /* If we weren't able to find a context, it's most likely the case
9626 that we are processing the return type of the function. So
9627 make a SAVE_EXPR to point to it and have the limbo DIE code
9628 find the proper die. The save_expr function doesn't always
9629 make a SAVE_EXPR, so do it ourselves. */
9631 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9632 current_function_decl, NULL_TREE);
9634 decl_die = new_die (DW_TAG_variable, ctx, bound);
9635 add_AT_flag (decl_die, DW_AT_artificial, 1);
9636 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9637 add_AT_loc (decl_die, DW_AT_location, loc);
9639 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9645 /* Note that the block of subscript information for an array type also
9646 includes information about the element type of type given array type. */
9649 add_subscript_info (dw_die_ref type_die, tree type)
9651 #ifndef MIPS_DEBUGGING_INFO
9652 unsigned dimension_number;
9655 dw_die_ref subrange_die;
9657 /* The GNU compilers represent multidimensional array types as sequences of
9658 one dimensional array types whose element types are themselves array
9659 types. Here we squish that down, so that each multidimensional array
9660 type gets only one array_type DIE in the Dwarf debugging info. The draft
9661 Dwarf specification say that we are allowed to do this kind of
9662 compression in C (because there is no difference between an array or
9663 arrays and a multidimensional array in C) but for other source languages
9664 (e.g. Ada) we probably shouldn't do this. */
9666 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9667 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9668 We work around this by disabling this feature. See also
9669 gen_array_type_die. */
9670 #ifndef MIPS_DEBUGGING_INFO
9671 for (dimension_number = 0;
9672 TREE_CODE (type) == ARRAY_TYPE;
9673 type = TREE_TYPE (type), dimension_number++)
9676 tree domain = TYPE_DOMAIN (type);
9678 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9679 and (in GNU C only) variable bounds. Handle all three forms
9681 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9684 /* We have an array type with specified bounds. */
9685 lower = TYPE_MIN_VALUE (domain);
9686 upper = TYPE_MAX_VALUE (domain);
9688 /* Define the index type. */
9689 if (TREE_TYPE (domain))
9691 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9692 TREE_TYPE field. We can't emit debug info for this
9693 because it is an unnamed integral type. */
9694 if (TREE_CODE (domain) == INTEGER_TYPE
9695 && TYPE_NAME (domain) == NULL_TREE
9696 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9697 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9700 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9704 /* ??? If upper is NULL, the array has unspecified length,
9705 but it does have a lower bound. This happens with Fortran
9707 Since the debugger is definitely going to need to know N
9708 to produce useful results, go ahead and output the lower
9709 bound solo, and hope the debugger can cope. */
9711 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9713 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9716 /* Otherwise we have an array type with an unspecified length. The
9717 DWARF-2 spec does not say how to handle this; let's just leave out the
9723 add_byte_size_attribute (dw_die_ref die, tree tree_node)
9727 switch (TREE_CODE (tree_node))
9735 case QUAL_UNION_TYPE:
9736 size = int_size_in_bytes (tree_node);
9739 /* For a data member of a struct or union, the DW_AT_byte_size is
9740 generally given as the number of bytes normally allocated for an
9741 object of the *declared* type of the member itself. This is true
9742 even for bit-fields. */
9743 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9749 /* Note that `size' might be -1 when we get to this point. If it is, that
9750 indicates that the byte size of the entity in question is variable. We
9751 have no good way of expressing this fact in Dwarf at the present time,
9752 so just let the -1 pass on through. */
9753 add_AT_unsigned (die, DW_AT_byte_size, size);
9756 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9757 which specifies the distance in bits from the highest order bit of the
9758 "containing object" for the bit-field to the highest order bit of the
9761 For any given bit-field, the "containing object" is a hypothetical object
9762 (of some integral or enum type) within which the given bit-field lives. The
9763 type of this hypothetical "containing object" is always the same as the
9764 declared type of the individual bit-field itself. The determination of the
9765 exact location of the "containing object" for a bit-field is rather
9766 complicated. It's handled by the `field_byte_offset' function (above).
9768 Note that it is the size (in bytes) of the hypothetical "containing object"
9769 which will be given in the DW_AT_byte_size attribute for this bit-field.
9770 (See `byte_size_attribute' above). */
9773 add_bit_offset_attribute (dw_die_ref die, tree decl)
9775 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9776 tree type = DECL_BIT_FIELD_TYPE (decl);
9777 HOST_WIDE_INT bitpos_int;
9778 HOST_WIDE_INT highest_order_object_bit_offset;
9779 HOST_WIDE_INT highest_order_field_bit_offset;
9780 HOST_WIDE_INT unsigned bit_offset;
9782 /* Must be a field and a bit field. */
9784 || TREE_CODE (decl) != FIELD_DECL)
9787 /* We can't yet handle bit-fields whose offsets are variable, so if we
9788 encounter such things, just return without generating any attribute
9789 whatsoever. Likewise for variable or too large size. */
9790 if (! host_integerp (bit_position (decl), 0)
9791 || ! host_integerp (DECL_SIZE (decl), 1))
9794 bitpos_int = int_bit_position (decl);
9796 /* Note that the bit offset is always the distance (in bits) from the
9797 highest-order bit of the "containing object" to the highest-order bit of
9798 the bit-field itself. Since the "high-order end" of any object or field
9799 is different on big-endian and little-endian machines, the computation
9800 below must take account of these differences. */
9801 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9802 highest_order_field_bit_offset = bitpos_int;
9804 if (! BYTES_BIG_ENDIAN)
9806 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9807 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9811 = (! BYTES_BIG_ENDIAN
9812 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9813 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9815 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9818 /* For a FIELD_DECL node which represents a bit field, output an attribute
9819 which specifies the length in bits of the given field. */
9822 add_bit_size_attribute (dw_die_ref die, tree decl)
9824 /* Must be a field and a bit field. */
9825 if (TREE_CODE (decl) != FIELD_DECL
9826 || ! DECL_BIT_FIELD_TYPE (decl))
9829 if (host_integerp (DECL_SIZE (decl), 1))
9830 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9833 /* If the compiled language is ANSI C, then add a 'prototyped'
9834 attribute, if arg types are given for the parameters of a function. */
9837 add_prototyped_attribute (dw_die_ref die, tree func_type)
9839 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9840 && TYPE_ARG_TYPES (func_type) != NULL)
9841 add_AT_flag (die, DW_AT_prototyped, 1);
9844 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9845 by looking in either the type declaration or object declaration
9849 add_abstract_origin_attribute (dw_die_ref die, tree origin)
9851 dw_die_ref origin_die = NULL;
9853 if (TREE_CODE (origin) != FUNCTION_DECL)
9855 /* We may have gotten separated from the block for the inlined
9856 function, if we're in an exception handler or some such; make
9857 sure that the abstract function has been written out.
9859 Doing this for nested functions is wrong, however; functions are
9860 distinct units, and our context might not even be inline. */
9864 fn = TYPE_STUB_DECL (fn);
9866 fn = decl_function_context (fn);
9868 dwarf2out_abstract_function (fn);
9871 if (DECL_P (origin))
9872 origin_die = lookup_decl_die (origin);
9873 else if (TYPE_P (origin))
9874 origin_die = lookup_type_die (origin);
9876 if (origin_die == NULL)
9879 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9882 /* We do not currently support the pure_virtual attribute. */
9885 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
9887 if (DECL_VINDEX (func_decl))
9889 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9891 if (host_integerp (DECL_VINDEX (func_decl), 0))
9892 add_AT_loc (die, DW_AT_vtable_elem_location,
9893 new_loc_descr (DW_OP_constu,
9894 tree_low_cst (DECL_VINDEX (func_decl), 0),
9897 /* GNU extension: Record what type this method came from originally. */
9898 if (debug_info_level > DINFO_LEVEL_TERSE)
9899 add_AT_die_ref (die, DW_AT_containing_type,
9900 lookup_type_die (DECL_CONTEXT (func_decl)));
9904 /* Add source coordinate attributes for the given decl. */
9907 add_src_coords_attributes (dw_die_ref die, tree decl)
9909 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9911 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9912 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9915 /* Add a DW_AT_name attribute and source coordinate attribute for the
9916 given decl, but only if it actually has a name. */
9919 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
9923 decl_name = DECL_NAME (decl);
9924 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9926 add_name_attribute (die, dwarf2_name (decl, 0));
9927 if (! DECL_ARTIFICIAL (decl))
9928 add_src_coords_attributes (die, decl);
9930 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9931 && TREE_PUBLIC (decl)
9932 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9933 && !DECL_ABSTRACT (decl))
9934 add_AT_string (die, DW_AT_MIPS_linkage_name,
9935 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9938 #ifdef VMS_DEBUGGING_INFO
9939 /* Get the function's name, as described by its RTL. This may be different
9940 from the DECL_NAME name used in the source file. */
9941 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9943 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9944 XEXP (DECL_RTL (decl), 0));
9945 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9950 /* Push a new declaration scope. */
9953 push_decl_scope (tree scope)
9955 VARRAY_PUSH_TREE (decl_scope_table, scope);
9958 /* Pop a declaration scope. */
9961 pop_decl_scope (void)
9963 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9966 VARRAY_POP (decl_scope_table);
9969 /* Return the DIE for the scope that immediately contains this type.
9970 Non-named types get global scope. Named types nested in other
9971 types get their containing scope if it's open, or global scope
9972 otherwise. All other types (i.e. function-local named types) get
9973 the current active scope. */
9976 scope_die_for (tree t, dw_die_ref context_die)
9978 dw_die_ref scope_die = NULL;
9979 tree containing_scope;
9982 /* Non-types always go in the current scope. */
9986 containing_scope = TYPE_CONTEXT (t);
9988 /* Ignore namespaces for the moment. */
9989 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9990 containing_scope = NULL_TREE;
9992 /* Ignore function type "scopes" from the C frontend. They mean that
9993 a tagged type is local to a parmlist of a function declarator, but
9994 that isn't useful to DWARF. */
9995 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9996 containing_scope = NULL_TREE;
9998 if (containing_scope == NULL_TREE)
9999 scope_die = comp_unit_die;
10000 else if (TYPE_P (containing_scope))
10002 /* For types, we can just look up the appropriate DIE. But
10003 first we check to see if we're in the middle of emitting it
10004 so we know where the new DIE should go. */
10005 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
10006 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
10011 if (debug_info_level > DINFO_LEVEL_TERSE
10012 && !TREE_ASM_WRITTEN (containing_scope))
10015 /* If none of the current dies are suitable, we get file scope. */
10016 scope_die = comp_unit_die;
10019 scope_die = lookup_type_die (containing_scope);
10022 scope_die = context_die;
10027 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10030 local_scope_p (dw_die_ref context_die)
10032 for (; context_die; context_die = context_die->die_parent)
10033 if (context_die->die_tag == DW_TAG_inlined_subroutine
10034 || context_die->die_tag == DW_TAG_subprogram)
10040 /* Returns nonzero if CONTEXT_DIE is a class. */
10043 class_scope_p (dw_die_ref context_die)
10045 return (context_die
10046 && (context_die->die_tag == DW_TAG_structure_type
10047 || context_die->die_tag == DW_TAG_union_type));
10050 /* Many forms of DIEs require a "type description" attribute. This
10051 routine locates the proper "type descriptor" die for the type given
10052 by 'type', and adds a DW_AT_type attribute below the given die. */
10055 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10056 int decl_volatile, dw_die_ref context_die)
10058 enum tree_code code = TREE_CODE (type);
10059 dw_die_ref type_die = NULL;
10061 /* ??? If this type is an unnamed subrange type of an integral or
10062 floating-point type, use the inner type. This is because we have no
10063 support for unnamed types in base_type_die. This can happen if this is
10064 an Ada subrange type. Correct solution is emit a subrange type die. */
10065 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10066 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10067 type = TREE_TYPE (type), code = TREE_CODE (type);
10069 if (code == ERROR_MARK
10070 /* Handle a special case. For functions whose return type is void, we
10071 generate *no* type attribute. (Note that no object may have type
10072 `void', so this only applies to function return types). */
10073 || code == VOID_TYPE)
10076 type_die = modified_type_die (type,
10077 decl_const || TYPE_READONLY (type),
10078 decl_volatile || TYPE_VOLATILE (type),
10081 if (type_die != NULL)
10082 add_AT_die_ref (object_die, DW_AT_type, type_die);
10085 /* Given a tree pointer to a struct, class, union, or enum type node, return
10086 a pointer to the (string) tag name for the given type, or zero if the type
10087 was declared without a tag. */
10089 static const char *
10090 type_tag (tree type)
10092 const char *name = 0;
10094 if (TYPE_NAME (type) != 0)
10098 /* Find the IDENTIFIER_NODE for the type name. */
10099 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
10100 t = TYPE_NAME (type);
10102 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10103 a TYPE_DECL node, regardless of whether or not a `typedef' was
10105 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10106 && ! DECL_IGNORED_P (TYPE_NAME (type)))
10107 t = DECL_NAME (TYPE_NAME (type));
10109 /* Now get the name as a string, or invent one. */
10111 name = IDENTIFIER_POINTER (t);
10114 return (name == 0 || *name == '\0') ? 0 : name;
10117 /* Return the type associated with a data member, make a special check
10118 for bit field types. */
10121 member_declared_type (tree member)
10123 return (DECL_BIT_FIELD_TYPE (member)
10124 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
10127 /* Get the decl's label, as described by its RTL. This may be different
10128 from the DECL_NAME name used in the source file. */
10131 static const char *
10132 decl_start_label (tree decl)
10135 const char *fnname;
10137 x = DECL_RTL (decl);
10138 if (GET_CODE (x) != MEM)
10142 if (GET_CODE (x) != SYMBOL_REF)
10145 fnname = XSTR (x, 0);
10150 /* These routines generate the internal representation of the DIE's for
10151 the compilation unit. Debugging information is collected by walking
10152 the declaration trees passed in from dwarf2out_decl(). */
10155 gen_array_type_die (tree type, dw_die_ref context_die)
10157 dw_die_ref scope_die = scope_die_for (type, context_die);
10158 dw_die_ref array_die;
10161 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10162 the inner array type comes before the outer array type. Thus we must
10163 call gen_type_die before we call new_die. See below also. */
10164 #ifdef MIPS_DEBUGGING_INFO
10165 gen_type_die (TREE_TYPE (type), context_die);
10168 array_die = new_die (DW_TAG_array_type, scope_die, type);
10169 add_name_attribute (array_die, type_tag (type));
10170 equate_type_number_to_die (type, array_die);
10172 if (TREE_CODE (type) == VECTOR_TYPE)
10174 /* The frontend feeds us a representation for the vector as a struct
10175 containing an array. Pull out the array type. */
10176 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
10177 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
10181 /* We default the array ordering. SDB will probably do
10182 the right things even if DW_AT_ordering is not present. It's not even
10183 an issue until we start to get into multidimensional arrays anyway. If
10184 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10185 then we'll have to put the DW_AT_ordering attribute back in. (But if
10186 and when we find out that we need to put these in, we will only do so
10187 for multidimensional arrays. */
10188 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
10191 #ifdef MIPS_DEBUGGING_INFO
10192 /* The SGI compilers handle arrays of unknown bound by setting
10193 AT_declaration and not emitting any subrange DIEs. */
10194 if (! TYPE_DOMAIN (type))
10195 add_AT_unsigned (array_die, DW_AT_declaration, 1);
10198 add_subscript_info (array_die, type);
10200 /* Add representation of the type of the elements of this array type. */
10201 element_type = TREE_TYPE (type);
10203 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10204 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10205 We work around this by disabling this feature. See also
10206 add_subscript_info. */
10207 #ifndef MIPS_DEBUGGING_INFO
10208 while (TREE_CODE (element_type) == ARRAY_TYPE)
10209 element_type = TREE_TYPE (element_type);
10211 gen_type_die (element_type, context_die);
10214 add_type_attribute (array_die, element_type, 0, 0, context_die);
10218 gen_set_type_die (tree type, dw_die_ref context_die)
10220 dw_die_ref type_die
10221 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
10223 equate_type_number_to_die (type, type_die);
10224 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
10229 gen_entry_point_die (tree decl, dw_die_ref context_die)
10231 tree origin = decl_ultimate_origin (decl);
10232 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
10234 if (origin != NULL)
10235 add_abstract_origin_attribute (decl_die, origin);
10238 add_name_and_src_coords_attributes (decl_die, decl);
10239 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
10240 0, 0, context_die);
10243 if (DECL_ABSTRACT (decl))
10244 equate_decl_number_to_die (decl, decl_die);
10246 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
10250 /* Walk through the list of incomplete types again, trying once more to
10251 emit full debugging info for them. */
10254 retry_incomplete_types (void)
10258 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
10259 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
10262 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10265 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
10267 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
10269 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10270 be incomplete and such types are not marked. */
10271 add_abstract_origin_attribute (type_die, type);
10274 /* Generate a DIE to represent an inlined instance of a structure type. */
10277 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
10279 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
10281 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10282 be incomplete and such types are not marked. */
10283 add_abstract_origin_attribute (type_die, type);
10286 /* Generate a DIE to represent an inlined instance of a union type. */
10289 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
10291 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
10293 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10294 be incomplete and such types are not marked. */
10295 add_abstract_origin_attribute (type_die, type);
10298 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10299 include all of the information about the enumeration values also. Each
10300 enumerated type name/value is listed as a child of the enumerated type
10304 gen_enumeration_type_die (tree type, dw_die_ref context_die)
10306 dw_die_ref type_die = lookup_type_die (type);
10308 if (type_die == NULL)
10310 type_die = new_die (DW_TAG_enumeration_type,
10311 scope_die_for (type, context_die), type);
10312 equate_type_number_to_die (type, type_die);
10313 add_name_attribute (type_die, type_tag (type));
10315 else if (! TYPE_SIZE (type))
10318 remove_AT (type_die, DW_AT_declaration);
10320 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10321 given enum type is incomplete, do not generate the DW_AT_byte_size
10322 attribute or the DW_AT_element_list attribute. */
10323 if (TYPE_SIZE (type))
10327 TREE_ASM_WRITTEN (type) = 1;
10328 add_byte_size_attribute (type_die, type);
10329 if (TYPE_STUB_DECL (type) != NULL_TREE)
10330 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10332 /* If the first reference to this type was as the return type of an
10333 inline function, then it may not have a parent. Fix this now. */
10334 if (type_die->die_parent == NULL)
10335 add_child_die (scope_die_for (type, context_die), type_die);
10337 for (link = TYPE_FIELDS (type);
10338 link != NULL; link = TREE_CHAIN (link))
10340 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10342 add_name_attribute (enum_die,
10343 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10345 if (host_integerp (TREE_VALUE (link),
10346 TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (link)))))
10348 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
10349 add_AT_int (enum_die, DW_AT_const_value,
10350 tree_low_cst (TREE_VALUE (link), 0));
10352 add_AT_unsigned (enum_die, DW_AT_const_value,
10353 tree_low_cst (TREE_VALUE (link), 1));
10358 add_AT_flag (type_die, DW_AT_declaration, 1);
10361 /* Generate a DIE to represent either a real live formal parameter decl or to
10362 represent just the type of some formal parameter position in some function
10365 Note that this routine is a bit unusual because its argument may be a
10366 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10367 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10368 node. If it's the former then this function is being called to output a
10369 DIE to represent a formal parameter object (or some inlining thereof). If
10370 it's the latter, then this function is only being called to output a
10371 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10372 argument type of some subprogram type. */
10375 gen_formal_parameter_die (tree node, dw_die_ref context_die)
10377 dw_die_ref parm_die
10378 = new_die (DW_TAG_formal_parameter, context_die, node);
10381 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10384 origin = decl_ultimate_origin (node);
10385 if (origin != NULL)
10386 add_abstract_origin_attribute (parm_die, origin);
10389 add_name_and_src_coords_attributes (parm_die, node);
10390 add_type_attribute (parm_die, TREE_TYPE (node),
10391 TREE_READONLY (node),
10392 TREE_THIS_VOLATILE (node),
10394 if (DECL_ARTIFICIAL (node))
10395 add_AT_flag (parm_die, DW_AT_artificial, 1);
10398 equate_decl_number_to_die (node, parm_die);
10399 if (! DECL_ABSTRACT (node))
10400 add_location_or_const_value_attribute (parm_die, node);
10405 /* We were called with some kind of a ..._TYPE node. */
10406 add_type_attribute (parm_die, node, 0, 0, context_die);
10416 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10417 at the end of an (ANSI prototyped) formal parameters list. */
10420 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
10422 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10425 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10426 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10427 parameters as specified in some function type specification (except for
10428 those which appear as part of a function *definition*). */
10431 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
10434 tree formal_type = NULL;
10435 tree first_parm_type;
10438 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10440 arg = DECL_ARGUMENTS (function_or_method_type);
10441 function_or_method_type = TREE_TYPE (function_or_method_type);
10446 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10448 /* Make our first pass over the list of formal parameter types and output a
10449 DW_TAG_formal_parameter DIE for each one. */
10450 for (link = first_parm_type; link; )
10452 dw_die_ref parm_die;
10454 formal_type = TREE_VALUE (link);
10455 if (formal_type == void_type_node)
10458 /* Output a (nameless) DIE to represent the formal parameter itself. */
10459 parm_die = gen_formal_parameter_die (formal_type, context_die);
10460 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10461 && link == first_parm_type)
10462 || (arg && DECL_ARTIFICIAL (arg)))
10463 add_AT_flag (parm_die, DW_AT_artificial, 1);
10465 link = TREE_CHAIN (link);
10467 arg = TREE_CHAIN (arg);
10470 /* If this function type has an ellipsis, add a
10471 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10472 if (formal_type != void_type_node)
10473 gen_unspecified_parameters_die (function_or_method_type, context_die);
10475 /* Make our second (and final) pass over the list of formal parameter types
10476 and output DIEs to represent those types (as necessary). */
10477 for (link = TYPE_ARG_TYPES (function_or_method_type);
10478 link && TREE_VALUE (link);
10479 link = TREE_CHAIN (link))
10480 gen_type_die (TREE_VALUE (link), context_die);
10483 /* We want to generate the DIE for TYPE so that we can generate the
10484 die for MEMBER, which has been defined; we will need to refer back
10485 to the member declaration nested within TYPE. If we're trying to
10486 generate minimal debug info for TYPE, processing TYPE won't do the
10487 trick; we need to attach the member declaration by hand. */
10490 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
10492 gen_type_die (type, context_die);
10494 /* If we're trying to avoid duplicate debug info, we may not have
10495 emitted the member decl for this function. Emit it now. */
10496 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10497 && ! lookup_decl_die (member))
10499 if (decl_ultimate_origin (member))
10502 push_decl_scope (type);
10503 if (TREE_CODE (member) == FUNCTION_DECL)
10504 gen_subprogram_die (member, lookup_type_die (type));
10506 gen_variable_die (member, lookup_type_die (type));
10512 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10513 may later generate inlined and/or out-of-line instances of. */
10516 dwarf2out_abstract_function (tree decl)
10518 dw_die_ref old_die;
10521 int was_abstract = DECL_ABSTRACT (decl);
10523 /* Make sure we have the actual abstract inline, not a clone. */
10524 decl = DECL_ORIGIN (decl);
10526 old_die = lookup_decl_die (decl);
10527 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10528 /* We've already generated the abstract instance. */
10531 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10532 we don't get confused by DECL_ABSTRACT. */
10533 if (debug_info_level > DINFO_LEVEL_TERSE)
10535 context = decl_class_context (decl);
10537 gen_type_die_for_member
10538 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10541 /* Pretend we've just finished compiling this function. */
10542 save_fn = current_function_decl;
10543 current_function_decl = decl;
10545 set_decl_abstract_flags (decl, 1);
10546 dwarf2out_decl (decl);
10547 if (! was_abstract)
10548 set_decl_abstract_flags (decl, 0);
10550 current_function_decl = save_fn;
10553 /* Generate a DIE to represent a declared function (either file-scope or
10557 gen_subprogram_die (tree decl, dw_die_ref context_die)
10559 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10560 tree origin = decl_ultimate_origin (decl);
10561 dw_die_ref subr_die;
10565 dw_die_ref old_die = lookup_decl_die (decl);
10566 int declaration = (current_function_decl != decl
10567 || class_scope_p (context_die));
10569 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10570 started to generate the abstract instance of an inline, decided to output
10571 its containing class, and proceeded to emit the declaration of the inline
10572 from the member list for the class. If so, DECLARATION takes priority;
10573 we'll get back to the abstract instance when done with the class. */
10575 /* The class-scope declaration DIE must be the primary DIE. */
10576 if (origin && declaration && class_scope_p (context_die))
10583 if (origin != NULL)
10585 if (declaration && ! local_scope_p (context_die))
10588 /* Fixup die_parent for the abstract instance of a nested
10589 inline function. */
10590 if (old_die && old_die->die_parent == NULL)
10591 add_child_die (context_die, old_die);
10593 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10594 add_abstract_origin_attribute (subr_die, origin);
10598 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10600 if (!get_AT_flag (old_die, DW_AT_declaration)
10601 /* We can have a normal definition following an inline one in the
10602 case of redefinition of GNU C extern inlines.
10603 It seems reasonable to use AT_specification in this case. */
10604 && !get_AT_unsigned (old_die, DW_AT_inline))
10606 /* ??? This can happen if there is a bug in the program, for
10607 instance, if it has duplicate function definitions. Ideally,
10608 we should detect this case and ignore it. For now, if we have
10609 already reported an error, any error at all, then assume that
10610 we got here because of an input error, not a dwarf2 bug. */
10616 /* If the definition comes from the same place as the declaration,
10617 maybe use the old DIE. We always want the DIE for this function
10618 that has the *_pc attributes to be under comp_unit_die so the
10619 debugger can find it. We also need to do this for abstract
10620 instances of inlines, since the spec requires the out-of-line copy
10621 to have the same parent. For local class methods, this doesn't
10622 apply; we just use the old DIE. */
10623 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10624 && (DECL_ARTIFICIAL (decl)
10625 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10626 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10627 == (unsigned) DECL_SOURCE_LINE (decl)))))
10629 subr_die = old_die;
10631 /* Clear out the declaration attribute and the parm types. */
10632 remove_AT (subr_die, DW_AT_declaration);
10633 remove_children (subr_die);
10637 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10638 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10639 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10640 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10641 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10642 != (unsigned) DECL_SOURCE_LINE (decl))
10644 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10649 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10651 if (TREE_PUBLIC (decl))
10652 add_AT_flag (subr_die, DW_AT_external, 1);
10654 add_name_and_src_coords_attributes (subr_die, decl);
10655 if (debug_info_level > DINFO_LEVEL_TERSE)
10657 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10658 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10659 0, 0, context_die);
10662 add_pure_or_virtual_attribute (subr_die, decl);
10663 if (DECL_ARTIFICIAL (decl))
10664 add_AT_flag (subr_die, DW_AT_artificial, 1);
10666 if (TREE_PROTECTED (decl))
10667 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10668 else if (TREE_PRIVATE (decl))
10669 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10674 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10676 add_AT_flag (subr_die, DW_AT_declaration, 1);
10678 /* The first time we see a member function, it is in the context of
10679 the class to which it belongs. We make sure of this by emitting
10680 the class first. The next time is the definition, which is
10681 handled above. The two may come from the same source text. */
10682 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10683 equate_decl_number_to_die (decl, subr_die);
10686 else if (DECL_ABSTRACT (decl))
10688 if (DECL_INLINE (decl) && !flag_no_inline)
10690 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10691 inline functions, but not for extern inline functions.
10692 We can't get this completely correct because information
10693 about whether the function was declared inline is not
10695 if (DECL_DEFER_OUTPUT (decl))
10696 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10698 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10701 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10703 equate_decl_number_to_die (decl, subr_die);
10705 else if (!DECL_EXTERNAL (decl))
10707 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10708 equate_decl_number_to_die (decl, subr_die);
10710 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10711 current_function_funcdef_no);
10712 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10713 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10714 current_function_funcdef_no);
10715 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10717 add_pubname (decl, subr_die);
10718 add_arange (decl, subr_die);
10720 #ifdef MIPS_DEBUGGING_INFO
10721 /* Add a reference to the FDE for this routine. */
10722 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10725 /* Define the "frame base" location for this routine. We use the
10726 frame pointer or stack pointer registers, since the RTL for local
10727 variables is relative to one of them. */
10729 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10730 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10733 /* ??? This fails for nested inline functions, because context_display
10734 is not part of the state saved/restored for inline functions. */
10735 if (current_function_needs_context)
10736 add_AT_location_description (subr_die, DW_AT_static_link,
10737 loc_descriptor (lookup_static_chain (decl)));
10741 /* Now output descriptions of the arguments for this function. This gets
10742 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10743 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10744 `...' at the end of the formal parameter list. In order to find out if
10745 there was a trailing ellipsis or not, we must instead look at the type
10746 associated with the FUNCTION_DECL. This will be a node of type
10747 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10748 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10749 an ellipsis at the end. */
10751 /* In the case where we are describing a mere function declaration, all we
10752 need to do here (and all we *can* do here) is to describe the *types* of
10753 its formal parameters. */
10754 if (debug_info_level <= DINFO_LEVEL_TERSE)
10756 else if (declaration)
10757 gen_formal_types_die (decl, subr_die);
10760 /* Generate DIEs to represent all known formal parameters. */
10761 tree arg_decls = DECL_ARGUMENTS (decl);
10764 /* When generating DIEs, generate the unspecified_parameters DIE
10765 instead if we come across the arg "__builtin_va_alist" */
10766 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10767 if (TREE_CODE (parm) == PARM_DECL)
10769 if (DECL_NAME (parm)
10770 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10771 "__builtin_va_alist"))
10772 gen_unspecified_parameters_die (parm, subr_die);
10774 gen_decl_die (parm, subr_die);
10777 /* Decide whether we need an unspecified_parameters DIE at the end.
10778 There are 2 more cases to do this for: 1) the ansi ... declaration -
10779 this is detectable when the end of the arg list is not a
10780 void_type_node 2) an unprototyped function declaration (not a
10781 definition). This just means that we have no info about the
10782 parameters at all. */
10783 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10784 if (fn_arg_types != NULL)
10786 /* This is the prototyped case, check for.... */
10787 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10788 gen_unspecified_parameters_die (decl, subr_die);
10790 else if (DECL_INITIAL (decl) == NULL_TREE)
10791 gen_unspecified_parameters_die (decl, subr_die);
10794 /* Output Dwarf info for all of the stuff within the body of the function
10795 (if it has one - it may be just a declaration). */
10796 outer_scope = DECL_INITIAL (decl);
10798 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10799 a function. This BLOCK actually represents the outermost binding contour
10800 for the function, i.e. the contour in which the function's formal
10801 parameters and labels get declared. Curiously, it appears that the front
10802 end doesn't actually put the PARM_DECL nodes for the current function onto
10803 the BLOCK_VARS list for this outer scope, but are strung off of the
10804 DECL_ARGUMENTS list for the function instead.
10806 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10807 the LABEL_DECL nodes for the function however, and we output DWARF info
10808 for those in decls_for_scope. Just within the `outer_scope' there will be
10809 a BLOCK node representing the function's outermost pair of curly braces,
10810 and any blocks used for the base and member initializers of a C++
10811 constructor function. */
10812 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10814 current_function_has_inlines = 0;
10815 decls_for_scope (outer_scope, subr_die, 0);
10817 #if 0 && defined (MIPS_DEBUGGING_INFO)
10818 if (current_function_has_inlines)
10820 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10821 if (! comp_unit_has_inlines)
10823 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10824 comp_unit_has_inlines = 1;
10831 /* Generate a DIE to represent a declared data object. */
10834 gen_variable_die (tree decl, dw_die_ref context_die)
10836 tree origin = decl_ultimate_origin (decl);
10837 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10839 dw_die_ref old_die = lookup_decl_die (decl);
10840 int declaration = (DECL_EXTERNAL (decl)
10841 || class_scope_p (context_die));
10843 if (origin != NULL)
10844 add_abstract_origin_attribute (var_die, origin);
10846 /* Loop unrolling can create multiple blocks that refer to the same
10847 static variable, so we must test for the DW_AT_declaration flag.
10849 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10850 copy decls and set the DECL_ABSTRACT flag on them instead of
10853 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10854 else if (old_die && TREE_STATIC (decl)
10855 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10857 /* This is a definition of a C++ class level static. */
10858 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10859 if (DECL_NAME (decl))
10861 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10863 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10864 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10866 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10867 != (unsigned) DECL_SOURCE_LINE (decl))
10869 add_AT_unsigned (var_die, DW_AT_decl_line,
10870 DECL_SOURCE_LINE (decl));
10875 add_name_and_src_coords_attributes (var_die, decl);
10876 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10877 TREE_THIS_VOLATILE (decl), context_die);
10879 if (TREE_PUBLIC (decl))
10880 add_AT_flag (var_die, DW_AT_external, 1);
10882 if (DECL_ARTIFICIAL (decl))
10883 add_AT_flag (var_die, DW_AT_artificial, 1);
10885 if (TREE_PROTECTED (decl))
10886 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10887 else if (TREE_PRIVATE (decl))
10888 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10892 add_AT_flag (var_die, DW_AT_declaration, 1);
10894 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10895 equate_decl_number_to_die (decl, var_die);
10897 if (! declaration && ! DECL_ABSTRACT (decl))
10899 add_location_or_const_value_attribute (var_die, decl);
10900 add_pubname (decl, var_die);
10903 tree_add_const_value_attribute (var_die, decl);
10906 /* Generate a DIE to represent a label identifier. */
10909 gen_label_die (tree decl, dw_die_ref context_die)
10911 tree origin = decl_ultimate_origin (decl);
10912 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10914 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10916 if (origin != NULL)
10917 add_abstract_origin_attribute (lbl_die, origin);
10919 add_name_and_src_coords_attributes (lbl_die, decl);
10921 if (DECL_ABSTRACT (decl))
10922 equate_decl_number_to_die (decl, lbl_die);
10925 insn = DECL_RTL (decl);
10927 /* Deleted labels are programmer specified labels which have been
10928 eliminated because of various optimizations. We still emit them
10929 here so that it is possible to put breakpoints on them. */
10930 if (GET_CODE (insn) == CODE_LABEL
10931 || ((GET_CODE (insn) == NOTE
10932 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10934 /* When optimization is enabled (via -O) some parts of the compiler
10935 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10936 represent source-level labels which were explicitly declared by
10937 the user. This really shouldn't be happening though, so catch
10938 it if it ever does happen. */
10939 if (INSN_DELETED_P (insn))
10942 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10943 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10948 /* Generate a DIE for a lexical block. */
10951 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
10953 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10954 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10956 if (! BLOCK_ABSTRACT (stmt))
10958 if (BLOCK_FRAGMENT_CHAIN (stmt))
10962 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10964 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10967 add_ranges (chain);
10968 chain = BLOCK_FRAGMENT_CHAIN (chain);
10975 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10976 BLOCK_NUMBER (stmt));
10977 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10978 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10979 BLOCK_NUMBER (stmt));
10980 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10984 decls_for_scope (stmt, stmt_die, depth);
10987 /* Generate a DIE for an inlined subprogram. */
10990 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
10992 tree decl = block_ultimate_origin (stmt);
10994 /* Emit info for the abstract instance first, if we haven't yet. We
10995 must emit this even if the block is abstract, otherwise when we
10996 emit the block below (or elsewhere), we may end up trying to emit
10997 a die whose origin die hasn't been emitted, and crashing. */
10998 dwarf2out_abstract_function (decl);
11000 if (! BLOCK_ABSTRACT (stmt))
11002 dw_die_ref subr_die
11003 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
11004 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11006 add_abstract_origin_attribute (subr_die, decl);
11007 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11008 BLOCK_NUMBER (stmt));
11009 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
11010 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
11011 BLOCK_NUMBER (stmt));
11012 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
11013 decls_for_scope (stmt, subr_die, depth);
11014 current_function_has_inlines = 1;
11017 /* We may get here if we're the outer block of function A that was
11018 inlined into function B that was inlined into function C. When
11019 generating debugging info for C, dwarf2out_abstract_function(B)
11020 would mark all inlined blocks as abstract, including this one.
11021 So, we wouldn't (and shouldn't) expect labels to be generated
11022 for this one. Instead, just emit debugging info for
11023 declarations within the block. This is particularly important
11024 in the case of initializers of arguments passed from B to us:
11025 if they're statement expressions containing declarations, we
11026 wouldn't generate dies for their abstract variables, and then,
11027 when generating dies for the real variables, we'd die (pun
11029 gen_lexical_block_die (stmt, context_die, depth);
11032 /* Generate a DIE for a field in a record, or structure. */
11035 gen_field_die (tree decl, dw_die_ref context_die)
11037 dw_die_ref decl_die;
11039 if (TREE_TYPE (decl) == error_mark_node)
11042 decl_die = new_die (DW_TAG_member, context_die, decl);
11043 add_name_and_src_coords_attributes (decl_die, decl);
11044 add_type_attribute (decl_die, member_declared_type (decl),
11045 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
11048 if (DECL_BIT_FIELD_TYPE (decl))
11050 add_byte_size_attribute (decl_die, decl);
11051 add_bit_size_attribute (decl_die, decl);
11052 add_bit_offset_attribute (decl_die, decl);
11055 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
11056 add_data_member_location_attribute (decl_die, decl);
11058 if (DECL_ARTIFICIAL (decl))
11059 add_AT_flag (decl_die, DW_AT_artificial, 1);
11061 if (TREE_PROTECTED (decl))
11062 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
11063 else if (TREE_PRIVATE (decl))
11064 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
11068 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11069 Use modified_type_die instead.
11070 We keep this code here just in case these types of DIEs may be needed to
11071 represent certain things in other languages (e.g. Pascal) someday. */
11074 gen_pointer_type_die (tree type, dw_die_ref context_die)
11077 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
11079 equate_type_number_to_die (type, ptr_die);
11080 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11081 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11084 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11085 Use modified_type_die instead.
11086 We keep this code here just in case these types of DIEs may be needed to
11087 represent certain things in other languages (e.g. Pascal) someday. */
11090 gen_reference_type_die (tree type, dw_die_ref context_die)
11093 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
11095 equate_type_number_to_die (type, ref_die);
11096 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
11097 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11101 /* Generate a DIE for a pointer to a member type. */
11104 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
11107 = new_die (DW_TAG_ptr_to_member_type,
11108 scope_die_for (type, context_die), type);
11110 equate_type_number_to_die (type, ptr_die);
11111 add_AT_die_ref (ptr_die, DW_AT_containing_type,
11112 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
11113 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11116 /* Generate the DIE for the compilation unit. */
11119 gen_compile_unit_die (const char *filename)
11122 char producer[250];
11123 const char *language_string = lang_hooks.name;
11126 die = new_die (DW_TAG_compile_unit, NULL, NULL);
11130 add_name_attribute (die, filename);
11131 /* Don't add cwd for <built-in>. */
11132 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
11133 add_comp_dir_attribute (die);
11136 sprintf (producer, "%s %s", language_string, version_string);
11138 #ifdef MIPS_DEBUGGING_INFO
11139 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11140 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11141 not appear in the producer string, the debugger reaches the conclusion
11142 that the object file is stripped and has no debugging information.
11143 To get the MIPS/SGI debugger to believe that there is debugging
11144 information in the object file, we add a -g to the producer string. */
11145 if (debug_info_level > DINFO_LEVEL_TERSE)
11146 strcat (producer, " -g");
11149 add_AT_string (die, DW_AT_producer, producer);
11151 if (strcmp (language_string, "GNU C++") == 0)
11152 language = DW_LANG_C_plus_plus;
11153 else if (strcmp (language_string, "GNU Ada") == 0)
11154 language = DW_LANG_Ada95;
11155 else if (strcmp (language_string, "GNU F77") == 0)
11156 language = DW_LANG_Fortran77;
11157 else if (strcmp (language_string, "GNU Pascal") == 0)
11158 language = DW_LANG_Pascal83;
11159 else if (strcmp (language_string, "GNU Java") == 0)
11160 language = DW_LANG_Java;
11162 language = DW_LANG_C89;
11164 add_AT_unsigned (die, DW_AT_language, language);
11168 /* Generate a DIE for a string type. */
11171 gen_string_type_die (tree type, dw_die_ref context_die)
11173 dw_die_ref type_die
11174 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
11176 equate_type_number_to_die (type, type_die);
11178 /* ??? Fudge the string length attribute for now.
11179 TODO: add string length info. */
11181 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
11182 bound_representation (upper_bound, 0, 'u');
11186 /* Generate the DIE for a base class. */
11189 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
11191 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
11193 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
11194 add_data_member_location_attribute (die, binfo);
11196 if (TREE_VIA_VIRTUAL (binfo))
11197 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
11199 if (access == access_public_node)
11200 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
11201 else if (access == access_protected_node)
11202 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
11205 /* Generate a DIE for a class member. */
11208 gen_member_die (tree type, dw_die_ref context_die)
11211 tree binfo = TYPE_BINFO (type);
11214 /* If this is not an incomplete type, output descriptions of each of its
11215 members. Note that as we output the DIEs necessary to represent the
11216 members of this record or union type, we will also be trying to output
11217 DIEs to represent the *types* of those members. However the `type'
11218 function (above) will specifically avoid generating type DIEs for member
11219 types *within* the list of member DIEs for this (containing) type except
11220 for those types (of members) which are explicitly marked as also being
11221 members of this (containing) type themselves. The g++ front- end can
11222 force any given type to be treated as a member of some other (containing)
11223 type by setting the TYPE_CONTEXT of the given (member) type to point to
11224 the TREE node representing the appropriate (containing) type. */
11226 /* First output info about the base classes. */
11227 if (binfo && BINFO_BASETYPES (binfo))
11229 tree bases = BINFO_BASETYPES (binfo);
11230 tree accesses = BINFO_BASEACCESSES (binfo);
11231 int n_bases = TREE_VEC_LENGTH (bases);
11234 for (i = 0; i < n_bases; i++)
11235 gen_inheritance_die (TREE_VEC_ELT (bases, i),
11236 (accesses ? TREE_VEC_ELT (accesses, i)
11237 : access_public_node), context_die);
11240 /* Now output info about the data members and type members. */
11241 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
11243 /* If we thought we were generating minimal debug info for TYPE
11244 and then changed our minds, some of the member declarations
11245 may have already been defined. Don't define them again, but
11246 do put them in the right order. */
11248 child = lookup_decl_die (member);
11250 splice_child_die (context_die, child);
11252 gen_decl_die (member, context_die);
11255 /* Now output info about the function members (if any). */
11256 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
11258 /* Don't include clones in the member list. */
11259 if (DECL_ABSTRACT_ORIGIN (member))
11262 child = lookup_decl_die (member);
11264 splice_child_die (context_die, child);
11266 gen_decl_die (member, context_die);
11270 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11271 is set, we pretend that the type was never defined, so we only get the
11272 member DIEs needed by later specification DIEs. */
11275 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
11277 dw_die_ref type_die = lookup_type_die (type);
11278 dw_die_ref scope_die = 0;
11280 int complete = (TYPE_SIZE (type)
11281 && (! TYPE_STUB_DECL (type)
11282 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
11284 if (type_die && ! complete)
11287 if (TYPE_CONTEXT (type) != NULL_TREE
11288 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
11291 scope_die = scope_die_for (type, context_die);
11293 if (! type_die || (nested && scope_die == comp_unit_die))
11294 /* First occurrence of type or toplevel definition of nested class. */
11296 dw_die_ref old_die = type_die;
11298 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
11299 ? DW_TAG_structure_type : DW_TAG_union_type,
11301 equate_type_number_to_die (type, type_die);
11303 add_AT_die_ref (type_die, DW_AT_specification, old_die);
11305 add_name_attribute (type_die, type_tag (type));
11308 remove_AT (type_die, DW_AT_declaration);
11310 /* If this type has been completed, then give it a byte_size attribute and
11311 then give a list of members. */
11314 /* Prevent infinite recursion in cases where the type of some member of
11315 this type is expressed in terms of this type itself. */
11316 TREE_ASM_WRITTEN (type) = 1;
11317 add_byte_size_attribute (type_die, type);
11318 if (TYPE_STUB_DECL (type) != NULL_TREE)
11319 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11321 /* If the first reference to this type was as the return type of an
11322 inline function, then it may not have a parent. Fix this now. */
11323 if (type_die->die_parent == NULL)
11324 add_child_die (scope_die, type_die);
11326 push_decl_scope (type);
11327 gen_member_die (type, type_die);
11330 /* GNU extension: Record what type our vtable lives in. */
11331 if (TYPE_VFIELD (type))
11333 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11335 gen_type_die (vtype, context_die);
11336 add_AT_die_ref (type_die, DW_AT_containing_type,
11337 lookup_type_die (vtype));
11342 add_AT_flag (type_die, DW_AT_declaration, 1);
11344 /* We don't need to do this for function-local types. */
11345 if (TYPE_STUB_DECL (type)
11346 && ! decl_function_context (TYPE_STUB_DECL (type)))
11347 VARRAY_PUSH_TREE (incomplete_types, type);
11351 /* Generate a DIE for a subroutine _type_. */
11354 gen_subroutine_type_die (tree type, dw_die_ref context_die)
11356 tree return_type = TREE_TYPE (type);
11357 dw_die_ref subr_die
11358 = new_die (DW_TAG_subroutine_type,
11359 scope_die_for (type, context_die), type);
11361 equate_type_number_to_die (type, subr_die);
11362 add_prototyped_attribute (subr_die, type);
11363 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11364 gen_formal_types_die (type, subr_die);
11367 /* Generate a DIE for a type definition. */
11370 gen_typedef_die (tree decl, dw_die_ref context_die)
11372 dw_die_ref type_die;
11375 if (TREE_ASM_WRITTEN (decl))
11378 TREE_ASM_WRITTEN (decl) = 1;
11379 type_die = new_die (DW_TAG_typedef, context_die, decl);
11380 origin = decl_ultimate_origin (decl);
11381 if (origin != NULL)
11382 add_abstract_origin_attribute (type_die, origin);
11387 add_name_and_src_coords_attributes (type_die, decl);
11388 if (DECL_ORIGINAL_TYPE (decl))
11390 type = DECL_ORIGINAL_TYPE (decl);
11392 if (type == TREE_TYPE (decl))
11395 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11398 type = TREE_TYPE (decl);
11400 add_type_attribute (type_die, type, TREE_READONLY (decl),
11401 TREE_THIS_VOLATILE (decl), context_die);
11404 if (DECL_ABSTRACT (decl))
11405 equate_decl_number_to_die (decl, type_die);
11408 /* Generate a type description DIE. */
11411 gen_type_die (tree type, dw_die_ref context_die)
11415 if (type == NULL_TREE || type == error_mark_node)
11418 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11419 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11421 if (TREE_ASM_WRITTEN (type))
11424 /* Prevent broken recursion; we can't hand off to the same type. */
11425 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11428 TREE_ASM_WRITTEN (type) = 1;
11429 gen_decl_die (TYPE_NAME (type), context_die);
11433 /* We are going to output a DIE to represent the unqualified version
11434 of this type (i.e. without any const or volatile qualifiers) so
11435 get the main variant (i.e. the unqualified version) of this type
11436 now. (Vectors are special because the debugging info is in the
11437 cloned type itself). */
11438 if (TREE_CODE (type) != VECTOR_TYPE)
11439 type = type_main_variant (type);
11441 if (TREE_ASM_WRITTEN (type))
11444 switch (TREE_CODE (type))
11450 case REFERENCE_TYPE:
11451 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11452 ensures that the gen_type_die recursion will terminate even if the
11453 type is recursive. Recursive types are possible in Ada. */
11454 /* ??? We could perhaps do this for all types before the switch
11456 TREE_ASM_WRITTEN (type) = 1;
11458 /* For these types, all that is required is that we output a DIE (or a
11459 set of DIEs) to represent the "basis" type. */
11460 gen_type_die (TREE_TYPE (type), context_die);
11464 /* This code is used for C++ pointer-to-data-member types.
11465 Output a description of the relevant class type. */
11466 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11468 /* Output a description of the type of the object pointed to. */
11469 gen_type_die (TREE_TYPE (type), context_die);
11471 /* Now output a DIE to represent this pointer-to-data-member type
11473 gen_ptr_to_mbr_type_die (type, context_die);
11477 gen_type_die (TYPE_DOMAIN (type), context_die);
11478 gen_set_type_die (type, context_die);
11482 gen_type_die (TREE_TYPE (type), context_die);
11483 abort (); /* No way to represent these in Dwarf yet! */
11486 case FUNCTION_TYPE:
11487 /* Force out return type (in case it wasn't forced out already). */
11488 gen_type_die (TREE_TYPE (type), context_die);
11489 gen_subroutine_type_die (type, context_die);
11493 /* Force out return type (in case it wasn't forced out already). */
11494 gen_type_die (TREE_TYPE (type), context_die);
11495 gen_subroutine_type_die (type, context_die);
11499 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11501 gen_type_die (TREE_TYPE (type), context_die);
11502 gen_string_type_die (type, context_die);
11505 gen_array_type_die (type, context_die);
11509 gen_array_type_die (type, context_die);
11512 case ENUMERAL_TYPE:
11515 case QUAL_UNION_TYPE:
11516 /* If this is a nested type whose containing class hasn't been written
11517 out yet, writing it out will cover this one, too. This does not apply
11518 to instantiations of member class templates; they need to be added to
11519 the containing class as they are generated. FIXME: This hurts the
11520 idea of combining type decls from multiple TUs, since we can't predict
11521 what set of template instantiations we'll get. */
11522 if (TYPE_CONTEXT (type)
11523 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11524 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11526 gen_type_die (TYPE_CONTEXT (type), context_die);
11528 if (TREE_ASM_WRITTEN (type))
11531 /* If that failed, attach ourselves to the stub. */
11532 push_decl_scope (TYPE_CONTEXT (type));
11533 context_die = lookup_type_die (TYPE_CONTEXT (type));
11539 if (TREE_CODE (type) == ENUMERAL_TYPE)
11540 gen_enumeration_type_die (type, context_die);
11542 gen_struct_or_union_type_die (type, context_die);
11547 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11548 it up if it is ever completed. gen_*_type_die will set it for us
11549 when appropriate. */
11558 /* No DIEs needed for fundamental types. */
11562 /* No Dwarf representation currently defined. */
11569 TREE_ASM_WRITTEN (type) = 1;
11572 /* Generate a DIE for a tagged type instantiation. */
11575 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
11577 if (type == NULL_TREE || type == error_mark_node)
11580 /* We are going to output a DIE to represent the unqualified version of
11581 this type (i.e. without any const or volatile qualifiers) so make sure
11582 that we have the main variant (i.e. the unqualified version) of this
11584 if (type != type_main_variant (type))
11587 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11588 an instance of an unresolved type. */
11590 switch (TREE_CODE (type))
11595 case ENUMERAL_TYPE:
11596 gen_inlined_enumeration_type_die (type, context_die);
11600 gen_inlined_structure_type_die (type, context_die);
11604 case QUAL_UNION_TYPE:
11605 gen_inlined_union_type_die (type, context_die);
11613 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11614 things which are local to the given block. */
11617 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
11619 int must_output_die = 0;
11622 enum tree_code origin_code;
11624 /* Ignore blocks never really used to make RTL. */
11625 if (stmt == NULL_TREE || !TREE_USED (stmt)
11626 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11629 /* If the block is one fragment of a non-contiguous block, do not
11630 process the variables, since they will have been done by the
11631 origin block. Do process subblocks. */
11632 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11636 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11637 gen_block_die (sub, context_die, depth + 1);
11642 /* Determine the "ultimate origin" of this block. This block may be an
11643 inlined instance of an inlined instance of inline function, so we have
11644 to trace all of the way back through the origin chain to find out what
11645 sort of node actually served as the original seed for the creation of
11646 the current block. */
11647 origin = block_ultimate_origin (stmt);
11648 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11650 /* Determine if we need to output any Dwarf DIEs at all to represent this
11652 if (origin_code == FUNCTION_DECL)
11653 /* The outer scopes for inlinings *must* always be represented. We
11654 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11655 must_output_die = 1;
11658 /* In the case where the current block represents an inlining of the
11659 "body block" of an inline function, we must *NOT* output any DIE for
11660 this block because we have already output a DIE to represent the whole
11661 inlined function scope and the "body block" of any function doesn't
11662 really represent a different scope according to ANSI C rules. So we
11663 check here to make sure that this block does not represent a "body
11664 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11665 if (! is_body_block (origin ? origin : stmt))
11667 /* Determine if this block directly contains any "significant"
11668 local declarations which we will need to output DIEs for. */
11669 if (debug_info_level > DINFO_LEVEL_TERSE)
11670 /* We are not in terse mode so *any* local declaration counts
11671 as being a "significant" one. */
11672 must_output_die = (BLOCK_VARS (stmt) != NULL);
11674 /* We are in terse mode, so only local (nested) function
11675 definitions count as "significant" local declarations. */
11676 for (decl = BLOCK_VARS (stmt);
11677 decl != NULL; decl = TREE_CHAIN (decl))
11678 if (TREE_CODE (decl) == FUNCTION_DECL
11679 && DECL_INITIAL (decl))
11681 must_output_die = 1;
11687 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11688 DIE for any block which contains no significant local declarations at
11689 all. Rather, in such cases we just call `decls_for_scope' so that any
11690 needed Dwarf info for any sub-blocks will get properly generated. Note
11691 that in terse mode, our definition of what constitutes a "significant"
11692 local declaration gets restricted to include only inlined function
11693 instances and local (nested) function definitions. */
11694 if (must_output_die)
11696 if (origin_code == FUNCTION_DECL)
11697 gen_inlined_subroutine_die (stmt, context_die, depth);
11699 gen_lexical_block_die (stmt, context_die, depth);
11702 decls_for_scope (stmt, context_die, depth);
11705 /* Generate all of the decls declared within a given scope and (recursively)
11706 all of its sub-blocks. */
11709 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
11714 /* Ignore blocks never really used to make RTL. */
11715 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11718 /* Output the DIEs to represent all of the data objects and typedefs
11719 declared directly within this block but not within any nested
11720 sub-blocks. Also, nested function and tag DIEs have been
11721 generated with a parent of NULL; fix that up now. */
11722 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11726 if (TREE_CODE (decl) == FUNCTION_DECL)
11727 die = lookup_decl_die (decl);
11728 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11729 die = lookup_type_die (TREE_TYPE (decl));
11733 if (die != NULL && die->die_parent == NULL)
11734 add_child_die (context_die, die);
11736 gen_decl_die (decl, context_die);
11739 /* If we're at -g1, we're not interested in subblocks. */
11740 if (debug_info_level <= DINFO_LEVEL_TERSE)
11743 /* Output the DIEs to represent all sub-blocks (and the items declared
11744 therein) of this block. */
11745 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11747 subblocks = BLOCK_CHAIN (subblocks))
11748 gen_block_die (subblocks, context_die, depth + 1);
11751 /* Is this a typedef we can avoid emitting? */
11754 is_redundant_typedef (tree decl)
11756 if (TYPE_DECL_IS_STUB (decl))
11759 if (DECL_ARTIFICIAL (decl)
11760 && DECL_CONTEXT (decl)
11761 && is_tagged_type (DECL_CONTEXT (decl))
11762 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11763 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11764 /* Also ignore the artificial member typedef for the class name. */
11770 /* Generate Dwarf debug information for a decl described by DECL. */
11773 gen_decl_die (tree decl, dw_die_ref context_die)
11777 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11780 switch (TREE_CODE (decl))
11786 /* The individual enumerators of an enum type get output when we output
11787 the Dwarf representation of the relevant enum type itself. */
11790 case FUNCTION_DECL:
11791 /* Don't output any DIEs to represent mere function declarations,
11792 unless they are class members or explicit block externs. */
11793 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11794 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11797 /* If we're emitting a clone, emit info for the abstract instance. */
11798 if (DECL_ORIGIN (decl) != decl)
11799 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11801 /* If we're emitting an out-of-line copy of an inline function,
11802 emit info for the abstract instance and set up to refer to it. */
11803 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11804 && ! class_scope_p (context_die)
11805 /* dwarf2out_abstract_function won't emit a die if this is just
11806 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11807 that case, because that works only if we have a die. */
11808 && DECL_INITIAL (decl) != NULL_TREE)
11810 dwarf2out_abstract_function (decl);
11811 set_decl_origin_self (decl);
11814 /* Otherwise we're emitting the primary DIE for this decl. */
11815 else if (debug_info_level > DINFO_LEVEL_TERSE)
11817 /* Before we describe the FUNCTION_DECL itself, make sure that we
11818 have described its return type. */
11819 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11821 /* And its virtual context. */
11822 if (DECL_VINDEX (decl) != NULL_TREE)
11823 gen_type_die (DECL_CONTEXT (decl), context_die);
11825 /* And its containing type. */
11826 origin = decl_class_context (decl);
11827 if (origin != NULL_TREE)
11828 gen_type_die_for_member (origin, decl, context_die);
11831 /* Now output a DIE to represent the function itself. */
11832 gen_subprogram_die (decl, context_die);
11836 /* If we are in terse mode, don't generate any DIEs to represent any
11837 actual typedefs. */
11838 if (debug_info_level <= DINFO_LEVEL_TERSE)
11841 /* In the special case of a TYPE_DECL node representing the declaration
11842 of some type tag, if the given TYPE_DECL is marked as having been
11843 instantiated from some other (original) TYPE_DECL node (e.g. one which
11844 was generated within the original definition of an inline function) we
11845 have to generate a special (abbreviated) DW_TAG_structure_type,
11846 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11847 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11849 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11853 if (is_redundant_typedef (decl))
11854 gen_type_die (TREE_TYPE (decl), context_die);
11856 /* Output a DIE to represent the typedef itself. */
11857 gen_typedef_die (decl, context_die);
11861 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11862 gen_label_die (decl, context_die);
11866 /* If we are in terse mode, don't generate any DIEs to represent any
11867 variable declarations or definitions. */
11868 if (debug_info_level <= DINFO_LEVEL_TERSE)
11871 /* Output any DIEs that are needed to specify the type of this data
11873 gen_type_die (TREE_TYPE (decl), context_die);
11875 /* And its containing type. */
11876 origin = decl_class_context (decl);
11877 if (origin != NULL_TREE)
11878 gen_type_die_for_member (origin, decl, context_die);
11880 /* Now output the DIE to represent the data object itself. This gets
11881 complicated because of the possibility that the VAR_DECL really
11882 represents an inlined instance of a formal parameter for an inline
11884 origin = decl_ultimate_origin (decl);
11885 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11886 gen_formal_parameter_die (decl, context_die);
11888 gen_variable_die (decl, context_die);
11892 /* Ignore the nameless fields that are used to skip bits but handle C++
11893 anonymous unions. */
11894 if (DECL_NAME (decl) != NULL_TREE
11895 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11897 gen_type_die (member_declared_type (decl), context_die);
11898 gen_field_die (decl, context_die);
11903 gen_type_die (TREE_TYPE (decl), context_die);
11904 gen_formal_parameter_die (decl, context_die);
11907 case NAMESPACE_DECL:
11908 /* Ignore for now. */
11912 if ((int)TREE_CODE (decl) > NUM_TREE_CODES)
11913 /* Probably some frontend-internal decl. Assume we don't care. */
11919 /* Add Ada "use" clause information for SGI Workshop debugger. */
11922 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
11924 unsigned int file_index;
11926 if (filename != NULL)
11928 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11929 tree context_list_decl
11930 = build_decl (LABEL_DECL, get_identifier (context_list),
11933 TREE_PUBLIC (context_list_decl) = TRUE;
11934 add_name_attribute (unit_die, context_list);
11935 file_index = lookup_filename (filename);
11936 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11937 add_pubname (context_list_decl, unit_die);
11941 /* Output debug information for global decl DECL. Called from toplev.c after
11942 compilation proper has finished. */
11945 dwarf2out_global_decl (tree decl)
11947 /* Output DWARF2 information for file-scope tentative data object
11948 declarations, file-scope (extern) function declarations (which had no
11949 corresponding body) and file-scope tagged type declarations and
11950 definitions which have not yet been forced out. */
11951 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11952 dwarf2out_decl (decl);
11955 /* Write the debugging output for DECL. */
11958 dwarf2out_decl (tree decl)
11960 dw_die_ref context_die = comp_unit_die;
11962 switch (TREE_CODE (decl))
11967 case FUNCTION_DECL:
11968 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11969 builtin function. Explicit programmer-supplied declarations of
11970 these same functions should NOT be ignored however. */
11971 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11974 /* What we would really like to do here is to filter out all mere
11975 file-scope declarations of file-scope functions which are never
11976 referenced later within this translation unit (and keep all of ones
11977 that *are* referenced later on) but we aren't clairvoyant, so we have
11978 no idea which functions will be referenced in the future (i.e. later
11979 on within the current translation unit). So here we just ignore all
11980 file-scope function declarations which are not also definitions. If
11981 and when the debugger needs to know something about these functions,
11982 it will have to hunt around and find the DWARF information associated
11983 with the definition of the function.
11985 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11986 nodes represent definitions and which ones represent mere
11987 declarations. We have to check DECL_INITIAL instead. That's because
11988 the C front-end supports some weird semantics for "extern inline"
11989 function definitions. These can get inlined within the current
11990 translation unit (an thus, we need to generate Dwarf info for their
11991 abstract instances so that the Dwarf info for the concrete inlined
11992 instances can have something to refer to) but the compiler never
11993 generates any out-of-lines instances of such things (despite the fact
11994 that they *are* definitions).
11996 The important point is that the C front-end marks these "extern
11997 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11998 them anyway. Note that the C++ front-end also plays some similar games
11999 for inline function definitions appearing within include files which
12000 also contain `#pragma interface' pragmas. */
12001 if (DECL_INITIAL (decl) == NULL_TREE)
12004 /* If we're a nested function, initially use a parent of NULL; if we're
12005 a plain function, this will be fixed up in decls_for_scope. If
12006 we're a method, it will be ignored, since we already have a DIE. */
12007 if (decl_function_context (decl)
12008 /* But if we're in terse mode, we don't care about scope. */
12009 && debug_info_level > DINFO_LEVEL_TERSE)
12010 context_die = NULL;
12014 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12015 declaration and if the declaration was never even referenced from
12016 within this entire compilation unit. We suppress these DIEs in
12017 order to save space in the .debug section (by eliminating entries
12018 which are probably useless). Note that we must not suppress
12019 block-local extern declarations (whether used or not) because that
12020 would screw-up the debugger's name lookup mechanism and cause it to
12021 miss things which really ought to be in scope at a given point. */
12022 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
12025 /* If we are in terse mode, don't generate any DIEs to represent any
12026 variable declarations or definitions. */
12027 if (debug_info_level <= DINFO_LEVEL_TERSE)
12032 /* Don't emit stubs for types unless they are needed by other DIEs. */
12033 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
12036 /* Don't bother trying to generate any DIEs to represent any of the
12037 normal built-in types for the language we are compiling. */
12038 if (DECL_SOURCE_LINE (decl) == 0)
12040 /* OK, we need to generate one for `bool' so GDB knows what type
12041 comparisons have. */
12042 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
12043 == DW_LANG_C_plus_plus)
12044 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
12045 && ! DECL_IGNORED_P (decl))
12046 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
12051 /* If we are in terse mode, don't generate any DIEs for types. */
12052 if (debug_info_level <= DINFO_LEVEL_TERSE)
12055 /* If we're a function-scope tag, initially use a parent of NULL;
12056 this will be fixed up in decls_for_scope. */
12057 if (decl_function_context (decl))
12058 context_die = NULL;
12066 gen_decl_die (decl, context_die);
12069 /* Output a marker (i.e. a label) for the beginning of the generated code for
12070 a lexical block. */
12073 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
12074 unsigned int blocknum)
12076 function_section (current_function_decl);
12077 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
12080 /* Output a marker (i.e. a label) for the end of the generated code for a
12084 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
12086 function_section (current_function_decl);
12087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
12090 /* Returns nonzero if it is appropriate not to emit any debugging
12091 information for BLOCK, because it doesn't contain any instructions.
12093 Don't allow this for blocks with nested functions or local classes
12094 as we would end up with orphans, and in the presence of scheduling
12095 we may end up calling them anyway. */
12098 dwarf2out_ignore_block (tree block)
12102 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
12103 if (TREE_CODE (decl) == FUNCTION_DECL
12104 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
12110 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12111 dwarf2out.c) and return its "index". The index of each (known) filename is
12112 just a unique number which is associated with only that one filename. We
12113 need such numbers for the sake of generating labels (in the .debug_sfnames
12114 section) and references to those files numbers (in the .debug_srcinfo
12115 and.debug_macinfo sections). If the filename given as an argument is not
12116 found in our current list, add it to the list and assign it the next
12117 available unique index number. In order to speed up searches, we remember
12118 the index of the filename was looked up last. This handles the majority of
12122 lookup_filename (const char *file_name)
12125 char *save_file_name;
12127 /* Check to see if the file name that was searched on the previous
12128 call matches this file name. If so, return the index. */
12129 if (file_table_last_lookup_index != 0)
12132 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
12133 if (strcmp (file_name, last) == 0)
12134 return file_table_last_lookup_index;
12137 /* Didn't match the previous lookup, search the table */
12138 n = VARRAY_ACTIVE_SIZE (file_table);
12139 for (i = 1; i < n; i++)
12140 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
12142 file_table_last_lookup_index = i;
12146 /* Add the new entry to the end of the filename table. */
12147 file_table_last_lookup_index = n;
12148 save_file_name = (char *) ggc_strdup (file_name);
12149 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
12150 VARRAY_PUSH_UINT (file_table_emitted, 0);
12156 maybe_emit_file (int fileno)
12158 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
12160 if (!VARRAY_UINT (file_table_emitted, fileno))
12162 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
12163 fprintf (asm_out_file, "\t.file %u ",
12164 VARRAY_UINT (file_table_emitted, fileno));
12165 output_quoted_string (asm_out_file,
12166 VARRAY_CHAR_PTR (file_table, fileno));
12167 fputc ('\n', asm_out_file);
12169 return VARRAY_UINT (file_table_emitted, fileno);
12176 init_file_table (void)
12178 /* Allocate the initial hunk of the file_table. */
12179 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
12180 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
12182 /* Skip the first entry - file numbers begin at 1. */
12183 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
12184 VARRAY_PUSH_UINT (file_table_emitted, 0);
12185 file_table_last_lookup_index = 0;
12188 /* Output a label to mark the beginning of a source code line entry
12189 and record information relating to this source line, in
12190 'line_info_table' for later output of the .debug_line section. */
12193 dwarf2out_source_line (unsigned int line, const char *filename)
12195 if (debug_info_level >= DINFO_LEVEL_NORMAL
12198 function_section (current_function_decl);
12200 /* If requested, emit something human-readable. */
12201 if (flag_debug_asm)
12202 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
12205 if (DWARF2_ASM_LINE_DEBUG_INFO)
12207 unsigned file_num = lookup_filename (filename);
12209 file_num = maybe_emit_file (file_num);
12211 /* Emit the .loc directive understood by GNU as. */
12212 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
12214 /* Indicate that line number info exists. */
12215 line_info_table_in_use++;
12217 /* Indicate that multiple line number tables exist. */
12218 if (DECL_SECTION_NAME (current_function_decl))
12219 separate_line_info_table_in_use++;
12221 else if (DECL_SECTION_NAME (current_function_decl))
12223 dw_separate_line_info_ref line_info;
12224 (*targetm.asm_out.internal_label) (asm_out_file, SEPARATE_LINE_CODE_LABEL,
12225 separate_line_info_table_in_use);
12227 /* expand the line info table if necessary */
12228 if (separate_line_info_table_in_use
12229 == separate_line_info_table_allocated)
12231 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
12232 separate_line_info_table
12233 = ggc_realloc (separate_line_info_table,
12234 separate_line_info_table_allocated
12235 * sizeof (dw_separate_line_info_entry));
12236 memset (separate_line_info_table
12237 + separate_line_info_table_in_use,
12239 (LINE_INFO_TABLE_INCREMENT
12240 * sizeof (dw_separate_line_info_entry)));
12243 /* Add the new entry at the end of the line_info_table. */
12245 = &separate_line_info_table[separate_line_info_table_in_use++];
12246 line_info->dw_file_num = lookup_filename (filename);
12247 line_info->dw_line_num = line;
12248 line_info->function = current_function_funcdef_no;
12252 dw_line_info_ref line_info;
12254 (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL,
12255 line_info_table_in_use);
12257 /* Expand the line info table if necessary. */
12258 if (line_info_table_in_use == line_info_table_allocated)
12260 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
12262 = ggc_realloc (line_info_table,
12263 (line_info_table_allocated
12264 * sizeof (dw_line_info_entry)));
12265 memset (line_info_table + line_info_table_in_use, 0,
12266 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
12269 /* Add the new entry at the end of the line_info_table. */
12270 line_info = &line_info_table[line_info_table_in_use++];
12271 line_info->dw_file_num = lookup_filename (filename);
12272 line_info->dw_line_num = line;
12277 /* Record the beginning of a new source file. */
12280 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
12282 if (flag_eliminate_dwarf2_dups)
12284 /* Record the beginning of the file for break_out_includes. */
12285 dw_die_ref bincl_die;
12287 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
12288 add_AT_string (bincl_die, DW_AT_name, filename);
12291 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12293 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12294 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
12295 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
12297 maybe_emit_file (lookup_filename (filename));
12298 dw2_asm_output_data_uleb128 (lookup_filename (filename),
12299 "Filename we just started");
12303 /* Record the end of a source file. */
12306 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
12308 if (flag_eliminate_dwarf2_dups)
12309 /* Record the end of the file for break_out_includes. */
12310 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
12312 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12314 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12315 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12319 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12320 the tail part of the directive line, i.e. the part which is past the
12321 initial whitespace, #, whitespace, directive-name, whitespace part. */
12324 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
12325 const char *buffer ATTRIBUTE_UNUSED)
12327 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12329 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12330 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12331 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12332 dw2_asm_output_nstring (buffer, -1, "The macro");
12336 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12337 the tail part of the directive line, i.e. the part which is past the
12338 initial whitespace, #, whitespace, directive-name, whitespace part. */
12341 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
12342 const char *buffer ATTRIBUTE_UNUSED)
12344 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12346 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12347 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12348 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12349 dw2_asm_output_nstring (buffer, -1, "The macro");
12353 /* Set up for Dwarf output at the start of compilation. */
12356 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
12358 init_file_table ();
12360 /* Allocate the initial hunk of the decl_die_table. */
12361 decl_die_table = ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT
12362 * sizeof (dw_die_ref));
12363 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12364 decl_die_table_in_use = 0;
12366 /* Allocate the initial hunk of the decl_scope_table. */
12367 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12369 /* Allocate the initial hunk of the abbrev_die_table. */
12370 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
12371 * sizeof (dw_die_ref));
12372 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12373 /* Zero-th entry is allocated, but unused */
12374 abbrev_die_table_in_use = 1;
12376 /* Allocate the initial hunk of the line_info_table. */
12377 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
12378 * sizeof (dw_line_info_entry));
12379 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12381 /* Zero-th entry is allocated, but unused */
12382 line_info_table_in_use = 1;
12384 /* Generate the initial DIE for the .debug section. Note that the (string)
12385 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12386 will (typically) be a relative pathname and that this pathname should be
12387 taken as being relative to the directory from which the compiler was
12388 invoked when the given (base) source file was compiled. We will fill
12389 in this value in dwarf2out_finish. */
12390 comp_unit_die = gen_compile_unit_die (NULL);
12392 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12394 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12396 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12397 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12398 DEBUG_ABBREV_SECTION_LABEL, 0);
12399 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12400 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12402 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12404 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12405 DEBUG_INFO_SECTION_LABEL, 0);
12406 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12407 DEBUG_LINE_SECTION_LABEL, 0);
12408 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12409 DEBUG_RANGES_SECTION_LABEL, 0);
12410 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12411 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12412 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12413 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12414 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12415 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12417 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12419 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12420 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12421 DEBUG_MACINFO_SECTION_LABEL, 0);
12422 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12425 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12428 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12432 /* A helper function for dwarf2out_finish called through
12433 ht_forall. Emit one queued .debug_str string. */
12436 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
12438 struct indirect_string_node *node = (struct indirect_string_node *) *h;
12440 if (node->form == DW_FORM_strp)
12442 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12443 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12444 assemble_string (node->str, strlen (node->str) + 1);
12452 /* Clear the marks for a die and its children.
12453 Be cool if the mark isn't set. */
12456 prune_unmark_dies (dw_die_ref die)
12460 for (c = die->die_child; c; c = c->die_sib)
12461 prune_unmark_dies (c);
12465 /* Given DIE that we're marking as used, find any other dies
12466 it references as attributes and mark them as used. */
12469 prune_unused_types_walk_attribs (dw_die_ref die)
12473 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
12475 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
12477 /* A reference to another DIE.
12478 Make sure that it will get emitted. */
12479 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
12481 else if (a->dw_attr == DW_AT_decl_file)
12483 /* A reference to a file. Make sure the file name is emitted. */
12484 a->dw_attr_val.v.val_unsigned =
12485 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
12491 /* Mark DIE as being used. If DOKIDS is true, then walk down
12492 to DIE's children. */
12495 prune_unused_types_mark (dw_die_ref die, int dokids)
12499 if (die->die_mark == 0)
12501 /* We haven't done this node yet. Mark it as used. */
12504 /* We also have to mark its parents as used.
12505 (But we don't want to mark our parents' kids due to this.) */
12506 if (die->die_parent)
12507 prune_unused_types_mark (die->die_parent, 0);
12509 /* Mark any referenced nodes. */
12510 prune_unused_types_walk_attribs (die);
12513 if (dokids && die->die_mark != 2)
12515 /* We need to walk the children, but haven't done so yet.
12516 Remember that we've walked the kids. */
12520 for (c = die->die_child; c; c = c->die_sib)
12522 /* If this is an array type, we need to make sure our
12523 kids get marked, even if they're types. */
12524 if (die->die_tag == DW_TAG_array_type)
12525 prune_unused_types_mark (c, 1);
12527 prune_unused_types_walk (c);
12533 /* Walk the tree DIE and mark types that we actually use. */
12536 prune_unused_types_walk (dw_die_ref die)
12540 /* Don't do anything if this node is already marked. */
12544 switch (die->die_tag) {
12545 case DW_TAG_const_type:
12546 case DW_TAG_packed_type:
12547 case DW_TAG_pointer_type:
12548 case DW_TAG_reference_type:
12549 case DW_TAG_volatile_type:
12550 case DW_TAG_typedef:
12551 case DW_TAG_array_type:
12552 case DW_TAG_structure_type:
12553 case DW_TAG_union_type:
12554 case DW_TAG_class_type:
12555 case DW_TAG_friend:
12556 case DW_TAG_variant_part:
12557 case DW_TAG_enumeration_type:
12558 case DW_TAG_subroutine_type:
12559 case DW_TAG_string_type:
12560 case DW_TAG_set_type:
12561 case DW_TAG_subrange_type:
12562 case DW_TAG_ptr_to_member_type:
12563 case DW_TAG_file_type:
12564 /* It's a type node --- don't mark it. */
12568 /* Mark everything else. */
12574 /* Now, mark any dies referenced from here. */
12575 prune_unused_types_walk_attribs (die);
12577 /* Mark children. */
12578 for (c = die->die_child; c; c = c->die_sib)
12579 prune_unused_types_walk (c);
12583 /* Remove from the tree DIE any dies that aren't marked. */
12586 prune_unused_types_prune (dw_die_ref die)
12588 dw_die_ref c, p, n;
12589 if (!die->die_mark)
12593 for (c = die->die_child; c; c = n)
12598 prune_unused_types_prune (c);
12606 die->die_child = n;
12613 /* Remove dies representing declarations that we never use. */
12616 prune_unused_types (void)
12619 limbo_die_node *node;
12621 /* Clear all the marks. */
12622 prune_unmark_dies (comp_unit_die);
12623 for (node = limbo_die_list; node; node = node->next)
12624 prune_unmark_dies (node->die);
12626 /* Set the mark on nodes that are actually used. */
12627 prune_unused_types_walk (comp_unit_die);
12628 for (node = limbo_die_list; node; node = node->next)
12629 prune_unused_types_walk (node->die);
12631 /* Also set the mark on nodes referenced from the
12632 pubname_table or arange_table. */
12633 for (i = 0; i < pubname_table_in_use; i++)
12634 prune_unused_types_mark (pubname_table[i].die, 1);
12635 for (i = 0; i < arange_table_in_use; i++)
12636 prune_unused_types_mark (arange_table[i], 1);
12638 /* Get rid of nodes that aren't marked. */
12639 prune_unused_types_prune (comp_unit_die);
12640 for (node = limbo_die_list; node; node = node->next)
12641 prune_unused_types_prune (node->die);
12643 /* Leave the marks clear. */
12644 prune_unmark_dies (comp_unit_die);
12645 for (node = limbo_die_list; node; node = node->next)
12646 prune_unmark_dies (node->die);
12649 /* Output stuff that dwarf requires at the end of every file,
12650 and generate the DWARF-2 debugging info. */
12653 dwarf2out_finish (const char *filename)
12655 limbo_die_node *node, *next_node;
12656 dw_die_ref die = 0;
12658 /* Add the name for the main input file now. We delayed this from
12659 dwarf2out_init to avoid complications with PCH. */
12660 add_name_attribute (comp_unit_die, filename);
12661 if (filename[0] != DIR_SEPARATOR)
12662 add_comp_dir_attribute (comp_unit_die);
12663 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
12666 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
12667 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
12668 /* Don't add cwd for <built-in>. */
12669 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
12671 add_comp_dir_attribute (comp_unit_die);
12676 /* Traverse the limbo die list, and add parent/child links. The only
12677 dies without parents that should be here are concrete instances of
12678 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12679 For concrete instances, we can get the parent die from the abstract
12681 for (node = limbo_die_list; node; node = next_node)
12683 next_node = node->next;
12686 if (die->die_parent == NULL)
12688 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12692 add_child_die (origin->die_parent, die);
12693 else if (die == comp_unit_die)
12695 /* If this was an expression for a bound involved in a function
12696 return type, it may be a SAVE_EXPR for which we weren't able
12697 to find a DIE previously. So try now. */
12698 else if (node->created_for
12699 && TREE_CODE (node->created_for) == SAVE_EXPR
12700 && 0 != (origin = (lookup_decl_die
12702 (node->created_for)))))
12703 add_child_die (origin, die);
12704 else if (errorcount > 0 || sorrycount > 0)
12705 /* It's OK to be confused by errors in the input. */
12706 add_child_die (comp_unit_die, die);
12707 else if (node->created_for
12708 && ((DECL_P (node->created_for)
12709 && (context = DECL_CONTEXT (node->created_for)))
12710 || (TYPE_P (node->created_for)
12711 && (context = TYPE_CONTEXT (node->created_for))))
12712 && TREE_CODE (context) == FUNCTION_DECL)
12714 /* In certain situations, the lexical block containing a
12715 nested function can be optimized away, which results
12716 in the nested function die being orphaned. Likewise
12717 with the return type of that nested function. Force
12718 this to be a child of the containing function. */
12719 origin = lookup_decl_die (context);
12722 add_child_die (origin, die);
12729 limbo_die_list = NULL;
12731 /* Walk through the list of incomplete types again, trying once more to
12732 emit full debugging info for them. */
12733 retry_incomplete_types ();
12735 /* We need to reverse all the dies before break_out_includes, or
12736 we'll see the end of an include file before the beginning. */
12737 reverse_all_dies (comp_unit_die);
12739 if (flag_eliminate_unused_debug_types)
12740 prune_unused_types ();
12742 /* Generate separate CUs for each of the include files we've seen.
12743 They will go into limbo_die_list. */
12744 if (flag_eliminate_dwarf2_dups)
12745 break_out_includes (comp_unit_die);
12747 /* Traverse the DIE's and add add sibling attributes to those DIE's
12748 that have children. */
12749 add_sibling_attributes (comp_unit_die);
12750 for (node = limbo_die_list; node; node = node->next)
12751 add_sibling_attributes (node->die);
12753 /* Output a terminator label for the .text section. */
12755 (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0);
12757 /* Output the source line correspondence table. We must do this
12758 even if there is no line information. Otherwise, on an empty
12759 translation unit, we will generate a present, but empty,
12760 .debug_info section. IRIX 6.5 `nm' will then complain when
12761 examining the file. */
12762 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12764 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12765 output_line_info ();
12768 /* Output location list section if necessary. */
12769 if (have_location_lists)
12771 /* Output the location lists info. */
12772 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12773 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12774 DEBUG_LOC_SECTION_LABEL, 0);
12775 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12776 output_location_lists (die);
12777 have_location_lists = 0;
12780 /* We can only use the low/high_pc attributes if all of the code was
12782 if (separate_line_info_table_in_use == 0)
12784 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12785 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12788 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12789 "base address". Use zero so that these addresses become absolute. */
12790 else if (have_location_lists || ranges_table_in_use)
12791 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12793 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12794 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12795 debug_line_section_label);
12797 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12798 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12800 /* Output all of the compilation units. We put the main one last so that
12801 the offsets are available to output_pubnames. */
12802 for (node = limbo_die_list; node; node = node->next)
12803 output_comp_unit (node->die, 0);
12805 output_comp_unit (comp_unit_die, 0);
12807 /* Output the abbreviation table. */
12808 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12809 output_abbrev_section ();
12811 /* Output public names table if necessary. */
12812 if (pubname_table_in_use)
12814 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12815 output_pubnames ();
12818 /* Output the address range information. We only put functions in the arange
12819 table, so don't write it out if we don't have any. */
12820 if (fde_table_in_use)
12822 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12826 /* Output ranges section if necessary. */
12827 if (ranges_table_in_use)
12829 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12830 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12834 /* Have to end the primary source file. */
12835 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12837 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12838 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12839 dw2_asm_output_data (1, 0, "End compilation unit");
12842 /* If we emitted any DW_FORM_strp form attribute, output the string
12844 if (debug_str_hash)
12845 htab_traverse (debug_str_hash, output_indirect_string, NULL);
12849 /* This should never be used, but its address is needed for comparisons. */
12850 const struct gcc_debug_hooks dwarf2_debug_hooks;
12852 #endif /* DWARF2_DEBUGGING_INFO */
12854 #include "gt-dwarf2out.h"