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 GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
61 /* DWARF2 Abbreviation Glossary:
62 CFA = Canonical Frame Address
63 a fixed address on the stack which identifies a call frame.
64 We define it to be the value of SP just before the call insn.
65 The CFA register and offset, which may change during the course
66 of the function, are used to calculate its value at runtime.
67 CFI = Call Frame Instruction
68 an instruction for the DWARF2 abstract machine
69 CIE = Common Information Entry
70 information describing information common to one or more FDEs
71 DIE = Debugging Information Entry
72 FDE = Frame Description Entry
73 information describing the stack call frame, in particular,
74 how to restore registers
76 DW_CFA_... = DWARF2 CFA call frame instruction
77 DW_TAG_... = DWARF2 DIE tag */
79 /* Decide whether we want to emit frame unwind information for the current
85 return (write_symbols == DWARF2_DEBUG
86 #ifdef DWARF2_FRAME_INFO
89 #ifdef DWARF2_UNWIND_INFO
91 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
96 /* The number of the current function definition for which debugging
97 information is being generated. These numbers range from 1 up to the
98 maximum number of function definitions contained within the current
99 compilation unit. These numbers are used to create unique label id's
100 unique to each function definition. */
101 unsigned current_funcdef_number = 0;
103 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
105 /* How to start an assembler comment. */
106 #ifndef ASM_COMMENT_START
107 #define ASM_COMMENT_START ";#"
110 typedef struct dw_cfi_struct *dw_cfi_ref;
111 typedef struct dw_fde_struct *dw_fde_ref;
112 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
114 /* Call frames are described using a sequence of Call Frame
115 Information instructions. The register number, offset
116 and address fields are provided as possible operands;
117 their use is selected by the opcode field. */
119 typedef union dw_cfi_oprnd_struct
121 unsigned long dw_cfi_reg_num;
122 long int dw_cfi_offset;
123 const char *dw_cfi_addr;
124 struct dw_loc_descr_struct *dw_cfi_loc;
128 typedef struct dw_cfi_struct
130 dw_cfi_ref dw_cfi_next;
131 enum dwarf_call_frame_info dw_cfi_opc;
132 dw_cfi_oprnd dw_cfi_oprnd1;
133 dw_cfi_oprnd dw_cfi_oprnd2;
137 /* This is how we define the location of the CFA. We use to handle it
138 as REG + OFFSET all the time, but now it can be more complex.
139 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
140 Instead of passing around REG and OFFSET, we pass a copy
141 of this structure. */
142 typedef struct cfa_loc
147 int indirect; /* 1 if CFA is accessed via a dereference. */
150 /* All call frame descriptions (FDE's) in the GCC generated DWARF
151 refer to a single Common Information Entry (CIE), defined at
152 the beginning of the .debug_frame section. This used of a single
153 CIE obviates the need to keep track of multiple CIE's
154 in the DWARF generation routines below. */
156 typedef struct dw_fde_struct
158 const char *dw_fde_begin;
159 const char *dw_fde_current_label;
160 const char *dw_fde_end;
161 dw_cfi_ref dw_fde_cfi;
162 unsigned funcdef_number;
163 unsigned nothrow : 1;
164 unsigned uses_eh_lsda : 1;
168 /* Maximum size (in bytes) of an artificially generated label. */
169 #define MAX_ARTIFICIAL_LABEL_BYTES 30
171 /* The size of the target's pointer type. */
173 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
176 /* The size of addresses as they appear in the Dwarf 2 data.
177 Some architectures use word addresses to refer to code locations,
178 but Dwarf 2 info always uses byte addresses. On such machines,
179 Dwarf 2 addresses need to be larger than the architecture's
181 #ifndef DWARF2_ADDR_SIZE
182 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
185 /* The size in bytes of a DWARF field indicating an offset or length
186 relative to a debug info section, specified to be 4 bytes in the
187 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
190 #ifndef DWARF_OFFSET_SIZE
191 #define DWARF_OFFSET_SIZE 4
194 #define DWARF_VERSION 2
196 /* Round SIZE up to the nearest BOUNDARY. */
197 #define DWARF_ROUND(SIZE,BOUNDARY) \
198 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
200 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
201 #ifndef DWARF_CIE_DATA_ALIGNMENT
202 #ifdef STACK_GROWS_DOWNWARD
203 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
205 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
207 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
209 /* A pointer to the base of a table that contains frame description
210 information for each routine. */
211 static dw_fde_ref fde_table;
213 /* Number of elements currently allocated for fde_table. */
214 static unsigned fde_table_allocated;
216 /* Number of elements in fde_table currently in use. */
217 static unsigned fde_table_in_use;
219 /* Size (in elements) of increments by which we may expand the
221 #define FDE_TABLE_INCREMENT 256
223 /* A list of call frame insns for the CIE. */
224 static dw_cfi_ref cie_cfi_head;
226 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
227 attribute that accelerates the lookup of the FDE associated
228 with the subprogram. This variable holds the table index of the FDE
229 associated with the current function (body) definition. */
230 static unsigned current_funcdef_fde;
232 /* Forward declarations for functions defined in this file. */
234 static char *stripattributes PARAMS ((const char *));
235 static const char *dwarf_cfi_name PARAMS ((unsigned));
236 static dw_cfi_ref new_cfi PARAMS ((void));
237 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
238 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
239 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
240 static void lookup_cfa PARAMS ((dw_cfa_location *));
241 static void reg_save PARAMS ((const char *, unsigned,
243 static void initial_return_save PARAMS ((rtx));
244 static long stack_adjust_offset PARAMS ((rtx));
245 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
246 static void output_call_frame_info PARAMS ((int));
247 static void dwarf2out_stack_adjust PARAMS ((rtx));
248 static void queue_reg_save PARAMS ((const char *, rtx, long));
249 static void flush_queued_reg_saves PARAMS ((void));
250 static bool clobbers_queued_reg_save PARAMS ((rtx));
251 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
253 /* Support for complex CFA locations. */
254 static void output_cfa_loc PARAMS ((dw_cfi_ref));
255 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
256 struct dw_loc_descr_struct *));
257 static struct dw_loc_descr_struct *build_cfa_loc
258 PARAMS ((dw_cfa_location *));
259 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
261 /* How to start an assembler comment. */
262 #ifndef ASM_COMMENT_START
263 #define ASM_COMMENT_START ";#"
266 /* Data and reference forms for relocatable data. */
267 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
268 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
270 /* Pseudo-op for defining a new section. */
271 #ifndef SECTION_ASM_OP
272 #define SECTION_ASM_OP "\t.section\t"
275 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
276 print the SECTION_ASM_OP and the section name. The default here works for
277 almost all svr4 assemblers, except for the sparc, where the section name
278 must be enclosed in double quotes. (See sparcv4.h). */
279 #ifndef SECTION_FORMAT
280 #ifdef PUSHSECTION_FORMAT
281 #define SECTION_FORMAT PUSHSECTION_FORMAT
283 #define SECTION_FORMAT "%s%s\n"
287 #ifndef DEBUG_FRAME_SECTION
288 #define DEBUG_FRAME_SECTION ".debug_frame"
291 #ifndef FUNC_BEGIN_LABEL
292 #define FUNC_BEGIN_LABEL "LFB"
294 #ifndef FUNC_END_LABEL
295 #define FUNC_END_LABEL "LFE"
297 #define CIE_AFTER_SIZE_LABEL "LSCIE"
298 #define CIE_END_LABEL "LECIE"
299 #define CIE_LENGTH_LABEL "LLCIE"
300 #define FDE_LABEL "LSFDE"
301 #define FDE_AFTER_SIZE_LABEL "LASFDE"
302 #define FDE_END_LABEL "LEFDE"
303 #define FDE_LENGTH_LABEL "LLFDE"
304 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
305 #define LINE_NUMBER_END_LABEL "LELT"
306 #define LN_PROLOG_AS_LABEL "LASLTP"
307 #define LN_PROLOG_END_LABEL "LELTP"
308 #define DIE_LABEL_PREFIX "DW"
310 /* Definitions of defaults for various types of primitive assembly language
311 output operations. These may be overridden from within the tm.h file,
312 but typically, that is unnecessary. */
314 #ifndef ASM_OUTPUT_SECTION
315 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
316 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
320 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
321 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
323 fprintf (FILE, "%s", SET_ASM_OP); \
324 assemble_name (FILE, SY); \
326 assemble_name (FILE, HI); \
328 assemble_name (FILE, LO); \
331 #endif /* SET_ASM_OP */
333 /* The DWARF 2 CFA column which tracks the return address. Normally this
334 is the column for PC, or the first column after all of the hard
336 #ifndef DWARF_FRAME_RETURN_COLUMN
338 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
340 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
344 /* The mapping from gcc register number to DWARF 2 CFA column number. By
345 default, we just provide columns for all registers. */
346 #ifndef DWARF_FRAME_REGNUM
347 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
350 /* Hook used by __throw. */
353 expand_builtin_dwarf_fp_regnum ()
355 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
358 /* The offset from the incoming value of %sp to the top of the stack frame
359 for the current function. */
360 #ifndef INCOMING_FRAME_SP_OFFSET
361 #define INCOMING_FRAME_SP_OFFSET 0
364 /* Return a pointer to a copy of the section string name S with all
365 attributes stripped off, and an asterisk prepended (for assemble_name). */
371 char *stripped = xmalloc (strlen (s) + 2);
376 while (*s && *s != ',')
383 /* Generate code to initialize the register size table. */
386 expand_builtin_init_dwarf_reg_sizes (address)
390 enum machine_mode mode = TYPE_MODE (char_type_node);
391 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
392 rtx mem = gen_rtx_MEM (mode, addr);
394 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
396 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
397 int size = GET_MODE_SIZE (reg_raw_mode[i]);
402 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
406 /* Convert a DWARF call frame info. operation to its string name */
409 dwarf_cfi_name (cfi_opc)
410 register unsigned cfi_opc;
414 case DW_CFA_advance_loc:
415 return "DW_CFA_advance_loc";
417 return "DW_CFA_offset";
419 return "DW_CFA_restore";
423 return "DW_CFA_set_loc";
424 case DW_CFA_advance_loc1:
425 return "DW_CFA_advance_loc1";
426 case DW_CFA_advance_loc2:
427 return "DW_CFA_advance_loc2";
428 case DW_CFA_advance_loc4:
429 return "DW_CFA_advance_loc4";
430 case DW_CFA_offset_extended:
431 return "DW_CFA_offset_extended";
432 case DW_CFA_restore_extended:
433 return "DW_CFA_restore_extended";
434 case DW_CFA_undefined:
435 return "DW_CFA_undefined";
436 case DW_CFA_same_value:
437 return "DW_CFA_same_value";
438 case DW_CFA_register:
439 return "DW_CFA_register";
440 case DW_CFA_remember_state:
441 return "DW_CFA_remember_state";
442 case DW_CFA_restore_state:
443 return "DW_CFA_restore_state";
445 return "DW_CFA_def_cfa";
446 case DW_CFA_def_cfa_register:
447 return "DW_CFA_def_cfa_register";
448 case DW_CFA_def_cfa_offset:
449 return "DW_CFA_def_cfa_offset";
450 case DW_CFA_def_cfa_expression:
451 return "DW_CFA_def_cfa_expression";
453 /* SGI/MIPS specific */
454 case DW_CFA_MIPS_advance_loc8:
455 return "DW_CFA_MIPS_advance_loc8";
458 case DW_CFA_GNU_window_save:
459 return "DW_CFA_GNU_window_save";
460 case DW_CFA_GNU_args_size:
461 return "DW_CFA_GNU_args_size";
462 case DW_CFA_GNU_negative_offset_extended:
463 return "DW_CFA_GNU_negative_offset_extended";
466 return "DW_CFA_<unknown>";
470 /* Return a pointer to a newly allocated Call Frame Instruction. */
472 static inline dw_cfi_ref
475 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
477 cfi->dw_cfi_next = NULL;
478 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
479 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
484 /* Add a Call Frame Instruction to list of instructions. */
487 add_cfi (list_head, cfi)
488 register dw_cfi_ref *list_head;
489 register dw_cfi_ref cfi;
491 register dw_cfi_ref *p;
493 /* Find the end of the chain. */
494 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
500 /* Generate a new label for the CFI info to refer to. */
503 dwarf2out_cfi_label ()
505 static char label[20];
506 static unsigned long label_num = 0;
508 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
509 ASM_OUTPUT_LABEL (asm_out_file, label);
514 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
515 or to the CIE if LABEL is NULL. */
518 add_fde_cfi (label, cfi)
519 register const char *label;
520 register dw_cfi_ref cfi;
524 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
527 label = dwarf2out_cfi_label ();
529 if (fde->dw_fde_current_label == NULL
530 || strcmp (label, fde->dw_fde_current_label) != 0)
532 register dw_cfi_ref xcfi;
534 fde->dw_fde_current_label = label = xstrdup (label);
536 /* Set the location counter to the new label. */
538 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
539 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
540 add_cfi (&fde->dw_fde_cfi, xcfi);
543 add_cfi (&fde->dw_fde_cfi, cfi);
547 add_cfi (&cie_cfi_head, cfi);
550 /* Subroutine of lookup_cfa. */
553 lookup_cfa_1 (cfi, loc)
554 register dw_cfi_ref cfi;
555 register dw_cfa_location *loc;
557 switch (cfi->dw_cfi_opc)
559 case DW_CFA_def_cfa_offset:
560 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
562 case DW_CFA_def_cfa_register:
563 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
566 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
567 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
569 case DW_CFA_def_cfa_expression:
570 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
577 /* Find the previous value for the CFA. */
581 register dw_cfa_location *loc;
583 register dw_cfi_ref cfi;
585 loc->reg = (unsigned long) -1;
588 loc->base_offset = 0;
590 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
591 lookup_cfa_1 (cfi, loc);
593 if (fde_table_in_use)
595 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
596 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
597 lookup_cfa_1 (cfi, loc);
601 /* The current rule for calculating the DWARF2 canonical frame address. */
602 static dw_cfa_location cfa;
604 /* The register used for saving registers to the stack, and its offset
606 static dw_cfa_location cfa_store;
608 /* The running total of the size of arguments pushed onto the stack. */
609 static long args_size;
611 /* The last args_size we actually output. */
612 static long old_args_size;
614 /* Entry point to update the canonical frame address (CFA).
615 LABEL is passed to add_fde_cfi. The value of CFA is now to be
616 calculated from REG+OFFSET. */
619 dwarf2out_def_cfa (label, reg, offset)
620 register const char *label;
629 def_cfa_1 (label, &loc);
632 /* This routine does the actual work. The CFA is now calculated from
633 the dw_cfa_location structure. */
635 def_cfa_1 (label, loc_p)
636 register const char *label;
637 dw_cfa_location *loc_p;
639 register dw_cfi_ref cfi;
640 dw_cfa_location old_cfa, loc;
645 if (cfa_store.reg == loc.reg && loc.indirect == 0)
646 cfa_store.offset = loc.offset;
648 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
649 lookup_cfa (&old_cfa);
651 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
652 loc.indirect == old_cfa.indirect)
654 if (loc.indirect == 0
655 || loc.base_offset == old_cfa.base_offset)
656 /* Nothing changed so no need to issue any call frame
663 if (loc.reg == old_cfa.reg && !loc.indirect)
665 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
666 indicating the CFA register did not change but the offset
668 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
669 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
672 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
673 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
676 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
677 indicating the CFA register has changed to <register> but the
678 offset has not changed. */
679 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
680 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
684 else if (loc.indirect == 0)
686 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
687 indicating the CFA register has changed to <register> with
688 the specified offset. */
689 cfi->dw_cfi_opc = DW_CFA_def_cfa;
690 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
691 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
695 /* Construct a DW_CFA_def_cfa_expression instruction to
696 calculate the CFA using a full location expression since no
697 register-offset pair is available. */
698 struct dw_loc_descr_struct *loc_list;
699 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
700 loc_list = build_cfa_loc (&loc);
701 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
704 add_fde_cfi (label, cfi);
707 /* Add the CFI for saving a register. REG is the CFA column number.
708 LABEL is passed to add_fde_cfi.
709 If SREG is -1, the register is saved at OFFSET from the CFA;
710 otherwise it is saved in SREG. */
713 reg_save (label, reg, sreg, offset)
714 register const char *label;
715 register unsigned reg;
716 register unsigned sreg;
717 register long offset;
719 register dw_cfi_ref cfi = new_cfi ();
721 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
723 /* The following comparison is correct. -1 is used to indicate that
724 the value isn't a register number. */
725 if (sreg == (unsigned int) -1)
728 /* The register number won't fit in 6 bits, so we have to use
730 cfi->dw_cfi_opc = DW_CFA_offset_extended;
732 cfi->dw_cfi_opc = DW_CFA_offset;
734 #ifdef ENABLE_CHECKING
736 /* If we get an offset that is not a multiple of
737 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
738 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
740 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
742 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
746 offset /= DWARF_CIE_DATA_ALIGNMENT;
749 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
752 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
754 else if (sreg == reg)
755 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
759 cfi->dw_cfi_opc = DW_CFA_register;
760 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
763 add_fde_cfi (label, cfi);
766 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
767 This CFI tells the unwinder that it needs to restore the window registers
768 from the previous frame's window save area.
770 ??? Perhaps we should note in the CIE where windows are saved (instead of
771 assuming 0(cfa)) and what registers are in the window. */
774 dwarf2out_window_save (label)
775 register const char *label;
777 register dw_cfi_ref cfi = new_cfi ();
778 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
779 add_fde_cfi (label, cfi);
782 /* Add a CFI to update the running total of the size of arguments
783 pushed onto the stack. */
786 dwarf2out_args_size (label, size)
790 register dw_cfi_ref cfi;
792 if (size == old_args_size)
794 old_args_size = size;
797 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
798 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
799 add_fde_cfi (label, cfi);
802 /* Entry point for saving a register to the stack. REG is the GCC register
803 number. LABEL and OFFSET are passed to reg_save. */
806 dwarf2out_reg_save (label, reg, offset)
807 register const char *label;
808 register unsigned reg;
809 register long offset;
811 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
814 /* Entry point for saving the return address in the stack.
815 LABEL and OFFSET are passed to reg_save. */
818 dwarf2out_return_save (label, offset)
819 register const char *label;
820 register long offset;
822 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
825 /* Entry point for saving the return address in a register.
826 LABEL and SREG are passed to reg_save. */
829 dwarf2out_return_reg (label, sreg)
830 register const char *label;
831 register unsigned sreg;
833 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
836 /* Record the initial position of the return address. RTL is
837 INCOMING_RETURN_ADDR_RTX. */
840 initial_return_save (rtl)
843 unsigned int reg = (unsigned int) -1;
846 switch (GET_CODE (rtl))
849 /* RA is in a register. */
850 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
853 /* RA is on the stack. */
855 switch (GET_CODE (rtl))
858 if (REGNO (rtl) != STACK_POINTER_REGNUM)
863 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
865 offset = INTVAL (XEXP (rtl, 1));
868 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
870 offset = -INTVAL (XEXP (rtl, 1));
877 /* The return address is at some offset from any value we can
878 actually load. For instance, on the SPARC it is in %i7+8. Just
879 ignore the offset for now; it doesn't matter for unwinding frames. */
880 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
882 initial_return_save (XEXP (rtl, 0));
888 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
891 /* Given a SET, calculate the amount of stack adjustment it
895 stack_adjust_offset (pattern)
898 rtx src = SET_SRC (pattern);
899 rtx dest = SET_DEST (pattern);
903 if (dest == stack_pointer_rtx)
905 /* (set (reg sp) (plus (reg sp) (const_int))) */
906 code = GET_CODE (src);
907 if (! (code == PLUS || code == MINUS)
908 || XEXP (src, 0) != stack_pointer_rtx
909 || GET_CODE (XEXP (src, 1)) != CONST_INT)
912 offset = INTVAL (XEXP (src, 1));
914 else if (GET_CODE (dest) == MEM)
916 /* (set (mem (pre_dec (reg sp))) (foo)) */
917 src = XEXP (dest, 0);
918 code = GET_CODE (src);
920 if (! (code == PRE_DEC || code == PRE_INC
921 || code == PRE_MODIFY)
922 || XEXP (src, 0) != stack_pointer_rtx)
925 if (code == PRE_MODIFY)
927 rtx val = XEXP (XEXP (src, 1), 1);
928 /* We handle only adjustments by constant amount. */
929 if (GET_CODE (XEXP (src, 1)) != PLUS ||
930 GET_CODE (val) != CONST_INT)
932 offset = -INTVAL (val);
934 else offset = GET_MODE_SIZE (GET_MODE (dest));
939 if (code == PLUS || code == PRE_INC)
945 /* Check INSN to see if it looks like a push or a stack adjustment, and
946 make a note of it if it does. EH uses this information to find out how
947 much extra space it needs to pop off the stack. */
950 dwarf2out_stack_adjust (insn)
956 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
958 /* Extract the size of the args from the CALL rtx itself. */
960 insn = PATTERN (insn);
961 if (GET_CODE (insn) == PARALLEL)
962 insn = XVECEXP (insn, 0, 0);
963 if (GET_CODE (insn) == SET)
964 insn = SET_SRC (insn);
965 if (GET_CODE (insn) != CALL)
967 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
971 /* If only calls can throw, and we have a frame pointer,
972 save up adjustments until we see the CALL_INSN. */
973 else if (! flag_non_call_exceptions
974 && cfa.reg != STACK_POINTER_REGNUM)
977 if (GET_CODE (insn) == BARRIER)
979 /* When we see a BARRIER, we know to reset args_size to 0. Usually
980 the compiler will have already emitted a stack adjustment, but
981 doesn't bother for calls to noreturn functions. */
982 #ifdef STACK_GROWS_DOWNWARD
988 else if (GET_CODE (PATTERN (insn)) == SET)
990 offset = stack_adjust_offset (PATTERN (insn));
992 else if (GET_CODE (PATTERN (insn)) == PARALLEL
993 || GET_CODE (PATTERN (insn)) == SEQUENCE)
995 /* There may be stack adjustments inside compound insns. Search
1000 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1002 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1003 if (GET_CODE (pattern) == SET)
1004 offset += stack_adjust_offset (pattern);
1013 if (cfa.reg == STACK_POINTER_REGNUM)
1014 cfa.offset += offset;
1016 #ifndef STACK_GROWS_DOWNWARD
1019 args_size += offset;
1023 label = dwarf2out_cfi_label ();
1024 def_cfa_1 (label, &cfa);
1025 dwarf2out_args_size (label, args_size);
1028 /* We delay emitting a register save until either (a) we reach the end
1029 of the prologue or (b) the register is clobbered. This clusters
1030 register saves so that there are fewer pc advances. */
1032 struct queued_reg_save
1034 struct queued_reg_save *next;
1039 static struct queued_reg_save *queued_reg_saves;
1040 static const char *last_reg_save_label;
1043 queue_reg_save (label, reg, offset)
1048 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1050 q->next = queued_reg_saves;
1052 q->cfa_offset = offset;
1053 queued_reg_saves = q;
1055 last_reg_save_label = label;
1059 flush_queued_reg_saves ()
1061 struct queued_reg_save *q, *next;
1063 for (q = queued_reg_saves; q ; q = next)
1065 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1070 queued_reg_saves = NULL;
1071 last_reg_save_label = NULL;
1075 clobbers_queued_reg_save (insn)
1078 struct queued_reg_save *q;
1080 for (q = queued_reg_saves; q ; q = q->next)
1081 if (modified_in_p (q->reg, insn))
1088 /* A temporary register holding an integral value used in adjusting SP
1089 or setting up the store_reg. The "offset" field holds the integer
1090 value, not an offset. */
1091 static dw_cfa_location cfa_temp;
1093 /* Record call frame debugging information for an expression EXPR,
1094 which either sets SP or FP (adjusting how we calculate the frame
1095 address) or saves a register to the stack. LABEL indicates the
1098 This function encodes a state machine mapping rtxes to actions on
1099 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1100 users need not read the source code.
1102 The High-Level Picture
1104 Changes in the register we use to calculate the CFA: Currently we
1105 assume that if you copy the CFA register into another register, we
1106 should take the other one as the new CFA register; this seems to
1107 work pretty well. If it's wrong for some target, it's simple
1108 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1110 Changes in the register we use for saving registers to the stack:
1111 This is usually SP, but not always. Again, we deduce that if you
1112 copy SP into another register (and SP is not the CFA register),
1113 then the new register is the one we will be using for register
1114 saves. This also seems to work.
1116 Register saves: There's not much guesswork about this one; if
1117 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1118 register save, and the register used to calculate the destination
1119 had better be the one we think we're using for this purpose.
1121 Except: If the register being saved is the CFA register, and the
1122 offset is non-zero, we are saving the CFA, so we assume we have to
1123 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1124 the intent is to save the value of SP from the previous frame.
1126 Invariants / Summaries of Rules
1128 cfa current rule for calculating the CFA. It usually
1129 consists of a register and an offset.
1130 cfa_store register used by prologue code to save things to the stack
1131 cfa_store.offset is the offset from the value of
1132 cfa_store.reg to the actual CFA
1133 cfa_temp register holding an integral value. cfa_temp.offset
1134 stores the value, which will be used to adjust the
1135 stack pointer. cfa_temp is also used like cfa_store,
1136 to track stores to the stack via fp or a temp reg.
1138 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1139 with cfa.reg as the first operand changes the cfa.reg and its
1140 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1143 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1144 expression yielding a constant. This sets cfa_temp.reg
1145 and cfa_temp.offset.
1147 Rule 5: Create a new register cfa_store used to save items to the
1150 Rules 10-14: Save a register to the stack. Define offset as the
1151 difference of the original location and cfa_store's
1152 location (or cfa_temp's location if cfa_temp is used).
1156 "{a,b}" indicates a choice of a xor b.
1157 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1160 (set <reg1> <reg2>:cfa.reg)
1161 effects: cfa.reg = <reg1>
1162 cfa.offset unchanged
1163 cfa_temp.reg = <reg1>
1164 cfa_temp.offset = cfa.offset
1167 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1168 effects: cfa.reg = sp if fp used
1169 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1170 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1171 if cfa_store.reg==sp
1174 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1175 effects: cfa.reg = fp
1176 cfa_offset += +/- <const_int>
1179 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1180 constraints: <reg1> != fp
1182 effects: cfa.reg = <reg1>
1183 cfa_temp.reg = <reg1>
1184 cfa_temp.offset = cfa.offset
1187 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1188 constraints: <reg1> != fp
1190 effects: cfa_store.reg = <reg1>
1191 cfa_store.offset = cfa.offset - cfa_temp.offset
1194 (set <reg> <const_int>)
1195 effects: cfa_temp.reg = <reg>
1196 cfa_temp.offset = <const_int>
1199 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1200 effects: cfa_temp.reg = <reg1>
1201 cfa_temp.offset |= <const_int>
1204 (set <reg> (high <exp>))
1208 (set <reg> (lo_sum <exp> <const_int>))
1209 effects: cfa_temp.reg = <reg>
1210 cfa_temp.offset = <const_int>
1213 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1214 effects: cfa_store.offset -= <const_int>
1215 cfa.offset = cfa_store.offset if cfa.reg == sp
1217 cfa.base_offset = -cfa_store.offset
1220 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1221 effects: cfa_store.offset += -/+ mode_size(mem)
1222 cfa.offset = cfa_store.offset if cfa.reg == sp
1224 cfa.base_offset = -cfa_store.offset
1227 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1228 effects: cfa.reg = <reg1>
1229 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1232 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1233 effects: cfa.reg = <reg1>
1234 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1237 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1238 effects: cfa.reg = <reg1>
1239 cfa.base_offset = -cfa_temp.offset
1240 cfa_temp.offset -= mode_size(mem) */
1243 dwarf2out_frame_debug_expr (expr, label)
1250 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1251 the PARALLEL independently. The first element is always processed if
1252 it is a SET. This is for backward compatibility. Other elements
1253 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1254 flag is set in them. */
1256 if (GET_CODE (expr) == PARALLEL
1257 || GET_CODE (expr) == SEQUENCE)
1260 int limit = XVECLEN (expr, 0);
1262 for (par_index = 0; par_index < limit; par_index++)
1264 rtx x = XVECEXP (expr, 0, par_index);
1266 if (GET_CODE (x) == SET &&
1267 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1268 dwarf2out_frame_debug_expr (x, label);
1273 if (GET_CODE (expr) != SET)
1276 src = SET_SRC (expr);
1277 dest = SET_DEST (expr);
1279 switch (GET_CODE (dest))
1283 /* Update the CFA rule wrt SP or FP. Make sure src is
1284 relative to the current CFA register. */
1285 switch (GET_CODE (src))
1287 /* Setting FP from SP. */
1289 if (cfa.reg == (unsigned) REGNO (src))
1295 /* We used to require that dest be either SP or FP, but the
1296 ARM copies SP to a temporary register, and from there to
1297 FP. So we just rely on the backends to only set
1298 RTX_FRAME_RELATED_P on appropriate insns. */
1299 cfa.reg = REGNO (dest);
1300 cfa_temp.reg = cfa.reg;
1301 cfa_temp.offset = cfa.offset;
1307 if (dest == stack_pointer_rtx)
1311 switch (GET_CODE (XEXP (src, 1)))
1314 offset = INTVAL (XEXP (src, 1));
1317 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1319 offset = cfa_temp.offset;
1325 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1327 /* Restoring SP from FP in the epilogue. */
1328 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1330 cfa.reg = STACK_POINTER_REGNUM;
1332 else if (GET_CODE (src) == LO_SUM)
1333 /* Assume we've set the source reg of the LO_SUM from sp. */
1335 else if (XEXP (src, 0) != stack_pointer_rtx)
1338 if (GET_CODE (src) != MINUS)
1340 if (cfa.reg == STACK_POINTER_REGNUM)
1341 cfa.offset += offset;
1342 if (cfa_store.reg == STACK_POINTER_REGNUM)
1343 cfa_store.offset += offset;
1345 else if (dest == hard_frame_pointer_rtx)
1348 /* Either setting the FP from an offset of the SP,
1349 or adjusting the FP */
1350 if (! frame_pointer_needed)
1353 if (GET_CODE (XEXP (src, 0)) == REG
1354 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1355 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1357 offset = INTVAL (XEXP (src, 1));
1358 if (GET_CODE (src) != MINUS)
1360 cfa.offset += offset;
1361 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1368 if (GET_CODE (src) == MINUS)
1372 if (GET_CODE (XEXP (src, 0)) == REG
1373 && REGNO (XEXP (src, 0)) == cfa.reg
1374 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1376 /* Setting a temporary CFA register that will be copied
1377 into the FP later on. */
1378 offset = - INTVAL (XEXP (src, 1));
1379 cfa.offset += offset;
1380 cfa.reg = REGNO (dest);
1381 /* Or used to save regs to the stack. */
1382 cfa_temp.reg = cfa.reg;
1383 cfa_temp.offset = cfa.offset;
1386 else if (GET_CODE (XEXP (src, 0)) == REG
1387 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1388 && XEXP (src, 1) == stack_pointer_rtx)
1390 /* Setting a scratch register that we will use instead
1391 of SP for saving registers to the stack. */
1392 if (cfa.reg != STACK_POINTER_REGNUM)
1394 cfa_store.reg = REGNO (dest);
1395 cfa_store.offset = cfa.offset - cfa_temp.offset;
1398 else if (GET_CODE (src) == LO_SUM
1399 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1401 cfa_temp.reg = REGNO (dest);
1402 cfa_temp.offset = INTVAL (XEXP (src, 1));
1411 cfa_temp.reg = REGNO (dest);
1412 cfa_temp.offset = INTVAL (src);
1417 if (GET_CODE (XEXP (src, 0)) != REG
1418 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1419 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1421 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1422 cfa_temp.reg = REGNO (dest);
1423 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1426 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1427 which will fill in all of the bits. */
1435 def_cfa_1 (label, &cfa);
1439 if (GET_CODE (src) != REG)
1442 /* Saving a register to the stack. Make sure dest is relative to the
1444 switch (GET_CODE (XEXP (dest, 0)))
1449 /* We can't handle variable size modifications. */
1450 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1452 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1454 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1455 || cfa_store.reg != STACK_POINTER_REGNUM)
1457 cfa_store.offset += offset;
1458 if (cfa.reg == STACK_POINTER_REGNUM)
1459 cfa.offset = cfa_store.offset;
1461 offset = -cfa_store.offset;
1466 offset = GET_MODE_SIZE (GET_MODE (dest));
1467 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1470 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1471 || cfa_store.reg != STACK_POINTER_REGNUM)
1473 cfa_store.offset += offset;
1474 if (cfa.reg == STACK_POINTER_REGNUM)
1475 cfa.offset = cfa_store.offset;
1477 offset = -cfa_store.offset;
1481 /* With an offset. */
1485 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1487 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1488 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1491 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1492 offset -= cfa_store.offset;
1493 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1494 offset -= cfa_temp.offset;
1500 /* Without an offset. */
1502 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1503 offset = -cfa_store.offset;
1504 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1505 offset = -cfa_temp.offset;
1512 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1514 offset = -cfa_temp.offset;
1515 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1522 if (REGNO (src) != STACK_POINTER_REGNUM
1523 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1524 && (unsigned) REGNO (src) == cfa.reg)
1526 /* We're storing the current CFA reg into the stack. */
1528 if (cfa.offset == 0)
1530 /* If the source register is exactly the CFA, assume
1531 we're saving SP like any other register; this happens
1534 def_cfa_1 (label, &cfa);
1535 queue_reg_save (label, stack_pointer_rtx, offset);
1540 /* Otherwise, we'll need to look in the stack to
1541 calculate the CFA. */
1543 rtx x = XEXP (dest, 0);
1544 if (GET_CODE (x) != REG)
1546 if (GET_CODE (x) != REG)
1548 cfa.reg = (unsigned) REGNO (x);
1549 cfa.base_offset = offset;
1551 def_cfa_1 (label, &cfa);
1556 def_cfa_1 (label, &cfa);
1557 queue_reg_save (label, src, offset);
1565 /* Record call frame debugging information for INSN, which either
1566 sets SP or FP (adjusting how we calculate the frame address) or saves a
1567 register to the stack. If INSN is NULL_RTX, initialize our state. */
1570 dwarf2out_frame_debug (insn)
1576 if (insn == NULL_RTX)
1578 /* Flush any queued register saves. */
1579 flush_queued_reg_saves ();
1581 /* Set up state for generating call frame debug info. */
1583 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1585 cfa.reg = STACK_POINTER_REGNUM;
1588 cfa_temp.offset = 0;
1592 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1593 flush_queued_reg_saves ();
1595 if (! RTX_FRAME_RELATED_P (insn))
1597 if (!ACCUMULATE_OUTGOING_ARGS)
1598 dwarf2out_stack_adjust (insn);
1602 label = dwarf2out_cfi_label ();
1604 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1606 insn = XEXP (src, 0);
1608 insn = PATTERN (insn);
1610 dwarf2out_frame_debug_expr (insn, label);
1613 /* Output a Call Frame Information opcode and its operand(s). */
1616 output_cfi (cfi, fde, for_eh)
1617 register dw_cfi_ref cfi;
1618 register dw_fde_ref fde;
1621 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1623 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1624 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1625 "DW_CFA_advance_loc 0x%lx",
1626 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1628 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1630 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1631 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1632 "DW_CFA_offset, column 0x%lx",
1633 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1634 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1636 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1638 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1639 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1640 "DW_CFA_restore, column 0x%lx",
1641 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1645 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1646 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1648 switch (cfi->dw_cfi_opc)
1650 case DW_CFA_set_loc:
1652 dw2_asm_output_encoded_addr_rtx (
1653 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1654 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1657 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1658 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1660 case DW_CFA_advance_loc1:
1661 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1662 fde->dw_fde_current_label, NULL);
1663 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1665 case DW_CFA_advance_loc2:
1666 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1667 fde->dw_fde_current_label, NULL);
1668 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1670 case DW_CFA_advance_loc4:
1671 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1672 fde->dw_fde_current_label, NULL);
1673 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1675 case DW_CFA_MIPS_advance_loc8:
1676 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1677 fde->dw_fde_current_label, NULL);
1678 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1680 case DW_CFA_offset_extended:
1681 case DW_CFA_GNU_negative_offset_extended:
1682 case DW_CFA_def_cfa:
1683 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1684 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1686 case DW_CFA_restore_extended:
1687 case DW_CFA_undefined:
1688 case DW_CFA_same_value:
1689 case DW_CFA_def_cfa_register:
1690 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1692 case DW_CFA_register:
1693 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1694 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1696 case DW_CFA_def_cfa_offset:
1697 case DW_CFA_GNU_args_size:
1698 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1700 case DW_CFA_GNU_window_save:
1702 case DW_CFA_def_cfa_expression:
1703 output_cfa_loc (cfi);
1711 /* Output the call frame information used to used to record information
1712 that relates to calculating the frame pointer, and records the
1713 location of saved registers. */
1716 output_call_frame_info (for_eh)
1719 register unsigned long i;
1720 register dw_fde_ref fde;
1721 register dw_cfi_ref cfi;
1722 char l1[20], l2[20];
1723 int any_lsda_needed = 0;
1724 char augmentation[6];
1725 int augmentation_size;
1726 int fde_encoding = DW_EH_PE_absptr;
1727 int per_encoding = DW_EH_PE_absptr;
1728 int lsda_encoding = DW_EH_PE_absptr;
1730 /* If we don't have any functions we'll want to unwind out of, don't
1731 emit any EH unwind information. */
1734 int any_eh_needed = 0;
1735 for (i = 0; i < fde_table_in_use; ++i)
1736 if (fde_table[i].uses_eh_lsda)
1737 any_eh_needed = any_lsda_needed = 1;
1738 else if (! fde_table[i].nothrow)
1741 if (! any_eh_needed)
1745 /* We're going to be generating comments, so turn on app. */
1751 #ifdef EH_FRAME_SECTION
1752 EH_FRAME_SECTION ();
1754 tree label = get_file_function_name ('F');
1756 force_data_section ();
1757 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1758 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1759 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1761 assemble_label ("__FRAME_BEGIN__");
1764 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION);
1766 /* Output the CIE. */
1767 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1768 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1769 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1770 "Length of Common Information Entry");
1771 ASM_OUTPUT_LABEL (asm_out_file, l1);
1773 /* Now that the CIE pointer is PC-relative for EH,
1774 use 0 to identify the CIE. */
1775 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1776 (for_eh ? 0 : DW_CIE_ID),
1777 "CIE Identifier Tag");
1779 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1781 augmentation[0] = 0;
1782 augmentation_size = 0;
1788 z Indicates that a uleb128 is present to size the
1789 augmentation section.
1790 L Indicates the encoding (and thus presence) of
1791 an LSDA pointer in the FDE augmentation.
1792 R Indicates a non-default pointer encoding for
1794 P Indicates the presence of an encoding + language
1795 personality routine in the CIE augmentation. */
1797 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1798 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1799 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1801 p = augmentation + 1;
1802 if (eh_personality_libfunc)
1805 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1807 if (any_lsda_needed)
1810 augmentation_size += 1;
1812 if (fde_encoding != DW_EH_PE_absptr)
1815 augmentation_size += 1;
1817 if (p > augmentation + 1)
1819 augmentation[0] = 'z';
1823 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1824 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1826 int offset = ( 4 /* Length */
1828 + 1 /* CIE version */
1829 + strlen (augmentation) + 1 /* Augmentation */
1830 + size_of_uleb128 (1) /* Code alignment */
1831 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1833 + 1 /* Augmentation size */
1834 + 1 /* Personality encoding */ );
1835 int pad = -offset & (PTR_SIZE - 1);
1837 augmentation_size += pad;
1839 /* Augmentations should be small, so there's scarce need to
1840 iterate for a solution. Die if we exceed one uleb128 byte. */
1841 if (size_of_uleb128 (augmentation_size) != 1)
1845 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1847 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1849 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1850 "CIE Data Alignment Factor");
1852 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1854 if (augmentation[0])
1856 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1857 if (eh_personality_libfunc)
1859 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1860 eh_data_format_name (per_encoding));
1861 dw2_asm_output_encoded_addr_rtx (per_encoding,
1862 eh_personality_libfunc, NULL);
1864 if (any_lsda_needed)
1865 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1866 eh_data_format_name (lsda_encoding));
1867 if (fde_encoding != DW_EH_PE_absptr)
1868 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1869 eh_data_format_name (fde_encoding));
1872 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1873 output_cfi (cfi, NULL, for_eh);
1875 /* Pad the CIE out to an address sized boundary. */
1876 ASM_OUTPUT_ALIGN (asm_out_file,
1877 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1878 ASM_OUTPUT_LABEL (asm_out_file, l2);
1880 /* Loop through all of the FDE's. */
1881 for (i = 0; i < fde_table_in_use; ++i)
1883 fde = &fde_table[i];
1885 /* Don't emit EH unwind info for leaf functions that don't need it. */
1886 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1889 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1890 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1891 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1892 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1894 ASM_OUTPUT_LABEL (asm_out_file, l1);
1896 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1897 emits a target dependent sized offset when for_eh is not true.
1898 This inconsistency may confuse gdb. The only case where we need a
1899 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1900 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1901 though in order to be compatible with the dwarf_fde struct in frame.c.
1902 If the for_eh case is changed, then the struct in frame.c has
1903 to be adjusted appropriately. */
1905 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1907 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1908 stripattributes (DEBUG_FRAME_SECTION),
1913 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1914 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1915 "FDE initial location");
1916 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1917 fde->dw_fde_end, fde->dw_fde_begin,
1918 "FDE address range");
1922 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1923 "FDE initial location");
1924 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1925 fde->dw_fde_end, fde->dw_fde_begin,
1926 "FDE address range");
1929 if (augmentation[0])
1931 if (any_lsda_needed)
1933 int size = size_of_encoded_value (lsda_encoding);
1935 if (lsda_encoding == DW_EH_PE_aligned)
1937 int offset = ( 4 /* Length */
1938 + 4 /* CIE offset */
1939 + 2 * size_of_encoded_value (fde_encoding)
1940 + 1 /* Augmentation size */ );
1941 int pad = -offset & (PTR_SIZE - 1);
1944 if (size_of_uleb128 (size) != 1)
1948 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1950 if (fde->uses_eh_lsda)
1952 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1953 fde->funcdef_number);
1954 dw2_asm_output_encoded_addr_rtx (
1955 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1956 "Language Specific Data Area");
1960 if (lsda_encoding == DW_EH_PE_aligned)
1961 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1962 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1963 0, "Language Specific Data Area (none)");
1967 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1970 /* Loop through the Call Frame Instructions associated with
1972 fde->dw_fde_current_label = fde->dw_fde_begin;
1973 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1974 output_cfi (cfi, fde, for_eh);
1976 /* Pad the FDE out to an address sized boundary. */
1977 ASM_OUTPUT_ALIGN (asm_out_file,
1978 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1979 ASM_OUTPUT_LABEL (asm_out_file, l2);
1982 #ifndef EH_FRAME_SECTION
1984 dw2_asm_output_data (4, 0, "End of Table");
1986 #ifdef MIPS_DEBUGGING_INFO
1987 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1988 get a value of 0. Putting .align 0 after the label fixes it. */
1989 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1992 /* Turn off app to make assembly quicker. */
1997 /* Output a marker (i.e. a label) for the beginning of a function, before
2001 dwarf2out_begin_prologue ()
2003 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2004 register dw_fde_ref fde;
2006 current_function_func_begin_label = 0;
2008 #ifdef IA64_UNWIND_INFO
2009 /* ??? current_function_func_begin_label is also used by except.c
2010 for call-site information. We must emit this label if it might
2012 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2013 && ! dwarf2out_do_frame ())
2016 if (! dwarf2out_do_frame ())
2020 ++current_funcdef_number;
2022 function_section (current_function_decl);
2023 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2024 current_funcdef_number);
2025 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2026 current_funcdef_number);
2027 current_function_func_begin_label = get_identifier (label);
2029 #ifdef IA64_UNWIND_INFO
2030 /* We can elide the fde allocation if we're not emitting debug info. */
2031 if (! dwarf2out_do_frame ())
2035 /* Expand the fde table if necessary. */
2036 if (fde_table_in_use == fde_table_allocated)
2038 fde_table_allocated += FDE_TABLE_INCREMENT;
2040 = (dw_fde_ref) xrealloc (fde_table,
2041 fde_table_allocated * sizeof (dw_fde_node));
2044 /* Record the FDE associated with this function. */
2045 current_funcdef_fde = fde_table_in_use;
2047 /* Add the new FDE at the end of the fde_table. */
2048 fde = &fde_table[fde_table_in_use++];
2049 fde->dw_fde_begin = xstrdup (label);
2050 fde->dw_fde_current_label = NULL;
2051 fde->dw_fde_end = NULL;
2052 fde->dw_fde_cfi = NULL;
2053 fde->funcdef_number = current_funcdef_number;
2054 fde->nothrow = current_function_nothrow;
2055 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2057 args_size = old_args_size = 0;
2060 /* Output a marker (i.e. a label) for the absolute end of the generated code
2061 for a function definition. This gets called *after* the epilogue code has
2065 dwarf2out_end_epilogue ()
2068 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2070 /* Output a label to mark the endpoint of the code generated for this
2072 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2073 ASM_OUTPUT_LABEL (asm_out_file, label);
2074 fde = &fde_table[fde_table_in_use - 1];
2075 fde->dw_fde_end = xstrdup (label);
2079 dwarf2out_frame_init ()
2081 /* Allocate the initial hunk of the fde_table. */
2082 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2083 fde_table_allocated = FDE_TABLE_INCREMENT;
2084 fde_table_in_use = 0;
2086 /* Generate the CFA instructions common to all FDE's. Do it now for the
2087 sake of lookup_cfa. */
2089 #ifdef DWARF2_UNWIND_INFO
2090 /* On entry, the Canonical Frame Address is at SP. */
2091 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2092 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2097 dwarf2out_frame_finish ()
2099 /* Output call frame information. */
2100 #ifdef MIPS_DEBUGGING_INFO
2101 if (write_symbols == DWARF2_DEBUG)
2102 output_call_frame_info (0);
2103 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2104 output_call_frame_info (1);
2106 if (write_symbols == DWARF2_DEBUG
2107 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2108 output_call_frame_info (1);
2112 /* And now, the subset of the debugging information support code necessary
2113 for emitting location expressions. */
2115 typedef struct dw_val_struct *dw_val_ref;
2116 typedef struct die_struct *dw_die_ref;
2117 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2118 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2120 /* Each DIE may have a series of attribute/value pairs. Values
2121 can take on several forms. The forms that are used in this
2122 implementation are listed below. */
2128 dw_val_class_loc_list,
2130 dw_val_class_unsigned_const,
2131 dw_val_class_long_long,
2134 dw_val_class_die_ref,
2135 dw_val_class_fde_ref,
2136 dw_val_class_lbl_id,
2137 dw_val_class_lbl_offset,
2142 /* Describe a double word constant value. */
2143 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2145 typedef struct dw_long_long_struct
2152 /* Describe a floating point constant value. */
2154 typedef struct dw_fp_struct
2161 /* The dw_val_node describes an attribute's value, as it is
2162 represented internally. */
2164 typedef struct dw_val_struct
2166 dw_val_class val_class;
2170 dw_loc_list_ref val_loc_list;
2171 dw_loc_descr_ref val_loc;
2173 long unsigned val_unsigned;
2174 dw_long_long_const val_long_long;
2175 dw_float_const val_float;
2180 unsigned val_fde_index;
2183 unsigned char val_flag;
2189 /* Locations in memory are described using a sequence of stack machine
2192 typedef struct dw_loc_descr_struct
2194 dw_loc_descr_ref dw_loc_next;
2195 enum dwarf_location_atom dw_loc_opc;
2196 dw_val_node dw_loc_oprnd1;
2197 dw_val_node dw_loc_oprnd2;
2202 /* Location lists are ranges + location descriptions for that range,
2203 so you can track variables that are in different places over
2204 their entire life. */
2205 typedef struct dw_loc_list_struct
2207 dw_loc_list_ref dw_loc_next;
2208 const char *begin; /* Label for begin address of range */
2209 const char *end; /* Label for end address of range */
2210 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2211 const char *section; /* Section this loclist is relative to */
2212 dw_loc_descr_ref expr;
2215 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2216 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2219 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2221 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2222 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2223 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2224 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2226 /* Convert a DWARF stack opcode into its string name. */
2229 dwarf_stack_op_name (op)
2230 register unsigned op;
2235 return "DW_OP_addr";
2237 return "DW_OP_deref";
2239 return "DW_OP_const1u";
2241 return "DW_OP_const1s";
2243 return "DW_OP_const2u";
2245 return "DW_OP_const2s";
2247 return "DW_OP_const4u";
2249 return "DW_OP_const4s";
2251 return "DW_OP_const8u";
2253 return "DW_OP_const8s";
2255 return "DW_OP_constu";
2257 return "DW_OP_consts";
2261 return "DW_OP_drop";
2263 return "DW_OP_over";
2265 return "DW_OP_pick";
2267 return "DW_OP_swap";
2271 return "DW_OP_xderef";
2279 return "DW_OP_minus";
2291 return "DW_OP_plus";
2292 case DW_OP_plus_uconst:
2293 return "DW_OP_plus_uconst";
2299 return "DW_OP_shra";
2317 return "DW_OP_skip";
2319 return "DW_OP_lit0";
2321 return "DW_OP_lit1";
2323 return "DW_OP_lit2";
2325 return "DW_OP_lit3";
2327 return "DW_OP_lit4";
2329 return "DW_OP_lit5";
2331 return "DW_OP_lit6";
2333 return "DW_OP_lit7";
2335 return "DW_OP_lit8";
2337 return "DW_OP_lit9";
2339 return "DW_OP_lit10";
2341 return "DW_OP_lit11";
2343 return "DW_OP_lit12";
2345 return "DW_OP_lit13";
2347 return "DW_OP_lit14";
2349 return "DW_OP_lit15";
2351 return "DW_OP_lit16";
2353 return "DW_OP_lit17";
2355 return "DW_OP_lit18";
2357 return "DW_OP_lit19";
2359 return "DW_OP_lit20";
2361 return "DW_OP_lit21";
2363 return "DW_OP_lit22";
2365 return "DW_OP_lit23";
2367 return "DW_OP_lit24";
2369 return "DW_OP_lit25";
2371 return "DW_OP_lit26";
2373 return "DW_OP_lit27";
2375 return "DW_OP_lit28";
2377 return "DW_OP_lit29";
2379 return "DW_OP_lit30";
2381 return "DW_OP_lit31";
2383 return "DW_OP_reg0";
2385 return "DW_OP_reg1";
2387 return "DW_OP_reg2";
2389 return "DW_OP_reg3";
2391 return "DW_OP_reg4";
2393 return "DW_OP_reg5";
2395 return "DW_OP_reg6";
2397 return "DW_OP_reg7";
2399 return "DW_OP_reg8";
2401 return "DW_OP_reg9";
2403 return "DW_OP_reg10";
2405 return "DW_OP_reg11";
2407 return "DW_OP_reg12";
2409 return "DW_OP_reg13";
2411 return "DW_OP_reg14";
2413 return "DW_OP_reg15";
2415 return "DW_OP_reg16";
2417 return "DW_OP_reg17";
2419 return "DW_OP_reg18";
2421 return "DW_OP_reg19";
2423 return "DW_OP_reg20";
2425 return "DW_OP_reg21";
2427 return "DW_OP_reg22";
2429 return "DW_OP_reg23";
2431 return "DW_OP_reg24";
2433 return "DW_OP_reg25";
2435 return "DW_OP_reg26";
2437 return "DW_OP_reg27";
2439 return "DW_OP_reg28";
2441 return "DW_OP_reg29";
2443 return "DW_OP_reg30";
2445 return "DW_OP_reg31";
2447 return "DW_OP_breg0";
2449 return "DW_OP_breg1";
2451 return "DW_OP_breg2";
2453 return "DW_OP_breg3";
2455 return "DW_OP_breg4";
2457 return "DW_OP_breg5";
2459 return "DW_OP_breg6";
2461 return "DW_OP_breg7";
2463 return "DW_OP_breg8";
2465 return "DW_OP_breg9";
2467 return "DW_OP_breg10";
2469 return "DW_OP_breg11";
2471 return "DW_OP_breg12";
2473 return "DW_OP_breg13";
2475 return "DW_OP_breg14";
2477 return "DW_OP_breg15";
2479 return "DW_OP_breg16";
2481 return "DW_OP_breg17";
2483 return "DW_OP_breg18";
2485 return "DW_OP_breg19";
2487 return "DW_OP_breg20";
2489 return "DW_OP_breg21";
2491 return "DW_OP_breg22";
2493 return "DW_OP_breg23";
2495 return "DW_OP_breg24";
2497 return "DW_OP_breg25";
2499 return "DW_OP_breg26";
2501 return "DW_OP_breg27";
2503 return "DW_OP_breg28";
2505 return "DW_OP_breg29";
2507 return "DW_OP_breg30";
2509 return "DW_OP_breg31";
2511 return "DW_OP_regx";
2513 return "DW_OP_fbreg";
2515 return "DW_OP_bregx";
2517 return "DW_OP_piece";
2518 case DW_OP_deref_size:
2519 return "DW_OP_deref_size";
2520 case DW_OP_xderef_size:
2521 return "DW_OP_xderef_size";
2525 return "OP_<unknown>";
2529 /* Return a pointer to a newly allocated location description. Location
2530 descriptions are simple expression terms that can be strung
2531 together to form more complicated location (address) descriptions. */
2533 static inline dw_loc_descr_ref
2534 new_loc_descr (op, oprnd1, oprnd2)
2535 register enum dwarf_location_atom op;
2536 register unsigned long oprnd1;
2537 register unsigned long oprnd2;
2539 /* Use xcalloc here so we clear out all of the long_long constant in
2541 register dw_loc_descr_ref descr
2542 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2544 descr->dw_loc_opc = op;
2545 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2546 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2547 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2548 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2554 /* Add a location description term to a location description expression. */
2557 add_loc_descr (list_head, descr)
2558 register dw_loc_descr_ref *list_head;
2559 register dw_loc_descr_ref descr;
2561 register dw_loc_descr_ref *d;
2563 /* Find the end of the chain. */
2564 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2570 /* Return the size of a location descriptor. */
2572 static unsigned long
2573 size_of_loc_descr (loc)
2574 register dw_loc_descr_ref loc;
2576 register unsigned long size = 1;
2578 switch (loc->dw_loc_opc)
2581 size += DWARF2_ADDR_SIZE;
2600 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2603 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2608 case DW_OP_plus_uconst:
2609 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2647 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2650 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2653 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2656 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2657 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2660 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2662 case DW_OP_deref_size:
2663 case DW_OP_xderef_size:
2673 /* Return the size of a series of location descriptors. */
2675 static unsigned long
2677 register dw_loc_descr_ref loc;
2679 register unsigned long size = 0;
2681 for (; loc != NULL; loc = loc->dw_loc_next)
2683 loc->dw_loc_addr = size;
2684 size += size_of_loc_descr (loc);
2690 /* Output location description stack opcode's operands (if any). */
2693 output_loc_operands (loc)
2694 register dw_loc_descr_ref loc;
2696 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2697 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2699 switch (loc->dw_loc_opc)
2701 #ifdef DWARF2_DEBUGGING_INFO
2703 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2707 dw2_asm_output_data (2, val1->v.val_int, NULL);
2711 dw2_asm_output_data (4, val1->v.val_int, NULL);
2715 if (HOST_BITS_PER_LONG < 64)
2717 dw2_asm_output_data (8, val1->v.val_int, NULL);
2724 if (val1->val_class == dw_val_class_loc)
2725 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2729 dw2_asm_output_data (2, offset, NULL);
2742 /* We currently don't make any attempt to make sure these are
2743 aligned properly like we do for the main unwind info, so
2744 don't support emitting things larger than a byte if we're
2745 only doing unwinding. */
2750 dw2_asm_output_data (1, val1->v.val_int, NULL);
2753 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2756 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2759 dw2_asm_output_data (1, val1->v.val_int, NULL);
2761 case DW_OP_plus_uconst:
2762 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2796 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2799 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2802 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2805 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2806 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2809 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2811 case DW_OP_deref_size:
2812 case DW_OP_xderef_size:
2813 dw2_asm_output_data (1, val1->v.val_int, NULL);
2816 /* Other codes have no operands. */
2821 /* Output a sequence of location operations. */
2824 output_loc_sequence (loc)
2825 dw_loc_descr_ref loc;
2827 for (; loc != NULL; loc = loc->dw_loc_next)
2829 /* Output the opcode. */
2830 dw2_asm_output_data (1, loc->dw_loc_opc,
2831 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2833 /* Output the operand(s) (if any). */
2834 output_loc_operands (loc);
2838 /* This routine will generate the correct assembly data for a location
2839 description based on a cfi entry with a complex address. */
2842 output_cfa_loc (cfi)
2845 dw_loc_descr_ref loc;
2848 /* Output the size of the block. */
2849 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2850 size = size_of_locs (loc);
2851 dw2_asm_output_data_uleb128 (size, NULL);
2853 /* Now output the operations themselves. */
2854 output_loc_sequence (loc);
2857 /* This function builds a dwarf location descriptor seqeunce from
2858 a dw_cfa_location. */
2860 static struct dw_loc_descr_struct *
2862 dw_cfa_location *cfa;
2864 struct dw_loc_descr_struct *head, *tmp;
2866 if (cfa->indirect == 0)
2869 if (cfa->base_offset)
2872 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2874 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2876 else if (cfa->reg <= 31)
2877 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2879 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2880 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2881 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2882 add_loc_descr (&head, tmp);
2883 if (cfa->offset != 0)
2885 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2886 add_loc_descr (&head, tmp);
2891 /* This function fills in aa dw_cfa_location structure from a
2892 dwarf location descriptor sequence. */
2895 get_cfa_from_loc_descr (cfa, loc)
2896 dw_cfa_location *cfa;
2897 struct dw_loc_descr_struct *loc;
2899 struct dw_loc_descr_struct *ptr;
2901 cfa->base_offset = 0;
2905 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2907 enum dwarf_location_atom op = ptr->dw_loc_opc;
2942 cfa->reg = op - DW_OP_reg0;
2945 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2979 cfa->reg = op - DW_OP_breg0;
2980 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2983 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2984 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2989 case DW_OP_plus_uconst:
2990 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2993 internal_error ("DW_LOC_OP %s not implememnted\n",
2994 dwarf_stack_op_name (ptr->dw_loc_opc));
2998 #endif /* .debug_frame support */
3000 /* And now, the support for symbolic debugging information. */
3001 #ifdef DWARF2_DEBUGGING_INFO
3003 /* NOTE: In the comments in this file, many references are made to
3004 "Debugging Information Entries". This term is abbreviated as `DIE'
3005 throughout the remainder of this file. */
3007 /* An internal representation of the DWARF output is built, and then
3008 walked to generate the DWARF debugging info. The walk of the internal
3009 representation is done after the entire program has been compiled.
3010 The types below are used to describe the internal representation. */
3012 /* Various DIE's use offsets relative to the beginning of the
3013 .debug_info section to refer to each other. */
3015 typedef long int dw_offset;
3017 /* Define typedefs here to avoid circular dependencies. */
3019 typedef struct dw_attr_struct *dw_attr_ref;
3020 typedef struct dw_line_info_struct *dw_line_info_ref;
3021 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3022 typedef struct pubname_struct *pubname_ref;
3023 typedef dw_die_ref *arange_ref;
3025 /* Each entry in the line_info_table maintains the file and
3026 line number associated with the label generated for that
3027 entry. The label gives the PC value associated with
3028 the line number entry. */
3030 typedef struct dw_line_info_struct
3032 unsigned long dw_file_num;
3033 unsigned long dw_line_num;
3037 /* Line information for functions in separate sections; each one gets its
3039 typedef struct dw_separate_line_info_struct
3041 unsigned long dw_file_num;
3042 unsigned long dw_line_num;
3043 unsigned long function;
3045 dw_separate_line_info_entry;
3047 /* Each DIE attribute has a field specifying the attribute kind,
3048 a link to the next attribute in the chain, and an attribute value.
3049 Attributes are typically linked below the DIE they modify. */
3051 typedef struct dw_attr_struct
3053 enum dwarf_attribute dw_attr;
3054 dw_attr_ref dw_attr_next;
3055 dw_val_node dw_attr_val;
3059 /* The Debugging Information Entry (DIE) structure */
3061 typedef struct die_struct
3063 enum dwarf_tag die_tag;
3065 dw_attr_ref die_attr;
3066 dw_die_ref die_parent;
3067 dw_die_ref die_child;
3069 dw_offset die_offset;
3070 unsigned long die_abbrev;
3075 /* The pubname structure */
3077 typedef struct pubname_struct
3084 /* The limbo die list structure. */
3085 typedef struct limbo_die_struct
3088 struct limbo_die_struct *next;
3092 /* How to start an assembler comment. */
3093 #ifndef ASM_COMMENT_START
3094 #define ASM_COMMENT_START ";#"
3097 /* Define a macro which returns non-zero for a TYPE_DECL which was
3098 implicitly generated for a tagged type.
3100 Note that unlike the gcc front end (which generates a NULL named
3101 TYPE_DECL node for each complete tagged type, each array type, and
3102 each function type node created) the g++ front end generates a
3103 _named_ TYPE_DECL node for each tagged type node created.
3104 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3105 generate a DW_TAG_typedef DIE for them. */
3107 #define TYPE_DECL_IS_STUB(decl) \
3108 (DECL_NAME (decl) == NULL_TREE \
3109 || (DECL_ARTIFICIAL (decl) \
3110 && is_tagged_type (TREE_TYPE (decl)) \
3111 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3112 /* This is necessary for stub decls that \
3113 appear in nested inline functions. */ \
3114 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3115 && (decl_ultimate_origin (decl) \
3116 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3118 /* Information concerning the compilation unit's programming
3119 language, and compiler version. */
3121 extern int flag_traditional;
3123 /* Fixed size portion of the DWARF compilation unit header. */
3124 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3126 /* Fixed size portion of debugging line information prolog. */
3127 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3129 /* Fixed size portion of public names info. */
3130 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3132 /* Fixed size portion of the address range info. */
3133 #define DWARF_ARANGES_HEADER_SIZE \
3134 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3135 - DWARF_OFFSET_SIZE)
3137 /* Size of padding portion in the address range info. It must be
3138 aligned to twice the pointer size. */
3139 #define DWARF_ARANGES_PAD_SIZE \
3140 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3141 - (2 * DWARF_OFFSET_SIZE + 4))
3143 /* Use assembler line directives if available. */
3144 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3145 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3146 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3148 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3152 /* Define the architecture-dependent minimum instruction length (in bytes).
3153 In this implementation of DWARF, this field is used for information
3154 purposes only. Since GCC generates assembly language, we have
3155 no a priori knowledge of how many instruction bytes are generated
3156 for each source line, and therefore can use only the DW_LNE_set_address
3157 and DW_LNS_fixed_advance_pc line information commands. */
3159 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3160 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3163 /* Minimum line offset in a special line info. opcode.
3164 This value was chosen to give a reasonable range of values. */
3165 #define DWARF_LINE_BASE -10
3167 /* First special line opcde - leave room for the standard opcodes. */
3168 #define DWARF_LINE_OPCODE_BASE 10
3170 /* Range of line offsets in a special line info. opcode. */
3171 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3173 /* Flag that indicates the initial value of the is_stmt_start flag.
3174 In the present implementation, we do not mark any lines as
3175 the beginning of a source statement, because that information
3176 is not made available by the GCC front-end. */
3177 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3179 /* This location is used by calc_die_sizes() to keep track
3180 the offset of each DIE within the .debug_info section. */
3181 static unsigned long next_die_offset;
3183 /* Record the root of the DIE's built for the current compilation unit. */
3184 static dw_die_ref comp_unit_die;
3186 /* A list of DIEs with a NULL parent waiting to be relocated. */
3187 static limbo_die_node *limbo_die_list = 0;
3189 /* Structure used by lookup_filename to manage sets of filenames. */
3195 unsigned last_lookup_index;
3198 /* Size (in elements) of increments by which we may expand the filename
3200 #define FILE_TABLE_INCREMENT 64
3202 /* Filenames referenced by this compilation unit. */
3203 static struct file_table file_table;
3205 /* Local pointer to the name of the main input file. Initialized in
3207 static const char *primary_filename;
3209 /* A pointer to the base of a table of references to DIE's that describe
3210 declarations. The table is indexed by DECL_UID() which is a unique
3211 number identifying each decl. */
3212 static dw_die_ref *decl_die_table;
3214 /* Number of elements currently allocated for the decl_die_table. */
3215 static unsigned decl_die_table_allocated;
3217 /* Number of elements in decl_die_table currently in use. */
3218 static unsigned decl_die_table_in_use;
3220 /* Size (in elements) of increments by which we may expand the
3222 #define DECL_DIE_TABLE_INCREMENT 256
3224 /* A pointer to the base of a table of references to declaration
3225 scopes. This table is a display which tracks the nesting
3226 of declaration scopes at the current scope and containing
3227 scopes. This table is used to find the proper place to
3228 define type declaration DIE's. */
3229 static tree *decl_scope_table;
3231 /* Number of elements currently allocated for the decl_scope_table. */
3232 static int decl_scope_table_allocated;
3234 /* Current level of nesting of declaration scopes. */
3235 static int decl_scope_depth;
3237 /* Size (in elements) of increments by which we may expand the
3238 decl_scope_table. */
3239 #define DECL_SCOPE_TABLE_INCREMENT 64
3241 /* A pointer to the base of a list of references to DIE's that
3242 are uniquely identified by their tag, presence/absence of
3243 children DIE's, and list of attribute/value pairs. */
3244 static dw_die_ref *abbrev_die_table;
3246 /* Number of elements currently allocated for abbrev_die_table. */
3247 static unsigned abbrev_die_table_allocated;
3249 /* Number of elements in type_die_table currently in use. */
3250 static unsigned abbrev_die_table_in_use;
3252 /* Size (in elements) of increments by which we may expand the
3253 abbrev_die_table. */
3254 #define ABBREV_DIE_TABLE_INCREMENT 256
3256 /* A pointer to the base of a table that contains line information
3257 for each source code line in .text in the compilation unit. */
3258 static dw_line_info_ref line_info_table;
3260 /* Number of elements currently allocated for line_info_table. */
3261 static unsigned line_info_table_allocated;
3263 /* Number of elements in separate_line_info_table currently in use. */
3264 static unsigned separate_line_info_table_in_use;
3266 /* A pointer to the base of a table that contains line information
3267 for each source code line outside of .text in the compilation unit. */
3268 static dw_separate_line_info_ref separate_line_info_table;
3270 /* Number of elements currently allocated for separate_line_info_table. */
3271 static unsigned separate_line_info_table_allocated;
3273 /* Number of elements in line_info_table currently in use. */
3274 static unsigned line_info_table_in_use;
3276 /* Size (in elements) of increments by which we may expand the
3278 #define LINE_INFO_TABLE_INCREMENT 1024
3280 /* A pointer to the base of a table that contains a list of publicly
3281 accessible names. */
3282 static pubname_ref pubname_table;
3284 /* Number of elements currently allocated for pubname_table. */
3285 static unsigned pubname_table_allocated;
3287 /* Number of elements in pubname_table currently in use. */
3288 static unsigned pubname_table_in_use;
3290 /* Size (in elements) of increments by which we may expand the
3292 #define PUBNAME_TABLE_INCREMENT 64
3294 /* A pointer to the base of a table that contains a list of publicly
3295 accessible names. */
3296 static arange_ref arange_table;
3298 /* Number of elements currently allocated for arange_table. */
3299 static unsigned arange_table_allocated;
3301 /* Number of elements in arange_table currently in use. */
3302 static unsigned arange_table_in_use;
3304 /* Size (in elements) of increments by which we may expand the
3306 #define ARANGE_TABLE_INCREMENT 64
3308 /* Whether we have location lists that need outputting */
3309 static unsigned have_location_lists;
3311 /* A pointer to the base of a list of incomplete types which might be
3312 completed at some later time. */
3314 static tree *incomplete_types_list;
3316 /* Number of elements currently allocated for the incomplete_types_list. */
3317 static unsigned incomplete_types_allocated;
3319 /* Number of elements of incomplete_types_list currently in use. */
3320 static unsigned incomplete_types;
3322 /* Size (in elements) of increments by which we may expand the incomplete
3323 types list. Actually, a single hunk of space of this size should
3324 be enough for most typical programs. */
3325 #define INCOMPLETE_TYPES_INCREMENT 64
3327 /* Record whether the function being analyzed contains inlined functions. */
3328 static int current_function_has_inlines;
3329 #if 0 && defined (MIPS_DEBUGGING_INFO)
3330 static int comp_unit_has_inlines;
3333 /* Array of RTXes referenced by the debugging information, which therefore
3334 must be kept around forever. We do this rather than perform GC on
3335 the dwarf info because almost all of the dwarf info lives forever, and
3336 it's easier to support non-GC frontends this way. */
3337 static varray_type used_rtx_varray;
3339 /* Forward declarations for functions defined in this file. */
3341 static int is_pseudo_reg PARAMS ((rtx));
3342 static tree type_main_variant PARAMS ((tree));
3343 static int is_tagged_type PARAMS ((tree));
3344 static const char *dwarf_tag_name PARAMS ((unsigned));
3345 static const char *dwarf_attr_name PARAMS ((unsigned));
3346 static const char *dwarf_form_name PARAMS ((unsigned));
3348 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3350 static tree decl_ultimate_origin PARAMS ((tree));
3351 static tree block_ultimate_origin PARAMS ((tree));
3352 static tree decl_class_context PARAMS ((tree));
3353 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3354 static void add_AT_flag PARAMS ((dw_die_ref,
3355 enum dwarf_attribute,
3357 static void add_AT_int PARAMS ((dw_die_ref,
3358 enum dwarf_attribute, long));
3359 static void add_AT_unsigned PARAMS ((dw_die_ref,
3360 enum dwarf_attribute,
3362 static void add_AT_long_long PARAMS ((dw_die_ref,
3363 enum dwarf_attribute,
3366 static void add_AT_float PARAMS ((dw_die_ref,
3367 enum dwarf_attribute,
3369 static void add_AT_string PARAMS ((dw_die_ref,
3370 enum dwarf_attribute,
3372 static void add_AT_die_ref PARAMS ((dw_die_ref,
3373 enum dwarf_attribute,
3375 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3376 enum dwarf_attribute,
3378 static void add_AT_loc PARAMS ((dw_die_ref,
3379 enum dwarf_attribute,
3381 static void add_AT_loc_list PARAMS ((dw_die_ref,
3382 enum dwarf_attribute,
3384 static void add_AT_addr PARAMS ((dw_die_ref,
3385 enum dwarf_attribute,
3387 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3388 enum dwarf_attribute,
3390 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3391 enum dwarf_attribute,
3393 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3394 enum dwarf_attribute));
3395 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3396 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3397 static const char *get_AT_string PARAMS ((dw_die_ref,
3398 enum dwarf_attribute));
3399 static int get_AT_flag PARAMS ((dw_die_ref,
3400 enum dwarf_attribute));
3401 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3402 enum dwarf_attribute));
3403 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3404 enum dwarf_attribute));
3405 static int is_c_family PARAMS ((void));
3406 static int is_java PARAMS ((void));
3407 static int is_fortran PARAMS ((void));
3408 static void remove_AT PARAMS ((dw_die_ref,
3409 enum dwarf_attribute));
3410 static void remove_children PARAMS ((dw_die_ref));
3411 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3412 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3413 static dw_die_ref lookup_type_die PARAMS ((tree));
3414 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3415 static dw_die_ref lookup_decl_die PARAMS ((tree));
3416 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3417 static void print_spaces PARAMS ((FILE *));
3418 static void print_die PARAMS ((dw_die_ref, FILE *));
3419 static void print_dwarf_line_table PARAMS ((FILE *));
3420 static void reverse_die_lists PARAMS ((dw_die_ref));
3421 static void reverse_all_dies PARAMS ((dw_die_ref));
3422 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3423 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3424 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3425 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3426 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3427 static void compute_section_prefix PARAMS ((dw_die_ref));
3428 static int is_type_die PARAMS ((dw_die_ref));
3429 static int is_comdat_die PARAMS ((dw_die_ref));
3430 static int is_symbol_die PARAMS ((dw_die_ref));
3431 static void assign_symbol_names PARAMS ((dw_die_ref));
3432 static void break_out_includes PARAMS ((dw_die_ref));
3433 static void add_sibling_attributes PARAMS ((dw_die_ref));
3434 static void build_abbrev_table PARAMS ((dw_die_ref));
3435 static void output_location_lists PARAMS ((dw_die_ref));
3436 static unsigned long size_of_string PARAMS ((const char *));
3437 static int constant_size PARAMS ((long unsigned));
3438 static unsigned long size_of_die PARAMS ((dw_die_ref));
3439 static void calc_die_sizes PARAMS ((dw_die_ref));
3440 static void mark_dies PARAMS ((dw_die_ref));
3441 static void unmark_dies PARAMS ((dw_die_ref));
3442 static unsigned long size_of_pubnames PARAMS ((void));
3443 static unsigned long size_of_aranges PARAMS ((void));
3444 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3445 static void output_value_format PARAMS ((dw_attr_ref));
3446 static void output_abbrev_section PARAMS ((void));
3447 static void output_die_symbol PARAMS ((dw_die_ref));
3448 static void output_die PARAMS ((dw_die_ref));
3449 static void output_compilation_unit_header PARAMS ((void));
3450 static void output_comp_unit PARAMS ((dw_die_ref));
3451 static const char *dwarf2_name PARAMS ((tree, int));
3452 static void add_pubname PARAMS ((tree, dw_die_ref));
3453 static void output_pubnames PARAMS ((void));
3454 static void add_arange PARAMS ((tree, dw_die_ref));
3455 static void output_aranges PARAMS ((void));
3456 static void output_line_info PARAMS ((void));
3457 static void output_file_names PARAMS ((void));
3458 static dw_die_ref base_type_die PARAMS ((tree));
3459 static tree root_type PARAMS ((tree));
3460 static int is_base_type PARAMS ((tree));
3461 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3462 static int type_is_enum PARAMS ((tree));
3463 static unsigned int reg_number PARAMS ((rtx));
3464 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3465 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3466 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3467 static int is_based_loc PARAMS ((rtx));
3468 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3469 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3470 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3471 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3472 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3473 static tree field_type PARAMS ((tree));
3474 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3475 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3476 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3477 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3478 static void add_AT_location_description PARAMS ((dw_die_ref,
3479 enum dwarf_attribute, rtx));
3480 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3481 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3482 static rtx rtl_for_decl_location PARAMS ((tree));
3483 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3484 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3485 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3486 static void add_bound_info PARAMS ((dw_die_ref,
3487 enum dwarf_attribute, tree));
3488 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3489 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3490 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3491 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3492 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3493 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3494 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3495 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3496 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3497 static void push_decl_scope PARAMS ((tree));
3498 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3499 static void pop_decl_scope PARAMS ((void));
3500 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3502 static const char *type_tag PARAMS ((tree));
3503 static tree member_declared_type PARAMS ((tree));
3505 static const char *decl_start_label PARAMS ((tree));
3507 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3508 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3510 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3512 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3513 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3514 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3515 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3516 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3517 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3518 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3519 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3520 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3521 static void gen_label_die PARAMS ((tree, dw_die_ref));
3522 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3523 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3524 static void gen_field_die PARAMS ((tree, dw_die_ref));
3525 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3526 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3527 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3528 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3529 static void gen_member_die PARAMS ((tree, dw_die_ref));
3530 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3531 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3532 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3533 static void gen_type_die PARAMS ((tree, dw_die_ref));
3534 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3535 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3536 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3537 static int is_redundant_typedef PARAMS ((tree));
3538 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3539 static unsigned lookup_filename PARAMS ((const char *));
3540 static void init_file_table PARAMS ((void));
3541 static void add_incomplete_type PARAMS ((tree));
3542 static void retry_incomplete_types PARAMS ((void));
3543 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3544 static rtx save_rtx PARAMS ((rtx));
3545 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3546 static int file_info_cmp PARAMS ((const void *, const void *));
3547 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3548 const char *, const char *,
3549 const char *, unsigned));
3550 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3552 const char *, const char *, const char *));
3553 static void output_loc_list PARAMS ((dw_loc_list_ref));
3554 static char *gen_internal_sym PARAMS ((const char *));
3556 /* Section names used to hold DWARF debugging information. */
3557 #ifndef DEBUG_INFO_SECTION
3558 #define DEBUG_INFO_SECTION ".debug_info"
3560 #ifndef DEBUG_ABBREV_SECTION
3561 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3563 #ifndef DEBUG_ARANGES_SECTION
3564 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3566 #ifndef DEBUG_MACINFO_SECTION
3567 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3569 #ifndef DEBUG_LINE_SECTION
3570 #define DEBUG_LINE_SECTION ".debug_line"
3572 #ifndef DEBUG_LOC_SECTION
3573 #define DEBUG_LOC_SECTION ".debug_loc"
3575 #ifndef DEBUG_PUBNAMES_SECTION
3576 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3578 #ifndef DEBUG_STR_SECTION
3579 #define DEBUG_STR_SECTION ".debug_str"
3582 /* Standard ELF section names for compiled code and data. */
3583 #ifndef TEXT_SECTION
3584 #define TEXT_SECTION ".text"
3586 #ifndef DATA_SECTION
3587 #define DATA_SECTION ".data"
3590 #define BSS_SECTION ".bss"
3593 /* Labels we insert at beginning sections we can reference instead of
3594 the section names themselves. */
3596 #ifndef TEXT_SECTION_LABEL
3597 #define TEXT_SECTION_LABEL "Ltext"
3599 #ifndef DEBUG_LINE_SECTION_LABEL
3600 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3602 #ifndef DEBUG_INFO_SECTION_LABEL
3603 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3605 #ifndef DEBUG_ABBREV_SECTION_LABEL
3606 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3608 #ifndef DEBUG_LOC_SECTION_LABEL
3609 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3611 #ifndef DEBUG_MACINFO_SECTION_LABEL
3612 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3614 /* Definitions of defaults for formats and names of various special
3615 (artificial) labels which may be generated within this file (when the -g
3616 options is used and DWARF_DEBUGGING_INFO is in effect.
3617 If necessary, these may be overridden from within the tm.h file, but
3618 typically, overriding these defaults is unnecessary. */
3620 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3621 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3622 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3623 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3624 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3625 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3626 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3627 #ifndef TEXT_END_LABEL
3628 #define TEXT_END_LABEL "Letext"
3630 #ifndef DATA_END_LABEL
3631 #define DATA_END_LABEL "Ledata"
3633 #ifndef BSS_END_LABEL
3634 #define BSS_END_LABEL "Lebss"
3636 #ifndef BLOCK_BEGIN_LABEL
3637 #define BLOCK_BEGIN_LABEL "LBB"
3639 #ifndef BLOCK_END_LABEL
3640 #define BLOCK_END_LABEL "LBE"
3642 #ifndef BODY_BEGIN_LABEL
3643 #define BODY_BEGIN_LABEL "Lbb"
3645 #ifndef BODY_END_LABEL
3646 #define BODY_END_LABEL "Lbe"
3648 #ifndef LINE_CODE_LABEL
3649 #define LINE_CODE_LABEL "LM"
3651 #ifndef SEPARATE_LINE_CODE_LABEL
3652 #define SEPARATE_LINE_CODE_LABEL "LSM"
3655 /* We allow a language front-end to designate a function that is to be
3656 called to "demangle" any name before it it put into a DIE. */
3658 static const char *(*demangle_name_func) PARAMS ((const char *));
3661 dwarf2out_set_demangle_name_func (func)
3662 const char *(*func) PARAMS ((const char *));
3664 demangle_name_func = func;
3667 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3668 that means adding it to used_rtx_varray. If not, that means making
3669 a copy on the permanent_obstack. */
3675 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3680 /* Test if rtl node points to a pseudo register. */
3686 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3687 || (GET_CODE (rtl) == SUBREG
3688 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3691 /* Return a reference to a type, with its const and volatile qualifiers
3695 type_main_variant (type)
3698 type = TYPE_MAIN_VARIANT (type);
3700 /* There really should be only one main variant among any group of variants
3701 of a given type (and all of the MAIN_VARIANT values for all members of
3702 the group should point to that one type) but sometimes the C front-end
3703 messes this up for array types, so we work around that bug here. */
3705 if (TREE_CODE (type) == ARRAY_TYPE)
3706 while (type != TYPE_MAIN_VARIANT (type))
3707 type = TYPE_MAIN_VARIANT (type);
3712 /* Return non-zero if the given type node represents a tagged type. */
3715 is_tagged_type (type)
3718 register enum tree_code code = TREE_CODE (type);
3720 return (code == RECORD_TYPE || code == UNION_TYPE
3721 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3724 /* Convert a DIE tag into its string name. */
3727 dwarf_tag_name (tag)
3728 register unsigned tag;
3732 case DW_TAG_padding:
3733 return "DW_TAG_padding";
3734 case DW_TAG_array_type:
3735 return "DW_TAG_array_type";
3736 case DW_TAG_class_type:
3737 return "DW_TAG_class_type";
3738 case DW_TAG_entry_point:
3739 return "DW_TAG_entry_point";
3740 case DW_TAG_enumeration_type:
3741 return "DW_TAG_enumeration_type";
3742 case DW_TAG_formal_parameter:
3743 return "DW_TAG_formal_parameter";
3744 case DW_TAG_imported_declaration:
3745 return "DW_TAG_imported_declaration";
3747 return "DW_TAG_label";
3748 case DW_TAG_lexical_block:
3749 return "DW_TAG_lexical_block";
3751 return "DW_TAG_member";
3752 case DW_TAG_pointer_type:
3753 return "DW_TAG_pointer_type";
3754 case DW_TAG_reference_type:
3755 return "DW_TAG_reference_type";
3756 case DW_TAG_compile_unit:
3757 return "DW_TAG_compile_unit";
3758 case DW_TAG_string_type:
3759 return "DW_TAG_string_type";
3760 case DW_TAG_structure_type:
3761 return "DW_TAG_structure_type";
3762 case DW_TAG_subroutine_type:
3763 return "DW_TAG_subroutine_type";
3764 case DW_TAG_typedef:
3765 return "DW_TAG_typedef";
3766 case DW_TAG_union_type:
3767 return "DW_TAG_union_type";
3768 case DW_TAG_unspecified_parameters:
3769 return "DW_TAG_unspecified_parameters";
3770 case DW_TAG_variant:
3771 return "DW_TAG_variant";
3772 case DW_TAG_common_block:
3773 return "DW_TAG_common_block";
3774 case DW_TAG_common_inclusion:
3775 return "DW_TAG_common_inclusion";
3776 case DW_TAG_inheritance:
3777 return "DW_TAG_inheritance";
3778 case DW_TAG_inlined_subroutine:
3779 return "DW_TAG_inlined_subroutine";
3781 return "DW_TAG_module";
3782 case DW_TAG_ptr_to_member_type:
3783 return "DW_TAG_ptr_to_member_type";
3784 case DW_TAG_set_type:
3785 return "DW_TAG_set_type";
3786 case DW_TAG_subrange_type:
3787 return "DW_TAG_subrange_type";
3788 case DW_TAG_with_stmt:
3789 return "DW_TAG_with_stmt";
3790 case DW_TAG_access_declaration:
3791 return "DW_TAG_access_declaration";
3792 case DW_TAG_base_type:
3793 return "DW_TAG_base_type";
3794 case DW_TAG_catch_block:
3795 return "DW_TAG_catch_block";
3796 case DW_TAG_const_type:
3797 return "DW_TAG_const_type";
3798 case DW_TAG_constant:
3799 return "DW_TAG_constant";
3800 case DW_TAG_enumerator:
3801 return "DW_TAG_enumerator";
3802 case DW_TAG_file_type:
3803 return "DW_TAG_file_type";
3805 return "DW_TAG_friend";
3806 case DW_TAG_namelist:
3807 return "DW_TAG_namelist";
3808 case DW_TAG_namelist_item:
3809 return "DW_TAG_namelist_item";
3810 case DW_TAG_packed_type:
3811 return "DW_TAG_packed_type";
3812 case DW_TAG_subprogram:
3813 return "DW_TAG_subprogram";
3814 case DW_TAG_template_type_param:
3815 return "DW_TAG_template_type_param";
3816 case DW_TAG_template_value_param:
3817 return "DW_TAG_template_value_param";
3818 case DW_TAG_thrown_type:
3819 return "DW_TAG_thrown_type";
3820 case DW_TAG_try_block:
3821 return "DW_TAG_try_block";
3822 case DW_TAG_variant_part:
3823 return "DW_TAG_variant_part";
3824 case DW_TAG_variable:
3825 return "DW_TAG_variable";
3826 case DW_TAG_volatile_type:
3827 return "DW_TAG_volatile_type";
3828 case DW_TAG_MIPS_loop:
3829 return "DW_TAG_MIPS_loop";
3830 case DW_TAG_format_label:
3831 return "DW_TAG_format_label";
3832 case DW_TAG_function_template:
3833 return "DW_TAG_function_template";
3834 case DW_TAG_class_template:
3835 return "DW_TAG_class_template";
3836 case DW_TAG_GNU_BINCL:
3837 return "DW_TAG_GNU_BINCL";
3838 case DW_TAG_GNU_EINCL:
3839 return "DW_TAG_GNU_EINCL";
3841 return "DW_TAG_<unknown>";
3845 /* Convert a DWARF attribute code into its string name. */
3848 dwarf_attr_name (attr)
3849 register unsigned attr;
3854 return "DW_AT_sibling";
3855 case DW_AT_location:
3856 return "DW_AT_location";
3858 return "DW_AT_name";
3859 case DW_AT_ordering:
3860 return "DW_AT_ordering";
3861 case DW_AT_subscr_data:
3862 return "DW_AT_subscr_data";
3863 case DW_AT_byte_size:
3864 return "DW_AT_byte_size";
3865 case DW_AT_bit_offset:
3866 return "DW_AT_bit_offset";
3867 case DW_AT_bit_size:
3868 return "DW_AT_bit_size";
3869 case DW_AT_element_list:
3870 return "DW_AT_element_list";
3871 case DW_AT_stmt_list:
3872 return "DW_AT_stmt_list";
3874 return "DW_AT_low_pc";
3876 return "DW_AT_high_pc";
3877 case DW_AT_language:
3878 return "DW_AT_language";
3880 return "DW_AT_member";
3882 return "DW_AT_discr";
3883 case DW_AT_discr_value:
3884 return "DW_AT_discr_value";
3885 case DW_AT_visibility:
3886 return "DW_AT_visibility";
3888 return "DW_AT_import";
3889 case DW_AT_string_length:
3890 return "DW_AT_string_length";
3891 case DW_AT_common_reference:
3892 return "DW_AT_common_reference";
3893 case DW_AT_comp_dir:
3894 return "DW_AT_comp_dir";
3895 case DW_AT_const_value:
3896 return "DW_AT_const_value";
3897 case DW_AT_containing_type:
3898 return "DW_AT_containing_type";
3899 case DW_AT_default_value:
3900 return "DW_AT_default_value";
3902 return "DW_AT_inline";
3903 case DW_AT_is_optional:
3904 return "DW_AT_is_optional";
3905 case DW_AT_lower_bound:
3906 return "DW_AT_lower_bound";
3907 case DW_AT_producer:
3908 return "DW_AT_producer";
3909 case DW_AT_prototyped:
3910 return "DW_AT_prototyped";
3911 case DW_AT_return_addr:
3912 return "DW_AT_return_addr";
3913 case DW_AT_start_scope:
3914 return "DW_AT_start_scope";
3915 case DW_AT_stride_size:
3916 return "DW_AT_stride_size";
3917 case DW_AT_upper_bound:
3918 return "DW_AT_upper_bound";
3919 case DW_AT_abstract_origin:
3920 return "DW_AT_abstract_origin";
3921 case DW_AT_accessibility:
3922 return "DW_AT_accessibility";
3923 case DW_AT_address_class:
3924 return "DW_AT_address_class";
3925 case DW_AT_artificial:
3926 return "DW_AT_artificial";
3927 case DW_AT_base_types:
3928 return "DW_AT_base_types";
3929 case DW_AT_calling_convention:
3930 return "DW_AT_calling_convention";
3932 return "DW_AT_count";
3933 case DW_AT_data_member_location:
3934 return "DW_AT_data_member_location";
3935 case DW_AT_decl_column:
3936 return "DW_AT_decl_column";
3937 case DW_AT_decl_file:
3938 return "DW_AT_decl_file";
3939 case DW_AT_decl_line:
3940 return "DW_AT_decl_line";
3941 case DW_AT_declaration:
3942 return "DW_AT_declaration";
3943 case DW_AT_discr_list:
3944 return "DW_AT_discr_list";
3945 case DW_AT_encoding:
3946 return "DW_AT_encoding";
3947 case DW_AT_external:
3948 return "DW_AT_external";
3949 case DW_AT_frame_base:
3950 return "DW_AT_frame_base";
3952 return "DW_AT_friend";
3953 case DW_AT_identifier_case:
3954 return "DW_AT_identifier_case";
3955 case DW_AT_macro_info:
3956 return "DW_AT_macro_info";
3957 case DW_AT_namelist_items:
3958 return "DW_AT_namelist_items";
3959 case DW_AT_priority:
3960 return "DW_AT_priority";
3962 return "DW_AT_segment";
3963 case DW_AT_specification:
3964 return "DW_AT_specification";
3965 case DW_AT_static_link:
3966 return "DW_AT_static_link";
3968 return "DW_AT_type";
3969 case DW_AT_use_location:
3970 return "DW_AT_use_location";
3971 case DW_AT_variable_parameter:
3972 return "DW_AT_variable_parameter";
3973 case DW_AT_virtuality:
3974 return "DW_AT_virtuality";
3975 case DW_AT_vtable_elem_location:
3976 return "DW_AT_vtable_elem_location";
3978 case DW_AT_MIPS_fde:
3979 return "DW_AT_MIPS_fde";
3980 case DW_AT_MIPS_loop_begin:
3981 return "DW_AT_MIPS_loop_begin";
3982 case DW_AT_MIPS_tail_loop_begin:
3983 return "DW_AT_MIPS_tail_loop_begin";
3984 case DW_AT_MIPS_epilog_begin:
3985 return "DW_AT_MIPS_epilog_begin";
3986 case DW_AT_MIPS_loop_unroll_factor:
3987 return "DW_AT_MIPS_loop_unroll_factor";
3988 case DW_AT_MIPS_software_pipeline_depth:
3989 return "DW_AT_MIPS_software_pipeline_depth";
3990 case DW_AT_MIPS_linkage_name:
3991 return "DW_AT_MIPS_linkage_name";
3992 case DW_AT_MIPS_stride:
3993 return "DW_AT_MIPS_stride";
3994 case DW_AT_MIPS_abstract_name:
3995 return "DW_AT_MIPS_abstract_name";
3996 case DW_AT_MIPS_clone_origin:
3997 return "DW_AT_MIPS_clone_origin";
3998 case DW_AT_MIPS_has_inlines:
3999 return "DW_AT_MIPS_has_inlines";
4001 case DW_AT_sf_names:
4002 return "DW_AT_sf_names";
4003 case DW_AT_src_info:
4004 return "DW_AT_src_info";
4005 case DW_AT_mac_info:
4006 return "DW_AT_mac_info";
4007 case DW_AT_src_coords:
4008 return "DW_AT_src_coords";
4009 case DW_AT_body_begin:
4010 return "DW_AT_body_begin";
4011 case DW_AT_body_end:
4012 return "DW_AT_body_end";
4014 return "DW_AT_<unknown>";
4018 /* Convert a DWARF value form code into its string name. */
4021 dwarf_form_name (form)
4022 register unsigned form;
4027 return "DW_FORM_addr";
4028 case DW_FORM_block2:
4029 return "DW_FORM_block2";
4030 case DW_FORM_block4:
4031 return "DW_FORM_block4";
4033 return "DW_FORM_data2";
4035 return "DW_FORM_data4";
4037 return "DW_FORM_data8";
4038 case DW_FORM_string:
4039 return "DW_FORM_string";
4041 return "DW_FORM_block";
4042 case DW_FORM_block1:
4043 return "DW_FORM_block1";
4045 return "DW_FORM_data1";
4047 return "DW_FORM_flag";
4049 return "DW_FORM_sdata";
4051 return "DW_FORM_strp";
4053 return "DW_FORM_udata";
4054 case DW_FORM_ref_addr:
4055 return "DW_FORM_ref_addr";
4057 return "DW_FORM_ref1";
4059 return "DW_FORM_ref2";
4061 return "DW_FORM_ref4";
4063 return "DW_FORM_ref8";
4064 case DW_FORM_ref_udata:
4065 return "DW_FORM_ref_udata";
4066 case DW_FORM_indirect:
4067 return "DW_FORM_indirect";
4069 return "DW_FORM_<unknown>";
4073 /* Convert a DWARF type code into its string name. */
4077 dwarf_type_encoding_name (enc)
4078 register unsigned enc;
4082 case DW_ATE_address:
4083 return "DW_ATE_address";
4084 case DW_ATE_boolean:
4085 return "DW_ATE_boolean";
4086 case DW_ATE_complex_float:
4087 return "DW_ATE_complex_float";
4089 return "DW_ATE_float";
4091 return "DW_ATE_signed";
4092 case DW_ATE_signed_char:
4093 return "DW_ATE_signed_char";
4094 case DW_ATE_unsigned:
4095 return "DW_ATE_unsigned";
4096 case DW_ATE_unsigned_char:
4097 return "DW_ATE_unsigned_char";
4099 return "DW_ATE_<unknown>";
4104 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4105 instance of an inlined instance of a decl which is local to an inline
4106 function, so we have to trace all of the way back through the origin chain
4107 to find out what sort of node actually served as the original seed for the
4111 decl_ultimate_origin (decl)
4114 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4115 nodes in the function to point to themselves; ignore that if
4116 we're trying to output the abstract instance of this function. */
4117 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4120 #ifdef ENABLE_CHECKING
4121 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4122 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4123 most distant ancestor, this should never happen. */
4127 return DECL_ABSTRACT_ORIGIN (decl);
4130 /* Determine the "ultimate origin" of a block. The block may be an inlined
4131 instance of an inlined instance of a block which is local to an inline
4132 function, so we have to trace all of the way back through the origin chain
4133 to find out what sort of node actually served as the original seed for the
4137 block_ultimate_origin (block)
4138 register tree block;
4140 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4142 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4143 nodes in the function to point to themselves; ignore that if
4144 we're trying to output the abstract instance of this function. */
4145 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4148 if (immediate_origin == NULL_TREE)
4152 register tree ret_val;
4153 register tree lookahead = immediate_origin;
4157 ret_val = lookahead;
4158 lookahead = (TREE_CODE (ret_val) == BLOCK)
4159 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4162 while (lookahead != NULL && lookahead != ret_val);
4168 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4169 of a virtual function may refer to a base class, so we check the 'this'
4173 decl_class_context (decl)
4176 tree context = NULL_TREE;
4178 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4179 context = DECL_CONTEXT (decl);
4181 context = TYPE_MAIN_VARIANT
4182 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4184 if (context && !TYPE_P (context))
4185 context = NULL_TREE;
4190 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4191 addition order, and correct that in reverse_all_dies. */
4194 add_dwarf_attr (die, attr)
4195 register dw_die_ref die;
4196 register dw_attr_ref attr;
4198 if (die != NULL && attr != NULL)
4200 attr->dw_attr_next = die->die_attr;
4201 die->die_attr = attr;
4205 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4206 static inline dw_val_class
4210 return a->dw_attr_val.val_class;
4213 /* Add a flag value attribute to a DIE. */
4216 add_AT_flag (die, attr_kind, flag)
4217 register dw_die_ref die;
4218 register enum dwarf_attribute attr_kind;
4219 register unsigned flag;
4221 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4223 attr->dw_attr_next = NULL;
4224 attr->dw_attr = attr_kind;
4225 attr->dw_attr_val.val_class = dw_val_class_flag;
4226 attr->dw_attr_val.v.val_flag = flag;
4227 add_dwarf_attr (die, attr);
4230 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4231 static inline unsigned
4233 register dw_attr_ref a;
4235 if (a && AT_class (a) == dw_val_class_flag)
4236 return a->dw_attr_val.v.val_flag;
4241 /* Add a signed integer attribute value to a DIE. */
4244 add_AT_int (die, attr_kind, int_val)
4245 register dw_die_ref die;
4246 register enum dwarf_attribute attr_kind;
4247 register long int int_val;
4249 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4251 attr->dw_attr_next = NULL;
4252 attr->dw_attr = attr_kind;
4253 attr->dw_attr_val.val_class = dw_val_class_const;
4254 attr->dw_attr_val.v.val_int = int_val;
4255 add_dwarf_attr (die, attr);
4258 static inline long int AT_int PARAMS ((dw_attr_ref));
4259 static inline long int
4261 register dw_attr_ref a;
4263 if (a && AT_class (a) == dw_val_class_const)
4264 return a->dw_attr_val.v.val_int;
4269 /* Add an unsigned integer attribute value to a DIE. */
4272 add_AT_unsigned (die, attr_kind, unsigned_val)
4273 register dw_die_ref die;
4274 register enum dwarf_attribute attr_kind;
4275 register unsigned long unsigned_val;
4277 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4279 attr->dw_attr_next = NULL;
4280 attr->dw_attr = attr_kind;
4281 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4282 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4283 add_dwarf_attr (die, attr);
4286 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4287 static inline unsigned long
4289 register dw_attr_ref a;
4291 if (a && AT_class (a) == dw_val_class_unsigned_const)
4292 return a->dw_attr_val.v.val_unsigned;
4297 /* Add an unsigned double integer attribute value to a DIE. */
4300 add_AT_long_long (die, attr_kind, val_hi, val_low)
4301 register dw_die_ref die;
4302 register enum dwarf_attribute attr_kind;
4303 register unsigned long val_hi;
4304 register unsigned long val_low;
4306 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4308 attr->dw_attr_next = NULL;
4309 attr->dw_attr = attr_kind;
4310 attr->dw_attr_val.val_class = dw_val_class_long_long;
4311 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4312 attr->dw_attr_val.v.val_long_long.low = val_low;
4313 add_dwarf_attr (die, attr);
4316 /* Add a floating point attribute value to a DIE and return it. */
4319 add_AT_float (die, attr_kind, length, array)
4320 register dw_die_ref die;
4321 register enum dwarf_attribute attr_kind;
4322 register unsigned length;
4323 register long *array;
4325 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4327 attr->dw_attr_next = NULL;
4328 attr->dw_attr = attr_kind;
4329 attr->dw_attr_val.val_class = dw_val_class_float;
4330 attr->dw_attr_val.v.val_float.length = length;
4331 attr->dw_attr_val.v.val_float.array = array;
4332 add_dwarf_attr (die, attr);
4335 /* Add a string attribute value to a DIE. */
4338 add_AT_string (die, attr_kind, str)
4339 register dw_die_ref die;
4340 register enum dwarf_attribute attr_kind;
4341 register const char *str;
4343 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4345 attr->dw_attr_next = NULL;
4346 attr->dw_attr = attr_kind;
4347 attr->dw_attr_val.val_class = dw_val_class_str;
4348 attr->dw_attr_val.v.val_str = xstrdup (str);
4349 add_dwarf_attr (die, attr);
4352 static inline const char *AT_string PARAMS ((dw_attr_ref));
4353 static inline const char *
4355 register dw_attr_ref a;
4357 if (a && AT_class (a) == dw_val_class_str)
4358 return a->dw_attr_val.v.val_str;
4363 /* Add a DIE reference attribute value to a DIE. */
4366 add_AT_die_ref (die, attr_kind, targ_die)
4367 register dw_die_ref die;
4368 register enum dwarf_attribute attr_kind;
4369 register dw_die_ref targ_die;
4371 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4373 attr->dw_attr_next = NULL;
4374 attr->dw_attr = attr_kind;
4375 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4376 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4377 attr->dw_attr_val.v.val_die_ref.external = 0;
4378 add_dwarf_attr (die, attr);
4381 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4382 static inline dw_die_ref
4384 register dw_attr_ref a;
4386 if (a && AT_class (a) == dw_val_class_die_ref)
4387 return a->dw_attr_val.v.val_die_ref.die;
4392 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4395 register dw_attr_ref a;
4397 if (a && AT_class (a) == dw_val_class_die_ref)
4398 return a->dw_attr_val.v.val_die_ref.external;
4403 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4405 set_AT_ref_external (a, i)
4406 register dw_attr_ref a;
4409 if (a && AT_class (a) == dw_val_class_die_ref)
4410 a->dw_attr_val.v.val_die_ref.external = i;
4415 /* Add an FDE reference attribute value to a DIE. */
4418 add_AT_fde_ref (die, attr_kind, targ_fde)
4419 register dw_die_ref die;
4420 register enum dwarf_attribute attr_kind;
4421 register unsigned targ_fde;
4423 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4425 attr->dw_attr_next = NULL;
4426 attr->dw_attr = attr_kind;
4427 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4428 attr->dw_attr_val.v.val_fde_index = targ_fde;
4429 add_dwarf_attr (die, attr);
4432 /* Add a location description attribute value to a DIE. */
4435 add_AT_loc (die, attr_kind, loc)
4436 register dw_die_ref die;
4437 register enum dwarf_attribute attr_kind;
4438 register dw_loc_descr_ref loc;
4440 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4442 attr->dw_attr_next = NULL;
4443 attr->dw_attr = attr_kind;
4444 attr->dw_attr_val.val_class = dw_val_class_loc;
4445 attr->dw_attr_val.v.val_loc = loc;
4446 add_dwarf_attr (die, attr);
4449 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4450 static inline dw_loc_descr_ref
4452 register dw_attr_ref a;
4454 if (a && AT_class (a) == dw_val_class_loc)
4455 return a->dw_attr_val.v.val_loc;
4461 add_AT_loc_list (die, attr_kind, loc_list)
4462 register dw_die_ref die;
4463 register enum dwarf_attribute attr_kind;
4464 register dw_loc_list_ref loc_list;
4466 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4468 attr->dw_attr_next = NULL;
4469 attr->dw_attr = attr_kind;
4470 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4471 attr->dw_attr_val.v.val_loc_list = loc_list;
4472 add_dwarf_attr (die, attr);
4473 have_location_lists = 1;
4476 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4478 static inline dw_loc_list_ref
4480 register dw_attr_ref a;
4482 if (a && AT_class (a) == dw_val_class_loc_list)
4483 return a->dw_attr_val.v.val_loc_list;
4488 /* Add an address constant attribute value to a DIE. */
4491 add_AT_addr (die, attr_kind, addr)
4492 register dw_die_ref die;
4493 register enum dwarf_attribute attr_kind;
4496 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4498 attr->dw_attr_next = NULL;
4499 attr->dw_attr = attr_kind;
4500 attr->dw_attr_val.val_class = dw_val_class_addr;
4501 attr->dw_attr_val.v.val_addr = addr;
4502 add_dwarf_attr (die, attr);
4505 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4508 register dw_attr_ref a;
4510 if (a && AT_class (a) == dw_val_class_addr)
4511 return a->dw_attr_val.v.val_addr;
4516 /* Add a label identifier attribute value to a DIE. */
4519 add_AT_lbl_id (die, attr_kind, lbl_id)
4520 register dw_die_ref die;
4521 register enum dwarf_attribute attr_kind;
4522 register const char *lbl_id;
4524 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4526 attr->dw_attr_next = NULL;
4527 attr->dw_attr = attr_kind;
4528 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4529 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4530 add_dwarf_attr (die, attr);
4533 /* Add a section offset attribute value to a DIE. */
4536 add_AT_lbl_offset (die, attr_kind, label)
4537 register dw_die_ref die;
4538 register enum dwarf_attribute attr_kind;
4539 register const char *label;
4541 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4543 attr->dw_attr_next = NULL;
4544 attr->dw_attr = attr_kind;
4545 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4546 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4547 add_dwarf_attr (die, attr);
4550 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4551 static inline const char *
4553 register dw_attr_ref a;
4555 if (a && (AT_class (a) == dw_val_class_lbl_id
4556 || AT_class (a) == dw_val_class_lbl_offset))
4557 return a->dw_attr_val.v.val_lbl_id;
4562 /* Get the attribute of type attr_kind. */
4564 static inline dw_attr_ref
4565 get_AT (die, attr_kind)
4566 register dw_die_ref die;
4567 register enum dwarf_attribute attr_kind;
4569 register dw_attr_ref a;
4570 register dw_die_ref spec = NULL;
4574 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4576 if (a->dw_attr == attr_kind)
4579 if (a->dw_attr == DW_AT_specification
4580 || a->dw_attr == DW_AT_abstract_origin)
4585 return get_AT (spec, attr_kind);
4591 /* Return the "low pc" attribute value, typically associated with
4592 a subprogram DIE. Return null if the "low pc" attribute is
4593 either not prsent, or if it cannot be represented as an
4594 assembler label identifier. */
4596 static inline const char *
4598 register dw_die_ref die;
4600 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4601 return a ? AT_lbl (a) : NULL;
4604 /* Return the "high pc" attribute value, typically associated with
4605 a subprogram DIE. Return null if the "high pc" attribute is
4606 either not prsent, or if it cannot be represented as an
4607 assembler label identifier. */
4609 static inline const char *
4611 register dw_die_ref die;
4613 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4614 return a ? AT_lbl (a) : NULL;
4617 /* Return the value of the string attribute designated by ATTR_KIND, or
4618 NULL if it is not present. */
4620 static inline const char *
4621 get_AT_string (die, attr_kind)
4622 register dw_die_ref die;
4623 register enum dwarf_attribute attr_kind;
4625 register dw_attr_ref a = get_AT (die, attr_kind);
4626 return a ? AT_string (a) : NULL;
4629 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4630 if it is not present. */
4633 get_AT_flag (die, attr_kind)
4634 register dw_die_ref die;
4635 register enum dwarf_attribute attr_kind;
4637 register dw_attr_ref a = get_AT (die, attr_kind);
4638 return a ? AT_flag (a) : 0;
4641 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4642 if it is not present. */
4644 static inline unsigned
4645 get_AT_unsigned (die, attr_kind)
4646 register dw_die_ref die;
4647 register enum dwarf_attribute attr_kind;
4649 register dw_attr_ref a = get_AT (die, attr_kind);
4650 return a ? AT_unsigned (a) : 0;
4653 static inline dw_die_ref
4654 get_AT_ref (die, attr_kind)
4656 register enum dwarf_attribute attr_kind;
4658 register dw_attr_ref a = get_AT (die, attr_kind);
4659 return a ? AT_ref (a) : NULL;
4665 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4667 return (lang == DW_LANG_C || lang == DW_LANG_C89
4668 || lang == DW_LANG_C_plus_plus);
4674 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4676 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4682 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4684 return (lang == DW_LANG_Java);
4687 /* Free up the memory used by A. */
4689 static inline void free_AT PARAMS ((dw_attr_ref));
4694 switch (AT_class (a))
4696 case dw_val_class_str:
4697 case dw_val_class_lbl_id:
4698 case dw_val_class_lbl_offset:
4699 free (a->dw_attr_val.v.val_str);
4702 case dw_val_class_float:
4703 free (a->dw_attr_val.v.val_float.array);
4713 /* Remove the specified attribute if present. */
4716 remove_AT (die, attr_kind)
4717 register dw_die_ref die;
4718 register enum dwarf_attribute attr_kind;
4720 register dw_attr_ref *p;
4721 register dw_attr_ref removed = NULL;
4725 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4726 if ((*p)->dw_attr == attr_kind)
4729 *p = (*p)->dw_attr_next;
4738 /* Free up the memory used by DIE. */
4740 static inline void free_die PARAMS ((dw_die_ref));
4745 remove_children (die);
4749 /* Discard the children of this DIE. */
4752 remove_children (die)
4753 register dw_die_ref die;
4755 register dw_die_ref child_die = die->die_child;
4757 die->die_child = NULL;
4759 while (child_die != NULL)
4761 register dw_die_ref tmp_die = child_die;
4762 register dw_attr_ref a;
4764 child_die = child_die->die_sib;
4766 for (a = tmp_die->die_attr; a != NULL;)
4768 register dw_attr_ref tmp_a = a;
4770 a = a->dw_attr_next;
4778 /* Add a child DIE below its parent. We build the lists up in reverse
4779 addition order, and correct that in reverse_all_dies. */
4782 add_child_die (die, child_die)
4783 register dw_die_ref die;
4784 register dw_die_ref child_die;
4786 if (die != NULL && child_die != NULL)
4788 if (die == child_die)
4790 child_die->die_parent = die;
4791 child_die->die_sib = die->die_child;
4792 die->die_child = child_die;
4796 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4797 is the specification, to the front of PARENT's list of children. */
4800 splice_child_die (parent, child)
4801 dw_die_ref parent, child;
4805 /* We want the declaration DIE from inside the class, not the
4806 specification DIE at toplevel. */
4807 if (child->die_parent != parent)
4809 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4814 if (child->die_parent != parent
4815 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4818 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4821 *p = child->die_sib;
4825 child->die_sib = parent->die_child;
4826 parent->die_child = child;
4829 /* Return a pointer to a newly created DIE node. */
4831 static inline dw_die_ref
4832 new_die (tag_value, parent_die)
4833 register enum dwarf_tag tag_value;
4834 register dw_die_ref parent_die;
4836 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4838 die->die_tag = tag_value;
4840 if (parent_die != NULL)
4841 add_child_die (parent_die, die);
4844 limbo_die_node *limbo_node;
4846 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4847 limbo_node->die = die;
4848 limbo_node->next = limbo_die_list;
4849 limbo_die_list = limbo_node;
4855 /* Return the DIE associated with the given type specifier. */
4857 static inline dw_die_ref
4858 lookup_type_die (type)
4861 if (TREE_CODE (type) == VECTOR_TYPE)
4862 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4863 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4866 /* Equate a DIE to a given type specifier. */
4869 equate_type_number_to_die (type, type_die)
4871 register dw_die_ref type_die;
4873 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4876 /* Return the DIE associated with a given declaration. */
4878 static inline dw_die_ref
4879 lookup_decl_die (decl)
4882 register unsigned decl_id = DECL_UID (decl);
4884 return (decl_id < decl_die_table_in_use
4885 ? decl_die_table[decl_id] : NULL);
4888 /* Equate a DIE to a particular declaration. */
4891 equate_decl_number_to_die (decl, decl_die)
4893 register dw_die_ref decl_die;
4895 register unsigned decl_id = DECL_UID (decl);
4896 register unsigned num_allocated;
4898 if (decl_id >= decl_die_table_allocated)
4901 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4902 / DECL_DIE_TABLE_INCREMENT)
4903 * DECL_DIE_TABLE_INCREMENT;
4906 = (dw_die_ref *) xrealloc (decl_die_table,
4907 sizeof (dw_die_ref) * num_allocated);
4909 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4910 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4911 decl_die_table_allocated = num_allocated;
4914 if (decl_id >= decl_die_table_in_use)
4915 decl_die_table_in_use = (decl_id + 1);
4917 decl_die_table[decl_id] = decl_die;
4920 /* Keep track of the number of spaces used to indent the
4921 output of the debugging routines that print the structure of
4922 the DIE internal representation. */
4923 static int print_indent;
4925 /* Indent the line the number of spaces given by print_indent. */
4928 print_spaces (outfile)
4931 fprintf (outfile, "%*s", print_indent, "");
4934 /* Print the information associated with a given DIE, and its children.
4935 This routine is a debugging aid only. */
4938 print_die (die, outfile)
4942 register dw_attr_ref a;
4943 register dw_die_ref c;
4945 print_spaces (outfile);
4946 fprintf (outfile, "DIE %4lu: %s\n",
4947 die->die_offset, dwarf_tag_name (die->die_tag));
4948 print_spaces (outfile);
4949 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4950 fprintf (outfile, " offset: %lu\n", die->die_offset);
4952 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4954 print_spaces (outfile);
4955 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4957 switch (AT_class (a))
4959 case dw_val_class_addr:
4960 fprintf (outfile, "address");
4962 case dw_val_class_loc:
4963 fprintf (outfile, "location descriptor");
4965 case dw_val_class_loc_list:
4966 fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol);
4968 case dw_val_class_const:
4969 fprintf (outfile, "%ld", AT_int (a));
4971 case dw_val_class_unsigned_const:
4972 fprintf (outfile, "%lu", AT_unsigned (a));
4974 case dw_val_class_long_long:
4975 fprintf (outfile, "constant (%lu,%lu)",
4976 a->dw_attr_val.v.val_long_long.hi,
4977 a->dw_attr_val.v.val_long_long.low);
4979 case dw_val_class_float:
4980 fprintf (outfile, "floating-point constant");
4982 case dw_val_class_flag:
4983 fprintf (outfile, "%u", AT_flag (a));
4985 case dw_val_class_die_ref:
4986 if (AT_ref (a) != NULL)
4988 if (AT_ref (a)->die_symbol)
4989 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4991 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4994 fprintf (outfile, "die -> <null>");
4996 case dw_val_class_lbl_id:
4997 case dw_val_class_lbl_offset:
4998 fprintf (outfile, "label: %s", AT_lbl (a));
5000 case dw_val_class_str:
5001 if (AT_string (a) != NULL)
5002 fprintf (outfile, "\"%s\"", AT_string (a));
5004 fprintf (outfile, "<null>");
5010 fprintf (outfile, "\n");
5013 if (die->die_child != NULL)
5016 for (c = die->die_child; c != NULL; c = c->die_sib)
5017 print_die (c, outfile);
5021 if (print_indent == 0)
5022 fprintf (outfile, "\n");
5025 /* Print the contents of the source code line number correspondence table.
5026 This routine is a debugging aid only. */
5029 print_dwarf_line_table (outfile)
5032 register unsigned i;
5033 register dw_line_info_ref line_info;
5035 fprintf (outfile, "\n\nDWARF source line information\n");
5036 for (i = 1; i < line_info_table_in_use; ++i)
5038 line_info = &line_info_table[i];
5039 fprintf (outfile, "%5d: ", i);
5040 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5041 fprintf (outfile, "%6ld", line_info->dw_line_num);
5042 fprintf (outfile, "\n");
5045 fprintf (outfile, "\n\n");
5048 /* Print the information collected for a given DIE. */
5051 debug_dwarf_die (die)
5054 print_die (die, stderr);
5057 /* Print all DWARF information collected for the compilation unit.
5058 This routine is a debugging aid only. */
5064 print_die (comp_unit_die, stderr);
5065 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5066 print_dwarf_line_table (stderr);
5069 /* We build up the lists of children and attributes by pushing new ones
5070 onto the beginning of the list. Reverse the lists for DIE so that
5071 they are in order of addition. */
5074 reverse_die_lists (die)
5075 register dw_die_ref die;
5077 register dw_die_ref c, cp, cn;
5078 register dw_attr_ref a, ap, an;
5080 for (a = die->die_attr, ap = 0; a; a = an)
5082 an = a->dw_attr_next;
5083 a->dw_attr_next = ap;
5088 for (c = die->die_child, cp = 0; c; c = cn)
5094 die->die_child = cp;
5097 /* reverse_die_lists only reverses the single die you pass it. Since
5098 we used to reverse all dies in add_sibling_attributes, which runs
5099 through all the dies, it would reverse all the dies. Now, however,
5100 since we don't call reverse_die_lists in add_sibling_attributes, we
5101 need a routine to recursively reverse all the dies. This is that
5105 reverse_all_dies (die)
5106 register dw_die_ref die;
5108 register dw_die_ref c;
5110 reverse_die_lists (die);
5112 for (c = die->die_child; c; c = c->die_sib)
5113 reverse_all_dies (c);
5116 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5117 the CU for the enclosing include file, if any. BINCL_DIE is the
5118 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5122 push_new_compile_unit (old_unit, bincl_die)
5123 dw_die_ref old_unit, bincl_die;
5125 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5126 dw_die_ref new_unit = gen_compile_unit_die (filename);
5127 new_unit->die_sib = old_unit;
5131 /* Close an include-file CU and reopen the enclosing one. */
5134 pop_compile_unit (old_unit)
5135 dw_die_ref old_unit;
5137 dw_die_ref new_unit = old_unit->die_sib;
5138 old_unit->die_sib = NULL;
5142 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5143 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5145 /* Calculate the checksum of a location expression. */
5148 loc_checksum (loc, ctx)
5149 dw_loc_descr_ref loc;
5150 struct md5_ctx *ctx;
5152 PROCESS (loc->dw_loc_opc);
5153 PROCESS (loc->dw_loc_oprnd1);
5154 PROCESS (loc->dw_loc_oprnd2);
5157 /* Calculate the checksum of an attribute. */
5160 attr_checksum (at, ctx)
5162 struct md5_ctx *ctx;
5164 dw_loc_descr_ref loc;
5167 PROCESS (at->dw_attr);
5169 /* We don't care about differences in file numbering. */
5170 if (at->dw_attr == DW_AT_decl_file
5171 /* Or that this was compiled with a different compiler snapshot; if
5172 the output is the same, that's what matters. */
5173 || at->dw_attr == DW_AT_producer)
5176 switch (AT_class (at))
5178 case dw_val_class_const:
5179 PROCESS (at->dw_attr_val.v.val_int);
5181 case dw_val_class_unsigned_const:
5182 PROCESS (at->dw_attr_val.v.val_unsigned);
5184 case dw_val_class_long_long:
5185 PROCESS (at->dw_attr_val.v.val_long_long);
5187 case dw_val_class_float:
5188 PROCESS (at->dw_attr_val.v.val_float);
5190 case dw_val_class_flag:
5191 PROCESS (at->dw_attr_val.v.val_flag);
5194 case dw_val_class_str:
5195 PROCESS_STRING (AT_string (at));
5197 case dw_val_class_addr:
5199 switch (GET_CODE (r))
5202 PROCESS_STRING (XSTR (r, 0));
5210 case dw_val_class_loc:
5211 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5212 loc_checksum (loc, ctx);
5215 case dw_val_class_die_ref:
5216 if (AT_ref (at)->die_offset)
5217 PROCESS (AT_ref (at)->die_offset);
5218 /* FIXME else use target die name or something. */
5220 case dw_val_class_fde_ref:
5221 case dw_val_class_lbl_id:
5222 case dw_val_class_lbl_offset:
5229 /* Calculate the checksum of a DIE. */
5232 die_checksum (die, ctx)
5234 struct md5_ctx *ctx;
5239 PROCESS (die->die_tag);
5241 for (a = die->die_attr; a; a = a->dw_attr_next)
5242 attr_checksum (a, ctx);
5244 for (c = die->die_child; c; c = c->die_sib)
5245 die_checksum (c, ctx);
5249 #undef PROCESS_STRING
5251 /* The prefix to attach to symbols on DIEs in the current comdat debug
5253 static char *comdat_symbol_id;
5255 /* The index of the current symbol within the current comdat CU. */
5256 static unsigned int comdat_symbol_number;
5258 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5259 children, and set comdat_symbol_id accordingly. */
5262 compute_section_prefix (unit_die)
5263 dw_die_ref unit_die;
5267 unsigned char checksum[16];
5270 md5_init_ctx (&ctx);
5271 die_checksum (unit_die, &ctx);
5272 md5_finish_ctx (&ctx, checksum);
5274 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5275 name = (char *) alloca (strlen (p) + 64);
5276 sprintf (name, "%s.", p);
5278 clean_symbol_name (name);
5280 p = name + strlen (name);
5281 for (i = 0; i < 4; ++i)
5283 sprintf (p, "%.2x", checksum[i]);
5287 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5288 comdat_symbol_number = 0;
5291 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5297 switch (die->die_tag)
5299 case DW_TAG_array_type:
5300 case DW_TAG_class_type:
5301 case DW_TAG_enumeration_type:
5302 case DW_TAG_pointer_type:
5303 case DW_TAG_reference_type:
5304 case DW_TAG_string_type:
5305 case DW_TAG_structure_type:
5306 case DW_TAG_subroutine_type:
5307 case DW_TAG_union_type:
5308 case DW_TAG_ptr_to_member_type:
5309 case DW_TAG_set_type:
5310 case DW_TAG_subrange_type:
5311 case DW_TAG_base_type:
5312 case DW_TAG_const_type:
5313 case DW_TAG_file_type:
5314 case DW_TAG_packed_type:
5315 case DW_TAG_volatile_type:
5322 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5323 Basically, we want to choose the bits that are likely to be shared between
5324 compilations (types) and leave out the bits that are specific to individual
5325 compilations (functions). */
5332 /* I think we want to leave base types and __vtbl_ptr_type in the
5333 main CU, as we do for stabs. The advantage is a greater
5334 likelihood of sharing between objects that don't include headers
5335 in the same order (and therefore would put the base types in a
5336 different comdat). jason 8/28/00 */
5337 if (c->die_tag == DW_TAG_base_type)
5340 if (c->die_tag == DW_TAG_pointer_type
5341 || c->die_tag == DW_TAG_reference_type
5342 || c->die_tag == DW_TAG_const_type
5343 || c->die_tag == DW_TAG_volatile_type)
5345 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5346 return t ? is_comdat_die (t) : 0;
5350 return is_type_die (c);
5353 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5354 compilation unit. */
5360 if (is_type_die (c))
5362 if (get_AT (c, DW_AT_declaration)
5363 && ! get_AT (c, DW_AT_specification))
5369 gen_internal_sym (prefix)
5373 static int label_num;
5374 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5375 return xstrdup (buf);
5378 /* Assign symbols to all worthy DIEs under DIE. */
5381 assign_symbol_names (die)
5382 register dw_die_ref die;
5384 register dw_die_ref c;
5386 if (is_symbol_die (die))
5388 if (comdat_symbol_id)
5390 char *p = alloca (strlen (comdat_symbol_id) + 64);
5391 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5392 comdat_symbol_id, comdat_symbol_number++);
5393 die->die_symbol = xstrdup (p);
5396 die->die_symbol = gen_internal_sym ("LDIE");
5399 for (c = die->die_child; c != NULL; c = c->die_sib)
5400 assign_symbol_names (c);
5403 /* Traverse the DIE (which is always comp_unit_die), and set up
5404 additional compilation units for each of the include files we see
5405 bracketed by BINCL/EINCL. */
5408 break_out_includes (die)
5409 register dw_die_ref die;
5412 register dw_die_ref unit = NULL;
5413 limbo_die_node *node;
5415 for (ptr = &(die->die_child); *ptr; )
5417 register dw_die_ref c = *ptr;
5419 if (c->die_tag == DW_TAG_GNU_BINCL
5420 || c->die_tag == DW_TAG_GNU_EINCL
5421 || (unit && is_comdat_die (c)))
5423 /* This DIE is for a secondary CU; remove it from the main one. */
5426 if (c->die_tag == DW_TAG_GNU_BINCL)
5428 unit = push_new_compile_unit (unit, c);
5431 else if (c->die_tag == DW_TAG_GNU_EINCL)
5433 unit = pop_compile_unit (unit);
5437 add_child_die (unit, c);
5441 /* Leave this DIE in the main CU. */
5442 ptr = &(c->die_sib);
5448 /* We can only use this in debugging, since the frontend doesn't check
5449 to make sure that we leave every include file we enter. */
5454 assign_symbol_names (die);
5455 for (node = limbo_die_list; node; node = node->next)
5457 compute_section_prefix (node->die);
5458 assign_symbol_names (node->die);
5462 /* Traverse the DIE and add a sibling attribute if it may have the
5463 effect of speeding up access to siblings. To save some space,
5464 avoid generating sibling attributes for DIE's without children. */
5467 add_sibling_attributes (die)
5468 register dw_die_ref die;
5470 register dw_die_ref c;
5472 if (die->die_tag != DW_TAG_compile_unit
5473 && die->die_sib && die->die_child != NULL)
5474 /* Add the sibling link to the front of the attribute list. */
5475 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5477 for (c = die->die_child; c != NULL; c = c->die_sib)
5478 add_sibling_attributes (c);
5481 /* Output all location lists for the DIE and it's children */
5483 output_location_lists (die)
5484 register dw_die_ref die;
5488 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5490 if (AT_class (d_attr) == dw_val_class_loc_list)
5492 output_loc_list (AT_loc_list (d_attr));
5495 for (c = die->die_child; c != NULL; c = c->die_sib)
5496 output_location_lists (c);
5499 /* The format of each DIE (and its attribute value pairs)
5500 is encoded in an abbreviation table. This routine builds the
5501 abbreviation table and assigns a unique abbreviation id for
5502 each abbreviation entry. The children of each die are visited
5506 build_abbrev_table (die)
5507 register dw_die_ref die;
5509 register unsigned long abbrev_id;
5510 register unsigned long n_alloc;
5511 register dw_die_ref c;
5512 register dw_attr_ref d_attr, a_attr;
5514 /* Scan the DIE references, and mark as external any that refer to
5515 DIEs from other CUs (i.e. those which are not marked). */
5516 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5518 if (AT_class (d_attr) == dw_val_class_die_ref
5519 && AT_ref (d_attr)->die_mark == 0)
5521 if (AT_ref (d_attr)->die_symbol == 0)
5523 set_AT_ref_external (d_attr, 1);
5527 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5529 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5531 if (abbrev->die_tag == die->die_tag)
5533 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5535 a_attr = abbrev->die_attr;
5536 d_attr = die->die_attr;
5538 while (a_attr != NULL && d_attr != NULL)
5540 if ((a_attr->dw_attr != d_attr->dw_attr)
5541 || (value_format (a_attr) != value_format (d_attr)))
5544 a_attr = a_attr->dw_attr_next;
5545 d_attr = d_attr->dw_attr_next;
5548 if (a_attr == NULL && d_attr == NULL)
5554 if (abbrev_id >= abbrev_die_table_in_use)
5556 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5558 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5560 = (dw_die_ref *) xrealloc (abbrev_die_table,
5561 sizeof (dw_die_ref) * n_alloc);
5563 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5564 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5565 abbrev_die_table_allocated = n_alloc;
5568 ++abbrev_die_table_in_use;
5569 abbrev_die_table[abbrev_id] = die;
5572 die->die_abbrev = abbrev_id;
5573 for (c = die->die_child; c != NULL; c = c->die_sib)
5574 build_abbrev_table (c);
5577 /* Return the size of a string, including the null byte.
5579 This used to treat backslashes as escapes, and hence they were not included
5580 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5581 which treats a backslash as a backslash, escaping it if necessary, and hence
5582 we must include them in the count. */
5584 static unsigned long
5585 size_of_string (str)
5586 register const char *str;
5588 return strlen (str) + 1;
5591 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5594 constant_size (value)
5595 long unsigned value;
5602 log = floor_log2 (value);
5605 log = 1 << (floor_log2 (log) + 1);
5610 /* Return the size of a DIE, as it is represented in the
5611 .debug_info section. */
5613 static unsigned long
5615 register dw_die_ref die;
5617 register unsigned long size = 0;
5618 register dw_attr_ref a;
5620 size += size_of_uleb128 (die->die_abbrev);
5621 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5623 switch (AT_class (a))
5625 case dw_val_class_addr:
5626 size += DWARF2_ADDR_SIZE;
5628 case dw_val_class_loc:
5630 register unsigned long lsize = size_of_locs (AT_loc (a));
5633 size += constant_size (lsize);
5637 case dw_val_class_loc_list:
5638 size += DWARF_OFFSET_SIZE;
5640 case dw_val_class_const:
5641 size += size_of_sleb128 (AT_int (a));
5643 case dw_val_class_unsigned_const:
5644 size += constant_size (AT_unsigned (a));
5646 case dw_val_class_long_long:
5647 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5649 case dw_val_class_float:
5650 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5652 case dw_val_class_flag:
5655 case dw_val_class_die_ref:
5656 size += DWARF_OFFSET_SIZE;
5658 case dw_val_class_fde_ref:
5659 size += DWARF_OFFSET_SIZE;
5661 case dw_val_class_lbl_id:
5662 size += DWARF2_ADDR_SIZE;
5664 case dw_val_class_lbl_offset:
5665 size += DWARF_OFFSET_SIZE;
5667 case dw_val_class_str:
5668 size += size_of_string (AT_string (a));
5678 /* Size the debugging information associated with a given DIE.
5679 Visits the DIE's children recursively. Updates the global
5680 variable next_die_offset, on each time through. Uses the
5681 current value of next_die_offset to update the die_offset
5682 field in each DIE. */
5685 calc_die_sizes (die)
5688 register dw_die_ref c;
5689 die->die_offset = next_die_offset;
5690 next_die_offset += size_of_die (die);
5692 for (c = die->die_child; c != NULL; c = c->die_sib)
5695 if (die->die_child != NULL)
5696 /* Count the null byte used to terminate sibling lists. */
5697 next_die_offset += 1;
5700 /* Set the marks for a die and its children. We do this so
5701 that we know whether or not a reference needs to use FORM_ref_addr; only
5702 DIEs in the same CU will be marked. We used to clear out the offset
5703 and use that as the flag, but ran into ordering problems. */
5709 register dw_die_ref c;
5711 for (c = die->die_child; c; c = c->die_sib)
5715 /* Clear the marks for a die and its children. */
5721 register dw_die_ref c;
5723 for (c = die->die_child; c; c = c->die_sib)
5727 /* Return the size of the .debug_pubnames table generated for the
5728 compilation unit. */
5730 static unsigned long
5733 register unsigned long size;
5734 register unsigned i;
5736 size = DWARF_PUBNAMES_HEADER_SIZE;
5737 for (i = 0; i < pubname_table_in_use; ++i)
5739 register pubname_ref p = &pubname_table[i];
5740 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5743 size += DWARF_OFFSET_SIZE;
5747 /* Return the size of the information in the .debug_aranges section. */
5749 static unsigned long
5752 register unsigned long size;
5754 size = DWARF_ARANGES_HEADER_SIZE;
5756 /* Count the address/length pair for this compilation unit. */
5757 size += 2 * DWARF2_ADDR_SIZE;
5758 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5760 /* Count the two zero words used to terminated the address range table. */
5761 size += 2 * DWARF2_ADDR_SIZE;
5765 /* Select the encoding of an attribute value. */
5767 static enum dwarf_form
5771 switch (a->dw_attr_val.val_class)
5773 case dw_val_class_addr:
5774 return DW_FORM_addr;
5775 case dw_val_class_loc_list:
5776 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5777 .debug_loc section */
5778 return DW_FORM_data4;
5779 case dw_val_class_loc:
5780 switch (constant_size (size_of_locs (AT_loc (a))))
5783 return DW_FORM_block1;
5785 return DW_FORM_block2;
5789 case dw_val_class_const:
5790 return DW_FORM_sdata;
5791 case dw_val_class_unsigned_const:
5792 switch (constant_size (AT_unsigned (a)))
5795 return DW_FORM_data1;
5797 return DW_FORM_data2;
5799 return DW_FORM_data4;
5801 return DW_FORM_data8;
5805 case dw_val_class_long_long:
5806 return DW_FORM_block1;
5807 case dw_val_class_float:
5808 return DW_FORM_block1;
5809 case dw_val_class_flag:
5810 return DW_FORM_flag;
5811 case dw_val_class_die_ref:
5812 if (AT_ref_external (a))
5813 return DW_FORM_ref_addr;
5816 case dw_val_class_fde_ref:
5817 return DW_FORM_data;
5818 case dw_val_class_lbl_id:
5819 return DW_FORM_addr;
5820 case dw_val_class_lbl_offset:
5821 return DW_FORM_data;
5822 case dw_val_class_str:
5823 return DW_FORM_string;
5829 /* Output the encoding of an attribute value. */
5832 output_value_format (a)
5835 enum dwarf_form form = value_format (a);
5836 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5839 /* Output the .debug_abbrev section which defines the DIE abbreviation
5843 output_abbrev_section ()
5845 unsigned long abbrev_id;
5848 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5850 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5852 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5854 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5855 dwarf_tag_name (abbrev->die_tag));
5857 if (abbrev->die_child != NULL)
5858 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5860 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5862 for (a_attr = abbrev->die_attr; a_attr != NULL;
5863 a_attr = a_attr->dw_attr_next)
5865 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5866 dwarf_attr_name (a_attr->dw_attr));
5867 output_value_format (a_attr);
5870 dw2_asm_output_data (1, 0, NULL);
5871 dw2_asm_output_data (1, 0, NULL);
5874 /* Terminate the table. */
5875 dw2_asm_output_data (1, 0, NULL);
5878 /* Output a symbol we can use to refer to this DIE from another CU. */
5881 output_die_symbol (die)
5882 register dw_die_ref die;
5884 char *sym = die->die_symbol;
5889 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5890 /* We make these global, not weak; if the target doesn't support
5891 .linkonce, it doesn't support combining the sections, so debugging
5893 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5894 ASM_OUTPUT_LABEL (asm_out_file, sym);
5897 /* Return a new location list, given the begin and end range, and the
5898 expression. gensym tells us whether to generate a new internal
5899 symbol for this location list node, which is done for the head of
5901 static inline dw_loc_list_ref
5902 new_loc_list (expr, begin, end, section, gensym)
5903 register dw_loc_descr_ref expr;
5904 register const char *begin;
5905 register const char *end;
5906 register const char *section;
5907 register unsigned gensym;
5909 register dw_loc_list_ref retlist
5910 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
5911 retlist->begin = begin;
5913 retlist->expr = expr;
5914 retlist->section = section;
5916 retlist->ll_symbol = gen_internal_sym ("LLST");
5920 /* Add a location description expression to a location list */
5922 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
5923 register dw_loc_list_ref *list_head;
5924 register dw_loc_descr_ref descr;
5925 register const char *begin;
5926 register const char *end;
5927 register const char *section;
5929 register dw_loc_list_ref *d;
5931 /* Find the end of the chain. */
5932 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
5934 /* Add a new location list node to the list */
5935 *d = new_loc_list (descr, begin, end, section, 0);
5940 /* Output the location list given to us */
5942 output_loc_list (list_head)
5943 register dw_loc_list_ref list_head;
5945 register dw_loc_list_ref curr=list_head;
5946 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
5947 if (strcmp (curr->section, ".text") == 0)
5949 if (DWARF2_ADDR_SIZE == 4)
5950 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0xffffffff, "Location list base address specifier fake entry");
5951 else if (DWARF2_ADDR_SIZE == 8)
5952 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0xffffffffffffffffLL, "Location list base address specifier fake entry");
5955 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, "Location list base address specifier base");
5957 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
5960 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, "Location list begin address (%s)", list_head->ll_symbol);
5961 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, "Location list end address (%s)", list_head->ll_symbol);
5962 size = size_of_locs (curr->expr);
5964 /* Output the block length for this list of location operations. */
5965 dw2_asm_output_data (constant_size (size), size, "%s", "Location expression size");
5967 output_loc_sequence (curr->expr);
5969 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "Location list terminator begin (%s)", list_head->ll_symbol);
5970 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, "Location list terminator end (%s)", list_head->ll_symbol);
5972 /* Output the DIE and its attributes. Called recursively to generate
5973 the definitions of each child DIE. */
5977 register dw_die_ref die;
5979 register dw_attr_ref a;
5980 register dw_die_ref c;
5981 register unsigned long size;
5983 /* If someone in another CU might refer to us, set up a symbol for
5984 them to point to. */
5985 if (die->die_symbol)
5986 output_die_symbol (die);
5988 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5989 die->die_offset, dwarf_tag_name (die->die_tag));
5991 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5993 const char *name = dwarf_attr_name (a->dw_attr);
5995 switch (AT_class (a))
5997 case dw_val_class_addr:
5998 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6001 case dw_val_class_loc:
6002 size = size_of_locs (AT_loc (a));
6004 /* Output the block length for this list of location operations. */
6005 dw2_asm_output_data (constant_size (size), size, "%s", name);
6007 output_loc_sequence (AT_loc (a));
6010 case dw_val_class_const:
6011 /* ??? It would be slightly more efficient to use a scheme like is
6012 used for unsigned constants below, but gdb 4.x does not sign
6013 extend. Gdb 5.x does sign extend. */
6014 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6017 case dw_val_class_unsigned_const:
6018 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6019 AT_unsigned (a), "%s", name);
6022 case dw_val_class_long_long:
6024 unsigned HOST_WIDE_INT first, second;
6026 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6029 if (WORDS_BIG_ENDIAN)
6031 first = a->dw_attr_val.v.val_long_long.hi;
6032 second = a->dw_attr_val.v.val_long_long.low;
6036 first = a->dw_attr_val.v.val_long_long.low;
6037 second = a->dw_attr_val.v.val_long_long.hi;
6039 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6040 first, "long long constant");
6041 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6046 case dw_val_class_float:
6048 register unsigned int i;
6050 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6053 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6054 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6055 "fp constant word %u", i);
6059 case dw_val_class_flag:
6060 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6062 case dw_val_class_loc_list:
6064 char *sym = AT_loc_list (a)->ll_symbol;
6067 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name);
6070 case dw_val_class_die_ref:
6071 if (AT_ref_external (a))
6073 char *sym = AT_ref (a)->die_symbol;
6076 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6078 else if (AT_ref (a)->die_offset == 0)
6081 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6085 case dw_val_class_fde_ref:
6088 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6089 a->dw_attr_val.v.val_fde_index * 2);
6090 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6094 case dw_val_class_lbl_id:
6095 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6098 case dw_val_class_lbl_offset:
6099 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6102 case dw_val_class_str:
6103 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6111 for (c = die->die_child; c != NULL; c = c->die_sib)
6114 if (die->die_child != NULL)
6116 /* Add null byte to terminate sibling list. */
6117 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6122 /* Output the compilation unit that appears at the beginning of the
6123 .debug_info section, and precedes the DIE descriptions. */
6126 output_compilation_unit_header ()
6128 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6129 "Length of Compilation Unit Info");
6131 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6133 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6134 "Offset Into Abbrev. Section");
6136 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6139 /* Output the compilation unit DIE and its children. */
6142 output_comp_unit (die)
6145 const char *secname;
6147 /* Even if there are no children of this DIE, we must output the
6148 information about the compilation unit. Otherwise, on an empty
6149 translation unit, we will generate a present, but empty,
6150 .debug_info section. IRIX 6.5 `nm' will then complain when
6153 Mark all the DIEs in this CU so we know which get local refs. */
6156 build_abbrev_table (die);
6158 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6159 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6160 calc_die_sizes (die);
6162 if (die->die_symbol)
6164 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6165 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6167 die->die_symbol = NULL;
6170 secname = (const char *) DEBUG_INFO_SECTION;
6172 /* Output debugging information. */
6173 ASM_OUTPUT_SECTION (asm_out_file, secname);
6174 output_compilation_unit_header ();
6177 /* Leave the marks on the main CU, so we can check them in
6179 if (die->die_symbol)
6183 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6184 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6185 argument list, and maybe the scope. */
6188 dwarf2_name (decl, scope)
6192 return (*decl_printable_name) (decl, scope ? 1 : 0);
6195 /* Add a new entry to .debug_pubnames if appropriate. */
6198 add_pubname (decl, die)
6204 if (! TREE_PUBLIC (decl))
6207 if (pubname_table_in_use == pubname_table_allocated)
6209 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6210 pubname_table = (pubname_ref) xrealloc
6211 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6214 p = &pubname_table[pubname_table_in_use++];
6217 p->name = xstrdup (dwarf2_name (decl, 1));
6220 /* Output the public names table used to speed up access to externally
6221 visible names. For now, only generate entries for externally
6222 visible procedures. */
6227 register unsigned i;
6228 register unsigned long pubnames_length = size_of_pubnames ();
6230 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6231 "Length of Public Names Info");
6233 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6235 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6236 "Offset of Compilation Unit Info");
6238 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6239 "Compilation Unit Length");
6241 for (i = 0; i < pubname_table_in_use; ++i)
6243 register pubname_ref pub = &pubname_table[i];
6245 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6246 if (pub->die->die_mark == 0)
6249 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6252 dw2_asm_output_nstring (pub->name, -1, "external name");
6255 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6258 /* Add a new entry to .debug_aranges if appropriate. */
6261 add_arange (decl, die)
6265 if (! DECL_SECTION_NAME (decl))
6268 if (arange_table_in_use == arange_table_allocated)
6270 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6272 = (arange_ref) xrealloc (arange_table,
6273 arange_table_allocated * sizeof (dw_die_ref));
6276 arange_table[arange_table_in_use++] = die;
6279 /* Output the information that goes into the .debug_aranges table.
6280 Namely, define the beginning and ending address range of the
6281 text section generated for this compilation unit. */
6286 register unsigned i;
6287 register unsigned long aranges_length = size_of_aranges ();
6289 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6290 "Length of Address Ranges Info");
6292 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6294 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6295 "Offset of Compilation Unit Info");
6297 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6299 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6301 /* We need to align to twice the pointer size here. */
6302 if (DWARF_ARANGES_PAD_SIZE)
6304 /* Pad using a 2 byte words so that padding is correct for any
6306 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6307 2 * DWARF2_ADDR_SIZE);
6308 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6309 dw2_asm_output_data (2, 0, NULL);
6312 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6313 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6314 text_section_label, "Length");
6316 for (i = 0; i < arange_table_in_use; ++i)
6318 dw_die_ref die = arange_table[i];
6320 /* We shouldn't see aranges for DIEs outside of the main CU. */
6321 if (die->die_mark == 0)
6324 if (die->die_tag == DW_TAG_subprogram)
6326 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6328 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6329 get_AT_low_pc (die), "Length");
6333 /* A static variable; extract the symbol from DW_AT_location.
6334 Note that this code isn't currently hit, as we only emit
6335 aranges for functions (jason 9/23/99). */
6337 dw_attr_ref a = get_AT (die, DW_AT_location);
6338 dw_loc_descr_ref loc;
6339 if (! a || AT_class (a) != dw_val_class_loc)
6343 if (loc->dw_loc_opc != DW_OP_addr)
6346 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6347 loc->dw_loc_oprnd1.v.val_addr, "Address");
6348 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6349 get_AT_unsigned (die, DW_AT_byte_size),
6354 /* Output the terminator words. */
6355 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6356 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6360 /* Data structure containing information about input files. */
6363 char *path; /* Complete file name. */
6364 char *fname; /* File name part. */
6365 int length; /* Length of entire string. */
6366 int file_idx; /* Index in input file table. */
6367 int dir_idx; /* Index in directory table. */
6370 /* Data structure containing information about directories with source
6374 char *path; /* Path including directory name. */
6375 int length; /* Path length. */
6376 int prefix; /* Index of directory entry which is a prefix. */
6377 int count; /* Number of files in this directory. */
6378 int dir_idx; /* Index of directory used as base. */
6379 int used; /* Used in the end? */
6382 /* Callback function for file_info comparison. We sort by looking at
6383 the directories in the path. */
6385 file_info_cmp (p1, p2)
6389 const struct file_info *s1 = p1;
6390 const struct file_info *s2 = p2;
6394 /* Take care of file names without directories. */
6395 if (s1->path == s1->fname)
6397 else if (s2->path == s2->fname)
6400 cp1 = (unsigned char *) s1->path;
6401 cp2 = (unsigned char *) s2->path;
6407 /* Reached the end of the first path? */
6408 if (cp1 == (unsigned char *) s1->fname)
6409 /* It doesn't really matter in which order files from the
6410 same directory are sorted in. Therefore don't test for
6411 the second path reaching the end. */
6413 else if (cp2 == (unsigned char *) s2->fname)
6416 /* Character of current path component the same? */
6422 /* Output the directory table and the file name table. We try to minimize
6423 the total amount of memory needed. A heuristic is used to avoid large
6424 slowdowns with many input files. */
6426 output_file_names ()
6428 struct file_info *files;
6429 struct dir_info *dirs;
6438 /* Allocate the various arrays we need. */
6439 files = (struct file_info *) alloca (file_table.in_use
6440 * sizeof (struct file_info));
6441 dirs = (struct dir_info *) alloca (file_table.in_use
6442 * sizeof (struct dir_info));
6444 /* Sort the file names. */
6445 for (i = 1; i < (int) file_table.in_use; ++i)
6449 /* Skip all leading "./". */
6450 f = file_table.table[i];
6451 while (f[0] == '.' && f[1] == '/')
6454 /* Create a new array entry. */
6456 files[i].length = strlen (f);
6457 files[i].file_idx = i;
6459 /* Search for the file name part. */
6460 f = strrchr (f, '/');
6461 files[i].fname = f == NULL ? files[i].path : f + 1;
6463 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6465 /* Find all the different directories used. */
6466 dirs[0].path = files[1].path;
6467 dirs[0].length = files[1].fname - files[1].path;
6468 dirs[0].prefix = -1;
6470 dirs[0].dir_idx = 0;
6472 files[1].dir_idx = 0;
6475 for (i = 2; i < (int) file_table.in_use; ++i)
6476 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6477 && memcmp (dirs[ndirs - 1].path, files[i].path,
6478 dirs[ndirs - 1].length) == 0)
6480 /* Same directory as last entry. */
6481 files[i].dir_idx = ndirs - 1;
6482 ++dirs[ndirs - 1].count;
6488 /* This is a new directory. */
6489 dirs[ndirs].path = files[i].path;
6490 dirs[ndirs].length = files[i].fname - files[i].path;
6491 dirs[ndirs].count = 1;
6492 dirs[ndirs].dir_idx = ndirs;
6493 dirs[ndirs].used = 0;
6494 files[i].dir_idx = ndirs;
6496 /* Search for a prefix. */
6497 dirs[ndirs].prefix = -1;
6498 for (j = 0; j < ndirs; ++j)
6499 if (dirs[j].length < dirs[ndirs].length
6500 && dirs[j].length > 1
6501 && (dirs[ndirs].prefix == -1
6502 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6503 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6504 dirs[ndirs].prefix = j;
6509 /* Now to the actual work. We have to find a subset of the
6510 directories which allow expressing the file name using references
6511 to the directory table with the least amount of characters. We
6512 do not do an exhaustive search where we would have to check out
6513 every combination of every single possible prefix. Instead we
6514 use a heuristic which provides nearly optimal results in most
6515 cases and never is much off. */
6516 saved = (int *) alloca (ndirs * sizeof (int));
6517 savehere = (int *) alloca (ndirs * sizeof (int));
6519 memset (saved, '\0', ndirs * sizeof (saved[0]));
6520 for (i = 0; i < ndirs; ++i)
6525 /* We can always save some space for the current directory. But
6526 this does not mean it will be enough to justify adding the
6528 savehere[i] = dirs[i].length;
6529 total = (savehere[i] - saved[i]) * dirs[i].count;
6531 for (j = i + 1; j < ndirs; ++j)
6535 if (saved[j] < dirs[i].length)
6537 /* Determine whether the dirs[i] path is a prefix of the
6542 while (k != -1 && k != i)
6547 /* Yes it is. We can possibly safe some memory but
6548 writing the filenames in dirs[j] relative to
6550 savehere[j] = dirs[i].length;
6551 total += (savehere[j] - saved[j]) * dirs[j].count;
6556 /* Check whether we can safe enough to justify adding the dirs[i]
6558 if (total > dirs[i].length + 1)
6560 /* It's worthwhile adding. */
6561 for (j = i; j < ndirs; ++j)
6562 if (savehere[j] > 0)
6564 /* Remember how much we saved for this directory so far. */
6565 saved[j] = savehere[j];
6567 /* Remember the prefix directory. */
6568 dirs[j].dir_idx = i;
6573 /* We have to emit them in the order they appear in the file_table
6574 array since the index is used in the debug info generation. To
6575 do this efficiently we generate a back-mapping of the indices
6577 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6578 for (i = 1; i < (int) file_table.in_use; ++i)
6580 backmap[files[i].file_idx] = i;
6581 /* Mark this directory as used. */
6582 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6585 /* That was it. We are ready to emit the information. First the
6586 directory name table. Here we have to make sure that the first
6587 actually emitted directory name has the index one. Zero is
6588 reserved for the current working directory. Make sure we do not
6589 confuse these indices with the one for the constructed table
6590 (even though most of the time they are identical). */
6592 idx_offset = dirs[0].length > 0 ? 1 : 0;
6593 for (i = 1 - idx_offset; i < ndirs; ++i)
6594 if (dirs[i].used != 0)
6596 dirs[i].used = idx++;
6597 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6598 "Directory Entry: 0x%x", dirs[i].used);
6600 dw2_asm_output_data (1, 0, "End directory table");
6602 /* Correct the index for the current working directory entry if it
6604 if (idx_offset == 0)
6607 /* Now write all the file names. */
6608 for (i = 1; i < (int) file_table.in_use; ++i)
6610 int file_idx = backmap[i];
6611 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6613 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6614 "File Entry: 0x%x", i);
6616 /* Include directory index. */
6617 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6619 /* Modification time. */
6620 dw2_asm_output_data_uleb128 (0, NULL);
6622 /* File length in bytes. */
6623 dw2_asm_output_data_uleb128 (0, NULL);
6625 dw2_asm_output_data (1, 0, "End file name table");
6629 /* Output the source line number correspondence information. This
6630 information goes into the .debug_line section. */
6635 char l1[20], l2[20], p1[20], p2[20];
6636 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6637 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6638 register unsigned opc;
6639 register unsigned n_op_args;
6640 register unsigned long lt_index;
6641 register unsigned long current_line;
6642 register long line_offset;
6643 register long line_delta;
6644 register unsigned long current_file;
6645 register unsigned long function;
6647 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6648 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6649 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6650 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6652 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6653 "Length of Source Line Info");
6654 ASM_OUTPUT_LABEL (asm_out_file, l1);
6656 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6658 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6659 ASM_OUTPUT_LABEL (asm_out_file, p1);
6661 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6662 "Minimum Instruction Length");
6664 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6665 "Default is_stmt_start flag");
6667 dw2_asm_output_data (1, DWARF_LINE_BASE,
6668 "Line Base Value (Special Opcodes)");
6670 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6671 "Line Range Value (Special Opcodes)");
6673 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6674 "Special Opcode Base");
6676 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6680 case DW_LNS_advance_pc:
6681 case DW_LNS_advance_line:
6682 case DW_LNS_set_file:
6683 case DW_LNS_set_column:
6684 case DW_LNS_fixed_advance_pc:
6692 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6696 /* Write out the information about the files we use. */
6697 output_file_names ();
6698 ASM_OUTPUT_LABEL (asm_out_file, p2);
6700 /* We used to set the address register to the first location in the text
6701 section here, but that didn't accomplish anything since we already
6702 have a line note for the opening brace of the first function. */
6704 /* Generate the line number to PC correspondence table, encoded as
6705 a series of state machine operations. */
6708 strcpy (prev_line_label, text_section_label);
6709 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6711 register dw_line_info_ref line_info = &line_info_table[lt_index];
6714 /* Disable this optimization for now; GDB wants to see two line notes
6715 at the beginning of a function so it can find the end of the
6718 /* Don't emit anything for redundant notes. Just updating the
6719 address doesn't accomplish anything, because we already assume
6720 that anything after the last address is this line. */
6721 if (line_info->dw_line_num == current_line
6722 && line_info->dw_file_num == current_file)
6726 /* Emit debug info for the address of the current line.
6728 Unfortunately, we have little choice here currently, and must always
6729 use the most general form. Gcc does not know the address delta
6730 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6731 attributes which will give an upper bound on the address range. We
6732 could perhaps use length attributes to determine when it is safe to
6733 use DW_LNS_fixed_advance_pc. */
6735 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6738 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6739 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6740 "DW_LNS_fixed_advance_pc");
6741 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6745 /* This can handle any delta. This takes
6746 4+DWARF2_ADDR_SIZE bytes. */
6747 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6748 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6749 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6750 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6752 strcpy (prev_line_label, line_label);
6754 /* Emit debug info for the source file of the current line, if
6755 different from the previous line. */
6756 if (line_info->dw_file_num != current_file)
6758 current_file = line_info->dw_file_num;
6759 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6760 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6761 file_table.table[current_file]);
6764 /* Emit debug info for the current line number, choosing the encoding
6765 that uses the least amount of space. */
6766 if (line_info->dw_line_num != current_line)
6768 line_offset = line_info->dw_line_num - current_line;
6769 line_delta = line_offset - DWARF_LINE_BASE;
6770 current_line = line_info->dw_line_num;
6771 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6773 /* This can handle deltas from -10 to 234, using the current
6774 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6776 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6777 "line %lu", current_line);
6781 /* This can handle any delta. This takes at least 4 bytes,
6782 depending on the value being encoded. */
6783 dw2_asm_output_data (1, DW_LNS_advance_line,
6784 "advance to line %lu", current_line);
6785 dw2_asm_output_data_sleb128 (line_offset, NULL);
6786 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6791 /* We still need to start a new row, so output a copy insn. */
6792 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6796 /* Emit debug info for the address of the end of the function. */
6799 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6800 "DW_LNS_fixed_advance_pc");
6801 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6805 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6806 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6807 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6808 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6811 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6812 dw2_asm_output_data_uleb128 (1, NULL);
6813 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6818 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6820 register dw_separate_line_info_ref line_info
6821 = &separate_line_info_table[lt_index];
6824 /* Don't emit anything for redundant notes. */
6825 if (line_info->dw_line_num == current_line
6826 && line_info->dw_file_num == current_file
6827 && line_info->function == function)
6831 /* Emit debug info for the address of the current line. If this is
6832 a new function, or the first line of a function, then we need
6833 to handle it differently. */
6834 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6836 if (function != line_info->function)
6838 function = line_info->function;
6840 /* Set the address register to the first line in the function */
6841 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6842 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6843 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6844 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6848 /* ??? See the DW_LNS_advance_pc comment above. */
6851 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6852 "DW_LNS_fixed_advance_pc");
6853 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6857 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6858 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6859 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6860 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6863 strcpy (prev_line_label, line_label);
6865 /* Emit debug info for the source file of the current line, if
6866 different from the previous line. */
6867 if (line_info->dw_file_num != current_file)
6869 current_file = line_info->dw_file_num;
6870 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6871 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6872 file_table.table[current_file]);
6875 /* Emit debug info for the current line number, choosing the encoding
6876 that uses the least amount of space. */
6877 if (line_info->dw_line_num != current_line)
6879 line_offset = line_info->dw_line_num - current_line;
6880 line_delta = line_offset - DWARF_LINE_BASE;
6881 current_line = line_info->dw_line_num;
6882 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6883 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6884 "line %lu", current_line);
6887 dw2_asm_output_data (1, DW_LNS_advance_line,
6888 "advance to line %lu", current_line);
6889 dw2_asm_output_data_sleb128 (line_offset, NULL);
6890 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6894 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6901 /* If we're done with a function, end its sequence. */
6902 if (lt_index == separate_line_info_table_in_use
6903 || separate_line_info_table[lt_index].function != function)
6908 /* Emit debug info for the address of the end of the function. */
6909 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6912 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6913 "DW_LNS_fixed_advance_pc");
6914 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6918 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6919 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6920 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6921 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6924 /* Output the marker for the end of this sequence. */
6925 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6926 dw2_asm_output_data_uleb128 (1, NULL);
6927 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6931 /* Output the marker for the end of the line number info. */
6932 ASM_OUTPUT_LABEL (asm_out_file, l2);
6935 /* Given a pointer to a tree node for some base type, return a pointer to
6936 a DIE that describes the given type.
6938 This routine must only be called for GCC type nodes that correspond to
6939 Dwarf base (fundamental) types. */
6942 base_type_die (type)
6945 register dw_die_ref base_type_result;
6946 register const char *type_name;
6947 register enum dwarf_type encoding;
6948 register tree name = TYPE_NAME (type);
6950 if (TREE_CODE (type) == ERROR_MARK
6951 || TREE_CODE (type) == VOID_TYPE)
6956 if (TREE_CODE (name) == TYPE_DECL)
6957 name = DECL_NAME (name);
6959 type_name = IDENTIFIER_POINTER (name);
6962 type_name = "__unknown__";
6964 switch (TREE_CODE (type))
6967 /* Carefully distinguish the C character types, without messing
6968 up if the language is not C. Note that we check only for the names
6969 that contain spaces; other names might occur by coincidence in other
6971 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6972 && (type == char_type_node
6973 || ! strcmp (type_name, "signed char")
6974 || ! strcmp (type_name, "unsigned char"))))
6976 if (TREE_UNSIGNED (type))
6977 encoding = DW_ATE_unsigned;
6979 encoding = DW_ATE_signed;
6982 /* else fall through. */
6985 /* GNU Pascal/Ada CHAR type. Not used in C. */
6986 if (TREE_UNSIGNED (type))
6987 encoding = DW_ATE_unsigned_char;
6989 encoding = DW_ATE_signed_char;
6993 encoding = DW_ATE_float;
6996 /* Dwarf2 doesn't know anything about complex ints, so use
6997 a user defined type for it. */
6999 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7000 encoding = DW_ATE_complex_float;
7002 encoding = DW_ATE_lo_user;
7006 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7007 encoding = DW_ATE_boolean;
7011 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7014 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7015 if (demangle_name_func)
7016 type_name = (*demangle_name_func) (type_name);
7018 add_AT_string (base_type_result, DW_AT_name, type_name);
7019 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7020 int_size_in_bytes (type));
7021 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7023 return base_type_result;
7026 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7027 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7028 a given type is generally the same as the given type, except that if the
7029 given type is a pointer or reference type, then the root type of the given
7030 type is the root type of the "basis" type for the pointer or reference
7031 type. (This definition of the "root" type is recursive.) Also, the root
7032 type of a `const' qualified type or a `volatile' qualified type is the
7033 root type of the given type without the qualifiers. */
7039 if (TREE_CODE (type) == ERROR_MARK)
7040 return error_mark_node;
7042 switch (TREE_CODE (type))
7045 return error_mark_node;
7048 case REFERENCE_TYPE:
7049 return type_main_variant (root_type (TREE_TYPE (type)));
7052 return type_main_variant (type);
7056 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7057 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7063 switch (TREE_CODE (type))
7078 case QUAL_UNION_TYPE:
7083 case REFERENCE_TYPE:
7097 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7098 entry that chains various modifiers in front of the given type. */
7101 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7103 register int is_const_type;
7104 register int is_volatile_type;
7105 register dw_die_ref context_die;
7107 register enum tree_code code = TREE_CODE (type);
7108 register dw_die_ref mod_type_die = NULL;
7109 register dw_die_ref sub_die = NULL;
7110 register tree item_type = NULL;
7112 if (code != ERROR_MARK)
7114 tree qualified_type;
7116 /* See if we already have the appropriately qualified variant of
7119 = get_qualified_type (type,
7120 ((is_const_type ? TYPE_QUAL_CONST : 0)
7122 ? TYPE_QUAL_VOLATILE : 0)));
7123 /* If we do, then we can just use its DIE, if it exists. */
7126 mod_type_die = lookup_type_die (qualified_type);
7128 return mod_type_die;
7131 /* Handle C typedef types. */
7132 if (qualified_type && TYPE_NAME (qualified_type)
7133 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7134 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7136 tree type_name = TYPE_NAME (qualified_type);
7137 tree dtype = TREE_TYPE (type_name);
7138 if (qualified_type == dtype)
7140 /* For a named type, use the typedef. */
7141 gen_type_die (qualified_type, context_die);
7142 mod_type_die = lookup_type_die (qualified_type);
7145 else if (is_const_type < TYPE_READONLY (dtype)
7146 || is_volatile_type < TYPE_VOLATILE (dtype))
7147 /* cv-unqualified version of named type. Just use the unnamed
7148 type to which it refers. */
7150 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7151 is_const_type, is_volatile_type,
7153 /* Else cv-qualified version of named type; fall through. */
7159 else if (is_const_type)
7161 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7162 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7164 else if (is_volatile_type)
7166 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7167 sub_die = modified_type_die (type, 0, 0, context_die);
7169 else if (code == POINTER_TYPE)
7171 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7172 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7174 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7176 item_type = TREE_TYPE (type);
7178 else if (code == REFERENCE_TYPE)
7180 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7181 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7183 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7185 item_type = TREE_TYPE (type);
7187 else if (is_base_type (type))
7188 mod_type_die = base_type_die (type);
7191 gen_type_die (type, context_die);
7193 /* We have to get the type_main_variant here (and pass that to the
7194 `lookup_type_die' routine) because the ..._TYPE node we have
7195 might simply be a *copy* of some original type node (where the
7196 copy was created to help us keep track of typedef names) and
7197 that copy might have a different TYPE_UID from the original
7199 mod_type_die = lookup_type_die (type_main_variant (type));
7200 if (mod_type_die == NULL)
7204 /* We want to equate the qualified type to the die below. */
7206 type = qualified_type;
7209 equate_type_number_to_die (type, mod_type_die);
7211 /* We must do this after the equate_type_number_to_die call, in case
7212 this is a recursive type. This ensures that the modified_type_die
7213 recursion will terminate even if the type is recursive. Recursive
7214 types are possible in Ada. */
7215 sub_die = modified_type_die (item_type,
7216 TYPE_READONLY (item_type),
7217 TYPE_VOLATILE (item_type),
7220 if (sub_die != NULL)
7221 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7223 return mod_type_die;
7226 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7227 an enumerated type. */
7233 return TREE_CODE (type) == ENUMERAL_TYPE;
7236 /* Return the register number described by a given RTL node. */
7242 register unsigned regno = REGNO (rtl);
7244 if (regno >= FIRST_PSEUDO_REGISTER)
7246 warning ("internal regno botch: regno = %d\n", regno);
7250 regno = DBX_REGISTER_NUMBER (regno);
7254 /* Return a location descriptor that designates a machine register. */
7256 static dw_loc_descr_ref
7257 reg_loc_descriptor (rtl)
7260 register dw_loc_descr_ref loc_result = NULL;
7261 register unsigned reg = reg_number (rtl);
7264 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7266 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7271 /* Return a location descriptor that designates a constant. */
7273 static dw_loc_descr_ref
7274 int_loc_descriptor (i)
7277 enum dwarf_location_atom op;
7279 /* Pick the smallest representation of a constant, rather than just
7280 defaulting to the LEB encoding. */
7284 op = DW_OP_lit0 + i;
7287 else if (i <= 0xffff)
7289 else if (HOST_BITS_PER_WIDE_INT == 32
7299 else if (i >= -0x8000)
7301 else if (HOST_BITS_PER_WIDE_INT == 32
7302 || i >= -0x80000000)
7308 return new_loc_descr (op, i, 0);
7311 /* Return a location descriptor that designates a base+offset location. */
7313 static dw_loc_descr_ref
7314 based_loc_descr (reg, offset)
7318 register dw_loc_descr_ref loc_result;
7319 /* For the "frame base", we use the frame pointer or stack pointer
7320 registers, since the RTL for local variables is relative to one of
7322 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7323 ? HARD_FRAME_POINTER_REGNUM
7324 : STACK_POINTER_REGNUM);
7327 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7329 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7331 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7336 /* Return true if this RTL expression describes a base+offset calculation. */
7342 return (GET_CODE (rtl) == PLUS
7343 && ((GET_CODE (XEXP (rtl, 0)) == REG
7344 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7347 /* The following routine converts the RTL for a variable or parameter
7348 (resident in memory) into an equivalent Dwarf representation of a
7349 mechanism for getting the address of that same variable onto the top of a
7350 hypothetical "address evaluation" stack.
7352 When creating memory location descriptors, we are effectively transforming
7353 the RTL for a memory-resident object into its Dwarf postfix expression
7354 equivalent. This routine recursively descends an RTL tree, turning
7355 it into Dwarf postfix code as it goes.
7357 MODE is the mode of the memory reference, needed to handle some
7358 autoincrement addressing modes. */
7360 static dw_loc_descr_ref
7361 mem_loc_descriptor (rtl, mode)
7363 enum machine_mode mode;
7365 dw_loc_descr_ref mem_loc_result = NULL;
7366 /* Note that for a dynamically sized array, the location we will generate a
7367 description of here will be the lowest numbered location which is
7368 actually within the array. That's *not* necessarily the same as the
7369 zeroth element of the array. */
7371 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7372 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7375 switch (GET_CODE (rtl))
7380 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7381 just fall into the SUBREG code. */
7386 /* The case of a subreg may arise when we have a local (register)
7387 variable or a formal (register) parameter which doesn't quite fill
7388 up an entire register. For now, just assume that it is
7389 legitimate to make the Dwarf info refer to the whole register which
7390 contains the given subreg. */
7391 rtl = SUBREG_REG (rtl);
7396 /* Whenever a register number forms a part of the description of the
7397 method for calculating the (dynamic) address of a memory resident
7398 object, DWARF rules require the register number be referred to as
7399 a "base register". This distinction is not based in any way upon
7400 what category of register the hardware believes the given register
7401 belongs to. This is strictly DWARF terminology we're dealing with
7402 here. Note that in cases where the location of a memory-resident
7403 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7404 OP_CONST (0)) the actual DWARF location descriptor that we generate
7405 may just be OP_BASEREG (basereg). This may look deceptively like
7406 the object in question was allocated to a register (rather than in
7407 memory) so DWARF consumers need to be aware of the subtle
7408 distinction between OP_REG and OP_BASEREG. */
7409 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7413 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7414 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7418 /* Some ports can transform a symbol ref into a label ref, because
7419 the symbol ref is too far away and has to be dumped into a constant
7423 /* Alternatively, the symbol in the constant pool can be referenced
7424 by a different symbol. */
7425 if (GET_CODE (rtl) == SYMBOL_REF
7426 && CONSTANT_POOL_ADDRESS_P (rtl))
7428 rtx tmp = get_pool_constant (rtl);
7429 /* Doesn't work for floating point constants. */
7430 if (! (GET_CODE (tmp) == CONST_DOUBLE && GET_MODE (tmp) != VOIDmode))
7435 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7436 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7437 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7441 /* Extract the PLUS expression nested inside and fall into
7442 PLUS code bellow. */
7443 rtl = XEXP (rtl, 1);
7448 /* Turn these into a PLUS expression and fall into the PLUS code
7450 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7451 GEN_INT (GET_CODE (rtl) == PRE_INC
7452 ? GET_MODE_UNIT_SIZE (mode)
7453 : -GET_MODE_UNIT_SIZE (mode)));
7459 if (is_based_loc (rtl))
7460 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7461 INTVAL (XEXP (rtl, 1)));
7464 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7466 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7467 && INTVAL (XEXP (rtl, 1)) >= 0)
7469 add_loc_descr (&mem_loc_result,
7470 new_loc_descr (DW_OP_plus_uconst,
7471 INTVAL (XEXP (rtl, 1)), 0));
7475 add_loc_descr (&mem_loc_result,
7476 mem_loc_descriptor (XEXP (rtl, 1), mode));
7477 add_loc_descr (&mem_loc_result,
7478 new_loc_descr (DW_OP_plus, 0, 0));
7484 /* If a pseudo-reg is optimized away, it is possible for it to
7485 be replaced with a MEM containing a multiply. */
7486 add_loc_descr (&mem_loc_result,
7487 mem_loc_descriptor (XEXP (rtl, 0), mode));
7488 add_loc_descr (&mem_loc_result,
7489 mem_loc_descriptor (XEXP (rtl, 1), mode));
7490 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7494 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7501 return mem_loc_result;
7504 /* Return a descriptor that describes the concatenation of two locations.
7505 This is typically a complex variable. */
7507 static dw_loc_descr_ref
7508 concat_loc_descriptor (x0, x1)
7509 register rtx x0, x1;
7511 dw_loc_descr_ref cc_loc_result = NULL;
7513 if (!is_pseudo_reg (x0)
7514 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7515 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7516 add_loc_descr (&cc_loc_result,
7517 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7519 if (!is_pseudo_reg (x1)
7520 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7521 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7522 add_loc_descr (&cc_loc_result,
7523 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7525 return cc_loc_result;
7528 /* Output a proper Dwarf location descriptor for a variable or parameter
7529 which is either allocated in a register or in a memory location. For a
7530 register, we just generate an OP_REG and the register number. For a
7531 memory location we provide a Dwarf postfix expression describing how to
7532 generate the (dynamic) address of the object onto the address stack. */
7534 static dw_loc_descr_ref
7535 loc_descriptor (rtl)
7538 dw_loc_descr_ref loc_result = NULL;
7539 switch (GET_CODE (rtl))
7542 /* The case of a subreg may arise when we have a local (register)
7543 variable or a formal (register) parameter which doesn't quite fill
7544 up an entire register. For now, just assume that it is
7545 legitimate to make the Dwarf info refer to the whole register which
7546 contains the given subreg. */
7547 rtl = SUBREG_REG (rtl);
7552 loc_result = reg_loc_descriptor (rtl);
7556 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7560 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7570 /* Similar, but generate the descriptor from trees instead of rtl.
7571 This comes up particularly with variable length arrays. */
7573 static dw_loc_descr_ref
7574 loc_descriptor_from_tree (loc, addressp)
7578 dw_loc_descr_ref ret = NULL;
7579 int indirect_size = 0;
7580 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7581 enum dwarf_location_atom op;
7583 /* ??? Most of the time we do not take proper care for sign/zero
7584 extending the values properly. Hopefully this won't be a real
7587 switch (TREE_CODE (loc))
7592 case WITH_RECORD_EXPR:
7593 /* This case involves extracting fields from an object to determine the
7594 position of other fields. We don't try to encode this here. The
7595 only user of this is Ada, which encodes the needed information using
7596 the names of types. */
7602 rtx rtl = rtl_for_decl_location (loc);
7603 enum machine_mode mode = DECL_MODE (loc);
7605 if (rtl == NULL_RTX)
7607 else if (CONSTANT_P (rtl))
7609 ret = new_loc_descr (DW_OP_addr, 0, 0);
7610 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7611 ret->dw_loc_oprnd1.v.val_addr = rtl;
7612 indirect_size = GET_MODE_SIZE (mode);
7616 if (GET_CODE (rtl) == MEM)
7618 indirect_size = GET_MODE_SIZE (mode);
7619 rtl = XEXP (rtl, 0);
7621 ret = mem_loc_descriptor (rtl, mode);
7627 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7628 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7633 case NON_LVALUE_EXPR:
7635 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7640 case ARRAY_RANGE_REF:
7643 HOST_WIDE_INT bitsize, bitpos, bytepos;
7644 enum machine_mode mode;
7646 unsigned int alignment;
7648 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7649 &unsignedp, &volatilep, &alignment);
7650 ret = loc_descriptor_from_tree (obj, 1);
7652 if (offset != NULL_TREE)
7654 /* Variable offset. */
7655 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7656 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7661 /* We cannot address anything not on a unit boundary. */
7662 if (bitpos % BITS_PER_UNIT != 0)
7667 if (bitpos % BITS_PER_UNIT != 0
7668 || bitsize % BITS_PER_UNIT != 0)
7670 /* ??? We could handle this by loading and shifting etc.
7671 Wait until someone needs it before expending the effort. */
7675 indirect_size = bitsize / BITS_PER_UNIT;
7678 bytepos = bitpos / BITS_PER_UNIT;
7680 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7681 else if (bytepos < 0)
7683 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7684 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7690 if (host_integerp (loc, 0))
7691 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7703 case TRUNC_DIV_EXPR:
7709 case TRUNC_MOD_EXPR:
7719 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7722 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7723 && host_integerp (TREE_OPERAND (loc, 1), 0))
7725 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7726 add_loc_descr (&ret,
7727 new_loc_descr (DW_OP_plus_uconst,
7728 tree_low_cst (TREE_OPERAND (loc, 1),
7736 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7741 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7746 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7751 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7763 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7764 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7765 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7779 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7780 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7784 loc = build (COND_EXPR, TREE_TYPE (loc),
7785 build (LT_EXPR, integer_type_node,
7786 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7787 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7792 dw_loc_descr_ref bra_node, jump_node, tmp;
7794 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7795 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7796 add_loc_descr (&ret, bra_node);
7798 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7799 add_loc_descr (&ret, tmp);
7800 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7801 add_loc_descr (&ret, jump_node);
7803 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7804 add_loc_descr (&ret, tmp);
7805 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7806 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7808 /* ??? Need a node to point the skip at. Use a nop. */
7809 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7810 add_loc_descr (&ret, tmp);
7811 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7812 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7820 /* If we can't fill the request for an address, die. */
7821 if (addressp && indirect_size == 0)
7824 /* If we've got an address and don't want one, dereference. */
7825 if (!addressp && indirect_size > 0)
7827 if (indirect_size > DWARF2_ADDR_SIZE)
7829 if (indirect_size == DWARF2_ADDR_SIZE)
7832 op = DW_OP_deref_size;
7833 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7839 /* Given a value, round it up to the lowest multiple of `boundary'
7840 which is not less than the value itself. */
7842 static inline HOST_WIDE_INT
7843 ceiling (value, boundary)
7844 HOST_WIDE_INT value;
7845 unsigned int boundary;
7847 return (((value + boundary - 1) / boundary) * boundary);
7850 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7851 pointer to the declared type for the relevant field variable, or return
7852 `integer_type_node' if the given node turns out to be an
7861 if (TREE_CODE (decl) == ERROR_MARK)
7862 return integer_type_node;
7864 type = DECL_BIT_FIELD_TYPE (decl);
7865 if (type == NULL_TREE)
7866 type = TREE_TYPE (decl);
7871 /* Given a pointer to a tree node, return the alignment in bits for
7872 it, or else return BITS_PER_WORD if the node actually turns out to
7873 be an ERROR_MARK node. */
7875 static inline unsigned
7876 simple_type_align_in_bits (type)
7879 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7882 static inline unsigned
7883 simple_decl_align_in_bits (decl)
7886 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7889 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7890 node, return the size in bits for the type if it is a constant, or else
7891 return the alignment for the type if the type's size is not constant, or
7892 else return BITS_PER_WORD if the type actually turns out to be an
7895 static inline unsigned HOST_WIDE_INT
7896 simple_type_size_in_bits (type)
7899 tree type_size_tree;
7901 if (TREE_CODE (type) == ERROR_MARK)
7902 return BITS_PER_WORD;
7903 type_size_tree = TYPE_SIZE (type);
7905 if (type_size_tree == NULL_TREE)
7907 if (! host_integerp (type_size_tree, 1))
7908 return TYPE_ALIGN (type);
7909 return tree_low_cst (type_size_tree, 1);
7912 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7913 return the byte offset of the lowest addressed byte of the "containing
7914 object" for the given FIELD_DECL, or return 0 if we are unable to
7915 determine what that offset is, either because the argument turns out to
7916 be a pointer to an ERROR_MARK node, or because the offset is actually
7917 variable. (We can't handle the latter case just yet). */
7919 static HOST_WIDE_INT
7920 field_byte_offset (decl)
7923 unsigned int type_align_in_bits;
7924 unsigned int decl_align_in_bits;
7925 unsigned HOST_WIDE_INT type_size_in_bits;
7926 HOST_WIDE_INT object_offset_in_bits;
7927 HOST_WIDE_INT object_offset_in_bytes;
7929 tree field_size_tree;
7930 HOST_WIDE_INT bitpos_int;
7931 HOST_WIDE_INT deepest_bitpos;
7932 unsigned HOST_WIDE_INT field_size_in_bits;
7934 if (TREE_CODE (decl) == ERROR_MARK)
7937 if (TREE_CODE (decl) != FIELD_DECL)
7940 type = field_type (decl);
7941 field_size_tree = DECL_SIZE (decl);
7943 /* The size could be unspecified if there was an error, or for
7944 a flexible array member. */
7945 if (! field_size_tree)
7946 field_size_tree = bitsize_zero_node;
7948 /* We cannot yet cope with fields whose positions are variable, so
7949 for now, when we see such things, we simply return 0. Someday, we may
7950 be able to handle such cases, but it will be damn difficult. */
7951 if (! host_integerp (bit_position (decl), 0))
7954 bitpos_int = int_bit_position (decl);
7956 /* If we don't know the size of the field, pretend it's a full word. */
7957 if (host_integerp (field_size_tree, 1))
7958 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7960 field_size_in_bits = BITS_PER_WORD;
7962 type_size_in_bits = simple_type_size_in_bits (type);
7963 type_align_in_bits = simple_type_align_in_bits (type);
7964 decl_align_in_bits = simple_decl_align_in_bits (decl);
7966 /* Note that the GCC front-end doesn't make any attempt to keep track of
7967 the starting bit offset (relative to the start of the containing
7968 structure type) of the hypothetical "containing object" for a bit-
7969 field. Thus, when computing the byte offset value for the start of the
7970 "containing object" of a bit-field, we must deduce this information on
7971 our own. This can be rather tricky to do in some cases. For example,
7972 handling the following structure type definition when compiling for an
7973 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7976 struct S { int field1; long long field2:31; };
7978 Fortunately, there is a simple rule-of-thumb which can be
7979 used in such cases. When compiling for an i386/i486, GCC will allocate
7980 8 bytes for the structure shown above. It decides to do this based upon
7981 one simple rule for bit-field allocation. Quite simply, GCC allocates
7982 each "containing object" for each bit-field at the first (i.e. lowest
7983 addressed) legitimate alignment boundary (based upon the required
7984 minimum alignment for the declared type of the field) which it can
7985 possibly use, subject to the condition that there is still enough
7986 available space remaining in the containing object (when allocated at
7987 the selected point) to fully accommodate all of the bits of the
7988 bit-field itself. This simple rule makes it obvious why GCC allocates
7989 8 bytes for each object of the structure type shown above. When looking
7990 for a place to allocate the "containing object" for `field2', the
7991 compiler simply tries to allocate a 64-bit "containing object" at each
7992 successive 32-bit boundary (starting at zero) until it finds a place to
7993 allocate that 64- bit field such that at least 31 contiguous (and
7994 previously unallocated) bits remain within that selected 64 bit field.
7995 (As it turns out, for the example above, the compiler finds that it is
7996 OK to allocate the "containing object" 64-bit field at bit-offset zero
7997 within the structure type.) Here we attempt to work backwards from the
7998 limited set of facts we're given, and we try to deduce from those facts,
7999 where GCC must have believed that the containing object started (within
8000 the structure type). The value we deduce is then used (by the callers of
8001 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8002 for fields (both bit-fields and, in the case of DW_AT_location, regular
8005 /* Figure out the bit-distance from the start of the structure to the
8006 "deepest" bit of the bit-field. */
8007 deepest_bitpos = bitpos_int + field_size_in_bits;
8009 /* This is the tricky part. Use some fancy footwork to deduce where the
8010 lowest addressed bit of the containing object must be. */
8011 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8013 /* Round up to type_align by default. This works best for bitfields. */
8014 object_offset_in_bits += type_align_in_bits - 1;
8015 object_offset_in_bits /= type_align_in_bits;
8016 object_offset_in_bits *= type_align_in_bits;
8018 if (object_offset_in_bits > bitpos_int)
8020 /* Sigh, the decl must be packed. */
8021 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8023 /* Round up to decl_align instead. */
8024 object_offset_in_bits += decl_align_in_bits - 1;
8025 object_offset_in_bits /= decl_align_in_bits;
8026 object_offset_in_bits *= decl_align_in_bits;
8029 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8031 return object_offset_in_bytes;
8034 /* The following routines define various Dwarf attributes and any data
8035 associated with them. */
8037 /* Add a location description attribute value to a DIE.
8039 This emits location attributes suitable for whole variables and
8040 whole parameters. Note that the location attributes for struct fields are
8041 generated by the routine `data_member_location_attribute' below. */
8044 add_AT_location_description (die, attr_kind, rtl)
8046 enum dwarf_attribute attr_kind;
8049 /* Handle a special case. If we are about to output a location descriptor
8050 for a variable or parameter which has been optimized out of existence,
8051 don't do that. A variable which has been optimized out
8052 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8053 Currently, in some rare cases, variables can have DECL_RTL values which
8054 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8055 elsewhere in the compiler. We treat such cases as if the variable(s) in
8056 question had been optimized out of existence. */
8058 if (is_pseudo_reg (rtl)
8059 || (GET_CODE (rtl) == MEM
8060 && is_pseudo_reg (XEXP (rtl, 0)))
8061 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8062 references the internal argument pointer (a pseudo) in a function
8063 where all references to the internal argument pointer were
8064 eliminated via the optimizers. */
8065 || (GET_CODE (rtl) == MEM
8066 && GET_CODE (XEXP (rtl, 0)) == PLUS
8067 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8068 || (GET_CODE (rtl) == CONCAT
8069 && is_pseudo_reg (XEXP (rtl, 0))
8070 && is_pseudo_reg (XEXP (rtl, 1))))
8073 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8076 /* Attach the specialized form of location attribute used for data
8077 members of struct and union types. In the special case of a
8078 FIELD_DECL node which represents a bit-field, the "offset" part
8079 of this special location descriptor must indicate the distance
8080 in bytes from the lowest-addressed byte of the containing struct
8081 or union type to the lowest-addressed byte of the "containing
8082 object" for the bit-field. (See the `field_byte_offset' function
8083 above).. For any given bit-field, the "containing object" is a
8084 hypothetical object (of some integral or enum type) within which
8085 the given bit-field lives. The type of this hypothetical
8086 "containing object" is always the same as the declared type of
8087 the individual bit-field itself (for GCC anyway... the DWARF
8088 spec doesn't actually mandate this). Note that it is the size
8089 (in bytes) of the hypothetical "containing object" which will
8090 be given in the DW_AT_byte_size attribute for this bit-field.
8091 (See the `byte_size_attribute' function below.) It is also used
8092 when calculating the value of the DW_AT_bit_offset attribute.
8093 (See the `bit_offset_attribute' function below). */
8096 add_data_member_location_attribute (die, decl)
8097 register dw_die_ref die;
8100 register unsigned long offset;
8101 register dw_loc_descr_ref loc_descr;
8102 register enum dwarf_location_atom op;
8104 if (TREE_CODE (decl) == TREE_VEC)
8105 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8107 offset = field_byte_offset (decl);
8109 /* The DWARF2 standard says that we should assume that the structure address
8110 is already on the stack, so we can specify a structure field address
8111 by using DW_OP_plus_uconst. */
8113 #ifdef MIPS_DEBUGGING_INFO
8114 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8115 correctly. It works only if we leave the offset on the stack. */
8118 op = DW_OP_plus_uconst;
8121 loc_descr = new_loc_descr (op, offset, 0);
8122 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8125 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8126 does not have a "location" either in memory or in a register. These
8127 things can arise in GNU C when a constant is passed as an actual parameter
8128 to an inlined function. They can also arise in C++ where declared
8129 constants do not necessarily get memory "homes". */
8132 add_const_value_attribute (die, rtl)
8133 register dw_die_ref die;
8136 switch (GET_CODE (rtl))
8139 /* Note that a CONST_INT rtx could represent either an integer
8140 or a floating-point constant. A CONST_INT is used whenever
8141 the constant will fit into a single word. In all such
8142 cases, the original mode of the constant value is wiped
8143 out, and the CONST_INT rtx is assigned VOIDmode. */
8145 HOST_WIDE_INT val = INTVAL (rtl);
8147 /* ??? We really should be using HOST_WIDE_INT throughout. */
8150 if ((long) val != val)
8152 add_AT_int (die, DW_AT_const_value, (long) val);
8156 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8158 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
8164 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8165 floating-point constant. A CONST_DOUBLE is used whenever the
8166 constant requires more than one word in order to be adequately
8167 represented. We output CONST_DOUBLEs as blocks. */
8169 register enum machine_mode mode = GET_MODE (rtl);
8171 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8173 register unsigned length = GET_MODE_SIZE (mode) / 4;
8174 long *array = (long *) xmalloc (sizeof (long) * length);
8177 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8181 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8185 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8190 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8197 add_AT_float (die, DW_AT_const_value, length, array);
8201 /* ??? We really should be using HOST_WIDE_INT throughout. */
8202 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8204 add_AT_long_long (die, DW_AT_const_value,
8205 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8211 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8217 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8221 /* In cases where an inlined instance of an inline function is passed
8222 the address of an `auto' variable (which is local to the caller) we
8223 can get a situation where the DECL_RTL of the artificial local
8224 variable (for the inlining) which acts as a stand-in for the
8225 corresponding formal parameter (of the inline function) will look
8226 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8227 exactly a compile-time constant expression, but it isn't the address
8228 of the (artificial) local variable either. Rather, it represents the
8229 *value* which the artificial local variable always has during its
8230 lifetime. We currently have no way to represent such quasi-constant
8231 values in Dwarf, so for now we just punt and generate nothing. */
8235 /* No other kinds of rtx should be possible here. */
8242 rtl_for_decl_location (decl)
8247 /* Here we have to decide where we are going to say the parameter "lives"
8248 (as far as the debugger is concerned). We only have a couple of
8249 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8251 DECL_RTL normally indicates where the parameter lives during most of the
8252 activation of the function. If optimization is enabled however, this
8253 could be either NULL or else a pseudo-reg. Both of those cases indicate
8254 that the parameter doesn't really live anywhere (as far as the code
8255 generation parts of GCC are concerned) during most of the function's
8256 activation. That will happen (for example) if the parameter is never
8257 referenced within the function.
8259 We could just generate a location descriptor here for all non-NULL
8260 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8261 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8262 where DECL_RTL is NULL or is a pseudo-reg.
8264 Note however that we can only get away with using DECL_INCOMING_RTL as
8265 a backup substitute for DECL_RTL in certain limited cases. In cases
8266 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8267 we can be sure that the parameter was passed using the same type as it is
8268 declared to have within the function, and that its DECL_INCOMING_RTL
8269 points us to a place where a value of that type is passed.
8271 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8272 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8273 because in these cases DECL_INCOMING_RTL points us to a value of some
8274 type which is *different* from the type of the parameter itself. Thus,
8275 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8276 such cases, the debugger would end up (for example) trying to fetch a
8277 `float' from a place which actually contains the first part of a
8278 `double'. That would lead to really incorrect and confusing
8279 output at debug-time.
8281 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8282 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8283 are a couple of exceptions however. On little-endian machines we can
8284 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8285 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8286 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8287 when (on a little-endian machine) a non-prototyped function has a
8288 parameter declared to be of type `short' or `char'. In such cases,
8289 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8290 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8291 passed `int' value. If the debugger then uses that address to fetch
8292 a `short' or a `char' (on a little-endian machine) the result will be
8293 the correct data, so we allow for such exceptional cases below.
8295 Note that our goal here is to describe the place where the given formal
8296 parameter lives during most of the function's activation (i.e. between
8297 the end of the prologue and the start of the epilogue). We'll do that
8298 as best as we can. Note however that if the given formal parameter is
8299 modified sometime during the execution of the function, then a stack
8300 backtrace (at debug-time) will show the function as having been
8301 called with the *new* value rather than the value which was
8302 originally passed in. This happens rarely enough that it is not
8303 a major problem, but it *is* a problem, and I'd like to fix it.
8305 A future version of dwarf2out.c may generate two additional
8306 attributes for any given DW_TAG_formal_parameter DIE which will
8307 describe the "passed type" and the "passed location" for the
8308 given formal parameter in addition to the attributes we now
8309 generate to indicate the "declared type" and the "active
8310 location" for each parameter. This additional set of attributes
8311 could be used by debuggers for stack backtraces. Separately, note
8312 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8313 NULL also. This happens (for example) for inlined-instances of
8314 inline function formal parameters which are never referenced.
8315 This really shouldn't be happening. All PARM_DECL nodes should
8316 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8317 doesn't currently generate these values for inlined instances of
8318 inline function parameters, so when we see such cases, we are
8319 just out-of-luck for the time being (until integrate.c
8322 /* Use DECL_RTL as the "location" unless we find something better. */
8323 rtl = DECL_RTL_IF_SET (decl);
8325 if (TREE_CODE (decl) == PARM_DECL)
8327 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8329 tree declared_type = type_main_variant (TREE_TYPE (decl));
8330 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8332 /* This decl represents a formal parameter which was optimized out.
8333 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8334 all* cases where (rtl == NULL_RTX) just below. */
8335 if (declared_type == passed_type)
8336 rtl = DECL_INCOMING_RTL (decl);
8337 else if (! BYTES_BIG_ENDIAN
8338 && TREE_CODE (declared_type) == INTEGER_TYPE
8339 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8340 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8341 rtl = DECL_INCOMING_RTL (decl);
8344 /* If the parm was passed in registers, but lives on the stack, then
8345 make a big endian correction if the mode of the type of the
8346 parameter is not the same as the mode of the rtl. */
8347 /* ??? This is the same series of checks that are made in dbxout.c before
8348 we reach the big endian correction code there. It isn't clear if all
8349 of these checks are necessary here, but keeping them all is the safe
8351 else if (GET_CODE (rtl) == MEM
8352 && XEXP (rtl, 0) != const0_rtx
8353 && ! CONSTANT_P (XEXP (rtl, 0))
8354 /* Not passed in memory. */
8355 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8356 /* Not passed by invisible reference. */
8357 && (GET_CODE (XEXP (rtl, 0)) != REG
8358 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8359 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8360 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8361 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8364 /* Big endian correction check. */
8366 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8367 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8370 int offset = (UNITS_PER_WORD
8371 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8372 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8373 plus_constant (XEXP (rtl, 0), offset));
8377 if (rtl != NULL_RTX)
8379 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8380 #ifdef LEAF_REG_REMAP
8381 if (current_function_uses_only_leaf_regs)
8382 leaf_renumber_regs_insn (rtl);
8389 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8390 data attribute for a variable or a parameter. We generate the
8391 DW_AT_const_value attribute only in those cases where the given variable
8392 or parameter does not have a true "location" either in memory or in a
8393 register. This can happen (for example) when a constant is passed as an
8394 actual argument in a call to an inline function. (It's possible that
8395 these things can crop up in other ways also.) Note that one type of
8396 constant value which can be passed into an inlined function is a constant
8397 pointer. This can happen for example if an actual argument in an inlined
8398 function call evaluates to a compile-time constant address. */
8401 add_location_or_const_value_attribute (die, decl)
8402 register dw_die_ref die;
8407 if (TREE_CODE (decl) == ERROR_MARK)
8410 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8413 rtl = rtl_for_decl_location (decl);
8414 if (rtl == NULL_RTX)
8417 switch (GET_CODE (rtl))
8420 /* The address of a variable that was optimized away; don't emit
8431 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8432 add_const_value_attribute (die, rtl);
8439 add_AT_location_description (die, DW_AT_location, rtl);
8447 /* If we don't have a copy of this variable in memory for some reason (such
8448 as a C++ member constant that doesn't have an out-of-line definition),
8449 we should tell the debugger about the constant value. */
8452 tree_add_const_value_attribute (var_die, decl)
8456 tree init = DECL_INITIAL (decl);
8457 tree type = TREE_TYPE (decl);
8459 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8460 && initializer_constant_valid_p (init, type) == null_pointer_node)
8465 switch (TREE_CODE (type))
8468 if (host_integerp (init, 0))
8469 add_AT_unsigned (var_die, DW_AT_const_value,
8470 TREE_INT_CST_LOW (init));
8472 add_AT_long_long (var_die, DW_AT_const_value,
8473 TREE_INT_CST_HIGH (init),
8474 TREE_INT_CST_LOW (init));
8481 /* Generate an DW_AT_name attribute given some string value to be included as
8482 the value of the attribute. */
8485 add_name_attribute (die, name_string)
8486 register dw_die_ref die;
8487 register const char *name_string;
8489 if (name_string != NULL && *name_string != 0)
8491 if (demangle_name_func)
8492 name_string = (*demangle_name_func) (name_string);
8494 add_AT_string (die, DW_AT_name, name_string);
8498 /* Given a tree node describing an array bound (either lower or upper) output
8499 a representation for that bound. */
8502 add_bound_info (subrange_die, bound_attr, bound)
8503 register dw_die_ref subrange_die;
8504 register enum dwarf_attribute bound_attr;
8505 register tree bound;
8507 /* If this is an Ada unconstrained array type, then don't emit any debug
8508 info because the array bounds are unknown. They are parameterized when
8509 the type is instantiated. */
8510 if (contains_placeholder_p (bound))
8513 switch (TREE_CODE (bound))
8518 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8520 if (! host_integerp (bound, 0)
8521 || (bound_attr == DW_AT_lower_bound
8522 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8523 || (is_fortran () && integer_onep (bound)))))
8524 /* use the default */
8527 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8532 case NON_LVALUE_EXPR:
8533 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8537 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8538 access the upper bound values may be bogus. If they refer to a
8539 register, they may only describe how to get at these values at the
8540 points in the generated code right after they have just been
8541 computed. Worse yet, in the typical case, the upper bound values
8542 will not even *be* computed in the optimized code (though the
8543 number of elements will), so these SAVE_EXPRs are entirely
8544 bogus. In order to compensate for this fact, we check here to see
8545 if optimization is enabled, and if so, we don't add an attribute
8546 for the (unknown and unknowable) upper bound. This should not
8547 cause too much trouble for existing (stupid?) debuggers because
8548 they have to deal with empty upper bounds location descriptions
8549 anyway in order to be able to deal with incomplete array types.
8550 Of course an intelligent debugger (GDB?) should be able to
8551 comprehend that a missing upper bound specification in a array
8552 type used for a storage class `auto' local array variable
8553 indicates that the upper bound is both unknown (at compile- time)
8554 and unknowable (at run-time) due to optimization.
8556 We assume that a MEM rtx is safe because gcc wouldn't put the
8557 value there unless it was going to be used repeatedly in the
8558 function, i.e. for cleanups. */
8559 if (SAVE_EXPR_RTL (bound)
8560 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8562 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8563 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8564 register rtx loc = SAVE_EXPR_RTL (bound);
8566 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8567 it references an outer function's frame. */
8569 if (GET_CODE (loc) == MEM)
8571 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8573 if (XEXP (loc, 0) != new_addr)
8574 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8577 add_AT_flag (decl_die, DW_AT_artificial, 1);
8578 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8579 add_AT_location_description (decl_die, DW_AT_location, loc);
8580 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8583 /* Else leave out the attribute. */
8589 dw_die_ref decl_die = lookup_decl_die (bound);
8591 /* ??? Can this happen, or should the variable have been bound
8592 first? Probably it can, since I imagine that we try to create
8593 the types of parameters in the order in which they exist in
8594 the list, and won't have created a forward reference to a
8596 if (decl_die != NULL)
8597 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8603 /* Otherwise try to create a stack operation procedure to
8604 evaluate the value of the array bound. */
8606 dw_die_ref ctx, decl_die;
8607 dw_loc_descr_ref loc;
8609 loc = loc_descriptor_from_tree (bound, 0);
8613 ctx = lookup_decl_die (current_function_decl);
8615 decl_die = new_die (DW_TAG_variable, ctx);
8616 add_AT_flag (decl_die, DW_AT_artificial, 1);
8617 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8618 add_AT_loc (decl_die, DW_AT_location, loc);
8620 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8626 /* Note that the block of subscript information for an array type also
8627 includes information about the element type of type given array type. */
8630 add_subscript_info (type_die, type)
8631 register dw_die_ref type_die;
8634 #ifndef MIPS_DEBUGGING_INFO
8635 register unsigned dimension_number;
8637 register tree lower, upper;
8638 register dw_die_ref subrange_die;
8640 /* The GNU compilers represent multidimensional array types as sequences of
8641 one dimensional array types whose element types are themselves array
8642 types. Here we squish that down, so that each multidimensional array
8643 type gets only one array_type DIE in the Dwarf debugging info. The draft
8644 Dwarf specification say that we are allowed to do this kind of
8645 compression in C (because there is no difference between an array or
8646 arrays and a multidimensional array in C) but for other source languages
8647 (e.g. Ada) we probably shouldn't do this. */
8649 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8650 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8651 We work around this by disabling this feature. See also
8652 gen_array_type_die. */
8653 #ifndef MIPS_DEBUGGING_INFO
8654 for (dimension_number = 0;
8655 TREE_CODE (type) == ARRAY_TYPE;
8656 type = TREE_TYPE (type), dimension_number++)
8659 register tree domain = TYPE_DOMAIN (type);
8661 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8662 and (in GNU C only) variable bounds. Handle all three forms
8664 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8667 /* We have an array type with specified bounds. */
8668 lower = TYPE_MIN_VALUE (domain);
8669 upper = TYPE_MAX_VALUE (domain);
8671 /* define the index type. */
8672 if (TREE_TYPE (domain))
8674 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8675 TREE_TYPE field. We can't emit debug info for this
8676 because it is an unnamed integral type. */
8677 if (TREE_CODE (domain) == INTEGER_TYPE
8678 && TYPE_NAME (domain) == NULL_TREE
8679 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8680 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8683 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8687 /* ??? If upper is NULL, the array has unspecified length,
8688 but it does have a lower bound. This happens with Fortran
8690 Since the debugger is definitely going to need to know N
8691 to produce useful results, go ahead and output the lower
8692 bound solo, and hope the debugger can cope. */
8694 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8696 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8699 /* We have an array type with an unspecified length. The DWARF-2
8700 spec does not say how to handle this; let's just leave out the
8704 #ifndef MIPS_DEBUGGING_INFO
8710 add_byte_size_attribute (die, tree_node)
8712 register tree tree_node;
8714 register unsigned size;
8716 switch (TREE_CODE (tree_node))
8724 case QUAL_UNION_TYPE:
8725 size = int_size_in_bytes (tree_node);
8728 /* For a data member of a struct or union, the DW_AT_byte_size is
8729 generally given as the number of bytes normally allocated for an
8730 object of the *declared* type of the member itself. This is true
8731 even for bit-fields. */
8732 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8738 /* Note that `size' might be -1 when we get to this point. If it is, that
8739 indicates that the byte size of the entity in question is variable. We
8740 have no good way of expressing this fact in Dwarf at the present time,
8741 so just let the -1 pass on through. */
8743 add_AT_unsigned (die, DW_AT_byte_size, size);
8746 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8747 which specifies the distance in bits from the highest order bit of the
8748 "containing object" for the bit-field to the highest order bit of the
8751 For any given bit-field, the "containing object" is a hypothetical
8752 object (of some integral or enum type) within which the given bit-field
8753 lives. The type of this hypothetical "containing object" is always the
8754 same as the declared type of the individual bit-field itself. The
8755 determination of the exact location of the "containing object" for a
8756 bit-field is rather complicated. It's handled by the
8757 `field_byte_offset' function (above).
8759 Note that it is the size (in bytes) of the hypothetical "containing object"
8760 which will be given in the DW_AT_byte_size attribute for this bit-field.
8761 (See `byte_size_attribute' above). */
8764 add_bit_offset_attribute (die, decl)
8765 register dw_die_ref die;
8768 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8769 tree type = DECL_BIT_FIELD_TYPE (decl);
8770 HOST_WIDE_INT bitpos_int;
8771 HOST_WIDE_INT highest_order_object_bit_offset;
8772 HOST_WIDE_INT highest_order_field_bit_offset;
8773 HOST_WIDE_INT unsigned bit_offset;
8775 /* Must be a field and a bit field. */
8777 || TREE_CODE (decl) != FIELD_DECL)
8780 /* We can't yet handle bit-fields whose offsets are variable, so if we
8781 encounter such things, just return without generating any attribute
8782 whatsoever. Likewise for variable or too large size. */
8783 if (! host_integerp (bit_position (decl), 0)
8784 || ! host_integerp (DECL_SIZE (decl), 1))
8787 bitpos_int = int_bit_position (decl);
8789 /* Note that the bit offset is always the distance (in bits) from the
8790 highest-order bit of the "containing object" to the highest-order bit of
8791 the bit-field itself. Since the "high-order end" of any object or field
8792 is different on big-endian and little-endian machines, the computation
8793 below must take account of these differences. */
8794 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8795 highest_order_field_bit_offset = bitpos_int;
8797 if (! BYTES_BIG_ENDIAN)
8799 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8800 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8804 = (! BYTES_BIG_ENDIAN
8805 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8806 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8808 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8811 /* For a FIELD_DECL node which represents a bit field, output an attribute
8812 which specifies the length in bits of the given field. */
8815 add_bit_size_attribute (die, decl)
8816 register dw_die_ref die;
8819 /* Must be a field and a bit field. */
8820 if (TREE_CODE (decl) != FIELD_DECL
8821 || ! DECL_BIT_FIELD_TYPE (decl))
8824 if (host_integerp (DECL_SIZE (decl), 1))
8825 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8828 /* If the compiled language is ANSI C, then add a 'prototyped'
8829 attribute, if arg types are given for the parameters of a function. */
8832 add_prototyped_attribute (die, func_type)
8833 register dw_die_ref die;
8834 register tree func_type;
8836 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8837 && TYPE_ARG_TYPES (func_type) != NULL)
8838 add_AT_flag (die, DW_AT_prototyped, 1);
8841 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8842 by looking in either the type declaration or object declaration
8846 add_abstract_origin_attribute (die, origin)
8847 register dw_die_ref die;
8848 register tree origin;
8850 dw_die_ref origin_die = NULL;
8852 if (TREE_CODE (origin) != FUNCTION_DECL)
8854 /* We may have gotten separated from the block for the inlined
8855 function, if we're in an exception handler or some such; make
8856 sure that the abstract function has been written out.
8858 Doing this for nested functions is wrong, however; functions are
8859 distinct units, and our context might not even be inline. */
8862 fn = TYPE_STUB_DECL (fn);
8863 fn = decl_function_context (fn);
8865 dwarf2out_abstract_function (fn);
8868 if (DECL_P (origin))
8869 origin_die = lookup_decl_die (origin);
8870 else if (TYPE_P (origin))
8871 origin_die = lookup_type_die (origin);
8873 if (origin_die == NULL)
8876 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8879 /* We do not currently support the pure_virtual attribute. */
8882 add_pure_or_virtual_attribute (die, func_decl)
8883 register dw_die_ref die;
8884 register tree func_decl;
8886 if (DECL_VINDEX (func_decl))
8888 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8890 if (host_integerp (DECL_VINDEX (func_decl), 0))
8891 add_AT_loc (die, DW_AT_vtable_elem_location,
8892 new_loc_descr (DW_OP_constu,
8893 tree_low_cst (DECL_VINDEX (func_decl), 0),
8896 /* GNU extension: Record what type this method came from originally. */
8897 if (debug_info_level > DINFO_LEVEL_TERSE)
8898 add_AT_die_ref (die, DW_AT_containing_type,
8899 lookup_type_die (DECL_CONTEXT (func_decl)));
8903 /* Add source coordinate attributes for the given decl. */
8906 add_src_coords_attributes (die, decl)
8907 register dw_die_ref die;
8910 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8912 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8913 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8916 /* Add an DW_AT_name attribute and source coordinate attribute for the
8917 given decl, but only if it actually has a name. */
8920 add_name_and_src_coords_attributes (die, decl)
8921 register dw_die_ref die;
8924 register tree decl_name;
8926 decl_name = DECL_NAME (decl);
8927 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8929 add_name_attribute (die, dwarf2_name (decl, 0));
8930 if (! DECL_ARTIFICIAL (decl))
8931 add_src_coords_attributes (die, decl);
8933 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8934 && TREE_PUBLIC (decl)
8935 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8936 && !DECL_ABSTRACT (decl))
8937 add_AT_string (die, DW_AT_MIPS_linkage_name,
8938 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8942 /* Push a new declaration scope. */
8945 push_decl_scope (scope)
8948 /* Make room in the decl_scope_table, if necessary. */
8949 if (decl_scope_table_allocated == decl_scope_depth)
8951 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8953 = (tree *) xrealloc (decl_scope_table,
8954 decl_scope_table_allocated * sizeof (tree));
8957 decl_scope_table[decl_scope_depth] = scope;
8961 /* Pop a declaration scope. */
8965 if (decl_scope_depth <= 0)
8970 /* Return the DIE for the scope that immediately contains this type.
8971 Non-named types get global scope. Named types nested in other
8972 types get their containing scope if it's open, or global scope
8973 otherwise. All other types (i.e. function-local named types) get
8974 the current active scope. */
8977 scope_die_for (t, context_die)
8979 register dw_die_ref context_die;
8981 register dw_die_ref scope_die = NULL;
8982 register tree containing_scope;
8985 /* Non-types always go in the current scope. */
8989 containing_scope = TYPE_CONTEXT (t);
8991 /* Ignore namespaces for the moment. */
8992 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8993 containing_scope = NULL_TREE;
8995 /* Ignore function type "scopes" from the C frontend. They mean that
8996 a tagged type is local to a parmlist of a function declarator, but
8997 that isn't useful to DWARF. */
8998 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8999 containing_scope = NULL_TREE;
9001 if (containing_scope == NULL_TREE)
9002 scope_die = comp_unit_die;
9003 else if (TYPE_P (containing_scope))
9005 /* For types, we can just look up the appropriate DIE. But
9006 first we check to see if we're in the middle of emitting it
9007 so we know where the new DIE should go. */
9009 for (i = decl_scope_depth - 1; i >= 0; --i)
9010 if (decl_scope_table[i] == containing_scope)
9015 if (debug_info_level > DINFO_LEVEL_TERSE
9016 && !TREE_ASM_WRITTEN (containing_scope))
9019 /* If none of the current dies are suitable, we get file scope. */
9020 scope_die = comp_unit_die;
9023 scope_die = lookup_type_die (containing_scope);
9026 scope_die = context_die;
9031 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9033 static inline int local_scope_p PARAMS ((dw_die_ref));
9035 local_scope_p (context_die)
9036 dw_die_ref context_die;
9038 for (; context_die; context_die = context_die->die_parent)
9039 if (context_die->die_tag == DW_TAG_inlined_subroutine
9040 || context_die->die_tag == DW_TAG_subprogram)
9045 /* Returns nonzero iff CONTEXT_DIE is a class. */
9047 static inline int class_scope_p PARAMS ((dw_die_ref));
9049 class_scope_p (context_die)
9050 dw_die_ref context_die;
9053 && (context_die->die_tag == DW_TAG_structure_type
9054 || context_die->die_tag == DW_TAG_union_type));
9057 /* Many forms of DIEs require a "type description" attribute. This
9058 routine locates the proper "type descriptor" die for the type given
9059 by 'type', and adds an DW_AT_type attribute below the given die. */
9062 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9063 register dw_die_ref object_die;
9065 register int decl_const;
9066 register int decl_volatile;
9067 register dw_die_ref context_die;
9069 register enum tree_code code = TREE_CODE (type);
9070 register dw_die_ref type_die = NULL;
9072 /* ??? If this type is an unnamed subrange type of an integral or
9073 floating-point type, use the inner type. This is because we have no
9074 support for unnamed types in base_type_die. This can happen if this is
9075 an Ada subrange type. Correct solution is emit a subrange type die. */
9076 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9077 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9078 type = TREE_TYPE (type), code = TREE_CODE (type);
9080 if (code == ERROR_MARK)
9083 /* Handle a special case. For functions whose return type is void, we
9084 generate *no* type attribute. (Note that no object may have type
9085 `void', so this only applies to function return types). */
9086 if (code == VOID_TYPE)
9089 type_die = modified_type_die (type,
9090 decl_const || TYPE_READONLY (type),
9091 decl_volatile || TYPE_VOLATILE (type),
9093 if (type_die != NULL)
9094 add_AT_die_ref (object_die, DW_AT_type, type_die);
9097 /* Given a tree pointer to a struct, class, union, or enum type node, return
9098 a pointer to the (string) tag name for the given type, or zero if the type
9099 was declared without a tag. */
9105 register const char *name = 0;
9107 if (TYPE_NAME (type) != 0)
9109 register tree t = 0;
9111 /* Find the IDENTIFIER_NODE for the type name. */
9112 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9113 t = TYPE_NAME (type);
9115 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9116 a TYPE_DECL node, regardless of whether or not a `typedef' was
9118 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9119 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9120 t = DECL_NAME (TYPE_NAME (type));
9122 /* Now get the name as a string, or invent one. */
9124 name = IDENTIFIER_POINTER (t);
9127 return (name == 0 || *name == '\0') ? 0 : name;
9130 /* Return the type associated with a data member, make a special check
9131 for bit field types. */
9134 member_declared_type (member)
9135 register tree member;
9137 return (DECL_BIT_FIELD_TYPE (member)
9138 ? DECL_BIT_FIELD_TYPE (member)
9139 : TREE_TYPE (member));
9142 /* Get the decl's label, as described by its RTL. This may be different
9143 from the DECL_NAME name used in the source file. */
9147 decl_start_label (decl)
9152 x = DECL_RTL (decl);
9153 if (GET_CODE (x) != MEM)
9157 if (GET_CODE (x) != SYMBOL_REF)
9160 fnname = XSTR (x, 0);
9165 /* These routines generate the internal representation of the DIE's for
9166 the compilation unit. Debugging information is collected by walking
9167 the declaration trees passed in from dwarf2out_decl(). */
9170 gen_array_type_die (type, context_die)
9172 register dw_die_ref context_die;
9174 register dw_die_ref scope_die = scope_die_for (type, context_die);
9175 register dw_die_ref array_die;
9176 register tree element_type;
9178 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9179 the inner array type comes before the outer array type. Thus we must
9180 call gen_type_die before we call new_die. See below also. */
9181 #ifdef MIPS_DEBUGGING_INFO
9182 gen_type_die (TREE_TYPE (type), context_die);
9185 array_die = new_die (DW_TAG_array_type, scope_die);
9188 /* We default the array ordering. SDB will probably do
9189 the right things even if DW_AT_ordering is not present. It's not even
9190 an issue until we start to get into multidimensional arrays anyway. If
9191 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9192 then we'll have to put the DW_AT_ordering attribute back in. (But if
9193 and when we find out that we need to put these in, we will only do so
9194 for multidimensional arrays. */
9195 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9198 #ifdef MIPS_DEBUGGING_INFO
9199 /* The SGI compilers handle arrays of unknown bound by setting
9200 AT_declaration and not emitting any subrange DIEs. */
9201 if (! TYPE_DOMAIN (type))
9202 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9205 add_subscript_info (array_die, type);
9207 add_name_attribute (array_die, type_tag (type));
9208 equate_type_number_to_die (type, array_die);
9210 /* Add representation of the type of the elements of this array type. */
9211 element_type = TREE_TYPE (type);
9213 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9214 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9215 We work around this by disabling this feature. See also
9216 add_subscript_info. */
9217 #ifndef MIPS_DEBUGGING_INFO
9218 while (TREE_CODE (element_type) == ARRAY_TYPE)
9219 element_type = TREE_TYPE (element_type);
9221 gen_type_die (element_type, context_die);
9224 add_type_attribute (array_die, element_type, 0, 0, context_die);
9228 gen_set_type_die (type, context_die)
9230 register dw_die_ref context_die;
9232 register dw_die_ref type_die
9233 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9235 equate_type_number_to_die (type, type_die);
9236 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9241 gen_entry_point_die (decl, context_die)
9243 register dw_die_ref context_die;
9245 register tree origin = decl_ultimate_origin (decl);
9246 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9248 add_abstract_origin_attribute (decl_die, origin);
9251 add_name_and_src_coords_attributes (decl_die, decl);
9252 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9256 if (DECL_ABSTRACT (decl))
9257 equate_decl_number_to_die (decl, decl_die);
9259 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9263 /* Remember a type in the incomplete_types_list. */
9266 add_incomplete_type (type)
9269 if (incomplete_types == incomplete_types_allocated)
9271 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9272 incomplete_types_list
9273 = (tree *) xrealloc (incomplete_types_list,
9274 sizeof (tree) * incomplete_types_allocated);
9277 incomplete_types_list[incomplete_types++] = type;
9280 /* Walk through the list of incomplete types again, trying once more to
9281 emit full debugging info for them. */
9284 retry_incomplete_types ()
9288 while (incomplete_types)
9291 type = incomplete_types_list[incomplete_types];
9292 gen_type_die (type, comp_unit_die);
9296 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9299 gen_inlined_enumeration_type_die (type, context_die)
9301 register dw_die_ref context_die;
9303 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9305 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9306 be incomplete and such types are not marked. */
9307 add_abstract_origin_attribute (type_die, type);
9310 /* Generate a DIE to represent an inlined instance of a structure type. */
9313 gen_inlined_structure_type_die (type, context_die)
9315 register dw_die_ref context_die;
9317 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9319 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9320 be incomplete and such types are not marked. */
9321 add_abstract_origin_attribute (type_die, type);
9324 /* Generate a DIE to represent an inlined instance of a union type. */
9327 gen_inlined_union_type_die (type, context_die)
9329 register dw_die_ref context_die;
9331 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9333 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9334 be incomplete and such types are not marked. */
9335 add_abstract_origin_attribute (type_die, type);
9338 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9339 include all of the information about the enumeration values also. Each
9340 enumerated type name/value is listed as a child of the enumerated type
9344 gen_enumeration_type_die (type, context_die)
9346 register dw_die_ref context_die;
9348 register dw_die_ref type_die = lookup_type_die (type);
9350 if (type_die == NULL)
9352 type_die = new_die (DW_TAG_enumeration_type,
9353 scope_die_for (type, context_die));
9354 equate_type_number_to_die (type, type_die);
9355 add_name_attribute (type_die, type_tag (type));
9357 else if (! TYPE_SIZE (type))
9360 remove_AT (type_die, DW_AT_declaration);
9362 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9363 given enum type is incomplete, do not generate the DW_AT_byte_size
9364 attribute or the DW_AT_element_list attribute. */
9365 if (TYPE_SIZE (type))
9369 TREE_ASM_WRITTEN (type) = 1;
9370 add_byte_size_attribute (type_die, type);
9371 if (TYPE_STUB_DECL (type) != NULL_TREE)
9372 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9374 /* If the first reference to this type was as the return type of an
9375 inline function, then it may not have a parent. Fix this now. */
9376 if (type_die->die_parent == NULL)
9377 add_child_die (scope_die_for (type, context_die), type_die);
9379 for (link = TYPE_FIELDS (type);
9380 link != NULL; link = TREE_CHAIN (link))
9382 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9384 add_name_attribute (enum_die,
9385 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9387 if (host_integerp (TREE_VALUE (link), 0))
9389 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9390 add_AT_int (enum_die, DW_AT_const_value,
9391 tree_low_cst (TREE_VALUE (link), 0));
9393 add_AT_unsigned (enum_die, DW_AT_const_value,
9394 tree_low_cst (TREE_VALUE (link), 0));
9399 add_AT_flag (type_die, DW_AT_declaration, 1);
9402 /* Generate a DIE to represent either a real live formal parameter decl or to
9403 represent just the type of some formal parameter position in some function
9406 Note that this routine is a bit unusual because its argument may be a
9407 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9408 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9409 node. If it's the former then this function is being called to output a
9410 DIE to represent a formal parameter object (or some inlining thereof). If
9411 it's the latter, then this function is only being called to output a
9412 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9413 argument type of some subprogram type. */
9416 gen_formal_parameter_die (node, context_die)
9418 register dw_die_ref context_die;
9420 register dw_die_ref parm_die
9421 = new_die (DW_TAG_formal_parameter, context_die);
9422 register tree origin;
9424 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9427 origin = decl_ultimate_origin (node);
9429 add_abstract_origin_attribute (parm_die, origin);
9432 add_name_and_src_coords_attributes (parm_die, node);
9433 add_type_attribute (parm_die, TREE_TYPE (node),
9434 TREE_READONLY (node),
9435 TREE_THIS_VOLATILE (node),
9437 if (DECL_ARTIFICIAL (node))
9438 add_AT_flag (parm_die, DW_AT_artificial, 1);
9441 equate_decl_number_to_die (node, parm_die);
9442 if (! DECL_ABSTRACT (node))
9443 add_location_or_const_value_attribute (parm_die, node);
9448 /* We were called with some kind of a ..._TYPE node. */
9449 add_type_attribute (parm_die, node, 0, 0, context_die);
9459 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9460 at the end of an (ANSI prototyped) formal parameters list. */
9463 gen_unspecified_parameters_die (decl_or_type, context_die)
9464 register tree decl_or_type ATTRIBUTE_UNUSED;
9465 register dw_die_ref context_die;
9467 new_die (DW_TAG_unspecified_parameters, context_die);
9470 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9471 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9472 parameters as specified in some function type specification (except for
9473 those which appear as part of a function *definition*). */
9476 gen_formal_types_die (function_or_method_type, context_die)
9477 register tree function_or_method_type;
9478 register dw_die_ref context_die;
9481 register tree formal_type = NULL;
9482 register tree first_parm_type;
9485 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9487 arg = DECL_ARGUMENTS (function_or_method_type);
9488 function_or_method_type = TREE_TYPE (function_or_method_type);
9493 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9495 /* Make our first pass over the list of formal parameter types and output a
9496 DW_TAG_formal_parameter DIE for each one. */
9497 for (link = first_parm_type; link; )
9499 register dw_die_ref parm_die;
9501 formal_type = TREE_VALUE (link);
9502 if (formal_type == void_type_node)
9505 /* Output a (nameless) DIE to represent the formal parameter itself. */
9506 parm_die = gen_formal_parameter_die (formal_type, context_die);
9507 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9508 && link == first_parm_type)
9509 || (arg && DECL_ARTIFICIAL (arg)))
9510 add_AT_flag (parm_die, DW_AT_artificial, 1);
9512 link = TREE_CHAIN (link);
9514 arg = TREE_CHAIN (arg);
9517 /* If this function type has an ellipsis, add a
9518 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9519 if (formal_type != void_type_node)
9520 gen_unspecified_parameters_die (function_or_method_type, context_die);
9522 /* Make our second (and final) pass over the list of formal parameter types
9523 and output DIEs to represent those types (as necessary). */
9524 for (link = TYPE_ARG_TYPES (function_or_method_type);
9526 link = TREE_CHAIN (link))
9528 formal_type = TREE_VALUE (link);
9529 if (formal_type == void_type_node)
9532 gen_type_die (formal_type, context_die);
9536 /* We want to generate the DIE for TYPE so that we can generate the
9537 die for MEMBER, which has been defined; we will need to refer back
9538 to the member declaration nested within TYPE. If we're trying to
9539 generate minimal debug info for TYPE, processing TYPE won't do the
9540 trick; we need to attach the member declaration by hand. */
9543 gen_type_die_for_member (type, member, context_die)
9545 dw_die_ref context_die;
9547 gen_type_die (type, context_die);
9549 /* If we're trying to avoid duplicate debug info, we may not have
9550 emitted the member decl for this function. Emit it now. */
9551 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9552 && ! lookup_decl_die (member))
9554 if (decl_ultimate_origin (member))
9557 push_decl_scope (type);
9558 if (TREE_CODE (member) == FUNCTION_DECL)
9559 gen_subprogram_die (member, lookup_type_die (type));
9561 gen_variable_die (member, lookup_type_die (type));
9566 /* Generate the DWARF2 info for the "abstract" instance
9567 of a function which we may later generate inlined and/or
9568 out-of-line instances of. */
9571 dwarf2out_abstract_function (decl)
9574 register dw_die_ref old_die;
9577 int was_abstract = DECL_ABSTRACT (decl);
9579 /* Make sure we have the actual abstract inline, not a clone. */
9580 decl = DECL_ORIGIN (decl);
9582 old_die = lookup_decl_die (decl);
9583 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9584 /* We've already generated the abstract instance. */
9587 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9588 we don't get confused by DECL_ABSTRACT. */
9589 context = decl_class_context (decl);
9591 gen_type_die_for_member
9592 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9594 /* Pretend we've just finished compiling this function. */
9595 save_fn = current_function_decl;
9596 current_function_decl = decl;
9598 set_decl_abstract_flags (decl, 1);
9599 dwarf2out_decl (decl);
9601 set_decl_abstract_flags (decl, 0);
9603 current_function_decl = save_fn;
9606 /* Generate a DIE to represent a declared function (either file-scope or
9610 gen_subprogram_die (decl, context_die)
9612 register dw_die_ref context_die;
9614 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9615 register tree origin = decl_ultimate_origin (decl);
9616 register dw_die_ref subr_die;
9617 register rtx fp_reg;
9618 register tree fn_arg_types;
9619 register tree outer_scope;
9620 register dw_die_ref old_die = lookup_decl_die (decl);
9621 register int declaration = (current_function_decl != decl
9622 || class_scope_p (context_die));
9624 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9625 be true, if we started to generate the abstract instance of an inline,
9626 decided to output its containing class, and proceeded to emit the
9627 declaration of the inline from the member list for the class. In that
9628 case, `declaration' takes priority; we'll get back to the abstract
9629 instance when we're done with the class. */
9631 /* The class-scope declaration DIE must be the primary DIE. */
9632 if (origin && declaration && class_scope_p (context_die))
9641 if (declaration && ! local_scope_p (context_die))
9644 /* Fixup die_parent for the abstract instance of a nested
9646 if (old_die && old_die->die_parent == NULL)
9647 add_child_die (context_die, old_die);
9649 subr_die = new_die (DW_TAG_subprogram, context_die);
9650 add_abstract_origin_attribute (subr_die, origin);
9654 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9656 if (!get_AT_flag (old_die, DW_AT_declaration)
9657 /* We can have a normal definition following an inline one in the
9658 case of redefinition of GNU C extern inlines.
9659 It seems reasonable to use AT_specification in this case. */
9660 && !get_AT_unsigned (old_die, DW_AT_inline))
9662 /* ??? This can happen if there is a bug in the program, for
9663 instance, if it has duplicate function definitions. Ideally,
9664 we should detect this case and ignore it. For now, if we have
9665 already reported an error, any error at all, then assume that
9666 we got here because of a input error, not a dwarf2 bug. */
9672 /* If the definition comes from the same place as the declaration,
9673 maybe use the old DIE. We always want the DIE for this function
9674 that has the *_pc attributes to be under comp_unit_die so the
9675 debugger can find it. We also need to do this for abstract
9676 instances of inlines, since the spec requires the out-of-line copy
9677 to have the same parent. For local class methods, this doesn't
9678 apply; we just use the old DIE. */
9679 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9680 && (DECL_ARTIFICIAL (decl)
9681 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9682 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9683 == (unsigned) DECL_SOURCE_LINE (decl)))))
9687 /* Clear out the declaration attribute and the parm types. */
9688 remove_AT (subr_die, DW_AT_declaration);
9689 remove_children (subr_die);
9693 subr_die = new_die (DW_TAG_subprogram, context_die);
9694 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9695 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9696 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9697 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9698 != (unsigned) DECL_SOURCE_LINE (decl))
9700 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9705 subr_die = new_die (DW_TAG_subprogram, context_die);
9707 if (TREE_PUBLIC (decl))
9708 add_AT_flag (subr_die, DW_AT_external, 1);
9710 add_name_and_src_coords_attributes (subr_die, decl);
9711 if (debug_info_level > DINFO_LEVEL_TERSE)
9713 register tree type = TREE_TYPE (decl);
9715 add_prototyped_attribute (subr_die, type);
9716 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9719 add_pure_or_virtual_attribute (subr_die, decl);
9720 if (DECL_ARTIFICIAL (decl))
9721 add_AT_flag (subr_die, DW_AT_artificial, 1);
9722 if (TREE_PROTECTED (decl))
9723 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9724 else if (TREE_PRIVATE (decl))
9725 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9730 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9732 add_AT_flag (subr_die, DW_AT_declaration, 1);
9734 /* The first time we see a member function, it is in the context of
9735 the class to which it belongs. We make sure of this by emitting
9736 the class first. The next time is the definition, which is
9737 handled above. The two may come from the same source text. */
9738 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9739 equate_decl_number_to_die (decl, subr_die);
9742 else if (DECL_ABSTRACT (decl))
9744 if (DECL_INLINE (decl) && !flag_no_inline)
9746 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9747 inline functions, but not for extern inline functions.
9748 We can't get this completely correct because information
9749 about whether the function was declared inline is not
9751 if (DECL_DEFER_OUTPUT (decl))
9752 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9754 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9757 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9759 equate_decl_number_to_die (decl, subr_die);
9761 else if (!DECL_EXTERNAL (decl))
9763 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9764 equate_decl_number_to_die (decl, subr_die);
9766 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9767 current_funcdef_number);
9768 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9769 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9770 current_funcdef_number);
9771 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9773 add_pubname (decl, subr_die);
9774 add_arange (decl, subr_die);
9776 #ifdef MIPS_DEBUGGING_INFO
9777 /* Add a reference to the FDE for this routine. */
9778 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9781 /* Define the "frame base" location for this routine. We use the
9782 frame pointer or stack pointer registers, since the RTL for local
9783 variables is relative to one of them. */
9785 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9786 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9789 /* ??? This fails for nested inline functions, because context_display
9790 is not part of the state saved/restored for inline functions. */
9791 if (current_function_needs_context)
9792 add_AT_location_description (subr_die, DW_AT_static_link,
9793 lookup_static_chain (decl));
9797 /* Now output descriptions of the arguments for this function. This gets
9798 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9799 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9800 `...' at the end of the formal parameter list. In order to find out if
9801 there was a trailing ellipsis or not, we must instead look at the type
9802 associated with the FUNCTION_DECL. This will be a node of type
9803 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9804 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9805 an ellipsis at the end. */
9807 /* In the case where we are describing a mere function declaration, all we
9808 need to do here (and all we *can* do here) is to describe the *types* of
9809 its formal parameters. */
9810 if (debug_info_level <= DINFO_LEVEL_TERSE)
9812 else if (declaration)
9813 gen_formal_types_die (decl, subr_die);
9816 /* Generate DIEs to represent all known formal parameters */
9817 register tree arg_decls = DECL_ARGUMENTS (decl);
9820 /* When generating DIEs, generate the unspecified_parameters DIE
9821 instead if we come across the arg "__builtin_va_alist" */
9822 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9823 if (TREE_CODE (parm) == PARM_DECL)
9825 if (DECL_NAME (parm)
9826 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9827 "__builtin_va_alist"))
9828 gen_unspecified_parameters_die (parm, subr_die);
9830 gen_decl_die (parm, subr_die);
9833 /* Decide whether we need a unspecified_parameters DIE at the end.
9834 There are 2 more cases to do this for: 1) the ansi ... declaration -
9835 this is detectable when the end of the arg list is not a
9836 void_type_node 2) an unprototyped function declaration (not a
9837 definition). This just means that we have no info about the
9838 parameters at all. */
9839 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9840 if (fn_arg_types != NULL)
9842 /* this is the prototyped case, check for ... */
9843 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9844 gen_unspecified_parameters_die (decl, subr_die);
9846 else if (DECL_INITIAL (decl) == NULL_TREE)
9847 gen_unspecified_parameters_die (decl, subr_die);
9850 /* Output Dwarf info for all of the stuff within the body of the function
9851 (if it has one - it may be just a declaration). */
9852 outer_scope = DECL_INITIAL (decl);
9854 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9855 node created to represent a function. This outermost BLOCK actually
9856 represents the outermost binding contour for the function, i.e. the
9857 contour in which the function's formal parameters and labels get
9858 declared. Curiously, it appears that the front end doesn't actually
9859 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9860 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9861 list for the function instead.) The BLOCK_VARS list for the
9862 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9863 the function however, and we output DWARF info for those in
9864 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9865 node representing the function's outermost pair of curly braces, and
9866 any blocks used for the base and member initializers of a C++
9867 constructor function. */
9868 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9870 current_function_has_inlines = 0;
9871 decls_for_scope (outer_scope, subr_die, 0);
9873 #if 0 && defined (MIPS_DEBUGGING_INFO)
9874 if (current_function_has_inlines)
9876 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9877 if (! comp_unit_has_inlines)
9879 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9880 comp_unit_has_inlines = 1;
9887 /* Generate a DIE to represent a declared data object. */
9890 gen_variable_die (decl, context_die)
9892 register dw_die_ref context_die;
9894 register tree origin = decl_ultimate_origin (decl);
9895 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9897 dw_die_ref old_die = lookup_decl_die (decl);
9898 int declaration = (DECL_EXTERNAL (decl)
9899 || class_scope_p (context_die));
9902 add_abstract_origin_attribute (var_die, origin);
9903 /* Loop unrolling can create multiple blocks that refer to the same
9904 static variable, so we must test for the DW_AT_declaration flag. */
9905 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9906 copy decls and set the DECL_ABSTRACT flag on them instead of
9908 else if (old_die && TREE_STATIC (decl)
9909 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9911 /* This is a definition of a C++ class level static. */
9912 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9913 if (DECL_NAME (decl))
9915 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9917 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9918 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9920 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9921 != (unsigned) DECL_SOURCE_LINE (decl))
9923 add_AT_unsigned (var_die, DW_AT_decl_line,
9924 DECL_SOURCE_LINE (decl));
9929 add_name_and_src_coords_attributes (var_die, decl);
9930 add_type_attribute (var_die, TREE_TYPE (decl),
9931 TREE_READONLY (decl),
9932 TREE_THIS_VOLATILE (decl), context_die);
9934 if (TREE_PUBLIC (decl))
9935 add_AT_flag (var_die, DW_AT_external, 1);
9937 if (DECL_ARTIFICIAL (decl))
9938 add_AT_flag (var_die, DW_AT_artificial, 1);
9940 if (TREE_PROTECTED (decl))
9941 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9943 else if (TREE_PRIVATE (decl))
9944 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9948 add_AT_flag (var_die, DW_AT_declaration, 1);
9950 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9951 equate_decl_number_to_die (decl, var_die);
9953 if (! declaration && ! DECL_ABSTRACT (decl))
9955 add_location_or_const_value_attribute (var_die, decl);
9956 add_pubname (decl, var_die);
9959 tree_add_const_value_attribute (var_die, decl);
9962 /* Generate a DIE to represent a label identifier. */
9965 gen_label_die (decl, context_die)
9967 register dw_die_ref context_die;
9969 register tree origin = decl_ultimate_origin (decl);
9970 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9972 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9975 add_abstract_origin_attribute (lbl_die, origin);
9977 add_name_and_src_coords_attributes (lbl_die, decl);
9979 if (DECL_ABSTRACT (decl))
9980 equate_decl_number_to_die (decl, lbl_die);
9983 insn = DECL_RTL (decl);
9985 /* Deleted labels are programmer specified labels which have been
9986 eliminated because of various optimisations. We still emit them
9987 here so that it is possible to put breakpoints on them. */
9988 if (GET_CODE (insn) == CODE_LABEL
9989 || ((GET_CODE (insn) == NOTE
9990 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9992 /* When optimization is enabled (via -O) some parts of the compiler
9993 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9994 represent source-level labels which were explicitly declared by
9995 the user. This really shouldn't be happening though, so catch
9996 it if it ever does happen. */
9997 if (INSN_DELETED_P (insn))
10000 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10001 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10006 /* Generate a DIE for a lexical block. */
10009 gen_lexical_block_die (stmt, context_die, depth)
10010 register tree stmt;
10011 register dw_die_ref context_die;
10014 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10015 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10017 if (! BLOCK_ABSTRACT (stmt))
10019 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10020 BLOCK_NUMBER (stmt));
10021 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10022 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10023 BLOCK_NUMBER (stmt));
10024 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10027 decls_for_scope (stmt, stmt_die, depth);
10030 /* Generate a DIE for an inlined subprogram. */
10033 gen_inlined_subroutine_die (stmt, context_die, depth)
10034 register tree stmt;
10035 register dw_die_ref context_die;
10038 if (! BLOCK_ABSTRACT (stmt))
10040 register dw_die_ref subr_die
10041 = new_die (DW_TAG_inlined_subroutine, context_die);
10042 register tree decl = block_ultimate_origin (stmt);
10043 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10045 /* Emit info for the abstract instance first, if we haven't yet. */
10046 dwarf2out_abstract_function (decl);
10048 add_abstract_origin_attribute (subr_die, decl);
10049 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10050 BLOCK_NUMBER (stmt));
10051 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10052 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10053 BLOCK_NUMBER (stmt));
10054 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10055 decls_for_scope (stmt, subr_die, depth);
10056 current_function_has_inlines = 1;
10060 /* Generate a DIE for a field in a record, or structure. */
10063 gen_field_die (decl, context_die)
10064 register tree decl;
10065 register dw_die_ref context_die;
10067 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10069 add_name_and_src_coords_attributes (decl_die, decl);
10070 add_type_attribute (decl_die, member_declared_type (decl),
10071 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10074 /* If this is a bit field... */
10075 if (DECL_BIT_FIELD_TYPE (decl))
10077 add_byte_size_attribute (decl_die, decl);
10078 add_bit_size_attribute (decl_die, decl);
10079 add_bit_offset_attribute (decl_die, decl);
10082 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10083 add_data_member_location_attribute (decl_die, decl);
10085 if (DECL_ARTIFICIAL (decl))
10086 add_AT_flag (decl_die, DW_AT_artificial, 1);
10088 if (TREE_PROTECTED (decl))
10089 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10091 else if (TREE_PRIVATE (decl))
10092 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10096 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10097 Use modified_type_die instead.
10098 We keep this code here just in case these types of DIEs may be needed to
10099 represent certain things in other languages (e.g. Pascal) someday. */
10101 gen_pointer_type_die (type, context_die)
10102 register tree type;
10103 register dw_die_ref context_die;
10105 register dw_die_ref ptr_die
10106 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10108 equate_type_number_to_die (type, ptr_die);
10109 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10110 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10113 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10114 Use modified_type_die instead.
10115 We keep this code here just in case these types of DIEs may be needed to
10116 represent certain things in other languages (e.g. Pascal) someday. */
10118 gen_reference_type_die (type, context_die)
10119 register tree type;
10120 register dw_die_ref context_die;
10122 register dw_die_ref ref_die
10123 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10125 equate_type_number_to_die (type, ref_die);
10126 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10127 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10131 /* Generate a DIE for a pointer to a member type. */
10133 gen_ptr_to_mbr_type_die (type, context_die)
10134 register tree type;
10135 register dw_die_ref context_die;
10137 register dw_die_ref ptr_die
10138 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10140 equate_type_number_to_die (type, ptr_die);
10141 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10142 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10143 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10146 /* Generate the DIE for the compilation unit. */
10149 gen_compile_unit_die (filename)
10150 register const char *filename;
10152 register dw_die_ref die;
10153 char producer[250];
10154 const char *wd = getpwd ();
10157 die = new_die (DW_TAG_compile_unit, NULL);
10158 add_name_attribute (die, filename);
10160 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10161 add_AT_string (die, DW_AT_comp_dir, wd);
10163 sprintf (producer, "%s %s", language_string, version_string);
10165 #ifdef MIPS_DEBUGGING_INFO
10166 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10167 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10168 not appear in the producer string, the debugger reaches the conclusion
10169 that the object file is stripped and has no debugging information.
10170 To get the MIPS/SGI debugger to believe that there is debugging
10171 information in the object file, we add a -g to the producer string. */
10172 if (debug_info_level > DINFO_LEVEL_TERSE)
10173 strcat (producer, " -g");
10176 add_AT_string (die, DW_AT_producer, producer);
10178 if (strcmp (language_string, "GNU C++") == 0)
10179 language = DW_LANG_C_plus_plus;
10180 else if (strcmp (language_string, "GNU Ada") == 0)
10181 language = DW_LANG_Ada83;
10182 else if (strcmp (language_string, "GNU F77") == 0)
10183 language = DW_LANG_Fortran77;
10184 else if (strcmp (language_string, "GNU Pascal") == 0)
10185 language = DW_LANG_Pascal83;
10186 else if (strcmp (language_string, "GNU Java") == 0)
10187 language = DW_LANG_Java;
10188 else if (flag_traditional)
10189 language = DW_LANG_C;
10191 language = DW_LANG_C89;
10193 add_AT_unsigned (die, DW_AT_language, language);
10198 /* Generate a DIE for a string type. */
10201 gen_string_type_die (type, context_die)
10202 register tree type;
10203 register dw_die_ref context_die;
10205 register dw_die_ref type_die
10206 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10208 equate_type_number_to_die (type, type_die);
10210 /* Fudge the string length attribute for now. */
10212 /* TODO: add string length info.
10213 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10214 bound_representation (upper_bound, 0, 'u'); */
10217 /* Generate the DIE for a base class. */
10220 gen_inheritance_die (binfo, context_die)
10221 register tree binfo;
10222 register dw_die_ref context_die;
10224 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10226 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10227 add_data_member_location_attribute (die, binfo);
10229 if (TREE_VIA_VIRTUAL (binfo))
10230 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10231 if (TREE_VIA_PUBLIC (binfo))
10232 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10233 else if (TREE_VIA_PROTECTED (binfo))
10234 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10237 /* Generate a DIE for a class member. */
10240 gen_member_die (type, context_die)
10241 register tree type;
10242 register dw_die_ref context_die;
10244 register tree member;
10247 /* If this is not an incomplete type, output descriptions of each of its
10248 members. Note that as we output the DIEs necessary to represent the
10249 members of this record or union type, we will also be trying to output
10250 DIEs to represent the *types* of those members. However the `type'
10251 function (above) will specifically avoid generating type DIEs for member
10252 types *within* the list of member DIEs for this (containing) type execpt
10253 for those types (of members) which are explicitly marked as also being
10254 members of this (containing) type themselves. The g++ front- end can
10255 force any given type to be treated as a member of some other
10256 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10257 to point to the TREE node representing the appropriate (containing)
10260 /* First output info about the base classes. */
10261 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10263 register tree bases = TYPE_BINFO_BASETYPES (type);
10264 register int n_bases = TREE_VEC_LENGTH (bases);
10267 for (i = 0; i < n_bases; i++)
10268 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10271 /* Now output info about the data members and type members. */
10272 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10274 /* If we thought we were generating minimal debug info for TYPE
10275 and then changed our minds, some of the member declarations
10276 may have already been defined. Don't define them again, but
10277 do put them in the right order. */
10279 child = lookup_decl_die (member);
10281 splice_child_die (context_die, child);
10283 gen_decl_die (member, context_die);
10286 /* Now output info about the function members (if any). */
10287 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10289 /* Don't include clones in the member list. */
10290 if (DECL_ABSTRACT_ORIGIN (member))
10293 child = lookup_decl_die (member);
10295 splice_child_die (context_die, child);
10297 gen_decl_die (member, context_die);
10301 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10302 is set, we pretend that the type was never defined, so we only get the
10303 member DIEs needed by later specification DIEs. */
10306 gen_struct_or_union_type_die (type, context_die)
10307 register tree type;
10308 register dw_die_ref context_die;
10310 register dw_die_ref type_die = lookup_type_die (type);
10311 register dw_die_ref scope_die = 0;
10312 register int nested = 0;
10313 int complete = (TYPE_SIZE (type)
10314 && (! TYPE_STUB_DECL (type)
10315 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10317 if (type_die && ! complete)
10320 if (TYPE_CONTEXT (type) != NULL_TREE
10321 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10324 scope_die = scope_die_for (type, context_die);
10326 if (! type_die || (nested && scope_die == comp_unit_die))
10327 /* First occurrence of type or toplevel definition of nested class. */
10329 register dw_die_ref old_die = type_die;
10331 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10332 ? DW_TAG_structure_type : DW_TAG_union_type,
10334 equate_type_number_to_die (type, type_die);
10336 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10338 add_name_attribute (type_die, type_tag (type));
10341 remove_AT (type_die, DW_AT_declaration);
10343 /* If this type has been completed, then give it a byte_size attribute and
10344 then give a list of members. */
10347 /* Prevent infinite recursion in cases where the type of some member of
10348 this type is expressed in terms of this type itself. */
10349 TREE_ASM_WRITTEN (type) = 1;
10350 add_byte_size_attribute (type_die, type);
10351 if (TYPE_STUB_DECL (type) != NULL_TREE)
10352 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10354 /* If the first reference to this type was as the return type of an
10355 inline function, then it may not have a parent. Fix this now. */
10356 if (type_die->die_parent == NULL)
10357 add_child_die (scope_die, type_die);
10359 push_decl_scope (type);
10360 gen_member_die (type, type_die);
10363 /* GNU extension: Record what type our vtable lives in. */
10364 if (TYPE_VFIELD (type))
10366 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10368 gen_type_die (vtype, context_die);
10369 add_AT_die_ref (type_die, DW_AT_containing_type,
10370 lookup_type_die (vtype));
10375 add_AT_flag (type_die, DW_AT_declaration, 1);
10377 /* We don't need to do this for function-local types. */
10378 if (! decl_function_context (TYPE_STUB_DECL (type)))
10379 add_incomplete_type (type);
10383 /* Generate a DIE for a subroutine _type_. */
10386 gen_subroutine_type_die (type, context_die)
10387 register tree type;
10388 register dw_die_ref context_die;
10390 register tree return_type = TREE_TYPE (type);
10391 register dw_die_ref subr_die
10392 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10394 equate_type_number_to_die (type, subr_die);
10395 add_prototyped_attribute (subr_die, type);
10396 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10397 gen_formal_types_die (type, subr_die);
10400 /* Generate a DIE for a type definition */
10403 gen_typedef_die (decl, context_die)
10404 register tree decl;
10405 register dw_die_ref context_die;
10407 register dw_die_ref type_die;
10408 register tree origin;
10410 if (TREE_ASM_WRITTEN (decl))
10412 TREE_ASM_WRITTEN (decl) = 1;
10414 type_die = new_die (DW_TAG_typedef, context_die);
10415 origin = decl_ultimate_origin (decl);
10416 if (origin != NULL)
10417 add_abstract_origin_attribute (type_die, origin);
10420 register tree type;
10421 add_name_and_src_coords_attributes (type_die, decl);
10422 if (DECL_ORIGINAL_TYPE (decl))
10424 type = DECL_ORIGINAL_TYPE (decl);
10426 if (type == TREE_TYPE (decl))
10429 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10432 type = TREE_TYPE (decl);
10433 add_type_attribute (type_die, type, TREE_READONLY (decl),
10434 TREE_THIS_VOLATILE (decl), context_die);
10437 if (DECL_ABSTRACT (decl))
10438 equate_decl_number_to_die (decl, type_die);
10441 /* Generate a type description DIE. */
10444 gen_type_die (type, context_die)
10445 register tree type;
10446 register dw_die_ref context_die;
10450 if (type == NULL_TREE || type == error_mark_node)
10453 /* We are going to output a DIE to represent the unqualified version of
10454 this type (i.e. without any const or volatile qualifiers) so get the
10455 main variant (i.e. the unqualified version) of this type now. */
10456 type = type_main_variant (type);
10458 if (TREE_ASM_WRITTEN (type))
10461 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10462 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10464 TREE_ASM_WRITTEN (type) = 1;
10465 gen_decl_die (TYPE_NAME (type), context_die);
10469 switch (TREE_CODE (type))
10475 case REFERENCE_TYPE:
10476 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10477 ensures that the gen_type_die recursion will terminate even if the
10478 type is recursive. Recursive types are possible in Ada. */
10479 /* ??? We could perhaps do this for all types before the switch
10481 TREE_ASM_WRITTEN (type) = 1;
10483 /* For these types, all that is required is that we output a DIE (or a
10484 set of DIEs) to represent the "basis" type. */
10485 gen_type_die (TREE_TYPE (type), context_die);
10489 /* This code is used for C++ pointer-to-data-member types.
10490 Output a description of the relevant class type. */
10491 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10493 /* Output a description of the type of the object pointed to. */
10494 gen_type_die (TREE_TYPE (type), context_die);
10496 /* Now output a DIE to represent this pointer-to-data-member type
10498 gen_ptr_to_mbr_type_die (type, context_die);
10502 gen_type_die (TYPE_DOMAIN (type), context_die);
10503 gen_set_type_die (type, context_die);
10507 gen_type_die (TREE_TYPE (type), context_die);
10508 abort (); /* No way to represent these in Dwarf yet! */
10511 case FUNCTION_TYPE:
10512 /* Force out return type (in case it wasn't forced out already). */
10513 gen_type_die (TREE_TYPE (type), context_die);
10514 gen_subroutine_type_die (type, context_die);
10518 /* Force out return type (in case it wasn't forced out already). */
10519 gen_type_die (TREE_TYPE (type), context_die);
10520 gen_subroutine_type_die (type, context_die);
10524 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10526 gen_type_die (TREE_TYPE (type), context_die);
10527 gen_string_type_die (type, context_die);
10530 gen_array_type_die (type, context_die);
10534 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10537 case ENUMERAL_TYPE:
10540 case QUAL_UNION_TYPE:
10541 /* If this is a nested type whose containing class hasn't been
10542 written out yet, writing it out will cover this one, too.
10543 This does not apply to instantiations of member class templates;
10544 they need to be added to the containing class as they are
10545 generated. FIXME: This hurts the idea of combining type decls
10546 from multiple TUs, since we can't predict what set of template
10547 instantiations we'll get. */
10548 if (TYPE_CONTEXT (type)
10549 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10550 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10552 gen_type_die (TYPE_CONTEXT (type), context_die);
10554 if (TREE_ASM_WRITTEN (type))
10557 /* If that failed, attach ourselves to the stub. */
10558 push_decl_scope (TYPE_CONTEXT (type));
10559 context_die = lookup_type_die (TYPE_CONTEXT (type));
10565 if (TREE_CODE (type) == ENUMERAL_TYPE)
10566 gen_enumeration_type_die (type, context_die);
10568 gen_struct_or_union_type_die (type, context_die);
10573 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10574 it up if it is ever completed. gen_*_type_die will set it for us
10575 when appropriate. */
10584 /* No DIEs needed for fundamental types. */
10588 /* No Dwarf representation currently defined. */
10595 TREE_ASM_WRITTEN (type) = 1;
10598 /* Generate a DIE for a tagged type instantiation. */
10601 gen_tagged_type_instantiation_die (type, context_die)
10602 register tree type;
10603 register dw_die_ref context_die;
10605 if (type == NULL_TREE || type == error_mark_node)
10608 /* We are going to output a DIE to represent the unqualified version of
10609 this type (i.e. without any const or volatile qualifiers) so make sure
10610 that we have the main variant (i.e. the unqualified version) of this
10612 if (type != type_main_variant (type))
10615 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10616 an instance of an unresolved type. */
10618 switch (TREE_CODE (type))
10623 case ENUMERAL_TYPE:
10624 gen_inlined_enumeration_type_die (type, context_die);
10628 gen_inlined_structure_type_die (type, context_die);
10632 case QUAL_UNION_TYPE:
10633 gen_inlined_union_type_die (type, context_die);
10641 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10642 things which are local to the given block. */
10645 gen_block_die (stmt, context_die, depth)
10646 register tree stmt;
10647 register dw_die_ref context_die;
10650 register int must_output_die = 0;
10651 register tree origin;
10652 register tree decl;
10653 register enum tree_code origin_code;
10655 /* Ignore blocks never really used to make RTL. */
10657 if (stmt == NULL_TREE || !TREE_USED (stmt)
10658 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10661 /* Determine the "ultimate origin" of this block. This block may be an
10662 inlined instance of an inlined instance of inline function, so we have
10663 to trace all of the way back through the origin chain to find out what
10664 sort of node actually served as the original seed for the creation of
10665 the current block. */
10666 origin = block_ultimate_origin (stmt);
10667 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10669 /* Determine if we need to output any Dwarf DIEs at all to represent this
10671 if (origin_code == FUNCTION_DECL)
10672 /* The outer scopes for inlinings *must* always be represented. We
10673 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10674 must_output_die = 1;
10677 /* In the case where the current block represents an inlining of the
10678 "body block" of an inline function, we must *NOT* output any DIE for
10679 this block because we have already output a DIE to represent the
10680 whole inlined function scope and the "body block" of any function
10681 doesn't really represent a different scope according to ANSI C
10682 rules. So we check here to make sure that this block does not
10683 represent a "body block inlining" before trying to set the
10684 `must_output_die' flag. */
10685 if (! is_body_block (origin ? origin : stmt))
10687 /* Determine if this block directly contains any "significant"
10688 local declarations which we will need to output DIEs for. */
10689 if (debug_info_level > DINFO_LEVEL_TERSE)
10690 /* We are not in terse mode so *any* local declaration counts
10691 as being a "significant" one. */
10692 must_output_die = (BLOCK_VARS (stmt) != NULL);
10694 /* We are in terse mode, so only local (nested) function
10695 definitions count as "significant" local declarations. */
10696 for (decl = BLOCK_VARS (stmt);
10697 decl != NULL; decl = TREE_CHAIN (decl))
10698 if (TREE_CODE (decl) == FUNCTION_DECL
10699 && DECL_INITIAL (decl))
10701 must_output_die = 1;
10707 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10708 DIE for any block which contains no significant local declarations at
10709 all. Rather, in such cases we just call `decls_for_scope' so that any
10710 needed Dwarf info for any sub-blocks will get properly generated. Note
10711 that in terse mode, our definition of what constitutes a "significant"
10712 local declaration gets restricted to include only inlined function
10713 instances and local (nested) function definitions. */
10714 if (must_output_die)
10716 if (origin_code == FUNCTION_DECL)
10717 gen_inlined_subroutine_die (stmt, context_die, depth);
10719 gen_lexical_block_die (stmt, context_die, depth);
10722 decls_for_scope (stmt, context_die, depth);
10725 /* Generate all of the decls declared within a given scope and (recursively)
10726 all of its sub-blocks. */
10729 decls_for_scope (stmt, context_die, depth)
10730 register tree stmt;
10731 register dw_die_ref context_die;
10734 register tree decl;
10735 register tree subblocks;
10737 /* Ignore blocks never really used to make RTL. */
10738 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10741 /* Output the DIEs to represent all of the data objects and typedefs
10742 declared directly within this block but not within any nested
10743 sub-blocks. Also, nested function and tag DIEs have been
10744 generated with a parent of NULL; fix that up now. */
10745 for (decl = BLOCK_VARS (stmt);
10746 decl != NULL; decl = TREE_CHAIN (decl))
10748 register dw_die_ref die;
10750 if (TREE_CODE (decl) == FUNCTION_DECL)
10751 die = lookup_decl_die (decl);
10752 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10753 die = lookup_type_die (TREE_TYPE (decl));
10757 if (die != NULL && die->die_parent == NULL)
10758 add_child_die (context_die, die);
10760 gen_decl_die (decl, context_die);
10763 /* Output the DIEs to represent all sub-blocks (and the items declared
10764 therein) of this block. */
10765 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10767 subblocks = BLOCK_CHAIN (subblocks))
10768 gen_block_die (subblocks, context_die, depth + 1);
10771 /* Is this a typedef we can avoid emitting? */
10774 is_redundant_typedef (decl)
10775 register tree decl;
10777 if (TYPE_DECL_IS_STUB (decl))
10780 if (DECL_ARTIFICIAL (decl)
10781 && DECL_CONTEXT (decl)
10782 && is_tagged_type (DECL_CONTEXT (decl))
10783 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10784 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10785 /* Also ignore the artificial member typedef for the class name. */
10791 /* Generate Dwarf debug information for a decl described by DECL. */
10794 gen_decl_die (decl, context_die)
10795 register tree decl;
10796 register dw_die_ref context_die;
10798 register tree origin;
10800 if (TREE_CODE (decl) == ERROR_MARK)
10803 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10804 if (DECL_IGNORED_P (decl))
10807 switch (TREE_CODE (decl))
10810 /* The individual enumerators of an enum type get output when we output
10811 the Dwarf representation of the relevant enum type itself. */
10814 case FUNCTION_DECL:
10815 /* Don't output any DIEs to represent mere function declarations,
10816 unless they are class members or explicit block externs. */
10817 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10818 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10821 /* If we're emitting a clone, emit info for the abstract instance. */
10822 if (DECL_ORIGIN (decl) != decl)
10823 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10824 /* If we're emitting an out-of-line copy of an inline function,
10825 emit info for the abstract instance and set up to refer to it. */
10826 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10827 && ! class_scope_p (context_die)
10828 /* dwarf2out_abstract_function won't emit a die if this is just
10829 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10830 that case, because that works only if we have a die. */
10831 && DECL_INITIAL (decl) != NULL_TREE)
10833 dwarf2out_abstract_function (decl);
10834 set_decl_origin_self (decl);
10836 /* Otherwise we're emitting the primary DIE for this decl. */
10837 else if (debug_info_level > DINFO_LEVEL_TERSE)
10839 /* Before we describe the FUNCTION_DECL itself, make sure that we
10840 have described its return type. */
10841 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10843 /* And its virtual context. */
10844 if (DECL_VINDEX (decl) != NULL_TREE)
10845 gen_type_die (DECL_CONTEXT (decl), context_die);
10847 /* And its containing type. */
10848 origin = decl_class_context (decl);
10849 if (origin != NULL_TREE)
10850 gen_type_die_for_member (origin, decl, context_die);
10853 /* Now output a DIE to represent the function itself. */
10854 gen_subprogram_die (decl, context_die);
10858 /* If we are in terse mode, don't generate any DIEs to represent any
10859 actual typedefs. */
10860 if (debug_info_level <= DINFO_LEVEL_TERSE)
10863 /* In the special case of a TYPE_DECL node representing the
10864 declaration of some type tag, if the given TYPE_DECL is marked as
10865 having been instantiated from some other (original) TYPE_DECL node
10866 (e.g. one which was generated within the original definition of an
10867 inline function) we have to generate a special (abbreviated)
10868 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10870 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10872 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10876 if (is_redundant_typedef (decl))
10877 gen_type_die (TREE_TYPE (decl), context_die);
10879 /* Output a DIE to represent the typedef itself. */
10880 gen_typedef_die (decl, context_die);
10884 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10885 gen_label_die (decl, context_die);
10889 /* If we are in terse mode, don't generate any DIEs to represent any
10890 variable declarations or definitions. */
10891 if (debug_info_level <= DINFO_LEVEL_TERSE)
10894 /* Output any DIEs that are needed to specify the type of this data
10896 gen_type_die (TREE_TYPE (decl), context_die);
10898 /* And its containing type. */
10899 origin = decl_class_context (decl);
10900 if (origin != NULL_TREE)
10901 gen_type_die_for_member (origin, decl, context_die);
10903 /* Now output the DIE to represent the data object itself. This gets
10904 complicated because of the possibility that the VAR_DECL really
10905 represents an inlined instance of a formal parameter for an inline
10907 origin = decl_ultimate_origin (decl);
10908 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10909 gen_formal_parameter_die (decl, context_die);
10911 gen_variable_die (decl, context_die);
10915 /* Ignore the nameless fields that are used to skip bits, but
10916 handle C++ anonymous unions. */
10917 if (DECL_NAME (decl) != NULL_TREE
10918 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10920 gen_type_die (member_declared_type (decl), context_die);
10921 gen_field_die (decl, context_die);
10926 gen_type_die (TREE_TYPE (decl), context_die);
10927 gen_formal_parameter_die (decl, context_die);
10930 case NAMESPACE_DECL:
10931 /* Ignore for now. */
10939 /* Add Ada "use" clause information for SGI Workshop debugger. */
10942 dwarf2out_add_library_unit_info (filename, context_list)
10943 const char *filename;
10944 const char *context_list;
10946 unsigned int file_index;
10948 if (filename != NULL)
10950 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10951 tree context_list_decl
10952 = build_decl (LABEL_DECL, get_identifier (context_list),
10955 TREE_PUBLIC (context_list_decl) = TRUE;
10956 add_name_attribute (unit_die, context_list);
10957 file_index = lookup_filename (filename);
10958 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10959 add_pubname (context_list_decl, unit_die);
10963 /* Write the debugging output for DECL. */
10966 dwarf2out_decl (decl)
10967 register tree decl;
10969 register dw_die_ref context_die = comp_unit_die;
10971 if (TREE_CODE (decl) == ERROR_MARK)
10974 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10975 if (DECL_IGNORED_P (decl))
10978 switch (TREE_CODE (decl))
10980 case FUNCTION_DECL:
10981 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10982 builtin function. Explicit programmer-supplied declarations of
10983 these same functions should NOT be ignored however. */
10984 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10987 /* What we would really like to do here is to filter out all mere
10988 file-scope declarations of file-scope functions which are never
10989 referenced later within this translation unit (and keep all of ones
10990 that *are* referenced later on) but we aren't clairvoyant, so we have
10991 no idea which functions will be referenced in the future (i.e. later
10992 on within the current translation unit). So here we just ignore all
10993 file-scope function declarations which are not also definitions. If
10994 and when the debugger needs to know something about these functions,
10995 it will have to hunt around and find the DWARF information associated
10996 with the definition of the function. Note that we can't just check
10997 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10998 definitions and which ones represent mere declarations. We have to
10999 check `DECL_INITIAL' instead. That's because the C front-end
11000 supports some weird semantics for "extern inline" function
11001 definitions. These can get inlined within the current translation
11002 unit (an thus, we need to generate DWARF info for their abstract
11003 instances so that the DWARF info for the concrete inlined instances
11004 can have something to refer to) but the compiler never generates any
11005 out-of-lines instances of such things (despite the fact that they
11006 *are* definitions). The important point is that the C front-end
11007 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11008 to generate DWARF for them anyway. Note that the C++ front-end also
11009 plays some similar games for inline function definitions appearing
11010 within include files which also contain
11011 `#pragma interface' pragmas. */
11012 if (DECL_INITIAL (decl) == NULL_TREE)
11015 /* If we're a nested function, initially use a parent of NULL; if we're
11016 a plain function, this will be fixed up in decls_for_scope. If
11017 we're a method, it will be ignored, since we already have a DIE. */
11018 if (decl_function_context (decl))
11019 context_die = NULL;
11024 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11025 declaration and if the declaration was never even referenced from
11026 within this entire compilation unit. We suppress these DIEs in
11027 order to save space in the .debug section (by eliminating entries
11028 which are probably useless). Note that we must not suppress
11029 block-local extern declarations (whether used or not) because that
11030 would screw-up the debugger's name lookup mechanism and cause it to
11031 miss things which really ought to be in scope at a given point. */
11032 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11035 /* If we are in terse mode, don't generate any DIEs to represent any
11036 variable declarations or definitions. */
11037 if (debug_info_level <= DINFO_LEVEL_TERSE)
11042 /* Don't emit stubs for types unless they are needed by other DIEs. */
11043 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11046 /* Don't bother trying to generate any DIEs to represent any of the
11047 normal built-in types for the language we are compiling. */
11048 if (DECL_SOURCE_LINE (decl) == 0)
11050 /* OK, we need to generate one for `bool' so GDB knows what type
11051 comparisons have. */
11052 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11053 == DW_LANG_C_plus_plus)
11054 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11055 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11060 /* If we are in terse mode, don't generate any DIEs for types. */
11061 if (debug_info_level <= DINFO_LEVEL_TERSE)
11064 /* If we're a function-scope tag, initially use a parent of NULL;
11065 this will be fixed up in decls_for_scope. */
11066 if (decl_function_context (decl))
11067 context_die = NULL;
11075 gen_decl_die (decl, context_die);
11078 /* Output a marker (i.e. a label) for the beginning of the generated code for
11079 a lexical block. */
11082 dwarf2out_begin_block (blocknum)
11083 register unsigned blocknum;
11085 function_section (current_function_decl);
11086 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11089 /* Output a marker (i.e. a label) for the end of the generated code for a
11093 dwarf2out_end_block (blocknum)
11094 register unsigned blocknum;
11096 function_section (current_function_decl);
11097 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11100 /* Returns nonzero if it is appropriate not to emit any debugging
11101 information for BLOCK, because it doesn't contain any instructions.
11103 Don't allow this for blocks with nested functions or local classes
11104 as we would end up with orphans, and in the presence of scheduling
11105 we may end up calling them anyway. */
11108 dwarf2out_ignore_block (block)
11112 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11113 if (TREE_CODE (decl) == FUNCTION_DECL
11114 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11119 /* Lookup a filename (in the list of filenames that we know about here in
11120 dwarf2out.c) and return its "index". The index of each (known) filename is
11121 just a unique number which is associated with only that one filename.
11122 We need such numbers for the sake of generating labels
11123 (in the .debug_sfnames section) and references to those
11124 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11125 If the filename given as an argument is not found in our current list,
11126 add it to the list and assign it the next available unique index number.
11127 In order to speed up searches, we remember the index of the filename
11128 was looked up last. This handles the majority of all searches. */
11131 lookup_filename (file_name)
11132 const char *file_name;
11134 register unsigned i;
11136 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11137 if (strcmp (file_name, "<internal>") == 0
11138 || strcmp (file_name, "<built-in>") == 0)
11141 /* Check to see if the file name that was searched on the previous
11142 call matches this file name. If so, return the index. */
11143 if (file_table.last_lookup_index != 0)
11144 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11145 return file_table.last_lookup_index;
11147 /* Didn't match the previous lookup, search the table */
11148 for (i = 1; i < file_table.in_use; ++i)
11149 if (strcmp (file_name, file_table.table[i]) == 0)
11151 file_table.last_lookup_index = i;
11155 /* Prepare to add a new table entry by making sure there is enough space in
11156 the table to do so. If not, expand the current table. */
11157 if (i == file_table.allocated)
11159 file_table.allocated = i + FILE_TABLE_INCREMENT;
11160 file_table.table = (char **)
11161 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11164 /* Add the new entry to the end of the filename table. */
11165 file_table.table[i] = xstrdup (file_name);
11166 file_table.in_use = i + 1;
11167 file_table.last_lookup_index = i;
11169 if (DWARF2_ASM_LINE_DEBUG_INFO)
11170 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11178 /* Allocate the initial hunk of the file_table. */
11179 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11180 file_table.allocated = FILE_TABLE_INCREMENT;
11182 /* Skip the first entry - file numbers begin at 1. */
11183 file_table.in_use = 1;
11184 file_table.last_lookup_index = 0;
11187 /* Output a label to mark the beginning of a source code line entry
11188 and record information relating to this source line, in
11189 'line_info_table' for later output of the .debug_line section. */
11192 dwarf2out_line (filename, line)
11193 register const char *filename;
11194 register unsigned line;
11196 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11198 function_section (current_function_decl);
11200 if (DWARF2_ASM_LINE_DEBUG_INFO)
11202 unsigned file_num = lookup_filename (filename);
11204 /* Emit the .loc directive understood by GNU as. */
11205 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11207 /* Indicate that line number info exists. */
11208 ++line_info_table_in_use;
11210 /* Indicate that multiple line number tables exist. */
11211 if (DECL_SECTION_NAME (current_function_decl))
11212 ++separate_line_info_table_in_use;
11214 else if (DECL_SECTION_NAME (current_function_decl))
11216 register dw_separate_line_info_ref line_info;
11217 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11218 separate_line_info_table_in_use);
11219 if (flag_debug_asm)
11220 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11223 /* expand the line info table if necessary */
11224 if (separate_line_info_table_in_use
11225 == separate_line_info_table_allocated)
11227 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11228 separate_line_info_table
11229 = (dw_separate_line_info_ref)
11230 xrealloc (separate_line_info_table,
11231 separate_line_info_table_allocated
11232 * sizeof (dw_separate_line_info_entry));
11235 /* Add the new entry at the end of the line_info_table. */
11237 = &separate_line_info_table[separate_line_info_table_in_use++];
11238 line_info->dw_file_num = lookup_filename (filename);
11239 line_info->dw_line_num = line;
11240 line_info->function = current_funcdef_number;
11244 register dw_line_info_ref line_info;
11246 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11247 line_info_table_in_use);
11248 if (flag_debug_asm)
11249 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11252 /* Expand the line info table if necessary. */
11253 if (line_info_table_in_use == line_info_table_allocated)
11255 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11257 = (dw_line_info_ref)
11258 xrealloc (line_info_table,
11259 (line_info_table_allocated
11260 * sizeof (dw_line_info_entry)));
11263 /* Add the new entry at the end of the line_info_table. */
11264 line_info = &line_info_table[line_info_table_in_use++];
11265 line_info->dw_file_num = lookup_filename (filename);
11266 line_info->dw_line_num = line;
11271 /* Record the beginning of a new source file. */
11274 dwarf2out_start_source_file (lineno, filename)
11275 register unsigned int lineno ATTRIBUTE_UNUSED;
11276 register const char *filename ATTRIBUTE_UNUSED;
11278 if (flag_eliminate_dwarf2_dups)
11280 /* Record the beginning of the file for break_out_includes. */
11281 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11282 add_AT_string (bincl_die, DW_AT_name, filename);
11284 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11286 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11287 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11288 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno);
11289 dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started");
11293 /* Record the end of a source file. */
11296 dwarf2out_end_source_file ()
11298 if (flag_eliminate_dwarf2_dups)
11300 /* Record the end of the file for break_out_includes. */
11301 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11303 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11305 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11306 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11310 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11311 the tail part of the directive line, i.e. the part which is past the
11312 initial whitespace, #, whitespace, directive-name, whitespace part. */
11315 dwarf2out_define (lineno, buffer)
11316 register unsigned lineno ATTRIBUTE_UNUSED;
11317 register const char *buffer ATTRIBUTE_UNUSED;
11319 static int initialized = 0;
11322 dwarf2out_start_source_file (0, primary_filename);
11325 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11327 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11328 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11329 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11330 dw2_asm_output_nstring (buffer, -1, "The macro");
11334 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11335 the tail part of the directive line, i.e. the part which is past the
11336 initial whitespace, #, whitespace, directive-name, whitespace part. */
11339 dwarf2out_undef (lineno, buffer)
11340 register unsigned lineno ATTRIBUTE_UNUSED;
11341 register const char *buffer ATTRIBUTE_UNUSED;
11343 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11345 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11346 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11347 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11348 dw2_asm_output_nstring (buffer, -1, "The macro");
11352 /* Set up for Dwarf output at the start of compilation. */
11355 dwarf2out_init (asm_out_file, main_input_filename)
11356 register FILE *asm_out_file;
11357 register const char *main_input_filename;
11359 init_file_table ();
11361 /* Remember the name of the primary input file. */
11362 primary_filename = main_input_filename;
11364 /* Add it to the file table first, under the assumption that we'll
11365 be emitting line number data for it first, which avoids having
11366 to add an initial DW_LNS_set_file. */
11367 lookup_filename (main_input_filename);
11369 /* Allocate the initial hunk of the decl_die_table. */
11371 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11372 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11373 decl_die_table_in_use = 0;
11375 /* Allocate the initial hunk of the decl_scope_table. */
11377 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11378 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11379 decl_scope_depth = 0;
11381 /* Allocate the initial hunk of the abbrev_die_table. */
11383 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11384 sizeof (dw_die_ref));
11385 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11386 /* Zero-th entry is allocated, but unused */
11387 abbrev_die_table_in_use = 1;
11389 /* Allocate the initial hunk of the line_info_table. */
11391 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11392 sizeof (dw_line_info_entry));
11393 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11394 /* Zero-th entry is allocated, but unused */
11395 line_info_table_in_use = 1;
11397 /* Generate the initial DIE for the .debug section. Note that the (string)
11398 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11399 will (typically) be a relative pathname and that this pathname should be
11400 taken as being relative to the directory from which the compiler was
11401 invoked when the given (base) source file was compiled. */
11402 comp_unit_die = gen_compile_unit_die (main_input_filename);
11404 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11405 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11407 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11408 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11409 DEBUG_ABBREV_SECTION_LABEL, 0);
11410 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11411 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11413 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11414 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11415 DEBUG_INFO_SECTION_LABEL, 0);
11416 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11417 DEBUG_LINE_SECTION_LABEL, 0);
11418 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
11419 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11420 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11421 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11422 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11423 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11425 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11426 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11428 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11429 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11430 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11431 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11432 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11434 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11435 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11436 DEBUG_MACINFO_SECTION_LABEL, 0);
11437 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11441 /* Output stuff that dwarf requires at the end of every file,
11442 and generate the DWARF-2 debugging info. */
11445 dwarf2out_finish ()
11447 limbo_die_node *node, *next_node;
11450 /* Traverse the limbo die list, and add parent/child links. The only
11451 dies without parents that should be here are concrete instances of
11452 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11453 For concrete instances, we can get the parent die from the abstract
11455 for (node = limbo_die_list; node; node = next_node)
11457 next_node = node->next;
11460 if (die->die_parent == NULL)
11462 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11464 add_child_die (origin->die_parent, die);
11465 else if (die == comp_unit_die)
11472 limbo_die_list = NULL;
11474 /* Walk through the list of incomplete types again, trying once more to
11475 emit full debugging info for them. */
11476 retry_incomplete_types ();
11478 /* We need to reverse all the dies before break_out_includes, or
11479 we'll see the end of an include file before the beginning. */
11480 reverse_all_dies (comp_unit_die);
11482 /* Generate separate CUs for each of the include files we've seen.
11483 They will go into limbo_die_list. */
11484 if (flag_eliminate_dwarf2_dups)
11485 break_out_includes (comp_unit_die);
11487 /* Traverse the DIE's and add add sibling attributes to those DIE's
11488 that have children. */
11489 add_sibling_attributes (comp_unit_die);
11490 for (node = limbo_die_list; node; node = node->next)
11491 add_sibling_attributes (node->die);
11493 /* Output a terminator label for the .text section. */
11494 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11495 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11498 /* Output a terminator label for the .data section. */
11499 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11500 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11502 /* Output a terminator label for the .bss section. */
11503 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11504 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11507 /* Output the source line correspondence table. We must do this
11508 even if there is no line information. Otherwise, on an empty
11509 translation unit, we will generate a present, but empty,
11510 .debug_info section. IRIX 6.5 `nm' will then complain when
11511 examining the file. */
11512 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11514 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11515 output_line_info ();
11518 /* We can only use the low/high_pc attributes if all of the code was
11520 if (separate_line_info_table_in_use == 0)
11522 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11523 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11526 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11527 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11528 debug_line_section_label);
11530 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11531 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11533 /* Output all of the compilation units. We put the main one last so that
11534 the offsets are available to output_pubnames. */
11535 for (node = limbo_die_list; node; node = node->next)
11536 output_comp_unit (node->die);
11537 output_comp_unit (comp_unit_die);
11539 /* Output the abbreviation table. */
11540 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11541 output_abbrev_section ();
11543 if (pubname_table_in_use)
11545 /* Output public names table. */
11546 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
11547 output_pubnames ();
11550 /* We only put functions in the arange table, so don't write it out if
11551 we don't have any. */
11552 if (fde_table_in_use)
11554 /* Output the address range information. */
11555 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
11558 /* Output location list section if necessary */
11559 if (have_location_lists)
11561 /* Output the location lists info. */
11562 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11563 output_location_lists (die);
11564 have_location_lists = 0;
11567 /* Have to end the primary source file. */
11568 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11570 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11571 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11575 #endif /* DWARF2_DEBUGGING_INFO */