1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 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
42 #include "hard-reg-set.h"
44 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
62 #include "langhooks.h"
63 #include "hashtable.h"
65 #ifdef DWARF2_DEBUGGING_INFO
66 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
69 /* DWARF2 Abbreviation Glossary:
70 CFA = Canonical Frame Address
71 a fixed address on the stack which identifies a call frame.
72 We define it to be the value of SP just before the call insn.
73 The CFA register and offset, which may change during the course
74 of the function, are used to calculate its value at runtime.
75 CFI = Call Frame Instruction
76 an instruction for the DWARF2 abstract machine
77 CIE = Common Information Entry
78 information describing information common to one or more FDEs
79 DIE = Debugging Information Entry
80 FDE = Frame Description Entry
81 information describing the stack call frame, in particular,
82 how to restore registers
84 DW_CFA_... = DWARF2 CFA call frame instruction
85 DW_TAG_... = DWARF2 DIE tag */
87 /* Decide whether we want to emit frame unwind information for the current
93 return (write_symbols == DWARF2_DEBUG
94 || write_symbols == VMS_AND_DWARF2_DEBUG
95 #ifdef DWARF2_FRAME_INFO
98 #ifdef DWARF2_UNWIND_INFO
100 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
105 /* The number of the current function definition for which debugging
106 information is being generated. These numbers range from 1 up to the
107 maximum number of function definitions contained within the current
108 compilation unit. These numbers are used to create unique label id's
109 unique to each function definition. */
110 unsigned current_funcdef_number = 0;
112 /* The size of the target's pointer type. */
114 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
117 /* Default version of targetm.eh_frame_section. Note this must appear
118 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
122 default_eh_frame_section ()
124 #ifdef EH_FRAME_SECTION_NAME
125 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
127 tree label = get_file_function_name ('F');
130 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
131 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
132 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
136 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
138 /* How to start an assembler comment. */
139 #ifndef ASM_COMMENT_START
140 #define ASM_COMMENT_START ";#"
143 typedef struct dw_cfi_struct *dw_cfi_ref;
144 typedef struct dw_fde_struct *dw_fde_ref;
145 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
147 /* Call frames are described using a sequence of Call Frame
148 Information instructions. The register number, offset
149 and address fields are provided as possible operands;
150 their use is selected by the opcode field. */
152 typedef union dw_cfi_oprnd_struct
154 unsigned long dw_cfi_reg_num;
155 long int dw_cfi_offset;
156 const char *dw_cfi_addr;
157 struct dw_loc_descr_struct *dw_cfi_loc;
161 typedef struct dw_cfi_struct
163 dw_cfi_ref dw_cfi_next;
164 enum dwarf_call_frame_info dw_cfi_opc;
165 dw_cfi_oprnd dw_cfi_oprnd1;
166 dw_cfi_oprnd dw_cfi_oprnd2;
170 /* This is how we define the location of the CFA. We use to handle it
171 as REG + OFFSET all the time, but now it can be more complex.
172 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
173 Instead of passing around REG and OFFSET, we pass a copy
174 of this structure. */
175 typedef struct cfa_loc
180 int indirect; /* 1 if CFA is accessed via a dereference. */
183 /* All call frame descriptions (FDE's) in the GCC generated DWARF
184 refer to a single Common Information Entry (CIE), defined at
185 the beginning of the .debug_frame section. This use of a single
186 CIE obviates the need to keep track of multiple CIE's
187 in the DWARF generation routines below. */
189 typedef struct dw_fde_struct
191 const char *dw_fde_begin;
192 const char *dw_fde_current_label;
193 const char *dw_fde_end;
194 dw_cfi_ref dw_fde_cfi;
195 unsigned funcdef_number;
196 unsigned nothrow : 1;
197 unsigned uses_eh_lsda : 1;
201 /* Maximum size (in bytes) of an artificially generated label. */
202 #define MAX_ARTIFICIAL_LABEL_BYTES 30
204 /* The size of addresses as they appear in the Dwarf 2 data.
205 Some architectures use word addresses to refer to code locations,
206 but Dwarf 2 info always uses byte addresses. On such machines,
207 Dwarf 2 addresses need to be larger than the architecture's
209 #ifndef DWARF2_ADDR_SIZE
210 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
213 /* The size in bytes of a DWARF field indicating an offset or length
214 relative to a debug info section, specified to be 4 bytes in the
215 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
218 #ifndef DWARF_OFFSET_SIZE
219 #define DWARF_OFFSET_SIZE 4
222 #define DWARF_VERSION 2
224 /* Round SIZE up to the nearest BOUNDARY. */
225 #define DWARF_ROUND(SIZE,BOUNDARY) \
226 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
228 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
229 #ifndef DWARF_CIE_DATA_ALIGNMENT
230 #ifdef STACK_GROWS_DOWNWARD
231 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
233 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
235 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
237 /* A pointer to the base of a table that contains frame description
238 information for each routine. */
239 static dw_fde_ref fde_table;
241 /* Number of elements currently allocated for fde_table. */
242 static unsigned fde_table_allocated;
244 /* Number of elements in fde_table currently in use. */
245 static unsigned fde_table_in_use;
247 /* Size (in elements) of increments by which we may expand the
249 #define FDE_TABLE_INCREMENT 256
251 /* A list of call frame insns for the CIE. */
252 static dw_cfi_ref cie_cfi_head;
254 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
255 attribute that accelerates the lookup of the FDE associated
256 with the subprogram. This variable holds the table index of the FDE
257 associated with the current function (body) definition. */
258 static unsigned current_funcdef_fde;
260 struct ht *debug_str_hash;
262 struct indirect_string_node
264 struct ht_identifier id;
265 unsigned int refcount;
270 /* Forward declarations for functions defined in this file. */
272 static char *stripattributes PARAMS ((const char *));
273 static const char *dwarf_cfi_name PARAMS ((unsigned));
274 static dw_cfi_ref new_cfi PARAMS ((void));
275 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
276 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
277 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
278 static void lookup_cfa PARAMS ((dw_cfa_location *));
279 static void reg_save PARAMS ((const char *, unsigned,
281 static void initial_return_save PARAMS ((rtx));
282 static long stack_adjust_offset PARAMS ((rtx));
283 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
284 static void output_call_frame_info PARAMS ((int));
285 static void dwarf2out_stack_adjust PARAMS ((rtx));
286 static void queue_reg_save PARAMS ((const char *, rtx, long));
287 static void flush_queued_reg_saves PARAMS ((void));
288 static bool clobbers_queued_reg_save PARAMS ((rtx));
289 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
291 /* Support for complex CFA locations. */
292 static void output_cfa_loc PARAMS ((dw_cfi_ref));
293 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
294 struct dw_loc_descr_struct *));
295 static struct dw_loc_descr_struct *build_cfa_loc
296 PARAMS ((dw_cfa_location *));
297 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
299 /* .debug_str support. */
300 static hashnode indirect_string_alloc PARAMS ((hash_table *));
301 static int output_indirect_string PARAMS ((struct cpp_reader *,
302 hashnode, const PTR));
304 /* How to start an assembler comment. */
305 #ifndef ASM_COMMENT_START
306 #define ASM_COMMENT_START ";#"
309 /* Data and reference forms for relocatable data. */
310 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
311 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
313 /* Pseudo-op for defining a new section. */
314 #ifndef SECTION_ASM_OP
315 #define SECTION_ASM_OP "\t.section\t"
318 #ifndef DEBUG_FRAME_SECTION
319 #define DEBUG_FRAME_SECTION ".debug_frame"
322 #ifndef FUNC_BEGIN_LABEL
323 #define FUNC_BEGIN_LABEL "LFB"
325 #ifndef FUNC_END_LABEL
326 #define FUNC_END_LABEL "LFE"
328 #define FRAME_BEGIN_LABEL "Lframe"
329 #define CIE_AFTER_SIZE_LABEL "LSCIE"
330 #define CIE_END_LABEL "LECIE"
331 #define CIE_LENGTH_LABEL "LLCIE"
332 #define FDE_LABEL "LSFDE"
333 #define FDE_AFTER_SIZE_LABEL "LASFDE"
334 #define FDE_END_LABEL "LEFDE"
335 #define FDE_LENGTH_LABEL "LLFDE"
336 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
337 #define LINE_NUMBER_END_LABEL "LELT"
338 #define LN_PROLOG_AS_LABEL "LASLTP"
339 #define LN_PROLOG_END_LABEL "LELTP"
340 #define DIE_LABEL_PREFIX "DW"
342 /* Definitions of defaults for various types of primitive assembly language
343 output operations. These may be overridden from within the tm.h file,
344 but typically, that is unnecessary. */
347 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
348 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
350 fprintf (FILE, "%s", SET_ASM_OP); \
351 assemble_name (FILE, SY); \
353 assemble_name (FILE, HI); \
355 assemble_name (FILE, LO); \
358 #endif /* SET_ASM_OP */
360 /* The DWARF 2 CFA column which tracks the return address. Normally this
361 is the column for PC, or the first column after all of the hard
363 #ifndef DWARF_FRAME_RETURN_COLUMN
365 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
367 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
371 /* The mapping from gcc register number to DWARF 2 CFA column number. By
372 default, we just provide columns for all registers. */
373 #ifndef DWARF_FRAME_REGNUM
374 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
377 /* Hook used by __throw. */
380 expand_builtin_dwarf_fp_regnum ()
382 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
385 /* The offset from the incoming value of %sp to the top of the stack frame
386 for the current function. */
387 #ifndef INCOMING_FRAME_SP_OFFSET
388 #define INCOMING_FRAME_SP_OFFSET 0
391 /* Return a pointer to a copy of the section string name S with all
392 attributes stripped off, and an asterisk prepended (for assemble_name). */
398 char *stripped = xmalloc (strlen (s) + 2);
403 while (*s && *s != ',')
410 /* Generate code to initialize the register size table. */
413 expand_builtin_init_dwarf_reg_sizes (address)
417 enum machine_mode mode = TYPE_MODE (char_type_node);
418 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
419 rtx mem = gen_rtx_MEM (mode, addr);
421 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
423 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
424 int size = GET_MODE_SIZE (reg_raw_mode[i]);
429 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
433 /* Convert a DWARF call frame info. operation to its string name */
436 dwarf_cfi_name (cfi_opc)
441 case DW_CFA_advance_loc:
442 return "DW_CFA_advance_loc";
444 return "DW_CFA_offset";
446 return "DW_CFA_restore";
450 return "DW_CFA_set_loc";
451 case DW_CFA_advance_loc1:
452 return "DW_CFA_advance_loc1";
453 case DW_CFA_advance_loc2:
454 return "DW_CFA_advance_loc2";
455 case DW_CFA_advance_loc4:
456 return "DW_CFA_advance_loc4";
457 case DW_CFA_offset_extended:
458 return "DW_CFA_offset_extended";
459 case DW_CFA_restore_extended:
460 return "DW_CFA_restore_extended";
461 case DW_CFA_undefined:
462 return "DW_CFA_undefined";
463 case DW_CFA_same_value:
464 return "DW_CFA_same_value";
465 case DW_CFA_register:
466 return "DW_CFA_register";
467 case DW_CFA_remember_state:
468 return "DW_CFA_remember_state";
469 case DW_CFA_restore_state:
470 return "DW_CFA_restore_state";
472 return "DW_CFA_def_cfa";
473 case DW_CFA_def_cfa_register:
474 return "DW_CFA_def_cfa_register";
475 case DW_CFA_def_cfa_offset:
476 return "DW_CFA_def_cfa_offset";
477 case DW_CFA_def_cfa_expression:
478 return "DW_CFA_def_cfa_expression";
480 /* SGI/MIPS specific */
481 case DW_CFA_MIPS_advance_loc8:
482 return "DW_CFA_MIPS_advance_loc8";
485 case DW_CFA_GNU_window_save:
486 return "DW_CFA_GNU_window_save";
487 case DW_CFA_GNU_args_size:
488 return "DW_CFA_GNU_args_size";
489 case DW_CFA_GNU_negative_offset_extended:
490 return "DW_CFA_GNU_negative_offset_extended";
493 return "DW_CFA_<unknown>";
497 /* Return a pointer to a newly allocated Call Frame Instruction. */
499 static inline dw_cfi_ref
502 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
504 cfi->dw_cfi_next = NULL;
505 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
506 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
511 /* Add a Call Frame Instruction to list of instructions. */
514 add_cfi (list_head, cfi)
515 dw_cfi_ref *list_head;
520 /* Find the end of the chain. */
521 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
527 /* Generate a new label for the CFI info to refer to. */
530 dwarf2out_cfi_label ()
532 static char label[20];
533 static unsigned long label_num = 0;
535 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
536 ASM_OUTPUT_LABEL (asm_out_file, label);
541 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
542 or to the CIE if LABEL is NULL. */
545 add_fde_cfi (label, cfi)
551 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
554 label = dwarf2out_cfi_label ();
556 if (fde->dw_fde_current_label == NULL
557 || strcmp (label, fde->dw_fde_current_label) != 0)
561 fde->dw_fde_current_label = label = xstrdup (label);
563 /* Set the location counter to the new label. */
565 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
566 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
567 add_cfi (&fde->dw_fde_cfi, xcfi);
570 add_cfi (&fde->dw_fde_cfi, cfi);
574 add_cfi (&cie_cfi_head, cfi);
577 /* Subroutine of lookup_cfa. */
580 lookup_cfa_1 (cfi, loc)
582 dw_cfa_location *loc;
584 switch (cfi->dw_cfi_opc)
586 case DW_CFA_def_cfa_offset:
587 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
589 case DW_CFA_def_cfa_register:
590 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
593 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
594 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
596 case DW_CFA_def_cfa_expression:
597 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
604 /* Find the previous value for the CFA. */
608 dw_cfa_location *loc;
612 loc->reg = (unsigned long) -1;
615 loc->base_offset = 0;
617 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
618 lookup_cfa_1 (cfi, loc);
620 if (fde_table_in_use)
622 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
623 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
624 lookup_cfa_1 (cfi, loc);
628 /* The current rule for calculating the DWARF2 canonical frame address. */
629 static dw_cfa_location cfa;
631 /* The register used for saving registers to the stack, and its offset
633 static dw_cfa_location cfa_store;
635 /* The running total of the size of arguments pushed onto the stack. */
636 static long args_size;
638 /* The last args_size we actually output. */
639 static long old_args_size;
641 /* Entry point to update the canonical frame address (CFA).
642 LABEL is passed to add_fde_cfi. The value of CFA is now to be
643 calculated from REG+OFFSET. */
646 dwarf2out_def_cfa (label, reg, offset)
656 def_cfa_1 (label, &loc);
659 /* This routine does the actual work. The CFA is now calculated from
660 the dw_cfa_location structure. */
662 def_cfa_1 (label, loc_p)
664 dw_cfa_location *loc_p;
667 dw_cfa_location old_cfa, loc;
672 if (cfa_store.reg == loc.reg && loc.indirect == 0)
673 cfa_store.offset = loc.offset;
675 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
676 lookup_cfa (&old_cfa);
678 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
679 loc.indirect == old_cfa.indirect)
681 if (loc.indirect == 0
682 || loc.base_offset == old_cfa.base_offset)
683 /* Nothing changed so no need to issue any call frame
690 if (loc.reg == old_cfa.reg && !loc.indirect)
692 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
693 indicating the CFA register did not change but the offset
695 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
696 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
699 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
700 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
703 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
704 indicating the CFA register has changed to <register> but the
705 offset has not changed. */
706 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
707 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
711 else if (loc.indirect == 0)
713 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
714 indicating the CFA register has changed to <register> with
715 the specified offset. */
716 cfi->dw_cfi_opc = DW_CFA_def_cfa;
717 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
718 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
722 /* Construct a DW_CFA_def_cfa_expression instruction to
723 calculate the CFA using a full location expression since no
724 register-offset pair is available. */
725 struct dw_loc_descr_struct *loc_list;
726 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
727 loc_list = build_cfa_loc (&loc);
728 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
731 add_fde_cfi (label, cfi);
734 /* Add the CFI for saving a register. REG is the CFA column number.
735 LABEL is passed to add_fde_cfi.
736 If SREG is -1, the register is saved at OFFSET from the CFA;
737 otherwise it is saved in SREG. */
740 reg_save (label, reg, sreg, offset)
746 dw_cfi_ref cfi = new_cfi ();
748 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
750 /* The following comparison is correct. -1 is used to indicate that
751 the value isn't a register number. */
752 if (sreg == (unsigned int) -1)
755 /* The register number won't fit in 6 bits, so we have to use
757 cfi->dw_cfi_opc = DW_CFA_offset_extended;
759 cfi->dw_cfi_opc = DW_CFA_offset;
761 #ifdef ENABLE_CHECKING
763 /* If we get an offset that is not a multiple of
764 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
765 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
767 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
769 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
773 offset /= DWARF_CIE_DATA_ALIGNMENT;
776 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
779 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
781 else if (sreg == reg)
782 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
786 cfi->dw_cfi_opc = DW_CFA_register;
787 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
790 add_fde_cfi (label, cfi);
793 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
794 This CFI tells the unwinder that it needs to restore the window registers
795 from the previous frame's window save area.
797 ??? Perhaps we should note in the CIE where windows are saved (instead of
798 assuming 0(cfa)) and what registers are in the window. */
801 dwarf2out_window_save (label)
804 dw_cfi_ref cfi = new_cfi ();
805 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
806 add_fde_cfi (label, cfi);
809 /* Add a CFI to update the running total of the size of arguments
810 pushed onto the stack. */
813 dwarf2out_args_size (label, size)
819 if (size == old_args_size)
821 old_args_size = size;
824 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
825 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
826 add_fde_cfi (label, cfi);
829 /* Entry point for saving a register to the stack. REG is the GCC register
830 number. LABEL and OFFSET are passed to reg_save. */
833 dwarf2out_reg_save (label, reg, offset)
838 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
841 /* Entry point for saving the return address in the stack.
842 LABEL and OFFSET are passed to reg_save. */
845 dwarf2out_return_save (label, offset)
849 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
852 /* Entry point for saving the return address in a register.
853 LABEL and SREG are passed to reg_save. */
856 dwarf2out_return_reg (label, sreg)
860 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
863 /* Record the initial position of the return address. RTL is
864 INCOMING_RETURN_ADDR_RTX. */
867 initial_return_save (rtl)
870 unsigned int reg = (unsigned int) -1;
873 switch (GET_CODE (rtl))
876 /* RA is in a register. */
877 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
880 /* RA is on the stack. */
882 switch (GET_CODE (rtl))
885 if (REGNO (rtl) != STACK_POINTER_REGNUM)
890 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
892 offset = INTVAL (XEXP (rtl, 1));
895 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
897 offset = -INTVAL (XEXP (rtl, 1));
904 /* The return address is at some offset from any value we can
905 actually load. For instance, on the SPARC it is in %i7+8. Just
906 ignore the offset for now; it doesn't matter for unwinding frames. */
907 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
909 initial_return_save (XEXP (rtl, 0));
915 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
918 /* Given a SET, calculate the amount of stack adjustment it
922 stack_adjust_offset (pattern)
925 rtx src = SET_SRC (pattern);
926 rtx dest = SET_DEST (pattern);
930 if (dest == stack_pointer_rtx)
932 /* (set (reg sp) (plus (reg sp) (const_int))) */
933 code = GET_CODE (src);
934 if (! (code == PLUS || code == MINUS)
935 || XEXP (src, 0) != stack_pointer_rtx
936 || GET_CODE (XEXP (src, 1)) != CONST_INT)
939 offset = INTVAL (XEXP (src, 1));
941 else if (GET_CODE (dest) == MEM)
943 /* (set (mem (pre_dec (reg sp))) (foo)) */
944 src = XEXP (dest, 0);
945 code = GET_CODE (src);
947 if (! (code == PRE_DEC || code == PRE_INC
948 || code == PRE_MODIFY)
949 || XEXP (src, 0) != stack_pointer_rtx)
952 if (code == PRE_MODIFY)
954 rtx val = XEXP (XEXP (src, 1), 1);
955 /* We handle only adjustments by constant amount. */
956 if (GET_CODE (XEXP (src, 1)) != PLUS ||
957 GET_CODE (val) != CONST_INT)
959 offset = -INTVAL (val);
961 else offset = GET_MODE_SIZE (GET_MODE (dest));
966 if (code == PLUS || code == PRE_INC)
972 /* Check INSN to see if it looks like a push or a stack adjustment, and
973 make a note of it if it does. EH uses this information to find out how
974 much extra space it needs to pop off the stack. */
977 dwarf2out_stack_adjust (insn)
983 if (!flag_asynchronous_unwind_tables
984 && GET_CODE (insn) == CALL_INSN)
986 /* Extract the size of the args from the CALL rtx itself. */
988 insn = PATTERN (insn);
989 if (GET_CODE (insn) == PARALLEL)
990 insn = XVECEXP (insn, 0, 0);
991 if (GET_CODE (insn) == SET)
992 insn = SET_SRC (insn);
993 if (GET_CODE (insn) != CALL)
995 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
999 /* If only calls can throw, and we have a frame pointer,
1000 save up adjustments until we see the CALL_INSN. */
1001 else if (!flag_asynchronous_unwind_tables
1002 && cfa.reg != STACK_POINTER_REGNUM)
1005 if (GET_CODE (insn) == BARRIER)
1007 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1008 the compiler will have already emitted a stack adjustment, but
1009 doesn't bother for calls to noreturn functions. */
1010 #ifdef STACK_GROWS_DOWNWARD
1011 offset = -args_size;
1016 else if (GET_CODE (PATTERN (insn)) == SET)
1018 offset = stack_adjust_offset (PATTERN (insn));
1020 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1021 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1023 /* There may be stack adjustments inside compound insns. Search
1028 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1030 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1031 if (GET_CODE (pattern) == SET)
1032 offset += stack_adjust_offset (pattern);
1041 if (cfa.reg == STACK_POINTER_REGNUM)
1042 cfa.offset += offset;
1044 #ifndef STACK_GROWS_DOWNWARD
1047 args_size += offset;
1051 label = dwarf2out_cfi_label ();
1052 def_cfa_1 (label, &cfa);
1053 dwarf2out_args_size (label, args_size);
1056 /* We delay emitting a register save until either (a) we reach the end
1057 of the prologue or (b) the register is clobbered. This clusters
1058 register saves so that there are fewer pc advances. */
1060 struct queued_reg_save
1062 struct queued_reg_save *next;
1067 static struct queued_reg_save *queued_reg_saves;
1068 static const char *last_reg_save_label;
1071 queue_reg_save (label, reg, offset)
1076 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1078 q->next = queued_reg_saves;
1080 q->cfa_offset = offset;
1081 queued_reg_saves = q;
1083 last_reg_save_label = label;
1087 flush_queued_reg_saves ()
1089 struct queued_reg_save *q, *next;
1091 for (q = queued_reg_saves; q ; q = next)
1093 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1098 queued_reg_saves = NULL;
1099 last_reg_save_label = NULL;
1103 clobbers_queued_reg_save (insn)
1106 struct queued_reg_save *q;
1108 for (q = queued_reg_saves; q ; q = q->next)
1109 if (modified_in_p (q->reg, insn))
1116 /* A temporary register holding an integral value used in adjusting SP
1117 or setting up the store_reg. The "offset" field holds the integer
1118 value, not an offset. */
1119 static dw_cfa_location cfa_temp;
1121 /* Record call frame debugging information for an expression EXPR,
1122 which either sets SP or FP (adjusting how we calculate the frame
1123 address) or saves a register to the stack. LABEL indicates the
1126 This function encodes a state machine mapping rtxes to actions on
1127 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1128 users need not read the source code.
1130 The High-Level Picture
1132 Changes in the register we use to calculate the CFA: Currently we
1133 assume that if you copy the CFA register into another register, we
1134 should take the other one as the new CFA register; this seems to
1135 work pretty well. If it's wrong for some target, it's simple
1136 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1138 Changes in the register we use for saving registers to the stack:
1139 This is usually SP, but not always. Again, we deduce that if you
1140 copy SP into another register (and SP is not the CFA register),
1141 then the new register is the one we will be using for register
1142 saves. This also seems to work.
1144 Register saves: There's not much guesswork about this one; if
1145 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1146 register save, and the register used to calculate the destination
1147 had better be the one we think we're using for this purpose.
1149 Except: If the register being saved is the CFA register, and the
1150 offset is non-zero, we are saving the CFA, so we assume we have to
1151 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1152 the intent is to save the value of SP from the previous frame.
1154 Invariants / Summaries of Rules
1156 cfa current rule for calculating the CFA. It usually
1157 consists of a register and an offset.
1158 cfa_store register used by prologue code to save things to the stack
1159 cfa_store.offset is the offset from the value of
1160 cfa_store.reg to the actual CFA
1161 cfa_temp register holding an integral value. cfa_temp.offset
1162 stores the value, which will be used to adjust the
1163 stack pointer. cfa_temp is also used like cfa_store,
1164 to track stores to the stack via fp or a temp reg.
1166 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1167 with cfa.reg as the first operand changes the cfa.reg and its
1168 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1171 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1172 expression yielding a constant. This sets cfa_temp.reg
1173 and cfa_temp.offset.
1175 Rule 5: Create a new register cfa_store used to save items to the
1178 Rules 10-14: Save a register to the stack. Define offset as the
1179 difference of the original location and cfa_store's
1180 location (or cfa_temp's location if cfa_temp is used).
1184 "{a,b}" indicates a choice of a xor b.
1185 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1188 (set <reg1> <reg2>:cfa.reg)
1189 effects: cfa.reg = <reg1>
1190 cfa.offset unchanged
1191 cfa_temp.reg = <reg1>
1192 cfa_temp.offset = cfa.offset
1195 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1196 effects: cfa.reg = sp if fp used
1197 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1198 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1199 if cfa_store.reg==sp
1202 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1203 effects: cfa.reg = fp
1204 cfa_offset += +/- <const_int>
1207 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1208 constraints: <reg1> != fp
1210 effects: cfa.reg = <reg1>
1211 cfa_temp.reg = <reg1>
1212 cfa_temp.offset = cfa.offset
1215 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1216 constraints: <reg1> != fp
1218 effects: cfa_store.reg = <reg1>
1219 cfa_store.offset = cfa.offset - cfa_temp.offset
1222 (set <reg> <const_int>)
1223 effects: cfa_temp.reg = <reg>
1224 cfa_temp.offset = <const_int>
1227 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1228 effects: cfa_temp.reg = <reg1>
1229 cfa_temp.offset |= <const_int>
1232 (set <reg> (high <exp>))
1236 (set <reg> (lo_sum <exp> <const_int>))
1237 effects: cfa_temp.reg = <reg>
1238 cfa_temp.offset = <const_int>
1241 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1242 effects: cfa_store.offset -= <const_int>
1243 cfa.offset = cfa_store.offset if cfa.reg == sp
1245 cfa.base_offset = -cfa_store.offset
1248 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1249 effects: cfa_store.offset += -/+ mode_size(mem)
1250 cfa.offset = cfa_store.offset if cfa.reg == sp
1252 cfa.base_offset = -cfa_store.offset
1255 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1256 effects: cfa.reg = <reg1>
1257 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1260 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1261 effects: cfa.reg = <reg1>
1262 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1265 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1266 effects: cfa.reg = <reg1>
1267 cfa.base_offset = -cfa_temp.offset
1268 cfa_temp.offset -= mode_size(mem) */
1271 dwarf2out_frame_debug_expr (expr, label)
1278 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1279 the PARALLEL independently. The first element is always processed if
1280 it is a SET. This is for backward compatibility. Other elements
1281 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1282 flag is set in them. */
1284 if (GET_CODE (expr) == PARALLEL
1285 || GET_CODE (expr) == SEQUENCE)
1288 int limit = XVECLEN (expr, 0);
1290 for (par_index = 0; par_index < limit; par_index++)
1292 rtx x = XVECEXP (expr, 0, par_index);
1294 if (GET_CODE (x) == SET &&
1295 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1296 dwarf2out_frame_debug_expr (x, label);
1301 if (GET_CODE (expr) != SET)
1304 src = SET_SRC (expr);
1305 dest = SET_DEST (expr);
1307 switch (GET_CODE (dest))
1311 /* Update the CFA rule wrt SP or FP. Make sure src is
1312 relative to the current CFA register. */
1313 switch (GET_CODE (src))
1315 /* Setting FP from SP. */
1317 if (cfa.reg == (unsigned) REGNO (src))
1323 /* We used to require that dest be either SP or FP, but the
1324 ARM copies SP to a temporary register, and from there to
1325 FP. So we just rely on the backends to only set
1326 RTX_FRAME_RELATED_P on appropriate insns. */
1327 cfa.reg = REGNO (dest);
1328 cfa_temp.reg = cfa.reg;
1329 cfa_temp.offset = cfa.offset;
1335 if (dest == stack_pointer_rtx)
1339 switch (GET_CODE (XEXP (src, 1)))
1342 offset = INTVAL (XEXP (src, 1));
1345 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1347 offset = cfa_temp.offset;
1353 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1355 /* Restoring SP from FP in the epilogue. */
1356 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1358 cfa.reg = STACK_POINTER_REGNUM;
1360 else if (GET_CODE (src) == LO_SUM)
1361 /* Assume we've set the source reg of the LO_SUM from sp. */
1363 else if (XEXP (src, 0) != stack_pointer_rtx)
1366 if (GET_CODE (src) != MINUS)
1368 if (cfa.reg == STACK_POINTER_REGNUM)
1369 cfa.offset += offset;
1370 if (cfa_store.reg == STACK_POINTER_REGNUM)
1371 cfa_store.offset += offset;
1373 else if (dest == hard_frame_pointer_rtx)
1376 /* Either setting the FP from an offset of the SP,
1377 or adjusting the FP */
1378 if (! frame_pointer_needed)
1381 if (GET_CODE (XEXP (src, 0)) == REG
1382 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1383 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1385 offset = INTVAL (XEXP (src, 1));
1386 if (GET_CODE (src) != MINUS)
1388 cfa.offset += offset;
1389 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1396 if (GET_CODE (src) == MINUS)
1400 if (GET_CODE (XEXP (src, 0)) == REG
1401 && REGNO (XEXP (src, 0)) == cfa.reg
1402 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1404 /* Setting a temporary CFA register that will be copied
1405 into the FP later on. */
1406 offset = - INTVAL (XEXP (src, 1));
1407 cfa.offset += offset;
1408 cfa.reg = REGNO (dest);
1409 /* Or used to save regs to the stack. */
1410 cfa_temp.reg = cfa.reg;
1411 cfa_temp.offset = cfa.offset;
1414 else if (GET_CODE (XEXP (src, 0)) == REG
1415 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1416 && XEXP (src, 1) == stack_pointer_rtx)
1418 /* Setting a scratch register that we will use instead
1419 of SP for saving registers to the stack. */
1420 if (cfa.reg != STACK_POINTER_REGNUM)
1422 cfa_store.reg = REGNO (dest);
1423 cfa_store.offset = cfa.offset - cfa_temp.offset;
1426 else if (GET_CODE (src) == LO_SUM
1427 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1429 cfa_temp.reg = REGNO (dest);
1430 cfa_temp.offset = INTVAL (XEXP (src, 1));
1439 cfa_temp.reg = REGNO (dest);
1440 cfa_temp.offset = INTVAL (src);
1445 if (GET_CODE (XEXP (src, 0)) != REG
1446 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1447 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1449 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1450 cfa_temp.reg = REGNO (dest);
1451 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1454 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1455 which will fill in all of the bits. */
1463 def_cfa_1 (label, &cfa);
1467 if (GET_CODE (src) != REG)
1470 /* Saving a register to the stack. Make sure dest is relative to the
1472 switch (GET_CODE (XEXP (dest, 0)))
1477 /* We can't handle variable size modifications. */
1478 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1480 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1482 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1483 || cfa_store.reg != STACK_POINTER_REGNUM)
1485 cfa_store.offset += offset;
1486 if (cfa.reg == STACK_POINTER_REGNUM)
1487 cfa.offset = cfa_store.offset;
1489 offset = -cfa_store.offset;
1494 offset = GET_MODE_SIZE (GET_MODE (dest));
1495 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1498 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1499 || cfa_store.reg != STACK_POINTER_REGNUM)
1501 cfa_store.offset += offset;
1502 if (cfa.reg == STACK_POINTER_REGNUM)
1503 cfa.offset = cfa_store.offset;
1505 offset = -cfa_store.offset;
1509 /* With an offset. */
1513 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1515 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1516 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1519 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1520 offset -= cfa_store.offset;
1521 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1522 offset -= cfa_temp.offset;
1528 /* Without an offset. */
1530 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1531 offset = -cfa_store.offset;
1532 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1533 offset = -cfa_temp.offset;
1540 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1542 offset = -cfa_temp.offset;
1543 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1550 if (REGNO (src) != STACK_POINTER_REGNUM
1551 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1552 && (unsigned) REGNO (src) == cfa.reg)
1554 /* We're storing the current CFA reg into the stack. */
1556 if (cfa.offset == 0)
1558 /* If the source register is exactly the CFA, assume
1559 we're saving SP like any other register; this happens
1562 def_cfa_1 (label, &cfa);
1563 queue_reg_save (label, stack_pointer_rtx, offset);
1568 /* Otherwise, we'll need to look in the stack to
1569 calculate the CFA. */
1571 rtx x = XEXP (dest, 0);
1572 if (GET_CODE (x) != REG)
1574 if (GET_CODE (x) != REG)
1576 cfa.reg = (unsigned) REGNO (x);
1577 cfa.base_offset = offset;
1579 def_cfa_1 (label, &cfa);
1584 def_cfa_1 (label, &cfa);
1585 queue_reg_save (label, src, offset);
1593 /* Record call frame debugging information for INSN, which either
1594 sets SP or FP (adjusting how we calculate the frame address) or saves a
1595 register to the stack. If INSN is NULL_RTX, initialize our state. */
1598 dwarf2out_frame_debug (insn)
1604 if (insn == NULL_RTX)
1606 /* Flush any queued register saves. */
1607 flush_queued_reg_saves ();
1609 /* Set up state for generating call frame debug info. */
1611 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1613 cfa.reg = STACK_POINTER_REGNUM;
1616 cfa_temp.offset = 0;
1620 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1621 flush_queued_reg_saves ();
1623 if (! RTX_FRAME_RELATED_P (insn))
1625 if (!ACCUMULATE_OUTGOING_ARGS)
1626 dwarf2out_stack_adjust (insn);
1630 label = dwarf2out_cfi_label ();
1632 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1634 insn = XEXP (src, 0);
1636 insn = PATTERN (insn);
1638 dwarf2out_frame_debug_expr (insn, label);
1641 /* Output a Call Frame Information opcode and its operand(s). */
1644 output_cfi (cfi, fde, for_eh)
1649 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1651 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1652 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1653 "DW_CFA_advance_loc 0x%lx",
1654 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1656 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1658 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1659 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1660 "DW_CFA_offset, column 0x%lx",
1661 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1662 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1664 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1666 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1667 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1668 "DW_CFA_restore, column 0x%lx",
1669 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1673 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1674 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1676 switch (cfi->dw_cfi_opc)
1678 case DW_CFA_set_loc:
1680 dw2_asm_output_encoded_addr_rtx (
1681 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1682 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1685 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1686 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1688 case DW_CFA_advance_loc1:
1689 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1690 fde->dw_fde_current_label, NULL);
1691 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1693 case DW_CFA_advance_loc2:
1694 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1695 fde->dw_fde_current_label, NULL);
1696 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1698 case DW_CFA_advance_loc4:
1699 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1700 fde->dw_fde_current_label, NULL);
1701 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1703 case DW_CFA_MIPS_advance_loc8:
1704 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1705 fde->dw_fde_current_label, NULL);
1706 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1708 case DW_CFA_offset_extended:
1709 case DW_CFA_GNU_negative_offset_extended:
1710 case DW_CFA_def_cfa:
1711 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1712 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1714 case DW_CFA_restore_extended:
1715 case DW_CFA_undefined:
1716 case DW_CFA_same_value:
1717 case DW_CFA_def_cfa_register:
1718 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1720 case DW_CFA_register:
1721 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1722 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1724 case DW_CFA_def_cfa_offset:
1725 case DW_CFA_GNU_args_size:
1726 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1728 case DW_CFA_GNU_window_save:
1730 case DW_CFA_def_cfa_expression:
1731 output_cfa_loc (cfi);
1739 /* Output the call frame information used to used to record information
1740 that relates to calculating the frame pointer, and records the
1741 location of saved registers. */
1744 output_call_frame_info (for_eh)
1750 char l1[20], l2[20], section_start_label[20];
1751 int any_lsda_needed = 0;
1752 char augmentation[6];
1753 int augmentation_size;
1754 int fde_encoding = DW_EH_PE_absptr;
1755 int per_encoding = DW_EH_PE_absptr;
1756 int lsda_encoding = DW_EH_PE_absptr;
1758 /* If we don't have any functions we'll want to unwind out of, don't
1759 emit any EH unwind information. */
1762 int any_eh_needed = flag_asynchronous_unwind_tables;
1763 for (i = 0; i < fde_table_in_use; ++i)
1764 if (fde_table[i].uses_eh_lsda)
1765 any_eh_needed = any_lsda_needed = 1;
1766 else if (! fde_table[i].nothrow)
1769 if (! any_eh_needed)
1773 /* We're going to be generating comments, so turn on app. */
1778 (*targetm.asm_out.eh_frame_section) ();
1780 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1782 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1783 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1785 /* Output the CIE. */
1786 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1787 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1788 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1789 "Length of Common Information Entry");
1790 ASM_OUTPUT_LABEL (asm_out_file, l1);
1792 /* Now that the CIE pointer is PC-relative for EH,
1793 use 0 to identify the CIE. */
1794 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1795 (for_eh ? 0 : DW_CIE_ID),
1796 "CIE Identifier Tag");
1798 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1800 augmentation[0] = 0;
1801 augmentation_size = 0;
1807 z Indicates that a uleb128 is present to size the
1808 augmentation section.
1809 L Indicates the encoding (and thus presence) of
1810 an LSDA pointer in the FDE augmentation.
1811 R Indicates a non-default pointer encoding for
1813 P Indicates the presence of an encoding + language
1814 personality routine in the CIE augmentation. */
1816 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1817 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1818 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1820 p = augmentation + 1;
1821 if (eh_personality_libfunc)
1824 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1826 if (any_lsda_needed)
1829 augmentation_size += 1;
1831 if (fde_encoding != DW_EH_PE_absptr)
1834 augmentation_size += 1;
1836 if (p > augmentation + 1)
1838 augmentation[0] = 'z';
1842 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1843 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1845 int offset = ( 4 /* Length */
1847 + 1 /* CIE version */
1848 + strlen (augmentation) + 1 /* Augmentation */
1849 + size_of_uleb128 (1) /* Code alignment */
1850 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1852 + 1 /* Augmentation size */
1853 + 1 /* Personality encoding */ );
1854 int pad = -offset & (PTR_SIZE - 1);
1856 augmentation_size += pad;
1858 /* Augmentations should be small, so there's scarce need to
1859 iterate for a solution. Die if we exceed one uleb128 byte. */
1860 if (size_of_uleb128 (augmentation_size) != 1)
1864 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1866 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1868 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1869 "CIE Data Alignment Factor");
1871 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1873 if (augmentation[0])
1875 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1876 if (eh_personality_libfunc)
1878 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1879 eh_data_format_name (per_encoding));
1880 dw2_asm_output_encoded_addr_rtx (per_encoding,
1881 eh_personality_libfunc, NULL);
1883 if (any_lsda_needed)
1884 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1885 eh_data_format_name (lsda_encoding));
1886 if (fde_encoding != DW_EH_PE_absptr)
1887 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1888 eh_data_format_name (fde_encoding));
1891 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1892 output_cfi (cfi, NULL, for_eh);
1894 /* Pad the CIE out to an address sized boundary. */
1895 ASM_OUTPUT_ALIGN (asm_out_file,
1896 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1897 ASM_OUTPUT_LABEL (asm_out_file, l2);
1899 /* Loop through all of the FDE's. */
1900 for (i = 0; i < fde_table_in_use; ++i)
1902 fde = &fde_table[i];
1904 /* Don't emit EH unwind info for leaf functions that don't need it. */
1905 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1908 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1909 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1910 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1911 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1913 ASM_OUTPUT_LABEL (asm_out_file, l1);
1916 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1918 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1923 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1924 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1925 "FDE initial location");
1926 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1927 fde->dw_fde_end, fde->dw_fde_begin,
1928 "FDE address range");
1932 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1933 "FDE initial location");
1934 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1935 fde->dw_fde_end, fde->dw_fde_begin,
1936 "FDE address range");
1939 if (augmentation[0])
1941 if (any_lsda_needed)
1943 int size = size_of_encoded_value (lsda_encoding);
1945 if (lsda_encoding == DW_EH_PE_aligned)
1947 int offset = ( 4 /* Length */
1948 + 4 /* CIE offset */
1949 + 2 * size_of_encoded_value (fde_encoding)
1950 + 1 /* Augmentation size */ );
1951 int pad = -offset & (PTR_SIZE - 1);
1954 if (size_of_uleb128 (size) != 1)
1958 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1960 if (fde->uses_eh_lsda)
1962 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1963 fde->funcdef_number);
1964 dw2_asm_output_encoded_addr_rtx (
1965 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1966 "Language Specific Data Area");
1970 if (lsda_encoding == DW_EH_PE_aligned)
1971 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1972 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1973 0, "Language Specific Data Area (none)");
1977 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1980 /* Loop through the Call Frame Instructions associated with
1982 fde->dw_fde_current_label = fde->dw_fde_begin;
1983 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1984 output_cfi (cfi, fde, for_eh);
1986 /* Pad the FDE out to an address sized boundary. */
1987 ASM_OUTPUT_ALIGN (asm_out_file,
1988 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1989 ASM_OUTPUT_LABEL (asm_out_file, l2);
1992 #ifndef EH_FRAME_SECTION_NAME
1994 dw2_asm_output_data (4, 0, "End of Table");
1996 #ifdef MIPS_DEBUGGING_INFO
1997 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1998 get a value of 0. Putting .align 0 after the label fixes it. */
1999 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2002 /* Turn off app to make assembly quicker. */
2007 /* Output a marker (i.e. a label) for the beginning of a function, before
2011 dwarf2out_begin_prologue (line, file)
2012 unsigned int line ATTRIBUTE_UNUSED;
2013 const char *file ATTRIBUTE_UNUSED;
2015 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2018 current_function_func_begin_label = 0;
2020 #ifdef IA64_UNWIND_INFO
2021 /* ??? current_function_func_begin_label is also used by except.c
2022 for call-site information. We must emit this label if it might
2024 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2025 && ! dwarf2out_do_frame ())
2028 if (! dwarf2out_do_frame ())
2032 ++current_funcdef_number;
2034 function_section (current_function_decl);
2035 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2036 current_funcdef_number);
2037 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2038 current_funcdef_number);
2039 current_function_func_begin_label = get_identifier (label);
2041 #ifdef IA64_UNWIND_INFO
2042 /* We can elide the fde allocation if we're not emitting debug info. */
2043 if (! dwarf2out_do_frame ())
2047 /* Expand the fde table if necessary. */
2048 if (fde_table_in_use == fde_table_allocated)
2050 fde_table_allocated += FDE_TABLE_INCREMENT;
2052 = (dw_fde_ref) xrealloc (fde_table,
2053 fde_table_allocated * sizeof (dw_fde_node));
2056 /* Record the FDE associated with this function. */
2057 current_funcdef_fde = fde_table_in_use;
2059 /* Add the new FDE at the end of the fde_table. */
2060 fde = &fde_table[fde_table_in_use++];
2061 fde->dw_fde_begin = xstrdup (label);
2062 fde->dw_fde_current_label = NULL;
2063 fde->dw_fde_end = NULL;
2064 fde->dw_fde_cfi = NULL;
2065 fde->funcdef_number = current_funcdef_number;
2066 fde->nothrow = current_function_nothrow;
2067 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2069 args_size = old_args_size = 0;
2071 /* We only want to output line number information for the genuine
2072 dwarf2 prologue case, not the eh frame case. */
2073 #ifdef DWARF2_DEBUGGING_INFO
2075 dwarf2out_source_line (line, file);
2079 /* Output a marker (i.e. a label) for the absolute end of the generated code
2080 for a function definition. This gets called *after* the epilogue code has
2084 dwarf2out_end_epilogue ()
2087 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2089 /* Output a label to mark the endpoint of the code generated for this
2091 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2092 ASM_OUTPUT_LABEL (asm_out_file, label);
2093 fde = &fde_table[fde_table_in_use - 1];
2094 fde->dw_fde_end = xstrdup (label);
2098 dwarf2out_frame_init ()
2100 /* Allocate the initial hunk of the fde_table. */
2101 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2102 fde_table_allocated = FDE_TABLE_INCREMENT;
2103 fde_table_in_use = 0;
2105 /* Generate the CFA instructions common to all FDE's. Do it now for the
2106 sake of lookup_cfa. */
2108 #ifdef DWARF2_UNWIND_INFO
2109 /* On entry, the Canonical Frame Address is at SP. */
2110 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2111 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2116 dwarf2out_frame_finish ()
2118 /* Output call frame information. */
2119 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2120 output_call_frame_info (0);
2121 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2122 output_call_frame_info (1);
2125 /* And now, the subset of the debugging information support code necessary
2126 for emitting location expressions. */
2128 typedef struct dw_val_struct *dw_val_ref;
2129 typedef struct die_struct *dw_die_ref;
2130 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2131 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2133 /* Each DIE may have a series of attribute/value pairs. Values
2134 can take on several forms. The forms that are used in this
2135 implementation are listed below. */
2140 dw_val_class_offset,
2142 dw_val_class_loc_list,
2144 dw_val_class_unsigned_const,
2145 dw_val_class_long_long,
2148 dw_val_class_die_ref,
2149 dw_val_class_fde_ref,
2150 dw_val_class_lbl_id,
2151 dw_val_class_lbl_offset,
2156 /* Describe a double word constant value. */
2157 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2159 typedef struct dw_long_long_struct
2166 /* Describe a floating point constant value. */
2168 typedef struct dw_fp_struct
2175 /* The dw_val_node describes an attribute's value, as it is
2176 represented internally. */
2178 typedef struct dw_val_struct
2180 dw_val_class val_class;
2184 long unsigned val_offset;
2185 dw_loc_list_ref val_loc_list;
2186 dw_loc_descr_ref val_loc;
2188 long unsigned val_unsigned;
2189 dw_long_long_const val_long_long;
2190 dw_float_const val_float;
2195 unsigned val_fde_index;
2196 struct indirect_string_node *val_str;
2198 unsigned char val_flag;
2204 /* Locations in memory are described using a sequence of stack machine
2207 typedef struct dw_loc_descr_struct
2209 dw_loc_descr_ref dw_loc_next;
2210 enum dwarf_location_atom dw_loc_opc;
2211 dw_val_node dw_loc_oprnd1;
2212 dw_val_node dw_loc_oprnd2;
2217 /* Location lists are ranges + location descriptions for that range,
2218 so you can track variables that are in different places over
2219 their entire life. */
2220 typedef struct dw_loc_list_struct
2222 dw_loc_list_ref dw_loc_next;
2223 const char *begin; /* Label for begin address of range */
2224 const char *end; /* Label for end address of range */
2225 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2226 const char *section; /* Section this loclist is relative to */
2227 dw_loc_descr_ref expr;
2230 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2231 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2234 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2236 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2237 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2238 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2239 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2241 /* Convert a DWARF stack opcode into its string name. */
2244 dwarf_stack_op_name (op)
2250 return "DW_OP_addr";
2252 return "DW_OP_deref";
2254 return "DW_OP_const1u";
2256 return "DW_OP_const1s";
2258 return "DW_OP_const2u";
2260 return "DW_OP_const2s";
2262 return "DW_OP_const4u";
2264 return "DW_OP_const4s";
2266 return "DW_OP_const8u";
2268 return "DW_OP_const8s";
2270 return "DW_OP_constu";
2272 return "DW_OP_consts";
2276 return "DW_OP_drop";
2278 return "DW_OP_over";
2280 return "DW_OP_pick";
2282 return "DW_OP_swap";
2286 return "DW_OP_xderef";
2294 return "DW_OP_minus";
2306 return "DW_OP_plus";
2307 case DW_OP_plus_uconst:
2308 return "DW_OP_plus_uconst";
2314 return "DW_OP_shra";
2332 return "DW_OP_skip";
2334 return "DW_OP_lit0";
2336 return "DW_OP_lit1";
2338 return "DW_OP_lit2";
2340 return "DW_OP_lit3";
2342 return "DW_OP_lit4";
2344 return "DW_OP_lit5";
2346 return "DW_OP_lit6";
2348 return "DW_OP_lit7";
2350 return "DW_OP_lit8";
2352 return "DW_OP_lit9";
2354 return "DW_OP_lit10";
2356 return "DW_OP_lit11";
2358 return "DW_OP_lit12";
2360 return "DW_OP_lit13";
2362 return "DW_OP_lit14";
2364 return "DW_OP_lit15";
2366 return "DW_OP_lit16";
2368 return "DW_OP_lit17";
2370 return "DW_OP_lit18";
2372 return "DW_OP_lit19";
2374 return "DW_OP_lit20";
2376 return "DW_OP_lit21";
2378 return "DW_OP_lit22";
2380 return "DW_OP_lit23";
2382 return "DW_OP_lit24";
2384 return "DW_OP_lit25";
2386 return "DW_OP_lit26";
2388 return "DW_OP_lit27";
2390 return "DW_OP_lit28";
2392 return "DW_OP_lit29";
2394 return "DW_OP_lit30";
2396 return "DW_OP_lit31";
2398 return "DW_OP_reg0";
2400 return "DW_OP_reg1";
2402 return "DW_OP_reg2";
2404 return "DW_OP_reg3";
2406 return "DW_OP_reg4";
2408 return "DW_OP_reg5";
2410 return "DW_OP_reg6";
2412 return "DW_OP_reg7";
2414 return "DW_OP_reg8";
2416 return "DW_OP_reg9";
2418 return "DW_OP_reg10";
2420 return "DW_OP_reg11";
2422 return "DW_OP_reg12";
2424 return "DW_OP_reg13";
2426 return "DW_OP_reg14";
2428 return "DW_OP_reg15";
2430 return "DW_OP_reg16";
2432 return "DW_OP_reg17";
2434 return "DW_OP_reg18";
2436 return "DW_OP_reg19";
2438 return "DW_OP_reg20";
2440 return "DW_OP_reg21";
2442 return "DW_OP_reg22";
2444 return "DW_OP_reg23";
2446 return "DW_OP_reg24";
2448 return "DW_OP_reg25";
2450 return "DW_OP_reg26";
2452 return "DW_OP_reg27";
2454 return "DW_OP_reg28";
2456 return "DW_OP_reg29";
2458 return "DW_OP_reg30";
2460 return "DW_OP_reg31";
2462 return "DW_OP_breg0";
2464 return "DW_OP_breg1";
2466 return "DW_OP_breg2";
2468 return "DW_OP_breg3";
2470 return "DW_OP_breg4";
2472 return "DW_OP_breg5";
2474 return "DW_OP_breg6";
2476 return "DW_OP_breg7";
2478 return "DW_OP_breg8";
2480 return "DW_OP_breg9";
2482 return "DW_OP_breg10";
2484 return "DW_OP_breg11";
2486 return "DW_OP_breg12";
2488 return "DW_OP_breg13";
2490 return "DW_OP_breg14";
2492 return "DW_OP_breg15";
2494 return "DW_OP_breg16";
2496 return "DW_OP_breg17";
2498 return "DW_OP_breg18";
2500 return "DW_OP_breg19";
2502 return "DW_OP_breg20";
2504 return "DW_OP_breg21";
2506 return "DW_OP_breg22";
2508 return "DW_OP_breg23";
2510 return "DW_OP_breg24";
2512 return "DW_OP_breg25";
2514 return "DW_OP_breg26";
2516 return "DW_OP_breg27";
2518 return "DW_OP_breg28";
2520 return "DW_OP_breg29";
2522 return "DW_OP_breg30";
2524 return "DW_OP_breg31";
2526 return "DW_OP_regx";
2528 return "DW_OP_fbreg";
2530 return "DW_OP_bregx";
2532 return "DW_OP_piece";
2533 case DW_OP_deref_size:
2534 return "DW_OP_deref_size";
2535 case DW_OP_xderef_size:
2536 return "DW_OP_xderef_size";
2540 return "OP_<unknown>";
2544 /* Return a pointer to a newly allocated location description. Location
2545 descriptions are simple expression terms that can be strung
2546 together to form more complicated location (address) descriptions. */
2548 static inline dw_loc_descr_ref
2549 new_loc_descr (op, oprnd1, oprnd2)
2550 enum dwarf_location_atom op;
2551 unsigned long oprnd1;
2552 unsigned long oprnd2;
2554 /* Use xcalloc here so we clear out all of the long_long constant in
2556 dw_loc_descr_ref descr
2557 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2559 descr->dw_loc_opc = op;
2560 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2561 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2562 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2563 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2569 /* Add a location description term to a location description expression. */
2572 add_loc_descr (list_head, descr)
2573 dw_loc_descr_ref *list_head;
2574 dw_loc_descr_ref descr;
2576 dw_loc_descr_ref *d;
2578 /* Find the end of the chain. */
2579 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2585 /* Return the size of a location descriptor. */
2587 static unsigned long
2588 size_of_loc_descr (loc)
2589 dw_loc_descr_ref loc;
2591 unsigned long size = 1;
2593 switch (loc->dw_loc_opc)
2596 size += DWARF2_ADDR_SIZE;
2615 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2618 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2623 case DW_OP_plus_uconst:
2624 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2662 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2665 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2668 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2671 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2672 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2675 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2677 case DW_OP_deref_size:
2678 case DW_OP_xderef_size:
2688 /* Return the size of a series of location descriptors. */
2690 static unsigned long
2692 dw_loc_descr_ref loc;
2694 unsigned long size = 0;
2696 for (; loc != NULL; loc = loc->dw_loc_next)
2698 loc->dw_loc_addr = size;
2699 size += size_of_loc_descr (loc);
2705 /* Output location description stack opcode's operands (if any). */
2708 output_loc_operands (loc)
2709 dw_loc_descr_ref loc;
2711 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2712 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2714 switch (loc->dw_loc_opc)
2716 #ifdef DWARF2_DEBUGGING_INFO
2718 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2722 dw2_asm_output_data (2, val1->v.val_int, NULL);
2726 dw2_asm_output_data (4, val1->v.val_int, NULL);
2730 if (HOST_BITS_PER_LONG < 64)
2732 dw2_asm_output_data (8, val1->v.val_int, NULL);
2739 if (val1->val_class == dw_val_class_loc)
2740 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2744 dw2_asm_output_data (2, offset, NULL);
2757 /* We currently don't make any attempt to make sure these are
2758 aligned properly like we do for the main unwind info, so
2759 don't support emitting things larger than a byte if we're
2760 only doing unwinding. */
2765 dw2_asm_output_data (1, val1->v.val_int, NULL);
2768 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2771 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2774 dw2_asm_output_data (1, val1->v.val_int, NULL);
2776 case DW_OP_plus_uconst:
2777 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2811 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2814 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2817 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2820 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2821 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2824 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2826 case DW_OP_deref_size:
2827 case DW_OP_xderef_size:
2828 dw2_asm_output_data (1, val1->v.val_int, NULL);
2831 /* Other codes have no operands. */
2836 /* Output a sequence of location operations. */
2839 output_loc_sequence (loc)
2840 dw_loc_descr_ref loc;
2842 for (; loc != NULL; loc = loc->dw_loc_next)
2844 /* Output the opcode. */
2845 dw2_asm_output_data (1, loc->dw_loc_opc,
2846 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2848 /* Output the operand(s) (if any). */
2849 output_loc_operands (loc);
2853 /* This routine will generate the correct assembly data for a location
2854 description based on a cfi entry with a complex address. */
2857 output_cfa_loc (cfi)
2860 dw_loc_descr_ref loc;
2863 /* Output the size of the block. */
2864 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2865 size = size_of_locs (loc);
2866 dw2_asm_output_data_uleb128 (size, NULL);
2868 /* Now output the operations themselves. */
2869 output_loc_sequence (loc);
2872 /* This function builds a dwarf location descriptor sequence from
2873 a dw_cfa_location. */
2875 static struct dw_loc_descr_struct *
2877 dw_cfa_location *cfa;
2879 struct dw_loc_descr_struct *head, *tmp;
2881 if (cfa->indirect == 0)
2884 if (cfa->base_offset)
2887 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2889 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2891 else if (cfa->reg <= 31)
2892 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2894 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2895 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2896 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2897 add_loc_descr (&head, tmp);
2898 if (cfa->offset != 0)
2900 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2901 add_loc_descr (&head, tmp);
2906 /* This function fills in aa dw_cfa_location structure from a
2907 dwarf location descriptor sequence. */
2910 get_cfa_from_loc_descr (cfa, loc)
2911 dw_cfa_location *cfa;
2912 struct dw_loc_descr_struct *loc;
2914 struct dw_loc_descr_struct *ptr;
2916 cfa->base_offset = 0;
2920 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2922 enum dwarf_location_atom op = ptr->dw_loc_opc;
2957 cfa->reg = op - DW_OP_reg0;
2960 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2994 cfa->reg = op - DW_OP_breg0;
2995 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2998 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2999 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3004 case DW_OP_plus_uconst:
3005 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3008 internal_error ("DW_LOC_OP %s not implemented\n",
3009 dwarf_stack_op_name (ptr->dw_loc_opc));
3013 #endif /* .debug_frame support */
3015 /* And now, the support for symbolic debugging information. */
3016 #ifdef DWARF2_DEBUGGING_INFO
3018 static void dwarf2out_init PARAMS ((const char *));
3019 static void dwarf2out_finish PARAMS ((const char *));
3020 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3021 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3022 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3023 static void dwarf2out_end_source_file PARAMS ((unsigned));
3024 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3025 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3026 static bool dwarf2out_ignore_block PARAMS ((tree));
3027 static void dwarf2out_global_decl PARAMS ((tree));
3028 static void dwarf2out_abstract_function PARAMS ((tree));
3030 /* The debug hooks structure. */
3032 struct gcc_debug_hooks dwarf2_debug_hooks =
3038 dwarf2out_start_source_file,
3039 dwarf2out_end_source_file,
3040 dwarf2out_begin_block,
3041 dwarf2out_end_block,
3042 dwarf2out_ignore_block,
3043 dwarf2out_source_line,
3044 dwarf2out_begin_prologue,
3045 debug_nothing_int, /* end_prologue */
3046 dwarf2out_end_epilogue,
3047 debug_nothing_tree, /* begin_function */
3048 debug_nothing_int, /* end_function */
3049 dwarf2out_decl, /* function_decl */
3050 dwarf2out_global_decl,
3051 debug_nothing_tree, /* deferred_inline_function */
3052 /* The DWARF 2 backend tries to reduce debugging bloat by not
3053 emitting the abstract description of inline functions until
3054 something tries to reference them. */
3055 dwarf2out_abstract_function, /* outlining_inline_function */
3056 debug_nothing_rtx /* label */
3059 /* NOTE: In the comments in this file, many references are made to
3060 "Debugging Information Entries". This term is abbreviated as `DIE'
3061 throughout the remainder of this file. */
3063 /* An internal representation of the DWARF output is built, and then
3064 walked to generate the DWARF debugging info. The walk of the internal
3065 representation is done after the entire program has been compiled.
3066 The types below are used to describe the internal representation. */
3068 /* Various DIE's use offsets relative to the beginning of the
3069 .debug_info section to refer to each other. */
3071 typedef long int dw_offset;
3073 /* Define typedefs here to avoid circular dependencies. */
3075 typedef struct dw_attr_struct *dw_attr_ref;
3076 typedef struct dw_line_info_struct *dw_line_info_ref;
3077 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3078 typedef struct pubname_struct *pubname_ref;
3079 typedef struct dw_ranges_struct *dw_ranges_ref;
3081 /* Each entry in the line_info_table maintains the file and
3082 line number associated with the label generated for that
3083 entry. The label gives the PC value associated with
3084 the line number entry. */
3086 typedef struct dw_line_info_struct
3088 unsigned long dw_file_num;
3089 unsigned long dw_line_num;
3093 /* Line information for functions in separate sections; each one gets its
3095 typedef struct dw_separate_line_info_struct
3097 unsigned long dw_file_num;
3098 unsigned long dw_line_num;
3099 unsigned long function;
3101 dw_separate_line_info_entry;
3103 /* Each DIE attribute has a field specifying the attribute kind,
3104 a link to the next attribute in the chain, and an attribute value.
3105 Attributes are typically linked below the DIE they modify. */
3107 typedef struct dw_attr_struct
3109 enum dwarf_attribute dw_attr;
3110 dw_attr_ref dw_attr_next;
3111 dw_val_node dw_attr_val;
3115 /* The Debugging Information Entry (DIE) structure */
3117 typedef struct die_struct
3119 enum dwarf_tag die_tag;
3121 dw_attr_ref die_attr;
3122 dw_die_ref die_parent;
3123 dw_die_ref die_child;
3125 dw_offset die_offset;
3126 unsigned long die_abbrev;
3131 /* The pubname structure */
3133 typedef struct pubname_struct
3140 struct dw_ranges_struct
3145 /* The limbo die list structure. */
3146 typedef struct limbo_die_struct
3149 struct limbo_die_struct *next;
3153 /* How to start an assembler comment. */
3154 #ifndef ASM_COMMENT_START
3155 #define ASM_COMMENT_START ";#"
3158 /* Define a macro which returns non-zero for a TYPE_DECL which was
3159 implicitly generated for a tagged type.
3161 Note that unlike the gcc front end (which generates a NULL named
3162 TYPE_DECL node for each complete tagged type, each array type, and
3163 each function type node created) the g++ front end generates a
3164 _named_ TYPE_DECL node for each tagged type node created.
3165 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3166 generate a DW_TAG_typedef DIE for them. */
3168 #define TYPE_DECL_IS_STUB(decl) \
3169 (DECL_NAME (decl) == NULL_TREE \
3170 || (DECL_ARTIFICIAL (decl) \
3171 && is_tagged_type (TREE_TYPE (decl)) \
3172 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3173 /* This is necessary for stub decls that \
3174 appear in nested inline functions. */ \
3175 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3176 && (decl_ultimate_origin (decl) \
3177 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3179 /* Information concerning the compilation unit's programming
3180 language, and compiler version. */
3182 extern int flag_traditional;
3184 /* Fixed size portion of the DWARF compilation unit header. */
3185 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3187 /* Fixed size portion of debugging line information prolog. */
3188 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3190 /* Fixed size portion of public names info. */
3191 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3193 /* Fixed size portion of the address range info. */
3194 #define DWARF_ARANGES_HEADER_SIZE \
3195 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3196 - DWARF_OFFSET_SIZE)
3198 /* Size of padding portion in the address range info. It must be
3199 aligned to twice the pointer size. */
3200 #define DWARF_ARANGES_PAD_SIZE \
3201 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3202 - (2 * DWARF_OFFSET_SIZE + 4))
3204 /* Use assembler line directives if available. */
3205 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3206 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3207 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3209 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3213 /* Define the architecture-dependent minimum instruction length (in bytes).
3214 In this implementation of DWARF, this field is used for information
3215 purposes only. Since GCC generates assembly language, we have
3216 no a priori knowledge of how many instruction bytes are generated
3217 for each source line, and therefore can use only the DW_LNE_set_address
3218 and DW_LNS_fixed_advance_pc line information commands. */
3220 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3221 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3224 /* Minimum line offset in a special line info. opcode.
3225 This value was chosen to give a reasonable range of values. */
3226 #define DWARF_LINE_BASE -10
3228 /* First special line opcode - leave room for the standard opcodes. */
3229 #define DWARF_LINE_OPCODE_BASE 10
3231 /* Range of line offsets in a special line info. opcode. */
3232 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3234 /* Flag that indicates the initial value of the is_stmt_start flag.
3235 In the present implementation, we do not mark any lines as
3236 the beginning of a source statement, because that information
3237 is not made available by the GCC front-end. */
3238 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3240 /* This location is used by calc_die_sizes() to keep track
3241 the offset of each DIE within the .debug_info section. */
3242 static unsigned long next_die_offset;
3244 /* Record the root of the DIE's built for the current compilation unit. */
3245 static dw_die_ref comp_unit_die;
3247 /* A list of DIEs with a NULL parent waiting to be relocated. */
3248 static limbo_die_node *limbo_die_list = 0;
3250 /* Structure used by lookup_filename to manage sets of filenames. */
3256 unsigned last_lookup_index;
3259 /* Size (in elements) of increments by which we may expand the filename
3261 #define FILE_TABLE_INCREMENT 64
3263 /* Filenames referenced by this compilation unit. */
3264 static struct file_table file_table;
3266 /* Local pointer to the name of the main input file. Initialized in
3268 static const char *primary_filename;
3270 /* A pointer to the base of a table of references to DIE's that describe
3271 declarations. The table is indexed by DECL_UID() which is a unique
3272 number identifying each decl. */
3273 static dw_die_ref *decl_die_table;
3275 /* Number of elements currently allocated for the decl_die_table. */
3276 static unsigned decl_die_table_allocated;
3278 /* Number of elements in decl_die_table currently in use. */
3279 static unsigned decl_die_table_in_use;
3281 /* Size (in elements) of increments by which we may expand the
3283 #define DECL_DIE_TABLE_INCREMENT 256
3285 /* A pointer to the base of a table of references to declaration
3286 scopes. This table is a display which tracks the nesting
3287 of declaration scopes at the current scope and containing
3288 scopes. This table is used to find the proper place to
3289 define type declaration DIE's. */
3290 varray_type decl_scope_table;
3292 /* A pointer to the base of a list of references to DIE's that
3293 are uniquely identified by their tag, presence/absence of
3294 children DIE's, and list of attribute/value pairs. */
3295 static dw_die_ref *abbrev_die_table;
3297 /* Number of elements currently allocated for abbrev_die_table. */
3298 static unsigned abbrev_die_table_allocated;
3300 /* Number of elements in type_die_table currently in use. */
3301 static unsigned abbrev_die_table_in_use;
3303 /* Size (in elements) of increments by which we may expand the
3304 abbrev_die_table. */
3305 #define ABBREV_DIE_TABLE_INCREMENT 256
3307 /* A pointer to the base of a table that contains line information
3308 for each source code line in .text in the compilation unit. */
3309 static dw_line_info_ref line_info_table;
3311 /* Number of elements currently allocated for line_info_table. */
3312 static unsigned line_info_table_allocated;
3314 /* Number of elements in separate_line_info_table currently in use. */
3315 static unsigned separate_line_info_table_in_use;
3317 /* A pointer to the base of a table that contains line information
3318 for each source code line outside of .text in the compilation unit. */
3319 static dw_separate_line_info_ref separate_line_info_table;
3321 /* Number of elements currently allocated for separate_line_info_table. */
3322 static unsigned separate_line_info_table_allocated;
3324 /* Number of elements in line_info_table currently in use. */
3325 static unsigned line_info_table_in_use;
3327 /* Size (in elements) of increments by which we may expand the
3329 #define LINE_INFO_TABLE_INCREMENT 1024
3331 /* A pointer to the base of a table that contains a list of publicly
3332 accessible names. */
3333 static pubname_ref pubname_table;
3335 /* Number of elements currently allocated for pubname_table. */
3336 static unsigned pubname_table_allocated;
3338 /* Number of elements in pubname_table currently in use. */
3339 static unsigned pubname_table_in_use;
3341 /* Size (in elements) of increments by which we may expand the
3343 #define PUBNAME_TABLE_INCREMENT 64
3345 /* Array of dies for which we should generate .debug_arange info. */
3346 static dw_die_ref *arange_table;
3348 /* Number of elements currently allocated for arange_table. */
3349 static unsigned arange_table_allocated;
3351 /* Number of elements in arange_table currently in use. */
3352 static unsigned arange_table_in_use;
3354 /* Size (in elements) of increments by which we may expand the
3356 #define ARANGE_TABLE_INCREMENT 64
3358 /* Array of dies for which we should generate .debug_ranges info. */
3359 static dw_ranges_ref ranges_table;
3361 /* Number of elements currently allocated for ranges_table. */
3362 static unsigned ranges_table_allocated;
3364 /* Number of elements in ranges_table currently in use. */
3365 static unsigned ranges_table_in_use;
3367 /* Size (in elements) of increments by which we may expand the
3369 #define RANGES_TABLE_INCREMENT 64
3371 /* Whether we have location lists that need outputting */
3372 static unsigned have_location_lists;
3374 /* A pointer to the base of a list of incomplete types which might be
3375 completed at some later time. incomplete_types_list needs to be a VARRAY
3376 because we want to tell the garbage collector about it. If we don't tell
3377 the garbage collector about it, we can garbage collect live data.
3379 varray_type incomplete_types;
3381 /* Record whether the function being analyzed contains inlined functions. */
3382 static int current_function_has_inlines;
3383 #if 0 && defined (MIPS_DEBUGGING_INFO)
3384 static int comp_unit_has_inlines;
3387 /* Array of RTXes referenced by the debugging information, which therefore
3388 must be kept around forever. We do this rather than perform GC on
3389 the dwarf info because almost all of the dwarf info lives forever, and
3390 it's easier to support non-GC frontends this way. */
3391 static varray_type used_rtx_varray;
3393 /* Forward declarations for functions defined in this file. */
3395 static int is_pseudo_reg PARAMS ((rtx));
3396 static tree type_main_variant PARAMS ((tree));
3397 static int is_tagged_type PARAMS ((tree));
3398 static const char *dwarf_tag_name PARAMS ((unsigned));
3399 static const char *dwarf_attr_name PARAMS ((unsigned));
3400 static const char *dwarf_form_name PARAMS ((unsigned));
3402 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3404 static tree decl_ultimate_origin PARAMS ((tree));
3405 static tree block_ultimate_origin PARAMS ((tree));
3406 static tree decl_class_context PARAMS ((tree));
3407 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3408 static void add_AT_flag PARAMS ((dw_die_ref,
3409 enum dwarf_attribute,
3411 static void add_AT_int PARAMS ((dw_die_ref,
3412 enum dwarf_attribute, long));
3413 static void add_AT_unsigned PARAMS ((dw_die_ref,
3414 enum dwarf_attribute,
3416 static void add_AT_long_long PARAMS ((dw_die_ref,
3417 enum dwarf_attribute,
3420 static void add_AT_float PARAMS ((dw_die_ref,
3421 enum dwarf_attribute,
3423 static void add_AT_string PARAMS ((dw_die_ref,
3424 enum dwarf_attribute,
3426 static void add_AT_die_ref PARAMS ((dw_die_ref,
3427 enum dwarf_attribute,
3429 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3430 enum dwarf_attribute,
3432 static void add_AT_loc PARAMS ((dw_die_ref,
3433 enum dwarf_attribute,
3435 static void add_AT_loc_list PARAMS ((dw_die_ref,
3436 enum dwarf_attribute,
3438 static void add_AT_addr PARAMS ((dw_die_ref,
3439 enum dwarf_attribute,
3441 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3442 enum dwarf_attribute,
3444 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3445 enum dwarf_attribute,
3447 static void add_AT_offset PARAMS ((dw_die_ref,
3448 enum dwarf_attribute,
3450 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3451 enum dwarf_attribute));
3452 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3453 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3454 static const char *get_AT_string PARAMS ((dw_die_ref,
3455 enum dwarf_attribute));
3456 static int get_AT_flag PARAMS ((dw_die_ref,
3457 enum dwarf_attribute));
3458 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3459 enum dwarf_attribute));
3460 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3461 enum dwarf_attribute));
3462 static int is_c_family PARAMS ((void));
3463 static int is_cxx PARAMS ((void));
3464 static int is_java PARAMS ((void));
3465 static int is_fortran PARAMS ((void));
3466 static void remove_AT PARAMS ((dw_die_ref,
3467 enum dwarf_attribute));
3468 static void remove_children PARAMS ((dw_die_ref));
3469 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3470 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3471 static dw_die_ref lookup_type_die PARAMS ((tree));
3472 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3473 static dw_die_ref lookup_decl_die PARAMS ((tree));
3474 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3475 static void print_spaces PARAMS ((FILE *));
3476 static void print_die PARAMS ((dw_die_ref, FILE *));
3477 static void print_dwarf_line_table PARAMS ((FILE *));
3478 static void reverse_die_lists PARAMS ((dw_die_ref));
3479 static void reverse_all_dies PARAMS ((dw_die_ref));
3480 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3481 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3482 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3483 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3484 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3485 static void compute_section_prefix PARAMS ((dw_die_ref));
3486 static int is_type_die PARAMS ((dw_die_ref));
3487 static int is_comdat_die PARAMS ((dw_die_ref));
3488 static int is_symbol_die PARAMS ((dw_die_ref));
3489 static void assign_symbol_names PARAMS ((dw_die_ref));
3490 static void break_out_includes PARAMS ((dw_die_ref));
3491 static void add_sibling_attributes PARAMS ((dw_die_ref));
3492 static void build_abbrev_table PARAMS ((dw_die_ref));
3493 static void output_location_lists PARAMS ((dw_die_ref));
3494 static int constant_size PARAMS ((long unsigned));
3495 static unsigned long size_of_die PARAMS ((dw_die_ref));
3496 static void calc_die_sizes PARAMS ((dw_die_ref));
3497 static void mark_dies PARAMS ((dw_die_ref));
3498 static void unmark_dies PARAMS ((dw_die_ref));
3499 static unsigned long size_of_pubnames PARAMS ((void));
3500 static unsigned long size_of_aranges PARAMS ((void));
3501 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3502 static void output_value_format PARAMS ((dw_attr_ref));
3503 static void output_abbrev_section PARAMS ((void));
3504 static void output_die_symbol PARAMS ((dw_die_ref));
3505 static void output_die PARAMS ((dw_die_ref));
3506 static void output_compilation_unit_header PARAMS ((void));
3507 static void output_comp_unit PARAMS ((dw_die_ref));
3508 static const char *dwarf2_name PARAMS ((tree, int));
3509 static void add_pubname PARAMS ((tree, dw_die_ref));
3510 static void output_pubnames PARAMS ((void));
3511 static void add_arange PARAMS ((tree, dw_die_ref));
3512 static void output_aranges PARAMS ((void));
3513 static unsigned int add_ranges PARAMS ((tree));
3514 static void output_ranges PARAMS ((void));
3515 static void output_line_info PARAMS ((void));
3516 static void output_file_names PARAMS ((void));
3517 static dw_die_ref base_type_die PARAMS ((tree));
3518 static tree root_type PARAMS ((tree));
3519 static int is_base_type PARAMS ((tree));
3520 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3521 static int type_is_enum PARAMS ((tree));
3522 static unsigned int reg_number PARAMS ((rtx));
3523 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3524 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3525 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3526 static int is_based_loc PARAMS ((rtx));
3527 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3528 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3529 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3530 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3531 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3532 static tree field_type PARAMS ((tree));
3533 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3534 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3535 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3536 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3537 static void add_AT_location_description PARAMS ((dw_die_ref,
3538 enum dwarf_attribute, rtx));
3539 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3540 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3541 static rtx rtl_for_decl_location PARAMS ((tree));
3542 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3543 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3544 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3545 static void add_bound_info PARAMS ((dw_die_ref,
3546 enum dwarf_attribute, tree));
3547 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3548 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3549 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3550 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3551 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3552 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3553 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3554 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3555 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3556 static void push_decl_scope PARAMS ((tree));
3557 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3558 static void pop_decl_scope PARAMS ((void));
3559 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3561 static const char *type_tag PARAMS ((tree));
3562 static tree member_declared_type PARAMS ((tree));
3564 static const char *decl_start_label PARAMS ((tree));
3566 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3567 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3569 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3571 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3572 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3573 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3574 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3575 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3576 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3577 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3578 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3579 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3580 static void gen_label_die PARAMS ((tree, dw_die_ref));
3581 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3582 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3583 static void gen_field_die PARAMS ((tree, dw_die_ref));
3584 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3585 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3586 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3587 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3588 static void gen_member_die PARAMS ((tree, dw_die_ref));
3589 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3590 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3591 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3592 static void gen_type_die PARAMS ((tree, dw_die_ref));
3593 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3594 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3595 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3596 static int is_redundant_typedef PARAMS ((tree));
3597 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3598 static unsigned lookup_filename PARAMS ((const char *));
3599 static void init_file_table PARAMS ((void));
3600 static void add_incomplete_type PARAMS ((tree));
3601 static void retry_incomplete_types PARAMS ((void));
3602 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3603 static rtx save_rtx PARAMS ((rtx));
3604 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3605 static int file_info_cmp PARAMS ((const void *, const void *));
3606 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3607 const char *, const char *,
3608 const char *, unsigned));
3609 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3611 const char *, const char *, const char *));
3612 static void output_loc_list PARAMS ((dw_loc_list_ref));
3613 static char *gen_internal_sym PARAMS ((const char *));
3615 /* Section names used to hold DWARF debugging information. */
3616 #ifndef DEBUG_INFO_SECTION
3617 #define DEBUG_INFO_SECTION ".debug_info"
3619 #ifndef DEBUG_ABBREV_SECTION
3620 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3622 #ifndef DEBUG_ARANGES_SECTION
3623 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3625 #ifndef DEBUG_MACINFO_SECTION
3626 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3628 #ifndef DEBUG_LINE_SECTION
3629 #define DEBUG_LINE_SECTION ".debug_line"
3631 #ifndef DEBUG_LOC_SECTION
3632 #define DEBUG_LOC_SECTION ".debug_loc"
3634 #ifndef DEBUG_PUBNAMES_SECTION
3635 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3637 #ifndef DEBUG_STR_SECTION
3638 #define DEBUG_STR_SECTION ".debug_str"
3640 #ifndef DEBUG_RANGES_SECTION
3641 #define DEBUG_RANGES_SECTION ".debug_ranges"
3644 /* Standard ELF section names for compiled code and data. */
3645 #ifndef TEXT_SECTION_NAME
3646 #define TEXT_SECTION_NAME ".text"
3649 /* Section flags for .debug_str section. */
3650 #ifdef HAVE_GAS_SHF_MERGE
3651 #define DEBUG_STR_SECTION_FLAGS \
3652 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3654 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3657 /* Labels we insert at beginning sections we can reference instead of
3658 the section names themselves. */
3660 #ifndef TEXT_SECTION_LABEL
3661 #define TEXT_SECTION_LABEL "Ltext"
3663 #ifndef DEBUG_LINE_SECTION_LABEL
3664 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3666 #ifndef DEBUG_INFO_SECTION_LABEL
3667 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3669 #ifndef DEBUG_ABBREV_SECTION_LABEL
3670 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3672 #ifndef DEBUG_LOC_SECTION_LABEL
3673 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3675 #ifndef DEBUG_MACINFO_SECTION_LABEL
3676 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3679 /* Definitions of defaults for formats and names of various special
3680 (artificial) labels which may be generated within this file (when the -g
3681 options is used and DWARF_DEBUGGING_INFO is in effect.
3682 If necessary, these may be overridden from within the tm.h file, but
3683 typically, overriding these defaults is unnecessary. */
3685 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3686 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3687 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3688 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3689 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3690 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3691 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3692 #ifndef TEXT_END_LABEL
3693 #define TEXT_END_LABEL "Letext"
3695 #ifndef DATA_END_LABEL
3696 #define DATA_END_LABEL "Ledata"
3698 #ifndef BSS_END_LABEL
3699 #define BSS_END_LABEL "Lebss"
3701 #ifndef BLOCK_BEGIN_LABEL
3702 #define BLOCK_BEGIN_LABEL "LBB"
3704 #ifndef BLOCK_END_LABEL
3705 #define BLOCK_END_LABEL "LBE"
3707 #ifndef BODY_BEGIN_LABEL
3708 #define BODY_BEGIN_LABEL "Lbb"
3710 #ifndef BODY_END_LABEL
3711 #define BODY_END_LABEL "Lbe"
3713 #ifndef LINE_CODE_LABEL
3714 #define LINE_CODE_LABEL "LM"
3716 #ifndef SEPARATE_LINE_CODE_LABEL
3717 #define SEPARATE_LINE_CODE_LABEL "LSM"
3720 /* We allow a language front-end to designate a function that is to be
3721 called to "demangle" any name before it it put into a DIE. */
3723 static const char *(*demangle_name_func) PARAMS ((const char *));
3726 dwarf2out_set_demangle_name_func (func)
3727 const char *(*func) PARAMS ((const char *));
3729 demangle_name_func = func;
3732 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3733 that means adding it to used_rtx_varray. If not, that means making
3734 a copy on the permanent_obstack. */
3740 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3745 /* Test if rtl node points to a pseudo register. */
3751 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3752 || (GET_CODE (rtl) == SUBREG
3753 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3756 /* Return a reference to a type, with its const and volatile qualifiers
3760 type_main_variant (type)
3763 type = TYPE_MAIN_VARIANT (type);
3765 /* There really should be only one main variant among any group of variants
3766 of a given type (and all of the MAIN_VARIANT values for all members of
3767 the group should point to that one type) but sometimes the C front-end
3768 messes this up for array types, so we work around that bug here. */
3770 if (TREE_CODE (type) == ARRAY_TYPE)
3771 while (type != TYPE_MAIN_VARIANT (type))
3772 type = TYPE_MAIN_VARIANT (type);
3777 /* Return non-zero if the given type node represents a tagged type. */
3780 is_tagged_type (type)
3783 enum tree_code code = TREE_CODE (type);
3785 return (code == RECORD_TYPE || code == UNION_TYPE
3786 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3789 /* Convert a DIE tag into its string name. */
3792 dwarf_tag_name (tag)
3797 case DW_TAG_padding:
3798 return "DW_TAG_padding";
3799 case DW_TAG_array_type:
3800 return "DW_TAG_array_type";
3801 case DW_TAG_class_type:
3802 return "DW_TAG_class_type";
3803 case DW_TAG_entry_point:
3804 return "DW_TAG_entry_point";
3805 case DW_TAG_enumeration_type:
3806 return "DW_TAG_enumeration_type";
3807 case DW_TAG_formal_parameter:
3808 return "DW_TAG_formal_parameter";
3809 case DW_TAG_imported_declaration:
3810 return "DW_TAG_imported_declaration";
3812 return "DW_TAG_label";
3813 case DW_TAG_lexical_block:
3814 return "DW_TAG_lexical_block";
3816 return "DW_TAG_member";
3817 case DW_TAG_pointer_type:
3818 return "DW_TAG_pointer_type";
3819 case DW_TAG_reference_type:
3820 return "DW_TAG_reference_type";
3821 case DW_TAG_compile_unit:
3822 return "DW_TAG_compile_unit";
3823 case DW_TAG_string_type:
3824 return "DW_TAG_string_type";
3825 case DW_TAG_structure_type:
3826 return "DW_TAG_structure_type";
3827 case DW_TAG_subroutine_type:
3828 return "DW_TAG_subroutine_type";
3829 case DW_TAG_typedef:
3830 return "DW_TAG_typedef";
3831 case DW_TAG_union_type:
3832 return "DW_TAG_union_type";
3833 case DW_TAG_unspecified_parameters:
3834 return "DW_TAG_unspecified_parameters";
3835 case DW_TAG_variant:
3836 return "DW_TAG_variant";
3837 case DW_TAG_common_block:
3838 return "DW_TAG_common_block";
3839 case DW_TAG_common_inclusion:
3840 return "DW_TAG_common_inclusion";
3841 case DW_TAG_inheritance:
3842 return "DW_TAG_inheritance";
3843 case DW_TAG_inlined_subroutine:
3844 return "DW_TAG_inlined_subroutine";
3846 return "DW_TAG_module";
3847 case DW_TAG_ptr_to_member_type:
3848 return "DW_TAG_ptr_to_member_type";
3849 case DW_TAG_set_type:
3850 return "DW_TAG_set_type";
3851 case DW_TAG_subrange_type:
3852 return "DW_TAG_subrange_type";
3853 case DW_TAG_with_stmt:
3854 return "DW_TAG_with_stmt";
3855 case DW_TAG_access_declaration:
3856 return "DW_TAG_access_declaration";
3857 case DW_TAG_base_type:
3858 return "DW_TAG_base_type";
3859 case DW_TAG_catch_block:
3860 return "DW_TAG_catch_block";
3861 case DW_TAG_const_type:
3862 return "DW_TAG_const_type";
3863 case DW_TAG_constant:
3864 return "DW_TAG_constant";
3865 case DW_TAG_enumerator:
3866 return "DW_TAG_enumerator";
3867 case DW_TAG_file_type:
3868 return "DW_TAG_file_type";
3870 return "DW_TAG_friend";
3871 case DW_TAG_namelist:
3872 return "DW_TAG_namelist";
3873 case DW_TAG_namelist_item:
3874 return "DW_TAG_namelist_item";
3875 case DW_TAG_packed_type:
3876 return "DW_TAG_packed_type";
3877 case DW_TAG_subprogram:
3878 return "DW_TAG_subprogram";
3879 case DW_TAG_template_type_param:
3880 return "DW_TAG_template_type_param";
3881 case DW_TAG_template_value_param:
3882 return "DW_TAG_template_value_param";
3883 case DW_TAG_thrown_type:
3884 return "DW_TAG_thrown_type";
3885 case DW_TAG_try_block:
3886 return "DW_TAG_try_block";
3887 case DW_TAG_variant_part:
3888 return "DW_TAG_variant_part";
3889 case DW_TAG_variable:
3890 return "DW_TAG_variable";
3891 case DW_TAG_volatile_type:
3892 return "DW_TAG_volatile_type";
3893 case DW_TAG_MIPS_loop:
3894 return "DW_TAG_MIPS_loop";
3895 case DW_TAG_format_label:
3896 return "DW_TAG_format_label";
3897 case DW_TAG_function_template:
3898 return "DW_TAG_function_template";
3899 case DW_TAG_class_template:
3900 return "DW_TAG_class_template";
3901 case DW_TAG_GNU_BINCL:
3902 return "DW_TAG_GNU_BINCL";
3903 case DW_TAG_GNU_EINCL:
3904 return "DW_TAG_GNU_EINCL";
3906 return "DW_TAG_<unknown>";
3910 /* Convert a DWARF attribute code into its string name. */
3913 dwarf_attr_name (attr)
3919 return "DW_AT_sibling";
3920 case DW_AT_location:
3921 return "DW_AT_location";
3923 return "DW_AT_name";
3924 case DW_AT_ordering:
3925 return "DW_AT_ordering";
3926 case DW_AT_subscr_data:
3927 return "DW_AT_subscr_data";
3928 case DW_AT_byte_size:
3929 return "DW_AT_byte_size";
3930 case DW_AT_bit_offset:
3931 return "DW_AT_bit_offset";
3932 case DW_AT_bit_size:
3933 return "DW_AT_bit_size";
3934 case DW_AT_element_list:
3935 return "DW_AT_element_list";
3936 case DW_AT_stmt_list:
3937 return "DW_AT_stmt_list";
3939 return "DW_AT_low_pc";
3941 return "DW_AT_high_pc";
3942 case DW_AT_language:
3943 return "DW_AT_language";
3945 return "DW_AT_member";
3947 return "DW_AT_discr";
3948 case DW_AT_discr_value:
3949 return "DW_AT_discr_value";
3950 case DW_AT_visibility:
3951 return "DW_AT_visibility";
3953 return "DW_AT_import";
3954 case DW_AT_string_length:
3955 return "DW_AT_string_length";
3956 case DW_AT_common_reference:
3957 return "DW_AT_common_reference";
3958 case DW_AT_comp_dir:
3959 return "DW_AT_comp_dir";
3960 case DW_AT_const_value:
3961 return "DW_AT_const_value";
3962 case DW_AT_containing_type:
3963 return "DW_AT_containing_type";
3964 case DW_AT_default_value:
3965 return "DW_AT_default_value";
3967 return "DW_AT_inline";
3968 case DW_AT_is_optional:
3969 return "DW_AT_is_optional";
3970 case DW_AT_lower_bound:
3971 return "DW_AT_lower_bound";
3972 case DW_AT_producer:
3973 return "DW_AT_producer";
3974 case DW_AT_prototyped:
3975 return "DW_AT_prototyped";
3976 case DW_AT_return_addr:
3977 return "DW_AT_return_addr";
3978 case DW_AT_start_scope:
3979 return "DW_AT_start_scope";
3980 case DW_AT_stride_size:
3981 return "DW_AT_stride_size";
3982 case DW_AT_upper_bound:
3983 return "DW_AT_upper_bound";
3984 case DW_AT_abstract_origin:
3985 return "DW_AT_abstract_origin";
3986 case DW_AT_accessibility:
3987 return "DW_AT_accessibility";
3988 case DW_AT_address_class:
3989 return "DW_AT_address_class";
3990 case DW_AT_artificial:
3991 return "DW_AT_artificial";
3992 case DW_AT_base_types:
3993 return "DW_AT_base_types";
3994 case DW_AT_calling_convention:
3995 return "DW_AT_calling_convention";
3997 return "DW_AT_count";
3998 case DW_AT_data_member_location:
3999 return "DW_AT_data_member_location";
4000 case DW_AT_decl_column:
4001 return "DW_AT_decl_column";
4002 case DW_AT_decl_file:
4003 return "DW_AT_decl_file";
4004 case DW_AT_decl_line:
4005 return "DW_AT_decl_line";
4006 case DW_AT_declaration:
4007 return "DW_AT_declaration";
4008 case DW_AT_discr_list:
4009 return "DW_AT_discr_list";
4010 case DW_AT_encoding:
4011 return "DW_AT_encoding";
4012 case DW_AT_external:
4013 return "DW_AT_external";
4014 case DW_AT_frame_base:
4015 return "DW_AT_frame_base";
4017 return "DW_AT_friend";
4018 case DW_AT_identifier_case:
4019 return "DW_AT_identifier_case";
4020 case DW_AT_macro_info:
4021 return "DW_AT_macro_info";
4022 case DW_AT_namelist_items:
4023 return "DW_AT_namelist_items";
4024 case DW_AT_priority:
4025 return "DW_AT_priority";
4027 return "DW_AT_segment";
4028 case DW_AT_specification:
4029 return "DW_AT_specification";
4030 case DW_AT_static_link:
4031 return "DW_AT_static_link";
4033 return "DW_AT_type";
4034 case DW_AT_use_location:
4035 return "DW_AT_use_location";
4036 case DW_AT_variable_parameter:
4037 return "DW_AT_variable_parameter";
4038 case DW_AT_virtuality:
4039 return "DW_AT_virtuality";
4040 case DW_AT_vtable_elem_location:
4041 return "DW_AT_vtable_elem_location";
4043 case DW_AT_allocated:
4044 return "DW_AT_allocated";
4045 case DW_AT_associated:
4046 return "DW_AT_associated";
4047 case DW_AT_data_location:
4048 return "DW_AT_data_location";
4050 return "DW_AT_stride";
4051 case DW_AT_entry_pc:
4052 return "DW_AT_entry_pc";
4053 case DW_AT_use_UTF8:
4054 return "DW_AT_use_UTF8";
4055 case DW_AT_extension:
4056 return "DW_AT_extension";
4058 return "DW_AT_ranges";
4059 case DW_AT_trampoline:
4060 return "DW_AT_trampoline";
4061 case DW_AT_call_column:
4062 return "DW_AT_call_column";
4063 case DW_AT_call_file:
4064 return "DW_AT_call_file";
4065 case DW_AT_call_line:
4066 return "DW_AT_call_line";
4068 case DW_AT_MIPS_fde:
4069 return "DW_AT_MIPS_fde";
4070 case DW_AT_MIPS_loop_begin:
4071 return "DW_AT_MIPS_loop_begin";
4072 case DW_AT_MIPS_tail_loop_begin:
4073 return "DW_AT_MIPS_tail_loop_begin";
4074 case DW_AT_MIPS_epilog_begin:
4075 return "DW_AT_MIPS_epilog_begin";
4076 case DW_AT_MIPS_loop_unroll_factor:
4077 return "DW_AT_MIPS_loop_unroll_factor";
4078 case DW_AT_MIPS_software_pipeline_depth:
4079 return "DW_AT_MIPS_software_pipeline_depth";
4080 case DW_AT_MIPS_linkage_name:
4081 return "DW_AT_MIPS_linkage_name";
4082 case DW_AT_MIPS_stride:
4083 return "DW_AT_MIPS_stride";
4084 case DW_AT_MIPS_abstract_name:
4085 return "DW_AT_MIPS_abstract_name";
4086 case DW_AT_MIPS_clone_origin:
4087 return "DW_AT_MIPS_clone_origin";
4088 case DW_AT_MIPS_has_inlines:
4089 return "DW_AT_MIPS_has_inlines";
4091 case DW_AT_sf_names:
4092 return "DW_AT_sf_names";
4093 case DW_AT_src_info:
4094 return "DW_AT_src_info";
4095 case DW_AT_mac_info:
4096 return "DW_AT_mac_info";
4097 case DW_AT_src_coords:
4098 return "DW_AT_src_coords";
4099 case DW_AT_body_begin:
4100 return "DW_AT_body_begin";
4101 case DW_AT_body_end:
4102 return "DW_AT_body_end";
4103 case DW_AT_VMS_rtnbeg_pd_address:
4104 return "DW_AT_VMS_rtnbeg_pd_address";
4107 return "DW_AT_<unknown>";
4111 /* Convert a DWARF value form code into its string name. */
4114 dwarf_form_name (form)
4120 return "DW_FORM_addr";
4121 case DW_FORM_block2:
4122 return "DW_FORM_block2";
4123 case DW_FORM_block4:
4124 return "DW_FORM_block4";
4126 return "DW_FORM_data2";
4128 return "DW_FORM_data4";
4130 return "DW_FORM_data8";
4131 case DW_FORM_string:
4132 return "DW_FORM_string";
4134 return "DW_FORM_block";
4135 case DW_FORM_block1:
4136 return "DW_FORM_block1";
4138 return "DW_FORM_data1";
4140 return "DW_FORM_flag";
4142 return "DW_FORM_sdata";
4144 return "DW_FORM_strp";
4146 return "DW_FORM_udata";
4147 case DW_FORM_ref_addr:
4148 return "DW_FORM_ref_addr";
4150 return "DW_FORM_ref1";
4152 return "DW_FORM_ref2";
4154 return "DW_FORM_ref4";
4156 return "DW_FORM_ref8";
4157 case DW_FORM_ref_udata:
4158 return "DW_FORM_ref_udata";
4159 case DW_FORM_indirect:
4160 return "DW_FORM_indirect";
4162 return "DW_FORM_<unknown>";
4166 /* Convert a DWARF type code into its string name. */
4170 dwarf_type_encoding_name (enc)
4175 case DW_ATE_address:
4176 return "DW_ATE_address";
4177 case DW_ATE_boolean:
4178 return "DW_ATE_boolean";
4179 case DW_ATE_complex_float:
4180 return "DW_ATE_complex_float";
4182 return "DW_ATE_float";
4184 return "DW_ATE_signed";
4185 case DW_ATE_signed_char:
4186 return "DW_ATE_signed_char";
4187 case DW_ATE_unsigned:
4188 return "DW_ATE_unsigned";
4189 case DW_ATE_unsigned_char:
4190 return "DW_ATE_unsigned_char";
4192 return "DW_ATE_<unknown>";
4197 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4198 instance of an inlined instance of a decl which is local to an inline
4199 function, so we have to trace all of the way back through the origin chain
4200 to find out what sort of node actually served as the original seed for the
4204 decl_ultimate_origin (decl)
4207 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4208 nodes in the function to point to themselves; ignore that if
4209 we're trying to output the abstract instance of this function. */
4210 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4213 #ifdef ENABLE_CHECKING
4214 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4215 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4216 most distant ancestor, this should never happen. */
4220 return DECL_ABSTRACT_ORIGIN (decl);
4223 /* Determine the "ultimate origin" of a block. The block may be an inlined
4224 instance of an inlined instance of a block which is local to an inline
4225 function, so we have to trace all of the way back through the origin chain
4226 to find out what sort of node actually served as the original seed for the
4230 block_ultimate_origin (block)
4233 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4235 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4236 nodes in the function to point to themselves; ignore that if
4237 we're trying to output the abstract instance of this function. */
4238 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4241 if (immediate_origin == NULL_TREE)
4246 tree lookahead = immediate_origin;
4250 ret_val = lookahead;
4251 lookahead = (TREE_CODE (ret_val) == BLOCK)
4252 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4255 while (lookahead != NULL && lookahead != ret_val);
4261 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4262 of a virtual function may refer to a base class, so we check the 'this'
4266 decl_class_context (decl)
4269 tree context = NULL_TREE;
4271 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4272 context = DECL_CONTEXT (decl);
4274 context = TYPE_MAIN_VARIANT
4275 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4277 if (context && !TYPE_P (context))
4278 context = NULL_TREE;
4283 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4284 addition order, and correct that in reverse_all_dies. */
4287 add_dwarf_attr (die, attr)
4291 if (die != NULL && attr != NULL)
4293 attr->dw_attr_next = die->die_attr;
4294 die->die_attr = attr;
4298 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4299 static inline dw_val_class
4303 return a->dw_attr_val.val_class;
4306 /* Add a flag value attribute to a DIE. */
4309 add_AT_flag (die, attr_kind, flag)
4311 enum dwarf_attribute attr_kind;
4314 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4316 attr->dw_attr_next = NULL;
4317 attr->dw_attr = attr_kind;
4318 attr->dw_attr_val.val_class = dw_val_class_flag;
4319 attr->dw_attr_val.v.val_flag = flag;
4320 add_dwarf_attr (die, attr);
4323 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4324 static inline unsigned
4328 if (a && AT_class (a) == dw_val_class_flag)
4329 return a->dw_attr_val.v.val_flag;
4334 /* Add a signed integer attribute value to a DIE. */
4337 add_AT_int (die, attr_kind, int_val)
4339 enum dwarf_attribute attr_kind;
4342 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4344 attr->dw_attr_next = NULL;
4345 attr->dw_attr = attr_kind;
4346 attr->dw_attr_val.val_class = dw_val_class_const;
4347 attr->dw_attr_val.v.val_int = int_val;
4348 add_dwarf_attr (die, attr);
4351 static inline long int AT_int PARAMS ((dw_attr_ref));
4352 static inline long int
4356 if (a && AT_class (a) == dw_val_class_const)
4357 return a->dw_attr_val.v.val_int;
4362 /* Add an unsigned integer attribute value to a DIE. */
4365 add_AT_unsigned (die, attr_kind, unsigned_val)
4367 enum dwarf_attribute attr_kind;
4368 unsigned long unsigned_val;
4370 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4372 attr->dw_attr_next = NULL;
4373 attr->dw_attr = attr_kind;
4374 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4375 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4376 add_dwarf_attr (die, attr);
4379 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4380 static inline unsigned long
4384 if (a && AT_class (a) == dw_val_class_unsigned_const)
4385 return a->dw_attr_val.v.val_unsigned;
4390 /* Add an unsigned double integer attribute value to a DIE. */
4393 add_AT_long_long (die, attr_kind, val_hi, val_low)
4395 enum dwarf_attribute attr_kind;
4396 unsigned long val_hi;
4397 unsigned long val_low;
4399 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4401 attr->dw_attr_next = NULL;
4402 attr->dw_attr = attr_kind;
4403 attr->dw_attr_val.val_class = dw_val_class_long_long;
4404 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4405 attr->dw_attr_val.v.val_long_long.low = val_low;
4406 add_dwarf_attr (die, attr);
4409 /* Add a floating point attribute value to a DIE and return it. */
4412 add_AT_float (die, attr_kind, length, array)
4414 enum dwarf_attribute attr_kind;
4418 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4420 attr->dw_attr_next = NULL;
4421 attr->dw_attr = attr_kind;
4422 attr->dw_attr_val.val_class = dw_val_class_float;
4423 attr->dw_attr_val.v.val_float.length = length;
4424 attr->dw_attr_val.v.val_float.array = array;
4425 add_dwarf_attr (die, attr);
4428 /* Add a string attribute value to a DIE. */
4431 add_AT_string (die, attr_kind, str)
4433 enum dwarf_attribute attr_kind;
4436 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4437 struct indirect_string_node *node;
4439 if (! debug_str_hash)
4441 debug_str_hash = ht_create (10);
4442 debug_str_hash->alloc_node = indirect_string_alloc;
4445 node = (struct indirect_string_node *)
4446 ht_lookup (debug_str_hash, (const unsigned char *) str,
4447 strlen (str), HT_ALLOC);
4450 attr->dw_attr_next = NULL;
4451 attr->dw_attr = attr_kind;
4452 attr->dw_attr_val.val_class = dw_val_class_str;
4453 attr->dw_attr_val.v.val_str = node;
4454 add_dwarf_attr (die, attr);
4457 static inline const char *AT_string PARAMS ((dw_attr_ref));
4458 static inline const char *
4462 if (a && AT_class (a) == dw_val_class_str)
4463 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4468 /* Find out whether a string should be output inline in DIE
4469 or out-of-line in .debug_str section. */
4471 static int AT_string_form PARAMS ((dw_attr_ref));
4476 if (a && AT_class (a) == dw_val_class_str)
4478 struct indirect_string_node *node;
4480 extern int const_labelno;
4483 node = a->dw_attr_val.v.val_str;
4487 len = HT_LEN (&node->id) + 1;
4489 /* If the string is shorter or equal to the size
4490 of the reference, it is always better to put it
4492 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4493 return node->form = DW_FORM_string;
4495 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0)
4497 /* If we cannot expect the linker to merge strings
4498 in .debug_str section, only put it into .debug_str
4499 if it is worth even in this single module. */
4500 if ((len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4501 return node->form = DW_FORM_string;
4504 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4506 node->label = xstrdup (label);
4507 return node->form = DW_FORM_strp;
4513 /* Add a DIE reference attribute value to a DIE. */
4516 add_AT_die_ref (die, attr_kind, targ_die)
4518 enum dwarf_attribute attr_kind;
4519 dw_die_ref targ_die;
4521 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4523 attr->dw_attr_next = NULL;
4524 attr->dw_attr = attr_kind;
4525 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4526 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4527 attr->dw_attr_val.v.val_die_ref.external = 0;
4528 add_dwarf_attr (die, attr);
4531 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4532 static inline dw_die_ref
4536 if (a && AT_class (a) == dw_val_class_die_ref)
4537 return a->dw_attr_val.v.val_die_ref.die;
4542 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4547 if (a && AT_class (a) == dw_val_class_die_ref)
4548 return a->dw_attr_val.v.val_die_ref.external;
4553 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4555 set_AT_ref_external (a, i)
4559 if (a && AT_class (a) == dw_val_class_die_ref)
4560 a->dw_attr_val.v.val_die_ref.external = i;
4565 /* Add an FDE reference attribute value to a DIE. */
4568 add_AT_fde_ref (die, attr_kind, targ_fde)
4570 enum dwarf_attribute attr_kind;
4573 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4575 attr->dw_attr_next = NULL;
4576 attr->dw_attr = attr_kind;
4577 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4578 attr->dw_attr_val.v.val_fde_index = targ_fde;
4579 add_dwarf_attr (die, attr);
4582 /* Add a location description attribute value to a DIE. */
4585 add_AT_loc (die, attr_kind, loc)
4587 enum dwarf_attribute attr_kind;
4588 dw_loc_descr_ref loc;
4590 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4592 attr->dw_attr_next = NULL;
4593 attr->dw_attr = attr_kind;
4594 attr->dw_attr_val.val_class = dw_val_class_loc;
4595 attr->dw_attr_val.v.val_loc = loc;
4596 add_dwarf_attr (die, attr);
4599 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4600 static inline dw_loc_descr_ref
4604 if (a && AT_class (a) == dw_val_class_loc)
4605 return a->dw_attr_val.v.val_loc;
4611 add_AT_loc_list (die, attr_kind, loc_list)
4613 enum dwarf_attribute attr_kind;
4614 dw_loc_list_ref loc_list;
4616 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4618 attr->dw_attr_next = NULL;
4619 attr->dw_attr = attr_kind;
4620 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4621 attr->dw_attr_val.v.val_loc_list = loc_list;
4622 add_dwarf_attr (die, attr);
4623 have_location_lists = 1;
4626 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4628 static inline dw_loc_list_ref
4632 if (a && AT_class (a) == dw_val_class_loc_list)
4633 return a->dw_attr_val.v.val_loc_list;
4638 /* Add an address constant attribute value to a DIE. */
4641 add_AT_addr (die, attr_kind, addr)
4643 enum dwarf_attribute attr_kind;
4646 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4648 attr->dw_attr_next = NULL;
4649 attr->dw_attr = attr_kind;
4650 attr->dw_attr_val.val_class = dw_val_class_addr;
4651 attr->dw_attr_val.v.val_addr = addr;
4652 add_dwarf_attr (die, attr);
4655 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4660 if (a && AT_class (a) == dw_val_class_addr)
4661 return a->dw_attr_val.v.val_addr;
4666 /* Add a label identifier attribute value to a DIE. */
4669 add_AT_lbl_id (die, attr_kind, lbl_id)
4671 enum dwarf_attribute attr_kind;
4674 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4676 attr->dw_attr_next = NULL;
4677 attr->dw_attr = attr_kind;
4678 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4679 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4680 add_dwarf_attr (die, attr);
4683 /* Add a section offset attribute value to a DIE. */
4686 add_AT_lbl_offset (die, attr_kind, label)
4688 enum dwarf_attribute attr_kind;
4691 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4693 attr->dw_attr_next = NULL;
4694 attr->dw_attr = attr_kind;
4695 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4696 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4697 add_dwarf_attr (die, attr);
4700 /* Add an offset attribute value to a DIE. */
4703 add_AT_offset (die, attr_kind, offset)
4705 enum dwarf_attribute attr_kind;
4706 unsigned long offset;
4708 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4710 attr->dw_attr_next = NULL;
4711 attr->dw_attr = attr_kind;
4712 attr->dw_attr_val.val_class = dw_val_class_offset;
4713 attr->dw_attr_val.v.val_offset = offset;
4714 add_dwarf_attr (die, attr);
4717 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4718 static inline const char *
4722 if (a && (AT_class (a) == dw_val_class_lbl_id
4723 || AT_class (a) == dw_val_class_lbl_offset))
4724 return a->dw_attr_val.v.val_lbl_id;
4729 /* Get the attribute of type attr_kind. */
4731 static inline dw_attr_ref
4732 get_AT (die, attr_kind)
4734 enum dwarf_attribute attr_kind;
4737 dw_die_ref spec = NULL;
4741 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4743 if (a->dw_attr == attr_kind)
4746 if (a->dw_attr == DW_AT_specification
4747 || a->dw_attr == DW_AT_abstract_origin)
4752 return get_AT (spec, attr_kind);
4758 /* Return the "low pc" attribute value, typically associated with
4759 a subprogram DIE. Return null if the "low pc" attribute is
4760 either not present, or if it cannot be represented as an
4761 assembler label identifier. */
4763 static inline const char *
4767 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4768 return a ? AT_lbl (a) : NULL;
4771 /* Return the "high pc" attribute value, typically associated with
4772 a subprogram DIE. Return null if the "high pc" attribute is
4773 either not present, or if it cannot be represented as an
4774 assembler label identifier. */
4776 static inline const char *
4780 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4781 return a ? AT_lbl (a) : NULL;
4784 /* Return the value of the string attribute designated by ATTR_KIND, or
4785 NULL if it is not present. */
4787 static inline const char *
4788 get_AT_string (die, attr_kind)
4790 enum dwarf_attribute attr_kind;
4792 dw_attr_ref a = get_AT (die, attr_kind);
4793 return a ? AT_string (a) : NULL;
4796 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4797 if it is not present. */
4800 get_AT_flag (die, attr_kind)
4802 enum dwarf_attribute attr_kind;
4804 dw_attr_ref a = get_AT (die, attr_kind);
4805 return a ? AT_flag (a) : 0;
4808 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4809 if it is not present. */
4811 static inline unsigned
4812 get_AT_unsigned (die, attr_kind)
4814 enum dwarf_attribute attr_kind;
4816 dw_attr_ref a = get_AT (die, attr_kind);
4817 return a ? AT_unsigned (a) : 0;
4820 static inline dw_die_ref
4821 get_AT_ref (die, attr_kind)
4823 enum dwarf_attribute attr_kind;
4825 dw_attr_ref a = get_AT (die, attr_kind);
4826 return a ? AT_ref (a) : NULL;
4832 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4834 return (lang == DW_LANG_C || lang == DW_LANG_C89
4835 || lang == DW_LANG_C_plus_plus);
4841 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4842 == DW_LANG_C_plus_plus);
4848 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4850 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4856 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4858 return (lang == DW_LANG_Java);
4861 /* Free up the memory used by A. */
4863 static inline void free_AT PARAMS ((dw_attr_ref));
4868 switch (AT_class (a))
4870 case dw_val_class_str:
4871 if (a->dw_attr_val.v.val_str->refcount)
4872 a->dw_attr_val.v.val_str->refcount--;
4875 case dw_val_class_lbl_id:
4876 case dw_val_class_lbl_offset:
4877 free (a->dw_attr_val.v.val_lbl_id);
4880 case dw_val_class_float:
4881 free (a->dw_attr_val.v.val_float.array);
4891 /* Remove the specified attribute if present. */
4894 remove_AT (die, attr_kind)
4896 enum dwarf_attribute attr_kind;
4899 dw_attr_ref removed = NULL;
4903 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4904 if ((*p)->dw_attr == attr_kind)
4907 *p = (*p)->dw_attr_next;
4916 /* Free up the memory used by DIE. */
4918 static inline void free_die PARAMS ((dw_die_ref));
4923 remove_children (die);
4927 /* Discard the children of this DIE. */
4930 remove_children (die)
4933 dw_die_ref child_die = die->die_child;
4935 die->die_child = NULL;
4937 while (child_die != NULL)
4939 dw_die_ref tmp_die = child_die;
4942 child_die = child_die->die_sib;
4944 for (a = tmp_die->die_attr; a != NULL;)
4946 dw_attr_ref tmp_a = a;
4948 a = a->dw_attr_next;
4956 /* Add a child DIE below its parent. We build the lists up in reverse
4957 addition order, and correct that in reverse_all_dies. */
4960 add_child_die (die, child_die)
4962 dw_die_ref child_die;
4964 if (die != NULL && child_die != NULL)
4966 if (die == child_die)
4968 child_die->die_parent = die;
4969 child_die->die_sib = die->die_child;
4970 die->die_child = child_die;
4974 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4975 is the specification, to the front of PARENT's list of children. */
4978 splice_child_die (parent, child)
4979 dw_die_ref parent, child;
4983 /* We want the declaration DIE from inside the class, not the
4984 specification DIE at toplevel. */
4985 if (child->die_parent != parent)
4987 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4992 if (child->die_parent != parent
4993 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4996 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4999 *p = child->die_sib;
5003 child->die_sib = parent->die_child;
5004 parent->die_child = child;
5007 /* Return a pointer to a newly created DIE node. */
5009 static inline dw_die_ref
5010 new_die (tag_value, parent_die)
5011 enum dwarf_tag tag_value;
5012 dw_die_ref parent_die;
5014 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5016 die->die_tag = tag_value;
5018 if (parent_die != NULL)
5019 add_child_die (parent_die, die);
5022 limbo_die_node *limbo_node;
5024 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5025 limbo_node->die = die;
5026 limbo_node->next = limbo_die_list;
5027 limbo_die_list = limbo_node;
5033 /* Return the DIE associated with the given type specifier. */
5035 static inline dw_die_ref
5036 lookup_type_die (type)
5039 if (TREE_CODE (type) == VECTOR_TYPE)
5040 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5041 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5044 /* Equate a DIE to a given type specifier. */
5047 equate_type_number_to_die (type, type_die)
5049 dw_die_ref type_die;
5051 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5054 /* Return the DIE associated with a given declaration. */
5056 static inline dw_die_ref
5057 lookup_decl_die (decl)
5060 unsigned decl_id = DECL_UID (decl);
5062 return (decl_id < decl_die_table_in_use
5063 ? decl_die_table[decl_id] : NULL);
5066 /* Equate a DIE to a particular declaration. */
5069 equate_decl_number_to_die (decl, decl_die)
5071 dw_die_ref decl_die;
5073 unsigned decl_id = DECL_UID (decl);
5074 unsigned num_allocated;
5076 if (decl_id >= decl_die_table_allocated)
5079 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5080 / DECL_DIE_TABLE_INCREMENT)
5081 * DECL_DIE_TABLE_INCREMENT;
5084 = (dw_die_ref *) xrealloc (decl_die_table,
5085 sizeof (dw_die_ref) * num_allocated);
5087 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5088 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5089 decl_die_table_allocated = num_allocated;
5092 if (decl_id >= decl_die_table_in_use)
5093 decl_die_table_in_use = (decl_id + 1);
5095 decl_die_table[decl_id] = decl_die;
5098 /* Keep track of the number of spaces used to indent the
5099 output of the debugging routines that print the structure of
5100 the DIE internal representation. */
5101 static int print_indent;
5103 /* Indent the line the number of spaces given by print_indent. */
5106 print_spaces (outfile)
5109 fprintf (outfile, "%*s", print_indent, "");
5112 /* Print the information associated with a given DIE, and its children.
5113 This routine is a debugging aid only. */
5116 print_die (die, outfile)
5123 print_spaces (outfile);
5124 fprintf (outfile, "DIE %4lu: %s\n",
5125 die->die_offset, dwarf_tag_name (die->die_tag));
5126 print_spaces (outfile);
5127 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5128 fprintf (outfile, " offset: %lu\n", die->die_offset);
5130 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5132 print_spaces (outfile);
5133 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5135 switch (AT_class (a))
5137 case dw_val_class_addr:
5138 fprintf (outfile, "address");
5140 case dw_val_class_offset:
5141 fprintf (outfile, "offset");
5143 case dw_val_class_loc:
5144 fprintf (outfile, "location descriptor");
5146 case dw_val_class_loc_list:
5147 fprintf (outfile, "location list -> label:%s",
5148 AT_loc_list (a)->ll_symbol);
5150 case dw_val_class_const:
5151 fprintf (outfile, "%ld", AT_int (a));
5153 case dw_val_class_unsigned_const:
5154 fprintf (outfile, "%lu", AT_unsigned (a));
5156 case dw_val_class_long_long:
5157 fprintf (outfile, "constant (%lu,%lu)",
5158 a->dw_attr_val.v.val_long_long.hi,
5159 a->dw_attr_val.v.val_long_long.low);
5161 case dw_val_class_float:
5162 fprintf (outfile, "floating-point constant");
5164 case dw_val_class_flag:
5165 fprintf (outfile, "%u", AT_flag (a));
5167 case dw_val_class_die_ref:
5168 if (AT_ref (a) != NULL)
5170 if (AT_ref (a)->die_symbol)
5171 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5173 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5176 fprintf (outfile, "die -> <null>");
5178 case dw_val_class_lbl_id:
5179 case dw_val_class_lbl_offset:
5180 fprintf (outfile, "label: %s", AT_lbl (a));
5182 case dw_val_class_str:
5183 if (AT_string (a) != NULL)
5184 fprintf (outfile, "\"%s\"", AT_string (a));
5186 fprintf (outfile, "<null>");
5192 fprintf (outfile, "\n");
5195 if (die->die_child != NULL)
5198 for (c = die->die_child; c != NULL; c = c->die_sib)
5199 print_die (c, outfile);
5203 if (print_indent == 0)
5204 fprintf (outfile, "\n");
5207 /* Print the contents of the source code line number correspondence table.
5208 This routine is a debugging aid only. */
5211 print_dwarf_line_table (outfile)
5215 dw_line_info_ref line_info;
5217 fprintf (outfile, "\n\nDWARF source line information\n");
5218 for (i = 1; i < line_info_table_in_use; ++i)
5220 line_info = &line_info_table[i];
5221 fprintf (outfile, "%5d: ", i);
5222 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5223 fprintf (outfile, "%6ld", line_info->dw_line_num);
5224 fprintf (outfile, "\n");
5227 fprintf (outfile, "\n\n");
5230 /* Print the information collected for a given DIE. */
5233 debug_dwarf_die (die)
5236 print_die (die, stderr);
5239 /* Print all DWARF information collected for the compilation unit.
5240 This routine is a debugging aid only. */
5246 print_die (comp_unit_die, stderr);
5247 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5248 print_dwarf_line_table (stderr);
5251 /* We build up the lists of children and attributes by pushing new ones
5252 onto the beginning of the list. Reverse the lists for DIE so that
5253 they are in order of addition. */
5256 reverse_die_lists (die)
5259 dw_die_ref c, cp, cn;
5260 dw_attr_ref a, ap, an;
5262 for (a = die->die_attr, ap = 0; a; a = an)
5264 an = a->dw_attr_next;
5265 a->dw_attr_next = ap;
5270 for (c = die->die_child, cp = 0; c; c = cn)
5276 die->die_child = cp;
5279 /* reverse_die_lists only reverses the single die you pass it. Since
5280 we used to reverse all dies in add_sibling_attributes, which runs
5281 through all the dies, it would reverse all the dies. Now, however,
5282 since we don't call reverse_die_lists in add_sibling_attributes, we
5283 need a routine to recursively reverse all the dies. This is that
5287 reverse_all_dies (die)
5292 reverse_die_lists (die);
5294 for (c = die->die_child; c; c = c->die_sib)
5295 reverse_all_dies (c);
5298 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5299 the CU for the enclosing include file, if any. BINCL_DIE is the
5300 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5304 push_new_compile_unit (old_unit, bincl_die)
5305 dw_die_ref old_unit, bincl_die;
5307 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5308 dw_die_ref new_unit = gen_compile_unit_die (filename);
5309 new_unit->die_sib = old_unit;
5313 /* Close an include-file CU and reopen the enclosing one. */
5316 pop_compile_unit (old_unit)
5317 dw_die_ref old_unit;
5319 dw_die_ref new_unit = old_unit->die_sib;
5320 old_unit->die_sib = NULL;
5324 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5325 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5327 /* Calculate the checksum of a location expression. */
5330 loc_checksum (loc, ctx)
5331 dw_loc_descr_ref loc;
5332 struct md5_ctx *ctx;
5334 PROCESS (loc->dw_loc_opc);
5335 PROCESS (loc->dw_loc_oprnd1);
5336 PROCESS (loc->dw_loc_oprnd2);
5339 /* Calculate the checksum of an attribute. */
5342 attr_checksum (at, ctx)
5344 struct md5_ctx *ctx;
5346 dw_loc_descr_ref loc;
5349 PROCESS (at->dw_attr);
5351 /* We don't care about differences in file numbering. */
5352 if (at->dw_attr == DW_AT_decl_file
5353 /* Or that this was compiled with a different compiler snapshot; if
5354 the output is the same, that's what matters. */
5355 || at->dw_attr == DW_AT_producer)
5358 switch (AT_class (at))
5360 case dw_val_class_const:
5361 PROCESS (at->dw_attr_val.v.val_int);
5363 case dw_val_class_unsigned_const:
5364 PROCESS (at->dw_attr_val.v.val_unsigned);
5366 case dw_val_class_long_long:
5367 PROCESS (at->dw_attr_val.v.val_long_long);
5369 case dw_val_class_float:
5370 PROCESS (at->dw_attr_val.v.val_float);
5372 case dw_val_class_flag:
5373 PROCESS (at->dw_attr_val.v.val_flag);
5376 case dw_val_class_str:
5377 PROCESS_STRING (AT_string (at));
5380 case dw_val_class_addr:
5382 switch (GET_CODE (r))
5385 PROCESS_STRING (XSTR (r, 0));
5393 case dw_val_class_offset:
5394 PROCESS (at->dw_attr_val.v.val_offset);
5397 case dw_val_class_loc:
5398 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5399 loc_checksum (loc, ctx);
5402 case dw_val_class_die_ref:
5403 if (AT_ref (at)->die_offset)
5404 PROCESS (AT_ref (at)->die_offset);
5405 /* FIXME else use target die name or something. */
5407 case dw_val_class_fde_ref:
5408 case dw_val_class_lbl_id:
5409 case dw_val_class_lbl_offset:
5417 /* Calculate the checksum of a DIE. */
5420 die_checksum (die, ctx)
5422 struct md5_ctx *ctx;
5427 PROCESS (die->die_tag);
5429 for (a = die->die_attr; a; a = a->dw_attr_next)
5430 attr_checksum (a, ctx);
5432 for (c = die->die_child; c; c = c->die_sib)
5433 die_checksum (c, ctx);
5437 #undef PROCESS_STRING
5439 /* The prefix to attach to symbols on DIEs in the current comdat debug
5441 static char *comdat_symbol_id;
5443 /* The index of the current symbol within the current comdat CU. */
5444 static unsigned int comdat_symbol_number;
5446 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5447 children, and set comdat_symbol_id accordingly. */
5450 compute_section_prefix (unit_die)
5451 dw_die_ref unit_die;
5455 unsigned char checksum[16];
5458 md5_init_ctx (&ctx);
5459 die_checksum (unit_die, &ctx);
5460 md5_finish_ctx (&ctx, checksum);
5463 const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
5464 name = (char *) alloca (strlen (p) + 64);
5465 sprintf (name, "%s.", p);
5468 clean_symbol_name (name);
5471 char *p = name + strlen (name);
5472 for (i = 0; i < 4; ++i)
5474 sprintf (p, "%.2x", checksum[i]);
5479 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5480 comdat_symbol_number = 0;
5483 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5489 switch (die->die_tag)
5491 case DW_TAG_array_type:
5492 case DW_TAG_class_type:
5493 case DW_TAG_enumeration_type:
5494 case DW_TAG_pointer_type:
5495 case DW_TAG_reference_type:
5496 case DW_TAG_string_type:
5497 case DW_TAG_structure_type:
5498 case DW_TAG_subroutine_type:
5499 case DW_TAG_union_type:
5500 case DW_TAG_ptr_to_member_type:
5501 case DW_TAG_set_type:
5502 case DW_TAG_subrange_type:
5503 case DW_TAG_base_type:
5504 case DW_TAG_const_type:
5505 case DW_TAG_file_type:
5506 case DW_TAG_packed_type:
5507 case DW_TAG_volatile_type:
5514 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5515 Basically, we want to choose the bits that are likely to be shared between
5516 compilations (types) and leave out the bits that are specific to individual
5517 compilations (functions). */
5524 /* I think we want to leave base types and __vtbl_ptr_type in the
5525 main CU, as we do for stabs. The advantage is a greater
5526 likelihood of sharing between objects that don't include headers
5527 in the same order (and therefore would put the base types in a
5528 different comdat). jason 8/28/00 */
5529 if (c->die_tag == DW_TAG_base_type)
5532 if (c->die_tag == DW_TAG_pointer_type
5533 || c->die_tag == DW_TAG_reference_type
5534 || c->die_tag == DW_TAG_const_type
5535 || c->die_tag == DW_TAG_volatile_type)
5537 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5538 return t ? is_comdat_die (t) : 0;
5542 return is_type_die (c);
5545 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5546 compilation unit. */
5552 if (is_type_die (c))
5554 if (get_AT (c, DW_AT_declaration)
5555 && ! get_AT (c, DW_AT_specification))
5561 gen_internal_sym (prefix)
5565 static int label_num;
5566 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5567 return xstrdup (buf);
5570 /* Assign symbols to all worthy DIEs under DIE. */
5573 assign_symbol_names (die)
5578 if (is_symbol_die (die))
5580 if (comdat_symbol_id)
5582 char *p = alloca (strlen (comdat_symbol_id) + 64);
5583 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5584 comdat_symbol_id, comdat_symbol_number++);
5585 die->die_symbol = xstrdup (p);
5588 die->die_symbol = gen_internal_sym ("LDIE");
5591 for (c = die->die_child; c != NULL; c = c->die_sib)
5592 assign_symbol_names (c);
5595 /* Traverse the DIE (which is always comp_unit_die), and set up
5596 additional compilation units for each of the include files we see
5597 bracketed by BINCL/EINCL. */
5600 break_out_includes (die)
5604 dw_die_ref unit = NULL;
5605 limbo_die_node *node;
5607 for (ptr = &(die->die_child); *ptr; )
5609 dw_die_ref c = *ptr;
5611 if (c->die_tag == DW_TAG_GNU_BINCL
5612 || c->die_tag == DW_TAG_GNU_EINCL
5613 || (unit && is_comdat_die (c)))
5615 /* This DIE is for a secondary CU; remove it from the main one. */
5618 if (c->die_tag == DW_TAG_GNU_BINCL)
5620 unit = push_new_compile_unit (unit, c);
5623 else if (c->die_tag == DW_TAG_GNU_EINCL)
5625 unit = pop_compile_unit (unit);
5629 add_child_die (unit, c);
5633 /* Leave this DIE in the main CU. */
5634 ptr = &(c->die_sib);
5640 /* We can only use this in debugging, since the frontend doesn't check
5641 to make sure that we leave every include file we enter. */
5646 assign_symbol_names (die);
5647 for (node = limbo_die_list; node; node = node->next)
5649 compute_section_prefix (node->die);
5650 assign_symbol_names (node->die);
5654 /* Traverse the DIE and add a sibling attribute if it may have the
5655 effect of speeding up access to siblings. To save some space,
5656 avoid generating sibling attributes for DIE's without children. */
5659 add_sibling_attributes (die)
5664 if (die->die_tag != DW_TAG_compile_unit
5665 && die->die_sib && die->die_child != NULL)
5666 /* Add the sibling link to the front of the attribute list. */
5667 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5669 for (c = die->die_child; c != NULL; c = c->die_sib)
5670 add_sibling_attributes (c);
5673 /* Output all location lists for the DIE and it's children */
5675 output_location_lists (die)
5680 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5682 if (AT_class (d_attr) == dw_val_class_loc_list)
5684 output_loc_list (AT_loc_list (d_attr));
5687 for (c = die->die_child; c != NULL; c = c->die_sib)
5688 output_location_lists (c);
5691 /* The format of each DIE (and its attribute value pairs)
5692 is encoded in an abbreviation table. This routine builds the
5693 abbreviation table and assigns a unique abbreviation id for
5694 each abbreviation entry. The children of each die are visited
5698 build_abbrev_table (die)
5701 unsigned long abbrev_id;
5702 unsigned int n_alloc;
5704 dw_attr_ref d_attr, a_attr;
5706 /* Scan the DIE references, and mark as external any that refer to
5707 DIEs from other CUs (i.e. those which are not marked). */
5708 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5710 if (AT_class (d_attr) == dw_val_class_die_ref
5711 && AT_ref (d_attr)->die_mark == 0)
5713 if (AT_ref (d_attr)->die_symbol == 0)
5715 set_AT_ref_external (d_attr, 1);
5719 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5721 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5723 if (abbrev->die_tag == die->die_tag)
5725 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5727 a_attr = abbrev->die_attr;
5728 d_attr = die->die_attr;
5730 while (a_attr != NULL && d_attr != NULL)
5732 if ((a_attr->dw_attr != d_attr->dw_attr)
5733 || (value_format (a_attr) != value_format (d_attr)))
5736 a_attr = a_attr->dw_attr_next;
5737 d_attr = d_attr->dw_attr_next;
5740 if (a_attr == NULL && d_attr == NULL)
5746 if (abbrev_id >= abbrev_die_table_in_use)
5748 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5750 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5752 = (dw_die_ref *) xrealloc (abbrev_die_table,
5753 sizeof (dw_die_ref) * n_alloc);
5755 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5756 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5757 abbrev_die_table_allocated = n_alloc;
5760 ++abbrev_die_table_in_use;
5761 abbrev_die_table[abbrev_id] = die;
5764 die->die_abbrev = abbrev_id;
5765 for (c = die->die_child; c != NULL; c = c->die_sib)
5766 build_abbrev_table (c);
5769 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5772 constant_size (value)
5773 long unsigned value;
5780 log = floor_log2 (value);
5783 log = 1 << (floor_log2 (log) + 1);
5788 /* Return the size of a DIE, as it is represented in the
5789 .debug_info section. */
5791 static unsigned long
5795 unsigned long size = 0;
5798 size += size_of_uleb128 (die->die_abbrev);
5799 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5801 switch (AT_class (a))
5803 case dw_val_class_addr:
5804 size += DWARF2_ADDR_SIZE;
5806 case dw_val_class_offset:
5807 size += DWARF_OFFSET_SIZE;
5809 case dw_val_class_loc:
5811 unsigned long lsize = size_of_locs (AT_loc (a));
5814 size += constant_size (lsize);
5818 case dw_val_class_loc_list:
5819 size += DWARF_OFFSET_SIZE;
5821 case dw_val_class_const:
5822 size += size_of_sleb128 (AT_int (a));
5824 case dw_val_class_unsigned_const:
5825 size += constant_size (AT_unsigned (a));
5827 case dw_val_class_long_long:
5828 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5830 case dw_val_class_float:
5831 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5833 case dw_val_class_flag:
5836 case dw_val_class_die_ref:
5837 size += DWARF_OFFSET_SIZE;
5839 case dw_val_class_fde_ref:
5840 size += DWARF_OFFSET_SIZE;
5842 case dw_val_class_lbl_id:
5843 size += DWARF2_ADDR_SIZE;
5845 case dw_val_class_lbl_offset:
5846 size += DWARF_OFFSET_SIZE;
5848 case dw_val_class_str:
5849 if (AT_string_form (a) == DW_FORM_strp)
5850 size += DWARF_OFFSET_SIZE;
5852 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5862 /* Size the debugging information associated with a given DIE.
5863 Visits the DIE's children recursively. Updates the global
5864 variable next_die_offset, on each time through. Uses the
5865 current value of next_die_offset to update the die_offset
5866 field in each DIE. */
5869 calc_die_sizes (die)
5873 die->die_offset = next_die_offset;
5874 next_die_offset += size_of_die (die);
5876 for (c = die->die_child; c != NULL; c = c->die_sib)
5879 if (die->die_child != NULL)
5880 /* Count the null byte used to terminate sibling lists. */
5881 next_die_offset += 1;
5884 /* Set the marks for a die and its children. We do this so
5885 that we know whether or not a reference needs to use FORM_ref_addr; only
5886 DIEs in the same CU will be marked. We used to clear out the offset
5887 and use that as the flag, but ran into ordering problems. */
5895 for (c = die->die_child; c; c = c->die_sib)
5899 /* Clear the marks for a die and its children. */
5907 for (c = die->die_child; c; c = c->die_sib)
5911 /* Return the size of the .debug_pubnames table generated for the
5912 compilation unit. */
5914 static unsigned long
5920 size = DWARF_PUBNAMES_HEADER_SIZE;
5921 for (i = 0; i < pubname_table_in_use; ++i)
5923 pubname_ref p = &pubname_table[i];
5924 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
5927 size += DWARF_OFFSET_SIZE;
5931 /* Return the size of the information in the .debug_aranges section. */
5933 static unsigned long
5938 size = DWARF_ARANGES_HEADER_SIZE;
5940 /* Count the address/length pair for this compilation unit. */
5941 size += 2 * DWARF2_ADDR_SIZE;
5942 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5944 /* Count the two zero words used to terminated the address range table. */
5945 size += 2 * DWARF2_ADDR_SIZE;
5949 /* Select the encoding of an attribute value. */
5951 static enum dwarf_form
5955 switch (a->dw_attr_val.val_class)
5957 case dw_val_class_addr:
5958 return DW_FORM_addr;
5959 case dw_val_class_offset:
5960 if (DWARF_OFFSET_SIZE == 4)
5961 return DW_FORM_data4;
5962 if (DWARF_OFFSET_SIZE == 8)
5963 return DW_FORM_data8;
5965 case dw_val_class_loc_list:
5966 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5967 .debug_loc section */
5968 return DW_FORM_data4;
5969 case dw_val_class_loc:
5970 switch (constant_size (size_of_locs (AT_loc (a))))
5973 return DW_FORM_block1;
5975 return DW_FORM_block2;
5979 case dw_val_class_const:
5980 return DW_FORM_sdata;
5981 case dw_val_class_unsigned_const:
5982 switch (constant_size (AT_unsigned (a)))
5985 return DW_FORM_data1;
5987 return DW_FORM_data2;
5989 return DW_FORM_data4;
5991 return DW_FORM_data8;
5995 case dw_val_class_long_long:
5996 return DW_FORM_block1;
5997 case dw_val_class_float:
5998 return DW_FORM_block1;
5999 case dw_val_class_flag:
6000 return DW_FORM_flag;
6001 case dw_val_class_die_ref:
6002 if (AT_ref_external (a))
6003 return DW_FORM_ref_addr;
6006 case dw_val_class_fde_ref:
6007 return DW_FORM_data;
6008 case dw_val_class_lbl_id:
6009 return DW_FORM_addr;
6010 case dw_val_class_lbl_offset:
6011 return DW_FORM_data;
6012 case dw_val_class_str:
6013 return AT_string_form (a);
6020 /* Output the encoding of an attribute value. */
6023 output_value_format (a)
6026 enum dwarf_form form = value_format (a);
6027 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6030 /* Output the .debug_abbrev section which defines the DIE abbreviation
6034 output_abbrev_section ()
6036 unsigned long abbrev_id;
6039 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6041 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6043 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6045 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6046 dwarf_tag_name (abbrev->die_tag));
6048 if (abbrev->die_child != NULL)
6049 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6051 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6053 for (a_attr = abbrev->die_attr; a_attr != NULL;
6054 a_attr = a_attr->dw_attr_next)
6056 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6057 dwarf_attr_name (a_attr->dw_attr));
6058 output_value_format (a_attr);
6061 dw2_asm_output_data (1, 0, NULL);
6062 dw2_asm_output_data (1, 0, NULL);
6065 /* Terminate the table. */
6066 dw2_asm_output_data (1, 0, NULL);
6069 /* Output a symbol we can use to refer to this DIE from another CU. */
6072 output_die_symbol (die)
6075 char *sym = die->die_symbol;
6080 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6081 /* We make these global, not weak; if the target doesn't support
6082 .linkonce, it doesn't support combining the sections, so debugging
6084 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6085 ASM_OUTPUT_LABEL (asm_out_file, sym);
6088 /* Return a new location list, given the begin and end range, and the
6089 expression. gensym tells us whether to generate a new internal
6090 symbol for this location list node, which is done for the head of
6092 static inline dw_loc_list_ref
6093 new_loc_list (expr, begin, end, section, gensym)
6094 dw_loc_descr_ref expr;
6097 const char *section;
6100 dw_loc_list_ref retlist
6101 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6102 retlist->begin = begin;
6104 retlist->expr = expr;
6105 retlist->section = section;
6107 retlist->ll_symbol = gen_internal_sym ("LLST");
6111 /* Add a location description expression to a location list */
6113 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6114 dw_loc_list_ref *list_head;
6115 dw_loc_descr_ref descr;
6118 const char *section;
6122 /* Find the end of the chain. */
6123 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6125 /* Add a new location list node to the list */
6126 *d = new_loc_list (descr, begin, end, section, 0);
6129 /* Output the location list given to us */
6131 output_loc_list (list_head)
6132 dw_loc_list_ref list_head;
6134 dw_loc_list_ref curr=list_head;
6135 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6137 /* ??? This shouldn't be needed now that we've forced the
6138 compilation unit base address to zero when there is code
6139 in more than one section. */
6140 if (strcmp (curr->section, ".text") == 0)
6142 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6143 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
6144 "Location list base address specifier fake entry");
6145 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6146 "Location list base address specifier base");
6148 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6151 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6152 "Location list begin address (%s)",
6153 list_head->ll_symbol);
6154 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6155 "Location list end address (%s)",
6156 list_head->ll_symbol);
6157 size = size_of_locs (curr->expr);
6159 /* Output the block length for this list of location operations. */
6160 dw2_asm_output_data (constant_size (size), size, "%s",
6161 "Location expression size");
6163 output_loc_sequence (curr->expr);
6165 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6166 "Location list terminator begin (%s)",
6167 list_head->ll_symbol);
6168 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6169 "Location list terminator end (%s)",
6170 list_head->ll_symbol);
6173 /* Output the DIE and its attributes. Called recursively to generate
6174 the definitions of each child DIE. */
6184 /* If someone in another CU might refer to us, set up a symbol for
6185 them to point to. */
6186 if (die->die_symbol)
6187 output_die_symbol (die);
6189 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6190 die->die_offset, dwarf_tag_name (die->die_tag));
6192 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6194 const char *name = dwarf_attr_name (a->dw_attr);
6196 switch (AT_class (a))
6198 case dw_val_class_addr:
6199 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6202 case dw_val_class_offset:
6203 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6207 case dw_val_class_loc:
6208 size = size_of_locs (AT_loc (a));
6210 /* Output the block length for this list of location operations. */
6211 dw2_asm_output_data (constant_size (size), size, "%s", name);
6213 output_loc_sequence (AT_loc (a));
6216 case dw_val_class_const:
6217 /* ??? It would be slightly more efficient to use a scheme like is
6218 used for unsigned constants below, but gdb 4.x does not sign
6219 extend. Gdb 5.x does sign extend. */
6220 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6223 case dw_val_class_unsigned_const:
6224 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6225 AT_unsigned (a), "%s", name);
6228 case dw_val_class_long_long:
6230 unsigned HOST_WIDE_INT first, second;
6232 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6235 if (WORDS_BIG_ENDIAN)
6237 first = a->dw_attr_val.v.val_long_long.hi;
6238 second = a->dw_attr_val.v.val_long_long.low;
6242 first = a->dw_attr_val.v.val_long_long.low;
6243 second = a->dw_attr_val.v.val_long_long.hi;
6245 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6246 first, "long long constant");
6247 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6252 case dw_val_class_float:
6256 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6259 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6260 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6261 "fp constant word %u", i);
6265 case dw_val_class_flag:
6266 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6269 case dw_val_class_loc_list:
6271 char *sym = AT_loc_list (a)->ll_symbol;
6274 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6275 loc_section_label, "%s", name);
6279 case dw_val_class_die_ref:
6280 if (AT_ref_external (a))
6282 char *sym = AT_ref (a)->die_symbol;
6285 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6287 else if (AT_ref (a)->die_offset == 0)
6290 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6294 case dw_val_class_fde_ref:
6297 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6298 a->dw_attr_val.v.val_fde_index * 2);
6299 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6303 case dw_val_class_lbl_id:
6304 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6307 case dw_val_class_lbl_offset:
6308 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6311 case dw_val_class_str:
6312 if (AT_string_form (a) == DW_FORM_strp)
6313 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6314 a->dw_attr_val.v.val_str->label,
6317 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6325 for (c = die->die_child; c != NULL; c = c->die_sib)
6328 if (die->die_child != NULL)
6330 /* Add null byte to terminate sibling list. */
6331 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6336 /* Output the compilation unit that appears at the beginning of the
6337 .debug_info section, and precedes the DIE descriptions. */
6340 output_compilation_unit_header ()
6342 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6343 "Length of Compilation Unit Info");
6345 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6347 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6348 "Offset Into Abbrev. Section");
6350 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6353 /* Output the compilation unit DIE and its children. */
6356 output_comp_unit (die)
6359 const char *secname;
6361 /* Even if there are no children of this DIE, we must output the
6362 information about the compilation unit. Otherwise, on an empty
6363 translation unit, we will generate a present, but empty,
6364 .debug_info section. IRIX 6.5 `nm' will then complain when
6367 Mark all the DIEs in this CU so we know which get local refs. */
6370 build_abbrev_table (die);
6372 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6373 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6374 calc_die_sizes (die);
6376 if (die->die_symbol)
6378 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6379 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6381 die->die_symbol = NULL;
6384 secname = (const char *) DEBUG_INFO_SECTION;
6386 /* Output debugging information. */
6387 named_section_flags (secname, SECTION_DEBUG);
6388 output_compilation_unit_header ();
6391 /* Leave the marks on the main CU, so we can check them in
6393 if (die->die_symbol)
6397 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6398 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6399 argument list, and maybe the scope. */
6402 dwarf2_name (decl, scope)
6406 return (*decl_printable_name) (decl, scope ? 1 : 0);
6409 /* Add a new entry to .debug_pubnames if appropriate. */
6412 add_pubname (decl, die)
6418 if (! TREE_PUBLIC (decl))
6421 if (pubname_table_in_use == pubname_table_allocated)
6423 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6424 pubname_table = (pubname_ref) xrealloc
6425 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6428 p = &pubname_table[pubname_table_in_use++];
6431 p->name = xstrdup (dwarf2_name (decl, 1));
6434 /* Output the public names table used to speed up access to externally
6435 visible names. For now, only generate entries for externally
6436 visible procedures. */
6442 unsigned long pubnames_length = size_of_pubnames ();
6444 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6445 "Length of Public Names Info");
6447 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6449 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6450 "Offset of Compilation Unit Info");
6452 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6453 "Compilation Unit Length");
6455 for (i = 0; i < pubname_table_in_use; ++i)
6457 pubname_ref pub = &pubname_table[i];
6459 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6460 if (pub->die->die_mark == 0)
6463 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6466 dw2_asm_output_nstring (pub->name, -1, "external name");
6469 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6472 /* Add a new entry to .debug_aranges if appropriate. */
6475 add_arange (decl, die)
6479 if (! DECL_SECTION_NAME (decl))
6482 if (arange_table_in_use == arange_table_allocated)
6484 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6485 arange_table = (dw_die_ref *)
6486 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6489 arange_table[arange_table_in_use++] = die;
6492 /* Output the information that goes into the .debug_aranges table.
6493 Namely, define the beginning and ending address range of the
6494 text section generated for this compilation unit. */
6500 unsigned long aranges_length = size_of_aranges ();
6502 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6503 "Length of Address Ranges Info");
6505 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6507 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6508 "Offset of Compilation Unit Info");
6510 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6512 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6514 /* We need to align to twice the pointer size here. */
6515 if (DWARF_ARANGES_PAD_SIZE)
6517 /* Pad using a 2 byte words so that padding is correct for any
6519 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6520 2 * DWARF2_ADDR_SIZE);
6521 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6522 dw2_asm_output_data (2, 0, NULL);
6525 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6526 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6527 text_section_label, "Length");
6529 for (i = 0; i < arange_table_in_use; ++i)
6531 dw_die_ref die = arange_table[i];
6533 /* We shouldn't see aranges for DIEs outside of the main CU. */
6534 if (die->die_mark == 0)
6537 if (die->die_tag == DW_TAG_subprogram)
6539 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6541 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6542 get_AT_low_pc (die), "Length");
6546 /* A static variable; extract the symbol from DW_AT_location.
6547 Note that this code isn't currently hit, as we only emit
6548 aranges for functions (jason 9/23/99). */
6550 dw_attr_ref a = get_AT (die, DW_AT_location);
6551 dw_loc_descr_ref loc;
6552 if (! a || AT_class (a) != dw_val_class_loc)
6556 if (loc->dw_loc_opc != DW_OP_addr)
6559 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6560 loc->dw_loc_oprnd1.v.val_addr, "Address");
6561 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6562 get_AT_unsigned (die, DW_AT_byte_size),
6567 /* Output the terminator words. */
6568 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6569 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6572 /* Add a new entry to .debug_ranges. Return the offset at which it
6579 unsigned int in_use = ranges_table_in_use;
6581 if (in_use == ranges_table_allocated)
6583 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6584 ranges_table = (dw_ranges_ref)
6585 xrealloc (ranges_table, (ranges_table_allocated
6586 * sizeof (struct dw_ranges_struct)));
6589 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6590 ranges_table_in_use = in_use + 1;
6592 return in_use * 2 * DWARF2_ADDR_SIZE;
6599 static const char *const start_fmt = "Offset 0x%x";
6600 const char *fmt = start_fmt;
6602 for (i = 0; i < ranges_table_in_use; ++i)
6604 int block_num = ranges_table[i].block_num;
6608 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6609 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6611 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6612 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6614 /* If all code is in the text section, then the compilation
6615 unit base address defaults to DW_AT_low_pc, which is the
6616 base of the text section. */
6617 if (separate_line_info_table_in_use == 0)
6619 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6621 fmt, i * 2 * DWARF2_ADDR_SIZE);
6622 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6623 text_section_label, NULL);
6625 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6626 compilation unit base address to zero, which allows us to
6627 use absolute addresses, and not worry about whether the
6628 target supports cross-section arithmetic. */
6631 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6632 fmt, i * 2 * DWARF2_ADDR_SIZE);
6633 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6640 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6641 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6647 /* Data structure containing information about input files. */
6650 char *path; /* Complete file name. */
6651 char *fname; /* File name part. */
6652 int length; /* Length of entire string. */
6653 int file_idx; /* Index in input file table. */
6654 int dir_idx; /* Index in directory table. */
6657 /* Data structure containing information about directories with source
6661 char *path; /* Path including directory name. */
6662 int length; /* Path length. */
6663 int prefix; /* Index of directory entry which is a prefix. */
6664 int count; /* Number of files in this directory. */
6665 int dir_idx; /* Index of directory used as base. */
6666 int used; /* Used in the end? */
6669 /* Callback function for file_info comparison. We sort by looking at
6670 the directories in the path. */
6673 file_info_cmp (p1, p2)
6677 const struct file_info *s1 = p1;
6678 const struct file_info *s2 = p2;
6682 /* Take care of file names without directories. We need to make sure that
6683 we return consistent values to qsort since some will get confused if
6684 we return the same value when identical operands are passed in opposite
6685 orders. So if neither has a directory, return 0 and otherwise return
6686 1 or -1 depending on which one has the directory. */
6687 if ((s1->path == s1->fname || s2->path == s2->fname))
6688 return (s2->path == s2->fname) - (s1->path == s1->fname);
6690 cp1 = (unsigned char *) s1->path;
6691 cp2 = (unsigned char *) s2->path;
6697 /* Reached the end of the first path? If so, handle like above. */
6698 if ((cp1 == (unsigned char *) s1->fname)
6699 || (cp2 == (unsigned char *) s2->fname))
6700 return ((cp2 == (unsigned char *) s2->fname)
6701 - (cp1 == (unsigned char *) s1->fname));
6703 /* Character of current path component the same? */
6704 else if (*cp1 != *cp2)
6709 /* Output the directory table and the file name table. We try to minimize
6710 the total amount of memory needed. A heuristic is used to avoid large
6711 slowdowns with many input files. */
6713 output_file_names ()
6715 struct file_info *files;
6716 struct dir_info *dirs;
6725 /* Allocate the various arrays we need. */
6726 files = (struct file_info *) alloca (file_table.in_use
6727 * sizeof (struct file_info));
6728 dirs = (struct dir_info *) alloca (file_table.in_use
6729 * sizeof (struct dir_info));
6731 /* Sort the file names. */
6732 for (i = 1; i < (int) file_table.in_use; ++i)
6736 /* Skip all leading "./". */
6737 f = file_table.table[i];
6738 while (f[0] == '.' && f[1] == '/')
6741 /* Create a new array entry. */
6743 files[i].length = strlen (f);
6744 files[i].file_idx = i;
6746 /* Search for the file name part. */
6747 f = strrchr (f, '/');
6748 files[i].fname = f == NULL ? files[i].path : f + 1;
6750 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6752 /* Find all the different directories used. */
6753 dirs[0].path = files[1].path;
6754 dirs[0].length = files[1].fname - files[1].path;
6755 dirs[0].prefix = -1;
6757 dirs[0].dir_idx = 0;
6759 files[1].dir_idx = 0;
6762 for (i = 2; i < (int) file_table.in_use; ++i)
6763 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6764 && memcmp (dirs[ndirs - 1].path, files[i].path,
6765 dirs[ndirs - 1].length) == 0)
6767 /* Same directory as last entry. */
6768 files[i].dir_idx = ndirs - 1;
6769 ++dirs[ndirs - 1].count;
6775 /* This is a new directory. */
6776 dirs[ndirs].path = files[i].path;
6777 dirs[ndirs].length = files[i].fname - files[i].path;
6778 dirs[ndirs].count = 1;
6779 dirs[ndirs].dir_idx = ndirs;
6780 dirs[ndirs].used = 0;
6781 files[i].dir_idx = ndirs;
6783 /* Search for a prefix. */
6784 dirs[ndirs].prefix = -1;
6785 for (j = 0; j < ndirs; ++j)
6786 if (dirs[j].length < dirs[ndirs].length
6787 && dirs[j].length > 1
6788 && (dirs[ndirs].prefix == -1
6789 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6790 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6791 dirs[ndirs].prefix = j;
6796 /* Now to the actual work. We have to find a subset of the
6797 directories which allow expressing the file name using references
6798 to the directory table with the least amount of characters. We
6799 do not do an exhaustive search where we would have to check out
6800 every combination of every single possible prefix. Instead we
6801 use a heuristic which provides nearly optimal results in most
6802 cases and never is much off. */
6803 saved = (int *) alloca (ndirs * sizeof (int));
6804 savehere = (int *) alloca (ndirs * sizeof (int));
6806 memset (saved, '\0', ndirs * sizeof (saved[0]));
6807 for (i = 0; i < ndirs; ++i)
6812 /* We can always save some space for the current directory. But
6813 this does not mean it will be enough to justify adding the
6815 savehere[i] = dirs[i].length;
6816 total = (savehere[i] - saved[i]) * dirs[i].count;
6818 for (j = i + 1; j < ndirs; ++j)
6822 if (saved[j] < dirs[i].length)
6824 /* Determine whether the dirs[i] path is a prefix of the
6829 while (k != -1 && k != i)
6834 /* Yes it is. We can possibly safe some memory but
6835 writing the filenames in dirs[j] relative to
6837 savehere[j] = dirs[i].length;
6838 total += (savehere[j] - saved[j]) * dirs[j].count;
6843 /* Check whether we can safe enough to justify adding the dirs[i]
6845 if (total > dirs[i].length + 1)
6847 /* It's worthwhile adding. */
6848 for (j = i; j < ndirs; ++j)
6849 if (savehere[j] > 0)
6851 /* Remember how much we saved for this directory so far. */
6852 saved[j] = savehere[j];
6854 /* Remember the prefix directory. */
6855 dirs[j].dir_idx = i;
6860 /* We have to emit them in the order they appear in the file_table
6861 array since the index is used in the debug info generation. To
6862 do this efficiently we generate a back-mapping of the indices
6864 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6865 for (i = 1; i < (int) file_table.in_use; ++i)
6867 backmap[files[i].file_idx] = i;
6868 /* Mark this directory as used. */
6869 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6872 /* That was it. We are ready to emit the information. First the
6873 directory name table. Here we have to make sure that the first
6874 actually emitted directory name has the index one. Zero is
6875 reserved for the current working directory. Make sure we do not
6876 confuse these indices with the one for the constructed table
6877 (even though most of the time they are identical). */
6879 idx_offset = dirs[0].length > 0 ? 1 : 0;
6880 for (i = 1 - idx_offset; i < ndirs; ++i)
6881 if (dirs[i].used != 0)
6883 dirs[i].used = idx++;
6884 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6885 "Directory Entry: 0x%x", dirs[i].used);
6887 dw2_asm_output_data (1, 0, "End directory table");
6889 /* Correct the index for the current working directory entry if it
6891 if (idx_offset == 0)
6894 /* Now write all the file names. */
6895 for (i = 1; i < (int) file_table.in_use; ++i)
6897 int file_idx = backmap[i];
6898 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6900 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6901 "File Entry: 0x%x", i);
6903 /* Include directory index. */
6904 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6906 /* Modification time. */
6907 dw2_asm_output_data_uleb128 (0, NULL);
6909 /* File length in bytes. */
6910 dw2_asm_output_data_uleb128 (0, NULL);
6912 dw2_asm_output_data (1, 0, "End file name table");
6916 /* Output the source line number correspondence information. This
6917 information goes into the .debug_line section. */
6922 char l1[20], l2[20], p1[20], p2[20];
6923 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6924 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6927 unsigned long lt_index;
6928 unsigned long current_line;
6931 unsigned long current_file;
6932 unsigned long function;
6934 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6935 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6936 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6937 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6939 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6940 "Length of Source Line Info");
6941 ASM_OUTPUT_LABEL (asm_out_file, l1);
6943 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6945 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6946 ASM_OUTPUT_LABEL (asm_out_file, p1);
6948 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6949 "Minimum Instruction Length");
6951 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6952 "Default is_stmt_start flag");
6954 dw2_asm_output_data (1, DWARF_LINE_BASE,
6955 "Line Base Value (Special Opcodes)");
6957 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6958 "Line Range Value (Special Opcodes)");
6960 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6961 "Special Opcode Base");
6963 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6967 case DW_LNS_advance_pc:
6968 case DW_LNS_advance_line:
6969 case DW_LNS_set_file:
6970 case DW_LNS_set_column:
6971 case DW_LNS_fixed_advance_pc:
6979 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6983 /* Write out the information about the files we use. */
6984 output_file_names ();
6985 ASM_OUTPUT_LABEL (asm_out_file, p2);
6987 /* We used to set the address register to the first location in the text
6988 section here, but that didn't accomplish anything since we already
6989 have a line note for the opening brace of the first function. */
6991 /* Generate the line number to PC correspondence table, encoded as
6992 a series of state machine operations. */
6995 strcpy (prev_line_label, text_section_label);
6996 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6998 dw_line_info_ref line_info = &line_info_table[lt_index];
7001 /* Disable this optimization for now; GDB wants to see two line notes
7002 at the beginning of a function so it can find the end of the
7005 /* Don't emit anything for redundant notes. Just updating the
7006 address doesn't accomplish anything, because we already assume
7007 that anything after the last address is this line. */
7008 if (line_info->dw_line_num == current_line
7009 && line_info->dw_file_num == current_file)
7013 /* Emit debug info for the address of the current line.
7015 Unfortunately, we have little choice here currently, and must always
7016 use the most general form. Gcc does not know the address delta
7017 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7018 attributes which will give an upper bound on the address range. We
7019 could perhaps use length attributes to determine when it is safe to
7020 use DW_LNS_fixed_advance_pc. */
7022 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7025 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7026 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7027 "DW_LNS_fixed_advance_pc");
7028 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7032 /* This can handle any delta. This takes
7033 4+DWARF2_ADDR_SIZE bytes. */
7034 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7035 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7036 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7037 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7039 strcpy (prev_line_label, line_label);
7041 /* Emit debug info for the source file of the current line, if
7042 different from the previous line. */
7043 if (line_info->dw_file_num != current_file)
7045 current_file = line_info->dw_file_num;
7046 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7047 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7048 file_table.table[current_file]);
7051 /* Emit debug info for the current line number, choosing the encoding
7052 that uses the least amount of space. */
7053 if (line_info->dw_line_num != current_line)
7055 line_offset = line_info->dw_line_num - current_line;
7056 line_delta = line_offset - DWARF_LINE_BASE;
7057 current_line = line_info->dw_line_num;
7058 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7060 /* This can handle deltas from -10 to 234, using the current
7061 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7063 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7064 "line %lu", current_line);
7068 /* This can handle any delta. This takes at least 4 bytes,
7069 depending on the value being encoded. */
7070 dw2_asm_output_data (1, DW_LNS_advance_line,
7071 "advance to line %lu", current_line);
7072 dw2_asm_output_data_sleb128 (line_offset, NULL);
7073 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7078 /* We still need to start a new row, so output a copy insn. */
7079 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7083 /* Emit debug info for the address of the end of the function. */
7086 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7087 "DW_LNS_fixed_advance_pc");
7088 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7092 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7093 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7094 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7095 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7098 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7099 dw2_asm_output_data_uleb128 (1, NULL);
7100 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7105 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7107 dw_separate_line_info_ref line_info
7108 = &separate_line_info_table[lt_index];
7111 /* Don't emit anything for redundant notes. */
7112 if (line_info->dw_line_num == current_line
7113 && line_info->dw_file_num == current_file
7114 && line_info->function == function)
7118 /* Emit debug info for the address of the current line. If this is
7119 a new function, or the first line of a function, then we need
7120 to handle it differently. */
7121 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7123 if (function != line_info->function)
7125 function = line_info->function;
7127 /* Set the address register to the first line in the function */
7128 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7129 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7130 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7131 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7135 /* ??? See the DW_LNS_advance_pc comment above. */
7138 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7139 "DW_LNS_fixed_advance_pc");
7140 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7144 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7145 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7146 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7147 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7150 strcpy (prev_line_label, line_label);
7152 /* Emit debug info for the source file of the current line, if
7153 different from the previous line. */
7154 if (line_info->dw_file_num != current_file)
7156 current_file = line_info->dw_file_num;
7157 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7158 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7159 file_table.table[current_file]);
7162 /* Emit debug info for the current line number, choosing the encoding
7163 that uses the least amount of space. */
7164 if (line_info->dw_line_num != current_line)
7166 line_offset = line_info->dw_line_num - current_line;
7167 line_delta = line_offset - DWARF_LINE_BASE;
7168 current_line = line_info->dw_line_num;
7169 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7170 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7171 "line %lu", current_line);
7174 dw2_asm_output_data (1, DW_LNS_advance_line,
7175 "advance to line %lu", current_line);
7176 dw2_asm_output_data_sleb128 (line_offset, NULL);
7177 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7181 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7188 /* If we're done with a function, end its sequence. */
7189 if (lt_index == separate_line_info_table_in_use
7190 || separate_line_info_table[lt_index].function != function)
7195 /* Emit debug info for the address of the end of the function. */
7196 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7199 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7200 "DW_LNS_fixed_advance_pc");
7201 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7205 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7206 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7207 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7208 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7211 /* Output the marker for the end of this sequence. */
7212 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7213 dw2_asm_output_data_uleb128 (1, NULL);
7214 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7218 /* Output the marker for the end of the line number info. */
7219 ASM_OUTPUT_LABEL (asm_out_file, l2);
7222 /* Given a pointer to a tree node for some base type, return a pointer to
7223 a DIE that describes the given type.
7225 This routine must only be called for GCC type nodes that correspond to
7226 Dwarf base (fundamental) types. */
7229 base_type_die (type)
7232 dw_die_ref base_type_result;
7233 const char *type_name;
7234 enum dwarf_type encoding;
7235 tree name = TYPE_NAME (type);
7237 if (TREE_CODE (type) == ERROR_MARK
7238 || TREE_CODE (type) == VOID_TYPE)
7243 if (TREE_CODE (name) == TYPE_DECL)
7244 name = DECL_NAME (name);
7246 type_name = IDENTIFIER_POINTER (name);
7249 type_name = "__unknown__";
7251 switch (TREE_CODE (type))
7254 /* Carefully distinguish the C character types, without messing
7255 up if the language is not C. Note that we check only for the names
7256 that contain spaces; other names might occur by coincidence in other
7258 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7259 && (type == char_type_node
7260 || ! strcmp (type_name, "signed char")
7261 || ! strcmp (type_name, "unsigned char"))))
7263 if (TREE_UNSIGNED (type))
7264 encoding = DW_ATE_unsigned;
7266 encoding = DW_ATE_signed;
7269 /* else fall through. */
7272 /* GNU Pascal/Ada CHAR type. Not used in C. */
7273 if (TREE_UNSIGNED (type))
7274 encoding = DW_ATE_unsigned_char;
7276 encoding = DW_ATE_signed_char;
7280 encoding = DW_ATE_float;
7283 /* Dwarf2 doesn't know anything about complex ints, so use
7284 a user defined type for it. */
7286 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7287 encoding = DW_ATE_complex_float;
7289 encoding = DW_ATE_lo_user;
7293 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7294 encoding = DW_ATE_boolean;
7298 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7301 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7302 if (demangle_name_func)
7303 type_name = (*demangle_name_func) (type_name);
7305 add_AT_string (base_type_result, DW_AT_name, type_name);
7306 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7307 int_size_in_bytes (type));
7308 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7310 return base_type_result;
7313 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7314 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7315 a given type is generally the same as the given type, except that if the
7316 given type is a pointer or reference type, then the root type of the given
7317 type is the root type of the "basis" type for the pointer or reference
7318 type. (This definition of the "root" type is recursive.) Also, the root
7319 type of a `const' qualified type or a `volatile' qualified type is the
7320 root type of the given type without the qualifiers. */
7326 if (TREE_CODE (type) == ERROR_MARK)
7327 return error_mark_node;
7329 switch (TREE_CODE (type))
7332 return error_mark_node;
7335 case REFERENCE_TYPE:
7336 return type_main_variant (root_type (TREE_TYPE (type)));
7339 return type_main_variant (type);
7343 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7344 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7350 switch (TREE_CODE (type))
7365 case QUAL_UNION_TYPE:
7370 case REFERENCE_TYPE:
7384 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7385 entry that chains various modifiers in front of the given type. */
7388 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7391 int is_volatile_type;
7392 dw_die_ref context_die;
7394 enum tree_code code = TREE_CODE (type);
7395 dw_die_ref mod_type_die = NULL;
7396 dw_die_ref sub_die = NULL;
7397 tree item_type = NULL;
7399 if (code != ERROR_MARK)
7401 tree qualified_type;
7403 /* See if we already have the appropriately qualified variant of
7406 = get_qualified_type (type,
7407 ((is_const_type ? TYPE_QUAL_CONST : 0)
7409 ? TYPE_QUAL_VOLATILE : 0)));
7410 /* If we do, then we can just use its DIE, if it exists. */
7413 mod_type_die = lookup_type_die (qualified_type);
7415 return mod_type_die;
7418 /* Handle C typedef types. */
7419 if (qualified_type && TYPE_NAME (qualified_type)
7420 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7421 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7423 tree type_name = TYPE_NAME (qualified_type);
7424 tree dtype = TREE_TYPE (type_name);
7425 if (qualified_type == dtype)
7427 /* For a named type, use the typedef. */
7428 gen_type_die (qualified_type, context_die);
7429 mod_type_die = lookup_type_die (qualified_type);
7432 else if (is_const_type < TYPE_READONLY (dtype)
7433 || is_volatile_type < TYPE_VOLATILE (dtype))
7434 /* cv-unqualified version of named type. Just use the unnamed
7435 type to which it refers. */
7437 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7438 is_const_type, is_volatile_type,
7440 /* Else cv-qualified version of named type; fall through. */
7446 else if (is_const_type)
7448 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7449 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7451 else if (is_volatile_type)
7453 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7454 sub_die = modified_type_die (type, 0, 0, context_die);
7456 else if (code == POINTER_TYPE)
7458 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7459 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7461 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7463 item_type = TREE_TYPE (type);
7465 else if (code == REFERENCE_TYPE)
7467 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7468 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7470 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7472 item_type = TREE_TYPE (type);
7474 else if (is_base_type (type))
7475 mod_type_die = base_type_die (type);
7478 gen_type_die (type, context_die);
7480 /* We have to get the type_main_variant here (and pass that to the
7481 `lookup_type_die' routine) because the ..._TYPE node we have
7482 might simply be a *copy* of some original type node (where the
7483 copy was created to help us keep track of typedef names) and
7484 that copy might have a different TYPE_UID from the original
7486 mod_type_die = lookup_type_die (type_main_variant (type));
7487 if (mod_type_die == NULL)
7491 /* We want to equate the qualified type to the die below. */
7493 type = qualified_type;
7496 equate_type_number_to_die (type, mod_type_die);
7498 /* We must do this after the equate_type_number_to_die call, in case
7499 this is a recursive type. This ensures that the modified_type_die
7500 recursion will terminate even if the type is recursive. Recursive
7501 types are possible in Ada. */
7502 sub_die = modified_type_die (item_type,
7503 TYPE_READONLY (item_type),
7504 TYPE_VOLATILE (item_type),
7507 if (sub_die != NULL)
7508 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7510 return mod_type_die;
7513 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7514 an enumerated type. */
7520 return TREE_CODE (type) == ENUMERAL_TYPE;
7523 /* Return the register number described by a given RTL node. */
7529 unsigned regno = REGNO (rtl);
7531 if (regno >= FIRST_PSEUDO_REGISTER)
7534 return DBX_REGISTER_NUMBER (regno);
7537 /* Return a location descriptor that designates a machine register or
7538 zero if there is no such. */
7540 static dw_loc_descr_ref
7541 reg_loc_descriptor (rtl)
7544 dw_loc_descr_ref loc_result = NULL;
7547 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7550 reg = reg_number (rtl);
7552 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7554 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7559 /* Return a location descriptor that designates a constant. */
7561 static dw_loc_descr_ref
7562 int_loc_descriptor (i)
7565 enum dwarf_location_atom op;
7567 /* Pick the smallest representation of a constant, rather than just
7568 defaulting to the LEB encoding. */
7572 op = DW_OP_lit0 + i;
7575 else if (i <= 0xffff)
7577 else if (HOST_BITS_PER_WIDE_INT == 32
7587 else if (i >= -0x8000)
7589 else if (HOST_BITS_PER_WIDE_INT == 32
7590 || i >= -0x80000000)
7596 return new_loc_descr (op, i, 0);
7599 /* Return a location descriptor that designates a base+offset location. */
7601 static dw_loc_descr_ref
7602 based_loc_descr (reg, offset)
7606 dw_loc_descr_ref loc_result;
7607 /* For the "frame base", we use the frame pointer or stack pointer
7608 registers, since the RTL for local variables is relative to one of
7610 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7611 ? HARD_FRAME_POINTER_REGNUM
7612 : STACK_POINTER_REGNUM);
7615 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7617 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7619 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7624 /* Return true if this RTL expression describes a base+offset calculation. */
7630 return (GET_CODE (rtl) == PLUS
7631 && ((GET_CODE (XEXP (rtl, 0)) == REG
7632 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7633 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7636 /* The following routine converts the RTL for a variable or parameter
7637 (resident in memory) into an equivalent Dwarf representation of a
7638 mechanism for getting the address of that same variable onto the top of a
7639 hypothetical "address evaluation" stack.
7641 When creating memory location descriptors, we are effectively transforming
7642 the RTL for a memory-resident object into its Dwarf postfix expression
7643 equivalent. This routine recursively descends an RTL tree, turning
7644 it into Dwarf postfix code as it goes.
7646 MODE is the mode of the memory reference, needed to handle some
7647 autoincrement addressing modes.
7649 Return 0 if we can't represent the location. */
7651 static dw_loc_descr_ref
7652 mem_loc_descriptor (rtl, mode)
7654 enum machine_mode mode;
7656 dw_loc_descr_ref mem_loc_result = NULL;
7658 /* Note that for a dynamically sized array, the location we will generate a
7659 description of here will be the lowest numbered location which is
7660 actually within the array. That's *not* necessarily the same as the
7661 zeroth element of the array. */
7663 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7664 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7667 switch (GET_CODE (rtl))
7672 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7673 just fall into the SUBREG code. */
7678 /* The case of a subreg may arise when we have a local (register)
7679 variable or a formal (register) parameter which doesn't quite fill
7680 up an entire register. For now, just assume that it is
7681 legitimate to make the Dwarf info refer to the whole register which
7682 contains the given subreg. */
7683 rtl = SUBREG_REG (rtl);
7688 /* Whenever a register number forms a part of the description of the
7689 method for calculating the (dynamic) address of a memory resident
7690 object, DWARF rules require the register number be referred to as
7691 a "base register". This distinction is not based in any way upon
7692 what category of register the hardware believes the given register
7693 belongs to. This is strictly DWARF terminology we're dealing with
7694 here. Note that in cases where the location of a memory-resident
7695 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7696 OP_CONST (0)) the actual DWARF location descriptor that we generate
7697 may just be OP_BASEREG (basereg). This may look deceptively like
7698 the object in question was allocated to a register (rather than in
7699 memory) so DWARF consumers need to be aware of the subtle
7700 distinction between OP_REG and OP_BASEREG. */
7701 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7702 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7706 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7707 if (mem_loc_result != 0)
7708 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7712 /* Some ports can transform a symbol ref into a label ref, because
7713 the symbol ref is too far away and has to be dumped into a constant
7717 /* Alternatively, the symbol in the constant pool might be referenced
7718 by a different symbol. */
7719 if (GET_CODE (rtl) == SYMBOL_REF
7720 && CONSTANT_POOL_ADDRESS_P (rtl))
7722 rtx tmp = get_pool_constant (rtl);
7723 if (GET_CODE (tmp) == SYMBOL_REF)
7727 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7728 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7729 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7733 /* Extract the PLUS expression nested inside and fall into
7735 rtl = XEXP (rtl, 1);
7740 /* Turn these into a PLUS expression and fall into the PLUS code
7742 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7743 GEN_INT (GET_CODE (rtl) == PRE_INC
7744 ? GET_MODE_UNIT_SIZE (mode)
7745 : -GET_MODE_UNIT_SIZE (mode)));
7751 if (is_based_loc (rtl))
7752 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7753 INTVAL (XEXP (rtl, 1)));
7756 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7757 if (mem_loc_result == 0)
7760 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7761 && INTVAL (XEXP (rtl, 1)) >= 0)
7762 add_loc_descr (&mem_loc_result,
7763 new_loc_descr (DW_OP_plus_uconst,
7764 INTVAL (XEXP (rtl, 1)), 0));
7767 add_loc_descr (&mem_loc_result,
7768 mem_loc_descriptor (XEXP (rtl, 1), mode));
7769 add_loc_descr (&mem_loc_result,
7770 new_loc_descr (DW_OP_plus, 0, 0));
7777 /* If a pseudo-reg is optimized away, it is possible for it to
7778 be replaced with a MEM containing a multiply. */
7779 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7780 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7782 if (op0 == 0 || op1 == 0)
7785 mem_loc_result = op0;
7786 add_loc_descr (&mem_loc_result, op1);
7787 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7792 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7799 return mem_loc_result;
7802 /* Return a descriptor that describes the concatenation of two locations.
7803 This is typically a complex variable. */
7805 static dw_loc_descr_ref
7806 concat_loc_descriptor (x0, x1)
7809 dw_loc_descr_ref cc_loc_result = NULL;
7810 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7811 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7813 if (x0_ref == 0 || x1_ref == 0)
7816 cc_loc_result = x0_ref;
7817 add_loc_descr (&cc_loc_result,
7818 new_loc_descr (DW_OP_piece,
7819 GET_MODE_SIZE (GET_MODE (x0)), 0));
7821 add_loc_descr (&cc_loc_result, x1_ref);
7822 add_loc_descr (&cc_loc_result,
7823 new_loc_descr (DW_OP_piece,
7824 GET_MODE_SIZE (GET_MODE (x1)), 0));
7826 return cc_loc_result;
7829 /* Output a proper Dwarf location descriptor for a variable or parameter
7830 which is either allocated in a register or in a memory location. For a
7831 register, we just generate an OP_REG and the register number. For a
7832 memory location we provide a Dwarf postfix expression describing how to
7833 generate the (dynamic) address of the object onto the address stack.
7835 If we don't know how to describe it, return 0. */
7837 static dw_loc_descr_ref
7838 loc_descriptor (rtl)
7841 dw_loc_descr_ref loc_result = NULL;
7843 switch (GET_CODE (rtl))
7846 /* The case of a subreg may arise when we have a local (register)
7847 variable or a formal (register) parameter which doesn't quite fill
7848 up an entire register. For now, just assume that it is
7849 legitimate to make the Dwarf info refer to the whole register which
7850 contains the given subreg. */
7851 rtl = SUBREG_REG (rtl);
7856 loc_result = reg_loc_descriptor (rtl);
7860 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7864 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7874 /* Similar, but generate the descriptor from trees instead of rtl.
7875 This comes up particularly with variable length arrays. If ADDRESSP
7876 is nonzero, we are looking for an address. Otherwise, we return a
7877 value. If we can't find a value, return 0. */
7879 static dw_loc_descr_ref
7880 loc_descriptor_from_tree (loc, addressp)
7884 dw_loc_descr_ref ret, ret1;
7886 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7887 enum dwarf_location_atom op;
7889 /* ??? Most of the time we do not take proper care for sign/zero
7890 extending the values properly. Hopefully this won't be a real
7893 switch (TREE_CODE (loc))
7898 case WITH_RECORD_EXPR:
7899 case PLACEHOLDER_EXPR:
7900 /* This case involves extracting fields from an object to determine the
7901 position of other fields. We don't try to encode this here. The
7902 only user of this is Ada, which encodes the needed information using
7903 the names of types. */
7909 rtx rtl = rtl_for_decl_location (loc);
7910 enum machine_mode mode = GET_MODE (rtl);
7912 if (rtl == NULL_RTX)
7914 else if (CONSTANT_P (rtl))
7916 ret = new_loc_descr (DW_OP_addr, 0, 0);
7917 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7918 ret->dw_loc_oprnd1.v.val_addr = rtl;
7923 if (GET_CODE (rtl) == MEM)
7926 rtl = XEXP (rtl, 0);
7928 ret = mem_loc_descriptor (rtl, mode);
7934 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7939 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
7943 case NON_LVALUE_EXPR:
7944 case VIEW_CONVERT_EXPR:
7946 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7951 case ARRAY_RANGE_REF:
7954 HOST_WIDE_INT bitsize, bitpos, bytepos;
7955 enum machine_mode mode;
7958 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7959 &unsignedp, &volatilep);
7964 ret = loc_descriptor_from_tree (obj, 1);
7966 || bitpos % BITS_PER_UNIT != 0
7967 || bitsize % BITS_PER_UNIT != 0)
7970 if (offset != NULL_TREE)
7972 /* Variable offset. */
7973 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7974 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7980 bytepos = bitpos / BITS_PER_UNIT;
7982 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7983 else if (bytepos < 0)
7985 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7986 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7992 if (host_integerp (loc, 0))
7993 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8010 case TRUNC_DIV_EXPR:
8018 case TRUNC_MOD_EXPR:
8031 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8035 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8036 && host_integerp (TREE_OPERAND (loc, 1), 0))
8038 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8042 add_loc_descr (&ret,
8043 new_loc_descr (DW_OP_plus_uconst,
8044 tree_low_cst (TREE_OPERAND (loc, 1),
8053 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8060 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8067 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8074 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8089 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8090 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8091 if (ret == 0 || ret1 == 0)
8094 add_loc_descr (&ret, ret1);
8095 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8111 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8115 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8119 loc = build (COND_EXPR, TREE_TYPE (loc),
8120 build (LT_EXPR, integer_type_node,
8121 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8122 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8127 dw_loc_descr_ref lhs
8128 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8129 dw_loc_descr_ref rhs
8130 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8131 dw_loc_descr_ref bra_node, jump_node, tmp;
8133 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8134 if (ret == 0 || lhs == 0 || rhs == 0)
8137 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8138 add_loc_descr (&ret, bra_node);
8140 add_loc_descr (&ret, rhs);
8141 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8142 add_loc_descr (&ret, jump_node);
8144 add_loc_descr (&ret, lhs);
8145 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8146 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8148 /* ??? Need a node to point the skip at. Use a nop. */
8149 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8150 add_loc_descr (&ret, tmp);
8151 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8152 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8160 /* Show if we can't fill the request for an address. */
8161 if (addressp && indirect_p == 0)
8164 /* If we've got an address and don't want one, dereference. */
8165 if (!addressp && indirect_p > 0)
8167 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8169 if (size > DWARF2_ADDR_SIZE || size == -1)
8171 if (size == DWARF2_ADDR_SIZE)
8174 op = DW_OP_deref_size;
8176 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8182 /* Given a value, round it up to the lowest multiple of `boundary'
8183 which is not less than the value itself. */
8185 static inline HOST_WIDE_INT
8186 ceiling (value, boundary)
8187 HOST_WIDE_INT value;
8188 unsigned int boundary;
8190 return (((value + boundary - 1) / boundary) * boundary);
8193 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8194 pointer to the declared type for the relevant field variable, or return
8195 `integer_type_node' if the given node turns out to be an
8204 if (TREE_CODE (decl) == ERROR_MARK)
8205 return integer_type_node;
8207 type = DECL_BIT_FIELD_TYPE (decl);
8208 if (type == NULL_TREE)
8209 type = TREE_TYPE (decl);
8214 /* Given a pointer to a tree node, return the alignment in bits for
8215 it, or else return BITS_PER_WORD if the node actually turns out to
8216 be an ERROR_MARK node. */
8218 static inline unsigned
8219 simple_type_align_in_bits (type)
8222 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8225 static inline unsigned
8226 simple_decl_align_in_bits (decl)
8229 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8232 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8233 node, return the size in bits for the type if it is a constant, or else
8234 return the alignment for the type if the type's size is not constant, or
8235 else return BITS_PER_WORD if the type actually turns out to be an
8238 static inline unsigned HOST_WIDE_INT
8239 simple_type_size_in_bits (type)
8242 tree type_size_tree;
8244 if (TREE_CODE (type) == ERROR_MARK)
8245 return BITS_PER_WORD;
8246 type_size_tree = TYPE_SIZE (type);
8248 if (type_size_tree == NULL_TREE)
8250 if (! host_integerp (type_size_tree, 1))
8251 return TYPE_ALIGN (type);
8252 return tree_low_cst (type_size_tree, 1);
8255 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8256 return the byte offset of the lowest addressed byte of the "containing
8257 object" for the given FIELD_DECL, or return 0 if we are unable to
8258 determine what that offset is, either because the argument turns out to
8259 be a pointer to an ERROR_MARK node, or because the offset is actually
8260 variable. (We can't handle the latter case just yet). */
8262 static HOST_WIDE_INT
8263 field_byte_offset (decl)
8266 unsigned int type_align_in_bits;
8267 unsigned int decl_align_in_bits;
8268 unsigned HOST_WIDE_INT type_size_in_bits;
8269 HOST_WIDE_INT object_offset_in_bits;
8270 HOST_WIDE_INT object_offset_in_bytes;
8272 tree field_size_tree;
8273 HOST_WIDE_INT bitpos_int;
8274 HOST_WIDE_INT deepest_bitpos;
8275 unsigned HOST_WIDE_INT field_size_in_bits;
8277 if (TREE_CODE (decl) == ERROR_MARK)
8280 if (TREE_CODE (decl) != FIELD_DECL)
8283 type = field_type (decl);
8284 field_size_tree = DECL_SIZE (decl);
8286 /* The size could be unspecified if there was an error, or for
8287 a flexible array member. */
8288 if (! field_size_tree)
8289 field_size_tree = bitsize_zero_node;
8291 /* We cannot yet cope with fields whose positions are variable, so
8292 for now, when we see such things, we simply return 0. Someday, we may
8293 be able to handle such cases, but it will be damn difficult. */
8294 if (! host_integerp (bit_position (decl), 0))
8297 bitpos_int = int_bit_position (decl);
8299 /* If we don't know the size of the field, pretend it's a full word. */
8300 if (host_integerp (field_size_tree, 1))
8301 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8303 field_size_in_bits = BITS_PER_WORD;
8305 type_size_in_bits = simple_type_size_in_bits (type);
8306 type_align_in_bits = simple_type_align_in_bits (type);
8307 decl_align_in_bits = simple_decl_align_in_bits (decl);
8309 /* Note that the GCC front-end doesn't make any attempt to keep track of
8310 the starting bit offset (relative to the start of the containing
8311 structure type) of the hypothetical "containing object" for a bit-
8312 field. Thus, when computing the byte offset value for the start of the
8313 "containing object" of a bit-field, we must deduce this information on
8314 our own. This can be rather tricky to do in some cases. For example,
8315 handling the following structure type definition when compiling for an
8316 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8319 struct S { int field1; long long field2:31; };
8321 Fortunately, there is a simple rule-of-thumb which can be
8322 used in such cases. When compiling for an i386/i486, GCC will allocate
8323 8 bytes for the structure shown above. It decides to do this based upon
8324 one simple rule for bit-field allocation. Quite simply, GCC allocates
8325 each "containing object" for each bit-field at the first (i.e. lowest
8326 addressed) legitimate alignment boundary (based upon the required
8327 minimum alignment for the declared type of the field) which it can
8328 possibly use, subject to the condition that there is still enough
8329 available space remaining in the containing object (when allocated at
8330 the selected point) to fully accommodate all of the bits of the
8331 bit-field itself. This simple rule makes it obvious why GCC allocates
8332 8 bytes for each object of the structure type shown above. When looking
8333 for a place to allocate the "containing object" for `field2', the
8334 compiler simply tries to allocate a 64-bit "containing object" at each
8335 successive 32-bit boundary (starting at zero) until it finds a place to
8336 allocate that 64- bit field such that at least 31 contiguous (and
8337 previously unallocated) bits remain within that selected 64 bit field.
8338 (As it turns out, for the example above, the compiler finds that it is
8339 OK to allocate the "containing object" 64-bit field at bit-offset zero
8340 within the structure type.) Here we attempt to work backwards from the
8341 limited set of facts we're given, and we try to deduce from those facts,
8342 where GCC must have believed that the containing object started (within
8343 the structure type). The value we deduce is then used (by the callers of
8344 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8345 for fields (both bit-fields and, in the case of DW_AT_location, regular
8348 /* Figure out the bit-distance from the start of the structure to the
8349 "deepest" bit of the bit-field. */
8350 deepest_bitpos = bitpos_int + field_size_in_bits;
8352 /* This is the tricky part. Use some fancy footwork to deduce where the
8353 lowest addressed bit of the containing object must be. */
8354 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8356 /* Round up to type_align by default. This works best for bitfields. */
8357 object_offset_in_bits += type_align_in_bits - 1;
8358 object_offset_in_bits /= type_align_in_bits;
8359 object_offset_in_bits *= type_align_in_bits;
8361 if (object_offset_in_bits > bitpos_int)
8363 /* Sigh, the decl must be packed. */
8364 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8366 /* Round up to decl_align instead. */
8367 object_offset_in_bits += decl_align_in_bits - 1;
8368 object_offset_in_bits /= decl_align_in_bits;
8369 object_offset_in_bits *= decl_align_in_bits;
8372 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8374 return object_offset_in_bytes;
8377 /* The following routines define various Dwarf attributes and any data
8378 associated with them. */
8380 /* Add a location description attribute value to a DIE.
8382 This emits location attributes suitable for whole variables and
8383 whole parameters. Note that the location attributes for struct fields are
8384 generated by the routine `data_member_location_attribute' below. */
8387 add_AT_location_description (die, attr_kind, rtl)
8389 enum dwarf_attribute attr_kind;
8392 dw_loc_descr_ref descr = loc_descriptor (rtl);
8395 add_AT_loc (die, attr_kind, descr);
8398 /* Attach the specialized form of location attribute used for data
8399 members of struct and union types. In the special case of a
8400 FIELD_DECL node which represents a bit-field, the "offset" part
8401 of this special location descriptor must indicate the distance
8402 in bytes from the lowest-addressed byte of the containing struct
8403 or union type to the lowest-addressed byte of the "containing
8404 object" for the bit-field. (See the `field_byte_offset' function
8405 above).. For any given bit-field, the "containing object" is a
8406 hypothetical object (of some integral or enum type) within which
8407 the given bit-field lives. The type of this hypothetical
8408 "containing object" is always the same as the declared type of
8409 the individual bit-field itself (for GCC anyway... the DWARF
8410 spec doesn't actually mandate this). Note that it is the size
8411 (in bytes) of the hypothetical "containing object" which will
8412 be given in the DW_AT_byte_size attribute for this bit-field.
8413 (See the `byte_size_attribute' function below.) It is also used
8414 when calculating the value of the DW_AT_bit_offset attribute.
8415 (See the `bit_offset_attribute' function below). */
8418 add_data_member_location_attribute (die, decl)
8423 dw_loc_descr_ref loc_descr = 0;
8425 if (TREE_CODE (decl) == TREE_VEC)
8427 /* We're working on the TAG_inheritance for a base class. */
8429 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8431 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8432 aren't at a fixed offset from all (sub)objects of the same
8433 type. We need to extract the appropriate offset from our
8434 vtable. The following dwarf expression means
8436 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8438 This is specific to the V3 ABI, of course. */
8440 dw_loc_descr_ref tmp;
8441 /* Make a copy of the object address. */
8442 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8443 add_loc_descr (&loc_descr, tmp);
8444 /* Extract the vtable address. */
8445 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8446 add_loc_descr (&loc_descr, tmp);
8447 /* Calculate the address of the offset. */
8448 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8451 tmp = int_loc_descriptor (-offset);
8452 add_loc_descr (&loc_descr, tmp);
8453 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8454 add_loc_descr (&loc_descr, tmp);
8455 /* Extract the offset. */
8456 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8457 add_loc_descr (&loc_descr, tmp);
8458 /* Add it to the object address. */
8459 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8460 add_loc_descr (&loc_descr, tmp);
8463 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8466 offset = field_byte_offset (decl);
8470 enum dwarf_location_atom op;
8472 /* The DWARF2 standard says that we should assume that the structure address
8473 is already on the stack, so we can specify a structure field address
8474 by using DW_OP_plus_uconst. */
8476 #ifdef MIPS_DEBUGGING_INFO
8477 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8478 correctly. It works only if we leave the offset on the stack. */
8481 op = DW_OP_plus_uconst;
8484 loc_descr = new_loc_descr (op, offset, 0);
8486 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8489 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8490 does not have a "location" either in memory or in a register. These
8491 things can arise in GNU C when a constant is passed as an actual parameter
8492 to an inlined function. They can also arise in C++ where declared
8493 constants do not necessarily get memory "homes". */
8496 add_const_value_attribute (die, rtl)
8500 switch (GET_CODE (rtl))
8503 /* Note that a CONST_INT rtx could represent either an integer
8504 or a floating-point constant. A CONST_INT is used whenever
8505 the constant will fit into a single word. In all such
8506 cases, the original mode of the constant value is wiped
8507 out, and the CONST_INT rtx is assigned VOIDmode. */
8509 HOST_WIDE_INT val = INTVAL (rtl);
8511 /* ??? We really should be using HOST_WIDE_INT throughout. */
8512 if (val < 0 && (long) val == val)
8513 add_AT_int (die, DW_AT_const_value, (long) val);
8514 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8515 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8518 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8519 add_AT_long_long (die, DW_AT_const_value,
8520 val >> HOST_BITS_PER_LONG, val);
8529 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8530 floating-point constant. A CONST_DOUBLE is used whenever the
8531 constant requires more than one word in order to be adequately
8532 represented. We output CONST_DOUBLEs as blocks. */
8534 enum machine_mode mode = GET_MODE (rtl);
8536 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8538 unsigned length = GET_MODE_SIZE (mode) / 4;
8539 long *array = (long *) xmalloc (sizeof (long) * length);
8542 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8546 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8550 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8555 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8562 add_AT_float (die, DW_AT_const_value, length, array);
8566 /* ??? We really should be using HOST_WIDE_INT throughout. */
8567 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8569 add_AT_long_long (die, DW_AT_const_value,
8570 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8576 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8582 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8586 /* In cases where an inlined instance of an inline function is passed
8587 the address of an `auto' variable (which is local to the caller) we
8588 can get a situation where the DECL_RTL of the artificial local
8589 variable (for the inlining) which acts as a stand-in for the
8590 corresponding formal parameter (of the inline function) will look
8591 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8592 exactly a compile-time constant expression, but it isn't the address
8593 of the (artificial) local variable either. Rather, it represents the
8594 *value* which the artificial local variable always has during its
8595 lifetime. We currently have no way to represent such quasi-constant
8596 values in Dwarf, so for now we just punt and generate nothing. */
8600 /* No other kinds of rtx should be possible here. */
8607 rtl_for_decl_location (decl)
8612 /* Here we have to decide where we are going to say the parameter "lives"
8613 (as far as the debugger is concerned). We only have a couple of
8614 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8616 DECL_RTL normally indicates where the parameter lives during most of the
8617 activation of the function. If optimization is enabled however, this
8618 could be either NULL or else a pseudo-reg. Both of those cases indicate
8619 that the parameter doesn't really live anywhere (as far as the code
8620 generation parts of GCC are concerned) during most of the function's
8621 activation. That will happen (for example) if the parameter is never
8622 referenced within the function.
8624 We could just generate a location descriptor here for all non-NULL
8625 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8626 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8627 where DECL_RTL is NULL or is a pseudo-reg.
8629 Note however that we can only get away with using DECL_INCOMING_RTL as
8630 a backup substitute for DECL_RTL in certain limited cases. In cases
8631 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8632 we can be sure that the parameter was passed using the same type as it is
8633 declared to have within the function, and that its DECL_INCOMING_RTL
8634 points us to a place where a value of that type is passed.
8636 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8637 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8638 because in these cases DECL_INCOMING_RTL points us to a value of some
8639 type which is *different* from the type of the parameter itself. Thus,
8640 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8641 such cases, the debugger would end up (for example) trying to fetch a
8642 `float' from a place which actually contains the first part of a
8643 `double'. That would lead to really incorrect and confusing
8644 output at debug-time.
8646 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8647 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8648 are a couple of exceptions however. On little-endian machines we can
8649 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8650 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8651 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8652 when (on a little-endian machine) a non-prototyped function has a
8653 parameter declared to be of type `short' or `char'. In such cases,
8654 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8655 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8656 passed `int' value. If the debugger then uses that address to fetch
8657 a `short' or a `char' (on a little-endian machine) the result will be
8658 the correct data, so we allow for such exceptional cases below.
8660 Note that our goal here is to describe the place where the given formal
8661 parameter lives during most of the function's activation (i.e. between
8662 the end of the prologue and the start of the epilogue). We'll do that
8663 as best as we can. Note however that if the given formal parameter is
8664 modified sometime during the execution of the function, then a stack
8665 backtrace (at debug-time) will show the function as having been
8666 called with the *new* value rather than the value which was
8667 originally passed in. This happens rarely enough that it is not
8668 a major problem, but it *is* a problem, and I'd like to fix it.
8670 A future version of dwarf2out.c may generate two additional
8671 attributes for any given DW_TAG_formal_parameter DIE which will
8672 describe the "passed type" and the "passed location" for the
8673 given formal parameter in addition to the attributes we now
8674 generate to indicate the "declared type" and the "active
8675 location" for each parameter. This additional set of attributes
8676 could be used by debuggers for stack backtraces. Separately, note
8677 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8678 NULL also. This happens (for example) for inlined-instances of
8679 inline function formal parameters which are never referenced.
8680 This really shouldn't be happening. All PARM_DECL nodes should
8681 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8682 doesn't currently generate these values for inlined instances of
8683 inline function parameters, so when we see such cases, we are
8684 just out-of-luck for the time being (until integrate.c
8687 /* Use DECL_RTL as the "location" unless we find something better. */
8688 rtl = DECL_RTL_IF_SET (decl);
8690 if (TREE_CODE (decl) == PARM_DECL)
8692 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8694 tree declared_type = type_main_variant (TREE_TYPE (decl));
8695 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8697 /* This decl represents a formal parameter which was optimized out.
8698 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8699 all* cases where (rtl == NULL_RTX) just below. */
8700 if (declared_type == passed_type)
8701 rtl = DECL_INCOMING_RTL (decl);
8702 else if (! BYTES_BIG_ENDIAN
8703 && TREE_CODE (declared_type) == INTEGER_TYPE
8704 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8705 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8706 rtl = DECL_INCOMING_RTL (decl);
8709 /* If the parm was passed in registers, but lives on the stack, then
8710 make a big endian correction if the mode of the type of the
8711 parameter is not the same as the mode of the rtl. */
8712 /* ??? This is the same series of checks that are made in dbxout.c before
8713 we reach the big endian correction code there. It isn't clear if all
8714 of these checks are necessary here, but keeping them all is the safe
8716 else if (GET_CODE (rtl) == MEM
8717 && XEXP (rtl, 0) != const0_rtx
8718 && ! CONSTANT_P (XEXP (rtl, 0))
8719 /* Not passed in memory. */
8720 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8721 /* Not passed by invisible reference. */
8722 && (GET_CODE (XEXP (rtl, 0)) != REG
8723 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8724 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8725 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8726 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8729 /* Big endian correction check. */
8731 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8732 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8735 int offset = (UNITS_PER_WORD
8736 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8737 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8738 plus_constant (XEXP (rtl, 0), offset));
8742 if (rtl != NULL_RTX)
8744 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8745 #ifdef LEAF_REG_REMAP
8746 if (current_function_uses_only_leaf_regs)
8747 leaf_renumber_regs_insn (rtl);
8751 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time
8752 constant, and will have been substituted directly into all
8753 expressions that use it. C does not have such a concept, but
8754 C++ and other languages do. */
8755 else if (DECL_INITIAL (decl))
8757 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8758 EXPAND_INITIALIZER);
8764 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8765 data attribute for a variable or a parameter. We generate the
8766 DW_AT_const_value attribute only in those cases where the given variable
8767 or parameter does not have a true "location" either in memory or in a
8768 register. This can happen (for example) when a constant is passed as an
8769 actual argument in a call to an inline function. (It's possible that
8770 these things can crop up in other ways also.) Note that one type of
8771 constant value which can be passed into an inlined function is a constant
8772 pointer. This can happen for example if an actual argument in an inlined
8773 function call evaluates to a compile-time constant address. */
8776 add_location_or_const_value_attribute (die, decl)
8782 if (TREE_CODE (decl) == ERROR_MARK)
8785 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8788 rtl = rtl_for_decl_location (decl);
8789 if (rtl == NULL_RTX)
8792 /* If we don't look past the constant pool, we risk emitting a
8793 reference to a constant pool entry that isn't referenced from
8794 code, and thus is not emitted. */
8795 rtl = avoid_constant_pool_reference (rtl);
8797 switch (GET_CODE (rtl))
8800 /* The address of a variable that was optimized away; don't emit
8811 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8812 add_const_value_attribute (die, rtl);
8819 add_AT_location_description (die, DW_AT_location, rtl);
8827 /* If we don't have a copy of this variable in memory for some reason (such
8828 as a C++ member constant that doesn't have an out-of-line definition),
8829 we should tell the debugger about the constant value. */
8832 tree_add_const_value_attribute (var_die, decl)
8836 tree init = DECL_INITIAL (decl);
8837 tree type = TREE_TYPE (decl);
8839 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8840 && initializer_constant_valid_p (init, type) == null_pointer_node)
8845 switch (TREE_CODE (type))
8848 if (host_integerp (init, 0))
8849 add_AT_unsigned (var_die, DW_AT_const_value,
8850 TREE_INT_CST_LOW (init));
8852 add_AT_long_long (var_die, DW_AT_const_value,
8853 TREE_INT_CST_HIGH (init),
8854 TREE_INT_CST_LOW (init));
8861 /* Generate an DW_AT_name attribute given some string value to be included as
8862 the value of the attribute. */
8865 add_name_attribute (die, name_string)
8867 const char *name_string;
8869 if (name_string != NULL && *name_string != 0)
8871 if (demangle_name_func)
8872 name_string = (*demangle_name_func) (name_string);
8874 add_AT_string (die, DW_AT_name, name_string);
8878 /* Given a tree node describing an array bound (either lower or upper) output
8879 a representation for that bound. */
8882 add_bound_info (subrange_die, bound_attr, bound)
8883 dw_die_ref subrange_die;
8884 enum dwarf_attribute bound_attr;
8887 switch (TREE_CODE (bound))
8892 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8894 if (! host_integerp (bound, 0)
8895 || (bound_attr == DW_AT_lower_bound
8896 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8897 || (is_fortran () && integer_onep (bound)))))
8898 /* use the default */
8901 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8906 case NON_LVALUE_EXPR:
8907 case VIEW_CONVERT_EXPR:
8908 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8912 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8913 access the upper bound values may be bogus. If they refer to a
8914 register, they may only describe how to get at these values at the
8915 points in the generated code right after they have just been
8916 computed. Worse yet, in the typical case, the upper bound values
8917 will not even *be* computed in the optimized code (though the
8918 number of elements will), so these SAVE_EXPRs are entirely
8919 bogus. In order to compensate for this fact, we check here to see
8920 if optimization is enabled, and if so, we don't add an attribute
8921 for the (unknown and unknowable) upper bound. This should not
8922 cause too much trouble for existing (stupid?) debuggers because
8923 they have to deal with empty upper bounds location descriptions
8924 anyway in order to be able to deal with incomplete array types.
8925 Of course an intelligent debugger (GDB?) should be able to
8926 comprehend that a missing upper bound specification in an array
8927 type used for a storage class `auto' local array variable
8928 indicates that the upper bound is both unknown (at compile- time)
8929 and unknowable (at run-time) due to optimization.
8931 We assume that a MEM rtx is safe because gcc wouldn't put the
8932 value there unless it was going to be used repeatedly in the
8933 function, i.e. for cleanups. */
8934 if (SAVE_EXPR_RTL (bound)
8935 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8937 dw_die_ref ctx = lookup_decl_die (current_function_decl);
8938 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8939 rtx loc = SAVE_EXPR_RTL (bound);
8941 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8942 it references an outer function's frame. */
8944 if (GET_CODE (loc) == MEM)
8946 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8948 if (XEXP (loc, 0) != new_addr)
8949 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8952 add_AT_flag (decl_die, DW_AT_artificial, 1);
8953 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8954 add_AT_location_description (decl_die, DW_AT_location, loc);
8955 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8958 /* Else leave out the attribute. */
8964 dw_die_ref decl_die = lookup_decl_die (bound);
8966 /* ??? Can this happen, or should the variable have been bound
8967 first? Probably it can, since I imagine that we try to create
8968 the types of parameters in the order in which they exist in
8969 the list, and won't have created a forward reference to a
8971 if (decl_die != NULL)
8972 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8978 /* Otherwise try to create a stack operation procedure to
8979 evaluate the value of the array bound. */
8981 dw_die_ref ctx, decl_die;
8982 dw_loc_descr_ref loc;
8984 loc = loc_descriptor_from_tree (bound, 0);
8988 if (current_function_decl == 0)
8989 ctx = comp_unit_die;
8991 ctx = lookup_decl_die (current_function_decl);
8993 decl_die = new_die (DW_TAG_variable, ctx);
8994 add_AT_flag (decl_die, DW_AT_artificial, 1);
8995 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8996 add_AT_loc (decl_die, DW_AT_location, loc);
8998 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9004 /* Note that the block of subscript information for an array type also
9005 includes information about the element type of type given array type. */
9008 add_subscript_info (type_die, type)
9009 dw_die_ref type_die;
9012 #ifndef MIPS_DEBUGGING_INFO
9013 unsigned dimension_number;
9016 dw_die_ref subrange_die;
9018 /* The GNU compilers represent multidimensional array types as sequences of
9019 one dimensional array types whose element types are themselves array
9020 types. Here we squish that down, so that each multidimensional array
9021 type gets only one array_type DIE in the Dwarf debugging info. The draft
9022 Dwarf specification say that we are allowed to do this kind of
9023 compression in C (because there is no difference between an array or
9024 arrays and a multidimensional array in C) but for other source languages
9025 (e.g. Ada) we probably shouldn't do this. */
9027 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9028 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9029 We work around this by disabling this feature. See also
9030 gen_array_type_die. */
9031 #ifndef MIPS_DEBUGGING_INFO
9032 for (dimension_number = 0;
9033 TREE_CODE (type) == ARRAY_TYPE;
9034 type = TREE_TYPE (type), dimension_number++)
9037 tree domain = TYPE_DOMAIN (type);
9039 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9040 and (in GNU C only) variable bounds. Handle all three forms
9042 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9045 /* We have an array type with specified bounds. */
9046 lower = TYPE_MIN_VALUE (domain);
9047 upper = TYPE_MAX_VALUE (domain);
9049 /* define the index type. */
9050 if (TREE_TYPE (domain))
9052 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9053 TREE_TYPE field. We can't emit debug info for this
9054 because it is an unnamed integral type. */
9055 if (TREE_CODE (domain) == INTEGER_TYPE
9056 && TYPE_NAME (domain) == NULL_TREE
9057 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9058 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9061 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9065 /* ??? If upper is NULL, the array has unspecified length,
9066 but it does have a lower bound. This happens with Fortran
9068 Since the debugger is definitely going to need to know N
9069 to produce useful results, go ahead and output the lower
9070 bound solo, and hope the debugger can cope. */
9072 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9074 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9077 /* We have an array type with an unspecified length. The DWARF-2
9078 spec does not say how to handle this; let's just leave out the
9082 #ifndef MIPS_DEBUGGING_INFO
9088 add_byte_size_attribute (die, tree_node)
9094 switch (TREE_CODE (tree_node))
9102 case QUAL_UNION_TYPE:
9103 size = int_size_in_bytes (tree_node);
9106 /* For a data member of a struct or union, the DW_AT_byte_size is
9107 generally given as the number of bytes normally allocated for an
9108 object of the *declared* type of the member itself. This is true
9109 even for bit-fields. */
9110 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9116 /* Note that `size' might be -1 when we get to this point. If it is, that
9117 indicates that the byte size of the entity in question is variable. We
9118 have no good way of expressing this fact in Dwarf at the present time,
9119 so just let the -1 pass on through. */
9121 add_AT_unsigned (die, DW_AT_byte_size, size);
9124 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9125 which specifies the distance in bits from the highest order bit of the
9126 "containing object" for the bit-field to the highest order bit of the
9129 For any given bit-field, the "containing object" is a hypothetical
9130 object (of some integral or enum type) within which the given bit-field
9131 lives. The type of this hypothetical "containing object" is always the
9132 same as the declared type of the individual bit-field itself. The
9133 determination of the exact location of the "containing object" for a
9134 bit-field is rather complicated. It's handled by the
9135 `field_byte_offset' function (above).
9137 Note that it is the size (in bytes) of the hypothetical "containing object"
9138 which will be given in the DW_AT_byte_size attribute for this bit-field.
9139 (See `byte_size_attribute' above). */
9142 add_bit_offset_attribute (die, decl)
9146 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9147 tree type = DECL_BIT_FIELD_TYPE (decl);
9148 HOST_WIDE_INT bitpos_int;
9149 HOST_WIDE_INT highest_order_object_bit_offset;
9150 HOST_WIDE_INT highest_order_field_bit_offset;
9151 HOST_WIDE_INT unsigned bit_offset;
9153 /* Must be a field and a bit field. */
9155 || TREE_CODE (decl) != FIELD_DECL)
9158 /* We can't yet handle bit-fields whose offsets are variable, so if we
9159 encounter such things, just return without generating any attribute
9160 whatsoever. Likewise for variable or too large size. */
9161 if (! host_integerp (bit_position (decl), 0)
9162 || ! host_integerp (DECL_SIZE (decl), 1))
9165 bitpos_int = int_bit_position (decl);
9167 /* Note that the bit offset is always the distance (in bits) from the
9168 highest-order bit of the "containing object" to the highest-order bit of
9169 the bit-field itself. Since the "high-order end" of any object or field
9170 is different on big-endian and little-endian machines, the computation
9171 below must take account of these differences. */
9172 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9173 highest_order_field_bit_offset = bitpos_int;
9175 if (! BYTES_BIG_ENDIAN)
9177 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9178 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9182 = (! BYTES_BIG_ENDIAN
9183 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9184 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9186 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9189 /* For a FIELD_DECL node which represents a bit field, output an attribute
9190 which specifies the length in bits of the given field. */
9193 add_bit_size_attribute (die, decl)
9197 /* Must be a field and a bit field. */
9198 if (TREE_CODE (decl) != FIELD_DECL
9199 || ! DECL_BIT_FIELD_TYPE (decl))
9202 if (host_integerp (DECL_SIZE (decl), 1))
9203 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9206 /* If the compiled language is ANSI C, then add a 'prototyped'
9207 attribute, if arg types are given for the parameters of a function. */
9210 add_prototyped_attribute (die, func_type)
9214 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9215 && TYPE_ARG_TYPES (func_type) != NULL)
9216 add_AT_flag (die, DW_AT_prototyped, 1);
9219 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9220 by looking in either the type declaration or object declaration
9224 add_abstract_origin_attribute (die, origin)
9228 dw_die_ref origin_die = NULL;
9230 if (TREE_CODE (origin) != FUNCTION_DECL)
9232 /* We may have gotten separated from the block for the inlined
9233 function, if we're in an exception handler or some such; make
9234 sure that the abstract function has been written out.
9236 Doing this for nested functions is wrong, however; functions are
9237 distinct units, and our context might not even be inline. */
9240 fn = TYPE_STUB_DECL (fn);
9241 fn = decl_function_context (fn);
9243 dwarf2out_abstract_function (fn);
9246 if (DECL_P (origin))
9247 origin_die = lookup_decl_die (origin);
9248 else if (TYPE_P (origin))
9249 origin_die = lookup_type_die (origin);
9251 if (origin_die == NULL)
9254 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9257 /* We do not currently support the pure_virtual attribute. */
9260 add_pure_or_virtual_attribute (die, func_decl)
9264 if (DECL_VINDEX (func_decl))
9266 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9268 if (host_integerp (DECL_VINDEX (func_decl), 0))
9269 add_AT_loc (die, DW_AT_vtable_elem_location,
9270 new_loc_descr (DW_OP_constu,
9271 tree_low_cst (DECL_VINDEX (func_decl), 0),
9274 /* GNU extension: Record what type this method came from originally. */
9275 if (debug_info_level > DINFO_LEVEL_TERSE)
9276 add_AT_die_ref (die, DW_AT_containing_type,
9277 lookup_type_die (DECL_CONTEXT (func_decl)));
9281 /* Add source coordinate attributes for the given decl. */
9284 add_src_coords_attributes (die, decl)
9288 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9290 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9291 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9294 /* Add an DW_AT_name attribute and source coordinate attribute for the
9295 given decl, but only if it actually has a name. */
9298 add_name_and_src_coords_attributes (die, decl)
9304 decl_name = DECL_NAME (decl);
9305 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9307 add_name_attribute (die, dwarf2_name (decl, 0));
9308 if (! DECL_ARTIFICIAL (decl))
9309 add_src_coords_attributes (die, decl);
9311 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9312 && TREE_PUBLIC (decl)
9313 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9314 && !DECL_ABSTRACT (decl))
9315 add_AT_string (die, DW_AT_MIPS_linkage_name,
9316 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9319 #ifdef VMS_DEBUGGING_INFO
9321 /* Get the function's name, as described by its RTL. This may be different
9322 from the DECL_NAME name used in the source file. */
9323 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9324 add_AT_string (die, DW_AT_VMS_rtnbeg_pd_address,
9325 xstrdup (XSTR (XEXP (DECL_RTL (decl), 0), 0)));
9329 /* Push a new declaration scope. */
9332 push_decl_scope (scope)
9335 VARRAY_PUSH_TREE (decl_scope_table, scope);
9338 /* Pop a declaration scope. */
9342 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9344 VARRAY_POP (decl_scope_table);
9347 /* Return the DIE for the scope that immediately contains this type.
9348 Non-named types get global scope. Named types nested in other
9349 types get their containing scope if it's open, or global scope
9350 otherwise. All other types (i.e. function-local named types) get
9351 the current active scope. */
9354 scope_die_for (t, context_die)
9356 dw_die_ref context_die;
9358 dw_die_ref scope_die = NULL;
9359 tree containing_scope;
9362 /* Non-types always go in the current scope. */
9366 containing_scope = TYPE_CONTEXT (t);
9368 /* Ignore namespaces for the moment. */
9369 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9370 containing_scope = NULL_TREE;
9372 /* Ignore function type "scopes" from the C frontend. They mean that
9373 a tagged type is local to a parmlist of a function declarator, but
9374 that isn't useful to DWARF. */
9375 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9376 containing_scope = NULL_TREE;
9378 if (containing_scope == NULL_TREE)
9379 scope_die = comp_unit_die;
9380 else if (TYPE_P (containing_scope))
9382 /* For types, we can just look up the appropriate DIE. But
9383 first we check to see if we're in the middle of emitting it
9384 so we know where the new DIE should go. */
9386 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9387 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9392 if (debug_info_level > DINFO_LEVEL_TERSE
9393 && !TREE_ASM_WRITTEN (containing_scope))
9396 /* If none of the current dies are suitable, we get file scope. */
9397 scope_die = comp_unit_die;
9400 scope_die = lookup_type_die (containing_scope);
9403 scope_die = context_die;
9408 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9410 static inline int local_scope_p PARAMS ((dw_die_ref));
9412 local_scope_p (context_die)
9413 dw_die_ref context_die;
9415 for (; context_die; context_die = context_die->die_parent)
9416 if (context_die->die_tag == DW_TAG_inlined_subroutine
9417 || context_die->die_tag == DW_TAG_subprogram)
9422 /* Returns nonzero iff CONTEXT_DIE is a class. */
9424 static inline int class_scope_p PARAMS ((dw_die_ref));
9426 class_scope_p (context_die)
9427 dw_die_ref context_die;
9430 && (context_die->die_tag == DW_TAG_structure_type
9431 || context_die->die_tag == DW_TAG_union_type));
9434 /* Many forms of DIEs require a "type description" attribute. This
9435 routine locates the proper "type descriptor" die for the type given
9436 by 'type', and adds an DW_AT_type attribute below the given die. */
9439 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9440 dw_die_ref object_die;
9444 dw_die_ref context_die;
9446 enum tree_code code = TREE_CODE (type);
9447 dw_die_ref type_die = NULL;
9449 /* ??? If this type is an unnamed subrange type of an integral or
9450 floating-point type, use the inner type. This is because we have no
9451 support for unnamed types in base_type_die. This can happen if this is
9452 an Ada subrange type. Correct solution is emit a subrange type die. */
9453 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9454 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9455 type = TREE_TYPE (type), code = TREE_CODE (type);
9457 if (code == ERROR_MARK)
9460 /* Handle a special case. For functions whose return type is void, we
9461 generate *no* type attribute. (Note that no object may have type
9462 `void', so this only applies to function return types). */
9463 if (code == VOID_TYPE)
9466 type_die = modified_type_die (type,
9467 decl_const || TYPE_READONLY (type),
9468 decl_volatile || TYPE_VOLATILE (type),
9470 if (type_die != NULL)
9471 add_AT_die_ref (object_die, DW_AT_type, type_die);
9474 /* Given a tree pointer to a struct, class, union, or enum type node, return
9475 a pointer to the (string) tag name for the given type, or zero if the type
9476 was declared without a tag. */
9482 const char *name = 0;
9484 if (TYPE_NAME (type) != 0)
9488 /* Find the IDENTIFIER_NODE for the type name. */
9489 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9490 t = TYPE_NAME (type);
9492 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9493 a TYPE_DECL node, regardless of whether or not a `typedef' was
9495 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9496 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9497 t = DECL_NAME (TYPE_NAME (type));
9499 /* Now get the name as a string, or invent one. */
9501 name = IDENTIFIER_POINTER (t);
9504 return (name == 0 || *name == '\0') ? 0 : name;
9507 /* Return the type associated with a data member, make a special check
9508 for bit field types. */
9511 member_declared_type (member)
9514 return (DECL_BIT_FIELD_TYPE (member)
9515 ? DECL_BIT_FIELD_TYPE (member)
9516 : TREE_TYPE (member));
9519 /* Get the decl's label, as described by its RTL. This may be different
9520 from the DECL_NAME name used in the source file. */
9524 decl_start_label (decl)
9529 x = DECL_RTL (decl);
9530 if (GET_CODE (x) != MEM)
9534 if (GET_CODE (x) != SYMBOL_REF)
9537 fnname = XSTR (x, 0);
9542 /* These routines generate the internal representation of the DIE's for
9543 the compilation unit. Debugging information is collected by walking
9544 the declaration trees passed in from dwarf2out_decl(). */
9547 gen_array_type_die (type, context_die)
9549 dw_die_ref context_die;
9551 dw_die_ref scope_die = scope_die_for (type, context_die);
9552 dw_die_ref array_die;
9555 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9556 the inner array type comes before the outer array type. Thus we must
9557 call gen_type_die before we call new_die. See below also. */
9558 #ifdef MIPS_DEBUGGING_INFO
9559 gen_type_die (TREE_TYPE (type), context_die);
9562 array_die = new_die (DW_TAG_array_type, scope_die);
9565 /* We default the array ordering. SDB will probably do
9566 the right things even if DW_AT_ordering is not present. It's not even
9567 an issue until we start to get into multidimensional arrays anyway. If
9568 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9569 then we'll have to put the DW_AT_ordering attribute back in. (But if
9570 and when we find out that we need to put these in, we will only do so
9571 for multidimensional arrays. */
9572 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9575 #ifdef MIPS_DEBUGGING_INFO
9576 /* The SGI compilers handle arrays of unknown bound by setting
9577 AT_declaration and not emitting any subrange DIEs. */
9578 if (! TYPE_DOMAIN (type))
9579 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9582 add_subscript_info (array_die, type);
9584 add_name_attribute (array_die, type_tag (type));
9585 equate_type_number_to_die (type, array_die);
9587 /* Add representation of the type of the elements of this array type. */
9588 element_type = TREE_TYPE (type);
9590 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9591 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9592 We work around this by disabling this feature. See also
9593 add_subscript_info. */
9594 #ifndef MIPS_DEBUGGING_INFO
9595 while (TREE_CODE (element_type) == ARRAY_TYPE)
9596 element_type = TREE_TYPE (element_type);
9598 gen_type_die (element_type, context_die);
9601 add_type_attribute (array_die, element_type, 0, 0, context_die);
9605 gen_set_type_die (type, context_die)
9607 dw_die_ref context_die;
9610 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9612 equate_type_number_to_die (type, type_die);
9613 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9618 gen_entry_point_die (decl, context_die)
9620 dw_die_ref context_die;
9622 tree origin = decl_ultimate_origin (decl);
9623 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9625 add_abstract_origin_attribute (decl_die, origin);
9628 add_name_and_src_coords_attributes (decl_die, decl);
9629 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9633 if (DECL_ABSTRACT (decl))
9634 equate_decl_number_to_die (decl, decl_die);
9636 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9640 /* Remember a type in the incomplete_types_list. */
9642 add_incomplete_type (type)
9645 VARRAY_PUSH_TREE (incomplete_types, type);
9648 /* Walk through the list of incomplete types again, trying once more to
9649 emit full debugging info for them. */
9652 retry_incomplete_types ()
9655 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9657 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9661 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9664 gen_inlined_enumeration_type_die (type, context_die)
9666 dw_die_ref context_die;
9668 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die);
9669 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9670 be incomplete and such types are not marked. */
9671 add_abstract_origin_attribute (type_die, type);
9674 /* Generate a DIE to represent an inlined instance of a structure type. */
9677 gen_inlined_structure_type_die (type, context_die)
9679 dw_die_ref context_die;
9681 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9683 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9684 be incomplete and such types are not marked. */
9685 add_abstract_origin_attribute (type_die, type);
9688 /* Generate a DIE to represent an inlined instance of a union type. */
9691 gen_inlined_union_type_die (type, context_die)
9693 dw_die_ref context_die;
9695 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9697 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9698 be incomplete and such types are not marked. */
9699 add_abstract_origin_attribute (type_die, type);
9702 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9703 include all of the information about the enumeration values also. Each
9704 enumerated type name/value is listed as a child of the enumerated type
9708 gen_enumeration_type_die (type, context_die)
9710 dw_die_ref context_die;
9712 dw_die_ref type_die = lookup_type_die (type);
9714 if (type_die == NULL)
9716 type_die = new_die (DW_TAG_enumeration_type,
9717 scope_die_for (type, context_die));
9718 equate_type_number_to_die (type, type_die);
9719 add_name_attribute (type_die, type_tag (type));
9721 else if (! TYPE_SIZE (type))
9724 remove_AT (type_die, DW_AT_declaration);
9726 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9727 given enum type is incomplete, do not generate the DW_AT_byte_size
9728 attribute or the DW_AT_element_list attribute. */
9729 if (TYPE_SIZE (type))
9733 TREE_ASM_WRITTEN (type) = 1;
9734 add_byte_size_attribute (type_die, type);
9735 if (TYPE_STUB_DECL (type) != NULL_TREE)
9736 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9738 /* If the first reference to this type was as the return type of an
9739 inline function, then it may not have a parent. Fix this now. */
9740 if (type_die->die_parent == NULL)
9741 add_child_die (scope_die_for (type, context_die), type_die);
9743 for (link = TYPE_FIELDS (type);
9744 link != NULL; link = TREE_CHAIN (link))
9746 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9748 add_name_attribute (enum_die,
9749 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9751 if (host_integerp (TREE_VALUE (link), 0))
9753 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9754 add_AT_int (enum_die, DW_AT_const_value,
9755 tree_low_cst (TREE_VALUE (link), 0));
9757 add_AT_unsigned (enum_die, DW_AT_const_value,
9758 tree_low_cst (TREE_VALUE (link), 0));
9763 add_AT_flag (type_die, DW_AT_declaration, 1);
9766 /* Generate a DIE to represent either a real live formal parameter decl or to
9767 represent just the type of some formal parameter position in some function
9770 Note that this routine is a bit unusual because its argument may be a
9771 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9772 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9773 node. If it's the former then this function is being called to output a
9774 DIE to represent a formal parameter object (or some inlining thereof). If
9775 it's the latter, then this function is only being called to output a
9776 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9777 argument type of some subprogram type. */
9780 gen_formal_parameter_die (node, context_die)
9782 dw_die_ref context_die;
9785 = new_die (DW_TAG_formal_parameter, context_die);
9788 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9791 origin = decl_ultimate_origin (node);
9793 add_abstract_origin_attribute (parm_die, origin);
9796 add_name_and_src_coords_attributes (parm_die, node);
9797 add_type_attribute (parm_die, TREE_TYPE (node),
9798 TREE_READONLY (node),
9799 TREE_THIS_VOLATILE (node),
9801 if (DECL_ARTIFICIAL (node))
9802 add_AT_flag (parm_die, DW_AT_artificial, 1);
9805 equate_decl_number_to_die (node, parm_die);
9806 if (! DECL_ABSTRACT (node))
9807 add_location_or_const_value_attribute (parm_die, node);
9812 /* We were called with some kind of a ..._TYPE node. */
9813 add_type_attribute (parm_die, node, 0, 0, context_die);
9823 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9824 at the end of an (ANSI prototyped) formal parameters list. */
9827 gen_unspecified_parameters_die (decl_or_type, context_die)
9828 tree decl_or_type ATTRIBUTE_UNUSED;
9829 dw_die_ref context_die;
9831 new_die (DW_TAG_unspecified_parameters, context_die);
9834 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9835 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9836 parameters as specified in some function type specification (except for
9837 those which appear as part of a function *definition*). */
9840 gen_formal_types_die (function_or_method_type, context_die)
9841 tree function_or_method_type;
9842 dw_die_ref context_die;
9845 tree formal_type = NULL;
9846 tree first_parm_type;
9849 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9851 arg = DECL_ARGUMENTS (function_or_method_type);
9852 function_or_method_type = TREE_TYPE (function_or_method_type);
9857 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9859 /* Make our first pass over the list of formal parameter types and output a
9860 DW_TAG_formal_parameter DIE for each one. */
9861 for (link = first_parm_type; link; )
9863 dw_die_ref parm_die;
9865 formal_type = TREE_VALUE (link);
9866 if (formal_type == void_type_node)
9869 /* Output a (nameless) DIE to represent the formal parameter itself. */
9870 parm_die = gen_formal_parameter_die (formal_type, context_die);
9871 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9872 && link == first_parm_type)
9873 || (arg && DECL_ARTIFICIAL (arg)))
9874 add_AT_flag (parm_die, DW_AT_artificial, 1);
9876 link = TREE_CHAIN (link);
9878 arg = TREE_CHAIN (arg);
9881 /* If this function type has an ellipsis, add a
9882 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9883 if (formal_type != void_type_node)
9884 gen_unspecified_parameters_die (function_or_method_type, context_die);
9886 /* Make our second (and final) pass over the list of formal parameter types
9887 and output DIEs to represent those types (as necessary). */
9888 for (link = TYPE_ARG_TYPES (function_or_method_type);
9890 link = TREE_CHAIN (link))
9892 formal_type = TREE_VALUE (link);
9893 if (formal_type == void_type_node)
9896 gen_type_die (formal_type, context_die);
9900 /* We want to generate the DIE for TYPE so that we can generate the
9901 die for MEMBER, which has been defined; we will need to refer back
9902 to the member declaration nested within TYPE. If we're trying to
9903 generate minimal debug info for TYPE, processing TYPE won't do the
9904 trick; we need to attach the member declaration by hand. */
9907 gen_type_die_for_member (type, member, context_die)
9909 dw_die_ref context_die;
9911 gen_type_die (type, context_die);
9913 /* If we're trying to avoid duplicate debug info, we may not have
9914 emitted the member decl for this function. Emit it now. */
9915 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9916 && ! lookup_decl_die (member))
9918 if (decl_ultimate_origin (member))
9921 push_decl_scope (type);
9922 if (TREE_CODE (member) == FUNCTION_DECL)
9923 gen_subprogram_die (member, lookup_type_die (type));
9925 gen_variable_die (member, lookup_type_die (type));
9930 /* Generate the DWARF2 info for the "abstract" instance
9931 of a function which we may later generate inlined and/or
9932 out-of-line instances of. */
9935 dwarf2out_abstract_function (decl)
9941 int was_abstract = DECL_ABSTRACT (decl);
9943 /* Make sure we have the actual abstract inline, not a clone. */
9944 decl = DECL_ORIGIN (decl);
9946 old_die = lookup_decl_die (decl);
9947 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9948 /* We've already generated the abstract instance. */
9951 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9952 we don't get confused by DECL_ABSTRACT. */
9953 if (debug_info_level > DINFO_LEVEL_TERSE)
9955 context = decl_class_context (decl);
9957 gen_type_die_for_member
9958 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9961 /* Pretend we've just finished compiling this function. */
9962 save_fn = current_function_decl;
9963 current_function_decl = decl;
9965 set_decl_abstract_flags (decl, 1);
9966 dwarf2out_decl (decl);
9968 set_decl_abstract_flags (decl, 0);
9970 current_function_decl = save_fn;
9973 /* Generate a DIE to represent a declared function (either file-scope or
9977 gen_subprogram_die (decl, context_die)
9979 dw_die_ref context_die;
9981 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9982 tree origin = decl_ultimate_origin (decl);
9983 dw_die_ref subr_die;
9987 dw_die_ref old_die = lookup_decl_die (decl);
9988 int declaration = (current_function_decl != decl
9989 || class_scope_p (context_die));
9991 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9992 be true, if we started to generate the abstract instance of an inline,
9993 decided to output its containing class, and proceeded to emit the
9994 declaration of the inline from the member list for the class. In that
9995 case, `declaration' takes priority; we'll get back to the abstract
9996 instance when we're done with the class. */
9998 /* The class-scope declaration DIE must be the primary DIE. */
9999 if (origin && declaration && class_scope_p (context_die))
10006 if (origin != NULL)
10008 if (declaration && ! local_scope_p (context_die))
10011 /* Fixup die_parent for the abstract instance of a nested
10012 inline function. */
10013 if (old_die && old_die->die_parent == NULL)
10014 add_child_die (context_die, old_die);
10016 subr_die = new_die (DW_TAG_subprogram, context_die);
10017 add_abstract_origin_attribute (subr_die, origin);
10021 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10023 if (!get_AT_flag (old_die, DW_AT_declaration)
10024 /* We can have a normal definition following an inline one in the
10025 case of redefinition of GNU C extern inlines.
10026 It seems reasonable to use AT_specification in this case. */
10027 && !get_AT_unsigned (old_die, DW_AT_inline))
10029 /* ??? This can happen if there is a bug in the program, for
10030 instance, if it has duplicate function definitions. Ideally,
10031 we should detect this case and ignore it. For now, if we have
10032 already reported an error, any error at all, then assume that
10033 we got here because of an input error, not a dwarf2 bug. */
10039 /* If the definition comes from the same place as the declaration,
10040 maybe use the old DIE. We always want the DIE for this function
10041 that has the *_pc attributes to be under comp_unit_die so the
10042 debugger can find it. We also need to do this for abstract
10043 instances of inlines, since the spec requires the out-of-line copy
10044 to have the same parent. For local class methods, this doesn't
10045 apply; we just use the old DIE. */
10046 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10047 && (DECL_ARTIFICIAL (decl)
10048 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10049 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10050 == (unsigned) DECL_SOURCE_LINE (decl)))))
10052 subr_die = old_die;
10054 /* Clear out the declaration attribute and the parm types. */
10055 remove_AT (subr_die, DW_AT_declaration);
10056 remove_children (subr_die);
10060 subr_die = new_die (DW_TAG_subprogram, context_die);
10061 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10062 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10063 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10064 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10065 != (unsigned) DECL_SOURCE_LINE (decl))
10067 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10072 subr_die = new_die (DW_TAG_subprogram, context_die);
10074 if (TREE_PUBLIC (decl))
10075 add_AT_flag (subr_die, DW_AT_external, 1);
10077 add_name_and_src_coords_attributes (subr_die, decl);
10078 if (debug_info_level > DINFO_LEVEL_TERSE)
10080 tree type = TREE_TYPE (decl);
10082 add_prototyped_attribute (subr_die, type);
10083 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10086 add_pure_or_virtual_attribute (subr_die, decl);
10087 if (DECL_ARTIFICIAL (decl))
10088 add_AT_flag (subr_die, DW_AT_artificial, 1);
10089 if (TREE_PROTECTED (decl))
10090 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10091 else if (TREE_PRIVATE (decl))
10092 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10097 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10099 add_AT_flag (subr_die, DW_AT_declaration, 1);
10101 /* The first time we see a member function, it is in the context of
10102 the class to which it belongs. We make sure of this by emitting
10103 the class first. The next time is the definition, which is
10104 handled above. The two may come from the same source text. */
10105 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10106 equate_decl_number_to_die (decl, subr_die);
10109 else if (DECL_ABSTRACT (decl))
10111 if (DECL_INLINE (decl) && !flag_no_inline)
10113 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10114 inline functions, but not for extern inline functions.
10115 We can't get this completely correct because information
10116 about whether the function was declared inline is not
10118 if (DECL_DEFER_OUTPUT (decl))
10119 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10121 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10124 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10126 equate_decl_number_to_die (decl, subr_die);
10128 else if (!DECL_EXTERNAL (decl))
10130 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10131 equate_decl_number_to_die (decl, subr_die);
10133 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10134 current_funcdef_number);
10135 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10136 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10137 current_funcdef_number);
10138 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10140 add_pubname (decl, subr_die);
10141 add_arange (decl, subr_die);
10143 #ifdef MIPS_DEBUGGING_INFO
10144 /* Add a reference to the FDE for this routine. */
10145 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10148 /* Define the "frame base" location for this routine. We use the
10149 frame pointer or stack pointer registers, since the RTL for local
10150 variables is relative to one of them. */
10152 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10153 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10156 /* ??? This fails for nested inline functions, because context_display
10157 is not part of the state saved/restored for inline functions. */
10158 if (current_function_needs_context)
10159 add_AT_location_description (subr_die, DW_AT_static_link,
10160 lookup_static_chain (decl));
10164 /* Now output descriptions of the arguments for this function. This gets
10165 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10166 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10167 `...' at the end of the formal parameter list. In order to find out if
10168 there was a trailing ellipsis or not, we must instead look at the type
10169 associated with the FUNCTION_DECL. This will be a node of type
10170 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10171 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10172 an ellipsis at the end. */
10174 /* In the case where we are describing a mere function declaration, all we
10175 need to do here (and all we *can* do here) is to describe the *types* of
10176 its formal parameters. */
10177 if (debug_info_level <= DINFO_LEVEL_TERSE)
10179 else if (declaration)
10180 gen_formal_types_die (decl, subr_die);
10183 /* Generate DIEs to represent all known formal parameters */
10184 tree arg_decls = DECL_ARGUMENTS (decl);
10187 /* When generating DIEs, generate the unspecified_parameters DIE
10188 instead if we come across the arg "__builtin_va_alist" */
10189 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10190 if (TREE_CODE (parm) == PARM_DECL)
10192 if (DECL_NAME (parm)
10193 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10194 "__builtin_va_alist"))
10195 gen_unspecified_parameters_die (parm, subr_die);
10197 gen_decl_die (parm, subr_die);
10200 /* Decide whether we need an unspecified_parameters DIE at the end.
10201 There are 2 more cases to do this for: 1) the ansi ... declaration -
10202 this is detectable when the end of the arg list is not a
10203 void_type_node 2) an unprototyped function declaration (not a
10204 definition). This just means that we have no info about the
10205 parameters at all. */
10206 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10207 if (fn_arg_types != NULL)
10209 /* this is the prototyped case, check for ... */
10210 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10211 gen_unspecified_parameters_die (decl, subr_die);
10213 else if (DECL_INITIAL (decl) == NULL_TREE)
10214 gen_unspecified_parameters_die (decl, subr_die);
10217 /* Output Dwarf info for all of the stuff within the body of the function
10218 (if it has one - it may be just a declaration). */
10219 outer_scope = DECL_INITIAL (decl);
10221 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10222 node created to represent a function. This outermost BLOCK actually
10223 represents the outermost binding contour for the function, i.e. the
10224 contour in which the function's formal parameters and labels get
10225 declared. Curiously, it appears that the front end doesn't actually
10226 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10227 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10228 list for the function instead.) The BLOCK_VARS list for the
10229 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10230 the function however, and we output DWARF info for those in
10231 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10232 node representing the function's outermost pair of curly braces, and
10233 any blocks used for the base and member initializers of a C++
10234 constructor function. */
10235 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10237 current_function_has_inlines = 0;
10238 decls_for_scope (outer_scope, subr_die, 0);
10240 #if 0 && defined (MIPS_DEBUGGING_INFO)
10241 if (current_function_has_inlines)
10243 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10244 if (! comp_unit_has_inlines)
10246 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10247 comp_unit_has_inlines = 1;
10254 /* Generate a DIE to represent a declared data object. */
10257 gen_variable_die (decl, context_die)
10259 dw_die_ref context_die;
10261 tree origin = decl_ultimate_origin (decl);
10262 dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10264 dw_die_ref old_die = lookup_decl_die (decl);
10265 int declaration = (DECL_EXTERNAL (decl)
10266 || class_scope_p (context_die));
10268 if (origin != NULL)
10269 add_abstract_origin_attribute (var_die, origin);
10270 /* Loop unrolling can create multiple blocks that refer to the same
10271 static variable, so we must test for the DW_AT_declaration flag. */
10272 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10273 copy decls and set the DECL_ABSTRACT flag on them instead of
10275 /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10276 else if (old_die && TREE_STATIC (decl)
10277 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10279 /* This is a definition of a C++ class level static. */
10280 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10281 if (DECL_NAME (decl))
10283 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10285 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10286 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10288 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10289 != (unsigned) DECL_SOURCE_LINE (decl))
10291 add_AT_unsigned (var_die, DW_AT_decl_line,
10292 DECL_SOURCE_LINE (decl));
10297 add_name_and_src_coords_attributes (var_die, decl);
10298 add_type_attribute (var_die, TREE_TYPE (decl),
10299 TREE_READONLY (decl),
10300 TREE_THIS_VOLATILE (decl), context_die);
10302 if (TREE_PUBLIC (decl))
10303 add_AT_flag (var_die, DW_AT_external, 1);
10305 if (DECL_ARTIFICIAL (decl))
10306 add_AT_flag (var_die, DW_AT_artificial, 1);
10308 if (TREE_PROTECTED (decl))
10309 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10311 else if (TREE_PRIVATE (decl))
10312 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10316 add_AT_flag (var_die, DW_AT_declaration, 1);
10318 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10319 equate_decl_number_to_die (decl, var_die);
10321 if (! declaration && ! DECL_ABSTRACT (decl))
10323 add_location_or_const_value_attribute (var_die, decl);
10324 add_pubname (decl, var_die);
10327 tree_add_const_value_attribute (var_die, decl);
10330 /* Generate a DIE to represent a label identifier. */
10333 gen_label_die (decl, context_die)
10335 dw_die_ref context_die;
10337 tree origin = decl_ultimate_origin (decl);
10338 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10340 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10342 if (origin != NULL)
10343 add_abstract_origin_attribute (lbl_die, origin);
10345 add_name_and_src_coords_attributes (lbl_die, decl);
10347 if (DECL_ABSTRACT (decl))
10348 equate_decl_number_to_die (decl, lbl_die);
10351 insn = DECL_RTL (decl);
10353 /* Deleted labels are programmer specified labels which have been
10354 eliminated because of various optimisations. We still emit them
10355 here so that it is possible to put breakpoints on them. */
10356 if (GET_CODE (insn) == CODE_LABEL
10357 || ((GET_CODE (insn) == NOTE
10358 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10360 /* When optimization is enabled (via -O) some parts of the compiler
10361 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10362 represent source-level labels which were explicitly declared by
10363 the user. This really shouldn't be happening though, so catch
10364 it if it ever does happen. */
10365 if (INSN_DELETED_P (insn))
10368 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10369 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10374 /* Generate a DIE for a lexical block. */
10377 gen_lexical_block_die (stmt, context_die, depth)
10379 dw_die_ref context_die;
10382 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10383 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10385 if (! BLOCK_ABSTRACT (stmt))
10387 if (BLOCK_FRAGMENT_CHAIN (stmt))
10391 add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
10393 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10396 add_ranges (chain);
10397 chain = BLOCK_FRAGMENT_CHAIN (chain);
10404 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10405 BLOCK_NUMBER (stmt));
10406 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10407 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10408 BLOCK_NUMBER (stmt));
10409 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10413 decls_for_scope (stmt, stmt_die, depth);
10416 /* Generate a DIE for an inlined subprogram. */
10419 gen_inlined_subroutine_die (stmt, context_die, depth)
10421 dw_die_ref context_die;
10424 if (! BLOCK_ABSTRACT (stmt))
10426 dw_die_ref subr_die
10427 = new_die (DW_TAG_inlined_subroutine, context_die);
10428 tree decl = block_ultimate_origin (stmt);
10429 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10431 /* Emit info for the abstract instance first, if we haven't yet. */
10432 dwarf2out_abstract_function (decl);
10434 add_abstract_origin_attribute (subr_die, decl);
10435 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10436 BLOCK_NUMBER (stmt));
10437 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10438 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10439 BLOCK_NUMBER (stmt));
10440 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10441 decls_for_scope (stmt, subr_die, depth);
10442 current_function_has_inlines = 1;
10446 /* Generate a DIE for a field in a record, or structure. */
10449 gen_field_die (decl, context_die)
10451 dw_die_ref context_die;
10453 dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10455 add_name_and_src_coords_attributes (decl_die, decl);
10456 add_type_attribute (decl_die, member_declared_type (decl),
10457 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10460 /* If this is a bit field... */
10461 if (DECL_BIT_FIELD_TYPE (decl))
10463 add_byte_size_attribute (decl_die, decl);
10464 add_bit_size_attribute (decl_die, decl);
10465 add_bit_offset_attribute (decl_die, decl);
10468 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10469 add_data_member_location_attribute (decl_die, decl);
10471 if (DECL_ARTIFICIAL (decl))
10472 add_AT_flag (decl_die, DW_AT_artificial, 1);
10474 if (TREE_PROTECTED (decl))
10475 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10477 else if (TREE_PRIVATE (decl))
10478 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10482 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10483 Use modified_type_die instead.
10484 We keep this code here just in case these types of DIEs may be needed to
10485 represent certain things in other languages (e.g. Pascal) someday. */
10487 gen_pointer_type_die (type, context_die)
10489 dw_die_ref context_die;
10492 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10494 equate_type_number_to_die (type, ptr_die);
10495 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10496 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10499 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10500 Use modified_type_die instead.
10501 We keep this code here just in case these types of DIEs may be needed to
10502 represent certain things in other languages (e.g. Pascal) someday. */
10504 gen_reference_type_die (type, context_die)
10506 dw_die_ref context_die;
10509 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10511 equate_type_number_to_die (type, ref_die);
10512 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10513 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10517 /* Generate a DIE for a pointer to a member type. */
10519 gen_ptr_to_mbr_type_die (type, context_die)
10521 dw_die_ref context_die;
10524 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10526 equate_type_number_to_die (type, ptr_die);
10527 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10528 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10529 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10532 /* Generate the DIE for the compilation unit. */
10535 gen_compile_unit_die (filename)
10536 const char *filename;
10539 char producer[250];
10540 const char *wd = getpwd ();
10541 const char *language_string = lang_hooks.name;
10544 die = new_die (DW_TAG_compile_unit, NULL);
10545 add_name_attribute (die, filename);
10547 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10548 add_AT_string (die, DW_AT_comp_dir, wd);
10550 sprintf (producer, "%s %s", language_string, version_string);
10552 #ifdef MIPS_DEBUGGING_INFO
10553 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10554 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10555 not appear in the producer string, the debugger reaches the conclusion
10556 that the object file is stripped and has no debugging information.
10557 To get the MIPS/SGI debugger to believe that there is debugging
10558 information in the object file, we add a -g to the producer string. */
10559 if (debug_info_level > DINFO_LEVEL_TERSE)
10560 strcat (producer, " -g");
10563 add_AT_string (die, DW_AT_producer, producer);
10565 if (strcmp (language_string, "GNU C++") == 0)
10566 language = DW_LANG_C_plus_plus;
10567 else if (strcmp (language_string, "GNU Ada") == 0)
10568 language = DW_LANG_Ada83;
10569 else if (strcmp (language_string, "GNU F77") == 0)
10570 language = DW_LANG_Fortran77;
10571 else if (strcmp (language_string, "GNU Pascal") == 0)
10572 language = DW_LANG_Pascal83;
10573 else if (strcmp (language_string, "GNU Java") == 0)
10574 language = DW_LANG_Java;
10575 else if (flag_traditional)
10576 language = DW_LANG_C;
10578 language = DW_LANG_C89;
10580 add_AT_unsigned (die, DW_AT_language, language);
10585 /* Generate a DIE for a string type. */
10588 gen_string_type_die (type, context_die)
10590 dw_die_ref context_die;
10592 dw_die_ref type_die
10593 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10595 equate_type_number_to_die (type, type_die);
10597 /* Fudge the string length attribute for now. */
10599 /* TODO: add string length info.
10600 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10601 bound_representation (upper_bound, 0, 'u'); */
10604 /* Generate the DIE for a base class. */
10607 gen_inheritance_die (binfo, context_die)
10609 dw_die_ref context_die;
10611 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10613 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10614 add_data_member_location_attribute (die, binfo);
10616 if (TREE_VIA_VIRTUAL (binfo))
10617 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10618 if (TREE_VIA_PUBLIC (binfo))
10619 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10620 else if (TREE_VIA_PROTECTED (binfo))
10621 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10624 /* Generate a DIE for a class member. */
10627 gen_member_die (type, context_die)
10629 dw_die_ref context_die;
10634 /* If this is not an incomplete type, output descriptions of each of its
10635 members. Note that as we output the DIEs necessary to represent the
10636 members of this record or union type, we will also be trying to output
10637 DIEs to represent the *types* of those members. However the `type'
10638 function (above) will specifically avoid generating type DIEs for member
10639 types *within* the list of member DIEs for this (containing) type except
10640 for those types (of members) which are explicitly marked as also being
10641 members of this (containing) type themselves. The g++ front- end can
10642 force any given type to be treated as a member of some other
10643 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10644 to point to the TREE node representing the appropriate (containing)
10647 /* First output info about the base classes. */
10648 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10650 tree bases = TYPE_BINFO_BASETYPES (type);
10651 int n_bases = TREE_VEC_LENGTH (bases);
10654 for (i = 0; i < n_bases; i++)
10655 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10658 /* Now output info about the data members and type members. */
10659 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10661 /* If we thought we were generating minimal debug info for TYPE
10662 and then changed our minds, some of the member declarations
10663 may have already been defined. Don't define them again, but
10664 do put them in the right order. */
10666 child = lookup_decl_die (member);
10668 splice_child_die (context_die, child);
10670 gen_decl_die (member, context_die);
10673 /* Now output info about the function members (if any). */
10674 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10676 /* Don't include clones in the member list. */
10677 if (DECL_ABSTRACT_ORIGIN (member))
10680 child = lookup_decl_die (member);
10682 splice_child_die (context_die, child);
10684 gen_decl_die (member, context_die);
10688 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10689 is set, we pretend that the type was never defined, so we only get the
10690 member DIEs needed by later specification DIEs. */
10693 gen_struct_or_union_type_die (type, context_die)
10695 dw_die_ref context_die;
10697 dw_die_ref type_die = lookup_type_die (type);
10698 dw_die_ref scope_die = 0;
10700 int complete = (TYPE_SIZE (type)
10701 && (! TYPE_STUB_DECL (type)
10702 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10704 if (type_die && ! complete)
10707 if (TYPE_CONTEXT (type) != NULL_TREE
10708 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10711 scope_die = scope_die_for (type, context_die);
10713 if (! type_die || (nested && scope_die == comp_unit_die))
10714 /* First occurrence of type or toplevel definition of nested class. */
10716 dw_die_ref old_die = type_die;
10718 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10719 ? DW_TAG_structure_type : DW_TAG_union_type,
10721 equate_type_number_to_die (type, type_die);
10723 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10725 add_name_attribute (type_die, type_tag (type));
10728 remove_AT (type_die, DW_AT_declaration);
10730 /* If this type has been completed, then give it a byte_size attribute and
10731 then give a list of members. */
10734 /* Prevent infinite recursion in cases where the type of some member of
10735 this type is expressed in terms of this type itself. */
10736 TREE_ASM_WRITTEN (type) = 1;
10737 add_byte_size_attribute (type_die, type);
10738 if (TYPE_STUB_DECL (type) != NULL_TREE)
10739 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10741 /* If the first reference to this type was as the return type of an
10742 inline function, then it may not have a parent. Fix this now. */
10743 if (type_die->die_parent == NULL)
10744 add_child_die (scope_die, type_die);
10746 push_decl_scope (type);
10747 gen_member_die (type, type_die);
10750 /* GNU extension: Record what type our vtable lives in. */
10751 if (TYPE_VFIELD (type))
10753 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10755 gen_type_die (vtype, context_die);
10756 add_AT_die_ref (type_die, DW_AT_containing_type,
10757 lookup_type_die (vtype));
10762 add_AT_flag (type_die, DW_AT_declaration, 1);
10764 /* We don't need to do this for function-local types. */
10765 if (! decl_function_context (TYPE_STUB_DECL (type)))
10766 add_incomplete_type (type);
10770 /* Generate a DIE for a subroutine _type_. */
10773 gen_subroutine_type_die (type, context_die)
10775 dw_die_ref context_die;
10777 tree return_type = TREE_TYPE (type);
10778 dw_die_ref subr_die
10779 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10781 equate_type_number_to_die (type, subr_die);
10782 add_prototyped_attribute (subr_die, type);
10783 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10784 gen_formal_types_die (type, subr_die);
10787 /* Generate a DIE for a type definition */
10790 gen_typedef_die (decl, context_die)
10792 dw_die_ref context_die;
10794 dw_die_ref type_die;
10797 if (TREE_ASM_WRITTEN (decl))
10799 TREE_ASM_WRITTEN (decl) = 1;
10801 type_die = new_die (DW_TAG_typedef, context_die);
10802 origin = decl_ultimate_origin (decl);
10803 if (origin != NULL)
10804 add_abstract_origin_attribute (type_die, origin);
10808 add_name_and_src_coords_attributes (type_die, decl);
10809 if (DECL_ORIGINAL_TYPE (decl))
10811 type = DECL_ORIGINAL_TYPE (decl);
10813 if (type == TREE_TYPE (decl))
10816 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10819 type = TREE_TYPE (decl);
10820 add_type_attribute (type_die, type, TREE_READONLY (decl),
10821 TREE_THIS_VOLATILE (decl), context_die);
10824 if (DECL_ABSTRACT (decl))
10825 equate_decl_number_to_die (decl, type_die);
10828 /* Generate a type description DIE. */
10831 gen_type_die (type, context_die)
10833 dw_die_ref context_die;
10837 if (type == NULL_TREE || type == error_mark_node)
10840 /* We are going to output a DIE to represent the unqualified version of
10841 this type (i.e. without any const or volatile qualifiers) so get the
10842 main variant (i.e. the unqualified version) of this type now. */
10843 type = type_main_variant (type);
10845 if (TREE_ASM_WRITTEN (type))
10848 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10849 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10851 TREE_ASM_WRITTEN (type) = 1;
10852 gen_decl_die (TYPE_NAME (type), context_die);
10856 switch (TREE_CODE (type))
10862 case REFERENCE_TYPE:
10863 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10864 ensures that the gen_type_die recursion will terminate even if the
10865 type is recursive. Recursive types are possible in Ada. */
10866 /* ??? We could perhaps do this for all types before the switch
10868 TREE_ASM_WRITTEN (type) = 1;
10870 /* For these types, all that is required is that we output a DIE (or a
10871 set of DIEs) to represent the "basis" type. */
10872 gen_type_die (TREE_TYPE (type), context_die);
10876 /* This code is used for C++ pointer-to-data-member types.
10877 Output a description of the relevant class type. */
10878 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10880 /* Output a description of the type of the object pointed to. */
10881 gen_type_die (TREE_TYPE (type), context_die);
10883 /* Now output a DIE to represent this pointer-to-data-member type
10885 gen_ptr_to_mbr_type_die (type, context_die);
10889 gen_type_die (TYPE_DOMAIN (type), context_die);
10890 gen_set_type_die (type, context_die);
10894 gen_type_die (TREE_TYPE (type), context_die);
10895 abort (); /* No way to represent these in Dwarf yet! */
10898 case FUNCTION_TYPE:
10899 /* Force out return type (in case it wasn't forced out already). */
10900 gen_type_die (TREE_TYPE (type), context_die);
10901 gen_subroutine_type_die (type, context_die);
10905 /* Force out return type (in case it wasn't forced out already). */
10906 gen_type_die (TREE_TYPE (type), context_die);
10907 gen_subroutine_type_die (type, context_die);
10911 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10913 gen_type_die (TREE_TYPE (type), context_die);
10914 gen_string_type_die (type, context_die);
10917 gen_array_type_die (type, context_die);
10921 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10924 case ENUMERAL_TYPE:
10927 case QUAL_UNION_TYPE:
10928 /* If this is a nested type whose containing class hasn't been
10929 written out yet, writing it out will cover this one, too.
10930 This does not apply to instantiations of member class templates;
10931 they need to be added to the containing class as they are
10932 generated. FIXME: This hurts the idea of combining type decls
10933 from multiple TUs, since we can't predict what set of template
10934 instantiations we'll get. */
10935 if (TYPE_CONTEXT (type)
10936 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10937 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10939 gen_type_die (TYPE_CONTEXT (type), context_die);
10941 if (TREE_ASM_WRITTEN (type))
10944 /* If that failed, attach ourselves to the stub. */
10945 push_decl_scope (TYPE_CONTEXT (type));
10946 context_die = lookup_type_die (TYPE_CONTEXT (type));
10952 if (TREE_CODE (type) == ENUMERAL_TYPE)
10953 gen_enumeration_type_die (type, context_die);
10955 gen_struct_or_union_type_die (type, context_die);
10960 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10961 it up if it is ever completed. gen_*_type_die will set it for us
10962 when appropriate. */
10971 /* No DIEs needed for fundamental types. */
10975 /* No Dwarf representation currently defined. */
10982 TREE_ASM_WRITTEN (type) = 1;
10985 /* Generate a DIE for a tagged type instantiation. */
10988 gen_tagged_type_instantiation_die (type, context_die)
10990 dw_die_ref context_die;
10992 if (type == NULL_TREE || type == error_mark_node)
10995 /* We are going to output a DIE to represent the unqualified version of
10996 this type (i.e. without any const or volatile qualifiers) so make sure
10997 that we have the main variant (i.e. the unqualified version) of this
10999 if (type != type_main_variant (type))
11002 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11003 an instance of an unresolved type. */
11005 switch (TREE_CODE (type))
11010 case ENUMERAL_TYPE:
11011 gen_inlined_enumeration_type_die (type, context_die);
11015 gen_inlined_structure_type_die (type, context_die);
11019 case QUAL_UNION_TYPE:
11020 gen_inlined_union_type_die (type, context_die);
11028 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11029 things which are local to the given block. */
11032 gen_block_die (stmt, context_die, depth)
11034 dw_die_ref context_die;
11037 int must_output_die = 0;
11040 enum tree_code origin_code;
11042 /* Ignore blocks never really used to make RTL. */
11043 if (stmt == NULL_TREE || !TREE_USED (stmt)
11044 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11047 /* If the block is one fragment of a non-contiguous block, do not
11048 process the variables, since they will have been done by the
11049 origin block. Do process subblocks. */
11050 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11054 for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11055 gen_block_die (sub, context_die, depth + 1);
11059 /* Determine the "ultimate origin" of this block. This block may be an
11060 inlined instance of an inlined instance of inline function, so we have
11061 to trace all of the way back through the origin chain to find out what
11062 sort of node actually served as the original seed for the creation of
11063 the current block. */
11064 origin = block_ultimate_origin (stmt);
11065 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11067 /* Determine if we need to output any Dwarf DIEs at all to represent this
11069 if (origin_code == FUNCTION_DECL)
11070 /* The outer scopes for inlinings *must* always be represented. We
11071 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11072 must_output_die = 1;
11075 /* In the case where the current block represents an inlining of the
11076 "body block" of an inline function, we must *NOT* output any DIE for
11077 this block because we have already output a DIE to represent the
11078 whole inlined function scope and the "body block" of any function
11079 doesn't really represent a different scope according to ANSI C
11080 rules. So we check here to make sure that this block does not
11081 represent a "body block inlining" before trying to set the
11082 `must_output_die' flag. */
11083 if (! is_body_block (origin ? origin : stmt))
11085 /* Determine if this block directly contains any "significant"
11086 local declarations which we will need to output DIEs for. */
11087 if (debug_info_level > DINFO_LEVEL_TERSE)
11088 /* We are not in terse mode so *any* local declaration counts
11089 as being a "significant" one. */
11090 must_output_die = (BLOCK_VARS (stmt) != NULL);
11092 /* We are in terse mode, so only local (nested) function
11093 definitions count as "significant" local declarations. */
11094 for (decl = BLOCK_VARS (stmt);
11095 decl != NULL; decl = TREE_CHAIN (decl))
11096 if (TREE_CODE (decl) == FUNCTION_DECL
11097 && DECL_INITIAL (decl))
11099 must_output_die = 1;
11105 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11106 DIE for any block which contains no significant local declarations at
11107 all. Rather, in such cases we just call `decls_for_scope' so that any
11108 needed Dwarf info for any sub-blocks will get properly generated. Note
11109 that in terse mode, our definition of what constitutes a "significant"
11110 local declaration gets restricted to include only inlined function
11111 instances and local (nested) function definitions. */
11112 if (must_output_die)
11114 if (origin_code == FUNCTION_DECL)
11115 gen_inlined_subroutine_die (stmt, context_die, depth);
11117 gen_lexical_block_die (stmt, context_die, depth);
11120 decls_for_scope (stmt, context_die, depth);
11123 /* Generate all of the decls declared within a given scope and (recursively)
11124 all of its sub-blocks. */
11127 decls_for_scope (stmt, context_die, depth)
11129 dw_die_ref context_die;
11135 /* Ignore blocks never really used to make RTL. */
11136 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11139 /* Output the DIEs to represent all of the data objects and typedefs
11140 declared directly within this block but not within any nested
11141 sub-blocks. Also, nested function and tag DIEs have been
11142 generated with a parent of NULL; fix that up now. */
11143 for (decl = BLOCK_VARS (stmt);
11144 decl != NULL; decl = TREE_CHAIN (decl))
11148 if (TREE_CODE (decl) == FUNCTION_DECL)
11149 die = lookup_decl_die (decl);
11150 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11151 die = lookup_type_die (TREE_TYPE (decl));
11155 if (die != NULL && die->die_parent == NULL)
11156 add_child_die (context_die, die);
11158 gen_decl_die (decl, context_die);
11161 /* Output the DIEs to represent all sub-blocks (and the items declared
11162 therein) of this block. */
11163 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11165 subblocks = BLOCK_CHAIN (subblocks))
11166 gen_block_die (subblocks, context_die, depth + 1);
11169 /* Is this a typedef we can avoid emitting? */
11172 is_redundant_typedef (decl)
11175 if (TYPE_DECL_IS_STUB (decl))
11178 if (DECL_ARTIFICIAL (decl)
11179 && DECL_CONTEXT (decl)
11180 && is_tagged_type (DECL_CONTEXT (decl))
11181 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11182 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11183 /* Also ignore the artificial member typedef for the class name. */
11189 /* Generate Dwarf debug information for a decl described by DECL. */
11192 gen_decl_die (decl, context_die)
11194 dw_die_ref context_die;
11198 if (TREE_CODE (decl) == ERROR_MARK)
11201 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11202 if (DECL_IGNORED_P (decl))
11205 switch (TREE_CODE (decl))
11208 /* The individual enumerators of an enum type get output when we output
11209 the Dwarf representation of the relevant enum type itself. */
11212 case FUNCTION_DECL:
11213 /* Don't output any DIEs to represent mere function declarations,
11214 unless they are class members or explicit block externs. */
11215 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11216 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11219 /* If we're emitting a clone, emit info for the abstract instance. */
11220 if (DECL_ORIGIN (decl) != decl)
11221 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11222 /* If we're emitting an out-of-line copy of an inline function,
11223 emit info for the abstract instance and set up to refer to it. */
11224 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11225 && ! class_scope_p (context_die)
11226 /* dwarf2out_abstract_function won't emit a die if this is just
11227 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11228 that case, because that works only if we have a die. */
11229 && DECL_INITIAL (decl) != NULL_TREE)
11231 dwarf2out_abstract_function (decl);
11232 set_decl_origin_self (decl);
11234 /* Otherwise we're emitting the primary DIE for this decl. */
11235 else if (debug_info_level > DINFO_LEVEL_TERSE)
11237 /* Before we describe the FUNCTION_DECL itself, make sure that we
11238 have described its return type. */
11239 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11241 /* And its virtual context. */
11242 if (DECL_VINDEX (decl) != NULL_TREE)
11243 gen_type_die (DECL_CONTEXT (decl), context_die);
11245 /* And its containing type. */
11246 origin = decl_class_context (decl);
11247 if (origin != NULL_TREE)
11248 gen_type_die_for_member (origin, decl, context_die);
11251 /* Now output a DIE to represent the function itself. */
11252 gen_subprogram_die (decl, context_die);
11256 /* If we are in terse mode, don't generate any DIEs to represent any
11257 actual typedefs. */
11258 if (debug_info_level <= DINFO_LEVEL_TERSE)
11261 /* In the special case of a TYPE_DECL node representing the
11262 declaration of some type tag, if the given TYPE_DECL is marked as
11263 having been instantiated from some other (original) TYPE_DECL node
11264 (e.g. one which was generated within the original definition of an
11265 inline function) we have to generate a special (abbreviated)
11266 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11268 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11270 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11274 if (is_redundant_typedef (decl))
11275 gen_type_die (TREE_TYPE (decl), context_die);
11277 /* Output a DIE to represent the typedef itself. */
11278 gen_typedef_die (decl, context_die);
11282 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11283 gen_label_die (decl, context_die);
11287 /* If we are in terse mode, don't generate any DIEs to represent any
11288 variable declarations or definitions. */
11289 if (debug_info_level <= DINFO_LEVEL_TERSE)
11292 /* Output any DIEs that are needed to specify the type of this data
11294 gen_type_die (TREE_TYPE (decl), context_die);
11296 /* And its containing type. */
11297 origin = decl_class_context (decl);
11298 if (origin != NULL_TREE)
11299 gen_type_die_for_member (origin, decl, context_die);
11301 /* Now output the DIE to represent the data object itself. This gets
11302 complicated because of the possibility that the VAR_DECL really
11303 represents an inlined instance of a formal parameter for an inline
11305 origin = decl_ultimate_origin (decl);
11306 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11307 gen_formal_parameter_die (decl, context_die);
11309 gen_variable_die (decl, context_die);
11313 /* Ignore the nameless fields that are used to skip bits, but
11314 handle C++ anonymous unions. */
11315 if (DECL_NAME (decl) != NULL_TREE
11316 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11318 gen_type_die (member_declared_type (decl), context_die);
11319 gen_field_die (decl, context_die);
11324 gen_type_die (TREE_TYPE (decl), context_die);
11325 gen_formal_parameter_die (decl, context_die);
11328 case NAMESPACE_DECL:
11329 /* Ignore for now. */
11337 /* Add Ada "use" clause information for SGI Workshop debugger. */
11340 dwarf2out_add_library_unit_info (filename, context_list)
11341 const char *filename;
11342 const char *context_list;
11344 unsigned int file_index;
11346 if (filename != NULL)
11348 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11349 tree context_list_decl
11350 = build_decl (LABEL_DECL, get_identifier (context_list),
11353 TREE_PUBLIC (context_list_decl) = TRUE;
11354 add_name_attribute (unit_die, context_list);
11355 file_index = lookup_filename (filename);
11356 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11357 add_pubname (context_list_decl, unit_die);
11361 /* Debug information for a global DECL. Called from toplev.c after
11362 compilation proper has finished. */
11364 dwarf2out_global_decl (decl)
11367 /* Output DWARF2 information for file-scope tentative data object
11368 declarations, file-scope (extern) function declarations (which
11369 had no corresponding body) and file-scope tagged type
11370 declarations and definitions which have not yet been forced out. */
11372 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11373 dwarf2out_decl (decl);
11376 /* Write the debugging output for DECL. */
11379 dwarf2out_decl (decl)
11382 dw_die_ref context_die = comp_unit_die;
11384 if (TREE_CODE (decl) == ERROR_MARK)
11387 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11388 if (DECL_IGNORED_P (decl))
11391 switch (TREE_CODE (decl))
11393 case FUNCTION_DECL:
11394 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11395 builtin function. Explicit programmer-supplied declarations of
11396 these same functions should NOT be ignored however. */
11397 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11400 /* What we would really like to do here is to filter out all mere
11401 file-scope declarations of file-scope functions which are never
11402 referenced later within this translation unit (and keep all of ones
11403 that *are* referenced later on) but we aren't clairvoyant, so we have
11404 no idea which functions will be referenced in the future (i.e. later
11405 on within the current translation unit). So here we just ignore all
11406 file-scope function declarations which are not also definitions. If
11407 and when the debugger needs to know something about these functions,
11408 it will have to hunt around and find the DWARF information associated
11409 with the definition of the function. Note that we can't just check
11410 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11411 definitions and which ones represent mere declarations. We have to
11412 check `DECL_INITIAL' instead. That's because the C front-end
11413 supports some weird semantics for "extern inline" function
11414 definitions. These can get inlined within the current translation
11415 unit (an thus, we need to generate DWARF info for their abstract
11416 instances so that the DWARF info for the concrete inlined instances
11417 can have something to refer to) but the compiler never generates any
11418 out-of-lines instances of such things (despite the fact that they
11419 *are* definitions). The important point is that the C front-end
11420 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11421 to generate DWARF for them anyway. Note that the C++ front-end also
11422 plays some similar games for inline function definitions appearing
11423 within include files which also contain
11424 `#pragma interface' pragmas. */
11425 if (DECL_INITIAL (decl) == NULL_TREE)
11428 /* If we're a nested function, initially use a parent of NULL; if we're
11429 a plain function, this will be fixed up in decls_for_scope. If
11430 we're a method, it will be ignored, since we already have a DIE. */
11431 if (decl_function_context (decl))
11432 context_die = NULL;
11437 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11438 declaration and if the declaration was never even referenced from
11439 within this entire compilation unit. We suppress these DIEs in
11440 order to save space in the .debug section (by eliminating entries
11441 which are probably useless). Note that we must not suppress
11442 block-local extern declarations (whether used or not) because that
11443 would screw-up the debugger's name lookup mechanism and cause it to
11444 miss things which really ought to be in scope at a given point. */
11445 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11448 /* If we are in terse mode, don't generate any DIEs to represent any
11449 variable declarations or definitions. */
11450 if (debug_info_level <= DINFO_LEVEL_TERSE)
11455 /* Don't emit stubs for types unless they are needed by other DIEs. */
11456 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11459 /* Don't bother trying to generate any DIEs to represent any of the
11460 normal built-in types for the language we are compiling. */
11461 if (DECL_SOURCE_LINE (decl) == 0)
11463 /* OK, we need to generate one for `bool' so GDB knows what type
11464 comparisons have. */
11465 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11466 == DW_LANG_C_plus_plus)
11467 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11468 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11473 /* If we are in terse mode, don't generate any DIEs for types. */
11474 if (debug_info_level <= DINFO_LEVEL_TERSE)
11477 /* If we're a function-scope tag, initially use a parent of NULL;
11478 this will be fixed up in decls_for_scope. */
11479 if (decl_function_context (decl))
11480 context_die = NULL;
11488 gen_decl_die (decl, context_die);
11491 /* Output a marker (i.e. a label) for the beginning of the generated code for
11492 a lexical block. */
11495 dwarf2out_begin_block (line, blocknum)
11496 unsigned int line ATTRIBUTE_UNUSED;
11497 unsigned int blocknum;
11499 function_section (current_function_decl);
11500 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11503 /* Output a marker (i.e. a label) for the end of the generated code for a
11507 dwarf2out_end_block (line, blocknum)
11508 unsigned int line ATTRIBUTE_UNUSED;
11509 unsigned int blocknum;
11511 function_section (current_function_decl);
11512 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11515 /* Returns nonzero if it is appropriate not to emit any debugging
11516 information for BLOCK, because it doesn't contain any instructions.
11518 Don't allow this for blocks with nested functions or local classes
11519 as we would end up with orphans, and in the presence of scheduling
11520 we may end up calling them anyway. */
11523 dwarf2out_ignore_block (block)
11527 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11528 if (TREE_CODE (decl) == FUNCTION_DECL
11529 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11534 /* Lookup a filename (in the list of filenames that we know about here in
11535 dwarf2out.c) and return its "index". The index of each (known) filename is
11536 just a unique number which is associated with only that one filename.
11537 We need such numbers for the sake of generating labels
11538 (in the .debug_sfnames section) and references to those
11539 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11540 If the filename given as an argument is not found in our current list,
11541 add it to the list and assign it the next available unique index number.
11542 In order to speed up searches, we remember the index of the filename
11543 was looked up last. This handles the majority of all searches. */
11546 lookup_filename (file_name)
11547 const char *file_name;
11551 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11552 if (strcmp (file_name, "<internal>") == 0
11553 || strcmp (file_name, "<built-in>") == 0)
11556 /* Check to see if the file name that was searched on the previous
11557 call matches this file name. If so, return the index. */
11558 if (file_table.last_lookup_index != 0)
11559 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11560 return file_table.last_lookup_index;
11562 /* Didn't match the previous lookup, search the table */
11563 for (i = 1; i < file_table.in_use; ++i)
11564 if (strcmp (file_name, file_table.table[i]) == 0)
11566 file_table.last_lookup_index = i;
11570 /* Prepare to add a new table entry by making sure there is enough space in
11571 the table to do so. If not, expand the current table. */
11572 if (i == file_table.allocated)
11574 file_table.allocated = i + FILE_TABLE_INCREMENT;
11575 file_table.table = (char **)
11576 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11579 /* Add the new entry to the end of the filename table. */
11580 file_table.table[i] = xstrdup (file_name);
11581 file_table.in_use = i + 1;
11582 file_table.last_lookup_index = i;
11584 if (DWARF2_ASM_LINE_DEBUG_INFO)
11585 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11593 /* Allocate the initial hunk of the file_table. */
11594 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11595 file_table.allocated = FILE_TABLE_INCREMENT;
11597 /* Skip the first entry - file numbers begin at 1. */
11598 file_table.in_use = 1;
11599 file_table.last_lookup_index = 0;
11602 /* Output a label to mark the beginning of a source code line entry
11603 and record information relating to this source line, in
11604 'line_info_table' for later output of the .debug_line section. */
11607 dwarf2out_source_line (line, filename)
11609 const char *filename;
11611 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11613 function_section (current_function_decl);
11615 /* If requested, emit something human-readable. */
11616 if (flag_debug_asm)
11617 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11620 if (DWARF2_ASM_LINE_DEBUG_INFO)
11622 unsigned file_num = lookup_filename (filename);
11624 /* Emit the .loc directive understood by GNU as. */
11625 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11627 /* Indicate that line number info exists. */
11628 ++line_info_table_in_use;
11630 /* Indicate that multiple line number tables exist. */
11631 if (DECL_SECTION_NAME (current_function_decl))
11632 ++separate_line_info_table_in_use;
11634 else if (DECL_SECTION_NAME (current_function_decl))
11636 dw_separate_line_info_ref line_info;
11637 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11638 separate_line_info_table_in_use);
11640 /* expand the line info table if necessary */
11641 if (separate_line_info_table_in_use
11642 == separate_line_info_table_allocated)
11644 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11645 separate_line_info_table
11646 = (dw_separate_line_info_ref)
11647 xrealloc (separate_line_info_table,
11648 separate_line_info_table_allocated
11649 * sizeof (dw_separate_line_info_entry));
11652 /* Add the new entry at the end of the line_info_table. */
11654 = &separate_line_info_table[separate_line_info_table_in_use++];
11655 line_info->dw_file_num = lookup_filename (filename);
11656 line_info->dw_line_num = line;
11657 line_info->function = current_funcdef_number;
11661 dw_line_info_ref line_info;
11663 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11664 line_info_table_in_use);
11666 /* Expand the line info table if necessary. */
11667 if (line_info_table_in_use == line_info_table_allocated)
11669 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11671 = (dw_line_info_ref)
11672 xrealloc (line_info_table,
11673 (line_info_table_allocated
11674 * sizeof (dw_line_info_entry)));
11677 /* Add the new entry at the end of the line_info_table. */
11678 line_info = &line_info_table[line_info_table_in_use++];
11679 line_info->dw_file_num = lookup_filename (filename);
11680 line_info->dw_line_num = line;
11685 /* Record the beginning of a new source file. */
11688 dwarf2out_start_source_file (lineno, filename)
11689 unsigned int lineno;
11690 const char *filename;
11692 if (flag_eliminate_dwarf2_dups)
11694 /* Record the beginning of the file for break_out_includes. */
11695 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11696 add_AT_string (bincl_die, DW_AT_name, filename);
11698 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11700 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11701 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11702 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11704 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11705 "Filename we just started");
11709 /* Record the end of a source file. */
11712 dwarf2out_end_source_file (lineno)
11713 unsigned int lineno ATTRIBUTE_UNUSED;
11715 if (flag_eliminate_dwarf2_dups)
11717 /* Record the end of the file for break_out_includes. */
11718 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11720 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11722 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11723 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11727 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11728 the tail part of the directive line, i.e. the part which is past the
11729 initial whitespace, #, whitespace, directive-name, whitespace part. */
11732 dwarf2out_define (lineno, buffer)
11733 unsigned lineno ATTRIBUTE_UNUSED;
11734 const char *buffer ATTRIBUTE_UNUSED;
11736 static int initialized = 0;
11739 dwarf2out_start_source_file (0, primary_filename);
11742 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11744 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11745 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11746 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11747 dw2_asm_output_nstring (buffer, -1, "The macro");
11751 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11752 the tail part of the directive line, i.e. the part which is past the
11753 initial whitespace, #, whitespace, directive-name, whitespace part. */
11756 dwarf2out_undef (lineno, buffer)
11757 unsigned lineno ATTRIBUTE_UNUSED;
11758 const char *buffer ATTRIBUTE_UNUSED;
11760 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11762 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11763 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11764 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11765 dw2_asm_output_nstring (buffer, -1, "The macro");
11769 /* Set up for Dwarf output at the start of compilation. */
11772 dwarf2out_init (main_input_filename)
11773 const char *main_input_filename;
11775 init_file_table ();
11777 /* Remember the name of the primary input file. */
11778 primary_filename = main_input_filename;
11780 /* Add it to the file table first, under the assumption that we'll
11781 be emitting line number data for it first, which avoids having
11782 to add an initial DW_LNS_set_file. */
11783 lookup_filename (main_input_filename);
11785 /* Allocate the initial hunk of the decl_die_table. */
11787 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11788 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11789 decl_die_table_in_use = 0;
11791 /* Allocate the initial hunk of the decl_scope_table. */
11792 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
11793 ggc_add_tree_varray_root (&decl_scope_table, 1);
11795 /* Allocate the initial hunk of the abbrev_die_table. */
11797 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11798 sizeof (dw_die_ref));
11799 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11800 /* Zero-th entry is allocated, but unused */
11801 abbrev_die_table_in_use = 1;
11803 /* Allocate the initial hunk of the line_info_table. */
11805 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11806 sizeof (dw_line_info_entry));
11807 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11808 /* Zero-th entry is allocated, but unused */
11809 line_info_table_in_use = 1;
11811 /* Generate the initial DIE for the .debug section. Note that the (string)
11812 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11813 will (typically) be a relative pathname and that this pathname should be
11814 taken as being relative to the directory from which the compiler was
11815 invoked when the given (base) source file was compiled. */
11816 comp_unit_die = gen_compile_unit_die (main_input_filename);
11818 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
11819 ggc_add_tree_varray_root (&incomplete_types, 1);
11821 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11822 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11824 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11825 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11826 DEBUG_ABBREV_SECTION_LABEL, 0);
11827 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11828 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11830 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
11831 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11832 DEBUG_INFO_SECTION_LABEL, 0);
11833 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11834 DEBUG_LINE_SECTION_LABEL, 0);
11835 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11836 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11837 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
11838 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11839 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11840 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11841 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11843 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11844 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11845 DEBUG_MACINFO_SECTION_LABEL, 0);
11846 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11849 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11852 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11856 /* Allocate a string in .debug_str hash table. */
11859 indirect_string_alloc (tab)
11860 hash_table *tab ATTRIBUTE_UNUSED;
11862 struct indirect_string_node *node;
11864 node = xmalloc (sizeof (struct indirect_string_node));
11865 node->refcount = 0;
11867 node->label = NULL;
11868 return (hashnode) node;
11871 /* A helper function for dwarf2out_finish called through
11872 ht_forall. Emit one queued .debug_str string. */
11875 output_indirect_string (pfile, h, v)
11876 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
11878 const PTR v ATTRIBUTE_UNUSED;
11880 struct indirect_string_node *node;
11882 node = (struct indirect_string_node *) h;
11883 if (node->form == DW_FORM_strp)
11885 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
11886 ASM_OUTPUT_LABEL (asm_out_file, node->label);
11887 assemble_string ((const char *) HT_STR (&node->id),
11888 HT_LEN (&node->id) + 1);
11893 /* Output stuff that dwarf requires at the end of every file,
11894 and generate the DWARF-2 debugging info. */
11897 dwarf2out_finish (input_filename)
11898 const char *input_filename ATTRIBUTE_UNUSED;
11900 limbo_die_node *node, *next_node;
11901 dw_die_ref die = 0;
11903 /* Traverse the limbo die list, and add parent/child links. The only
11904 dies without parents that should be here are concrete instances of
11905 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11906 For concrete instances, we can get the parent die from the abstract
11908 for (node = limbo_die_list; node; node = next_node)
11910 next_node = node->next;
11913 if (die->die_parent == NULL)
11915 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11917 add_child_die (origin->die_parent, die);
11918 else if (die == comp_unit_die)
11920 else if (errorcount > 0 || sorrycount > 0)
11921 /* It's OK to be confused by errors in the input. */
11922 add_child_die (comp_unit_die, die);
11928 limbo_die_list = NULL;
11930 /* Walk through the list of incomplete types again, trying once more to
11931 emit full debugging info for them. */
11932 retry_incomplete_types ();
11934 /* We need to reverse all the dies before break_out_includes, or
11935 we'll see the end of an include file before the beginning. */
11936 reverse_all_dies (comp_unit_die);
11938 /* Generate separate CUs for each of the include files we've seen.
11939 They will go into limbo_die_list. */
11940 if (flag_eliminate_dwarf2_dups)
11941 break_out_includes (comp_unit_die);
11943 /* Traverse the DIE's and add add sibling attributes to those DIE's
11944 that have children. */
11945 add_sibling_attributes (comp_unit_die);
11946 for (node = limbo_die_list; node; node = node->next)
11947 add_sibling_attributes (node->die);
11949 /* Output a terminator label for the .text section. */
11951 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11953 /* Output the source line correspondence table. We must do this
11954 even if there is no line information. Otherwise, on an empty
11955 translation unit, we will generate a present, but empty,
11956 .debug_info section. IRIX 6.5 `nm' will then complain when
11957 examining the file. */
11958 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11960 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11961 output_line_info ();
11964 /* Output location list section if necessary. */
11965 if (have_location_lists)
11967 /* Output the location lists info. */
11968 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
11969 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
11970 DEBUG_LOC_SECTION_LABEL, 0);
11971 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11972 output_location_lists (die);
11973 have_location_lists = 0;
11976 /* We can only use the low/high_pc attributes if all of the code was
11978 if (separate_line_info_table_in_use == 0)
11980 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11981 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11983 /* And if it wasn't, we need to give .debug_loc and .debug_ranges
11984 an appropriate "base address". Use zero so that these addresses
11985 become absolute. */
11986 else if (have_location_lists || ranges_table_in_use)
11987 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
11989 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11990 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11991 debug_line_section_label);
11993 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11994 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11996 /* Output all of the compilation units. We put the main one last so that
11997 the offsets are available to output_pubnames. */
11998 for (node = limbo_die_list; node; node = node->next)
11999 output_comp_unit (node->die);
12000 output_comp_unit (comp_unit_die);
12002 /* Output the abbreviation table. */
12003 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12004 output_abbrev_section ();
12006 if (pubname_table_in_use)
12008 /* Output public names table. */
12009 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12010 output_pubnames ();
12013 /* We only put functions in the arange table, so don't write it out if
12014 we don't have any. */
12015 if (fde_table_in_use)
12017 /* Output the address range information. */
12018 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12022 /* Output ranges section if necessary. */
12023 if (ranges_table_in_use)
12025 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12029 /* Have to end the primary source file. */
12030 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12032 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12033 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12036 /* If we emitted any DW_FORM_strp form attribute, output string
12038 if (debug_str_hash)
12039 ht_forall (debug_str_hash, output_indirect_string, NULL);
12041 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */