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"
51 #include "dwarf2out.h"
52 #include "dwarf2asm.h"
59 /* DWARF2 Abbreviation Glossary:
60 CFA = Canonical Frame Address
61 a fixed address on the stack which identifies a call frame.
62 We define it to be the value of SP just before the call insn.
63 The CFA register and offset, which may change during the course
64 of the function, are used to calculate its value at runtime.
65 CFI = Call Frame Instruction
66 an instruction for the DWARF2 abstract machine
67 CIE = Common Information Entry
68 information describing information common to one or more FDEs
69 DIE = Debugging Information Entry
70 FDE = Frame Description Entry
71 information describing the stack call frame, in particular,
72 how to restore registers
74 DW_CFA_... = DWARF2 CFA call frame instruction
75 DW_TAG_... = DWARF2 DIE tag */
77 /* Decide whether we want to emit frame unwind information for the current
83 return (write_symbols == DWARF2_DEBUG
84 #ifdef DWARF2_FRAME_INFO
87 #ifdef DWARF2_UNWIND_INFO
89 || (flag_exceptions && ! exceptions_via_longjmp)
94 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
96 /* How to start an assembler comment. */
97 #ifndef ASM_COMMENT_START
98 #define ASM_COMMENT_START ";#"
101 typedef struct dw_cfi_struct *dw_cfi_ref;
102 typedef struct dw_fde_struct *dw_fde_ref;
103 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
105 /* Call frames are described using a sequence of Call Frame
106 Information instructions. The register number, offset
107 and address fields are provided as possible operands;
108 their use is selected by the opcode field. */
110 typedef union dw_cfi_oprnd_struct
112 unsigned long dw_cfi_reg_num;
113 long int dw_cfi_offset;
114 const char *dw_cfi_addr;
115 struct dw_loc_descr_struct *dw_cfi_loc;
119 typedef struct dw_cfi_struct
121 dw_cfi_ref dw_cfi_next;
122 enum dwarf_call_frame_info dw_cfi_opc;
123 dw_cfi_oprnd dw_cfi_oprnd1;
124 dw_cfi_oprnd dw_cfi_oprnd2;
128 /* This is how we define the location of the CFA. We use to handle it
129 as REG + OFFSET all the time, but now it can be more complex.
130 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
131 Instead of passing around REG and OFFSET, we pass a copy
132 of this structure. */
133 typedef struct cfa_loc
138 int indirect; /* 1 if CFA is accessed via a dereference. */
141 /* All call frame descriptions (FDE's) in the GCC generated DWARF
142 refer to a single Common Information Entry (CIE), defined at
143 the beginning of the .debug_frame section. This used of a single
144 CIE obviates the need to keep track of multiple CIE's
145 in the DWARF generation routines below. */
147 typedef struct dw_fde_struct
149 const char *dw_fde_begin;
150 const char *dw_fde_current_label;
151 const char *dw_fde_end;
152 dw_cfi_ref dw_fde_cfi;
157 /* Maximum size (in bytes) of an artificially generated label. */
158 #define MAX_ARTIFICIAL_LABEL_BYTES 30
160 /* The size of the target's pointer type. */
162 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
165 /* The size of addresses as they appear in the Dwarf 2 data.
166 Some architectures use word addresses to refer to code locations,
167 but Dwarf 2 info always uses byte addresses. On such machines,
168 Dwarf 2 addresses need to be larger than the architecture's
170 #ifndef DWARF2_ADDR_SIZE
171 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
174 /* The size in bytes of a DWARF field indicating an offset or length
175 relative to a debug info section, specified to be 4 bytes in the
176 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
179 #ifndef DWARF_OFFSET_SIZE
180 #define DWARF_OFFSET_SIZE 4
183 #define DWARF_VERSION 2
185 /* Round SIZE up to the nearest BOUNDARY. */
186 #define DWARF_ROUND(SIZE,BOUNDARY) \
187 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
189 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
190 #ifndef DWARF_CIE_DATA_ALIGNMENT
191 #ifdef STACK_GROWS_DOWNWARD
192 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
194 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
196 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
198 /* A pointer to the base of a table that contains frame description
199 information for each routine. */
200 static dw_fde_ref fde_table;
202 /* Number of elements currently allocated for fde_table. */
203 static unsigned fde_table_allocated;
205 /* Number of elements in fde_table currently in use. */
206 static unsigned fde_table_in_use;
208 /* Size (in elements) of increments by which we may expand the
210 #define FDE_TABLE_INCREMENT 256
212 /* A list of call frame insns for the CIE. */
213 static dw_cfi_ref cie_cfi_head;
215 /* The number of the current function definition for which debugging
216 information is being generated. These numbers range from 1 up to the
217 maximum number of function definitions contained within the current
218 compilation unit. These numbers are used to create unique label id's
219 unique to each function definition. */
220 static unsigned current_funcdef_number = 0;
222 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
223 attribute that accelerates the lookup of the FDE associated
224 with the subprogram. This variable holds the table index of the FDE
225 associated with the current function (body) definition. */
226 static unsigned current_funcdef_fde;
228 /* Forward declarations for functions defined in this file. */
230 static char *stripattributes PARAMS ((const char *));
231 static const char *dwarf_cfi_name PARAMS ((unsigned));
232 static dw_cfi_ref new_cfi PARAMS ((void));
233 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
234 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
235 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
236 static void lookup_cfa PARAMS ((dw_cfa_location *));
237 static void reg_save PARAMS ((const char *, unsigned,
239 static void initial_return_save PARAMS ((rtx));
240 static long stack_adjust_offset PARAMS ((rtx));
241 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
242 static void output_call_frame_info PARAMS ((int));
243 static void dwarf2out_stack_adjust PARAMS ((rtx));
244 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
246 /* Support for complex CFA locations. */
247 static void output_cfa_loc PARAMS ((dw_cfi_ref));
248 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
249 struct dw_loc_descr_struct *));
250 static struct dw_loc_descr_struct *build_cfa_loc
251 PARAMS ((dw_cfa_location *));
252 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
254 /* How to start an assembler comment. */
255 #ifndef ASM_COMMENT_START
256 #define ASM_COMMENT_START ";#"
259 /* Data and reference forms for relocatable data. */
260 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
261 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
263 /* Pseudo-op for defining a new section. */
264 #ifndef SECTION_ASM_OP
265 #define SECTION_ASM_OP "\t.section\t"
268 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
269 print the SECTION_ASM_OP and the section name. The default here works for
270 almost all svr4 assemblers, except for the sparc, where the section name
271 must be enclosed in double quotes. (See sparcv4.h). */
272 #ifndef SECTION_FORMAT
273 #ifdef PUSHSECTION_FORMAT
274 #define SECTION_FORMAT PUSHSECTION_FORMAT
276 #define SECTION_FORMAT "%s%s\n"
280 #ifndef FRAME_SECTION
281 #define FRAME_SECTION ".debug_frame"
284 #ifndef FUNC_BEGIN_LABEL
285 #define FUNC_BEGIN_LABEL "LFB"
287 #ifndef FUNC_END_LABEL
288 #define FUNC_END_LABEL "LFE"
290 #define CIE_AFTER_SIZE_LABEL "LSCIE"
291 #define CIE_END_LABEL "LECIE"
292 #define CIE_LENGTH_LABEL "LLCIE"
293 #define FDE_LABEL "LSFDE"
294 #define FDE_AFTER_SIZE_LABEL "LASFDE"
295 #define FDE_END_LABEL "LEFDE"
296 #define FDE_LENGTH_LABEL "LLFDE"
297 #define LINE_NUMBER_BEGIN_LABEL "LTSTART"
298 #define LINE_NUMBER_END_LABEL "LTEND"
299 #define DIE_LABEL_PREFIX "DW"
301 /* Definitions of defaults for various types of primitive assembly language
302 output operations. These may be overridden from within the tm.h file,
303 but typically, that is unnecessary. */
305 #ifndef ASM_OUTPUT_SECTION
306 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
307 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
311 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
312 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
314 fprintf (FILE, "%s", SET_ASM_OP); \
315 assemble_name (FILE, SY); \
317 assemble_name (FILE, HI); \
319 assemble_name (FILE, LO); \
322 #endif /* SET_ASM_OP */
324 /* The DWARF 2 CFA column which tracks the return address. Normally this
325 is the column for PC, or the first column after all of the hard
327 #ifndef DWARF_FRAME_RETURN_COLUMN
329 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
331 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
335 /* The mapping from gcc register number to DWARF 2 CFA column number. By
336 default, we just provide columns for all registers. */
337 #ifndef DWARF_FRAME_REGNUM
338 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
341 /* Hook used by __throw. */
344 expand_builtin_dwarf_fp_regnum ()
346 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
349 /* The offset from the incoming value of %sp to the top of the stack frame
350 for the current function. */
351 #ifndef INCOMING_FRAME_SP_OFFSET
352 #define INCOMING_FRAME_SP_OFFSET 0
355 /* Return a pointer to a copy of the section string name S with all
356 attributes stripped off, and an asterisk prepended (for assemble_name). */
362 char *stripped = xmalloc (strlen (s) + 2);
367 while (*s && *s != ',')
374 /* Generate code to initialize the register size table. */
377 expand_builtin_init_dwarf_reg_sizes (address)
381 enum machine_mode mode = TYPE_MODE (char_type_node);
382 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
383 rtx mem = gen_rtx_MEM (mode, addr);
385 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
387 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
388 int size = GET_MODE_SIZE (reg_raw_mode[i]);
393 emit_move_insn (change_address (mem, mode,
394 plus_constant (addr, offset)),
399 /* Convert a DWARF call frame info. operation to its string name */
402 dwarf_cfi_name (cfi_opc)
403 register unsigned cfi_opc;
407 case DW_CFA_advance_loc:
408 return "DW_CFA_advance_loc";
410 return "DW_CFA_offset";
412 return "DW_CFA_restore";
416 return "DW_CFA_set_loc";
417 case DW_CFA_advance_loc1:
418 return "DW_CFA_advance_loc1";
419 case DW_CFA_advance_loc2:
420 return "DW_CFA_advance_loc2";
421 case DW_CFA_advance_loc4:
422 return "DW_CFA_advance_loc4";
423 case DW_CFA_offset_extended:
424 return "DW_CFA_offset_extended";
425 case DW_CFA_restore_extended:
426 return "DW_CFA_restore_extended";
427 case DW_CFA_undefined:
428 return "DW_CFA_undefined";
429 case DW_CFA_same_value:
430 return "DW_CFA_same_value";
431 case DW_CFA_register:
432 return "DW_CFA_register";
433 case DW_CFA_remember_state:
434 return "DW_CFA_remember_state";
435 case DW_CFA_restore_state:
436 return "DW_CFA_restore_state";
438 return "DW_CFA_def_cfa";
439 case DW_CFA_def_cfa_register:
440 return "DW_CFA_def_cfa_register";
441 case DW_CFA_def_cfa_offset:
442 return "DW_CFA_def_cfa_offset";
443 case DW_CFA_def_cfa_expression:
444 return "DW_CFA_def_cfa_expression";
446 /* SGI/MIPS specific */
447 case DW_CFA_MIPS_advance_loc8:
448 return "DW_CFA_MIPS_advance_loc8";
451 case DW_CFA_GNU_window_save:
452 return "DW_CFA_GNU_window_save";
453 case DW_CFA_GNU_args_size:
454 return "DW_CFA_GNU_args_size";
455 case DW_CFA_GNU_negative_offset_extended:
456 return "DW_CFA_GNU_negative_offset_extended";
459 return "DW_CFA_<unknown>";
463 /* Return a pointer to a newly allocated Call Frame Instruction. */
465 static inline dw_cfi_ref
468 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
470 cfi->dw_cfi_next = NULL;
471 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
472 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
477 /* Add a Call Frame Instruction to list of instructions. */
480 add_cfi (list_head, cfi)
481 register dw_cfi_ref *list_head;
482 register dw_cfi_ref cfi;
484 register dw_cfi_ref *p;
486 /* Find the end of the chain. */
487 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
493 /* Generate a new label for the CFI info to refer to. */
496 dwarf2out_cfi_label ()
498 static char label[20];
499 static unsigned long label_num = 0;
501 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
502 ASM_OUTPUT_LABEL (asm_out_file, label);
507 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
508 or to the CIE if LABEL is NULL. */
511 add_fde_cfi (label, cfi)
512 register const char *label;
513 register dw_cfi_ref cfi;
517 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
520 label = dwarf2out_cfi_label ();
522 if (fde->dw_fde_current_label == NULL
523 || strcmp (label, fde->dw_fde_current_label) != 0)
525 register dw_cfi_ref xcfi;
527 fde->dw_fde_current_label = label = xstrdup (label);
529 /* Set the location counter to the new label. */
531 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
532 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
533 add_cfi (&fde->dw_fde_cfi, xcfi);
536 add_cfi (&fde->dw_fde_cfi, cfi);
540 add_cfi (&cie_cfi_head, cfi);
543 /* Subroutine of lookup_cfa. */
546 lookup_cfa_1 (cfi, loc)
547 register dw_cfi_ref cfi;
548 register dw_cfa_location *loc;
550 switch (cfi->dw_cfi_opc)
552 case DW_CFA_def_cfa_offset:
553 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
555 case DW_CFA_def_cfa_register:
556 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
559 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
560 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
562 case DW_CFA_def_cfa_expression:
563 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
570 /* Find the previous value for the CFA. */
574 register dw_cfa_location *loc;
576 register dw_cfi_ref cfi;
578 loc->reg = (unsigned long) -1;
581 loc->base_offset = 0;
583 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
584 lookup_cfa_1 (cfi, loc);
586 if (fde_table_in_use)
588 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
589 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
590 lookup_cfa_1 (cfi, loc);
594 /* The current rule for calculating the DWARF2 canonical frame address. */
597 /* The register used for saving registers to the stack, and its offset
599 dw_cfa_location cfa_store;
601 /* The running total of the size of arguments pushed onto the stack. */
602 static long args_size;
604 /* The last args_size we actually output. */
605 static long old_args_size;
607 /* Entry point to update the canonical frame address (CFA).
608 LABEL is passed to add_fde_cfi. The value of CFA is now to be
609 calculated from REG+OFFSET. */
612 dwarf2out_def_cfa (label, reg, offset)
613 register const char *label;
622 def_cfa_1 (label, &loc);
625 /* This routine does the actual work. The CFA is now calculated from
626 the dw_cfa_location structure. */
628 def_cfa_1 (label, loc_p)
629 register const char *label;
630 dw_cfa_location *loc_p;
632 register dw_cfi_ref cfi;
633 dw_cfa_location old_cfa, loc;
638 if (cfa_store.reg == loc.reg && loc.indirect == 0)
639 cfa_store.offset = loc.offset;
641 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
642 lookup_cfa (&old_cfa);
644 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
645 loc.indirect == old_cfa.indirect)
647 if (loc.indirect == 0
648 || loc.base_offset == old_cfa.base_offset)
649 /* Nothing changed so no need to issue any call frame
656 if (loc.reg == old_cfa.reg && !loc.indirect)
658 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
659 indicating the CFA register did not change but the offset
661 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
662 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
665 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
666 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
669 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
670 indicating the CFA register has changed to <register> but the
671 offset has not changed. */
672 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
673 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
677 else if (loc.indirect == 0)
679 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
680 indicating the CFA register has changed to <register> with
681 the specified offset. */
682 cfi->dw_cfi_opc = DW_CFA_def_cfa;
683 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
684 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
688 /* Construct a DW_CFA_def_cfa_expression instruction to
689 calculate the CFA using a full location expression since no
690 register-offset pair is available. */
691 struct dw_loc_descr_struct *loc_list;
692 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
693 loc_list = build_cfa_loc (&loc);
694 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
697 add_fde_cfi (label, cfi);
700 /* Add the CFI for saving a register. REG is the CFA column number.
701 LABEL is passed to add_fde_cfi.
702 If SREG is -1, the register is saved at OFFSET from the CFA;
703 otherwise it is saved in SREG. */
706 reg_save (label, reg, sreg, offset)
707 register const char *label;
708 register unsigned reg;
709 register unsigned sreg;
710 register long offset;
712 register dw_cfi_ref cfi = new_cfi ();
714 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
716 /* The following comparison is correct. -1 is used to indicate that
717 the value isn't a register number. */
718 if (sreg == (unsigned int) -1)
721 /* The register number won't fit in 6 bits, so we have to use
723 cfi->dw_cfi_opc = DW_CFA_offset_extended;
725 cfi->dw_cfi_opc = DW_CFA_offset;
727 #ifdef ENABLE_CHECKING
729 /* If we get an offset that is not a multiple of
730 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
731 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
733 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
735 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
739 offset /= DWARF_CIE_DATA_ALIGNMENT;
742 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
745 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
747 else if (sreg == reg)
748 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
752 cfi->dw_cfi_opc = DW_CFA_register;
753 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
756 add_fde_cfi (label, cfi);
759 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
760 This CFI tells the unwinder that it needs to restore the window registers
761 from the previous frame's window save area.
763 ??? Perhaps we should note in the CIE where windows are saved (instead of
764 assuming 0(cfa)) and what registers are in the window. */
767 dwarf2out_window_save (label)
768 register const char *label;
770 register dw_cfi_ref cfi = new_cfi ();
771 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
772 add_fde_cfi (label, cfi);
775 /* Add a CFI to update the running total of the size of arguments
776 pushed onto the stack. */
779 dwarf2out_args_size (label, size)
783 register dw_cfi_ref cfi;
785 if (size == old_args_size)
787 old_args_size = size;
790 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
791 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
792 add_fde_cfi (label, cfi);
795 /* Entry point for saving a register to the stack. REG is the GCC register
796 number. LABEL and OFFSET are passed to reg_save. */
799 dwarf2out_reg_save (label, reg, offset)
800 register const char *label;
801 register unsigned reg;
802 register long offset;
804 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
807 /* Entry point for saving the return address in the stack.
808 LABEL and OFFSET are passed to reg_save. */
811 dwarf2out_return_save (label, offset)
812 register const char *label;
813 register long offset;
815 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
818 /* Entry point for saving the return address in a register.
819 LABEL and SREG are passed to reg_save. */
822 dwarf2out_return_reg (label, sreg)
823 register const char *label;
824 register unsigned sreg;
826 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
829 /* Record the initial position of the return address. RTL is
830 INCOMING_RETURN_ADDR_RTX. */
833 initial_return_save (rtl)
836 unsigned int reg = (unsigned int) -1;
839 switch (GET_CODE (rtl))
842 /* RA is in a register. */
843 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
846 /* RA is on the stack. */
848 switch (GET_CODE (rtl))
851 if (REGNO (rtl) != STACK_POINTER_REGNUM)
856 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
858 offset = INTVAL (XEXP (rtl, 1));
861 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
863 offset = -INTVAL (XEXP (rtl, 1));
870 /* The return address is at some offset from any value we can
871 actually load. For instance, on the SPARC it is in %i7+8. Just
872 ignore the offset for now; it doesn't matter for unwinding frames. */
873 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
875 initial_return_save (XEXP (rtl, 0));
881 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
884 /* Given a SET, calculate the amount of stack adjustment it
888 stack_adjust_offset (pattern)
891 rtx src = SET_SRC (pattern);
892 rtx dest = SET_DEST (pattern);
896 if (dest == stack_pointer_rtx)
898 /* (set (reg sp) (plus (reg sp) (const_int))) */
899 code = GET_CODE (src);
900 if (! (code == PLUS || code == MINUS)
901 || XEXP (src, 0) != stack_pointer_rtx
902 || GET_CODE (XEXP (src, 1)) != CONST_INT)
905 offset = INTVAL (XEXP (src, 1));
907 else if (GET_CODE (dest) == MEM)
909 /* (set (mem (pre_dec (reg sp))) (foo)) */
910 src = XEXP (dest, 0);
911 code = GET_CODE (src);
913 if (! (code == PRE_DEC || code == PRE_INC
914 || code == PRE_MODIFY)
915 || XEXP (src, 0) != stack_pointer_rtx)
918 if (code == PRE_MODIFY)
920 rtx val = XEXP (XEXP (src, 1), 1);
921 /* We handle only adjustments by constant amount. */
922 if (GET_CODE (XEXP (src, 1)) != PLUS ||
923 GET_CODE (val) != CONST_INT)
925 offset = -INTVAL (val);
927 else offset = GET_MODE_SIZE (GET_MODE (dest));
932 if (code == PLUS || code == PRE_INC)
938 /* Check INSN to see if it looks like a push or a stack adjustment, and
939 make a note of it if it does. EH uses this information to find out how
940 much extra space it needs to pop off the stack. */
943 dwarf2out_stack_adjust (insn)
949 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
951 /* Extract the size of the args from the CALL rtx itself. */
953 insn = PATTERN (insn);
954 if (GET_CODE (insn) == PARALLEL)
955 insn = XVECEXP (insn, 0, 0);
956 if (GET_CODE (insn) == SET)
957 insn = SET_SRC (insn);
958 if (GET_CODE (insn) != CALL)
960 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
964 /* If only calls can throw, and we have a frame pointer,
965 save up adjustments until we see the CALL_INSN. */
966 else if (! asynchronous_exceptions
967 && cfa.reg != STACK_POINTER_REGNUM)
970 if (GET_CODE (insn) == BARRIER)
972 /* When we see a BARRIER, we know to reset args_size to 0. Usually
973 the compiler will have already emitted a stack adjustment, but
974 doesn't bother for calls to noreturn functions. */
975 #ifdef STACK_GROWS_DOWNWARD
981 else if (GET_CODE (PATTERN (insn)) == SET)
983 offset = stack_adjust_offset (PATTERN (insn));
985 else if (GET_CODE (PATTERN (insn)) == PARALLEL
986 || GET_CODE (PATTERN (insn)) == SEQUENCE)
988 /* There may be stack adjustments inside compound insns. Search
993 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
995 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
996 if (GET_CODE (pattern) == SET)
997 offset += stack_adjust_offset (pattern);
1006 if (cfa.reg == STACK_POINTER_REGNUM)
1007 cfa.offset += offset;
1009 #ifndef STACK_GROWS_DOWNWARD
1012 args_size += offset;
1016 label = dwarf2out_cfi_label ();
1017 def_cfa_1 (label, &cfa);
1018 dwarf2out_args_size (label, args_size);
1021 /* A temporary register holding an integral value used in adjusting SP
1022 or setting up the store_reg. The "offset" field holds the integer
1023 value, not an offset. */
1024 dw_cfa_location cfa_temp;
1026 /* Record call frame debugging information for an expression EXPR,
1027 which either sets SP or FP (adjusting how we calculate the frame
1028 address) or saves a register to the stack. LABEL indicates the
1031 This function encodes a state machine mapping rtxes to actions on
1032 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1033 users need not read the source code.
1035 The High-Level Picture
1037 Changes in the register we use to calculate the CFA: Currently we
1038 assume that if you copy the CFA register into another register, we
1039 should take the other one as the new CFA register; this seems to
1040 work pretty well. If it's wrong for some target, it's simple
1041 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1043 Changes in the register we use for saving registers to the stack:
1044 This is usually SP, but not always. Again, we deduce that if you
1045 copy SP into another register (and SP is not the CFA register),
1046 then the new register is the one we will be using for register
1047 saves. This also seems to work.
1049 Register saves: There's not much guesswork about this one; if
1050 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1051 register save, and the register used to calculate the destination
1052 had better be the one we think we're using for this purpose.
1054 Except: If the register being saved is the CFA register, and the
1055 offset is non-zero, we are saving the CFA, so we assume we have to
1056 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1057 the intent is to save the value of SP from the previous frame.
1059 Invariants / Summaries of Rules
1061 cfa current rule for calculating the CFA. It usually
1062 consists of a register and an offset.
1063 cfa_store register used by prologue code to save things to the stack
1064 cfa_store.offset is the offset from the value of
1065 cfa_store.reg to the actual CFA
1066 cfa_temp register holding an integral value. cfa_temp.offset
1067 stores the value, which will be used to adjust the
1070 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1071 with cfa.reg as the first operand changes the cfa.reg and its
1074 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1075 expression yielding a constant. This sets cfa_temp.reg
1076 and cfa_temp.offset.
1078 Rule 5: Create a new register cfa_store used to save items to the
1081 Rules 10-13: Save a register to the stack. Define offset as the
1082 difference of the original location and cfa_store's
1087 "{a,b}" indicates a choice of a xor b.
1088 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1091 (set <reg1> <reg2>:cfa.reg)
1092 effects: cfa.reg = <REG1>
1093 cfa.offset unchanged
1096 (set sp ({minus,plus} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1097 effects: cfa.reg = sp if fp used
1098 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1099 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1100 if cfa_store.reg==sp
1103 (set fp ({minus,plus} <reg>:cfa.reg <const_int>))
1104 effects: cfa.reg = fp
1105 cfa_offset += +/- <const_int>
1108 (set <reg1> (plus <reg2>:cfa.reg <const_int>))
1109 constraints: <reg1> != fp
1111 effects: cfa.reg = <reg1>
1114 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1115 constraints: <reg1> != fp
1117 effects: cfa_store.reg = <reg1>
1118 cfa_store.offset = cfa.offset - cfa_temp.offset
1121 (set <reg> <const_int>)
1122 effects: cfa_temp.reg = <reg>
1123 cfa_temp.offset = <const_int>
1126 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1127 effects: cfa_temp.reg = <reg1>
1128 cfa_temp.offset |= <const_int>
1131 (set <reg> (high <exp>))
1135 (set <reg> (lo_sum <exp> <const_int>))
1136 effects: cfa_temp.reg = <reg>
1137 cfa_temp.offset = <const_int>
1140 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1141 effects: cfa_store.offset -= <const_int>
1142 cfa.offset = cfa_store.offset if cfa.reg == sp
1143 offset = -cfa_store.offset
1145 cfa.base_offset = offset
1148 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1149 effects: cfa_store.offset += -/+ mode_size(mem)
1150 cfa.offset = cfa_store.offset if cfa.reg == sp
1151 offset = -cfa_store.offset
1153 cfa.base_offset = offset
1156 (set (mem ({minus,plus} <reg1>:cfa_store <const_int>)) <reg2>)
1157 effects: cfa_store.offset += -/+ <const_int>
1158 offset = -cfa_store.offset
1160 cfa.base_offset = offset
1163 (set (mem <reg1>:cfa_store) <reg2>)
1164 effects: offset = -cfa_store.offset
1166 cfa.base_offset = offset */
1169 dwarf2out_frame_debug_expr (expr, label)
1176 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1177 the PARALLEL independently. The first element is always processed if
1178 it is a SET. This is for backward compatibility. Other elements
1179 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1180 flag is set in them. */
1182 if (GET_CODE (expr) == PARALLEL
1183 || GET_CODE (expr) == SEQUENCE)
1186 int limit = XVECLEN (expr, 0);
1188 for (par_index = 0; par_index < limit; par_index++)
1190 rtx x = XVECEXP (expr, 0, par_index);
1192 if (GET_CODE (x) == SET &&
1193 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1194 dwarf2out_frame_debug_expr (x, label);
1199 if (GET_CODE (expr) != SET)
1202 src = SET_SRC (expr);
1203 dest = SET_DEST (expr);
1205 switch (GET_CODE (dest))
1209 /* Update the CFA rule wrt SP or FP. Make sure src is
1210 relative to the current CFA register. */
1211 switch (GET_CODE (src))
1213 /* Setting FP from SP. */
1215 if (cfa.reg == (unsigned) REGNO (src))
1221 /* We used to require that dest be either SP or FP, but the
1222 ARM copies SP to a temporary register, and from there to
1223 FP. So we just rely on the backends to only set
1224 RTX_FRAME_RELATED_P on appropriate insns. */
1225 cfa.reg = REGNO (dest);
1230 if (dest == stack_pointer_rtx)
1234 switch (GET_CODE (XEXP (src, 1)))
1237 offset = INTVAL (XEXP (src, 1));
1240 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1242 offset = cfa_temp.offset;
1248 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1250 /* Restoring SP from FP in the epilogue. */
1251 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1253 cfa.reg = STACK_POINTER_REGNUM;
1255 else if (XEXP (src, 0) != stack_pointer_rtx)
1258 if (GET_CODE (src) == PLUS)
1260 if (cfa.reg == STACK_POINTER_REGNUM)
1261 cfa.offset += offset;
1262 if (cfa_store.reg == STACK_POINTER_REGNUM)
1263 cfa_store.offset += offset;
1265 else if (dest == hard_frame_pointer_rtx)
1268 /* Either setting the FP from an offset of the SP,
1269 or adjusting the FP */
1270 if (! frame_pointer_needed)
1273 if (GET_CODE (XEXP (src, 0)) == REG
1274 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1275 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1277 offset = INTVAL (XEXP (src, 1));
1278 if (GET_CODE (src) == PLUS)
1280 cfa.offset += offset;
1281 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1288 if (GET_CODE (src) != PLUS)
1292 if (GET_CODE (XEXP (src, 0)) == REG
1293 && REGNO (XEXP (src, 0)) == cfa.reg
1294 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1296 /* Setting a temporary CFA register that will be copied
1297 into the FP later on. */
1298 offset = INTVAL (XEXP (src, 1));
1299 if (GET_CODE (src) == PLUS)
1301 cfa.offset += offset;
1302 cfa.reg = REGNO (dest);
1307 /* Setting a scratch register that we will use instead
1308 of SP for saving registers to the stack. */
1309 if (XEXP (src, 1) != stack_pointer_rtx)
1311 if (GET_CODE (XEXP (src, 0)) != REG
1312 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1314 if (cfa.reg != STACK_POINTER_REGNUM)
1316 cfa_store.reg = REGNO (dest);
1317 cfa_store.offset = cfa.offset - cfa_temp.offset;
1324 cfa_temp.reg = REGNO (dest);
1325 cfa_temp.offset = INTVAL (src);
1330 if (GET_CODE (XEXP (src, 0)) != REG
1331 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1332 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1334 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1335 cfa_temp.reg = REGNO (dest);
1336 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1342 def_cfa_1 (label, &cfa);
1345 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1346 will fill in all of the bits. */
1353 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1355 cfa_temp.reg = REGNO (dest);
1356 cfa_temp.offset = INTVAL (XEXP (src, 1));
1360 if (GET_CODE (src) != REG)
1363 /* Saving a register to the stack. Make sure dest is relative to the
1365 switch (GET_CODE (XEXP (dest, 0)))
1370 /* We can't handle variable size modifications. */
1371 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1373 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1375 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1376 || cfa_store.reg != STACK_POINTER_REGNUM)
1378 cfa_store.offset += offset;
1379 if (cfa.reg == STACK_POINTER_REGNUM)
1380 cfa.offset = cfa_store.offset;
1382 offset = -cfa_store.offset;
1387 offset = GET_MODE_SIZE (GET_MODE (dest));
1388 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1391 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1392 || cfa_store.reg != STACK_POINTER_REGNUM)
1394 cfa_store.offset += offset;
1395 if (cfa.reg == STACK_POINTER_REGNUM)
1396 cfa.offset = cfa_store.offset;
1398 offset = -cfa_store.offset;
1402 /* With an offset. */
1405 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1407 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1408 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1411 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1413 offset -= cfa_store.offset;
1417 /* Without an offset. */
1419 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1421 offset = -cfa_store.offset;
1428 if (REGNO (src) != STACK_POINTER_REGNUM
1429 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1430 && (unsigned) REGNO (src) == cfa.reg)
1432 /* We're storing the current CFA reg into the stack. */
1434 if (cfa.offset == 0)
1436 /* If the source register is exactly the CFA, assume
1437 we're saving SP like any other register; this happens
1440 def_cfa_1 (label, &cfa);
1441 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1446 /* Otherwise, we'll need to look in the stack to
1447 calculate the CFA. */
1449 rtx x = XEXP (dest, 0);
1450 if (GET_CODE (x) != REG)
1452 if (GET_CODE (x) != REG)
1454 cfa.reg = (unsigned) REGNO (x);
1455 cfa.base_offset = offset;
1457 def_cfa_1 (label, &cfa);
1462 def_cfa_1 (label, &cfa);
1463 dwarf2out_reg_save (label, REGNO (src), offset);
1471 /* Record call frame debugging information for INSN, which either
1472 sets SP or FP (adjusting how we calculate the frame address) or saves a
1473 register to the stack. If INSN is NULL_RTX, initialize our state. */
1476 dwarf2out_frame_debug (insn)
1482 if (insn == NULL_RTX)
1484 /* Set up state for generating call frame debug info. */
1486 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1488 cfa.reg = STACK_POINTER_REGNUM;
1491 cfa_temp.offset = 0;
1495 if (! RTX_FRAME_RELATED_P (insn))
1497 dwarf2out_stack_adjust (insn);
1501 label = dwarf2out_cfi_label ();
1503 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1505 insn = XEXP (src, 0);
1507 insn = PATTERN (insn);
1509 dwarf2out_frame_debug_expr (insn, label);
1512 /* Output a Call Frame Information opcode and its operand(s). */
1515 output_cfi (cfi, fde)
1516 register dw_cfi_ref cfi;
1517 register dw_fde_ref fde;
1519 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1521 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1522 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1523 "DW_CFA_advance_loc 0x%lx",
1524 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1526 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1528 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1529 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1530 "DW_CFA_offset, column 0x%lx",
1531 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1532 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1534 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1536 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1537 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1538 "DW_CFA_restore, column 0x%lx",
1539 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1543 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1544 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1546 switch (cfi->dw_cfi_opc)
1548 case DW_CFA_set_loc:
1549 dw2_asm_output_offset (DWARF2_ADDR_SIZE,
1550 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1552 case DW_CFA_advance_loc1:
1553 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1554 fde->dw_fde_current_label, NULL);
1555 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1557 case DW_CFA_advance_loc2:
1558 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1559 fde->dw_fde_current_label, NULL);
1560 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1562 case DW_CFA_advance_loc4:
1563 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1564 fde->dw_fde_current_label, NULL);
1565 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1567 case DW_CFA_MIPS_advance_loc8:
1568 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1569 fde->dw_fde_current_label, NULL);
1570 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1572 case DW_CFA_offset_extended:
1573 case DW_CFA_GNU_negative_offset_extended:
1574 case DW_CFA_def_cfa:
1575 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1576 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1578 case DW_CFA_restore_extended:
1579 case DW_CFA_undefined:
1580 case DW_CFA_same_value:
1581 case DW_CFA_def_cfa_register:
1582 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1584 case DW_CFA_register:
1585 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1586 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1588 case DW_CFA_def_cfa_offset:
1589 case DW_CFA_GNU_args_size:
1590 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1592 case DW_CFA_GNU_window_save:
1594 case DW_CFA_def_cfa_expression:
1595 output_cfa_loc (cfi);
1603 /* Output the call frame information used to used to record information
1604 that relates to calculating the frame pointer, and records the
1605 location of saved registers. */
1608 output_call_frame_info (for_eh)
1611 register unsigned long i;
1612 register dw_fde_ref fde;
1613 register dw_cfi_ref cfi;
1614 char l1[20], l2[20];
1615 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1619 /* Do we want to include a pointer to the exception table? */
1620 int eh_ptr = for_eh && exception_table_p ();
1622 /* If we don't have any functions we'll want to unwind out of, don't
1623 emit any EH unwind information. */
1626 for (i = 0; i < fde_table_in_use; ++i)
1627 if (! fde_table[i].nothrow)
1633 /* We're going to be generating comments, so turn on app. */
1639 #ifdef EH_FRAME_SECTION
1640 EH_FRAME_SECTION ();
1642 tree label = get_file_function_name ('F');
1644 force_data_section ();
1645 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1646 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1647 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1649 assemble_label ("__FRAME_BEGIN__");
1652 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1654 /* Output the CIE. */
1655 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1656 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1657 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1658 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1659 dw2_asm_output_offset (for_eh ? 4 : DWARF_OFFSET_SIZE, ld,
1660 "Length of Common Information Entry");
1662 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1663 "Length of Common Information Entry");
1665 ASM_OUTPUT_LABEL (asm_out_file, l1);
1667 /* Now that the CIE pointer is PC-relative for EH,
1668 use 0 to identify the CIE. */
1669 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1670 (for_eh ? 0 : DW_CIE_ID),
1671 "CIE Identifier Tag");
1673 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1677 /* The CIE contains a pointer to the exception region info for the
1678 frame. Make the augmentation string three bytes (including the
1679 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1680 can't handle unaligned relocs. */
1681 dw2_asm_output_nstring ("eh", -1, "CIE Augmentation");
1682 dw2_asm_output_offset (DWARF2_ADDR_SIZE, "__EXCEPTION_TABLE__",
1683 "pointer to exception region info");
1687 dw2_asm_output_data (1, 0, "CIE Augmentation (none)");
1690 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1692 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1693 "CIE Data Alignment Factor");
1695 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1697 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1698 output_cfi (cfi, NULL);
1700 /* Pad the CIE out to an address sized boundary. */
1701 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1702 ASM_OUTPUT_LABEL (asm_out_file, l2);
1703 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1704 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1706 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1707 fputc ('\n', asm_out_file);
1710 /* Loop through all of the FDE's. */
1711 for (i = 0; i < fde_table_in_use; ++i)
1713 fde = &fde_table[i];
1715 /* Don't emit EH unwind info for leaf functions. */
1716 if (for_eh && fde->nothrow)
1719 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1720 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1721 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1722 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1723 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1724 dw2_asm_output_offset (for_eh ? 4 : DWARF_OFFSET_SIZE, ld, "FDE Length");
1726 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1729 ASM_OUTPUT_LABEL (asm_out_file, l1);
1731 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1732 emits a target dependent sized offset when for_eh is not true.
1733 This inconsistency may confuse gdb. The only case where we need a
1734 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1735 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1736 though in order to be compatible with the dwarf_fde struct in frame.c.
1737 If the for_eh case is changed, then the struct in frame.c has
1738 to be adjusted appropriately. */
1740 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1742 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1743 stripattributes (FRAME_SECTION),
1746 dw2_asm_output_offset (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1747 "FDE initial location");
1749 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
1750 fde->dw_fde_begin, "FDE address range");
1752 /* Loop through the Call Frame Instructions associated with
1754 fde->dw_fde_current_label = fde->dw_fde_begin;
1755 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1756 output_cfi (cfi, fde);
1758 /* Pad the FDE out to an address sized boundary. */
1759 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1760 ASM_OUTPUT_LABEL (asm_out_file, l2);
1761 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1762 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1764 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1765 fputc ('\n', asm_out_file);
1769 #ifndef EH_FRAME_SECTION
1771 dw2_asm_output_data (4, 0, "End of Table");
1773 #ifdef MIPS_DEBUGGING_INFO
1774 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1775 get a value of 0. Putting .align 0 after the label fixes it. */
1776 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1779 /* Turn off app to make assembly quicker. */
1784 /* Output a marker (i.e. a label) for the beginning of a function, before
1788 dwarf2out_begin_prologue ()
1790 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1791 register dw_fde_ref fde;
1793 ++current_funcdef_number;
1795 function_section (current_function_decl);
1796 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1797 current_funcdef_number);
1798 ASM_OUTPUT_LABEL (asm_out_file, label);
1799 current_function_func_begin_label = get_identifier (label);
1801 /* Expand the fde table if necessary. */
1802 if (fde_table_in_use == fde_table_allocated)
1804 fde_table_allocated += FDE_TABLE_INCREMENT;
1806 = (dw_fde_ref) xrealloc (fde_table,
1807 fde_table_allocated * sizeof (dw_fde_node));
1810 /* Record the FDE associated with this function. */
1811 current_funcdef_fde = fde_table_in_use;
1813 /* Add the new FDE at the end of the fde_table. */
1814 fde = &fde_table[fde_table_in_use++];
1815 fde->dw_fde_begin = xstrdup (label);
1816 fde->dw_fde_current_label = NULL;
1817 fde->dw_fde_end = NULL;
1818 fde->dw_fde_cfi = NULL;
1819 fde->nothrow = current_function_nothrow;
1821 args_size = old_args_size = 0;
1824 /* Output a marker (i.e. a label) for the absolute end of the generated code
1825 for a function definition. This gets called *after* the epilogue code has
1829 dwarf2out_end_epilogue ()
1832 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1834 /* Output a label to mark the endpoint of the code generated for this
1836 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1837 ASM_OUTPUT_LABEL (asm_out_file, label);
1838 fde = &fde_table[fde_table_in_use - 1];
1839 fde->dw_fde_end = xstrdup (label);
1843 dwarf2out_frame_init ()
1845 /* Allocate the initial hunk of the fde_table. */
1846 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1847 fde_table_allocated = FDE_TABLE_INCREMENT;
1848 fde_table_in_use = 0;
1850 /* Generate the CFA instructions common to all FDE's. Do it now for the
1851 sake of lookup_cfa. */
1853 #ifdef DWARF2_UNWIND_INFO
1854 /* On entry, the Canonical Frame Address is at SP. */
1855 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1856 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1861 dwarf2out_frame_finish ()
1863 /* Output call frame information. */
1864 #ifdef MIPS_DEBUGGING_INFO
1865 if (write_symbols == DWARF2_DEBUG)
1866 output_call_frame_info (0);
1867 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1868 output_call_frame_info (1);
1870 if (write_symbols == DWARF2_DEBUG
1871 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1872 output_call_frame_info (1);
1876 /* And now, the subset of the debugging information support code necessary
1877 for emitting location expressions. */
1879 typedef struct dw_val_struct *dw_val_ref;
1880 typedef struct die_struct *dw_die_ref;
1881 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1883 /* Each DIE may have a series of attribute/value pairs. Values
1884 can take on several forms. The forms that are used in this
1885 implementation are listed below. */
1892 dw_val_class_unsigned_const,
1893 dw_val_class_long_long,
1896 dw_val_class_die_ref,
1897 dw_val_class_fde_ref,
1898 dw_val_class_lbl_id,
1899 dw_val_class_lbl_offset,
1904 /* Describe a double word constant value. */
1905 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
1907 typedef struct dw_long_long_struct
1914 /* Describe a floating point constant value. */
1916 typedef struct dw_fp_struct
1923 /* The dw_val_node describes an attribute's value, as it is
1924 represented internally. */
1926 typedef struct dw_val_struct
1928 dw_val_class val_class;
1932 dw_loc_descr_ref val_loc;
1934 long unsigned val_unsigned;
1935 dw_long_long_const val_long_long;
1936 dw_float_const val_float;
1941 unsigned val_fde_index;
1944 unsigned char val_flag;
1950 /* Locations in memory are described using a sequence of stack machine
1953 typedef struct dw_loc_descr_struct
1955 dw_loc_descr_ref dw_loc_next;
1956 enum dwarf_location_atom dw_loc_opc;
1957 dw_val_node dw_loc_oprnd1;
1958 dw_val_node dw_loc_oprnd2;
1963 static const char *dwarf_stack_op_name PARAMS ((unsigned));
1964 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
1967 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
1969 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
1970 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
1971 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
1972 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
1974 /* Convert a DWARF stack opcode into its string name. */
1977 dwarf_stack_op_name (op)
1978 register unsigned op;
1983 return "DW_OP_addr";
1985 return "DW_OP_deref";
1987 return "DW_OP_const1u";
1989 return "DW_OP_const1s";
1991 return "DW_OP_const2u";
1993 return "DW_OP_const2s";
1995 return "DW_OP_const4u";
1997 return "DW_OP_const4s";
1999 return "DW_OP_const8u";
2001 return "DW_OP_const8s";
2003 return "DW_OP_constu";
2005 return "DW_OP_consts";
2009 return "DW_OP_drop";
2011 return "DW_OP_over";
2013 return "DW_OP_pick";
2015 return "DW_OP_swap";
2019 return "DW_OP_xderef";
2027 return "DW_OP_minus";
2039 return "DW_OP_plus";
2040 case DW_OP_plus_uconst:
2041 return "DW_OP_plus_uconst";
2047 return "DW_OP_shra";
2065 return "DW_OP_skip";
2067 return "DW_OP_lit0";
2069 return "DW_OP_lit1";
2071 return "DW_OP_lit2";
2073 return "DW_OP_lit3";
2075 return "DW_OP_lit4";
2077 return "DW_OP_lit5";
2079 return "DW_OP_lit6";
2081 return "DW_OP_lit7";
2083 return "DW_OP_lit8";
2085 return "DW_OP_lit9";
2087 return "DW_OP_lit10";
2089 return "DW_OP_lit11";
2091 return "DW_OP_lit12";
2093 return "DW_OP_lit13";
2095 return "DW_OP_lit14";
2097 return "DW_OP_lit15";
2099 return "DW_OP_lit16";
2101 return "DW_OP_lit17";
2103 return "DW_OP_lit18";
2105 return "DW_OP_lit19";
2107 return "DW_OP_lit20";
2109 return "DW_OP_lit21";
2111 return "DW_OP_lit22";
2113 return "DW_OP_lit23";
2115 return "DW_OP_lit24";
2117 return "DW_OP_lit25";
2119 return "DW_OP_lit26";
2121 return "DW_OP_lit27";
2123 return "DW_OP_lit28";
2125 return "DW_OP_lit29";
2127 return "DW_OP_lit30";
2129 return "DW_OP_lit31";
2131 return "DW_OP_reg0";
2133 return "DW_OP_reg1";
2135 return "DW_OP_reg2";
2137 return "DW_OP_reg3";
2139 return "DW_OP_reg4";
2141 return "DW_OP_reg5";
2143 return "DW_OP_reg6";
2145 return "DW_OP_reg7";
2147 return "DW_OP_reg8";
2149 return "DW_OP_reg9";
2151 return "DW_OP_reg10";
2153 return "DW_OP_reg11";
2155 return "DW_OP_reg12";
2157 return "DW_OP_reg13";
2159 return "DW_OP_reg14";
2161 return "DW_OP_reg15";
2163 return "DW_OP_reg16";
2165 return "DW_OP_reg17";
2167 return "DW_OP_reg18";
2169 return "DW_OP_reg19";
2171 return "DW_OP_reg20";
2173 return "DW_OP_reg21";
2175 return "DW_OP_reg22";
2177 return "DW_OP_reg23";
2179 return "DW_OP_reg24";
2181 return "DW_OP_reg25";
2183 return "DW_OP_reg26";
2185 return "DW_OP_reg27";
2187 return "DW_OP_reg28";
2189 return "DW_OP_reg29";
2191 return "DW_OP_reg30";
2193 return "DW_OP_reg31";
2195 return "DW_OP_breg0";
2197 return "DW_OP_breg1";
2199 return "DW_OP_breg2";
2201 return "DW_OP_breg3";
2203 return "DW_OP_breg4";
2205 return "DW_OP_breg5";
2207 return "DW_OP_breg6";
2209 return "DW_OP_breg7";
2211 return "DW_OP_breg8";
2213 return "DW_OP_breg9";
2215 return "DW_OP_breg10";
2217 return "DW_OP_breg11";
2219 return "DW_OP_breg12";
2221 return "DW_OP_breg13";
2223 return "DW_OP_breg14";
2225 return "DW_OP_breg15";
2227 return "DW_OP_breg16";
2229 return "DW_OP_breg17";
2231 return "DW_OP_breg18";
2233 return "DW_OP_breg19";
2235 return "DW_OP_breg20";
2237 return "DW_OP_breg21";
2239 return "DW_OP_breg22";
2241 return "DW_OP_breg23";
2243 return "DW_OP_breg24";
2245 return "DW_OP_breg25";
2247 return "DW_OP_breg26";
2249 return "DW_OP_breg27";
2251 return "DW_OP_breg28";
2253 return "DW_OP_breg29";
2255 return "DW_OP_breg30";
2257 return "DW_OP_breg31";
2259 return "DW_OP_regx";
2261 return "DW_OP_fbreg";
2263 return "DW_OP_bregx";
2265 return "DW_OP_piece";
2266 case DW_OP_deref_size:
2267 return "DW_OP_deref_size";
2268 case DW_OP_xderef_size:
2269 return "DW_OP_xderef_size";
2273 return "OP_<unknown>";
2277 /* Return a pointer to a newly allocated location description. Location
2278 descriptions are simple expression terms that can be strung
2279 together to form more complicated location (address) descriptions. */
2281 static inline dw_loc_descr_ref
2282 new_loc_descr (op, oprnd1, oprnd2)
2283 register enum dwarf_location_atom op;
2284 register unsigned long oprnd1;
2285 register unsigned long oprnd2;
2287 /* Use xcalloc here so we clear out all of the long_long constant in
2289 register dw_loc_descr_ref descr
2290 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2292 descr->dw_loc_opc = op;
2293 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2294 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2295 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2296 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2301 /* Add a location description term to a location description expression. */
2304 add_loc_descr (list_head, descr)
2305 register dw_loc_descr_ref *list_head;
2306 register dw_loc_descr_ref descr;
2308 register dw_loc_descr_ref *d;
2310 /* Find the end of the chain. */
2311 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2317 /* Return the size of a location descriptor. */
2319 static unsigned long
2320 size_of_loc_descr (loc)
2321 register dw_loc_descr_ref loc;
2323 register unsigned long size = 1;
2325 switch (loc->dw_loc_opc)
2328 size += DWARF2_ADDR_SIZE;
2347 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2350 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2355 case DW_OP_plus_uconst:
2356 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2394 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2397 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2400 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2403 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2404 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2407 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2409 case DW_OP_deref_size:
2410 case DW_OP_xderef_size:
2420 /* Return the size of a series of location descriptors. */
2422 static unsigned long
2424 register dw_loc_descr_ref loc;
2426 register unsigned long size = 0;
2428 for (; loc != NULL; loc = loc->dw_loc_next)
2430 loc->dw_loc_addr = size;
2431 size += size_of_loc_descr (loc);
2437 /* Output location description stack opcode's operands (if any). */
2440 output_loc_operands (loc)
2441 register dw_loc_descr_ref loc;
2443 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2444 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2446 switch (loc->dw_loc_opc)
2448 #ifdef DWARF2_DEBUGGING_INFO
2450 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2454 dw2_asm_output_data (2, val1->v.val_int, NULL);
2458 dw2_asm_output_data (4, val1->v.val_int, NULL);
2462 if (HOST_BITS_PER_LONG < 64)
2464 dw2_asm_output_data (8, val1->v.val_int, NULL);
2471 if (val1->val_class == dw_val_class_loc)
2472 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2476 dw2_asm_output_data (2, offset, NULL);
2489 /* We currently don't make any attempt to make sure these are
2490 aligned properly like we do for the main unwind info, so
2491 don't support emitting things larger than a byte if we're
2492 only doing unwinding. */
2497 dw2_asm_output_data (1, val1->v.val_int, NULL);
2500 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2503 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2506 dw2_asm_output_data (1, val1->v.val_int, NULL);
2508 case DW_OP_plus_uconst:
2509 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2543 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2546 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2549 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2552 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2553 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2556 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2558 case DW_OP_deref_size:
2559 case DW_OP_xderef_size:
2560 dw2_asm_output_data (1, val1->v.val_int, NULL);
2563 /* Other codes have no operands. */
2568 /* Output a sequence of location operations. */
2571 output_loc_sequence (loc)
2572 dw_loc_descr_ref loc;
2574 for (; loc != NULL; loc = loc->dw_loc_next)
2576 /* Output the opcode. */
2577 dw2_asm_output_data (1, loc->dw_loc_opc,
2578 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2580 /* Output the operand(s) (if any). */
2581 output_loc_operands (loc);
2585 /* This routine will generate the correct assembly data for a location
2586 description based on a cfi entry with a complex address. */
2589 output_cfa_loc (cfi)
2592 dw_loc_descr_ref loc;
2595 /* Output the size of the block. */
2596 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2597 size = size_of_locs (loc);
2598 dw2_asm_output_data_uleb128 (size, NULL);
2600 /* Now output the operations themselves. */
2601 output_loc_sequence (loc);
2604 /* This function builds a dwarf location descriptor seqeunce from
2605 a dw_cfa_location. */
2607 static struct dw_loc_descr_struct *
2609 dw_cfa_location *cfa;
2611 struct dw_loc_descr_struct *head, *tmp;
2613 if (cfa->indirect == 0)
2616 if (cfa->base_offset)
2619 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2621 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2623 else if (cfa->reg <= 31)
2624 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2626 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2627 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2628 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2629 add_loc_descr (&head, tmp);
2630 if (cfa->offset != 0)
2632 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2633 add_loc_descr (&head, tmp);
2638 /* This function fills in aa dw_cfa_location structure from a
2639 dwarf location descriptor sequence. */
2642 get_cfa_from_loc_descr (cfa, loc)
2643 dw_cfa_location *cfa;
2644 struct dw_loc_descr_struct *loc;
2646 struct dw_loc_descr_struct *ptr;
2648 cfa->base_offset = 0;
2652 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2654 enum dwarf_location_atom op = ptr->dw_loc_opc;
2689 cfa->reg = op - DW_OP_reg0;
2692 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2726 cfa->reg = op - DW_OP_breg0;
2727 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2730 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2731 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2736 case DW_OP_plus_uconst:
2737 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2740 internal_error ("DW_LOC_OP %s not implememnted\n",
2741 dwarf_stack_op_name (ptr->dw_loc_opc));
2745 #endif /* .debug_frame support */
2747 /* And now, the support for symbolic debugging information. */
2748 #ifdef DWARF2_DEBUGGING_INFO
2750 /* NOTE: In the comments in this file, many references are made to
2751 "Debugging Information Entries". This term is abbreviated as `DIE'
2752 throughout the remainder of this file. */
2754 /* An internal representation of the DWARF output is built, and then
2755 walked to generate the DWARF debugging info. The walk of the internal
2756 representation is done after the entire program has been compiled.
2757 The types below are used to describe the internal representation. */
2759 /* Various DIE's use offsets relative to the beginning of the
2760 .debug_info section to refer to each other. */
2762 typedef long int dw_offset;
2764 /* Define typedefs here to avoid circular dependencies. */
2766 typedef struct dw_attr_struct *dw_attr_ref;
2767 typedef struct dw_line_info_struct *dw_line_info_ref;
2768 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2769 typedef struct pubname_struct *pubname_ref;
2770 typedef dw_die_ref *arange_ref;
2772 /* Each entry in the line_info_table maintains the file and
2773 line number associated with the label generated for that
2774 entry. The label gives the PC value associated with
2775 the line number entry. */
2777 typedef struct dw_line_info_struct
2779 unsigned long dw_file_num;
2780 unsigned long dw_line_num;
2784 /* Line information for functions in separate sections; each one gets its
2786 typedef struct dw_separate_line_info_struct
2788 unsigned long dw_file_num;
2789 unsigned long dw_line_num;
2790 unsigned long function;
2792 dw_separate_line_info_entry;
2794 /* Each DIE attribute has a field specifying the attribute kind,
2795 a link to the next attribute in the chain, and an attribute value.
2796 Attributes are typically linked below the DIE they modify. */
2798 typedef struct dw_attr_struct
2800 enum dwarf_attribute dw_attr;
2801 dw_attr_ref dw_attr_next;
2802 dw_val_node dw_attr_val;
2806 /* The Debugging Information Entry (DIE) structure */
2808 typedef struct die_struct
2810 enum dwarf_tag die_tag;
2812 dw_attr_ref die_attr;
2813 dw_die_ref die_parent;
2814 dw_die_ref die_child;
2816 dw_offset die_offset;
2817 unsigned long die_abbrev;
2822 /* The pubname structure */
2824 typedef struct pubname_struct
2831 /* The limbo die list structure. */
2832 typedef struct limbo_die_struct
2835 struct limbo_die_struct *next;
2839 /* How to start an assembler comment. */
2840 #ifndef ASM_COMMENT_START
2841 #define ASM_COMMENT_START ";#"
2844 /* Define a macro which returns non-zero for a TYPE_DECL which was
2845 implicitly generated for a tagged type.
2847 Note that unlike the gcc front end (which generates a NULL named
2848 TYPE_DECL node for each complete tagged type, each array type, and
2849 each function type node created) the g++ front end generates a
2850 _named_ TYPE_DECL node for each tagged type node created.
2851 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2852 generate a DW_TAG_typedef DIE for them. */
2854 #define TYPE_DECL_IS_STUB(decl) \
2855 (DECL_NAME (decl) == NULL_TREE \
2856 || (DECL_ARTIFICIAL (decl) \
2857 && is_tagged_type (TREE_TYPE (decl)) \
2858 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2859 /* This is necessary for stub decls that \
2860 appear in nested inline functions. */ \
2861 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2862 && (decl_ultimate_origin (decl) \
2863 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2865 /* Information concerning the compilation unit's programming
2866 language, and compiler version. */
2868 extern int flag_traditional;
2870 /* Fixed size portion of the DWARF compilation unit header. */
2871 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2873 /* Fixed size portion of debugging line information prolog. */
2874 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2876 /* Fixed size portion of public names info. */
2877 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2879 /* Fixed size portion of the address range info. */
2880 #define DWARF_ARANGES_HEADER_SIZE \
2881 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2882 - DWARF_OFFSET_SIZE)
2884 /* Size of padding portion in the address range info. It must be
2885 aligned to twice the pointer size. */
2886 #define DWARF_ARANGES_PAD_SIZE \
2887 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
2888 - (2 * DWARF_OFFSET_SIZE + 4))
2890 /* Use assembler line directives if available. */
2891 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2892 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2893 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2895 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2899 /* Define the architecture-dependent minimum instruction length (in bytes).
2900 In this implementation of DWARF, this field is used for information
2901 purposes only. Since GCC generates assembly language, we have
2902 no a priori knowledge of how many instruction bytes are generated
2903 for each source line, and therefore can use only the DW_LNE_set_address
2904 and DW_LNS_fixed_advance_pc line information commands. */
2906 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2907 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2910 /* Minimum line offset in a special line info. opcode.
2911 This value was chosen to give a reasonable range of values. */
2912 #define DWARF_LINE_BASE -10
2914 /* First special line opcde - leave room for the standard opcodes. */
2915 #define DWARF_LINE_OPCODE_BASE 10
2917 /* Range of line offsets in a special line info. opcode. */
2918 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2920 /* Flag that indicates the initial value of the is_stmt_start flag.
2921 In the present implementation, we do not mark any lines as
2922 the beginning of a source statement, because that information
2923 is not made available by the GCC front-end. */
2924 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2926 /* This location is used by calc_die_sizes() to keep track
2927 the offset of each DIE within the .debug_info section. */
2928 static unsigned long next_die_offset;
2930 /* Record the root of the DIE's built for the current compilation unit. */
2931 static dw_die_ref comp_unit_die;
2933 /* A list of DIEs with a NULL parent waiting to be relocated. */
2934 static limbo_die_node *limbo_die_list = 0;
2936 /* Structure used by lookup_filename to manage sets of filenames. */
2942 unsigned last_lookup_index;
2945 /* Size (in elements) of increments by which we may expand the filename
2947 #define FILE_TABLE_INCREMENT 64
2949 /* Filenames referenced by declarations this compilation unit. */
2950 static struct file_table decl_file_table;
2952 /* Filenames referenced by line numbers in this compilation unit. */
2953 static struct file_table line_file_table;
2955 /* Local pointer to the name of the main input file. Initialized in
2957 static const char *primary_filename;
2959 /* A pointer to the base of a table of references to DIE's that describe
2960 declarations. The table is indexed by DECL_UID() which is a unique
2961 number identifying each decl. */
2962 static dw_die_ref *decl_die_table;
2964 /* Number of elements currently allocated for the decl_die_table. */
2965 static unsigned decl_die_table_allocated;
2967 /* Number of elements in decl_die_table currently in use. */
2968 static unsigned decl_die_table_in_use;
2970 /* Size (in elements) of increments by which we may expand the
2972 #define DECL_DIE_TABLE_INCREMENT 256
2974 /* A pointer to the base of a table of references to declaration
2975 scopes. This table is a display which tracks the nesting
2976 of declaration scopes at the current scope and containing
2977 scopes. This table is used to find the proper place to
2978 define type declaration DIE's. */
2979 static tree *decl_scope_table;
2981 /* Number of elements currently allocated for the decl_scope_table. */
2982 static int decl_scope_table_allocated;
2984 /* Current level of nesting of declaration scopes. */
2985 static int decl_scope_depth;
2987 /* Size (in elements) of increments by which we may expand the
2988 decl_scope_table. */
2989 #define DECL_SCOPE_TABLE_INCREMENT 64
2991 /* A pointer to the base of a list of references to DIE's that
2992 are uniquely identified by their tag, presence/absence of
2993 children DIE's, and list of attribute/value pairs. */
2994 static dw_die_ref *abbrev_die_table;
2996 /* Number of elements currently allocated for abbrev_die_table. */
2997 static unsigned abbrev_die_table_allocated;
2999 /* Number of elements in type_die_table currently in use. */
3000 static unsigned abbrev_die_table_in_use;
3002 /* Size (in elements) of increments by which we may expand the
3003 abbrev_die_table. */
3004 #define ABBREV_DIE_TABLE_INCREMENT 256
3006 /* A pointer to the base of a table that contains line information
3007 for each source code line in .text in the compilation unit. */
3008 static dw_line_info_ref line_info_table;
3010 /* Number of elements currently allocated for line_info_table. */
3011 static unsigned line_info_table_allocated;
3013 /* Number of elements in separate_line_info_table currently in use. */
3014 static unsigned separate_line_info_table_in_use;
3016 /* A pointer to the base of a table that contains line information
3017 for each source code line outside of .text in the compilation unit. */
3018 static dw_separate_line_info_ref separate_line_info_table;
3020 /* Number of elements currently allocated for separate_line_info_table. */
3021 static unsigned separate_line_info_table_allocated;
3023 /* Number of elements in line_info_table currently in use. */
3024 static unsigned line_info_table_in_use;
3026 /* Size (in elements) of increments by which we may expand the
3028 #define LINE_INFO_TABLE_INCREMENT 1024
3030 /* A pointer to the base of a table that contains a list of publicly
3031 accessible names. */
3032 static pubname_ref pubname_table;
3034 /* Number of elements currently allocated for pubname_table. */
3035 static unsigned pubname_table_allocated;
3037 /* Number of elements in pubname_table currently in use. */
3038 static unsigned pubname_table_in_use;
3040 /* Size (in elements) of increments by which we may expand the
3042 #define PUBNAME_TABLE_INCREMENT 64
3044 /* A pointer to the base of a table that contains a list of publicly
3045 accessible names. */
3046 static arange_ref arange_table;
3048 /* Number of elements currently allocated for arange_table. */
3049 static unsigned arange_table_allocated;
3051 /* Number of elements in arange_table currently in use. */
3052 static unsigned arange_table_in_use;
3054 /* Size (in elements) of increments by which we may expand the
3056 #define ARANGE_TABLE_INCREMENT 64
3058 /* A pointer to the base of a list of incomplete types which might be
3059 completed at some later time. */
3061 static tree *incomplete_types_list;
3063 /* Number of elements currently allocated for the incomplete_types_list. */
3064 static unsigned incomplete_types_allocated;
3066 /* Number of elements of incomplete_types_list currently in use. */
3067 static unsigned incomplete_types;
3069 /* Size (in elements) of increments by which we may expand the incomplete
3070 types list. Actually, a single hunk of space of this size should
3071 be enough for most typical programs. */
3072 #define INCOMPLETE_TYPES_INCREMENT 64
3074 /* Record whether the function being analyzed contains inlined functions. */
3075 static int current_function_has_inlines;
3076 #if 0 && defined (MIPS_DEBUGGING_INFO)
3077 static int comp_unit_has_inlines;
3080 /* Array of RTXes referenced by the debugging information, which therefore
3081 must be kept around forever. We do this rather than perform GC on
3082 the dwarf info because almost all of the dwarf info lives forever, and
3083 it's easier to support non-GC frontends this way. */
3084 static varray_type used_rtx_varray;
3086 /* Forward declarations for functions defined in this file. */
3088 static int is_pseudo_reg PARAMS ((rtx));
3089 static tree type_main_variant PARAMS ((tree));
3090 static int is_tagged_type PARAMS ((tree));
3091 static const char *dwarf_tag_name PARAMS ((unsigned));
3092 static const char *dwarf_attr_name PARAMS ((unsigned));
3093 static const char *dwarf_form_name PARAMS ((unsigned));
3095 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3097 static tree decl_ultimate_origin PARAMS ((tree));
3098 static tree block_ultimate_origin PARAMS ((tree));
3099 static tree decl_class_context PARAMS ((tree));
3100 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3101 static void add_AT_flag PARAMS ((dw_die_ref,
3102 enum dwarf_attribute,
3104 static void add_AT_int PARAMS ((dw_die_ref,
3105 enum dwarf_attribute, long));
3106 static void add_AT_unsigned PARAMS ((dw_die_ref,
3107 enum dwarf_attribute,
3109 static void add_AT_long_long PARAMS ((dw_die_ref,
3110 enum dwarf_attribute,
3113 static void add_AT_float PARAMS ((dw_die_ref,
3114 enum dwarf_attribute,
3116 static void add_AT_string PARAMS ((dw_die_ref,
3117 enum dwarf_attribute,
3119 static void add_AT_die_ref PARAMS ((dw_die_ref,
3120 enum dwarf_attribute,
3122 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3123 enum dwarf_attribute,
3125 static void add_AT_loc PARAMS ((dw_die_ref,
3126 enum dwarf_attribute,
3128 static void add_AT_addr PARAMS ((dw_die_ref,
3129 enum dwarf_attribute,
3131 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3132 enum dwarf_attribute,
3134 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3135 enum dwarf_attribute,
3137 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3138 enum dwarf_attribute));
3139 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3140 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3141 static const char *get_AT_string PARAMS ((dw_die_ref,
3142 enum dwarf_attribute));
3143 static int get_AT_flag PARAMS ((dw_die_ref,
3144 enum dwarf_attribute));
3145 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3146 enum dwarf_attribute));
3147 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3148 enum dwarf_attribute));
3149 static int is_c_family PARAMS ((void));
3150 static int is_java PARAMS ((void));
3151 static int is_fortran PARAMS ((void));
3152 static void remove_AT PARAMS ((dw_die_ref,
3153 enum dwarf_attribute));
3154 static void remove_children PARAMS ((dw_die_ref));
3155 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3156 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3157 static dw_die_ref lookup_type_die PARAMS ((tree));
3158 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3159 static dw_die_ref lookup_decl_die PARAMS ((tree));
3160 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3161 static void print_spaces PARAMS ((FILE *));
3162 static void print_die PARAMS ((dw_die_ref, FILE *));
3163 static void print_dwarf_line_table PARAMS ((FILE *));
3164 static void reverse_die_lists PARAMS ((dw_die_ref));
3165 static void reverse_all_dies PARAMS ((dw_die_ref));
3166 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3167 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3168 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3169 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3170 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3171 static void compute_section_prefix PARAMS ((dw_die_ref));
3172 static int is_type_die PARAMS ((dw_die_ref));
3173 static int is_comdat_die PARAMS ((dw_die_ref));
3174 static int is_symbol_die PARAMS ((dw_die_ref));
3175 static char *gen_internal_sym PARAMS ((void));
3176 static void assign_symbol_names PARAMS ((dw_die_ref));
3177 static void break_out_includes PARAMS ((dw_die_ref));
3178 static void add_sibling_attributes PARAMS ((dw_die_ref));
3179 static void build_abbrev_table PARAMS ((dw_die_ref));
3180 static unsigned long size_of_string PARAMS ((const char *));
3181 static int constant_size PARAMS ((long unsigned));
3182 static unsigned long size_of_die PARAMS ((dw_die_ref));
3183 static void calc_die_sizes PARAMS ((dw_die_ref));
3184 static void mark_dies PARAMS ((dw_die_ref));
3185 static void unmark_dies PARAMS ((dw_die_ref));
3186 static unsigned long size_of_line_prolog PARAMS ((void));
3187 static unsigned long size_of_pubnames PARAMS ((void));
3188 static unsigned long size_of_aranges PARAMS ((void));
3189 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3190 static void output_value_format PARAMS ((dw_attr_ref));
3191 static void output_abbrev_section PARAMS ((void));
3192 static void output_die_symbol PARAMS ((dw_die_ref));
3193 static void output_die PARAMS ((dw_die_ref));
3194 static void output_compilation_unit_header PARAMS ((void));
3195 static void output_comp_unit PARAMS ((dw_die_ref));
3196 static const char *dwarf2_name PARAMS ((tree, int));
3197 static void add_pubname PARAMS ((tree, dw_die_ref));
3198 static void output_pubnames PARAMS ((void));
3199 static void add_arange PARAMS ((tree, dw_die_ref));
3200 static void output_aranges PARAMS ((void));
3201 static void output_line_info PARAMS ((void));
3202 static void output_file_names PARAMS ((void));
3203 static dw_die_ref base_type_die PARAMS ((tree));
3204 static tree root_type PARAMS ((tree));
3205 static int is_base_type PARAMS ((tree));
3206 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3207 static int type_is_enum PARAMS ((tree));
3208 static unsigned int reg_number PARAMS ((rtx));
3209 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3210 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3211 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3212 static int is_based_loc PARAMS ((rtx));
3213 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3214 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3215 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3216 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3217 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3218 static tree field_type PARAMS ((tree));
3219 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3220 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3221 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3222 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3223 static void add_AT_location_description PARAMS ((dw_die_ref,
3224 enum dwarf_attribute, rtx));
3225 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3226 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3227 static rtx rtl_for_decl_location PARAMS ((tree));
3228 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3229 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3230 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3231 static void add_bound_info PARAMS ((dw_die_ref,
3232 enum dwarf_attribute, tree));
3233 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3234 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3235 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3236 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3237 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3238 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3239 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3240 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3241 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3242 static void push_decl_scope PARAMS ((tree));
3243 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3244 static void pop_decl_scope PARAMS ((void));
3245 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3247 static const char *type_tag PARAMS ((tree));
3248 static tree member_declared_type PARAMS ((tree));
3250 static const char *decl_start_label PARAMS ((tree));
3252 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3253 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3255 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3257 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3258 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3259 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3260 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3261 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3262 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3263 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3264 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3265 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3266 static void gen_label_die PARAMS ((tree, dw_die_ref));
3267 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3268 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3269 static void gen_field_die PARAMS ((tree, dw_die_ref));
3270 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3271 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3272 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3273 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3274 static void gen_member_die PARAMS ((tree, dw_die_ref));
3275 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3276 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3277 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3278 static void gen_type_die PARAMS ((tree, dw_die_ref));
3279 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3280 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3281 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3282 static int is_redundant_typedef PARAMS ((tree));
3283 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3284 static unsigned lookup_filename PARAMS ((struct file_table *,
3286 static void init_file_table PARAMS ((struct file_table *));
3287 static void add_incomplete_type PARAMS ((tree));
3288 static void retry_incomplete_types PARAMS ((void));
3289 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3290 static rtx save_rtx PARAMS ((rtx));
3291 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3292 static int file_info_cmp PARAMS ((const void *, const void *));
3294 /* Section names used to hold DWARF debugging information. */
3295 #ifndef DEBUG_INFO_SECTION
3296 #define DEBUG_INFO_SECTION ".debug_info"
3298 #ifndef ABBREV_SECTION
3299 #define ABBREV_SECTION ".debug_abbrev"
3301 #ifndef ARANGES_SECTION
3302 #define ARANGES_SECTION ".debug_aranges"
3304 #ifndef DW_MACINFO_SECTION
3305 #define DW_MACINFO_SECTION ".debug_macinfo"
3307 #ifndef DEBUG_LINE_SECTION
3308 #define DEBUG_LINE_SECTION ".debug_line"
3311 #define LOC_SECTION ".debug_loc"
3313 #ifndef PUBNAMES_SECTION
3314 #define PUBNAMES_SECTION ".debug_pubnames"
3317 #define STR_SECTION ".debug_str"
3320 /* Standard ELF section names for compiled code and data. */
3321 #ifndef TEXT_SECTION
3322 #define TEXT_SECTION ".text"
3324 #ifndef DATA_SECTION
3325 #define DATA_SECTION ".data"
3328 #define BSS_SECTION ".bss"
3331 /* Labels we insert at beginning sections we can reference instead of
3332 the section names themselves. */
3334 #ifndef TEXT_SECTION_LABEL
3335 #define TEXT_SECTION_LABEL "Ltext"
3337 #ifndef DEBUG_LINE_SECTION_LABEL
3338 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3340 #ifndef DEBUG_INFO_SECTION_LABEL
3341 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3343 #ifndef ABBREV_SECTION_LABEL
3344 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3347 /* Definitions of defaults for formats and names of various special
3348 (artificial) labels which may be generated within this file (when the -g
3349 options is used and DWARF_DEBUGGING_INFO is in effect.
3350 If necessary, these may be overridden from within the tm.h file, but
3351 typically, overriding these defaults is unnecessary. */
3353 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3354 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3355 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3356 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3357 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3359 #ifndef TEXT_END_LABEL
3360 #define TEXT_END_LABEL "Letext"
3362 #ifndef DATA_END_LABEL
3363 #define DATA_END_LABEL "Ledata"
3365 #ifndef BSS_END_LABEL
3366 #define BSS_END_LABEL "Lebss"
3368 #ifndef BLOCK_BEGIN_LABEL
3369 #define BLOCK_BEGIN_LABEL "LBB"
3371 #ifndef BLOCK_END_LABEL
3372 #define BLOCK_END_LABEL "LBE"
3374 #ifndef BODY_BEGIN_LABEL
3375 #define BODY_BEGIN_LABEL "Lbb"
3377 #ifndef BODY_END_LABEL
3378 #define BODY_END_LABEL "Lbe"
3380 #ifndef LINE_CODE_LABEL
3381 #define LINE_CODE_LABEL "LM"
3383 #ifndef SEPARATE_LINE_CODE_LABEL
3384 #define SEPARATE_LINE_CODE_LABEL "LSM"
3387 /* We allow a language front-end to designate a function that is to be
3388 called to "demangle" any name before it it put into a DIE. */
3390 static const char *(*demangle_name_func) PARAMS ((const char *));
3393 dwarf2out_set_demangle_name_func (func)
3394 const char *(*func) PARAMS ((const char *));
3396 demangle_name_func = func;
3399 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3400 that means adding it to used_rtx_varray. If not, that means making
3401 a copy on the permanent_obstack. */
3407 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3412 /* Test if rtl node points to a pseudo register. */
3418 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3419 || (GET_CODE (rtl) == SUBREG
3420 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3423 /* Return a reference to a type, with its const and volatile qualifiers
3427 type_main_variant (type)
3430 type = TYPE_MAIN_VARIANT (type);
3432 /* There really should be only one main variant among any group of variants
3433 of a given type (and all of the MAIN_VARIANT values for all members of
3434 the group should point to that one type) but sometimes the C front-end
3435 messes this up for array types, so we work around that bug here. */
3437 if (TREE_CODE (type) == ARRAY_TYPE)
3438 while (type != TYPE_MAIN_VARIANT (type))
3439 type = TYPE_MAIN_VARIANT (type);
3444 /* Return non-zero if the given type node represents a tagged type. */
3447 is_tagged_type (type)
3450 register enum tree_code code = TREE_CODE (type);
3452 return (code == RECORD_TYPE || code == UNION_TYPE
3453 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3456 /* Convert a DIE tag into its string name. */
3459 dwarf_tag_name (tag)
3460 register unsigned tag;
3464 case DW_TAG_padding:
3465 return "DW_TAG_padding";
3466 case DW_TAG_array_type:
3467 return "DW_TAG_array_type";
3468 case DW_TAG_class_type:
3469 return "DW_TAG_class_type";
3470 case DW_TAG_entry_point:
3471 return "DW_TAG_entry_point";
3472 case DW_TAG_enumeration_type:
3473 return "DW_TAG_enumeration_type";
3474 case DW_TAG_formal_parameter:
3475 return "DW_TAG_formal_parameter";
3476 case DW_TAG_imported_declaration:
3477 return "DW_TAG_imported_declaration";
3479 return "DW_TAG_label";
3480 case DW_TAG_lexical_block:
3481 return "DW_TAG_lexical_block";
3483 return "DW_TAG_member";
3484 case DW_TAG_pointer_type:
3485 return "DW_TAG_pointer_type";
3486 case DW_TAG_reference_type:
3487 return "DW_TAG_reference_type";
3488 case DW_TAG_compile_unit:
3489 return "DW_TAG_compile_unit";
3490 case DW_TAG_string_type:
3491 return "DW_TAG_string_type";
3492 case DW_TAG_structure_type:
3493 return "DW_TAG_structure_type";
3494 case DW_TAG_subroutine_type:
3495 return "DW_TAG_subroutine_type";
3496 case DW_TAG_typedef:
3497 return "DW_TAG_typedef";
3498 case DW_TAG_union_type:
3499 return "DW_TAG_union_type";
3500 case DW_TAG_unspecified_parameters:
3501 return "DW_TAG_unspecified_parameters";
3502 case DW_TAG_variant:
3503 return "DW_TAG_variant";
3504 case DW_TAG_common_block:
3505 return "DW_TAG_common_block";
3506 case DW_TAG_common_inclusion:
3507 return "DW_TAG_common_inclusion";
3508 case DW_TAG_inheritance:
3509 return "DW_TAG_inheritance";
3510 case DW_TAG_inlined_subroutine:
3511 return "DW_TAG_inlined_subroutine";
3513 return "DW_TAG_module";
3514 case DW_TAG_ptr_to_member_type:
3515 return "DW_TAG_ptr_to_member_type";
3516 case DW_TAG_set_type:
3517 return "DW_TAG_set_type";
3518 case DW_TAG_subrange_type:
3519 return "DW_TAG_subrange_type";
3520 case DW_TAG_with_stmt:
3521 return "DW_TAG_with_stmt";
3522 case DW_TAG_access_declaration:
3523 return "DW_TAG_access_declaration";
3524 case DW_TAG_base_type:
3525 return "DW_TAG_base_type";
3526 case DW_TAG_catch_block:
3527 return "DW_TAG_catch_block";
3528 case DW_TAG_const_type:
3529 return "DW_TAG_const_type";
3530 case DW_TAG_constant:
3531 return "DW_TAG_constant";
3532 case DW_TAG_enumerator:
3533 return "DW_TAG_enumerator";
3534 case DW_TAG_file_type:
3535 return "DW_TAG_file_type";
3537 return "DW_TAG_friend";
3538 case DW_TAG_namelist:
3539 return "DW_TAG_namelist";
3540 case DW_TAG_namelist_item:
3541 return "DW_TAG_namelist_item";
3542 case DW_TAG_packed_type:
3543 return "DW_TAG_packed_type";
3544 case DW_TAG_subprogram:
3545 return "DW_TAG_subprogram";
3546 case DW_TAG_template_type_param:
3547 return "DW_TAG_template_type_param";
3548 case DW_TAG_template_value_param:
3549 return "DW_TAG_template_value_param";
3550 case DW_TAG_thrown_type:
3551 return "DW_TAG_thrown_type";
3552 case DW_TAG_try_block:
3553 return "DW_TAG_try_block";
3554 case DW_TAG_variant_part:
3555 return "DW_TAG_variant_part";
3556 case DW_TAG_variable:
3557 return "DW_TAG_variable";
3558 case DW_TAG_volatile_type:
3559 return "DW_TAG_volatile_type";
3560 case DW_TAG_MIPS_loop:
3561 return "DW_TAG_MIPS_loop";
3562 case DW_TAG_format_label:
3563 return "DW_TAG_format_label";
3564 case DW_TAG_function_template:
3565 return "DW_TAG_function_template";
3566 case DW_TAG_class_template:
3567 return "DW_TAG_class_template";
3568 case DW_TAG_GNU_BINCL:
3569 return "DW_TAG_GNU_BINCL";
3570 case DW_TAG_GNU_EINCL:
3571 return "DW_TAG_GNU_EINCL";
3573 return "DW_TAG_<unknown>";
3577 /* Convert a DWARF attribute code into its string name. */
3580 dwarf_attr_name (attr)
3581 register unsigned attr;
3586 return "DW_AT_sibling";
3587 case DW_AT_location:
3588 return "DW_AT_location";
3590 return "DW_AT_name";
3591 case DW_AT_ordering:
3592 return "DW_AT_ordering";
3593 case DW_AT_subscr_data:
3594 return "DW_AT_subscr_data";
3595 case DW_AT_byte_size:
3596 return "DW_AT_byte_size";
3597 case DW_AT_bit_offset:
3598 return "DW_AT_bit_offset";
3599 case DW_AT_bit_size:
3600 return "DW_AT_bit_size";
3601 case DW_AT_element_list:
3602 return "DW_AT_element_list";
3603 case DW_AT_stmt_list:
3604 return "DW_AT_stmt_list";
3606 return "DW_AT_low_pc";
3608 return "DW_AT_high_pc";
3609 case DW_AT_language:
3610 return "DW_AT_language";
3612 return "DW_AT_member";
3614 return "DW_AT_discr";
3615 case DW_AT_discr_value:
3616 return "DW_AT_discr_value";
3617 case DW_AT_visibility:
3618 return "DW_AT_visibility";
3620 return "DW_AT_import";
3621 case DW_AT_string_length:
3622 return "DW_AT_string_length";
3623 case DW_AT_common_reference:
3624 return "DW_AT_common_reference";
3625 case DW_AT_comp_dir:
3626 return "DW_AT_comp_dir";
3627 case DW_AT_const_value:
3628 return "DW_AT_const_value";
3629 case DW_AT_containing_type:
3630 return "DW_AT_containing_type";
3631 case DW_AT_default_value:
3632 return "DW_AT_default_value";
3634 return "DW_AT_inline";
3635 case DW_AT_is_optional:
3636 return "DW_AT_is_optional";
3637 case DW_AT_lower_bound:
3638 return "DW_AT_lower_bound";
3639 case DW_AT_producer:
3640 return "DW_AT_producer";
3641 case DW_AT_prototyped:
3642 return "DW_AT_prototyped";
3643 case DW_AT_return_addr:
3644 return "DW_AT_return_addr";
3645 case DW_AT_start_scope:
3646 return "DW_AT_start_scope";
3647 case DW_AT_stride_size:
3648 return "DW_AT_stride_size";
3649 case DW_AT_upper_bound:
3650 return "DW_AT_upper_bound";
3651 case DW_AT_abstract_origin:
3652 return "DW_AT_abstract_origin";
3653 case DW_AT_accessibility:
3654 return "DW_AT_accessibility";
3655 case DW_AT_address_class:
3656 return "DW_AT_address_class";
3657 case DW_AT_artificial:
3658 return "DW_AT_artificial";
3659 case DW_AT_base_types:
3660 return "DW_AT_base_types";
3661 case DW_AT_calling_convention:
3662 return "DW_AT_calling_convention";
3664 return "DW_AT_count";
3665 case DW_AT_data_member_location:
3666 return "DW_AT_data_member_location";
3667 case DW_AT_decl_column:
3668 return "DW_AT_decl_column";
3669 case DW_AT_decl_file:
3670 return "DW_AT_decl_file";
3671 case DW_AT_decl_line:
3672 return "DW_AT_decl_line";
3673 case DW_AT_declaration:
3674 return "DW_AT_declaration";
3675 case DW_AT_discr_list:
3676 return "DW_AT_discr_list";
3677 case DW_AT_encoding:
3678 return "DW_AT_encoding";
3679 case DW_AT_external:
3680 return "DW_AT_external";
3681 case DW_AT_frame_base:
3682 return "DW_AT_frame_base";
3684 return "DW_AT_friend";
3685 case DW_AT_identifier_case:
3686 return "DW_AT_identifier_case";
3687 case DW_AT_macro_info:
3688 return "DW_AT_macro_info";
3689 case DW_AT_namelist_items:
3690 return "DW_AT_namelist_items";
3691 case DW_AT_priority:
3692 return "DW_AT_priority";
3694 return "DW_AT_segment";
3695 case DW_AT_specification:
3696 return "DW_AT_specification";
3697 case DW_AT_static_link:
3698 return "DW_AT_static_link";
3700 return "DW_AT_type";
3701 case DW_AT_use_location:
3702 return "DW_AT_use_location";
3703 case DW_AT_variable_parameter:
3704 return "DW_AT_variable_parameter";
3705 case DW_AT_virtuality:
3706 return "DW_AT_virtuality";
3707 case DW_AT_vtable_elem_location:
3708 return "DW_AT_vtable_elem_location";
3710 case DW_AT_MIPS_fde:
3711 return "DW_AT_MIPS_fde";
3712 case DW_AT_MIPS_loop_begin:
3713 return "DW_AT_MIPS_loop_begin";
3714 case DW_AT_MIPS_tail_loop_begin:
3715 return "DW_AT_MIPS_tail_loop_begin";
3716 case DW_AT_MIPS_epilog_begin:
3717 return "DW_AT_MIPS_epilog_begin";
3718 case DW_AT_MIPS_loop_unroll_factor:
3719 return "DW_AT_MIPS_loop_unroll_factor";
3720 case DW_AT_MIPS_software_pipeline_depth:
3721 return "DW_AT_MIPS_software_pipeline_depth";
3722 case DW_AT_MIPS_linkage_name:
3723 return "DW_AT_MIPS_linkage_name";
3724 case DW_AT_MIPS_stride:
3725 return "DW_AT_MIPS_stride";
3726 case DW_AT_MIPS_abstract_name:
3727 return "DW_AT_MIPS_abstract_name";
3728 case DW_AT_MIPS_clone_origin:
3729 return "DW_AT_MIPS_clone_origin";
3730 case DW_AT_MIPS_has_inlines:
3731 return "DW_AT_MIPS_has_inlines";
3733 case DW_AT_sf_names:
3734 return "DW_AT_sf_names";
3735 case DW_AT_src_info:
3736 return "DW_AT_src_info";
3737 case DW_AT_mac_info:
3738 return "DW_AT_mac_info";
3739 case DW_AT_src_coords:
3740 return "DW_AT_src_coords";
3741 case DW_AT_body_begin:
3742 return "DW_AT_body_begin";
3743 case DW_AT_body_end:
3744 return "DW_AT_body_end";
3746 return "DW_AT_<unknown>";
3750 /* Convert a DWARF value form code into its string name. */
3753 dwarf_form_name (form)
3754 register unsigned form;
3759 return "DW_FORM_addr";
3760 case DW_FORM_block2:
3761 return "DW_FORM_block2";
3762 case DW_FORM_block4:
3763 return "DW_FORM_block4";
3765 return "DW_FORM_data2";
3767 return "DW_FORM_data4";
3769 return "DW_FORM_data8";
3770 case DW_FORM_string:
3771 return "DW_FORM_string";
3773 return "DW_FORM_block";
3774 case DW_FORM_block1:
3775 return "DW_FORM_block1";
3777 return "DW_FORM_data1";
3779 return "DW_FORM_flag";
3781 return "DW_FORM_sdata";
3783 return "DW_FORM_strp";
3785 return "DW_FORM_udata";
3786 case DW_FORM_ref_addr:
3787 return "DW_FORM_ref_addr";
3789 return "DW_FORM_ref1";
3791 return "DW_FORM_ref2";
3793 return "DW_FORM_ref4";
3795 return "DW_FORM_ref8";
3796 case DW_FORM_ref_udata:
3797 return "DW_FORM_ref_udata";
3798 case DW_FORM_indirect:
3799 return "DW_FORM_indirect";
3801 return "DW_FORM_<unknown>";
3805 /* Convert a DWARF type code into its string name. */
3809 dwarf_type_encoding_name (enc)
3810 register unsigned enc;
3814 case DW_ATE_address:
3815 return "DW_ATE_address";
3816 case DW_ATE_boolean:
3817 return "DW_ATE_boolean";
3818 case DW_ATE_complex_float:
3819 return "DW_ATE_complex_float";
3821 return "DW_ATE_float";
3823 return "DW_ATE_signed";
3824 case DW_ATE_signed_char:
3825 return "DW_ATE_signed_char";
3826 case DW_ATE_unsigned:
3827 return "DW_ATE_unsigned";
3828 case DW_ATE_unsigned_char:
3829 return "DW_ATE_unsigned_char";
3831 return "DW_ATE_<unknown>";
3836 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3837 instance of an inlined instance of a decl which is local to an inline
3838 function, so we have to trace all of the way back through the origin chain
3839 to find out what sort of node actually served as the original seed for the
3843 decl_ultimate_origin (decl)
3846 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3847 nodes in the function to point to themselves; ignore that if
3848 we're trying to output the abstract instance of this function. */
3849 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3852 #ifdef ENABLE_CHECKING
3853 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3854 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3855 most distant ancestor, this should never happen. */
3859 return DECL_ABSTRACT_ORIGIN (decl);
3862 /* Determine the "ultimate origin" of a block. The block may be an inlined
3863 instance of an inlined instance of a block which is local to an inline
3864 function, so we have to trace all of the way back through the origin chain
3865 to find out what sort of node actually served as the original seed for the
3869 block_ultimate_origin (block)
3870 register tree block;
3872 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3874 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3875 nodes in the function to point to themselves; ignore that if
3876 we're trying to output the abstract instance of this function. */
3877 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3880 if (immediate_origin == NULL_TREE)
3884 register tree ret_val;
3885 register tree lookahead = immediate_origin;
3889 ret_val = lookahead;
3890 lookahead = (TREE_CODE (ret_val) == BLOCK)
3891 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3894 while (lookahead != NULL && lookahead != ret_val);
3900 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3901 of a virtual function may refer to a base class, so we check the 'this'
3905 decl_class_context (decl)
3908 tree context = NULL_TREE;
3910 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3911 context = DECL_CONTEXT (decl);
3913 context = TYPE_MAIN_VARIANT
3914 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3916 if (context && !TYPE_P (context))
3917 context = NULL_TREE;
3922 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3923 addition order, and correct that in reverse_all_dies. */
3926 add_dwarf_attr (die, attr)
3927 register dw_die_ref die;
3928 register dw_attr_ref attr;
3930 if (die != NULL && attr != NULL)
3932 attr->dw_attr_next = die->die_attr;
3933 die->die_attr = attr;
3937 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3938 static inline dw_val_class
3942 return a->dw_attr_val.val_class;
3945 /* Add a flag value attribute to a DIE. */
3948 add_AT_flag (die, attr_kind, flag)
3949 register dw_die_ref die;
3950 register enum dwarf_attribute attr_kind;
3951 register unsigned flag;
3953 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3955 attr->dw_attr_next = NULL;
3956 attr->dw_attr = attr_kind;
3957 attr->dw_attr_val.val_class = dw_val_class_flag;
3958 attr->dw_attr_val.v.val_flag = flag;
3959 add_dwarf_attr (die, attr);
3962 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3963 static inline unsigned
3965 register dw_attr_ref a;
3967 if (a && AT_class (a) == dw_val_class_flag)
3968 return a->dw_attr_val.v.val_flag;
3973 /* Add a signed integer attribute value to a DIE. */
3976 add_AT_int (die, attr_kind, int_val)
3977 register dw_die_ref die;
3978 register enum dwarf_attribute attr_kind;
3979 register long int int_val;
3981 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3983 attr->dw_attr_next = NULL;
3984 attr->dw_attr = attr_kind;
3985 attr->dw_attr_val.val_class = dw_val_class_const;
3986 attr->dw_attr_val.v.val_int = int_val;
3987 add_dwarf_attr (die, attr);
3990 static inline long int AT_int PARAMS ((dw_attr_ref));
3991 static inline long int
3993 register dw_attr_ref a;
3995 if (a && AT_class (a) == dw_val_class_const)
3996 return a->dw_attr_val.v.val_int;
4001 /* Add an unsigned integer attribute value to a DIE. */
4004 add_AT_unsigned (die, attr_kind, unsigned_val)
4005 register dw_die_ref die;
4006 register enum dwarf_attribute attr_kind;
4007 register unsigned long unsigned_val;
4009 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4011 attr->dw_attr_next = NULL;
4012 attr->dw_attr = attr_kind;
4013 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4014 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4015 add_dwarf_attr (die, attr);
4018 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4019 static inline unsigned long
4021 register dw_attr_ref a;
4023 if (a && AT_class (a) == dw_val_class_unsigned_const)
4024 return a->dw_attr_val.v.val_unsigned;
4029 /* Add an unsigned double integer attribute value to a DIE. */
4032 add_AT_long_long (die, attr_kind, val_hi, val_low)
4033 register dw_die_ref die;
4034 register enum dwarf_attribute attr_kind;
4035 register unsigned long val_hi;
4036 register unsigned long val_low;
4038 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4040 attr->dw_attr_next = NULL;
4041 attr->dw_attr = attr_kind;
4042 attr->dw_attr_val.val_class = dw_val_class_long_long;
4043 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4044 attr->dw_attr_val.v.val_long_long.low = val_low;
4045 add_dwarf_attr (die, attr);
4048 /* Add a floating point attribute value to a DIE and return it. */
4051 add_AT_float (die, attr_kind, length, array)
4052 register dw_die_ref die;
4053 register enum dwarf_attribute attr_kind;
4054 register unsigned length;
4055 register long *array;
4057 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4059 attr->dw_attr_next = NULL;
4060 attr->dw_attr = attr_kind;
4061 attr->dw_attr_val.val_class = dw_val_class_float;
4062 attr->dw_attr_val.v.val_float.length = length;
4063 attr->dw_attr_val.v.val_float.array = array;
4064 add_dwarf_attr (die, attr);
4067 /* Add a string attribute value to a DIE. */
4070 add_AT_string (die, attr_kind, str)
4071 register dw_die_ref die;
4072 register enum dwarf_attribute attr_kind;
4073 register const char *str;
4075 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4077 attr->dw_attr_next = NULL;
4078 attr->dw_attr = attr_kind;
4079 attr->dw_attr_val.val_class = dw_val_class_str;
4080 attr->dw_attr_val.v.val_str = xstrdup (str);
4081 add_dwarf_attr (die, attr);
4084 static inline const char *AT_string PARAMS ((dw_attr_ref));
4085 static inline const char *
4087 register dw_attr_ref a;
4089 if (a && AT_class (a) == dw_val_class_str)
4090 return a->dw_attr_val.v.val_str;
4095 /* Add a DIE reference attribute value to a DIE. */
4098 add_AT_die_ref (die, attr_kind, targ_die)
4099 register dw_die_ref die;
4100 register enum dwarf_attribute attr_kind;
4101 register dw_die_ref targ_die;
4103 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4105 attr->dw_attr_next = NULL;
4106 attr->dw_attr = attr_kind;
4107 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4108 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4109 attr->dw_attr_val.v.val_die_ref.external = 0;
4110 add_dwarf_attr (die, attr);
4113 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4114 static inline dw_die_ref
4116 register dw_attr_ref a;
4118 if (a && AT_class (a) == dw_val_class_die_ref)
4119 return a->dw_attr_val.v.val_die_ref.die;
4124 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4127 register dw_attr_ref a;
4129 if (a && AT_class (a) == dw_val_class_die_ref)
4130 return a->dw_attr_val.v.val_die_ref.external;
4135 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4137 set_AT_ref_external (a, i)
4138 register dw_attr_ref a;
4141 if (a && AT_class (a) == dw_val_class_die_ref)
4142 a->dw_attr_val.v.val_die_ref.external = i;
4147 /* Add an FDE reference attribute value to a DIE. */
4150 add_AT_fde_ref (die, attr_kind, targ_fde)
4151 register dw_die_ref die;
4152 register enum dwarf_attribute attr_kind;
4153 register unsigned targ_fde;
4155 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4157 attr->dw_attr_next = NULL;
4158 attr->dw_attr = attr_kind;
4159 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4160 attr->dw_attr_val.v.val_fde_index = targ_fde;
4161 add_dwarf_attr (die, attr);
4164 /* Add a location description attribute value to a DIE. */
4167 add_AT_loc (die, attr_kind, loc)
4168 register dw_die_ref die;
4169 register enum dwarf_attribute attr_kind;
4170 register dw_loc_descr_ref loc;
4172 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4174 attr->dw_attr_next = NULL;
4175 attr->dw_attr = attr_kind;
4176 attr->dw_attr_val.val_class = dw_val_class_loc;
4177 attr->dw_attr_val.v.val_loc = loc;
4178 add_dwarf_attr (die, attr);
4181 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4182 static inline dw_loc_descr_ref
4184 register dw_attr_ref a;
4186 if (a && AT_class (a) == dw_val_class_loc)
4187 return a->dw_attr_val.v.val_loc;
4192 /* Add an address constant attribute value to a DIE. */
4195 add_AT_addr (die, attr_kind, addr)
4196 register dw_die_ref die;
4197 register enum dwarf_attribute attr_kind;
4200 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4202 attr->dw_attr_next = NULL;
4203 attr->dw_attr = attr_kind;
4204 attr->dw_attr_val.val_class = dw_val_class_addr;
4205 attr->dw_attr_val.v.val_addr = addr;
4206 add_dwarf_attr (die, attr);
4209 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4212 register dw_attr_ref a;
4214 if (a && AT_class (a) == dw_val_class_addr)
4215 return a->dw_attr_val.v.val_addr;
4220 /* Add a label identifier attribute value to a DIE. */
4223 add_AT_lbl_id (die, attr_kind, lbl_id)
4224 register dw_die_ref die;
4225 register enum dwarf_attribute attr_kind;
4226 register const char *lbl_id;
4228 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4230 attr->dw_attr_next = NULL;
4231 attr->dw_attr = attr_kind;
4232 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4233 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4234 add_dwarf_attr (die, attr);
4237 /* Add a section offset attribute value to a DIE. */
4240 add_AT_lbl_offset (die, attr_kind, label)
4241 register dw_die_ref die;
4242 register enum dwarf_attribute attr_kind;
4243 register const char *label;
4245 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4247 attr->dw_attr_next = NULL;
4248 attr->dw_attr = attr_kind;
4249 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4250 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4251 add_dwarf_attr (die, attr);
4254 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4255 static inline const char *
4257 register dw_attr_ref a;
4259 if (a && (AT_class (a) == dw_val_class_lbl_id
4260 || AT_class (a) == dw_val_class_lbl_offset))
4261 return a->dw_attr_val.v.val_lbl_id;
4266 /* Get the attribute of type attr_kind. */
4268 static inline dw_attr_ref
4269 get_AT (die, attr_kind)
4270 register dw_die_ref die;
4271 register enum dwarf_attribute attr_kind;
4273 register dw_attr_ref a;
4274 register dw_die_ref spec = NULL;
4278 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4280 if (a->dw_attr == attr_kind)
4283 if (a->dw_attr == DW_AT_specification
4284 || a->dw_attr == DW_AT_abstract_origin)
4289 return get_AT (spec, attr_kind);
4295 /* Return the "low pc" attribute value, typically associated with
4296 a subprogram DIE. Return null if the "low pc" attribute is
4297 either not prsent, or if it cannot be represented as an
4298 assembler label identifier. */
4300 static inline const char *
4302 register dw_die_ref die;
4304 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4305 return a ? AT_lbl (a) : NULL;
4308 /* Return the "high pc" attribute value, typically associated with
4309 a subprogram DIE. Return null if the "high pc" attribute is
4310 either not prsent, or if it cannot be represented as an
4311 assembler label identifier. */
4313 static inline const char *
4315 register dw_die_ref die;
4317 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4318 return a ? AT_lbl (a) : NULL;
4321 /* Return the value of the string attribute designated by ATTR_KIND, or
4322 NULL if it is not present. */
4324 static inline const char *
4325 get_AT_string (die, attr_kind)
4326 register dw_die_ref die;
4327 register enum dwarf_attribute attr_kind;
4329 register dw_attr_ref a = get_AT (die, attr_kind);
4330 return a ? AT_string (a) : NULL;
4333 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4334 if it is not present. */
4337 get_AT_flag (die, attr_kind)
4338 register dw_die_ref die;
4339 register enum dwarf_attribute attr_kind;
4341 register dw_attr_ref a = get_AT (die, attr_kind);
4342 return a ? AT_flag (a) : 0;
4345 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4346 if it is not present. */
4348 static inline unsigned
4349 get_AT_unsigned (die, attr_kind)
4350 register dw_die_ref die;
4351 register enum dwarf_attribute attr_kind;
4353 register dw_attr_ref a = get_AT (die, attr_kind);
4354 return a ? AT_unsigned (a) : 0;
4357 static inline dw_die_ref
4358 get_AT_ref (die, attr_kind)
4360 register enum dwarf_attribute attr_kind;
4362 register dw_attr_ref a = get_AT (die, attr_kind);
4363 return a ? AT_ref (a) : NULL;
4369 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4371 return (lang == DW_LANG_C || lang == DW_LANG_C89
4372 || lang == DW_LANG_C_plus_plus);
4378 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4380 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4386 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4388 return (lang == DW_LANG_Java);
4391 /* Free up the memory used by A. */
4393 static inline void free_AT PARAMS ((dw_attr_ref));
4398 switch (AT_class (a))
4400 case dw_val_class_str:
4401 case dw_val_class_lbl_id:
4402 case dw_val_class_lbl_offset:
4403 free (a->dw_attr_val.v.val_str);
4406 case dw_val_class_float:
4407 free (a->dw_attr_val.v.val_float.array);
4417 /* Remove the specified attribute if present. */
4420 remove_AT (die, attr_kind)
4421 register dw_die_ref die;
4422 register enum dwarf_attribute attr_kind;
4424 register dw_attr_ref *p;
4425 register dw_attr_ref removed = NULL;
4429 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4430 if ((*p)->dw_attr == attr_kind)
4433 *p = (*p)->dw_attr_next;
4442 /* Free up the memory used by DIE. */
4444 static inline void free_die PARAMS ((dw_die_ref));
4449 remove_children (die);
4453 /* Discard the children of this DIE. */
4456 remove_children (die)
4457 register dw_die_ref die;
4459 register dw_die_ref child_die = die->die_child;
4461 die->die_child = NULL;
4463 while (child_die != NULL)
4465 register dw_die_ref tmp_die = child_die;
4466 register dw_attr_ref a;
4468 child_die = child_die->die_sib;
4470 for (a = tmp_die->die_attr; a != NULL;)
4472 register dw_attr_ref tmp_a = a;
4474 a = a->dw_attr_next;
4482 /* Add a child DIE below its parent. We build the lists up in reverse
4483 addition order, and correct that in reverse_all_dies. */
4486 add_child_die (die, child_die)
4487 register dw_die_ref die;
4488 register dw_die_ref child_die;
4490 if (die != NULL && child_die != NULL)
4492 if (die == child_die)
4494 child_die->die_parent = die;
4495 child_die->die_sib = die->die_child;
4496 die->die_child = child_die;
4500 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4501 is the specification, to the front of PARENT's list of children. */
4504 splice_child_die (parent, child)
4505 dw_die_ref parent, child;
4509 /* We want the declaration DIE from inside the class, not the
4510 specification DIE at toplevel. */
4511 if (child->die_parent != parent)
4513 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4518 if (child->die_parent != parent
4519 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4522 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4525 *p = child->die_sib;
4529 child->die_sib = parent->die_child;
4530 parent->die_child = child;
4533 /* Return a pointer to a newly created DIE node. */
4535 static inline dw_die_ref
4536 new_die (tag_value, parent_die)
4537 register enum dwarf_tag tag_value;
4538 register dw_die_ref parent_die;
4540 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4542 die->die_tag = tag_value;
4544 if (parent_die != NULL)
4545 add_child_die (parent_die, die);
4548 limbo_die_node *limbo_node;
4550 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4551 limbo_node->die = die;
4552 limbo_node->next = limbo_die_list;
4553 limbo_die_list = limbo_node;
4559 /* Return the DIE associated with the given type specifier. */
4561 static inline dw_die_ref
4562 lookup_type_die (type)
4565 if (TREE_CODE (type) == VECTOR_TYPE)
4566 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4567 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4570 /* Equate a DIE to a given type specifier. */
4573 equate_type_number_to_die (type, type_die)
4575 register dw_die_ref type_die;
4577 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4580 /* Return the DIE associated with a given declaration. */
4582 static inline dw_die_ref
4583 lookup_decl_die (decl)
4586 register unsigned decl_id = DECL_UID (decl);
4588 return (decl_id < decl_die_table_in_use
4589 ? decl_die_table[decl_id] : NULL);
4592 /* Equate a DIE to a particular declaration. */
4595 equate_decl_number_to_die (decl, decl_die)
4597 register dw_die_ref decl_die;
4599 register unsigned decl_id = DECL_UID (decl);
4600 register unsigned num_allocated;
4602 if (decl_id >= decl_die_table_allocated)
4605 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4606 / DECL_DIE_TABLE_INCREMENT)
4607 * DECL_DIE_TABLE_INCREMENT;
4610 = (dw_die_ref *) xrealloc (decl_die_table,
4611 sizeof (dw_die_ref) * num_allocated);
4613 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4614 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4615 decl_die_table_allocated = num_allocated;
4618 if (decl_id >= decl_die_table_in_use)
4619 decl_die_table_in_use = (decl_id + 1);
4621 decl_die_table[decl_id] = decl_die;
4624 /* Keep track of the number of spaces used to indent the
4625 output of the debugging routines that print the structure of
4626 the DIE internal representation. */
4627 static int print_indent;
4629 /* Indent the line the number of spaces given by print_indent. */
4632 print_spaces (outfile)
4635 fprintf (outfile, "%*s", print_indent, "");
4638 /* Print the information associated with a given DIE, and its children.
4639 This routine is a debugging aid only. */
4642 print_die (die, outfile)
4646 register dw_attr_ref a;
4647 register dw_die_ref c;
4649 print_spaces (outfile);
4650 fprintf (outfile, "DIE %4lu: %s\n",
4651 die->die_offset, dwarf_tag_name (die->die_tag));
4652 print_spaces (outfile);
4653 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4654 fprintf (outfile, " offset: %lu\n", die->die_offset);
4656 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4658 print_spaces (outfile);
4659 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4661 switch (AT_class (a))
4663 case dw_val_class_addr:
4664 fprintf (outfile, "address");
4666 case dw_val_class_loc:
4667 fprintf (outfile, "location descriptor");
4669 case dw_val_class_const:
4670 fprintf (outfile, "%ld", AT_int (a));
4672 case dw_val_class_unsigned_const:
4673 fprintf (outfile, "%lu", AT_unsigned (a));
4675 case dw_val_class_long_long:
4676 fprintf (outfile, "constant (%lu,%lu)",
4677 a->dw_attr_val.v.val_long_long.hi,
4678 a->dw_attr_val.v.val_long_long.low);
4680 case dw_val_class_float:
4681 fprintf (outfile, "floating-point constant");
4683 case dw_val_class_flag:
4684 fprintf (outfile, "%u", AT_flag (a));
4686 case dw_val_class_die_ref:
4687 if (AT_ref (a) != NULL)
4689 if (AT_ref (a)->die_symbol)
4690 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4692 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4695 fprintf (outfile, "die -> <null>");
4697 case dw_val_class_lbl_id:
4698 case dw_val_class_lbl_offset:
4699 fprintf (outfile, "label: %s", AT_lbl (a));
4701 case dw_val_class_str:
4702 if (AT_string (a) != NULL)
4703 fprintf (outfile, "\"%s\"", AT_string (a));
4705 fprintf (outfile, "<null>");
4711 fprintf (outfile, "\n");
4714 if (die->die_child != NULL)
4717 for (c = die->die_child; c != NULL; c = c->die_sib)
4718 print_die (c, outfile);
4722 if (print_indent == 0)
4723 fprintf (outfile, "\n");
4726 /* Print the contents of the source code line number correspondence table.
4727 This routine is a debugging aid only. */
4730 print_dwarf_line_table (outfile)
4733 register unsigned i;
4734 register dw_line_info_ref line_info;
4736 fprintf (outfile, "\n\nDWARF source line information\n");
4737 for (i = 1; i < line_info_table_in_use; ++i)
4739 line_info = &line_info_table[i];
4740 fprintf (outfile, "%5d: ", i);
4741 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
4742 fprintf (outfile, "%6ld", line_info->dw_line_num);
4743 fprintf (outfile, "\n");
4746 fprintf (outfile, "\n\n");
4749 /* Print the information collected for a given DIE. */
4752 debug_dwarf_die (die)
4755 print_die (die, stderr);
4758 /* Print all DWARF information collected for the compilation unit.
4759 This routine is a debugging aid only. */
4765 print_die (comp_unit_die, stderr);
4766 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4767 print_dwarf_line_table (stderr);
4770 /* We build up the lists of children and attributes by pushing new ones
4771 onto the beginning of the list. Reverse the lists for DIE so that
4772 they are in order of addition. */
4775 reverse_die_lists (die)
4776 register dw_die_ref die;
4778 register dw_die_ref c, cp, cn;
4779 register dw_attr_ref a, ap, an;
4781 for (a = die->die_attr, ap = 0; a; a = an)
4783 an = a->dw_attr_next;
4784 a->dw_attr_next = ap;
4789 for (c = die->die_child, cp = 0; c; c = cn)
4795 die->die_child = cp;
4798 /* reverse_die_lists only reverses the single die you pass it. Since
4799 we used to reverse all dies in add_sibling_attributes, which runs
4800 through all the dies, it would reverse all the dies. Now, however,
4801 since we don't call reverse_die_lists in add_sibling_attributes, we
4802 need a routine to recursively reverse all the dies. This is that
4806 reverse_all_dies (die)
4807 register dw_die_ref die;
4809 register dw_die_ref c;
4811 reverse_die_lists (die);
4813 for (c = die->die_child; c; c = c->die_sib)
4814 reverse_all_dies (c);
4817 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
4818 the CU for the enclosing include file, if any. BINCL_DIE is the
4819 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
4823 push_new_compile_unit (old_unit, bincl_die)
4824 dw_die_ref old_unit, bincl_die;
4826 const char *filename = get_AT_string (bincl_die, DW_AT_name);
4827 dw_die_ref new_unit = gen_compile_unit_die (filename);
4828 new_unit->die_sib = old_unit;
4832 /* Close an include-file CU and reopen the enclosing one. */
4835 pop_compile_unit (old_unit)
4836 dw_die_ref old_unit;
4838 dw_die_ref new_unit = old_unit->die_sib;
4839 old_unit->die_sib = NULL;
4843 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4844 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4846 /* Calculate the checksum of a location expression. */
4849 loc_checksum (loc, ctx)
4850 dw_loc_descr_ref loc;
4851 struct md5_ctx *ctx;
4853 PROCESS (loc->dw_loc_opc);
4854 PROCESS (loc->dw_loc_oprnd1);
4855 PROCESS (loc->dw_loc_oprnd2);
4858 /* Calculate the checksum of an attribute. */
4861 attr_checksum (at, ctx)
4863 struct md5_ctx *ctx;
4865 dw_loc_descr_ref loc;
4868 PROCESS (at->dw_attr);
4870 /* We don't care about differences in file numbering. */
4871 if (at->dw_attr == DW_AT_decl_file
4872 /* Or that this was compiled with a different compiler snapshot; if
4873 the output is the same, that's what matters. */
4874 || at->dw_attr == DW_AT_producer)
4877 switch (AT_class (at))
4879 case dw_val_class_const:
4880 PROCESS (at->dw_attr_val.v.val_int);
4882 case dw_val_class_unsigned_const:
4883 PROCESS (at->dw_attr_val.v.val_unsigned);
4885 case dw_val_class_long_long:
4886 PROCESS (at->dw_attr_val.v.val_long_long);
4888 case dw_val_class_float:
4889 PROCESS (at->dw_attr_val.v.val_float);
4891 case dw_val_class_flag:
4892 PROCESS (at->dw_attr_val.v.val_flag);
4895 case dw_val_class_str:
4896 PROCESS_STRING (AT_string (at));
4898 case dw_val_class_addr:
4900 switch (GET_CODE (r))
4903 PROCESS_STRING (XSTR (r, 0));
4911 case dw_val_class_loc:
4912 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
4913 loc_checksum (loc, ctx);
4916 case dw_val_class_die_ref:
4917 if (AT_ref (at)->die_offset)
4918 PROCESS (AT_ref (at)->die_offset);
4919 /* FIXME else use target die name or something. */
4921 case dw_val_class_fde_ref:
4922 case dw_val_class_lbl_id:
4923 case dw_val_class_lbl_offset:
4930 /* Calculate the checksum of a DIE. */
4933 die_checksum (die, ctx)
4935 struct md5_ctx *ctx;
4940 PROCESS (die->die_tag);
4942 for (a = die->die_attr; a; a = a->dw_attr_next)
4943 attr_checksum (a, ctx);
4945 for (c = die->die_child; c; c = c->die_sib)
4946 die_checksum (c, ctx);
4950 #undef PROCESS_STRING
4952 /* The prefix to attach to symbols on DIEs in the current comdat debug
4954 static char *comdat_symbol_id;
4956 /* The index of the current symbol within the current comdat CU. */
4957 static unsigned int comdat_symbol_number;
4959 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
4960 children, and set comdat_symbol_id accordingly. */
4963 compute_section_prefix (unit_die)
4964 dw_die_ref unit_die;
4968 unsigned char checksum[16];
4971 md5_init_ctx (&ctx);
4972 die_checksum (unit_die, &ctx);
4973 md5_finish_ctx (&ctx, checksum);
4975 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
4976 name = (char *) alloca (strlen (p) + 64);
4977 sprintf (name, "%s.", p);
4979 clean_symbol_name (name);
4981 p = name + strlen (name);
4982 for (i = 0; i < 4; ++i)
4984 sprintf (p, "%.2x", checksum[i]);
4988 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
4989 comdat_symbol_number = 0;
4992 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
4998 switch (die->die_tag)
5000 case DW_TAG_array_type:
5001 case DW_TAG_class_type:
5002 case DW_TAG_enumeration_type:
5003 case DW_TAG_pointer_type:
5004 case DW_TAG_reference_type:
5005 case DW_TAG_string_type:
5006 case DW_TAG_structure_type:
5007 case DW_TAG_subroutine_type:
5008 case DW_TAG_union_type:
5009 case DW_TAG_ptr_to_member_type:
5010 case DW_TAG_set_type:
5011 case DW_TAG_subrange_type:
5012 case DW_TAG_base_type:
5013 case DW_TAG_const_type:
5014 case DW_TAG_file_type:
5015 case DW_TAG_packed_type:
5016 case DW_TAG_volatile_type:
5023 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5024 Basically, we want to choose the bits that are likely to be shared between
5025 compilations (types) and leave out the bits that are specific to individual
5026 compilations (functions). */
5033 /* I think we want to leave base types and __vtbl_ptr_type in the
5034 main CU, as we do for stabs. The advantage is a greater
5035 likelihood of sharing between objects that don't include headers
5036 in the same order (and therefore would put the base types in a
5037 different comdat). jason 8/28/00 */
5038 if (c->die_tag == DW_TAG_base_type)
5041 if (c->die_tag == DW_TAG_pointer_type
5042 || c->die_tag == DW_TAG_reference_type
5043 || c->die_tag == DW_TAG_const_type
5044 || c->die_tag == DW_TAG_volatile_type)
5046 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5047 return t ? is_comdat_die (t) : 0;
5051 return is_type_die (c);
5054 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5055 compilation unit. */
5061 if (is_type_die (c))
5063 if (get_AT (c, DW_AT_declaration)
5064 && ! get_AT (c, DW_AT_specification))
5073 static int label_num;
5074 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5075 return xstrdup (buf);
5078 /* Assign symbols to all worthy DIEs under DIE. */
5081 assign_symbol_names (die)
5082 register dw_die_ref die;
5084 register dw_die_ref c;
5086 if (is_symbol_die (die))
5088 if (comdat_symbol_id)
5090 char *p = alloca (strlen (comdat_symbol_id) + 64);
5091 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5092 comdat_symbol_id, comdat_symbol_number++);
5093 die->die_symbol = xstrdup (p);
5096 die->die_symbol = gen_internal_sym ();
5099 for (c = die->die_child; c != NULL; c = c->die_sib)
5100 assign_symbol_names (c);
5103 /* Traverse the DIE (which is always comp_unit_die), and set up
5104 additional compilation units for each of the include files we see
5105 bracketed by BINCL/EINCL. */
5108 break_out_includes (die)
5109 register dw_die_ref die;
5112 register dw_die_ref unit = NULL;
5113 limbo_die_node *node;
5115 for (ptr = &(die->die_child); *ptr; )
5117 register dw_die_ref c = *ptr;
5119 if (c->die_tag == DW_TAG_GNU_BINCL
5120 || c->die_tag == DW_TAG_GNU_EINCL
5121 || (unit && is_comdat_die (c)))
5123 /* This DIE is for a secondary CU; remove it from the main one. */
5126 if (c->die_tag == DW_TAG_GNU_BINCL)
5128 unit = push_new_compile_unit (unit, c);
5131 else if (c->die_tag == DW_TAG_GNU_EINCL)
5133 unit = pop_compile_unit (unit);
5137 add_child_die (unit, c);
5141 /* Leave this DIE in the main CU. */
5142 ptr = &(c->die_sib);
5148 /* We can only use this in debugging, since the frontend doesn't check
5149 to make sure that we leave every include file we enter. */
5154 assign_symbol_names (die);
5155 for (node = limbo_die_list; node; node = node->next)
5157 compute_section_prefix (node->die);
5158 assign_symbol_names (node->die);
5162 /* Traverse the DIE and add a sibling attribute if it may have the
5163 effect of speeding up access to siblings. To save some space,
5164 avoid generating sibling attributes for DIE's without children. */
5167 add_sibling_attributes (die)
5168 register dw_die_ref die;
5170 register dw_die_ref c;
5172 if (die->die_tag != DW_TAG_compile_unit
5173 && die->die_sib && die->die_child != NULL)
5174 /* Add the sibling link to the front of the attribute list. */
5175 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5177 for (c = die->die_child; c != NULL; c = c->die_sib)
5178 add_sibling_attributes (c);
5181 /* The format of each DIE (and its attribute value pairs)
5182 is encoded in an abbreviation table. This routine builds the
5183 abbreviation table and assigns a unique abbreviation id for
5184 each abbreviation entry. The children of each die are visited
5188 build_abbrev_table (die)
5189 register dw_die_ref die;
5191 register unsigned long abbrev_id;
5192 register unsigned long n_alloc;
5193 register dw_die_ref c;
5194 register dw_attr_ref d_attr, a_attr;
5196 /* Scan the DIE references, and mark as external any that refer to
5197 DIEs from other CUs (i.e. those which are not marked). */
5198 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5200 if (AT_class (d_attr) == dw_val_class_die_ref
5201 && AT_ref (d_attr)->die_mark == 0)
5203 if (AT_ref (d_attr)->die_symbol == 0)
5205 set_AT_ref_external (d_attr, 1);
5209 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5211 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5213 if (abbrev->die_tag == die->die_tag)
5215 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5217 a_attr = abbrev->die_attr;
5218 d_attr = die->die_attr;
5220 while (a_attr != NULL && d_attr != NULL)
5222 if ((a_attr->dw_attr != d_attr->dw_attr)
5223 || (value_format (a_attr) != value_format (d_attr)))
5226 a_attr = a_attr->dw_attr_next;
5227 d_attr = d_attr->dw_attr_next;
5230 if (a_attr == NULL && d_attr == NULL)
5236 if (abbrev_id >= abbrev_die_table_in_use)
5238 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5240 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5242 = (dw_die_ref *) xrealloc (abbrev_die_table,
5243 sizeof (dw_die_ref) * n_alloc);
5245 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5246 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5247 abbrev_die_table_allocated = n_alloc;
5250 ++abbrev_die_table_in_use;
5251 abbrev_die_table[abbrev_id] = die;
5254 die->die_abbrev = abbrev_id;
5255 for (c = die->die_child; c != NULL; c = c->die_sib)
5256 build_abbrev_table (c);
5259 /* Return the size of a string, including the null byte.
5261 This used to treat backslashes as escapes, and hence they were not included
5262 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5263 which treats a backslash as a backslash, escaping it if necessary, and hence
5264 we must include them in the count. */
5266 static unsigned long
5267 size_of_string (str)
5268 register const char *str;
5270 return strlen (str) + 1;
5273 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5276 constant_size (value)
5277 long unsigned value;
5284 log = floor_log2 (value);
5287 log = 1 << (floor_log2 (log) + 1);
5292 /* Return the size of a DIE, as it is represented in the
5293 .debug_info section. */
5295 static unsigned long
5297 register dw_die_ref die;
5299 register unsigned long size = 0;
5300 register dw_attr_ref a;
5302 size += size_of_uleb128 (die->die_abbrev);
5303 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5305 switch (AT_class (a))
5307 case dw_val_class_addr:
5308 size += DWARF2_ADDR_SIZE;
5310 case dw_val_class_loc:
5312 register unsigned long lsize = size_of_locs (AT_loc (a));
5315 size += constant_size (lsize);
5319 case dw_val_class_const:
5320 size += size_of_sleb128 (AT_int (a));
5322 case dw_val_class_unsigned_const:
5323 size += constant_size (AT_unsigned (a));
5325 case dw_val_class_long_long:
5326 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5328 case dw_val_class_float:
5329 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5331 case dw_val_class_flag:
5334 case dw_val_class_die_ref:
5335 size += DWARF_OFFSET_SIZE;
5337 case dw_val_class_fde_ref:
5338 size += DWARF_OFFSET_SIZE;
5340 case dw_val_class_lbl_id:
5341 size += DWARF2_ADDR_SIZE;
5343 case dw_val_class_lbl_offset:
5344 size += DWARF_OFFSET_SIZE;
5346 case dw_val_class_str:
5347 size += size_of_string (AT_string (a));
5357 /* Size the debugging information associated with a given DIE.
5358 Visits the DIE's children recursively. Updates the global
5359 variable next_die_offset, on each time through. Uses the
5360 current value of next_die_offset to update the die_offset
5361 field in each DIE. */
5364 calc_die_sizes (die)
5367 register dw_die_ref c;
5368 die->die_offset = next_die_offset;
5369 next_die_offset += size_of_die (die);
5371 for (c = die->die_child; c != NULL; c = c->die_sib)
5374 if (die->die_child != NULL)
5375 /* Count the null byte used to terminate sibling lists. */
5376 next_die_offset += 1;
5379 /* Set the marks for a die and its children. We do this so
5380 that we know whether or not a reference needs to use FORM_ref_addr; only
5381 DIEs in the same CU will be marked. We used to clear out the offset
5382 and use that as the flag, but ran into ordering problems. */
5388 register dw_die_ref c;
5390 for (c = die->die_child; c; c = c->die_sib)
5394 /* Clear the marks for a die and its children. */
5400 register dw_die_ref c;
5402 for (c = die->die_child; c; c = c->die_sib)
5406 /* Return the size of the line information prolog generated for the
5407 compilation unit. */
5409 static unsigned long
5410 size_of_line_prolog ()
5412 register unsigned long size;
5413 register unsigned long ft_index;
5415 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5417 /* Count the size of the table giving number of args for each
5419 size += DWARF_LINE_OPCODE_BASE - 1;
5421 /* Include directory table is empty (at present). Count only the
5422 null byte used to terminate the table. */
5425 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5427 /* File name entry. */
5428 size += size_of_string (decl_file_table.table[ft_index]);
5430 /* Include directory index. */
5431 size += size_of_uleb128 (0);
5433 /* Modification time. */
5434 size += size_of_uleb128 (0);
5436 /* File length in bytes. */
5437 size += size_of_uleb128 (0);
5440 /* Count the file table terminator. */
5445 /* Return the size of the .debug_pubnames table generated for the
5446 compilation unit. */
5448 static unsigned long
5451 register unsigned long size;
5452 register unsigned i;
5454 size = DWARF_PUBNAMES_HEADER_SIZE;
5455 for (i = 0; i < pubname_table_in_use; ++i)
5457 register pubname_ref p = &pubname_table[i];
5458 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5461 size += DWARF_OFFSET_SIZE;
5465 /* Return the size of the information in the .debug_aranges section. */
5467 static unsigned long
5470 register unsigned long size;
5472 size = DWARF_ARANGES_HEADER_SIZE;
5474 /* Count the address/length pair for this compilation unit. */
5475 size += 2 * DWARF2_ADDR_SIZE;
5476 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5478 /* Count the two zero words used to terminated the address range table. */
5479 size += 2 * DWARF2_ADDR_SIZE;
5483 /* Select the encoding of an attribute value. */
5485 static enum dwarf_form
5489 switch (a->dw_attr_val.val_class)
5491 case dw_val_class_addr:
5492 return DW_FORM_addr;
5493 case dw_val_class_loc:
5494 switch (constant_size (size_of_locs (AT_loc (a))))
5497 return DW_FORM_block1;
5499 return DW_FORM_block2;
5503 case dw_val_class_const:
5504 return DW_FORM_sdata;
5505 case dw_val_class_unsigned_const:
5506 switch (constant_size (AT_unsigned (a)))
5509 return DW_FORM_data1;
5511 return DW_FORM_data2;
5513 return DW_FORM_data4;
5515 return DW_FORM_data8;
5519 case dw_val_class_long_long:
5520 return DW_FORM_block1;
5521 case dw_val_class_float:
5522 return DW_FORM_block1;
5523 case dw_val_class_flag:
5524 return DW_FORM_flag;
5525 case dw_val_class_die_ref:
5526 if (AT_ref_external (a))
5527 return DW_FORM_ref_addr;
5530 case dw_val_class_fde_ref:
5531 return DW_FORM_data;
5532 case dw_val_class_lbl_id:
5533 return DW_FORM_addr;
5534 case dw_val_class_lbl_offset:
5535 return DW_FORM_data;
5536 case dw_val_class_str:
5537 return DW_FORM_string;
5543 /* Output the encoding of an attribute value. */
5546 output_value_format (a)
5549 enum dwarf_form form = value_format (a);
5550 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5553 /* Output the .debug_abbrev section which defines the DIE abbreviation
5557 output_abbrev_section ()
5559 unsigned long abbrev_id;
5562 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5564 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5566 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5568 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5569 dwarf_tag_name (abbrev->die_tag));
5571 if (abbrev->die_child != NULL)
5572 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5574 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5576 for (a_attr = abbrev->die_attr; a_attr != NULL;
5577 a_attr = a_attr->dw_attr_next)
5579 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5580 dwarf_attr_name (a_attr->dw_attr));
5581 output_value_format (a_attr);
5584 dw2_asm_output_data (1, 0, NULL);
5585 dw2_asm_output_data (1, 0, NULL);
5588 /* Terminate the table. */
5589 dw2_asm_output_data (1, 0, NULL);
5592 /* Output a symbol we can use to refer to this DIE from another CU. */
5595 output_die_symbol (die)
5596 register dw_die_ref die;
5598 char *sym = die->die_symbol;
5603 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5604 /* We make these global, not weak; if the target doesn't support
5605 .linkonce, it doesn't support combining the sections, so debugging
5607 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5608 ASM_OUTPUT_LABEL (asm_out_file, sym);
5611 /* Output the DIE and its attributes. Called recursively to generate
5612 the definitions of each child DIE. */
5616 register dw_die_ref die;
5618 register dw_attr_ref a;
5619 register dw_die_ref c;
5620 register unsigned long size;
5622 /* If someone in another CU might refer to us, set up a symbol for
5623 them to point to. */
5624 if (die->die_symbol)
5625 output_die_symbol (die);
5627 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5628 die->die_offset, dwarf_tag_name (die->die_tag));
5630 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5632 const char *name = dwarf_attr_name (a->dw_attr);
5634 switch (AT_class (a))
5636 case dw_val_class_addr:
5637 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
5640 case dw_val_class_loc:
5641 size = size_of_locs (AT_loc (a));
5643 /* Output the block length for this list of location operations. */
5644 dw2_asm_output_data (constant_size (size), size, "%s", name);
5646 output_loc_sequence (AT_loc (a));
5649 case dw_val_class_const:
5650 /* ??? It would be slightly more efficient to use a scheme like is
5651 used for unsigned constants below, but gdb 4.x does not sign
5652 extend. Gdb 5.x does sign extend. */
5653 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
5656 case dw_val_class_unsigned_const:
5657 dw2_asm_output_data (constant_size (AT_unsigned (a)),
5658 AT_unsigned (a), "%s", name);
5661 case dw_val_class_long_long:
5663 unsigned HOST_WIDE_INT first, second;
5665 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5668 if (WORDS_BIG_ENDIAN)
5670 first = a->dw_attr_val.v.val_long_long.hi;
5671 second = a->dw_attr_val.v.val_long_long.low;
5675 first = a->dw_attr_val.v.val_long_long.low;
5676 second = a->dw_attr_val.v.val_long_long.hi;
5678 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5679 first, "long long constant");
5680 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5685 case dw_val_class_float:
5687 register unsigned int i;
5689 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
5692 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5693 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
5694 "fp constant word %u", i);
5698 case dw_val_class_flag:
5699 dw2_asm_output_data (1, AT_flag (a), "%s", name);
5702 case dw_val_class_die_ref:
5703 if (AT_ref_external (a))
5705 char *sym = AT_ref (a)->die_symbol;
5708 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
5710 else if (AT_ref (a)->die_offset == 0)
5713 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
5717 case dw_val_class_fde_ref:
5720 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
5721 a->dw_attr_val.v.val_fde_index * 2);
5722 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
5726 case dw_val_class_lbl_id:
5727 dw2_asm_output_offset (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
5730 case dw_val_class_lbl_offset:
5731 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
5734 case dw_val_class_str:
5735 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
5743 for (c = die->die_child; c != NULL; c = c->die_sib)
5746 if (die->die_child != NULL)
5748 /* Add null byte to terminate sibling list. */
5749 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
5754 /* Output the compilation unit that appears at the beginning of the
5755 .debug_info section, and precedes the DIE descriptions. */
5758 output_compilation_unit_header ()
5760 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
5761 "Length of Compilation Unit Info");
5763 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
5765 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
5766 "Offset Into Abbrev. Section");
5768 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
5771 /* Output the compilation unit DIE and its children. */
5774 output_comp_unit (die)
5777 const char *secname;
5779 if (die->die_child == 0)
5782 /* Mark all the DIEs in this CU so we know which get local refs. */
5785 build_abbrev_table (die);
5787 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
5788 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
5789 calc_die_sizes (die);
5791 if (die->die_symbol)
5793 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
5794 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
5796 die->die_symbol = NULL;
5799 secname = (const char *) DEBUG_INFO_SECTION;
5801 /* Output debugging information. */
5802 ASM_OUTPUT_SECTION (asm_out_file, secname);
5803 output_compilation_unit_header ();
5806 /* Leave the marks on the main CU, so we can check them in
5808 if (die->die_symbol)
5812 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5813 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5814 argument list, and maybe the scope. */
5817 dwarf2_name (decl, scope)
5821 return (*decl_printable_name) (decl, scope ? 1 : 0);
5824 /* Add a new entry to .debug_pubnames if appropriate. */
5827 add_pubname (decl, die)
5833 if (! TREE_PUBLIC (decl))
5836 if (pubname_table_in_use == pubname_table_allocated)
5838 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5839 pubname_table = (pubname_ref) xrealloc
5840 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5843 p = &pubname_table[pubname_table_in_use++];
5846 p->name = xstrdup (dwarf2_name (decl, 1));
5849 /* Output the public names table used to speed up access to externally
5850 visible names. For now, only generate entries for externally
5851 visible procedures. */
5856 register unsigned i;
5857 register unsigned long pubnames_length = size_of_pubnames ();
5859 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
5860 "Length of Public Names Info");
5862 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5864 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5865 "Offset of Compilation Unit Info");
5867 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
5868 "Compilation Unit Length");
5870 for (i = 0; i < pubname_table_in_use; ++i)
5872 register pubname_ref pub = &pubname_table[i];
5874 /* We shouldn't see pubnames for DIEs outside of the main CU. */
5875 if (pub->die->die_mark == 0)
5878 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
5881 dw2_asm_output_nstring (pub->name, -1, "external name");
5884 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
5887 /* Add a new entry to .debug_aranges if appropriate. */
5890 add_arange (decl, die)
5894 if (! DECL_SECTION_NAME (decl))
5897 if (arange_table_in_use == arange_table_allocated)
5899 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5901 = (arange_ref) xrealloc (arange_table,
5902 arange_table_allocated * sizeof (dw_die_ref));
5905 arange_table[arange_table_in_use++] = die;
5908 /* Output the information that goes into the .debug_aranges table.
5909 Namely, define the beginning and ending address range of the
5910 text section generated for this compilation unit. */
5915 register unsigned i;
5916 register unsigned long aranges_length = size_of_aranges ();
5918 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
5919 "Length of Address Ranges Info");
5921 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5923 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5924 "Offset of Compilation Unit Info");
5926 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
5928 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
5930 /* We need to align to twice the pointer size here. */
5931 if (DWARF_ARANGES_PAD_SIZE)
5933 /* Pad using a 2 byte words so that padding is correct for any
5935 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
5936 2 * DWARF2_ADDR_SIZE);
5937 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
5938 dw2_asm_output_data (2, 0, NULL);
5941 dw2_asm_output_offset (DWARF2_ADDR_SIZE, text_section_label, "Address");
5942 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
5943 text_section_label, "Length");
5945 for (i = 0; i < arange_table_in_use; ++i)
5947 dw_die_ref die = arange_table[i];
5949 /* We shouldn't see aranges for DIEs outside of the main CU. */
5950 if (die->die_mark == 0)
5953 if (die->die_tag == DW_TAG_subprogram)
5955 dw2_asm_output_offset (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
5957 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
5958 get_AT_low_pc (die), "Length");
5962 /* A static variable; extract the symbol from DW_AT_location.
5963 Note that this code isn't currently hit, as we only emit
5964 aranges for functions (jason 9/23/99). */
5966 dw_attr_ref a = get_AT (die, DW_AT_location);
5967 dw_loc_descr_ref loc;
5968 if (! a || AT_class (a) != dw_val_class_loc)
5972 if (loc->dw_loc_opc != DW_OP_addr)
5975 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
5976 loc->dw_loc_oprnd1.v.val_addr, "Address");
5977 dw2_asm_output_data (DWARF2_ADDR_SIZE,
5978 get_AT_unsigned (die, DW_AT_byte_size),
5983 /* Output the terminator words. */
5984 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
5985 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
5989 /* Data structure containing information about input files. */
5992 char *path; /* Complete file name. */
5993 char *fname; /* File name part. */
5994 int length; /* Length of entire string. */
5995 int file_idx; /* Index in input file table. */
5996 int dir_idx; /* Index in directory table. */
5999 /* Data structure containing information about directories with source
6003 char *path; /* Path including directory name. */
6004 int length; /* Path length. */
6005 int prefix; /* Index of directory entry which is a prefix. */
6006 int nbytes; /* Total number of bytes in all file names excluding
6008 int count; /* Number of files in this directory. */
6009 int dir_idx; /* Index of directory used as base. */
6010 int used; /* Used in the end? */
6013 /* Callback function for file_info comparison. We sort by looking at
6014 the directories in the path. */
6016 file_info_cmp (p1, p2)
6020 const struct file_info *s1 = p1;
6021 const struct file_info *s2 = p2;
6025 /* Take care of file names without directories. */
6026 if (s1->path == s1->fname)
6028 else if (s2->path == s2->fname)
6031 cp1 = (unsigned char *) s1->path;
6032 cp2 = (unsigned char *) s2->path;
6038 /* Reached the end of the first path? */
6039 if (cp1 == (unsigned char *) s1->fname)
6040 /* It doesn't really matter in which order files from the
6041 same directory are sorted in. Therefore don't test for
6042 the second path reaching the end. */
6044 else if (cp2 == (unsigned char *) s2->fname)
6047 /* Character of current path component the same? */
6053 /* Compute the maximum prefix of P2 appearing also in P1. Entire
6054 directory names must match. */
6055 static int prefix_of PARAMS ((struct dir_info *, struct dir_info *));
6058 struct dir_info *p1;
6059 struct dir_info *p2;
6061 char *s1 = p1->path;
6062 char *s2 = p2->path;
6063 int len = p1->length < p2->length ? p1->length : p2->length;
6065 while (*s1 == *s2 && s1 < p1->path + len)
6068 if (*s1 == '/' && *s2 == '/')
6069 /* The whole of P1 is the prefix. */
6072 /* Go back to the last directory component. */
6073 while (s1 > p1->path)
6075 return s1 - p1->path + 1;
6080 /* Output the directory table and the file name table. We try to minimize
6081 the total amount of memory needed. A heuristic is used to avoid large
6082 slowdowns with many input files. */
6084 output_file_names ()
6086 struct file_info *files;
6087 struct dir_info *dirs;
6096 /* Allocate the various arrays we need. */
6097 files = (struct file_info *) alloca (line_file_table.in_use
6098 * sizeof (struct file_info));
6099 dirs = (struct dir_info *) alloca (line_file_table.in_use * 2
6100 * sizeof (struct dir_info));
6102 /* Sort the file names. */
6103 for (i = 1; i < (int) line_file_table.in_use; ++i)
6107 /* Skip all leading "./". */
6108 f = line_file_table.table[i];
6109 while (f[0] == '.' && f[1] == '/')
6112 /* Create a new array entry. */
6114 files[i].length = strlen (f);
6115 files[i].file_idx = i;
6117 /* Search for the file name part. */
6118 f = strrchr (f, '/');
6119 files[i].fname = f == NULL ? files[i].path : f + 1;
6121 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6124 /* Find all the different directories used. */
6125 dirs[0].path = files[1].path;
6126 dirs[0].length = files[1].fname - files[1].path;
6127 dirs[0].prefix = -1;
6128 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6130 dirs[0].dir_idx = 0;
6132 files[1].dir_idx = 0;
6135 for (i = 2; i < (int) line_file_table.in_use; ++i)
6136 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6137 && memcmp (dirs[ndirs - 1].path, files[i].path,
6138 dirs[ndirs - 1].length) == 0)
6140 /* Same directory as last entry. */
6141 files[i].dir_idx = ndirs - 1;
6142 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6143 ++dirs[ndirs - 1].count;
6151 /* This is a new directory. */
6152 dirs[ndirs].path = files[i].path;
6153 dirs[ndirs].length = files[i].fname - files[i].path;
6154 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6155 dirs[ndirs].count = 1;
6156 dirs[ndirs].dir_idx = ndirs;
6157 dirs[ndirs].used = 0;
6158 files[i].dir_idx = ndirs;
6160 /* Search for a prefix. */
6163 for (j = 0; j < ndirs; ++j)
6164 if (dirs[j].length > max_len)
6166 int this_len = prefix_of (&dirs[j], &dirs[ndirs]);
6168 if (this_len > max_len)
6175 /* Remember the prefix. If this is a known prefix simply
6176 remember the index. Otherwise we will have to create an
6177 artificial entry. */
6178 if (max_len == dirs[max_idx].length)
6179 /* This is our prefix. */
6180 dirs[ndirs].prefix = max_idx;
6181 else if (max_len > 0)
6183 /* Create an entry without associated file. Since we have
6184 to keep the dirs array sorted (means, entries with paths
6185 which come first) we have to move the new entry in the
6186 place of the old one. */
6187 dirs[++ndirs] = dirs[max_idx];
6189 /* We don't have to set .path. */
6190 dirs[max_idx].length = max_len;
6191 dirs[max_idx].nbytes = 0;
6192 dirs[max_idx].count = 0;
6193 dirs[max_idx].dir_idx = ndirs;
6194 dirs[max_idx].used = 0;
6195 dirs[max_idx].prefix = dirs[ndirs].prefix;
6197 dirs[ndirs - 1].prefix = dirs[ndirs].prefix = max_idx;
6200 dirs[ndirs].prefix = -1;
6205 /* Now to the actual work. We have to find a subset of the
6206 directories which allow expressing the file name using references
6207 to the directory table with the least amount of characters. We
6208 do not do an exhaustive search where we would have to check out
6209 every combination of every single possible prefix. Instead we
6210 use a heuristic which provides nearly optimal results in most
6211 cases and never is much off. */
6212 saved = (int *) alloca (ndirs * sizeof (int));
6213 savehere = (int *) alloca (ndirs * sizeof (int));
6215 memset (saved, '\0', ndirs * sizeof (saved[0]));
6216 for (i = 0; i < ndirs; ++i)
6221 /* We can always safe some space for the current directory. But
6222 this does not mean it will be enough to justify adding the
6224 savehere[i] = dirs[i].length;
6225 total = (savehere[i] - saved[i]) * dirs[i].count;
6227 for (j = i + 1; j < ndirs; ++j)
6231 if (saved[j] < dirs[i].length)
6233 /* Determine whether the dirs[i] path is a prefix of the
6238 while (k != -1 && k != i)
6243 /* Yes it is. We can possibly safe some memory but
6244 writing the filenames in dirs[j] relative to
6246 savehere[j] = dirs[i].length;
6247 total += (savehere[j] - saved[j]) * dirs[j].count;
6252 /* Check whether we can safe enough to justify adding the dirs[i]
6254 if (total > dirs[i].length + 1)
6256 /* It's worthwhile adding. */
6257 for (j = i; j < ndirs; ++j)
6258 if (savehere[j] > 0)
6260 /* Remember how much we saved for this directory so far. */
6261 saved[j] = savehere[j];
6263 /* Remember the prefix directory. */
6264 dirs[j].dir_idx = i;
6269 /* We have to emit them in the order they appear in the line_file_table
6270 array since the index is used in the debug info generation. To
6271 do this efficiently we generate a back-mapping of the indices
6273 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6274 for (i = 1; i < (int) line_file_table.in_use; ++i)
6276 backmap[files[i].file_idx] = i;
6277 /* Mark this directory as used. */
6278 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6281 /* That was it. We are ready to emit the information. First the
6282 directory name table. Here we have to make sure that the first
6283 actually emitted directory name has the index one. Zero is
6284 reserved for the current working directory. Make sure we do not
6285 confuse these indices with the one for the constructed table
6286 (even though most of the time they are identical). */
6288 idx_offset = dirs[0].length > 0 ? 1 : 0;
6289 for (i = 1 - idx_offset; i < ndirs; ++i)
6290 if (dirs[i].used != 0)
6292 dirs[i].used = idx++;
6293 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6294 "Directory Entry: 0x%x", dirs[i].used);
6296 dw2_asm_output_data (1, 0, "End directory table");
6298 /* Correct the index for the current working directory entry if it
6300 if (idx_offset == 0)
6303 /* Now write all the file names. */
6304 for (i = 1; i < (int) line_file_table.in_use; ++i)
6306 int file_idx = backmap[i];
6307 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6309 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6310 "File Entry: 0x%x", i);
6312 /* Include directory index. */
6313 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6315 /* Modification time. */
6316 dw2_asm_output_data_uleb128 (0, NULL);
6318 /* File length in bytes. */
6319 dw2_asm_output_data_uleb128 (0, NULL);
6321 dw2_asm_output_data (1, 0, "End file name table");
6325 /* Output the source line number correspondence information. This
6326 information goes into the .debug_line section. */
6331 char l1[20], l2[20];
6332 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6333 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6334 register unsigned opc;
6335 register unsigned n_op_args;
6336 register unsigned long lt_index;
6337 register unsigned long current_line;
6338 register long line_offset;
6339 register long line_delta;
6340 register unsigned long current_file;
6341 register unsigned long function;
6343 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6344 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6346 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6347 "Length of Source Line Info");
6348 ASM_OUTPUT_LABEL (asm_out_file, l1);
6350 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6352 dw2_asm_output_data (DWARF_OFFSET_SIZE, size_of_line_prolog (),
6355 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6356 "Minimum Instruction Length");
6358 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6359 "Default is_stmt_start flag");
6361 dw2_asm_output_data (1, DWARF_LINE_BASE,
6362 "Line Base Value (Special Opcodes)");
6364 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6365 "Line Range Value (Special Opcodes)");
6367 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6368 "Special Opcode Base");
6370 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6374 case DW_LNS_advance_pc:
6375 case DW_LNS_advance_line:
6376 case DW_LNS_set_file:
6377 case DW_LNS_set_column:
6378 case DW_LNS_fixed_advance_pc:
6386 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6390 /* Write out the information about the files we use. */
6391 output_file_names ();
6393 /* We used to set the address register to the first location in the text
6394 section here, but that didn't accomplish anything since we already
6395 have a line note for the opening brace of the first function. */
6397 /* Generate the line number to PC correspondence table, encoded as
6398 a series of state machine operations. */
6401 strcpy (prev_line_label, text_section_label);
6402 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6404 register dw_line_info_ref line_info = &line_info_table[lt_index];
6407 /* Disable this optimization for now; GDB wants to see two line notes
6408 at the beginning of a function so it can find the end of the
6411 /* Don't emit anything for redundant notes. Just updating the
6412 address doesn't accomplish anything, because we already assume
6413 that anything after the last address is this line. */
6414 if (line_info->dw_line_num == current_line
6415 && line_info->dw_file_num == current_file)
6419 /* Emit debug info for the address of the current line.
6421 Unfortunately, we have little choice here currently, and must always
6422 use the most general form. Gcc does not know the address delta
6423 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6424 attributes which will give an upper bound on the address range. We
6425 could perhaps use length attributes to determine when it is safe to
6426 use DW_LNS_fixed_advance_pc. */
6428 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6431 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6432 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6433 "DW_LNS_fixed_advance_pc");
6434 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6438 /* This can handle any delta. This takes
6439 4+DWARF2_ADDR_SIZE bytes. */
6440 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6441 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6442 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6443 dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
6445 strcpy (prev_line_label, line_label);
6447 /* Emit debug info for the source file of the current line, if
6448 different from the previous line. */
6449 if (line_info->dw_file_num != current_file)
6451 current_file = line_info->dw_file_num;
6452 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6453 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6454 line_file_table.table[current_file]);
6457 /* Emit debug info for the current line number, choosing the encoding
6458 that uses the least amount of space. */
6459 if (line_info->dw_line_num != current_line)
6461 line_offset = line_info->dw_line_num - current_line;
6462 line_delta = line_offset - DWARF_LINE_BASE;
6463 current_line = line_info->dw_line_num;
6464 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6466 /* This can handle deltas from -10 to 234, using the current
6467 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6469 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6470 "line %lu", current_line);
6474 /* This can handle any delta. This takes at least 4 bytes,
6475 depending on the value being encoded. */
6476 dw2_asm_output_data (1, DW_LNS_advance_line,
6477 "advance to line %lu", current_line);
6478 dw2_asm_output_data_sleb128 (line_offset, NULL);
6479 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6484 /* We still need to start a new row, so output a copy insn. */
6485 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6489 /* Emit debug info for the address of the end of the function. */
6492 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6493 "DW_LNS_fixed_advance_pc");
6494 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6498 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6499 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6500 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6501 dw2_asm_output_offset (DWARF2_ADDR_SIZE, text_end_label, NULL);
6504 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6505 dw2_asm_output_data_uleb128 (1, NULL);
6506 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6511 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6513 register dw_separate_line_info_ref line_info
6514 = &separate_line_info_table[lt_index];
6517 /* Don't emit anything for redundant notes. */
6518 if (line_info->dw_line_num == current_line
6519 && line_info->dw_file_num == current_file
6520 && line_info->function == function)
6524 /* Emit debug info for the address of the current line. If this is
6525 a new function, or the first line of a function, then we need
6526 to handle it differently. */
6527 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6529 if (function != line_info->function)
6531 function = line_info->function;
6533 /* Set the address register to the first line in the function */
6534 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6535 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6536 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6537 dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
6541 /* ??? See the DW_LNS_advance_pc comment above. */
6544 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6545 "DW_LNS_fixed_advance_pc");
6546 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6550 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6551 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6552 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6553 dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
6556 strcpy (prev_line_label, line_label);
6558 /* Emit debug info for the source file of the current line, if
6559 different from the previous line. */
6560 if (line_info->dw_file_num != current_file)
6562 current_file = line_info->dw_file_num;
6563 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6564 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6565 line_file_table.table[current_file]);
6568 /* Emit debug info for the current line number, choosing the encoding
6569 that uses the least amount of space. */
6570 if (line_info->dw_line_num != current_line)
6572 line_offset = line_info->dw_line_num - current_line;
6573 line_delta = line_offset - DWARF_LINE_BASE;
6574 current_line = line_info->dw_line_num;
6575 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6576 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6577 "line %lu", current_line);
6580 dw2_asm_output_data (1, DW_LNS_advance_line,
6581 "advance to line %lu", current_line);
6582 dw2_asm_output_data_sleb128 (line_offset, NULL);
6583 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6587 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6594 /* If we're done with a function, end its sequence. */
6595 if (lt_index == separate_line_info_table_in_use
6596 || separate_line_info_table[lt_index].function != function)
6601 /* Emit debug info for the address of the end of the function. */
6602 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6605 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6606 "DW_LNS_fixed_advance_pc");
6607 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6611 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6612 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6613 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6614 dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
6617 /* Output the marker for the end of this sequence. */
6618 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6619 dw2_asm_output_data_uleb128 (1, NULL);
6620 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6624 /* Output the marker for the end of the line number info. */
6625 ASM_OUTPUT_LABEL (asm_out_file, l2);
6628 /* Given a pointer to a tree node for some base type, return a pointer to
6629 a DIE that describes the given type.
6631 This routine must only be called for GCC type nodes that correspond to
6632 Dwarf base (fundamental) types. */
6635 base_type_die (type)
6638 register dw_die_ref base_type_result;
6639 register const char *type_name;
6640 register enum dwarf_type encoding;
6641 register tree name = TYPE_NAME (type);
6643 if (TREE_CODE (type) == ERROR_MARK
6644 || TREE_CODE (type) == VOID_TYPE)
6649 if (TREE_CODE (name) == TYPE_DECL)
6650 name = DECL_NAME (name);
6652 type_name = IDENTIFIER_POINTER (name);
6655 type_name = "__unknown__";
6657 switch (TREE_CODE (type))
6660 /* Carefully distinguish the C character types, without messing
6661 up if the language is not C. Note that we check only for the names
6662 that contain spaces; other names might occur by coincidence in other
6664 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6665 && (type == char_type_node
6666 || ! strcmp (type_name, "signed char")
6667 || ! strcmp (type_name, "unsigned char"))))
6669 if (TREE_UNSIGNED (type))
6670 encoding = DW_ATE_unsigned;
6672 encoding = DW_ATE_signed;
6675 /* else fall through. */
6678 /* GNU Pascal/Ada CHAR type. Not used in C. */
6679 if (TREE_UNSIGNED (type))
6680 encoding = DW_ATE_unsigned_char;
6682 encoding = DW_ATE_signed_char;
6686 encoding = DW_ATE_float;
6689 /* Dwarf2 doesn't know anything about complex ints, so use
6690 a user defined type for it. */
6692 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6693 encoding = DW_ATE_complex_float;
6695 encoding = DW_ATE_lo_user;
6699 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6700 encoding = DW_ATE_boolean;
6704 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6707 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6708 if (demangle_name_func)
6709 type_name = (*demangle_name_func) (type_name);
6711 add_AT_string (base_type_result, DW_AT_name, type_name);
6712 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6713 int_size_in_bytes (type));
6714 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6716 return base_type_result;
6719 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6720 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6721 a given type is generally the same as the given type, except that if the
6722 given type is a pointer or reference type, then the root type of the given
6723 type is the root type of the "basis" type for the pointer or reference
6724 type. (This definition of the "root" type is recursive.) Also, the root
6725 type of a `const' qualified type or a `volatile' qualified type is the
6726 root type of the given type without the qualifiers. */
6732 if (TREE_CODE (type) == ERROR_MARK)
6733 return error_mark_node;
6735 switch (TREE_CODE (type))
6738 return error_mark_node;
6741 case REFERENCE_TYPE:
6742 return type_main_variant (root_type (TREE_TYPE (type)));
6745 return type_main_variant (type);
6749 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6750 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6756 switch (TREE_CODE (type))
6771 case QUAL_UNION_TYPE:
6776 case REFERENCE_TYPE:
6790 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6791 entry that chains various modifiers in front of the given type. */
6794 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6796 register int is_const_type;
6797 register int is_volatile_type;
6798 register dw_die_ref context_die;
6800 register enum tree_code code = TREE_CODE (type);
6801 register dw_die_ref mod_type_die = NULL;
6802 register dw_die_ref sub_die = NULL;
6803 register tree item_type = NULL;
6805 if (code != ERROR_MARK)
6807 type = build_type_variant (type, is_const_type, is_volatile_type);
6809 mod_type_die = lookup_type_die (type);
6811 return mod_type_die;
6813 /* Handle C typedef types. */
6814 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6815 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6817 tree dtype = TREE_TYPE (TYPE_NAME (type));
6820 /* For a named type, use the typedef. */
6821 gen_type_die (type, context_die);
6822 mod_type_die = lookup_type_die (type);
6825 else if (is_const_type < TYPE_READONLY (dtype)
6826 || is_volatile_type < TYPE_VOLATILE (dtype))
6827 /* cv-unqualified version of named type. Just use the unnamed
6828 type to which it refers. */
6830 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6831 is_const_type, is_volatile_type,
6833 /* Else cv-qualified version of named type; fall through. */
6839 else if (is_const_type)
6841 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6842 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6844 else if (is_volatile_type)
6846 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6847 sub_die = modified_type_die (type, 0, 0, context_die);
6849 else if (code == POINTER_TYPE)
6851 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6852 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6854 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6856 item_type = TREE_TYPE (type);
6858 else if (code == REFERENCE_TYPE)
6860 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6861 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6863 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6865 item_type = TREE_TYPE (type);
6867 else if (is_base_type (type))
6868 mod_type_die = base_type_die (type);
6871 gen_type_die (type, context_die);
6873 /* We have to get the type_main_variant here (and pass that to the
6874 `lookup_type_die' routine) because the ..._TYPE node we have
6875 might simply be a *copy* of some original type node (where the
6876 copy was created to help us keep track of typedef names) and
6877 that copy might have a different TYPE_UID from the original
6879 mod_type_die = lookup_type_die (type_main_variant (type));
6880 if (mod_type_die == NULL)
6885 equate_type_number_to_die (type, mod_type_die);
6887 /* We must do this after the equate_type_number_to_die call, in case
6888 this is a recursive type. This ensures that the modified_type_die
6889 recursion will terminate even if the type is recursive. Recursive
6890 types are possible in Ada. */
6891 sub_die = modified_type_die (item_type,
6892 TYPE_READONLY (item_type),
6893 TYPE_VOLATILE (item_type),
6896 if (sub_die != NULL)
6897 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6899 return mod_type_die;
6902 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6903 an enumerated type. */
6909 return TREE_CODE (type) == ENUMERAL_TYPE;
6912 /* Return the register number described by a given RTL node. */
6918 register unsigned regno = REGNO (rtl);
6920 if (regno >= FIRST_PSEUDO_REGISTER)
6922 warning ("internal regno botch: regno = %d\n", regno);
6926 regno = DBX_REGISTER_NUMBER (regno);
6930 /* Return a location descriptor that designates a machine register. */
6932 static dw_loc_descr_ref
6933 reg_loc_descriptor (rtl)
6936 register dw_loc_descr_ref loc_result = NULL;
6937 register unsigned reg = reg_number (rtl);
6940 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6942 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6947 /* Return a location descriptor that designates a constant. */
6949 static dw_loc_descr_ref
6950 int_loc_descriptor (i)
6953 enum dwarf_location_atom op;
6955 /* Pick the smallest representation of a constant, rather than just
6956 defaulting to the LEB encoding. */
6960 op = DW_OP_lit0 + i;
6963 else if (i <= 0xffff)
6965 else if (HOST_BITS_PER_WIDE_INT == 32
6975 else if (i >= -0x8000)
6977 else if (HOST_BITS_PER_WIDE_INT == 32
6978 || i >= -0x80000000)
6984 return new_loc_descr (op, i, 0);
6987 /* Return a location descriptor that designates a base+offset location. */
6989 static dw_loc_descr_ref
6990 based_loc_descr (reg, offset)
6994 register dw_loc_descr_ref loc_result;
6995 /* For the "frame base", we use the frame pointer or stack pointer
6996 registers, since the RTL for local variables is relative to one of
6998 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6999 ? HARD_FRAME_POINTER_REGNUM
7000 : STACK_POINTER_REGNUM);
7003 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7005 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7007 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7012 /* Return true if this RTL expression describes a base+offset calculation. */
7018 return (GET_CODE (rtl) == PLUS
7019 && ((GET_CODE (XEXP (rtl, 0)) == REG
7020 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7023 /* The following routine converts the RTL for a variable or parameter
7024 (resident in memory) into an equivalent Dwarf representation of a
7025 mechanism for getting the address of that same variable onto the top of a
7026 hypothetical "address evaluation" stack.
7028 When creating memory location descriptors, we are effectively transforming
7029 the RTL for a memory-resident object into its Dwarf postfix expression
7030 equivalent. This routine recursively descends an RTL tree, turning
7031 it into Dwarf postfix code as it goes.
7033 MODE is the mode of the memory reference, needed to handle some
7034 autoincrement addressing modes. */
7036 static dw_loc_descr_ref
7037 mem_loc_descriptor (rtl, mode)
7039 enum machine_mode mode;
7041 dw_loc_descr_ref mem_loc_result = NULL;
7042 /* Note that for a dynamically sized array, the location we will generate a
7043 description of here will be the lowest numbered location which is
7044 actually within the array. That's *not* necessarily the same as the
7045 zeroth element of the array. */
7047 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7048 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7051 switch (GET_CODE (rtl))
7056 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7057 just fall into the SUBREG code. */
7062 /* The case of a subreg may arise when we have a local (register)
7063 variable or a formal (register) parameter which doesn't quite fill
7064 up an entire register. For now, just assume that it is
7065 legitimate to make the Dwarf info refer to the whole register which
7066 contains the given subreg. */
7067 rtl = XEXP (rtl, 0);
7072 /* Whenever a register number forms a part of the description of the
7073 method for calculating the (dynamic) address of a memory resident
7074 object, DWARF rules require the register number be referred to as
7075 a "base register". This distinction is not based in any way upon
7076 what category of register the hardware believes the given register
7077 belongs to. This is strictly DWARF terminology we're dealing with
7078 here. Note that in cases where the location of a memory-resident
7079 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7080 OP_CONST (0)) the actual DWARF location descriptor that we generate
7081 may just be OP_BASEREG (basereg). This may look deceptively like
7082 the object in question was allocated to a register (rather than in
7083 memory) so DWARF consumers need to be aware of the subtle
7084 distinction between OP_REG and OP_BASEREG. */
7085 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7089 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7090 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7094 /* Some ports can transform a symbol ref into a label ref, because
7095 the symbol ref is too far away and has to be dumped into a constant
7099 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7100 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7101 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7105 /* Extract the PLUS expression nested inside and fall into
7106 PLUS code bellow. */
7107 rtl = XEXP (rtl, 1);
7112 /* Turn these into a PLUS expression and fall into the PLUS code
7114 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7115 GEN_INT (GET_CODE (rtl) == PRE_INC
7116 ? GET_MODE_UNIT_SIZE (mode)
7117 : -GET_MODE_UNIT_SIZE (mode)));
7123 if (is_based_loc (rtl))
7124 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7125 INTVAL (XEXP (rtl, 1)));
7128 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7130 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7131 && INTVAL (XEXP (rtl, 1)) >= 0)
7133 add_loc_descr (&mem_loc_result,
7134 new_loc_descr (DW_OP_plus_uconst,
7135 INTVAL (XEXP (rtl, 1)), 0));
7139 add_loc_descr (&mem_loc_result,
7140 mem_loc_descriptor (XEXP (rtl, 1), mode));
7141 add_loc_descr (&mem_loc_result,
7142 new_loc_descr (DW_OP_plus, 0, 0));
7148 /* If a pseudo-reg is optimized away, it is possible for it to
7149 be replaced with a MEM containing a multiply. */
7150 add_loc_descr (&mem_loc_result,
7151 mem_loc_descriptor (XEXP (rtl, 0), mode));
7152 add_loc_descr (&mem_loc_result,
7153 mem_loc_descriptor (XEXP (rtl, 1), mode));
7154 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7158 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7165 return mem_loc_result;
7168 /* Return a descriptor that describes the concatenation of two locations.
7169 This is typically a complex variable. */
7171 static dw_loc_descr_ref
7172 concat_loc_descriptor (x0, x1)
7173 register rtx x0, x1;
7175 dw_loc_descr_ref cc_loc_result = NULL;
7177 if (!is_pseudo_reg (x0)
7178 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7179 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7180 add_loc_descr (&cc_loc_result,
7181 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7183 if (!is_pseudo_reg (x1)
7184 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7185 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7186 add_loc_descr (&cc_loc_result,
7187 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7189 return cc_loc_result;
7192 /* Output a proper Dwarf location descriptor for a variable or parameter
7193 which is either allocated in a register or in a memory location. For a
7194 register, we just generate an OP_REG and the register number. For a
7195 memory location we provide a Dwarf postfix expression describing how to
7196 generate the (dynamic) address of the object onto the address stack. */
7198 static dw_loc_descr_ref
7199 loc_descriptor (rtl)
7202 dw_loc_descr_ref loc_result = NULL;
7203 switch (GET_CODE (rtl))
7206 /* The case of a subreg may arise when we have a local (register)
7207 variable or a formal (register) parameter which doesn't quite fill
7208 up an entire register. For now, just assume that it is
7209 legitimate to make the Dwarf info refer to the whole register which
7210 contains the given subreg. */
7211 rtl = XEXP (rtl, 0);
7216 loc_result = reg_loc_descriptor (rtl);
7220 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7224 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7234 /* Similar, but generate the descriptor from trees instead of rtl.
7235 This comes up particularly with variable length arrays. */
7237 static dw_loc_descr_ref
7238 loc_descriptor_from_tree (loc, addressp)
7242 dw_loc_descr_ref ret = NULL;
7243 int indirect_size = 0;
7244 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7245 enum dwarf_location_atom op;
7247 /* ??? Most of the time we do not take proper care for sign/zero
7248 extending the values properly. Hopefully this won't be a real
7251 switch (TREE_CODE (loc))
7256 case WITH_RECORD_EXPR:
7257 /* This case involves extracting fields from an object to determine the
7258 position of other fields. We don't try to encode this here. The
7259 only user of this is Ada, which encodes the needed information using
7260 the names of types. */
7266 rtx rtl = rtl_for_decl_location (loc);
7267 enum machine_mode mode = DECL_MODE (loc);
7269 if (rtl == NULL_RTX)
7271 else if (CONSTANT_P (rtl))
7273 ret = new_loc_descr (DW_OP_addr, 0, 0);
7274 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7275 ret->dw_loc_oprnd1.v.val_addr = rtl;
7276 indirect_size = GET_MODE_SIZE (mode);
7280 if (GET_CODE (rtl) == MEM)
7282 indirect_size = GET_MODE_SIZE (mode);
7283 rtl = XEXP (rtl, 0);
7285 ret = mem_loc_descriptor (rtl, mode);
7291 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7292 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7297 case NON_LVALUE_EXPR:
7299 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7306 HOST_WIDE_INT bitsize, bitpos, bytepos;
7307 enum machine_mode mode;
7309 unsigned int alignment;
7311 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7312 &unsignedp, &volatilep, &alignment);
7313 ret = loc_descriptor_from_tree (obj, 1);
7315 if (offset != NULL_TREE)
7317 /* Variable offset. */
7318 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7319 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7324 /* We cannot address anything not on a unit boundary. */
7325 if (bitpos % BITS_PER_UNIT != 0)
7330 if (bitpos % BITS_PER_UNIT != 0
7331 || bitsize % BITS_PER_UNIT != 0)
7333 /* ??? We could handle this by loading and shifting etc.
7334 Wait until someone needs it before expending the effort. */
7338 indirect_size = bitsize / BITS_PER_UNIT;
7341 bytepos = bitpos / BITS_PER_UNIT;
7343 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7344 else if (bytepos < 0)
7346 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7347 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7353 if (host_integerp (loc, 0))
7354 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7366 case TRUNC_DIV_EXPR:
7372 case TRUNC_MOD_EXPR:
7382 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7385 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7386 && host_integerp (TREE_OPERAND (loc, 1), 0))
7388 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7389 add_loc_descr (&ret,
7390 new_loc_descr (DW_OP_plus_uconst,
7391 tree_low_cst (TREE_OPERAND (loc, 1),
7399 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7404 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7409 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7414 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7426 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7427 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7428 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7442 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7443 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7447 loc = build (COND_EXPR, TREE_TYPE (loc),
7448 build (LT_EXPR, integer_type_node,
7449 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7450 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7455 dw_loc_descr_ref bra_node, jump_node, tmp;
7457 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7458 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7459 add_loc_descr (&ret, bra_node);
7461 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7462 add_loc_descr (&ret, tmp);
7463 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7464 add_loc_descr (&ret, jump_node);
7466 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7467 add_loc_descr (&ret, tmp);
7468 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7469 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7471 /* ??? Need a node to point the skip at. Use a nop. */
7472 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7473 add_loc_descr (&ret, tmp);
7474 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7475 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7483 /* If we can't fill the request for an address, die. */
7484 if (addressp && indirect_size == 0)
7487 /* If we've got an address and don't want one, dereference. */
7488 if (!addressp && indirect_size > 0)
7490 if (indirect_size > DWARF2_ADDR_SIZE)
7492 if (indirect_size == DWARF2_ADDR_SIZE)
7495 op = DW_OP_deref_size;
7496 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7502 /* Given a value, round it up to the lowest multiple of `boundary'
7503 which is not less than the value itself. */
7505 static inline HOST_WIDE_INT
7506 ceiling (value, boundary)
7507 HOST_WIDE_INT value;
7508 unsigned int boundary;
7510 return (((value + boundary - 1) / boundary) * boundary);
7513 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7514 pointer to the declared type for the relevant field variable, or return
7515 `integer_type_node' if the given node turns out to be an
7524 if (TREE_CODE (decl) == ERROR_MARK)
7525 return integer_type_node;
7527 type = DECL_BIT_FIELD_TYPE (decl);
7528 if (type == NULL_TREE)
7529 type = TREE_TYPE (decl);
7534 /* Given a pointer to a tree node, return the alignment in bits for
7535 it, or else return BITS_PER_WORD if the node actually turns out to
7536 be an ERROR_MARK node. */
7538 static inline unsigned
7539 simple_type_align_in_bits (type)
7542 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7545 static inline unsigned
7546 simple_decl_align_in_bits (decl)
7549 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7552 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7553 node, return the size in bits for the type if it is a constant, or else
7554 return the alignment for the type if the type's size is not constant, or
7555 else return BITS_PER_WORD if the type actually turns out to be an
7558 static inline unsigned HOST_WIDE_INT
7559 simple_type_size_in_bits (type)
7562 tree type_size_tree;
7564 if (TREE_CODE (type) == ERROR_MARK)
7565 return BITS_PER_WORD;
7566 type_size_tree = TYPE_SIZE (type);
7568 if (type_size_tree == NULL_TREE)
7570 if (! host_integerp (type_size_tree, 1))
7571 return TYPE_ALIGN (type);
7572 return tree_low_cst (type_size_tree, 1);
7575 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7576 return the byte offset of the lowest addressed byte of the "containing
7577 object" for the given FIELD_DECL, or return 0 if we are unable to
7578 determine what that offset is, either because the argument turns out to
7579 be a pointer to an ERROR_MARK node, or because the offset is actually
7580 variable. (We can't handle the latter case just yet). */
7582 static HOST_WIDE_INT
7583 field_byte_offset (decl)
7586 unsigned int type_align_in_bits;
7587 unsigned int decl_align_in_bits;
7588 unsigned HOST_WIDE_INT type_size_in_bits;
7589 HOST_WIDE_INT object_offset_in_bits;
7590 HOST_WIDE_INT object_offset_in_bytes;
7592 tree field_size_tree;
7593 HOST_WIDE_INT bitpos_int;
7594 HOST_WIDE_INT deepest_bitpos;
7595 unsigned HOST_WIDE_INT field_size_in_bits;
7597 if (TREE_CODE (decl) == ERROR_MARK)
7600 if (TREE_CODE (decl) != FIELD_DECL)
7603 type = field_type (decl);
7604 field_size_tree = DECL_SIZE (decl);
7606 /* The size could be unspecified if there was an error, or for
7607 a flexible array member. */
7608 if (! field_size_tree)
7609 field_size_tree = bitsize_zero_node;
7611 /* We cannot yet cope with fields whose positions are variable, so
7612 for now, when we see such things, we simply return 0. Someday, we may
7613 be able to handle such cases, but it will be damn difficult. */
7614 if (! host_integerp (bit_position (decl), 0))
7617 bitpos_int = int_bit_position (decl);
7619 /* If we don't know the size of the field, pretend it's a full word. */
7620 if (host_integerp (field_size_tree, 1))
7621 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7623 field_size_in_bits = BITS_PER_WORD;
7625 type_size_in_bits = simple_type_size_in_bits (type);
7626 type_align_in_bits = simple_type_align_in_bits (type);
7627 decl_align_in_bits = simple_decl_align_in_bits (decl);
7629 /* Note that the GCC front-end doesn't make any attempt to keep track of
7630 the starting bit offset (relative to the start of the containing
7631 structure type) of the hypothetical "containing object" for a bit-
7632 field. Thus, when computing the byte offset value for the start of the
7633 "containing object" of a bit-field, we must deduce this information on
7634 our own. This can be rather tricky to do in some cases. For example,
7635 handling the following structure type definition when compiling for an
7636 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7639 struct S { int field1; long long field2:31; };
7641 Fortunately, there is a simple rule-of-thumb which can be
7642 used in such cases. When compiling for an i386/i486, GCC will allocate
7643 8 bytes for the structure shown above. It decides to do this based upon
7644 one simple rule for bit-field allocation. Quite simply, GCC allocates
7645 each "containing object" for each bit-field at the first (i.e. lowest
7646 addressed) legitimate alignment boundary (based upon the required
7647 minimum alignment for the declared type of the field) which it can
7648 possibly use, subject to the condition that there is still enough
7649 available space remaining in the containing object (when allocated at
7650 the selected point) to fully accommodate all of the bits of the
7651 bit-field itself. This simple rule makes it obvious why GCC allocates
7652 8 bytes for each object of the structure type shown above. When looking
7653 for a place to allocate the "containing object" for `field2', the
7654 compiler simply tries to allocate a 64-bit "containing object" at each
7655 successive 32-bit boundary (starting at zero) until it finds a place to
7656 allocate that 64- bit field such that at least 31 contiguous (and
7657 previously unallocated) bits remain within that selected 64 bit field.
7658 (As it turns out, for the example above, the compiler finds that it is
7659 OK to allocate the "containing object" 64-bit field at bit-offset zero
7660 within the structure type.) Here we attempt to work backwards from the
7661 limited set of facts we're given, and we try to deduce from those facts,
7662 where GCC must have believed that the containing object started (within
7663 the structure type). The value we deduce is then used (by the callers of
7664 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7665 for fields (both bit-fields and, in the case of DW_AT_location, regular
7668 /* Figure out the bit-distance from the start of the structure to the
7669 "deepest" bit of the bit-field. */
7670 deepest_bitpos = bitpos_int + field_size_in_bits;
7672 /* This is the tricky part. Use some fancy footwork to deduce where the
7673 lowest addressed bit of the containing object must be. */
7674 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7676 /* Round up to type_align by default. This works best for bitfields. */
7677 object_offset_in_bits += type_align_in_bits - 1;
7678 object_offset_in_bits /= type_align_in_bits;
7679 object_offset_in_bits *= type_align_in_bits;
7681 if (object_offset_in_bits > bitpos_int)
7683 /* Sigh, the decl must be packed. */
7684 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7686 /* Round up to decl_align instead. */
7687 object_offset_in_bits += decl_align_in_bits - 1;
7688 object_offset_in_bits /= decl_align_in_bits;
7689 object_offset_in_bits *= decl_align_in_bits;
7692 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
7694 return object_offset_in_bytes;
7697 /* The following routines define various Dwarf attributes and any data
7698 associated with them. */
7700 /* Add a location description attribute value to a DIE.
7702 This emits location attributes suitable for whole variables and
7703 whole parameters. Note that the location attributes for struct fields are
7704 generated by the routine `data_member_location_attribute' below. */
7707 add_AT_location_description (die, attr_kind, rtl)
7709 enum dwarf_attribute attr_kind;
7712 /* Handle a special case. If we are about to output a location descriptor
7713 for a variable or parameter which has been optimized out of existence,
7714 don't do that. A variable which has been optimized out
7715 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7716 Currently, in some rare cases, variables can have DECL_RTL values which
7717 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7718 elsewhere in the compiler. We treat such cases as if the variable(s) in
7719 question had been optimized out of existence. */
7721 if (is_pseudo_reg (rtl)
7722 || (GET_CODE (rtl) == MEM
7723 && is_pseudo_reg (XEXP (rtl, 0)))
7724 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7725 references the internal argument pointer (a pseudo) in a function
7726 where all references to the internal argument pointer were
7727 eliminated via the optimizers. */
7728 || (GET_CODE (rtl) == MEM
7729 && GET_CODE (XEXP (rtl, 0)) == PLUS
7730 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7731 || (GET_CODE (rtl) == CONCAT
7732 && is_pseudo_reg (XEXP (rtl, 0))
7733 && is_pseudo_reg (XEXP (rtl, 1))))
7736 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7739 /* Attach the specialized form of location attribute used for data
7740 members of struct and union types. In the special case of a
7741 FIELD_DECL node which represents a bit-field, the "offset" part
7742 of this special location descriptor must indicate the distance
7743 in bytes from the lowest-addressed byte of the containing struct
7744 or union type to the lowest-addressed byte of the "containing
7745 object" for the bit-field. (See the `field_byte_offset' function
7746 above).. For any given bit-field, the "containing object" is a
7747 hypothetical object (of some integral or enum type) within which
7748 the given bit-field lives. The type of this hypothetical
7749 "containing object" is always the same as the declared type of
7750 the individual bit-field itself (for GCC anyway... the DWARF
7751 spec doesn't actually mandate this). Note that it is the size
7752 (in bytes) of the hypothetical "containing object" which will
7753 be given in the DW_AT_byte_size attribute for this bit-field.
7754 (See the `byte_size_attribute' function below.) It is also used
7755 when calculating the value of the DW_AT_bit_offset attribute.
7756 (See the `bit_offset_attribute' function below). */
7759 add_data_member_location_attribute (die, decl)
7760 register dw_die_ref die;
7763 register unsigned long offset;
7764 register dw_loc_descr_ref loc_descr;
7765 register enum dwarf_location_atom op;
7767 if (TREE_CODE (decl) == TREE_VEC)
7768 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7770 offset = field_byte_offset (decl);
7772 /* The DWARF2 standard says that we should assume that the structure address
7773 is already on the stack, so we can specify a structure field address
7774 by using DW_OP_plus_uconst. */
7776 #ifdef MIPS_DEBUGGING_INFO
7777 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7778 correctly. It works only if we leave the offset on the stack. */
7781 op = DW_OP_plus_uconst;
7784 loc_descr = new_loc_descr (op, offset, 0);
7785 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7788 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7789 does not have a "location" either in memory or in a register. These
7790 things can arise in GNU C when a constant is passed as an actual parameter
7791 to an inlined function. They can also arise in C++ where declared
7792 constants do not necessarily get memory "homes". */
7795 add_const_value_attribute (die, rtl)
7796 register dw_die_ref die;
7799 switch (GET_CODE (rtl))
7802 /* Note that a CONST_INT rtx could represent either an integer
7803 or a floating-point constant. A CONST_INT is used whenever
7804 the constant will fit into a single word. In all such
7805 cases, the original mode of the constant value is wiped
7806 out, and the CONST_INT rtx is assigned VOIDmode. */
7808 HOST_WIDE_INT val = INTVAL (rtl);
7810 /* ??? We really should be using HOST_WIDE_INT throughout. */
7813 if ((long) val != val)
7815 add_AT_int (die, DW_AT_const_value, (long) val);
7819 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
7821 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
7827 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7828 floating-point constant. A CONST_DOUBLE is used whenever the
7829 constant requires more than one word in order to be adequately
7830 represented. We output CONST_DOUBLEs as blocks. */
7832 register enum machine_mode mode = GET_MODE (rtl);
7834 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7836 register unsigned length = GET_MODE_SIZE (mode) / 4;
7837 long *array = (long *) xmalloc (sizeof (long) * length);
7840 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7844 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7848 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7853 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7860 add_AT_float (die, DW_AT_const_value, length, array);
7864 /* ??? We really should be using HOST_WIDE_INT throughout. */
7865 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
7867 add_AT_long_long (die, DW_AT_const_value,
7868 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7874 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7880 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7884 /* In cases where an inlined instance of an inline function is passed
7885 the address of an `auto' variable (which is local to the caller) we
7886 can get a situation where the DECL_RTL of the artificial local
7887 variable (for the inlining) which acts as a stand-in for the
7888 corresponding formal parameter (of the inline function) will look
7889 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7890 exactly a compile-time constant expression, but it isn't the address
7891 of the (artificial) local variable either. Rather, it represents the
7892 *value* which the artificial local variable always has during its
7893 lifetime. We currently have no way to represent such quasi-constant
7894 values in Dwarf, so for now we just punt and generate nothing. */
7898 /* No other kinds of rtx should be possible here. */
7905 rtl_for_decl_location (decl)
7910 /* Here we have to decide where we are going to say the parameter "lives"
7911 (as far as the debugger is concerned). We only have a couple of
7912 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7914 DECL_RTL normally indicates where the parameter lives during most of the
7915 activation of the function. If optimization is enabled however, this
7916 could be either NULL or else a pseudo-reg. Both of those cases indicate
7917 that the parameter doesn't really live anywhere (as far as the code
7918 generation parts of GCC are concerned) during most of the function's
7919 activation. That will happen (for example) if the parameter is never
7920 referenced within the function.
7922 We could just generate a location descriptor here for all non-NULL
7923 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7924 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7925 where DECL_RTL is NULL or is a pseudo-reg.
7927 Note however that we can only get away with using DECL_INCOMING_RTL as
7928 a backup substitute for DECL_RTL in certain limited cases. In cases
7929 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7930 we can be sure that the parameter was passed using the same type as it is
7931 declared to have within the function, and that its DECL_INCOMING_RTL
7932 points us to a place where a value of that type is passed.
7934 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7935 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7936 because in these cases DECL_INCOMING_RTL points us to a value of some
7937 type which is *different* from the type of the parameter itself. Thus,
7938 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7939 such cases, the debugger would end up (for example) trying to fetch a
7940 `float' from a place which actually contains the first part of a
7941 `double'. That would lead to really incorrect and confusing
7942 output at debug-time.
7944 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7945 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
7946 are a couple of exceptions however. On little-endian machines we can
7947 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
7948 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
7949 an integral type that is smaller than TREE_TYPE (decl). These cases arise
7950 when (on a little-endian machine) a non-prototyped function has a
7951 parameter declared to be of type `short' or `char'. In such cases,
7952 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
7953 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
7954 passed `int' value. If the debugger then uses that address to fetch
7955 a `short' or a `char' (on a little-endian machine) the result will be
7956 the correct data, so we allow for such exceptional cases below.
7958 Note that our goal here is to describe the place where the given formal
7959 parameter lives during most of the function's activation (i.e. between
7960 the end of the prologue and the start of the epilogue). We'll do that
7961 as best as we can. Note however that if the given formal parameter is
7962 modified sometime during the execution of the function, then a stack
7963 backtrace (at debug-time) will show the function as having been
7964 called with the *new* value rather than the value which was
7965 originally passed in. This happens rarely enough that it is not
7966 a major problem, but it *is* a problem, and I'd like to fix it.
7968 A future version of dwarf2out.c may generate two additional
7969 attributes for any given DW_TAG_formal_parameter DIE which will
7970 describe the "passed type" and the "passed location" for the
7971 given formal parameter in addition to the attributes we now
7972 generate to indicate the "declared type" and the "active
7973 location" for each parameter. This additional set of attributes
7974 could be used by debuggers for stack backtraces. Separately, note
7975 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
7976 NULL also. This happens (for example) for inlined-instances of
7977 inline function formal parameters which are never referenced.
7978 This really shouldn't be happening. All PARM_DECL nodes should
7979 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
7980 doesn't currently generate these values for inlined instances of
7981 inline function parameters, so when we see such cases, we are
7982 just out-of-luck for the time being (until integrate.c
7985 /* Use DECL_RTL as the "location" unless we find something better. */
7986 rtl = DECL_RTL (decl);
7988 if (TREE_CODE (decl) == PARM_DECL)
7990 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7992 tree declared_type = type_main_variant (TREE_TYPE (decl));
7993 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7995 /* This decl represents a formal parameter which was optimized out.
7996 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7997 all* cases where (rtl == NULL_RTX) just below. */
7998 if (declared_type == passed_type)
7999 rtl = DECL_INCOMING_RTL (decl);
8000 else if (! BYTES_BIG_ENDIAN
8001 && TREE_CODE (declared_type) == INTEGER_TYPE
8002 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8003 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8004 rtl = DECL_INCOMING_RTL (decl);
8007 /* If the parm was passed in registers, but lives on the stack, then
8008 make a big endian correction if the mode of the type of the
8009 parameter is not the same as the mode of the rtl. */
8010 /* ??? This is the same series of checks that are made in dbxout.c before
8011 we reach the big endian correction code there. It isn't clear if all
8012 of these checks are necessary here, but keeping them all is the safe
8014 else if (GET_CODE (rtl) == MEM
8015 && XEXP (rtl, 0) != const0_rtx
8016 && ! CONSTANT_P (XEXP (rtl, 0))
8017 /* Not passed in memory. */
8018 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8019 /* Not passed by invisible reference. */
8020 && (GET_CODE (XEXP (rtl, 0)) != REG
8021 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8022 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8023 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8024 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8027 /* Big endian correction check. */
8029 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8030 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8033 int offset = (UNITS_PER_WORD
8034 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8035 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8036 plus_constant (XEXP (rtl, 0), offset));
8040 if (rtl != NULL_RTX)
8042 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8043 #ifdef LEAF_REG_REMAP
8044 if (current_function_uses_only_leaf_regs)
8045 leaf_renumber_regs_insn (rtl);
8052 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8053 data attribute for a variable or a parameter. We generate the
8054 DW_AT_const_value attribute only in those cases where the given variable
8055 or parameter does not have a true "location" either in memory or in a
8056 register. This can happen (for example) when a constant is passed as an
8057 actual argument in a call to an inline function. (It's possible that
8058 these things can crop up in other ways also.) Note that one type of
8059 constant value which can be passed into an inlined function is a constant
8060 pointer. This can happen for example if an actual argument in an inlined
8061 function call evaluates to a compile-time constant address. */
8064 add_location_or_const_value_attribute (die, decl)
8065 register dw_die_ref die;
8070 if (TREE_CODE (decl) == ERROR_MARK)
8073 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8076 rtl = rtl_for_decl_location (decl);
8077 if (rtl == NULL_RTX)
8080 switch (GET_CODE (rtl))
8083 /* The address of a variable that was optimized away; don't emit
8094 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8095 add_const_value_attribute (die, rtl);
8102 add_AT_location_description (die, DW_AT_location, rtl);
8110 /* If we don't have a copy of this variable in memory for some reason (such
8111 as a C++ member constant that doesn't have an out-of-line definition),
8112 we should tell the debugger about the constant value. */
8115 tree_add_const_value_attribute (var_die, decl)
8119 tree init = DECL_INITIAL (decl);
8120 tree type = TREE_TYPE (decl);
8122 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8123 && initializer_constant_valid_p (init, type) == null_pointer_node)
8128 switch (TREE_CODE (type))
8131 if (host_integerp (init, 0))
8132 add_AT_unsigned (var_die, DW_AT_const_value,
8133 TREE_INT_CST_LOW (init));
8135 add_AT_long_long (var_die, DW_AT_const_value,
8136 TREE_INT_CST_HIGH (init),
8137 TREE_INT_CST_LOW (init));
8144 /* Generate an DW_AT_name attribute given some string value to be included as
8145 the value of the attribute. */
8148 add_name_attribute (die, name_string)
8149 register dw_die_ref die;
8150 register const char *name_string;
8152 if (name_string != NULL && *name_string != 0)
8154 if (demangle_name_func)
8155 name_string = (*demangle_name_func) (name_string);
8157 add_AT_string (die, DW_AT_name, name_string);
8161 /* Given a tree node describing an array bound (either lower or upper) output
8162 a representation for that bound. */
8165 add_bound_info (subrange_die, bound_attr, bound)
8166 register dw_die_ref subrange_die;
8167 register enum dwarf_attribute bound_attr;
8168 register tree bound;
8170 /* If this is an Ada unconstrained array type, then don't emit any debug
8171 info because the array bounds are unknown. They are parameterized when
8172 the type is instantiated. */
8173 if (contains_placeholder_p (bound))
8176 switch (TREE_CODE (bound))
8181 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8183 if (! host_integerp (bound, 0)
8184 || (bound_attr == DW_AT_lower_bound
8185 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8186 || (is_fortran () && integer_onep (bound)))))
8187 /* use the default */
8190 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8195 case NON_LVALUE_EXPR:
8196 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8200 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8201 access the upper bound values may be bogus. If they refer to a
8202 register, they may only describe how to get at these values at the
8203 points in the generated code right after they have just been
8204 computed. Worse yet, in the typical case, the upper bound values
8205 will not even *be* computed in the optimized code (though the
8206 number of elements will), so these SAVE_EXPRs are entirely
8207 bogus. In order to compensate for this fact, we check here to see
8208 if optimization is enabled, and if so, we don't add an attribute
8209 for the (unknown and unknowable) upper bound. This should not
8210 cause too much trouble for existing (stupid?) debuggers because
8211 they have to deal with empty upper bounds location descriptions
8212 anyway in order to be able to deal with incomplete array types.
8213 Of course an intelligent debugger (GDB?) should be able to
8214 comprehend that a missing upper bound specification in a array
8215 type used for a storage class `auto' local array variable
8216 indicates that the upper bound is both unknown (at compile- time)
8217 and unknowable (at run-time) due to optimization.
8219 We assume that a MEM rtx is safe because gcc wouldn't put the
8220 value there unless it was going to be used repeatedly in the
8221 function, i.e. for cleanups. */
8222 if (SAVE_EXPR_RTL (bound)
8223 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8225 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8226 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8227 register rtx loc = SAVE_EXPR_RTL (bound);
8229 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8230 it references an outer function's frame. */
8232 if (GET_CODE (loc) == MEM)
8234 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8236 if (XEXP (loc, 0) != new_addr)
8237 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8240 add_AT_flag (decl_die, DW_AT_artificial, 1);
8241 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8242 add_AT_location_description (decl_die, DW_AT_location, loc);
8243 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8246 /* Else leave out the attribute. */
8252 dw_die_ref decl_die = lookup_decl_die (bound);
8254 /* ??? Can this happen, or should the variable have been bound
8255 first? Probably it can, since I imagine that we try to create
8256 the types of parameters in the order in which they exist in
8257 the list, and won't have created a forward reference to a
8259 if (decl_die != NULL)
8260 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8266 /* Otherwise try to create a stack operation procedure to
8267 evaluate the value of the array bound. */
8269 dw_die_ref ctx, decl_die;
8270 dw_loc_descr_ref loc;
8272 loc = loc_descriptor_from_tree (bound, 0);
8276 ctx = lookup_decl_die (current_function_decl);
8278 decl_die = new_die (DW_TAG_variable, ctx);
8279 add_AT_flag (decl_die, DW_AT_artificial, 1);
8280 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8281 add_AT_loc (decl_die, DW_AT_location, loc);
8283 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8289 /* Note that the block of subscript information for an array type also
8290 includes information about the element type of type given array type. */
8293 add_subscript_info (type_die, type)
8294 register dw_die_ref type_die;
8297 #ifndef MIPS_DEBUGGING_INFO
8298 register unsigned dimension_number;
8300 register tree lower, upper;
8301 register dw_die_ref subrange_die;
8303 /* The GNU compilers represent multidimensional array types as sequences of
8304 one dimensional array types whose element types are themselves array
8305 types. Here we squish that down, so that each multidimensional array
8306 type gets only one array_type DIE in the Dwarf debugging info. The draft
8307 Dwarf specification say that we are allowed to do this kind of
8308 compression in C (because there is no difference between an array or
8309 arrays and a multidimensional array in C) but for other source languages
8310 (e.g. Ada) we probably shouldn't do this. */
8312 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8313 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8314 We work around this by disabling this feature. See also
8315 gen_array_type_die. */
8316 #ifndef MIPS_DEBUGGING_INFO
8317 for (dimension_number = 0;
8318 TREE_CODE (type) == ARRAY_TYPE;
8319 type = TREE_TYPE (type), dimension_number++)
8322 register tree domain = TYPE_DOMAIN (type);
8324 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8325 and (in GNU C only) variable bounds. Handle all three forms
8327 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8330 /* We have an array type with specified bounds. */
8331 lower = TYPE_MIN_VALUE (domain);
8332 upper = TYPE_MAX_VALUE (domain);
8334 /* define the index type. */
8335 if (TREE_TYPE (domain))
8337 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8338 TREE_TYPE field. We can't emit debug info for this
8339 because it is an unnamed integral type. */
8340 if (TREE_CODE (domain) == INTEGER_TYPE
8341 && TYPE_NAME (domain) == NULL_TREE
8342 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8343 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8346 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8350 /* ??? If upper is NULL, the array has unspecified length,
8351 but it does have a lower bound. This happens with Fortran
8353 Since the debugger is definitely going to need to know N
8354 to produce useful results, go ahead and output the lower
8355 bound solo, and hope the debugger can cope. */
8357 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8359 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8362 /* We have an array type with an unspecified length. The DWARF-2
8363 spec does not say how to handle this; let's just leave out the
8367 #ifndef MIPS_DEBUGGING_INFO
8373 add_byte_size_attribute (die, tree_node)
8375 register tree tree_node;
8377 register unsigned size;
8379 switch (TREE_CODE (tree_node))
8387 case QUAL_UNION_TYPE:
8388 size = int_size_in_bytes (tree_node);
8391 /* For a data member of a struct or union, the DW_AT_byte_size is
8392 generally given as the number of bytes normally allocated for an
8393 object of the *declared* type of the member itself. This is true
8394 even for bit-fields. */
8395 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8401 /* Note that `size' might be -1 when we get to this point. If it is, that
8402 indicates that the byte size of the entity in question is variable. We
8403 have no good way of expressing this fact in Dwarf at the present time,
8404 so just let the -1 pass on through. */
8406 add_AT_unsigned (die, DW_AT_byte_size, size);
8409 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8410 which specifies the distance in bits from the highest order bit of the
8411 "containing object" for the bit-field to the highest order bit of the
8414 For any given bit-field, the "containing object" is a hypothetical
8415 object (of some integral or enum type) within which the given bit-field
8416 lives. The type of this hypothetical "containing object" is always the
8417 same as the declared type of the individual bit-field itself. The
8418 determination of the exact location of the "containing object" for a
8419 bit-field is rather complicated. It's handled by the
8420 `field_byte_offset' function (above).
8422 Note that it is the size (in bytes) of the hypothetical "containing object"
8423 which will be given in the DW_AT_byte_size attribute for this bit-field.
8424 (See `byte_size_attribute' above). */
8427 add_bit_offset_attribute (die, decl)
8428 register dw_die_ref die;
8431 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8432 tree type = DECL_BIT_FIELD_TYPE (decl);
8433 HOST_WIDE_INT bitpos_int;
8434 HOST_WIDE_INT highest_order_object_bit_offset;
8435 HOST_WIDE_INT highest_order_field_bit_offset;
8436 HOST_WIDE_INT unsigned bit_offset;
8438 /* Must be a field and a bit field. */
8440 || TREE_CODE (decl) != FIELD_DECL)
8443 /* We can't yet handle bit-fields whose offsets are variable, so if we
8444 encounter such things, just return without generating any attribute
8445 whatsoever. Likewise for variable or too large size. */
8446 if (! host_integerp (bit_position (decl), 0)
8447 || ! host_integerp (DECL_SIZE (decl), 1))
8450 bitpos_int = int_bit_position (decl);
8452 /* Note that the bit offset is always the distance (in bits) from the
8453 highest-order bit of the "containing object" to the highest-order bit of
8454 the bit-field itself. Since the "high-order end" of any object or field
8455 is different on big-endian and little-endian machines, the computation
8456 below must take account of these differences. */
8457 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8458 highest_order_field_bit_offset = bitpos_int;
8460 if (! BYTES_BIG_ENDIAN)
8462 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8463 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8467 = (! BYTES_BIG_ENDIAN
8468 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8469 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8471 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8474 /* For a FIELD_DECL node which represents a bit field, output an attribute
8475 which specifies the length in bits of the given field. */
8478 add_bit_size_attribute (die, decl)
8479 register dw_die_ref die;
8482 /* Must be a field and a bit field. */
8483 if (TREE_CODE (decl) != FIELD_DECL
8484 || ! DECL_BIT_FIELD_TYPE (decl))
8487 if (host_integerp (DECL_SIZE (decl), 1))
8488 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8491 /* If the compiled language is ANSI C, then add a 'prototyped'
8492 attribute, if arg types are given for the parameters of a function. */
8495 add_prototyped_attribute (die, func_type)
8496 register dw_die_ref die;
8497 register tree func_type;
8499 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8500 && TYPE_ARG_TYPES (func_type) != NULL)
8501 add_AT_flag (die, DW_AT_prototyped, 1);
8504 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8505 by looking in either the type declaration or object declaration
8509 add_abstract_origin_attribute (die, origin)
8510 register dw_die_ref die;
8511 register tree origin;
8513 dw_die_ref origin_die = NULL;
8515 if (TREE_CODE (origin) != FUNCTION_DECL)
8517 /* We may have gotten separated from the block for the inlined
8518 function, if we're in an exception handler or some such; make
8519 sure that the abstract function has been written out.
8521 Doing this for nested functions is wrong, however; functions are
8522 distinct units, and our context might not even be inline. */
8525 fn = TYPE_STUB_DECL (fn);
8526 fn = decl_function_context (fn);
8528 dwarf2out_abstract_function (fn);
8531 if (DECL_P (origin))
8532 origin_die = lookup_decl_die (origin);
8533 else if (TYPE_P (origin))
8534 origin_die = lookup_type_die (origin);
8536 if (origin_die == NULL)
8539 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8542 /* We do not currently support the pure_virtual attribute. */
8545 add_pure_or_virtual_attribute (die, func_decl)
8546 register dw_die_ref die;
8547 register tree func_decl;
8549 if (DECL_VINDEX (func_decl))
8551 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8553 if (host_integerp (DECL_VINDEX (func_decl), 0))
8554 add_AT_loc (die, DW_AT_vtable_elem_location,
8555 new_loc_descr (DW_OP_constu,
8556 tree_low_cst (DECL_VINDEX (func_decl), 0),
8559 /* GNU extension: Record what type this method came from originally. */
8560 if (debug_info_level > DINFO_LEVEL_TERSE)
8561 add_AT_die_ref (die, DW_AT_containing_type,
8562 lookup_type_die (DECL_CONTEXT (func_decl)));
8566 /* Add source coordinate attributes for the given decl. */
8569 add_src_coords_attributes (die, decl)
8570 register dw_die_ref die;
8573 register unsigned file_index = lookup_filename (&decl_file_table,
8574 DECL_SOURCE_FILE (decl));
8576 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8577 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8580 /* Add an DW_AT_name attribute and source coordinate attribute for the
8581 given decl, but only if it actually has a name. */
8584 add_name_and_src_coords_attributes (die, decl)
8585 register dw_die_ref die;
8588 register tree decl_name;
8590 decl_name = DECL_NAME (decl);
8591 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8593 add_name_attribute (die, dwarf2_name (decl, 0));
8594 if (! DECL_ARTIFICIAL (decl))
8595 add_src_coords_attributes (die, decl);
8597 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8598 && TREE_PUBLIC (decl)
8599 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8600 && !DECL_ABSTRACT (decl))
8601 add_AT_string (die, DW_AT_MIPS_linkage_name,
8602 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8606 /* Push a new declaration scope. */
8609 push_decl_scope (scope)
8612 /* Make room in the decl_scope_table, if necessary. */
8613 if (decl_scope_table_allocated == decl_scope_depth)
8615 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8617 = (tree *) xrealloc (decl_scope_table,
8618 decl_scope_table_allocated * sizeof (tree));
8621 decl_scope_table[decl_scope_depth] = scope;
8625 /* Pop a declaration scope. */
8629 if (decl_scope_depth <= 0)
8634 /* Return the DIE for the scope that immediately contains this type.
8635 Non-named types get global scope. Named types nested in other
8636 types get their containing scope if it's open, or global scope
8637 otherwise. All other types (i.e. function-local named types) get
8638 the current active scope. */
8641 scope_die_for (t, context_die)
8643 register dw_die_ref context_die;
8645 register dw_die_ref scope_die = NULL;
8646 register tree containing_scope;
8649 /* Non-types always go in the current scope. */
8653 containing_scope = TYPE_CONTEXT (t);
8655 /* Ignore namespaces for the moment. */
8656 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8657 containing_scope = NULL_TREE;
8659 /* Ignore function type "scopes" from the C frontend. They mean that
8660 a tagged type is local to a parmlist of a function declarator, but
8661 that isn't useful to DWARF. */
8662 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8663 containing_scope = NULL_TREE;
8665 if (containing_scope == NULL_TREE)
8666 scope_die = comp_unit_die;
8667 else if (TYPE_P (containing_scope))
8669 /* For types, we can just look up the appropriate DIE. But
8670 first we check to see if we're in the middle of emitting it
8671 so we know where the new DIE should go. */
8673 for (i = decl_scope_depth - 1; i >= 0; --i)
8674 if (decl_scope_table[i] == containing_scope)
8679 if (debug_info_level > DINFO_LEVEL_TERSE
8680 && !TREE_ASM_WRITTEN (containing_scope))
8683 /* If none of the current dies are suitable, we get file scope. */
8684 scope_die = comp_unit_die;
8687 scope_die = lookup_type_die (containing_scope);
8690 scope_die = context_die;
8695 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8697 static inline int local_scope_p PARAMS ((dw_die_ref));
8699 local_scope_p (context_die)
8700 dw_die_ref context_die;
8702 for (; context_die; context_die = context_die->die_parent)
8703 if (context_die->die_tag == DW_TAG_inlined_subroutine
8704 || context_die->die_tag == DW_TAG_subprogram)
8709 /* Returns nonzero iff CONTEXT_DIE is a class. */
8711 static inline int class_scope_p PARAMS ((dw_die_ref));
8713 class_scope_p (context_die)
8714 dw_die_ref context_die;
8717 && (context_die->die_tag == DW_TAG_structure_type
8718 || context_die->die_tag == DW_TAG_union_type));
8721 /* Many forms of DIEs require a "type description" attribute. This
8722 routine locates the proper "type descriptor" die for the type given
8723 by 'type', and adds an DW_AT_type attribute below the given die. */
8726 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8727 register dw_die_ref object_die;
8729 register int decl_const;
8730 register int decl_volatile;
8731 register dw_die_ref context_die;
8733 register enum tree_code code = TREE_CODE (type);
8734 register dw_die_ref type_die = NULL;
8736 /* ??? If this type is an unnamed subrange type of an integral or
8737 floating-point type, use the inner type. This is because we have no
8738 support for unnamed types in base_type_die. This can happen if this is
8739 an Ada subrange type. Correct solution is emit a subrange type die. */
8740 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8741 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8742 type = TREE_TYPE (type), code = TREE_CODE (type);
8744 if (code == ERROR_MARK)
8747 /* Handle a special case. For functions whose return type is void, we
8748 generate *no* type attribute. (Note that no object may have type
8749 `void', so this only applies to function return types). */
8750 if (code == VOID_TYPE)
8753 type_die = modified_type_die (type,
8754 decl_const || TYPE_READONLY (type),
8755 decl_volatile || TYPE_VOLATILE (type),
8757 if (type_die != NULL)
8758 add_AT_die_ref (object_die, DW_AT_type, type_die);
8761 /* Given a tree pointer to a struct, class, union, or enum type node, return
8762 a pointer to the (string) tag name for the given type, or zero if the type
8763 was declared without a tag. */
8769 register const char *name = 0;
8771 if (TYPE_NAME (type) != 0)
8773 register tree t = 0;
8775 /* Find the IDENTIFIER_NODE for the type name. */
8776 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8777 t = TYPE_NAME (type);
8779 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8780 a TYPE_DECL node, regardless of whether or not a `typedef' was
8782 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8783 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8784 t = DECL_NAME (TYPE_NAME (type));
8786 /* Now get the name as a string, or invent one. */
8788 name = IDENTIFIER_POINTER (t);
8791 return (name == 0 || *name == '\0') ? 0 : name;
8794 /* Return the type associated with a data member, make a special check
8795 for bit field types. */
8798 member_declared_type (member)
8799 register tree member;
8801 return (DECL_BIT_FIELD_TYPE (member)
8802 ? DECL_BIT_FIELD_TYPE (member)
8803 : TREE_TYPE (member));
8806 /* Get the decl's label, as described by its RTL. This may be different
8807 from the DECL_NAME name used in the source file. */
8811 decl_start_label (decl)
8816 x = DECL_RTL (decl);
8817 if (GET_CODE (x) != MEM)
8821 if (GET_CODE (x) != SYMBOL_REF)
8824 fnname = XSTR (x, 0);
8829 /* These routines generate the internal representation of the DIE's for
8830 the compilation unit. Debugging information is collected by walking
8831 the declaration trees passed in from dwarf2out_decl(). */
8834 gen_array_type_die (type, context_die)
8836 register dw_die_ref context_die;
8838 register dw_die_ref scope_die = scope_die_for (type, context_die);
8839 register dw_die_ref array_die;
8840 register tree element_type;
8842 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8843 the inner array type comes before the outer array type. Thus we must
8844 call gen_type_die before we call new_die. See below also. */
8845 #ifdef MIPS_DEBUGGING_INFO
8846 gen_type_die (TREE_TYPE (type), context_die);
8849 array_die = new_die (DW_TAG_array_type, scope_die);
8852 /* We default the array ordering. SDB will probably do
8853 the right things even if DW_AT_ordering is not present. It's not even
8854 an issue until we start to get into multidimensional arrays anyway. If
8855 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8856 then we'll have to put the DW_AT_ordering attribute back in. (But if
8857 and when we find out that we need to put these in, we will only do so
8858 for multidimensional arrays. */
8859 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8862 #ifdef MIPS_DEBUGGING_INFO
8863 /* The SGI compilers handle arrays of unknown bound by setting
8864 AT_declaration and not emitting any subrange DIEs. */
8865 if (! TYPE_DOMAIN (type))
8866 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8869 add_subscript_info (array_die, type);
8871 add_name_attribute (array_die, type_tag (type));
8872 equate_type_number_to_die (type, array_die);
8874 /* Add representation of the type of the elements of this array type. */
8875 element_type = TREE_TYPE (type);
8877 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8878 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8879 We work around this by disabling this feature. See also
8880 add_subscript_info. */
8881 #ifndef MIPS_DEBUGGING_INFO
8882 while (TREE_CODE (element_type) == ARRAY_TYPE)
8883 element_type = TREE_TYPE (element_type);
8885 gen_type_die (element_type, context_die);
8888 add_type_attribute (array_die, element_type, 0, 0, context_die);
8892 gen_set_type_die (type, context_die)
8894 register dw_die_ref context_die;
8896 register dw_die_ref type_die
8897 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8899 equate_type_number_to_die (type, type_die);
8900 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8905 gen_entry_point_die (decl, context_die)
8907 register dw_die_ref context_die;
8909 register tree origin = decl_ultimate_origin (decl);
8910 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8912 add_abstract_origin_attribute (decl_die, origin);
8915 add_name_and_src_coords_attributes (decl_die, decl);
8916 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8920 if (DECL_ABSTRACT (decl))
8921 equate_decl_number_to_die (decl, decl_die);
8923 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8927 /* Remember a type in the incomplete_types_list. */
8930 add_incomplete_type (type)
8933 if (incomplete_types == incomplete_types_allocated)
8935 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8936 incomplete_types_list
8937 = (tree *) xrealloc (incomplete_types_list,
8938 sizeof (tree) * incomplete_types_allocated);
8941 incomplete_types_list[incomplete_types++] = type;
8944 /* Walk through the list of incomplete types again, trying once more to
8945 emit full debugging info for them. */
8948 retry_incomplete_types ()
8952 while (incomplete_types)
8955 type = incomplete_types_list[incomplete_types];
8956 gen_type_die (type, comp_unit_die);
8960 /* Generate a DIE to represent an inlined instance of an enumeration type. */
8963 gen_inlined_enumeration_type_die (type, context_die)
8965 register dw_die_ref context_die;
8967 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
8969 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8970 be incomplete and such types are not marked. */
8971 add_abstract_origin_attribute (type_die, type);
8974 /* Generate a DIE to represent an inlined instance of a structure type. */
8977 gen_inlined_structure_type_die (type, context_die)
8979 register dw_die_ref context_die;
8981 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
8983 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8984 be incomplete and such types are not marked. */
8985 add_abstract_origin_attribute (type_die, type);
8988 /* Generate a DIE to represent an inlined instance of a union type. */
8991 gen_inlined_union_type_die (type, context_die)
8993 register dw_die_ref context_die;
8995 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
8997 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
8998 be incomplete and such types are not marked. */
8999 add_abstract_origin_attribute (type_die, type);
9002 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9003 include all of the information about the enumeration values also. Each
9004 enumerated type name/value is listed as a child of the enumerated type
9008 gen_enumeration_type_die (type, context_die)
9010 register dw_die_ref context_die;
9012 register dw_die_ref type_die = lookup_type_die (type);
9014 if (type_die == NULL)
9016 type_die = new_die (DW_TAG_enumeration_type,
9017 scope_die_for (type, context_die));
9018 equate_type_number_to_die (type, type_die);
9019 add_name_attribute (type_die, type_tag (type));
9021 else if (! TYPE_SIZE (type))
9024 remove_AT (type_die, DW_AT_declaration);
9026 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9027 given enum type is incomplete, do not generate the DW_AT_byte_size
9028 attribute or the DW_AT_element_list attribute. */
9029 if (TYPE_SIZE (type))
9033 TREE_ASM_WRITTEN (type) = 1;
9034 add_byte_size_attribute (type_die, type);
9035 if (TYPE_STUB_DECL (type) != NULL_TREE)
9036 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9038 /* If the first reference to this type was as the return type of an
9039 inline function, then it may not have a parent. Fix this now. */
9040 if (type_die->die_parent == NULL)
9041 add_child_die (scope_die_for (type, context_die), type_die);
9043 for (link = TYPE_FIELDS (type);
9044 link != NULL; link = TREE_CHAIN (link))
9046 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9048 add_name_attribute (enum_die,
9049 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9051 if (host_integerp (TREE_VALUE (link), 0))
9053 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9054 add_AT_int (enum_die, DW_AT_const_value,
9055 tree_low_cst (TREE_VALUE (link), 0));
9057 add_AT_unsigned (enum_die, DW_AT_const_value,
9058 tree_low_cst (TREE_VALUE (link), 0));
9063 add_AT_flag (type_die, DW_AT_declaration, 1);
9066 /* Generate a DIE to represent either a real live formal parameter decl or to
9067 represent just the type of some formal parameter position in some function
9070 Note that this routine is a bit unusual because its argument may be a
9071 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9072 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9073 node. If it's the former then this function is being called to output a
9074 DIE to represent a formal parameter object (or some inlining thereof). If
9075 it's the latter, then this function is only being called to output a
9076 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9077 argument type of some subprogram type. */
9080 gen_formal_parameter_die (node, context_die)
9082 register dw_die_ref context_die;
9084 register dw_die_ref parm_die
9085 = new_die (DW_TAG_formal_parameter, context_die);
9086 register tree origin;
9088 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9091 origin = decl_ultimate_origin (node);
9093 add_abstract_origin_attribute (parm_die, origin);
9096 add_name_and_src_coords_attributes (parm_die, node);
9097 add_type_attribute (parm_die, TREE_TYPE (node),
9098 TREE_READONLY (node),
9099 TREE_THIS_VOLATILE (node),
9101 if (DECL_ARTIFICIAL (node))
9102 add_AT_flag (parm_die, DW_AT_artificial, 1);
9105 equate_decl_number_to_die (node, parm_die);
9106 if (! DECL_ABSTRACT (node))
9107 add_location_or_const_value_attribute (parm_die, node);
9112 /* We were called with some kind of a ..._TYPE node. */
9113 add_type_attribute (parm_die, node, 0, 0, context_die);
9123 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9124 at the end of an (ANSI prototyped) formal parameters list. */
9127 gen_unspecified_parameters_die (decl_or_type, context_die)
9128 register tree decl_or_type ATTRIBUTE_UNUSED;
9129 register dw_die_ref context_die;
9131 new_die (DW_TAG_unspecified_parameters, context_die);
9134 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9135 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9136 parameters as specified in some function type specification (except for
9137 those which appear as part of a function *definition*). */
9140 gen_formal_types_die (function_or_method_type, context_die)
9141 register tree function_or_method_type;
9142 register dw_die_ref context_die;
9145 register tree formal_type = NULL;
9146 register tree first_parm_type;
9149 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9151 arg = DECL_ARGUMENTS (function_or_method_type);
9152 function_or_method_type = TREE_TYPE (function_or_method_type);
9157 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9159 /* Make our first pass over the list of formal parameter types and output a
9160 DW_TAG_formal_parameter DIE for each one. */
9161 for (link = first_parm_type; link; )
9163 register dw_die_ref parm_die;
9165 formal_type = TREE_VALUE (link);
9166 if (formal_type == void_type_node)
9169 /* Output a (nameless) DIE to represent the formal parameter itself. */
9170 parm_die = gen_formal_parameter_die (formal_type, context_die);
9171 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9172 && link == first_parm_type)
9173 || (arg && DECL_ARTIFICIAL (arg)))
9174 add_AT_flag (parm_die, DW_AT_artificial, 1);
9176 link = TREE_CHAIN (link);
9178 arg = TREE_CHAIN (arg);
9181 /* If this function type has an ellipsis, add a
9182 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9183 if (formal_type != void_type_node)
9184 gen_unspecified_parameters_die (function_or_method_type, context_die);
9186 /* Make our second (and final) pass over the list of formal parameter types
9187 and output DIEs to represent those types (as necessary). */
9188 for (link = TYPE_ARG_TYPES (function_or_method_type);
9190 link = TREE_CHAIN (link))
9192 formal_type = TREE_VALUE (link);
9193 if (formal_type == void_type_node)
9196 gen_type_die (formal_type, context_die);
9200 /* We want to generate the DIE for TYPE so that we can generate the
9201 die for MEMBER, which has been defined; we will need to refer back
9202 to the member declaration nested within TYPE. If we're trying to
9203 generate minimal debug info for TYPE, processing TYPE won't do the
9204 trick; we need to attach the member declaration by hand. */
9207 gen_type_die_for_member (type, member, context_die)
9209 dw_die_ref context_die;
9211 gen_type_die (type, context_die);
9213 /* If we're trying to avoid duplicate debug info, we may not have
9214 emitted the member decl for this function. Emit it now. */
9215 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9216 && ! lookup_decl_die (member))
9218 if (decl_ultimate_origin (member))
9221 push_decl_scope (type);
9222 if (TREE_CODE (member) == FUNCTION_DECL)
9223 gen_subprogram_die (member, lookup_type_die (type));
9225 gen_variable_die (member, lookup_type_die (type));
9230 /* Generate the DWARF2 info for the "abstract" instance
9231 of a function which we may later generate inlined and/or
9232 out-of-line instances of. */
9235 dwarf2out_abstract_function (decl)
9238 register dw_die_ref old_die;
9241 int was_abstract = DECL_ABSTRACT (decl);
9243 /* Make sure we have the actual abstract inline, not a clone. */
9244 decl = DECL_ORIGIN (decl);
9246 old_die = lookup_decl_die (decl);
9247 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9248 /* We've already generated the abstract instance. */
9251 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9252 we don't get confused by DECL_ABSTRACT. */
9253 context = decl_class_context (decl);
9255 gen_type_die_for_member
9256 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9258 /* Pretend we've just finished compiling this function. */
9259 save_fn = current_function_decl;
9260 current_function_decl = decl;
9262 set_decl_abstract_flags (decl, 1);
9263 dwarf2out_decl (decl);
9265 set_decl_abstract_flags (decl, 0);
9267 current_function_decl = save_fn;
9270 /* Generate a DIE to represent a declared function (either file-scope or
9274 gen_subprogram_die (decl, context_die)
9276 register dw_die_ref context_die;
9278 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9279 register tree origin = decl_ultimate_origin (decl);
9280 register dw_die_ref subr_die;
9281 register rtx fp_reg;
9282 register tree fn_arg_types;
9283 register tree outer_scope;
9284 register dw_die_ref old_die = lookup_decl_die (decl);
9285 register int declaration = (current_function_decl != decl
9286 || class_scope_p (context_die));
9288 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9289 be true, if we started to generate the abstract instance of an inline,
9290 decided to output its containing class, and proceeded to emit the
9291 declaration of the inline from the member list for the class. In that
9292 case, `declaration' takes priority; we'll get back to the abstract
9293 instance when we're done with the class. */
9295 /* The class-scope declaration DIE must be the primary DIE. */
9296 if (origin && declaration && class_scope_p (context_die))
9305 if (declaration && ! local_scope_p (context_die))
9308 /* Fixup die_parent for the abstract instance of a nested
9310 if (old_die && old_die->die_parent == NULL)
9311 add_child_die (context_die, old_die);
9313 subr_die = new_die (DW_TAG_subprogram, context_die);
9314 add_abstract_origin_attribute (subr_die, origin);
9318 register unsigned file_index
9319 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
9321 if (!get_AT_flag (old_die, DW_AT_declaration)
9322 /* We can have a normal definition following an inline one in the
9323 case of redefinition of GNU C extern inlines.
9324 It seems reasonable to use AT_specification in this case. */
9325 && !get_AT_unsigned (old_die, DW_AT_inline))
9327 /* ??? This can happen if there is a bug in the program, for
9328 instance, if it has duplicate function definitions. Ideally,
9329 we should detect this case and ignore it. For now, if we have
9330 already reported an error, any error at all, then assume that
9331 we got here because of a input error, not a dwarf2 bug. */
9337 /* If the definition comes from the same place as the declaration,
9338 maybe use the old DIE. We always want the DIE for this function
9339 that has the *_pc attributes to be under comp_unit_die so the
9340 debugger can find it. We also need to do this for abstract
9341 instances of inlines, since the spec requires the out-of-line copy
9342 to have the same parent. For local class methods, this doesn't
9343 apply; we just use the old DIE. */
9344 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9345 && (DECL_ARTIFICIAL (decl)
9346 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9347 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9348 == (unsigned) DECL_SOURCE_LINE (decl)))))
9352 /* Clear out the declaration attribute and the parm types. */
9353 remove_AT (subr_die, DW_AT_declaration);
9354 remove_children (subr_die);
9358 subr_die = new_die (DW_TAG_subprogram, context_die);
9359 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9360 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9361 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9362 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9363 != (unsigned) DECL_SOURCE_LINE (decl))
9365 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9370 subr_die = new_die (DW_TAG_subprogram, context_die);
9372 if (TREE_PUBLIC (decl))
9373 add_AT_flag (subr_die, DW_AT_external, 1);
9375 add_name_and_src_coords_attributes (subr_die, decl);
9376 if (debug_info_level > DINFO_LEVEL_TERSE)
9378 register tree type = TREE_TYPE (decl);
9380 add_prototyped_attribute (subr_die, type);
9381 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9384 add_pure_or_virtual_attribute (subr_die, decl);
9385 if (DECL_ARTIFICIAL (decl))
9386 add_AT_flag (subr_die, DW_AT_artificial, 1);
9387 if (TREE_PROTECTED (decl))
9388 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9389 else if (TREE_PRIVATE (decl))
9390 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9395 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9397 add_AT_flag (subr_die, DW_AT_declaration, 1);
9399 /* The first time we see a member function, it is in the context of
9400 the class to which it belongs. We make sure of this by emitting
9401 the class first. The next time is the definition, which is
9402 handled above. The two may come from the same source text. */
9403 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9404 equate_decl_number_to_die (decl, subr_die);
9407 else if (DECL_ABSTRACT (decl))
9409 if (DECL_INLINE (decl) && !flag_no_inline)
9411 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9412 inline functions, but not for extern inline functions.
9413 We can't get this completely correct because information
9414 about whether the function was declared inline is not
9416 if (DECL_DEFER_OUTPUT (decl))
9417 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9419 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9422 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9424 equate_decl_number_to_die (decl, subr_die);
9426 else if (!DECL_EXTERNAL (decl))
9428 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9429 equate_decl_number_to_die (decl, subr_die);
9431 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9432 current_funcdef_number);
9433 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9434 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9435 current_funcdef_number);
9436 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9438 add_pubname (decl, subr_die);
9439 add_arange (decl, subr_die);
9441 #ifdef MIPS_DEBUGGING_INFO
9442 /* Add a reference to the FDE for this routine. */
9443 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9446 /* Define the "frame base" location for this routine. We use the
9447 frame pointer or stack pointer registers, since the RTL for local
9448 variables is relative to one of them. */
9450 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9451 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9454 /* ??? This fails for nested inline functions, because context_display
9455 is not part of the state saved/restored for inline functions. */
9456 if (current_function_needs_context)
9457 add_AT_location_description (subr_die, DW_AT_static_link,
9458 lookup_static_chain (decl));
9462 /* Now output descriptions of the arguments for this function. This gets
9463 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9464 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9465 `...' at the end of the formal parameter list. In order to find out if
9466 there was a trailing ellipsis or not, we must instead look at the type
9467 associated with the FUNCTION_DECL. This will be a node of type
9468 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9469 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9470 an ellipsis at the end. */
9472 /* In the case where we are describing a mere function declaration, all we
9473 need to do here (and all we *can* do here) is to describe the *types* of
9474 its formal parameters. */
9475 if (debug_info_level <= DINFO_LEVEL_TERSE)
9477 else if (declaration)
9478 gen_formal_types_die (decl, subr_die);
9481 /* Generate DIEs to represent all known formal parameters */
9482 register tree arg_decls = DECL_ARGUMENTS (decl);
9485 /* When generating DIEs, generate the unspecified_parameters DIE
9486 instead if we come across the arg "__builtin_va_alist" */
9487 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9488 if (TREE_CODE (parm) == PARM_DECL)
9490 if (DECL_NAME (parm)
9491 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9492 "__builtin_va_alist"))
9493 gen_unspecified_parameters_die (parm, subr_die);
9495 gen_decl_die (parm, subr_die);
9498 /* Decide whether we need a unspecified_parameters DIE at the end.
9499 There are 2 more cases to do this for: 1) the ansi ... declaration -
9500 this is detectable when the end of the arg list is not a
9501 void_type_node 2) an unprototyped function declaration (not a
9502 definition). This just means that we have no info about the
9503 parameters at all. */
9504 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9505 if (fn_arg_types != NULL)
9507 /* this is the prototyped case, check for ... */
9508 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9509 gen_unspecified_parameters_die (decl, subr_die);
9511 else if (DECL_INITIAL (decl) == NULL_TREE)
9512 gen_unspecified_parameters_die (decl, subr_die);
9515 /* Output Dwarf info for all of the stuff within the body of the function
9516 (if it has one - it may be just a declaration). */
9517 outer_scope = DECL_INITIAL (decl);
9519 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9520 node created to represent a function. This outermost BLOCK actually
9521 represents the outermost binding contour for the function, i.e. the
9522 contour in which the function's formal parameters and labels get
9523 declared. Curiously, it appears that the front end doesn't actually
9524 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9525 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9526 list for the function instead.) The BLOCK_VARS list for the
9527 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9528 the function however, and we output DWARF info for those in
9529 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9530 node representing the function's outermost pair of curly braces, and
9531 any blocks used for the base and member initializers of a C++
9532 constructor function. */
9533 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9535 current_function_has_inlines = 0;
9536 decls_for_scope (outer_scope, subr_die, 0);
9538 #if 0 && defined (MIPS_DEBUGGING_INFO)
9539 if (current_function_has_inlines)
9541 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9542 if (! comp_unit_has_inlines)
9544 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9545 comp_unit_has_inlines = 1;
9552 /* Generate a DIE to represent a declared data object. */
9555 gen_variable_die (decl, context_die)
9557 register dw_die_ref context_die;
9559 register tree origin = decl_ultimate_origin (decl);
9560 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9562 dw_die_ref old_die = lookup_decl_die (decl);
9563 int declaration = (DECL_EXTERNAL (decl)
9564 || class_scope_p (context_die));
9567 add_abstract_origin_attribute (var_die, origin);
9568 /* Loop unrolling can create multiple blocks that refer to the same
9569 static variable, so we must test for the DW_AT_declaration flag. */
9570 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9571 copy decls and set the DECL_ABSTRACT flag on them instead of
9573 else if (old_die && TREE_STATIC (decl)
9574 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9576 /* This is a definition of a C++ class level static. */
9577 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9578 if (DECL_NAME (decl))
9580 register unsigned file_index
9581 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
9583 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9584 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9586 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9587 != (unsigned) DECL_SOURCE_LINE (decl))
9589 add_AT_unsigned (var_die, DW_AT_decl_line,
9590 DECL_SOURCE_LINE (decl));
9595 add_name_and_src_coords_attributes (var_die, decl);
9596 add_type_attribute (var_die, TREE_TYPE (decl),
9597 TREE_READONLY (decl),
9598 TREE_THIS_VOLATILE (decl), context_die);
9600 if (TREE_PUBLIC (decl))
9601 add_AT_flag (var_die, DW_AT_external, 1);
9603 if (DECL_ARTIFICIAL (decl))
9604 add_AT_flag (var_die, DW_AT_artificial, 1);
9606 if (TREE_PROTECTED (decl))
9607 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9609 else if (TREE_PRIVATE (decl))
9610 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9614 add_AT_flag (var_die, DW_AT_declaration, 1);
9616 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9617 equate_decl_number_to_die (decl, var_die);
9619 if (! declaration && ! DECL_ABSTRACT (decl))
9621 add_location_or_const_value_attribute (var_die, decl);
9622 add_pubname (decl, var_die);
9625 tree_add_const_value_attribute (var_die, decl);
9628 /* Generate a DIE to represent a label identifier. */
9631 gen_label_die (decl, context_die)
9633 register dw_die_ref context_die;
9635 register tree origin = decl_ultimate_origin (decl);
9636 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9638 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9641 add_abstract_origin_attribute (lbl_die, origin);
9643 add_name_and_src_coords_attributes (lbl_die, decl);
9645 if (DECL_ABSTRACT (decl))
9646 equate_decl_number_to_die (decl, lbl_die);
9649 insn = DECL_RTL (decl);
9651 /* Deleted labels are programmer specified labels which have been
9652 eliminated because of various optimisations. We still emit them
9653 here so that it is possible to put breakpoints on them. */
9654 if (GET_CODE (insn) == CODE_LABEL
9655 || ((GET_CODE (insn) == NOTE
9656 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9658 /* When optimization is enabled (via -O) some parts of the compiler
9659 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9660 represent source-level labels which were explicitly declared by
9661 the user. This really shouldn't be happening though, so catch
9662 it if it ever does happen. */
9663 if (INSN_DELETED_P (insn))
9666 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9667 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9672 /* Generate a DIE for a lexical block. */
9675 gen_lexical_block_die (stmt, context_die, depth)
9677 register dw_die_ref context_die;
9680 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9681 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9683 if (! BLOCK_ABSTRACT (stmt))
9685 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9686 BLOCK_NUMBER (stmt));
9687 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9688 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9689 BLOCK_NUMBER (stmt));
9690 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9693 decls_for_scope (stmt, stmt_die, depth);
9696 /* Generate a DIE for an inlined subprogram. */
9699 gen_inlined_subroutine_die (stmt, context_die, depth)
9701 register dw_die_ref context_die;
9704 if (! BLOCK_ABSTRACT (stmt))
9706 register dw_die_ref subr_die
9707 = new_die (DW_TAG_inlined_subroutine, context_die);
9708 register tree decl = block_ultimate_origin (stmt);
9709 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9711 /* Emit info for the abstract instance first, if we haven't yet. */
9712 dwarf2out_abstract_function (decl);
9714 add_abstract_origin_attribute (subr_die, decl);
9715 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9716 BLOCK_NUMBER (stmt));
9717 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9718 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9719 BLOCK_NUMBER (stmt));
9720 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9721 decls_for_scope (stmt, subr_die, depth);
9722 current_function_has_inlines = 1;
9726 /* Generate a DIE for a field in a record, or structure. */
9729 gen_field_die (decl, context_die)
9731 register dw_die_ref context_die;
9733 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9735 add_name_and_src_coords_attributes (decl_die, decl);
9736 add_type_attribute (decl_die, member_declared_type (decl),
9737 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9740 /* If this is a bit field... */
9741 if (DECL_BIT_FIELD_TYPE (decl))
9743 add_byte_size_attribute (decl_die, decl);
9744 add_bit_size_attribute (decl_die, decl);
9745 add_bit_offset_attribute (decl_die, decl);
9748 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9749 add_data_member_location_attribute (decl_die, decl);
9751 if (DECL_ARTIFICIAL (decl))
9752 add_AT_flag (decl_die, DW_AT_artificial, 1);
9754 if (TREE_PROTECTED (decl))
9755 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9757 else if (TREE_PRIVATE (decl))
9758 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9762 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9763 Use modified_type_die instead.
9764 We keep this code here just in case these types of DIEs may be needed to
9765 represent certain things in other languages (e.g. Pascal) someday. */
9767 gen_pointer_type_die (type, context_die)
9769 register dw_die_ref context_die;
9771 register dw_die_ref ptr_die
9772 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9774 equate_type_number_to_die (type, ptr_die);
9775 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9776 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9779 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9780 Use modified_type_die instead.
9781 We keep this code here just in case these types of DIEs may be needed to
9782 represent certain things in other languages (e.g. Pascal) someday. */
9784 gen_reference_type_die (type, context_die)
9786 register dw_die_ref context_die;
9788 register dw_die_ref ref_die
9789 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9791 equate_type_number_to_die (type, ref_die);
9792 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9793 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9797 /* Generate a DIE for a pointer to a member type. */
9799 gen_ptr_to_mbr_type_die (type, context_die)
9801 register dw_die_ref context_die;
9803 register dw_die_ref ptr_die
9804 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9806 equate_type_number_to_die (type, ptr_die);
9807 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9808 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9809 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9812 /* Generate the DIE for the compilation unit. */
9815 gen_compile_unit_die (filename)
9816 register const char *filename;
9818 register dw_die_ref die;
9820 const char *wd = getpwd ();
9823 die = new_die (DW_TAG_compile_unit, NULL);
9824 add_name_attribute (die, filename);
9826 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9827 add_AT_string (die, DW_AT_comp_dir, wd);
9829 sprintf (producer, "%s %s", language_string, version_string);
9831 #ifdef MIPS_DEBUGGING_INFO
9832 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9833 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9834 not appear in the producer string, the debugger reaches the conclusion
9835 that the object file is stripped and has no debugging information.
9836 To get the MIPS/SGI debugger to believe that there is debugging
9837 information in the object file, we add a -g to the producer string. */
9838 if (debug_info_level > DINFO_LEVEL_TERSE)
9839 strcat (producer, " -g");
9842 add_AT_string (die, DW_AT_producer, producer);
9844 if (strcmp (language_string, "GNU C++") == 0)
9845 language = DW_LANG_C_plus_plus;
9846 else if (strcmp (language_string, "GNU Ada") == 0)
9847 language = DW_LANG_Ada83;
9848 else if (strcmp (language_string, "GNU F77") == 0)
9849 language = DW_LANG_Fortran77;
9850 else if (strcmp (language_string, "GNU Pascal") == 0)
9851 language = DW_LANG_Pascal83;
9852 else if (strcmp (language_string, "GNU Java") == 0)
9853 language = DW_LANG_Java;
9854 else if (flag_traditional)
9855 language = DW_LANG_C;
9857 language = DW_LANG_C89;
9859 add_AT_unsigned (die, DW_AT_language, language);
9864 /* Generate a DIE for a string type. */
9867 gen_string_type_die (type, context_die)
9869 register dw_die_ref context_die;
9871 register dw_die_ref type_die
9872 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9874 equate_type_number_to_die (type, type_die);
9876 /* Fudge the string length attribute for now. */
9878 /* TODO: add string length info.
9879 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9880 bound_representation (upper_bound, 0, 'u'); */
9883 /* Generate the DIE for a base class. */
9886 gen_inheritance_die (binfo, context_die)
9887 register tree binfo;
9888 register dw_die_ref context_die;
9890 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9892 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9893 add_data_member_location_attribute (die, binfo);
9895 if (TREE_VIA_VIRTUAL (binfo))
9896 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9897 if (TREE_VIA_PUBLIC (binfo))
9898 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9899 else if (TREE_VIA_PROTECTED (binfo))
9900 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9903 /* Generate a DIE for a class member. */
9906 gen_member_die (type, context_die)
9908 register dw_die_ref context_die;
9910 register tree member;
9913 /* If this is not an incomplete type, output descriptions of each of its
9914 members. Note that as we output the DIEs necessary to represent the
9915 members of this record or union type, we will also be trying to output
9916 DIEs to represent the *types* of those members. However the `type'
9917 function (above) will specifically avoid generating type DIEs for member
9918 types *within* the list of member DIEs for this (containing) type execpt
9919 for those types (of members) which are explicitly marked as also being
9920 members of this (containing) type themselves. The g++ front- end can
9921 force any given type to be treated as a member of some other
9922 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9923 to point to the TREE node representing the appropriate (containing)
9926 /* First output info about the base classes. */
9927 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9929 register tree bases = TYPE_BINFO_BASETYPES (type);
9930 register int n_bases = TREE_VEC_LENGTH (bases);
9933 for (i = 0; i < n_bases; i++)
9934 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9937 /* Now output info about the data members and type members. */
9938 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9940 /* If we thought we were generating minimal debug info for TYPE
9941 and then changed our minds, some of the member declarations
9942 may have already been defined. Don't define them again, but
9943 do put them in the right order. */
9945 child = lookup_decl_die (member);
9947 splice_child_die (context_die, child);
9949 gen_decl_die (member, context_die);
9952 /* Now output info about the function members (if any). */
9953 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
9955 /* Don't include clones in the member list. */
9956 if (DECL_ABSTRACT_ORIGIN (member))
9959 child = lookup_decl_die (member);
9961 splice_child_die (context_die, child);
9963 gen_decl_die (member, context_die);
9967 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
9968 is set, we pretend that the type was never defined, so we only get the
9969 member DIEs needed by later specification DIEs. */
9972 gen_struct_or_union_type_die (type, context_die)
9974 register dw_die_ref context_die;
9976 register dw_die_ref type_die = lookup_type_die (type);
9977 register dw_die_ref scope_die = 0;
9978 register int nested = 0;
9979 int complete = (TYPE_SIZE (type)
9980 && (! TYPE_STUB_DECL (type)
9981 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
9983 if (type_die && ! complete)
9986 if (TYPE_CONTEXT (type) != NULL_TREE
9987 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
9990 scope_die = scope_die_for (type, context_die);
9992 if (! type_die || (nested && scope_die == comp_unit_die))
9993 /* First occurrence of type or toplevel definition of nested class. */
9995 register dw_die_ref old_die = type_die;
9997 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
9998 ? DW_TAG_structure_type : DW_TAG_union_type,
10000 equate_type_number_to_die (type, type_die);
10002 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10004 add_name_attribute (type_die, type_tag (type));
10007 remove_AT (type_die, DW_AT_declaration);
10009 /* If this type has been completed, then give it a byte_size attribute and
10010 then give a list of members. */
10013 /* Prevent infinite recursion in cases where the type of some member of
10014 this type is expressed in terms of this type itself. */
10015 TREE_ASM_WRITTEN (type) = 1;
10016 add_byte_size_attribute (type_die, type);
10017 if (TYPE_STUB_DECL (type) != NULL_TREE)
10018 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10020 /* If the first reference to this type was as the return type of an
10021 inline function, then it may not have a parent. Fix this now. */
10022 if (type_die->die_parent == NULL)
10023 add_child_die (scope_die, type_die);
10025 push_decl_scope (type);
10026 gen_member_die (type, type_die);
10029 /* GNU extension: Record what type our vtable lives in. */
10030 if (TYPE_VFIELD (type))
10032 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10034 gen_type_die (vtype, context_die);
10035 add_AT_die_ref (type_die, DW_AT_containing_type,
10036 lookup_type_die (vtype));
10041 add_AT_flag (type_die, DW_AT_declaration, 1);
10043 /* We don't need to do this for function-local types. */
10044 if (! decl_function_context (TYPE_STUB_DECL (type)))
10045 add_incomplete_type (type);
10049 /* Generate a DIE for a subroutine _type_. */
10052 gen_subroutine_type_die (type, context_die)
10053 register tree type;
10054 register dw_die_ref context_die;
10056 register tree return_type = TREE_TYPE (type);
10057 register dw_die_ref subr_die
10058 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10060 equate_type_number_to_die (type, subr_die);
10061 add_prototyped_attribute (subr_die, type);
10062 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10063 gen_formal_types_die (type, subr_die);
10066 /* Generate a DIE for a type definition */
10069 gen_typedef_die (decl, context_die)
10070 register tree decl;
10071 register dw_die_ref context_die;
10073 register dw_die_ref type_die;
10074 register tree origin;
10076 if (TREE_ASM_WRITTEN (decl))
10078 TREE_ASM_WRITTEN (decl) = 1;
10080 type_die = new_die (DW_TAG_typedef, context_die);
10081 origin = decl_ultimate_origin (decl);
10082 if (origin != NULL)
10083 add_abstract_origin_attribute (type_die, origin);
10086 register tree type;
10087 add_name_and_src_coords_attributes (type_die, decl);
10088 if (DECL_ORIGINAL_TYPE (decl))
10090 type = DECL_ORIGINAL_TYPE (decl);
10092 if (type == TREE_TYPE (decl))
10095 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10098 type = TREE_TYPE (decl);
10099 add_type_attribute (type_die, type, TREE_READONLY (decl),
10100 TREE_THIS_VOLATILE (decl), context_die);
10103 if (DECL_ABSTRACT (decl))
10104 equate_decl_number_to_die (decl, type_die);
10107 /* Generate a type description DIE. */
10110 gen_type_die (type, context_die)
10111 register tree type;
10112 register dw_die_ref context_die;
10116 if (type == NULL_TREE || type == error_mark_node)
10119 /* We are going to output a DIE to represent the unqualified version of
10120 this type (i.e. without any const or volatile qualifiers) so get the
10121 main variant (i.e. the unqualified version) of this type now. */
10122 type = type_main_variant (type);
10124 if (TREE_ASM_WRITTEN (type))
10127 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10128 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10130 TREE_ASM_WRITTEN (type) = 1;
10131 gen_decl_die (TYPE_NAME (type), context_die);
10135 switch (TREE_CODE (type))
10141 case REFERENCE_TYPE:
10142 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10143 ensures that the gen_type_die recursion will terminate even if the
10144 type is recursive. Recursive types are possible in Ada. */
10145 /* ??? We could perhaps do this for all types before the switch
10147 TREE_ASM_WRITTEN (type) = 1;
10149 /* For these types, all that is required is that we output a DIE (or a
10150 set of DIEs) to represent the "basis" type. */
10151 gen_type_die (TREE_TYPE (type), context_die);
10155 /* This code is used for C++ pointer-to-data-member types.
10156 Output a description of the relevant class type. */
10157 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10159 /* Output a description of the type of the object pointed to. */
10160 gen_type_die (TREE_TYPE (type), context_die);
10162 /* Now output a DIE to represent this pointer-to-data-member type
10164 gen_ptr_to_mbr_type_die (type, context_die);
10168 gen_type_die (TYPE_DOMAIN (type), context_die);
10169 gen_set_type_die (type, context_die);
10173 gen_type_die (TREE_TYPE (type), context_die);
10174 abort (); /* No way to represent these in Dwarf yet! */
10177 case FUNCTION_TYPE:
10178 /* Force out return type (in case it wasn't forced out already). */
10179 gen_type_die (TREE_TYPE (type), context_die);
10180 gen_subroutine_type_die (type, context_die);
10184 /* Force out return type (in case it wasn't forced out already). */
10185 gen_type_die (TREE_TYPE (type), context_die);
10186 gen_subroutine_type_die (type, context_die);
10190 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10192 gen_type_die (TREE_TYPE (type), context_die);
10193 gen_string_type_die (type, context_die);
10196 gen_array_type_die (type, context_die);
10200 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10203 case ENUMERAL_TYPE:
10206 case QUAL_UNION_TYPE:
10207 /* If this is a nested type whose containing class hasn't been
10208 written out yet, writing it out will cover this one, too.
10209 This does not apply to instantiations of member class templates;
10210 they need to be added to the containing class as they are
10211 generated. FIXME: This hurts the idea of combining type decls
10212 from multiple TUs, since we can't predict what set of template
10213 instantiations we'll get. */
10214 if (TYPE_CONTEXT (type)
10215 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10216 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10218 gen_type_die (TYPE_CONTEXT (type), context_die);
10220 if (TREE_ASM_WRITTEN (type))
10223 /* If that failed, attach ourselves to the stub. */
10224 push_decl_scope (TYPE_CONTEXT (type));
10225 context_die = lookup_type_die (TYPE_CONTEXT (type));
10231 if (TREE_CODE (type) == ENUMERAL_TYPE)
10232 gen_enumeration_type_die (type, context_die);
10234 gen_struct_or_union_type_die (type, context_die);
10239 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10240 it up if it is ever completed. gen_*_type_die will set it for us
10241 when appropriate. */
10250 /* No DIEs needed for fundamental types. */
10254 /* No Dwarf representation currently defined. */
10261 TREE_ASM_WRITTEN (type) = 1;
10264 /* Generate a DIE for a tagged type instantiation. */
10267 gen_tagged_type_instantiation_die (type, context_die)
10268 register tree type;
10269 register dw_die_ref context_die;
10271 if (type == NULL_TREE || type == error_mark_node)
10274 /* We are going to output a DIE to represent the unqualified version of
10275 this type (i.e. without any const or volatile qualifiers) so make sure
10276 that we have the main variant (i.e. the unqualified version) of this
10278 if (type != type_main_variant (type))
10281 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10282 an instance of an unresolved type. */
10284 switch (TREE_CODE (type))
10289 case ENUMERAL_TYPE:
10290 gen_inlined_enumeration_type_die (type, context_die);
10294 gen_inlined_structure_type_die (type, context_die);
10298 case QUAL_UNION_TYPE:
10299 gen_inlined_union_type_die (type, context_die);
10307 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10308 things which are local to the given block. */
10311 gen_block_die (stmt, context_die, depth)
10312 register tree stmt;
10313 register dw_die_ref context_die;
10316 register int must_output_die = 0;
10317 register tree origin;
10318 register tree decl;
10319 register enum tree_code origin_code;
10321 /* Ignore blocks never really used to make RTL. */
10323 if (stmt == NULL_TREE || !TREE_USED (stmt)
10324 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10327 /* Determine the "ultimate origin" of this block. This block may be an
10328 inlined instance of an inlined instance of inline function, so we have
10329 to trace all of the way back through the origin chain to find out what
10330 sort of node actually served as the original seed for the creation of
10331 the current block. */
10332 origin = block_ultimate_origin (stmt);
10333 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10335 /* Determine if we need to output any Dwarf DIEs at all to represent this
10337 if (origin_code == FUNCTION_DECL)
10338 /* The outer scopes for inlinings *must* always be represented. We
10339 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10340 must_output_die = 1;
10343 /* In the case where the current block represents an inlining of the
10344 "body block" of an inline function, we must *NOT* output any DIE for
10345 this block because we have already output a DIE to represent the
10346 whole inlined function scope and the "body block" of any function
10347 doesn't really represent a different scope according to ANSI C
10348 rules. So we check here to make sure that this block does not
10349 represent a "body block inlining" before trying to set the
10350 `must_output_die' flag. */
10351 if (! is_body_block (origin ? origin : stmt))
10353 /* Determine if this block directly contains any "significant"
10354 local declarations which we will need to output DIEs for. */
10355 if (debug_info_level > DINFO_LEVEL_TERSE)
10356 /* We are not in terse mode so *any* local declaration counts
10357 as being a "significant" one. */
10358 must_output_die = (BLOCK_VARS (stmt) != NULL);
10360 /* We are in terse mode, so only local (nested) function
10361 definitions count as "significant" local declarations. */
10362 for (decl = BLOCK_VARS (stmt);
10363 decl != NULL; decl = TREE_CHAIN (decl))
10364 if (TREE_CODE (decl) == FUNCTION_DECL
10365 && DECL_INITIAL (decl))
10367 must_output_die = 1;
10373 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10374 DIE for any block which contains no significant local declarations at
10375 all. Rather, in such cases we just call `decls_for_scope' so that any
10376 needed Dwarf info for any sub-blocks will get properly generated. Note
10377 that in terse mode, our definition of what constitutes a "significant"
10378 local declaration gets restricted to include only inlined function
10379 instances and local (nested) function definitions. */
10380 if (must_output_die)
10382 if (origin_code == FUNCTION_DECL)
10383 gen_inlined_subroutine_die (stmt, context_die, depth);
10385 gen_lexical_block_die (stmt, context_die, depth);
10388 decls_for_scope (stmt, context_die, depth);
10391 /* Generate all of the decls declared within a given scope and (recursively)
10392 all of its sub-blocks. */
10395 decls_for_scope (stmt, context_die, depth)
10396 register tree stmt;
10397 register dw_die_ref context_die;
10400 register tree decl;
10401 register tree subblocks;
10403 /* Ignore blocks never really used to make RTL. */
10404 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10407 /* Output the DIEs to represent all of the data objects and typedefs
10408 declared directly within this block but not within any nested
10409 sub-blocks. Also, nested function and tag DIEs have been
10410 generated with a parent of NULL; fix that up now. */
10411 for (decl = BLOCK_VARS (stmt);
10412 decl != NULL; decl = TREE_CHAIN (decl))
10414 register dw_die_ref die;
10416 if (TREE_CODE (decl) == FUNCTION_DECL)
10417 die = lookup_decl_die (decl);
10418 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10419 die = lookup_type_die (TREE_TYPE (decl));
10423 if (die != NULL && die->die_parent == NULL)
10424 add_child_die (context_die, die);
10426 gen_decl_die (decl, context_die);
10429 /* Output the DIEs to represent all sub-blocks (and the items declared
10430 therein) of this block. */
10431 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10433 subblocks = BLOCK_CHAIN (subblocks))
10434 gen_block_die (subblocks, context_die, depth + 1);
10437 /* Is this a typedef we can avoid emitting? */
10440 is_redundant_typedef (decl)
10441 register tree decl;
10443 if (TYPE_DECL_IS_STUB (decl))
10446 if (DECL_ARTIFICIAL (decl)
10447 && DECL_CONTEXT (decl)
10448 && is_tagged_type (DECL_CONTEXT (decl))
10449 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10450 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10451 /* Also ignore the artificial member typedef for the class name. */
10457 /* Generate Dwarf debug information for a decl described by DECL. */
10460 gen_decl_die (decl, context_die)
10461 register tree decl;
10462 register dw_die_ref context_die;
10464 register tree origin;
10466 if (TREE_CODE (decl) == ERROR_MARK)
10469 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10470 if (DECL_IGNORED_P (decl))
10473 switch (TREE_CODE (decl))
10476 /* The individual enumerators of an enum type get output when we output
10477 the Dwarf representation of the relevant enum type itself. */
10480 case FUNCTION_DECL:
10481 /* Don't output any DIEs to represent mere function declarations,
10482 unless they are class members or explicit block externs. */
10483 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10484 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10487 /* If we're emitting a clone, emit info for the abstract instance. */
10488 if (DECL_ORIGIN (decl) != decl)
10489 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10490 /* If we're emitting an out-of-line copy of an inline function,
10491 emit info for the abstract instance and set up to refer to it. */
10492 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10493 && ! class_scope_p (context_die)
10494 /* dwarf2out_abstract_function won't emit a die if this is just
10495 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10496 that case, because that works only if we have a die. */
10497 && DECL_INITIAL (decl) != NULL_TREE)
10499 dwarf2out_abstract_function (decl);
10500 set_decl_origin_self (decl);
10502 /* Otherwise we're emitting the primary DIE for this decl. */
10503 else if (debug_info_level > DINFO_LEVEL_TERSE)
10505 /* Before we describe the FUNCTION_DECL itself, make sure that we
10506 have described its return type. */
10507 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10509 /* And its virtual context. */
10510 if (DECL_VINDEX (decl) != NULL_TREE)
10511 gen_type_die (DECL_CONTEXT (decl), context_die);
10513 /* And its containing type. */
10514 origin = decl_class_context (decl);
10515 if (origin != NULL_TREE)
10516 gen_type_die_for_member (origin, decl, context_die);
10519 /* Now output a DIE to represent the function itself. */
10520 gen_subprogram_die (decl, context_die);
10524 /* If we are in terse mode, don't generate any DIEs to represent any
10525 actual typedefs. */
10526 if (debug_info_level <= DINFO_LEVEL_TERSE)
10529 /* In the special case of a TYPE_DECL node representing the
10530 declaration of some type tag, if the given TYPE_DECL is marked as
10531 having been instantiated from some other (original) TYPE_DECL node
10532 (e.g. one which was generated within the original definition of an
10533 inline function) we have to generate a special (abbreviated)
10534 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10536 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10538 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10542 if (is_redundant_typedef (decl))
10543 gen_type_die (TREE_TYPE (decl), context_die);
10545 /* Output a DIE to represent the typedef itself. */
10546 gen_typedef_die (decl, context_die);
10550 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10551 gen_label_die (decl, context_die);
10555 /* If we are in terse mode, don't generate any DIEs to represent any
10556 variable declarations or definitions. */
10557 if (debug_info_level <= DINFO_LEVEL_TERSE)
10560 /* Output any DIEs that are needed to specify the type of this data
10562 gen_type_die (TREE_TYPE (decl), context_die);
10564 /* And its containing type. */
10565 origin = decl_class_context (decl);
10566 if (origin != NULL_TREE)
10567 gen_type_die_for_member (origin, decl, context_die);
10569 /* Now output the DIE to represent the data object itself. This gets
10570 complicated because of the possibility that the VAR_DECL really
10571 represents an inlined instance of a formal parameter for an inline
10573 origin = decl_ultimate_origin (decl);
10574 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10575 gen_formal_parameter_die (decl, context_die);
10577 gen_variable_die (decl, context_die);
10581 /* Ignore the nameless fields that are used to skip bits, but
10582 handle C++ anonymous unions. */
10583 if (DECL_NAME (decl) != NULL_TREE
10584 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10586 gen_type_die (member_declared_type (decl), context_die);
10587 gen_field_die (decl, context_die);
10592 gen_type_die (TREE_TYPE (decl), context_die);
10593 gen_formal_parameter_die (decl, context_die);
10596 case NAMESPACE_DECL:
10597 /* Ignore for now. */
10605 /* Add Ada "use" clause information for SGI Workshop debugger. */
10608 dwarf2out_add_library_unit_info (filename, context_list)
10609 const char *filename;
10610 const char *context_list;
10612 unsigned int file_index;
10614 if (filename != NULL)
10616 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10617 tree context_list_decl
10618 = build_decl (LABEL_DECL, get_identifier (context_list),
10621 TREE_PUBLIC (context_list_decl) = TRUE;
10622 add_name_attribute (unit_die, context_list);
10623 file_index = lookup_filename (&decl_file_table, filename);
10624 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10625 add_pubname (context_list_decl, unit_die);
10629 /* Write the debugging output for DECL. */
10632 dwarf2out_decl (decl)
10633 register tree decl;
10635 register dw_die_ref context_die = comp_unit_die;
10637 if (TREE_CODE (decl) == ERROR_MARK)
10640 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10641 if (DECL_IGNORED_P (decl))
10644 switch (TREE_CODE (decl))
10646 case FUNCTION_DECL:
10647 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10648 builtin function. Explicit programmer-supplied declarations of
10649 these same functions should NOT be ignored however. */
10650 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10653 /* What we would really like to do here is to filter out all mere
10654 file-scope declarations of file-scope functions which are never
10655 referenced later within this translation unit (and keep all of ones
10656 that *are* referenced later on) but we aren't clairvoyant, so we have
10657 no idea which functions will be referenced in the future (i.e. later
10658 on within the current translation unit). So here we just ignore all
10659 file-scope function declarations which are not also definitions. If
10660 and when the debugger needs to know something about these functions,
10661 it will have to hunt around and find the DWARF information associated
10662 with the definition of the function. Note that we can't just check
10663 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10664 definitions and which ones represent mere declarations. We have to
10665 check `DECL_INITIAL' instead. That's because the C front-end
10666 supports some weird semantics for "extern inline" function
10667 definitions. These can get inlined within the current translation
10668 unit (an thus, we need to generate DWARF info for their abstract
10669 instances so that the DWARF info for the concrete inlined instances
10670 can have something to refer to) but the compiler never generates any
10671 out-of-lines instances of such things (despite the fact that they
10672 *are* definitions). The important point is that the C front-end
10673 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10674 to generate DWARF for them anyway. Note that the C++ front-end also
10675 plays some similar games for inline function definitions appearing
10676 within include files which also contain
10677 `#pragma interface' pragmas. */
10678 if (DECL_INITIAL (decl) == NULL_TREE)
10681 /* If we're a nested function, initially use a parent of NULL; if we're
10682 a plain function, this will be fixed up in decls_for_scope. If
10683 we're a method, it will be ignored, since we already have a DIE. */
10684 if (decl_function_context (decl))
10685 context_die = NULL;
10690 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10691 declaration and if the declaration was never even referenced from
10692 within this entire compilation unit. We suppress these DIEs in
10693 order to save space in the .debug section (by eliminating entries
10694 which are probably useless). Note that we must not suppress
10695 block-local extern declarations (whether used or not) because that
10696 would screw-up the debugger's name lookup mechanism and cause it to
10697 miss things which really ought to be in scope at a given point. */
10698 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10701 /* If we are in terse mode, don't generate any DIEs to represent any
10702 variable declarations or definitions. */
10703 if (debug_info_level <= DINFO_LEVEL_TERSE)
10708 /* Don't emit stubs for types unless they are needed by other DIEs. */
10709 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10712 /* Don't bother trying to generate any DIEs to represent any of the
10713 normal built-in types for the language we are compiling. */
10714 if (DECL_SOURCE_LINE (decl) == 0)
10716 /* OK, we need to generate one for `bool' so GDB knows what type
10717 comparisons have. */
10718 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10719 == DW_LANG_C_plus_plus)
10720 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10721 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10726 /* If we are in terse mode, don't generate any DIEs for types. */
10727 if (debug_info_level <= DINFO_LEVEL_TERSE)
10730 /* If we're a function-scope tag, initially use a parent of NULL;
10731 this will be fixed up in decls_for_scope. */
10732 if (decl_function_context (decl))
10733 context_die = NULL;
10741 gen_decl_die (decl, context_die);
10744 /* Output a marker (i.e. a label) for the beginning of the generated code for
10745 a lexical block. */
10748 dwarf2out_begin_block (blocknum)
10749 register unsigned blocknum;
10751 function_section (current_function_decl);
10752 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10755 /* Output a marker (i.e. a label) for the end of the generated code for a
10759 dwarf2out_end_block (blocknum)
10760 register unsigned blocknum;
10762 function_section (current_function_decl);
10763 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10766 /* Returns nonzero if it is appropriate not to emit any debugging
10767 information for BLOCK, because it doesn't contain any instructions.
10769 Don't allow this for blocks with nested functions or local classes
10770 as we would end up with orphans, and in the presence of scheduling
10771 we may end up calling them anyway. */
10774 dwarf2out_ignore_block (block)
10778 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10779 if (TREE_CODE (decl) == FUNCTION_DECL
10780 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10785 /* Lookup a filename (in the list of filenames that we know about here in
10786 dwarf2out.c) and return its "index". The index of each (known) filename is
10787 just a unique number which is associated with only that one filename.
10788 We need such numbers for the sake of generating labels
10789 (in the .debug_sfnames section) and references to those
10790 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10791 If the filename given as an argument is not found in our current list,
10792 add it to the list and assign it the next available unique index number.
10793 In order to speed up searches, we remember the index of the filename
10794 was looked up last. This handles the majority of all searches. */
10797 lookup_filename (t, file_name)
10798 struct file_table *t;
10799 const char *file_name;
10801 register unsigned i;
10803 /* Check to see if the file name that was searched on the previous
10804 call matches this file name. If so, return the index. */
10805 if (t->last_lookup_index != 0)
10806 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
10807 return t->last_lookup_index;
10809 /* Didn't match the previous lookup, search the table */
10810 for (i = 1; i < t->in_use; ++i)
10811 if (strcmp (file_name, t->table[i]) == 0)
10813 t->last_lookup_index = i;
10817 /* Prepare to add a new table entry by making sure there is enough space in
10818 the table to do so. If not, expand the current table. */
10819 if (i == t->allocated)
10821 t->allocated = i + FILE_TABLE_INCREMENT;
10822 t->table = (char **)
10823 xrealloc (t->table, t->allocated * sizeof (char *));
10826 /* Add the new entry to the end of the filename table. */
10827 t->table[i] = xstrdup (file_name);
10829 t->last_lookup_index = i;
10835 init_file_table (t)
10836 struct file_table *t;
10838 /* Allocate the initial hunk of the file_table. */
10839 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10840 t->allocated = FILE_TABLE_INCREMENT;
10842 /* Skip the first entry - file numbers begin at 1. */
10844 t->last_lookup_index = 0;
10847 /* Output a label to mark the beginning of a source code line entry
10848 and record information relating to this source line, in
10849 'line_info_table' for later output of the .debug_line section. */
10852 dwarf2out_line (filename, line)
10853 register const char *filename;
10854 register unsigned line;
10856 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10858 function_section (current_function_decl);
10860 if (DWARF2_ASM_LINE_DEBUG_INFO)
10863 unsigned old_in_use = line_file_table.in_use;
10865 unsigned file_num = lookup_filename (&line_file_table, filename);
10867 /* Emit the .file and .loc directives understood by GNU as. */
10869 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
10870 actually use the file number argument. It merely remembers
10871 the last .file directive emitted. */
10872 if (file_num >= old_in_use)
10873 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
10874 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
10876 static unsigned int last_file_num;
10877 if (file_num != last_file_num)
10879 last_file_num = file_num;
10880 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
10882 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
10885 /* Indicate that line number info exists. */
10886 ++line_info_table_in_use;
10888 /* Indicate that multiple line number tables exist. */
10889 if (DECL_SECTION_NAME (current_function_decl))
10890 ++separate_line_info_table_in_use;
10892 else if (DECL_SECTION_NAME (current_function_decl))
10894 register dw_separate_line_info_ref line_info;
10895 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10896 separate_line_info_table_in_use);
10897 if (flag_debug_asm)
10898 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10901 /* expand the line info table if necessary */
10902 if (separate_line_info_table_in_use
10903 == separate_line_info_table_allocated)
10905 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10906 separate_line_info_table
10907 = (dw_separate_line_info_ref)
10908 xrealloc (separate_line_info_table,
10909 separate_line_info_table_allocated
10910 * sizeof (dw_separate_line_info_entry));
10913 /* Add the new entry at the end of the line_info_table. */
10915 = &separate_line_info_table[separate_line_info_table_in_use++];
10916 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
10917 line_info->dw_line_num = line;
10918 line_info->function = current_funcdef_number;
10922 register dw_line_info_ref line_info;
10924 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10925 line_info_table_in_use);
10926 if (flag_debug_asm)
10927 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10930 /* Expand the line info table if necessary. */
10931 if (line_info_table_in_use == line_info_table_allocated)
10933 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10935 = (dw_line_info_ref)
10936 xrealloc (line_info_table,
10937 (line_info_table_allocated
10938 * sizeof (dw_line_info_entry)));
10941 /* Add the new entry at the end of the line_info_table. */
10942 line_info = &line_info_table[line_info_table_in_use++];
10943 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
10944 line_info->dw_line_num = line;
10949 /* Record the beginning of a new source file, for later output
10950 of the .debug_macinfo section. At present, unimplemented. */
10953 dwarf2out_start_source_file (filename)
10954 register const char *filename ATTRIBUTE_UNUSED;
10956 if (flag_eliminate_dwarf2_dups)
10958 /* Record the beginning of the file for break_out_includes. */
10959 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10960 add_AT_string (bincl_die, DW_AT_name, filename);
10964 /* Record the end of a source file, for later output
10965 of the .debug_macinfo section. At present, unimplemented. */
10968 dwarf2out_end_source_file ()
10970 if (flag_eliminate_dwarf2_dups)
10972 /* Record the end of the file for break_out_includes. */
10973 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
10977 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10978 the tail part of the directive line, i.e. the part which is past the
10979 initial whitespace, #, whitespace, directive-name, whitespace part. */
10982 dwarf2out_define (lineno, buffer)
10983 register unsigned lineno ATTRIBUTE_UNUSED;
10984 register const char *buffer ATTRIBUTE_UNUSED;
10986 static int initialized = 0;
10989 dwarf2out_start_source_file (primary_filename);
10994 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
10995 the tail part of the directive line, i.e. the part which is past the
10996 initial whitespace, #, whitespace, directive-name, whitespace part. */
10999 dwarf2out_undef (lineno, buffer)
11000 register unsigned lineno ATTRIBUTE_UNUSED;
11001 register const char *buffer ATTRIBUTE_UNUSED;
11005 /* Set up for Dwarf output at the start of compilation. */
11008 dwarf2out_init (asm_out_file, main_input_filename)
11009 register FILE *asm_out_file;
11010 register const char *main_input_filename;
11012 /* Remember the name of the primary input file. */
11013 primary_filename = main_input_filename;
11015 init_file_table (&decl_file_table);
11016 init_file_table (&line_file_table);
11018 /* Allocate the initial hunk of the decl_die_table. */
11020 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11021 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11022 decl_die_table_in_use = 0;
11024 /* Allocate the initial hunk of the decl_scope_table. */
11026 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11027 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11028 decl_scope_depth = 0;
11030 /* Allocate the initial hunk of the abbrev_die_table. */
11032 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11033 sizeof (dw_die_ref));
11034 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11035 /* Zero-th entry is allocated, but unused */
11036 abbrev_die_table_in_use = 1;
11038 /* Allocate the initial hunk of the line_info_table. */
11040 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11041 sizeof (dw_line_info_entry));
11042 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11043 /* Zero-th entry is allocated, but unused */
11044 line_info_table_in_use = 1;
11046 /* Generate the initial DIE for the .debug section. Note that the (string)
11047 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11048 will (typically) be a relative pathname and that this pathname should be
11049 taken as being relative to the directory from which the compiler was
11050 invoked when the given (base) source file was compiled. */
11051 comp_unit_die = gen_compile_unit_die (main_input_filename);
11053 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11054 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11056 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11057 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11058 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11059 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11061 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11062 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11063 DEBUG_INFO_SECTION_LABEL, 0);
11064 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11065 DEBUG_LINE_SECTION_LABEL, 0);
11067 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11068 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11069 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11071 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11072 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11074 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11075 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11076 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11077 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11080 /* Output stuff that dwarf requires at the end of every file,
11081 and generate the DWARF-2 debugging info. */
11084 dwarf2out_finish ()
11086 limbo_die_node *node, *next_node;
11089 /* Traverse the limbo die list, and add parent/child links. The only
11090 dies without parents that should be here are concrete instances of
11091 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11092 For concrete instances, we can get the parent die from the abstract
11094 for (node = limbo_die_list; node; node = next_node)
11096 next_node = node->next;
11099 if (die->die_parent == NULL)
11101 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11103 add_child_die (origin->die_parent, die);
11104 else if (die == comp_unit_die)
11111 limbo_die_list = NULL;
11113 /* Walk through the list of incomplete types again, trying once more to
11114 emit full debugging info for them. */
11115 retry_incomplete_types ();
11117 /* We need to reverse all the dies before break_out_includes, or
11118 we'll see the end of an include file before the beginning. */
11119 reverse_all_dies (comp_unit_die);
11121 /* Generate separate CUs for each of the include files we've seen.
11122 They will go into limbo_die_list. */
11123 if (flag_eliminate_dwarf2_dups)
11124 break_out_includes (comp_unit_die);
11126 /* Traverse the DIE's and add add sibling attributes to those DIE's
11127 that have children. */
11128 add_sibling_attributes (comp_unit_die);
11129 for (node = limbo_die_list; node; node = node->next)
11130 add_sibling_attributes (node->die);
11132 /* Output a terminator label for the .text section. */
11133 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11134 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11137 /* Output a terminator label for the .data section. */
11138 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11139 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11141 /* Output a terminator label for the .bss section. */
11142 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11143 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11146 /* Output the source line correspondence table. */
11147 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11149 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11151 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11152 output_line_info ();
11155 /* We can only use the low/high_pc attributes if all of the code
11157 if (separate_line_info_table_in_use == 0)
11159 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11160 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11163 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11164 debug_line_section_label);
11167 #if 0 /* unimplemented */
11168 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11169 add_AT_unsigned (die, DW_AT_macro_info, 0);
11172 /* Output all of the compilation units. We put the main one last so that
11173 the offsets are available to output_pubnames. */
11174 for (node = limbo_die_list; node; node = node->next)
11175 output_comp_unit (node->die);
11176 output_comp_unit (comp_unit_die);
11178 /* Output the abbreviation table. */
11179 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11180 output_abbrev_section ();
11182 if (pubname_table_in_use)
11184 /* Output public names table. */
11185 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11186 output_pubnames ();
11189 /* We only put functions in the arange table, so don't write it out if
11190 we don't have any. */
11191 if (fde_table_in_use)
11193 /* Output the address range information. */
11194 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11198 #endif /* DWARF2_DEBUGGING_INFO */