1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: 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"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #ifdef DWARF2_DEBUGGING_INFO
64 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
67 /* DWARF2 Abbreviation Glossary:
68 CFA = Canonical Frame Address
69 a fixed address on the stack which identifies a call frame.
70 We define it to be the value of SP just before the call insn.
71 The CFA register and offset, which may change during the course
72 of the function, are used to calculate its value at runtime.
73 CFI = Call Frame Instruction
74 an instruction for the DWARF2 abstract machine
75 CIE = Common Information Entry
76 information describing information common to one or more FDEs
77 DIE = Debugging Information Entry
78 FDE = Frame Description Entry
79 information describing the stack call frame, in particular,
80 how to restore registers
82 DW_CFA_... = DWARF2 CFA call frame instruction
83 DW_TAG_... = DWARF2 DIE tag */
85 /* Decide whether we want to emit frame unwind information for the current
91 return (write_symbols == DWARF2_DEBUG
92 #ifdef DWARF2_FRAME_INFO
95 #ifdef DWARF2_UNWIND_INFO
97 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
102 /* The number of the current function definition for which debugging
103 information is being generated. These numbers range from 1 up to the
104 maximum number of function definitions contained within the current
105 compilation unit. These numbers are used to create unique label id's
106 unique to each function definition. */
107 unsigned current_funcdef_number = 0;
109 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
111 /* How to start an assembler comment. */
112 #ifndef ASM_COMMENT_START
113 #define ASM_COMMENT_START ";#"
116 typedef struct dw_cfi_struct *dw_cfi_ref;
117 typedef struct dw_fde_struct *dw_fde_ref;
118 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
120 /* Call frames are described using a sequence of Call Frame
121 Information instructions. The register number, offset
122 and address fields are provided as possible operands;
123 their use is selected by the opcode field. */
125 typedef union dw_cfi_oprnd_struct
127 unsigned long dw_cfi_reg_num;
128 long int dw_cfi_offset;
129 const char *dw_cfi_addr;
130 struct dw_loc_descr_struct *dw_cfi_loc;
134 typedef struct dw_cfi_struct
136 dw_cfi_ref dw_cfi_next;
137 enum dwarf_call_frame_info dw_cfi_opc;
138 dw_cfi_oprnd dw_cfi_oprnd1;
139 dw_cfi_oprnd dw_cfi_oprnd2;
143 /* This is how we define the location of the CFA. We use to handle it
144 as REG + OFFSET all the time, but now it can be more complex.
145 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
146 Instead of passing around REG and OFFSET, we pass a copy
147 of this structure. */
148 typedef struct cfa_loc
153 int indirect; /* 1 if CFA is accessed via a dereference. */
156 /* All call frame descriptions (FDE's) in the GCC generated DWARF
157 refer to a single Common Information Entry (CIE), defined at
158 the beginning of the .debug_frame section. This used of a single
159 CIE obviates the need to keep track of multiple CIE's
160 in the DWARF generation routines below. */
162 typedef struct dw_fde_struct
164 const char *dw_fde_begin;
165 const char *dw_fde_current_label;
166 const char *dw_fde_end;
167 dw_cfi_ref dw_fde_cfi;
168 unsigned funcdef_number;
169 unsigned nothrow : 1;
170 unsigned uses_eh_lsda : 1;
174 /* Maximum size (in bytes) of an artificially generated label. */
175 #define MAX_ARTIFICIAL_LABEL_BYTES 30
177 /* The size of the target's pointer type. */
179 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
182 /* The size of addresses as they appear in the Dwarf 2 data.
183 Some architectures use word addresses to refer to code locations,
184 but Dwarf 2 info always uses byte addresses. On such machines,
185 Dwarf 2 addresses need to be larger than the architecture's
187 #ifndef DWARF2_ADDR_SIZE
188 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
191 /* The size in bytes of a DWARF field indicating an offset or length
192 relative to a debug info section, specified to be 4 bytes in the
193 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
196 #ifndef DWARF_OFFSET_SIZE
197 #define DWARF_OFFSET_SIZE 4
200 #define DWARF_VERSION 2
202 /* Round SIZE up to the nearest BOUNDARY. */
203 #define DWARF_ROUND(SIZE,BOUNDARY) \
204 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
206 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
207 #ifndef DWARF_CIE_DATA_ALIGNMENT
208 #ifdef STACK_GROWS_DOWNWARD
209 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
211 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
213 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
215 /* A pointer to the base of a table that contains frame description
216 information for each routine. */
217 static dw_fde_ref fde_table;
219 /* Number of elements currently allocated for fde_table. */
220 static unsigned fde_table_allocated;
222 /* Number of elements in fde_table currently in use. */
223 static unsigned fde_table_in_use;
225 /* Size (in elements) of increments by which we may expand the
227 #define FDE_TABLE_INCREMENT 256
229 /* A list of call frame insns for the CIE. */
230 static dw_cfi_ref cie_cfi_head;
232 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
233 attribute that accelerates the lookup of the FDE associated
234 with the subprogram. This variable holds the table index of the FDE
235 associated with the current function (body) definition. */
236 static unsigned current_funcdef_fde;
238 /* Forward declarations for functions defined in this file. */
240 static char *stripattributes PARAMS ((const char *));
241 static const char *dwarf_cfi_name PARAMS ((unsigned));
242 static dw_cfi_ref new_cfi PARAMS ((void));
243 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
244 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
245 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
246 static void lookup_cfa PARAMS ((dw_cfa_location *));
247 static void reg_save PARAMS ((const char *, unsigned,
249 static void initial_return_save PARAMS ((rtx));
250 static long stack_adjust_offset PARAMS ((rtx));
251 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
252 static void output_call_frame_info PARAMS ((int));
253 static void dwarf2out_stack_adjust PARAMS ((rtx));
254 static void queue_reg_save PARAMS ((const char *, rtx, long));
255 static void flush_queued_reg_saves PARAMS ((void));
256 static bool clobbers_queued_reg_save PARAMS ((rtx));
257 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
259 /* Support for complex CFA locations. */
260 static void output_cfa_loc PARAMS ((dw_cfi_ref));
261 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
262 struct dw_loc_descr_struct *));
263 static struct dw_loc_descr_struct *build_cfa_loc
264 PARAMS ((dw_cfa_location *));
265 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
267 /* How to start an assembler comment. */
268 #ifndef ASM_COMMENT_START
269 #define ASM_COMMENT_START ";#"
272 /* Data and reference forms for relocatable data. */
273 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
274 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
276 /* Pseudo-op for defining a new section. */
277 #ifndef SECTION_ASM_OP
278 #define SECTION_ASM_OP "\t.section\t"
281 #ifndef DEBUG_FRAME_SECTION
282 #define DEBUG_FRAME_SECTION ".debug_frame"
285 #ifndef FUNC_BEGIN_LABEL
286 #define FUNC_BEGIN_LABEL "LFB"
288 #ifndef FUNC_END_LABEL
289 #define FUNC_END_LABEL "LFE"
291 #define CIE_AFTER_SIZE_LABEL "LSCIE"
292 #define CIE_END_LABEL "LECIE"
293 #define CIE_LENGTH_LABEL "LLCIE"
294 #define FDE_LABEL "LSFDE"
295 #define FDE_AFTER_SIZE_LABEL "LASFDE"
296 #define FDE_END_LABEL "LEFDE"
297 #define FDE_LENGTH_LABEL "LLFDE"
298 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
299 #define LINE_NUMBER_END_LABEL "LELT"
300 #define LN_PROLOG_AS_LABEL "LASLTP"
301 #define LN_PROLOG_END_LABEL "LELTP"
302 #define DIE_LABEL_PREFIX "DW"
304 /* Definitions of defaults for various types of primitive assembly language
305 output operations. These may be overridden from within the tm.h file,
306 but typically, that is unnecessary. */
309 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
310 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
312 fprintf (FILE, "%s", SET_ASM_OP); \
313 assemble_name (FILE, SY); \
315 assemble_name (FILE, HI); \
317 assemble_name (FILE, LO); \
320 #endif /* SET_ASM_OP */
322 /* The DWARF 2 CFA column which tracks the return address. Normally this
323 is the column for PC, or the first column after all of the hard
325 #ifndef DWARF_FRAME_RETURN_COLUMN
327 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
329 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
333 /* The mapping from gcc register number to DWARF 2 CFA column number. By
334 default, we just provide columns for all registers. */
335 #ifndef DWARF_FRAME_REGNUM
336 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
339 /* Hook used by __throw. */
342 expand_builtin_dwarf_fp_regnum ()
344 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
347 /* The offset from the incoming value of %sp to the top of the stack frame
348 for the current function. */
349 #ifndef INCOMING_FRAME_SP_OFFSET
350 #define INCOMING_FRAME_SP_OFFSET 0
353 /* Return a pointer to a copy of the section string name S with all
354 attributes stripped off, and an asterisk prepended (for assemble_name). */
360 char *stripped = xmalloc (strlen (s) + 2);
365 while (*s && *s != ',')
372 /* Generate code to initialize the register size table. */
375 expand_builtin_init_dwarf_reg_sizes (address)
379 enum machine_mode mode = TYPE_MODE (char_type_node);
380 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
381 rtx mem = gen_rtx_MEM (mode, addr);
383 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
385 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
386 int size = GET_MODE_SIZE (reg_raw_mode[i]);
391 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
395 /* Convert a DWARF call frame info. operation to its string name */
398 dwarf_cfi_name (cfi_opc)
399 register unsigned cfi_opc;
403 case DW_CFA_advance_loc:
404 return "DW_CFA_advance_loc";
406 return "DW_CFA_offset";
408 return "DW_CFA_restore";
412 return "DW_CFA_set_loc";
413 case DW_CFA_advance_loc1:
414 return "DW_CFA_advance_loc1";
415 case DW_CFA_advance_loc2:
416 return "DW_CFA_advance_loc2";
417 case DW_CFA_advance_loc4:
418 return "DW_CFA_advance_loc4";
419 case DW_CFA_offset_extended:
420 return "DW_CFA_offset_extended";
421 case DW_CFA_restore_extended:
422 return "DW_CFA_restore_extended";
423 case DW_CFA_undefined:
424 return "DW_CFA_undefined";
425 case DW_CFA_same_value:
426 return "DW_CFA_same_value";
427 case DW_CFA_register:
428 return "DW_CFA_register";
429 case DW_CFA_remember_state:
430 return "DW_CFA_remember_state";
431 case DW_CFA_restore_state:
432 return "DW_CFA_restore_state";
434 return "DW_CFA_def_cfa";
435 case DW_CFA_def_cfa_register:
436 return "DW_CFA_def_cfa_register";
437 case DW_CFA_def_cfa_offset:
438 return "DW_CFA_def_cfa_offset";
439 case DW_CFA_def_cfa_expression:
440 return "DW_CFA_def_cfa_expression";
442 /* SGI/MIPS specific */
443 case DW_CFA_MIPS_advance_loc8:
444 return "DW_CFA_MIPS_advance_loc8";
447 case DW_CFA_GNU_window_save:
448 return "DW_CFA_GNU_window_save";
449 case DW_CFA_GNU_args_size:
450 return "DW_CFA_GNU_args_size";
451 case DW_CFA_GNU_negative_offset_extended:
452 return "DW_CFA_GNU_negative_offset_extended";
455 return "DW_CFA_<unknown>";
459 /* Return a pointer to a newly allocated Call Frame Instruction. */
461 static inline dw_cfi_ref
464 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
466 cfi->dw_cfi_next = NULL;
467 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
468 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
473 /* Add a Call Frame Instruction to list of instructions. */
476 add_cfi (list_head, cfi)
477 register dw_cfi_ref *list_head;
478 register dw_cfi_ref cfi;
480 register dw_cfi_ref *p;
482 /* Find the end of the chain. */
483 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
489 /* Generate a new label for the CFI info to refer to. */
492 dwarf2out_cfi_label ()
494 static char label[20];
495 static unsigned long label_num = 0;
497 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
498 ASM_OUTPUT_LABEL (asm_out_file, label);
503 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
504 or to the CIE if LABEL is NULL. */
507 add_fde_cfi (label, cfi)
508 register const char *label;
509 register dw_cfi_ref cfi;
513 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
516 label = dwarf2out_cfi_label ();
518 if (fde->dw_fde_current_label == NULL
519 || strcmp (label, fde->dw_fde_current_label) != 0)
521 register dw_cfi_ref xcfi;
523 fde->dw_fde_current_label = label = xstrdup (label);
525 /* Set the location counter to the new label. */
527 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
528 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
529 add_cfi (&fde->dw_fde_cfi, xcfi);
532 add_cfi (&fde->dw_fde_cfi, cfi);
536 add_cfi (&cie_cfi_head, cfi);
539 /* Subroutine of lookup_cfa. */
542 lookup_cfa_1 (cfi, loc)
543 register dw_cfi_ref cfi;
544 register dw_cfa_location *loc;
546 switch (cfi->dw_cfi_opc)
548 case DW_CFA_def_cfa_offset:
549 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
551 case DW_CFA_def_cfa_register:
552 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
555 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
556 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
558 case DW_CFA_def_cfa_expression:
559 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
566 /* Find the previous value for the CFA. */
570 register dw_cfa_location *loc;
572 register dw_cfi_ref cfi;
574 loc->reg = (unsigned long) -1;
577 loc->base_offset = 0;
579 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
580 lookup_cfa_1 (cfi, loc);
582 if (fde_table_in_use)
584 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
585 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
586 lookup_cfa_1 (cfi, loc);
590 /* The current rule for calculating the DWARF2 canonical frame address. */
591 static dw_cfa_location cfa;
593 /* The register used for saving registers to the stack, and its offset
595 static dw_cfa_location cfa_store;
597 /* The running total of the size of arguments pushed onto the stack. */
598 static long args_size;
600 /* The last args_size we actually output. */
601 static long old_args_size;
603 /* Entry point to update the canonical frame address (CFA).
604 LABEL is passed to add_fde_cfi. The value of CFA is now to be
605 calculated from REG+OFFSET. */
608 dwarf2out_def_cfa (label, reg, offset)
609 register const char *label;
618 def_cfa_1 (label, &loc);
621 /* This routine does the actual work. The CFA is now calculated from
622 the dw_cfa_location structure. */
624 def_cfa_1 (label, loc_p)
625 register const char *label;
626 dw_cfa_location *loc_p;
628 register dw_cfi_ref cfi;
629 dw_cfa_location old_cfa, loc;
634 if (cfa_store.reg == loc.reg && loc.indirect == 0)
635 cfa_store.offset = loc.offset;
637 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
638 lookup_cfa (&old_cfa);
640 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
641 loc.indirect == old_cfa.indirect)
643 if (loc.indirect == 0
644 || loc.base_offset == old_cfa.base_offset)
645 /* Nothing changed so no need to issue any call frame
652 if (loc.reg == old_cfa.reg && !loc.indirect)
654 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
655 indicating the CFA register did not change but the offset
657 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
658 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
661 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
662 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
665 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
666 indicating the CFA register has changed to <register> but the
667 offset has not changed. */
668 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
669 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
673 else if (loc.indirect == 0)
675 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
676 indicating the CFA register has changed to <register> with
677 the specified offset. */
678 cfi->dw_cfi_opc = DW_CFA_def_cfa;
679 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
680 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
684 /* Construct a DW_CFA_def_cfa_expression instruction to
685 calculate the CFA using a full location expression since no
686 register-offset pair is available. */
687 struct dw_loc_descr_struct *loc_list;
688 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
689 loc_list = build_cfa_loc (&loc);
690 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
693 add_fde_cfi (label, cfi);
696 /* Add the CFI for saving a register. REG is the CFA column number.
697 LABEL is passed to add_fde_cfi.
698 If SREG is -1, the register is saved at OFFSET from the CFA;
699 otherwise it is saved in SREG. */
702 reg_save (label, reg, sreg, offset)
703 register const char *label;
704 register unsigned reg;
705 register unsigned sreg;
706 register long offset;
708 register dw_cfi_ref cfi = new_cfi ();
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
712 /* The following comparison is correct. -1 is used to indicate that
713 the value isn't a register number. */
714 if (sreg == (unsigned int) -1)
717 /* The register number won't fit in 6 bits, so we have to use
719 cfi->dw_cfi_opc = DW_CFA_offset_extended;
721 cfi->dw_cfi_opc = DW_CFA_offset;
723 #ifdef ENABLE_CHECKING
725 /* If we get an offset that is not a multiple of
726 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
727 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
729 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
731 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
735 offset /= DWARF_CIE_DATA_ALIGNMENT;
738 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
741 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
743 else if (sreg == reg)
744 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
748 cfi->dw_cfi_opc = DW_CFA_register;
749 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
752 add_fde_cfi (label, cfi);
755 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
756 This CFI tells the unwinder that it needs to restore the window registers
757 from the previous frame's window save area.
759 ??? Perhaps we should note in the CIE where windows are saved (instead of
760 assuming 0(cfa)) and what registers are in the window. */
763 dwarf2out_window_save (label)
764 register const char *label;
766 register dw_cfi_ref cfi = new_cfi ();
767 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
768 add_fde_cfi (label, cfi);
771 /* Add a CFI to update the running total of the size of arguments
772 pushed onto the stack. */
775 dwarf2out_args_size (label, size)
779 register dw_cfi_ref cfi;
781 if (size == old_args_size)
783 old_args_size = size;
786 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
787 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
788 add_fde_cfi (label, cfi);
791 /* Entry point for saving a register to the stack. REG is the GCC register
792 number. LABEL and OFFSET are passed to reg_save. */
795 dwarf2out_reg_save (label, reg, offset)
796 register const char *label;
797 register unsigned reg;
798 register long offset;
800 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
803 /* Entry point for saving the return address in the stack.
804 LABEL and OFFSET are passed to reg_save. */
807 dwarf2out_return_save (label, offset)
808 register const char *label;
809 register long offset;
811 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
814 /* Entry point for saving the return address in a register.
815 LABEL and SREG are passed to reg_save. */
818 dwarf2out_return_reg (label, sreg)
819 register const char *label;
820 register unsigned sreg;
822 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
825 /* Record the initial position of the return address. RTL is
826 INCOMING_RETURN_ADDR_RTX. */
829 initial_return_save (rtl)
832 unsigned int reg = (unsigned int) -1;
835 switch (GET_CODE (rtl))
838 /* RA is in a register. */
839 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
842 /* RA is on the stack. */
844 switch (GET_CODE (rtl))
847 if (REGNO (rtl) != STACK_POINTER_REGNUM)
852 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
854 offset = INTVAL (XEXP (rtl, 1));
857 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
859 offset = -INTVAL (XEXP (rtl, 1));
866 /* The return address is at some offset from any value we can
867 actually load. For instance, on the SPARC it is in %i7+8. Just
868 ignore the offset for now; it doesn't matter for unwinding frames. */
869 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
871 initial_return_save (XEXP (rtl, 0));
877 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
880 /* Given a SET, calculate the amount of stack adjustment it
884 stack_adjust_offset (pattern)
887 rtx src = SET_SRC (pattern);
888 rtx dest = SET_DEST (pattern);
892 if (dest == stack_pointer_rtx)
894 /* (set (reg sp) (plus (reg sp) (const_int))) */
895 code = GET_CODE (src);
896 if (! (code == PLUS || code == MINUS)
897 || XEXP (src, 0) != stack_pointer_rtx
898 || GET_CODE (XEXP (src, 1)) != CONST_INT)
901 offset = INTVAL (XEXP (src, 1));
903 else if (GET_CODE (dest) == MEM)
905 /* (set (mem (pre_dec (reg sp))) (foo)) */
906 src = XEXP (dest, 0);
907 code = GET_CODE (src);
909 if (! (code == PRE_DEC || code == PRE_INC
910 || code == PRE_MODIFY)
911 || XEXP (src, 0) != stack_pointer_rtx)
914 if (code == PRE_MODIFY)
916 rtx val = XEXP (XEXP (src, 1), 1);
917 /* We handle only adjustments by constant amount. */
918 if (GET_CODE (XEXP (src, 1)) != PLUS ||
919 GET_CODE (val) != CONST_INT)
921 offset = -INTVAL (val);
923 else offset = GET_MODE_SIZE (GET_MODE (dest));
928 if (code == PLUS || code == PRE_INC)
934 /* Check INSN to see if it looks like a push or a stack adjustment, and
935 make a note of it if it does. EH uses this information to find out how
936 much extra space it needs to pop off the stack. */
939 dwarf2out_stack_adjust (insn)
945 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
947 /* Extract the size of the args from the CALL rtx itself. */
949 insn = PATTERN (insn);
950 if (GET_CODE (insn) == PARALLEL)
951 insn = XVECEXP (insn, 0, 0);
952 if (GET_CODE (insn) == SET)
953 insn = SET_SRC (insn);
954 if (GET_CODE (insn) != CALL)
956 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
960 /* If only calls can throw, and we have a frame pointer,
961 save up adjustments until we see the CALL_INSN. */
962 else if (! flag_non_call_exceptions
963 && cfa.reg != STACK_POINTER_REGNUM)
966 if (GET_CODE (insn) == BARRIER)
968 /* When we see a BARRIER, we know to reset args_size to 0. Usually
969 the compiler will have already emitted a stack adjustment, but
970 doesn't bother for calls to noreturn functions. */
971 #ifdef STACK_GROWS_DOWNWARD
977 else if (GET_CODE (PATTERN (insn)) == SET)
979 offset = stack_adjust_offset (PATTERN (insn));
981 else if (GET_CODE (PATTERN (insn)) == PARALLEL
982 || GET_CODE (PATTERN (insn)) == SEQUENCE)
984 /* There may be stack adjustments inside compound insns. Search
989 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
991 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
992 if (GET_CODE (pattern) == SET)
993 offset += stack_adjust_offset (pattern);
1002 if (cfa.reg == STACK_POINTER_REGNUM)
1003 cfa.offset += offset;
1005 #ifndef STACK_GROWS_DOWNWARD
1008 args_size += offset;
1012 label = dwarf2out_cfi_label ();
1013 def_cfa_1 (label, &cfa);
1014 dwarf2out_args_size (label, args_size);
1017 /* We delay emitting a register save until either (a) we reach the end
1018 of the prologue or (b) the register is clobbered. This clusters
1019 register saves so that there are fewer pc advances. */
1021 struct queued_reg_save
1023 struct queued_reg_save *next;
1028 static struct queued_reg_save *queued_reg_saves;
1029 static const char *last_reg_save_label;
1032 queue_reg_save (label, reg, offset)
1037 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1039 q->next = queued_reg_saves;
1041 q->cfa_offset = offset;
1042 queued_reg_saves = q;
1044 last_reg_save_label = label;
1048 flush_queued_reg_saves ()
1050 struct queued_reg_save *q, *next;
1052 for (q = queued_reg_saves; q ; q = next)
1054 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1059 queued_reg_saves = NULL;
1060 last_reg_save_label = NULL;
1064 clobbers_queued_reg_save (insn)
1067 struct queued_reg_save *q;
1069 for (q = queued_reg_saves; q ; q = q->next)
1070 if (modified_in_p (q->reg, insn))
1077 /* A temporary register holding an integral value used in adjusting SP
1078 or setting up the store_reg. The "offset" field holds the integer
1079 value, not an offset. */
1080 static dw_cfa_location cfa_temp;
1082 /* Record call frame debugging information for an expression EXPR,
1083 which either sets SP or FP (adjusting how we calculate the frame
1084 address) or saves a register to the stack. LABEL indicates the
1087 This function encodes a state machine mapping rtxes to actions on
1088 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1089 users need not read the source code.
1091 The High-Level Picture
1093 Changes in the register we use to calculate the CFA: Currently we
1094 assume that if you copy the CFA register into another register, we
1095 should take the other one as the new CFA register; this seems to
1096 work pretty well. If it's wrong for some target, it's simple
1097 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1099 Changes in the register we use for saving registers to the stack:
1100 This is usually SP, but not always. Again, we deduce that if you
1101 copy SP into another register (and SP is not the CFA register),
1102 then the new register is the one we will be using for register
1103 saves. This also seems to work.
1105 Register saves: There's not much guesswork about this one; if
1106 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1107 register save, and the register used to calculate the destination
1108 had better be the one we think we're using for this purpose.
1110 Except: If the register being saved is the CFA register, and the
1111 offset is non-zero, we are saving the CFA, so we assume we have to
1112 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1113 the intent is to save the value of SP from the previous frame.
1115 Invariants / Summaries of Rules
1117 cfa current rule for calculating the CFA. It usually
1118 consists of a register and an offset.
1119 cfa_store register used by prologue code to save things to the stack
1120 cfa_store.offset is the offset from the value of
1121 cfa_store.reg to the actual CFA
1122 cfa_temp register holding an integral value. cfa_temp.offset
1123 stores the value, which will be used to adjust the
1124 stack pointer. cfa_temp is also used like cfa_store,
1125 to track stores to the stack via fp or a temp reg.
1127 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1128 with cfa.reg as the first operand changes the cfa.reg and its
1129 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1132 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1133 expression yielding a constant. This sets cfa_temp.reg
1134 and cfa_temp.offset.
1136 Rule 5: Create a new register cfa_store used to save items to the
1139 Rules 10-14: Save a register to the stack. Define offset as the
1140 difference of the original location and cfa_store's
1141 location (or cfa_temp's location if cfa_temp is used).
1145 "{a,b}" indicates a choice of a xor b.
1146 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1149 (set <reg1> <reg2>:cfa.reg)
1150 effects: cfa.reg = <reg1>
1151 cfa.offset unchanged
1152 cfa_temp.reg = <reg1>
1153 cfa_temp.offset = cfa.offset
1156 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1157 effects: cfa.reg = sp if fp used
1158 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1159 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1160 if cfa_store.reg==sp
1163 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1164 effects: cfa.reg = fp
1165 cfa_offset += +/- <const_int>
1168 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1169 constraints: <reg1> != fp
1171 effects: cfa.reg = <reg1>
1172 cfa_temp.reg = <reg1>
1173 cfa_temp.offset = cfa.offset
1176 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1177 constraints: <reg1> != fp
1179 effects: cfa_store.reg = <reg1>
1180 cfa_store.offset = cfa.offset - cfa_temp.offset
1183 (set <reg> <const_int>)
1184 effects: cfa_temp.reg = <reg>
1185 cfa_temp.offset = <const_int>
1188 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1189 effects: cfa_temp.reg = <reg1>
1190 cfa_temp.offset |= <const_int>
1193 (set <reg> (high <exp>))
1197 (set <reg> (lo_sum <exp> <const_int>))
1198 effects: cfa_temp.reg = <reg>
1199 cfa_temp.offset = <const_int>
1202 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1203 effects: cfa_store.offset -= <const_int>
1204 cfa.offset = cfa_store.offset if cfa.reg == sp
1206 cfa.base_offset = -cfa_store.offset
1209 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1210 effects: cfa_store.offset += -/+ mode_size(mem)
1211 cfa.offset = cfa_store.offset if cfa.reg == sp
1213 cfa.base_offset = -cfa_store.offset
1216 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1217 effects: cfa.reg = <reg1>
1218 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1221 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1222 effects: cfa.reg = <reg1>
1223 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1226 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1227 effects: cfa.reg = <reg1>
1228 cfa.base_offset = -cfa_temp.offset
1229 cfa_temp.offset -= mode_size(mem) */
1232 dwarf2out_frame_debug_expr (expr, label)
1239 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1240 the PARALLEL independently. The first element is always processed if
1241 it is a SET. This is for backward compatibility. Other elements
1242 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1243 flag is set in them. */
1245 if (GET_CODE (expr) == PARALLEL
1246 || GET_CODE (expr) == SEQUENCE)
1249 int limit = XVECLEN (expr, 0);
1251 for (par_index = 0; par_index < limit; par_index++)
1253 rtx x = XVECEXP (expr, 0, par_index);
1255 if (GET_CODE (x) == SET &&
1256 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1257 dwarf2out_frame_debug_expr (x, label);
1262 if (GET_CODE (expr) != SET)
1265 src = SET_SRC (expr);
1266 dest = SET_DEST (expr);
1268 switch (GET_CODE (dest))
1272 /* Update the CFA rule wrt SP or FP. Make sure src is
1273 relative to the current CFA register. */
1274 switch (GET_CODE (src))
1276 /* Setting FP from SP. */
1278 if (cfa.reg == (unsigned) REGNO (src))
1284 /* We used to require that dest be either SP or FP, but the
1285 ARM copies SP to a temporary register, and from there to
1286 FP. So we just rely on the backends to only set
1287 RTX_FRAME_RELATED_P on appropriate insns. */
1288 cfa.reg = REGNO (dest);
1289 cfa_temp.reg = cfa.reg;
1290 cfa_temp.offset = cfa.offset;
1296 if (dest == stack_pointer_rtx)
1300 switch (GET_CODE (XEXP (src, 1)))
1303 offset = INTVAL (XEXP (src, 1));
1306 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1308 offset = cfa_temp.offset;
1314 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1316 /* Restoring SP from FP in the epilogue. */
1317 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1319 cfa.reg = STACK_POINTER_REGNUM;
1321 else if (GET_CODE (src) == LO_SUM)
1322 /* Assume we've set the source reg of the LO_SUM from sp. */
1324 else if (XEXP (src, 0) != stack_pointer_rtx)
1327 if (GET_CODE (src) != MINUS)
1329 if (cfa.reg == STACK_POINTER_REGNUM)
1330 cfa.offset += offset;
1331 if (cfa_store.reg == STACK_POINTER_REGNUM)
1332 cfa_store.offset += offset;
1334 else if (dest == hard_frame_pointer_rtx)
1337 /* Either setting the FP from an offset of the SP,
1338 or adjusting the FP */
1339 if (! frame_pointer_needed)
1342 if (GET_CODE (XEXP (src, 0)) == REG
1343 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1344 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1346 offset = INTVAL (XEXP (src, 1));
1347 if (GET_CODE (src) != MINUS)
1349 cfa.offset += offset;
1350 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1357 if (GET_CODE (src) == MINUS)
1361 if (GET_CODE (XEXP (src, 0)) == REG
1362 && REGNO (XEXP (src, 0)) == cfa.reg
1363 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1365 /* Setting a temporary CFA register that will be copied
1366 into the FP later on. */
1367 offset = - INTVAL (XEXP (src, 1));
1368 cfa.offset += offset;
1369 cfa.reg = REGNO (dest);
1370 /* Or used to save regs to the stack. */
1371 cfa_temp.reg = cfa.reg;
1372 cfa_temp.offset = cfa.offset;
1375 else if (GET_CODE (XEXP (src, 0)) == REG
1376 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1377 && XEXP (src, 1) == stack_pointer_rtx)
1379 /* Setting a scratch register that we will use instead
1380 of SP for saving registers to the stack. */
1381 if (cfa.reg != STACK_POINTER_REGNUM)
1383 cfa_store.reg = REGNO (dest);
1384 cfa_store.offset = cfa.offset - cfa_temp.offset;
1387 else if (GET_CODE (src) == LO_SUM
1388 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1390 cfa_temp.reg = REGNO (dest);
1391 cfa_temp.offset = INTVAL (XEXP (src, 1));
1400 cfa_temp.reg = REGNO (dest);
1401 cfa_temp.offset = INTVAL (src);
1406 if (GET_CODE (XEXP (src, 0)) != REG
1407 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1408 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1410 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1411 cfa_temp.reg = REGNO (dest);
1412 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1415 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1416 which will fill in all of the bits. */
1424 def_cfa_1 (label, &cfa);
1428 if (GET_CODE (src) != REG)
1431 /* Saving a register to the stack. Make sure dest is relative to the
1433 switch (GET_CODE (XEXP (dest, 0)))
1438 /* We can't handle variable size modifications. */
1439 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1441 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1443 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1444 || cfa_store.reg != STACK_POINTER_REGNUM)
1446 cfa_store.offset += offset;
1447 if (cfa.reg == STACK_POINTER_REGNUM)
1448 cfa.offset = cfa_store.offset;
1450 offset = -cfa_store.offset;
1455 offset = GET_MODE_SIZE (GET_MODE (dest));
1456 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1459 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1460 || cfa_store.reg != STACK_POINTER_REGNUM)
1462 cfa_store.offset += offset;
1463 if (cfa.reg == STACK_POINTER_REGNUM)
1464 cfa.offset = cfa_store.offset;
1466 offset = -cfa_store.offset;
1470 /* With an offset. */
1474 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1476 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1477 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1480 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1481 offset -= cfa_store.offset;
1482 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1483 offset -= cfa_temp.offset;
1489 /* Without an offset. */
1491 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1492 offset = -cfa_store.offset;
1493 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1494 offset = -cfa_temp.offset;
1501 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1503 offset = -cfa_temp.offset;
1504 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1511 if (REGNO (src) != STACK_POINTER_REGNUM
1512 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1513 && (unsigned) REGNO (src) == cfa.reg)
1515 /* We're storing the current CFA reg into the stack. */
1517 if (cfa.offset == 0)
1519 /* If the source register is exactly the CFA, assume
1520 we're saving SP like any other register; this happens
1523 def_cfa_1 (label, &cfa);
1524 queue_reg_save (label, stack_pointer_rtx, offset);
1529 /* Otherwise, we'll need to look in the stack to
1530 calculate the CFA. */
1532 rtx x = XEXP (dest, 0);
1533 if (GET_CODE (x) != REG)
1535 if (GET_CODE (x) != REG)
1537 cfa.reg = (unsigned) REGNO (x);
1538 cfa.base_offset = offset;
1540 def_cfa_1 (label, &cfa);
1545 def_cfa_1 (label, &cfa);
1546 queue_reg_save (label, src, offset);
1554 /* Record call frame debugging information for INSN, which either
1555 sets SP or FP (adjusting how we calculate the frame address) or saves a
1556 register to the stack. If INSN is NULL_RTX, initialize our state. */
1559 dwarf2out_frame_debug (insn)
1565 if (insn == NULL_RTX)
1567 /* Flush any queued register saves. */
1568 flush_queued_reg_saves ();
1570 /* Set up state for generating call frame debug info. */
1572 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1574 cfa.reg = STACK_POINTER_REGNUM;
1577 cfa_temp.offset = 0;
1581 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1582 flush_queued_reg_saves ();
1584 if (! RTX_FRAME_RELATED_P (insn))
1586 if (!ACCUMULATE_OUTGOING_ARGS)
1587 dwarf2out_stack_adjust (insn);
1591 label = dwarf2out_cfi_label ();
1593 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1595 insn = XEXP (src, 0);
1597 insn = PATTERN (insn);
1599 dwarf2out_frame_debug_expr (insn, label);
1602 /* Output a Call Frame Information opcode and its operand(s). */
1605 output_cfi (cfi, fde, for_eh)
1606 register dw_cfi_ref cfi;
1607 register dw_fde_ref fde;
1610 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1612 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1613 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1614 "DW_CFA_advance_loc 0x%lx",
1615 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1617 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1619 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1620 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1621 "DW_CFA_offset, column 0x%lx",
1622 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1623 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1625 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1627 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1628 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1629 "DW_CFA_restore, column 0x%lx",
1630 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1634 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1635 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1637 switch (cfi->dw_cfi_opc)
1639 case DW_CFA_set_loc:
1641 dw2_asm_output_encoded_addr_rtx (
1642 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1643 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1646 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1647 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1649 case DW_CFA_advance_loc1:
1650 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1651 fde->dw_fde_current_label, NULL);
1652 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1654 case DW_CFA_advance_loc2:
1655 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1656 fde->dw_fde_current_label, NULL);
1657 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1659 case DW_CFA_advance_loc4:
1660 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1661 fde->dw_fde_current_label, NULL);
1662 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1664 case DW_CFA_MIPS_advance_loc8:
1665 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1666 fde->dw_fde_current_label, NULL);
1667 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1669 case DW_CFA_offset_extended:
1670 case DW_CFA_GNU_negative_offset_extended:
1671 case DW_CFA_def_cfa:
1672 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1673 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1675 case DW_CFA_restore_extended:
1676 case DW_CFA_undefined:
1677 case DW_CFA_same_value:
1678 case DW_CFA_def_cfa_register:
1679 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1681 case DW_CFA_register:
1682 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1683 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1685 case DW_CFA_def_cfa_offset:
1686 case DW_CFA_GNU_args_size:
1687 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1689 case DW_CFA_GNU_window_save:
1691 case DW_CFA_def_cfa_expression:
1692 output_cfa_loc (cfi);
1700 /* Output the call frame information used to used to record information
1701 that relates to calculating the frame pointer, and records the
1702 location of saved registers. */
1705 output_call_frame_info (for_eh)
1708 register unsigned int i;
1709 register dw_fde_ref fde;
1710 register dw_cfi_ref cfi;
1711 char l1[20], l2[20];
1712 int any_lsda_needed = 0;
1713 char augmentation[6];
1714 int augmentation_size;
1715 int fde_encoding = DW_EH_PE_absptr;
1716 int per_encoding = DW_EH_PE_absptr;
1717 int lsda_encoding = DW_EH_PE_absptr;
1719 /* If we don't have any functions we'll want to unwind out of, don't
1720 emit any EH unwind information. */
1723 int any_eh_needed = 0;
1724 for (i = 0; i < fde_table_in_use; ++i)
1725 if (fde_table[i].uses_eh_lsda)
1726 any_eh_needed = any_lsda_needed = 1;
1727 else if (! fde_table[i].nothrow)
1730 if (! any_eh_needed)
1734 /* We're going to be generating comments, so turn on app. */
1740 #ifdef EH_FRAME_SECTION_NAME
1741 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
1743 tree label = get_file_function_name ('F');
1746 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1747 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1748 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1750 assemble_label ("__FRAME_BEGIN__");
1753 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1755 /* Output the CIE. */
1756 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1757 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1758 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1759 "Length of Common Information Entry");
1760 ASM_OUTPUT_LABEL (asm_out_file, l1);
1762 /* Now that the CIE pointer is PC-relative for EH,
1763 use 0 to identify the CIE. */
1764 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1765 (for_eh ? 0 : DW_CIE_ID),
1766 "CIE Identifier Tag");
1768 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1770 augmentation[0] = 0;
1771 augmentation_size = 0;
1777 z Indicates that a uleb128 is present to size the
1778 augmentation section.
1779 L Indicates the encoding (and thus presence) of
1780 an LSDA pointer in the FDE augmentation.
1781 R Indicates a non-default pointer encoding for
1783 P Indicates the presence of an encoding + language
1784 personality routine in the CIE augmentation. */
1786 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1787 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1788 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1790 p = augmentation + 1;
1791 if (eh_personality_libfunc)
1794 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1796 if (any_lsda_needed)
1799 augmentation_size += 1;
1801 if (fde_encoding != DW_EH_PE_absptr)
1804 augmentation_size += 1;
1806 if (p > augmentation + 1)
1808 augmentation[0] = 'z';
1812 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1813 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1815 int offset = ( 4 /* Length */
1817 + 1 /* CIE version */
1818 + strlen (augmentation) + 1 /* Augmentation */
1819 + size_of_uleb128 (1) /* Code alignment */
1820 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1822 + 1 /* Augmentation size */
1823 + 1 /* Personality encoding */ );
1824 int pad = -offset & (PTR_SIZE - 1);
1826 augmentation_size += pad;
1828 /* Augmentations should be small, so there's scarce need to
1829 iterate for a solution. Die if we exceed one uleb128 byte. */
1830 if (size_of_uleb128 (augmentation_size) != 1)
1834 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1836 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1838 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1839 "CIE Data Alignment Factor");
1841 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1843 if (augmentation[0])
1845 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1846 if (eh_personality_libfunc)
1848 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1849 eh_data_format_name (per_encoding));
1850 dw2_asm_output_encoded_addr_rtx (per_encoding,
1851 eh_personality_libfunc, NULL);
1853 if (any_lsda_needed)
1854 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1855 eh_data_format_name (lsda_encoding));
1856 if (fde_encoding != DW_EH_PE_absptr)
1857 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1858 eh_data_format_name (fde_encoding));
1861 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1862 output_cfi (cfi, NULL, for_eh);
1864 /* Pad the CIE out to an address sized boundary. */
1865 ASM_OUTPUT_ALIGN (asm_out_file,
1866 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1867 ASM_OUTPUT_LABEL (asm_out_file, l2);
1869 /* Loop through all of the FDE's. */
1870 for (i = 0; i < fde_table_in_use; ++i)
1872 fde = &fde_table[i];
1874 /* Don't emit EH unwind info for leaf functions that don't need it. */
1875 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1878 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1879 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1880 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1881 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1883 ASM_OUTPUT_LABEL (asm_out_file, l1);
1885 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1886 emits a target dependent sized offset when for_eh is not true.
1887 This inconsistency may confuse gdb. The only case where we need a
1888 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1889 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1890 though in order to be compatible with the dwarf_fde struct in frame.c.
1891 If the for_eh case is changed, then the struct in frame.c has
1892 to be adjusted appropriately. */
1894 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1896 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1897 stripattributes (DEBUG_FRAME_SECTION),
1902 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1903 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1904 "FDE initial location");
1905 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1906 fde->dw_fde_end, fde->dw_fde_begin,
1907 "FDE address range");
1911 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1912 "FDE initial location");
1913 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1914 fde->dw_fde_end, fde->dw_fde_begin,
1915 "FDE address range");
1918 if (augmentation[0])
1920 if (any_lsda_needed)
1922 int size = size_of_encoded_value (lsda_encoding);
1924 if (lsda_encoding == DW_EH_PE_aligned)
1926 int offset = ( 4 /* Length */
1927 + 4 /* CIE offset */
1928 + 2 * size_of_encoded_value (fde_encoding)
1929 + 1 /* Augmentation size */ );
1930 int pad = -offset & (PTR_SIZE - 1);
1933 if (size_of_uleb128 (size) != 1)
1937 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1939 if (fde->uses_eh_lsda)
1941 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1942 fde->funcdef_number);
1943 dw2_asm_output_encoded_addr_rtx (
1944 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1945 "Language Specific Data Area");
1949 if (lsda_encoding == DW_EH_PE_aligned)
1950 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1951 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1952 0, "Language Specific Data Area (none)");
1956 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1959 /* Loop through the Call Frame Instructions associated with
1961 fde->dw_fde_current_label = fde->dw_fde_begin;
1962 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1963 output_cfi (cfi, fde, for_eh);
1965 /* Pad the FDE out to an address sized boundary. */
1966 ASM_OUTPUT_ALIGN (asm_out_file,
1967 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1968 ASM_OUTPUT_LABEL (asm_out_file, l2);
1971 #ifndef EH_FRAME_SECTION_NAME
1973 dw2_asm_output_data (4, 0, "End of Table");
1975 #ifdef MIPS_DEBUGGING_INFO
1976 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1977 get a value of 0. Putting .align 0 after the label fixes it. */
1978 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1981 /* Turn off app to make assembly quicker. */
1986 /* Output a marker (i.e. a label) for the beginning of a function, before
1990 dwarf2out_begin_prologue (line, file)
1991 unsigned int line ATTRIBUTE_UNUSED;
1992 const char *file ATTRIBUTE_UNUSED;
1994 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1995 register dw_fde_ref fde;
1997 current_function_func_begin_label = 0;
1999 #ifdef IA64_UNWIND_INFO
2000 /* ??? current_function_func_begin_label is also used by except.c
2001 for call-site information. We must emit this label if it might
2003 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2004 && ! dwarf2out_do_frame ())
2007 if (! dwarf2out_do_frame ())
2011 ++current_funcdef_number;
2013 function_section (current_function_decl);
2014 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2015 current_funcdef_number);
2016 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2017 current_funcdef_number);
2018 current_function_func_begin_label = get_identifier (label);
2020 #ifdef IA64_UNWIND_INFO
2021 /* We can elide the fde allocation if we're not emitting debug info. */
2022 if (! dwarf2out_do_frame ())
2026 /* Expand the fde table if necessary. */
2027 if (fde_table_in_use == fde_table_allocated)
2029 fde_table_allocated += FDE_TABLE_INCREMENT;
2031 = (dw_fde_ref) xrealloc (fde_table,
2032 fde_table_allocated * sizeof (dw_fde_node));
2035 /* Record the FDE associated with this function. */
2036 current_funcdef_fde = fde_table_in_use;
2038 /* Add the new FDE at the end of the fde_table. */
2039 fde = &fde_table[fde_table_in_use++];
2040 fde->dw_fde_begin = xstrdup (label);
2041 fde->dw_fde_current_label = NULL;
2042 fde->dw_fde_end = NULL;
2043 fde->dw_fde_cfi = NULL;
2044 fde->funcdef_number = current_funcdef_number;
2045 fde->nothrow = current_function_nothrow;
2046 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2048 args_size = old_args_size = 0;
2050 /* We only want to output line number information for the genuine
2051 dwarf2 prologue case, not the eh frame case. */
2052 #ifdef DWARF2_DEBUGGING_INFO
2054 dwarf2out_source_line (line, file);
2058 /* Output a marker (i.e. a label) for the absolute end of the generated code
2059 for a function definition. This gets called *after* the epilogue code has
2063 dwarf2out_end_epilogue ()
2066 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2068 /* Output a label to mark the endpoint of the code generated for this
2070 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2071 ASM_OUTPUT_LABEL (asm_out_file, label);
2072 fde = &fde_table[fde_table_in_use - 1];
2073 fde->dw_fde_end = xstrdup (label);
2077 dwarf2out_frame_init ()
2079 /* Allocate the initial hunk of the fde_table. */
2080 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2081 fde_table_allocated = FDE_TABLE_INCREMENT;
2082 fde_table_in_use = 0;
2084 /* Generate the CFA instructions common to all FDE's. Do it now for the
2085 sake of lookup_cfa. */
2087 #ifdef DWARF2_UNWIND_INFO
2088 /* On entry, the Canonical Frame Address is at SP. */
2089 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2090 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2095 dwarf2out_frame_finish ()
2097 /* Output call frame information. */
2098 #ifdef MIPS_DEBUGGING_INFO
2099 if (write_symbols == DWARF2_DEBUG)
2100 output_call_frame_info (0);
2101 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2102 output_call_frame_info (1);
2104 int for_eh = (! USING_SJLJ_EXCEPTIONS
2105 && (flag_unwind_tables || flag_exceptions));
2106 if (write_symbols == DWARF2_DEBUG || for_eh)
2107 output_call_frame_info (for_eh);
2111 /* And now, the subset of the debugging information support code necessary
2112 for emitting location expressions. */
2114 typedef struct dw_val_struct *dw_val_ref;
2115 typedef struct die_struct *dw_die_ref;
2116 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2117 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2119 /* Each DIE may have a series of attribute/value pairs. Values
2120 can take on several forms. The forms that are used in this
2121 implementation are listed below. */
2126 dw_val_class_offset,
2128 dw_val_class_loc_list,
2130 dw_val_class_unsigned_const,
2131 dw_val_class_long_long,
2134 dw_val_class_die_ref,
2135 dw_val_class_fde_ref,
2136 dw_val_class_lbl_id,
2137 dw_val_class_lbl_offset,
2142 /* Describe a double word constant value. */
2143 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2145 typedef struct dw_long_long_struct
2152 /* Describe a floating point constant value. */
2154 typedef struct dw_fp_struct
2161 /* The dw_val_node describes an attribute's value, as it is
2162 represented internally. */
2164 typedef struct dw_val_struct
2166 dw_val_class val_class;
2170 long unsigned val_offset;
2171 dw_loc_list_ref val_loc_list;
2172 dw_loc_descr_ref val_loc;
2174 long unsigned val_unsigned;
2175 dw_long_long_const val_long_long;
2176 dw_float_const val_float;
2181 unsigned val_fde_index;
2184 unsigned char val_flag;
2190 /* Locations in memory are described using a sequence of stack machine
2193 typedef struct dw_loc_descr_struct
2195 dw_loc_descr_ref dw_loc_next;
2196 enum dwarf_location_atom dw_loc_opc;
2197 dw_val_node dw_loc_oprnd1;
2198 dw_val_node dw_loc_oprnd2;
2203 /* Location lists are ranges + location descriptions for that range,
2204 so you can track variables that are in different places over
2205 their entire life. */
2206 typedef struct dw_loc_list_struct
2208 dw_loc_list_ref dw_loc_next;
2209 const char *begin; /* Label for begin address of range */
2210 const char *end; /* Label for end address of range */
2211 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2212 const char *section; /* Section this loclist is relative to */
2213 dw_loc_descr_ref expr;
2216 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2217 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2220 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2222 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2223 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2224 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2225 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2227 /* Convert a DWARF stack opcode into its string name. */
2230 dwarf_stack_op_name (op)
2231 register unsigned op;
2236 return "DW_OP_addr";
2238 return "DW_OP_deref";
2240 return "DW_OP_const1u";
2242 return "DW_OP_const1s";
2244 return "DW_OP_const2u";
2246 return "DW_OP_const2s";
2248 return "DW_OP_const4u";
2250 return "DW_OP_const4s";
2252 return "DW_OP_const8u";
2254 return "DW_OP_const8s";
2256 return "DW_OP_constu";
2258 return "DW_OP_consts";
2262 return "DW_OP_drop";
2264 return "DW_OP_over";
2266 return "DW_OP_pick";
2268 return "DW_OP_swap";
2272 return "DW_OP_xderef";
2280 return "DW_OP_minus";
2292 return "DW_OP_plus";
2293 case DW_OP_plus_uconst:
2294 return "DW_OP_plus_uconst";
2300 return "DW_OP_shra";
2318 return "DW_OP_skip";
2320 return "DW_OP_lit0";
2322 return "DW_OP_lit1";
2324 return "DW_OP_lit2";
2326 return "DW_OP_lit3";
2328 return "DW_OP_lit4";
2330 return "DW_OP_lit5";
2332 return "DW_OP_lit6";
2334 return "DW_OP_lit7";
2336 return "DW_OP_lit8";
2338 return "DW_OP_lit9";
2340 return "DW_OP_lit10";
2342 return "DW_OP_lit11";
2344 return "DW_OP_lit12";
2346 return "DW_OP_lit13";
2348 return "DW_OP_lit14";
2350 return "DW_OP_lit15";
2352 return "DW_OP_lit16";
2354 return "DW_OP_lit17";
2356 return "DW_OP_lit18";
2358 return "DW_OP_lit19";
2360 return "DW_OP_lit20";
2362 return "DW_OP_lit21";
2364 return "DW_OP_lit22";
2366 return "DW_OP_lit23";
2368 return "DW_OP_lit24";
2370 return "DW_OP_lit25";
2372 return "DW_OP_lit26";
2374 return "DW_OP_lit27";
2376 return "DW_OP_lit28";
2378 return "DW_OP_lit29";
2380 return "DW_OP_lit30";
2382 return "DW_OP_lit31";
2384 return "DW_OP_reg0";
2386 return "DW_OP_reg1";
2388 return "DW_OP_reg2";
2390 return "DW_OP_reg3";
2392 return "DW_OP_reg4";
2394 return "DW_OP_reg5";
2396 return "DW_OP_reg6";
2398 return "DW_OP_reg7";
2400 return "DW_OP_reg8";
2402 return "DW_OP_reg9";
2404 return "DW_OP_reg10";
2406 return "DW_OP_reg11";
2408 return "DW_OP_reg12";
2410 return "DW_OP_reg13";
2412 return "DW_OP_reg14";
2414 return "DW_OP_reg15";
2416 return "DW_OP_reg16";
2418 return "DW_OP_reg17";
2420 return "DW_OP_reg18";
2422 return "DW_OP_reg19";
2424 return "DW_OP_reg20";
2426 return "DW_OP_reg21";
2428 return "DW_OP_reg22";
2430 return "DW_OP_reg23";
2432 return "DW_OP_reg24";
2434 return "DW_OP_reg25";
2436 return "DW_OP_reg26";
2438 return "DW_OP_reg27";
2440 return "DW_OP_reg28";
2442 return "DW_OP_reg29";
2444 return "DW_OP_reg30";
2446 return "DW_OP_reg31";
2448 return "DW_OP_breg0";
2450 return "DW_OP_breg1";
2452 return "DW_OP_breg2";
2454 return "DW_OP_breg3";
2456 return "DW_OP_breg4";
2458 return "DW_OP_breg5";
2460 return "DW_OP_breg6";
2462 return "DW_OP_breg7";
2464 return "DW_OP_breg8";
2466 return "DW_OP_breg9";
2468 return "DW_OP_breg10";
2470 return "DW_OP_breg11";
2472 return "DW_OP_breg12";
2474 return "DW_OP_breg13";
2476 return "DW_OP_breg14";
2478 return "DW_OP_breg15";
2480 return "DW_OP_breg16";
2482 return "DW_OP_breg17";
2484 return "DW_OP_breg18";
2486 return "DW_OP_breg19";
2488 return "DW_OP_breg20";
2490 return "DW_OP_breg21";
2492 return "DW_OP_breg22";
2494 return "DW_OP_breg23";
2496 return "DW_OP_breg24";
2498 return "DW_OP_breg25";
2500 return "DW_OP_breg26";
2502 return "DW_OP_breg27";
2504 return "DW_OP_breg28";
2506 return "DW_OP_breg29";
2508 return "DW_OP_breg30";
2510 return "DW_OP_breg31";
2512 return "DW_OP_regx";
2514 return "DW_OP_fbreg";
2516 return "DW_OP_bregx";
2518 return "DW_OP_piece";
2519 case DW_OP_deref_size:
2520 return "DW_OP_deref_size";
2521 case DW_OP_xderef_size:
2522 return "DW_OP_xderef_size";
2526 return "OP_<unknown>";
2530 /* Return a pointer to a newly allocated location description. Location
2531 descriptions are simple expression terms that can be strung
2532 together to form more complicated location (address) descriptions. */
2534 static inline dw_loc_descr_ref
2535 new_loc_descr (op, oprnd1, oprnd2)
2536 register enum dwarf_location_atom op;
2537 register unsigned long oprnd1;
2538 register unsigned long oprnd2;
2540 /* Use xcalloc here so we clear out all of the long_long constant in
2542 register dw_loc_descr_ref descr
2543 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2545 descr->dw_loc_opc = op;
2546 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2547 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2548 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2549 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2555 /* Add a location description term to a location description expression. */
2558 add_loc_descr (list_head, descr)
2559 register dw_loc_descr_ref *list_head;
2560 register dw_loc_descr_ref descr;
2562 register dw_loc_descr_ref *d;
2564 /* Find the end of the chain. */
2565 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2571 /* Return the size of a location descriptor. */
2573 static unsigned long
2574 size_of_loc_descr (loc)
2575 register dw_loc_descr_ref loc;
2577 register unsigned long size = 1;
2579 switch (loc->dw_loc_opc)
2582 size += DWARF2_ADDR_SIZE;
2601 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2604 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2609 case DW_OP_plus_uconst:
2610 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2648 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2651 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2654 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2657 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2658 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2661 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2663 case DW_OP_deref_size:
2664 case DW_OP_xderef_size:
2674 /* Return the size of a series of location descriptors. */
2676 static unsigned long
2678 register dw_loc_descr_ref loc;
2680 register unsigned long size = 0;
2682 for (; loc != NULL; loc = loc->dw_loc_next)
2684 loc->dw_loc_addr = size;
2685 size += size_of_loc_descr (loc);
2691 /* Output location description stack opcode's operands (if any). */
2694 output_loc_operands (loc)
2695 register dw_loc_descr_ref loc;
2697 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2698 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2700 switch (loc->dw_loc_opc)
2702 #ifdef DWARF2_DEBUGGING_INFO
2704 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2708 dw2_asm_output_data (2, val1->v.val_int, NULL);
2712 dw2_asm_output_data (4, val1->v.val_int, NULL);
2716 if (HOST_BITS_PER_LONG < 64)
2718 dw2_asm_output_data (8, val1->v.val_int, NULL);
2725 if (val1->val_class == dw_val_class_loc)
2726 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2730 dw2_asm_output_data (2, offset, NULL);
2743 /* We currently don't make any attempt to make sure these are
2744 aligned properly like we do for the main unwind info, so
2745 don't support emitting things larger than a byte if we're
2746 only doing unwinding. */
2751 dw2_asm_output_data (1, val1->v.val_int, NULL);
2754 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2757 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2760 dw2_asm_output_data (1, val1->v.val_int, NULL);
2762 case DW_OP_plus_uconst:
2763 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2797 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2800 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2803 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2806 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2807 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2810 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2812 case DW_OP_deref_size:
2813 case DW_OP_xderef_size:
2814 dw2_asm_output_data (1, val1->v.val_int, NULL);
2817 /* Other codes have no operands. */
2822 /* Output a sequence of location operations. */
2825 output_loc_sequence (loc)
2826 dw_loc_descr_ref loc;
2828 for (; loc != NULL; loc = loc->dw_loc_next)
2830 /* Output the opcode. */
2831 dw2_asm_output_data (1, loc->dw_loc_opc,
2832 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2834 /* Output the operand(s) (if any). */
2835 output_loc_operands (loc);
2839 /* This routine will generate the correct assembly data for a location
2840 description based on a cfi entry with a complex address. */
2843 output_cfa_loc (cfi)
2846 dw_loc_descr_ref loc;
2849 /* Output the size of the block. */
2850 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2851 size = size_of_locs (loc);
2852 dw2_asm_output_data_uleb128 (size, NULL);
2854 /* Now output the operations themselves. */
2855 output_loc_sequence (loc);
2858 /* This function builds a dwarf location descriptor sequence from
2859 a dw_cfa_location. */
2861 static struct dw_loc_descr_struct *
2863 dw_cfa_location *cfa;
2865 struct dw_loc_descr_struct *head, *tmp;
2867 if (cfa->indirect == 0)
2870 if (cfa->base_offset)
2873 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2875 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2877 else if (cfa->reg <= 31)
2878 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2880 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2881 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2882 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2883 add_loc_descr (&head, tmp);
2884 if (cfa->offset != 0)
2886 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2887 add_loc_descr (&head, tmp);
2892 /* This function fills in aa dw_cfa_location structure from a
2893 dwarf location descriptor sequence. */
2896 get_cfa_from_loc_descr (cfa, loc)
2897 dw_cfa_location *cfa;
2898 struct dw_loc_descr_struct *loc;
2900 struct dw_loc_descr_struct *ptr;
2902 cfa->base_offset = 0;
2906 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2908 enum dwarf_location_atom op = ptr->dw_loc_opc;
2943 cfa->reg = op - DW_OP_reg0;
2946 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2980 cfa->reg = op - DW_OP_breg0;
2981 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2984 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2985 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2990 case DW_OP_plus_uconst:
2991 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2994 internal_error ("DW_LOC_OP %s not implememnted\n",
2995 dwarf_stack_op_name (ptr->dw_loc_opc));
2999 #endif /* .debug_frame support */
3001 /* And now, the support for symbolic debugging information. */
3002 #ifdef DWARF2_DEBUGGING_INFO
3004 static void dwarf2out_init PARAMS ((const char *));
3005 static void dwarf2out_finish PARAMS ((const char *));
3006 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3007 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3008 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3009 static void dwarf2out_end_source_file PARAMS ((unsigned));
3010 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3011 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3012 static bool dwarf2out_ignore_block PARAMS ((tree));
3013 static void dwarf2out_global_decl PARAMS ((tree));
3014 static void dwarf2out_abstract_function PARAMS ((tree));
3016 /* The debug hooks structure. */
3018 struct gcc_debug_hooks dwarf2_debug_hooks =
3024 dwarf2out_start_source_file,
3025 dwarf2out_end_source_file,
3026 dwarf2out_begin_block,
3027 dwarf2out_end_block,
3028 dwarf2out_ignore_block,
3029 dwarf2out_source_line,
3030 dwarf2out_begin_prologue,
3031 debug_nothing_int, /* end_prologue */
3032 dwarf2out_end_epilogue,
3033 debug_nothing_tree, /* begin_function */
3034 debug_nothing_int, /* end_function */
3035 dwarf2out_decl, /* function_decl */
3036 dwarf2out_global_decl,
3037 debug_nothing_tree, /* deferred_inline_function */
3038 /* The DWARF 2 backend tries to reduce debugging bloat by not
3039 emitting the abstract description of inline functions until
3040 something tries to reference them. */
3041 dwarf2out_abstract_function, /* outlining_inline_function */
3042 debug_nothing_rtx /* label */
3045 /* NOTE: In the comments in this file, many references are made to
3046 "Debugging Information Entries". This term is abbreviated as `DIE'
3047 throughout the remainder of this file. */
3049 /* An internal representation of the DWARF output is built, and then
3050 walked to generate the DWARF debugging info. The walk of the internal
3051 representation is done after the entire program has been compiled.
3052 The types below are used to describe the internal representation. */
3054 /* Various DIE's use offsets relative to the beginning of the
3055 .debug_info section to refer to each other. */
3057 typedef long int dw_offset;
3059 /* Define typedefs here to avoid circular dependencies. */
3061 typedef struct dw_attr_struct *dw_attr_ref;
3062 typedef struct dw_line_info_struct *dw_line_info_ref;
3063 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3064 typedef struct pubname_struct *pubname_ref;
3065 typedef struct dw_ranges_struct *dw_ranges_ref;
3067 /* Each entry in the line_info_table maintains the file and
3068 line number associated with the label generated for that
3069 entry. The label gives the PC value associated with
3070 the line number entry. */
3072 typedef struct dw_line_info_struct
3074 unsigned long dw_file_num;
3075 unsigned long dw_line_num;
3079 /* Line information for functions in separate sections; each one gets its
3081 typedef struct dw_separate_line_info_struct
3083 unsigned long dw_file_num;
3084 unsigned long dw_line_num;
3085 unsigned long function;
3087 dw_separate_line_info_entry;
3089 /* Each DIE attribute has a field specifying the attribute kind,
3090 a link to the next attribute in the chain, and an attribute value.
3091 Attributes are typically linked below the DIE they modify. */
3093 typedef struct dw_attr_struct
3095 enum dwarf_attribute dw_attr;
3096 dw_attr_ref dw_attr_next;
3097 dw_val_node dw_attr_val;
3101 /* The Debugging Information Entry (DIE) structure */
3103 typedef struct die_struct
3105 enum dwarf_tag die_tag;
3107 dw_attr_ref die_attr;
3108 dw_die_ref die_parent;
3109 dw_die_ref die_child;
3111 dw_offset die_offset;
3112 unsigned long die_abbrev;
3117 /* The pubname structure */
3119 typedef struct pubname_struct
3126 struct dw_ranges_struct
3131 /* The limbo die list structure. */
3132 typedef struct limbo_die_struct
3135 struct limbo_die_struct *next;
3139 /* How to start an assembler comment. */
3140 #ifndef ASM_COMMENT_START
3141 #define ASM_COMMENT_START ";#"
3144 /* Define a macro which returns non-zero for a TYPE_DECL which was
3145 implicitly generated for a tagged type.
3147 Note that unlike the gcc front end (which generates a NULL named
3148 TYPE_DECL node for each complete tagged type, each array type, and
3149 each function type node created) the g++ front end generates a
3150 _named_ TYPE_DECL node for each tagged type node created.
3151 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3152 generate a DW_TAG_typedef DIE for them. */
3154 #define TYPE_DECL_IS_STUB(decl) \
3155 (DECL_NAME (decl) == NULL_TREE \
3156 || (DECL_ARTIFICIAL (decl) \
3157 && is_tagged_type (TREE_TYPE (decl)) \
3158 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3159 /* This is necessary for stub decls that \
3160 appear in nested inline functions. */ \
3161 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3162 && (decl_ultimate_origin (decl) \
3163 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3165 /* Information concerning the compilation unit's programming
3166 language, and compiler version. */
3168 extern int flag_traditional;
3170 /* Fixed size portion of the DWARF compilation unit header. */
3171 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3173 /* Fixed size portion of debugging line information prolog. */
3174 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3176 /* Fixed size portion of public names info. */
3177 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3179 /* Fixed size portion of the address range info. */
3180 #define DWARF_ARANGES_HEADER_SIZE \
3181 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3182 - DWARF_OFFSET_SIZE)
3184 /* Size of padding portion in the address range info. It must be
3185 aligned to twice the pointer size. */
3186 #define DWARF_ARANGES_PAD_SIZE \
3187 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3188 - (2 * DWARF_OFFSET_SIZE + 4))
3190 /* Use assembler line directives if available. */
3191 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3192 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3193 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3195 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3199 /* Define the architecture-dependent minimum instruction length (in bytes).
3200 In this implementation of DWARF, this field is used for information
3201 purposes only. Since GCC generates assembly language, we have
3202 no a priori knowledge of how many instruction bytes are generated
3203 for each source line, and therefore can use only the DW_LNE_set_address
3204 and DW_LNS_fixed_advance_pc line information commands. */
3206 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3207 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3210 /* Minimum line offset in a special line info. opcode.
3211 This value was chosen to give a reasonable range of values. */
3212 #define DWARF_LINE_BASE -10
3214 /* First special line opcde - leave room for the standard opcodes. */
3215 #define DWARF_LINE_OPCODE_BASE 10
3217 /* Range of line offsets in a special line info. opcode. */
3218 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3220 /* Flag that indicates the initial value of the is_stmt_start flag.
3221 In the present implementation, we do not mark any lines as
3222 the beginning of a source statement, because that information
3223 is not made available by the GCC front-end. */
3224 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3226 /* This location is used by calc_die_sizes() to keep track
3227 the offset of each DIE within the .debug_info section. */
3228 static unsigned long next_die_offset;
3230 /* Record the root of the DIE's built for the current compilation unit. */
3231 static dw_die_ref comp_unit_die;
3233 /* A list of DIEs with a NULL parent waiting to be relocated. */
3234 static limbo_die_node *limbo_die_list = 0;
3236 /* Structure used by lookup_filename to manage sets of filenames. */
3242 unsigned last_lookup_index;
3245 /* Size (in elements) of increments by which we may expand the filename
3247 #define FILE_TABLE_INCREMENT 64
3249 /* Filenames referenced by this compilation unit. */
3250 static struct file_table file_table;
3252 /* Local pointer to the name of the main input file. Initialized in
3254 static const char *primary_filename;
3256 /* A pointer to the base of a table of references to DIE's that describe
3257 declarations. The table is indexed by DECL_UID() which is a unique
3258 number identifying each decl. */
3259 static dw_die_ref *decl_die_table;
3261 /* Number of elements currently allocated for the decl_die_table. */
3262 static unsigned decl_die_table_allocated;
3264 /* Number of elements in decl_die_table currently in use. */
3265 static unsigned decl_die_table_in_use;
3267 /* Size (in elements) of increments by which we may expand the
3269 #define DECL_DIE_TABLE_INCREMENT 256
3271 /* A pointer to the base of a table of references to declaration
3272 scopes. This table is a display which tracks the nesting
3273 of declaration scopes at the current scope and containing
3274 scopes. This table is used to find the proper place to
3275 define type declaration DIE's. */
3276 static tree *decl_scope_table;
3278 /* Number of elements currently allocated for the decl_scope_table. */
3279 static int decl_scope_table_allocated;
3281 /* Current level of nesting of declaration scopes. */
3282 static int decl_scope_depth;
3284 /* Size (in elements) of increments by which we may expand the
3285 decl_scope_table. */
3286 #define DECL_SCOPE_TABLE_INCREMENT 64
3288 /* A pointer to the base of a list of references to DIE's that
3289 are uniquely identified by their tag, presence/absence of
3290 children DIE's, and list of attribute/value pairs. */
3291 static dw_die_ref *abbrev_die_table;
3293 /* Number of elements currently allocated for abbrev_die_table. */
3294 static unsigned abbrev_die_table_allocated;
3296 /* Number of elements in type_die_table currently in use. */
3297 static unsigned abbrev_die_table_in_use;
3299 /* Size (in elements) of increments by which we may expand the
3300 abbrev_die_table. */
3301 #define ABBREV_DIE_TABLE_INCREMENT 256
3303 /* A pointer to the base of a table that contains line information
3304 for each source code line in .text in the compilation unit. */
3305 static dw_line_info_ref line_info_table;
3307 /* Number of elements currently allocated for line_info_table. */
3308 static unsigned line_info_table_allocated;
3310 /* Number of elements in separate_line_info_table currently in use. */
3311 static unsigned separate_line_info_table_in_use;
3313 /* A pointer to the base of a table that contains line information
3314 for each source code line outside of .text in the compilation unit. */
3315 static dw_separate_line_info_ref separate_line_info_table;
3317 /* Number of elements currently allocated for separate_line_info_table. */
3318 static unsigned separate_line_info_table_allocated;
3320 /* Number of elements in line_info_table currently in use. */
3321 static unsigned line_info_table_in_use;
3323 /* Size (in elements) of increments by which we may expand the
3325 #define LINE_INFO_TABLE_INCREMENT 1024
3327 /* A pointer to the base of a table that contains a list of publicly
3328 accessible names. */
3329 static pubname_ref pubname_table;
3331 /* Number of elements currently allocated for pubname_table. */
3332 static unsigned pubname_table_allocated;
3334 /* Number of elements in pubname_table currently in use. */
3335 static unsigned pubname_table_in_use;
3337 /* Size (in elements) of increments by which we may expand the
3339 #define PUBNAME_TABLE_INCREMENT 64
3341 /* Array of dies for which we should generate .debug_arange info. */
3342 static dw_die_ref *arange_table;
3344 /* Number of elements currently allocated for arange_table. */
3345 static unsigned arange_table_allocated;
3347 /* Number of elements in arange_table currently in use. */
3348 static unsigned arange_table_in_use;
3350 /* Size (in elements) of increments by which we may expand the
3352 #define ARANGE_TABLE_INCREMENT 64
3354 /* Array of dies for which we should generate .debug_ranges info. */
3355 static dw_ranges_ref ranges_table;
3357 /* Number of elements currently allocated for ranges_table. */
3358 static unsigned ranges_table_allocated;
3360 /* Number of elements in ranges_table currently in use. */
3361 static unsigned ranges_table_in_use;
3363 /* Size (in elements) of increments by which we may expand the
3365 #define RANGES_TABLE_INCREMENT 64
3367 /* Whether we have location lists that need outputting */
3368 static unsigned have_location_lists;
3370 /* A pointer to the base of a list of incomplete types which might be
3371 completed at some later time. */
3373 static tree *incomplete_types_list;
3375 /* Number of elements currently allocated for the incomplete_types_list. */
3376 static unsigned incomplete_types_allocated;
3378 /* Number of elements of incomplete_types_list currently in use. */
3379 static unsigned incomplete_types;
3381 /* Size (in elements) of increments by which we may expand the incomplete
3382 types list. Actually, a single hunk of space of this size should
3383 be enough for most typical programs. */
3384 #define INCOMPLETE_TYPES_INCREMENT 64
3386 /* Record whether the function being analyzed contains inlined functions. */
3387 static int current_function_has_inlines;
3388 #if 0 && defined (MIPS_DEBUGGING_INFO)
3389 static int comp_unit_has_inlines;
3392 /* Array of RTXes referenced by the debugging information, which therefore
3393 must be kept around forever. We do this rather than perform GC on
3394 the dwarf info because almost all of the dwarf info lives forever, and
3395 it's easier to support non-GC frontends this way. */
3396 static varray_type used_rtx_varray;
3398 /* Forward declarations for functions defined in this file. */
3400 static int is_pseudo_reg PARAMS ((rtx));
3401 static tree type_main_variant PARAMS ((tree));
3402 static int is_tagged_type PARAMS ((tree));
3403 static const char *dwarf_tag_name PARAMS ((unsigned));
3404 static const char *dwarf_attr_name PARAMS ((unsigned));
3405 static const char *dwarf_form_name PARAMS ((unsigned));
3407 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3409 static tree decl_ultimate_origin PARAMS ((tree));
3410 static tree block_ultimate_origin PARAMS ((tree));
3411 static tree decl_class_context PARAMS ((tree));
3412 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3413 static void add_AT_flag PARAMS ((dw_die_ref,
3414 enum dwarf_attribute,
3416 static void add_AT_int PARAMS ((dw_die_ref,
3417 enum dwarf_attribute, long));
3418 static void add_AT_unsigned PARAMS ((dw_die_ref,
3419 enum dwarf_attribute,
3421 static void add_AT_long_long PARAMS ((dw_die_ref,
3422 enum dwarf_attribute,
3425 static void add_AT_float PARAMS ((dw_die_ref,
3426 enum dwarf_attribute,
3428 static void add_AT_string PARAMS ((dw_die_ref,
3429 enum dwarf_attribute,
3431 static void add_AT_die_ref PARAMS ((dw_die_ref,
3432 enum dwarf_attribute,
3434 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3435 enum dwarf_attribute,
3437 static void add_AT_loc PARAMS ((dw_die_ref,
3438 enum dwarf_attribute,
3440 static void add_AT_loc_list PARAMS ((dw_die_ref,
3441 enum dwarf_attribute,
3443 static void add_AT_addr PARAMS ((dw_die_ref,
3444 enum dwarf_attribute,
3446 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3447 enum dwarf_attribute,
3449 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3450 enum dwarf_attribute,
3452 static void add_AT_offset PARAMS ((dw_die_ref,
3453 enum dwarf_attribute,
3455 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3456 enum dwarf_attribute));
3457 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3458 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3459 static const char *get_AT_string PARAMS ((dw_die_ref,
3460 enum dwarf_attribute));
3461 static int get_AT_flag PARAMS ((dw_die_ref,
3462 enum dwarf_attribute));
3463 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3464 enum dwarf_attribute));
3465 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3466 enum dwarf_attribute));
3467 static int is_c_family PARAMS ((void));
3468 static int is_java PARAMS ((void));
3469 static int is_fortran PARAMS ((void));
3470 static void remove_AT PARAMS ((dw_die_ref,
3471 enum dwarf_attribute));
3472 static void remove_children PARAMS ((dw_die_ref));
3473 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3474 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3475 static dw_die_ref lookup_type_die PARAMS ((tree));
3476 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3477 static dw_die_ref lookup_decl_die PARAMS ((tree));
3478 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3479 static void print_spaces PARAMS ((FILE *));
3480 static void print_die PARAMS ((dw_die_ref, FILE *));
3481 static void print_dwarf_line_table PARAMS ((FILE *));
3482 static void reverse_die_lists PARAMS ((dw_die_ref));
3483 static void reverse_all_dies PARAMS ((dw_die_ref));
3484 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3485 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3486 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3487 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3488 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3489 static void compute_section_prefix PARAMS ((dw_die_ref));
3490 static int is_type_die PARAMS ((dw_die_ref));
3491 static int is_comdat_die PARAMS ((dw_die_ref));
3492 static int is_symbol_die PARAMS ((dw_die_ref));
3493 static void assign_symbol_names PARAMS ((dw_die_ref));
3494 static void break_out_includes PARAMS ((dw_die_ref));
3495 static void add_sibling_attributes PARAMS ((dw_die_ref));
3496 static void build_abbrev_table PARAMS ((dw_die_ref));
3497 static void output_location_lists PARAMS ((dw_die_ref));
3498 static unsigned long size_of_string PARAMS ((const char *));
3499 static int constant_size PARAMS ((long unsigned));
3500 static unsigned long size_of_die PARAMS ((dw_die_ref));
3501 static void calc_die_sizes PARAMS ((dw_die_ref));
3502 static void mark_dies PARAMS ((dw_die_ref));
3503 static void unmark_dies PARAMS ((dw_die_ref));
3504 static unsigned long size_of_pubnames PARAMS ((void));
3505 static unsigned long size_of_aranges PARAMS ((void));
3506 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3507 static void output_value_format PARAMS ((dw_attr_ref));
3508 static void output_abbrev_section PARAMS ((void));
3509 static void output_die_symbol PARAMS ((dw_die_ref));
3510 static void output_die PARAMS ((dw_die_ref));
3511 static void output_compilation_unit_header PARAMS ((void));
3512 static void output_comp_unit PARAMS ((dw_die_ref));
3513 static const char *dwarf2_name PARAMS ((tree, int));
3514 static void add_pubname PARAMS ((tree, dw_die_ref));
3515 static void output_pubnames PARAMS ((void));
3516 static void add_arange PARAMS ((tree, dw_die_ref));
3517 static void output_aranges PARAMS ((void));
3518 static unsigned int add_ranges PARAMS ((tree));
3519 static void output_ranges PARAMS ((void));
3520 static void output_line_info PARAMS ((void));
3521 static void output_file_names PARAMS ((void));
3522 static dw_die_ref base_type_die PARAMS ((tree));
3523 static tree root_type PARAMS ((tree));
3524 static int is_base_type PARAMS ((tree));
3525 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3526 static int type_is_enum PARAMS ((tree));
3527 static unsigned int reg_number PARAMS ((rtx));
3528 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3529 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3530 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3531 static int is_based_loc PARAMS ((rtx));
3532 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3533 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3534 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3535 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3536 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3537 static tree field_type PARAMS ((tree));
3538 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3539 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3540 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3541 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3542 static void add_AT_location_description PARAMS ((dw_die_ref,
3543 enum dwarf_attribute, rtx));
3544 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3545 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3546 static rtx rtl_for_decl_location PARAMS ((tree));
3547 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3548 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3549 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3550 static void add_bound_info PARAMS ((dw_die_ref,
3551 enum dwarf_attribute, tree));
3552 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3553 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3554 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3555 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3556 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3557 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3558 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3559 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3560 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3561 static void push_decl_scope PARAMS ((tree));
3562 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3563 static void pop_decl_scope PARAMS ((void));
3564 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3566 static const char *type_tag PARAMS ((tree));
3567 static tree member_declared_type PARAMS ((tree));
3569 static const char *decl_start_label PARAMS ((tree));
3571 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3572 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3574 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3576 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3577 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3578 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3579 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3580 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3581 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3582 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3583 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3584 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3585 static void gen_label_die PARAMS ((tree, dw_die_ref));
3586 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3587 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3588 static void gen_field_die PARAMS ((tree, dw_die_ref));
3589 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3590 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3591 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3592 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3593 static void gen_member_die PARAMS ((tree, dw_die_ref));
3594 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3595 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3596 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3597 static void gen_type_die PARAMS ((tree, dw_die_ref));
3598 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3599 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3600 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3601 static int is_redundant_typedef PARAMS ((tree));
3602 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3603 static unsigned lookup_filename PARAMS ((const char *));
3604 static void init_file_table PARAMS ((void));
3605 static void add_incomplete_type PARAMS ((tree));
3606 static void retry_incomplete_types PARAMS ((void));
3607 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3608 static rtx save_rtx PARAMS ((rtx));
3609 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3610 static int file_info_cmp PARAMS ((const void *, const void *));
3611 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3612 const char *, const char *,
3613 const char *, unsigned));
3614 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3616 const char *, const char *, const char *));
3617 static void output_loc_list PARAMS ((dw_loc_list_ref));
3618 static char *gen_internal_sym PARAMS ((const char *));
3620 /* Section names used to hold DWARF debugging information. */
3621 #ifndef DEBUG_INFO_SECTION
3622 #define DEBUG_INFO_SECTION ".debug_info"
3624 #ifndef DEBUG_ABBREV_SECTION
3625 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3627 #ifndef DEBUG_ARANGES_SECTION
3628 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3630 #ifndef DEBUG_MACINFO_SECTION
3631 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3633 #ifndef DEBUG_LINE_SECTION
3634 #define DEBUG_LINE_SECTION ".debug_line"
3636 #ifndef DEBUG_LOC_SECTION
3637 #define DEBUG_LOC_SECTION ".debug_loc"
3639 #ifndef DEBUG_PUBNAMES_SECTION
3640 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3642 #ifndef DEBUG_STR_SECTION
3643 #define DEBUG_STR_SECTION ".debug_str"
3645 #ifndef DEBUG_RANGES_SECTION
3646 #define DEBUG_RANGES_SECTION ".debug_ranges"
3649 /* Standard ELF section names for compiled code and data. */
3650 #ifndef TEXT_SECTION_NAME
3651 #define TEXT_SECTION_NAME ".text"
3654 /* Labels we insert at beginning sections we can reference instead of
3655 the section names themselves. */
3657 #ifndef TEXT_SECTION_LABEL
3658 #define TEXT_SECTION_LABEL "Ltext"
3660 #ifndef DEBUG_LINE_SECTION_LABEL
3661 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3663 #ifndef DEBUG_INFO_SECTION_LABEL
3664 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3666 #ifndef DEBUG_ABBREV_SECTION_LABEL
3667 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3669 #ifndef DEBUG_LOC_SECTION_LABEL
3670 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3672 #ifndef DEBUG_MACINFO_SECTION_LABEL
3673 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3676 /* Definitions of defaults for formats and names of various special
3677 (artificial) labels which may be generated within this file (when the -g
3678 options is used and DWARF_DEBUGGING_INFO is in effect.
3679 If necessary, these may be overridden from within the tm.h file, but
3680 typically, overriding these defaults is unnecessary. */
3682 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3683 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3684 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3685 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3686 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3687 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3688 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3689 #ifndef TEXT_END_LABEL
3690 #define TEXT_END_LABEL "Letext"
3692 #ifndef DATA_END_LABEL
3693 #define DATA_END_LABEL "Ledata"
3695 #ifndef BSS_END_LABEL
3696 #define BSS_END_LABEL "Lebss"
3698 #ifndef BLOCK_BEGIN_LABEL
3699 #define BLOCK_BEGIN_LABEL "LBB"
3701 #ifndef BLOCK_END_LABEL
3702 #define BLOCK_END_LABEL "LBE"
3704 #ifndef BODY_BEGIN_LABEL
3705 #define BODY_BEGIN_LABEL "Lbb"
3707 #ifndef BODY_END_LABEL
3708 #define BODY_END_LABEL "Lbe"
3710 #ifndef LINE_CODE_LABEL
3711 #define LINE_CODE_LABEL "LM"
3713 #ifndef SEPARATE_LINE_CODE_LABEL
3714 #define SEPARATE_LINE_CODE_LABEL "LSM"
3717 /* We allow a language front-end to designate a function that is to be
3718 called to "demangle" any name before it it put into a DIE. */
3720 static const char *(*demangle_name_func) PARAMS ((const char *));
3723 dwarf2out_set_demangle_name_func (func)
3724 const char *(*func) PARAMS ((const char *));
3726 demangle_name_func = func;
3729 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3730 that means adding it to used_rtx_varray. If not, that means making
3731 a copy on the permanent_obstack. */
3737 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3742 /* Test if rtl node points to a pseudo register. */
3748 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3749 || (GET_CODE (rtl) == SUBREG
3750 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3753 /* Return a reference to a type, with its const and volatile qualifiers
3757 type_main_variant (type)
3760 type = TYPE_MAIN_VARIANT (type);
3762 /* There really should be only one main variant among any group of variants
3763 of a given type (and all of the MAIN_VARIANT values for all members of
3764 the group should point to that one type) but sometimes the C front-end
3765 messes this up for array types, so we work around that bug here. */
3767 if (TREE_CODE (type) == ARRAY_TYPE)
3768 while (type != TYPE_MAIN_VARIANT (type))
3769 type = TYPE_MAIN_VARIANT (type);
3774 /* Return non-zero if the given type node represents a tagged type. */
3777 is_tagged_type (type)
3780 register enum tree_code code = TREE_CODE (type);
3782 return (code == RECORD_TYPE || code == UNION_TYPE
3783 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3786 /* Convert a DIE tag into its string name. */
3789 dwarf_tag_name (tag)
3790 register unsigned tag;
3794 case DW_TAG_padding:
3795 return "DW_TAG_padding";
3796 case DW_TAG_array_type:
3797 return "DW_TAG_array_type";
3798 case DW_TAG_class_type:
3799 return "DW_TAG_class_type";
3800 case DW_TAG_entry_point:
3801 return "DW_TAG_entry_point";
3802 case DW_TAG_enumeration_type:
3803 return "DW_TAG_enumeration_type";
3804 case DW_TAG_formal_parameter:
3805 return "DW_TAG_formal_parameter";
3806 case DW_TAG_imported_declaration:
3807 return "DW_TAG_imported_declaration";
3809 return "DW_TAG_label";
3810 case DW_TAG_lexical_block:
3811 return "DW_TAG_lexical_block";
3813 return "DW_TAG_member";
3814 case DW_TAG_pointer_type:
3815 return "DW_TAG_pointer_type";
3816 case DW_TAG_reference_type:
3817 return "DW_TAG_reference_type";
3818 case DW_TAG_compile_unit:
3819 return "DW_TAG_compile_unit";
3820 case DW_TAG_string_type:
3821 return "DW_TAG_string_type";
3822 case DW_TAG_structure_type:
3823 return "DW_TAG_structure_type";
3824 case DW_TAG_subroutine_type:
3825 return "DW_TAG_subroutine_type";
3826 case DW_TAG_typedef:
3827 return "DW_TAG_typedef";
3828 case DW_TAG_union_type:
3829 return "DW_TAG_union_type";
3830 case DW_TAG_unspecified_parameters:
3831 return "DW_TAG_unspecified_parameters";
3832 case DW_TAG_variant:
3833 return "DW_TAG_variant";
3834 case DW_TAG_common_block:
3835 return "DW_TAG_common_block";
3836 case DW_TAG_common_inclusion:
3837 return "DW_TAG_common_inclusion";
3838 case DW_TAG_inheritance:
3839 return "DW_TAG_inheritance";
3840 case DW_TAG_inlined_subroutine:
3841 return "DW_TAG_inlined_subroutine";
3843 return "DW_TAG_module";
3844 case DW_TAG_ptr_to_member_type:
3845 return "DW_TAG_ptr_to_member_type";
3846 case DW_TAG_set_type:
3847 return "DW_TAG_set_type";
3848 case DW_TAG_subrange_type:
3849 return "DW_TAG_subrange_type";
3850 case DW_TAG_with_stmt:
3851 return "DW_TAG_with_stmt";
3852 case DW_TAG_access_declaration:
3853 return "DW_TAG_access_declaration";
3854 case DW_TAG_base_type:
3855 return "DW_TAG_base_type";
3856 case DW_TAG_catch_block:
3857 return "DW_TAG_catch_block";
3858 case DW_TAG_const_type:
3859 return "DW_TAG_const_type";
3860 case DW_TAG_constant:
3861 return "DW_TAG_constant";
3862 case DW_TAG_enumerator:
3863 return "DW_TAG_enumerator";
3864 case DW_TAG_file_type:
3865 return "DW_TAG_file_type";
3867 return "DW_TAG_friend";
3868 case DW_TAG_namelist:
3869 return "DW_TAG_namelist";
3870 case DW_TAG_namelist_item:
3871 return "DW_TAG_namelist_item";
3872 case DW_TAG_packed_type:
3873 return "DW_TAG_packed_type";
3874 case DW_TAG_subprogram:
3875 return "DW_TAG_subprogram";
3876 case DW_TAG_template_type_param:
3877 return "DW_TAG_template_type_param";
3878 case DW_TAG_template_value_param:
3879 return "DW_TAG_template_value_param";
3880 case DW_TAG_thrown_type:
3881 return "DW_TAG_thrown_type";
3882 case DW_TAG_try_block:
3883 return "DW_TAG_try_block";
3884 case DW_TAG_variant_part:
3885 return "DW_TAG_variant_part";
3886 case DW_TAG_variable:
3887 return "DW_TAG_variable";
3888 case DW_TAG_volatile_type:
3889 return "DW_TAG_volatile_type";
3890 case DW_TAG_MIPS_loop:
3891 return "DW_TAG_MIPS_loop";
3892 case DW_TAG_format_label:
3893 return "DW_TAG_format_label";
3894 case DW_TAG_function_template:
3895 return "DW_TAG_function_template";
3896 case DW_TAG_class_template:
3897 return "DW_TAG_class_template";
3898 case DW_TAG_GNU_BINCL:
3899 return "DW_TAG_GNU_BINCL";
3900 case DW_TAG_GNU_EINCL:
3901 return "DW_TAG_GNU_EINCL";
3903 return "DW_TAG_<unknown>";
3907 /* Convert a DWARF attribute code into its string name. */
3910 dwarf_attr_name (attr)
3911 register unsigned attr;
3916 return "DW_AT_sibling";
3917 case DW_AT_location:
3918 return "DW_AT_location";
3920 return "DW_AT_name";
3921 case DW_AT_ordering:
3922 return "DW_AT_ordering";
3923 case DW_AT_subscr_data:
3924 return "DW_AT_subscr_data";
3925 case DW_AT_byte_size:
3926 return "DW_AT_byte_size";
3927 case DW_AT_bit_offset:
3928 return "DW_AT_bit_offset";
3929 case DW_AT_bit_size:
3930 return "DW_AT_bit_size";
3931 case DW_AT_element_list:
3932 return "DW_AT_element_list";
3933 case DW_AT_stmt_list:
3934 return "DW_AT_stmt_list";
3936 return "DW_AT_low_pc";
3938 return "DW_AT_high_pc";
3939 case DW_AT_language:
3940 return "DW_AT_language";
3942 return "DW_AT_member";
3944 return "DW_AT_discr";
3945 case DW_AT_discr_value:
3946 return "DW_AT_discr_value";
3947 case DW_AT_visibility:
3948 return "DW_AT_visibility";
3950 return "DW_AT_import";
3951 case DW_AT_string_length:
3952 return "DW_AT_string_length";
3953 case DW_AT_common_reference:
3954 return "DW_AT_common_reference";
3955 case DW_AT_comp_dir:
3956 return "DW_AT_comp_dir";
3957 case DW_AT_const_value:
3958 return "DW_AT_const_value";
3959 case DW_AT_containing_type:
3960 return "DW_AT_containing_type";
3961 case DW_AT_default_value:
3962 return "DW_AT_default_value";
3964 return "DW_AT_inline";
3965 case DW_AT_is_optional:
3966 return "DW_AT_is_optional";
3967 case DW_AT_lower_bound:
3968 return "DW_AT_lower_bound";
3969 case DW_AT_producer:
3970 return "DW_AT_producer";
3971 case DW_AT_prototyped:
3972 return "DW_AT_prototyped";
3973 case DW_AT_return_addr:
3974 return "DW_AT_return_addr";
3975 case DW_AT_start_scope:
3976 return "DW_AT_start_scope";
3977 case DW_AT_stride_size:
3978 return "DW_AT_stride_size";
3979 case DW_AT_upper_bound:
3980 return "DW_AT_upper_bound";
3981 case DW_AT_abstract_origin:
3982 return "DW_AT_abstract_origin";
3983 case DW_AT_accessibility:
3984 return "DW_AT_accessibility";
3985 case DW_AT_address_class:
3986 return "DW_AT_address_class";
3987 case DW_AT_artificial:
3988 return "DW_AT_artificial";
3989 case DW_AT_base_types:
3990 return "DW_AT_base_types";
3991 case DW_AT_calling_convention:
3992 return "DW_AT_calling_convention";
3994 return "DW_AT_count";
3995 case DW_AT_data_member_location:
3996 return "DW_AT_data_member_location";
3997 case DW_AT_decl_column:
3998 return "DW_AT_decl_column";
3999 case DW_AT_decl_file:
4000 return "DW_AT_decl_file";
4001 case DW_AT_decl_line:
4002 return "DW_AT_decl_line";
4003 case DW_AT_declaration:
4004 return "DW_AT_declaration";
4005 case DW_AT_discr_list:
4006 return "DW_AT_discr_list";
4007 case DW_AT_encoding:
4008 return "DW_AT_encoding";
4009 case DW_AT_external:
4010 return "DW_AT_external";
4011 case DW_AT_frame_base:
4012 return "DW_AT_frame_base";
4014 return "DW_AT_friend";
4015 case DW_AT_identifier_case:
4016 return "DW_AT_identifier_case";
4017 case DW_AT_macro_info:
4018 return "DW_AT_macro_info";
4019 case DW_AT_namelist_items:
4020 return "DW_AT_namelist_items";
4021 case DW_AT_priority:
4022 return "DW_AT_priority";
4024 return "DW_AT_segment";
4025 case DW_AT_specification:
4026 return "DW_AT_specification";
4027 case DW_AT_static_link:
4028 return "DW_AT_static_link";
4030 return "DW_AT_type";
4031 case DW_AT_use_location:
4032 return "DW_AT_use_location";
4033 case DW_AT_variable_parameter:
4034 return "DW_AT_variable_parameter";
4035 case DW_AT_virtuality:
4036 return "DW_AT_virtuality";
4037 case DW_AT_vtable_elem_location:
4038 return "DW_AT_vtable_elem_location";
4040 case DW_AT_allocated:
4041 return "DW_AT_allocated";
4042 case DW_AT_associated:
4043 return "DW_AT_associated";
4044 case DW_AT_data_location:
4045 return "DW_AT_data_location";
4047 return "DW_AT_stride";
4048 case DW_AT_entry_pc:
4049 return "DW_AT_entry_pc";
4050 case DW_AT_use_UTF8:
4051 return "DW_AT_use_UTF8";
4052 case DW_AT_extension:
4053 return "DW_AT_extension";
4055 return "DW_AT_ranges";
4056 case DW_AT_trampoline:
4057 return "DW_AT_trampoline";
4058 case DW_AT_call_column:
4059 return "DW_AT_call_column";
4060 case DW_AT_call_file:
4061 return "DW_AT_call_file";
4062 case DW_AT_call_line:
4063 return "DW_AT_call_line";
4065 case DW_AT_MIPS_fde:
4066 return "DW_AT_MIPS_fde";
4067 case DW_AT_MIPS_loop_begin:
4068 return "DW_AT_MIPS_loop_begin";
4069 case DW_AT_MIPS_tail_loop_begin:
4070 return "DW_AT_MIPS_tail_loop_begin";
4071 case DW_AT_MIPS_epilog_begin:
4072 return "DW_AT_MIPS_epilog_begin";
4073 case DW_AT_MIPS_loop_unroll_factor:
4074 return "DW_AT_MIPS_loop_unroll_factor";
4075 case DW_AT_MIPS_software_pipeline_depth:
4076 return "DW_AT_MIPS_software_pipeline_depth";
4077 case DW_AT_MIPS_linkage_name:
4078 return "DW_AT_MIPS_linkage_name";
4079 case DW_AT_MIPS_stride:
4080 return "DW_AT_MIPS_stride";
4081 case DW_AT_MIPS_abstract_name:
4082 return "DW_AT_MIPS_abstract_name";
4083 case DW_AT_MIPS_clone_origin:
4084 return "DW_AT_MIPS_clone_origin";
4085 case DW_AT_MIPS_has_inlines:
4086 return "DW_AT_MIPS_has_inlines";
4088 case DW_AT_sf_names:
4089 return "DW_AT_sf_names";
4090 case DW_AT_src_info:
4091 return "DW_AT_src_info";
4092 case DW_AT_mac_info:
4093 return "DW_AT_mac_info";
4094 case DW_AT_src_coords:
4095 return "DW_AT_src_coords";
4096 case DW_AT_body_begin:
4097 return "DW_AT_body_begin";
4098 case DW_AT_body_end:
4099 return "DW_AT_body_end";
4101 return "DW_AT_<unknown>";
4105 /* Convert a DWARF value form code into its string name. */
4108 dwarf_form_name (form)
4109 register unsigned form;
4114 return "DW_FORM_addr";
4115 case DW_FORM_block2:
4116 return "DW_FORM_block2";
4117 case DW_FORM_block4:
4118 return "DW_FORM_block4";
4120 return "DW_FORM_data2";
4122 return "DW_FORM_data4";
4124 return "DW_FORM_data8";
4125 case DW_FORM_string:
4126 return "DW_FORM_string";
4128 return "DW_FORM_block";
4129 case DW_FORM_block1:
4130 return "DW_FORM_block1";
4132 return "DW_FORM_data1";
4134 return "DW_FORM_flag";
4136 return "DW_FORM_sdata";
4138 return "DW_FORM_strp";
4140 return "DW_FORM_udata";
4141 case DW_FORM_ref_addr:
4142 return "DW_FORM_ref_addr";
4144 return "DW_FORM_ref1";
4146 return "DW_FORM_ref2";
4148 return "DW_FORM_ref4";
4150 return "DW_FORM_ref8";
4151 case DW_FORM_ref_udata:
4152 return "DW_FORM_ref_udata";
4153 case DW_FORM_indirect:
4154 return "DW_FORM_indirect";
4156 return "DW_FORM_<unknown>";
4160 /* Convert a DWARF type code into its string name. */
4164 dwarf_type_encoding_name (enc)
4165 register unsigned enc;
4169 case DW_ATE_address:
4170 return "DW_ATE_address";
4171 case DW_ATE_boolean:
4172 return "DW_ATE_boolean";
4173 case DW_ATE_complex_float:
4174 return "DW_ATE_complex_float";
4176 return "DW_ATE_float";
4178 return "DW_ATE_signed";
4179 case DW_ATE_signed_char:
4180 return "DW_ATE_signed_char";
4181 case DW_ATE_unsigned:
4182 return "DW_ATE_unsigned";
4183 case DW_ATE_unsigned_char:
4184 return "DW_ATE_unsigned_char";
4186 return "DW_ATE_<unknown>";
4191 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4192 instance of an inlined instance of a decl which is local to an inline
4193 function, so we have to trace all of the way back through the origin chain
4194 to find out what sort of node actually served as the original seed for the
4198 decl_ultimate_origin (decl)
4201 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4202 nodes in the function to point to themselves; ignore that if
4203 we're trying to output the abstract instance of this function. */
4204 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4207 #ifdef ENABLE_CHECKING
4208 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4209 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4210 most distant ancestor, this should never happen. */
4214 return DECL_ABSTRACT_ORIGIN (decl);
4217 /* Determine the "ultimate origin" of a block. The block may be an inlined
4218 instance of an inlined instance of a block which is local to an inline
4219 function, so we have to trace all of the way back through the origin chain
4220 to find out what sort of node actually served as the original seed for the
4224 block_ultimate_origin (block)
4225 register tree block;
4227 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4229 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4230 nodes in the function to point to themselves; ignore that if
4231 we're trying to output the abstract instance of this function. */
4232 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4235 if (immediate_origin == NULL_TREE)
4239 register tree ret_val;
4240 register tree lookahead = immediate_origin;
4244 ret_val = lookahead;
4245 lookahead = (TREE_CODE (ret_val) == BLOCK)
4246 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4249 while (lookahead != NULL && lookahead != ret_val);
4255 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4256 of a virtual function may refer to a base class, so we check the 'this'
4260 decl_class_context (decl)
4263 tree context = NULL_TREE;
4265 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4266 context = DECL_CONTEXT (decl);
4268 context = TYPE_MAIN_VARIANT
4269 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4271 if (context && !TYPE_P (context))
4272 context = NULL_TREE;
4277 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4278 addition order, and correct that in reverse_all_dies. */
4281 add_dwarf_attr (die, attr)
4282 register dw_die_ref die;
4283 register dw_attr_ref attr;
4285 if (die != NULL && attr != NULL)
4287 attr->dw_attr_next = die->die_attr;
4288 die->die_attr = attr;
4292 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4293 static inline dw_val_class
4297 return a->dw_attr_val.val_class;
4300 /* Add a flag value attribute to a DIE. */
4303 add_AT_flag (die, attr_kind, flag)
4304 register dw_die_ref die;
4305 register enum dwarf_attribute attr_kind;
4306 register unsigned flag;
4308 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4310 attr->dw_attr_next = NULL;
4311 attr->dw_attr = attr_kind;
4312 attr->dw_attr_val.val_class = dw_val_class_flag;
4313 attr->dw_attr_val.v.val_flag = flag;
4314 add_dwarf_attr (die, attr);
4317 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4318 static inline unsigned
4320 register dw_attr_ref a;
4322 if (a && AT_class (a) == dw_val_class_flag)
4323 return a->dw_attr_val.v.val_flag;
4328 /* Add a signed integer attribute value to a DIE. */
4331 add_AT_int (die, attr_kind, int_val)
4332 register dw_die_ref die;
4333 register enum dwarf_attribute attr_kind;
4334 register long int int_val;
4336 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4338 attr->dw_attr_next = NULL;
4339 attr->dw_attr = attr_kind;
4340 attr->dw_attr_val.val_class = dw_val_class_const;
4341 attr->dw_attr_val.v.val_int = int_val;
4342 add_dwarf_attr (die, attr);
4345 static inline long int AT_int PARAMS ((dw_attr_ref));
4346 static inline long int
4348 register dw_attr_ref a;
4350 if (a && AT_class (a) == dw_val_class_const)
4351 return a->dw_attr_val.v.val_int;
4356 /* Add an unsigned integer attribute value to a DIE. */
4359 add_AT_unsigned (die, attr_kind, unsigned_val)
4360 register dw_die_ref die;
4361 register enum dwarf_attribute attr_kind;
4362 register unsigned long unsigned_val;
4364 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4366 attr->dw_attr_next = NULL;
4367 attr->dw_attr = attr_kind;
4368 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4369 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4370 add_dwarf_attr (die, attr);
4373 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4374 static inline unsigned long
4376 register dw_attr_ref a;
4378 if (a && AT_class (a) == dw_val_class_unsigned_const)
4379 return a->dw_attr_val.v.val_unsigned;
4384 /* Add an unsigned double integer attribute value to a DIE. */
4387 add_AT_long_long (die, attr_kind, val_hi, val_low)
4388 register dw_die_ref die;
4389 register enum dwarf_attribute attr_kind;
4390 register unsigned long val_hi;
4391 register unsigned long val_low;
4393 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4395 attr->dw_attr_next = NULL;
4396 attr->dw_attr = attr_kind;
4397 attr->dw_attr_val.val_class = dw_val_class_long_long;
4398 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4399 attr->dw_attr_val.v.val_long_long.low = val_low;
4400 add_dwarf_attr (die, attr);
4403 /* Add a floating point attribute value to a DIE and return it. */
4406 add_AT_float (die, attr_kind, length, array)
4407 register dw_die_ref die;
4408 register enum dwarf_attribute attr_kind;
4409 register unsigned length;
4410 register long *array;
4412 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4414 attr->dw_attr_next = NULL;
4415 attr->dw_attr = attr_kind;
4416 attr->dw_attr_val.val_class = dw_val_class_float;
4417 attr->dw_attr_val.v.val_float.length = length;
4418 attr->dw_attr_val.v.val_float.array = array;
4419 add_dwarf_attr (die, attr);
4422 /* Add a string attribute value to a DIE. */
4425 add_AT_string (die, attr_kind, str)
4426 register dw_die_ref die;
4427 register enum dwarf_attribute attr_kind;
4428 register const char *str;
4430 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4432 attr->dw_attr_next = NULL;
4433 attr->dw_attr = attr_kind;
4434 attr->dw_attr_val.val_class = dw_val_class_str;
4435 attr->dw_attr_val.v.val_str = xstrdup (str);
4436 add_dwarf_attr (die, attr);
4439 static inline const char *AT_string PARAMS ((dw_attr_ref));
4440 static inline const char *
4442 register dw_attr_ref a;
4444 if (a && AT_class (a) == dw_val_class_str)
4445 return a->dw_attr_val.v.val_str;
4450 /* Add a DIE reference attribute value to a DIE. */
4453 add_AT_die_ref (die, attr_kind, targ_die)
4454 register dw_die_ref die;
4455 register enum dwarf_attribute attr_kind;
4456 register dw_die_ref targ_die;
4458 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4460 attr->dw_attr_next = NULL;
4461 attr->dw_attr = attr_kind;
4462 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4463 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4464 attr->dw_attr_val.v.val_die_ref.external = 0;
4465 add_dwarf_attr (die, attr);
4468 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4469 static inline dw_die_ref
4471 register dw_attr_ref a;
4473 if (a && AT_class (a) == dw_val_class_die_ref)
4474 return a->dw_attr_val.v.val_die_ref.die;
4479 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4482 register dw_attr_ref a;
4484 if (a && AT_class (a) == dw_val_class_die_ref)
4485 return a->dw_attr_val.v.val_die_ref.external;
4490 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4492 set_AT_ref_external (a, i)
4493 register dw_attr_ref a;
4496 if (a && AT_class (a) == dw_val_class_die_ref)
4497 a->dw_attr_val.v.val_die_ref.external = i;
4502 /* Add an FDE reference attribute value to a DIE. */
4505 add_AT_fde_ref (die, attr_kind, targ_fde)
4506 register dw_die_ref die;
4507 register enum dwarf_attribute attr_kind;
4508 register unsigned targ_fde;
4510 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4512 attr->dw_attr_next = NULL;
4513 attr->dw_attr = attr_kind;
4514 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4515 attr->dw_attr_val.v.val_fde_index = targ_fde;
4516 add_dwarf_attr (die, attr);
4519 /* Add a location description attribute value to a DIE. */
4522 add_AT_loc (die, attr_kind, loc)
4523 register dw_die_ref die;
4524 register enum dwarf_attribute attr_kind;
4525 register dw_loc_descr_ref loc;
4527 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4529 attr->dw_attr_next = NULL;
4530 attr->dw_attr = attr_kind;
4531 attr->dw_attr_val.val_class = dw_val_class_loc;
4532 attr->dw_attr_val.v.val_loc = loc;
4533 add_dwarf_attr (die, attr);
4536 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4537 static inline dw_loc_descr_ref
4539 register dw_attr_ref a;
4541 if (a && AT_class (a) == dw_val_class_loc)
4542 return a->dw_attr_val.v.val_loc;
4548 add_AT_loc_list (die, attr_kind, loc_list)
4549 register dw_die_ref die;
4550 register enum dwarf_attribute attr_kind;
4551 register dw_loc_list_ref loc_list;
4553 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4555 attr->dw_attr_next = NULL;
4556 attr->dw_attr = attr_kind;
4557 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4558 attr->dw_attr_val.v.val_loc_list = loc_list;
4559 add_dwarf_attr (die, attr);
4560 have_location_lists = 1;
4563 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4565 static inline dw_loc_list_ref
4567 register dw_attr_ref a;
4569 if (a && AT_class (a) == dw_val_class_loc_list)
4570 return a->dw_attr_val.v.val_loc_list;
4575 /* Add an address constant attribute value to a DIE. */
4578 add_AT_addr (die, attr_kind, addr)
4579 register dw_die_ref die;
4580 register enum dwarf_attribute attr_kind;
4583 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4585 attr->dw_attr_next = NULL;
4586 attr->dw_attr = attr_kind;
4587 attr->dw_attr_val.val_class = dw_val_class_addr;
4588 attr->dw_attr_val.v.val_addr = addr;
4589 add_dwarf_attr (die, attr);
4592 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4595 register dw_attr_ref a;
4597 if (a && AT_class (a) == dw_val_class_addr)
4598 return a->dw_attr_val.v.val_addr;
4603 /* Add a label identifier attribute value to a DIE. */
4606 add_AT_lbl_id (die, attr_kind, lbl_id)
4607 register dw_die_ref die;
4608 register enum dwarf_attribute attr_kind;
4609 register const char *lbl_id;
4611 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4613 attr->dw_attr_next = NULL;
4614 attr->dw_attr = attr_kind;
4615 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4616 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4617 add_dwarf_attr (die, attr);
4620 /* Add a section offset attribute value to a DIE. */
4623 add_AT_lbl_offset (die, attr_kind, label)
4624 register dw_die_ref die;
4625 register enum dwarf_attribute attr_kind;
4626 register const char *label;
4628 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4630 attr->dw_attr_next = NULL;
4631 attr->dw_attr = attr_kind;
4632 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4633 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4634 add_dwarf_attr (die, attr);
4637 /* Add an offset attribute value to a DIE. */
4640 add_AT_offset (die, attr_kind, offset)
4641 register dw_die_ref die;
4642 register enum dwarf_attribute attr_kind;
4643 register unsigned long offset;
4645 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4647 attr->dw_attr_next = NULL;
4648 attr->dw_attr = attr_kind;
4649 attr->dw_attr_val.val_class = dw_val_class_offset;
4650 attr->dw_attr_val.v.val_offset = offset;
4651 add_dwarf_attr (die, attr);
4654 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4655 static inline const char *
4657 register dw_attr_ref a;
4659 if (a && (AT_class (a) == dw_val_class_lbl_id
4660 || AT_class (a) == dw_val_class_lbl_offset))
4661 return a->dw_attr_val.v.val_lbl_id;
4666 /* Get the attribute of type attr_kind. */
4668 static inline dw_attr_ref
4669 get_AT (die, attr_kind)
4670 register dw_die_ref die;
4671 register enum dwarf_attribute attr_kind;
4673 register dw_attr_ref a;
4674 register dw_die_ref spec = NULL;
4678 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4680 if (a->dw_attr == attr_kind)
4683 if (a->dw_attr == DW_AT_specification
4684 || a->dw_attr == DW_AT_abstract_origin)
4689 return get_AT (spec, attr_kind);
4695 /* Return the "low pc" attribute value, typically associated with
4696 a subprogram DIE. Return null if the "low pc" attribute is
4697 either not prsent, or if it cannot be represented as an
4698 assembler label identifier. */
4700 static inline const char *
4702 register dw_die_ref die;
4704 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4705 return a ? AT_lbl (a) : NULL;
4708 /* Return the "high pc" attribute value, typically associated with
4709 a subprogram DIE. Return null if the "high pc" attribute is
4710 either not prsent, or if it cannot be represented as an
4711 assembler label identifier. */
4713 static inline const char *
4715 register dw_die_ref die;
4717 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4718 return a ? AT_lbl (a) : NULL;
4721 /* Return the value of the string attribute designated by ATTR_KIND, or
4722 NULL if it is not present. */
4724 static inline const char *
4725 get_AT_string (die, attr_kind)
4726 register dw_die_ref die;
4727 register enum dwarf_attribute attr_kind;
4729 register dw_attr_ref a = get_AT (die, attr_kind);
4730 return a ? AT_string (a) : NULL;
4733 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4734 if it is not present. */
4737 get_AT_flag (die, attr_kind)
4738 register dw_die_ref die;
4739 register enum dwarf_attribute attr_kind;
4741 register dw_attr_ref a = get_AT (die, attr_kind);
4742 return a ? AT_flag (a) : 0;
4745 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4746 if it is not present. */
4748 static inline unsigned
4749 get_AT_unsigned (die, attr_kind)
4750 register dw_die_ref die;
4751 register enum dwarf_attribute attr_kind;
4753 register dw_attr_ref a = get_AT (die, attr_kind);
4754 return a ? AT_unsigned (a) : 0;
4757 static inline dw_die_ref
4758 get_AT_ref (die, attr_kind)
4760 register enum dwarf_attribute attr_kind;
4762 register dw_attr_ref a = get_AT (die, attr_kind);
4763 return a ? AT_ref (a) : NULL;
4769 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4771 return (lang == DW_LANG_C || lang == DW_LANG_C89
4772 || lang == DW_LANG_C_plus_plus);
4778 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4780 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4786 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4788 return (lang == DW_LANG_Java);
4791 /* Free up the memory used by A. */
4793 static inline void free_AT PARAMS ((dw_attr_ref));
4798 switch (AT_class (a))
4800 case dw_val_class_str:
4801 case dw_val_class_lbl_id:
4802 case dw_val_class_lbl_offset:
4803 free (a->dw_attr_val.v.val_str);
4806 case dw_val_class_float:
4807 free (a->dw_attr_val.v.val_float.array);
4817 /* Remove the specified attribute if present. */
4820 remove_AT (die, attr_kind)
4821 register dw_die_ref die;
4822 register enum dwarf_attribute attr_kind;
4824 register dw_attr_ref *p;
4825 register dw_attr_ref removed = NULL;
4829 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4830 if ((*p)->dw_attr == attr_kind)
4833 *p = (*p)->dw_attr_next;
4842 /* Free up the memory used by DIE. */
4844 static inline void free_die PARAMS ((dw_die_ref));
4849 remove_children (die);
4853 /* Discard the children of this DIE. */
4856 remove_children (die)
4857 register dw_die_ref die;
4859 register dw_die_ref child_die = die->die_child;
4861 die->die_child = NULL;
4863 while (child_die != NULL)
4865 register dw_die_ref tmp_die = child_die;
4866 register dw_attr_ref a;
4868 child_die = child_die->die_sib;
4870 for (a = tmp_die->die_attr; a != NULL;)
4872 register dw_attr_ref tmp_a = a;
4874 a = a->dw_attr_next;
4882 /* Add a child DIE below its parent. We build the lists up in reverse
4883 addition order, and correct that in reverse_all_dies. */
4886 add_child_die (die, child_die)
4887 register dw_die_ref die;
4888 register dw_die_ref child_die;
4890 if (die != NULL && child_die != NULL)
4892 if (die == child_die)
4894 child_die->die_parent = die;
4895 child_die->die_sib = die->die_child;
4896 die->die_child = child_die;
4900 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4901 is the specification, to the front of PARENT's list of children. */
4904 splice_child_die (parent, child)
4905 dw_die_ref parent, child;
4909 /* We want the declaration DIE from inside the class, not the
4910 specification DIE at toplevel. */
4911 if (child->die_parent != parent)
4913 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4918 if (child->die_parent != parent
4919 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4922 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4925 *p = child->die_sib;
4929 child->die_sib = parent->die_child;
4930 parent->die_child = child;
4933 /* Return a pointer to a newly created DIE node. */
4935 static inline dw_die_ref
4936 new_die (tag_value, parent_die)
4937 register enum dwarf_tag tag_value;
4938 register dw_die_ref parent_die;
4940 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4942 die->die_tag = tag_value;
4944 if (parent_die != NULL)
4945 add_child_die (parent_die, die);
4948 limbo_die_node *limbo_node;
4950 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4951 limbo_node->die = die;
4952 limbo_node->next = limbo_die_list;
4953 limbo_die_list = limbo_node;
4959 /* Return the DIE associated with the given type specifier. */
4961 static inline dw_die_ref
4962 lookup_type_die (type)
4965 if (TREE_CODE (type) == VECTOR_TYPE)
4966 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4967 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4970 /* Equate a DIE to a given type specifier. */
4973 equate_type_number_to_die (type, type_die)
4975 register dw_die_ref type_die;
4977 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4980 /* Return the DIE associated with a given declaration. */
4982 static inline dw_die_ref
4983 lookup_decl_die (decl)
4986 register unsigned decl_id = DECL_UID (decl);
4988 return (decl_id < decl_die_table_in_use
4989 ? decl_die_table[decl_id] : NULL);
4992 /* Equate a DIE to a particular declaration. */
4995 equate_decl_number_to_die (decl, decl_die)
4997 register dw_die_ref decl_die;
4999 register unsigned decl_id = DECL_UID (decl);
5000 register unsigned num_allocated;
5002 if (decl_id >= decl_die_table_allocated)
5005 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5006 / DECL_DIE_TABLE_INCREMENT)
5007 * DECL_DIE_TABLE_INCREMENT;
5010 = (dw_die_ref *) xrealloc (decl_die_table,
5011 sizeof (dw_die_ref) * num_allocated);
5013 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5014 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5015 decl_die_table_allocated = num_allocated;
5018 if (decl_id >= decl_die_table_in_use)
5019 decl_die_table_in_use = (decl_id + 1);
5021 decl_die_table[decl_id] = decl_die;
5024 /* Keep track of the number of spaces used to indent the
5025 output of the debugging routines that print the structure of
5026 the DIE internal representation. */
5027 static int print_indent;
5029 /* Indent the line the number of spaces given by print_indent. */
5032 print_spaces (outfile)
5035 fprintf (outfile, "%*s", print_indent, "");
5038 /* Print the information associated with a given DIE, and its children.
5039 This routine is a debugging aid only. */
5042 print_die (die, outfile)
5046 register dw_attr_ref a;
5047 register dw_die_ref c;
5049 print_spaces (outfile);
5050 fprintf (outfile, "DIE %4lu: %s\n",
5051 die->die_offset, dwarf_tag_name (die->die_tag));
5052 print_spaces (outfile);
5053 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5054 fprintf (outfile, " offset: %lu\n", die->die_offset);
5056 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5058 print_spaces (outfile);
5059 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5061 switch (AT_class (a))
5063 case dw_val_class_addr:
5064 fprintf (outfile, "address");
5066 case dw_val_class_offset:
5067 fprintf (outfile, "offset");
5069 case dw_val_class_loc:
5070 fprintf (outfile, "location descriptor");
5072 case dw_val_class_loc_list:
5073 fprintf (outfile, "location list -> label:%s",
5074 AT_loc_list (a)->ll_symbol);
5076 case dw_val_class_const:
5077 fprintf (outfile, "%ld", AT_int (a));
5079 case dw_val_class_unsigned_const:
5080 fprintf (outfile, "%lu", AT_unsigned (a));
5082 case dw_val_class_long_long:
5083 fprintf (outfile, "constant (%lu,%lu)",
5084 a->dw_attr_val.v.val_long_long.hi,
5085 a->dw_attr_val.v.val_long_long.low);
5087 case dw_val_class_float:
5088 fprintf (outfile, "floating-point constant");
5090 case dw_val_class_flag:
5091 fprintf (outfile, "%u", AT_flag (a));
5093 case dw_val_class_die_ref:
5094 if (AT_ref (a) != NULL)
5096 if (AT_ref (a)->die_symbol)
5097 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5099 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5102 fprintf (outfile, "die -> <null>");
5104 case dw_val_class_lbl_id:
5105 case dw_val_class_lbl_offset:
5106 fprintf (outfile, "label: %s", AT_lbl (a));
5108 case dw_val_class_str:
5109 if (AT_string (a) != NULL)
5110 fprintf (outfile, "\"%s\"", AT_string (a));
5112 fprintf (outfile, "<null>");
5118 fprintf (outfile, "\n");
5121 if (die->die_child != NULL)
5124 for (c = die->die_child; c != NULL; c = c->die_sib)
5125 print_die (c, outfile);
5129 if (print_indent == 0)
5130 fprintf (outfile, "\n");
5133 /* Print the contents of the source code line number correspondence table.
5134 This routine is a debugging aid only. */
5137 print_dwarf_line_table (outfile)
5140 register unsigned i;
5141 register dw_line_info_ref line_info;
5143 fprintf (outfile, "\n\nDWARF source line information\n");
5144 for (i = 1; i < line_info_table_in_use; ++i)
5146 line_info = &line_info_table[i];
5147 fprintf (outfile, "%5d: ", i);
5148 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5149 fprintf (outfile, "%6ld", line_info->dw_line_num);
5150 fprintf (outfile, "\n");
5153 fprintf (outfile, "\n\n");
5156 /* Print the information collected for a given DIE. */
5159 debug_dwarf_die (die)
5162 print_die (die, stderr);
5165 /* Print all DWARF information collected for the compilation unit.
5166 This routine is a debugging aid only. */
5172 print_die (comp_unit_die, stderr);
5173 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5174 print_dwarf_line_table (stderr);
5177 /* We build up the lists of children and attributes by pushing new ones
5178 onto the beginning of the list. Reverse the lists for DIE so that
5179 they are in order of addition. */
5182 reverse_die_lists (die)
5183 register dw_die_ref die;
5185 register dw_die_ref c, cp, cn;
5186 register dw_attr_ref a, ap, an;
5188 for (a = die->die_attr, ap = 0; a; a = an)
5190 an = a->dw_attr_next;
5191 a->dw_attr_next = ap;
5196 for (c = die->die_child, cp = 0; c; c = cn)
5202 die->die_child = cp;
5205 /* reverse_die_lists only reverses the single die you pass it. Since
5206 we used to reverse all dies in add_sibling_attributes, which runs
5207 through all the dies, it would reverse all the dies. Now, however,
5208 since we don't call reverse_die_lists in add_sibling_attributes, we
5209 need a routine to recursively reverse all the dies. This is that
5213 reverse_all_dies (die)
5214 register dw_die_ref die;
5216 register dw_die_ref c;
5218 reverse_die_lists (die);
5220 for (c = die->die_child; c; c = c->die_sib)
5221 reverse_all_dies (c);
5224 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5225 the CU for the enclosing include file, if any. BINCL_DIE is the
5226 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5230 push_new_compile_unit (old_unit, bincl_die)
5231 dw_die_ref old_unit, bincl_die;
5233 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5234 dw_die_ref new_unit = gen_compile_unit_die (filename);
5235 new_unit->die_sib = old_unit;
5239 /* Close an include-file CU and reopen the enclosing one. */
5242 pop_compile_unit (old_unit)
5243 dw_die_ref old_unit;
5245 dw_die_ref new_unit = old_unit->die_sib;
5246 old_unit->die_sib = NULL;
5250 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5251 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5253 /* Calculate the checksum of a location expression. */
5256 loc_checksum (loc, ctx)
5257 dw_loc_descr_ref loc;
5258 struct md5_ctx *ctx;
5260 PROCESS (loc->dw_loc_opc);
5261 PROCESS (loc->dw_loc_oprnd1);
5262 PROCESS (loc->dw_loc_oprnd2);
5265 /* Calculate the checksum of an attribute. */
5268 attr_checksum (at, ctx)
5270 struct md5_ctx *ctx;
5272 dw_loc_descr_ref loc;
5275 PROCESS (at->dw_attr);
5277 /* We don't care about differences in file numbering. */
5278 if (at->dw_attr == DW_AT_decl_file
5279 /* Or that this was compiled with a different compiler snapshot; if
5280 the output is the same, that's what matters. */
5281 || at->dw_attr == DW_AT_producer)
5284 switch (AT_class (at))
5286 case dw_val_class_const:
5287 PROCESS (at->dw_attr_val.v.val_int);
5289 case dw_val_class_unsigned_const:
5290 PROCESS (at->dw_attr_val.v.val_unsigned);
5292 case dw_val_class_long_long:
5293 PROCESS (at->dw_attr_val.v.val_long_long);
5295 case dw_val_class_float:
5296 PROCESS (at->dw_attr_val.v.val_float);
5298 case dw_val_class_flag:
5299 PROCESS (at->dw_attr_val.v.val_flag);
5302 case dw_val_class_str:
5303 PROCESS_STRING (AT_string (at));
5306 case dw_val_class_addr:
5308 switch (GET_CODE (r))
5311 PROCESS_STRING (XSTR (r, 0));
5319 case dw_val_class_offset:
5320 PROCESS (at->dw_attr_val.v.val_offset);
5323 case dw_val_class_loc:
5324 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5325 loc_checksum (loc, ctx);
5328 case dw_val_class_die_ref:
5329 if (AT_ref (at)->die_offset)
5330 PROCESS (AT_ref (at)->die_offset);
5331 /* FIXME else use target die name or something. */
5333 case dw_val_class_fde_ref:
5334 case dw_val_class_lbl_id:
5335 case dw_val_class_lbl_offset:
5343 /* Calculate the checksum of a DIE. */
5346 die_checksum (die, ctx)
5348 struct md5_ctx *ctx;
5353 PROCESS (die->die_tag);
5355 for (a = die->die_attr; a; a = a->dw_attr_next)
5356 attr_checksum (a, ctx);
5358 for (c = die->die_child; c; c = c->die_sib)
5359 die_checksum (c, ctx);
5363 #undef PROCESS_STRING
5365 /* The prefix to attach to symbols on DIEs in the current comdat debug
5367 static char *comdat_symbol_id;
5369 /* The index of the current symbol within the current comdat CU. */
5370 static unsigned int comdat_symbol_number;
5372 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5373 children, and set comdat_symbol_id accordingly. */
5376 compute_section_prefix (unit_die)
5377 dw_die_ref unit_die;
5381 unsigned char checksum[16];
5384 md5_init_ctx (&ctx);
5385 die_checksum (unit_die, &ctx);
5386 md5_finish_ctx (&ctx, checksum);
5389 const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
5390 name = (char *) alloca (strlen (p) + 64);
5391 sprintf (name, "%s.", p);
5394 clean_symbol_name (name);
5397 char *p = name + strlen (name);
5398 for (i = 0; i < 4; ++i)
5400 sprintf (p, "%.2x", checksum[i]);
5405 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5406 comdat_symbol_number = 0;
5409 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5415 switch (die->die_tag)
5417 case DW_TAG_array_type:
5418 case DW_TAG_class_type:
5419 case DW_TAG_enumeration_type:
5420 case DW_TAG_pointer_type:
5421 case DW_TAG_reference_type:
5422 case DW_TAG_string_type:
5423 case DW_TAG_structure_type:
5424 case DW_TAG_subroutine_type:
5425 case DW_TAG_union_type:
5426 case DW_TAG_ptr_to_member_type:
5427 case DW_TAG_set_type:
5428 case DW_TAG_subrange_type:
5429 case DW_TAG_base_type:
5430 case DW_TAG_const_type:
5431 case DW_TAG_file_type:
5432 case DW_TAG_packed_type:
5433 case DW_TAG_volatile_type:
5440 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5441 Basically, we want to choose the bits that are likely to be shared between
5442 compilations (types) and leave out the bits that are specific to individual
5443 compilations (functions). */
5450 /* I think we want to leave base types and __vtbl_ptr_type in the
5451 main CU, as we do for stabs. The advantage is a greater
5452 likelihood of sharing between objects that don't include headers
5453 in the same order (and therefore would put the base types in a
5454 different comdat). jason 8/28/00 */
5455 if (c->die_tag == DW_TAG_base_type)
5458 if (c->die_tag == DW_TAG_pointer_type
5459 || c->die_tag == DW_TAG_reference_type
5460 || c->die_tag == DW_TAG_const_type
5461 || c->die_tag == DW_TAG_volatile_type)
5463 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5464 return t ? is_comdat_die (t) : 0;
5468 return is_type_die (c);
5471 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5472 compilation unit. */
5478 if (is_type_die (c))
5480 if (get_AT (c, DW_AT_declaration)
5481 && ! get_AT (c, DW_AT_specification))
5487 gen_internal_sym (prefix)
5491 static int label_num;
5492 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5493 return xstrdup (buf);
5496 /* Assign symbols to all worthy DIEs under DIE. */
5499 assign_symbol_names (die)
5500 register dw_die_ref die;
5502 register dw_die_ref c;
5504 if (is_symbol_die (die))
5506 if (comdat_symbol_id)
5508 char *p = alloca (strlen (comdat_symbol_id) + 64);
5509 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5510 comdat_symbol_id, comdat_symbol_number++);
5511 die->die_symbol = xstrdup (p);
5514 die->die_symbol = gen_internal_sym ("LDIE");
5517 for (c = die->die_child; c != NULL; c = c->die_sib)
5518 assign_symbol_names (c);
5521 /* Traverse the DIE (which is always comp_unit_die), and set up
5522 additional compilation units for each of the include files we see
5523 bracketed by BINCL/EINCL. */
5526 break_out_includes (die)
5527 register dw_die_ref die;
5530 register dw_die_ref unit = NULL;
5531 limbo_die_node *node;
5533 for (ptr = &(die->die_child); *ptr; )
5535 register dw_die_ref c = *ptr;
5537 if (c->die_tag == DW_TAG_GNU_BINCL
5538 || c->die_tag == DW_TAG_GNU_EINCL
5539 || (unit && is_comdat_die (c)))
5541 /* This DIE is for a secondary CU; remove it from the main one. */
5544 if (c->die_tag == DW_TAG_GNU_BINCL)
5546 unit = push_new_compile_unit (unit, c);
5549 else if (c->die_tag == DW_TAG_GNU_EINCL)
5551 unit = pop_compile_unit (unit);
5555 add_child_die (unit, c);
5559 /* Leave this DIE in the main CU. */
5560 ptr = &(c->die_sib);
5566 /* We can only use this in debugging, since the frontend doesn't check
5567 to make sure that we leave every include file we enter. */
5572 assign_symbol_names (die);
5573 for (node = limbo_die_list; node; node = node->next)
5575 compute_section_prefix (node->die);
5576 assign_symbol_names (node->die);
5580 /* Traverse the DIE and add a sibling attribute if it may have the
5581 effect of speeding up access to siblings. To save some space,
5582 avoid generating sibling attributes for DIE's without children. */
5585 add_sibling_attributes (die)
5586 register dw_die_ref die;
5588 register dw_die_ref c;
5590 if (die->die_tag != DW_TAG_compile_unit
5591 && die->die_sib && die->die_child != NULL)
5592 /* Add the sibling link to the front of the attribute list. */
5593 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5595 for (c = die->die_child; c != NULL; c = c->die_sib)
5596 add_sibling_attributes (c);
5599 /* Output all location lists for the DIE and it's children */
5601 output_location_lists (die)
5602 register dw_die_ref die;
5606 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5608 if (AT_class (d_attr) == dw_val_class_loc_list)
5610 output_loc_list (AT_loc_list (d_attr));
5613 for (c = die->die_child; c != NULL; c = c->die_sib)
5614 output_location_lists (c);
5617 /* The format of each DIE (and its attribute value pairs)
5618 is encoded in an abbreviation table. This routine builds the
5619 abbreviation table and assigns a unique abbreviation id for
5620 each abbreviation entry. The children of each die are visited
5624 build_abbrev_table (die)
5625 register dw_die_ref die;
5627 register unsigned long abbrev_id;
5628 register unsigned int n_alloc;
5629 register dw_die_ref c;
5630 register dw_attr_ref d_attr, a_attr;
5632 /* Scan the DIE references, and mark as external any that refer to
5633 DIEs from other CUs (i.e. those which are not marked). */
5634 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5636 if (AT_class (d_attr) == dw_val_class_die_ref
5637 && AT_ref (d_attr)->die_mark == 0)
5639 if (AT_ref (d_attr)->die_symbol == 0)
5641 set_AT_ref_external (d_attr, 1);
5645 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5647 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5649 if (abbrev->die_tag == die->die_tag)
5651 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5653 a_attr = abbrev->die_attr;
5654 d_attr = die->die_attr;
5656 while (a_attr != NULL && d_attr != NULL)
5658 if ((a_attr->dw_attr != d_attr->dw_attr)
5659 || (value_format (a_attr) != value_format (d_attr)))
5662 a_attr = a_attr->dw_attr_next;
5663 d_attr = d_attr->dw_attr_next;
5666 if (a_attr == NULL && d_attr == NULL)
5672 if (abbrev_id >= abbrev_die_table_in_use)
5674 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5676 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5678 = (dw_die_ref *) xrealloc (abbrev_die_table,
5679 sizeof (dw_die_ref) * n_alloc);
5681 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5682 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5683 abbrev_die_table_allocated = n_alloc;
5686 ++abbrev_die_table_in_use;
5687 abbrev_die_table[abbrev_id] = die;
5690 die->die_abbrev = abbrev_id;
5691 for (c = die->die_child; c != NULL; c = c->die_sib)
5692 build_abbrev_table (c);
5695 /* Return the size of a string, including the null byte.
5697 This used to treat backslashes as escapes, and hence they were not included
5698 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5699 which treats a backslash as a backslash, escaping it if necessary, and hence
5700 we must include them in the count. */
5702 static unsigned long
5703 size_of_string (str)
5704 register const char *str;
5706 return strlen (str) + 1;
5709 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5712 constant_size (value)
5713 long unsigned value;
5720 log = floor_log2 (value);
5723 log = 1 << (floor_log2 (log) + 1);
5728 /* Return the size of a DIE, as it is represented in the
5729 .debug_info section. */
5731 static unsigned long
5733 register dw_die_ref die;
5735 register unsigned long size = 0;
5736 register dw_attr_ref a;
5738 size += size_of_uleb128 (die->die_abbrev);
5739 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5741 switch (AT_class (a))
5743 case dw_val_class_addr:
5744 size += DWARF2_ADDR_SIZE;
5746 case dw_val_class_offset:
5747 size += DWARF_OFFSET_SIZE;
5749 case dw_val_class_loc:
5751 register unsigned long lsize = size_of_locs (AT_loc (a));
5754 size += constant_size (lsize);
5758 case dw_val_class_loc_list:
5759 size += DWARF_OFFSET_SIZE;
5761 case dw_val_class_const:
5762 size += size_of_sleb128 (AT_int (a));
5764 case dw_val_class_unsigned_const:
5765 size += constant_size (AT_unsigned (a));
5767 case dw_val_class_long_long:
5768 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5770 case dw_val_class_float:
5771 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5773 case dw_val_class_flag:
5776 case dw_val_class_die_ref:
5777 size += DWARF_OFFSET_SIZE;
5779 case dw_val_class_fde_ref:
5780 size += DWARF_OFFSET_SIZE;
5782 case dw_val_class_lbl_id:
5783 size += DWARF2_ADDR_SIZE;
5785 case dw_val_class_lbl_offset:
5786 size += DWARF_OFFSET_SIZE;
5788 case dw_val_class_str:
5789 size += size_of_string (AT_string (a));
5799 /* Size the debugging information associated with a given DIE.
5800 Visits the DIE's children recursively. Updates the global
5801 variable next_die_offset, on each time through. Uses the
5802 current value of next_die_offset to update the die_offset
5803 field in each DIE. */
5806 calc_die_sizes (die)
5809 register dw_die_ref c;
5810 die->die_offset = next_die_offset;
5811 next_die_offset += size_of_die (die);
5813 for (c = die->die_child; c != NULL; c = c->die_sib)
5816 if (die->die_child != NULL)
5817 /* Count the null byte used to terminate sibling lists. */
5818 next_die_offset += 1;
5821 /* Set the marks for a die and its children. We do this so
5822 that we know whether or not a reference needs to use FORM_ref_addr; only
5823 DIEs in the same CU will be marked. We used to clear out the offset
5824 and use that as the flag, but ran into ordering problems. */
5830 register dw_die_ref c;
5832 for (c = die->die_child; c; c = c->die_sib)
5836 /* Clear the marks for a die and its children. */
5842 register dw_die_ref c;
5844 for (c = die->die_child; c; c = c->die_sib)
5848 /* Return the size of the .debug_pubnames table generated for the
5849 compilation unit. */
5851 static unsigned long
5854 register unsigned long size;
5855 register unsigned i;
5857 size = DWARF_PUBNAMES_HEADER_SIZE;
5858 for (i = 0; i < pubname_table_in_use; ++i)
5860 register pubname_ref p = &pubname_table[i];
5861 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5864 size += DWARF_OFFSET_SIZE;
5868 /* Return the size of the information in the .debug_aranges section. */
5870 static unsigned long
5873 register unsigned long size;
5875 size = DWARF_ARANGES_HEADER_SIZE;
5877 /* Count the address/length pair for this compilation unit. */
5878 size += 2 * DWARF2_ADDR_SIZE;
5879 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5881 /* Count the two zero words used to terminated the address range table. */
5882 size += 2 * DWARF2_ADDR_SIZE;
5886 /* Select the encoding of an attribute value. */
5888 static enum dwarf_form
5892 switch (a->dw_attr_val.val_class)
5894 case dw_val_class_addr:
5895 return DW_FORM_addr;
5896 case dw_val_class_offset:
5897 if (DWARF_OFFSET_SIZE == 4)
5898 return DW_FORM_data4;
5899 if (DWARF_OFFSET_SIZE == 8)
5900 return DW_FORM_data8;
5902 case dw_val_class_loc_list:
5903 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5904 .debug_loc section */
5905 return DW_FORM_data4;
5906 case dw_val_class_loc:
5907 switch (constant_size (size_of_locs (AT_loc (a))))
5910 return DW_FORM_block1;
5912 return DW_FORM_block2;
5916 case dw_val_class_const:
5917 return DW_FORM_sdata;
5918 case dw_val_class_unsigned_const:
5919 switch (constant_size (AT_unsigned (a)))
5922 return DW_FORM_data1;
5924 return DW_FORM_data2;
5926 return DW_FORM_data4;
5928 return DW_FORM_data8;
5932 case dw_val_class_long_long:
5933 return DW_FORM_block1;
5934 case dw_val_class_float:
5935 return DW_FORM_block1;
5936 case dw_val_class_flag:
5937 return DW_FORM_flag;
5938 case dw_val_class_die_ref:
5939 if (AT_ref_external (a))
5940 return DW_FORM_ref_addr;
5943 case dw_val_class_fde_ref:
5944 return DW_FORM_data;
5945 case dw_val_class_lbl_id:
5946 return DW_FORM_addr;
5947 case dw_val_class_lbl_offset:
5948 return DW_FORM_data;
5949 case dw_val_class_str:
5950 return DW_FORM_string;
5957 /* Output the encoding of an attribute value. */
5960 output_value_format (a)
5963 enum dwarf_form form = value_format (a);
5964 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5967 /* Output the .debug_abbrev section which defines the DIE abbreviation
5971 output_abbrev_section ()
5973 unsigned long abbrev_id;
5976 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5978 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5980 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5982 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5983 dwarf_tag_name (abbrev->die_tag));
5985 if (abbrev->die_child != NULL)
5986 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5988 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5990 for (a_attr = abbrev->die_attr; a_attr != NULL;
5991 a_attr = a_attr->dw_attr_next)
5993 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5994 dwarf_attr_name (a_attr->dw_attr));
5995 output_value_format (a_attr);
5998 dw2_asm_output_data (1, 0, NULL);
5999 dw2_asm_output_data (1, 0, NULL);
6002 /* Terminate the table. */
6003 dw2_asm_output_data (1, 0, NULL);
6006 /* Output a symbol we can use to refer to this DIE from another CU. */
6009 output_die_symbol (die)
6010 register dw_die_ref die;
6012 char *sym = die->die_symbol;
6017 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6018 /* We make these global, not weak; if the target doesn't support
6019 .linkonce, it doesn't support combining the sections, so debugging
6021 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6022 ASM_OUTPUT_LABEL (asm_out_file, sym);
6025 /* Return a new location list, given the begin and end range, and the
6026 expression. gensym tells us whether to generate a new internal
6027 symbol for this location list node, which is done for the head of
6029 static inline dw_loc_list_ref
6030 new_loc_list (expr, begin, end, section, gensym)
6031 register dw_loc_descr_ref expr;
6032 register const char *begin;
6033 register const char *end;
6034 register const char *section;
6035 register unsigned gensym;
6037 register dw_loc_list_ref retlist
6038 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6039 retlist->begin = begin;
6041 retlist->expr = expr;
6042 retlist->section = section;
6044 retlist->ll_symbol = gen_internal_sym ("LLST");
6048 /* Add a location description expression to a location list */
6050 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6051 register dw_loc_list_ref *list_head;
6052 register dw_loc_descr_ref descr;
6053 register const char *begin;
6054 register const char *end;
6055 register const char *section;
6057 register dw_loc_list_ref *d;
6059 /* Find the end of the chain. */
6060 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6062 /* Add a new location list node to the list */
6063 *d = new_loc_list (descr, begin, end, section, 0);
6066 /* Output the location list given to us */
6068 output_loc_list (list_head)
6069 register dw_loc_list_ref list_head;
6071 register dw_loc_list_ref curr=list_head;
6072 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6074 /* ??? This shouldn't be needed now that we've forced the
6075 compilation unit base address to zero when there is code
6076 in more than one section. */
6077 if (strcmp (curr->section, ".text") == 0)
6079 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6080 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
6081 "Location list base address specifier fake entry");
6082 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6083 "Location list base address specifier base");
6085 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6088 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6089 "Location list begin address (%s)",
6090 list_head->ll_symbol);
6091 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6092 "Location list end address (%s)",
6093 list_head->ll_symbol);
6094 size = size_of_locs (curr->expr);
6096 /* Output the block length for this list of location operations. */
6097 dw2_asm_output_data (constant_size (size), size, "%s",
6098 "Location expression size");
6100 output_loc_sequence (curr->expr);
6102 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6103 "Location list terminator begin (%s)",
6104 list_head->ll_symbol);
6105 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6106 "Location list terminator end (%s)",
6107 list_head->ll_symbol);
6109 /* Output the DIE and its attributes. Called recursively to generate
6110 the definitions of each child DIE. */
6114 register dw_die_ref die;
6116 register dw_attr_ref a;
6117 register dw_die_ref c;
6118 register unsigned long size;
6120 /* If someone in another CU might refer to us, set up a symbol for
6121 them to point to. */
6122 if (die->die_symbol)
6123 output_die_symbol (die);
6125 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6126 die->die_offset, dwarf_tag_name (die->die_tag));
6128 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6130 const char *name = dwarf_attr_name (a->dw_attr);
6132 switch (AT_class (a))
6134 case dw_val_class_addr:
6135 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6138 case dw_val_class_offset:
6139 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6143 case dw_val_class_loc:
6144 size = size_of_locs (AT_loc (a));
6146 /* Output the block length for this list of location operations. */
6147 dw2_asm_output_data (constant_size (size), size, "%s", name);
6149 output_loc_sequence (AT_loc (a));
6152 case dw_val_class_const:
6153 /* ??? It would be slightly more efficient to use a scheme like is
6154 used for unsigned constants below, but gdb 4.x does not sign
6155 extend. Gdb 5.x does sign extend. */
6156 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6159 case dw_val_class_unsigned_const:
6160 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6161 AT_unsigned (a), "%s", name);
6164 case dw_val_class_long_long:
6166 unsigned HOST_WIDE_INT first, second;
6168 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6171 if (WORDS_BIG_ENDIAN)
6173 first = a->dw_attr_val.v.val_long_long.hi;
6174 second = a->dw_attr_val.v.val_long_long.low;
6178 first = a->dw_attr_val.v.val_long_long.low;
6179 second = a->dw_attr_val.v.val_long_long.hi;
6181 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6182 first, "long long constant");
6183 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6188 case dw_val_class_float:
6190 register unsigned int i;
6192 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6195 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6196 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6197 "fp constant word %u", i);
6201 case dw_val_class_flag:
6202 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6205 case dw_val_class_loc_list:
6207 char *sym = AT_loc_list (a)->ll_symbol;
6210 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6211 loc_section_label, "%s", name);
6215 case dw_val_class_die_ref:
6216 if (AT_ref_external (a))
6218 char *sym = AT_ref (a)->die_symbol;
6221 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6223 else if (AT_ref (a)->die_offset == 0)
6226 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6230 case dw_val_class_fde_ref:
6233 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6234 a->dw_attr_val.v.val_fde_index * 2);
6235 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6239 case dw_val_class_lbl_id:
6240 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6243 case dw_val_class_lbl_offset:
6244 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6247 case dw_val_class_str:
6248 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6256 for (c = die->die_child; c != NULL; c = c->die_sib)
6259 if (die->die_child != NULL)
6261 /* Add null byte to terminate sibling list. */
6262 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6267 /* Output the compilation unit that appears at the beginning of the
6268 .debug_info section, and precedes the DIE descriptions. */
6271 output_compilation_unit_header ()
6273 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6274 "Length of Compilation Unit Info");
6276 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6278 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6279 "Offset Into Abbrev. Section");
6281 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6284 /* Output the compilation unit DIE and its children. */
6287 output_comp_unit (die)
6290 const char *secname;
6292 /* Even if there are no children of this DIE, we must output the
6293 information about the compilation unit. Otherwise, on an empty
6294 translation unit, we will generate a present, but empty,
6295 .debug_info section. IRIX 6.5 `nm' will then complain when
6298 Mark all the DIEs in this CU so we know which get local refs. */
6301 build_abbrev_table (die);
6303 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6304 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6305 calc_die_sizes (die);
6307 if (die->die_symbol)
6309 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6310 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6312 die->die_symbol = NULL;
6315 secname = (const char *) DEBUG_INFO_SECTION;
6317 /* Output debugging information. */
6318 named_section_flags (secname, SECTION_DEBUG);
6319 output_compilation_unit_header ();
6322 /* Leave the marks on the main CU, so we can check them in
6324 if (die->die_symbol)
6328 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6329 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6330 argument list, and maybe the scope. */
6333 dwarf2_name (decl, scope)
6337 return (*decl_printable_name) (decl, scope ? 1 : 0);
6340 /* Add a new entry to .debug_pubnames if appropriate. */
6343 add_pubname (decl, die)
6349 if (! TREE_PUBLIC (decl))
6352 if (pubname_table_in_use == pubname_table_allocated)
6354 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6355 pubname_table = (pubname_ref) xrealloc
6356 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6359 p = &pubname_table[pubname_table_in_use++];
6362 p->name = xstrdup (dwarf2_name (decl, 1));
6365 /* Output the public names table used to speed up access to externally
6366 visible names. For now, only generate entries for externally
6367 visible procedures. */
6372 register unsigned i;
6373 register unsigned long pubnames_length = size_of_pubnames ();
6375 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6376 "Length of Public Names Info");
6378 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6380 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6381 "Offset of Compilation Unit Info");
6383 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6384 "Compilation Unit Length");
6386 for (i = 0; i < pubname_table_in_use; ++i)
6388 register pubname_ref pub = &pubname_table[i];
6390 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6391 if (pub->die->die_mark == 0)
6394 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6397 dw2_asm_output_nstring (pub->name, -1, "external name");
6400 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6403 /* Add a new entry to .debug_aranges if appropriate. */
6406 add_arange (decl, die)
6410 if (! DECL_SECTION_NAME (decl))
6413 if (arange_table_in_use == arange_table_allocated)
6415 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6416 arange_table = (dw_die_ref *)
6417 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6420 arange_table[arange_table_in_use++] = die;
6423 /* Output the information that goes into the .debug_aranges table.
6424 Namely, define the beginning and ending address range of the
6425 text section generated for this compilation unit. */
6430 register unsigned i;
6431 register unsigned long aranges_length = size_of_aranges ();
6433 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6434 "Length of Address Ranges Info");
6436 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6438 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6439 "Offset of Compilation Unit Info");
6441 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6443 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6445 /* We need to align to twice the pointer size here. */
6446 if (DWARF_ARANGES_PAD_SIZE)
6448 /* Pad using a 2 byte words so that padding is correct for any
6450 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6451 2 * DWARF2_ADDR_SIZE);
6452 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6453 dw2_asm_output_data (2, 0, NULL);
6456 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6457 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6458 text_section_label, "Length");
6460 for (i = 0; i < arange_table_in_use; ++i)
6462 dw_die_ref die = arange_table[i];
6464 /* We shouldn't see aranges for DIEs outside of the main CU. */
6465 if (die->die_mark == 0)
6468 if (die->die_tag == DW_TAG_subprogram)
6470 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6472 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6473 get_AT_low_pc (die), "Length");
6477 /* A static variable; extract the symbol from DW_AT_location.
6478 Note that this code isn't currently hit, as we only emit
6479 aranges for functions (jason 9/23/99). */
6481 dw_attr_ref a = get_AT (die, DW_AT_location);
6482 dw_loc_descr_ref loc;
6483 if (! a || AT_class (a) != dw_val_class_loc)
6487 if (loc->dw_loc_opc != DW_OP_addr)
6490 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6491 loc->dw_loc_oprnd1.v.val_addr, "Address");
6492 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6493 get_AT_unsigned (die, DW_AT_byte_size),
6498 /* Output the terminator words. */
6499 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6500 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6503 /* Add a new entry to .debug_ranges. Return the offset at which it
6510 unsigned int in_use = ranges_table_in_use;
6512 if (in_use == ranges_table_allocated)
6514 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6515 ranges_table = (dw_ranges_ref)
6516 xrealloc (ranges_table, (ranges_table_allocated
6517 * sizeof (struct dw_ranges_struct)));
6520 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6521 ranges_table_in_use = in_use + 1;
6523 return in_use * 2 * DWARF2_ADDR_SIZE;
6529 register unsigned i;
6530 const char *start_fmt = "Offset 0x%x";
6531 const char *fmt = start_fmt;
6533 for (i = 0; i < ranges_table_in_use; ++i)
6535 int block_num = ranges_table[i].block_num;
6539 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6540 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6542 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6543 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6545 /* If all code is in the text section, then the compilation
6546 unit base address defaults to DW_AT_low_pc, which is the
6547 base of the text section. */
6548 if (separate_line_info_table_in_use == 0)
6550 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6552 fmt, i * 2 * DWARF2_ADDR_SIZE);
6553 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6554 text_section_label, NULL);
6556 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6557 compilation unit base address to zero, which allows us to
6558 use absolute addresses, and not worry about whether the
6559 target supports cross-section arithmetic. */
6562 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6563 fmt, i * 2 * DWARF2_ADDR_SIZE);
6564 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6571 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6572 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6578 /* Data structure containing information about input files. */
6581 char *path; /* Complete file name. */
6582 char *fname; /* File name part. */
6583 int length; /* Length of entire string. */
6584 int file_idx; /* Index in input file table. */
6585 int dir_idx; /* Index in directory table. */
6588 /* Data structure containing information about directories with source
6592 char *path; /* Path including directory name. */
6593 int length; /* Path length. */
6594 int prefix; /* Index of directory entry which is a prefix. */
6595 int count; /* Number of files in this directory. */
6596 int dir_idx; /* Index of directory used as base. */
6597 int used; /* Used in the end? */
6600 /* Callback function for file_info comparison. We sort by looking at
6601 the directories in the path. */
6603 file_info_cmp (p1, p2)
6607 const struct file_info *s1 = p1;
6608 const struct file_info *s2 = p2;
6612 /* Take care of file names without directories. */
6613 if (s1->path == s1->fname)
6615 else if (s2->path == s2->fname)
6618 cp1 = (unsigned char *) s1->path;
6619 cp2 = (unsigned char *) s2->path;
6625 /* Reached the end of the first path? */
6626 if (cp1 == (unsigned char *) s1->fname)
6627 /* It doesn't really matter in which order files from the
6628 same directory are sorted in. Therefore don't test for
6629 the second path reaching the end. */
6631 else if (cp2 == (unsigned char *) s2->fname)
6634 /* Character of current path component the same? */
6640 /* Output the directory table and the file name table. We try to minimize
6641 the total amount of memory needed. A heuristic is used to avoid large
6642 slowdowns with many input files. */
6644 output_file_names ()
6646 struct file_info *files;
6647 struct dir_info *dirs;
6656 /* Allocate the various arrays we need. */
6657 files = (struct file_info *) alloca (file_table.in_use
6658 * sizeof (struct file_info));
6659 dirs = (struct dir_info *) alloca (file_table.in_use
6660 * sizeof (struct dir_info));
6662 /* Sort the file names. */
6663 for (i = 1; i < (int) file_table.in_use; ++i)
6667 /* Skip all leading "./". */
6668 f = file_table.table[i];
6669 while (f[0] == '.' && f[1] == '/')
6672 /* Create a new array entry. */
6674 files[i].length = strlen (f);
6675 files[i].file_idx = i;
6677 /* Search for the file name part. */
6678 f = strrchr (f, '/');
6679 files[i].fname = f == NULL ? files[i].path : f + 1;
6681 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6683 /* Find all the different directories used. */
6684 dirs[0].path = files[1].path;
6685 dirs[0].length = files[1].fname - files[1].path;
6686 dirs[0].prefix = -1;
6688 dirs[0].dir_idx = 0;
6690 files[1].dir_idx = 0;
6693 for (i = 2; i < (int) file_table.in_use; ++i)
6694 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6695 && memcmp (dirs[ndirs - 1].path, files[i].path,
6696 dirs[ndirs - 1].length) == 0)
6698 /* Same directory as last entry. */
6699 files[i].dir_idx = ndirs - 1;
6700 ++dirs[ndirs - 1].count;
6706 /* This is a new directory. */
6707 dirs[ndirs].path = files[i].path;
6708 dirs[ndirs].length = files[i].fname - files[i].path;
6709 dirs[ndirs].count = 1;
6710 dirs[ndirs].dir_idx = ndirs;
6711 dirs[ndirs].used = 0;
6712 files[i].dir_idx = ndirs;
6714 /* Search for a prefix. */
6715 dirs[ndirs].prefix = -1;
6716 for (j = 0; j < ndirs; ++j)
6717 if (dirs[j].length < dirs[ndirs].length
6718 && dirs[j].length > 1
6719 && (dirs[ndirs].prefix == -1
6720 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6721 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6722 dirs[ndirs].prefix = j;
6727 /* Now to the actual work. We have to find a subset of the
6728 directories which allow expressing the file name using references
6729 to the directory table with the least amount of characters. We
6730 do not do an exhaustive search where we would have to check out
6731 every combination of every single possible prefix. Instead we
6732 use a heuristic which provides nearly optimal results in most
6733 cases and never is much off. */
6734 saved = (int *) alloca (ndirs * sizeof (int));
6735 savehere = (int *) alloca (ndirs * sizeof (int));
6737 memset (saved, '\0', ndirs * sizeof (saved[0]));
6738 for (i = 0; i < ndirs; ++i)
6743 /* We can always save some space for the current directory. But
6744 this does not mean it will be enough to justify adding the
6746 savehere[i] = dirs[i].length;
6747 total = (savehere[i] - saved[i]) * dirs[i].count;
6749 for (j = i + 1; j < ndirs; ++j)
6753 if (saved[j] < dirs[i].length)
6755 /* Determine whether the dirs[i] path is a prefix of the
6760 while (k != -1 && k != i)
6765 /* Yes it is. We can possibly safe some memory but
6766 writing the filenames in dirs[j] relative to
6768 savehere[j] = dirs[i].length;
6769 total += (savehere[j] - saved[j]) * dirs[j].count;
6774 /* Check whether we can safe enough to justify adding the dirs[i]
6776 if (total > dirs[i].length + 1)
6778 /* It's worthwhile adding. */
6779 for (j = i; j < ndirs; ++j)
6780 if (savehere[j] > 0)
6782 /* Remember how much we saved for this directory so far. */
6783 saved[j] = savehere[j];
6785 /* Remember the prefix directory. */
6786 dirs[j].dir_idx = i;
6791 /* We have to emit them in the order they appear in the file_table
6792 array since the index is used in the debug info generation. To
6793 do this efficiently we generate a back-mapping of the indices
6795 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6796 for (i = 1; i < (int) file_table.in_use; ++i)
6798 backmap[files[i].file_idx] = i;
6799 /* Mark this directory as used. */
6800 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6803 /* That was it. We are ready to emit the information. First the
6804 directory name table. Here we have to make sure that the first
6805 actually emitted directory name has the index one. Zero is
6806 reserved for the current working directory. Make sure we do not
6807 confuse these indices with the one for the constructed table
6808 (even though most of the time they are identical). */
6810 idx_offset = dirs[0].length > 0 ? 1 : 0;
6811 for (i = 1 - idx_offset; i < ndirs; ++i)
6812 if (dirs[i].used != 0)
6814 dirs[i].used = idx++;
6815 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6816 "Directory Entry: 0x%x", dirs[i].used);
6818 dw2_asm_output_data (1, 0, "End directory table");
6820 /* Correct the index for the current working directory entry if it
6822 if (idx_offset == 0)
6825 /* Now write all the file names. */
6826 for (i = 1; i < (int) file_table.in_use; ++i)
6828 int file_idx = backmap[i];
6829 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6831 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6832 "File Entry: 0x%x", i);
6834 /* Include directory index. */
6835 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6837 /* Modification time. */
6838 dw2_asm_output_data_uleb128 (0, NULL);
6840 /* File length in bytes. */
6841 dw2_asm_output_data_uleb128 (0, NULL);
6843 dw2_asm_output_data (1, 0, "End file name table");
6847 /* Output the source line number correspondence information. This
6848 information goes into the .debug_line section. */
6853 char l1[20], l2[20], p1[20], p2[20];
6854 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6855 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6856 register unsigned opc;
6857 register unsigned n_op_args;
6858 register unsigned long lt_index;
6859 register unsigned long current_line;
6860 register long line_offset;
6861 register long line_delta;
6862 register unsigned long current_file;
6863 register unsigned long function;
6865 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6866 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6867 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6868 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6870 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6871 "Length of Source Line Info");
6872 ASM_OUTPUT_LABEL (asm_out_file, l1);
6874 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6876 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6877 ASM_OUTPUT_LABEL (asm_out_file, p1);
6879 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6880 "Minimum Instruction Length");
6882 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6883 "Default is_stmt_start flag");
6885 dw2_asm_output_data (1, DWARF_LINE_BASE,
6886 "Line Base Value (Special Opcodes)");
6888 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6889 "Line Range Value (Special Opcodes)");
6891 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6892 "Special Opcode Base");
6894 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6898 case DW_LNS_advance_pc:
6899 case DW_LNS_advance_line:
6900 case DW_LNS_set_file:
6901 case DW_LNS_set_column:
6902 case DW_LNS_fixed_advance_pc:
6910 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6914 /* Write out the information about the files we use. */
6915 output_file_names ();
6916 ASM_OUTPUT_LABEL (asm_out_file, p2);
6918 /* We used to set the address register to the first location in the text
6919 section here, but that didn't accomplish anything since we already
6920 have a line note for the opening brace of the first function. */
6922 /* Generate the line number to PC correspondence table, encoded as
6923 a series of state machine operations. */
6926 strcpy (prev_line_label, text_section_label);
6927 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6929 register dw_line_info_ref line_info = &line_info_table[lt_index];
6932 /* Disable this optimization for now; GDB wants to see two line notes
6933 at the beginning of a function so it can find the end of the
6936 /* Don't emit anything for redundant notes. Just updating the
6937 address doesn't accomplish anything, because we already assume
6938 that anything after the last address is this line. */
6939 if (line_info->dw_line_num == current_line
6940 && line_info->dw_file_num == current_file)
6944 /* Emit debug info for the address of the current line.
6946 Unfortunately, we have little choice here currently, and must always
6947 use the most general form. Gcc does not know the address delta
6948 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6949 attributes which will give an upper bound on the address range. We
6950 could perhaps use length attributes to determine when it is safe to
6951 use DW_LNS_fixed_advance_pc. */
6953 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6956 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6957 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6958 "DW_LNS_fixed_advance_pc");
6959 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6963 /* This can handle any delta. This takes
6964 4+DWARF2_ADDR_SIZE bytes. */
6965 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6966 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6967 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6968 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6970 strcpy (prev_line_label, line_label);
6972 /* Emit debug info for the source file of the current line, if
6973 different from the previous line. */
6974 if (line_info->dw_file_num != current_file)
6976 current_file = line_info->dw_file_num;
6977 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6978 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6979 file_table.table[current_file]);
6982 /* Emit debug info for the current line number, choosing the encoding
6983 that uses the least amount of space. */
6984 if (line_info->dw_line_num != current_line)
6986 line_offset = line_info->dw_line_num - current_line;
6987 line_delta = line_offset - DWARF_LINE_BASE;
6988 current_line = line_info->dw_line_num;
6989 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6991 /* This can handle deltas from -10 to 234, using the current
6992 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6994 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6995 "line %lu", current_line);
6999 /* This can handle any delta. This takes at least 4 bytes,
7000 depending on the value being encoded. */
7001 dw2_asm_output_data (1, DW_LNS_advance_line,
7002 "advance to line %lu", current_line);
7003 dw2_asm_output_data_sleb128 (line_offset, NULL);
7004 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7009 /* We still need to start a new row, so output a copy insn. */
7010 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7014 /* Emit debug info for the address of the end of the function. */
7017 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7018 "DW_LNS_fixed_advance_pc");
7019 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7023 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7024 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7025 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7026 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7029 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7030 dw2_asm_output_data_uleb128 (1, NULL);
7031 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7036 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7038 register dw_separate_line_info_ref line_info
7039 = &separate_line_info_table[lt_index];
7042 /* Don't emit anything for redundant notes. */
7043 if (line_info->dw_line_num == current_line
7044 && line_info->dw_file_num == current_file
7045 && line_info->function == function)
7049 /* Emit debug info for the address of the current line. If this is
7050 a new function, or the first line of a function, then we need
7051 to handle it differently. */
7052 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7054 if (function != line_info->function)
7056 function = line_info->function;
7058 /* Set the address register to the first line in the function */
7059 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7060 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7061 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7062 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7066 /* ??? See the DW_LNS_advance_pc comment above. */
7069 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7070 "DW_LNS_fixed_advance_pc");
7071 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7075 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7076 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7077 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7078 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7081 strcpy (prev_line_label, line_label);
7083 /* Emit debug info for the source file of the current line, if
7084 different from the previous line. */
7085 if (line_info->dw_file_num != current_file)
7087 current_file = line_info->dw_file_num;
7088 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7089 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7090 file_table.table[current_file]);
7093 /* Emit debug info for the current line number, choosing the encoding
7094 that uses the least amount of space. */
7095 if (line_info->dw_line_num != current_line)
7097 line_offset = line_info->dw_line_num - current_line;
7098 line_delta = line_offset - DWARF_LINE_BASE;
7099 current_line = line_info->dw_line_num;
7100 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7101 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7102 "line %lu", current_line);
7105 dw2_asm_output_data (1, DW_LNS_advance_line,
7106 "advance to line %lu", current_line);
7107 dw2_asm_output_data_sleb128 (line_offset, NULL);
7108 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7112 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7119 /* If we're done with a function, end its sequence. */
7120 if (lt_index == separate_line_info_table_in_use
7121 || separate_line_info_table[lt_index].function != function)
7126 /* Emit debug info for the address of the end of the function. */
7127 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7130 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7131 "DW_LNS_fixed_advance_pc");
7132 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7136 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7137 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7138 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7139 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7142 /* Output the marker for the end of this sequence. */
7143 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7144 dw2_asm_output_data_uleb128 (1, NULL);
7145 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7149 /* Output the marker for the end of the line number info. */
7150 ASM_OUTPUT_LABEL (asm_out_file, l2);
7153 /* Given a pointer to a tree node for some base type, return a pointer to
7154 a DIE that describes the given type.
7156 This routine must only be called for GCC type nodes that correspond to
7157 Dwarf base (fundamental) types. */
7160 base_type_die (type)
7163 register dw_die_ref base_type_result;
7164 register const char *type_name;
7165 register enum dwarf_type encoding;
7166 register tree name = TYPE_NAME (type);
7168 if (TREE_CODE (type) == ERROR_MARK
7169 || TREE_CODE (type) == VOID_TYPE)
7174 if (TREE_CODE (name) == TYPE_DECL)
7175 name = DECL_NAME (name);
7177 type_name = IDENTIFIER_POINTER (name);
7180 type_name = "__unknown__";
7182 switch (TREE_CODE (type))
7185 /* Carefully distinguish the C character types, without messing
7186 up if the language is not C. Note that we check only for the names
7187 that contain spaces; other names might occur by coincidence in other
7189 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7190 && (type == char_type_node
7191 || ! strcmp (type_name, "signed char")
7192 || ! strcmp (type_name, "unsigned char"))))
7194 if (TREE_UNSIGNED (type))
7195 encoding = DW_ATE_unsigned;
7197 encoding = DW_ATE_signed;
7200 /* else fall through. */
7203 /* GNU Pascal/Ada CHAR type. Not used in C. */
7204 if (TREE_UNSIGNED (type))
7205 encoding = DW_ATE_unsigned_char;
7207 encoding = DW_ATE_signed_char;
7211 encoding = DW_ATE_float;
7214 /* Dwarf2 doesn't know anything about complex ints, so use
7215 a user defined type for it. */
7217 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7218 encoding = DW_ATE_complex_float;
7220 encoding = DW_ATE_lo_user;
7224 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7225 encoding = DW_ATE_boolean;
7229 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7232 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7233 if (demangle_name_func)
7234 type_name = (*demangle_name_func) (type_name);
7236 add_AT_string (base_type_result, DW_AT_name, type_name);
7237 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7238 int_size_in_bytes (type));
7239 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7241 return base_type_result;
7244 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7245 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7246 a given type is generally the same as the given type, except that if the
7247 given type is a pointer or reference type, then the root type of the given
7248 type is the root type of the "basis" type for the pointer or reference
7249 type. (This definition of the "root" type is recursive.) Also, the root
7250 type of a `const' qualified type or a `volatile' qualified type is the
7251 root type of the given type without the qualifiers. */
7257 if (TREE_CODE (type) == ERROR_MARK)
7258 return error_mark_node;
7260 switch (TREE_CODE (type))
7263 return error_mark_node;
7266 case REFERENCE_TYPE:
7267 return type_main_variant (root_type (TREE_TYPE (type)));
7270 return type_main_variant (type);
7274 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7275 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7281 switch (TREE_CODE (type))
7296 case QUAL_UNION_TYPE:
7301 case REFERENCE_TYPE:
7315 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7316 entry that chains various modifiers in front of the given type. */
7319 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7321 register int is_const_type;
7322 register int is_volatile_type;
7323 register dw_die_ref context_die;
7325 register enum tree_code code = TREE_CODE (type);
7326 register dw_die_ref mod_type_die = NULL;
7327 register dw_die_ref sub_die = NULL;
7328 register tree item_type = NULL;
7330 if (code != ERROR_MARK)
7332 tree qualified_type;
7334 /* See if we already have the appropriately qualified variant of
7337 = get_qualified_type (type,
7338 ((is_const_type ? TYPE_QUAL_CONST : 0)
7340 ? TYPE_QUAL_VOLATILE : 0)));
7341 /* If we do, then we can just use its DIE, if it exists. */
7344 mod_type_die = lookup_type_die (qualified_type);
7346 return mod_type_die;
7349 /* Handle C typedef types. */
7350 if (qualified_type && TYPE_NAME (qualified_type)
7351 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7352 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7354 tree type_name = TYPE_NAME (qualified_type);
7355 tree dtype = TREE_TYPE (type_name);
7356 if (qualified_type == dtype)
7358 /* For a named type, use the typedef. */
7359 gen_type_die (qualified_type, context_die);
7360 mod_type_die = lookup_type_die (qualified_type);
7363 else if (is_const_type < TYPE_READONLY (dtype)
7364 || is_volatile_type < TYPE_VOLATILE (dtype))
7365 /* cv-unqualified version of named type. Just use the unnamed
7366 type to which it refers. */
7368 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7369 is_const_type, is_volatile_type,
7371 /* Else cv-qualified version of named type; fall through. */
7377 else if (is_const_type)
7379 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7380 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7382 else if (is_volatile_type)
7384 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7385 sub_die = modified_type_die (type, 0, 0, context_die);
7387 else if (code == POINTER_TYPE)
7389 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7390 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7392 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7394 item_type = TREE_TYPE (type);
7396 else if (code == REFERENCE_TYPE)
7398 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7399 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7401 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7403 item_type = TREE_TYPE (type);
7405 else if (is_base_type (type))
7406 mod_type_die = base_type_die (type);
7409 gen_type_die (type, context_die);
7411 /* We have to get the type_main_variant here (and pass that to the
7412 `lookup_type_die' routine) because the ..._TYPE node we have
7413 might simply be a *copy* of some original type node (where the
7414 copy was created to help us keep track of typedef names) and
7415 that copy might have a different TYPE_UID from the original
7417 mod_type_die = lookup_type_die (type_main_variant (type));
7418 if (mod_type_die == NULL)
7422 /* We want to equate the qualified type to the die below. */
7424 type = qualified_type;
7427 equate_type_number_to_die (type, mod_type_die);
7429 /* We must do this after the equate_type_number_to_die call, in case
7430 this is a recursive type. This ensures that the modified_type_die
7431 recursion will terminate even if the type is recursive. Recursive
7432 types are possible in Ada. */
7433 sub_die = modified_type_die (item_type,
7434 TYPE_READONLY (item_type),
7435 TYPE_VOLATILE (item_type),
7438 if (sub_die != NULL)
7439 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7441 return mod_type_die;
7444 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7445 an enumerated type. */
7451 return TREE_CODE (type) == ENUMERAL_TYPE;
7454 /* Return the register number described by a given RTL node. */
7460 register unsigned regno = REGNO (rtl);
7462 if (regno >= FIRST_PSEUDO_REGISTER)
7464 warning ("internal regno botch: regno = %d\n", regno);
7468 regno = DBX_REGISTER_NUMBER (regno);
7472 /* Return a location descriptor that designates a machine register. */
7474 static dw_loc_descr_ref
7475 reg_loc_descriptor (rtl)
7478 register dw_loc_descr_ref loc_result = NULL;
7479 register unsigned reg = reg_number (rtl);
7482 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7484 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7489 /* Return a location descriptor that designates a constant. */
7491 static dw_loc_descr_ref
7492 int_loc_descriptor (i)
7495 enum dwarf_location_atom op;
7497 /* Pick the smallest representation of a constant, rather than just
7498 defaulting to the LEB encoding. */
7502 op = DW_OP_lit0 + i;
7505 else if (i <= 0xffff)
7507 else if (HOST_BITS_PER_WIDE_INT == 32
7517 else if (i >= -0x8000)
7519 else if (HOST_BITS_PER_WIDE_INT == 32
7520 || i >= -0x80000000)
7526 return new_loc_descr (op, i, 0);
7529 /* Return a location descriptor that designates a base+offset location. */
7531 static dw_loc_descr_ref
7532 based_loc_descr (reg, offset)
7536 register dw_loc_descr_ref loc_result;
7537 /* For the "frame base", we use the frame pointer or stack pointer
7538 registers, since the RTL for local variables is relative to one of
7540 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7541 ? HARD_FRAME_POINTER_REGNUM
7542 : STACK_POINTER_REGNUM);
7545 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7547 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7549 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7554 /* Return true if this RTL expression describes a base+offset calculation. */
7560 return (GET_CODE (rtl) == PLUS
7561 && ((GET_CODE (XEXP (rtl, 0)) == REG
7562 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7565 /* The following routine converts the RTL for a variable or parameter
7566 (resident in memory) into an equivalent Dwarf representation of a
7567 mechanism for getting the address of that same variable onto the top of a
7568 hypothetical "address evaluation" stack.
7570 When creating memory location descriptors, we are effectively transforming
7571 the RTL for a memory-resident object into its Dwarf postfix expression
7572 equivalent. This routine recursively descends an RTL tree, turning
7573 it into Dwarf postfix code as it goes.
7575 MODE is the mode of the memory reference, needed to handle some
7576 autoincrement addressing modes. */
7578 static dw_loc_descr_ref
7579 mem_loc_descriptor (rtl, mode)
7581 enum machine_mode mode;
7583 dw_loc_descr_ref mem_loc_result = NULL;
7584 /* Note that for a dynamically sized array, the location we will generate a
7585 description of here will be the lowest numbered location which is
7586 actually within the array. That's *not* necessarily the same as the
7587 zeroth element of the array. */
7589 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7590 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7593 switch (GET_CODE (rtl))
7598 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7599 just fall into the SUBREG code. */
7604 /* The case of a subreg may arise when we have a local (register)
7605 variable or a formal (register) parameter which doesn't quite fill
7606 up an entire register. For now, just assume that it is
7607 legitimate to make the Dwarf info refer to the whole register which
7608 contains the given subreg. */
7609 rtl = SUBREG_REG (rtl);
7614 /* Whenever a register number forms a part of the description of the
7615 method for calculating the (dynamic) address of a memory resident
7616 object, DWARF rules require the register number be referred to as
7617 a "base register". This distinction is not based in any way upon
7618 what category of register the hardware believes the given register
7619 belongs to. This is strictly DWARF terminology we're dealing with
7620 here. Note that in cases where the location of a memory-resident
7621 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7622 OP_CONST (0)) the actual DWARF location descriptor that we generate
7623 may just be OP_BASEREG (basereg). This may look deceptively like
7624 the object in question was allocated to a register (rather than in
7625 memory) so DWARF consumers need to be aware of the subtle
7626 distinction between OP_REG and OP_BASEREG. */
7627 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7631 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7632 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7636 /* Some ports can transform a symbol ref into a label ref, because
7637 the symbol ref is too far away and has to be dumped into a constant
7641 /* Alternatively, the symbol in the constant pool might be referenced
7642 by a different symbol. */
7643 if (GET_CODE (rtl) == SYMBOL_REF
7644 && CONSTANT_POOL_ADDRESS_P (rtl))
7646 rtx tmp = get_pool_constant (rtl);
7647 if (GET_CODE (tmp) == SYMBOL_REF)
7651 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7652 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7653 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7657 /* Extract the PLUS expression nested inside and fall into
7659 rtl = XEXP (rtl, 1);
7664 /* Turn these into a PLUS expression and fall into the PLUS code
7666 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7667 GEN_INT (GET_CODE (rtl) == PRE_INC
7668 ? GET_MODE_UNIT_SIZE (mode)
7669 : -GET_MODE_UNIT_SIZE (mode)));
7675 if (is_based_loc (rtl))
7676 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7677 INTVAL (XEXP (rtl, 1)));
7680 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7682 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7683 && INTVAL (XEXP (rtl, 1)) >= 0)
7685 add_loc_descr (&mem_loc_result,
7686 new_loc_descr (DW_OP_plus_uconst,
7687 INTVAL (XEXP (rtl, 1)), 0));
7691 add_loc_descr (&mem_loc_result,
7692 mem_loc_descriptor (XEXP (rtl, 1), mode));
7693 add_loc_descr (&mem_loc_result,
7694 new_loc_descr (DW_OP_plus, 0, 0));
7700 /* If a pseudo-reg is optimized away, it is possible for it to
7701 be replaced with a MEM containing a multiply. */
7702 add_loc_descr (&mem_loc_result,
7703 mem_loc_descriptor (XEXP (rtl, 0), mode));
7704 add_loc_descr (&mem_loc_result,
7705 mem_loc_descriptor (XEXP (rtl, 1), mode));
7706 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7710 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7717 return mem_loc_result;
7720 /* Return a descriptor that describes the concatenation of two locations.
7721 This is typically a complex variable. */
7723 static dw_loc_descr_ref
7724 concat_loc_descriptor (x0, x1)
7725 register rtx x0, x1;
7727 dw_loc_descr_ref cc_loc_result = NULL;
7729 if (!is_pseudo_reg (x0)
7730 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7731 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7732 add_loc_descr (&cc_loc_result,
7733 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7735 if (!is_pseudo_reg (x1)
7736 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7737 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7738 add_loc_descr (&cc_loc_result,
7739 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7741 return cc_loc_result;
7744 /* Output a proper Dwarf location descriptor for a variable or parameter
7745 which is either allocated in a register or in a memory location. For a
7746 register, we just generate an OP_REG and the register number. For a
7747 memory location we provide a Dwarf postfix expression describing how to
7748 generate the (dynamic) address of the object onto the address stack. */
7750 static dw_loc_descr_ref
7751 loc_descriptor (rtl)
7754 dw_loc_descr_ref loc_result = NULL;
7755 switch (GET_CODE (rtl))
7758 /* The case of a subreg may arise when we have a local (register)
7759 variable or a formal (register) parameter which doesn't quite fill
7760 up an entire register. For now, just assume that it is
7761 legitimate to make the Dwarf info refer to the whole register which
7762 contains the given subreg. */
7763 rtl = SUBREG_REG (rtl);
7768 loc_result = reg_loc_descriptor (rtl);
7772 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7776 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7786 /* Similar, but generate the descriptor from trees instead of rtl.
7787 This comes up particularly with variable length arrays. */
7789 static dw_loc_descr_ref
7790 loc_descriptor_from_tree (loc, addressp)
7794 dw_loc_descr_ref ret = NULL;
7795 int indirect_size = 0;
7796 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7797 enum dwarf_location_atom op;
7799 /* ??? Most of the time we do not take proper care for sign/zero
7800 extending the values properly. Hopefully this won't be a real
7803 switch (TREE_CODE (loc))
7808 case WITH_RECORD_EXPR:
7809 /* This case involves extracting fields from an object to determine the
7810 position of other fields. We don't try to encode this here. The
7811 only user of this is Ada, which encodes the needed information using
7812 the names of types. */
7818 rtx rtl = rtl_for_decl_location (loc);
7819 enum machine_mode mode = DECL_MODE (loc);
7821 if (rtl == NULL_RTX)
7823 else if (CONSTANT_P (rtl))
7825 ret = new_loc_descr (DW_OP_addr, 0, 0);
7826 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7827 ret->dw_loc_oprnd1.v.val_addr = rtl;
7828 indirect_size = GET_MODE_SIZE (mode);
7832 if (GET_CODE (rtl) == MEM)
7834 indirect_size = GET_MODE_SIZE (mode);
7835 rtl = XEXP (rtl, 0);
7837 ret = mem_loc_descriptor (rtl, mode);
7843 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7844 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7849 case NON_LVALUE_EXPR:
7851 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7856 case ARRAY_RANGE_REF:
7859 HOST_WIDE_INT bitsize, bitpos, bytepos;
7860 enum machine_mode mode;
7862 unsigned int alignment;
7864 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7865 &unsignedp, &volatilep, &alignment);
7866 ret = loc_descriptor_from_tree (obj, 1);
7868 if (offset != NULL_TREE)
7870 /* Variable offset. */
7871 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7872 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7877 /* We cannot address anything not on a unit boundary. */
7878 if (bitpos % BITS_PER_UNIT != 0)
7883 if (bitpos % BITS_PER_UNIT != 0
7884 || bitsize % BITS_PER_UNIT != 0)
7886 /* ??? We could handle this by loading and shifting etc.
7887 Wait until someone needs it before expending the effort. */
7891 indirect_size = bitsize / BITS_PER_UNIT;
7894 bytepos = bitpos / BITS_PER_UNIT;
7896 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7897 else if (bytepos < 0)
7899 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7900 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7906 if (host_integerp (loc, 0))
7907 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7919 case TRUNC_DIV_EXPR:
7925 case TRUNC_MOD_EXPR:
7935 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7938 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7939 && host_integerp (TREE_OPERAND (loc, 1), 0))
7941 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7942 add_loc_descr (&ret,
7943 new_loc_descr (DW_OP_plus_uconst,
7944 tree_low_cst (TREE_OPERAND (loc, 1),
7952 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7957 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7962 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7967 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7979 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7980 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7981 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7995 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7996 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8000 loc = build (COND_EXPR, TREE_TYPE (loc),
8001 build (LT_EXPR, integer_type_node,
8002 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8003 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8008 dw_loc_descr_ref bra_node, jump_node, tmp;
8010 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8011 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8012 add_loc_descr (&ret, bra_node);
8014 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8015 add_loc_descr (&ret, tmp);
8016 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8017 add_loc_descr (&ret, jump_node);
8019 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8020 add_loc_descr (&ret, tmp);
8021 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8022 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8024 /* ??? Need a node to point the skip at. Use a nop. */
8025 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8026 add_loc_descr (&ret, tmp);
8027 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8028 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8036 /* If we can't fill the request for an address, die. */
8037 if (addressp && indirect_size == 0)
8040 /* If we've got an address and don't want one, dereference. */
8041 if (!addressp && indirect_size > 0)
8043 if (indirect_size > DWARF2_ADDR_SIZE)
8045 if (indirect_size == DWARF2_ADDR_SIZE)
8048 op = DW_OP_deref_size;
8049 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8055 /* Given a value, round it up to the lowest multiple of `boundary'
8056 which is not less than the value itself. */
8058 static inline HOST_WIDE_INT
8059 ceiling (value, boundary)
8060 HOST_WIDE_INT value;
8061 unsigned int boundary;
8063 return (((value + boundary - 1) / boundary) * boundary);
8066 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8067 pointer to the declared type for the relevant field variable, or return
8068 `integer_type_node' if the given node turns out to be an
8077 if (TREE_CODE (decl) == ERROR_MARK)
8078 return integer_type_node;
8080 type = DECL_BIT_FIELD_TYPE (decl);
8081 if (type == NULL_TREE)
8082 type = TREE_TYPE (decl);
8087 /* Given a pointer to a tree node, return the alignment in bits for
8088 it, or else return BITS_PER_WORD if the node actually turns out to
8089 be an ERROR_MARK node. */
8091 static inline unsigned
8092 simple_type_align_in_bits (type)
8095 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8098 static inline unsigned
8099 simple_decl_align_in_bits (decl)
8102 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8105 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8106 node, return the size in bits for the type if it is a constant, or else
8107 return the alignment for the type if the type's size is not constant, or
8108 else return BITS_PER_WORD if the type actually turns out to be an
8111 static inline unsigned HOST_WIDE_INT
8112 simple_type_size_in_bits (type)
8115 tree type_size_tree;
8117 if (TREE_CODE (type) == ERROR_MARK)
8118 return BITS_PER_WORD;
8119 type_size_tree = TYPE_SIZE (type);
8121 if (type_size_tree == NULL_TREE)
8123 if (! host_integerp (type_size_tree, 1))
8124 return TYPE_ALIGN (type);
8125 return tree_low_cst (type_size_tree, 1);
8128 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8129 return the byte offset of the lowest addressed byte of the "containing
8130 object" for the given FIELD_DECL, or return 0 if we are unable to
8131 determine what that offset is, either because the argument turns out to
8132 be a pointer to an ERROR_MARK node, or because the offset is actually
8133 variable. (We can't handle the latter case just yet). */
8135 static HOST_WIDE_INT
8136 field_byte_offset (decl)
8139 unsigned int type_align_in_bits;
8140 unsigned int decl_align_in_bits;
8141 unsigned HOST_WIDE_INT type_size_in_bits;
8142 HOST_WIDE_INT object_offset_in_bits;
8143 HOST_WIDE_INT object_offset_in_bytes;
8145 tree field_size_tree;
8146 HOST_WIDE_INT bitpos_int;
8147 HOST_WIDE_INT deepest_bitpos;
8148 unsigned HOST_WIDE_INT field_size_in_bits;
8150 if (TREE_CODE (decl) == ERROR_MARK)
8153 if (TREE_CODE (decl) != FIELD_DECL)
8156 type = field_type (decl);
8157 field_size_tree = DECL_SIZE (decl);
8159 /* The size could be unspecified if there was an error, or for
8160 a flexible array member. */
8161 if (! field_size_tree)
8162 field_size_tree = bitsize_zero_node;
8164 /* We cannot yet cope with fields whose positions are variable, so
8165 for now, when we see such things, we simply return 0. Someday, we may
8166 be able to handle such cases, but it will be damn difficult. */
8167 if (! host_integerp (bit_position (decl), 0))
8170 bitpos_int = int_bit_position (decl);
8172 /* If we don't know the size of the field, pretend it's a full word. */
8173 if (host_integerp (field_size_tree, 1))
8174 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8176 field_size_in_bits = BITS_PER_WORD;
8178 type_size_in_bits = simple_type_size_in_bits (type);
8179 type_align_in_bits = simple_type_align_in_bits (type);
8180 decl_align_in_bits = simple_decl_align_in_bits (decl);
8182 /* Note that the GCC front-end doesn't make any attempt to keep track of
8183 the starting bit offset (relative to the start of the containing
8184 structure type) of the hypothetical "containing object" for a bit-
8185 field. Thus, when computing the byte offset value for the start of the
8186 "containing object" of a bit-field, we must deduce this information on
8187 our own. This can be rather tricky to do in some cases. For example,
8188 handling the following structure type definition when compiling for an
8189 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8192 struct S { int field1; long long field2:31; };
8194 Fortunately, there is a simple rule-of-thumb which can be
8195 used in such cases. When compiling for an i386/i486, GCC will allocate
8196 8 bytes for the structure shown above. It decides to do this based upon
8197 one simple rule for bit-field allocation. Quite simply, GCC allocates
8198 each "containing object" for each bit-field at the first (i.e. lowest
8199 addressed) legitimate alignment boundary (based upon the required
8200 minimum alignment for the declared type of the field) which it can
8201 possibly use, subject to the condition that there is still enough
8202 available space remaining in the containing object (when allocated at
8203 the selected point) to fully accommodate all of the bits of the
8204 bit-field itself. This simple rule makes it obvious why GCC allocates
8205 8 bytes for each object of the structure type shown above. When looking
8206 for a place to allocate the "containing object" for `field2', the
8207 compiler simply tries to allocate a 64-bit "containing object" at each
8208 successive 32-bit boundary (starting at zero) until it finds a place to
8209 allocate that 64- bit field such that at least 31 contiguous (and
8210 previously unallocated) bits remain within that selected 64 bit field.
8211 (As it turns out, for the example above, the compiler finds that it is
8212 OK to allocate the "containing object" 64-bit field at bit-offset zero
8213 within the structure type.) Here we attempt to work backwards from the
8214 limited set of facts we're given, and we try to deduce from those facts,
8215 where GCC must have believed that the containing object started (within
8216 the structure type). The value we deduce is then used (by the callers of
8217 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8218 for fields (both bit-fields and, in the case of DW_AT_location, regular
8221 /* Figure out the bit-distance from the start of the structure to the
8222 "deepest" bit of the bit-field. */
8223 deepest_bitpos = bitpos_int + field_size_in_bits;
8225 /* This is the tricky part. Use some fancy footwork to deduce where the
8226 lowest addressed bit of the containing object must be. */
8227 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8229 /* Round up to type_align by default. This works best for bitfields. */
8230 object_offset_in_bits += type_align_in_bits - 1;
8231 object_offset_in_bits /= type_align_in_bits;
8232 object_offset_in_bits *= type_align_in_bits;
8234 if (object_offset_in_bits > bitpos_int)
8236 /* Sigh, the decl must be packed. */
8237 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8239 /* Round up to decl_align instead. */
8240 object_offset_in_bits += decl_align_in_bits - 1;
8241 object_offset_in_bits /= decl_align_in_bits;
8242 object_offset_in_bits *= decl_align_in_bits;
8245 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8247 return object_offset_in_bytes;
8250 /* The following routines define various Dwarf attributes and any data
8251 associated with them. */
8253 /* Add a location description attribute value to a DIE.
8255 This emits location attributes suitable for whole variables and
8256 whole parameters. Note that the location attributes for struct fields are
8257 generated by the routine `data_member_location_attribute' below. */
8260 add_AT_location_description (die, attr_kind, rtl)
8262 enum dwarf_attribute attr_kind;
8265 /* Handle a special case. If we are about to output a location descriptor
8266 for a variable or parameter which has been optimized out of existence,
8267 don't do that. A variable which has been optimized out
8268 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8269 Currently, in some rare cases, variables can have DECL_RTL values which
8270 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8271 elsewhere in the compiler. We treat such cases as if the variable(s) in
8272 question had been optimized out of existence. */
8274 if (is_pseudo_reg (rtl)
8275 || (GET_CODE (rtl) == MEM
8276 && is_pseudo_reg (XEXP (rtl, 0)))
8277 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8278 references the internal argument pointer (a pseudo) in a function
8279 where all references to the internal argument pointer were
8280 eliminated via the optimizers. */
8281 || (GET_CODE (rtl) == MEM
8282 && GET_CODE (XEXP (rtl, 0)) == PLUS
8283 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8284 || (GET_CODE (rtl) == CONCAT
8285 && is_pseudo_reg (XEXP (rtl, 0))
8286 && is_pseudo_reg (XEXP (rtl, 1))))
8289 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8292 /* Attach the specialized form of location attribute used for data
8293 members of struct and union types. In the special case of a
8294 FIELD_DECL node which represents a bit-field, the "offset" part
8295 of this special location descriptor must indicate the distance
8296 in bytes from the lowest-addressed byte of the containing struct
8297 or union type to the lowest-addressed byte of the "containing
8298 object" for the bit-field. (See the `field_byte_offset' function
8299 above).. For any given bit-field, the "containing object" is a
8300 hypothetical object (of some integral or enum type) within which
8301 the given bit-field lives. The type of this hypothetical
8302 "containing object" is always the same as the declared type of
8303 the individual bit-field itself (for GCC anyway... the DWARF
8304 spec doesn't actually mandate this). Note that it is the size
8305 (in bytes) of the hypothetical "containing object" which will
8306 be given in the DW_AT_byte_size attribute for this bit-field.
8307 (See the `byte_size_attribute' function below.) It is also used
8308 when calculating the value of the DW_AT_bit_offset attribute.
8309 (See the `bit_offset_attribute' function below). */
8312 add_data_member_location_attribute (die, decl)
8313 register dw_die_ref die;
8316 register unsigned long offset;
8317 register dw_loc_descr_ref loc_descr;
8318 register enum dwarf_location_atom op;
8320 if (TREE_CODE (decl) == TREE_VEC)
8321 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8323 offset = field_byte_offset (decl);
8325 /* The DWARF2 standard says that we should assume that the structure address
8326 is already on the stack, so we can specify a structure field address
8327 by using DW_OP_plus_uconst. */
8329 #ifdef MIPS_DEBUGGING_INFO
8330 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8331 correctly. It works only if we leave the offset on the stack. */
8334 op = DW_OP_plus_uconst;
8337 loc_descr = new_loc_descr (op, offset, 0);
8338 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8341 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8342 does not have a "location" either in memory or in a register. These
8343 things can arise in GNU C when a constant is passed as an actual parameter
8344 to an inlined function. They can also arise in C++ where declared
8345 constants do not necessarily get memory "homes". */
8348 add_const_value_attribute (die, rtl)
8349 register dw_die_ref die;
8352 switch (GET_CODE (rtl))
8355 /* Note that a CONST_INT rtx could represent either an integer
8356 or a floating-point constant. A CONST_INT is used whenever
8357 the constant will fit into a single word. In all such
8358 cases, the original mode of the constant value is wiped
8359 out, and the CONST_INT rtx is assigned VOIDmode. */
8361 HOST_WIDE_INT val = INTVAL (rtl);
8363 /* ??? We really should be using HOST_WIDE_INT throughout. */
8366 if ((long) val != val)
8368 add_AT_int (die, DW_AT_const_value, (long) val);
8372 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8374 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8380 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8381 floating-point constant. A CONST_DOUBLE is used whenever the
8382 constant requires more than one word in order to be adequately
8383 represented. We output CONST_DOUBLEs as blocks. */
8385 register enum machine_mode mode = GET_MODE (rtl);
8387 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8389 register unsigned length = GET_MODE_SIZE (mode) / 4;
8390 long *array = (long *) xmalloc (sizeof (long) * length);
8393 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8397 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8401 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8406 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8413 add_AT_float (die, DW_AT_const_value, length, array);
8417 /* ??? We really should be using HOST_WIDE_INT throughout. */
8418 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8420 add_AT_long_long (die, DW_AT_const_value,
8421 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8427 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8433 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8437 /* In cases where an inlined instance of an inline function is passed
8438 the address of an `auto' variable (which is local to the caller) we
8439 can get a situation where the DECL_RTL of the artificial local
8440 variable (for the inlining) which acts as a stand-in for the
8441 corresponding formal parameter (of the inline function) will look
8442 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8443 exactly a compile-time constant expression, but it isn't the address
8444 of the (artificial) local variable either. Rather, it represents the
8445 *value* which the artificial local variable always has during its
8446 lifetime. We currently have no way to represent such quasi-constant
8447 values in Dwarf, so for now we just punt and generate nothing. */
8451 /* No other kinds of rtx should be possible here. */
8458 rtl_for_decl_location (decl)
8463 /* Here we have to decide where we are going to say the parameter "lives"
8464 (as far as the debugger is concerned). We only have a couple of
8465 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8467 DECL_RTL normally indicates where the parameter lives during most of the
8468 activation of the function. If optimization is enabled however, this
8469 could be either NULL or else a pseudo-reg. Both of those cases indicate
8470 that the parameter doesn't really live anywhere (as far as the code
8471 generation parts of GCC are concerned) during most of the function's
8472 activation. That will happen (for example) if the parameter is never
8473 referenced within the function.
8475 We could just generate a location descriptor here for all non-NULL
8476 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8477 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8478 where DECL_RTL is NULL or is a pseudo-reg.
8480 Note however that we can only get away with using DECL_INCOMING_RTL as
8481 a backup substitute for DECL_RTL in certain limited cases. In cases
8482 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8483 we can be sure that the parameter was passed using the same type as it is
8484 declared to have within the function, and that its DECL_INCOMING_RTL
8485 points us to a place where a value of that type is passed.
8487 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8488 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8489 because in these cases DECL_INCOMING_RTL points us to a value of some
8490 type which is *different* from the type of the parameter itself. Thus,
8491 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8492 such cases, the debugger would end up (for example) trying to fetch a
8493 `float' from a place which actually contains the first part of a
8494 `double'. That would lead to really incorrect and confusing
8495 output at debug-time.
8497 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8498 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8499 are a couple of exceptions however. On little-endian machines we can
8500 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8501 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8502 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8503 when (on a little-endian machine) a non-prototyped function has a
8504 parameter declared to be of type `short' or `char'. In such cases,
8505 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8506 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8507 passed `int' value. If the debugger then uses that address to fetch
8508 a `short' or a `char' (on a little-endian machine) the result will be
8509 the correct data, so we allow for such exceptional cases below.
8511 Note that our goal here is to describe the place where the given formal
8512 parameter lives during most of the function's activation (i.e. between
8513 the end of the prologue and the start of the epilogue). We'll do that
8514 as best as we can. Note however that if the given formal parameter is
8515 modified sometime during the execution of the function, then a stack
8516 backtrace (at debug-time) will show the function as having been
8517 called with the *new* value rather than the value which was
8518 originally passed in. This happens rarely enough that it is not
8519 a major problem, but it *is* a problem, and I'd like to fix it.
8521 A future version of dwarf2out.c may generate two additional
8522 attributes for any given DW_TAG_formal_parameter DIE which will
8523 describe the "passed type" and the "passed location" for the
8524 given formal parameter in addition to the attributes we now
8525 generate to indicate the "declared type" and the "active
8526 location" for each parameter. This additional set of attributes
8527 could be used by debuggers for stack backtraces. Separately, note
8528 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8529 NULL also. This happens (for example) for inlined-instances of
8530 inline function formal parameters which are never referenced.
8531 This really shouldn't be happening. All PARM_DECL nodes should
8532 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8533 doesn't currently generate these values for inlined instances of
8534 inline function parameters, so when we see such cases, we are
8535 just out-of-luck for the time being (until integrate.c
8538 /* Use DECL_RTL as the "location" unless we find something better. */
8539 rtl = DECL_RTL_IF_SET (decl);
8541 if (TREE_CODE (decl) == PARM_DECL)
8543 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8545 tree declared_type = type_main_variant (TREE_TYPE (decl));
8546 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8548 /* This decl represents a formal parameter which was optimized out.
8549 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8550 all* cases where (rtl == NULL_RTX) just below. */
8551 if (declared_type == passed_type)
8552 rtl = DECL_INCOMING_RTL (decl);
8553 else if (! BYTES_BIG_ENDIAN
8554 && TREE_CODE (declared_type) == INTEGER_TYPE
8555 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8556 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8557 rtl = DECL_INCOMING_RTL (decl);
8560 /* If the parm was passed in registers, but lives on the stack, then
8561 make a big endian correction if the mode of the type of the
8562 parameter is not the same as the mode of the rtl. */
8563 /* ??? This is the same series of checks that are made in dbxout.c before
8564 we reach the big endian correction code there. It isn't clear if all
8565 of these checks are necessary here, but keeping them all is the safe
8567 else if (GET_CODE (rtl) == MEM
8568 && XEXP (rtl, 0) != const0_rtx
8569 && ! CONSTANT_P (XEXP (rtl, 0))
8570 /* Not passed in memory. */
8571 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8572 /* Not passed by invisible reference. */
8573 && (GET_CODE (XEXP (rtl, 0)) != REG
8574 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8575 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8576 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8577 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8580 /* Big endian correction check. */
8582 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8583 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8586 int offset = (UNITS_PER_WORD
8587 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8588 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8589 plus_constant (XEXP (rtl, 0), offset));
8593 if (rtl != NULL_RTX)
8595 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8596 #ifdef LEAF_REG_REMAP
8597 if (current_function_uses_only_leaf_regs)
8598 leaf_renumber_regs_insn (rtl);
8605 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8606 data attribute for a variable or a parameter. We generate the
8607 DW_AT_const_value attribute only in those cases where the given variable
8608 or parameter does not have a true "location" either in memory or in a
8609 register. This can happen (for example) when a constant is passed as an
8610 actual argument in a call to an inline function. (It's possible that
8611 these things can crop up in other ways also.) Note that one type of
8612 constant value which can be passed into an inlined function is a constant
8613 pointer. This can happen for example if an actual argument in an inlined
8614 function call evaluates to a compile-time constant address. */
8617 add_location_or_const_value_attribute (die, decl)
8618 register dw_die_ref die;
8623 if (TREE_CODE (decl) == ERROR_MARK)
8626 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8629 rtl = rtl_for_decl_location (decl);
8630 if (rtl == NULL_RTX)
8633 /* If we don't look past the constant pool, we risk emitting a
8634 reference to a constant pool entry that isn't referenced from
8635 code, and thus is not emitted. */
8636 rtl = avoid_constant_pool_reference (rtl);
8638 switch (GET_CODE (rtl))
8641 /* The address of a variable that was optimized away; don't emit
8652 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8653 add_const_value_attribute (die, rtl);
8660 add_AT_location_description (die, DW_AT_location, rtl);
8668 /* If we don't have a copy of this variable in memory for some reason (such
8669 as a C++ member constant that doesn't have an out-of-line definition),
8670 we should tell the debugger about the constant value. */
8673 tree_add_const_value_attribute (var_die, decl)
8677 tree init = DECL_INITIAL (decl);
8678 tree type = TREE_TYPE (decl);
8680 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8681 && initializer_constant_valid_p (init, type) == null_pointer_node)
8686 switch (TREE_CODE (type))
8689 if (host_integerp (init, 0))
8690 add_AT_unsigned (var_die, DW_AT_const_value,
8691 TREE_INT_CST_LOW (init));
8693 add_AT_long_long (var_die, DW_AT_const_value,
8694 TREE_INT_CST_HIGH (init),
8695 TREE_INT_CST_LOW (init));
8702 /* Generate an DW_AT_name attribute given some string value to be included as
8703 the value of the attribute. */
8706 add_name_attribute (die, name_string)
8707 register dw_die_ref die;
8708 register const char *name_string;
8710 if (name_string != NULL && *name_string != 0)
8712 if (demangle_name_func)
8713 name_string = (*demangle_name_func) (name_string);
8715 add_AT_string (die, DW_AT_name, name_string);
8719 /* Given a tree node describing an array bound (either lower or upper) output
8720 a representation for that bound. */
8723 add_bound_info (subrange_die, bound_attr, bound)
8724 register dw_die_ref subrange_die;
8725 register enum dwarf_attribute bound_attr;
8726 register tree bound;
8728 /* If this is an Ada unconstrained array type, then don't emit any debug
8729 info because the array bounds are unknown. They are parameterized when
8730 the type is instantiated. */
8731 if (contains_placeholder_p (bound))
8734 switch (TREE_CODE (bound))
8739 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8741 if (! host_integerp (bound, 0)
8742 || (bound_attr == DW_AT_lower_bound
8743 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8744 || (is_fortran () && integer_onep (bound)))))
8745 /* use the default */
8748 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8753 case NON_LVALUE_EXPR:
8754 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8758 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8759 access the upper bound values may be bogus. If they refer to a
8760 register, they may only describe how to get at these values at the
8761 points in the generated code right after they have just been
8762 computed. Worse yet, in the typical case, the upper bound values
8763 will not even *be* computed in the optimized code (though the
8764 number of elements will), so these SAVE_EXPRs are entirely
8765 bogus. In order to compensate for this fact, we check here to see
8766 if optimization is enabled, and if so, we don't add an attribute
8767 for the (unknown and unknowable) upper bound. This should not
8768 cause too much trouble for existing (stupid?) debuggers because
8769 they have to deal with empty upper bounds location descriptions
8770 anyway in order to be able to deal with incomplete array types.
8771 Of course an intelligent debugger (GDB?) should be able to
8772 comprehend that a missing upper bound specification in a array
8773 type used for a storage class `auto' local array variable
8774 indicates that the upper bound is both unknown (at compile- time)
8775 and unknowable (at run-time) due to optimization.
8777 We assume that a MEM rtx is safe because gcc wouldn't put the
8778 value there unless it was going to be used repeatedly in the
8779 function, i.e. for cleanups. */
8780 if (SAVE_EXPR_RTL (bound)
8781 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8783 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8784 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8785 register rtx loc = SAVE_EXPR_RTL (bound);
8787 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8788 it references an outer function's frame. */
8790 if (GET_CODE (loc) == MEM)
8792 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8794 if (XEXP (loc, 0) != new_addr)
8795 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8798 add_AT_flag (decl_die, DW_AT_artificial, 1);
8799 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8800 add_AT_location_description (decl_die, DW_AT_location, loc);
8801 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8804 /* Else leave out the attribute. */
8810 dw_die_ref decl_die = lookup_decl_die (bound);
8812 /* ??? Can this happen, or should the variable have been bound
8813 first? Probably it can, since I imagine that we try to create
8814 the types of parameters in the order in which they exist in
8815 the list, and won't have created a forward reference to a
8817 if (decl_die != NULL)
8818 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8824 /* Otherwise try to create a stack operation procedure to
8825 evaluate the value of the array bound. */
8827 dw_die_ref ctx, decl_die;
8828 dw_loc_descr_ref loc;
8830 loc = loc_descriptor_from_tree (bound, 0);
8834 ctx = lookup_decl_die (current_function_decl);
8836 decl_die = new_die (DW_TAG_variable, ctx);
8837 add_AT_flag (decl_die, DW_AT_artificial, 1);
8838 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8839 add_AT_loc (decl_die, DW_AT_location, loc);
8841 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8847 /* Note that the block of subscript information for an array type also
8848 includes information about the element type of type given array type. */
8851 add_subscript_info (type_die, type)
8852 register dw_die_ref type_die;
8855 #ifndef MIPS_DEBUGGING_INFO
8856 register unsigned dimension_number;
8858 register tree lower, upper;
8859 register dw_die_ref subrange_die;
8861 /* The GNU compilers represent multidimensional array types as sequences of
8862 one dimensional array types whose element types are themselves array
8863 types. Here we squish that down, so that each multidimensional array
8864 type gets only one array_type DIE in the Dwarf debugging info. The draft
8865 Dwarf specification say that we are allowed to do this kind of
8866 compression in C (because there is no difference between an array or
8867 arrays and a multidimensional array in C) but for other source languages
8868 (e.g. Ada) we probably shouldn't do this. */
8870 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8871 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8872 We work around this by disabling this feature. See also
8873 gen_array_type_die. */
8874 #ifndef MIPS_DEBUGGING_INFO
8875 for (dimension_number = 0;
8876 TREE_CODE (type) == ARRAY_TYPE;
8877 type = TREE_TYPE (type), dimension_number++)
8880 register tree domain = TYPE_DOMAIN (type);
8882 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8883 and (in GNU C only) variable bounds. Handle all three forms
8885 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8888 /* We have an array type with specified bounds. */
8889 lower = TYPE_MIN_VALUE (domain);
8890 upper = TYPE_MAX_VALUE (domain);
8892 /* define the index type. */
8893 if (TREE_TYPE (domain))
8895 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8896 TREE_TYPE field. We can't emit debug info for this
8897 because it is an unnamed integral type. */
8898 if (TREE_CODE (domain) == INTEGER_TYPE
8899 && TYPE_NAME (domain) == NULL_TREE
8900 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8901 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8904 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8908 /* ??? If upper is NULL, the array has unspecified length,
8909 but it does have a lower bound. This happens with Fortran
8911 Since the debugger is definitely going to need to know N
8912 to produce useful results, go ahead and output the lower
8913 bound solo, and hope the debugger can cope. */
8915 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8917 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8920 /* We have an array type with an unspecified length. The DWARF-2
8921 spec does not say how to handle this; let's just leave out the
8925 #ifndef MIPS_DEBUGGING_INFO
8931 add_byte_size_attribute (die, tree_node)
8933 register tree tree_node;
8935 register unsigned size;
8937 switch (TREE_CODE (tree_node))
8945 case QUAL_UNION_TYPE:
8946 size = int_size_in_bytes (tree_node);
8949 /* For a data member of a struct or union, the DW_AT_byte_size is
8950 generally given as the number of bytes normally allocated for an
8951 object of the *declared* type of the member itself. This is true
8952 even for bit-fields. */
8953 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8959 /* Note that `size' might be -1 when we get to this point. If it is, that
8960 indicates that the byte size of the entity in question is variable. We
8961 have no good way of expressing this fact in Dwarf at the present time,
8962 so just let the -1 pass on through. */
8964 add_AT_unsigned (die, DW_AT_byte_size, size);
8967 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8968 which specifies the distance in bits from the highest order bit of the
8969 "containing object" for the bit-field to the highest order bit of the
8972 For any given bit-field, the "containing object" is a hypothetical
8973 object (of some integral or enum type) within which the given bit-field
8974 lives. The type of this hypothetical "containing object" is always the
8975 same as the declared type of the individual bit-field itself. The
8976 determination of the exact location of the "containing object" for a
8977 bit-field is rather complicated. It's handled by the
8978 `field_byte_offset' function (above).
8980 Note that it is the size (in bytes) of the hypothetical "containing object"
8981 which will be given in the DW_AT_byte_size attribute for this bit-field.
8982 (See `byte_size_attribute' above). */
8985 add_bit_offset_attribute (die, decl)
8986 register dw_die_ref die;
8989 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8990 tree type = DECL_BIT_FIELD_TYPE (decl);
8991 HOST_WIDE_INT bitpos_int;
8992 HOST_WIDE_INT highest_order_object_bit_offset;
8993 HOST_WIDE_INT highest_order_field_bit_offset;
8994 HOST_WIDE_INT unsigned bit_offset;
8996 /* Must be a field and a bit field. */
8998 || TREE_CODE (decl) != FIELD_DECL)
9001 /* We can't yet handle bit-fields whose offsets are variable, so if we
9002 encounter such things, just return without generating any attribute
9003 whatsoever. Likewise for variable or too large size. */
9004 if (! host_integerp (bit_position (decl), 0)
9005 || ! host_integerp (DECL_SIZE (decl), 1))
9008 bitpos_int = int_bit_position (decl);
9010 /* Note that the bit offset is always the distance (in bits) from the
9011 highest-order bit of the "containing object" to the highest-order bit of
9012 the bit-field itself. Since the "high-order end" of any object or field
9013 is different on big-endian and little-endian machines, the computation
9014 below must take account of these differences. */
9015 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9016 highest_order_field_bit_offset = bitpos_int;
9018 if (! BYTES_BIG_ENDIAN)
9020 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9021 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9025 = (! BYTES_BIG_ENDIAN
9026 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9027 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9029 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9032 /* For a FIELD_DECL node which represents a bit field, output an attribute
9033 which specifies the length in bits of the given field. */
9036 add_bit_size_attribute (die, decl)
9037 register dw_die_ref die;
9040 /* Must be a field and a bit field. */
9041 if (TREE_CODE (decl) != FIELD_DECL
9042 || ! DECL_BIT_FIELD_TYPE (decl))
9045 if (host_integerp (DECL_SIZE (decl), 1))
9046 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9049 /* If the compiled language is ANSI C, then add a 'prototyped'
9050 attribute, if arg types are given for the parameters of a function. */
9053 add_prototyped_attribute (die, func_type)
9054 register dw_die_ref die;
9055 register tree func_type;
9057 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9058 && TYPE_ARG_TYPES (func_type) != NULL)
9059 add_AT_flag (die, DW_AT_prototyped, 1);
9062 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9063 by looking in either the type declaration or object declaration
9067 add_abstract_origin_attribute (die, origin)
9068 register dw_die_ref die;
9069 register tree origin;
9071 dw_die_ref origin_die = NULL;
9073 if (TREE_CODE (origin) != FUNCTION_DECL)
9075 /* We may have gotten separated from the block for the inlined
9076 function, if we're in an exception handler or some such; make
9077 sure that the abstract function has been written out.
9079 Doing this for nested functions is wrong, however; functions are
9080 distinct units, and our context might not even be inline. */
9083 fn = TYPE_STUB_DECL (fn);
9084 fn = decl_function_context (fn);
9086 dwarf2out_abstract_function (fn);
9089 if (DECL_P (origin))
9090 origin_die = lookup_decl_die (origin);
9091 else if (TYPE_P (origin))
9092 origin_die = lookup_type_die (origin);
9094 if (origin_die == NULL)
9097 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9100 /* We do not currently support the pure_virtual attribute. */
9103 add_pure_or_virtual_attribute (die, func_decl)
9104 register dw_die_ref die;
9105 register tree func_decl;
9107 if (DECL_VINDEX (func_decl))
9109 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9111 if (host_integerp (DECL_VINDEX (func_decl), 0))
9112 add_AT_loc (die, DW_AT_vtable_elem_location,
9113 new_loc_descr (DW_OP_constu,
9114 tree_low_cst (DECL_VINDEX (func_decl), 0),
9117 /* GNU extension: Record what type this method came from originally. */
9118 if (debug_info_level > DINFO_LEVEL_TERSE)
9119 add_AT_die_ref (die, DW_AT_containing_type,
9120 lookup_type_die (DECL_CONTEXT (func_decl)));
9124 /* Add source coordinate attributes for the given decl. */
9127 add_src_coords_attributes (die, decl)
9128 register dw_die_ref die;
9131 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9133 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9134 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9137 /* Add an DW_AT_name attribute and source coordinate attribute for the
9138 given decl, but only if it actually has a name. */
9141 add_name_and_src_coords_attributes (die, decl)
9142 register dw_die_ref die;
9145 register tree decl_name;
9147 decl_name = DECL_NAME (decl);
9148 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9150 add_name_attribute (die, dwarf2_name (decl, 0));
9151 if (! DECL_ARTIFICIAL (decl))
9152 add_src_coords_attributes (die, decl);
9154 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9155 && TREE_PUBLIC (decl)
9156 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9157 && !DECL_ABSTRACT (decl))
9158 add_AT_string (die, DW_AT_MIPS_linkage_name,
9159 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9163 /* Push a new declaration scope. */
9166 push_decl_scope (scope)
9169 /* Make room in the decl_scope_table, if necessary. */
9170 if (decl_scope_table_allocated == decl_scope_depth)
9172 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9174 = (tree *) xrealloc (decl_scope_table,
9175 decl_scope_table_allocated * sizeof (tree));
9178 decl_scope_table[decl_scope_depth] = scope;
9182 /* Pop a declaration scope. */
9186 if (decl_scope_depth <= 0)
9191 /* Return the DIE for the scope that immediately contains this type.
9192 Non-named types get global scope. Named types nested in other
9193 types get their containing scope if it's open, or global scope
9194 otherwise. All other types (i.e. function-local named types) get
9195 the current active scope. */
9198 scope_die_for (t, context_die)
9200 register dw_die_ref context_die;
9202 register dw_die_ref scope_die = NULL;
9203 register tree containing_scope;
9206 /* Non-types always go in the current scope. */
9210 containing_scope = TYPE_CONTEXT (t);
9212 /* Ignore namespaces for the moment. */
9213 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9214 containing_scope = NULL_TREE;
9216 /* Ignore function type "scopes" from the C frontend. They mean that
9217 a tagged type is local to a parmlist of a function declarator, but
9218 that isn't useful to DWARF. */
9219 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9220 containing_scope = NULL_TREE;
9222 if (containing_scope == NULL_TREE)
9223 scope_die = comp_unit_die;
9224 else if (TYPE_P (containing_scope))
9226 /* For types, we can just look up the appropriate DIE. But
9227 first we check to see if we're in the middle of emitting it
9228 so we know where the new DIE should go. */
9230 for (i = decl_scope_depth - 1; i >= 0; --i)
9231 if (decl_scope_table[i] == containing_scope)
9236 if (debug_info_level > DINFO_LEVEL_TERSE
9237 && !TREE_ASM_WRITTEN (containing_scope))
9240 /* If none of the current dies are suitable, we get file scope. */
9241 scope_die = comp_unit_die;
9244 scope_die = lookup_type_die (containing_scope);
9247 scope_die = context_die;
9252 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9254 static inline int local_scope_p PARAMS ((dw_die_ref));
9256 local_scope_p (context_die)
9257 dw_die_ref context_die;
9259 for (; context_die; context_die = context_die->die_parent)
9260 if (context_die->die_tag == DW_TAG_inlined_subroutine
9261 || context_die->die_tag == DW_TAG_subprogram)
9266 /* Returns nonzero iff CONTEXT_DIE is a class. */
9268 static inline int class_scope_p PARAMS ((dw_die_ref));
9270 class_scope_p (context_die)
9271 dw_die_ref context_die;
9274 && (context_die->die_tag == DW_TAG_structure_type
9275 || context_die->die_tag == DW_TAG_union_type));
9278 /* Many forms of DIEs require a "type description" attribute. This
9279 routine locates the proper "type descriptor" die for the type given
9280 by 'type', and adds an DW_AT_type attribute below the given die. */
9283 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9284 register dw_die_ref object_die;
9286 register int decl_const;
9287 register int decl_volatile;
9288 register dw_die_ref context_die;
9290 register enum tree_code code = TREE_CODE (type);
9291 register dw_die_ref type_die = NULL;
9293 /* ??? If this type is an unnamed subrange type of an integral or
9294 floating-point type, use the inner type. This is because we have no
9295 support for unnamed types in base_type_die. This can happen if this is
9296 an Ada subrange type. Correct solution is emit a subrange type die. */
9297 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9298 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9299 type = TREE_TYPE (type), code = TREE_CODE (type);
9301 if (code == ERROR_MARK)
9304 /* Handle a special case. For functions whose return type is void, we
9305 generate *no* type attribute. (Note that no object may have type
9306 `void', so this only applies to function return types). */
9307 if (code == VOID_TYPE)
9310 type_die = modified_type_die (type,
9311 decl_const || TYPE_READONLY (type),
9312 decl_volatile || TYPE_VOLATILE (type),
9314 if (type_die != NULL)
9315 add_AT_die_ref (object_die, DW_AT_type, type_die);
9318 /* Given a tree pointer to a struct, class, union, or enum type node, return
9319 a pointer to the (string) tag name for the given type, or zero if the type
9320 was declared without a tag. */
9326 register const char *name = 0;
9328 if (TYPE_NAME (type) != 0)
9330 register tree t = 0;
9332 /* Find the IDENTIFIER_NODE for the type name. */
9333 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9334 t = TYPE_NAME (type);
9336 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9337 a TYPE_DECL node, regardless of whether or not a `typedef' was
9339 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9340 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9341 t = DECL_NAME (TYPE_NAME (type));
9343 /* Now get the name as a string, or invent one. */
9345 name = IDENTIFIER_POINTER (t);
9348 return (name == 0 || *name == '\0') ? 0 : name;
9351 /* Return the type associated with a data member, make a special check
9352 for bit field types. */
9355 member_declared_type (member)
9356 register tree member;
9358 return (DECL_BIT_FIELD_TYPE (member)
9359 ? DECL_BIT_FIELD_TYPE (member)
9360 : TREE_TYPE (member));
9363 /* Get the decl's label, as described by its RTL. This may be different
9364 from the DECL_NAME name used in the source file. */
9368 decl_start_label (decl)
9373 x = DECL_RTL (decl);
9374 if (GET_CODE (x) != MEM)
9378 if (GET_CODE (x) != SYMBOL_REF)
9381 fnname = XSTR (x, 0);
9386 /* These routines generate the internal representation of the DIE's for
9387 the compilation unit. Debugging information is collected by walking
9388 the declaration trees passed in from dwarf2out_decl(). */
9391 gen_array_type_die (type, context_die)
9393 register dw_die_ref context_die;
9395 register dw_die_ref scope_die = scope_die_for (type, context_die);
9396 register dw_die_ref array_die;
9397 register tree element_type;
9399 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9400 the inner array type comes before the outer array type. Thus we must
9401 call gen_type_die before we call new_die. See below also. */
9402 #ifdef MIPS_DEBUGGING_INFO
9403 gen_type_die (TREE_TYPE (type), context_die);
9406 array_die = new_die (DW_TAG_array_type, scope_die);
9409 /* We default the array ordering. SDB will probably do
9410 the right things even if DW_AT_ordering is not present. It's not even
9411 an issue until we start to get into multidimensional arrays anyway. If
9412 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9413 then we'll have to put the DW_AT_ordering attribute back in. (But if
9414 and when we find out that we need to put these in, we will only do so
9415 for multidimensional arrays. */
9416 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9419 #ifdef MIPS_DEBUGGING_INFO
9420 /* The SGI compilers handle arrays of unknown bound by setting
9421 AT_declaration and not emitting any subrange DIEs. */
9422 if (! TYPE_DOMAIN (type))
9423 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9426 add_subscript_info (array_die, type);
9428 add_name_attribute (array_die, type_tag (type));
9429 equate_type_number_to_die (type, array_die);
9431 /* Add representation of the type of the elements of this array type. */
9432 element_type = TREE_TYPE (type);
9434 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9435 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9436 We work around this by disabling this feature. See also
9437 add_subscript_info. */
9438 #ifndef MIPS_DEBUGGING_INFO
9439 while (TREE_CODE (element_type) == ARRAY_TYPE)
9440 element_type = TREE_TYPE (element_type);
9442 gen_type_die (element_type, context_die);
9445 add_type_attribute (array_die, element_type, 0, 0, context_die);
9449 gen_set_type_die (type, context_die)
9451 register dw_die_ref context_die;
9453 register dw_die_ref type_die
9454 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9456 equate_type_number_to_die (type, type_die);
9457 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9462 gen_entry_point_die (decl, context_die)
9464 register dw_die_ref context_die;
9466 register tree origin = decl_ultimate_origin (decl);
9467 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9469 add_abstract_origin_attribute (decl_die, origin);
9472 add_name_and_src_coords_attributes (decl_die, decl);
9473 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9477 if (DECL_ABSTRACT (decl))
9478 equate_decl_number_to_die (decl, decl_die);
9480 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9484 /* Remember a type in the incomplete_types_list. */
9487 add_incomplete_type (type)
9490 if (incomplete_types == incomplete_types_allocated)
9492 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9493 incomplete_types_list
9494 = (tree *) xrealloc (incomplete_types_list,
9495 sizeof (tree) * incomplete_types_allocated);
9498 incomplete_types_list[incomplete_types++] = type;
9501 /* Walk through the list of incomplete types again, trying once more to
9502 emit full debugging info for them. */
9505 retry_incomplete_types ()
9509 while (incomplete_types)
9512 type = incomplete_types_list[incomplete_types];
9513 gen_type_die (type, comp_unit_die);
9517 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9520 gen_inlined_enumeration_type_die (type, context_die)
9522 register dw_die_ref context_die;
9524 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9526 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9527 be incomplete and such types are not marked. */
9528 add_abstract_origin_attribute (type_die, type);
9531 /* Generate a DIE to represent an inlined instance of a structure type. */
9534 gen_inlined_structure_type_die (type, context_die)
9536 register dw_die_ref context_die;
9538 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9540 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9541 be incomplete and such types are not marked. */
9542 add_abstract_origin_attribute (type_die, type);
9545 /* Generate a DIE to represent an inlined instance of a union type. */
9548 gen_inlined_union_type_die (type, context_die)
9550 register dw_die_ref context_die;
9552 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9554 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9555 be incomplete and such types are not marked. */
9556 add_abstract_origin_attribute (type_die, type);
9559 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9560 include all of the information about the enumeration values also. Each
9561 enumerated type name/value is listed as a child of the enumerated type
9565 gen_enumeration_type_die (type, context_die)
9567 register dw_die_ref context_die;
9569 register dw_die_ref type_die = lookup_type_die (type);
9571 if (type_die == NULL)
9573 type_die = new_die (DW_TAG_enumeration_type,
9574 scope_die_for (type, context_die));
9575 equate_type_number_to_die (type, type_die);
9576 add_name_attribute (type_die, type_tag (type));
9578 else if (! TYPE_SIZE (type))
9581 remove_AT (type_die, DW_AT_declaration);
9583 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9584 given enum type is incomplete, do not generate the DW_AT_byte_size
9585 attribute or the DW_AT_element_list attribute. */
9586 if (TYPE_SIZE (type))
9590 TREE_ASM_WRITTEN (type) = 1;
9591 add_byte_size_attribute (type_die, type);
9592 if (TYPE_STUB_DECL (type) != NULL_TREE)
9593 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9595 /* If the first reference to this type was as the return type of an
9596 inline function, then it may not have a parent. Fix this now. */
9597 if (type_die->die_parent == NULL)
9598 add_child_die (scope_die_for (type, context_die), type_die);
9600 for (link = TYPE_FIELDS (type);
9601 link != NULL; link = TREE_CHAIN (link))
9603 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9605 add_name_attribute (enum_die,
9606 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9608 if (host_integerp (TREE_VALUE (link), 0))
9610 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9611 add_AT_int (enum_die, DW_AT_const_value,
9612 tree_low_cst (TREE_VALUE (link), 0));
9614 add_AT_unsigned (enum_die, DW_AT_const_value,
9615 tree_low_cst (TREE_VALUE (link), 0));
9620 add_AT_flag (type_die, DW_AT_declaration, 1);
9623 /* Generate a DIE to represent either a real live formal parameter decl or to
9624 represent just the type of some formal parameter position in some function
9627 Note that this routine is a bit unusual because its argument may be a
9628 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9629 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9630 node. If it's the former then this function is being called to output a
9631 DIE to represent a formal parameter object (or some inlining thereof). If
9632 it's the latter, then this function is only being called to output a
9633 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9634 argument type of some subprogram type. */
9637 gen_formal_parameter_die (node, context_die)
9639 register dw_die_ref context_die;
9641 register dw_die_ref parm_die
9642 = new_die (DW_TAG_formal_parameter, context_die);
9643 register tree origin;
9645 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9648 origin = decl_ultimate_origin (node);
9650 add_abstract_origin_attribute (parm_die, origin);
9653 add_name_and_src_coords_attributes (parm_die, node);
9654 add_type_attribute (parm_die, TREE_TYPE (node),
9655 TREE_READONLY (node),
9656 TREE_THIS_VOLATILE (node),
9658 if (DECL_ARTIFICIAL (node))
9659 add_AT_flag (parm_die, DW_AT_artificial, 1);
9662 equate_decl_number_to_die (node, parm_die);
9663 if (! DECL_ABSTRACT (node))
9664 add_location_or_const_value_attribute (parm_die, node);
9669 /* We were called with some kind of a ..._TYPE node. */
9670 add_type_attribute (parm_die, node, 0, 0, context_die);
9680 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9681 at the end of an (ANSI prototyped) formal parameters list. */
9684 gen_unspecified_parameters_die (decl_or_type, context_die)
9685 register tree decl_or_type ATTRIBUTE_UNUSED;
9686 register dw_die_ref context_die;
9688 new_die (DW_TAG_unspecified_parameters, context_die);
9691 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9692 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9693 parameters as specified in some function type specification (except for
9694 those which appear as part of a function *definition*). */
9697 gen_formal_types_die (function_or_method_type, context_die)
9698 register tree function_or_method_type;
9699 register dw_die_ref context_die;
9702 register tree formal_type = NULL;
9703 register tree first_parm_type;
9706 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9708 arg = DECL_ARGUMENTS (function_or_method_type);
9709 function_or_method_type = TREE_TYPE (function_or_method_type);
9714 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9716 /* Make our first pass over the list of formal parameter types and output a
9717 DW_TAG_formal_parameter DIE for each one. */
9718 for (link = first_parm_type; link; )
9720 register dw_die_ref parm_die;
9722 formal_type = TREE_VALUE (link);
9723 if (formal_type == void_type_node)
9726 /* Output a (nameless) DIE to represent the formal parameter itself. */
9727 parm_die = gen_formal_parameter_die (formal_type, context_die);
9728 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9729 && link == first_parm_type)
9730 || (arg && DECL_ARTIFICIAL (arg)))
9731 add_AT_flag (parm_die, DW_AT_artificial, 1);
9733 link = TREE_CHAIN (link);
9735 arg = TREE_CHAIN (arg);
9738 /* If this function type has an ellipsis, add a
9739 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9740 if (formal_type != void_type_node)
9741 gen_unspecified_parameters_die (function_or_method_type, context_die);
9743 /* Make our second (and final) pass over the list of formal parameter types
9744 and output DIEs to represent those types (as necessary). */
9745 for (link = TYPE_ARG_TYPES (function_or_method_type);
9747 link = TREE_CHAIN (link))
9749 formal_type = TREE_VALUE (link);
9750 if (formal_type == void_type_node)
9753 gen_type_die (formal_type, context_die);
9757 /* We want to generate the DIE for TYPE so that we can generate the
9758 die for MEMBER, which has been defined; we will need to refer back
9759 to the member declaration nested within TYPE. If we're trying to
9760 generate minimal debug info for TYPE, processing TYPE won't do the
9761 trick; we need to attach the member declaration by hand. */
9764 gen_type_die_for_member (type, member, context_die)
9766 dw_die_ref context_die;
9768 gen_type_die (type, context_die);
9770 /* If we're trying to avoid duplicate debug info, we may not have
9771 emitted the member decl for this function. Emit it now. */
9772 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9773 && ! lookup_decl_die (member))
9775 if (decl_ultimate_origin (member))
9778 push_decl_scope (type);
9779 if (TREE_CODE (member) == FUNCTION_DECL)
9780 gen_subprogram_die (member, lookup_type_die (type));
9782 gen_variable_die (member, lookup_type_die (type));
9787 /* Generate the DWARF2 info for the "abstract" instance
9788 of a function which we may later generate inlined and/or
9789 out-of-line instances of. */
9792 dwarf2out_abstract_function (decl)
9795 register dw_die_ref old_die;
9798 int was_abstract = DECL_ABSTRACT (decl);
9800 /* Make sure we have the actual abstract inline, not a clone. */
9801 decl = DECL_ORIGIN (decl);
9803 old_die = lookup_decl_die (decl);
9804 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9805 /* We've already generated the abstract instance. */
9808 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9809 we don't get confused by DECL_ABSTRACT. */
9810 if (debug_info_level > DINFO_LEVEL_TERSE)
9812 context = decl_class_context (decl);
9814 gen_type_die_for_member
9815 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9818 /* Pretend we've just finished compiling this function. */
9819 save_fn = current_function_decl;
9820 current_function_decl = decl;
9822 set_decl_abstract_flags (decl, 1);
9823 dwarf2out_decl (decl);
9825 set_decl_abstract_flags (decl, 0);
9827 current_function_decl = save_fn;
9830 /* Generate a DIE to represent a declared function (either file-scope or
9834 gen_subprogram_die (decl, context_die)
9836 register dw_die_ref context_die;
9838 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9839 register tree origin = decl_ultimate_origin (decl);
9840 register dw_die_ref subr_die;
9841 register rtx fp_reg;
9842 register tree fn_arg_types;
9843 register tree outer_scope;
9844 register dw_die_ref old_die = lookup_decl_die (decl);
9845 register int declaration = (current_function_decl != decl
9846 || class_scope_p (context_die));
9848 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9849 be true, if we started to generate the abstract instance of an inline,
9850 decided to output its containing class, and proceeded to emit the
9851 declaration of the inline from the member list for the class. In that
9852 case, `declaration' takes priority; we'll get back to the abstract
9853 instance when we're done with the class. */
9855 /* The class-scope declaration DIE must be the primary DIE. */
9856 if (origin && declaration && class_scope_p (context_die))
9865 if (declaration && ! local_scope_p (context_die))
9868 /* Fixup die_parent for the abstract instance of a nested
9870 if (old_die && old_die->die_parent == NULL)
9871 add_child_die (context_die, old_die);
9873 subr_die = new_die (DW_TAG_subprogram, context_die);
9874 add_abstract_origin_attribute (subr_die, origin);
9878 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9880 if (!get_AT_flag (old_die, DW_AT_declaration)
9881 /* We can have a normal definition following an inline one in the
9882 case of redefinition of GNU C extern inlines.
9883 It seems reasonable to use AT_specification in this case. */
9884 && !get_AT_unsigned (old_die, DW_AT_inline))
9886 /* ??? This can happen if there is a bug in the program, for
9887 instance, if it has duplicate function definitions. Ideally,
9888 we should detect this case and ignore it. For now, if we have
9889 already reported an error, any error at all, then assume that
9890 we got here because of a input error, not a dwarf2 bug. */
9896 /* If the definition comes from the same place as the declaration,
9897 maybe use the old DIE. We always want the DIE for this function
9898 that has the *_pc attributes to be under comp_unit_die so the
9899 debugger can find it. We also need to do this for abstract
9900 instances of inlines, since the spec requires the out-of-line copy
9901 to have the same parent. For local class methods, this doesn't
9902 apply; we just use the old DIE. */
9903 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9904 && (DECL_ARTIFICIAL (decl)
9905 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9906 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9907 == (unsigned) DECL_SOURCE_LINE (decl)))))
9911 /* Clear out the declaration attribute and the parm types. */
9912 remove_AT (subr_die, DW_AT_declaration);
9913 remove_children (subr_die);
9917 subr_die = new_die (DW_TAG_subprogram, context_die);
9918 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9919 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9920 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9921 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9922 != (unsigned) DECL_SOURCE_LINE (decl))
9924 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9929 subr_die = new_die (DW_TAG_subprogram, context_die);
9931 if (TREE_PUBLIC (decl))
9932 add_AT_flag (subr_die, DW_AT_external, 1);
9934 add_name_and_src_coords_attributes (subr_die, decl);
9935 if (debug_info_level > DINFO_LEVEL_TERSE)
9937 register tree type = TREE_TYPE (decl);
9939 add_prototyped_attribute (subr_die, type);
9940 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9943 add_pure_or_virtual_attribute (subr_die, decl);
9944 if (DECL_ARTIFICIAL (decl))
9945 add_AT_flag (subr_die, DW_AT_artificial, 1);
9946 if (TREE_PROTECTED (decl))
9947 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9948 else if (TREE_PRIVATE (decl))
9949 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9954 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9956 add_AT_flag (subr_die, DW_AT_declaration, 1);
9958 /* The first time we see a member function, it is in the context of
9959 the class to which it belongs. We make sure of this by emitting
9960 the class first. The next time is the definition, which is
9961 handled above. The two may come from the same source text. */
9962 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9963 equate_decl_number_to_die (decl, subr_die);
9966 else if (DECL_ABSTRACT (decl))
9968 if (DECL_INLINE (decl) && !flag_no_inline)
9970 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9971 inline functions, but not for extern inline functions.
9972 We can't get this completely correct because information
9973 about whether the function was declared inline is not
9975 if (DECL_DEFER_OUTPUT (decl))
9976 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9978 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9981 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9983 equate_decl_number_to_die (decl, subr_die);
9985 else if (!DECL_EXTERNAL (decl))
9987 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9988 equate_decl_number_to_die (decl, subr_die);
9990 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9991 current_funcdef_number);
9992 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9993 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9994 current_funcdef_number);
9995 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9997 add_pubname (decl, subr_die);
9998 add_arange (decl, subr_die);
10000 #ifdef MIPS_DEBUGGING_INFO
10001 /* Add a reference to the FDE for this routine. */
10002 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10005 /* Define the "frame base" location for this routine. We use the
10006 frame pointer or stack pointer registers, since the RTL for local
10007 variables is relative to one of them. */
10009 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10010 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10013 /* ??? This fails for nested inline functions, because context_display
10014 is not part of the state saved/restored for inline functions. */
10015 if (current_function_needs_context)
10016 add_AT_location_description (subr_die, DW_AT_static_link,
10017 lookup_static_chain (decl));
10021 /* Now output descriptions of the arguments for this function. This gets
10022 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10023 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10024 `...' at the end of the formal parameter list. In order to find out if
10025 there was a trailing ellipsis or not, we must instead look at the type
10026 associated with the FUNCTION_DECL. This will be a node of type
10027 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10028 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10029 an ellipsis at the end. */
10031 /* In the case where we are describing a mere function declaration, all we
10032 need to do here (and all we *can* do here) is to describe the *types* of
10033 its formal parameters. */
10034 if (debug_info_level <= DINFO_LEVEL_TERSE)
10036 else if (declaration)
10037 gen_formal_types_die (decl, subr_die);
10040 /* Generate DIEs to represent all known formal parameters */
10041 register tree arg_decls = DECL_ARGUMENTS (decl);
10042 register tree parm;
10044 /* When generating DIEs, generate the unspecified_parameters DIE
10045 instead if we come across the arg "__builtin_va_alist" */
10046 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10047 if (TREE_CODE (parm) == PARM_DECL)
10049 if (DECL_NAME (parm)
10050 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10051 "__builtin_va_alist"))
10052 gen_unspecified_parameters_die (parm, subr_die);
10054 gen_decl_die (parm, subr_die);
10057 /* Decide whether we need a unspecified_parameters DIE at the end.
10058 There are 2 more cases to do this for: 1) the ansi ... declaration -
10059 this is detectable when the end of the arg list is not a
10060 void_type_node 2) an unprototyped function declaration (not a
10061 definition). This just means that we have no info about the
10062 parameters at all. */
10063 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10064 if (fn_arg_types != NULL)
10066 /* this is the prototyped case, check for ... */
10067 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10068 gen_unspecified_parameters_die (decl, subr_die);
10070 else if (DECL_INITIAL (decl) == NULL_TREE)
10071 gen_unspecified_parameters_die (decl, subr_die);
10074 /* Output Dwarf info for all of the stuff within the body of the function
10075 (if it has one - it may be just a declaration). */
10076 outer_scope = DECL_INITIAL (decl);
10078 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10079 node created to represent a function. This outermost BLOCK actually
10080 represents the outermost binding contour for the function, i.e. the
10081 contour in which the function's formal parameters and labels get
10082 declared. Curiously, it appears that the front end doesn't actually
10083 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10084 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10085 list for the function instead.) The BLOCK_VARS list for the
10086 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10087 the function however, and we output DWARF info for those in
10088 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10089 node representing the function's outermost pair of curly braces, and
10090 any blocks used for the base and member initializers of a C++
10091 constructor function. */
10092 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10094 current_function_has_inlines = 0;
10095 decls_for_scope (outer_scope, subr_die, 0);
10097 #if 0 && defined (MIPS_DEBUGGING_INFO)
10098 if (current_function_has_inlines)
10100 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10101 if (! comp_unit_has_inlines)
10103 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10104 comp_unit_has_inlines = 1;
10111 /* Generate a DIE to represent a declared data object. */
10114 gen_variable_die (decl, context_die)
10115 register tree decl;
10116 register dw_die_ref context_die;
10118 register tree origin = decl_ultimate_origin (decl);
10119 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10121 dw_die_ref old_die = lookup_decl_die (decl);
10122 int declaration = (DECL_EXTERNAL (decl)
10123 || class_scope_p (context_die));
10125 if (origin != NULL)
10126 add_abstract_origin_attribute (var_die, origin);
10127 /* Loop unrolling can create multiple blocks that refer to the same
10128 static variable, so we must test for the DW_AT_declaration flag. */
10129 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10130 copy decls and set the DECL_ABSTRACT flag on them instead of
10132 /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10133 else if (old_die && TREE_STATIC (decl)
10134 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10136 /* This is a definition of a C++ class level static. */
10137 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10138 if (DECL_NAME (decl))
10140 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10142 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10143 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10145 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10146 != (unsigned) DECL_SOURCE_LINE (decl))
10148 add_AT_unsigned (var_die, DW_AT_decl_line,
10149 DECL_SOURCE_LINE (decl));
10154 add_name_and_src_coords_attributes (var_die, decl);
10155 add_type_attribute (var_die, TREE_TYPE (decl),
10156 TREE_READONLY (decl),
10157 TREE_THIS_VOLATILE (decl), context_die);
10159 if (TREE_PUBLIC (decl))
10160 add_AT_flag (var_die, DW_AT_external, 1);
10162 if (DECL_ARTIFICIAL (decl))
10163 add_AT_flag (var_die, DW_AT_artificial, 1);
10165 if (TREE_PROTECTED (decl))
10166 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10168 else if (TREE_PRIVATE (decl))
10169 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10173 add_AT_flag (var_die, DW_AT_declaration, 1);
10175 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10176 equate_decl_number_to_die (decl, var_die);
10178 if (! declaration && ! DECL_ABSTRACT (decl))
10180 add_location_or_const_value_attribute (var_die, decl);
10181 add_pubname (decl, var_die);
10184 tree_add_const_value_attribute (var_die, decl);
10187 /* Generate a DIE to represent a label identifier. */
10190 gen_label_die (decl, context_die)
10191 register tree decl;
10192 register dw_die_ref context_die;
10194 register tree origin = decl_ultimate_origin (decl);
10195 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10197 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10199 if (origin != NULL)
10200 add_abstract_origin_attribute (lbl_die, origin);
10202 add_name_and_src_coords_attributes (lbl_die, decl);
10204 if (DECL_ABSTRACT (decl))
10205 equate_decl_number_to_die (decl, lbl_die);
10208 insn = DECL_RTL (decl);
10210 /* Deleted labels are programmer specified labels which have been
10211 eliminated because of various optimisations. We still emit them
10212 here so that it is possible to put breakpoints on them. */
10213 if (GET_CODE (insn) == CODE_LABEL
10214 || ((GET_CODE (insn) == NOTE
10215 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10217 /* When optimization is enabled (via -O) some parts of the compiler
10218 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10219 represent source-level labels which were explicitly declared by
10220 the user. This really shouldn't be happening though, so catch
10221 it if it ever does happen. */
10222 if (INSN_DELETED_P (insn))
10225 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10226 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10231 /* Generate a DIE for a lexical block. */
10234 gen_lexical_block_die (stmt, context_die, depth)
10235 register tree stmt;
10236 register dw_die_ref context_die;
10239 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10240 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10242 if (! BLOCK_ABSTRACT (stmt))
10244 if (BLOCK_FRAGMENT_CHAIN (stmt))
10248 add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
10250 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10253 add_ranges (chain);
10254 chain = BLOCK_FRAGMENT_CHAIN (chain);
10261 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10262 BLOCK_NUMBER (stmt));
10263 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10264 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10265 BLOCK_NUMBER (stmt));
10266 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10270 decls_for_scope (stmt, stmt_die, depth);
10273 /* Generate a DIE for an inlined subprogram. */
10276 gen_inlined_subroutine_die (stmt, context_die, depth)
10277 register tree stmt;
10278 register dw_die_ref context_die;
10281 if (! BLOCK_ABSTRACT (stmt))
10283 register dw_die_ref subr_die
10284 = new_die (DW_TAG_inlined_subroutine, context_die);
10285 register tree decl = block_ultimate_origin (stmt);
10286 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10288 /* Emit info for the abstract instance first, if we haven't yet. */
10289 dwarf2out_abstract_function (decl);
10291 add_abstract_origin_attribute (subr_die, decl);
10292 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10293 BLOCK_NUMBER (stmt));
10294 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10295 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10296 BLOCK_NUMBER (stmt));
10297 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10298 decls_for_scope (stmt, subr_die, depth);
10299 current_function_has_inlines = 1;
10303 /* Generate a DIE for a field in a record, or structure. */
10306 gen_field_die (decl, context_die)
10307 register tree decl;
10308 register dw_die_ref context_die;
10310 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10312 add_name_and_src_coords_attributes (decl_die, decl);
10313 add_type_attribute (decl_die, member_declared_type (decl),
10314 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10317 /* If this is a bit field... */
10318 if (DECL_BIT_FIELD_TYPE (decl))
10320 add_byte_size_attribute (decl_die, decl);
10321 add_bit_size_attribute (decl_die, decl);
10322 add_bit_offset_attribute (decl_die, decl);
10325 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10326 add_data_member_location_attribute (decl_die, decl);
10328 if (DECL_ARTIFICIAL (decl))
10329 add_AT_flag (decl_die, DW_AT_artificial, 1);
10331 if (TREE_PROTECTED (decl))
10332 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10334 else if (TREE_PRIVATE (decl))
10335 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10339 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10340 Use modified_type_die instead.
10341 We keep this code here just in case these types of DIEs may be needed to
10342 represent certain things in other languages (e.g. Pascal) someday. */
10344 gen_pointer_type_die (type, context_die)
10345 register tree type;
10346 register dw_die_ref context_die;
10348 register dw_die_ref ptr_die
10349 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10351 equate_type_number_to_die (type, ptr_die);
10352 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10353 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10356 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10357 Use modified_type_die instead.
10358 We keep this code here just in case these types of DIEs may be needed to
10359 represent certain things in other languages (e.g. Pascal) someday. */
10361 gen_reference_type_die (type, context_die)
10362 register tree type;
10363 register dw_die_ref context_die;
10365 register dw_die_ref ref_die
10366 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10368 equate_type_number_to_die (type, ref_die);
10369 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10370 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10374 /* Generate a DIE for a pointer to a member type. */
10376 gen_ptr_to_mbr_type_die (type, context_die)
10377 register tree type;
10378 register dw_die_ref context_die;
10380 register dw_die_ref ptr_die
10381 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10383 equate_type_number_to_die (type, ptr_die);
10384 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10385 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10386 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10389 /* Generate the DIE for the compilation unit. */
10392 gen_compile_unit_die (filename)
10393 register const char *filename;
10395 register dw_die_ref die;
10396 char producer[250];
10397 const char *wd = getpwd ();
10400 die = new_die (DW_TAG_compile_unit, NULL);
10401 add_name_attribute (die, filename);
10403 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10404 add_AT_string (die, DW_AT_comp_dir, wd);
10406 sprintf (producer, "%s %s", language_string, version_string);
10408 #ifdef MIPS_DEBUGGING_INFO
10409 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10410 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10411 not appear in the producer string, the debugger reaches the conclusion
10412 that the object file is stripped and has no debugging information.
10413 To get the MIPS/SGI debugger to believe that there is debugging
10414 information in the object file, we add a -g to the producer string. */
10415 if (debug_info_level > DINFO_LEVEL_TERSE)
10416 strcat (producer, " -g");
10419 add_AT_string (die, DW_AT_producer, producer);
10421 if (strcmp (language_string, "GNU C++") == 0)
10422 language = DW_LANG_C_plus_plus;
10423 else if (strcmp (language_string, "GNU Ada") == 0)
10424 language = DW_LANG_Ada83;
10425 else if (strcmp (language_string, "GNU F77") == 0)
10426 language = DW_LANG_Fortran77;
10427 else if (strcmp (language_string, "GNU Pascal") == 0)
10428 language = DW_LANG_Pascal83;
10429 else if (strcmp (language_string, "GNU Java") == 0)
10430 language = DW_LANG_Java;
10431 else if (flag_traditional)
10432 language = DW_LANG_C;
10434 language = DW_LANG_C89;
10436 add_AT_unsigned (die, DW_AT_language, language);
10441 /* Generate a DIE for a string type. */
10444 gen_string_type_die (type, context_die)
10445 register tree type;
10446 register dw_die_ref context_die;
10448 register dw_die_ref type_die
10449 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10451 equate_type_number_to_die (type, type_die);
10453 /* Fudge the string length attribute for now. */
10455 /* TODO: add string length info.
10456 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10457 bound_representation (upper_bound, 0, 'u'); */
10460 /* Generate the DIE for a base class. */
10463 gen_inheritance_die (binfo, context_die)
10464 register tree binfo;
10465 register dw_die_ref context_die;
10467 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10469 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10470 add_data_member_location_attribute (die, binfo);
10472 if (TREE_VIA_VIRTUAL (binfo))
10473 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10474 if (TREE_VIA_PUBLIC (binfo))
10475 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10476 else if (TREE_VIA_PROTECTED (binfo))
10477 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10480 /* Generate a DIE for a class member. */
10483 gen_member_die (type, context_die)
10484 register tree type;
10485 register dw_die_ref context_die;
10487 register tree member;
10490 /* If this is not an incomplete type, output descriptions of each of its
10491 members. Note that as we output the DIEs necessary to represent the
10492 members of this record or union type, we will also be trying to output
10493 DIEs to represent the *types* of those members. However the `type'
10494 function (above) will specifically avoid generating type DIEs for member
10495 types *within* the list of member DIEs for this (containing) type execpt
10496 for those types (of members) which are explicitly marked as also being
10497 members of this (containing) type themselves. The g++ front- end can
10498 force any given type to be treated as a member of some other
10499 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10500 to point to the TREE node representing the appropriate (containing)
10503 /* First output info about the base classes. */
10504 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10506 register tree bases = TYPE_BINFO_BASETYPES (type);
10507 register int n_bases = TREE_VEC_LENGTH (bases);
10510 for (i = 0; i < n_bases; i++)
10511 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10514 /* Now output info about the data members and type members. */
10515 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10517 /* If we thought we were generating minimal debug info for TYPE
10518 and then changed our minds, some of the member declarations
10519 may have already been defined. Don't define them again, but
10520 do put them in the right order. */
10522 child = lookup_decl_die (member);
10524 splice_child_die (context_die, child);
10526 gen_decl_die (member, context_die);
10529 /* Now output info about the function members (if any). */
10530 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10532 /* Don't include clones in the member list. */
10533 if (DECL_ABSTRACT_ORIGIN (member))
10536 child = lookup_decl_die (member);
10538 splice_child_die (context_die, child);
10540 gen_decl_die (member, context_die);
10544 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10545 is set, we pretend that the type was never defined, so we only get the
10546 member DIEs needed by later specification DIEs. */
10549 gen_struct_or_union_type_die (type, context_die)
10550 register tree type;
10551 register dw_die_ref context_die;
10553 register dw_die_ref type_die = lookup_type_die (type);
10554 register dw_die_ref scope_die = 0;
10555 register int nested = 0;
10556 int complete = (TYPE_SIZE (type)
10557 && (! TYPE_STUB_DECL (type)
10558 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10560 if (type_die && ! complete)
10563 if (TYPE_CONTEXT (type) != NULL_TREE
10564 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10567 scope_die = scope_die_for (type, context_die);
10569 if (! type_die || (nested && scope_die == comp_unit_die))
10570 /* First occurrence of type or toplevel definition of nested class. */
10572 register dw_die_ref old_die = type_die;
10574 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10575 ? DW_TAG_structure_type : DW_TAG_union_type,
10577 equate_type_number_to_die (type, type_die);
10579 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10581 add_name_attribute (type_die, type_tag (type));
10584 remove_AT (type_die, DW_AT_declaration);
10586 /* If this type has been completed, then give it a byte_size attribute and
10587 then give a list of members. */
10590 /* Prevent infinite recursion in cases where the type of some member of
10591 this type is expressed in terms of this type itself. */
10592 TREE_ASM_WRITTEN (type) = 1;
10593 add_byte_size_attribute (type_die, type);
10594 if (TYPE_STUB_DECL (type) != NULL_TREE)
10595 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10597 /* If the first reference to this type was as the return type of an
10598 inline function, then it may not have a parent. Fix this now. */
10599 if (type_die->die_parent == NULL)
10600 add_child_die (scope_die, type_die);
10602 push_decl_scope (type);
10603 gen_member_die (type, type_die);
10606 /* GNU extension: Record what type our vtable lives in. */
10607 if (TYPE_VFIELD (type))
10609 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10611 gen_type_die (vtype, context_die);
10612 add_AT_die_ref (type_die, DW_AT_containing_type,
10613 lookup_type_die (vtype));
10618 add_AT_flag (type_die, DW_AT_declaration, 1);
10620 /* We don't need to do this for function-local types. */
10621 if (! decl_function_context (TYPE_STUB_DECL (type)))
10622 add_incomplete_type (type);
10626 /* Generate a DIE for a subroutine _type_. */
10629 gen_subroutine_type_die (type, context_die)
10630 register tree type;
10631 register dw_die_ref context_die;
10633 register tree return_type = TREE_TYPE (type);
10634 register dw_die_ref subr_die
10635 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10637 equate_type_number_to_die (type, subr_die);
10638 add_prototyped_attribute (subr_die, type);
10639 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10640 gen_formal_types_die (type, subr_die);
10643 /* Generate a DIE for a type definition */
10646 gen_typedef_die (decl, context_die)
10647 register tree decl;
10648 register dw_die_ref context_die;
10650 register dw_die_ref type_die;
10651 register tree origin;
10653 if (TREE_ASM_WRITTEN (decl))
10655 TREE_ASM_WRITTEN (decl) = 1;
10657 type_die = new_die (DW_TAG_typedef, context_die);
10658 origin = decl_ultimate_origin (decl);
10659 if (origin != NULL)
10660 add_abstract_origin_attribute (type_die, origin);
10663 register tree type;
10664 add_name_and_src_coords_attributes (type_die, decl);
10665 if (DECL_ORIGINAL_TYPE (decl))
10667 type = DECL_ORIGINAL_TYPE (decl);
10669 if (type == TREE_TYPE (decl))
10672 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10675 type = TREE_TYPE (decl);
10676 add_type_attribute (type_die, type, TREE_READONLY (decl),
10677 TREE_THIS_VOLATILE (decl), context_die);
10680 if (DECL_ABSTRACT (decl))
10681 equate_decl_number_to_die (decl, type_die);
10684 /* Generate a type description DIE. */
10687 gen_type_die (type, context_die)
10688 register tree type;
10689 register dw_die_ref context_die;
10693 if (type == NULL_TREE || type == error_mark_node)
10696 /* We are going to output a DIE to represent the unqualified version of
10697 this type (i.e. without any const or volatile qualifiers) so get the
10698 main variant (i.e. the unqualified version) of this type now. */
10699 type = type_main_variant (type);
10701 if (TREE_ASM_WRITTEN (type))
10704 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10705 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10707 TREE_ASM_WRITTEN (type) = 1;
10708 gen_decl_die (TYPE_NAME (type), context_die);
10712 switch (TREE_CODE (type))
10718 case REFERENCE_TYPE:
10719 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10720 ensures that the gen_type_die recursion will terminate even if the
10721 type is recursive. Recursive types are possible in Ada. */
10722 /* ??? We could perhaps do this for all types before the switch
10724 TREE_ASM_WRITTEN (type) = 1;
10726 /* For these types, all that is required is that we output a DIE (or a
10727 set of DIEs) to represent the "basis" type. */
10728 gen_type_die (TREE_TYPE (type), context_die);
10732 /* This code is used for C++ pointer-to-data-member types.
10733 Output a description of the relevant class type. */
10734 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10736 /* Output a description of the type of the object pointed to. */
10737 gen_type_die (TREE_TYPE (type), context_die);
10739 /* Now output a DIE to represent this pointer-to-data-member type
10741 gen_ptr_to_mbr_type_die (type, context_die);
10745 gen_type_die (TYPE_DOMAIN (type), context_die);
10746 gen_set_type_die (type, context_die);
10750 gen_type_die (TREE_TYPE (type), context_die);
10751 abort (); /* No way to represent these in Dwarf yet! */
10754 case FUNCTION_TYPE:
10755 /* Force out return type (in case it wasn't forced out already). */
10756 gen_type_die (TREE_TYPE (type), context_die);
10757 gen_subroutine_type_die (type, context_die);
10761 /* Force out return type (in case it wasn't forced out already). */
10762 gen_type_die (TREE_TYPE (type), context_die);
10763 gen_subroutine_type_die (type, context_die);
10767 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10769 gen_type_die (TREE_TYPE (type), context_die);
10770 gen_string_type_die (type, context_die);
10773 gen_array_type_die (type, context_die);
10777 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10780 case ENUMERAL_TYPE:
10783 case QUAL_UNION_TYPE:
10784 /* If this is a nested type whose containing class hasn't been
10785 written out yet, writing it out will cover this one, too.
10786 This does not apply to instantiations of member class templates;
10787 they need to be added to the containing class as they are
10788 generated. FIXME: This hurts the idea of combining type decls
10789 from multiple TUs, since we can't predict what set of template
10790 instantiations we'll get. */
10791 if (TYPE_CONTEXT (type)
10792 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10793 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10795 gen_type_die (TYPE_CONTEXT (type), context_die);
10797 if (TREE_ASM_WRITTEN (type))
10800 /* If that failed, attach ourselves to the stub. */
10801 push_decl_scope (TYPE_CONTEXT (type));
10802 context_die = lookup_type_die (TYPE_CONTEXT (type));
10808 if (TREE_CODE (type) == ENUMERAL_TYPE)
10809 gen_enumeration_type_die (type, context_die);
10811 gen_struct_or_union_type_die (type, context_die);
10816 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10817 it up if it is ever completed. gen_*_type_die will set it for us
10818 when appropriate. */
10827 /* No DIEs needed for fundamental types. */
10831 /* No Dwarf representation currently defined. */
10838 TREE_ASM_WRITTEN (type) = 1;
10841 /* Generate a DIE for a tagged type instantiation. */
10844 gen_tagged_type_instantiation_die (type, context_die)
10845 register tree type;
10846 register dw_die_ref context_die;
10848 if (type == NULL_TREE || type == error_mark_node)
10851 /* We are going to output a DIE to represent the unqualified version of
10852 this type (i.e. without any const or volatile qualifiers) so make sure
10853 that we have the main variant (i.e. the unqualified version) of this
10855 if (type != type_main_variant (type))
10858 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10859 an instance of an unresolved type. */
10861 switch (TREE_CODE (type))
10866 case ENUMERAL_TYPE:
10867 gen_inlined_enumeration_type_die (type, context_die);
10871 gen_inlined_structure_type_die (type, context_die);
10875 case QUAL_UNION_TYPE:
10876 gen_inlined_union_type_die (type, context_die);
10884 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10885 things which are local to the given block. */
10888 gen_block_die (stmt, context_die, depth)
10889 register tree stmt;
10890 register dw_die_ref context_die;
10893 register int must_output_die = 0;
10894 register tree origin;
10895 register tree decl;
10896 register enum tree_code origin_code;
10898 /* Ignore blocks never really used to make RTL. */
10899 if (stmt == NULL_TREE || !TREE_USED (stmt)
10900 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10903 /* If the block is one fragment of a non-contiguous block, do not
10904 process the variables, since they will have been done by the
10905 origin block. Do process subblocks. */
10906 if (BLOCK_FRAGMENT_ORIGIN (stmt))
10910 for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
10911 gen_block_die (sub, context_die, depth + 1);
10915 /* Determine the "ultimate origin" of this block. This block may be an
10916 inlined instance of an inlined instance of inline function, so we have
10917 to trace all of the way back through the origin chain to find out what
10918 sort of node actually served as the original seed for the creation of
10919 the current block. */
10920 origin = block_ultimate_origin (stmt);
10921 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10923 /* Determine if we need to output any Dwarf DIEs at all to represent this
10925 if (origin_code == FUNCTION_DECL)
10926 /* The outer scopes for inlinings *must* always be represented. We
10927 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10928 must_output_die = 1;
10931 /* In the case where the current block represents an inlining of the
10932 "body block" of an inline function, we must *NOT* output any DIE for
10933 this block because we have already output a DIE to represent the
10934 whole inlined function scope and the "body block" of any function
10935 doesn't really represent a different scope according to ANSI C
10936 rules. So we check here to make sure that this block does not
10937 represent a "body block inlining" before trying to set the
10938 `must_output_die' flag. */
10939 if (! is_body_block (origin ? origin : stmt))
10941 /* Determine if this block directly contains any "significant"
10942 local declarations which we will need to output DIEs for. */
10943 if (debug_info_level > DINFO_LEVEL_TERSE)
10944 /* We are not in terse mode so *any* local declaration counts
10945 as being a "significant" one. */
10946 must_output_die = (BLOCK_VARS (stmt) != NULL);
10948 /* We are in terse mode, so only local (nested) function
10949 definitions count as "significant" local declarations. */
10950 for (decl = BLOCK_VARS (stmt);
10951 decl != NULL; decl = TREE_CHAIN (decl))
10952 if (TREE_CODE (decl) == FUNCTION_DECL
10953 && DECL_INITIAL (decl))
10955 must_output_die = 1;
10961 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10962 DIE for any block which contains no significant local declarations at
10963 all. Rather, in such cases we just call `decls_for_scope' so that any
10964 needed Dwarf info for any sub-blocks will get properly generated. Note
10965 that in terse mode, our definition of what constitutes a "significant"
10966 local declaration gets restricted to include only inlined function
10967 instances and local (nested) function definitions. */
10968 if (must_output_die)
10970 if (origin_code == FUNCTION_DECL)
10971 gen_inlined_subroutine_die (stmt, context_die, depth);
10973 gen_lexical_block_die (stmt, context_die, depth);
10976 decls_for_scope (stmt, context_die, depth);
10979 /* Generate all of the decls declared within a given scope and (recursively)
10980 all of its sub-blocks. */
10983 decls_for_scope (stmt, context_die, depth)
10984 register tree stmt;
10985 register dw_die_ref context_die;
10988 register tree decl;
10989 register tree subblocks;
10991 /* Ignore blocks never really used to make RTL. */
10992 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10995 /* Output the DIEs to represent all of the data objects and typedefs
10996 declared directly within this block but not within any nested
10997 sub-blocks. Also, nested function and tag DIEs have been
10998 generated with a parent of NULL; fix that up now. */
10999 for (decl = BLOCK_VARS (stmt);
11000 decl != NULL; decl = TREE_CHAIN (decl))
11002 register dw_die_ref die;
11004 if (TREE_CODE (decl) == FUNCTION_DECL)
11005 die = lookup_decl_die (decl);
11006 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11007 die = lookup_type_die (TREE_TYPE (decl));
11011 if (die != NULL && die->die_parent == NULL)
11012 add_child_die (context_die, die);
11014 gen_decl_die (decl, context_die);
11017 /* Output the DIEs to represent all sub-blocks (and the items declared
11018 therein) of this block. */
11019 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11021 subblocks = BLOCK_CHAIN (subblocks))
11022 gen_block_die (subblocks, context_die, depth + 1);
11025 /* Is this a typedef we can avoid emitting? */
11028 is_redundant_typedef (decl)
11029 register tree decl;
11031 if (TYPE_DECL_IS_STUB (decl))
11034 if (DECL_ARTIFICIAL (decl)
11035 && DECL_CONTEXT (decl)
11036 && is_tagged_type (DECL_CONTEXT (decl))
11037 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11038 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11039 /* Also ignore the artificial member typedef for the class name. */
11045 /* Generate Dwarf debug information for a decl described by DECL. */
11048 gen_decl_die (decl, context_die)
11049 register tree decl;
11050 register dw_die_ref context_die;
11052 register tree origin;
11054 if (TREE_CODE (decl) == ERROR_MARK)
11057 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11058 if (DECL_IGNORED_P (decl))
11061 switch (TREE_CODE (decl))
11064 /* The individual enumerators of an enum type get output when we output
11065 the Dwarf representation of the relevant enum type itself. */
11068 case FUNCTION_DECL:
11069 /* Don't output any DIEs to represent mere function declarations,
11070 unless they are class members or explicit block externs. */
11071 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11072 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11075 /* If we're emitting a clone, emit info for the abstract instance. */
11076 if (DECL_ORIGIN (decl) != decl)
11077 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11078 /* If we're emitting an out-of-line copy of an inline function,
11079 emit info for the abstract instance and set up to refer to it. */
11080 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11081 && ! class_scope_p (context_die)
11082 /* dwarf2out_abstract_function won't emit a die if this is just
11083 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11084 that case, because that works only if we have a die. */
11085 && DECL_INITIAL (decl) != NULL_TREE)
11087 dwarf2out_abstract_function (decl);
11088 set_decl_origin_self (decl);
11090 /* Otherwise we're emitting the primary DIE for this decl. */
11091 else if (debug_info_level > DINFO_LEVEL_TERSE)
11093 /* Before we describe the FUNCTION_DECL itself, make sure that we
11094 have described its return type. */
11095 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11097 /* And its virtual context. */
11098 if (DECL_VINDEX (decl) != NULL_TREE)
11099 gen_type_die (DECL_CONTEXT (decl), context_die);
11101 /* And its containing type. */
11102 origin = decl_class_context (decl);
11103 if (origin != NULL_TREE)
11104 gen_type_die_for_member (origin, decl, context_die);
11107 /* Now output a DIE to represent the function itself. */
11108 gen_subprogram_die (decl, context_die);
11112 /* If we are in terse mode, don't generate any DIEs to represent any
11113 actual typedefs. */
11114 if (debug_info_level <= DINFO_LEVEL_TERSE)
11117 /* In the special case of a TYPE_DECL node representing the
11118 declaration of some type tag, if the given TYPE_DECL is marked as
11119 having been instantiated from some other (original) TYPE_DECL node
11120 (e.g. one which was generated within the original definition of an
11121 inline function) we have to generate a special (abbreviated)
11122 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11124 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11126 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11130 if (is_redundant_typedef (decl))
11131 gen_type_die (TREE_TYPE (decl), context_die);
11133 /* Output a DIE to represent the typedef itself. */
11134 gen_typedef_die (decl, context_die);
11138 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11139 gen_label_die (decl, context_die);
11143 /* If we are in terse mode, don't generate any DIEs to represent any
11144 variable declarations or definitions. */
11145 if (debug_info_level <= DINFO_LEVEL_TERSE)
11148 /* Output any DIEs that are needed to specify the type of this data
11150 gen_type_die (TREE_TYPE (decl), context_die);
11152 /* And its containing type. */
11153 origin = decl_class_context (decl);
11154 if (origin != NULL_TREE)
11155 gen_type_die_for_member (origin, decl, context_die);
11157 /* Now output the DIE to represent the data object itself. This gets
11158 complicated because of the possibility that the VAR_DECL really
11159 represents an inlined instance of a formal parameter for an inline
11161 origin = decl_ultimate_origin (decl);
11162 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11163 gen_formal_parameter_die (decl, context_die);
11165 gen_variable_die (decl, context_die);
11169 /* Ignore the nameless fields that are used to skip bits, but
11170 handle C++ anonymous unions. */
11171 if (DECL_NAME (decl) != NULL_TREE
11172 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11174 gen_type_die (member_declared_type (decl), context_die);
11175 gen_field_die (decl, context_die);
11180 gen_type_die (TREE_TYPE (decl), context_die);
11181 gen_formal_parameter_die (decl, context_die);
11184 case NAMESPACE_DECL:
11185 /* Ignore for now. */
11193 /* Add Ada "use" clause information for SGI Workshop debugger. */
11196 dwarf2out_add_library_unit_info (filename, context_list)
11197 const char *filename;
11198 const char *context_list;
11200 unsigned int file_index;
11202 if (filename != NULL)
11204 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11205 tree context_list_decl
11206 = build_decl (LABEL_DECL, get_identifier (context_list),
11209 TREE_PUBLIC (context_list_decl) = TRUE;
11210 add_name_attribute (unit_die, context_list);
11211 file_index = lookup_filename (filename);
11212 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11213 add_pubname (context_list_decl, unit_die);
11217 /* Debug information for a global DECL. Called from toplev.c after
11218 compilation proper has finished. */
11220 dwarf2out_global_decl (decl)
11223 /* Output DWARF2 information for file-scope tentative data object
11224 declarations, file-scope (extern) function declarations (which
11225 had no corresponding body) and file-scope tagged type
11226 declarations and definitions which have not yet been forced out. */
11228 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11229 dwarf2out_decl (decl);
11232 /* Write the debugging output for DECL. */
11235 dwarf2out_decl (decl)
11236 register tree decl;
11238 register dw_die_ref context_die = comp_unit_die;
11240 if (TREE_CODE (decl) == ERROR_MARK)
11243 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11244 if (DECL_IGNORED_P (decl))
11247 switch (TREE_CODE (decl))
11249 case FUNCTION_DECL:
11250 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11251 builtin function. Explicit programmer-supplied declarations of
11252 these same functions should NOT be ignored however. */
11253 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11256 /* What we would really like to do here is to filter out all mere
11257 file-scope declarations of file-scope functions which are never
11258 referenced later within this translation unit (and keep all of ones
11259 that *are* referenced later on) but we aren't clairvoyant, so we have
11260 no idea which functions will be referenced in the future (i.e. later
11261 on within the current translation unit). So here we just ignore all
11262 file-scope function declarations which are not also definitions. If
11263 and when the debugger needs to know something about these functions,
11264 it will have to hunt around and find the DWARF information associated
11265 with the definition of the function. Note that we can't just check
11266 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11267 definitions and which ones represent mere declarations. We have to
11268 check `DECL_INITIAL' instead. That's because the C front-end
11269 supports some weird semantics for "extern inline" function
11270 definitions. These can get inlined within the current translation
11271 unit (an thus, we need to generate DWARF info for their abstract
11272 instances so that the DWARF info for the concrete inlined instances
11273 can have something to refer to) but the compiler never generates any
11274 out-of-lines instances of such things (despite the fact that they
11275 *are* definitions). The important point is that the C front-end
11276 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11277 to generate DWARF for them anyway. Note that the C++ front-end also
11278 plays some similar games for inline function definitions appearing
11279 within include files which also contain
11280 `#pragma interface' pragmas. */
11281 if (DECL_INITIAL (decl) == NULL_TREE)
11284 /* If we're a nested function, initially use a parent of NULL; if we're
11285 a plain function, this will be fixed up in decls_for_scope. If
11286 we're a method, it will be ignored, since we already have a DIE. */
11287 if (decl_function_context (decl))
11288 context_die = NULL;
11293 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11294 declaration and if the declaration was never even referenced from
11295 within this entire compilation unit. We suppress these DIEs in
11296 order to save space in the .debug section (by eliminating entries
11297 which are probably useless). Note that we must not suppress
11298 block-local extern declarations (whether used or not) because that
11299 would screw-up the debugger's name lookup mechanism and cause it to
11300 miss things which really ought to be in scope at a given point. */
11301 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11304 /* If we are in terse mode, don't generate any DIEs to represent any
11305 variable declarations or definitions. */
11306 if (debug_info_level <= DINFO_LEVEL_TERSE)
11311 /* Don't emit stubs for types unless they are needed by other DIEs. */
11312 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11315 /* Don't bother trying to generate any DIEs to represent any of the
11316 normal built-in types for the language we are compiling. */
11317 if (DECL_SOURCE_LINE (decl) == 0)
11319 /* OK, we need to generate one for `bool' so GDB knows what type
11320 comparisons have. */
11321 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11322 == DW_LANG_C_plus_plus)
11323 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11324 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11329 /* If we are in terse mode, don't generate any DIEs for types. */
11330 if (debug_info_level <= DINFO_LEVEL_TERSE)
11333 /* If we're a function-scope tag, initially use a parent of NULL;
11334 this will be fixed up in decls_for_scope. */
11335 if (decl_function_context (decl))
11336 context_die = NULL;
11344 gen_decl_die (decl, context_die);
11347 /* Output a marker (i.e. a label) for the beginning of the generated code for
11348 a lexical block. */
11351 dwarf2out_begin_block (line, blocknum)
11352 unsigned int line ATTRIBUTE_UNUSED;
11353 unsigned int blocknum;
11355 function_section (current_function_decl);
11356 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11359 /* Output a marker (i.e. a label) for the end of the generated code for a
11363 dwarf2out_end_block (line, blocknum)
11364 unsigned int line ATTRIBUTE_UNUSED;
11365 unsigned int blocknum;
11367 function_section (current_function_decl);
11368 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11371 /* Returns nonzero if it is appropriate not to emit any debugging
11372 information for BLOCK, because it doesn't contain any instructions.
11374 Don't allow this for blocks with nested functions or local classes
11375 as we would end up with orphans, and in the presence of scheduling
11376 we may end up calling them anyway. */
11379 dwarf2out_ignore_block (block)
11383 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11384 if (TREE_CODE (decl) == FUNCTION_DECL
11385 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11390 /* Lookup a filename (in the list of filenames that we know about here in
11391 dwarf2out.c) and return its "index". The index of each (known) filename is
11392 just a unique number which is associated with only that one filename.
11393 We need such numbers for the sake of generating labels
11394 (in the .debug_sfnames section) and references to those
11395 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11396 If the filename given as an argument is not found in our current list,
11397 add it to the list and assign it the next available unique index number.
11398 In order to speed up searches, we remember the index of the filename
11399 was looked up last. This handles the majority of all searches. */
11402 lookup_filename (file_name)
11403 const char *file_name;
11405 register unsigned i;
11407 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11408 if (strcmp (file_name, "<internal>") == 0
11409 || strcmp (file_name, "<built-in>") == 0)
11412 /* Check to see if the file name that was searched on the previous
11413 call matches this file name. If so, return the index. */
11414 if (file_table.last_lookup_index != 0)
11415 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11416 return file_table.last_lookup_index;
11418 /* Didn't match the previous lookup, search the table */
11419 for (i = 1; i < file_table.in_use; ++i)
11420 if (strcmp (file_name, file_table.table[i]) == 0)
11422 file_table.last_lookup_index = i;
11426 /* Prepare to add a new table entry by making sure there is enough space in
11427 the table to do so. If not, expand the current table. */
11428 if (i == file_table.allocated)
11430 file_table.allocated = i + FILE_TABLE_INCREMENT;
11431 file_table.table = (char **)
11432 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11435 /* Add the new entry to the end of the filename table. */
11436 file_table.table[i] = xstrdup (file_name);
11437 file_table.in_use = i + 1;
11438 file_table.last_lookup_index = i;
11440 if (DWARF2_ASM_LINE_DEBUG_INFO)
11441 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11449 /* Allocate the initial hunk of the file_table. */
11450 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11451 file_table.allocated = FILE_TABLE_INCREMENT;
11453 /* Skip the first entry - file numbers begin at 1. */
11454 file_table.in_use = 1;
11455 file_table.last_lookup_index = 0;
11458 /* Output a label to mark the beginning of a source code line entry
11459 and record information relating to this source line, in
11460 'line_info_table' for later output of the .debug_line section. */
11463 dwarf2out_source_line (line, filename)
11465 register const char *filename;
11467 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11469 function_section (current_function_decl);
11471 /* If requested, emit something human-readable. */
11472 if (flag_debug_asm)
11473 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11476 if (DWARF2_ASM_LINE_DEBUG_INFO)
11478 unsigned file_num = lookup_filename (filename);
11480 /* Emit the .loc directive understood by GNU as. */
11481 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11483 /* Indicate that line number info exists. */
11484 ++line_info_table_in_use;
11486 /* Indicate that multiple line number tables exist. */
11487 if (DECL_SECTION_NAME (current_function_decl))
11488 ++separate_line_info_table_in_use;
11490 else if (DECL_SECTION_NAME (current_function_decl))
11492 register dw_separate_line_info_ref line_info;
11493 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11494 separate_line_info_table_in_use);
11496 /* expand the line info table if necessary */
11497 if (separate_line_info_table_in_use
11498 == separate_line_info_table_allocated)
11500 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11501 separate_line_info_table
11502 = (dw_separate_line_info_ref)
11503 xrealloc (separate_line_info_table,
11504 separate_line_info_table_allocated
11505 * sizeof (dw_separate_line_info_entry));
11508 /* Add the new entry at the end of the line_info_table. */
11510 = &separate_line_info_table[separate_line_info_table_in_use++];
11511 line_info->dw_file_num = lookup_filename (filename);
11512 line_info->dw_line_num = line;
11513 line_info->function = current_funcdef_number;
11517 register dw_line_info_ref line_info;
11519 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11520 line_info_table_in_use);
11522 /* Expand the line info table if necessary. */
11523 if (line_info_table_in_use == line_info_table_allocated)
11525 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11527 = (dw_line_info_ref)
11528 xrealloc (line_info_table,
11529 (line_info_table_allocated
11530 * sizeof (dw_line_info_entry)));
11533 /* Add the new entry at the end of the line_info_table. */
11534 line_info = &line_info_table[line_info_table_in_use++];
11535 line_info->dw_file_num = lookup_filename (filename);
11536 line_info->dw_line_num = line;
11541 /* Record the beginning of a new source file. */
11544 dwarf2out_start_source_file (lineno, filename)
11545 register unsigned int lineno;
11546 register const char *filename;
11548 if (flag_eliminate_dwarf2_dups)
11550 /* Record the beginning of the file for break_out_includes. */
11551 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11552 add_AT_string (bincl_die, DW_AT_name, filename);
11554 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11556 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11557 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11558 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11560 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11561 "Filename we just started");
11565 /* Record the end of a source file. */
11568 dwarf2out_end_source_file (lineno)
11569 unsigned int lineno ATTRIBUTE_UNUSED;
11571 if (flag_eliminate_dwarf2_dups)
11573 /* Record the end of the file for break_out_includes. */
11574 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11576 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11578 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11579 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11583 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11584 the tail part of the directive line, i.e. the part which is past the
11585 initial whitespace, #, whitespace, directive-name, whitespace part. */
11588 dwarf2out_define (lineno, buffer)
11589 register unsigned lineno ATTRIBUTE_UNUSED;
11590 register const char *buffer ATTRIBUTE_UNUSED;
11592 static int initialized = 0;
11595 dwarf2out_start_source_file (0, primary_filename);
11598 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11600 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11601 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11602 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11603 dw2_asm_output_nstring (buffer, -1, "The macro");
11607 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11608 the tail part of the directive line, i.e. the part which is past the
11609 initial whitespace, #, whitespace, directive-name, whitespace part. */
11612 dwarf2out_undef (lineno, buffer)
11613 register unsigned lineno ATTRIBUTE_UNUSED;
11614 register const char *buffer ATTRIBUTE_UNUSED;
11616 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11618 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11619 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11620 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11621 dw2_asm_output_nstring (buffer, -1, "The macro");
11625 /* Set up for Dwarf output at the start of compilation. */
11628 dwarf2out_init (main_input_filename)
11629 register const char *main_input_filename;
11631 init_file_table ();
11633 /* Remember the name of the primary input file. */
11634 primary_filename = main_input_filename;
11636 /* Add it to the file table first, under the assumption that we'll
11637 be emitting line number data for it first, which avoids having
11638 to add an initial DW_LNS_set_file. */
11639 lookup_filename (main_input_filename);
11641 /* Allocate the initial hunk of the decl_die_table. */
11643 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11644 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11645 decl_die_table_in_use = 0;
11647 /* Allocate the initial hunk of the decl_scope_table. */
11649 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11650 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11651 decl_scope_depth = 0;
11653 /* Allocate the initial hunk of the abbrev_die_table. */
11655 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11656 sizeof (dw_die_ref));
11657 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11658 /* Zero-th entry is allocated, but unused */
11659 abbrev_die_table_in_use = 1;
11661 /* Allocate the initial hunk of the line_info_table. */
11663 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11664 sizeof (dw_line_info_entry));
11665 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11666 /* Zero-th entry is allocated, but unused */
11667 line_info_table_in_use = 1;
11669 /* Generate the initial DIE for the .debug section. Note that the (string)
11670 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11671 will (typically) be a relative pathname and that this pathname should be
11672 taken as being relative to the directory from which the compiler was
11673 invoked when the given (base) source file was compiled. */
11674 comp_unit_die = gen_compile_unit_die (main_input_filename);
11676 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11677 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11679 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11680 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11681 DEBUG_ABBREV_SECTION_LABEL, 0);
11682 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11683 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11685 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
11686 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11687 DEBUG_INFO_SECTION_LABEL, 0);
11688 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11689 DEBUG_LINE_SECTION_LABEL, 0);
11690 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11691 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11692 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
11693 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11694 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11695 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11696 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11698 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11699 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11700 DEBUG_MACINFO_SECTION_LABEL, 0);
11701 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11704 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11707 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11711 /* Output stuff that dwarf requires at the end of every file,
11712 and generate the DWARF-2 debugging info. */
11715 dwarf2out_finish (input_filename)
11716 register const char *input_filename ATTRIBUTE_UNUSED;
11718 limbo_die_node *node, *next_node;
11719 dw_die_ref die = 0;
11721 /* Traverse the limbo die list, and add parent/child links. The only
11722 dies without parents that should be here are concrete instances of
11723 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11724 For concrete instances, we can get the parent die from the abstract
11726 for (node = limbo_die_list; node; node = next_node)
11728 next_node = node->next;
11731 if (die->die_parent == NULL)
11733 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11735 add_child_die (origin->die_parent, die);
11736 else if (die == comp_unit_die)
11743 limbo_die_list = NULL;
11745 /* Walk through the list of incomplete types again, trying once more to
11746 emit full debugging info for them. */
11747 retry_incomplete_types ();
11749 /* We need to reverse all the dies before break_out_includes, or
11750 we'll see the end of an include file before the beginning. */
11751 reverse_all_dies (comp_unit_die);
11753 /* Generate separate CUs for each of the include files we've seen.
11754 They will go into limbo_die_list. */
11755 if (flag_eliminate_dwarf2_dups)
11756 break_out_includes (comp_unit_die);
11758 /* Traverse the DIE's and add add sibling attributes to those DIE's
11759 that have children. */
11760 add_sibling_attributes (comp_unit_die);
11761 for (node = limbo_die_list; node; node = node->next)
11762 add_sibling_attributes (node->die);
11764 /* Output a terminator label for the .text section. */
11766 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11768 /* Output the source line correspondence table. We must do this
11769 even if there is no line information. Otherwise, on an empty
11770 translation unit, we will generate a present, but empty,
11771 .debug_info section. IRIX 6.5 `nm' will then complain when
11772 examining the file. */
11773 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11775 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11776 output_line_info ();
11779 /* Output location list section if necessary. */
11780 if (have_location_lists)
11782 /* Output the location lists info. */
11783 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
11784 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
11785 DEBUG_LOC_SECTION_LABEL, 0);
11786 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11787 output_location_lists (die);
11788 have_location_lists = 0;
11791 /* We can only use the low/high_pc attributes if all of the code was
11793 if (separate_line_info_table_in_use == 0)
11795 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11796 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11798 /* And if it wasn't, we need to give .debug_loc and .debug_ranges
11799 an appropriate "base address". Use zero so that these addresses
11800 become absolute. */
11801 else if (have_location_lists || ranges_table_in_use)
11802 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
11804 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11805 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11806 debug_line_section_label);
11808 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11809 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11811 /* Output all of the compilation units. We put the main one last so that
11812 the offsets are available to output_pubnames. */
11813 for (node = limbo_die_list; node; node = node->next)
11814 output_comp_unit (node->die);
11815 output_comp_unit (comp_unit_die);
11817 /* Output the abbreviation table. */
11818 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11819 output_abbrev_section ();
11821 if (pubname_table_in_use)
11823 /* Output public names table. */
11824 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
11825 output_pubnames ();
11828 /* We only put functions in the arange table, so don't write it out if
11829 we don't have any. */
11830 if (fde_table_in_use)
11832 /* Output the address range information. */
11833 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
11837 /* Output ranges section if necessary. */
11838 if (ranges_table_in_use)
11840 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
11844 /* Have to end the primary source file. */
11845 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11847 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11848 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11851 #endif /* DWARF2_DEBUGGING_INFO */